|
| 1 | +/* |
| 2 | + * Module : multibyte.c |
| 3 | + * |
| 4 | + * Description: Mlutibyte related additional function. |
| 5 | + * |
| 6 | + * Create 2001-03-03 Eiji Tokuya |
| 7 | + * |
| 8 | + */ |
| 9 | +#include <string.h> |
| 10 | +#include "multibyte.h" |
| 11 | + |
| 12 | +int multibyte_client_encoding ; /* Multibyte Client Encoding. */ |
| 13 | +int multibyte_status ; /* Multibyte Odds and ends character. */ |
| 14 | + |
| 15 | +unsigned char *multibyte_strchr(unsigned char *s,unsigned char c) |
| 16 | +{ |
| 17 | + int mb_st = 0 ,i = 0; |
| 18 | + while (!(mb_st == 0 && s[i] == c || s[i] == 0)) |
| 19 | + { |
| 20 | + if (s[i] == 0) |
| 21 | + return (0); |
| 22 | + switch ( multibyte_client_encoding ) |
| 23 | + { |
| 24 | + case SJIS: |
| 25 | + { |
| 26 | + if (mb_st < 2 && s[i] > 0x80 && !(s[i] > 0x9f && s[i] < 0xe0)) |
| 27 | + mb_st = 2; |
| 28 | + else if (mb_st == 2) |
| 29 | + mb_st = 1; |
| 30 | + else |
| 31 | + mb_st = 0; |
| 32 | + } |
| 33 | + break; |
| 34 | + |
| 35 | + |
| 36 | +/* Chinese Big5 Support. */ |
| 37 | + case BIG5: |
| 38 | + { |
| 39 | + if ( mb_st < 2 && s[i] > 0xA0 ) |
| 40 | + mb_st = 2; |
| 41 | + else if ( mb_st == 2 ) |
| 42 | + mb_st = 1; |
| 43 | + else |
| 44 | + mb_st = 0; |
| 45 | + } |
| 46 | + break; |
| 47 | + default: |
| 48 | + { |
| 49 | + mb_st = 0; |
| 50 | + } |
| 51 | + } |
| 52 | + i++; |
| 53 | + } |
| 54 | +#ifdef _DEBUG |
| 55 | + qlog("i = %d\n",i); |
| 56 | +#endif |
| 57 | + return (s + i); |
| 58 | +} |
| 59 | + |
| 60 | +void multibyte_init(void) |
| 61 | +{ |
| 62 | + multibyte_status = 0; |
| 63 | +} |
| 64 | + |
| 65 | +unsigned char *check_client_encoding(unsigned char *str) |
| 66 | +{ |
| 67 | + if(strstr(str,"%27SJIS%27")||strstr(str,"'SJIS'")||strstr(str,"'sjis'")) |
| 68 | + { |
| 69 | + multibyte_client_encoding = SJIS; |
| 70 | + return ("SJIS"); |
| 71 | + } |
| 72 | + if(strstr(str,"%27BIG5%27")||strstr(str,"'BIG5'")||strstr(str,"'big5'")) |
| 73 | + { |
| 74 | + multibyte_client_encoding = BIG5; |
| 75 | + return ("BIG5"); |
| 76 | + } |
| 77 | + return ("OHTER"); |
| 78 | +} |
| 79 | + |
| 80 | +/* |
| 81 | + * Multibyte Status Function. |
| 82 | + * Input char |
| 83 | + * Output 0 : 1 Byte Character. |
| 84 | + * 1 : MultibyteCharacter Last Byte. |
| 85 | + * N : MultibyteCharacter Fast or Middle Byte. |
| 86 | + */ |
| 87 | +int multibyte_char_check(unsigned char s) |
| 88 | +{ |
| 89 | + switch ( multibyte_client_encoding ) |
| 90 | + { |
| 91 | +/* Japanese Shift-JIS(CP932) Support. */ |
| 92 | + case SJIS: |
| 93 | + { |
| 94 | + if ( multibyte_status < 2 && s > 0x80 && !(s > 0x9f && s < 0xE0)) |
| 95 | + multibyte_status = 2; |
| 96 | + else if (multibyte_status == 2) |
| 97 | + multibyte_status = 1; |
| 98 | + else |
| 99 | + multibyte_status = 0; |
| 100 | + } |
| 101 | + break; |
| 102 | + |
| 103 | + |
| 104 | +/* Chinese Big5(CP950) Support. */ |
| 105 | + case BIG5: |
| 106 | + { |
| 107 | + if ( multibyte_status < 2 && s > 0xA0) |
| 108 | + multibyte_status = 2; |
| 109 | + else if (multibyte_status == 2) |
| 110 | + multibyte_status = 1; |
| 111 | + else |
| 112 | + multibyte_status = 0; |
| 113 | + } |
| 114 | + break; |
| 115 | + default: |
| 116 | + { |
| 117 | + multibyte_status = 0; |
| 118 | + } |
| 119 | + } |
| 120 | +#ifdef _DEBUG |
| 121 | + qlog("multibyte_client_encoding = %d s = 0x%02X multibyte_stat = %d\n", multibyte_client_encoding, s, multibyte_status ); |
| 122 | +#endif |
| 123 | + return( multibyte_status ); |
| 124 | +} |
0 commit comments