diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 1998-11-10 19:47:00 -0500 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 1998-11-10 19:47:00 -0500 |
commit | d3f9d5478df478427c2aa5db4507ddd0a38f0eb6 (patch) | |
tree | e27eacd6bbda653dd77f11cc020b9e0a59f7f4fc /src/LYKeymap.c | |
parent | 18024037b515bfff83e0230b35151babe6005e18 (diff) | |
download | lynx-snapshots-d3f9d5478df478427c2aa5db4507ddd0a38f0eb6.tar.gz |
snapshot of project "lynx", label v2-8-2dev_2
Diffstat (limited to 'src/LYKeymap.c')
-rw-r--r-- | src/LYKeymap.c | 314 |
1 files changed, 229 insertions, 85 deletions
diff --git a/src/LYKeymap.c b/src/LYKeymap.c index 1ae0e763..9ab5df62 100644 --- a/src/LYKeymap.c +++ b/src/LYKeymap.c @@ -1,5 +1,4 @@ #include <HTUtils.h> -#include <tcp.h> #include <LYUtils.h> #include <LYKeymap.h> #include <LYGlobalDefs.h> @@ -11,7 +10,7 @@ PRIVATE CONST DocAddress keymap_anchor = {"LYNXKEYMAP", NULL, NULL}; -struct _HTStream +struct _HTStream { HTStreamClass * isa; }; @@ -19,7 +18,7 @@ struct _HTStream /* the character gets 1 added to it before lookup, * so that EOF maps to 0 */ -char keymap[] = { +unsigned short keymap[] = { 0, /* EOF */ @@ -39,10 +38,6 @@ LYK_REFRESH, LYK_ACTIVATE, LYK_DOWN_TWO, 0, LYK_UP_TWO, 0, LYK_RELOAD, 0, /* ^P */ /* XON */ /* ^R */ /* XOFF */ -#ifdef NOT_USED -LYK_TRACE_TOGGLE, 0, LYK_VERSION, LYK_REFRESH, -/* ^T */ /* ^U */ /* ^V */ /* ^W */ -#endif /* NOT_USED */ LYK_TRACE_TOGGLE, 0, LYK_SWITCH_DTD, LYK_REFRESH, /* ^T */ /* ^U */ /* ^V */ /* ^W */ @@ -84,15 +79,15 @@ LYK_UP_LINK, LYK_INFO, LYK_DOWN_LINK, LYK_HELP, LYK_RAW_TOGGLE, LYK_ADD_BOOKMARK, LYK_PREV_PAGE, LYK_COMMENT, /* @ */ /* A */ /* B */ /* C */ -LYK_DOWNLOAD, LYK_ELGOTO, -/* D */ /* E */ +LYK_DOWNLOAD, LYK_ELGOTO, +/* D */ /* E */ #if defined(DIRED_SUPPORT) || defined(VMS) LYK_DIRED_MENU, #else -0, +0, #endif /* DIRED_SUPPORT || VMS */ -/* F */ +/* F */ LYK_ECGOTO, /* G */ @@ -106,20 +101,9 @@ LYK_LIST, LYK_MAIN_MENU, LYK_NEXT, LYK_OPTIONS, LYK_PRINT, LYK_ABORT, LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH, /* P */ /* Q */ /* R */ /* S */ -#ifdef DIRED_SUPPORT -LYK_TAG_LINK, -#else -0, -#endif /* DIRED_SUPPORT */ -/* T */ - - LYK_PREV_DOC, LYK_VLINKS, 0, - /* U */ /* V */ /* W */ +LYK_TAG_LINK, LYK_PREV_DOC, LYK_VLINKS, 0, +/* T */ /* U */ /* V */ /* W */ -#ifdef NOT_USED -LYK_FORM_UP, 0, LYK_FORM_DOWN, LYK_INLINE_TOGGLE, -/* X */ /* Y */ /* Z */ /* [ */ -#endif /* NOT_USED */ LYK_NOCACHE, 0, LYK_INTERRUPT, LYK_INLINE_TOGGLE, /* X */ /* Y */ /* Z */ /* [ */ @@ -129,15 +113,15 @@ LYK_SOURCE, LYK_HEAD, 0, LYK_CLEAR_AUTH, LYK_MINIMAL, LYK_ADD_BOOKMARK, LYK_PREV_PAGE, LYK_COMMENT, /* ` */ /* a */ /* b */ /* c */ -LYK_DOWNLOAD, LYK_EDIT, -/* d */ /* e */ +LYK_DOWNLOAD, LYK_EDIT, +/* d */ /* e */ #if defined(DIRED_SUPPORT) || defined(VMS) LYK_DIRED_MENU, #else -0, +0, #endif /* DIRED_SUPPORT || VMS */ -/* f */ +/* f */ LYK_GOTO, /* g */ @@ -151,20 +135,9 @@ LYK_LIST, LYK_MAIN_MENU, LYK_NEXT, LYK_OPTIONS, LYK_PRINT, LYK_QUIT, LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH, /* p */ /* q */ /* r */ /* s */ -#ifdef DIRED_SUPPORT -LYK_TAG_LINK, -#else -0, -#endif /* DIRED_SUPPORT */ -/* t */ - - LYK_PREV_DOC, LYK_VIEW_BOOKMARK, 0, - /* u */ /* v */ /* w */ +LYK_TAG_LINK, LYK_PREV_DOC, LYK_VIEW_BOOKMARK, 0, +/* t */ /* u */ /* v */ /* w */ -#ifdef NOT_USED -LYK_FORM_UP, 0, LYK_FORM_DOWN, 0, -/* x */ /* y */ /* z */ /* { */ -#endif /* NOT_USED */ LYK_NOCACHE, 0, LYK_INTERRUPT, 0, /* x */ /* y */ /* z */ /* { */ @@ -214,6 +187,22 @@ LYK_PREV_LINK, LYK_NEXT_LINK, LYK_ACTIVATE, LYK_PREV_DOC, LYK_NEXT_PAGE, LYK_PREV_PAGE, LYK_HOME, LYK_END, /* PGDOWN */ /* PGUP */ /* HOME */ /* END */ +#if defined(__DJGPP__) || defined(_WINDOWS) +#ifdef USE_SLANG +LYK_END, LYK_HOME, LYK_PREV_PAGE, 0, +/* END */ /* HOME */ /* PGUP */ /* B2 Key */ + +LYK_END, LYK_NEXT_PAGE, 0, +/* END */ /* PGDOWN */ + +#else + 0, LYK_HELP, 0, 0, +/* F0 */ /* F1 */ /* F2 */ /* F3 */ + + 0, 0, 0, + +#endif /* USE_SLANG */ +#else LYK_HELP, LYK_ACTIVATE, LYK_HOME, LYK_END, /* F1*/ /* Do key */ /* Find key */ /* Select key */ @@ -222,6 +211,135 @@ LYK_UP_TWO, LYK_DOWN_TWO, LYK_DO_NOTHING, /* DO_NOTHING*/ +#endif /* __DJGPP__ || _WINDOWS */ +/* 10F..18F */ + + 0, +#if defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER) + LYK_HISTORY, LYK_ACTIVATE, 0, 0, + /* Backspace */ /* Enter */ +#else + 0, 0, 0, 0, +#endif /* USE_SLANG */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, +#ifdef DJGPP_KEYHANDLER + 0, LYK_ABORT, 0, 0, + /* ALT_X */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, LYK_HELP, + /* F1 */ +#else + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, +#endif /* DJGPP_KEYHANDLER */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, +/* 190..20F */ + + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + LYK_ABORT, 0, 0, 0, + /* ALT_X */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, LYK_ACTIVATE, + /* KP_ENTER */ + 0, 0, 0, LYK_IMAGE_TOGGLE, + /* KP_* */ + LYK_PREV_PAGE, LYK_NEXT_PAGE, 0, 0, + /* KP_- */ /* KP_+ */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, +#if defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER) + 0, LYK_HELP, 0, 0, + /* F1 */ +#else + 0, 0, 0, 0, +#endif /* USE_SLANG */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, +/* 210..28F */ + + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + /* 290...293 */ + 0, 0, 0, 0, }; #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE) @@ -231,7 +349,7 @@ LYK_DO_NOTHING, * allowed at compile time. */ -char override[] = { +unsigned short key_override[TABLESIZE(keymap)] = { 0, /* EOF */ @@ -387,8 +505,8 @@ LYK_DO_NOTHING, #endif /* DIRED_SUPPORT && OK_OVERRIDE */ struct rmap { - char *name; - char *doc; + CONST char *name; + CONST char *doc; }; PRIVATE struct rmap revmap[] = { { "UNMAPPED", NULL }, @@ -481,15 +599,10 @@ PRIVATE struct rmap revmap[] = { { "INSTALL", "install file or tagged files into a system area" }, #endif /* DIRED_SUPPORT */ #endif /* VMS */ -#ifdef NOT_USED -{ "VERSION", "report version of lynx"}, -{ "FORM_UP", "toggle a checkbox" }, -{ "FORM_DOWN", "toggle a checkbox" }, -#endif /* NOT_USED */ { NULL, "" } }; -PRIVATE char *funckey[] = { +PRIVATE CONST char *funckey[] = { "Up Arrow", "Down Arrow", "Right Arrow", @@ -526,27 +639,44 @@ PRIVATE char *pretty ARGS1 (int, c) sprintf(buf, "%c", c); else if (c < ' ') sprintf(buf, "^%c", c|0100); - else + else if (c >= 0400 && (c - 0400) < (int) TABLESIZE(funckey)) sprintf(buf, "%s", funckey[c-0400]); - + else + return 0; + return buf; } +PRIVATE BOOL format_binding ARGS3( + char *, buf, + unsigned short *, table, + int, i) +{ + unsigned the_key = table[i]; + char *formatted; + + if (the_key != 0 + && the_key < TABLESIZE(revmap) + && revmap[the_key].name != 0 + && revmap[the_key].doc != 0 + && (formatted = pretty(i-1)) != 0) { + sprintf(buf, "%-12s%-14s%s\n", formatted, + revmap[the_key].name, + revmap[the_key].doc); + return TRUE; + } + return FALSE; +} + PRIVATE void print_binding ARGS3(HTStream *, target, char *, buf, int, i) { #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE) if (prev_lynx_edit_mode && !no_dired_support && - override[i] && revmap[(unsigned char)override[i]].doc) { - sprintf(buf, "%-12s%-14s%s\n", pretty(i-1), - revmap[(unsigned char)override[i]].name, - revmap[(unsigned char)override[i]].doc); + format_binding(buf, key_override, i)) { (*target->isa->put_block)(target, buf, strlen(buf)); } else #endif /* DIRED_SUPPORT && OK_OVERRIDE */ - if (keymap[i] && revmap[(unsigned char)keymap[i]].doc) { - sprintf(buf, "%-12s%-14s%s\n", pretty(i-1), - revmap[(unsigned char)keymap[i]].name, - revmap[(unsigned char)keymap[i]].doc); + if (format_binding(buf, keymap, i)) { (*target->isa->put_block)(target, buf, strlen(buf)); } } @@ -577,9 +707,12 @@ PRIVATE int LYLoadKeymap ARGS4 ( sprintf(buf, "<head>\n<title>%s</title>\n</head>\n<body>\n", CURRENT_KEYMAP_TITLE); (*target->isa->put_block)(target, buf, strlen(buf)); - - sprintf(buf, "<h1>%s (%s Version %s)</h1>\n<pre>", - CURRENT_KEYMAP_TITLE, LYNX_NAME, LYNX_VERSION); + sprintf(buf, "<h1>%s (%s)%s<a href=\"%s%s\">%s</a></h1>\n", + LYNX_NAME, LYNX_VERSION, + HELP_ON_SEGMENT, + helpfilepath, CURRENT_KEYMAP_HELP, CURRENT_KEYMAP_TITLE); + (*target->isa->put_block)(target, buf, strlen(buf)); + sprintf(buf, "<pre>\n"); (*target->isa->put_block)(target, buf, strlen(buf)); for (i = 'a'+1; i <= 'z'+1; i++) { @@ -589,12 +722,12 @@ PRIVATE int LYLoadKeymap ARGS4 ( i-' '); /* uppercase mapping is different */ } } - for (i = 1; i < (int) sizeof(keymap); i++) { + for (i = 1; i < (int) TABLESIZE(keymap); i++) { /* * LYK_PIPE not implemented yet. */ - if ((i > 127 || i <= ' ' || !isalpha(i-1)) && - strcmp(revmap[(unsigned char)keymap[i]].name, "PIPE")) { + if ((i > (int) TABLESIZE(keymap) || i <= ' ' || !isalpha(i-1)) && + strcmp(revmap[keymap[i]].name, "PIPE")) { print_binding(target, buf, i); } } @@ -646,8 +779,8 @@ PUBLIC int remap ARGS2(char *,key, char *,func) PUBLIC void set_vms_keys NOARGS { keymap[26+1] = LYK_ABORT; /* control-Z */ - keymap['$'+1] = LYK_SHELL; -} + keymap['$'+1] = LYK_SHELL; +} static char saved_vi_keys[4]; static BOOLEAN did_vi_keys; @@ -763,27 +896,40 @@ PUBLIC void reset_numbers_as_arrows NOARGS did_number_keys = FALSE; } -PUBLIC char *key_for_func ARGS1 ( +PUBLIC int lookup_keymap ARGS1( int, func) { - static char buf[512]; - size_t i; - - buf[0] = '\0'; - for (i = 1; i < sizeof(keymap); i++) { - if (keymap[i] == func) { - if (*buf) - strcat(buf, " or "); - strcat(buf, pretty(i-1)); - } + size_t i; + + for (i = 1; i < TABLESIZE(keymap); i++) { + if (LYisNonAlnumKeyname(i, func)) { + return i; } - return buf; + } + return -1; +} + +PUBLIC char *key_for_func ARGS1 ( + int, func) +{ + static char buf[512]; + int i; + char *formatted; + + buf[0] = '\0'; + if ((i = LYReverseKeymap(func)) >= 0) { + if (*buf) + strcat(buf, " or "); + formatted = pretty(i); + strcat(buf, formatted != 0 ? formatted : "?"); + } + return buf; } /* * This function returns TRUE if the ch is non-alphanumeric * and maps to key_name (LYK_foo in the keymap[] array). - FM - */ + */ PUBLIC BOOL LYisNonAlnumKeyname ARGS2( int, ch, int, key_name) @@ -796,7 +942,6 @@ PUBLIC BOOL LYisNonAlnumKeyname ARGS2( return(keymap[ch+1] == key_name); } -#ifdef NOTUSED_FOTEMODS /* * This function returns the (int)ch mapped to the * LYK_foo value passed to it as an argument. - FM @@ -806,12 +951,11 @@ PUBLIC int LYReverseKeymap ARGS1( { int i; - for (i = 1; i < sizeof(keymap); i++) { + for (i = 1; i < (int) TABLESIZE(keymap); i++) { if (keymap[i] == key_name) { return(i - 1); } } - return(0); + return(-1); } -#endif |