home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / FRUGALED.ZIP / FE.H < prev    next >
C/C++ Source or Header  |  1993-10-13  |  15KB  |  355 lines

  1. // FE.H
  2. //----------------------------------------------------------------------//
  3. //      [FE] FrugalEdit v1.0  (c) 1993 by S.C.Park, Esq. [shareware]    //
  4. //      Full Function Built-In Text Editor Library for Programmers      //
  5. //      Free personal use as stand-alone text editor / FE.EXE for DOS   //
  6. //      Based on ee.c (c) 1991 Yijun Ding (PD) / Written in Turbo C++   //
  7. //----------------------------------------------------------------------//
  8. // This should be included to call Fedit().
  9.  
  10. #include <conio.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #define LF '\n'
  14. #define EOL '\0'  
  15.  
  16. ////////// VARIABLE DECLARATIONS //////////
  17. int FeUserRoutine[4] = {  // Turn these on (1) to use
  18.                           // your own implementation
  19.     0,  //1,  // user's printing routine
  20.     0,  //1,  // user's shell routine
  21.     0,  //1,  // user's function selection (menu) routine
  22.     0   //1,  // user's file selection routine
  23.     };
  24. char *FeErr[20] = {
  25.     "None",
  26.     "Printer!",
  27.     "Not Enough Memory!",
  28.     "Window Too Small!",
  29.     "Disk Drive!",
  30.     "Cannot Open File!",
  31.     "User Abort!",
  32.     "Illegal Drive/Path!",
  33.     "Unknown Error!"
  34.     };
  35.  
  36. char friar[] = "<<FE>>";// Do NOT REMOVE THIS LINE!
  37. // It is used to find the location of the following defaults
  38. // by config.exe: [FE] configuration program.
  39.  
  40. // USING CONFIG.EXE INSTEAD OF CHANGING THE FOLLOWING IS RECOMMENDED.
  41. // Do NOT change the order of the comment line.
  42. // Order of functions are fixed.
  43. // Special keys: 
  44. // ^=Ctrl, @=Alt, &=Meta: one of two user selected keys
  45. // For Example, "^p" means Ctrl-p key.
  46. // For Meta key "^p" and "^q" are recommended.
  47. // Only LOWER CASE ALPHABET should be used with special keys. 
  48. // Do not use number keys (except for Function keys).
  49. // Function keys: #=Shifted
  50. // F11 and F12 keys are not supported.
  51. // Function keys should be in the form "F1", "#1", "@1", or "^1".
  52. // Upper class letter 'F' or shifting symbol plus number between 0-9.
  53. // Note F10 is symbolized by "F0".
  54.  
  55. char  FeKey [60][2] = {
  56.     "^c",    // function  0: show copyright notice
  57.              // TO CHANGE THE ABOVE KEY, YOU SHOULD REGISTER FIRST.
  58.     "@h",    // function  1: show internal help
  59.     "^h",    // function  2: view help documentation
  60.     "^p",    // function  3: meta key
  61.     "^q",    // function  4: meta key
  62.     "^a",    // function  5: block begin marking
  63.     "^k",    // function  6: block store (copy)
  64.     "&k",    // function  7: block cut
  65.     "^u",    // function  8: block paste
  66.     "^n",    // function  9: block print
  67.     "&n",    // function 10: block write (to file)
  68.     "^f",    // function 11: search forward
  69.     "&f",    // function 12: search backward
  70.     "^l",    // function 13: search again
  71.     "^r",    // function 14: replace all asking confirmation
  72.     "&r",    // function 15: replace without asking    
  73.     "^m",    // function 16: get more file (if any)
  74.     "&m",    // function 17: load new file (in another window)
  75.     "^z",    // function 18: save file and quit editing
  76.     "&z",    // function 19: save file in new name
  77.     "^y",    // function 20: delete one line (store in block buffer)
  78.     "^t",    // function 21: delete one word
  79.     "&t",    // function 22: delete from cursor to end of line
  80.     "^g",    // function 23: go to row
  81.     "&g",    // function 24: go to column
  82.     "^i",    // function 25: go to top of file
  83.     "&i",    // function 26: go to bottom of file
  84.     "^d",    // function 27: stamp date
  85.     "&d",    // function 28: stamp time
  86.     "^e",    // function 29: insert user's stamp
  87.     "&e",    // function 30: make user's stamp
  88.     "^j",    // function 31: insert formfeed (also Ctrl-Enter)
  89.     "^b",    // function 32: format paragraph (to fit in window)
  90.     "^x",    // function 33: execute a DOS command
  91.     "&x",    // function 34: go to DOS shell 
  92.     "F8",    // Function 35: show file size
  93.     "#8",    // Function 36: show memory size
  94.     "@8",    // function 37: show date/time 
  95.              // User Programmer Hooks Functions
  96.     "F9",    // Function 38: User implemented SHELL
  97.     "F0",    // Function 39: User implemented MENU
  98.              // Grouped functions - Two keys for each
  99.     "F2",    // Function 40: SEARCH and REPLACE
  100.     "@s",    // Function 41:  Forward/Backward/Again/Replace/alL
  101.     "F3",    // Function 42: FILE
  102.     "@f",    // Function 43:  Helpfile/Load/Quit
  103.     "F4",    // Function 44: BLOCK
  104.     "@k",    // Function 45:  Mar/Paste or Copy/cuT/priNt/Write
  105.     "F5",    // Function 46: MODE toggle
  106.     "^o",    // Function 47:  Wrap/Overwrite/Case/Tab/View
  107.     "F6",    // Function 48: STAMP
  108.     "@p",    // Function 49:  Both/Date/Time/User/Make
  109.              // Duplicate keys and reserved
  110.     "F1",    // function 50: show internal help
  111.     "F7",    // function 51: save file and quit editing
  112.     "  "
  113.     };
  114.  
  115. // COLORS
  116. int   FeC1 =  7;    // Edit window foreground
  117. int   FeC2 =  0;    //             background
  118. int   FeC3 =  0;    // Status line foreground
  119. int   FeC4 =  7;    //             background
  120. int   FeC5 =  7;    // Border      foreground
  121. int   FeC6 =  0;    //             background
  122. int   FeC7 =  0;    // Blocked text && Help window
  123. int   FeC8 =  7;    // Reverse of Edit window is recommended
  124.  
  125. int FeLeft   = 0;     // if 0, use whole screen.
  126. int FeTop    = 1;     // otherwise, window coordinates
  127. int FeRight  = 80;    // including statuse line at bottom
  128. int FeBottom = 25;    // and borders, if any.
  129.  
  130. int FeTabsize = 4;
  131. int FeBorder = 0;    // 0=none, 1=horizontal, 2=vertical, 3=both
  132. int FeBorderStr = 1; // 1=single line┌─┐, 2=double╔═╗, 3=block▄▄▄
  133. int FeSaveScr = 1;   // 0=no, 1=yes
  134.  
  135. int FeNoShell = 0;   // do not allow shelling out to DOS
  136. int FeView = 0;      // start with view mode (1= no editing allowed)
  137. int FeSensitive = 0; // default 0 = no; 1 = yes; for search/replace
  138. int FeWrap = 1;      // start in word wrap mode
  139. int FePrint = 0;     // use default printer initialization
  140.  
  141. int FeNoNewFile = 0; // edit given existing file only
  142.                      // should be 1 for built-in editor
  143. int FeNoOther = 0;   // do not allow multiple files
  144. int FeNoHelpline = 0;// do not show help message on status line
  145. int FeSilence = 0;   // do not buz (ring bell) on error
  146. int FeBackup = 1;    // leave back up when saving
  147.  
  148. int   FePrintBuf [40] = {      // initial printer control codes
  149.     // for EPSON LQ-2500
  150.     27, 120,   0,  // letter quality = draft
  151.     27,  77,       // pitch = elite = 96 cpi
  152.     27, 108,  10,  // left margin = 10
  153.     27,  81,  96,  // right margin = 96
  154.     10,  10,  10,  10,  10, // top margin = 5 lines
  155.     27,  67,  66,  // page length = 66 lines
  156.     27,  78,  10,  // skip at bottom = 10 lines
  157.                    // bottom margin = 5 lines
  158.     999  }; // Required to end initializing
  159.  
  160. char FeHelpLine [50] = // Do NOT change this line
  161.     // change the next line to show correct keys
  162.     // or to show whatever you want on the status line
  163.     " [FE] F1=Help F2=Search F3=File F4=Block ";
  164.  
  165. char FeHelpText [4096] = "\
  166.  EDITING KEY HELP   [FE] Frugal Edit v1.0 (c) \n\
  167.  ============================================ \n\
  168.  GROUPED FUNCTIONS - main key - another below \n\
  169.  -------------------------------------------- \n\
  170.  F1   HELP    Show this help                  \n\
  171.  F2   SEARCH  Forward/Back/Again/Replace/All  \n\
  172.  F3   FILE    More/Helpfile/Save/Load/Quit    \n\
  173.  F4   BLOCK   Mark/Copy/cuT/Paste/priNt/Write \n\
  174.  F5   MODE    Wrap/Overwrite/Case/Tab/View    \n\
  175.  F6   STAMP   Both/Date/Time/User/Make        \n\
  176.  F7   EXIT    Quit editing after saving       \n\
  177.  ============================================ \n\
  178.  FIXED BINDING KEYS - movement/block_marking  \n\
  179.  -------------------------------------------- \n\
  180.  ESC      Abort user_input/blocking/help      \n\
  181.  TAB      Insert/advance depending on mode    \n\
  182.  INSERT   Toggle insert/overwrite mode        \n\
  183.  ^PgUp    Go to top of file                   \n\
  184.  ^PgDown  Go to bottom of file                \n\
  185.  Other movement keys behave as expected       \n\
  186.  SHIFTED cursors/home/end begins BLOCKING     \n\
  187.  ============================================ \n\
  188.  No  Function    Key   Action                 \n\
  189.  -------------------------------------------- \n\
  190.  00  Copyright     ^c  Show copyright notice  \n\
  191.  01  HELP Short    @h  Show this help         \n\
  192.  02  HELP Doc      ^h  Show help document     \n\
  193.  03  META key      ^p  Meta key prefix        \n\
  194.  04  META key      ^q  Meta key prefix        \n\
  195.  05  BLOCK Mark    ^a  Start marking block    \n\
  196.  06  BLOCK Store   ^k  Store marked block     \n\
  197.  07  BLOCK Cut     &k  Cut (delete and store) \n\
  198.  08  BLOCK Paste   ^u  Paste stored block/line\n\
  199.  09  BLOCK Print   ^n  Print marked block     \n\
  200.  10  BLOCK Write   &n  Write to disk file     \n\
  201.  11  SEARCH For    ^f  Search string forward  \n\
  202.  12  SEARCH Back   &f  Search string backward \n\
  203.  13  SEARCH Again  ^l  Search again for/back  \n\
  204.  14  REPLACE Ask   ^r  Replace after asking   \n\
  205.  15  REPLACE alL   &r  Replace without asking \n\
  206.  16  FILE More     ^m  Load more into buffer  \n\
  207.  17  FILE Load     &m  Load another file      \n\
  208.  18  FILE Quit     ^z  Save file and Quit     \n\
  209.  19  FILE SaveAs   &z  Save file in new name  \n\
  210.  20  DELETE Line   ^y  Delete one line/marked \n\
  211.  21  DELETE Word   ^t  Delete one word        \n\
  212.  22  DELETE to End &t  Delete to end of line  \n\
  213.  23  GOTO Row      ^g  Go to specified row    \n\
  214.  24  GOTO Column   &g  Go to specified column \n\
  215.  25  GOTO Top      ^i  Go to top of file      \n\
  216.  26  GOTO Bottom   &i  Go to bottom of file   \n\
  217.  27  STAMP Date    ^d  Insert today's date    \n\
  218.  28  STAMP Time    &d  Insert current time    \n\
  219.  29  STAMP User    ^e  Insert user made string\n\
  220.  30  STAMP Make    &e  Make user's stamp      \n\
  221.  31  FORMFEED      ^j  Insert formfeed/enter  \n\
  222.  32  FORMAT        ^b  Format paragraph       \n\
  223.  33  SHELL Line    ^x  Execute a DOS command  \n\
  224.  34  SHELL Goto    &x  Go to DOS shell        \n\
  225.  35  INFO file     F8  Show file size         \n\
  226.  36  INFO mem      #8  Show memory size       \n\
  227.  37  INFO now      @8  Show date/time         \n\
  228.  38  HOOK Shell    F9  [if implemented]       \n\
  229.  39  HOOK Menu     F0  [if implemented]       \n\
  230.  -------------------------------------------- \n\
  231.  No.s   GROUPED FUNCTIONS     KEYS            \n\
  232.  -------------------------------------------- \n\
  233.  40/41  SEARCH                F2     @s       \n\
  234.  42/43  FILE                  F3     @f       \n\
  235.  44/45  BLOCK                 F4     @k       \n\
  236.  46/47  MODE                  F5     ^o       \n\
  237.  48/49  STAMP                 F6     @p       \n\
  238.  -------------------------------------------- \n\
  239.  Duplicate Keys                               \n\
  240.  -------------------------------------------- \n\
  241.  50  HELP Short    F1  Show this help         \n\
  242.  51  FILE Quit     F7  Save file and Quit     \n\
  243.  52-59             RESERVED                   \n\
  244.  ============================================ \n\
  245.  Press ESC to exit                            \n";
  246.  
  247. ////////// FUNCTION DECLARATIONS //////////
  248.  
  249. int Fedit (char *filename, char *helpfilename,
  250.     int border, int border_str, int save_scr,
  251.     int left, int top, int right, int bottom,
  252.     int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8,
  253.     int tab_size, int line_no, int col_no, int no_shell,
  254.     int view, int sensitive, int wrap, int print,
  255.     int no_new_file, int no_other, int no_helpline, int silence, int backup,
  256.     char *string_input, unsigned text_buf_size);
  257. void FeHelp();  // command line options
  258.  
  259. char *FeDate(); // returns pointer to current date in 01-01-93 format
  260. char *FeTime(); // current time in 12:59am format
  261.  
  262. void FeBlockPrint( char *start, char *end );
  263. char *FeShell();
  264. int  FeMenu();
  265. char *FeGetName( char *prp );
  266.  
  267. //////////  H O O K S    F O R    U S E R S
  268. //////////  MAY BE MODIFIED BUT SHOULD NEVER BE DELETED
  269.  
  270. ///// user hook for block print
  271. // Turn FeUserRoutine[0] to use.
  272. // Note: text is stored as multiple strings
  273. //       replace '\0' with '\n' to print
  274. //       End of file marker is another '\0'.
  275. void FeBlockPrint( char *start, char *end )
  276. {
  277.     char *s;
  278.     s = start;
  279.     do {
  280.         if (*s && fputs (s, stdprn) <= 0) break;
  281.         fputc (LF, stdprn);
  282.         while (*s++ != EOL);
  283.     } while ((s < end));
  284.     fputc (LF, stdprn);
  285.     fflush (stdprn);
  286.     return;
  287. }
  288.  
  289. ///// For the following three routines,
  290. ///// whole screen will be saved before calling them and 
  291. ///// it will be restored on returning.
  292.  
  293. ///// user hook for shell
  294. // Using this as a shell to DOS, as in [FE],
  295. // is Not recommended for a built-in editor.
  296. // Proper use:  to show another help file or
  297. //              to provide a pick list.
  298. // Turn FeUserRoutine[1] on (=1) AND
  299. // turn on the NO_SHELL command line parameter.
  300. // If any string (pointer to allocated character array)
  301. // is returned, it will be inserted into text.
  302. // The string will be stored in user's stamp buffer.
  303. // Not bound in (stand-alone) FE.EXE.
  304.  
  305. char *FeShell()
  306. {
  307.     static char string[80]; // MAXIMUM = 80 character
  308.  
  309.     puts( " DESIRED TEXT: (up to 80 characters) ");
  310.     return( gets( string ) );
  311. }
  312.  
  313. ///// user hook for menu
  314. // I don't think any menu system is necessary 
  315. // because of the intuitive command structure of [FE]. 
  316. // However if you want, feel free to implement one 
  317. // so long as it returns an integal value of 
  318. // the selected function's number. (See, internal help - F1)
  319. // Turn FeUserRoutine[2] on (=1) to use.
  320. // Not bound in (stand-alone) FE.EXE.
  321.  
  322. int FeMenu()
  323. {
  324.     char  buf[80];
  325.     char *function;
  326.     int   number;
  327.  
  328.     cputs( " DESIRED FUNCTION'S NUMBER:     \b\b\b\b" );
  329.     function = gets( buf );
  330.     number = atoi( function ); // if fails, function0: show copyright notice
  331.     // if (!number) number = 1; // show help instead
  332.     return( number );
  333. }
  334.  
  335. ///// user hook for file selection system
  336. // Usually not required for built-in editor.
  337. // Used only if you allow the end-user 
  338. // access other files than the given one.
  339. // User implementation is Not recommeded, 
  340. // unless you are intending to use [FE] as a stand alone editor.
  341. // In such a case, the program should be free.
  342. // Turn FeUserRoutine[3] on (=1) to use.
  343.  
  344. char *FeGetName( char *prp )
  345. {
  346.     static char name[40];
  347.  
  348.     clrscr();
  349.     system( "dir /p" );
  350.     cputs( prp );
  351.     return( gets( name ) );
  352. }
  353.  
  354. // END OF FE.H
  355.