OSDN Git Service

change xputc2 to take strings instead of two chars
[jnethack/source.git] / sys / winnt / nttty.c
index bd0ec04..3da2b6a 100644 (file)
@@ -82,7 +82,7 @@ cell_t undefined_cell = { CONSOLE_UNDEFINED_CHARACTER,
 static BOOL FDECL(CtrlHandler, (DWORD));
 static void FDECL(xputc_core, (char));
 #if 1 /*JP*/
-static void FDECL(xputc2_core, (unsigned int, unsigned int));
+static void FDECL(xputc2_core, (unsigned char *));
 #endif
 void FDECL(cmov, (int, int));
 void FDECL(nocmov, (int, int));
@@ -237,8 +237,9 @@ static void back_buffer_flip()
             if (back->iskanji == 1) {
                 cell_t * back2 = back + 1;
                 cell_t * front2 = front + 1;
+                /* pos.x == 0 \82Ì\8fð\8c\8f\82Í\95s\97v\82Ì\82Í\82¸\82¾\82ª #42072 \91Î\8dô\82Å\92Ç\89Á\81B */
                 if (back->attribute != front->attribute ||
-                    back2->attribute != front2->attribute) {
+                    back2->attribute != front2->attribute || pos.X == 0) {
                     WORD attrs[2];
                     attrs[0] = attrs[1] = back->attribute;
                     WriteConsoleOutputAttribute(console.hConOut, attrs,
@@ -246,15 +247,15 @@ static void back_buffer_flip()
                     front->attribute = back->attribute;
                     front2->attribute = back2->attribute;
                 }
+                /* pos.x == 0 \82Ì\8fð\8c\8f\82Í\95s\97v\82Ì\82Í\82¸\82¾\82ª #42072 \91Î\8dô\82Å\92Ç\89Á\81B */
                 if (back->character != front->character ||
-                    back2->character != front2->character) {
-                    unsigned char buf[2];
-                    buf[0] = (unsigned char)(back->character);
-                    buf[1] = (unsigned char)(back2->character);
-                    WriteConsoleOutputCharacter(console.hConOut, buf, 2, pos,
+                    back2->character != front2->character || pos.X == 0) {
+                    wchar_t wbuf[1];
+                    wbuf[0] = back->character;
+                    WriteConsoleOutputCharacterW(console.hConOut, wbuf, 1, pos,
                                                     &unused);
-                    front->character = back->character;
-                    front2->character = back2->character;
+                    *front = *back;
+                    *front2 = *back2;
                 }
                 pos.X++;
                 back += 2;
@@ -276,6 +277,13 @@ static void back_buffer_flip()
                     WriteConsoleOutputCharacterA(console.hConOut, &ch, 1, pos,
                                                     &unused);
                 }
+#if 1 /*JP*/
+                /* \8a¿\8e\9a\82Ì1\83o\83C\83g\96Ú\82¾\82Á\82½\8fê\8d\87\81A
+                   2\83o\83C\83g\96Ú\82ð\83N\83\8a\83A\82µ\82Ä\8am\8eÀ\82É\8dX\90V\82·\82é */
+                if (front->iskanji == 1) {
+                    (front + 1)->character = '\0';
+                }
+#endif
                 *front = *back;
             }
             back++;
@@ -609,15 +617,15 @@ int ch;
 
 #if 1 /*JP*/
 void
-xputc2_core(ch1, ch2)
-unsigned int ch1;
-unsigned int ch2;
+xputc2_core(str)
+unsigned char *str;
 {
     nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
     nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
 
     boolean inverse = FALSE;
     cell_t cell;
+    wchar_t wbuf[1];
 
     /* xputc_core()\82©\82ç\82Ì\83R\83s\81[ */
     inverse = (console.current_nhattr[ATR_INVERSE] && iflags.wc_inverse);
@@ -647,12 +655,22 @@ unsigned int ch2;
         }
     }
 
-    cell.character = ch1;
+    int ret = MultiByteToWideChar(
+        CP_ACP,
+        MB_PRECOMPOSED,
+        str,
+        strlen(str),
+        wbuf,
+        1);
+
+    /* \8d\91¤\82É\83\8f\83C\83h\95\8e\9a\8fî\95ñ\82ð\8bl\82ß\82é */
+    cell.character = wbuf[0];
     cell.iskanji = 1;
     buffer_write(console.back_buffer, &cell, console.cursor);
     console.cursor.X++;
 
-    cell.character = ch2;
+    /* \89E\91¤\82Í\83_\83~\81[ */
+    cell.character = 255;
     cell.iskanji = 2;
     buffer_write(console.back_buffer, &cell, console.cursor);
 
@@ -670,17 +688,16 @@ unsigned int ch2;
 }
 
 void
-xputc2(ch1, ch2)
-int ch1;
-int ch2;
+xputc2(str)
+unsigned char *str;
 {
     /* wintty.c \82Å\82Í 1 \83o\83C\83g\96\88\82É curx \82ð\89Á\8eZ\82·\82é\82ª\81A\82±\82±\82Í
-       \83o\83C\83g\82½\82Ü\82Á\82Ä\82©\82ç\8cÄ\82Ñ\8fo\82³\82ê\82é\82Ì\82Å\81A\95\8e\9a\95ª\90æ\82É\90i\82ñ\82Å
-      \82µ\82Ü\82Á\82Ä\82¢\82é\81B\8f]\82Á\82Ä 1 \82ð\88ø\82­\81B */
-    console.cursor.X = ttyDisplay->curx - 1;
+       \83o\83C\83g\82½\82Ü\82Á\82Ä\82©\82ç\8cÄ\82Ñ\8fo\82³\82ê\82é\82Ì\82Å\81An-\95\8e\9a\95ª\90æ\82É\90i\82ñ\82Å
+      \82µ\82Ü\82Á\82Ä\82¢\82é\81B\8f]\82Á\82Ä n-\82ð\88ø\82­\81B */
+    console.cursor.X = ttyDisplay->curx - (strlen(str) - 1);
     console.cursor.Y = ttyDisplay->cury;
 
-    xputc2_core(ch1, ch2);
+    xputc2_core(str);
 }
 #endif