home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / workbench / fv-220 / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-17  |  15.9 KB  |  553 lines

  1. /* fv is a binary file editor written by Chris Hooper (cdh@mtu.edu)
  2.  *    on 6-2-91 and has gone through many revisions since then.
  3.  *      Much inspiration was given by Bill Moore, the first real user!
  4.  *
  5.  *   Author:  CHRISTOPHER D HOOPER
  6.  *
  7.  *   fv source Copyright (c) 1992 - 1998  Chris Hooper
  8.  *
  9.  *   Modification and redistribution is strictly prohibited.
  10.  *   Sale of this software above media cost is prohibited.
  11.  *
  12.  *   Except for above two restrictions, this software may be used for
  13.  *       any purpose, commercial or private.
  14.  *
  15.  *   Disclaimer:  This product is fit for no use, foreign or domestic.
  16.  *                Use implies knowledge you intend to destroy something.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <curses.h>
  21. #include "main.h"
  22. #if !defined(Amiga) && !defined(OS9) && !defined(FreeBSD)
  23. #    include <malloc.h>
  24. #endif
  25. #include "screen.h"
  26. #include "pcurses.h"
  27.  
  28. #ifdef LINT
  29. #    include "lint.h"
  30. #endif
  31.  
  32. char *strdup();
  33.  
  34. char *help_main = "\
  35.               Main Display Keyboard Mappings (brief)            \n\
  36. -------------------------------------------------------------------    \n\
  37.          0G()   = Start/End/Top/Bottom                    \n\
  38.          hjkl   = Scrolling, HJKL moves buffer view            \n\
  39.          {Enter}= Edit string or hex                    \n\
  40.          {Tab}  = Toggle string/hex edit mode                \n\
  41.          wq^X   = Finished editing                     \n\
  42.          m'     = Set/Go to mark                        \n\
  43.          twc    = Toggle hex/dec,word,character modes            \n\
  44.          a+-    = Toggle address mode,change columns            \n\
  45.          /?nN   = Search forward/backward/next                \n\
  46.          g      = Go to (jump) to hex address                \n\
  47.          []{}   = Location/Range display address divisor        \n\
  48.          AC     = Append/Create file from cursor to mark        \n\
  49.          udfb   = Half Up/Down, Full Forward/Back page            \n\
  50.          t<>    = Type (hex,dec,flt,dbl) Alignment up/down        \n\
  51.                                     \n\
  52.                                     \n\
  53. ===================================================================    \n\
  54.                                     \n\
  55.                                     \n\
  56.              Main Display Keyboard Mappings (detailed)            \n\
  57. -------------------------------------------------------------------    \n\
  58. 0-9      Enter number of times to perform command            \n\
  59. a        Address display on/off                        \n\
  60. A        Append from current cursor position until mark to file        \n\
  61. b        Back one full display page                    \n\
  62. ^B       Back one full display page                    \n\
  63. c        Character display on/off                    \n\
  64. C        Copy from current cursor position until mark to file        \n\
  65. ^C       Exit (do not ask to save)                    \n\
  66. d        Down one half display page                    \n\
  67. ^D       Down one half display page                    \n\
  68. f        Forward one full display page                    \n\
  69. F        Select new file from list given on command line        \n\
  70. ^F       Forward one full display page                    \n\
  71. g        Go to specific byte position (hex) in file            \n\
  72. G        Go to bottom of file                        \n\
  73. ^G       Show current filename and cursor position in file        \n\
  74. h        Cursor left                            \n\
  75. H        Buffer window left (fix cursor at file position)        \n\
  76. ^H       Provide Help screen, ? is Help Screen in other modes        \n\
  77. ^I       {tab}  Change word search mode (string or hex/dec)        \n\
  78. j        Cursor down                            \n\
  79. J        Buffer window down (fix cursor at file position)        \n\
  80. ^J       Edit at word (same as Return, either String or Hex)        \n\
  81. k        Cursor up                            \n\
  82. K        Buffer window up (fix cursor at file position)            \n\
  83. l        Cursor right                            \n\
  84. L        Buffer window right (fix cursor at file position)        \n\
  85. ^L       Redraw screen                            \n\
  86. m        Set mark at current file position (type mark character)    \n\
  87. M        Move cursor to middle of screen                \n\
  88. ^M       Edit at word (same as Return, either String or Hex)        \n\
  89. n        Search for next occurrence in current direction        \n\
  90. N        Reverse direction of search and look again            \n\
  91. o        Change character that shows for non-ASCII            \n\
  92. O        Change character that shows for zero                \n\
  93. q        Exit (ask to save if modified)                    \n\
  94. Q        Exit (do not ask to save)                    \n\
  95. r        Reread buffer and redisplay                    \n\
  96. R        Change Read-only mode                        \n\
  97. s        Change byte swapping mode (off, word, long)            \n\
  98. S        Toggle byte swapping cursor motion relative to chars/words    \n\
  99. t        Toggle word display type (hex, decimal)            \n\
  100. T        Cycle word display type (hex, decimal, float, or double)    \n\
  101. u        Up one half display page                    \n\
  102. ^U       Up one half display page                    \n\
  103. w        Toggle word display on/off                    \n\
  104. W        Write current buffer contents to file                \n\
  105. ^W       Write current buffer contents to file                \n\
  106. x        Exit (ask to save if modified)                    \n\
  107. ^X       Exit (ask to save if modified)                    \n\
  108. z        Set current line of display at top \"z<CR>\"; middle \"z.\";     \n\
  109.          bottom \"z-\"; or force bottom to top \"z+\" of display    \n\
  110. 0        Beginning page of file / location zero of file            \n\
  111. /        Search forward for String or Hex (depending on '^I' mode)    \n\
  112. ?        Search backward for String or Hex (depending on '^I' mode)    \n\
  113.          ? is used in other modes to provide help            \n\
  114. ^        Go to beginning of current display row                \n\
  115. $        Go to end of current display row                \n\
  116. +        Add more display columns (up to screen size)            \n\
  117. =        Add more display columns (up to screen size)            \n\
  118. -        Subtract display columns (down to a single word column)    \n\
  119. _        Subtract display columns (down to a single word column)    \n\
  120. '        Go to mark (type mark character)                \n\
  121. `        Go to mark (type mark character)                \n\
  122. (        Go to top / left of screen                    \n\
  123. )        Go to bottom / right of screen                    \n\
  124. <        Increase cursor alignment (1, 2, 4, 8 bytes)            \n\
  125. >        Decrease cursor alignment (8, 4, 2, 1 bytes)            \n\
  126. [        Double lower status address display divisor / modulus        \n\
  127. ]        Halve lower status address display divisor / modulus        \n\
  128. {        Double left address display divisor / modulus ('a' mode)    \n\
  129. }        Halve left address display divisor / modulus ('a' mode)    \n\
  130. \"        Toggle status range address modify between div and mod    \n\
  131. ~        Toggle left address modify between divisor & modulator        \n\
  132. .        Go to string edit mode and repeat last session commands    \n\
  133. :        Enter colon mode command                                       \n\
  134. ";
  135.  
  136.  
  137. char *help_hex = "\
  138.                 Hex Edit Mode            \n\
  139. ---------------------------------------------    \n\
  140. ^B    Move cursor left            \n\
  141. ^F    Move cursor right            \n\
  142. h    Move cursor left            \n\
  143. j    Move cursor down            \n\
  144. k    Move cursor up                \n\
  145. l    Move cursor right            \n\
  146. <CR>    Store word in file (same as ^M)        \n\
  147. q    Quit editing the string, do not store    \n\
  148. ^X    Quit editing the string, do not store    \n\
  149. <Del>    Move cursor left            \n\
  150. 0-9    Enter Hex digit 0-9            \n\
  151. a-f    Enter Hex digit a-f            \n\
  152. ^    Jump to start of line            \n\
  153. ?    Display this help            \n\
  154. ";
  155.  
  156.  
  157. char *help_string = "\
  158.                      String Edit Mode                \n\
  159. -------------------------------------------------------------    \n\
  160.                          ESC Mode:                \n\
  161. a    Add after cursor position, enter insert mode        \n\
  162. A    Add at end of string, enter insert mode            \n\
  163. b    Go to previous word                    \n\
  164. c    f   Delete including character, insert mode        \n\
  165. c    t   Delete to character, put in insert mode        \n\
  166. c    w   Delete word, put in insert mode            \n\
  167. c    ^   Delete to beginning of string, put in insert mode    \n\
  168. c    0   Delete to beginning of string, put in insert mode    \n\
  169. c    $   Delete to end of string, put in insert mode        \n\
  170. C    Change to end of string                    \n\
  171. d    f   Delete including character                \n\
  172. d    t   Delete to character                    \n\
  173. d    w   Delete word                        \n\
  174. d    ^   Delete to beginning of string                \n\
  175. d    0   Delete to beginning of string                \n\
  176. d    $   Delete to end of string                \n\
  177. D    Delete to end of string                    \n\
  178. e    Go to end of this word or next                \n\
  179. f    Go to next character typed                    \n\
  180. G    Go to end of string                    \n\
  181. h    Cursor left (same as backspace key)            \n\
  182. ^H   Cursor left (same as backspace key)            \n\
  183. i    Insert at cursor position, enter insert mode        \n\
  184. I    Insert at beginning of string, enter insert mode        \n\
  185. j    Cursor down                        \n\
  186. k    Cursor up                            \n\
  187. l    Cursor right                        \n\
  188. q    Quit editing the string, do not store            \n\
  189. r    Replace single character                    \n\
  190. R    Replace multiple characters (overstrike)            \n\
  191. s    Substitute for single character                \n\
  192. t    Go to character before next typed character        \n\
  193. T    Go to character before next typed character        \n\
  194. u    Undo last change                        \n\
  195. U    Undo all changes to string                    \n\
  196. w    Go to next word                        \n\
  197. x    Erase single character                    \n\
  198. 0    Go to beginning of string                    \n\
  199. $    Go to end of string                    \n\
  200. ~    Switch case of current alphabetic character        \n\
  201. .    Repeat last edit command                    \n\
  202. ^    Go to beginning of string                    \n\
  203. ^M   Finished editing (same as return)                \n\
  204. ^X   Quit editing the string, do not store            \n\
  205. ?    Display this help information                \n\
  206. ESC  Enter ESC command mode                    \n\
  207.                                 \n\
  208.                      Insert Mode only:                \n\
  209. ^H    Delete left of cursor (same as backspace key)        \n\
  210. ^V    Add next raw character to string            \n\
  211. ";
  212.  
  213.  
  214. char *help_prompt = "\
  215.         File name prompt editor            \n\
  216. ----------------------------------------    \n\
  217. a    = Add after current cursor position    \n\
  218. A    = Add at end of name            \n\
  219. c    = Change w=word t=to (character)        \n\
  220. d    = Delete w=word t=to (character)        \n\
  221. h    = Cursor Left                \n\
  222. i    = Insert at current cursor position    \n\
  223. I    = Insert at beginning of name         \n\
  224. j    = Cursor Right                \n\
  225. k    = Cursor Left                \n\
  226. l    = Cursor Right                \n\
  227. r    = Replace single character            \n\
  228. s    = Substitute for single character        \n\
  229. 0    = Go to beginning of name            \n\
  230. ^    = Go to beginning of name            \n\
  231. $    = Go to end of name            \n\
  232. u    = Undo last edit                \n\
  233. U    = Undo all edits to name            \n\
  234. ^H   = Delete left of cursor            \n\
  235. ^U   = Erase line                \n\
  236. ^V   = Next character is raw            \n\
  237. ESC  = Escape (command mode) from insert    \n\
  238. ";
  239.  
  240.  
  241. char *help_select = "\
  242.        Select file help            \n\
  243. -------------------------------        \n\
  244. b     = Move cursor left        \n\
  245. f     = Move cursor right        \n\
  246. h     = Move cursor left        \n\
  247. l     = Move cursor right        \n\
  248. q     = Quit without selecting        \n\
  249. <CR>  = Select new file to edit        \n\
  250. $     = Go to last file            \n\
  251. 0     = Go to first file        \n\
  252. ^     = Go to first file        \n\
  253. %     = Go to current file        \n\
  254. <Tab> = Go to next file (wraps)        \n\
  255. ?     = Display this help        \n\
  256. ^L    = Refresh (redraw) screen        \n\
  257. ";
  258.  
  259. #ifdef COLON_MODE
  260. char *help_colon = "\
  261.              Colon prompt help             \n\
  262. ------------------------------------------    \n\
  263.     :e  = Edit new filename(s)            \n\
  264.     :h  = This help information            \n\
  265.     :n  = Go to next file            \n\
  266.     :p  = Go to previous file            \n\
  267.     :q  = Quit fv                \n\
  268.     :q! = Quit fv without saving        \n\
  269.     :r  = Go to first file            \n\
  270.     :w  = Write current buffer            \n\
  271.     :wq = Write current buffer and exit        \n\
  272.     :x  = Exit and write if needed        \n\
  273.                         \n\
  274. Press ^H in main editor for keystroke help    \n\
  275. ";
  276. #endif
  277.  
  278. char *help_oops = "\
  279. FV has detected an internal error, #            \n\
  280.                         \n\
  281. Please report this to the author, including    \n\
  282. a brief description of what you were attempting    \n\
  283. to do and which mode the editor was in.        \n\
  284. ";
  285.  
  286. WINDOW *help_window = NULL;
  287. void help_me_text();
  288.  
  289.  
  290. void help_me(which)
  291. int which;
  292. {
  293.     if (noscreen)
  294.         return;
  295.  
  296.     switch (which) {
  297.         case 0:        /* main */
  298.         help_me_text(help_main);
  299.         break;
  300.         case 1:        /* hex editor */
  301.         help_me_text(help_hex);
  302.         break;
  303.         case 2:        /* string editor */
  304.         help_me_text(help_string);
  305.         break;
  306.         case 3:        /* prompt string */
  307.         help_me_text(help_prompt);
  308.         break;
  309.         case 4:        /* file selector */
  310.         help_me_text(help_select);
  311.         break;
  312. #ifdef COLON_MODE
  313.         case 5:        /* colon mode */
  314.         help_me_text(help_colon);
  315.         break;
  316. #endif
  317.         default:
  318.         {
  319.         char *buf;
  320.         buf = strdup(help_oops);
  321.         sprintf(buf + 36, "%d.", which);
  322.         /* get rid of sprintf's '\0' */
  323.         buf[strlen(buf)] = ' ';
  324.         help_me_text(buf);
  325.         free(buf);
  326.         break;
  327.         }
  328.     }
  329. }
  330.  
  331. void help_me_text(str)
  332. char *str;
  333. {
  334.     int row;
  335.     int col;
  336.     int rows = 0;
  337.     int cols = 0;
  338.     int ccols = 1;
  339.     int scols = 0;
  340.     int srows = 0;
  341.     int index;
  342.     int temp;
  343.     int SCOLS;
  344.     int SLINES;
  345.     int ch;
  346.     char *ptr;
  347.     WINDOW *help_window;
  348.  
  349.     for (ptr = str; *ptr != '\0'; ptr++) {
  350.         ch = *ptr;
  351.         switch (ch) {
  352.         case '\n':
  353.             rows++;
  354.             if (ccols > cols)
  355.             cols = ccols;
  356.             ccols = 0;
  357.             scols = 0;
  358.             break;
  359.         case '\t':
  360.             scols += 8 - ((ccols + scols) & 7);
  361.             break;
  362.         case ' ':
  363.             scols++;
  364.             break;
  365.         default:
  366.             ccols += scols + 1;
  367.             scols = 0;
  368.         }
  369.     }
  370.  
  371.     recalc_screen:
  372.     SCOLS = COLS;
  373.     SLINES = LINES;
  374.     if (rows > SLINES - 6)
  375.         srows = SLINES - 6;
  376.     else
  377.         srows = rows;
  378.  
  379.     if (cols > SCOLS - 6)
  380.         scols = SCOLS - 6;
  381.     else
  382.         scols = cols;
  383.  
  384.     help_window = xnewwin(srows + 2, scols + 2,
  385.                               (SLINES - srows - 2) / 2, (SCOLS - scols - 2) / 2);
  386. #ifdef STAT_COLOR
  387.     wattron(help_window, STAT_COLOR);
  388. #endif
  389.     box(help_window, '|', '-');
  390. #ifdef CRSR_COLOR
  391.     wattron(help_window, CRSR_COLOR);
  392.     leaveok(help_window, TRUE);
  393. #else
  394.     leaveok(help_window, FALSE);
  395. #endif
  396.  
  397.     col = 0;
  398.     row = 0;
  399.     do {
  400.         /* move to start row in string */
  401.         for (ptr = str, index = 0; index < row; index++) {
  402.             for (; (ch = *ptr) != '\n'; ptr++)
  403.             if (ch == '\0')
  404.                 break;
  405.             ptr++;
  406.         }
  407.  
  408.         /* display up to srows rows from here */
  409.         for (index = 0; index < srows; index++) {
  410.             xmove(help_window, index + 1, 1);
  411.             for (temp = 0; (ch = *ptr) != '\n'; ptr++) {
  412.             if ((ch == '\0') || (temp >= col))
  413.                 break;
  414.             else if (ch == '\t')
  415.                 temp += 8 - (temp & 7);
  416.             else
  417.                 temp++;
  418.             if (temp > col)
  419.                 break;
  420.             }
  421.             ccols = 0;
  422.             for (; (ch = *ptr) != '\n'; ptr++) {
  423.             if (ch == '\0')
  424.                 break;
  425.             if (ch == '\t') {
  426.                 temp = 8 - ((ccols + col) & 7);
  427.                 while (temp--)
  428.                 if (ccols++ < scols)
  429.                     xaddch(help_window, ' ');
  430.             } else {
  431.                 if (ccols++ < scols)
  432.                 xaddch(help_window, ch);
  433.             }
  434.             }
  435.             for (; ccols < scols; ccols++)
  436.             xaddch(help_window, ' ');
  437.             ptr++;
  438.         }
  439.         xmove(help_window, srows + 1, scols + 1);
  440.         xrefresh(help_window);
  441.         ch = get_key();
  442.         if ((COLS != SCOLS) || (LINES != SLINES)) {
  443.             unget_key(ch);
  444.             delwin(help_window);
  445.             touchwin(main_window);
  446.             xrefresh(main_window);
  447.             goto recalc_screen;
  448.         }
  449.  
  450.         switch (ch) {
  451. #ifndef EMACS_FEEL
  452.             case 2:    /* ^B */
  453. #endif
  454.             case 'b':
  455.             row -= srows;
  456.             if (row < 0)
  457.                 row = 0;
  458.             break;
  459.             case 4:    /* ^D */
  460.             row += srows / 2;
  461.             if (row > rows - srows)
  462.                 row = rows - srows;
  463.             break;
  464.             case ' ':
  465.             if (row == rows - srows)
  466.                 ch = 13;
  467. #ifndef EMACS_FEEL
  468.             case 6:    /* ^F */
  469. #endif
  470.             case 'f':
  471.             row += srows;
  472.             if (row > rows - srows)
  473.                 row = rows - srows;
  474.             break;
  475.             case 'h':
  476.             case 'H':
  477. #ifdef EMACS_FEEL
  478.             case 2:    /* ^B */
  479. #endif
  480. #ifdef KEY_LEFT
  481.             case KEY_LEFT:
  482. #endif
  483.             if (col > 0)
  484.                 col--;
  485.             break;
  486.             case 'j':
  487.             case 'J':
  488.             case 14:    /* ^N */
  489. #ifdef KEY_DOWN
  490.             case KEY_DOWN:
  491. #endif
  492.             if (row < rows - srows)
  493.                 row++;
  494.             break;
  495.             case 'k':
  496.             case 'K':
  497.             case 16:    /* ^P */
  498. #ifdef KEY_UP
  499.             case KEY_UP:
  500. #endif
  501.             if (row > 0)
  502.                 row--;
  503.             break;
  504.             case 12:    /* ^L */
  505.             xclear(stdscr);
  506.             xmove(stdscr, 0, 0);
  507.             xclrtobot(stdscr);
  508.             xtouchwin(main_window);
  509.             xtouchwin(status_window);
  510.             xtouchwin(help_window);
  511.             xrefresh(stdscr);
  512.             xrefresh(main_window);
  513.             xrefresh(status_window);
  514.             xrefresh(help_window);
  515.             break;
  516.             case 'l':
  517.             case 'L':
  518. #ifdef EMACS_FEEL
  519.             case 6:    /* ^F */
  520. #endif
  521. #ifdef KEY_RIGHT
  522.             case KEY_RIGHT:
  523. #endif
  524.             if (col < cols - scols)
  525.                 col++;
  526.             break;
  527.             case 'G':
  528.             row = rows - srows;
  529.             if (row < 0)
  530.                 row = 0;
  531.             break;
  532.             case 21:    /* ^U */
  533.             row -= srows / 2;
  534.             if (row < 0)
  535.                 row = 0;
  536.             break;
  537.             case 24:    /* ^X */
  538.             case 13:    /* ^M */
  539.             case 10:    /* ^R */
  540.             case 27:    /* ESC */
  541.             case 'q':
  542.             case 'x':
  543.             ch = 13;
  544.             break;
  545.             case '0':
  546.             row = 0;
  547.             break;
  548.         }
  549.     } while (ch != 13);    /* ^M */
  550.  
  551.     delwin(help_window);
  552. }
  553.