home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / source / kanji.h < prev    next >
C/C++ Source or Header  |  1998-05-04  |  6KB  |  172 lines

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