Loading slc/trunk/Makefile.am +4 Changes for slc/trunk/Makefile.am: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ slc_SOURCES= src/slc.hh \ src/options.hh \ src/screen.hh \ src/screen.cc \ src/connection.hh \ src/connection.cc \ src/history.hh \ src/history.cc \ src/error.hh \ src/error.cc Loading slc/trunk/src/connection.cc +10 Changes for slc/trunk/src/connection.cc: 10 added lines, 0 removed lines. Original line number Diff line number Diff line #include "slc.hh" #include "connection.hh" void Connection::start() { return; } void Connection::stop() { return; } slc/trunk/src/connection.hh +17 Changes for slc/trunk/src/connection.hh: 17 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef CONNECTION_HH # define CONNECTION_HH class Connection { public: void start(); void stop(); void send(const string &data); void send(const char* buf, size_t len); private: void connect_(); void disconnect_(); private: int socket_; }; #endif slc/trunk/src/history.cc +82 Changes for slc/trunk/src/history.cc: 82 added lines, 0 removed lines. Original line number Diff line number Diff line #include "slc.hh" #include "history.hh" #include "error.hh" History::History() : max_size_(100) {} void History::add(const string &s) { assert(strchr(s.c_str(), '\n') == 0); assert(max_size_ > 0); if (s.empty()) return; if (table_.size() >= max_size_) table_.resize(max_size_); table_.push_front(s); } const string &History::get(size_t off) const { assert(max_size_ > 0); assert(off < table_.size()); t_lines::const_iterator it; size_t pos; static string empty; for (pos = 0, it = table_.begin(); it != table_.end(); ++pos, ++it) if (pos == off) return *it; return empty; } void History::load(const string &filename) { ifstream fs; t_lines::const_iterator it; char buf[MAX_LINE_SIZE]; fs.open(filename.c_str(), ifstream::in); if (!fs.is_open()) return; while (!fs.eof()) { if (fs.fail()) throw Error(ERR_FILE, "Unable to load history"); fs.getline(buf, MAX_LINE_SIZE); add(buf); } fs.close(); } void History::save(const string &filename) const { ofstream fs; t_lines::const_reverse_iterator rit; fs.open(filename.c_str(), ostream::out | ostream::trunc); if (!fs.is_open()) throw Error(ERR_FILE, "Unable to open history file"); for (rit = table_.rbegin(); rit != table_.rend(); ++rit) { fs.write((*rit).c_str(), (*rit).length()); fs.put('\n'); if (fs.fail()) throw Error(ERR_FILE, "Unable to save history"); } fs.close(); } size_t History::size() const { return table_.size(); } void History::max_size(size_t s) { assert(s > 0); max_size_ = s; } slc/trunk/src/history.hh +28 Changes for slc/trunk/src/history.hh: 28 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef HISTORY_HH # define HISTORY_HH # include <list> class History { public: typedef std::list<string> t_lines; History(); public: const string &get(size_t off) const; void add(const string &line); size_t size() const; void max_size(size_t s); void save(const string &filename) const; void load(const string &filename); private: t_lines table_; size_t max_size_; }; #endif Loading
slc/trunk/Makefile.am +4 Changes for slc/trunk/Makefile.am: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ slc_SOURCES= src/slc.hh \ src/options.hh \ src/screen.hh \ src/screen.cc \ src/connection.hh \ src/connection.cc \ src/history.hh \ src/history.cc \ src/error.hh \ src/error.cc Loading
slc/trunk/src/connection.cc +10 Changes for slc/trunk/src/connection.cc: 10 added lines, 0 removed lines. Original line number Diff line number Diff line #include "slc.hh" #include "connection.hh" void Connection::start() { return; } void Connection::stop() { return; }
slc/trunk/src/connection.hh +17 Changes for slc/trunk/src/connection.hh: 17 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef CONNECTION_HH # define CONNECTION_HH class Connection { public: void start(); void stop(); void send(const string &data); void send(const char* buf, size_t len); private: void connect_(); void disconnect_(); private: int socket_; }; #endif
slc/trunk/src/history.cc +82 Changes for slc/trunk/src/history.cc: 82 added lines, 0 removed lines. Original line number Diff line number Diff line #include "slc.hh" #include "history.hh" #include "error.hh" History::History() : max_size_(100) {} void History::add(const string &s) { assert(strchr(s.c_str(), '\n') == 0); assert(max_size_ > 0); if (s.empty()) return; if (table_.size() >= max_size_) table_.resize(max_size_); table_.push_front(s); } const string &History::get(size_t off) const { assert(max_size_ > 0); assert(off < table_.size()); t_lines::const_iterator it; size_t pos; static string empty; for (pos = 0, it = table_.begin(); it != table_.end(); ++pos, ++it) if (pos == off) return *it; return empty; } void History::load(const string &filename) { ifstream fs; t_lines::const_iterator it; char buf[MAX_LINE_SIZE]; fs.open(filename.c_str(), ifstream::in); if (!fs.is_open()) return; while (!fs.eof()) { if (fs.fail()) throw Error(ERR_FILE, "Unable to load history"); fs.getline(buf, MAX_LINE_SIZE); add(buf); } fs.close(); } void History::save(const string &filename) const { ofstream fs; t_lines::const_reverse_iterator rit; fs.open(filename.c_str(), ostream::out | ostream::trunc); if (!fs.is_open()) throw Error(ERR_FILE, "Unable to open history file"); for (rit = table_.rbegin(); rit != table_.rend(); ++rit) { fs.write((*rit).c_str(), (*rit).length()); fs.put('\n'); if (fs.fail()) throw Error(ERR_FILE, "Unable to save history"); } fs.close(); } size_t History::size() const { return table_.size(); } void History::max_size(size_t s) { assert(s > 0); max_size_ = s; }
slc/trunk/src/history.hh +28 Changes for slc/trunk/src/history.hh: 28 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef HISTORY_HH # define HISTORY_HH # include <list> class History { public: typedef std::list<string> t_lines; History(); public: const string &get(size_t off) const; void add(const string &line); size_t size() const; void max_size(size_t s); void save(const string &filename) const; void load(const string &filename); private: t_lines table_; size_t max_size_; }; #endif