kanji.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Unix SMB/Netbios implementation.
  3. Version 1.9.
  4. Kanji Extensions
  5. Copyright (C) Andrew Tridgell 1992-1998
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. Adding for Japanese language by <fujita@ainix.isac.co.jp> 1994.9.5
  18. and extend coding system to EUC/SJIS/JIS/HEX at 1994.10.11
  19. and add all jis codes sequence at 1995.8.16
  20. Notes: Hexadecimal code by <ohki@gssm.otuka.tsukuba.ac.jp>
  21. and add upper/lower case conversion 1997.8.21
  22. */
  23. #ifndef _KANJI_H_
  24. #define _KANJI_H_
  25. /* FOR SHIFT JIS CODE */
  26. #define is_shift_jis(c) \
  27. ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0x9f) \
  28. || (0xe0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xef))
  29. #define is_shift_jis2(c) \
  30. (0x40 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfc \
  31. && ((unsigned char) (c)) != 0x7f)
  32. #define is_kana(c) ((0xa0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xdf))
  33. /* case conversion */
  34. #define is_sj_upper2(c) \
  35. ((0x60 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x79))
  36. #define is_sj_lower2(c) \
  37. ((0x81 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x9A))
  38. #define sjis_alph 0x82
  39. #define is_sj_alph(c) (sjis_alph == (unsigned char) (c))
  40. #define is_sj_upper(c1, c2) (is_sj_alph (c1) && is_sj_upper2 (c2))
  41. #define is_sj_lower(c1, c2) (is_sj_alph (c1) && is_sj_lower2 (c2))
  42. #define sj_toupper2(c) \
  43. (is_sj_lower2 (c) ? ((int) ((unsigned char) (c) - 0x81 + 0x60)) : \
  44. ((int) (unsigned char) (c)))
  45. #define sj_tolower2(c) \
  46. (is_sj_upper2 (c) ? ((int) ((unsigned char) (c) - 0x60 + 0x81)) : \
  47. ((int) (unsigned char) (c)))
  48. #ifdef _KANJI_C_
  49. /* FOR EUC CODE */
  50. #define euc_kana (0x8e)
  51. #define is_euc_kana(c) (((unsigned char) (c)) == euc_kana)
  52. #define is_euc(c) (0xa0 < ((unsigned char) (c)) && ((unsigned char) (c)) < 0xff)
  53. /* FOR JIS CODE */
  54. /* default jis third shift code, use for output */
  55. #ifndef JIS_KSO
  56. #define JIS_KSO 'B'
  57. #endif
  58. #ifndef JIS_KSI
  59. #define JIS_KSI 'J'
  60. #endif
  61. /* in: \E$B or \E$@ */
  62. /* out: \E(J or \E(B or \E(H */
  63. #define jis_esc (0x1b)
  64. #define jis_so (0x0e)
  65. #define jis_so1 ('$')
  66. #define jis_so2 ('B')
  67. #define jis_si (0x0f)
  68. #define jis_si1 ('(')
  69. #define jis_si2 ('J')
  70. #define is_esc(c) (((unsigned char) (c)) == jis_esc)
  71. #define is_so1(c) (((unsigned char) (c)) == jis_so1)
  72. #define is_so2(c) (((unsigned char) (c)) == jis_so2 || ((unsigned char) (c)) == '@')
  73. #define is_si1(c) (((unsigned char) (c)) == jis_si1)
  74. #define is_si2(c) (((unsigned char) (c)) == jis_si2 || ((unsigned char) (c)) == 'B' \
  75. || ((unsigned char) (c)) == 'H')
  76. #define is_so(c) (((unsigned char) (c)) == jis_so)
  77. #define is_si(c) (((unsigned char) (c)) == jis_si)
  78. #define junet_kana1 ('(')
  79. #define junet_kana2 ('I')
  80. #define is_juk1(c) (((unsigned char) (c)) == junet_kana1)
  81. #define is_juk2(c) (((unsigned char) (c)) == junet_kana2)
  82. #define _KJ_ROMAN (0)
  83. #define _KJ_KANJI (1)
  84. #define _KJ_KANA (2)
  85. /* FOR HEX */
  86. #define HEXTAG ':'
  87. #define hex2bin(x) \
  88. ( ((int) '0' <= ((int) (x)) && ((int) (x)) <= (int)'9')? \
  89. (((int) (x))-(int)'0'): \
  90. ((int) 'a'<= ((int) (x)) && ((int) (x))<= (int) 'f')? \
  91. (((int) (x)) - (int)'a'+10): \
  92. (((int) (x)) - (int)'A'+10) )
  93. #define bin2hex(x) \
  94. ( (((int) (x)) >= 10)? (((int) (x))-10 + (int) 'a'): (((int) (x)) + (int) '0') )
  95. /* For Hangul (Korean - code page 949). */
  96. #define is_hangul(c) ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfd))
  97. /* For traditional Chinese (known as Big5 encoding - code page 950). */
  98. #define is_big5_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf9))
  99. /* For simplified Chinese (code page - 936). */
  100. #define is_simpch_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf7))
  101. #else /* not _KANJI_C_ */
  102. /*
  103. * The following is needed for AIX systems that have
  104. * their own #defines for strchr, strrchr, strstr
  105. * and strtok.
  106. */
  107. #ifdef strchr
  108. #undef strchr
  109. #endif /* strchr */
  110. #ifdef strrchr
  111. #undef strrchr
  112. #endif /* strrchr */
  113. #ifdef strstr
  114. #undef strstr
  115. #endif /* strstr */
  116. #ifdef strtok
  117. #undef strtok
  118. #endif /* strtok */
  119. /* Ensure we use our definitions in all other files than kanji.c. */
  120. /* Function pointers we will replace. */
  121. extern char *(*multibyte_strchr)(const char *s, int c);
  122. extern char *(*multibyte_strrchr)(const char *s, int c);
  123. extern char *(*multibyte_strstr)(const char *s1, const char *s2);
  124. extern char *(*multibyte_strtok)(char *s1, const char *s2);
  125. extern char *(*_dos_to_unix)(char *str, BOOL overwrite);
  126. extern char *(*_unix_to_dos)(char *str, BOOL overwrite);
  127. extern BOOL (*is_multibyte_char)(char c);
  128. extern int (*_skip_multibyte_char)(char c);
  129. #define strchr(s1, c) ((*multibyte_strchr)((s1), (c)))
  130. #define strrchr(s1, c) ((*multibyte_strrchr)((s1), (c)))
  131. #define strstr(s1, s2) ((*multibyte_strstr)((s1), (s2)))
  132. #define strtok(s1, s2) ((*multibyte_strtok)((s1), (s2)))
  133. #define dos_to_unix(x,y) ((*_dos_to_unix)((x), (y)))
  134. #define unix_to_dos(x,y) ((*_unix_to_dos)((x), (y)))
  135. #define skip_multibyte_char(c) ((*_skip_multibyte_char)((c)))
  136. #endif /* _KANJI_C_ */
  137. #define UNKNOWN_CODE (-1)
  138. #define SJIS_CODE (0)
  139. #define EUC_CODE (1)
  140. #define JIS7_CODE (2)
  141. #define JIS8_CODE (3)
  142. #define JUNET_CODE (4)
  143. #define HEX_CODE (5)
  144. #define CAP_CODE (6)
  145. #define DOSV_CODE SJIS_CODE
  146. #endif /* _KANJI_H_ */