aboutsummaryrefslogtreecommitdiffstats
path: root/graphics/gd1/files/patch-gdkanji.c
blob: 2162a7e95c38a7025499c5bb586dd0a737233bf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--- gdkanji.c.orig  Fri Feb  2 05:23:56 2001
+++ gdkanji.c   Wed Feb  7 20:59:08 2001
@@ -103,14 +103,18 @@
 unsigned char *str;
 #endif
 {
-   static int whatcode;
+   static int whatcode = ASCII;
+   int oldcode = ASCII;
    int c, i;
    char *lang = NULL;
 
    c = '\1';
    i = 0;
 
-   if (whatcode == 0) whatcode = ASCII;
+   if (whatcode != EUCORSJIS && whatcode != ASCII) {
+       oldcode = whatcode;
+       whatcode = ASCII;
+   }
    
    while ((whatcode == EUCORSJIS || whatcode == ASCII) && c != '\0') {
        if ((c = str[i++]) != '\0') {
@@ -167,7 +171,7 @@
                if ((c >= 64 && c <= 126) || (c >= 128 && c <= 160))
                    whatcode = SJIS;
                else
-               if (c >= 253 && c >= 254) whatcode = EUC;
+               if (c >= 253 && c <= 254) whatcode = EUC;
                else
                if (c >= 161 && c <= 252) whatcode = EUCORSJIS;
            }
@@ -184,6 +188,8 @@
        debug("Kanji code detected at %d byte.", i);
 #endif
 
+   if (whatcode == EUCORSJIS && oldcode != ASCII) whatcode = oldcode;
+
    if (whatcode == EUCORSJIS) {
        if (getenv ("LC_ALL")) lang = getenv ("LC_ALL");
        else
@@ -310,7 +316,7 @@
            error("invalid code specification: \"%s\" or \"%s\"",
                                EUCSTR, code);
 #endif
-       strcpy(to, from);
+       ustrcpy(to, from);
        return;
    }
 
@@ -328,7 +334,7 @@
        else
 #endif
            error("something happen");
-       strcpy(to, from);
+       ustrcpy(to, from);
        return;
    }
 
@@ -526,11 +532,10 @@
 
    t = (unsigned char *)gdMalloc(BUFSIZ);
    any2eucjp(t, s, BUFSIZ);
-   i = strlen(t);
+   i = strlen((const char *)t);
    gdFree(t);
    return i;
 }
-#endif
 
 #ifdef DEBUG
 int main()
@@ -543,7 +548,7 @@
    while ( (c = fgetc(stdin)) != '\n' && i < BUFSIZ ) input[i++] = c;
    input[i] = '\0';
 
-   printf("input : %d bytes\n", strlen(input));
+   printf("input : %d bytes\n", strlen((const char *)input));
    printf("output: %d bytes\n", strwidth(input));
 
    output = (unsigned char *)gdMalloc(BUFSIZ);
@@ -555,4 +560,5 @@
 
    return 0;
 }
+#endif
 #endif