| version 1.4, 2003/11/21 06:51:10 | version 1.10, 2004/06/20 11:19:45 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  |  | 
 |  |  | 
|  | // ---- ANK / UCS2 / UCS4 | 
| // ---- ANK |  | 
 |  |  | 
 | #if defined(SUPPORT_ANK) | #if defined(SUPPORT_ANK) | 
| int milank_cmp(const char *str, const char *cmp) { | int milank_charsize(const OEMCHAR *str) { | 
|  |  | 
|  | return((str[0] != '\0')?1:0); | 
|  | } | 
|  |  | 
|  | int milank_cmp(const OEMCHAR *str, const OEMCHAR *cmp) { | 
 |  |  | 
 | int             s; | int             s; | 
 | int             c; | int             c; | 
 |  |  | 
 | do { | do { | 
| s = (BYTE)*str++; | s = *str++; | 
| if (((s - 'a') & 0xff) < 26) { | if ((s >= 'a') && (s <= 'z')) { | 
 | s -= 0x20; | s -= 0x20; | 
 | } | } | 
| c = (BYTE)*cmp++; | c = *cmp++; | 
| if (((c - 'a') & 0xff) < 26) { | if ((c >= 'a') && (c <= 'z')) { | 
 | c -= 0x20; | c -= 0x20; | 
 | } | } | 
 | if (s != c) { | if (s != c) { | 
| Line 26  int milank_cmp(const char *str, const ch | Line 30  int milank_cmp(const char *str, const ch | 
 | return(0); | return(0); | 
 | } | } | 
 |  |  | 
| int milank_memcmp(const char *str, const char *cmp) { | int milank_memcmp(const OEMCHAR *str, const OEMCHAR *cmp) { | 
 |  |  | 
 | int             s; | int             s; | 
 | int             c; | int             c; | 
 |  |  | 
 | do { | do { | 
| c = (BYTE)*cmp++; | c = *cmp++; | 
 | if (c == 0) { | if (c == 0) { | 
 | return(0); | return(0); | 
 | } | } | 
| if (((c - 'a') & 0xff) < 26) { | if ((c >= 'a') && (c <= 'z')) { | 
 | c -= 0x20; | c -= 0x20; | 
 | } | } | 
| s = (BYTE)*str++; | s = *str++; | 
| if (((s - 'a') & 0xff) < 26) { | if ((s >= 'a') && (s <= 'z')) { | 
 | s -= 0x20; | s -= 0x20; | 
 | } | } | 
 | } while(s == c); | } while(s == c); | 
 | return((s > c)?1:-1); | return((s > c)?1:-1); | 
 | } | } | 
 |  |  | 
| void milank_ncpy(char *dst, const char *src, int maxlen) { | void milank_ncpy(OEMCHAR *dst, const OEMCHAR *src, int maxlen) { | 
 |  |  | 
 | int             i; | int             i; | 
 |  |  | 
| Line 60  void milank_ncpy(char *dst, const char * | Line 64  void milank_ncpy(char *dst, const char * | 
 | } | } | 
 | } | } | 
 |  |  | 
| void milank_ncat(char *dst, const char *src, int maxlen) { | void milank_ncat(OEMCHAR *dst, const OEMCHAR *src, int maxlen) { | 
 |  |  | 
 | int             i; | int             i; | 
 | int             j; | int             j; | 
| Line 78  void milank_ncat(char *dst, const char * | Line 82  void milank_ncat(char *dst, const char * | 
 | dst[i] = '\0'; | dst[i] = '\0'; | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | OEMCHAR *milank_chr(const OEMCHAR *str, int c) { | 
 |  |  | 
 |  | int             s; | 
 |  |  | 
 |  | if (str) { | 
 |  | do { | 
 |  | s = *str; | 
 |  | if (s == c) { | 
 |  | return((OEMCHAR *)str); | 
 |  | } | 
 |  | str++; | 
 |  | } while(s); | 
 |  | } | 
 |  | return(NULL); | 
 |  | } | 
 | #endif | #endif | 
 |  |  | 
 |  |  | 
 | // ---- Shift-JIS | // ---- Shift-JIS | 
 |  |  | 
 | #if defined(SUPPORT_SJIS) | #if defined(SUPPORT_SJIS) | 
 |  | int milsjis_charsize(const char *str) { | 
 |  |  | 
 |  | int             pos; | 
 |  |  | 
 |  | pos = ((((str[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c)?1:0; | 
 |  | return((str[pos] != '\0')?(pos+1):0); | 
 |  | } | 
 |  |  | 
 | int milsjis_cmp(const char *str, const char *cmp) { | int milsjis_cmp(const char *str, const char *cmp) { | 
 |  |  | 
 | int             s; | int             s; | 
| Line 212  void milsjis_ncat(char *dst, const char | Line 240  void milsjis_ncat(char *dst, const char | 
 | dst[i] = '\0'; | dst[i] = '\0'; | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | char *milsjis_chr(const char *str, int c) { | 
 |  |  | 
 |  | int             s; | 
 |  |  | 
 |  | if (str) { | 
 |  | do { | 
 |  | s = *str; | 
 |  | if (s == c) { | 
 |  | return((char *)str); | 
 |  | } | 
 |  | if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x3c) { | 
 |  | str++; | 
 |  | s = *str; | 
 |  | } | 
 |  | str++; | 
 |  | } while(s); | 
 |  | } | 
 |  | return(NULL); | 
 |  | } | 
 | #endif | #endif | 
 |  |  | 
 |  |  | 
 | // ---- EUC | // ---- EUC | 
 |  |  | 
| #if defined(SUPPORT_EUC) | #if defined(SUPPORT_EUC)                // あれ 半角カナ忘れてるぞ? | 
|  | int mileuc_charsize(const char *str) { | 
|  |  | 
|  | int             pos; | 
|  |  | 
|  | pos = (((str[0] - 0xa1) & 0xff) < 0x5d)?1:0; | 
|  | return((str[pos] != '\0')?(pos+1):0); | 
|  | } | 
|  |  | 
 | int mileuc_cmp(const char *str, const char *cmp) { | int mileuc_cmp(const char *str, const char *cmp) { | 
 |  |  | 
 | int             s; | int             s; | 
| Line 346  void mileuc_ncat(char *dst, const char * | Line 402  void mileuc_ncat(char *dst, const char * | 
 | dst[i] = '\0'; | dst[i] = '\0'; | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | char *mileuc_chr(const char *str, int c) { | 
 |  |  | 
 |  | int             s; | 
 |  |  | 
 |  | if (str) { | 
 |  | do { | 
 |  | s = *str; | 
 |  | if (s == c) { | 
 |  | return((char *)str); | 
 |  | } | 
 |  | if (((s - 0xa1) & 0xff) < 0x5d) { | 
 |  | str++; | 
 |  | s = *str; | 
 |  | } | 
 |  | str++; | 
 |  | } while(s); | 
 |  | } | 
 |  | return(NULL); | 
 |  | } | 
 |  | #endif | 
 |  |  | 
 |  |  | 
 |  | // ---- UTF8 | 
 |  |  | 
 |  | #if defined(SUPPORT_UTF8) | 
 |  | int milutf8_charsize(const char *str) { | 
 |  |  | 
 |  | if (str[0] == '\0') { | 
 |  | return(0); | 
 |  | } | 
 |  | else if (!(str[0] & 0x80)) { | 
 |  | return(1); | 
 |  | } | 
 |  | else if ((str[0] & 0xe0) == 0xc0) { | 
 |  | if ((str[1] & 0xc0) == 0x80) { | 
 |  | return(2); | 
 |  | } | 
 |  | } | 
 |  | else if ((str[0] & 0xf0) == 0xe0) { | 
 |  | if (((str[1] & 0xc0) == 0x80) || | 
 |  | ((str[2] & 0xc0) == 0x80)) { | 
 |  | return(3); | 
 |  | } | 
 |  | } | 
 |  | return(0); | 
 |  | } | 
 |  |  | 
 |  | int milutf8_cmp(const char *str, const char *cmp) { | 
 |  |  | 
 |  | int             s; | 
 |  | int             c; | 
 |  |  | 
 |  | do { | 
 |  | s = (UINT8)*str++; | 
 |  | if (((s - 'a') & 0xff) < 26) { | 
 |  | s -= 0x20; | 
 |  | } | 
 |  | c = (BYTE)*cmp++; | 
 |  | if (((c - 'a') & 0xff) < 26) { | 
 |  | c -= 0x20; | 
 |  | } | 
 |  | if (s != c) { | 
 |  | return((s > c)?1:-1); | 
 |  | } | 
 |  | } while(s); | 
 |  | return(0); | 
 |  | } | 
 |  |  | 
 |  | int milutf8_memcmp(const char *str, const char *cmp) { | 
 |  |  | 
 |  | int             s; | 
 |  | int             c; | 
 |  |  | 
 |  | do { | 
 |  | c = (UINT8)*cmp++; | 
 |  | if (c == 0) { | 
 |  | return(0); | 
 |  | } | 
 |  | if (((c - 'a') & 0xff) < 26) { | 
 |  | c -= 0x20; | 
 |  | } | 
 |  | s = (UINT8)*str++; | 
 |  | if (((s - 'a') & 0xff) < 26) { | 
 |  | s -= 0x20; | 
 |  | } | 
 |  | } while(s == c); | 
 |  | return((s > c)?1:-1); | 
 |  | } | 
 |  |  | 
 |  | int milutf8_kanji1st(const char *str, int pos) { | 
 |  |  | 
 |  | return(((str[pos] & 0xc0) >= 0xc0)?1:0); | 
 |  | } | 
 |  |  | 
 |  | int milutf8_kanji2nd(const char *str, int pos) { | 
 |  |  | 
 |  | return(((str[pos] & 0xc0) == 0x80)?1:0); | 
 |  | } | 
 |  |  | 
 |  | void milutf8_ncpy(char *dst, const char *src, int maxlen) { | 
 |  |  | 
 |  | int             i; | 
 |  |  | 
 |  | if (maxlen > 0) { | 
 |  | maxlen--; | 
 |  | for (i=0; i<maxlen && src[i]; i++) { | 
 |  | dst[i] = src[i]; | 
 |  | } | 
 |  | while((i) && ((dst[i-1] & 0xc0) == 0x80)) { | 
 |  | i--; | 
 |  | } | 
 |  | dst[i] = '\0'; | 
 |  | } | 
 |  | } | 
 |  |  | 
 |  | void milutf8_ncat(char *dst, const char *src, int maxlen) { | 
 |  |  | 
 |  | int             i; | 
 |  | int             j; | 
 |  |  | 
 |  | if (maxlen > 0) { | 
 |  | maxlen--; | 
 |  | for (i=0; i<maxlen; i++) { | 
 |  | if (!dst[i]) { | 
 |  | break; | 
 |  | } | 
 |  | } | 
 |  | for (j=0; i<maxlen && src[j]; i++, j++) { | 
 |  | dst[i] = src[j]; | 
 |  | } | 
 |  | while((i) && ((dst[i-1] & 0xc0) == 0x80)) { | 
 |  | i--; | 
 |  | } | 
 |  | dst[i] = '\0'; | 
 |  | } | 
 |  | } | 
 |  |  | 
 |  | char *milutf8_chr(const char *str, int c) { | 
 |  |  | 
 |  | int             s; | 
 |  |  | 
 |  | if (str) { | 
 |  | do { | 
 |  | s = *str; | 
 |  | if (s == c) { | 
 |  | return((char *)str); | 
 |  | } | 
 |  | str++; | 
 |  | } while(s); | 
 |  | } | 
 |  | return(NULL); | 
 |  | } | 
 | #endif | #endif | 
 |  |  | 
 |  |  | 
| Line 387  int milstr_extendcmp(const char *str, co | Line 596  int milstr_extendcmp(const char *str, co | 
 | return((s > c)?1:-1); | return((s > c)?1:-1); | 
 | } | } | 
 |  |  | 
| int milstr_getarg(char *str, char *arg[], int maxarg) { | OEMCHAR *milstr_nextword(const OEMCHAR *str) { | 
|  |  | 
|  | if (str) { | 
|  | while((*str > '\0') && (*str <= ' ')) { | 
|  | str++; | 
|  | } | 
|  | } | 
|  | return((OEMCHAR *)str); | 
|  | } | 
|  |  | 
|  | int milstr_getarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { | 
 |  |  | 
 | int             ret = 0; | int             ret = 0; | 
| char    *p; | OEMCHAR *p; | 
 | BOOL    quot; | BOOL    quot; | 
 |  |  | 
 | while(maxarg--) { | while(maxarg--) { | 
 | quot = FALSE; | quot = FALSE; | 
| while((*str) && (((BYTE)*str) <= 0x20)) { | while((*str > '\0') && (*str <= ' ')) { | 
 | str++; | str++; | 
 | } | } | 
 | if (*str == '\0') { | if (*str == '\0') { | 
| Line 404  int milstr_getarg(char *str, char *arg[] | Line 623  int milstr_getarg(char *str, char *arg[] | 
 | arg[ret++] = str; | arg[ret++] = str; | 
 | p = str; | p = str; | 
 | while(*str) { | while(*str) { | 
| if (*str == 0x22) { | if (*str == '\"') { | 
 | quot = !quot; | quot = !quot; | 
 | } | } | 
| else if ((((BYTE)*str) > 0x20) || (quot)) { | else if ((quot) || (*str < '\0') || (*str > ' ')) { | 
 | *p++ = *str; | *p++ = *str; | 
 | } | } | 
 | else { | else { | 
| Line 421  int milstr_getarg(char *str, char *arg[] | Line 640  int milstr_getarg(char *str, char *arg[] | 
 | return(ret); | return(ret); | 
 | } | } | 
 |  |  | 
| long milstr_solveHEX(const char *str) { | long milstr_solveHEX(const OEMCHAR *str) { | 
 |  |  | 
 | long    ret; | long    ret; | 
 | int             i; | int             i; | 
| Line 448  long milstr_solveHEX(const char *str) { | Line 667  long milstr_solveHEX(const char *str) { | 
 | return(ret); | return(ret); | 
 | } | } | 
 |  |  | 
| long milstr_solveINT(const char *str) { | long milstr_solveINT(const OEMCHAR *str) { | 
 |  |  | 
 | long    ret; | long    ret; | 
 | int             c; | int             c; | 
| Line 477  long milstr_solveINT(const char *str) { | Line 696  long milstr_solveINT(const char *str) { | 
 | return(ret * s); | return(ret * s); | 
 | } | } | 
 |  |  | 
 |  | OEMCHAR *milstr_list(const OEMCHAR *lststr, UINT pos) { | 
 |  |  | 
 |  | if (lststr) { | 
 |  | while(pos) { | 
 |  | pos--; | 
 |  | while(*lststr++ != '\0') { | 
 |  | } | 
 |  | } | 
 |  | } | 
 |  | return((OEMCHAR *)lststr); | 
 |  | } | 
 |  |  |