OSDN Git Service

show_file()の中で画面をスクロールすると文字化けが起る事があるバグ修正。
authormogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Thu, 23 Oct 2003 18:57:43 +0000 (18:57 +0000)
committermogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Thu, 23 Oct 2003 18:57:43 +0000 (18:57 +0000)
Revision 1.139 で画面がチラチラしないように、全画面消去をしないで画面
のアップデートをするように変更したが、そのような場合に漢字を含む文字列
を表示する為に1byteずつz-term.cの関数を呼んではいけない。

つまり、Term_addstr()、Term_queue_chars()、prt()等は使って良いが、
Term_addch()、Term_draw()、Term_queue_char()等は使ってはいけない。

src/files.c

index 63a249d..e104259 100644 (file)
@@ -5044,6 +5044,81 @@ msg_print("
 
 
 /*
+ * Display single line of on-line help file
+ */
+static void show_file_aux_line(cptr str, int cy, byte color)
+{
+       int cx = 0;
+
+       /* Initial cursor position */
+       Term_gotoxy(cx, cy);
+
+
+       while (*str)
+       {
+               cptr leftb = my_strchr(str, '[');
+               int len;
+
+               /* Get length of white text */
+               if (NULL == leftb)
+               {
+                       len = strlen(str);
+               }
+               else
+               {
+                       len = (int)(leftb - str);
+               }
+
+               /* Print a white (actually default colored) text */
+               Term_addstr(len, color, str);
+               cx += len;
+               str += len;
+
+               /* Colored segment? */
+               if (prefix(str, "[[[[["))
+               {
+                       cptr rightb;
+                       byte attr;
+
+                       str += 5;
+
+                       /* Illigal end of line */
+                       if (!isalpha((int)((unsigned char)*str))) break;
+
+                       /* Get color attr */
+                       attr = color_char_to_attr(*str);
+
+                       str++;
+
+                       rightb = my_strchr(str, ']');
+
+                       /* No close-bracket? */
+                       if (NULL == rightb) break;
+
+                       len = (int)(rightb - str);
+
+                       /* Ok print a colored text */
+                       Term_addstr(len, attr, str);
+                       cx += len;
+                       str = rightb + 1;
+               }
+
+               /* This '[' was not a part of color tag */
+               else if (*str == '[')
+               {
+                       /* Print the '[' */
+                       Term_addstr(1, color, str);
+                       cx++;
+                       str++;
+               }
+       }
+
+       /* Clear rest of line */
+       Term_erase(cx, cy, 255);
+}
+
+
+/*
  * Recursive file perusal.
  *
  * Return FALSE on 'Q', otherwise TRUE.
@@ -5338,7 +5413,6 @@ msg_format("'%s'
                /* Dump the next 20, or rows, lines of the file */
                for (i = 0; i < rows; )
                {
-                       int print_x, x;
                        cptr str = buf;
 
                        /* Hack -- track the "first" line */
@@ -5388,42 +5462,7 @@ msg_format("'%s'
                        find = NULL;
 
                        /* Dump the line */
-                       x = 0;
-                       print_x = 0;
-                       while (str[x])
-                       {
-                               /* Color ? */
-                               if (prefix(str + x, "[[[[["))
-                               {
-                                       byte c;
-                                       x += 5;
-
-                                       /* Illigal end of line */
-                                       if (!str[x]) break;
-
-                                       /* Get color attr */
-                                       c = color_char_to_attr(str[x++]);
-
-                                       /* Ok print a colored text */
-                                       while (str[x] && str[x] != ']')
-                                       {
-                                               Term_putch(print_x, i + 2, c, str[x]);
-                                               x++;
-                                               print_x++;
-                                       }
-
-                                       if (str[x] == ']') x++;
-                               }
-                               else
-                               {
-                                       Term_putch(print_x, i + 2, color, str[x]);
-                                       x++;
-                                       print_x++;
-                               }
-                       }
-
-                       /* Clear rest of line */
-                       Term_erase(print_x, i + 2, 255);
+                       show_file_aux_line(str, i + 2, color);
 
                        /* Hilite "shower" */
                        if (shower[0])