home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / STVI369G.ZIP / HELP.C < prev    next >
C/C++ Source or Header  |  1990-05-01  |  15KB  |  539 lines

  1. /* $Header: /nw/tony/src/stevie/src/RCS/help.c,v 1.9 89/08/06 09:50:09 tony Exp $
  2.  *
  3.  * Routine to display a command summary.
  4.  * (Dave Tutelman note:
  5.  *    I added the ability to page backwards and forwards through help.
  6.  *    In order to minimize the abuse to the existing code, I used
  7.  *    "goto"s and labeled each screen.  It's not the way I would have
  8.  *    done help from scratch, but it's not TOO ugly.
  9.  * )
  10.  */
  11.  
  12. #include <ctype.h>
  13. #include "stevie.h"
  14. #include "ascii.h"
  15. #include "keymap.h"
  16.  
  17. /* Macro to show help screen 'n'.
  18.  * If C supported label types, it'd be cleaner to do it that way. */
  19. #define    SHOWHELP( n )    switch(n) {        \
  20.             case 0: goto Screen0;   \
  21.             case 1: goto Screen1;    \
  22.             case 2: goto Screen2;    \
  23.             case 3: goto Screen3;    \
  24.             case 4: goto Screen4;    \
  25.             case 5: goto Screen5;    \
  26.             case 6: goto Screen6;    \
  27.             case 7: goto Screen7;    \
  28.             case 8: goto Screen8;   \
  29.             default: return (TRUE);    }
  30.  
  31. extern    char    *Version;
  32.  
  33. static    int    helprow;
  34. static    int    lastscreen = 0;        /* return to help in previous screen */
  35.  
  36. #ifdef    HELP
  37.  
  38. static    void    longline();
  39.  
  40. bool_t
  41. help()
  42. {
  43.     int k;
  44.  
  45.     SHOWHELP( lastscreen );        /* where did we quit help last ? */
  46.  
  47. /***********************************************************************
  48.  * Zeroth Screen : Index to the help screens.
  49.  ***********************************************************************/
  50.  
  51. Screen0:
  52.     CLS;
  53.     windgoto(helprow = 0, 0);
  54.  
  55. longline("\
  56.    Index to HELP Screens\n\
  57.    =====================\n\n");
  58. longline("\
  59.       0    Help index  (this screen)\n\
  60.       1    Positioning within file, adjusting the screen\n\
  61.       2    Character positioning\n\
  62.       3    Line positioning, marking & returning, undo & redo\n");
  63. longline("\
  64.       4    Insert & replace, words, sentences, paragraphs\n\
  65.       5    Operators, miscellaneous operations, yank & put\n\
  66.       6    \"Ex\" command line operations\n\
  67.       7    Set parameters\n\
  68.       8    System-specific features\n");
  69.  
  70.     windgoto(0, 52);
  71.     longline(Version);
  72.  
  73.     SHOWHELP( helpkey (0) );
  74.  
  75.  
  76. /***********************************************************************
  77.  * First Screen:   Positioning within file, Adjusting the Screen
  78.  ***********************************************************************/
  79.  
  80. Screen1:
  81.     CLS;
  82.     windgoto(helprow = 0, 0);
  83.  
  84. longline("\
  85.    Positioning within file\n\
  86.    =======================\n\
  87.       ^F             Forward screenfull\n\
  88.       ^B             Backward screenfull\n");
  89. longline("\
  90.       ^D             scroll down half screen\n\
  91.       ^U             scroll up half screen\n");
  92. longline("\
  93.       G              Goto line (end default)\n\
  94.       ]]             next function\n\
  95.       [[             previous function\n\
  96.       /re            next occurence of regular expression 're'\n");
  97. longline("\
  98.       ?re            prior occurence of regular expression 're'\n\
  99.       n              repeat last / or ?\n\
  100.       N              reverse last / or ?\n\
  101.       %              find matching (, ), {, }, [, or ]\n");
  102. longline("\
  103. \n\
  104.    Adjusting the screen\n\
  105.    ====================\n\
  106.       ^L             Redraw the screen\n\
  107.       ^E             scroll window down 1 line\n\
  108.       ^Y             scroll window up 1 line\n");
  109. longline("\
  110.       z<RETURN>      redraw, current line at top\n\
  111.       z-             ... at bottom\n\
  112.       z.             ... at center\n");
  113.  
  114.     SHOWHELP( helpkey (1) );
  115.  
  116.  
  117. /***********************************************************************
  118.  * Second Screen:   Character positioning
  119.  ***********************************************************************/
  120.  
  121. Screen2:
  122.     CLS;
  123.     windgoto(helprow = 0, 0);
  124.  
  125. longline("\
  126.    Character Positioning\n\
  127.    =====================\n\
  128.       ^              first non-white\n\
  129.       0              beginning of line\n\
  130.       $              end of line\n\
  131.       h              backward\n");
  132. longline("\
  133.       l              forward\n\
  134.       ^H             same as h\n\
  135.       space          same as l\n\
  136.       fx             find 'x' forward\n");
  137. longline("\
  138.       Fx             find 'x' backward\n\
  139.       tx             upto 'x' forward\n\
  140.       Tx             upto 'x' backward\n\
  141.       ;              Repeat last f, F, t, or T\n");
  142. longline("\
  143.       ,              inverse of ;\n\
  144.       |              to specified column\n\
  145.       %              find matching (, ), {, }, [, or ]\n");
  146.  
  147.     SHOWHELP( helpkey (2) );
  148.  
  149.  
  150. /***********************************************************************
  151.  * Third Screen:   Line Positioning, Marking and Returning
  152.  ***********************************************************************/
  153.  
  154. Screen3:
  155.     CLS;
  156.     windgoto(helprow = 0, 0);
  157.  
  158. longline("\
  159.     Line Positioning\n\
  160.     ================\n\
  161.     H           home window line\n\
  162.     L           last window line\n\
  163.     M           middle window line\n");
  164. longline("\
  165.     +           next line, at first non-white\n\
  166.     -           previous line, at first non-white\n\
  167.     CR          return, same as +\n\
  168.     j           next line, same column\n\
  169.     k           previous line, same column\n");
  170.  
  171. longline("\
  172. \n\
  173.     Marking and Returning\n\
  174.     =====================\n\
  175.     ``          previous context\n\
  176.     ''          ... at first non-white in line\n");
  177. longline("\
  178.     mx          mark position with letter 'x'\n\
  179.     `x          to mark 'x'\n\
  180.     'x          ... at first non-white in line\n");
  181.  
  182. longline("\n\
  183.     Undo  &  Redo\n\
  184.     =============\n\
  185.     u           undo last change\n\
  186.     U           restore current line\n\
  187.     .           repeat last change\n");
  188.  
  189.     SHOWHELP( helpkey (3) );
  190.  
  191.  
  192. /***********************************************************************
  193.  * Fourth Screen:   Insert & Replace,
  194.  ***********************************************************************/
  195.  
  196. Screen4:
  197.     CLS;
  198.     windgoto(helprow = 0, 0);
  199.  
  200. longline("\
  201.     Insert and Replace\n\
  202.     ==================\n\
  203.     a           append after cursor\n\
  204.     i           insert before cursor\n\
  205.     A           append at end of line\n\
  206.     I           insert before first non-blank\n");
  207. longline("\
  208.     o           open line below\n\
  209.     O           open line above\n\
  210.     rx          replace single char with 'x'\n\
  211.     R           replace characters\n");
  212. if (! P(P_TO))
  213. longline("\
  214.     ~           change case (upper/lower) of single char\n");
  215.  
  216. longline("\
  217. \n\
  218.     Words, sentences, paragraphs\n\
  219.     ============================\n\
  220.     w           word forward\n\
  221.     b           back word\n\
  222.     e           end of word\n\
  223.     )           to next sentence\n\
  224.     }           to next paragraph\n");
  225. longline("\
  226.     (           back sentence\n\
  227.     {           back paragraph\n\
  228.     W           blank delimited word\n\
  229.     B           back W\n\
  230.     E           to end of W\n");
  231.  
  232.     SHOWHELP( helpkey (4) );
  233.  
  234.  
  235. /***********************************************************************
  236.  * Fifth Screen:   Operators, Misc. operations, Yank & Put
  237.  ***********************************************************************/
  238.  
  239. Screen5:
  240.     CLS;
  241.     windgoto(helprow = 0, 0);
  242.  
  243. longline("\
  244.     Operators (double to affect lines)\n\
  245.     ==================================\n\
  246.     d           delete\n\
  247.     c           change\n");
  248. longline("\
  249.     <           left shift\n\
  250.     >           right shift\n\
  251.     y           yank to buffer\n\
  252.     !           filter lines (command name follows)\n");
  253. if (P(P_TO))
  254. longline("\
  255.     ~           reverse case (upper/lower)\n");
  256.  
  257. longline("\n\
  258.     Miscellaneous operations\n\
  259.     ========================\n\
  260.     C           change rest of line\n\
  261.     D           delete rest of line\n\
  262.     s           substitute chars\n");
  263. longline("\
  264.     S           substitute lines (not yet)\n\
  265.     J           join lines\n\
  266.     x           delete characters\n\
  267.     X           ... before cursor\n");
  268.  
  269. longline("\n\
  270.     Yank and Put\n\
  271.     ============\n\
  272.     p           put back text\n\
  273.     P           put before\n\
  274.     Y           yank lines");
  275.  
  276.     SHOWHELP( helpkey (5) );
  277.  
  278.  
  279. /***********************************************************************
  280.  * Sixth Screen:   Command-line operations
  281.  ***********************************************************************/
  282.  
  283. Screen6:
  284.     CLS;
  285.     windgoto(helprow = 0, 0);
  286.  
  287. longline("\
  288.     EX command-line operations\n\
  289.     ==========================\n");
  290. longline("\
  291.     :w          write back changes\n\
  292.     :wq         write and quit\n\
  293.     :x          write if modified, and quit\n\
  294.     :q          quit\n\
  295.     :q!         quit, discard changes\n\
  296.     :e name     edit file 'name'\n\
  297.     :e!         reedit, discard changes\n");
  298. if (P(P_TG))
  299. longline("\
  300.     :e #        edit alternate file\n");
  301. else
  302. longline("\
  303.     :e #        edit alternate file (also ctrl-^)\n");
  304. longline("\
  305.     :w name     write file 'name'\n\
  306.     :n          edit next file in arglist\n\
  307.     :N          edit prior file in arglist\n\
  308.     :rew        rewind arglist\n\
  309.     :f          show current file and lines\n");
  310. longline("\
  311.     :f file     change current file name\n\
  312.     :g/pat/p|d  global command (print or delete only)\n\
  313.     :s/p1/p2/   text substitution (trailing 'g' optional)\n\
  314.     :ta tag     to tag file entry 'tag'\n\
  315.     ^]          :ta, current word is tag\n");
  316. if (P(P_TG))
  317. longline("\
  318.     :untag      back to before last ':ta' (also ctrl-^)\n");
  319. longline("\
  320.     :sh         run an interactive shell\n\
  321.     :!cmd       execute a shell command\n\
  322. ");
  323.  
  324.     SHOWHELP( helpkey (6) );
  325.  
  326.  
  327. /***********************************************************************
  328.  * Seventh Screen:   Set parameters
  329.  ***********************************************************************/
  330.  
  331. Screen7:
  332.     CLS;
  333.     windgoto(helprow = 0, 0);
  334.  
  335. longline("\
  336.     Set Parameters\n\
  337.     ==============\n");
  338. longline("\
  339.     :set param-name[=param-value]   to set\n\
  340.     :set sm, :set nosm, :set co=23  examples\n\
  341.     :set all    display all values\n\
  342.     :set        display non-default values\n\n");
  343. longline("Abbrev, name, and current value:\n");
  344. hparm(P_AI); hparm(P_SM); longline("\n");
  345. hparm(P_BK); hparm(P_CO); longline("\n");
  346. hparm(P_TS); hparm(P_MO); longline("\n");
  347. hparm(P_IC); hparm(P_ML); longline("\n");
  348. hparm(P_TG); hparm(P_TO); longline("\n");
  349. hparm(P_EB); hparm(P_VB); longline("\n");
  350. hparm(P_LI); hparm(P_NU); longline("\n");
  351. hparm(P_SS); longline(" (# of lines for ^D, ^U)\n");
  352. hparm(P_LS); longline(" (show tabs, newlines graphically)\n");
  353. hparm(P_RP); longline(" (min # of lines to report on oper)\n");
  354. hparm(P_WS); longline(" (search wraps around end of file)\n");
  355. hparm(P_CR); longline(" (write newline to file as CR-LF)\n");
  356.  
  357.     SHOWHELP( helpkey (7) );
  358.  
  359.  
  360. /***********************************************************************
  361.  * Eighth Screen:   System-Specific Features for DOS and OS/2
  362.  ***********************************************************************/
  363.  
  364. Screen8:
  365.     CLS;
  366.     windgoto(helprow = 0, 0);
  367.  
  368. longline("\
  369.     MSDOS & OS/2 Special Keys\n\
  370.     =========================\n");
  371. longline("\
  372.     The cursor keypad does pretty much what you'd expect,\n");
  373. longline("\
  374.     as long as you're not in text entry mode:\n\
  375. \n\
  376.     Home, End, PgUp, PgDn, and the arrow keys navigate.\n\
  377.     Insert    enter text before cursor.\n\
  378.     Delete    delete character at the cursor.\n\n");
  379.  
  380. longline("\
  381.     Function Keys\n\
  382.     =============\n\
  383.     F1      Help\n\
  384.     F2      Next file (:n)             Shift-F2  discard changes (:n!)\n\
  385.     F3      Previous file (:N)         Shift-F3  discard changes (:N!)\n");
  386. longline("\
  387.     F4      Alternate file (:e #)      Shift-F4  discard changes (:e! #)\n\
  388.     F5      Rewind file list (:rew)    Shift-F5  discard changes (:rew!)\n\
  389.     F6      Next function (]])         Shift-F6  Prev. function ([[)\n\
  390.     F8      Global subst. (:1,$s/)\n\
  391.     F10     Save & quit (:x)           Shift-F10 discard changes (:q!)");
  392.  
  393.     SHOWHELP( helpkey (8) );
  394.  
  395. }
  396.  
  397.  
  398. /*    longline (p)
  399.  *    Put the string p into the buffer, expanding newlines.
  400.  */
  401. static void
  402. longline(p)
  403. char    *p;
  404. {
  405.     register char    *s;
  406.  
  407.     for ( s = p; *s ;s++ ) {
  408.         if ( *s == '\n' )
  409.             windgoto(++helprow, 0);
  410.         else
  411.             outchar(*s);
  412.     }
  413. }
  414.  
  415. /*    hparm (n)
  416.  *    Put the help info for param #n into the buffer.
  417.  */
  418. hparm (p)
  419.   int p;
  420. {
  421.     char    buf[25];
  422.     char    *bp;
  423.  
  424.     sprintf(buf, "     %6s  %-10s  ",
  425.             params[p].shortname, params[p].fullname);
  426.     bp = buf + strlen (buf);
  427.     if (params[p].flags & P_NUM)    /* numeric param */
  428.         sprintf(bp, "%-3d", params[p].value);
  429.     else {                /* Boolean param */
  430.         if (params[p].value)
  431.             strcpy (bp, "yes");
  432.         else
  433.             strcpy (bp, "no ");
  434.     }
  435.     longline (buf);
  436. }
  437.  
  438. /* Get keystroke and return instructions on what to do next.
  439.  * Argument is current help screen.
  440.  * Return value is target help screen, or -1 to quit help.
  441.  */
  442.  
  443. #ifdef DOS
  444. #  define    NSCREEN    8
  445. #else
  446. #ifdef OS2
  447. #  define    NSCREEN 8
  448. #else
  449. #  define    NSCREEN 7
  450. #endif
  451. #endif
  452.  
  453. int
  454. helpkey (n)
  455.   int n;
  456. {
  457.     static int    c = '\0';
  458.     int    prevkey;
  459.     char    banner [16];
  460.  
  461.     /* Start with instructions on navigating Help */
  462.     strcpy (banner, "PAGE 0 OF HELP");
  463.     banner [5] = (char)n + '0';
  464.     windgoto(helprow = Rows-4, 63);
  465.     longline(banner);
  466.     windgoto(helprow = Rows-3, 63);
  467.     longline("^^^^^^^^^^^^^^");
  468.     windgoto(helprow = Rows-2, 54);
  469.     longline("<Press Esc to quit Help>");
  470.     windgoto(helprow = Rows-1, 44);
  471.     longline("<Other keys navigate Help screens>\n");
  472.  
  473.     /* Now get keystrokes till we get a valid one */
  474.     while (1) {
  475.         prevkey = c;
  476.         c = vgetc();
  477.         switch (c) {
  478.           /* cases for Next Screen */
  479.           case ' ':      case '\t':
  480.           case '\n':      case '\r':    case '+':
  481.           case K_DARROW:
  482.           case 'f':      case CTRL('F'):
  483.           case CTRL('D'): case CTRL('Y'):
  484.           case 'n':      case 'N':    case CTRL('N'):
  485.           case 'j':
  486.             if (n < NSCREEN)    return (n+1);
  487.             break;
  488.  
  489.           /* cases for Previous Screen */
  490.           case BS:      case '-':
  491.           case K_UARROW:
  492.           case 'b':      case CTRL('B'):
  493.           case CTRL('U'): case CTRL('E'):
  494.           case 'p':      case 'P':    case CTRL('P'):
  495.           case 'k':
  496.             if (n > 0) return (n-1);
  497.             break;
  498.  
  499.           /* cases for Quit Help */
  500.           case ESC:
  501.           case 'Q':
  502.           case 'q':
  503.           case 'X':
  504.           case 'x':
  505.             lastscreen = n;        /* remember where we quit */
  506.             return (-1);
  507.  
  508.           /* "G" is presumed to be a "vi-style" go-to-line,
  509.            * except that we interpret it as go-to-screen.
  510.            */
  511.           case 'G':
  512.             /* If previous key was a number,
  513.              * we're already there.  Otherwise, go to
  514.              * last screen.
  515.              */
  516.             if (prevkey<(int)'0' || prevkey>NSCREEN+(int)'0')
  517.                 return (NSCREEN);
  518.             break;
  519.  
  520.           /* Default is screen number or invalid code */
  521.           default:
  522.             if (c>=(int)'0' && c<=NSCREEN+(int)'0')
  523.                 return ( c - (int)'0' );
  524.             break;
  525.         }
  526.     }
  527. }
  528.  
  529.  
  530. #else
  531.  
  532. bool_t
  533. help()
  534. {
  535.     msg("Sorry, help not configured");
  536.     return FALSE;
  537. }
  538. #endif
  539.