├── AUTHORS ├── config_debug.h.in ├── ChangeLog ├── config_config_dir.h.in ├── config_version.h.in ├── bootstrap ├── NEWS ├── config_types.h.in ├── config_curses.h.in ├── config_function.h.in ├── config_streambuf.h.in ├── config_filebuf.h.in ├── do_conf ├── do_confdeb ├── qtrever.cpp ├── config_locale.h.in ├── select.h ├── config_fork.h.in ├── config_wait.h.in ├── history.h ├── qtreassert.cpp ├── selectfile.h ├── qtre.psf ├── exec.h ├── config_dirent.h.in ├── qtreassert.h ├── textwindow.h ├── action.h ├── qtrehelp.cpp ├── linkperl.h ├── status.h ├── dirutil.h ├── screen.h ├── selectfile.cpp ├── finder.h ├── screen.cpp ├── history.cpp ├── textwindow.cpp ├── dialog.h ├── util.h ├── linkperl.cpp ├── Makefile.am ├── action.cpp ├── mkinstalldirs ├── status.cpp ├── menu.h ├── trace.h ├── screenbase.h ├── qperl.h ├── trace.cpp ├── compile ├── select.cpp ├── exec.cpp ├── config.h.in ├── text.h ├── termstream.h ├── dirutil.cpp ├── qtre.cpp ├── configure.ac ├── textline.h ├── menuscreen.cpp ├── README ├── screenimpl.h ├── screenbase.cpp ├── INSTALL ├── install-sh ├── missing ├── termstream.cpp ├── menu.cpp └── qtre.pl /AUTHORS: -------------------------------------------------------------------------------- 1 | (C) 2000-2006 Julian Albo 2 | -------------------------------------------------------------------------------- /config_debug.h.in: -------------------------------------------------------------------------------- 1 | /* config_debug.h.in */ 2 | 3 | #undef NDEBUG 4 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See also the NEWS file. 2 | 3 | 2013-08-08 Started git repository 4 | -------------------------------------------------------------------------------- /config_config_dir.h.in: -------------------------------------------------------------------------------- 1 | /* config_config_dir.h.in */ 2 | 3 | #undef CONFIG_DIR 4 | -------------------------------------------------------------------------------- /config_version.h.in: -------------------------------------------------------------------------------- 1 | /* config_version.h.in */ 2 | 3 | #undef PACKAGE_VERSION 4 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | aclocal -I . 4 | automake --add-missing --copy 5 | autoconf 6 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 2006-01-25 2 | 3 | Locales wifh utf8 encoding are now supported. 4 | Now we have configure ! 5 | -------------------------------------------------------------------------------- /config_types.h.in: -------------------------------------------------------------------------------- 1 | /* config_types.h.in */ 2 | 3 | #undef pid_t 4 | #undef uid_t 5 | #undef mode_t 6 | -------------------------------------------------------------------------------- /config_curses.h.in: -------------------------------------------------------------------------------- 1 | /* config_curses.h.in */ 2 | 3 | #undef HAVE_NCURSESW_NCURSES_H 4 | #undef HAVE_NCURSES_H 5 | -------------------------------------------------------------------------------- /config_function.h.in: -------------------------------------------------------------------------------- 1 | /* config_function.h.in */ 2 | 3 | #undef HAVE_FUNCTION 4 | #undef HAVE_PRETTY_FUNCTION 5 | -------------------------------------------------------------------------------- /config_streambuf.h.in: -------------------------------------------------------------------------------- 1 | /* config_streambuf.h.in */ 2 | 3 | #undef HAVE_STREAMBUF 4 | #undef HAVE_STREAMBUF_H 5 | -------------------------------------------------------------------------------- /config_filebuf.h.in: -------------------------------------------------------------------------------- 1 | /* config_filebuf.h.in */ 2 | 3 | #undef HAVE_EXT_STDIO_FILEBUF_H 4 | #undef FILEBUF_PARAMS 5 | -------------------------------------------------------------------------------- /do_conf: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # My usual config for direct compiling. 4 | 5 | ./configure \ 6 | --sysconfdir=/etc \ 7 | "$@" \ 8 | CXXFLAGS="-g -O3 -W -Wall -Wunused -Werror -Wno-deprecated" 9 | -------------------------------------------------------------------------------- /do_confdeb: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # My usual config for direct compiling. 4 | 5 | ./configure \ 6 | --enable-debug \ 7 | --sysconfdir=/etc \ 8 | "$@" \ 9 | CXXFLAGS="-g -O3 -W -Wall -Wunused -Werror -Wno-deprecated" 10 | -------------------------------------------------------------------------------- /qtrever.cpp: -------------------------------------------------------------------------------- 1 | // qtrever.cpp 2 | 3 | #include "config_version.h" 4 | 5 | #include 6 | 7 | extern const std::string 8 | strVersion= "Version " PACKAGE_VERSION, 9 | strAbout1= " qtre ", 10 | strAbout2= "Quick Tool for Raw Editing", 11 | strAbout3= "(C) 2000-2009 Julian Albo"; 12 | 13 | // Fin de qtrever.cpp 14 | -------------------------------------------------------------------------------- /config_locale.h.in: -------------------------------------------------------------------------------- 1 | /* config_locale.h.in */ 2 | 3 | #undef HAVE_LOCALE_H 4 | #undef HAVE_NL_TYPES_H 5 | #undef HAVE_LANGINFO_H 6 | 7 | #if HAVE_LOCALE_H 8 | # include 9 | #endif 10 | 11 | #ifdef HAVE_NL_TYPES_H 12 | # include 13 | #endif 14 | 15 | #ifdef HAVE_LANGINFO_H 16 | # include 17 | #endif 18 | -------------------------------------------------------------------------------- /select.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SELECT_H_ 2 | #define INCLUDE_SELECT_H_ 3 | 4 | // select.h 5 | // Revision 29-jan-2006 6 | 7 | #include "termstream.h" 8 | 9 | #include 10 | #include 11 | 12 | size_t selectlist (otermstream & ot, const std::string & title, 13 | const std::vector & vstr); 14 | 15 | #endif 16 | 17 | // End of select.h 18 | -------------------------------------------------------------------------------- /config_fork.h.in: -------------------------------------------------------------------------------- 1 | /* config_debug.h.in */ 2 | 3 | #undef HAVE_FORK 4 | #undef HAVE_WORKING_FORK 5 | 6 | #undef HAVE_VFORK_H 7 | #undef HAVE_WORKING_VFORK 8 | 9 | #ifdef HAVE_VFORK_H 10 | # include 11 | #endif 12 | 13 | #ifndef HAVE_WORKING_VFORK 14 | # ifndef HAVE_FORK 15 | # error Cannot fork, configure error? 16 | # endif 17 | # define vfork fork 18 | #endif 19 | -------------------------------------------------------------------------------- /config_wait.h.in: -------------------------------------------------------------------------------- 1 | /* config_debug.h.in */ 2 | 3 | #undef HAVE_SYS_TYPES_H 4 | #undef HAVE_SYS_WAIT_H 5 | 6 | #ifdef HAVE_SYS_TYPES_H 7 | # include 8 | #endif 9 | 10 | #ifdef HAVE_SYS_WAIT_H 11 | # include 12 | #endif 13 | 14 | #ifndef WEXITSTATUS 15 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) 16 | #endif 17 | #ifndef WIFEXITED 18 | # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 19 | #endif 20 | -------------------------------------------------------------------------------- /history.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_HISTORY_H_ 2 | #define INCLUDE_HISTORY_H_ 3 | 4 | // history.h 5 | // Revision 18-sep-2004 6 | 7 | #include 8 | 9 | class History { 10 | public: 11 | History (); 12 | ~History (); 13 | size_t size () const; 14 | std::string operator [] (const size_t n) const; 15 | void push_back (const std::string & str); 16 | private: 17 | class Internal; 18 | Internal * pin; 19 | }; 20 | 21 | #endif 22 | 23 | // End of history.h 24 | -------------------------------------------------------------------------------- /qtreassert.cpp: -------------------------------------------------------------------------------- 1 | // qtreassert.cpp 2 | // Revision 19-sep-2003 3 | 4 | #include 5 | #include 6 | 7 | #ifndef NDEBUG 8 | 9 | extern "C" 10 | void qtre_assert_failed (const char * a, const char * file, size_t line) 11 | { 12 | std::ostringstream oss; 13 | oss << "ASSERTION FAILED: " << a << " in file " << file << 14 | " line " << line; 15 | throw std::logic_error (oss.str () ); 16 | } 17 | 18 | #endif 19 | 20 | // End of qtreassert.cpp 21 | -------------------------------------------------------------------------------- /selectfile.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SELECTFILE_H_ 2 | #define INCLUDE_SELECTFILE_H_ 3 | 4 | // selectfile.h 5 | // Revision 17-oct-2005 6 | 7 | #include 8 | 9 | #include "termstream.h" 10 | 11 | class RedrawerSelectFile { 12 | public: 13 | virtual void doit ()= 0; 14 | virtual ~RedrawerSelectFile (); 15 | }; 16 | 17 | std::string selectfile (otermstream & ot, const std::string & title, 18 | RedrawerSelectFile & redrawer); 19 | 20 | #endif 21 | 22 | // End of selectfile.h 23 | -------------------------------------------------------------------------------- /qtre.psf: -------------------------------------------------------------------------------- 1 | # 2 | # qtre.psf 3 | # 4 | # Product Specification File to distribute qtre 5 | # in hp-ux depot format. 6 | # 7 | # Autor: Julian Albo 8 | # 9 | 10 | depot 11 | product 12 | tag qtre 13 | 14 | fileset 15 | tag qtre-fileset 16 | 17 | file_permissions -o root -g root 18 | 19 | file -m 0755 ./qtre /usr/contrib/bin/qtre 20 | file -m 0644 ./qtre.pl /etc/qtre.pl 21 | 22 | end #fileset 23 | 24 | end #product 25 | 26 | end #depot 27 | 28 | # End of qtre.psf 29 | -------------------------------------------------------------------------------- /exec.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_EXEC_H_ 2 | #define INCLUDE_EXEC_H_ 3 | 4 | // exec.h 5 | // Revision 18-sep-2004 6 | 7 | #include 8 | 9 | class Exec { 10 | protected: 11 | Exec (); 12 | virtual ~Exec (); 13 | virtual void ExecSendChar (char c)= 0; 14 | virtual bool ExecSendBlock (const char * str, size_t size); 15 | virtual bool ExecQueryAbort (); 16 | void Command (const std::string & strCommand); 17 | private: 18 | class Impl; 19 | Impl * pi; 20 | friend class Impl; 21 | }; 22 | 23 | #endif 24 | 25 | // Fin de exec.h 26 | -------------------------------------------------------------------------------- /config_dirent.h.in: -------------------------------------------------------------------------------- 1 | /* config_debug.h.in */ 2 | 3 | #undef CLOSEDIR_VOID 4 | #undef HAVE_DIRENT_H 5 | #undef HAVE_SYS_NDIR_H 6 | #undef HAVE_SYS_DIR_H 7 | #undef HAVE_NDIR_H 8 | 9 | /* This is from autoconf manual */ 10 | #if HAVE_DIRENT_H 11 | # include 12 | # define NAMELEN(dirent) strlen((dirent)->d_name) 13 | #else 14 | # define dirent direct 15 | # define NAMELEN(dirent) (dirent)->namlen 16 | # if HAVE_SYS_DIR_H 17 | # include 18 | # endif 19 | # if HAVE_NDIR_H 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /qtreassert.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_QTREASSERT_H_ 2 | #define INCLUDE_QTREASSERT_H_ 3 | 4 | /* 5 | qtreassert.h 6 | Revision 27-jan-2006 7 | */ 8 | 9 | #include "config_debug.h" 10 | 11 | 12 | #ifndef NDEBUG 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | #endif 17 | void qtre_assert_failed (const char * a, const char * file, size_t line); 18 | 19 | #define ASSERT(a) if (a) ; else \ 20 | qtre_assert_failed (#a, __FILE__, __LINE__) 21 | 22 | #else 23 | 24 | #define ASSERT(a) 25 | 26 | #endif 27 | 28 | #endif 29 | 30 | /* End of qtreassert.h */ 31 | -------------------------------------------------------------------------------- /textwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TEXTWINDOW_H_ 2 | #define INCLUDE_TEXTWINDOW_H_ 3 | 4 | // textwindow.h 5 | // Revision 25-jan-2006 6 | 7 | #include "text.h" 8 | 9 | class TextWindow 10 | { 11 | private: 12 | size_t * pcount; 13 | TextFile * ptext; 14 | public: 15 | TextWindow (bool useutf8); 16 | TextWindow (const TextWindow & tw); 17 | ~TextWindow (); 18 | void operator = (const TextWindow & tw); 19 | TextFile * text (); 20 | size_t lin; 21 | Col col; 22 | size_t inilin; 23 | Col inicol; 24 | Selection sel; 25 | }; 26 | 27 | #endif 28 | 29 | // End of textwindow.h 30 | -------------------------------------------------------------------------------- /action.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_ACTION_H 2 | #define INCLUDE_ACTION_H 3 | 4 | // action.h 5 | // Revision 27-sep-2004 6 | 7 | #include 8 | 9 | class Action { 10 | public: 11 | Action (); 12 | virtual ~Action (); 13 | virtual void doit ()= 0; 14 | //virtual Action * clone ()= 0; 15 | private: 16 | Action (const Action &); 17 | void operator= (const Action &); 18 | }; 19 | 20 | class MapKeyAction { 21 | public: 22 | virtual ~MapKeyAction (); 23 | void addKeyAction (int key, Action * action); 24 | Action * getKeyAction (int key); 25 | 26 | typedef std::map mapka; 27 | private: 28 | mapka m; 29 | }; 30 | 31 | #endif 32 | 33 | // End of action.h 34 | -------------------------------------------------------------------------------- /qtrehelp.cpp: -------------------------------------------------------------------------------- 1 | // qtrehelp.cpp 2 | // Revision 28-sep-2004 3 | 4 | extern const char strHelp []= 5 | 6 | "\t\tqtre: Quick Tool for Raw Editing\n\n" 7 | 8 | "MENU: F10, ctrl-N\n" 9 | "Quit: ctrl-q\n" 10 | "Close file or quit: F8\n" 11 | "Save: F2\n" 12 | 13 | "\n\tSearch and replace\n\n" 14 | 15 | "Find: ctrl-F\n" 16 | "Find again: ctrl-A\n" 17 | "Replace: ctrl-R\n" 18 | 19 | "\n\tEdition.\n\n" 20 | 21 | "Delete line: ctrl-Y\n" 22 | "Insert special char: ctrl-T\n" 23 | "Begin/end selection: ctrl-S\n" 24 | "Cut: ctrl-X\n" 25 | "Copy: ctrl-C\n" 26 | "Paste: ctrl-V\n" 27 | 28 | "\n\tSystem\n\n" 29 | 30 | "Evaluate expression: ctrl-E\n" 31 | "Execute macro: ctrl-K\n" 32 | 33 | ; 34 | 35 | // Fin de qtrehelp.cpp 36 | -------------------------------------------------------------------------------- /linkperl.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_LINKPERL_H 2 | #define INCLUDE_LINKPERL_H 3 | 4 | // linkperl.h 5 | // Revision 4-oct-2004 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ScreenImpl; 12 | 13 | class LinkPerl { 14 | public: 15 | LinkPerl (char * * env, ScreenImpl * pscreen); 16 | ~LinkPerl (); 17 | void perlinitdone (); 18 | 19 | void callperlfunc (const std::string & func); 20 | void callperlfunc (const std::string & func, 21 | const std::vector vargs); 22 | int callperleval (const std::string & expression); 23 | 24 | class Error : public std::runtime_error { 25 | public: 26 | Error (const std::string & str); 27 | }; 28 | }; 29 | 30 | #endif 31 | 32 | // End of linkperl.h 33 | -------------------------------------------------------------------------------- /status.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_STATUS_H_ 2 | #define INCLUDE_STATUS_H_ 3 | 4 | // status.h 5 | // Revision 2-oct-2004 6 | 7 | #include "termstream.h" 8 | 9 | #include 10 | 11 | class StatusLine 12 | { 13 | public: 14 | StatusLine (int ancho, int y); 15 | ~StatusLine (); 16 | void invalidate (); 17 | void refresh (); 18 | void update (); 19 | void settext (std::string str); 20 | int getkey (const std::string & str); 21 | void clear (); 22 | void lincol (int y, int x); 23 | char question (const std::string & q, const std::string & values); 24 | private: 25 | void plincol (); 26 | void puttext (); 27 | otermstream ot; 28 | size_t max; 29 | int y; 30 | int x; 31 | std::string str; 32 | bool invalid; 33 | }; 34 | 35 | #endif 36 | 37 | // Fin de status.h 38 | -------------------------------------------------------------------------------- /dirutil.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DIRUTIL_H_ 2 | #define INCLUDE_DIRUTIL_H_ 3 | 4 | // dirutil.h 5 | // Revision 3-oct-2004 6 | 7 | #include 8 | #include 9 | 10 | namespace dirutil { 11 | 12 | bool is_directory (const std::string & str); 13 | 14 | std::string base_name (const std::string & str); 15 | std::string dir_name (const std::string & str); 16 | std::string extension (const std::string & str); 17 | 18 | std::string enter_dir (const std::string & old, const std::string & enter); 19 | 20 | void directory (const std::string & dirname, std::vector & v); 21 | 22 | void delete_file (const std::string & filename); 23 | 24 | std::string create_temp_file (); 25 | 26 | void copy_remote_file (const std::string & source, const std::string & dest); 27 | 28 | } // namespace dirutil 29 | 30 | #endif 31 | 32 | // End of dirutil.h 33 | -------------------------------------------------------------------------------- /screen.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SCREEN_H_ 2 | #define INCLUDE_SCREEN_H_ 3 | 4 | // screen.h 5 | // Revision 25-jan-2006 6 | 7 | //#include "menu.h" 8 | //#include "qperl.h" 9 | 10 | #include 11 | 12 | #include 13 | 14 | class Screen 15 | { 16 | protected: 17 | Screen (); 18 | public: 19 | virtual ~Screen (); 20 | 21 | #ifndef NDEBUG 22 | static bool screenpointervalid (Screen * p); 23 | #endif 24 | 25 | virtual void windownew ()= 0; 26 | virtual size_t textlines () const= 0; 27 | virtual void gotoline (size_t l)= 0; 28 | virtual void loadtext (FILE * fin)= 0; 29 | virtual void loadtext (const std::string & strFileName)= 0; 30 | virtual void changewindow (size_t newwin)= 0; 31 | virtual void interact ()= 0; 32 | }; 33 | 34 | Screen * createScreen (bool useutf8, char * * env); 35 | 36 | #endif 37 | 38 | // End of screen.h 39 | -------------------------------------------------------------------------------- /selectfile.cpp: -------------------------------------------------------------------------------- 1 | // selectfile.cpp 2 | // Revision 29-jan-2006 3 | 4 | #include "selectfile.h" 5 | 6 | #include "select.h" 7 | #include "dirutil.h" 8 | 9 | #include 10 | 11 | RedrawerSelectFile::~RedrawerSelectFile () 12 | { 13 | } 14 | 15 | std::string selectfile (otermstream & ot, const std::string & title, 16 | RedrawerSelectFile & redrawer) 17 | { 18 | using namespace dirutil; 19 | 20 | std::vector v; 21 | std::string dir= "."; 22 | 23 | std::string result; 24 | for (;;) 25 | { 26 | directory (dir, v); 27 | std::sort (v.begin (), v.end () ); 28 | 29 | size_t r= selectlist (ot, title, v); 30 | if (r == size_t (-1) ) 31 | break; 32 | std::string sel= enter_dir (dir, v [r] ); 33 | if (! is_directory (sel) ) 34 | { 35 | result= sel; 36 | break; 37 | } 38 | dir= sel; 39 | redrawer.doit (); 40 | } 41 | return result; 42 | } 43 | 44 | // End of selectfile.cpp 45 | -------------------------------------------------------------------------------- /finder.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_FINDER_H_ 2 | #define INCLUDE_FINDER_H_ 3 | 4 | // finder.h 5 | // Revision 21-sep-2004 6 | 7 | #include 8 | 9 | struct SearchOptions { 10 | bool backwards; 11 | bool nocase; 12 | bool wholeword; 13 | bool regex; 14 | bool function; 15 | SearchOptions (); 16 | }; 17 | 18 | class Finder { 19 | public: 20 | typedef std::string string; 21 | typedef std::string::size_type size_type; 22 | static const size_type npos= string::npos; 23 | 24 | virtual bool backwards () const { return false; } 25 | virtual size_type find (const string & str)= 0; 26 | virtual size_type find (const string & str, size_type from) = 0; 27 | virtual size_type length () const = 0; // Length of last match. 28 | virtual string replace (const string & str, const string & line)= 0; 29 | virtual string replace (const string & function, const string & line, 30 | size_type pos, void * data) = 0; 31 | 32 | virtual ~Finder () { } 33 | }; 34 | 35 | Finder * createFinder 36 | (const SearchOptions & options, const std::string & strFind); 37 | 38 | 39 | #endif 40 | 41 | // End of finder.h 42 | -------------------------------------------------------------------------------- /screen.cpp: -------------------------------------------------------------------------------- 1 | // screen.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "screen.h" 5 | 6 | #include "trace.h" 7 | 8 | #include 9 | #include 10 | 11 | using std::set; 12 | using std::logic_error; 13 | 14 | //*********************************************** 15 | // Screen 16 | //*********************************************** 17 | 18 | #ifndef NDEBUG 19 | 20 | namespace { 21 | 22 | set validscreen; 23 | 24 | } // namespace 25 | 26 | #endif 27 | 28 | Screen::Screen () 29 | { 30 | TRF; 31 | 32 | #ifndef NDEBUG 33 | 34 | if (validscreen.find (this) != validscreen.end () ) 35 | throw logic_error ("Error registering Screen instance"); 36 | validscreen.insert (this); 37 | 38 | #endif 39 | } 40 | 41 | Screen::~Screen () 42 | { 43 | TRF; 44 | 45 | #ifndef NDEBUG 46 | 47 | if (validscreen.find (this) == validscreen.end () ) 48 | throw logic_error ("Error unregistering Screen instance"); 49 | validscreen.erase (this); 50 | 51 | #endif 52 | } 53 | 54 | #ifndef NDEBUG 55 | 56 | bool Screen::screenpointervalid (Screen * p) 57 | { 58 | return validscreen.find (p) != validscreen.end (); 59 | } 60 | 61 | #endif 62 | 63 | 64 | // End of screen.cpp 65 | -------------------------------------------------------------------------------- /history.cpp: -------------------------------------------------------------------------------- 1 | // history.cpp 2 | // Revision 21-nov-2003 3 | 4 | #include "history.h" 5 | //#include 6 | #include 7 | 8 | class History::Internal { 9 | public: 10 | size_t size () const 11 | { 12 | return h.size (); 13 | } 14 | std::string operator [] (size_t n) const 15 | { 16 | return h [n]; 17 | } 18 | void push_back (const std::string & str) 19 | { 20 | if (size () >= maxsize) 21 | { 22 | h.erase (h.begin (), 23 | h.begin () + size () - maxsize + 1); 24 | } 25 | if (! str.empty () && (h.empty () || str != h.back () ) ) 26 | h.push_back (str); 27 | } 28 | private: 29 | static const size_t maxsize= 50; 30 | //std::deque h; 31 | std::vector h; 32 | }; 33 | 34 | const size_t History::Internal::maxsize; 35 | 36 | History::History () : 37 | pin (new Internal) 38 | { 39 | } 40 | 41 | History::~History () 42 | { 43 | delete pin; 44 | } 45 | 46 | size_t History::size () const 47 | { 48 | return pin->size (); 49 | } 50 | 51 | std::string History::operator [] (size_t n) const 52 | { 53 | return (* pin) [n]; 54 | } 55 | 56 | void History::push_back (const std::string & str) 57 | { 58 | pin->push_back (str); 59 | } 60 | 61 | // End of history.cpp 62 | -------------------------------------------------------------------------------- /textwindow.cpp: -------------------------------------------------------------------------------- 1 | // textwindow.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "textwindow.h" 5 | 6 | #include "trace.h" 7 | #undef ASSERT 8 | #include "qtreassert.h" 9 | 10 | TextWindow::TextWindow (bool useutf8) : 11 | pcount (new size_t), 12 | ptext (new TextFile (useutf8) ), 13 | lin (0), 14 | col (0), 15 | inilin (0), 16 | inicol (0) 17 | { 18 | TRF; 19 | 20 | * pcount= 1; 21 | } 22 | 23 | TextWindow::TextWindow (const TextWindow & tw) : 24 | pcount (tw.pcount), 25 | ptext (tw.ptext), 26 | lin (tw.lin), 27 | col (tw.col), 28 | inilin (tw.inilin), 29 | inicol (tw.inicol), 30 | sel (tw.sel) 31 | { 32 | TRF; 33 | 34 | ++ * pcount; 35 | } 36 | 37 | TextWindow::~TextWindow () 38 | { 39 | TRF; 40 | 41 | if (-- * pcount == 0) 42 | delete ptext; 43 | } 44 | 45 | void TextWindow::operator = (const TextWindow & tw) 46 | { 47 | TRF; 48 | 49 | if (this != & tw) 50 | { 51 | if (-- * pcount == 0) 52 | delete ptext; 53 | pcount= tw.pcount; 54 | ++ * pcount; 55 | ptext= tw.ptext; 56 | lin= tw.lin; 57 | col= tw.col; 58 | inilin= tw.inilin; 59 | inicol= tw.inicol; 60 | sel= tw.sel; 61 | } 62 | } 63 | 64 | TextFile * TextWindow::text () 65 | { 66 | return ptext; 67 | } 68 | 69 | // End of textwindow.cpp 70 | -------------------------------------------------------------------------------- /dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DIALOG_H_ 2 | #define INCLUDE_DIALOG_H_ 3 | 4 | // dialog.h 5 | // Revision 2-oct-2004 6 | 7 | #include "termstream.h" 8 | #include "history.h" 9 | 10 | #include 11 | #include 12 | 13 | void centertext (otermstream & ot, int lin, int width, std::string str); 14 | 15 | bool dialogGetString (otermstream &ots, 16 | int & keyend, const std::set & keyender, 17 | const std::string & title, const std::string & prompt, 18 | std::string & str, History & history, 19 | size_t width, std::string::size_type maxlength= std::string::npos); 20 | 21 | bool dialogGetString (otermstream &ots, 22 | const std::string & title, const std::string & prompt, 23 | std::string & str, History & history, 24 | size_t width, std::string::size_type maxlength= std::string::npos); 25 | 26 | void dialogShowText (otermstream & ots, const char * title, const char * str, 27 | int height, int width); 28 | 29 | 30 | enum dialogResult { dialogCancel, dialogYes, dialogNo }; 31 | 32 | dialogResult dialogQuestion (otermstream & ots, const std::string & str); 33 | 34 | class DialogOptions { 35 | public: 36 | DialogOptions (otermstream & ots, const std::string & title); 37 | ~DialogOptions (); 38 | void add (const std::string & description, bool & option); 39 | bool do_it (); 40 | private: 41 | class Internal; 42 | Internal * pin; 43 | }; 44 | 45 | #endif 46 | 47 | // Fin de dialog.h 48 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_UTIL_H_ 2 | #define INCLUDE_UTIL_H_ 3 | 4 | // util.h 5 | // Revision 27-nov-2003 6 | 7 | #include 8 | 9 | namespace util { 10 | 11 | template 12 | 13 | DEST checked_cast (ORG org, EX ex) 14 | { 15 | DEST dest= static_cast (org); 16 | if (static_cast (dest) != org) 17 | throw ex; 18 | return dest; 19 | } 20 | 21 | template 22 | 23 | inline size_t dim_array (C (&) [N]) 24 | { return N; } 25 | 26 | template 27 | 28 | inline size_t dim_array (const C (&) [N]) 29 | { return N; } 30 | 31 | template 32 | std::string to_string (const C & c) 33 | { 34 | std::ostringstream oss; 35 | oss << c; 36 | return oss.str (); 37 | } 38 | 39 | template 40 | 41 | class auto_buffer 42 | { 43 | public: 44 | auto_buffer (size_t s) : 45 | buffer (new C [s]) 46 | { 47 | } 48 | ~auto_buffer () 49 | { 50 | delete [] buffer; 51 | } 52 | operator C * () { return buffer; } 53 | private: 54 | auto_buffer (const auto_buffer &); // Forbidden 55 | auto_buffer & operator = (const auto_buffer &); // Forbidden 56 | C * buffer; 57 | }; 58 | 59 | class bool_saver { 60 | public: 61 | bool_saver (bool & save, bool value) : 62 | save (save), 63 | old (save) 64 | { 65 | save= value; 66 | } 67 | ~bool_saver () 68 | { 69 | save= old; 70 | } 71 | private: 72 | bool & save; 73 | bool old; 74 | }; 75 | 76 | } // namespace util 77 | 78 | #endif 79 | 80 | // End of util.h 81 | -------------------------------------------------------------------------------- /linkperl.cpp: -------------------------------------------------------------------------------- 1 | // linkperl.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "linkperl.h" 5 | 6 | #include "qperl.h" 7 | 8 | #include "trace.h" 9 | 10 | using std::string; 11 | 12 | LinkPerl::Error::Error (const std::string & str) : 13 | std::runtime_error (str) 14 | { 15 | } 16 | 17 | LinkPerl::LinkPerl (char * * env, ScreenImpl * pscreen) 18 | { 19 | TRF; 20 | 21 | if (qperl_init (env, pscreen) ) 22 | throw Error ("Failed perl initialization"); 23 | } 24 | 25 | LinkPerl::~LinkPerl () 26 | { 27 | TRF; 28 | 29 | qperl_destroy (); 30 | } 31 | 32 | void LinkPerl::perlinitdone () 33 | { 34 | qperl_init_done (); 35 | } 36 | 37 | void LinkPerl::callperlfunc (const std::string & func) 38 | { 39 | switch (qperl_function (func.c_str (), this) ) 40 | { 41 | case qpfunction_ok: 42 | break; 43 | case qpfunction_notfound: 44 | throw Error (string ("Undefined function ") + func); 45 | break; 46 | case qpfunction_failed: 47 | throw Error (string ("Error in function ") + func); 48 | break; 49 | } 50 | } 51 | 52 | void LinkPerl::callperlfunc (const std::string & func, 53 | const std::vector vargs) 54 | { 55 | const size_t nargs= vargs.size (); 56 | const char * * argv= new const char * [nargs]; 57 | for (size_t i= 0; i < nargs; ++i) 58 | argv [i]= vargs [i].c_str (); 59 | qperl_function_args (func.c_str (), this, nargs, argv); 60 | } 61 | 62 | int LinkPerl::callperleval (const std::string & expression) 63 | { 64 | return qperl_eval (expression.c_str (), this); 65 | } 66 | 67 | // End of linkperl.cpp 68 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | ## Makefile.am for qtre 3 | 4 | srcdir = @srcdir@ 5 | VPATH = @srcdir@ 6 | 7 | bin_PROGRAMS = qtre 8 | 9 | dist_sysconf_DATA = qtre.pl 10 | 11 | BUILT_SOURCES = qperlxsi.c 12 | CLEANFILES = qperlxsi.c 13 | 14 | qtre_SOURCES = \ 15 | action.h \ 16 | action.cpp \ 17 | dialog.h \ 18 | dialog.cpp \ 19 | dirutil.h \ 20 | dirutil.cpp \ 21 | exec.h \ 22 | exec.cpp \ 23 | finder.h \ 24 | finder.cpp \ 25 | history.h \ 26 | history.cpp \ 27 | linkperl.h \ 28 | linkperl.cpp \ 29 | menu.h \ 30 | menu.cpp \ 31 | menuscreen.cpp \ 32 | qperl.h \ 33 | qperl.c \ 34 | qtre.cpp \ 35 | qtreassert.h \ 36 | qtreassert.cpp \ 37 | qtrehelp.cpp \ 38 | qtrever.cpp \ 39 | screen.h \ 40 | screen.cpp \ 41 | screenbase.h \ 42 | screenbase.cpp \ 43 | screenimpl.h \ 44 | screenimpl.cpp \ 45 | select.h \ 46 | select.cpp \ 47 | selectfile.h \ 48 | selectfile.cpp \ 49 | status.h \ 50 | status.cpp \ 51 | termstream.h \ 52 | termstream.cpp \ 53 | text.h \ 54 | text.cpp \ 55 | textline.h \ 56 | textline.cpp \ 57 | textwindow.h \ 58 | textwindow.cpp \ 59 | trace.h \ 60 | trace.cpp \ 61 | util.h 62 | 63 | nodist_qtre_SOURCES= qperlxsi.c 64 | 65 | # Make qperlxsi depends of almost any change in configuration, 66 | # just in case. 67 | qperlxsi.c: config.h 68 | $(PERL) -MExtUtils::Embed -e xsinit -- -o qperlxsi.c 69 | 70 | AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" 71 | AM_CFLAGS = $(PERL_CCOPTS) 72 | 73 | qtre_LDADD= $(PERL_LDOPTS) 74 | 75 | 76 | # This is to create and install a package in hp-ux. 77 | 78 | depot: qtre 79 | strip qtre 80 | swpackage -v -s qtre.psf -d qtre.depot \ 81 | -x target_type=tape 82 | 83 | swinstall: 84 | swinstall -s `pwd`/qtre.depot qtre 85 | 86 | 87 | EXTRA_DIST = \ 88 | .qtre.pl \ 89 | qtre.psf \ 90 | bootstrap \ 91 | do_conf \ 92 | do_confdeb 93 | 94 | # End of Makefile.am 95 | -------------------------------------------------------------------------------- /action.cpp: -------------------------------------------------------------------------------- 1 | // action.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "action.h" 5 | 6 | #include "util.h" 7 | 8 | #include "trace.h" 9 | #undef ASSERT 10 | #include "qtreassert.h" 11 | 12 | #include 13 | 14 | using util::to_string; 15 | 16 | namespace { 17 | 18 | #ifndef NDEBUG 19 | 20 | class ActionInstanceCounter { 21 | public: 22 | ActionInstanceCounter (); 23 | ~ActionInstanceCounter (); 24 | void operator ++ () { ++count; } 25 | void operator -- (); 26 | private: 27 | size_t count; 28 | }; 29 | 30 | ActionInstanceCounter::ActionInstanceCounter () : count (0) 31 | { 32 | TRF; 33 | } 34 | 35 | ActionInstanceCounter::~ActionInstanceCounter () 36 | { 37 | TRF; 38 | 39 | if (count != 0) 40 | TRDEB ("ERROR: Action instance counter " 41 | "is not 0, is " + to_string (count) ); 42 | } 43 | 44 | void ActionInstanceCounter::operator -- () 45 | { 46 | ASSERT (count > 0); 47 | --count; 48 | } 49 | 50 | ActionInstanceCounter actioncount; 51 | 52 | #endif 53 | 54 | } // namespace 55 | 56 | Action::Action () 57 | { 58 | #ifndef NDEBUG 59 | ++actioncount; 60 | #endif 61 | } 62 | 63 | Action::~Action () 64 | { 65 | #ifndef NDEBUG 66 | --actioncount; 67 | #endif 68 | } 69 | 70 | namespace { 71 | 72 | struct Destroy { 73 | void operator () (MapKeyAction::mapka::value_type & v) 74 | { 75 | delete v.second; 76 | } 77 | }; 78 | 79 | } // namespace 80 | 81 | void MapKeyAction::addKeyAction (int key, Action * action) 82 | { 83 | mapka::iterator it= m.find (key); 84 | if (it != m.end () ) 85 | Destroy () (* it); 86 | m [key]= action; 87 | } 88 | 89 | Action * MapKeyAction::getKeyAction (int key) 90 | { 91 | mapka::iterator it= m.find (key); 92 | if (it != m.end () ) 93 | return it->second; 94 | else 95 | return 0; 96 | } 97 | 98 | MapKeyAction::~MapKeyAction () 99 | { 100 | std::for_each (m.begin (), m.end (), Destroy () ); 101 | } 102 | 103 | // End of action.cpp 104 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | # $Id: mkinstalldirs,v 1.13 1999/01/05 03:18:55 bje Exp $ 8 | 9 | errstatus=0 10 | dirmode="" 11 | 12 | usage="\ 13 | Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 14 | 15 | # process command line arguments 16 | while test $# -gt 0 ; do 17 | case "${1}" in 18 | -h | --help | --h* ) # -h for help 19 | echo "${usage}" 1>&2; exit 0 ;; 20 | -m ) # -m PERM arg 21 | shift 22 | test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } 23 | dirmode="${1}" 24 | shift ;; 25 | -- ) shift; break ;; # stop option processing 26 | -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option 27 | * ) break ;; # first non-opt arg 28 | esac 29 | done 30 | 31 | for file 32 | do 33 | if test -d "$file"; then 34 | shift 35 | else 36 | break 37 | fi 38 | done 39 | 40 | case $# in 41 | 0) exit 0 ;; 42 | esac 43 | 44 | case $dirmode in 45 | '') 46 | if mkdir -p -- . 2>/dev/null; then 47 | echo "mkdir -p -- $*" 48 | exec mkdir -p -- "$@" 49 | fi ;; 50 | *) 51 | if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 52 | echo "mkdir -m $dirmode -p -- $*" 53 | exec mkdir -m "$dirmode" -p -- "$@" 54 | fi ;; 55 | esac 56 | 57 | for file 58 | do 59 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 60 | shift 61 | 62 | pathcomp= 63 | for d 64 | do 65 | pathcomp="$pathcomp$d" 66 | case "$pathcomp" in 67 | -* ) pathcomp=./$pathcomp ;; 68 | esac 69 | 70 | if test ! -d "$pathcomp"; then 71 | echo "mkdir $pathcomp" 72 | 73 | mkdir "$pathcomp" || lasterr=$? 74 | 75 | if test ! -d "$pathcomp"; then 76 | errstatus=$lasterr 77 | else 78 | if test ! -z "$dirmode"; then 79 | echo "chmod $dirmode $pathcomp" 80 | 81 | lasterr="" 82 | chmod "$dirmode" "$pathcomp" || lasterr=$? 83 | 84 | if test ! -z "$lasterr"; then 85 | errstatus=$lasterr 86 | fi 87 | fi 88 | fi 89 | fi 90 | 91 | pathcomp="$pathcomp/" 92 | done 93 | done 94 | 95 | exit $errstatus 96 | 97 | # Local Variables: 98 | # mode: shell-script 99 | # sh-indentation: 3 100 | # End: 101 | # mkinstalldirs ends here 102 | -------------------------------------------------------------------------------- /status.cpp: -------------------------------------------------------------------------------- 1 | // status.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "status.h" 5 | #include "trace.h" 6 | 7 | #include 8 | 9 | using std::string; 10 | using std::flush; 11 | 12 | namespace { 13 | 14 | const size_t width= 7; 15 | 16 | const size_t postext= width * 2 + 1; 17 | 18 | } // namespace 19 | 20 | StatusLine::StatusLine (int ancho, int y) : 21 | ot (1, ancho, y, 0), 22 | invalid (true) 23 | { 24 | TRF; 25 | 26 | ot.inverse (true); 27 | max= ancho - postext; 28 | ot << at (0, 0) << string (ancho, ' ') << flush; 29 | } 30 | 31 | StatusLine::~StatusLine () 32 | { 33 | TRF; 34 | } 35 | 36 | void StatusLine::invalidate () 37 | { 38 | invalid= true; 39 | } 40 | 41 | void StatusLine::refresh () 42 | { 43 | plincol (); 44 | puttext (); 45 | } 46 | 47 | void StatusLine::update () 48 | { 49 | if (invalid) 50 | { 51 | refresh (); 52 | invalid= false; 53 | } 54 | } 55 | 56 | void StatusLine::settext (std::string str) 57 | { 58 | TRFDEB (str); 59 | 60 | size_t l= str.size (); 61 | if (l < max) 62 | str+= string (max - l, ' '); 63 | else if (l > max) 64 | str= str.substr (0, max); 65 | this->str= str; 66 | if (! invalid) 67 | puttext (); 68 | } 69 | 70 | int StatusLine::getkey (const std::string & str) 71 | { 72 | clear (); 73 | ot << at (0, postext) << ' ' << str; 74 | int key= ot.getkey (); 75 | update (); 76 | return key; 77 | } 78 | 79 | void StatusLine::clear () 80 | { 81 | TRF; 82 | 83 | str.assign (max, ' '); 84 | puttext (); 85 | } 86 | 87 | void StatusLine::lincol (int y, int x) 88 | { 89 | this->x= x; this->y= y; 90 | if (! invalid) 91 | { 92 | plincol (); 93 | ot << flush; 94 | } 95 | } 96 | 97 | void StatusLine::plincol () 98 | { 99 | ot << at (0, 0) << std::setw (width) << y + 1 << ' ' << 100 | std::setw (width) << x + 1; 101 | } 102 | 103 | void StatusLine::puttext () 104 | { 105 | TRF; 106 | 107 | ot << at (0, postext) << ' ' << str << flush; 108 | } 109 | 110 | char StatusLine::question (const std::string & q, const std::string & values) 111 | { 112 | TRFDEB (values); 113 | 114 | settext (q); 115 | ot << at (0, postext + 2 + q.size () ); 116 | char c; 117 | do 118 | { 119 | int i= ot.getkey (); 120 | c= (i > 255 | i < 0) ? 0 : static_cast (i); 121 | } while (values.find (c) == std::string::npos); 122 | ot << c << flush; 123 | return c; 124 | } 125 | 126 | // Fin de status.cpp 127 | -------------------------------------------------------------------------------- /menu.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_MENU_H_ 2 | #define INCLUDE_MENU_H_ 3 | 4 | // menu.h 5 | // Revision 29-jan-2006 6 | 7 | #include "termstream.h" 8 | #include "action.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | class Menu; 15 | 16 | class Option { 17 | public: 18 | typedef size_t pos_t; 19 | typedef enum { OptionIsSub, OptionIsAction } TypeOption; 20 | 21 | Option (std::string ntext, Menu * nmenu); 22 | Option (std::string ntext, Action * naction); 23 | ~Option (); 24 | 25 | const std::string & name () const; 26 | void setname (const std::string & newname); 27 | pos_t pos () const; 28 | void pos (pos_t npos); 29 | char charabrev () const; 30 | 31 | TypeOption type () const; 32 | Menu * submenu () const; 33 | Action * getAction () const; 34 | private: 35 | Option (const Option & opt); // Forbidden 36 | Option & operator= (const Option & opt); // Forbidden 37 | 38 | std::string str; 39 | pos_t position; 40 | char abrev; 41 | 42 | TypeOption typeopt; 43 | union UPointer{ 44 | Menu * menu; 45 | Action * action; 46 | UPointer (Menu * m) { menu= m; } 47 | UPointer (Action * a) { action= a; } 48 | } pointer; 49 | std::string parsestr (const std::string & str); 50 | }; 51 | 52 | class Menu { 53 | public: 54 | Menu (); 55 | ~Menu (); 56 | 57 | void addOption (Option * pop); 58 | void insertOption (Option * pop, size_t position); 59 | 60 | bool rename (const std::string & from, const std::string & to); 61 | 62 | Menu * getSubMenu (const std::string & name); 63 | void show (); 64 | void show (otermstream & ots); 65 | Action * selectoption (otermstream & ots); 66 | private: 67 | Menu (const Menu &); // Forbidden 68 | void operator= (const Menu &); // Forbidden 69 | otermstream * pot; 70 | class MenuOption { 71 | public: 72 | MenuOption (Option * poption); 73 | ~MenuOption (); 74 | void erase (); 75 | std::string name () const; 76 | void setname (const std::string & newname); 77 | Option::pos_t pos () const; 78 | void pos (Option::pos_t npos); 79 | char charabrev () const; 80 | Option::TypeOption type () const; 81 | Menu * submenu () const; 82 | Action * getAction () const; 83 | private: 84 | Option * poption; 85 | }; 86 | std::vector options; 87 | size_t width; 88 | std::string clear; 89 | size_t inipos; 90 | size_t numopts; 91 | static const size_t NO_SEL= size_t (-1); 92 | size_t active; 93 | 94 | Action * do_selectoption (otermstream & ots); 95 | void calcpositions (); 96 | void auxputopt (size_t nopt); 97 | void putopt (size_t nopt); 98 | void putall (); 99 | void setactive (size_t newactive); 100 | Action * activate (size_t n, otermstream & ots); 101 | }; 102 | 103 | #endif 104 | 105 | // Fin de menu.h 106 | -------------------------------------------------------------------------------- /trace.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TRACE_H 2 | #define INCLUDE_TRACE_H 3 | 4 | // trace.h 5 | // Revision 30-jan-2006 6 | 7 | #include "config_debug.h" 8 | #include "config_function.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | class TraceFunc { 15 | public: 16 | TraceFunc (const char * filename, size_t linenum, 17 | const char * funcname_n= 0, const char * shortname_n= 0); 18 | ~TraceFunc (); 19 | void message (const std::string & text); 20 | static void show (int); 21 | private: 22 | const char * funcname; 23 | const char * shortname; 24 | TraceFunc * * previous; 25 | TraceFunc * next; 26 | }; 27 | 28 | 29 | #ifndef NDEBUG 30 | 31 | #include 32 | 33 | #define TRFUNC(tr,name) \ 34 | TraceFunc tr (__FILE__, __LINE__, name) 35 | #define TRMESSAGE(tr,text) \ 36 | tr.message (text) 37 | #define TRSTREAM(tr,text) \ 38 | { \ 39 | std::ostringstream oss; \ 40 | oss << text; \ 41 | tr.message (oss.str () ); \ 42 | } 43 | 44 | #ifdef HAVE_FUNCTION 45 | 46 | #ifdef HAVE_PRETTY_FUNCTION 47 | #define TRF \ 48 | TraceFunc tracefunc_obj (__FILE__, __LINE__, \ 49 | __PRETTY_FUNCTION__, __FUNCTION__) 50 | #define TRFDEB(text) \ 51 | TraceFunc tracefunc_obj (__FILE__, __LINE__, \ 52 | __PRETTY_FUNCTION__, __FUNCTION__); \ 53 | tracefunc_obj.message (text) 54 | #define TRFDEBS(tex) \ 55 | TraceFunc tracefunc_obj (__FILE__, __LINE__, \ 56 | __PRETTY_FUNCTION__, __FUNCTION__); \ 57 | { \ 58 | std::ostringstream oss; \ 59 | oss << tex; \ 60 | tracefunc_obj.message (oss.str () ); \ 61 | } 62 | #else 63 | #define TRF \ 64 | TraceFunc tracefunc_obj (__FILE, __LINE__, __FUNCTION__) 65 | #define TRFDEB(text) \ 66 | TraceFunc tracefunc_obj (__FILE__, __LINE__, __FUNCTION__); \ 67 | tracefunc_obj.message (text) 68 | #define TRFDEBS(tex) \ 69 | TraceFunc tracefunc_obj (__FILE__, __LINE__, __FUNCTION__); \ 70 | { \ 71 | std::ostringstream oss; \ 72 | oss << tex; \ 73 | tracefunc_obj.message (oss.str () ); \ 74 | } 75 | #endif 76 | 77 | #else 78 | 79 | #define TRF \ 80 | TraceFunc tracefunc_obj (__FILE__, __LINE__) 81 | #define TRFDEB(text) \ 82 | TraceFunc tracefunc_obj (__FILE__, __LINE__); \ 83 | tracefunc_obj.message (text) 84 | #define TRFDEBS(tex) \ 85 | TraceFunc tracefunc_obj (__FILE__, __LINE__); \ 86 | { \ 87 | std::ostringstream oss; \ 88 | oss << tex; \ 89 | tracefunc_obj.message (oss.str () ); \ 90 | } 91 | 92 | #endif 93 | 94 | #define TRDEB(text) \ 95 | tracefunc_obj.message (text) 96 | 97 | #define TRDEBS(tex) \ 98 | { \ 99 | std::ostringstream oss; \ 100 | oss << tex; \ 101 | tracefunc_obj.message (oss.str () ); \ 102 | } 103 | 104 | 105 | void trace_assertion_failed (const char * a, const char * file, size_t line); 106 | 107 | #define ASSERT(a) \ 108 | if (a) ; \ 109 | else trace_assertion_failed (#a, __FILE__, __LINE__) 110 | 111 | 112 | #else 113 | 114 | 115 | #define TRFUNC(tr,name) 116 | #define TRMESSAGE(tr,text) 117 | #define TRSTREAM(tr,text) 118 | 119 | #define TRF 120 | #define TRFDEB(text) 121 | #define TRFDEBS(tex) 122 | #define TRDEB(text) 123 | #define TRDEBS(tex) 124 | 125 | #define ASSERT(a) 126 | 127 | 128 | #endif 129 | 130 | 131 | #endif 132 | 133 | // Fin de trace.h 134 | -------------------------------------------------------------------------------- /screenbase.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SCREENBASE_H 2 | #define INCLUDE_SCREENBASE_H 3 | 4 | // screenbase.h 5 | // Revision 25-jan-2006 6 | 7 | #include "screen.h" 8 | 9 | #include "termstream.h" 10 | #include "text.h" 11 | #include "menu.h" 12 | #include "status.h" 13 | #include "history.h" 14 | 15 | #include 16 | #include 17 | 18 | //*********************************************** 19 | // ScreenBase 20 | //*********************************************** 21 | 22 | class ScreenBase : public Screen 23 | { 24 | protected: 25 | ScreenBase (bool useuft8); 26 | virtual ~ScreenBase (); 27 | 28 | void set_text_inited (); 29 | 30 | otermstream & get_textwindow (); 31 | 32 | void mainwindow_clrscr (); 33 | 34 | void screen_invalidate (); 35 | virtual void invalidate_all_lines ()= 0; 36 | virtual void update_lines ()= 0; 37 | public: 38 | void textwindow_invalidate (); 39 | protected: 40 | bool usingutf8 () const; 41 | void textwindow_update (); 42 | bool setmode (int n); 43 | int getkey (); 44 | int checkkey (); 45 | //size_t maxlin () const; 46 | //Col maxcol () const; 47 | size_t lines (); 48 | size_t columns (); 49 | void textwindow_at (size_t lin, Col col= Col () ); 50 | void textwindow_clreol (); 51 | void textwindow_inverse (bool flag); 52 | void textwindow_insline (); 53 | void textwindow_delline (); 54 | void outchar (char c); 55 | void outstring (const std::string & str); 56 | 57 | size_t selector (const std::string & title, 58 | const std::vector & vstr); 59 | 60 | void dialog_show_text (const char * title, const char * str, 61 | int height, int width); 62 | bool dialog_get_string ( 63 | int & keyend, const std::set & keyender, 64 | const std::string & title, const std::string & prompt, 65 | std::string & str, History & history, 66 | size_t width, 67 | std::string::size_type maxlength= std::string::npos); 68 | bool dialog_get_string ( 69 | const std::string & title, const std::string & prompt, 70 | std::string & str, History & history, 71 | size_t width, 72 | std::string::size_type maxlength= std::string::npos); 73 | enum dialog_result { dialog_cancel, dialog_yes, dialog_no }; 74 | dialog_result dialog_question (const std::string & str); 75 | 76 | typedef std::vector > vdopts_t; 77 | bool dialog_options (const std::string & title, vdopts_t vdopts); 78 | 79 | void menu_invalidate (); 80 | void menu_update (); 81 | public: 82 | void menu_add_option (Option * popt); 83 | protected: 84 | void menu_insert_option (Option * pop, size_t position); 85 | bool menu_insert_suboption (const std::string & submenuname, 86 | Option * pop, size_t position); 87 | bool menu_rename (const std::string & from, const std::string & to); 88 | public: 89 | void menu_select (); 90 | 91 | protected: 92 | void status_invalidate (); 93 | void status_update (); 94 | virtual void status_current_lincol ()= 0; 95 | void status_lincol (size_t lin, Col col); 96 | void status_clear (); 97 | void setstatus (const std::string & str); 98 | public: 99 | int statusgetkey (const std::string & str); 100 | protected: 101 | char status_question 102 | (const std::string & q, const std::string & values); 103 | 104 | void perlfunchelp_set (const char * func, const char * helptext); 105 | void perlfunchelp_show (); 106 | public: 107 | void update (); 108 | private: 109 | otermstream mainwindow; 110 | otermstream textwindow; 111 | Menu menu; 112 | otermstream menuwindow; 113 | StatusLine status; 114 | bool flagutf8; 115 | bool text_inited; 116 | bool redraw_text_window; 117 | bool redraw_menu; 118 | 119 | typedef std::map perlfunchelp_t; 120 | perlfunchelp_t perlfunchelp; 121 | 122 | void menu_show (); 123 | }; 124 | 125 | #endif 126 | 127 | // End of screenbase.h 128 | -------------------------------------------------------------------------------- /qperl.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_QPERL_H_ 2 | #define INCLUDE_QPERL_H_ 3 | 4 | /* 5 | qperl.h 6 | Revision 29-jan-2005 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | int qperl_init (char * * env, void * data); 14 | void qperl_init_done (); 15 | void qperl_destroy (void); 16 | 17 | typedef enum { 18 | qpMode, 19 | qpIsEmpty, qpGetModified, qpSetModified, 20 | qpUp, qpDown, qpLeft, qpRight, 21 | qpHome, qpEnd, qpPageUp, qpPageDown, 22 | qpGotoLine, 23 | qpGetChar, qpGetWord, 24 | qpDeleteChar, qpBackspace, 25 | qpDeleteLine, qpReplaceLine, 26 | qpInsertChar, qpInsert, 27 | 28 | qpGetSelection, qpSelectionLimits, 29 | qpSelect, qpBeginSelect, qpEndSelect, 30 | qpSelectAll, qpDeleteSelection, 31 | 32 | qpGetClipboard, 33 | qpSetClipboard, 34 | qpCut, qpCopy, qpPaste, 35 | 36 | qpLine, qpNumLines, qpCharLine, 37 | qpGetLine, qpGetPos, qpGetCol, 38 | qpGetFileExt, qpGetFileName, 39 | qpStatus, qpStatusQuestion, 40 | qpDialogGetString, qpDialogShowText, 41 | qpDefineControl, 42 | qpRedraw, qpQuiet, qpUpdate, 43 | qpGetKey, 44 | qpSetAutoindent, qpGetAutoindent, qpSetAutocr, qpGetAutocr, 45 | 46 | qpMenuAdd, qpMenuAddOption, qpMenuRename, 47 | 48 | /* qpWindowNew, qpWindowNext, qpWindowClose, */ 49 | 50 | qpFileLoad, qpFileNew, qpFileSave, qpFileSaveAs, 51 | qpFileNext, qpFileClose, qpFileQuit, 52 | qpHelpAddFunc, 53 | qpMacro, 54 | qpFreeString, 55 | qpCopyNewFile, 56 | 57 | qpHelp, qpHelpPerl, qpHelpAbout, 58 | 59 | qpCompile, qpMake, qpCompileOptions, qpMan, qpManOf, 60 | 61 | /* Do not insert new function codes after here */ 62 | 63 | qpFailTest, qpLastFuncCode= qpFailTest 64 | } qpFuncCode; 65 | 66 | typedef enum { 67 | qpRetOk= 0, 68 | qpRetFailed, 69 | qpRetInvalidFunc, 70 | qpRetInvalidValue, 71 | qpRetTrue, 72 | qpRetFalse, 73 | qpRetUnexpected= -1 74 | } qpRetCode; 75 | 76 | const char * nameqpFunc (qpFuncCode n); 77 | 78 | typedef struct { 79 | char * str; 80 | size_t len; 81 | } qpStringParam; 82 | 83 | typedef struct { 84 | int beginline; 85 | int beginpos; 86 | int endline; 87 | int endpos; 88 | } qpSelectionLimitsParam; 89 | 90 | typedef struct { 91 | const char * question; 92 | const char * values; 93 | char result; 94 | } qpStatusQuestionParam; 95 | 96 | typedef struct { 97 | const char * title; 98 | const char * prompt; 99 | char * str; 100 | unsigned int width; 101 | unsigned int maxlength; 102 | } qpDialogGetStringParam; 103 | 104 | typedef struct { 105 | const char * title; 106 | const char * str; 107 | unsigned int height; 108 | unsigned int width; 109 | } qpDialogShowTextParam; 110 | 111 | typedef struct { 112 | char key; 113 | const char * function; 114 | } qpDefineControlParam; 115 | 116 | typedef struct { 117 | int position; 118 | const char * menuname; 119 | } qpMenuAddParam; 120 | 121 | typedef struct { 122 | const char * menuname; 123 | int position; 124 | const char * optionname; 125 | const char * perlfunc; 126 | } qpMenuAddOptionParam; 127 | 128 | typedef struct { 129 | const char * from; 130 | const char * to; 131 | } qpMenuRenameParam; 132 | 133 | typedef struct { 134 | const char * func; 135 | const char * desc; 136 | } qpHelpAddFuncParam; 137 | 138 | qpRetCode qpCallback (void *, qpFuncCode, int n, void *); 139 | 140 | typedef enum { qpfunction_notfound, qpfunction_failed, qpfunction_ok } 141 | qpfunctionresult; 142 | 143 | qpfunctionresult qperl_function (const char * function, void * data); 144 | qpfunctionresult qperl_function_args (const char * function, void * data, 145 | int argc, const char * const * argv); 146 | qpfunctionresult qperl_function_args_r (const char * function, void * data, 147 | int argc, const char * const * argv, char * * result); 148 | 149 | void qperl_free_str (char * str); 150 | 151 | int qperl_eval (const char * str, void * data); 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | #endif 158 | 159 | /* Fin de qperl.h */ 160 | -------------------------------------------------------------------------------- /trace.cpp: -------------------------------------------------------------------------------- 1 | // trace.cpp 2 | // Revision 29-jan-2006 3 | 4 | #include "trace.h" 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | using std::cerr; 18 | using std::endl; 19 | using std::ostream; 20 | using std::ofstream; 21 | using std::string; 22 | using std::find; 23 | 24 | 25 | namespace { 26 | 27 | 28 | ostream * pout= 0; 29 | bool flag= true; 30 | size_t indent= 0; 31 | 32 | TraceFunc * initial= NULL; 33 | TraceFunc * * lastpos= & initial; 34 | 35 | ostream * opentracefile (const char * filename) 36 | { 37 | std::ofstream * pof= 38 | new ofstream (filename, std::ios::app | std::ios::out); 39 | if (! pof->is_open () ) 40 | { 41 | cerr << "Error opening " << filename << endl; 42 | delete pof; 43 | pof= 0; 44 | } 45 | return pof; 46 | } 47 | 48 | string traceindent () 49 | { 50 | //return string (indent / 8, '\t') + string (indent % 8, ' '); 51 | return string (indent, ' '); 52 | } 53 | 54 | void showinfo (const char * enterexit, const char * funcname) 55 | { 56 | * pout << traceindent () << enterexit << ' '; 57 | 58 | if (std::uncaught_exception () ) 59 | * pout << "(throwing) "; 60 | 61 | * pout << funcname; 62 | } 63 | 64 | void showenterinfo (const char * funcname, 65 | const char * filename, size_t linenum) 66 | { 67 | if (pout) 68 | { 69 | showinfo ("Enter", funcname); 70 | * pout << " in " << filename << " at " << linenum << endl; 71 | } 72 | } 73 | 74 | void showexitinfo (const char * funcname) 75 | { 76 | if (pout) 77 | { 78 | showinfo ("Exit", funcname); 79 | * pout << endl; 80 | } 81 | } 82 | 83 | const char BAD_USE []= "Bad use of TraceFunc"; 84 | 85 | 86 | } // namespace 87 | 88 | 89 | TraceFunc::TraceFunc (const char * filename, size_t linenum, 90 | const char * funcname_n, const char * shortname_n) : 91 | funcname (funcname_n ? funcname_n : "[unknown]"), 92 | shortname (shortname_n ? shortname_n : funcname_n), 93 | next (NULL) 94 | { 95 | if (flag) 96 | { 97 | flag= false; 98 | char * aux= getenv ("TRFILE"); 99 | if (aux) 100 | { 101 | if (strcmp (aux, "-") == 0) 102 | pout= & std::cerr; 103 | else 104 | pout= opentracefile (aux); 105 | } 106 | } 107 | 108 | previous= lastpos; 109 | * lastpos= this; 110 | lastpos= & next; 111 | 112 | //showinfo ("Enter", funcname, filename, linenum); 113 | showenterinfo (funcname, filename, linenum); 114 | ++indent; 115 | } 116 | 117 | TraceFunc::~TraceFunc () 118 | { 119 | --indent; 120 | 121 | //showinfo ("Exit", funcname, filename, linenum); 122 | showexitinfo (funcname); 123 | 124 | if (next != NULL) 125 | { 126 | cerr << BAD_USE << endl; 127 | abort (); 128 | } 129 | if (lastpos != & next) 130 | { 131 | cerr << BAD_USE << endl; 132 | abort (); 133 | } 134 | lastpos= previous; 135 | if (* lastpos != this) 136 | { 137 | cerr << BAD_USE << endl; 138 | abort (); 139 | } 140 | * lastpos= NULL; 141 | } 142 | 143 | void TraceFunc::message (const std::string & text) 144 | { 145 | if (pout) 146 | { 147 | * pout << traceindent () << shortname; 148 | 149 | if (std::uncaught_exception () ) 150 | * pout << "(throwing) "; 151 | 152 | * pout << ": " << text << endl; 153 | } 154 | } 155 | 156 | void TraceFunc::show (int) 157 | { 158 | cerr << "\r\n"; 159 | 160 | if (initial == NULL) 161 | cerr << "TraceFunc: no calls."; 162 | else 163 | { 164 | cerr << "TraceFunc dump of calls: \r\n"; 165 | for (TraceFunc * act= initial; act != NULL; act= act->next) 166 | cerr << act->funcname << "\r\n"; 167 | cerr << "TraceFunc dump ended."; 168 | } 169 | cerr << "\r\n"; 170 | } 171 | 172 | void trace_assertion_failed (const char * a, const char * file, size_t line) 173 | { 174 | std::ostringstream oss; 175 | oss << "Assertion failed: '" << a << "' in file " << file << 176 | " line " << line; 177 | throw std::logic_error (oss.str () ); 178 | } 179 | 180 | 181 | // Fin de trace.cpp 182 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand `-c -o'. 3 | 4 | scriptversion=2005-02-03.08 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | case $1 in 33 | '') 34 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35 | exit 1; 36 | ;; 37 | -h | --h*) 38 | cat <<\EOF 39 | Usage: compile [--help] [--version] PROGRAM [ARGS] 40 | 41 | Wrapper for compilers which do not understand `-c -o'. 42 | Remove `-o dest.o' from ARGS, run PROGRAM with the remaining 43 | arguments, and rename the output as expected. 44 | 45 | If you are trying to build a whole package this is not the 46 | right script to run: please start by reading the file `INSTALL'. 47 | 48 | Report bugs to . 49 | EOF 50 | exit $? 51 | ;; 52 | -v | --v*) 53 | echo "compile $scriptversion" 54 | exit $? 55 | ;; 56 | esac 57 | 58 | ofile= 59 | cfile= 60 | eat= 61 | 62 | for arg 63 | do 64 | if test -n "$eat"; then 65 | eat= 66 | else 67 | case $1 in 68 | -o) 69 | # configure might choose to run compile as `compile cc -o foo foo.c'. 70 | # So we strip `-o arg' only if arg is an object. 71 | eat=1 72 | case $2 in 73 | *.o | *.obj) 74 | ofile=$2 75 | ;; 76 | *) 77 | set x "$@" -o "$2" 78 | shift 79 | ;; 80 | esac 81 | ;; 82 | *.c) 83 | cfile=$1 84 | set x "$@" "$1" 85 | shift 86 | ;; 87 | *) 88 | set x "$@" "$1" 89 | shift 90 | ;; 91 | esac 92 | fi 93 | shift 94 | done 95 | 96 | if test -z "$ofile" || test -z "$cfile"; then 97 | # If no `-o' option was seen then we might have been invoked from a 98 | # pattern rule where we don't need one. That is ok -- this is a 99 | # normal compilation that the losing compiler can handle. If no 100 | # `.c' file was seen then we are probably linking. That is also 101 | # ok. 102 | exec "$@" 103 | fi 104 | 105 | # Name of file we expect compiler to create. 106 | cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107 | 108 | # Create the lock directory. 109 | # Note: use `[/.-]' here to ensure that we don't use the same name 110 | # that we are using for the .o file. Also, base the name on the expected 111 | # object file name, since that is what matters with a parallel build. 112 | lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113 | while true; do 114 | if mkdir "$lockdir" >/dev/null 2>&1; then 115 | break 116 | fi 117 | sleep 1 118 | done 119 | # FIXME: race condition here if user kills between mkdir and trap. 120 | trap "rmdir '$lockdir'; exit 1" 1 2 15 121 | 122 | # Run the compile. 123 | "$@" 124 | ret=$? 125 | 126 | if test -f "$cofile"; then 127 | mv "$cofile" "$ofile" 128 | elif test -f "${cofile}bj"; then 129 | mv "${cofile}bj" "$ofile" 130 | fi 131 | 132 | rmdir "$lockdir" 133 | exit $ret 134 | 135 | # Local Variables: 136 | # mode: shell-script 137 | # sh-indentation: 2 138 | # eval: (add-hook 'write-file-hooks 'time-stamp) 139 | # time-stamp-start: "scriptversion=" 140 | # time-stamp-format: "%:y-%02m-%02d.%02H" 141 | # time-stamp-end: "$" 142 | # End: 143 | -------------------------------------------------------------------------------- /select.cpp: -------------------------------------------------------------------------------- 1 | // select.cpp 2 | // Revision 29-jan-2006 3 | 4 | #include "select.h" 5 | #include "qtreassert.h" 6 | 7 | namespace { 8 | 9 | class Select { 10 | public: 11 | Select (otermstream & ot, const std::string & title, 12 | const std::vector & vstr); 13 | ~Select (); 14 | size_t doit (); 15 | private: 16 | std::string title; 17 | const std::vector & vstr; 18 | const size_t n; 19 | otermstream * pot; 20 | size_t elem; 21 | size_t width; 22 | size_t lines; 23 | size_t first; 24 | size_t actual; 25 | size_t maxline; 26 | size_t maxfirst; 27 | 28 | void putall (); 29 | void put (size_t i); 30 | }; 31 | 32 | Select::Select (otermstream & ot, const std::string & title, 33 | const std::vector & vstr) : 34 | vstr (vstr), 35 | n (vstr.size () ), 36 | pot (0), 37 | first (0), 38 | actual (0) 39 | { 40 | ASSERT (n > 0); 41 | lines= vstr.size () ; 42 | if (lines > size_t (ot.lines () ) - 2) 43 | lines= ot.lines () - 2; 44 | width= title.size (); 45 | for (size_t i= 0; i < n; ++i) 46 | if (vstr [i].size () > width) 47 | width= vstr [i].size (); 48 | if (width > size_t (ot.columns () ) - 2) 49 | width= ot.columns () - 2; 50 | elem= vstr.size (); 51 | if (elem > lines) 52 | elem= lines; 53 | maxline= vstr.size () - 1; 54 | maxfirst= maxline - lines + 1; 55 | 56 | this->title= title.substr (0, width); 57 | pot= new otermstream (ot, lines + 2, width + 2, 58 | (ot.lines () - lines - 2) / 2, 59 | (ot.columns () - width - 2) / 2); 60 | pot->cursor (false); 61 | } 62 | 63 | Select::~Select () 64 | { 65 | pot->cursor (true); 66 | delete pot; 67 | } 68 | 69 | namespace { 70 | 71 | char firstchar (const std::string & str) 72 | { 73 | if (str.empty () ) 74 | return '\0'; 75 | return str [0]; 76 | } 77 | 78 | } // namespace 79 | 80 | size_t Select::doit () 81 | { 82 | using namespace key; 83 | 84 | pot->clrscr (); 85 | pot->border (); 86 | * pot << at (0, 1 + (width - title.size () ) / 2) << title; 87 | 88 | putall (); 89 | 90 | for (;;) 91 | { 92 | size_t ant= actual; 93 | size_t antfirst= first; 94 | int k= pot->getkey (); 95 | switch (k) 96 | { 97 | case '\r': case '\n': 98 | return actual; 99 | case Esc: case F8: 100 | return size_t (-1); 101 | case Down: 102 | if (actual < vstr.size () - 1) 103 | ++actual; 104 | break; 105 | case Up: 106 | if (actual > 0) 107 | --actual; 108 | break; 109 | case PageUp: 110 | if (first > lines - 1) 111 | first-= lines - 1; 112 | else 113 | first= 0; 114 | if (actual > lines - 1) 115 | actual-= lines - 1; 116 | else 117 | actual= 0; 118 | break; 119 | case PageDown: 120 | first+= lines - 1; 121 | if (first > maxfirst) 122 | first= maxfirst; 123 | actual+= lines - 1; 124 | if (actual > maxline) 125 | actual= maxline; 126 | break; 127 | case Home: 128 | actual= 0; 129 | first= 0; 130 | break; 131 | case End: 132 | actual= maxline; 133 | first= maxfirst; 134 | break; 135 | default: 136 | if (k <= 0 || k > 255) 137 | break; 138 | for (size_t i= actual + 1, l= vstr.size (); i < l; ++i) 139 | if (firstchar (vstr [i] ) == k) 140 | { 141 | actual= i; 142 | break; 143 | } 144 | } 145 | if (actual >= first + lines) 146 | first= actual - lines + 1; 147 | if (actual < first) 148 | first= actual; 149 | if (first != antfirst) 150 | putall (); 151 | else 152 | if (ant != actual) 153 | { 154 | put (ant); 155 | put (actual); 156 | } 157 | } 158 | } 159 | 160 | void Select::putall () 161 | { 162 | for (size_t i= first, end= first + lines; i < end; ++i) 163 | { 164 | if (i < vstr.size () ) 165 | { 166 | put (i); 167 | } 168 | else 169 | * pot << at (i - first + 1, 1) << 170 | std::string (' ', width); 171 | } 172 | pot->flush (); 173 | } 174 | 175 | void Select::put (size_t i) 176 | { 177 | if (i == actual) 178 | * pot << inverse (true); 179 | std::string str (vstr [i].substr (0, width) ); 180 | if (str.size () < width) 181 | str+= std::string (width - str.size (), ' '); 182 | * pot << at (i - first + 1, 1) << str; 183 | if (i == actual) 184 | * pot << inverse (false); 185 | } 186 | 187 | } // namespace 188 | 189 | size_t selectlist (otermstream & ot, const std::string & title, 190 | const std::vector & vstr) 191 | { 192 | Select s (ot, title, vstr); 193 | return s.doit (); 194 | } 195 | 196 | // End of select.cpp 197 | -------------------------------------------------------------------------------- /exec.cpp: -------------------------------------------------------------------------------- 1 | // exec.cpp 2 | // Revision 29-jan-2006 3 | 4 | #include "exec.h" 5 | 6 | #include "trace.h" 7 | 8 | #include "config_types.h" 9 | #include "config_fork.h" 10 | #include "config_wait.h" 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | //*********************************************** 22 | // Exec::Impl 23 | //*********************************************** 24 | 25 | class Exec::Impl 26 | { 27 | public: 28 | Impl (Exec & exec); 29 | ~Impl (); 30 | void Command (const std::string & strCommand); 31 | private: 32 | Impl (const Impl &); // Forbidden 33 | void operator = (const Impl &); // Forbidden 34 | 35 | void killchild (); 36 | bool createchild (const std::string & strCommand); 37 | void readfromchild (); 38 | 39 | Exec & exec; 40 | int hchild; 41 | pid_t pidchild; 42 | 43 | static const int h_none= -1; 44 | static const pid_t pid_none= static_cast (-1); 45 | }; 46 | 47 | Exec::Impl::Impl (Exec & exec) : 48 | exec (exec), 49 | hchild (h_none), 50 | pidchild (pid_none) 51 | { 52 | } 53 | 54 | Exec::Impl::~Impl () 55 | { 56 | killchild (); 57 | } 58 | 59 | void Exec::Impl::killchild () 60 | { 61 | if (pidchild != pid_none) 62 | { 63 | kill (pidchild, SIGTERM); 64 | pidchild= pid_none; 65 | } 66 | if (hchild != h_none) 67 | { 68 | close (hchild); 69 | hchild= h_none; 70 | } 71 | } 72 | 73 | bool Exec::Impl::createchild (const std::string & strCommand) 74 | { 75 | TRF; 76 | 77 | // If any previous child exist, kill it. 78 | killchild (); 79 | 80 | int handle [2]; 81 | if (pipe (handle) != 0) 82 | { 83 | TRDEB ("Error en pipe"); 84 | return false; 85 | } 86 | 87 | pid_t child= vfork (); 88 | switch (child) 89 | { 90 | case pid_t (0): 91 | // Child 92 | close (handle [0] ); 93 | dup2 (handle [1], STDOUT_FILENO); 94 | dup2 (handle [1], STDERR_FILENO); 95 | close (handle [1] ); 96 | { 97 | const char * strShell; 98 | strShell= getenv ("SHELL"); 99 | if (! strShell) 100 | strShell= "/bin/sh"; 101 | execlp (strShell, strShell, 102 | "-c", strCommand.c_str (), 103 | static_cast (0) ); 104 | } 105 | TRDEB ("Error en execlp"); 106 | exit (1); 107 | return false; 108 | case pid_t (-1): 109 | // Error 110 | TRDEB ("Error en fork"); 111 | close (handle [0] ); 112 | close (handle [1] ); 113 | return false; 114 | default: 115 | hchild= handle [0]; 116 | close (handle [1] ); 117 | pidchild= child; 118 | return true; 119 | } 120 | } 121 | 122 | void Exec::Impl::readfromchild () 123 | { 124 | TRF; 125 | 126 | // Put the handle in non blocking mode. 127 | { 128 | int r= fcntl 129 | (hchild, F_SETFL, static_cast (O_NONBLOCK) ); 130 | if (r != 0) 131 | { 132 | TRDEB (strerror (errno) ); 133 | } 134 | } 135 | 136 | const size_t bufsize= 1024; 137 | char buffer [bufsize]; 138 | bool aborted= false; 139 | 140 | for (;;) 141 | { 142 | TRDEB ("Reading from child"); 143 | size_t r= read (hchild, buffer, bufsize); 144 | if (r == 0) 145 | { 146 | TRDEB ("End of child"); 147 | break; 148 | } 149 | TRDEB ("Read done"); 150 | 151 | if (r == size_t (-1) ) 152 | { 153 | if (errno == EAGAIN) 154 | { 155 | r= 0; 156 | sleep (1); 157 | } 158 | else 159 | { 160 | TRDEB ("Error en read"); 161 | break; 162 | } 163 | } 164 | 165 | if (r > 0) 166 | { 167 | // Try to send block, if rejected 168 | // send char by char. 169 | if (! exec.ExecSendBlock (buffer, r) ) 170 | { 171 | for (size_t i= 0; i < r; ++i) 172 | exec.ExecSendChar (buffer [i] ); 173 | } 174 | } 175 | 176 | if (exec.ExecQueryAbort () ) 177 | { 178 | aborted= true; 179 | break; 180 | } 181 | } 182 | 183 | close (hchild); 184 | hchild= h_none; 185 | 186 | if (aborted) 187 | { 188 | TRDEB ("Killing child"); 189 | kill (pidchild, SIGTERM); 190 | } 191 | 192 | TRDEB ("Waiting for child"); 193 | waitpid (pidchild, 0, 0); 194 | 195 | pidchild= pid_none; 196 | } 197 | 198 | void Exec::Impl::Command (const std::string & strCommand) 199 | { 200 | TRF; 201 | 202 | if (createchild (strCommand) ) 203 | readfromchild (); 204 | } 205 | 206 | //*********************************************** 207 | // Exec 208 | //*********************************************** 209 | 210 | Exec::Exec () : 211 | pi (new Impl (* this) ) 212 | { 213 | } 214 | 215 | Exec::~Exec () 216 | { 217 | delete pi; 218 | } 219 | 220 | bool Exec::ExecSendBlock (const char * /*str*/, size_t /*size*/) 221 | { 222 | return false; 223 | } 224 | 225 | bool Exec::ExecQueryAbort () 226 | { 227 | return false; 228 | } 229 | 230 | void Exec::Command (const std::string & strCommand) 231 | { 232 | TRF; 233 | 234 | pi->Command (strCommand); 235 | } 236 | 237 | // Fin de exec.cpp 238 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if the `closedir' function returns void instead of `int'. */ 4 | #undef CLOSEDIR_VOID 5 | 6 | /* Directory for qtre.pl */ 7 | #undef CONFIG_DIR 8 | 9 | /* Number of parameters for filebuf constructor */ 10 | #undef FILEBUF_PARAMS 11 | 12 | /* Define to 1 if you have the header file, and it defines `DIR'. 13 | */ 14 | #undef HAVE_DIRENT_H 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #undef HAVE_EXT_STDIO_FILEBUF_H 18 | 19 | /* Define to 1 if you have the `fork' function. */ 20 | #undef HAVE_FORK 21 | 22 | /* Has __FUNCTION__ */ 23 | #undef HAVE_FUNCTION 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #undef HAVE_INTTYPES_H 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #undef HAVE_LANGINFO_H 30 | 31 | /* Define to 1 if you have the `ncurses' library (-lncurses). */ 32 | #undef HAVE_LIBNCURSES 33 | 34 | /* Define to 1 if you have the `ncursesw' library (-lncursesw). */ 35 | #undef HAVE_LIBNCURSESW 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #undef HAVE_LOCALE_H 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #undef HAVE_MEMORY_H 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #undef HAVE_NCURSESW_NCURSES_H 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #undef HAVE_NCURSES_H 48 | 49 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 50 | #undef HAVE_NDIR_H 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #undef HAVE_NL_TYPES_H 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_OSTREAM 57 | 58 | /* Has __PRETTY_FUNCTION__ */ 59 | #undef HAVE_PRETTY_FUNCTION 60 | 61 | /* Define to 1 if `stat' has the bug that it succeeds when given the 62 | zero-length file name argument. */ 63 | #undef HAVE_STAT_EMPTY_STRING_BUG 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #undef HAVE_STDINT_H 67 | 68 | /* Define to 1 if you have the header file. */ 69 | #undef HAVE_STDLIB_H 70 | 71 | /* Define to 1 if you have the header file. */ 72 | #undef HAVE_STREAMBUF 73 | 74 | /* Define to 1 if you have the header file. */ 75 | #undef HAVE_STREAMBUF_H 76 | 77 | /* Define to 1 if you have the header file. */ 78 | #undef HAVE_STRINGS_H 79 | 80 | /* Define to 1 if you have the header file. */ 81 | #undef HAVE_STRING_H 82 | 83 | /* Define to 1 if you have the header file, and it defines `DIR'. 84 | */ 85 | #undef HAVE_SYS_DIR_H 86 | 87 | /* Define to 1 if you have the header file, and it defines `DIR'. 88 | */ 89 | #undef HAVE_SYS_NDIR_H 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #undef HAVE_SYS_STAT_H 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #undef HAVE_SYS_TYPES_H 96 | 97 | /* Define to 1 if you have that is POSIX.1 compatible. */ 98 | #undef HAVE_SYS_WAIT_H 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #undef HAVE_UNISTD_H 102 | 103 | /* Define to 1 if you have the `vfork' function. */ 104 | #undef HAVE_VFORK 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #undef HAVE_VFORK_H 108 | 109 | /* Define to 1 if `fork' works. */ 110 | #undef HAVE_WORKING_FORK 111 | 112 | /* Define to 1 if `vfork' works. */ 113 | #undef HAVE_WORKING_VFORK 114 | 115 | /* Define to 1 if `lstat' dereferences a symlink specified with a trailing 116 | slash. */ 117 | #undef LSTAT_FOLLOWS_SLASHED_SYMLINK 118 | 119 | /* Not in debug mode */ 120 | #undef NDEBUG 121 | 122 | /* Name of package */ 123 | #undef PACKAGE 124 | 125 | /* Define to the address where bug reports for this package should be sent. */ 126 | #undef PACKAGE_BUGREPORT 127 | 128 | /* Define to the full name of this package. */ 129 | #undef PACKAGE_NAME 130 | 131 | /* Define to the full name and version of this package. */ 132 | #undef PACKAGE_STRING 133 | 134 | /* Define to the one symbol short name of this package. */ 135 | #undef PACKAGE_TARNAME 136 | 137 | /* Define to the version of this package. */ 138 | #undef PACKAGE_VERSION 139 | 140 | /* Define to 1 if you have the ANSI C header files. */ 141 | #undef STDC_HEADERS 142 | 143 | /* Version number of package */ 144 | #undef VERSION 145 | 146 | /* Define to `int' if doesn't define. */ 147 | #undef gid_t 148 | 149 | /* Define to `int' if does not define. */ 150 | #undef mode_t 151 | 152 | /* Define to `int' if does not define. */ 153 | #undef pid_t 154 | 155 | /* Define to `int' if doesn't define. */ 156 | #undef uid_t 157 | 158 | /* Define as `fork' if `vfork' does not work. */ 159 | #undef vfork 160 | -------------------------------------------------------------------------------- /text.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TEXT_H_ 2 | #define INCLUDE_TEXT_H_ 3 | 4 | // text.h 5 | // Revision 29-jan-2006 6 | 7 | #include "textline.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | class PosText { 18 | public: 19 | PosText () : lin (0), pos (0) { } 20 | PosText (size_t nlin, size_t npos) : lin (nlin), pos (npos) { } 21 | size_t lin, pos; 22 | bool operator < (const PosText &pt) const 23 | { 24 | if (lin < pt.lin) 25 | return true; 26 | if (lin == pt.lin && pos < pt.pos) 27 | return true; 28 | return false; 29 | } 30 | bool operator == (const PosText &pt) const 31 | { return lin == pt.lin && pos == pt.pos; } 32 | bool operator != (const PosText & pt) const 33 | { return lin != pt.lin || pos != pt.pos; } 34 | void set (size_t nlin, size_t npos) 35 | { lin= nlin; pos= npos; } 36 | }; 37 | 38 | class Selection { 39 | public: 40 | void init (int lin, int pos) 41 | { 42 | ptBegin.set (lin, pos); 43 | ptEnd.set (lin, pos); 44 | } 45 | const PosText & begin () const { return ptBegin; } 46 | const PosText & end () const { return ptEnd; } 47 | bool empty () const { return ptBegin == ptEnd; } 48 | void movebegin (const PosText & npt) 49 | { 50 | ptBegin= npt; 51 | adjust (); 52 | } 53 | void movebegin (int lin, int pos) { movebegin (PosText (lin, pos) ); } 54 | void moveend (const PosText & npt) 55 | { 56 | ptEnd= npt; 57 | adjust (); 58 | } 59 | void moveend (int lin, int pos) { moveend (PosText (lin, pos) ); } 60 | private: 61 | PosText ptBegin, ptEnd; 62 | inline void adjust () 63 | { if (ptEnd < ptBegin) std::swap (ptBegin, ptEnd); } 64 | }; 65 | 66 | class Text { 67 | public: 68 | class Error : public std::runtime_error { 69 | public: 70 | Error (const std::string & str); 71 | }; 72 | class ErrorSaving : public Error { 73 | public: 74 | ErrorSaving (const std::string & filename); 75 | }; 76 | class ErrorReadOnly : public Error { 77 | public: 78 | ErrorReadOnly (); 79 | }; 80 | 81 | //typedef std::vector VecLine; 82 | typedef VecTextLine VecLine; 83 | 84 | Text (bool useutf8); 85 | virtual ~Text (); 86 | private: 87 | Text (const Text & other); 88 | public: 89 | void operator = (const Text & other); 90 | void swap (Text & other); 91 | 92 | bool empty () const; 93 | size_t size () const; 94 | size_t lines () const; 95 | bool getutf8 () const; 96 | void setutf8 (bool f); 97 | 98 | const TextLine & operator [] (size_t n) const; 99 | std::string wordat (size_t lin, Col col) const; 100 | 101 | void copyselection (const Selection & sel, Text & copyto) const; 102 | 103 | std::string str () const; 104 | 105 | void clear (); 106 | bool set (const char * str); 107 | void setline (size_t lin, const std::string & str); 108 | void deletecharpos (size_t lin, size_t pos); 109 | void insertchar (size_t lin, Col col, unsigned char c); 110 | void insertcharpos (size_t lin, size_t pos, unsigned char c); 111 | void append (size_t lin, const std::string & str); 112 | void appendchar (size_t lin, unsigned char c); 113 | size_t insertline (size_t lin, Col col, bool autoindent); 114 | void insertline (size_t lin, const std::string & str); 115 | void deleteline (size_t lin); 116 | void deletechar (size_t lin, size_t col); 117 | void joinline (size_t lin); 118 | void replace (size_t lin, size_t pos, std::string::size_type l, 119 | const std::string & str); 120 | void push_back (const std::string & s); 121 | protected: 122 | bool load (FILE * fin); 123 | bool load (const std::string & filename); 124 | void save (const std::string & strFile); 125 | private: 126 | bool flagutf8; 127 | VecLine t; 128 | }; 129 | 130 | namespace std { 131 | 132 | template <> inline void swap (Text & one, Text & two) 133 | { 134 | one.swap (two); 135 | } 136 | 137 | } // namespace std 138 | 139 | class TextFile : public Text { 140 | public: 141 | TextFile (bool useutf8); 142 | ~TextFile (); 143 | bool saved () const; 144 | bool modified () const; 145 | void modified (bool f); 146 | bool readonly () const; 147 | void readonly (bool f); 148 | bool getutf8 () const; 149 | void setutf8 (bool f); 150 | bool hasname () const; 151 | std::string name () const; 152 | void clear (); 153 | 154 | bool load (FILE * fin); 155 | bool load (const std::string & strFile); 156 | void save (); 157 | void save (const std::string & strFile); 158 | 159 | bool set (const char * str); 160 | void setline (size_t lin, const std::string & str); 161 | void deletecharpos (size_t lin, size_t pos); 162 | void insertchar (size_t lin, Col col, unsigned char c); 163 | void insertcharpos (size_t lin, size_t pos, unsigned char c); 164 | void append (size_t lin, const std::string & str); 165 | void appendchar (size_t lin, unsigned char c); 166 | size_t insertline (size_t lin, Col col, bool autoindent); 167 | void insertline (size_t lin, const std::string & str); 168 | void deleteline (size_t lin); 169 | void joinline (size_t lin); 170 | void replace (size_t lin, size_t pos, std::string::size_type l, 171 | const std::string & str); 172 | void push_back (const std::string & s); 173 | private: 174 | class FileId { 175 | public: 176 | FileId (); 177 | FileId (const std::string & newname); 178 | ~FileId (); 179 | void operator = (const FileId & other); 180 | void erase (); 181 | void set (const std::string & newname); 182 | bool empty () const; 183 | bool isremote () const; 184 | std::string filename () const; 185 | std::string remotename () const; 186 | private: 187 | FileId (const FileId &); // Forbidden. 188 | std::string strFilename; 189 | std::string strRemotename; 190 | }; 191 | FileId fileid; 192 | bool isSaved; 193 | bool isReadOnly; 194 | 195 | void checkreadonly (); 196 | }; 197 | 198 | #endif 199 | 200 | // Fin de text.h 201 | -------------------------------------------------------------------------------- /termstream.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TERMSTREAM_H_ 2 | #define INCLUDE_TERMSTREAM_H_ 3 | 4 | // termstream.h 5 | // Revision 7-feb-2007 6 | 7 | #include "config_streambuf.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | #if HAVE_STREAMBUF 14 | #include 15 | #elif HAVE_STREAMBUF_H 16 | #include 17 | #else 18 | #error No streambuf 19 | #endif 20 | 21 | class Color 22 | { 23 | public: 24 | typedef short value; 25 | static const value 26 | Black= 0, 27 | Red= 1, 28 | Green= 2, 29 | Yellow= 3, 30 | Blue= 4, 31 | Magenta= 5, 32 | Cyan= 6, 33 | White= 7; 34 | }; 35 | 36 | class termbuf : public std::streambuf 37 | { 38 | public: 39 | explicit termbuf (std::ios::openmode); 40 | void setWindow (void * window); 41 | int getkey (); 42 | int checkkey (); 43 | virtual int sync (); 44 | protected: 45 | virtual int overflow (int ch= EOF); 46 | virtual int underflow (); 47 | private: 48 | static const std::streamsize bufsize= 64; 49 | char defbuf [bufsize]; 50 | void *w; 51 | class Control 52 | { 53 | public: 54 | Control (); 55 | ~Control (); 56 | }; 57 | Control control; 58 | }; 59 | 60 | 61 | void termstream_set_terminal (FILE * termtouse); 62 | 63 | 64 | class termstreambase : virtual public std::ios 65 | { 66 | protected: 67 | termbuf __my_tb; 68 | public: 69 | termbuf * rdbuf (); 70 | static void shellmode (); 71 | static void progmode (); 72 | static void clr_all (); 73 | static void redraw_all (); 74 | void sync (); 75 | int getkey (); 76 | int checkkey (); 77 | int lines () const; 78 | int columns () const; 79 | int wherex () const; 80 | int wherey () const; 81 | protected: 82 | termstreambase (std::ios::openmode which); 83 | void setWindow (void *window); 84 | void *w; 85 | }; 86 | 87 | 88 | class ts_bool 89 | { 90 | public: 91 | std::ostream & (* f) (std::ostream &, bool); 92 | bool b; 93 | ts_bool (std::ostream & (*ff) (std::ostream &, bool), bool bb) 94 | : f (ff), b (bb) {} 95 | }; 96 | 97 | class ts_2int 98 | { 99 | public: 100 | std::ostream & (* f) (std::ostream &, int, int); 101 | int i1, i2; 102 | ts_2int (std::ostream & (*ff) (std::ostream &, int, int), 103 | int ii1, int ii2) 104 | : f (ff), i1 (ii1), i2 (ii2) 105 | {} 106 | }; 107 | 108 | class ts_short 109 | { 110 | public: 111 | std::ostream & (* f) (std::ostream &, short); 112 | short s; 113 | ts_short (std::ostream & (*ff) (std::ostream &, short), short ss) 114 | : f (ff), s (ss) {} 115 | }; 116 | 117 | 118 | std::ostream & operator << (std::ostream & os, const ts_bool & tb); 119 | std::ostream & operator << (std::ostream & os, const ts_2int & t2i); 120 | std::ostream & operator << (std::ostream & os, const ts_short & ts); 121 | 122 | 123 | class otermstream : public termstreambase, public std::ostream 124 | { 125 | public: 126 | otermstream (std::ios::openmode which= std::ios::out); 127 | otermstream (int nlines, int ncols, int y, int x); 128 | otermstream (otermstream & ot, int nlines, int ncols, int y, int x); 129 | ~otermstream (); 130 | void update (); 131 | void border (); 132 | void clrscr (); 133 | void clreol (); 134 | void insertline (); 135 | void deleteline (); 136 | void at (int y, int x); 137 | inline void gotoxy (int x, int y) { at (y, x); } 138 | void inverse (bool flag); 139 | void delay (bool flag); 140 | void cursor (bool flag); 141 | int getBegX () const; 142 | int getBegY () const; 143 | int getWidth () const; 144 | int getHeight () const; 145 | void setcolor (short n, Color::value f, Color::value b); 146 | void color (short c); 147 | void background (short c); 148 | 149 | friend std::ostream & operator << 150 | (std::ostream & os, const ts_bool & tb); 151 | friend std::ostream & operator << 152 | (std::ostream & os, const ts_2int & t2i); 153 | friend std::ostream & operator << 154 | (std::ostream & os, const ts_short & ts); 155 | private: 156 | bool isStd; 157 | }; 158 | 159 | 160 | std::ostream & inverse (std::ostream &os, bool b); 161 | 162 | std::ostream & delay (std::ostream &os, bool b); 163 | 164 | std::ostream & cursor (std::ostream &os, bool b); 165 | 166 | std::ostream & gotoxy (std::ostream &os, int x, int y); 167 | 168 | std::ostream & at (std::ostream & os, int y, int x); 169 | 170 | std::ostream & color (std::ostream &os, short c); 171 | 172 | ts_bool inverse (bool b); 173 | 174 | ts_bool delay (bool b); 175 | 176 | ts_bool cursor (bool b); 177 | 178 | ts_2int gotoxy (int x, int y); 179 | 180 | ts_2int at (int y, int x); 181 | 182 | ts_short color (short c); 183 | 184 | std::ostream & update (std::ostream & os); 185 | 186 | std::ostream & clrscr (std::ostream &os); 187 | 188 | std::ostream & clreol (std::ostream &os); 189 | 190 | std::ostream & delline (std::ostream &os); 191 | 192 | std::ostream & insline (std::ostream &os); 193 | 194 | namespace key 195 | { 196 | const int 197 | Ctl_A= 0x01, 198 | Ctl_B= 0x02, 199 | Ctl_C= 0x03, 200 | Ctl_D= 0x04, 201 | Ctl_E= 0x05, 202 | Ctl_F= 0x06, 203 | Ctl_G= 0x07, 204 | Ctl_H= 0x08, 205 | Ctl_I= 0x09, 206 | Ctl_J= 0x0A, 207 | Ctl_K= 0x0B, 208 | Ctl_L= 0x0C, 209 | Ctl_M= 0x0D, 210 | Ctl_N= 0x0E, 211 | Ctl_O= 0x0F, 212 | Ctl_P= 0x10, 213 | Ctl_Q= 0x11, 214 | Ctl_R= 0x12, 215 | Ctl_S= 0x13, 216 | Ctl_T= 0x14, 217 | Ctl_U= 0x15, 218 | Ctl_V= 0x16, 219 | Ctl_W= 0x17, 220 | Ctl_X= 0x18, 221 | Ctl_Y= 0x19, 222 | Ctl_Z= 0x1A, 223 | 224 | Esc= 0x1B, 225 | 226 | Left= 0x0100, 227 | Right= 0x0101, 228 | Up= 0x0102, 229 | Down= 0x0103, 230 | PageUp= 0x0104, 231 | PageDown= 0x0105, 232 | Backspace= 0x0106, 233 | Delete= 0x0107, 234 | Home= 0x0108, 235 | End= 0x0109, 236 | 237 | Select= 0x010A, 238 | 239 | F1= 0x0201, 240 | F2= 0x0202, 241 | F3= 0x0203, 242 | F4= 0x0204, 243 | F5= 0x0205, 244 | F6= 0x0206, 245 | F7= 0x0207, 246 | F8= 0x0208, 247 | F9= 0x0209, 248 | F10= 0x020A, 249 | F11= 0x020B, 250 | F12= 0x020C; 251 | } 252 | 253 | #endif 254 | 255 | // End of termstream.h 256 | -------------------------------------------------------------------------------- /dirutil.cpp: -------------------------------------------------------------------------------- 1 | // dirutil.cpp 2 | // Revision 29-jul-2009 3 | 4 | #include "dirutil.h" 5 | 6 | #include "termstream.h" 7 | 8 | #include "trace.h" 9 | 10 | #include "config_types.h" 11 | #include "config_dirent.h" 12 | #include "config_fork.h" 13 | #include "config_wait.h" 14 | 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using std::string; 26 | using std::runtime_error; 27 | 28 | namespace { 29 | 30 | class AutoCString { 31 | public: 32 | AutoCString (const char * str) : str (str) 33 | { } 34 | ~AutoCString () 35 | { 36 | free (const_cast (str) ); 37 | } 38 | private: 39 | const char * str; 40 | }; 41 | 42 | class AutoDir { 43 | public: 44 | AutoDir (DIR * dir) : dir (dir) 45 | { } 46 | ~AutoDir (); 47 | private: 48 | DIR * dir; 49 | }; 50 | 51 | AutoDir::~AutoDir () 52 | { 53 | TRF; 54 | 55 | #if CLOSEDIR_VOID 56 | closedir (dir); 57 | #else 58 | int r= closedir (dir); 59 | if (r != 0) 60 | { 61 | TRDEB ("Failed closedir"); 62 | } 63 | #endif 64 | } 65 | 66 | 67 | bool has_leading_slash (const std::string & str) 68 | { 69 | if (str.empty () ) 70 | return false; 71 | return str [str.size () - 1] == '/'; 72 | } 73 | 74 | } // namespace 75 | 76 | bool dirutil::is_directory (const std::string & str) 77 | { 78 | struct stat st; 79 | if (stat (str.c_str (), & st) != 0) 80 | return false; 81 | if (! S_ISDIR (st.st_mode) ) 82 | return false; 83 | return true; 84 | } 85 | 86 | std::string dirutil::base_name (const std::string & str) 87 | { 88 | // basename requires a writable c string. 89 | char * aux= strdup (str.c_str () ); 90 | if (! aux) 91 | throw std::bad_alloc (); 92 | AutoCString aaux (aux); 93 | return basename (aux); 94 | } 95 | 96 | std::string dirutil::dir_name (const std::string & str) 97 | { 98 | // basename requires a writable c string. 99 | char * aux= strdup (str.c_str () ); 100 | if (! aux) 101 | throw std::bad_alloc (); 102 | AutoCString aaux (aux); 103 | return dirname (aux); 104 | } 105 | 106 | std::string dirutil::extension (const std::string & str) 107 | { 108 | //TraceFunc tr ("file::extension"); 109 | 110 | const string file= base_name (str); 111 | //tr.message (file); 112 | string::size_type l= file.rfind ('.'); 113 | if (l == string::npos) 114 | return string (); 115 | if (l == file.size () ) 116 | return string (); 117 | else return file.substr (l + 1); 118 | } 119 | 120 | std::string dirutil::enter_dir (const std::string & old, 121 | const std::string & enter) 122 | { 123 | if (enter == ".") 124 | return old; 125 | if (enter == "..") 126 | { 127 | string base= base_name (old); 128 | if (base == "/") 129 | return old; 130 | if (base != ".." && base != ".") 131 | return dir_name (old); 132 | } 133 | return old + (has_leading_slash (old) ? "" : "/") + enter; 134 | } 135 | 136 | void dirutil::directory (const std::string & dirname, 137 | std::vector & v) 138 | { 139 | v.clear (); 140 | DIR * dir= opendir (dirname.c_str () ); 141 | if (! dir) 142 | return; 143 | AutoDir adir (dir); 144 | struct dirent * ent; 145 | while ( (ent= readdir (dir) ) ) 146 | v.push_back (ent->d_name); 147 | } 148 | 149 | void dirutil::delete_file (const std::string & filename) 150 | { 151 | if (unlink (filename.c_str () ) != 0) 152 | throw runtime_error ("Error deleting " + filename + 153 | ": " + strerror (errno) ); 154 | } 155 | 156 | std::string dirutil::create_temp_file () 157 | { 158 | TRF; 159 | 160 | char buffer [PATH_MAX]; 161 | 162 | // Generate temporary file template. 163 | 164 | const char * tmp_path= getenv ("TMP"); 165 | if (tmp_path != NULL) 166 | { 167 | strncpy (buffer, tmp_path, PATH_MAX - 2); 168 | buffer [sizeof (buffer) - 2]= '\0'; 169 | size_t l= strlen (buffer); 170 | if (l > 0 && buffer [l - 1] != '/') 171 | { 172 | buffer [l]= '/'; 173 | buffer [l + 1]= '\0'; 174 | } 175 | } 176 | else 177 | strcpy (buffer, "/tmp/"); 178 | strcat (buffer, "qtre_XXXXXX"); 179 | 180 | // Create temporary file with the template. 181 | 182 | int r= mkstemp (buffer); 183 | if (r == -1) 184 | { 185 | throw runtime_error 186 | (string ("Error creating temporay file: ") + 187 | strerror (errno) ); 188 | } 189 | close (r); 190 | return string (buffer); 191 | } 192 | 193 | namespace { 194 | 195 | class EnterShellMode { 196 | public: 197 | EnterShellMode () 198 | { 199 | otermstream::clr_all (); 200 | otermstream::shellmode (); 201 | } 202 | ~EnterShellMode () 203 | { 204 | otermstream::progmode (); 205 | } 206 | }; 207 | 208 | int do_copy_remote_file (const std::string & source, const std::string & dest) 209 | { 210 | TRF; 211 | 212 | //int r= system ( ("scp " + source + " " + dest).c_str () ); 213 | 214 | int r= -1; 215 | 216 | pid_t pid= vfork (); 217 | switch (pid) 218 | { 219 | case pid_t (-1): 220 | // Failed fork. 221 | r= -1; 222 | break; 223 | case pid_t (0): 224 | // Child process. 225 | execlp ("scp", "scp", 226 | source.c_str (), dest.c_str (), 227 | static_cast (0) ); 228 | TRDEB ( string ("execlp failed: ") + strerror (errno) ); 229 | exit (127); 230 | default: 231 | // Parent process. 232 | { 233 | int status; 234 | if (waitpid (pid, & status, 0) != pid) 235 | r= -1; 236 | else 237 | { 238 | if (WIFEXITED (status) ) 239 | r= WEXITSTATUS (status); 240 | else 241 | r= -1; 242 | } 243 | } 244 | } 245 | 246 | return r; 247 | } 248 | 249 | } // namespace 250 | 251 | void dirutil::copy_remote_file 252 | (const std::string & source, const std::string & dest) 253 | { 254 | TRF; 255 | 256 | EnterShellMode esm; 257 | 258 | std::cerr << "Remote copying..." << std::endl; 259 | 260 | //int r= system ( ("scp " + source + " " + dest).c_str () ); 261 | int r= do_copy_remote_file (source, dest); 262 | 263 | if (r != 0) 264 | throw runtime_error 265 | (string ("Error copying remote file: ") + 266 | strerror (errno) ); 267 | } 268 | 269 | // End of dirutil.cpp 270 | -------------------------------------------------------------------------------- /qtre.cpp: -------------------------------------------------------------------------------- 1 | // qtre.cpp 2 | // Revision 29-jan-2006 3 | 4 | #include "termstream.h" 5 | #include "screen.h" 6 | 7 | #include "trace.h" 8 | #undef ASSERT 9 | #include "qtreassert.h" 10 | 11 | #include "config_locale.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | using std::cout; 25 | using std::cerr; 26 | using std::endl; 27 | using std::flush; 28 | using std::string; 29 | using std::vector; 30 | using std::exception; 31 | using std::runtime_error; 32 | using std::auto_ptr; 33 | 34 | extern const string strVersion; 35 | extern const string strAbout1; 36 | extern const string strAbout2; 37 | extern const string strAbout3; 38 | 39 | // Used to end the program when received a SIGTERM signal. 40 | bool fExit= false; 41 | 42 | namespace { 43 | 44 | //********************************************************* 45 | // Initialization. 46 | //********************************************************* 47 | 48 | class FileLoader { 49 | public: 50 | FileLoader (Screen & screen); 51 | ~FileLoader (); 52 | size_t size () const; 53 | void load (const string & filename); 54 | void load (FILE * fin); 55 | private: 56 | size_t numfiles; 57 | Screen & screen; 58 | }; 59 | 60 | FileLoader::FileLoader (Screen & screen) : 61 | numfiles (0), 62 | screen (screen) 63 | { 64 | TRF; 65 | } 66 | 67 | FileLoader::~FileLoader () 68 | { 69 | TRF; 70 | } 71 | 72 | size_t FileLoader::size () const 73 | { 74 | return numfiles; 75 | } 76 | 77 | void FileLoader::load (const string & filename) 78 | { 79 | TRFDEBS ("Loading: " << filename); 80 | 81 | if (numfiles > 0) 82 | screen.windownew (); 83 | screen.loadtext (filename); 84 | ++numfiles; 85 | } 86 | 87 | void FileLoader::load (FILE * fin) 88 | { 89 | TRF; 90 | 91 | if (numfiles > 0) 92 | screen.windownew (); 93 | screen.loadtext (fin); 94 | ++numfiles; 95 | } 96 | 97 | 98 | class Options { 99 | public: 100 | Options (int argc, char * * argv); 101 | ~Options (); 102 | bool use_stderr () const; 103 | bool has_line () const; 104 | size_t line () const; 105 | size_t numfiles () const; 106 | string filename (size_t n) const; 107 | private: 108 | bool stdin_used; 109 | bool flagline; 110 | size_t numline; 111 | vector files; 112 | }; 113 | 114 | Options::Options (int argc, char * * argv) : 115 | stdin_used (false), 116 | flagline (false), 117 | numline (0) 118 | { 119 | TRF; 120 | 121 | bool allowoptions= true; 122 | for (int i= 1; i < argc; ++i) 123 | { 124 | string param (argv [i] ); 125 | if (allowoptions) 126 | { 127 | if (param == "--") 128 | { 129 | allowoptions= false; 130 | continue; 131 | } 132 | if (param.substr (0, 1) == "+") 133 | { 134 | const char * aux= param.c_str () + 1; 135 | char * auxres; 136 | numline= strtoul (aux, & auxres, 10); 137 | if (* auxres != '\0') 138 | throw runtime_error ("Invalid option"); 139 | flagline= true; 140 | continue; 141 | } 142 | } 143 | if (param == "-") 144 | stdin_used= true; 145 | files.push_back (param); 146 | } 147 | 148 | } 149 | 150 | Options::~Options () 151 | { 152 | TRF; 153 | } 154 | 155 | bool Options::use_stderr () const 156 | { 157 | return stdin_used; 158 | } 159 | 160 | bool Options::has_line () const 161 | { 162 | return flagline; 163 | } 164 | 165 | size_t Options::line () const 166 | { 167 | return numline; 168 | } 169 | 170 | size_t Options::numfiles () const 171 | { 172 | return files.size (); 173 | } 174 | 175 | string Options::filename (size_t n) const 176 | { 177 | ASSERT (n < files.size () ); 178 | return files [n]; 179 | } 180 | 181 | int qtre_main (int argc, char * * argv, char * * env) 182 | { 183 | TRF; 184 | 185 | bool useutf8= false; 186 | 187 | // Use locale and langinfo, if available, to check utf8 use. 188 | #if HAVE_LOCALE_H 189 | setlocale (LC_ALL, ""); 190 | #if HAVE_LANGINFO_H 191 | const std::string codeset (nl_langinfo (CODESET) ); 192 | useutf8= codeset == "UTF-8"; 193 | #endif 194 | #endif 195 | 196 | TRDEBS (codeset << " is utf8: " << (useutf8 ? "Yes" : "No") ); 197 | 198 | Options options (argc, argv); 199 | 200 | if (options.use_stderr () ) 201 | termstream_set_terminal (stderr); 202 | 203 | // Screen is the main object of the application. 204 | 205 | auto_ptr pscreen (createScreen (useutf8, env) ); 206 | Screen & screen= * pscreen.get (); 207 | 208 | FileLoader fl (screen); 209 | const size_t numfiles= options.numfiles (); 210 | for (size_t i= 0; i < numfiles; ++i) 211 | { 212 | const string filename= options.filename (i); 213 | if (filename == "-") 214 | { 215 | fl.load (stdin); 216 | } 217 | else 218 | fl.load (filename); 219 | } 220 | 221 | if (numfiles > 0) 222 | screen.changewindow (0); 223 | 224 | if (options.has_line () ) 225 | { 226 | const size_t optline= options.line (); 227 | const size_t maxline= screen.textlines (); 228 | const size_t numline= optline > 0 ? 229 | std::min (optline, maxline) : 230 | maxline; 231 | screen.gotoline (numline - 1); 232 | } 233 | 234 | screen.interact (); 235 | 236 | return 0; 237 | } 238 | 239 | void handleSigTerm (int) 240 | { 241 | fExit= true; 242 | } 243 | 244 | void init_signals () 245 | { 246 | TRF; 247 | 248 | #ifndef NDEBUG 249 | signal (SIGUSR1, TraceFunc::show); 250 | #endif 251 | 252 | #if 0 253 | struct sigaction action; 254 | action.sa_handler= handleSigTerm; 255 | action.sa_flags= SA_RESTART; 256 | sigaction (SIGTERM, & action, NULL); 257 | #endif 258 | } 259 | 260 | } // namespace 261 | 262 | int main (int argc, char * * argv, char * * env) 263 | { 264 | TRF; 265 | 266 | init_signals (); 267 | 268 | int r= 0; 269 | try 270 | { 271 | r= qtre_main (argc, argv, env); 272 | } 273 | catch (exception &e) 274 | { 275 | cout << endl << "Error: " << e.what (); 276 | r= 127; 277 | } 278 | catch (...) 279 | { 280 | cout << endl << "Unexpected error"; 281 | r= 127; 282 | } 283 | 284 | cout << endl; 285 | return r; 286 | } // main 287 | 288 | // End of qtre.cpp 289 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # configure.ac for qtre 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.57) 5 | 6 | AC_INIT(qtre, 0.1.0.0, julian.notfound@gmail.com) 7 | 8 | AC_CONFIG_HEADERS([config.h config_config_dir.h config_debug.h config_function.h config_types.h config_version.h config_locale.h config_filebuf.h config_streambuf.h config_curses.h config_dirent.h config_fork.h config_wait.h] ) 9 | 10 | AM_INIT_AUTOMAKE 11 | 12 | AC_CANONICAL_BUILD 13 | AC_CANONICAL_HOST 14 | 15 | AC_DEFINE_UNQUOTED(CONFIG_DIR, "$sysconfdir", [Directory for qtre.pl]) 16 | 17 | 18 | ##################################################################### 19 | # Check perl 20 | ##################################################################### 21 | 22 | 23 | # Those checks must be done before AC_PROG_CC, in order to avoid 24 | # autoconf setting the value of CC. 25 | 26 | AC_PATH_PROG(PERL, perl, no) 27 | if test "$PERL" = "no"; then 28 | AC_MSG_ERROR([Perl is required]) 29 | fi 30 | 31 | # Requirements for perl embedding: 32 | 33 | # Check the C compiler used to build perl, but allow user 34 | # to override it. 35 | 36 | if test "$CC" = "" ; then 37 | AC_MSG_CHECKING([for perl Config module]) 38 | $PERL -e 'eval { require Config; }; if ($@) { exit (1); } else { exit (0); }' 39 | if test "$?" = "0"; then 40 | AC_MSG_RESULT([yes]) 41 | else 42 | AC_MSG_RESULT([no]) 43 | AC_MSG_ERROR([Perl module Config is required]) 44 | fi 45 | AC_MSG_CHECKING([for compiler used to build perl]) 46 | CC=`$PERL -MConfig -e 'print $Config{cc}."\n";'` 47 | AC_MSG_RESULT([$CC]) 48 | fi 49 | 50 | # Check the availability of the ExtUtils::Embed module, 51 | # required to set compilation flags. 52 | # TODO: add a way for user override. 53 | 54 | AC_MSG_CHECKING([for perl ExtUtils::Embed module]) 55 | $PERL -e 'eval { require ExtUtils::Embed; }; if ($@) { exit (1); } else { exit (0); }' 56 | if test "$?" = "0"; then 57 | AC_MSG_RESULT([yes]) 58 | else 59 | AC_MSG_RESULT([no]) 60 | AC_MSG_ERROR([Perl module ExtUtils::Embed is required]) 61 | fi 62 | 63 | PERL_CCOPTS=`$PERL -MExtUtils::Embed -e ccopts` 64 | AC_SUBST(PERL_CCOPTS) 65 | 66 | PERL_LDOPTS=`$PERL -MExtUtils::Embed -e ldopts` 67 | AC_SUBST(PERL_LDOPTS) 68 | 69 | ##################################################################### 70 | 71 | 72 | AC_PROG_CC 73 | AC_PROG_CXX 74 | 75 | AC_PROG_INSTALL 76 | 77 | ##################################################################### 78 | # Options 79 | ##################################################################### 80 | 81 | 82 | AC_ARG_ENABLE(debug, AC_HELP_STRING( 83 | [--enable-debug], [Debug version [[no]]] ) ) 84 | 85 | if test "$enable_debug" = "yes" ; then 86 | AC_MSG_RESULT([Configured for debug version]) 87 | else 88 | AC_MSG_RESULT([Configured for release version]) 89 | AC_DEFINE([NDEBUG], [1], [Not in debug mode]) 90 | fi 91 | 92 | 93 | ##################################################################### 94 | # Check for macros used in trace system 95 | ##################################################################### 96 | 97 | 98 | if test "$enable_debug" = "yes" ; then 99 | 100 | AC_MSG_CHECKING(wheter the C++ compiler(${CXX}) supports __FUNCTION__) 101 | AC_TRY_COMPILE([#include ],[puts(__FUNCTION__);], 102 | have_function=yes,have_function=no) 103 | AC_MSG_RESULT($have_function) 104 | 105 | if test "$have_function" = "yes" ; then 106 | AC_DEFINE(HAVE_FUNCTION, [1], [Has __FUNCTION__]) 107 | AC_MSG_CHECKING(wheter the C++ compiler(${CXX}) supports __PRETTY_FUNCTION__) 108 | AC_TRY_COMPILE([#include ],[puts(__PRETTY_FUNCTION__);], 109 | have_pretty_function=yes,have_pretty_function=no) 110 | AC_MSG_RESULT($have_pretty_function) 111 | if test "$have_pretty_function" = "yes" ; then 112 | AC_DEFINE(HAVE_PRETTY_FUNCTION, [1], [Has __PRETTY_FUNCTION__]) 113 | fi 114 | 115 | fi 116 | 117 | fi 118 | 119 | 120 | ##################################################################### 121 | # Check headers and libraries used 122 | ##################################################################### 123 | 124 | 125 | AC_LANG_PUSH([C++]) 126 | 127 | AC_TYPE_PID_T 128 | AC_TYPE_UID_T 129 | AC_TYPE_MODE_T 130 | 131 | AC_HEADER_DIRENT 132 | AC_FUNC_CLOSEDIR_VOID 133 | 134 | AC_FUNC_FORK 135 | 136 | # This is just to avoid autoscan warn. 137 | AC_FUNC_STAT 138 | 139 | AC_CHECK_HEADER([sys/types.h]) 140 | AC_HEADER_SYS_WAIT 141 | 142 | AC_CHECK_HEADERS([locale.h]) 143 | AC_CHECK_HEADERS([nl_types.h]) 144 | AC_CHECK_HEADERS([langinfo.h]) 145 | 146 | AC_CHECK_HEADERS([ostream]) 147 | 148 | AC_CHECK_HEADERS([streambuf],, 149 | [AC_CHECK_HEADERS([streambuf.h],, 150 | AC_MSG_ERROR([streambuf header not available]) ] ) ) 151 | 152 | 153 | # Find a way to build a stream from a file handle 154 | 155 | 156 | AC_CHECK_HEADERS([ext/stdio_filebuf.h],[filebuf=yes],[filebuf=no]) 157 | 158 | if test "$filebuf" = "yes"; then 159 | AC_MSG_CHECKING([for filebuf constructor parameters]) 160 | AC_TRY_COMPILE( 161 | [ 162 | #include 163 | ], 164 | [ 165 | __gnu_cxx::stdio_filebuf 166 | bufin (1, std::ios::in, size_t (1) ); 167 | ], 168 | filebuf_params=3 169 | , 170 | AC_TRY_COMPILE( 171 | [ 172 | #include 173 | ], 174 | [ 175 | __gnu_cxx::stdio_filebuf 176 | bufin (1, std::ios::in, false, 1); 177 | ], 178 | filebuf_params=4 179 | , 180 | AC_MSG_RESULT([unknown]) 181 | AC_MSG_ERROR([unknown filebuf style]) 182 | ) 183 | ) 184 | AC_MSG_RESULT([$filebuf_params]) 185 | else 186 | AC_MSG_CHECKING([for ifstream construction from file handle]) 187 | AC_TRY_COMPILE( 188 | [ 189 | #include 190 | ], 191 | [ 192 | std::ifstream bufin (1); 193 | ], 194 | filebuf_params=0 195 | AC_MSG_RESULT([yes]) 196 | , 197 | AC_MSG_RESULT([no]) 198 | AC_MSG_ERROR([No way to build a stream from a file handle]) 199 | ) 200 | fi 201 | 202 | AC_DEFINE_UNQUOTED([FILEBUF_PARAMS], $filebuf_params, 203 | [Number of parameters for filebuf constructor]) 204 | 205 | 206 | # Check for ncursesw, if not available check for ncurses 207 | 208 | 209 | AC_CHECK_HEADERS([ncursesw/ncurses.h],[wncurses=yes],[wncurses=no]) 210 | if test "$wncurses" = "yes"; then 211 | AC_CHECK_LIB([ncursesw],[tputs],,[wncurses=no]) 212 | if test "$wncurses" = "no"; then 213 | AC_MSG_ERROR([ncursesw header found but no library]) 214 | fi 215 | else 216 | AC_CHECK_HEADERS([ncurses.h],[ncurses=yes],[ncurses=no]) 217 | if test "$ncurses" = "no"; then 218 | AC_MSG_ERROR([No ncursesw nor ncurses headers found]) 219 | else 220 | AC_CHECK_LIB([ncurses],[tputs],,[ncurses=no]) 221 | if test "$ncurses" = no; then 222 | AC_MSG_ERROR([ncurses header found but no library]) 223 | fi 224 | fi 225 | fi 226 | 227 | 228 | AC_LANG_POP 229 | 230 | 231 | ##################################################################### 232 | # Generate files 233 | ##################################################################### 234 | 235 | 236 | AC_CONFIG_FILES([Makefile]) 237 | 238 | AC_OUTPUT 239 | 240 | # End of configure.ac 241 | -------------------------------------------------------------------------------- /textline.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TEXTLINE_H_ 2 | #define INCLUDE_TEXTLINE_H_ 3 | 4 | // textline.h 5 | // Revision 25-jan-2006 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | unsigned char escapable (unsigned char c, bool useutf8); 13 | unsigned char escaped (unsigned char c); 14 | 15 | class Col { 16 | public: 17 | class Bad : public std::exception { 18 | const char * what () { return "Bad column"; } 19 | }; 20 | 21 | Col () : n (0) { } 22 | explicit Col (size_t nn) : n (nn) { } 23 | size_t getn () const { return n; } 24 | Col & operator += (size_t inc) 25 | { 26 | if (n > colmax.n - inc) 27 | throw Bad (); 28 | n+= inc; 29 | return * this; 30 | } 31 | Col operator + (size_t nn) const 32 | { 33 | if (n > colmax.n - nn) 34 | throw Bad (); 35 | return Col (n + nn); 36 | } 37 | Col operator + (const Col & col) const 38 | { return Col (n + col.n); } 39 | Col & operator ++ () 40 | { 41 | if (n == colmax.n) 42 | throw Bad (); 43 | ++n; 44 | return * this; 45 | } 46 | Col operator - (const Col & col) const 47 | { 48 | if (col.n > n) 49 | throw Bad (); 50 | return Col (n - col.n); 51 | } 52 | bool operator == (const Col & col) const 53 | { return n == col.n; } 54 | bool operator != (const Col & col) const 55 | { return n != col.n; } 56 | bool operator < (const Col & col) const 57 | { return n < col.n; } 58 | bool operator <= (const Col & col) const 59 | { return n <= col.n; } 60 | bool operator > (const Col & col) const 61 | { return n > col.n; } 62 | static Col & max () { return colmax; } 63 | /* 64 | Col nexttab () const 65 | { return Col ( (n / 8 + 1) * 8); } 66 | Col previoustab () const 67 | { return Col ( (n / 8) * 8); } 68 | */ 69 | void nexttab () 70 | { n= (n / 8 + 1) * 8; } 71 | void previoustab () 72 | { n= (n / 8) * 8; } 73 | bool odd () const 74 | { return n & 1; } 75 | friend std::ostream & operator << (std::ostream & os, const Col & col); 76 | private: 77 | static Col colmax; 78 | size_t n; 79 | }; 80 | 81 | inline std::ostream & operator << (std::ostream & os, const Col & col) 82 | { 83 | os << col.n; 84 | return os; 85 | } 86 | 87 | class TextLine { 88 | std::string s; 89 | public: 90 | TextLine (bool useutf8); 91 | TextLine (bool useutf8, const std::string & snue); 92 | ~TextLine (); 93 | private: 94 | TextLine (const TextLine &); // Forbidden 95 | void operator = (const TextLine &); // Forbidden 96 | public: 97 | bool empty () const; 98 | size_t size () const; 99 | const std::string & str () const; 100 | char operator [] (size_t n) const; 101 | std::string substr (size_t n, size_t fin= std::string::npos) const; 102 | std::string wordat (Col col) const; 103 | 104 | void operator = (std::string snue); 105 | void operator += (char c); 106 | void operator += (const std::string & str); 107 | void operator += (const TextLine & tnue); 108 | 109 | size_t col2pos (Col col) const; 110 | Col pos2col (size_t pos) const; 111 | Col colmax () const; 112 | 113 | void deletechar (Col col); 114 | void deletecharpos (size_t pos); 115 | void insertchar (Col col, char c); 116 | void insertcharpos (size_t pos, char c); 117 | void insert (const std::string & str); 118 | void replace (size_t pos, std::string::size_type l, 119 | const std::string & str); 120 | friend std::ostream & operator << 121 | (std::ostream & os, const TextLine & tl); 122 | private: 123 | class AuxImpl; 124 | AuxImpl *aimpl; 125 | }; 126 | 127 | class TextLineRef { 128 | public: 129 | TextLineRef (TextLine & tl) : tl (tl) 130 | { } 131 | TextLineRef (const TextLineRef & tlf) : tl (tlf.tl) 132 | { } 133 | size_t size () const { return tl.size (); } 134 | char operator [] (size_t n) const { return tl [n]; } 135 | std::string substr (size_t n, size_t fin= std::string::npos) const 136 | { return tl.substr (n, fin); } 137 | 138 | void operator = (std::string snue) { tl= snue; } 139 | void operator += (char c) { tl+= c; } 140 | void operator += (const std::string & str) { tl+= str; } 141 | void operator += (const TextLine & tnue) { tl+= tnue; } 142 | void operator += (const TextLineRef & tlnue) { tl+= tlnue.tl; } 143 | 144 | size_t col2pos (Col col) const { return tl.col2pos (col); } 145 | 146 | void deletecharpos (size_t pos) { tl.deletecharpos (pos); } 147 | void insertchar (Col col, char c) { tl.insertchar (col, c); } 148 | void insertcharpos (size_t pos, char c) { tl.insertcharpos (pos, c); } 149 | void insert (const std::string & str) { tl.insert (str); } 150 | void replace (size_t pos, std::string::size_type l, 151 | const std::string & str) 152 | { tl.replace (pos, l, str); } 153 | 154 | friend std::ostream & operator << 155 | (std::ostream & os, const TextLineRef & tlr); 156 | private: 157 | TextLine & tl; 158 | }; 159 | 160 | inline std::ostream & operator << 161 | (std::ostream & os, const TextLineRef & tlr) 162 | { 163 | os << tlr.tl; 164 | return os; 165 | } 166 | 167 | class VecTextLine { 168 | public: 169 | typedef TextLineRef reference; 170 | typedef const TextLine & const_reference; 171 | 172 | VecTextLine (bool useutf8); 173 | ~VecTextLine (); 174 | VecTextLine (const VecTextLine &); 175 | private: 176 | void operator = (const VecTextLine &); 177 | public: 178 | void swap (VecTextLine & other); 179 | 180 | class range : public std::out_of_range { 181 | public: 182 | range (const std::string & str) : 183 | out_of_range ("VecTextLine index out of range: " + 184 | str) 185 | { } 186 | }; 187 | 188 | bool empty () const; 189 | size_t size () const; 190 | 191 | void clear (); 192 | void push_back (); 193 | void push_back (const std::string & str); 194 | void insert_at (size_t n); 195 | void insert_at (size_t n, const std::string & str); 196 | void erase (size_t n); 197 | 198 | const_reference operator [] (size_t n) const; 199 | reference operator [] (size_t n); 200 | 201 | class iterator { 202 | friend class VecTextLine; 203 | iterator (const VecTextLine & vtl, size_t pos) : 204 | vtl (vtl), pos (pos) 205 | { } 206 | public: 207 | const TextLine & operator * () const { return vtl [pos]; } 208 | iterator & operator ++ () 209 | { 210 | if (pos == size_t (-1) || pos >= vtl.size () ) 211 | throw range ("in operator ++"); 212 | ++pos; 213 | return * this; 214 | } 215 | iterator operator ++ (int) 216 | { 217 | if (pos == size_t (-1) || pos >= vtl.size () ) 218 | throw range ("in operator ++"); 219 | iterator it (* this); 220 | ++pos; 221 | return it; 222 | } 223 | bool operator != (const iterator it) const 224 | { 225 | return & vtl != & it.vtl || pos != it.pos; 226 | } 227 | private: 228 | const VecTextLine & vtl; 229 | size_t pos; 230 | }; 231 | typedef const iterator const_iterator; 232 | 233 | iterator begin () { return iterator (* this, 0); } 234 | const_iterator begin () const { return iterator (* this, 0); } 235 | const_iterator end () const 236 | { return iterator (* this, vtl.size () ); } 237 | private: 238 | std::vector vtl; 239 | bool flagutf8; 240 | }; 241 | 242 | #endif 243 | 244 | // Fin de textline.h 245 | -------------------------------------------------------------------------------- /menuscreen.cpp: -------------------------------------------------------------------------------- 1 | // menuscreen.cpp 2 | // Revision 27-jan-2006 3 | 4 | #include "screenimpl.h" 5 | #include "menu.h" 6 | 7 | #include "util.h" 8 | 9 | #include "trace.h" 10 | #undef ASSERT 11 | #include "qtreassert.h" 12 | 13 | #include 14 | #include 15 | 16 | using std::auto_ptr; 17 | using std::for_each; 18 | 19 | using util::dim_array; 20 | 21 | namespace { 22 | 23 | struct MenuOption { 24 | const char * str; 25 | union Func { 26 | void (ScreenImpl::*function) (); 27 | const char * perlfunc; 28 | Func (void (ScreenImpl::*function) () ) : 29 | function (function) 30 | { } 31 | Func (const char * perlfunc) : 32 | perlfunc (perlfunc) 33 | { } 34 | }; 35 | Func func; 36 | enum TypeOption { Function, Perl }; 37 | TypeOption type; 38 | 39 | MenuOption (const char * str, void (ScreenImpl::* function) () ) : 40 | str (str), func (function), type (Function) 41 | { } 42 | MenuOption (const char * str, const char * perlfunc) : 43 | str (str), func (perlfunc), type (Perl) 44 | { } 45 | Option * option (ScreenImpl & screen) const 46 | { 47 | auto_ptr paction; 48 | switch (type) 49 | { 50 | case Function: 51 | paction.reset (new ScreenActionFunction 52 | (screen, func.function) ); 53 | break; 54 | case Perl: 55 | paction.reset (new ScreenActionPerl 56 | (screen, func.perlfunc) ); 57 | break; 58 | default: 59 | break; 60 | } 61 | Option * popt= new Option (str, paction.get () ); 62 | paction.release (); 63 | return popt; 64 | } 65 | }; 66 | 67 | MenuOption 68 | mopFile []= { 69 | MenuOption ("&Open", "file_load"), 70 | MenuOption ("&New", "file_new"), 71 | MenuOption ("&Save", "file_save"), 72 | MenuOption ("save &As", "file_save_as"), 73 | MenuOption ("nex&T", "file_next"), 74 | MenuOption ("&Close", "file_close"), 75 | MenuOption ("e&Xit", "file_quit"), 76 | MenuOption ("s&Elect", & ScreenImpl::optionFileSelect), 77 | MenuOption ("op&Tions", & ScreenImpl::optionFileOptions), 78 | }, 79 | 80 | mopEdit []= { 81 | MenuOption ("&Select", "toggle_select"), 82 | MenuOption ("cu&T", "cut"), 83 | MenuOption ("&Copy", "copy"), 84 | MenuOption ("&Paste", "paste"), 85 | MenuOption ("&Delete", "delete_selection"), 86 | MenuOption ("sel. &Todo", "select_all"), 87 | MenuOption ("copy to &New", "copy_new_file"), 88 | MenuOption ("&Options", & ScreenImpl::optionEditOptions), 89 | }, 90 | mopFind []= { 91 | MenuOption ("&Find", & ScreenImpl::optionFindFind), 92 | MenuOption ("find &Again", & ScreenImpl::optionFindAgain), 93 | MenuOption ("&Replace", & ScreenImpl::optionFindReplace), 94 | }, 95 | mopGo []= { 96 | MenuOption ("&Begin", & ScreenImpl::optionGoBegin), 97 | MenuOption ("&End", & ScreenImpl::optionGoEnd), 98 | MenuOption ("line &Number", & ScreenImpl::optionGoLine), 99 | }, 100 | mopSystem []= { 101 | MenuOption ("&Shell", & ScreenImpl::optionSystemShell), 102 | MenuOption ("&Execute", & ScreenImpl::optionSystemExecute), 103 | MenuOption ("execute &Line", & ScreenImpl::optionSystemExecuteLine), 104 | MenuOption ("&Prompt", & ScreenImpl::optionSystemPrompt), 105 | }, 106 | mopPerl []= { 107 | MenuOption ("&Evaluate", & ScreenImpl::optionPerlEval), 108 | MenuOption ("evaluate &Selection", & ScreenImpl::optionPerlEvalSelection), 109 | MenuOption ("evaluate &Clipboard", & ScreenImpl::optionPerlEvalClipboard), 110 | MenuOption ("evaluate &Line", & ScreenImpl::optionPerlEvalLine), 111 | MenuOption ("&Define control", & ScreenImpl::optionPerlDefineControl), 112 | }, 113 | mopProgram []= { 114 | MenuOption ("&Compile", "compile"), 115 | MenuOption ("&Make", "make"), 116 | MenuOption ("&Options", "compile_options"), 117 | MenuOption ("m&An", "man"), 118 | MenuOption ("man o&F", "man_of"), 119 | }, 120 | mopHelp []= { 121 | MenuOption ("&Index", "help"), 122 | MenuOption ("&Perl functions", "help_perl"), 123 | MenuOption ("&About", "help_about"), 124 | }; 125 | 126 | class MenuOptionAdder { 127 | public: 128 | MenuOptionAdder (ScreenImpl & screen, Menu & menu); 129 | void operator () (const MenuOption & mop); 130 | private: 131 | ScreenImpl & screen; 132 | Menu & menu; 133 | }; 134 | 135 | 136 | MenuOptionAdder::MenuOptionAdder (ScreenImpl & screen, Menu & menu) : 137 | screen (screen), menu (menu) 138 | { 139 | TRF; 140 | } 141 | 142 | void MenuOptionAdder::operator () (const MenuOption & mop) 143 | { 144 | TRF; 145 | 146 | auto_ptr