Changeset 494


Ignore:
Timestamp:
Aug 1, 2003, 8:42:12 AM (22 years ago)
Author:
zap
Message:

See ChangeLog.

Location:
trunk/src/emx
Files:
3 added
15 deleted
63 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/386/builtin.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    8787}
    8888
     89/* Quick routines similar to div() and friends, but inline */
     90
     91static __inline__ long __ldivmod (long num, long den, long *rem)
     92{
     93  long q, r;
     94  __asm__ ("cltd; idivl %2"
     95           : "=a" (q), "=&d" (r)
     96           : "r?m" (den), "a" (num));
     97  *rem = r;
     98  return q;
     99}
     100
     101static __inline__ unsigned long __uldivmod (unsigned long num,
     102  unsigned long den, unsigned long *rem)
     103{
     104  unsigned long q, r;
     105  __asm__ ("xorl %%edx,%%edx; divl %2"
     106           : "=a" (q), "=&d" (r)
     107           : "r?m" (den), "a" (num));
     108  *rem = r;
     109  return q;
     110}
     111
     112/*
     113    Divide a 64-bit integer by a 32-bit one:
     114
     115    A*2^32 + B    A            B + (A mod 32)
     116    ---------- = --- * 2^32 + ----------------
     117        C         C                  C
     118*/
     119static __inline__ long long __lldivmod (long long num, long den, long *rem)
     120{
     121  long long q;
     122  long r;
     123  __asm__ ("    movl    %%eax,%%esi;"
     124           "    movl    %%edx,%%eax;"
     125           "    pushl   %%edx;"
     126           "    cltd;"
     127           "    idivl   %2;"
     128           "    ;"
     129/* Now ensure remainder is smallest of possible two values (negative and
     130   positive). For this we compare the remainder with positive and negative
     131   denominator/2; if it is smaller than one and bigger than another we
     132   consider it optimal, otherwise it can be made smaller by adding or
     133   subtracting denominator to it. This is done to ensure no overflow
     134   will occur at next division. */
     135           "    movl    %2,%%ecx;"
     136           "    sarl    $1,%%ecx;"      /* ecx = den/2 */
     137           "    cmpl    %%ecx,%%edx;"
     138           "    setl    %%bl;"
     139           "    negl    %%ecx;"
     140           "    cmpl    %%ecx,%%edx;"
     141           "    setl    %%bh;"
     142           "    xorb    %%bh,%%bl;"
     143           "    jnz     1f;"            /* Remainder is between -den/2...den/2 */
     144           "    ;"
     145/* If remainder has same sign as denominator, we have to do r -= den; q++;
     146   otherwise we have to do r += den; q--; */
     147           "    movl    %2,%%ebx;"      /* ebx = den */
     148           "    xorl    %%edx,%%ebx;"   /* r ^ den */
     149           "    js      0f;"            /* Different signs */
     150           "    subl    %2,%%edx;"      /* r -= den */
     151           "    addl    $1,%%eax;"      /* q++ */
     152           "    adcl    $0,%%edx;"
     153           "    jmp     1f;"
     154           "    ;"
     155           "0:  addl    %2,%%edx;"      /* r += den */
     156           "    subl    $1,%%eax;"      /* q-- */
     157           "    sbbl    $0,%%edx;"
     158           "    ;"
     159           "1:  xchgl   %%eax,%%esi;"
     160           "    idivl   %2;"
     161           "    ;"
     162           "    movl    %%edx,%1;"
     163           "    cltd;"
     164           "    addl    %%esi,%%edx;"
     165           "    ;"
     166/* Check if numerator has the same sign as remainder; if they have different
     167   sign we should make the remainder have same sign as numerator to comply
     168   with ANSI standard, which says we always should truncate the quotient
     169   towards zero. */
     170           "    popl    %%ebx;"         /* ebx = num >> 32 */
     171           "    xorl    %1,%%ebx;"      /* sign(r) ^ sign(num) */
     172           "    jns     3f;"            /* jump if same sign */
     173           "    ;"
     174/* If remainder has same sign as denominator, we have to do r -= den; q++;
     175   otherwise we have to do r += den; q--; */
     176           "    movl    %2,%%ebx;"
     177           "    xorl    %1,%%ebx;"      /* r ^ den */
     178           "    js      2f;"            /* Different signs */
     179           "    subl    %2,%1;"         /* r -= den */
     180           "    addl    $1,%%eax;"      /* q++ */
     181           "    adcl    $0,%%edx;"
     182           "    jmp     3f;"
     183           "    ;"
     184           "2:  addl    %2,%1;"         /* r += den */
     185           "    subl    $1,%%eax;"      /* q-- */
     186           "    sbbl    $0,%%edx;"
     187           "    ;"
     188           "3:  ;"
     189           : "=A" (q), "=&c" (r)
     190           : "r" (den), "A" (num)
     191           : "ebx", "esi");
     192  *rem = r;
     193  return q;
     194}
     195
     196/*
     197    Same as __lldivmod except that if A < C, we can do just one division
     198    instead of two because the result is always a 32-bit integer.
     199*/
     200static __inline__ unsigned long long __ulldivmod (unsigned long long num,
     201  unsigned long den, unsigned long *rem)
     202{
     203  unsigned long long q;
     204  unsigned long r;
     205  __asm__ ("    movl    %%eax,%1;"
     206           "    movl    %%edx,%%eax;"
     207           "    xorl    %%edx,%%edx;"
     208           "    divl    %2;"
     209           "    xchgl   %%eax,%%ecx;"
     210           "    divl    %2;"
     211           "    xchgl   %%edx,%1;"
     212           : "=A" (q), "=c" (r)
     213           : "r?m" (den), "A" (num));
     214  *rem = r;
     215  return q;
     216}
     217
    89218#if defined (__cplusplus)
    90219}
  • trunk/src/emx/include/ctype.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* ctype.h (emx+gcc) */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Character type querying.
     8*/
    29
    310#ifndef _CTYPE_H
     
    815#endif
    916
    10 extern unsigned char _ctype[];
     17#include <sys/locale.h>
    1118
    12 #define _UPPER  0x01
    13 #define _LOWER  0x02
    14 #define _DIGIT  0x04
    15 #define _XDIGIT 0x08
    16 #define _CNTRL  0x10
    17 #define _SPACE  0x20
    18 #define _PUNCT  0x40
    19 #define _PRINT  0x80
     19static inline int isalnum (int _c)
     20{ return __locale_ctype.cflags [_c & 0xff] & (__UPPER|__LOWER|__DIGIT); }
    2021
    21 #if defined (__cplusplus)
     22static inline int isalpha (int _c)
     23{ return __locale_ctype.cflags [_c & 0xff] & (__UPPER|__LOWER); }
    2224
    23 extern inline int isalnum (int _c)
    24   { return (_ctype+1)[(unsigned char)_c] & (_UPPER|_LOWER|_DIGIT); }
    25 extern inline int isalpha (int _c)
    26   { return (_ctype+1)[(unsigned char)_c] & (_UPPER|_LOWER); }
    27 extern inline int iscntrl (int _c)
    28   { return (_ctype+1)[(unsigned char)_c] & (_CNTRL); }
    29 extern inline int isdigit (int _c)
    30   { return (_ctype+1)[(unsigned char)_c] & (_DIGIT); }
    31 extern inline int isgraph (int _c)
    32   { return (_ctype+1)[(unsigned char)_c] & (_PUNCT|_UPPER|_LOWER|_DIGIT); }
    33 extern inline int islower (int _c)
    34   { return (_ctype+1)[(unsigned char)_c] & (_LOWER); }
    35 extern inline int isprint (int _c)
    36   { return (_ctype+1)[(unsigned char)_c] & (_PRINT); }
    37 extern inline int ispunct (int _c)
    38   { return (_ctype+1)[(unsigned char)_c] & (_PUNCT); }
    39 extern inline int isspace (int _c)
    40   { return (_ctype+1)[(unsigned char)_c] & (_SPACE); }
    41 extern inline int isupper (int _c)
    42   { return (_ctype+1)[(unsigned char)_c] & (_UPPER); }
    43 extern inline int isxdigit (int _c)
    44   { return (_ctype+1)[(unsigned char)_c] & (_XDIGIT); }
     25static inline int iscntrl (int _c)
     26{ return __locale_ctype.cflags [_c & 0xff] & (__CNTRL); }
    4527
    46 #else
     28static inline int isdigit (int _c)
     29{ return __locale_ctype.cflags [_c & 0xff] & (__DIGIT); }
    4730
    48 #define isalnum(c)  ((_ctype+1)[(unsigned char)c] & (_UPPER|_LOWER|_DIGIT))
    49 #define isalpha(c)  ((_ctype+1)[(unsigned char)c] & (_UPPER|_LOWER))
    50 #define iscntrl(c)  ((_ctype+1)[(unsigned char)c] & (_CNTRL))
    51 #define isdigit(c)  ((_ctype+1)[(unsigned char)c] & (_DIGIT))
    52 #define isgraph(c)  ((_ctype+1)[(unsigned char)c] & (_PUNCT|_UPPER|_LOWER|_DIGIT))
    53 #define islower(c)  ((_ctype+1)[(unsigned char)c] & (_LOWER))
    54 #define isprint(c)  ((_ctype+1)[(unsigned char)c] & (_PRINT))
    55 #define ispunct(c)  ((_ctype+1)[(unsigned char)c] & (_PUNCT))
    56 #define isspace(c)  ((_ctype+1)[(unsigned char)c] & (_SPACE))
    57 #define isupper(c)  ((_ctype+1)[(unsigned char)c] & (_UPPER))
    58 #define isxdigit(c) ((_ctype+1)[(unsigned char)c] & (_XDIGIT))
     31static inline int isgraph (int _c)
     32{ return __locale_ctype.cflags [_c & 0xff] & (__PUNCT|__UPPER|__LOWER|__DIGIT); }
    5933
    60 int (isalnum)(int);
    61 int (isalpha)(int);
    62 int (iscntrl)(int);
    63 int (isdigit)(int);
    64 int (isgraph)(int);
    65 int (islower)(int);
    66 int (isprint)(int);
    67 int (ispunct)(int);
    68 int (isspace)(int);
    69 int (isupper)(int);
    70 int (isxdigit)(int);
     34static inline int islower (int _c)
     35{ return __locale_ctype.cflags [_c & 0xff] & (__LOWER); }
    7136
    72 int toupper (int);
    73 int tolower (int);
    74 int _toupper (int);
    75 int _tolower (int);
     37static inline int isprint (int _c)
     38{ return __locale_ctype.cflags [_c & 0xff] & (__PRINT); }
    7639
    77 #endif
     40static inline int ispunct (int _c)
     41{ return __locale_ctype.cflags [_c & 0xff] & (__PUNCT); }
    7842
    79 #if !defined (_CTYPE_FUN)
    80 extern __inline__ int _toupper (int _c) { return (_c-'a'+'A'); }
    81 extern __inline__ int _tolower (int _c) { return (_c-'A'+'a'); }
    82 extern __inline__ int toupper(int _c)
    83   {return (islower(_c) ? _toupper(_c) : _c);}
    84 extern __inline__ int tolower(int _c)
    85   {return (isupper(_c) ? _tolower(_c) : _c);}
    86 #endif
     43static inline int isspace (int _c)
     44{ return __locale_ctype.cflags [_c & 0xff] & (__SPACE); }
     45
     46static inline int isupper (int _c)
     47{ return __locale_ctype.cflags [_c & 0xff] & (__UPPER); }
     48
     49static inline int isxdigit (int _c)
     50{ return __locale_ctype.cflags [_c & 0xff] & (__XDIGIT); }
     51
     52static inline int toupper (int _c)
     53{ return __locale_ctype.upcase [_c & 0xff]; }
     54
     55static inline int tolower (int _c)
     56{ return __locale_ctype.locase [_c & 0xff]; }
    8757
    8858#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)
    8959
    90 int (toascii)(int);
    91 int (isascii)(int);
     60static inline int isascii (int _c)
     61{ return (unsigned)_c <= 0x7f; }
    9262
    93 #define isascii(c)  ((unsigned)(c) <= 0x7f)
    94 #define toascii(c)  ((c) & 0x7f)
     63static inline int toascii (int _c)
     64{ return _c & 0x7f; }
    9565
    9666#endif
    97 
    9867
    9968#if defined (__cplusplus)
  • trunk/src/emx/include/emx/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    179179int __mkdir (__const__ char *name);
    180180int __newthread (int tid);
    181 int __nls_ctype (unsigned char *buf);
    182 void __nls_memupr (unsigned char *buf, size_t size);
    183181int __open (__const__ char *name, int flags, unsigned long size);
    184182int __pause (void);
  • trunk/src/emx/include/emx/thread.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    3737  unsigned int    _th_rand;                 /* Used by rand() */
    3838  void          * _th_store;                /* Pointer to user data */
    39   int             _th_mblen_shift;          /* Shift state for mblen() */
    40   int             _th_mbtowc_shift;         /* Shift state for mbtowc() */
    41   int             _th_wctomb_shift;         /* Shift state for wctomb() */
    4239  char            _th_vollabel[12];         /* Used by _getvol() */
    4340  char            _th_error[28];            /* Used by strerror() */
     
    4643  char            _th_ttyname[32];          /* Used by ttyname() */
    4744  char            _th_inetntoa[16];         /* Used by inetntoa() */
    48   int             _th_reserved[971];        /* 4096 bytes, total */
     45  int             _th_reserved[974];        /* 4096 bytes, total */
    4946};
    5047
  • trunk/src/emx/include/locale.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r493 r494  
    1 /* locale.h (emx+gcc) */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    POSIX locale implementation.
     8*/
    29
    310#ifndef _LOCALE_H
     
    815#endif
    916
    10 #if !defined (NULL)
    11 #if defined (__cplusplus)
    12 #define NULL 0
    13 #else
    14 #define NULL ((void *)0)
    15 #endif
    16 #endif
     17/* lconv and categories */
     18#include <sys/locale.h>
    1719
    18 #define LC_ALL          0
    19 #define LC_COLLATE      1
    20 #define LC_CTYPE        2
    21 #define LC_MONETARY     3
    22 #define LC_NUMERIC      4
    23 #define LC_TIME         5
    24 
    25 #define LC_C             "C"
    26 #define LC_C_FRANCE      "FRAN"
    27 #define LC_C_GERMANY     "GERM"
    28 #define LC_C_ITALY       "ITAL"
    29 #define LC_C_SPAIN       "SPAI"
    30 #define LC_C_UK          "UK"
    31 #define LC_C_USA         "USA"
    32 
    33 struct lconv
    34 {
    35   char *decimal_point;
    36   char *thousands_sep;
    37   char *grouping;
    38   char *int_curr_symbol;
    39   char *currency_symbol;
    40   char *mon_decimal_point;
    41   char *mon_thousands_sep;
    42   char *mon_grouping;
    43   char *positive_sign;
    44   char *negative_sign;
    45   char int_frac_digits;
    46   char frac_digits;
    47   char p_cs_precedes;
    48   char p_sep_by_space;
    49   char n_cs_precedes;
    50   char n_sep_by_space;
    51   char p_sign_posn;
    52   char n_sign_posn;
    53 };
    54 
    55 
    56 char *setlocale (int, __const__ char *);
    57 
    58 struct lconv *_localeconv (int);
    59 struct lconv *localeconv (void);
    60 
    61 #if defined (__CHAR_UNSIGNED__)
    62 #define localeconv() _localeconv (255)
    63 #else
    64 #define localeconv() _localeconv (127)
    65 #endif
     20/* Set current locale, if __locale is not NULL. Returns previous locale. */
     21extern char *setlocale (int category, __const__ char *locale);
     22/* Get information about current locale. */
     23extern struct lconv *localeconv (void);
    6624
    6725#if defined (__cplusplus)
  • trunk/src/emx/include/stdlib.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    7979    int (*)(__const__ void *, __const__ void *));
    8080div_t div (int, int);
     81ldiv_t ldiv (long, long);
    8182void exit (int) __attribute__ ((__noreturn__));
    8283char *getenv (__const__ char *);
    83 ldiv_t ldiv (long, long);
    8484int mblen (__const__ char *, size_t);
    8585size_t mbstowcs (wchar_t *, __const__ char *, size_t);
     
    149149extern char **environ;
    150150
    151 extern __const__ char * __const__ sys_errlist[];
    152 extern __const__ int sys_nerr;
    153 
    154151extern __const__ unsigned char _osminor;
    155152extern __const__ unsigned char _osmajor;
     
    159156
    160157unsigned alarm (unsigned);
    161 int      brk(const void *);
     158int brk(const void *);
    162159int chdir (__const__ char *);
    163160char *gcvt (double, int, char *);
     
    169166int putenv (__const__ char *);
    170167int rmdir (__const__ char *);
    171 void    *sbrk(intptr_t);
     168void *sbrk(intptr_t);
    172169unsigned sleep (unsigned);
    173170void swab (__const__ void *, void *, size_t);
     
    181178void srandom (unsigned);                                /* BSD */
    182179
     180char *itoa (int, char *, int);
     181char *ltoa (long, char *, int);
     182char *ultoa (unsigned long, char *, int);
     183char *lltoa (long long, char *, int);
     184char *ulltoa (unsigned long long, char *, int);
     185
    183186#endif
    184187
     
    188191
    189192extern char **_environ;
    190 extern __const__ char * __const__ _sys_errlist[];
    191 extern __const__ int _sys_nerr;
    192193
    193194unsigned _alarm (unsigned);
    194 int      _brk(const void *);
     195int _brk(const void *);
    195196int _chdir (__const__ char *);
    196197char *_gcvt (double, int, char *);
     
    201202int _putenv (__const__ char *);
    202203int _rmdir (__const__ char *);
    203 void     *_sbrk(intptr_t);
     204void *_sbrk(intptr_t);
    204205unsigned _sleep (unsigned);
    205206void _swab (__const__ void *, void *, size_t);
     
    217218void _exit (int) __attribute__ ((__noreturn__));
    218219int _filesys (__const__ char *, char *, size_t);
    219 int _fncmp (__const__ unsigned char *, __const__ unsigned char *);
    220220char **_fnexplode (__const__ char *);
    221221void _fnexplodefree (char **);
     
    239239_lldiv_t _lldiv (long long, long long);
    240240char *_lltoa (long long, char *, int);
     241_uldiv_t _uldiv (unsigned long, unsigned long);
     242_ulldiv_t _ulldiv (unsigned long long, unsigned long long);
     243char *_itoa (int, char *, int);
    241244char *_ltoa (long, char *, int);
     245char *_ultoa (unsigned long, char *, int);
     246char *_lltoa (long long, char *, int);
     247char *_ulltoa (unsigned long long, char *, int);
    242248void _makepath (char *, __const__ char *, __const__ char *,
    243249    __const__ char *, __const__ char *);
     
    258264unsigned long long _strtoull (__const__ char *, char **, int);
    259265char _swchar (void);
    260 _uldiv_t _uldiv (unsigned long, unsigned long);
    261 _ulldiv_t _ulldiv (unsigned long long, unsigned long long);
    262 char *_ulltoa (unsigned long long, char *, int);
    263 char *_ultoa (unsigned long, char *, int);
    264266void _wildcard (int *, char ***);
    265267
  • trunk/src/emx/include/sys/errno.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    4747#define _SYS_ERRNO_H /* bird: emx */
    4848
    49 #if !defined(_KERNEL) && !defined(__ASSEMBLER__) && !defined(_ERRNO) /* bird: emx */
    50 #include <sys/cdefs.h>
    51 __BEGIN_DECLS
    52 #define _ERRNO                        /* bird: emx */
    53 extern int * _errno(void);            /* bird: emx */
    54 __END_DECLS
    55 #define errno           (* _errno())  /* bird: emx */
     49#if !defined (_ERRNO) && !defined (__ASSEMBLER__)
     50#define _ERRNO
     51extern int *_errno (void);
     52#define errno (*_errno ())
     53#endif
     54
     55#ifndef __ASSEMBLER__
     56extern __const__ char * __const__ sys_errlist[];
     57extern __const__ int sys_nerr;
    5658#endif
    5759
     
    189191#endif /* _POSIX_SOURCE */
    190192
    191 #ifdef _KERNEL
    192 /* pseudo-errors returned inside kernel to modify return to process */
    193 #define ERESTART        (-1)            /* restart syscall */
    194 #define EJUSTRETURN     (-2)            /* don't modify regs, just return */
    195 #define ENOIOCTL        (-3)            /* ioctl not handled by this layer */
    196 #define EDIRIOCTL       (-4)            /* do direct ioctl in GEOM */
    197193#endif
    198 
    199 #endif
  • trunk/src/emx/include/sys/param.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    180180#endif
    181181
     182#if defined (__cplusplus) && (__GNUC__ >= 2)
     183#  define MIN(a,b) (((a)<?(b))
     184#else
     185#  define MIN(a,b) (((a)<(b))?(a):(b))
     186#endif
     187#if defined (__cplusplus) && (__GNUC__ >= 2)
     188#  define MAX(a,b) (((a)>?(b))
     189#else
     190#  define MAX(a,b) (((a)>(b))?(a):(b))
     191#endif
    182192
    183193#if defined (__cplusplus)
  • trunk/src/emx/include/utils.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    4444#endif
    4545
    46 #ifndef MIN
    47 #define MIN(a,b) (((a)<(b))?(a):(b))
    48 #define imin(x,y) MIN((x),(y))
    49 #define MAX(a,b) (((a)>(b))?(a):(b))
    50 #endif
    51 #ifndef min
    52 #define min(a,b) (((a)<(b))?(a):(b))
    53 #endif
     46/* MIN/MAX */
     47#include <sys/param.h>
    5448/* timercmp */
    5549#include <sys/time.h>
  • trunk/src/emx/src/emxbind/emxbind.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    471471      file_name (out_fname, (dll_flag ? "dll" : "exe"),
    472472                 (opt_o != NULL ? opt_o : inp_fname));
    473       if (_fncmp (inp_fname, out_fname) == 0)
     473      if (strcasecmp (inp_fname, out_fname) == 0)
    474474        error ("The input and output files have the same name");
    475475      break;
  • trunk/src/emx/src/emxbind/emxbind.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    2121
    2222#include "a_out.h"
     23#include <sys/param.h>
    2324
    2425#if defined (EXTERN)
     
    432433
    433434#define round_4(X) ((((X)-1) & ~3) + 4)
    434 
    435 /* Round up to the next multiple of the page size (0x1000). */
    436 
    437 #define round_page(X) ((((X)-1) & ~0xfff) + 0x1000)
    438435
    439436/* Divide by the page size, rounding down. */
  • trunk/src/emx/src/emxbind/exec.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r493 r494  
    106106static struct grow header = GROW_INIT;
    107107
    108 
    109 /* Return the minimum of A and B. */
    110 
    111 #define min(a,b) (((a) < (b)) ? (a) : (b))
    112108
    113109/* Compute the virtual end address of a memory object of an LX
     
    838834  while (size > 0)
    839835    {
    840       n = min (size, BUFSIZ);
     836      n = MIN (size, BUFSIZ);
    841837      my_read (buf, n, src);
    842838      my_write (buf, n, &out_file);
     
    857853  while (count > 0)
    858854    {
    859       n = min (count, BUFSIZ);
     855      n = MIN (count, BUFSIZ);
    860856      my_write (buf, n, &out_file);
    861857      count -= n;
  • trunk/src/emx/src/emxcat/emxcat.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    526526     (FAT). */
    527527
    528   return _fncmp (*(const char * const *)p1,
    529                  *(const char * const *)p2);
     528  return strcasecmp (*(const char * const *)p1,
     529                     *(const char * const *)p2);
    530530}
    531531
     
    611611
    612612      for (j = i; j < argc; ++j)
    613         if (_fncmp (output_fname, argv[j]) != 0)
     613        if (strcasecmp (output_fname, argv[j]) != 0)
    614614          read_file (argv[j], pass);
    615615    }
  • trunk/src/emx/src/emxload/emxload.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    336336
    337337  for (i = 0; i < procs; ++i)
    338     if (table[i].name != NULL && _fncmp (table[i].name, req->name) == 0)
     338    if (table[i].name != NULL && strcasecmp (table[i].name, req->name) == 0)
    339339      {
    340340        if (req->req_code != _EMXLOAD_LOAD)
  • trunk/src/emx/src/emxomf/emxomfar.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r493 r494  
    382382          _remext (bak_fname);
    383383          _defext (bak_fname, "bak");
    384           if (_fncmp (lib_fname, bak_fname) == 0)
     384          if (strcasecmp (lib_fname, bak_fname) == 0)
    385385            {
    386386              fprintf (stderr, "Cannot update backup file\n");
  • trunk/src/emx/src/lib/alias/alias.smak

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r493 r494  
    2727        @$(call DO.STDALIAS,_strcasecmp,__std_stricmp,$.strcasecmp.o)
    2828        @$(call DO.STDALIAS,_strncasecmp,__std_strnicmp,$.strncasecmp.o)
     29        @$(call DO.STDALIAS,_itoa,__std_ltoa,$.itoa.o)
     30        @$(call DO.STDALIAS,__itoa,__std_ltoa,$._itoa.o)
    2931        @$(foreach x,$(ALIAS.FUNCS),\
    3032          $(call DO.STDALIAS,_$x,__std_$x,$.$x.o)$(NL))
     
    3234          $(call DO.STDALIAS,__$x,__std_$x,$._$x.o)$(NL))
    3335        $(AR) $(ARFLAGS) $@ $(addprefix $.,\
    34           strcasecmp.o strncasecmp.o \
     36          strcasecmp.o strncasecmp.o itoa.o _itoa.o \
    3537          $(addsuffix .o,$(ALIAS.FUNCS) $(addprefix _,$(ALIAS._FUNCS))))
    3638        @$(call RM,$(addprefix $., \
    37           strcasecmp.o strncasecmp.o \
     39          strcasecmp.o strncasecmp.o itoa.o _itoa.o \
    3840          $(addsuffix .o,$(ALIAS.FUNCS) $(addprefix _,$(ALIAS._FUNCS)))))
    3941
  • trunk/src/emx/src/lib/conv/atod.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* atod.c (emx+gcc) -- Copyright (c) 1996-1998 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
     
    1112#include <emx/bigint.h>
    1213#include <emx/float.h>
    13 #include <emx/locale.h>
     14#include <sys/locale.h>
    1415
    1516#define BBITS           (LDBL_MAX_EXP + LDBL_MANT_DIG - LDBL_MAX_10_EXP \
     
    2122#define MAX2    (_BI_WORDMAX - 10 * MAX1)
    2223
    23 #define DOT     (unsigned char)_cur_lconv.decimal_point[0]
     24#define DOT     (unsigned char)__locale_lconv.decimal_point[0]
    2425
    2526const char * __atod (long double *p_result, const char *string,
  • trunk/src/emx/src/lib/conv/dtoa.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    77#include <assert.h>
    88#include <sys/builtin.h>
     9#include <sys/param.h>
    910#include <emx/float.h>
    1011#include <emx/bigint.h>
     
    1213#define BWORDS          _BI_WORDS (LDBL_MAX_EXP)
    1314#define BIAS            16383
    14 
    15 #define MIN(a,b) ((a) < (b) ? (a) : (b))
    1615
    1716struct long_double_bits
  • trunk/src/emx/src/lib/conv/gcvt.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* gcvt.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
     
    89#include <locale.h>
    910#include <emx/float.h>
    10 #include <emx/locale.h>
     11#include <sys/locale.h>
    1112
    1213char *_STD(gcvt) (double x, int digits, char *buffer)
     
    8182      *dst++ = str[0];
    8283      if (str[1] != 0)
    83         *dst++ = _cur_lconv.decimal_point[0];
     84        *dst++ = __locale_lconv.decimal_point[0];
    8485      for (src = str+1; *src != 0; ++src)
    8586        *dst++ = *src;
     
    111112        {
    112113          if (i == xp + 1)
    113             *dst++ = _cur_lconv.decimal_point[0];
     114            *dst++ = __locale_lconv.decimal_point[0];
    114115          *dst++ = str[i];
    115116        }
  • trunk/src/emx/src/lib/conv/lltoa.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* lltoa.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Integer to ASCII conversion routines.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    long long -> ascii conversion routine.
     8*/
    29
    310#include "libc-alias.h"
    411#include <stdlib.h>
     12#include <386/builtin.h>
    513
    6 char *_lltoa (long long value, char *string, int radix)
     14extern const char *__digits;
     15
     16char *_STD(lltoa) (long long value, char *string, int radix)
    717{
    818  char *dst;
    919  char digits[64];
    1020  unsigned long long x;
    11   int i, n;
    12  
     21  int i;
     22  long rem;
     23
    1324  dst = string;
    1425  if (radix < 2 || radix > 36)
    15     {
    16       *dst = 0;
    17       return string;
    18     }
    19   if (radix == 10 && value < 0)
    20     {
    21       *dst++ = '-';
    22       x = -value;
    23     }
     26  {
     27    *dst = 0;
     28    return string;
     29  }
     30  if ((value < 0) && (radix == 10))
     31  {
     32    *dst++ = '-';
     33    x = -value;
     34  }
    2435  else
    2536    x = value;
     37
    2638  i = 0;
    2739  do
    28     {
    29       n = x % radix;
    30       digits[i++] = (n < 10 ? (char)n+'0' : (char)n-10+'a');
    31       x /= radix;
    32     } while (x != 0);
     40  {
     41    x = __ulldivmod (x, radix, &rem);
     42    digits [i++] = __digits [rem];
     43  } while (x != 0);
     44
    3345  while (i > 0)
    3446    *dst++ = digits[--i];
     47
    3548  *dst = 0;
    3649  return string;
  • trunk/src/emx/src/lib/conv/ltoa.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* ltoa.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Integer to ASCII conversion routines.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    long (AKA int) -> ascii conversion routine.
     8*/
    29
    310#include "libc-alias.h"
    411#include <stdlib.h>
     12#include <386/builtin.h>
    513
    6 char *_ltoa (long value, char *string, int radix)
     14extern const char *__digits;
     15
     16char *_STD(ltoa) (long value, char *string, int radix)
    717{
     18  int i;
    819  char *dst;
    920  char digits[32];
    10   unsigned long x;
    11   int i, n;
    12  
     21  unsigned long rem;
     22
    1323  dst = string;
    1424  if (radix < 2 || radix > 36)
    15     {
    16       *dst = 0;
    17       return string;
    18     }
    19   if (radix == 10 && value < 0)
    20     {
    21       *dst++ = '-';
    22       x = -value;
    23     }
    24   else
    25     x = value;
     25  {
     26    *dst = 0;
     27    return string;
     28  }
     29  if ((value < 0) && (radix == 10))
     30  {
     31    *dst++ = '-';
     32    value = -value;
     33  }
     34
    2635  i = 0;
    2736  do
    28     {
    29       n = x % radix;
    30       digits[i++] = (n < 10 ? (char)n+'0' : (char)n-10+'a');
    31       x /= radix;
    32     } while (x != 0);
     37  {
     38    value = __uldivmod (value, radix, &rem);
     39    digits [i++] = __digits [rem];
     40  } while (value);
     41
    3342  while (i > 0)
    3443    *dst++ = digits[--i];
     44
    3545  *dst = 0;
    3646  return string;
  • trunk/src/emx/src/lib/conv/smalatod.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* smalatod.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
     
    910#include <errno.h>
    1011#include <emx/float.h>
    11 #include <emx/locale.h>
     12#include <sys/locale.h>
    1213
    1314
     
    102103  for (;;)
    103104    {
    104       if (*s == (unsigned char)_cur_lconv.decimal_point[0] && !dot)
     105      if (*s == (unsigned char)__locale_lconv.decimal_point[0] && !dot)
    105106        {
    106107          dot = 1;
  • trunk/src/emx/src/lib/conv/ulltoa.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    1 /* ulltoa.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Integer to ASCII conversion routines.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    unsigned long long -> ascii conversion routine.
     8*/
    29
    310#include "libc-alias.h"
    411#include <stdlib.h>
     12#include <386/builtin.h>
    513
    6 char *_ulltoa (unsigned long long value, char *string, int radix)
     14extern const char *__digits;
     15
     16char *_STD(ulltoa) (unsigned long long value, char *string, int radix)
    717{
    818  char *dst;
    919  char digits[64];
    10   int i, n;
    11  
     20  int i;
     21  unsigned long rem;
     22
    1223  dst = string;
    1324  if (radix < 2 || radix > 36)
    14     {
    15       *dst = 0;
    16       return string;
    17     }
     25  {
     26    *dst = 0;
     27    return string;
     28  }
     29
    1830  i = 0;
    1931  do
    20     {
    21       n = value % radix;
    22       digits[i++] = (n < 10 ? (char)n+'0' : (char)n-10+'a');
    23       value /= radix;
    24     } while (value != 0);
     32  {
     33    value = __ulldivmod (value, radix, &rem);
     34    digits [i++] = __digits [rem];
     35  } while (value != 0);
     36
    2537  while (i > 0)
    2638    *dst++ = digits[--i];
     39
    2740  *dst = 0;
    2841  return string;
  • trunk/src/emx/src/lib/conv/ultoa.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    1 /* ultoa.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Integer to ASCII conversion routines.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    unsigned long (AKA unsigned int) -> ascii conversion routine.
     8*/
    29
    310#include "libc-alias.h"
    411#include <stdlib.h>
     12#include <386/builtin.h>
    513
    6 char *_ultoa (unsigned long value, char *string, int radix)
     14extern const char *__digits;
     15
     16char *_STD(ultoa) (unsigned long value, char *string, int radix)
    717{
     18  int i;
    819  char *dst;
    920  char digits[32];
    10   int i, n;
    11  
     21  unsigned long rem;
     22
    1223  dst = string;
    1324  if (radix < 2 || radix > 36)
    14     {
    15       *dst = 0;
    16       return string;
    17     }
     25  {
     26    *dst = 0;
     27    return string;
     28  }
     29
    1830  i = 0;
    1931  do
    20     {
    21       n = value % radix;
    22       digits[i++] = (n < 10 ? (char)n+'0' : (char)n-10+'a');
    23       value /= radix;
    24     } while (value != 0);
     32  {
     33    value = __uldivmod (value, radix, &rem);
     34    digits [i++] = __digits [rem];
     35  } while (value);
     36
    2537  while (i > 0)
    2638    *dst++ = digits[--i];
     39
    2740  *dst = 0;
    2841  return string;
  • trunk/src/emx/src/lib/io/_input.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    11/* _input.c (emx+gcc) -- Copyright (c) 1990-2000 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdio.h>
     
    910#include <limits.h>
    1011#include <locale.h>
    11 #include <emx/locale.h>
     12#include <sys/locale.h>
    1213#include <emx/io.h>
    1314#include "getputc.h"
     
    476477          c = get (v);
    477478        }
    478       if (c == (unsigned char)_cur_lconv.decimal_point[0])
     479      if (c == (unsigned char)__locale_lconv.decimal_point[0])
    479480        {
    480481          COLLECT (c);
     
    594595             differs from one comprising the directive, the directive
    595596             fails, and the differing and subsequent characters remain
    596              unread."
    597 
    598              Avoid the overhead of calling mblen(). */
    599 
    600           if (f <= 127 || _cur_mbyte.mode == _MB_8BITS)
     597             unread." */
     598
     599          if (!CHK_MBCS_PREFIX (__locale_ctype, f, mbn))
    601600            mbn = 1;
    602           else
    603             {
    604               mbn = _mbtowc (NULL, format, MB_LEN_MAX, &shift);
    605               if (mbn < 1)
    606                 mbn = 1;        /* Treat an invalid character as is */
    607             }
    608601          for (mbi = 0; mbi < mbn; ++mbi)
    609602            {
  • trunk/src/emx/src/lib/io/_output.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    11/* _output.c (emx+gcc) -- Copyright (c) 1990-2000 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdio.h>
     
    1213#include <emx/io.h>
    1314#include <emx/float.h>
    14 #include <emx/locale.h>
     15#include <sys/locale.h>
    1516#include "getputc.h"
    1617
     
    395396      /* Cases (1) through (4).  We print "0." followed by
    396397
    397            min (-xp - 1, v->prec)
     398           MIN (-xp - 1, v->prec)
    398399
    399400         zeros and the string of digit. */
     
    703704  v.stream = stream;
    704705  v.count = 0;
    705   zdot[1] = _cur_lconv.decimal_point[0];
     706  zdot[1] = __locale_lconv.decimal_point[0];
    706707
    707708  /* ANSI X3.159-1989, 4.9.6.1: "The format shall be a multibyte
     
    722723           Avoid the overhead of calling mblen(). */
    723724
    724         if (c <= 127 || _cur_mbyte.mode == _MB_8BITS)
     725        if (!CHK_MBCS_PREFIX (__locale_ctype, c, mbn))
     726          mbn = 1;
     727        while (mbn > 0)
    725728          {
    726             PUTC (&v, c);
    727             ++format;
    728           }
    729         else
    730           {
    731             mbn = _mbtowc (NULL, format, MB_LEN_MAX, &shift);
    732             if (mbn < 1)
    733               mbn = 1;          /* Output an invalid character as is */
    734             while (mbn > 0)
    735               {
    736                 PUTC (&v, *format);
    737                 ++format; --mbn;
    738               }
     729            PUTC (&v, *format);
     730            ++format; --mbn;
    739731          }
    740732      }
  • trunk/src/emx/src/lib/io/_trslash.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* _trslash.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    4 #include <sys/nls.h>
    55#include <emx/io.h>
     6#include <sys/locale.h>
    67
    78/* Detect trailing slash or backslash for stat(), access(), and
     
    1718int _trslash (const char *name, size_t len, int mode)
    1819{
    19   size_t i;
     20  size_t i, mbcl;
    2021
    2122  switch (mode)
     
    5960  for (;;)
    6061    {
    61       if (_nls_is_dbcs_lead ((unsigned char)name[i]))
     62      if (CHK_MBCS_PREFIX (__locale_ctype, name[i], mbcl))
    6263        {
    63           if (i == len - 3)
     64          if (i == len - 1 - mbcl)
    6465            {
    6566              /* Case (c) -- a DBCS character precedes the trailing
     
    6768              return 1;
    6869            }
    69           else if (i == len - 2)
     70          else if (i == len - mbcl)
    7071            {
    7172              /* Case (d) -- the last byte is the 2nd byte of a DBCS
     
    7475            }
    7576          else
    76             i += 2;
     77            i += mbcl;
    7778        }
    7879      else if (i == len - 2)
  • trunk/src/emx/src/lib/io/fread.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    55#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    66#include <sys/rmutex.h>
     7#include <sys/param.h>
    78#include <stdio.h>
    89#include <stdlib.h>
     
    1112#include <errno.h>
    1213#include <emx/io.h>
    13 
    14 #define min(a,b) (((a) < (b)) ? (a) : (b))
    1514
    1615size_t _STD(fread) (void *buffer, size_t size, size_t count, FILE *stream)
     
    4241        if (stream->_rcount > 0)
    4342          {
    44             n = min ((size_t)stream->_rcount, left);
     43            n = MIN ((size_t)stream->_rcount, left);
    4544            memcpy (dst, stream->_ptr, n);
    4645            stream->_ptr += n;
     
    8382      if (stream->_rcount > 0)
    8483        {
    85           n = min ((size_t)stream->_rcount, left);
     84          n = MIN ((size_t)stream->_rcount, left);
    8685          memcpy (dst, stream->_ptr, n);
    8786          stream->_ptr += n;
  • trunk/src/emx/src/lib/io/select.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    99#include <emx/io.h>
    1010#include <emx/syscalls.h>
    11 
    12 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
    1311
    1412int _STD(select) (int nfds, fd_set *readfds, fd_set *writefds,
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    3030    "__lookahead" @10
    3131    "__mb_cur_max" @11
    32     "__nls_ctype_tab" @12
    33     "__nls_tolower_tab" @13
    34     "__nls_toupper_tab" @14
    3532    "__org_environ" @15
    3633    "__osmajor" @16
     
    225222    "___fmutex_release_internal" @249
    226223    "___fmutex_request_internal" @250
    227     "__fncmp" @251
    228224    "__fnexplode" @252
    229225    "__fnexplodefree" @253
     
    334330    "___newthread" @358
    335331    "__nfiles" @359
    336     "___nls_ctype" @360
    337     "__nls_ctype_init" @361
    338     "__nls_init" @362
    339     "___nls_memupr" @363
    340     "__nls_strlwr" @364
    341     "__nls_strupr" @365
    342     "__nls_tolower_init" @366
    343     "__nls_toupper_init" @367
    344332    "___open" @368
    345333    "__openstream" @369
  • trunk/src/emx/src/lib/libc.smak

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r493 r494  
    153153        $(call CP,$^,$(dir $@))
    154154
    155 
    156155# How libc-std.h can be auto-generated.
    157156# Unfortunately, we cannot use c.a to find out all _std_ names since
  • trunk/src/emx/src/lib/mbyte/mbcurmax.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r493 r494  
    1 /* mbcurmax.c (emx+gcc) -- Copyright (c) 1994 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
     4
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    This file contains the _mb_cur_max variable which is the maximal
     8    length of a multibyte character (depends on LC_CTYPE locale setting).
     9    Accessed through MB_CUR_MAX macro defined in <stdlib.h>.
     10*/
    211
    312#include <stdlib.h>
  • trunk/src/emx/src/lib/mbyte/mblen.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* mblen.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Compute the number of bytes comprising the multibyte character pointed
     8    to by s. If s is NULL, the shift state is reset to the initial state.
     9    At most n bytes at s are examined; a multibyte character consisting of
     10    more than n bytes is deemed invalid.
     11
     12    If s is NULL, mblen() returns a non-zero value (if state-dependent encoding
     13    is used) or a zero value (if state-dependent encoding is not used).
     14    If s is not NULL, mblen() returns 0 (if s points to the null character),
     15    the number of bytes comprising the multibyte character pointed to by s
     16    (if there is a valid multibyte character), or -1 (if there is not a valid
     17    multibyte character).
     18
     19    Affected by LC_CTYPE locale setting.
     20
     21    BUGS: Currently shift states between calls to multibyte/widechar
     22    functions are lost.
     23*/
     24
     25#define __INTERNAL_DEFS
    326#include "libc-alias.h"
    4 #include <stdlib.h>
    5 #include <emx/thread.h>
    6 #include <emx/locale.h>
     27#include <sys/locale.h>
    728
    829int _STD(mblen) (const char *s, size_t n)
    930{
    10   struct _thread *tp = _thread ();
    11 
    12   if (s == NULL)
    13     {
    14       if (_cur_mbyte.mode == _MB_SHIFT)
    15         {
    16           tp->_th_mblen_shift = 0;
    17           return 1;             /* State dependency */
    18         }
    19       else
    20         return 0;               /* No state dependency */
    21     }
    22   return _mbtowc (NULL, s, n, &tp->_th_mblen_shift);
     31  int pl;
     32  if (!n)
     33    return -1;
     34  CHK_MBCS_PREFIX (__locale_ctype, *s, pl);
     35  return pl ? pl : -1;
    2336}
  • trunk/src/emx/src/lib/mbyte/mbstowcs.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* mbstowcs.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Convert the null-terminated sequence of multibyte character pointed to
     8    by s to a sequence of wchar_t codes pointed to by pwcs. The multibyte
     9    character sequence starts in the initial shift state. At most n codes
     10    are stored to pwcs. pwcs will be terminated with a code of value zero
     11    if n is big enough.
     12
     13    The shift state of mbtowc() and mblen() is not affected.
     14
     15    mbstowcs() returns the number of codes stored to pwcs (excluding the
     16    terminating zero code) or (size_t)-1 if an invalid multibyte character
     17    is encountered.
     18
     19    Affected by LC_CTYPE locale setting.
     20
     21    BUGS: Currently shift states between calls to multibyte/widechar
     22    functions are lost.
     23*/
     24
     25#define __INTERNAL_DEFS
    326#include "libc-alias.h"
    4 #include <stdlib.h>
    5 #include <limits.h>
    6 #include <emx/locale.h>
     27#include <sys/locale.h>
     28#include <string.h>
    729
    830size_t _STD(mbstowcs) (wchar_t *pwcs, const char *s, size_t n)
    931{
    10   int shift, i;
    11   size_t result;
     32  size_t nonid, sl = strlen (s) + 1, nw = n;
    1233
    13   shift = 0; result = 0;
    14   switch (_cur_mbyte.mode)
    15     {
    16     case _MB_8BITS:
    17       while (*s != 0 && n != 0)
    18         {
    19           pwcs[result++] = (unsigned char)*s++;
    20           --n;
    21         }
    22       break;
     34  if (UniUconvToUcs (__locale_ctype.uconv, (void *)&s, &sl, &pwcs,
     35    &nw, &nonid))
     36    return -1;
    2337
    24     default:
    25       while (*s != 0 && n != 0)
    26         {
    27           i = _mbtowc (pwcs + result, s, MB_LEN_MAX, &shift);
    28           if (i < 1)
    29             return (size_t)-1;
    30           s += i; ++result; --n;
    31         }
    32       break;
    33     }
    34 
    35   if (n != 0)
    36     pwcs[result] = 0;
    37   return result;
     38  return n - nw - 1;
    3839}
  • trunk/src/emx/src/lib/mbyte/mbtowc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* mbtowc.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Convert the multibyte character pointed to by s to a wchar_t code and
     8    store it to pwc. If s is NULL, the shift state is reset to the initial
     9    state. At most n bytes at s are examined; a multibyte character consisting
     10    of more than n bytes is deemed invalid.
     11
     12    The shift state of mblen() is not affected.
     13
     14    If s is NULL, mbtowc() returns a non-zero value (if state-dependent
     15    encoding is used) or a zero value (if state-dependent encoding is not used).
     16    If s is not NULL, mbtowc() returns 0 (if s points to the null character),
     17    the number of bytes comprising the multibyte character pointed to by s
     18    (if there is a valid multibyte character), or -1 (if there is not a valid
     19    multibyte character).
     20
     21    Affected by LC_CTYPE locale setting.
     22
     23    BUGS: Currently shift states between calls to multibyte/widechar
     24    functions are lost.
     25*/
     26
     27#define __INTERNAL_DEFS
    328#include "libc-alias.h"
    4 #include <stdlib.h>
    5 #include <emx/thread.h>
    6 #include <emx/locale.h>
     29#include <sys/locale.h>
     30#include <string.h>
    731
    832int _STD(mbtowc) (wchar_t *pwc, const char *s, size_t n)
    933{
    10   struct _thread *tp = _thread ();
     34  size_t nonid, ni = n, no = 1;
     35  int rc;
    1136
    12   if (s == NULL)
    13     {
    14       if (_cur_mbyte.mode == _MB_SHIFT)
    15         {
    16           tp->_th_mbtowc_shift = 0;
    17           return 1;             /* State dependency */
    18         }
    19       else
    20         return 0;               /* No state dependency */
    21     }
    22   return _mbtowc (pwc, s, n, &tp->_th_mbtowc_shift);
     37  if (!s)
     38    return 0;               /* No state dependency */
     39
     40  rc = UniUconvToUcs (__locale_ctype.uconv, (void *)&s, &ni, &pwc, &no, &nonid);
     41
     42  if ((rc == 0) || (rc == UCONV_E2BIG))
     43    return n - ni;
     44
     45  return -1;
    2346}
  • trunk/src/emx/src/lib/mbyte/wcstombs.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* wcstombs.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Convert the zero-terminated sequence of wchar_t codes at pwcs to a
     8    multibyte character sequence beginning at s. The multibyte character
     9    sequence starts in the initial shift state. At most n bytes are stored.
     10    s will be terminated with a null character if n is big enough.
     11
     12    The shift state of wctomb() is not affected.
     13
     14    wcstombs() returns the number of bytes stored to s (excluding the
     15    terminating null character) or (size_t_t)-1 if a code could not be
     16    counverted.
     17
     18    Affected by LC_CTYPE locale setting.
     19
     20    BUGS: Currently shift states between calls to multibyte/widechar
     21    functions are lost.
     22*/
     23
     24#define __INTERNAL_DEFS
    325#include "libc-alias.h"
    4 #include <stdlib.h>
    5 #include <ctype.h>
    6 #include <emx/locale.h>
     26#include <sys/locale.h>
     27#include <string.h>
    728
    829size_t _STD(wcstombs) (char *s, const wchar_t *pwcs, size_t n)
    930{
    10   size_t result;
    11   wchar_t wc;
    12   int shift, i;
     31  size_t nonid, sl = UniStrlen (pwcs) + 1, nw = n;
    1332
    14   shift = 0; result = 0;
    15   switch (_cur_mbyte.mode)
    16     {
    17     case _MB_8BITS:
    18       while (n != 0 && *pwcs != 0)
    19         {
    20           wc = *pwcs++;
    21           if (wc > 255)         /* wchar_t is unsigned */
    22             return (size_t)-1;
    23           s[result++] = (char)wc;
    24           --n;
    25         }
    26       break;
     33  if (UniUconvFromUcs (__locale_ctype.uconv, (UniChar **)&pwcs, &sl,
     34    (void *)&s, &nw, &nonid))
     35    return -1;
    2736
    28     default:
    29       while (n != 0 && *pwcs != 0)
    30         {
    31           i = _wctomb (s + result, *pwcs++, n, &shift);
    32           if (i < 1)
    33             return (size_t)-1;
    34           result += i; n -= i;
    35         }
    36       break;
    37     }
    38 
    39   /* ANSI X3.159-1989, 4.10.8.2: "Otherwise, the wcstombs function
    40      returns the number of bytes modified, not including a terminating
    41      null character, if any." */
    42 
    43   if (n != 0)
    44     s[result] = 0;
    45   return result;
     37  return n - nw - 1;
    4638}
  • trunk/src/emx/src/lib/mbyte/wctomb.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* wctomb.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Convert the wchar_t code wchar to a multibyte character sequence pointed
     8    to by s.At most MB_CUR_MAX bytes are stored. If s is NULL, the shift state
     9    is reset to the initial state. If wchar is zero, the shift state is the
     10    initial state after return from wctomb().
     11
     12    If s is NULL, wctomb() returns a non-zero value (if state-dependent
     13    encoding is used) or a zero value (if state-dependent encoding is not used).
     14    If s is not NULL, wctomb() returns 0 (if wchar is zero), the number of
     15    bytes comprising the multibyte character stored to s (if conversion is
     16    successful), or -1 (if wchar could not be converted).
     17*/
     18
     19#define __INTERNAL_DEFS
    320#include "libc-alias.h"
     21#include <sys/locale.h>
    422#include <stdlib.h>
    5 #include <limits.h>
    6 #include <emx/thread.h>
    7 #include <emx/locale.h>
    823
    924int _STD(wctomb) (char *s, wchar_t wchar)
    1025{
    11   struct _thread *tp = _thread ();
     26  UniChar *ucs = &wchar;
     27  size_t nonid, ni = 1, no = MB_CUR_MAX;
    1228
    13   if (s == NULL)
    14     {
    15       if (_cur_mbyte.mode == _MB_SHIFT)
    16         {
    17           tp->_th_wctomb_shift = 0;
    18           return 1;             /* State dependency */
    19         }
    20       else
    21         return 0;               /* No state dependency */
    22     }
    23   return _wctomb (s, wchar, MB_LEN_MAX, &tp->_th_wctomb_shift);
     29  if (!s)
     30    return 0;               /* No state dependency */
     31
     32  if (UniUconvFromUcs (__locale_ctype.uconv, &ucs, &ni, (void **)&s, &no, &nonid))
     33    return -1;
     34
     35  return MB_CUR_MAX - no;
    2436}
  • trunk/src/emx/src/lib/misc/abspath.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* abspath.c (emx+gcc) -- Copyright (c) 1992-1998 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
     
    78#include <errno.h>
    89#include <sys/param.h>
    9 #include <sys/nls.h>
    1010#include <emx/syscalls.h>
     11#include <sys/locale.h>
    1112
    1213#define FALSE   0
     
    1718{
    1819  char drive, dir[MAXPATHLEN+1], src_drive, *s, *p;
    19   int i, j, rel, server, trail;
     20  int i, j, rel, server, trail, mbcl;
    2021
    2122  s = alloca (strlen (src) + 1);
     
    7172          while (*s != 0)
    7273            {
    73               if (_nls_is_dbcs_lead ((unsigned char)*s) && s[1] != 0)
     74              if (CHK_MBCS_PREFIX (__locale_ctype, *s, mbcl) && s[1] != 0)
    7475                {
    75                   if (i < sizeof (dir) - 2)
     76                  if (i < sizeof (dir) - mbcl)
    7677                    {
    77                       dir[i++] = s[0];
    78                       dir[i++] = s[1];
     78                      memcpy (dir + i, s, mbcl);
     79                      i += mbcl;
    7980                    }
    80                   s += 2;
     81                  s += mbcl;
    8182                }
    8283              else if (IS_PATH_DELIM (*s))
  • trunk/src/emx/src/lib/misc/defext.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* defext.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    56#include <string.h>
    6 #include <sys/nls.h>
    7 
    8 /* Note that _nls_is_dbcs_lead() returns false for all characters if
    9    _nls_init() has not been called.  In consequence, this function
    10    works properly for SBCS strings even if _nls_init() has not been
    11    called. */
    12 
    13 /* Note: This function is used by emx.dll. */
     7#include <sys/locale.h>
    148
    159#define FALSE   0
     
    1812void _defext (char *dst, const char *ext)
    1913{
    20   int dot, sep;
     14  int dot, sep, mbcl;
    2115
    2216  dot = FALSE; sep = TRUE;
    2317  while (*dst != 0)
    24     if (_nls_is_dbcs_lead ((unsigned char)*dst))
     18    if (CHK_MBCS_PREFIX (__locale_ctype, *dst, mbcl))
    2519      {
    2620        if (dst[1] == 0)        /* Invalid DBCS character */
    2721          return;
    28         dst += 2;
     22        dst += mbcl;
    2923        sep = FALSE;
    3024      }
  • trunk/src/emx/src/lib/misc/dtsort.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    77#include <sys/dirent.h>
    88#include <sys/dirtree.h>
    9 #include <sys/nls.h>
    109
    1110
     
    7372  if (ext2 == NULL && ext1 != NULL)
    7473    return 1;
    75   d = _fncmp (ext1, ext2);
     74  d = strcasecmp (ext1, ext2);
    7675  if (d == 0)
    7776    d = strcmp (ext1, ext2);
     
    8584  int d;
    8685
    87   d = _fncmp (n1->name, n2->name);
     86  d = strcasecmp (n1->name, n2->name);
    8887  if (d == 0)
    8988    d = strcmp (n1->name, n2->name);
  • trunk/src/emx/src/lib/misc/fnmatch.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    11/* fnmatch.c (emx+gcc) -- Copyright (c) 1994-1998 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <string.h>
    56#include <ctype.h>
    67#include <emx/fnmatch.h>
    7 #include <sys/nls.h>
     8#include <sys/locale.h>
    89
    910/* In OS/2 and DOS styles, both / and \ separate components of a path.
     
    2526static const unsigned char *skip_comp_os2 (const unsigned char *src)
    2627{
     28  /* Correct reading: em-be-ce-el :-) */
     29  int mbcl;
    2730  /* Skip characters until hitting a separator or the end of the
    2831     string. */
    2932
    3033  while (!IS_OS2_COMP_END (*src))
    31     if (_nls_is_dbcs_lead (*src) && src[1] != 0)
    32       src += 2;
     34    if (CHK_MBCS_PREFIX (__locale_ctype, *src, mbcl) && src[1] != 0)
     35      src += mbcl;
    3336    else
    3437      ++src;
     
    4649static int has_colon (const unsigned char *p)
    4750{
     51  int mbcl;
     52
    4853  while (*p != 0)
    4954    if (*p == ':')
    5055      return 1;
    51     else if (_nls_is_dbcs_lead (p[0]) && p[1] != 0)
    52       p += 2;
     56    else if (CHK_MBCS_PREFIX (__locale_ctype, p[0], mbcl) && p[1] != 0)
     57      p += mbcl;
    5358    else
    5459      ++p;
     
    7075                           unsigned flags, int has_dot)
    7176{
    72   int rc;
     77  int rc, mbcl;
    7378
    7479  for (;;)
    75     if (_nls_is_dbcs_lead (*mask) && mask[1] != 0)
     80    if (CHK_MBCS_PREFIX (__locale_ctype, *mask, mbcl) && mask[1] != 0)
    7681      {
    77         /* DBCS characters match themselves. */
    78 
    79         if (mask[0] != name[0] || mask[1] != name[1])
     82        if (memicmp (mask, name, mbcl))
    8083          return FNM_NOMATCH;
    81         mask += 2; name += 2;
     84        mask += mbcl; name += mbcl;
    8285      }
    8386    else
     
    122125          if (*name != '.' && !IS_OS2_COMP_END (*name))
    123126            {
    124               if (_nls_is_dbcs_lead (name[0]) && name[1] != 0)
    125                 name += 2;
     127              if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     128                name += mbcl;
    126129              else
    127130                ++name;
     
    148151              if (*name == '.' && (flags & _FNM_STYLE_MASK) == _FNM_DOS)
    149152                return FNM_NOMATCH;
    150               if (_nls_is_dbcs_lead (name[0]) && name[1] != 0)
    151                 name += 2;
     153              if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     154                name += mbcl;
    152155              else
    153156                ++name;
     
    172175          if (flags & _FNM_IGNORECASE)
    173176            {
    174               if (_nls_tolower (*mask) != _nls_tolower (*name))
     177              if (tolower (*mask) != tolower (*name))
    175178                return FNM_NOMATCH;
    176179            }
     
    197200{
    198201  const unsigned char *s;
     202  int mbcl;
    199203
    200204  switch (flags & _FNM_STYLE_MASK)
     
    208212      s = name;
    209213      while (!IS_OS2_COMP_END (*s) && *s != '.')
    210         if (_nls_is_dbcs_lead (s[0]) && s[1] != 0)
    211           s += 2;
     214        if (CHK_MBCS_PREFIX (__locale_ctype, s[0], mbcl) && s[1] != 0)
     215          s += mbcl;
    212216        else
    213217          ++s;
     
    245249  char invert, matched;
    246250  const unsigned char *start;
    247   int rc;
     251  int rc, mbcl;
    248252
    249253  for (;;)
    250     if (_nls_is_dbcs_lead (*mask))
     254    if (CHK_MBCS_PREFIX (__locale_ctype, *mask, mbcl))
    251255      {
    252         /* DBCS characters match themselves. */
    253 
    254         if (mask[0] != name[0] || mask[1] != name[1])
     256        if (memicmp (mask, name, mbcl))
    255257          return FNM_NOMATCH;
    256         mask += 2; name += 2;
     258        mask += mbcl; name += mbcl;
    257259      }
    258260    else
     
    285287            return FNM_NOMATCH;
    286288          ++mask;
    287           if (_nls_is_dbcs_lead (name[0]) && name[1] != 0)
    288             name += 2;
     289          if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     290            name += mbcl;
    289291          else
    290292            ++name;
     
    313315              if ((flags & FNM_PATHNAME) && IS_UNIX_COMP_SEP (*name))
    314316                return FNM_NOMATCH;
    315               if (_nls_is_dbcs_lead (name[0]) && name[1] != 0)
    316                 name += 2;
     317              if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     318                name += mbcl;
    317319              else
    318320                ++name;
     
    363365              ++mask; invert = 1;
    364366            }
    365           else if (_nls_is_dbcs_lead (*name))
     367          else if (IS_MBCS_PREFIX (__locale_ctype, *name))
    366368            {
    367369              /* DBCS characters can only match inverted sets. */
     
    382384
    383385              c1 = *mask++;
    384               if (_nls_is_dbcs_lead (c1))
     386              if (IS_MBCS_PREFIX (__locale_ctype, c1))
    385387                return _FNM_ERR; /* DBCS characters not supported in sets */
    386388              if (!(flags & FNM_NOESCAPE) && c1 == '\\')
     
    404406                    break;
    405407                  c2 = *mask++;
    406                   if (_nls_is_dbcs_lead (c2))
     408                  if (IS_MBCS_PREFIX (__locale_ctype, c2))
    407409                    return _FNM_ERR; /* DBCS chars not supported in sets */
    408410                }
     
    437439              if (*name != 0)
    438440                {
    439                   if (_nls_is_dbcs_lead (name[0]) && name[1] != 0)
    440                     name += 2;
     441                  if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     442                    name += mbcl;
    441443                  else
    442444                    ++name;
     
    467469          if (flags & _FNM_IGNORECASE)
    468470            {
    469               if (_nls_tolower (*mask) != _nls_tolower (*name))
     471              if (tolower (*mask) != tolower (*name))
    470472                return FNM_NOMATCH;
    471473            }
     
    504506      if (!(flags & _FNM_IGNORECASE))
    505507        return FNM_NOMATCH;
    506       if (_nls_tolower (m_drive) != _nls_tolower (n_drive))
     508      if (tolower (m_drive) != tolower (n_drive))
    507509        return FNM_NOMATCH;
    508510    }
  • trunk/src/emx/src/lib/misc/fnslashi.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* fnslashi.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    5 #include <sys/nls.h>
     6#include <sys/locale.h>
    67
    78char *_fnslashify (char *name)
    89{
    910  char *p;
     11  int mbcl;
    1012
    1113  p = name;
    1214  while (*p != 0)
    13     if (_nls_is_dbcs_lead ((unsigned char)*p) && p[1] != 0)
    14       p += 2;
     15    if (CHK_MBCS_PREFIX (__locale_ctype, *p, mbcl) && p[1] != 0)
     16      p += mbcl;
    1517    else if (*p == '\\')
    1618      *p++ = '/';
  • trunk/src/emx/src/lib/misc/getext.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* getext.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    56#include <string.h>
    6 #include <sys/nls.h>
    7 
    8 /* Note that _nls_is_dbcs_lead() returns false for all characters if
    9    _nls_init() has not been called.  In consequence, this function
    10    works properly for SBCS strings even if _nls_init() has not been
    11    called. */
     7#include <sys/locale.h>
    128
    139#define FALSE   0
     
    1612char *_getext (const char *path)
    1713{
    18   int sep;
     14  int sep, mbcl;
    1915  const char *dotp;
    2016
    2117  sep = TRUE; dotp = NULL;
    2218  while (*path != 0)
    23     if (_nls_is_dbcs_lead ((unsigned char)*path))
     19    if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
    2420      {
    2521        if (path[1] == 0)       /* Invalid DBCS character */
    2622          break;
    27         path += 2;
     23        path += mbcl;
    2824        sep = FALSE;
    2925      }
  • trunk/src/emx/src/lib/misc/getname.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    11/* getname.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    56#include <string.h>
    6 #include <sys/nls.h>
    7 
    8 /* Note that _nls_is_dbcs_lead() returns false for all characters if
    9    _nls_init() has not been called.  In consequence, this function
    10    works properly for SBCS strings even if _nls_init() has not been
    11    called. */
    12 
    13 /* Note: This function is used by emx.dll. */
     7#include <sys/locale.h>
    148
    159char *_getname (const char *path)
    1610{
    1711  const char *p;
     12  int mbcl;
    1813
    1914  p = path;
    2015  while (*path != 0)
    21     if (_nls_is_dbcs_lead ((unsigned char)*path))
     16    if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
    2217      {
    2318        if (path[1] == 0)       /* Invalid DBCS character */
    2419          break;
    25         path += 2;
     20        path += mbcl;
    2621      }
    2722    else
  • trunk/src/emx/src/lib/misc/makepath.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* makepath.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    5 #include <sys/nls.h>
     6#include <sys/locale.h>
     7#include <string.h>
    68
    79void _makepath (char *dst, const char *drive, const char *dir,
    810                const char *fname, const char *ext)
    911{
    10   int n;
     12  int n, mbcl;
    1113  char slash, last;
    1214
     
    2224      while (n < _MAX_PATH - 1 && *dir != 0)
    2325        {
    24           if (_nls_is_dbcs_lead ((unsigned char)*dir))
     26          if (CHK_MBCS_PREFIX (__locale_ctype, *dir, mbcl))
    2527            {
    2628              if (dir[1] == 0)
    2729                ++dir;          /* Invalid DBCS character */
    28               else if (n + 1 < _MAX_PATH - 1)
     30              else if (n + mbcl < _MAX_PATH)
    2931                {
    30                   dst[n++] = *dir++;
    31                   dst[n++] = *dir++;
     32                  memcpy (dst, dir, mbcl);
     33                  dst += mbcl; dir += mbcl;
    3234                }
    3335              last = 0;
  • trunk/src/emx/src/lib/misc/perror.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    44#include <stdio.h>
    55#include <stdlib.h>
     6#include <sys/errno.h>
    67
    78void _STD(perror) (const char *string)
  • trunk/src/emx/src/lib/misc/remext.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* remext.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    56#include <string.h>
    6 #include <sys/nls.h>
    7 
    8 /* Note that _nls_is_dbcs_lead() returns false for all characters if
    9    _nls_init() has not been called.  In consequence, this function
    10    works properly for SBCS strings even if _nls_init() has not been
    11    called. */
     7#include <sys/locale.h>
    128
    139#define FALSE   0
     
    1612void _remext (char *path)
    1713{
    18   int dot, sep;
     14  int dot, sep, mbcl;
    1915  char *dotp;
    2016
    2117  dot = FALSE; sep = TRUE; dotp = NULL;
    2218  while (*path != 0)
    23     if (_nls_is_dbcs_lead ((unsigned char)*path))
     19    if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
    2420      {
    2521        if (path[1] == 0)       /* Invalid DBCS character */
    2622          break;
    27         path += 2;
     23        path += mbcl;
    2824        sep = FALSE;
    2925      }
  • trunk/src/emx/src/lib/misc/splitpat.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r493 r494  
    11/* splitpath.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
    22
     3#define __INTERNAL_DEFS
    34#include "libc-alias.h"
    45#include <stdlib.h>
    56#include <string.h>
    6 #include <sys/nls.h>
    7 
    8 #define min(a,b) (((a) < (b)) ? (a) : (b))
     7#include <sys/param.h>
     8#include <sys/locale.h>
    99
    1010void _splitpath (const char *src, char *drive, char *dir, char *fname,
    1111                 char *ext)
    1212{
    13   int i, j;
     13  int i, j, mbcl;
    1414
    1515  i = 0;
    1616  while (src[i] != 0)
    17     if (_nls_is_dbcs_lead ((unsigned char)src[i]))
     17    if (CHK_MBCS_PREFIX (__locale_ctype, src[i], mbcl))
    1818      {
    1919        if (src[i+1] == 0)      /* Invalid DBCS character */
    2020          break;
    21         i += 2;
     21        i += mbcl;
    2222      }
    2323    else if (src[i] == ':')
     
    2929    {
    3030      if (drive != NULL)
    31         _strncpy (drive, src, min (i+2, _MAX_DRIVE));
     31        _strncpy (drive, src, MIN (i+2, _MAX_DRIVE));
    3232      src += i + 1;
    3333    }
     
    3737  i = 0; j = 0;
    3838  while (src[j] != 0)
    39     if (_nls_is_dbcs_lead ((unsigned char)src[j]))
     39    if (CHK_MBCS_PREFIX (__locale_ctype, src[j], mbcl))
    4040      {
    4141        if (src[j+1] == 0)      /* Invalid DBCS character */
    4242          break;
    43         j += 2;
     43        j += mbcl;
    4444      }
    4545    else if (src[j] == '/' || src[j] == '\\')
     
    4949
    5050  if (dir != NULL)
    51     _strncpy (dir, src, min (_MAX_DIR, i + 1));
     51    _strncpy (dir, src, MIN (_MAX_DIR, i + 1));
    5252  src += i;
    5353 
    5454  i = 0; j = 0;
    5555  while (src[j] != 0)
    56     if (_nls_is_dbcs_lead ((unsigned char)src[j]))
     56    if (CHK_MBCS_PREFIX (__locale_ctype, src[j], mbcl))
    5757      {
    5858        if (src[j+1] == 0)      /* Invalid DBCS character */
    5959          break;
    60         j += 2;
     60        j += mbcl;
    6161      }
    6262    else if (src[j] == '.')
     
    6868    i = j;
    6969  if (fname != NULL)
    70     _strncpy (fname, src, min (_MAX_FNAME, i + 1));
     70    _strncpy (fname, src, MIN (_MAX_FNAME, i + 1));
    7171  src += i;
    7272 
  • trunk/src/emx/src/lib/process/beginthr.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    2525  1,                            /* _th_rand */
    2626  NULL,                         /* _th_store */
    27   0,                            /* _th_mblen_shift */
    28   0,                            /* _th_mbtowc_shift */
    29   0,                            /* _th_wctomb_shift */
    3027  "",                           /* _th_vollabel */
    3128  "",                           /* _th_error */
  • trunk/src/emx/src/lib/str/memicmp.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* memicmp.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Compare two memory areas case-insensitively.
     8*/
     9
     10#define __INTERNAL_DEFS
    311#include "libc-alias.h"
    4 #include <string.h>
    5 #include <ctype.h>
     12#include <sys/locale.h>
     13#include <stddef.h>
    614
    7 int _STD(memicmp) (const void *s1, const void *s2, size_t n)
     15int _STD(memicmp) (const void *m1, const void *m2, size_t len)
    816{
    9   size_t i;
    10   int d;
     17  unsigned char c1;
     18  unsigned char c2;
     19  const unsigned char *s1 = (const unsigned char *)m1;
     20  const unsigned char *s2 = (const unsigned char *)m2;
    1121
    12   for (i = 0; i < n; ++i)
     22  if (!len)
     23    return 0;
     24
     25  c1 = *s1; c2 = *s2;
     26
     27  if (__locale_ctype.mbcs)
     28    /* MBCS case. One additional memory lookup per character. */
     29    for (;;)
    1330    {
    14       d = tolower (((unsigned char *)s1)[i])
    15         - tolower (((unsigned char *)s2)[i]);
    16       if (d != 0)
    17         {
    18           if (d > 0)
    19             return 1;
    20           else
    21             return -1;
    22         }
    23     }
    24   return 0;
     31      int d;
     32
     33      if (IS_MBCS_PREFIX (__locale_ctype, c1)
     34       || IS_MBCS_PREFIX (__locale_ctype, c2))
     35      {
     36        /* Translate unknown characters to Unicode, and compare them...
     37           We perhaps should convert them back to MBCS, but anyway it is
     38           not defined how memicmp should work on multi-byte characters... */
     39        UniChar uc1, uc2;
     40        int c1l, c2l;
     41        if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, len, &uc1)))
     42          uc1 = c1, c1l = 1;
     43        else
     44          uc1 = UniTransLower (__locale_ctype.locale, uc1);
     45        if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, len, &uc2)))
     46          uc2 = c2, c2l = 1;
     47        else
     48          uc2 = UniTransLower (__locale_ctype.locale, uc2);
     49        d = uc1 - uc2;
     50        c1l--; c2l--;
     51        s1 += c1l; s2 += c2l;
     52        len -= c1l;
     53      }
     54      else
     55        d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     56      if (d)
     57        return d;
     58      if (!--len)
     59        return 0;
     60      c1 = *++s1;
     61      c2 = *++s2;
     62    } /* endfor */
     63  else
     64    /* SBCS case (faster). */
     65    for (;;)
     66    {
     67      int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     68      if (d)
     69        return d;
     70      if (!--len)
     71        return 0;
     72      c1 = *++s1;
     73      c2 = *++s2;
     74    } /* endfor */
     75
     76  /* This point never reached */
    2577}
  • trunk/src/emx/src/lib/str/strcoll.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* strcoll.c (emx+gcc) -- Copyright (c) 1994-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Compare two strings, interpreting every character as appropiate
     8    to the LC_COLLATE category of the locale. The result of the comparison
     9    is always in alphabetical order of selected language.
     10*/
     11
     12#define __INTERNAL_DEFS
    313#include "libc-alias.h"
     14#include <sys/locale.h>
     15#include <alloca.h>
    416#include <string.h>
    517
    6 /* Ignore the current locale for now. */
     18int _STD(strcoll) (const char *s1, const char *s2)
     19{
     20  int i, d;
     21  unsigned char c1 = *s1;
     22  unsigned char c2 = *s2;
    723
    8 int _STD(strcoll) (const char *string1, const char *string2)
    9 {
    10   return strcmp (string1, string2);
     24  if (__locale_collate.mbcs)
     25    /* MBCS case. We compare the strings as usual, but as soon as we
     26       encounter a MBCS character we translate the rests of the strings
     27       to Unicode and continue comparation in Unicode. */
     28    for (;;)
     29    {
     30      if (IS_MBCS_PREFIX (__locale_collate, c1)
     31       || IS_MBCS_PREFIX (__locale_collate, c2))
     32      {
     33        /* Allright, we found a MBCS character. */
     34        UniChar *ucs [2];
     35        const char *sbcs [2] = { s1, s2 };
     36
     37        /* I can't imagine X bytes to convert into more
     38           than X unicode characters... */
     39        for (i = 0; i < 2; i++)
     40        {
     41          void *inbuf = (void *)sbcs [i];
     42          size_t sl = strlen (sbcs [i]) + 1;
     43          size_t nonid, in_left = sl, out_left = sl;
     44          UniChar *outbuf = ucs [i] = alloca (sl * sizeof (UniChar));
     45
     46          if (UniUconvToUcs (__locale_collate.uconv, &inbuf, &in_left, &outbuf,
     47                &out_left, &nonid))
     48          {
     49            /* Oops, something bad happened (invalid character code). Suppose
     50               the string that caused the fault is "less" than the other */
     51            return i * 2 - 1;
     52          }
     53        }
     54
     55        /* Okay, now we have two Unicode strings. Compare them. */
     56        return UniStrcoll (__locale_collate.locale, ucs [0], ucs [1]);
     57      }
     58
     59      d = __locale_collate.weight [c1] - __locale_collate.weight [c2];
     60      if (d || !c1 || !c2)
     61        return d;
     62      c1 = *++s1;
     63      c2 = *++s2;
     64    } /* endfor */
     65  else
     66    /* SBCS case (faster). */
     67    for (;;)
     68    {
     69      d = __locale_collate.weight [c1] - __locale_collate.weight [c2];
     70      if (d || !c1 || !c2)
     71        return d;
     72      c1 = *++s1;
     73      c2 = *++s2;
     74    } /* endfor */
     75
     76  /* This point never achieved */
    1177}
  • trunk/src/emx/src/lib/str/strerror.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r493 r494  
    55#include <string.h>
    66#include <emx/thread.h>
     7#include <sys/errno.h>
    78
    89char *_STD(strerror) (int errnum)
  • trunk/src/emx/src/lib/str/stricmp.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* stricmp.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Compare two strings case-insensitively.
     8*/
     9
     10#define __INTERNAL_DEFS
    311#include "libc-alias.h"
     12#include <sys/locale.h>
     13#include <alloca.h>
    414#include <string.h>
    5 #include <ctype.h>
    615
    7 int _STD(stricmp) (const char *string1, const char *string2)
     16static int __strnlen (const char *s, int maxlen)
    817{
    9   int d;
     18  int sl = 0;
     19  while (*s++ && maxlen--)
     20    sl++;
     21  return sl;
     22}
    1023
    11   for (;;)
     24int _STD(stricmp) (__const__ char *s1, __const__ char *s2)
     25{
     26  unsigned char c1 = *s1;
     27  unsigned char c2 = *s2;
     28
     29  if (__locale_ctype.mbcs)
     30    /* MBCS case. One additional memory lookup per character. */
     31    for (;;)
    1232    {
    13       d = tolower ((unsigned char)*string1)
    14         - tolower ((unsigned char)*string2);
    15       if (d != 0 || *string1 == 0 || *string2 == 0)
     33      int d;
     34
     35      if (IS_MBCS_PREFIX (__locale_ctype, c1)
     36       || IS_MBCS_PREFIX (__locale_ctype, c2))
     37      {
     38        /* Translate unknown characters to Unicode, and compare them...
     39           We perhaps should convert them back to MBCS, but anyway it is
     40           not defined how memicmp should work on multi-byte characters... */
     41        UniChar uc1, uc2;
     42        int c1l, c2l;
     43        if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, __strnlen (s1, 3), &uc1)))
     44          uc1 = c1, c1l = 1;
     45        else
     46          uc1 = UniTransLower (__locale_ctype.locale, uc1);
     47        if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, __strnlen (s2, 3), &uc2)))
     48          uc2 = c2, c2l = 1;
     49        else
     50          uc2 = UniTransLower (__locale_ctype.locale, uc2);
     51        d = uc1 - uc2;
     52        s1 += c1l - 1;
     53        s2 += c2l - 1;
     54      }
     55      else
     56        d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     57
     58      if (d || !c1 || !c2)
    1659        return d;
    17       ++string1; ++string2;
    18     }
     60      c1 = *++s1;
     61      c2 = *++s2;
     62    } /* endfor */
     63  else
     64    /* SBCS case (faster). */
     65    for (;;)
     66    {
     67      int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     68      if (d || !c1 || !c2)
     69        return d;
     70      c1 = *++s1;
     71      c2 = *++s2;
     72    } /* endfor */
     73
     74  /* This point never reached */
    1975}
  • trunk/src/emx/src/lib/str/strlwr.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* strlwr.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Lowercase an ASCIIZ string.
     8*/
     9
     10#define __INTERNAL_DEFS
    311#include "libc-alias.h"
    4 #include <string.h>
    5 #include <ctype.h>
     12#include <sys/locale.h>
     13
     14static int __uni_strlwr (UniChar *ucs, void *arg)
     15{
     16  UniChar *c;
     17  (void)arg;
     18  for (c = ucs; *c; c++)
     19    *c = UniTransLower (__locale_ctype.locale, *c);
     20  return 1;
     21}
    622
    723char *_STD(strlwr) (char *string)
    824{
    9   unsigned char *p;
     25  unsigned char c;
     26  unsigned char *s = (unsigned char *)string;
    1027
    11   for (p = (unsigned char *)string; *p != 0; ++p)
    12     *p = (unsigned char)tolower (*p);
     28  if (__locale_ctype.mbcs)
     29  {
     30    while ((c = *s))
     31    {
     32      if (IS_MBCS_PREFIX (__locale_ctype, c))
     33      {
     34        /* Allright, we encountered a MBCS character. Convert everything
     35           until the end to Unicode, do the work in Unicode and then
     36           convert back to MBCS. */
     37        __do_Unicode (__locale_ctype.uconv, s, s, __uni_strlwr);
     38        break;
     39      }
     40      *s++ = __locale_ctype.locase [c];
     41    }
     42  }
     43  else
     44    while ((c = *s))
     45      *s++ = __locale_ctype.locase [c];
     46
    1347  return string;
    1448}
  • trunk/src/emx/src/lib/str/strnicmp.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* strnicmp.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Compare at most 'len' characters from two zero-terminated strings
     8    case-insensitively.
     9*/
     10
     11#define __INTERNAL_DEFS
    312#include "libc-alias.h"
    4 #include <string.h>
    5 #include <ctype.h>
     13#include <stddef.h>
     14#include <sys/locale.h>
    615
    7 int _STD(strnicmp) (const char *string1, const char *string2, size_t count)
     16int _STD(strnicmp) (__const__ char *s1, __const__ char *s2, size_t len)
    817{
    9   int d;
     18  unsigned char c1;
     19  unsigned char c2;
    1020
    11   while (count != 0)
     21  if (!len)
     22    return 0;
     23
     24  c1 = *s1; c2 = *s2;
     25
     26  if (__locale_ctype.mbcs)
     27    /* MBCS case. One additional memory lookup per character. */
     28    for (;;)
    1229    {
    13       d = tolower ((unsigned char)*string1)
    14         - tolower ((unsigned char)*string2);
    15       if (d != 0 || *string1 == 0 || *string2 == 0)
     30      int d;
     31
     32      if (IS_MBCS_PREFIX (__locale_ctype, c1)
     33       || IS_MBCS_PREFIX (__locale_ctype, c2))
     34      {
     35        /* Translate unknown characters to Unicode, and compare them...
     36           We perhaps should convert them back to MBCS, but anyway it is
     37           not defined how memicmp should work on multi-byte characters... */
     38        UniChar uc1, uc2;
     39        int c1l, c2l;
     40        if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, len, &uc1)))
     41          uc1 = c1, c1l = 1;
     42        else
     43          uc1 = UniTransLower (__locale_ctype.locale, uc1);
     44        if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, len, &uc2)))
     45          uc2 = c2, c2l = 1;
     46        else
     47          uc2 = UniTransLower (__locale_ctype.locale, uc2);
     48        d = uc1 - uc2;
     49        c1l--; c2l--;
     50        s1 += c1l; s2 += c2l;
     51        len -= c1l;
     52      }
     53      else
     54        d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     55      if (d || !c1 || !c2)
    1656        return d;
    17       ++string1; ++string2;
    18       --count;
    19     }
    20   return 0;
     57      if (!--len)
     58        return 0;
     59      c1 = *++s1;
     60      c2 = *++s2;
     61    } /* endfor */
     62  else
     63    /* SBCS case (faster). */
     64    for (;;)
     65    {
     66      int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     67      if (d || !c1 || !c2)
     68        return d;
     69      if (!--len)
     70        return 0;
     71      c1 = *++s1;
     72      c2 = *++s2;
     73    } /* endfor */
     74
     75  /* This point never achieved */
    2176}
  • trunk/src/emx/src/lib/str/strupr.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* strupr.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Uppercase an ASCIIZ string.
     8*/
     9
     10#define __INTERNAL_DEFS
    311#include "libc-alias.h"
    4 #include <string.h>
    5 #include <ctype.h>
     12#include <sys/locale.h>
     13
     14static int __uni_strupr (UniChar *ucs, void *arg)
     15{
     16  UniChar *c;
     17  (void)arg;
     18  for (c = ucs; *c; c++)
     19    *c = UniTransUpper (__locale_ctype.locale, *c);
     20  return 1;
     21}
    622
    723char *_STD(strupr) (char *string)
    824{
    9   unsigned char *p;
     25  unsigned char c;
     26  unsigned char *s = (unsigned char *)string;
    1027
    11   for (p = (unsigned char *)string; *p != 0; ++p)
    12       *p = (unsigned char)toupper (*p);
     28  if (__locale_ctype.mbcs)
     29  {
     30    while ((c = *s))
     31    {
     32      if (IS_MBCS_PREFIX (__locale_ctype, c))
     33      {
     34        /* Allright, we encountered a MBCS character. Convert everything
     35           until the end to Unicode, do the work in Unicode and then
     36           convert back to MBCS. */
     37        __do_Unicode (__locale_ctype.uconv, s, s, __uni_strupr);
     38        break;
     39      }
     40      *s++ = __locale_ctype.upcase [c];
     41    }
     42  }
     43  else
     44    while ((c = *s))
     45      *s++ = __locale_ctype.upcase [c];
     46
    1347  return string;
    1448}
  • trunk/src/emx/src/lib/str/strxfrm.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r493 r494  
    1 /* strxfrm.c (emx+gcc) -- Copyright (c) 1994-1995 by Eberhard Mattes */
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 2003 InnoTek Systemberatung GmbH
    24
     5    For conditions of distribution and use, see the file COPYING.
     6
     7    Transform a string so that the resulting string is suitable for
     8    comparison with strcmp() and the comparison results will use the
     9    alphabetic order in conformance to currently selected locale.
     10*/
     11
     12#define __INTERNAL_DEFS
    313#include "libc-alias.h"
    4 #include <string.h>
     14#include <sys/locale.h>
     15#include <stddef.h>
    516
    6 /* Ignore the current locale for now. */
     17struct __strxfrm_arg
     18{
     19  char *out;
     20  size_t size;
     21};
    722
    8 size_t _STD(strxfrm) (char *string1, const char *string2, size_t count)
     23static int __uni_strxfrm (UniChar *ucs, void *arg)
    924{
    10   size_t result;
     25  struct __strxfrm_arg *x = (struct __strxfrm_arg *)arg;
    1126
    12   result = 0;
    13   while (*string2 != 0)
     27  /* BUG WARNING!
     28   * As far as I've observed Unicode DLL has a bug that UniStrxfrm returns
     29   * one character less than it really fills in the buffer. I haven't
     30   * implemented any workaround for that first because it can be fixed
     31   * in the future and second because the information at the end of the
     32   * buffer seems very seldom really needed. UniStrxfrm generates a lot
     33   * of output, and every character in the input buffer generates three
     34   * characters in the output buffer: one wchar_t and two bytes that
     35   * seems to be related to character type (e.g. similar to character
     36   * flags isXXX() works with).
     37   */
     38
     39  size_t rs = UniStrxfrm (__locale_collate.locale, (UniChar *)x->out,
     40    ucs, x->size);
     41  /* rs is in UniChar's without trailing zero */
     42  rs *= sizeof (UniChar);
     43  if (rs < x->size)
     44  {
     45    /* The string returned by Unicode API often contain zero characters
     46       (in the top or bottom 8 bits of a Unicode character).
     47       This is inappropiate for MBCS strings, so we increment all
     48       character codes by one except code 0xff (which is very seldom
     49       encountered). There is no other way to represent a Unicode
     50       xfrm'ed string as a MBCS string, alas. */
     51
     52    int i;
     53    for (i = 0; i < rs; i++)
     54      if (x->out [i] != -1)
     55        x->out [i]++;
     56    x->out [rs] = 0;
     57  }
     58  x->size = rs + 1; /* We need space for trailing zero too */
     59  return 0;
     60}
     61
     62/* Copy s2 to s1, applying the collate transform. */
     63size_t _STD(strxfrm) (char *s1, const char *s2, size_t size)
     64{
     65  unsigned char c;
     66  size_t ret = 1; /* We need at least space for trailing zero */
     67
     68  if (__locale_collate.mbcs)
     69  {
     70    /* When using MBCS codepaes, we will convert the entire string to
     71       Unicode and then apply the UniStrxfrm() function. The output strings
     72       can be much longer than the original in this case, but if user program
     73       is correctly written, it will work since strxfrm will return the
     74       required output string length. */
     75    struct __strxfrm_arg x;
     76    x.out = s1;
     77    x.size = size / sizeof (UniChar);
     78    __do_Unicode (__locale_collate.uconv, (char *)s2, &x, __uni_strxfrm);
     79    return x.size;
     80  }
     81
     82  while ((c = *s2++))
     83  {
     84    if (size)
    1485    {
    15       if (count != 0)
    16         {
    17           *string1++ = *string2;
    18           --count;
    19         }
    20       ++result;
    21       ++string2;
     86      *s1++ = __locale_collate.weight [c];
     87      size--;
    2288    }
    23   if (count != 0)
    24     *string1 = 0;
    25   return result;
     89    ret++;
     90  }
     91
     92  /* Append trailing zero, if there is space. */
     93  if (size)
     94    *s1 = 0;
     95
     96  return ret;
    2697}
  • trunk/src/emx/src/lib/time/gmtime.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    66#include <emx/thread.h>
    77#include <emx/time.h>
    8 
    9 struct tm *_STD(gmtime) (const time_t *t)
    10 {
    11   struct _thread *tp = _thread ();
    12   return _gmtime (&tp->_th_gmtime_buf, t);
    13 }
    148
    159struct tm *_gmtime (struct tm *dst, const time_t *t)
     
    6054  return dst;
    6155}
     56
     57struct tm *_STD(gmtime) (const time_t *t)
     58{
     59  struct _thread *tp = _thread ();
     60  return _gmtime (&tp->_th_gmtime_buf, t);
     61}
  • trunk/src/emx/src/lib/time/strftime.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* strftime.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
    2 
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 1992-1996 by Eberhard Mattes
     4    Copyright (c) 2003 InnoTek Systemberatung GmbH
     5
     6    For conditions of distribution and use, see the file COPYING.
     7
     8    Format time. The output string is written to the array of size characters
     9    pointed to by string, including the terminating null character. Like
     10    sprintf(), strftime() copies the string pointed to by format to the
     11    array pointed to by string, replacing format specifications with formatted
     12    data from t. Ordinary characters are copied unmodified.
     13
     14    On success, strftime() returns the number of characters copied to the
     15    array pointed to by string, excluding the terminating null character.
     16    On failure (size exceeded), strftime() returns 0.
     17*/
     18
     19#define __INTERNAL_DEFS
    320#include "libc-alias.h"
    421#include <stdlib.h>
     
    623#include <time.h>
    724#include <limits.h>
    8 #include <emx/locale.h>
     25#include <sys/locale.h>
    926#include <emx/time.h>
    10 
    11 static int ins (char *string, size_t *n, size_t size, const char *s,
    12     size_t len);
    13 static int num2 (char *string, size_t *n, size_t size, int x);
    14 static int num3 (char *string, size_t *n, size_t size, int x);
    15 static int week (const struct tm *t, int first);
    16 
    17 #define INS(STR,LEN) if (!ins (string, &n, size, (STR), (LEN))) return 0;
    18 #define NUM2(X) if (!num2 (string, &n, size, (X))) return 0;
    19 #define NUM3(X) if (!num3 (string, &n, size, (X))) return 0;
     27#include <sys/builtin.h>
     28
     29#define INS(STR) \
     30  if (!(i = ins (string, size, STR))) \
     31    return 0; \
     32  else \
     33    string += i, size -= i
     34#define NUM2(X) \
     35  if (!(i = num2 (string, size, X, minlen))) \
     36    return 0; \
     37  else \
     38    string += i, size -= i
     39#define NUM3(X) \
     40  if (!(i = num3 (string, size, X, minlen))) \
     41    return 0; \
     42  else \
     43    string += i, size -= i
    2044#define FMT(F) \
    21     i = strftime (string + n, size - n, (F), t); \
    22     if (i == 0) \
    23       return 0; \
    24     else \
    25       n += i;
     45  if (!(i = strftime (string, size, F, t))) \
     46    return 0; \
     47  else \
     48    string += i, size -= i
    2649#define CHR(C) \
    27     if (n < size) \
    28       string[n++] = C; \
    29     else \
    30       return 0;
    31 
    32 
    33 static int ins (char *string, size_t *n, size_t size, const char *s,
    34                 size_t len)
    35 {
    36   size_t i;
    37 
    38   i = *n;
    39   if (len < size - i)
    40     {
    41       memcpy (string + i, s, len);
    42       *n += len;
    43       return 1;
    44     }
    45   else
     50  if (!size) \
     51    return 0; \
     52  else \
     53    *string++ = C, size--
     54
     55static size_t ins (char *string, size_t size, const char *s)
     56{
     57  size_t len = strlen (s);
     58
     59  if (len >= size)
    4660    return 0;
    47 }
    48 
    49 
    50 static int num2 (char *string, size_t *n, size_t size, int x)
    51 {
    52   int i;
    53 
    54   i = *n;
    55   if (2 < size - i)
    56     {
    57       string[i++] = (char)('0' + (x / 10) % 10);
    58       string[i++] = (char)('0' + (x % 10));
    59       *n = i;
    60       return 1;
    61     }
    62   else
     61
     62  memcpy (string, s, len);
     63  return len;
     64}
     65
     66static size_t num2 (char *string, size_t size, int x, unsigned char minlen)
     67{
     68  char *orgstring = string;
     69  long r;
     70
     71  if (size < 2)
    6372    return 0;
    64 }
    65 
    66 
    67 static int num3 (char *string, size_t *n, size_t size, int x)
    68 {
    69   int i;
    70 
    71   i = *n;
    72   if (3 < size - i)
    73     {
    74       string[i++] = (char)('0' + (x / 100) % 10);
    75       string[i++] = (char)('0' + (x / 10) % 10);
    76       string[i++] = (char)('0' + (x % 10));
    77       *n = i;
    78       return 1;
    79     }
    80   else
     73
     74  if (x < 0)
     75    x = 0;
     76
     77  x = __ldivmod (x, 10, &r);
     78  if (x > 9)
     79    x = x % 10;
     80
     81  if (minlen > 1 || x > 0)
     82    *string++ = x + '0';
     83  *string++ = r + '0';
     84  return string - orgstring;
     85}
     86
     87static size_t num3 (char *string, size_t size, int x, unsigned char minlen)
     88{
     89  char *orgstring = string;
     90  long r1, r2;
     91
     92  if (size < 3)
    8193    return 0;
    82 }
    83 
     94
     95  if (x < 0)
     96    x = 0;
     97
     98  x = __ldivmod (x, 10, &r1);
     99  x = __ldivmod (x, 10, &r2);
     100  if (x > 9)
     101    x = x % 10;
     102
     103  if (minlen >= 3 || x > 0)
     104    *string++ = x + '0', minlen = 2;
     105  if (minlen >= 2 || r2 > 0)
     106    *string++ = r2 + '0';
     107  *string++ = r1 + '0';
     108  return string - orgstring;
     109}
    84110
    85111static int week (const struct tm *t, int first)
     
    94120}
    95121
    96 
    97122size_t _STD(strftime) (char *string, size_t size, const char *format,
    98123  const struct tm *t)
    99124{
    100   size_t i, n;
    101   char *p, tmp[40];
    102   unsigned char c;
    103   int mbn, shift;
     125  size_t i;
     126  unsigned char c, minlen;
     127  char *orgstring = string;
    104128
    105129  if (!_tzset_flag) tzset ();
    106   shift = 0; n = 0;
     130
    107131  while ((c = *format) != 0)
     132  {
     133    if (c == '%')
    108134    {
    109       if (c == '%')
    110         {
    111           ++format; p = NULL;
    112           switch (*format)
    113             {
    114             case 0:
    115             case '%':
    116               CHR ('%');
    117               if (*format == 0)
    118                 --format;
    119               break;
    120             case 'a':
    121               p = _cur_lcf_time.wdays1[t->tm_wday];
    122               INS (p, strlen (p));
    123               break;
    124             case 'A':
    125               p = _cur_lcf_time.wdays2[t->tm_wday];
    126               INS (p, strlen (p));
    127               break;
    128             case 'b':
    129             case 'h':
    130               p = _cur_lcf_time.months1[t->tm_mon];
    131               INS (p, strlen (p));
    132               break;
    133             case 'B':
    134               p = _cur_lcf_time.months2[t->tm_mon];
    135               INS (p, strlen (p));
    136               break;
    137             case 'c':
    138               FMT (_cur_lcf_time.date_time_fmt);
    139               break;
    140             case 'd':
    141               NUM2 (t->tm_mday);
    142               break;
    143             case 'D':
    144               FMT ("%m/%d/%y");
    145               break;
    146             case 'e':
    147               NUM2 (t->tm_mday);
    148               if (string[n-2] == '0')
    149                 string[n-2] = ' ';
    150               break;
    151             case 'H':
    152               NUM2 (t->tm_hour);
    153               break;
    154             case 'I':
    155               NUM2 ((t->tm_hour + 11) % 12 + 1);
    156               break;
    157             case 'j':
    158               NUM3 (t->tm_yday + 1);
    159               break;
    160             case 'm':
    161               NUM2 (t->tm_mon + 1);
    162               break;
    163             case 'M':
    164               NUM2 (t->tm_min);
    165               break;
    166             case 'n':
    167               CHR ('\n');
    168               break;
    169             case 'p':
    170               p = (t->tm_hour >= 12 ? _cur_lcf_time.pm : _cur_lcf_time.am);
    171               INS (p, strlen (p));
    172               break;
    173             case 'r':
    174               FMT ("%I:%M:%S %p");
    175               break;
    176             case 'S':
    177               NUM2 (t->tm_sec);
    178               break;
    179             case 't':
    180               CHR ('\t');
    181               break;
    182             case 'T':
    183               FMT ("%H:%M:%S");
    184               break;
    185             case 'U':
    186               NUM2 (week (t, 0));
    187               break;
    188             case 'w':
    189               NUM2 (t->tm_wday);
    190               break;
    191             case 'W':
    192               NUM2 (week (t, 1));
    193               break;
    194             case 'x':
    195               FMT (_cur_lcf_time.date_fmt);
    196               break;
    197             case 'X':
    198               FMT (_cur_lcf_time.time_fmt);
    199               break;
    200             case 'y':
    201               NUM2 (t->tm_year % 100);
    202               break;
    203             case 'Y':
    204               p = _itoa (t->tm_year + 1900, tmp, 10);
    205               INS (p, strlen (p));
    206               break;
    207             case 'Z':
    208               if (t->tm_isdst >= 0)
    209                 {
    210                   p = _tzname[(t->tm_isdst ? 1 : 0)];
    211                   INS (p, strlen (p));
    212                 }
    213               break;
    214             default:
    215               break;
    216             }
    217         }
    218       else if (c <= 127 || _cur_mbyte.mode == _MB_8BITS)
    219         {
    220           if (n < size)
    221             string[n++] = c;
    222           else
    223             return 0;
    224         }
    225       else
    226         {
    227           mbn = _mbtowc (NULL, format, MB_LEN_MAX, &shift);
    228           if (mbn < 1)
    229             mbn = 1;
    230           if (n + mbn > size)
    231             return 0;
    232           while (mbn > 0)
    233             {
    234               string[n++] = *format++;
    235               --mbn;
    236             }
    237           --format;
    238         }
     135      minlen = 9;
     136nextformat:
    239137      ++format;
     138      switch (*format)
     139      {
     140        case 0:
     141        case '%':
     142          CHR ('%');
     143          if (*format == 0)
     144            --format;
     145          break;
     146
     147        /* Handle prefixes first */
     148        case 'E':
     149          /* Alternative date/time formats not supported for now */
     150        case 'O':
     151          /* Alternative numeric formats not supported for now */
     152          goto nextformat;
     153
     154        case '1':
     155          /* Undocumented in Unicode API reference, encountered in Russian
     156             locale. I think it should mean that the next number should occupy
     157             such much characters how it should (e.g. %1H:%M = 1:20 or 23:00). */
     158          minlen = 1;
     159          goto nextformat;
     160
     161        case 'a':
     162          INS (__locale_time.swdays [t->tm_wday]);
     163          break;
     164        case 'A':
     165          INS (__locale_time.lwdays [t->tm_wday]);
     166          break;
     167        case 'b':
     168        case 'h':
     169          INS (__locale_time.smonths [t->tm_mon]);
     170          break;
     171        case 'B':
     172          INS (__locale_time.lmonths [t->tm_mon]);
     173          break;
     174        case 'c':
     175          FMT (__locale_time.date_time_fmt);
     176          break;
     177        case 'C':
     178          /* 2000 A.D. is still 20th century (not 21st) */
     179          NUM2 (1 + (t->tm_year - 1) / 100);
     180          break;
     181        case 'd':
     182          NUM2 (t->tm_mday);
     183          break;
     184        case 'D':
     185          FMT ("%m/%d/%y");
     186          break;
     187        case 'e':
     188          NUM2 (t->tm_mday);
     189          if (string [-2] == '0')
     190            string [-2] = ' ';
     191          break;
     192        case 'H':
     193          NUM2 (t->tm_hour);
     194          break;
     195        case 'I':
     196          NUM2 ((t->tm_hour + 11) % 12 + 1);
     197          break;
     198        case 'j':
     199          NUM3 (t->tm_yday + 1);
     200          break;
     201        case 'm':
     202          NUM2 (t->tm_mon + 1);
     203          break;
     204        case 'M':
     205          NUM2 (t->tm_min);
     206          break;
     207        case 'n':
     208          CHR ('\n');
     209          break;
     210        case 'p':
     211          INS (t->tm_hour >= 12 ? __locale_time.pm : __locale_time.am);
     212          break;
     213        case 'r':
     214          FMT ("%I:%M:%S %p");
     215          break;
     216        case 'S':
     217          NUM2 (t->tm_sec);
     218          break;
     219        case 't':
     220          CHR ('\t');
     221          break;
     222        case 'T':
     223          FMT ("%H:%M:%S");
     224          break;
     225        case 'U':
     226          NUM2 (week (t, 0));
     227          break;
     228        case 'w':
     229          NUM2 (t->tm_wday);
     230          break;
     231        case 'W':
     232          NUM2 (week (t, 1));
     233          break;
     234        case 'x':
     235          FMT (__locale_time.date_fmt);
     236          break;
     237        case 'X':
     238          FMT (__locale_time.time_fmt);
     239          break;
     240        case 'y':
     241          NUM2 (t->tm_year % 100);
     242          break;
     243        case 'Y':
     244          CHR ('0' + (1900 + t->tm_year) / 1000);
     245          NUM3 ((t->tm_year + 1900) % 1000);
     246          break;
     247        case 'Z':
     248          if (t->tm_isdst >= 0)
     249          {
     250            INS (_tzname [(t->tm_isdst ? 1 : 0)]);
     251          }
     252          break;
     253      }
    240254    }
    241   if (n < size)
     255    else if (!CHK_MBCS_PREFIX (__locale_ctype, c, i))
     256      CHR (c);
     257    else
    242258    {
    243       string[n] = 0;
    244       return n;
     259      if (i > size)
     260        return 0;
     261      memcpy (string, format, i);
     262      string += i;
     263      format += i - 1;
    245264    }
    246   else
    247     return 0;
    248 }
     265    ++format;
     266  }
     267
     268  if (size)
     269  {
     270    *string = 0;
     271    return string - orgstring;
     272  }
     273
     274  return 0;
     275}
  • trunk/src/emx/src/lib/time/strptime.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r493 r494  
    1 /* strptime.c (emx+gcc) -- Copyright (c) 1994-1998 by Eberhard Mattes */
    2 
     1/*
     2    Locale support implementation through OS/2 Unicode API.
     3    Copyright (c) 1992-1996 by Eberhard Mattes
     4    Copyright (c) 2003 InnoTek Systemberatung GmbH
     5
     6    For conditions of distribution and use, see the file COPYING.
     7
     8    Parse a time specification in the input string pointed to by buffer
     9    according to the format string pointed to by format, updating the
     10    structure pointed to by t.
     11
     12    Whitespace (any number of spaces) in the format string matches whitespace
     13    (any number of spaces, including zero) in the input string. All other
     14    characters except for % are compared to the input. Parsing ends (with an
     15    error being indicated) when a mismatch is encountered. %% in the format
     16    string matches % in the input string. A % which is not followed by another
     17    % or the end of the string starts a field specification. The field in the
     18    input is interpreted according to the field specification. For all field
     19    types, whitespace is ignored at the start of a field. Field specifications
     20    matching numbers skip leading zeros. Case is ignored when comparing strings.
     21    The field width is not restricted, that is, as many characters as possible
     22    are matched.
     23
     24    If successful, strptime() returns a pointer to the character following the
     25    last character parsed. On error, strptime() returns NULL.
     26*/
     27
     28#define __INTERNAL_DEFS
    329#include "libc-alias.h"
    430#include <stdlib.h>
     
    632#include <time.h>
    733#include <ctype.h>
    8 #include <emx/locale.h>
    9 
    10 #define RECURSE(FMT)  parse_fmt (s, FMT, tm)
    11 #define NUMBER(DST,MIN,MAX,ADD)  parse_number (s, DST, MIN, MAX, ADD)
    12 #define STRING(STR)  parse_string (s, STR)
    13 #define TABLE(DST,TAB,N)  parse_table (s, DST, TAB, N)
     34#include <sys/locale.h>
     35#include <emx/time.h>
     36
     37#define RECURSE(FMT) \
     38  if (!(s = parse_fmt (s, FMT, tm, &mask))) \
     39    return NULL;
     40#define NUMBER(DST,MIN,MAX,ADD) \
     41  if (!(s = parse_number (s, DST, MIN, MAX, ADD))) \
     42    return NULL;
     43#define STRING(STR) \
     44  if (!(s = parse_string (s, STR))) \
     45    return NULL;
     46#define TABLE(DST,TAB,N) \
     47  if (!(s = parse_table (s, DST, TAB, N))) \
     48    return NULL;
    1449
    1550static const unsigned char *parse_number (const unsigned char *s, int *dst,
    16                                           int min, int max, int add)
     51  int min, int max, int add)
    1752{
    1853  int n;
     
    3166}
    3267
    33 
    3468static const unsigned char *parse_string (const unsigned char *s,
    35                                           const char *str)
     69  const char *str)
    3670{
    3771  size_t len;
     
    4074    ++s;
    4175  len = strlen (str);
    42   if (len == 0 || _strnicmp (s, str, len) != 0)
     76  if (len == 0 || strnicmp (s, str, len) != 0)
    4377    return NULL;
    4478  return s + len;
    4579}
    4680
    47 
    4881static const unsigned char *parse_table (const unsigned char *s, int *dst,
    49                                          char **tab, int n)
     82  char **tab, int n)
    5083{
    5184  int i;
     
    5588    ++s;
    5689  for (i = 0; i < n; ++i)
    57     {
    58       len = strlen (tab[i]);
    59       if (_strnicmp (s, tab[i], len) == 0)
    60         {
    61           *dst = i;
    62           return s + len;
    63         }
    64     }
     90  {
     91    len = strlen (tab[i]);
     92    if (strnicmp (s, tab[i], len) == 0)
     93    {
     94      *dst = i;
     95      return s + len;
     96    }
     97  }
    6598  return NULL;
    6699}
    67100
    68 
    69101static const unsigned char *parse_fmt (const unsigned char *s,
    70                                        const unsigned char *f, struct tm *tm)
     102  const unsigned char *f, struct tm *tm, unsigned *retmask)
    71103{
    72104  const unsigned char *t;
    73105  int week = -1;
     106  int century = -1;
     107  /* The mask of found fields */
     108  unsigned mask = 0;
     109
     110#define MASK_CENTURY    0x00000001
     111#define MASK_YEAR2      0x00000002
     112#define MASK_YEAR4      0x00000004
     113#define MASK_YEAR       (MASK_YEAR2 | MASK_YEAR4)
     114#define MASK_YEARDAY    0x00000008
     115#define MASK_MONTH      0x00000010
     116#define MASK_MONTHDAY   0x00000020
     117#define MASK_WEEKS      0x00000040
     118#define MASK_WEEKM      0x00000080
     119#define MASK_WEEK       (MASK_WEEKM | MASK_WEEKS)
     120#define MASK_WEEKDAY    0x00000100
     121#define MASK_HOUR       0x00000200
     122#define MASK_MINUTE     0x00000400
     123#define MASK_SECOND     0x00000800
    74124
    75125  while (*f != 0)
    76     {
    77       if (isspace (*f))
    78         {
    79           while (*s != 0 && isspace (*s))
    80             ++s;
    81           ++f;
    82         }
    83       else if (*f != '%')
    84         {
    85           if (*s != *f)
    86             return NULL;
    87           ++s; ++f;
    88         }
    89       else
    90         {
    91           ++f;
    92           switch (*f++)
    93             {
    94             case 0:
    95               if (*s != '%')
    96                 return NULL;
    97               return s + 1;
    98               break;
    99 
    100             case '%':
    101               if (*s != '%')
    102                 return NULL;
    103               ++s;
    104               break;
    105 
    106             case 'a':
    107               s = TABLE (&tm->tm_wday, _cur_lcf_time.wdays1, 7);
    108               if (s == NULL) return NULL;
    109               break;
    110 
    111             case 'A':
    112               s = TABLE (&tm->tm_wday, _cur_lcf_time.wdays2, 7);
    113               if (s == NULL) return NULL;
    114               break;
    115 
    116             case 'b':
    117             case 'h':
    118               s = TABLE (&tm->tm_mon, _cur_lcf_time.months1, 12);
    119               if (s == NULL) return NULL;
    120               break;
    121 
    122             case 'B':
    123               s = TABLE (&tm->tm_mon, _cur_lcf_time.months2, 12);
    124               if (s == NULL) return NULL;
    125               break;
    126 
    127             case 'c':
    128               s = RECURSE (_cur_lcf_time.date_time_fmt);
    129               if (s == NULL) return NULL;
    130               break;
    131 
    132             case 'C':
    133               s = RECURSE ("%x %X");
    134               if (s == NULL) return NULL;
    135               break;
    136 
    137             case 'd':
    138             case 'e':
    139               s = NUMBER (&tm->tm_mday, 1, 31, 0);
    140               if (s == NULL) return NULL;
    141               break;
    142 
    143             case 'D':
    144               s = RECURSE ("%m/%d/%y");
    145               if (s == NULL) return NULL;
    146               break;
    147 
    148             case 'H':
    149             case 'k':
    150               s = NUMBER (&tm->tm_hour, 0, 23, 0);
    151               if (s == NULL) return NULL;
    152               break;
    153 
    154             case 'I':
    155             case 'l':
    156               s = NUMBER (&tm->tm_hour, 1, 12, 0);
    157               if (s == NULL) return NULL;
    158               break;
    159 
    160             case 'j':
    161               s = NUMBER (&tm->tm_yday, 1, 366, -1);
    162               if (s == NULL) return NULL;
    163               break;
    164 
    165             case 'm':
    166               s = NUMBER (&tm->tm_mon, 1, 12, -1);
    167               if (s == NULL) return NULL;
    168               break;
    169 
    170             case 'M':
    171               s = NUMBER (&tm->tm_min, 0, 59, 0);
    172               if (s == NULL) return NULL;
    173               break;
    174 
    175             case 'n':
    176               if (*s != '\n')
    177                 return NULL;
    178               ++s;
    179               break;
    180 
    181             case 'p':
    182               if (tm->tm_hour < 1 || tm->tm_hour > 12)
    183                 return NULL;
    184               if ((t = STRING (_cur_lcf_time.am)) != NULL)
    185                 {
    186                   if (tm->tm_hour == 12)
    187                     tm->tm_hour = 0;
    188                 }
    189               else if ((t = STRING (_cur_lcf_time.pm)) != NULL)
    190                 {
    191                   if (tm->tm_hour != 12)
    192                     tm->tm_hour += 12;
    193                 }
    194               else
    195                 return NULL;
    196               s = t;
    197               break;
    198 
    199             case 'r':
    200               s = RECURSE ("%I:%M:%S %p");
    201               if (s == NULL) return NULL;
    202               break;
    203 
    204             case 'R':
    205               s = RECURSE ("%H:%M");
    206               if (s == NULL) return NULL;
    207               break;
    208 
    209             case 'S':
    210               s = NUMBER (&tm->tm_sec, 0, 61, 0);
    211               if (s == NULL) return NULL;
    212               break;
    213 
    214             case 't':
    215               if (*s != '\t')
    216                 return NULL;
    217               ++s;
    218               break;
    219 
    220             case 'T':
    221               s = RECURSE ("%H:%M:%S");
    222               if (s == NULL) return NULL;
    223               break;
    224 
    225             case 'w':
    226               s = NUMBER (&tm->tm_wday, 0, 6, 0);
    227               if (s == NULL) return NULL;
    228               break;
    229 
    230             case 'U':
    231             case 'W':
    232               /* %U and %W are currently ignored. */
    233               s = NUMBER (&week, 0, 53, 0);
    234               if (s == NULL) return NULL;
    235               break;
    236 
    237             case 'x':
    238               s = RECURSE (_cur_lcf_time.date_fmt);
    239               if (s == NULL) return NULL;
    240               break;
    241 
    242             case 'X':
    243               s = RECURSE (_cur_lcf_time.time_fmt);
    244               if (s == NULL) return NULL;
    245               break;
    246 
    247             case 'y':
    248               s = NUMBER (&tm->tm_year, 0, 99, 0);
    249               if (s == NULL) return NULL;
    250               if (tm->tm_year < 69)
    251                 tm->tm_year += 100;
    252               break;
    253 
    254             case 'Y':
    255               s = NUMBER (&tm->tm_year, 1900, -1, -1900);
    256               if (s == NULL) return NULL;
    257               break;
    258 
    259             default:
    260               return NULL;
    261             }
    262         }
    263     }
     126  {
     127    if (isspace (*f))
     128    {
     129      while (*s != 0 && isspace (*s))
     130        ++s;
     131      ++f;
     132    }
     133    else if (*f != '%')
     134    {
     135      if (*s != *f)
     136        return NULL;
     137      ++s; ++f;
     138    }
     139    else
     140    {
     141      ++f;
     142nextformat:
     143      switch (*f++)
     144      {
     145        case 0:
     146          if (*s != '%')
     147            return NULL;
     148          return s + 1;
     149          break;
     150
     151        case '%': /* A percent is just a percent */
     152          if (*s != '%')
     153            return NULL;
     154          ++s;
     155          break;
     156
     157        /* Handle prefixes first */
     158        case 'E':
     159          /* Alternative date/time formats not supported for now */
     160        case 'O':
     161          /* Alternative numeric formats not supported for now */
     162        case '1':
     163          /* Numeric length does not have sense here */
     164          goto nextformat;
     165
     166        case 'a': /* Short weekday name */
     167          TABLE (&tm->tm_wday, __locale_time.swdays, 7);
     168          mask |= MASK_WEEKDAY;
     169          break;
     170
     171        case 'A': /* Long weekday name */
     172          TABLE (&tm->tm_wday, __locale_time.lwdays, 7);
     173          mask |= MASK_WEEKDAY;
     174          break;
     175
     176        case 'b': /* Short month name */
     177        case 'h':
     178          TABLE (&tm->tm_mon, __locale_time.smonths, 12);
     179          mask |= MASK_MONTH;
     180          break;
     181
     182        case 'B': /* Long month name */
     183          TABLE (&tm->tm_mon, __locale_time.lmonths, 12);
     184          mask |= MASK_MONTH;
     185          break;
     186
     187        case 'c': /* Locale's defined time and date format */
     188          RECURSE (__locale_time.date_time_fmt);
     189          break;
     190
     191        case 'C': /* Century number */
     192          NUMBER (&century, 0, 99, 0);
     193          mask |= MASK_CENTURY;
     194          break;
     195
     196        case 'd': /* Day of the month (1-31) */
     197        case 'e':
     198          NUMBER (&tm->tm_mday, 1, 31, 0);
     199          mask |= MASK_MONTHDAY;
     200          break;
     201
     202        case 'D': /* MM/DD/YY */
     203          RECURSE ("%m/%d/%y");
     204          break;
     205
     206        case 'H': /* Hour (00-23) */
     207        case 'k':
     208          NUMBER (&tm->tm_hour, 0, 23, 0);
     209          mask |= MASK_HOUR;
     210          break;
     211
     212        case 'I': /* Hour (01-12) */
     213        case 'l':
     214          NUMBER (&tm->tm_hour, 1, 12, 0);
     215          mask |= MASK_HOUR;
     216          break;
     217
     218        case 'j': /* Day of the year (1-366) */
     219          NUMBER (&tm->tm_yday, 1, 366, -1);
     220          mask |= MASK_YEARDAY;
     221          break;
     222
     223        case 'm': /* Month (01-12) */
     224          NUMBER (&tm->tm_mon, 1, 12, -1);
     225          mask |= MASK_MONTH;
     226          break;
     227
     228        case 'M': /* Minutes (00-59) */
     229          NUMBER (&tm->tm_min, 0, 59, 0);
     230          mask |= MASK_MINUTE;
     231          break;
     232
     233        case 'n': /* Newline */
     234          if (*s != '\n')
     235            return NULL;
     236          ++s;
     237          break;
     238
     239        case 'p': /* am or pm */
     240          if (!(mask & MASK_HOUR)
     241           || (tm->tm_hour < 1)
     242           || (tm->tm_hour > 12))
     243            return NULL;
     244          if ((t = parse_string (s, __locale_time.am)) != NULL)
     245          {
     246            if (tm->tm_hour == 12)
     247              tm->tm_hour = 0;
     248          }
     249          else if ((t = parse_string (s, __locale_time.pm)) != NULL)
     250          {
     251            if (tm->tm_hour != 12)
     252              tm->tm_hour += 12;
     253          }
     254          else
     255            return NULL;
     256          s = t;
     257          break;
     258
     259        case 'r': /* HH:MM:SS am/pm */
     260          RECURSE ("%I:%M:%S %p");
     261          break;
     262
     263        case 'R': /* HH:MM */
     264          RECURSE ("%H:%M");
     265          break;
     266
     267        case 'S': /* Seconds (00-61(?)) */
     268          NUMBER (&tm->tm_sec, 0, 61, 0);
     269          mask |= MASK_SECOND;
     270          break;
     271
     272        case 't': /* Tabulation */
     273          if (*s != '\t')
     274            return NULL;
     275          ++s;
     276          break;
     277
     278        case 'T': /* HH:MM:SS */
     279          RECURSE ("%H:%M:%S");
     280          break;
     281
     282        case 'w': /* Weekday (0-6), 0 = Sunday */
     283          NUMBER (&tm->tm_wday, 0, 6, 0);
     284          mask |= MASK_WEEKDAY;
     285          break;
     286
     287        case 'U': /* Week number (0-53), 0 = Sunday */
     288          NUMBER (&week, 0, 53, 0);
     289          mask |= MASK_WEEKS;
     290          break;
     291
     292        case 'W': /* Week number (0-53), 0 = Monday */
     293          NUMBER (&week, 0, 53, 0);
     294          mask |= MASK_WEEKM;
     295          break;
     296
     297        case 'x':
     298          RECURSE (__locale_time.date_fmt);
     299          break;
     300
     301        case 'X':
     302          RECURSE (__locale_time.time_fmt);
     303          break;
     304
     305        case 'y':
     306          NUMBER (&tm->tm_year, 0, 99, 0);
     307          if (tm->tm_year < 69)
     308            tm->tm_year += 100;
     309          mask |= MASK_YEAR2;
     310          break;
     311
     312        case 'Y':
     313          NUMBER (&tm->tm_year, 1900, -1, -1900);
     314          mask |= MASK_YEAR4;
     315          /* Ignore century since it was explicitely given */
     316          century = -1; mask &= ~MASK_CENTURY;
     317          break;
     318
     319        default:
     320          return NULL;
     321      }
     322    }
     323  }
     324
     325  if (mask & MASK_CENTURY)
     326  {
     327    if (!(mask & MASK_YEAR))
     328      tm->tm_year = 0;
     329    tm->tm_year = (century - 19) * 100 + (tm->tm_year % 100);
     330    mask |= MASK_YEAR4;
     331  }
     332
     333  /* We should know which fields are already correctly filled */
     334  if (retmask)
     335    mask |= *retmask;
     336
     337  if ((mask & MASK_YEAR) && (mask & MASK_YEARDAY)
     338   && (mask & (MASK_MONTH | MASK_MONTHDAY)) != (MASK_MONTH | MASK_MONTHDAY))
     339  {
     340    /* Compute month and day of the month if any of them is not given */
     341    const unsigned short *md = _leap_year (tm->tm_year + 1900) ?
     342      _month_day_leap : _month_day_non_leap;
     343    for (tm->tm_mon = 0; tm->tm_mon < 12 && tm->tm_yday < md [tm->tm_mon];
     344         tm->tm_mon++) ;
     345    tm->tm_mday = 1 + tm->tm_yday - md [tm->tm_mon];
     346    mask |= MASK_MONTH | MASK_MONTHDAY;
     347  }
     348
     349  if (!(mask & MASK_YEARDAY))
     350  {
     351    if ((mask & MASK_WEEK) && (mask & MASK_WEEKDAY) && (mask & MASK_YEAR)
     352     && (tm->tm_year >= 70) && (tm->tm_year <= 206))
     353    {
     354      /* Compute day of the year given week number and weekday */
     355      int dow = (4 + _year_day [tm->tm_year - 70]) % 7;
     356      if (mask & MASK_WEEKM)
     357        dow--;
     358      dow = (tm->tm_wday - dow) % 7;
     359      if (dow < 0) dow += 7;
     360      tm->tm_yday = week * 7 + dow;
     361      mask |= MASK_YEARDAY;
     362    }
     363    else if ((mask & MASK_YEAR) && (mask & MASK_MONTH) && (mask & MASK_MONTHDAY))
     364    {
     365      /* Compute year day from month and day of the month */
     366      const unsigned short *md = _leap_year (tm->tm_year + 1900) ?
     367        _month_day_leap : _month_day_non_leap;
     368      tm->tm_yday = tm->tm_mday - 1 + md [tm->tm_mon];
     369      mask |= MASK_YEARDAY;
     370    }
     371  }
     372
     373  if (!(mask & MASK_WEEKDAY) && (mask & MASK_YEAR) && (mask & MASK_YEARDAY))
     374  {
     375    /* Compute day of the week if it was not given */
     376    if ((tm->tm_year < 70) || (tm->tm_year > 206))
     377      tm->tm_wday = 0; /* Unknown */
     378    else
     379    {
     380      int absday = _year_day [tm->tm_year - 70] + tm->tm_yday;
     381      /* 1st January 1970 was Thursday (4) */
     382      tm->tm_wday = ((4 + absday) % 7);
     383      mask |= MASK_WEEKDAY;
     384    }
     385  }
     386
     387  if (((mask & (MASK_WEEK | MASK_WEEKDAY | MASK_YEAR)) == (MASK_WEEK | MASK_WEEKDAY | MASK_YEAR))
     388   && ((mask & (MASK_MONTH | MASK_MONTHDAY)) != (MASK_MONTH | MASK_MONTHDAY)))
     389  {
     390    /* Compute month and day of the month given weekday and week number */
     391    const unsigned short *md = _leap_year (tm->tm_year + 1900) ?
     392      _month_day_leap : _month_day_non_leap;
     393    int days;
     394
     395    for (days = tm->tm_yday, tm->tm_mon = 0; days >= md [tm->tm_mon];
     396         days -= md [tm->tm_mon], tm->tm_mon++)
     397      ;
     398    tm->tm_mday = 1 + days;
     399    mask |= MASK_MONTH | MASK_MONTHDAY;
     400  }
     401
     402  /* Communicate to the caller which fields are filled, except fields
     403     that are not located inside the tm structure. */
     404  if (retmask)
     405    *retmask |= mask & ~(MASK_WEEK | MASK_CENTURY);
     406
    264407  return s;
    265408}
    266 
    267409
    268410char *_STD(strptime) (const char *buf, const char *format, struct tm *tm)
    269411{
    270412  return (char *)parse_fmt ((const unsigned char *)buf,
    271                             (const unsigned char *)format, tm);
     413                            (const unsigned char *)format, tm, NULL);
    272414}
  • trunk/src/emx/src/pmgdb/breakpoi.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r493 r494  
    344344  for (const brkpt_node *p = list; p != NULL; p = p->next)
    345345    if (!p->source.is_null () && p->lineno == lineno
    346         && _fncmp ((const unsigned char *)p->source,
    347                    (const unsigned char *)fname) == 0)
     346        && strcasecmp ((const unsigned char *)p->source,
     347                       (const unsigned char *)fname) == 0)
    348348      return p;
    349349  return NULL;
  • trunk/src/emx/src/pmgdb/command.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r493 r494  
    343343       p = p->next)
    344344    if (p->get_source () != NULL
    345         && _fncmp ((const unsigned char *)p->get_source (),
    346                    (const unsigned char *)name) == 0)
     345        && strcasecmp ((const unsigned char *)p->get_source (),
     346                       (const unsigned char *)name) == 0)
    347347      src->set_breakpoint (p->get_lineno (), true, paint);
    348348}
     
    358358{
    359359  for (src_node *node = src_list; node != NULL; node = node->next)
    360     if (_fncmp ((const unsigned char *)node->src->get_short_filename (),
    361                 (const unsigned char *)fname) == 0)
     360    if (strcasecmp ((const unsigned char *)node->src->get_short_filename (),
     361                    (const unsigned char *)fname) == 0)
    362362      return node->src;
    363363  return NULL;
     
    368368{
    369369  for (src_node *node = src_list; node != NULL; node = node->next)
    370     if (_fncmp ((const unsigned char *)node->src->get_long_filename (),
    371                 (const unsigned char *)fname) == 0)
     370    if (strcasecmp ((const unsigned char *)node->src->get_long_filename (),
     371                    (const unsigned char *)fname) == 0)
    372372      return node->src;
    373373  return NULL;
  • trunk/src/emx/src/pmgdb/srcfiles.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r493 r494  
    136136  const source_files_window::srcs_node *n2
    137137    = *((source_files_window::srcs_node **)p2);
    138   return _fncmp ((const unsigned char *)_getname (n1->fname),
    139                  (const unsigned char *)_getname (n2->fname));
     138  return strcasecmp ((const unsigned char *)_getname (n1->fname),
     139                     (const unsigned char *)_getname (n2->fname));
    140140}
    141141
Note: See TracChangeset for help on using the changeset viewer.