From 93f39e4bbf3c553a11b4214c65dd7a6399a4abbc Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:33:47 +0200 Subject: [PATCH 01/37] Run libcc.ansi through clang-format. --- lang/cem/libcc.ansi/assert/assert.c | 9 +- lang/cem/libcc.ansi/ctype/tolower.c | 7 +- lang/cem/libcc.ansi/ctype/toupper.c | 7 +- lang/cem/libcc.ansi/errno/errlist.c | 74 +-- lang/cem/libcc.ansi/locale/localeconv.c | 8 +- lang/cem/libcc.ansi/locale/setlocale.c | 36 +- lang/cem/libcc.ansi/malloc/calloc.c | 24 +- lang/cem/libcc.ansi/malloc/malloc.c | 11 +- lang/cem/libcc.ansi/malloc/realloc.c | 4 +- lang/cem/libcc.ansi/math/asin.c | 52 +- lang/cem/libcc.ansi/math/atan.c | 51 +- lang/cem/libcc.ansi/math/atan2.c | 24 +- lang/cem/libcc.ansi/math/ceil.c | 4 +- lang/cem/libcc.ansi/math/exp.c | 42 +- lang/cem/libcc.ansi/math/fabs.c | 2 +- lang/cem/libcc.ansi/math/floor.c | 4 +- lang/cem/libcc.ansi/math/fmod.c | 33 +- lang/cem/libcc.ansi/math/hypot.c | 21 +- lang/cem/libcc.ansi/math/isnan.c | 4 +- lang/cem/libcc.ansi/math/ldexp.c | 46 +- lang/cem/libcc.ansi/math/log.c | 44 +- lang/cem/libcc.ansi/math/log10.c | 15 +- lang/cem/libcc.ansi/math/pow.c | 82 +-- lang/cem/libcc.ansi/math/sin.c | 53 +- lang/cem/libcc.ansi/math/sinh.c | 55 +- lang/cem/libcc.ansi/math/sqrt.c | 28 +- lang/cem/libcc.ansi/math/tan.c | 55 +- lang/cem/libcc.ansi/math/tanh.c | 41 +- lang/cem/libcc.ansi/misc/closedir.c | 35 +- lang/cem/libcc.ansi/misc/getdents.c | 293 +++++----- lang/cem/libcc.ansi/misc/getgrent.c | 165 +++--- lang/cem/libcc.ansi/misc/getopt.c | 66 ++- lang/cem/libcc.ansi/misc/getpass.c | 31 +- lang/cem/libcc.ansi/misc/getw.c | 12 +- lang/cem/libcc.ansi/misc/mktemp.c | 42 +- lang/cem/libcc.ansi/misc/opendir.c | 71 ++- lang/cem/libcc.ansi/misc/popen.c | 83 +-- lang/cem/libcc.ansi/misc/putw.c | 13 +- lang/cem/libcc.ansi/misc/readdir.c | 45 +- lang/cem/libcc.ansi/misc/rewinddir.c | 29 +- lang/cem/libcc.ansi/misc/seekdir.c | 120 ++--- lang/cem/libcc.ansi/misc/sleep.c | 30 +- lang/cem/libcc.ansi/misc/telldir.c | 29 +- lang/cem/libcc.ansi/setjmp/sigmisc.c | 29 +- lang/cem/libcc.ansi/signal/raise.c | 5 +- lang/cem/libcc.ansi/stdio/clearerr.c | 5 +- lang/cem/libcc.ansi/stdio/data.c | 10 +- lang/cem/libcc.ansi/stdio/doprnt.c | 461 +++++++++------- lang/cem/libcc.ansi/stdio/doscan.c | 672 +++++++++++++---------- lang/cem/libcc.ansi/stdio/ecvt.c | 20 +- lang/cem/libcc.ansi/stdio/fclose.c | 20 +- lang/cem/libcc.ansi/stdio/fdopen.c | 70 +-- lang/cem/libcc.ansi/stdio/feof.c | 5 +- lang/cem/libcc.ansi/stdio/ferror.c | 5 +- lang/cem/libcc.ansi/stdio/fflush.c | 50 +- lang/cem/libcc.ansi/stdio/fgetc.c | 5 +- lang/cem/libcc.ansi/stdio/fgetpos.c | 8 +- lang/cem/libcc.ansi/stdio/fgets.c | 25 +- lang/cem/libcc.ansi/stdio/fileno.c | 5 +- lang/cem/libcc.ansi/stdio/fillbuf.c | 46 +- lang/cem/libcc.ansi/stdio/fltpr.c | 177 +++--- lang/cem/libcc.ansi/stdio/flushbuf.c | 103 ++-- lang/cem/libcc.ansi/stdio/fopen.c | 91 ++-- lang/cem/libcc.ansi/stdio/fprintf.c | 13 +- lang/cem/libcc.ansi/stdio/fputc.c | 5 +- lang/cem/libcc.ansi/stdio/fputs.c | 13 +- lang/cem/libcc.ansi/stdio/fread.c | 12 +- lang/cem/libcc.ansi/stdio/freopen.c | 89 +-- lang/cem/libcc.ansi/stdio/fscanf.c | 9 +- lang/cem/libcc.ansi/stdio/fseek.c | 17 +- lang/cem/libcc.ansi/stdio/fsetpos.c | 5 +- lang/cem/libcc.ansi/stdio/ftell.c | 19 +- lang/cem/libcc.ansi/stdio/fwrite.c | 19 +- lang/cem/libcc.ansi/stdio/getc.c | 5 +- lang/cem/libcc.ansi/stdio/getchar.c | 5 +- lang/cem/libcc.ansi/stdio/gets.c | 22 +- lang/cem/libcc.ansi/stdio/icompute.c | 11 +- lang/cem/libcc.ansi/stdio/isatty.c | 4 +- lang/cem/libcc.ansi/stdio/perror.c | 20 +- lang/cem/libcc.ansi/stdio/printf.c | 9 +- lang/cem/libcc.ansi/stdio/putc.c | 5 +- lang/cem/libcc.ansi/stdio/putchar.c | 5 +- lang/cem/libcc.ansi/stdio/puts.c | 19 +- lang/cem/libcc.ansi/stdio/remove.c | 4 +- lang/cem/libcc.ansi/stdio/rewind.c | 9 +- lang/cem/libcc.ansi/stdio/scanf.c | 11 +- lang/cem/libcc.ansi/stdio/setbuf.c | 9 +- lang/cem/libcc.ansi/stdio/setvbuf.c | 35 +- lang/cem/libcc.ansi/stdio/snprintf.c | 21 +- lang/cem/libcc.ansi/stdio/sprintf.c | 21 +- lang/cem/libcc.ansi/stdio/sscanf.c | 20 +- lang/cem/libcc.ansi/stdio/tmpfile.c | 20 +- lang/cem/libcc.ansi/stdio/tmpnam.c | 18 +- lang/cem/libcc.ansi/stdio/ungetc.c | 23 +- lang/cem/libcc.ansi/stdio/vfprintf.c | 11 +- lang/cem/libcc.ansi/stdio/vprintf.c | 9 +- lang/cem/libcc.ansi/stdio/vsnprintf.c | 21 +- lang/cem/libcc.ansi/stdio/vsprintf.c | 21 +- lang/cem/libcc.ansi/stdlib/abort.c | 15 +- lang/cem/libcc.ansi/stdlib/abs.c | 5 +- lang/cem/libcc.ansi/stdlib/atexit.c | 7 +- lang/cem/libcc.ansi/stdlib/atof.c | 9 +- lang/cem/libcc.ansi/stdlib/atoi.c | 17 +- lang/cem/libcc.ansi/stdlib/atol.c | 17 +- lang/cem/libcc.ansi/stdlib/bsearch.c | 30 +- lang/cem/libcc.ansi/stdlib/div.c | 10 +- lang/cem/libcc.ansi/stdlib/exit.c | 12 +- lang/cem/libcc.ansi/stdlib/ext_comp.c | 689 ++++++++++++++---------- lang/cem/libcc.ansi/stdlib/getenv.c | 31 +- lang/cem/libcc.ansi/stdlib/labs.c | 5 +- lang/cem/libcc.ansi/stdlib/ldiv.c | 7 +- lang/cem/libcc.ansi/stdlib/mblen.c | 15 +- lang/cem/libcc.ansi/stdlib/mbstowcs.c | 8 +- lang/cem/libcc.ansi/stdlib/mbtowc.c | 16 +- lang/cem/libcc.ansi/stdlib/putenv.c | 57 +- lang/cem/libcc.ansi/stdlib/qsort.c | 77 +-- lang/cem/libcc.ansi/stdlib/rand.c | 4 +- lang/cem/libcc.ansi/stdlib/setenv.c | 119 ++-- lang/cem/libcc.ansi/stdlib/strtod.c | 12 +- lang/cem/libcc.ansi/stdlib/strtol.c | 90 ++-- lang/cem/libcc.ansi/stdlib/system.c | 55 +- lang/cem/libcc.ansi/stdlib/wcstombs.c | 11 +- lang/cem/libcc.ansi/stdlib/wctomb.c | 10 +- lang/cem/libcc.ansi/string/memchr.c | 20 +- lang/cem/libcc.ansi/string/memcmp.c | 14 +- lang/cem/libcc.ansi/string/memcpy.c | 16 +- lang/cem/libcc.ansi/string/memmove.c | 25 +- lang/cem/libcc.ansi/string/memset.c | 13 +- lang/cem/libcc.ansi/string/strcat.c | 11 +- lang/cem/libcc.ansi/string/strchr.c | 15 +- lang/cem/libcc.ansi/string/strcmp.c | 19 +- lang/cem/libcc.ansi/string/strcoll.c | 13 +- lang/cem/libcc.ansi/string/strcpy.c | 9 +- lang/cem/libcc.ansi/string/strcspn.c | 11 +- lang/cem/libcc.ansi/string/strdup.c | 7 +- lang/cem/libcc.ansi/string/strerror.c | 11 +- lang/cem/libcc.ansi/string/strlen.c | 8 +- lang/cem/libcc.ansi/string/strncat.c | 22 +- lang/cem/libcc.ansi/string/strncmp.c | 22 +- lang/cem/libcc.ansi/string/strncpy.c | 22 +- lang/cem/libcc.ansi/string/strpbrk.c | 16 +- lang/cem/libcc.ansi/string/strrchr.c | 14 +- lang/cem/libcc.ansi/string/strspn.c | 9 +- lang/cem/libcc.ansi/string/strstr.c | 12 +- lang/cem/libcc.ansi/string/strtok.c | 18 +- lang/cem/libcc.ansi/string/strxfrm.c | 15 +- lang/cem/libcc.ansi/time/asctime.c | 39 +- lang/cem/libcc.ansi/time/clock.c | 73 +-- lang/cem/libcc.ansi/time/ctime.c | 5 +- lang/cem/libcc.ansi/time/difftime.c | 11 +- lang/cem/libcc.ansi/time/gmtime.c | 20 +- lang/cem/libcc.ansi/time/localtime.c | 15 +- lang/cem/libcc.ansi/time/misc.c | 492 +++++++++-------- lang/cem/libcc.ansi/time/mktime.c | 82 +-- lang/cem/libcc.ansi/time/strftime.c | 265 ++++----- lang/cem/libcc.ansi/time/time.c | 5 +- lang/cem/libcc.ansi/time/tzset.c | 9 +- 157 files changed, 3836 insertions(+), 3121 deletions(-) diff --git a/lang/cem/libcc.ansi/assert/assert.c b/lang/cem/libcc.ansi/assert/assert.c index ac143b51c..be1df2037 100644 --- a/lang/cem/libcc.ansi/assert/assert.c +++ b/lang/cem/libcc.ansi/assert/assert.c @@ -3,11 +3,12 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include -void __bad_assertion(const char *mess) { +void __bad_assertion(const char* mess) +{ fputs(mess, stderr); abort(); diff --git a/lang/cem/libcc.ansi/ctype/tolower.c b/lang/cem/libcc.ansi/ctype/tolower.c index ff95ae0d8..0d5ece39d 100644 --- a/lang/cem/libcc.ansi/ctype/tolower.c +++ b/lang/cem/libcc.ansi/ctype/tolower.c @@ -1,5 +1,6 @@ -#include +#include -int tolower(int c) { - return isupper(c) ? c - 'A' + 'a' : c ; +int tolower(int c) +{ + return isupper(c) ? c - 'A' + 'a' : c; } diff --git a/lang/cem/libcc.ansi/ctype/toupper.c b/lang/cem/libcc.ansi/ctype/toupper.c index 521ae5569..8b77933c5 100644 --- a/lang/cem/libcc.ansi/ctype/toupper.c +++ b/lang/cem/libcc.ansi/ctype/toupper.c @@ -1,5 +1,6 @@ -#include +#include -int toupper(int c) { - return islower(c) ? c - 'a' + 'A' : c ; +int toupper(int c) +{ + return islower(c) ? c - 'a' + 'A' : c; } diff --git a/lang/cem/libcc.ansi/errno/errlist.c b/lang/cem/libcc.ansi/errno/errlist.c index 4d45c447b..1177777b1 100644 --- a/lang/cem/libcc.ansi/errno/errlist.c +++ b/lang/cem/libcc.ansi/errno/errlist.c @@ -4,44 +4,44 @@ */ /* $Id$ */ -#include +#include -const char *_sys_errlist[] = { - "Error 0", - "Not owner", - "No such file or directory", - "No such process", - "Interrupted system call", - "I/O error", - "No such device or address", - "Arg list too long", - "Exec format error", - "Bad file number", - "No children", - "No more processes", - "Not enough core", - "Permission denied", - "Bad address", - "Block device required", - "Mount device busy", - "File exists", - "Cross-device link", - "No such device", - "Not a directory", - "Is a directory", - "Invalid argument", - "File table overflow", - "Too many open files", - "Not a typewriter", - "Text file busy", - "File too large", - "No space left on device", - "Illegal seek", - "Read-only file system", - "Too many links", - "Broken pipe", - "Math argument", - "Result too large" +const char* _sys_errlist[] = { + "Error 0", + "Not owner", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Arg list too long", + "Exec format error", + "Bad file number", + "No children", + "No more processes", + "Not enough core", + "Permission denied", + "Bad address", + "Block device required", + "Mount device busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument", + "Result too large" }; const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]); diff --git a/lang/cem/libcc.ansi/locale/localeconv.c b/lang/cem/libcc.ansi/locale/localeconv.c index 766a4b87c..16da65cd6 100644 --- a/lang/cem/libcc.ansi/locale/localeconv.c +++ b/lang/cem/libcc.ansi/locale/localeconv.c @@ -3,15 +3,15 @@ */ /* $Id$ */ -#include -#include +#include +#include extern struct lconv _lc; -struct lconv * +struct lconv* localeconv(void) { - register struct lconv *lcp = &_lc; + register struct lconv* lcp = &_lc; lcp->decimal_point = "."; lcp->thousands_sep = ""; diff --git a/lang/cem/libcc.ansi/locale/setlocale.c b/lang/cem/libcc.ansi/locale/setlocale.c index 9b61ed58e..76780c444 100644 --- a/lang/cem/libcc.ansi/locale/setlocale.c +++ b/lang/cem/libcc.ansi/locale/setlocale.c @@ -3,26 +3,28 @@ */ /* $Id$ */ -#include -#include +#include +#include struct lconv _lc; -char * -setlocale(int category, const char *locale) +char* setlocale(int category, const char* locale) { - if (!locale) return "C"; - if (*locale && strcmp(locale, "C")) return (char *)NULL; - - switch(category) { - case LC_ALL: - case LC_CTYPE: - case LC_COLLATE: - case LC_TIME: - case LC_NUMERIC: - case LC_MONETARY: - return *locale ? (char *)locale : "C"; - default: - return (char *)NULL; + if (!locale) + return "C"; + if (*locale && strcmp(locale, "C")) + return (char*)NULL; + + switch (category) + { + case LC_ALL: + case LC_CTYPE: + case LC_COLLATE: + case LC_TIME: + case LC_NUMERIC: + case LC_MONETARY: + return *locale ? (char*)locale : "C"; + default: + return (char*)NULL; } } diff --git a/lang/cem/libcc.ansi/malloc/calloc.c b/lang/cem/libcc.ansi/malloc/calloc.c index 2e9d3be16..814841fd5 100644 --- a/lang/cem/libcc.ansi/malloc/calloc.c +++ b/lang/cem/libcc.ansi/malloc/calloc.c @@ -4,20 +4,20 @@ void* calloc(size_t nmemb, size_t size) { - size_t bytes = nmemb * size; - void* ptr; - - /* Test for overflow. + size_t bytes = nmemb * size; + void* ptr; + + /* Test for overflow. * See http://stackoverflow.com/questions/1815367/multiplication-of-large-numbers-how-to-catch-overflow */ - if ((nmemb == 0) || (size == 0) || (nmemb > (SIZE_MAX / size))) - return NULL; - - ptr = malloc(bytes); - if (!ptr) - return NULL; + if ((nmemb == 0) || (size == 0) || (nmemb > (SIZE_MAX / size))) + return NULL; - memset(ptr, 0, bytes); - return ptr; + ptr = malloc(bytes); + if (!ptr) + return NULL; + + memset(ptr, 0, bytes); + return ptr; } diff --git a/lang/cem/libcc.ansi/malloc/malloc.c b/lang/cem/libcc.ansi/malloc/malloc.c index 7eaaacaba..71f3c80b2 100644 --- a/lang/cem/libcc.ansi/malloc/malloc.c +++ b/lang/cem/libcc.ansi/malloc/malloc.c @@ -3,7 +3,7 @@ #include #include "malloc.h" -block_t __mem_root = {&__mem_root, 0}; +block_t __mem_root = { &__mem_root, 0 }; block_t* __mem_freelist = &__mem_root; /* Pulls more memory from the system. */ @@ -57,7 +57,7 @@ void* malloc(size_t size) * The size field is already set. */ prev->next = p->next; __mem_freelist = prev; - return (void*) (p+1); + return (void*)(p + 1); } else if (p->size > nblocks) { @@ -67,7 +67,7 @@ void* malloc(size_t size) p += p->size; /* p now points at our new block */ p->size = nblocks; __mem_freelist = prev; - return (void*) (p+1); + return (void*)(p + 1); } if (p == __mem_freelist) @@ -84,7 +84,7 @@ void* malloc(size_t size) } } -void free(void *ptr) +void free(void* ptr) { block_t* h = BLOCKOF(ptr); block_t* p; @@ -118,7 +118,7 @@ void free(void *ptr) p = p->next; } - + /* If we can, merge the next block onto the end of h. */ if ((h + h->size) == p->next) @@ -148,4 +148,3 @@ void free(void *ptr) /* ...and update the ring pointer. */ __mem_freelist = p; } - diff --git a/lang/cem/libcc.ansi/malloc/realloc.c b/lang/cem/libcc.ansi/malloc/realloc.c index 7e6dfbb70..c941d8091 100644 --- a/lang/cem/libcc.ansi/malloc/realloc.c +++ b/lang/cem/libcc.ansi/malloc/realloc.c @@ -4,7 +4,7 @@ #include #include "malloc.h" -void* realloc(void *ptr, size_t size) +void* realloc(void* ptr, size_t size) { block_t* h; size_t nblocks; @@ -25,7 +25,7 @@ void* realloc(void *ptr, size_t size) /* Overflow check. */ if (nblocks < size) return NULL; - + /* Shrinking the block? Don't bother doing anything (it's never worth it). */ if (nblocks <= h->size) return ptr; diff --git a/lang/cem/libcc.ansi/math/asin.c b/lang/cem/libcc.ansi/math/asin.c index 2a7ddd7c7..1e3180086 100644 --- a/lang/cem/libcc.ansi/math/asin.c +++ b/lang/cem/libcc.ansi/math/asin.c @@ -6,66 +6,76 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include "localmath.h" static double asin_acos(double x, int cosfl) { int negative = x < 0; - int i; - double g; + int i; + double g; static double p[] = { -0.27368494524164255994e+2, - 0.57208227877891731407e+2, + 0.57208227877891731407e+2, -0.39688862997540877339e+2, - 0.10152522233806463645e+2, + 0.10152522233806463645e+2, -0.69674573447350646411e+0 }; static double q[] = { -0.16421096714498560795e+3, - 0.41714430248260412556e+3, + 0.41714430248260412556e+3, -0.38186303361750149284e+3, - 0.15095270841030604719e+3, + 0.15095270841030604719e+3, -0.23823859153670238830e+2, - 1.0 + 1.0 }; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (negative) { + if (negative) + { x = -x; } - if (x > 0.5) { + if (x > 0.5) + { i = 1; - if (x > 1) { + if (x > 1) + { errno = EDOM; return 0; } g = 0.5 - 0.5 * x; - x = - sqrt(g); + x = -sqrt(g); x += x; } - else { + else + { /* ??? avoid underflow ??? */ i = 0; g = x * x; } x += x * g * POLYNOM4(g, p) / POLYNOM5(g, q); - if (cosfl) { - if (! negative) x = -x; + if (cosfl) + { + if (!negative) + x = -x; } - if ((cosfl == 0) == (i == 1)) { + if ((cosfl == 0) == (i == 1)) + { x = (x + M_PI_4) + M_PI_4; } - else if (cosfl && negative && i == 1) { + else if (cosfl && negative && i == 1) + { x = (x + M_PI_2) + M_PI_2; } - if (! cosfl && negative) x = -x; + if (!cosfl && negative) + x = -x; return x; } diff --git a/lang/cem/libcc.ansi/math/atan.c b/lang/cem/libcc.ansi/math/atan.c index 055d0fdba..eb04d095f 100644 --- a/lang/cem/libcc.ansi/math/atan.c +++ b/lang/cem/libcc.ansi/math/atan.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" double atan(double x) @@ -26,47 +26,52 @@ atan(double x) -0.83758299368150059274e+0 }; static double q[] = { - 0.41066306682575781263e+2, - 0.86157349597130242515e+2, - 0.59578436142597344465e+2, - 0.15024001160028576121e+2, - 1.0 + 0.41066306682575781263e+2, + 0.86157349597130242515e+2, + 0.59578436142597344465e+2, + 0.15024001160028576121e+2, + 1.0 }; static double a[] = { 0.0, - 0.52359877559829887307710723554658381, /* pi/6 */ + 0.52359877559829887307710723554658381, /* pi/6 */ M_PI_2, - 1.04719755119659774615421446109316763 /* pi/3 */ + 1.04719755119659774615421446109316763 /* pi/3 */ }; - int neg = x < 0; - int n; - double g; + int neg = x < 0; + int n; + double g; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (neg) { + if (neg) + { x = -x; } - if (x > 1.0) { - x = 1.0/x; + if (x > 1.0) + { + x = 1.0 / x; n = 2; } - else n = 0; + else + n = 0; - if (x > 0.26794919243112270647) { /* 2-sqtr(3) */ + if (x > 0.26794919243112270647) + { /* 2-sqtr(3) */ n = n + 1; - x = (((0.73205080756887729353*x-0.5)-0.5)+x)/ - (1.73205080756887729353+x); + x = (((0.73205080756887729353 * x - 0.5) - 0.5) + x) / (1.73205080756887729353 + x); } /* ??? avoid underflow ??? */ g = x * x; x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q); - if (n > 1) x = -x; + if (n > 1) + x = -x; x += a[n]; return neg ? -x : x; } diff --git a/lang/cem/libcc.ansi/math/atan2.c b/lang/cem/libcc.ansi/math/atan2.c index b822f989a..6f8362468 100644 --- a/lang/cem/libcc.ansi/math/atan2.c +++ b/lang/cem/libcc.ansi/math/atan2.c @@ -6,35 +6,41 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include "localmath.h" double atan2(double y, double x) { double absx, absy, val; - if (x == 0 && y == 0) { + if (x == 0 && y == 0) + { errno = EDOM; return 0; } absy = y < 0 ? -y : y; absx = x < 0 ? -x : x; - if (absy - absx == absy) { + if (absy - absx == absy) + { /* x negligible compared to y */ return y < 0 ? -M_PI_2 : M_PI_2; } - if (absx - absy == absx) { + if (absx - absy == absx) + { /* y negligible compared to x */ val = 0.0; } - else val = atan(y/x); - if (x > 0) { + else + val = atan(y / x); + if (x > 0) + { /* first or fourth quadrant; already correct */ return val; } - if (y < 0) { + if (y < 0) + { /* third quadrant */ return val - M_PI; } diff --git a/lang/cem/libcc.ansi/math/ceil.c b/lang/cem/libcc.ansi/math/ceil.c index eab485e2e..2d06949a2 100644 --- a/lang/cem/libcc.ansi/math/ceil.c +++ b/lang/cem/libcc.ansi/math/ceil.c @@ -6,14 +6,14 @@ */ /* $Id$ */ -#include +#include double ceil(double x) { double val; - return modf(x, &val) > 0 ? val + 1.0 : val ; + return modf(x, &val) > 0 ? val + 1.0 : val; /* this also works if modf always returns a positive fractional part */ diff --git a/lang/cem/libcc.ansi/math/exp.c b/lang/cem/libcc.ansi/math/exp.c index 95014d6bc..1583d913c 100644 --- a/lang/cem/libcc.ansi/math/exp.c +++ b/lang/cem/libcc.ansi/math/exp.c @@ -6,11 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" - +#include +#include +#include +#include "localmath.h" double exp(double x) @@ -32,41 +31,46 @@ exp(double x) 0.63121894374398503557e-3, 0.75104028399870046114e-6 }; - double xn, g; - int n; - int negative = x < 0; + double xn, g; + int n; + int negative = x < 0; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (x < M_LN_MIN_D) { + if (x < M_LN_MIN_D) + { errno = ERANGE; return 0.0; } - if (x > M_LN_MAX_D) { + if (x > M_LN_MAX_D) + { errno = ERANGE; return HUGE_VAL; } - if (negative) x = -x; - + if (negative) + x = -x; + /* ??? avoid underflow ??? */ - n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */ + n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */ xn = n; { - double x1 = (long) x; - double x2 = x - x1; + double x1 = (long)x; + double x2 = x - x1; - g = ((x1-xn*0.693359375)+x2) - xn*(-2.1219444005469058277e-4); + g = ((x1 - xn * 0.693359375) + x2) - xn * (-2.1219444005469058277e-4); } - if (negative) { + if (negative) + { g = -g; n = -n; } xn = g * g; x = g * POLYNOM2(xn, p); n += 1; - return (ldexp(0.5 + x/(POLYNOM3(xn, q) - x), n)); + return (ldexp(0.5 + x / (POLYNOM3(xn, q) - x), n)); } diff --git a/lang/cem/libcc.ansi/math/fabs.c b/lang/cem/libcc.ansi/math/fabs.c index e7a533de5..526d5d63e 100644 --- a/lang/cem/libcc.ansi/math/fabs.c +++ b/lang/cem/libcc.ansi/math/fabs.c @@ -9,5 +9,5 @@ double fabs(double x) { - return x < 0 ? -x : x; + return x < 0 ? -x : x; } diff --git a/lang/cem/libcc.ansi/math/floor.c b/lang/cem/libcc.ansi/math/floor.c index 0be49ca42..4f1cd2dc0 100644 --- a/lang/cem/libcc.ansi/math/floor.c +++ b/lang/cem/libcc.ansi/math/floor.c @@ -6,14 +6,14 @@ */ /* $Id$ */ -#include +#include double floor(double x) { double val; - return modf(x, &val) < 0 ? val - 1.0 : val ; + return modf(x, &val) < 0 ? val - 1.0 : val; /* this also works if modf always returns a positive fractional part */ diff --git a/lang/cem/libcc.ansi/math/fmod.c b/lang/cem/libcc.ansi/math/fmod.c index ae0783e6b..4a784a98f 100644 --- a/lang/cem/libcc.ansi/math/fmod.c +++ b/lang/cem/libcc.ansi/math/fmod.c @@ -6,29 +6,34 @@ #include #include -double -(fmod)(double x, double y) -{ /* compute fmod(x, y) */ +double(fmod)(double x, double y) +{ /* compute fmod(x, y) */ double t; int n, neg; int ychar, xchar; - if (y == 0.0) { + if (y == 0.0) + { errno = EDOM; return 0.0; - } - /* fmod(finite, finite) */ - if (y < 0.0) y = -y; - if (x < 0.0) x = -x, neg = 1; - else neg = 0; + } + /* fmod(finite, finite) */ + if (y < 0.0) + y = -y; + if (x < 0.0) + x = -x, neg = 1; + else + neg = 0; t = frexp(y, &ychar); - /* substract |y| until |x| < |y| */ + /* substract |y| until |x| < |y| */ t = frexp(x, &xchar); - for (n = xchar - ychar; 0 <= n; --n) { - /* try to substract |y|*2^n */ - t = ldexp(y, n); - if (t <= x) x -= t; + for (n = xchar - ychar; 0 <= n; --n) + { + /* try to substract |y|*2^n */ + t = ldexp(y, n); + if (t <= x) + x -= t; } return (neg ? -x : x); } diff --git a/lang/cem/libcc.ansi/math/hypot.c b/lang/cem/libcc.ansi/math/hypot.c index 612a4bde1..ad181d157 100644 --- a/lang/cem/libcc.ansi/math/hypot.c +++ b/lang/cem/libcc.ansi/math/hypot.c @@ -10,25 +10,30 @@ /* $Id$ */ double -hypot(double x,double y) +hypot(double x, double y) { /* Computes sqrt(x*x+y*y), avoiding overflow */ - if (x < 0) x = -x; - if (y < 0) y = -y; - if (x > y) { + if (x < 0) + x = -x; + if (y < 0) + y = -y; + if (x > y) + { double t = y; y = x; x = t; } /* sqrt(x*x+y*y) = sqrt(y*y*(x*x/(y*y)+1.0)) = y*sqrt(x*x/(y*y)+1.0) */ - if (y == 0.0) return 0.0; + if (y == 0.0) + return 0.0; x /= y; - return y*sqrt(x*x+1.0); + return y * sqrt(x * x + 1.0); } -struct complex { - double r,i; +struct complex +{ + double r, i; }; double diff --git a/lang/cem/libcc.ansi/math/isnan.c b/lang/cem/libcc.ansi/math/isnan.c index b64c6d905..7f1b31aed 100644 --- a/lang/cem/libcc.ansi/math/isnan.c +++ b/lang/cem/libcc.ansi/math/isnan.c @@ -4,8 +4,8 @@ __IsNan(double d) #else float f = d; - if ((*((long *) &f) & 0x7f800000) == 0x7f800000 && - (*((long *) &f) & 0x007fffff) != 0) return 1; + if ((*((long*)&f) & 0x7f800000) == 0x7f800000 && (*((long*)&f) & 0x007fffff) != 0) + return 1; #endif return 0; } diff --git a/lang/cem/libcc.ansi/math/ldexp.c b/lang/cem/libcc.ansi/math/ldexp.c index eb7e3d9ee..7f1b0ee19 100644 --- a/lang/cem/libcc.ansi/math/ldexp.c +++ b/lang/cem/libcc.ansi/math/ldexp.c @@ -4,9 +4,9 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include double ldexp(double fl, int exp) @@ -14,42 +14,52 @@ ldexp(double fl, int exp) int sign = 1; int currexp; - if (__IsNan(fl)) { + if (__IsNan(fl)) + { errno = EDOM; return fl; } - if (fl == 0.0) return 0.0; - if (fl<0) { + if (fl == 0.0) + return 0.0; + if (fl < 0) + { fl = -fl; sign = -1; } - if (fl > DBL_MAX) { /* for infinity */ + if (fl > DBL_MAX) + { /* for infinity */ errno = ERANGE; return sign * fl; } - fl = frexp(fl,&currexp); + fl = frexp(fl, &currexp); exp += currexp; - if (exp > 0) { - if (exp > DBL_MAX_EXP) { + if (exp > 0) + { + if (exp > DBL_MAX_EXP) + { errno = ERANGE; return sign * HUGE_VAL; } - while (exp>30) { - fl *= (double) (1L << 30); + while (exp > 30) + { + fl *= (double)(1L << 30); exp -= 30; } - fl *= (double) (1L << exp); + fl *= (double)(1L << exp); } - else { + else + { /* number need not be normalized */ - if (exp < DBL_MIN_EXP - DBL_MANT_DIG) { + if (exp < DBL_MIN_EXP - DBL_MANT_DIG) + { return 0.0; } - while (exp<-30) { - fl /= (double) (1L << 30); + while (exp < -30) + { + fl /= (double)(1L << 30); exp += 30; } - fl /= (double) (1L << -exp); + fl /= (double)(1L << -exp); } return sign * fl; } diff --git a/lang/cem/libcc.ansi/math/log.c b/lang/cem/libcc.ansi/math/log.c index c1ec51f95..3be9c87c7 100644 --- a/lang/cem/libcc.ansi/math/log.c +++ b/lang/cem/libcc.ansi/math/log.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" double log(double x) @@ -20,47 +20,55 @@ log(double x) */ static double a[] = { -0.64124943423745581147e2, - 0.16383943563021534222e2, + 0.16383943563021534222e2, -0.78956112887491257267e0 }; static double b[] = { -0.76949932108494879777e3, - 0.31203222091924532844e3, + 0.31203222091924532844e3, -0.35667977739034646171e2, - 1.0 + 1.0 }; - double znum, zden, z, w; - int exponent; + double znum, zden, z, w; + int exponent; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (x < 0) { + if (x < 0) + { errno = EDOM; return -HUGE_VAL; } - else if (x == 0) { + else if (x == 0) + { errno = ERANGE; return -HUGE_VAL; } - if (x <= DBL_MAX) { + if (x <= DBL_MAX) + { } - else return x; /* for infinity and Nan */ + else + return x; /* for infinity and Nan */ x = frexp(x, &exponent); - if (x > M_1_SQRT2) { + if (x > M_1_SQRT2) + { znum = (x - 0.5) - 0.5; zden = x * 0.5 + 0.5; } - else { + else + { znum = x - 0.5; zden = znum * 0.5 + 0.5; exponent--; } - z = znum/zden; w = z * z; - x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b)); + z = znum / zden; + w = z * z; + x = z + z * w * (POLYNOM2(w, a) / POLYNOM3(w, b)); z = exponent; x += z * (-2.121944400546905827679e-4); return x + z * 0.693359375; diff --git a/lang/cem/libcc.ansi/math/log10.c b/lang/cem/libcc.ansi/math/log10.c index b759c8478..9eb270ec2 100644 --- a/lang/cem/libcc.ansi/math/log10.c +++ b/lang/cem/libcc.ansi/math/log10.c @@ -6,22 +6,25 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include "localmath.h" double log10(double x) { - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (x < 0) { + if (x < 0) + { errno = EDOM; return -HUGE_VAL; } - else if (x == 0) { + else if (x == 0) + { errno = ERANGE; return -HUGE_VAL; } diff --git a/lang/cem/libcc.ansi/math/pow.c b/lang/cem/libcc.ansi/math/pow.c index 639dc07e5..0e6d6c99b 100644 --- a/lang/cem/libcc.ansi/math/pow.c +++ b/lang/cem/libcc.ansi/math/pow.c @@ -6,94 +6,116 @@ */ /* $Id$ */ -#include -#include -#include -#include +#include +#include +#include +#include double pow(double x, double y) { - double y_intpart, y_fractpart, fp; - int negexp, negx; - int ex, newexp; + double y_intpart, y_fractpart, fp; + int negexp, negx; + int ex, newexp; unsigned long yi; - if (x == 1.0) return x; + if (x == 1.0) + return x; - if (x == 0 && y <= 0) { + if (x == 0 && y <= 0) + { errno = EDOM; return 0; } - if (y == 0) return 1.0; + if (y == 0) + return 1.0; - if (y < 0) { + if (y < 0) + { y = -y; negexp = 1; } - else negexp = 0; + else + negexp = 0; y_fractpart = modf(y, &y_intpart); - if (y_fractpart != 0) { - if (x < 0) { + if (y_fractpart != 0) + { + if (x < 0) + { errno = EDOM; return 0; } } negx = 0; - if (x < 0) { + if (x < 0) + { x = -x; negx = 1; } - if (y_intpart > ULONG_MAX) { - if (negx && modf(y_intpart/2.0, &y_fractpart) == 0) { + if (y_intpart > ULONG_MAX) + { + if (negx && modf(y_intpart / 2.0, &y_fractpart) == 0) + { negx = 0; } x = log(x); /* Beware of overflow in the multiplication */ - if (x > 1.0 && y > DBL_MAX/x) { + if (x > 1.0 && y > DBL_MAX / x) + { errno = ERANGE; return HUGE_VAL; } - if (negexp) y = -y; + if (negexp) + y = -y; - if (negx) return -exp(x*y); + if (negx) + return -exp(x * y); return exp(x * y); } - if (y_fractpart != 0) { + if (y_fractpart != 0) + { fp = exp(y_fractpart * log(x)); } - else fp = 1.0; + else + fp = 1.0; yi = y_intpart; - if (! (yi & 1)) negx = 0; + if (!(yi & 1)) + negx = 0; x = frexp(x, &ex); newexp = 0; - for (;;) { - if (yi & 1) { + for (;;) + { + if (yi & 1) + { fp *= x; newexp += ex; } yi >>= 1; - if (yi == 0) break; + if (yi == 0) + break; x *= x; ex <<= 1; - if (x < 0.5) { + if (x < 0.5) + { x += x; ex -= 1; } } - if (negexp) { - fp = 1.0/fp; + if (negexp) + { + fp = 1.0 / fp; newexp = -newexp; } - if (negx) { + if (negx) + { return -ldexp(fp, newexp); } return ldexp(fp, newexp); diff --git a/lang/cem/libcc.ansi/math/sin.c b/lang/cem/libcc.ansi/math/sin.c index 9c4591d5a..a55fa93d0 100644 --- a/lang/cem/libcc.ansi/math/sin.c +++ b/lang/cem/libcc.ansi/math/sin.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" static double sinus(double x, int cos_flag) @@ -21,39 +21,44 @@ sinus(double x, int cos_flag) static double r[] = { -0.16666666666666665052e+0, - 0.83333333333331650314e-2, + 0.83333333333331650314e-2, -0.19841269841201840457e-3, - 0.27557319210152756119e-5, + 0.27557319210152756119e-5, -0.25052106798274584544e-7, - 0.16058936490371589114e-9, + 0.16058936490371589114e-9, -0.76429178068910467734e-12, - 0.27204790957888846175e-14 + 0.27204790957888846175e-14 }; - double y; - int neg = 1; + double y; + int neg = 1; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (x < 0) { + if (x < 0) + { x = -x; neg = -1; } - if (cos_flag) { + if (cos_flag) + { neg = 1; y = M_PI_2 + x; } - else y = x; + else + y = x; /* ??? avoid loss of significance, if y is too large, error ??? */ y = y * M_1_PI + 0.5; - if (y >= DBL_MAX/M_PI) return 0.0; + if (y >= DBL_MAX / M_PI) + return 0.0; - /* Use extended precision to calculate reduced argument. +/* Use extended precision to calculate reduced argument. Here we used 12 bits of the mantissa for a1. Also split x in integer part x1 and fraction part x2. */ @@ -63,8 +68,10 @@ sinus(double x, int cos_flag) double x1, x2; modf(y, &y); - if (modf(0.5*y, &x1)) neg = -neg; - if (cos_flag) y -= 0.5; + if (modf(0.5 * y, &x1)) + neg = -neg; + if (cos_flag) + y -= 0.5; x2 = modf(x, &x1); x = x1 - y * A1; x += x2; @@ -72,8 +79,9 @@ sinus(double x, int cos_flag) #undef A1 #undef A2 } - - if (x < 0) { + + if (x < 0) + { neg = -neg; x = -x; } @@ -82,7 +90,7 @@ sinus(double x, int cos_flag) y = x * x; x += x * y * POLYNOM7(y, r); - return neg==-1 ? -x : x; + return neg == -1 ? -x : x; } double @@ -94,6 +102,7 @@ sin(double x) double cos(double x) { - if (x < 0) x = -x; + if (x < 0) + x = -x; return sinus(x, 1); } diff --git a/lang/cem/libcc.ansi/math/sinh.c b/lang/cem/libcc.ansi/math/sinh.c index bce95441d..00ad3fc36 100644 --- a/lang/cem/libcc.ansi/math/sinh.c +++ b/lang/cem/libcc.ansi/math/sinh.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" static double sinh_cosh(double x, int cosh_flag) @@ -27,42 +27,48 @@ sinh_cosh(double x, int cosh_flag) }; static double q[] = { -0.21108770058106271242e+7, - 0.36162723109421836460e+5, + 0.36162723109421836460e+5, -0.27773523119650701167e+3, - 1.0 + 1.0 }; - int negative = x < 0; - double y = negative ? -x : x; + int negative = x < 0; + double y = negative ? -x : x; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (! cosh_flag && y <= 1.0) { + if (!cosh_flag && y <= 1.0) + { /* ??? check for underflow ??? */ y = y * y; - return x + x * y * POLYNOM3(y, p)/POLYNOM3(y,q); + return x + x * y * POLYNOM3(y, p) / POLYNOM3(y, q); } - if (y >= M_LN_MAX_D) { - /* exp(y) would cause overflow */ -#define LNV 0.69316101074218750000e+0 -#define VD2M1 0.52820835025874852469e-4 - double w = y - LNV; - - if (w < M_LN_MAX_D+M_LN2-LNV) { + if (y >= M_LN_MAX_D) + { +/* exp(y) would cause overflow */ +#define LNV 0.69316101074218750000e+0 +#define VD2M1 0.52820835025874852469e-4 + double w = y - LNV; + + if (w < M_LN_MAX_D + M_LN2 - LNV) + { x = exp(w); x += VD2M1 * x; } - else { + else + { errno = ERANGE; x = HUGE_VAL; } } - else { - double z = exp(y); - - x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0)/z); + else + { + double z = exp(y); + + x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0) / z); } return negative ? -x : x; } @@ -76,6 +82,7 @@ sinh(double x) double cosh(double x) { - if (x < 0) x = -x; + if (x < 0) + x = -x; return sinh_cosh(x, 1); } diff --git a/lang/cem/libcc.ansi/math/sqrt.c b/lang/cem/libcc.ansi/math/sqrt.c index 172f35059..17cfcdc0e 100644 --- a/lang/cem/libcc.ansi/math/sqrt.c +++ b/lang/cem/libcc.ansi/math/sqrt.c @@ -6,11 +6,11 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include -#define NITER 5 +#define NITER 5 double sqrt(double x) @@ -18,25 +18,31 @@ sqrt(double x) int exponent; double val; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (x <= 0) { - if (x < 0) errno = EDOM; + if (x <= 0) + { + if (x < 0) + errno = EDOM; return 0; } - if (x > DBL_MAX) return x; /* for infinity */ + if (x > DBL_MAX) + return x; /* for infinity */ val = frexp(x, &exponent); - if (exponent & 1) { + if (exponent & 1) + { exponent--; val *= 2; } - val = ldexp(val + 1.0, exponent/2 - 1); + val = ldexp(val + 1.0, exponent / 2 - 1); /* was: val = (val + 1.0)/2.0; val = ldexp(val, exponent/2); */ - for (exponent = NITER - 1; exponent >= 0; exponent--) { + for (exponent = NITER - 1; exponent >= 0; exponent--) + { val = (val + x / val) / 2.0; } return val; diff --git a/lang/cem/libcc.ansi/math/tan.c b/lang/cem/libcc.ansi/math/tan.c index 159071d87..0d7a32589 100644 --- a/lang/cem/libcc.ansi/math/tan.c +++ b/lang/cem/libcc.ansi/math/tan.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" double tan(double x) @@ -21,56 +21,61 @@ tan(double x) int negative = x < 0; int invert = 0; - double y; - static double p[] = { - 1.0, + double y; + static double p[] = { + 1.0, -0.13338350006421960681e+0, - 0.34248878235890589960e-2, + 0.34248878235890589960e-2, -0.17861707342254426711e-4 }; - static double q[] = { - 1.0, + static double q[] = { + 1.0, -0.46671683339755294240e+0, - 0.25663832289440112864e-1, + 0.25663832289440112864e-1, -0.31181531907010027307e-3, - 0.49819433993786512270e-6 + 0.49819433993786512270e-6 }; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (negative) x = -x; - + if (negative) + x = -x; + /* ??? avoid loss of significance, error if x is too large ??? */ y = x * M_2_PI + 0.5; - if (y >= DBL_MAX/M_PI_2) return 0.0; + if (y >= DBL_MAX / M_PI_2) + return 0.0; - /* Use extended precision to calculate reduced argument. +/* Use extended precision to calculate reduced argument. Here we used 12 bits of the mantissa for a1. Also split x in integer part x1 and fraction part x2. */ - #define A1 1.57080078125 - #define A2 -4.454455103380768678308e-6 +#define A1 1.57080078125 +#define A2 -4.454455103380768678308e-6 { double x1, x2; modf(y, &y); - if (modf(0.5*y, &x1)) invert = 1; + if (modf(0.5 * y, &x1)) + invert = 1; x2 = modf(x, &x1); x = x1 - y * A1; x += x2; x -= y * A2; - #undef A1 - #undef A2 +#undef A1 +#undef A2 } /* ??? avoid underflow ??? */ y = x * x; - x += x * y * POLYNOM2(y, p+1); + x += x * y * POLYNOM2(y, p + 1); y = POLYNOM4(y, q); - if (negative) x = -x; - return invert ? -y/x : x/y; + if (negative) + x = -x; + return invert ? -y / x : x / y; } diff --git a/lang/cem/libcc.ansi/math/tanh.c b/lang/cem/libcc.ansi/math/tanh.c index 0e351029b..1bf90dd9b 100644 --- a/lang/cem/libcc.ansi/math/tanh.c +++ b/lang/cem/libcc.ansi/math/tanh.c @@ -6,10 +6,10 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" double tanh(double x) @@ -25,31 +25,36 @@ tanh(double x) -0.96437492777225469787e+0 }; static double q[] = { - 0.48402357071988688686e+4, - 0.22337720718962312926e+4, - 0.11274474380534949335e+3, - 1.0 + 0.48402357071988688686e+4, + 0.22337720718962312926e+4, + 0.11274474380534949335e+3, + 1.0 }; - int negative = x < 0; + int negative = x < 0; - if (__IsNan(x)) { + if (__IsNan(x)) + { errno = EDOM; return x; } - if (negative) x = -x; + if (negative) + x = -x; - if (x >= 0.5*M_LN_MAX_D) { + if (x >= 0.5 * M_LN_MAX_D) + { x = 1.0; } -#define LN3D2 0.54930614433405484570e+0 /* ln(3)/2 */ - else if (x > LN3D2) { - x = 0.5 - 1.0/(exp(x+x)+1.0); +#define LN3D2 0.54930614433405484570e+0 /* ln(3)/2 */ + else if (x > LN3D2) + { + x = 0.5 - 1.0 / (exp(x + x) + 1.0); x += x; } - else { + else + { /* ??? avoid underflow ??? */ - double g = x*x; - x += x * g * POLYNOM2(g, p)/POLYNOM3(g, q); + double g = x * x; + x += x * g * POLYNOM2(g, p) / POLYNOM3(g, q); } return negative ? -x : x; } diff --git a/lang/cem/libcc.ansi/misc/closedir.c b/lang/cem/libcc.ansi/misc/closedir.c index 826026f13..12f7c825a 100644 --- a/lang/cem/libcc.ansi/misc/closedir.c +++ b/lang/cem/libcc.ansi/misc/closedir.c @@ -4,33 +4,32 @@ last edit: 11-Nov-1988 D A Gwyn */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -typedef void *pointer; /* (void *) if you have it */ +typedef void* pointer; /* (void *) if you have it */ #ifndef NULL -#define NULL 0 +#define NULL 0 #endif int _close(int d); -int -closedir(register DIR *dirp) /* stream from opendir */ +int closedir(register DIR* dirp) /* stream from opendir */ { - register int fd; + register int fd; - if ( dirp == NULL || dirp->dd_buf == NULL ) - { + if (dirp == NULL || dirp->dd_buf == NULL) + { errno = EFAULT; - return -1; /* invalid pointer */ - } + return -1; /* invalid pointer */ + } - fd = dirp->dd_fd; /* bug fix thanks to R. Salz */ - free( (pointer)dirp->dd_buf ); - free( (pointer)dirp ); - return _close( fd ); + fd = dirp->dd_fd; /* bug fix thanks to R. Salz */ + free((pointer)dirp->dd_buf); + free((pointer)dirp); + return _close(fd); } diff --git a/lang/cem/libcc.ansi/misc/getdents.c b/lang/cem/libcc.ansi/misc/getdents.c index e9d34c19a..c6d40723c 100644 --- a/lang/cem/libcc.ansi/misc/getdents.c +++ b/lang/cem/libcc.ansi/misc/getdents.c @@ -29,91 +29,92 @@ to always work, you shouldn't be using this source file at all. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #ifdef BSD_SYSV -#include /* BSD flavor, not System V */ +#include /* BSD flavor, not System V */ #else -#if defined(UFS) -#define DIRSIZ 14 /* 14 char filename in Version 7 */ +#if defined(UFS) +#define DIRSIZ 14 /* 14 char filename in Version 7 */ #endif -#define MAXNAMLEN 255 -struct direct { - off_t d_off; /* offset of next disk directory entry */ - u_long d_fileno; /* file number of entry */ - u_short d_reclen; /* length of this record */ - u_short d_namlen; /* length of string in d_name */ - char d_name[MAXNAMLEN + 1]; /* name (up to MAXNAMLEN + 1) */ +#define MAXNAMLEN 255 +struct direct +{ + off_t d_off; /* offset of next disk directory entry */ + u_long d_fileno; /* file number of entry */ + u_short d_reclen; /* length of this record */ + u_short d_namlen; /* length of string in d_name */ + char d_name[MAXNAMLEN + 1]; /* name (up to MAXNAMLEN + 1) */ }; -#undef MAXNAMLEN /* avoid conflict with SVR3 */ +#undef MAXNAMLEN /* avoid conflict with SVR3 */ -#define d_ino d_fileno /* compatability */ +#define d_ino d_fileno /* compatability */ -#ifdef d_ino /* 4.3BSD/NFS using d_fileno */ -#undef d_ino /* (not absolutely necessary) */ +#ifdef d_ino /* 4.3BSD/NFS using d_fileno */ +#undef d_ino /* (not absolutely necessary) */ #else -#define d_fileno d_ino /* (struct direct) member */ +#define d_fileno d_ino /* (struct direct) member */ #endif #endif -#include -#include +#include +#include #ifdef UNK #ifndef UFS -#error UNK applies only to UFS +#error UNK applies only to UFS /* One could do something similar for getdirentries(), but I didn't bother. */ #endif -#include +#include #endif -#if defined(UFS) + defined(BFS) + defined(NFS) != 1 /* sanity check */ -#error exactly one of UFS, BFS, or NFS must be defined +#if defined(UFS) + defined(BFS) + defined(NFS) != 1 /* sanity check */ +#error exactly one of UFS, BFS, or NFS must be defined #endif #ifdef UFS -#define RecLen( dp ) (sizeof(struct direct)) /* fixed-length entries */ -#else /* BFS || NFS */ -#define RecLen( dp ) ((dp)->d_reclen) /* variable-length entries */ +#define RecLen(dp) (sizeof(struct direct)) /* fixed-length entries */ +#else /* BFS || NFS */ +#define RecLen(dp) ((dp)->d_reclen) /* variable-length entries */ #endif #ifdef NFS #ifdef BSD_SYSV -#define getdirentries _getdirentries /* package hides this system call */ +#define getdirentries _getdirentries /* package hides this system call */ #endif -extern int getdirentries(int fd, char *buf, int nbytes, long *basep); -static long dummy; /* getdirentries() needs basep */ -#define GetBlock( fd, buf, n ) getdirentries( fd, buf, (unsigned)n, &dummy ) -#else /* UFS || BFS */ +extern int getdirentries(int fd, char* buf, int nbytes, long* basep); +static long dummy; /* getdirentries() needs basep */ +#define GetBlock(fd, buf, n) getdirentries(fd, buf, (unsigned)n, &dummy) +#else /* UFS || BFS */ #ifdef BSD_SYSV -#define read _read /* avoid emulation overhead */ +#define read _read /* avoid emulation overhead */ #endif -extern int read(); -#define GetBlock( fd, buf, n ) read( fd, buf, (unsigned)n ) +extern int read(); +#define GetBlock(fd, buf, n) read(fd, buf, (unsigned)n) #endif #ifdef UNK -extern int _getdents(); /* actual system call */ +extern int _getdents(); /* actual system call */ #endif -extern int _fstat(int fd, struct stat *buf); -extern off_t _lseek(int d, int offset, int whence); +extern int _fstat(int fd, struct stat* buf); +extern off_t _lseek(int d, int offset, int whence); #ifndef DIRBLKSIZ -#define DIRBLKSIZ 4096 /* directory file read buffer size */ +#define DIRBLKSIZ 4096 /* directory file read buffer size */ #endif #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #ifndef SEEK_CUR -#define SEEK_CUR 1 +#define SEEK_CUR 1 #endif -#ifndef S_ISDIR /* macro to test for directory file */ -#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR) +#ifndef S_ISDIR /* macro to test for directory file */ +#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #endif #ifdef UFS @@ -124,166 +125,168 @@ extern off_t _lseek(int d, int offset, int whence); */ static int -NameLen( char name[] ) /* return # chars in embedded name */ - /* -> name embedded in struct direct */ +NameLen(char name[]) /* return # chars in embedded name */ +/* -> name embedded in struct direct */ { - register char *s; /* -> name[.] */ - register char *stop = &name[DIRSIZ]; /* -> past end of name field */ + register char* s; /* -> name[.] */ + register char* stop = &name[DIRSIZ]; /* -> past end of name field */ - for ( s = &name[1]; /* (empty names are impossible) */ - *s != '\0' /* not NUL terminator */ - && ++s < stop; /* < DIRSIZ characters scanned */ + for (s = &name[1]; /* (empty names are impossible) */ + *s != '\0' /* not NUL terminator */ + && ++s < stop; /* < DIRSIZ characters scanned */ ) ; - return s - name; /* # valid characters in name */ + return s - name; /* # valid characters in name */ } -#else /* BFS || NFS */ +#else /* BFS || NFS */ -#define NameLen( name ) strlen( name ) /* names are always NUL-terminated */ +#define NameLen(name) strlen(name) /* names are always NUL-terminated */ #endif #ifdef UNK -static enum { maybe, no, yes } state = maybe; - /* does _getdents() work? */ +static enum { maybe, + no, + yes } state + = maybe; +/* does _getdents() work? */ /*ARGSUSED*/ static void -sig_catch(int sig) /* sig must be SIGSYS */ +sig_catch(int sig) /* sig must be SIGSYS */ { - state = no; /* attempted _getdents() faulted */ + state = no; /* attempted _getdents() faulted */ } #endif -int -getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read; +int getdents(int fildes, char* buf, unsigned nbyte) /* returns # bytes read; 0 on EOF, -1 on error */ /* fildes == directory file descriptor */ /* *buf == where to put the (struct dirent)s */ /* nbyte == size of buf[] */ { - int serrno; /* entry errno */ - off_t offset; /* initial directory file offset */ - struct stat statb; /* fstat() info */ - union { - char dblk[DIRBLKSIZ]; - /* directory file block buffer */ - struct direct dummy; /* just for alignment */ - } u; /* (avoids having to malloc()) */ - register struct direct *dp; /* -> u.dblk[.] */ - register struct dirent *bp; /* -> buf[.] */ + int serrno; /* entry errno */ + off_t offset; /* initial directory file offset */ + struct stat statb; /* fstat() info */ + union { + char dblk[DIRBLKSIZ]; + /* directory file block buffer */ + struct direct dummy; /* just for alignment */ + } u; /* (avoids having to malloc()) */ + register struct direct* dp; /* -> u.dblk[.] */ + register struct dirent* bp; /* -> buf[.] */ #ifdef UNK - switch ( state ) - { - void (*shdlr)(); /* entry SIGSYS handler */ - register int retval; /* return from _getdents() if any */ + switch (state) + { + void (*shdlr)(); /* entry SIGSYS handler */ + register int retval; /* return from _getdents() if any */ - case yes: /* _getdents() is known to work */ - return _getdents( fildes, buf, nbyte ); + case yes: /* _getdents() is known to work */ + return _getdents(fildes, buf, nbyte); - case maybe: /* first time only */ - shdlr = signal( SIGSYS, sig_catch ); - retval = _getdents( fildes, buf, nbyte ); /* try it */ - (void)signal( SIGSYS, shdlr ); + case maybe: /* first time only */ + shdlr = signal(SIGSYS, sig_catch); + retval = _getdents(fildes, buf, nbyte); /* try it */ + (void)signal(SIGSYS, shdlr); - if ( state == maybe ) /* SIGSYS did not occur */ + if (state == maybe) /* SIGSYS did not occur */ { - state = yes; /* so _getdents() must have worked */ - return retval; + state = yes; /* so _getdents() must have worked */ + return retval; } - /* else fall through into emulation */ + /* else fall through into emulation */ -/* case no:*/ /* fall through into emulation */ - } + /* case no:*/ /* fall through into emulation */ + } #endif - if ( buf == NULL + if (buf == NULL #ifdef ATT_SPEC - || (unsigned long)buf % sizeof(long) != 0 /* ugh */ + || (unsigned long)buf % sizeof(long) != 0 /* ugh */ #endif - ) { - errno = EFAULT; /* invalid pointer */ + ) + { + errno = EFAULT; /* invalid pointer */ return -1; - } + } - if ( _fstat( fildes, &statb ) != 0 ) - return -1; /* errno set by fstat() */ + if (_fstat(fildes, &statb) != 0) + return -1; /* errno set by fstat() */ - if ( !S_ISDIR( statb.st_mode ) ) - { - errno = ENOTDIR; /* not a directory */ + if (!S_ISDIR(statb.st_mode)) + { + errno = ENOTDIR; /* not a directory */ return -1; - } + } - if ( (offset = _lseek( fildes, (off_t)0, SEEK_CUR )) < 0 ) - return -1; /* errno set by lseek() */ + if ((offset = _lseek(fildes, (off_t)0, SEEK_CUR)) < 0) + return -1; /* errno set by lseek() */ -#ifdef BFS /* no telling what remote hosts do */ - if ( (unsigned long)offset % DIRBLKSIZ != 0 ) - { - errno = ENOENT; /* file pointer probably misaligned */ +#ifdef BFS /* no telling what remote hosts do */ + if ((unsigned long)offset % DIRBLKSIZ != 0) + { + errno = ENOENT; /* file pointer probably misaligned */ return -1; - } + } #endif - serrno = errno; /* save entry errno */ + serrno = errno; /* save entry errno */ - for ( bp = (struct dirent *)buf; bp == (struct dirent *)buf; ) - { /* convert next directory block */ - int size; + for (bp = (struct dirent*)buf; bp == (struct dirent*)buf;) + { /* convert next directory block */ + int size; - do size = GetBlock( fildes, u.dblk, DIRBLKSIZ ); - while ( size == -1 && errno == EINTR ); + do + size = GetBlock(fildes, u.dblk, DIRBLKSIZ); + while (size == -1 && errno == EINTR); - if ( size <= 0 ) - return size; /* EOF or error (EBADF) */ + if (size <= 0) + return size; /* EOF or error (EBADF) */ - for ( dp = (struct direct *)u.dblk; - (char *)dp < &u.dblk[size]; - dp = (struct direct *)((char *)dp + RecLen( dp )) - ) { + for (dp = (struct direct*)u.dblk; + (char*)dp < &u.dblk[size]; + dp = (struct direct*)((char*)dp + RecLen(dp))) + { #ifndef UFS - if ( dp->d_reclen <= 0 ) - { - errno = EIO; /* corrupted directory */ + if (dp->d_reclen <= 0) + { + errno = EIO; /* corrupted directory */ return -1; - } + } #endif - if ( dp->d_fileno != 0 ) - { /* non-empty; copy to user buffer */ - register int reclen = - DIRENTSIZ( NameLen( dp->d_name ) ); + if (dp->d_fileno != 0) + { /* non-empty; copy to user buffer */ + register int reclen = DIRENTSIZ(NameLen(dp->d_name)); - if ( (char *)bp + reclen > &buf[nbyte] ) - { + if ((char*)bp + reclen > &buf[nbyte]) + { errno = EINVAL; - return -1; /* buf too small */ - } + return -1; /* buf too small */ + } bp->d_ino = dp->d_fileno; - bp->d_off = offset + ((char *)dp - u.dblk); + bp->d_off = offset + ((char*)dp - u.dblk); bp->d_reclen = reclen; - (void)strncpy( bp->d_name, dp->d_name, - reclen - DIRENTBASESIZ - ); /* adds NUL padding */ + (void)strncpy(bp->d_name, dp->d_name, + reclen - DIRENTBASESIZ); /* adds NUL padding */ - bp = (struct dirent *)((char *)bp + reclen); - } + bp = (struct dirent*)((char*)bp + reclen); } - -#ifndef BFS /* 4.2BSD screwed up; fixed in 4.3BSD */ - if ( (char *)dp > &u.dblk[size] ) - { - errno = EIO; /* corrupted directory */ - return -1; - } -#endif } - errno = serrno; /* restore entry errno */ - return (char *)bp - buf; /* return # bytes read */ +#ifndef BFS /* 4.2BSD screwed up; fixed in 4.3BSD */ + if ((char*)dp > &u.dblk[size]) + { + errno = EIO; /* corrupted directory */ + return -1; + } +#endif + } + + errno = serrno; /* restore entry errno */ + return (char*)bp - buf; /* return # bytes read */ } diff --git a/lang/cem/libcc.ansi/misc/getgrent.c b/lang/cem/libcc.ansi/misc/getgrent.c index 343884a22..33517f961 100644 --- a/lang/cem/libcc.ansi/misc/getgrent.c +++ b/lang/cem/libcc.ansi/misc/getgrent.c @@ -5,131 +5,130 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include -#define O_RDONLY 0 +#define O_RDONLY 0 -int open(const char *path, int flags); +int open(const char* path, int flags); -#if defined(__BSD4_2) -typedef int off_t; /* see lseek(2) */ +#if defined(__BSD4_2) +typedef int off_t; /* see lseek(2) */ #else typedef long off_t; #endif off_t _lseek(int d, off_t offset, int whence); -int _read(int d, char *buf, int nbytes); +int _read(int d, char* buf, int nbytes); int _close(int d); -#define RBUFSIZE 1024 +#define RBUFSIZE 1024 static char _gr_file[] = "/etc/group"; static char _grbuf[256]; static char _buffer[RBUFSIZE]; -static char *_pnt; -static char *_buf; -static int _gfd = -1; -static int _bufcnt; +static char* _pnt; +static char* _buf; +static int _gfd = -1; +static int _bufcnt; static struct group grp; -int -setgrent(void) +int setgrent(void) { - if (_gfd >= 0) - _lseek(_gfd, 0L, 0); - else - _gfd = open(_gr_file, O_RDONLY); + if (_gfd >= 0) + _lseek(_gfd, 0L, 0); + else + _gfd = open(_gr_file, O_RDONLY); - _bufcnt = 0; - return _gfd; + _bufcnt = 0; + return _gfd; } -void -endgrent(void) +void endgrent(void) { - if (_gfd >= 0) - _close(_gfd); + if (_gfd >= 0) + _close(_gfd); - _gfd = -1; - _bufcnt = 0; + _gfd = -1; + _bufcnt = 0; } - static int -getline(void) +getline(void) { - if (_gfd < 0 && setgrent() < 0) - return 0; + if (_gfd < 0 && setgrent() < 0) + return 0; - _buf = _grbuf; - do { - if (--_bufcnt <= 0){ - if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0) - return 0; - else - _pnt = _buffer; + _buf = _grbuf; + do + { + if (--_bufcnt <= 0) + { + if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0) + return 0; + else + _pnt = _buffer; } - *_buf++ = *_pnt++; - } while (*_pnt != '\n'); - _pnt++; - _bufcnt--; - *_buf = 0; - _buf = _grbuf; - return 1; + *_buf++ = *_pnt++; + } while (*_pnt != '\n'); + _pnt++; + _bufcnt--; + *_buf = 0; + _buf = _grbuf; + return 1; } static void -skip_period(void) +skip_period(void) { - while (*_buf && *_buf != ':') - _buf++; - *_buf++ = '\0'; + while (*_buf && *_buf != ':') + _buf++; + *_buf++ = '\0'; } -struct group * -getgrent(void) +struct group* +getgrent(void) { - if (getline() == 0) - return 0; + if (getline() == 0) + return 0; - grp.gr_name = _buf; - skip_period(); - grp.gr_passwd = _buf; - skip_period(); - grp.gr_gid = atoi(_buf); - skip_period(); - return &grp; + grp.gr_name = _buf; + skip_period(); + grp.gr_passwd = _buf; + skip_period(); + grp.gr_gid = atoi(_buf); + skip_period(); + return &grp; } -struct group * -getgrnam(const char *name) +struct group* +getgrnam(const char* name) { - struct group *g; + struct group* g; - setgrent(); - while ((g = getgrent()) != 0) - if (!strcmp(g -> gr_name, name)) - break; - endgrent(); - if (g != 0) - return g; - else - return 0; + setgrent(); + while ((g = getgrent()) != 0) + if (!strcmp(g->gr_name, name)) + break; + endgrent(); + if (g != 0) + return g; + else + return 0; } -struct group * +struct group* getgrgid(int gid) { - struct group *g; + struct group* g; - setgrent(); - while ((g = getgrent()) != 0) - if (g -> gr_gid == gid) - break; - endgrent(); - if (g != 0) - return g; - else - return 0; + setgrent(); + while ((g = getgrent()) != 0) + if (g->gr_gid == gid) + break; + endgrent(); + if (g != 0) + return g; + else + return 0; } diff --git a/lang/cem/libcc.ansi/misc/getopt.c b/lang/cem/libcc.ansi/misc/getopt.c index cad57fc10..9c9b88e20 100644 --- a/lang/cem/libcc.ansi/misc/getopt.c +++ b/lang/cem/libcc.ansi/misc/getopt.c @@ -3,56 +3,66 @@ */ /* $Id$ */ -#include -#include +#include +#include -#define ERR(s, c) if(opterr){\ - fputs(argv[0], stderr);\ - fputs(s, stderr);\ - fputc(c, stderr);\ - fputc('\n', stderr);} +#define ERR(s, c) \ + if (opterr) \ + { \ + fputs(argv[0], stderr); \ + fputs(s, stderr); \ + fputc(c, stderr); \ + fputc('\n', stderr); \ + } -int opterr = 1; -int optind = 1; -int optopt; -char *optarg; +int opterr = 1; +int optind = 1; +int optopt; +char* optarg; -int -getopt(int argc, char **argv, char *opts) +int getopt(int argc, char** argv, char* opts) { static int sp = 1; register c; - register char *cp; + register char* cp; if (sp == 1) - if (optind >= argc || - argv[optind][0] != '-' || argv[optind][1] == '\0') + if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return EOF; - else if (!strcmp(argv[optind], "--")) { + else if (!strcmp(argv[optind], "--")) + { optind++; return EOF; } optopt = c = argv[optind][sp]; - if (c == ':' || (cp=strchr(opts, c)) == NULL) { - ERR (": illegal option -- ", c); - if (argv[optind][++sp] == '\0') { + if (c == ':' || (cp = strchr(opts, c)) == NULL) + { + ERR(": illegal option -- ", c); + if (argv[optind][++sp] == '\0') + { optind++; sp = 1; } return '?'; } - if (*++cp == ':') { - if (argv[optind][sp+1] != '\0') - optarg = &argv[optind++][sp+1]; - else if (++optind >= argc) { - ERR (": option requires an argument -- ", c); + if (*++cp == ':') + { + if (argv[optind][sp + 1] != '\0') + optarg = &argv[optind++][sp + 1]; + else if (++optind >= argc) + { + ERR(": option requires an argument -- ", c); sp = 1; return '?'; - } else + } + else optarg = argv[optind++]; sp = 1; - } else { - if (argv[optind][++sp] == '\0') { + } + else + { + if (argv[optind][++sp] == '\0') + { sp = 1; optind++; } diff --git a/lang/cem/libcc.ansi/misc/getpass.c b/lang/cem/libcc.ansi/misc/getpass.c index ec209f37f..4b21512ee 100644 --- a/lang/cem/libcc.ansi/misc/getpass.c +++ b/lang/cem/libcc.ansi/misc/getpass.c @@ -3,22 +3,21 @@ */ /* $Id$ */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -int _open(const char *path, int flags); -int _write(int d, const char *buf, int nbytes); -int _read(int d, char *buf, int nbytes); +int _open(const char* path, int flags); +int _write(int d, const char* buf, int nbytes); +int _read(int d, char* buf, int nbytes); int _close(int d); -int _stty(int, struct sgttyb *); -int _gtty(int, struct sgttyb *); +int _stty(int, struct sgttyb*); +int _gtty(int, struct sgttyb*); -char * -getpass(const char *prompt) +char* getpass(const char* prompt) { int i = 0; struct sgttyb tty, ttysave; @@ -26,7 +25,8 @@ getpass(const char *prompt) int fd; void (*savesig)(int); - if ((fd = _open("/dev/tty", O_RDONLY)) < 0) fd = 0; + if ((fd = _open("/dev/tty", O_RDONLY)) < 0) + fd = 0; savesig = signal(SIGINT, SIG_IGN); _write(2, prompt, strlen(prompt)); _gtty(fd, &tty); @@ -39,7 +39,8 @@ getpass(const char *prompt) pwdbuf[i - 1] = '\0'; _stty(fd, &ttysave); _write(2, "\n", 1); - if (fd != 0) _close(fd); + if (fd != 0) + _close(fd); signal(SIGINT, savesig); - return(pwdbuf); + return (pwdbuf); } diff --git a/lang/cem/libcc.ansi/misc/getw.c b/lang/cem/libcc.ansi/misc/getw.c index 70efda78d..7b1f1f95e 100644 --- a/lang/cem/libcc.ansi/misc/getw.c +++ b/lang/cem/libcc.ansi/misc/getw.c @@ -3,17 +3,19 @@ */ /* $Id$ */ -#include +#include -int getw(register FILE *stream) +int getw(register FILE* stream) { register int cnt = sizeof(int); int w; - register char *p = (char *) &w; + register char* p = (char*)&w; - while (cnt--) { + while (cnt--) + { *p++ = getc(stream); } - if (feof(stream) || ferror(stream)) return EOF; + if (feof(stream) || ferror(stream)) + return EOF; return w; } diff --git a/lang/cem/libcc.ansi/misc/mktemp.c b/lang/cem/libcc.ansi/misc/mktemp.c index 695dad4e1..a5b789050 100644 --- a/lang/cem/libcc.ansi/misc/mktemp.c +++ b/lang/cem/libcc.ansi/misc/mktemp.c @@ -3,28 +3,32 @@ /* no _-protected system-calls? */ unsigned int getpid(void); -int access(char *, int); +int access(char*, int); -char *mktemp(char *template) +char* mktemp(char* template) { - register int pid, k; - register char *p; + register int pid, k; + register char* p; - pid = getpid(); /* get process id as semi-unique number */ - p = template; - while (*p) p++; /* find end of string */ + pid = getpid(); /* get process id as semi-unique number */ + p = template; + while (*p) + p++; /* find end of string */ - /* Replace XXXXXX at end of template with pid. */ - while (*--p == 'X') { - *p = '0' + (pid % 10); - pid /= 10; - } - p++; - for (k = 'a'; k <= 'z'; k++) { - *p = k; - if (access(template, 0) < 0) { - return template; + /* Replace XXXXXX at end of template with pid. */ + while (*--p == 'X') + { + *p = '0' + (pid % 10); + pid /= 10; } - } - return("/"); + p++; + for (k = 'a'; k <= 'z'; k++) + { + *p = k; + if (access(template, 0) < 0) + { + return template; + } + } + return ("/"); } diff --git a/lang/cem/libcc.ansi/misc/opendir.c b/lang/cem/libcc.ansi/misc/opendir.c index 7e3842055..b7b3472d0 100644 --- a/lang/cem/libcc.ansi/misc/opendir.c +++ b/lang/cem/libcc.ansi/misc/opendir.c @@ -4,64 +4,63 @@ last edit: 16-Jun-1987 D A Gwyn */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -typedef void *pointer; /* (void *) if you have it */ +typedef void* pointer; /* (void *) if you have it */ -extern int _open(const char *path, int flags, int mode); +extern int _open(const char* path, int flags, int mode); extern int _close(int d); -extern int _fstat(int fd, struct stat *buf); +extern int _fstat(int fd, struct stat* buf); #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #ifndef O_RDONLY -#define O_RDONLY 0 +#define O_RDONLY 0 #endif -#ifndef S_ISDIR /* macro to test for directory file */ -#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR) +#ifndef S_ISDIR /* macro to test for directory file */ +#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #endif -DIR * -opendir(const char *dirname) /* name of directory */ +DIR* opendir(const char* dirname) /* name of directory */ { - register DIR *dirp; /* -> malloc'ed storage */ - register int fd; /* file descriptor for read */ - struct stat sbuf; /* result of fstat() */ + register DIR* dirp; /* -> malloc'ed storage */ + register int fd; /* file descriptor for read */ + struct stat sbuf; /* result of fstat() */ - if ( (fd = _open( dirname, O_RDONLY, 0 )) < 0 ) - return NULL; /* errno set by open() */ + if ((fd = _open(dirname, O_RDONLY, 0)) < 0) + return NULL; /* errno set by open() */ - if ( _fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) ) - { - (void)_close( fd ); + if (_fstat(fd, &sbuf) != 0 || !S_ISDIR(sbuf.st_mode)) + { + (void)_close(fd); errno = ENOTDIR; - return NULL; /* not a directory */ - } + return NULL; /* not a directory */ + } - if ( (dirp = (DIR *)malloc( sizeof(DIR) )) == NULL - || (dirp->dd_buf = (char *)malloc( (unsigned)DIRBUF )) == NULL - ) { - register int serrno = errno; - /* errno set to ENOMEM by sbrk() */ + if ((dirp = (DIR*)malloc(sizeof(DIR))) == NULL + || (dirp->dd_buf = (char*)malloc((unsigned)DIRBUF)) == NULL) + { + register int serrno = errno; + /* errno set to ENOMEM by sbrk() */ - if ( dirp != NULL ) - free( (pointer)dirp ); + if (dirp != NULL) + free((pointer)dirp); - (void)_close( fd ); + (void)_close(fd); errno = serrno; - return NULL; /* not enough memory */ - } + return NULL; /* not enough memory */ + } dirp->dd_fd = fd; - dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ + dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ return dirp; } diff --git a/lang/cem/libcc.ansi/misc/popen.c b/lang/cem/libcc.ansi/misc/popen.c index b0dd8d400..b3352e9ad 100644 --- a/lang/cem/libcc.ansi/misc/popen.c +++ b/lang/cem/libcc.ansi/misc/popen.c @@ -3,55 +3,57 @@ */ /* $Id$ */ -#include -#include -#include -#if defined(__BSD4_2) +#include +#include +#include +#if defined(__BSD4_2) union wait { - int w_status; + int w_status; }; typedef union wait wait_arg; #else typedef int wait_arg; -#endif /* __BSD4_2 */ -#include "../stdio/loc_incl.h" +#endif /* __BSD4_2 */ +#include "../stdio/loc_incl.h" int _close(int d); #if defined(__USG) static #endif -int _dup2(int oldd, int newd); /* not present in System 5 */ -int _execl(const char *name, ... ); + int + _dup2(int oldd, int newd); /* not present in System 5 */ +int _execl(const char* name, ...); int _fork(void); int _pipe(int fildes[2]); -int _wait(wait_arg *status); +int _wait(wait_arg* status); void _exit(int status); static int pids[FOPEN_MAX]; -FILE * -popen(const char *command, const char *type) +FILE* popen(const char* command, const char* type) { int piped[2]; int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2; int pid; - if (Xtype == 2 || - _pipe(piped) < 0 || - (pid = _fork()) < 0) return 0; - - if (pid == 0) { - /* child */ - register int *p; + if (Xtype == 2 || _pipe(piped) < 0 || (pid = _fork()) < 0) + return 0; - for (p = pids; p < &pids[ FOPEN_MAX]; p++) { - if (*p) _close(p - pids); + if (pid == 0) + { + /* child */ + register int* p; + + for (p = pids; p < &pids[FOPEN_MAX]; p++) + { + if (*p) + _close(p - pids); } _close(piped[Xtype]); _dup2(piped[!Xtype], !Xtype); _close(piped[!Xtype]); - _execl("/bin/sh", "sh", "-c", command, (char *) 0); - _exit(127); /* like system() ??? */ + _execl("/bin/sh", "sh", "-c", command, (char*)0); + _exit(127); /* like system() ??? */ } pids[piped[Xtype]] = pid; @@ -59,14 +61,13 @@ popen(const char *command, const char *type) return fdopen(piped[Xtype], type); } -#if defined(__BSD4_2) -#define ret_val status.w_status +#if defined(__BSD4_2) +#define ret_val status.w_status #else -#define ret_val status +#define ret_val status #endif -int -pclose(FILE *stream) +int pclose(FILE* stream) { int fd = fileno(stream); wait_arg status; @@ -75,17 +76,20 @@ pclose(FILE *stream) void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN); fclose(stream); - while ((wret = _wait(&status)) != -1) { - if (wret == pids[fd]) break; + while ((wret = _wait(&status)) != -1) + { + if (wret == pids[fd]) + break; } - if (wret == -1) ret_val = -1; + if (wret == -1) + ret_val = -1; signal(SIGINT, intsave); signal(SIGQUIT, quitsave); pids[fd] = 0; return ret_val; } -#if defined(__USG) +#if defined(__USG) int _dup(int fildes); static int @@ -95,16 +99,21 @@ _dup2(int oldd, int newd) int fdbuf[FOPEN_MAX]; /* ignore the error on the close() */ - tmp = errno; (void) _close(newd); errno = tmp; - while ((fd = _dup(oldd)) != newd) { - if (fd == -1) break; + tmp = errno; + (void)_close(newd); + errno = tmp; + while ((fd = _dup(oldd)) != newd) + { + if (fd == -1) + break; fdbuf[i++] = fd; } tmp = errno; - while (--i >= 0) { + while (--i >= 0) + { _close(fdbuf[i]); } errno = tmp; return -(fd == -1); } -#endif /* __USG */ +#endif /* __USG */ diff --git a/lang/cem/libcc.ansi/misc/putw.c b/lang/cem/libcc.ansi/misc/putw.c index a195a2d32..d5c137df2 100644 --- a/lang/cem/libcc.ansi/misc/putw.c +++ b/lang/cem/libcc.ansi/misc/putw.c @@ -3,17 +3,18 @@ */ /* $Id$ */ -#include +#include -int -putw(int w, register FILE *stream) +int putw(int w, register FILE* stream) { register int cnt = sizeof(int); - register char *p = (char *) &w; + register char* p = (char*)&w; - while (cnt--) { + while (cnt--) + { putc(*p++, stream); } - if (ferror(stream)) return EOF; + if (ferror(stream)) + return EOF; return w; } diff --git a/lang/cem/libcc.ansi/misc/readdir.c b/lang/cem/libcc.ansi/misc/readdir.c index 2497e4673..ac1d800b1 100644 --- a/lang/cem/libcc.ansi/misc/readdir.c +++ b/lang/cem/libcc.ansi/misc/readdir.c @@ -4,44 +4,41 @@ last edit: 25-Apr-1987 D A Gwyn */ -#include -#include -#include -#include +#include +#include +#include +#include /* SVR3 system call, or emulation for getdents() */ -extern int getdents(int fildes, char *buf, unsigned nbyte); +extern int getdents(int fildes, char* buf, unsigned nbyte); #ifndef NULL -#define NULL 0 +#define NULL 0 #endif -struct dirent * -readdir(register DIR *dirp) +struct dirent* +readdir(register DIR* dirp) { - register struct dirent *dp; /* -> directory data */ + register struct dirent* dp; /* -> directory data */ - if ( dirp == NULL || dirp->dd_buf == NULL ) - { + if (dirp == NULL || dirp->dd_buf == NULL) + { errno = EFAULT; - return NULL; /* invalid pointer */ - } + return NULL; /* invalid pointer */ + } - do { - if ( dirp->dd_loc >= dirp->dd_size ) /* empty or obsolete */ + do + { + if (dirp->dd_loc >= dirp->dd_size) /* empty or obsolete */ dirp->dd_loc = dirp->dd_size = 0; - if ( dirp->dd_size == 0 /* need to refill buffer */ - && (dirp->dd_size = - getdents( dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF ) - ) <= 0 - ) - return NULL; /* EOF or error */ + if (dirp->dd_size == 0 /* need to refill buffer */ + && (dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF)) <= 0) + return NULL; /* EOF or error */ - dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc]; + dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc]; dirp->dd_loc += dp->d_reclen; - } - while ( dp->d_ino == 0L ); /* don't rely on getdents() */ + } while (dp->d_ino == 0L); /* don't rely on getdents() */ return dp; } diff --git a/lang/cem/libcc.ansi/misc/rewinddir.c b/lang/cem/libcc.ansi/misc/rewinddir.c index 6186153cd..e8c9e4749 100644 --- a/lang/cem/libcc.ansi/misc/rewinddir.c +++ b/lang/cem/libcc.ansi/misc/rewinddir.c @@ -8,30 +8,29 @@ rewinddir() to forget about buffered data. */ -#include -#include -#include -#include +#include +#include +#include +#include -extern off_t _lseek(int d, int offset, int whence); +extern off_t _lseek(int d, int offset, int whence); #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #ifndef SEEK_SET -#define SEEK_SET 0 +#define SEEK_SET 0 #endif -void -rewinddir(register DIR *dirp) +void rewinddir(register DIR* dirp) { - if ( dirp == NULL || dirp->dd_buf == NULL ) - { + if (dirp == NULL || dirp->dd_buf == NULL) + { errno = EFAULT; - return; /* invalid pointer */ - } + return; /* invalid pointer */ + } - dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */ - (void)_lseek( dirp->dd_fd, (off_t)0, SEEK_SET ); /* may set errno */ + dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */ + (void)_lseek(dirp->dd_fd, (off_t)0, SEEK_SET); /* may set errno */ } diff --git a/lang/cem/libcc.ansi/misc/seekdir.c b/lang/cem/libcc.ansi/misc/seekdir.c index b162a3346..c53629292 100644 --- a/lang/cem/libcc.ansi/misc/seekdir.c +++ b/lang/cem/libcc.ansi/misc/seekdir.c @@ -10,36 +10,35 @@ practically impossible to do right. Avoid using them! */ -#include -#include -#include -#include +#include +#include +#include +#include extern off_t _lseek(int d, int offset, int whence); #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #ifndef SEEK_SET -#define SEEK_SET 0 +#define SEEK_SET 0 #endif -typedef int bool; /* Boolean data type */ -#define false 0 -#define true 1 +typedef int bool; /* Boolean data type */ +#define false 0 +#define true 1 -void -seekdir(register DIR *dirp, register off_t loc) +void seekdir(register DIR* dirp, register off_t loc) /* loc == position from telldir() */ { - register bool rewind; /* "start over when stymied" flag */ + register bool rewind; /* "start over when stymied" flag */ - if ( dirp == NULL || dirp->dd_buf == NULL ) - { + if (dirp == NULL || dirp->dd_buf == NULL) + { errno = EFAULT; - return; /* invalid pointer */ - } + return; /* invalid pointer */ + } /* A (struct dirent)'s d_off is an invented quantity on 4.nBSD NFS-supporting systems, so it is not safe to lseek() to it. */ @@ -52,58 +51,57 @@ seekdir(register DIR *dirp, register off_t loc) or even to use binary search on the directory blocks. I doubt that the extra code for that would be worthwhile. */ - if ( dirp->dd_loc >= dirp->dd_size /* invalid index */ - || ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off > loc - /* too far along in buffer */ - ) - dirp->dd_loc = 0; /* reset to beginning of buffer */ + if (dirp->dd_loc >= dirp->dd_size /* invalid index */ + || ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off > loc + /* too far along in buffer */ + ) + dirp->dd_loc = 0; /* reset to beginning of buffer */ /* else save time by starting at current dirp->dd_loc */ - for ( rewind = true; ; ) - { - register struct dirent *dp; + for (rewind = true;;) + { + register struct dirent* dp; /* See whether the matching entry is in the current buffer. */ - if ( (dirp->dd_loc < dirp->dd_size /* valid index */ - || readdir( dirp ) != NULL /* next buffer read */ - && (dirp->dd_loc = 0, true) /* beginning of buffer set */ - ) - && (dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off - <= loc /* match possible in this buffer */ - ) { - for ( /* dp initialized above */ ; - (char *)dp < &dirp->dd_buf[dirp->dd_size]; - dp = (struct dirent *)((char *)dp + dp->d_reclen) - ) - if ( dp->d_off == loc ) - { /* found it! */ - dirp->dd_loc = - (char *)dp - dirp->dd_buf; + if ((dirp->dd_loc < dirp->dd_size /* valid index */ + || readdir(dirp) != NULL /* next buffer read */ + && (dirp->dd_loc = 0, true) /* beginning of buffer set */ + ) + && (dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off + <= loc /* match possible in this buffer */ + ) + { + for (/* dp initialized above */; + (char*)dp < &dirp->dd_buf[dirp->dd_size]; + dp = (struct dirent*)((char*)dp + dp->d_reclen)) + if (dp->d_off == loc) + { /* found it! */ + dirp->dd_loc = (char*)dp - dirp->dd_buf; return; - } - - rewind = false; /* no point in backing up later */ - dirp->dd_loc = dirp->dd_size; /* set end of buffer */ - } - else /* whole buffer past matching entry */ - if ( !rewind ) - { /* no point in searching further */ - errno = EINVAL; - return; /* no entry at specified loc */ } - else { /* rewind directory and start over */ - rewind = false; /* but only once! */ - dirp->dd_loc = dirp->dd_size = 0; - - if ( _lseek( dirp->dd_fd, (off_t)0, SEEK_SET ) - != 0 - ) - return; /* errno already set (EBADF) */ - - if ( loc == 0 ) - return; /* save time */ - } + rewind = false; /* no point in backing up later */ + dirp->dd_loc = dirp->dd_size; /* set end of buffer */ } + else /* whole buffer past matching entry */ + if (!rewind) + { /* no point in searching further */ + errno = EINVAL; + return; /* no entry at specified loc */ + } + else + { /* rewind directory and start over */ + rewind = false; /* but only once! */ + + dirp->dd_loc = dirp->dd_size = 0; + + if (_lseek(dirp->dd_fd, (off_t)0, SEEK_SET) + != 0) + return; /* errno already set (EBADF) */ + + if (loc == 0) + return; /* save time */ + } + } } diff --git a/lang/cem/libcc.ansi/misc/sleep.c b/lang/cem/libcc.ansi/misc/sleep.c index 4bc8f2d57..1b7c9a8d7 100644 --- a/lang/cem/libcc.ansi/misc/sleep.c +++ b/lang/cem/libcc.ansi/misc/sleep.c @@ -3,44 +3,48 @@ */ /* $Id$ */ -#include -#include +#include +#include int _alarm(int n); void _pause(void); -static jmp_buf setjmpbuf; +static jmp_buf setjmpbuf; static void alfun(int sig) { longjmp(setjmpbuf, 1); -} /* used with sleep() below */ +} /* used with sleep() below */ -void -sleep(int n) +void sleep(int n) { -/* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */ + /* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */ unsigned oldalarm = 0; void (*oldsig)(int) = 0; - if (n <= 0) return; - if (setjmp(setjmpbuf)) { + if (n <= 0) + return; + if (setjmp(setjmpbuf)) + { signal(SIGALRM, oldsig); _alarm(oldalarm); return; } - oldalarm = _alarm(5000); /* Who cares how long, as long + oldalarm = _alarm(5000); /* Who cares how long, as long * as it is long enough */ - if (oldalarm > n) oldalarm -= n; - else if (oldalarm) { + if (oldalarm > n) + oldalarm -= n; + else if (oldalarm) + { n = oldalarm; oldalarm = 1; } oldsig = signal(SIGALRM, alfun); _alarm(n); - for (;;) { + for (;;) + { /* allow for other handlers ... */ _pause(); } diff --git a/lang/cem/libcc.ansi/misc/telldir.c b/lang/cem/libcc.ansi/misc/telldir.c index d96d78c62..9db00740a 100644 --- a/lang/cem/libcc.ansi/misc/telldir.c +++ b/lang/cem/libcc.ansi/misc/telldir.c @@ -7,28 +7,27 @@ practically impossible to do right. Avoid using them! */ -#include -#include -#include -#include +#include +#include +#include +#include extern off_t _lseek(int d, int offset, int whence); #ifndef SEEK_CUR -#define SEEK_CUR 1 +#define SEEK_CUR 1 #endif -off_t -telldir(register DIR *dirp) /* return offset of next entry */ +off_t telldir(register DIR* dirp) /* return offset of next entry */ { - if ( dirp == NULL || dirp->dd_buf == NULL ) - { + if (dirp == NULL || dirp->dd_buf == NULL) + { errno = EFAULT; - return -1; /* invalid pointer */ - } + return -1; /* invalid pointer */ + } - if ( dirp->dd_loc < dirp->dd_size ) /* valid index */ - return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off; - else /* beginning of next directory block */ - return _lseek( dirp->dd_fd, (off_t)0, SEEK_CUR ); + if (dirp->dd_loc < dirp->dd_size) /* valid index */ + return ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off; + else /* beginning of next directory block */ + return _lseek(dirp->dd_fd, (off_t)0, SEEK_CUR); } diff --git a/lang/cem/libcc.ansi/setjmp/sigmisc.c b/lang/cem/libcc.ansi/setjmp/sigmisc.c index 3c807e126..d9c58d092 100644 --- a/lang/cem/libcc.ansi/setjmp/sigmisc.c +++ b/lang/cem/libcc.ansi/setjmp/sigmisc.c @@ -3,37 +3,38 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#if defined(_POSIX_SOURCE) /* This can't be done in setjmp.e, since SIG_SETMASK is defined in * . This is a C-file, which can't be included. */ -#include -#include -#include +#include +#include +#include -int _sigprocmask(int, sigset_t *, sigset_t *); +int _sigprocmask(int, sigset_t*, sigset_t*); static void -__testsigset(void) { +__testsigset(void) +{ /* This switch compiles when a sigset_t has the right size. */ - switch(0) { - case 0: - case sizeof(sigset_t) <= sizeof(long): break; + switch (0) + { + case 0: + case sizeof(sigset_t) <= sizeof(long): + break; } } -void -__newsigset(sigset_t *p) +void __newsigset(sigset_t* p) { /* The SIG_SETMASK is not significant */ _sigprocmask(SIG_SETMASK, NULL, p); } -void -__oldsigset(sigset_t *p) +void __oldsigset(sigset_t* p) { _sigprocmask(SIG_SETMASK, p, NULL); } -#endif /* _POSIX_SOURCE */ +#endif /* _POSIX_SOURCE */ diff --git a/lang/cem/libcc.ansi/signal/raise.c b/lang/cem/libcc.ansi/signal/raise.c index 42b3b4cec..e1aedaa01 100644 --- a/lang/cem/libcc.ansi/signal/raise.c +++ b/lang/cem/libcc.ansi/signal/raise.c @@ -4,13 +4,12 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#if defined(_POSIX_SOURCE) #include #endif #include -int -raise(int sig) +int raise(int sig) { if (sig < 0 || sig > _NSIG) return -1; diff --git a/lang/cem/libcc.ansi/stdio/clearerr.c b/lang/cem/libcc.ansi/stdio/clearerr.c index 3455229a2..8bfaaca79 100644 --- a/lang/cem/libcc.ansi/stdio/clearerr.c +++ b/lang/cem/libcc.ansi/stdio/clearerr.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -void -(clearerr)(FILE *stream) +void(clearerr)(FILE* stream) { clearerr(stream); } diff --git a/lang/cem/libcc.ansi/stdio/data.c b/lang/cem/libcc.ansi/stdio/data.c index 92be83b11..debff7771 100644 --- a/lang/cem/libcc.ansi/stdio/data.c +++ b/lang/cem/libcc.ansi/stdio/data.c @@ -3,24 +3,24 @@ */ /* $Id$ */ -#include +#include struct __iobuf __stdin = { 0, 0, _IOREAD, 0, - (unsigned char *)NULL, (unsigned char *)NULL, + (unsigned char*)NULL, (unsigned char*)NULL, }; struct __iobuf __stdout = { 0, 1, _IOWRITE, 0, - (unsigned char *)NULL, (unsigned char *)NULL, + (unsigned char*)NULL, (unsigned char*)NULL, }; struct __iobuf __stderr = { 0, 2, _IOWRITE | _IOLBF, 0, - (unsigned char *)NULL, (unsigned char *)NULL, + (unsigned char*)NULL, (unsigned char*)NULL, }; -FILE *__iotab[FOPEN_MAX] = { +FILE* __iotab[FOPEN_MAX] = { &__stdin, &__stdout, &__stderr, diff --git a/lang/cem/libcc.ansi/stdio/doprnt.c b/lang/cem/libcc.ansi/stdio/doprnt.c index 395c45704..dca935aad 100644 --- a/lang/cem/libcc.ansi/stdio/doprnt.c +++ b/lang/cem/libcc.ansi/stdio/doprnt.c @@ -3,25 +3,29 @@ */ /* $Id$ */ -#include -#include -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include +#include "loc_incl.h" /* gnum() is used to get the width and precision fields of a format. */ -static const char * -gnum(register const char *f, int *ip, va_list *app) +static const char* +gnum(register const char* f, int* ip, va_list* app) { - register int i, c; + register int i, c; - if (*f == '*') { + if (*f == '*') + { *ip = va_arg((*app), int); f++; - } else { + } + else + { i = 0; - while ((c = *f - '0') >= 0 && c <= 9) { - i = i*10 + c; + while ((c = *f - '0') >= 0 && c <= 9) + { + i = i * 10 + c; f++; } *ip = i; @@ -29,91 +33,121 @@ gnum(register const char *f, int *ip, va_list *app) return f; } -#if _EM_WSIZE == _EM_PSIZE -#define set_pointer(flags) /* nothing */ -#elif _EM_LSIZE == _EM_PSIZE -#define set_pointer(flags) (flags |= FL_LONG) +#if _EM_WSIZE == _EM_PSIZE +#define set_pointer(flags) /* nothing */ +#elif _EM_LSIZE == _EM_PSIZE +#define set_pointer(flags) (flags |= FL_LONG) #else #error garbage pointer size -#define set_pointer(flags) /* compilation might continue */ +#define set_pointer(flags) /* compilation might continue */ #endif -#define PUTC(c) \ - do { \ +#define PUTC(c) \ + do \ + { \ int i = putc(c, stream); \ - if (i == EOF) \ - { \ - if (ferror(stream)) \ - return -1; \ - } \ + if (i == EOF) \ + { \ + if (ferror(stream)) \ + return -1; \ + } \ } while (0) /* print an ordinal number */ -static char * -o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed) +static char* +o_print(va_list* ap, int flags, char* s, char c, int precision, int is_signed) { long signed_val; unsigned long unsigned_val; - char *old_s = s; + char* old_s = s; int base; - switch (flags & (FL_SHORT | FL_LONG)) { - case FL_SHORT: - if (is_signed) { - signed_val = (short) va_arg(*ap, int); - } else { - unsigned_val = (unsigned short) va_arg(*ap, unsigned); - } - break; - case FL_LONG: - if (is_signed) { - signed_val = va_arg(*ap, long); - } else { - unsigned_val = va_arg(*ap, unsigned long); - } - break; - default: - if (is_signed) { - signed_val = va_arg(*ap, int); - } else { - unsigned_val = va_arg(*ap, unsigned int); - } - break; + switch (flags & (FL_SHORT | FL_LONG)) + { + case FL_SHORT: + if (is_signed) + { + signed_val = (short)va_arg(*ap, int); + } + else + { + unsigned_val = (unsigned short)va_arg(*ap, unsigned); + } + break; + case FL_LONG: + if (is_signed) + { + signed_val = va_arg(*ap, long); + } + else + { + unsigned_val = va_arg(*ap, unsigned long); + } + break; + default: + if (is_signed) + { + signed_val = va_arg(*ap, int); + } + else + { + unsigned_val = va_arg(*ap, unsigned int); + } + break; } - if (is_signed) { - if (signed_val < 0) { + if (is_signed) + { + if (signed_val < 0) + { *s++ = '-'; signed_val = -signed_val; - } else if (flags & FL_SIGN) *s++ = '+'; - else if (flags & FL_SPACE) *s++ = ' '; + } + else if (flags & FL_SIGN) + *s++ = '+'; + else if (flags & FL_SPACE) + *s++ = ' '; unsigned_val = signed_val; } - if ((flags & FL_ALT) && (c == 'o')) *s++ = '0'; - if (!unsigned_val) { - if (!precision) + if ((flags & FL_ALT) && (c == 'o')) + *s++ = '0'; + if (!unsigned_val) + { + if (!precision) return s; - } else if (((flags & FL_ALT) && (c == 'x' || c == 'X')) - || c == 'p') { + } + else if (((flags & FL_ALT) && (c == 'x' || c == 'X')) + || c == 'p') + { *s++ = '0'; *s++ = (c == 'X' ? 'X' : 'x'); } - switch (c) { - case 'b': base = 2; break; - case 'o': base = 8; break; - case 'd': - case 'i': - case 'u': base = 10; break; - case 'x': - case 'X': - case 'p': base = 16; break; + switch (c) + { + case 'b': + base = 2; + break; + case 'o': + base = 8; + break; + case 'd': + case 'i': + case 'u': + base = 10; + break; + case 'x': + case 'X': + case 'p': + base = 16; + break; } s = _i_compute(unsigned_val, base, s, precision); if (c == 'X') - while (old_s != s) { + while (old_s != s) + { *old_s = toupper(*old_s); old_s++; } @@ -121,20 +155,22 @@ o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed) return s; } -int -_doprnt(register const char *fmt, va_list ap, FILE *stream) +int _doprnt(register const char* fmt, va_list ap, FILE* stream) { - register char *s; - register int j; - int i, c, width, precision, zfill, flags, between_fill; - int nrchars=0; - const char *oldfmt; - char *s1, buf[1025]; + register char* s; + register int j; + int i, c, width, precision, zfill, flags, between_fill; + int nrchars = 0; + const char* oldfmt; + char *s1, buf[1025]; - while (c = *fmt++) { - if (c != '%') { -#ifdef CPM - if (c == '\n') { + while (c = *fmt++) + { + if (c != '%') + { +#ifdef CPM + if (c == '\n') + { PUTC('\r'); } #endif @@ -143,125 +179,164 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream) continue; } flags = 0; - do { - switch(*fmt) { - case '-': flags |= FL_LJUST; break; - case '+': flags |= FL_SIGN; break; - case ' ': flags |= FL_SPACE; break; - case '#': flags |= FL_ALT; break; - case '0': flags |= FL_ZEROFILL; break; - default: flags |= FL_NOMORE; continue; + do + { + switch (*fmt) + { + case '-': + flags |= FL_LJUST; + break; + case '+': + flags |= FL_SIGN; + break; + case ' ': + flags |= FL_SPACE; + break; + case '#': + flags |= FL_ALT; + break; + case '0': + flags |= FL_ZEROFILL; + break; + default: + flags |= FL_NOMORE; + continue; } fmt++; - } while(!(flags & FL_NOMORE)); + } while (!(flags & FL_NOMORE)); oldfmt = fmt; fmt = gnum(fmt, &width, &ap); - if (fmt != oldfmt) flags |= FL_WIDTHSPEC; + if (fmt != oldfmt) + flags |= FL_WIDTHSPEC; - if (*fmt == '.') { - fmt++; oldfmt = fmt; + if (*fmt == '.') + { + fmt++; + oldfmt = fmt; fmt = gnum(fmt, &precision, &ap); - if (precision >= 0) flags |= FL_PRECSPEC; + if (precision >= 0) + flags |= FL_PRECSPEC; } - if ((flags & FL_WIDTHSPEC) && width < 0) { + if ((flags & FL_WIDTHSPEC) && width < 0) + { width = -width; flags |= FL_LJUST; } - if (!(flags & FL_WIDTHSPEC)) width = 0; + if (!(flags & FL_WIDTHSPEC)) + width = 0; - if (flags & FL_SIGN) flags &= ~FL_SPACE; - - if (flags & FL_LJUST) flags &= ~FL_ZEROFILL; + if (flags & FL_SIGN) + flags &= ~FL_SPACE; + if (flags & FL_LJUST) + flags &= ~FL_ZEROFILL; s = s1 = buf; - switch (*fmt) { - case 'h': flags |= FL_SHORT; fmt++; break; - case 'l': flags |= FL_LONG; fmt++; break; - case 'L': flags |= FL_LONGDOUBLE; fmt++; break; + switch (*fmt) + { + case 'h': + flags |= FL_SHORT; + fmt++; + break; + case 'l': + flags |= FL_LONG; + fmt++; + break; + case 'L': + flags |= FL_LONGDOUBLE; + fmt++; + break; } - switch (c = *fmt++) { - default: -#ifdef CPM - if (c == '\n') { - PUTC('\r'); - nrchars++; - } + switch (c = *fmt++) + { + default: +#ifdef CPM + if (c == '\n') + { + PUTC('\r'); + nrchars++; + } #endif - PUTC(c); - nrchars++; - continue; - case 'n': - if (flags & FL_SHORT) - *va_arg(ap, short *) = (short) nrchars; - else if (flags & FL_LONG) - *va_arg(ap, long *) = (long) nrchars; - else - *va_arg(ap, int *) = (int) nrchars; - continue; - case 's': - s1 = va_arg(ap, char *); - if (s1 == NULL) - s1 = "(null)"; - s = s1; - while (precision || !(flags & FL_PRECSPEC)) { - if (*s == '\0') - break; - s++; - precision--; - } - break; - case 'p': - set_pointer(flags); + PUTC(c); + nrchars++; + continue; + case 'n': + if (flags & FL_SHORT) + *va_arg(ap, short*) = (short)nrchars; + else if (flags & FL_LONG) + *va_arg(ap, long*) = (long)nrchars; + else + *va_arg(ap, int*) = (int)nrchars; + continue; + case 's': + s1 = va_arg(ap, char*); + if (s1 == NULL) + s1 = "(null)"; + s = s1; + while (precision || !(flags & FL_PRECSPEC)) + { + if (*s == '\0') + break; + s++; + precision--; + } + break; + case 'p': + set_pointer(flags); /* fallthrough */ - case 'b': - case 'o': - case 'u': - case 'x': - case 'X': - if (!(flags & FL_PRECSPEC)) precision = 1; - else if (c != 'p') flags &= ~FL_ZEROFILL; - s = o_print(&ap, flags, s, c, precision, 0); - break; - case 'd': - case 'i': - flags |= FL_SIGNEDCONV; - if (!(flags & FL_PRECSPEC)) precision = 1; - else flags &= ~FL_ZEROFILL; - s = o_print(&ap, flags, s, c, precision, 1); - break; - case 'c': - *s++ = va_arg(ap, int); - break; + case 'b': + case 'o': + case 'u': + case 'x': + case 'X': + if (!(flags & FL_PRECSPEC)) + precision = 1; + else if (c != 'p') + flags &= ~FL_ZEROFILL; + s = o_print(&ap, flags, s, c, precision, 0); + break; + case 'd': + case 'i': + flags |= FL_SIGNEDCONV; + if (!(flags & FL_PRECSPEC)) + precision = 1; + else + flags &= ~FL_ZEROFILL; + s = o_print(&ap, flags, s, c, precision, 1); + break; + case 'c': + *s++ = va_arg(ap, int); + break; #ifndef ACKCONF_NO_STDIO_FLOAT - case 'G': - case 'g': - if ((flags & FL_PRECSPEC) && (precision == 0)) - precision = 1; - case 'f': - case 'E': - case 'e': - if (!(flags & FL_PRECSPEC)) - precision = 6; + case 'G': + case 'g': + if ((flags & FL_PRECSPEC) && (precision == 0)) + precision = 1; + case 'f': + case 'E': + case 'e': + if (!(flags & FL_PRECSPEC)) + precision = 6; - if (precision >= sizeof(buf)) - precision = sizeof(buf) - 1; + if (precision >= sizeof(buf)) + precision = sizeof(buf) - 1; - flags |= FL_SIGNEDCONV; - s = _f_print(&ap, flags, s, c, precision); - break; -#endif /* ACKCONF_NO_STDIO_FLOAT */ - case 'r': - ap = va_arg(ap, va_list); - fmt = va_arg(ap, char *); - continue; + flags |= FL_SIGNEDCONV; + s = _f_print(&ap, flags, s, c, precision); + break; +#endif /* ACKCONF_NO_STDIO_FLOAT */ + case 'r': + ap = va_arg(ap, va_list); + fmt = va_arg(ap, char*); + continue; } zfill = ' '; - if (flags & FL_ZEROFILL) zfill = '0'; + if (flags & FL_ZEROFILL) + zfill = '0'; j = s - s1; /* between_fill is true under the following conditions: @@ -274,35 +349,45 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream) between_fill = 0; if ((flags & FL_ZEROFILL) && (((c == 'x' || c == 'X') && (flags & FL_ALT)) - || (c == 'p') - || ((flags & FL_SIGNEDCONV) - && ( *s1 == '+' || *s1 == '-' || *s1 == ' ')))) + || (c == 'p') + || ((flags & FL_SIGNEDCONV) + && (*s1 == '+' || *s1 == '-' || *s1 == ' ')))) between_fill++; if ((i = width - j) > 0) - if (!(flags & FL_LJUST)) { /* right justify */ + if (!(flags & FL_LJUST)) + { /* right justify */ nrchars += i; - if (between_fill) { - if (flags & FL_SIGNEDCONV) { - j--; nrchars++; - PUTC(*s1++); - } else { - j -= 2; nrchars += 2; - PUTC(*s1++); - PUTC(*s1++); + if (between_fill) + { + if (flags & FL_SIGNEDCONV) + { + j--; + nrchars++; + PUTC(*s1++); + } + else + { + j -= 2; + nrchars += 2; + PUTC(*s1++); + PUTC(*s1++); } } - do { + do + { PUTC(zfill); } while (--i); } nrchars += j; - while (--j >= 0) { + while (--j >= 0) + { PUTC(*s1++); } - if (i > 0) nrchars += i; + if (i > 0) + nrchars += i; while (--i >= 0) PUTC(zfill); } diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/stdio/doscan.c index eb93a4029..52e957a5d 100644 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ b/lang/cem/libcc.ansi/stdio/doscan.c @@ -3,26 +3,26 @@ */ /* $Id$ */ -#include -#include -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include +#include "loc_incl.h" -#if _EM_WSIZE == _EM_PSIZE -#define set_pointer(flags) /* nothing */ -#elif _EM_LSIZE == _EM_PSIZE -#define set_pointer(flags) (flags |= FL_LONG) +#if _EM_WSIZE == _EM_PSIZE +#define set_pointer(flags) /* nothing */ +#elif _EM_LSIZE == _EM_PSIZE +#define set_pointer(flags) (flags |= FL_LONG) #else #error garbage pointer size -#define set_pointer(flags) /* compilation might continue */ +#define set_pointer(flags) /* compilation might continue */ #endif -#define NUMLEN 512 -#define NR_CHARS 256 +#define NUMLEN 512 +#define NR_CHARS 256 -static char Xtable[NR_CHARS]; -static char inp_buf[NUMLEN]; +static char Xtable[NR_CHARS]; +static char inp_buf[NUMLEN]; /* Collect a number of characters which constitite an ordinal number. * When the type is 'i', the base can be 8, 10, or 16, depending on the @@ -30,65 +30,85 @@ static char inp_buf[NUMLEN]; * according to the format of the number. At the end of the function, base * is then set to 0, so strtol() will get the right argument. */ -static char * -o_collect(register int c, register FILE *stream, char type, - int width, int *basep) +static char* +o_collect(register int c, register FILE* stream, char type, + int width, int* basep) { - register char *bufp = inp_buf; + register char* bufp = inp_buf; register int base; - switch (type) { - case 'i': /* i means octal, decimal or hexadecimal */ - case 'p': - case 'x': - case 'X': base = 16; break; - case 'd': - case 'u': base = 10; break; - case 'o': base = 8; break; - case 'b': base = 2; break; + switch (type) + { + case 'i': /* i means octal, decimal or hexadecimal */ + case 'p': + case 'x': + case 'X': + base = 16; + break; + case 'd': + case 'u': + base = 10; + break; + case 'o': + base = 8; + break; + case 'b': + base = 2; + break; } - if (c == '-' || c == '+') { - *bufp++ = c; - if (--width) - c = getc(stream); - } - - if (width && c == '0' && base == 16) { + if (c == '-' || c == '+') + { *bufp++ = c; if (--width) c = getc(stream); - if (c != 'x' && c != 'X') { - if (type == 'i') base = 8; + } + + if (width && c == '0' && base == 16) + { + *bufp++ = c; + if (--width) + c = getc(stream); + if (c != 'x' && c != 'X') + { + if (type == 'i') + base = 8; } - else if (width) { + else if (width) + { *bufp++ = c; if (--width) c = getc(stream); } } - else if (type == 'i') base = 10; + else if (type == 'i') + base = 10; - while (width) { + while (width) + { if (((base == 10) && isdigit(c)) || ((base == 16) && isxdigit(c)) || ((base == 8) && isdigit(c) && (c < '8')) - || ((base == 2) && isdigit(c) && (c < '2'))) { + || ((base == 2) && isdigit(c) && (c < '2'))) + { *bufp++ = c; if (--width) c = getc(stream); } - else break; + else + break; } - if (width && c != EOF) ungetc(c, stream); - if (type == 'i') base = 0; + if (width && c != EOF) + ungetc(c, stream); + if (type == 'i') + base = 0; *basep = base; *bufp = '\0'; return bufp - 1; } -#ifndef ACKCONF_NO_STDIO_FLOAT +#ifndef ACKCONF_NO_STDIO_FLOAT /* The function f_collect() reads a string that has the format of a * floating-point number. The function returns as soon as a format-error * is encountered, leaving the offending character in the input. This means @@ -97,353 +117,425 @@ o_collect(register int c, register FILE *stream, char type, * not necessary, although the use of the width field can cause incomplete * numbers to be passed to strtod(). (e.g. 1.3e+) */ -static char * -f_collect(register int c, register FILE *stream, register int width) +static char* +f_collect(register int c, register FILE* stream, register int width) { - register char *bufp = inp_buf; + register char* bufp = inp_buf; int digit_seen = 0; - if (c == '-' || c == '+') { + if (c == '-' || c == '+') + { *bufp++ = c; if (--width) c = getc(stream); } - while (width && isdigit(c)) { + while (width && isdigit(c)) + { digit_seen++; *bufp++ = c; if (--width) c = getc(stream); } - if (width && c == '.') { - *bufp++ = c; - if(--width) - c = getc(stream); - while (width && isdigit(c)) { - digit_seen++; - *bufp++ = c; - if (--width) - c = getc(stream); - } - } - - if (!digit_seen) { - if (width && c != EOF) ungetc(c, stream); - return inp_buf - 1; - } - else digit_seen = 0; - - if (width && (c == 'e' || c == 'E')) { + if (width && c == '.') + { *bufp++ = c; if (--width) c = getc(stream); - if (width && (c == '+' || c == '-')) { - *bufp++ = c; - if (--width) - c = getc(stream); - } - while (width && isdigit(c)) { + while (width && isdigit(c)) + { digit_seen++; *bufp++ = c; if (--width) c = getc(stream); } - if (!digit_seen) { - if (width && c != EOF) ungetc(c,stream); + } + + if (!digit_seen) + { + if (width && c != EOF) + ungetc(c, stream); + return inp_buf - 1; + } + else + digit_seen = 0; + + if (width && (c == 'e' || c == 'E')) + { + *bufp++ = c; + if (--width) + c = getc(stream); + if (width && (c == '+' || c == '-')) + { + *bufp++ = c; + if (--width) + c = getc(stream); + } + while (width && isdigit(c)) + { + digit_seen++; + *bufp++ = c; + if (--width) + c = getc(stream); + } + if (!digit_seen) + { + if (width && c != EOF) + ungetc(c, stream); return inp_buf - 1; } } - if (width && c != EOF) ungetc(c, stream); + if (width && c != EOF) + ungetc(c, stream); *bufp = '\0'; return bufp - 1; } -#endif /* ACKCONF_NO_STDIO_FLOAT */ - +#endif /* ACKCONF_NO_STDIO_FLOAT */ /* * the routine that does the scanning */ -int -_doscan(register FILE *stream, const char *format, va_list ap) +int _doscan(register FILE* stream, const char* format, va_list ap) { - int done = 0; /* number of items done */ - int nrchars = 0; /* number of characters read */ - int conv = 0; /* # of conversions */ - int base; /* conversion base */ - unsigned long val; /* an integer value */ - register char *str; /* temporary pointer */ - char *tmp_string; /* ditto */ - unsigned width; /* width of field */ - int flags; /* some flags */ - int reverse; /* reverse the checking in [...] */ - int kind; - register int ic; /* the input character */ -#ifndef ACKCONF_NO_STDIO_FLOAT - long double ld_val; + int done = 0; /* number of items done */ + int nrchars = 0; /* number of characters read */ + int conv = 0; /* # of conversions */ + int base; /* conversion base */ + unsigned long val; /* an integer value */ + register char* str; /* temporary pointer */ + char* tmp_string; /* ditto */ + unsigned width; /* width of field */ + int flags; /* some flags */ + int reverse; /* reverse the checking in [...] */ + int kind; + register int ic; /* the input character */ +#ifndef ACKCONF_NO_STDIO_FLOAT + long double ld_val; #endif - if (!*format) return 0; + if (!*format) + return 0; - while (1) { - if (isspace(*format)) { + while (1) + { + if (isspace(*format)) + { while (isspace(*format)) - format++; /* skip whitespace */ + format++; /* skip whitespace */ ic = getc(stream); nrchars++; - while (isspace (ic)) { + while (isspace(ic)) + { ic = getc(stream); nrchars++; } - if (ic != EOF) ungetc(ic,stream); + if (ic != EOF) + ungetc(ic, stream); nrchars--; } - if (!*format) break; /* end of format */ + if (!*format) + break; /* end of format */ - if (*format != '%') { + if (*format != '%') + { ic = getc(stream); nrchars++; - if (ic != *format++) { - if (ic != EOF) ungetc(ic,stream); + if (ic != *format++) + { + if (ic != EOF) + ungetc(ic, stream); nrchars--; - break; /* error */ + break; /* error */ } continue; } format++; - if (*format == '%') { + if (*format == '%') + { ic = getc(stream); nrchars++; - if (ic == '%') { + if (ic == '%') + { format++; continue; } - else break; + else + break; } flags = 0; - if (*format == '*') { + if (*format == '*') + { format++; flags |= FL_NOASSIGN; } - if (isdigit (*format)) { + if (isdigit(*format)) + { flags |= FL_WIDTHSPEC; - for (width = 0; isdigit (*format);) + for (width = 0; isdigit(*format);) width = width * 10 + *format++ - '0'; } - switch (*format) { - case 'h': flags |= FL_SHORT; format++; break; - case 'l': flags |= FL_LONG; format++; break; - case 'L': flags |= FL_LONGDOUBLE; format++; break; + switch (*format) + { + case 'h': + flags |= FL_SHORT; + format++; + break; + case 'l': + flags |= FL_LONG; + format++; + break; + case 'L': + flags |= FL_LONGDOUBLE; + format++; + break; } kind = *format; - if ((kind != 'c') && (kind != '[') && (kind != 'n')) { - do { + if ((kind != 'c') && (kind != '[') && (kind != 'n')) + { + do + { ic = getc(stream); nrchars++; } while (isspace(ic)); - if (ic == EOF) break; /* outer while */ - } else if (kind != 'n') { /* %c or %[ */ + if (ic == EOF) + break; /* outer while */ + } + else if (kind != 'n') + { /* %c or %[ */ ic = getc(stream); - if (ic == EOF) break; /* outer while */ + if (ic == EOF) + break; /* outer while */ nrchars++; } - switch (kind) { - default: - /* not recognized, like %q */ - return conv || (ic != EOF) ? done : EOF; - break; - case 'n': - if (!(flags & FL_NOASSIGN)) { /* silly, though */ - if (flags & FL_SHORT) - *va_arg(ap, short *) = (short) nrchars; - else if (flags & FL_LONG) - *va_arg(ap, long *) = (long) nrchars; - else - *va_arg(ap, int *) = (int) nrchars; - } - break; - case 'p': /* pointer */ - set_pointer(flags); + switch (kind) + { + default: + /* not recognized, like %q */ + return conv || (ic != EOF) ? done : EOF; + break; + case 'n': + if (!(flags & FL_NOASSIGN)) + { /* silly, though */ + if (flags & FL_SHORT) + *va_arg(ap, short*) = (short)nrchars; + else if (flags & FL_LONG) + *va_arg(ap, long*) = (long)nrchars; + else + *va_arg(ap, int*) = (int)nrchars; + } + break; + case 'p': /* pointer */ + set_pointer(flags); /* fallthrough */ - case 'b': /* binary */ - case 'd': /* decimal */ - case 'i': /* general integer */ - case 'o': /* octal */ - case 'u': /* unsigned */ - case 'x': /* hexadecimal */ - case 'X': /* ditto */ - if (!(flags & FL_WIDTHSPEC) || width > NUMLEN) - width = NUMLEN; - if (!width) return done; + case 'b': /* binary */ + case 'd': /* decimal */ + case 'i': /* general integer */ + case 'o': /* octal */ + case 'u': /* unsigned */ + case 'x': /* hexadecimal */ + case 'X': /* ditto */ + if (!(flags & FL_WIDTHSPEC) || width > NUMLEN) + width = NUMLEN; + if (!width) + return done; - str = o_collect(ic, stream, kind, width, &base); - if (str < inp_buf - || (str == inp_buf - && (*str == '-' - || *str == '+'))) return done; + str = o_collect(ic, stream, kind, width, &base); + if (str < inp_buf + || (str == inp_buf + && (*str == '-' + || *str == '+'))) + return done; - /* + /* * Although the length of the number is str-inp_buf+1 * we don't add the 1 since we counted it already */ - nrchars += str - inp_buf; + nrchars += str - inp_buf; - if (!(flags & FL_NOASSIGN)) { - if (kind == 'd' || kind == 'i') - val = strtol(inp_buf, &tmp_string, base); - else - val = strtoul(inp_buf, &tmp_string, base); - if (flags & FL_LONG) - *va_arg(ap, unsigned long *) = (unsigned long) val; - else if (flags & FL_SHORT) - *va_arg(ap, unsigned short *) = (unsigned short) val; - else - *va_arg(ap, unsigned *) = (unsigned) val; - } - break; - case 'c': - if (!(flags & FL_WIDTHSPEC)) - width = 1; - if (!(flags & FL_NOASSIGN)) - str = va_arg(ap, char *); - if (!width) return done; - - while (width && ic != EOF) { if (!(flags & FL_NOASSIGN)) - *str++ = (char) ic; - if (--width) { - ic = getc(stream); - nrchars++; + { + if (kind == 'd' || kind == 'i') + val = strtol(inp_buf, &tmp_string, base); + else + val = strtoul(inp_buf, &tmp_string, base); + if (flags & FL_LONG) + *va_arg(ap, unsigned long*) = (unsigned long)val; + else if (flags & FL_SHORT) + *va_arg(ap, unsigned short*) = (unsigned short)val; + else + *va_arg(ap, unsigned*) = (unsigned)val; } - } - - if (width) { - if (ic != EOF) ungetc(ic,stream); - nrchars--; - } - break; - case 's': - if (!(flags & FL_WIDTHSPEC)) - width = 0xffff; - if (!(flags & FL_NOASSIGN)) - str = va_arg(ap, char *); - if (!width) return done; - - while (width && ic != EOF && !isspace(ic)) { + break; + case 'c': + if (!(flags & FL_WIDTHSPEC)) + width = 1; if (!(flags & FL_NOASSIGN)) - *str++ = (char) ic; - if (--width) { - ic = getc(stream); - nrchars++; - } - } - /* terminate the string */ - if (!(flags & FL_NOASSIGN)) - *str = '\0'; - if (width) { - if (ic != EOF) ungetc(ic,stream); - nrchars--; - } - break; - case '[': - if (!(flags & FL_WIDTHSPEC)) - width = 0xffff; - if (!width) return done; + str = va_arg(ap, char*); + if (!width) + return done; - if ( *++format == '^' ) { - reverse = 1; - format++; - } else - reverse = 0; - - for (str = Xtable; str < &Xtable[NR_CHARS] - ; str++) - *str = 0; - - if (*format == ']') Xtable[*format++] = 1; - - while (*format && *format != ']') { - Xtable[*format++] = 1; - if (*format == '-') { - format++; - if (*format - && *format != ']' - && *(format) >= *(format -2)) { - int c; - - for( c = *(format -2) + 1 - ; c <= *format ; c++) - Xtable[c] = 1; - format++; + while (width && ic != EOF) + { + if (!(flags & FL_NOASSIGN)) + *str++ = (char)ic; + if (--width) + { + ic = getc(stream); + nrchars++; } - else Xtable['-'] = 1; } - } - if (!*format || !(Xtable[ic] ^ reverse)) { - if (ic != EOF) ungetc(ic, stream); - return done; - } - if (!(flags & FL_NOASSIGN)) - str = va_arg(ap, char *); - - do { + if (width) + { + if (ic != EOF) + ungetc(ic, stream); + nrchars--; + } + break; + case 's': + if (!(flags & FL_WIDTHSPEC)) + width = 0xffff; if (!(flags & FL_NOASSIGN)) - *str++ = (char) ic; - if (--width) { - ic = getc(stream); - nrchars++; + str = va_arg(ap, char*); + if (!width) + return done; + + while (width && ic != EOF && !isspace(ic)) + { + if (!(flags & FL_NOASSIGN)) + *str++ = (char)ic; + if (--width) + { + ic = getc(stream); + nrchars++; + } } - } while (width && ic != EOF && (Xtable[ic] ^ reverse)); + /* terminate the string */ + if (!(flags & FL_NOASSIGN)) + *str = '\0'; + if (width) + { + if (ic != EOF) + ungetc(ic, stream); + nrchars--; + } + break; + case '[': + if (!(flags & FL_WIDTHSPEC)) + width = 0xffff; + if (!width) + return done; - if (width) { - if (ic != EOF) ungetc(ic, stream); - nrchars--; - } - if (!(flags & FL_NOASSIGN)) { /* terminate string */ - *str = '\0'; - } - break; -#ifndef ACKCONF_NO_STDIO_FLOAT - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - if (!(flags & FL_WIDTHSPEC) || width > NUMLEN) - width = NUMLEN; + if (*++format == '^') + { + reverse = 1; + format++; + } + else + reverse = 0; - if (!width) return done; - str = f_collect(ic, stream, width); + for (str = Xtable; str < &Xtable[NR_CHARS]; str++) + *str = 0; - if (str < inp_buf - || (str == inp_buf - && (*str == '-' - || *str == '+'))) return done; + if (*format == ']') + Xtable[*format++] = 1; - /* + while (*format && *format != ']') + { + Xtable[*format++] = 1; + if (*format == '-') + { + format++; + if (*format + && *format != ']' + && *(format) >= *(format - 2)) + { + int c; + + for (c = *(format - 2) + 1; c <= *format; c++) + Xtable[c] = 1; + format++; + } + else + Xtable['-'] = 1; + } + } + if (!*format || !(Xtable[ic] ^ reverse)) + { + if (ic != EOF) + ungetc(ic, stream); + return done; + } + + if (!(flags & FL_NOASSIGN)) + str = va_arg(ap, char*); + + do + { + if (!(flags & FL_NOASSIGN)) + *str++ = (char)ic; + if (--width) + { + ic = getc(stream); + nrchars++; + } + } while (width && ic != EOF && (Xtable[ic] ^ reverse)); + + if (width) + { + if (ic != EOF) + ungetc(ic, stream); + nrchars--; + } + if (!(flags & FL_NOASSIGN)) + { /* terminate string */ + *str = '\0'; + } + break; +#ifndef ACKCONF_NO_STDIO_FLOAT + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (!(flags & FL_WIDTHSPEC) || width > NUMLEN) + width = NUMLEN; + + if (!width) + return done; + str = f_collect(ic, stream, width); + + if (str < inp_buf + || (str == inp_buf + && (*str == '-' + || *str == '+'))) + return done; + + /* * Although the length of the number is str-inp_buf+1 * we don't add the 1 since we counted it already */ - nrchars += str - inp_buf; + nrchars += str - inp_buf; - if (!(flags & FL_NOASSIGN)) { - ld_val = strtod(inp_buf, &tmp_string); - if (flags & FL_LONGDOUBLE) - *va_arg(ap, long double *) = (long double) ld_val; - else - if (flags & FL_LONG) - *va_arg(ap, double *) = (double) ld_val; - else - *va_arg(ap, float *) = (float) ld_val; - } - break; + if (!(flags & FL_NOASSIGN)) + { + ld_val = strtod(inp_buf, &tmp_string); + if (flags & FL_LONGDOUBLE) + *va_arg(ap, long double*) = (long double)ld_val; + else if (flags & FL_LONG) + *va_arg(ap, double*) = (double)ld_val; + else + *va_arg(ap, float*) = (float)ld_val; + } + break; #endif - } /* end switch */ + } /* end switch */ conv++; - if (!(flags & FL_NOASSIGN) && kind != 'n') done++; + if (!(flags & FL_NOASSIGN) && kind != 'n') + done++; format++; } return conv || (ic != EOF) ? done : EOF; diff --git a/lang/cem/libcc.ansi/stdio/ecvt.c b/lang/cem/libcc.ansi/stdio/ecvt.c index 9a15b5cde..4821fccbc 100644 --- a/lang/cem/libcc.ansi/stdio/ecvt.c +++ b/lang/cem/libcc.ansi/stdio/ecvt.c @@ -1,15 +1,15 @@ /* $Id$ */ -#include "loc_incl.h" +#include "loc_incl.h" #ifndef ACKCONF_NO_STDIO_FLOAT -#include "../stdlib/ext_fmt.h" -void _dbl_ext_cvt(double value, struct EXTEND *e); -char *_ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int * sign, int ecvtflag); +#include "../stdlib/ext_fmt.h" +void _dbl_ext_cvt(double value, struct EXTEND* e); +char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag); -static char * -cvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag) +static char* +cvt(long double value, int ndigit, int* decpt, int* sign, int ecvtflag) { struct EXTEND e; @@ -17,17 +17,15 @@ cvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag) return _ext_str_cvt(&e, ndigit, decpt, sign, ecvtflag); } -char * -_ecvt(long double value, int ndigit, int *decpt, int *sign) +char* _ecvt(long double value, int ndigit, int* decpt, int* sign) { return cvt(value, ndigit, decpt, sign, 1); } -char * -_fcvt(long double value, int ndigit, int *decpt, int *sign) +char* _fcvt(long double value, int ndigit, int* decpt, int* sign) { return cvt(value, ndigit, decpt, sign, 0); } -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif /* ACKCONF_NO_STDIO_FLOAT */ diff --git a/lang/cem/libcc.ansi/stdio/fclose.c b/lang/cem/libcc.ansi/stdio/fclose.c index 0003535a7..7ed925251 100644 --- a/lang/cem/libcc.ansi/stdio/fclose.c +++ b/lang/cem/libcc.ansi/stdio/fclose.c @@ -8,23 +8,25 @@ #include #include "loc_incl.h" -int -fclose(FILE *fp) +int fclose(FILE* fp) { register int i, retval = 0; - for (i=0; i= FOPEN_MAX) return EOF; - if (fflush(fp)) retval = EOF; - if (close(fileno(fp))) retval = EOF; - if ( io_testflag(fp,_IOMYBUF) && fp->_buf ) - free((void *)fp->_buf); + if (fflush(fp)) + retval = EOF; + if (close(fileno(fp))) + retval = EOF; + if (io_testflag(fp, _IOMYBUF) && fp->_buf) + free((void*)fp->_buf); if (fp != stdin && fp != stdout && fp != stderr) - free((void *)fp); + free((void*)fp); return retval; } diff --git a/lang/cem/libcc.ansi/stdio/fdopen.c b/lang/cem/libcc.ansi/stdio/fdopen.c index a665ddd3f..d6b46bafe 100644 --- a/lang/cem/libcc.ansi/stdio/fdopen.c +++ b/lang/cem/libcc.ansi/stdio/fdopen.c @@ -3,50 +3,54 @@ */ /* $Id$ */ -#include -#include -#include "../stdio/loc_incl.h" +#include +#include +#include "../stdio/loc_incl.h" -FILE * -fdopen(int fd, const char *mode) +FILE* fdopen(int fd, const char* mode) { register int i; - FILE *stream; + FILE* stream; int flags = 0; - if (fd < 0) return (FILE *)NULL; - for (i = 0; __iotab[i] != 0 ; i++) - if (i >= FOPEN_MAX-1) - return (FILE *)NULL; + if (fd < 0) + return (FILE*)NULL; + for (i = 0; __iotab[i] != 0; i++) + if (i >= FOPEN_MAX - 1) + return (FILE*)NULL; - switch(*mode++) { - case 'r': - flags |= _IOREAD | _IOREADING; - break; - case 'a': - flags |= _IOAPPEND; - case 'w': - flags |= _IOWRITE | _IOWRITING; - break; - default: - return (FILE *)NULL; - } - while(*mode) { - switch(*mode++) { - case 'b': - continue; - case '+': - flags |= _IOREAD | _IOWRITE; - continue; - /* The sequence may be followed by aditional characters */ - default: + switch (*mode++) + { + case 'r': + flags |= _IOREAD | _IOREADING; break; + case 'a': + flags |= _IOAPPEND; + case 'w': + flags |= _IOWRITE | _IOWRITING; + break; + default: + return (FILE*)NULL; + } + while (*mode) + { + switch (*mode++) + { + case 'b': + continue; + case '+': + flags |= _IOREAD | _IOWRITE; + continue; + /* The sequence may be followed by aditional characters */ + default: + break; } break; } - if ((stream = (FILE *) malloc(sizeof(FILE))) == NULL) { - return (FILE *)NULL; + if ((stream = (FILE*)malloc(sizeof(FILE))) == NULL) + { + return (FILE*)NULL; } if ((flags & _IOREAD) && (flags & _IOWRITE)) diff --git a/lang/cem/libcc.ansi/stdio/feof.c b/lang/cem/libcc.ansi/stdio/feof.c index 5c7d4a74c..550792f36 100644 --- a/lang/cem/libcc.ansi/stdio/feof.c +++ b/lang/cem/libcc.ansi/stdio/feof.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(feof)(FILE *stream) +int(feof)(FILE* stream) { return feof(stream); } diff --git a/lang/cem/libcc.ansi/stdio/ferror.c b/lang/cem/libcc.ansi/stdio/ferror.c index 44880785d..d0271f0eb 100644 --- a/lang/cem/libcc.ansi/stdio/ferror.c +++ b/lang/cem/libcc.ansi/stdio/ferror.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(ferror)(FILE *stream) +int(ferror)(FILE* stream) { return ferror(stream); } diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c index 573764fd4..f5ef6c355 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -8,67 +8,71 @@ #include #include "loc_incl.h" -int -fflush(FILE *stream) +int fflush(FILE* stream) { int count, c1, i, retval = 0; - if (!stream) { - for(i= 0; i < FOPEN_MAX; i++) - if (__iotab[i] && fflush(__iotab[i])) - retval = EOF; - return retval; + if (!stream) + { + for (i = 0; i < FOPEN_MAX; i++) + if (__iotab[i] && fflush(__iotab[i])) + retval = EOF; + return retval; } if (!stream->_buf || (!io_testflag(stream, _IOREADING) - && !io_testflag(stream, _IOWRITING))) + && !io_testflag(stream, _IOWRITING))) return 0; - if (io_testflag(stream, _IOREADING)) { + if (io_testflag(stream, _IOREADING)) + { /* (void) fseek(stream, 0L, SEEK_CUR); */ int adjust = 0; - if (stream->_buf && !io_testflag(stream,_IONBF)) + if (stream->_buf && !io_testflag(stream, _IONBF)) adjust = stream->_count; stream->_count = 0; - lseek(fileno(stream), (off_t) adjust, SEEK_CUR); + lseek(fileno(stream), (off_t)adjust, SEEK_CUR); if (io_testflag(stream, _IOWRITE)) stream->_flags &= ~(_IOREADING | _IOWRITING); stream->_ptr = stream->_buf; return 0; - } else if (io_testflag(stream, _IONBF)) return 0; + } + else if (io_testflag(stream, _IONBF)) + return 0; - if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */ + if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */ stream->_flags &= ~_IOWRITING; count = stream->_ptr - stream->_buf; stream->_ptr = stream->_buf; - if ( count <= 0 ) + if (count <= 0) return 0; - if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (io_testflag(stream, _IOAPPEND)) + { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) + { stream->_flags |= _IOERR; return EOF; } } - c1 = write(stream->_fd, (char *)stream->_buf, count); + c1 = write(stream->_fd, (char*)stream->_buf, count); stream->_count = 0; - if ( count == c1 ) + if (count == c1) return 0; stream->_flags |= _IOERR; - return EOF; + return EOF; } -void -__cleanup(void) +void __cleanup(void) { register int i; - for(i= 0; i < FOPEN_MAX; i++) + for (i = 0; i < FOPEN_MAX; i++) if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING)) - (void) fflush(__iotab[i]); + (void)fflush(__iotab[i]); } diff --git a/lang/cem/libcc.ansi/stdio/fgetc.c b/lang/cem/libcc.ansi/stdio/fgetc.c index 9e3df5016..08e7ca461 100644 --- a/lang/cem/libcc.ansi/stdio/fgetc.c +++ b/lang/cem/libcc.ansi/stdio/fgetc.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -fgetc(FILE *stream) +int fgetc(FILE* stream) { return getc(stream); } diff --git a/lang/cem/libcc.ansi/stdio/fgetpos.c b/lang/cem/libcc.ansi/stdio/fgetpos.c index 20ff8bed5..687fbef17 100644 --- a/lang/cem/libcc.ansi/stdio/fgetpos.c +++ b/lang/cem/libcc.ansi/stdio/fgetpos.c @@ -3,12 +3,12 @@ */ /* $Id$ */ -#include +#include -int -fgetpos(FILE *stream, fpos_t *pos) +int fgetpos(FILE* stream, fpos_t* pos) { *pos = ftell(stream); - if (*pos == -1) return -1; + if (*pos == -1) + return -1; return 0; } diff --git a/lang/cem/libcc.ansi/stdio/fgets.c b/lang/cem/libcc.ansi/stdio/fgets.c index c5476429d..6f4890e0c 100644 --- a/lang/cem/libcc.ansi/stdio/fgets.c +++ b/lang/cem/libcc.ansi/stdio/fgets.c @@ -3,24 +3,29 @@ */ /* $Id$ */ -#include +#include -char * -fgets(char *s, register int n, register FILE *stream) +char* fgets(char* s, register int n, register FILE* stream) { register int ch; - register char *ptr; + register char* ptr; ptr = s; - while (--n > 0 && (ch = getc(stream)) != EOF) { + while (--n > 0 && (ch = getc(stream)) != EOF) + { *ptr++ = ch; - if ( ch == '\n') + if (ch == '\n') break; } - if (ch == EOF) { - if (feof(stream)) { - if (ptr == s) return NULL; - } else return NULL; + if (ch == EOF) + { + if (feof(stream)) + { + if (ptr == s) + return NULL; + } + else + return NULL; } *ptr = '\0'; return s; diff --git a/lang/cem/libcc.ansi/stdio/fileno.c b/lang/cem/libcc.ansi/stdio/fileno.c index b36b7cf29..eef38788a 100644 --- a/lang/cem/libcc.ansi/stdio/fileno.c +++ b/lang/cem/libcc.ansi/stdio/fileno.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(fileno)(FILE *stream) +int(fileno)(FILE* stream) { return stream->_fd; } diff --git a/lang/cem/libcc.ansi/stdio/fillbuf.c b/lang/cem/libcc.ansi/stdio/fillbuf.c index d01e208bf..c323da4cd 100644 --- a/lang/cem/libcc.ansi/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/stdio/fillbuf.c @@ -8,57 +8,67 @@ #include #include "loc_incl.h" -int -__fillbuf(register FILE *stream) +int __fillbuf(register FILE* stream) { static unsigned char ch[FOPEN_MAX]; register int i; stream->_count = 0; - if (fileno(stream) < 0) return EOF; - if (io_testflag(stream, _IOEOF)) return EOF; - if (!io_testflag(stream, _IOREAD)) { + if (fileno(stream) < 0) + return EOF; + if (io_testflag(stream, _IOEOF)) + return EOF; + if (!io_testflag(stream, _IOREAD)) + { stream->_flags |= _IOERR; return EOF; } - if (io_testflag(stream, _IOWRITING)) { + if (io_testflag(stream, _IOWRITING)) + { stream->_flags |= _IOERR; return EOF; } if (!io_testflag(stream, _IOREADING)) stream->_flags |= _IOREADING; - - if (!io_testflag(stream, _IONBF) && !stream->_buf) { - stream->_buf = (unsigned char *) malloc(BUFSIZ); - if (!stream->_buf) { + + if (!io_testflag(stream, _IONBF) && !stream->_buf) + { + stream->_buf = (unsigned char*)malloc(BUFSIZ); + if (!stream->_buf) + { stream->_flags |= _IONBF; } - else { + else + { stream->_flags |= _IOMYBUF; stream->_bufsiz = BUFSIZ; } } /* flush line-buffered output when filling an input buffer */ - for (i = 0; i < FOPEN_MAX; i++) { + for (i = 0; i < FOPEN_MAX; i++) + { if (__iotab[i] && io_testflag(__iotab[i], _IOLBF)) if (io_testflag(__iotab[i], _IOWRITING)) - (void) fflush(__iotab[i]); + (void)fflush(__iotab[i]); } - if (!stream->_buf) { + if (!stream->_buf) + { stream->_buf = &ch[fileno(stream)]; stream->_bufsiz = 1; } stream->_ptr = stream->_buf; - stream->_count = read(stream->_fd, (char *)stream->_buf, stream->_bufsiz); + stream->_count = read(stream->_fd, (char*)stream->_buf, stream->_bufsiz); - if (stream->_count <= 0){ - if (stream->_count == 0) { + if (stream->_count <= 0) + { + if (stream->_count == 0) + { stream->_flags |= _IOEOF; } - else + else stream->_flags |= _IOERR; return EOF; diff --git a/lang/cem/libcc.ansi/stdio/fltpr.c b/lang/cem/libcc.ansi/stdio/fltpr.c index ad8e16d46..091111949 100644 --- a/lang/cem/libcc.ansi/stdio/fltpr.c +++ b/lang/cem/libcc.ansi/stdio/fltpr.c @@ -3,16 +3,16 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -#ifndef ACKCONF_NO_STDIO_FLOAT +#ifndef ACKCONF_NO_STDIO_FLOAT -static char * -_pfloat(long double r, register char *s, int n, int flags) +static char* +_pfloat(long double r, register char* s, int n, int flags) { - register char *s1; + register char* s1; int sign, dp; register int i; @@ -24,29 +24,34 @@ _pfloat(long double r, register char *s, int n, int flags) else if (flags & FL_SPACE) *s++ = ' '; - if (dp<=0) + if (dp <= 0) *s++ = '0'; - for (i=dp; i>0; i--) - if (*s1) *s++ = *s1++; - else *s++ = '0'; - if (((i=n) > 0) || (flags & FL_ALT)) + for (i = dp; i > 0; i--) + if (*s1) + *s++ = *s1++; + else + *s++ = '0'; + if (((i = n) > 0) || (flags & FL_ALT)) *s++ = '.'; - while (++dp <= 0) { - if (--i<0) + while (++dp <= 0) + { + if (--i < 0) break; *s++ = '0'; } while (--i >= 0) - if (*s1) *s++ = *s1++; - else *s++ = '0'; + if (*s1) + *s++ = *s1++; + else + *s++ = '0'; return s; } -static char * -_pscien(long double r, register char *s, int n, int flags) +static char* +_pscien(long double r, register char* s, int n, int flags) { - int sign, dp; - register char *s1; + int sign, dp; + register char* s1; s1 = _ecvt(r, n + 1, &dp, &sign); if (sign) @@ -60,30 +65,38 @@ _pscien(long double r, register char *s, int n, int flags) if ((n > 0) || (flags & FL_ALT)) *s++ = '.'; while (--n >= 0) - if (*s1) *s++ = *s1++; - else *s++ = '0'; + if (*s1) + *s++ = *s1++; + else + *s++ = '0'; *s++ = 'e'; - if ( r != 0 ) --dp ; - if ( dp<0 ) { - *s++ = '-' ; dp= -dp ; - } else { - *s++ = '+' ; + if (r != 0) + --dp; + if (dp < 0) + { + *s++ = '-'; + dp = -dp; } - if (dp >= 100) { + else + { + *s++ = '+'; + } + if (dp >= 100) + { *s++ = '0' + (dp / 100); dp %= 100; } - *s++ = '0' + (dp/10); - *s++ = '0' + (dp%10); + *s++ = '0' + (dp / 10); + *s++ = '0' + (dp % 10); return s; } -#define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2) -#define LOW_EXP -4 -#define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1)) +#define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2) +#define LOW_EXP -4 +#define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1)) -static char * -_gcvt(long double value, int ndigit, char *s, int flags) +static char* +_gcvt(long double value, int ndigit, char* s, int flags) { int sign, dp; register char *s1, *s2; @@ -92,7 +105,8 @@ _gcvt(long double value, int ndigit, char *s, int flags) s1 = _ecvt(value, ndigit, &dp, &sign); s2 = s; - if (sign) *s2++ = '-'; + if (sign) + *s2++ = '-'; else if (flags & FL_SIGN) *s2++ = '+'; else if (flags & FL_SPACE) @@ -102,78 +116,97 @@ _gcvt(long double value, int ndigit, char *s, int flags) for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) nndigit--; - if (USE_EXP(dp,ndigit)) { + if (USE_EXP(dp, ndigit)) + { /* Use E format */ dp--; *s2++ = *s1++; - if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.'; - while (--nndigit > 0) *s2++ = *s1++; + if ((nndigit > 1) || (flags & FL_ALT)) + *s2++ = '.'; + while (--nndigit > 0) + *s2++ = *s1++; *s2++ = 'e'; - if (dp < 0) { + if (dp < 0) + { *s2++ = '-'; dp = -dp; } - else *s2++ = '+'; + else + *s2++ = '+'; s2 += NDIGINEXP(dp); *s2 = 0; - for (i = NDIGINEXP(dp); i > 0; i--) { + for (i = NDIGINEXP(dp); i > 0; i--) + { *--s2 = dp % 10 + '0'; dp /= 10; } return s; } /* Use f format */ - if (dp <= 0) { - if (*s1 != '0') { + if (dp <= 0) + { + if (*s1 != '0') + { /* otherwise the whole number is 0 */ *s2++ = '0'; *s2++ = '.'; } - while (dp < 0) { + while (dp < 0) + { dp++; *s2++ = '0'; } } - for (i = 1; i <= nndigit; i++) { + for (i = 1; i <= nndigit; i++) + { *s2++ = *s1++; - if (i == dp) *s2++ = '.'; + if (i == dp) + *s2++ = '.'; } - if (i <= dp) { - while (i++ <= dp) *s2++ = '0'; + if (i <= dp) + { + while (i++ <= dp) + *s2++ = '0'; *s2++ = '.'; } - if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--; + if ((s2[-1] == '.') && !(flags & FL_ALT)) + s2--; *s2 = '\0'; return s; } -char * -_f_print(va_list *ap, int flags, char *s, char c, int precision) +char* _f_print(va_list* ap, int flags, char* s, char c, int precision) { - register char *old_s = s; + register char* old_s = s; long double ld_val; - if (flags & FL_LONGDOUBLE) ld_val = va_arg(*ap, long double); - else ld_val = (long double) va_arg(*ap, double); + if (flags & FL_LONGDOUBLE) + ld_val = va_arg(*ap, long double); + else + ld_val = (long double)va_arg(*ap, double); - switch(c) { - case 'f': - s = _pfloat(ld_val, s, precision, flags); - break; - case 'e': - case 'E': - s = _pscien(ld_val, s, precision , flags); - break; - case 'g': - case 'G': - s = _gcvt(ld_val, precision, s, flags); - s += strlen(s); - break; + switch (c) + { + case 'f': + s = _pfloat(ld_val, s, precision, flags); + break; + case 'e': + case 'E': + s = _pscien(ld_val, s, precision, flags); + break; + case 'g': + case 'G': + s = _gcvt(ld_val, precision, s, flags); + s += strlen(s); + break; } - if ( c == 'E' || c == 'G') { - while (*old_s && *old_s != 'e') old_s++; - if (*old_s == 'e') *old_s = 'E'; + if (c == 'E' || c == 'G') + { + while (*old_s && *old_s != 'e') + old_s++; + if (*old_s == 'e') + *old_s = 'E'; } return s; } -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif /* ACKCONF_NO_STDIO_FLOAT */ diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c index 22340e2e3..9518de70d 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -11,107 +11,136 @@ extern void (*_clean)(void); static int -do_write(int d, char *buf, int nbytes) +do_write(int d, char* buf, int nbytes) { int c; /* POSIX actually allows write() to return a positive value less than nbytes, so loop ... */ - while ((c = write(d, buf, nbytes)) > 0 && c < nbytes) { + while ((c = write(d, buf, nbytes)) > 0 && c < nbytes) + { nbytes -= c; buf += c; } return c > 0; } -int -__flushbuf(int c, FILE * stream) +int __flushbuf(int c, FILE* stream) { _clean = __cleanup; - if (fileno(stream) < 0) return EOF; - if (!io_testflag(stream, _IOWRITE)) return EOF; - if (io_testflag(stream, _IOREADING) && !feof(stream)) return EOF; + if (fileno(stream) < 0) + return EOF; + if (!io_testflag(stream, _IOWRITE)) + return EOF; + if (io_testflag(stream, _IOREADING) && !feof(stream)) + return EOF; stream->_flags &= ~_IOREADING; stream->_flags |= _IOWRITING; - if (!io_testflag(stream, _IONBF)) { - if (!stream->_buf) { - if (stream == stdout && isatty(fileno(stdout))) { - if (!(stream->_buf = - (unsigned char *) malloc(BUFSIZ))) { + if (!io_testflag(stream, _IONBF)) + { + if (!stream->_buf) + { + if (stream == stdout && isatty(fileno(stdout))) + { + if (!(stream->_buf = (unsigned char*)malloc(BUFSIZ))) + { stream->_flags |= _IONBF; - } else { - stream->_flags |= _IOLBF|_IOMYBUF; + } + else + { + stream->_flags |= _IOLBF | _IOMYBUF; stream->_bufsiz = BUFSIZ; stream->_count = -1; } - } else { - if (!(stream->_buf = - (unsigned char *) malloc(BUFSIZ))) { + } + else + { + if (!(stream->_buf = (unsigned char*)malloc(BUFSIZ))) + { stream->_flags |= _IONBF; - } else { + } + else + { stream->_flags |= _IOMYBUF; stream->_bufsiz = BUFSIZ; if (!io_testflag(stream, _IOLBF)) stream->_count = BUFSIZ - 1; - else stream->_count = -1; + else + stream->_count = -1; } } stream->_ptr = stream->_buf; } } - if (io_testflag(stream, _IONBF)) { + if (io_testflag(stream, _IONBF)) + { char c1 = c; stream->_count = 0; - if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (io_testflag(stream, _IOAPPEND)) + { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) + { stream->_flags |= _IOERR; return EOF; } } - if (write(fileno(stream), &c1, 1) != 1) { + if (write(fileno(stream), &c1, 1) != 1) + { stream->_flags |= _IOERR; return EOF; } - return (unsigned char) c; - } else if (io_testflag(stream, _IOLBF)) { + return (unsigned char)c; + } + else if (io_testflag(stream, _IOLBF)) + { *stream->_ptr++ = c; /* stream->_count has been updated in putc macro. */ - if (c == '\n' || stream->_count == -stream->_bufsiz) { + if (c == '\n' || stream->_count == -stream->_bufsiz) + { int count = -stream->_count; - stream->_ptr = stream->_buf; + stream->_ptr = stream->_buf; stream->_count = 0; - if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (io_testflag(stream, _IOAPPEND)) + { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) + { stream->_flags |= _IOERR; return EOF; } } - if (! do_write(fileno(stream), (char *)stream->_buf, - count)) { + if (!do_write(fileno(stream), (char*)stream->_buf, + count)) + { stream->_flags |= _IOERR; return EOF; } } - } else { + } + else + { int count = stream->_ptr - stream->_buf; stream->_count = stream->_bufsiz - 1; stream->_ptr = stream->_buf + 1; - if (count > 0) { - if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (count > 0) + { + if (io_testflag(stream, _IOAPPEND)) + { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) + { stream->_flags |= _IOERR; return EOF; } } - if (! do_write(fileno(stream), (char *)stream->_buf, count)) { + if (!do_write(fileno(stream), (char*)stream->_buf, count)) + { *(stream->_buf) = c; stream->_flags |= _IOERR; return EOF; @@ -119,5 +148,5 @@ __flushbuf(int c, FILE * stream) } *(stream->_buf) = c; } - return (unsigned char) c; + return (unsigned char)c; } diff --git a/lang/cem/libcc.ansi/stdio/fopen.c b/lang/cem/libcc.ansi/stdio/fopen.c index a0bd9f40c..e3b935494 100644 --- a/lang/cem/libcc.ansi/stdio/fopen.c +++ b/lang/cem/libcc.ansi/stdio/fopen.c @@ -10,7 +10,7 @@ #include #include "loc_incl.h" -#define PMODE 0666 +#define PMODE 0666 /* Since the O_CREAT flag is not available on all systems, we can't get it * from the standard library. Furthermore, even if we know that @@ -31,48 +31,50 @@ * Remember to fix freopen.c if changing this. */ -FILE * -fopen(const char *name, const char *mode) +FILE* fopen(const char* name, const char* mode) { register int i; int rwmode = 0, rwflags = 0; - FILE *stream; + FILE* stream; int fd, flags = 0; - for (i = 0; __iotab[i] != 0 ; i++) - if ( i >= FOPEN_MAX-1 ) - return (FILE *)NULL; + for (i = 0; __iotab[i] != 0; i++) + if (i >= FOPEN_MAX - 1) + return (FILE*)NULL; - switch(*mode++) { - case 'r': - flags |= _IOREAD | _IOREADING; - rwmode = O_RDONLY; - break; - case 'w': - flags |= _IOWRITE | _IOWRITING; - rwmode = O_WRONLY; - rwflags = O_CREAT | O_TRUNC; - break; - case 'a': - flags |= _IOWRITE | _IOWRITING | _IOAPPEND; - rwmode = O_WRONLY; - rwflags |= O_APPEND | O_CREAT; - break; - default: - return (FILE *)NULL; + switch (*mode++) + { + case 'r': + flags |= _IOREAD | _IOREADING; + rwmode = O_RDONLY; + break; + case 'w': + flags |= _IOWRITE | _IOWRITING; + rwmode = O_WRONLY; + rwflags = O_CREAT | O_TRUNC; + break; + case 'a': + flags |= _IOWRITE | _IOWRITING | _IOAPPEND; + rwmode = O_WRONLY; + rwflags |= O_APPEND | O_CREAT; + break; + default: + return (FILE*)NULL; } - while (*mode) { - switch(*mode++) { - case 'b': - continue; - case '+': - rwmode = O_RDWR; - flags |= _IOREAD | _IOWRITE; - continue; - /* The sequence may be followed by additional characters */ - default: - break; + while (*mode) + { + switch (*mode++) + { + case 'b': + continue; + case '+': + rwmode = O_RDWR; + flags |= _IOREAD | _IOWRITE; + continue; + /* The sequence may be followed by additional characters */ + default: + break; } break; } @@ -82,22 +84,25 @@ fopen(const char *name, const char *mode) */ if ((rwflags & O_TRUNC) || (((fd = open(name, rwmode)) < 0) - && (rwflags & O_CREAT))) { - if (((fd = creat(name, PMODE)) > 0) && flags | _IOREAD) { - (void) close(fd); + && (rwflags & O_CREAT))) + { + if (((fd = creat(name, PMODE)) > 0) && flags | _IOREAD) + { + (void)close(fd); fd = open(name, rwmode); } - } - if (fd < 0) return (FILE *)NULL; + if (fd < 0) + return (FILE*)NULL; - if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) { + if ((stream = (FILE*)malloc(sizeof(FILE))) == NULL) + { close(fd); - return (FILE *)NULL; + return (FILE*)NULL; } - if ((flags & (_IOREAD | _IOWRITE)) == (_IOREAD | _IOWRITE)) + if ((flags & (_IOREAD | _IOWRITE)) == (_IOREAD | _IOWRITE)) flags &= ~(_IOREADING | _IOWRITING); stream->_count = 0; diff --git a/lang/cem/libcc.ansi/stdio/fprintf.c b/lang/cem/libcc.ansi/stdio/fprintf.c index 6caeee311..cdcb16fee 100644 --- a/lang/cem/libcc.ansi/stdio/fprintf.c +++ b/lang/cem/libcc.ansi/stdio/fprintf.c @@ -3,19 +3,18 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -fprintf(FILE *stream, const char *format, ...) +int fprintf(FILE* stream, const char* format, ...) { va_list ap; int retval; - + va_start(ap, format); - retval = _doprnt (format, ap, stream); + retval = _doprnt(format, ap, stream); va_end(ap); diff --git a/lang/cem/libcc.ansi/stdio/fputc.c b/lang/cem/libcc.ansi/stdio/fputc.c index 334a34151..a0ac05c82 100644 --- a/lang/cem/libcc.ansi/stdio/fputc.c +++ b/lang/cem/libcc.ansi/stdio/fputc.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -fputc(int c, FILE *stream) +int fputc(int c, FILE* stream) { return putc(c, stream); } diff --git a/lang/cem/libcc.ansi/stdio/fputs.c b/lang/cem/libcc.ansi/stdio/fputs.c index cd1ce3362..8b1f33397 100644 --- a/lang/cem/libcc.ansi/stdio/fputs.c +++ b/lang/cem/libcc.ansi/stdio/fputs.c @@ -3,16 +3,17 @@ */ /* $Id$ */ -#include +#include -int -fputs(register const char *s, register FILE *stream) +int fputs(register const char* s, register FILE* stream) { register int i = 0; - while (*s) - if (putc(*s++, stream) == EOF) return EOF; - else i++; + while (*s) + if (putc(*s++, stream) == EOF) + return EOF; + else + i++; return i; } diff --git a/lang/cem/libcc.ansi/stdio/fread.c b/lang/cem/libcc.ansi/stdio/fread.c index f4ac6b9d4..cf0806345 100644 --- a/lang/cem/libcc.ansi/stdio/fread.c +++ b/lang/cem/libcc.ansi/stdio/fread.c @@ -3,20 +3,22 @@ */ /* $Id$ */ -#include +#include size_t -fread(void *ptr, size_t size, size_t nmemb, register FILE *stream) +fread(void* ptr, size_t size, size_t nmemb, register FILE* stream) { - register char *cp = ptr; + register char* cp = ptr; register int c; size_t ndone = 0; register size_t s; if (size) - while ( ndone < nmemb ) { + while (ndone < nmemb) + { s = size; - do { + do + { if ((c = getc(stream)) != EOF) *cp++ = c; else diff --git a/lang/cem/libcc.ansi/stdio/freopen.c b/lang/cem/libcc.ansi/stdio/freopen.c index b51acba83..3f4e0a169 100644 --- a/lang/cem/libcc.ansi/stdio/freopen.c +++ b/lang/cem/libcc.ansi/stdio/freopen.c @@ -9,75 +9,82 @@ #include #include "loc_incl.h" -#define PMODE 0666 +#define PMODE 0666 /* Do not "optimize" this file to use the open with O_CREAT if the file * does not exist. The reason is given in fopen.c. */ -FILE * -freopen(const char *name, const char *mode, FILE *stream) +FILE* freopen(const char* name, const char* mode, FILE* stream) { register int i; int rwmode = 0, rwflags = 0; int fd, flags = stream->_flags & (_IONBF | _IOFBF | _IOLBF | _IOMYBUF); - (void) fflush(stream); /* ignore errors */ - (void) close(fileno(stream)); + (void)fflush(stream); /* ignore errors */ + (void)close(fileno(stream)); - switch(*mode++) { - case 'r': - flags |= _IOREAD; - rwmode = O_RDONLY; - break; - case 'w': - flags |= _IOWRITE; - rwmode = O_WRONLY; - rwflags = O_CREAT | O_TRUNC; - break; - case 'a': - flags |= _IOWRITE | _IOAPPEND; - rwmode = O_WRONLY; - rwflags |= O_APPEND | O_CREAT; - break; - default: - return (FILE *)NULL; + switch (*mode++) + { + case 'r': + flags |= _IOREAD; + rwmode = O_RDONLY; + break; + case 'w': + flags |= _IOWRITE; + rwmode = O_WRONLY; + rwflags = O_CREAT | O_TRUNC; + break; + case 'a': + flags |= _IOWRITE | _IOAPPEND; + rwmode = O_WRONLY; + rwflags |= O_APPEND | O_CREAT; + break; + default: + return (FILE*)NULL; } - while (*mode) { - switch(*mode++) { - case 'b': - continue; - case '+': - rwmode = O_RDWR; - flags |= _IOREAD | _IOWRITE; - continue; - /* The sequence may be followed by aditional characters */ - default: - break; + while (*mode) + { + switch (*mode++) + { + case 'b': + continue; + case '+': + rwmode = O_RDWR; + flags |= _IOREAD | _IOWRITE; + continue; + /* The sequence may be followed by aditional characters */ + default: + break; } break; } if ((rwflags & O_TRUNC) || (((fd = open(name, rwmode)) < 0) - && (rwflags & O_CREAT))) { - if (((fd = creat(name, PMODE)) < 0) && flags | _IOREAD) { - (void) close(fd); + && (rwflags & O_CREAT))) + { + if (((fd = creat(name, PMODE)) < 0) && flags | _IOREAD) + { + (void)close(fd); fd = open(name, rwmode); } } - if (fd < 0) { - for( i = 0; i < FOPEN_MAX; i++) { - if (stream == __iotab[i]) { + if (fd < 0) + { + for (i = 0; i < FOPEN_MAX; i++) + { + if (stream == __iotab[i]) + { __iotab[i] = 0; break; } } if (stream != stdin && stream != stdout && stream != stderr) - free((void *)stream); - return (FILE *)NULL; + free((void*)stream); + return (FILE*)NULL; } stream->_count = 0; diff --git a/lang/cem/libcc.ansi/stdio/fscanf.c b/lang/cem/libcc.ansi/stdio/fscanf.c index 25349b24e..05e69af50 100644 --- a/lang/cem/libcc.ansi/stdio/fscanf.c +++ b/lang/cem/libcc.ansi/stdio/fscanf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -fscanf(FILE *stream, const char *format, ...) +int fscanf(FILE* stream, const char* format, ...) { va_list ap; int retval; diff --git a/lang/cem/libcc.ansi/stdio/fseek.c b/lang/cem/libcc.ansi/stdio/fseek.c index 83d7640a3..2ab275cdc 100644 --- a/lang/cem/libcc.ansi/stdio/fseek.c +++ b/lang/cem/libcc.ansi/stdio/fseek.c @@ -8,8 +8,7 @@ #include #include "loc_incl.h" -int -fseek(FILE *stream, long int offset, int whence) +int fseek(FILE* stream, long int offset, int whence) { int adjust = 0; long pos; @@ -17,16 +16,20 @@ fseek(FILE *stream, long int offset, int whence) stream->_flags &= ~(_IOEOF | _IOERR); /* Clear both the end of file and error flags */ - if (io_testflag(stream, _IOREADING)) { + if (io_testflag(stream, _IOREADING)) + { if (whence == SEEK_CUR && stream->_buf - && !io_testflag(stream,_IONBF)) + && !io_testflag(stream, _IONBF)) adjust = stream->_count; stream->_count = 0; - } else if (io_testflag(stream,_IOWRITING)) { + } + else if (io_testflag(stream, _IOWRITING)) + { fflush(stream); - } else /* neither reading nor writing. The buffer must be empty */ - /* EMPTY */ ; + } + else /* neither reading nor writing. The buffer must be empty */ + /* EMPTY */; pos = lseek(fileno(stream), offset - adjust, whence); if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE)) diff --git a/lang/cem/libcc.ansi/stdio/fsetpos.c b/lang/cem/libcc.ansi/stdio/fsetpos.c index a2a06ce0b..629abeed6 100644 --- a/lang/cem/libcc.ansi/stdio/fsetpos.c +++ b/lang/cem/libcc.ansi/stdio/fsetpos.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -fsetpos(FILE *stream, fpos_t *pos) +int fsetpos(FILE* stream, fpos_t* pos) { return fseek(stream, *pos, SEEK_SET); } diff --git a/lang/cem/libcc.ansi/stdio/ftell.c b/lang/cem/libcc.ansi/stdio/ftell.c index 54c266c38..1fcbca25f 100644 --- a/lang/cem/libcc.ansi/stdio/ftell.c +++ b/lang/cem/libcc.ansi/stdio/ftell.c @@ -6,26 +6,27 @@ #include #include #include -#include "loc_incl.h" +#include "loc_incl.h" -long ftell(FILE *stream) +long ftell(FILE* stream) { long result; int adjust = 0; - if (io_testflag(stream,_IOREADING)) + if (io_testflag(stream, _IOREADING)) adjust = -stream->_count; - else if (io_testflag(stream,_IOWRITING) - && stream->_buf - && !io_testflag(stream,_IONBF)) + else if (io_testflag(stream, _IOWRITING) + && stream->_buf + && !io_testflag(stream, _IONBF)) adjust = stream->_ptr - stream->_buf; - else adjust = 0; + else + adjust = 0; result = lseek(fileno(stream), 0, SEEK_CUR); - if ( result == -1 ) + if (result == -1) return result; - result += (long) adjust; + result += (long)adjust; return result; } diff --git a/lang/cem/libcc.ansi/stdio/fwrite.c b/lang/cem/libcc.ansi/stdio/fwrite.c index ed9a89f66..325257174 100644 --- a/lang/cem/libcc.ansi/stdio/fwrite.c +++ b/lang/cem/libcc.ansi/stdio/fwrite.c @@ -3,26 +3,27 @@ */ /* $Id$ */ -#include +#include size_t -fwrite(const void *ptr, size_t size, size_t nmemb, - register FILE *stream) +fwrite(const void* ptr, size_t size, size_t nmemb, + register FILE* stream) { - register const unsigned char *cp = ptr; + register const unsigned char* cp = ptr; register size_t s; size_t ndone = 0; if (size) - while ( ndone < nmemb ) { + while (ndone < nmemb) + { s = size; - do { + do + { if (putc((int)*cp, stream) - == EOF) + == EOF) return ndone; cp++; - } - while (--s); + } while (--s); ndone++; } return ndone; diff --git a/lang/cem/libcc.ansi/stdio/getc.c b/lang/cem/libcc.ansi/stdio/getc.c index bd5e8cb77..20bdfa9f9 100644 --- a/lang/cem/libcc.ansi/stdio/getc.c +++ b/lang/cem/libcc.ansi/stdio/getc.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(getc)(FILE *stream) +int(getc)(FILE* stream) { return getc(stream); } diff --git a/lang/cem/libcc.ansi/stdio/getchar.c b/lang/cem/libcc.ansi/stdio/getchar.c index 8c2955ba4..e76f15d40 100644 --- a/lang/cem/libcc.ansi/stdio/getchar.c +++ b/lang/cem/libcc.ansi/stdio/getchar.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(getchar)(void) +int(getchar)(void) { return getchar(); } diff --git a/lang/cem/libcc.ansi/stdio/gets.c b/lang/cem/libcc.ansi/stdio/gets.c index 74595a153..c58db3378 100644 --- a/lang/cem/libcc.ansi/stdio/gets.c +++ b/lang/cem/libcc.ansi/stdio/gets.c @@ -3,23 +3,27 @@ */ /* $Id$ */ -#include +#include -char * -gets(char *s) +char* gets(char* s) { - register FILE *stream = stdin; + register FILE* stream = stdin; register int ch; - register char *ptr; + register char* ptr; ptr = s; while ((ch = getc(stream)) != EOF && ch != '\n') *ptr++ = ch; - if (ch == EOF) { - if (feof(stream)) { - if (ptr == s) return NULL; - } else return NULL; + if (ch == EOF) + { + if (feof(stream)) + { + if (ptr == s) + return NULL; + } + else + return NULL; } *ptr = '\0'; diff --git a/lang/cem/libcc.ansi/stdio/icompute.c b/lang/cem/libcc.ansi/stdio/icompute.c index 78c63580f..bc73f1ddb 100644 --- a/lang/cem/libcc.ansi/stdio/icompute.c +++ b/lang/cem/libcc.ansi/stdio/icompute.c @@ -3,19 +3,18 @@ */ /* $Id$ */ -#include "loc_incl.h" +#include "loc_incl.h" /* This routine is used in doprnt.c as well as in tmpfile.c and tmpnam.c. */ -char * -_i_compute(unsigned long val, int base, char *s, int nrdigits) +char* _i_compute(unsigned long val, int base, char* s, int nrdigits) { int c; - c= val % base ; - val /= base ; + c = val % base; + val /= base; if (val || nrdigits > 1) s = _i_compute(val, base, s, nrdigits - 1); - *s++ = (c>9 ? c-10+'a' : c+'0'); + *s++ = (c > 9 ? c - 10 + 'a' : c + '0'); return s; } diff --git a/lang/cem/libcc.ansi/stdio/isatty.c b/lang/cem/libcc.ansi/stdio/isatty.c index 10b2bdb36..97d7ca442 100644 --- a/lang/cem/libcc.ansi/stdio/isatty.c +++ b/lang/cem/libcc.ansi/stdio/isatty.c @@ -3,11 +3,11 @@ */ /* $Id$ */ -int _gtty(int d, char *buf); +int _gtty(int d, char* buf); int _isatty(int d) { - char buf[128]; + char buf[128]; /* not a sgttyb struct; it might not be large enough; I know for a fact that it isn't large enough on PC/IX, where gtty is an ioctl(..., TCGETA, ...) diff --git a/lang/cem/libcc.ansi/stdio/perror.c b/lang/cem/libcc.ansi/stdio/perror.c index f7329f6dc..1ff33f2c3 100644 --- a/lang/cem/libcc.ansi/stdio/perror.c +++ b/lang/cem/libcc.ansi/stdio/perror.c @@ -3,17 +3,17 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include -void -perror(const char *s) +void perror(const char* s) { - if (s && *s) { - (void) fputs(s, stderr); - (void) fputs(": ", stderr); + if (s && *s) + { + (void)fputs(s, stderr); + (void)fputs(": ", stderr); } - (void) fputs(strerror(errno), stderr); - (void) fputs("\n", stderr); + (void)fputs(strerror(errno), stderr); + (void)fputs("\n", stderr); } diff --git a/lang/cem/libcc.ansi/stdio/printf.c b/lang/cem/libcc.ansi/stdio/printf.c index da49b2efc..d52d47525 100644 --- a/lang/cem/libcc.ansi/stdio/printf.c +++ b/lang/cem/libcc.ansi/stdio/printf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -printf(const char *format, ...) +int printf(const char* format, ...) { va_list ap; int retval; diff --git a/lang/cem/libcc.ansi/stdio/putc.c b/lang/cem/libcc.ansi/stdio/putc.c index cf79939b2..ee47c72cc 100644 --- a/lang/cem/libcc.ansi/stdio/putc.c +++ b/lang/cem/libcc.ansi/stdio/putc.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(putc)(int c, FILE *stream) +int(putc)(int c, FILE* stream) { return putc(c, stream); } diff --git a/lang/cem/libcc.ansi/stdio/putchar.c b/lang/cem/libcc.ansi/stdio/putchar.c index 2cddd5e10..ecf091f74 100644 --- a/lang/cem/libcc.ansi/stdio/putchar.c +++ b/lang/cem/libcc.ansi/stdio/putchar.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -int -(putchar)(int c) +int(putchar)(int c) { return putchar(c); } diff --git a/lang/cem/libcc.ansi/stdio/puts.c b/lang/cem/libcc.ansi/stdio/puts.c index 99dfc8db8..faa762426 100644 --- a/lang/cem/libcc.ansi/stdio/puts.c +++ b/lang/cem/libcc.ansi/stdio/puts.c @@ -3,18 +3,21 @@ */ /* $Id$ */ -#include +#include -int -puts(register const char *s) +int puts(register const char* s) { - register FILE *file = stdout; + register FILE* file = stdout; register int i = 0; - while (*s) { - if (putc(*s++, file) == EOF) return EOF; - else i++; + while (*s) + { + if (putc(*s++, file) == EOF) + return EOF; + else + i++; } - if (putc('\n', file) == EOF) return EOF; + if (putc('\n', file) == EOF) + return EOF; return i + 1; } diff --git a/lang/cem/libcc.ansi/stdio/remove.c b/lang/cem/libcc.ansi/stdio/remove.c index 204c4a25d..fb0f4de8e 100644 --- a/lang/cem/libcc.ansi/stdio/remove.c +++ b/lang/cem/libcc.ansi/stdio/remove.c @@ -7,7 +7,7 @@ #include #include -int -remove(const char *filename) { +int remove(const char* filename) +{ return unlink(filename); } diff --git a/lang/cem/libcc.ansi/stdio/rewind.c b/lang/cem/libcc.ansi/stdio/rewind.c index f3c9b22c3..41791a7d0 100644 --- a/lang/cem/libcc.ansi/stdio/rewind.c +++ b/lang/cem/libcc.ansi/stdio/rewind.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include "loc_incl.h" +#include +#include "loc_incl.h" -void -rewind(FILE *stream) +void rewind(FILE* stream) { - (void) fseek(stream, 0L, SEEK_SET); + (void)fseek(stream, 0L, SEEK_SET); clearerr(stream); } diff --git a/lang/cem/libcc.ansi/stdio/scanf.c b/lang/cem/libcc.ansi/stdio/scanf.c index 2157419db..c8c03c52b 100644 --- a/lang/cem/libcc.ansi/stdio/scanf.c +++ b/lang/cem/libcc.ansi/stdio/scanf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -scanf(const char *format, ...) +int scanf(const char* format, ...) { va_list ap; int retval; @@ -21,5 +20,3 @@ scanf(const char *format, ...) return retval; } - - diff --git a/lang/cem/libcc.ansi/stdio/setbuf.c b/lang/cem/libcc.ansi/stdio/setbuf.c index aafacdbf6..c906bc47a 100644 --- a/lang/cem/libcc.ansi/stdio/setbuf.c +++ b/lang/cem/libcc.ansi/stdio/setbuf.c @@ -3,11 +3,10 @@ */ /* $Id$ */ -#include -#include "loc_incl.h" +#include +#include "loc_incl.h" -void -setbuf(register FILE *stream, char *buf) +void setbuf(register FILE* stream, char* buf) { - (void) setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t) BUFSIZ); + (void)setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t)BUFSIZ); } diff --git a/lang/cem/libcc.ansi/stdio/setvbuf.c b/lang/cem/libcc.ansi/stdio/setvbuf.c index 2c5e769df..b7571ccc6 100644 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/stdio/setvbuf.c @@ -3,14 +3,13 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" extern void (*_clean)(void); -int -setvbuf(register FILE *stream, char *buf, int mode, size_t size) +int setvbuf(register FILE* stream, char* buf, int mode, size_t size) { int retval = 0; @@ -18,29 +17,37 @@ setvbuf(register FILE *stream, char *buf, int mode, size_t size) if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) return EOF; - if (stream->_buf && io_testflag(stream,_IOMYBUF) ) - free((void *)stream->_buf); + if (stream->_buf && io_testflag(stream, _IOMYBUF)) + free((void*)stream->_buf); stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF); - if (buf && size <= 0) retval = EOF; - if (!buf && (mode != _IONBF)) { - if (size <= 0 || (buf = (char *) malloc(size)) == NULL) { + if (buf && size <= 0) + retval = EOF; + if (!buf && (mode != _IONBF)) + { + if (size <= 0 || (buf = (char*)malloc(size)) == NULL) + { retval = EOF; - } else { + } + else + { stream->_flags |= _IOMYBUF; } } - stream->_buf = (unsigned char *) buf; + stream->_buf = (unsigned char*)buf; stream->_count = 0; stream->_flags |= mode; stream->_ptr = stream->_buf; - if (!buf) { + if (!buf) + { stream->_bufsiz = 1; - } else { + } + else + { stream->_bufsiz = size; } diff --git a/lang/cem/libcc.ansi/stdio/snprintf.c b/lang/cem/libcc.ansi/stdio/snprintf.c index 7d428118c..603b0a3d1 100644 --- a/lang/cem/libcc.ansi/stdio/snprintf.c +++ b/lang/cem/libcc.ansi/stdio/snprintf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -snprintf(char * s, size_t len, const char *format, ...) +int snprintf(char* s, size_t len, const char* format, ...) { va_list ap; int retval; @@ -16,14 +15,14 @@ snprintf(char * s, size_t len, const char *format, ...) va_start(ap, format); - tmp_stream._fd = -1; - tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; - tmp_stream._buf = (unsigned char *) s; - tmp_stream._ptr = (unsigned char *) s; - tmp_stream._count = len; + tmp_stream._fd = -1; + tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; + tmp_stream._buf = (unsigned char*)s; + tmp_stream._ptr = (unsigned char*)s; + tmp_stream._count = len; retval = _doprnt(format, ap, &tmp_stream); - putc('\0',&tmp_stream); + putc('\0', &tmp_stream); va_end(ap); diff --git a/lang/cem/libcc.ansi/stdio/sprintf.c b/lang/cem/libcc.ansi/stdio/sprintf.c index 6e52bce4a..78349a3a5 100644 --- a/lang/cem/libcc.ansi/stdio/sprintf.c +++ b/lang/cem/libcc.ansi/stdio/sprintf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -sprintf(char * s, const char *format, ...) +int sprintf(char* s, const char* format, ...) { va_list ap; int retval; @@ -16,14 +15,14 @@ sprintf(char * s, const char *format, ...) va_start(ap, format); - tmp_stream._fd = -1; - tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; - tmp_stream._buf = (unsigned char *) s; - tmp_stream._ptr = (unsigned char *) s; - tmp_stream._count = 32767; + tmp_stream._fd = -1; + tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; + tmp_stream._buf = (unsigned char*)s; + tmp_stream._ptr = (unsigned char*)s; + tmp_stream._count = 32767; retval = _doprnt(format, ap, &tmp_stream); - putc('\0',&tmp_stream); + putc('\0', &tmp_stream); va_end(ap); diff --git a/lang/cem/libcc.ansi/stdio/sscanf.c b/lang/cem/libcc.ansi/stdio/sscanf.c index b352db03e..723f6c231 100644 --- a/lang/cem/libcc.ansi/stdio/sscanf.c +++ b/lang/cem/libcc.ansi/stdio/sscanf.c @@ -3,12 +3,12 @@ */ /* $Id$ */ -#include -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include "loc_incl.h" -int sscanf(const char *s, const char *format, ...) +int sscanf(const char* s, const char* format, ...) { va_list ap; int retval; @@ -16,11 +16,11 @@ int sscanf(const char *s, const char *format, ...) va_start(ap, format); - tmp_stream._fd = -1; - tmp_stream._flags = _IOREAD + _IONBF + _IOREADING; - tmp_stream._buf = (unsigned char *) s; - tmp_stream._ptr = (unsigned char *) s; - tmp_stream._count = strlen(s); + tmp_stream._fd = -1; + tmp_stream._flags = _IOREAD + _IONBF + _IOREADING; + tmp_stream._buf = (unsigned char*)s; + tmp_stream._ptr = (unsigned char*)s; + tmp_stream._count = strlen(s); retval = _doscan(&tmp_stream, format, ap); diff --git a/lang/cem/libcc.ansi/stdio/tmpfile.c b/lang/cem/libcc.ansi/stdio/tmpfile.c index 19c91593d..cc525220d 100644 --- a/lang/cem/libcc.ansi/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/stdio/tmpfile.c @@ -9,20 +9,22 @@ #include #include "loc_incl.h" -FILE * -tmpfile(void) { - static char name_buffer[L_tmpnam] = "/tmp/tmp." ; - static char *name = NULL; - FILE *file; +FILE* tmpfile(void) +{ + static char name_buffer[L_tmpnam] = "/tmp/tmp."; + static char* name = NULL; + FILE* file; - if (!name) { + if (!name) + { name = name_buffer + strlen(name_buffer); name = _i_compute(getpid(), 10, name, 5); *name = '\0'; } - file = fopen(name_buffer,"wb+"); - if (!file) return (FILE *)NULL; - (void) remove(name_buffer); + file = fopen(name_buffer, "wb+"); + if (!file) + return (FILE*)NULL; + (void)remove(name_buffer); return file; } diff --git a/lang/cem/libcc.ansi/stdio/tmpnam.c b/lang/cem/libcc.ansi/stdio/tmpnam.c index 9c6bc6be5..02df608ba 100644 --- a/lang/cem/libcc.ansi/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/stdio/tmpnam.c @@ -9,20 +9,24 @@ #include #include "loc_incl.h" -char * -tmpnam(char *s) { +char* tmpnam(char* s) +{ static char name_buffer[L_tmpnam] = "/tmp/tmp."; static unsigned long count = 0; - static char *name = NULL; + static char* name = NULL; - if (!name) { + if (!name) + { name = name_buffer + strlen(name_buffer); name = _i_compute(getpid(), 10, name, 5); *name++ = '.'; *name = '\0'; } - if (++count > TMP_MAX) count = 1; /* wrap-around */ + if (++count > TMP_MAX) + count = 1; /* wrap-around */ *_i_compute(count, 10, name, 3) = '\0'; - if (s) return strcpy(s, name_buffer); - else return name_buffer; + if (s) + return strcpy(s, name_buffer); + else + return name_buffer; } diff --git a/lang/cem/libcc.ansi/stdio/ungetc.c b/lang/cem/libcc.ansi/stdio/ungetc.c index 6e832d67b..cf690a52a 100644 --- a/lang/cem/libcc.ansi/stdio/ungetc.c +++ b/lang/cem/libcc.ansi/stdio/ungetc.c @@ -3,24 +3,25 @@ */ /* $Id$ */ -#include -#include "loc_incl.h" +#include +#include "loc_incl.h" -int -ungetc(int ch, FILE *stream) +int ungetc(int ch, FILE* stream) { - unsigned char *p; + unsigned char* p; - if (ch == EOF || !io_testflag(stream,_IOREADING)) + if (ch == EOF || !io_testflag(stream, _IOREADING)) return EOF; - if (stream->_ptr == stream->_buf) { - if (stream->_count != 0) return EOF; + if (stream->_ptr == stream->_buf) + { + if (stream->_count != 0) + return EOF; stream->_ptr++; } stream->_count++; - p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */ + p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */ /* ungetc() in sscanf() shouldn't write in rom */ - if (*p != (unsigned char) ch) - *p = (unsigned char) ch; + if (*p != (unsigned char)ch) + *p = (unsigned char)ch; return ch; } diff --git a/lang/cem/libcc.ansi/stdio/vfprintf.c b/lang/cem/libcc.ansi/stdio/vfprintf.c index 96dcea9f5..fd896a720 100644 --- a/lang/cem/libcc.ansi/stdio/vfprintf.c +++ b/lang/cem/libcc.ansi/stdio/vfprintf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -vfprintf(FILE *stream, const char *format, va_list arg) +int vfprintf(FILE* stream, const char* format, va_list arg) { - return _doprnt (format, arg, stream); + return _doprnt(format, arg, stream); } diff --git a/lang/cem/libcc.ansi/stdio/vprintf.c b/lang/cem/libcc.ansi/stdio/vprintf.c index bc25f7363..bf884e576 100644 --- a/lang/cem/libcc.ansi/stdio/vprintf.c +++ b/lang/cem/libcc.ansi/stdio/vprintf.c @@ -3,12 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -vprintf(const char *format, va_list arg) +int vprintf(const char* format, va_list arg) { return _doprnt(format, arg, stdout); } diff --git a/lang/cem/libcc.ansi/stdio/vsnprintf.c b/lang/cem/libcc.ansi/stdio/vsnprintf.c index 870e23df2..033e39d72 100644 --- a/lang/cem/libcc.ansi/stdio/vsnprintf.c +++ b/lang/cem/libcc.ansi/stdio/vsnprintf.c @@ -3,24 +3,23 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -vsnprintf(char *s, size_t len, const char *format, va_list arg) +int vsnprintf(char* s, size_t len, const char* format, va_list arg) { int retval; FILE tmp_stream; - tmp_stream._fd = -1; - tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; - tmp_stream._buf = (unsigned char *) s; - tmp_stream._ptr = (unsigned char *) s; - tmp_stream._count = len; + tmp_stream._fd = -1; + tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; + tmp_stream._buf = (unsigned char*)s; + tmp_stream._ptr = (unsigned char*)s; + tmp_stream._count = len; retval = _doprnt(format, arg, &tmp_stream); - putc('\0',&tmp_stream); + putc('\0', &tmp_stream); return retval; } diff --git a/lang/cem/libcc.ansi/stdio/vsprintf.c b/lang/cem/libcc.ansi/stdio/vsprintf.c index b4ae4ed74..b0cbc124c 100644 --- a/lang/cem/libcc.ansi/stdio/vsprintf.c +++ b/lang/cem/libcc.ansi/stdio/vsprintf.c @@ -3,24 +3,23 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -vsprintf(char *s, const char *format, va_list arg) +int vsprintf(char* s, const char* format, va_list arg) { int retval; FILE tmp_stream; - tmp_stream._fd = -1; - tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; - tmp_stream._buf = (unsigned char *) s; - tmp_stream._ptr = (unsigned char *) s; - tmp_stream._count = 32767; + tmp_stream._fd = -1; + tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING; + tmp_stream._buf = (unsigned char*)s; + tmp_stream._ptr = (unsigned char*)s; + tmp_stream._count = 32767; retval = _doprnt(format, arg, &tmp_stream); - putc('\0',&tmp_stream); + putc('\0', &tmp_stream); return retval; } diff --git a/lang/cem/libcc.ansi/stdlib/abort.c b/lang/cem/libcc.ansi/stdlib/abort.c index d5ceff27c..afad36bf9 100644 --- a/lang/cem/libcc.ansi/stdlib/abort.c +++ b/lang/cem/libcc.ansi/stdlib/abort.c @@ -4,18 +4,17 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) -#include +#if defined(_POSIX_SOURCE) +#include #endif -#include -#include +#include +#include extern void (*_clean)(void); -void -abort(void) +void abort(void) { - if (_clean) _clean(); /* flush all output files */ + if (_clean) + _clean(); /* flush all output files */ raise(SIGABRT); } - diff --git a/lang/cem/libcc.ansi/stdlib/abs.c b/lang/cem/libcc.ansi/stdlib/abs.c index 04a0fb642..3270f087a 100644 --- a/lang/cem/libcc.ansi/stdlib/abs.c +++ b/lang/cem/libcc.ansi/stdlib/abs.c @@ -4,10 +4,9 @@ */ /* $Id$ */ -#include +#include -int -abs(register int i) +int abs(register int i) { return i >= 0 ? i : -i; } diff --git a/lang/cem/libcc.ansi/stdlib/atexit.c b/lang/cem/libcc.ansi/stdlib/atexit.c index 77e343336..c9dc7964a 100644 --- a/lang/cem/libcc.ansi/stdlib/atexit.c +++ b/lang/cem/libcc.ansi/stdlib/atexit.c @@ -1,14 +1,13 @@ /* $Id$ */ -#include +#include -#define NEXITS 32 +#define NEXITS 32 extern void (*__functab[NEXITS])(void); extern int __funccnt; -int -atexit(void (*func)(void)) +int atexit(void (*func)(void)) { if (__funccnt >= NEXITS) return 1; diff --git a/lang/cem/libcc.ansi/stdlib/atof.c b/lang/cem/libcc.ansi/stdlib/atof.c index 834dc9242..c46304817 100644 --- a/lang/cem/libcc.ansi/stdlib/atof.c +++ b/lang/cem/libcc.ansi/stdlib/atof.c @@ -4,16 +4,15 @@ */ /* $Id$ */ -#include -#include +#include +#include -double -(atof)(const char *nptr) +double(atof)(const char* nptr) { double d; int e = errno; - d = strtod(nptr, (char **) NULL); + d = strtod(nptr, (char**)NULL); errno = e; return d; } diff --git a/lang/cem/libcc.ansi/stdlib/atoi.c b/lang/cem/libcc.ansi/stdlib/atoi.c index f8dd99d8f..6cd0c8d05 100644 --- a/lang/cem/libcc.ansi/stdlib/atoi.c +++ b/lang/cem/libcc.ansi/stdlib/atoi.c @@ -4,24 +4,27 @@ */ /* $Id$ */ -#include +#include /* We do not use strtol here for backwards compatibility in behaviour on overflow. */ -int -atoi(register const char *nptr) +int atoi(register const char* nptr) { int total = 0; int minus = 0; - while (isspace(*nptr)) nptr++; - if (*nptr == '+') nptr++; - else if (*nptr == '-') { + while (isspace(*nptr)) + nptr++; + if (*nptr == '+') + nptr++; + else if (*nptr == '-') + { minus = 1; nptr++; } - while (isdigit(*nptr)) { + while (isdigit(*nptr)) + { total *= 10; total += (*nptr++ - '0'); } diff --git a/lang/cem/libcc.ansi/stdlib/atol.c b/lang/cem/libcc.ansi/stdlib/atol.c index 456852cb5..27adb3479 100644 --- a/lang/cem/libcc.ansi/stdlib/atol.c +++ b/lang/cem/libcc.ansi/stdlib/atol.c @@ -4,24 +4,27 @@ */ /* $Id$ */ -#include +#include /* We do not use strtol here for backwards compatibility in behaviour on overflow. */ -long -atol(register const char *nptr) +long atol(register const char* nptr) { long total = 0; int minus = 0; - while (isspace(*nptr)) nptr++; - if (*nptr == '+') nptr++; - else if (*nptr == '-') { + while (isspace(*nptr)) + nptr++; + if (*nptr == '+') + nptr++; + else if (*nptr == '-') + { minus = 1; nptr++; } - while (isdigit(*nptr)) { + while (isdigit(*nptr)) + { total *= 10; total += (*nptr++ - '0'); } diff --git a/lang/cem/libcc.ansi/stdlib/bsearch.c b/lang/cem/libcc.ansi/stdlib/bsearch.c index 0958e3d78..519fff9dd 100644 --- a/lang/cem/libcc.ansi/stdlib/bsearch.c +++ b/lang/cem/libcc.ansi/stdlib/bsearch.c @@ -4,25 +4,27 @@ */ /* $Id$ */ -#include +#include -void * -bsearch(register const void *key, register const void *base, - register size_t nmemb, register size_t size, - int (*compar)(const void *, const void *)) +void* bsearch(register const void* key, register const void* base, + register size_t nmemb, register size_t size, + int (*compar)(const void*, const void*)) { - register const void *mid_point; - register int cmp; + register const void* mid_point; + register int cmp; - while (nmemb > 0) { - mid_point = (char *)base + size * (nmemb >> 1); + while (nmemb > 0) + { + mid_point = (char*)base + size * (nmemb >> 1); if ((cmp = (*compar)(key, mid_point)) == 0) - return (void *)mid_point; - if (cmp >= 0) { - base = (char *)mid_point + size; + return (void*)mid_point; + if (cmp >= 0) + { + base = (char*)mid_point + size; nmemb = (nmemb - 1) >> 1; - } else + } + else nmemb >>= 1; } - return (void *)NULL; + return (void*)NULL; } diff --git a/lang/cem/libcc.ansi/stdlib/div.c b/lang/cem/libcc.ansi/stdlib/div.c index 659363564..42f739b0e 100644 --- a/lang/cem/libcc.ansi/stdlib/div.c +++ b/lang/cem/libcc.ansi/stdlib/div.c @@ -4,17 +4,17 @@ */ /* $Id$ */ -#include +#include -div_t -div(register int numer, register int denom) +div_t div(register int numer, register int denom) { div_t r; - r.quot = numer / denom; /* might trap if denom == 0 */ + r.quot = numer / denom; /* might trap if denom == 0 */ r.rem = numer % denom; - if (r.rem != 0 && (numer > 0) != (r.rem > 0)) { + if (r.rem != 0 && (numer > 0) != (r.rem > 0)) + { r.quot++; r.rem -= denom; } diff --git a/lang/cem/libcc.ansi/stdlib/exit.c b/lang/cem/libcc.ansi/stdlib/exit.c index 16be42f4d..ef8976bc0 100644 --- a/lang/cem/libcc.ansi/stdlib/exit.c +++ b/lang/cem/libcc.ansi/stdlib/exit.c @@ -8,7 +8,7 @@ #include #include -#define NEXITS 32 +#define NEXITS 32 void (*__functab[NEXITS])(void); int __funccnt = 0; @@ -20,16 +20,16 @@ static void _calls(void) { register int i = __funccnt; - + /* "Called in reversed order of their registration" */ while (--i >= 0) (*__functab[i])(); } -void -exit(int status) +void exit(int status) { _calls(); - if (_clean) _clean(); - _exit(status) ; + if (_clean) + _clean(); + _exit(status); } diff --git a/lang/cem/libcc.ansi/stdlib/ext_comp.c b/lang/cem/libcc.ansi/stdlib/ext_comp.c index 2133e64bd..c9b0b8b13 100644 --- a/lang/cem/libcc.ansi/stdlib/ext_comp.c +++ b/lang/cem/libcc.ansi/stdlib/ext_comp.c @@ -11,27 +11,26 @@ bytes. In this case, these routines may become obsolete. ??? */ -#include "ext_fmt.h" -#include -#include -#include -#include +#include "ext_fmt.h" +#include +#include +#include +#include -static int b64_add(struct mantissa *e1, struct mantissa *e2); -static b64_sft(struct mantissa *e1, int n); +static int b64_add(struct mantissa* e1, struct mantissa* e2); +static b64_sft(struct mantissa* e1, int n); -static -mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) +static mul_ext(struct EXTEND* e1, struct EXTEND* e2, struct EXTEND* e3) { /* Multiply the extended numbers e1 and e2, and put the result in e3. */ - register int i,j; /* loop control */ - unsigned short mp[4]; - unsigned short mc[4]; - unsigned short result[8]; /* result */ + register int i, j; /* loop control */ + unsigned short mp[4]; + unsigned short mc[4]; + unsigned short result[8]; /* result */ - register unsigned short *pres; + register unsigned short* pres; /* first save the sign (XOR) */ e3->sign = e1->sign ^ e2->sign; @@ -46,47 +45,58 @@ mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) /* assign unknown long formats */ /* to known unsigned word formats */ mp[0] = e1->m1 >> 16; - mp[1] = (unsigned short) e1->m1; + mp[1] = (unsigned short)e1->m1; mp[2] = e1->m2 >> 16; - mp[3] = (unsigned short) e1->m2; + mp[3] = (unsigned short)e1->m2; mc[0] = e2->m1 >> 16; - mc[1] = (unsigned short) e2->m1; + mc[1] = (unsigned short)e2->m1; mc[2] = e2->m2 >> 16; - mc[3] = (unsigned short) e2->m2; - for (i = 8; i--;) { + mc[3] = (unsigned short)e2->m2; + for (i = 8; i--;) + { result[i] = 0; } /* * fill registers with their components */ - for(i=4, pres = &result[4];i--;pres--) if (mp[i]) { - unsigned short k = 0; - unsigned long mpi = mp[i]; - for(j=4;j--;) { - unsigned long tmp = (unsigned long)pres[j] + k; - if (mc[j]) tmp += mpi * mc[j]; - pres[j] = tmp; - k = tmp >> 16; + for (i = 4, pres = &result[4]; i--; pres--) + if (mp[i]) + { + unsigned short k = 0; + unsigned long mpi = mp[i]; + for (j = 4; j--;) + { + unsigned long tmp = (unsigned long)pres[j] + k; + if (mc[j]) + tmp += mpi * mc[j]; + pres[j] = tmp; + k = tmp >> 16; + } + pres[-1] = k; } - pres[-1] = k; - } - if (! (result[0] & 0x8000)) { + if (!(result[0] & 0x8000)) + { e3->exp--; - for (i = 0; i <= 3; i++) { + for (i = 0; i <= 3; i++) + { result[i] <<= 1; - if (result[i+1]&0x8000) result[i] |= 1; + if (result[i + 1] & 0x8000) + result[i] |= 1; } result[4] <<= 1; - } + } /* * combine the registers to a total */ e3->m1 = ((unsigned long)(result[0]) << 16) + result[1]; e3->m2 = ((unsigned long)(result[2]) << 16) + result[3]; - if (result[4] & 0x8000) { - if (++e3->m2 == 0) { - if (++e3->m1 == 0) { + if (result[4] & 0x8000) + { + if (++e3->m2 == 0) + { + if (++e3->m1 == 0) + { e3->m1 = 0x80000000; e3->exp++; } @@ -94,8 +104,7 @@ mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) } } -static -add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) +static add_ext(struct EXTEND* e1, struct EXTEND* e2, struct EXTEND* e3) { /* Add two extended numbers e1 and e2, and put the result in e3 @@ -103,11 +112,13 @@ add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) struct EXTEND ce2; int diff; - if ((e2->m1 | e2->m2) == 0L) { + if ((e2->m1 | e2->m2) == 0L) + { *e3 = *e1; return; } - if ((e1->m1 | e1->m2) == 0L) { + if ((e1->m1 | e1->m2) == 0L) + { *e3 = *e2; return; } @@ -117,52 +128,66 @@ add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) /* adjust mantissas to equal power */ diff = e3->exp - e1->exp; - if (diff < 0) { + if (diff < 0) + { diff = -diff; e3->exp += diff; b64_sft(&(e3->mantissa), diff); } - else if (diff > 0) { + else if (diff > 0) + { e1->exp += diff; b64_sft(&(e1->mantissa), diff); } - if (e1->sign != e3->sign) { + if (e1->sign != e3->sign) + { /* e3 + e1 = e3 - (-e1) */ - if (e1->m1 > e3->m1 || - (e1->m1 == e3->m1 && e1->m2 > e3->m2)) { - /* abs(e1) > abs(e3) */ - if (e3->m2 > e1->m2) { - e1->m1 -= 1; /* carry in */ - } - e1->m1 -= e3->m1; - e1->m2 -= e3->m2; - *e3 = *e1; - } - else { - if (e1->m2 > e3->m2) - e3->m1 -= 1; /* carry in */ - e3->m1 -= e1->m1; - e3->m2 -= e1->m2; - } - } - else { - if (b64_add(&e3->mantissa,&e1->mantissa)) {/* addition carry */ - b64_sft(&e3->mantissa,1);/* shift mantissa one bit RIGHT */ - e3->m1 |= 0x80000000L; /* set max bit */ - e3->exp++; /* increase the exponent */ + if (e1->m1 > e3->m1 || (e1->m1 == e3->m1 && e1->m2 > e3->m2)) + { + /* abs(e1) > abs(e3) */ + if (e3->m2 > e1->m2) + { + e1->m1 -= 1; /* carry in */ + } + e1->m1 -= e3->m1; + e1->m2 -= e3->m2; + *e3 = *e1; + } + else + { + if (e1->m2 > e3->m2) + e3->m1 -= 1; /* carry in */ + e3->m1 -= e1->m1; + e3->m2 -= e1->m2; } } - if ((e3->m2 | e3->m1) != 0L) { + else + { + if (b64_add(&e3->mantissa, &e1->mantissa)) + { /* addition carry */ + b64_sft(&e3->mantissa, 1); /* shift mantissa one bit RIGHT */ + e3->m1 |= 0x80000000L; /* set max bit */ + e3->exp++; /* increase the exponent */ + } + } + if ((e3->m2 | e3->m1) != 0L) + { /* normalize */ - if (e3->m1 == 0L) { - e3->m1 = e3->m2; e3->m2 = 0L; e3->exp -= 32; + if (e3->m1 == 0L) + { + e3->m1 = e3->m2; + e3->m2 = 0L; + e3->exp -= 32; } - if (!(e3->m1 & 0x80000000)) { + if (!(e3->m1 & 0x80000000)) + { unsigned long l = 0x40000000; int cnt = -1; - while (! (l & e3->m1)) { - l >>= 1; cnt--; + while (!(l & e3->m1)) + { + l >>= 1; + cnt--; } e3->exp += cnt; b64_sft(&(e3->mantissa), cnt); @@ -171,35 +196,41 @@ add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3) } static int -cmp_ext(struct EXTEND *e1, struct EXTEND *e2) +cmp_ext(struct EXTEND* e1, struct EXTEND* e2) { - struct EXTEND tmp; - - e2->sign = ! e2->sign; - add_ext(e1, e2, &tmp); - e2->sign = ! e2->sign; - if (tmp.m1 == 0 && tmp.m2 == 0) return 0; - if (tmp.sign) return -1; - return 1; + struct EXTEND tmp; + + e2->sign = !e2->sign; + add_ext(e1, e2, &tmp); + e2->sign = !e2->sign; + if (tmp.m1 == 0 && tmp.m2 == 0) + return 0; + if (tmp.sign) + return -1; + return 1; } -static -b64_sft(struct mantissa *e1, int n) +static b64_sft(struct mantissa* e1, int n) { - if (n > 0) { - if (n > 63) { + if (n > 0) + { + if (n > 63) + { e1->l_32 = 0; e1->h_32 = 0; return; } - if (n >= 32) { + if (n >= 32) + { e1->l_32 = e1->h_32; e1->h_32 = 0; n -= 32; } - if (n > 0) { + if (n > 0) + { e1->l_32 >>= n; - if (e1->h_32 != 0) { + if (e1->h_32 != 0) + { e1->l_32 |= (e1->h_32 << (32 - n)); e1->h_32 >>= n; } @@ -207,20 +238,25 @@ b64_sft(struct mantissa *e1, int n) return; } n = -n; - if (n > 0) { - if (n > 63) { + if (n > 0) + { + if (n > 63) + { e1->l_32 = 0; e1->h_32 = 0; return; } - if (n >= 32) { + if (n >= 32) + { e1->h_32 = e1->l_32; e1->l_32 = 0; n -= 32; } - if (n > 0) { + if (n > 0) + { e1->h_32 <<= n; - if (e1->l_32 != 0) { + if (e1->l_32 != 0) + { e1->h_32 |= (e1->l_32 >> (32 - n)); e1->l_32 <<= n; } @@ -229,25 +265,25 @@ b64_sft(struct mantissa *e1, int n) } static int -b64_add(struct mantissa *e1, struct mantissa *e2) - /* +b64_add(struct mantissa* e1, struct mantissa* e2) +/* * pointers to 64 bit 'registers' */ { - register int overflow; - int carry; + register int overflow; + int carry; - /* add higher pair of 32 bits */ - overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32); + /* add higher pair of 32 bits */ + overflow = ((unsigned long)0xFFFFFFFF - e1->h_32 < e2->h_32); e1->h_32 += e2->h_32; - /* add lower pair of 32 bits */ - carry = ((unsigned long) 0xFFFFFFFF - e1->l_32 < e2->l_32); + /* add lower pair of 32 bits */ + carry = ((unsigned long)0xFFFFFFFF - e1->l_32 < e2->l_32); e1->l_32 += e2->l_32; if ((carry) && (++e1->h_32 == 0)) - return(1); /* had a 64 bit overflow */ + return (1); /* had a 64 bit overflow */ else - return(overflow); /* return status from higher add */ + return (overflow); /* return status from higher add */ } /* The following tables can be computed with the following bc(1) @@ -325,164 +361,172 @@ for (i=1;i<20;i++) { 0 */ -static struct EXTEND ten_powers[] = { /* representation of 10 ** i */ - { 0, 0, 0x80000000, 0 }, - { 0, 3, 0xA0000000, 0 }, - { 0, 6, 0xC8000000, 0 }, - { 0, 9, 0xFA000000, 0 }, - { 0, 13, 0x9C400000, 0 }, - { 0, 16, 0xC3500000, 0 }, - { 0, 19, 0xF4240000, 0 }, - { 0, 23, 0x98968000, 0 }, - { 0, 26, 0xBEBC2000, 0 }, - { 0, 29, 0xEE6B2800, 0 }, - { 0, 33, 0x9502F900, 0 }, - { 0, 36, 0xBA43B740, 0 }, - { 0, 39, 0xE8D4A510, 0 }, - { 0, 43, 0x9184E72A, 0 }, - { 0, 46, 0xB5E620F4, 0x80000000 }, - { 0, 49, 0xE35FA931, 0xA0000000 }, - { 0, 53, 0x8E1BC9BF, 0x04000000 }, - { 0, 56, 0xB1A2BC2E, 0xC5000000 }, - { 0, 59, 0xDE0B6B3A, 0x76400000 }, - { 0, 63, 0x8AC72304, 0x89E80000 }, - { 0, 66, 0xAD78EBC5, 0xAC620000 }, - { 0, 69, 0xD8D726B7, 0x177A8000 }, - { 0, 73, 0x87867832, 0x6EAC9000 }, - { 0, 76, 0xA968163F, 0x0A57B400 }, - { 0, 79, 0xD3C21BCE, 0xCCEDA100 }, - { 0, 83, 0x84595161, 0x401484A0 }, - { 0, 86, 0xA56FA5B9, 0x9019A5C8 }, - { 0, 89, 0xCECB8F27, 0xF4200F3A } +static struct EXTEND ten_powers[] = { /* representation of 10 ** i */ + { 0, 0, 0x80000000, 0 }, + { 0, 3, 0xA0000000, 0 }, + { 0, 6, 0xC8000000, 0 }, + { 0, 9, 0xFA000000, 0 }, + { 0, 13, 0x9C400000, 0 }, + { 0, 16, 0xC3500000, 0 }, + { 0, 19, 0xF4240000, 0 }, + { 0, 23, 0x98968000, 0 }, + { 0, 26, 0xBEBC2000, 0 }, + { 0, 29, 0xEE6B2800, 0 }, + { 0, 33, 0x9502F900, 0 }, + { 0, 36, 0xBA43B740, 0 }, + { 0, 39, 0xE8D4A510, 0 }, + { 0, 43, 0x9184E72A, 0 }, + { 0, 46, 0xB5E620F4, 0x80000000 }, + { 0, 49, 0xE35FA931, 0xA0000000 }, + { 0, 53, 0x8E1BC9BF, 0x04000000 }, + { 0, 56, 0xB1A2BC2E, 0xC5000000 }, + { 0, 59, 0xDE0B6B3A, 0x76400000 }, + { 0, 63, 0x8AC72304, 0x89E80000 }, + { 0, 66, 0xAD78EBC5, 0xAC620000 }, + { 0, 69, 0xD8D726B7, 0x177A8000 }, + { 0, 73, 0x87867832, 0x6EAC9000 }, + { 0, 76, 0xA968163F, 0x0A57B400 }, + { 0, 79, 0xD3C21BCE, 0xCCEDA100 }, + { 0, 83, 0x84595161, 0x401484A0 }, + { 0, 86, 0xA56FA5B9, 0x9019A5C8 }, + { 0, 89, 0xCECB8F27, 0xF4200F3A } }; -static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */ - { 0, 0, 0x80000000, 0 }, - { 0, 93, 0x813F3978, 0xF8940984 }, - { 0, 186, 0x82818F12, 0x81ED44A0 }, - { 0, 279, 0x83C7088E, 0x1AAB65DB }, - { 0, 372, 0x850FADC0, 0x9923329E }, - { 0, 465, 0x865B8692, 0x5B9BC5C2 }, - { 0, 558, 0x87AA9AFF, 0x79042287 }, - { 0, 651, 0x88FCF317, 0xF22241E2 }, - { 0, 744, 0x8A5296FF, 0xE33CC930 }, - { 0, 837, 0x8BAB8EEF, 0xB6409C1A }, - { 0, 930, 0x8D07E334, 0x55637EB3 }, - { 0, 1023, 0x8E679C2F, 0x5E44FF8F }, - { 0, 1116, 0x8FCAC257, 0x558EE4E6 }, - { 0, 1209, 0x91315E37, 0xDB165AA9 }, - { 0, 1302, 0x929B7871, 0xDE7F22B9 }, - { 0, 1395, 0x940919BB, 0xD4620B6D }, - { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 }, - { 0, 1581, 0x96EF14C6, 0x454AA840 }, - { 0, 1674, 0x98678061, 0x27ECE4F5 }, - { 0, 1767, 0x99E396C1, 0x3A3ACFF2 } +static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */ + { 0, 0, 0x80000000, 0 }, + { 0, 93, 0x813F3978, 0xF8940984 }, + { 0, 186, 0x82818F12, 0x81ED44A0 }, + { 0, 279, 0x83C7088E, 0x1AAB65DB }, + { 0, 372, 0x850FADC0, 0x9923329E }, + { 0, 465, 0x865B8692, 0x5B9BC5C2 }, + { 0, 558, 0x87AA9AFF, 0x79042287 }, + { 0, 651, 0x88FCF317, 0xF22241E2 }, + { 0, 744, 0x8A5296FF, 0xE33CC930 }, + { 0, 837, 0x8BAB8EEF, 0xB6409C1A }, + { 0, 930, 0x8D07E334, 0x55637EB3 }, + { 0, 1023, 0x8E679C2F, 0x5E44FF8F }, + { 0, 1116, 0x8FCAC257, 0x558EE4E6 }, + { 0, 1209, 0x91315E37, 0xDB165AA9 }, + { 0, 1302, 0x929B7871, 0xDE7F22B9 }, + { 0, 1395, 0x940919BB, 0xD4620B6D }, + { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 }, + { 0, 1581, 0x96EF14C6, 0x454AA840 }, + { 0, 1674, 0x98678061, 0x27ECE4F5 }, + { 0, 1767, 0x99E396C1, 0x3A3ACFF2 } }; static struct EXTEND r_ten_powers[] = { /* representation of 10 ** -i */ - { 0, 0, 0x80000000, 0 }, - { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD }, - { 0, -7, 0xA3D70A3D, 0x70A3D70A }, - { 0, -10, 0x83126E97, 0x8D4FDF3B }, - { 0, -14, 0xD1B71758, 0xE219652C }, - { 0, -17, 0xA7C5AC47, 0x1B478423 }, - { 0, -20, 0x8637BD05, 0xAF6C69B6 }, - { 0, -24, 0xD6BF94D5, 0xE57A42BC }, - { 0, -27, 0xABCC7711, 0x8461CEFD }, - { 0, -30, 0x89705F41, 0x36B4A597 }, - { 0, -34, 0xDBE6FECE, 0xBDEDD5BF }, - { 0, -37, 0xAFEBFF0B, 0xCB24AAFF }, - { 0, -40, 0x8CBCCC09, 0x6F5088CC }, - { 0, -44, 0xE12E1342, 0x4BB40E13 }, - { 0, -47, 0xB424DC35, 0x095CD80F }, - { 0, -50, 0x901D7CF7, 0x3AB0ACD9 }, - { 0, -54, 0xE69594BE, 0xC44DE15B }, - { 0, -57, 0xB877AA32, 0x36A4B449 }, - { 0, -60, 0x9392EE8E, 0x921D5D07 }, - { 0, -64, 0xEC1E4A7D, 0xB69561A5 }, - { 0, -67, 0xBCE50864, 0x92111AEB }, - { 0, -70, 0x971DA050, 0x74DA7BEF }, - { 0, -74, 0xF1C90080, 0xBAF72CB1 }, - { 0, -77, 0xC16D9A00, 0x95928A27 }, - { 0, -80, 0x9ABE14CD, 0x44753B53 }, - { 0, -84, 0xF79687AE, 0xD3EEC551 }, - { 0, -87, 0xC6120625, 0x76589DDB }, - { 0, -90, 0x9E74D1B7, 0x91E07E48 } + { 0, 0, 0x80000000, 0 }, + { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD }, + { 0, -7, 0xA3D70A3D, 0x70A3D70A }, + { 0, -10, 0x83126E97, 0x8D4FDF3B }, + { 0, -14, 0xD1B71758, 0xE219652C }, + { 0, -17, 0xA7C5AC47, 0x1B478423 }, + { 0, -20, 0x8637BD05, 0xAF6C69B6 }, + { 0, -24, 0xD6BF94D5, 0xE57A42BC }, + { 0, -27, 0xABCC7711, 0x8461CEFD }, + { 0, -30, 0x89705F41, 0x36B4A597 }, + { 0, -34, 0xDBE6FECE, 0xBDEDD5BF }, + { 0, -37, 0xAFEBFF0B, 0xCB24AAFF }, + { 0, -40, 0x8CBCCC09, 0x6F5088CC }, + { 0, -44, 0xE12E1342, 0x4BB40E13 }, + { 0, -47, 0xB424DC35, 0x095CD80F }, + { 0, -50, 0x901D7CF7, 0x3AB0ACD9 }, + { 0, -54, 0xE69594BE, 0xC44DE15B }, + { 0, -57, 0xB877AA32, 0x36A4B449 }, + { 0, -60, 0x9392EE8E, 0x921D5D07 }, + { 0, -64, 0xEC1E4A7D, 0xB69561A5 }, + { 0, -67, 0xBCE50864, 0x92111AEB }, + { 0, -70, 0x971DA050, 0x74DA7BEF }, + { 0, -74, 0xF1C90080, 0xBAF72CB1 }, + { 0, -77, 0xC16D9A00, 0x95928A27 }, + { 0, -80, 0x9ABE14CD, 0x44753B53 }, + { 0, -84, 0xF79687AE, 0xD3EEC551 }, + { 0, -87, 0xC6120625, 0x76589DDB }, + { 0, -90, 0x9E74D1B7, 0x91E07E48 } }; static struct EXTEND r_big_ten_powers[] = { /* representation of 10 ** -(28*i) */ - { 0, 0, 0x80000000, 0 }, - { 0, -94, 0xFD87B5F2, 0x8300CA0E }, - { 0, -187, 0xFB158592, 0xBE068D2F }, - { 0, -280, 0xF8A95FCF, 0x88747D94 }, - { 0, -373, 0xF64335BC, 0xF065D37D }, - { 0, -466, 0xF3E2F893, 0xDEC3F126 }, - { 0, -559, 0xF18899B1, 0xBC3F8CA2 }, - { 0, -652, 0xEF340A98, 0x172AACE5 }, - { 0, -745, 0xECE53CEC, 0x4A314EBE }, - { 0, -838, 0xEA9C2277, 0x23EE8BCB }, - { 0, -931, 0xE858AD24, 0x8F5C22CA }, - { 0, -1024, 0xE61ACF03, 0x3D1A45DF }, - { 0, -1117, 0xE3E27A44, 0x4D8D98B8 }, - { 0, -1210, 0xE1AFA13A, 0xFBD14D6E }, - { 0, -1303, 0xDF82365C, 0x497B5454 }, - { 0, -1396, 0xDD5A2C3E, 0xAB3097CC }, - { 0, -1489, 0xDB377599, 0xB6074245 }, - { 0, -1582, 0xD91A0545, 0xCDB51186 }, - { 0, -1675, 0xD701CE3B, 0xD387BF48 }, - { 0, -1768, 0xD4EEC394, 0xD6258BF8 } + { 0, 0, 0x80000000, 0 }, + { 0, -94, 0xFD87B5F2, 0x8300CA0E }, + { 0, -187, 0xFB158592, 0xBE068D2F }, + { 0, -280, 0xF8A95FCF, 0x88747D94 }, + { 0, -373, 0xF64335BC, 0xF065D37D }, + { 0, -466, 0xF3E2F893, 0xDEC3F126 }, + { 0, -559, 0xF18899B1, 0xBC3F8CA2 }, + { 0, -652, 0xEF340A98, 0x172AACE5 }, + { 0, -745, 0xECE53CEC, 0x4A314EBE }, + { 0, -838, 0xEA9C2277, 0x23EE8BCB }, + { 0, -931, 0xE858AD24, 0x8F5C22CA }, + { 0, -1024, 0xE61ACF03, 0x3D1A45DF }, + { 0, -1117, 0xE3E27A44, 0x4D8D98B8 }, + { 0, -1210, 0xE1AFA13A, 0xFBD14D6E }, + { 0, -1303, 0xDF82365C, 0x497B5454 }, + { 0, -1396, 0xDD5A2C3E, 0xAB3097CC }, + { 0, -1489, 0xDB377599, 0xB6074245 }, + { 0, -1582, 0xD91A0545, 0xCDB51186 }, + { 0, -1675, 0xD701CE3B, 0xD387BF48 }, + { 0, -1768, 0xD4EEC394, 0xD6258BF8 } }; -#define TP (int)(sizeof(ten_powers)/sizeof(ten_powers[0])) -#define BTP (int)(sizeof(big_ten_powers)/sizeof(big_ten_powers[0])) -#define MAX_EXP (TP * BTP - 1) +#define TP (int)(sizeof(ten_powers) / sizeof(ten_powers[0])) +#define BTP (int)(sizeof(big_ten_powers) / sizeof(big_ten_powers[0])) +#define MAX_EXP (TP * BTP - 1) -static -add_exponent(struct EXTEND *e, int exp) +static add_exponent(struct EXTEND* e, int exp) { int neg = exp < 0; int divsz, modsz; struct EXTEND x; - if (neg) exp = -exp; + if (neg) + exp = -exp; divsz = exp / TP; modsz = exp % TP; - if (neg) { + if (neg) + { mul_ext(e, &r_ten_powers[modsz], &x); mul_ext(&x, &r_big_ten_powers[divsz], e); } - else { + else + { mul_ext(e, &ten_powers[modsz], &x); mul_ext(&x, &big_ten_powers[divsz], e); } } -_str_ext_cvt(const char *s, char **ss, struct EXTEND *e) +_str_ext_cvt(const char* s, char** ss, struct EXTEND* e) { /* Like strtod, but for extended precision */ - register int c; - int dotseen = 0; - int digitseen = 0; - int exp = 0; + register int c; + int dotseen = 0; + int digitseen = 0; + int exp = 0; - if (ss) *ss = (char *)s; - while (isspace(*s)) s++; + if (ss) + *ss = (char*)s; + while (isspace(*s)) + s++; e->sign = 0; e->exp = 0; e->m1 = e->m2 = 0; c = *s; - switch(c) { - case '-': - e->sign = 1; - case '+': - s++; + switch (c) + { + case '-': + e->sign = 1; + case '+': + s++; } - while (c = *s++, isdigit(c) || (c == '.' && ! dotseen++)) { - if (c == '.') continue; + while (c = *s++, isdigit(c) || (c == '.' && !dotseen++)) + { + if (c == '.') + continue; digitseen = 1; - if (e->m1 <= (unsigned long)(0xFFFFFFFF)/10) { - struct mantissa a1; + if (e->m1 <= (unsigned long)(0xFFFFFFFF) / 10) + { + struct mantissa a1; a1 = e->mantissa; b64_sft(&(e->mantissa), -3); @@ -492,55 +536,67 @@ _str_ext_cvt(const char *s, char **ss, struct EXTEND *e) a1.l_32 = c - '0'; b64_add(&(e->mantissa), &a1); } - else exp++; - if (dotseen) exp--; + else + exp++; + if (dotseen) + exp--; } - if (! digitseen) return; + if (!digitseen) + return; - if (ss) *ss = (char *)s - 1; + if (ss) + *ss = (char*)s - 1; - if (c == 'E' || c == 'e') { - int exp1 = 0; - int sign = 1; - int exp_overflow = 0; + if (c == 'E' || c == 'e') + { + int exp1 = 0; + int sign = 1; + int exp_overflow = 0; - switch(*s) { - case '-': - sign = -1; - case '+': - s++; + switch (*s) + { + case '-': + sign = -1; + case '+': + s++; } - if (c = *s, isdigit(c)) { - do { + if (c = *s, isdigit(c)) + { + do + { int tmp; exp1 = 10 * exp1 + (c - '0'); - if ((tmp = sign * exp1 + exp) > MAX_EXP || - tmp < -MAX_EXP) { + if ((tmp = sign * exp1 + exp) > MAX_EXP || tmp < -MAX_EXP) + { exp_overflow = 1; } } while (c = *++s, isdigit(c)); - if (ss) *ss = (char *)s; + if (ss) + *ss = (char*)s; } exp += sign * exp1; - if (exp_overflow) { + if (exp_overflow) + { exp = sign * MAX_EXP; - if (e->m1 != 0 || e->m2 != 0) errno = ERANGE; + if (e->m1 != 0 || e->m2 != 0) + errno = ERANGE; } } - if (e->m1 == 0 && e->m2 == 0) return; + if (e->m1 == 0 && e->m2 == 0) + return; e->exp = 63; - while (! (e->m1 & 0x80000000)) { - b64_sft(&(e->mantissa),-1); + while (!(e->m1 & 0x80000000)) + { + b64_sft(&(e->mantissa), -1); e->exp--; } add_exponent(e, exp); } -#include +#include -static -ten_mult(struct EXTEND *e) +static ten_mult(struct EXTEND* e) { struct EXTEND e1 = *e; @@ -552,50 +608,58 @@ ten_mult(struct EXTEND *e) #define NDIGITS 128 #define NSIGNIFICANT 19 -char * -_ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag) +char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag) { /* Like cvt(), but for extended precision */ - static char buf[NDIGITS+1]; + static char buf[NDIGITS + 1]; struct EXTEND m; - register char *p = buf; - register char *pe; + register char* p = buf; + register char* pe; int findex = 0; - if (ndigit < 0) ndigit = 0; - if (ndigit > NDIGITS) ndigit = NDIGITS; + if (ndigit < 0) + ndigit = 0; + if (ndigit > NDIGITS) + ndigit = NDIGITS; pe = &buf[ndigit]; buf[0] = '\0'; *sign = 0; - if (e->sign) { + if (e->sign) + { *sign = 1; e->sign = 0; } *decpt = 0; - if (e->m1 != 0) { - register struct EXTEND *pp = &big_ten_powers[1]; + if (e->m1 != 0) + { + register struct EXTEND* pp = &big_ten_powers[1]; - while(cmp_ext(e,pp) >= 0) { + while (cmp_ext(e, pp) >= 0) + { pp++; findex = pp - big_ten_powers; - if (findex >= BTP) break; + if (findex >= BTP) + break; } pp--; findex = pp - big_ten_powers; - mul_ext(e,&r_big_ten_powers[findex],e); + mul_ext(e, &r_big_ten_powers[findex], e); *decpt += findex * TP; pp = &ten_powers[1]; - while(pp < &ten_powers[TP] && cmp_ext(e, pp) >= 0) pp++; + while (pp < &ten_powers[TP] && cmp_ext(e, pp) >= 0) + pp++; pp--; findex = pp - ten_powers; *decpt += findex; - if (cmp_ext(e, &ten_powers[0]) < 0) { + if (cmp_ext(e, &ten_powers[0]) < 0) + { pp = &r_big_ten_powers[1]; - while(cmp_ext(e,pp) < 0) pp++; + while (cmp_ext(e, pp) < 0) + pp++; pp--; findex = pp - r_big_ten_powers; mul_ext(e, &big_ten_powers[findex], e); @@ -604,31 +668,37 @@ _ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag) ten_mult(e); (*decpt)--; pp = &r_ten_powers[0]; - while(cmp_ext(e, pp) < 0) pp++; + while (cmp_ext(e, pp) < 0) + pp++; findex = pp - r_ten_powers; mul_ext(e, &ten_powers[findex], e); *decpt -= findex; findex = 0; } - (*decpt)++; /* because now value in [1.0, 10.0) */ + (*decpt)++; /* because now value in [1.0, 10.0) */ } - if (! ecvtflag) { + if (!ecvtflag) + { /* for fcvt() we need ndigit digits behind the dot */ pe += *decpt; - if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS]; + if (pe > &buf[NDIGITS]) + pe = &buf[NDIGITS]; } m.exp = -62; m.sign = 0; m.m1 = 0xA0000000; m.m2 = 0; - while (p <= pe) { + while (p <= pe) + { struct EXTEND oneminm; - if (p - pe > NSIGNIFICANT) { + if (p - pe > NSIGNIFICANT) + { findex = 0; e->m1 = 0; } - if (findex) { + if (findex) + { struct EXTEND tc, oldtc; int count = 0; @@ -637,7 +707,8 @@ _ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag) oldtc.m1 = 0; oldtc.m2 = 0; tc = ten_powers[findex]; - while (cmp_ext(e, &tc) >= 0) { + while (cmp_ext(e, &tc) >= 0) + { oldtc = tc; add_ext(&tc, &ten_powers[findex], &tc); count++; @@ -648,46 +719,59 @@ _ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag) findex--; continue; } - if (e->m1) { + if (e->m1) + { m.sign = 1; add_ext(&ten_powers[0], &m, &oneminm); m.sign = 0; - if (e->exp >= 0) { + if (e->exp >= 0) + { struct EXTEND x; - x.m2 = 0; x.exp = e->exp; + x.m2 = 0; + x.exp = e->exp; x.sign = 1; - x.m1 = e->m1>>(31-e->exp); + x.m1 = e->m1 >> (31 - e->exp); *p++ = (x.m1) + '0'; - x.m1 = x.m1 << (31-e->exp); + x.m1 = x.m1 << (31 - e->exp); add_ext(e, &x, e); } - else *p++ = '0'; + else + *p++ = '0'; /* Check that remainder is still significant */ - if (cmp_ext(&m, e) > 0 || cmp_ext(e, &oneminm) > 0) { - if (e->m1 && e->exp >= -1) *(p-1) += 1; + if (cmp_ext(&m, e) > 0 || cmp_ext(e, &oneminm) > 0) + { + if (e->m1 && e->exp >= -1) + *(p - 1) += 1; e->m1 = 0; continue; } ten_mult(&m); ten_mult(e); } - else *p++ = '0'; + else + *p++ = '0'; } - if (pe >= buf) { + if (pe >= buf) + { p = pe; - *p += 5; /* round of at the end */ - while (*p > '9') { + *p += 5; /* round of at the end */ + while (*p > '9') + { *p = '0'; - if (p > buf) ++*--p; - else { + if (p > buf) + ++*--p; + else + { *p = '1'; ++*decpt; - if (! ecvtflag) { + if (!ecvtflag) + { /* maybe add another digit at the end, because the point was shifted right */ - if (pe > buf) *pe = '0'; + if (pe > buf) + *pe = '0'; pe++; } } @@ -697,7 +781,7 @@ _ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag) return buf; } -_dbl_ext_cvt(double value, struct EXTEND *e) +_dbl_ext_cvt(double value, struct EXTEND* e) { /* Convert double to extended */ @@ -705,7 +789,8 @@ _dbl_ext_cvt(double value, struct EXTEND *e) value = frexp(value, &exponent); e->sign = value < 0.0; - if (e->sign) value = -value; + if (e->sign) + value = -value; e->exp = exponent - 1; value *= 4294967296.0; e->m1 = value; @@ -717,7 +802,7 @@ _dbl_ext_cvt(double value, struct EXTEND *e) static struct EXTEND max_d; double -_ext_dbl_cvt(struct EXTEND *e) +_ext_dbl_cvt(struct EXTEND* e) { /* Convert extended to double */ @@ -725,19 +810,25 @@ _ext_dbl_cvt(struct EXTEND *e) int sign = e->sign; e->sign = 0; - if (e->m1 == 0 && e->m2 == 0) { + if (e->m1 == 0 && e->m2 == 0) + { return 0.0; } - if (max_d.exp == 0) { + if (max_d.exp == 0) + { _dbl_ext_cvt(DBL_MAX, &max_d); } - if (cmp_ext(&max_d, e) < 0) { + if (cmp_ext(&max_d, e) < 0) + { f = HUGE_VAL; errno = ERANGE; } - else f = ldexp((double)e->m1*4294967296.0 + (double)e->m2, e->exp-63); - if (sign) f = -f; - if (f == 0.0 && (e->m1 != 0 || e->m2 != 0)) { + else + f = ldexp((double)e->m1 * 4294967296.0 + (double)e->m2, e->exp - 63); + if (sign) + f = -f; + if (f == 0.0 && (e->m1 != 0 || e->m2 != 0)) + { errno = ERANGE; } return f; diff --git a/lang/cem/libcc.ansi/stdlib/getenv.c b/lang/cem/libcc.ansi/stdlib/getenv.c index 592e0c05d..3db5c3797 100644 --- a/lang/cem/libcc.ansi/stdlib/getenv.c +++ b/lang/cem/libcc.ansi/stdlib/getenv.c @@ -15,9 +15,9 @@ extern char* _findenv(const char* name, int* offset); */ char* getenv(const char* name) { - int offset; + int offset; - return(_findenv(name,&offset)); + return (_findenv(name, &offset)); } /* @@ -31,21 +31,22 @@ char* getenv(const char* name) */ char* _findenv(register const char* name, int* offset) { - extern char **environ; - register int len; - register char **P; - register const char *C; + extern char** environ; + register int len; + register char** P; + register const char* C; if (!environ) return NULL; - for (C = name,len = 0;*C && *C != '=';++C,++len); - for (P = environ;*P;++P) - if (!strncmp(*P,name,len)) - if (*(C = *P + len) == '=') { - *offset = P - environ; - return (char*)(++C); - } - return(NULL); + for (C = name, len = 0; *C && *C != '='; ++C, ++len) + ; + for (P = environ; *P; ++P) + if (!strncmp(*P, name, len)) + if (*(C = *P + len) == '=') + { + *offset = P - environ; + return (char*)(++C); + } + return (NULL); } - diff --git a/lang/cem/libcc.ansi/stdlib/labs.c b/lang/cem/libcc.ansi/stdlib/labs.c index c19464939..e0acaed86 100644 --- a/lang/cem/libcc.ansi/stdlib/labs.c +++ b/lang/cem/libcc.ansi/stdlib/labs.c @@ -4,10 +4,9 @@ */ /* $Id$ */ -#include +#include -long -labs(register long l) +long labs(register long l) { return l >= 0 ? l : -l; } diff --git a/lang/cem/libcc.ansi/stdlib/ldiv.c b/lang/cem/libcc.ansi/stdlib/ldiv.c index 4f2b25eb2..e35c06715 100644 --- a/lang/cem/libcc.ansi/stdlib/ldiv.c +++ b/lang/cem/libcc.ansi/stdlib/ldiv.c @@ -4,17 +4,18 @@ */ /* $Id$ */ -#include +#include ldiv_t ldiv(register long numer, register long denom) { ldiv_t r; - r.quot = numer / denom; /* might trap if denom == 0 */ + r.quot = numer / denom; /* might trap if denom == 0 */ r.rem = numer % denom; - if (r.rem != 0 && (numer > 0) != (r.rem > 0)) { + if (r.rem != 0 && (numer > 0) != (r.rem > 0)) + { r.quot++; r.rem -= denom; } diff --git a/lang/cem/libcc.ansi/stdlib/mblen.c b/lang/cem/libcc.ansi/stdlib/mblen.c index f3c54a540..4c8f728e9 100644 --- a/lang/cem/libcc.ansi/stdlib/mblen.c +++ b/lang/cem/libcc.ansi/stdlib/mblen.c @@ -4,15 +4,16 @@ */ /* $Id$ */ -#include -#include +#include +#include -#define CHAR_SHIFT 8 +#define CHAR_SHIFT 8 -int -(mblen)(const char *s, size_t n) +int(mblen)(const char* s, size_t n) { - if (s == (const char *)NULL) return 0; /* no state dependent codings */ - if (n <= 0) return 0; + if (s == (const char*)NULL) + return 0; /* no state dependent codings */ + if (n <= 0) + return 0; return (*s != 0); } diff --git a/lang/cem/libcc.ansi/stdlib/mbstowcs.c b/lang/cem/libcc.ansi/stdlib/mbstowcs.c index e2a6cf362..34d120e60 100644 --- a/lang/cem/libcc.ansi/stdlib/mbstowcs.c +++ b/lang/cem/libcc.ansi/stdlib/mbstowcs.c @@ -4,17 +4,17 @@ */ /* $Id$ */ -#include +#include size_t -mbstowcs(register wchar_t *pwcs, register const char *s, size_t n) +mbstowcs(register wchar_t* pwcs, register const char* s, size_t n) { register int i = n; - while (--i >= 0) { + while (--i >= 0) + { if (!(*pwcs++ = *s++)) return n - i - 1; } return n - i; } - diff --git a/lang/cem/libcc.ansi/stdlib/mbtowc.c b/lang/cem/libcc.ansi/stdlib/mbtowc.c index 3b1687c55..8e80ca263 100644 --- a/lang/cem/libcc.ansi/stdlib/mbtowc.c +++ b/lang/cem/libcc.ansi/stdlib/mbtowc.c @@ -4,14 +4,16 @@ */ /* $Id$ */ -#include -#include +#include +#include -int -mbtowc(wchar_t *pwc, register const char *s, size_t n) +int mbtowc(wchar_t* pwc, register const char* s, size_t n) { - if (s == (const char *)NULL) return 0; - if (n <= 0) return 0; - if (pwc) *pwc = *s; + if (s == (const char*)NULL) + return 0; + if (n <= 0) + return 0; + if (pwc) + *pwc = *s; return (*s != 0); } diff --git a/lang/cem/libcc.ansi/stdlib/putenv.c b/lang/cem/libcc.ansi/stdlib/putenv.c index a1f94aba4..09412f341 100644 --- a/lang/cem/libcc.ansi/stdlib/putenv.c +++ b/lang/cem/libcc.ansi/stdlib/putenv.c @@ -4,39 +4,45 @@ */ /* $Id$ */ -#include -#include +#include +#include -#define ENTRY_INC 10 -#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC) +#define ENTRY_INC 10 +#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC) -extern char **environ; +extern char** environ; -int -putenv(char *name) +int putenv(char* name) { - register char **v = environ; - register char *r; + register char** v = environ; + register char* r; static int size = 0; /* When size != 0, it contains the number of entries in the * table (including the final NULL pointer). This means that the * last non-null entry is environ[size - 2]. */ - if (!name) return 0; - if (r = strchr(name, '=')) { + if (!name) + return 0; + if (r = strchr(name, '=')) + { register const char *p, *q; *r = '\0'; - if (v != NULL) { - while ((p = *v) != NULL) { + if (v != NULL) + { + while ((p = *v) != NULL) + { q = name; while (*q && (*q++ == *p++)) - /* EMPTY */ ; - if (*q || (*p != '=')) { + /* EMPTY */; + if (*q || (*p != '=')) + { v++; - } else { + } + else + { /* The name was already in the * environment. */ @@ -50,23 +56,28 @@ putenv(char *name) v = environ; } - if (!size) { - register char **p; + if (!size) + { + register char** p; register int i = 0; if (v) - do { + do + { i++; } while (*v++); - if (!(v = malloc(rounded(i) * sizeof(char **)))) + if (!(v = malloc(rounded(i) * sizeof(char**)))) return 1; size = i; p = environ; environ = v; - while (*v++ = *p++); /* copy the environment */ + while (*v++ = *p++) + ; /* copy the environment */ v = environ; - } else if (!(size % ENTRY_INC)) { - if (!(v = realloc(environ, rounded(size) * sizeof(char **)))) + } + else if (!(size % ENTRY_INC)) + { + if (!(v = realloc(environ, rounded(size) * sizeof(char**)))) return 1; environ = v; } diff --git a/lang/cem/libcc.ansi/stdlib/qsort.c b/lang/cem/libcc.ansi/stdlib/qsort.c index c7211fea8..c3129fcff 100644 --- a/lang/cem/libcc.ansi/stdlib/qsort.c +++ b/lang/cem/libcc.ansi/stdlib/qsort.c @@ -4,36 +4,38 @@ */ /* $Id$ */ -#include +#include -static void qsort1(char *, char *, size_t); -static int (*qcompar)(const char *, const char *); -static void qexchange(char *, char *, size_t); -static void q3exchange(char *, char *, char *, size_t); +static void qsort1(char*, char*, size_t); +static int (*qcompar)(const char*, const char*); +static void qexchange(char*, char*, size_t); +static void q3exchange(char*, char*, char*, size_t); -void -qsort(void *base, size_t nel, size_t width, - int (*compar)(const void *, const void *)) +void qsort(void* base, size_t nel, size_t width, + int (*compar)(const void*, const void*)) { /* when nel is 0, the expression '(nel - 1) * width' is wrong */ - if (!nel) return; - qcompar = (int (*)(const char *, const char *)) compar; - qsort1(base, (char *)base + (nel - 1) * width, width); + if (!nel) + return; + qcompar = (int (*)(const char*, const char*))compar; + qsort1(base, (char*)base + (nel - 1) * width, width); } static void -qsort1(char *a1, char *a2, register size_t width) +qsort1(char* a1, char* a2, register size_t width) { register char *left, *right; register char *lefteq, *righteq; int cmp; - for (;;) { - if (a2 <= a1) return; + for (;;) + { + if (a2 <= a1) + return; left = a1; right = a2; - lefteq = righteq = a1 + width * (((a2-a1)+width)/(2*width)); - /* + lefteq = righteq = a1 + width * (((a2 - a1) + width) / (2 * width)); + /* Pick an element in the middle of the array. We will collect the equals around it. "lefteq" and "righteq" indicate the left and right @@ -41,13 +43,16 @@ qsort1(char *a1, char *a2, register size_t width) Smaller elements end up left of it, larger elements end up right of it. */ -again: - while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) { - if (cmp < 0) { + again: + while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) + { + if (cmp < 0) + { /* leave it where it is */ left += width; } - else { + else + { /* equal, so exchange with the element to the left of the "equal"-interval. */ @@ -55,11 +60,14 @@ again: qexchange(left, lefteq, width); } } - while (right > righteq) { - if ((cmp = (*qcompar)(right, righteq)) < 0) { + while (right > righteq) + { + if ((cmp = (*qcompar)(right, righteq)) < 0) + { /* smaller, should go to left part */ - if (left < lefteq) { + if (left < lefteq) + { /* yes, we had a larger one at the left, so we can just exchange */ @@ -80,16 +88,19 @@ again: lefteq += width; left = lefteq; } - else if (cmp == 0) { + else if (cmp == 0) + { /* equal, so exchange with the element to the right of the "equal-interval" */ righteq += width; qexchange(right, righteq, width); } - else /* just leave it */ right -= width; + else /* just leave it */ + right -= width; } - if (left < lefteq) { + if (left < lefteq) + { /* larger element to the left, but no more room, so move the "equal-interval" one place to the left, and the larger element to the right @@ -112,12 +123,13 @@ again: } static void -qexchange(register char *p, register char *q, - register size_t n) +qexchange(register char* p, register char* q, + register size_t n) { register int c; - while (n-- > 0) { + while (n-- > 0) + { c = *p; *p++ = *q; *q++ = c; @@ -125,12 +137,13 @@ qexchange(register char *p, register char *q, } static void -q3exchange(register char *p, register char *q, register char *r, - register size_t n) +q3exchange(register char* p, register char* q, register char* r, + register size_t n) { register int c; - while (n-- > 0) { + while (n-- > 0) + { c = *p; *p++ = *r; *r++ = *q; diff --git a/lang/cem/libcc.ansi/stdlib/rand.c b/lang/cem/libcc.ansi/stdlib/rand.c index 87b5e1b5c..20f72e26b 100644 --- a/lang/cem/libcc.ansi/stdlib/rand.c +++ b/lang/cem/libcc.ansi/stdlib/rand.c @@ -4,14 +4,14 @@ */ /* $Id$ */ -#include +#include static unsigned long int next = 1; int rand(void) { next = next * 1103515245 + 12345; - return (unsigned int)(next/(2 * (RAND_MAX +1L)) % (RAND_MAX+1L)); + return (unsigned int)(next / (2 * (RAND_MAX + 1L)) % (RAND_MAX + 1L)); } void srand(unsigned int seed) diff --git a/lang/cem/libcc.ansi/stdlib/setenv.c b/lang/cem/libcc.ansi/stdlib/setenv.c index 086b2118d..e6f7b8d88 100644 --- a/lang/cem/libcc.ansi/stdlib/setenv.c +++ b/lang/cem/libcc.ansi/stdlib/setenv.c @@ -8,7 +8,7 @@ #include extern char* _findenv(const char* name, int* offset); -extern char **environ; +extern char** environ; /* * setenv(name,value,rewrite) @@ -17,71 +17,78 @@ extern char **environ; */ int setenv(register const char* name, register const char* value, int rewrite) { - static int alloced = 0; /* if allocated space before */ - register char *C; - int l_value, - offset; + static int alloced = 0; /* if allocated space before */ + register char* C; + int l_value, + offset; - if (*value == '=') /* no `=' in value */ - ++value; - l_value = strlen(value); - if ((C = _findenv(name,&offset))) { /* find if already exists */ - if (!rewrite) - return(0); - if (strlen(C) >= l_value) { /* old larger; copy over */ - while (*C++ = *value++); - return(0); - } - } - else { /* create new slot */ - register int cnt = 0; - register char **P; + if (*value == '=') /* no `=' in value */ + ++value; + l_value = strlen(value); + if ((C = _findenv(name, &offset))) + { /* find if already exists */ + if (!rewrite) + return (0); + if (strlen(C) >= l_value) + { /* old larger; copy over */ + while (*C++ = *value++) + ; + return (0); + } + } + else + { /* create new slot */ + register int cnt = 0; + register char** P; if (environ) - for (P = environ;*P;++P,++cnt); - if (alloced) { /* just increase size */ - environ = (char **)realloc((char *)environ, - (unsigned)(sizeof(char *) * (cnt + 2))); - if (!environ) - return(-1); - } - else { /* get new space */ - alloced = 1; /* copy old entries into it */ - P = (char **)malloc((unsigned)(sizeof(char *) * - (cnt + 2))); - if (!P) - return(-1); - if (environ) - bcopy(environ,P,cnt * sizeof(char *)); - environ = P; - } - environ[cnt + 1] = NULL; - offset = cnt; - } - for (C = name;*C && *C != '=';++C); /* no `=' in name */ - if (!(environ[offset] = /* name + `=' + value */ - malloc((unsigned)((int)(C - name) + l_value + 2)))) - return(-1); - for (C = environ[offset];(*C = *name++) && *C != '=';++C); - for (*C++ = '=';*C++ = *value++;); - return(0); + for (P = environ; *P; ++P, ++cnt) + ; + if (alloced) + { /* just increase size */ + environ = (char**)realloc((char*)environ, + (unsigned)(sizeof(char*) * (cnt + 2))); + if (!environ) + return (-1); + } + else + { /* get new space */ + alloced = 1; /* copy old entries into it */ + P = (char**)malloc((unsigned)(sizeof(char*) * (cnt + 2))); + if (!P) + return (-1); + if (environ) + bcopy(environ, P, cnt * sizeof(char*)); + environ = P; + } + environ[cnt + 1] = NULL; + offset = cnt; + } + for (C = name; *C && *C != '='; ++C) + ; /* no `=' in name */ + if (!(environ[offset] = /* name + `=' + value */ + malloc((unsigned)((int)(C - name) + l_value + 2)))) + return (-1); + for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) + ; + for (*C++ = '='; *C++ = *value++;) + ; + return (0); } /* * unsetenv(name) -- * Delete environmental variable "name". */ -int -unsetenv(const char* name) +int unsetenv(const char* name) { - register char **P; - int offset; + register char** P; + int offset; - while (_findenv(name,&offset)) /* if set multiple times */ - for (P = &environ[offset];;++P) - if (!(*P = *(P + 1))) - break; + while (_findenv(name, &offset)) /* if set multiple times */ + for (P = &environ[offset];; ++P) + if (!(*P = *(P + 1))) + break; - return 0; + return 0; } - diff --git a/lang/cem/libcc.ansi/stdlib/strtod.c b/lang/cem/libcc.ansi/stdlib/strtod.c index 222a744b9..48f60e200 100644 --- a/lang/cem/libcc.ansi/stdlib/strtod.c +++ b/lang/cem/libcc.ansi/stdlib/strtod.c @@ -1,15 +1,15 @@ /* $Id$ */ -#include -#include "ext_fmt.h" +#include +#include "ext_fmt.h" -#ifndef ACKCONF_NO_STDIO_FLOAT +#ifndef ACKCONF_NO_STDIO_FLOAT -void _str_ext_cvt(const char *s, char **ss, struct EXTEND *e); -double _ext_dbl_cvt(struct EXTEND *e); +void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); +double _ext_dbl_cvt(struct EXTEND* e); double -strtod(const char *p, char **pp) +strtod(const char* p, char** pp) { struct EXTEND e; diff --git a/lang/cem/libcc.ansi/stdlib/strtol.c b/lang/cem/libcc.ansi/stdlib/strtol.c index ad9a5166c..ce072d49d 100644 --- a/lang/cem/libcc.ansi/stdlib/strtol.c +++ b/lang/cem/libcc.ansi/stdlib/strtol.c @@ -4,30 +4,30 @@ */ /* $Id$ */ -#include -#include -#include -#include +#include +#include +#include +#include static unsigned long -string2long(register const char *nptr, char **endptr, - int base, int is_signed); +string2long(register const char* nptr, char** endptr, + int base, int is_signed); long int -strtol(register const char *nptr, char **endptr, int base) +strtol(register const char* nptr, char** endptr, int base) { return (signed long)string2long(nptr, endptr, base, 1); } unsigned long int -strtoul(register const char *nptr, char **endptr, int base) +strtoul(register const char* nptr, char** endptr, int base) { return (unsigned long)string2long(nptr, endptr, base, 0); } static unsigned long -string2long(register const char *nptr, char ** const endptr, - int base, int is_signed) +string2long(register const char* nptr, char** const endptr, + int base, int is_signed) { register unsigned int v; register unsigned long val = 0; @@ -35,62 +35,82 @@ string2long(register const char *nptr, char ** const endptr, int ovfl = 0, sign = 1; const char *startnptr = nptr, *nrstart; - if (endptr) *endptr = (char *)nptr; - while (isspace(*nptr)) nptr++; + if (endptr) + *endptr = (char*)nptr; + while (isspace(*nptr)) + nptr++; c = *nptr; - if (c == '-' || c == '+') { - if (c == '-') sign = -1; + if (c == '-' || c == '+') + { + if (c == '-') + sign = -1; nptr++; } - nrstart = nptr; /* start of the number */ + nrstart = nptr; /* start of the number */ /* When base is 0, the syntax determines the actual base */ if (base == 0) if (*nptr == '0') - if (*++nptr == 'x' || *nptr == 'X') { + if (*++nptr == 'x' || *nptr == 'X') + { base = 16; nptr++; } - else base = 8; - else base = 10; - else if (base==16 && *nptr=='0' && (*++nptr =='x' || *nptr =='X')) + else + base = 8; + else + base = 10; + else if (base == 16 && *nptr == '0' && (*++nptr == 'x' || *nptr == 'X')) nptr++; - while (isdigit(c = *nptr) || isalpha(c)) { - if (!ovfl) { + while (isdigit(c = *nptr) || isalpha(c)) + { + if (!ovfl) + { if (isalpha(c)) v = 10 + (isupper(c) ? c - 'A' : c - 'a'); else v = c - '0'; - if (v >= base) break; - if (val > (ULONG_MAX - v) / base) ++ovfl; - else val = (val * base) + v; + if (v >= base) + break; + if (val > (ULONG_MAX - v) / base) + ++ovfl; + else + val = (val * base) + v; } nptr++; } - if (endptr) { - if (nrstart == nptr) *endptr = (char *)startnptr; - else *endptr = (char *)nptr; + if (endptr) + { + if (nrstart == nptr) + *endptr = (char*)startnptr; + else + *endptr = (char*)nptr; } - if (!ovfl) { + if (!ovfl) + { /* Overflow is only possible when converting a signed long. * The "-(LONG_MIN+1)+(unsigned long) 1" construction is there * to prevent overflow warnings on -LONG_MIN. */ if (is_signed - && ( (sign < 0 && val > -(LONG_MIN+1)+(unsigned long) 1) - || (sign > 0 && val > LONG_MAX))) - ovfl++; + && ((sign < 0 && val > -(LONG_MIN + 1) + (unsigned long)1) + || (sign > 0 && val > LONG_MAX))) + ovfl++; } - if (ovfl) { + if (ovfl) + { errno = ERANGE; if (is_signed) - if (sign < 0) return LONG_MIN; - else return LONG_MAX; - else return ULONG_MAX; + if (sign < 0) + return LONG_MIN; + else + return LONG_MAX; + else + return ULONG_MAX; } return (sign * val); } diff --git a/lang/cem/libcc.ansi/stdlib/system.c b/lang/cem/libcc.ansi/stdlib/system.c index 99a8d6e6a..ba31b0477 100644 --- a/lang/cem/libcc.ansi/stdlib/system.c +++ b/lang/cem/libcc.ansi/stdlib/system.c @@ -4,7 +4,7 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#if defined(_POSIX_SOURCE) #include #endif #include @@ -13,48 +13,55 @@ extern char** environ; extern int _fork(void); -extern int _wait(int *); +extern int _wait(int*); extern void _exit(int); -extern void _execve(const char *path, const char ** argv, const char ** envp); +extern void _execve(const char* path, const char** argv, const char** envp); extern void _close(int); -#define FAIL 127 +#define FAIL 127 -static const char *exec_tab[] = { - "sh", /* argv[0] */ - "-c", /* argument to the shell */ - NULL, /* to be filled with user command */ - NULL /* terminating NULL */ - }; +static const char* exec_tab[] = { + "sh", /* argv[0] */ + "-c", /* argument to the shell */ + NULL, /* to be filled with user command */ + NULL /* terminating NULL */ +}; -int -system(const char *str) +int system(const char* str) { int pid, exitstatus, waitval; int i; - if ((pid = _fork()) < 0) return str ? -1 : 0; + if ((pid = _fork()) < 0) + return str ? -1 : 0; - if (pid == 0) { + if (pid == 0) + { for (i = 3; i <= 20; i++) _close(i); - if (!str) str = "cd ."; /* just testing for a shell */ - exec_tab[2] = str; /* fill in command */ - _execve("/bin/sh", exec_tab, (char const**) environ); + if (!str) + str = "cd ."; /* just testing for a shell */ + exec_tab[2] = str; /* fill in command */ + _execve("/bin/sh", exec_tab, (char const**)environ); /* get here if execve fails ... */ - _exit(FAIL); /* see manual page */ + _exit(FAIL); /* see manual page */ } - while ((waitval = _wait(&exitstatus)) != pid) { - if (waitval == -1) break; + while ((waitval = _wait(&exitstatus)) != pid) + { + if (waitval == -1) + break; } - if (waitval == -1) { + if (waitval == -1) + { /* no child ??? or maybe interrupted ??? */ exitstatus = -1; } - if (!str) { - if (exitstatus == FAIL << 8) /* execve() failed */ + if (!str) + { + if (exitstatus == FAIL << 8) /* execve() failed */ exitstatus = 0; - else exitstatus = 1; /* /bin/sh exists */ + else + exitstatus = 1; /* /bin/sh exists */ } return exitstatus; } diff --git a/lang/cem/libcc.ansi/stdlib/wcstombs.c b/lang/cem/libcc.ansi/stdlib/wcstombs.c index fccd626ed..2803b7b2a 100644 --- a/lang/cem/libcc.ansi/stdlib/wcstombs.c +++ b/lang/cem/libcc.ansi/stdlib/wcstombs.c @@ -4,16 +4,17 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include size_t -wcstombs(register char *s, register const wchar_t *pwcs, size_t n) +wcstombs(register char* s, register const wchar_t* pwcs, size_t n) { register int i = n; - while (--i >= 0) { + while (--i >= 0) + { if (!(*s++ = *pwcs++)) break; } diff --git a/lang/cem/libcc.ansi/stdlib/wctomb.c b/lang/cem/libcc.ansi/stdlib/wctomb.c index 3322b0d9c..d80f0baf0 100644 --- a/lang/cem/libcc.ansi/stdlib/wctomb.c +++ b/lang/cem/libcc.ansi/stdlib/wctomb.c @@ -4,13 +4,13 @@ */ /* $Id$ */ -#include -#include +#include +#include -int -wctomb(char *s, wchar_t wchar) +int wctomb(char* s, wchar_t wchar) { - if (!s) return 0; /* no state dependent codings */ + if (!s) + return 0; /* no state dependent codings */ *s = wchar; return 1; diff --git a/lang/cem/libcc.ansi/string/memchr.c b/lang/cem/libcc.ansi/string/memchr.c index 067776b4b..0d891e83d 100644 --- a/lang/cem/libcc.ansi/string/memchr.c +++ b/lang/cem/libcc.ansi/string/memchr.c @@ -4,19 +4,21 @@ */ /* $Id$ */ -#include +#include -void * -memchr(const void *s, register int c, register size_t n) +void* memchr(const void* s, register int c, register size_t n) { - register const unsigned char *s1 = s; + register const unsigned char* s1 = s; - c = (unsigned char) c; - if (n) { + c = (unsigned char)c; + if (n) + { n++; - while (--n > 0) { - if (*s1++ != c) continue; - return (void *) --s1; + while (--n > 0) + { + if (*s1++ != c) + continue; + return (void*)--s1; } } return NULL; diff --git a/lang/cem/libcc.ansi/string/memcmp.c b/lang/cem/libcc.ansi/string/memcmp.c index b44eefcf4..625dbaafb 100644 --- a/lang/cem/libcc.ansi/string/memcmp.c +++ b/lang/cem/libcc.ansi/string/memcmp.c @@ -4,17 +4,19 @@ */ /* $Id$ */ -#include +#include -int -memcmp(const void *s1, const void *s2, size_t n) +int memcmp(const void* s1, const void* s2, size_t n) { register const unsigned char *p1 = s1, *p2 = s2; - if (n) { + if (n) + { n++; - while (--n > 0) { - if (*p1++ == *p2++) continue; + while (--n > 0) + { + if (*p1++ == *p2++) + continue; return *--p1 - *--p2; } } diff --git a/lang/cem/libcc.ansi/string/memcpy.c b/lang/cem/libcc.ansi/string/memcpy.c index 32d4ba29c..d648815cd 100644 --- a/lang/cem/libcc.ansi/string/memcpy.c +++ b/lang/cem/libcc.ansi/string/memcpy.c @@ -4,18 +4,18 @@ */ /* $Id$ */ -#include +#include -void * -memcpy(void *s1, const void *s2, register size_t n) +void* memcpy(void* s1, const void* s2, register size_t n) { - register char *p1 = s1; - register const char *p2 = s2; + register char* p1 = s1; + register const char* p2 = s2; - - if (n) { + if (n) + { n++; - while (--n > 0) { + while (--n > 0) + { *p1++ = *p2++; } } diff --git a/lang/cem/libcc.ansi/string/memmove.c b/lang/cem/libcc.ansi/string/memmove.c index ec1dd8bad..78fbd0c6a 100644 --- a/lang/cem/libcc.ansi/string/memmove.c +++ b/lang/cem/libcc.ansi/string/memmove.c @@ -4,26 +4,31 @@ */ /* $Id$ */ -#include +#include -void * -memmove(void *s1, const void *s2, register size_t n) +void* memmove(void* s1, const void* s2, register size_t n) { - register char *p1 = s1; - register const char *p2 = s2; + register char* p1 = s1; + register const char* p2 = s2; - if (n>0) { - if (p2 <= p1 && p2 + n > p1) { + if (n > 0) + { + if (p2 <= p1 && p2 + n > p1) + { /* overlap, copy backwards */ p1 += n; p2 += n; n++; - while (--n > 0) { + while (--n > 0) + { *--p1 = *--p2; } - } else { + } + else + { n++; - while (--n > 0) { + while (--n > 0) + { *p1++ = *p2++; } } diff --git a/lang/cem/libcc.ansi/string/memset.c b/lang/cem/libcc.ansi/string/memset.c index 266b10c07..649f8c783 100644 --- a/lang/cem/libcc.ansi/string/memset.c +++ b/lang/cem/libcc.ansi/string/memset.c @@ -4,16 +4,17 @@ */ /* $Id$ */ -#include +#include -void * -memset(void *s, register int c, register size_t n) +void* memset(void* s, register int c, register size_t n) { - register char *s1 = s; + register char* s1 = s; - if (n>0) { + if (n > 0) + { n++; - while (--n > 0) { + while (--n > 0) + { *s1++ = c; } } diff --git a/lang/cem/libcc.ansi/string/strcat.c b/lang/cem/libcc.ansi/string/strcat.c index 4ef13ea17..613050957 100644 --- a/lang/cem/libcc.ansi/string/strcat.c +++ b/lang/cem/libcc.ansi/string/strcat.c @@ -4,17 +4,16 @@ */ /* $Id$ */ -#include +#include -char * -strcat(char *ret, register const char *s2) +char* strcat(char* ret, register const char* s2) { - register char *s1 = ret; + register char* s1 = ret; while (*s1++ != '\0') - /* EMPTY */ ; + /* EMPTY */; s1--; while (*s1++ = *s2++) - /* EMPTY */ ; + /* EMPTY */; return ret; } diff --git a/lang/cem/libcc.ansi/string/strchr.c b/lang/cem/libcc.ansi/string/strchr.c index 2e7df4c23..da906e136 100644 --- a/lang/cem/libcc.ansi/string/strchr.c +++ b/lang/cem/libcc.ansi/string/strchr.c @@ -4,15 +4,16 @@ */ /* $Id$ */ -#include +#include -char * -strchr(register const char *s, register int c) +char* strchr(register const char* s, register int c) { - c = (char) c; + c = (char)c; - while (c != *s) { - if (*s++ == '\0') return NULL; + while (c != *s) + { + if (*s++ == '\0') + return NULL; } - return (char *)s; + return (char*)s; } diff --git a/lang/cem/libcc.ansi/string/strcmp.c b/lang/cem/libcc.ansi/string/strcmp.c index bfe801905..12406c956 100644 --- a/lang/cem/libcc.ansi/string/strcmp.c +++ b/lang/cem/libcc.ansi/string/strcmp.c @@ -4,17 +4,20 @@ */ /* $Id$ */ -#include +#include -int -strcmp(register const char *s1, register const char *s2) +int strcmp(register const char* s1, register const char* s2) { - while (*s1 == *s2++) { - if (*s1++ == '\0') { + while (*s1 == *s2++) + { + if (*s1++ == '\0') + { return 0; } } - if (*s1 == '\0') return -1; - if (*--s2 == '\0') return 1; - return (unsigned char) *s1 - (unsigned char) *s2; + if (*s1 == '\0') + return -1; + if (*--s2 == '\0') + return 1; + return (unsigned char)*s1 - (unsigned char)*s2; } diff --git a/lang/cem/libcc.ansi/string/strcoll.c b/lang/cem/libcc.ansi/string/strcoll.c index 8a9b408b6..6e9a634af 100644 --- a/lang/cem/libcc.ansi/string/strcoll.c +++ b/lang/cem/libcc.ansi/string/strcoll.c @@ -4,14 +4,15 @@ */ /* $Id$ */ -#include -#include +#include +#include -int -strcoll(register const char *s1, register const char *s2) +int strcoll(register const char* s1, register const char* s2) { - while (*s1 == *s2++) { - if (*s1++ == '\0') { + while (*s1 == *s2++) + { + if (*s1++ == '\0') + { return 0; } } diff --git a/lang/cem/libcc.ansi/string/strcpy.c b/lang/cem/libcc.ansi/string/strcpy.c index bd77c0d50..652f76376 100644 --- a/lang/cem/libcc.ansi/string/strcpy.c +++ b/lang/cem/libcc.ansi/string/strcpy.c @@ -4,15 +4,14 @@ */ /* $Id$ */ -#include +#include -char * -strcpy(char *ret, register const char *s2) +char* strcpy(char* ret, register const char* s2) { - register char *s1 = ret; + register char* s1 = ret; while (*s1++ = *s2++) - /* EMPTY */ ; + /* EMPTY */; return ret; } diff --git a/lang/cem/libcc.ansi/string/strcspn.c b/lang/cem/libcc.ansi/string/strcspn.c index f99a5c441..37b22857e 100644 --- a/lang/cem/libcc.ansi/string/strcspn.c +++ b/lang/cem/libcc.ansi/string/strcspn.c @@ -4,16 +4,17 @@ */ /* $Id$ */ -#include +#include size_t -strcspn(const char *string, const char *notin) +strcspn(const char* string, const char* notin) { register const char *s1, *s2; - for (s1 = string; *s1; s1++) { - for(s2 = notin; *s2 != *s1 && *s2; s2++) - /* EMPTY */ ; + for (s1 = string; *s1; s1++) + { + for (s2 = notin; *s2 != *s1 && *s2; s2++) + /* EMPTY */; if (*s2) break; } diff --git a/lang/cem/libcc.ansi/string/strdup.c b/lang/cem/libcc.ansi/string/strdup.c index d197171a9..0e7999ad7 100644 --- a/lang/cem/libcc.ansi/string/strdup.c +++ b/lang/cem/libcc.ansi/string/strdup.c @@ -7,12 +7,11 @@ #include #include -char* -strdup(const char *s) +char* strdup(const char* s) { int len = strlen(s); - char *p = malloc(len+1); + char* p = malloc(len + 1); if (p) - memcpy(p, s, len+1); + memcpy(p, s, len + 1); return p; } diff --git a/lang/cem/libcc.ansi/string/strerror.c b/lang/cem/libcc.ansi/string/strerror.c index 62f787ce6..c00276ac5 100644 --- a/lang/cem/libcc.ansi/string/strerror.c +++ b/lang/cem/libcc.ansi/string/strerror.c @@ -4,19 +4,18 @@ */ /* $Id$ */ -#include +#include /* * I don't know why, but X3J11 says that strerror() should be in declared * in . That is why the function is defined here. */ -char * -strerror(register int errnum) +char* strerror(register int errnum) { - extern const char *_sys_errlist[]; + extern const char* _sys_errlist[]; extern const int _sys_nerr; - if (errnum < 0 || errnum >= _sys_nerr) + if (errnum < 0 || errnum >= _sys_nerr) return "unknown error"; - return (char *)_sys_errlist[errnum]; + return (char*)_sys_errlist[errnum]; } diff --git a/lang/cem/libcc.ansi/string/strlen.c b/lang/cem/libcc.ansi/string/strlen.c index 48bee4e9d..acf3a8acf 100644 --- a/lang/cem/libcc.ansi/string/strlen.c +++ b/lang/cem/libcc.ansi/string/strlen.c @@ -4,15 +4,15 @@ */ /* $Id$ */ -#include +#include size_t -strlen(const char *org) +strlen(const char* org) { - register const char *s = org; + register const char* s = org; while (*s++) - /* EMPTY */ ; + /* EMPTY */; return --s - org; } diff --git a/lang/cem/libcc.ansi/string/strncat.c b/lang/cem/libcc.ansi/string/strncat.c index f0b8313c3..77013ccb0 100644 --- a/lang/cem/libcc.ansi/string/strncat.c +++ b/lang/cem/libcc.ansi/string/strncat.c @@ -4,22 +4,26 @@ */ /* $Id$ */ -#include +#include -char * -strncat(char *ret, register const char *s2, size_t n) +char* strncat(char* ret, register const char* s2, size_t n) { - register char *s1 = ret; + register char* s1 = ret; - if (n > 0) { + if (n > 0) + { while (*s1++) - /* EMPTY */ ; + /* EMPTY */; s1--; - while (*s1++ = *s2++) { - if (--n > 0) continue; + while (*s1++ = *s2++) + { + if (--n > 0) + continue; *s1 = '\0'; break; } return ret; - } else return s1; + } + else + return s1; } diff --git a/lang/cem/libcc.ansi/string/strncmp.c b/lang/cem/libcc.ansi/string/strncmp.c index 950ede4fe..b0e16b014 100644 --- a/lang/cem/libcc.ansi/string/strncmp.c +++ b/lang/cem/libcc.ansi/string/strncmp.c @@ -4,22 +4,26 @@ */ /* $Id$ */ -#include +#include -int -strncmp(register const char *s1, register const char *s2, register size_t n) +int strncmp(register const char* s1, register const char* s2, register size_t n) { - if (n) { - do { + if (n) + { + do + { if (*s1 != *s2++) break; if (*s1++ == '\0') return 0; } while (--n > 0); - if (n > 0) { - if (*s1 == '\0') return -1; - if (*--s2 == '\0') return 1; - return (unsigned char) *s1 - (unsigned char) *s2; + if (n > 0) + { + if (*s1 == '\0') + return -1; + if (*--s2 == '\0') + return 1; + return (unsigned char)*s1 - (unsigned char)*s2; } } return 0; diff --git a/lang/cem/libcc.ansi/string/strncpy.c b/lang/cem/libcc.ansi/string/strncpy.c index 0c0bfd625..bdf9129e7 100644 --- a/lang/cem/libcc.ansi/string/strncpy.c +++ b/lang/cem/libcc.ansi/string/strncpy.c @@ -4,20 +4,22 @@ */ /* $Id$ */ -#include +#include -char * -strncpy(char *ret, register const char *s2, register size_t n) +char* strncpy(char* ret, register const char* s2, register size_t n) { - register char *s1 = ret; + register char* s1 = ret; - if (n>0) { - while((*s1++ = *s2++) && --n > 0) - /* EMPTY */ ; - if ((*--s2 == '\0') && --n > 0) { - do { + if (n > 0) + { + while ((*s1++ = *s2++) && --n > 0) + /* EMPTY */; + if ((*--s2 == '\0') && --n > 0) + { + do + { *s1++ = '\0'; - } while(--n > 0); + } while (--n > 0); } } return ret; diff --git a/lang/cem/libcc.ansi/string/strpbrk.c b/lang/cem/libcc.ansi/string/strpbrk.c index 98a4fab7e..aa517445d 100644 --- a/lang/cem/libcc.ansi/string/strpbrk.c +++ b/lang/cem/libcc.ansi/string/strpbrk.c @@ -4,19 +4,19 @@ */ /* $Id$ */ -#include +#include -char * -strpbrk(register const char *string, register const char *brk) +char* strpbrk(register const char* string, register const char* brk) { - register const char *s1; + register const char* s1; - while (*string) { + while (*string) + { for (s1 = brk; *s1 && *s1 != *string; s1++) - /* EMPTY */ ; + /* EMPTY */; if (*s1) - return (char *)string; + return (char*)string; string++; } - return (char *)NULL; + return (char*)NULL; } diff --git a/lang/cem/libcc.ansi/string/strrchr.c b/lang/cem/libcc.ansi/string/strrchr.c index 964b59f5e..b55ced1cd 100644 --- a/lang/cem/libcc.ansi/string/strrchr.c +++ b/lang/cem/libcc.ansi/string/strrchr.c @@ -4,19 +4,19 @@ */ /* $Id$ */ -#include +#include -char * -strrchr(register const char *s, int c) +char* strrchr(register const char* s, int c) { - register const char *result = NULL; + register const char* result = NULL; - c = (char) c; + c = (char)c; - do { + do + { if (c == *s) result = s; } while (*s++ != '\0'); - return (char *)result; + return (char*)result; } diff --git a/lang/cem/libcc.ansi/string/strspn.c b/lang/cem/libcc.ansi/string/strspn.c index ceb609f2e..908d6f9ea 100644 --- a/lang/cem/libcc.ansi/string/strspn.c +++ b/lang/cem/libcc.ansi/string/strspn.c @@ -4,16 +4,17 @@ */ /* $Id$ */ -#include +#include size_t -strspn(const char *string, const char *in) +strspn(const char* string, const char* in) { register const char *s1, *s2; - for (s1 = string; *s1; s1++) { + for (s1 = string; *s1; s1++) + { for (s2 = in; *s2 && *s2 != *s1; s2++) - /* EMPTY */ ; + /* EMPTY */; if (*s2 == '\0') break; } diff --git a/lang/cem/libcc.ansi/string/strstr.c b/lang/cem/libcc.ansi/string/strstr.c index 578223542..2b9b1178d 100644 --- a/lang/cem/libcc.ansi/string/strstr.c +++ b/lang/cem/libcc.ansi/string/strstr.c @@ -4,16 +4,16 @@ */ /* $Id$ */ -#include +#include -char * -strstr(register const char *s, register const char *wanted) +char* strstr(register const char* s, register const char* wanted) { register const int len = strlen(wanted); - if (len == 0) return (char *)s; + if (len == 0) + return (char*)s; while (*s != *wanted || strncmp(s, wanted, len)) if (*s++ == '\0') - return (char *)NULL; - return (char *)s; + return (char*)NULL; + return (char*)s; } diff --git a/lang/cem/libcc.ansi/string/strtok.c b/lang/cem/libcc.ansi/string/strtok.c index d2bbbde51..9582ea7c3 100644 --- a/lang/cem/libcc.ansi/string/strtok.c +++ b/lang/cem/libcc.ansi/string/strtok.c @@ -4,23 +4,25 @@ */ /* $Id$ */ -#include +#include -char * -strtok(register char *string, const char *separators) +char* strtok(register char* string, const char* separators) { register char *s1, *s2; - static char *savestring; + static char* savestring; - if (string == NULL) { + if (string == NULL) + { string = savestring; - if (string == NULL) return (char *)NULL; + if (string == NULL) + return (char*)NULL; } s1 = string + strspn(string, separators); - if (*s1 == '\0') { + if (*s1 == '\0') + { savestring = NULL; - return (char *)NULL; + return (char*)NULL; } s2 = strpbrk(s1, separators); diff --git a/lang/cem/libcc.ansi/string/strxfrm.c b/lang/cem/libcc.ansi/string/strxfrm.c index 7ce96a9f8..f6163bd5b 100644 --- a/lang/cem/libcc.ansi/string/strxfrm.c +++ b/lang/cem/libcc.ansi/string/strxfrm.c @@ -4,18 +4,21 @@ */ /* $Id$ */ -#include +#include size_t -strxfrm(register char *s1, register const char *save, register size_t n) +strxfrm(register char* s1, register const char* save, register size_t n) { - register const char *s2 = save; + register const char* s2 = save; - while (*s2) { - if (n > 1) { + while (*s2) + { + if (n > 1) + { n--; *s1++ = *s2++; - } else + } + else s2++; } if (n > 0) diff --git a/lang/cem/libcc.ansi/time/asctime.c b/lang/cem/libcc.ansi/time/asctime.c index 2b0adc9ad..dda8b8006 100644 --- a/lang/cem/libcc.ansi/time/asctime.c +++ b/lang/cem/libcc.ansi/time/asctime.c @@ -3,24 +3,25 @@ */ /* $Id$ */ -#include -#include -#include "loc_time.h" +#include +#include +#include "loc_time.h" -#define DATE_STR "??? ??? ?? ??:??:?? ????\n" +#define DATE_STR "??? ??? ?? ??:??:?? ????\n" -static char * -two_digits(register char *pb, int i, int nospace) +static char* +two_digits(register char* pb, int i, int nospace) { *pb = (i / 10) % 10 + '0'; - if (!nospace && *pb == '0') *pb = ' '; + if (!nospace && *pb == '0') + *pb = ' '; pb++; *pb++ = (i % 10) + '0'; return ++pb; } -static char * -four_digits(register char *pb, int i) +static char* +four_digits(register char* pb, int i) { i %= 10000; *pb++ = (i / 1000) + '0'; @@ -32,28 +33,28 @@ four_digits(register char *pb, int i) return ++pb; } -char *asctime(const struct tm *timeptr) +char* asctime(const struct tm* timeptr) { static char buf[26]; - register char *pb = buf; - register const char *ps; + register char* pb = buf; + register const char* ps; register int n; strcpy(pb, DATE_STR); ps = _days[timeptr->tm_wday]; n = ABB_LEN; - while(--n >= 0) *pb++ = *ps++; + while (--n >= 0) + *pb++ = *ps++; pb++; ps = _months[timeptr->tm_mon]; n = ABB_LEN; - while(--n >= 0) *pb++ = *ps++; + while (--n >= 0) + *pb++ = *ps++; pb++; pb = two_digits( - two_digits( - two_digits(two_digits(pb, timeptr->tm_mday, 0) - , timeptr->tm_hour, 1) - , timeptr->tm_min, 1) - , timeptr->tm_sec, 1); + two_digits( + two_digits(two_digits(pb, timeptr->tm_mday, 0), timeptr->tm_hour, 1), timeptr->tm_min, 1), + timeptr->tm_sec, 1); four_digits(pb, timeptr->tm_year + 1900); return buf; diff --git a/lang/cem/libcc.ansi/time/clock.c b/lang/cem/libcc.ansi/time/clock.c index 3c7f81d37..e5d25779f 100644 --- a/lang/cem/libcc.ansi/time/clock.c +++ b/lang/cem/libcc.ansi/time/clock.c @@ -3,69 +3,72 @@ */ /* $Id$ */ -#include +#include -#if defined(__BSD4_2) +#if defined(__BSD4_2) -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN -1 +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 -struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ +struct rusage +{ + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data size */ + long ru_isrss; /* integral unshared stack size */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary context switches */ }; -void _getrusage(int who, struct rusage *rusage); +void _getrusage(int who, struct rusage* rusage); -#elif defined(_POSIX_SOURCE) || defined(__USG) +#elif defined(_POSIX_SOURCE) || defined(__USG) -struct tms { - time_t tms_utime; /* user time */ - time_t tms_stime; /* system time */ - time_t tms_cutime; /* user time, children */ - time_t tms_cstime; /* system time, children */ +struct tms +{ + time_t tms_utime; /* user time */ + time_t tms_stime; /* system time */ + time_t tms_cutime; /* user time, children */ + time_t tms_cstime; /* system time, children */ }; -long _times(struct tms *buffer); +long _times(struct tms* buffer); -#else /* Version 7 UNIX */ +#else /* Version 7 UNIX */ -struct tbuffer { +struct tbuffer +{ long proc_user_time; long proc_system_time; long child_user_time; long child_system_time; }; -long _times(struct tbuffer *buffer); +long _times(struct tbuffer* buffer); #endif clock_t clock(void) { -#if defined(__BSD4_2) +#if defined(__BSD4_2) struct rusage rusage; _getrusage(RUSAGE_SELF, &rusage); return (((unsigned long)rusage.ru_utime.tv_sec * CLOCKS_PER_SEC) - + rusage.ru_utime.tv_usec); -#elif defined(_POSIX_SOURCE) || defined(__USG) + + rusage.ru_utime.tv_usec); +#elif defined(_POSIX_SOURCE) || defined(__USG) struct tms tms; _times(&tms); diff --git a/lang/cem/libcc.ansi/time/ctime.c b/lang/cem/libcc.ansi/time/ctime.c index f7e81b41f..775ef806c 100644 --- a/lang/cem/libcc.ansi/time/ctime.c +++ b/lang/cem/libcc.ansi/time/ctime.c @@ -3,10 +3,9 @@ */ /* $Id$ */ -#include +#include -char * -(ctime)(const time_t *timer) +char*(ctime)(const time_t* timer) { return asctime(localtime(timer)); } diff --git a/lang/cem/libcc.ansi/time/difftime.c b/lang/cem/libcc.ansi/time/difftime.c index 0ff2d6c3d..cd01e0080 100644 --- a/lang/cem/libcc.ansi/time/difftime.c +++ b/lang/cem/libcc.ansi/time/difftime.c @@ -3,15 +3,18 @@ */ /* $Id$ */ -#include +#include double difftime(time_t time1, time_t time0) { /* be careful: time_t may be unsigned */ - if ((time_t)-1 > 0 && time0 > time1) { - return - (double) (time0 - time1); - } else { + if ((time_t)-1 > 0 && time0 > time1) + { + return -(double)(time0 - time1); + } + else + { return (double)(time1 - time0); } } diff --git a/lang/cem/libcc.ansi/time/gmtime.c b/lang/cem/libcc.ansi/time/gmtime.c index 03578a91c..0dcb1c25d 100644 --- a/lang/cem/libcc.ansi/time/gmtime.c +++ b/lang/cem/libcc.ansi/time/gmtime.c @@ -3,15 +3,15 @@ */ /* $Id$ */ -#include -#include -#include "loc_time.h" +#include +#include +#include "loc_time.h" -struct tm * -gmtime(register const time_t *timer) +struct tm* +gmtime(register const time_t* timer) { static struct tm br_time; - register struct tm *timep = &br_time; + register struct tm* timep = &br_time; time_t tim = *timer; register unsigned long dayclock, dayno; int year = EPOCH_YR; @@ -22,15 +22,17 @@ gmtime(register const time_t *timer) timep->tm_sec = dayclock % 60; timep->tm_min = (dayclock % 3600) / 60; timep->tm_hour = dayclock / 3600; - timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */ - while (dayno >= YEARSIZE(year)) { + timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */ + while (dayno >= YEARSIZE(year)) + { dayno -= YEARSIZE(year); year++; } timep->tm_year = year - YEAR0; timep->tm_yday = dayno; timep->tm_mon = 0; - while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) { + while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) + { dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon]; timep->tm_mon++; } diff --git a/lang/cem/libcc.ansi/time/localtime.c b/lang/cem/libcc.ansi/time/localtime.c index a475f3a2a..87fd2ad2a 100644 --- a/lang/cem/libcc.ansi/time/localtime.c +++ b/lang/cem/libcc.ansi/time/localtime.c @@ -3,8 +3,8 @@ */ /* $Id$ */ -#include -#include "loc_time.h" +#include +#include "loc_time.h" /* We must be careful, since an int can't represent all the seconds in a day. * Hence the adjustment of minutes when adding timezone and dst information. @@ -12,20 +12,21 @@ * Furthermore, it is assumed that both fit into an integer when expressed as * minutes (this is about 22 days, so this should not cause any problems). */ -struct tm * -localtime(const time_t *timer) +struct tm* +localtime(const time_t* timer) { - struct tm *timep; + struct tm* timep; unsigned dst; _tzset(); - timep = gmtime(timer); /* tm->tm_isdst == 0 */ + timep = gmtime(timer); /* tm->tm_isdst == 0 */ timep->tm_min -= _timezone / 60; timep->tm_sec -= _timezone % 60; mktime(timep); dst = _dstget(timep); - if (dst) { + if (dst) + { timep->tm_min += dst / 60; timep->tm_sec += dst % 60; mktime(timep); diff --git a/lang/cem/libcc.ansi/time/misc.c b/lang/cem/libcc.ansi/time/misc.c index 00da98fa4..8a21fb561 100644 --- a/lang/cem/libcc.ansi/time/misc.c +++ b/lang/cem/libcc.ansi/time/misc.c @@ -3,139 +3,141 @@ */ /* $Id$ */ -#include -#include -#include -#include +#include +#include +#include +#include -#if defined(__BSD4_2) +#if defined(__BSD4_2) -extern int _gettimeofday(struct timeval *tp, struct timezone *tzp); +extern int _gettimeofday(struct timeval* tp, struct timezone* tzp); -#elif !defined(_POSIX_SOURCE) && !defined(__USG) -#if !defined(_MINIX) /* MINIX has no ftime() */ -struct timeb { - long time; +#elif !defined(_POSIX_SOURCE) && !defined(__USG) +#if !defined(_MINIX) /* MINIX has no ftime() */ +struct timeb +{ + long time; unsigned short millitm; - short timezone; - short dstflag; + short timezone; + short dstflag; }; -void _ftime(struct timeb *bp); +void _ftime(struct timeb* bp); #endif #endif -#include "loc_time.h" +#include "loc_time.h" -#define RULE_LEN 120 -#define TZ_LEN 10 +#define RULE_LEN 120 +#define TZ_LEN 10 /* Make sure that the strings do not end up in ROM. * These strings probably contain the wrong value, and we cannot obtain the * right value from the system. TZ is the only help. */ -static char ntstr[TZ_LEN + 1] = "GMT"; /* string for normal time */ -static char dststr[TZ_LEN + 1] = "GDT"; /* string for daylight saving */ +static char ntstr[TZ_LEN + 1] = "GMT"; /* string for normal time */ +static char dststr[TZ_LEN + 1] = "GDT"; /* string for daylight saving */ -long _timezone = 0; -long _dst_off = 60 * 60; -int _daylight = 0; -char *_tzname[2] = {ntstr, dststr}; +long _timezone = 0; +long _dst_off = 60 * 60; +int _daylight = 0; +char* _tzname[2] = { ntstr, dststr }; -#if defined(__USG) || defined(_POSIX_SOURCE) -char *tzname[2] = {ntstr, dststr}; +#if defined(__USG) || defined(_POSIX_SOURCE) +char* tzname[2] = { ntstr, dststr }; -#if defined(__USG) -long timezone = 0; -int daylight = 0; +#if defined(__USG) +long timezone = 0; +int daylight = 0; #endif #endif -static struct dsttype { - char ds_type; /* Unknown, Julian, Zero-based or M */ - int ds_date[3]; /* months, weeks, days */ - long ds_sec; /* usually 02:00:00 */ -} dststart = { 'U', { 0, 0, 0 }, 2 * 60 * 60 } - , dstend = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }; +static struct dsttype +{ + char ds_type; /* Unknown, Julian, Zero-based or M */ + int ds_date[3]; /* months, weeks, days */ + long ds_sec; /* usually 02:00:00 */ +} dststart = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }, dstend = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }; -const char *_days[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" - }; +const char* _days[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" +}; -const char *_months[] = { - "January", "February", "March", - "April", "May", "June", - "July", "August", "September", - "October", "November", "December" - }; +const char* _months[] = { + "January", "February", "March", + "April", "May", "June", + "July", "August", "September", + "October", "November", "December" +}; const int _ytab[2][12] = { - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } - }; + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; -#if !defined(_POSIX_SOURCE) && !defined(__USG) -#define USE_TABLE 1 +#if !defined(_POSIX_SOURCE) && !defined(__USG) +#define USE_TABLE 1 #endif -#if USE_TABLE +#if USE_TABLE static int usetable = 1; -typedef struct table { - const char *tz_name; +typedef struct table +{ + const char* tz_name; const int daylight; const long zoneoffset; } TABLE; -#define HOUR(x) ((x) * 60*60) +#define HOUR(x) ((x)*60 * 60) static TABLE TimezoneTable[] = { - {"GMT", 0, HOUR(0) }, /* Greenwich Mean */ - {"BST", 60*60, HOUR(0) }, /* British Summer */ - {"WAT", 0, HOUR(1) }, /* West Africa */ - {"AT", 0, HOUR(2) }, /* Azores */ - {"BST", 0, HOUR(3) }, /* Brazil Standard */ - {"NFT", 0, HOUR(3.5) }, /* Newfoundland */ - {"NDT", 60*60, HOUR(3.5) }, /* Newfoundland Daylight */ - {"AST", 0, HOUR(4) }, /* Atlantic Standard */ - {"ADT", 60*60, HOUR(4) }, /* Atlantic Daylight */ - {"EST", 0, HOUR(5) }, /* Eastern Standard */ - {"EDT", 60*60, HOUR(5) }, /* Eastern Daylight */ - {"CST", 0, HOUR(6) }, /* Central Standard */ - {"CDT", 60*60, HOUR(6) }, /* Central Daylight */ - {"MST", 0, HOUR(7) }, /* Mountain Standard */ - {"MDT", 60*60, HOUR(7) }, /* Mountain Daylight */ - {"PST", 0, HOUR(8) }, /* Pacific Standard */ - {"PDT", 60*60, HOUR(8) }, /* Pacific Daylight */ - {"YST", 0, HOUR(9) }, /* Yukon Standard */ - {"YDT", 60*60, HOUR(9) }, /* Yukon Daylight */ - {"HST", 0, HOUR(10) }, /* Hawaii Standard */ - {"HDT", 60*60, HOUR(10) }, /* Hawaii Daylight */ - {"NT", 0, HOUR(11) }, /* Nome */ - {"IDLW", 0, HOUR(12) }, /* International Date Line West */ - {"MET", 0, -HOUR(1) }, /* Middle European */ - {"MDT", 60*60, -HOUR(1) }, /* Middle European Summer */ - {"EET", 0, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */ - {"BT", 0, -HOUR(3) }, /* Baghdad, USSR Zone 2 */ - {"IT", 0, -HOUR(3.5) }, /* Iran */ - {"ZP4", 0, -HOUR(4) }, /* USSR Zone 3 */ - {"ZP5", 0, -HOUR(5) }, /* USSR Zone 4 */ - {"IST", 0, -HOUR(5.5) }, /* Indian Standard */ - {"ZP6", 0, -HOUR(6) }, /* USSR Zone 5 */ - {"NST", 0, -HOUR(6.5) }, /* North Sumatra */ - {"SST", 0, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */ - {"WAST", 0, -HOUR(7) }, /* West Australian Standard */ - {"WADT", 60*60, -HOUR(7) }, /* West Australian Daylight */ - {"JT", 0, -HOUR(7.5) }, /* Java (3pm in Cronusland!) */ - {"CCT", 0, -HOUR(8) }, /* China Coast, USSR Zone 7 */ - {"JST", 0, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */ - {"CAST", 0, -HOUR(9.5) }, /* Central Australian Standard */ - {"CADT", 60*60, -HOUR(9.5) }, /* Central Australian Daylight */ - {"EAST", 0, -HOUR(10) }, /* Eastern Australian Standard */ - {"EADT", 60*60, -HOUR(10) }, /* Eastern Australian Daylight */ - {"NZT", 0, -HOUR(12) }, /* New Zealand */ - {"NZDT", 60*60, -HOUR(12) }, /* New Zealand Daylight */ - { NULL, 0, 0 } + { "GMT", 0, HOUR(0) }, /* Greenwich Mean */ + { "BST", 60 * 60, HOUR(0) }, /* British Summer */ + { "WAT", 0, HOUR(1) }, /* West Africa */ + { "AT", 0, HOUR(2) }, /* Azores */ + { "BST", 0, HOUR(3) }, /* Brazil Standard */ + { "NFT", 0, HOUR(3.5) }, /* Newfoundland */ + { "NDT", 60 * 60, HOUR(3.5) }, /* Newfoundland Daylight */ + { "AST", 0, HOUR(4) }, /* Atlantic Standard */ + { "ADT", 60 * 60, HOUR(4) }, /* Atlantic Daylight */ + { "EST", 0, HOUR(5) }, /* Eastern Standard */ + { "EDT", 60 * 60, HOUR(5) }, /* Eastern Daylight */ + { "CST", 0, HOUR(6) }, /* Central Standard */ + { "CDT", 60 * 60, HOUR(6) }, /* Central Daylight */ + { "MST", 0, HOUR(7) }, /* Mountain Standard */ + { "MDT", 60 * 60, HOUR(7) }, /* Mountain Daylight */ + { "PST", 0, HOUR(8) }, /* Pacific Standard */ + { "PDT", 60 * 60, HOUR(8) }, /* Pacific Daylight */ + { "YST", 0, HOUR(9) }, /* Yukon Standard */ + { "YDT", 60 * 60, HOUR(9) }, /* Yukon Daylight */ + { "HST", 0, HOUR(10) }, /* Hawaii Standard */ + { "HDT", 60 * 60, HOUR(10) }, /* Hawaii Daylight */ + { "NT", 0, HOUR(11) }, /* Nome */ + { "IDLW", 0, HOUR(12) }, /* International Date Line West */ + { "MET", 0, -HOUR(1) }, /* Middle European */ + { "MDT", 60 * 60, -HOUR(1) }, /* Middle European Summer */ + { "EET", 0, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */ + { "BT", 0, -HOUR(3) }, /* Baghdad, USSR Zone 2 */ + { "IT", 0, -HOUR(3.5) }, /* Iran */ + { "ZP4", 0, -HOUR(4) }, /* USSR Zone 3 */ + { "ZP5", 0, -HOUR(5) }, /* USSR Zone 4 */ + { "IST", 0, -HOUR(5.5) }, /* Indian Standard */ + { "ZP6", 0, -HOUR(6) }, /* USSR Zone 5 */ + { "NST", 0, -HOUR(6.5) }, /* North Sumatra */ + { "SST", 0, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */ + { "WAST", 0, -HOUR(7) }, /* West Australian Standard */ + { "WADT", 60 * 60, -HOUR(7) }, /* West Australian Daylight */ + { "JT", 0, -HOUR(7.5) }, /* Java (3pm in Cronusland!) */ + { "CCT", 0, -HOUR(8) }, /* China Coast, USSR Zone 7 */ + { "JST", 0, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */ + { "CAST", 0, -HOUR(9.5) }, /* Central Australian Standard */ + { "CADT", 60 * 60, -HOUR(9.5) }, /* Central Australian Daylight */ + { "EAST", 0, -HOUR(10) }, /* Eastern Australian Standard */ + { "EADT", 60 * 60, -HOUR(10) }, /* Eastern Australian Daylight */ + { "NZT", 0, -HOUR(12) }, /* New Zealand */ + { "NZDT", 60 * 60, -HOUR(12) }, /* New Zealand Daylight */ + { NULL, 0, 0 } }; /* @@ -147,155 +149,196 @@ static TABLE TimezoneTable[] = { static void ZoneFromTable(long timezone) { - register TABLE *tptr = TimezoneTable; + register TABLE* tptr = TimezoneTable; - while (tptr->tz_name != NULL) { - if (tptr->zoneoffset == timezone) { - if (tptr->daylight == 0) { - strncpy(ntstr,tptr->tz_name, TZ_LEN); + while (tptr->tz_name != NULL) + { + if (tptr->zoneoffset == timezone) + { + if (tptr->daylight == 0) + { + strncpy(ntstr, tptr->tz_name, TZ_LEN); ntstr[TZ_LEN] = '\0'; - } else { - strncpy(dststr,tptr->tz_name, TZ_LEN); + } + else + { + strncpy(dststr, tptr->tz_name, TZ_LEN); dststr[TZ_LEN] = '\0'; } } tptr++; } } -#endif /* USE_TABLE */ +#endif /* USE_TABLE */ -static const char * -parseZoneName(register char *buf, register const char *p) +static const char* +parseZoneName(register char* buf, register const char* p) { register int n = 0; - if (*p == ':') return NULL; - while (*p && !isdigit(*p) && *p != ',' && *p != '-' && *p != '+') { + if (*p == ':') + return NULL; + while (*p && !isdigit(*p) && *p != ',' && *p != '-' && *p != '+') + { if (n < TZ_LEN) *buf++ = *p; p++; n++; } - if (n < 3) return NULL; /* error */ + if (n < 3) + return NULL; /* error */ *buf = '\0'; return p; } -static const char * -parseTime(register long *tm, const char *p, register struct dsttype *dst) +static const char* +parseTime(register long* tm, const char* p, register struct dsttype* dst) { register int n = 0; - register const char *q = p; + register const char* q = p; char ds_type = (dst ? dst->ds_type : '\0'); - if (dst) dst->ds_type = 'U'; + if (dst) + dst->ds_type = 'U'; *tm = 0; - while(*p >= '0' && *p <= '9') { + while (*p >= '0' && *p <= '9') + { n = 10 * n + (*p++ - '0'); } - if (q == p) return NULL; /* "The hour shall be required" */ - if (n < 0 || n >= 24) return NULL; + if (q == p) + return NULL; /* "The hour shall be required" */ + if (n < 0 || n >= 24) + return NULL; *tm = n * 60 * 60; - if (*p == ':') { + if (*p == ':') + { p++; n = 0; - while(*p >= '0' && *p <= '9') { + while (*p >= '0' && *p <= '9') + { n = 10 * n + (*p++ - '0'); } - if (q == p) return NULL; /* format error */ - if (n < 0 || n >= 60) return NULL; + if (q == p) + return NULL; /* format error */ + if (n < 0 || n >= 60) + return NULL; *tm += n * 60; - if (*p == ':') { + if (*p == ':') + { p++; n = 0; - while(*p >= '0' && *p <= '9') { + while (*p >= '0' && *p <= '9') + { n = 10 * n + (*p++ - '0'); } - if (q == p) return NULL; /* format error */ - if (n < 0 || n >= 60) return NULL; + if (q == p) + return NULL; /* format error */ + if (n < 0 || n >= 60) + return NULL; *tm += n; } } - if (dst) { + if (dst) + { dst->ds_type = ds_type; dst->ds_sec = *tm; } return p; } -static const char * -parseDate(register char *buf, register const char *p, struct dsttype *dstinfo) +static const char* +parseDate(register char* buf, register const char* p, struct dsttype* dstinfo) { - register const char *q; + register const char* q; register int n = 0; int cnt = 0; - const int bnds[3][2] = { { 1, 12 }, - { 1, 5 }, - { 0, 6} - }; + const int bnds[3][2] = { { 1, 12 }, + { 1, 5 }, + { 0, 6 } }; char ds_type; - if (*p != 'M') { - if (*p == 'J') { + if (*p != 'M') + { + if (*p == 'J') + { *buf++ = *p++; ds_type = 'J'; } - else ds_type = 'Z'; + else + ds_type = 'Z'; q = p; - while(*p >= '0' && *p <= '9') { + while (*p >= '0' && *p <= '9') + { n = 10 * n + (*p - '0'); *buf++ = *p++; } - if (q == p) return NULL; /* format error */ - if (n < (ds_type == 'J') || n > 365) return NULL; + if (q == p) + return NULL; /* format error */ + if (n < (ds_type == 'J') || n > 365) + return NULL; dstinfo->ds_type = ds_type; dstinfo->ds_date[0] = n; return p; } ds_type = 'M'; - do { + do + { *buf++ = *p++; q = p; n = 0; - while(*p >= '0' && *p <= '9') { + while (*p >= '0' && *p <= '9') + { n = 10 * n + (*p - '0'); *buf++ = *p++; } - if (q == p) return NULL; /* format error */ - if (n < bnds[cnt][0] || n > bnds[cnt][1]) return NULL; + if (q == p) + return NULL; /* format error */ + if (n < bnds[cnt][0] || n > bnds[cnt][1]) + return NULL; dstinfo->ds_date[cnt] = n; cnt++; } while (cnt < 3 && *p == '.'); - if (cnt != 3) return NULL; + if (cnt != 3) + return NULL; *buf = '\0'; dstinfo->ds_type = ds_type; return p; } -static const char * -parseRule(register char *buf, register const char *p) +static const char* +parseRule(register char* buf, register const char* p) { long tim; - register const char *q; + register const char* q; - if (!(p = parseDate(buf, p, &dststart))) return NULL; + if (!(p = parseDate(buf, p, &dststart))) + return NULL; buf += strlen(buf); - if (*p == '/') { + if (*p == '/') + { q = ++p; - if (!(p = parseTime(&tim, p, &dststart))) return NULL; - while( p != q) *buf++ = *q++; + if (!(p = parseTime(&tim, p, &dststart))) + return NULL; + while (p != q) + *buf++ = *q++; } - if (*p != ',') return NULL; + if (*p != ',') + return NULL; p++; - if (!(p = parseDate(buf, p, &dstend))) return NULL; + if (!(p = parseDate(buf, p, &dstend))) + return NULL; buf += strlen(buf); - if (*p == '/') { + if (*p == '/') + { q = ++p; - if (!(p = parseTime(&tim, p, &dstend))) return NULL; - while(*buf++ = *q++); + if (!(p = parseTime(&tim, p, &dstend))) + return NULL; + while (*buf++ = *q++) + ; } - if (*p) return NULL; + if (*p) + return NULL; return p; } @@ -304,18 +347,20 @@ parseRule(register char *buf, register const char *p) * The function returns as soon as it spots an error. */ static void -parseTZ(const char *p) +parseTZ(const char* p) { long tz, dst = 60 * 60, sign = 1; static char lastTZ[2 * RULE_LEN]; static char buffer[RULE_LEN]; - if (!p) return; + if (!p) + return; -#if USE_TABLE +#if USE_TABLE usetable = 0; #endif - if (*p == ':') { + if (*p == ':') + { /* * According to POSIX, this is implementation defined. * Since it depends on the particular operating system, we @@ -324,7 +369,8 @@ parseTZ(const char *p) return; } - if (!strcmp(lastTZ, p)) return; /* nothing changed */ + if (!strcmp(lastTZ, p)) + return; /* nothing changed */ *_tzname[0] = '\0'; *_tzname[1] = '\0'; @@ -333,43 +379,55 @@ parseTZ(const char *p) dstend.ds_type = 'U'; dstend.ds_sec = 2 * 60 * 60; - if (strlen(p) > 2 * RULE_LEN) return; + if (strlen(p) > 2 * RULE_LEN) + return; strcpy(lastTZ, p); - if (!(p = parseZoneName(buffer, p))) return; + if (!(p = parseZoneName(buffer, p))) + return; - if (*p == '-') { + if (*p == '-') + { sign = -1; p++; - } else if (*p == '+') p++; + } + else if (*p == '+') + p++; - if (!(p = parseTime(&tz, p, NULL))) return; + if (!(p = parseTime(&tz, p, NULL))) + return; tz *= sign; _timezone = tz; strncpy(_tzname[0], buffer, TZ_LEN); - if (!(_daylight = (*p != '\0'))) return; + if (!(_daylight = (*p != '\0'))) + return; buffer[0] = '\0'; - if (!(p = parseZoneName(buffer, p))) return; + if (!(p = parseZoneName(buffer, p))) + return; strncpy(_tzname[1], buffer, TZ_LEN); buffer[0] = '\0'; if (*p && (*p != ',')) - if (!(p = parseTime(&dst, p, NULL))) return; - _dst_off = dst; /* dst was initialized to 1 hour */ - if (*p) { - if (*p != ',') return; + if (!(p = parseTime(&dst, p, NULL))) + return; + _dst_off = dst; /* dst was initialized to 1 hour */ + if (*p) + { + if (*p != ',') + return; p++; - if (strlen(p) > RULE_LEN) return; - if (!(p = parseRule(buffer, p))) return; + if (strlen(p) > RULE_LEN) + return; + if (!(p = parseRule(buffer, p))) + return; } } -void -_tzset(void) +void _tzset(void) { -#if defined(__BSD4_2) +#if defined(__BSD4_2) struct timeval tv; struct timezone tz; @@ -378,9 +436,9 @@ _tzset(void) _daylight = tz.tz_dsttime; _timezone = tz.tz_minuteswest * 60L; -#elif !defined(_POSIX_SOURCE) && !defined(__USG) +#elif !defined(_POSIX_SOURCE) && !defined(__USG) -#if !defined(_MINIX) /* MINIX has no ftime() */ +#if !defined(_MINIX) /* MINIX has no ftime() */ struct timeb tim; _ftime(&tim); @@ -388,54 +446,58 @@ _tzset(void) _daylight = tim.dstflag; #endif -#endif /* !_POSIX_SOURCE && !__USG */ +#endif /* !_POSIX_SOURCE && !__USG */ - parseTZ(getenv("TZ")); /* should go inside #if */ + parseTZ(getenv("TZ")); /* should go inside #if */ -#if defined(__USG) || defined(_POSIX_SOURCE) +#if defined(__USG) || defined(_POSIX_SOURCE) tzname[0] = _tzname[0]; tzname[1] = _tzname[1]; -#if defined(__USG) +#if defined(__USG) timezone = _timezone; daylight = _daylight; #endif -#endif /* __USG || _POSIX_SOURCE */ +#endif /* __USG || _POSIX_SOURCE */ } static int -last_sunday(register int day, register struct tm *timep) +last_sunday(register int day, register struct tm* timep) { int first = FIRSTSUNDAY(timep); - if (day >= 58 && LEAPYEAR(YEAR0 + timep->tm_year)) day++; - if (day < first) return first; + if (day >= 58 && LEAPYEAR(YEAR0 + timep->tm_year)) + day++; + if (day < first) + return first; return day - (day - first) % 7; } static int -date_of(register struct dsttype *dst, struct tm *timep) +date_of(register struct dsttype* dst, struct tm* timep) { int leap = LEAPYEAR(YEAR0 + timep->tm_year); int firstday, tmpday; register int day, month; - if (dst->ds_type != 'M') { - return dst->ds_date[0] - - (dst->ds_type == 'J' - && leap - && dst->ds_date[0] < 58); + if (dst->ds_type != 'M') + { + return dst->ds_date[0] - (dst->ds_type == 'J' + && leap + && dst->ds_date[0] < 58); } day = 0; month = 1; - while (month < dst->ds_date[0]) { + while (month < dst->ds_date[0]) + { day += _ytab[leap][month - 1]; month++; } firstday = (day + FIRSTDAYOF(timep)) % 7; tmpday = day; day += (dst->ds_date[2] - firstday + 7) % 7 - + 7 * (dst->ds_date[1] - 1); - if (day >= tmpday + _ytab[leap][month]) day -= 7; + + 7 * (dst->ds_date[1] - 1); + if (day >= tmpday + _ytab[leap][month]) + day -= 7; return day; } @@ -444,7 +506,7 @@ date_of(register struct dsttype *dst, struct tm *timep) * Britain). */ unsigned -_dstget(register struct tm *timep) +_dstget(register struct tm* timep) { int begindst, enddst; register struct dsttype *dsts = &dststart, *dste = &dstend; @@ -454,43 +516,53 @@ _dstget(register struct tm *timep) _tzset(); timep->tm_isdst = _daylight; - if (!_daylight) return 0; + if (!_daylight) + return 0; if (dsts->ds_type != 'U') begindst = date_of(dsts, timep); - else begindst = last_sunday(89, timep); /* last Sun before Apr */ + else + begindst = last_sunday(89, timep); /* last Sun before Apr */ if (dste->ds_type != 'U') enddst = date_of(dste, timep); - else enddst = last_sunday(272, timep); /* last Sun in Sep */ + else + enddst = last_sunday(272, timep); /* last Sun in Sep */ /* assume begindst != enddst (otherwise it would be no use) */ - if (begindst < enddst) { /* northern hemisphere */ + if (begindst < enddst) + { /* northern hemisphere */ if (timep->tm_yday > begindst && timep->tm_yday < enddst) do_dst = 1; - } else { /* southern hemisphere */ + } + else + { /* southern hemisphere */ if (timep->tm_yday > begindst || timep->tm_yday < enddst) do_dst = 1; } if (!do_dst - && (timep->tm_yday == begindst || timep->tm_yday == enddst)) { - long dsttranssec; /* transition when day is this old */ + && (timep->tm_yday == begindst || timep->tm_yday == enddst)) + { + long dsttranssec; /* transition when day is this old */ long cursec; if (timep->tm_yday == begindst) dsttranssec = dsts->ds_sec; - else dsttranssec = dste->ds_sec; + else + dsttranssec = dste->ds_sec; cursec = ((timep->tm_hour * 60) + timep->tm_min) * 60L - + timep->tm_sec; + + timep->tm_sec; if ((timep->tm_yday == begindst && cursec >= dsttranssec) || (timep->tm_yday == enddst && cursec < dsttranssec)) do_dst = 1; } #if USE_TABLE - if (usetable) ZoneFromTable(_timezone); + if (usetable) + ZoneFromTable(_timezone); #endif - if (do_dst) return _dst_off; + if (do_dst) + return _dst_off; timep->tm_isdst = 0; return 0; } diff --git a/lang/cem/libcc.ansi/time/mktime.c b/lang/cem/libcc.ansi/time/mktime.c index 6d4008082..174d2c266 100644 --- a/lang/cem/libcc.ansi/time/mktime.c +++ b/lang/cem/libcc.ansi/time/mktime.c @@ -3,16 +3,16 @@ */ /* $Id$ */ -#include -#include -#include "loc_time.h" +#include +#include +#include "loc_time.h" /* The code assumes that unsigned long can be converted to time_t. * A time_t should not be wider than unsigned long, since this would mean * that the check for overflow at the end could fail. */ time_t -mktime(register struct tm *timep) +mktime(register struct tm* timep) { register long day, year; register int tm_year; @@ -23,88 +23,102 @@ mktime(register struct tm *timep) timep->tm_min += timep->tm_sec / 60; timep->tm_sec %= 60; - if (timep->tm_sec < 0) { + if (timep->tm_sec < 0) + { timep->tm_sec += 60; timep->tm_min--; } timep->tm_hour += timep->tm_min / 60; timep->tm_min = timep->tm_min % 60; - if (timep->tm_min < 0) { + if (timep->tm_min < 0) + { timep->tm_min += 60; timep->tm_hour--; } day = timep->tm_hour / 24; - timep->tm_hour= timep->tm_hour % 24; - if (timep->tm_hour < 0) { + timep->tm_hour = timep->tm_hour % 24; + if (timep->tm_hour < 0) + { timep->tm_hour += 24; day--; } timep->tm_year += timep->tm_mon / 12; timep->tm_mon %= 12; - if (timep->tm_mon < 0) { + if (timep->tm_mon < 0) + { timep->tm_mon += 12; timep->tm_year--; } day += (timep->tm_mday - 1); - while (day < 0) { + while (day < 0) + { day += YEARSIZE(YEAR0 + timep->tm_year - 1); timep->tm_year--; } - while (day >= YEARSIZE(YEAR0 + timep->tm_year)) { + while (day >= YEARSIZE(YEAR0 + timep->tm_year)) + { day -= YEARSIZE(YEAR0 + timep->tm_year); timep->tm_year++; } - while (day >= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon]) { + while (day >= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon]) + { day -= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon]; - if (++(timep->tm_mon) == 12) { + if (++(timep->tm_mon) == 12) + { timep->tm_mon = 0; timep->tm_year++; } } timep->tm_mday = day + 1; - _tzset(); /* set timezone and dst info */ + _tzset(); /* set timezone and dst info */ year = EPOCH_YR; - if (timep->tm_year < year - YEAR0) return (time_t)-1; + if (timep->tm_year < year - YEAR0) + return (time_t)-1; seconds = 0; - day = 0; /* means days since day 0 now */ + day = 0; /* means days since day 0 now */ overflow = 0; - /* Assume that when day becomes negative, there will certainly +/* Assume that when day becomes negative, there will certainly * be overflow on seconds. * The check for overflow needs not to be done for leapyears * divisible by 400. * The code only works when year (1970) is not a leapyear. */ -#if EPOCH_YR != 1970 -#error EPOCH_YR != 1970 +#if EPOCH_YR != 1970 +#error EPOCH_YR != 1970 #endif tm_year = timep->tm_year + YEAR0; - if (LONG_MAX / 365 < tm_year - year) overflow++; + if (LONG_MAX / 365 < tm_year - year) + overflow++; day = (tm_year - year) * 365; - if (LONG_MAX - day < (tm_year - year) / 4 + 1) overflow++; + if (LONG_MAX - day < (tm_year - year) / 4 + 1) + overflow++; day += (tm_year - year) / 4 - + ((tm_year % 4) && tm_year % 4 < year % 4); + + ((tm_year % 4) && tm_year % 4 < year % 4); day -= (tm_year - year) / 100 - + ((tm_year % 100) && tm_year % 100 < year % 100); + + ((tm_year % 100) && tm_year % 100 < year % 100); day += (tm_year - year) / 400 - + ((tm_year % 400) && tm_year % 400 < year % 400); + + ((tm_year % 400) && tm_year % 400 < year % 400); yday = month = 0; - while (month < timep->tm_mon) { + while (month < timep->tm_mon) + { yday += _ytab[LEAPYEAR(tm_year)][month]; month++; } yday += (timep->tm_mday - 1); - if (day + yday < 0) overflow++; + if (day + yday < 0) + overflow++; day += yday; timep->tm_yday = yday; - timep->tm_wday = (day + 4) % 7; /* day 0 was thursday (4) */ + timep->tm_wday = (day + 4) % 7; /* day 0 was thursday (4) */ seconds = ((timep->tm_hour * 60L) + timep->tm_min) * 60L + timep->tm_sec; - if ((TIME_MAX - seconds) / SECS_DAY < day) overflow++; + if ((TIME_MAX - seconds) / SECS_DAY < day) + overflow++; seconds += day * SECS_DAY; /* Now adjust according to timezone and daylight saving time */ @@ -118,13 +132,17 @@ mktime(register struct tm *timep) dst = _dstget(timep); else if (timep->tm_isdst) dst = _dst_off; - else dst = 0; + else + dst = 0; - if (dst > seconds) overflow++; /* dst is always non-negative */ + if (dst > seconds) + overflow++; /* dst is always non-negative */ seconds -= dst; - if (overflow) return (time_t)-1; + if (overflow) + return (time_t)-1; - if ((time_t)seconds != seconds) return (time_t)-1; + if ((time_t)seconds != seconds) + return (time_t)-1; return (time_t)seconds; } diff --git a/lang/cem/libcc.ansi/time/strftime.c b/lang/cem/libcc.ansi/time/strftime.c index c002d3179..cae3b6eb3 100644 --- a/lang/cem/libcc.ansi/time/strftime.c +++ b/lang/cem/libcc.ansi/time/strftime.c @@ -3,17 +3,19 @@ */ /* $Id$ */ -#include -#include "loc_time.h" +#include +#include "loc_time.h" /* The width can be -1 in both s_prnt() as in u_prnt(). This * indicates that as many characters as needed should be printed. */ -static char * -s_prnt(char *s, size_t maxsize, const char *str, int width) +static char* +s_prnt(char* s, size_t maxsize, const char* str, int width) { - while (width > 0 || (width < 0 && *str)) { - if (!maxsize) break; + while (width > 0 || (width < 0 && *str)) + { + if (!maxsize) + break; *s++ = *str++; maxsize--; width--; @@ -21,8 +23,8 @@ s_prnt(char *s, size_t maxsize, const char *str, int width) return s; } -static char * -u_prnt(char *s, size_t maxsize, unsigned val, int width) +static char* +u_prnt(char* s, size_t maxsize, unsigned val, int width) { int c; @@ -30,143 +32,156 @@ u_prnt(char *s, size_t maxsize, unsigned val, int width) val = val / 10; if (--width > 0 || (width < 0 && val != 0)) s = u_prnt(s, (maxsize ? maxsize - 1 : 0), val, width); - if (maxsize) *s++ = c + '0'; + if (maxsize) + *s++ = c + '0'; return s; } size_t -strftime(char *s, size_t maxsize, - const char *format, const struct tm *timeptr) +strftime(char* s, size_t maxsize, + const char* format, const struct tm* timeptr) { size_t n; char *firsts, *olds; - if (!format) return 0; + if (!format) + return 0; - _tzset(); /* for %Z conversion */ + _tzset(); /* for %Z conversion */ firsts = s; - while (maxsize && *format) { - while (maxsize && *format && *format != '%') { + while (maxsize && *format) + { + while (maxsize && *format && *format != '%') + { *s++ = *format++; maxsize--; } - if (!maxsize || !*format) break; + if (!maxsize || !*format) + break; format++; olds = s; - switch (*format++) { - case 'a': - s = s_prnt(s, maxsize, - _days[timeptr->tm_wday], ABB_LEN); - maxsize -= s - olds; - break; - case 'A': - s = s_prnt(s, maxsize, _days[timeptr->tm_wday], -1); - maxsize -= s - olds; - break; - case 'b': - s = s_prnt(s, maxsize, - _months[timeptr->tm_mon], ABB_LEN); - maxsize -= s - olds; - break; - case 'B': - s = s_prnt(s, maxsize, _months[timeptr->tm_mon], -1); - maxsize -= s - olds; - break; - case 'c': - n = strftime(s, maxsize, - "%a %b %d %H:%M:%S %Y", timeptr); - if (n) maxsize -= n; - else maxsize = 0; - s += n; - break; - case 'd': - s = u_prnt(s, maxsize, timeptr->tm_mday, 2); - maxsize -= s - olds; - break; - case 'H': - s = u_prnt(s, maxsize, timeptr->tm_hour, 2); - maxsize -= s - olds; - break; - case 'I': - s = u_prnt(s, maxsize, - (timeptr->tm_hour + 11) % 12 + 1, 2); - maxsize -= s - olds; - break; - case 'j': - s = u_prnt(s, maxsize, timeptr->tm_yday + 1, 3); - maxsize -= s - olds; - break; - case 'm': - s = u_prnt(s, maxsize, timeptr->tm_mon + 1, 2); - maxsize -= s - olds; - break; - case 'M': - s = u_prnt(s, maxsize, timeptr->tm_min, 2); - maxsize -= s - olds; - break; - case 'p': - s = s_prnt(s, maxsize, + switch (*format++) + { + case 'a': + s = s_prnt(s, maxsize, + _days[timeptr->tm_wday], ABB_LEN); + maxsize -= s - olds; + break; + case 'A': + s = s_prnt(s, maxsize, _days[timeptr->tm_wday], -1); + maxsize -= s - olds; + break; + case 'b': + s = s_prnt(s, maxsize, + _months[timeptr->tm_mon], ABB_LEN); + maxsize -= s - olds; + break; + case 'B': + s = s_prnt(s, maxsize, _months[timeptr->tm_mon], -1); + maxsize -= s - olds; + break; + case 'c': + n = strftime(s, maxsize, + "%a %b %d %H:%M:%S %Y", timeptr); + if (n) + maxsize -= n; + else + maxsize = 0; + s += n; + break; + case 'd': + s = u_prnt(s, maxsize, timeptr->tm_mday, 2); + maxsize -= s - olds; + break; + case 'H': + s = u_prnt(s, maxsize, timeptr->tm_hour, 2); + maxsize -= s - olds; + break; + case 'I': + s = u_prnt(s, maxsize, + (timeptr->tm_hour + 11) % 12 + 1, 2); + maxsize -= s - olds; + break; + case 'j': + s = u_prnt(s, maxsize, timeptr->tm_yday + 1, 3); + maxsize -= s - olds; + break; + case 'm': + s = u_prnt(s, maxsize, timeptr->tm_mon + 1, 2); + maxsize -= s - olds; + break; + case 'M': + s = u_prnt(s, maxsize, timeptr->tm_min, 2); + maxsize -= s - olds; + break; + case 'p': + s = s_prnt(s, maxsize, (timeptr->tm_hour < 12) ? "AM" : "PM", 2); - maxsize -= s - olds; - break; - case 'S': - s = u_prnt(s, maxsize, timeptr->tm_sec, 2); - maxsize -= s - olds; - break; - case 'U': - s = u_prnt(s, maxsize, /* ??? */ - (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7, 2); - maxsize -= s - olds; - break; - case 'w': - s = u_prnt(s, maxsize, timeptr->tm_wday, 1); - maxsize -= s - olds; - break; - case 'W': - s = u_prnt(s, maxsize, /* ??? */ - (timeptr->tm_yday+7-(timeptr->tm_wday+6)%7)/7,2); - maxsize -= s - olds; - break; - case 'x': - n = strftime(s, maxsize, "%a %b %d %Y", timeptr); - if (n) maxsize -= n; - else maxsize = 0; - s += n; - break; - case 'X': - n = strftime(s, maxsize, "%H:%M:%S", timeptr); - if (n) maxsize -= n; - else maxsize = 0; - s += n; - break; - case 'y': - s = u_prnt(s, maxsize, timeptr->tm_year % 100, 2); - maxsize -= s - olds; - break; - case 'Y': - s = u_prnt(s, maxsize, timeptr->tm_year + YEAR0, -1); - maxsize -= s - olds; - break; - case 'Z': - s = s_prnt(s, maxsize, - _tzname[(timeptr->tm_isdst > 0)], -1); - maxsize -= s - olds; - break; - case '%': - *s++ = '%'; - maxsize--; - break; - default: - /* A conversion error. Leave the loop. */ - while (*format) format++; - break; + maxsize -= s - olds; + break; + case 'S': + s = u_prnt(s, maxsize, timeptr->tm_sec, 2); + maxsize -= s - olds; + break; + case 'U': + s = u_prnt(s, maxsize, /* ??? */ + (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7, 2); + maxsize -= s - olds; + break; + case 'w': + s = u_prnt(s, maxsize, timeptr->tm_wday, 1); + maxsize -= s - olds; + break; + case 'W': + s = u_prnt(s, maxsize, /* ??? */ + (timeptr->tm_yday + 7 - (timeptr->tm_wday + 6) % 7) / 7, 2); + maxsize -= s - olds; + break; + case 'x': + n = strftime(s, maxsize, "%a %b %d %Y", timeptr); + if (n) + maxsize -= n; + else + maxsize = 0; + s += n; + break; + case 'X': + n = strftime(s, maxsize, "%H:%M:%S", timeptr); + if (n) + maxsize -= n; + else + maxsize = 0; + s += n; + break; + case 'y': + s = u_prnt(s, maxsize, timeptr->tm_year % 100, 2); + maxsize -= s - olds; + break; + case 'Y': + s = u_prnt(s, maxsize, timeptr->tm_year + YEAR0, -1); + maxsize -= s - olds; + break; + case 'Z': + s = s_prnt(s, maxsize, + _tzname[(timeptr->tm_isdst > 0)], -1); + maxsize -= s - olds; + break; + case '%': + *s++ = '%'; + maxsize--; + break; + default: + /* A conversion error. Leave the loop. */ + while (*format) + format++; + break; } - } - if (maxsize) { + if (maxsize) + { *s = '\0'; return s - firsts; } - return 0; /* The buffer is full */ + return 0; /* The buffer is full */ } diff --git a/lang/cem/libcc.ansi/time/time.c b/lang/cem/libcc.ansi/time/time.c index f4def4c98..1379723a3 100644 --- a/lang/cem/libcc.ansi/time/time.c +++ b/lang/cem/libcc.ansi/time/time.c @@ -11,13 +11,14 @@ #ifndef ACKCONF_TIME_IS_A_SYSCALL time_t -time(time_t *timer) +time(time_t* timer) { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); - if (timer) *timer = tv.tv_sec; + if (timer) + *timer = tv.tv_sec; return tv.tv_sec; } diff --git a/lang/cem/libcc.ansi/time/tzset.c b/lang/cem/libcc.ansi/time/tzset.c index 04d498db8..94b38d6d5 100644 --- a/lang/cem/libcc.ansi/time/tzset.c +++ b/lang/cem/libcc.ansi/time/tzset.c @@ -5,11 +5,10 @@ /* This function is present for System V && POSIX */ -#include -#include "loc_time.h" +#include +#include "loc_time.h" -void -tzset(void) +void tzset(void) { - _tzset(); /* does the job */ + _tzset(); /* does the job */ } From 83e1b2ad9467551776c96ad361c0aeec66bd4870 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:39:08 +0200 Subject: [PATCH 02/37] Move the str and mem functions into the new src/core. --- lang/cem/libcc.ansi/build.lua | 1 + .../libcc.ansi/{string => errno}/strerror.c | 0 .../libcc.ansi/{string => src/core}/memchr.c | 0 .../libcc.ansi/{string => src/core}/memcmp.c | 0 .../libcc.ansi/{string => src/core}/memcpy.c | 0 .../libcc.ansi/{string => src/core}/memmove.c | 0 .../libcc.ansi/{string => src/core}/memset.c | 0 .../libcc.ansi/{string => src/core}/strcat.c | 0 .../libcc.ansi/{string => src/core}/strchr.c | 0 .../libcc.ansi/{string => src/core}/strcmp.c | 0 .../libcc.ansi/{string => src/core}/strcoll.c | 0 .../libcc.ansi/{string => src/core}/strcpy.c | 0 .../libcc.ansi/{string => src/core}/strcspn.c | 0 .../libcc.ansi/{string => src/core}/strdup.c | 0 .../libcc.ansi/{string => src/core}/strlen.c | 0 .../libcc.ansi/{string => src/core}/strncat.c | 0 .../libcc.ansi/{string => src/core}/strncmp.c | 0 .../libcc.ansi/{string => src/core}/strncpy.c | 0 .../libcc.ansi/{string => src/core}/strpbrk.c | 0 .../libcc.ansi/{string => src/core}/strrchr.c | 0 .../libcc.ansi/{string => src/core}/strspn.c | 0 .../libcc.ansi/{string => src/core}/strstr.c | 0 .../libcc.ansi/{string => src/core}/strtok.c | 0 .../libcc.ansi/{string => src/core}/strxfrm.c | 0 lang/cem/libcc.ansi/string/LIST | 22 ------------------- lang/cem/libcc.ansi/string/Makefile | 5 ----- 26 files changed, 1 insertion(+), 27 deletions(-) rename lang/cem/libcc.ansi/{string => errno}/strerror.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/memchr.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/memcmp.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/memcpy.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/memmove.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/memset.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strcat.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strchr.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strcmp.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strcoll.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strcpy.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strcspn.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strdup.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strlen.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strncat.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strncmp.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strncpy.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strpbrk.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strrchr.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strspn.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strstr.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strtok.c (100%) rename lang/cem/libcc.ansi/{string => src/core}/strxfrm.c (100%) delete mode 100644 lang/cem/libcc.ansi/string/LIST delete mode 100644 lang/cem/libcc.ansi/string/Makefile diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 27704f208..25011e729 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -33,6 +33,7 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", + "./src/core/*.c", "./ctype/*.c", "./errno/*.c", "./locale/*.c", diff --git a/lang/cem/libcc.ansi/string/strerror.c b/lang/cem/libcc.ansi/errno/strerror.c similarity index 100% rename from lang/cem/libcc.ansi/string/strerror.c rename to lang/cem/libcc.ansi/errno/strerror.c diff --git a/lang/cem/libcc.ansi/string/memchr.c b/lang/cem/libcc.ansi/src/core/memchr.c similarity index 100% rename from lang/cem/libcc.ansi/string/memchr.c rename to lang/cem/libcc.ansi/src/core/memchr.c diff --git a/lang/cem/libcc.ansi/string/memcmp.c b/lang/cem/libcc.ansi/src/core/memcmp.c similarity index 100% rename from lang/cem/libcc.ansi/string/memcmp.c rename to lang/cem/libcc.ansi/src/core/memcmp.c diff --git a/lang/cem/libcc.ansi/string/memcpy.c b/lang/cem/libcc.ansi/src/core/memcpy.c similarity index 100% rename from lang/cem/libcc.ansi/string/memcpy.c rename to lang/cem/libcc.ansi/src/core/memcpy.c diff --git a/lang/cem/libcc.ansi/string/memmove.c b/lang/cem/libcc.ansi/src/core/memmove.c similarity index 100% rename from lang/cem/libcc.ansi/string/memmove.c rename to lang/cem/libcc.ansi/src/core/memmove.c diff --git a/lang/cem/libcc.ansi/string/memset.c b/lang/cem/libcc.ansi/src/core/memset.c similarity index 100% rename from lang/cem/libcc.ansi/string/memset.c rename to lang/cem/libcc.ansi/src/core/memset.c diff --git a/lang/cem/libcc.ansi/string/strcat.c b/lang/cem/libcc.ansi/src/core/strcat.c similarity index 100% rename from lang/cem/libcc.ansi/string/strcat.c rename to lang/cem/libcc.ansi/src/core/strcat.c diff --git a/lang/cem/libcc.ansi/string/strchr.c b/lang/cem/libcc.ansi/src/core/strchr.c similarity index 100% rename from lang/cem/libcc.ansi/string/strchr.c rename to lang/cem/libcc.ansi/src/core/strchr.c diff --git a/lang/cem/libcc.ansi/string/strcmp.c b/lang/cem/libcc.ansi/src/core/strcmp.c similarity index 100% rename from lang/cem/libcc.ansi/string/strcmp.c rename to lang/cem/libcc.ansi/src/core/strcmp.c diff --git a/lang/cem/libcc.ansi/string/strcoll.c b/lang/cem/libcc.ansi/src/core/strcoll.c similarity index 100% rename from lang/cem/libcc.ansi/string/strcoll.c rename to lang/cem/libcc.ansi/src/core/strcoll.c diff --git a/lang/cem/libcc.ansi/string/strcpy.c b/lang/cem/libcc.ansi/src/core/strcpy.c similarity index 100% rename from lang/cem/libcc.ansi/string/strcpy.c rename to lang/cem/libcc.ansi/src/core/strcpy.c diff --git a/lang/cem/libcc.ansi/string/strcspn.c b/lang/cem/libcc.ansi/src/core/strcspn.c similarity index 100% rename from lang/cem/libcc.ansi/string/strcspn.c rename to lang/cem/libcc.ansi/src/core/strcspn.c diff --git a/lang/cem/libcc.ansi/string/strdup.c b/lang/cem/libcc.ansi/src/core/strdup.c similarity index 100% rename from lang/cem/libcc.ansi/string/strdup.c rename to lang/cem/libcc.ansi/src/core/strdup.c diff --git a/lang/cem/libcc.ansi/string/strlen.c b/lang/cem/libcc.ansi/src/core/strlen.c similarity index 100% rename from lang/cem/libcc.ansi/string/strlen.c rename to lang/cem/libcc.ansi/src/core/strlen.c diff --git a/lang/cem/libcc.ansi/string/strncat.c b/lang/cem/libcc.ansi/src/core/strncat.c similarity index 100% rename from lang/cem/libcc.ansi/string/strncat.c rename to lang/cem/libcc.ansi/src/core/strncat.c diff --git a/lang/cem/libcc.ansi/string/strncmp.c b/lang/cem/libcc.ansi/src/core/strncmp.c similarity index 100% rename from lang/cem/libcc.ansi/string/strncmp.c rename to lang/cem/libcc.ansi/src/core/strncmp.c diff --git a/lang/cem/libcc.ansi/string/strncpy.c b/lang/cem/libcc.ansi/src/core/strncpy.c similarity index 100% rename from lang/cem/libcc.ansi/string/strncpy.c rename to lang/cem/libcc.ansi/src/core/strncpy.c diff --git a/lang/cem/libcc.ansi/string/strpbrk.c b/lang/cem/libcc.ansi/src/core/strpbrk.c similarity index 100% rename from lang/cem/libcc.ansi/string/strpbrk.c rename to lang/cem/libcc.ansi/src/core/strpbrk.c diff --git a/lang/cem/libcc.ansi/string/strrchr.c b/lang/cem/libcc.ansi/src/core/strrchr.c similarity index 100% rename from lang/cem/libcc.ansi/string/strrchr.c rename to lang/cem/libcc.ansi/src/core/strrchr.c diff --git a/lang/cem/libcc.ansi/string/strspn.c b/lang/cem/libcc.ansi/src/core/strspn.c similarity index 100% rename from lang/cem/libcc.ansi/string/strspn.c rename to lang/cem/libcc.ansi/src/core/strspn.c diff --git a/lang/cem/libcc.ansi/string/strstr.c b/lang/cem/libcc.ansi/src/core/strstr.c similarity index 100% rename from lang/cem/libcc.ansi/string/strstr.c rename to lang/cem/libcc.ansi/src/core/strstr.c diff --git a/lang/cem/libcc.ansi/string/strtok.c b/lang/cem/libcc.ansi/src/core/strtok.c similarity index 100% rename from lang/cem/libcc.ansi/string/strtok.c rename to lang/cem/libcc.ansi/src/core/strtok.c diff --git a/lang/cem/libcc.ansi/string/strxfrm.c b/lang/cem/libcc.ansi/src/core/strxfrm.c similarity index 100% rename from lang/cem/libcc.ansi/string/strxfrm.c rename to lang/cem/libcc.ansi/src/core/strxfrm.c diff --git a/lang/cem/libcc.ansi/string/LIST b/lang/cem/libcc.ansi/string/LIST deleted file mode 100644 index 5f594fd11..000000000 --- a/lang/cem/libcc.ansi/string/LIST +++ /dev/null @@ -1,22 +0,0 @@ -memchr.c -memcmp.c -memcpy.c -memmove.c -memset.c -strcat.c -strchr.c -strcmp.c -strcoll.c -strcpy.c -strcspn.c -strerror.c -strncat.c -strncpy.c -strrchr.c -strstr.c -strlen.c -strtok.c -strpbrk.c -strspn.c -strncmp.c -strxfrm.c diff --git a/lang/cem/libcc.ansi/string/Makefile b/lang/cem/libcc.ansi/string/Makefile deleted file mode 100644 index f6263807f..000000000 --- a/lang/cem/libcc.ansi/string/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -clean: - rm -f memchr.o memcmp.o memcpy.o memmove.o memset.o strcat.o \ - strchr.o strcmp.o strcoll.o strcpy.o strcspn.o strerror.o \ - strncat.o strncpy.o strrchr.o strstr.o strlen.o strtok.o \ - strpbrk.o strspn.o strncmp.o strxfrm.o OLIST From 4dbdb7d8d52702fe404f0bdf2909e1f48404c737 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:47:02 +0200 Subject: [PATCH 03/37] Rethink the libc layout. --- lang/cem/libcc.ansi/build.lua | 2 +- lang/cem/libcc.ansi/pure/README.md | 3 +++ lang/cem/libcc.ansi/{src/core => pure/string}/memchr.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/memcmp.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/memcpy.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/memmove.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/memset.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strcat.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strchr.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strcmp.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strcoll.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strcpy.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strcspn.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strdup.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strlen.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strncat.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strncmp.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strncpy.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strpbrk.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strrchr.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strspn.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strstr.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strtok.c | 0 lang/cem/libcc.ansi/{src/core => pure/string}/strxfrm.c | 0 24 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 lang/cem/libcc.ansi/pure/README.md rename lang/cem/libcc.ansi/{src/core => pure/string}/memchr.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/memcmp.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/memcpy.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/memmove.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/memset.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strcat.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strchr.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strcmp.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strcoll.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strcpy.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strcspn.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strdup.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strlen.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strncat.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strncmp.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strncpy.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strpbrk.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strrchr.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strspn.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strstr.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strtok.c (100%) rename lang/cem/libcc.ansi/{src/core => pure/string}/strxfrm.c (100%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 25011e729..fce3470af 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -33,7 +33,7 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", - "./src/core/*.c", + "./pure/string/*.c", "./ctype/*.c", "./errno/*.c", "./locale/*.c", diff --git a/lang/cem/libcc.ansi/pure/README.md b/lang/cem/libcc.ansi/pure/README.md new file mode 100644 index 000000000..484205837 --- /dev/null +++ b/lang/cem/libcc.ansi/pure/README.md @@ -0,0 +1,3 @@ +This directory contains _only_ pure-code libc functions with no dependencies +on anything other than other pure functions (for example: strcmp, div). There +should be no reason why any platform won't want these in its libc. diff --git a/lang/cem/libcc.ansi/src/core/memchr.c b/lang/cem/libcc.ansi/pure/string/memchr.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/memchr.c rename to lang/cem/libcc.ansi/pure/string/memchr.c diff --git a/lang/cem/libcc.ansi/src/core/memcmp.c b/lang/cem/libcc.ansi/pure/string/memcmp.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/memcmp.c rename to lang/cem/libcc.ansi/pure/string/memcmp.c diff --git a/lang/cem/libcc.ansi/src/core/memcpy.c b/lang/cem/libcc.ansi/pure/string/memcpy.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/memcpy.c rename to lang/cem/libcc.ansi/pure/string/memcpy.c diff --git a/lang/cem/libcc.ansi/src/core/memmove.c b/lang/cem/libcc.ansi/pure/string/memmove.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/memmove.c rename to lang/cem/libcc.ansi/pure/string/memmove.c diff --git a/lang/cem/libcc.ansi/src/core/memset.c b/lang/cem/libcc.ansi/pure/string/memset.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/memset.c rename to lang/cem/libcc.ansi/pure/string/memset.c diff --git a/lang/cem/libcc.ansi/src/core/strcat.c b/lang/cem/libcc.ansi/pure/string/strcat.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strcat.c rename to lang/cem/libcc.ansi/pure/string/strcat.c diff --git a/lang/cem/libcc.ansi/src/core/strchr.c b/lang/cem/libcc.ansi/pure/string/strchr.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strchr.c rename to lang/cem/libcc.ansi/pure/string/strchr.c diff --git a/lang/cem/libcc.ansi/src/core/strcmp.c b/lang/cem/libcc.ansi/pure/string/strcmp.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strcmp.c rename to lang/cem/libcc.ansi/pure/string/strcmp.c diff --git a/lang/cem/libcc.ansi/src/core/strcoll.c b/lang/cem/libcc.ansi/pure/string/strcoll.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strcoll.c rename to lang/cem/libcc.ansi/pure/string/strcoll.c diff --git a/lang/cem/libcc.ansi/src/core/strcpy.c b/lang/cem/libcc.ansi/pure/string/strcpy.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strcpy.c rename to lang/cem/libcc.ansi/pure/string/strcpy.c diff --git a/lang/cem/libcc.ansi/src/core/strcspn.c b/lang/cem/libcc.ansi/pure/string/strcspn.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strcspn.c rename to lang/cem/libcc.ansi/pure/string/strcspn.c diff --git a/lang/cem/libcc.ansi/src/core/strdup.c b/lang/cem/libcc.ansi/pure/string/strdup.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strdup.c rename to lang/cem/libcc.ansi/pure/string/strdup.c diff --git a/lang/cem/libcc.ansi/src/core/strlen.c b/lang/cem/libcc.ansi/pure/string/strlen.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strlen.c rename to lang/cem/libcc.ansi/pure/string/strlen.c diff --git a/lang/cem/libcc.ansi/src/core/strncat.c b/lang/cem/libcc.ansi/pure/string/strncat.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strncat.c rename to lang/cem/libcc.ansi/pure/string/strncat.c diff --git a/lang/cem/libcc.ansi/src/core/strncmp.c b/lang/cem/libcc.ansi/pure/string/strncmp.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strncmp.c rename to lang/cem/libcc.ansi/pure/string/strncmp.c diff --git a/lang/cem/libcc.ansi/src/core/strncpy.c b/lang/cem/libcc.ansi/pure/string/strncpy.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strncpy.c rename to lang/cem/libcc.ansi/pure/string/strncpy.c diff --git a/lang/cem/libcc.ansi/src/core/strpbrk.c b/lang/cem/libcc.ansi/pure/string/strpbrk.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strpbrk.c rename to lang/cem/libcc.ansi/pure/string/strpbrk.c diff --git a/lang/cem/libcc.ansi/src/core/strrchr.c b/lang/cem/libcc.ansi/pure/string/strrchr.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strrchr.c rename to lang/cem/libcc.ansi/pure/string/strrchr.c diff --git a/lang/cem/libcc.ansi/src/core/strspn.c b/lang/cem/libcc.ansi/pure/string/strspn.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strspn.c rename to lang/cem/libcc.ansi/pure/string/strspn.c diff --git a/lang/cem/libcc.ansi/src/core/strstr.c b/lang/cem/libcc.ansi/pure/string/strstr.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strstr.c rename to lang/cem/libcc.ansi/pure/string/strstr.c diff --git a/lang/cem/libcc.ansi/src/core/strtok.c b/lang/cem/libcc.ansi/pure/string/strtok.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strtok.c rename to lang/cem/libcc.ansi/pure/string/strtok.c diff --git a/lang/cem/libcc.ansi/src/core/strxfrm.c b/lang/cem/libcc.ansi/pure/string/strxfrm.c similarity index 100% rename from lang/cem/libcc.ansi/src/core/strxfrm.c rename to lang/cem/libcc.ansi/pure/string/strxfrm.c From b9d2f353d96fb5452df9a85f13164435edcdd6c3 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:52:31 +0200 Subject: [PATCH 04/37] Move the pure stdlib functions into the new pure directory. --- lang/cem/libcc.ansi/build.lua | 1 + lang/cem/libcc.ansi/{ => pure}/stdlib/abs.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/atoi.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/atol.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/bsearch.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/div.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/getenv.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/labs.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/ldiv.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/mblen.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/mbstowcs.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/mbtowc.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/putenv.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/qsort.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/rand.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/setenv.c | 2 +- lang/cem/libcc.ansi/{ => pure}/stdlib/strtol.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/wcstombs.c | 0 lang/cem/libcc.ansi/{ => pure}/stdlib/wctomb.c | 0 19 files changed, 2 insertions(+), 1 deletion(-) rename lang/cem/libcc.ansi/{ => pure}/stdlib/abs.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/atoi.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/atol.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/bsearch.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/div.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/getenv.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/labs.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/ldiv.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/mblen.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/mbstowcs.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/mbtowc.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/putenv.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/qsort.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/rand.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/setenv.c (97%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/strtol.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/wcstombs.c (100%) rename lang/cem/libcc.ansi/{ => pure}/stdlib/wctomb.c (100%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index fce3470af..7536d002f 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -34,6 +34,7 @@ for _, plat in ipairs(vars.plats) do "+ctype_files", "+ctype_tab", "./pure/string/*.c", + "./pure/stdlib/*.c", "./ctype/*.c", "./errno/*.c", "./locale/*.c", diff --git a/lang/cem/libcc.ansi/stdlib/abs.c b/lang/cem/libcc.ansi/pure/stdlib/abs.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/abs.c rename to lang/cem/libcc.ansi/pure/stdlib/abs.c diff --git a/lang/cem/libcc.ansi/stdlib/atoi.c b/lang/cem/libcc.ansi/pure/stdlib/atoi.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/atoi.c rename to lang/cem/libcc.ansi/pure/stdlib/atoi.c diff --git a/lang/cem/libcc.ansi/stdlib/atol.c b/lang/cem/libcc.ansi/pure/stdlib/atol.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/atol.c rename to lang/cem/libcc.ansi/pure/stdlib/atol.c diff --git a/lang/cem/libcc.ansi/stdlib/bsearch.c b/lang/cem/libcc.ansi/pure/stdlib/bsearch.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/bsearch.c rename to lang/cem/libcc.ansi/pure/stdlib/bsearch.c diff --git a/lang/cem/libcc.ansi/stdlib/div.c b/lang/cem/libcc.ansi/pure/stdlib/div.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/div.c rename to lang/cem/libcc.ansi/pure/stdlib/div.c diff --git a/lang/cem/libcc.ansi/stdlib/getenv.c b/lang/cem/libcc.ansi/pure/stdlib/getenv.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/getenv.c rename to lang/cem/libcc.ansi/pure/stdlib/getenv.c diff --git a/lang/cem/libcc.ansi/stdlib/labs.c b/lang/cem/libcc.ansi/pure/stdlib/labs.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/labs.c rename to lang/cem/libcc.ansi/pure/stdlib/labs.c diff --git a/lang/cem/libcc.ansi/stdlib/ldiv.c b/lang/cem/libcc.ansi/pure/stdlib/ldiv.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/ldiv.c rename to lang/cem/libcc.ansi/pure/stdlib/ldiv.c diff --git a/lang/cem/libcc.ansi/stdlib/mblen.c b/lang/cem/libcc.ansi/pure/stdlib/mblen.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/mblen.c rename to lang/cem/libcc.ansi/pure/stdlib/mblen.c diff --git a/lang/cem/libcc.ansi/stdlib/mbstowcs.c b/lang/cem/libcc.ansi/pure/stdlib/mbstowcs.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/mbstowcs.c rename to lang/cem/libcc.ansi/pure/stdlib/mbstowcs.c diff --git a/lang/cem/libcc.ansi/stdlib/mbtowc.c b/lang/cem/libcc.ansi/pure/stdlib/mbtowc.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/mbtowc.c rename to lang/cem/libcc.ansi/pure/stdlib/mbtowc.c diff --git a/lang/cem/libcc.ansi/stdlib/putenv.c b/lang/cem/libcc.ansi/pure/stdlib/putenv.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/putenv.c rename to lang/cem/libcc.ansi/pure/stdlib/putenv.c diff --git a/lang/cem/libcc.ansi/stdlib/qsort.c b/lang/cem/libcc.ansi/pure/stdlib/qsort.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/qsort.c rename to lang/cem/libcc.ansi/pure/stdlib/qsort.c diff --git a/lang/cem/libcc.ansi/stdlib/rand.c b/lang/cem/libcc.ansi/pure/stdlib/rand.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/rand.c rename to lang/cem/libcc.ansi/pure/stdlib/rand.c diff --git a/lang/cem/libcc.ansi/stdlib/setenv.c b/lang/cem/libcc.ansi/pure/stdlib/setenv.c similarity index 97% rename from lang/cem/libcc.ansi/stdlib/setenv.c rename to lang/cem/libcc.ansi/pure/stdlib/setenv.c index e6f7b8d88..c973bd58a 100644 --- a/lang/cem/libcc.ansi/stdlib/setenv.c +++ b/lang/cem/libcc.ansi/pure/stdlib/setenv.c @@ -64,7 +64,7 @@ int setenv(register const char* name, register const char* value, int rewrite) environ[cnt + 1] = NULL; offset = cnt; } - for (C = name; *C && *C != '='; ++C) + for (C = (char*) name; *C && *C != '='; ++C) ; /* no `=' in name */ if (!(environ[offset] = /* name + `=' + value */ malloc((unsigned)((int)(C - name) + l_value + 2)))) diff --git a/lang/cem/libcc.ansi/stdlib/strtol.c b/lang/cem/libcc.ansi/pure/stdlib/strtol.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/strtol.c rename to lang/cem/libcc.ansi/pure/stdlib/strtol.c diff --git a/lang/cem/libcc.ansi/stdlib/wcstombs.c b/lang/cem/libcc.ansi/pure/stdlib/wcstombs.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/wcstombs.c rename to lang/cem/libcc.ansi/pure/stdlib/wcstombs.c diff --git a/lang/cem/libcc.ansi/stdlib/wctomb.c b/lang/cem/libcc.ansi/pure/stdlib/wctomb.c similarity index 100% rename from lang/cem/libcc.ansi/stdlib/wctomb.c rename to lang/cem/libcc.ansi/pure/stdlib/wctomb.c From 32f47b1d24126bec36c0f6d830b99a0d73ade909 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:54:25 +0200 Subject: [PATCH 05/37] Move the pure locale functions into the new pure directory. --- lang/cem/libcc.ansi/build.lua | 1 + lang/cem/libcc.ansi/locale/LIST | 2 -- lang/cem/libcc.ansi/locale/Makefile | 2 -- lang/cem/libcc.ansi/{ => pure}/locale/localeconv.c | 0 lang/cem/libcc.ansi/{ => pure}/locale/setlocale.c | 0 5 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 lang/cem/libcc.ansi/locale/LIST delete mode 100644 lang/cem/libcc.ansi/locale/Makefile rename lang/cem/libcc.ansi/{ => pure}/locale/localeconv.c (100%) rename lang/cem/libcc.ansi/{ => pure}/locale/setlocale.c (100%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 7536d002f..8ff63ea7c 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -35,6 +35,7 @@ for _, plat in ipairs(vars.plats) do "+ctype_tab", "./pure/string/*.c", "./pure/stdlib/*.c", + "./pure/locale/*.c", "./ctype/*.c", "./errno/*.c", "./locale/*.c", diff --git a/lang/cem/libcc.ansi/locale/LIST b/lang/cem/libcc.ansi/locale/LIST deleted file mode 100644 index 6ec7d31e6..000000000 --- a/lang/cem/libcc.ansi/locale/LIST +++ /dev/null @@ -1,2 +0,0 @@ -localeconv.c -setlocale.c diff --git a/lang/cem/libcc.ansi/locale/Makefile b/lang/cem/libcc.ansi/locale/Makefile deleted file mode 100644 index dea8cb17b..000000000 --- a/lang/cem/libcc.ansi/locale/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f localeconv.o setlocale.o OLIST diff --git a/lang/cem/libcc.ansi/locale/localeconv.c b/lang/cem/libcc.ansi/pure/locale/localeconv.c similarity index 100% rename from lang/cem/libcc.ansi/locale/localeconv.c rename to lang/cem/libcc.ansi/pure/locale/localeconv.c diff --git a/lang/cem/libcc.ansi/locale/setlocale.c b/lang/cem/libcc.ansi/pure/locale/setlocale.c similarity index 100% rename from lang/cem/libcc.ansi/locale/setlocale.c rename to lang/cem/libcc.ansi/pure/locale/setlocale.c From f9c059812b5121309989cf126e09ba09b69d1526 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 22:55:42 +0200 Subject: [PATCH 06/37] Moved the setjmp functions into the new pure directoy. --- lang/cem/libcc.ansi/build.lua | 5 ++--- lang/cem/libcc.ansi/{ => pure}/setjmp/setjmp.e | 0 lang/cem/libcc.ansi/{ => pure}/setjmp/sigmisc.c | 0 lang/cem/libcc.ansi/setjmp/LIST | 2 -- lang/cem/libcc.ansi/setjmp/Makefile | 2 -- 5 files changed, 2 insertions(+), 7 deletions(-) rename lang/cem/libcc.ansi/{ => pure}/setjmp/setjmp.e (100%) rename lang/cem/libcc.ansi/{ => pure}/setjmp/sigmisc.c (100%) delete mode 100644 lang/cem/libcc.ansi/setjmp/LIST delete mode 100644 lang/cem/libcc.ansi/setjmp/Makefile diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 8ff63ea7c..e1845eb69 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -36,15 +36,14 @@ for _, plat in ipairs(vars.plats) do "./pure/string/*.c", "./pure/stdlib/*.c", "./pure/locale/*.c", + "./pure/setjmp/*.c", + "./pure/setjmp/*.e", "./ctype/*.c", "./errno/*.c", - "./locale/*.c", "./malloc/*.c", "./math/*.c", -- hypot.c "./math/*.e", "./misc/environ.c", -- don't build everything here as it's all obsolete - "./setjmp/*.c", - "./setjmp/*.e", "./signal/*.c", "./assert/*.c", "./stdio/*.c", diff --git a/lang/cem/libcc.ansi/setjmp/setjmp.e b/lang/cem/libcc.ansi/pure/setjmp/setjmp.e similarity index 100% rename from lang/cem/libcc.ansi/setjmp/setjmp.e rename to lang/cem/libcc.ansi/pure/setjmp/setjmp.e diff --git a/lang/cem/libcc.ansi/setjmp/sigmisc.c b/lang/cem/libcc.ansi/pure/setjmp/sigmisc.c similarity index 100% rename from lang/cem/libcc.ansi/setjmp/sigmisc.c rename to lang/cem/libcc.ansi/pure/setjmp/sigmisc.c diff --git a/lang/cem/libcc.ansi/setjmp/LIST b/lang/cem/libcc.ansi/setjmp/LIST deleted file mode 100644 index 63685a130..000000000 --- a/lang/cem/libcc.ansi/setjmp/LIST +++ /dev/null @@ -1,2 +0,0 @@ -setjmp.e -sigmisc.c diff --git a/lang/cem/libcc.ansi/setjmp/Makefile b/lang/cem/libcc.ansi/setjmp/Makefile deleted file mode 100644 index fa727ca6e..000000000 --- a/lang/cem/libcc.ansi/setjmp/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f setjmp.o sigmisc.o OLIST From d9d7ffe0d77a92ffb4c40d909c4813d69cdfe882 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 23:00:33 +0200 Subject: [PATCH 07/37] The maths library is pure. --- lang/cem/libcc.ansi/build.lua | 6 ++--- lang/cem/libcc.ansi/math/LIST | 22 ------------------- lang/cem/libcc.ansi/math/Makefile | 4 ---- lang/cem/libcc.ansi/{ => pure}/math/asin.c | 0 lang/cem/libcc.ansi/{ => pure}/math/atan.c | 0 lang/cem/libcc.ansi/{ => pure}/math/atan2.c | 0 lang/cem/libcc.ansi/{ => pure}/math/ceil.c | 0 lang/cem/libcc.ansi/{ => pure}/math/exp.c | 0 lang/cem/libcc.ansi/{ => pure}/math/fabs.c | 0 lang/cem/libcc.ansi/{ => pure}/math/floor.c | 0 lang/cem/libcc.ansi/{ => pure}/math/fmod.c | 0 lang/cem/libcc.ansi/{ => pure}/math/frexp.e | 0 lang/cem/libcc.ansi/{ => pure}/math/hugeval.c | 0 lang/cem/libcc.ansi/{ => pure}/math/hypot.c | 0 lang/cem/libcc.ansi/{ => pure}/math/isnan.c | 0 lang/cem/libcc.ansi/{ => pure}/math/ldexp.c | 0 .../libcc.ansi/{ => pure}/math/localmath.h | 0 lang/cem/libcc.ansi/{ => pure}/math/log.c | 0 lang/cem/libcc.ansi/{ => pure}/math/log10.c | 0 lang/cem/libcc.ansi/{ => pure}/math/modf.e | 0 lang/cem/libcc.ansi/{ => pure}/math/pow.c | 0 lang/cem/libcc.ansi/{ => pure}/math/sin.c | 0 lang/cem/libcc.ansi/{ => pure}/math/sinh.c | 0 lang/cem/libcc.ansi/{ => pure}/math/sqrt.c | 0 lang/cem/libcc.ansi/{ => pure}/math/tan.c | 0 lang/cem/libcc.ansi/{ => pure}/math/tanh.c | 0 26 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 lang/cem/libcc.ansi/math/LIST delete mode 100644 lang/cem/libcc.ansi/math/Makefile rename lang/cem/libcc.ansi/{ => pure}/math/asin.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/atan.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/atan2.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/ceil.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/exp.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/fabs.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/floor.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/fmod.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/frexp.e (100%) rename lang/cem/libcc.ansi/{ => pure}/math/hugeval.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/hypot.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/isnan.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/ldexp.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/localmath.h (100%) rename lang/cem/libcc.ansi/{ => pure}/math/log.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/log10.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/modf.e (100%) rename lang/cem/libcc.ansi/{ => pure}/math/pow.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/sin.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/sinh.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/sqrt.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/tan.c (100%) rename lang/cem/libcc.ansi/{ => pure}/math/tanh.c (100%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index e1845eb69..47d9bc4b3 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -38,11 +38,11 @@ for _, plat in ipairs(vars.plats) do "./pure/locale/*.c", "./pure/setjmp/*.c", "./pure/setjmp/*.e", + "./pure/math/*.c", -- hypot.c + "./pure/math/*.e", "./ctype/*.c", "./errno/*.c", "./malloc/*.c", - "./math/*.c", -- hypot.c - "./math/*.e", "./misc/environ.c", -- don't build everything here as it's all obsolete "./signal/*.c", "./assert/*.c", @@ -56,7 +56,7 @@ for _, plat in ipairs(vars.plats) do "lang/cem/libcc.ansi/headers+pkg", "plat/"..plat.."/include+pkg", "./malloc/malloc.h", - "./math/localmath.h", + "./pure/math/localmath.h", "./stdio/loc_incl.h", "./stdlib/ext_fmt.h", "./time/loc_time.h", diff --git a/lang/cem/libcc.ansi/math/LIST b/lang/cem/libcc.ansi/math/LIST deleted file mode 100644 index 09a0b3c06..000000000 --- a/lang/cem/libcc.ansi/math/LIST +++ /dev/null @@ -1,22 +0,0 @@ -localmath.h -asin.c -atan2.c -atan.c -ceil.c -fabs.c -pow.c -log10.c -log.c -sin.c -sinh.c -sqrt.c -tan.c -tanh.c -exp.c -ldexp.c -fmod.c -floor.c -hugeval.c -frexp.e -modf.e -isnan.c diff --git a/lang/cem/libcc.ansi/math/Makefile b/lang/cem/libcc.ansi/math/Makefile deleted file mode 100644 index 1081596a0..000000000 --- a/lang/cem/libcc.ansi/math/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -clean: - rm -f asin.o atan2.o atan.o ceil.o fabs.o pow.o log10.o \ - log.o sin.o sinh.o sqrt.o tan.o tanh.o exp.o ldexp.o \ - fmod.o floor.o hugeval.o frexp.o modf.o isnan.o OLIST diff --git a/lang/cem/libcc.ansi/math/asin.c b/lang/cem/libcc.ansi/pure/math/asin.c similarity index 100% rename from lang/cem/libcc.ansi/math/asin.c rename to lang/cem/libcc.ansi/pure/math/asin.c diff --git a/lang/cem/libcc.ansi/math/atan.c b/lang/cem/libcc.ansi/pure/math/atan.c similarity index 100% rename from lang/cem/libcc.ansi/math/atan.c rename to lang/cem/libcc.ansi/pure/math/atan.c diff --git a/lang/cem/libcc.ansi/math/atan2.c b/lang/cem/libcc.ansi/pure/math/atan2.c similarity index 100% rename from lang/cem/libcc.ansi/math/atan2.c rename to lang/cem/libcc.ansi/pure/math/atan2.c diff --git a/lang/cem/libcc.ansi/math/ceil.c b/lang/cem/libcc.ansi/pure/math/ceil.c similarity index 100% rename from lang/cem/libcc.ansi/math/ceil.c rename to lang/cem/libcc.ansi/pure/math/ceil.c diff --git a/lang/cem/libcc.ansi/math/exp.c b/lang/cem/libcc.ansi/pure/math/exp.c similarity index 100% rename from lang/cem/libcc.ansi/math/exp.c rename to lang/cem/libcc.ansi/pure/math/exp.c diff --git a/lang/cem/libcc.ansi/math/fabs.c b/lang/cem/libcc.ansi/pure/math/fabs.c similarity index 100% rename from lang/cem/libcc.ansi/math/fabs.c rename to lang/cem/libcc.ansi/pure/math/fabs.c diff --git a/lang/cem/libcc.ansi/math/floor.c b/lang/cem/libcc.ansi/pure/math/floor.c similarity index 100% rename from lang/cem/libcc.ansi/math/floor.c rename to lang/cem/libcc.ansi/pure/math/floor.c diff --git a/lang/cem/libcc.ansi/math/fmod.c b/lang/cem/libcc.ansi/pure/math/fmod.c similarity index 100% rename from lang/cem/libcc.ansi/math/fmod.c rename to lang/cem/libcc.ansi/pure/math/fmod.c diff --git a/lang/cem/libcc.ansi/math/frexp.e b/lang/cem/libcc.ansi/pure/math/frexp.e similarity index 100% rename from lang/cem/libcc.ansi/math/frexp.e rename to lang/cem/libcc.ansi/pure/math/frexp.e diff --git a/lang/cem/libcc.ansi/math/hugeval.c b/lang/cem/libcc.ansi/pure/math/hugeval.c similarity index 100% rename from lang/cem/libcc.ansi/math/hugeval.c rename to lang/cem/libcc.ansi/pure/math/hugeval.c diff --git a/lang/cem/libcc.ansi/math/hypot.c b/lang/cem/libcc.ansi/pure/math/hypot.c similarity index 100% rename from lang/cem/libcc.ansi/math/hypot.c rename to lang/cem/libcc.ansi/pure/math/hypot.c diff --git a/lang/cem/libcc.ansi/math/isnan.c b/lang/cem/libcc.ansi/pure/math/isnan.c similarity index 100% rename from lang/cem/libcc.ansi/math/isnan.c rename to lang/cem/libcc.ansi/pure/math/isnan.c diff --git a/lang/cem/libcc.ansi/math/ldexp.c b/lang/cem/libcc.ansi/pure/math/ldexp.c similarity index 100% rename from lang/cem/libcc.ansi/math/ldexp.c rename to lang/cem/libcc.ansi/pure/math/ldexp.c diff --git a/lang/cem/libcc.ansi/math/localmath.h b/lang/cem/libcc.ansi/pure/math/localmath.h similarity index 100% rename from lang/cem/libcc.ansi/math/localmath.h rename to lang/cem/libcc.ansi/pure/math/localmath.h diff --git a/lang/cem/libcc.ansi/math/log.c b/lang/cem/libcc.ansi/pure/math/log.c similarity index 100% rename from lang/cem/libcc.ansi/math/log.c rename to lang/cem/libcc.ansi/pure/math/log.c diff --git a/lang/cem/libcc.ansi/math/log10.c b/lang/cem/libcc.ansi/pure/math/log10.c similarity index 100% rename from lang/cem/libcc.ansi/math/log10.c rename to lang/cem/libcc.ansi/pure/math/log10.c diff --git a/lang/cem/libcc.ansi/math/modf.e b/lang/cem/libcc.ansi/pure/math/modf.e similarity index 100% rename from lang/cem/libcc.ansi/math/modf.e rename to lang/cem/libcc.ansi/pure/math/modf.e diff --git a/lang/cem/libcc.ansi/math/pow.c b/lang/cem/libcc.ansi/pure/math/pow.c similarity index 100% rename from lang/cem/libcc.ansi/math/pow.c rename to lang/cem/libcc.ansi/pure/math/pow.c diff --git a/lang/cem/libcc.ansi/math/sin.c b/lang/cem/libcc.ansi/pure/math/sin.c similarity index 100% rename from lang/cem/libcc.ansi/math/sin.c rename to lang/cem/libcc.ansi/pure/math/sin.c diff --git a/lang/cem/libcc.ansi/math/sinh.c b/lang/cem/libcc.ansi/pure/math/sinh.c similarity index 100% rename from lang/cem/libcc.ansi/math/sinh.c rename to lang/cem/libcc.ansi/pure/math/sinh.c diff --git a/lang/cem/libcc.ansi/math/sqrt.c b/lang/cem/libcc.ansi/pure/math/sqrt.c similarity index 100% rename from lang/cem/libcc.ansi/math/sqrt.c rename to lang/cem/libcc.ansi/pure/math/sqrt.c diff --git a/lang/cem/libcc.ansi/math/tan.c b/lang/cem/libcc.ansi/pure/math/tan.c similarity index 100% rename from lang/cem/libcc.ansi/math/tan.c rename to lang/cem/libcc.ansi/pure/math/tan.c diff --git a/lang/cem/libcc.ansi/math/tanh.c b/lang/cem/libcc.ansi/pure/math/tanh.c similarity index 100% rename from lang/cem/libcc.ansi/math/tanh.c rename to lang/cem/libcc.ansi/pure/math/tanh.c From 62025c92bdec6048ffa70b361279f4f3277c8d8f Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 23:06:29 +0200 Subject: [PATCH 08/37] The ctype functions are pure. --- lang/cem/libcc.ansi/build.lua | 6 +++--- lang/cem/libcc.ansi/ctype/LIST | 15 --------------- lang/cem/libcc.ansi/ctype/Makefile | 15 --------------- lang/cem/libcc.ansi/{ => pure}/ctype/char.tab | 0 lang/cem/libcc.ansi/{ => pure}/ctype/genfiles | 0 lang/cem/libcc.ansi/{ => pure}/ctype/tolower.c | 0 lang/cem/libcc.ansi/{ => pure}/ctype/toupper.c | 0 7 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 lang/cem/libcc.ansi/ctype/LIST delete mode 100644 lang/cem/libcc.ansi/ctype/Makefile rename lang/cem/libcc.ansi/{ => pure}/ctype/char.tab (100%) rename lang/cem/libcc.ansi/{ => pure}/ctype/genfiles (100%) rename lang/cem/libcc.ansi/{ => pure}/ctype/tolower.c (100%) rename lang/cem/libcc.ansi/{ => pure}/ctype/toupper.c (100%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 47d9bc4b3..c49bdf0e2 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -2,12 +2,12 @@ include("plat/build.lua") tabgen { name = "ctype_tab", - srcs = { "./ctype/char.tab" } + srcs = { "./pure/ctype/char.tab" } } normalrule { name = "ctype_files", - ins = { "./ctype/genfiles" }, + ins = { "./pure/ctype/genfiles" }, outleaves = { "isalnum.c", "isalpha.c", @@ -40,7 +40,7 @@ for _, plat in ipairs(vars.plats) do "./pure/setjmp/*.e", "./pure/math/*.c", -- hypot.c "./pure/math/*.e", - "./ctype/*.c", + "./pure/ctype/*.c", "./errno/*.c", "./malloc/*.c", "./misc/environ.c", -- don't build everything here as it's all obsolete diff --git a/lang/cem/libcc.ansi/ctype/LIST b/lang/cem/libcc.ansi/ctype/LIST deleted file mode 100644 index a8f581760..000000000 --- a/lang/cem/libcc.ansi/ctype/LIST +++ /dev/null @@ -1,15 +0,0 @@ -isalnum.c -isalpha.c -iscntrl.c -isdigit.c -isgraph.c -islower.c -isprint.c -ispunct.c -isspace.c -isupper.c -isxdigit.c -isascii.c -toupper.c -tolower.c -chartab.c diff --git a/lang/cem/libcc.ansi/ctype/Makefile b/lang/cem/libcc.ansi/ctype/Makefile deleted file mode 100644 index 56ef72a02..000000000 --- a/lang/cem/libcc.ansi/ctype/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -clean: - rm -f isalnum.o isalpha.o iscntrl.o isdigit.o isgraph.o \ - islower.o isprint.o ispunct.o isspace.o isupper.o \ - isxdigit.o isascii.o tolower.o toupper.o chartab.o \ - isalnum.c isalpha.c iscntrl.c isdigit.c isgraph.c \ - islower.c isprint.c ispunct.c isspace.c isupper.c \ - isxdigit.c isascii.c chartab.c \ - OLIST - -chartab.c: char.tab - tabgen -fchar.tab > chartab.c - -isalnum.c isalpha.c iscntrl.c isdigit.c isgraph.c islower.c isprint.c \ -ispunct.c isspace.c isupper.c isxdigit.c isascii.c: genfiles - sh genfiles diff --git a/lang/cem/libcc.ansi/ctype/char.tab b/lang/cem/libcc.ansi/pure/ctype/char.tab similarity index 100% rename from lang/cem/libcc.ansi/ctype/char.tab rename to lang/cem/libcc.ansi/pure/ctype/char.tab diff --git a/lang/cem/libcc.ansi/ctype/genfiles b/lang/cem/libcc.ansi/pure/ctype/genfiles similarity index 100% rename from lang/cem/libcc.ansi/ctype/genfiles rename to lang/cem/libcc.ansi/pure/ctype/genfiles diff --git a/lang/cem/libcc.ansi/ctype/tolower.c b/lang/cem/libcc.ansi/pure/ctype/tolower.c similarity index 100% rename from lang/cem/libcc.ansi/ctype/tolower.c rename to lang/cem/libcc.ansi/pure/ctype/tolower.c diff --git a/lang/cem/libcc.ansi/ctype/toupper.c b/lang/cem/libcc.ansi/pure/ctype/toupper.c similarity index 100% rename from lang/cem/libcc.ansi/ctype/toupper.c rename to lang/cem/libcc.ansi/pure/ctype/toupper.c From d1cdb07719e4aa8e60941bbcc7df9ffe7c0f3f2b Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 21 Jun 2018 23:24:23 +0200 Subject: [PATCH 09/37] Realise that the libc core can safely call other libc core functions, even if they're not defined in the core: so putw() can call stdio stuff, for example. So the earlier concept of pureness isn't necessary. Rename accordingly. --- lang/cem/libcc.ansi/build.lua | 22 +++++++++---------- lang/cem/libcc.ansi/core/README.md | 19 ++++++++++++++++ .../libcc.ansi/{pure => core}/ctype/char.tab | 0 .../libcc.ansi/{pure => core}/ctype/genfiles | 0 .../libcc.ansi/{pure => core}/ctype/tolower.c | 0 .../libcc.ansi/{pure => core}/ctype/toupper.c | 0 .../{pure => core}/locale/localeconv.c | 0 .../{pure => core}/locale/setlocale.c | 0 .../cem/libcc.ansi/{pure => core}/math/asin.c | 0 .../cem/libcc.ansi/{pure => core}/math/atan.c | 0 .../libcc.ansi/{pure => core}/math/atan2.c | 0 .../cem/libcc.ansi/{pure => core}/math/ceil.c | 0 lang/cem/libcc.ansi/{pure => core}/math/exp.c | 0 .../cem/libcc.ansi/{pure => core}/math/fabs.c | 0 .../libcc.ansi/{pure => core}/math/floor.c | 0 .../cem/libcc.ansi/{pure => core}/math/fmod.c | 0 .../libcc.ansi/{pure => core}/math/frexp.e | 0 .../libcc.ansi/{pure => core}/math/hugeval.c | 0 .../libcc.ansi/{pure => core}/math/hypot.c | 0 .../libcc.ansi/{pure => core}/math/isnan.c | 0 .../libcc.ansi/{pure => core}/math/ldexp.c | 0 .../{pure => core}/math/localmath.h | 0 lang/cem/libcc.ansi/{pure => core}/math/log.c | 0 .../libcc.ansi/{pure => core}/math/log10.c | 0 .../cem/libcc.ansi/{pure => core}/math/modf.e | 0 lang/cem/libcc.ansi/{pure => core}/math/pow.c | 0 lang/cem/libcc.ansi/{pure => core}/math/sin.c | 0 .../cem/libcc.ansi/{pure => core}/math/sinh.c | 0 .../cem/libcc.ansi/{pure => core}/math/sqrt.c | 0 lang/cem/libcc.ansi/{pure => core}/math/tan.c | 0 .../cem/libcc.ansi/{pure => core}/math/tanh.c | 0 .../libcc.ansi/{pure => core}/setjmp/setjmp.e | 0 .../{pure => core}/setjmp/sigmisc.c | 0 .../libcc.ansi/{pure => core}/stdlib/abs.c | 0 .../libcc.ansi/{pure => core}/stdlib/atoi.c | 0 .../libcc.ansi/{pure => core}/stdlib/atol.c | 0 .../{pure => core}/stdlib/bsearch.c | 0 .../libcc.ansi/{pure => core}/stdlib/div.c | 0 .../libcc.ansi/{pure => core}/stdlib/getenv.c | 0 .../libcc.ansi/{pure => core}/stdlib/labs.c | 0 .../libcc.ansi/{pure => core}/stdlib/ldiv.c | 0 .../libcc.ansi/{pure => core}/stdlib/mblen.c | 0 .../{pure => core}/stdlib/mbstowcs.c | 0 .../libcc.ansi/{pure => core}/stdlib/mbtowc.c | 0 .../libcc.ansi/{pure => core}/stdlib/putenv.c | 0 .../libcc.ansi/{pure => core}/stdlib/qsort.c | 0 .../libcc.ansi/{pure => core}/stdlib/rand.c | 0 .../libcc.ansi/{pure => core}/stdlib/setenv.c | 0 .../libcc.ansi/{pure => core}/stdlib/strtol.c | 0 .../{pure => core}/stdlib/wcstombs.c | 0 .../libcc.ansi/{pure => core}/stdlib/wctomb.c | 0 .../libcc.ansi/{pure => core}/string/memchr.c | 0 .../libcc.ansi/{pure => core}/string/memcmp.c | 0 .../libcc.ansi/{pure => core}/string/memcpy.c | 0 .../{pure => core}/string/memmove.c | 0 .../libcc.ansi/{pure => core}/string/memset.c | 0 .../libcc.ansi/{pure => core}/string/strcat.c | 0 .../libcc.ansi/{pure => core}/string/strchr.c | 0 .../libcc.ansi/{pure => core}/string/strcmp.c | 0 .../{pure => core}/string/strcoll.c | 0 .../libcc.ansi/{pure => core}/string/strcpy.c | 0 .../{pure => core}/string/strcspn.c | 0 .../libcc.ansi/{pure => core}/string/strdup.c | 0 .../libcc.ansi/{pure => core}/string/strlen.c | 0 .../{pure => core}/string/strncat.c | 0 .../{pure => core}/string/strncmp.c | 0 .../{pure => core}/string/strncpy.c | 0 .../{pure => core}/string/strpbrk.c | 0 .../{pure => core}/string/strrchr.c | 0 .../libcc.ansi/{pure => core}/string/strspn.c | 0 .../libcc.ansi/{pure => core}/string/strstr.c | 0 .../libcc.ansi/{pure => core}/string/strtok.c | 0 .../{pure => core}/string/strxfrm.c | 0 lang/cem/libcc.ansi/pure/README.md | 3 --- 74 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 lang/cem/libcc.ansi/core/README.md rename lang/cem/libcc.ansi/{pure => core}/ctype/char.tab (100%) rename lang/cem/libcc.ansi/{pure => core}/ctype/genfiles (100%) rename lang/cem/libcc.ansi/{pure => core}/ctype/tolower.c (100%) rename lang/cem/libcc.ansi/{pure => core}/ctype/toupper.c (100%) rename lang/cem/libcc.ansi/{pure => core}/locale/localeconv.c (100%) rename lang/cem/libcc.ansi/{pure => core}/locale/setlocale.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/asin.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/atan.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/atan2.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/ceil.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/exp.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/fabs.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/floor.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/fmod.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/frexp.e (100%) rename lang/cem/libcc.ansi/{pure => core}/math/hugeval.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/hypot.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/isnan.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/ldexp.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/localmath.h (100%) rename lang/cem/libcc.ansi/{pure => core}/math/log.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/log10.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/modf.e (100%) rename lang/cem/libcc.ansi/{pure => core}/math/pow.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/sin.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/sinh.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/sqrt.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/tan.c (100%) rename lang/cem/libcc.ansi/{pure => core}/math/tanh.c (100%) rename lang/cem/libcc.ansi/{pure => core}/setjmp/setjmp.e (100%) rename lang/cem/libcc.ansi/{pure => core}/setjmp/sigmisc.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/abs.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/atoi.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/atol.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/bsearch.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/div.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/getenv.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/labs.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/ldiv.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/mblen.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/mbstowcs.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/mbtowc.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/putenv.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/qsort.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/rand.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/setenv.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/strtol.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/wcstombs.c (100%) rename lang/cem/libcc.ansi/{pure => core}/stdlib/wctomb.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/memchr.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/memcmp.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/memcpy.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/memmove.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/memset.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strcat.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strchr.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strcmp.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strcoll.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strcpy.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strcspn.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strdup.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strlen.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strncat.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strncmp.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strncpy.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strpbrk.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strrchr.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strspn.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strstr.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strtok.c (100%) rename lang/cem/libcc.ansi/{pure => core}/string/strxfrm.c (100%) delete mode 100644 lang/cem/libcc.ansi/pure/README.md diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index c49bdf0e2..b40ec30ec 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -2,12 +2,12 @@ include("plat/build.lua") tabgen { name = "ctype_tab", - srcs = { "./pure/ctype/char.tab" } + srcs = { "./core/ctype/char.tab" } } normalrule { name = "ctype_files", - ins = { "./pure/ctype/genfiles" }, + ins = { "./core/ctype/genfiles" }, outleaves = { "isalnum.c", "isalpha.c", @@ -33,14 +33,14 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", - "./pure/string/*.c", - "./pure/stdlib/*.c", - "./pure/locale/*.c", - "./pure/setjmp/*.c", - "./pure/setjmp/*.e", - "./pure/math/*.c", -- hypot.c - "./pure/math/*.e", - "./pure/ctype/*.c", + "./core/string/*.c", + "./core/stdlib/*.c", + "./core/locale/*.c", + "./core/setjmp/*.c", + "./core/setjmp/*.e", + "./core/math/*.c", -- hypot.c + "./core/math/*.e", + "./core/ctype/*.c", "./errno/*.c", "./malloc/*.c", "./misc/environ.c", -- don't build everything here as it's all obsolete @@ -56,7 +56,7 @@ for _, plat in ipairs(vars.plats) do "lang/cem/libcc.ansi/headers+pkg", "plat/"..plat.."/include+pkg", "./malloc/malloc.h", - "./pure/math/localmath.h", + "./core/math/localmath.h", "./stdio/loc_incl.h", "./stdlib/ext_fmt.h", "./time/loc_time.h", diff --git a/lang/cem/libcc.ansi/core/README.md b/lang/cem/libcc.ansi/core/README.md new file mode 100644 index 000000000..48243c8c6 --- /dev/null +++ b/lang/cem/libcc.ansi/core/README.md @@ -0,0 +1,19 @@ +This directory contains the libc core: functions here may depend on other +libc functions _only_ (so, no `unistd.h` stuff). Plats don't get to configure +this, so nothing here should add any overhead if the function isn't linked. + +Examples of what goes here: + + - `strcmp()` --- because it's pure code. + - `setjmp()` --- in EM, it's portable. + - `assert()` --- because it only calls other core functions (`fputs()` + and `abort()`). + +Examples of what doesn't go here: + + - `malloc()` --- because it calls the `unistd.h` function `sbrk()` (and so a + plat might want to swap it out). + - stdio --- because it calls the `unistd.h` functions `read()`, `write()` + etc. + - `signal()` --- because it can't be implemented portably and needs to go + in the plat. diff --git a/lang/cem/libcc.ansi/pure/ctype/char.tab b/lang/cem/libcc.ansi/core/ctype/char.tab similarity index 100% rename from lang/cem/libcc.ansi/pure/ctype/char.tab rename to lang/cem/libcc.ansi/core/ctype/char.tab diff --git a/lang/cem/libcc.ansi/pure/ctype/genfiles b/lang/cem/libcc.ansi/core/ctype/genfiles similarity index 100% rename from lang/cem/libcc.ansi/pure/ctype/genfiles rename to lang/cem/libcc.ansi/core/ctype/genfiles diff --git a/lang/cem/libcc.ansi/pure/ctype/tolower.c b/lang/cem/libcc.ansi/core/ctype/tolower.c similarity index 100% rename from lang/cem/libcc.ansi/pure/ctype/tolower.c rename to lang/cem/libcc.ansi/core/ctype/tolower.c diff --git a/lang/cem/libcc.ansi/pure/ctype/toupper.c b/lang/cem/libcc.ansi/core/ctype/toupper.c similarity index 100% rename from lang/cem/libcc.ansi/pure/ctype/toupper.c rename to lang/cem/libcc.ansi/core/ctype/toupper.c diff --git a/lang/cem/libcc.ansi/pure/locale/localeconv.c b/lang/cem/libcc.ansi/core/locale/localeconv.c similarity index 100% rename from lang/cem/libcc.ansi/pure/locale/localeconv.c rename to lang/cem/libcc.ansi/core/locale/localeconv.c diff --git a/lang/cem/libcc.ansi/pure/locale/setlocale.c b/lang/cem/libcc.ansi/core/locale/setlocale.c similarity index 100% rename from lang/cem/libcc.ansi/pure/locale/setlocale.c rename to lang/cem/libcc.ansi/core/locale/setlocale.c diff --git a/lang/cem/libcc.ansi/pure/math/asin.c b/lang/cem/libcc.ansi/core/math/asin.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/asin.c rename to lang/cem/libcc.ansi/core/math/asin.c diff --git a/lang/cem/libcc.ansi/pure/math/atan.c b/lang/cem/libcc.ansi/core/math/atan.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/atan.c rename to lang/cem/libcc.ansi/core/math/atan.c diff --git a/lang/cem/libcc.ansi/pure/math/atan2.c b/lang/cem/libcc.ansi/core/math/atan2.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/atan2.c rename to lang/cem/libcc.ansi/core/math/atan2.c diff --git a/lang/cem/libcc.ansi/pure/math/ceil.c b/lang/cem/libcc.ansi/core/math/ceil.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/ceil.c rename to lang/cem/libcc.ansi/core/math/ceil.c diff --git a/lang/cem/libcc.ansi/pure/math/exp.c b/lang/cem/libcc.ansi/core/math/exp.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/exp.c rename to lang/cem/libcc.ansi/core/math/exp.c diff --git a/lang/cem/libcc.ansi/pure/math/fabs.c b/lang/cem/libcc.ansi/core/math/fabs.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/fabs.c rename to lang/cem/libcc.ansi/core/math/fabs.c diff --git a/lang/cem/libcc.ansi/pure/math/floor.c b/lang/cem/libcc.ansi/core/math/floor.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/floor.c rename to lang/cem/libcc.ansi/core/math/floor.c diff --git a/lang/cem/libcc.ansi/pure/math/fmod.c b/lang/cem/libcc.ansi/core/math/fmod.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/fmod.c rename to lang/cem/libcc.ansi/core/math/fmod.c diff --git a/lang/cem/libcc.ansi/pure/math/frexp.e b/lang/cem/libcc.ansi/core/math/frexp.e similarity index 100% rename from lang/cem/libcc.ansi/pure/math/frexp.e rename to lang/cem/libcc.ansi/core/math/frexp.e diff --git a/lang/cem/libcc.ansi/pure/math/hugeval.c b/lang/cem/libcc.ansi/core/math/hugeval.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/hugeval.c rename to lang/cem/libcc.ansi/core/math/hugeval.c diff --git a/lang/cem/libcc.ansi/pure/math/hypot.c b/lang/cem/libcc.ansi/core/math/hypot.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/hypot.c rename to lang/cem/libcc.ansi/core/math/hypot.c diff --git a/lang/cem/libcc.ansi/pure/math/isnan.c b/lang/cem/libcc.ansi/core/math/isnan.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/isnan.c rename to lang/cem/libcc.ansi/core/math/isnan.c diff --git a/lang/cem/libcc.ansi/pure/math/ldexp.c b/lang/cem/libcc.ansi/core/math/ldexp.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/ldexp.c rename to lang/cem/libcc.ansi/core/math/ldexp.c diff --git a/lang/cem/libcc.ansi/pure/math/localmath.h b/lang/cem/libcc.ansi/core/math/localmath.h similarity index 100% rename from lang/cem/libcc.ansi/pure/math/localmath.h rename to lang/cem/libcc.ansi/core/math/localmath.h diff --git a/lang/cem/libcc.ansi/pure/math/log.c b/lang/cem/libcc.ansi/core/math/log.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/log.c rename to lang/cem/libcc.ansi/core/math/log.c diff --git a/lang/cem/libcc.ansi/pure/math/log10.c b/lang/cem/libcc.ansi/core/math/log10.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/log10.c rename to lang/cem/libcc.ansi/core/math/log10.c diff --git a/lang/cem/libcc.ansi/pure/math/modf.e b/lang/cem/libcc.ansi/core/math/modf.e similarity index 100% rename from lang/cem/libcc.ansi/pure/math/modf.e rename to lang/cem/libcc.ansi/core/math/modf.e diff --git a/lang/cem/libcc.ansi/pure/math/pow.c b/lang/cem/libcc.ansi/core/math/pow.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/pow.c rename to lang/cem/libcc.ansi/core/math/pow.c diff --git a/lang/cem/libcc.ansi/pure/math/sin.c b/lang/cem/libcc.ansi/core/math/sin.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/sin.c rename to lang/cem/libcc.ansi/core/math/sin.c diff --git a/lang/cem/libcc.ansi/pure/math/sinh.c b/lang/cem/libcc.ansi/core/math/sinh.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/sinh.c rename to lang/cem/libcc.ansi/core/math/sinh.c diff --git a/lang/cem/libcc.ansi/pure/math/sqrt.c b/lang/cem/libcc.ansi/core/math/sqrt.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/sqrt.c rename to lang/cem/libcc.ansi/core/math/sqrt.c diff --git a/lang/cem/libcc.ansi/pure/math/tan.c b/lang/cem/libcc.ansi/core/math/tan.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/tan.c rename to lang/cem/libcc.ansi/core/math/tan.c diff --git a/lang/cem/libcc.ansi/pure/math/tanh.c b/lang/cem/libcc.ansi/core/math/tanh.c similarity index 100% rename from lang/cem/libcc.ansi/pure/math/tanh.c rename to lang/cem/libcc.ansi/core/math/tanh.c diff --git a/lang/cem/libcc.ansi/pure/setjmp/setjmp.e b/lang/cem/libcc.ansi/core/setjmp/setjmp.e similarity index 100% rename from lang/cem/libcc.ansi/pure/setjmp/setjmp.e rename to lang/cem/libcc.ansi/core/setjmp/setjmp.e diff --git a/lang/cem/libcc.ansi/pure/setjmp/sigmisc.c b/lang/cem/libcc.ansi/core/setjmp/sigmisc.c similarity index 100% rename from lang/cem/libcc.ansi/pure/setjmp/sigmisc.c rename to lang/cem/libcc.ansi/core/setjmp/sigmisc.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/abs.c b/lang/cem/libcc.ansi/core/stdlib/abs.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/abs.c rename to lang/cem/libcc.ansi/core/stdlib/abs.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/atoi.c b/lang/cem/libcc.ansi/core/stdlib/atoi.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/atoi.c rename to lang/cem/libcc.ansi/core/stdlib/atoi.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/atol.c b/lang/cem/libcc.ansi/core/stdlib/atol.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/atol.c rename to lang/cem/libcc.ansi/core/stdlib/atol.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/bsearch.c b/lang/cem/libcc.ansi/core/stdlib/bsearch.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/bsearch.c rename to lang/cem/libcc.ansi/core/stdlib/bsearch.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/div.c b/lang/cem/libcc.ansi/core/stdlib/div.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/div.c rename to lang/cem/libcc.ansi/core/stdlib/div.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/getenv.c b/lang/cem/libcc.ansi/core/stdlib/getenv.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/getenv.c rename to lang/cem/libcc.ansi/core/stdlib/getenv.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/labs.c b/lang/cem/libcc.ansi/core/stdlib/labs.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/labs.c rename to lang/cem/libcc.ansi/core/stdlib/labs.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/ldiv.c b/lang/cem/libcc.ansi/core/stdlib/ldiv.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/ldiv.c rename to lang/cem/libcc.ansi/core/stdlib/ldiv.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/mblen.c b/lang/cem/libcc.ansi/core/stdlib/mblen.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/mblen.c rename to lang/cem/libcc.ansi/core/stdlib/mblen.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/mbstowcs.c b/lang/cem/libcc.ansi/core/stdlib/mbstowcs.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/mbstowcs.c rename to lang/cem/libcc.ansi/core/stdlib/mbstowcs.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/mbtowc.c b/lang/cem/libcc.ansi/core/stdlib/mbtowc.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/mbtowc.c rename to lang/cem/libcc.ansi/core/stdlib/mbtowc.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/putenv.c b/lang/cem/libcc.ansi/core/stdlib/putenv.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/putenv.c rename to lang/cem/libcc.ansi/core/stdlib/putenv.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/qsort.c b/lang/cem/libcc.ansi/core/stdlib/qsort.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/qsort.c rename to lang/cem/libcc.ansi/core/stdlib/qsort.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/rand.c b/lang/cem/libcc.ansi/core/stdlib/rand.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/rand.c rename to lang/cem/libcc.ansi/core/stdlib/rand.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/setenv.c b/lang/cem/libcc.ansi/core/stdlib/setenv.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/setenv.c rename to lang/cem/libcc.ansi/core/stdlib/setenv.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/strtol.c b/lang/cem/libcc.ansi/core/stdlib/strtol.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/strtol.c rename to lang/cem/libcc.ansi/core/stdlib/strtol.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/wcstombs.c b/lang/cem/libcc.ansi/core/stdlib/wcstombs.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/wcstombs.c rename to lang/cem/libcc.ansi/core/stdlib/wcstombs.c diff --git a/lang/cem/libcc.ansi/pure/stdlib/wctomb.c b/lang/cem/libcc.ansi/core/stdlib/wctomb.c similarity index 100% rename from lang/cem/libcc.ansi/pure/stdlib/wctomb.c rename to lang/cem/libcc.ansi/core/stdlib/wctomb.c diff --git a/lang/cem/libcc.ansi/pure/string/memchr.c b/lang/cem/libcc.ansi/core/string/memchr.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/memchr.c rename to lang/cem/libcc.ansi/core/string/memchr.c diff --git a/lang/cem/libcc.ansi/pure/string/memcmp.c b/lang/cem/libcc.ansi/core/string/memcmp.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/memcmp.c rename to lang/cem/libcc.ansi/core/string/memcmp.c diff --git a/lang/cem/libcc.ansi/pure/string/memcpy.c b/lang/cem/libcc.ansi/core/string/memcpy.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/memcpy.c rename to lang/cem/libcc.ansi/core/string/memcpy.c diff --git a/lang/cem/libcc.ansi/pure/string/memmove.c b/lang/cem/libcc.ansi/core/string/memmove.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/memmove.c rename to lang/cem/libcc.ansi/core/string/memmove.c diff --git a/lang/cem/libcc.ansi/pure/string/memset.c b/lang/cem/libcc.ansi/core/string/memset.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/memset.c rename to lang/cem/libcc.ansi/core/string/memset.c diff --git a/lang/cem/libcc.ansi/pure/string/strcat.c b/lang/cem/libcc.ansi/core/string/strcat.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strcat.c rename to lang/cem/libcc.ansi/core/string/strcat.c diff --git a/lang/cem/libcc.ansi/pure/string/strchr.c b/lang/cem/libcc.ansi/core/string/strchr.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strchr.c rename to lang/cem/libcc.ansi/core/string/strchr.c diff --git a/lang/cem/libcc.ansi/pure/string/strcmp.c b/lang/cem/libcc.ansi/core/string/strcmp.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strcmp.c rename to lang/cem/libcc.ansi/core/string/strcmp.c diff --git a/lang/cem/libcc.ansi/pure/string/strcoll.c b/lang/cem/libcc.ansi/core/string/strcoll.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strcoll.c rename to lang/cem/libcc.ansi/core/string/strcoll.c diff --git a/lang/cem/libcc.ansi/pure/string/strcpy.c b/lang/cem/libcc.ansi/core/string/strcpy.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strcpy.c rename to lang/cem/libcc.ansi/core/string/strcpy.c diff --git a/lang/cem/libcc.ansi/pure/string/strcspn.c b/lang/cem/libcc.ansi/core/string/strcspn.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strcspn.c rename to lang/cem/libcc.ansi/core/string/strcspn.c diff --git a/lang/cem/libcc.ansi/pure/string/strdup.c b/lang/cem/libcc.ansi/core/string/strdup.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strdup.c rename to lang/cem/libcc.ansi/core/string/strdup.c diff --git a/lang/cem/libcc.ansi/pure/string/strlen.c b/lang/cem/libcc.ansi/core/string/strlen.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strlen.c rename to lang/cem/libcc.ansi/core/string/strlen.c diff --git a/lang/cem/libcc.ansi/pure/string/strncat.c b/lang/cem/libcc.ansi/core/string/strncat.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strncat.c rename to lang/cem/libcc.ansi/core/string/strncat.c diff --git a/lang/cem/libcc.ansi/pure/string/strncmp.c b/lang/cem/libcc.ansi/core/string/strncmp.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strncmp.c rename to lang/cem/libcc.ansi/core/string/strncmp.c diff --git a/lang/cem/libcc.ansi/pure/string/strncpy.c b/lang/cem/libcc.ansi/core/string/strncpy.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strncpy.c rename to lang/cem/libcc.ansi/core/string/strncpy.c diff --git a/lang/cem/libcc.ansi/pure/string/strpbrk.c b/lang/cem/libcc.ansi/core/string/strpbrk.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strpbrk.c rename to lang/cem/libcc.ansi/core/string/strpbrk.c diff --git a/lang/cem/libcc.ansi/pure/string/strrchr.c b/lang/cem/libcc.ansi/core/string/strrchr.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strrchr.c rename to lang/cem/libcc.ansi/core/string/strrchr.c diff --git a/lang/cem/libcc.ansi/pure/string/strspn.c b/lang/cem/libcc.ansi/core/string/strspn.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strspn.c rename to lang/cem/libcc.ansi/core/string/strspn.c diff --git a/lang/cem/libcc.ansi/pure/string/strstr.c b/lang/cem/libcc.ansi/core/string/strstr.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strstr.c rename to lang/cem/libcc.ansi/core/string/strstr.c diff --git a/lang/cem/libcc.ansi/pure/string/strtok.c b/lang/cem/libcc.ansi/core/string/strtok.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strtok.c rename to lang/cem/libcc.ansi/core/string/strtok.c diff --git a/lang/cem/libcc.ansi/pure/string/strxfrm.c b/lang/cem/libcc.ansi/core/string/strxfrm.c similarity index 100% rename from lang/cem/libcc.ansi/pure/string/strxfrm.c rename to lang/cem/libcc.ansi/core/string/strxfrm.c diff --git a/lang/cem/libcc.ansi/pure/README.md b/lang/cem/libcc.ansi/pure/README.md deleted file mode 100644 index 484205837..000000000 --- a/lang/cem/libcc.ansi/pure/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This directory contains _only_ pure-code libc functions with no dependencies -on anything other than other pure functions (for example: strcmp, div). There -should be no reason why any platform won't want these in its libc. From c0276416d84a784e4675096ce3516a5e0870d2c8 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 22 Jun 2018 22:20:02 +0200 Subject: [PATCH 10/37] Move some more libc functions into core. --- build.lua | 2 +- lang/cem/libcc.ansi/build.lua | 2 +- lang/cem/libcc.ansi/{ => core}/misc/getopt.c | 0 lang/cem/libcc.ansi/{ => core}/misc/termcap.c | 0 lang/cem/libcc.ansi/{misc => core/stdio}/getw.c | 0 lang/cem/libcc.ansi/{misc => core/stdio}/putw.c | 0 lang/cem/libcc.ansi/{misc => core/stdlib}/environ.c | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename lang/cem/libcc.ansi/{ => core}/misc/getopt.c (100%) rename lang/cem/libcc.ansi/{ => core}/misc/termcap.c (100%) rename lang/cem/libcc.ansi/{misc => core/stdio}/getw.c (100%) rename lang/cem/libcc.ansi/{misc => core/stdio}/putw.c (100%) rename lang/cem/libcc.ansi/{misc => core/stdlib}/environ.c (100%) diff --git a/build.lua b/build.lua index a1fe98e80..73844b358 100644 --- a/build.lua +++ b/build.lua @@ -16,7 +16,7 @@ vars.plats = { "pc86", "rpi", "pdpv7", - "em22", +-- "em22", temporarily disabled due to ass bugs } vars.plats_with_tests = { "linux68k", diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index b40ec30ec..9ca2279cd 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -41,9 +41,9 @@ for _, plat in ipairs(vars.plats) do "./core/math/*.c", -- hypot.c "./core/math/*.e", "./core/ctype/*.c", + "./core/misc/*.c", "./errno/*.c", "./malloc/*.c", - "./misc/environ.c", -- don't build everything here as it's all obsolete "./signal/*.c", "./assert/*.c", "./stdio/*.c", diff --git a/lang/cem/libcc.ansi/misc/getopt.c b/lang/cem/libcc.ansi/core/misc/getopt.c similarity index 100% rename from lang/cem/libcc.ansi/misc/getopt.c rename to lang/cem/libcc.ansi/core/misc/getopt.c diff --git a/lang/cem/libcc.ansi/misc/termcap.c b/lang/cem/libcc.ansi/core/misc/termcap.c similarity index 100% rename from lang/cem/libcc.ansi/misc/termcap.c rename to lang/cem/libcc.ansi/core/misc/termcap.c diff --git a/lang/cem/libcc.ansi/misc/getw.c b/lang/cem/libcc.ansi/core/stdio/getw.c similarity index 100% rename from lang/cem/libcc.ansi/misc/getw.c rename to lang/cem/libcc.ansi/core/stdio/getw.c diff --git a/lang/cem/libcc.ansi/misc/putw.c b/lang/cem/libcc.ansi/core/stdio/putw.c similarity index 100% rename from lang/cem/libcc.ansi/misc/putw.c rename to lang/cem/libcc.ansi/core/stdio/putw.c diff --git a/lang/cem/libcc.ansi/misc/environ.c b/lang/cem/libcc.ansi/core/stdlib/environ.c similarity index 100% rename from lang/cem/libcc.ansi/misc/environ.c rename to lang/cem/libcc.ansi/core/stdlib/environ.c From a0c6fea32c9f6fca5710a31ebf128b9f8bbf3f54 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 22 Jun 2018 22:29:52 +0200 Subject: [PATCH 11/37] Replace fake-varargs, which doesn't work on 64-bit machines, with real varargs. --- util/ass/ass00.h | 3 +++ util/ass/ass80.c | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/util/ass/ass00.h b/util/ass/ass00.h index 42bd5b01c..3f393c236 100644 --- a/util/ass/ass00.h +++ b/util/ass/ass00.h @@ -256,3 +256,6 @@ struct proctab { cons_t pr_off; /* distance from pb */ cons_t pr_loc; /* number of bytes locals */ }; + +extern void error(const char* string1, ...); +extern void werror(const char* string1, ...); diff --git a/util/ass/ass80.c b/util/ass/ass80.c index 514c8dbc0..122796c24 100644 --- a/util/ass/ass80.c +++ b/util/ass/ass80.c @@ -4,9 +4,10 @@ * */ -#include "ass00.h" -#include "assex.h" -#include +#include "ass00.h" +#include "assex.h" +#include +#include #ifndef NORCSID static char rcs_id[] = "$Id$" ; @@ -29,7 +30,7 @@ zero(area,length) char *area; unsigned length ; { } /* VARARGS1 */ -static void pr_error(string1,a1,a2,a3,a4) char *string1 ; { +static void pr_error(const char* string1, va_list ap) { /* * diagnostic output */ @@ -44,20 +45,28 @@ static void pr_error(string1,a1,a2,a3,a4) char *string1 ; { fprintf(stderr,"proc %s, ",pstate.s_curpro->p_name); } fprintf(stderr,"line %d: ",line_num); - fprintf(stderr,string1,a1,a2,a3,a4); + vfprintf(stderr,string1,ap); fprintf(stderr,"\n"); } /* VARARGS1 */ -void error(string1,a1,a2,a3,a4) char *string1 ; { - pr_error(string1,a1,a2,a3,a4) ; +void error(const char* string1, ...) +{ + va_list ap; + va_start(ap, string1); + pr_error(string1, ap); + va_end(ap); nerrors++ ; } /* VARARGS1 */ -void werror(string1,a1,a2,a3,a4) char *string1 ; { +void werror(const char* string1, ...) { + va_list ap; if ( wflag ) return ; - pr_error(string1,a1,a2,a3,a4) ; + + va_start(ap, string1); + pr_error(string1, ap); + va_end(ap); } fatal(s) char *s; { From b21c099a57db9650dcd1d757e586dd5ac10875da Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 22 Jun 2018 23:17:14 +0200 Subject: [PATCH 12/37] Get the em libc working again: remove the modula-2 termcap library, as it's a straight copy of the libc one and having two symbols defined at once gets ass upset. --- build.lua | 2 +- lang/m2/libm2/XXTermcap.c | 573 -------------------------------------- 2 files changed, 1 insertion(+), 574 deletions(-) delete mode 100644 lang/m2/libm2/XXTermcap.c diff --git a/build.lua b/build.lua index 73844b358..a1fe98e80 100644 --- a/build.lua +++ b/build.lua @@ -16,7 +16,7 @@ vars.plats = { "pc86", "rpi", "pdpv7", --- "em22", temporarily disabled due to ass bugs + "em22", } vars.plats_with_tests = { "linux68k", diff --git a/lang/m2/libm2/XXTermcap.c b/lang/m2/libm2/XXTermcap.c deleted file mode 100644 index 81608dcab..000000000 --- a/lang/m2/libm2/XXTermcap.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * termcap.c 1.1 20/7/87 agc Joypace Ltd - * - * Copyright Joypace Ltd, London, UK, 1987. All rights reserved. - * This file may be freely distributed provided that this notice - * remains attached. - * - * A public domain implementation of the termcap(3) routines. - * - * Made fully functional by Ceriel J.H. Jacobs. - * - * BUGS: - * - does not check termcap entry sizes - * - not fully tested - */ - -#define CAPABLEN 2 - -#define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') -#define ISDIGIT(x) ((x) >= '0' && (x) <= '9') - -short ospeed = 0; /* output speed */ -char PC = 0; /* padding character */ -char *BC = 0; /* back cursor movement */ -char *UP = 0; /* up cursor movement */ - -static char *capab = 0; /* the capability itself */ -static int check_for_tc(); -static int match_name(); - -#define NULL 0 - -/* Some things from C-library, needed here because the C-library is not - loaded with Modula-2 programs -*/ - -static char * -strcat(s1, s2) -register char *s1, *s2; -{ - /* Append s2 to the end of s1. */ - - char *original = s1; - - /* Find the end of s1. */ - while (*s1 != 0) s1++; - - /* Now copy s2 to the end of s1. */ - while (*s1++ = *s2++) /* nothing */ ; - return(original); -} - -static char * -strcpy(s1, s2) -register char *s1, *s2; -{ -/* Copy s2 to s1. */ - char *original = s1; - - while (*s1++ = *s2++) /* nothing */; - return(original); -} - -static int -strlen(s) -char *s; -{ -/* Return length of s. */ - - char *original = s; - - while (*s != 0) s++; - return(s - original); -} - -static int -strcmp(s1, s2) -register char *s1, *s2; -{ -/* Compare 2 strings. */ - - for(;;) { - if (*s1 != *s2) { - if (!*s1) return -1; - if (!*s2) return 1; - return(*s1 - *s2); - } - if (*s1++ == 0) return(0); - s2++; - } -} - -static int -strncmp(s1, s2, n) - register char *s1, *s2; - int n; -{ -/* Compare two strings, but at most n characters. */ - - while (n-- > 0) { - if (*s1 != *s2) { - if (!*s1) return -1; - if (!*s2) return 1; - return(*s1 - *s2); - } - if (*s1++ == 0) break; - s2++; - } - return 0; -} - -static char * -getenv(name) -register char *name; -{ - extern char **environ; - register char **v = environ, *p, *q; - - if (v == 0 || name == 0) return 0; - while ((p = *v++) != 0) { - q = name; - while (*q && *q++ == *p++) /* nothing */ ; - if (*q || *p != '=') continue; - return(p+1); - } - return(0); -} - -static char * -fgets(buf, count, fd) - char *buf; -{ - static char bf[1024]; - static int cnt = 0; - static char *pbf = &bf[0]; - register char *c = buf; - - - while (--count) { - if (pbf >= &bf[cnt]) { - if ((cnt = read(fd, bf, 1024)) <= 0) { - if (c == buf) return (char *) NULL; - *c = 0; - return buf; - } - pbf = &bf[0]; - } - *c = *pbf++; - if (*c++ == '\n') { - *c = 0; - return buf; - } - } - *c = 0; - return buf; -} - -/* - * tgetent - get the termcap entry for terminal name, and put it - * in bp (which must be an array of 1024 chars). Returns 1 if - * termcap entry found, 0 if not found, and -1 if file not found. - */ -int -tgetent(bp, name) -char *bp; -char *name; -{ - int fp; - char *file; - char *cp; - short len = strlen(name); - char buf[1024]; - - capab = bp; - if ((file = getenv("TERMCAP")) != (char *) NULL) { - if (*file != '/' && - (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) { - (void) strcpy(bp, file); - return(1); - } - else file = "/etc/termcap"; - } else - file = "/etc/termcap"; - if ((fp = open(file, 0)) < 0) { - capab = 0; - return(-1); - } - while (fgets(buf, 1024, fp) != NULL) { - if (buf[0] == '#') continue; - while (*(cp = &buf[strlen(buf) - 2]) == '\\') - if (fgets(cp, 1024, fp) == NULL) - return (0); - if (match_name(buf, name)) { - strcpy(bp, buf); - close(fp); - if(check_for_tc() == 0) { - capab = 0; - return 0; - } - return 1; - } - } - capab = 0; - close(fp); - return(0); -} - -/* - * Compare the terminal name with each termcap entry name; Return 1 if a - * match is found. - */ -static int -match_name(buf, name) - char *buf; - char *name; -{ - register char *tp = buf; - register char *np; - - for (;;) { - for (np = name; *np && *tp == *np; np++, tp++) { } - if (*np == 0 && (*tp == '|' || *tp == ':' || *tp == 0)) - return(1); - while (*tp != 0 && *tp != '|' && *tp != ':') tp++; - if (*tp++ != '|') return (0); - } -} - -/* - * Handle tc= definitions recursively. - */ -static int -check_for_tc() -{ - static int count = 0; - char *savcapab = capab; - char buf[1024]; - char terminalname[128]; - register char *p = capab + strlen(capab) - 2, *q; - - while (*p != ':') - if (--p < capab) - return(0); /* no : in termcap entry */ - if (p[1] != 't' || p[2] != 'c') - return(1); - if (count > 16) { - return(0); /* recursion in tc= definitions */ - } - count++; - strcpy(terminalname, &p[4]); - q = terminalname; - while (*q && *q != ':') q++; - *q = 0; - if (tgetent(buf, terminalname) != 1) { - --count; - return(0); - } - --count; - for (q = buf; *q && *q != ':'; q++) { } - strcpy(p, q); - capab = savcapab; - return(1); -} - -/* - * tgetnum - get the numeric terminal capability corresponding - * to id. Returns the value, -1 if invalid. - */ -int -tgetnum(id) -char *id; -{ - char *cp; - int ret; - - if ((cp = capab) == NULL || id == NULL || *cp == 0) - return(-1); - while (*++cp && *cp != ':') - ; - while (*cp) { - cp++; - while (ISSPACE(*cp)) - cp++; - if (strncmp(cp, id, CAPABLEN) == 0) { - while (*cp && *cp != ':' && *cp != '#') - cp++; - if (*cp != '#') - return(-1); - for (ret = 0, cp++ ; *cp && ISDIGIT(*cp) ; cp++) - ret = ret * 10 + *cp - '0'; - return(ret); - } - while (*cp && *cp != ':') - cp++; - } - return(-1); -} - -/* - * tgetflag - get the boolean flag corresponding to id. Returns -1 - * if invalid, 0 if the flag is not in termcap entry, or 1 if it is - * present. - */ -int -tgetflag(id) -char *id; -{ - char *cp; - - if ((cp = capab) == NULL || id == NULL || *cp == 0) - return(-1); - while (*++cp && *cp != ':') - ; - while (*cp) { - cp++; - while (ISSPACE(*cp)) - cp++; - if (strncmp(cp, id, CAPABLEN) == 0) - return(1); - while (*cp && *cp != ':') - cp++; - } - return(0); -} - -/* - * tgetstr - get the string capability corresponding to id and place - * it in area (advancing area at same time). Expand escape sequences - * etc. Returns the string, or NULL if it can't do it. - */ -char * -tgetstr(id, area) -char *id; -char **area; -{ - char *cp; - char *ret; - int i; - - if ((cp = capab) == NULL || id == NULL || *cp == 0) - return(NULL); - while (*++cp != ':') - ; - while (*cp) { - cp++; - while (ISSPACE(*cp)) - cp++; - if (strncmp(cp, id, CAPABLEN) == 0) { - while (*cp && *cp != ':' && *cp != '=') - cp++; - if (*cp != '=') - return(NULL); - for (ret = *area, cp++; *cp && *cp != ':' ; (*area)++, cp++) - switch(*cp) { - case '^' : - **area = *++cp - 'A' + 1; - break; - case '\\' : - switch(*++cp) { - case 'E' : - **area = '\033'; - break; - case 'n' : - **area = '\n'; - break; - case 'r' : - **area = '\r'; - break; - case 't' : - **area = '\t'; - break; - case 'b' : - **area = '\b'; - break; - case 'f' : - **area = '\f'; - break; - case '0' : - case '1' : - case '2' : - case '3' : - for (i=0 ; *cp && ISDIGIT(*cp) ; cp++) - i = i * 8 + *cp - '0'; - **area = i; - cp--; - break; - case '^' : - case '\\' : - **area = *cp; - break; - } - break; - default : - **area = *cp; - } - *(*area)++ = '\0'; - return(ret); - } - while (*cp && *cp != ':') - cp++; - } - return(NULL); -} - -/* - * tgoto - given the cursor motion string cm, make up the string - * for the cursor to go to (destcol, destline), and return the string. - * Returns "OOPS" if something's gone wrong, or the string otherwise. - */ -char * -tgoto(cm, destcol, destline) -char *cm; -int destcol; -int destline; -{ - register char *rp; - static char ret[32]; - char added[16]; - int *dp = &destline; - int numval; - int swapped = 0; - - added[0] = 0; - for (rp = ret ; *cm ; cm++) { - if (*cm == '%') { - switch(*++cm) { - case '>' : - if (dp == NULL) - return("OOPS"); - cm++; - if (*dp > *cm++) { - *dp += *cm; - } - break; - case '+' : - case '.' : - if (dp == NULL) - return("OOPS"); - if (*cm == '+') *dp = *dp + *++cm; - for (;;) { - switch(*dp) { - case 0: - case 04: - case '\t': - case '\n': - /* filter these out */ - if (dp == &destcol || swapped || UP) { - strcat(added, dp == &destcol || swapped ? - (BC ? BC : "\b") : - UP); - (*dp)++; - continue; - } - } - break; - } - *rp++ = *dp; - dp = (dp == &destline) ? &destcol : NULL; - break; - - case 'r' : { - int tmp = destline; - - destline = destcol; - destcol = tmp; - swapped = 1 - swapped; - break; - } - case 'n' : - destcol ^= 0140; - destline ^= 0140; - break; - - case '%' : - *rp++ = '%'; - break; - - case 'i' : - destcol++; - destline++; - break; - - case 'B' : - if (dp == NULL) - return("OOPS"); - *dp = 16 * (*dp / 10) + *dp % 10; - break; - - case 'D' : - if (dp == NULL) - return("OOPS"); - *dp = *dp - 2 * (*dp % 16); - break; - - case 'd' : - case '2' : - case '3' : - if (dp == NULL) - return("OOPS"); - numval = *dp; - dp = (dp == &destline) ? &destcol : NULL; - if (numval >= 100) { - *rp++ = '0' + numval / 100; - } - else if (*cm == '3') { - *rp++ = ' '; - } - if (numval >= 10) { - *rp++ = '0' + ((numval%100)/10); - } - else if (*cm == '3' || *cm == '2') { - *rp++ = ' '; - } - *rp++ = '0' + (numval%10); - break; - default : - return("OOPS"); - } - } - else *rp++ = *cm; - } - *rp = '\0'; - strcpy(rp, added); - return(ret); -} - -static int tens_of_ms_p_char[] = { /* index as returned by gtty */ - /* assume 10 bits per char */ - 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 2 -}; -/* - * tputs - put the string cp out onto the terminal, using the function - * outc. Also handle padding. - */ -int -tputs(cp, affcnt, outc) -register char *cp; -int affcnt; -int (*outc)(); -{ - int delay = 0; - if (cp == NULL) - return(1); - while (ISDIGIT(*cp)) { - delay = delay * 10 + (*cp++ - '0'); - } - delay *= 10; - if (*cp == '.') { - cp++; - if (ISDIGIT(*cp)) { - delay += *cp++ - '0'; - } - while (ISDIGIT(*cp)) cp++; - } - if (*cp == '*') { - delay *= affcnt; - cp++; - } - while (*cp) - (*outc)(*cp++); - if (delay != 0 && - ospeed > 0 && - ospeed < (sizeof tens_of_ms_p_char / sizeof tens_of_ms_p_char[0])) { - delay = (delay + tens_of_ms_p_char[ospeed] - 1) / - tens_of_ms_p_char[ospeed]; - while (delay--) (*outc)(PC); - } - return(1); -} - -/* - * That's all, folks... - */ From 9bf1d548fc51fdc097876db9b254956ddee3eac7 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 22 Jun 2018 23:43:15 +0200 Subject: [PATCH 13/37] Rearrange the libc config files, ready for adding new options. --- .../include => lang/cem/libcc.ansi/headers}/ack/config.h | 2 +- lang/cem/libcc.ansi/headers/build.lua | 1 + plat/cpm/include/ack/{config.h => plat.h} | 4 ++-- plat/cpm/include/build.lua | 2 +- plat/em22/include/ack/plat.h | 6 ++++++ plat/em22/include/build.lua | 2 +- plat/linux386/include/ack/{config.h => plat.h} | 4 ++-- plat/linux386/include/build.lua | 2 +- plat/linux68k/include/ack/{config.h => plat.h} | 4 ++-- plat/linux68k/include/build.lua | 2 +- plat/linuxppc/include/ack/{config.h => plat.h} | 4 ++-- plat/linuxppc/include/build.lua | 2 +- plat/osx/include/ack/{config.h => plat.h} | 4 ++-- plat/osx/include/build.lua | 2 +- plat/pc86/include/ack/{config.h => plat.h} | 4 ++-- plat/pc86/include/build.lua | 2 +- plat/pdpv7/include/ack/{config.h => plat.h} | 4 ++-- plat/pdpv7/include/build.lua | 2 +- plat/qemuppc/include/ack/{config.h => plat.h} | 4 ++-- plat/qemuppc/include/build.lua | 2 +- plat/rpi/include/ack/{config.h => plat.h} | 4 ++-- plat/rpi/include/build.lua | 2 +- 22 files changed, 36 insertions(+), 29 deletions(-) rename {plat/em22/include => lang/cem/libcc.ansi/headers}/ack/config.h (60%) rename plat/cpm/include/ack/{config.h => plat.h} (88%) create mode 100644 plat/em22/include/ack/plat.h rename plat/linux386/include/ack/{config.h => plat.h} (82%) rename plat/linux68k/include/ack/{config.h => plat.h} (86%) rename plat/linuxppc/include/ack/{config.h => plat.h} (89%) rename plat/osx/include/ack/{config.h => plat.h} (82%) rename plat/pc86/include/ack/{config.h => plat.h} (81%) rename plat/pdpv7/include/ack/{config.h => plat.h} (89%) rename plat/qemuppc/include/ack/{config.h => plat.h} (85%) rename plat/rpi/include/ack/{config.h => plat.h} (89%) diff --git a/plat/em22/include/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h similarity index 60% rename from plat/em22/include/ack/config.h rename to lang/cem/libcc.ansi/headers/ack/config.h index 2618ad74c..de714af4e 100644 --- a/plat/em22/include/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -1,6 +1,6 @@ #ifndef _ACK_CONFIG_H #define _ACK_CONFIG_H -#define ACKCONF_TIME_IS_A_SYSCALL +#include #endif diff --git a/lang/cem/libcc.ansi/headers/build.lua b/lang/cem/libcc.ansi/headers/build.lua index 80feaf073..57e4c12ee 100644 --- a/lang/cem/libcc.ansi/headers/build.lua +++ b/lang/cem/libcc.ansi/headers/build.lua @@ -13,6 +13,7 @@ end addheader("", filenamesof("./*.h")) addheader("sys/", filenamesof("./sys/*.h")) +addheader("ack/", filenamesof("./ack/*.h")) acklibrary { name = "headers", diff --git a/plat/cpm/include/ack/config.h b/plat/cpm/include/ack/plat.h similarity index 88% rename from plat/cpm/include/ack/config.h rename to plat/cpm/include/ack/plat.h index ebd5c1198..5f785b0e1 100644 --- a/plat/cpm/include/ack/config.h +++ b/plat/cpm/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision$ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/cpm/include/build.lua b/plat/cpm/include/build.lua index b6f713684..0fdc2903d 100644 --- a/plat/cpm/include/build.lua +++ b/plat/cpm/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/cpm/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("cpm.h") addheader("unistd.h") diff --git a/plat/em22/include/ack/plat.h b/plat/em22/include/ack/plat.h new file mode 100644 index 000000000..87be3d0ec --- /dev/null +++ b/plat/em22/include/ack/plat.h @@ -0,0 +1,6 @@ +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_TIME_IS_A_SYSCALL + +#endif diff --git a/plat/em22/include/build.lua b/plat/em22/include/build.lua index 298f9b033..ab7564b5c 100644 --- a/plat/em22/include/build.lua +++ b/plat/em22/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/em22/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/types.h") addheader("sys/timeb.h") addheader("unistd.h") diff --git a/plat/linux386/include/ack/config.h b/plat/linux386/include/ack/plat.h similarity index 82% rename from plat/linux386/include/ack/config.h rename to plat/linux386/include/ack/plat.h index af4a90ed2..f65adb8d7 100644 --- a/plat/linux386/include/ack/config.h +++ b/plat/linux386/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision$ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/linux386/include/build.lua b/plat/linux386/include/build.lua index ce1f2adc6..129fd9035 100644 --- a/plat/linux386/include/build.lua +++ b/plat/linux386/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/linux386/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/ioctl.h") addheader("unistd.h") diff --git a/plat/linux68k/include/ack/config.h b/plat/linux68k/include/ack/plat.h similarity index 86% rename from plat/linux68k/include/ack/config.h rename to plat/linux68k/include/ack/plat.h index 77ac5528d..9145197c4 100644 --- a/plat/linux68k/include/ack/config.h +++ b/plat/linux68k/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision: 1.1 $ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/linux68k/include/build.lua b/plat/linux68k/include/build.lua index 291fa0c36..131a52ba9 100644 --- a/plat/linux68k/include/build.lua +++ b/plat/linux68k/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/linux68k/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/ioctl.h") addheader("unistd.h") diff --git a/plat/linuxppc/include/ack/config.h b/plat/linuxppc/include/ack/plat.h similarity index 89% rename from plat/linuxppc/include/ack/config.h rename to plat/linuxppc/include/ack/plat.h index 7c3c147b3..e25914574 100644 --- a/plat/linuxppc/include/ack/config.h +++ b/plat/linuxppc/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision: 1.1 $ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/linuxppc/include/build.lua b/plat/linuxppc/include/build.lua index 27325b43d..5fef69c6e 100644 --- a/plat/linuxppc/include/build.lua +++ b/plat/linuxppc/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/linuxppc/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/ioctl.h") addheader("unistd.h") diff --git a/plat/osx/include/ack/config.h b/plat/osx/include/ack/plat.h similarity index 82% rename from plat/osx/include/ack/config.h rename to plat/osx/include/ack/plat.h index 9f58a3941..ba64a6d56 100644 --- a/plat/osx/include/ack/config.h +++ b/plat/osx/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision$ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/osx/include/build.lua b/plat/osx/include/build.lua index ff7c87a4d..859a3730a 100644 --- a/plat/osx/include/build.lua +++ b/plat/osx/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/osx/include/"..h] = "plat/osx/include/"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/dirent.h") addheader("sys/mman.h") addheader("sys/stat.h") diff --git a/plat/pc86/include/ack/config.h b/plat/pc86/include/ack/plat.h similarity index 81% rename from plat/pc86/include/ack/config.h rename to plat/pc86/include/ack/plat.h index dac9af4c1..cbd879396 100644 --- a/plat/pc86/include/ack/config.h +++ b/plat/pc86/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision$ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/pc86/include/build.lua b/plat/pc86/include/build.lua index 6ae120358..cb504b837 100644 --- a/plat/pc86/include/build.lua +++ b/plat/pc86/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/pc86/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("unistd.h") acklibrary { diff --git a/plat/pdpv7/include/ack/config.h b/plat/pdpv7/include/ack/plat.h similarity index 89% rename from plat/pdpv7/include/ack/config.h rename to plat/pdpv7/include/ack/plat.h index 73dbbc34d..42a302513 100644 --- a/plat/pdpv7/include/ack/config.h +++ b/plat/pdpv7/include/ack/plat.h @@ -5,8 +5,8 @@ * See the file 'Copying' in the root of the distribution for the full text. */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/pdpv7/include/build.lua b/plat/pdpv7/include/build.lua index c0334a341..70d9666c6 100644 --- a/plat/pdpv7/include/build.lua +++ b/plat/pdpv7/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/pdpv7/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/select.h") addheader("termios.h") addheader("unistd.h") diff --git a/plat/qemuppc/include/ack/config.h b/plat/qemuppc/include/ack/plat.h similarity index 85% rename from plat/qemuppc/include/ack/config.h rename to plat/qemuppc/include/ack/plat.h index f58ee3a43..4ad324142 100644 --- a/plat/qemuppc/include/ack/config.h +++ b/plat/qemuppc/include/ack/plat.h @@ -3,8 +3,8 @@ * $Revision: 1.1 $ */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/qemuppc/include/build.lua b/plat/qemuppc/include/build.lua index dc1b0bb43..896043e63 100644 --- a/plat/qemuppc/include/build.lua +++ b/plat/qemuppc/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/qemuppc/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("sys/ioctl.h") addheader("unistd.h") diff --git a/plat/rpi/include/ack/config.h b/plat/rpi/include/ack/plat.h similarity index 89% rename from plat/rpi/include/ack/config.h rename to plat/rpi/include/ack/plat.h index 995673236..9f9d08b27 100644 --- a/plat/rpi/include/ack/config.h +++ b/plat/rpi/include/ack/plat.h @@ -5,8 +5,8 @@ * See the file 'Copying' in the root of the distribution for the full text. */ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ diff --git a/plat/rpi/include/build.lua b/plat/rpi/include/build.lua index 4e6b8521b..105f05988 100644 --- a/plat/rpi/include/build.lua +++ b/plat/rpi/include/build.lua @@ -8,7 +8,7 @@ local function addheader(h) packagemap["$(PLATIND)/rpi/include/"..h] = "./"..h end -addheader("ack/config.h") +addheader("ack/plat.h") addheader("pi.h") addheader("sys/select.h") addheader("termios.h") From 94ffa3ba88efbc9e8ecddc83a5b095be4baa7814 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 00:04:14 +0200 Subject: [PATCH 14/37] libc floating point and stdio floating point can now be turned on and off using ACKCONF variables. --- lang/cem/libcc.ansi/core/math/asin.c | 5 +++++ lang/cem/libcc.ansi/core/math/atan.c | 6 ++++++ lang/cem/libcc.ansi/core/math/atan2.c | 6 ++++++ lang/cem/libcc.ansi/core/math/ceil.c | 6 ++++++ lang/cem/libcc.ansi/core/math/exp.c | 6 ++++++ lang/cem/libcc.ansi/core/math/fabs.c | 6 ++++++ lang/cem/libcc.ansi/core/math/floor.c | 6 ++++++ lang/cem/libcc.ansi/core/math/fmod.c | 6 ++++++ lang/cem/libcc.ansi/core/math/frexp.e | 6 ++++++ lang/cem/libcc.ansi/core/math/hugeval.c | 6 ++++++ lang/cem/libcc.ansi/core/math/hypot.c | 6 ++++++ lang/cem/libcc.ansi/core/math/isnan.c | 8 ++++++++ lang/cem/libcc.ansi/core/math/ldexp.c | 6 ++++++ lang/cem/libcc.ansi/core/math/log.c | 6 ++++++ lang/cem/libcc.ansi/core/math/log10.c | 6 ++++++ lang/cem/libcc.ansi/core/math/modf.e | 4 ++++ lang/cem/libcc.ansi/core/math/pow.c | 6 ++++++ lang/cem/libcc.ansi/core/math/sin.c | 6 ++++++ lang/cem/libcc.ansi/core/math/sinh.c | 6 ++++++ lang/cem/libcc.ansi/core/math/sqrt.c | 6 ++++++ lang/cem/libcc.ansi/core/math/tan.c | 6 ++++++ lang/cem/libcc.ansi/core/math/tanh.c | 6 ++++++ lang/cem/libcc.ansi/headers/ack/config.h | 8 ++++++++ lang/cem/libcc.ansi/stdio/doprnt.c | 4 ++-- lang/cem/libcc.ansi/stdio/doscan.c | 8 ++++---- lang/cem/libcc.ansi/stdio/ecvt.c | 4 ++-- lang/cem/libcc.ansi/stdio/fltpr.c | 4 ++-- lang/cem/libcc.ansi/stdio/loc_incl.h | 4 ++-- lang/cem/libcc.ansi/stdlib/strtod.c | 3 ++- plat/cpm/include/ack/plat.h | 5 ----- plat/linuxppc/include/ack/plat.h | 4 ---- 31 files changed, 153 insertions(+), 22 deletions(-) diff --git a/lang/cem/libcc.ansi/core/math/asin.c b/lang/cem/libcc.ansi/core/math/asin.c index 1e3180086..ffa286e40 100644 --- a/lang/cem/libcc.ansi/core/math/asin.c +++ b/lang/cem/libcc.ansi/core/math/asin.c @@ -8,8 +8,11 @@ #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + static double asin_acos(double x, int cosfl) { @@ -90,3 +93,5 @@ acos(double x) { return asin_acos(x, 1); } + +#endif diff --git a/lang/cem/libcc.ansi/core/math/atan.c b/lang/cem/libcc.ansi/core/math/atan.c index eb04d095f..c1d52f6a3 100644 --- a/lang/cem/libcc.ansi/core/math/atan.c +++ b/lang/cem/libcc.ansi/core/math/atan.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double atan(double x) { @@ -75,3 +78,6 @@ atan(double x) x += a[n]; return neg ? -x : x; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/atan2.c b/lang/cem/libcc.ansi/core/math/atan2.c index 6f8362468..ec1b45c7e 100644 --- a/lang/cem/libcc.ansi/core/math/atan2.c +++ b/lang/cem/libcc.ansi/core/math/atan2.c @@ -8,8 +8,11 @@ #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double atan2(double y, double x) { @@ -46,3 +49,6 @@ atan2(double y, double x) } return val + M_PI; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/ceil.c b/lang/cem/libcc.ansi/core/math/ceil.c index 2d06949a2..e5671739b 100644 --- a/lang/cem/libcc.ansi/core/math/ceil.c +++ b/lang/cem/libcc.ansi/core/math/ceil.c @@ -7,6 +7,9 @@ /* $Id$ */ #include +#include + +#if ACKCONF_WANT_FLOAT double ceil(double x) @@ -18,3 +21,6 @@ ceil(double x) fractional part */ } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/exp.c b/lang/cem/libcc.ansi/core/math/exp.c index 1583d913c..5bbdc1978 100644 --- a/lang/cem/libcc.ansi/core/math/exp.c +++ b/lang/cem/libcc.ansi/core/math/exp.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double exp(double x) { @@ -74,3 +77,6 @@ exp(double x) n += 1; return (ldexp(0.5 + x / (POLYNOM3(xn, q) - x), n)); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/fabs.c b/lang/cem/libcc.ansi/core/math/fabs.c index 526d5d63e..5c467e415 100644 --- a/lang/cem/libcc.ansi/core/math/fabs.c +++ b/lang/cem/libcc.ansi/core/math/fabs.c @@ -5,9 +5,15 @@ * Author: Ceriel J.H. Jacobs */ /* $Id$ */ +#include + +#if ACKCONF_WANT_FLOAT double fabs(double x) { return x < 0 ? -x : x; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/floor.c b/lang/cem/libcc.ansi/core/math/floor.c index 4f1cd2dc0..bce630bd2 100644 --- a/lang/cem/libcc.ansi/core/math/floor.c +++ b/lang/cem/libcc.ansi/core/math/floor.c @@ -7,6 +7,9 @@ /* $Id$ */ #include +#include + +#if ACKCONF_WANT_FLOAT double floor(double x) @@ -18,3 +21,6 @@ floor(double x) fractional part */ } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/fmod.c b/lang/cem/libcc.ansi/core/math/fmod.c index 4a784a98f..3329a41b1 100644 --- a/lang/cem/libcc.ansi/core/math/fmod.c +++ b/lang/cem/libcc.ansi/core/math/fmod.c @@ -5,6 +5,9 @@ #include #include +#include + +#if ACKCONF_WANT_FLOAT double(fmod)(double x, double y) { /* compute fmod(x, y) */ @@ -37,3 +40,6 @@ double(fmod)(double x, double y) } return (neg ? -x : x); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/frexp.e b/lang/cem/libcc.ansi/core/math/frexp.e index d3ccca819..0e64b4b1b 100644 --- a/lang/cem/libcc.ansi/core/math/frexp.e +++ b/lang/cem/libcc.ansi/core/math/frexp.e @@ -5,7 +5,11 @@ */ /* $Id$ */ +#include + mes 2,_EM_WSIZE,_EM_PSIZE + +#if ACKCONF_WANT_FLOAT exp $frexp pro $frexp,0 lal 0 @@ -16,3 +20,5 @@ sti _EM_WSIZE ret _EM_DSIZE end +#endif + diff --git a/lang/cem/libcc.ansi/core/math/hugeval.c b/lang/cem/libcc.ansi/core/math/hugeval.c index 2d51c2994..6d526f2c8 100644 --- a/lang/cem/libcc.ansi/core/math/hugeval.c +++ b/lang/cem/libcc.ansi/core/math/hugeval.c @@ -7,5 +7,11 @@ /* $Id$ */ #include +#include + +#if ACKCONF_WANT_FLOAT double __huge_val = 1.0e+1000; /* This will generate a warning */ + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/hypot.c b/lang/cem/libcc.ansi/core/math/hypot.c index ad181d157..f3e70819f 100644 --- a/lang/cem/libcc.ansi/core/math/hypot.c +++ b/lang/cem/libcc.ansi/core/math/hypot.c @@ -6,6 +6,9 @@ */ #include +#include + +#if ACKCONF_WANT_FLOAT /* $Id$ */ @@ -41,3 +44,6 @@ cabs(struct complex p_compl) { return hypot(p_compl.r, p_compl.i); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/isnan.c b/lang/cem/libcc.ansi/core/math/isnan.c index 7f1b31aed..9203875ce 100644 --- a/lang/cem/libcc.ansi/core/math/isnan.c +++ b/lang/cem/libcc.ansi/core/math/isnan.c @@ -1,3 +1,8 @@ +#include +#include + +#if ACKCONF_WANT_FLOAT + __IsNan(double d) { #if defined(__vax) || defined(__pdp) @@ -9,3 +14,6 @@ __IsNan(double d) #endif return 0; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/ldexp.c b/lang/cem/libcc.ansi/core/math/ldexp.c index 7f1b0ee19..683c70e6c 100644 --- a/lang/cem/libcc.ansi/core/math/ldexp.c +++ b/lang/cem/libcc.ansi/core/math/ldexp.c @@ -7,6 +7,9 @@ #include #include #include +#include + +#if ACKCONF_WANT_FLOAT double ldexp(double fl, int exp) @@ -63,3 +66,6 @@ ldexp(double fl, int exp) } return sign * fl; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/log.c b/lang/cem/libcc.ansi/core/math/log.c index 3be9c87c7..3c698c10a 100644 --- a/lang/cem/libcc.ansi/core/math/log.c +++ b/lang/cem/libcc.ansi/core/math/log.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double log(double x) { @@ -73,3 +76,6 @@ log(double x) x += z * (-2.121944400546905827679e-4); return x + z * 0.693359375; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/log10.c b/lang/cem/libcc.ansi/core/math/log10.c index 9eb270ec2..1c170026c 100644 --- a/lang/cem/libcc.ansi/core/math/log10.c +++ b/lang/cem/libcc.ansi/core/math/log10.c @@ -8,8 +8,11 @@ #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double log10(double x) { @@ -31,3 +34,6 @@ log10(double x) return log(x) / M_LN10; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/modf.e b/lang/cem/libcc.ansi/core/math/modf.e index 8e819a7f5..8f0ea8adb 100644 --- a/lang/cem/libcc.ansi/core/math/modf.e +++ b/lang/cem/libcc.ansi/core/math/modf.e @@ -4,8 +4,11 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ +#include mes 2,_EM_WSIZE,_EM_PSIZE + +#if ACKCONF_WANT_FLOAT exp $modf pro $modf,0 lal 0 @@ -20,3 +23,4 @@ sti _EM_DSIZE ret _EM_DSIZE end +#endif diff --git a/lang/cem/libcc.ansi/core/math/pow.c b/lang/cem/libcc.ansi/core/math/pow.c index 0e6d6c99b..3fb40cb7f 100644 --- a/lang/cem/libcc.ansi/core/math/pow.c +++ b/lang/cem/libcc.ansi/core/math/pow.c @@ -10,6 +10,9 @@ #include #include #include +#include + +#if ACKCONF_WANT_FLOAT double pow(double x, double y) @@ -120,3 +123,6 @@ pow(double x, double y) } return ldexp(fp, newexp); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/sin.c b/lang/cem/libcc.ansi/core/math/sin.c index a55fa93d0..9a4078c56 100644 --- a/lang/cem/libcc.ansi/core/math/sin.c +++ b/lang/cem/libcc.ansi/core/math/sin.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + static double sinus(double x, int cos_flag) { @@ -106,3 +109,6 @@ cos(double x) x = -x; return sinus(x, 1); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/sinh.c b/lang/cem/libcc.ansi/core/math/sinh.c index 00ad3fc36..a16535527 100644 --- a/lang/cem/libcc.ansi/core/math/sinh.c +++ b/lang/cem/libcc.ansi/core/math/sinh.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + static double sinh_cosh(double x, int cosh_flag) { @@ -86,3 +89,6 @@ cosh(double x) x = -x; return sinh_cosh(x, 1); } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/sqrt.c b/lang/cem/libcc.ansi/core/math/sqrt.c index 17cfcdc0e..b5a6f71cf 100644 --- a/lang/cem/libcc.ansi/core/math/sqrt.c +++ b/lang/cem/libcc.ansi/core/math/sqrt.c @@ -9,6 +9,9 @@ #include #include #include +#include + +#if ACKCONF_WANT_FLOAT #define NITER 5 @@ -47,3 +50,6 @@ sqrt(double x) } return val; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/tan.c b/lang/cem/libcc.ansi/core/math/tan.c index 0d7a32589..b51df5a74 100644 --- a/lang/cem/libcc.ansi/core/math/tan.c +++ b/lang/cem/libcc.ansi/core/math/tan.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double tan(double x) { @@ -79,3 +82,6 @@ tan(double x) x = -x; return invert ? -y / x : x / y; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/tanh.c b/lang/cem/libcc.ansi/core/math/tanh.c index 1bf90dd9b..3978c2427 100644 --- a/lang/cem/libcc.ansi/core/math/tanh.c +++ b/lang/cem/libcc.ansi/core/math/tanh.c @@ -9,8 +9,11 @@ #include #include #include +#include #include "localmath.h" +#if ACKCONF_WANT_FLOAT + double tanh(double x) { @@ -58,3 +61,6 @@ tanh(double x) } return negative ? -x : x; } + +#endif + diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index de714af4e..13a3305c5 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -3,4 +3,12 @@ #include +#ifndef ACKCONF_WANT_FLOAT +#define ACKCONF_WANT_FLOAT 1 +#endif + +#ifndef ACKCONF_WANT_STDIO_FLOAT +#define ACKCONF_WANT_STDIO_FLOAT ACKCONF_WANT_FLOAT +#endif + #endif diff --git a/lang/cem/libcc.ansi/stdio/doprnt.c b/lang/cem/libcc.ansi/stdio/doprnt.c index dca935aad..3e754801d 100644 --- a/lang/cem/libcc.ansi/stdio/doprnt.c +++ b/lang/cem/libcc.ansi/stdio/doprnt.c @@ -311,7 +311,7 @@ int _doprnt(register const char* fmt, va_list ap, FILE* stream) case 'c': *s++ = va_arg(ap, int); break; -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT case 'G': case 'g': if ((flags & FL_PRECSPEC) && (precision == 0)) @@ -328,7 +328,7 @@ int _doprnt(register const char* fmt, va_list ap, FILE* stream) flags |= FL_SIGNEDCONV; s = _f_print(&ap, flags, s, c, precision); break; -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif case 'r': ap = va_arg(ap, va_list); fmt = va_arg(ap, char*); diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/stdio/doscan.c index 52e957a5d..b53b4666f 100644 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ b/lang/cem/libcc.ansi/stdio/doscan.c @@ -108,7 +108,7 @@ o_collect(register int c, register FILE* stream, char type, return bufp - 1; } -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT /* The function f_collect() reads a string that has the format of a * floating-point number. The function returns as soon as a format-error * is encountered, leaving the offending character in the input. This means @@ -191,7 +191,7 @@ f_collect(register int c, register FILE* stream, register int width) *bufp = '\0'; return bufp - 1; } -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif /* * the routine that does the scanning @@ -211,7 +211,7 @@ int _doscan(register FILE* stream, const char* format, va_list ap) int reverse; /* reverse the checking in [...] */ int kind; register int ic; /* the input character */ -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT long double ld_val; #endif @@ -495,7 +495,7 @@ int _doscan(register FILE* stream, const char* format, va_list ap) *str = '\0'; } break; -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT case 'e': case 'E': case 'f': diff --git a/lang/cem/libcc.ansi/stdio/ecvt.c b/lang/cem/libcc.ansi/stdio/ecvt.c index 4821fccbc..25243f0a4 100644 --- a/lang/cem/libcc.ansi/stdio/ecvt.c +++ b/lang/cem/libcc.ansi/stdio/ecvt.c @@ -2,7 +2,7 @@ #include "loc_incl.h" -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT #include "../stdlib/ext_fmt.h" void _dbl_ext_cvt(double value, struct EXTEND* e); @@ -28,4 +28,4 @@ char* _fcvt(long double value, int ndigit, int* decpt, int* sign) return cvt(value, ndigit, decpt, sign, 0); } -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif diff --git a/lang/cem/libcc.ansi/stdio/fltpr.c b/lang/cem/libcc.ansi/stdio/fltpr.c index 091111949..af1ca8728 100644 --- a/lang/cem/libcc.ansi/stdio/fltpr.c +++ b/lang/cem/libcc.ansi/stdio/fltpr.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT static char* _pfloat(long double r, register char* s, int n, int flags) @@ -209,4 +209,4 @@ char* _f_print(va_list* ap, int flags, char* s, char c, int precision) } return s; } -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/stdio/loc_incl.h index 126a31faf..52488e0c9 100644 --- a/lang/cem/libcc.ansi/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/stdio/loc_incl.h @@ -19,10 +19,10 @@ void __cleanup(void); FILE *popen(const char *command, const char *type); FILE *fdopen(int fd, const char *mode); -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT char *_ecvt(long double value, int ndigit, int *decpt, int *sign); char *_fcvt(long double value, int ndigit, int *decpt, int *sign); -#endif /* ACKCONF_NO_STDIO_FLOAT */ +#endif #define FL_LJUST 0x0001 /* left-justify field */ #define FL_SIGN 0x0002 /* sign in signed conversions */ diff --git a/lang/cem/libcc.ansi/stdlib/strtod.c b/lang/cem/libcc.ansi/stdlib/strtod.c index 48f60e200..d9009bcc6 100644 --- a/lang/cem/libcc.ansi/stdlib/strtod.c +++ b/lang/cem/libcc.ansi/stdlib/strtod.c @@ -1,9 +1,10 @@ /* $Id$ */ #include +#include #include "ext_fmt.h" -#ifndef ACKCONF_NO_STDIO_FLOAT +#if ACKCONF_WANT_STDIO_FLOAT void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); double _ext_dbl_cvt(struct EXTEND* e); diff --git a/plat/cpm/include/ack/plat.h b/plat/cpm/include/ack/plat.h index 5f785b0e1..cbd879396 100644 --- a/plat/cpm/include/ack/plat.h +++ b/plat/cpm/include/ack/plat.h @@ -11,9 +11,4 @@ #define ACKCONF_TIME_IS_A_SYSCALL -/* Since the i80 code generator doesn't support floating point, don't include - * it in the stdio libraries. */ - -#define ACKCONF_NO_STDIO_FLOAT - #endif diff --git a/plat/linuxppc/include/ack/plat.h b/plat/linuxppc/include/ack/plat.h index e25914574..9145197c4 100644 --- a/plat/linuxppc/include/ack/plat.h +++ b/plat/linuxppc/include/ack/plat.h @@ -11,8 +11,4 @@ /* #define ACKCONF_TIME_IS_A_SYSCALL */ -/* We don't support floating point right now. */ - -/* #define ACKCONF_NO_STDIO_FLOAT */ - #endif From 5fd8d772fd078915c0e892cb383fbebb7a1da716 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:14:24 +0200 Subject: [PATCH 15/37] Move the string-to-float functions into core, after marking them as ACKCONF_WANT_FLOAT. --- lang/cem/libcc.ansi/build.lua | 2 +- lang/cem/libcc.ansi/{ => core}/stdlib/atof.c | 5 +++++ .../libcc.ansi/{stdio => core/stdlib}/ecvt.c | 7 +++--- .../libcc.ansi/{ => core}/stdlib/ext_comp.c | 8 +++++-- lang/cem/libcc.ansi/core/stdlib/ext_fmt.h | 22 +++++++++++++++++++ .../cem/libcc.ansi/{ => core}/stdlib/strtod.c | 5 +---- lang/cem/libcc.ansi/stdlib/ext_fmt.h | 13 ----------- 7 files changed, 38 insertions(+), 24 deletions(-) rename lang/cem/libcc.ansi/{ => core}/stdlib/atof.c (85%) rename lang/cem/libcc.ansi/{stdio => core/stdlib}/ecvt.c (71%) rename lang/cem/libcc.ansi/{ => core}/stdlib/ext_comp.c (99%) create mode 100644 lang/cem/libcc.ansi/core/stdlib/ext_fmt.h rename lang/cem/libcc.ansi/{ => core}/stdlib/strtod.c (60%) delete mode 100644 lang/cem/libcc.ansi/stdlib/ext_fmt.h diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 9ca2279cd..d5e33a6e2 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -57,8 +57,8 @@ for _, plat in ipairs(vars.plats) do "plat/"..plat.."/include+pkg", "./malloc/malloc.h", "./core/math/localmath.h", + "./core/stdlib/ext_fmt.h", "./stdio/loc_incl.h", - "./stdlib/ext_fmt.h", "./time/loc_time.h", }, vars = { plat = plat } diff --git a/lang/cem/libcc.ansi/stdlib/atof.c b/lang/cem/libcc.ansi/core/stdlib/atof.c similarity index 85% rename from lang/cem/libcc.ansi/stdlib/atof.c rename to lang/cem/libcc.ansi/core/stdlib/atof.c index c46304817..d8092b841 100644 --- a/lang/cem/libcc.ansi/stdlib/atof.c +++ b/lang/cem/libcc.ansi/core/stdlib/atof.c @@ -6,6 +6,9 @@ #include #include +#include + +#if ACKCONF_WANT_FLOAT double(atof)(const char* nptr) { @@ -16,3 +19,5 @@ double(atof)(const char* nptr) errno = e; return d; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/ecvt.c b/lang/cem/libcc.ansi/core/stdlib/ecvt.c similarity index 71% rename from lang/cem/libcc.ansi/stdio/ecvt.c rename to lang/cem/libcc.ansi/core/stdlib/ecvt.c index 25243f0a4..f17ec9f50 100644 --- a/lang/cem/libcc.ansi/stdio/ecvt.c +++ b/lang/cem/libcc.ansi/core/stdlib/ecvt.c @@ -1,12 +1,11 @@ /* $Id$ */ -#include "loc_incl.h" +#include +#include #if ACKCONF_WANT_STDIO_FLOAT -#include "../stdlib/ext_fmt.h" -void _dbl_ext_cvt(double value, struct EXTEND* e); -char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag); +#include "ext_fmt.h" static char* cvt(long double value, int ndigit, int* decpt, int* sign, int ecvtflag) diff --git a/lang/cem/libcc.ansi/stdlib/ext_comp.c b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c similarity index 99% rename from lang/cem/libcc.ansi/stdlib/ext_comp.c rename to lang/cem/libcc.ansi/core/stdlib/ext_comp.c index c9b0b8b13..28eb213a4 100644 --- a/lang/cem/libcc.ansi/stdlib/ext_comp.c +++ b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c @@ -17,6 +17,8 @@ #include #include +#if ACKCONF_WANT_FLOAT + static int b64_add(struct mantissa* e1, struct mantissa* e2); static b64_sft(struct mantissa* e1, int n); @@ -494,7 +496,7 @@ static add_exponent(struct EXTEND* e, int exp) } } -_str_ext_cvt(const char* s, char** ss, struct EXTEND* e) +void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e) { /* Like strtod, but for extended precision */ register int c; @@ -781,7 +783,7 @@ char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvt return buf; } -_dbl_ext_cvt(double value, struct EXTEND* e) +void _dbl_ext_cvt(double value, struct EXTEND* e) { /* Convert double to extended */ @@ -833,3 +835,5 @@ _ext_dbl_cvt(struct EXTEND* e) } return f; } + +#endif diff --git a/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h b/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h new file mode 100644 index 000000000..7b3a88824 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/ext_fmt.h @@ -0,0 +1,22 @@ +#ifndef _EXT_FMT_H +#define _EXT_FMT_H + +struct mantissa { + unsigned long h_32; + unsigned long l_32; +}; + +struct EXTEND { + short sign; + short exp; + struct mantissa mantissa; +#define m1 mantissa.h_32 +#define m2 mantissa.l_32 +}; + +extern void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); +extern double _ext_dbl_cvt(struct EXTEND* e); +extern void _dbl_ext_cvt(double value, struct EXTEND* e); +extern char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag); + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/strtod.c b/lang/cem/libcc.ansi/core/stdlib/strtod.c similarity index 60% rename from lang/cem/libcc.ansi/stdlib/strtod.c rename to lang/cem/libcc.ansi/core/stdlib/strtod.c index d9009bcc6..36a568d05 100644 --- a/lang/cem/libcc.ansi/stdlib/strtod.c +++ b/lang/cem/libcc.ansi/core/stdlib/strtod.c @@ -4,10 +4,7 @@ #include #include "ext_fmt.h" -#if ACKCONF_WANT_STDIO_FLOAT - -void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e); -double _ext_dbl_cvt(struct EXTEND* e); +#if ACKCONF_WANT_FLOAT double strtod(const char* p, char** pp) diff --git a/lang/cem/libcc.ansi/stdlib/ext_fmt.h b/lang/cem/libcc.ansi/stdlib/ext_fmt.h deleted file mode 100644 index e8a5db1b8..000000000 --- a/lang/cem/libcc.ansi/stdlib/ext_fmt.h +++ /dev/null @@ -1,13 +0,0 @@ -struct mantissa { - unsigned long h_32; - unsigned long l_32; -}; - -struct EXTEND { - short sign; - short exp; - struct mantissa mantissa; -#define m1 mantissa.h_32 -#define m2 mantissa.l_32 -}; - From fac0764621b46b5e6d0569d0554cfb13f81de325 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:14:40 +0200 Subject: [PATCH 16/37] Don't crash and burn if there are no tests to run. --- first/testsummary.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/first/testsummary.sh b/first/testsummary.sh index 2aca1d225..20cdc66ae 100755 --- a/first/testsummary.sh +++ b/first/testsummary.sh @@ -1,6 +1,11 @@ #!/bin/sh echo "" +if [ "$1" = "" ]; then + echo "No tests." + exit 0 +fi + succeeding="$(find "$@" -size 0)" notsucceeding="$(find "$@" ! -size 0)" if [ "$notsucceeding" != "" ]; then From fe3951d4ae19c87ddf8126133ff9d5e901bfe685 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:14:49 +0200 Subject: [PATCH 17/37] Warning fix. --- h/bc_string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h/bc_string.h b/h/bc_string.h index 32430a1ee..6b5a4cdbc 100644 --- a/h/bc_string.h +++ b/h/bc_string.h @@ -16,6 +16,6 @@ typedef struct{ int strlength; } String; -String *_newstr() ; +extern String *_newstr(char* str); #define MAXSTRING 1024 From dd0f959245b18201b2413ae6a410639ca48bf2e9 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:16:06 +0200 Subject: [PATCH 18/37] Move assert into core. --- lang/cem/libcc.ansi/assert/LIST | 1 - lang/cem/libcc.ansi/assert/Makefile | 2 -- lang/cem/libcc.ansi/{assert => core/misc}/assert.c | 0 3 files changed, 3 deletions(-) delete mode 100644 lang/cem/libcc.ansi/assert/LIST delete mode 100644 lang/cem/libcc.ansi/assert/Makefile rename lang/cem/libcc.ansi/{assert => core/misc}/assert.c (100%) diff --git a/lang/cem/libcc.ansi/assert/LIST b/lang/cem/libcc.ansi/assert/LIST deleted file mode 100644 index 87515cc41..000000000 --- a/lang/cem/libcc.ansi/assert/LIST +++ /dev/null @@ -1 +0,0 @@ -assert.c diff --git a/lang/cem/libcc.ansi/assert/Makefile b/lang/cem/libcc.ansi/assert/Makefile deleted file mode 100644 index a4dd9a5e8..000000000 --- a/lang/cem/libcc.ansi/assert/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f assert.o OLIST diff --git a/lang/cem/libcc.ansi/assert/assert.c b/lang/cem/libcc.ansi/core/misc/assert.c similarity index 100% rename from lang/cem/libcc.ansi/assert/assert.c rename to lang/cem/libcc.ansi/core/misc/assert.c From 32c881474e67637c4563e7ecb68ed2ea27929378 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 11:46:55 +0200 Subject: [PATCH 19/37] Create a basic and probably wrong common unistd.h, which replaces the plat one. Made this work with cpm (but nothing else yet). --- build.lua | 30 +++---- lang/cem/libcc.ansi/headers/ack/config.h | 8 ++ lang/cem/libcc.ansi/headers/stdint.h | 2 + .../cem/libcc.ansi/headers}/unistd.h | 84 ++++++++++--------- plat/cpm/include/build.lua | 2 +- plat/cpm/include/sys/types.h | 7 ++ plat/cpm/libsys/read.c | 6 +- plat/cpm/libsys/write.c | 2 +- 8 files changed, 83 insertions(+), 58 deletions(-) rename {plat/cpm/include => lang/cem/libcc.ansi/headers}/unistd.h (54%) create mode 100644 plat/cpm/include/sys/types.h diff --git a/build.lua b/build.lua index a1fe98e80..f675b96ea 100644 --- a/build.lua +++ b/build.lua @@ -7,23 +7,23 @@ vars.ackcflags = { vars.ackldflags = {} vars.plats = { "cpm", - "linux386", - "linux68k", - "linuxppc", - "osx386", - "osxppc", - --"qemuppc", - "pc86", - "rpi", - "pdpv7", - "em22", +-- "linux386", +-- "linux68k", +-- "linuxppc", +-- "osx386", +-- "osxppc", +-- --"qemuppc", +-- "pc86", +-- "rpi", +-- "pdpv7", +-- "em22", } vars.plats_with_tests = { - "linux68k", - "linux386", - "linuxppc", - --"qemuppc", - "pc86", +-- "linux68k", +-- "linux386", +-- "linuxppc", +-- --"qemuppc", +-- "pc86", } local plat_packages = {} diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index 13a3305c5..84174a11d 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -11,4 +11,12 @@ #define ACKCONF_WANT_STDIO_FLOAT ACKCONF_WANT_FLOAT #endif +#ifndef ACKCONF_WANT_STANDARD_O +#define ACKCONF_WANT_STANDARD_O 1 +#endif + +#ifndef ACKCONF_WANT_STANDARD_SIGNALS +#define ACKCONF_WANT_STANDARD_SIGNALS 1 +#endif + #endif diff --git a/lang/cem/libcc.ansi/headers/stdint.h b/lang/cem/libcc.ansi/headers/stdint.h index ce9cf3e38..e2eb4c201 100644 --- a/lang/cem/libcc.ansi/headers/stdint.h +++ b/lang/cem/libcc.ansi/headers/stdint.h @@ -58,6 +58,7 @@ typedef int16_t intptr_t; typedef uint16_t uintptr_t; typedef int16_t ptrdiff_t; typedef uint16_t size_t; +typedef int16_t ssize_t; #define INTPTR_MAX 32767 #define INTPTR_MIN (-32768) #define UINTPTR_MAX 65535 @@ -66,6 +67,7 @@ typedef int32_t intptr_t; typedef uint32_t uintptr_t; typedef int32_t ptrdiff_t; typedef uint32_t size_t; +typedef int32_t ssize_t; #define INTPTR_MAX 2147483647 #define INTPTR_MIN (-2147483647) #define UINTPTR_MAX 4294967295 diff --git a/plat/cpm/include/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h similarity index 54% rename from plat/cpm/include/unistd.h rename to lang/cem/libcc.ansi/headers/unistd.h index 99f1fb2d4..65e0b9991 100644 --- a/plat/cpm/include/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -1,19 +1,20 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ - #ifndef _UNISTD_H #define _UNISTD_H +/* + * Generic Posix prototypes used by the rest of the libc. Plats don't have to + * implement these if they don't care about the functionality, but if they do, + * they must conform to these prototypes. + */ + +#include #include +#include +#include -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -/* Constants for file access (open and friends) */ +#if ACKCONF_WANT_STANDARD_O +/* A standard set of flags for read/write/creat and friends for platforms + * where these aren't determined by the operating system. */ enum { @@ -28,31 +29,11 @@ enum O_APPEND = 02000, O_NONBLOCK = 04000 }; +#endif -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern void* sbrk(int increment); -extern int isatty(int d); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int close(int d); -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern int unlink(const char* path); - -/* Unimplemented system calls (these are just prototypes to let the library - * compile). */ - -extern int fcntl(int fd, int op, ...); - -/* Signal handling */ +#if ACKCONF_WANT_STANDARD_SIGNALS +/* A standard set of definitions for signal handling for platforms where these + * aren't determined by the operating system. */ typedef int sig_atomic_t; @@ -63,10 +44,37 @@ typedef int sig_atomic_t; #define SIGABRT 6 /* Abort (ANSI) */ #define SIGILL 11 /* Illegal instruction */ -#define _NSIG 32 /* Biggest signal number + 1 +#define _NSIG 16 /* Biggest signal number + 1 (not including real-time signals). */ typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int raise(int signum); +typedef uint16_t sigset_t; + +#endif + +/* Special variables */ + +extern char** environ; + +/* Implemented system calls */ + +extern int brk(void* ptr); +extern int close(int d); +extern int creat(const char* path, mode_t mode); +extern int execve(const char *path, char *const argv[], char *const envp[]); +extern int isatty(int d); +extern int isatty(int d); +extern int kill(pid_t old, int sig); +extern int open(const char* path, int access, ...); +extern int raise(int signum); +extern int sigprocmask(int, const sigset_t *, sigset_t *); +extern int unlink(const char* path); +extern off_t lseek(int fildes, off_t offset, int whence); +extern pid_t getpid(void); +extern sighandler_t signal(int signum, sighandler_t handler); +extern ssize_t read(int fd, void* buffer, size_t count); +extern ssize_t write(int fd, void* buffer, size_t count); +extern void _exit(int); +extern void* sbrk(int increment); +extern int fcntl(int fd, int op, ...); #endif diff --git a/plat/cpm/include/build.lua b/plat/cpm/include/build.lua index 0fdc2903d..9820e3e09 100644 --- a/plat/cpm/include/build.lua +++ b/plat/cpm/include/build.lua @@ -9,8 +9,8 @@ local function addheader(h) end addheader("ack/plat.h") +addheader("sys/types.h") addheader("cpm.h") -addheader("unistd.h") acklibrary { name = "headers", diff --git a/plat/cpm/include/sys/types.h b/plat/cpm/include/sys/types.h new file mode 100644 index 000000000..9b384113d --- /dev/null +++ b/plat/cpm/include/sys/types.h @@ -0,0 +1,7 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef int pid_t; +typedef int mode_t; + +#endif diff --git a/plat/cpm/libsys/read.c b/plat/cpm/libsys/read.c index f81bda777..df4a3ef3b 100644 --- a/plat/cpm/libsys/read.c +++ b/plat/cpm/libsys/read.c @@ -8,7 +8,7 @@ #include #include -int read(int fd, void* buffer, size_t count) +ssize_t read(int fd, void* buffer, size_t count) { short save; unsigned char before_n; @@ -37,7 +37,7 @@ int read(int fd, void* buffer, size_t count) /* Read one line from the console. */ ((unsigned char*)buffer)[-2] = before_n; cpm_bc_register = CPM_BDOS_READ_CONSOLE_BUFFER; - cpm_de_register = (char*)buffer - 2; + cpm_de_register = (uint16_t)(char*)buffer - 2; cpm_bdos(); before_n = ((unsigned char*)buffer)[-1]; @@ -46,7 +46,7 @@ int read(int fd, void* buffer, size_t count) /* Echo '\n' to console. */ cpm_bc_register = CPM_BDOS_PRINT_STRING; - cpm_de_register = "\r\n$"; + cpm_de_register = (uint16_t)"\r\n$"; cpm_bdos(); return (int)before_n + 1; diff --git a/plat/cpm/libsys/write.c b/plat/cpm/libsys/write.c index 0b5f2613d..21dbc90c0 100644 --- a/plat/cpm/libsys/write.c +++ b/plat/cpm/libsys/write.c @@ -22,7 +22,7 @@ void _sys_write_tty(char c) } } -int write(int fd, void* buffer, size_t count) +ssize_t write(int fd, void* buffer, size_t count) { int i; char* p = buffer; From 66815ff987866d0da26bd6899ad431fbf4f596b1 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:13:33 +0200 Subject: [PATCH 20/37] Make linux386 work with the new libc layout. --- build.lua | 4 +- lang/cem/libcc.ansi/headers/time.h | 5 +- lang/cem/libcc.ansi/headers/unistd.h | 78 +++++++++++------- plat/cpm/include/sys/types.h | 2 + plat/linux/libsys/ioctl.c | 2 +- plat/linux386/include/ack/fcntl.h | 19 +++++ plat/linux386/include/ack/plat.h | 5 ++ .../include/{unistd.h => ack/signal.h} | 80 +------------------ plat/linux386/include/build.lua | 4 +- plat/linux386/include/sys/types.h | 9 +++ 10 files changed, 96 insertions(+), 112 deletions(-) create mode 100644 plat/linux386/include/ack/fcntl.h rename plat/linux386/include/{unistd.h => ack/signal.h} (64%) create mode 100644 plat/linux386/include/sys/types.h diff --git a/build.lua b/build.lua index f675b96ea..7b187c6d0 100644 --- a/build.lua +++ b/build.lua @@ -7,7 +7,7 @@ vars.ackcflags = { vars.ackldflags = {} vars.plats = { "cpm", --- "linux386", + "linux386", -- "linux68k", -- "linuxppc", -- "osx386", @@ -20,7 +20,7 @@ vars.plats = { } vars.plats_with_tests = { -- "linux68k", --- "linux386", + "linux386", -- "linuxppc", -- --"qemuppc", -- "pc86", diff --git a/lang/cem/libcc.ansi/headers/time.h b/lang/cem/libcc.ansi/headers/time.h index 27901bee9..088a0b0d1 100644 --- a/lang/cem/libcc.ansi/headers/time.h +++ b/lang/cem/libcc.ansi/headers/time.h @@ -7,10 +7,9 @@ #define _TIME_H #include +#include #define CLOCKS_PER_SEC 1000000 - -typedef unsigned long time_t; /* type returned by TOD clock */ typedef unsigned long clock_t; /* type returned by real time clock */ struct tm { @@ -25,7 +24,9 @@ struct tm { int tm_isdst; /* Daylight Saving Time flag */ }; +/* Not a system call; this calls gettimeofday() or times() to do the work */ extern clock_t clock(void); + extern double difftime(time_t _time1, time_t _time0); extern time_t mktime(struct tm *_timeptr); extern time_t time(time_t *_timeptr); diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index 65e0b9991..374a42070 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -13,44 +13,61 @@ #include #if ACKCONF_WANT_STANDARD_O -/* A standard set of flags for read/write/creat and friends for platforms - * where these aren't determined by the operating system. */ + /* A standard set of flags for read/write/creat and friends for platforms + * where these aren't determined by the operating system. */ -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; + enum + { + O_ACCMODE = 0x3, + + O_RDONLY = 0, + O_WRONLY = 1, + O_RDWR = 2, + + O_CREAT = 0100, + O_TRUNC = 01000, + O_APPEND = 02000, + O_NONBLOCK = 04000 + }; +#else + #include #endif #if ACKCONF_WANT_STANDARD_SIGNALS -/* A standard set of definitions for signal handling for platforms where these - * aren't determined by the operating system. */ + /* A standard set of definitions for signal handling for platforms where these + * aren't determined by the operating system. */ -typedef int sig_atomic_t; + typedef int sig_atomic_t; -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ + #define SIG_ERR ((sighandler_t) -1) /* Error return. */ + #define SIG_DFL ((sighandler_t) 0) /* Default action. */ + #define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ -#define SIGABRT 6 /* Abort (ANSI) */ -#define SIGILL 11 /* Illegal instruction */ - -#define _NSIG 16 /* Biggest signal number + 1 - (not including real-time signals). */ -typedef void (*sighandler_t)(int); -typedef uint16_t sigset_t; + #define SIGABRT 6 /* Abort (ANSI) */ + #define SIGILL 11 /* Illegal instruction */ + #define _NSIG 16 /* Biggest signal number + 1 + (not including real-time signals). */ + typedef void (*sighandler_t)(int); + typedef uint16_t sigset_t; +#else + #include #endif +/* Time handling. */ + +struct timeval +{ + time_t tv_sec; + suseconds_t tv_usec; +}; + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; /* obsolete, unused */ + /* Special variables */ extern char** environ; @@ -61,11 +78,14 @@ extern int brk(void* ptr); extern int close(int d); extern int creat(const char* path, mode_t mode); extern int execve(const char *path, char *const argv[], char *const envp[]); +extern int fcntl(int fd, int op, ...); +extern int gettimeofday(struct timeval* tv, struct timezone* tz); extern int isatty(int d); extern int isatty(int d); extern int kill(pid_t old, int sig); extern int open(const char* path, int access, ...); extern int raise(int signum); +extern int settimeofday(const struct timeval* tv, const struct timezone* tz); extern int sigprocmask(int, const sigset_t *, sigset_t *); extern int unlink(const char* path); extern off_t lseek(int fildes, off_t offset, int whence); @@ -75,6 +95,6 @@ extern ssize_t read(int fd, void* buffer, size_t count); extern ssize_t write(int fd, void* buffer, size_t count); extern void _exit(int); extern void* sbrk(int increment); -extern int fcntl(int fd, int op, ...); + #endif diff --git a/plat/cpm/include/sys/types.h b/plat/cpm/include/sys/types.h index 9b384113d..6a0c3d3db 100644 --- a/plat/cpm/include/sys/types.h +++ b/plat/cpm/include/sys/types.h @@ -3,5 +3,7 @@ typedef int pid_t; typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; #endif diff --git a/plat/linux/libsys/ioctl.c b/plat/linux/libsys/ioctl.c index a77d1f49f..13be2cd24 100644 --- a/plat/linux/libsys/ioctl.c +++ b/plat/linux/libsys/ioctl.c @@ -7,5 +7,5 @@ */ int ioctl(int fd, unsigned long request, void *argp) { - return _syscall(__NR_ioctl, fd, request, argp); + return _syscall(__NR_ioctl, fd, request, (quad)argp); } diff --git a/plat/linux386/include/ack/fcntl.h b/plat/linux386/include/ack/fcntl.h new file mode 100644 index 000000000..c3e2e643b --- /dev/null +++ b/plat/linux386/include/ack/fcntl.h @@ -0,0 +1,19 @@ +#ifndef _ACK_FCNTL_H +#define _ACK_FCNTL_H + +/* Linux O_ constants. */ + +enum +{ + O_ACCMODE = 0x3, + + O_RDONLY = 0, + O_WRONLY = 1, + O_RDWR = 2, + + O_CREAT = 0x40, + O_TRUNC = 0x200, + O_APPEND = 0x400 +}; + +#endif diff --git a/plat/linux386/include/ack/plat.h b/plat/linux386/include/ack/plat.h index f65adb8d7..65911f47e 100644 --- a/plat/linux386/include/ack/plat.h +++ b/plat/linux386/include/ack/plat.h @@ -11,4 +11,9 @@ /* #define ACKCONF_TIME_IS_A_SYSCALL */ +/* Linux has its own O_ definitions. */ + +#define ACKCONF_WANT_STANDARD_O 0 +#define ACKCONF_WANT_STANDARD_SIGNALS 0 + #endif diff --git a/plat/linux386/include/unistd.h b/plat/linux386/include/ack/signal.h similarity index 64% rename from plat/linux386/include/unistd.h rename to plat/linux386/include/ack/signal.h index 8c8637c09..1f41234b6 100644 --- a/plat/linux386/include/unistd.h +++ b/plat/linux386/include/ack/signal.h @@ -1,76 +1,7 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ +#ifndef _ACK_SIGNAL_H +#define _ACK_SIGNAL_H -#ifndef _UNISTD_H -#define _UNISTD_H - -#include -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* File access. */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0x40, - O_TRUNC = 0x200, - O_APPEND = 0x400 -}; - -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int close(int d); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int fcntl(int fd, int op, ...); -extern int unlink(const char* path); - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* ptr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern int execve(const char *path, char *const argv[], char *const envp[]); - -/* Signal handling */ +/* Signal constants. */ typedef int sig_atomic_t; @@ -124,10 +55,5 @@ typedef int sig_atomic_t; typedef unsigned long sigset_t; typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int sigprocmask(int, const sigset_t *, sigset_t *); -extern int raise(int signum); - - #endif diff --git a/plat/linux386/include/build.lua b/plat/linux386/include/build.lua index 129fd9035..37ef9c565 100644 --- a/plat/linux386/include/build.lua +++ b/plat/linux386/include/build.lua @@ -9,8 +9,10 @@ local function addheader(h) end addheader("ack/plat.h") +addheader("ack/fcntl.h") +addheader("ack/signal.h") addheader("sys/ioctl.h") -addheader("unistd.h") +addheader("sys/types.h") acklibrary { name = "headers", diff --git a/plat/linux386/include/sys/types.h b/plat/linux386/include/sys/types.h new file mode 100644 index 000000000..b706026ef --- /dev/null +++ b/plat/linux386/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef int pid_t; +typedef int mode_t; +typedef long suseconds_t; +typedef long time_t; + +#endif From b267b56ad921c6d645f7c9b16b285c2b97209e9d Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:35:17 +0200 Subject: [PATCH 21/37] Made linux68k work; commoned up all the generic linux includes. --- build.lua | 4 +- lang/cem/libcc.ansi/malloc/calloc.c | 1 + plat/{linux386 => linux}/include/ack/fcntl.h | 6 +- plat/{linux386 => linux}/include/ack/plat.h | 2 - plat/{linux386 => linux}/include/ack/signal.h | 0 plat/{linux386 => linux}/include/sys/ioctl.h | 0 plat/{linux386 => linux}/include/sys/types.h | 0 plat/linux386/include/build.lua | 4 +- plat/linux68k/include/ack/plat.h | 14 -- plat/linux68k/include/build.lua | 9 +- plat/linux68k/include/sys/ioctl.h | 76 ---------- plat/linux68k/include/unistd.h | 133 ------------------ 12 files changed, 14 insertions(+), 235 deletions(-) rename plat/{linux386 => linux}/include/ack/fcntl.h (70%) rename plat/{linux386 => linux}/include/ack/plat.h (88%) rename plat/{linux386 => linux}/include/ack/signal.h (100%) rename plat/{linux386 => linux}/include/sys/ioctl.h (100%) rename plat/{linux386 => linux}/include/sys/types.h (100%) delete mode 100644 plat/linux68k/include/ack/plat.h delete mode 100644 plat/linux68k/include/sys/ioctl.h delete mode 100644 plat/linux68k/include/unistd.h diff --git a/build.lua b/build.lua index 7b187c6d0..3476efaec 100644 --- a/build.lua +++ b/build.lua @@ -8,7 +8,7 @@ vars.ackldflags = {} vars.plats = { "cpm", "linux386", --- "linux68k", + "linux68k", -- "linuxppc", -- "osx386", -- "osxppc", @@ -19,7 +19,7 @@ vars.plats = { -- "em22", } vars.plats_with_tests = { --- "linux68k", + "linux68k", "linux386", -- "linuxppc", -- --"qemuppc", diff --git a/lang/cem/libcc.ansi/malloc/calloc.c b/lang/cem/libcc.ansi/malloc/calloc.c index 814841fd5..8695f17f0 100644 --- a/lang/cem/libcc.ansi/malloc/calloc.c +++ b/lang/cem/libcc.ansi/malloc/calloc.c @@ -1,6 +1,7 @@ #include #include #include +#include void* calloc(size_t nmemb, size_t size) { diff --git a/plat/linux386/include/ack/fcntl.h b/plat/linux/include/ack/fcntl.h similarity index 70% rename from plat/linux386/include/ack/fcntl.h rename to plat/linux/include/ack/fcntl.h index c3e2e643b..361fad97a 100644 --- a/plat/linux386/include/ack/fcntl.h +++ b/plat/linux/include/ack/fcntl.h @@ -11,9 +11,9 @@ enum O_WRONLY = 1, O_RDWR = 2, - O_CREAT = 0x40, - O_TRUNC = 0x200, - O_APPEND = 0x400 + O_CREAT = 00000100, + O_TRUNC = 00001000, + O_APPEND = 00002000 }; #endif diff --git a/plat/linux386/include/ack/plat.h b/plat/linux/include/ack/plat.h similarity index 88% rename from plat/linux386/include/ack/plat.h rename to plat/linux/include/ack/plat.h index 65911f47e..0a2f9dded 100644 --- a/plat/linux386/include/ack/plat.h +++ b/plat/linux/include/ack/plat.h @@ -11,8 +11,6 @@ /* #define ACKCONF_TIME_IS_A_SYSCALL */ -/* Linux has its own O_ definitions. */ - #define ACKCONF_WANT_STANDARD_O 0 #define ACKCONF_WANT_STANDARD_SIGNALS 0 diff --git a/plat/linux386/include/ack/signal.h b/plat/linux/include/ack/signal.h similarity index 100% rename from plat/linux386/include/ack/signal.h rename to plat/linux/include/ack/signal.h diff --git a/plat/linux386/include/sys/ioctl.h b/plat/linux/include/sys/ioctl.h similarity index 100% rename from plat/linux386/include/sys/ioctl.h rename to plat/linux/include/sys/ioctl.h diff --git a/plat/linux386/include/sys/types.h b/plat/linux/include/sys/types.h similarity index 100% rename from plat/linux386/include/sys/types.h rename to plat/linux/include/sys/types.h diff --git a/plat/linux386/include/build.lua b/plat/linux386/include/build.lua index 37ef9c565..c26cdf067 100644 --- a/plat/linux386/include/build.lua +++ b/plat/linux386/include/build.lua @@ -4,8 +4,8 @@ headermap = {} packagemap = {} local function addheader(h) - headermap[h] = "./"..h - packagemap["$(PLATIND)/linux386/include/"..h] = "./"..h + headermap[h] = "plat/linux/include/"..h + packagemap["$(PLATIND)/linux386/include/"..h] = "plat/linux/include/"..h end addheader("ack/plat.h") diff --git a/plat/linux68k/include/ack/plat.h b/plat/linux68k/include/ack/plat.h deleted file mode 100644 index 9145197c4..000000000 --- a/plat/linux68k/include/ack/plat.h +++ /dev/null @@ -1,14 +0,0 @@ -/* $Source: /cvsroot/tack/Ack/plat/linux386/include/ack/config.h,v $ - * $State: Exp $ - * $Revision: 1.1 $ - */ - -#ifndef _ACK_PLAT_H -#define _ACK_PLAT_H - -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -/* #define ACKCONF_TIME_IS_A_SYSCALL */ - -#endif diff --git a/plat/linux68k/include/build.lua b/plat/linux68k/include/build.lua index 131a52ba9..dc5333430 100644 --- a/plat/linux68k/include/build.lua +++ b/plat/linux68k/include/build.lua @@ -4,13 +4,15 @@ headermap = {} packagemap = {} local function addheader(h) - headermap[h] = "./"..h - packagemap["$(PLATIND)/linux68k/include/"..h] = "./"..h + headermap[h] = "plat/linux/include/"..h + packagemap["$(PLATIND)/linux68k/include/"..h] = "plat/linux/include/"..h end addheader("ack/plat.h") +addheader("ack/fcntl.h") +addheader("ack/signal.h") addheader("sys/ioctl.h") -addheader("unistd.h") +addheader("sys/types.h") acklibrary { name = "headers", @@ -22,3 +24,4 @@ installable { map = packagemap } + diff --git a/plat/linux68k/include/sys/ioctl.h b/plat/linux68k/include/sys/ioctl.h deleted file mode 100644 index af41165d7..000000000 --- a/plat/linux68k/include/sys/ioctl.h +++ /dev/null @@ -1,76 +0,0 @@ -/* $Source: /cvsroot/tack/Ack/plat/linux386/include/sys/ioctl.h,v $ - * $State: Exp $ - * $Revision: 1.1 $ - */ - -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - -/* These are copied from the ioctl_list(2) man page. */ - -/* */ - -#define FIOSETOWN 0x00008901 -#define SIOCSPGRP 0x00008902 -#define FIOGETOWN 0x00008903 -#define SIOCGPGRP 0x00008904 -#define SIOCATMARK 0x00008905 -#define SIOCGSTAMP 0x00008906 - -/* */ - -#define TCGETS 0x00005401 -#define TCSETS 0x00005402 -#define TCSETSW 0x00005403 -#define TCSETSF 0x00005404 -#define TCGETA 0x00005405 -#define TCSETA 0x00005406 -#define TCSETAW 0x00005407 -#define TCSETAF 0x00005408 -#define TCSBRK 0x00005409 -#define TCXONC 0x0000540A -#define TCFLSH 0x0000540B -#define TIOCEXCL 0x0000540C -#define TIOCNXCL 0x0000540D -#define TIOCSCTTY 0x0000540E -#define TIOCGPGRP 0x0000540F -#define TIOCSPGRP 0x00005410 -#define TIOCOUTQ 0x00005411 -#define TIOCSTI 0x00005412 -#define TIOCGWINSZ 0x00005413 -#define TIOCSWINSZ 0x00005414 -#define TIOCMGET 0x00005415 -#define TIOCMBIS 0x00005416 -#define TIOCMBIC 0x00005417 -#define TIOCMSET 0x00005418 -#define TIOCGSOFTCAR 0x00005419 -#define TIOCSSOFTCAR 0x0000541A -#define FIONREAD 0x0000541B -#define TIOCINQ 0x0000541B -#define TIOCLINUX 0x0000541C -#define TIOCCONS 0x0000541D -#define TIOCGSERIAL 0x0000541E -#define TIOCSSERIAL 0x0000541F -#define TIOCPKT 0x00005420 -#define FIONBIO 0x00005421 -#define TIOCNOTTY 0x00005422 -#define TIOCSETD 0x00005423 -#define TIOCGETD 0x00005424 -#define TCSBRKP 0x00005425 -#define TIOCTTYGSTRUCT 0x00005426 -#define FIONCLEX 0x00005450 -#define FIOCLEX 0x00005451 -#define FIOASYNC 0x00005452 -#define TIOCSERCONFIG 0x00005453 -#define TIOCSERGWILD 0x00005454 -#define TIOCSERSWILD 0x00005455 -#define TIOCGLCKTRMIOS 0x00005456 -#define TIOCSLCKTRMIOS 0x00005457 -#define TIOCSERGSTRUCT 0x00005458 -#define TIOCSERGETLSR 0x00005459 -#define TIOCSERGETMULTI 0x0000545A -#define TIOCSERSETMULTI 0x0000545B - - - -#endif diff --git a/plat/linux68k/include/unistd.h b/plat/linux68k/include/unistd.h deleted file mode 100644 index 927a20459..000000000 --- a/plat/linux68k/include/unistd.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ - -#ifndef _UNISTD_H -#define _UNISTD_H - -#include -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* File access. */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0x10, - O_TRUNC = 0x20, - O_APPEND = 0x40 -}; - -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int close(int d); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int fcntl(int fd, int op, ...); -extern int unlink(const char* path); - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* ptr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern int execve(const char *path, char *const argv[], char *const envp[]); - -/* Signal handling */ - -typedef int sig_atomic_t; - -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ - -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGABRT 6 /* Abort (ANSI). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGBUS 7 /* BUS error (4.2 BSD). */ -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */ -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGSTKFLT 16 /* Stack fault. */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGCHLD 17 /* Child status has changed (POSIX). */ -#define SIGCONT 18 /* Continue (POSIX). */ -#define SIGSTOP 19 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 20 /* Keyboard stop (POSIX). */ -#define SIGTTIN 21 /* Background read from tty (POSIX). */ -#define SIGTTOU 22 /* Background write to tty (POSIX). */ -#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */ -#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */ -#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */ -#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */ -#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ -#define SIGPOLL SIGIO /* Pollable event occurred (System V). */ -#define SIGIO 29 /* I/O now possible (4.2 BSD). */ -#define SIGPWR 30 /* Power failure restart (System V). */ -#define SIGSYS 31 /* Bad system call. */ -#define SIGUNUSED 31 - -#define _NSIG 32 /* Biggest signal number + 1 - (not including real-time signals). */ - -/* sigprocmask */ -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 -typedef unsigned long sigset_t; - -typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int sigprocmask(int, const sigset_t *, sigset_t *); -extern int raise(int signum); - - - -#endif From b727b7affdbbae14d36ba9fafd898aa1d9756771 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:41:54 +0200 Subject: [PATCH 22/37] Make linuxppc work. --- build.lua | 4 +- lang/cem/libcc.ansi/headers/unistd.h | 3 + plat/linux/include/ack/signal.h | 17 +++ plat/linuxppc/include/ack/plat.h | 14 --- plat/linuxppc/include/build.lua | 10 +- plat/linuxppc/include/sys/ioctl.h | 76 -------------- plat/linuxppc/include/unistd.h | 151 --------------------------- 7 files changed, 29 insertions(+), 246 deletions(-) delete mode 100644 plat/linuxppc/include/ack/plat.h delete mode 100644 plat/linuxppc/include/sys/ioctl.h delete mode 100644 plat/linuxppc/include/unistd.h diff --git a/build.lua b/build.lua index 3476efaec..f182020b2 100644 --- a/build.lua +++ b/build.lua @@ -9,7 +9,7 @@ vars.plats = { "cpm", "linux386", "linux68k", --- "linuxppc", + "linuxppc", -- "osx386", -- "osxppc", -- --"qemuppc", @@ -21,7 +21,7 @@ vars.plats = { vars.plats_with_tests = { "linux68k", "linux386", --- "linuxppc", + "linuxppc", -- --"qemuppc", -- "pc86", } diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index 374a42070..8818fa66e 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -50,6 +50,8 @@ (not including real-time signals). */ typedef void (*sighandler_t)(int); typedef uint16_t sigset_t; + + struct sigaction; #else #include #endif @@ -86,6 +88,7 @@ extern int kill(pid_t old, int sig); extern int open(const char* path, int access, ...); extern int raise(int signum); extern int settimeofday(const struct timeval* tv, const struct timezone* tz); +extern int sigaction(int, const struct sigaction *, struct sigaction *); extern int sigprocmask(int, const sigset_t *, sigset_t *); extern int unlink(const char* path); extern off_t lseek(int fildes, off_t offset, int whence); diff --git a/plat/linux/include/ack/signal.h b/plat/linux/include/ack/signal.h index 1f41234b6..d7ec086b2 100644 --- a/plat/linux/include/ack/signal.h +++ b/plat/linux/include/ack/signal.h @@ -56,4 +56,21 @@ typedef unsigned long sigset_t; typedef void (*sighandler_t)(int); +/* sa_flags */ +#define SA_NODEFER 0x40000000UL +#define SA_RESETHAND 0x80000000UL + +struct __siginfo; +struct sigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, struct __siginfo *, void *); + } __sigaction_u; + sigset_t sa_mask; + unsigned long sa_flags; + void (*sa_restorer)(void); +}; +#define sa_handler __sigaction_u.__sa_handler +#define sa_sigaction __sigaction_u.__sa_sigaction + #endif diff --git a/plat/linuxppc/include/ack/plat.h b/plat/linuxppc/include/ack/plat.h deleted file mode 100644 index 9145197c4..000000000 --- a/plat/linuxppc/include/ack/plat.h +++ /dev/null @@ -1,14 +0,0 @@ -/* $Source: /cvsroot/tack/Ack/plat/linux386/include/ack/config.h,v $ - * $State: Exp $ - * $Revision: 1.1 $ - */ - -#ifndef _ACK_PLAT_H -#define _ACK_PLAT_H - -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -/* #define ACKCONF_TIME_IS_A_SYSCALL */ - -#endif diff --git a/plat/linuxppc/include/build.lua b/plat/linuxppc/include/build.lua index 5fef69c6e..8adc0c7d1 100644 --- a/plat/linuxppc/include/build.lua +++ b/plat/linuxppc/include/build.lua @@ -4,13 +4,15 @@ headermap = {} packagemap = {} local function addheader(h) - headermap[h] = "./"..h - packagemap["$(PLATIND)/linuxppc/include/"..h] = "./"..h + headermap[h] = "plat/linux/include/"..h + packagemap["$(PLATIND)/linuxppc/include/"..h] = "plat/linux/include/"..h end addheader("ack/plat.h") +addheader("ack/fcntl.h") +addheader("ack/signal.h") addheader("sys/ioctl.h") -addheader("unistd.h") +addheader("sys/types.h") acklibrary { name = "headers", @@ -22,3 +24,5 @@ installable { map = packagemap } + + diff --git a/plat/linuxppc/include/sys/ioctl.h b/plat/linuxppc/include/sys/ioctl.h deleted file mode 100644 index af41165d7..000000000 --- a/plat/linuxppc/include/sys/ioctl.h +++ /dev/null @@ -1,76 +0,0 @@ -/* $Source: /cvsroot/tack/Ack/plat/linux386/include/sys/ioctl.h,v $ - * $State: Exp $ - * $Revision: 1.1 $ - */ - -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - -/* These are copied from the ioctl_list(2) man page. */ - -/* */ - -#define FIOSETOWN 0x00008901 -#define SIOCSPGRP 0x00008902 -#define FIOGETOWN 0x00008903 -#define SIOCGPGRP 0x00008904 -#define SIOCATMARK 0x00008905 -#define SIOCGSTAMP 0x00008906 - -/* */ - -#define TCGETS 0x00005401 -#define TCSETS 0x00005402 -#define TCSETSW 0x00005403 -#define TCSETSF 0x00005404 -#define TCGETA 0x00005405 -#define TCSETA 0x00005406 -#define TCSETAW 0x00005407 -#define TCSETAF 0x00005408 -#define TCSBRK 0x00005409 -#define TCXONC 0x0000540A -#define TCFLSH 0x0000540B -#define TIOCEXCL 0x0000540C -#define TIOCNXCL 0x0000540D -#define TIOCSCTTY 0x0000540E -#define TIOCGPGRP 0x0000540F -#define TIOCSPGRP 0x00005410 -#define TIOCOUTQ 0x00005411 -#define TIOCSTI 0x00005412 -#define TIOCGWINSZ 0x00005413 -#define TIOCSWINSZ 0x00005414 -#define TIOCMGET 0x00005415 -#define TIOCMBIS 0x00005416 -#define TIOCMBIC 0x00005417 -#define TIOCMSET 0x00005418 -#define TIOCGSOFTCAR 0x00005419 -#define TIOCSSOFTCAR 0x0000541A -#define FIONREAD 0x0000541B -#define TIOCINQ 0x0000541B -#define TIOCLINUX 0x0000541C -#define TIOCCONS 0x0000541D -#define TIOCGSERIAL 0x0000541E -#define TIOCSSERIAL 0x0000541F -#define TIOCPKT 0x00005420 -#define FIONBIO 0x00005421 -#define TIOCNOTTY 0x00005422 -#define TIOCSETD 0x00005423 -#define TIOCGETD 0x00005424 -#define TCSBRKP 0x00005425 -#define TIOCTTYGSTRUCT 0x00005426 -#define FIONCLEX 0x00005450 -#define FIOCLEX 0x00005451 -#define FIOASYNC 0x00005452 -#define TIOCSERCONFIG 0x00005453 -#define TIOCSERGWILD 0x00005454 -#define TIOCSERSWILD 0x00005455 -#define TIOCGLCKTRMIOS 0x00005456 -#define TIOCSLCKTRMIOS 0x00005457 -#define TIOCSERGSTRUCT 0x00005458 -#define TIOCSERGETLSR 0x00005459 -#define TIOCSERGETMULTI 0x0000545A -#define TIOCSERSETMULTI 0x0000545B - - - -#endif diff --git a/plat/linuxppc/include/unistd.h b/plat/linuxppc/include/unistd.h deleted file mode 100644 index f57705365..000000000 --- a/plat/linuxppc/include/unistd.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ - -#ifndef _UNISTD_H -#define _UNISTD_H - -#include -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* File access. */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0x10, - O_TRUNC = 0x20, - O_APPEND = 0x40 -}; - -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int close(int d); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int fcntl(int fd, int op, ...); -extern int unlink(const char* path); - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* ptr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern int execve(const char *path, char *const argv[], char *const envp[]); - -/* Signal handling */ - -typedef int sig_atomic_t; - -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ - -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGABRT 6 /* Abort (ANSI). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGBUS 7 /* BUS error (4.2 BSD). */ -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */ -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGSTKFLT 16 /* Stack fault. */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGCHLD 17 /* Child status has changed (POSIX). */ -#define SIGCONT 18 /* Continue (POSIX). */ -#define SIGSTOP 19 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 20 /* Keyboard stop (POSIX). */ -#define SIGTTIN 21 /* Background read from tty (POSIX). */ -#define SIGTTOU 22 /* Background write to tty (POSIX). */ -#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */ -#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */ -#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */ -#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */ -#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ -#define SIGPOLL SIGIO /* Pollable event occurred (System V). */ -#define SIGIO 29 /* I/O now possible (4.2 BSD). */ -#define SIGPWR 30 /* Power failure restart (System V). */ -#define SIGSYS 31 /* Bad system call. */ -#define SIGUNUSED 31 - -#define _NSIG 32 /* Biggest signal number + 1 - (not including real-time signals). */ - -/* sigprocmask */ -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 -typedef unsigned long sigset_t; - -/* sa_flags */ -#define SA_NODEFER 0x40000000UL -#define SA_RESETHAND 0x80000000UL - -struct __siginfo; -struct sigaction { - union { - void (*__sa_handler)(int); - void (*__sa_sigaction)(int, struct __siginfo *, void *); - } __sigaction_u; - sigset_t sa_mask; - unsigned long sa_flags; - void (*sa_restorer)(void); -}; -#define sa_handler __sigaction_u.__sa_handler -#define sa_sigaction __sigaction_u.__sa_sigaction - -typedef void (*sighandler_t)(int); -extern int sigaction(int, const struct sigaction *, struct sigaction *); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int sigprocmask(int, const sigset_t *, sigset_t *); -extern int raise(int signum); - - - -#endif From 680b4071b743b1c167a01083bd399da7fac93ba6 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:55:59 +0200 Subject: [PATCH 23/37] Made the two OSX platforms work with the new libc layout. --- build.lua | 4 +- lang/cem/libcc.ansi/headers/sys/ioctl.h | 11 -- lang/cem/libcc.ansi/headers/unistd.h | 2 +- plat/linux/include/ack/signal.h | 2 - plat/osx/include/ack/fcntl.h | 13 +++ plat/osx/include/ack/plat.h | 3 + plat/osx/include/ack/signal.h | 60 +++++++++++ plat/osx/include/build.lua | 4 +- plat/osx/include/sys/ioctl.h | 8 ++ plat/osx/include/sys/types.h | 3 +- plat/osx/include/unistd.h | 137 ------------------------ 11 files changed, 92 insertions(+), 155 deletions(-) delete mode 100644 lang/cem/libcc.ansi/headers/sys/ioctl.h create mode 100644 plat/osx/include/ack/fcntl.h create mode 100644 plat/osx/include/ack/signal.h create mode 100644 plat/osx/include/sys/ioctl.h delete mode 100644 plat/osx/include/unistd.h diff --git a/build.lua b/build.lua index f182020b2..4019f22ce 100644 --- a/build.lua +++ b/build.lua @@ -10,8 +10,8 @@ vars.plats = { "linux386", "linux68k", "linuxppc", --- "osx386", --- "osxppc", + "osx386", + "osxppc", -- --"qemuppc", -- "pc86", -- "rpi", diff --git a/lang/cem/libcc.ansi/headers/sys/ioctl.h b/lang/cem/libcc.ansi/headers/sys/ioctl.h deleted file mode 100644 index 2823d4581..000000000 --- a/lang/cem/libcc.ansi/headers/sys/ioctl.h +++ /dev/null @@ -1,11 +0,0 @@ -/* $Source$ - * $State$ - * $Revision$ - */ - -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - -#include - -#endif diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index 8818fa66e..b088f9559 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -48,13 +48,13 @@ #define _NSIG 16 /* Biggest signal number + 1 (not including real-time signals). */ - typedef void (*sighandler_t)(int); typedef uint16_t sigset_t; struct sigaction; #else #include #endif +typedef void (*sighandler_t)(int); /* Time handling. */ diff --git a/plat/linux/include/ack/signal.h b/plat/linux/include/ack/signal.h index d7ec086b2..55c0f3a04 100644 --- a/plat/linux/include/ack/signal.h +++ b/plat/linux/include/ack/signal.h @@ -54,8 +54,6 @@ typedef int sig_atomic_t; #define SIG_SETMASK 2 typedef unsigned long sigset_t; -typedef void (*sighandler_t)(int); - /* sa_flags */ #define SA_NODEFER 0x40000000UL #define SA_RESETHAND 0x80000000UL diff --git a/plat/osx/include/ack/fcntl.h b/plat/osx/include/ack/fcntl.h new file mode 100644 index 000000000..aa07e30f2 --- /dev/null +++ b/plat/osx/include/ack/fcntl.h @@ -0,0 +1,13 @@ +#ifndef _ACK_FCNTL_H +#define _ACK_FCNTL_H + +#define O_RDONLY 0x0000 +#define O_WRONLY 0x0001 +#define O_RDWR 0x0002 +#define O_NONBLOCK 0x0004 +#define O_APPEND 0x0008 +#define O_CREAT 0x0200 +#define O_TRUNC 0x0400 +#define O_EXCL 0x0800 + +#endif diff --git a/plat/osx/include/ack/plat.h b/plat/osx/include/ack/plat.h index ba64a6d56..6d6baa515 100644 --- a/plat/osx/include/ack/plat.h +++ b/plat/osx/include/ack/plat.h @@ -11,4 +11,7 @@ /* #define ACKCONF_TIME_IS_A_SYSCALL */ +#define ACKCONF_WANT_STANDARD_O 0 +#define ACKCONF_WANT_STANDARD_SIGNALS 0 + #endif diff --git a/plat/osx/include/ack/signal.h b/plat/osx/include/ack/signal.h new file mode 100644 index 000000000..0eda97952 --- /dev/null +++ b/plat/osx/include/ack/signal.h @@ -0,0 +1,60 @@ +#ifndef _ACK_SIGNAL_H +#define _ACK_SIGNAL_H + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGEMT 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGBUS 10 +#define SIGSEGV 11 +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGIO 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGINFO 29 +#define SIGUSR1 30 +#define SIGUSR2 31 +#define _NSIG 32 + +/* sa_flags */ +#define SA_RESTART 0x0002 + +typedef void (*sig_t)(int); +#define SIG_DFL ((sig_t)0) +#define SIG_IGN ((sig_t)1) +#define SIG_ERR ((sig_t)-1) + +typedef unsigned int sigset_t; + +struct __siginfo; + +struct sigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, struct __siginfo *, void *); + } __sigaction_u; + sigset_t sa_mask; + int sa_flags; +}; +#define sa_handler __sigaction_u.__sa_handler +#define sa_sigaction __sigaction_u.__sa_sigaction + +#endif diff --git a/plat/osx/include/build.lua b/plat/osx/include/build.lua index 859a3730a..78ac3246f 100644 --- a/plat/osx/include/build.lua +++ b/plat/osx/include/build.lua @@ -9,11 +9,13 @@ local function addheader(h) end addheader("ack/plat.h") +addheader("ack/signal.h") +addheader("ack/fcntl.h") addheader("sys/dirent.h") addheader("sys/mman.h") addheader("sys/stat.h") addheader("sys/types.h") -addheader("unistd.h") +addheader("sys/ioctl.h") acklibrary { name = "headers", diff --git a/plat/osx/include/sys/ioctl.h b/plat/osx/include/sys/ioctl.h new file mode 100644 index 000000000..80d2b06c0 --- /dev/null +++ b/plat/osx/include/sys/ioctl.h @@ -0,0 +1,8 @@ +#ifndef _SYS_IOCTL_H +#define _SYS_IOCTL_H + +#define TIOCGETD 0x4004741a + +extern int ioctl(int fd, unsigned long request, ...); + +#endif diff --git a/plat/osx/include/sys/types.h b/plat/osx/include/sys/types.h index b4561b7b3..e1330271f 100644 --- a/plat/osx/include/sys/types.h +++ b/plat/osx/include/sys/types.h @@ -11,7 +11,8 @@ typedef unsigned int ino_t; typedef unsigned short mode_t; typedef unsigned short nlink_t; typedef int pid_t; -typedef ptrdiff_t ssize_t; typedef unsigned int uid_t; +typedef long time_t; +typedef int suseconds_t; #endif diff --git a/plat/osx/include/unistd.h b/plat/osx/include/unistd.h deleted file mode 100644 index bafa2a6c4..000000000 --- a/plat/osx/include/unistd.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _UNISTD_H -#define _UNISTD_H - -#include - -/* - * XXX - The following parts belong in other header files, - * but those headers are including us! - */ - -/* XXX - begin sys/ioctl.h */ - -#define TIOCGETD 0x4004741a - -int ioctl(int, unsigned long, ...); - -/* XXX - end sys/ioctl.h */ - -/* XXX - begin sys/time.h */ - -/* Don't conflict with time_t from */ -typedef long _libsys_time_t; -typedef int suseconds_t; - -struct timespec { - _libsys_time_t tv_sec; - long tv_nsec; -}; - -struct timeval { - _libsys_time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; - -int gettimeofday(struct timeval *, struct timezone *); - -/* XXX - end sys/time.h */ - -/* XXX - begin fcntl.h */ - -/* flags for open() */ -#define O_RDONLY 0x0000 -#define O_WRONLY 0x0001 -#define O_RDWR 0x0002 -#define O_NONBLOCK 0x0004 -#define O_APPEND 0x0008 -#define O_CREAT 0x0200 -#define O_TRUNC 0x0400 -#define O_EXCL 0x0800 - -int creat(const char *, mode_t); -int open(const char *, int, ...); - -/* XXX - end fcntl.h */ - -/* XXX - begin signal.h */ - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGEMT 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGBUS 10 -#define SIGSEGV 11 -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGIO 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGINFO 29 -#define SIGUSR1 30 -#define SIGUSR2 31 -#define _NSIG 32 - -/* sa_flags */ -#define SA_RESTART 0x0002 - -typedef void (*sig_t)(int); -#define SIG_DFL ((sig_t)0) -#define SIG_IGN ((sig_t)1) -#define SIG_ERR ((sig_t)-1) - -typedef unsigned int sigset_t; - -struct __siginfo; - -struct sigaction { - union { - void (*__sa_handler)(int); - void (*__sa_sigaction)(int, struct __siginfo *, void *); - } __sigaction_u; - sigset_t sa_mask; - int sa_flags; -}; -#define sa_handler __sigaction_u.__sa_handler -#define sa_sigaction __sigaction_u.__sa_sigaction - -int kill(pid_t, int); -int sigaction(int, const struct sigaction *, struct sigaction *); -sig_t signal(int, sig_t); - -int raise(int); /* in libc */ - -/* XXX - end signal.h */ - -void _exit(int); -int brk(void *); -int close(int); -pid_t getpid(void); -int isatty(int); -off_t lseek(int, off_t, int); -ssize_t read(int, void *, size_t); -void *sbrk(int); -ssize_t write(int, const void *, size_t); - -#endif From dbb2062d03264444ec6bc39d2872a8552ce961c1 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:59:40 +0200 Subject: [PATCH 24/37] Made pc86 work with the new libc. --- build.lua | 4 +- plat/pc86/include/build.lua | 2 +- plat/pc86/include/sys/types.h | 9 +++++ plat/pc86/include/unistd.h | 73 ----------------------------------- plat/pc86/libsys/read.c | 2 +- plat/pc86/libsys/write.c | 2 +- 6 files changed, 14 insertions(+), 78 deletions(-) create mode 100644 plat/pc86/include/sys/types.h delete mode 100644 plat/pc86/include/unistd.h diff --git a/build.lua b/build.lua index 4019f22ce..8a765c032 100644 --- a/build.lua +++ b/build.lua @@ -13,7 +13,7 @@ vars.plats = { "osx386", "osxppc", -- --"qemuppc", --- "pc86", + "pc86", -- "rpi", -- "pdpv7", -- "em22", @@ -23,7 +23,7 @@ vars.plats_with_tests = { "linux386", "linuxppc", -- --"qemuppc", --- "pc86", + "pc86", } local plat_packages = {} diff --git a/plat/pc86/include/build.lua b/plat/pc86/include/build.lua index cb504b837..3ae81836a 100644 --- a/plat/pc86/include/build.lua +++ b/plat/pc86/include/build.lua @@ -9,7 +9,7 @@ local function addheader(h) end addheader("ack/plat.h") -addheader("unistd.h") +addheader("sys/types.h") acklibrary { name = "headers", diff --git a/plat/pc86/include/sys/types.h b/plat/pc86/include/sys/types.h new file mode 100644 index 000000000..6a0c3d3db --- /dev/null +++ b/plat/pc86/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef int pid_t; +typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; + +#endif diff --git a/plat/pc86/include/unistd.h b/plat/pc86/include/unistd.h deleted file mode 100644 index 77bdcf10d..000000000 --- a/plat/pc86/include/unistd.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ - -#ifndef _UNISTD_H -#define _UNISTD_H - -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -/* Constants for file access (open and friends) */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* addr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int close(int d); -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern int unlink(const char* path); - -/* Unimplemented system calls (these are just prototypes to let the library - * compile). */ - -extern int fcntl(int fd, int op, ...); - -/* Signal handling */ - -typedef int sig_atomic_t; - -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ - -#define SIGABRT 6 /* Abort (ANSI) */ -#define SIGILL 11 /* Illegal instruction */ - -#define _NSIG 32 /* Biggest signal number + 1 - (not including real-time signals). */ -typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int raise(int signum); - -#endif diff --git a/plat/pc86/libsys/read.c b/plat/pc86/libsys/read.c index 968124784..c888660a4 100644 --- a/plat/pc86/libsys/read.c +++ b/plat/pc86/libsys/read.c @@ -8,7 +8,7 @@ #include #include "libsys.h" -int read(int fd, void* buffer, size_t count) +ssize_t read(int fd, void* buffer, size_t count) { char i; diff --git a/plat/pc86/libsys/write.c b/plat/pc86/libsys/write.c index 8d2dd0d74..064e5f487 100644 --- a/plat/pc86/libsys/write.c +++ b/plat/pc86/libsys/write.c @@ -19,7 +19,7 @@ void _sys_write_tty(char c) _sys_rawwrite('\r'); } -int write(int fd, void* buffer, size_t count) +ssize_t write(int fd, void* buffer, size_t count) { int i; char* p = buffer; From 3e40374297619108c5f10d0bcb20b23c397a54ff Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 13:05:27 +0200 Subject: [PATCH 25/37] Made the rpi platform work with the new libc layout. --- build.lua | 2 +- plat/rpi/include/build.lua | 2 +- plat/rpi/include/sys/select.h | 12 +++- plat/rpi/include/sys/types.h | 9 +++ plat/rpi/include/unistd.h | 107 ---------------------------------- plat/rpi/libsys/read.c | 2 +- plat/rpi/libsys/select.c | 1 + plat/rpi/libsys/write.c | 2 +- 8 files changed, 25 insertions(+), 112 deletions(-) create mode 100644 plat/rpi/include/sys/types.h delete mode 100644 plat/rpi/include/unistd.h diff --git a/build.lua b/build.lua index 8a765c032..09142dbd1 100644 --- a/build.lua +++ b/build.lua @@ -14,7 +14,7 @@ vars.plats = { "osxppc", -- --"qemuppc", "pc86", --- "rpi", + "rpi", -- "pdpv7", -- "em22", } diff --git a/plat/rpi/include/build.lua b/plat/rpi/include/build.lua index 105f05988..e568b6a5e 100644 --- a/plat/rpi/include/build.lua +++ b/plat/rpi/include/build.lua @@ -11,8 +11,8 @@ end addheader("ack/plat.h") addheader("pi.h") addheader("sys/select.h") +addheader("sys/types.h") addheader("termios.h") -addheader("unistd.h") acklibrary { name = "headers", diff --git a/plat/rpi/include/sys/select.h b/plat/rpi/include/sys/select.h index df7488da4..d126bbf10 100644 --- a/plat/rpi/include/sys/select.h +++ b/plat/rpi/include/sys/select.h @@ -8,6 +8,16 @@ #ifndef _SYS_SELECT_H #define _SYS_SELECT_H -#include +#include + +typedef uint32_t fd_set; + +extern int select(int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout); + +#define FD_ZERO(set) do { *set = 0; } while (0) +#define FD_SET(fd, set) do { *set |= (1< -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* Constants for file access (open and friends) */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern void* sbrk(int increment); -extern int isatty(int d); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int close(int d); -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern int unlink(const char* path); - -/* Unimplemented system calls (these are just prototypes to let the library - * compile). */ - -extern int fcntl(int fd, int op, ...); - -/* Signal handling */ - -typedef int sig_atomic_t; - -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ - -#define SIGABRT 6 /* Abort (ANSI) */ -#define SIGILL 11 /* Illegal instruction */ - -#define _NSIG 32 /* Biggest signal number + 1 - (not including real-time signals). */ -typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int raise(int signum); -extern int kill(pid_t pid, int sig); - -/* Select */ - -typedef uint32_t fd_set; - -extern int select(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout); - -#define FD_ZERO(set) do { *set = 0; } while (0) -#define FD_SET(fd, set) do { *set |= (1< #include "libsys.h" -int read(int fd, void* buffer, size_t count) +ssize_t read(int fd, void* buffer, size_t count) { char i; diff --git a/plat/rpi/libsys/select.c b/plat/rpi/libsys/select.c index 280bfd694..4ea87e76c 100644 --- a/plat/rpi/libsys/select.c +++ b/plat/rpi/libsys/select.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include "libsys.h" diff --git a/plat/rpi/libsys/write.c b/plat/rpi/libsys/write.c index 0fba49884..29cae0c38 100644 --- a/plat/rpi/libsys/write.c +++ b/plat/rpi/libsys/write.c @@ -20,7 +20,7 @@ void _sys_write_tty(char c) _sys_rawwrite('\r'); } -int write(int fd, void* buffer, size_t count) +ssize_t write(int fd, void* buffer, size_t count) { int i; char* p = buffer; From 74d166ef9aea04be49abb9fc5284d9e99cf6a6a9 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 15:18:26 +0200 Subject: [PATCH 26/37] Get the pdp7 plat working; remove the leading-underscore syscalls. --- build.lua | 2 +- plat/pdpv7/boot.s | 4 +- plat/pdpv7/include/build.lua | 2 +- plat/pdpv7/include/sys/select.h | 10 ++- plat/pdpv7/include/sys/types.h | 9 +++ plat/pdpv7/include/unistd.h | 106 -------------------------------- plat/pdpv7/libsys/_alarm.s | 12 ---- plat/pdpv7/libsys/_close.s | 14 ----- plat/pdpv7/libsys/_creat.s | 17 ----- plat/pdpv7/libsys/_dup.s | 20 ------ plat/pdpv7/libsys/_execl.s | 19 ------ plat/pdpv7/libsys/_fork.s | 15 ----- plat/pdpv7/libsys/_fstat.s | 19 ------ plat/pdpv7/libsys/_ftime.s | 12 ---- plat/pdpv7/libsys/_getpid.s | 6 -- plat/pdpv7/libsys/_gtty.c | 7 --- plat/pdpv7/libsys/_ioctl.s | 20 ------ plat/pdpv7/libsys/_kill.s | 20 ------ plat/pdpv7/libsys/_link.s | 19 ------ plat/pdpv7/libsys/_lseek.s | 20 ------ plat/pdpv7/libsys/_open.s | 17 ----- plat/pdpv7/libsys/_pause.s | 6 -- plat/pdpv7/libsys/_pipe.s | 18 ------ plat/pdpv7/libsys/_read.s | 18 ------ plat/pdpv7/libsys/_sbrk.s | 38 ------------ plat/pdpv7/libsys/_unlink.s | 18 ------ plat/pdpv7/libsys/_wait.s | 16 ----- plat/pdpv7/libsys/_write.s | 18 ------ 28 files changed, 22 insertions(+), 480 deletions(-) create mode 100644 plat/pdpv7/include/sys/types.h delete mode 100644 plat/pdpv7/include/unistd.h delete mode 100644 plat/pdpv7/libsys/_alarm.s delete mode 100644 plat/pdpv7/libsys/_close.s delete mode 100644 plat/pdpv7/libsys/_creat.s delete mode 100644 plat/pdpv7/libsys/_dup.s delete mode 100644 plat/pdpv7/libsys/_execl.s delete mode 100644 plat/pdpv7/libsys/_fork.s delete mode 100644 plat/pdpv7/libsys/_fstat.s delete mode 100644 plat/pdpv7/libsys/_ftime.s delete mode 100644 plat/pdpv7/libsys/_getpid.s delete mode 100644 plat/pdpv7/libsys/_gtty.c delete mode 100644 plat/pdpv7/libsys/_ioctl.s delete mode 100644 plat/pdpv7/libsys/_kill.s delete mode 100644 plat/pdpv7/libsys/_link.s delete mode 100644 plat/pdpv7/libsys/_lseek.s delete mode 100644 plat/pdpv7/libsys/_open.s delete mode 100644 plat/pdpv7/libsys/_pause.s delete mode 100644 plat/pdpv7/libsys/_pipe.s delete mode 100644 plat/pdpv7/libsys/_read.s delete mode 100644 plat/pdpv7/libsys/_sbrk.s delete mode 100644 plat/pdpv7/libsys/_unlink.s delete mode 100644 plat/pdpv7/libsys/_wait.s delete mode 100644 plat/pdpv7/libsys/_write.s diff --git a/build.lua b/build.lua index 09142dbd1..8175af520 100644 --- a/build.lua +++ b/build.lua @@ -15,7 +15,7 @@ vars.plats = { -- --"qemuppc", "pc86", "rpi", --- "pdpv7", + "pdpv7", -- "em22", } vars.plats_with_tests = { diff --git a/plat/pdpv7/boot.s b/plat/pdpv7/boot.s index a51c8d80b..a684fdb6a 100644 --- a/plat/pdpv7/boot.s +++ b/plat/pdpv7/boot.s @@ -51,9 +51,9 @@ EXIT: jsr pc,__exit sys 1 -WRITE: jmp __write +WRITE: jmp _write -BRK: jmp __brk +BRK: jmp _brk .sect .data hol0: .data2 0,0 ! line no diff --git a/plat/pdpv7/include/build.lua b/plat/pdpv7/include/build.lua index 70d9666c6..f785644b4 100644 --- a/plat/pdpv7/include/build.lua +++ b/plat/pdpv7/include/build.lua @@ -10,8 +10,8 @@ end addheader("ack/plat.h") addheader("sys/select.h") +addheader("sys/types.h") addheader("termios.h") -addheader("unistd.h") acklibrary { name = "headers", diff --git a/plat/pdpv7/include/sys/select.h b/plat/pdpv7/include/sys/select.h index 33525587f..f1841994f 100644 --- a/plat/pdpv7/include/sys/select.h +++ b/plat/pdpv7/include/sys/select.h @@ -8,6 +8,14 @@ #ifndef _SYS_SELECT_H #define _SYS_SELECT_H -#include +typedef uint32_t fd_set; + +extern int select(int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout); + +#define FD_ZERO(set) do { *set = 0; } while (0) +#define FD_SET(fd, set) do { *set |= (1< -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* Constants for file access (open and friends) */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern void* sbrk(int increment); -extern int isatty(int d); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int close(int d); -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern int unlink(const char* path); - -/* Unimplemented system calls (these are just prototypes to let the library - * compile). */ - -extern int fcntl(int fd, int op, ...); - -/* Signal handling */ - -typedef int sig_atomic_t; - -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ - -#define SIGABRT 6 /* Abort (ANSI) */ -#define SIGILL 11 /* Illegal instruction */ - -#define _NSIG 32 /* Biggest signal number + 1 - (not including real-time signals). */ -typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int raise(int signum); - -/* Select */ - -typedef uint32_t fd_set; - -extern int select(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout); - -#define FD_ZERO(set) do { *set = 0; } while (0) -#define FD_SET(fd, set) do { *set |= (1< Date: Sat, 23 Jun 2018 15:57:57 +0200 Subject: [PATCH 27/37] Get em22 working. Remove the leading-underscore system calls from its libsys. --- build.lua | 2 +- lang/cem/libcc.ansi/build.lua | 2 + lang/cem/libcc.ansi/headers/ack/config.h | 5 ++ lang/cem/libcc.ansi/headers/sys/times.h | 13 +++ lang/cem/libcc.ansi/headers/unistd.h | 2 + lang/cem/libcc.ansi/misc/getpass.c | 90 ++++++++++++------- lang/cem/libcc.ansi/misc/isatty.c | 13 ++- lang/cem/libcc.ansi/stdio/isatty.c | 17 ---- lang/cem/libcc.ansi/stdlib/system.c | 19 ++-- lang/cem/libcc.ansi/time/clock.c | 70 +-------------- lang/cem/libcc.ansi/time/misc.c | 51 ----------- plat/{em22 => em}/include/ack/plat.h | 2 + .../unistd.h => em/include/ack/signal.h} | 62 +------------ plat/em/include/build.lua | 27 ++++++ plat/{em22 => em}/include/sgtty.h | 0 plat/{em22 => em}/include/sys/timeb.h | 5 ++ plat/{em22 => em}/include/sys/types.h | 4 +- plat/em/libsys/_alarm.e | 9 -- plat/em/libsys/_brk.e | 54 ----------- plat/em/libsys/_close.e | 15 ---- plat/em/libsys/_creat.e | 14 --- plat/em/libsys/_dup.e | 14 --- plat/em/libsys/_dup2.e | 16 ---- plat/em/libsys/_execl.e | 15 ---- plat/em/libsys/_execve.e | 12 --- plat/em/libsys/_fork.e | 18 ---- plat/em/libsys/_fstat.e | 16 ---- plat/em/libsys/_ftime.e | 17 ---- plat/em/libsys/_getpid.e | 8 -- plat/em/libsys/_gtty.c | 6 -- plat/em/libsys/_ioctl.e | 16 ---- plat/em/libsys/_kill.e | 15 ---- plat/em/libsys/_link.e | 16 ---- plat/em/libsys/_lseek.e | 33 ------- plat/em/libsys/_open.e | 14 --- plat/em/libsys/_pause.e | 8 -- plat/em/libsys/_pipe.e | 18 ---- plat/em/libsys/_read.e | 23 ----- plat/em/libsys/_sbrk.e | 60 ------------- plat/em/libsys/_stty.c | 6 -- plat/em/libsys/_times.e | 10 --- plat/em/libsys/_unlink.e | 16 ---- plat/em/libsys/_wait.e | 33 ------- plat/em/libsys/_write.e | 23 ----- plat/em22/descr | 2 +- plat/em22/include/build.lua | 25 +----- 46 files changed, 140 insertions(+), 776 deletions(-) create mode 100644 lang/cem/libcc.ansi/headers/sys/times.h delete mode 100644 lang/cem/libcc.ansi/stdio/isatty.c rename plat/{em22 => em}/include/ack/plat.h (66%) rename plat/{em22/include/unistd.h => em/include/ack/signal.h} (51%) create mode 100644 plat/em/include/build.lua rename plat/{em22 => em}/include/sgtty.h (100%) rename plat/{em22 => em}/include/sys/timeb.h (83%) rename plat/{em22 => em}/include/sys/types.h (86%) delete mode 100644 plat/em/libsys/_alarm.e delete mode 100644 plat/em/libsys/_brk.e delete mode 100644 plat/em/libsys/_close.e delete mode 100644 plat/em/libsys/_creat.e delete mode 100644 plat/em/libsys/_dup.e delete mode 100644 plat/em/libsys/_dup2.e delete mode 100644 plat/em/libsys/_execl.e delete mode 100644 plat/em/libsys/_execve.e delete mode 100644 plat/em/libsys/_fork.e delete mode 100644 plat/em/libsys/_fstat.e delete mode 100644 plat/em/libsys/_ftime.e delete mode 100644 plat/em/libsys/_getpid.e delete mode 100644 plat/em/libsys/_gtty.c delete mode 100644 plat/em/libsys/_ioctl.e delete mode 100644 plat/em/libsys/_kill.e delete mode 100644 plat/em/libsys/_link.e delete mode 100644 plat/em/libsys/_lseek.e delete mode 100644 plat/em/libsys/_open.e delete mode 100644 plat/em/libsys/_pause.e delete mode 100644 plat/em/libsys/_pipe.e delete mode 100644 plat/em/libsys/_read.e delete mode 100644 plat/em/libsys/_sbrk.e delete mode 100644 plat/em/libsys/_stty.c delete mode 100644 plat/em/libsys/_times.e delete mode 100644 plat/em/libsys/_unlink.e delete mode 100644 plat/em/libsys/_wait.e delete mode 100644 plat/em/libsys/_write.e diff --git a/build.lua b/build.lua index 8175af520..9bce99f90 100644 --- a/build.lua +++ b/build.lua @@ -16,7 +16,7 @@ vars.plats = { "pc86", "rpi", "pdpv7", --- "em22", + "em22", } vars.plats_with_tests = { "linux68k", diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index d5e33a6e2..4c89867af 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -50,6 +50,8 @@ for _, plat in ipairs(vars.plats) do "./stdlib/*.c", "./string/*.c", "./time/*.c", + "./misc/getpass.c", + "./misc/isatty.c", }, hdrs = {}, -- must be empty deps = { diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index 84174a11d..ae397dbfe 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -19,4 +19,9 @@ #define ACKCONF_WANT_STANDARD_SIGNALS 1 #endif +#ifndef ACKCONF_WANT_TERMIOS +/* Don't compile termios-using functions unless the plat explicitly asks for it. */ +#define ACKCONF_WANT_TERMIOS 0 +#endif + #endif diff --git a/lang/cem/libcc.ansi/headers/sys/times.h b/lang/cem/libcc.ansi/headers/sys/times.h new file mode 100644 index 000000000..8311a807d --- /dev/null +++ b/lang/cem/libcc.ansi/headers/sys/times.h @@ -0,0 +1,13 @@ +#ifndef _SYS_TIMES_H +#define _SYS_TIMES_H + +struct tms { + clock_t tms_utime; /* user time */ + clock_t tms_stime; /* system time */ + clock_t tms_cutime; /* user time of children */ + clock_t tms_cstime; /* system time of children */ +}; + +extern clock_t times(struct tms* buf); + +#endif diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index b088f9559..ef3b81689 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -92,7 +92,9 @@ extern int sigaction(int, const struct sigaction *, struct sigaction *); extern int sigprocmask(int, const sigset_t *, sigset_t *); extern int unlink(const char* path); extern off_t lseek(int fildes, off_t offset, int whence); +extern pid_t fork(void); extern pid_t getpid(void); +extern pid_t wait(int* wstatus); extern sighandler_t signal(int signum, sighandler_t handler); extern ssize_t read(int fd, void* buffer, size_t count); extern ssize_t write(int fd, void* buffer, size_t count); diff --git a/lang/cem/libcc.ansi/misc/getpass.c b/lang/cem/libcc.ansi/misc/getpass.c index 4b21512ee..a24c65dfd 100644 --- a/lang/cem/libcc.ansi/misc/getpass.c +++ b/lang/cem/libcc.ansi/misc/getpass.c @@ -6,41 +6,67 @@ #include #include #include -#include #include -int _open(const char* path, int flags); -int _write(int d, const char* buf, int nbytes); -int _read(int d, char* buf, int nbytes); -int _close(int d); +#if ACKCONF_WANT_TERMIOS -int _stty(int, struct sgttyb*); -int _gtty(int, struct sgttyb*); +#include +static int intr; -char* getpass(const char* prompt) +static void catch(int sig) { - int i = 0; - struct sgttyb tty, ttysave; - static char pwdbuf[9]; - int fd; - void (*savesig)(int); - - if ((fd = _open("/dev/tty", O_RDONLY)) < 0) - fd = 0; - savesig = signal(SIGINT, SIG_IGN); - _write(2, prompt, strlen(prompt)); - _gtty(fd, &tty); - ttysave = tty; - tty.sg_flags &= ~ECHO; - _stty(fd, &tty); - i = _read(fd, pwdbuf, 9); - while (pwdbuf[i - 1] != '\n') - _read(fd, &pwdbuf[i - 1], 1); - pwdbuf[i - 1] = '\0'; - _stty(fd, &ttysave); - _write(2, "\n", 1); - if (fd != 0) - _close(fd); - signal(SIGINT, savesig); - return (pwdbuf); + intr= 1; } + +char *getpass(const char *prompt) +{ + struct sigaction osa, sa; + struct termios cooked, raw; + static char password[32+1]; + int fd, n= 0; + + /* Try to open the controlling terminal. */ + if ((fd= open("/dev/tty", O_RDONLY)) < 0) return NULL; + + /* Trap interrupts unless ignored. */ + intr= 0; + sigaction(SIGINT, NULL, &osa); + if (osa.sa_handler != SIG_IGN) { + sigemptyset(&sa.sa_mask); + sa.sa_flags= 0; + sa.sa_handler= catch; + sigaction(SIGINT, &sa, &osa); + } + + /* Set the terminal to non-echo mode. */ + tcgetattr(fd, &cooked); + raw= cooked; + raw.c_iflag|= ICRNL; + raw.c_lflag&= ~ECHO; + raw.c_lflag|= ECHONL; + raw.c_oflag|= OPOST | ONLCR; + tcsetattr(fd, TCSANOW, &raw); + + /* Print the prompt. (After setting non-echo!) */ + write(2, prompt, strlen(prompt)); + + /* Read the password, 32 characters max. */ + while (read(fd, password+n, 1) > 0) { + if (password[n] == '\n') break; + if (n < 32) n++; + } + password[n]= 0; + + /* Terminal back to cooked mode. */ + tcsetattr(fd, TCSANOW, &cooked); + + close(fd); + + /* Interrupt? */ + sigaction(SIGINT, &osa, NULL); + if (intr) raise(SIGINT); + + return password; +} + +#endif diff --git a/lang/cem/libcc.ansi/misc/isatty.c b/lang/cem/libcc.ansi/misc/isatty.c index cda06f4dc..a2d3f78e2 100644 --- a/lang/cem/libcc.ansi/misc/isatty.c +++ b/lang/cem/libcc.ansi/misc/isatty.c @@ -3,9 +3,16 @@ */ /* $Id$ */ -int _isatty(int d); +#include -int isatty(int d) +#if ACKCONF_WANT_TERMIOS + +#include +int isatty(int fd) { - return _isatty(d); + struct termios dummy; + + return(tcgetattr(fd, &dummy) == 0); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/isatty.c b/lang/cem/libcc.ansi/stdio/isatty.c deleted file mode 100644 index 97d7ca442..000000000 --- a/lang/cem/libcc.ansi/stdio/isatty.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * _isatty - check if a file descriptor is associated with a terminal - */ -/* $Id$ */ - -int _gtty(int d, char* buf); - -int _isatty(int d) -{ - char buf[128]; - /* not a sgttyb struct; it might not be large enough; - I know for a fact that it isn't large enough on PC/IX, - where gtty is an ioctl(..., TCGETA, ...) - */ - - return _gtty(d, buf) >= 0; -} diff --git a/lang/cem/libcc.ansi/stdlib/system.c b/lang/cem/libcc.ansi/stdlib/system.c index ba31b0477..49dba6318 100644 --- a/lang/cem/libcc.ansi/stdlib/system.c +++ b/lang/cem/libcc.ansi/stdlib/system.c @@ -4,19 +4,10 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) #include -#endif #include #include - -extern char** environ; - -extern int _fork(void); -extern int _wait(int*); -extern void _exit(int); -extern void _execve(const char* path, const char** argv, const char** envp); -extern void _close(int); +#include #define FAIL 127 @@ -32,21 +23,21 @@ int system(const char* str) int pid, exitstatus, waitval; int i; - if ((pid = _fork()) < 0) + if ((pid = fork()) < 0) return str ? -1 : 0; if (pid == 0) { for (i = 3; i <= 20; i++) - _close(i); + close(i); if (!str) str = "cd ."; /* just testing for a shell */ exec_tab[2] = str; /* fill in command */ - _execve("/bin/sh", exec_tab, (char const**)environ); + execve("/bin/sh", (char* const*)exec_tab, (char* const*)environ); /* get here if execve fails ... */ _exit(FAIL); /* see manual page */ } - while ((waitval = _wait(&exitstatus)) != pid) + while ((waitval = wait(&exitstatus)) != pid) { if (waitval == -1) break; diff --git a/lang/cem/libcc.ansi/time/clock.c b/lang/cem/libcc.ansi/time/clock.c index e5d25779f..f41e12dd4 100644 --- a/lang/cem/libcc.ansi/time/clock.c +++ b/lang/cem/libcc.ansi/time/clock.c @@ -4,80 +4,14 @@ /* $Id$ */ #include - -#if defined(__BSD4_2) - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN -1 - -struct rusage -{ - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ -}; - -void _getrusage(int who, struct rusage* rusage); - -#elif defined(_POSIX_SOURCE) || defined(__USG) - -struct tms -{ - time_t tms_utime; /* user time */ - time_t tms_stime; /* system time */ - time_t tms_cutime; /* user time, children */ - time_t tms_cstime; /* system time, children */ -}; - -long _times(struct tms* buffer); - -#else /* Version 7 UNIX */ - -struct tbuffer -{ - long proc_user_time; - long proc_system_time; - long child_user_time; - long child_system_time; -}; - -long _times(struct tbuffer* buffer); - -#endif +#include clock_t clock(void) { -#if defined(__BSD4_2) - struct rusage rusage; - - _getrusage(RUSAGE_SELF, &rusage); - - return (((unsigned long)rusage.ru_utime.tv_sec * CLOCKS_PER_SEC) - + rusage.ru_utime.tv_usec); -#elif defined(_POSIX_SOURCE) || defined(__USG) struct tms tms; - _times(&tms); + times(&tms); /* Assume that time_t can be converted to clock_t for Sys5 */ return tms.tms_utime; -#else - struct tbuffer tbuffer; - - _times(&tbuffer); - return tbuffer.proc_user_time; -#endif } diff --git a/lang/cem/libcc.ansi/time/misc.c b/lang/cem/libcc.ansi/time/misc.c index 8a21fb561..6a182307f 100644 --- a/lang/cem/libcc.ansi/time/misc.c +++ b/lang/cem/libcc.ansi/time/misc.c @@ -8,23 +8,6 @@ #include #include -#if defined(__BSD4_2) - -extern int _gettimeofday(struct timeval* tp, struct timezone* tzp); - -#elif !defined(_POSIX_SOURCE) && !defined(__USG) -#if !defined(_MINIX) /* MINIX has no ftime() */ -struct timeb -{ - long time; - unsigned short millitm; - short timezone; - short dstflag; -}; -void _ftime(struct timeb* bp); -#endif -#endif - #include "loc_time.h" #define RULE_LEN 120 @@ -42,15 +25,8 @@ long _dst_off = 60 * 60; int _daylight = 0; char* _tzname[2] = { ntstr, dststr }; -#if defined(__USG) || defined(_POSIX_SOURCE) char* tzname[2] = { ntstr, dststr }; -#if defined(__USG) -long timezone = 0; -int daylight = 0; -#endif -#endif - static struct dsttype { char ds_type; /* Unknown, Julian, Zero-based or M */ @@ -427,37 +403,10 @@ parseTZ(const char* p) void _tzset(void) { -#if defined(__BSD4_2) - - struct timeval tv; - struct timezone tz; - - _gettimeofday(&tv, &tz); - _daylight = tz.tz_dsttime; - _timezone = tz.tz_minuteswest * 60L; - -#elif !defined(_POSIX_SOURCE) && !defined(__USG) - -#if !defined(_MINIX) /* MINIX has no ftime() */ - struct timeb tim; - - _ftime(&tim); - _timezone = tim.timezone * 60L; - _daylight = tim.dstflag; -#endif - -#endif /* !_POSIX_SOURCE && !__USG */ - parseTZ(getenv("TZ")); /* should go inside #if */ -#if defined(__USG) || defined(_POSIX_SOURCE) tzname[0] = _tzname[0]; tzname[1] = _tzname[1]; -#if defined(__USG) - timezone = _timezone; - daylight = _daylight; -#endif -#endif /* __USG || _POSIX_SOURCE */ } static int diff --git a/plat/em22/include/ack/plat.h b/plat/em/include/ack/plat.h similarity index 66% rename from plat/em22/include/ack/plat.h rename to plat/em/include/ack/plat.h index 87be3d0ec..585a6abf7 100644 --- a/plat/em22/include/ack/plat.h +++ b/plat/em/include/ack/plat.h @@ -3,4 +3,6 @@ #define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_STANDARD_SIGNALS 0 + #endif diff --git a/plat/em22/include/unistd.h b/plat/em/include/ack/signal.h similarity index 51% rename from plat/em22/include/unistd.h rename to plat/em/include/ack/signal.h index 7b455738f..6b8edd85d 100644 --- a/plat/em22/include/unistd.h +++ b/plat/em/include/ack/signal.h @@ -1,59 +1,9 @@ -/* - * unistd.h - standard system calls - */ - -#ifndef _UNISTD_H -#define _UNISTD_H - -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -/* Constants for file access (open and friends) */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* addr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int close(int d); -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); - -/* Unimplemented system calls (these are just prototypes to let the library - * compile). */ - -extern int fcntl(int fd, int op, ...); - -/* Signal handling */ +#ifndef _ACK_SIGNAL_H +#define _ACK_SIGNAL_H typedef int sig_atomic_t; +struct sigaction; +typedef unsigned short sigset_t; #define SIG_ERR ((sighandler_t) -1) /* Error return. */ #define SIG_DFL ((sighandler_t) 0) /* Default action. */ @@ -78,8 +28,4 @@ typedef int sig_atomic_t; #define SIGALRM 14 /* alarm clock */ #define SIGTERM 15 /* software termination signal from kill */ -typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int raise(int signum); - #endif diff --git a/plat/em/include/build.lua b/plat/em/include/build.lua new file mode 100644 index 000000000..b59e64dea --- /dev/null +++ b/plat/em/include/build.lua @@ -0,0 +1,27 @@ +include("plat/build.lua") + +headermap = {} +packagemap = {} + +local function addheader(h) + headermap[h] = "./"..h + packagemap["$(PLATIND)/em/include/"..h] = "./"..h +end + +addheader("ack/plat.h") +addheader("sys/types.h") +addheader("sys/timeb.h") +addheader("ack/signal.h") +addheader("sgtty.h") + +acklibrary { + name = "headers", + hdrs = headermap +} + +installable { + name = "pkg", + map = packagemap +} + + diff --git a/plat/em22/include/sgtty.h b/plat/em/include/sgtty.h similarity index 100% rename from plat/em22/include/sgtty.h rename to plat/em/include/sgtty.h diff --git a/plat/em22/include/sys/timeb.h b/plat/em/include/sys/timeb.h similarity index 83% rename from plat/em22/include/sys/timeb.h rename to plat/em/include/sys/timeb.h index 92f48ed9d..5a8286a69 100644 --- a/plat/em22/include/sys/timeb.h +++ b/plat/em/include/sys/timeb.h @@ -3,9 +3,14 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#ifndef _SYS_TIMEB_H +#define _SYS_TIMEB_H + struct timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; + +#endif diff --git a/plat/em22/include/sys/types.h b/plat/em/include/sys/types.h similarity index 86% rename from plat/em22/include/sys/types.h rename to plat/em/include/sys/types.h index 8d431b051..e1330271f 100644 --- a/plat/em22/include/sys/types.h +++ b/plat/em/include/sys/types.h @@ -11,8 +11,8 @@ typedef unsigned int ino_t; typedef unsigned short mode_t; typedef unsigned short nlink_t; typedef int pid_t; -typedef ptrdiff_t ssize_t; typedef unsigned int uid_t; -typedef unsigned long time_t; +typedef long time_t; +typedef int suseconds_t; #endif diff --git a/plat/em/libsys/_alarm.e b/plat/em/libsys/_alarm.e deleted file mode 100644 index dc530b2bd..000000000 --- a/plat/em/libsys/_alarm.e +++ /dev/null @@ -1,9 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_alarm - pro $_alarm,0 - lol 0 - loc 27 - mon - ret EM_WSIZE - end diff --git a/plat/em/libsys/_brk.e b/plat/em/libsys/_brk.e deleted file mode 100644 index d7dd6e470..000000000 --- a/plat/em/libsys/_brk.e +++ /dev/null @@ -1,54 +0,0 @@ -# -#include - - mes 2,EM_WSIZE,EM_PSIZE - -.1 - bss EM_PSIZE,0,0 -.2 - bss EM_WSIZE,0,0 - - pro $ctch,0 - lol 0 - loc EHEAP - beq *1 - lae .1 - loi EM_PSIZE - sig - asp EM_PSIZE - lol 0 - trp - rtt -1 - loc 1 - ste .2 - rtt - end - - - exp $_brk - pro $_brk,0 - lpi $ctch - sig - lae .1 - sti EM_PSIZE - loc 0 - ste .2 - lal 0 - loi EM_PSIZE - str 2 ; The - possibly - occurring trap is caught - lae .1 - loi EM_PSIZE - sig - asp EM_PSIZE - loe .2 - zgt *1 - zer EM_PSIZE - ret EM_PSIZE -1 - loc -1 - loc EM_WSIZE - loc EM_PSIZE - cii - ret EM_PSIZE - end diff --git a/plat/em/libsys/_close.e b/plat/em/libsys/_close.e deleted file mode 100644 index e22c98245..000000000 --- a/plat/em/libsys/_close.e +++ /dev/null @@ -1,15 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_close - pro $_close,0 - lol 0 - loc 6 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_creat.e b/plat/em/libsys/_creat.e deleted file mode 100644 index 0d883dd78..000000000 --- a/plat/em/libsys/_creat.e +++ /dev/null @@ -1,14 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_creat - pro $_creat,0 - lal 0 - loi EM_WSIZE+EM_PSIZE - loc 8 - mon - zeq *1 - ste errno ; since e==r0 - loc -1 -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_dup.e b/plat/em/libsys/_dup.e deleted file mode 100644 index 9d117000a..000000000 --- a/plat/em/libsys/_dup.e +++ /dev/null @@ -1,14 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_dup - pro $_dup,0 - lol 0 - dup EM_WSIZE - loc 41 - mon - zeq *1 - ste errno - loc -1 -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_dup2.e b/plat/em/libsys/_dup2.e deleted file mode 100644 index 719e3a158..000000000 --- a/plat/em/libsys/_dup2.e +++ /dev/null @@ -1,16 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_dup2 - pro $_dup2,0 - lal 0 - loi 2*EM_WSIZE - loc 64 - ior EM_WSIZE - loc 41 - mon - zeq *1 - ste errno - loc -1 -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_execl.e b/plat/em/libsys/_execl.e deleted file mode 100644 index 3ce7ed5c8..000000000 --- a/plat/em/libsys/_execl.e +++ /dev/null @@ -1,15 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_execl - pro $_execl,0 - lae environ - loi EM_PSIZE - lal EM_PSIZE - lal 0 - loi EM_PSIZE - loc 59 - mon - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_execve.e b/plat/em/libsys/_execve.e deleted file mode 100644 index 023a5b8ba..000000000 --- a/plat/em/libsys/_execve.e +++ /dev/null @@ -1,12 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_execve - pro $_execve,0 - lal 0 - loi 3*EM_PSIZE - loc 59 - mon - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_fork.e b/plat/em/libsys/_fork.e deleted file mode 100644 index 610414009..000000000 --- a/plat/em/libsys/_fork.e +++ /dev/null @@ -1,18 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - - exp $_fork - pro $_fork,0 - loc 2 - mon - zeq *1 - ste errno - loc -1 - ret EM_WSIZE -1 - zeq *2 - asp EM_WSIZE - loc 0 -2 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_fstat.e b/plat/em/libsys/_fstat.e deleted file mode 100644 index 336e1c833..000000000 --- a/plat/em/libsys/_fstat.e +++ /dev/null @@ -1,16 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_fstat - pro $_fstat,0 - lal 0 - loi EM_WSIZE+EM_PSIZE - loc 28 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_ftime.e b/plat/em/libsys/_ftime.e deleted file mode 100644 index 46190b6b3..000000000 --- a/plat/em/libsys/_ftime.e +++ /dev/null @@ -1,17 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_ftime - pro $_ftime,0 - lal 0 - loi EM_PSIZE - loc 35 - mon - zne *1 - loc 0 - bra *2 -1 - ste errno - loc -1 -2 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_getpid.e b/plat/em/libsys/_getpid.e deleted file mode 100644 index c4527b9c6..000000000 --- a/plat/em/libsys/_getpid.e +++ /dev/null @@ -1,8 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_getpid - pro $_getpid,0 - loc 20 - mon - ret EM_WSIZE - end diff --git a/plat/em/libsys/_gtty.c b/plat/em/libsys/_gtty.c deleted file mode 100644 index 7b7cf08c2..000000000 --- a/plat/em/libsys/_gtty.c +++ /dev/null @@ -1,6 +0,0 @@ -/* $Id$ */ -#include -int -_gtty(fildes,argp) int fildes ; struct sgttyb *argp ; { - return _ioctl(fildes,TIOCGETP,argp) ; -} diff --git a/plat/em/libsys/_ioctl.e b/plat/em/libsys/_ioctl.e deleted file mode 100644 index ce4126269..000000000 --- a/plat/em/libsys/_ioctl.e +++ /dev/null @@ -1,16 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_ioctl - pro $_ioctl,0 - lal 0 - loi EM_PSIZE+2*EM_WSIZE - loc 54 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_kill.e b/plat/em/libsys/_kill.e deleted file mode 100644 index fed5ec776..000000000 --- a/plat/em/libsys/_kill.e +++ /dev/null @@ -1,15 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_kill - pro $_kill,0 - ldl 0 - loc 37 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_link.e b/plat/em/libsys/_link.e deleted file mode 100644 index 21d3a86bc..000000000 --- a/plat/em/libsys/_link.e +++ /dev/null @@ -1,16 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_link - pro $_link,0 - lal 0 - loi 2*EM_PSIZE - loc 9 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_lseek.e b/plat/em/libsys/_lseek.e deleted file mode 100644 index a2b160a9b..000000000 --- a/plat/em/libsys/_lseek.e +++ /dev/null @@ -1,33 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_lseek - pro $_lseek,0 - lal 0 - loi 4*EM_WSIZE - loc 19 - mon - zeq *1 - ste errno -#if EM_WSIZE==1 - ldc -1 - loc 2 - loc 4 - cii -#endif -#if EM_WSIZE==2 - ldc -1 -#endif -#if EM_WSIZE==4 - loc -1 -#endif -1 -#if EM_WSIZE==1 - ret 4*EM_WSIZE -#endif -#if EM_WSIZE==2 - ret 2*EM_WSIZE -#endif -#if EM_WSIZE==4 - ret EM_WSIZE -#endif - end diff --git a/plat/em/libsys/_open.e b/plat/em/libsys/_open.e deleted file mode 100644 index 0f3d511fc..000000000 --- a/plat/em/libsys/_open.e +++ /dev/null @@ -1,14 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_open - pro $_open,0 - lal 0 - loi EM_WSIZE+EM_PSIZE - loc 5 - mon - zeq *1 - ste errno - loc -1 -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_pause.e b/plat/em/libsys/_pause.e deleted file mode 100644 index 81a9cabf1..000000000 --- a/plat/em/libsys/_pause.e +++ /dev/null @@ -1,8 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_pause - pro $_pause,0 - loc 29 - mon - ret 0 - end diff --git a/plat/em/libsys/_pipe.e b/plat/em/libsys/_pipe.e deleted file mode 100644 index faed4f683..000000000 --- a/plat/em/libsys/_pipe.e +++ /dev/null @@ -1,18 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_pipe - pro $_pipe,0 - loc 42 - mon - zeq *1 - ste errno - loc -1 - ret EM_WSIZE -1 - lal 0 - loi EM_PSIZE - stf EM_WSIZE - sil 0 - loc 0 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_read.e b/plat/em/libsys/_read.e deleted file mode 100644 index 0c47d271f..000000000 --- a/plat/em/libsys/_read.e +++ /dev/null @@ -1,23 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_read - pro $_read,0 - lol EM_WSIZE+EM_PSIZE - loc EM_WSIZE - loc EM_PSIZE - ciu - lal 0 - loi EM_WSIZE+EM_PSIZE - loc 3 - mon - zne *1 - loc EM_PSIZE - loc EM_WSIZE - cui - bra *2 -1 - ste errno - loc -1 -2 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_sbrk.e b/plat/em/libsys/_sbrk.e deleted file mode 100644 index cd59228f1..000000000 --- a/plat/em/libsys/_sbrk.e +++ /dev/null @@ -1,60 +0,0 @@ -# -#include - - mes 2,EM_WSIZE,EM_PSIZE - -.1 - bss EM_PSIZE,0,0 -.2 - bss EM_WSIZE,0,0 - - pro $ctch,0 - lol 0 - loc EHEAP - beq *1 - lae .1 - loi EM_PSIZE - sig - asp EM_PSIZE - lol 0 - trp - rtt -1 - loc 1 - ste .2 - rtt - end - - - exp $_sbrk - pro $_sbrk,0 - lor 2 - lor 2 - lpi $ctch - sig - lae .1 - sti EM_PSIZE - loc 0 - ste .2 - lol 0 - ads EM_WSIZE ; this is the new heap pointer, but watch out for overflow! - dup EM_PSIZE - lor 2 - cmp ; compare with old heap pointer - zlt *1 - str 2 ; The - possibly - occurring trap is caught - lae .1 - loi EM_PSIZE - sig - asp EM_PSIZE - loe .2 - zgt *1 - ret EM_PSIZE -1 - asp EM_PSIZE - loc -1 - loc EM_WSIZE - loc EM_PSIZE - cii - ret EM_PSIZE - end diff --git a/plat/em/libsys/_stty.c b/plat/em/libsys/_stty.c deleted file mode 100644 index b5d1f9a6f..000000000 --- a/plat/em/libsys/_stty.c +++ /dev/null @@ -1,6 +0,0 @@ -/* $Id$ */ -#include -int -_stty(fildes,argp) int fildes ; struct sgttyb *argp ; { - return _ioctl(fildes,TIOCSETP,argp) ; -} diff --git a/plat/em/libsys/_times.e b/plat/em/libsys/_times.e deleted file mode 100644 index a94fa4f45..000000000 --- a/plat/em/libsys/_times.e +++ /dev/null @@ -1,10 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_times - pro $_times,0 - lal 0 - loi EM_PSIZE - loc 43 - mon - ret 0 - end diff --git a/plat/em/libsys/_unlink.e b/plat/em/libsys/_unlink.e deleted file mode 100644 index 7a72b3e02..000000000 --- a/plat/em/libsys/_unlink.e +++ /dev/null @@ -1,16 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_unlink - pro $_unlink,0 - lal 0 - loi EM_PSIZE - loc 10 - mon - zne *1 - loc 0 - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_wait.e b/plat/em/libsys/_wait.e deleted file mode 100644 index 3ed01f040..000000000 --- a/plat/em/libsys/_wait.e +++ /dev/null @@ -1,33 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE -#if EM_WSIZE<4 -#define STATUS_SIZE 2 -#else -#define STATUS_SIZE EM_WSIZE -#endif - exp $_wait - pro $_wait,0 - loc 7 - mon - zne *1 - lal 0 - loi EM_PSIZE - zer EM_PSIZE - cms EM_PSIZE - zeq *2 -#if EM_WSIZE==1 - lal 0 - loi EM_PSIZE - sti 2 ; 2 bytes, not one int! -#else - sil 0 -#endif - ret EM_WSIZE -2 - asp STATUS_SIZE - ret EM_WSIZE -1 - ste errno - loc -1 - ret EM_WSIZE - end diff --git a/plat/em/libsys/_write.e b/plat/em/libsys/_write.e deleted file mode 100644 index f83775d60..000000000 --- a/plat/em/libsys/_write.e +++ /dev/null @@ -1,23 +0,0 @@ -# - mes 2,EM_WSIZE,EM_PSIZE - exp $_write - pro $_write,0 - lol EM_WSIZE+EM_PSIZE - loc EM_WSIZE - loc EM_PSIZE - ciu - lal 0 - loi EM_WSIZE+EM_PSIZE - loc 4 - mon - zne *1 - loc EM_PSIZE - loc EM_WSIZE - cui - bra *2 -1 - ste errno - loc -1 -2 - ret EM_WSIZE - end diff --git a/plat/em22/descr b/plat/em22/descr index 27e0c0f6c..c8610ddaf 100644 --- a/plat/em22/descr +++ b/plat/em22/descr @@ -24,7 +24,7 @@ var SIZE_FLAG=-sx # Override the setting in fe so that files compiled for this platform can see # the platform-specific headers. -var C_INCLUDES=-I{PLATFORMDIR}/include -I{EM}/share/ack/include/ansi +var C_INCLUDES=-I{EM}/share/ack/em/include -I{EM}/share/ack/include/ansi name asld from .k.m.a.g diff --git a/plat/em22/include/build.lua b/plat/em22/include/build.lua index ab7564b5c..0a2c69de1 100644 --- a/plat/em22/include/build.lua +++ b/plat/em22/include/build.lua @@ -1,27 +1,4 @@ -include("plat/build.lua") - -headermap = {} -packagemap = {} - -local function addheader(h) - headermap[h] = "./"..h - packagemap["$(PLATIND)/em22/include/"..h] = "./"..h -end - -addheader("ack/plat.h") -addheader("sys/types.h") -addheader("sys/timeb.h") -addheader("unistd.h") -addheader("sgtty.h") - -acklibrary { - name = "headers", - hdrs = headermap -} - installable { name = "pkg", - map = packagemap + map = { "plat/em/include+pkg" } } - - From c4e4505a730f81de65df6a7b91fada15c6e42898 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 17:52:15 +0200 Subject: [PATCH 28/37] Move the errno functions into core. --- lang/cem/libcc.ansi/build.lua | 1 + lang/cem/libcc.ansi/{ => core}/errno/errlist.c | 0 lang/cem/libcc.ansi/{ => core}/errno/strerror.c | 0 lang/cem/libcc.ansi/errno/LIST | 1 - lang/cem/libcc.ansi/errno/Makefile | 2 -- 5 files changed, 1 insertion(+), 3 deletions(-) rename lang/cem/libcc.ansi/{ => core}/errno/errlist.c (100%) rename lang/cem/libcc.ansi/{ => core}/errno/strerror.c (100%) delete mode 100644 lang/cem/libcc.ansi/errno/LIST delete mode 100644 lang/cem/libcc.ansi/errno/Makefile diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 4c89867af..18b2a44d6 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -33,6 +33,7 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", + "./core/errno/*.c", "./core/string/*.c", "./core/stdlib/*.c", "./core/locale/*.c", diff --git a/lang/cem/libcc.ansi/errno/errlist.c b/lang/cem/libcc.ansi/core/errno/errlist.c similarity index 100% rename from lang/cem/libcc.ansi/errno/errlist.c rename to lang/cem/libcc.ansi/core/errno/errlist.c diff --git a/lang/cem/libcc.ansi/errno/strerror.c b/lang/cem/libcc.ansi/core/errno/strerror.c similarity index 100% rename from lang/cem/libcc.ansi/errno/strerror.c rename to lang/cem/libcc.ansi/core/errno/strerror.c diff --git a/lang/cem/libcc.ansi/errno/LIST b/lang/cem/libcc.ansi/errno/LIST deleted file mode 100644 index fd69e9793..000000000 --- a/lang/cem/libcc.ansi/errno/LIST +++ /dev/null @@ -1 +0,0 @@ -errlist.c diff --git a/lang/cem/libcc.ansi/errno/Makefile b/lang/cem/libcc.ansi/errno/Makefile deleted file mode 100644 index 39d27b10e..000000000 --- a/lang/cem/libcc.ansi/errno/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f errlist.o OLIST From df1cdf77623f21b99a3780f643de44fa724caf56 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 18:08:03 +0200 Subject: [PATCH 29/37] Add the sys directory for libc functions which use system calls; move the malloc functions in there. --- lang/cem/libcc.ansi/build.lua | 5 ++--- lang/cem/libcc.ansi/sys/README.md | 4 ++++ lang/cem/libcc.ansi/{ => sys}/malloc/calloc.c | 4 ++++ lang/cem/libcc.ansi/{ => sys}/malloc/malloc.c | 4 ++++ lang/cem/libcc.ansi/{ => sys}/malloc/malloc.h | 0 lang/cem/libcc.ansi/{ => sys}/malloc/realloc.c | 4 ++++ 6 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 lang/cem/libcc.ansi/sys/README.md rename lang/cem/libcc.ansi/{ => sys}/malloc/calloc.c (93%) rename lang/cem/libcc.ansi/{ => sys}/malloc/malloc.c (98%) rename lang/cem/libcc.ansi/{ => sys}/malloc/malloc.h (100%) rename lang/cem/libcc.ansi/{ => sys}/malloc/realloc.c (95%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 18b2a44d6..38fba6bb3 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -43,8 +43,7 @@ for _, plat in ipairs(vars.plats) do "./core/math/*.e", "./core/ctype/*.c", "./core/misc/*.c", - "./errno/*.c", - "./malloc/*.c", + "./sys/malloc/*.c", "./signal/*.c", "./assert/*.c", "./stdio/*.c", @@ -58,7 +57,7 @@ for _, plat in ipairs(vars.plats) do deps = { "lang/cem/libcc.ansi/headers+pkg", "plat/"..plat.."/include+pkg", - "./malloc/malloc.h", + "./sys/malloc/malloc.h", "./core/math/localmath.h", "./core/stdlib/ext_fmt.h", "./stdio/loc_incl.h", diff --git a/lang/cem/libcc.ansi/sys/README.md b/lang/cem/libcc.ansi/sys/README.md new file mode 100644 index 000000000..b38a2f08f --- /dev/null +++ b/lang/cem/libcc.ansi/sys/README.md @@ -0,0 +1,4 @@ +The functions here all use Posix system calls to do the actual work, and so +require `unistd.h` (at the minimum). Typically each group of functions will +be protected by an `ACKCONF` variable so the plat can turn them on and off as +necessary. diff --git a/lang/cem/libcc.ansi/malloc/calloc.c b/lang/cem/libcc.ansi/sys/malloc/calloc.c similarity index 93% rename from lang/cem/libcc.ansi/malloc/calloc.c rename to lang/cem/libcc.ansi/sys/malloc/calloc.c index 8695f17f0..e21c5266a 100644 --- a/lang/cem/libcc.ansi/malloc/calloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/calloc.c @@ -3,6 +3,8 @@ #include #include +#if ACKCONF_WANT_MALLOC + void* calloc(size_t nmemb, size_t size) { size_t bytes = nmemb * size; @@ -22,3 +24,5 @@ void* calloc(size_t nmemb, size_t size) memset(ptr, 0, bytes); return ptr; } + +#endif diff --git a/lang/cem/libcc.ansi/malloc/malloc.c b/lang/cem/libcc.ansi/sys/malloc/malloc.c similarity index 98% rename from lang/cem/libcc.ansi/malloc/malloc.c rename to lang/cem/libcc.ansi/sys/malloc/malloc.c index 71f3c80b2..ea1381600 100644 --- a/lang/cem/libcc.ansi/malloc/malloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/malloc.c @@ -3,6 +3,8 @@ #include #include "malloc.h" +#if ACKCONF_WANT_MALLOC + block_t __mem_root = { &__mem_root, 0 }; block_t* __mem_freelist = &__mem_root; @@ -148,3 +150,5 @@ void free(void* ptr) /* ...and update the ring pointer. */ __mem_freelist = p; } + +#endif diff --git a/lang/cem/libcc.ansi/malloc/malloc.h b/lang/cem/libcc.ansi/sys/malloc/malloc.h similarity index 100% rename from lang/cem/libcc.ansi/malloc/malloc.h rename to lang/cem/libcc.ansi/sys/malloc/malloc.h diff --git a/lang/cem/libcc.ansi/malloc/realloc.c b/lang/cem/libcc.ansi/sys/malloc/realloc.c similarity index 95% rename from lang/cem/libcc.ansi/malloc/realloc.c rename to lang/cem/libcc.ansi/sys/malloc/realloc.c index c941d8091..6e2b4c924 100644 --- a/lang/cem/libcc.ansi/malloc/realloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/realloc.c @@ -4,6 +4,8 @@ #include #include "malloc.h" +#if ACKCONF_WANT_MALLOC + void* realloc(void* ptr, size_t size) { block_t* h; @@ -39,3 +41,5 @@ void* realloc(void* ptr, size_t size) free(ptr); return newptr; } + +#endif From f744a216996c08e237be568ef07046daabfa11f6 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 18:25:26 +0200 Subject: [PATCH 30/37] All the opendir()/readdir() stuff is obsolete because it's all implemented in terms of open() and read(), which isn't how it's done any more; move the functions into an attic. --- lang/cem/libcc.ansi/{misc => _dead}/closedir.c | 0 lang/cem/libcc.ansi/{misc => _dead}/getdents.c | 0 lang/cem/libcc.ansi/{misc => _dead}/opendir.c | 0 lang/cem/libcc.ansi/{misc => _dead}/readdir.c | 0 lang/cem/libcc.ansi/{misc => _dead}/rewinddir.c | 0 lang/cem/libcc.ansi/{misc => _dead}/seekdir.c | 0 lang/cem/libcc.ansi/{misc => _dead}/telldir.c | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename lang/cem/libcc.ansi/{misc => _dead}/closedir.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/getdents.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/opendir.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/readdir.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/rewinddir.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/seekdir.c (100%) rename lang/cem/libcc.ansi/{misc => _dead}/telldir.c (100%) diff --git a/lang/cem/libcc.ansi/misc/closedir.c b/lang/cem/libcc.ansi/_dead/closedir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/closedir.c rename to lang/cem/libcc.ansi/_dead/closedir.c diff --git a/lang/cem/libcc.ansi/misc/getdents.c b/lang/cem/libcc.ansi/_dead/getdents.c similarity index 100% rename from lang/cem/libcc.ansi/misc/getdents.c rename to lang/cem/libcc.ansi/_dead/getdents.c diff --git a/lang/cem/libcc.ansi/misc/opendir.c b/lang/cem/libcc.ansi/_dead/opendir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/opendir.c rename to lang/cem/libcc.ansi/_dead/opendir.c diff --git a/lang/cem/libcc.ansi/misc/readdir.c b/lang/cem/libcc.ansi/_dead/readdir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/readdir.c rename to lang/cem/libcc.ansi/_dead/readdir.c diff --git a/lang/cem/libcc.ansi/misc/rewinddir.c b/lang/cem/libcc.ansi/_dead/rewinddir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/rewinddir.c rename to lang/cem/libcc.ansi/_dead/rewinddir.c diff --git a/lang/cem/libcc.ansi/misc/seekdir.c b/lang/cem/libcc.ansi/_dead/seekdir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/seekdir.c rename to lang/cem/libcc.ansi/_dead/seekdir.c diff --git a/lang/cem/libcc.ansi/misc/telldir.c b/lang/cem/libcc.ansi/_dead/telldir.c similarity index 100% rename from lang/cem/libcc.ansi/misc/telldir.c rename to lang/cem/libcc.ansi/_dead/telldir.c From af22b7ea8550bdb93f07bcef47121a8cdc4feeea Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 18:35:45 +0200 Subject: [PATCH 31/37] Change stdio to use atexit() rather than the internal __clean variable; this breaks the dependency between exit/atexit and stdio. Buffers are no longer flushed on abort() (because it's pretty risky). Move the relevant functions into sys/core. --- lang/cem/libcc.ansi/build.lua | 2 +- .../libcc.ansi/{stdlib => core/misc}/abort.c | 10 ++------ .../libcc.ansi/{signal => core/misc}/raise.c | 7 ++++-- lang/cem/libcc.ansi/headers/ack/config.h | 10 ++++++++ lang/cem/libcc.ansi/signal/LIST | 1 - lang/cem/libcc.ansi/signal/Makefile | 2 -- lang/cem/libcc.ansi/stdio/fflush.c | 12 +++++++++- lang/cem/libcc.ansi/stdio/flushbuf.c | 4 +--- lang/cem/libcc.ansi/stdio/loc_incl.h | 3 ++- lang/cem/libcc.ansi/stdio/setvbuf.c | 2 +- .../libcc.ansi/{stdlib => sys/exit}/atexit.c | 6 +---- lang/cem/libcc.ansi/sys/exit/atexits.h | 9 ++++++++ .../libcc.ansi/{stdlib => sys/exit}/exit.c | 23 ++++--------------- 13 files changed, 48 insertions(+), 43 deletions(-) rename lang/cem/libcc.ansi/{stdlib => core/misc}/abort.c (70%) rename lang/cem/libcc.ansi/{signal => core/misc}/raise.c (85%) delete mode 100644 lang/cem/libcc.ansi/signal/LIST delete mode 100644 lang/cem/libcc.ansi/signal/Makefile rename lang/cem/libcc.ansi/{stdlib => sys/exit}/atexit.c (64%) create mode 100644 lang/cem/libcc.ansi/sys/exit/atexits.h rename lang/cem/libcc.ansi/{stdlib => sys/exit}/exit.c (62%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 38fba6bb3..3427826e6 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -44,7 +44,7 @@ for _, plat in ipairs(vars.plats) do "./core/ctype/*.c", "./core/misc/*.c", "./sys/malloc/*.c", - "./signal/*.c", + "./sys/exit/*.c", "./assert/*.c", "./stdio/*.c", "./stdlib/*.c", diff --git a/lang/cem/libcc.ansi/stdlib/abort.c b/lang/cem/libcc.ansi/core/misc/abort.c similarity index 70% rename from lang/cem/libcc.ansi/stdlib/abort.c rename to lang/cem/libcc.ansi/core/misc/abort.c index afad36bf9..d59624169 100644 --- a/lang/cem/libcc.ansi/stdlib/abort.c +++ b/lang/cem/libcc.ansi/core/misc/abort.c @@ -4,17 +4,11 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) -#include -#endif -#include #include - -extern void (*_clean)(void); +#include +#include void abort(void) { - if (_clean) - _clean(); /* flush all output files */ raise(SIGABRT); } diff --git a/lang/cem/libcc.ansi/signal/raise.c b/lang/cem/libcc.ansi/core/misc/raise.c similarity index 85% rename from lang/cem/libcc.ansi/signal/raise.c rename to lang/cem/libcc.ansi/core/misc/raise.c index e1aedaa01..e50193136 100644 --- a/lang/cem/libcc.ansi/signal/raise.c +++ b/lang/cem/libcc.ansi/core/misc/raise.c @@ -4,14 +4,17 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#include #include -#endif #include +#if ACKCONF_WANT_EMULATED_RAISE + int raise(int sig) { if (sig < 0 || sig > _NSIG) return -1; return kill(getpid(), sig); } + +#endif diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index ae397dbfe..593767d4c 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -24,4 +24,14 @@ #define ACKCONF_WANT_TERMIOS 0 #endif +#ifndef ACKCONF_WANT_EMULATED_RAISE +/* Implement raise() in terms of kill() and getpid(). */ +#define ACKCONF_WANT_EMULATED_RAISE 1 +#endif + +#ifndef ACKCONF_WANT_MALLOC +/* Uses sbrk() to get memory from the system. */ +#define ACKCONF_WANT_MALLOC 1 +#endif + #endif diff --git a/lang/cem/libcc.ansi/signal/LIST b/lang/cem/libcc.ansi/signal/LIST deleted file mode 100644 index ff77f128d..000000000 --- a/lang/cem/libcc.ansi/signal/LIST +++ /dev/null @@ -1 +0,0 @@ -raise.c diff --git a/lang/cem/libcc.ansi/signal/Makefile b/lang/cem/libcc.ansi/signal/Makefile deleted file mode 100644 index c9578ae90..000000000 --- a/lang/cem/libcc.ansi/signal/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -f raise.o OLIST diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c index f5ef6c355..24baa6e70 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -68,7 +68,7 @@ int fflush(FILE* stream) return EOF; } -void __cleanup(void) +static void cleanup(void) { register int i; @@ -76,3 +76,13 @@ void __cleanup(void) if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING)) (void)fflush(__iotab[i]); } + +void __register_stdio_cleanup(void) +{ + static char registered = 0; + if (!registered) + { + registered = 1; + atexit(cleanup); + } +} diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c index 9518de70d..976d82a89 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -8,8 +8,6 @@ #include #include "loc_incl.h" -extern void (*_clean)(void); - static int do_write(int d, char* buf, int nbytes) { @@ -28,7 +26,7 @@ do_write(int d, char* buf, int nbytes) int __flushbuf(int c, FILE* stream) { - _clean = __cleanup; + __register_stdio_cleanup(); if (fileno(stream) < 0) return EOF; if (!io_testflag(stream, _IOWRITE)) diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/stdio/loc_incl.h index 52488e0c9..b30d3272a 100644 --- a/lang/cem/libcc.ansi/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/stdio/loc_incl.h @@ -14,7 +14,8 @@ int _doprnt(const char *format, va_list ap, FILE *stream); int _doscan(FILE * stream, const char *format, va_list ap); char *_i_compute(unsigned long val, int base, char *s, int nrdigits); char *_f_print(va_list *ap, int flags, char *s, char c, int precision); -void __cleanup(void); + +extern void __register_stdio_cleanup(void); FILE *popen(const char *command, const char *type); FILE *fdopen(int fd, const char *mode); diff --git a/lang/cem/libcc.ansi/stdio/setvbuf.c b/lang/cem/libcc.ansi/stdio/setvbuf.c index b7571ccc6..4650db03d 100644 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/stdio/setvbuf.c @@ -13,7 +13,7 @@ int setvbuf(register FILE* stream, char* buf, int mode, size_t size) { int retval = 0; - _clean = __cleanup; + __register_stdio_cleanup(); if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) return EOF; diff --git a/lang/cem/libcc.ansi/stdlib/atexit.c b/lang/cem/libcc.ansi/sys/exit/atexit.c similarity index 64% rename from lang/cem/libcc.ansi/stdlib/atexit.c rename to lang/cem/libcc.ansi/sys/exit/atexit.c index c9dc7964a..2cb16da9f 100644 --- a/lang/cem/libcc.ansi/stdlib/atexit.c +++ b/lang/cem/libcc.ansi/sys/exit/atexit.c @@ -1,11 +1,7 @@ /* $Id$ */ #include - -#define NEXITS 32 - -extern void (*__functab[NEXITS])(void); -extern int __funccnt; +#include "atexits.h" int atexit(void (*func)(void)) { diff --git a/lang/cem/libcc.ansi/sys/exit/atexits.h b/lang/cem/libcc.ansi/sys/exit/atexits.h new file mode 100644 index 000000000..3cca599c5 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/exit/atexits.h @@ -0,0 +1,9 @@ +#ifndef ATEXITS_H +#define ATEXITS_H + +#define NEXITS 32 + +extern void (*__functab[NEXITS])(void); +extern int __funccnt; + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/exit.c b/lang/cem/libcc.ansi/sys/exit/exit.c similarity index 62% rename from lang/cem/libcc.ansi/stdlib/exit.c rename to lang/cem/libcc.ansi/sys/exit/exit.c index ef8976bc0..7f861321f 100644 --- a/lang/cem/libcc.ansi/stdlib/exit.c +++ b/lang/cem/libcc.ansi/sys/exit/exit.c @@ -7,29 +7,16 @@ #include #include #include - -#define NEXITS 32 +#include "atexits.h" void (*__functab[NEXITS])(void); int __funccnt = 0; -/* only flush output buffers when necessary */ -int (*_clean)(void) = NULL; - -static void -_calls(void) -{ - register int i = __funccnt; - - /* "Called in reversed order of their registration" */ - while (--i >= 0) - (*__functab[i])(); -} - void exit(int status) { - _calls(); - if (_clean) - _clean(); + /* "Called in reversed order of their registration" */ + while (__funccnt >= 0) + (*__functab[__funccnt])(); + _exit(status); } From 6a729b846ab0f5485748366c46513d629829a201 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 18:54:40 +0200 Subject: [PATCH 32/37] Move stdio into (mostly) sys. --- lang/cem/libcc.ansi/build.lua | 3 +- .../libcc.ansi/{stdio => core/errno}/perror.c | 0 .../cem/libcc.ansi/{ => core}/stdio/fgetpos.c | 0 .../cem/libcc.ansi/{ => core}/stdio/fsetpos.c | 0 lang/cem/libcc.ansi/{ => core}/stdio/gets.c | 0 lang/cem/libcc.ansi/{ => core}/stdio/rewind.c | 1 - lang/cem/libcc.ansi/headers/ack/config.h | 4 ++ lang/cem/libcc.ansi/headers/stddef.h | 1 + lang/cem/libcc.ansi/stdio/LIST | 52 ------------------- lang/cem/libcc.ansi/stdio/Makefile | 10 ---- .../cem/libcc.ansi/{stdio => stdlib}/remove.c | 0 .../cem/libcc.ansi/{ => sys}/stdio/clearerr.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/data.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/doprnt.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/doscan.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fclose.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fdopen.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/feof.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/ferror.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fflush.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fgetc.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fgets.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fileno.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fillbuf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fltpr.c | 2 +- .../cem/libcc.ansi/{ => sys}/stdio/flushbuf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fopen.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fprintf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fputc.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fputs.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fread.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/freopen.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fscanf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fseek.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/ftell.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/fwrite.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/getc.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/getchar.c | 4 ++ .../cem/libcc.ansi/{ => sys}/stdio/icompute.c | 4 ++ .../cem/libcc.ansi/{ => sys}/stdio/loc_incl.h | 0 lang/cem/libcc.ansi/{ => sys}/stdio/printf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/putc.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/putchar.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/puts.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/rename.c | 0 lang/cem/libcc.ansi/{ => sys}/stdio/scanf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/setbuf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/setvbuf.c | 4 +- .../cem/libcc.ansi/{ => sys}/stdio/snprintf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/sprintf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/sscanf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/tmpfile.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/tmpnam.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/ungetc.c | 4 ++ .../cem/libcc.ansi/{ => sys}/stdio/vfprintf.c | 4 ++ lang/cem/libcc.ansi/{ => sys}/stdio/vprintf.c | 4 ++ .../libcc.ansi/{ => sys}/stdio/vsnprintf.c | 4 ++ .../cem/libcc.ansi/{ => sys}/stdio/vsprintf.c | 4 ++ 58 files changed, 183 insertions(+), 66 deletions(-) rename lang/cem/libcc.ansi/{stdio => core/errno}/perror.c (100%) rename lang/cem/libcc.ansi/{ => core}/stdio/fgetpos.c (100%) rename lang/cem/libcc.ansi/{ => core}/stdio/fsetpos.c (100%) rename lang/cem/libcc.ansi/{ => core}/stdio/gets.c (100%) rename lang/cem/libcc.ansi/{ => core}/stdio/rewind.c (89%) delete mode 100644 lang/cem/libcc.ansi/stdio/LIST delete mode 100644 lang/cem/libcc.ansi/stdio/Makefile rename lang/cem/libcc.ansi/{stdio => stdlib}/remove.c (100%) rename lang/cem/libcc.ansi/{ => sys}/stdio/clearerr.c (83%) rename lang/cem/libcc.ansi/{ => sys}/stdio/data.c (93%) rename lang/cem/libcc.ansi/{ => sys}/stdio/doprnt.c (99%) rename lang/cem/libcc.ansi/{ => sys}/stdio/doscan.c (99%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fclose.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fdopen.c (97%) rename lang/cem/libcc.ansi/{ => sys}/stdio/feof.c (80%) rename lang/cem/libcc.ansi/{ => sys}/stdio/ferror.c (82%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fflush.c (98%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fgetc.c (82%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fgets.c (92%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fileno.c (81%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fillbuf.c (97%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fltpr.c (98%) rename lang/cem/libcc.ansi/{ => sys}/stdio/flushbuf.c (98%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fopen.c (98%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fprintf.c (90%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fputc.c (81%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fputs.c (88%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fread.c (93%) rename lang/cem/libcc.ansi/{ => sys}/stdio/freopen.c (98%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fscanf.c (90%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fseek.c (96%) rename lang/cem/libcc.ansi/{ => sys}/stdio/ftell.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/fwrite.c (93%) rename lang/cem/libcc.ansi/{ => sys}/stdio/getc.c (80%) rename lang/cem/libcc.ansi/{ => sys}/stdio/getchar.c (81%) rename lang/cem/libcc.ansi/{ => sys}/stdio/icompute.c (92%) rename lang/cem/libcc.ansi/{ => sys}/stdio/loc_incl.h (100%) rename lang/cem/libcc.ansi/{ => sys}/stdio/printf.c (90%) rename lang/cem/libcc.ansi/{ => sys}/stdio/putc.c (81%) rename lang/cem/libcc.ansi/{ => sys}/stdio/putchar.c (83%) rename lang/cem/libcc.ansi/{ => sys}/stdio/puts.c (91%) rename lang/cem/libcc.ansi/{ => sys}/stdio/rename.c (100%) rename lang/cem/libcc.ansi/{ => sys}/stdio/scanf.c (90%) rename lang/cem/libcc.ansi/{ => sys}/stdio/setbuf.c (87%) rename lang/cem/libcc.ansi/{ => sys}/stdio/setvbuf.c (96%) rename lang/cem/libcc.ansi/{ => sys}/stdio/snprintf.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/sprintf.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/sscanf.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/tmpfile.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/tmpnam.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/ungetc.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/vfprintf.c (87%) rename lang/cem/libcc.ansi/{ => sys}/stdio/vprintf.c (88%) rename lang/cem/libcc.ansi/{ => sys}/stdio/vsnprintf.c (94%) rename lang/cem/libcc.ansi/{ => sys}/stdio/vsprintf.c (94%) diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 3427826e6..68a506b26 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -45,6 +45,7 @@ for _, plat in ipairs(vars.plats) do "./core/misc/*.c", "./sys/malloc/*.c", "./sys/exit/*.c", + "./sys/stdio/*.c", "./assert/*.c", "./stdio/*.c", "./stdlib/*.c", @@ -60,7 +61,7 @@ for _, plat in ipairs(vars.plats) do "./sys/malloc/malloc.h", "./core/math/localmath.h", "./core/stdlib/ext_fmt.h", - "./stdio/loc_incl.h", + "./sys/stdio/loc_incl.h", "./time/loc_time.h", }, vars = { plat = plat } diff --git a/lang/cem/libcc.ansi/stdio/perror.c b/lang/cem/libcc.ansi/core/errno/perror.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/perror.c rename to lang/cem/libcc.ansi/core/errno/perror.c diff --git a/lang/cem/libcc.ansi/stdio/fgetpos.c b/lang/cem/libcc.ansi/core/stdio/fgetpos.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/fgetpos.c rename to lang/cem/libcc.ansi/core/stdio/fgetpos.c diff --git a/lang/cem/libcc.ansi/stdio/fsetpos.c b/lang/cem/libcc.ansi/core/stdio/fsetpos.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/fsetpos.c rename to lang/cem/libcc.ansi/core/stdio/fsetpos.c diff --git a/lang/cem/libcc.ansi/stdio/gets.c b/lang/cem/libcc.ansi/core/stdio/gets.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/gets.c rename to lang/cem/libcc.ansi/core/stdio/gets.c diff --git a/lang/cem/libcc.ansi/stdio/rewind.c b/lang/cem/libcc.ansi/core/stdio/rewind.c similarity index 89% rename from lang/cem/libcc.ansi/stdio/rewind.c rename to lang/cem/libcc.ansi/core/stdio/rewind.c index 41791a7d0..db2a5e2a4 100644 --- a/lang/cem/libcc.ansi/stdio/rewind.c +++ b/lang/cem/libcc.ansi/core/stdio/rewind.c @@ -4,7 +4,6 @@ /* $Id$ */ #include -#include "loc_incl.h" void rewind(FILE* stream) { diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index 593767d4c..c3daa68fe 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -34,4 +34,8 @@ #define ACKCONF_WANT_MALLOC 1 #endif +#ifndef ACKCONF_WANT_STDIO +#define ACKCONF_WANT_STDIO 1 +#endif + #endif diff --git a/lang/cem/libcc.ansi/headers/stddef.h b/lang/cem/libcc.ansi/headers/stddef.h index eb14ffb27..ab5707643 100644 --- a/lang/cem/libcc.ansi/headers/stddef.h +++ b/lang/cem/libcc.ansi/headers/stddef.h @@ -9,6 +9,7 @@ #ifndef _STDDEF_H #define _STDDEF_H +#include #include #define NULL 0 diff --git a/lang/cem/libcc.ansi/stdio/LIST b/lang/cem/libcc.ansi/stdio/LIST deleted file mode 100644 index a7ecf217d..000000000 --- a/lang/cem/libcc.ansi/stdio/LIST +++ /dev/null @@ -1,52 +0,0 @@ -loc_incl.h -tmpfile.c -tmpnam.c -rename.c -remove.c -fopen.c -freopen.c -setbuf.c -setvbuf.c -perror.c -fprintf.c -printf.c -sprintf.c -vfprintf.c -vprintf.c -vsprintf.c -doprnt.c -icompute.c -fscanf.c -scanf.c -sscanf.c -doscan.c -fgetc.c -fgets.c -getc.c -getchar.c -gets.c -putc.c -putchar.c -fputc.c -puts.c -fputs.c -ungetc.c -fread.c -fwrite.c -fgetpos.c -fsetpos.c -rewind.c -fseek.c -ftell.c -clearerr.c -feof.c -ferror.c -fileno.c -fltpr.c -ecvt.c -fillbuf.c -fclose.c -flushbuf.c -fflush.c -isatty.c -data.c diff --git a/lang/cem/libcc.ansi/stdio/Makefile b/lang/cem/libcc.ansi/stdio/Makefile deleted file mode 100644 index d0d501c05..000000000 --- a/lang/cem/libcc.ansi/stdio/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -clean: - rm -f tmpfile.o tmpnam.o rename.o remove.o fopen.o freopen.o \ - setbuf.o setvbuf.o perror.o fprintf.o printf.o sprintf.o \ - vfprintf.o vprintf.o vsprintf.o doprnt.o icompute.o \ - fscanf.o scanf.o sscanf.o doscan.o fgetc.o fgets.o getc.o \ - getchar.o gets.o putc.o putchar.o fputc.o puts.o fputs.o \ - ungetc.o fread.o fwrite.o fgetpos.o fsetpos.o rewind.o \ - fseek.o ftell.o clearerr.o feof.o ferror.o fileno.o \ - fltpr.o ecvt.o gcvt.o fillbuf.o fclose.o flushbuf.o \ - fflush.o isatty.o data.o OLIST diff --git a/lang/cem/libcc.ansi/stdio/remove.c b/lang/cem/libcc.ansi/stdlib/remove.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/remove.c rename to lang/cem/libcc.ansi/stdlib/remove.c diff --git a/lang/cem/libcc.ansi/stdio/clearerr.c b/lang/cem/libcc.ansi/sys/stdio/clearerr.c similarity index 83% rename from lang/cem/libcc.ansi/stdio/clearerr.c rename to lang/cem/libcc.ansi/sys/stdio/clearerr.c index 8bfaaca79..df673423b 100644 --- a/lang/cem/libcc.ansi/stdio/clearerr.c +++ b/lang/cem/libcc.ansi/sys/stdio/clearerr.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + void(clearerr)(FILE* stream) { clearerr(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/data.c b/lang/cem/libcc.ansi/sys/stdio/data.c similarity index 93% rename from lang/cem/libcc.ansi/stdio/data.c rename to lang/cem/libcc.ansi/sys/stdio/data.c index debff7771..ccf1664ce 100644 --- a/lang/cem/libcc.ansi/stdio/data.c +++ b/lang/cem/libcc.ansi/sys/stdio/data.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + struct __iobuf __stdin = { 0, 0, _IOREAD, 0, (unsigned char*)NULL, (unsigned char*)NULL, @@ -26,3 +28,5 @@ FILE* __iotab[FOPEN_MAX] = { &__stderr, 0 }; + +#endif diff --git a/lang/cem/libcc.ansi/stdio/doprnt.c b/lang/cem/libcc.ansi/sys/stdio/doprnt.c similarity index 99% rename from lang/cem/libcc.ansi/stdio/doprnt.c rename to lang/cem/libcc.ansi/sys/stdio/doprnt.c index 3e754801d..9f74c7659 100644 --- a/lang/cem/libcc.ansi/stdio/doprnt.c +++ b/lang/cem/libcc.ansi/sys/stdio/doprnt.c @@ -9,6 +9,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + /* gnum() is used to get the width and precision fields of a format. */ static const char* gnum(register const char* f, int* ip, va_list* app) @@ -393,3 +395,5 @@ int _doprnt(register const char* fmt, va_list ap, FILE* stream) } return nrchars; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/sys/stdio/doscan.c similarity index 99% rename from lang/cem/libcc.ansi/stdio/doscan.c rename to lang/cem/libcc.ansi/sys/stdio/doscan.c index b53b4666f..3a1076bad 100644 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ b/lang/cem/libcc.ansi/sys/stdio/doscan.c @@ -9,6 +9,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + #if _EM_WSIZE == _EM_PSIZE #define set_pointer(flags) /* nothing */ #elif _EM_LSIZE == _EM_PSIZE @@ -540,3 +542,5 @@ int _doscan(register FILE* stream, const char* format, va_list ap) } return conv || (ic != EOF) ? done : EOF; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fclose.c b/lang/cem/libcc.ansi/sys/stdio/fclose.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/fclose.c rename to lang/cem/libcc.ansi/sys/stdio/fclose.c index 7ed925251..9a56b4cfe 100644 --- a/lang/cem/libcc.ansi/stdio/fclose.c +++ b/lang/cem/libcc.ansi/sys/stdio/fclose.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int fclose(FILE* fp) { register int i, retval = 0; @@ -30,3 +32,5 @@ int fclose(FILE* fp) free((void*)fp); return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fdopen.c b/lang/cem/libcc.ansi/sys/stdio/fdopen.c similarity index 97% rename from lang/cem/libcc.ansi/stdio/fdopen.c rename to lang/cem/libcc.ansi/sys/stdio/fdopen.c index d6b46bafe..084d39c14 100644 --- a/lang/cem/libcc.ansi/stdio/fdopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/fdopen.c @@ -7,6 +7,8 @@ #include #include "../stdio/loc_incl.h" +#if ACKCONF_WANT_STDIO + FILE* fdopen(int fd, const char* mode) { register int i; @@ -63,3 +65,5 @@ FILE* fdopen(int fd, const char* mode) __iotab[i] = stream; return stream; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/feof.c b/lang/cem/libcc.ansi/sys/stdio/feof.c similarity index 80% rename from lang/cem/libcc.ansi/stdio/feof.c rename to lang/cem/libcc.ansi/sys/stdio/feof.c index 550792f36..71451ee0f 100644 --- a/lang/cem/libcc.ansi/stdio/feof.c +++ b/lang/cem/libcc.ansi/sys/stdio/feof.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(feof)(FILE* stream) { return feof(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/ferror.c b/lang/cem/libcc.ansi/sys/stdio/ferror.c similarity index 82% rename from lang/cem/libcc.ansi/stdio/ferror.c rename to lang/cem/libcc.ansi/sys/stdio/ferror.c index d0271f0eb..f346ca791 100644 --- a/lang/cem/libcc.ansi/stdio/ferror.c +++ b/lang/cem/libcc.ansi/sys/stdio/ferror.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(ferror)(FILE* stream) { return ferror(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/sys/stdio/fflush.c similarity index 98% rename from lang/cem/libcc.ansi/stdio/fflush.c rename to lang/cem/libcc.ansi/sys/stdio/fflush.c index 24baa6e70..f0f53bb25 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/sys/stdio/fflush.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int fflush(FILE* stream) { int count, c1, i, retval = 0; @@ -86,3 +88,5 @@ void __register_stdio_cleanup(void) atexit(cleanup); } } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fgetc.c b/lang/cem/libcc.ansi/sys/stdio/fgetc.c similarity index 82% rename from lang/cem/libcc.ansi/stdio/fgetc.c rename to lang/cem/libcc.ansi/sys/stdio/fgetc.c index 08e7ca461..1b153c7f9 100644 --- a/lang/cem/libcc.ansi/stdio/fgetc.c +++ b/lang/cem/libcc.ansi/sys/stdio/fgetc.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int fgetc(FILE* stream) { return getc(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fgets.c b/lang/cem/libcc.ansi/sys/stdio/fgets.c similarity index 92% rename from lang/cem/libcc.ansi/stdio/fgets.c rename to lang/cem/libcc.ansi/sys/stdio/fgets.c index 6f4890e0c..14ecc488a 100644 --- a/lang/cem/libcc.ansi/stdio/fgets.c +++ b/lang/cem/libcc.ansi/sys/stdio/fgets.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + char* fgets(char* s, register int n, register FILE* stream) { register int ch; @@ -30,3 +32,5 @@ char* fgets(char* s, register int n, register FILE* stream) *ptr = '\0'; return s; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fileno.c b/lang/cem/libcc.ansi/sys/stdio/fileno.c similarity index 81% rename from lang/cem/libcc.ansi/stdio/fileno.c rename to lang/cem/libcc.ansi/sys/stdio/fileno.c index eef38788a..e42608845 100644 --- a/lang/cem/libcc.ansi/stdio/fileno.c +++ b/lang/cem/libcc.ansi/sys/stdio/fileno.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(fileno)(FILE* stream) { return stream->_fd; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fillbuf.c b/lang/cem/libcc.ansi/sys/stdio/fillbuf.c similarity index 97% rename from lang/cem/libcc.ansi/stdio/fillbuf.c rename to lang/cem/libcc.ansi/sys/stdio/fillbuf.c index c323da4cd..75187edac 100644 --- a/lang/cem/libcc.ansi/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fillbuf.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int __fillbuf(register FILE* stream) { static unsigned char ch[FOPEN_MAX]; @@ -77,3 +79,5 @@ int __fillbuf(register FILE* stream) return *stream->_ptr++; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fltpr.c b/lang/cem/libcc.ansi/sys/stdio/fltpr.c similarity index 98% rename from lang/cem/libcc.ansi/stdio/fltpr.c rename to lang/cem/libcc.ansi/sys/stdio/fltpr.c index af1ca8728..3fdc80852 100644 --- a/lang/cem/libcc.ansi/stdio/fltpr.c +++ b/lang/cem/libcc.ansi/sys/stdio/fltpr.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -#if ACKCONF_WANT_STDIO_FLOAT +#if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT static char* _pfloat(long double r, register char* s, int n, int flags) diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c similarity index 98% rename from lang/cem/libcc.ansi/stdio/flushbuf.c rename to lang/cem/libcc.ansi/sys/stdio/flushbuf.c index 976d82a89..81325d3a6 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + static int do_write(int d, char* buf, int nbytes) { @@ -148,3 +150,5 @@ int __flushbuf(int c, FILE* stream) } return (unsigned char)c; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fopen.c b/lang/cem/libcc.ansi/sys/stdio/fopen.c similarity index 98% rename from lang/cem/libcc.ansi/stdio/fopen.c rename to lang/cem/libcc.ansi/sys/stdio/fopen.c index e3b935494..ce8c5634e 100644 --- a/lang/cem/libcc.ansi/stdio/fopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/fopen.c @@ -10,6 +10,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + #define PMODE 0666 /* Since the O_CREAT flag is not available on all systems, we can't get it @@ -112,3 +114,5 @@ FILE* fopen(const char* name, const char* mode) __iotab[i] = stream; return stream; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fprintf.c b/lang/cem/libcc.ansi/sys/stdio/fprintf.c similarity index 90% rename from lang/cem/libcc.ansi/stdio/fprintf.c rename to lang/cem/libcc.ansi/sys/stdio/fprintf.c index cdcb16fee..3085bf96a 100644 --- a/lang/cem/libcc.ansi/stdio/fprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fprintf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int fprintf(FILE* stream, const char* format, ...) { va_list ap; @@ -20,3 +22,5 @@ int fprintf(FILE* stream, const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fputc.c b/lang/cem/libcc.ansi/sys/stdio/fputc.c similarity index 81% rename from lang/cem/libcc.ansi/stdio/fputc.c rename to lang/cem/libcc.ansi/sys/stdio/fputc.c index a0ac05c82..cf67ca421 100644 --- a/lang/cem/libcc.ansi/stdio/fputc.c +++ b/lang/cem/libcc.ansi/sys/stdio/fputc.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int fputc(int c, FILE* stream) { return putc(c, stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fputs.c b/lang/cem/libcc.ansi/sys/stdio/fputs.c similarity index 88% rename from lang/cem/libcc.ansi/stdio/fputs.c rename to lang/cem/libcc.ansi/sys/stdio/fputs.c index 8b1f33397..5c4ea7caa 100644 --- a/lang/cem/libcc.ansi/stdio/fputs.c +++ b/lang/cem/libcc.ansi/sys/stdio/fputs.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + int fputs(register const char* s, register FILE* stream) { register int i = 0; @@ -17,3 +19,5 @@ int fputs(register const char* s, register FILE* stream) return i; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fread.c b/lang/cem/libcc.ansi/sys/stdio/fread.c similarity index 93% rename from lang/cem/libcc.ansi/stdio/fread.c rename to lang/cem/libcc.ansi/sys/stdio/fread.c index cf0806345..5bdcf41ac 100644 --- a/lang/cem/libcc.ansi/stdio/fread.c +++ b/lang/cem/libcc.ansi/sys/stdio/fread.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + size_t fread(void* ptr, size_t size, size_t nmemb, register FILE* stream) { @@ -29,3 +31,5 @@ fread(void* ptr, size_t size, size_t nmemb, register FILE* stream) return ndone; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/freopen.c b/lang/cem/libcc.ansi/sys/stdio/freopen.c similarity index 98% rename from lang/cem/libcc.ansi/stdio/freopen.c rename to lang/cem/libcc.ansi/sys/stdio/freopen.c index 3f4e0a169..255e04cb6 100644 --- a/lang/cem/libcc.ansi/stdio/freopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/freopen.c @@ -9,6 +9,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + #define PMODE 0666 /* Do not "optimize" this file to use the open with O_CREAT if the file @@ -92,3 +94,5 @@ FILE* freopen(const char* name, const char* mode, FILE* stream) stream->_flags = flags; return stream; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fscanf.c b/lang/cem/libcc.ansi/sys/stdio/fscanf.c similarity index 90% rename from lang/cem/libcc.ansi/stdio/fscanf.c rename to lang/cem/libcc.ansi/sys/stdio/fscanf.c index 05e69af50..b06d47253 100644 --- a/lang/cem/libcc.ansi/stdio/fscanf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fscanf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int fscanf(FILE* stream, const char* format, ...) { va_list ap; @@ -20,3 +22,5 @@ int fscanf(FILE* stream, const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fseek.c b/lang/cem/libcc.ansi/sys/stdio/fseek.c similarity index 96% rename from lang/cem/libcc.ansi/stdio/fseek.c rename to lang/cem/libcc.ansi/sys/stdio/fseek.c index 2ab275cdc..c1ecd5650 100644 --- a/lang/cem/libcc.ansi/stdio/fseek.c +++ b/lang/cem/libcc.ansi/sys/stdio/fseek.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int fseek(FILE* stream, long int offset, int whence) { int adjust = 0; @@ -38,3 +40,5 @@ int fseek(FILE* stream, long int offset, int whence) stream->_ptr = stream->_buf; return ((pos == -1) ? -1 : 0); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/ftell.c b/lang/cem/libcc.ansi/sys/stdio/ftell.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/ftell.c rename to lang/cem/libcc.ansi/sys/stdio/ftell.c index 1fcbca25f..8053a1de2 100644 --- a/lang/cem/libcc.ansi/stdio/ftell.c +++ b/lang/cem/libcc.ansi/sys/stdio/ftell.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + long ftell(FILE* stream) { long result; @@ -30,3 +32,5 @@ long ftell(FILE* stream) result += (long)adjust; return result; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fwrite.c b/lang/cem/libcc.ansi/sys/stdio/fwrite.c similarity index 93% rename from lang/cem/libcc.ansi/stdio/fwrite.c rename to lang/cem/libcc.ansi/sys/stdio/fwrite.c index 325257174..02112e76a 100644 --- a/lang/cem/libcc.ansi/stdio/fwrite.c +++ b/lang/cem/libcc.ansi/sys/stdio/fwrite.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + size_t fwrite(const void* ptr, size_t size, size_t nmemb, register FILE* stream) @@ -28,3 +30,5 @@ fwrite(const void* ptr, size_t size, size_t nmemb, } return ndone; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/getc.c b/lang/cem/libcc.ansi/sys/stdio/getc.c similarity index 80% rename from lang/cem/libcc.ansi/stdio/getc.c rename to lang/cem/libcc.ansi/sys/stdio/getc.c index 20bdfa9f9..b69ecf9d6 100644 --- a/lang/cem/libcc.ansi/stdio/getc.c +++ b/lang/cem/libcc.ansi/sys/stdio/getc.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(getc)(FILE* stream) { return getc(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/getchar.c b/lang/cem/libcc.ansi/sys/stdio/getchar.c similarity index 81% rename from lang/cem/libcc.ansi/stdio/getchar.c rename to lang/cem/libcc.ansi/sys/stdio/getchar.c index e76f15d40..79f6764ab 100644 --- a/lang/cem/libcc.ansi/stdio/getchar.c +++ b/lang/cem/libcc.ansi/sys/stdio/getchar.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(getchar)(void) { return getchar(); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/icompute.c b/lang/cem/libcc.ansi/sys/stdio/icompute.c similarity index 92% rename from lang/cem/libcc.ansi/stdio/icompute.c rename to lang/cem/libcc.ansi/sys/stdio/icompute.c index bc73f1ddb..9b48d51a4 100644 --- a/lang/cem/libcc.ansi/stdio/icompute.c +++ b/lang/cem/libcc.ansi/sys/stdio/icompute.c @@ -5,6 +5,8 @@ #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + /* This routine is used in doprnt.c as well as in tmpfile.c and tmpnam.c. */ char* _i_compute(unsigned long val, int base, char* s, int nrdigits) @@ -18,3 +20,5 @@ char* _i_compute(unsigned long val, int base, char* s, int nrdigits) *s++ = (c > 9 ? c - 10 + 'a' : c + '0'); return s; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/sys/stdio/loc_incl.h similarity index 100% rename from lang/cem/libcc.ansi/stdio/loc_incl.h rename to lang/cem/libcc.ansi/sys/stdio/loc_incl.h diff --git a/lang/cem/libcc.ansi/stdio/printf.c b/lang/cem/libcc.ansi/sys/stdio/printf.c similarity index 90% rename from lang/cem/libcc.ansi/stdio/printf.c rename to lang/cem/libcc.ansi/sys/stdio/printf.c index d52d47525..6b118c859 100644 --- a/lang/cem/libcc.ansi/stdio/printf.c +++ b/lang/cem/libcc.ansi/sys/stdio/printf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int printf(const char* format, ...) { va_list ap; @@ -20,3 +22,5 @@ int printf(const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/putc.c b/lang/cem/libcc.ansi/sys/stdio/putc.c similarity index 81% rename from lang/cem/libcc.ansi/stdio/putc.c rename to lang/cem/libcc.ansi/sys/stdio/putc.c index ee47c72cc..ed8d1e519 100644 --- a/lang/cem/libcc.ansi/stdio/putc.c +++ b/lang/cem/libcc.ansi/sys/stdio/putc.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(putc)(int c, FILE* stream) { return putc(c, stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/putchar.c b/lang/cem/libcc.ansi/sys/stdio/putchar.c similarity index 83% rename from lang/cem/libcc.ansi/stdio/putchar.c rename to lang/cem/libcc.ansi/sys/stdio/putchar.c index ecf091f74..73f0e3a01 100644 --- a/lang/cem/libcc.ansi/stdio/putchar.c +++ b/lang/cem/libcc.ansi/sys/stdio/putchar.c @@ -5,7 +5,11 @@ #include +#if ACKCONF_WANT_STDIO + int(putchar)(int c) { return putchar(c); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/puts.c b/lang/cem/libcc.ansi/sys/stdio/puts.c similarity index 91% rename from lang/cem/libcc.ansi/stdio/puts.c rename to lang/cem/libcc.ansi/sys/stdio/puts.c index faa762426..3592e7cfe 100644 --- a/lang/cem/libcc.ansi/stdio/puts.c +++ b/lang/cem/libcc.ansi/sys/stdio/puts.c @@ -5,6 +5,8 @@ #include +#if ACKCONF_WANT_STDIO + int puts(register const char* s) { register FILE* file = stdout; @@ -21,3 +23,5 @@ int puts(register const char* s) return EOF; return i + 1; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/rename.c b/lang/cem/libcc.ansi/sys/stdio/rename.c similarity index 100% rename from lang/cem/libcc.ansi/stdio/rename.c rename to lang/cem/libcc.ansi/sys/stdio/rename.c diff --git a/lang/cem/libcc.ansi/stdio/scanf.c b/lang/cem/libcc.ansi/sys/stdio/scanf.c similarity index 90% rename from lang/cem/libcc.ansi/stdio/scanf.c rename to lang/cem/libcc.ansi/sys/stdio/scanf.c index c8c03c52b..d52788084 100644 --- a/lang/cem/libcc.ansi/stdio/scanf.c +++ b/lang/cem/libcc.ansi/sys/stdio/scanf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int scanf(const char* format, ...) { va_list ap; @@ -20,3 +22,5 @@ int scanf(const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/setbuf.c b/lang/cem/libcc.ansi/sys/stdio/setbuf.c similarity index 87% rename from lang/cem/libcc.ansi/stdio/setbuf.c rename to lang/cem/libcc.ansi/sys/stdio/setbuf.c index c906bc47a..5ac3e8ece 100644 --- a/lang/cem/libcc.ansi/stdio/setbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/setbuf.c @@ -6,7 +6,11 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + void setbuf(register FILE* stream, char* buf) { (void)setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t)BUFSIZ); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/setvbuf.c b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c similarity index 96% rename from lang/cem/libcc.ansi/stdio/setvbuf.c rename to lang/cem/libcc.ansi/sys/stdio/setvbuf.c index 4650db03d..1dfc6a0be 100644 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -extern void (*_clean)(void); +#if ACKCONF_WANT_STDIO int setvbuf(register FILE* stream, char* buf, int mode, size_t size) { @@ -53,3 +53,5 @@ int setvbuf(register FILE* stream, char* buf, int mode, size_t size) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/snprintf.c b/lang/cem/libcc.ansi/sys/stdio/snprintf.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/snprintf.c rename to lang/cem/libcc.ansi/sys/stdio/snprintf.c index 603b0a3d1..4ee372faa 100644 --- a/lang/cem/libcc.ansi/stdio/snprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/snprintf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int snprintf(char* s, size_t len, const char* format, ...) { va_list ap; @@ -28,3 +30,5 @@ int snprintf(char* s, size_t len, const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/sprintf.c b/lang/cem/libcc.ansi/sys/stdio/sprintf.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/sprintf.c rename to lang/cem/libcc.ansi/sys/stdio/sprintf.c index 78349a3a5..3a116c0f4 100644 --- a/lang/cem/libcc.ansi/stdio/sprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/sprintf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int sprintf(char* s, const char* format, ...) { va_list ap; @@ -28,3 +30,5 @@ int sprintf(char* s, const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/sscanf.c b/lang/cem/libcc.ansi/sys/stdio/sscanf.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/sscanf.c rename to lang/cem/libcc.ansi/sys/stdio/sscanf.c index 723f6c231..bd39100bd 100644 --- a/lang/cem/libcc.ansi/stdio/sscanf.c +++ b/lang/cem/libcc.ansi/sys/stdio/sscanf.c @@ -8,6 +8,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int sscanf(const char* s, const char* format, ...) { va_list ap; @@ -28,3 +30,5 @@ int sscanf(const char* s, const char* format, ...) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/tmpfile.c b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/tmpfile.c rename to lang/cem/libcc.ansi/sys/stdio/tmpfile.c index cc525220d..e50fd0d35 100644 --- a/lang/cem/libcc.ansi/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c @@ -9,6 +9,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + FILE* tmpfile(void) { static char name_buffer[L_tmpnam] = "/tmp/tmp."; @@ -28,3 +30,5 @@ FILE* tmpfile(void) (void)remove(name_buffer); return file; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/tmpnam.c b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/tmpnam.c rename to lang/cem/libcc.ansi/sys/stdio/tmpnam.c index 02df608ba..89fb9a4e3 100644 --- a/lang/cem/libcc.ansi/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c @@ -9,6 +9,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + char* tmpnam(char* s) { static char name_buffer[L_tmpnam] = "/tmp/tmp."; @@ -30,3 +32,5 @@ char* tmpnam(char* s) else return name_buffer; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/ungetc.c b/lang/cem/libcc.ansi/sys/stdio/ungetc.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/ungetc.c rename to lang/cem/libcc.ansi/sys/stdio/ungetc.c index cf690a52a..a53cc1cf9 100644 --- a/lang/cem/libcc.ansi/stdio/ungetc.c +++ b/lang/cem/libcc.ansi/sys/stdio/ungetc.c @@ -6,6 +6,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int ungetc(int ch, FILE* stream) { unsigned char* p; @@ -25,3 +27,5 @@ int ungetc(int ch, FILE* stream) *p = (unsigned char)ch; return ch; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/vfprintf.c b/lang/cem/libcc.ansi/sys/stdio/vfprintf.c similarity index 87% rename from lang/cem/libcc.ansi/stdio/vfprintf.c rename to lang/cem/libcc.ansi/sys/stdio/vfprintf.c index fd896a720..02b473dd6 100644 --- a/lang/cem/libcc.ansi/stdio/vfprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/vfprintf.c @@ -7,7 +7,11 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int vfprintf(FILE* stream, const char* format, va_list arg) { return _doprnt(format, arg, stream); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/vprintf.c b/lang/cem/libcc.ansi/sys/stdio/vprintf.c similarity index 88% rename from lang/cem/libcc.ansi/stdio/vprintf.c rename to lang/cem/libcc.ansi/sys/stdio/vprintf.c index bf884e576..5cc6b837f 100644 --- a/lang/cem/libcc.ansi/stdio/vprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/vprintf.c @@ -7,7 +7,11 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int vprintf(const char* format, va_list arg) { return _doprnt(format, arg, stdout); } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/vsnprintf.c b/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/vsnprintf.c rename to lang/cem/libcc.ansi/sys/stdio/vsnprintf.c index 033e39d72..d973b8066 100644 --- a/lang/cem/libcc.ansi/stdio/vsnprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int vsnprintf(char* s, size_t len, const char* format, va_list arg) { int retval; @@ -23,3 +25,5 @@ int vsnprintf(char* s, size_t len, const char* format, va_list arg) return retval; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/vsprintf.c b/lang/cem/libcc.ansi/sys/stdio/vsprintf.c similarity index 94% rename from lang/cem/libcc.ansi/stdio/vsprintf.c rename to lang/cem/libcc.ansi/sys/stdio/vsprintf.c index b0cbc124c..00065bec0 100644 --- a/lang/cem/libcc.ansi/stdio/vsprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/vsprintf.c @@ -7,6 +7,8 @@ #include #include "loc_incl.h" +#if ACKCONF_WANT_STDIO + int vsprintf(char* s, const char* format, va_list arg) { int retval; @@ -23,3 +25,5 @@ int vsprintf(char* s, const char* format, va_list arg) return retval; } + +#endif From bb78fd158c312d3ba6d3182fb7695fd9995a411b Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 19:18:16 +0200 Subject: [PATCH 33/37] Move the big gnarly functions like system() and popen() into sys, and make them build. --- lang/cem/libcc.ansi/build.lua | 6 +- lang/cem/libcc.ansi/headers/ack/config.h | 20 +++ lang/cem/libcc.ansi/headers/unistd.h | 10 +- lang/cem/libcc.ansi/misc/popen.c | 119 ------------------ lang/cem/libcc.ansi/stdlib/LIST | 25 ---- lang/cem/libcc.ansi/stdlib/Makefile | 14 --- lang/cem/libcc.ansi/{ => sys}/misc/getpass.c | 0 lang/cem/libcc.ansi/{ => sys}/misc/isatty.c | 0 lang/cem/libcc.ansi/sys/misc/popen.c | 68 ++++++++++ .../libcc.ansi/{stdlib => sys/misc}/remove.c | 4 + lang/cem/libcc.ansi/{ => sys}/misc/sleep.c | 15 ++- .../libcc.ansi/{stdlib => sys/misc}/system.c | 4 + lang/cem/libcc.ansi/sys/stdio/rename.c | 20 --- 13 files changed, 115 insertions(+), 190 deletions(-) delete mode 100644 lang/cem/libcc.ansi/misc/popen.c delete mode 100644 lang/cem/libcc.ansi/stdlib/LIST delete mode 100644 lang/cem/libcc.ansi/stdlib/Makefile rename lang/cem/libcc.ansi/{ => sys}/misc/getpass.c (100%) rename lang/cem/libcc.ansi/{ => sys}/misc/isatty.c (100%) create mode 100644 lang/cem/libcc.ansi/sys/misc/popen.c rename lang/cem/libcc.ansi/{stdlib => sys/misc}/remove.c (80%) rename lang/cem/libcc.ansi/{ => sys}/misc/sleep.c (79%) rename lang/cem/libcc.ansi/{stdlib => sys/misc}/system.c (96%) delete mode 100644 lang/cem/libcc.ansi/sys/stdio/rename.c diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 68a506b26..9e06c243b 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -46,13 +46,9 @@ for _, plat in ipairs(vars.plats) do "./sys/malloc/*.c", "./sys/exit/*.c", "./sys/stdio/*.c", - "./assert/*.c", + "./sys/misc/*.c", "./stdio/*.c", - "./stdlib/*.c", - "./string/*.c", "./time/*.c", - "./misc/getpass.c", - "./misc/isatty.c", }, hdrs = {}, -- must be empty deps = { diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index c3daa68fe..cefa902bd 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -29,6 +29,26 @@ #define ACKCONF_WANT_EMULATED_RAISE 1 #endif +#ifndef ACKCONF_WANT_EMULATED_REMOVE +/* Implement remove() as unlink(). */ +#define ACKCONF_WANT_EMULATED_REMOVE 1 +#endif + +#ifndef ACKCONF_WANT_EMULATED_SYSTEM +/* Implement system() as fork()/execve()/wait(). */ +#define ACKCONF_WANT_EMULATED_SYSTEM 1 +#endif + +#ifndef ACKCONF_WANT_EMULATED_SLEEP +/* Implement sleep() with SIGALRM. */ +#define ACKCONF_WANT_EMULATED_SLEEP 1 +#endif + +#ifndef ACKCONF_WANT_EMULATED_POPEN +/* Implement popen() with fork()/dup2() etc. */ +#define ACKCONF_WANT_EMULATED_POPEN 1 +#endif + #ifndef ACKCONF_WANT_MALLOC /* Uses sbrk() to get memory from the system. */ #define ACKCONF_WANT_MALLOC 1 diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index ef3b81689..9ae315648 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -43,8 +43,11 @@ #define SIG_DFL ((sighandler_t) 0) /* Default action. */ #define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ + #define SIGINT 2 /* Terminal interrupt */ + #define SIGQUIT 3 /* Terminal quit */ #define SIGABRT 6 /* Abort (ANSI) */ #define SIGILL 11 /* Illegal instruction */ + #define SIGALRM 14 /* Alarm clock */ #define _NSIG 16 /* Biggest signal number + 1 (not including real-time signals). */ @@ -79,6 +82,9 @@ extern char** environ; extern int brk(void* ptr); extern int close(int d); extern int creat(const char* path, mode_t mode); +extern int dup(int oldfd); +extern int dup2(int oldfd, int newfd); +extern int execl(const char *path, const char* arg, ...); extern int execve(const char *path, char *const argv[], char *const envp[]); extern int fcntl(int fd, int op, ...); extern int gettimeofday(struct timeval* tv, struct timezone* tz); @@ -86,6 +92,8 @@ extern int isatty(int d); extern int isatty(int d); extern int kill(pid_t old, int sig); extern int open(const char* path, int access, ...); +extern int pause(void); +extern int pipe(int pipefd[2]); extern int raise(int signum); extern int settimeofday(const struct timeval* tv, const struct timezone* tz); extern int sigaction(int, const struct sigaction *, struct sigaction *); @@ -94,6 +102,7 @@ extern int unlink(const char* path); extern off_t lseek(int fildes, off_t offset, int whence); extern pid_t fork(void); extern pid_t getpid(void); +extern unsigned int alarm(unsigned int seconds); extern pid_t wait(int* wstatus); extern sighandler_t signal(int signum, sighandler_t handler); extern ssize_t read(int fd, void* buffer, size_t count); @@ -101,5 +110,4 @@ extern ssize_t write(int fd, void* buffer, size_t count); extern void _exit(int); extern void* sbrk(int increment); - #endif diff --git a/lang/cem/libcc.ansi/misc/popen.c b/lang/cem/libcc.ansi/misc/popen.c deleted file mode 100644 index b3352e9ad..000000000 --- a/lang/cem/libcc.ansi/misc/popen.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * popen - open a pipe - */ -/* $Id$ */ - -#include -#include -#include -#if defined(__BSD4_2) -union wait { - int w_status; -}; -typedef union wait wait_arg; -#else -typedef int wait_arg; -#endif /* __BSD4_2 */ -#include "../stdio/loc_incl.h" - -int _close(int d); -#if defined(__USG) -static -#endif - int - _dup2(int oldd, int newd); /* not present in System 5 */ -int _execl(const char* name, ...); -int _fork(void); -int _pipe(int fildes[2]); -int _wait(wait_arg* status); -void _exit(int status); - -static int pids[FOPEN_MAX]; - -FILE* popen(const char* command, const char* type) -{ - int piped[2]; - int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2; - int pid; - - if (Xtype == 2 || _pipe(piped) < 0 || (pid = _fork()) < 0) - return 0; - - if (pid == 0) - { - /* child */ - register int* p; - - for (p = pids; p < &pids[FOPEN_MAX]; p++) - { - if (*p) - _close(p - pids); - } - _close(piped[Xtype]); - _dup2(piped[!Xtype], !Xtype); - _close(piped[!Xtype]); - _execl("/bin/sh", "sh", "-c", command, (char*)0); - _exit(127); /* like system() ??? */ - } - - pids[piped[Xtype]] = pid; - _close(piped[!Xtype]); - return fdopen(piped[Xtype], type); -} - -#if defined(__BSD4_2) -#define ret_val status.w_status -#else -#define ret_val status -#endif - -int pclose(FILE* stream) -{ - int fd = fileno(stream); - wait_arg status; - int wret; - void (*intsave)(int) = signal(SIGINT, SIG_IGN); - void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN); - - fclose(stream); - while ((wret = _wait(&status)) != -1) - { - if (wret == pids[fd]) - break; - } - if (wret == -1) - ret_val = -1; - signal(SIGINT, intsave); - signal(SIGQUIT, quitsave); - pids[fd] = 0; - return ret_val; -} - -#if defined(__USG) -int _dup(int fildes); - -static int -_dup2(int oldd, int newd) -{ - int i = 0, fd, tmp; - int fdbuf[FOPEN_MAX]; - - /* ignore the error on the close() */ - tmp = errno; - (void)_close(newd); - errno = tmp; - while ((fd = _dup(oldd)) != newd) - { - if (fd == -1) - break; - fdbuf[i++] = fd; - } - tmp = errno; - while (--i >= 0) - { - _close(fdbuf[i]); - } - errno = tmp; - return -(fd == -1); -} -#endif /* __USG */ diff --git a/lang/cem/libcc.ansi/stdlib/LIST b/lang/cem/libcc.ansi/stdlib/LIST deleted file mode 100644 index daa2f1cf2..000000000 --- a/lang/cem/libcc.ansi/stdlib/LIST +++ /dev/null @@ -1,25 +0,0 @@ -ext_fmt.h -abort.c -abs.c -atof.c -atoi.c -atol.c -bsearch.c -div.c -atexit.c -exit.c -getenv.c -labs.c -ldiv.c -malloc.c -mblen.c -mbstowcs.c -mbtowc.c -qsort.c -rand.c -strtod.c -strtol.c -system.c -wcstombs.c -wctomb.c -ext_comp.c diff --git a/lang/cem/libcc.ansi/stdlib/Makefile b/lang/cem/libcc.ansi/stdlib/Makefile deleted file mode 100644 index 8c8533fbe..000000000 --- a/lang/cem/libcc.ansi/stdlib/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -clean: - rm -f abort.o abs.o atof.o atoi.o atol.o bsearch.o div.o \ - atexit.o exit.o getenv.o labs.o ldiv.o malloc.o mblen.o \ - mbstowcs.o mbtowc.o qsort.o rand.o strtod.o strtol.o \ - system.o wcstombs.o wctomb.o ext_comp.o malloc.c OLIST - -malloc/malloc.c: - -(cd malloc; make) - -malloc.c: malloc/malloc.c - -cp malloc/malloc.c malloc.c - -distr: malloc.c - diff --git a/lang/cem/libcc.ansi/misc/getpass.c b/lang/cem/libcc.ansi/sys/misc/getpass.c similarity index 100% rename from lang/cem/libcc.ansi/misc/getpass.c rename to lang/cem/libcc.ansi/sys/misc/getpass.c diff --git a/lang/cem/libcc.ansi/misc/isatty.c b/lang/cem/libcc.ansi/sys/misc/isatty.c similarity index 100% rename from lang/cem/libcc.ansi/misc/isatty.c rename to lang/cem/libcc.ansi/sys/misc/isatty.c diff --git a/lang/cem/libcc.ansi/sys/misc/popen.c b/lang/cem/libcc.ansi/sys/misc/popen.c new file mode 100644 index 000000000..4631ce85c --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/popen.c @@ -0,0 +1,68 @@ +/* + * popen - open a pipe + */ +/* $Id$ */ + +#include +#include +#include +#include + +#if ACKCONF_WANT_EMULATED_POPEN + +static int pids[FOPEN_MAX]; + +FILE* popen(const char* command, const char* type) +{ + int piped[2]; + int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2; + int pid; + + if (Xtype == 2 || pipe(piped) < 0 || (pid = fork()) < 0) + return 0; + + if (pid == 0) + { + /* child */ + register int* p; + + for (p = pids; p < &pids[FOPEN_MAX]; p++) + { + if (*p) + close(p - pids); + } + close(piped[Xtype]); + dup2(piped[!Xtype], !Xtype); + close(piped[!Xtype]); + execl("/bin/sh", "sh", "-c", command, (char*)0); + _exit(127); /* like system() ??? */ + } + + pids[piped[Xtype]] = pid; + close(piped[!Xtype]); + return fdopen(piped[Xtype], type); +} + +int pclose(FILE* stream) +{ + int fd = fileno(stream); + int status; + int wret; + void (*intsave)(int) = signal(SIGINT, SIG_IGN); + void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN); + + fclose(stream); + while ((wret = wait(&status)) != -1) + { + if (wret == pids[fd]) + break; + } + if (wret == -1) + status = -1; + signal(SIGINT, intsave); + signal(SIGQUIT, quitsave); + pids[fd] = 0; + return status; +} + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/remove.c b/lang/cem/libcc.ansi/sys/misc/remove.c similarity index 80% rename from lang/cem/libcc.ansi/stdlib/remove.c rename to lang/cem/libcc.ansi/sys/misc/remove.c index fb0f4de8e..4c442df94 100644 --- a/lang/cem/libcc.ansi/stdlib/remove.c +++ b/lang/cem/libcc.ansi/sys/misc/remove.c @@ -7,7 +7,11 @@ #include #include +#if ACKCONF_WANT_EMULATED_REMOVE + int remove(const char* filename) { return unlink(filename); } + +#endif diff --git a/lang/cem/libcc.ansi/misc/sleep.c b/lang/cem/libcc.ansi/sys/misc/sleep.c similarity index 79% rename from lang/cem/libcc.ansi/misc/sleep.c rename to lang/cem/libcc.ansi/sys/misc/sleep.c index 1b7c9a8d7..97db561de 100644 --- a/lang/cem/libcc.ansi/misc/sleep.c +++ b/lang/cem/libcc.ansi/sys/misc/sleep.c @@ -3,11 +3,12 @@ */ /* $Id$ */ +#include #include +#include #include -int _alarm(int n); -void _pause(void); +#if ACKCONF_WANT_EMULATED_SLEEP static jmp_buf setjmpbuf; @@ -28,10 +29,10 @@ void sleep(int n) if (setjmp(setjmpbuf)) { signal(SIGALRM, oldsig); - _alarm(oldalarm); + alarm(oldalarm); return; } - oldalarm = _alarm(5000); /* Who cares how long, as long + oldalarm = alarm(5000); /* Who cares how long, as long * as it is long enough */ if (oldalarm > n) @@ -42,10 +43,12 @@ void sleep(int n) oldalarm = 1; } oldsig = signal(SIGALRM, alfun); - _alarm(n); + alarm(n); for (;;) { /* allow for other handlers ... */ - _pause(); + pause(); } } + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/system.c b/lang/cem/libcc.ansi/sys/misc/system.c similarity index 96% rename from lang/cem/libcc.ansi/stdlib/system.c rename to lang/cem/libcc.ansi/sys/misc/system.c index 49dba6318..8ed21d405 100644 --- a/lang/cem/libcc.ansi/stdlib/system.c +++ b/lang/cem/libcc.ansi/sys/misc/system.c @@ -9,6 +9,8 @@ #include #include +#if ACKCONF_WANT_EMULATED_SYSTEM + #define FAIL 127 static const char* exec_tab[] = { @@ -56,3 +58,5 @@ int system(const char* str) } return exitstatus; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/rename.c b/lang/cem/libcc.ansi/sys/stdio/rename.c deleted file mode 100644 index ff177ccd5..000000000 --- a/lang/cem/libcc.ansi/sys/stdio/rename.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * rename.c - rename a file - */ -/* $Id$ */ - -#include -#include -#include - -/* Disabled, dtrg: rename is a system call these days. */ -#if 0 -int _link(const char *name1, const char *name2); - -int -rename(const char *old, const char *new) { - if (!_link(old, new)) - return remove(old); - else return -1; -} -#endif From 64ae1d7583e27d03c410e3aaf57b96c9d8711956 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 19:40:50 +0200 Subject: [PATCH 34/37] Move time() into sys; change the name of the variable which controls it. --- lang/cem/libcc.ansi/headers/ack/config.h | 5 +++++ lang/cem/libcc.ansi/{time => sys/misc}/time.c | 5 ++--- plat/cpm/include/ack/plat.h | 2 +- plat/em/include/ack/plat.h | 3 +-- plat/linux/include/ack/plat.h | 5 ----- plat/osx/include/ack/plat.h | 5 ----- plat/pc86/include/ack/plat.h | 5 +---- plat/pdpv7/include/ack/plat.h | 5 +---- plat/qemuppc/include/ack/plat.h | 5 +---- plat/rpi/include/ack/plat.h | 5 +---- 10 files changed, 13 insertions(+), 32 deletions(-) rename lang/cem/libcc.ansi/{time => sys/misc}/time.c (83%) diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h index cefa902bd..2ee784213 100644 --- a/lang/cem/libcc.ansi/headers/ack/config.h +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -49,6 +49,11 @@ #define ACKCONF_WANT_EMULATED_POPEN 1 #endif +#ifndef ACKCONF_WANT_EMULATED_TIME +/* Implement time() with gettimeofday(). */ +#define ACKCONF_WANT_EMULATED_TIME 1 +#endif + #ifndef ACKCONF_WANT_MALLOC /* Uses sbrk() to get memory from the system. */ #define ACKCONF_WANT_MALLOC 1 diff --git a/lang/cem/libcc.ansi/time/time.c b/lang/cem/libcc.ansi/sys/misc/time.c similarity index 83% rename from lang/cem/libcc.ansi/time/time.c rename to lang/cem/libcc.ansi/sys/misc/time.c index 1379723a3..813cd2a30 100644 --- a/lang/cem/libcc.ansi/time/time.c +++ b/lang/cem/libcc.ansi/sys/misc/time.c @@ -8,10 +8,9 @@ #include #include -#ifndef ACKCONF_TIME_IS_A_SYSCALL +#if ACKCONF_WANT_EMULATED_TIME -time_t -time(time_t* timer) +time_t time(time_t* timer) { struct timeval tv; struct timezone tz; diff --git a/plat/cpm/include/ack/plat.h b/plat/cpm/include/ack/plat.h index cbd879396..321dadf18 100644 --- a/plat/cpm/include/ack/plat.h +++ b/plat/cpm/include/ack/plat.h @@ -9,6 +9,6 @@ /* We're providing a time() system call rather than wanting a wrapper around * gettimeofday() in the libc. */ -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/em/include/ack/plat.h b/plat/em/include/ack/plat.h index 585a6abf7..8506e8781 100644 --- a/plat/em/include/ack/plat.h +++ b/plat/em/include/ack/plat.h @@ -1,8 +1,7 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -#define ACKCONF_TIME_IS_A_SYSCALL - +#define ACKCONF_WANT_EMULATED_TIME 0 #define ACKCONF_WANT_STANDARD_SIGNALS 0 #endif diff --git a/plat/linux/include/ack/plat.h b/plat/linux/include/ack/plat.h index 0a2f9dded..f0ad12797 100644 --- a/plat/linux/include/ack/plat.h +++ b/plat/linux/include/ack/plat.h @@ -6,11 +6,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -/* #define ACKCONF_TIME_IS_A_SYSCALL */ - #define ACKCONF_WANT_STANDARD_O 0 #define ACKCONF_WANT_STANDARD_SIGNALS 0 diff --git a/plat/osx/include/ack/plat.h b/plat/osx/include/ack/plat.h index 6d6baa515..f0ad12797 100644 --- a/plat/osx/include/ack/plat.h +++ b/plat/osx/include/ack/plat.h @@ -6,11 +6,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -/* #define ACKCONF_TIME_IS_A_SYSCALL */ - #define ACKCONF_WANT_STANDARD_O 0 #define ACKCONF_WANT_STANDARD_SIGNALS 0 diff --git a/plat/pc86/include/ack/plat.h b/plat/pc86/include/ack/plat.h index cbd879396..e8c2251a0 100644 --- a/plat/pc86/include/ack/plat.h +++ b/plat/pc86/include/ack/plat.h @@ -6,9 +6,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/pdpv7/include/ack/plat.h b/plat/pdpv7/include/ack/plat.h index 42a302513..da2767148 100644 --- a/plat/pdpv7/include/ack/plat.h +++ b/plat/pdpv7/include/ack/plat.h @@ -8,9 +8,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/qemuppc/include/ack/plat.h b/plat/qemuppc/include/ack/plat.h index 4ad324142..fa39da2e4 100644 --- a/plat/qemuppc/include/ack/plat.h +++ b/plat/qemuppc/include/ack/plat.h @@ -6,9 +6,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/rpi/include/ack/plat.h b/plat/rpi/include/ack/plat.h index 9f9d08b27..e512c58e3 100644 --- a/plat/rpi/include/ack/plat.h +++ b/plat/rpi/include/ack/plat.h @@ -8,9 +8,6 @@ #ifndef _ACK_PLAT_H #define _ACK_PLAT_H -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif From 3f10299f43aa356386cad60d8889d815303dbabf Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 19:49:29 +0200 Subject: [PATCH 35/37] Move the portable time code into core. clock() goes into sys (as it calls times()). --- lang/cem/libcc.ansi/build.lua | 5 ++--- lang/cem/libcc.ansi/{ => core}/time/asctime.c | 0 lang/cem/libcc.ansi/{ => core}/time/ctime.c | 0 lang/cem/libcc.ansi/{ => core}/time/difftime.c | 0 lang/cem/libcc.ansi/{ => core}/time/gmtime.c | 0 lang/cem/libcc.ansi/{ => core}/time/loc_time.h | 4 ++-- lang/cem/libcc.ansi/{ => core}/time/localtime.c | 0 lang/cem/libcc.ansi/{ => core}/time/misc.c | 0 lang/cem/libcc.ansi/{ => core}/time/mktime.c | 0 lang/cem/libcc.ansi/{ => core}/time/strftime.c | 0 lang/cem/libcc.ansi/{ => core}/time/tzset.c | 0 lang/cem/libcc.ansi/{time => sys/misc}/clock.c | 0 lang/cem/libcc.ansi/time/LIST | 12 ------------ lang/cem/libcc.ansi/time/Makefile | 3 --- 14 files changed, 4 insertions(+), 20 deletions(-) rename lang/cem/libcc.ansi/{ => core}/time/asctime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/ctime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/difftime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/gmtime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/loc_time.h (91%) rename lang/cem/libcc.ansi/{ => core}/time/localtime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/misc.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/mktime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/strftime.c (100%) rename lang/cem/libcc.ansi/{ => core}/time/tzset.c (100%) rename lang/cem/libcc.ansi/{time => sys/misc}/clock.c (100%) delete mode 100644 lang/cem/libcc.ansi/time/LIST delete mode 100644 lang/cem/libcc.ansi/time/Makefile diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 9e06c243b..f6bdc8f45 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -39,16 +39,15 @@ for _, plat in ipairs(vars.plats) do "./core/locale/*.c", "./core/setjmp/*.c", "./core/setjmp/*.e", - "./core/math/*.c", -- hypot.c + "./core/math/*.c", "./core/math/*.e", "./core/ctype/*.c", "./core/misc/*.c", + "./core/time/*.c", "./sys/malloc/*.c", "./sys/exit/*.c", "./sys/stdio/*.c", "./sys/misc/*.c", - "./stdio/*.c", - "./time/*.c", }, hdrs = {}, -- must be empty deps = { diff --git a/lang/cem/libcc.ansi/time/asctime.c b/lang/cem/libcc.ansi/core/time/asctime.c similarity index 100% rename from lang/cem/libcc.ansi/time/asctime.c rename to lang/cem/libcc.ansi/core/time/asctime.c diff --git a/lang/cem/libcc.ansi/time/ctime.c b/lang/cem/libcc.ansi/core/time/ctime.c similarity index 100% rename from lang/cem/libcc.ansi/time/ctime.c rename to lang/cem/libcc.ansi/core/time/ctime.c diff --git a/lang/cem/libcc.ansi/time/difftime.c b/lang/cem/libcc.ansi/core/time/difftime.c similarity index 100% rename from lang/cem/libcc.ansi/time/difftime.c rename to lang/cem/libcc.ansi/core/time/difftime.c diff --git a/lang/cem/libcc.ansi/time/gmtime.c b/lang/cem/libcc.ansi/core/time/gmtime.c similarity index 100% rename from lang/cem/libcc.ansi/time/gmtime.c rename to lang/cem/libcc.ansi/core/time/gmtime.c diff --git a/lang/cem/libcc.ansi/time/loc_time.h b/lang/cem/libcc.ansi/core/time/loc_time.h similarity index 91% rename from lang/cem/libcc.ansi/time/loc_time.h rename to lang/cem/libcc.ansi/core/time/loc_time.h index 180bc74a4..e0f43ad5b 100644 --- a/lang/cem/libcc.ansi/time/loc_time.h +++ b/lang/cem/libcc.ansi/core/time/loc_time.h @@ -17,8 +17,8 @@ extern const int _ytab[2][12]; extern const char *_days[]; extern const char *_months[]; -void _tzset(void); -unsigned _dstget(struct tm *timep); +extern void _tzset(void); +extern unsigned _dstget(struct tm *timep); extern long _timezone; extern long _dst_off; diff --git a/lang/cem/libcc.ansi/time/localtime.c b/lang/cem/libcc.ansi/core/time/localtime.c similarity index 100% rename from lang/cem/libcc.ansi/time/localtime.c rename to lang/cem/libcc.ansi/core/time/localtime.c diff --git a/lang/cem/libcc.ansi/time/misc.c b/lang/cem/libcc.ansi/core/time/misc.c similarity index 100% rename from lang/cem/libcc.ansi/time/misc.c rename to lang/cem/libcc.ansi/core/time/misc.c diff --git a/lang/cem/libcc.ansi/time/mktime.c b/lang/cem/libcc.ansi/core/time/mktime.c similarity index 100% rename from lang/cem/libcc.ansi/time/mktime.c rename to lang/cem/libcc.ansi/core/time/mktime.c diff --git a/lang/cem/libcc.ansi/time/strftime.c b/lang/cem/libcc.ansi/core/time/strftime.c similarity index 100% rename from lang/cem/libcc.ansi/time/strftime.c rename to lang/cem/libcc.ansi/core/time/strftime.c diff --git a/lang/cem/libcc.ansi/time/tzset.c b/lang/cem/libcc.ansi/core/time/tzset.c similarity index 100% rename from lang/cem/libcc.ansi/time/tzset.c rename to lang/cem/libcc.ansi/core/time/tzset.c diff --git a/lang/cem/libcc.ansi/time/clock.c b/lang/cem/libcc.ansi/sys/misc/clock.c similarity index 100% rename from lang/cem/libcc.ansi/time/clock.c rename to lang/cem/libcc.ansi/sys/misc/clock.c diff --git a/lang/cem/libcc.ansi/time/LIST b/lang/cem/libcc.ansi/time/LIST deleted file mode 100644 index 4beee1806..000000000 --- a/lang/cem/libcc.ansi/time/LIST +++ /dev/null @@ -1,12 +0,0 @@ -loc_time.h -ctime.c -asctime.c -localtime.c -clock.c -difftime.c -gmtime.c -mktime.c -strftime.c -time.c -tzset.c -misc.c diff --git a/lang/cem/libcc.ansi/time/Makefile b/lang/cem/libcc.ansi/time/Makefile deleted file mode 100644 index e0cbf5db6..000000000 --- a/lang/cem/libcc.ansi/time/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -clean: - rm -f ctime.o asctime.o localtime.o clock.o difftime.o gmtime.o \ - mktime.o strftime.o time.o tzset.o misc.o OLIST From 59dbdea48a2297f435d24a38851081e5180bb6af Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 23:15:42 +0200 Subject: [PATCH 36/37] Move mktemp to sys; attic getgrent as noone will ever use this. --- .../cem/libcc.ansi/{misc => _dead}/getgrent.c | 0 lang/cem/libcc.ansi/build.lua | 18 +++++++-------- lang/cem/libcc.ansi/headers/unistd.h | 1 + lang/cem/libcc.ansi/misc/LIST | 22 ------------------- lang/cem/libcc.ansi/misc/Makefile | 5 ----- lang/cem/libcc.ansi/{ => sys}/misc/mktemp.c | 4 ++-- 6 files changed, 12 insertions(+), 38 deletions(-) rename lang/cem/libcc.ansi/{misc => _dead}/getgrent.c (100%) delete mode 100644 lang/cem/libcc.ansi/misc/LIST delete mode 100644 lang/cem/libcc.ansi/misc/Makefile rename lang/cem/libcc.ansi/{ => sys}/misc/mktemp.c (91%) diff --git a/lang/cem/libcc.ansi/misc/getgrent.c b/lang/cem/libcc.ansi/_dead/getgrent.c similarity index 100% rename from lang/cem/libcc.ansi/misc/getgrent.c rename to lang/cem/libcc.ansi/_dead/getgrent.c diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index f6bdc8f45..ee1049d66 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -33,31 +33,31 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", + "./core/ctype/*.c", "./core/errno/*.c", - "./core/string/*.c", - "./core/stdlib/*.c", "./core/locale/*.c", - "./core/setjmp/*.c", - "./core/setjmp/*.e", "./core/math/*.c", "./core/math/*.e", - "./core/ctype/*.c", "./core/misc/*.c", + "./core/setjmp/*.c", + "./core/setjmp/*.e", + "./core/stdlib/*.c", + "./core/string/*.c", "./core/time/*.c", - "./sys/malloc/*.c", "./sys/exit/*.c", - "./sys/stdio/*.c", + "./sys/malloc/*.c", "./sys/misc/*.c", + "./sys/stdio/*.c", }, hdrs = {}, -- must be empty deps = { "lang/cem/libcc.ansi/headers+pkg", "plat/"..plat.."/include+pkg", - "./sys/malloc/malloc.h", "./core/math/localmath.h", "./core/stdlib/ext_fmt.h", + "./core/time/loc_time.h", + "./sys/malloc/malloc.h", "./sys/stdio/loc_incl.h", - "./time/loc_time.h", }, vars = { plat = plat } } diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index 9ae315648..bab5ada71 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -79,6 +79,7 @@ extern char** environ; /* Implemented system calls */ +extern int access(const char* pathname, int mode); extern int brk(void* ptr); extern int close(int d); extern int creat(const char* path, mode_t mode); diff --git a/lang/cem/libcc.ansi/misc/LIST b/lang/cem/libcc.ansi/misc/LIST deleted file mode 100644 index bcf708244..000000000 --- a/lang/cem/libcc.ansi/misc/LIST +++ /dev/null @@ -1,22 +0,0 @@ -getgrent.c -getopt.c -getpass.c -getpw.c -getw.c -putw.c -putenv.c -environ.c -popen.c -sleep.c -termcap.c -fdopen.c -closedir.c -getdents.c -opendir.c -readdir.c -rewinddir.c -seekdir.c -telldir.c -isatty.c -mktemp.c -hypot.c diff --git a/lang/cem/libcc.ansi/misc/Makefile b/lang/cem/libcc.ansi/misc/Makefile deleted file mode 100644 index b191a6ed6..000000000 --- a/lang/cem/libcc.ansi/misc/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -clean: - rm -f getgrent.o getopt.o getpass.o getpw.o getw.o putw.o putenv.o \ - environ.o popen.o sleep.o termcap.o fdopen.o closedir.o \ - getdents.o opendir.o readdir.o rewinddir.o seekdir.o \ - telldir.o isatty.o OLIST diff --git a/lang/cem/libcc.ansi/misc/mktemp.c b/lang/cem/libcc.ansi/sys/misc/mktemp.c similarity index 91% rename from lang/cem/libcc.ansi/misc/mktemp.c rename to lang/cem/libcc.ansi/sys/misc/mktemp.c index a5b789050..41b72e5ef 100644 --- a/lang/cem/libcc.ansi/misc/mktemp.c +++ b/lang/cem/libcc.ansi/sys/misc/mktemp.c @@ -2,8 +2,8 @@ /* mktemp - make a name for a temporary file; only here for backwards compat */ /* no _-protected system-calls? */ -unsigned int getpid(void); -int access(char*, int); +#include +#include char* mktemp(char* template) { From fd94e219d41735015750a9f949851abf76bdaf18 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 23:16:22 +0200 Subject: [PATCH 37/37] Remove the attic. --- lang/cem/libcc.ansi/_dead/closedir.c | 35 --- lang/cem/libcc.ansi/_dead/getdents.c | 292 -------------------------- lang/cem/libcc.ansi/_dead/getgrent.c | 134 ------------ lang/cem/libcc.ansi/_dead/opendir.c | 66 ------ lang/cem/libcc.ansi/_dead/readdir.c | 44 ---- lang/cem/libcc.ansi/_dead/rewinddir.c | 36 ---- lang/cem/libcc.ansi/_dead/seekdir.c | 107 ---------- lang/cem/libcc.ansi/_dead/telldir.c | 33 --- 8 files changed, 747 deletions(-) delete mode 100644 lang/cem/libcc.ansi/_dead/closedir.c delete mode 100644 lang/cem/libcc.ansi/_dead/getdents.c delete mode 100644 lang/cem/libcc.ansi/_dead/getgrent.c delete mode 100644 lang/cem/libcc.ansi/_dead/opendir.c delete mode 100644 lang/cem/libcc.ansi/_dead/readdir.c delete mode 100644 lang/cem/libcc.ansi/_dead/rewinddir.c delete mode 100644 lang/cem/libcc.ansi/_dead/seekdir.c delete mode 100644 lang/cem/libcc.ansi/_dead/telldir.c diff --git a/lang/cem/libcc.ansi/_dead/closedir.c b/lang/cem/libcc.ansi/_dead/closedir.c deleted file mode 100644 index 12f7c825a..000000000 --- a/lang/cem/libcc.ansi/_dead/closedir.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - closedir -- close a directory stream - - last edit: 11-Nov-1988 D A Gwyn -*/ - -#include -#include -#include -#include -#include - -typedef void* pointer; /* (void *) if you have it */ - -#ifndef NULL -#define NULL 0 -#endif - -int _close(int d); - -int closedir(register DIR* dirp) /* stream from opendir */ -{ - register int fd; - - if (dirp == NULL || dirp->dd_buf == NULL) - { - errno = EFAULT; - return -1; /* invalid pointer */ - } - - fd = dirp->dd_fd; /* bug fix thanks to R. Salz */ - free((pointer)dirp->dd_buf); - free((pointer)dirp); - return _close(fd); -} diff --git a/lang/cem/libcc.ansi/_dead/getdents.c b/lang/cem/libcc.ansi/_dead/getdents.c deleted file mode 100644 index c6d40723c..000000000 --- a/lang/cem/libcc.ansi/_dead/getdents.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - getdents -- get directory entries in a file system independent format - (SVR3 system call emulation) - - last edit: 06-Jul-1987 D A Gwyn - - This single source file supports several different methods of - getting directory entries from the operating system. Define - whichever one of the following describes your system: - - UFS original UNIX filesystem (14-character name limit) - BFS 4.2BSD (also 4.3BSD) native filesystem (long names) - NFS getdirentries() system call - - Also define any of the following that are pertinent: - - ATT_SPEC check user buffer address for longword alignment - BSD_SYSV BRL UNIX System V emulation environment on 4.nBSD - UNK have _getdents() system call, but kernel may not - support it - - If your C library has a getdents() system call interface, but you - can't count on all kernels on which your application binaries may - run to support it, change the system call interface name to - _getdents() and define "UNK" to enable the system-call validity - test in this "wrapper" around _getdents(). - - If your system has a getdents() system call that is guaranteed - to always work, you shouldn't be using this source file at all. -*/ - -#include -#include -#include -#include -#include -#ifdef BSD_SYSV -#include /* BSD flavor, not System V */ -#else -#if defined(UFS) -#define DIRSIZ 14 /* 14 char filename in Version 7 */ -#endif -#define MAXNAMLEN 255 -struct direct -{ - off_t d_off; /* offset of next disk directory entry */ - u_long d_fileno; /* file number of entry */ - u_short d_reclen; /* length of this record */ - u_short d_namlen; /* length of string in d_name */ - char d_name[MAXNAMLEN + 1]; /* name (up to MAXNAMLEN + 1) */ -}; -#undef MAXNAMLEN /* avoid conflict with SVR3 */ - -#define d_ino d_fileno /* compatability */ - -#ifdef d_ino /* 4.3BSD/NFS using d_fileno */ -#undef d_ino /* (not absolutely necessary) */ -#else -#define d_fileno d_ino /* (struct direct) member */ -#endif -#endif -#include -#include -#ifdef UNK -#ifndef UFS -#error UNK applies only to UFS -/* One could do something similar for getdirentries(), but I didn't bother. */ -#endif -#include -#endif - -#if defined(UFS) + defined(BFS) + defined(NFS) != 1 /* sanity check */ -#error exactly one of UFS, BFS, or NFS must be defined -#endif - -#ifdef UFS -#define RecLen(dp) (sizeof(struct direct)) /* fixed-length entries */ -#else /* BFS || NFS */ -#define RecLen(dp) ((dp)->d_reclen) /* variable-length entries */ -#endif - -#ifdef NFS -#ifdef BSD_SYSV -#define getdirentries _getdirentries /* package hides this system call */ -#endif -extern int getdirentries(int fd, char* buf, int nbytes, long* basep); -static long dummy; /* getdirentries() needs basep */ -#define GetBlock(fd, buf, n) getdirentries(fd, buf, (unsigned)n, &dummy) -#else /* UFS || BFS */ -#ifdef BSD_SYSV -#define read _read /* avoid emulation overhead */ -#endif -extern int read(); -#define GetBlock(fd, buf, n) read(fd, buf, (unsigned)n) -#endif - -#ifdef UNK -extern int _getdents(); /* actual system call */ -#endif - -extern int _fstat(int fd, struct stat* buf); -extern off_t _lseek(int d, int offset, int whence); - -#ifndef DIRBLKSIZ -#define DIRBLKSIZ 4096 /* directory file read buffer size */ -#endif - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef S_ISDIR /* macro to test for directory file */ -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -#endif - -#ifdef UFS - -/* - The following routine is necessary to handle DIRSIZ-long entry names. - Thanks to Richard Todd for pointing this out. -*/ - -static int -NameLen(char name[]) /* return # chars in embedded name */ -/* -> name embedded in struct direct */ -{ - register char* s; /* -> name[.] */ - register char* stop = &name[DIRSIZ]; /* -> past end of name field */ - - for (s = &name[1]; /* (empty names are impossible) */ - *s != '\0' /* not NUL terminator */ - && ++s < stop; /* < DIRSIZ characters scanned */ - ) - ; - - return s - name; /* # valid characters in name */ -} - -#else /* BFS || NFS */ - -#define NameLen(name) strlen(name) /* names are always NUL-terminated */ - -#endif - -#ifdef UNK -static enum { maybe, - no, - yes } state - = maybe; -/* does _getdents() work? */ - -/*ARGSUSED*/ -static void -sig_catch(int sig) /* sig must be SIGSYS */ -{ - state = no; /* attempted _getdents() faulted */ -} -#endif - -int getdents(int fildes, char* buf, unsigned nbyte) /* returns # bytes read; - 0 on EOF, -1 on error */ -/* fildes == directory file descriptor */ -/* *buf == where to put the (struct dirent)s */ -/* nbyte == size of buf[] */ -{ - int serrno; /* entry errno */ - off_t offset; /* initial directory file offset */ - struct stat statb; /* fstat() info */ - union { - char dblk[DIRBLKSIZ]; - /* directory file block buffer */ - struct direct dummy; /* just for alignment */ - } u; /* (avoids having to malloc()) */ - register struct direct* dp; /* -> u.dblk[.] */ - register struct dirent* bp; /* -> buf[.] */ - -#ifdef UNK - switch (state) - { - void (*shdlr)(); /* entry SIGSYS handler */ - register int retval; /* return from _getdents() if any */ - - case yes: /* _getdents() is known to work */ - return _getdents(fildes, buf, nbyte); - - case maybe: /* first time only */ - shdlr = signal(SIGSYS, sig_catch); - retval = _getdents(fildes, buf, nbyte); /* try it */ - (void)signal(SIGSYS, shdlr); - - if (state == maybe) /* SIGSYS did not occur */ - { - state = yes; /* so _getdents() must have worked */ - return retval; - } - /* else fall through into emulation */ - - /* case no:*/ /* fall through into emulation */ - } -#endif - - if (buf == NULL -#ifdef ATT_SPEC - || (unsigned long)buf % sizeof(long) != 0 /* ugh */ -#endif - ) - { - errno = EFAULT; /* invalid pointer */ - return -1; - } - - if (_fstat(fildes, &statb) != 0) - return -1; /* errno set by fstat() */ - - if (!S_ISDIR(statb.st_mode)) - { - errno = ENOTDIR; /* not a directory */ - return -1; - } - - if ((offset = _lseek(fildes, (off_t)0, SEEK_CUR)) < 0) - return -1; /* errno set by lseek() */ - -#ifdef BFS /* no telling what remote hosts do */ - if ((unsigned long)offset % DIRBLKSIZ != 0) - { - errno = ENOENT; /* file pointer probably misaligned */ - return -1; - } -#endif - - serrno = errno; /* save entry errno */ - - for (bp = (struct dirent*)buf; bp == (struct dirent*)buf;) - { /* convert next directory block */ - int size; - - do - size = GetBlock(fildes, u.dblk, DIRBLKSIZ); - while (size == -1 && errno == EINTR); - - if (size <= 0) - return size; /* EOF or error (EBADF) */ - - for (dp = (struct direct*)u.dblk; - (char*)dp < &u.dblk[size]; - dp = (struct direct*)((char*)dp + RecLen(dp))) - { -#ifndef UFS - if (dp->d_reclen <= 0) - { - errno = EIO; /* corrupted directory */ - return -1; - } -#endif - - if (dp->d_fileno != 0) - { /* non-empty; copy to user buffer */ - register int reclen = DIRENTSIZ(NameLen(dp->d_name)); - - if ((char*)bp + reclen > &buf[nbyte]) - { - errno = EINVAL; - return -1; /* buf too small */ - } - - bp->d_ino = dp->d_fileno; - bp->d_off = offset + ((char*)dp - u.dblk); - bp->d_reclen = reclen; - (void)strncpy(bp->d_name, dp->d_name, - reclen - DIRENTBASESIZ); /* adds NUL padding */ - - bp = (struct dirent*)((char*)bp + reclen); - } - } - -#ifndef BFS /* 4.2BSD screwed up; fixed in 4.3BSD */ - if ((char*)dp > &u.dblk[size]) - { - errno = EIO; /* corrupted directory */ - return -1; - } -#endif - } - - errno = serrno; /* restore entry errno */ - return (char*)bp - buf; /* return # bytes read */ -} diff --git a/lang/cem/libcc.ansi/_dead/getgrent.c b/lang/cem/libcc.ansi/_dead/getgrent.c deleted file mode 100644 index 33517f961..000000000 --- a/lang/cem/libcc.ansi/_dead/getgrent.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * getgrent - get entry form group file - * - * Author: Patrick van Kleef - */ -/* $Id$ */ - -#include -#include -#include - -#define O_RDONLY 0 - -int open(const char* path, int flags); - -#if defined(__BSD4_2) -typedef int off_t; /* see lseek(2) */ -#else -typedef long off_t; -#endif - -off_t _lseek(int d, off_t offset, int whence); -int _read(int d, char* buf, int nbytes); -int _close(int d); - -#define RBUFSIZE 1024 -static char _gr_file[] = "/etc/group"; -static char _grbuf[256]; -static char _buffer[RBUFSIZE]; -static char* _pnt; -static char* _buf; -static int _gfd = -1; -static int _bufcnt; -static struct group grp; - -int setgrent(void) -{ - if (_gfd >= 0) - _lseek(_gfd, 0L, 0); - else - _gfd = open(_gr_file, O_RDONLY); - - _bufcnt = 0; - return _gfd; -} - -void endgrent(void) -{ - if (_gfd >= 0) - _close(_gfd); - - _gfd = -1; - _bufcnt = 0; -} - -static int -getline(void) -{ - if (_gfd < 0 && setgrent() < 0) - return 0; - - _buf = _grbuf; - do - { - if (--_bufcnt <= 0) - { - if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0) - return 0; - else - _pnt = _buffer; - } - *_buf++ = *_pnt++; - } while (*_pnt != '\n'); - _pnt++; - _bufcnt--; - *_buf = 0; - _buf = _grbuf; - return 1; -} - -static void -skip_period(void) -{ - while (*_buf && *_buf != ':') - _buf++; - *_buf++ = '\0'; -} - -struct group* -getgrent(void) -{ - if (getline() == 0) - return 0; - - grp.gr_name = _buf; - skip_period(); - grp.gr_passwd = _buf; - skip_period(); - grp.gr_gid = atoi(_buf); - skip_period(); - return &grp; -} - -struct group* -getgrnam(const char* name) -{ - struct group* g; - - setgrent(); - while ((g = getgrent()) != 0) - if (!strcmp(g->gr_name, name)) - break; - endgrent(); - if (g != 0) - return g; - else - return 0; -} - -struct group* -getgrgid(int gid) -{ - struct group* g; - - setgrent(); - while ((g = getgrent()) != 0) - if (g->gr_gid == gid) - break; - endgrent(); - if (g != 0) - return g; - else - return 0; -} diff --git a/lang/cem/libcc.ansi/_dead/opendir.c b/lang/cem/libcc.ansi/_dead/opendir.c deleted file mode 100644 index b7b3472d0..000000000 --- a/lang/cem/libcc.ansi/_dead/opendir.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - opendir -- open a directory stream - - last edit: 16-Jun-1987 D A Gwyn -*/ - -#include -#include -#include -#include -#include -#include - -typedef void* pointer; /* (void *) if you have it */ - -extern int _open(const char* path, int flags, int mode); -extern int _close(int d); -extern int _fstat(int fd, struct stat* buf); - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif - -#ifndef S_ISDIR /* macro to test for directory file */ -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -#endif - -DIR* opendir(const char* dirname) /* name of directory */ -{ - register DIR* dirp; /* -> malloc'ed storage */ - register int fd; /* file descriptor for read */ - struct stat sbuf; /* result of fstat() */ - - if ((fd = _open(dirname, O_RDONLY, 0)) < 0) - return NULL; /* errno set by open() */ - - if (_fstat(fd, &sbuf) != 0 || !S_ISDIR(sbuf.st_mode)) - { - (void)_close(fd); - errno = ENOTDIR; - return NULL; /* not a directory */ - } - - if ((dirp = (DIR*)malloc(sizeof(DIR))) == NULL - || (dirp->dd_buf = (char*)malloc((unsigned)DIRBUF)) == NULL) - { - register int serrno = errno; - /* errno set to ENOMEM by sbrk() */ - - if (dirp != NULL) - free((pointer)dirp); - - (void)_close(fd); - errno = serrno; - return NULL; /* not enough memory */ - } - - dirp->dd_fd = fd; - dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ - - return dirp; -} diff --git a/lang/cem/libcc.ansi/_dead/readdir.c b/lang/cem/libcc.ansi/_dead/readdir.c deleted file mode 100644 index ac1d800b1..000000000 --- a/lang/cem/libcc.ansi/_dead/readdir.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - readdir -- read next entry from a directory stream - - last edit: 25-Apr-1987 D A Gwyn -*/ - -#include -#include -#include -#include - -/* SVR3 system call, or emulation for getdents() */ -extern int getdents(int fildes, char* buf, unsigned nbyte); - -#ifndef NULL -#define NULL 0 -#endif - -struct dirent* -readdir(register DIR* dirp) -{ - register struct dirent* dp; /* -> directory data */ - - if (dirp == NULL || dirp->dd_buf == NULL) - { - errno = EFAULT; - return NULL; /* invalid pointer */ - } - - do - { - if (dirp->dd_loc >= dirp->dd_size) /* empty or obsolete */ - dirp->dd_loc = dirp->dd_size = 0; - - if (dirp->dd_size == 0 /* need to refill buffer */ - && (dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF)) <= 0) - return NULL; /* EOF or error */ - - dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc]; - dirp->dd_loc += dp->d_reclen; - } while (dp->d_ino == 0L); /* don't rely on getdents() */ - - return dp; -} diff --git a/lang/cem/libcc.ansi/_dead/rewinddir.c b/lang/cem/libcc.ansi/_dead/rewinddir.c deleted file mode 100644 index e8c9e4749..000000000 --- a/lang/cem/libcc.ansi/_dead/rewinddir.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - rewinddir -- rewind a directory stream - - last edit: 25-Apr-1987 D A Gwyn - - This is not simply a call to seekdir(), because seekdir() - will use the current buffer whenever possible and we need - rewinddir() to forget about buffered data. -*/ - -#include -#include -#include -#include - -extern off_t _lseek(int d, int offset, int whence); - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -void rewinddir(register DIR* dirp) -{ - if (dirp == NULL || dirp->dd_buf == NULL) - { - errno = EFAULT; - return; /* invalid pointer */ - } - - dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */ - (void)_lseek(dirp->dd_fd, (off_t)0, SEEK_SET); /* may set errno */ -} diff --git a/lang/cem/libcc.ansi/_dead/seekdir.c b/lang/cem/libcc.ansi/_dead/seekdir.c deleted file mode 100644 index c53629292..000000000 --- a/lang/cem/libcc.ansi/_dead/seekdir.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - seekdir -- reposition a directory stream - - last edit: 24-May-1987 D A Gwyn - - An unsuccessful seekdir() will in general alter the current - directory position; beware. - - NOTE: 4.nBSD directory compaction makes seekdir() & telldir() - practically impossible to do right. Avoid using them! -*/ - -#include -#include -#include -#include - -extern off_t _lseek(int d, int offset, int whence); - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -typedef int bool; /* Boolean data type */ -#define false 0 -#define true 1 - -void seekdir(register DIR* dirp, register off_t loc) -/* loc == position from telldir() */ -{ - register bool rewind; /* "start over when stymied" flag */ - - if (dirp == NULL || dirp->dd_buf == NULL) - { - errno = EFAULT; - return; /* invalid pointer */ - } - - /* A (struct dirent)'s d_off is an invented quantity on 4.nBSD - NFS-supporting systems, so it is not safe to lseek() to it. */ - - /* Monotonicity of d_off is heavily exploited in the following. */ - - /* This algorithm is tuned for modest directory sizes. For - huge directories, it might be more efficient to read blocks - until the first d_off is too large, then back up one block, - or even to use binary search on the directory blocks. I - doubt that the extra code for that would be worthwhile. */ - - if (dirp->dd_loc >= dirp->dd_size /* invalid index */ - || ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off > loc - /* too far along in buffer */ - ) - dirp->dd_loc = 0; /* reset to beginning of buffer */ - /* else save time by starting at current dirp->dd_loc */ - - for (rewind = true;;) - { - register struct dirent* dp; - - /* See whether the matching entry is in the current buffer. */ - - if ((dirp->dd_loc < dirp->dd_size /* valid index */ - || readdir(dirp) != NULL /* next buffer read */ - && (dirp->dd_loc = 0, true) /* beginning of buffer set */ - ) - && (dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off - <= loc /* match possible in this buffer */ - ) - { - for (/* dp initialized above */; - (char*)dp < &dirp->dd_buf[dirp->dd_size]; - dp = (struct dirent*)((char*)dp + dp->d_reclen)) - if (dp->d_off == loc) - { /* found it! */ - dirp->dd_loc = (char*)dp - dirp->dd_buf; - return; - } - - rewind = false; /* no point in backing up later */ - dirp->dd_loc = dirp->dd_size; /* set end of buffer */ - } - else /* whole buffer past matching entry */ - if (!rewind) - { /* no point in searching further */ - errno = EINVAL; - return; /* no entry at specified loc */ - } - else - { /* rewind directory and start over */ - rewind = false; /* but only once! */ - - dirp->dd_loc = dirp->dd_size = 0; - - if (_lseek(dirp->dd_fd, (off_t)0, SEEK_SET) - != 0) - return; /* errno already set (EBADF) */ - - if (loc == 0) - return; /* save time */ - } - } -} diff --git a/lang/cem/libcc.ansi/_dead/telldir.c b/lang/cem/libcc.ansi/_dead/telldir.c deleted file mode 100644 index 9db00740a..000000000 --- a/lang/cem/libcc.ansi/_dead/telldir.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - telldir -- report directory stream position - - last edit: 25-Apr-1987 D A Gwyn - - NOTE: 4.nBSD directory compaction makes seekdir() & telldir() - practically impossible to do right. Avoid using them! -*/ - -#include -#include -#include -#include - -extern off_t _lseek(int d, int offset, int whence); - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -off_t telldir(register DIR* dirp) /* return offset of next entry */ -{ - if (dirp == NULL || dirp->dd_buf == NULL) - { - errno = EFAULT; - return -1; /* invalid pointer */ - } - - if (dirp->dd_loc < dirp->dd_size) /* valid index */ - return ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off; - else /* beginning of next directory block */ - return _lseek(dirp->dd_fd, (off_t)0, SEEK_CUR); -}