home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d352 / mg.lha / MG / src.LZH / mg / keymap.c < prev    next >
C/C++ Source or Header  |  1990-05-23  |  40KB  |  1,371 lines

  1. /*
  2.  * Keyboard maps.  This is character set dependent. The terminal specific
  3.  * parts of building the keymap has been moved to a better place. 
  4.  */
  5. #include    "no_dir.h"
  6. #include    "no_dired.h"
  7. #include    "no_backup.h"
  8. #include    "no_help.h"
  9. #include    "no_macro.h"
  10. #include    "no_metakey.h"
  11. #include    "do_eval.h"
  12. #include    "gosmacs.h"
  13. #include    "regexp.h"
  14. #include    "bsmap.h"
  15. #include    "notab.h"
  16. #include    "prefixregion.h"
  17. #undef        AMIGA
  18. #include    "system.h"
  19.  
  20. #ifdef        AMIGA
  21. #include    "do_menu.h"
  22. #include    "do_iconify.h"
  23. #include    "mouse.h"
  24. #include    "change_font.h"
  25. #include    "change_color.h"
  26. #include    "rexx.h"
  27. #endif
  28.  
  29. #include    "def.h"
  30. #include    "kbd.h"
  31.  
  32. #ifdef    ANSI
  33. #include <string.h>
  34. #endif
  35.  
  36. /*
  37.  * My one little static function. 
  38.  */
  39. static          name_fent
  40. PROTO((char *fname, int flag));
  41.  
  42. /*
  43.  * Defined by "basic.c". 
  44.  */
  45. extern int      gotobol();    /* Move to start of line     */
  46. extern int      backchar();    /* Move backward by characters     */
  47. extern int      gotoeol();    /* Move to end of line         */
  48. extern int      forwchar();    /* Move forward by characters     */
  49. extern int      gotobob();    /* Move to start of buffer     */
  50. extern int      gotoeob();    /* Move to end of buffer     */
  51. extern int      forwline();    /* Move forward by lines     */
  52. extern int      backline();    /* Move backward by lines     */
  53. extern int      forwpage();    /* Move forward by pages     */
  54. extern int      backpage();    /* Move backward by pages     */
  55. extern int      pagenext();    /* Page forward next window     */
  56. extern int      setmark();    /* Set mark             */
  57. extern int      swapmark();    /* Swap "." and mark         */
  58. extern int      gotoline();    /* Go to a specified line.     */
  59. #ifdef    GOSMACS
  60. extern int      forw1page();    /* move forward by lines     */
  61. extern int      back1page();    /* move back by lines         */
  62. #endif
  63.  
  64. /*
  65.  * Defined by "buffer.c". 
  66.  */
  67. extern int      listbuffers();    /* Display list of buffers     */
  68. extern int      usebuffer();    /* Switch a window to a buffer     */
  69. extern int      poptobuffer();    /* Other window to a buffer     */
  70. extern int      killbuffer();    /* Make a buffer go away.     */
  71. extern int      savebuffers();    /* Save unmodified buffers     */
  72. extern int      bufferinsert();    /* Insert buffer into another     */
  73. extern int      notmodified();    /* Reset modification flag     */
  74.  
  75. #ifndef NO_DIR
  76. /*
  77.  * Defined by "dir.c" 
  78.  */
  79. extern int      changedir();    /* change current directory     */
  80. extern int      showcwdir();    /* show current directory     */
  81.  
  82. #ifndef NO_DIRED
  83. /*
  84.  * defined by "dired.c" 
  85.  */
  86. extern int      dired();    /* dired             */
  87. extern int      d_findfile();    /* dired find file         */
  88. extern int      d_del();    /* dired mark for deletion     */
  89. extern int      d_undel();    /* dired unmark             */
  90. extern int      d_undelbak();    /* dired unmark backwards     */
  91. extern int      d_expunge();    /* dired expunge         */
  92. extern int      d_copy();    /* dired copy             */
  93. extern int      d_rename();    /* dired rename             */
  94. extern int      d_otherwindow();/* dired other window         */
  95. extern int      d_ffotherwindow();    /* dired find file other window */
  96. #endif
  97. #endif
  98.  
  99. /*
  100.  * Defined by "extend.c". 
  101.  */
  102. extern int      extend();    /* Extended commands.         */
  103. extern int      bindtokey();    /* Modify global key bindings.     */
  104. #ifdef DO_EVAL
  105. extern int      evalexpr();    /* Extended commands (again)     */
  106. extern int      evalbuffer();    /* Evaluate current buffer     */
  107. extern int      evalfile();    /* Evaluate a file         */
  108. #endif
  109.  
  110.  
  111. /*
  112.  * Defined by "bind.c". 
  113.  */
  114. extern int      localbind();    /* Modify mode key bindings.     */
  115. extern int      unbindtokey();    /* delete global binding     */
  116. extern int      localunbind();    /* delete local binding         */
  117. extern int      define_key();    /* Modify key in any map     */
  118.  
  119. /*
  120.  * Defined by "file.c". 
  121.  */
  122. extern int      filevisit();    /* Get a file, read write     */
  123. extern int      poptofile();    /* Get a file, other window     */
  124. extern int      filewrite();    /* Write a file             */
  125. extern int      filesave();    /* Save current file         */
  126. extern int      fileinsert();    /* Insert file into buffer     */
  127. extern int      revertbuffer();    /* revert buffer from file     */
  128. #ifndef NO_BACKUP
  129. extern int      makebkfile();    /* Control backups on saves     */
  130. #endif
  131.  
  132. /*
  133.  * defined by help.c 
  134.  */
  135. #ifndef NO_HELP
  136. extern int      desckey();    /* describe key             */
  137. extern int      wallchart();    /* Make wall chart.         */
  138. extern int      help_help();    /* help help             */
  139. extern int      apropos_command();    /* apropos             */
  140. #endif
  141.  
  142. /*
  143.  * defined by "kbd.c" 
  144.  */
  145. #ifndef    NO_METAKEY
  146. extern int      do_meta();    /* interpret meta keys         */
  147. #endif
  148. #ifdef    BSMAP
  149. extern int      bsmap();    /* backspace mapping         */
  150. #endif
  151. extern int      universal_argument();    /* Ctrl-U             */
  152. extern int      digit_argument();    /* M-1, etc.             */
  153. extern int      negative_argument();    /* M--                 */
  154. extern int      selfinsert();    /* Insert character         */
  155. extern int      rescan();    /* internal try again function     */
  156.  
  157. /*
  158.  * defined by "macro.c" 
  159.  */
  160. #ifndef NO_MACRO
  161. extern int      definemacro();    /* Begin macro             */
  162. extern int      finishmacro();    /* End macro             */
  163. extern int      executemacro();    /* Execute macro         */
  164. extern int      insertmacro();    /* Insert macro definition     */
  165. extern int      namemacro();    /* Name keyboard macro         */
  166. extern int      macroquery();    /* Query user during kbd macro     */
  167. extern int      macroset();    /* evalable macro definer     */
  168. #endif
  169.  
  170. /*
  171.  * Defined by "main.c". 
  172.  */
  173. extern int      ctrlg();    /* Abort out of things         */
  174. extern int      quit();        /* Quit                 */
  175.  
  176. /*
  177.  * Defined by "match.c" 
  178.  */
  179. extern int      showmatch();    /* Hack to show matching paren     */
  180.  
  181. /* defined by "modes.c" */
  182.  
  183. extern int      indentmode();    /* set auto-indent mode         */
  184. extern int      fillmode();    /* set word-wrap mode         */
  185. extern int      blinkparen();    /* Fake blink-matching-paren var */
  186. #ifdef    NOTAB
  187. extern int      notabmode();    /* no tab mode             */
  188. #endif
  189. extern int      overwrite();    /* overwrite mode         */
  190. extern int      set_default_mode();    /* set default modes         */
  191.  
  192. /*
  193.  * defined by "paragraph.c" - the paragraph justification code. 
  194.  */
  195. extern int      gotobop();    /* Move to start of paragraph.     */
  196. extern int      gotoeop();    /* Move to end of paragraph.     */
  197. extern int      fillpara();    /* Justify a paragraph.         */
  198. extern int      killpara();    /* Delete a paragraph.         */
  199. extern int      setfillcol();    /* Set fill column for justify. */
  200. extern int      fillword();    /* Insert char with word wrap.     */
  201.  
  202. /*
  203.  * Defined by "random.c". 
  204.  */
  205. extern int      showcpos();    /* Show the cursor position     */
  206. extern int      twiddle();    /* Twiddle characters         */
  207. extern int      quote();    /* Insert literal         */
  208. extern int      openline();    /* Open up a blank line         */
  209. extern int      newline();    /* Insert newline         */
  210. extern int      deblank();    /* Delete blank lines         */
  211. extern int      justone();    /* Delete extra whitespace     */
  212. extern int      delwhite();    /* Delete all whitespace     */
  213. extern int      indent();    /* Insert newline, then indent     */
  214. extern int      forwdel();    /* Forward delete         */
  215. extern int      backdel();    /* Backward delete in         */
  216. extern int      killline();    /* Kill forward             */
  217. extern int      yank();        /* Yank back from killbuffer.     */
  218. #ifdef NOTAB
  219. extern int      space_to_tabstop();
  220. #endif
  221.  
  222. #ifdef    REGEXP
  223. /*
  224.  * Defined by "re_search.c" 
  225.  */
  226. extern int      re_forwsearch();/* Regex search forward         */
  227. extern int      re_backsearch();/* Regex search backwards     */
  228. extern int      re_searchagain();    /* Repeat regex search command     */
  229. extern int      re_queryrepl();    /* Regex query replace         */
  230. extern int      setcasefold();    /* Set case fold in searches     */
  231. extern int      delmatchlines();/* Delete all lines matching     */
  232. extern int      delnonmatchlines();    /* Delete all lines not matching */
  233. extern int      cntmatchlines();/* Count matching lines         */
  234. extern int      cntnonmatchlines();    /* Count nonmatching lines     */
  235. #endif
  236.  
  237. /*
  238.  * Defined by "region.c". 
  239.  */
  240. extern int      killregion();    /* Kill region.             */
  241. extern int      copyregion();    /* Copy region to kill buffer.     */
  242. extern int      lowerregion();    /* Lower case region.         */
  243. extern int      upperregion();    /* Upper case region.         */
  244. #ifdef    PREFIXREGION
  245. extern int      prefixregion();    /* Prefix all lines in region     */
  246. extern int      setprefix();    /* Set line prefix string     */
  247. #endif
  248.  
  249. /*
  250.  * Defined by "search.c". 
  251.  */
  252. extern int      forwsearch();    /* Search forward         */
  253. extern int      backsearch();    /* Search backwards         */
  254. extern int      searchagain();    /* Repeat last search command     */
  255. extern int      forwisearch();    /* Incremental search forward     */
  256. extern int      backisearch();    /* Incremental search backwards */
  257. extern int      queryrepl();    /* Query replace         */
  258.  
  259. /*
  260.  * Defined by "spawn.c". 
  261.  */
  262. extern int      spawncli();    /* Run CLI in a subjob.         */
  263. #ifdef    VMS
  264. extern int      attachtoparent();    /* Attach to parent process     */
  265. #endif
  266.  
  267. /* defined by "version.c" */
  268.  
  269. extern int      showversion();    /* Show version numbers, etc.     */
  270.  
  271. /*
  272.  * Defined by "window.c". 
  273.  */
  274. extern int      reposition();    /* Reposition window         */
  275. extern int      refresh();    /* Refresh the screen         */
  276. extern int      nextwind();    /* Move to the next window     */
  277. #ifdef    GOSMACS
  278. extern int      prevwind();    /* Move to the previous window     */
  279. #endif
  280. extern int      onlywind();    /* Make current window only one */
  281. extern int      splitwind();    /* Split current window         */
  282. extern int      delwind();    /* Delete current window     */
  283. extern int      enlargewind();    /* Enlarge display window.     */
  284. extern int      shrinkwind();    /* Shrink window.         */
  285.  
  286. /*
  287.  * Defined by "word.c". 
  288.  */
  289. extern int      backword();    /* Backup by words         */
  290. extern int      forwword();    /* Advance by words         */
  291. extern int      upperword();    /* Upper case word.         */
  292. extern int      lowerword();    /* Lower case word.         */
  293. extern int      capword();    /* Initial capitalize word.     */
  294. extern int      delfword();    /* Delete forward word.         */
  295. extern int      delbword();    /* Delete backward word.     */
  296.  
  297. #ifdef    AMIGA
  298. #ifdef    DO_ICONIFY
  299. extern int      tticon();
  300. #endif
  301. #ifdef    DO_MENU
  302. extern int      amigamenu();    /* Menu function         */
  303. #endif
  304. #ifdef    MOUSE
  305. extern int      amigamouse();    /* Amiga mouse functions     */
  306. extern int      mgotobob();
  307. extern int      mforwdel();
  308. extern int      mdelwhite();
  309. extern int      mdelwind();
  310. extern int      mgotoeob();
  311. extern int      menlargewind();
  312. extern int      mkillline();
  313. extern int      mkillregion();
  314. extern int      mdelfword();
  315. extern int      mreposition();
  316. extern int      mbackpage();
  317. extern int      mforwpage();
  318. extern int      mshrinkwind();
  319. extern int      msplitwind();
  320. extern int      myank();
  321. #endif
  322.  
  323. extern int      togglewindow();    /* Defined by "ttyio.c"         */
  324. extern int      togglezooms();    /* ""         ""         */
  325.  
  326. #ifdef    CHANGE_FONT
  327. extern int      setfont();    /* Defined by "ttyio.c"         */
  328. #endif
  329.  
  330. #ifdef    CHANGE_COLOR
  331. /* functions to mess with the mode line rendition, window colors */
  332. extern int      ttmode();    /* Defined by "tty.c"         */
  333. extern int      tttext();    /* ""                 */
  334. extern int      textforeground();    /* ""                 */
  335. extern int      textbackground();    /* ""                 */
  336. extern int      modeforeground();    /* ""                 */
  337. extern int      modebackground();    /* ""                 */
  338. #endif
  339.  
  340. #ifdef    REXX
  341. /*
  342.  * Defined by "rexx.c". 
  343.  */
  344. extern int      rexxcommand();    /* Issue REXX command */
  345. extern int    rexxexitcommand();/* */ 
  346. extern int      rexxbuffer();    /* return buffer data */
  347. extern int      rexxbuflist();    /* return buffer list */
  348. extern int    rexxregion();    /* */
  349. extern int      rexxdisplay();    /* display a string in echo area */
  350. extern int      rexxinsert();    /* insert text into buffer */
  351. extern int      rexxline();    /* return line */
  352. extern int      rexxcomregion();/* execute region */
  353. extern int      rexxmark();    /* return mark data */
  354. extern int      rexxpoint();    /* return point data */
  355. extern int      rexxrequest();    /* request string from user */
  356. extern int      rexxreqbuf();    /* request buffer name from user */
  357. extern int      rexxreqfunc();    /* request function name from user */
  358. extern int    rexxreqmacro();    /* */
  359. extern int      rexxwindow();    /* return window data */
  360. extern int      rexxlock();    /* Lock to this rexx macro */
  361. extern int      rexxunlock();    /* Unlock current rexx macro */
  362. extern int      rexxwait();    /* Vanish the window and wait for rexx */
  363. extern int      rexxtopwindow();/* Pop the window to the top of it's screen */
  364. #endif
  365.  
  366. /*
  367.  * This file contains map segment definitions for adding function keys to
  368.  * keymap declarations.  Currently you can add things to the fundamental mode
  369.  * keymap and the dired mode keymap.  See the declaration of diredmap and
  370.  * fundmap for details. 
  371.  */
  372. #include "amiga_maps.h"
  373.  
  374. #endif                /* AMIGA */
  375.  
  376. /* initial keymap declarations, deepest first */
  377.  
  378. /*
  379.  * But first, the two struct functions that are the default for all cases.
  380.  * (NB - the keymap code just flat needs to be rewritten. It is both arcane,
  381.  * and profligate of space). 
  382.  */
  383.  
  384. static struct function rescan_default = {rescan, F_CFUNCT};
  385. static struct function selfinsert_default = {selfinsert, F_CFUNCT};
  386.  
  387. #ifndef NO_HELP
  388. static struct function cHcG[] = {
  389.                  {ctrlg, F_CFUNCT},    /* ^G */
  390.                  {help_help, F_CFUNCT},    /* ^H */
  391. };
  392. static struct function cHa[] = {
  393.                 {apropos_command, F_CFUNCT},    /* a */
  394.                 {wallchart, F_CFUNCT},    /* b */
  395.                 {desckey, F_CFUNCT},    /* c */
  396. };
  397. static struct KEYMAPE (2 + IMAPEXT) helpmap = {
  398.                     2,
  399.                     2 + IMAPEXT,
  400.                    &rescan_default,
  401.     {
  402.         {
  403.                             CCHR('G'), CCHR('H'), cHcG
  404.         }              ,
  405.         {
  406.                             'a', 'c', cHa
  407.         }              ,
  408.     }
  409. };
  410. #endif
  411.  
  412. static struct function cX4cF[] = {
  413.                   {poptofile, F_CFUNCT},    /* ^f */
  414.                   {ctrlg, F_CFUNCT},    /* ^g */
  415. };
  416. static struct function cX4b[] = {
  417.                  {poptobuffer, F_CFUNCT},    /* b */
  418.                  {rescan, F_CFUNCT},    /* c */
  419.                  {rescan, F_CFUNCT},    /* d */
  420.                  {rescan, F_CFUNCT},    /* e */
  421.                  {poptofile, F_CFUNCT},    /* f */
  422. };
  423. static struct KEYMAPE (2 + IMAPEXT) cX4map = {
  424.                     2,
  425.                     2 + IMAPEXT,
  426.                    &rescan_default,
  427.     {
  428.         {
  429.                             CCHR('F'), CCHR('G'), cX4cF
  430.         }              ,
  431.         {
  432.                             'b', 'f', cX4b
  433.         }              ,
  434.     }
  435. };
  436.  
  437. static struct function cXcB[] = {
  438.                  {listbuffers, F_CFUNCT},    /* ^B */
  439.                  {quit, F_CFUNCT},    /* ^C */
  440.                  {rescan, F_CFUNCT},    /* ^D */
  441.                  {rescan, F_CFUNCT},    /* ^E */
  442.                  {filevisit, F_CFUNCT},    /* ^F */
  443.                  {ctrlg, F_CFUNCT},    /* ^G */
  444. };
  445. static struct function cXcL[] = {
  446.                  {lowerregion, F_CFUNCT},    /* ^L */
  447.                  {rescan, F_CFUNCT},    /* ^M */
  448.                  {rescan, F_CFUNCT},    /* ^N */
  449.                  {deblank, F_CFUNCT},    /* ^O */
  450.                  {rescan, F_CFUNCT},    /* ^P */
  451.                  {rescan, F_CFUNCT},    /* ^Q */
  452.                  {rescan, F_CFUNCT},    /* ^R */
  453.                  {filesave, F_CFUNCT},    /* ^S */
  454.                  {rescan, F_CFUNCT},    /* ^T */
  455.                  {upperregion, F_CFUNCT},    /* ^U */
  456.                  {rescan, F_CFUNCT},    /* ^V */
  457.                  {filewrite, F_CFUNCT},    /* ^W */
  458.                  {swapmark, F_CFUNCT},    /* ^X */
  459. };
  460. #ifndef NO_MACRO
  461. static struct function cXlp[] = {
  462.                  {definemacro, F_CFUNCT},    /* ( */
  463.                  {finishmacro, F_CFUNCT},    /* ) */
  464. };
  465. #endif
  466. static struct function cX0[] = {
  467.                 {delwind, F_CFUNCT},    /* 0 */
  468.                 {onlywind, F_CFUNCT},    /* 1 */
  469.                 {splitwind, F_CFUNCT},    /* 2 */
  470.                 {rescan, F_CFUNCT},    /* 3 */
  471.                 {(
  472.                   int (*) ()) &cX4map, F_PREFIX},    /* 4 */
  473. };
  474. static struct function cXeq[] = {
  475.                  {showcpos, F_CFUNCT},    /* = */
  476. };
  477. static struct function cXcar[] = {
  478.                   {enlargewind, F_CFUNCT},    /* ^ */
  479.                   {rescan, F_CFUNCT},    /* _ */
  480.                   {rescan, F_CFUNCT},    /* ` */
  481.                   {rescan, F_CFUNCT},    /* a */
  482.                   {usebuffer, F_CFUNCT},    /* b */
  483.                   {rescan, F_CFUNCT},    /* c */
  484. #ifndef NO_DIRED
  485.                   {dired, F_CFUNCT},    /* d */
  486. #else
  487.                   {rescan, F_CFUNCT},    /* d */
  488. #endif
  489. #ifndef NO_MACRO
  490.                   {executemacro, F_CFUNCT},    /* e */
  491. #else
  492.                   {rescan, F_CFUNCT},    /* e */
  493. #endif
  494.                   {setfillcol, F_CFUNCT},    /* f */
  495.                   {rescan, F_CFUNCT},    /* g */
  496.                   {rescan, F_CFUNCT},    /* h */
  497.                   {fileinsert, F_CFUNCT},    /* i */
  498.                   {rescan, F_CFUNCT},    /* j */
  499.                   {killbuffer, F_CFUNCT},    /* k */
  500.                   {rescan, F_CFUNCT},    /* l */
  501.                   {rescan, F_CFUNCT},    /* m */
  502. #ifdef    GOSMACS
  503.                   {nextwind, F_CFUNCT},    /* n */
  504. #else
  505.                   {rescan, F_CFUNCT},    /* n */
  506. #endif
  507.                   {nextwind, F_CFUNCT},    /* o */
  508. #ifdef    GOSMACS
  509.                   {prevwind, F_CFUNCT},    /* p */
  510. #else
  511.                   {rescan, F_CFUNCT},    /* p */
  512. #endif
  513. #ifndef    NO_MACRO
  514.                   {macroquery, F_CFUNCT},    /* q */
  515. #else
  516.                   {rescan, F_CFUNCT},    /* q */
  517. #endif
  518.                   {rescan, F_CFUNCT},    /* r */
  519.                   {savebuffers, F_CFUNCT},    /* s */
  520. };
  521. #ifndef NO_MACRO
  522. static struct KEYMAPE (6 + IMAPEXT) cXmap = {
  523.                     6,
  524.                     6 + IMAPEXT,
  525. #else
  526. static struct KEYMAPE (5 + IMAPEXT) cXmap = {
  527.                     5,
  528.                     5 + IMAPEXT,
  529. #endif
  530.                    &rescan_default,
  531.     {
  532.         {
  533.                             CCHR('B'), CCHR('G'), cXcB
  534.         }              ,
  535.         {
  536.                             CCHR('L'), CCHR('X'), cXcL
  537.         }              ,
  538. #ifndef NO_MACRO
  539.         {
  540.                             '(', ')', cXlp
  541.         }              ,
  542. #endif
  543.         {
  544.                             '0', '4', cX0
  545.         }              ,
  546.         {
  547.                             '=', '=', cXeq
  548.         }              ,
  549.         {
  550.                             '^', 's', cXcar
  551.         }              ,
  552.     }
  553. };
  554.  
  555. static struct function metacG[] = {
  556.                    {ctrlg, F_CFUNCT},    /* ^G */
  557. };
  558. static struct function metacV[] = {
  559.                    {pagenext, F_CFUNCT},    /* ^V */
  560. };
  561. static struct function metasp[] = {
  562.                    {justone, F_CFUNCT},    /* space */
  563. };
  564. static struct function metapct[] = {
  565.                     {queryrepl, F_CFUNCT},    /* % */
  566. };
  567. static struct function metami[] = {
  568.                    {negative_argument, F_CFUNCT},    /* - */
  569.                    {rescan, F_CFUNCT},    /* . */
  570.                    {rescan, F_CFUNCT},    /* / */
  571.                    {digit_argument, F_CFUNCT},    /* 0 */
  572.                    {digit_argument, F_CFUNCT},    /* 1 */
  573.                    {digit_argument, F_CFUNCT},    /* 2 */
  574.                    {digit_argument, F_CFUNCT},    /* 3 */
  575.                    {digit_argument, F_CFUNCT},    /* 4 */
  576.                    {digit_argument, F_CFUNCT},    /* 5 */
  577.                    {digit_argument, F_CFUNCT},    /* 6 */
  578.                    {digit_argument, F_CFUNCT},    /* 7 */
  579.                    {digit_argument, F_CFUNCT},    /* 8 */
  580.                    {digit_argument, F_CFUNCT},    /* 9 */
  581.                    {rescan, F_CFUNCT},    /* : */
  582.                    {rescan, F_CFUNCT},    /* ; */
  583.                    {gotobob, F_CFUNCT},    /* < */
  584.                    {rescan, F_CFUNCT},    /* = */
  585.                    {gotoeob, F_CFUNCT},    /* > */
  586. };
  587. static struct function metalb[] = {
  588.                    {gotobop, F_CFUNCT},    /* [ */
  589.                    {delwhite, F_CFUNCT},    /* \ */
  590.                    {gotoeop, F_CFUNCT},    /* ] */
  591.                    {rescan, F_CFUNCT},    /* ^ */
  592.                    {rescan, F_CFUNCT},    /* _ */
  593.                    {rescan, F_CFUNCT},    /* ` */
  594.                    {rescan, F_CFUNCT},    /* a */
  595.                    {backword, F_CFUNCT},    /* b */
  596.                    {capword, F_CFUNCT},    /* c */
  597.                    {delfword, F_CFUNCT},    /* d */
  598.                    {rescan, F_CFUNCT},    /* e */
  599.                    {forwword, F_CFUNCT},    /* f */
  600. };
  601. static struct function metal[] = {
  602.                   {lowerword, F_CFUNCT},    /* l */
  603.                   {rescan, F_CFUNCT},    /* m */
  604.                   {rescan, F_CFUNCT},    /* n */
  605.                   {rescan, F_CFUNCT},    /* o */
  606.                   {rescan, F_CFUNCT},    /* p */
  607.                   {fillpara, F_CFUNCT},    /* q */
  608.                   {backsearch, F_CFUNCT},    /* r */
  609.                   {forwsearch, F_CFUNCT},    /* s */
  610.                   {rescan, F_CFUNCT},    /* t */
  611.                   {upperword, F_CFUNCT},    /* u */
  612.                   {backpage, F_CFUNCT},    /* v */
  613.                   {copyregion, F_CFUNCT},    /* w */
  614.                   {extend, F_CFUNCT},    /* x */
  615. };
  616. static struct function metatilde[] = {
  617.                       {notmodified, F_CFUNCT},    /* ~ */
  618.                       {delbword, F_CFUNCT},    /* DEL */
  619. };
  620. static struct KEYMAPE (8 + IMAPEXT) metamap = {
  621.                     8,
  622.                     8 + IMAPEXT,
  623.                    &rescan_default,
  624.     {
  625.         {
  626.                             CCHR('G'), CCHR('G'), metacG
  627.         }              ,
  628.         {
  629.                             CCHR('V'), CCHR('V'), metacV
  630.         }              ,
  631.         {
  632.                             ' ', ' ', metasp
  633.         }              ,
  634.         {
  635.                             '%', '%', metapct
  636.         }              ,
  637.         {
  638.                             '-', '>', metami
  639.         }              ,
  640.         {
  641.                             '[', 'f', metalb
  642.         }              ,
  643.         {
  644.                             'l', 'x', metal
  645.         }              ,
  646.         {
  647.                             '~', CCHR('?'), metatilde
  648.         }              ,
  649.     }
  650. };
  651.  
  652. static struct function fund_at[] = {
  653.                     {setmark, F_CFUNCT},    /* ^@ */
  654.                     {gotobol, F_CFUNCT},    /* ^A */
  655.                     {backchar, F_CFUNCT},    /* ^B */
  656.                     {rescan, F_CFUNCT},    /* ^C */
  657.                     {forwdel, F_CFUNCT},    /* ^D */
  658.                     {gotoeol, F_CFUNCT},    /* ^E */
  659.                     {forwchar, F_CFUNCT},    /* ^F */
  660.                     {ctrlg, F_CFUNCT},    /* ^G */
  661. #ifndef NO_HELP
  662.                     {(
  663.                       int (*) ()) &helpmap, F_PREFIX},    /* ^H */
  664. #else
  665.                     {rescan, F_CFUNCT},    /* ^H */
  666. #endif
  667.                     {selfinsert, F_CFUNCT},    /* ^I */
  668.                     {indent, F_CFUNCT},    /* ^J */
  669.                     {killline, F_CFUNCT},    /* ^K */
  670.                     {reposition, F_CFUNCT},    /* ^L */
  671.                     {newline, F_CFUNCT},    /* ^M */
  672.                     {forwline, F_CFUNCT},    /* ^N */
  673.                     {openline, F_CFUNCT},    /* ^O */
  674.                     {backline, F_CFUNCT},    /* ^P */
  675.                     {quote, F_CFUNCT},    /* ^Q */
  676.                     {backisearch, F_CFUNCT},    /* ^R */
  677.                     {forwisearch, F_CFUNCT},    /* ^S */
  678.                     {twiddle, F_CFUNCT},    /* ^T */
  679.                     {universal_argument, F_CFUNCT},    /* ^U */
  680.                     {forwpage, F_CFUNCT},    /* ^V */
  681.                     {killregion, F_CFUNCT},    /* ^W */
  682.                     {(int (*) ()) &cXmap, F_PREFIX},    /* ^X */
  683.                     {yank, F_CFUNCT},    /* ^Y */
  684. #ifndef VMS
  685.                     {spawncli, F_CFUNCT},    /* ^Z */
  686. #else
  687.                     {attachtoparent, F_CFUNCT},    /* ^Z */
  688. #endif
  689.                     {(int (*) ()) &metamap, F_PREFIX},    /* esc */
  690. };
  691. static struct function fund_del[] = {
  692.                      {backdel, F_CFUNCT},    /* DEL */
  693. };
  694.  
  695. #ifndef    FUND_XMAPS
  696. #define NFUND_XMAPS    0    /* extra map sections after normal ones */
  697. #endif
  698.  
  699. static struct KEYMAPE (2 + NFUND_XMAPS + IMAPEXT) fundmap = {
  700.                     2 + NFUND_XMAPS,
  701.                     2 + NFUND_XMAPS + IMAPEXT,
  702.                    &selfinsert_default,
  703.     {
  704.         {
  705.                             CCHR('@'), CCHR('['), fund_at
  706.         }              ,
  707.         {
  708.                             CCHR('?'), CCHR('?'), fund_del
  709.         }              ,
  710. #ifdef    FUND_XMAPS
  711.                         FUND_XMAPS,
  712. #endif
  713.     }
  714. };
  715.  
  716. static struct function fill_sp[] = {
  717.                     {fillword, F_CFUNCT},    /* ' ' */
  718. };
  719. static struct KEYMAPE (1 + IMAPEXT) fillmap = {
  720.                     1,
  721.                     1 + IMAPEXT,
  722.                    &rescan_default,
  723.     {
  724.         {
  725.                             ' ', ' ', fill_sp
  726.         }              ,
  727.     }
  728. };
  729.  
  730. static struct function indent_lf[] = {
  731.                       {newline, F_CFUNCT},    /* ^J */
  732.                       {rescan, F_CFUNCT},    /* ^K */
  733.                       {rescan, F_CFUNCT},    /* ^L */
  734.                       {indent, F_CFUNCT},    /* ^M */
  735. };
  736. static struct KEYMAPE (1 + IMAPEXT) indntmap = {
  737.                     1,
  738.                     1 + IMAPEXT,
  739.                    &rescan_default,
  740.     {
  741.         {
  742.                             CCHR('J'), CCHR('M'), indent_lf
  743.         }              ,
  744.     }
  745. };
  746. static struct function blink_rp[] = {
  747.                      {showmatch, F_CFUNCT},    /* ) */
  748. };
  749. static struct KEYMAPE (1 + IMAPEXT) blinkmap = {
  750.                     1,
  751.                     1 + IMAPEXT,
  752.                    &rescan_default,
  753.     {
  754.         {
  755.                             ')', ')', blink_rp
  756.         }              ,
  757.     }
  758. };
  759.  
  760. #ifdef    NOTAB
  761. static struct function notab_tab[] = {
  762.                       {space_to_tabstop, F_CFUNCT},    /* ^I */
  763. };
  764. static struct KEYMAPE (1 + IMAPEXT) notabmap = {
  765.                     1,
  766.                     1 + IMAPEXT,
  767.                    &rescan_default,
  768.     {
  769.         {
  770.                             CCHR('I'), CCHR('I'), notab_tab
  771.         }              ,
  772.     }
  773. };
  774. #endif
  775.  
  776. static struct KEYMAPE (1 + IMAPEXT) overwmap = {
  777.                     0,
  778.                     1 + IMAPEXT,    /* 1 to avoid 0 sized array */
  779.                    &rescan_default,
  780.     {
  781.         /* unused dummy entry for VMS C */
  782.         {
  783.                             (KCHAR) 0, (KCHAR) 0, NULL
  784.         }              ,
  785.     }
  786. };
  787.  
  788. #ifndef NO_DIRED
  789. static struct function dirednul[] = {
  790.                      {setmark, F_CFUNCT},    /* ^@ */
  791.                      {gotobol, F_CFUNCT},    /* ^A */
  792.                      {backchar, F_CFUNCT},    /* ^B */
  793.                      {rescan, F_CFUNCT},    /* ^C */
  794.                      {d_del, F_CFUNCT},    /* ^D */
  795.                      {gotoeol, F_CFUNCT},    /* ^E */
  796.                      {forwchar, F_CFUNCT},    /* ^F */
  797.                      {ctrlg, F_CFUNCT},    /* ^G */
  798. #ifndef NO_HELP
  799.                      {(
  800.                        int (*) ()) &helpmap, F_PREFIX},    /* ^H */
  801. #endif
  802. };
  803. static struct function diredcl[] = {
  804.                     {reposition, F_CFUNCT},    /* ^L */
  805.                     {forwline, F_CFUNCT},    /* ^M */
  806.                     {forwline, F_CFUNCT},    /* ^N */
  807.                     {rescan, F_CFUNCT},    /* ^O */
  808.                     {backline, F_CFUNCT},    /* ^P */
  809.                     {rescan, F_CFUNCT},    /* ^Q */
  810.                     {backisearch, F_CFUNCT},    /* ^R */
  811.                     {forwisearch, F_CFUNCT},    /* ^S */
  812.                     {rescan, F_CFUNCT},    /* ^T */
  813.                     {universal_argument, F_CFUNCT},    /* ^U */
  814.                     {forwpage, F_CFUNCT},    /* ^V */
  815.                     {rescan, F_CFUNCT},    /* ^W */
  816.                     {(
  817.                       int (*) ()) &cXmap, F_PREFIX},    /* ^X */
  818. };
  819. static struct function diredcz[] = {
  820. #ifndef VMS
  821.                     {spawncli, F_CFUNCT},    /* ^Z */
  822. #else
  823.                     {attachtoparent, F_CFUNCT},    /* ^Z */
  824. #endif
  825.                     {(
  826.                       int (*) ()) &metamap, F_PREFIX},    /* esc */
  827.                     {rescan, F_CFUNCT},    /* ^\ */
  828.                     {rescan, F_CFUNCT},    /* ^] */
  829.                     {rescan, F_CFUNCT},    /* ^^ */
  830.                     {rescan, F_CFUNCT},    /* ^_ */
  831.                     {forwline, F_CFUNCT},    /* SP */
  832. };
  833. static struct function diredc[] = {
  834.                    {d_copy, F_CFUNCT},    /* c */
  835.                    {d_del, F_CFUNCT},    /* d */
  836.                    {d_findfile, F_CFUNCT},    /* e */
  837.                    {d_findfile, F_CFUNCT},    /* f */
  838. };
  839. static struct function diredn[] = {
  840.                    {forwline, F_CFUNCT},    /* n */
  841.                    {d_ffotherwindow, F_CFUNCT},    /* o */
  842.                    {backline, F_CFUNCT},    /* p */
  843.                    {rescan, F_CFUNCT},    /* q */
  844.                    {d_rename, F_CFUNCT},    /* r */
  845.                    {rescan, F_CFUNCT},    /* s */
  846.                    {rescan, F_CFUNCT},    /* t */
  847.                    {d_undel, F_CFUNCT},    /* u */
  848.                    {rescan, F_CFUNCT},    /* v */
  849.                    {rescan, F_CFUNCT},    /* w */
  850.                    {d_expunge, F_CFUNCT},    /* x */
  851. };
  852. static struct function direddl[] = {
  853.                     {d_undelbak, F_CFUNCT},    /* del */
  854. };
  855.  
  856. #ifndef    DIRED_XMAPS
  857. #define    NDIRED_XMAPS    0    /* number of extra map sections */
  858. #endif
  859.  
  860. static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
  861.                     6 + NDIRED_XMAPS,
  862.                     6 + NDIRED_XMAPS + IMAPEXT,
  863.                    &rescan_default,
  864.     {
  865. #ifndef NO_HELP
  866.         {
  867.                             CCHR('@'), CCHR('H'), dirednul
  868.         }              ,
  869. #else
  870.         {
  871.                             CCHR('@'), CCHR('G'), dirednul
  872.         }              ,
  873. #endif
  874.         {
  875.                             CCHR('L'), CCHR('X'), diredcl
  876.         }              ,
  877.         {
  878.                             CCHR('Z'), ' ', diredcz
  879.         }              ,
  880.         {
  881.                             'c', 'f', diredc
  882.         }              ,
  883.         {
  884.                             'n', 'x', diredn
  885.         }              ,
  886.         {
  887.                             CCHR('?'), CCHR('?'), direddl
  888.         }              ,
  889. #ifdef    DIRED_XMAPS
  890.                         DIRED_XMAPS,    /* map sections for dired
  891.                          * mode keys     */
  892. #endif
  893.     }
  894. };
  895. #endif
  896.  
  897. /*
  898.  * give names to the maps, for use by help etc. If the map is to be bindable,
  899.  * it must also be listed in the function name table below with the same
  900.  * name. Maps created dynamicly currently don't get added here, thus are
  901.  * unnamed. Modes are just named keymaps with functions to add/subtract them
  902.  * from a buffer's list of modes.  If you change a mode name, change it in
  903.  * modes.c also. 
  904.  */
  905.  
  906. struct maps     map_table[] = {
  907. /* fundamental map MUST be first entry */
  908.                    {(struct keymap *) & fundmap, "fundamental"},
  909.                    {(struct keymap *) & fillmap, "fill"},
  910.                    {(struct keymap *) & indntmap, "indent"},
  911.                    {(struct keymap *) & blinkmap, "blink"},
  912. #ifdef    NOTAB
  913.                    {(struct keymap *) & notabmap, "notab"},
  914. #endif
  915.                    {(struct keymap *) & overwmap, "overwrite"},
  916.                    {(struct keymap *) & metamap, "esc prefix"},
  917.                    {(struct keymap *) & cXmap, "c-x prefix"},
  918.                    {(struct keymap *) & cX4map, "c-x 4 prefix"},
  919. #ifndef NO_HELP
  920.                    {(struct keymap *) & helpmap, "help"},
  921. #endif
  922. #ifndef NO_DIRED
  923.                    {(struct keymap *) & diredmap, "dired"},
  924. #endif
  925. };
  926.  
  927. #define NMAPS    (sizeof map_table/sizeof(struct maps))
  928. int             nmaps = NMAPS;    /* for use by rebind in extend.c */
  929.  
  930. char           *
  931. map_name(map)
  932.     struct keymap  *map;
  933. {
  934.     struct maps    *mp = &map_table[0];
  935.  
  936.     do {
  937.         if (mp->p_map == map)
  938.             return mp->p_name;
  939.     } while (++mp < &map_table[NMAPS]);
  940.     return (char *) NULL;
  941. }
  942.  
  943. struct maps    *
  944. name_mode(name)
  945.     char           *name;
  946. {
  947.     struct maps    *mp = &map_table[0];
  948.  
  949.     if (!name)
  950.         return NULL;
  951.     do {
  952.         if (strcmp(mp->p_name, name) == 0)
  953.             return mp;
  954.     } while (++mp < &map_table[NMAPS]);
  955.     return NULL;
  956. }
  957.  
  958. struct keymap  *
  959. name_map(name)
  960.     char           *name;
  961. {
  962.     struct maps    *mp;
  963.     return (mp = name_mode(name)) == NULL ? (struct keymap *) NULL : mp->p_map;
  964. }
  965.  
  966. /*
  967.  * Warning: functnames MUST be in alphabetical order!  (due to binary search
  968.  * in name_function.)  If the function is prefix, it must be listed with the
  969.  * same name in the map_table struct above. 
  970.  */
  971.  
  972. struct functnames functnames[] = {
  973. #ifdef    AMIGA
  974. #ifdef    DO_ICONIFY
  975.                   {tticon, "amiga-iconify"},
  976. #endif
  977. #ifdef    DO_MENU
  978.                   {amigamenu, "amiga-menu"},
  979. #endif
  980. #ifdef    CHANGE_COLOR
  981.                   {modebackground, "amiga-mode-background"},
  982.                   {modeforeground, "amiga-mode-foreground"},
  983.                   {ttmode, "amiga-mode-rendition"},
  984. #endif
  985. #ifdef    CHANGE_FONT
  986.                   {setfont, "amiga-set-font"},
  987. #endif
  988. #ifdef    CHANGE_COLOR
  989.                   {textbackground, "amiga-text-background"},
  990.                   {textforeground, "amiga-text-foreground"},
  991.                   {tttext, "amiga-text-rendition"},
  992. #endif
  993.                   {togglewindow, "amiga-toggle-border"},
  994. #ifdef    REXX
  995.                   {rexxtopwindow, "amiga-window-to-top"},
  996. #endif
  997.                   {togglezooms, "amiga-zoom-mode"},
  998. #endif                /* AMIGA */
  999. #ifndef    NO_HELP
  1000.                   {apropos_command, "apropos"},
  1001. #endif
  1002.                   {fillmode, "auto-fill-mode"},
  1003.                   {indentmode, "auto-indent-mode"},
  1004.                   {backchar, "backward-char"},
  1005.                   {delbword, "backward-kill-word"},
  1006.                   {gotobop, "backward-paragraph"},
  1007.                   {backword, "backward-word"},
  1008.                   {gotobob, "beginning-of-buffer"},
  1009.                   {gotobol, "beginning-of-line"},
  1010.                   {blinkparen, "blink-matching-paren"},
  1011.                   {showmatch, "blink-matching-paren-hack"},
  1012. #ifdef    BSMAP
  1013.                   {bsmap, "bsmap-mode"},
  1014. #endif
  1015.                   {NULL, "c-x 4 prefix"},
  1016.                   {NULL, "c-x prefix"},
  1017. #ifndef NO_MACRO
  1018.                   {executemacro, "call-last-kbd-macro"},
  1019. #endif
  1020.                   {capword, "capitalize-word"},
  1021. #ifndef NO_DIR
  1022.                   {changedir, "cd"},
  1023. #endif
  1024.                   {copyregion, "copy-region-as-kill"},
  1025. #ifdef    REGEXP
  1026.                   {cntmatchlines, "count-matches"},
  1027.                   {cntnonmatchlines, "count-non-matches"},
  1028. #endif
  1029.                   {define_key, "define-key"},
  1030.                   {backdel, "delete-backward-char"},
  1031.                   {deblank, "delete-blank-lines"},
  1032.                   {forwdel, "delete-char"},
  1033.                   {delwhite, "delete-horizontal-space"},
  1034. #ifdef    REGEXP
  1035.                   {delmatchlines, "delete-matching-lines"},
  1036.                 {delnonmatchlines, "delete-non-matching-lines"},
  1037. #endif
  1038.                   {onlywind, "delete-other-windows"},
  1039.                   {delwind, "delete-window"},
  1040. #ifndef NO_HELP
  1041.                   {wallchart, "describe-bindings"},
  1042.                   {desckey, "describe-key-briefly"},
  1043. #endif
  1044.                   {digit_argument, "digit-argument"},
  1045. #ifndef NO_DIRED
  1046.                   {dired, "dired"},
  1047.                   {d_undelbak, "dired-backup-unflag"},
  1048.                   {d_copy, "dired-copy-file"},
  1049.                   {d_expunge, "dired-do-deletions"},
  1050.                   {d_findfile, "dired-find-file"},
  1051.               {d_ffotherwindow, "dired-find-file-other-window"},
  1052.                   {d_del, "dired-flag-file-deleted"},
  1053.                   {d_otherwindow, "dired-other-window"},
  1054.                   {d_rename, "dired-rename-file"},
  1055.                   {d_undel, "dired-unflag"},
  1056. #endif
  1057.                   {lowerregion, "downcase-region"},
  1058.                   {lowerword, "downcase-word"},
  1059.                   {showversion, "emacs-version"},
  1060. #ifndef NO_MACRO
  1061.                   {finishmacro, "end-kbd-macro"},
  1062. #endif
  1063.                   {gotoeob, "end-of-buffer"},
  1064.                   {gotoeol, "end-of-line"},
  1065.                   {enlargewind, "enlarge-window"},
  1066.                   {NULL, "esc prefix"},
  1067. #ifdef DO_EVAL
  1068.                   {evalbuffer, "eval-current-buffer"},
  1069.                   {evalexpr, "eval-expression"},
  1070. #endif
  1071.                   {swapmark, "exchange-point-and-mark"},
  1072.                   {extend, "execute-extended-command"},
  1073.                   {fillpara, "fill-paragraph"},
  1074.                   {filevisit, "find-file"},
  1075.                   {poptofile, "find-file-other-window"},
  1076.                   {forwchar, "forward-char"},
  1077.                   {gotoeop, "forward-paragraph"},
  1078.                   {forwword, "forward-word"},
  1079. #ifndef    NO_MACRO
  1080.                   {macroset, "fset"},
  1081. #endif
  1082.                   {bindtokey, "global-set-key"},
  1083.                   {unbindtokey, "global-unset-key"},
  1084.                   {gotoline, "goto-line"},
  1085. #ifndef NO_HELP
  1086.                   {NULL, "help"},
  1087.                   {help_help, "help-help"},
  1088. #endif
  1089.                   {bufferinsert, "insert-buffer"},
  1090.                   {fileinsert, "insert-file"},
  1091. #ifndef    NO_MACRO
  1092.                   {insertmacro, "insert-kbd-macro"},
  1093. #endif
  1094.                   {fillword, "insert-with-wrap"},
  1095.                   {backisearch, "isearch-backward"},
  1096.                   {forwisearch, "isearch-forward"},
  1097.                   {justone, "just-one-space"},
  1098. #ifndef    NO_MACRO
  1099.                   {macroquery, "kbd-macro-query"},
  1100. #endif
  1101.                   {ctrlg, "keyboard-quit"},
  1102.                   {killbuffer, "kill-buffer"},
  1103.                   {killline, "kill-line"},
  1104.                   {killpara, "kill-paragraph"},
  1105.                   {killregion, "kill-region"},
  1106.                   {delfword, "kill-word"},
  1107.                   {listbuffers, "list-buffers"},
  1108. #ifdef DO_EVAL
  1109.                   {evalfile, "load"},
  1110. #endif
  1111.                   {localbind, "local-set-key"},
  1112.                   {localunbind, "local-unset-key"},
  1113. #ifndef NO_BACKUP
  1114.                   {makebkfile, "make-backup-files"},
  1115. #endif
  1116. #ifndef    NO_METAKEY
  1117.                   {do_meta, "meta-key-mode"},    /* better name, anyone? */
  1118. #endif
  1119. #ifdef    AMIGA
  1120. #ifdef    MOUSE
  1121.                   {mgotobob, "mouse-beginning-of-buffer"},
  1122.                   {mforwdel, "mouse-delete-char"},
  1123.                    {mdelwhite, "mouse-delete-horizontal-space"},
  1124.                   {mdelwind, "mouse-delete-window"},
  1125.                   {mgotoeob, "mouse-end-of-buffer"},
  1126.                   {menlargewind, "mouse-enlarge-window"},
  1127.                   {mkillline, "mouse-kill-line"},
  1128.                   {mkillregion, "mouse-kill-region"},
  1129.                   {mdelfword, "mouse-kill-word"},
  1130.                   {mreposition, "mouse-recenter"},
  1131.                   {mbackpage, "mouse-scroll-down"},
  1132.                   {mforwpage, "mouse-scroll-up"},
  1133.                   {amigamouse, "mouse-set-point"},
  1134.                   {mshrinkwind, "mouse-shrink-window"},
  1135.                   {msplitwind, "mouse-split-window-vertically"},
  1136.                   {myank, "mouse-yank"},
  1137. #endif
  1138. #endif
  1139. #ifndef    NO_MACRO
  1140.                   {namemacro, "name-last-kbd-macro"},
  1141. #endif
  1142.                   {negative_argument, "negative-argument"},
  1143.                   {newline, "newline"},
  1144.                   {indent, "newline-and-indent"},
  1145.                   {forwline, "next-line"},
  1146. #ifdef    NOTAB
  1147.                   {notabmode, "no-tab-mode"},
  1148. #endif
  1149.                   {notmodified, "not-modified"},
  1150.                   {openline, "open-line"},
  1151.                   {nextwind, "other-window"},
  1152.                   {overwrite, "overwrite-mode"},
  1153. #ifdef    PREFIXREGION
  1154.                   {prefixregion, "prefix-region"},
  1155. #endif
  1156.                   {backline, "previous-line"},
  1157. #ifdef    GOSMACS
  1158.                   {prevwind, "previous-window"},
  1159. #endif
  1160. #ifdef    VMS
  1161.                   {spawncli, "push-to-dcl"},
  1162. #endif
  1163. #ifndef NO_DIR
  1164.                   {showcwdir, "pwd"},
  1165. #endif
  1166.                   {queryrepl, "query-replace"},
  1167. #ifdef    REGEXP
  1168.                   {re_queryrepl, "query-replace-regexp"},
  1169. #endif
  1170.                   {quote, "quoted-insert"},
  1171. #ifdef    REGEXP
  1172.                   {re_searchagain, "re-search-again"},
  1173.                   {re_backsearch, "re-search-backward"},
  1174.                   {re_forwsearch, "re-search-forward"},
  1175. #endif
  1176.                   {reposition, "recenter"},
  1177.                   {refresh, "redraw-display"},
  1178.                   {revertbuffer, "revert-buffer"},
  1179. #ifdef    REXX
  1180.                   {rexxcommand, "rexx"},
  1181.                   {rexxbuffer, "rexx-buffer"},
  1182.                   {rexxbuflist, "rexx-buffer-list"},
  1183.                   {rexxdisplay, "rexx-display"},
  1184.                   {rexxexitcommand, "rexx-do-on-exit"},
  1185.                   {rexxcomregion, "rexx-do-region"},
  1186.                   {rexxinsert, "rexx-insert"},
  1187.                   {rexxline, "rexx-line"},
  1188.                   {rexxlock, "rexx-lock"},
  1189.                   {rexxmark, "rexx-mark"},
  1190.                   {rexxpoint, "rexx-point"},
  1191.                   {rexxregion, "rexx-region"},
  1192.                   {rexxrequest, "rexx-request"},
  1193.                   {rexxreqbuf, "rexx-request-buffer"},
  1194.                   {rexxreqfunc, "rexx-request-function"},
  1195.                   {rexxreqmacro, "rexx-request-macro"},
  1196.                   {rexxunlock, "rexx-unlock"},
  1197.                   {rexxwait, "rexx-wait"},
  1198.                   {rexxwindow, "rexx-window"},
  1199. #endif
  1200.                   {filesave, "save-buffer"},
  1201.                   {quit, "save-buffers-kill-emacs"},
  1202.                   {savebuffers, "save-some-buffers"},
  1203.                   {backpage, "scroll-down"},
  1204. #ifdef    GOSMACS
  1205.                   {back1page, "scroll-one-line-down"},
  1206.                   {forw1page, "scroll-one-line-up"},
  1207. #endif
  1208.                   {pagenext, "scroll-other-window"},
  1209.                   {forwpage, "scroll-up"},
  1210.                   {searchagain, "search-again"},
  1211.                   {backsearch, "search-backward"},
  1212.                   {forwsearch, "search-forward"},
  1213.                   {selfinsert, "self-insert-command"},
  1214. #ifdef    REGEXP
  1215.                   {setcasefold, "set-case-fold-search"},
  1216. #endif
  1217.                   {set_default_mode, "set-default-mode"},
  1218.                   {setfillcol, "set-fill-column"},
  1219.                   {setmark, "set-mark-command"},
  1220. #ifdef    PREFIXREGION
  1221.                   {setprefix, "set-prefix-string"},
  1222. #endif
  1223.                   {shrinkwind, "shrink-window"},
  1224. #ifdef    NOTAB
  1225.                   {space_to_tabstop, "space-to-tabstop"},
  1226. #endif
  1227.                   {splitwind, "split-window-vertically"},
  1228. #ifndef NO_MACRO
  1229.                   {definemacro, "start-kbd-macro"},
  1230. #endif
  1231. #ifdef    VMS
  1232.                   {attachtoparent, "suspend-emacs"},
  1233. #else
  1234.                   {spawncli, "suspend-emacs"},
  1235. #endif
  1236.                   {usebuffer, "switch-to-buffer"},
  1237.                  {poptobuffer, "switch-to-buffer-other-window"},
  1238.                   {twiddle, "transpose-chars"},
  1239.                   {universal_argument, "universal-argument"},
  1240.                   {upperregion, "upcase-region"},
  1241.                   {upperword, "upcase-word"},
  1242.                   {showcpos, "what-cursor-position"},
  1243.                   {filewrite, "write-file"},
  1244.                   {yank, "yank"},
  1245. };
  1246.  
  1247. #define NFUNCT    (sizeof(functnames)/sizeof(struct functnames))
  1248.  
  1249. int             nfunct = NFUNCT;/* used by help.c */
  1250.  
  1251. #ifdef    LATTICE_50
  1252. static char     a;        /* Sigh */
  1253. #endif
  1254.  
  1255. /*
  1256.  * The general-purpose version of ROUND2 blows osk C (2.0) out of the water.
  1257.  * (reboot required)  If you need to build a version of mg with less than 32
  1258.  * or more than 511 functions, something better must be done. The version
  1259.  * that should work, but doesn't is: #define ROUND2(x)
  1260.  * (1+((x>>1)|(x>>2)|(x>>3)|(x>>4)|(x>>5)|(x>>6)|(x>>7)|\
  1261.  * (x>>8)|(x>>9)|(x>>10)|(x>>11)|(x>>12)|(x>>13)|(x>>14)|(x>>15))) 
  1262.  */
  1263. #define ROUND2(x) (x<128?(x<64?32:64):(x<256?128:256))
  1264.  
  1265. static
  1266. name_fent(fname, flag)
  1267.     register char  *fname;
  1268.     int             flag;
  1269. {
  1270.     register int    try;
  1271.     register int    x = ROUND2(NFUNCT);
  1272.     register int    base = 0;
  1273.     register int    notit;
  1274.  
  1275.     do {
  1276.         /* + can be used instead of | here if more efficent.     */
  1277.         if ((try = base | x) < NFUNCT) {
  1278.             if ((notit = strcmp(fname, functnames[try].n_name)) >= 0) {
  1279.                 if (!notit)
  1280.                     return try;
  1281.                 base = try;
  1282.             }
  1283.         }
  1284.     } while ((x >>= 1) || (try == 1 && base == 0));    /* try 0 once if needed */
  1285.     return flag ? base : -1;
  1286. }
  1287.  
  1288. /*
  1289.  * Translate from function name to function pointer, using binary search. 
  1290.  */
  1291.  
  1292. int
  1293.                 (*
  1294.          name_function(fname)) ()
  1295.     char           *fname;
  1296. {
  1297.     int             i;
  1298.     if ((i = name_fent(fname, FALSE)) >= 0 && functnames[i].n_funct)
  1299.         return functnames[i].n_funct;
  1300.     return NULL;
  1301. }
  1302.  
  1303. /* complete function name */
  1304.  
  1305. complete_function(fname, c)
  1306.     register char  *fname;
  1307. {
  1308.     register int    i, j, k, l;
  1309.     int             oj;
  1310.  
  1311.     i = name_fent(fname, TRUE);
  1312.     for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) {
  1313.     }
  1314.     if (fname[j] != '\0') {
  1315.         if (++i >= NFUNCT)
  1316.             return -1;    /* no match */
  1317.         for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) {
  1318.         }
  1319.         if (fname[j] != '\0')
  1320.             return -1;    /* no match */
  1321.     }
  1322.     if (c == CCHR('M') && functnames[i].n_name[j] == '\0')
  1323.         return -3;
  1324.     for (k = i + 1; k < NFUNCT; k++) {    /* find last match */
  1325.         for (l = 0; functnames[k].n_name[l] == fname[l]; l++) {
  1326.         }
  1327.         if (l < j)
  1328.             break;
  1329.     }
  1330.     k--;
  1331.     oj = j;
  1332.     if (k > i) {        /* multiple matches */
  1333.         while ((l = functnames[i].n_name[j]) == functnames[k].n_name[j]) {
  1334.             fname[j++] = l;
  1335.             if (l == '-' && c == ' ')
  1336.                 break;
  1337.         }
  1338.         if (j == oj)
  1339.             return -2;    /* ambiguous     */
  1340.     } else {        /* single match */
  1341.         while (l = functnames[i].n_name[j]) {
  1342.             fname[j++] = l;
  1343.             if (!ISWORD(l) && c == ' ')
  1344.                 break;
  1345.         }
  1346.         if (c == CCHR('M')) {
  1347.             fname[j] = '\0';
  1348.             return -3;
  1349.         }
  1350.     }
  1351.     fname[j] = '\0';
  1352.     return j - oj;
  1353. }
  1354.  
  1355. /* translate from function pointer to function name. */
  1356.  
  1357. char           *
  1358. function_name(fpoint)
  1359.     register int    (*fpoint) ();
  1360. {
  1361.     register struct functnames *fnp = &functnames[0];
  1362.  
  1363.     if (fpoint == (int (*) ()) NULL)
  1364.         return (char *) NULL;    /* ambiguous */
  1365.     do {
  1366.         if (fnp->n_funct == fpoint)
  1367.             return fnp->n_name;
  1368.     } while (++fnp < &functnames[NFUNCT]);
  1369.     return (char *) NULL;
  1370. }
  1371.