OSDN Git Service

fix #37913
authorSHIRAKATA Kentaro <argrath@ub32.org>
Tue, 23 Jan 2018 17:46:03 +0000 (02:46 +0900)
committerSHIRAKATA Kentaro <argrath@ub32.org>
Tue, 23 Jan 2018 17:46:58 +0000 (02:46 +0900)
ChangeLog.j
include/extern.h
japanese/jlib.c
win/tty/getline.c

index 72647ed..32c5231 100644 (file)
@@ -3,6 +3,7 @@
        * \93à\95\94\83R\81[\83h\82Æ\95\\8e¦\83R\81[\83h\82ª\88á\82¤\8e\9e\82Ì\96â\91è\82ð\8fC\90³:
          * -u\83I\83v\83V\83\87\83\93\82Å\93ú\96{\8cê\82ð\8eg\82¤\82Æ\95\8e\9a\89»\82¯\82·\82é (#37911)
          * -s\83I\83v\83V\83\87\83\93\82Å\93ú\96{\8cê\82ð\8eg\82¤\82Æ\95\8e\9a\89»\82¯\82·\82é (#37912)
+         * \93ú\96{\8cê\93ü\97Í\82ª\90³\82µ\82­\93®\8dì\82µ\82È\82¢ (#37913)
 
 Fri Feb 17 2017  Kentaro Shirakata  <argrath@ub32.org>
 
index cd776db..1c3d240 100644 (file)
@@ -2794,6 +2794,7 @@ E void FDECL(jputchar,(int));
 E void FDECL(jputs,(const char *));
 E int FDECL(is_kanji2, (const char *,int));
 E int FDECL(is_kanji1, (const char *,int));
+E int FDECL(offset_in_kanji, (const unsigned char *, int));
 E int FDECL(isspace_8, (int));
 E void FDECL(split_japanese, (char *,char *,char *,int));
 E void FDECL(jrndm_replace, (char *));
index 6416051..212dd39 100644 (file)
@@ -532,6 +532,54 @@ is_kanji1(s, pos)
 }
 
 /*
+ * \8a¿\8e\9a\82Ì\90æ\93ª\88Ê\92u\82Ü\82Å\89½\83o\83C\83g\96ß\82é\95K\97v\82ª\82 \82é\82©\82ð\8cv\8eZ\82·\82é
+ */
+int
+offset_in_kanji(s, pos)
+     const unsigned char *s;
+     int pos;
+{
+    static int mask[7] = {
+        0,
+        0xc0,
+        0xe0,
+        0xf0,
+        0xf8,
+        0xfc,
+        0xfe,
+    };
+    if (output_kcode == UTF8) {
+        int c = 1;
+        int i;
+
+        /* \90æ\93ª\82È\82ç\8fí\82É0 */
+        if (pos == 0) {
+            return 0;
+        }
+        
+        pos--;
+        /* \92¼\91O\82Ì\95\8e\9a\82ÍASCII */
+        if ((s[pos] & 0x80) == 0x00) {
+            return 0;
+        }
+
+        for (i = pos; i >= 0; i--) {
+            if ((s[i] & 0xc0) == 0xc0)
+                break;
+            c++;
+        }
+
+        if (s[i] < mask[c]) {
+            return 0;
+        } else {
+            return c;
+        }
+    } else {
+        return is_kanji2(s, pos);
+    }
+}
+
+/*
 ** 8\83r\83b\83g\83X\83\8b\81[\82Èisspace()
 */
 int
index 4ab182b..0147b00 100644 (file)
@@ -156,8 +156,15 @@ getlin_hook_proc hook;
             } else
                 tty_nhbell();
 #if 1 /*JP*/
-           if(is_kanji2(tmp, bufp-tmp))
-             goto moreback;
+            {
+                int n;
+                n = offset_in_kanji(tmp, bufp - tmp);
+                if (n > 0) {
+                    /* \8cã\82Å1\83o\83C\83g\88ø\82©\82ê\82é\82Ì\82Å\82»\82Ì\95ª\82Í\82±\82±\82Å\82Í\88ø\82©\82È\82¢ */
+                    bufp = bufp - (n - 1);
+                    goto moreback;
+                }
+            }
 #endif
 #if defined(apollo)
         } else if (c == '\n' || c == '\r') {
@@ -231,8 +238,7 @@ getlin_hook_proc hook;
     ttyDisplay->inread--;
     clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
 #if 1 /*JP*/
-/*     Strcpy(bfp, str2ic(tmp)); JPTB not need for no convert? */
-       Strcpy(bfp, tmp);
+    Strcpy(bfp, str2ic(tmp));
 #endif
 }