home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / pvic_10a.lzh / SRCE / help.c < prev    next >
C/C++ Source or Header  |  1998-06-09  |  13KB  |  392 lines

  1. #include <stdio.h>
  2. #include "pvic.h"
  3. #include "locdefs.h"
  4.  
  5.  
  6.  
  7.  
  8. #define LAST_HELP_PAGE         8
  9.  
  10.  
  11.  
  12. void help_param();
  13.  
  14.  
  15.  
  16.  
  17.  
  18. int help()
  19. {
  20.     static int current_help_page = 0;
  21.  
  22.     if(current_columns<80)return 1;
  23.  
  24.     for(;;)
  25.     {
  26.         termcap_out(termcap_clear_screen);
  27.         termcap_out(termcap_cursor_invisible);
  28.                 goto_screen_pos(0,0);
  29.     
  30.         switch(current_help_page)
  31.         {
  32.  
  33.             default:
  34.  
  35. fprintf(stdout,"Help Index\n");
  36. fprintf(stdout,"==========\n");
  37. fprintf(stdout,"0           Help Index (this screen)\n");
  38. fprintf(stdout,"1           Positioning within Files\n");
  39. fprintf(stdout,"            Adjusting the Screen\n");
  40. fprintf(stdout,"2           Character Positioning\n");
  41. fprintf(stdout,"3           Line Positioning\n");
  42. fprintf(stdout,"            Marking and Returning\n");
  43. fprintf(stdout,"            Undo and Redo\n");
  44. fprintf(stdout,"4           Insert and Replace\n");
  45. fprintf(stdout,"            Words, Sentences, Paragraphs\n");
  46. fprintf(stdout,"5           Operators\n");
  47. fprintf(stdout,"            Miscellaneous Operations\n");
  48. fprintf(stdout,"            Yank and Put\n");
  49. fprintf(stdout,"6           EX Command-Line Operations\n");
  50. fprintf(stdout,"7           Set Parameters\n");
  51. fprintf(stdout,"8           About PVIC");
  52.  
  53.             break;
  54.  
  55.             case 1:
  56.  
  57. fprintf(stdout,"Positioning within File\n");
  58. fprintf(stdout,"=======================\n");
  59. fprintf(stdout,"^F          forward screenfull\n");
  60. fprintf(stdout,"^B          backward screenfull\n");
  61. fprintf(stdout,"^D          scroll down half screen\n");
  62. fprintf(stdout,"^U          scroll up half screen\n");
  63. fprintf(stdout,"G           goto line (end default)\n");
  64. fprintf(stdout,"]]          next function\n");
  65. fprintf(stdout,"[[          previous function\n");
  66. fprintf(stdout,"/re         next occurence of regular expression 're'\n");
  67. fprintf(stdout,"?re         prior occurence of regular expression 're'\n");
  68. fprintf(stdout,"n           repeat last / or ?\n");
  69. fprintf(stdout,"N           reverse last / or ?\n");
  70. fprintf(stdout,"%%           find matching (, ), {, }, [, or ]\n");
  71. fprintf(stdout,"\n");
  72. fprintf(stdout,"Adjusting the Screen\n");
  73. fprintf(stdout,"====================\n");
  74. fprintf(stdout,"^L          redraw the screen\n");
  75. fprintf(stdout,"^E          scroll window down 1 line\n");
  76. fprintf(stdout,"^Y          scroll window up 1 line\n");
  77. fprintf(stdout,"z<RETURN>   redraw, current line at top\n");
  78. fprintf(stdout,"z-          ... at bottom\n");
  79. fprintf(stdout,"z.          ... at center");
  80.  
  81.             break;
  82.  
  83.             case 2:
  84.  
  85. fprintf(stdout,"Character Positioning\n");
  86. fprintf(stdout,"=====================\n");
  87. fprintf(stdout,"^           first non-white\n");
  88. fprintf(stdout,"0           beginning of line\n");
  89. fprintf(stdout,"$           end of line\n");
  90. fprintf(stdout,"h           backward\n");
  91. fprintf(stdout,"l           forward\n");
  92. fprintf(stdout,"^H          same as h\n");
  93. fprintf(stdout,"space       same as l\n");
  94. fprintf(stdout,"fx          find 'x' forward\n");
  95. fprintf(stdout,"Fx          find 'x' backward\n");
  96. fprintf(stdout,"tx          upto 'x' forward\n");
  97. fprintf(stdout,"Tx          upto 'x' backward\n");
  98. fprintf(stdout,";           Repeat last f, F, t, or T\n");
  99. fprintf(stdout,",           inverse of ;\n");
  100. fprintf(stdout,"|           to specified column\n");
  101. fprintf(stdout,"%%           find matching (, ), {, }, [, or ]");
  102.  
  103.             break;
  104.  
  105.             case 3:
  106.  
  107. fprintf(stdout,"Line Positioning\n");
  108. fprintf(stdout,"================\n");
  109. fprintf(stdout,"H           home window line\n");
  110. fprintf(stdout,"L           last window line\n");
  111. fprintf(stdout,"M           middle window line\n");
  112. fprintf(stdout,"+           next line, at first non-white\n");
  113. fprintf(stdout,"-           previous line, at first non-white\n");
  114. fprintf(stdout,"CR          return, same as +\n");
  115. fprintf(stdout,"j           next line, same column\n");
  116. fprintf(stdout,"k           previous line, same column\n");
  117. fprintf(stdout,"\n");
  118. fprintf(stdout,"Marking and Returning\n");
  119. fprintf(stdout,"=====================\n");
  120. fprintf(stdout,"``          previous context\n");
  121. fprintf(stdout,"''          ... at first non-white in line\n");
  122. fprintf(stdout,"mx          mark position with letter 'x'\n");
  123. fprintf(stdout,"`x          to mark 'x'\n");
  124. fprintf(stdout,"'x          ... at first non-white in line\n");
  125. fprintf(stdout,"\n");
  126. fprintf(stdout,"Undo and Redo\n");
  127. fprintf(stdout,"=============\n");
  128. fprintf(stdout,"u           undo last change\n");
  129. fprintf(stdout,"U           restore current line\n");
  130. fprintf(stdout,".           repeat last change");
  131.  
  132.             break;
  133.  
  134.             case 4:
  135.  
  136. fprintf(stdout,"Insert and Replace\n");
  137. fprintf(stdout,"==================\n");
  138. fprintf(stdout,"a           append after cursor\n");
  139. fprintf(stdout,"i           insert before cursor\n");
  140. fprintf(stdout,"A           append at end of line\n");
  141. fprintf(stdout,"I           insert before first non-blank\n");
  142. fprintf(stdout,"o           open line below\n");
  143. fprintf(stdout,"O           open line above\n");
  144. fprintf(stdout,"rx          replace single char with 'x'\n");
  145. fprintf(stdout,"R           replace characters\n");
  146. fprintf(stdout,"~           change case (upper/lower) of single char\n");
  147. fprintf(stdout,"\n");
  148. fprintf(stdout,"Words, Sentences, Paragraphs\n");
  149. fprintf(stdout,"============================\n");
  150. fprintf(stdout,"w           word forward\n");
  151. fprintf(stdout,"b           back word\n");
  152. fprintf(stdout,"e           end of word\n");
  153. fprintf(stdout,")           to next sentence\n");
  154. fprintf(stdout,"}           to next paragraph\n");
  155. fprintf(stdout,"(           back sentence\n");
  156. fprintf(stdout,"{           back paragraph\n");
  157. fprintf(stdout,"W           blank delimited word\n");
  158. fprintf(stdout,"B           back W\n");
  159. fprintf(stdout,"E           to end of W");
  160.  
  161.             break;
  162.  
  163.             case 5:
  164.  
  165. fprintf(stdout,"Operators (double to affect lines)\n");
  166. fprintf(stdout,"==================================\n");
  167. fprintf(stdout,"d           delete\n");
  168. fprintf(stdout,"c           change\n");
  169. fprintf(stdout,"<           left shift\n");
  170. fprintf(stdout,">           right shift\n");
  171. fprintf(stdout,"y           yank to buffer\n");
  172. fprintf(stdout,"!           filter lines (command name follows)\n");
  173. fprintf(stdout,"\n");
  174. fprintf(stdout,"Miscellaneous Operations\n");
  175. fprintf(stdout,"========================\n");
  176. fprintf(stdout,"C           change rest of line\n");
  177. fprintf(stdout,"D           delete rest of line\n");
  178. fprintf(stdout,"s           substitute chars\n");
  179. fprintf(stdout,"S           substitute lines (not yet)\n");
  180. fprintf(stdout,"J           join lines\n");
  181. fprintf(stdout,"x           delete characters\n");
  182. fprintf(stdout,"X           ... before cursor\n");
  183. fprintf(stdout,"\n");
  184. fprintf(stdout,"Yank and Put\n");
  185. fprintf(stdout,"============\n");
  186. fprintf(stdout,"p           put back text\n");
  187. fprintf(stdout,"P           put before\n");
  188. fprintf(stdout,"Y           yank lines");
  189.  
  190.             break;
  191.  
  192.             case 6:
  193.  
  194. fprintf(stdout,"EX Command-Line Operations                        ");
  195. fprintf(stdout,"Line specifiers\n");
  196. fprintf(stdout,"==========================                        ");
  197. fprintf(stdout,"===============\n");
  198. fprintf(stdout,":w          write back changes                    ");
  199. fprintf(stdout,"n     abs. line number\n");
  200. fprintf(stdout,":wq         write and quit                        ");
  201. fprintf(stdout,".     current line\n");
  202. fprintf(stdout,":x          write if modified, and quit           ");
  203. fprintf(stdout,"+n    relative to current\n");
  204. fprintf(stdout,":q          quit                                  ");
  205. fprintf(stdout,"-n    relative to current\n");
  206. fprintf(stdout,":q!         quit, discard changes                 ");
  207. fprintf(stdout,".+n   relative to current\n");
  208. fprintf(stdout,":e name     edit file 'name'                      ");
  209. fprintf(stdout,".-n   relative to current\n");
  210. fprintf(stdout,":e!         reedit, discard changes               ");
  211. fprintf(stdout,"1     first line\n");
  212. fprintf(stdout,":w name     write file 'name'                     ");
  213. fprintf(stdout,"$     last line\n");
  214. fprintf(stdout,":e #        edit alternate file                   ");
  215. fprintf(stdout,"'x    line at mark 'x'\n");
  216. fprintf(stdout,":r name     read file 'name' at '.'               \n");
  217. fprintf(stdout,":n          edit next file in arglist             ");
  218. fprintf(stdout,"Range specifiers\n");
  219. fprintf(stdout,":N          edit prior file in arglist            ");
  220. fprintf(stdout,"================\n");
  221. fprintf(stdout,":rew        rewind arglist                        ");
  222. fprintf(stdout,"first,last  range\n");
  223. fprintf(stdout,":f          show current file and lines           ");
  224. fprintf(stdout,"1,$         all\n");
  225. fprintf(stdout,":f file     change current file name              ");
  226. fprintf(stdout,"%%           all\n");
  227. fprintf(stdout,":g/pat/p|d  global command (print, delete only)   \n");
  228. fprintf(stdout,":s/p1/p2/g  text substitution ('g' is optional)   \n");
  229. fprintf(stdout,":j          join the current and next lines\n");
  230. fprintf(stdout,":sh         run an interactive shell\n");
  231. fprintf(stdout,":!cmd       execute a shell command");
  232.  
  233.             break;
  234.  
  235.             case 7:
  236.  
  237. fprintf(stdout,"Set Parameters\n");
  238. fprintf(stdout,"==============\n");
  239. fprintf(stdout,":set [no]param-name            set boolean parameters\n");
  240. fprintf(stdout,":set param-name=param-value    set other parameters\n");
  241. fprintf(stdout,":set all                       display all values\n");
  242. fprintf(stdout,":set                           display non-default values\n");
  243. fprintf(stdout,"\n");
  244. fprintf(stdout,"Abbrev, name, and current value:\n");
  245. help_param(PARAMETER_AUTOINDENT);help_param(PARAMETER_BACKUP);fprintf(stdout,"\n");
  246. help_param(PARAMETER_ERRORBELLS);help_param(PARAMETER_IGNORECASE);fprintf(stdout,"\n");
  247. help_param(PARAMETER_LINES);help_param(PARAMETER_MODELINES);fprintf(stdout,"\n");
  248. help_param(PARAMETER_NUMBER);help_param(PARAMETER_SHOWMATCH);fprintf(stdout,"\n");
  249. help_param(PARAMETER_SHOWMODE);help_param(PARAMETER_TABSTOP);fprintf(stdout,"\n");
  250. help_param(PARAMETER_LIST);fprintf(stdout," (show tabs, newlines graphically)\n");
  251. help_param(PARAMETER_REPORT);fprintf(stdout," (min # of lines to report on oper)\n");
  252. help_param(PARAMETER_SCROLL);fprintf(stdout," (# of lines for ^D, ^U)\n");
  253. help_param(PARAMETER_WRAPSCAN);fprintf(stdout," (search wraps around end of file)\n");
  254.  
  255.             break;
  256.  
  257.             case 8:
  258. fprintf(stdout,"About PVIC\n");
  259. fprintf(stdout,"==========\n");
  260. fprintf(stdout,"\n");
  261. fprintf(stdout,"%s\n",VERSION_STRING);
  262. fprintf(stdout,"\n");
  263. fprintf(stdout,"PVIC is a public domain Portable VI Clone, derived from\n");
  264. fprintf(stdout,"STEVIE 3.69B.\n");
  265.             break;
  266.         }
  267.  
  268.         if(current_help_page!=0)
  269.         {
  270.             goto_screen_pos(termcap_lines-3,termcap_columns-30);
  271.             fprintf(stdout,"Press '0' for index");
  272.         }
  273.         goto_screen_pos(termcap_lines-2,termcap_columns-30);
  274.         fprintf(stdout,"Press ESC to quit");
  275.         goto_screen_pos(termcap_lines-1,termcap_columns-30);
  276.         fprintf(stdout,"Other keys navigate screens");
  277.  
  278.         if(get_next_help_page(¤t_help_page)<0)
  279.         {
  280.             termcap_out(termcap_cursor_visible);
  281.             return 0;
  282.         }
  283.     }
  284.  
  285. }
  286.  
  287.  
  288.  
  289. /*      help_param (n)
  290.  *      Put the help info for param #n into the buffer.
  291.  */
  292. void help_param (p)
  293. int p;
  294. {
  295.     fprintf(stdout, "        %6s  %-10s  ",
  296.         params[p].shortname, params[p].fullname);
  297.     if(params[p].flags & NUMERIC_PARAMETER)
  298.         fprintf(stdout, "%-3d", params[p].value);
  299.     else 
  300.     {
  301.         if(params[p].value)fprintf(stdout,"yes");
  302.         else fprintf(stdout,"no ");
  303.     }
  304. }
  305.  
  306. /* Get keystroke and return instructions on what to do next.
  307.  * Argument is current help screen.
  308.  * Return value is target help screen, or -1 to quit help.
  309.  */
  310.  
  311.  
  312. int get_next_help_page(current_help_page)
  313. int *current_help_page;
  314. {
  315.     int c;
  316.  
  317.     /* Now get keystrokes till we get a valid one */
  318.     for(;;)
  319.     {
  320.         c=get_char_from_input_buffer();
  321.         switch(c)
  322.         {
  323.             /* Next screen. */
  324.             case ' ':       
  325.             case CTRL_I:
  326.             case CTRL_J:    
  327.             case CTRL_M:    
  328.             case '+':
  329.             case 'f':       
  330.             case CTRL_F:
  331.             case CTRL_D:    
  332.             case CTRL_Y:
  333.             case 'n':       
  334.             case 'N':     
  335.             case CTRL_N:
  336.             case 'j':
  337.             if(*current_help_page<LAST_HELP_PAGE)
  338.             {
  339.                 (*current_help_page)++;
  340.                 return *current_help_page;
  341.             }
  342.             break;
  343.  
  344.             /* Previous screen. */
  345.             case CTRL_H:    
  346.             case '-':
  347.             case 'b':       
  348.             case CTRL_B:
  349.             case CTRL_U: 
  350.             case CTRL_E:
  351.             case 'p':       
  352.             case 'P':     
  353.             case CTRL_P:
  354.             case 'k':
  355.             if(*current_help_page>0)
  356.             {
  357.                 (*current_help_page)--;
  358.                 return *current_help_page;
  359.             }
  360.             break;
  361.  
  362.                     /* Redraw. */
  363.                     case CTRL_L:
  364.                         return *current_help_page;
  365.  
  366.             /* Quit help. */
  367.             case ESC:
  368.             case 'Q':
  369.             case 'q':
  370.             case 'X':
  371.             case 'x':
  372.             return -1;
  373.  
  374.             case 'Z':
  375.                 if(get_char_from_input_buffer()=='Z')return -1;
  376.             break;
  377.  
  378.             /* Page number or invalid key. */
  379.             default:
  380.             if(c>='0' && c<=LAST_HELP_PAGE+'0')
  381.             {
  382.                 *current_help_page=c-'0';
  383.                 return *current_help_page;
  384.             }
  385.             break;
  386.         }
  387.     }
  388.  
  389.     return *current_help_page;
  390. }
  391.  
  392.