diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/LYCharUtils.c | 291 | ||||
-rw-r--r-- | src/LYEditmap.c | 300 | ||||
-rw-r--r-- | src/LYGetFile.c | 5 | ||||
-rw-r--r-- | src/LYHistory.c | 3 | ||||
-rw-r--r-- | src/LYKeymap.c | 102 | ||||
-rw-r--r-- | src/LYKeymap.h | 3 | ||||
-rw-r--r-- | src/LYMain.c | 5 | ||||
-rw-r--r-- | src/LYMainLoop.c | 66 | ||||
-rw-r--r-- | src/LYUtils.c | 111 | ||||
-rw-r--r-- | src/LYUtils.h | 11 |
10 files changed, 545 insertions, 352 deletions
diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index 4d240ddf..ded061b2 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYCharUtils.c,v 1.124 2013/10/13 14:26:51 tom Exp $ + * $LynxId: LYCharUtils.c,v 1.126 2013/10/19 19:12:09 tom Exp $ * * Functions associated with LYCharSets.c and the Lynx version of HTML.c - FM * ========================================================================== @@ -46,17 +46,31 @@ int OL_CONTINUE = -29999; /* flag for whether CONTINUE is set */ int OL_VOID = -29998; /* flag for whether a count is set */ +static size_t count_char(const char *value, int ch) +{ + const char *found; + size_t result = 0; + + while ((*value != '\0') && (found = strchr(value, ch)) != NULL) { + ++result; + value = (found + 1); + } + return result; +} + /* - * This function converts any ampersands in allocated - * strings to "&". If isTITLE is TRUE, it also - * converts any angle-brackets to "<" or ">". - FM + * This function converts any ampersands in a pre-allocated string to "&". + * If brackets is TRUE, it also converts any angle-brackets to "<" or ">". */ -void LYEntify(char **str, - int isTITLE) +void LYEntify(char **in_out, + int brackets) { - char *p = *str; - char *q = NULL, *cp = NULL; - int amps = 0, lts = 0, gts = 0; + char *source = *in_out; + char *target; + char *result = NULL; + size_t count_AMPs = 0; + size_t count_LTs = 0; + size_t count_GTs = 0; #ifdef CJK_EX enum _state { @@ -70,166 +84,133 @@ void LYEntify(char **str, int in_sjis = 0; #endif - if (isEmpty(p)) - return; - - /* - * Count the ampersands. - FM - */ - while ((*p != '\0') && (q = strchr(p, '&')) != NULL) { - amps++; - p = (q + 1); - } - - /* - * Count the left-angle-brackets, if needed. - FM - */ - if (isTITLE == TRUE) { - p = *str; - while ((*p != '\0') && (q = strchr(p, '<')) != NULL) { - lts++; - p = (q + 1); + if (non_empty(source)) { + count_AMPs = count_char(*in_out, '&'); + if (brackets) { + count_LTs = count_char(*in_out, '<'); + count_GTs = count_char(*in_out, '>'); } - } - /* - * Count the right-angle-brackets, if needed. - FM - */ - if (isTITLE == TRUE) { - p = *str; - while ((*p != '\0') && (q = strchr(p, '>')) != NULL) { - gts++; - p = (q + 1); - } - } + if (count_AMPs != 0 || count_LTs != 0 || count_GTs != 0) { - /* - * Check whether we need to convert anything. - FM - */ - if (amps == 0 && lts == 0 && gts == 0) - return; + target = typecallocn(char, + (strlen(*in_out) + + (4 * count_AMPs) + + (3 * count_LTs) + + (3 * count_GTs) + 1)); - /* - * Allocate space and convert. - FM - */ - q = typecallocn(char, - (strlen(*str) - + (unsigned)(4 * amps) - + (unsigned)(3 * lts) - + (unsigned)(3 * gts) + 1)); - if ((cp = q) == NULL) - outofmem(__FILE__, "LYEntify"); - - assert(cp != NULL); - assert(q != NULL); - - for (p = *str; *p; p++) { + if ((result = target) == NULL) + outofmem(__FILE__, "LYEntify"); + + for (source = *in_out; *source; source++) { #ifdef CJK_EX - if (IS_CJK_TTY) { - switch (state) { - case S_text: - if (*p == '\033') { - state = S_esc; - *q++ = *p; - continue; - } - break; + if (IS_CJK_TTY) { + switch (state) { + case S_text: + if (*source == '\033') { + state = S_esc; + *target++ = *source; + continue; + } + break; - case S_esc: - if (*p == '$') { - state = S_dollar; - *q++ = *p; - continue; - } else if (*p == '(') { - state = S_paren; - *q++ = *p; - continue; - } else { - state = S_text; - *q++ = *p; - continue; - } + case S_esc: + if (*source == '$') { + state = S_dollar; + } else if (*source == '(') { + state = S_paren; + } else { + state = S_text; + } + *target++ = *source; + continue; - case S_dollar: - if (*p == '@' || *p == 'B' || *p == 'A') { - state = S_nonascii_text; - *q++ = *p; - continue; - } else if (*p == '(') { - state = S_dollar_paren; - *q++ = *p; - continue; - } else { - state = S_text; - *q++ = *p; - continue; - } + case S_dollar: + if (*source == '@' || *source == 'B' || *source == 'A') { + state = S_nonascii_text; + } else if (*source == '(') { + state = S_dollar_paren; + } else { + state = S_text; + } + *target++ = *source; + continue; - case S_dollar_paren: - if (*p == 'C') { - state = S_nonascii_text; - *q++ = *p; - continue; - } else { - state = S_text; - *q++ = *p; - continue; - } + case S_dollar_paren: + if (*source == 'C') { + state = S_nonascii_text; + } else { + state = S_text; + } + *target++ = *source; + continue; - case S_paren: - if (*p == 'B' || *p == 'J' || *p == 'T') { - state = S_text; - *q++ = *p; - continue; - } else if (*p == 'I') { - state = S_nonascii_text; - *q++ = *p; - continue; - } - /* FALLTHRU */ + case S_paren: + if (*source == 'B' || *source == 'J' || *source == 'T') { + state = S_text; + } else if (*source == 'I') { + state = S_nonascii_text; + } else if (*source == '\033') { + state = S_esc; + } + *target++ = *source; + continue; - case S_nonascii_text: - if (*p == '\033') - state = S_esc; - *q++ = *p; - continue; + case S_nonascii_text: + if (*source == '\033') + state = S_esc; + *target++ = *source; + continue; - default: - break; - } - if (*(p + 1) != '\0' && - (IS_EUC(UCH(*p), UCH(*(p + 1))) || - IS_SJIS(UCH(*p), UCH(*(p + 1)), in_sjis) || - IS_BIG5(UCH(*p), UCH(*(p + 1))))) { - *q++ = *p++; - *q++ = *p; - continue; - } - } + default: + break; + } + if (*(source + 1) != '\0' && + (IS_EUC(UCH(*source), UCH(*(source + 1))) || + IS_SJIS(UCH(*source), UCH(*(source + 1)), in_sjis) || + IS_BIG5(UCH(*source), UCH(*(source + 1))))) { + *target++ = *source++; + *target++ = *source; + continue; + } + } #endif - if (*p == '&') { - *q++ = '&'; - *q++ = 'a'; - *q++ = 'm'; - *q++ = 'p'; - *q++ = ';'; - } else if (isTITLE && *p == '<') { - *q++ = '&'; - *q++ = 'l'; - *q++ = 't'; - *q++ = ';'; - } else if (isTITLE && *p == '>') { - *q++ = '&'; - *q++ = 'g'; - *q++ = 't'; - *q++ = ';'; - } else { - *q++ = *p; + switch (*source) { + case '&': + *target++ = '&'; + *target++ = 'a'; + *target++ = 'm'; + *target++ = 'p'; + *target++ = ';'; + break; + case '<': + if (brackets) { + *target++ = '&'; + *target++ = 'l'; + *target++ = 't'; + *target++ = ';'; + break; + } + /* FALLTHRU */ + case '>': + if (brackets) { + *target++ = '&'; + *target++ = 'g'; + *target++ = 't'; + *target++ = ';'; + break; + } + /* FALLTHRU */ + default: + *target++ = *source; + break; + } + } + *target = '\0'; + FREE(*in_out); + *in_out = result; } } - *q = '\0'; - FREE(*str); - *str = cp; } /* diff --git a/src/LYEditmap.c b/src/LYEditmap.c index e49475ca..8f94fce3 100644 --- a/src/LYEditmap.c +++ b/src/LYEditmap.c @@ -1,15 +1,20 @@ /* - * $LynxId: LYEditmap.c,v 1.54 2013/10/13 20:23:07 tom Exp $ + * $LynxId: LYEditmap.c,v 1.68 2013/10/19 20:04:16 tom Exp $ * * LYEditMap.c * Keybindings for line and form editing. */ #include <HTUtils.h> +#include <HTAlert.h> +#include <HTFile.h> #include <LYGlobalDefs.h> +#include <LYCharUtils.h> #include <LYStrings.h> #include <LYKeymap.h> /* KEYMAP_SIZE, LKC_*, LYK_* - kw */ +#define PUTS(buf) (*target->isa->put_string)(target, buf) + /* * * * * LynxEditactionCodes * * * * */ #ifdef USE_ALT_BINDINGS @@ -35,6 +40,72 @@ int escape_bound = 0; /* User wanted Escape to perform actions? */ /* * See LYStrings.h for the LYE definitions. */ +/* *INDENT-OFF* */ +struct emap { + const char *name; + const int code; + const char *descr; +}; + +#define SEPARATOR {"", -1, ""} + +static struct emap ekmap[] = { + {"NOP", LYE_NOP, "Do Nothing"}, + {"CHAR", LYE_CHAR, "Insert printable char"}, + SEPARATOR, + {"ENTER", LYE_ENTER, "Input complete, return char"}, + {"TAB", LYE_TAB, "Input complete, return TAB"}, + {"STOP", LYE_STOP, "Input deactivated"}, + {"ABORT", LYE_ABORT, "Input cancelled"}, + SEPARATOR, + {"PASS", LYE_FORM_PASS, "Fields only: input complete"}, + SEPARATOR, + {"DELBL", LYE_DELBL, "Delete back to BOL"}, + {"DELEL", LYE_DELEL, "Delete thru EOL"}, + {"DELN", LYE_DELN, "Delete next/curr char"}, + {"DELP", LYE_DELP, "Delete prev char"}, + {"DELNW", LYE_DELNW, "Delete next word"}, + {"DELPW", LYE_DELPW, "Delete prev word"}, + SEPARATOR, + + {"ERASE", LYE_ERASE, "Erase the line"}, + SEPARATOR, + {"BOL", LYE_BOL, "Go to begin of line"}, + {"EOL", LYE_EOL, "Go to end of line"}, + {"FORW", LYE_FORW, "Cursor forwards"}, + {"FORW_RL", LYE_FORW_RL, "Cursor forwards or right link"}, + {"BACK", LYE_BACK, "Cursor backwards"}, + {"BACK_LL", LYE_BACK_LL, "Cursor backwards or left link"}, + {"FORWW", LYE_FORWW, "Word forward"}, + {"BACKW", LYE_BACKW, "Word back"}, + SEPARATOR, + {"LOWER", LYE_LOWER, "Lower case the line"}, + {"UPPER", LYE_UPPER, "Upper case the line"}, + SEPARATOR, + {"LKCMD", LYE_LKCMD, "Invoke command prompt"}, + {"SWMAP", LYE_SWMAP, "Switch input keymap"}, + SEPARATOR, + {"C1CHAR", LYE_C1CHAR, "Insert C1 char if printable"}, + {"SETM1", LYE_SETM1, "Set modifier 1 flag"}, + {"SETM2", LYE_SETM2, "Set modifier 2 flag"}, + {"UNMOD", LYE_UNMOD, "Fall back to no-modifier command"}, + SEPARATOR, + {"TPOS", LYE_TPOS, "Transpose characters"}, + {"SETMARK", LYE_SETMARK, "emacs-like set-mark-command"}, + {"XPMARK", LYE_XPMARK, "emacs-like exchange-point-and-mark"}, + {"KILLREG", LYE_KILLREG, "emacs-like kill-region"}, + {"YANK", LYE_YANK, "emacs-like yank"}, +#ifdef CAN_CUT_AND_PASTE + SEPARATOR, + {"PASTE", LYE_PASTE, "ClipBoard to Lynx"}, +#endif + SEPARATOR, + {"AIX", LYE_AIX, "Hex 97"}, + {0, -1, 0}, +}; +#undef SEPARATOR +/* *INDENT-ON* */ + static LYEditCode DefaultEditBinding[KEYMAP_SIZE - 1]; #ifdef USE_ALT_BINDINGS @@ -1170,6 +1241,62 @@ const char *LYLineeditHelpURLs[] = (char *) 0 }; +static struct emap *name2emap(const char *name) +{ + struct emap *mp; + struct emap *result = 0; + + if (non_empty(name)) { + for (mp = ekmap; mp->name != NULL; mp++) { + if (strcmp(mp->name, name) == 0) { + result = mp; + break; + } + } + } + return result; +} + +static struct emap *code2emap(int code) +{ + struct emap *mp; + struct emap *result = 0; + + for (mp = ekmap; mp->name != NULL; mp++) { + if (mp->code == code) { + result = mp; + break; + } + } + return result; +} + +/* + * Return editactioncode whose name is the string func. func must be present + * in the ekmap table. returns -1 if not found. - kw + */ +int lecname_to_lec(const char *func) +{ + struct emap *mp; + int result = -1; + + if ((mp = name2emap(func)) != 0) { + result = mp->code; + } + return result; +} + +const char *lec_to_lecname(int code) +{ + struct emap *mp; + const char *result = 0; + + if ((mp = code2emap(code)) != 0) { + result = mp->name; + } + return result; +} + int EditBinding(int xlkc) { int editaction, xleac = LYE_UNMOD; @@ -1639,3 +1766,174 @@ void LYinitEditmap(void) initLineEditor(&LYModifierBindings[j]); } } + +static char *showRanges(int *state) +{ + char *result = 0; + int range[2]; + int i; + + range[0] = range[1] = -1; + for (i = 0; i < KEYMAP_SIZE - 1; ++i) { + if (!state[i]) { + int code = CurrentLineEditor()[i]; + + if (code == LYE_CHAR) { + if (range[0] < 0) + range[0] = i; + range[1] = i; + state[i] = 3; + } else if (range[0] >= 0) { + if (non_empty(result)) + StrAllocCat(result, ", "); + HTSprintf(&result, "%d-%d", range[0], range[1]); + range[0] = range[1] = -1; + } + } + } + return result; +} + +static int LYLoadEditmap(const char *arg GCC_UNUSED, + HTParentAnchor *anAnchor, + HTFormat format_out, + HTStream *sink) +{ +#define FORMAT " %-*s %-*s - %s\n" + HTFormat format_in = WWW_HTML; + HTStream *target; + int state[KEYMAP_SIZE - 1]; + int width[2]; + char *buf = 0; + char *ranges = 0; + struct emap *mp; + int i; + int hanging; + int wrapped; + int had_output = FALSE; + int result; + + if ((target = HTStreamStack(format_in, format_out, sink, anAnchor)) != 0) { + anAnchor->no_cache = TRUE; + + HTSprintf0(&buf, + "<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n", + CURRENT_EDITMAP_TITLE); + PUTS(buf); + HTSprintf0(&buf, "<pre>\n"); + PUTS(buf); + + /* determine the column-widths we will use for showing bindings */ + width[0] = 0; + width[1] = 0; + for (i = 0; i < KEYMAP_SIZE - 1; ++i) { + int code = CurrentLineEditor()[i]; + + if (code == LYE_NOP) { + state[i] = 1; + } else { + int need; + + if ((mp = code2emap(code)) != 0) { + state[i] = 0; + if ((need = (int) strlen(mp->name)) > width[0]) + width[0] = need; + if ((need = (int) strlen(mp->descr)) > width[1]) + width[1] = need; + } else { + state[i] = 2; + } + } + } + hanging = 2 + width[0] + 2 + width[1] + 5; + wrapped = hanging; + + /* + * Tell which set of bindings we are showing, and link to the + * handcrafted page, which adds explanations. + */ + PUTS(gettext("These are the current edit-bindings:")); + HTSprintf0(&buf, + " <a href=\"%s\">%s</a>\n\n", + LYLineeditHelpURL(), + LYEditorNames[current_lineedit]); + PUTS(buf); + + /* Show by groups to match the arrangement in the handmade files. */ + for (mp = ekmap; mp->name != 0; ++mp) { + if (isEmpty(mp->name)) { + if (had_output) { + PUTS("\n"); + had_output = FALSE; + } + } else if (mp->code == LYE_CHAR) { + ranges = showRanges(state); + HTSprintf0(&buf, FORMAT, + width[0], mp->name, + width[1], mp->descr, + ranges); + FREE(ranges); + PUTS(buf); + had_output = TRUE; + } else { + for (i = 0; i < KEYMAP_SIZE - 1; ++i) { + int code = CurrentLineEditor()[i]; + + if ((code == mp->code) && !state[i]) { + char *value = LYKeycodeToString(i, (i >= 160 && + i <= 255)); + int before = wrapped + (ranges ? ((int) + strlen(ranges)) : 0); + int after = before; + + if (non_empty(ranges)) { + StrAllocCat(ranges, ", "); + after += 2; + } + after += (int) strlen(value) + 2; + if ((before / LYcols) != (after / LYcols)) { + wrapped += (LYcols - (before % LYcols)); + HTSprintf(&ranges, "\n%-*s", hanging, " "); + } + StrAllocCat(ranges, value); + } + } + if (non_empty(ranges)) { + LYEntify(&ranges, TRUE); + HTSprintf0(&buf, FORMAT, + width[0], mp->name, + width[1], mp->descr, + ranges); + PUTS(buf); + FREE(ranges); + had_output = TRUE; + } + } + } + + HTSprintf0(&buf, "</pre>\n</body>\n</html>\n"); + PUTS(buf); + + (*target->isa->_free) (target); + result = HT_LOADED; + } else { + HTSprintf0(&buf, CANNOT_CONVERT_I_TO_O, + HTAtom_name(format_in), HTAtom_name(format_out)); + HTAlert(buf); + result = HT_NOT_LOADED; + } + FREE(ranges); + FREE(buf); + return result; +#undef FORMAT +} + +#ifdef GLOBALDEF_IS_MACRO +#define _LYEDITMAP_C_GLOBALDEF_1_INIT { "LYNXEDITMAP", LYLoadEditmap, 0} +GLOBALDEF(HTProtocol, LYLynxEditmap, _LYEDITMAP_C_GLOBALDEF_1_INIT); +#else +GLOBALDEF HTProtocol LYLynxEditmap = +{ + "LYNXEDITMAP", LYLoadEditmap, 0 +}; +#endif /* GLOBALDEF_IS_MACRO */ diff --git a/src/LYGetFile.c b/src/LYGetFile.c index 3feebcc1..866d780e 100644 --- a/src/LYGetFile.c +++ b/src/LYGetFile.c @@ -1,4 +1,4 @@ -/* $LynxId: LYGetFile.c,v 1.90 2013/10/12 14:51:18 tom Exp $ */ +/* $LynxId: LYGetFile.c,v 1.91 2013/10/19 01:08:57 tom Exp $ */ #include <HTUtils.h> #include <HTTP.h> #include <HTAnchor.h> /* Anchor class */ @@ -189,6 +189,7 @@ int getfile(DocInfo *doc, int *target) if (!(url_type == HTTP_URL_TYPE || url_type == HTTPS_URL_TYPE || url_type == LYNXHIST_URL_TYPE || + url_type == LYNXEDITMAP_URL_TYPE || url_type == LYNXKEYMAP_URL_TYPE || url_type == LYNXIMGMAP_URL_TYPE || url_type == LYNXCOOKIE_URL_TYPE || @@ -225,6 +226,7 @@ int getfile(DocInfo *doc, int *target) if (!(0 == StrNCmp(startrealm, WWWDoc.address, strlen(startrealm)) || url_type == LYNXHIST_URL_TYPE || + url_type == LYNXEDITMAP_URL_TYPE || url_type == LYNXKEYMAP_URL_TYPE || url_type == LYNXIMGMAP_URL_TYPE || url_type == LYNXCOOKIE_URL_TYPE || @@ -560,6 +562,7 @@ int getfile(DocInfo *doc, int *target) * allowed. */ } else if (local_host_only && + url_type != LYNXEDITMAP_URL_TYPE && url_type != LYNXKEYMAP_URL_TYPE && url_type != LYNXIMGMAP_URL_TYPE && url_type != LYNXCOOKIE_URL_TYPE && diff --git a/src/LYHistory.c b/src/LYHistory.c index 32e6b3c7..016fe7be 100644 --- a/src/LYHistory.c +++ b/src/LYHistory.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYHistory.c,v 1.85 2013/04/30 22:20:30 tom Exp $ + * $LynxId: LYHistory.c,v 1.86 2013/10/19 00:46:43 tom Exp $ */ #include <HTUtils.h> #include <HTTP.h> @@ -128,6 +128,7 @@ void LYAddVisitedLink(DocInfo *doc) LYIsUIPage(doc->address, UIP_PRINT_OPTIONS) || LYIsUIPage(doc->address, UIP_DOWNLOAD_OPTIONS) || LYIsUIPage(doc->address, UIP_OPTIONS_MENU) || + isLYNXEDITMAP(doc->address) || isLYNXKEYMAP(doc->address) || LYIsUIPage(doc->address, UIP_LIST_PAGE) || #ifdef USE_ADDRLIST_PAGE diff --git a/src/LYKeymap.c b/src/LYKeymap.c index f7b59ecf..362182c5 100644 --- a/src/LYKeymap.c +++ b/src/LYKeymap.c @@ -1,4 +1,4 @@ -/* $LynxId: LYKeymap.c,v 1.97 2013/10/15 08:16:40 tom Exp $ */ +/* $LynxId: LYKeymap.c,v 1.100 2013/10/19 13:51:38 tom Exp $ */ #include <HTUtils.h> #include <LYUtils.h> #include <LYGlobalDefs.h> @@ -845,6 +845,9 @@ static Kcmd revmap[] = { LYK_JUMP, "JUMP", "go directly to a target document or action" ), DATA( + LYK_EDITMAP, "EDITMAP", + "display the current edit-key map" ), + DATA( LYK_KEYMAP, "KEYMAP", "display the current key map" ), DATA( @@ -1034,67 +1037,6 @@ static const struct { { BACKTAB_KEY, "Back Tab" }, { MOUSE_KEY, "mouse pseudo key" }, }; - -struct emap { - const char *name; - const int code; - const char *descr; -}; - -static struct emap ekmap[] = { - {"NOP", LYE_NOP, "Do Nothing"}, - {"CHAR", LYE_CHAR, "Insert printable char"}, - {"ENTER", LYE_ENTER, "Input complete, return char/lynxkeycode"}, - {"TAB", LYE_TAB, "Input complete, return TAB"}, - {"STOP", LYE_STOP, "Input deactivated"}, - {"ABORT", LYE_ABORT, "Input cancelled"}, - - {"PASS", LYE_FORM_PASS, "In fields: input complete, or Do Nothing"}, - - {"DELN", LYE_DELN, "Delete next/curr char"}, - {"DELP", LYE_DELP, "Delete prev char"}, - {"DELNW", LYE_DELNW, "Delete next word"}, - {"DELPW", LYE_DELPW, "Delete prev word"}, - - {"ERASE", LYE_ERASE, "Erase the line"}, - - {"BOL", LYE_BOL, "Go to begin of line"}, - {"EOL", LYE_EOL, "Go to end of line"}, - {"FORW", LYE_FORW, "Cursor forwards"}, - {"FORW_RL", LYE_FORW_RL, "Cursor forwards or right link"}, - {"BACK", LYE_BACK, "Cursor backwards"}, - {"BACK_LL", LYE_BACK_LL, "Cursor backwards or left link"}, - {"FORWW", LYE_FORWW, "Word forward"}, - {"BACKW", LYE_BACKW, "Word back"}, - - {"LOWER", LYE_LOWER, "Lower case the line"}, - {"UPPER", LYE_UPPER, "Upper case the line"}, - - {"LKCMD", LYE_LKCMD, "Invoke command prompt"}, - - {"AIX", LYE_AIX, "Hex 97"}, - - {"DELBL", LYE_DELBL, "Delete back to BOL"}, - {"DELEL", LYE_DELEL, "Delete thru EOL"}, - - {"SWMAP", LYE_SWMAP, "Switch input keymap"}, - - {"TPOS", LYE_TPOS, "Transpose characters"}, - - {"SETM1", LYE_SETM1, "Set modifier 1 flag"}, - {"SETM2", LYE_SETM2, "Set modifier 2 flag"}, - {"UNMOD", LYE_UNMOD, "Fall back to no-modifier command"}, - - {"C1CHAR", LYE_C1CHAR, "Insert C1 char if printable"}, - - {"SETMARK", LYE_SETMARK, "emacs-like set-mark-command"}, - {"XPMARK", LYE_XPMARK, "emacs-like exchange-point-and-mark"}, - {"KILLREG", LYE_KILLREG, "emacs-like kill-region"}, - {"YANK", LYE_YANK, "emacs-like yank"}, -#ifdef CAN_CUT_AND_PASTE - {"PASTE", LYE_PASTE, "ClipBoard to Lynx"}, -#endif -}; /* *INDENT-ON* */ /* @@ -1364,42 +1306,6 @@ int lacname_to_lac(const char *func) } /* - * Return editactioncode whose name is the string func. func must be present - * in the ekmap table. returns -1 if not found. - kw - */ -int lecname_to_lec(const char *func) -{ - int i; - struct emap *mp; - int result = -1; - - if (non_empty(func)) { - for (i = 0, mp = ekmap; (*mp).name != NULL; mp++, i++) { - if (strcmp((*mp).name, func) == 0) { - result = (*mp).code; - break; - } - } - } - return result; -} - -const char *lec_to_lecname(int code) -{ - struct emap *mp; - int i; - const char *result = 0; - - for (i = 0, mp = ekmap; (*mp).name != NULL; mp++, i++) { - if ((*mp).code == code) { - result = (*mp).name; - break; - } - } - return result; -} - -/* * Return lynxkeycode represented by string src. returns -1 if not valid. * * This is simpler than what map_string_to_keysym() does for USE_KEYMAP, but diff --git a/src/LYKeymap.h b/src/LYKeymap.h index 5e4e3591..98dd67f7 100644 --- a/src/LYKeymap.h +++ b/src/LYKeymap.h @@ -1,4 +1,4 @@ -/* $LynxId: LYKeymap.h,v 1.49 2013/10/12 00:04:22 tom Exp $ */ +/* $LynxId: LYKeymap.h,v 1.50 2013/10/19 12:59:21 tom Exp $ */ #ifndef LYKEYMAP_H #define LYKEYMAP_H @@ -185,6 +185,7 @@ extern "C" { ,LYK_DO_NOTHING ,LYK_TOGGLE_HELP ,LYK_JUMP + ,LYK_EDITMAP ,LYK_KEYMAP ,LYK_LIST ,LYK_TOOLBAR diff --git a/src/LYMain.c b/src/LYMain.c index aecdfb48..dcca4d71 100644 --- a/src/LYMain.c +++ b/src/LYMain.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYMain.c,v 1.246 2013/10/13 20:35:38 tom Exp $ + * $LynxId: LYMain.c,v 1.247 2013/10/19 01:22:25 tom Exp $ */ #include <HTUtils.h> #include <HTTP.h> @@ -2262,6 +2262,7 @@ int main(int argc, * LYNXKEYMAP, lynxcgi, LYNXIMGMAP, LYNXCOOKIE, LYNXCACHE, LYNXMESSAGES */ #ifdef GLOBALREF_IS_MACRO +extern GLOBALREF (HTProtocol, LYLynxEditmap); extern GLOBALREF (HTProtocol, LYLynxKeymap); extern GLOBALREF (HTProtocol, LYLynxCGI); extern GLOBALREF (HTProtocol, LYLynxIMGmap); @@ -2273,6 +2274,7 @@ extern GLOBALREF (HTProtocol, LYLynxCache); extern GLOBALREF (HTProtocol, LYLynxStatusMessages); #else +GLOBALREF HTProtocol LYLynxEditmap; GLOBALREF HTProtocol LYLynxKeymap; GLOBALREF HTProtocol LYLynxCGI; GLOBALREF HTProtocol LYLynxIMGmap; @@ -2286,6 +2288,7 @@ GLOBALREF HTProtocol LYLynxStatusMessages; void LYRegisterLynxProtocols(void) { + HTRegisterProtocol(&LYLynxEditmap); HTRegisterProtocol(&LYLynxKeymap); HTRegisterProtocol(&LYLynxCGI); HTRegisterProtocol(&LYLynxIMGmap); diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c index 011432b7..500f91ae 100644 --- a/src/LYMainLoop.c +++ b/src/LYMainLoop.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYMainLoop.c,v 1.224 2013/10/13 20:23:07 tom Exp $ + * $LynxId: LYMainLoop.c,v 1.226 2013/10/19 13:06:29 tom Exp $ */ #include <HTUtils.h> #include <HTAccess.h> @@ -1101,9 +1101,7 @@ static int handle_LYK_ACTIVATE(int *c, * FM */ if (isLYNXCOOKIE(links[curdoc.link].l_form->submit_action) || -#ifdef USE_CACHEJAR isLYNXCACHE(links[curdoc.link].l_form->submit_action) || -#endif #ifdef DIRED_SUPPORT #ifdef OK_PERMIT (isLYNXDIRED(links[curdoc.link].l_form->submit_action) && @@ -1118,6 +1116,7 @@ static int handle_LYK_ACTIVATE(int *c, #endif /* DIRED_SUPPORT */ isLYNXDOWNLOAD(links[curdoc.link].l_form->submit_action) || isLYNXHIST(links[curdoc.link].l_form->submit_action) || + isLYNXEDITMAP(links[curdoc.link].l_form->submit_action) || isLYNXKEYMAP(links[curdoc.link].l_form->submit_action) || isLYNXIMGMAP(links[curdoc.link].l_form->submit_action) || isLYNXPRINT(links[curdoc.link].l_form->submit_action) || @@ -1275,13 +1274,10 @@ static int handle_LYK_ACTIVATE(int *c, */ if (no_file_url && isFILE_URL(links[curdoc.link].lname)) { if (!isFILE_URL(curdoc.address) && - !((isLYNXKEYMAP(curdoc.address) || -#ifndef USE_CACHEJAR - isLYNXCOOKIE(curdoc.address)) && -#else + !((isLYNXEDITMAP(curdoc.address) || + isLYNXKEYMAP(curdoc.address) || isLYNXCOOKIE(curdoc.address) || isLYNXCACHE(curdoc.address)) && -#endif !StrNCmp(links[curdoc.link].lname, helpfilepath, strlen(helpfilepath)))) { @@ -1476,10 +1472,7 @@ static int handle_LYK_ACTIVATE(int *c, } #endif /* DIRED_SUPPORT && !__DJGPP__ */ if (isLYNXCOOKIE(curdoc.address) -#ifdef USE_CACHEJAR - || isLYNXCACHE(curdoc.address) -#endif - ) { + || isLYNXCACHE(curdoc.address)) { HTuncache_current_document(); } } @@ -1649,9 +1642,7 @@ static void handle_LYK_ADD_BOOKMARK(BOOLEAN *refresh_screen, #endif /* DIRED_SUPPORT */ !LYIsUIPage(curdoc.address, UIP_DOWNLOAD_OPTIONS) && !isLYNXCOOKIE(curdoc.address) && -#ifdef USE_CACHEJAR !isLYNXCACHE(curdoc.address) && -#endif !LYIsUIPage(curdoc.address, UIP_OPTIONS_MENU) && ((nlinks <= 0) || (links[curdoc.link].lname != NULL && @@ -1660,9 +1651,7 @@ static void handle_LYK_ADD_BOOKMARK(BOOLEAN *refresh_screen, !isLYNXDIRED(links[curdoc.link].lname) && !isLYNXDOWNLOAD(links[curdoc.link].lname) && !isLYNXCOOKIE(links[curdoc.link].lname) && -#ifdef USE_CACHEJAR !isLYNXCACHE(links[curdoc.link].lname) && -#endif !isLYNXPRINT(links[curdoc.link].lname)))) { if (nlinks > 0) { if (curdoc.post_data == NULL && @@ -2276,9 +2265,7 @@ static int handle_LYK_DOWNLOAD(int *cmd, } } else if (isLYNXCOOKIE(links[curdoc.link].lname) || -#ifdef USE_CACHEJAR isLYNXCACHE(links[curdoc.link].lname) || -#endif isLYNXDIRED(links[curdoc.link].lname) || isLYNXDOWNLOAD(links[curdoc.link].lname) || isLYNXPRINT(links[curdoc.link].lname) || @@ -2628,6 +2615,43 @@ static void handle_LYK_DWIMHELP(const char **cshelpfile) } } +static void handle_LYK_EDITMAP(BOOLEAN *vi_keys_flag, + BOOLEAN *emacs_keys_flag, + int *old_c, + int real_c) +{ + if (*old_c != real_c) { + *old_c = real_c; + set_address(&newdoc, STR_LYNXEDITMAP); + StrAllocCopy(newdoc.title, CURRENT_EDITMAP_TITLE); + LYFreePostData(&newdoc); + FREE(newdoc.bookmark); + newdoc.isHEAD = FALSE; + newdoc.safe = FALSE; + newdoc.internal_link = FALSE; + /* + * If vi_keys changed, the keymap did too, so force no cache, and reset + * the flag. - FM + */ + if (*vi_keys_flag != vi_keys || + *emacs_keys_flag != emacs_keys) { + LYforce_no_cache = TRUE; + *vi_keys_flag = vi_keys; + *emacs_keys_flag = emacs_keys; + } +#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE) + /* + * Remember whether we are in dired menu so we can display the right + * keymap. + */ + if (!no_dired_support) { + prev_lynx_edit_mode = lynx_edit_mode; + } +#endif /* DIRED_SUPPORT && OK_OVERRIDE */ + LYforce_no_cache = TRUE; + } +} + static void handle_LYK_EDIT_TEXTAREA(BOOLEAN *refresh_screen, int *old_c, int real_c) @@ -5885,9 +5909,7 @@ int mainloop(void) HTMainText && nlinks > 0 && curdoc.link < nlinks && !isLYNXHIST(NonNull(newdoc.address)) && -#ifdef USE_CACHEJAR !isLYNXCACHE(NonNull(newdoc.address)) && -#endif !isLYNXCOOKIE(NonNull(newdoc.address))) { char *mail_owner = NULL; @@ -7675,6 +7697,10 @@ int mainloop(void) handle_LYK_TOGGLE_HELP(); break; + case LYK_EDITMAP: + handle_LYK_EDITMAP(&vi_keys_flag, &emacs_keys_flag, &old_c, real_c); + break; + case LYK_KEYMAP: handle_LYK_KEYMAP(&vi_keys_flag, &emacs_keys_flag, &old_c, real_c); break; diff --git a/src/LYUtils.c b/src/LYUtils.c index 8256e44b..6aedd0e3 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYUtils.c,v 1.253 2013/10/18 00:39:19 tom Exp $ + * $LynxId: LYUtils.c,v 1.254 2013/10/19 00:59:45 tom Exp $ */ #include <HTUtils.h> #include <HTTCP.h> @@ -2292,16 +2292,14 @@ static BOOLEAN compare_type(char *tst, && CompareType(tst, cmp, len)) /* - * Must recognize a URL and return the type. - * If recognized, based on a case-insensitive - * analysis of the scheme field, ensures that - * the scheme field has the expected case. + * Must recognize a URL and return the type. If recognized, based on a + * case-insensitive analysis of the scheme field, ensures that the scheme field + * has the expected case. * - * Returns 0 (not a URL) for a NULL argument, - * one which lacks a colon. + * Returns 0 (not a URL) for a NULL argument, one which lacks a colon. * - * Chains to LYCheckForProxyURL() if a colon - * is present but the type is not recognized. + * Chains to LYCheckForProxyURL() if a colon is present but the type is not + * recognized. */ UrlTypes is_url(char *filename) { @@ -2357,92 +2355,56 @@ UrlTypes is_url(char *filename) } else if (CompareType(cp, STR_LYNXPROG, LEN_LYNXPROG)) { /* * Special External Lynx type to handle execution of commands, - * scripts or programs with do not require a pause to read + * scripts or programs which do not require a pause to read * screen upon completion. */ result = LYNXPROG_URL_TYPE; } else if (CompareType(cp, STR_LYNXCGI, LEN_LYNXCGI)) { - /* - * Special External Lynx type to handle cgi scripts. - */ result = LYNXCGI_URL_TYPE; } else if (CompareType(cp, STR_LYNXPRINT, LEN_LYNXPRINT)) { - /* - * Special Internal Lynx type. - */ result = LYNXPRINT_URL_TYPE; } else if (CompareType(cp, STR_LYNXOPTIONS, LEN_LYNXOPTIONS)) { - /* - * Special Internal Lynx type. - */ result = LYNXOPTIONS_URL_TYPE; } else if (CompareType(cp, STR_LYNXCFG, LEN_LYNXCFG)) { - /* - * Special Internal Lynx type. - */ result = LYNXCFG_URL_TYPE; } else if (CompareType(cp, STR_LYNXMESSAGES, LEN_LYNXMESSAGES)) { - /* - * Special Internal Lynx type. - */ result = LYNXMESSAGES_URL_TYPE; } else if (CompareType(cp, STR_LYNXCFLAGS, LEN_LYNXCFLAGS)) { - /* - * Special Internal Lynx type. - */ result = LYNXCOMPILE_OPTS_URL_TYPE; } else if (CompareType(cp, STR_LYNXDOWNLOAD, LEN_LYNXDOWNLOAD)) { - /* - * Special Internal Lynx type. - */ result = LYNXDOWNLOAD_URL_TYPE; } else if (CompareType(cp, STR_LYNXDIRED, LEN_LYNXDIRED)) { - /* - * Special Internal Lynx type. - */ result = LYNXDIRED_URL_TYPE; + } else if (CompareType(cp, STR_LYNXEDITMAP, LEN_LYNXEDITMAP)) { + result = LYNXEDITMAP_URL_TYPE; + } else if (CompareType(cp, STR_LYNXHIST, LEN_LYNXHIST)) { - /* - * Special Internal Lynx type. - */ result = LYNXHIST_URL_TYPE; #ifdef USE_CACHEJAR } else if (CompareType(cp, STR_LYNXCACHE, LEN_LYNXCACHE)) { - /* - * Special Internal Lynx type. - */ result = LYNXCACHE_URL_TYPE; #endif - } else if (CompareType(cp, STR_LYNXKEYMAP, LEN_LYNXKEYMAP)) { - /* - * Special Internal Lynx type. - */ result = LYNXKEYMAP_URL_TYPE; } else if (CompareType(cp, STR_LYNXIMGMAP, LEN_LYNXIMGMAP)) { - /* - * Special Internal Lynx type. - */ /* force lower/uppercase of next part */ (void) is_url(&cp[LEN_LYNXIMGMAP]); result = LYNXIMGMAP_URL_TYPE; } else if (CompareType(cp, STR_LYNXCOOKIE, LEN_LYNXCOOKIE)) { - /* - * Special Internal Lynx type. - */ result = LYNXCOOKIE_URL_TYPE; + } break; #ifndef DISABLE_NEWS @@ -6586,34 +6548,37 @@ BOOL LYIsUIPage3(const char *url, { unsigned int i; size_t l; + BOOL result = NO; - if (!url) - return NO; - for (i = 0; i < TABLESIZE(ly_uip); i++) { - if (ly_uip[i].type == type) { - if (!ly_uip[i].url) { - return NO; - } else if ((flagparam & UIP_P_FRAG) ? - (!StrNCmp(ly_uip[i].url, url, (l = strlen(ly_uip[i].url))) - && (url[l] == '\0' || url[l] == '#')) : - !strcmp(ly_uip[i].url, url)) { - return YES; - } else if (ly_uip[i].flags & UIP_F_MULTI) { - char *p; - HTList *l0 = ly_uip[i].alturls; - - while ((p = (char *) HTList_nextObject(l0)) != NULL) { - if ((flagparam & UIP_P_FRAG) ? - (!StrNCmp(p, url, (l = strlen(p))) - && (url[l] == '\0' || url[l] == '#')) : - !strcmp(p, url)) - return YES; + if (url) { + for (i = 0; i < TABLESIZE(ly_uip); i++) { + if (ly_uip[i].type == type) { + if (!ly_uip[i].url) { + break; + } else if ((flagparam & UIP_P_FRAG) ? + (!StrNCmp(ly_uip[i].url, url, (l = strlen(ly_uip[i].url))) + && (url[l] == '\0' || url[l] == '#')) : + !strcmp(ly_uip[i].url, url)) { + result = YES; + } else if (ly_uip[i].flags & UIP_F_MULTI) { + char *p; + HTList *l0 = ly_uip[i].alturls; + + while ((p = (char *) HTList_nextObject(l0)) != NULL) { + if ((flagparam & UIP_P_FRAG) + ? (!StrNCmp(p, url, (l = strlen(p))) && + (url[l] == '\0' || url[l] == '#')) + : !strcmp(p, url)) { + result = YES; + break; + } + } } + break; } - return NO; } } - return NO; + return result; } void LYRegisterUIPage(const char *url, diff --git a/src/LYUtils.h b/src/LYUtils.h index ba5de817..3545b6f8 100644 --- a/src/LYUtils.h +++ b/src/LYUtils.h @@ -1,4 +1,4 @@ -/* $LynxId: LYUtils.h,v 1.91 2012/02/09 18:55:26 tom Exp $ */ +/* $LynxId: LYUtils.h,v 1.92 2013/10/19 00:55:45 tom Exp $ */ #ifndef LYUTILS_H #define LYUTILS_H @@ -358,6 +358,7 @@ extern "C" { LYNXCOOKIE_URL_TYPE, LYNXDIRED_URL_TYPE, LYNXDOWNLOAD_URL_TYPE, + LYNXEDITMAP_URL_TYPE, LYNXHIST_URL_TYPE, LYNXIMGMAP_URL_TYPE, LYNXKEYMAP_URL_TYPE, @@ -439,9 +440,13 @@ extern "C" { #define isWAIS_URL(addr) !strncasecomp(addr, STR_WAIS_URL, LEN_WAIS_URL) /* internal URLs */ +#ifdef USE_CACHEJAR #define STR_LYNXCACHE "LYNXCACHE:" #define LEN_LYNXCACHE 10 #define isLYNXCACHE(addr) !strncasecomp(addr, STR_LYNXCACHE, LEN_LYNXCACHE) +#else +#define isLYNXCACHE(addr) FALSE +#endif #define STR_LYNXCFG "LYNXCFG:" #define LEN_LYNXCFG 8 @@ -473,6 +478,10 @@ extern "C" { #define LEN_LYNXDOWNLOAD 13 #define isLYNXDOWNLOAD(addr) !strncasecomp(addr, STR_LYNXDOWNLOAD, LEN_LYNXDOWNLOAD) +#define STR_LYNXEDITMAP "LYNXEDITMAP:" +#define LEN_LYNXEDITMAP 11 +#define isLYNXEDITMAP(addr) !strncasecomp(addr, STR_LYNXEDITMAP, LEN_LYNXEDITMAP) + #define STR_LYNXHIST "LYNXHIST:" #define LEN_LYNXHIST 9 #define isLYNXHIST(addr) !strncasecomp(addr, STR_LYNXHIST, LEN_LYNXHIST) |