home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lynx2.8.1dev.10.tar.gz / lynx2.8.1dev.10.tar / lynx2-8 / src / LYKeymap.c < prev    next >
C/C++ Source or Header  |  1998-03-25  |  27KB  |  818 lines

  1. #include <HTUtils.h>
  2. #include <tcp.h>
  3. #include <LYUtils.h>
  4. #include <LYKeymap.h>
  5. #include <LYGlobalDefs.h>
  6. #include <HTAccess.h>
  7. #include <HTFormat.h>
  8. #include <HTAlert.h>
  9.  
  10. #include <LYLeaks.h>
  11.  
  12. PRIVATE CONST DocAddress keymap_anchor = {"LYNXKEYMAP", NULL, NULL};
  13.  
  14. struct _HTStream 
  15. {
  16.   HTStreamClass * isa;
  17. };
  18.  
  19. /* the character gets 1 added to it before lookup,
  20.  * so that EOF maps to 0
  21.  */
  22. char keymap[] = {
  23.  
  24. 0,
  25. /* EOF */
  26.  
  27. 0,                  LYK_HOME,       LYK_PREV_PAGE,     0,
  28. /* nul */           /* ^A */        /* ^B */       /* ^C */
  29.  
  30. LYK_ABORT,          LYK_END,        LYK_NEXT_PAGE,     0,
  31. /* ^D */            /* ^E */        /* ^F */       /* ^G */
  32.  
  33. LYK_HISTORY,      LYK_NEXT_LINK,    LYK_ACTIVATE,  LYK_COOKIE_JAR,
  34. /* bs */            /* ht */        /* nl */       /* ^K */
  35.  
  36. LYK_REFRESH,      LYK_ACTIVATE,     LYK_DOWN_TWO,      0,
  37. /* ^L */            /* cr */        /* ^N */       /* ^O */
  38.  
  39. LYK_UP_TWO,             0,          LYK_RELOAD,        0,
  40. /* ^P */            /* XON */       /* ^R */       /* XOFF */
  41.  
  42. #ifdef NOT_USED
  43. LYK_TRACE_TOGGLE,       0,          LYK_VERSION,   LYK_REFRESH,
  44. /* ^T */            /* ^U */        /* ^V */       /* ^W */
  45. #endif /* NOT_USED */
  46. LYK_TRACE_TOGGLE,       0,        LYK_SWITCH_DTD,  LYK_REFRESH,
  47. /* ^T */            /* ^U */        /* ^V */       /* ^W */
  48.  
  49. 0,                      0,              0,             0,
  50. /* ^X */            /* ^Y */        /* ^Z */       /* ESC */
  51.  
  52. 0,                      0,              0,             0,
  53. /* ^\ */            /* ^] */        /* ^^ */       /* ^_ */
  54.  
  55. LYK_NEXT_PAGE,       LYK_SHELL,  LYK_SOFT_DQUOTES,  LYK_TOOLBAR,
  56. /* sp */             /* ! */         /* " */        /* # */
  57.  
  58. 0,                      0,              0,          LYK_HISTORICAL,
  59. /* $ */              /* % */         /* & */        /* ' */
  60.  
  61. LYK_UP_HALF,      LYK_DOWN_HALF, LYK_IMAGE_TOGGLE,  LYK_NEXT_PAGE,
  62. /* ( */              /* ) */         /* * */        /* + */
  63.  
  64. #ifndef USE_EXTERNALS
  65. LYK_NEXT_PAGE,    LYK_PREV_PAGE,        0,          LYK_WHEREIS,
  66. /* , */              /* - */         /* . */        /* / */
  67. #else
  68. LYK_NEXT_PAGE,    LYK_PREV_PAGE, LYK_EXTERN,        LYK_WHEREIS,
  69. /* , */              /* - */         /* . */        /* / */
  70. #endif
  71.  
  72. LYK_F_LINK_NUM,      LYK_1,          LYK_2,         LYK_3,
  73. /* 0 */              /* 1 */         /* 2 */        /* 3 */
  74.  
  75. LYK_4,               LYK_5,          LYK_6,         LYK_7,
  76. /* 4 */              /* 5 */         /* 6 */        /* 7 */
  77.  
  78. LYK_8,               LYK_9,             0,          LYK_TRACE_LOG,
  79. /* 8 */              /* 9 */         /* : */        /* ; */
  80.  
  81. LYK_UP_LINK,         LYK_INFO,     LYK_DOWN_LINK,   LYK_HELP,
  82. /* < */              /* = */         /* > */        /* ? */
  83.  
  84. LYK_RAW_TOGGLE,  LYK_ADD_BOOKMARK, LYK_PREV_PAGE,   LYK_COMMENT,
  85. /* @ */              /* A */         /* B */        /* C */
  86.  
  87. LYK_DOWNLOAD,        LYK_ELGOTO,             
  88. /* D */              /* E */         
  89.  
  90. #if defined(DIRED_SUPPORT) || defined(VMS)
  91. LYK_DIRED_MENU,
  92. #else
  93. 0,          
  94. #endif /* DIRED_SUPPORT || VMS */
  95. /* F */        
  96.  
  97. LYK_ECGOTO,
  98. /* G */
  99.  
  100. LYK_HELP,            LYK_INDEX,      LYK_JUMP,      LYK_KEYMAP,
  101. /* H */              /* I */         /* J */        /* K */
  102.  
  103. LYK_LIST,          LYK_MAIN_MENU,    LYK_NEXT,      LYK_OPTIONS,
  104. /* L */              /* M */         /* N */        /* O */
  105.  
  106. LYK_PRINT,          LYK_ABORT,    LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH,
  107. /* P */              /* Q */         /* R */        /* S */
  108.  
  109. #ifdef DIRED_SUPPORT
  110. LYK_TAG_LINK,     
  111. #else
  112. 0,
  113. #endif /* DIRED_SUPPORT */
  114. /* T */
  115.  
  116.                LYK_PREV_DOC,    LYK_VLINKS,         0,
  117.                      /* U */         /* V */        /* W */
  118.  
  119. #ifdef NOT_USED
  120. LYK_FORM_UP,            0,        LYK_FORM_DOWN,    LYK_INLINE_TOGGLE,
  121. /* X */              /* Y */         /* Z */        /* [ */
  122. #endif /* NOT_USED */
  123. LYK_NOCACHE,            0,        LYK_INTERRUPT,    LYK_INLINE_TOGGLE,
  124. /* X */              /* Y */         /* Z */        /* [ */
  125.  
  126. LYK_SOURCE,          LYK_HEAD,          0,          LYK_CLEAR_AUTH,
  127. /* \ */              /* ] */         /* ^ */        /* _ */
  128.  
  129. LYK_MINIMAL,   LYK_ADD_BOOKMARK,  LYK_PREV_PAGE,    LYK_COMMENT,
  130. /* ` */              /* a */         /* b */        /* c */
  131.  
  132. LYK_DOWNLOAD,        LYK_EDIT,             
  133. /* d */              /* e */         
  134.  
  135. #if defined(DIRED_SUPPORT) || defined(VMS)
  136. LYK_DIRED_MENU,
  137. #else
  138. 0,          
  139. #endif /* DIRED_SUPPORT || VMS */
  140. /* f */        
  141.  
  142. LYK_GOTO,
  143. /* g */
  144.  
  145. LYK_HELP,            LYK_INDEX,      LYK_JUMP,      LYK_KEYMAP,
  146. /* h */              /* i */         /* j */        /* k */
  147.  
  148. LYK_LIST,         LYK_MAIN_MENU,     LYK_NEXT,      LYK_OPTIONS,
  149. /* l */              /* m */         /* n */        /* o */
  150.  
  151. LYK_PRINT,           LYK_QUIT,    LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH,
  152. /* p */              /* q */         /* r */        /* s */
  153.  
  154. #ifdef DIRED_SUPPORT
  155. LYK_TAG_LINK,     
  156. #else
  157. 0,
  158. #endif /* DIRED_SUPPORT */
  159. /* t */
  160.  
  161.                     LYK_PREV_DOC,   LYK_VIEW_BOOKMARK,   0,
  162.                      /* u */         /* v */         /* w */
  163.  
  164. #ifdef NOT_USED
  165. LYK_FORM_UP,            0,          LYK_FORM_DOWN,     0,
  166. /* x */              /* y */          /* z */       /* { */
  167. #endif /* NOT_USED */
  168. LYK_NOCACHE,            0,          LYK_INTERRUPT,     0,
  169. /* x */              /* y */          /* z */       /* { */
  170.  
  171. LYK_PIPE,               0,              0,          LYK_HISTORY,
  172. /* | */               /* } */         /* ~ */       /* del */
  173.  
  174. /* 80..9F (illegal ISO-8859-1) 8-bit characters. */
  175.    0,                  0,              0,             0,
  176.    0,                  0,              0,             0,
  177.    0,                  0,              0,             0,
  178.    0,                  0,              0,             0,
  179.    0,                  0,              0,             0,
  180.    0,                  0,              0,             0,
  181.    0,                  0,              0,             0,
  182.    0,                  0,              0,             0,
  183.  
  184. /* A0..FF (permissible ISO-8859-1) 8-bit characters. */
  185.    0,                  0,              0,             0,
  186.    0,                  0,              0,             0,
  187.    0,                  0,              0,             0,
  188.    0,                  0,              0,             0,
  189.    0,                  0,              0,             0,
  190.    0,                  0,              0,             0,
  191.    0,                  0,              0,             0,
  192.    0,                  0,              0,             0,
  193.    0,                  0,              0,             0,
  194.    0,                  0,              0,             0,
  195.    0,                  0,              0,             0,
  196.    0,                  0,              0,             0,
  197.    0,                  0,              0,             0,
  198.    0,                  0,              0,             0,
  199.    0,                  0,              0,             0,
  200.    0,                  0,              0,             0,
  201.    0,                  0,              0,             0,
  202.    0,                  0,              0,             0,
  203.    0,                  0,              0,             0,
  204.    0,                  0,              0,             0,
  205.    0,                  0,              0,             0,
  206.    0,                  0,              0,             0,
  207.    0,                  0,              0,             0,
  208.    0,                  0,              0,             0,
  209.  
  210. /* 100..10E function key definitions in LYStrings.h */
  211. LYK_PREV_LINK,    LYK_NEXT_LINK,    LYK_ACTIVATE,   LYK_PREV_DOC,
  212. /* UPARROW */     /* DNARROW */     /* RTARROW */   /* LTARROW */
  213.  
  214. LYK_NEXT_PAGE,    LYK_PREV_PAGE,    LYK_HOME,       LYK_END,
  215. /* PGDOWN */      /* PGUP */        /* HOME */      /* END */
  216.  
  217. LYK_HELP,         LYK_ACTIVATE,     LYK_HOME,       LYK_END,
  218. /* F1*/       /* Do key */      /* Find key */  /* Select key */
  219.  
  220. LYK_UP_TWO,       LYK_DOWN_TWO,
  221. /* Insert key */  /* Remove key */
  222.  
  223. LYK_DO_NOTHING,
  224. /* DO_NOTHING*/
  225. };
  226.  
  227. #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
  228. /*
  229.  * This table is used to override the standard keyboard assignments
  230.  * when lynx_edit_mode is in effect and keyboard overrides have been
  231.  * allowed at compile time.
  232.  */
  233.  
  234. char override[] = {
  235.  
  236.     0,
  237. /* EOF */
  238.  
  239.     0,                  0,              0,            0,
  240. /* nul */           /* ^A */        /* ^B */      /* ^C */
  241.  
  242.     0,                  0,              0,            0,
  243. /* ^D */            /* ^E */        /* ^F */      /* ^G */
  244.  
  245.     0,                  0,              0,            0,
  246. /* bs */            /* ht */        /* nl */      /* ^K */
  247.  
  248.     0,                  0,              0,            0,
  249. /* ^L */            /* cr */        /* ^N */      /* ^O */
  250.  
  251.     0,                  0,              0,            0,
  252. /* ^P */            /* XON */       /* ^R */      /* XOFF */
  253.  
  254.     0,            LYK_PREV_DOC,         0,            0,
  255. /* ^T */            /* ^U */        /* ^V */      /* ^W */
  256.  
  257.     0,                  0,              0,            0,
  258. /* ^X */            /* ^Y */        /* ^Z */      /* ESC */
  259.  
  260.     0,                  0,              0,            0,
  261. /* ^\ */            /* ^] */        /* ^^ */      /* ^_ */
  262.  
  263.     0,                 0,              0,            0,
  264. /* sp */            /* ! */         /* " */       /* # */
  265.  
  266.    0,                  0,              0,            0,
  267. /* $ */             /* % */         /* & */       /* ' */
  268.  
  269.     0,                 0,              0,            0,
  270. /* ( */             /* ) */         /* * */       /* + */
  271.  
  272.     0,                 0,         LYK_TAG_LINK,      0,
  273. /* , */             /* - */         /* . */       /* / */
  274.  
  275.    0,                  0,              0,            0,
  276. /* 0 */             /* 1 */         /* 2 */       /* 3 */
  277.  
  278.    0,                  0,              0,            0,
  279. /* 4 */             /* 5 */         /* 6 */       /* 7 */
  280.  
  281.    0,                  0,              0,             0,
  282. /* 8 */             /* 9 */         /* : */        /* ; */
  283.  
  284.    0,                  0,              0,             0,
  285. /* < */             /* = */         /* > */        /* ? */
  286.  
  287.    0,                  0,              0,         LYK_CREATE,
  288. /* @ */             /* A */         /* B */        /* C */
  289.  
  290.    0,                  0,        LYK_DIRED_MENU,       0,
  291. /* D */             /* E */         /* F */        /* G */
  292.  
  293.    0,                  0,              0,             0,
  294. /* H */             /* I */         /* J */        /* K */
  295.  
  296.    0,             LYK_MODIFY,          0,             0,
  297. /* L */             /* M */         /* N */        /* O */
  298.  
  299.    0,                  0,         LYK_REMOVE,         0,
  300. /* P */             /* Q */         /* R */        /* S */
  301.  
  302. LYK_TAG_LINK,     LYK_UPLOAD,          0,             0,
  303. /* T */             /* U */         /* V */        /* W */
  304.  
  305.    0,                  0,              0,             0,
  306. /* X */             /* Y */         /* Z */        /* [ */
  307.  
  308.    0,                  0,              0,             0,
  309. /* \ */             /* ] */         /* ^ */        /* _ */
  310.  
  311. 0,                     0,              0,         LYK_CREATE,
  312. /* ` */             /* a */         /* b */        /* c */
  313.  
  314.    0,                  0,       LYK_DIRED_MENU,       0,
  315. /* d */             /* e */         /* f */        /* g */
  316.  
  317.    0,                  0,              0,             0,
  318. /* h */             /* i */         /* j */        /* k */
  319.  
  320. 0,                LYK_MODIFY,          0,             0,
  321. /* l */             /* m */         /* n */        /* o */
  322.  
  323.    0,                  0,          LYK_REMOVE,        0,
  324. /* p */             /* q */         /* r */        /* s */
  325.  
  326. LYK_TAG_LINK,      LYK_UPLOAD,         0,             0,
  327. /* t */             /* u */         /* v */         /* w */
  328.  
  329.    0,                  0,               0,            0,
  330. /* x */             /* y */          /* z */       /* { */
  331.  
  332.    0,                   0,             0,              0,
  333. /* | */              /* } */         /* ~ */       /* del */
  334.  
  335. /* 80..9F (illegal ISO-8859-1) 8-bit characters. */
  336.    0,                  0,              0,             0,
  337.    0,                  0,              0,             0,
  338.    0,                  0,              0,             0,
  339.    0,                  0,              0,             0,
  340.    0,                  0,              0,             0,
  341.    0,                  0,              0,             0,
  342.    0,                  0,              0,             0,
  343.    0,                  0,              0,             0,
  344.  
  345. /* A0..FF (permissible ISO-8859-1) 8-bit characters. */
  346.    0,                  0,              0,             0,
  347.    0,                  0,              0,             0,
  348.    0,                  0,              0,             0,
  349.    0,                  0,              0,             0,
  350.    0,                  0,              0,             0,
  351.    0,                  0,              0,             0,
  352.    0,                  0,              0,             0,
  353.    0,                  0,              0,             0,
  354.    0,                  0,              0,             0,
  355.    0,                  0,              0,             0,
  356.    0,                  0,              0,             0,
  357.    0,                  0,              0,             0,
  358.    0,                  0,              0,             0,
  359.    0,                  0,              0,             0,
  360.    0,                  0,              0,             0,
  361.    0,                  0,              0,             0,
  362.    0,                  0,              0,             0,
  363.    0,                  0,              0,             0,
  364.    0,                  0,              0,             0,
  365.    0,                  0,              0,             0,
  366.    0,                  0,              0,             0,
  367.    0,                  0,              0,             0,
  368.    0,                  0,              0,             0,
  369.    0,                  0,              0,             0,
  370.  
  371. /* 100..10E function key definitions in LYStrings.h */
  372.    0,                   0,             0,              0,
  373. /* UPARROW */     /* DNARROW */     /* RTARROW */   /* LTARROW */
  374.  
  375.    0,                  0,              0,              0,
  376. /* PGDOWN */      /* PGUP */        /* HOME */      /* END */
  377.  
  378.    0,                  0,              0,              0,
  379. /* F1*/       /* Do key */      /* Find key */  /* Select key */
  380.  
  381.    0,                  0,
  382. /* Insert key */  /* Remove key */
  383.  
  384. LYK_DO_NOTHING,
  385. /* DO_NOTHING*/
  386. };
  387. #endif /* DIRED_SUPPORT && OK_OVERRIDE */
  388.  
  389. struct rmap {
  390.     char *name;
  391.     char *doc;
  392. };
  393. PRIVATE struct rmap revmap[] = {
  394. { "UNMAPPED",        NULL },
  395. { "1",            NULL },
  396. { "2",            NULL },
  397. { "3",            NULL },
  398. { "4",            NULL },
  399. { "5",            NULL },
  400. { "6",            NULL },
  401. { "7",            NULL },
  402. { "8",            NULL },
  403. { "9",            NULL },
  404. { "SOURCE",        "toggle source/presentation for current document" },
  405. { "RELOAD",        "reload the current document" },
  406. { "PIPE",        "pipe the current document to an external command" },
  407. { "QUIT",        "quit the browser" },
  408. { "ABORT",        "quit the browser unconditionally" },
  409. { "NEXT_PAGE",        "view the next page of the document" },
  410. { "PREV_PAGE",        "view the previous page of the document" },
  411. { "UP_TWO",        "go back two lines in the document" },
  412. { "DOWN_TWO",        "go forward two lines in the document" },
  413. { "UP_HALF",        "go back half a page in the document" },
  414. { "DOWN_HALF",        "go forward half a page in the document" },
  415. { "REFRESH",        "refresh the screen to clear garbled text" },
  416. { "HOME",        "go to the beginning of the current document" },
  417. { "END",        "go to the end of the current document" },
  418. { "PREV_LINK",        "make the previous link current" },
  419. { "NEXT_LINK",        "make the next link current" },
  420. { "UP_LINK",        "move up the page to a previous link" },
  421. { "DOWN_LINK",        "move down the page to another link" },
  422. { "RIGHT_LINK",        "move right to another link" },
  423. { "LEFT_LINK",        "move left to a previous link" },
  424. { "HISTORY",        "display stack of currently-suspended documents" },
  425. { "PREV_DOC",        "go back to the previous document" },
  426. { "ACTIVATE",        "go to the document given by the current link" },
  427. { "GOTO",        "go to a document given as a URL" },
  428. { "ECGOTO",        "edit the current document's URL and go to it" },
  429. { "HELP",        "display help on using the browser" },
  430. { "INDEX",        "display an index of potentially useful documents" },
  431. { "NOCACHE",        "force submission of form or link with no-cache" },
  432. { "INTERRUPT",        "interrupt network transmission" },
  433. { "MAIN_MENU",        "return to the first screen (home page)" },
  434. { "OPTIONS",        "display and change option settings" },
  435. { "INDEX_SEARCH",    "allow searching of an index" },
  436. { "WHEREIS",        "search within the current document" },
  437. { "NEXT",        "search for the next occurence" },
  438. { "COMMENT",        "send a comment to the author of the current document" },
  439. { "EDIT",        "edit the current document" },
  440. { "INFO",        "display information on the current document and link" },
  441. { "PRINT",        "display choices for printing the current document" },
  442. { "ADD_BOOKMARK",    "add to your personal bookmark list" },
  443. { "DEL_BOOKMARK",    "delete from your personal bookmark list" },
  444. { "VIEW_BOOKMARK",    "view your personal bookmark list" },
  445. { "VLINKS",        "list links visited during the current Lynx session" },
  446. { "SHELL",        "escape from the browser to the system" },
  447. { "DOWNLOAD",        "download the current link to your computer" },
  448. { "TRACE_TOGGLE",    "toggle tracing of browser operations" },
  449. { "TRACE_LOG",        "view trace log if started in the current session" },
  450. { "IMAGE_TOGGLE",    "toggle handling of all images as links" },
  451. { "INLINE_TOGGLE",    "toggle pseudo-ALTs for inlines with no ALT string" },
  452. { "HEAD",        "send a HEAD request for the current document or link" },
  453. { "DO_NOTHING",        NULL },
  454. { "TOGGLE_HELP",    "show other commands in the novice help menu" },
  455. { "JUMP",        "go directly to a target document or action" },
  456. { "KEYMAP",        "display the current key map" },
  457. { "LIST",        "list the references (links) in the current document" },
  458. { "TOOLBAR",        "go to Toolbar or Banner in the current document" },
  459. { "HISTORICAL",        "toggle historical vs. valid/minimal comment parsing" },
  460. { "MINIMAL",        "toggle minimal vs. valid comment parsing" },
  461. { "SOFT_DQUOTES",    "toggle valid vs. soft double-quote parsing" },
  462. { "RAW_TOGGLE",        "toggle raw 8-bit translations or CJK mode ON or OFF" },
  463. { "COOKIE_JAR",        "examine the Cookie Jar" },
  464. { "F_LINK_NUM",        "invoke the 'Follow link (or page) number:' prompt" },
  465. { "CLEAR_AUTH",        "clear all authorization info for this session" },
  466. { "SWITCH_DTD",        "switch between two ways of parsing HTML" },
  467. { "ELGOTO",        "edit the current link's URL or ACTION and go to it" },
  468. #ifdef USE_EXTERNALS
  469. { "EXTERN",        "run external program with url" },
  470. #endif
  471. #ifdef VMS
  472. { "DIRED_MENU",        "invoke File/Directory Manager, if available" },
  473. #else
  474. #ifdef DIRED_SUPPORT
  475. { "DIRED_MENU",        "display a full menu of file operations" },
  476. { "CREATE",        "create a new file or directory" },
  477. { "REMOVE",        "remove a file or directory" },
  478. { "MODIFY",        "modify the name or location of a file or directory" },
  479. { "TAG_LINK",        "tag a file or directory for later action" },
  480. { "UPLOAD",        "upload from your computer to the current directory" },
  481. { "INSTALL",        "install file or tagged files into a system area" },
  482. #endif /* DIRED_SUPPORT */
  483. #endif /* VMS */
  484. #ifdef NOT_USED
  485. { "VERSION",        "report version of lynx"},
  486. { "FORM_UP",        "toggle a checkbox" },
  487. { "FORM_DOWN",        "toggle a checkbox" },
  488. #endif /* NOT_USED */
  489. { NULL,            "" }
  490. };
  491.  
  492. PRIVATE char *funckey[] = {
  493.   "Up Arrow",
  494.   "Down Arrow",
  495.   "Right Arrow",
  496.   "Left Arrow",
  497.   "Page Down",
  498.   "Page Up",
  499.   "Home",
  500.   "End",
  501.   "F1",
  502.   "Do key",
  503.   "Find key",
  504.   "Select key",
  505.   "Insert key",
  506.   "Remove key"
  507. };
  508.  
  509. PRIVATE char *pretty ARGS1 (int, c)
  510. {
  511.     static char buf[30];
  512.  
  513.     if (c == '\t')
  514.         sprintf(buf, "<tab>       ");
  515.     else if (c == '\r')
  516.         sprintf(buf, "<return>    ");
  517.     else if (c == ' ')
  518.         sprintf(buf, "<space>     ");
  519.     else if (c == '<')
  520.         sprintf(buf, "<           ");
  521.     else if (c == '>')
  522.         sprintf(buf, ">           ");
  523.     else if (c == 0177)
  524.         sprintf(buf, "<delete>    ");
  525.     else if (c > ' ' && c <= 0377)
  526.         sprintf(buf, "%c", c);
  527.     else if (c < ' ')
  528.         sprintf(buf, "^%c", c|0100);
  529.     else
  530.         sprintf(buf, "%s", funckey[c-0400]);
  531.     
  532.     return buf;
  533. }
  534.  
  535. PRIVATE void print_binding ARGS3(HTStream *, target, char *, buf, int, i)
  536. {
  537. #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
  538.     if (prev_lynx_edit_mode && !no_dired_support &&
  539.         override[i] && revmap[(unsigned char)override[i]].doc) {
  540.     sprintf(buf, "%-12s%-14s%s\n", pretty(i-1),
  541.         revmap[(unsigned char)override[i]].name,
  542.         revmap[(unsigned char)override[i]].doc);
  543.     (*target->isa->put_block)(target, buf, strlen(buf));
  544.     } else
  545. #endif /* DIRED_SUPPORT && OK_OVERRIDE */
  546.     if (keymap[i] && revmap[(unsigned char)keymap[i]].doc) {
  547.     sprintf(buf, "%-12s%-14s%s\n", pretty(i-1),
  548.         revmap[(unsigned char)keymap[i]].name,
  549.         revmap[(unsigned char)keymap[i]].doc);
  550.     (*target->isa->put_block)(target, buf, strlen(buf));
  551.     }
  552. }
  553.  
  554. PRIVATE int LYLoadKeymap ARGS4 (
  555.     CONST char *,         arg GCC_UNUSED,
  556.     HTParentAnchor *,    anAnchor,
  557.     HTFormat,        format_out,
  558.     HTStream*,        sink)
  559. {
  560.     HTFormat format_in = WWW_HTML;
  561.     HTStream *target;
  562.     char buf[256];
  563.     int i;
  564.  
  565.     /*
  566.      *  Set up the stream. - FM
  567.      */
  568.     target = HTStreamStack(format_in, format_out, sink, anAnchor);
  569.     if (!target || target == NULL) {
  570.     sprintf(buf, CANNOT_CONVERT_I_TO_O,
  571.              HTAtom_name(format_in), HTAtom_name(format_out));
  572.     HTAlert(buf);
  573.     return(HT_NOT_LOADED);
  574.     }
  575.     anAnchor->no_cache = TRUE;
  576.  
  577.     sprintf(buf, "<head>\n<title>%s</title>\n</head>\n<body>\n",
  578.               CURRENT_KEYMAP_TITLE);
  579.     (*target->isa->put_block)(target, buf, strlen(buf));
  580.     
  581.     sprintf(buf, "<h1>%s (%s Version %s)</h1>\n<pre>",
  582.          CURRENT_KEYMAP_TITLE, LYNX_NAME, LYNX_VERSION);
  583.     (*target->isa->put_block)(target, buf, strlen(buf));
  584.  
  585.     for (i = 'a'+1; i <= 'z'+1; i++) {
  586.     print_binding(target, buf, i);
  587.     if (keymap[i - ' '] != keymap[i]) {
  588.         print_binding(target, buf,
  589.               i-' ');  /* uppercase mapping is different */
  590.     }
  591.     }
  592.     for (i = 1; i < (int) sizeof(keymap); i++) {
  593.     /*
  594.      *  LYK_PIPE not implemented yet.
  595.      */
  596.     if ((i > 127 || i <= ' ' || !isalpha(i-1)) &&
  597.         strcmp(revmap[(unsigned char)keymap[i]].name, "PIPE")) {
  598.         print_binding(target, buf, i);
  599.     }
  600.     }
  601.  
  602.     sprintf(buf,"</pre>\n</body>\n");
  603.     (*target->isa->put_block)(target, buf, strlen(buf));
  604.  
  605.     (*target->isa->_free)(target);
  606.     return(HT_LOADED);
  607. }
  608.  
  609. #ifdef GLOBALDEF_IS_MACRO
  610. #define _LYKEYMAP_C_GLOBALDEF_1_INIT { "LYNXKEYMAP", LYLoadKeymap, 0}
  611. GLOBALDEF (HTProtocol,LYLynxKeymap,_LYKEYMAP_C_GLOBALDEF_1_INIT);
  612. #else
  613. GLOBALDEF PUBLIC HTProtocol LYLynxKeymap = {"LYNXKEYMAP", LYLoadKeymap, 0};
  614. #endif /* GLOBALDEF_IS_MACRO */
  615.  
  616. /*
  617.  * install func as the mapping for key.
  618.  * func must be present in the revmap table.
  619.  * returns TRUE if the mapping was made, FALSE if not.
  620.  */
  621. PUBLIC int remap ARGS2(char *,key, char *,func)
  622.  {
  623.        int i;
  624.        struct rmap *mp;
  625.        int c = 0;
  626.  
  627.        if (func == NULL)
  628.            return 0;
  629.        if (strlen(key) == 1)
  630.                c = *key;
  631.        else if (strlen(key) == 2 && *key == '^')
  632.                c = key[1] & 037;
  633.        else if (strlen(key) >= 2 && isdigit(*key))
  634.                if (sscanf(key, "%i", &c) != 1)
  635.                        return 0;
  636.        for (i = 0, mp = revmap; (*mp).name != NULL; mp++, i++) {
  637.                if (strcmp((*mp).name, func) == 0) {
  638.                        keymap[c+1] = i;
  639.                        return c;
  640.                }
  641.        }
  642.        return 0;
  643. }
  644.  
  645.  
  646. PUBLIC void set_vms_keys NOARGS
  647. {
  648.       keymap[26+1] = LYK_ABORT;  /* control-Z */
  649.       keymap['$'+1] = LYK_SHELL;  
  650.  
  651. static char saved_vi_keys[4];
  652. static BOOLEAN did_vi_keys;
  653.  
  654. PUBLIC void set_vi_keys NOARGS
  655. {
  656.       saved_vi_keys[0] = keymap['h'+1];
  657.       keymap['h'+1] = LYK_PREV_DOC;
  658.       saved_vi_keys[1] = keymap['j'+1];
  659.       keymap['j'+1] = LYK_NEXT_LINK;
  660.       saved_vi_keys[2] = keymap['k'+1];
  661.       keymap['k'+1] = LYK_PREV_LINK;
  662.       saved_vi_keys[3] = keymap['l'+1];
  663.       keymap['l'+1] = LYK_ACTIVATE;
  664.  
  665.       did_vi_keys = TRUE;
  666. }
  667.  
  668. PUBLIC void reset_vi_keys NOARGS
  669. {
  670.       if (!did_vi_keys)
  671.               return;
  672.  
  673.       keymap['h'+1] = saved_vi_keys[0];
  674.       keymap['j'+1] = saved_vi_keys[1];
  675.       keymap['k'+1] = saved_vi_keys[2];
  676.       keymap['l'+1] = saved_vi_keys[3];
  677.  
  678.       did_vi_keys = FALSE;
  679. }
  680.  
  681. static char saved_emacs_keys[4];
  682. static BOOLEAN did_emacs_keys;
  683.  
  684. PUBLIC void set_emacs_keys NOARGS
  685. {
  686.       saved_emacs_keys[0] = keymap[2+1];
  687.       keymap[2+1] = LYK_PREV_DOC;       /* ^B */
  688.       saved_emacs_keys[1] = keymap[14+1];
  689.       keymap[14+1] = LYK_NEXT_LINK;     /* ^N */
  690.       saved_emacs_keys[2] = keymap[16+1];
  691.       keymap[16+1] = LYK_PREV_LINK;     /* ^P */
  692.       saved_emacs_keys[3] = keymap[6+1];
  693.       keymap[6+1] = LYK_ACTIVATE;         /* ^F */
  694.  
  695.       did_emacs_keys = TRUE;
  696. }
  697.  
  698. PUBLIC void reset_emacs_keys NOARGS
  699. {
  700.       if (!did_emacs_keys)
  701.               return;
  702.  
  703.       keymap[2+1] = saved_emacs_keys[0];
  704.       keymap[14+1] = saved_emacs_keys[1];
  705.       keymap[16+1] = saved_emacs_keys[2];
  706.       keymap[6+1] = saved_emacs_keys[3];
  707.  
  708.       did_emacs_keys = FALSE;
  709. }
  710.  
  711. static char saved_number_keys[9];
  712. static BOOLEAN did_number_keys;
  713.  
  714. PUBLIC void set_numbers_as_arrows NOARGS
  715. {
  716.     /*
  717.      *  Map numbers to functions as labeled on the
  718.      *  IBM Enhanced keypad, and save their original
  719.      *  mapping for reset_numbers_as_arrows(). - FM
  720.      */
  721.     saved_number_keys[0] = keymap['4'+1];
  722.     keymap['4'+1] = LYK_PREV_DOC;
  723.     saved_number_keys[1] = keymap['2'+1];
  724.     keymap['2'+1] = LYK_NEXT_LINK;
  725.     saved_number_keys[2] = keymap['8'+1];
  726.     keymap['8'+1] = LYK_PREV_LINK;
  727.     saved_number_keys[3] = keymap['6'+1];
  728.     keymap['6'+1] = LYK_ACTIVATE;
  729.     saved_number_keys[4] = keymap['7'+1];
  730.     keymap['7'+1] = LYK_HOME;
  731.     saved_number_keys[5] = keymap['1'+1];
  732.     keymap['1'+1] = LYK_END;
  733.     saved_number_keys[6] = keymap['9'+1];
  734.     keymap['9'+1] = LYK_PREV_PAGE;
  735.     saved_number_keys[7] = keymap['3'+1];
  736.     keymap['3'+1] = LYK_NEXT_PAGE;
  737.  
  738.     /*
  739.      *  Disable the 5.
  740.      */
  741.     saved_number_keys[8] = keymap['5'+1];
  742.     keymap['5'+1] = LYK_DO_NOTHING;
  743.  
  744.     did_number_keys = TRUE;
  745. }
  746.  
  747. PUBLIC void reset_numbers_as_arrows NOARGS
  748. {
  749.     if (!did_number_keys)
  750.     return;
  751.  
  752.     keymap['4'+1] = saved_number_keys[0];
  753.     keymap['2'+1] = saved_number_keys[1];
  754.     keymap['8'+1] = saved_number_keys[2];
  755.     keymap['6'+1] = saved_number_keys[3];
  756.     keymap['7'+1] = saved_number_keys[4];
  757.     keymap['1'+1] = saved_number_keys[5];
  758.     keymap['9'+1] = saved_number_keys[6];
  759.     keymap['3'+1] = saved_number_keys[7];
  760.     keymap['5'+1] = saved_number_keys[8];
  761.  
  762.     did_number_keys = FALSE;
  763. }
  764.  
  765. PUBLIC char *key_for_func ARGS1 (
  766.     int,        func)
  767. {
  768.     static char buf[512];
  769.     size_t i;
  770.  
  771.     buf[0] = '\0';
  772.     for (i = 1; i < sizeof(keymap); i++) {
  773.         if (keymap[i] == func) {
  774.             if (*buf)
  775.                 strcat(buf, " or ");
  776.             strcat(buf, pretty(i-1));
  777.         }
  778.     }
  779.     return buf;
  780. }
  781.  
  782. /*
  783.  *  This function returns TRUE if the ch is non-alphanumeric
  784.  *  and maps to key_name (LYK_foo in the keymap[] array). - FM
  785.  */ 
  786. PUBLIC BOOL LYisNonAlnumKeyname ARGS2(
  787.     int,    ch,
  788.     int,    key_name)
  789. {
  790.     if ((ch >= '0' && ch <= '9') ||
  791.         (ch >= 'A' && ch <= 'z') ||
  792.     ch < 0 || ch > 269)
  793.     return (FALSE);
  794.  
  795.     return(keymap[ch+1] == key_name);
  796. }
  797.  
  798. #ifdef NOTUSED_FOTEMODS
  799. /*
  800.  *  This function returns the (int)ch mapped to the
  801.  *  LYK_foo value passed to it as an argument. - FM
  802.  */
  803. PUBLIC int LYReverseKeymap ARGS1(
  804.     int,        key_name)
  805. {
  806.     int i;
  807.  
  808.     for (i = 1; i < sizeof(keymap); i++) {
  809.     if (keymap[i] == key_name) {
  810.         return(i - 1);
  811.     }
  812.     }
  813.  
  814.     return(0);
  815. }
  816. #endif
  817.