and extend coding system to EUC/SJIS/JIS/HEX at 1994.10.11
and add all jis codes sequence at 1995.8.16
Notes: Hexadecimal code by <ohki@gssm.otuka.tsukuba.ac.jp>
+ and add upper/lower case conversion 1997.8.21
*/
#ifndef _KANJI_H_
#define _KANJI_H_
&& ((unsigned char) (c)) != 0x7f)
#define is_kana(c) ((0xa0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xdf))
+/* case conversion */
+#define is_sj_upper2(c) \
+ ((0x60 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x79))
+#define is_sj_lower2(c) \
+ ((0x81 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x9A))
+#define sjis_alph 0x82
+#define is_sj_alph(c) (sjis_alph == (unsigned char) (c))
+#define is_sj_upper(c1, c2) (is_sj_alph (c1) && is_sj_upper2 (c2))
+#define is_sj_lower(c1, c2) (is_sj_alph (c1) && is_sj_lower2 (c2))
+#define sj_toupper2(c) \
+ (is_sj_lower2 (c) ? ((int) ((unsigned char) (c) - 0x81 + 0x60)) : \
+ ((int) (unsigned char) (c)))
+#define sj_tolower2(c) \
+ (is_sj_upper2 (c) ? ((int) ((unsigned char) (c) - 0x60 + 0x81)) : \
+ ((int) (unsigned char) (c)))
+
#ifdef _KANJI_C_
/* FOR EUC CODE */
#define euc_kana (0x8e)
return(chmod(dos_to_unix(fname,False),mode));
}
+/*******************************************************************
+for getwd
+********************************************************************/
+char *sys_getwd(char *s)
+{
+ char *wd;
+#ifdef USE_GETCWD
+ wd = (char *) getcwd (s, sizeof (pstring));
+#else
+ wd = (char *) getwd (s);
+#endif
+ if (wd)
+ unix_to_dos (wd, True);
+ return wd;
+}
+
/*******************************************************************
chown isn't used much but OS/2 doesn't have it
********************************************************************/
/* We *must* use toupper rather than tolower here due to the
asynchronous upper to lower mapping.
*/
+#ifdef KANJI
+ int diff;
+ for (;;)
+ {
+ if (!*s || !*t)
+ return toupper (*s) - toupper (*t);
+ else if (is_sj_alph (*s) && is_sj_alph (*t))
+ {
+ diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ }
+ else if (is_shift_jis (*s) && is_shift_jis (*t))
+ {
+ diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
+ if (diff)
+ return diff;
+ diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ }
+ else if (is_shift_jis (*s))
+ return 1;
+ else if (is_shift_jis (*t))
+ return -1;
+ else
+ {
+ diff = toupper (*s) - toupper (*t);
+ if (diff)
+ return diff;
+ s++;
+ t++;
+ }
+ }
+#else /* KANJI */
while (*s && *t && toupper(*s) == toupper(*t))
{
s++; t++;
}
return(toupper(*s) - toupper(*t));
+#endif /* KANJI */
}
/*******************************************************************
/* We *must* use toupper rather than tolower here due to the
asynchronous upper to lower mapping.
*/
+#ifdef KANJI
+ int diff;
+ for (;n > 0;)
+ {
+ if (!*s || !*t)
+ return toupper (*s) - toupper (*t);
+ else if (is_sj_alph (*s) && is_sj_alph (*t))
+ {
+ diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ n -= 2;
+ }
+ else if (is_shift_jis (*s) && is_shift_jis (*t))
+ {
+ diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
+ if (diff)
+ return diff;
+ diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ n -= 2;
+ }
+ else if (is_shift_jis (*s))
+ return 1;
+ else if (is_shift_jis (*t))
+ return -1;
+ else
+ {
+ diff = toupper (*s) - toupper (*t);
+ if (diff)
+ return diff;
+ s++;
+ t++;
+ n--;
+ }
+ }
+ return 0;
+#else /* KANJI */
while (n-- && *s && *t && toupper(*s) == toupper(*t))
{
s++; t++;
/* identical up to where we run out of chars, and strings are same length */
return(0);
+#endif /* KANJI */
}
/*******************************************************************
{
#ifdef KANJI
if (is_shift_jis (*s)) {
+ if (is_sj_upper (s[0], s[1])) {
+ s[1] = sj_tolower2 (s[1]);
+ }
s += 2;
} else if (is_kana (*s)) {
s++;
*s = tolower(*s);
s++;
}
-#else
+#else /* KANJI */
if (isupper(*s))
*s = tolower(*s);
s++;
{
#ifdef KANJI
if (is_shift_jis (*s)) {
+ if (is_sj_lower (s[0], s[1])) {
+ s[1] = sj_toupper2 (s[1]);
+ }
s += 2;
} else if (is_kana (*s)) {
s++;
*s = toupper(*s);
s++;
}
-#else
+#else /* KANJI */
if (islower(*s))
*s = toupper(*s);
s++;
-#endif
+#endif /* KANJI */
}
}
*s = newc;
s++;
}
-#else
+#else /* KANJI */
if (oldc == *s)
*s = newc;
s++;
return(res);
}
-
-/*******************************************************************
- return the absolute current directory path. A dumb version.
-********************************************************************/
-static char *Dumb_GetWd(char *s)
-{
- char *p;
-#ifdef USE_GETCWD
- p = (char *)getcwd(s,sizeof(pstring));
-#else
- p = (char *)getwd(s));
-#endif
- if(!p)
- return NULL;
-
- /* Ensure we always return in dos format. */
- unix_to_dos(p,True);
- return p;
-}
-
-
/* number of list structures for a caching GetWd function. */
#define MAX_GETWDCACHE (50)
*s = 0;
if (!use_getwd_cache)
- return(Dumb_GetWd(str));
+ return(sys_getwd(str));
/* init the cache */
if (!getwd_cache_init)
if (stat(".",&st) == -1)
{
DEBUG(0,("Very strange, couldn't stat \".\"\n"));
- return(Dumb_GetWd(str));
+ return(sys_getwd(str));
}
The very slow getcwd, which spawns a process on some systems, or the
not quite so bad getwd. */
- if (!Dumb_GetWd(s))
+ if (!sys_getwd(s))
{
DEBUG(0,("Getwd failed, errno %d\n",errno));
return (NULL);
if (isupper(*s)) return(True);
s++;
}
-#else
+#else /* KANJI */
if (isupper(*s)) return(True);
s++;
#endif /* KANJI */
{
#ifdef KANJI
if (is_shift_jis (*s)) {
+ if (is_sj_upper (s[0], s[1])) return(True);
+ if (is_sj_lower (s[0], s[1])) return (True);
s += 2;
} else if (is_kana (*s)) {
s++;
if (islower(*s)) return(True);
s++;
}
-#else
+#else /* KANJI */
if (islower(*s)) return(True);
s++;
#endif /* KANJI */
int count_chars(char *s,char c)
{
int count=0;
+#ifdef KANJI
+ while (*s)
+ {
+ if (is_shift_jis (*s))
+ s += 2;
+ else
+ {
+ if (*s == c)
+ count++;
+ s++;
+ }
+ }
+#else /* KANJI */
while (*s)
{
if (*s == c)
count++;
s++;
}
+#endif /* KANJI */
return(count);
}