diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 2013-10-14 00:13:37 -0400 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 2013-10-14 00:13:37 -0400 |
commit | ed46d3cc0121dbce87345bbbb119cd4080c247c7 (patch) | |
tree | c34bdd611f309476e5c1c1d7b72bf43236b522fb /src/LYStrings.c | |
parent | f1977d62c94d74a72d1c7a4abbbecdec21e3980e (diff) | |
download | lynx-snapshots-ed46d3cc0121dbce87345bbbb119cd4080c247c7.tar.gz |
snapshot of project "lynx", label v2-8-8dev_16q
Diffstat (limited to 'src/LYStrings.c')
-rw-r--r-- | src/LYStrings.c | 2054 |
1 files changed, 998 insertions, 1056 deletions
diff --git a/src/LYStrings.c b/src/LYStrings.c index ac5405c3..66acf897 100644 --- a/src/LYStrings.c +++ b/src/LYStrings.c @@ -1,4 +1,4 @@ -/* $LynxId: LYStrings.c,v 1.215 2013/10/02 23:58:20 tom Exp $ */ +/* $LynxId: LYStrings.c,v 1.253 2013/10/13 20:47:25 tom Exp $ */ #include <HTUtils.h> #include <HTCJK.h> #include <UCAux.h> @@ -54,6 +54,12 @@ #define CTRACE_EDIT(p) /*nothing */ #endif +#ifdef SUPPORT_MULTIBYTE_EDIT +#define IsWordChar(c) (isalnum(UCH(c)) || is8bits(c)) +#else +#define IsWordChar(c) isalnum(UCH(c)) +#endif + /* * The edit_history lists allow the user to press tab when entering URL to get * the closest match in the closet @@ -406,7 +412,7 @@ static int set_clicked_link(int x, else if (clicks > 1) { if (x < left + toolbar) c = (code == FOR_PROMPT && y) - ? HOME : LAC_TO_LKC0(LYK_MAIN_MENU); + ? HOME_KEY : LAC_TO_LKC0(LYK_MAIN_MENU); else if (x > right) c = (code == FOR_PROMPT && y) ? END_KEY : LAC_TO_LKC0(LYK_VLINKS); @@ -417,7 +423,7 @@ static int set_clicked_link(int x, } else { if (x < left + toolbar) c = (code == FOR_PROMPT && y) - ? LTARROW + ? LTARROW_KEY : ( #ifdef USE_COLOR_STYLE (s_forw_backw != NOSTYLE && x - toolbar >= 3) @@ -429,7 +435,7 @@ static int set_clicked_link(int x, ); else if (x > right) c = (code == FOR_PROMPT && y) - ? RTARROW : LAC_TO_LKC0(LYK_HISTORY); + ? RTARROW_KEY : LAC_TO_LKC0(LYK_HISTORY); else if (y) /* Last row */ c = LAC_TO_LKC0(LYK_NEXT_PAGE); else /* First row */ @@ -569,28 +575,28 @@ static int set_clicked_link(int x, #endif /* USE_MOUSE */ /* - * LYstrncpy() terminates strings with a null byte. Writes a null byte into - * the n+1 byte of dst. + * LYstrncpy() ensures that the copied strings end with a nul byte. + * The nul is written to the n+1 position of the target. */ -char *LYstrncpy(char *dst, - const char *src, +char *LYstrncpy(char *target, + const char *source, int n) { - char *val = dst; + char *val = target; int len; - if (src == 0) - src = ""; - len = (int) strlen(src); + if (source == 0) + source = ""; + len = (int) strlen(source); if (n > 0) { if (n > len) n = len; - (void) StrNCpy(dst, src, n); + (void) StrNCpy(target, source, n); } else { n = 0; } - dst[n] = '\0'; + target[n] = '\0'; return val; } @@ -599,17 +605,17 @@ char *LYstrncpy(char *dst, /* * LYmbcsstrncpy() terminates strings with a null byte. It takes account of - * multibyte characters. The src string is copied until either end of string + * multibyte characters. The source string is copied until either end of string * or max number of either bytes or glyphs (mbcs sequences) (CJK or UTF8). The * utf_flag argument should be TRUE for UTF8. - KW & FM */ -char *LYmbcsstrncpy(char *dst, - const char *src, +char *LYmbcsstrncpy(char *target, + const char *source, int n_bytes, int n_glyphs, int utf_flag) { - char *val = dst; + char *val = target; int i_bytes = 0, i_glyphs = 0; if (n_bytes < 0) @@ -617,16 +623,16 @@ char *LYmbcsstrncpy(char *dst, if (n_glyphs < 0) n_glyphs = 0; - for (; *src != '\0' && i_bytes < n_bytes; i_bytes++) { - if (IS_NEW_GLYPH(*src)) { + for (; *source != '\0' && i_bytes < n_bytes; i_bytes++) { + if (IS_NEW_GLYPH(*source)) { if (i_glyphs++ >= n_glyphs) { - *dst = '\0'; + *target = '\0'; return val; } } - *(dst++) = *(src++); + *(target++) = *(source++); } - *dst = '\0'; + *target = '\0'; return val; } @@ -900,8 +906,8 @@ void ena_csi(int flag) (unsigned) code, \ Keymap_List) #if SLANG_VERSION < 20000 -#define expand_substring(dst, first, last, final) \ - (SLexpand_escaped_string(dst, \ +#define expand_substring(target, first, last, final) \ + (SLexpand_escaped_string(target, \ (char *)first, \ (char *)last), 1) static int SLang_get_error(void) @@ -911,8 +917,8 @@ static int SLang_get_error(void) #else int LY_Slang_UTF8_Mode = 0; -#define expand_substring(dst, first, last, final) \ - (SLexpand_escaped_string(dst, \ +#define expand_substring(target, first, last, final) \ + (SLexpand_escaped_string(target, \ (char *)first, \ (char *)last, \ LY_Slang_UTF8_Mode), 1) @@ -934,28 +940,40 @@ static SLKeyMap_List_Type *Keymap_List; # else # define EXTERN_KEY(string,string1,lynx,curses) {string,lynx},{string1,lynx} # endif -# define INTERN_KEY(string,lynx,curses) {string,lynx} +# define INTERN_KEY(string,lynx,curses) {string,lynx,lynx} #else -#define INTERN_KEY(string,lynx,curses) {string,curses} -#define EXTERN_KEY(string,string1,lynx,curses) {string,curses} +# define INTERN_KEY(string,lynx,curses) {string,curses,lynx} +# define EXTERN_KEY(string,string1,lynx,curses) {string,curses,lynx} #endif typedef struct { const char *string; int value; + LYExtraKeys internal; } Keysym_String_List; /* *INDENT-OFF* */ static Keysym_String_List Keysym_Strings [] = { - INTERN_KEY( "UPARROW", UPARROW, KEY_UP ), - INTERN_KEY( "DNARROW", DNARROW, KEY_DOWN ), - INTERN_KEY( "RTARROW", RTARROW, KEY_RIGHT ), - INTERN_KEY( "LTARROW", LTARROW, KEY_LEFT ), - INTERN_KEY( "PGDOWN", PGDOWN, KEY_NPAGE ), - INTERN_KEY( "PGUP", PGUP, KEY_PPAGE ), - INTERN_KEY( "HOME", HOME, KEY_HOME ), + INTERN_KEY( "UPARROW", UPARROW_KEY, KEY_UP ), + INTERN_KEY( "DNARROW", DNARROW_KEY, KEY_DOWN ), + INTERN_KEY( "RTARROW", RTARROW_KEY, KEY_RIGHT ), + INTERN_KEY( "LTARROW", LTARROW_KEY, KEY_LEFT ), + INTERN_KEY( "PGDOWN", PGDOWN_KEY, KEY_NPAGE ), + INTERN_KEY( "PGUP", PGUP_KEY, KEY_PPAGE ), + INTERN_KEY( "HOME", HOME_KEY, KEY_HOME ), INTERN_KEY( "END", END_KEY, KEY_END ), - INTERN_KEY( "F1", F1, KEY_F(1) ), + INTERN_KEY( "F1", F1_KEY, KEY_F(1) ), + INTERN_KEY( "F2", F2_KEY, KEY_F(2) ), + INTERN_KEY( "F3", F3_KEY, KEY_F(3) ), + INTERN_KEY( "F4", F4_KEY, KEY_F(4) ), + INTERN_KEY( "F5", F5_KEY, KEY_F(5) ), + INTERN_KEY( "F6", F6_KEY, KEY_F(7) ), + INTERN_KEY( "F7", F7_KEY, KEY_F(7) ), + INTERN_KEY( "F8", F8_KEY, KEY_F(8) ), + INTERN_KEY( "F9", F9_KEY, KEY_F(9) ), + INTERN_KEY( "F10", F10_KEY, KEY_F(10) ), + INTERN_KEY( "F11", F11_KEY, KEY_F(11) ), + INTERN_KEY( "F12", F12_KEY, KEY_F(12) ), INTERN_KEY( "DO_KEY", DO_KEY, KEY_F(16) ), INTERN_KEY( "FIND_KEY", FIND_KEY, KEY_FIND ), INTERN_KEY( "SELECT_KEY", SELECT_KEY, KEY_SELECT ), @@ -1070,7 +1088,7 @@ static const char *expand_tichar(const char *first, char **result, char *final) return first; } -static BOOLEAN expand_substring(char *dst, +static BOOLEAN expand_substring(char *target, const char *first, const char *last, char *final) @@ -1080,27 +1098,27 @@ static BOOLEAN expand_substring(char *dst, while (first < last) { switch (ch = *first++) { case ESCAPE: - first = expand_tichar(first, &dst, final); + first = expand_tichar(first, &target, final); break; case '^': ch = *first++; if (ch == LPAREN) { const char *s = strchr(first, RPAREN); - char *was = dst; + char *was = target; if (s == 0) s = first + strlen(first); - first = expand_tiname(first, (size_t) (s - first), &dst, final); - if (dst == was) + first = expand_tiname(first, (size_t) (s - first), &target, final); + if (target == was) return FALSE; if (*first) first++; } else if (ch == '?') { /* ASCII delete? */ - *dst++ = 127; + *target++ = 127; } else if ((ch & 0x3f) < 0x20) { /* ASCII control char? */ - *dst++ = (char) (ch & 0x1f); + *target++ = (char) (ch & 0x1f); } else { - *dst++ = '^'; + *target++ = '^'; first--; /* not legal... */ } break; @@ -1108,11 +1126,11 @@ static BOOLEAN expand_substring(char *dst, ch = 0200; /* FALLTHRU */ default: - *dst++ = (char) ch; + *target++ = (char) ch; break; } } - *dst = '\0'; + *target = '\0'; return TRUE; } #endif @@ -1132,27 +1150,43 @@ static void unescaped_char(const char *parse, int *keysym) } } -static BOOLEAN unescape_string(char *src, char *dst, char *final) +static BOOLEAN unescape_string(char *source, char *target, char *final) { BOOLEAN ok = FALSE; - if (*src == SQUOTE) { + if (*source == SQUOTE) { int keysym = -1; - unescaped_char(src, &keysym); + unescaped_char(source, &keysym); if (keysym >= 0) { - dst[0] = (char) keysym; - dst[1] = '\0'; + target[0] = (char) keysym; + target[1] = '\0'; ok = TRUE; } - } else if (*src == DQUOTE) { - if (expand_substring(dst, src + 1, src + strlen(src) - 1, final)) + } else if (*source == DQUOTE) { + if (expand_substring(target, source + 1, source + strlen(source) - 1, final)) ok = TRUE; (void) final; } return ok; } +static Keysym_String_List *lookupKeysymByName(const char *name) +{ + Keysym_String_List *k; + Keysym_String_List *result = 0; + + k = Keysym_Strings; + while (k->string != NULL) { + if (0 == strcasecomp(k->string, name)) { + result = k; + break; + } + k++; + } + return result; +} + int map_string_to_keysym(const char *str, int *keysym) { int modifier = 0; @@ -1223,15 +1257,10 @@ int map_string_to_keysym(const char *str, int *keysym) #endif } } else { - Keysym_String_List *k; + Keysym_String_List *k = lookupKeysymByName(str); - k = Keysym_Strings; - while (k->string != NULL) { - if (0 == strcmp(k->string, str)) { - *keysym = k->value; - break; - } - k++; + if (k != 0) { + *keysym = k->value; } } @@ -1240,6 +1269,32 @@ int map_string_to_keysym(const char *str, int *keysym) return (*keysym); } +LYExtraKeys LYnameToExtraKeys(const char *name) +{ + Keysym_String_List *k = lookupKeysymByName(name); + LYExtraKeys result = -1; + + if (k != 0) + result = k->internal; + return result; +} + +const char *LYextraKeysToName(LYExtraKeys code) +{ + Keysym_String_List *k; + const char *result = 0; + + k = Keysym_Strings; + while (k->string != NULL) { + if (k->internal == code) { + result = k->string; + break; + } + k++; + } + return result; +} + /* * Starting at a nonblank character, skip over a token, counting quoted and * escaped characters. @@ -1404,55 +1459,68 @@ static void setup_vtXXX_keymap(void) { /* *INDENT-OFF* */ static Keysym_String_List table[] = { - INTERN_KEY( "\033[A", UPARROW, KEY_UP ), - INTERN_KEY( "\033OA", UPARROW, KEY_UP ), - INTERN_KEY( "\033[B", DNARROW, KEY_DOWN ), - INTERN_KEY( "\033OB", DNARROW, KEY_DOWN ), - INTERN_KEY( "\033[C", RTARROW, KEY_RIGHT ), - INTERN_KEY( "\033OC", RTARROW, KEY_RIGHT ), - INTERN_KEY( "\033[D", LTARROW, KEY_LEFT ), - INTERN_KEY( "\033OD", LTARROW, KEY_LEFT ), + INTERN_KEY( "\033[A", UPARROW_KEY, KEY_UP ), + INTERN_KEY( "\033OA", UPARROW_KEY, KEY_UP ), + INTERN_KEY( "\033[B", DNARROW_KEY, KEY_DOWN ), + INTERN_KEY( "\033OB", DNARROW_KEY, KEY_DOWN ), + INTERN_KEY( "\033[C", RTARROW_KEY, KEY_RIGHT ), + INTERN_KEY( "\033OC", RTARROW_KEY, KEY_RIGHT ), + INTERN_KEY( "\033[D", LTARROW_KEY, KEY_LEFT ), + INTERN_KEY( "\033OD", LTARROW_KEY, KEY_LEFT ), INTERN_KEY( "\033[1~", FIND_KEY, KEY_FIND ), INTERN_KEY( "\033[2~", INSERT_KEY, KEY_IC ), INTERN_KEY( "\033[3~", REMOVE_KEY, KEY_DC ), INTERN_KEY( "\033[4~", SELECT_KEY, KEY_SELECT ), - INTERN_KEY( "\033[5~", PGUP, KEY_PPAGE ), - INTERN_KEY( "\033[6~", PGDOWN, KEY_NPAGE ), - INTERN_KEY( "\033[7~", HOME, KEY_HOME), + INTERN_KEY( "\033[5~", PGUP_KEY, KEY_PPAGE ), + INTERN_KEY( "\033[6~", PGDOWN_KEY, KEY_NPAGE ), + INTERN_KEY( "\033[7~", HOME_KEY, KEY_HOME), INTERN_KEY( "\033[8~", END_KEY, KEY_END ), - INTERN_KEY( "\033[11~", F1, KEY_F(1) ), - INTERN_KEY( "\033[28~", F1, KEY_F(1) ), - INTERN_KEY( "\033OP", F1, KEY_F(1) ), - INTERN_KEY( "\033[OP", F1, KEY_F(1) ), + INTERN_KEY( "\033[11~", F1_KEY, KEY_F(1) ), + INTERN_KEY( "\033[28~", F1_KEY, KEY_F(1) ), + INTERN_KEY( "\033OP", F1_KEY, KEY_F(1) ), + INTERN_KEY( "\033[OP", F1_KEY, KEY_F(1) ), INTERN_KEY( "\033[29~", DO_KEY, KEY_F(16) ), -#if defined(USE_SLANG) && (defined(__WIN32__) || defined(__MINGW32__)) - INTERN_KEY( "\xE0H", UPARROW, KEY_UP ), - INTERN_KEY( "\xE0P", DNARROW, KEY_DOWN ), - INTERN_KEY( "\xE0M", RTARROW, KEY_RIGHT ), - INTERN_KEY( "\xE0K", LTARROW, KEY_LEFT ), +#if defined(USE_SLANG) +#if defined(__WIN32__) || defined(__MINGW32__) + INTERN_KEY( "\xE0H", UPARROW_KEY, KEY_UP ), + INTERN_KEY( "\xE0P", DNARROW_KEY, KEY_DOWN ), + INTERN_KEY( "\xE0M", RTARROW_KEY, KEY_RIGHT ), + INTERN_KEY( "\xE0K", LTARROW_KEY, KEY_LEFT ), INTERN_KEY( "\xE0R", INSERT_KEY, KEY_IC ), INTERN_KEY( "\xE0S", REMOVE_KEY, KEY_DC ), - INTERN_KEY( "\xE0I", PGUP, KEY_PPAGE ), - INTERN_KEY( "\xE0Q", PGDOWN, KEY_NPAGE ), - INTERN_KEY( "\xE0G", HOME, KEY_HOME), + INTERN_KEY( "\xE0I", PGUP_KEY, KEY_PPAGE ), + INTERN_KEY( "\xE0Q", PGDOWN_KEY, KEY_NPAGE ), + INTERN_KEY( "\xE0G", HOME_KEY, KEY_HOME), INTERN_KEY( "\xE0O", END_KEY, KEY_END ), #endif -#if defined(USE_SLANG) && !defined(VMS) - INTERN_KEY( "^(ku)", UPARROW, KEY_UP ), - INTERN_KEY( "^(kd)", DNARROW, KEY_DOWN ), - INTERN_KEY( "^(kr)", RTARROW, KEY_RIGHT ), - INTERN_KEY( "^(kl)", LTARROW, KEY_LEFT ), +#if !defined(VMS) + INTERN_KEY( "^(ku)", UPARROW_KEY, KEY_UP ), + INTERN_KEY( "^(kd)", DNARROW_KEY, KEY_DOWN ), + INTERN_KEY( "^(kr)", RTARROW_KEY, KEY_RIGHT ), + INTERN_KEY( "^(kl)", LTARROW_KEY, KEY_LEFT ), INTERN_KEY( "^(@0)", FIND_KEY, KEY_FIND ), INTERN_KEY( "^(kI)", INSERT_KEY, KEY_IC ), INTERN_KEY( "^(kD)", REMOVE_KEY, KEY_DC ), INTERN_KEY( "^(*6)", SELECT_KEY, KEY_SELECT ), - INTERN_KEY( "^(kP)", PGUP, KEY_PPAGE ), - INTERN_KEY( "^(kN)", PGDOWN, KEY_NPAGE ), + INTERN_KEY( "^(kP)", PGUP_KEY, KEY_PPAGE ), + INTERN_KEY( "^(kN)", PGDOWN_KEY, KEY_NPAGE ), INTERN_KEY( "^(@7)", END_KEY, KEY_END ), - INTERN_KEY( "^(kh)", HOME, KEY_HOME), - INTERN_KEY( "^(k1)", F1, KEY_F(1) ), + INTERN_KEY( "^(kh)", HOME_KEY, KEY_HOME), + INTERN_KEY( "^(k1)", F1_KEY, KEY_F(1) ), + INTERN_KEY( "^(k2)", F2_KEY, KEY_F(2) ), + INTERN_KEY( "^(k3)", F3_KEY, KEY_F(3) ), + INTERN_KEY( "^(k4)", F4_KEY, KEY_F(4) ), + INTERN_KEY( "^(k5)", F5_KEY, KEY_F(5) ), + INTERN_KEY( "^(k6)", F6_KEY, KEY_F(6) ), + INTERN_KEY( "^(k7)", F7_KEY, KEY_F(7) ), + INTERN_KEY( "^(k8)", F8_KEY, KEY_F(8) ), + INTERN_KEY( "^(k9)", F9_KEY, KEY_F(9) ), + INTERN_KEY( "^(k;)", F10_KEY, KEY_F(10) ), + INTERN_KEY( "^(F1)", F11_KEY, KEY_F(11) ), + INTERN_KEY( "^(F2)", F12_KEY, KEY_F(12) ), INTERN_KEY( "^(F6)", DO_KEY, KEY_F(16) ), -#endif /* SLANG && !VMS */ +#endif /* !VMS */ +#endif /* SLANG */ }; /* *INDENT-ON* */ @@ -1647,16 +1715,16 @@ static int LYgetch_for(int code) keysym = key->f.keysym; switch (keysym) { case 'H': - keysym = UPARROW; + keysym = UPARROW_KEY; break; case 'P': - keysym = DNARROW; + keysym = DNARROW_KEY; break; case 'M': - keysym = RTARROW; + keysym = RTARROW_KEY; break; case 'K': - keysym = LTARROW; + keysym = LTARROW_KEY; break; case 'R': keysym = INSERT_KEY; @@ -1665,51 +1733,52 @@ static int LYgetch_for(int code) keysym = REMOVE_KEY; break; case 'I': - keysym = PGUP; + keysym = PGUP_KEY; break; case 'Q': - keysym = PGDOWN; + keysym = PGDOWN_KEY; break; case 'G': - keysym = HOME; + keysym = HOME_KEY; break; case 'O': keysym = END_KEY; break; case ';': - keysym = F1; + keysym = F1_KEY; break; } return (keysym); } #endif - return (current_sl_modifier ? 0 : DO_NOTHING); - } - - keysym = (int) key->f.keysym; + } else { + keysym = (int) key->f.keysym; #if defined (USE_MOUSE) - if (keysym == MOUSE_KEYSYM) - return sl_read_mouse_event(code); + if (keysym == MOUSE_KEYSYM) + return sl_read_mouse_event(code); #endif - if (keysym < 0) - return 0; + if (keysym < 0) { + return 0; - if (keysym & (LKC_ISLECLAC | LKC_ISLAC)) - return (keysym); + } else if (keysym & (LKC_ISLECLAC | LKC_ISLAC)) { + return (keysym); + } else { + current_sl_modifier = 0; + if (LKC_HAS_ESC_MOD(keysym)) { + current_sl_modifier = LKC_MOD2; + keysym &= LKC_MASK; + } - current_sl_modifier = 0; - if (LKC_HAS_ESC_MOD(keysym)) { - current_sl_modifier = LKC_MOD2; - keysym &= LKC_MASK; + if (keysym + 1 >= KEYMAP_SIZE) { + return 0; + } else { + return (keysym | current_sl_modifier); + } + } } - - if (keysym + 1 >= KEYMAP_SIZE) - return 0; - - return (keysym | current_sl_modifier); } /************************************************************************/ @@ -1854,40 +1923,40 @@ static int LYgetch_for(int code) switch (a) { case 'A': - c = UPARROW; + c = UPARROW_KEY; break; case 'B': - c = DNARROW; + c = DNARROW_KEY; break; case 'C': - c = RTARROW; + c = RTARROW_KEY; break; case 'D': - c = LTARROW; + c = LTARROW_KEY; break; case 'q': /* vt100 application keypad 1 */ c = END_KEY; break; case 'r': /* vt100 application keypad 2 */ - c = DNARROW; + c = DNARROW_KEY; break; case 's': /* vt100 application keypad 3 */ - c = PGDOWN; + c = PGDOWN_KEY; break; case 't': /* vt100 application keypad 4 */ - c = LTARROW; + c = LTARROW_KEY; break; case 'v': /* vt100 application keypad 6 */ - c = RTARROW; + c = RTARROW_KEY; break; case 'w': /* vt100 application keypad 7 */ - c = HOME; + c = HOME_KEY; break; case 'x': /* vt100 application keypad 8 */ - c = UPARROW; + c = UPARROW_KEY; break; case 'y': /* vt100 application keypad 9 */ - c = PGUP; + c = PGUP_KEY; break; case 'M': #if defined(USE_SLANG) && defined(USE_MOUSE) @@ -1920,13 +1989,13 @@ static int LYgetch_for(int code) #ifdef VMS if (b != 'O') #endif /* VMS */ - c = F1; + c = F1_KEY; break; case 'u': #ifdef VMS if (b != 'O') #endif /* VMS */ - c = F1; /* macintosh help button */ + c = F1_KEY; /* macintosh help button */ break; case 'p': #ifdef VMS @@ -1948,7 +2017,7 @@ static int LYgetch_for(int code) d == '9') && found_TLD(GetChar())) { if (d == '8') /* VTxxx Help */ - c = F1; + c = F1_KEY; else if (d == '9') /* VTxxx Do */ c = DO_KEY; d = -1; @@ -1970,20 +2039,20 @@ static int LYgetch_for(int code) break; case '5': /** VTxxx PrevScreen **/ if (found_CSI(c, b) && found_TLD(d = GetChar())) - c = PGUP; + c = PGUP_KEY; else done_esc = FALSE; /* we have another look below - kw */ break; case '6': /** VTxxx NextScreen **/ if (found_CSI(c, b) && found_TLD(d = GetChar())) - c = PGDOWN; + c = PGDOWN_KEY; else done_esc = FALSE; /* we have another look below - kw */ break; case '[': /** Linux F1-F5: ^[[[A etc. **/ if (found_CSI(c, b)) { if ((d = GetChar()) == 'A') - c = F1; + c = F1_KEY; break; } /* FALLTHRU */ @@ -2037,29 +2106,29 @@ static int LYgetch_for(int code) */ switch (c) { case KEY_DOWN: /* The four arrow keys ... */ - c = DNARROW; + c = DNARROW_KEY; break; case KEY_UP: - c = UPARROW; + c = UPARROW_KEY; break; case KEY_LEFT: - c = LTARROW; + c = LTARROW_KEY; break; case KEY_RIGHT: /* ... */ - c = RTARROW; + c = RTARROW_KEY; break; #if defined(PDCURSES) /* for NEC PC-9800 1998/08/30 (Sun) 21:50:35 */ case KEY_C2: - c = DNARROW; + c = DNARROW_KEY; break; case KEY_A2: - c = UPARROW; + c = UPARROW_KEY; break; case KEY_B1: - c = LTARROW; + c = LTARROW_KEY; break; case KEY_B3: - c = RTARROW; + c = RTARROW_KEY; break; case PAD0: /* PC-9800 Ins */ c = INSERT_KEY; @@ -2069,16 +2138,16 @@ static int LYgetch_for(int code) break; #endif /* PDCURSES */ case KEY_HOME: /* Home key (upward+left arrow) */ - c = HOME; + c = HOME_KEY; break; case KEY_CLEAR: /* Clear screen */ c = 18; /* CTRL-R */ break; case KEY_NPAGE: /* Next page */ - c = PGDOWN; + c = PGDOWN_KEY; break; case KEY_PPAGE: /* Previous page */ - c = PGUP; + c = PGUP_KEY; break; case KEY_LL: /* home down or bottom (lower left) */ c = END_KEY; @@ -2089,10 +2158,10 @@ static int LYgetch_for(int code) /* left b2 right */ /* c1 down c3 */ case KEY_A1: /* upper left of keypad */ - c = HOME; + c = HOME_KEY; break; case KEY_A3: /* upper right of keypad */ - c = PGUP; + c = PGUP_KEY; break; case KEY_B2: /* center of keypad */ c = DO_NOTHING; @@ -2101,7 +2170,7 @@ static int LYgetch_for(int code) c = END_KEY; break; case KEY_C3: /* lower right of keypad */ - c = PGDOWN; + c = PGDOWN_KEY; break; #endif /* defined(KEY_A1) && defined(KEY_C3) */ #ifdef KEY_ENTER @@ -2121,7 +2190,7 @@ static int LYgetch_for(int code) #endif /* KEY_END */ #ifdef KEY_HELP case KEY_HELP: /* help key 001 */ - c = F1; + c = F1_KEY; break; #endif /* KEY_HELP */ #ifdef KEY_BACKSPACE @@ -2130,7 +2199,7 @@ static int LYgetch_for(int code) break; #endif /* KEY_BACKSPACE */ case KEY_F(1): - c = F1; /* VTxxx Help */ + c = F1_KEY; /* VTxxx Help */ break; #if defined(KEY_F) && !defined(__DJGPP__) && !defined(_WINDOWS) case KEY_F(16): @@ -2183,15 +2252,6 @@ static int LYgetch_for(int code) recent_sizechange)); #endif /* HAVE_SIZECHANGE || USE_SLANG */ if (!recent_sizechange) { -#if 0 /* assumption seems flawed? */ - /* Not detected by us or already processed by us. It can - * happens that ncurses lags behind us in detecting the change, - * since its own SIGTSTP handler is not installed so detecting - * happened *at the end* of the last refresh. Tell it to - * refresh again... - kw - */ - LYrefresh(); -#endif #if defined(NCURSES) /* * Work-around for scenario (Linux libc5) where we got a @@ -2312,10 +2372,6 @@ static int LYgetch_for(int code) lac = LYK_REFRESH; } c = LAC_TO_LKC(lac); -#if 0 /* Probably not necessary any more - kw */ - lynx_force_repaint(); - LYrefresh(); -#endif } #if NCURSES_MOUSE_VERSION > 1 else if (event.bstate & BUTTON4_PRESSED) { @@ -2367,31 +2423,31 @@ static int LYgetch_for(int code) if (MOUSE_Y_POS > (LYlines - V_CMD_AREA - 1)) { /* Screen BOTTOM */ if (MOUSE_X_POS < left) { - c = LTARROW; + c = LTARROW_KEY; p = "<-"; } else if (MOUSE_X_POS < HIST_CMD_2) { - c = RTARROW; + c = RTARROW_KEY; p = "->"; } else if (MOUSE_X_POS > right) { c = 'z'; p = "Cancel"; } else { - c = PGDOWN; + c = PGDOWN_KEY; p = "PGDOWN"; } } else if (MOUSE_Y_POS < V_CMD_AREA) { /* Screen TOP */ if (MOUSE_X_POS < left) { - c = LTARROW; + c = LTARROW_KEY; p = "<-"; } else if (MOUSE_X_POS < HIST_CMD_2) { - c = RTARROW; + c = RTARROW_KEY; p = "->"; } else if (MOUSE_X_POS > right) { c = 'z'; p = "Cancel"; } else { - c = PGUP; + c = PGUP_KEY; p = "PGUP"; } } else { @@ -2420,38 +2476,38 @@ static int LYgetch_for(int code) switch (c) { case K_Down: /* The four arrow keys ... */ case K_EDown: - c = DNARROW; + c = DNARROW_KEY; break; case K_Up: case K_EUp: - c = UPARROW; + c = UPARROW_KEY; break; case K_Left: case K_ELeft: - c = LTARROW; + c = LTARROW_KEY; break; case K_Right: /* ... */ case K_ERight: - c = RTARROW; + c = RTARROW_KEY; break; case K_Home: /* Home key (upward+left arrow) */ case K_EHome: - c = HOME; + c = HOME_KEY; break; case K_PageDown: /* Next page */ case K_EPageDown: - c = PGDOWN; + c = PGDOWN_KEY; break; case K_PageUp: /* Previous page */ case K_EPageUp: - c = PGUP; + c = PGUP_KEY; break; case K_End: /* home down or bottom (lower left) */ case K_EEnd: c = END_KEY; break; case K_F1: /* F1 key */ - c = F1; + c = F1_KEY; break; case K_Insert: /* Insert key */ case K_EInsert: @@ -2478,35 +2534,35 @@ static int LYgetch_for(int code) #if defined(USE_SLANG) && (defined(__DJGPP__) || defined(__CYGWIN__)) && !defined(DJGPP_KEYHANDLER) && !defined(USE_KEYMAPS) switch (c) { case SL_KEY_DOWN: /* The four arrow keys ... */ - c = DNARROW; + c = DNARROW_KEY; break; case SL_KEY_UP: - c = UPARROW; + c = UPARROW_KEY; break; case SL_KEY_LEFT: - c = LTARROW; + c = LTARROW_KEY; break; case SL_KEY_RIGHT: /* ... */ - c = RTARROW; + c = RTARROW_KEY; break; case SL_KEY_HOME: /* Home key (upward+left arrow) */ case SL_KEY_A1: /* upper left of keypad */ - c = HOME; + c = HOME_KEY; break; case SL_KEY_NPAGE: /* Next page */ case SL_KEY_C3: /* lower right of keypad */ - c = PGDOWN; + c = PGDOWN_KEY; break; case SL_KEY_PPAGE: /* Previous page */ case SL_KEY_A3: /* upper right of keypad */ - c = PGUP; + c = PGUP_KEY; break; case SL_KEY_END: /* home down or bottom (lower left) */ case SL_KEY_C1: /* lower left of keypad */ c = END_KEY; break; case SL_KEY_F(1): /* F1 key */ - c = F1; + c = F1_KEY; break; case SL_KEY_IC: /* Insert key */ c = INSERT_KEY; @@ -2518,9 +2574,9 @@ static int LYgetch_for(int code) #endif /* USE_SLANG && __DJGPP__ && !DJGPP_KEYHANDLER && !USE_KEYMAPS */ } - if (c & (LKC_ISLAC | LKC_ISLECLAC)) + if (c & (LKC_ISLAC | LKC_ISLECLAC)) { return (c); - if ((c + 1) >= KEYMAP_SIZE) { + } else if ((c + 1) >= KEYMAP_SIZE) { /* * Don't return raw values for KEYPAD symbols which we may have missed * in the switch above if they are obviously invalid when used as an @@ -2587,9 +2643,8 @@ void LYLowerCase(char *arg_buffer) register unsigned char *buffer = (unsigned char *) arg_buffer; size_t i; - for (i = 0; buffer[i]; i++) + for (i = 0; buffer[i]; i++) { #ifdef SUPPORT_MULTIBYTE_EDIT /* 1998/11/23 (Mon) 17:04:55 */ - { if ((buffer[i] & 0x80) != 0 && buffer[i + 1] != 0) { if ((kanji_code == SJIS) && IS_SJIS_X0201KANA(UCH((buffer[i])))) { @@ -2599,10 +2654,10 @@ void LYLowerCase(char *arg_buffer) } else { buffer[i] = UCH(TOLOWER(buffer[i])); } - } #else buffer[i] = TOLOWER(buffer[i]); #endif + } } /* @@ -2613,9 +2668,8 @@ void LYUpperCase(char *arg_buffer) register unsigned char *buffer = (unsigned char *) arg_buffer; size_t i; - for (i = 0; buffer[i]; i++) + for (i = 0; buffer[i]; i++) { #ifdef SUPPORT_MULTIBYTE_EDIT /* 1998/11/23 (Mon) 17:05:10 */ - { if ((buffer[i] & 0x80) != 0 && buffer[i + 1] != 0) { if ((kanji_code == SJIS) && IS_SJIS_X0201KANA(UCH((buffer[i])))) { @@ -2625,10 +2679,10 @@ void LYUpperCase(char *arg_buffer) } else { buffer[i] = UCH(TOUPPER(buffer[i])); } - } #else buffer[i] = UCH(TOUPPER(buffer[i])); #endif + } } /* @@ -2636,6 +2690,8 @@ void LYUpperCase(char *arg_buffer) */ BOOLEAN LYRemoveNewlines(char *buffer) { + BOOLEAN result = FALSE; + if (buffer != 0) { register char *buf = buffer; @@ -2649,10 +2705,10 @@ BOOLEAN LYRemoveNewlines(char *buffer) *buf++ = *old; } *buf = '\0'; - return TRUE; + result = TRUE; } } - return FALSE; + return result; } /* @@ -2675,6 +2731,8 @@ char *LYReduceBlanks(char *buffer) */ char *LYRemoveBlanks(char *buffer) { + char *result = NULL; + if (buffer != 0) { register char *buf = buffer; @@ -2689,9 +2747,9 @@ char *LYRemoveBlanks(char *buffer) } *buf = '\0'; } - return buf; + result = buf; } - return NULL; + return result; } /* @@ -2799,6 +2857,8 @@ char *LYElideString(char *str, */ BOOLEAN LYTrimStartfile(char *buffer) { + BOOLEAN result = FALSE; + LYTrimHead(buffer); if (isLYNXEXEC(buffer) || isLYNXPROG(buffer)) { @@ -2810,9 +2870,9 @@ BOOLEAN LYTrimStartfile(char *buffer) */ HTUnEscapeSome(buffer, " \r\n\t"); convert_to_spaces(buffer, TRUE); - return TRUE; + result = TRUE; } - return FALSE; + return result; } /* @@ -2839,53 +2899,58 @@ void LYTrimAllStartfile(char *buffer) } /* - * Display the current value of the string and allow the user - * to edit it. + * Display the current value of the string and allow the user to edit it. */ -#define EDREC EditFieldData - /* * Shorthand to get rid of the "edit->suchandsos". */ -#define IsDirty edit->dirty -#define IsHidden edit->hidden -#define StartX edit->sx -#define StartY edit->sy -#define Buf edit->buffer -#define Pos edit->pos /* current editing position (bytes) */ -#define StrLen edit->buffer_used /* length (bytes) */ -#define MaxLen edit->buffer_size -#define BufLimit edit->buffer_limit -#define DspWdth edit->dspwdth -#define DspStart edit->xpan /* display-start (columns) */ -#define Margin edit->margin -#define PanOn edit->panon -#define PadChar edit->pad +#define IsDirty edit->efIsDirty +#define IsHidden edit->efIsMasked +#define StartX edit->efStartX +#define StartY edit->efStartY +#define Buffer edit->efBuffer +#define EditAt edit->efEditAt /* current editing position (bytes) */ +#define BufInUse edit->efBufInUse /* length (bytes) */ +#define BufAlloc edit->efBufAlloc +#define BufLimit edit->efBufLimit +#define DpyWidth edit->efWidth +#define DpyStart edit->efDpyStart /* display-start (columns) */ +#define PanMargin edit->efPanMargin +#define IsPanned edit->efIsPanned +#define PadChar edit->efPadChar #ifdef ENHANCED_LINEEDIT -#define Mark edit->mark +#define EditMark edit->efEditMark #endif -#define CurModif edit->current_modifiers -#define Offs2Col edit->offset2col +#define InputMods edit->efInputMods +#define Offs2Col edit->efOffs2Col + +#define enableEditMark() \ + if (EditMark < 0) \ + EditMark = -(1 + EditMark) + +#define disableEditMark() \ + if (EditMark >= 0) \ + EditMark = -(1 + EditMark) #ifdef ENHANCED_LINEEDIT static bstring *killbuffer; #endif -static void updateMargin(EDREC * edit) +static void updateMargin(FieldEditor * edit) { - if ((int) MaxLen > DspWdth) { /* Need panning? */ - if (DspWdth > 4) /* Else "{}" take up precious screen space */ - PanOn = TRUE; + if ((int) BufAlloc > DpyWidth) { /* Need panning? */ + if (DpyWidth > 4) + IsPanned = TRUE; /* * Figure out margins. If too big, we do a lot of unnecessary * scrolling. If too small, user doesn't have sufficient look-ahead. * Let's say 25% for each margin, upper bound is 10 columns. */ - Margin = DspWdth / 4; - if (Margin > 10) - Margin = 10; + PanMargin = DpyWidth / 4; + if (PanMargin > 10) + PanMargin = 10; } } @@ -2893,34 +2958,34 @@ static void updateMargin(EDREC * edit) * Before using an array position, make sure that the array is long enough. * Reallocate if needed. */ -static void ExtendEditor(EDREC * edit, int position) +static void ExtendEditor(FieldEditor * edit, int position) { size_t need = (size_t) (++position); - if (need >= MaxLen && (BufLimit == 0 || need < BufLimit)) { - CTRACE((tfp, "ExtendEditor from %u to %u\n", - (unsigned) MaxLen, - (unsigned) need)); - Buf = typeRealloc(char, Buf, need); + if (need >= BufAlloc && (BufLimit == 0 || need < BufLimit)) { + CTRACE((tfp, "ExtendEditor from %lu to %lu\n", + (unsigned long) BufAlloc, + (unsigned long) need)); + Buffer = typeRealloc(char, Buffer, need); Offs2Col = typeRealloc(int, Offs2Col, need + 1); - MaxLen = need; + BufAlloc = need; updateMargin(edit); } } -void LYFinishEdit(EDREC * edit) +void LYFinishEdit(FieldEditor * edit) { - CTRACE((tfp, "LYFinishEdit:%s\n", NonNull(Buf))); + CTRACE((tfp, "LYFinishEdit:%s\n", NonNull(Buffer))); - FREE(Buf); + FREE(Buffer); FREE(Offs2Col); } -void LYSetupEdit(EDREC * edit, char *old_value, size_t buffer_limit, int display_limit) +void LYSetupEdit(FieldEditor * edit, char *old_value, size_t buffer_limit, int display_limit) { - CTRACE((tfp, "LYSetupEdit buffer %u, display %d:%s\n", - (unsigned) buffer_limit, + CTRACE((tfp, "LYSetupEdit buffer %lu, display %d:%s\n", + (unsigned long) buffer_limit, display_limit, old_value)); @@ -2934,28 +2999,28 @@ void LYSetupEdit(EDREC * edit, char *old_value, size_t buffer_limit, int display LYGetYX(StartY, StartX); PadChar = ' '; IsDirty = TRUE; - PanOn = FALSE; - CurModif = 0; + IsPanned = FALSE; + InputMods = 0; - MaxLen = buffer_limit; - DspWdth = display_limit; - Margin = 0; - Pos = (int) strlen(old_value); + BufAlloc = buffer_limit; + DpyWidth = display_limit; + PanMargin = 0; + EditAt = (int) strlen(old_value); #ifdef ENHANCED_LINEEDIT - Mark = -1; /* pos=0, but do not show it yet */ + EditMark = -1; /* pos=0, but do not show it yet */ #endif - DspStart = 0; + DpyStart = 0; updateMargin(edit); - StrLen = strlen(old_value); - Buf = typecallocn(char, MaxLen + 1); + BufInUse = strlen(old_value); + Buffer = typecallocn(char, BufAlloc + 1); - if (Buf == 0) + if (Buffer == 0) outofmem(__FILE__, "LYSetupEdit"); - LYStrNCpy(Buf, old_value, buffer_limit); - Offs2Col = typecallocn(int, MaxLen + 1); + LYStrNCpy(Buffer, old_value, buffer_limit); + Offs2Col = typecallocn(int, BufAlloc + 1); if (Offs2Col == 0) outofmem(__FILE__, "LYSetupEdit"); @@ -3065,13 +3130,13 @@ static int map_active = 0; #define map_active 0 #endif -int LYEditInsert(EDREC * edit, unsigned const char *s, +int LYEditInsert(FieldEditor * edit, unsigned const char *s, int len, int map GCC_UNUSED, int maxMessage) { - int length = (int) strlen(Buf); - int remains = (int) MaxLen - (length + len); + int length = (int) strlen(Buffer); + int remains = (int) BufAlloc - (length + len); int edited = 0, overflow = 0; /* @@ -3080,20 +3145,20 @@ int LYEditInsert(EDREC * edit, unsigned const char *s, if (remains < 0) { overflow = 1; len = 0; - if ((int) MaxLen > length) /* Insert as much as we can */ - len = (int) MaxLen - length; + if ((int) BufAlloc > length) /* Insert as much as we can */ + len = (int) BufAlloc - length; else goto finish; } ExtendEditor(edit, length + len); - Buf[length + len] = '\0'; - for (; length >= Pos; length--) /* Make room */ - Buf[length + len] = Buf[length]; + Buffer[length + len] = '\0'; + for (; length >= EditAt; length--) /* Make room */ + Buffer[length + len] = Buffer[length]; #ifdef EXP_KEYBOARD_LAYOUT if (map < 0) map = map_active; if (map && IS_UTF8_TTY) { - int off = Pos; + int off = EditAt; unsigned const char *e = s + len; char *tail = 0; @@ -3111,31 +3176,31 @@ int LYEditInsert(EDREC * edit, unsigned const char *s, remains -= l - 1; if (remains < 0) { if (tail) - strcpy(Buf + off, tail); + strcpy(Buffer + off, tail); FREE(tail); len = off; overflow = 1; goto finish; } if (l > 1 && !tail) - StrAllocCopy(tail, Buf + Pos + len); + StrAllocCopy(tail, Buffer + EditAt + len); } else utfbuf[0] = '?'; } else utfbuf[0] = (char) ucode; } - StrNCpy(Buf + off, utfbuf, l); + StrNCpy(Buffer + off, utfbuf, l); edited = 1; off += l; s++; } if (tail) - strcpy(Buf + off, tail); - len = off - Pos; + strcpy(Buffer + off, tail); + len = off - EditAt; FREE(tail); } else if (map) { unsigned const char *e = s + len; - unsigned char *t = (unsigned char *) Buf + Pos; + unsigned char *t = (unsigned char *) Buffer + EditAt; while (s < e) { int ch; @@ -3154,46 +3219,48 @@ int LYEditInsert(EDREC * edit, unsigned const char *s, } else #endif /* defined EXP_KEYBOARD_LAYOUT */ { - StrNCpy(Buf + Pos, (const char *) s, len); + StrNCpy(Buffer + EditAt, (const char *) s, len); edited = 1; } finish: - Pos += len; - StrLen += (size_t) len; + EditAt += len; + BufInUse += (size_t) len; if (edited) IsDirty = TRUE; if (overflow && maxMessage) _statusline(MAXLEN_REACHED_DEL_OR_MOV); #ifdef ENHANCED_LINEEDIT - if (Mark > Pos) - Mark += len; - else if (Mark < -(1 + Pos)) - Mark -= len; - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ + if (EditMark > EditAt) + EditMark += len; + else if (EditMark < -(1 + EditAt)) + EditMark -= len; + disableEditMark(); #endif return edited; } -/* returns 0 character processed - * -ch if action should be performed outside of line-editing mode - * ch otherwise +/* + * Do one edit-operation, given the input 'ch' and working buffer 'edit'. + * + * If the input is processed, returns zero. + * If the action should be performed outside of line-editing mode, return -ch. + * Otherwise, e.g., returns 'ch'. */ -int LYEdit1(EDREC * edit, int ch, - int action, - int maxMessage) +int LYDoEdit(FieldEditor * edit, int ch, + int action, + int maxMessage) { int i; int length; unsigned char uch; int offset; - if ((int) MaxLen <= 0) + if ((int) BufAlloc <= 0) return (0); /* Be defensive */ - StrLen = strlen(&Buf[0]); - length = (int) StrLen; + BufInUse = strlen(&Buffer[0]); + length = (int) BufInUse; switch (action) { #ifdef EXP_KEYBOARD_LAYOUT @@ -3207,10 +3274,8 @@ int LYEdit1(EDREC * edit, int ch, #ifndef CJK_EX case LYE_AIX: /* - * Hex 97. - * Fall through as a character for CJK, or if this is a valid character - * in the current display character set. Otherwise, we treat this as - * LYE_ENTER. + * Handle CJK characters, or as a valid character in the current + * display character set. Otherwise, we treat this as LYE_ENTER. */ if (!IS_CJK_TTY && LYlowest_eightbit[current_char_set] > 0x97) return (ch); @@ -3227,28 +3292,27 @@ int LYEdit1(EDREC * edit, int ch, * replacement for a character in the 8-bit C1 control range. * * This is meant to undo transformations like 0x81 -> 0x1b 0x41 (ESC A) - * etc. done by slang on Unix and possibly some comm programs. It's + * etc., done by slang on Unix and possibly some comm programs. It's * an imperfect workaround that doesn't work for all such characters. */ ch &= 0xFF; if (ch + 64 >= LYlowest_eightbit[current_char_set]) ch += 64; - if (Pos <= ((int) MaxLen) && StrLen < MaxLen) { + if (EditAt <= ((int) BufAlloc) && BufInUse < BufAlloc) { #ifdef ENHANCED_LINEEDIT - if (Mark > Pos) - Mark++; - else if (Mark < -(1 + Pos)) - Mark--; - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ + if (EditMark > EditAt) + EditMark++; + else if (EditMark < -(1 + EditAt)) + EditMark--; + disableEditMark(); #endif ExtendEditor(edit, length + 1); - for (i = length; i >= Pos; i--) /* Make room */ - Buf[i + 1] = Buf[i]; - Buf[length + 1] = '\0'; - Buf[Pos] = (char) ch; - Pos++; + for (i = length; i >= EditAt; i--) /* Make room */ + Buffer[i + 1] = Buffer[i]; + Buffer[length + 1] = '\0'; + Buffer[EditAt] = (char) ch; + EditAt++; } else { if (maxMessage) { _statusline(MAXLEN_REACHED_DEL_OR_MOV); @@ -3257,203 +3321,143 @@ int LYEdit1(EDREC * edit, int ch, } break; - case LYE_BACKW: - /* - * Backword. - * Definition of word is very naive: 1 or more a/n characters. - */ -#ifndef SUPPORT_MULTIBYTE_EDIT - while (Pos && !isalnum(UCH(Buf[Pos - 1]))) - Pos--; - while (Pos && isalnum(UCH(Buf[Pos - 1]))) - Pos--; -#else - while (Pos && !(isalnum(UCH(Buf[Pos - 1])) || is8bits(Buf[Pos - 1]))) - Pos--; - while (Pos && (isalnum(UCH(Buf[Pos - 1])) || is8bits(Buf[Pos - 1]))) - Pos--; -#endif + case LYE_BACKW: /* go backward one word */ + while (EditAt && !IsWordChar(Buffer[EditAt - 1])) + EditAt--; + while (EditAt && IsWordChar(UCH(Buffer[EditAt - 1]))) + EditAt--; break; - case LYE_FORWW: - /* - * Word forward. - */ -#ifndef SUPPORT_MULTIBYTE_EDIT - while (isalnum(UCH(Buf[Pos]))) - Pos++; /* '\0' is not a/n */ - while (!isalnum(UCH(Buf[Pos])) && Buf[Pos]) - Pos++; -#else - while (isalnum(UCH(Buf[Pos])) || is8bits(Buf[Pos])) - Pos++; /* '\0' is not a/n */ - while (!(isalnum(UCH(Buf[Pos])) || is8bits(Buf[Pos])) && Buf[Pos]) - Pos++; -#endif + case LYE_FORWW: /* go forward one word */ + while (IsWordChar(UCH(Buffer[EditAt]))) + EditAt++; + while (!IsWordChar(Buffer[EditAt]) && Buffer[EditAt]) + EditAt++; break; - case LYE_ERASE: - /* - * Erase the line to start fresh. - */ - Buf[0] = '\0'; + case LYE_ERASE: /* erase the line */ + Buffer[0] = '\0'; #ifdef ENHANCED_LINEEDIT - Mark = -1; /* Do not show the mark */ + EditMark = -1; /* Do not show the mark */ #endif - /* fall through */ + /* FALLTHRU */ - case LYE_BOL: - /* - * Go to first column. - */ - Pos = 0; + case LYE_BOL: /* go to beginning of line */ + EditAt = 0; break; - case LYE_EOL: - /* - * Go to last column. - */ - Pos = length; + case LYE_EOL: /* go to end of line */ + EditAt = length; break; - case LYE_DELNW: - /* - * Delete next word. - */ - offset = Pos; - LYEdit1(edit, 0, LYE_FORWW, FALSE); - offset = Pos - offset; - Pos -= offset; + case LYE_DELNW: /* delete next word */ + offset = EditAt; + LYDoEdit(edit, 0, LYE_FORWW, FALSE); + offset = EditAt - offset; + EditAt -= offset; goto shrink; /* right below */ - case LYE_DELPW: - /* - * Delete previous word. - */ - offset = Pos; - LYEdit1(edit, 0, LYE_BACKW, FALSE); - offset -= Pos; + case LYE_DELPW: /* delete previous word */ + offset = EditAt; + LYDoEdit(edit, 0, LYE_BACKW, FALSE); + offset -= EditAt; shrink: - for (i = Pos; i < length - offset + 1; i++) - Buf[i] = Buf[i + offset]; + for (i = EditAt; i < length - offset + 1; i++) + Buffer[i] = Buffer[i + offset]; #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Mark <= -(1 + Pos + offset)) - Mark += offset; /* Shift it */ - if (-(1 + Pos + offset) < Mark && Mark < -(1 + Pos)) - Mark = -(1 + Pos); /* Set to the current position */ + disableEditMark(); + if (EditMark <= -(1 + EditAt + offset)) + EditMark += offset; /* Shift it */ + if (-(1 + EditAt + offset) < EditMark && EditMark < -(1 + EditAt)) + EditMark = -(1 + EditAt); /* Set to the current position */ #endif break; - case LYE_DELBL: - /* - * Delete from current cursor position back to BOL. - */ - for (i = Pos; i < length + 1; i++) - Buf[i - Pos] = Buf[i]; + case LYE_DELBL: /* delete from cursor to beginning of line */ + for (i = EditAt; i < length + 1; i++) + Buffer[i - EditAt] = Buffer[i]; #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Mark <= -(1 + Pos)) - Mark += Pos; /* Shift it */ + disableEditMark(); + if (EditMark <= -(1 + EditAt)) + EditMark += EditAt; /* Shift it */ else - Mark = -1; /* Reset it */ + EditMark = -1; /* Reset it */ #endif - Pos = 0; + EditAt = 0; break; - case LYE_DELEL: /* @@@ */ - /* - * Delete from current cursor position thru EOL. - */ - Buf[Pos] = '\0'; + case LYE_DELEL: /* delete from cursor to end of line */ + Buffer[EditAt] = '\0'; #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Mark <= -(1 + Pos)) - Mark = -1; /* Reset it */ + disableEditMark(); + if (EditMark <= -(1 + EditAt)) + EditMark = -1; /* Reset it */ #endif break; - case LYE_DELN: - /* - * Delete next character (I-beam style cursor), or current character - * (box/underline style cursor). - */ - if (Pos >= length) + case LYE_DELN: /* delete next character */ + if (EditAt >= length) break; #ifndef SUPPORT_MULTIBYTE_EDIT - Pos++; + EditAt++; #else - Pos += mbcs_skip(Buf + Pos, 1); + EditAt += mbcs_skip(Buffer + EditAt, 1); #endif - /* fall through - DO NOT RELOCATE the LYE_DELN case wrt LYE_DELP */ + /* FALLTHRU */ - case LYE_DELP: - /* - * Delete preceding character. - */ - if (length == 0 || Pos == 0) + case LYE_DELP: /* delete previous character */ + if (length == 0 || EditAt == 0) break; #ifndef SUPPORT_MULTIBYTE_EDIT #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Mark <= -(1 + Pos)) - Mark++; + disableEditMark(); + if (EditMark <= -(1 + EditAt)) + EditMark++; #endif - Pos--; - for (i = Pos; i < length; i++) - Buf[i] = Buf[i + 1]; + EditAt--; + for (i = EditAt; i < length; i++) + Buffer[i] = Buffer[i + 1]; #else /* SUPPORT_MULTIBYTE_EDIT */ - offset = Pos - mbcs_skip(Buf, mbcs_glyphs(Buf, Pos) - 1); - Pos -= offset; - for (i = Pos; i < length - offset + 1; i++) - Buf[i] = Buf[i + offset]; + offset = EditAt - mbcs_skip(Buffer, mbcs_glyphs(Buffer, EditAt) - 1); + EditAt -= offset; + for (i = EditAt; i < length - offset + 1; i++) + Buffer[i] = Buffer[i + offset]; #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Mark <= -(1 + Pos)) - Mark += offset; /* Shift it */ + disableEditMark(); + if (EditMark <= -(1 + EditAt)) + EditMark += offset; /* Shift it */ #endif #endif /* SUPPORT_MULTIBYTE_EDIT */ break; case LYE_FORW_RL: - case LYE_FORW: - /* - * Move cursor to the right. - */ + case LYE_FORW: /* move cursor forward */ #ifndef SUPPORT_MULTIBYTE_EDIT - if (Pos < length) - Pos++; + if (EditAt < length) + EditAt++; #else - if (Pos < length) - Pos += mbcs_skip(Buf + Pos, 1); + if (EditAt < length) + EditAt += mbcs_skip(Buffer + EditAt, 1); #endif else if (action == LYE_FORW_RL) return -ch; break; case LYE_BACK_LL: - case LYE_BACK: - /* - * Left-arrow move cursor to the left. - */ + case LYE_BACK: /* move cursor backward */ #ifndef SUPPORT_MULTIBYTE_EDIT - if (Pos > 0) - Pos--; + if (EditAt > 0) + EditAt--; #else - if (Pos > 0) - Pos = mbcs_skip(Buf, mbcs_glyphs(Buf, Pos) - 1); + if (EditAt > 0) + EditAt = mbcs_skip(Buffer, mbcs_glyphs(Buffer, EditAt) - 1); #endif else if (action == LYE_BACK_LL) return -ch; @@ -3470,91 +3474,74 @@ int LYEdit1(EDREC * edit, int ch, break; /* Can't help it now */ #endif - if (length <= 1 || Pos == 0) + if (length <= 1 || EditAt == 0) return (ch); - if (Pos == length) - Pos--; - if (Mark < 0) - Mark = -(1 + Mark); /* Temporary enable it */ - if (Mark == Pos || Mark == Pos + 1) - Mark = Pos - 1; - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ - if (Buf[Pos - 1] == Buf[Pos]) { - Pos++; + if (EditAt == length) + EditAt--; + enableEditMark(); + if (EditMark == EditAt || EditMark == EditAt + 1) + EditMark = EditAt - 1; + disableEditMark(); + if (Buffer[EditAt - 1] == Buffer[EditAt]) { + EditAt++; break; } - i = Buf[Pos - 1]; - Buf[Pos - 1] = Buf[Pos]; - Buf[Pos++] = (char) i; + i = Buffer[EditAt - 1]; + Buffer[EditAt - 1] = Buffer[EditAt]; + Buffer[EditAt++] = (char) i; break; - case LYE_SETMARK: - /* - * primitive emacs-like set-mark-command - */ - Mark = Pos; + case LYE_SETMARK: /* Emacs-like set-mark-command */ + EditMark = EditAt; return (0); - case LYE_XPMARK: - /* - * emacs-like exchange-point-and-mark - */ - if (Mark < 0) - Mark = -(1 + Mark); /* Enable it */ - if (Mark == Pos) + case LYE_XPMARK: /* Emacs-like exchange-point-and-mark */ + enableEditMark(); + if (EditMark == EditAt) return (0); - i = Pos; - Pos = Mark; - Mark = i; + i = EditAt; + EditAt = EditMark; + EditMark = i; break; - case LYE_KILLREG: - /* - * primitive emacs-like kill-region - */ - if (Mark < 0) - Mark = -(1 + Mark); /* Enable it */ - if (Mark == Pos) { + case LYE_KILLREG: /* Emacs-like kill-region */ + enableEditMark(); + if (EditMark == EditAt) { BStrFree(killbuffer); return (0); } - if (Mark > Pos) - LYEdit1(edit, 0, LYE_XPMARK, FALSE); + if (EditMark > EditAt) + LYDoEdit(edit, 0, LYE_XPMARK, FALSE); { - int reglen = Pos - Mark; + int reglen = EditAt - EditMark; - BStrCopy1(killbuffer, Buf + Mark, reglen); - for (i = Mark; Buf[i + reglen]; i++) - Buf[i] = Buf[i + reglen]; - Buf[i] = Buf[i + reglen]; /* terminate */ - Pos = Mark; + BStrCopy1(killbuffer, Buffer + EditMark, reglen); + for (i = EditMark; Buffer[i + reglen]; i++) + Buffer[i] = Buffer[i + reglen]; + Buffer[i] = Buffer[i + reglen]; /* terminate */ + EditAt = EditMark; } - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ + disableEditMark(); break; - case LYE_YANK: - /* - * primitive emacs-like yank - */ + case LYE_YANK: /* Emacs-like yank */ if (!killbuffer) { - Mark = -(1 + Pos); + EditMark = -(1 + EditAt); return (0); } else { int yanklen = killbuffer->len; - if ((Pos + yanklen) <= (int) MaxLen && - StrLen + (size_t) yanklen <= MaxLen) { + if ((EditAt + yanklen) <= (int) BufAlloc && + BufInUse + (size_t) yanklen <= BufAlloc) { - ExtendEditor(edit, Pos + yanklen); + ExtendEditor(edit, EditAt + yanklen); - Mark = -(1 + Pos); + EditMark = -(1 + EditAt); - for (i = length; i >= Pos; i--) /* Make room */ - Buf[i + yanklen] = Buf[i]; + for (i = length; i >= EditAt; i--) /* Make room */ + Buffer[i + yanklen] = Buffer[i]; for (i = 0; i < yanklen; i++) - Buf[Pos++] = killbuffer->str[i]; + Buffer[EditAt++] = killbuffer->str[i]; } else if (maxMessage) { _statusline(MAXLEN_REACHED_DEL_OR_MOV); @@ -3565,18 +3552,18 @@ int LYEdit1(EDREC * edit, int ch, #endif /* ENHANCED_LINEEDIT */ case LYE_UPPER: - LYUpperCase(Buf); + LYUpperCase(Buffer); break; case LYE_LOWER: - LYLowerCase(Buf); + LYLowerCase(Buffer); break; default: return (ch); } IsDirty = TRUE; - StrLen = strlen(&Buf[0]); + BufInUse = strlen(&Buffer[0]); return (0); } @@ -3603,7 +3590,7 @@ int get_popup_number(const char *msg, /* * Get the number, possibly with a suffix, from the user. */ - if (LYgetBString(&temp, VISIBLE, 0, NORECALL) < 0 || isBEmpty(temp)) { + if (LYgetBString(&temp, FALSE, 0, NORECALL) < 0 || isBEmpty(temp)) { HTInfoMsg(CANCELLED); *c = '\0'; *rel = '\0'; @@ -3655,7 +3642,7 @@ int get_popup_number(const char *msg, # define TmpStyleOff(s) #endif /* defined USE_COLOR_STYLE */ -static void remember_column(EDREC * edit, int offset) +static void remember_column(FieldEditor * edit, int offset) { int y0, x0; @@ -3688,24 +3675,24 @@ static void fill_edited_line(int prompting GCC_UNUSED, int length, int ch) /* * Multibyte string display subroutine. - * EDREC fields retain their values as byte offsets. + * FieldEditor fields retain their values as byte offsets. * All external logic still works fine with byte values. */ -void LYRefreshEdit(EDREC * edit) +void LYRefreshEdit(FieldEditor * edit) { /* bytes and characters are not the same thing */ #if defined(DEBUG_EDIT) int all_bytes; #endif - int pos_bytes = Pos; + int pos_bytes = EditAt; int dpy_bytes; int lft_bytes; /* base of string which is displayed */ /* cells refer to display-columns on the screen */ - int all_cells; /* total of display-cells in Buf */ + int all_cells; /* total of display-cells in Buffer */ int dpy_cells; /* number of cells which are displayed */ int lft_cells; /* number of cells before display (on left) */ - int pos_cells; /* number of display-cells up to Pos */ + int pos_cells; /* number of display-cells up to EditAt */ #if defined(SUPPORT_MULTIBYTE_EDIT) int dpy_chars; @@ -3734,63 +3721,62 @@ void LYRefreshEdit(EDREC * edit) /* * If we've made no changes, or if there is nothing to display, just leave. */ - if (!IsDirty || (DspWdth == 0)) + if (!IsDirty || (DpyWidth == 0)) return; - CTRACE((tfp, "LYRefreshEdit:%s\n", Buf)); + CTRACE((tfp, "LYRefreshEdit:%s\n", Buffer)); IsDirty = FALSE; - StrLen = strlen(&Buf[0]); + BufInUse = strlen(&Buffer[0]); - all_cells = LYstrCells(Buf); - pos_cells = LYstrExtent2(Buf, Pos); + all_cells = LYstrCells(Buffer); + pos_cells = LYstrExtent2(Buffer, EditAt); #if defined(SUPPORT_MULTIBYTE_EDIT) && defined(DEBUG_EDIT) - all_bytes = (int) StrLen; - lft_chars = mbcs_glyphs(Buf, DspStart); - pos_chars = mbcs_glyphs(Buf, Pos); - all_chars = mbcs_glyphs(Buf, all_bytes); + all_bytes = (int) BufInUse; + lft_chars = mbcs_glyphs(Buffer, DpyStart); + pos_chars = mbcs_glyphs(Buffer, EditAt); + all_chars = mbcs_glyphs(Buffer, all_bytes); #endif /* * Now we have: - * .--DspWdth---. + * .--DpyWidth--. * +---------+=============+-----------+ - * | |M M| | (M=margin) + * | |M M| | (M=PanMargin) * +---------+=============+-----------+ - * 0 DspStart StrLen + * 0 DpyStart BufInUse * - * Insertion point can be anywhere between 0 and stringlength. Figure out - * new display starting point. + * Insertion point can be anywhere between 0 and stringlength. Calculate + * a new display starting point. * - * The first "if" below makes Lynx scroll several columns at a time when - * extending the string. Looks awful, but that way we can keep up with - * data entry at low baudrates. + * First, make Lynx scroll several columns at a time as needed when + * extending the string. Doing this helps with lowspeed connections. */ - lft_bytes = DspStart; - lft_cells = LYstrExtent2(Buf, DspStart); + lft_bytes = DpyStart; + lft_cells = LYstrExtent2(Buffer, DpyStart); - if ((lft_cells + DspWdth) <= all_cells) { - if (pos_cells >= (lft_cells + DspWdth) - Margin) { - lft_cells = (pos_cells - DspWdth) + Margin; + if ((lft_cells + DpyWidth) <= all_cells) { + if (pos_cells >= (lft_cells + DpyWidth) - PanMargin) { + lft_cells = (pos_cells - DpyWidth) + PanMargin; #ifdef SUPPORT_MULTIBYTE_EDIT - lft_chars = cell2char(Buf, lft_cells); - lft_bytes = mbcs_skip(Buf, lft_chars); + lft_chars = cell2char(Buffer, lft_cells); + lft_bytes = mbcs_skip(Buffer, lft_chars); #else lft_bytes = lft_cells; #endif /* SUPPORT_MULTIBYTE_EDIT */ } } - if (pos_cells < lft_cells + Margin) { - lft_cells = pos_cells - Margin; + if (pos_cells < lft_cells + PanMargin) { + lft_cells = pos_cells - PanMargin; if (lft_cells < 0) lft_cells = 0; #ifdef SUPPORT_MULTIBYTE_EDIT - lft_chars = cell2char(Buf, lft_cells); - lft_bytes = mbcs_skip(Buf, lft_chars); + lft_chars = cell2char(Buffer, lft_cells); + lft_bytes = mbcs_skip(Buffer, lft_chars); #else lft_bytes = lft_cells; #endif /* SUPPORT_MULTIBYTE_EDIT */ @@ -3803,7 +3789,7 @@ void LYRefreshEdit(EDREC * edit) * overwriting part of a multicolumn character which may lie in the first * position. */ - if (PanOn && lft_cells) { + if (IsPanned && lft_cells) { CTRACE_EDIT((tfp, "Draw left scroll-indicator\n")); TmpStyleOn(prompting ? s_prompt_edit_arr : s_aedit_arr); LYmove(StartY, StartX); @@ -3812,15 +3798,15 @@ void LYRefreshEdit(EDREC * edit) lft_shift = 1; } - str = &Buf[lft_bytes]; - DspStart = lft_bytes; + str = &Buffer[lft_bytes]; + DpyStart = lft_bytes; dpy_cells = all_cells - lft_cells; CTRACE_EDIT((tfp, "Comparing dpy_cells %d > (%d - %d)\n", - dpy_cells, DspWdth, lft_shift)); - if (dpy_cells > (DspWdth - lft_shift)) { + dpy_cells, DpyWidth, lft_shift)); + if (dpy_cells > (DpyWidth - lft_shift)) { rgt_shift = 1; - dpy_cells = (DspWdth - lft_shift - rgt_shift); + dpy_cells = (DpyWidth - lft_shift - rgt_shift); } for (;;) { #ifdef SUPPORT_MULTIBYTE_EDIT @@ -3899,17 +3885,17 @@ void LYRefreshEdit(EDREC * edit) Offs2Col[i] = cell + StartX; } else { #if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE) - if (Mark >= 0 && DspStart > Mark) + if (EditMark >= 0 && DpyStart > EditMark) TmpStyleOn(prompting ? s_prompt_sel : s_aedit_sel); #endif remember_column(edit, 0); for (i = 0; i < dpy_bytes; i++) { #if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE) - if (Mark >= 0 && ((DspStart + i == Mark && Pos > Mark) - || (DspStart + i == Pos && Pos < Mark))) + if (EditMark >= 0 && ((DpyStart + i == EditMark && EditAt > EditMark) + || (DpyStart + i == EditAt && EditAt < EditMark))) TmpStyleOn(prompting ? s_prompt_sel : s_aedit_sel); - if (Mark >= 0 && ((DspStart + i == Mark && Pos < Mark) - || (DspStart + i == Pos && Pos > Mark))) + if (EditMark >= 0 && ((DpyStart + i == EditMark && EditAt < EditMark) + || (DpyStart + i == EditAt && EditAt > EditMark))) TmpStyleOff(prompting ? s_prompt_sel : s_aedit_sel); #endif if (str[i] == 1 || str[i] == 2 || @@ -3935,10 +3921,10 @@ void LYRefreshEdit(EDREC * edit) remember_column(edit, i + 1); } #if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE) - if (Mark >= 0 && - ((DspStart + dpy_bytes <= Mark && DspStart + dpy_bytes > Pos) - || (DspStart + dpy_bytes > Mark - && DspStart + dpy_bytes <= Pos))) { + if (EditMark >= 0 && + ((DpyStart + dpy_bytes <= EditMark && DpyStart + dpy_bytes > EditAt) + || (DpyStart + dpy_bytes > EditMark + && DpyStart + dpy_bytes <= EditAt))) { TmpStyleOff(prompting ? s_prompt_sel : s_aedit_sel); } #endif @@ -3947,13 +3933,13 @@ void LYRefreshEdit(EDREC * edit) /* * Erase rest of input area. */ - padsize = DspWdth - (Offs2Col[dpy_bytes] - StartX); + padsize = DpyWidth - (Offs2Col[dpy_bytes] - StartX); fill_edited_line(prompting, padsize, PadChar); /* * Scrolling indicators. */ - if (PanOn && dpy_bytes && rgt_shift) { + if (IsPanned && dpy_bytes && rgt_shift) { CTRACE((tfp, "Draw right-scroller offset (%d + %d)\n", dpy_cells, lft_shift)); TmpStyleOn(prompting ? s_prompt_edit_arr : s_aedit_arr); @@ -3965,7 +3951,7 @@ void LYRefreshEdit(EDREC * edit) /* * Finally, move the cursor to the point where the next edit will occur. */ - LYmove(StartY, Offs2Col[Pos - DspStart]); + LYmove(StartY, Offs2Col[EditAt - DpyStart]); #ifdef USE_COLOR_STYLE if (estyle != NOSTYLE) @@ -3974,10 +3960,10 @@ void LYRefreshEdit(EDREC * edit) LYrefresh(); } -static void reinsertEdit(EditFieldData *edit, char *result) +static void reinsertEdit(FieldEditor * edit, char *result) { if (result != 0) { - LYEdit1(edit, '\0', LYE_ERASE, FALSE); + LYDoEdit(edit, '\0', LYE_ERASE, FALSE); while (*result != '\0') { LYLineEdit(edit, (int) (*result), FALSE); result++; @@ -4059,7 +4045,7 @@ int LYarrayWidth(STRING2PTR list) return result; } -static void FormatChoiceNum(char *dst, +static void FormatChoiceNum(char *target, int num_choices, int choice, const char *value) @@ -4067,11 +4053,11 @@ static void FormatChoiceNum(char *dst, if (num_choices >= 0) { int digits = (num_choices > 9) ? 2 : 1; - sprintf(dst, "%*d: %.*s", + sprintf(target, "%*d: %.*s", digits, (choice + 1), MAX_LINE - 9 - digits, value); } else { - LYStrNCpy(dst, value, MAX_LINE - 1); + LYStrNCpy(target, value, MAX_LINE - 1); } } @@ -4829,7 +4815,7 @@ int LYhandlePopupList(int cur_choice, case LYK_WHEREIS: if (isBEmpty(prev_target)) { _statusline(ENTER_WHEREIS_QUERY); - if ((ch = LYgetBString(&prev_target, VISIBLE, 0, recall)) < 0) { + if ((ch = LYgetBString(&prev_target, FALSE, 0, recall)) < 0) { /* * User cancelled the search via ^G. - FM */ @@ -4840,7 +4826,7 @@ int LYhandlePopupList(int cur_choice, check_recall: if (isBEmpty(prev_target) && - !(recall && (ch == UPARROW || ch == DNARROW))) { + !(recall && (ch == UPARROW_KEY || ch == DNARROW_KEY))) { /* * No entry. Simply break. - FM */ @@ -4848,7 +4834,7 @@ int LYhandlePopupList(int cur_choice, goto restore_popup_statusline; } - if (recall && ch == UPARROW) { + if (recall && ch == UPARROW_KEY) { if (FirstRecall) { /* * Use the current string or last query in the list. - FM @@ -4892,7 +4878,7 @@ int LYhandlePopupList(int cur_choice, _statusline(EDIT_A_PREV_QUERY); } if ((ch = LYgetBString(&prev_target, - VISIBLE, 0, recall)) < 0) { + FALSE, 0, recall)) < 0) { /* * User cancelled the search via ^G. - FM */ @@ -4901,7 +4887,7 @@ int LYhandlePopupList(int cur_choice, } goto check_recall; } - } else if (recall && ch == DNARROW) { + } else if (recall && ch == DNARROW_KEY) { if (FirstRecall) { /* * Use the current string or first query in the list. - FM @@ -4945,7 +4931,7 @@ int LYhandlePopupList(int cur_choice, _statusline(EDIT_A_PREV_QUERY); } if ((ch = LYgetBString(&prev_target, - VISIBLE, 0, recall)) < 0) { + FALSE, 0, recall)) < 0) { /* * User cancelled the search via ^G. - FM */ @@ -5079,11 +5065,13 @@ int LYgetBString(bstring **inputline, int xlec = -2; int last_xlec = -1; int last_xlkc = -1; - EditFieldData MyEdit, *edit = &MyEdit; + FieldEditor MyEdit, *edit = &MyEdit; #ifdef SUPPORT_MULTIBYTE_EDIT BOOL refresh_mb = TRUE; #endif /* SUPPORT_MULTIBYTE_EDIT */ + BOOL done = FALSE; + int result = -1; CTRACE((tfp, "called LYgetBString hidden %d, recall %d\n", hidden, (int) recall)); @@ -5101,8 +5089,8 @@ int LYgetBString(bstring **inputline, fep_on(); #endif - for (;;) { - again: + while (!done) { + beginning: #ifndef SUPPORT_MULTIBYTE_EDIT LYRefreshEdit(edit); #else /* SUPPORT_MULTIBYTE_EDIT */ @@ -5114,12 +5102,12 @@ int LYgetBString(bstring **inputline, #ifdef CJK_EX /* for SJIS code */ if (!refresh_mb && (EditBinding(ch) != LYE_CHAR)) - goto again; + goto beginning; #else if (!refresh_mb && (EditBinding(ch) != LYE_CHAR) && (EditBinding(ch) != LYE_AIX)) - goto again; + goto beginning; #endif #endif /* SUPPORT_MULTIBYTE_EDIT */ @@ -5137,18 +5125,20 @@ int LYgetBString(bstring **inputline, ch = LYCharINTERRUPT2; } - if (recall != NORECALL && (ch == UPARROW || ch == DNARROW)) { - BStrCopy0(*inputline, Buf); - LYAddToCloset(recall, Buf); + if (recall != NORECALL && (ch == UPARROW_KEY || ch == DNARROW_KEY)) { + BStrCopy0(*inputline, Buffer); + LYAddToCloset(recall, Buffer); CTRACE((tfp, "LYgetstr(%s) recall\n", (*inputline)->str)); #ifdef FEPCTRL fep_off(); #endif LYFinishEdit(edit); - return (ch); + result = ch; + done = TRUE; + break; } - ch |= CurModif; - CurModif = 0; + ch |= InputMods; + InputMods = 0; if (last_xlkc != -1) { if (ch == last_xlkc) ch |= LKC_MOD3; @@ -5156,7 +5146,7 @@ int LYgetBString(bstring **inputline, } #ifndef WIN_EX if (LKC_TO_LAC(keymap, ch) == LYK_REFRESH) - goto again; + goto beginning; #endif last_xlec = xlec; xlec = EditBinding(ch); @@ -5168,16 +5158,10 @@ int LYgetBString(bstring **inputline, } switch (xlec) { case LYE_SETM1: - /* - * Set flag for modifier 1. - */ - CurModif |= LKC_MOD1; + InputMods |= LKC_MOD1; break; case LYE_SETM2: - /* - * Set flag for modifier 2. - */ - CurModif |= LKC_MOD2; + InputMods |= LKC_MOD2; break; case LYE_TAB: if (xlec == last_xlec && recall != NORECALL) { @@ -5190,7 +5174,7 @@ int LYgetBString(bstring **inputline, int num_options = LYarrayLength((STRING2PTR) data); while (cur_choice < num_options - && strcasecomp(data[cur_choice], Buf) < 0) + && strcasecomp(data[cur_choice], Buffer) < 0) cur_choice++; LYGetYX(old_y, old_x); @@ -5211,17 +5195,15 @@ int LYgetBString(bstring **inputline, FREE(data); } } else { - reinsertEdit(edit, LYFindInCloset(recall, Buf)); + reinsertEdit(edit, LYFindInCloset(recall, Buffer)); } break; -#ifndef CJK_EX /* 1997/11/03 (Mon) 20:13:45 */ +#ifndef CJK_EX case LYE_AIX: /* - * Hex 97. - * Treat as a character for CJK, or if this is a valid character in - * the current display character set. Otherwise, we treat this as - * LYE_ENTER. + * Handle CJK characters, or as a valid character in the current + * display character set. Otherwise, we treat this as LYE_ENTER. */ if (ch != '\t' && (IS_CJK_TTY || @@ -5232,33 +5214,30 @@ int LYgetBString(bstring **inputline, /* FALLTHRU */ #endif case LYE_ENTER: - /* - * Terminate the string and return. - */ - BStrCopy0(*inputline, Buf); + BStrCopy0(*inputline, Buffer); if (!hidden) - LYAddToCloset(recall, Buf); + LYAddToCloset(recall, Buffer); CTRACE((tfp, "LYgetstr(%s) LYE_ENTER\n", (*inputline)->str)); #ifdef FEPCTRL fep_off(); #endif LYFinishEdit(edit); - return (ch); + result = ch; + done = TRUE; + break; #ifdef CAN_CUT_AND_PASTE - /* 1998/10/01 (Thu) 15:05:49 */ - case LYE_PASTE: { unsigned char *s = (unsigned char *) get_clip_grab(), *e; - int len; + size_t len; if (!s) break; - len = (int) strlen((const char *) s); + len = strlen((const char *) s); e = s + len; - if (len > 0) { + if (len != 0) { unsigned char *e1 = s; while (e1 < e) { @@ -5274,13 +5253,16 @@ int LYgetBString(bstring **inputline, map_active, TRUE); s = ++e1; - } else + } else { break; - } else + } + } else { ++e1; + } } - if (e1 > s) + if (e1 > s) { LYEditInsert(edit, s, (int) (e1 - s), map_active, TRUE); + } } get_clip_release(); break; @@ -5288,31 +5270,26 @@ int LYgetBString(bstring **inputline, #endif case LYE_ABORT: - /* - * Control-C or Control-G aborts. - */ CTRACE((tfp, "LYgetstr LYE_ABORT\n")); #ifdef FEPCTRL fep_off(); #endif LYFinishEdit(edit); BStrCopy0(*inputline, ""); - return (-1); + done = TRUE; + break; case LYE_STOP: - /* - * Deactivate. - */ CTRACE((tfp, "LYgetstr LYE_STOP\n")); #ifdef TEXTFIELDS_MAY_NEED_ACTIVATION textfields_need_activation = TRUE; LYFinishEdit(edit); BStrCopy0(*inputline, ""); - return (-1); + done = TRUE; + break; #else #ifdef ENHANCED_LINEEDIT - if (Mark >= 0) - Mark = -(1 + Mark); /* Disable it */ + disableEditMark(); #endif break; #endif @@ -5350,12 +5327,13 @@ int LYgetBString(bstring **inputline, refresh_mb = TRUE; } else { if (!refresh_mb) { - LYEdit1(edit, 0, LYE_DELP, FALSE); + LYDoEdit(edit, 0, LYE_DELP, FALSE); } } #endif /* SUPPORT_MULTIBYTE_EDIT */ } } + return result; } /* @@ -5387,23 +5365,27 @@ const char *LYLineeditHelpURL(void) static int lasthelp_lineedit = -1; static char helpbuf[LY_MAXPATH] = "\0"; static char *phelp = &helpbuf[0]; + const char *result = NULL; - if (lasthelp_lineedit == current_lineedit) - return &helpbuf[0]; - if (lasthelp_lineedit == -1) { - LYStrNCpy(helpbuf, helpfilepath, sizeof(helpbuf) - 1); - phelp += strlen(helpbuf); - } - if (LYLineeditHelpURLs[current_lineedit] && - strlen(LYLineeditHelpURLs[current_lineedit]) && - (strlen(LYLineeditHelpURLs[current_lineedit]) <= - sizeof(helpbuf) - (unsigned) (phelp - helpbuf))) { - LYStrNCpy(phelp, LYLineeditHelpURLs[current_lineedit], - (int) (sizeof(helpbuf) - (unsigned) (phelp - helpbuf) - 1)); - lasthelp_lineedit = current_lineedit; - return (&helpbuf[0]); + if (lasthelp_lineedit == current_lineedit) { + result = helpbuf; + } else { + const char *source = LYLineeditHelpURLs[current_lineedit]; + size_t available; + + if (lasthelp_lineedit == -1) { + LYStrNCpy(helpbuf, helpfilepath, sizeof(helpbuf) - 1); + phelp += strlen(helpbuf); + } + available = (sizeof(helpbuf) - (size_t) (phelp - helpbuf)); + if (non_empty(source) && + (strlen(source) <= available)) { + LYStrNCpy(phelp, source, available); + lasthelp_lineedit = current_lineedit; + result = helpbuf; + } } - return NULL; + return result; } /* @@ -5485,151 +5467,156 @@ int LYscanFloat(const char *source, float *result) char *LYstrsep(char **stringp, const char *delim) { - char *tmp, *out; - - if (isEmpty(stringp)) /* nothing to do? */ - return 0; /* then don't fall on our faces */ + char *marker; + char *result = 0; - out = *stringp; /* save the start of the string */ - tmp = strpbrk(*stringp, delim); - if (tmp) { - *tmp = '\0'; /* terminate the substring with \0 */ - *stringp = ++tmp; /* point at the next substring */ - } else - *stringp = 0; /* this was the last substring: */ - /* let caller see he's done */ - return out; + if (non_empty(stringp)) { + result = *stringp; /* will return the old value */ + marker = strpbrk(*stringp, delim); + if (marker) { + *marker = '\0'; /* terminate the substring */ + *stringp = ++marker; /* point to the next substring */ + } else { + *stringp = 0; /* this was the last */ + } + } + return result; } /* - * LYstrstr will find the first occurrence of the string pointed to by tarptr - * in the string pointed to by chptr. It returns NULL if string not found. It - * is a case insensitive search. + * LYstrstr finds the first occurrence of the string pointed to by needle + * in the string pointed to by haystack. + * + * It returns NULL if the string is not found. + * + * It is a case insensitive search. */ -char *LYstrstr(char *chptr, - const char *tarptr) +char *LYstrstr(char *haystack, + const char *needle) { - int len = (int) strlen(tarptr); + int len = (int) strlen(needle); + char *result = NULL; - for (; *chptr != '\0'; chptr++) { - if (0 == UPPER8(*chptr, *tarptr)) { - if (0 == strncasecomp8(chptr + 1, tarptr + 1, len - 1)) - return (chptr); + for (; *haystack != '\0'; haystack++) { + if (0 == UPPER8(*haystack, *needle)) { + if (0 == strncasecomp8(haystack + 1, needle + 1, len - 1)) { + result = haystack; + break; + } } - } /* end for */ + } - return (NULL); /* string not found or initial chptr was empty */ + return (result); } +#define SkipSpecialChars(p) \ + while (IsSpecialAttrChar(*p) && *p != '\0') \ + p++ + /* - * LYno_attr_char_case_strstr will find the first occurrence of the - * string pointed to by tarptr in the string pointed to by chptr. - * It ignores the characters: LY_UNDERLINE_START_CHAR and - * LY_UNDERLINE_END_CHAR - * LY_BOLD_START_CHAR - * LY_BOLD_END_CHAR - * LY_SOFT_HYPHEN - * if present in chptr. + * LYno_attr_char_case_strstr finds the first occurrence of the + * string pointed to by needle in the string pointed to by haystack. + * + * It ignores special characters, e.g., LY_UNDERLINE_START_CHAR in haystack. + * * It is a case insensitive search. */ -const char *LYno_attr_char_case_strstr(const char *chptr, - const char *tarptr) +const char *LYno_attr_char_case_strstr(const char *haystack, + const char *needle) { - register const char *tmpchptr, *tmptarptr; + const char *refptr, *tstptr; + const char *result = NULL; - if (!chptr) - return (NULL); + if (haystack != NULL && needle != NULL) { - while (IsSpecialAttrChar(*chptr) && *chptr != '\0') - chptr++; + SkipSpecialChars(haystack); - for (; *chptr != '\0'; chptr++) { - if (0 == UPPER8(*chptr, *tarptr)) { - /* - * See if they line up. - */ - tmpchptr = chptr + 1; - tmptarptr = tarptr + 1; + for (; *haystack != '\0' && (result == NULL); haystack++) { + if (0 == UPPER8(*haystack, *needle)) { + refptr = haystack + 1; + tstptr = needle + 1; - if (*tmptarptr == '\0') /* one char target */ - return (chptr); + if (*tstptr == '\0') { + result = haystack; + break; + } - while (1) { - if (!IsSpecialAttrChar(*tmpchptr)) { - if (0 != UPPER8(*tmpchptr, *tmptarptr)) + while (1) { + if (!IsSpecialAttrChar(*refptr)) { + if (0 != UPPER8(*refptr, *tstptr)) + break; + refptr++; + tstptr++; + } else { + refptr++; + } + if (*tstptr == '\0') { + result = haystack; + break; + } + if (*refptr == '\0') break; - tmpchptr++; - tmptarptr++; - } else { - tmpchptr++; } - if (*tmptarptr == '\0') - return (chptr); - if (*tmpchptr == '\0') - break; } } - } /* end for */ + } - return (NULL); + return (result); } /* - * LYno_attr_char_strstr will find the first occurrence of the - * string pointed to by tarptr in the string pointed to by chptr. - * It ignores the characters: LY_UNDERLINE_START_CHAR and - * LY_UNDERLINE_END_CHAR - * LY_BOLD_START_CHAR - * LY_BOLD_END_CHAR - * LY_SOFT_HYPHEN - * if present in chptr. + * LYno_attr_char_strstr finds the first occurrence of the + * string pointed to by needle in the string pointed to by haystack. + * It ignores special characters, e.g., LY_UNDERLINE_START_CHAR in haystack. + * * It is a case sensitive search. */ -const char *LYno_attr_char_strstr(const char *chptr, - const char *tarptr) +const char *LYno_attr_char_strstr(const char *haystack, + const char *needle) { - register const char *tmpchptr, *tmptarptr; + const char *refptr, *tstptr; + const char *result = NULL; - if (!chptr) - return (NULL); + if (haystack != NULL && needle != NULL) { - while (IsSpecialAttrChar(*chptr) && *chptr != '\0') - chptr++; + SkipSpecialChars(haystack); - for (; *chptr != '\0'; chptr++) { - if ((*chptr) == (*tarptr)) { - /* - * See if they line up. - */ - tmpchptr = chptr + 1; - tmptarptr = tarptr + 1; + for (; *haystack != '\0' && (result == NULL); haystack++) { + if ((*haystack) == (*needle)) { + refptr = haystack + 1; + tstptr = needle + 1; - if (*tmptarptr == '\0') /* one char target */ - return (chptr); + if (*tstptr == '\0') { + result = haystack; + break; + } - while (1) { - if (!IsSpecialAttrChar(*tmpchptr)) { - if ((*tmpchptr) != (*tmptarptr)) + while (1) { + if (!IsSpecialAttrChar(*refptr)) { + if ((*refptr) != (*tstptr)) + break; + refptr++; + tstptr++; + } else { + refptr++; + } + if (*tstptr == '\0') { + result = haystack; break; - tmpchptr++; - tmptarptr++; - } else { - tmpchptr++; + } else if (*refptr == '\0') { + break; + } } - if (*tmptarptr == '\0') - return (chptr); - if (*tmpchptr == '\0') - break; } } - } /* end for */ + } - return (NULL); + return (result); } /* - * LYno_attr_mbcs_case_strstr will find the first occurrence of the string - * pointed to by tarptr in the string pointed to by chptr. It takes account of + * LYno_attr_mbcs_case_strstr finds the first occurrence of the string pointed + * to by needle in the string pointed to by haystack. It takes account of * MultiByte Character Sequences (UTF8). The physical lengths of the displayed * string up to the start and end (= next position after) of the target string * are returned in *nstartp and *nendp if the search is successful. @@ -5639,158 +5626,133 @@ const char *LYno_attr_char_strstr(const char *chptr, * count actual glyphs if count_gcells is unset. (Full-width characters in CJK * mode count as one.) * - * It ignores the characters: LY_UNDERLINE_START_CHAR and - * LY_UNDERLINE_END_CHAR - * LY_BOLD_START_CHAR - * LY_BOLD_END_CHAR - * LY_SOFT_HYPHEN - * if present in chptr. + * It ignores special characters, e.g., LY_UNDERLINE_START_CHAR in haystack. + * * It assumes UTF8 if utf_flag is set. - * It is a case insensitive search. - KW & FM + * + * It is a case insensitive search. */ -const char *LYno_attr_mbcs_case_strstr(const char *chptr, - const char *tarptr, +const char *LYno_attr_mbcs_case_strstr(const char *haystack, + const char *needle, int utf_flag, int count_gcells, int *nstartp, int *nendp) { - const char *tmpchptr; - const char *tmptarptr; + const char *refptr; + const char *tstptr; int len = 0; int offset; + const char *result = NULL; - if (!(chptr && tarptr)) - return (NULL); + if (haystack != NULL && needle != NULL) { - /* - * Skip initial IsSpecial chars. - FM - */ - while (IsSpecialAttrChar(*chptr) && *chptr != '\0') - chptr++; + SkipSpecialChars(haystack); - /* - * Seek a first target match. - FM - */ - for (; *chptr != '\0'; chptr++) { - if ((!utf_flag && IS_CJK_TTY && is8bits(*chptr) && - *chptr == *tarptr && - IsNormalChar(*(chptr + 1))) || - (0 == UPPER8(*chptr, *tarptr))) { - int tarlen = 0; + for (; *haystack != '\0' && (result == NULL); haystack++) { + if ((!utf_flag && IS_CJK_TTY && is8bits(*haystack) && + *haystack == *needle && + IsNormalChar(*(haystack + 1))) || + (0 == UPPER8(*haystack, *needle))) { + int tarlen = 0; - offset = len; - len++; + offset = len; + len++; - /* - * See if they line up. - */ - tmpchptr = (chptr + 1); - tmptarptr = (tarptr + 1); + refptr = (haystack + 1); + tstptr = (needle + 1); - if (*tmptarptr == '\0') { - /* - * One char target. - */ - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len; - return (chptr); - } - if (!utf_flag && IS_CJK_TTY && is8bits(*chptr) && - *chptr == *tarptr && - IsNormalChar(*tmpchptr)) { - /* - * Check the CJK multibyte. - FM - */ - if (*tmpchptr == *tmptarptr) { - /* - * It's a match. Advance to next char. - FM - */ - tmpchptr++; - tmptarptr++; - if (count_gcells) - tarlen++; - if (*tmptarptr == '\0') { - /* - * One character match. - FM - */ - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len + tarlen; - return (chptr); - } - } else { - /* - * It's not a match, so go back to seeking a first target - * match. - FM - */ - chptr++; - if (count_gcells) - len++; - continue; + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len; + result = haystack; + break; } - } - /* - * See if the rest of the target matches. - FM - */ - while (1) { - if (!IsSpecialAttrChar(*tmpchptr)) { - if (!utf_flag && IS_CJK_TTY && is8bits(*tmpchptr)) { - if (*tmpchptr == *tmptarptr && - *(tmpchptr + 1) == *(tmptarptr + 1) && - !IsSpecialAttrChar(*(tmpchptr + 1))) { - tmpchptr++; - tmptarptr++; - if (count_gcells) - tarlen++; - } else { + if (!utf_flag && IS_CJK_TTY && is8bits(*haystack) && + *haystack == *needle && + IsNormalChar(*refptr)) { + /* handle a CJK multibyte string */ + if (*refptr == *tstptr) { + refptr++; + tstptr++; + if (count_gcells) + tarlen++; + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len + tarlen; + result = haystack; break; } - } else if (0 != UPPER8(*tmpchptr, *tmptarptr)) { - break; + } else { + /* not a match */ + haystack++; + if (count_gcells) + len++; + continue; } + } + /* compare the remainder of the string */ + while (1) { + if (!IsSpecialAttrChar(*refptr)) { + if (!utf_flag && IS_CJK_TTY && is8bits(*refptr)) { + if (*refptr == *tstptr && + *(refptr + 1) == *(tstptr + 1) && + !IsSpecialAttrChar(*(refptr + 1))) { + refptr++; + tstptr++; + if (count_gcells) + tarlen++; + } else { + break; + } + } else if (0 != UPPER8(*refptr, *tstptr)) { + break; + } - if (!IS_UTF_EXTRA(*tmptarptr)) { - tarlen++; + if (!IS_UTF_EXTRA(*tstptr)) { + tarlen++; + } + refptr++; + tstptr++; + + } else { + refptr++; } - tmpchptr++; - tmptarptr++; - } else { - tmpchptr++; + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len + tarlen; + result = haystack; + break; + } + if (*refptr == '\0') + break; } - - if (*tmptarptr == '\0') { - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len + tarlen; - return (chptr); + } else if (!(IS_UTF_EXTRA(*haystack) || + IsSpecialAttrChar(*haystack))) { + if (!utf_flag && IS_CJK_TTY && is8bits(*haystack) && + IsNormalChar(*(haystack + 1))) { + haystack++; + if (count_gcells) + len++; } - if (*tmpchptr == '\0') - break; + len++; } - } else if (!(IS_UTF_EXTRA(*chptr) || - IsSpecialAttrChar(*chptr))) { - if (!utf_flag && IS_CJK_TTY && is8bits(*chptr) && - IsNormalChar(*(chptr + 1))) { - chptr++; - if (count_gcells) - len++; - } - len++; } - } /* end for */ + } - return (NULL); + return (result); } /* - * LYno_attr_mbcs_strstr will find the first occurrence of the string pointed - * to by tarptr in the string pointed to by chptr. + * LYno_attr_mbcs_strstr finds the first occurrence of the string pointed + * to by needle in the string pointed to by haystack. * * It takes account of CJK and MultiByte Character Sequences (UTF8). The * physical lengths of the displayed string up to the start and end (= next @@ -5802,199 +5764,177 @@ const char *LYno_attr_mbcs_case_strstr(const char *chptr, * count actual glyphs if count_gcells is unset. (Full-width characters in CJK * mode count as one.) * - * It ignores the characters: LY_UNDERLINE_START_CHAR and - * LY_UNDERLINE_END_CHAR - * LY_BOLD_START_CHAR - * LY_BOLD_END_CHAR - * LY_SOFT_HYPHEN - * if present in chptr. + * It ignores special characters, e.g., LY_UNDERLINE_START_CHAR in haystack. + * * It assumes UTF8 if utf_flag is set. - * It is a case sensitive search. - KW & FM + * + * It is a case sensitive search. */ -const char *LYno_attr_mbcs_strstr(const char *chptr, - const char *tarptr, +const char *LYno_attr_mbcs_strstr(const char *haystack, + const char *needle, int utf_flag, int count_gcells, int *nstartp, int *nendp) { - const char *tmpchptr; - const char *tmptarptr; + const char *refptr; + const char *tstptr; int len = 0; int offset; + const char *result = NULL; - if (!(chptr && tarptr)) - return (NULL); + if (haystack != NULL && needle != NULL) { - /* - * Skip initial IsSpecial chars. - FM - */ - while (IsSpecialAttrChar(*chptr) && *chptr != '\0') - chptr++; + SkipSpecialChars(haystack); - /* - * Seek a first target match. - FM - */ - for (; *chptr != '\0'; chptr++) { - if ((*chptr) == (*tarptr)) { - int tarlen = 0; + for (; *haystack != '\0' && (result == NULL); haystack++) { + if ((*haystack) == (*needle)) { + int tarlen = 0; - offset = len; - len++; + offset = len; + len++; - /* - * See if they line up. - */ - tmpchptr = (chptr + 1); - tmptarptr = (tarptr + 1); + refptr = (haystack + 1); + tstptr = (needle + 1); - if (*tmptarptr == '\0') { - /* - * One char target. - */ - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len; - return (chptr); - } - if (!utf_flag && IS_CJK_TTY && is8bits(*chptr) && - IsNormalChar(*tmpchptr)) { - /* - * Check the CJK multibyte. - FM - */ - if (*tmpchptr == *tmptarptr) { - /* - * It's a match. Advance to next char. - FM - */ - tmpchptr++; - tmptarptr++; - if (count_gcells) - tarlen++; - if (*tmptarptr == '\0') { - /* - * One character match. - FM - */ - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len + tarlen; - return (chptr); + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len; + result = haystack; + break; + } else if (!utf_flag && + IS_CJK_TTY && + is8bits(*haystack) && + IsNormalChar(*refptr)) { + /* handle a CJK multibyte string */ + if (*refptr == *tstptr) { + /* found match */ + refptr++; + tstptr++; + if (count_gcells) + tarlen++; + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len + tarlen; + result = haystack; + break; + } + } else { + /* not a match - restart comparison */ + haystack++; + if (count_gcells) + len++; + continue; } - } else { - /* - * It's not a match, so go back to seeking a first target - * match. - FM - */ - chptr++; - if (count_gcells) - len++; - continue; } - } - /* - * See if the rest of the target matches. - FM - */ - while (1) { - if (!IsSpecialAttrChar(*tmpchptr)) { - if (!utf_flag && IS_CJK_TTY && is8bits(*tmpchptr)) { - if (*tmpchptr == *tmptarptr && - *(tmpchptr + 1) == *(tmptarptr + 1) && - !IsSpecialAttrChar(*(tmpchptr + 1))) { - tmpchptr++; - tmptarptr++; - if (count_gcells) - tarlen++; - } else { + /* compare the remainder of the string */ + while (1) { + if (!IsSpecialAttrChar(*refptr)) { + if (!utf_flag && IS_CJK_TTY && is8bits(*refptr)) { + if (*refptr == *tstptr && + *(refptr + 1) == *(tstptr + 1) && + !IsSpecialAttrChar(*(refptr + 1))) { + refptr++; + tstptr++; + if (count_gcells) + tarlen++; + } else { + break; + } + } else if ((*refptr) != (*tstptr)) { break; } - } else if ((*tmpchptr) != (*tmptarptr)) { - break; + + if (!IS_UTF_EXTRA(*tstptr)) { + tarlen++; + } + refptr++; + tstptr++; + } else { + refptr++; } - if (!IS_UTF_EXTRA(*tmptarptr)) { - tarlen++; + if (*tstptr == '\0') { + if (nstartp) + *nstartp = offset; + if (nendp) + *nendp = len + tarlen; + result = haystack; + break; } - tmpchptr++; - tmptarptr++; - } else { - tmpchptr++; + if (*refptr == '\0') + break; } - - if (*tmptarptr == '\0') { - if (nstartp) - *nstartp = offset; - if (nendp) - *nendp = len + tarlen; - return (chptr); + } else if (!(IS_UTF_EXTRA(*haystack) || + IsSpecialAttrChar(*haystack))) { + if (!utf_flag && IS_CJK_TTY && is8bits(*haystack) && + IsNormalChar(*(haystack + 1))) { + haystack++; + if (count_gcells) + len++; } - if (*tmpchptr == '\0') - break; + len++; } - } else if (!(IS_UTF_EXTRA(*chptr) || - IsSpecialAttrChar(*chptr))) { - if (!utf_flag && IS_CJK_TTY && is8bits(*chptr) && - IsNormalChar(*(chptr + 1))) { - chptr++; - if (count_gcells) - len++; - } - len++; } - } /* end for */ - - return (NULL); + } + return (result); } /* - * Allocate a new copy of a string, and returns it. + * Allocate and return a copy of a string. + * see StrAllocCopy */ -char *SNACopy(char **dest, - const char *src, - int n) +char *SNACopy(char **target, + const char *source, + size_t n) { - FREE(*dest); - if (src) { - *dest = typeMallocn(char, (unsigned) n + 1); + FREE(*target); + if (source) { + *target = typeMallocn(char, n + 1); - if (*dest == NULL) { - CTRACE((tfp, "Tried to malloc %d bytes\n", n)); + if (*target == NULL) { + CTRACE((tfp, "Tried to malloc %lu bytes\n", (unsigned long) n)); outofmem(__FILE__, "SNACopy"); - assert(*dest != NULL); + assert(*target != NULL); } - LYStrNCpy(*dest, src, n); + LYStrNCpy(*target, source, n); } - return *dest; + return *target; } /* - * String Allocate and Concatenate. + * Combinate string allocation and concatenation. + * see StrAllocCat */ -char *SNACat(char **dest, - const char *src, - int n) +char *SNACat(char **target, + const char *source, + size_t n) { - if (non_empty(src)) { - if (*dest) { - int length = (int) strlen(*dest); + if (non_empty(source)) { + if (*target) { + size_t length = strlen(*target); - *dest = typeRealloc(char, *dest, length + n + 1); + *target = typeRealloc(char, *target, length + n + 1); - if (*dest == NULL) + if (*target == NULL) outofmem(__FILE__, "SNACat"); - assert(*dest != NULL); - LYStrNCpy(*dest + length, src, n); + assert(*target != NULL); + LYStrNCpy(*target + length, source, n); } else { - *dest = typeMallocn(char, (unsigned) n + 1); + *target = typeMallocn(char, n + 1); - if (*dest == NULL) + if (*target == NULL) outofmem(__FILE__, "SNACat"); - assert(*dest != NULL); - MemCpy(*dest, src, n); - (*dest)[n] = '\0'; /* terminate */ + assert(*target != NULL); + MemCpy(*target, source, n); + (*target)[n] = '\0'; /* terminate */ } } - return *dest; + return *target; } #include <caselower.h> @@ -6007,33 +5947,32 @@ static long UniToLowerCase(long upper) { size_t i, high, low; long diff = 0; + long result = upper; - /* - * Make check for sure. - */ - if (upper <= 0) - return (upper); - - /* - * Try unicode_to_lower_case[]. - */ - low = 0; - high = TABLESIZE(unicode_to_lower_case); - while (low < high) { + if (upper > 0) { /* - * Binary search. + * Try unicode_to_lower_case[]. */ - i = (low + (high - low) / 2); - diff = (unicode_to_lower_case[i].upper - upper); - if (diff < 0) - low = i + 1; - if (diff > 0) - high = i; - if (diff == 0) - return (unicode_to_lower_case[i].lower); + low = 0; + high = TABLESIZE(unicode_to_lower_case); + while (low < high) { + /* + * Binary search. + */ + i = (low + (high - low) / 2); + diff = (unicode_to_lower_case[i].upper - upper); + if (diff < 0) { + low = i + 1; + } else if (diff > 0) { + high = i; + } else if (diff == 0) { + result = unicode_to_lower_case[i].lower; + break; + } + } } - return (upper); /* if we came here */ + return result; } /* @@ -6051,35 +5990,38 @@ static long UniToLowerCase(long upper) */ int UPPER8(int ch1, int ch2) { - /* if they are the same or one is a null characters return immediately. */ - if (ch1 == ch2) - return 0; - if (!ch2) - return UCH(ch1); - else if (!ch1) - return -UCH(ch2); - - /* case-insensitive match for us-ascii */ - if (UCH(TOASCII(ch1)) < 128 && UCH(TOASCII(ch2)) < 128) - return (TOUPPER(ch1) - TOUPPER(ch2)); - - /* case-insensitive match for upper half */ - if (UCH(TOASCII(ch1)) > 127 && /* S/390 -- gil -- 2066 */ - UCH(TOASCII(ch2)) > 127) { - if (DisplayCharsetMatchLocale) - return (TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */ - else { + int result = 0; + + if (ch1 == ch2) { + result = 0; + } else if (!ch2) { + result = UCH(ch1); + } else if (!ch1) { + result = -UCH(ch2); + } else if (UCH(TOASCII(ch1)) < 128 && UCH(TOASCII(ch2)) < 128) { + /* case-insensitive match for us-ascii */ + result = (TOUPPER(ch1) - TOUPPER(ch2)); + } else if (UCH(TOASCII(ch1)) > 127 && + UCH(TOASCII(ch2)) > 127) { + /* case-insensitive match for upper half */ + if (DisplayCharsetMatchLocale) { + result = (TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */ + } else { long uni_ch2 = UCTransToUni((char) ch2, current_char_set); long uni_ch1; - if (uni_ch2 < 0) - return UCH(ch1); - uni_ch1 = UCTransToUni((char) ch1, current_char_set); - return (int) (UniToLowerCase(uni_ch1) - UniToLowerCase(uni_ch2)); + if (uni_ch2 < 0) { + result = UCH(ch1); + } else { + uni_ch1 = UCTransToUni((char) ch1, current_char_set); + result = (int) (UniToLowerCase(uni_ch1) - UniToLowerCase(uni_ch2)); + } } + } else { + result = -10; /* mismatch */ } - return (-10); /* mismatch, if we come to here */ + return result; } /* @@ -6087,14 +6029,14 @@ int UPPER8(int ch1, int ch2) * that is allocated. When an EOF or error is found, the buffer is freed * automatically. */ -char *LYSafeGets(char **src, +char *LYSafeGets(char **target, FILE *fp) { char buffer[BUFSIZ]; char *result = 0; - if (src != 0) - result = *src; + if (target != 0) + result = *target; if (result != 0) *result = 0; @@ -6113,8 +6055,8 @@ char *LYSafeGets(char **src, */ FREE(result); } - if (src != 0) - *src = result; + if (target != 0) + *target = result; return result; } |