From 836c97f0ac899042d5de2c2885ecadf1849fd66f Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Tue, 26 Jun 2007 00:54:22 +0000 Subject: [PATCH] Clib string & memory functions git-svn-id: svn://kolibrios.org@553 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../open watcom/trunk/clib/cgsupp/7fu8386.asm | 99 ++++ .../open watcom/trunk/clib/cgsupp/7u8f386.asm | 81 +++ .../open watcom/trunk/clib/cgsupp/__copy.asm | 68 +++ .../open watcom/trunk/clib/cgsupp/__stos.asm | 143 ++++++ .../trunk/clib/cgsupp/amodf386.asm | 237 +++++++++ .../trunk/clib/{src => cgsupp}/bufld386.asm | 0 .../open watcom/trunk/clib/cgsupp/div386.asm | 307 +++++++++++ .../open watcom/trunk/clib/cgsupp/fdc386.asm | 85 +++ .../open watcom/trunk/clib/cgsupp/fdfs386.asm | 84 +++ .../open watcom/trunk/clib/cgsupp/fdi4386.asm | 144 ++++++ .../open watcom/trunk/clib/cgsupp/fdi8386.asm | 151 ++++++ .../open watcom/trunk/clib/cgsupp/fdmath.asm | 150 ++++++ .../trunk/clib/cgsupp/fdmth386.asm | 484 ++++++++++++++++++ .../open watcom/trunk/clib/cgsupp/fdn386.asm | 59 +++ .../trunk/clib/cgsupp/fprem386.asm | 180 +++++++ .../open watcom/trunk/clib/cgsupp/fsc386.asm | 71 +++ .../open watcom/trunk/clib/cgsupp/fsfd386.asm | 89 ++++ .../open watcom/trunk/clib/cgsupp/fsi4386.asm | 171 +++++++ .../open watcom/trunk/clib/cgsupp/fsi8386.asm | 150 ++++++ .../trunk/clib/cgsupp/fsmth386.asm | 453 ++++++++++++++++ .../open watcom/trunk/clib/cgsupp/fsn386.asm | 56 ++ .../trunk/clib/cgsupp/fstat386.asm | 136 +++++ .../open watcom/trunk/clib/cgsupp/i4fd386.asm | 90 ++++ .../open watcom/trunk/clib/cgsupp/i4fs386.asm | 82 +++ .../open watcom/trunk/clib/cgsupp/i8d.asm | 224 ++++++++ .../open watcom/trunk/clib/cgsupp/i8fd386.asm | 101 ++++ .../open watcom/trunk/clib/cgsupp/i8fs386.asm | 102 ++++ .../trunk/clib/{src => cgsupp}/i8m386.asm | 0 .../trunk/clib/{src => cgsupp}/i8rs386.asm | 0 .../open watcom/trunk/clib/cgsupp/ldiv386.asm | 79 +++ .../trunk/clib/cgsupp/lldiv386.asm | 82 +++ .../trunk/clib/{src => heap}/amblksiz.c | 0 .../trunk/clib/{src => heap}/ambsptr.c | 0 .../trunk/clib/{src => heap}/calloc.c | 0 .../trunk/clib/{src => heap}/freect.c | 0 .../trunk/clib/{src => heap}/grownear.c | 0 .../trunk/clib/{src => heap}/heap.h | 0 .../trunk/clib/{src => heap}/heapacc.h | 0 .../trunk/clib/{src => heap}/heapen.c | 0 .../trunk/clib/{src => heap}/heapgrow.c | 0 .../trunk/clib/{src => heap}/mem.c | 0 .../trunk/clib/{src => heap}/memavl.c | 0 .../trunk/clib/{src => heap}/memmax.c | 0 .../trunk/clib/{src => heap}/ncalloc.c | 0 .../trunk/clib/{src => heap}/nexpand.c | 0 .../trunk/clib/{src => heap}/nfree.c | 0 .../trunk/clib/{src => heap}/nheapchk.c | 0 .../trunk/clib/{src => heap}/nheapmin.c | 0 .../trunk/clib/{src => heap}/nheapset.c | 0 .../trunk/clib/{src => heap}/nheapwal.c | 0 .../trunk/clib/{src => heap}/nmalloc.c | 0 .../trunk/clib/{src => heap}/nmemneed.c | 0 .../trunk/clib/{src => heap}/nmsize.c | 0 .../trunk/clib/{src => heap}/nrealloc.c | 0 .../trunk/clib/{src => heap}/sbrkwnt.c | 0 .../open watcom/trunk/clib/memory/bcmp.c | 45 ++ .../open watcom/trunk/clib/memory/bcopy.c | 41 ++ .../open watcom/trunk/clib/memory/bzero.c | 41 ++ .../open watcom/trunk/clib/memory/fmemccpy.c | 49 ++ .../open watcom/trunk/clib/memory/fmemchr.c | 56 ++ .../open watcom/trunk/clib/memory/fmemcmp.c | 52 ++ .../open watcom/trunk/clib/memory/fmemcpy.c | 49 ++ .../open watcom/trunk/clib/memory/fmemicmp.c | 54 ++ .../open watcom/trunk/clib/memory/fmemmove.c | 166 ++++++ .../open watcom/trunk/clib/memory/fmemset.c | 51 ++ .../open watcom/trunk/clib/memory/memccpy.c | 49 ++ .../open watcom/trunk/clib/memory/memchr.c | 59 +++ .../open watcom/trunk/clib/memory/memcmp.c | 56 ++ .../trunk/clib/{src => memory}/memcpy.c | 0 .../open watcom/trunk/clib/memory/memcpy_s.c | 75 +++ .../open watcom/trunk/clib/memory/memicmp.c | 54 ++ .../open watcom/trunk/clib/memory/memmov_s.c | 74 +++ .../trunk/clib/{src => memory}/memmove.c | 0 .../trunk/clib/{src => memory}/memset.c | 0 .../open watcom/trunk/clib/memory/memtest.c | 289 +++++++++++ .../open watcom/trunk/clib/memory/movedata.c | 46 ++ .../open watcom/trunk/clib/memory/swab.c | 47 ++ .../open watcom/trunk/clib/search/bsearch.c | 83 +++ .../open watcom/trunk/clib/search/bsrch_s.c | 84 +++ .../open watcom/trunk/clib/search/lfind.c | 65 +++ .../open watcom/trunk/clib/search/lsearch.c | 68 +++ .../open watcom/trunk/clib/search/qsort.c | 83 +++ .../open watcom/trunk/clib/search/qsort_s.c | 118 +++++ .../open watcom/trunk/clib/search/qsortr_s.c | 360 +++++++++++++ .../open watcom/trunk/clib/search/qsortrtn.c | 349 +++++++++++++ .../open watcom/trunk/clib/src/fstatus.inc | 47 ++ .../open watcom/trunk/clib/src/saferlib.h | 103 ++++ .../open watcom/trunk/clib/src/strdup.h | 41 ++ .../open watcom/trunk/clib/string/bits.c | 48 ++ .../open watcom/trunk/clib/string/bprintf.c | 139 +++++ .../open watcom/trunk/clib/string/cmp386.asm | 213 ++++++++ .../open watcom/trunk/clib/string/errstr.h | 46 ++ .../open watcom/trunk/clib/string/fsetbits.c | 45 ++ .../open watcom/trunk/clib/string/fstrcat.c | 51 ++ .../open watcom/trunk/clib/string/fstrchr.c | 91 ++++ .../open watcom/trunk/clib/string/fstrcmp.c | 50 ++ .../open watcom/trunk/clib/string/fstrcpy.c | 49 ++ .../open watcom/trunk/clib/string/fstrcspn.c | 57 +++ .../open watcom/trunk/clib/string/fstrdup.c | 49 ++ .../open watcom/trunk/clib/string/fstricmp.c | 55 ++ .../open watcom/trunk/clib/string/fstrlen.c | 49 ++ .../open watcom/trunk/clib/string/fstrlwr.c | 52 ++ .../open watcom/trunk/clib/string/fstrncat.c | 86 ++++ .../open watcom/trunk/clib/string/fstrncmp.c | 80 +++ .../open watcom/trunk/clib/string/fstrncpy.c | 82 +++ .../open watcom/trunk/clib/string/fstrnicm.c | 56 ++ .../open watcom/trunk/clib/string/fstrnset.c | 45 ++ .../open watcom/trunk/clib/string/fstrpbrk.c | 54 ++ .../open watcom/trunk/clib/string/fstrrchr.c | 78 +++ .../open watcom/trunk/clib/string/fstrrev.c | 121 +++++ .../open watcom/trunk/clib/string/fstrset.c | 75 +++ .../open watcom/trunk/clib/string/fstrspn.c | 55 ++ .../open watcom/trunk/clib/string/fstrspnp.c | 47 ++ .../open watcom/trunk/clib/string/fstrstr.c | 93 ++++ .../open watcom/trunk/clib/string/fstrtok.c | 70 +++ .../open watcom/trunk/clib/string/fstrupr.c | 52 ++ .../open watcom/trunk/clib/string/nextftok.h | 54 ++ .../open watcom/trunk/clib/string/nexttok.h | 48 ++ .../open watcom/trunk/clib/string/selptr.c | 44 ++ .../open watcom/trunk/clib/string/setbits.h | 36 ++ .../open watcom/trunk/clib/string/sneptr.c | 44 ++ .../open watcom/trunk/clib/string/snprintf.c | 93 ++++ .../open watcom/trunk/clib/string/snprtf_s.c | 100 ++++ .../trunk/clib/{src => string}/sprintf.c | 0 .../open watcom/trunk/clib/string/sprntf_s.c | 107 ++++ .../trunk/clib/{src => string}/sscanf.c | 0 .../open watcom/trunk/clib/string/sscanf_s.c | 87 ++++ .../open watcom/trunk/clib/string/stncat_s.c | 90 ++++ .../open watcom/trunk/clib/string/stncpy_s.c | 81 +++ .../trunk/clib/{src => string}/strcat.c | 0 .../open watcom/trunk/clib/string/strcat_s.c | 81 +++ .../trunk/clib/{src => string}/strchr.c | 0 .../open watcom/trunk/clib/string/strcoll.c | 55 ++ .../trunk/clib/{src => string}/strcpy.c | 0 .../open watcom/trunk/clib/string/strcpy_s.c | 76 +++ .../open watcom/trunk/clib/string/strcspn.c | 78 +++ .../open watcom/trunk/clib/string/strdup.c | 57 +++ .../open watcom/trunk/clib/string/streln_s.c | 57 +++ .../open watcom/trunk/clib/string/strerr_s.c | 99 ++++ .../open watcom/trunk/clib/string/strerror.c | 344 +++++++++++++ .../open watcom/trunk/clib/string/stricmp.c | 62 +++ .../open watcom/trunk/clib/string/strlcat.c | 68 +++ .../open watcom/trunk/clib/string/strlcpy.c | 64 +++ .../trunk/clib/{src => string}/strlen.c | 0 .../open watcom/trunk/clib/string/strlwr.c | 59 +++ .../open watcom/trunk/clib/string/strncat.c | 116 +++++ .../trunk/clib/{src => string}/strncmp.c | 0 .../trunk/clib/{src => string}/strncpy.c | 0 .../trunk/clib/{src => string}/strnicmp.c | 0 .../open watcom/trunk/clib/string/strnln_s.c | 51 ++ .../open watcom/trunk/clib/string/strnset.c | 52 ++ .../open watcom/trunk/clib/string/strpbrk.c | 75 +++ .../trunk/clib/{src => string}/strrchr.c | 0 .../open watcom/trunk/clib/string/strrev.c | 157 ++++++ .../open watcom/trunk/clib/string/strset.c | 50 ++ .../open watcom/trunk/clib/string/strspn.c | 78 +++ .../open watcom/trunk/clib/string/strspnp.c | 48 ++ .../open watcom/trunk/clib/string/strstr.c | 113 ++++ .../open watcom/trunk/clib/string/strtok.c | 139 +++++ .../open watcom/trunk/clib/string/strtok_s.c | 137 +++++ .../trunk/clib/{src => string}/strupr.c | 0 .../open watcom/trunk/clib/string/strxfrm.c | 55 ++ 162 files changed, 11855 insertions(+) create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm rename programs/develop/open watcom/trunk/clib/{src => cgsupp}/bufld386.asm (100%) create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/div386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm rename programs/develop/open watcom/trunk/clib/{src => cgsupp}/i8m386.asm (100%) rename programs/develop/open watcom/trunk/clib/{src => cgsupp}/i8rs386.asm (100%) create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm create mode 100644 programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm rename programs/develop/open watcom/trunk/clib/{src => heap}/amblksiz.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/ambsptr.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/calloc.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/freect.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/grownear.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/heap.h (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/heapacc.h (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/heapen.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/heapgrow.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/mem.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/memavl.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/memmax.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/ncalloc.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nexpand.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nfree.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nheapchk.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nheapmin.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nheapset.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nheapwal.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nmalloc.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nmemneed.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nmsize.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/nrealloc.c (100%) rename programs/develop/open watcom/trunk/clib/{src => heap}/sbrkwnt.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/memory/bcmp.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/bcopy.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/bzero.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemccpy.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemchr.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemcmp.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemcpy.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemicmp.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemmove.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/fmemset.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/memccpy.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/memchr.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/memcmp.c rename programs/develop/open watcom/trunk/clib/{src => memory}/memcpy.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/memory/memcpy_s.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/memicmp.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/memmov_s.c rename programs/develop/open watcom/trunk/clib/{src => memory}/memmove.c (100%) rename programs/develop/open watcom/trunk/clib/{src => memory}/memset.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/memory/memtest.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/movedata.c create mode 100644 programs/develop/open watcom/trunk/clib/memory/swab.c create mode 100644 programs/develop/open watcom/trunk/clib/search/bsearch.c create mode 100644 programs/develop/open watcom/trunk/clib/search/bsrch_s.c create mode 100644 programs/develop/open watcom/trunk/clib/search/lfind.c create mode 100644 programs/develop/open watcom/trunk/clib/search/lsearch.c create mode 100644 programs/develop/open watcom/trunk/clib/search/qsort.c create mode 100644 programs/develop/open watcom/trunk/clib/search/qsort_s.c create mode 100644 programs/develop/open watcom/trunk/clib/search/qsortr_s.c create mode 100644 programs/develop/open watcom/trunk/clib/search/qsortrtn.c create mode 100644 programs/develop/open watcom/trunk/clib/src/fstatus.inc create mode 100644 programs/develop/open watcom/trunk/clib/src/saferlib.h create mode 100644 programs/develop/open watcom/trunk/clib/src/strdup.h create mode 100644 programs/develop/open watcom/trunk/clib/string/bits.c create mode 100644 programs/develop/open watcom/trunk/clib/string/bprintf.c create mode 100644 programs/develop/open watcom/trunk/clib/string/cmp386.asm create mode 100644 programs/develop/open watcom/trunk/clib/string/errstr.h create mode 100644 programs/develop/open watcom/trunk/clib/string/fsetbits.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrcat.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrchr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrcmp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrcpy.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrcspn.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrdup.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstricmp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrlen.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrlwr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrncat.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrncmp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrncpy.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrnicm.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrnset.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrpbrk.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrrchr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrrev.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrset.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrspn.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrspnp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrstr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrtok.c create mode 100644 programs/develop/open watcom/trunk/clib/string/fstrupr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/nextftok.h create mode 100644 programs/develop/open watcom/trunk/clib/string/nexttok.h create mode 100644 programs/develop/open watcom/trunk/clib/string/selptr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/setbits.h create mode 100644 programs/develop/open watcom/trunk/clib/string/sneptr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/snprintf.c create mode 100644 programs/develop/open watcom/trunk/clib/string/snprtf_s.c rename programs/develop/open watcom/trunk/clib/{src => string}/sprintf.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/sprntf_s.c rename programs/develop/open watcom/trunk/clib/{src => string}/sscanf.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/sscanf_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/stncat_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/stncpy_s.c rename programs/develop/open watcom/trunk/clib/{src => string}/strcat.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strcat_s.c rename programs/develop/open watcom/trunk/clib/{src => string}/strchr.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strcoll.c rename programs/develop/open watcom/trunk/clib/{src => string}/strcpy.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strcpy_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strcspn.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strdup.c create mode 100644 programs/develop/open watcom/trunk/clib/string/streln_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strerr_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strerror.c create mode 100644 programs/develop/open watcom/trunk/clib/string/stricmp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strlcat.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strlcpy.c rename programs/develop/open watcom/trunk/clib/{src => string}/strlen.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strlwr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strncat.c rename programs/develop/open watcom/trunk/clib/{src => string}/strncmp.c (100%) rename programs/develop/open watcom/trunk/clib/{src => string}/strncpy.c (100%) rename programs/develop/open watcom/trunk/clib/{src => string}/strnicmp.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strnln_s.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strnset.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strpbrk.c rename programs/develop/open watcom/trunk/clib/{src => string}/strrchr.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strrev.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strset.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strspn.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strspnp.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strstr.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strtok.c create mode 100644 programs/develop/open watcom/trunk/clib/string/strtok_s.c rename programs/develop/open watcom/trunk/clib/{src => string}/strupr.c (100%) create mode 100644 programs/develop/open watcom/trunk/clib/string/strxfrm.c diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm new file mode 100644 index 000000000..d980327e8 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm @@ -0,0 +1,99 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + +.8087 + modstart _7fu8386 + + xdefp __FSU87 + xdefp __FDU87 + +defpe __FSU87 + sub esp,12 + mov [esp],eax + fld dword ptr [esp] + jmp short convert + +defpe __FDU87 + sub esp,12 + mov [esp],eax + mov 4[esp],edx + fld qword ptr [esp] + + ; fall through + +convert: + push ecx + fstp tbyte ptr 4[esp] ; get number out in memory + mov ax,12[esp] ; pick up sign/exponent + and ax,7fffh ; isolate exponent + sub ax,16383 ; remove bias + jl ret_zero ; if less than .5, return zero + cmp ax,64 ; are we too big? + jae ret_inf ; if so, return infinity + mov cl,63 ; calculate shift count + sub cl,al ; ... + mov eax,4[esp] ; pick up mantissa + mov edx,8[esp] ; ... + je negate ; skip out if no shifting +L2: + shr edx,1 ; shift down one bit + rcr eax,1 ; ... + dec cl ; are we done? + jne L2 ; do it again if not +negate: + test byte ptr 13[esp],80h ; is number negative? + jns done ; if not, we're done + neg edx ; negate number + neg eax ; ... + sbb edx,0 ; ... +done: + pop ecx ; ... + add esp,12 ; outta here + ret ; ... + +ret_zero: + xor edx,edx + xor eax,eax + jmp done + +ret_inf: + mov edx,0ffffffffh + mov eax,edx + jmp done +endproc __FDU87 +endproc __FSU87 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm new file mode 100644 index 000000000..f42125434 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm @@ -0,0 +1,81 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + +.8087 + modstart _7u8f386 + + xdefp __U8FD7 + xdefp __U8FS7 + +;;;;two_to_64 dw 0000h, 0000h, 0000h, 43f0h ; removed by JBS + +ULLMXP1: + DB 00H, 00H, 80H, 5FH ; (float)(ULONGLONG_MAX +1) + ; (only exponent set) + +defpe __U8FS7 + push edx ; save unsigned int64 (hi) + push eax ; save unsigned int64 (lo) + fild qword ptr [esp] ; load as int64 + test byte ptr 07H[esp],80H ; most significant bit set? + jns L$2 ; no, jump + fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as + ; as float (because expression is exact + ; in powers of 2, so save 4 bytes) +L$2: + pop eax ; correct stack + fstp dword ptr [esp] ; save float and pop coproc stack + pop eax ; return float in eax + ret +endproc __U8FS7 + +defpe __U8FD7 + push edx ; save unsigned int64 (hi) + push eax ; save unsigned int64 (lo) + fild qword ptr [esp] ; load as int64 + test byte ptr 07H[esp],80H ; most significant bit set? + jns L$3 ; no, jump + fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as + ; as float (because expression is exact + ; in powers of 2, so save 4 bytes) +L$3: + fstp qword ptr [esp] ; save double and pop coproc stack + pop eax ; return double (lo) + pop edx ; return double (hi) + ret +endproc __U8FD7 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm b/programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm new file mode 100644 index 000000000..54c431f55 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm @@ -0,0 +1,68 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +; char *__COPY( char *dst, char *src, unsigned len ); +; +; +include mdef.inc + + name __copy +_TEXT segment use32 para public 'CODE' + assume cs:_TEXT + + public __COPY + public __COPY_ + +__COPY proc near +__COPY_ proc near + push edi ; save regs + push esi ; ... + push ecx ; ... + mov edi,16+0[esp] ; get dst + mov esi,16+4[esp] ; get src + mov ecx,16+8[esp] ; get len + mov eax,edi ; return with dst ptr in eax + shr ecx,2 ; calc. # of dwords + rep movsd ; do the copy + mov ecx,16+8[esp] ; get len + and ecx,3 ; plus extra bytes + rep movsb ; do the copy + pop ecx ; restore regs + pop esi ; ... + pop edi ; ... + ret 12 ; return and remove parms +__COPY_ endp +__COPY endp + +_TEXT ends + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm b/programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm new file mode 100644 index 000000000..00abebdb6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm @@ -0,0 +1,143 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +; __STOSB( char *EAX, int EDX, unsigned ECX ); +; __STOSD( char *EAX, int EDX, unsigned ECX ); +; +include mdef.inc +include struct.inc + + modstart __stos,para + + xdefp __STOSB + xdefp __STOSD + + + defpe __STOSB + or ECX,ECX ; if length not zero + _if ne ; then + cmp [EAX],DL ; - access cache line + _loop ; - loop (get onto 4-byte boundary) + test AL,3 ; - - quit if on 4-byte boundary + _quif e ; - - ... + mov [EAX],DL ; - - store byte + inc EAX ; - - increment address + ror EDX,8 ; - - (DH can be different from DL) + dec ECX ; - - decrement length + _until e ; - until done + push ECX ; - save length + shr ECX,2 ; - calculate number of dwords + call __STOSD ; - store dwords + pop ECX ; - restore length + _guess ; - guess: some bytes left to do + and ECX,3 ; - - calculate number of bytes left + _quif e ; - - quit if done + mov [EAX],DL ; - - store a byte + dec ECX ; - - decrement length + _quif e ; - - quit if done + mov 1[EAX],DH ; - - store a byte + dec ECX ; - - decrement length + _quif e ; - - quit if done + mov 2[EAX],DL ; - - store a byte + _endguess ; - endguess + _endif ; endif + ret ; return + endproc __STOSB + + nop + nop + nop + nop + nop + nop + + defpe __STOSD + or ECX,ECX ; if length not zero + _if ne ; then + _loop ; - loop (get onto 32-byte boundary) + test AL,1Fh ; - - quit if on 32-byte boundary + _quif e ; - - ... + mov [EAX],EDX ; - - store dword + lea EAX,4[EAX] ; - - increment address + dec ECX ; - - decrement length + _until e ; - until done + push ECX ; - save length + shr ECX,2 ; - calculate number of paragraphs + _if ne ; - if at least one paragraph + dec ECX ; - - decrement # of paragraphs + _if ne ; - - if still have paragraphs to do + _loop ; - - - loop + mov [EAX],EDX ; - - - - store dword + mov 4[EAX],EDX ; - - - - ... + dec ECX ; - - - - decrement count + mov 8[EAX],EDX ; - - - - store dword + mov 12[EAX],EDX ; - - - - ... + je short add16 ; - - - - quit if done + cmp 32[EAX],DL ; - - - - access next cache line + mov 16[EAX],EDX ; - - - - store dword + mov 20[EAX],EDX ; - - - - ... + dec ECX ; - - - - decrement count + mov 24[EAX],EDX ; - - - - store dword + mov 28[EAX],EDX ; - - - - ... + lea EAX,32[EAX] ; - - - - advance to next 32-byte chunk + _until e ; - - - until done + lea EAX,-16[EAX] ; - - - back up 16 +add16: lea EAX,16[EAX] ; - - - advance 16 + _endif ; - - endif + mov [EAX],EDX ; - - fill last full paragraph + mov 4[EAX],EDX ; - - ... + mov 8[EAX],EDX ; - - ... + mov 12[EAX],EDX ; - - ... + lea EAX,16[EAX] ; - - advance pointer + _endif ; - endif + pop ECX ; - restore length + _guess ; - guess: some dwords left to do + and ECX,3 ; - - calculate number of dwords left + _quif e ; - - quit if done + mov [EAX],EDX ; - - store dword + lea EAX,4[EAX] ; - - advance pointer + dec ECX ; - - decrement length + _quif e ; - - quit if done + mov [EAX],EDX ; - - store dword + lea EAX,4[EAX] ; - - advance pointer + dec ECX ; - - decrement length + _quif e ; - - quit if done + mov [EAX],EDX ; - - store dword + lea EAX,4[EAX] ; - - advance pointer + _endguess ; - endguess + _endif ; endif + ret ; return + endproc __STOSD + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm new file mode 100644 index 000000000..dab2a1f7c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm @@ -0,0 +1,237 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; double modf( double value, double *iptr ); +; +; Description: +; The modf function breaks the argument value into integral and +; fractional parts, each of which has the same sign as the argument. +; It stores the integral part as a double in the object pointed to +; by iptr. +; +; Returns: +; The modf function returns the signed fractional part of value. +; +; 18-oct-86 ... Fraction in Modf not computed right +; significant digits +; +include mdef.inc +include struct.inc + + modstart amodf386 + + xdefp __ModF + xdefp __ZBuf2F + +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] +;[] +;[] __ModF +;[] +;[] void __ModF( double near *AX, double near *DX ); +;[] Input: EAX - pointer to double precision float +;[] EDX - place to store integral part +;[] Output: [EAX] - fractional part of value. +;[] [EDX] - integral part of value +;[] +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] + + defpe __ModF + push EBP ; save BP + push ESI ; save SI + push EDI ; save DI + push ECX ; save CX + push EBX ; save BX + mov ESI,EDX ; get address for ipart + mov EBP,EAX ; get address of float + mov EAX,0[EBP] ; get float + mov EDX,4[EBP] ; . . . + xchg ESI,EBP ; flip pointers + mov 0[EBP],EAX ; store integral part of value + mov 4[EBP],EDX ; . . . + _guess ; guess: fraction is zero + mov ECX,EDX ; - get exponent + and ECX,7FF00000h ; - get exponent part of R into DI + je short done ; - set integer part to 0 if exponent = 0 + cmp ECX,(3FFh+52) shl 20; - check for exponent > 52 + _quif b ; - quit if fraction not zero + xchg EBP,ESI ; - get address of fractional part +done: sub EAX,EAX ; - set fraction(or integer) to 0 + mov 4[EBP],EAX ; - . . . + mov 0[EBP],EAX ; - . . . + pop EBX ; - restore BX + pop ECX ; - restore CX + pop EDI ; - restore DI + pop ESI ; - restore SI + pop EBP ; - restore BP + ret ; - return + _endguess ; endguess + mov EDI,ECX ; save exponent + shr ECX,20 ; move exponent to bottom + sub CX,03FFh ; remove bias + jb done ; quit if number < 1.0 + push EDX ; save sign + sub EAX,EAX ; initialize mask to 0 + mov EDX,0FFF00000h ; ... + cmp CL,20 ; if exponent > 20 + _if a ; then + sar EDX,21 ; - set ESI to all ones + rcr EAX,1 ; - set high bit of EBX + sub CL,21 ; - get shift count for second part + sar EAX,CL ; - create rest of mask + _else ; else + sar EDX,CL ; - create mask in high part only + _endif ; endif + and 4[EBP],EDX ; mask off the remaining fraction bits + and 0[EBP],EAX ; . . . + not EDX ; complement the mask to get fractional part + not EAX ; . . . + mov EBP,ESI ; get address of fractional part + and EDX,4[EBP] ; get fraction bits + and EAX,0[EBP] ; . . . + call Norm ; normalize the fraction + pop ESI ; restore sign + or EDX,EDX ; if fraction is not 0 + _if ne ; then + and ESI,80000000h ; - isolate sign + or EDX,ESI ; - set sign in fractional part + _endif ; endif + mov 4[EBP],EDX ; store fractional part + mov 0[EBP],EAX ; . . . + pop EBX ; restore BX + pop ECX ; restore CX + pop EDI ; restore DI + pop ESI ; restore SI + pop EBP ; restore BP + ret ; return + endproc __ModF + + +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> +;<> <> +;<> __ZBuf2F - convert buffer of significant digits into floating <> +;<> void __ZBuf2F( char near *buf, double near *value ) <> +;<> <> +;<> input: EAX - address of buffer of significant digits <> +;<> EDX - place to store value <> +;<> output: [EDX] - floating point number <> +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> + + defpe __ZBuf2F + push EBP ; save BP + push ESI ; save SI + push EDI ; save DI + push ECX ; save CX + push EBX ; save BX + push EDX ; save pointer to result + mov ESI,EAX ; get address of buffer + sub EDX,EDX ; set 54-bit integer to 0 + sub ECX,ECX ; . . . + sub EAX,EAX ; zero out EAX + _loop ; loop (convert digits into 54-bit int) + mov AL,[ESI] ; - get next digit + cmp AL,0 ; - quit if at end of buffer + _quif e ; - . . . + +;[] multiply current value in EDX:ECX by 10 + + mov EDI,EDX ; - save current value + mov EBX,ECX ; - ... + _shl ECX,1 ; - multiply number by 4 + _rcl EDX,1 ; - by shifting left 2 places + _shl ECX,1 ; - . . . + _rcl EDX,1 ; - . . . + add ECX,EBX ; - add original value + adc EDX,EDI ; - (this will make it times 5) + _shl ECX,1 ; - shift left to make it times 10 + _rcl EDX,1 ; - . . . + and AL,0Fh ; - isolate binary digit + add ECX,EAX ; - add in current digit + adc EDX,0 ; - . . . + inc ESI ; - point to next digit in buffer + _endloop ; endloop + mov EAX,ECX ; get low order word into EAX + +;[] Turn the integer in EDX:EAX into a real number + + mov EDI,(3FFh+52) shl 20; set exponent + call Norm ; convert the 52 bit integer to a float + pop EBP ; restore pointer to result + mov 4[EBP],EDX ; store result + mov 0[EBP],EAX ; . . . + pop EBX ; restore BX + pop ECX ; restore CX + pop EDI ; restore DI + pop ESI ; restore SI + pop EBP ; restore BP + ret ; return to caller + endproc __ZBuf2F + + +;[] Norm normalizes an unsigned real in EDX:EAX +;[] expects the exponent to be in EDI. The real returned is in 'packed' +;[] format +;[] ESI is destroyed + +Norm proc near ; normalize floating point number + sub ESI,ESI ; clear out SI + or ESI,EAX ; see if the integer is zero + or ESI,EDX ; . . . + je short Z_52ret ; if integer is zero, return to caller + test EDX,0FFF00000h ; see if we have to shift forward or backward + _if e ; if (we haven't shifted msb into bit 53) + _loop ; - loop + sub EDI,00100000h ; - - exp <-- exp - 1 + _shl EAX,1 ; - - shift integer left by 1 bit + _rcl EDX,1 ; - - . . . + test EDX,0FFF00000h; + _until ne ; - until( msb is shifted into bit 53 ) + _else ; else (we must shift to the right) + test EDX,0FFE00000h ; - + je short done1 ; - if msb is bit 53, we are done + _loop ; - loop + add EDI,00100000h ; - - exp <-- exp + 1 + shr EDX,1 ; - - shift integer right by 1 bit + rcr EAX,1 ; - - . . . + rcr ESI,1 ; - - save lsb + test EDX,0FFE00000h; - + _until e ; - until( msb is bit 53 ) + _rcl ESI,1 ; - get lsb + adc EAX,0 ; - and use it to round off the number + adc EDX,0 ; - . . . + _endif ; endif +done1: and EDX,000FFFFFh ; clear out implied bit + or EDX,EDI ; put in exponent +Z_52ret:ret ; return + endproc Norm + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/src/bufld386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/bufld386.asm similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/bufld386.asm rename to programs/develop/open watcom/trunk/clib/cgsupp/bufld386.asm diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/div386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/div386.asm new file mode 100644 index 000000000..fecd352fa --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/div386.asm @@ -0,0 +1,307 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +include mdef.inc +include struct.inc + +.8087 + modstart div386 + + xref __8087 ; indicate that NDP instructions are present + + datasegment + extrn __real87 : byte ; 8087.asm + extrn __chipbug: byte + enddata + + xref F8DivZero ; Fstatus + xref F8OverFlow ; Fstatus + xref F8UnderFlow ; Fstatus + xref __fdiv_m64 + + xdefp __FDD + +; double __FDD( double , double ) +sign equ -12 +den equ sign-8 +quot equ den-12 +lo equ 0 +hi equ 4 + + defpe __FDD + or EBX,EBX ; if low word of divisor is 0 + _if e ; then + _shl ECX,1 ; - shift sign of divisor into carry + _if e ; - if divisor is zero + jmp F8DivZero ; - - handle divide by zero + _endif ; - endif + rcr ECX,1 ; - restore sign of divisor + _endif ; endif + or EAX,EAX ; check dividend for zero + _if e ; if so then + _shl EDX,1 ; - save sign of dividend + _if e ; - if dividend is 0 + ret ; - - return + _endif ; - endif + rcr EDX,1 ; - restore sign of dividend + _endif ; endif + + cmp byte ptr __real87,0 ; if no 80x87 is present + je short __FDDemu ; then emulate + +__FDD87: + push EDX ; push operand 1 + push EAX ; . . . + fld qword ptr [ESP] ; load operand 1 + push ECX ; push operand 2 + push EBX ; . . . + test byte ptr __chipbug,1 ; have we got a bad divider? + _if ne ; then + call __fdiv_m64 ; - call support rtn for divide + _else ; else + fdiv qword ptr [ESP] ; - divide operand 1 by operand 2 + add ESP,8 ; - clean up stack + _endif ; endif + fstp qword ptr [ESP] ; store result + fwait ; wait + pop EAX ; load result into DX:AX + pop EDX ; . . . + cmp EDX,80000000H ; is it a negative zero? + _if e ; if it is then + sub EDX,EDX ; - make it positive 0.0 + mov EAX,EDX ; - ... + _endif ; endif + ret ; return + +__FDDemu: + push EBP ; save EBP + mov EBP,ESP ; get access to stack + push EDI ; save EDI + push ESI ; and ESI + + mov EDI,EDX ; get high part of op1 + mov ESI,ECX ; get high part of op2 + sar EDI,20 ; shift exponent to bottom, duplicating sign + sar ECX,20 ; shift exponent to bottom, duplicating sign + and EDI,0800007FFh ; isolate signs and exponent + and ECX,0800007FFh ; ... + rol EDI,16 ; rotate signs to bottom + rol ECX,16 ; ... + add DI,CX ; calc sign of result + rol EDI,16 ; rotate signs to top + rol ECX,16 ; ... + and EDX,000FFFFFh ; isolate fraction + and ESI,000FFFFFh ; isolate fraction + or DI,DI ; if op1 is not a denormal + _if ne ; then + or EDX,00100000h ; - turn on implied 1 bit + _else ; else (denormal) + _loop ; - loop (normalize it) + _shl EAX,1 ; - - shift fraction left + _rcl EDX,1 ; - - . . . + dec DI ; - - decrement exponent + test EDX,00100000h ; - - until implied 1 bit is on + _until ne ; - until implied 1 bit is on + _endif ; endif + or CX,CX ; if op2 is not a denormal + _if ne ; then + or ESI,00100000h ; - turn on implied 1 bit + _else ; else (denormal) + _loop ; - loop (normalize it) + _shl EBX,1 ; - - shift fraction left + _rcl ESI,1 ; - - . . . + dec CX ; - - decrement exponent + test ESI,00100000h ; - - until implied 1 bit is on + _until ne ; - until implied 1 bit is on + _endif ; endif + + sub DI,CX ; calculate exponent of result + add DI,03ffh ; add in removed bias + _guess ; guess: overflow + _quif s ; - quit if exponent is negative + cmp DI,07FFh ; - quit if not overflow + _quif b ; - . . . + mov EAX,ECX ; - put sign into EAX + pop ESI ; - restore ESI + pop EDI ; - restore EDI + pop EBP ; - restore EBP + jmp F8OverFlow ; - handle overflow + _endguess ; endguess + cmp DI,-52 ; if exponent is too small + _if l ; then underflow + pop ESI ; - restore ESI + pop EDI ; - restore EDI + pop EBP ; - restore EBP + jmp F8UnderFlow ; - handle underflow + _endif ; endif + + push EDI ; save sign and exponent + mov CL,11 ; shift fractions to top of registers + shld EDX,EAX,CL ; ... + shld EAX,EBP,CL ; ... + and EAX,0FFFFF800h ; ... + shld ESI,EBX,CL ; ... + shld EBX,EBP,CL ; ... + and EBX,0FFFFF800h ; ... + push ESI ; save divisor + push EBX ; ... + mov ECX,ESI ; get top part of divisor + mov EDI,EDX ; get dividend + mov ESI,EAX ; ... + sub EAX,EAX ; assume top bit is 0 + cmp ECX,EDX ; check high parts + _if be ; if hi(divisor) <= hi(dividend) + sub EDX,ECX ; - subtract divisor from dividend + inc EAX ; - set quotient to 1 + _endif ; endif + push EAX ; save high word of quotient + mov EAX,ESI ; get low part of dividend + div ECX ; estimate next word of quotient + push EAX ; save estimate of quotient (quot+4[EBP]) + xchg EAX,EBX ; save quot., get low word of divisor + mul EBX ; calc. estimate * lo(divisor) + xchg EAX,ECX ; ... + xchg EBX,EDX ; save partial product + mul EDX ; calc. estimate * hi(divisor) + add EAX,EBX ; add to partial product + adc EDX,0 ; ... + mov EBX,den+lo[EBP] ; get low word of divisor + test byte ptr quot+8[EBP],1 ; if high word of quot is 1 + _if ne ; then + add EAX,EBX ; - add in divisor + adc EDX,den+hi[EBP] ; - ... + _endif ; endif +; subtract estimate * divisor from dividend + neg ECX ; 0 - ECX + sbb ESI,EAX ; ... + sbb EDI,EDX ; ... + _if ne ; if high word not 0 (quotient too big) + _loop ; - loop (find correct quotient) + sub dword ptr quot+4[EBP],1; - - decrement quotient + sbb dword ptr quot+8[EBP],0; - - ... + add ECX,EBX ; - - add divisor back to dividend + adc ESI,den+hi[EBP] ; - - ... + adc EDI,0 ; - - ... + _until e ; - until done + _endif ; endif + mov EDI,ESI ; get new dividend + mov ESI,ECX ; ... + mov ECX,den+hi[EBP] ; get divisor + cmp ECX,EDI ; check high parts 13-aug-90 + _if be ; if hi(divisor) <= hi(dividend) + sub EDI,ECX ; - subtract divisor from dividend + add dword ptr quot+4[EBP],1 ; - increment quotient + adc dword ptr quot+8[EBP],0 ; - ... + _endif ; endif + mov EDX,EDI ; get dividend into EDX:EAX + mov EAX,ESI ; ... + div ECX ; estimate next word of quotient + push EAX ; save estimate of quotient (-4[EBP]) + or EAX,EAX ; if quotient non-zero + _if ne ; then + xchg EAX,EBX ; - save quot., get low word of divisor + mul EBX ; - calc. estimate * lo(divisor) + xchg EAX,ECX ; - ... + xchg EBX,EDX ; - save partial product + mul EDX ; - calc. estimate * hi(divisor) + add EAX,EBX ; - add to partial product + adc EDX,0 ; - ... +; - subtract estimate * divisor from dividend + neg ECX ; - 0 - ECX + sbb ESI,EAX ; - ... + sbb EDI,EDX ; - ... + _if ne ; - if high word not 0 (quotient too big) + _loop ; - - loop (find correct quotient) + sub dword ptr quot+0[EBP],1; - - - decrement quotient + sbb dword ptr quot+4[EBP],0; - - - ... + sbb dword ptr quot+8[EBP],0; - - - ... + add ECX,den+lo[EBP] ; - - - add divisor back to dividend + adc ESI,den+hi[EBP] ; - - - ... + adc EDI,0 ; - - - ... + _until e ; - - until done + _endif ; - endif + _endif ; endif + pop EAX ; get quotient + pop EDX ; ... + pop EBX ; get high bit + add ESP,8 ; remove divisor + pop EDI ; restore sign and exponent + dec DI ; decrement exponent + shr EBX,1 ; if non-zero + _if c ; then + rcr EDX,1 ; - shift answer right + rcr EAX,1 ; - ... + inc EDI ; - increment exponent + _endif ; endif + sub ESI,ESI ; get zero for zero fill + mov CL,11 ; shift result over + shrd EAX,EDX,CL ; ... + rcr ESI,1 ; save carry + shrd EDX,ESI,CL ; ... + + or EDX,0FFF00000h ; turn top bits all on + _shl ESI,1 ; get guard bit + adc EAX,0 ; round up + adc EDX,0 ; ... + adc EDI,0 ; increment exponent if required + or DI,DI ; if exponent <= 0 + _if le ; then (denormal result) + _if e ; - if exponent = 0 + mov CL,1 ; - - set shift count to 1 + _else ; - else + neg DI ; - - negate to get shift count + mov CX,DI ; - - ... + _endif ; - endif + and EDX,001FFFFFh ; - isolate fraction + sub EBX,EBX ; - for zero fill + shrd EAX,EDX,CL ; - align the fraction + shrd EDX,EBX,CL ; - ... + sub DI,DI ; - set exponent to 0 + _endif ; endif + + and EDX,000FFFFFh ; isolate fraction + mov ESI,EDI ; get copy of sign + ror EDI,11 ; get exponent + _shl ESI,1 ; get sign + rcr EDI,1 ; put it in + and EDI,0FFF00000h ; isolate sign and exponent + or EDX,EDI ; place it in result + + pop ESI ; restore registers + pop EDI ; ... + pop EBP ; ... + ret ; return + endproc __FDD + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm new file mode 100644 index 000000000..67e1d2f2c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm @@ -0,0 +1,85 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> +;<> +;<> __FDC - floating double comparison +;<> input: EDX:EAX - operand 1 +;<> ECX:EBX - operand 2 +;<> if op1 > op2, 1 is returned in EAX +;<> if op1 < op2, -1 is returned in EAX +;<> if op1 = op2, 0 is returned in EAX +;<> +;<> +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> +include mdef.inc +include struct.inc + + modstart fdc386 + + xdefp __FDC + + defpe __FDC + push EBP ; save BP + test EDX,07ff00000h ; check for zero + _if e ; if it is then + sub EDX,EDX ; - make whole damn thing a zero + _endif ; endif + test ECX,07ff00000h ; check op2 for zero + _if e ; if it is then + sub ECX,ECX ; - make whole damn thing a zero + _endif ; endif + mov EBP,ECX ; save op2 exponent + xor EBP,EDX ; see about signs of the operands + mov EBP,0 ; clear result + js short cmpdone ; quif arg1 & arg2 have diff signs + _guess ; guess + cmp EDX,ECX ; - compare high words of arg1, arg2 + _quif ne ; - quif not equal + cmp EAX,EBX ; - compare 2nd words of arg1, arg2 + _endguess ; endguess + _if ne ; if arg1 <> arg2 + rcr ECX,1 ; - save carry in CX + xor EDX,ECX ; - sign of BX is sign of result + +cmpdone: _shl EDX,1 ; - get sign of result into carry + sbb EBP,0 ; - BP gets sign of result + _shl EBP,1 ; - double BP + inc EBP ; - make BP -1 or 1 + _endif ; endif + mov EAX,EBP ; get result + pop EBP ; restore BP + ret ; return to caller + endproc __FDC + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm new file mode 100644 index 000000000..47635898f --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm @@ -0,0 +1,84 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;========================================================================= +;== Name: FDFS == +;== Operation: Float double to float single conversion == +;== Inputs: EDX:EAX double precision float == +;== Outputs: EAX single precision float == +;== Volatile: EDX destroyed == +;========================================================================= +include mdef.inc +include struct.inc + + modstart fdfs386 + + xdefp __FDFS + + defpe __FDFS + push EBX ; save EBX + test EDX,07ff00000h ; check exponent + je short retzero ; if exponent = 0 then just return 0 + sub EBX,EBX ; set to 0 + _shl EAX,1 ; shift number over + _rcl EDX,1 ; ... + rcr EBX,1 ; save sign + add EAX,20000000h ; round floating point number + adc EDX,0 ; ... + je oflow ; overflow if exponent went to 0 + cmp EDX,(03ffh+80h) shl 21 ; check for maximum exponent + jae oflow ; overflow if above or equal + cmp EDX,(03ffh-7eh) shl 21 ; check for minimum exponent + jb uflow ; underflow if below + sub EDX,(03ffh-7fh) shl 21 ; correct bias + _shl EAX,1 ; do rest of shift + _rcl EDX,1 ; ... + _shl EAX,1 ; ... + _rcl EDX,1 ; ... + or EDX,EBX ; put in sign bit + mov EAX,EDX ; get result into EAX + pop EBX ; restore EBX + ret ; return + +oflow: mov EAX,7F800000h ; return maximum possible number + or EAX,EBX ; put in sign bit + pop EBX ; restore EBX + ret ; and return + +uflow: +retzero:sub EAX,EAX ; set result to 0 + pop EBX ; restore EBX + ret + endproc __FDFS + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm new file mode 100644 index 000000000..12be3111f --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm @@ -0,0 +1,144 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +include mdef.inc +include struct.inc + + modstart fdi4386 + + xdefp __FDI4 + xdefp __RDI4 + + xdefp __FDU4 + xdefp __RDU4 + +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] +;[] +;[] __FDU4 convert double float EDX:EAX into 32-bit integer EAX +;[] Input: EDX:EAX - double precision floating point number +;[] Output: EAX - 32-bit integer +;[] +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] +; convert floating double to 4-byte integer with rounding + + defpe __RDU4 + mov AL,80h+20h ; indicate we are rounding + jmp short DtoI ; do it + + defpe __RDI4 + mov AL,80h+1Fh ; indicate we are rounding + jmp short DtoI ; do it + + defpe __FDI4 + mov AL,1Fh ; indicate we are truncating + jmp short DtoI ; do it + +; convert floating double to 4-byte integer with truncation + + defpe __FDU4 + mov AL,20h ; indicate we are truncating + +DtoI: _shl EDX,1 ; get sign + rcr AH,1 ; AH <-- sign + shr AH,1 ; shift sign bit over 1 + or AH,AL ; get rounding bit + shr EDX,1 ; restore exponent to its place + +; high bit of AH is rounding bit +; next bit is the sign bit + +;<~> Shift real right four places so that exponent occupies an entire +;<~> word and the mantissa occupies the remaining words. We do not need +;<~> AX because we only need 32 sig digits + + push ECX ; save ECX + mov ECX,EDX ; get high part + sar ECX,20 ; get exponent to the bottom + and CX,07FFh ; isolate exponent + sub CX,03FEh ; remove bias from exponent + jl short DIzero ; if |real| < .5 goto DIzero + cmp CX,20h ; if exponent > 32 + jg short DIo_f ; goto DIo_flow + and AL,3Fh ; isolate # of significant bits + cmp CL,AL ; quit if number too big + jg short DIo_f ; goto DIo_flow + mov CH,AH ; save rounding/truncation bit + and EDX,000FFFFFh ; isolate top 20 bits of fraction + and EAX,0FFF00000h ; isolate next 12 bits of fraction + or EDX,EAX ; glue them together + rol EDX,12 ; and rotate into position + + stc ; set carry and + rcr EDX,1 ; restore implied 1/2 bit + + rcr CH,1 ; save rounding bit + cmp CL,32 ; if want 32 bits + _if e ; then + mov EAX,EDX ; - get them + _shl CH,1 ; - get rounding bit + _else ; else + sub EAX,EAX ; - zero result register + shld EAX,EDX,CL ; - shift answer into EAX + shl EDX,CL ; - shift rounding bit into position + _shl CH,1 ; - get rid of rounding bit from CH + _shl EDX,1 ; - get proper rounding bit + _endif ; endif + mov CL,0FFh ; get mask + rcr CL,1 ; get rounding bit + and CH,CL ; mask it with rounding control bit + _shl CH,1 ; get rounding bit + adc EAX,0 ; add it to the integer to round it up + _shl CH,1 ; get sign + _if c ; if negative + neg EAX ; - negate integer + _endif ; endif + pop ECX ; restore ECX + ret ; return + +DIo_f: + mov EAX,80000000h ; set answer to largest negative number + pop ECX ; restore ECX + ret ; return +; jmp I4OverFlow ; report overflow + +DIzero: sub EAX,EAX ; set result to zero + pop ECX ; restore ECX + ret + + endproc __FDU4 + endproc __FDI4 + endproc __RDI4 + endproc __RDU4 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm new file mode 100644 index 000000000..0443ee558 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm @@ -0,0 +1,151 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +; from double to signed/unsigned int64 +; +include mdef.inc +include struct.inc + + modstart fdi8386 + + xref __U8LS + xref __U8RS + +; Convert double precision float to unsigned 64-bit integer with truncation +; Input: [EDX, EAX] = 64-bit float +; Output: [EDX, EAX] = 64-bit integer + + xdefp __FDU8 + defp __FDU8 + push ECX ; save ECX + mov CX,3ffh+64 ; maximum number 2^64-1 + call __FDU ; convert float to unsigned __int64 + pop ECX ; restore ECX + ret ; return + endproc __FDU8 + +; Convert double precision float to signed 64-bit integer with truncation +; Input: [EDX, EAX] = 64-bit float +; Output: [EDX, EAX] = 64-bit integer + + xdefp __FDI8 + defp __FDI8 + push ECX ; save ECX + mov CX,3ffh+63 ; maximum number 2^63-1 + call __FDI ; convert float to signed __int64 + pop ECX ; restore ECX + ret ; return + endproc __FDI8 + +__FDI proc near +__FDU: ; what? they both do the same thing + or EDX,EDX ; check sign bit + jns short __FDAbs ; treat as unsigned if positive + call __FDAbs ; otherwise convert number + neg EDX ; negate the result + neg EAX ; + sbb EDX,0 ; + ret ; return + endproc __FDI + +__FDAbs proc near + or EAX,EAX ; check if number 0 + jne short notzero ; + or EDX,EDX ; check if number 0 + jne short notzero ; + ret +notzero: + push EBX ; save EBX + _shl EDX,1 ; shift mantissa over + rol EDX,11 ; get exponent to bottom + mov BX,DX ; copy and isolate + and BX,07ffh ; exponent + cmp BX,3ffh ; quit if number < 1.0 + jb short dbluflow ; ... + stc ; set carry for implied bit + rcr EDX,1 ; put implied '1' bit in + shr EDX,11 ; remove exponent and extra bit + cmp BX,CX ; check if exponent exceeds maximum + jae short dblmax ; return maximum value if so + sub BX,3ffh+52 ; calculate amount to shift (+ve -> left) + jae short dblm_left ; jump if left shift/no shift + neg BX ; make positive + call __U8RS ; shift mantissa right + pop EBX ; restore EBX + ret ; return + +dblm_left: + _if ne ; done if exponent exactly 55 + call __U8LS ; - shift mantissa left + _endif ; endif + pop EBX ; restore EBX + ret ; return + +; CX = 3ffh+64 for unsigned +; 3ffh+63 for signed +dblmax: + mov EAX,0FFFFFFFFh ; return maximum value + mov EDX,EAX ; + sub CX,3fFh+64 ; subtract bias + 64, results in 0 or -1 + neg CX ; get shift count + mov BX,CX ; set shift count + call __U8RS ; shift mantissa right 1 bit for signed + pop EBX ; restore EBX + ret ; return + +dbluflow: + sub EAX,EAX ; ensure entire number 0 + sub EDX,EDX ; + pop EBX ; restore EBX + ret ; return + + endproc __FDAbs + +; Convert double precision float to unsigned 64-bit integer with rounding +; Input: [EDX, EAX] = 64-bit float + +; xdefp __RDU8 +; defp __RDU8 +; not implemented +; endproc __RDU8 + +; Convert double precision float to signed 64-bit integer with rounding +; Input: [EDX, EAX] = 64-bit float + +; xdefp __RDI8 +; defp __RDI8 +; not implemented +; endproc __RDI8 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm new file mode 100644 index 000000000..42449d100 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm @@ -0,0 +1,150 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; These compiler support routines are called by the Fast code generator +; when compiling with the -fpc option. +; + name fdmath + + extrn __FDA : near + extrn __FDS : near + extrn __FDM : near + extrn __FDD : near + extrn __FDC : near + +_TEXT segment use32 dword public 'CODE' + assume cs:_TEXT + + public __FADD +__FADD proc near + push ecx ; save regs + push ebx ; ... + mov ebx,12[esp] ; load op2 + mov ecx,16[esp] ; ... + call __FDA ; do the add + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op2 +__FADD endp + + public __FSUB +__FSUB proc near + push ecx ; save regs + push ebx ; ... + mov ebx,12[esp] ; load op2 + mov ecx,16[esp] ; ... + call __FDS ; do the subtract + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op2 +__FSUB endp + + public __FSUBR +__FSUBR proc near + push ecx ; save regs + push ebx ; ... + mov ecx,edx ; load op2 + mov ebx,eax ; ... + mov eax,12[esp] ; load op1 + mov edx,16[esp] ; ... + call __FDS ; do the subtract + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op1 +__FSUBR endp + + public __FMUL +__FMUL proc near + push ecx ; save regs + push ebx ; ... + mov ebx,12[esp] ; load op2 + mov ecx,16[esp] ; ... + call __FDM ; do the multiply + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op2 +__FMUL endp + + public __FDIV +__FDIV proc near + push ecx ; save regs + push ebx ; ... + mov ebx,12[esp] ; load op2 + mov ecx,16[esp] ; ... + call __FDD ; do the divide + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op2 +__FDIV endp + + public __FDIVR +__FDIVR proc near + push ecx ; save regs + push ebx ; ... + mov ecx,edx ; load op2 + mov ebx,eax ; ... + mov eax,12[esp] ; load op1 + mov edx,16[esp] ; ... + call __FDD ; do the divide + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op1 +__FDIVR endp + + public __FCMP +__FCMP proc near + push ecx ; save regs + push ebx ; ... + mov ebx,12[esp] ; load op2 + mov ecx,16[esp] ; ... + call __FDC ; do the compare + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op2 +__FCMP endp + + public __FCMPR +__FCMPR proc near + push ecx ; save regs + push ebx ; ... + mov ecx,edx ; load op2 + mov ebx,eax ; ... + mov eax,12[esp] ; load op1 + mov edx,16[esp] ; ... + call __FDC ; do the compare + pop ebx ; restore regs + pop ecx ; ... + ret 8 ; return and remove op1 +__FCMPR endp + +_TEXT ends + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm new file mode 100644 index 000000000..4147b0d11 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm @@ -0,0 +1,484 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: REAL*8 math library. +;* +;***************************************************************************** + + +; +; inputs: EDX,EAX - operand 1 (high word, low word resp. ) (op1) +; ECX,EBX - operand 2 (op2) +; +; operations are performed as op1 (*) op2 where (*) is the selected +; operation +; +; output: EDX,EAX - result (high word, low word resp. ) +; +; +include mdef.inc +include struct.inc + +.8087 + modstart fdmth386 + + xref __8087 ; indicate that NDP instructions are present + + datasegment + extrn __real87 : byte ; 8087.asm + enddata + + xref F8DivZero ; Fstatus + xref F8OverFlow ; Fstatus + xref F8UnderFlow ; Fstatus + + xdefp __FDA ; add real*8 to real*8 + xdefp __FDS ; subtract real*8 from real*8 + xdefp __FDM ; 8-byte real multiply + + + defpe __FDS + xor ECX,80000000h ; flip the sign of op2 and add + + defpe __FDA + or EBX,EBX ; if low word of op2 is 0 + _if e ; then + _shl ECX,1 ; - place sign in carry + je ret_op1 ; - if op2 is 0 then return operand 1 + rcr ECX,1 ; - put sign back + _endif ; endif + or EAX,EAX ; if op1 is 0 + _if e ; then + _shl EDX,1 ; - place sign in carry + _if e ; - if op1 really is 0 + mov EDX,ECX ; - - return operand 2 + mov EAX,EBX ; - - . . . +ret_op1: ret ; - - return + _endif ; - endif + rcr EDX,1 ; - put sign back + _endif ; endif + + cmp byte ptr __real87,0; if 8087 not to be used + je short __FDAemu ; then emulate + +__FDA87: + push EDX ; push operand 1 + push EAX ; . . . + fld qword ptr [ESP] ; load operand 1 + push ECX ; push operand 2 + push EBX ; . . . + fadd qword ptr [ESP] ; add operand 2 to operand 1 +_ret87: + fstp qword ptr 8[ESP]; store result + add ESP,8 ; clean up stack + fwait ; wait + pop EAX ; load result into EDX:EAX + pop EDX ; . . . + cmp EDX,80000000H ; is it a negative zero? + _if e ; if it is then + sub EDX,EDX ; - make it positive 0.0 + mov EAX,EDX ; - ... + _endif ; endif + ret ; return + +__FDAemu: + push EBP ; save EBP + push EDI ; save EDI + push ESI ; save EDI + mov EDI,EDX ; get high part of op1 + mov ESI,ECX ; get high part of op2 + sar EDI,20 ; shift exponent to bottom, duplicating sign + sar ECX,20 ; shift exponent to bottom, duplicating sign + and EDI,0800007FFh ; isolate signs and exponent + and ECX,0800007FFh ; ... + mov EBP,ECX ; assume op1 < op2 + rol EDI,16 ; rotate signs to bottom + rol ECX,16 ; ... + add CX,DI ; calc sign of result + rol EDI,16 ; rotate signs to top + rol ECX,16 ; ... + and EDX,000FFFFFh ; isolate fraction + and ESI,000FFFFFh ; isolate fraction + or DI,DI ; if op1 is not a denormal + _if ne ; then + or EDX,00100000h ; - turn on implied 1 bit + _endif ; endif + or CX,CX ; if op2 is not a denormal + _if ne ; then + or ESI,00100000h ; - turn on implied 1 bit + _endif ; endif + _shl EAX,1 ; shift left 1 to make room for guard bit + _rcl EDX,1 ; ... + _shl EBX,1 ; ... + _rcl ESI,1 ; ... + sub CX,DI ; calculate difference in exponents + _if ne ; if different + _if b ; - if op1 < op2 + mov EBP,EDI ; - - get larger exponent for result + neg CX ; - - negate the shift count + xchg EAX,EBX ; - - flip operands + xchg EDX,ESI ; - - . . . + _endif ; - endif + cmp CX,53+1 ; - if shift count too big + _if a ; - then, return operand 1 + mov EDX,ESI ; - - get value in correct registers + mov EAX,EBX ; - - . . . + _shl EBP,1 ; - - get sign + rcr EDX,1 ; - - rebuild operand 1 + rcr EAX,1 ; - - ... + and EDX,800FFFFFh ; - - ... + ror EBP,13 ; - - rotate exponent into position + and EBP,7FF00000h ; - - ... + or EDX,EBP ; - - put in exponent + pop ESI ; - - restore ESI + pop EDI ; - - restore EDI + pop EBP ; - - restore EBP + ret ; - - return + _endif ; - endif + _endif ; endif + or ECX,ECX ; get bit 0 of sign word - value is 0 if + ; both operands have same sign, 1 if not + _if s ; if signs are different + neg ESI ; - negate the fraction of op2 + neg EBX ; - . . . + sbb ESI,0 ; - . . . + xor EBP,80000000h ; - flip sign + _endif ; endif + sub EDI,EDI ; get a zero for sticky bits + cmp CL,0 ; if shifting required + _if ne ; then + push EBX ; - save EBX + sub EBX,EBX ; - for zero fill + cmp CL,32 ; - if shift count >= 32 + _if ae ; - then + or EAX,EAX ; - - check low order word for 1 bits + setne BL ; - - BL=1 if EAX non zero + mov EDI,EBX ; - - save sticky bits + sub EBX,EBX ; - - for zero fill + mov EAX,EDX ; - - shift right 32 + sub EDX,EDX ; - - zero high word +;;; sub CL,32 ; - - adjust shift count + _endif ; - endif + shrd EBX,EAX,CL ; - get the extra sticky bits + or EDI,EBX ; - save them + sub EBX,EBX ; - for zero fill + shrd EAX,EDX,CL ; - align the fractions + shrd EDX,EBX,CL ; - ... + pop EBX ; - restore EBX + _endif ; endif + + add EAX,EBX ; add the fractions + adc EDX,ESI ; . . . + _if s ; if answer is negative + cmp CL,53 ; - if shift count >= 53 + _if ae ; - then + test EDI,7FFFFFFFh ; - - check the sticky bits + setne BL ; - - make single sticky bit + shr EBX,1 ; - - carry set if sticky=1 + adc EAX,0 ; - - round up fraction if required + adc EDX,0 ; - - . . . + _endif ; - endif + neg EDX ; - negate the fraction + neg EAX ; - . . . + sbb EDX,0 ; - . . . + xor EBP,80000000h ; - flip the sign + _endif ; endif + mov EBX,EAX ; get result + or EBX,EDX ; if not zero + _if ne ; then + or BP,BP ; - if exponent is 0 + je short denormal ; - denormal when exponent hits 0 + _loop ; - loop (normalize) + test EDX,7FE00000h ; - - stop when bit slides into exponent field + _quif ne ; - - ... + dec BP ; - - decrement exponent + je short denormal; - - denormal when exponent hits 0 + _shl EAX,1 ; - - shift fraction left one bit + _rcl EDX,1 ; - - ... + _endloop ; - endloop + test EDX,00400000h ; - if we got a carry + _if ne ; - then + shr EDX,1 ; - - shift fraction right 1 + rcr EAX,1 ; - - ... + adc EDI,0 ; - - keep sticky bit + inc BP ; - - increment exponent + cmp BP,07FFh ; - - quit if overflow + je add_oflow ; - - . . . + _endif ; - endif + ; normalize the fraction + shr EDX,1 ; - get guard bit + rcr EAX,1 ; - ... + _if c ; - if guard bit is on + or EDI,EDI ; - - check the sticky bits + setne BL ; - - make single sticky bit + or EBX,EAX ; - - or sticky bit with bottom bit + shr EBX,1 ; - - carry set if sticky=1 or bottom=1 + adc EAX,0 ; - - round up fraction if required + adc EDX,0 ; - - . . . + test EDX,00200000h ; - - if we got a carry (02-nov-90) + _if ne ; - - then + shr EDX,1 ; - - - shift fraction right 1 + rcr EAX,1 ; - - - ... + inc BP ; - - - increment exponent + cmp BP,07FFh ; - - - quit if overflow + je add_oflow ; - - - . . . + _endif ; - - endif + _endif ; - endif + and EDX,000FFFFFh ; - get rid of implied 1 bit + mov ECX,EBP ; - get sign + shl EBP,21 ; - shift exponent to top + _shl ECX,1 ; - get sign + rcr EBP,1 ; - put it in + or EDX,EBP ; - put exponent and sign into result + _endif ; endif + pop ESI ; restore ESI + pop EDI ; restore EDI + pop EBP ; restore EBP + ret ; return + +denormal: ; handle denormal + _shl EBP,1 ; get sign + rcr EDX,1 ; put it in result + rcr EAX,1 ; ... + pop ESI ; restore ESI + pop EDI ; restore EDI + pop EBP ; restore EBP + ret ; return + +add_oflow: ; handle overflow + mov EAX,EBP ; get proper sign for infinity + pop ESI ; restore ESI + pop EDI ; restore EDI + pop EBP ; restore EBP + jmp F8OverFlow ; handle overflow + endproc __FDA + endproc __FDS +;===================================================================== +;<> multiplies X by Y and places result in C. +;<> X2 and X1 represent the high and low words of X. Similarly for Y and C +;<> Special care is taken to use only six registers, so the code is a bit +;<> obscure + + defpe __FDM + _guess ; guess: one of the operands is 0 + or EAX,EAX ; - see if first arg is zero + _quif ne ; - quit if op1 is not 0 + _shl EDX,1 ; - place sign in carry + _if e ; - if operand one is 0 + ret ; - - return + _endif ; - endif + rcr EDX,1 ; - restore sign + _endguess ; endguess + _guess ; guess: op2 is 0 + or EBX,EBX ; - quit if op2 is not 0 + _quif ne ; - . . . + _shl ECX,1 ; - place sign in carry + _if e ; - if operand 2 is 0 + sub EAX,EAX ; - - set result to 0 + sub EDX,EDX ; - - . . . + ret ; - - return + _endif ; - endif + rcr ECX,1 ; - restore sign of op2 + _endguess ; endguess + + cmp byte ptr __real87,0; if 8087 not to be used + je short __FDMemu ; then emulate + +__FDM87: + push EDX ; push operand 1 + push EAX ; . . . + fld qword ptr [ESP] ; load operand 1 + push ECX ; push operand 2 + push EBX ; . . . + fmul qword ptr [ESP] ; multiply operand 1 by operand 2 + jmp _ret87 ; goto common epilogue + +__FDMemu: + push EBP ; save EBP + push EDI ; save EDI + push ESI ; save EDI + mov EDI,EDX ; get high part of op1 + mov ESI,ECX ; get high part of op2 + sar EDI,20 ; shift exponent to bottom, duplicating sign + sar ECX,20 ; shift exponent to bottom, duplicating sign + and EDI,0800007FFh ; isolate signs and exponent + and ECX,0800007FFh ; ... + rol EDI,16 ; rotate signs to bottom + rol ECX,16 ; ... + add CX,DI ; calc sign of result + rol EDI,16 ; rotate signs to top + rol ECX,16 ; ... + and EDX,000FFFFFh ; isolate fraction + and ESI,000FFFFFh ; isolate fraction + or DI,DI ; if op1 is a denormal + _if e ; then + inc DI ; - adjust exponent by 1 + _loop ; - loop (normalize it) 27-jul-90 + dec DI ; - - decrement exponent + _shl EAX,1 ; - - shift left 1 + _rcl EDX,1 ; - - ... + test EDX,00100000h ; - - check for implied 1 bit + _until ne ; - until normalized + _endif ; endif + or EDX,00100000h ; turn on implied 1 bit + or CX,CX ; if op2 is a denormal + _if e ; then + inc CX ; - adjust exponent by 1 + _loop ; - loop (normalize it) 27-jul-90 + dec CX ; - - decrement exponent + _shl EBX,1 ; - - shift left 1 + _rcl ESI,1 ; - - ... + test ESI,00100000h ; - - check for implied 1 bit + _until ne ; - until normalized + _endif ; endif + or ESI,00100000h ; turn on implied 1 bit + + _guess ; guess: overflow + add CX,DI ; - determine exponent of result + sub CX,03ffh ; - remove extra bias + _quif s ; - quit if exponent is negative + cmp CX,07FFh ; - quit if not overflow + _quif b ; - . . . + mov EAX,ECX ; - put sign into EAX + pop ESI ; - restore ESI + pop EDI ; - restore EDI + pop EBP ; - restore EBP + jmp F8OverFlow ; - handle overflow + _endguess ; endguess + cmp CX,-53 ; if exponent is too small + _if l ; then underflow + pop ESI ; - restore ESI + pop EDI ; - restore EDI + pop EBP ; - restore EBP + jmp F8UnderFlow ; - handle underflow + _endif ; endif + push ECX ; save sign and exponent + mov CL,11 ; shift fractions to top of registers + shld EDX,EAX,CL ; ... + shld EAX,EBP,CL ; ... + and EAX,0FFFFF800h ; ... + shld ESI,EBX,CL ; ... + shld EBX,EBP,CL ; ... + and EBX,0FFFFF800h ; ... + + sub EBP,EBP ; zero EBP + push ESI ; save high part of op2 + push EDX ; save high part of op1 + push EAX ; save low part of op1 + mul EBX ; low part of op1 * low part of op2 + xchg EAX,ESI ; ESI becomes start of the sticky bits + mov ECX,EDX ; save high part of result + pop EDX ; restore low part of op1 + mul EDX ; low part of op1 * high part of op2 + mov EDI,EDX ; save high part of product + add ECX,EAX ; add partial product + adc EDI,EBP ; ... + adc EBP,EBP ; ... + pop EAX ; restore high part of op1 + xchg EAX,EBX ; flip with low part of op2 + mul EBX ; high part of op1 * low part of op2 + add ECX,EAX ; add partial product + adc EDI,EDX ; ... + adc EBP,0 ; ... + mov EAX,EBX ; get high part of op1 + pop EDX ; restore high part of op2 + mul EDX ; high part of op1 * high part of op2 + add EAX,EDI ; add partial product + adc EDX,EBP ; ... + sub EBX,EBX ; get zero for zero fill + mov CL,10 ; shift result over + shrd EBX,EAX,CL ; ... get sticky bits 18-feb-91 + shrd EAX,EDX,CL ; ... + shrd EDX,EBX,CL ; ... + pop ECX ; restore sign and exponent + + _loop ; loop + test EDX,00200000h ; - test to see if bit in exponent field + _quif e ; - quit if not + shr EDX,1 ; - shift result right + rcr EAX,1 ; - . . . + rcr EBX,1 ; - save carry + inc CX ; - inc exponent for every shift + cmp CX,07FFh ; - quit if overflow + je mul_oflow ; - . . . + _endloop ; endloop + _shl EBX,1 ; get guard bit + _if c ; if set + _if e ; - if rest of sticky bits are 0 + or ESI,ESI ; - - check the bottom sticky bits + setne BL ; - - ... + shr EBX,1 ; - - if all sticky bits are zero + _if nc ; - - then + mov ESI,EAX ; - - - get bottom bit of result + shr ESI,1 ; - - - as rounding bit + _endif ; - - endif + _endif ; - endif + adc EAX,0 ; - round up + adc EDX,0 ; - ... + test EDX,00200000h ; - test to see if bit in exponent field + _if ne ; - if fraction overflowed + shr EDX,1 ; - - shift right + rcr EAX,1 ; - - ... + inc CX ; - - increment exponent + cmp CX,07FFh ; - - quit if overflow + je mul_oflow ; - - . . . + _endif ; - endif + _endif ; endif + or CX,CX ; if exponent <= 0 + _if le ; then (denormal result) + _if e ; - if exponent = 0 + mov CL,1 ; - - set shift count to 1 + _else ; - else + neg CX ; - - negate to get shift count + dec CX ; - - adjust + _endif ; - endif + sub EBX,EBX ; - for zero fill + shrd EAX,EDX,CL ; - align the fraction + shrd EDX,EBX,CL ; - ... + sub CX,CX ; - set exponent to 0 + _endif ; endif + and EDX,000FFFFFh ; isolate fraction + mov ESI,ECX ; get copy of sign + ror ECX,11 ; get exponent + _shl ESI,1 ; get sign + rcr ECX,1 ; put it in + and ECX,0FFF00000h ; isolate sign and exponent + or EDX,ECX ; place it in result + pop ESI ; restore ESI + pop EDI ; restore EDI + pop EBP ; restore EBP + ret ; return + +mul_oflow: ; overflow + mov EAX,ECX ; get sign of infinity + pop ESI ; restore ESI + pop EDI ; restore EDI + pop EBP ; restore EBP + jmp F8OverFlow ; handle overflow + endproc __FDM + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm new file mode 100644 index 000000000..6460c1ce8 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm @@ -0,0 +1,59 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;======================================================================== +;== Name: FDN == +;== Operation: Floating double negate == +;== Inputs: EDX high word of float == +;== Outputs: EDX new high word of float == +;== Volatile: none == +;======================================================================== +include mdef.inc +include struct.inc + + modstart fdn386 + + xdefp __FDN + + defpe __FDN + test EDX,EDX ; if non zero number then + _if e + test EAX,EAX + _endif + _if ne ; ... + xor EDX,80000000h ; - flip the sign bit + _endif ; endif + ret ; and return!!! + endproc __FDN + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm new file mode 100644 index 000000000..9fbe5461a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm @@ -0,0 +1,180 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + + modstart fprem386 + + xdefp __fprem_ + +; +; EDX:EAX ECX:EBX +; void fprem( double x, double modulus, int *quot, double *rem ) +; + defpe __fprem_ + push EBP ; save BP + mov EBP,ESP ; get access to parms + push EDX ; save registers + push ECX ; ... + push EBX ; ... + push EAX ; ... + mov EAX,8[EBP] ; get argument x + mov EDX,12[EBP] ; ... + mov EBX,16[EBP] ; get modulus + mov ECX,20[EBP] ; ... + or ECX,ECX ; if modulus is zero + _if e ; then + sub EAX,EAX ; - set result to 0 + mov EBX,24[EBP] ; - quot = 0 + mov [EBX],EAX ; - ... + mov EBX,28[EBP] ; - remainder = 0 + mov [EBX],EAX ; - ... + mov 4[EBX],EAX ; - ... + pop EAX ; - restore registers + pop EBX ; - ... + pop ECX ; - ... + pop EDX ; - ... + pop EBP ; - restore EBP + ret ; - return + _endif ; endif + push ESI ; save ESI + push EDI ; save EDI + push EDX ; save sign of operand + push ECX ; save high part of modulus + + mov ESI,EDX ; get most sig word of op1 + mov EDI,ECX ; get most sig word of op2 + and ESI,7FF00000h ; isolate exponent + and EDI,7FF00000h ; isolate exponent of modulus + and EDX,000FFFFFh ; isolate mantissa of op1 + and ECX,000FFFFFh ; isolate mantissa of modulus + or EDX,00100000h ; set implied 1 bit + or ECX,00100000h ; ... + sub ESI,EDI ; calculate difference in exponents + _if ge ; if operand >= modulus + sub EDI,EDI ; - set quotient to 0 + _loop ; - loop + _guess ; - - guess + cmp ECX,EDX ; - - - The purpose of this guess is to + _quif ne ; - - - determine if the divisor will subtract + cmp EBX,EAX ; - - - + je try ; - - - + _endguess ; - - endguess + _if c ; - - if the carry is set (ie the modulus will + ; - - - definitely subtract from the dividend + ; - - - without a borrow +try: + sub EAX,EBX ; - - - subtract divisor from dividend + sbb EDX,ECX ; - - - . . . + stc ; - - - set carry to indicate that modulus was + ; - - - successfully subtracted from dividend + _endif ; - - endif +didnt_go: _rcl EDI,1 ; - - rotate 1 (if carry set) into quotient word + sub ESI,00100000h ; - - adjust difference in exponents + jl _done ; - - quit if done + _shl EAX,1 ; - - shift dividend left + _rcl EDX,1 ; - - . . . + cmp EDX,00200000h + jae try + +; If bit 5 of dividend is set here, we didnt subtract the modulus from the +; dividend (recall that the divisor has a 1 in the msb -- if we subtracted +; it from the dividend without a borrow, the dividend would not have a one +; in its msb to be shifted into bit 5 tested for in the condition above. If +; we are rotating a bit into bit 5, the dividend is now big enough that we +; can be sure of subtracting out the divisor without a borrow, as we have +; shifted it left one digit. + + cmp EDX,00100000h + _until b ; - until + + cmc ; - flip the carry bit + jmp short didnt_go ; - continue +_done: sub ESI,ESI ; - set SI to 0 +; normalize the remainder in AL:BX:CX:DX + _guess ; - guess: number is zero + or EAX,EAX ; - - quit if not zero + _quif ne ; - - ... + or EDX,EDX ; - - ... + _quif ne ; - - ... + _admit ; - admit: not zero + _loop ; - - loop + test EDX,00200000h; - - - quit if number is normalized + _quif ne ; - - - . . . + _rcl EAX,1 ; - - - shift result left + _rcl EDX,1 + sub ESI,00100000h; - - - decrement exponent + _endloop ; - - endloop + shr EDX,1 ; - - put in correct position + rcr EAX,1 ; - - . . . + add ESI,00100000h ; - - increment exponent + pop ECX ; - - get high part of modulus + push ECX ; - - save it again + and ECX,7FF00000h ; - - isolate exponent of modulus + add ESI,ECX ; - - adjust exponent of result + _endguess ; - endguess + _else ; else + add ESI,EDI ; - restore exponent + sub EDI,EDI ; - set quotient to 0 + _endif ; endif + and EDX,000FFFFFh ; keep just the fraction + add EDX,ESI ; update high order word + pop ECX ; restore high part of modulus + pop ESI ; restore sign + and ESI,080000000h ; isolate sign bit + or EDX,EDX ; test high word of remainder + _if ne ; if remainder is non-zero + or EDX,ESI ; - make remainder same sign as original opnd + _endif ; endif + xor ESI,ECX ; calc sign of quotient + _if s ; if quotient should be negative + neg EDI ; - negate quotient + _endif ; endif + mov ESI,24[EBP] ; get address of quotient + mov [ESI],EDI ; store quotient + mov ESI,28[EBP] ; get address of remainder + mov [ESI],EAX ; store remainder + mov 4[ESI],EDX ; ... + pop EDI ; restore EDI + pop ESI ; restore ESI + pop EAX ; restore registers + pop EBX ; ... + pop ECX ; ... + pop EDX ; ... + pop EBP ; restore EBP + ret ; return + endproc __fprem_ + + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm new file mode 100644 index 000000000..6773d7cba --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm @@ -0,0 +1,71 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> +;<> +;<> __FSC compares EAX with EDX +;<> if EAX > EDX, 1 is returned in EAX +;<> if EAX = EDX, 0 is returned in EAX +;<> if EAX < EDX, -1 is returned in EAX +;<> +;<> ========= === ======= +;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> +include mdef.inc +include struct.inc + + modstart fsc386 + + xdefp __FSC + + defpe __FSC + _guess have_cmp ; guess - comparison done + xor EAX,EDX ; - check if signs differ + _if ns ; - if signs are the same + xor EAX,EDX ; - - restore EAX + sub EAX,EDX ; - - find difference, EAX=0 if equal + _quif e,have_cmp ; - - done if mantissas also equal + ; - - carry=1 iff |EAX| < |EDX| + rcr EAX,1 ; - - EAX sign set iff |EAX| < |EDX| + xor EDX,EAX ; - - EDX sign set iff EAX < EDX + not EDX ; - - EDX sign set iff EAX > EDX + _endif ; - endif + sub EAX,EAX ; - clear result + _shl EDX,1 ; - carry=1 iff EAX > EDX + adc EAX,EAX ; - EAX = 1 iff EAX > EDX, else EAX = 0 + _shl EAX,1 ; - EAX = 2 iff EAX > EDX, else EAX = 0 + dec EAX ; - EAX = 1 iff EAX > EDX, else EAX = -1 + _endguess ; endguess + ret ; return with sign in EAX, conditions set + endproc __FSC + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm new file mode 100644 index 000000000..71538bcad --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm @@ -0,0 +1,89 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;========================================================================= +;== Name: FSFD == +;== Operation: Float single to float double conversion == +;== Inputs: EAX single precision float == +;== Outputs: EDX:EAX double precision float == +;== Volatile: none == +;========================================================================= +include mdef.inc +include struct.inc + + modstart fsfd386 + + xdefp __FSFD + + defpe __FSFD + _guess ; guess: number is 0.0 or -0.0 + mov EDX,EAX ; - get float + and EAX,7fffffffh ; - remove sign + _quif ne ; - quit if number is not +0.0 or -0.0 + _admit ; guess: number is +-infinity + cmp EAX,7f800000h ; - quit if not +-infinity + _quif ne ; - ... + or EDX,7ff00000h ; - set double precision infinity + sub EAX,EAX ; - ... + _admit ; admit: not a special number + test EAX,7f800000h ; - if exponent is 0 (denormal number) + _if e ; - then + or EDX,7F800000h ; - - set exponent to 0xFF + _loop ; - - loop (normalize the fraction) + sub EDX,00800000h ; - - - subtract 1 from exponent adjustment + _shl EAX,1 ; - - - shift fraction left + test EAX,00800000h ; - - - check to see if fraction is normalized + _until ne ; - - until normalized + and EDX,0FF800000h ; - - copy fraction back to EDX + and EAX,007FFFFFh ; - - ... + or EDX,EAX ; - - ... + sar EDX,3 ; - shift over 3 + and EDX,8FFFFFFFh ; - reset exponent extended bits + add EDX,28200000h ; - adjust exponent by (3FF - FF -7F + 1) shl 20 + _else ; - else + sar EDX,3 ; - shift over 3 + and EDX,8FFFFFFFh ; - reset exponent extended bits + cmp EAX,7F800000h ; - if number is not number (NaN) + _if a ; + or EDX,7FF00000h; - adjust exponent to NaN 7FF shl 20 + _else + add EDX,38000000h; - adjust exponent by (3FF-7F) shl 20 + _endif + _endif ; - endif + and EAX,7 ; - get bottom 3 bits of fraction + ror EAX,3 ; - shift them to the top + _endguess ; endguess + ret ; return + endproc __FSFD + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm new file mode 100644 index 000000000..ba5e2e3e5 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm @@ -0,0 +1,171 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;======================================================================== +;== Name: FSI4, FSU4, FSI2, FSU2, FSI1, FSU1 == +;== Operation: Convert single precision to integer == +;== Inputs: EAX single precision floating point == +;== Outputs: EAX integer value == +;== Volatile: none == +;== == +;== == +;== handle -1.0 -> 0xffffffff == +;======================================================================== +include mdef.inc +include struct.inc + + modstart fsi4386 + + xdefp __FSI4 + xdefp __FSU4 + xdefp __FSI2 + xdefp __FSU2 + xdefp __FSI1 + xdefp __FSU1 + + defpe __FSI4 + push ECX ; save cx + mov cl,7fh+31 ; maximum number 2^31-1 + call __FSI ; convert to integer + pop ECX ; restore cx + ret ; return (overflow already handled + endproc __FSI4 + + defpe __FSU4 + push ECX ; save cx + mov cl,7fh+32 ; maximum number 2^32-1 + call __FSU ; convert to integer + pop ECX ; restore cx + ret ; return if no overflow + endproc __FSU4 + + defpe __FSI2 + push ECX ; save cx + mov cl,7fh+15 ; maximum number 2^15-1 + call __FSI ; convert to integer + pop ECX ; restore cx + ret ; return (overflow already handled + endproc __FSI2 + + defpe __FSU2 + push ECX ; save cx + mov cl,7fh+16 ; maximum number 2^16-1 + call __FSU ; convert to integer + pop ECX ; restore cx + ret ; return if no overflow + endproc __FSU2 + + defpe __FSI1 + push ECX ; save cx + mov cl,7fh+7 ; maximum number 2^7-1 + call __FSI ; convert to integer + pop ECX ; restore cx + ret ; return (overflow already handled + endproc __FSI1 + + + defpe __FSU1 + push ECX ; save cx + mov cl,7fh+8 ; maximum number 2^8-1 + call __FSU ; convert to integer + pop ECX ; restore cx + ret ; return if no overflow + endproc __FSU1 + +__FSI proc near +__FSU: + or EAX,EAX ; check sign bit + jns short __FSAbs ; treat as unsigned if positive + call __FSAbs ; otherwise convert number + neg EAX ; negate the result + ret ; and return + endproc __FSI + +; 18-nov-87 AFS (for WATCOM C) +;__FSU proc near +; jmp +; or dx,dx ; check sign bit +; jns __FSAbs ; just convert if positive +; sub ax,ax ; return 0 if negative +; sub dx,dx ; ... +; ret +; endproc __FSU + +;======================================================================== +;== Name: FSAbs_ == +;== Inputs: EAX float == +;== CL maximum exponent excess $7f == +;== Outputs: EAX integer, absolute value of float == +;== if exponent >= maximum then 2^max - 1 == +;== returned == +;======================================================================== + +__FSAbs proc near + or EAX,EAX ; check if number 0 + je short retzero ; if so, just return it + _shl EAX,1 ; shift mantissa over + rol EAX,8 ; get exponent to bottom + cmp AL,7fh ; quit if number < 1.0 15-apr-91 + jb short uflow ; ... + mov CH,AL ; save exponent + stc ; set carry for implied bit + rcr EAX,1 ; put implied '1' bit in + shr EAX,8 ; remove exponent + cmp CH,CL ; check if exponent exceeds maximum + jae short retmax ; return maximum value if so + sub CH,7fh+23 ; calculate amount to shift (+ve -> left) + jae short m_left ; jump if left shift/no shift + xchg CH,CL ; get shift count + neg CL ; make positive + shr EAX,CL ; shift mantissa + ret ; return with number + +m_left: + _if ne ; done if exponent exactly 23 + mov CL,CH ; - get shift count + shl EAX,CL ; - shift number left + _endif ; endif + ret ; return + +retmax: mov EAX,0FFFFFFFFh ; return maximum value + sub CL,7Fh+32 ; subtract bias + 32 + neg CL ; get shift count + shr EAX,CL ; compute value + ret ; return + +uflow: +retzero:sub EAX,EAX ; ensure entire number 0 + ret ; return + endproc __FSAbs + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm new file mode 100644 index 000000000..19104f017 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm @@ -0,0 +1,150 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +; from float to signed/unsigned int64 +; +include mdef.inc +include struct.inc + + modstart fsi8386 + + xref __U8LS + xref __U8RS + +; Convert single precision float to unsigned 64-bit integer with truncation +; Input: [EAX] = 32-bit float +; Output: [EDX, EAX] = 64-bit integer + + xdefp __FSU8 + defp __FSU8 + push ECX ; save ECX + mov CL,7fh+64 ; maximum number 2^64-1 + call __FSU ; convert float to unsigned __int64 + pop ECX ; restore ECX + ret ; return + endproc __FSU8 + +; Convert single precision float to signed 64-bit integer with truncation +; Input: [EAX] = 32-bit float +; Output: [EDX, EAX] = 64-bit integer + + xdefp __FSI8 + defp __FSI8 + push ECX ; save ECX + mov CL,7fh+63 ; maximum number 2^63-1 + call __FSI ; convert float to signed __int64 + pop ECX ; restore ECX + ret ; return + endproc __FSI8 + +__FSI proc near +__FSU: ; what? they both do the same thing + or EAX,EAX ; check sign bit + jns short __FSAbs ; treat as unsigned if positive + call __FSAbs ; otherwise convert number + neg EDX ; negate the result + neg EAX ; + sbb EDX,0 ; + ret ; return + endproc __FSI + +__FSAbs proc near + or EAX,EAX ; check if number 0 + je short fltzero ; if so, just return 0 + _shl EAX,1 ; shift mantissa over + rol EAX,8 ; get exponent to bottom + cmp AL,7fh ; quit if number < 1.0 + jb short fltuflow ; ... + push EBX ; save EBX + mov CH,AL ; save exponent + stc ; set carry for implied bit + rcr EAX,1 ; put implied '1' bit in + shr EAX,8 ; remove exponent and extra bit + mov EDX,EAX ; put into 64-bit hi part + xor EAX,EAX ; zero 64-bit lo part + cmp CH,CL ; check if exponent exceeds maximum + jae short fltmax ; return maximum value if so + sub CH,7fh+55 ; calculate amount to shift (+ve -> left) + jae short fltm_left ; jump if left shift/no shift + xchg CH,CL ; get shift count + neg CL ; make positive + mov BX,CX + call __U8RS ; shift mantissa right + pop EBX ; restore EBX + ret ; return + +fltm_left: + _if ne ; done if exponent exactly 55 + mov BL,CH ; - get shift count + call __U8LS ; - shift mantissa left + _endif ; endif + pop EBX ; restore EBX + ret ; return + +; CL = 7fh+64 for unsigned +; 7fh+63 for signed +fltmax: + mov EAX,0FFFFFFFFh ; return maximum value + mov EDX,EAX ; + sub CL,7fh+64 ; subtract bias + 64, results in 0 or -1 + neg CL ; get shift count + mov BL,CL ; set shift count + call __U8RS ; shift mantissa right 1 bit for signed + pop EBX ; restore EBX + ret ; return + +fltuflow: + sub EAX,EAX ; ensure entire number 0 +fltzero: + sub EDX,EDX ; + ret ; return + endproc __FSAbs + +; Convert single precision float to unsigned 64-bit integer with rounding +; Input: [EAX] = 32-bit float + +; xdefp __RSU8 +; defp __RSU8 +; not implemented +; endproc __RSU8 + +; Convert single precision float to signed 64-bit integer with rounding +; Input: [EAX] = 32-bit float + +; xdefp __RSI8 +; defp __RSI8 +; not implemented +; endproc __RSI8 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm new file mode 100644 index 000000000..94b01ca7a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm @@ -0,0 +1,453 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: REAL*4 math library. +;* +;***************************************************************************** + + +; +; inputs: EAX - operand 1 (high word, low word resp. ) (op1) +; EDX - operand 2 (op2) +; +; operations are performed as op1 (*) op2 where (*) is the selected +; operation +; +; output: EAX - result +; +; F4Add, F4Sub - written 28-apr-84 +; - modified by A.Kasapi 15-may-84 +; - to: Calculate sign of result +; - Guard bit in addition for extra accuracy +; Add documentation +; F4Mul - written 16-may-84 +; - by Athos Kasapi +; F4DIV - written may-84 by " +; +include mdef.inc +include struct.inc + +.287 + modstart fsmth386 + + xref __8087 ; indicate that NDP instructions are present + + xref __fdiv_m32 + + datasegment + extrn __real87 : byte ; cstart + extrn __chipbug : byte +fsadd dd _chkadd +fsmul dd _chkmul +fsdiv dd _chkdiv + enddata + + + xref F4DivZero ; Fstatus + xref F4OverFlow ; Fstatus + xref F4UnderFlow ; Fstatus + + xdefp __FSA ; add real*4 to real*4 + xdefp __FSS ; subtract real*4 from real*4 + xdefp __FSM ; 4-byte real multiply + xdefp __FSD ; 4-byte real divide + + + defpe __FSS + or EDX,EDX ; if op2 is 0 + je short ret_op1 ; then return operand 1 + xor EDX,80000000h ; flip the sign of op2 and add + + defpe __FSA + or EDX,EDX ; if op2 is 0 + je short ret_op1 ; then return operand 1 + or EAX,EAX ; if op1 is 0 + _if e ; then + mov EAX,EDX ; - return operand 2 +ret_op1: ret ; - return + _endif ; endif + jmp fsadd + +__FSA87: + push EBP ; save EBP + mov EBP,ESP ; get access to stack + push EAX ; push operand 1 + fld dword ptr -4[EBP]; load operand 1 + push EDX ; push operand 2 + fadd dword ptr -8[EBP]; add operand 2 to operand 1 +_ret87: + fstp dword ptr -4[EBP]; store result + add ESP,4 ; clean up stack + fwait ; wait + pop EAX ; load result into EAX + cmp EAX,80000000H ; is result -0.0 + _if e ; if it is then + xor EAX,EAX ; - make it positive + _endif ; endif + pop EBP ; restore EBP + ret ; return + +__FSAemu: + push ECX ; save ECX + push EBX ; save EBX +;<> Scheme for calculating sign of result: +;<> The sign word is built and kept in CL +;<> Bits 0 and 1 hold the sum of the sign bits +;<> shifted out of op_1 and op_2 +;<> Bit 2 holds the sign of the larger operand. It is assumed to be +;<> op_1 until op_2 is found larger + + sub ECX,ECX ; clear ECX + _shl EAX,1 ; get sign of op1 + _rcl CL,1 ; + mov CH,CL ; + _shl CL,1 ; + _shl CL,1 ; + add CL,CH ; + rol EAX,8 ; get exponent of op1 into AL + _shl EDX,1 ; get sign of op2 + adc CL,0 ; place in CL + rol EDX,8 ; get exponent of op2 in DL + mov BL,AL ; get exponent of op1 + mov BH,DL ; get exponent of op2 + + mov AL,0 ; zero rest of fraction + stc ; put implied 1 bit into top bit of + rcr EAX,1 ; ... fraction + mov DL,0 ; zero rest of fraction + stc ; put implied 1 bit into top bit + rcr EDX,1 ; ... of fraction + + mov CH,BL ; assume op1 > op2 + sub BL,BH ; calculate difference in exponents + _if ne ; if different + _if b ; - if op1 < op2 + mov CH,BH ; - - get larger exponent for result + neg BL ; - - negate the shift count + xchg EAX,EDX ; - - flip operands + xor CL,4 + +;<> op_2 is larger, so its sign now occupies bit 2 of sign word. This +;<> information is only correct if the signs of op-1 and op-2 are different. +;<> Since we look past bit 1 for sign only if the signs are different, bit2 +;<> will supply the correct information when it is needed. We get the sign of +;<> op_2 by flipping the sign of op_1, already in bit 2 + + _endif ; - endif + xchg CL,BL ; - get shift count + cmp CL,32 ; - if count >= 32 + _if ge ; - then + sub EDX,EDX ; - - answer is 0 + _else ; - else + shr EDX,CL ; - - align fraction + _endif ; - endif + xchg CL,BL ; - put back + _endif ; endif + shr CL,1 ; get bit 0 of sign word - value is 0 if + ; both operands have same sign, 1 if not + _if nc ; if signs are the same + add EAX,EDX ; - add the fractions + _if c ; - if carry + rcr EAX,1 ; - - shift fraction right 1 bit + inc CH ; - - increment exponent + _if z ; - - if we overflowed + ror CL,1 ; - - - set sign of infinity + rcr EAX,1 ; - - - . . . + jmp short add_oflow;- - - handle overflow + _endif ; - - endif + _endif ; - endif + _else ; else (signs are different) + shr CL,1 ; - skip junk bit + sub EAX,EDX ; - subtract the fractions + _guess ; - guess + _quif nc ; - - quit if no borrow + inc CL ; - - sign := sign of op_2 + neg EAX ; - - negate the fraction + _admit ; - admit + or EAX,EAX ; - - quit if answer is not 0 + _quif ne ; - - . . . + pop EBX ; - - restore EBX + pop ECX ; - - restore ECX + ret ; - - return (answer is 0) + _endguess ; - endguess + _endif ; endif + + ; normalize the fraction + add EAX,00000080h ; round up fraction if required + mov AL,0 ; zero bottom 8 bits 10-jul-89 + _guess underflow ; guess + _quif nc ; - quit if round up didn't overflow frac + inc CH ; - adjust exponent + _admit ; admit + _loop ; - loop (shift until high bit appears) + _shl EAX,1 ; - - shift fraction left + _quif c,underflow ; - - quit if carry has appeared + dec CH ; - - decrement exponent + _until e ; - until underflow + jmp short add_uflow ; - handle underflow + _endguess ; endguess + mov AL,CH ; get exponent + ror EAX,8 ; rotate into position + ror CL,1 ; get sign bit + rcr EAX,1 ; shift it into result + pop EBX ; restore EBX + pop ECX ; restore ECX + ret ; return + +add_uflow: ; handle underflow + pop EBX ; restore EBX + pop ECX ; restore ECX + jmp F4UnderFlow ; goto underflow routine + +add_oflow: ; handle overflow + pop EBX ; restore EBX + pop ECX ; restore ECX + jmp F4OverFlow ; handle overflow + endproc __FSA + endproc __FSS + +;===================================================================== + + defpe __FSM + +;<> multiplies X by Y and places result in C. +;<> X2 and X1 represent the high and low words of X. Similarly for Y and C +;<> Special care is taken to use only six registers, so the code is a bit +;<> obscure + + _guess ; guess: answer not 0 + or EAX,EAX ; - see if first arg is zero + _quif e ; - quit if op1 is 0 + or EDX,EDX ; - quit if op2 is 0 + _quif e ; - . . . + jmp fsmul ; - perform multiplication + _endguess ; endguess + sub EAX,EAX ; set answer to 0 + ret ; return + +__FSM87: + push EBP ; save EBP + mov EBP,ESP ; get access to stack + push EAX ; push operand 1 + fld dword ptr -4[EBP]; load operand 1 + push EDX ; push operand 2 + fmul dword ptr -8[EBP]; mulitply operand 1 by operand 2 + jmp _ret87 ; goto common epilogue + +__FSMemu: + push ECX ; save ECX + _shl EAX,1 ; get sign of op1 + _rcl ECX,1 ; save it + _shl EDX,1 ; get sign of op2 + adc ECX,0 ; calc sign of result + ror ECX,1 ; move to the top + rol EAX,8 ; move exponent of op1 into AL + rol EDX,8 ; move exponent of op2 into DL + sub AL,7Fh ; remove bias from exponents + sub DL,7Fh ; . . . + add DL,AL ; add exponents + _if o ; if over or underflow + js short mul_oflow ; - report overflow if signed + jmp short mul_uflow ; - handle underflow + _endif ; endif + cmp DL,81h ; check for underflow + jle short mul_uflow ; quit if underflow + add DL,7fh+1 ; bias exponent + mov CL,DL ; save exponent + mov AL,0 ; zero rest of fraction + mov DL,0 ; ... + stc ; turn on implied 1 bit in fraction + rcr EAX,1 ; ... + stc ; turn on implied 1 bit in fraction + rcr EDX,1 ; ... + mul EDX ; calc fraction + or EDX,EDX ; check top bit + _if ns ; if not set + _shl EDX,1 ; - move left 1 + dec CL ; - decrement exponent + _endif ; endif + sar EDX,8 ; place fraction in correct location + adc EDX,0 ; round up + adc CL,0 ; increment exponent if necessary + jz short mul_oflow ; report overflow if required + shl EDX,9 ; get rid of implied 1 bit + mov DL,CL ; get exponent + ror EDX,8 ; rotate into position except for sign + _shl ECX,1 ; get sign + rcr EDX,1 ; place sign in result + mov EAX,EDX ; place in correct register + pop ECX ; restore ECX + ret ; return + +mul_uflow: ; underflow + pop ECX ; restore ECX + jmp F4UnderFlow ; . . . + +mul_oflow: ; overflow + mov EAX,ECX ; get sign + pop ECX ; restore ECX + jmp F4OverFlow ; report overflow + endproc __FSM + +;==================================================================== + + defpe __FSD + jmp fsdiv + +__FSDbad_div: + push EBP ; save EBP + mov EBP,ESP ; get access to stack + push EAX ; push operand 1 + fld dword ptr -4[EBP]; load operand 1 + push EDX ; push operand 2 + call __fdiv_m32 ; divide operand 1 by operand 2 + push EDX ; __fdiv_m32 popped operand 2, _ret87 wants it + jmp _ret87 ; goto common epilogue + +__FSD87: + push EBP ; save EBP + mov EBP,ESP ; get access to stack + push EAX ; push operand 1 + fld dword ptr -4[EBP]; load operand 1 + push EDX ; push operand 2 + fdiv dword ptr -8[EBP]; divide operand 1 by operand 2 + jmp _ret87 ; goto common epilogue + + +__FSDemu: + _shl EDX,1 ; shift sign of divisor into carry + _if e ; if divisor is zero + jmp F4DivZero ; - handle divide by zero + _endif ; endif + push ECX ; save ECX + _rcl ECX,1 ; save sign in ECX + _shl EAX,1 ; shift sign of dividend into carry + _if e ; if dividend is 0, then + pop ECX ; - restore ECX + ret ; - return + _endif ; endif + adc ECX,0 ; now calculate save sign of result in ECX + ror ECX,1 ; rotate sign to top + rol EAX,8 ; get exponent into AL + rol EDX,8 ; get exponent into DL + sub AL,7Fh ; calculate exponent of result + sub DL,7Fh ; . . . + sub AL,DL ; . . . + _if o ; if over or underflow + jns short div_uflow ; - handle underflow + _shl ECX,1 ; - get sign of infinity + rcr EAX,1 ; - . . . + jmp short div_oflow ; - handle overflow + _endif ; endif + cmp AL,81h ; check for underflow + jle short div_uflow ; . . . + add AL,7Fh ; restore bias to exponent + mov CH,AL ; save calculated exponent + mov AL,0 ; zero bottom of fraction + mov DL,0 ; ... + stc ; rotate implied '1'bit back into divisor + rcr EDX,1 ; . . . + stc ; rotate implied '1' bit into dividend + rcr EAX,1 ; . . . + push ECX ; save sign and exponent + mov ECX,EDX ; save divisor + mov EDX,EAX ; place dividend into EDX + sub EAX,EAX ; set rest to 0 + shr EDX,1 ; so we don't get a divide overflow trap + div ECX ; do the divide + pop ECX ; restore sign and exponent + or EAX,EAX ; check top bit + _if ns ; if not set + _shl EAX,1 ; - move left 1 + dec CH ; - decrement exponent + _endif ; endif + sar EAX,8 ; place fraction in correct location + adc EAX,0 ; round up + _guess ; guess have to inc exponent + _quif nc ; - quit if no carry + inc CH ; - increment exponent + _quif nz ; - quit if no overflow + mov EAX,ECX ; - get sign of infinity + jmp short div_oflow ; - handle overflow + _endguess ; endguess + shl EAX,9 ; get rid of implied 1 bit + mov AL,CH ; get exponent + ror EAX,8 ; rotate into position except for sign + _shl ECX,1 ; get sign + rcr EAX,1 ; place sign in result + pop ECX ; restore ECX + ret ; return to caller + +div_uflow: ; handle underflow + pop ECX ; restore ECX + jmp F4UnderFlow ; handle underflow + + +div_oflow: ; handle overflow + pop ECX ; restore ECX + jmp F4OverFlow ; handle overflow + endproc __FSD + + +_chkadd: call _chk8087 + jmp fsadd + +_chkmul: call _chk8087 + jmp fsmul + +_chkdiv: call _chk8087 + jmp fsdiv + + +_chk8087 proc near + push eax ; save AX + cmp byte ptr __real87,0 ; if real 80x87 NDP present + _if ne ; then + mov eax,offset __FSA87 ; - get addr of add rtn + mov fsadd,eax ; - ... + mov eax,offset __FSM87 ; - get addr of mul rtn + mov fsmul,eax ; - ... + test byte ptr __chipbug, 1 ; - if we've got a bad divider + _if ne ; - then + mov eax,offset __FSDbad_div ; - - get addr of div rtn + _else ; - else + mov eax,offset __FSD87 ; - - get addr of div rtn + _endif ; - endif + mov fsdiv,eax ; - ... + _else ; else + mov eax,offset __FSAemu ; - get addr of add rtn + mov fsadd,eax ; - ... + mov eax,offset __FSMemu ; - get addr of mul rtn + mov fsmul,eax ; - ... + mov eax,offset __FSDemu ; - get addr of div rtn + mov fsdiv,eax ; - ... + _endif ; endif + pop eax ; restore AX + ret ; return + endproc _chk8087 + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm new file mode 100644 index 000000000..b705ddc5d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm @@ -0,0 +1,56 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;======================================================================== +;== Name: FSN == +;== Operation: Floating single negate == +;== Inputs: EAX flaot value == +;== Outputs: EAX new float value == +;== Volatile: none == +;======================================================================== +include mdef.inc +include struct.inc + + modstart fsn386 + + xdefp __FSN + + defpe __FSN + or EAX,EAX ; if number not zero + _if ne ; then + xor EAX,80000000h ; - flip the sign bit + _endif ; endif + ret ; and return!!! + endproc __FSN + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm new file mode 100644 index 000000000..0b84d522f --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm @@ -0,0 +1,136 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; of AX:DX +; +include mdef.inc +include struct.inc +include fstatus.inc + + modstart fstat386 + + xref "C",__set_ERANGE + xref __FPE_exception_ + + datasegment + enddata + assume ss:nothing + + +FPS_OK = 0 +FPS_UNDERFLOW = 1 +FPS_OVERFLOW = 2 +FPS_DIVIDE_BY_0 = 3 +FPS_BAD_ARG = 4 + +jmps macro dsym + jmp short dsym + endm + + + xdefp F8UnderFlow + xdefp F4UnderFlow + xdefp F8InvalidOp + xdefp F8DivZero + xdefp F4DivZero + xdefp F8OverFlow + xdefp F4OverFlow + xdefp F8RetInf_ + xdefp _F8RetInf_ + + defpe F8UnderFlow + sub EDX,EDX ; . . . + + defpe F4UnderFlow +;; mov EAX,FPE_UNDERFLOW; indicate underflow +;; call __FPE_exception_; + sub EAX,EAX ; return a zero + ret ; return + endproc F4UnderFlow + endproc F8UnderFlow + + + defpe F8InvalidOp + mov EAX,FPE_ZERODIVIDE; indicate divide by 0 + call __FPE_exception_; + jmps F8RetInf9 ; return infinity + endproc F8InvalidOp + + defpe F8DivZero + mov EAX,FPE_ZERODIVIDE; indicate divide by 0 + call __FPE_exception_; + jmps F8RetInf9 ; return infinity + endproc F8DivZero + + defpe F8OverFlow +; +; F8RetInf( sign : int ) : reallong +; + defpe F8RetInf_ + defpe _F8RetInf_ + push EAX ; save sign of result + call __set_ERANGE ; errno = ERANGE + mov EAX,FPE_OVERFLOW ; indicate overflow + call __FPE_exception_; + pop EAX ; restore sign of result +F8RetInf9: and EAX,80000000h ; get sign + or EAX,7FF00000h ; set infinity + mov EDX,EAX ; + sub EAX,EAX ; ... + ret ; return + endproc _F8RetInf_ + endproc F8RetInf_ + endproc F8OverFlow + + + defpe F4DivZero + mov EAX,FPE_ZERODIVIDE; indicate divide by 0 + call __FPE_exception_; + jmps F4RetInf9 ; return infinity + endproc F4DivZero + + defpe F4OverFlow + defp F4RetInf ; return infinity + push EAX ; save sign of result + call __set_ERANGE ; errno = ERANGE + mov EAX,FPE_OVERFLOW ; indicate overflow + call __FPE_exception_; + pop EAX ; restore sign of result +F4RetInf9: and EAX,80000000h ; get sign + or EAX,7F800000h + ret + endproc F4RetInf + endproc F4OverFlow + + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm new file mode 100644 index 000000000..58e16bfc1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm @@ -0,0 +1,90 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +; +include mdef.inc +include struct.inc + + modstart i4fd386 + + xdefp __I4FD + xdefp __U4FD + +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] +;[] +;[] __I4FD convert signed 32-bit integer in EAX into double float +;[] __U4FD convert unsigned 32-bit integer in EAX into double float +;[] Input: EAX - 32-bit integer +;[] Output: EDX:EAX - double precision representation of integer +;[] +;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] + + defpe __I4FD + or EAX,EAX ; if number is negative + _if s ; then + neg EAX ; - negate number + mov EDX,00000BFFh ; - set exponent + _else ; else + +; convert unsigned 32-bit integer to double + + defpe __U4FD + mov EDX,000003FFh ; - set exponent + _endif ; endif + or EAX,EAX ; if number is not zero + _if ne ; then + push ECX ; - save ECX + bsr ECX,EAX ; - find most significant non-zero bit + mov CH,CL ; - save shift count + mov CL,31 ; - calculate # of bits to shift by + sub CL,CH ; - ... + shl EAX,CL ; - shift bits into position + _shl EAX,1 ; - one more to get rid of implied 1 bit + mov CL,CH ; - get shift count + movzx ECX,CH ; - get shift count + add ECX,EDX ; - calculate exponent + mov EDX,EAX ; - get the bits + and EDX,0FFFFF000h ; - keep 20 bits + or EDX,ECX ; - get exponent in there + ror EDX,12 ; - rotate into position + shl EAX,20 ; - get last 12 bits into place + pop ECX ; - restore ECX + ret ; - return + _endif ; endif + sub EDX,EDX ; zero EDX + ret ; return + + endproc __U4FD + endproc __I4FD + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm new file mode 100644 index 000000000..78935b39c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm @@ -0,0 +1,82 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;======================================================================== +;== Name: I4FS, U4FS == +;== Operation: Convert Integer types to single precision == +;== Inputs: EAX, unsigned or signed integer == +;== Outputs: EAX single precision floating point == +;== Volatile: none == +;== == +;======================================================================== +include mdef.inc +include struct.inc + + modstart i4fs386 + + xdefp __I4FS + xdefp __U4FS + + + defpe __U4FS + or EAX,EAX ; if number is not zero + _if ne ; then + push ECX ; - save ECX + bsr ECX,EAX ; - find most significant non-zero bit + mov CH,CL ; - save shift count + neg CL ; - calculate # of bits to rotate by + add CL,23 ; - ... + and CL,1fh ; - just keep last 5 bits + rol EAX,CL ; - shift bits into position + and EAX,007FFFFFh ; - mask out sign and exponent bits + mov CL,CH ; - get shift count + add CL,7Fh ; - calculate exponent + and ECX,0FFh ; - isolate exponent + shl ECX,23 ; - shift exponent into position + or EAX,ECX ; - place into result + pop ECX ; - restore ECX + _endif ; endif + ret ; return + + endproc __U4FS + + defpe __I4FS + or EAX,EAX ; check sign + jns __U4FS ; if positive, just convert + neg EAX ; take absolute value of number + call __U4FS ; convert to FS + or EAX,80000000h ; set sign bit on + ret ; and return + endproc __I4FS + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm new file mode 100644 index 000000000..597b4c0a5 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm @@ -0,0 +1,224 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +;======================================================================== +;== Name: I8D == +;== Operation: Signed 8 byte divide == +;== Inputs: EDX;EAX Dividend == +;== ECX;EBX Divisor == +;== Outputs: EDX;EAX Quotient == +;== ECX;EBX Remainder (same sign as dividend) == +;== Volatile: none == +;== same sign as dividend for == +;== consistency with 8086 idiv == +;== and so (a/b)*b + a%b == a == +;== to get a 64-bit version for 386== +;======================================================================== +include mdef.inc +include struct.inc + + modstart i8d + + xdefp __I8D + + defpe __I8D + or edx,edx ; check sign of dividend + js divneg ; handle case where dividend < 0 + or ecx,ecx ; check sign of divisor + js notU8D ; easy case if it is also positive + + ; dividend >= 0, divisor >= 0 + docall __U8D ; - ... + ret ; - ... + + ; dividend >= 0, divisor < 0 +notU8D: neg ecx ; take positive value of divisor + neg ebx ; ... + sbb ecx,0 ; ... + docall __U8D ; do unsigned division + neg edx ; negate quotient + neg eax ; ... + sbb edx,0 ; ... + ret ; and return + +divneg: ; dividend is negative + neg edx ; take absolute value of dividend + neg eax ; ... + sbb edx,0 ; ... + or ecx,ecx ; check sign of divisor + jns negres ; negative result if divisor > 0 + + ; dividend < 0, divisor < 0 + neg ecx ; negate divisor too + neg ebx ; ... + sbb ecx,0 ; ... + docall __U8D ; and do unsigned division + neg ecx ; negate remainder + neg ebx ; ... + sbb ecx,0 ; ... + ret ; and return + + ; dividend < 0, divisor >= 0 +negres: docall __U8D ; do unsigned division + neg ecx ; negate remainder + neg ebx ; ... + sbb ecx,0 ; ... + neg edx ; negate quotient + neg eax ; ... + sbb edx,0 ; ... + ret ; and return + + endproc __I8D + +;======================================================================== +;== Name: U8D == +;== Operation: Unsigned 8 byte divide == +;== Inputs: EDX;EAX Dividend == +;== ECX;EBX Divisor == +;== Outputs: EDX;EAX Quotient == +;== ECX;EBX Remainder == +;== Volatile: none == +;======================================================================== + + xdefp __U8D + + defpe __U8D + or ecx,ecx ; check for easy case + jne noteasy ; easy if divisor is 16 bit + dec ebx ; decrement divisor + _if ne ; if not dividing by 1 + inc ebx ; - put divisor back + cmp ebx,edx ; - if quotient will be >= 64K + _if be ; - then +; +; 12-aug-88, added thanks to Eric Christensen from Fox Software +; divisor < 64K, dividend >= 64K, quotient will be >= 64K +; +; *note* this sequence is used in ltoa's #pragmas; any bug fixes +; should be reflected in ltoa's code bursts +; + mov ecx,eax ; - - save low word of dividend + mov eax,edx ; - - get high word of dividend + sub edx,edx ; - - zero high part + div ebx ; - - divide bx into high part of dividend + xchg eax,ecx ; - - swap high part of quot,low word of dvdnd + _endif ; - endif + div ebx ; - calculate low part + mov ebx,edx ; - get remainder + mov edx,ecx ; - get high part of quotient + sub ecx,ecx ; - zero high part of remainder + _endif ; endif + ret ; return + + +noteasy: ; have to work to do division +; +; check for divisor > dividend +; + _guess ; guess: divisor > dividend + cmp ecx,edx ; - quit if divisor <= dividend + _quif b ; - . . . + _if e ; - if high parts are the same + cmp ebx,eax ; - - compare the lower order words + _if be ; - - if divisor <= dividend + sub eax,ebx ; - - - calulate remainder + mov ebx,eax ; - - - ... + sub ecx,ecx ; - - - ... + sub edx,edx ; - - - quotient = 1 + mov eax,1 ; - - - ... + ret ; - - - return + _endif ; - - endif + _endif ; - endif + sub ecx,ecx ; - set divisor = 0 (this will be quotient) + sub ebx,ebx ; - ... + xchg eax,ebx ; - return remainder = dividend + xchg edx,ecx ; - and quotient = 0 + ret ; - return + _endguess ; endguess + push ebp ; save work registers + push esi ; ... + push edi ; ... + sub esi,esi ; zero quotient + mov edi,esi ; ... + mov ebp,esi ; and shift count +moveup: ; loop until divisor > dividend + _shl ebx,1 ; - divisor *= 2 + _rcl ecx,1 ; - ... + jc backup ; - know its bigger if carry out + inc ebp ; - increment shift count + cmp ecx,edx ; - check if its bigger yet + jb moveup ; - no, keep going + ja divlup ; - if below, know we're done + cmp ebx,eax ; - check low parts (high parts equal) + jbe moveup ; until divisor > dividend +divlup: ; division loop + clc ; clear carry for rotate below + _loop ; loop + _loop ; - loop + _rcl esi,1 ; - - shift bit into quotient + _rcl edi,1 ; - - . . . + dec ebp ; - - quif( -- shift < 0 ) NB carry not changed + js donediv ; - - ... +backup: ; - - entry to remove last shift + rcr ecx,1 ; - - divisor /= 2 (NB also used by 'backup') + rcr ebx,1 ; - - ... + sub eax,ebx ; - - dividend -= divisor + sbb edx,ecx ; - - c=1 iff it won't go + cmc ; - - c=1 iff it will go + _until nc ; - until it won't go + _loop ; - loop + _shl esi,1 ; - - shift 0 into quotient + _rcl edi,1 ; - - . . . + dec ebp ; - - going to add, check if done + js toomuch ; - - if done, we subtracted to much + shr ecx,1 ; - - divisor /= 2 + rcr ebx,1 ; - - ... + add eax,ebx ; - - dividend += divisor + adc edx,ecx ; - - c = 1 iff bit of quotient should be 1 + _until c ; - until divisor will go into dividend + _endloop ; endloop +toomuch: ; we subtracted too much + add eax,ebx ; dividend += divisor + adc edx,ecx ; ... +donediv: ; now quotient in di;si, remainder in dx;ax + mov ebx,eax ; move remainder to cx;bx + mov ecx,edx ; ... + mov eax,esi ; move quotient to dx;ax + mov edx,edi ; ... + pop edi ; restore registers + pop esi ; ... + pop ebp ; ... + ret ; and return + endproc __U8D + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm new file mode 100644 index 000000000..112e2b9dd --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm @@ -0,0 +1,101 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + + modstart i8fd386 + + xref __I8LS + xref __I8RS + +; Convert signed 64-bit integer to double precision float +; Input: [EDX, EAX] = 64-bit integer +; Output: [EDX, EAX] = double + + xdefp __I8FD + defp __I8FD + or EDX,EDX ; check sign + jns __U8FD ; if positive, just convert + neg EDX ; + neg EAX ; take absolute value of number + sbb EDX,0 ; + call __U8FD ; convert to FD + or EDX,80000000h ; set sign bit on + ret ; return + endproc __I8FD + +; Convert unsigned 64-bit integer to double precision float +; Input: [EDX, EAX] = 64-bit integer +; Output: [EDX, EAX] = double + + xdefp __U8FD + defp __U8FD + or EAX,EAX ; if lo is zero + _if e ; + or EDX,EDX ; and if hi is zero + _if e ; + ret ; - return + _endif + _endif ; endif + push ECX ; save ECX + push EBX ; save EBX + bsr ECX,EDX ; find most significant non-zero bit in hi + _if e ; if all zero bits + bsr ECX,EAX ; - find most significant non-zero bit in lo + _else ; else + add CL,32 ; - adjust shift count since hi was not 0 + _endif ; endif + push ECX ; save shift count + neg CL ; calculate # of bits to shift by + add CL,63-11 ; ... + mov EBX,ECX ; set up for call + or CL,CL ; if mantissa should move left + _if ge ; then + call __I8LS ; - shift left + _else ; else + neg BL ; - make positive + call __I8RS ; - shift right + _endif ; endif + pop ECX ; restore shift count + and EDX,000FFFFFh ; mask out sign and exponent bits + add CX,1023 ; calculate exponent (excess 1023) +; and ECX,0FFFh ; isolate exponent (not required) + shl ECX,20 ; shift exponent into position + or EDX,ECX ; place into result + pop EBX ; restore EBX + pop ECX ; restore ECX + ret ; return + endproc __U8FD + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm new file mode 100644 index 000000000..6bd99ec0d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm @@ -0,0 +1,102 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + + modstart i8fs386 + + xref __I8LS + xref __I8RS + +; Convert signed 64-bit integer to single precision float +; Input: [EDX, EAX] = 64-bit integer +; Output: [EAX] = 32-bit float + + xdefp __I8FS + defp __I8FS + or EDX,EDX ; check sign + jns __U8FS ; if positive, just convert + neg EDX ; + neg EAX ; take absolute value of number + sbb EDX,0 ; + call __U8FS ; convert to FS + or EAX,80000000h ; set sign bit on + ret ; return + endproc __I8FS + +; Convert unsigned 64-bit integer to single precision float +; Input: [EDX, EAX] = 64-bit integer +; Output: [EAX] = 32-bit float + + xdefp __U8FS + defp __U8FS + or EAX,EAX ; if lo is zero + _if e ; + or EDX,EDX ; and if hi is zero + _if e ; + ret ; - return + _endif + _endif ; endif + push ECX ; save ECX + push EBX ; save EBX + bsr ECX,EDX ; find most significant non-zero bit in hi + _if e ; if all zero bits + bsr ECX,EAX ; - find most significant non-zero bit in lo + _else ; else + add CL,32 ; - adjust shift count since hi was not 0 + _endif ; endif + push ECX ; save shift count + neg CL ; calculate # of bits to shift by + add CL,63-8 ; ... + mov EBX,ECX ; set up for call + or CL,CL ; if mantissa should move left + _if ge ; then + call __I8LS ; - shift left + _else ; else + neg BL ; - make positive + call __I8RS ; - shift right + _endif ; endif + pop ECX ; restore shift count + and EDX,007FFFFFh ; mask out sign and exponent bits + add CL,127 ; calculate exponent (excess 127) +; and ECX,0FFh ; isolate exponent (not required) + shl ECX,23 ; shift exponent into position + or EDX,ECX ; place into result + mov EAX,EDX ; single precision is only 32 bits + pop EBX ; restore EBX + pop ECX ; restore ECX + ret ; return + endproc __U8FS + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/src/i8m386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i8m386.asm similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/i8m386.asm rename to programs/develop/open watcom/trunk/clib/cgsupp/i8m386.asm diff --git a/programs/develop/open watcom/trunk/clib/src/i8rs386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/i8rs386.asm similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/i8rs386.asm rename to programs/develop/open watcom/trunk/clib/cgsupp/i8rs386.asm diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm new file mode 100644 index 000000000..b58a858d7 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm @@ -0,0 +1,79 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: Signed 4-byte division for 386. +;* +;***************************************************************************** + + +;======================================================================== +;== Name: LDIV == +;== Operation: Signed 4 byte divide == +;== Inputs: EAX Dividend == +;== EDX/ECX Divisor == +;== SS:ESI pointer to result structure == +;== Volatile: none == +;======================================================================== + +include mdef.inc +include struct.inc + +ifdef _PROFILE +include p5prof.inc +endif + modstart ldiv386 + + defpe div + xdefp "C",div + defpe ldiv + xdefp "C",ldiv + ifdef _PROFILE + P5Prolog + endif + ifdef __STACK__ + mov EAX,4[ESP] ; get numerator + mov ECX,8[ESP] ; get divisor + ; we don't need to save/restore ECX + else + push ECX ; save ECX + mov ECX,EDX ; get divisor + endif + cdq ; sign extend dividend + idiv ECX ; do the divide + mov [ESI],EAX ; store quotient + mov 4[ESI],EDX ; store remainder + ifndef __STACK__ + pop ECX ; restore ECX + endif + ifdef _PROFILE + P5Epilog + endif + ret ; return + endproc ldiv + endproc div + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm b/programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm new file mode 100644 index 000000000..9f939e371 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm @@ -0,0 +1,82 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: Signed 64-bit division for 386. +;* +;***************************************************************************** + + +;======================================================================== +;== Name: LLDIV == +;== Operation: Signed 8 byte divide == +;== Inputs: EAX;EDX Dividend == +;== ECX;EBX Divisor == +;== SS:ESI pointer to result structure == +;== Volatile: none == +;======================================================================== + +include mdef.inc +include struct.inc + +ifdef _PROFILE +include p5prof.inc +endif + modstart lldiv386 + + xref __I8D + +; defpe imaxdiv +; xdefp "C",imaxdiv + defpe lldiv + xdefp "C",lldiv + ifdef _PROFILE + P5Prolog + endif + ifdef __STACK__ + push EBX ; save EBX + mov EAX,08[ESP] ; get numerator + mov EDX,12[ESP] + mov EBX,16[ESP] ; get denominator + mov ECX,20[ESP] + endif + docall __I8D ; call long division routine + + mov [ESI],EAX ; store quotient + mov 4[ESI],EDX + mov 8[ESI],EBX ; store remainder + mov 12[ESI],ECX + ifdef __STACK__ + pop EBX ; restore EBX + endif + ifdef _PROFILE + P5Epilog + endif + ret ; return + endproc lldiv +; endproc imaxdiv + + endmod + end diff --git a/programs/develop/open watcom/trunk/clib/src/amblksiz.c b/programs/develop/open watcom/trunk/clib/heap/amblksiz.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/amblksiz.c rename to programs/develop/open watcom/trunk/clib/heap/amblksiz.c diff --git a/programs/develop/open watcom/trunk/clib/src/ambsptr.c b/programs/develop/open watcom/trunk/clib/heap/ambsptr.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/ambsptr.c rename to programs/develop/open watcom/trunk/clib/heap/ambsptr.c diff --git a/programs/develop/open watcom/trunk/clib/src/calloc.c b/programs/develop/open watcom/trunk/clib/heap/calloc.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/calloc.c rename to programs/develop/open watcom/trunk/clib/heap/calloc.c diff --git a/programs/develop/open watcom/trunk/clib/src/freect.c b/programs/develop/open watcom/trunk/clib/heap/freect.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/freect.c rename to programs/develop/open watcom/trunk/clib/heap/freect.c diff --git a/programs/develop/open watcom/trunk/clib/src/grownear.c b/programs/develop/open watcom/trunk/clib/heap/grownear.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/grownear.c rename to programs/develop/open watcom/trunk/clib/heap/grownear.c diff --git a/programs/develop/open watcom/trunk/clib/src/heap.h b/programs/develop/open watcom/trunk/clib/heap/heap.h similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/heap.h rename to programs/develop/open watcom/trunk/clib/heap/heap.h diff --git a/programs/develop/open watcom/trunk/clib/src/heapacc.h b/programs/develop/open watcom/trunk/clib/heap/heapacc.h similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/heapacc.h rename to programs/develop/open watcom/trunk/clib/heap/heapacc.h diff --git a/programs/develop/open watcom/trunk/clib/src/heapen.c b/programs/develop/open watcom/trunk/clib/heap/heapen.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/heapen.c rename to programs/develop/open watcom/trunk/clib/heap/heapen.c diff --git a/programs/develop/open watcom/trunk/clib/src/heapgrow.c b/programs/develop/open watcom/trunk/clib/heap/heapgrow.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/heapgrow.c rename to programs/develop/open watcom/trunk/clib/heap/heapgrow.c diff --git a/programs/develop/open watcom/trunk/clib/src/mem.c b/programs/develop/open watcom/trunk/clib/heap/mem.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/mem.c rename to programs/develop/open watcom/trunk/clib/heap/mem.c diff --git a/programs/develop/open watcom/trunk/clib/src/memavl.c b/programs/develop/open watcom/trunk/clib/heap/memavl.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/memavl.c rename to programs/develop/open watcom/trunk/clib/heap/memavl.c diff --git a/programs/develop/open watcom/trunk/clib/src/memmax.c b/programs/develop/open watcom/trunk/clib/heap/memmax.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/memmax.c rename to programs/develop/open watcom/trunk/clib/heap/memmax.c diff --git a/programs/develop/open watcom/trunk/clib/src/ncalloc.c b/programs/develop/open watcom/trunk/clib/heap/ncalloc.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/ncalloc.c rename to programs/develop/open watcom/trunk/clib/heap/ncalloc.c diff --git a/programs/develop/open watcom/trunk/clib/src/nexpand.c b/programs/develop/open watcom/trunk/clib/heap/nexpand.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nexpand.c rename to programs/develop/open watcom/trunk/clib/heap/nexpand.c diff --git a/programs/develop/open watcom/trunk/clib/src/nfree.c b/programs/develop/open watcom/trunk/clib/heap/nfree.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nfree.c rename to programs/develop/open watcom/trunk/clib/heap/nfree.c diff --git a/programs/develop/open watcom/trunk/clib/src/nheapchk.c b/programs/develop/open watcom/trunk/clib/heap/nheapchk.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nheapchk.c rename to programs/develop/open watcom/trunk/clib/heap/nheapchk.c diff --git a/programs/develop/open watcom/trunk/clib/src/nheapmin.c b/programs/develop/open watcom/trunk/clib/heap/nheapmin.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nheapmin.c rename to programs/develop/open watcom/trunk/clib/heap/nheapmin.c diff --git a/programs/develop/open watcom/trunk/clib/src/nheapset.c b/programs/develop/open watcom/trunk/clib/heap/nheapset.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nheapset.c rename to programs/develop/open watcom/trunk/clib/heap/nheapset.c diff --git a/programs/develop/open watcom/trunk/clib/src/nheapwal.c b/programs/develop/open watcom/trunk/clib/heap/nheapwal.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nheapwal.c rename to programs/develop/open watcom/trunk/clib/heap/nheapwal.c diff --git a/programs/develop/open watcom/trunk/clib/src/nmalloc.c b/programs/develop/open watcom/trunk/clib/heap/nmalloc.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nmalloc.c rename to programs/develop/open watcom/trunk/clib/heap/nmalloc.c diff --git a/programs/develop/open watcom/trunk/clib/src/nmemneed.c b/programs/develop/open watcom/trunk/clib/heap/nmemneed.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nmemneed.c rename to programs/develop/open watcom/trunk/clib/heap/nmemneed.c diff --git a/programs/develop/open watcom/trunk/clib/src/nmsize.c b/programs/develop/open watcom/trunk/clib/heap/nmsize.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nmsize.c rename to programs/develop/open watcom/trunk/clib/heap/nmsize.c diff --git a/programs/develop/open watcom/trunk/clib/src/nrealloc.c b/programs/develop/open watcom/trunk/clib/heap/nrealloc.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/nrealloc.c rename to programs/develop/open watcom/trunk/clib/heap/nrealloc.c diff --git a/programs/develop/open watcom/trunk/clib/src/sbrkwnt.c b/programs/develop/open watcom/trunk/clib/heap/sbrkwnt.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/sbrkwnt.c rename to programs/develop/open watcom/trunk/clib/heap/sbrkwnt.c diff --git a/programs/develop/open watcom/trunk/clib/memory/bcmp.c b/programs/develop/open watcom/trunk/clib/memory/bcmp.c new file mode 100644 index 000000000..6cb857cbb --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/bcmp.c @@ -0,0 +1,45 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + + +_WCRTLINK int bcmp( const void *s1, const void *s2, size_t n ) +/************************************************************/ +{ + if( memcmp( s1, s2, n ) == 0 ) { + return( 0 ); + } else { + return( 1 ); + } +} diff --git a/programs/develop/open watcom/trunk/clib/memory/bcopy.c b/programs/develop/open watcom/trunk/clib/memory/bcopy.c new file mode 100644 index 000000000..e425fbc67 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/bcopy.c @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + + +_WCRTLINK void bcopy( const void *s1, void *s2, size_t n ) +/********************************************************/ +{ + memmove( s2, s1, n ); +} diff --git a/programs/develop/open watcom/trunk/clib/memory/bzero.c b/programs/develop/open watcom/trunk/clib/memory/bzero.c new file mode 100644 index 000000000..adbe96a8b --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/bzero.c @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + + +_WCRTLINK void bzero( void *s, size_t n ) +/***************************************/ +{ + memset( s, 0, n ); +} diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemccpy.c b/programs/develop/open watcom/trunk/clib/memory/fmemccpy.c new file mode 100644 index 000000000..8bf9faa13 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemccpy.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +_WCRTLINK void _WCFAR *_fmemccpy( void _WCFAR *d, const void _WCFAR *s, int c, size_t cnt ) + { + char _WCFAR *dst = d; + const char _WCFAR *src = s; + for(;;) { + if( cnt == 0 ) break; + *dst = *src; + ++dst; + if( *src == c ) return( dst ); + ++src; + --cnt; + } + return( NULL ); + } diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemchr.c b/programs/develop/open watcom/trunk/clib/memory/fmemchr.c new file mode 100644 index 000000000..640e2c908 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemchr.c @@ -0,0 +1,56 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of fmemchr(). +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "xstring.h" + +/* locate the first occurrence of c in the initial n characters of the + object pointed to by s. + If the character c is not found, NULL is returned. +*/ + +#undef _fmemchr + +_WCRTLINK void _WCFAR *_fmemchr( const void _WCFAR *vs, int c, size_t n ) +{ +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fmemchr( vs, c, n ) ); +#else + const char _WCFAR *s = vs; + while( n ) { + if( *s == c ) return( (void _WCFAR *)s ); + ++s; + --n; + } + return( NULL ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemcmp.c b/programs/develop/open watcom/trunk/clib/memory/fmemcmp.c new file mode 100644 index 000000000..11bf87bc0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemcmp.c @@ -0,0 +1,52 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "xstring.h" +#undef _fmemcmp + +_WCRTLINK int _fmemcmp( const void _WCFAR *v1, + const void _WCFAR *v2, size_t len ) + { +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fmemcmp( v1, v2, len ) ); +#else + const unsigned char _WCFAR *s1 = v1; + const unsigned char _WCFAR *s2 = v2; + for( ; len; --len ) { + if( *s1 != *s2 ) return( *s1 - *s2 ); + ++s1; + ++s2; + } + return( 0 ); /* both operands are equal */ +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemcpy.c b/programs/develop/open watcom/trunk/clib/memory/fmemcpy.c new file mode 100644 index 000000000..78b51cbb2 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemcpy.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "xstring.h" +#undef _fmemcpy + +_WCRTLINK void _WCFAR *_fmemcpy( void _WCFAR *dst, const void _WCFAR *s, size_t len ) + { +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fmemcpy( dst, s, len ) ); +#else + const char _WCFAR *src = s; + char _WCFAR *p; + for( p = dst; len; --len ) { + *p++ = *src++; + } + return( dst ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemicmp.c b/programs/develop/open watcom/trunk/clib/memory/fmemicmp.c new file mode 100644 index 000000000..b841e1dff --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemicmp.c @@ -0,0 +1,54 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +_WCRTLINK int _fmemicmp( const void _WCFAR *v1, const void _WCFAR *v2, size_t len ) + { + unsigned char c1; + unsigned char c2; + const unsigned char _WCFAR *s1; + const unsigned char _WCFAR *s2; + + for( s1 = v1, s2 = v2 ; len; --len ) { + c1 = *s1; + if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A'; + c2 = *s2; + if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A'; + if( c1 != c2 ) return( c1 - c2 ); + ++s1; + ++s2; + } + return( 0 ); /* both operands are equal */ + } diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemmove.c b/programs/develop/open watcom/trunk/clib/memory/fmemmove.c new file mode 100644 index 000000000..2f200e214 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemmove.c @@ -0,0 +1,166 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +#if defined(__386__) + +#if defined(__FLAT__) +extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movefwd = \ + 0x06 /* push es */\ + 0x8e 0xc2 /* mov es,dx */\ + 0x1e /* push ds */\ + 0x96 /* xchg esi,eax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0x66 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0xf3 0xa4 /* rep movsb */\ + 0x1f /* pop ds */\ + 0x07 /* pop es */\ + parm [dx edi] [si eax] [ecx] \ + modify exact [edi esi ecx eax]; +#else +extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movefwd = \ + 0x1e /* push ds */\ + 0x96 /* xchg esi,eax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0x66 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0xf3 0xa4 /* rep movsb */\ + 0x1f /* pop ds */\ + parm [es edi] [si eax] [ecx] \ + modify exact [edi esi ecx eax]; +#endif + +#elif defined(M_I86) +#if defined(__SMALL_DATA__) +extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movebwd = \ + 0xfd /* std */\ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0x4e /* dec si */\ + 0x4f /* dec di */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0x46 /* inc si */\ + 0x47 /* inc di */\ + 0xf3 0xa4 /* rep movsb */\ + 0xfc /* cld */\ + 0x1f /* pop ds */\ + parm [es di] [si ax] [cx] \ + modify exact [di si cx ax]; + +extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movefwd = \ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0xf3 0xa4 /* rep movsb */\ + 0x1f /* pop ds */\ + parm [es di] [si ax] [cx] \ + modify exact [di si cx ax]; +#else +extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movebwd = \ + 0xfd /* std */\ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0x4e /* dec si */\ + 0x4f /* dec di */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0x46 /* inc si */\ + 0x47 /* inc di */\ + 0xf3 0xa4 /* rep movsb */\ + 0xfc /* cld */\ + 0x1f /* pop ds */\ + parm [es di] [si ax] [cx] \ + modify exact [di si cx ax]; + +extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len); +#pragma aux movefwd = \ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xf3 0xa5 /* rep movsw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0xf3 0xa4 /* rep movsb */\ + 0x1f /* pop ds */\ + parm [es di] [si ax] [cx] \ + modify exact [di si cx ax]; +#endif +#else +#error platform not supported +#endif + + +_WCRTLINK void _WCFAR *_fmemmove( void _WCFAR *t, const void _WCFAR *f, size_t len ) + { + char _WCFAR *to = t; + const char _WCFAR *from = f; + if( from == to ) { + return( to ); + } + if( from < to && from + len > to ) { /* if buffers are overlapped*/ +#if defined(__HUGE__) || defined(__386__) + to += len; + from += len; + while( len != 0 ) { + to--; + from--; + *to = *from; + len--; + } +#else + movebwd(( to + len ) - 1, ( from + len ) - 1, len ); +#endif + } else { + movefwd( to, from, len ); + } + return( to ); + } + diff --git a/programs/develop/open watcom/trunk/clib/memory/fmemset.c b/programs/develop/open watcom/trunk/clib/memory/fmemset.c new file mode 100644 index 000000000..04529a1e4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/fmemset.c @@ -0,0 +1,51 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "xstring.h" + +#undef _fmemset + +_WCRTLINK void _WCFAR *_fmemset( void _WCFAR *dst, int c, size_t len ) + { + +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fmemset( dst, c, len ) ); +#else + char _WCFAR *p; + for( p = dst; len; --len ) { + *p++ = c; + } + return( dst ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/memory/memccpy.c b/programs/develop/open watcom/trunk/clib/memory/memccpy.c new file mode 100644 index 000000000..94067fa7a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memccpy.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +_WCRTLINK void *memccpy( void *d, const void *s, int c, size_t cnt ) + { + char *dst = d; + const char *src = s; + for(;;) { + if( cnt == 0 ) break; + *dst = *src; + ++dst; + if( *src == c ) return( dst ); + ++src; + --cnt; + } + return( NULL ); + } diff --git a/programs/develop/open watcom/trunk/clib/memory/memchr.c b/programs/develop/open watcom/trunk/clib/memory/memchr.c new file mode 100644 index 000000000..e9e44ecc1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memchr.c @@ -0,0 +1,59 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of memchr() and wmemchr(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "xstring.h" + +/* locate the first occurrence of c in the initial n characters of the + object pointed to by s. + If the character c is not found, NULL is returned. +*/ + +_WCRTLINK VOID_WC_TYPE *__F_NAME(memchr,wmemchr)( const VOID_WC_TYPE *s, INT_WC_TYPE c, size_t n ) +{ +#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86) + return( _inline_memchr( s, c, n ) ); +#else + const CHAR_TYPE *cs = s; + + while( n ) { + if( *cs == c ) { + return( (VOID_WC_TYPE *)cs ); + } + ++cs; + --n; + } + return( NULL ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/memory/memcmp.c b/programs/develop/open watcom/trunk/clib/memory/memcmp.c new file mode 100644 index 000000000..995c79724 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memcmp.c @@ -0,0 +1,56 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of memcmp() and wmemcmp(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "xstring.h" + + +_WCRTLINK int __F_NAME(memcmp,wmemcmp)( const VOID_WC_TYPE *in_s1, const VOID_WC_TYPE *in_s2, size_t len ) +{ +#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86) + return( _inline_memcmp( in_s1, in_s2, len ) ); +#else + const CHAR_TYPE *s1 = in_s1; + const CHAR_TYPE *s2 = in_s2; + + for( ; len; --len ) { + if( *s1 != *s2 ) { + return( *s1 - *s2 ); + } + ++s1; + ++s2; + } + return( 0 ); /* both operands are equal */ +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/src/memcpy.c b/programs/develop/open watcom/trunk/clib/memory/memcpy.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/memcpy.c rename to programs/develop/open watcom/trunk/clib/memory/memcpy.c diff --git a/programs/develop/open watcom/trunk/clib/memory/memcpy_s.c b/programs/develop/open watcom/trunk/clib/memory/memcpy_s.c new file mode 100644 index 000000000..b5e2ed368 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memcpy_s.c @@ -0,0 +1,75 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of memcpy_s() - bounds-checking memcpy(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include "xstring.h" + +_WCRTLINK errno_t __F_NAME(memcpy_s,wmemcpy_s)( VOID_WC_TYPE * __restrict s1, + rsize_t s1max, + const VOID_WC_TYPE * __restrict s2, + rsize_t n ) +/*****************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // n <= RSIZE_MAX + // n <= s1max + // s1 and s2 no overlap + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_maxsize_msg( msg, n ) && + __check_constraint_a_gt_b_msg( msg, n, s1max ) && + __check_constraint_overlap_msg( msg, s1, s1max, s2, n ) ) { + + // now it's safe to use memcpy + __F_NAME(memcpy,wmemcpy)( s1, s2, n ); + rc = 0; + } else { + // Runtime-constraints violated, zero out destination array + if( (s1 != NULL) && __lte_rsizmax( s1max ) ) { + __F_NAME(memset,wmemset)( s1, 0, s1max ); + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/memory/memicmp.c b/programs/develop/open watcom/trunk/clib/memory/memicmp.c new file mode 100644 index 000000000..ab14497ab --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memicmp.c @@ -0,0 +1,54 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +_WCRTLINK int memicmp( const void *in_s1, const void *in_s2, size_t len ) + { + const unsigned char * s1 = (const unsigned char *)in_s1; + const unsigned char * s2 = (const unsigned char *)in_s2; + unsigned char c1; + unsigned char c2; + + for( ; len; --len ) { + c1 = *s1; + c2 = *s2; + if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A'; + if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A'; + if( c1 != c2 ) return( c1 - c2 ); + ++s1; + ++s2; + } + return( 0 ); /* both operands are equal */ + } diff --git a/programs/develop/open watcom/trunk/clib/memory/memmov_s.c b/programs/develop/open watcom/trunk/clib/memory/memmov_s.c new file mode 100644 index 000000000..1db9d8182 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memmov_s.c @@ -0,0 +1,74 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of memmove_s() - bounds-checking memmove(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include "xstring.h" + +_WCRTLINK errno_t __F_NAME(memmove_s,wmemmove_s)( VOID_WC_TYPE * __restrict s1, + rsize_t s1max, + const VOID_WC_TYPE * __restrict s2, + rsize_t n ) +/*******************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // n <= RSIZE_MAX + // n <= s1max + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_maxsize_msg( msg, n ) && + __check_constraint_a_gt_b_msg( msg, n, s1max ) ) { + + /* now it's safe to use memmove */ + __F_NAME(memmove,wmemmove)( s1, s2, n ); + rc = 0; + } else { + // Runtime-constraints violated, zero out destination array + if( (s1 != NULL) && __lte_rsizmax( s1max ) ) { + __F_NAME(memset,wmemset)( s1, 0, s1max ); + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/memmove.c b/programs/develop/open watcom/trunk/clib/memory/memmove.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/memmove.c rename to programs/develop/open watcom/trunk/clib/memory/memmove.c diff --git a/programs/develop/open watcom/trunk/clib/src/memset.c b/programs/develop/open watcom/trunk/clib/memory/memset.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/memset.c rename to programs/develop/open watcom/trunk/clib/memory/memset.c diff --git a/programs/develop/open watcom/trunk/clib/memory/memtest.c b/programs/develop/open watcom/trunk/clib/memory/memtest.c new file mode 100644 index 000000000..45c780eb6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/memtest.c @@ -0,0 +1,289 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +/* + * MEMTEST.C + * Non-exhaustive test of the C library memory manipulation functions. + */ + +#include +#include +#include +#if defined(__386__) || defined(M_I86) + #include +#endif +#ifdef __SW_BW + #include +#endif + + +#define VERIFY( exp ) if( !(exp) ) { \ + printf( "%s: ***FAILURE*** at line %d of %s.\n",\ + ProgramName, __LINE__, \ + strlwr(__FILE__) ); \ + NumErrors++; \ + exit(-1); \ + } + +void TestCompare( void ); +void TestCompareF( void ); +void TestCopy( void ); +void TestCopyF( void ); +void TestOverlap( void ); +void TestOverlapF( void ); +void TestMisc( void ); + + +char ProgramName[128]; /* executable filename */ +int NumErrors = 0; /* number of errors */ + + + +/**** +***** Program entry point. +****/ + +int main( int argc, char *argv[] ) +{ + #ifdef __SW_BW + FILE *my_stdout; + my_stdout = freopen( "tmp.log", "a", stdout ); + if( my_stdout == NULL ) { + fprintf( stderr, "Unable to redirect stdout\n" ); + exit( -1 ); + } + #endif + + /*** Initialize ***/ + strcpy( ProgramName, strlwr(argv[0]) ); /* store filename */ + + /*** Test various functions ***/ + TestCompare(); /* comparing stuff */ + TestCopy(); /* copying stuff */ + TestOverlap(); /* test overlapping copy */ + TestMisc(); /* other stuff */ + + #if defined(__386__) || defined(M_I86) + TestCompareF(); + TestCopyF(); + TestOverlapF(); + #endif + + /*** Print a pass/fail message and quit ***/ + if( NumErrors!=0 ) { + printf( "%s: SUCCESS.\n", ProgramName ); + return( EXIT_SUCCESS ); + } + printf( "Tests completed (%s).\n", strlwr( argv[0] ) ); + #ifdef __SW_BW + { + fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) ); + fclose( my_stdout ); + _dwShutDown(); + } + #endif + return( 0 ); +} + + + +/**** +***** Test memcmp(), memicmp(), and memchr(). +****/ + +void TestCompare( void ) +{ + char buf[80]; + char * ptr; + int status; + + strcpy( buf, "Foo !" ); /* initialize string */ + + status = memcmp( buf, "Foo", 3 ); /* compare */ + VERIFY( status == 0 ); + + status = memcmp( buf, "Foo!", 4 ); /* compare */ + VERIFY( status != 0 ); + + status = memicmp( buf, "FOO", 3 ); /* compare */ + VERIFY( status == 0 ); + + status = memicmp( buf, "fOo!", 4 ); /* compare */ + VERIFY( status != 0 ); + + ptr = memchr( buf, '~', 6 ); /* try to find a tilde */ + VERIFY( ptr == NULL ); + + ptr = memchr( buf, '!', 6 ); /* find the '!' */ + VERIFY( ptr == buf+4 ); +} + + +#if defined(__386__) || defined(M_I86) +void TestCompareF( void ) +{ + char buf[80]; + char __far * ptr; + int status; + + strcpy( buf, "Foo !" ); /* initialize string */ + + status = _fmemcmp( buf, "Foo", 3 ); /* compare */ + VERIFY( status == 0 ); + + status = _fmemcmp( buf, "Foo!", 4 ); /* compare */ + VERIFY( status != 0 ); + + ptr = _fmemchr( buf, '~', 6 ); /* try to find a tilde */ + VERIFY( ptr == NULL ); + + ptr = _fmemchr( buf, '!', 6 ); /* find the '!' */ + VERIFY( ptr == buf+4 ); +} +#endif + + + +/**** +***** Test memcpy(), memccpy(), and movedata(). +****/ + +void TestCopy( void ) +{ + char bufA[80], bufB[80]; + + strcpy( bufB, "Hello, world!" ); /* initialize bufB */ + memccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */ + VERIFY( !memcmp(bufA, "Hello", 5) ); /* ensure copied ok */ + + memcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */ + VERIFY( !strcmp(bufA, bufB) ); /* ensure copied ok */ +} + + +#if defined(__386__) || defined(M_I86) +void TestCopyF( void ) +{ + char __far bufA[80], bufB[80]; + char __far testStr[] = "Foo Bar Goober Blah"; + + strcpy( bufB, "Hello, world!" ); /* initialize bufB */ + _fmemccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */ + VERIFY( !_fmemcmp(bufA, "Hello", 5) ); /* ensure copied ok */ + + _fmemcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */ + VERIFY( !_fstrcmp(bufA, bufB) ); /* ensure copied ok */ + + movedata( FP_SEG(bufA), FP_OFF(bufA), /* copy data */ + FP_SEG(testStr), FP_OFF(testStr), + _fstrlen(testStr) ); + VERIFY( !_fmemcmp(bufA, testStr, _fstrlen(testStr)) ); +} +#endif + + + +/**** +***** Test memmove(). +****/ + +void TestOverlap( void ) +{ + char bufA[80], bufB[80]; + + strcpy( bufA, " Hello, world!" ); /* initialize string */ + + memmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */ + VERIFY( !strcmp(bufB, bufA) ); + + memmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */ + VERIFY( !strcmp(bufA, "Hello, world!!") ); + + memmove( bufA+1, bufA, strlen(bufA+1) ); + VERIFY( !strcmp(bufA, "HHello, world!") ); +} + + +#if defined(__386__) || defined(M_I86) +void TestOverlapF( void ) +{ + char bufA[80], bufB[80]; + + strcpy( bufA, " Hello, world!" ); /* initialize string */ + + _fmemmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */ + VERIFY( !strcmp(bufB, bufA) ); + + _fmemmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */ + VERIFY( !strcmp(bufA, "Hello, world!!") ); + + _fmemmove( bufA+1, bufA, strlen(bufA+1) ); + VERIFY( !strcmp(bufA, "HHello, world!") ); +} +#endif + + + +/**** +***** Test memset(), _fmemset(), and swab(). +****/ + +void TestMisc( void ) +{ + char bufA[80], bufB[80]; + void * addr; + int count; + + addr = memset( bufA, 0x00, 80 ); /* zero out memory */ + VERIFY( addr == bufA ); + + for( count=0; count<80; count++ ) /* ensure all zero bytes */ + VERIFY( bufA[count] == 0x00 ); + + #if defined(__386__) || defined(M_I86) + { + void __far * addrFar; + addrFar = _fmemset( bufB, 0x00, 80 ); /* zero out memory */ + VERIFY( addrFar == bufB ); + + for( count=0; count<80; count++ ) { /* ensure all zero bytes */ + VERIFY( bufB[count] == 0x00 ); + } + } + #else + memset( bufB, 0x00, 80 ); /* zero out memory */ + #endif + + strcpy( bufA, "eHll,ow rodl" ); /* initialize string */ + swab( bufA, bufB, strlen(bufA) ); /* swap pairs of characters */ + VERIFY( !strcmp(bufB, "Hello, world") ); /* ensure swapped ok */ +} diff --git a/programs/develop/open watcom/trunk/clib/memory/movedata.c b/programs/develop/open watcom/trunk/clib/memory/movedata.c new file mode 100644 index 000000000..b29c51a27 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/movedata.c @@ -0,0 +1,46 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of movedata(). +* +****************************************************************************/ + + +#include "variety.h" +/* Inline variant must always be used, no equivalent exists */ +#ifndef __INLINE_FUNCTIONS__ + #define __INLINE_FUNCTIONS__ +#endif +#include "xstring.h" + +#undef movedata + + +_WCRTLINK void movedata( unsigned fromseg, unsigned fromoff, + unsigned toseg, unsigned tooff, unsigned len ) +{ + _inline_movedata( fromseg, fromoff, toseg, tooff, len ); +} diff --git a/programs/develop/open watcom/trunk/clib/memory/swab.c b/programs/develop/open watcom/trunk/clib/memory/swab.c new file mode 100644 index 000000000..1cb2e3f4e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/memory/swab.c @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +_WCRTLINK void swab( char *src, char *dst, int n ) + { + char c; + + for( n = n >> 1; n; --n ) { + c = src[0]; /* 25-jun-90: just in case src and dst are the same */ + dst[0] = src[1]; + dst[1] = c; + dst += 2; + src += 2; + } + } diff --git a/programs/develop/open watcom/trunk/clib/search/bsearch.c b/programs/develop/open watcom/trunk/clib/search/bsearch.c new file mode 100644 index 000000000..c19a8277a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/bsearch.c @@ -0,0 +1,83 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#undef __INLINE_FUNCTIONS__ +#include +#include +#include "extfunc.h" + +/* + The old bsearch could SIGSEGV if the compare is done on elements + which are not within the given segment. The error occurs if the search + key is larger than the 'high' element (or lower than the 'low' member) + and 'low','mid' and 'high' are all equal (either from the start or + after several iterations). +*/ + +typedef int bcomp(); +#if defined(_M_IX86) + #pragma aux (__outside_CLIB) bcomp; +#endif + +_WCRTLINK void * bsearch( const void * key, + const void * base, + size_t nmemb, + size_t size, + int (*cmp)() ) + { + char *low; + char *high; + char *mid; + int cond; + bcomp *compar = cmp; + + if( nmemb == 0 ) { + return( NULL ); + } + low = (char *) base; + high = low + (nmemb-1) * size; +// JBS while( low <= high ) { + while( low < high ) { + mid = low + ( (high-low)/size/2 ) * size; + cond = (*compar)( key, mid ); + if( cond == 0 ) return( mid ); + if( cond < 0 ) { /* key < mid */ +// JBS high = mid - size; + high = mid; + } else { /* key > mid */ + low = mid + size; + } + } + if (low == high) return( (*compar)(key, low) ? NULL : low ); + return( NULL ); + } diff --git a/programs/develop/open watcom/trunk/clib/search/bsrch_s.c b/programs/develop/open watcom/trunk/clib/search/bsrch_s.c new file mode 100644 index 000000000..17b27605a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/bsrch_s.c @@ -0,0 +1,84 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of bsearch_s() - bounds-checking bsearch(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#undef __INLINE_FUNCTIONS__ +#include +#include +#include "extfunc.h" + +typedef int bcomp(); +#ifdef _M_IX86 + #pragma aux (__outside_CLIB) bcomp; +#endif + +_WCRTLINK void * bsearch_s( const void * key, const void * base, + rsize_t nmemb, rsize_t size, + int (*compar)( const void *k, const void *y, void *context ), + void *context ) +/***********************************************************************/ +{ + char *low; + char *high; + char *mid; + int cond; + bcomp *comp = compar; + + /* runtime-constraints */ + // nmemb <= RSIZE_MAX + // size <= RSIZE_MAX + // if nmemb > 0 then key, base, compar not NULL + if( __check_constraint_maxsize( nmemb ) && + __check_constraint_maxsize( size ) && + ( (nmemb == 0) || __check_constraint_nullptr( key ) && + __check_constraint_nullptr( base ) && + __check_constraint_nullptr( compar )) ) { + + if( nmemb == 0 ) { /* empty array - nothing to do */ + return( NULL ); + } + low = (char *) base; + high = low + (nmemb - 1) * size; + while( low < high ) { + mid = low + ( (high - low) / size / 2 ) * size; + cond = (*comp)( key, mid, context ); + if( cond == 0 ) return( mid ); + if( cond < 0 ) { /* key < mid */ + high = mid; + } else { /* key > mid */ + low = mid + size; + } + } + if (low == high) return( (*comp)( key, low, context ) ? NULL : low ); + } + return( NULL ); +} diff --git a/programs/develop/open watcom/trunk/clib/search/lfind.c b/programs/develop/open watcom/trunk/clib/search/lfind.c new file mode 100644 index 000000000..96eded78c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/lfind.c @@ -0,0 +1,65 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "extfunc.h" +#undef __INLINE_FUNCTIONS__ +#include +#include + +typedef int lcomp( const void *, const void * ); +#if defined(_M_IX86) + #pragma aux (__outside_CLIB) lcomp; +#endif + +_WCRTLINK void *lfind( + const void *key, + const void *base, + unsigned *num, + unsigned width, + int (*compare)( + const void *, + const void * + ) + ) +{ + lcomp *cmp = (lcomp *)compare; + unsigned n; + + for( n = *num; n; --n ) + { + if( cmp( key, base ) == 0 ) + return( (void *)base ); + base = ((const char *)base) + width; + } + return( NULL ); +} diff --git a/programs/develop/open watcom/trunk/clib/search/lsearch.c b/programs/develop/open watcom/trunk/clib/search/lsearch.c new file mode 100644 index 000000000..35410a2ae --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/lsearch.c @@ -0,0 +1,68 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "extfunc.h" +#undef __INLINE_FUNCTIONS__ +#include +#include +#include + +typedef int lcomp( const void *, const void * ); +#if defined(_M_IX86) + #pragma aux (__outside_CLIB) lcomp; +#endif + +_WCRTLINK void *lsearch( + const void *key, + void *base, + unsigned *num, + unsigned width, + int (*compare)( + const void *, + const void * + ) + ) +{ + lcomp *cmp = (lcomp *)compare; + unsigned n; + + for( n = *num; n; --n ) + { + if( cmp( key, base ) == 0 ) + return( base ); + base = ((char *)base) + width; + } + memcpy( base, key, width ); + ++*num; + return( base ); +} diff --git a/programs/develop/open watcom/trunk/clib/search/qsort.c b/programs/develop/open watcom/trunk/clib/search/qsort.c new file mode 100644 index 000000000..49737cded --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/qsort.c @@ -0,0 +1,83 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#undef __INLINE_FUNCTIONS__ +#include +#include +#include "extfunc.h" + +typedef int qcomp( const void *, const void * ); +#if defined(_M_IX86) + #pragma aux (__outside_CLIB) qcomp; +#endif + + +/* Function to find the median value */ +static char *med3( char *a, char *b, char *c, qcomp cmp ) +{ + if( cmp( a, b ) > 0 ) { + if( cmp( a, c ) > 0 ) { + if( cmp( b, c ) > 0 ) { + return( b ); + } else { + return( c ); + } + } else { + return( a ); + } + } else { + if( cmp( a, c ) >= 0 ) { + return( a ); + } else { + if( cmp( b, c ) > 0 ) { + return( c ); + } else { + return( b ); + } + } + } +} + + +#ifdef __AXP__ + +#else + + #define FUNCTION_LINKAGE _WCRTLINK + #define FUNCTION_NAME qsort + #define PTRATTR + #define MED3 med3 + #define BYTESWAP byteswap + #include "qsortrtn.c" + +#endif diff --git a/programs/develop/open watcom/trunk/clib/search/qsort_s.c b/programs/develop/open watcom/trunk/clib/search/qsort_s.c new file mode 100644 index 000000000..a0966ebd1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/qsort_s.c @@ -0,0 +1,118 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of qsort_s() - bounds-checking qsort(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#undef __INLINE_FUNCTIONS__ +#include +#include +#include "extfunc.h" + +typedef int qcomp( const void *, const void *, void * ); +#if defined(_M_IX86) + #pragma aux (__outside_CLIB) qcomp; +#endif + + +/* Function to find the median value */ +static char *med3( char *a, char *b, char *c, qcomp cmp, void *context ) +{ + if( cmp( a, b, context ) > 0 ) { + if( cmp( a, c, context ) > 0 ) { + if( cmp( b, c, context ) > 0 ) { + return( b ); + } else { + return( c ); + } + } else { + return( a ); + } + } else { + if( cmp( a, c, context ) >= 0 ) { + return( a ); + } else { + if( cmp( b, c, context ) > 0 ) { + return( c ); + } else { + return( b ); + } + } + } +} + + +#ifdef __AXP__ + + #define FUNCTION_LINKAGE static + #define FUNCTION_NAME aligned_qsort + #define PTRATTR + #define MED3 med3 + #define BYTESWAP aligned_byteswap + #include "qsortr_s.c" + + #undef FUNCTION_NAME + #undef PTRATTR + #undef MED3 + #undef BYTESWAP + #define FUNCTION_NAME unaligned_qsort + #define PTRATTR __unaligned + #define BYTESWAP unaligned_byteswap + #define MED3(a,b,c,f,x) med3( (char*)(a), (char*)(b), (char*)(c), (f), (x) ) + #include "qsortr_s.c" + + _WCRTLINK errno_t qsort_s( void *in_base, rsize_t n, rsize_t size, + int (*compar)( const void *, const void *, void * ), + void *context ) + /*****************************************************************/ + { + /* + * If size%4 is 0 and the input base pointer is on a word boundary, + * call the aligned version of qsort. Otherwise, call the version + * that knows its pointers will be unaligned, so all the fixups can + * be done by qsort rather than by expensive OS exceptions. + */ + if( (size&3) == 0 && (((unsigned)in_base)&3) == 0 ) { + return( aligned_qsort( in_base, n, size, compar, context ) ); + } else { + return( unaligned_qsort( (__unaligned void *)in_base, n, size, compar, context ) ); + } + } + +#else + + #define FUNCTION_LINKAGE _WCRTLINK + #define FUNCTION_NAME qsort_s + #define PTRATTR + #define MED3 med3 + #define BYTESWAP byteswap + #include "qsortr_s.c" + +#endif diff --git a/programs/develop/open watcom/trunk/clib/search/qsortr_s.c b/programs/develop/open watcom/trunk/clib/search/qsortr_s.c new file mode 100644 index 000000000..ad9bf8fb4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/qsortr_s.c @@ -0,0 +1,360 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of qsort_s() - bounds-checking qsort(). +* Included by qsort_s.c. +* +****************************************************************************/ + + +/* Support OS/2 16-bit protected mode - will never get stack overflow */ +#define MAXDEPTH (sizeof( long ) * 8) + +#define SHELL 3 /* Shell constant used in shell sort */ + +typedef int WORD; +#define W sizeof( WORD ) + +/* + swap() is a macro that chooses between an in_line function call and + an exchange macro. +*/ +#define exch( a, b, t) ( t = a, a = b, b = t ) +#define swap( a, b ) \ + swaptype != 0 ? BYTESWAP( a, b, size ) : \ + ( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t ) + +/* + Note: The following assembly was timed against several other methods + of doing the same thing. The pragmas here were either fastest on all + machines tested, or fastest on most machines tested. (including an 8088, + 386 16mhz, 386 33mhz, and 486 25mhz). +*/ + +#if defined( __386__ ) + /* this is intended for 386 only... */ + void inline_swap( char *p, char *q, size_t size ); + #pragma aux inline_swap = \ + 0x06 /* push es */ \ + 0x1e /* push ds */ \ + 0x07 /* pop es */ \ + 0x0f 0xb6 0xd1 /* movzx edx,cl */ \ + 0xc1 0xe9 0x02 /* shr ecx,02H */ \ + 0x74 0x0b /* je L1 */ \ + 0x8b 0x07 /*L2 mov eax,[edi] */ \ + 0x87 0x06 /* xchg eax,[esi] */ \ + 0xab /* stosd */ \ + 0x83 0xc6 0x04 /* add esi,0004H */ \ + 0x49 /* dec ecx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x80 0xe2 0x03 /*L1 and dl,03H */ \ + 0x74 0x09 /* je L3 */ \ + 0x8a 0x07 /*L4 mov al,[edi] */ \ + 0x86 0x06 /* xchg al,[esi] */ \ + 0xaa /* stosb */ \ + 0x46 /* inc esi */ \ + 0x4a /* dec edx */ \ + 0x75 0xf7 /* jne L4 */ \ + /*L3 */ \ + 0x07 /* pop es */ \ + parm caller [esi] [edi] [ecx] \ + value \ + modify exact [esi edi ecx eax edx]; + #pragma aux byteswap parm [esi] [edi] [ecx] \ + modify exact [esi edi ecx eax edx]; + static void _WCNEAR byteswap( char *p, char *q, size_t size ) { + inline_swap( p, q, size ); + } + +#elif defined( M_I86 ) && defined( __BIG_DATA__ ) + void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size ); + #pragma aux inline_swap = \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0xd1 0xe9 /* shr cx,1 */ \ + 0x74 0x0b /* je L1 */ \ + 0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \ + 0x87 0x04 /* xchg ax,[si] */ \ + 0xab /* stosw */ \ + 0x46 /* inc si */ \ + 0x46 /* inc si */ \ + 0x49 /* dec cx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x73 0x07 /*L1 jnc L3 */ \ + 0x8a 0x04 /* mov al,[si] */ \ + 0x26 0x86 0x05 /* xchg al,es:[di] */ \ + 0x88 0x04 /* mov [si],al */ \ + 0x1f /*L3 pop ds */ \ + parm caller [dx si] [es di] [cx] \ + value \ + modify exact [si di cx ax]; + #pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax]; + static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) { + inline_swap( p, q, size ); + } + +#elif defined( M_I86 ) && defined( __SMALL_DATA__ ) + /* we'll ask for char __far *q to save us writing code to load es */ + void inline_swap( char *p, char _WCFAR *q, size_t size ); + #pragma aux inline_swap = \ + 0xd1 0xe9 /* shr cx,1 */ \ + 0x74 0x0b /* je L1 */ \ + 0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \ + 0x87 0x04 /* xchg ax,[si] */ \ + 0xab /* stosw */ \ + 0x46 /* inc si */ \ + 0x46 /* inc si */ \ + 0x49 /* dec cx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x73 0x07 /*L1 jnc L3 */ \ + 0x8a 0x04 /* mov al,[si] */ \ + 0x26 0x86 0x05 /* xchg al,es:[di] */ \ + 0x88 0x04 /* mov [si],al */ \ + /*L3 */ \ + parm caller [si] [es di] [cx] \ + value \ + modify exact [si di cx ax]; + #pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax]; + static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) { + inline_swap( p, q, size ); + } + +#else + /* this is an optimized version of a simple byteswap */ + #define inline_swap BYTESWAP + static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) { + long dword; + short word; + char byte; + + #if 1 /* this is for 32 bit machines */ + while( size > 3 ) { + dword = *(PTRATTR long *)p; + *(PTRATTR long *)p = *(PTRATTR long *)q; + *(PTRATTR long *)q = dword; + p += 4; + q += 4; + size -= 4; + } + if( size > 1 ) { + word = *(PTRATTR short *)p; + *(PTRATTR short *)p = *(PTRATTR short *)q; + *(PTRATTR short *)q = word; + p += 2; + q += 2; + size -= 2; + } + #else /* this is for 16 bit machines */ + while( size > 1 ) { + word = *(PTRATTR short *)p; + *(PTRATTR short *)p = *(PTRATTR short *)q; + *(PTRATTR short *)q = word; + p += 2; + q += 2; + size -= 2; + } + #endif + if( size ) { + byte = *p; + *p = *q; + *q = byte; + } + } +#endif + + +FUNCTION_LINKAGE errno_t FUNCTION_NAME( PTRATTR void *in_base, + rsize_t n, rsize_t size, + int (*compar)( const void *, const void *, void * ), + void *context ) +/*****************************************************************/ +{ + PTRATTR char *base = (PTRATTR char*) in_base; + PTRATTR char *p1; + PTRATTR char *p2; + PTRATTR char *pa; + PTRATTR char *pb; + PTRATTR char *pc; + PTRATTR char *pd; + PTRATTR char *pn; + PTRATTR char *pv; + PTRATTR char *mid; + WORD v; /* used in pivot initialization */ + WORD t; /* used in exch() macro */ + int comparison, swaptype, shell; + size_t count, r, s; + unsigned sp; + auto char *base_stack[MAXDEPTH]; + unsigned n_stack[MAXDEPTH]; + qcomp *cmp = (qcomp*)compar; + errno_t rc = -1; + + /* runtime-constraints */ + // n <= RSIZE_MAX + // size <= RSIZE_MAX + // if n > 0 then in_base, compar not NULL + if( __check_constraint_maxsize( n ) && + __check_constraint_maxsize( size ) && + ((n == 0) || __check_constraint_nullptr( in_base ) && + __check_constraint_nullptr( compar )) ) { + + if( n == 0 ) { /* empty array - nothing to do */ + return( 0 ); + } + + /* + Initialization of the swaptype variable, which determines which + type of swapping should be performed when swap() is called. + 0 for single-word swaps, 1 for general swapping by words, and + 2 for swapping by bytes. W (it's a macro) = sizeof(WORD). + */ + swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0; + sp = 0; + for( ;; ) { + while( n > 1 ) { + if( n < 16 ) { /* 2-shell sort on smallest arrays */ + for( shell = (size * SHELL) ; + shell > 0 ; + shell -= ((SHELL-1) * size) ) { + p1 = base + shell; + for( ; p1 < base + n * size; p1 += shell ) { + for( p2 = p1; + p2 > base && cmp( p2 - shell, p2, context ) > 0; + p2 -= shell ) { + swap( p2, p2 - shell ); + } + } + } + break; + } else { /* n >= 16 */ + /* Small array (15 < n < 30), mid element */ + mid = base + (n >> 1) * size; + if( n > 29 ) { + p1 = base; + p2 = base + ( n - 1 ) * size; + if( n > 42 ) { /* Big array, pseudomedian of 9 */ + s = (n >> 3) * size; + p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp, context ); + mid = MED3( mid - s, mid, mid + s, cmp, context ); + p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp, context ); + } + /* Mid-size (29 < n < 43), med of 3 */ + mid = MED3( p1, mid, p2, cmp, context ); + } + /* + The following sets up the pivot (pv) for partitioning. + It's better to store the pivot value out of line + instead of swapping it to base. However, it's + inconvenient in C unless the element size is fixed. + So, only the important special case of word-size + objects has utilized it. + */ + if( swaptype != 0 ) { /* Not word-size objects */ + pv = base; + swap( pv, mid ); + } else { /* Storing the pivot out of line (at v) */ + pv = (char *)&v; + v = *(WORD *)mid; + } + + pa = pb = base; + pc = pd = base + ( n - 1 ) * size; + count = n; + /* + count keeps track of how many entries we have + examined. Once we have looked at all the entries + then we know that the partitioning is complete. + We use count to terminate the looping, rather than + a pointer comparison, to handle 16bit pointer + limitations that may lead pb or pc to wrap. + i.e. pc = 0x0000; + pc -= 0x0004; + pc == 0xfffc; + pc is no longer less that 0x0000; + */ + for( ;; ) { + while( count && (comparison = cmp(pb, pv, context )) <= 0 ) { + if( comparison == 0 ) { + swap( pa, pb ); + pa += size; + } + pb += size; + count--; + } + while( count && (comparison = cmp(pc, pv, context )) >= 0 ) { + if( comparison == 0 ) { + swap( pc, pd ); + pd -= size; + } + pc -= size; + count--; + } + if( !count ) break; + swap( pb, pc ); + pb += size; + count--; + if( !count ) break; + pc -= size; + count--; + } + pn = base + n * size; + s = min( pa - base, pb - pa ); + if( s > 0 ) { + inline_swap( base, pb - s, s ); + } + s = min( pd - pc, pn - pd - size); + if( s > 0 ) { + inline_swap( pb, pn - s, s ); + } + /* Now, base to (pb-pa) needs to be sorted */ + /* Also, pn-(pd-pc) needs to be sorted */ + /* The middle 'chunk' contains all elements=pivot value */ + r = pb - pa; + s = pd - pc; + if( s >= r ) { /* Stack up the larger chunk */ + base_stack[sp] = pn - s; /* Stack up base */ + n_stack[sp] = s / size; /* Stack up n */ + n = r / size; /* Set up n for next 'call' */ + /* next base is still base */ + } else { + if( r <= size ) break; + base_stack[sp] = base; /* Stack up base */ + n_stack[sp] = r / size; /* Stack up n */ + base = pn - s; /* Set up base and n for */ + n = s / size; /* next 'call' */ + } + ++sp; + } + } + if( sp == 0 ) break; + --sp; + base = base_stack[sp]; + n = n_stack[sp]; + } + rc = 0; + } + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/search/qsortrtn.c b/programs/develop/open watcom/trunk/clib/search/qsortrtn.c new file mode 100644 index 000000000..76df5f50d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/search/qsortrtn.c @@ -0,0 +1,349 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +/* + * This file is #included by qsort.c. + */ + + +/* Support OS/2 16-bit protected mode - will never get stack overflow */ +#define MAXDEPTH (sizeof(long) * 8) + +#define SHELL 3 /* Shell constant used in shell sort */ + +typedef int WORD; +#define W sizeof( WORD ) + +/* + swap() is a macro that chooses between an in_line function call and + an exchange macro. +*/ +#define exch( a, b, t) ( t = a, a = b, b = t ) +#define swap( a, b ) \ + swaptype != 0 ? BYTESWAP( a, b, size ) : \ + ( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t ) + +/* + Note: The following assembly was timed against several other methods + of doing the same thing. The pragmas here were either fastest on all + machines tested, or fastest on most machines tested. (including an 8088, + 386 16mhz, 386 33mhz, and 486 25mhz). +*/ + +#if defined( __386__ ) + /* this is intended for 386 only... */ + void inline_swap( char *p, char *q, size_t size ); + #pragma aux inline_swap = \ + 0x06 /* push es */ \ + 0x1e /* push ds */ \ + 0x07 /* pop es */ \ + 0x0f 0xb6 0xd1 /* movzx edx,cl */ \ + 0xc1 0xe9 0x02 /* shr ecx,02H */ \ + 0x74 0x0b /* je L1 */ \ + 0x8b 0x07 /*L2 mov eax,[edi] */ \ + 0x87 0x06 /* xchg eax,[esi] */ \ + 0xab /* stosd */ \ + 0x83 0xc6 0x04 /* add esi,0004H */ \ + 0x49 /* dec ecx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x80 0xe2 0x03 /*L1 and dl,03H */ \ + 0x74 0x09 /* je L3 */ \ + 0x8a 0x07 /*L4 mov al,[edi] */ \ + 0x86 0x06 /* xchg al,[esi] */ \ + 0xaa /* stosb */ \ + 0x46 /* inc esi */ \ + 0x4a /* dec edx */ \ + 0x75 0xf7 /* jne L4 */ \ + /*L3 */ \ + 0x07 /* pop es */ \ + parm caller [esi] [edi] [ecx] \ + value \ + modify exact [esi edi ecx eax edx]; + #pragma aux byteswap parm [esi] [edi] [ecx] \ + modify exact [esi edi ecx eax edx]; + static void _WCNEAR byteswap( char *p, char *q, size_t size ) { + inline_swap( p, q, size ); + } + +#elif defined( M_I86 ) && defined( __BIG_DATA__ ) + void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size ); + #pragma aux inline_swap = \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0xd1 0xe9 /* shr cx,1 */ \ + 0x74 0x0b /* je L1 */ \ + 0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \ + 0x87 0x04 /* xchg ax,[si] */ \ + 0xab /* stosw */ \ + 0x46 /* inc si */ \ + 0x46 /* inc si */ \ + 0x49 /* dec cx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x73 0x07 /*L1 jnc L3 */ \ + 0x8a 0x04 /* mov al,[si] */ \ + 0x26 0x86 0x05 /* xchg al,es:[di] */ \ + 0x88 0x04 /* mov [si],al */ \ + 0x1f /*L3 pop ds */ \ + parm caller [dx si] [es di] [cx] \ + value \ + modify exact [si di cx ax]; + #pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax]; + static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) { + inline_swap( p, q, size ); + } + +#elif defined( M_I86 ) && defined( __SMALL_DATA__ ) + /* we'll ask for char __far *q to save us writing code to load es */ + void inline_swap( char *p, char _WCFAR *q, size_t size ); + #pragma aux inline_swap = \ + 0xd1 0xe9 /* shr cx,1 */ \ + 0x74 0x0b /* je L1 */ \ + 0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \ + 0x87 0x04 /* xchg ax,[si] */ \ + 0xab /* stosw */ \ + 0x46 /* inc si */ \ + 0x46 /* inc si */ \ + 0x49 /* dec cx */ \ + 0x75 0xf5 /* jne L2 */ \ + 0x73 0x07 /*L1 jnc L3 */ \ + 0x8a 0x04 /* mov al,[si] */ \ + 0x26 0x86 0x05 /* xchg al,es:[di] */ \ + 0x88 0x04 /* mov [si],al */ \ + /*L3 */ \ + parm caller [si] [es di] [cx] \ + value \ + modify exact [si di cx ax]; + #pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax]; + static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) { + inline_swap( p, q, size ); + } + +#else + /* this is an optimized version of a simple byteswap */ + #define inline_swap BYTESWAP + static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) { + long dword; + short word; + char byte; + + #if 1 /* this is for 32 bit machines */ + while( size > 3 ) { + dword = *(PTRATTR long *)p; + *(PTRATTR long *)p = *(PTRATTR long *)q; + *(PTRATTR long *)q = dword; + p += 4; + q += 4; + size -= 4; + } + if( size > 1 ) { + word = *(PTRATTR short *)p; + *(PTRATTR short *)p = *(PTRATTR short *)q; + *(PTRATTR short *)q = word; + p += 2; + q += 2; + size -= 2; + } + #else /* this is for 16 bit machines */ + while( size > 1 ) { + word = *(PTRATTR short *)p; + *(PTRATTR short *)p = *(PTRATTR short *)q; + *(PTRATTR short *)q = word; + p += 2; + q += 2; + size -= 2; + } + #endif + if( size ) { + byte = *p; + *p = *q; + *q = byte; + } + } +#endif + + +FUNCTION_LINKAGE void FUNCTION_NAME( + PTRATTR void *in_base, size_t n, + size_t size, + int (*compar)(const void *, const void *) + ) +/**********************************************************************/ +{ + PTRATTR char * base = (PTRATTR char*) in_base; + PTRATTR char * p1; + PTRATTR char * p2; + PTRATTR char * pa; + PTRATTR char * pb; + PTRATTR char * pc; + PTRATTR char * pd; + PTRATTR char * pn; + PTRATTR char * pv; + PTRATTR char * mid; + WORD v; /* used in pivot initialization */ + WORD t; /* used in exch() macro */ + int comparison, swaptype, shell; + size_t count, r, s; + unsigned int sp; + auto char * base_stack[MAXDEPTH]; + auto unsigned int n_stack[MAXDEPTH]; + qcomp * cmp = (qcomp*) compar; + + /* + Initialization of the swaptype variable, which determines which + type of swapping should be performed when swap() is called. + 0 for single-word swaps, 1 for general swapping by words, and + 2 for swapping by bytes. W (it's a macro) = sizeof(WORD). + */ + swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0; + sp = 0; + for(;;) { + while( n > 1 ) { + if( n < 16 ) { /* 2-shell sort on smallest arrays */ + for( shell = (size * SHELL) ; + shell > 0 ; + shell -= ((SHELL-1) * size) ) { + p1 = base + shell; + for( ; p1 < base + n * size; p1 += shell ) { + for( p2 = p1; + p2 > base && cmp( p2 - shell, p2 ) > 0; + p2 -= shell ) { + swap( p2, p2 - shell ); + } + } + } + break; + } else { /* n >= 16 */ + /* Small array (15 < n < 30), mid element */ + mid = base + (n >> 1) * size; + if( n > 29 ) { + p1 = base; + p2 = base + ( n - 1 ) * size; + if( n > 42 ) { /* Big array, pseudomedian of 9 */ + s = (n >> 3) * size; + p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp ); + mid = MED3( mid - s, mid, mid + s, cmp ); + p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp ); + } + /* Mid-size (29 < n < 43), med of 3 */ + mid = MED3( p1, mid, p2, cmp ); + } + /* + The following sets up the pivot (pv) for partitioning. + It's better to store the pivot value out of line + instead of swapping it to base. However, it's + inconvenient in C unless the element size is fixed. + So, only the important special case of word-size + objects has utilized it. + */ + if( swaptype != 0 ) { /* Not word-size objects */ + pv = base; + swap( pv, mid ); + } else { /* Storing the pivot out of line (at v) */ + pv = ( char* )&v; + v = *( WORD* )mid; + } + + pa = pb = base; + pc = pd = base + ( n - 1 ) * size; + count = n; + /* + count keeps track of how many entries we have + examined. Once we have looked at all the entries + then we know that the partitioning is complete. + We use count to terminate the looping, rather than + a pointer comparison, to handle 16bit pointer + limitations that may lead pb or pc to wrap. + i.e. pc = 0x0000; + pc -= 0x0004; + pc == 0xfffc; + pc is no longer less that 0x0000; + */ + for(;;) { + while(count && (comparison = cmp(pb, pv)) <= 0) { + if( comparison == 0 ) { + swap( pa, pb ); + pa += size; + } + pb += size; + count--; + } + while(count && (comparison = cmp(pc, pv)) >= 0) { + if( comparison == 0 ) { + swap( pc, pd ); + pd -= size; + } + pc -= size; + count--; + } + if( !count ) break; + swap( pb, pc ); + pb += size; + count--; + if( !count ) break; + pc -= size; + count--; + } + pn = base + n * size; + s = min( pa - base, pb - pa ); + if( s > 0 ) { + inline_swap( base, pb - s, s ); + } + s = min( pd - pc, pn - pd - size); + if( s > 0 ) { + inline_swap( pb, pn - s, s ); + } + /* Now, base to (pb-pa) needs to be sorted */ + /* Also, pn-(pd-pc) needs to be sorted */ + /* The middle 'chunk' contains all elements=pivot value*/ + r = pb - pa; + s = pd - pc; + if( s >= r ) { /* Stack up the larger chunk */ + base_stack[sp] = pn - s;/* Stack up base */ + n_stack[sp] = s / size; /* Stack up n */ + n = r / size; /* Set up n for next 'call'*/ + /* next base is still base */ + } else { + if( r <= size ) break; + base_stack[sp] = base; /* Stack up base */ + n_stack[sp] = r / size; /* Stack up n */ + base = pn - s; /* Set up base and n for */ + n = s / size; /* next 'call' */ + } + ++sp; + } + } + if( sp == 0 ) break; + --sp; + base = base_stack[sp]; + n = n_stack[sp]; + } +} diff --git a/programs/develop/open watcom/trunk/clib/src/fstatus.inc b/programs/develop/open watcom/trunk/clib/src/fstatus.inc new file mode 100644 index 000000000..e7ff411ff --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/fstatus.inc @@ -0,0 +1,47 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +;* DESCRIBE IT HERE! +;* +;***************************************************************************** + + +FPE_OK equ 0 +FPE_INVALID equ 81h +FPE_DENORMAL equ 82h +FPE_ZERODIVIDE equ 83h +FPE_OVERFLOW equ 84h +FPE_UNDERFLOW equ 85h +FPE_INEXACT equ 86h +FPE_UNEMULATED equ 87h +FPE_SQRTNEG equ 88h +FPE_STACKOVERFLOW equ 8ah +FPE_STACKUNDERFLOW equ 8bh +FPE_EXPLICITGEN equ 8ch +FPE_IOVERFLOW equ 8dh +FPE_LOGERR equ 8eh +FPE_MODERR equ 8fh diff --git a/programs/develop/open watcom/trunk/clib/src/saferlib.h b/programs/develop/open watcom/trunk/clib/src/saferlib.h new file mode 100644 index 000000000..77a1907fe --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/saferlib.h @@ -0,0 +1,103 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Internal data and routines for "Safer C", or bounds-checking +* library extension. +* +****************************************************************************/ + + +#ifndef _SAFERLIB_H_INCLUDED +#define _SAFERLIB_H_INCLUDED + +#define __STDC_WANT_LIB_EXT1__ 1 +#include +#include + +// Maximum length of runtime-constraint error message +#define RTCT_MSG_MAX 128 + +#define _RWD_rtcthandler __runtime_constraint_handler + +extern constraint_handler_t __runtime_constraint_handler; + +extern void __rtct_fail( const char *fn, const char *reason, void *reserved ); + +// Runtime-constraint validation macros. Call the handler and return zero if check +// failed, return non-zero value if check succeeded. + +#define __check_constraint_nullptr( arg ) \ + ((arg == NULL) ? __rtct_fail( __func__, #arg " == NULL", NULL ), 0 : 1) + +#define __check_constraint_maxsize( arg ) \ + ((arg > RSIZE_MAX) ? __rtct_fail( __func__, #arg " > RSIZE_MAX", NULL ), 0 : 1) + +#define __check_constraint_zero( arg ) \ + ((arg == 0) ? __rtct_fail( __func__, #arg " == 0", NULL ), 0 : 1) + +#define __check_constraint_toosmall( name, left ) \ + ((left == 0) ? __rtct_fail( __func__, #name " is too small to hold data", NULL ), 0 : 1) + + +// Runtime-constraint validation macros. Construct the message and return +// zero if check failed, return non-zero value if check succeeded. +// __rtct_fail has to be explicitly called later. + +#define __check_constraint_nullptr_msg( msg, arg ) \ + ((arg == NULL) ? ( msg = #arg " == NULL" ), 0 : 1) + +#define __check_constraint_maxsize_msg( msg, arg ) \ + ((arg > RSIZE_MAX) ? ( msg = #arg " > RSIZE_MAX" ), 0 : 1) + +#define __check_constraint_zero_msg( msg, arg ) \ + ((arg == 0) ? ( msg = #arg " == 0" ), 0 : 1) + +#define __check_constraint_toosmall_msg( msg, name, left ) \ + ((left == 0) ? ( msg = #name " is too small to hold data" ), 0 : 1) + +#define __check_constraint_a_gt_b_msg( msg, a, b ) \ + ((a > b) ? ( msg = #a " > " #b ), 0 : 1) + +#define __check_constraint_overlap_msg( msg, p1, len1, p2, len2 ) \ + (((p1 == p2) || ( (p1 > p2) && ( p1 < (CHAR_TYPE *)p2 + len2 * sizeof( CHAR_TYPE ))) \ + || ( (p2 > p1) && ( p2 < (CHAR_TYPE *)p1 + len1 * sizeof( CHAR_TYPE )))) \ + ? ( msg = #p1 " overlap " #p2 ), 0 : 1) + + +// For 16-bit targets, the RSIZE_MAX check is effectively no-op. Object sizes +// up to SIZE_MAX are legal and not uncommon. +#if RSIZE_MAX == SIZE_MAX + #undef __check_constraint_maxsize + #define __check_constraint_maxsize( arg ) 1 + #undef __check_constraint_maxsize_msg + #define __check_constraint_maxsize_msg( msg, arg ) 1 + + #define __lte_rsizmax( arg ) 1 +#else + #define __lte_rsizmax( arg ) (arg <= RSIZE_MAX) +#endif + +#endif // _SAFERLIB_H_INCLUDED diff --git a/programs/develop/open watcom/trunk/clib/src/strdup.h b/programs/develop/open watcom/trunk/clib/src/strdup.h new file mode 100644 index 000000000..81164eb09 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/src/strdup.h @@ -0,0 +1,41 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#ifndef __STRDUP_H_INCLUDED +#define __STRDUP_H_INCLUDED + +#include "variety.h" +#include "widechar.h" + +_WCRTLINK extern char *__clib_strdup( const char *str ); +_WCRTLINK extern wchar_t *__clib_wcsdup( const wchar_t *str ); +#endif diff --git a/programs/develop/open watcom/trunk/clib/string/bits.c b/programs/develop/open watcom/trunk/clib/string/bits.c new file mode 100644 index 000000000..0c9e34186 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/bits.c @@ -0,0 +1,48 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "setbits.h" + +const unsigned char _HUGEDATA _Bits[] = + { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; + +void __setbits( unsigned char vector[32], const char *charset ) +{ + unsigned char c; + + memset( vector, 0, 32 ); + for( ; c = *charset; ++charset ) { + vector[ c >> 3 ] |= _Bits[ c & 0x07 ]; + } +} diff --git a/programs/develop/open watcom/trunk/clib/string/bprintf.c b/programs/develop/open watcom/trunk/clib/string/bprintf.c new file mode 100644 index 000000000..2acdf1b6d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/bprintf.c @@ -0,0 +1,139 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: This module supports formatted output to a character buffer. +* Both character and wide character formatting are included. +* For added library granularity, this module could be split +* into two, with "bprintf" functions in one file and the +* "snprintf" functions in another. +* +* C library functions: +* _bprintf, _vbprintf +* _bwprintf, _vbwprintf +* _snprintf, _snwprintf +* _vsnprintf, _vsnwprintf +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "printf.h" + +struct buf_limit { + CHAR_TYPE *bufptr; + size_t bufsize; + int bufover; +}; + +/* + * buf_putc -- append a character to a string in memory + */ +static slib_callback_t buf_putc; // setup calling convention +static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char ) +{ + struct buf_limit *bufinfo; + + bufinfo = (struct buf_limit *)specs->_dest; + if( specs->_output_count < bufinfo->bufsize ) { + *( bufinfo->bufptr++ ) = op_char; + specs->_output_count++; + } else { + bufinfo->bufover = -1; + } +} + +_WCRTLINK int __F_NAME(_vbprintf,_vbwprintf) ( CHAR_TYPE *s, size_t bufsize, + const CHAR_TYPE *format, va_list arg) +{ + register int len; + auto struct buf_limit bufinfo; + slib_callback_t *tmp; + + bufinfo.bufptr = s; + bufinfo.bufsize = bufsize - 1; + bufinfo.bufover = 0; +#if defined( __386__ ) && defined( __QNX__ ) + /* avoid some segment relocations for 32-bit QNX */ + tmp = (void (*)())buf_putc; +#else + tmp = buf_putc; +#endif + len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp ); + s[len] = '\0'; + return( len ); +} + +_WCRTLINK int __F_NAME(_bprintf,_bwprintf) ( CHAR_TYPE *dest, size_t bufsize, + const CHAR_TYPE *format, ... ) +{ + auto va_list args; + + va_start( args, format ); + return( __F_NAME(_vbprintf,_vbwprintf)( dest, bufsize, format, args ) ); +} + +// Notes: +// _vsnprintf, _vsnwprintf must return an error (-1) when buffer too small +// If a NULL character can fit, append it. If not, no error. + +_WCRTLINK int __F_NAME(_vsnprintf,_vsnwprintf) ( CHAR_TYPE *s, size_t bufsize, + const CHAR_TYPE *format, va_list arg) +{ + register int len; + auto struct buf_limit bufinfo; + slib_callback_t *tmp; + + bufinfo.bufptr = s; + bufinfo.bufsize = bufsize; + bufinfo.bufover = 0; +#if defined( __386__ ) && defined( __QNX__ ) + /* avoid some segment relocations for 32-bit QNX */ + tmp = (void (*)())buf_putc; +#else + tmp = buf_putc; +#endif + len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp ); + if( len < bufsize ) { + s[len] = '\0'; + } + if( bufinfo.bufover == 0 ) { + return( len ); + } else { + return( -1 ); + } +} + +_WCRTLINK int __F_NAME(_snprintf,_snwprintf) ( CHAR_TYPE *dest, size_t bufsize, + const CHAR_TYPE *format, ... ) +{ + auto va_list args; + + va_start( args, format ); + return( __F_NAME(_vsnprintf,_vsnwprintf)( dest, bufsize, format, args ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/cmp386.asm b/programs/develop/open watcom/trunk/clib/string/cmp386.asm new file mode 100644 index 000000000..132dd01fc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/cmp386.asm @@ -0,0 +1,213 @@ +;***************************************************************************** +;* +;* Open Watcom Project +;* +;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +;* +;* ======================================================================== +;* +;* This file contains Original Code and/or Modifications of Original +;* Code as defined in and that are subject to the Sybase Open Watcom +;* Public License version 1.0 (the 'License'). You may not use this file +;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +;* provided with the Original Code and Modifications, and is also +;* available at www.sybase.com/developer/opensource. +;* +;* The Original Code and all software distributed under the License are +;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +;* NON-INFRINGEMENT. Please see the License for the specific language +;* governing rights and limitations under the License. +;* +;* ======================================================================== +;* +;* Description: Intel 386 implementation strcmp(). +;* +;***************************************************************************** + + +include mdef.inc +include struct.inc + +ifdef _PROFILE +include p5prof.inc +endif + + modstart _strcmp,para + +cmp4 macro off + mov ebx,off[eax] ; get dword from op1 + mov ecx,off[edx] ; get dword from op2 + cmp ecx,ebx ; compare them + jne unequal ; quit if not equal + ife off-12 + add eax,off+4 ; point to next group of dwords + add edx,off+4 ; ... + endif + not ecx ; ... + add ebx,0FEFEFEFFh ; determine if '\0' is one of bytes + and ebx,ecx ; ... + and ebx,80808080h ; ebx will be non-zero if '\0' found + endm + + defpe strcmp + xdefp "C",strcmp + ifdef _PROFILE + P5Prolog + endif + ifdef __STACK__ + mov eax,4[esp] ; get p1 + mov edx,8[esp] ; get p2 + endif + cmp eax,edx ; pointers equal ? + je equalnorst ; yes, return 0 + ifndef __STACK__ + push ecx ; save register + endif + test al,3 ; p1 aligned ? + jne realign ; no, go and realign + test dl,3 ; p2 aligned ? + jne slowcpy ; no, do the slow copy (impossible to align both) + +fastcpy: + push ebx ; save register + + align 4 + _loop ; - loop + cmp4 0 ; - - compare first dword + _quif ne ; - - quit if end of string + cmp4 4 ; - - compare second dword + _quif ne ; - - quit if end of string + cmp4 8 ; - - compare third dword + _quif ne ; - - quit if end of string + cmp4 12 ; - - compare fourth dword + _until ne ; - until end of string +equalrst: ; strings equal, restore registers + pop ebx ; restore register + ifndef __STACK__ + pop ecx ; ... + endif +equalnorst: ; strings equal, skip register restore + sub eax,eax ; indicate strings equal + ifdef _PROFILE + P5Epilog + endif + ret ; return + +unequal: ; dword was not equal + _guess ; guess strings are equal + cmp bl,cl ; - check low bytes + _quif ne ; - quit if not equal + cmp bl,0 ; - stop if end of string + je equalrst ; - ... + cmp bh,ch ; - check next bytes + _quif ne ; - quit if not equal + cmp bh,0 ; - stop if end of string + je equalrst ; - ... + shr ebx,16 ; - shift top 2 bytes to bottom + shr ecx,16 ; - ... + cmp bl,cl ; - check third byte + _quif ne ; - quit if not equal + cmp bl,0 ; - stop if end of string + je equalrst ; - ... + cmp bh,ch ; - check high order byte +;; we know at this point that bh != ch, just have to do the compare +;; _quif ne ; - quit if not equal +;; cmp bh,0 ; - stop if end of string +;; je equalrst ; - ... + _endguess ; endguess + sbb eax,eax ; eax = 0 if op1>op2, -1 if op1op2, -1 if op1op2, -1 if op1op2, -1 if op1 +#include "setbits.h" + +void __fsetbits( unsigned char _WCFAR *vector, const char _WCFAR *charset ) +{ + unsigned char c; + + _fmemset( vector, 0, 32 ); + for( ; c = *charset; ++charset ) { + vector[ c >> 3 ] |= _Bits[ c & 0x07 ]; + } +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrcat.c b/programs/develop/open watcom/trunk/clib/string/fstrcat.c new file mode 100644 index 000000000..3dbf98a86 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrcat.c @@ -0,0 +1,51 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "xstring.h" + +#undef _fstrcat +/* concatenate t to the end of dst */ + +_WCRTLINK char _WCFAR *_fstrcat( char _WCFAR *dst, const char _WCFAR *t ) + { +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fstrcat( dst, t ) ); +#else + char _WCFAR *s; + s = dst; + while( *s != '\0' ) ++s; + while( *s++ = *t++ ) ; + return( dst ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrchr.c b/programs/develop/open watcom/trunk/clib/string/fstrchr.c new file mode 100644 index 000000000..1dd0edaa9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrchr.c @@ -0,0 +1,91 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern char _WCFAR * _scan1( char _WCFAR *s, int c ); + +/* use scan1 to find the char we are looking for */ + +#pragma aux _scan1 = 0x1e /* push ds */\ + 0x8e 0xda /* mov ds,dx */\ + 0xad /* L1:lodsw */\ + 0x38 0xd8 /* cmp al,bl */\ + 0x74 0x22 /* je L3 */\ + 0x84 0xc0 /* test al,al*/\ + 0x74 0x19 /* je L2 */\ + 0x38 0xdc /* cmp ah,bl */\ + 0x74 0x1b /* je L4 */\ + 0x84 0xe4 /* test ah,ah*/\ + 0x74 0x11 /* je L2 */\ + 0xad /* lodsw */\ + 0x38 0xd8 /* cmp al,bl */\ + 0x74 0x11 /* je L3 */\ + 0x84 0xc0 /* test al,al*/\ + 0x74 0x08 /* je L2 */\ + 0x38 0xdc /* cmp ah,bl */\ + 0x74 0x0a /* je L4 */\ + 0x84 0xe4 /* test ah,ah*/\ + 0x75 0xde /* jne L1 */\ + 0x31 0xf6 /* L2:xor si,si*/\ + 0x89 0xf2 /* mov dx,si */\ + 0xa9 /* test ax,... */\ + 0x4e /* L3:dec si */\ + 0x4e /* L4:dec si */\ + 0x1f /* pop ds */\ + parm caller [dx si] [bl]\ + value [dx si]\ + modify [ax dx si]; +#endif + + +/* locate the first occurrence of c in the initial n characters of the + string pointed to by s. The terminating null character is considered + to be part of the string. + If the character c is not found, NULL is returned. +*/ +#undef _fstrchr + +_WCRTLINK char _WCFAR *_fstrchr( const char _WCFAR *s, int c ) + { +//#if defined(M_I86) + //return( _scan1( (char _WCFAR *)s, c ) ); +//#else + do { + if( *s == c ) return( (char _WCFAR *)s ); + } while( *s++ != '\0' ); + return( NULL ); +//#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrcmp.c b/programs/develop/open watcom/trunk/clib/string/fstrcmp.c new file mode 100644 index 000000000..8e4ab771e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrcmp.c @@ -0,0 +1,50 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "xstring.h" + +#undef _fstrcmp + +/* return <0 if s0 if s>t */ + +_WCRTLINK int _fstrcmp( const char _WCFAR *s, const char _WCFAR *t ) + { +#if /*defined(M_I86) &&*/ defined(__INLINE_FUNCTIONS__) + return( _inline__fstrcmp( s, t ) ); +#else + for( ; *s == *t; s++, t++ ) + if( *s == '\0' ) + return( 0 ); + return( *s - *t ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrcpy.c b/programs/develop/open watcom/trunk/clib/string/fstrcpy.c new file mode 100644 index 000000000..3c252d181 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrcpy.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "xstring.h" + +#undef _fstrcpy + /* copy string t to string s */ + +_WCRTLINK char _WCFAR *_fstrcpy( char _WCFAR *s, const char _WCFAR *t ) + { +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fstrcpy( s, t ) ); +#else + char _WCFAR *dst; + dst = s; + while( *dst++ = *t++ ); + return( s ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrcspn.c b/programs/develop/open watcom/trunk/clib/string/fstrcspn.c new file mode 100644 index 000000000..34c08aa21 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrcspn.c @@ -0,0 +1,57 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "setbits.h" + +/* The strcspn function computes the length of the initial segment of the + string pointed to by str which consists entirely of characters not from + the string pointed to by charset. The terminating NULL character is not + considered part of charset. +*/ + +_WCRTLINK size_t _fstrcspn( const char _WCFAR *str, const char _WCFAR *charset ) +{ + unsigned /*char*/ tc; + unsigned char vector[32]; + size_t len; + + __fsetbits( vector, charset ); + len = 0; + for( ; tc = (unsigned char) *str; ++len, ++str ) { + /* quit if we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) break; + } + return( len ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrdup.c b/programs/develop/open watcom/trunk/clib/string/fstrdup.c new file mode 100644 index 000000000..f005e5774 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrdup.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "liballoc.h" + +_WCRTLINK char _WCFAR *_fstrdup( const char _WCFAR *str ) +{ + char _WCFAR *mem; + int len; + + len = _fstrlen( str ) + 1; + mem = lib_malloc( len ); + if( mem ) { + (_fmemcpy)( mem, str, len ); + } + return( mem ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstricmp.c b/programs/develop/open watcom/trunk/clib/string/fstricmp.c new file mode 100644 index 000000000..39d5eb9d9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstricmp.c @@ -0,0 +1,55 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +/* return <0 if s0 if s>t */ + +_WCRTLINK int _fstricmp( const char _WCFAR *s, const char _WCFAR *t ) + { + unsigned char c1; + unsigned char c2; + + for(;;) { + c1 = *s; + if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A'; + c2 = *t; + if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A'; + if( c1 != c2 ) break; + if( c1 == '\0' ) break; + ++s; + ++t; + } + return( c1 - c2 ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrlen.c b/programs/develop/open watcom/trunk/clib/string/fstrlen.c new file mode 100644 index 000000000..b26406043 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrlen.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of _fstrlen(). +* +****************************************************************************/ + + +#include "variety.h" +#include "xstring.h" + +#undef _fstrlen + +_WCRTLINK size_t _fstrlen( const char _WCFAR *s ) /* return length of string s */ +{ +#if defined(__INLINE_FUNCTIONS__) + return( _inline__fstrlen( s ) ); +#else + const char _WCFAR *p; + + p = s; + while( *p != '\0' ) + ++p; + return( p - s ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrlwr.c b/programs/develop/open watcom/trunk/clib/string/fstrlwr.c new file mode 100644 index 000000000..3c18fb9d6 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrlwr.c @@ -0,0 +1,52 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +_WCRTLINK char _WCFAR *_fstrlwr( char _WCFAR *str ) + { + char _WCFAR *p; + unsigned char c; + + p = str; + while( c = *p ) { + c -= 'A'; + if( c <= 'Z' - 'A' ) { + c += 'a'; + *p = c; + } + ++p; + } + return( str ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrncat.c b/programs/develop/open watcom/trunk/clib/string/fstrncat.c new file mode 100644 index 000000000..91f0b995e --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrncat.c @@ -0,0 +1,86 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern char _WCFAR *_fast_strncat( char _WCFAR *, const char _WCFAR *, size_t ); + +#pragma aux _fast_strncat = \ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0x57 /* push di */\ + 0xb9 0xff 0xff /* mov cx,ffffh */\ + 0x31 0xc0 /* xor ax,ax */\ + 0xf2 0xae /* repne scasb */\ + 0x4f /* dec di */\ + 0x89 0xd1 /* mov cx,dx */\ + 0xac /* L1: lodsb */\ + 0xaa /* stosb */\ + 0x84 0xc0 /* test al,al */\ + 0xe0 0xfa /* loopne L1 */\ + 0x74 0x03 /* je L2 */\ + 0x26 0x88 0x25 /* mov es:[di],ah */\ + 0x58 /* L2: pop ax */\ + 0x1f /* pop ds */\ + parm caller [es di] [si ax] [dx]\ + value [es ax] \ + modify exact [ax cx si di]; +#endif + +/* concatenate t to the end of dst */ + +_WCRTLINK char _WCFAR *_fstrncat( char _WCFAR *dst, const char _WCFAR *t, size_t n ) + { +#ifdef M_I86 + if( n ) { + return( _fast_strncat( dst, t, n ) ); + } + return( dst ); +#else + char _WCFAR *s; + + s = _fmemchr( dst, '\0', ~0 ); + while( n != 0 ) { + *s = *t; + if( *s == '\0' ) break; + ++s; + ++t; + --n; + } + *s = '\0'; + return( dst ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrncmp.c b/programs/develop/open watcom/trunk/clib/string/fstrncmp.c new file mode 100644 index 000000000..ef661479d --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrncmp.c @@ -0,0 +1,80 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern int _fast_strncmp( const char _WCFAR *, const char _WCFAR *, size_t ); + +#pragma aux _fast_strncmp = \ + 0x1e /* push ds */ \ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0x89 0xfa /* mov dx,di */ \ + 0x30 0xc0 /* xor al,al */ \ + 0xf2 0xae /* repne scasb */ \ + 0x89 0xf9 /* mov cx,di */ \ + 0x89 0xd7 /* mov di,dx */ \ + 0x29 0xf9 /* sub cx,di */ \ + 0xf3 0xa6 /* repe cmpsb */ \ + 0x74 0x05 /* je L1 */ \ + 0x19 0xc9 /* sbb cx,cx */ \ + 0x83 0xd9 0xff /* sbb cx,ffffh */ \ + /* L1: */ \ + 0x1f /* pop ds */\ + parm caller [si ax] [es di] [cx] \ + value [cx] \ + modify exact [dx ax di cx si]; +#endif + +/* return <0 if s0 if s>t */ + +_WCRTLINK int _fstrncmp( const char _WCFAR *s, const char _WCFAR *t, size_t n ) + { +#if defined(M_I86) + if( n ) { + return( _fast_strncmp( s, t, n ) ); + } + return( 0 ); +#else + for(;;) { + if( n == 0 ) return( 0 ); /* equal */ + if( *s != *t ) return( *s - *t ); /* less than or greater than */ + if( *s == '\0' ) return( 0 ); /* equal */ + ++s; + ++t; + --n; + } +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrncpy.c b/programs/develop/open watcom/trunk/clib/string/fstrncpy.c new file mode 100644 index 000000000..e3260b0ff --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrncpy.c @@ -0,0 +1,82 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern char _WCFAR *fast_strncpy( char _WCFAR *, const char _WCFAR *, size_t ); + +#pragma aux fast_strncpy = \ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0x57 /* push di */\ + 0xac /* L1: lodsb */\ + 0xaa /* stosb */\ + 0x84 0xc0 /* test al,al */\ + 0xe0 0xfa /* loopne L1 */\ + 0x31 0xc0 /* xor ax,ax */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xf3 0xab /* rep stosw */\ + 0x11 0xc9 /* adc cx,cx */\ + 0xf3 0xaa /* rep stosb */\ + 0x58 /* pop ax */\ + 0x1f /* pop ds */\ + parm caller [es di] [si ax] [cx]\ + value [es ax] \ + modify exact [ax cx si di]; +#endif + +_WCRTLINK char _WCFAR *_fstrncpy( char _WCFAR *dst, const char _WCFAR *src, size_t len ) + { +#ifdef M_I86 + if( len ) { + return( fast_strncpy( dst, src, len ) ); + } + return( dst ); +#else + char _WCFAR *ret; + + ret = dst; + for(;len; --len ) { + if( *src == '\0' ) break; + *dst++ = *src++; + } + while( len != 0 ) { + *dst++ = '\0'; /* pad destination string with null chars */ + --len; + } + return( ret ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrnicm.c b/programs/develop/open watcom/trunk/clib/string/fstrnicm.c new file mode 100644 index 000000000..21425cde9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrnicm.c @@ -0,0 +1,56 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +/* return <0 if s0 if s>t */ + +_WCRTLINK int _fstrnicmp( const char _WCFAR *s, const char _WCFAR *t, size_t n ) + { + unsigned char c1; + unsigned char c2; + + for(;;) { + if( n == 0 ) return( 0 ); /* equal */ + c1 = *s; + if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A'; + c2 = *t; + if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A'; + if( c1 != c2 ) return( c1 - c2 ); /* less than or greater than */ + if( c1 == '\0' ) return( 0 ); /* equal */ + ++s; + ++t; + --n; + } + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrnset.c b/programs/develop/open watcom/trunk/clib/string/fstrnset.c new file mode 100644 index 000000000..5846fdd76 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrnset.c @@ -0,0 +1,45 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +_WCRTLINK char _WCFAR *_fstrnset( char _WCFAR *str, int c, size_t len ) + { + char _WCFAR *p; + + for( p = str; len; --len ) { + if( *p == '\0' ) break; + *p++ = c; + } + return( str ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrpbrk.c b/programs/develop/open watcom/trunk/clib/string/fstrpbrk.c new file mode 100644 index 000000000..3543086f1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrpbrk.c @@ -0,0 +1,54 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "setbits.h" + +/* The strpbrk function locates the first occurrence in the string pointed + to by str of any character from the string pointed to by charset. +*/ + +_WCRTLINK char _WCFAR *_fstrpbrk( const char _WCFAR *str, const char _WCFAR *charset ) +{ + unsigned char tc; + unsigned char vector[32]; + + __fsetbits( vector, charset ); + for( ; tc = *str; ++str ) { + /* quit when we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) + return( (char _WCFAR *)str ); + } + return( NULL ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrrchr.c b/programs/develop/open watcom/trunk/clib/string/fstrrchr.c new file mode 100644 index 000000000..267355a36 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrrchr.c @@ -0,0 +1,78 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern char _WCFAR *_fast_strrchr( const char _WCFAR *, char ); + +#pragma aux _fast_strrchr = \ + 0xb9 0xff 0xff /* mov cx,ffffh */ \ + 0x30 0xc0 /* xor al,al */ \ + 0xf2 0xae /* repne scasb */ \ + 0xf7 0xd1 /* not cx */ \ + 0x4f /* dec di */ \ + 0x88 0xd8 /* mov al,bl */ \ + 0xfd /* std */ \ + 0xf2 0xae /* repne scasb */ \ + 0xfc /* cld */ \ + 0x75 0x04 /* jne L1 */ \ + 0x89 0xf9 /* mov cx,di */ \ + 0x41 /* inc cx */ \ + 0xa9 /* hide 2 bytes */ \ + 0x8e 0xc1 /* L1: mov es,cx */ \ + parm caller [es di] [bl] \ + value [es cx] \ + modify exact [es cx ax di]; +#endif + +/* Locate the last occurrence of c in the string pointed to by s. + The terminating null character is considered to be part of the string. + If the character c is not found, NULL is returned. +*/ + +_WCRTLINK char _WCFAR *_fstrrchr( const char _WCFAR *s, int c ) + { +#if defined(M_I86) + return( _fast_strrchr( s, c ) ); +#else + char _WCFAR *p; + + p = NULL; /* assume c will not be found */ + do { + if( *s == c ) p = (char _WCFAR *)s; + } while( *s++ != '\0' ); + return( p ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrrev.c b/programs/develop/open watcom/trunk/clib/string/fstrrev.c new file mode 100644 index 000000000..5b7938d2c --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrrev.c @@ -0,0 +1,121 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +#ifdef M_I86 + +/* + explanation of algorithm: + + (1) reverse as much of the string as possible as words + + (2) after main loop: reverse residual inner string (0-3 bytes) + + the string falls into one of these forms: + + { prefix_word }* { suffix_word }* + { prefix_word }* middle_byte { suffix_word }* + { prefix_word }* pre_middle_byte post_middle_byte { suffix_word }* + { prefix_word }* pre_middle_byte middle_byte post_middle_byte { suffix_word }* + + we only have to swap two bytes when: + + len & 2 != 0 is true (ie. the carry is set after second shr cx,1) + +***************************************************************************** + WARNING: the code in the L1: ... reverse loop cannot modify the carry flag +***************************************************************************** +*/ + +extern void fast_rev( char _WCFAR * ); + +#pragma aux fast_rev = \ + 0x1e /* push ds */\ + 0x8e 0xc1 /* mov es,cx */\ + 0x8e 0xd9 /* mov ds,cx */\ + 0x89 0xfe /* mov si,di */\ + 0xb9 0xff 0xff /* mov cx,ffff */\ + 0x30 0xc0 /* xor al,al */\ + 0xf2 0xae /* repne scasb */\ + 0xf7 0xd1 /* not cx */\ + 0x49 /* dec cx */\ + 0xfd /* std */\ + 0x83 0xef 0x03 /* sub di,3 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xe3 0x0d /* jcxz L2 */\ + 0x8b 0x05 /* L1:mov ax,[di] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0x87 0x04 /* xchg ax,[si] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0xab /* stosw */\ + 0x46 /* inc si */\ + 0x46 /* inc si */\ + 0xe2 0xf3 /* loop L1 */\ + 0x73 0x07 /* L2:jnc L3 */\ + 0x47 /* inc di */\ + 0x8a 0x05 /* mov al,[di] */\ + 0x86 0x04 /* xchg al,[si] */\ + 0x88 0x05 /* mov [di],al */\ + 0xfc /* L3:cld */\ + 0x1f /* pop ds */\ + parm caller [cx di] \ + modify [si cx ax di es]; +#endif + +_WCRTLINK char _WCFAR *_fstrrev( char _WCFAR *str ) /* reverse characters in string */ + { +#if defined(M_I86) + fast_rev( str ); + return( str ); +#else + char _WCFAR *p1; + char _WCFAR *p2; + char c1; + char c2; + + p1 = str; + p2 = p1 + _fstrlen( p1 ) - 1; + while( p1 < p2 ) { + c1 = *p1; + c2 = *p2; + *p1 = c2; + *p2 = c1; + ++p1; + --p2; + } + return( str ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrset.c b/programs/develop/open watcom/trunk/clib/string/fstrset.c new file mode 100644 index 000000000..897cd39a1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrset.c @@ -0,0 +1,75 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + +#ifdef M_I86 + +extern char _WCFAR *fast_strset( char _WCFAR *, char ); + +#pragma aux fast_strset = \ + 0x1e /* push ds */\ + 0x56 /* push si */\ + 0x50 /* push ax */\ + 0x8e 0xda /* mov ds,dx */\ + 0x89 0xc6 /* mov si,ax */\ + 0x88 0xdf /* mov bh,bl */\ + 0xad /* L1:lodsw */\ + 0x84 0xc0 /* test al,al */\ + 0x74 0x0c /* je L3 */\ + 0x84 0xe4 /* test ah,ah */\ + 0x74 0x05 /* je L2 */\ + 0x89 0x5c 0xfe /* mov -2[si],bx */\ + 0xeb 0xf2 /* jmp L1 */\ + 0x88 0x5c 0xfe /* L2:mov -2[si],bl */\ + 0x58 /* L3:pop ax */\ + 0x5e /* pop si */\ + 0x1f /* pop ds */\ + parm caller [dx ax] [bl] \ + value [dx ax] \ + modify exact [bh]; +#endif + +_WCRTLINK char _WCFAR *_fstrset( char _WCFAR *s, int c ) + { +//#ifdef M_I86 + //return( fast_strset( s, c ) ); +//#else + char _WCFAR *p; + + for( p = s; *p; ++p ) { + *p = c; + } + return( s ); +//#endif + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrspn.c b/programs/develop/open watcom/trunk/clib/string/fstrspn.c new file mode 100644 index 000000000..d33439f58 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrspn.c @@ -0,0 +1,55 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "setbits.h" + +/* The strspn function computes the length of the initial segment of the + string pointed to by str which consists entirely of characters from + the string pointed to by charset. +*/ + +_WCRTLINK size_t _fstrspn( const char _WCFAR *str, const char _WCFAR *charset ) +{ + unsigned /*char*/ tc; + unsigned char vector[32]; + size_t len; + + __fsetbits( vector, charset ); + len = 0; + for( ; tc = (unsigned char) *str; ++str, ++len ) { + /* quit if we find any char not in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break; + } + return( len ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrspnp.c b/programs/develop/open watcom/trunk/clib/string/fstrspnp.c new file mode 100644 index 000000000..7e61ae797 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrspnp.c @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include + + +_WCRTLINK char _WCFAR *_fstrspnp( const char _WCFAR *p1, const char _WCFAR *p2 ) +{ + size_t index; + + index = _fstrspn( p1, p2 ); + if( *(p1+index) != '\0' ) { + return( (char _WCFAR*)(p1+index) ); + } else { + return( NULL ); + } +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrstr.c b/programs/develop/open watcom/trunk/clib/string/fstrstr.c new file mode 100644 index 000000000..b13663aee --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrstr.c @@ -0,0 +1,93 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: _fstrstr() implementation. +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +#ifdef M_I86 +#if defined(__QNX__) +#include +#else +#include +#endif + +extern int i86_memeq( const char _WCFAR *, const char _WCFAR *, int ); + +#define _ZFLAG (INTR_ZF<<8) + +#pragma aux i86_memeq = \ + 0x1e /* push ds */\ + 0x96 /* xchg si,ax */\ + 0x8e 0xd8 /* mov ds,ax */\ + 0xf3 0xa6 /* rep cmpsb */\ + 0x9f /* lahf */\ + 0x1f /* pop ds */\ + parm caller [si ax] [es di] [cx]\ + value [ax] \ + modify exact [si di cx ax]; + +#define memeq( p1, p2, len ) ( i86_memeq((p1),(p2),(len)) & _ZFLAG ) + +#else + +#define memeq( p1, p2, len ) ( _fmemcmp((p1),(p2),(len)) == 0 ) + +#endif + +/* Locate the first occurrence of the string pointed to by s2 in the + string pointed to by s1. + The strstr function returns a pointer to the located string, or a + null pointer if the string is not found. +*/ + +_WCRTLINK char _WCFAR *_fstrstr( const char _WCFAR *s1, const char _WCFAR *s2 ) + { + char _WCFAR *end_of_s1; + size_t s1len, s2len; + + if( s2[0] == '\0' ) { + return( (char _WCFAR *)s1 ); + } else if( s2[1] == '\0' ) { + return( _fstrchr( s1, s2[0] ) ); + } + end_of_s1 = _fmemchr( s1, '\0', ~0u ); + s2len = _fstrlen( s2 ); + for(;;) { + s1len = end_of_s1 - s1; + if( s1len < s2len ) break; + s1 = _fmemchr( s1, *s2, s1len ); /* find start of possible match */ + if( s1 == NULL ) break; + if( memeq( s1, s2, s2len ) ) return( (char _WCFAR *)s1 ); + ++s1; + } + return( NULL ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/fstrtok.c b/programs/develop/open watcom/trunk/clib/string/fstrtok.c new file mode 100644 index 000000000..657f81c47 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrtok.c @@ -0,0 +1,70 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include +#include "rtdata.h" +#include "nextftok.h" +#include "setbits.h" + + +_WCRTLINK char _WCFAR *_fstrtok( char _WCFAR *str, const char _WCFAR *charset ) +{ + unsigned /*char*/ tc; + unsigned char vector[32]; + unsigned char _WCFAR *p1; + + _INITNEXTFTOK + if( str == NULL ) { + str = _RWD_nextftok; /* use previous value */ + if( str == NULL ) return( NULL ); + } + __fsetbits( vector, charset ); + for( ; tc = (unsigned char) *str; ++str ) { + /* quit if we find any char not in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break; + } + if( tc == '\0' ) return( NULL ); + p1 = str; + for( ; tc = *p1; ++p1 ) { + /* quit when we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) { + *p1 = '\0'; /* terminate the token */ + p1++; /* start of next token */ + _RWD_nextftok = p1; + return( str ); + } + } + _RWD_nextftok = NULL; + return( str ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/fstrupr.c b/programs/develop/open watcom/trunk/clib/string/fstrupr.c new file mode 100644 index 000000000..7c54a6478 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/fstrupr.c @@ -0,0 +1,52 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include + +_WCRTLINK char _WCFAR *_fstrupr( char _WCFAR *str ) + { + char _WCFAR *p; + unsigned char c; + + p = str; + while( c = *p ) { + c -= 'a'; + if( c <= 'z' - 'a' ) { + c += 'A'; + *p = c; + } + ++p; + } + return( str ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/nextftok.h b/programs/develop/open watcom/trunk/clib/string/nextftok.h new file mode 100644 index 000000000..cf451f12f --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/nextftok.h @@ -0,0 +1,54 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#if defined(__OS2__) || defined(__NT__) || defined(__NETWARE__) + #if defined(__SW_BM) + + #include "thread.h" + + #define _INITNEXTFTOK + #define _NEXTFTOK (__THREADDATAPTR->__nextftokP) + + #else + + static char _WCFAR *nextftok = NULL; + + #define _INITNEXTFTOK + #define _NEXTFTOK nextftok + + #endif +#else + #define _INITNEXTFTOK + static char _WCFAR *nextftok = NULL; + #define _NEXTFTOK nextftok +#endif diff --git a/programs/develop/open watcom/trunk/clib/string/nexttok.h b/programs/develop/open watcom/trunk/clib/string/nexttok.h new file mode 100644 index 000000000..f703c7171 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/nexttok.h @@ -0,0 +1,48 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#define _INITNEXTTOK +#if defined(__OS2__) || defined(__NT__) || defined(__NETWARE__) + // the OS/2, NT and NETWARE files are identical + // note that NETWARE is always multi-thread + #if defined(__SW_BM) + #include "thread.h" + #define _NEXTTOK (__THREADDATAPTR->__nexttokP) + #else + static char *nexttok = NULL; + #define _NEXTTOK nexttok + #endif +#else + static char *nexttok = NULL; + #define _NEXTTOK nexttok +#endif diff --git a/programs/develop/open watcom/trunk/clib/string/selptr.c b/programs/develop/open watcom/trunk/clib/string/selptr.c new file mode 100644 index 000000000..68a5f4d16 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/selptr.c @@ -0,0 +1,44 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "rtdata.h" + +#ifdef __NETWARE__ +_WCRTLINKD extern char *sys_errlist[];/* strerror error message table */ +#define _sys_errlist sys_errlist +#endif + +_WCRTLINK char * (*__get_sys_errlist_ptr())[] { + return &_sys_errlist; +} diff --git a/programs/develop/open watcom/trunk/clib/string/setbits.h b/programs/develop/open watcom/trunk/clib/string/setbits.h new file mode 100644 index 000000000..c6977dc59 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/setbits.h @@ -0,0 +1,36 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: declaration for character set bit array routines +* +****************************************************************************/ + + +extern void __setbits( unsigned char *vector, const char *charset ); +extern void __fsetbits( unsigned char _WCFAR *vector, const char _WCFAR *charset ); + +extern const unsigned char _HUGEDATA _Bits[8]; + diff --git a/programs/develop/open watcom/trunk/clib/string/sneptr.c b/programs/develop/open watcom/trunk/clib/string/sneptr.c new file mode 100644 index 000000000..f3bc8b5e0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/sneptr.c @@ -0,0 +1,44 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include +#include "rtdata.h" + +#ifdef __NETWARE__ +_WCRTLINKD extern int _WCNEAR sys_nerr; /* # of entries in sys_errlist array */ +#define _sys_nerr sys_nerr +#endif + +_WCRTLINK int (*__get_sys_nerr_ptr()) { + return &_sys_nerr; +} diff --git a/programs/develop/open watcom/trunk/clib/string/snprintf.c b/programs/develop/open watcom/trunk/clib/string/snprintf.c new file mode 100644 index 000000000..c48783bde --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/snprintf.c @@ -0,0 +1,93 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of snprintf(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "printf.h" + +struct buf_limit { + CHAR_TYPE *bufptr; + size_t bufsize; +}; + +/* + * buf_putc -- append a character to a string in memory + */ +static slib_callback_t buf_putc; // setup calling convention +static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char ) +{ + struct buf_limit *bufinfo; + + bufinfo = (struct buf_limit *)specs->_dest; + if( specs->_output_count < bufinfo->bufsize ) { + *( bufinfo->bufptr++ ) = op_char; + } + specs->_output_count++; +} + +/* + * buf_count_putc -- only count characters to be output + */ +static slib_callback_t buf_count_putc; // setup calling convention +static void __SLIB_CALLBACK buf_count_putc( SPECS __SLIB *specs, int op_char ) +{ + specs->_output_count++; +} + + +_WCRTLINK int __F_NAME(vsnprintf,vsnwprintf) ( CHAR_TYPE *s, size_t bufsize, + const CHAR_TYPE *format, va_list arg) +{ + register int len; + auto struct buf_limit bufinfo; + + bufinfo.bufptr = s; + bufinfo.bufsize = bufsize - 1; + if( bufsize == 0 ) + len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_count_putc ); + else { + len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_putc ); + s[(( len >= 0 ) && ( len < bufsize )) ? len : bufsize - 1] = '\0'; + } + return( len ); +} + + +_WCRTLINK int __F_NAME(snprintf,snwprintf) ( CHAR_TYPE *dest, size_t bufsize, + const CHAR_TYPE *format, ... ) +{ + auto va_list args; + + va_start( args, format ); + return( __F_NAME(vsnprintf,vsnwprintf)( dest, bufsize, format, args ) ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/snprtf_s.c b/programs/develop/open watcom/trunk/clib/string/snprtf_s.c new file mode 100644 index 000000000..49e393e1b --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/snprtf_s.c @@ -0,0 +1,100 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of snprintf_s() - safe string fmt'd output. +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include +#include "printf.h" + + +struct buf_limit { + CHAR_TYPE *bufptr; + rsize_t chars_output; + rsize_t max_chars; +}; + +/* + * buf_putc -- append a character to a string in memory + */ +static slib_callback_t buf_putc; // setup calling convention +static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char ) +{ + struct buf_limit *info; + + info = (struct buf_limit *)specs->_dest; + if( specs->_output_count < info->max_chars ) { + *( info->bufptr++ ) = op_char; + info->chars_output++; + } + specs->_output_count++; +} + + +_WCRTLINK int __F_NAME(snprintf_s,snwprintf_s)( CHAR_TYPE * __restrict s, rsize_t n, + const CHAR_TYPE * __restrict format, ... ) +{ + va_list arg; + struct buf_limit info; + const char *msg; + + /* First check the critical conditions; if any of those + * is violated, return immediately and don't touch anything. + */ + if( __check_constraint_nullptr_msg( msg, s ) + && __check_constraint_maxsize_msg( msg, n ) + && __check_constraint_zero_msg( msg, n ) ) { + + /* The buffer looks okay, try doing something useful */ + if( __check_constraint_nullptr_msg( msg, format ) ) { + int len; + + info.bufptr = s; + info.chars_output = 0; + info.max_chars = n - 1; + msg = NULL; + va_start( arg, format ); + len = __F_NAME(__prtf_s,__wprtf_s)( &info, format, arg, &msg, buf_putc ); + va_end( arg ); + if( msg == NULL ) { + /* No rt-constraint violation while formatting */ + s[info.chars_output] = NULLCHAR; + return( len ); + } + } + /* Something went wrong, output buffer will contain empty string */ + *s = NULLCHAR; + } + __rtct_fail( __func__, msg, NULL ); + return( -1 ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/sprintf.c b/programs/develop/open watcom/trunk/clib/string/sprintf.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/sprintf.c rename to programs/develop/open watcom/trunk/clib/string/sprintf.c diff --git a/programs/develop/open watcom/trunk/clib/string/sprntf_s.c b/programs/develop/open watcom/trunk/clib/string/sprntf_s.c new file mode 100644 index 000000000..34cc411f1 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/sprntf_s.c @@ -0,0 +1,107 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of sprintf_s() - safe formatted string output. +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include +#include "printf.h" + + +/* + * mem_putc -- append a character to a string in memory, with overflow check + */ + +struct vsprtf_s_buf { + CHAR_TYPE *bufptr; + rsize_t chars_output; + rsize_t max_chars; +}; + +static slib_callback_t mem_putc; // set up calling convention +static void __SLIB_CALLBACK mem_putc( SPECS __SLIB *specs, int op_char ) +{ + struct vsprtf_s_buf *info; + + info = (struct vsprtf_s_buf *)specs->_dest; + if( info->chars_output <= info->max_chars ) { + *( info->bufptr++ ) = op_char; + specs->_output_count++; + info->chars_output++; + } +} + +_WCRTLINK int __F_NAME(sprintf_s,swprintf_s)( CHAR_TYPE * __restrict s, rsize_t n, + const CHAR_TYPE * __restrict format, ... ) +{ + va_list arg; + struct vsprtf_s_buf info; + const char *msg; + int rc = 0; + + /* First check the critical conditions; if any of those + * is violated, return immediately and don't touch anything. + */ + if( __check_constraint_nullptr_msg( msg, s ) + && __check_constraint_maxsize_msg( msg, n ) + && __check_constraint_zero_msg( msg, n ) ) { + + /* The buffer looks okay, try doing something useful */ + if( __check_constraint_nullptr_msg( msg, format ) ) { + info.bufptr = s; + info.chars_output = 0; + info.max_chars = n - 1; + msg = NULL; + + va_start( arg, format ); + __F_NAME(__prtf_s,__wprtf_s)( &info, format, arg, &msg, mem_putc ); + va_end( arg ); + + if( msg == NULL ) { + if( info.chars_output <= info.max_chars ) { + s[info.chars_output] = NULLCHAR; + return( info.chars_output ); + } + /* If we got here, the output buffer was too small */ + msg = "n < chars_output"; +#ifdef __WIDECHAR__ + rc = -1; /* Return value for swprintf_s is different! */ +#endif + } + } + /* Something went wrong, output buffer will contain empty string */ + *s = NULLCHAR; + } + __rtct_fail( __func__, msg, NULL ); + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/sscanf.c b/programs/develop/open watcom/trunk/clib/string/sscanf.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/sscanf.c rename to programs/develop/open watcom/trunk/clib/string/sscanf.c diff --git a/programs/develop/open watcom/trunk/clib/string/sscanf_s.c b/programs/develop/open watcom/trunk/clib/string/sscanf_s.c new file mode 100644 index 000000000..6e1a5d188 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/sscanf_s.c @@ -0,0 +1,87 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of sscanf_s() - safe formatted string input. +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include +#include "scanf.h" + + +static int cget_string( PTR_SCNF_SPECS specs ) +{ + int c; + + if( (c = *(specs->ptr)) != NULLCHAR ) { + ++(specs->ptr); + } else { + c = EOF; + specs->eoinp = 1; + } + return( c ); +} + + +static void uncget_string( int c, PTR_SCNF_SPECS specs ) +{ + --specs->ptr; +} + + + +_WCRTLINK int __F_NAME(sscanf_s,swscanf_s)( const CHAR_TYPE *s, const CHAR_TYPE *format, ... ) +{ + SCNF_SPECS specs; + const char *msg; + int rc; + va_list args; + + /* Basic check for null pointers to see if we can continue */ + if( __check_constraint_nullptr_msg( msg, s ) + && __check_constraint_nullptr_msg( msg, format ) ) { + + specs.ptr = (CHAR_TYPE *)s; + specs.cget_rtn = cget_string; + specs.uncget_rtn = uncget_string; + msg = NULL; + va_start( args, format ); + rc = __F_NAME(__scnf_s,__wscnf_s)( (PTR_SCNF_SPECS)&specs, format, &msg, args ); + va_end( args ); + if( msg == NULL ) { + /* no rt-constraint violation inside worker routine */ + return( rc ); + } + } + __rtct_fail( __func__, msg, NULL ); + return( __F_NAME(EOF,WEOF) ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/stncat_s.c b/programs/develop/open watcom/trunk/clib/string/stncat_s.c new file mode 100644 index 000000000..936b2d130 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/stncat_s.c @@ -0,0 +1,90 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strncat_s() - bounds-checking strncat(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include + + +_WCRTLINK errno_t __F_NAME(strncat_s,wcsncat_s)( CHAR_TYPE * __restrict s1, + rsize_t s1max, const CHAR_TYPE * __restrict s2, + rsize_t n ) +/*************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + // strnlen_s is safe to use as it has no rt constraints + rsize_t m = s1max - __F_NAME(strnlen_s,wcsnlen_s)( s1, s1max ); + + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // n <= RSIZE_MAX + // s1max != 0 + // m = s1max - strnlen_s( s1, s1max ) != 0 + // if n >= m then m > strnlen_s( s2, m ) + // s1 and s2 no overlap + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_maxsize_msg( msg, m ) && + __check_constraint_zero_msg( msg, s1max ) && + __check_constraint_zero_msg( msg, m ) && + ((n < m) || __check_constraint_a_gt_b_msg( msg, __F_NAME(strnlen_s,wcsnlen_s)( s2, m ), m - 1 )) && + __check_constraint_overlap_msg( msg, s1, s1max, s2, __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ))) { + + while( *s1 != NULLCHAR ) ++s1; //find end of field + + while( n != 0 ) { + *s1 = *s2; + if( *s2 == NULLCHAR ) break; + ++s1; + ++s2; + --n; + } + *s1 = NULLCHAR; + + rc = 0; + } else { + // Runtime-constraints found, store zero in receiving field + if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) { + s1[0] = NULLCHAR; + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/stncpy_s.c b/programs/develop/open watcom/trunk/clib/string/stncpy_s.c new file mode 100644 index 000000000..9e76c4a19 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/stncpy_s.c @@ -0,0 +1,81 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strncpy_s() - bounds-checking strncpy(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include + + +_WCRTLINK errno_t __F_NAME(strncpy_s,wcsncpy_s)( CHAR_TYPE * __restrict s1, + rsize_t s1max, const CHAR_TYPE * __restrict s2, + rsize_t n ) +/*************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + // strnlen_s is safe to use as it has no rt constraints + rsize_t s2len = __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ); + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // n <= RSIZE_MAX + // s1max != 0 + // if n >= s1max then s1max > strnlen_s( s2, s1max ) + // s1 s2 no overlap + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_maxsize_msg( msg, n ) && + __check_constraint_zero_msg( msg, s1max ) && + ((n < s1max) || __check_constraint_a_gt_b_msg( msg, s2len, s1max - 1 )) && + __check_constraint_overlap_msg( msg, s1, s1max, s2, s2len )) { + + for( ; n; --n) { + if( *s2 == '\0' ) break; + *s1++ = *s2++; + } + *s1 = '\0'; + rc = 0; + } else { + // Runtime-constraints found, store zero in receiving field + if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) { + s1[0] = '\0'; + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/strcat.c b/programs/develop/open watcom/trunk/clib/string/strcat.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strcat.c rename to programs/develop/open watcom/trunk/clib/string/strcat.c diff --git a/programs/develop/open watcom/trunk/clib/string/strcat_s.c b/programs/develop/open watcom/trunk/clib/string/strcat_s.c new file mode 100644 index 000000000..44136ef98 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strcat_s.c @@ -0,0 +1,81 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strcat_s() - bounds-checking strcat(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include + + +_WCRTLINK errno_t __F_NAME(strcat_s,wcscat_s)( CHAR_TYPE * __restrict s1, + rsize_t s1max, const CHAR_TYPE * __restrict s2 ) +/************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + // strnlen_s is safe to use as it has no rt constraints + rsize_t m = s1max - __F_NAME(strnlen_s,wcsnlen_s)( s1, s1max ); + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // s1max != 0 + // m != 0 + // m > strnlen_s( s2, m ) + // s1 and s2 no overlap + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_zero_msg( msg, s1max ) && + __check_constraint_zero_msg( msg, m ) && + __check_constraint_a_gt_b_msg( msg, + __F_NAME(strnlen_s,wcsnlen_s)( s2, m ), m - 1 ) && + __check_constraint_overlap_msg( msg, s1, s1max, s2, + __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ) ) ) { + + while( *s1 != NULLCHAR ) ++s1; // find end of field + while( *s1++ = *s2++ ); // append source field + + rc = 0; + } else { + // Runtime-constraints found, store zero in receiving field + if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) { + s1[0] = NULLCHAR; + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + return( rc ); +} + diff --git a/programs/develop/open watcom/trunk/clib/src/strchr.c b/programs/develop/open watcom/trunk/clib/string/strchr.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strchr.c rename to programs/develop/open watcom/trunk/clib/string/strchr.c diff --git a/programs/develop/open watcom/trunk/clib/string/strcoll.c b/programs/develop/open watcom/trunk/clib/string/strcoll.c new file mode 100644 index 000000000..93a1f4f73 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strcoll.c @@ -0,0 +1,55 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include "xstring.h" + +#undef strcoll + + + +/* This function is identical to strcmp, except it is suppose to use + the current locale. We only support the "C" locale, so this code + is identical to strcmp. +*/ +/* return <0 if s0 if s>t */ + + +_WCRTLINK int __F_NAME(strcoll,wcscoll) ( const CHAR_TYPE *s, const CHAR_TYPE *t ) + { + for( ; *s == *t; s++, t++ ) + if( *s == '\0' ) + return( 0 ); + return( *s - *t ); + } diff --git a/programs/develop/open watcom/trunk/clib/src/strcpy.c b/programs/develop/open watcom/trunk/clib/string/strcpy.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strcpy.c rename to programs/develop/open watcom/trunk/clib/string/strcpy.c diff --git a/programs/develop/open watcom/trunk/clib/string/strcpy_s.c b/programs/develop/open watcom/trunk/clib/string/strcpy_s.c new file mode 100644 index 000000000..41737db46 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strcpy_s.c @@ -0,0 +1,76 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strcpy_s() - bounds-checking strcpy(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include + + +_WCRTLINK errno_t __F_NAME(strcpy_s,wcscpy_s)( CHAR_TYPE * __restrict s1, + rsize_t s1max, const CHAR_TYPE * __restrict s2 ) +/************************************************************************/ +{ + errno_t rc = -1; + const char *msg; + + // strnlen_s is safe to use as it has no rt constraints + rsize_t s2len = __F_NAME(strnlen_s,wcsnlen_s)( s2, s1max ); + + // Verify runtime-constraints + // s1 not NULL + // s2 not NULL + // s1max <= RSIZE_MAX + // s1max != 0 + // s1max > strnlen_s( s2, s1max ) + // s1 s2 no overlap + if( __check_constraint_nullptr_msg( msg, s1 ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_maxsize_msg( msg, s1max ) && + __check_constraint_zero_msg( msg, s1max ) && + __check_constraint_a_gt_b_msg( msg, s2len, s1max - 1 ) && + __check_constraint_overlap_msg( msg, s1, s1max, s2, s2len ) ) { + + while( *s1++ = *s2++) + ; + + rc = 0; + } else { + // Runtime-constraints violated, make destination string empty + if( (s1 != NULL) && (s1max > 0) && __lte_rsizmax( s1max ) ) { + s1[0] = NULLCHAR; + } + // Now call the handler + __rtct_fail( __func__, msg, NULL ); + } + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strcspn.c b/programs/develop/open watcom/trunk/clib/string/strcspn.c new file mode 100644 index 000000000..3409c2557 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strcspn.c @@ -0,0 +1,78 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "setbits.h" + +/* The strcspn function computes the length of the initial segment of the + string pointed to by str which consists entirely of characters not from + the string pointed to by charset. The terminating NULL character is not + considered part of charset. +*/ + + +_WCRTLINK size_t __F_NAME(strcspn,wcscspn) ( const CHAR_TYPE *str, const CHAR_TYPE *charset ) +{ +#if defined(__WIDECHAR__) + + const CHAR_TYPE *p1; + const CHAR_TYPE *p2; + CHAR_TYPE tc1; + CHAR_TYPE tc2; + size_t len; + + len = 0; + for( p1 = str; tc1 = *p1; p1++, len++ ) { + for( p2 = charset; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 != NULLCHAR ) break; + } + return( len ); + +#else + unsigned /*char*/ tc; + unsigned char vector[32]; + size_t len; + + __setbits( vector, charset ); + len = 0; + for( ; tc = (unsigned char) *str; ++len, ++str ) { + /* quit if we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) break; + } + return( len ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/string/strdup.c b/programs/develop/open watcom/trunk/clib/string/strdup.c new file mode 100644 index 000000000..6ebed8a41 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strdup.c @@ -0,0 +1,57 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include "strdup.h" +#include +#include +#include +#include "liballoc.h" + +#ifdef __WIDECHAR__ +extern size_t wcslen( const CHAR_TYPE * ); +#endif + + +_WCRTLINK CHAR_TYPE *__F_NAME(__clib_strdup,__clib_wcsdup) ( const CHAR_TYPE *str ) +{ + CHAR_TYPE *mem; + int len; + + len = __F_NAME(strlen,wcslen)( str ) + 1; + mem = lib_malloc( len * CHARSIZE ); + if( mem ) { + (memcpy)( mem, str, len * CHARSIZE ); + } + return( mem ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/streln_s.c b/programs/develop/open watcom/trunk/clib/string/streln_s.c new file mode 100644 index 000000000..bb9f87cdf --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/streln_s.c @@ -0,0 +1,57 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strerrorlen_s(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include "errstr.h" + + +_WCRTLINK size_t __F_NAME(strerrorlen_s,wcserrorlen_s)( errno_t errnum ) +/************************************************************************/ +{ + size_t m = 0; + char *msg; + + if( errnum < 0 || errnum >= _sys_nerr ) { + msg = UNKNOWN_ERROR; + } else { + msg = _sys_errlist[ errnum ]; + } + + // count chars up to '\0' assuming _sys_errlist is singlebyte + while( *msg++ != '\0' ) { + ++m; + } + return( m ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strerr_s.c b/programs/develop/open watcom/trunk/clib/string/strerr_s.c new file mode 100644 index 000000000..5a9b15a9a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strerr_s.c @@ -0,0 +1,99 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strerror_s() - bounds checking strerror(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include +#include "errstr.h" + + +_WCRTLINK errno_t __F_NAME(strerror_s,wcserror_s)( CHAR_TYPE *s, + rsize_t maxsize, + errno_t errnum ) +/*****************************************************************/ +{ + errno_t rc = -1; + +#ifdef __WIDECHAR__ + wchar_t Wide_Error_String[ 128 ]; +#endif + char *msg; + CHAR_TYPE *p; + CHAR_TYPE *p2; + size_t msglen; + int k; + + /* runtime-constraints */ + // s not NULL + // maxsize <= RSIZE_MAX + // maxsize != 0 + if( __check_constraint_nullptr( s ) && + __check_constraint_maxsize( maxsize ) && + __check_constraint_zero( maxsize ) ) { + + if( errnum < 0 || errnum >= _sys_nerr ) { + msg = UNKNOWN_ERROR; + } else { + msg = _sys_errlist[ errnum ]; + } + + msglen = strlen( msg ); + +#ifdef __WIDECHAR__ + _AToUni( Wide_Error_String, msg ); + p2 = Wide_Error_String; +#else + p2 = msg; +#endif + p = s; + k = 0; + // copy string up to end of string or end of receiving field + while ( (k < maxsize - 1) && (*p2 != NULLCHAR) ) { + *p++ = *p2++; + ++k; + }; + + if( (maxsize > 3) && (msglen > maxsize - 4) ) { + /* msg does not fit, indicate it's incomplete */ + /* and terminate string */ + __F_NAME(strcpy,wcscpy)( p - 3, STRING( "..." ) ); + } else { + *p = NULLCHAR; // terminate string + } + if( msglen < maxsize) { + rc = 0; // msg not truncated + } + } + return( rc ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strerror.c b/programs/develop/open watcom/trunk/clib/string/strerror.c new file mode 100644 index 000000000..341f6b62f --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strerror.c @@ -0,0 +1,344 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strerror() function. +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "rtdata.h" +#if defined(__NT__) + #include +#endif +#include "errstr.h" + + +#ifndef __WIDECHAR__ + +#ifdef __LINUX__ +char *_sys_errlist[] = { + /* 0 EOK */ "No error", + /* 1 EPERM */ "Operation not permitted", + /* 2 ENOENT */ "No such file or directory", + /* 3 ESRCH */ "No such process", + /* 4 EINTR */ "Interrupted system call", + /* 5 EIO */ "I/O error", + /* 6 ENXIO */ "No such device or address", + /* 7 E2BIG */ "Arg list too long", + /* 8 ENOEXEC */ "Exec format error", + /* 9 EBADF */ "Bad file number", + /* 10 ECHILD */ "No child processes", + /* 11 EAGAIN */ "Try again", + /* 12 ENOMEM */ "Out of memory", + /* 13 EACCES */ "Permission denied", + /* 14 EFAULT */ "Bad address", + /* 15 ENOTBLK */ "Block device required", + /* 16 EBUSY */ "Device or resource busy", + /* 17 EEXIST */ "File exists", + /* 18 EXDEV */ "Cross-device link", + /* 19 ENODEV */ "No such device", + /* 20 ENOTDIR */ "Not a directory", + /* 21 EISDIR */ "Is a directory", + /* 22 EINVAL */ "Invalid argument", + /* 23 ENFILE */ "File table overflow", + /* 24 EMFILE */ "Too many open files", + /* 25 ENOTTY */ "Not a typewriter", + /* 26 ETXTBSY */ "Text file busy", + /* 27 EFBIG */ "File too large", + /* 28 ENOSPC */ "No space left on device", + /* 29 ESPIPE */ "Illegal seek", + /* 30 EROFS */ "Read-only file system", + /* 31 EMLINK */ "Too many links", + /* 32 EPIPE */ "Broken pipe", + /* 33 EDOM */ "Math argument out of domain of func", + /* 34 ERANGE */ "Math result not representable", + /* 35 EDEADLK */ "Resource deadlock would occur", + /* 36 ENAMETOOLONG */ "File name too long", + /* 37 ENOLCK */ "No record locks available", + /* 38 ENOSYS */ "Function not implemented", + /* 39 ENOTEMPTY */ "Directory not empty", + /* 40 ELOOP */ "Too many symbolic links encountered", + /* 41 */ "", + /* 42 ENOMSG */ "No message of desired type", + /* 43 EIDRM */ "Identifier removed", + /* 44 ECHRNG */ "Channel number out of range", + /* 45 EL2NSYNC */ "Level 2 not synchronized", + /* 46 EL3HLT */ "Level 3 halted", + /* 47 EL3RST */ "Level 3 reset", + /* 48 ELNRNG */ "Link number out of range", + /* 49 EUNATCH */ "Protocol driver not attached", + /* 50 ENOCSI */ "No CSI structure available", + /* 51 EL2HLT */ "Level 2 halted", + /* 52 EBADE */ "Invalid exchange", + /* 53 EBADR */ "Invalid request descriptor", + /* 54 EXFULL */ "Exchange full", + /* 55 ENOANO */ "No anode", + /* 56 EBADRQC */ "Invalid request code", + /* 57 EBADSLT */ "Invalid slot", + /* 58 */ "", + /* 59 EBFONT */ "Bad font file format", + /* 60 ENOSTR */ "Device not a stream", + /* 61 ENODATA */ "No data available", + /* 62 ETIME */ "Timer expired", + /* 63 ENOSR */ "Out of streams resources", + /* 64 ENONET */ "Machine is not on the network", + /* 65 ENOPKG */ "Package not installed", + /* 66 EREMOTE */ "Object is remote", + /* 67 ENOLINK */ "Link has been severed", + /* 68 EADV */ "Advertise error", + /* 69 ESRMNT */ "Srmount error", + /* 70 ECOMM */ "Communication error on send", + /* 71 EPROTO */ "Protocol error", + /* 72 EMULTIHOP */ "Multihop attempted", + /* 73 EDOTDOT */ "RFS specific error", + /* 74 EBADMSG */ "Not a data message", + /* 75 EOVERFLOW */ "Value too large for defined data type", + /* 76 ENOTUNIQ */ "Name not unique on network", + /* 77 EBADFD */ "File descriptor in bad state", + /* 78 EREMCHG */ "Remote address changed", + /* 79 ELIBACC */ "Can not access a needed shared library", + /* 80 ELIBBAD */ "Accessing a corrupted shared library", + /* 81 ELIBSCN */ ".lib section in a.out corrupted", + /* 82 ELIBMAX */ "Attempting to link in too many shared libraries", + /* 83 ELIBEXEC */ "Cannot exec a shared library directly", + /* 84 EILSEQ */ "Illegal byte sequence", + /* 85 ERESTART */ "Interrupted system call should be restarted", + /* 86 ESTRPIPE */ "Streams pipe error", + /* 87 EUSERS */ "Too many users", + /* 88 ENOTSOCK */ "Socket operation on non-socket", + /* 89 EDESTADDRREQ */ "Destination address required", + /* 90 EMSGSIZE */ "Message too long", + /* 91 EPROTOTYPE */ "Protocol wrong type for socket", + /* 92 ENOPROTOOPT */ "Protocol not available", + /* 93 EPROTONOSUPPORT */ "Protocol not supported", + /* 94 ESOCKTNOSUPPORT */ "Socket type not supported", + /* 95 EOPNOTSUPP */ "Operation not supported on transport endpoint", + /* 96 EPFNOSUPPORT */ "Protocol family not supported", + /* 97 EAFNOSUPPORT */ "Address family not supported by protocol", + /* 98 EADDRINUSE */ "Address already in use", + /* 99 EADDRNOTAVAIL */ "Cannot assign requested address", + /* 100 ENETDOWN */ "Network is down", + /* 101 ENETUNREACH */ "Network is unreachable", + /* 102 ENETRESET */ "Network dropped connection because of reset", + /* 103 ECONNABORTED */ "Software caused connection abort", + /* 104 ECONNRESET */ "Connection reset by peer", + /* 105 ENOBUFS */ "No buffer space available", + /* 106 EISCONN */ "Transport endpoint is already connected", + /* 107 ENOTCONN */ "Transport endpoint is not connected", + /* 108 ESHUTDOWN */ "Cannot send after transport endpoint shutdown", + /* 109 ETOOMANYREFS */ "Too many references: cannot splice", + /* 110 ETIMEDOUT */ "Connection timed out", + /* 111 ECONNREFUSED */ "Connection refused", + /* 112 EHOSTDOWN */ "Host is down", + /* 113 EHOSTUNREACH */ "No route to host", + /* 114 EALREADY */ "Operation already in progress", + /* 115 EINPROGRESS */ "Operation now in progress", + /* 116 ESTALE */ "Stale NFS file handle", + /* 117 EUCLEAN */ "Structure needs cleaning", + /* 118 ENOTNAM */ "Not a XENIX named type file", + /* 119 ENAVAIL */ "No XENIX semaphores available", + /* 120 EISNAM */ "Is a named type file", + /* 121 EREMOTEIO */ "Remote I/O error", + /* 122 EDQUOT */ "Quota exceeded", + /* 121 */ "", + /* 123 ENOMEDIUM */ "No medium found", + /* 124 EMEDIUMTYPE */ "Wrong medium type" + /* if more are added, be sure to update _sys_nerr accordingly */ +}; +#else +char *_sys_errlist[] = { + /* 0 EZERO */ "No error", + /* 1 ENOENT */ "No such file or directory", + /* 2 E2BIG */ "Arg list too big", + /* 3 ENOEXEC */ "Exec format error", + /* 4 EBADF */ "Bad file number", + /* 5 ENOMEM */ "Not enough memory", + /* 6 EACCES */ "Permission denied", + /* 7 EEXIST */ "File exists", + /* 8 EXDEV */ "Cross-device link", + /* 9 EINVAL */ "Invalid argument", + /* 10 ENFILE */ "File table overflow", + /* 11 EMFILE */ "Too many open files", + /* 12 ENOSPC */ "No space left on device", + /* 13 EDOM */ "Argument too large", + /* 14 ERANGE */ "Result too large", + /* 15 EDEADLK */ "Resource deadlock would occur", + /* 16 EINTR */ "System call interrupted", + /* 17 ECHILD */ "Child does not exist", + /* 18 EAGAIN */ "Resource unavailable, try again", + /* 19 EBUSY */ "Device or resource busy", + /* 20 EFBIG */ "File too large", + /* 21 EIO */ "I/O error", + /* 22 EISDIR */ "Is a directory", + /* 23 ENOTDIR */ "Not a directory", + /* 24 EMLINK */ "Too many links", + /* 25 ENOTBLK */ "Block device required", + /* 26 ENOTTY */ "Not a character device", + /* 27 ENXIO */ "No such device or address", + /* 28 EPERM */ "Not owner", + /* 29 EPIPE */ "Broken pipe", + /* 30 EROFS */ "Read-only file system", + /* 31 ESPIPE */ "Illegal seek", + /* 32 ESRCH */ "No such process", + /* 33 ETXTBSY */ "Text file busy", + /* 34 EFAULT */ "Bad address", + /* 35 ENAMETOOLONG */ "Filename too long", + /* 36 ENODEV */ "No such device", + /* 37 ENOLCK */ "No locks available in system", + /* 38 ENOSYS */ "Unknown system call", + /* 39 ENOTEMPTY */ "Directory not empty", + /* 40 EILSEQ */ "Illegal multibyte sequence" + /* if more are added, be sure to update _sys_nerr accordingly */ +}; +#endif + +int _WCNEAR _sys_nerr = ( sizeof( _sys_errlist ) / sizeof( *_sys_errlist ) ); + +#endif + +_WCRTLINK CHAR_TYPE *__F_NAME(strerror,wcserror)( int errnum ) +{ +#ifdef __WIDECHAR__ + static wchar_t Wide_Error_String[40]; +#endif + char *msg; + + if( errnum < 0 || errnum >= _sys_nerr ) { + msg = UNKNOWN_ERROR; + } else { + msg = _sys_errlist[ errnum ]; + } + return( _AToUni( Wide_Error_String, msg ) ); +} + +// Note: Windows FORMAT_MESSAGE_MAX_WIDTH_MASK is 255 + +#if !defined(FORMAT_MESSAGE_MAX_WIDTH_MASK) + #define FORMAT_MESSAGE_MAX_WIDTH_MASK 255 +#endif + +#ifdef __WIDECHAR__ +static wchar_t Wide_Error_String[FORMAT_MESSAGE_MAX_WIDTH_MASK+1]; +#else +static char Error_String[FORMAT_MESSAGE_MAX_WIDTH_MASK+1]; +#endif + + +/* + char *_strerror( const char *strErrMsg ); + + Description from the MSDN: + + If strErrMsg is passed as NULL, _strerror returns a pointer to a + string containing the system error message for the last library call + that produced an error. The error-message string is terminated by + the newline character ('\n'). If strErrMsg is not equal to NULL, + then _strerror returns a pointer to a string containing (in order) + your string message, a colon, a space, the system error message for + the last library call producing an error, and a newline character. + Your string message can be, at most, 94 bytes long. + + The actual error number for _strerror is stored in the variable + errno. The system error messages are accessed through the variable + _sys_errlist, which is an array of messages ordered by error number. + _strerror accesses the appropriate error message by using the errno + value as an index to the variable _sys_errlist. The value of the + variable _sys_nerr is defined as the maximum number of elements in + the _sys_errlist array. To produce accurate results, call _strerror + immediately after a library routine returns with an error. + Otherwise, subsequent calls to strerror or _strerror can overwrite + the errno value. + + _strerror is not part of the ANSI definition but is instead a + Microsoft extension to it. Do not use it where portability is + desired; for ANSI compatibility, use strerror instead. + + */ + +_WCRTLINK CHAR_TYPE *__F_NAME(_strerror,_wcserror)( const CHAR_TYPE *strErrMsg ) +{ + int errnum; + + errnum = _RWD_errno; +#ifdef __WIDECHAR__ + Wide_Error_String[0] = L'\0'; + if( strErrMsg != NULL ) { + wcsncpy( Wide_Error_String, strErrMsg, 94 ); + Wide_Error_String[94] = L'\0'; // just in case more than 94 + wcscat( Wide_Error_String, L": " ); + } + wcscat( Wide_Error_String, wcserror( errnum ) ); + wcscat( Wide_Error_String, L"\n" ); + return( Wide_Error_String ); +#else + Error_String[0] = '\0'; + if( strErrMsg != NULL ) { + strncpy( Error_String, strErrMsg, 94 ); + Error_String[94] = '\0'; // just in case more than 94 + strcat( Error_String, ": " ); + } + strcat( Error_String, strerror( errnum ) ); + strcat( Error_String, "\n" ); + return( Error_String ); +#endif +} + +#if defined(__NT__) + +_WCRTLINK CHAR_TYPE *__F_NAME(_doserror,_wdoserror)( int errnum ) +{ +#ifdef __WIDECHAR__ + Wide_Error_String[0] = L'\0'; + FormatMessageW( FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + errnum, + 0, + Wide_Error_String, + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL ); + return( Wide_Error_String ); +#else + Error_String[0] = '\0'; + FormatMessageA( FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + errnum, + 0, + Error_String, + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL ); + return( Error_String ); +#endif +} + +#endif diff --git a/programs/develop/open watcom/trunk/clib/string/stricmp.c b/programs/develop/open watcom/trunk/clib/string/stricmp.c new file mode 100644 index 000000000..896ae3754 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/stricmp.c @@ -0,0 +1,62 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "riscstr.h" + +/* return <0 if s0 if s>t */ + +#if defined(__RISCSTR__) && defined(__WIDECHAR__) + _WCRTLINK int __simple__wcsicmp( const CHAR_TYPE *s, const CHAR_TYPE *t ) { +#else + _WCRTLINK int __F_NAME(stricmp,_wcsicmp)( const CHAR_TYPE *s, const CHAR_TYPE *t ) { +#endif + UCHAR_TYPE c1; + UCHAR_TYPE c2; + + for(;;) { + c1 = *s; + c2 = *t; + if( IS_ASCII( c1 ) && IS_ASCII( c2 ) ) { + if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A'; + if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A'; + } + if( c1 != c2 ) break; + if( c1 == NULLCHAR ) break; + ++s; + ++t; + } + return( c1 - c2 ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strlcat.c b/programs/develop/open watcom/trunk/clib/string/strlcat.c new file mode 100644 index 000000000..56a24f5a8 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strlcat.c @@ -0,0 +1,68 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of BSD style strlcat() and wcslcat(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include + + +_WCRTLINK size_t __F_NAME(strlcat,wcslcat)( CHAR_TYPE *dst, const CHAR_TYPE *t, size_t n ) +{ + CHAR_TYPE *s; + size_t len; + + s = dst; + // Find end of string in destination buffer but don't overrun + for( len = n; len; --len ) { + if( *s == NULLCHAR ) break; + ++s; + } + // If no null char was found in dst, the buffer is messed up; don't + // touch it + if( *s == NULLCHAR ) { + --len; // Decrement len to leave space for terminating null + while( len != 0 ) { + *s = *t; + if( *s == NULLCHAR ) { + return( n - len - 1 ); + } + ++s; + ++t; + --len; + } + // Buffer not large enough. Terminate and figure out desired length + *s = NULLCHAR; + while( *t++ != NULLCHAR ) + ++n; + --n; + } + return( n ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strlcpy.c b/programs/develop/open watcom/trunk/clib/string/strlcpy.c new file mode 100644 index 000000000..95adad2b8 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strlcpy.c @@ -0,0 +1,64 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of BSD style strlcpy() and wcslcpy(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include + + +_WCRTLINK size_t __F_NAME(strlcpy,wcslcpy)( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t len ) +{ + const CHAR_TYPE *s; + size_t count; + + count = len; + if( len ) { + --len; // leave space for terminating null + for( ; len; --len ) { + if( *src == NULLCHAR ) { + break; + } + *dst++ = *src++; + } + *dst = NULLCHAR; // terminate 'dst' + } else { + ++count; // account for not decrementing 'len' + } + + if( !len ) { // source string was truncated + s = src; + while( *s != NULLCHAR ) { + ++s; + } + count += s - src; // find out how long 'src' really is + } + return( count - len - 1 ); // final null doesn't count +} diff --git a/programs/develop/open watcom/trunk/clib/src/strlen.c b/programs/develop/open watcom/trunk/clib/string/strlen.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strlen.c rename to programs/develop/open watcom/trunk/clib/string/strlen.c diff --git a/programs/develop/open watcom/trunk/clib/string/strlwr.c b/programs/develop/open watcom/trunk/clib/string/strlwr.c new file mode 100644 index 000000000..a138b4abe --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strlwr.c @@ -0,0 +1,59 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strlwr(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "riscstr.h" + + +#if defined(__RISCSTR__) && defined(__WIDECHAR__) + _WCRTLINK CHAR_TYPE *__simple__wcslwr( CHAR_TYPE *str ) { +#else + _WCRTLINK CHAR_TYPE *__F_NAME(strlwr,_wcslwr)( CHAR_TYPE *str ) { +#endif + CHAR_TYPE *p; + UCHAR_TYPE c; + + p = str; + while( (c = *p) ) { + if( IS_ASCII( c ) ) { + c -= 'A'; + if( c <= 'Z' - 'A' ) { + c += 'a'; + *p = c; + } + } + ++p; + } + return( str ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strncat.c b/programs/develop/open watcom/trunk/clib/string/strncat.c new file mode 100644 index 000000000..57ece7d01 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strncat.c @@ -0,0 +1,116 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include + +#if defined(M_I86) && !defined(__WIDECHAR__) + +extern char *_fast_strncat( char _WCFAR *, const char *, size_t ); + +#if defined(__SMALL_DATA__) + +#pragma aux _fast_strncat = \ + 0x57 /* push di */\ + 0xb9 0xff 0xff /* mov cx,ffffh */\ + 0x31 0xc0 /* xor ax,ax */\ + 0xf2 0xae /* repne scasb */\ + 0x4f /* dec di */\ + 0x89 0xd1 /* mov cx,dx */\ + 0xac /* L1: lodsb */\ + 0xaa /* stosb */\ + 0x84 0xc0 /* test al,al */\ + 0xe0 0xfa /* loopne L1 */\ + 0x74 0x03 /* je L2 */\ + 0x26 0x88 0x25 /* mov es:[di],ah */\ + 0x58 /* L2: pop ax */\ + parm caller [es di] [si] [dx]\ + value [ax] \ + modify exact [ax cx si di]; + +#else + +#pragma aux _fast_strncat = \ + 0x1e /* push ds */ \ + 0x8e 0xd9 /* mov ds,cx */ \ + 0x57 /* push di */\ + 0xb9 0xff 0xff /* mov cx,ffffh */\ + 0x31 0xc0 /* xor ax,ax */\ + 0xf2 0xae /* repne scasb */\ + 0x4f /* dec di */\ + 0x89 0xd1 /* mov cx,dx */\ + 0xac /* L1: lodsb */\ + 0xaa /* stosb */\ + 0x84 0xc0 /* test al,al */\ + 0xe0 0xfa /* loopne L1 */\ + 0x74 0x03 /* je L2 */\ + 0x26 0x88 0x25 /* mov es:[di],ah */\ + 0x58 /* L2: pop ax */\ + 0x1f /* pop ds */ \ + parm caller [es di] [cx si] [dx]\ + value [es ax] \ + modify exact [ax cx si di]; +#endif + +#endif + + +/* concatenate t to the end of dst */ + +_WCRTLINK CHAR_TYPE *__F_NAME(strncat,wcsncat) ( CHAR_TYPE *dst, const CHAR_TYPE *t, size_t n ) + { +#if defined(M_I86) && !defined(__WIDECHAR__) + if( n ) { + return( _fast_strncat( dst, t, n ) ); + } + return( dst ); +#else + CHAR_TYPE *s; + + #ifdef __WIDECHAR__ + s = dst + wcslen( dst ); + #else + s = memchr( dst, NULLCHAR, ~0u ); + #endif + while( n != 0 ) { + *s = *t; + if( *s == NULLCHAR ) break; + ++s; + ++t; + --n; + } + *s = NULLCHAR; + return( dst ); +#endif + } diff --git a/programs/develop/open watcom/trunk/clib/src/strncmp.c b/programs/develop/open watcom/trunk/clib/string/strncmp.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strncmp.c rename to programs/develop/open watcom/trunk/clib/string/strncmp.c diff --git a/programs/develop/open watcom/trunk/clib/src/strncpy.c b/programs/develop/open watcom/trunk/clib/string/strncpy.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strncpy.c rename to programs/develop/open watcom/trunk/clib/string/strncpy.c diff --git a/programs/develop/open watcom/trunk/clib/src/strnicmp.c b/programs/develop/open watcom/trunk/clib/string/strnicmp.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strnicmp.c rename to programs/develop/open watcom/trunk/clib/string/strnicmp.c diff --git a/programs/develop/open watcom/trunk/clib/string/strnln_s.c b/programs/develop/open watcom/trunk/clib/string/strnln_s.c new file mode 100644 index 000000000..cd302736a --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strnln_s.c @@ -0,0 +1,51 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strnlen_s() - "safe" strnlen(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include + + +_WCRTLINK size_t __F_NAME(strnlen_s,wcsnlen_s)( const CHAR_TYPE *s, size_t maxsize ) +/**********************************************************************************/ +{ + size_t m = 0; + + // ensure the pointer is not NULL + if( s != NULL ) { + // count chars up to '\0' or maxsize + while( *(s + m) != NULLCHAR && m < maxsize ) + ++m; + } + return( m ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strnset.c b/programs/develop/open watcom/trunk/clib/string/strnset.c new file mode 100644 index 000000000..ac2cc5dcb --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strnset.c @@ -0,0 +1,52 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include "riscstr.h" + + +#if defined(__RISCSTR__) && defined(__WIDECHAR__) + _WCRTLINK CHAR_TYPE *__simple__wcsnset( CHAR_TYPE *str, int c, size_t len ) +#else + _WCRTLINK CHAR_TYPE *__F_NAME(strnset,_wcsnset)( CHAR_TYPE *str, int c, size_t len ) +#endif + { + CHAR_TYPE *p; + + for( p = str; len; --len ) { + if( *p == NULLCHAR ) break; + *p++ = c; + } + return( str ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/strpbrk.c b/programs/develop/open watcom/trunk/clib/string/strpbrk.c new file mode 100644 index 000000000..52e9f07bf --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strpbrk.c @@ -0,0 +1,75 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "setbits.h" + +/* The strpbrk function locates the first occurrence in the string pointed + to by str of any character from the string pointed to by charset. +*/ + + +_WCRTLINK CHAR_TYPE *__F_NAME(strpbrk,wcspbrk) ( const CHAR_TYPE *str, const CHAR_TYPE *charset ) +{ +#if defined(__WIDECHAR__) + + const CHAR_TYPE *p1; + const CHAR_TYPE *p2; + CHAR_TYPE tc1; + CHAR_TYPE tc2; + size_t len; + + len = 0; + for( p1 = str; tc1 = *p1; p1++, len++ ) { + for( p2 = charset; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 != NULLCHAR ) return( (CHAR_TYPE *)p1 ); + } + return( NULL ); + +#else + unsigned char tc; + unsigned char vector[32]; + + __setbits( vector, charset ); + for( ; tc = *str; ++str ) { + /* quit when we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) + return( (char *)str ); + } + return( NULL ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/src/strrchr.c b/programs/develop/open watcom/trunk/clib/string/strrchr.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strrchr.c rename to programs/develop/open watcom/trunk/clib/string/strrchr.c diff --git a/programs/develop/open watcom/trunk/clib/string/strrev.c b/programs/develop/open watcom/trunk/clib/string/strrev.c new file mode 100644 index 000000000..4b9527db4 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strrev.c @@ -0,0 +1,157 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include + +#if defined(__WIDECHAR__) +extern size_t wcslen( const CHAR_TYPE * ); +#endif + +#if defined(M_I86) && !defined(__WIDECHAR__) + +/* + explanation of algorithm: + + (1) reverse as much of the string as possible as words + + (2) after main loop: reverse residual inner string (0-3 bytes) + + the string falls into one of these forms: + + { prefix_word }* { suffix_word }* + { prefix_word }* middle_byte { suffix_word }* + { prefix_word }* pre_middle_byte post_middle_byte { suffix_word }* + { prefix_word }* pre_middle_byte middle_byte post_middle_byte { suffix_word }* + + we only have to swap two bytes when: + + len & 2 != 0 is true (ie. the carry is set after second shr cx,1) + +***************************************************************************** + WARNING: the code in the L1: ... reverse loop cannot modify the carry flag +***************************************************************************** +*/ + +extern void fast_rev( char *, char _WCFAR * ); + +#if defined(__SMALL_DATA__) +#pragma aux fast_rev = \ + 0xb9 0xff 0xff /* mov cx,ffff */\ + 0x30 0xc0 /* xor al,al */\ + 0xf2 0xae /* repne scasb */\ + 0xf7 0xd1 /* not cx */\ + 0x49 /* dec cx */\ + 0xfd /* std */\ + 0x83 0xef 0x03 /* sub di,3 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xe3 0x0d /* jcxz L2 */\ + 0x8b 0x05 /* L1:mov ax,[di] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0x87 0x04 /* xchg ax,[si] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0xab /* stosw */\ + 0x46 /* inc si */\ + 0x46 /* inc si */\ + 0xe2 0xf3 /* loop L1 */\ + 0x73 0x07 /* L2:jnc L3 */\ + 0x47 /* inc di */\ + 0x8a 0x05 /* mov al,[di] */\ + 0x86 0x04 /* xchg al,[si] */\ + 0x88 0x05 /* mov [di],al */\ + 0xfc /* L3:cld */\ + parm caller [si] [es di] \ + value [ax] \ + modify [si cx ax di]; +#else +#pragma aux fast_rev = \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0xb9 0xff 0xff /* mov cx,ffff */\ + 0x30 0xc0 /* xor al,al */\ + 0xf2 0xae /* repne scasb */\ + 0xf7 0xd1 /* not cx */\ + 0x49 /* dec cx */\ + 0xfd /* std */\ + 0x83 0xef 0x03 /* sub di,3 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xd1 0xe9 /* shr cx,1 */\ + 0xe3 0x0d /* jcxz L2 */\ + 0x8b 0x05 /* L1:mov ax,[di] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0x87 0x04 /* xchg ax,[si] */\ + 0x86 0xe0 /* xchg ah,al */\ + 0xab /* stosw */\ + 0x46 /* inc si */\ + 0x46 /* inc si */\ + 0xe2 0xf3 /* loop L1 */\ + 0x73 0x07 /* L2:jnc L3 */\ + 0x47 /* inc di */\ + 0x8a 0x05 /* mov al,[di] */\ + 0x86 0x04 /* xchg al,[si] */\ + 0x88 0x05 /* mov [di],al */\ + 0xfc /* L3:cld */\ + 0x1f /* pop ds */ \ + parm caller [dx si] [es di] \ + value [ax] \ + modify [si cx ax di]; +#endif + +#endif + + +_WCRTLINK CHAR_TYPE *__F_NAME(strrev,_wcsrev) ( CHAR_TYPE *str ) { /* reverse characters in string */ + #if defined(M_I86) && !defined(__WIDECHAR__) + fast_rev( str, (char _WCFAR *) str ); + return( str ); + #else + CHAR_TYPE *p1; + CHAR_TYPE *p2; + CHAR_TYPE c1; + CHAR_TYPE c2; + + p1 = str; + p2 = p1 + __F_NAME(strlen,wcslen)( p1 ) - 1; + while( p1 < p2 ) { + c1 = *p1; + c2 = *p2; + *p1 = c2; + *p2 = c1; + ++p1; + --p2; + } + return( str ); + #endif +} diff --git a/programs/develop/open watcom/trunk/clib/string/strset.c b/programs/develop/open watcom/trunk/clib/string/strset.c new file mode 100644 index 000000000..f2caf68ac --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strset.c @@ -0,0 +1,50 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strset() and _wcsset() +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include "riscstr.h" + + +#if defined(__RISCSTR__) && defined(__WIDECHAR__) + _WCRTLINK CHAR_TYPE *__simple__wcsset( CHAR_TYPE *s, INTCHAR_TYPE c ) +#else + _WCRTLINK CHAR_TYPE *__F_NAME(strset,_wcsset)( CHAR_TYPE *s, INTCHAR_TYPE c ) +#endif +{ + CHAR_TYPE *p; + + for( p = s; *p; ++p ) { + *p = c; + } + return( s ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strspn.c b/programs/develop/open watcom/trunk/clib/string/strspn.c new file mode 100644 index 000000000..09f275096 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strspn.c @@ -0,0 +1,78 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "setbits.h" + +/* The strspn function computes the length of the initial segment of the + string pointed to by str which consists entirely of characters from + the string pointed to by charset. +*/ + + +_WCRTLINK size_t __F_NAME(strspn,wcsspn) ( const CHAR_TYPE *str, const CHAR_TYPE *charset ) +{ +#if defined(__WIDECHAR__) + + const CHAR_TYPE *p1; + const CHAR_TYPE *p2; + CHAR_TYPE tc1; + CHAR_TYPE tc2; + size_t len; + + len = 0; + for( p1 = str; tc1 = *p1; p1++, len++ ) { + for( p2 = charset; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 == NULLCHAR ) break; + } + return( len ); + + +#else + unsigned /*char*/ tc; + unsigned char vector[32]; + size_t len; + + __setbits( vector, charset ); + len = 0; + for( ; tc = (unsigned char) *str; ++str, ++len ) { + /* quit if we find any char not in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break; + } + return( len ); +#endif +} diff --git a/programs/develop/open watcom/trunk/clib/string/strspnp.c b/programs/develop/open watcom/trunk/clib/string/strspnp.c new file mode 100644 index 000000000..8f2e3eb84 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strspnp.c @@ -0,0 +1,48 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include + + +_WCRTLINK CHAR_TYPE *__F_NAME(strspnp,_wcsspnp)( const CHAR_TYPE *p1, const CHAR_TYPE *p2 ) +{ + size_t index; + + index = __F_NAME(strspn,wcsspn)( p1, p2 ); + if( *(p1+index) != __F_NAME('\0',L'\0') ) { + return( (CHAR_TYPE*)(p1+index) ); + } else { + return( NULL ); + } +} diff --git a/programs/develop/open watcom/trunk/clib/string/strstr.c b/programs/develop/open watcom/trunk/clib/string/strstr.c new file mode 100644 index 000000000..f232fddfc --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strstr.c @@ -0,0 +1,113 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strstr() and wcsstr(). +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#if defined(_M_IX86) + #include +#endif + +#if defined(M_I86) && !defined( __WIDECHAR__ ) + +extern int i86_memeq( const char *, const char _WCFAR *, int ); + +#define _ZFLAG (INTR_ZF<<8) + +#if defined(__SMALL_DATA__) + +#pragma aux i86_memeq = \ + 0xf3 0xa6 /* rep cmpsb */\ + 0x9f /* lahf */\ + parm caller [si] [es di] [cx]\ + value [ax] \ + modify exact [si di cx ax]; + +#else + +#pragma aux i86_memeq = \ + 0x1e /* push ds */ \ + 0x8e 0xda /* mov ds,dx */ \ + 0xf3 0xa6 /* rep cmpsb */\ + 0x9f /* lahf */\ + 0x1f /* pop ds */ \ + parm caller [dx si] [es di] [cx]\ + value [ax] \ + modify exact [si di cx ax]; + +#endif + +#define memeq( p1, p2, len ) ( i86_memeq((p1),(p2),(len)) & _ZFLAG ) + +#else + +#define memeq( p1, p2, len ) ( memcmp((p1),(p2),(len)*CHARSIZE) == 0 ) + +#endif + +/* Locate the first occurrence of the string pointed to by s2 in the + string pointed to by s1. + The strstr function returns a pointer to the located string, or a + null pointer if the string is not found. +*/ + + +_WCRTLINK CHAR_TYPE *__F_NAME(strstr,wcsstr) ( const CHAR_TYPE *s1, const CHAR_TYPE *s2 ) + { + CHAR_TYPE *end_of_s1; + size_t s1len, s2len; + + if( s2[0] == NULLCHAR ) { + return( (CHAR_TYPE *)s1 ); + } else if( s2[1] == NULLCHAR ) { + return( __F_NAME(strchr,wcschr)( s1, s2[0] ) ); + } + #ifdef __WIDECHAR__ + end_of_s1 = (CHAR_TYPE*)s1 + wcslen( s1 ); + #else + end_of_s1 = memchr( s1, NULLCHAR, ~0u ); + #endif + s2len = __F_NAME(strlen,wcslen)( s2 ); + for(;;) { + s1len = end_of_s1 - s1; + if( s1len < s2len ) break; + #ifdef __WIDECHAR__ + s1 = wcschr( s1, *s2 ); /* find start of possible match */ + #else + s1 = memchr( s1, *s2, s1len ); /* find start of possible match */ + #endif + if( s1 == NULL ) break; + if( memeq( s1, s2, s2len ) ) return( (CHAR_TYPE *)s1 ); + ++s1; + } + return( NULL ); + } diff --git a/programs/develop/open watcom/trunk/clib/string/strtok.c b/programs/develop/open watcom/trunk/clib/string/strtok.c new file mode 100644 index 000000000..38d7da9f9 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strtok.c @@ -0,0 +1,139 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include +#include +#include "rtdata.h" +#ifdef __WIDECHAR__ + #include "nextwtok.h" +#else + #include "nexttok.h" +#endif +#include "setbits.h" + + +#ifdef __WIDECHAR__ +_WCRTLINK wchar_t *_ustrtok( wchar_t *str, const wchar_t *charset ) +{ + return( wcstok( str, charset, NULL ) ); +} +#endif + + +#ifdef __WIDECHAR__ + _WCRTLINK wchar_t *wcstok( wchar_t *str, const wchar_t *charset, wchar_t **ptr ) +#else + _WCRTLINK char *strtok( char *str, const char *charset ) +#endif +{ +#if defined(__WIDECHAR__) + CHAR_TYPE *p1; + const CHAR_TYPE *p2; + CHAR_TYPE tc1; + CHAR_TYPE tc2; +#else + unsigned /*char*/ tc; + unsigned char vector[32]; + unsigned char *p1; +#endif + +#if defined(__WIDECHAR__) + /* if necessary, continue from where we left off */ + if( str == NULL ) { + if( ptr == NULL ) { + str = _RWD_nextwtok; + } else { + str = *ptr; /* use previous value */ + } + if( str == NULL ) return( NULL ); + } + + /* skip characters until we reach one not in charset */ + for( ; tc1 = *str; str++ ) { + for( p2 = charset; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 == NULLCHAR ) break; + } + if( tc1 == NULLCHAR ) return( NULL ); + /* skip characters until we reach one in charset */ + for( p1 = str; tc1 = *p1; p1++ ) { + for( p2 = charset; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 != NULLCHAR ){ + *p1 = NULLCHAR; /* terminate the token */ + p1++; /* start of next token */ + if( ptr == NULL ) { + _RWD_nextwtok = p1; + } else { + *ptr = p1; + } + return( str ); + } + } + if( ptr == NULL ) { + _RWD_nextwtok = NULL; + } else { + *ptr = NULL; + } +#else + /* if necessary, continue from where we left off */ + _INITNEXTTOK + if( str == NULL ) { + str = (CHAR_TYPE*)_RWD_nexttok; /* use previous value */ + if( str == NULL ) return( NULL ); + } + + __setbits( vector, charset ); + for( ; tc = (unsigned char) *str; ++str ) { + /* quit if we find any char not in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) == 0 ) break; + } + if( tc == '\0' ) return( NULL ); + p1 = str; + for( ; tc = *p1; ++p1 ) { + /* quit when we find any char in charset */ + if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) { + *p1 = '\0'; /* terminate the token */ + p1++; /* start of next token */ + _RWD_nexttok = p1; + return( str ); + } + } + _RWD_nexttok = NULL; +#endif + + return( str ); +} diff --git a/programs/develop/open watcom/trunk/clib/string/strtok_s.c b/programs/develop/open watcom/trunk/clib/string/strtok_s.c new file mode 100644 index 000000000..f87efaf04 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strtok_s.c @@ -0,0 +1,137 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: Implementation of strtok_s() - bounds-checking strtok(). +* +****************************************************************************/ + + +#include "variety.h" +#include "saferlib.h" +#include "widechar.h" +#include +#include +#include "setbits.h" + + +_WCRTLINK CHAR_TYPE *__F_NAME(strtok_s,wcstok_s)( CHAR_TYPE * __restrict s1, + rsize_t * __restrict s1max, const CHAR_TYPE * __restrict s2, + CHAR_TYPE ** __restrict ptr ) +/****************************************************************************/ +{ +#ifdef __WIDECHAR__ + const CHAR_TYPE *p2; + CHAR_TYPE tc2; +#else + char vector[32]; +#endif + char *msg = NULL; + CHAR_TYPE *p1 = s1; + CHAR_TYPE *str; + rsize_t m; + CHAR_TYPE tc1; + + // Verify runtime-constraints + // s1max not NULL + // s2 not NULL + // ptr not NULL + // *s1max <= RSIZE_MAX + // if s1 == NULL then *ptr != NULL + if( __check_constraint_nullptr_msg( msg, s1max ) && + __check_constraint_nullptr_msg( msg, s2 ) && + __check_constraint_nullptr_msg( msg, ptr ) && + __check_constraint_maxsize_msg( msg, *s1max ) && + ((s1 != NULL) || __check_constraint_nullptr_msg( msg, *ptr )) ) { + + /* if necessary, continue from where we left off */ + if( s1 == NULL ) { + p1 = *ptr; /* use previous value */ + } +#ifndef __WIDECHAR__ + __setbits( vector, s2 ); +#endif + m = *s1max; + for( ; tc1 = *p1; ++p1 ) { + if( ! ((m == 0) ? ( msg = "no start of token found" ), 0 : 1 ) ) { + break; /* limit reached, quit */ + } + +#ifdef __WIDECHAR__ + for( p2 = s2; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 == NULLCHAR ) break; +#else + /* quit if we find any char not in charset */ + if( ( vector[ tc1 >> 3 ] & _Bits[ tc1 & 0x07 ] ) == 0 ) break; +#endif + --m; + } + + if( msg == NULL ) { /* no rt-constraint violated */ + if( tc1 == NULLCHAR ) return( NULL ); /* no (more) tokens */ + } else { + /* Now call the handler */ + __rtct_fail( __func__, msg, NULL ); + return( NULL ); + } + + str = p1++; /* start of token */ + + for( ; tc1 = *p1; p1++ ) { + if( ! ((m == 0) ? ( msg = "no closing token delimiter found" ), 0 : 1 ) ) { + break; /* limit reached, quit */ + } + + --m; + + /* skip characters until we reach one in delimiterset */ +#ifdef __WIDECHAR__ + for( p2 = s2; tc2 = *p2; p2++ ) { + if( tc1 == tc2 ) break; + } + if( tc2 != NULLCHAR ) { +#else + if( ( vector[ tc1 >> 3 ] & _Bits[ tc1 & 0x07 ] ) != 0 ) { +#endif + *p1 = NULLCHAR; /* terminate the token */ + p1++; /* start of next token */ + *ptr = p1; + *s1max = m; + return( str ); + } + } + } + if( msg != NULL ) { /* rt-constraint violated */ + /* Now call the handler */ + __rtct_fail( __func__, msg, NULL ); + return( NULL ); + } else { + *ptr = NULL; /* last token reached */ + *s1max = 0; + } + return( str ); +} diff --git a/programs/develop/open watcom/trunk/clib/src/strupr.c b/programs/develop/open watcom/trunk/clib/string/strupr.c similarity index 100% rename from programs/develop/open watcom/trunk/clib/src/strupr.c rename to programs/develop/open watcom/trunk/clib/string/strupr.c diff --git a/programs/develop/open watcom/trunk/clib/string/strxfrm.c b/programs/develop/open watcom/trunk/clib/string/strxfrm.c new file mode 100644 index 000000000..2597292a0 --- /dev/null +++ b/programs/develop/open watcom/trunk/clib/string/strxfrm.c @@ -0,0 +1,55 @@ +/**************************************************************************** +* +* Open Watcom Project +* +* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. +* +* ======================================================================== +* +* This file contains Original Code and/or Modifications of Original +* Code as defined in and that are subject to the Sybase Open Watcom +* Public License version 1.0 (the 'License'). You may not use this file +* except in compliance with the License. BY USING THIS FILE YOU AGREE TO +* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is +* provided with the Original Code and Modifications, and is also +* available at www.sybase.com/developer/opensource. +* +* The Original Code and all software distributed under the License are +* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM +* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR +* NON-INFRINGEMENT. Please see the License for the specific language +* governing rights and limitations under the License. +* +* ======================================================================== +* +* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE +* DESCRIBE IT HERE! +* +****************************************************************************/ + + +#include "variety.h" +#include "widechar.h" +#include + +/* Transform the string so that two transformed strings can be properly + compared in the current locale. + We only support the "C" locale, so just copy the string. +*/ + +_WCRTLINK size_t __F_NAME(strxfrm,wcsxfrm)( CHAR_TYPE *dst, const CHAR_TYPE *src, size_t n ) + { + size_t len; + + len = 0; + for(;;) { + if( len < n ) *dst = *src; + if( *src == __F_NAME('\0',L'\0') ) break; + ++src; + ++dst; + ++len; + } + return( len ); + }