From: mogami Date: Sat, 1 Nov 2003 23:33:31 +0000 (+0000) Subject: show_file()で、色付けタグ"[[[[[〜]" と強調表示(検索時と'='コマンド) X-Git-Tag: v2.1.2~924 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4563c5f579efe066b7b2d1e6a0fc87f47ab6f051;p=hengbandforosx%2Fhengbandosx.git show_file()で、色付けタグ"[[[[[〜]" と強調表示(検索時と'='コマンド) とがコンフリクトして、表示がおかしくなっていたので修正。 その過程で、全行に色を付けるタグ"#####"は廃止。部分文字列に色を付ける"[[[[[〜]"で十分。 また、強調表示コマンド'='で大文字の文字列を入力すると、検出に失敗するバグ修正。 --- 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. *