📄 lystrings.c
字号:
* Control-C or Control-G aborts. */ inputline[0] = '\0'; return(-1); break; case LYE_LKCMD: /* * Used only in form_getstr() for invoking * the LYK_F_LINK_NUM prompt when in form * text fields. - FM */ break; default: LYLineEdit(&MyEdit, ch, FALSE); } }}/* * 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. */PUBLIC char * LYstrstr ARGS2( char *, chptr, char *, tarptr){ int len = strlen(tarptr); for(; *chptr != '\0'; chptr++) { if (0 == UPPER8(*chptr, *tarptr)) { if (0 == strncasecomp8(chptr+1, tarptr+1, len-1)) return(chptr); } } /* end for */ return(NULL); /* string not found or initial chptr was empty */}/* * 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. * It is a case insensitive search. */PUBLIC char * LYno_attr_char_case_strstr ARGS2( char *, chptr, char *, tarptr){ register char *tmpchptr, *tmptarptr; if (!chptr) return(NULL); while (IsSpecialAttrChar(*chptr) && *chptr != '\0') chptr++; for (; *chptr != '\0'; chptr++) { if (0 == UPPER8(*chptr, *tarptr)) { /* * See if they line up. */ tmpchptr = chptr+1; tmptarptr = tarptr+1; if (*tmptarptr == '\0') /* one char target */ return(chptr); while (1) { if (!IsSpecialAttrChar(*tmpchptr)) { if (0 != UPPER8(*tmpchptr, *tmptarptr)) break; tmpchptr++; tmptarptr++; } else { tmpchptr++; } if (*tmptarptr == '\0') return(chptr); if (*tmpchptr == '\0') break; } } } /* end for */ return(NULL);}/* * 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. * It is a case sensitive search. */PUBLIC char * LYno_attr_char_strstr ARGS2( char *, chptr, char *, tarptr){ register char *tmpchptr, *tmptarptr; if (!chptr) return(NULL); while (IsSpecialAttrChar(*chptr) && *chptr != '\0') chptr++; for (; *chptr != '\0'; chptr++) { if ((*chptr) == (*tarptr)) { /* * See if they line up. */ tmpchptr = chptr + 1; tmptarptr = tarptr + 1; if (*tmptarptr == '\0') /* one char target */ return(chptr); while (1) { if (!IsSpecialAttrChar(*tmpchptr)) { if ((*tmpchptr) != (*tmptarptr)) break; tmpchptr++; tmptarptr++; } else { tmpchptr++; } if (*tmptarptr == '\0') return(chptr); if (*tmpchptr == '\0') break; } } } /* end for */ return(NULL);}/* * 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 MultiByte Character Sequences (UTF8). * The physical length of the displayed string up to the end of the target * string is returned in *nendp if the search is successful. * 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 assumes UTF8 if utf_flag is set. * It is a case insensitive search. - KW & FM */PUBLIC char * LYno_attr_mbcs_case_strstr ARGS5( char *, chptr, char *, tarptr, BOOL, utf_flag, int *, nstartp, int *, nendp){ register char *tmpchptr, *tmptarptr; int len = 0; int offset; if (!(chptr && tarptr)) return(NULL); /* * Skip initial IsSpecial chars. - FM */ while (IsSpecialAttrChar(*chptr) && *chptr != '\0') chptr++; /* * Seek a first target match. - FM */ for (; *chptr != '\0'; chptr++) { if ((!utf_flag && HTCJK != NOCJK && !isascii(*chptr) && *chptr == *tarptr && *(chptr + 1) != '\0' && !IsSpecialAttrChar(*(chptr + 1))) || (0 == UPPER8(*chptr, *tarptr))) { int tarlen = 0; offset = len; len++; /* * See if they line up. */ tmpchptr = (chptr + 1); tmptarptr = (tarptr + 1); if (*tmptarptr == '\0') { /* * One char target. */ *nstartp = offset; *nendp = len; return(chptr); } if (!utf_flag && HTCJK != NOCJK && !isascii(*chptr) && *chptr == *tarptr && *tmpchptr != '\0' && !IsSpecialAttrChar(*tmpchptr)) { /* * Check the CJK multibyte. - FM */ if (*tmpchptr == *tmptarptr) { /* * It's a match. Advance to next char. - FM */ tmpchptr++; tmptarptr++; if (*tmptarptr == '\0') { /* * One character match. - FM */ *nstartp = offset; *nendp = len + tarlen; return(chptr); } tarlen++; } else { /* * It's not a match, so go back to * seeking a first target match. - FM */ chptr++; continue; } } /* * See if the rest of the target matches. - FM */ while (1) { if (!IsSpecialAttrChar(*tmpchptr)) { if (!utf_flag && HTCJK != NOCJK && !isascii(*tmpchptr)) { if (*tmpchptr == *tmptarptr && *(tmpchptr + 1) == *(tmptarptr + 1) && !IsSpecialAttrChar(*(tmpchptr + 1))) { tmpchptr++; tmptarptr++; } else { break; } } else if (0 != UPPER8(*tmpchptr, *tmptarptr)) { break; } if (!IS_UTF_EXTRA(*tmptarptr)) { tarlen++; } tmpchptr++; tmptarptr++; } else { tmpchptr++; } if (*tmptarptr == '\0') { *nstartp = offset; *nendp = len + tarlen; return(chptr); } if (*tmpchptr == '\0') { break; } } } else if (!(IS_UTF_EXTRA(*chptr) || IsSpecialAttrChar(*chptr))) { if (!utf_flag && HTCJK != NOCJK && !isascii(*chptr) && *(chptr + 1) != '\0' && !IsSpecialAttrChar(*(chptr + 1))) { chptr++; } len++; } } /* end for */ return(NULL);}/* * LYno_attr_mbcs_strstr will find the first occurrence of the string * pointed to by tarptr in the string pointed to by chptr. * It takes account of CJK and MultiByte Character Sequences (UTF8). * The physical lengths of the displayed string up to the start and * end of the target string are returned in *nstartp and *nendp if * the search is successful. * 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 assumes UTF8 if utf_flag is set. * It is a case sensitive search. - KW & FM */PUBLIC char * LYno_attr_mbcs_strstr ARGS5( char *, chptr, char *, tarptr, BOOL, utf_flag, int *, nstartp, int *, nendp){ register char *tmpchptr, *tmptarptr; int len = 0; int offset; if (!(chptr && tarptr)) return(NULL); /* * Skip initial IsSpecial chars. - FM */ while (IsSpecialAttrChar(*chptr) && *chptr != '\0') chptr++; /* * Seek a first target match. - FM */ for (; *chptr != '\0'; chptr++) { if ((*chptr) == (*tarptr)) { int tarlen = 0; offset = len; len++; /* * See if they line up. */ tmpchptr = (chptr + 1); tmptarptr = (tarptr + 1); if (*tmptarptr == '\0') { /* * One char target. */ *nstartp = offset; *nendp = len + 1; return(chptr); } if (!utf_flag && HTCJK != NOCJK && !isascii(*chptr) && *tmpchptr != '\0' && !IsSpecialAttrChar(*tmpchptr)) { /* * Check the CJK multibyte. - FM */ if (*tmpchptr == *tmptarptr) { /* * It's a match. Advance to next char. - FM */ tmpchptr++; tmptarptr++; if (*tmptarptr == '\0') { /* * One character match. - FM */ *nstartp = offset; *nendp = len + tarlen; return(chptr); } tarlen++; } else { /* * It's not a match, so go back to * seeking a first target match. - FM */ chptr++; continue; } } /* * See if the rest of the target matches. - FM */ while (1) { if (!IsSpecialAttrChar(*tmpchptr)) { if (!utf_flag && HTCJK != NOCJK && !isascii(*tmpchptr)) { if (*tmpchptr == *tmptarptr && *(tmpchptr + 1) == *(tmptarptr + 1) && !IsSpecialAttrChar(*(tmpchptr + 1))) { tmpchptr++; tmptarptr++; } else { break; } } else if ((*tmpchptr) != (*tmptarptr)) { break; } if (!IS_UTF_EXTRA(*tmptarptr)) { tarlen++; } tmpchptr++; tmptarptr++; } else { tmpchptr++; } if (*tmptarptr == '\0') { *nstartp = offset; *nendp = len + tarlen; return(chptr); } if (*tmpchptr == '\0') { break; } } } else if (!(IS_UTF_EXTRA(*chptr) || IsSpecialAttrChar(*chptr))) { if (!utf_flag && HTCJK != NOCJK && !isascii(*chptr) && *(chptr + 1) != '\0' && !IsSpecialAttrChar(*(chptr + 1))) { chptr++; } len++; } } /* end for */ return(NULL);}/* * Allocate a new copy of a string, and returns it. */PUBLIC char * SNACopy ARGS3( char **, dest, CONST char *, src, int, n){ FREE(*dest); if (src) { *dest = (char *)calloc(1, n + 1); if (*dest == NULL) { if (TRACE) fprintf(stderr, "Tried to calloc %d bytes\n", n); outofmem(__FILE__, "SNACopy"); } strncpy (*dest, src, n); *(*dest + n) = '\0'; /* terminate */ } return *dest;}/* * String Allocate and Concatenate. */PUBLIC char * SNACat ARGS3( char **, dest, CONST char *, src, int, n){ if (src && *src) { if (*dest) { int length = strlen(*dest); *dest = (char *)realloc(*dest, length + n + 1); if (*dest == NULL) outofmem(__FILE__, "SNACat"); strncpy(*dest + length, src, n); *(*dest + length + n) = '\0'; /* terminate */ } else { *dest = (char *)calloc(1, strlen(src) + 1); if (*dest == NULL) outofmem(__FILE__, "SNACat"); strncpy(*dest, src, n); *dest[n] = '\0'; /* terminate */ } } return *dest;}/*** UPPER8 ?** it was "TOUPPER(a) - TOUPPER(b)" in its previous life...**** It was realized that case-insensitive user search** got information about upper/lower mapping from TOUPPER** (precisely from "(TOUPPER(a) - TOUPPER(b))==0").** This function depends on locale in its 8bit mapping** and usually fails with DOS/WINDOWS display charsets** as well as on non-UNIX systems.**** We extend this function for 8bit letters** using Lynx internal chartrans feature:** we assume that upper/lower case letters** have their "7bit approximation" images (in def7_uni.tbl)** matched case-insensitive (7bit).**** By this technique we automatically cover *any* charset** known for Lynx chartrans and need no any extra information for it.**** The cost of this assumption is that several differently accented letters** may be interpreted as equal, but this side effect is negligible** if the user search string is more than one character long. - LP**** Currently we enable new technique only for DOS/WINDOWS display charsets** and also for EXP_8BIT_TOUPPER compilation symbol.*/PUBLIC int UPPER8 ARGS2(int,ch1, int,ch2){ /* case-insensitive match for us-ascii */ if ((unsigned char)ch1 < 128 && (unsigned char)ch2 < 128) return(TOUPPER(ch1) - TOUPPER(ch2)); /* case-insensitive match for upper half */ if ((unsigned char)ch1 > 127 && (unsigned char)ch2 >127) { CONST char *disp_charset; disp_charset = LYCharSet_UC[current_char_set].MIMEname;#if !defined(EXP_8BIT_TOUPPER) if (!(strncasecomp(disp_charset, "cp", 2) || strncasecomp(disp_charset, "windows", 7))) { return(TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */ } else #endif { /* compare "7bit approximation" for letters >127 */ /* BTW, if we remove the check for >127 above */ /* we get even more "relaxed" insensitive match... */ int charset_in, charset_out, uck1, uck2; char replace_buf1 [10], replace_buf2 [10]; charset_in = UCGetLYhndl_byMIME(disp_charset); charset_out = UCGetLYhndl_byMIME("us-ascii"); uck1 = UCTransCharStr(replace_buf1, sizeof(replace_buf1), ch1, charset_in, charset_out, YES); uck2 = UCTransCharStr(replace_buf2, sizeof(replace_buf2), ch2, charset_in, charset_out, YES); if ((uck1 > 0) && (uck2 > 0)) /* both replacement strings found */ return (strcasecomp(replace_buf1, replace_buf2)); /* check to be sure we have not lost any strange characters */ /* which are not found in def7_uni.tbl but _equal_ in fact. */ if ((unsigned char)ch1==(unsigned char)ch2) return(0); /* match */ } } return(-10); /* mismatch, if we come to here */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -