From 4563c5f579efe066b7b2d1e6a0fc87f47ab6f051 Mon Sep 17 00:00:00 2001 From: mogami Date: Sat, 1 Nov 2003 23:33:31 +0000 Subject: [PATCH] =?utf8?q?show=5Ffile()=E3=81=A7=E3=80=81=E8=89=B2?= =?utf8?q?=E4=BB=98=E3=81=91=E3=82=BF=E3=82=B0"[[[[[=E3=80=9C]"=20?= =?utf8?q?=E3=81=A8=E5=BC=B7=E8=AA=BF=E8=A1=A8=E7=A4=BA(=E6=A4=9C=E7=B4=A2?= =?utf8?q?=E6=99=82=E3=81=A8'=3D'=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89)=20?= =?utf8?q?=E3=81=A8=E3=81=8C=E3=82=B3=E3=83=B3=E3=83=95=E3=83=AA=E3=82=AF?= =?utf8?q?=E3=83=88=E3=81=97=E3=81=A6=E3=80=81=E8=A1=A8=E7=A4=BA=E3=81=8C?= =?utf8?q?=E3=81=8A=E3=81=8B=E3=81=97=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=A6?= =?utf8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3=E3=80=82?= =?utf8?q?=20=E3=81=9D=E3=81=AE=E9=81=8E=E7=A8=8B=E3=81=A7=E3=80=81?= =?utf8?q?=E5=85=A8=E8=A1=8C=E3=81=AB=E8=89=B2=E3=82=92=E4=BB=98=E3=81=91?= =?utf8?q?=E3=82=8B=E3=82=BF=E3=82=B0"#####"=E3=81=AF=E5=BB=83=E6=AD=A2?= =?utf8?q?=E3=80=82=E9=83=A8=E5=88=86=E6=96=87=E5=AD=97=E5=88=97=E3=81=AB?= =?utf8?q?=E8=89=B2=E3=82=92=E4=BB=98=E3=81=91=E3=82=8B"[[[[[=E3=80=9C]"?= =?utf8?q?=E3=81=A7=E5=8D=81=E5=88=86=E3=80=82=20=E3=81=BE=E3=81=9F?= =?utf8?q?=E3=80=81=E5=BC=B7=E8=AA=BF=E8=A1=A8=E7=A4=BA=E3=82=B3=E3=83=9E?= =?utf8?q?=E3=83=B3=E3=83=89'=3D'=E3=81=A7=E5=A4=A7=E6=96=87=E5=AD=97?= =?utf8?q?=E3=81=AE=E6=96=87=E5=AD=97=E5=88=97=E3=82=92=E5=85=A5=E5=8A=9B?= =?utf8?q?=E3=81=99=E3=82=8B=E3=81=A8=E3=80=81=E6=A4=9C=E5=87=BA=E3=81=AB?= =?utf8?q?=E5=A4=B1=E6=95=97=E3=81=99=E3=82=8B=E3=83=90=E3=82=B0=E4=BF=AE?= =?utf8?q?=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/autopick.c | 20 ----- src/externs.h | 1 + src/files.c | 230 +++++++++++++++++++++++++++------------------------------ src/util.c | 20 +++++ 4 files changed, 129 insertions(+), 142 deletions(-) diff --git a/src/autopick.c b/src/autopick.c index 936347fe9..8293296ed 100644 --- a/src/autopick.c +++ b/src/autopick.c @@ -557,26 +557,6 @@ static bool is_rare(object_type *o_ptr) /* - * Convert string to lower case - */ -static void str_tolower(char *str) -{ - /* Force to be lower case string */ - for (; *str; str++) - { -#ifdef JP - if (iskanji(*str)) - { - str++; - continue; - } -#endif - *str = tolower(*str); - } -} - - -/* * Get auto-picker entry from o_ptr. */ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr) diff --git a/src/externs.h b/src/externs.h index 7bbdc1c95..7981850d2 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1285,6 +1285,7 @@ extern size_t my_strcpy(char *buf, const char *src, size_t bufsize); extern size_t my_strcat(char *buf, const char *src, size_t bufsize); extern char *my_strstr(const char *haystack, const char *needle); extern char *my_strchr(const char *ptr, char ch); +extern void str_tolower(char *str); extern int inkey_special(void); diff --git a/src/files.c b/src/files.c index 622b9daaf..d57dc43ff 100644 --- a/src/files.c +++ b/src/files.c @@ -5051,72 +5051,108 @@ msg_print(" /* * Display single line of on-line help file */ -static void show_file_aux_line(cptr str, int cy, byte color) +static void show_file_aux_line(cptr str, int cy, cptr shower) { + byte color = TERM_WHITE; + bool in_tag = FALSE; int cx = 0; + int i; + char lcstr[1024]; + + if (shower) + { + /* Make a lower case version of str for searching */ + strcpy(lcstr, str); + str_tolower(lcstr); + } /* Initial cursor position */ Term_gotoxy(cx, cy); - - while (*str) + for (i = 0; str[i];) { - cptr leftb = my_strchr(str, '['); - int len; + int len = strlen(&str[i]); + int showercol = len + 1; + int bracketcol = len + 1; + int endcol = len; + cptr ptr; - /* Get length of white text */ - if (NULL == leftb) - { - len = strlen(str); - } - else + /* Search for a shower string in the line */ + if (shower) { - len = (int)(leftb - str); + ptr = my_strstr(&lcstr[i], shower); + if (ptr) showercol = ptr - &lcstr[i]; } - /* Print a white (actually default colored) text */ - Term_addstr(len, color, str); - cx += len; - str += len; + /* Search for a color segment tag */ + ptr = in_tag ? my_strchr(&str[i], ']') : my_strstr(&str[i], "[[[[["); + if (ptr) bracketcol = ptr - &str[i]; - /* Colored segment? */ - if (prefix(str, "[[[[[")) + /* A color tag is found */ + if (bracketcol < endcol) endcol = bracketcol; + + /* The shower string is found before the color tag */ + if (showercol < endcol) endcol = showercol; + + /* Print a segment of the line */ + Term_addstr(endcol, color, &str[i]); + cx += endcol; + i += endcol; + + /* Shower string? */ + if (endcol == showercol) { - cptr rightb; - byte attr; + int showerlen = strlen(shower); - str += 5; + /* Print the shower string in yellow */ + Term_addstr(showerlen, TERM_YELLOW, &str[i]); + cx += showerlen; + i += showerlen; + } - /* Illigal end of line */ - if (!isalpha((int)((unsigned char)*str))) break; + /* Colored segment? */ + else if (endcol == bracketcol) + { + if (in_tag) + { + /* Found a ']', the end of colored segment */ + i++; - /* Get color attr */ - attr = color_char_to_attr(*str); + /* Now looking for an another "[[[[[" */ + in_tag = FALSE; - str++; + /* Set back to the default color */ + color = TERM_WHITE; + } + else + { + /* Found a "[[[[[", and get a tag color */ + i += 5; - rightb = my_strchr(str, ']'); + /* Get tag color */ + color = color_char_to_attr(str[i]); - /* No close-bracket? */ - if (NULL == rightb) break; + if (color == 255) + { + /* Illegal color tag */ + color = TERM_WHITE; - len = (int)(rightb - str); + /* Print the broken tag as a string */ + Term_addstr(-1, TERM_WHITE, "[[[[["); + cx += 5; + } + else + { + /* Skip the color tag */ + i++; - /* Ok print a colored text */ - Term_addstr(len, attr, str); - cx += len; - str = rightb + 1; + /* Now looking for a ']' */ + in_tag = TRUE; + } + } } - /* This '[' was not a part of color tag */ - else if (*str == '[') - { - /* Print the '[' */ - Term_addstr(1, color, str); - cx++; - str++; - } - } + } /* for (i = 0; str[i];) */ /* Clear rest of line */ Term_erase(cx, cy, 255); @@ -5144,12 +5180,6 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode) /* Backup value for "line" */ int back = 0; - /* Color of the next line */ - byte color = TERM_WHITE; - - /* Loop counter */ - int cnt; - /* This screen has sub-screens */ bool menu = FALSE; @@ -5162,11 +5192,12 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode) /* Jump to this tag */ cptr tag = NULL; - /* Hold a string to find */ - char finder[81]; + /* Hold strings to find/show */ + char finder_str[81]; + char shower_str[81]; - /* Hold a string to show */ - char shower[81]; + /* String to show */ + cptr shower = NULL; /* Filename */ char filename[1024]; @@ -5180,12 +5211,6 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode) /* General buffer */ char buf[1024]; - /* Lower case version of the buffer, for searching */ - char lc_buf[1024]; - - /* Aux pointer for making lc_buf (and find!) lowercase */ - cptr lc_buf_ptr; - /* Sub-menu information */ char hook[68][32]; @@ -5197,10 +5222,10 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode) rows = hgt - 4; /* Wipe finder */ - strcpy(finder, ""); + strcpy(finder_str, ""); /* Wipe shower */ - strcpy(shower, ""); + strcpy(shower_str, ""); /* Wipe caption */ strcpy(caption, ""); @@ -5425,63 +5450,26 @@ msg_format("'%s' /* Hack -- skip "special" lines */ if (prefix(buf, "***** ")) continue; - /* Get a color */ - if (prefix(str, "#####")) - { - if (str[5] && isalpha(str[5])) - { - str += 5; - color = color_char_to_attr(*str); - str++; - } - } - else - { - color = TERM_WHITE; - } - /* Count the "real" lines */ next++; - /* Make a lower case version of str for searching */ - strcpy(lc_buf, str); - - for (lc_buf_ptr = lc_buf; *lc_buf_ptr != 0; lc_buf_ptr++) + /* Hack -- keep searching */ + if (find && !i) { -#ifdef JP - if (iskanji(*lc_buf_ptr)) - lc_buf_ptr++; - else -#endif - lc_buf[lc_buf_ptr-lc_buf] = tolower(*lc_buf_ptr); - } + char lc_buf[1024]; - /* Hack -- keep searching */ - if (find && !i && !my_strstr(lc_buf, find)) continue; + /* Make a lower case version of str for searching */ + strcpy(lc_buf, str); + str_tolower(lc_buf); + + if (!my_strstr(lc_buf, find)) continue; + } /* Hack -- stop searching */ find = NULL; /* Dump the line */ - show_file_aux_line(str, i + 2, color); - - /* Hilite "shower" */ - if (shower[0]) - { - cptr s2 = lc_buf; - - /* Display matches */ - while ((s2 = my_strstr(s2, shower)) != NULL) - { - int len = strlen(shower); - - /* Display the match */ - Term_putstr(s2-lc_buf, i+2, len, TERM_YELLOW, &str[s2-lc_buf]); - - /* Advance */ - s2 += len; - } - } + show_file_aux_line(str, i + 2, shower); /* Count the printed lines */ i++; @@ -5575,12 +5563,18 @@ prt("[ { /* Get "shower" */ #ifdef JP -prt("¶¯Ä´: ", hgt - 1, 0); + prt("¶¯Ä´: ", hgt - 1, 0); #else prt("Show: ", hgt - 1, 0); #endif - (void)askfor_aux(shower, 80); + (void)askfor_aux(shower_str, 80); + + /* Make it lowercase */ + str_tolower(shower_str); + + /* Show it */ + shower = shower_str; } /* Hack -- try finding */ @@ -5594,26 +5588,18 @@ prt(" #endif - if (askfor_aux(finder, 80)) + if (askfor_aux(finder_str, 80)) { /* Find it */ - find = finder; + find = finder_str; back = line; line = line + 1; /* Make finder lowercase */ - for (cnt = 0; finder[cnt] != 0; cnt++) - { -#ifdef JP - if (iskanji(finder[cnt])) - cnt++; - else -#endif - finder[cnt] = tolower(finder[cnt]); - } + str_tolower(finder_str); /* Show it */ - strcpy(shower, finder); + shower = finder_str; } } diff --git a/src/util.c b/src/util.c index 0743aa72d..2cb8f71c3 100644 --- a/src/util.c +++ b/src/util.c @@ -5290,6 +5290,26 @@ char *my_strchr(const char *ptr, char ch) /* + * Convert string to lower case + */ +void str_tolower(char *str) +{ + /* Force to be lower case string */ + for (; *str; str++) + { +#ifdef JP + if (iskanji(*str)) + { + str++; + continue; + } +#endif + *str = tolower(*str); + } +} + + +/* * Get a keypress from the user. * And interpret special keys as internal code. * -- 2.11.0