Diff for /np2/common/milstr.c between versions 1.9 and 1.13

version 1.9, 2004/06/20 02:57:47 version 1.13, 2005/02/07 14:46:08
Line 4 Line 4
 // ---- ANK / UCS2 / UCS4  // ---- ANK / UCS2 / UCS4
   
 #if defined(SUPPORT_ANK)  #if defined(SUPPORT_ANK)
 int milank_charsize(const OEMCHAR *str) {  int STRCALL milank_charsize(const OEMCHAR *str) {
   
         return((str[0] != '\0')?1:0);          return((str[0] != '\0')?1:0);
 }  }
   
 int milank_cmp(const OEMCHAR *str, const OEMCHAR *cmp) {  int STRCALL milank_cmp(const OEMCHAR *str, const OEMCHAR *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
Line 30  int milank_cmp(const OEMCHAR *str, const Line 30  int milank_cmp(const OEMCHAR *str, const
         return(0);          return(0);
 }  }
   
 int milank_memcmp(const OEMCHAR *str, const OEMCHAR *cmp) {  int STRCALL milank_memcmp(const OEMCHAR *str, const OEMCHAR *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
Line 51  int milank_memcmp(const OEMCHAR *str, co Line 51  int milank_memcmp(const OEMCHAR *str, co
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 void milank_ncpy(OEMCHAR *dst, const OEMCHAR *src, int maxlen) {  void STRCALL milank_ncpy(OEMCHAR *dst, const OEMCHAR *src, int maxlen) {
   
         int             i;          int             i;
   
Line 64  void milank_ncpy(OEMCHAR *dst, const OEM Line 64  void milank_ncpy(OEMCHAR *dst, const OEM
         }          }
 }  }
   
 void milank_ncat(OEMCHAR *dst, const OEMCHAR *src, int maxlen) {  void STRCALL milank_ncat(OEMCHAR *dst, const OEMCHAR *src, int maxlen) {
   
         int             i;          int             i;
         int             j;          int             j;
Line 83  void milank_ncat(OEMCHAR *dst, const OEM Line 83  void milank_ncat(OEMCHAR *dst, const OEM
         }          }
 }  }
   
 OEMCHAR *milank_chr(const OEMCHAR *str, int c) {  OEMCHAR * STRCALL milank_chr(const OEMCHAR *str, int c) {
   
         int             s;          int             s;
   
Line 104  OEMCHAR *milank_chr(const OEMCHAR *str,  Line 104  OEMCHAR *milank_chr(const OEMCHAR *str, 
 // ---- Shift-JIS  // ---- Shift-JIS
   
 #if defined(SUPPORT_SJIS)  #if defined(SUPPORT_SJIS)
 int milsjis_charsize(const char *str) {  int STRCALL milsjis_charsize(const char *str) {
   
         int             pos;          int             pos;
   
Line 112  int milsjis_charsize(const char *str) { Line 112  int milsjis_charsize(const char *str) {
         return((str[pos] != '\0')?(pos+1):0);          return((str[pos] != '\0')?(pos+1):0);
 }  }
   
 int milsjis_cmp(const char *str, const char *cmp) {  int STRCALL milsjis_cmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
   
         do {          do {
                 s = (BYTE)*str++;                  s = (UINT8)*str++;
                 if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x3c) {                  if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x3c) {
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         if (s != c) {                          if (s != c) {
                                 goto mscp_err;                                  goto mscp_err;
                         }                          }
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                 }                  }
                 else {                  else {
                         if (((s - 'a') & 0xff) < 26) {                          if (((s - 'a') & 0xff) < 26) {
                                 s -= 0x20;                                  s -= 0x20;
                         }                          }
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         if (((c - 'a') & 0xff) < 26) {                          if (((c - 'a') & 0xff) < 26) {
                                 c -= 0x20;                                  c -= 0x20;
                         }                          }
Line 146  mscp_err: Line 146  mscp_err:
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 int milsjis_memcmp(const char *str, const char *cmp) {  int STRCALL milsjis_memcmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
   
         do {          do {
                 c = (BYTE)*cmp++;                  c = (UINT8)*cmp++;
                 if ((((c ^ 0x20) - 0xa1) & 0xff) < 0x3c) {                  if ((((c ^ 0x20) - 0xa1) & 0xff) < 0x3c) {
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         if (c != s) {                          if (c != s) {
                                 break;                                  break;
                         }                          }
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                 }                  }
                 else if (c) {                  else if (c) {
                         if (((c - 'a') & 0xff) < 26) {                          if (((c - 'a') & 0xff) < 26) {
                                 c &= ~0x20;                                  c &= ~0x20;
                         }                          }
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         if (((s - 'a') & 0xff) < 26) {                          if (((s - 'a') & 0xff) < 26) {
                                 s &= ~0x20;                                  s &= ~0x20;
                         }                          }
Line 177  int milsjis_memcmp(const char *str, cons Line 177  int milsjis_memcmp(const char *str, cons
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 int milsjis_kanji1st(const char *str, int pos) {  int STRCALL milsjis_kanji1st(const char *str, int pos) {
   
         int             ret;          int             ret;
   
Line 189  int milsjis_kanji1st(const char *str, in Line 189  int milsjis_kanji1st(const char *str, in
         return(ret);          return(ret);
 }  }
   
 int milsjis_kanji2nd(const char *str, int pos) {  int STRCALL milsjis_kanji2nd(const char *str, int pos) {
   
         int             ret = 0;          int             ret;
   
           ret = 0;
         while((pos > 0) && ((((str[--pos] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) {          while((pos > 0) && ((((str[--pos] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) {
                 ret ^= 1;                  ret ^= 1;
         }          }
         return(ret);          return(ret);
 }  }
   
 void milsjis_ncpy(char *dst, const char *src, int maxlen) {  void STRCALL milsjis_ncpy(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
   
Line 217  void milsjis_ncpy(char *dst, const char  Line 218  void milsjis_ncpy(char *dst, const char 
         }          }
 }  }
   
 void milsjis_ncat(char *dst, const char *src, int maxlen) {  void STRCALL milsjis_ncat(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
         int             j;          int             j;
Line 241  void milsjis_ncat(char *dst, const char  Line 242  void milsjis_ncat(char *dst, const char 
         }          }
 }  }
   
 char *milsjis_chr(const char *str, int c) {  char * STRCALL milsjis_chr(const char *str, int c) {
   
         int             s;          int             s;
   
Line 266  char *milsjis_chr(const char *str, int c Line 267  char *milsjis_chr(const char *str, int c
 // ---- EUC  // ---- EUC
   
 #if defined(SUPPORT_EUC)                // あれ 半角カナ忘れてるぞ?  #if defined(SUPPORT_EUC)                // あれ 半角カナ忘れてるぞ?
 int mileuc_charsize(const char *str) {  int STRCALL mileuc_charsize(const char *str) {
   
         int             pos;          int             pos;
   
         pos = (((str[0] - 0xa1) & 0xff) < 0x5d)?1:0;          pos = (str[0] & 0x80)?1:0;
         return((str[pos] != '\0')?(pos+1):0);          return((str[pos] != '\0')?(pos+1):0);
 }  }
   
 int mileuc_cmp(const char *str, const char *cmp) {  int STRCALL mileuc_cmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
   
         do {          do {
                 s = (BYTE)*str++;                  s = (UINT8)*str++;
                 if (((s - 0xa1) & 0xff) < 0x5d) {                  if (s & 0x80) {
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         if (s != c) {                          if (s != c) {
                                 goto mscp_err;                                  goto mscp_err;
                         }                          }
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                 }                  }
                 else {                  else {
                         if (((s - 'a') & 0xff) < 26) {                          if (((s - 'a') & 0xff) < 26) {
                                 s -= 0x20;                                  s -= 0x20;
                         }                          }
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         if (((c - 'a') & 0xff) < 26) {                          if (((c - 'a') & 0xff) < 26) {
                                 c -= 0x20;                                  c -= 0x20;
                         }                          }
Line 308  mscp_err: Line 309  mscp_err:
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 int mileuc_memcmp(const char *str, const char *cmp) {  int STRCALL mileuc_memcmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
   
         do {          do {
                 c = (BYTE)*cmp++;                  c = (UINT8)*cmp++;
                 if (((c - 0xa1) & 0xff) < 0x5d) {                  if (c & 0x80) {
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         if (c != s) {                          if (c != s) {
                                 break;                                  break;
                         }                          }
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                 }                  }
                 else if (c) {                  else if (c) {
                         if (((c - 'a') & 0xff) < 26) {                          if (((c - 'a') & 0xff) < 26) {
                                 c -= 0x20;                                  c -= 0x20;
                         }                          }
                         s = (BYTE)*str++;                          s = (UINT8)*str++;
                         if (((s - 'a') & 0xff) < 26) {                          if (((s - 'a') & 0xff) < 26) {
                                 s -= 0x20;                                  s -= 0x20;
                         }                          }
Line 339  int mileuc_memcmp(const char *str, const Line 340  int mileuc_memcmp(const char *str, const
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 int mileuc_kanji1st(const char *str, int pos) {  int STRCALL mileuc_kanji1st(const char *str, int pos) {
   
         int             ret;          int             ret;
   
         ret = 0;          ret = 0;
         while((pos >= 0) &&          while((pos >= 0) && (str[pos--] & 0x80)) {
                 (((str[pos--] - 0xa1) & 0xff) < 0x5d)) {  
                 ret ^= 1;                  ret ^= 1;
         }          }
         return(ret);          return(ret);
 }  }
   
 int mileuc_kanji2nd(const char *str, int pos) {  int STRCALL mileuc_kanji2nd(const char *str, int pos) {
   
         int             ret = 0;          int             ret;
   
         while((pos > 0) && (((str[--pos] - 0xa1) & 0xff) < 0x5d)) {          ret = 0;
           while((pos > 0) && (str[--pos] & 0x80)) {
                 ret ^= 1;                  ret ^= 1;
         }          }
         return(ret);          return(ret);
 }  }
   
 void mileuc_ncpy(char *dst, const char *src, int maxlen) {  void STRCALL mileuc_ncpy(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
   
Line 379  void mileuc_ncpy(char *dst, const char * Line 380  void mileuc_ncpy(char *dst, const char *
         }          }
 }  }
   
 void mileuc_ncat(char *dst, const char *src, int maxlen) {  void STRCALL mileuc_ncat(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
         int             j;          int             j;
Line 403  void mileuc_ncat(char *dst, const char * Line 404  void mileuc_ncat(char *dst, const char *
         }          }
 }  }
   
 char *mileuc_chr(const char *str, int c) {  char * STRCALL mileuc_chr(const char *str, int c) {
   
         int             s;          int             s;
   
Line 413  char *mileuc_chr(const char *str, int c) Line 414  char *mileuc_chr(const char *str, int c)
                         if (s == c) {                          if (s == c) {
                                 return((char *)str);                                  return((char *)str);
                         }                          }
                         if (((s - 0xa1) & 0xff) < 0x5d) {                          if (s & 0x80) {
                                 str++;                                  str++;
                                 s = *str;                                  s = *str;
                         }                          }
Line 428  char *mileuc_chr(const char *str, int c) Line 429  char *mileuc_chr(const char *str, int c)
 // ---- UTF8  // ---- UTF8
   
 #if defined(SUPPORT_UTF8)  #if defined(SUPPORT_UTF8)
 int milutf8_charsize(const char *str) {  int STRCALL milutf8_charsize(const char *str) {
   
         if (str[0] == '\0') {          if (str[0] == '\0') {
                 return(0);                  return(0);
Line 450  int milutf8_charsize(const char *str) { Line 451  int milutf8_charsize(const char *str) {
         return(0);          return(0);
 }  }
   
 int milutf8_cmp(const char *str, const char *cmp) {  int STRCALL milutf8_cmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
Line 460  int milutf8_cmp(const char *str, const c Line 461  int milutf8_cmp(const char *str, const c
                 if (((s - 'a') & 0xff) < 26) {                  if (((s - 'a') & 0xff) < 26) {
                         s -= 0x20;                          s -= 0x20;
                 }                  }
                 c = (BYTE)*cmp++;                  c = (UINT8)*cmp++;
                 if (((c - 'a') & 0xff) < 26) {                  if (((c - 'a') & 0xff) < 26) {
                         c -= 0x20;                          c -= 0x20;
                 }                  }
Line 471  int milutf8_cmp(const char *str, const c Line 472  int milutf8_cmp(const char *str, const c
         return(0);          return(0);
 }  }
   
 int milutf8_memcmp(const char *str, const char *cmp) {  int STRCALL milutf8_memcmp(const char *str, const char *cmp) {
   
         int             s;          int             s;
         int             c;          int             c;
Line 492  int milutf8_memcmp(const char *str, cons Line 493  int milutf8_memcmp(const char *str, cons
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 int milutf8_kanji1st(const char *str, int pos) {  int STRCALL milutf8_kanji1st(const char *str, int pos) {
   
         return(((str[pos] & 0xc0) >= 0xc0)?1:0);          return(((str[pos] & 0xc0) >= 0xc0)?1:0);
 }  }
   
 int milutf8_kanji2nd(const char *str, int pos) {  int STRCALL milutf8_kanji2nd(const char *str, int pos) {
   
         return(((str[pos] & 0xc0) == 0x80)?1:0);          return(((str[pos] & 0xc0) == 0x80)?1:0);
 }  }
   
 void milutf8_ncpy(char *dst, const char *src, int maxlen) {  void STRCALL milutf8_ncpy(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
   
Line 511  void milutf8_ncpy(char *dst, const char  Line 512  void milutf8_ncpy(char *dst, const char 
                 for (i=0; i<maxlen && src[i]; i++) {                  for (i=0; i<maxlen && src[i]; i++) {
                         dst[i] = src[i];                          dst[i] = src[i];
                 }                  }
                 while((i) && ((dst[i] & 0xc0) == 0x80)) {  
                         i--;  
                 }  
                 dst[i] = '\0';                  dst[i] = '\0';
                   if (i) {
                           do {
                                   i--;
                           } while((i) && ((dst[i] & 0xc0) == 0x80));
                           i += milutf8_charsize(dst + i);
                           dst[i] = '\0';
                   }
         }          }
 }  }
   
 void milutf8_ncat(char *dst, const char *src, int maxlen) {  void STRCALL milutf8_ncat(char *dst, const char *src, int maxlen) {
   
         int             i;          int             i;
         int             j;          int             j;
Line 533  void milutf8_ncat(char *dst, const char  Line 538  void milutf8_ncat(char *dst, const char 
                 for (j=0; i<maxlen && src[j]; i++, j++) {                  for (j=0; i<maxlen && src[j]; i++, j++) {
                         dst[i] = src[j];                          dst[i] = src[j];
                 }                  }
                 while((i) && ((dst[i] & 0xc0) == 0x80)) {  
                         i--;  
                 }  
                 dst[i] = '\0';                  dst[i] = '\0';
                   if (i) {
                           do {
                                   i--;
                           } while((i) && ((dst[i] & 0xc0) == 0x80));
                           i += milutf8_charsize(dst + i);
                           dst[i] = '\0';
                   }
         }          }
 }  }
   
 char *milutf8_chr(const char *str, int c) {  char * STRCALL milutf8_chr(const char *str, int c) {
   
         int             s;          int             s;
   
Line 560  char *milutf8_chr(const char *str, int c Line 569  char *milutf8_chr(const char *str, int c
   
 // ---- other  // ---- other
   
 int milstr_extendcmp(const char *str, const char *cmp) {  int STRCALL milstr_extendcmp(const OEMCHAR *str, const OEMCHAR *cmp) {
   
         int             c;          int             c;
         int             s;          int             s;
   
         do {          do {
                 while(1) {                  while(1) {
                         c = (BYTE)*cmp++;                          c = (UINT8)*cmp++;
                         if (!c) {                          if (!c) {
                                 return(0);                                  return(0);
                         }                          }
Line 596  int milstr_extendcmp(const char *str, co Line 605  int milstr_extendcmp(const char *str, co
         return((s > c)?1:-1);          return((s > c)?1:-1);
 }  }
   
 OEMCHAR *milstr_nextword(const OEMCHAR *str) {  OEMCHAR * STRCALL milstr_nextword(const OEMCHAR *str) {
   
         if (str) {          if (str) {
                 while((*str > '\0') && (*str <= ' ')) {                  while((*str > '\0') && (*str <= ' ')) {
Line 606  OEMCHAR *milstr_nextword(const OEMCHAR * Line 615  OEMCHAR *milstr_nextword(const OEMCHAR *
         return((OEMCHAR *)str);          return((OEMCHAR *)str);
 }  }
   
 int milstr_getarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) {  int STRCALL milstr_getarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) {
   
         int             ret = 0;          int             ret = 0;
         OEMCHAR *p;          OEMCHAR *p;
         BOOL    quot;          BRESULT quot;
   
         while(maxarg--) {          while(maxarg--) {
                 quot = FALSE;                  quot = FALSE;
Line 640  int milstr_getarg(OEMCHAR *str, OEMCHAR  Line 649  int milstr_getarg(OEMCHAR *str, OEMCHAR 
         return(ret);          return(ret);
 }  }
   
 long milstr_solveHEX(const OEMCHAR *str) {  long STRCALL milstr_solveHEX(const OEMCHAR *str) {
   
         long    ret;          long    ret;
         int             i;          int             i;
         char    c;          OEMCHAR c;
   
         ret = 0;          ret = 0;
         for (i=0; i<8; i++) {          for (i=0; i<8; i++) {
Line 667  long milstr_solveHEX(const OEMCHAR *str) Line 676  long milstr_solveHEX(const OEMCHAR *str)
         return(ret);          return(ret);
 }  }
   
 long milstr_solveINT(const OEMCHAR *str) {  long STRCALL milstr_solveINT(const OEMCHAR *str) {
   
         long    ret;          long    ret;
         int             c;          int             c;
Line 696  long milstr_solveINT(const OEMCHAR *str) Line 705  long milstr_solveINT(const OEMCHAR *str)
         return(ret * s);          return(ret * s);
 }  }
   
 OEMCHAR *milstr_list(const OEMCHAR *lststr, UINT pos) {  OEMCHAR * STRCALL milstr_list(const OEMCHAR *lststr, UINT pos) {
   
         if (lststr) {          if (lststr) {
                 while(pos) {                  while(pos) {

Removed from v.1.9  
changed lines
  Added in v.1.13


RetroPC.NET-CVS <cvs@retropc.net>