diff --git a/build.lua b/build.lua index a1fe98e80..9bce99f90 100644 --- a/build.lua +++ b/build.lua @@ -12,7 +12,7 @@ vars.plats = { "linuxppc", "osx386", "osxppc", - --"qemuppc", +-- --"qemuppc", "pc86", "rpi", "pdpv7", @@ -22,7 +22,7 @@ vars.plats_with_tests = { "linux68k", "linux386", "linuxppc", - --"qemuppc", +-- --"qemuppc", "pc86", } 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 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 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/assert/assert.c deleted file mode 100644 index ac143b51c..000000000 --- a/lang/cem/libcc.ansi/assert/assert.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * assert.c - diagnostics - */ -/* $Id$ */ - -#include -#include -#include - -void __bad_assertion(const char *mess) { - - fputs(mess, stderr); - abort(); -} diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 27704f208..ee1049d66 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 = { "./core/ctype/char.tab" } } normalrule { name = "ctype_files", - ins = { "./ctype/genfiles" }, + ins = { "./core/ctype/genfiles" }, outleaves = { "isalnum.c", "isalpha.c", @@ -33,31 +33,31 @@ for _, plat in ipairs(vars.plats) do srcs = { "+ctype_files", "+ctype_tab", - "./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", - "./stdlib/*.c", - "./string/*.c", - "./time/*.c", + "./core/ctype/*.c", + "./core/errno/*.c", + "./core/locale/*.c", + "./core/math/*.c", + "./core/math/*.e", + "./core/misc/*.c", + "./core/setjmp/*.c", + "./core/setjmp/*.e", + "./core/stdlib/*.c", + "./core/string/*.c", + "./core/time/*.c", + "./sys/exit/*.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", - "./malloc/malloc.h", - "./math/localmath.h", - "./stdio/loc_incl.h", - "./stdlib/ext_fmt.h", - "./time/loc_time.h", + "./core/math/localmath.h", + "./core/stdlib/ext_fmt.h", + "./core/time/loc_time.h", + "./sys/malloc/malloc.h", + "./sys/stdio/loc_incl.h", }, vars = { plat = plat } } 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/ctype/char.tab b/lang/cem/libcc.ansi/core/ctype/char.tab similarity index 100% rename from lang/cem/libcc.ansi/ctype/char.tab rename to lang/cem/libcc.ansi/core/ctype/char.tab diff --git a/lang/cem/libcc.ansi/ctype/genfiles b/lang/cem/libcc.ansi/core/ctype/genfiles similarity index 100% rename from lang/cem/libcc.ansi/ctype/genfiles rename to lang/cem/libcc.ansi/core/ctype/genfiles diff --git a/lang/cem/libcc.ansi/core/ctype/tolower.c b/lang/cem/libcc.ansi/core/ctype/tolower.c new file mode 100644 index 000000000..0d5ece39d --- /dev/null +++ b/lang/cem/libcc.ansi/core/ctype/tolower.c @@ -0,0 +1,6 @@ +#include + +int tolower(int c) +{ + return isupper(c) ? c - 'A' + 'a' : c; +} diff --git a/lang/cem/libcc.ansi/core/ctype/toupper.c b/lang/cem/libcc.ansi/core/ctype/toupper.c new file mode 100644 index 000000000..8b77933c5 --- /dev/null +++ b/lang/cem/libcc.ansi/core/ctype/toupper.c @@ -0,0 +1,6 @@ +#include + +int toupper(int c) +{ + return islower(c) ? c - 'a' + 'A' : c; +} diff --git a/lang/cem/libcc.ansi/core/errno/errlist.c b/lang/cem/libcc.ansi/core/errno/errlist.c new file mode 100644 index 000000000..1177777b1 --- /dev/null +++ b/lang/cem/libcc.ansi/core/errno/errlist.c @@ -0,0 +1,47 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#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 int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]); diff --git a/lang/cem/libcc.ansi/core/errno/perror.c b/lang/cem/libcc.ansi/core/errno/perror.c new file mode 100644 index 000000000..1ff33f2c3 --- /dev/null +++ b/lang/cem/libcc.ansi/core/errno/perror.c @@ -0,0 +1,19 @@ +/* + * perror.c - print an error message on the standard error output + */ +/* $Id$ */ + +#include +#include +#include + +void perror(const char* s) +{ + if (s && *s) + { + (void)fputs(s, stderr); + (void)fputs(": ", stderr); + } + (void)fputs(strerror(errno), stderr); + (void)fputs("\n", stderr); +} diff --git a/lang/cem/libcc.ansi/string/strerror.c b/lang/cem/libcc.ansi/core/errno/strerror.c similarity index 68% rename from lang/cem/libcc.ansi/string/strerror.c rename to lang/cem/libcc.ansi/core/errno/strerror.c index 62f787ce6..c00276ac5 100644 --- a/lang/cem/libcc.ansi/string/strerror.c +++ b/lang/cem/libcc.ansi/core/errno/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/locale/localeconv.c b/lang/cem/libcc.ansi/core/locale/localeconv.c similarity index 88% rename from lang/cem/libcc.ansi/locale/localeconv.c rename to lang/cem/libcc.ansi/core/locale/localeconv.c index 766a4b87c..16da65cd6 100644 --- a/lang/cem/libcc.ansi/locale/localeconv.c +++ b/lang/cem/libcc.ansi/core/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/core/locale/setlocale.c b/lang/cem/libcc.ansi/core/locale/setlocale.c new file mode 100644 index 000000000..76780c444 --- /dev/null +++ b/lang/cem/libcc.ansi/core/locale/setlocale.c @@ -0,0 +1,30 @@ +/* + * setlocale - set the programs locale + */ +/* $Id$ */ + +#include +#include + +struct lconv _lc; + +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; + } +} diff --git a/lang/cem/libcc.ansi/math/asin.c b/lang/cem/libcc.ansi/core/math/asin.c similarity index 64% rename from lang/cem/libcc.ansi/math/asin.c rename to lang/cem/libcc.ansi/core/math/asin.c index 2a7ddd7c7..ffa286e40 100644 --- a/lang/cem/libcc.ansi/math/asin.c +++ b/lang/cem/libcc.ansi/core/math/asin.c @@ -6,66 +6,79 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT 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; } @@ -80,3 +93,5 @@ acos(double x) { return asin_acos(x, 1); } + +#endif diff --git a/lang/cem/libcc.ansi/math/atan.c b/lang/cem/libcc.ansi/core/math/atan.c similarity index 55% rename from lang/cem/libcc.ansi/math/atan.c rename to lang/cem/libcc.ansi/core/math/atan.c index 055d0fdba..c1d52f6a3 100644 --- a/lang/cem/libcc.ansi/math/atan.c +++ b/lang/cem/libcc.ansi/core/math/atan.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT double atan(double x) @@ -26,47 +29,55 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/atan2.c b/lang/cem/libcc.ansi/core/math/atan2.c similarity index 70% rename from lang/cem/libcc.ansi/math/atan2.c rename to lang/cem/libcc.ansi/core/math/atan2.c index b822f989a..ec1b45c7e 100644 --- a/lang/cem/libcc.ansi/math/atan2.c +++ b/lang/cem/libcc.ansi/core/math/atan2.c @@ -6,37 +6,49 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT 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; } return val + M_PI; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/ceil.c b/lang/cem/libcc.ansi/core/math/ceil.c similarity index 73% rename from lang/cem/libcc.ansi/math/ceil.c rename to lang/cem/libcc.ansi/core/math/ceil.c index eab485e2e..e5671739b 100644 --- a/lang/cem/libcc.ansi/math/ceil.c +++ b/lang/cem/libcc.ansi/core/math/ceil.c @@ -6,15 +6,21 @@ */ /* $Id$ */ -#include +#include +#include + +#if ACKCONF_WANT_FLOAT 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 */ } + +#endif + diff --git a/lang/cem/libcc.ansi/math/exp.c b/lang/cem/libcc.ansi/core/math/exp.c similarity index 62% rename from lang/cem/libcc.ansi/math/exp.c rename to lang/cem/libcc.ansi/core/math/exp.c index 95014d6bc..5bbdc1978 100644 --- a/lang/cem/libcc.ansi/math/exp.c +++ b/lang/cem/libcc.ansi/core/math/exp.c @@ -6,11 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" +#if ACKCONF_WANT_FLOAT double exp(double x) @@ -32,41 +34,49 @@ 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)); } + +#endif + diff --git a/lang/cem/libcc.ansi/math/fabs.c b/lang/cem/libcc.ansi/core/math/fabs.c similarity index 74% rename from lang/cem/libcc.ansi/math/fabs.c rename to lang/cem/libcc.ansi/core/math/fabs.c index e7a533de5..5c467e415 100644 --- a/lang/cem/libcc.ansi/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; + return x < 0 ? -x : x; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/floor.c b/lang/cem/libcc.ansi/core/math/floor.c similarity index 73% rename from lang/cem/libcc.ansi/math/floor.c rename to lang/cem/libcc.ansi/core/math/floor.c index 0be49ca42..bce630bd2 100644 --- a/lang/cem/libcc.ansi/math/floor.c +++ b/lang/cem/libcc.ansi/core/math/floor.c @@ -6,15 +6,21 @@ */ /* $Id$ */ -#include +#include +#include + +#if ACKCONF_WANT_FLOAT 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 */ } + +#endif + diff --git a/lang/cem/libcc.ansi/core/math/fmod.c b/lang/cem/libcc.ansi/core/math/fmod.c new file mode 100644 index 000000000..3329a41b1 --- /dev/null +++ b/lang/cem/libcc.ansi/core/math/fmod.c @@ -0,0 +1,45 @@ +/* fmod function */ +/* Author Robert R. Hall (hall@crach.cts.com) */ + +/* $Id$ */ + +#include +#include +#include + +#if ACKCONF_WANT_FLOAT + +double(fmod)(double x, double y) +{ /* compute fmod(x, y) */ + double t; + int n, neg; + int ychar, xchar; + + 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; + t = frexp(y, &ychar); + /* 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; + } + return (neg ? -x : x); +} + +#endif + diff --git a/lang/cem/libcc.ansi/math/frexp.e b/lang/cem/libcc.ansi/core/math/frexp.e similarity index 85% rename from lang/cem/libcc.ansi/math/frexp.e rename to lang/cem/libcc.ansi/core/math/frexp.e index d3ccca819..0e64b4b1b 100644 --- a/lang/cem/libcc.ansi/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/math/hugeval.c b/lang/cem/libcc.ansi/core/math/hugeval.c similarity index 83% rename from lang/cem/libcc.ansi/math/hugeval.c rename to lang/cem/libcc.ansi/core/math/hugeval.c index 2d51c2994..6d526f2c8 100644 --- a/lang/cem/libcc.ansi/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/math/hypot.c b/lang/cem/libcc.ansi/core/math/hypot.c similarity index 67% rename from lang/cem/libcc.ansi/math/hypot.c rename to lang/cem/libcc.ansi/core/math/hypot.c index 612a4bde1..f3e70819f 100644 --- a/lang/cem/libcc.ansi/math/hypot.c +++ b/lang/cem/libcc.ansi/core/math/hypot.c @@ -6,29 +6,37 @@ */ #include +#include + +#if ACKCONF_WANT_FLOAT /* $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 @@ -36,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 new file mode 100644 index 000000000..9203875ce --- /dev/null +++ b/lang/cem/libcc.ansi/core/math/isnan.c @@ -0,0 +1,19 @@ +#include +#include + +#if ACKCONF_WANT_FLOAT + +__IsNan(double d) +{ +#if defined(__vax) || defined(__pdp) +#else + float f = d; + + if ((*((long*)&f) & 0x7f800000) == 0x7f800000 && (*((long*)&f) & 0x007fffff) != 0) + return 1; +#endif + return 0; +} + +#endif + diff --git a/lang/cem/libcc.ansi/math/ldexp.c b/lang/cem/libcc.ansi/core/math/ldexp.c similarity index 50% rename from lang/cem/libcc.ansi/math/ldexp.c rename to lang/cem/libcc.ansi/core/math/ldexp.c index eb7e3d9ee..683c70e6c 100644 --- a/lang/cem/libcc.ansi/math/ldexp.c +++ b/lang/cem/libcc.ansi/core/math/ldexp.c @@ -4,9 +4,12 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include +#include + +#if ACKCONF_WANT_FLOAT double ldexp(double fl, int exp) @@ -14,42 +17,55 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/localmath.h b/lang/cem/libcc.ansi/core/math/localmath.h similarity index 100% rename from lang/cem/libcc.ansi/math/localmath.h rename to lang/cem/libcc.ansi/core/math/localmath.h diff --git a/lang/cem/libcc.ansi/math/log.c b/lang/cem/libcc.ansi/core/math/log.c similarity index 65% rename from lang/cem/libcc.ansi/math/log.c rename to lang/cem/libcc.ansi/core/math/log.c index c1ec51f95..3c698c10a 100644 --- a/lang/cem/libcc.ansi/math/log.c +++ b/lang/cem/libcc.ansi/core/math/log.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT double log(double x) @@ -20,48 +23,59 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/log10.c b/lang/cem/libcc.ansi/core/math/log10.c similarity index 68% rename from lang/cem/libcc.ansi/math/log10.c rename to lang/cem/libcc.ansi/core/math/log10.c index b759c8478..1c170026c 100644 --- a/lang/cem/libcc.ansi/math/log10.c +++ b/lang/cem/libcc.ansi/core/math/log10.c @@ -6,25 +6,34 @@ */ /* $Id$ */ -#include -#include -#include "localmath.h" +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT 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; } return log(x) / M_LN10; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/modf.e b/lang/cem/libcc.ansi/core/math/modf.e similarity index 87% rename from lang/cem/libcc.ansi/math/modf.e rename to lang/cem/libcc.ansi/core/math/modf.e index 8e819a7f5..8f0ea8adb 100644 --- a/lang/cem/libcc.ansi/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/math/pow.c b/lang/cem/libcc.ansi/core/math/pow.c similarity index 52% rename from lang/cem/libcc.ansi/math/pow.c rename to lang/cem/libcc.ansi/core/math/pow.c index 639dc07e5..3fb40cb7f 100644 --- a/lang/cem/libcc.ansi/math/pow.c +++ b/lang/cem/libcc.ansi/core/math/pow.c @@ -6,95 +6,123 @@ */ /* $Id$ */ -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#if ACKCONF_WANT_FLOAT 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); } + +#endif + diff --git a/lang/cem/libcc.ansi/math/sin.c b/lang/cem/libcc.ansi/core/math/sin.c similarity index 67% rename from lang/cem/libcc.ansi/math/sin.c rename to lang/cem/libcc.ansi/core/math/sin.c index 9c4591d5a..9a4078c56 100644 --- a/lang/cem/libcc.ansi/math/sin.c +++ b/lang/cem/libcc.ansi/core/math/sin.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT static double sinus(double x, int cos_flag) @@ -21,39 +24,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 +71,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 +82,9 @@ sinus(double x, int cos_flag) #undef A1 #undef A2 } - - if (x < 0) { + + if (x < 0) + { neg = -neg; x = -x; } @@ -82,7 +93,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 +105,10 @@ sin(double x) double cos(double x) { - if (x < 0) x = -x; + if (x < 0) + x = -x; return sinus(x, 1); } + +#endif + diff --git a/lang/cem/libcc.ansi/math/sinh.c b/lang/cem/libcc.ansi/core/math/sinh.c similarity index 59% rename from lang/cem/libcc.ansi/math/sinh.c rename to lang/cem/libcc.ansi/core/math/sinh.c index bce95441d..a16535527 100644 --- a/lang/cem/libcc.ansi/math/sinh.c +++ b/lang/cem/libcc.ansi/core/math/sinh.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT static double sinh_cosh(double x, int cosh_flag) @@ -27,42 +30,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 +85,10 @@ sinh(double x) double cosh(double x) { - if (x < 0) x = -x; + if (x < 0) + x = -x; return sinh_cosh(x, 1); } + +#endif + diff --git a/lang/cem/libcc.ansi/math/sqrt.c b/lang/cem/libcc.ansi/core/math/sqrt.c similarity index 56% rename from lang/cem/libcc.ansi/math/sqrt.c rename to lang/cem/libcc.ansi/core/math/sqrt.c index 172f35059..b5a6f71cf 100644 --- a/lang/cem/libcc.ansi/math/sqrt.c +++ b/lang/cem/libcc.ansi/core/math/sqrt.c @@ -6,11 +6,14 @@ */ /* $Id$ */ -#include -#include -#include +#include +#include +#include +#include -#define NITER 5 +#if ACKCONF_WANT_FLOAT + +#define NITER 5 double sqrt(double x) @@ -18,26 +21,35 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/tan.c b/lang/cem/libcc.ansi/core/math/tan.c similarity index 59% rename from lang/cem/libcc.ansi/math/tan.c rename to lang/cem/libcc.ansi/core/math/tan.c index 159071d87..b51df5a74 100644 --- a/lang/cem/libcc.ansi/math/tan.c +++ b/lang/cem/libcc.ansi/core/math/tan.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT double tan(double x) @@ -21,56 +24,64 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/math/tanh.c b/lang/cem/libcc.ansi/core/math/tanh.c similarity index 55% rename from lang/cem/libcc.ansi/math/tanh.c rename to lang/cem/libcc.ansi/core/math/tanh.c index 0e351029b..3978c2427 100644 --- a/lang/cem/libcc.ansi/math/tanh.c +++ b/lang/cem/libcc.ansi/core/math/tanh.c @@ -6,10 +6,13 @@ */ /* $Id$ */ -#include -#include -#include -#include "localmath.h" +#include +#include +#include +#include +#include "localmath.h" + +#if ACKCONF_WANT_FLOAT double tanh(double x) @@ -25,31 +28,39 @@ 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; } + +#endif + diff --git a/lang/cem/libcc.ansi/core/misc/abort.c b/lang/cem/libcc.ansi/core/misc/abort.c new file mode 100644 index 000000000..d59624169 --- /dev/null +++ b/lang/cem/libcc.ansi/core/misc/abort.c @@ -0,0 +1,14 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include +#include +#include + +void abort(void) +{ + raise(SIGABRT); +} diff --git a/lang/cem/libcc.ansi/core/misc/assert.c b/lang/cem/libcc.ansi/core/misc/assert.c new file mode 100644 index 000000000..be1df2037 --- /dev/null +++ b/lang/cem/libcc.ansi/core/misc/assert.c @@ -0,0 +1,15 @@ +/* + * assert.c - diagnostics + */ +/* $Id$ */ + +#include +#include +#include + +void __bad_assertion(const char* mess) +{ + + fputs(mess, stderr); + abort(); +} diff --git a/lang/cem/libcc.ansi/core/misc/getopt.c b/lang/cem/libcc.ansi/core/misc/getopt.c new file mode 100644 index 000000000..9c9b88e20 --- /dev/null +++ b/lang/cem/libcc.ansi/core/misc/getopt.c @@ -0,0 +1,72 @@ +/* + * getopt - parse command-line options + */ +/* $Id$ */ + +#include +#include + +#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 getopt(int argc, char** argv, char* opts) +{ + static int sp = 1; + register c; + register char* cp; + + if (sp == 1) + if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') + return EOF; + 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') + { + 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); + sp = 1; + return '?'; + } + else + optarg = argv[optind++]; + sp = 1; + } + else + { + if (argv[optind][++sp] == '\0') + { + sp = 1; + optind++; + } + optarg = NULL; + } + return c; +} diff --git a/lang/cem/libcc.ansi/signal/raise.c b/lang/cem/libcc.ansi/core/misc/raise.c similarity index 80% rename from lang/cem/libcc.ansi/signal/raise.c rename to lang/cem/libcc.ansi/core/misc/raise.c index 42b3b4cec..e50193136 100644 --- a/lang/cem/libcc.ansi/signal/raise.c +++ b/lang/cem/libcc.ansi/core/misc/raise.c @@ -4,15 +4,17 @@ */ /* $Id$ */ -#if defined(_POSIX_SOURCE) +#include #include -#endif #include -int -raise(int sig) +#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/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/setjmp/setjmp.e b/lang/cem/libcc.ansi/core/setjmp/setjmp.e similarity index 100% rename from lang/cem/libcc.ansi/setjmp/setjmp.e rename to lang/cem/libcc.ansi/core/setjmp/setjmp.e diff --git a/lang/cem/libcc.ansi/setjmp/sigmisc.c b/lang/cem/libcc.ansi/core/setjmp/sigmisc.c similarity index 55% rename from lang/cem/libcc.ansi/setjmp/sigmisc.c rename to lang/cem/libcc.ansi/core/setjmp/sigmisc.c index 3c807e126..d9c58d092 100644 --- a/lang/cem/libcc.ansi/setjmp/sigmisc.c +++ b/lang/cem/libcc.ansi/core/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/stdio/fgetpos.c b/lang/cem/libcc.ansi/core/stdio/fgetpos.c similarity index 53% rename from lang/cem/libcc.ansi/stdio/fgetpos.c rename to lang/cem/libcc.ansi/core/stdio/fgetpos.c index 20ff8bed5..687fbef17 100644 --- a/lang/cem/libcc.ansi/stdio/fgetpos.c +++ b/lang/cem/libcc.ansi/core/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/fsetpos.c b/lang/cem/libcc.ansi/core/stdio/fsetpos.c similarity index 64% rename from lang/cem/libcc.ansi/stdio/fsetpos.c rename to lang/cem/libcc.ansi/core/stdio/fsetpos.c index a2a06ce0b..629abeed6 100644 --- a/lang/cem/libcc.ansi/stdio/fsetpos.c +++ b/lang/cem/libcc.ansi/core/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/core/stdio/gets.c b/lang/cem/libcc.ansi/core/stdio/gets.c new file mode 100644 index 000000000..c58db3378 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdio/gets.c @@ -0,0 +1,31 @@ +/* + * gets.c - read a line from a stream + */ +/* $Id$ */ + +#include + +char* gets(char* s) +{ + register FILE* stream = stdin; + register int ch; + 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; + } + + *ptr = '\0'; + return s; +} diff --git a/lang/cem/libcc.ansi/core/stdio/getw.c b/lang/cem/libcc.ansi/core/stdio/getw.c new file mode 100644 index 000000000..7b1f1f95e --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdio/getw.c @@ -0,0 +1,21 @@ +/* + * getw - read a word from a stream + */ +/* $Id$ */ + +#include + +int getw(register FILE* stream) +{ + register int cnt = sizeof(int); + int w; + register char* p = (char*)&w; + + while (cnt--) + { + *p++ = getc(stream); + } + if (feof(stream) || ferror(stream)) + return EOF; + return w; +} diff --git a/lang/cem/libcc.ansi/core/stdio/putw.c b/lang/cem/libcc.ansi/core/stdio/putw.c new file mode 100644 index 000000000..d5c137df2 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdio/putw.c @@ -0,0 +1,20 @@ +/* + * putw - write an word on a stream + */ +/* $Id$ */ + +#include + +int putw(int w, register FILE* stream) +{ + register int cnt = sizeof(int); + register char* p = (char*)&w; + + while (cnt--) + { + putc(*p++, stream); + } + if (ferror(stream)) + return EOF; + return w; +} diff --git a/lang/cem/libcc.ansi/stdio/rewind.c b/lang/cem/libcc.ansi/core/stdio/rewind.c similarity index 52% rename from lang/cem/libcc.ansi/stdio/rewind.c rename to lang/cem/libcc.ansi/core/stdio/rewind.c index f3c9b22c3..db2a5e2a4 100644 --- a/lang/cem/libcc.ansi/stdio/rewind.c +++ b/lang/cem/libcc.ansi/core/stdio/rewind.c @@ -3,12 +3,10 @@ */ /* $Id$ */ -#include -#include "loc_incl.h" +#include -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/stdlib/abs.c b/lang/cem/libcc.ansi/core/stdlib/abs.c similarity index 82% rename from lang/cem/libcc.ansi/stdlib/abs.c rename to lang/cem/libcc.ansi/core/stdlib/abs.c index 04a0fb642..3270f087a 100644 --- a/lang/cem/libcc.ansi/stdlib/abs.c +++ b/lang/cem/libcc.ansi/core/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/atof.c b/lang/cem/libcc.ansi/core/stdlib/atof.c similarity index 59% rename from lang/cem/libcc.ansi/stdlib/atof.c rename to lang/cem/libcc.ansi/core/stdlib/atof.c index 834dc9242..d8092b841 100644 --- a/lang/cem/libcc.ansi/stdlib/atof.c +++ b/lang/cem/libcc.ansi/core/stdlib/atof.c @@ -4,16 +4,20 @@ */ /* $Id$ */ -#include -#include +#include +#include +#include -double -(atof)(const char *nptr) +#if ACKCONF_WANT_FLOAT + +double(atof)(const char* nptr) { double d; int e = errno; - d = strtod(nptr, (char **) NULL); + d = strtod(nptr, (char**)NULL); errno = e; return d; } + +#endif diff --git a/lang/cem/libcc.ansi/stdlib/atoi.c b/lang/cem/libcc.ansi/core/stdlib/atoi.c similarity index 70% rename from lang/cem/libcc.ansi/stdlib/atoi.c rename to lang/cem/libcc.ansi/core/stdlib/atoi.c index f8dd99d8f..6cd0c8d05 100644 --- a/lang/cem/libcc.ansi/stdlib/atoi.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/atol.c similarity index 70% rename from lang/cem/libcc.ansi/stdlib/atol.c rename to lang/cem/libcc.ansi/core/stdlib/atol.c index 456852cb5..27adb3479 100644 --- a/lang/cem/libcc.ansi/stdlib/atol.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/bsearch.c b/lang/cem/libcc.ansi/core/stdlib/bsearch.c new file mode 100644 index 000000000..519fff9dd --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/bsearch.c @@ -0,0 +1,30 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#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*)) +{ + register const void* mid_point; + register int cmp; + + 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; + nmemb = (nmemb - 1) >> 1; + } + else + nmemb >>= 1; + } + return (void*)NULL; +} diff --git a/lang/cem/libcc.ansi/stdlib/div.c b/lang/cem/libcc.ansi/core/stdlib/div.c similarity index 59% rename from lang/cem/libcc.ansi/stdlib/div.c rename to lang/cem/libcc.ansi/core/stdlib/div.c index 659363564..42f739b0e 100644 --- a/lang/cem/libcc.ansi/stdlib/div.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/ecvt.c b/lang/cem/libcc.ansi/core/stdlib/ecvt.c new file mode 100644 index 000000000..f17ec9f50 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/ecvt.c @@ -0,0 +1,30 @@ +/* $Id$ */ + +#include +#include + +#if ACKCONF_WANT_STDIO_FLOAT + +#include "ext_fmt.h" + +static char* +cvt(long double value, int ndigit, int* decpt, int* sign, int ecvtflag) +{ + struct EXTEND e; + + _dbl_ext_cvt(value, &e); + return _ext_str_cvt(&e, ndigit, decpt, sign, ecvtflag); +} + +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) +{ + return cvt(value, ndigit, decpt, sign, 0); +} + +#endif 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 diff --git a/lang/cem/libcc.ansi/core/stdlib/ext_comp.c b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c new file mode 100644 index 000000000..28eb213a4 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/ext_comp.c @@ -0,0 +1,839 @@ +/* + (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands. + See the copyright notice in the ACK home directory, in the file "Copyright". +*/ + +/* $Id$ */ + +/* extended precision arithmetic for the strtod() and cvt() routines */ + +/* This may require some more work when long doubles get bigger than 8 + bytes. In this case, these routines may become obsolete. ??? +*/ + +#include "ext_fmt.h" +#include +#include +#include +#include + +#if ACKCONF_WANT_FLOAT + +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) +{ + /* 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 unsigned short* pres; + + /* first save the sign (XOR) */ + e3->sign = e1->sign ^ e2->sign; + + /* compute new exponent */ + e3->exp = e1->exp + e2->exp + 1; + + /* check for overflow/underflow ??? */ + + /* 128 bit multiply of mantissas */ + + /* assign unknown long formats */ + /* to known unsigned word formats */ + mp[0] = e1->m1 >> 16; + mp[1] = (unsigned short)e1->m1; + mp[2] = e1->m2 >> 16; + mp[3] = (unsigned short)e1->m2; + mc[0] = e2->m1 >> 16; + mc[1] = (unsigned short)e2->m1; + mc[2] = e2->m2 >> 16; + 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; + } + pres[-1] = k; + } + + if (!(result[0] & 0x8000)) + { + e3->exp--; + for (i = 0; i <= 3; i++) + { + 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) + { + e3->m1 = 0x80000000; + e3->exp++; + } + } + } +} + +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 + */ + struct EXTEND ce2; + int diff; + + if ((e2->m1 | e2->m2) == 0L) + { + *e3 = *e1; + return; + } + if ((e1->m1 | e1->m2) == 0L) + { + *e3 = *e2; + return; + } + ce2 = *e2; + *e3 = *e1; + e1 = &ce2; + + /* adjust mantissas to equal power */ + diff = e3->exp - e1->exp; + if (diff < 0) + { + diff = -diff; + e3->exp += diff; + b64_sft(&(e3->mantissa), diff); + } + else if (diff > 0) + { + e1->exp += diff; + b64_sft(&(e1->mantissa), diff); + } + 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 ((e3->m2 | e3->m1) != 0L) + { + /* normalize */ + if (e3->m1 == 0L) + { + e3->m1 = e3->m2; + e3->m2 = 0L; + e3->exp -= 32; + } + if (!(e3->m1 & 0x80000000)) + { + unsigned long l = 0x40000000; + int cnt = -1; + + while (!(l & e3->m1)) + { + l >>= 1; + cnt--; + } + e3->exp += cnt; + b64_sft(&(e3->mantissa), cnt); + } + } +} + +static int +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; +} + +static b64_sft(struct mantissa* e1, int n) +{ + if (n > 0) + { + if (n > 63) + { + e1->l_32 = 0; + e1->h_32 = 0; + return; + } + if (n >= 32) + { + e1->l_32 = e1->h_32; + e1->h_32 = 0; + n -= 32; + } + if (n > 0) + { + e1->l_32 >>= n; + if (e1->h_32 != 0) + { + e1->l_32 |= (e1->h_32 << (32 - n)); + e1->h_32 >>= n; + } + } + return; + } + n = -n; + if (n > 0) + { + if (n > 63) + { + e1->l_32 = 0; + e1->h_32 = 0; + return; + } + if (n >= 32) + { + e1->h_32 = e1->l_32; + e1->l_32 = 0; + n -= 32; + } + if (n > 0) + { + e1->h_32 <<= n; + if (e1->l_32 != 0) + { + e1->h_32 |= (e1->l_32 >> (32 - n)); + e1->l_32 <<= n; + } + } + } +} + +static int +b64_add(struct mantissa* e1, struct mantissa* e2) +/* + * pointers to 64 bit 'registers' + */ +{ + register int overflow; + int carry; + + /* 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); + e1->l_32 += e2->l_32; + if ((carry) && (++e1->h_32 == 0)) + return (1); /* had a 64 bit overflow */ + else + return (overflow); /* return status from higher add */ +} + +/* The following tables can be computed with the following bc(1) + program: + +obase=16 +scale=0 +define t(x){ + auto a, b, c + a=2;b=1;c=2^32;n=1 + while(asign = 0; + e->exp = 0; + e->m1 = e->m2 = 0; + + c = *s; + switch (c) + { + case '-': + e->sign = 1; + case '+': + s++; + } + while (c = *s++, isdigit(c) || (c == '.' && !dotseen++)) + { + if (c == '.') + continue; + digitseen = 1; + if (e->m1 <= (unsigned long)(0xFFFFFFFF) / 10) + { + struct mantissa a1; + + a1 = e->mantissa; + b64_sft(&(e->mantissa), -3); + b64_sft(&a1, -1); + b64_add(&(e->mantissa), &a1); + a1.h_32 = 0; + a1.l_32 = c - '0'; + b64_add(&(e->mantissa), &a1); + } + else + exp++; + if (dotseen) + exp--; + } + if (!digitseen) + return; + + if (ss) + *ss = (char*)s - 1; + + if (c == 'E' || c == 'e') + { + int exp1 = 0; + int sign = 1; + int exp_overflow = 0; + + switch (*s) + { + case '-': + sign = -1; + case '+': + s++; + } + if (c = *s, isdigit(c)) + { + do + { + int tmp; + + exp1 = 10 * exp1 + (c - '0'); + if ((tmp = sign * exp1 + exp) > MAX_EXP || tmp < -MAX_EXP) + { + exp_overflow = 1; + } + } while (c = *++s, isdigit(c)); + if (ss) + *ss = (char*)s; + } + exp += sign * exp1; + if (exp_overflow) + { + exp = sign * MAX_EXP; + if (e->m1 != 0 || e->m2 != 0) + errno = ERANGE; + } + } + if (e->m1 == 0 && e->m2 == 0) + return; + e->exp = 63; + while (!(e->m1 & 0x80000000)) + { + b64_sft(&(e->mantissa), -1); + e->exp--; + } + add_exponent(e, exp); +} + +#include + +static ten_mult(struct EXTEND* e) +{ + struct EXTEND e1 = *e; + + e1.exp++; + e->exp += 3; + add_ext(e, &e1, e); +} + +#define NDIGITS 128 +#define NSIGNIFICANT 19 + +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]; + struct EXTEND m; + register char* p = buf; + register char* pe; + int findex = 0; + + if (ndigit < 0) + ndigit = 0; + if (ndigit > NDIGITS) + ndigit = NDIGITS; + pe = &buf[ndigit]; + buf[0] = '\0'; + + *sign = 0; + if (e->sign) + { + *sign = 1; + e->sign = 0; + } + + *decpt = 0; + if (e->m1 != 0) + { + register struct EXTEND* pp = &big_ten_powers[1]; + + while (cmp_ext(e, pp) >= 0) + { + pp++; + findex = pp - big_ten_powers; + if (findex >= BTP) + break; + } + pp--; + findex = pp - big_ten_powers; + 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++; + pp--; + findex = pp - ten_powers; + *decpt += findex; + + if (cmp_ext(e, &ten_powers[0]) < 0) + { + pp = &r_big_ten_powers[1]; + while (cmp_ext(e, pp) < 0) + pp++; + pp--; + findex = pp - r_big_ten_powers; + mul_ext(e, &big_ten_powers[findex], e); + *decpt -= findex * TP; + /* here, value >= 10 ** -28 */ + ten_mult(e); + (*decpt)--; + pp = &r_ten_powers[0]; + 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) */ + } + if (!ecvtflag) + { + /* for fcvt() we need ndigit digits behind the dot */ + pe += *decpt; + if (pe > &buf[NDIGITS]) + pe = &buf[NDIGITS]; + } + m.exp = -62; + m.sign = 0; + m.m1 = 0xA0000000; + m.m2 = 0; + while (p <= pe) + { + struct EXTEND oneminm; + + if (p - pe > NSIGNIFICANT) + { + findex = 0; + e->m1 = 0; + } + if (findex) + { + struct EXTEND tc, oldtc; + int count = 0; + + oldtc.exp = 0; + oldtc.sign = 0; + oldtc.m1 = 0; + oldtc.m2 = 0; + tc = ten_powers[findex]; + while (cmp_ext(e, &tc) >= 0) + { + oldtc = tc; + add_ext(&tc, &ten_powers[findex], &tc); + count++; + } + *p++ = count + '0'; + oldtc.sign = 1; + add_ext(e, &oldtc, e); + findex--; + continue; + } + if (e->m1) + { + m.sign = 1; + add_ext(&ten_powers[0], &m, &oneminm); + m.sign = 0; + if (e->exp >= 0) + { + struct EXTEND x; + + x.m2 = 0; + x.exp = e->exp; + x.sign = 1; + x.m1 = e->m1 >> (31 - e->exp); + *p++ = (x.m1) + '0'; + x.m1 = x.m1 << (31 - e->exp); + add_ext(e, &x, e); + } + 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; + e->m1 = 0; + continue; + } + ten_mult(&m); + ten_mult(e); + } + else + *p++ = '0'; + } + if (pe >= buf) + { + p = pe; + *p += 5; /* round of at the end */ + while (*p > '9') + { + *p = '0'; + if (p > buf) + ++*--p; + else + { + *p = '1'; + ++*decpt; + if (!ecvtflag) + { + /* maybe add another digit at the end, + because the point was shifted right + */ + if (pe > buf) + *pe = '0'; + pe++; + } + } + } + *pe = '\0'; + } + return buf; +} + +void _dbl_ext_cvt(double value, struct EXTEND* e) +{ + /* Convert double to extended + */ + int exponent; + + value = frexp(value, &exponent); + e->sign = value < 0.0; + if (e->sign) + value = -value; + e->exp = exponent - 1; + value *= 4294967296.0; + e->m1 = value; + value -= e->m1; + value *= 4294967296.0; + e->m2 = value; +} + +static struct EXTEND max_d; + +double +_ext_dbl_cvt(struct EXTEND* e) +{ + /* Convert extended to double + */ + double f; + int sign = e->sign; + + e->sign = 0; + if (e->m1 == 0 && e->m2 == 0) + { + return 0.0; + } + if (max_d.exp == 0) + { + _dbl_ext_cvt(DBL_MAX, &max_d); + } + 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)) + { + errno = ERANGE; + } + 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/getenv.c b/lang/cem/libcc.ansi/core/stdlib/getenv.c similarity index 66% rename from lang/cem/libcc.ansi/stdlib/getenv.c rename to lang/cem/libcc.ansi/core/stdlib/getenv.c index 592e0c05d..3db5c3797 100644 --- a/lang/cem/libcc.ansi/stdlib/getenv.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/labs.c similarity index 81% rename from lang/cem/libcc.ansi/stdlib/labs.c rename to lang/cem/libcc.ansi/core/stdlib/labs.c index c19464939..e0acaed86 100644 --- a/lang/cem/libcc.ansi/stdlib/labs.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/ldiv.c similarity index 71% rename from lang/cem/libcc.ansi/stdlib/ldiv.c rename to lang/cem/libcc.ansi/core/stdlib/ldiv.c index 4f2b25eb2..e35c06715 100644 --- a/lang/cem/libcc.ansi/stdlib/ldiv.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/mblen.c similarity index 50% rename from lang/cem/libcc.ansi/stdlib/mblen.c rename to lang/cem/libcc.ansi/core/stdlib/mblen.c index f3c54a540..4c8f728e9 100644 --- a/lang/cem/libcc.ansi/stdlib/mblen.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/mbstowcs.c similarity index 72% rename from lang/cem/libcc.ansi/stdlib/mbstowcs.c rename to lang/cem/libcc.ansi/core/stdlib/mbstowcs.c index e2a6cf362..34d120e60 100644 --- a/lang/cem/libcc.ansi/stdlib/mbstowcs.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/mbtowc.c similarity index 51% rename from lang/cem/libcc.ansi/stdlib/mbtowc.c rename to lang/cem/libcc.ansi/core/stdlib/mbtowc.c index 3b1687c55..8e80ca263 100644 --- a/lang/cem/libcc.ansi/stdlib/mbtowc.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/putenv.c similarity index 57% rename from lang/cem/libcc.ansi/stdlib/putenv.c rename to lang/cem/libcc.ansi/core/stdlib/putenv.c index a1f94aba4..09412f341 100644 --- a/lang/cem/libcc.ansi/stdlib/putenv.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/qsort.c similarity index 68% rename from lang/cem/libcc.ansi/stdlib/qsort.c rename to lang/cem/libcc.ansi/core/stdlib/qsort.c index c7211fea8..c3129fcff 100644 --- a/lang/cem/libcc.ansi/stdlib/qsort.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/rand.c similarity index 77% rename from lang/cem/libcc.ansi/stdlib/rand.c rename to lang/cem/libcc.ansi/core/stdlib/rand.c index 87b5e1b5c..20f72e26b 100644 --- a/lang/cem/libcc.ansi/stdlib/rand.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/setenv.c b/lang/cem/libcc.ansi/core/stdlib/setenv.c new file mode 100644 index 000000000..c973bd58a --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/setenv.c @@ -0,0 +1,94 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include +#include + +extern char* _findenv(const char* name, int* offset); +extern char** environ; + +/* + * setenv(name,value,rewrite) + * Set the value of the environmental variable "name" to be + * "value". If rewrite is set, replace any current value. + */ +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; + + 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 = (char*) 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) +{ + register char** P; + int offset; + + while (_findenv(name, &offset)) /* if set multiple times */ + for (P = &environ[offset];; ++P) + if (!(*P = *(P + 1))) + break; + + return 0; +} diff --git a/lang/cem/libcc.ansi/core/stdlib/strtod.c b/lang/cem/libcc.ansi/core/stdlib/strtod.c new file mode 100644 index 000000000..36a568d05 --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/strtod.c @@ -0,0 +1,18 @@ +/* $Id$ */ + +#include +#include +#include "ext_fmt.h" + +#if ACKCONF_WANT_FLOAT + +double +strtod(const char* p, char** pp) +{ + struct EXTEND e; + + _str_ext_cvt(p, pp, &e); + return _ext_dbl_cvt(&e); +} + +#endif diff --git a/lang/cem/libcc.ansi/core/stdlib/strtol.c b/lang/cem/libcc.ansi/core/stdlib/strtol.c new file mode 100644 index 000000000..ce072d49d --- /dev/null +++ b/lang/cem/libcc.ansi/core/stdlib/strtol.c @@ -0,0 +1,116 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include +#include +#include +#include + +static unsigned long +string2long(register const char* nptr, char** endptr, + int base, int is_signed); + +long int +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) +{ + return (unsigned long)string2long(nptr, endptr, base, 0); +} + +static unsigned long +string2long(register const char* nptr, char** const endptr, + int base, int is_signed) +{ + register unsigned int v; + register unsigned long val = 0; + register int c; + int ovfl = 0, sign = 1; + const char *startnptr = nptr, *nrstart; + + if (endptr) + *endptr = (char*)nptr; + while (isspace(*nptr)) + nptr++; + c = *nptr; + + if (c == '-' || c == '+') + { + if (c == '-') + sign = -1; + nptr++; + } + 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') + { + base = 16; + nptr++; + } + 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) + { + 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; + } + nptr++; + } + if (endptr) + { + if (nrstart == nptr) + *endptr = (char*)startnptr; + else + *endptr = (char*)nptr; + } + + 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++; + } + + if (ovfl) + { + errno = ERANGE; + if (is_signed) + 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/wcstombs.c b/lang/cem/libcc.ansi/core/stdlib/wcstombs.c similarity index 65% rename from lang/cem/libcc.ansi/stdlib/wcstombs.c rename to lang/cem/libcc.ansi/core/stdlib/wcstombs.c index fccd626ed..2803b7b2a 100644 --- a/lang/cem/libcc.ansi/stdlib/wcstombs.c +++ b/lang/cem/libcc.ansi/core/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/core/stdlib/wctomb.c similarity index 61% rename from lang/cem/libcc.ansi/stdlib/wctomb.c rename to lang/cem/libcc.ansi/core/stdlib/wctomb.c index 3322b0d9c..d80f0baf0 100644 --- a/lang/cem/libcc.ansi/stdlib/wctomb.c +++ b/lang/cem/libcc.ansi/core/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/core/string/memchr.c b/lang/cem/libcc.ansi/core/string/memchr.c new file mode 100644 index 000000000..0d891e83d --- /dev/null +++ b/lang/cem/libcc.ansi/core/string/memchr.c @@ -0,0 +1,25 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include + +void* memchr(const void* s, register int c, register size_t n) +{ + register const unsigned char* s1 = s; + + c = (unsigned char)c; + if (n) + { + n++; + 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/core/string/memcmp.c similarity index 66% rename from lang/cem/libcc.ansi/string/memcmp.c rename to lang/cem/libcc.ansi/core/string/memcmp.c index b44eefcf4..625dbaafb 100644 --- a/lang/cem/libcc.ansi/string/memcmp.c +++ b/lang/cem/libcc.ansi/core/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/core/string/memcpy.c similarity index 57% rename from lang/cem/libcc.ansi/string/memcpy.c rename to lang/cem/libcc.ansi/core/string/memcpy.c index 32d4ba29c..d648815cd 100644 --- a/lang/cem/libcc.ansi/string/memcpy.c +++ b/lang/cem/libcc.ansi/core/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/core/string/memmove.c similarity index 56% rename from lang/cem/libcc.ansi/string/memmove.c rename to lang/cem/libcc.ansi/core/string/memmove.c index ec1dd8bad..78fbd0c6a 100644 --- a/lang/cem/libcc.ansi/string/memmove.c +++ b/lang/cem/libcc.ansi/core/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/core/string/memset.c similarity index 61% rename from lang/cem/libcc.ansi/string/memset.c rename to lang/cem/libcc.ansi/core/string/memset.c index 266b10c07..649f8c783 100644 --- a/lang/cem/libcc.ansi/string/memset.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strcat.c similarity index 65% rename from lang/cem/libcc.ansi/string/strcat.c rename to lang/cem/libcc.ansi/core/string/strcat.c index 4ef13ea17..613050957 100644 --- a/lang/cem/libcc.ansi/string/strcat.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strchr.c similarity index 53% rename from lang/cem/libcc.ansi/string/strchr.c rename to lang/cem/libcc.ansi/core/string/strchr.c index 2e7df4c23..da906e136 100644 --- a/lang/cem/libcc.ansi/string/strchr.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strcmp.c b/lang/cem/libcc.ansi/core/string/strcmp.c new file mode 100644 index 000000000..12406c956 --- /dev/null +++ b/lang/cem/libcc.ansi/core/string/strcmp.c @@ -0,0 +1,23 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include + +int strcmp(register const char* s1, register const char* s2) +{ + 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; +} diff --git a/lang/cem/libcc.ansi/string/strcoll.c b/lang/cem/libcc.ansi/core/string/strcoll.c similarity index 59% rename from lang/cem/libcc.ansi/string/strcoll.c rename to lang/cem/libcc.ansi/core/string/strcoll.c index 8a9b408b6..6e9a634af 100644 --- a/lang/cem/libcc.ansi/string/strcoll.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strcpy.c similarity index 66% rename from lang/cem/libcc.ansi/string/strcpy.c rename to lang/cem/libcc.ansi/core/string/strcpy.c index bd77c0d50..652f76376 100644 --- a/lang/cem/libcc.ansi/string/strcpy.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strcspn.c similarity index 62% rename from lang/cem/libcc.ansi/string/strcspn.c rename to lang/cem/libcc.ansi/core/string/strcspn.c index f99a5c441..37b22857e 100644 --- a/lang/cem/libcc.ansi/string/strcspn.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strdup.c similarity index 76% rename from lang/cem/libcc.ansi/string/strdup.c rename to lang/cem/libcc.ansi/core/string/strdup.c index d197171a9..0e7999ad7 100644 --- a/lang/cem/libcc.ansi/string/strdup.c +++ b/lang/cem/libcc.ansi/core/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/strlen.c b/lang/cem/libcc.ansi/core/string/strlen.c similarity index 71% rename from lang/cem/libcc.ansi/string/strlen.c rename to lang/cem/libcc.ansi/core/string/strlen.c index 48bee4e9d..acf3a8acf 100644 --- a/lang/cem/libcc.ansi/string/strlen.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strncat.c similarity index 53% rename from lang/cem/libcc.ansi/string/strncat.c rename to lang/cem/libcc.ansi/core/string/strncat.c index f0b8313c3..77013ccb0 100644 --- a/lang/cem/libcc.ansi/string/strncat.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strncmp.c similarity index 52% rename from lang/cem/libcc.ansi/string/strncmp.c rename to lang/cem/libcc.ansi/core/string/strncmp.c index 950ede4fe..b0e16b014 100644 --- a/lang/cem/libcc.ansi/string/strncmp.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strncpy.c b/lang/cem/libcc.ansi/core/string/strncpy.c new file mode 100644 index 000000000..bdf9129e7 --- /dev/null +++ b/lang/cem/libcc.ansi/core/string/strncpy.c @@ -0,0 +1,26 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include + +char* strncpy(char* ret, register const char* s2, register size_t n) +{ + register char* s1 = ret; + + if (n > 0) + { + while ((*s1++ = *s2++) && --n > 0) + /* EMPTY */; + if ((*--s2 == '\0') && --n > 0) + { + do + { + *s1++ = '\0'; + } while (--n > 0); + } + } + return ret; +} diff --git a/lang/cem/libcc.ansi/string/strpbrk.c b/lang/cem/libcc.ansi/core/string/strpbrk.c similarity index 55% rename from lang/cem/libcc.ansi/string/strpbrk.c rename to lang/cem/libcc.ansi/core/string/strpbrk.c index 98a4fab7e..aa517445d 100644 --- a/lang/cem/libcc.ansi/string/strpbrk.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strrchr.c similarity index 61% rename from lang/cem/libcc.ansi/string/strrchr.c rename to lang/cem/libcc.ansi/core/string/strrchr.c index 964b59f5e..b55ced1cd 100644 --- a/lang/cem/libcc.ansi/string/strrchr.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strspn.c similarity index 73% rename from lang/cem/libcc.ansi/string/strspn.c rename to lang/cem/libcc.ansi/core/string/strspn.c index ceb609f2e..908d6f9ea 100644 --- a/lang/cem/libcc.ansi/string/strspn.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strstr.c similarity index 64% rename from lang/cem/libcc.ansi/string/strstr.c rename to lang/cem/libcc.ansi/core/string/strstr.c index 578223542..2b9b1178d 100644 --- a/lang/cem/libcc.ansi/string/strstr.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strtok.c similarity index 64% rename from lang/cem/libcc.ansi/string/strtok.c rename to lang/cem/libcc.ansi/core/string/strtok.c index d2bbbde51..9582ea7c3 100644 --- a/lang/cem/libcc.ansi/string/strtok.c +++ b/lang/cem/libcc.ansi/core/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/core/string/strxfrm.c similarity index 63% rename from lang/cem/libcc.ansi/string/strxfrm.c rename to lang/cem/libcc.ansi/core/string/strxfrm.c index 7ce96a9f8..f6163bd5b 100644 --- a/lang/cem/libcc.ansi/string/strxfrm.c +++ b/lang/cem/libcc.ansi/core/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/core/time/asctime.c b/lang/cem/libcc.ansi/core/time/asctime.c new file mode 100644 index 000000000..dda8b8006 --- /dev/null +++ b/lang/cem/libcc.ansi/core/time/asctime.c @@ -0,0 +1,61 @@ +/* + * asctime - print a date + */ +/* $Id$ */ + +#include +#include +#include "loc_time.h" + +#define DATE_STR "??? ??? ?? ??:??:?? ????\n" + +static char* +two_digits(register char* pb, int i, int nospace) +{ + *pb = (i / 10) % 10 + '0'; + if (!nospace && *pb == '0') + *pb = ' '; + pb++; + *pb++ = (i % 10) + '0'; + return ++pb; +} + +static char* +four_digits(register char* pb, int i) +{ + i %= 10000; + *pb++ = (i / 1000) + '0'; + i %= 1000; + *pb++ = (i / 100) + '0'; + i %= 100; + *pb++ = (i / 10) + '0'; + *pb++ = (i % 10) + '0'; + return ++pb; +} + +char* asctime(const struct tm* timeptr) +{ + static char buf[26]; + 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++; + pb++; + ps = _months[timeptr->tm_mon]; + n = ABB_LEN; + 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); + + four_digits(pb, timeptr->tm_year + 1900); + return buf; +} diff --git a/lang/cem/libcc.ansi/time/ctime.c b/lang/cem/libcc.ansi/core/time/ctime.c similarity index 66% rename from lang/cem/libcc.ansi/time/ctime.c rename to lang/cem/libcc.ansi/core/time/ctime.c index f7e81b41f..775ef806c 100644 --- a/lang/cem/libcc.ansi/time/ctime.c +++ b/lang/cem/libcc.ansi/core/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/core/time/difftime.c similarity index 66% rename from lang/cem/libcc.ansi/time/difftime.c rename to lang/cem/libcc.ansi/core/time/difftime.c index 0ff2d6c3d..cd01e0080 100644 --- a/lang/cem/libcc.ansi/time/difftime.c +++ b/lang/cem/libcc.ansi/core/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/core/time/gmtime.c similarity index 68% rename from lang/cem/libcc.ansi/time/gmtime.c rename to lang/cem/libcc.ansi/core/time/gmtime.c index 03578a91c..0dcb1c25d 100644 --- a/lang/cem/libcc.ansi/time/gmtime.c +++ b/lang/cem/libcc.ansi/core/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/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 80% rename from lang/cem/libcc.ansi/time/localtime.c rename to lang/cem/libcc.ansi/core/time/localtime.c index a475f3a2a..87fd2ad2a 100644 --- a/lang/cem/libcc.ansi/time/localtime.c +++ b/lang/cem/libcc.ansi/core/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/core/time/misc.c b/lang/cem/libcc.ansi/core/time/misc.c new file mode 100644 index 000000000..6a182307f --- /dev/null +++ b/lang/cem/libcc.ansi/core/time/misc.c @@ -0,0 +1,517 @@ +/* + * misc - data and miscellaneous routines + */ +/* $Id$ */ + +#include +#include +#include +#include + +#include "loc_time.h" + +#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 */ + +long _timezone = 0; +long _dst_off = 60 * 60; +int _daylight = 0; +char* _tzname[2] = { ntstr, dststr }; + +char* tzname[2] = { ntstr, dststr }; + +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* _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 } +}; + +#if !defined(_POSIX_SOURCE) && !defined(__USG) +#define USE_TABLE 1 +#endif + +#if USE_TABLE +static int usetable = 1; + +typedef struct table +{ + const char* tz_name; + const int daylight; + const long zoneoffset; +} TABLE; + +#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 } +}; + +/* + * The function ZoneFromTable() searches the table for the current + * timezone. It saves the last one found in ntstr or dststr, depending on + * wheter the name is for daylight-saving-time or not. + * Both ntstr and dststr are TZ_LEN + 1 chars. + */ +static void +ZoneFromTable(long timezone) +{ + register TABLE* tptr = TimezoneTable; + + 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); + dststr[TZ_LEN] = '\0'; + } + } + tptr++; + } +} +#endif /* USE_TABLE */ + +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 (n < TZ_LEN) + *buf++ = *p; + p++; + n++; + } + if (n < 3) + return NULL; /* error */ + *buf = '\0'; + return p; +} + +static const char* +parseTime(register long* tm, const char* p, register struct dsttype* dst) +{ + register int n = 0; + register const char* q = p; + char ds_type = (dst ? dst->ds_type : '\0'); + + if (dst) + dst->ds_type = 'U'; + + *tm = 0; + 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; + *tm = n * 60 * 60; + if (*p == ':') + { + p++; + n = 0; + while (*p >= '0' && *p <= '9') + { + n = 10 * n + (*p++ - '0'); + } + if (q == p) + return NULL; /* format error */ + if (n < 0 || n >= 60) + return NULL; + *tm += n * 60; + if (*p == ':') + { + p++; + n = 0; + while (*p >= '0' && *p <= '9') + { + n = 10 * n + (*p++ - '0'); + } + if (q == p) + return NULL; /* format error */ + if (n < 0 || n >= 60) + return NULL; + *tm += n; + } + } + 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) +{ + register const char* q; + register int n = 0; + int cnt = 0; + const int bnds[3][2] = { { 1, 12 }, + { 1, 5 }, + { 0, 6 } }; + char ds_type; + + if (*p != 'M') + { + if (*p == 'J') + { + *buf++ = *p++; + ds_type = 'J'; + } + else + ds_type = 'Z'; + q = p; + 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; + dstinfo->ds_type = ds_type; + dstinfo->ds_date[0] = n; + return p; + } + ds_type = 'M'; + do + { + *buf++ = *p++; + q = p; + n = 0; + 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; + dstinfo->ds_date[cnt] = n; + cnt++; + } while (cnt < 3 && *p == '.'); + 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) +{ + long tim; + register const char* q; + + if (!(p = parseDate(buf, p, &dststart))) + return NULL; + buf += strlen(buf); + if (*p == '/') + { + q = ++p; + if (!(p = parseTime(&tim, p, &dststart))) + return NULL; + while (p != q) + *buf++ = *q++; + } + if (*p != ',') + return NULL; + p++; + if (!(p = parseDate(buf, p, &dstend))) + return NULL; + buf += strlen(buf); + if (*p == '/') + { + q = ++p; + if (!(p = parseTime(&tim, p, &dstend))) + return NULL; + while (*buf++ = *q++) + ; + } + if (*p) + return NULL; + return p; +} + +/* The following routine parses timezone information in POSIX-format. For + * the requirements, see IEEE Std 1003.1-1988 section 8.1.1. + * The function returns as soon as it spots an error. + */ +static void +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 USE_TABLE + usetable = 0; +#endif + if (*p == ':') + { + /* + * According to POSIX, this is implementation defined. + * Since it depends on the particular operating system, we + * can do nothing. + */ + return; + } + + if (!strcmp(lastTZ, p)) + return; /* nothing changed */ + + *_tzname[0] = '\0'; + *_tzname[1] = '\0'; + dststart.ds_type = 'U'; + dststart.ds_sec = 2 * 60 * 60; + dstend.ds_type = 'U'; + dstend.ds_sec = 2 * 60 * 60; + + if (strlen(p) > 2 * RULE_LEN) + return; + strcpy(lastTZ, p); + + if (!(p = parseZoneName(buffer, p))) + return; + + if (*p == '-') + { + sign = -1; + p++; + } + else if (*p == '+') + p++; + + if (!(p = parseTime(&tz, p, NULL))) + return; + tz *= sign; + _timezone = tz; + strncpy(_tzname[0], buffer, TZ_LEN); + + if (!(_daylight = (*p != '\0'))) + return; + + buffer[0] = '\0'; + 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; + p++; + if (strlen(p) > RULE_LEN) + return; + if (!(p = parseRule(buffer, p))) + return; + } +} + +void _tzset(void) +{ + parseTZ(getenv("TZ")); /* should go inside #if */ + + tzname[0] = _tzname[0]; + tzname[1] = _tzname[1]; +} + +static int +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; + return day - (day - first) % 7; +} + +static int +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); + } + day = 0; + month = 1; + 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; + return day; +} + +/* + * The default dst transitions are those for Western Europe (except Great + * Britain). + */ +unsigned +_dstget(register struct tm* timep) +{ + int begindst, enddst; + register struct dsttype *dsts = &dststart, *dste = &dstend; + int do_dst = 0; + + if (_daylight == -1) + _tzset(); + + timep->tm_isdst = _daylight; + if (!_daylight) + return 0; + + if (dsts->ds_type != 'U') + begindst = date_of(dsts, timep); + 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 */ + + /* assume begindst != enddst (otherwise it would be no use) */ + if (begindst < enddst) + { /* northern hemisphere */ + if (timep->tm_yday > begindst && timep->tm_yday < enddst) + do_dst = 1; + } + 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 */ + long cursec; + + if (timep->tm_yday == begindst) + dsttranssec = dsts->ds_sec; + else + dsttranssec = dste->ds_sec; + cursec = ((timep->tm_hour * 60) + timep->tm_min) * 60L + + 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); +#endif + 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/core/time/mktime.c similarity index 63% rename from lang/cem/libcc.ansi/time/mktime.c rename to lang/cem/libcc.ansi/core/time/mktime.c index 6d4008082..174d2c266 100644 --- a/lang/cem/libcc.ansi/time/mktime.c +++ b/lang/cem/libcc.ansi/core/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/core/time/strftime.c b/lang/cem/libcc.ansi/core/time/strftime.c new file mode 100644 index 000000000..cae3b6eb3 --- /dev/null +++ b/lang/cem/libcc.ansi/core/time/strftime.c @@ -0,0 +1,187 @@ +/* + * strftime - convert a structure to a string, controlled by an argument + */ +/* $Id$ */ + +#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) +{ + while (width > 0 || (width < 0 && *str)) + { + if (!maxsize) + break; + *s++ = *str++; + maxsize--; + width--; + } + return s; +} + +static char* +u_prnt(char* s, size_t maxsize, unsigned val, int width) +{ + int c; + + c = val % 10; + 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'; + return s; +} + +size_t +strftime(char* s, size_t maxsize, + const char* format, const struct tm* timeptr) +{ + size_t n; + char *firsts, *olds; + + if (!format) + return 0; + + _tzset(); /* for %Z conversion */ + firsts = s; + while (maxsize && *format) + { + while (maxsize && *format && *format != '%') + { + *s++ = *format++; + maxsize--; + } + 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, + (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; + } + } + if (maxsize) + { + *s = '\0'; + return s - firsts; + } + return 0; /* The buffer is full */ +} diff --git a/lang/cem/libcc.ansi/time/tzset.c b/lang/cem/libcc.ansi/core/time/tzset.c similarity index 56% rename from lang/cem/libcc.ansi/time/tzset.c rename to lang/cem/libcc.ansi/core/time/tzset.c index 04d498db8..94b38d6d5 100644 --- a/lang/cem/libcc.ansi/time/tzset.c +++ b/lang/cem/libcc.ansi/core/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 */ } 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/tolower.c b/lang/cem/libcc.ansi/ctype/tolower.c deleted file mode 100644 index ff95ae0d8..000000000 --- a/lang/cem/libcc.ansi/ctype/tolower.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -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 deleted file mode 100644 index 521ae5569..000000000 --- a/lang/cem/libcc.ansi/ctype/toupper.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int toupper(int c) { - return islower(c) ? c - 'a' + 'A' : 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 diff --git a/lang/cem/libcc.ansi/errno/errlist.c b/lang/cem/libcc.ansi/errno/errlist.c deleted file mode 100644 index 4d45c447b..000000000 --- a/lang/cem/libcc.ansi/errno/errlist.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#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 int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]); diff --git a/lang/cem/libcc.ansi/headers/ack/config.h b/lang/cem/libcc.ansi/headers/ack/config.h new file mode 100644 index 000000000..2ee784213 --- /dev/null +++ b/lang/cem/libcc.ansi/headers/ack/config.h @@ -0,0 +1,66 @@ +#ifndef _ACK_CONFIG_H +#define _ACK_CONFIG_H + +#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 + +#ifndef ACKCONF_WANT_STANDARD_O +#define ACKCONF_WANT_STANDARD_O 1 +#endif + +#ifndef ACKCONF_WANT_STANDARD_SIGNALS +#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 + +#ifndef ACKCONF_WANT_EMULATED_RAISE +/* Implement raise() in terms of kill() and getpid(). */ +#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_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 +#endif + +#ifndef ACKCONF_WANT_STDIO +#define ACKCONF_WANT_STDIO 1 +#endif + +#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/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/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/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/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/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 new file mode 100644 index 000000000..bab5ada71 --- /dev/null +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -0,0 +1,114 @@ +#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 + +#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 + { + 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. */ + + 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 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). */ + typedef uint16_t sigset_t; + + struct sigaction; +#else + #include +#endif +typedef void (*sighandler_t)(int); + +/* 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; + +/* 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); +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); +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 *); +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 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); +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/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/setlocale.c b/lang/cem/libcc.ansi/locale/setlocale.c deleted file mode 100644 index 9b61ed58e..000000000 --- a/lang/cem/libcc.ansi/locale/setlocale.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * setlocale - set the programs locale - */ -/* $Id$ */ - -#include -#include - -struct lconv _lc; - -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; - } -} diff --git a/lang/cem/libcc.ansi/malloc/calloc.c b/lang/cem/libcc.ansi/malloc/calloc.c deleted file mode 100644 index 2e9d3be16..000000000 --- a/lang/cem/libcc.ansi/malloc/calloc.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -void* calloc(size_t nmemb, size_t size) -{ - 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; - - memset(ptr, 0, bytes); - return ptr; -} 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/fmod.c b/lang/cem/libcc.ansi/math/fmod.c deleted file mode 100644 index ae0783e6b..000000000 --- a/lang/cem/libcc.ansi/math/fmod.c +++ /dev/null @@ -1,34 +0,0 @@ -/* fmod function */ -/* Author Robert R. Hall (hall@crach.cts.com) */ - -/* $Id$ */ - -#include -#include - -double -(fmod)(double x, double y) -{ /* compute fmod(x, y) */ - double t; - int n, neg; - int ychar, xchar; - - 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; - t = frexp(y, &ychar); - /* 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; - } - return (neg ? -x : x); -} diff --git a/lang/cem/libcc.ansi/math/isnan.c b/lang/cem/libcc.ansi/math/isnan.c deleted file mode 100644 index b64c6d905..000000000 --- a/lang/cem/libcc.ansi/math/isnan.c +++ /dev/null @@ -1,11 +0,0 @@ -__IsNan(double d) -{ -#if defined(__vax) || defined(__pdp) -#else - float f = d; - - if ((*((long *) &f) & 0x7f800000) == 0x7f800000 && - (*((long *) &f) & 0x007fffff) != 0) return 1; -#endif - return 0; -} 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/closedir.c b/lang/cem/libcc.ansi/misc/closedir.c deleted file mode 100644 index 826026f13..000000000 --- a/lang/cem/libcc.ansi/misc/closedir.c +++ /dev/null @@ -1,36 +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/misc/getdents.c b/lang/cem/libcc.ansi/misc/getdents.c deleted file mode 100644 index e9d34c19a..000000000 --- a/lang/cem/libcc.ansi/misc/getdents.c +++ /dev/null @@ -1,289 +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/misc/getgrent.c b/lang/cem/libcc.ansi/misc/getgrent.c deleted file mode 100644 index 343884a22..000000000 --- a/lang/cem/libcc.ansi/misc/getgrent.c +++ /dev/null @@ -1,135 +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/misc/getopt.c b/lang/cem/libcc.ansi/misc/getopt.c deleted file mode 100644 index cad57fc10..000000000 --- a/lang/cem/libcc.ansi/misc/getopt.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * getopt - parse command-line options - */ -/* $Id$ */ - -#include -#include - -#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 -getopt(int argc, char **argv, char *opts) -{ - static int sp = 1; - register c; - register char *cp; - - if (sp == 1) - if (optind >= argc || - argv[optind][0] != '-' || argv[optind][1] == '\0') - return EOF; - 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') { - 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); - sp = 1; - return '?'; - } else - optarg = argv[optind++]; - sp = 1; - } else { - if (argv[optind][++sp] == '\0') { - sp = 1; - optind++; - } - optarg = NULL; - } - return c; -} diff --git a/lang/cem/libcc.ansi/misc/getpass.c b/lang/cem/libcc.ansi/misc/getpass.c deleted file mode 100644 index ec209f37f..000000000 --- a/lang/cem/libcc.ansi/misc/getpass.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * getpass - ask for a password - */ -/* $Id$ */ - -#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); - -int _stty(int, struct sgttyb *); -int _gtty(int, struct sgttyb *); - -char * -getpass(const char *prompt) -{ - 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); -} diff --git a/lang/cem/libcc.ansi/misc/getw.c b/lang/cem/libcc.ansi/misc/getw.c deleted file mode 100644 index 70efda78d..000000000 --- a/lang/cem/libcc.ansi/misc/getw.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * getw - read a word from a stream - */ -/* $Id$ */ - -#include - -int getw(register FILE *stream) -{ - register int cnt = sizeof(int); - int w; - register char *p = (char *) &w; - - while (cnt--) { - *p++ = getc(stream); - } - if (feof(stream) || ferror(stream)) return EOF; - return w; -} diff --git a/lang/cem/libcc.ansi/misc/isatty.c b/lang/cem/libcc.ansi/misc/isatty.c deleted file mode 100644 index cda06f4dc..000000000 --- a/lang/cem/libcc.ansi/misc/isatty.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * isatty - check if a file descriptor is associated with a terminal - */ -/* $Id$ */ - -int _isatty(int d); - -int isatty(int d) -{ - return _isatty(d); -} diff --git a/lang/cem/libcc.ansi/misc/mktemp.c b/lang/cem/libcc.ansi/misc/mktemp.c deleted file mode 100644 index 695dad4e1..000000000 --- a/lang/cem/libcc.ansi/misc/mktemp.c +++ /dev/null @@ -1,30 +0,0 @@ -/* $Id$ */ -/* 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); - -char *mktemp(char *template) -{ - 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 */ - - /* 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; - } - } - return("/"); -} diff --git a/lang/cem/libcc.ansi/misc/opendir.c b/lang/cem/libcc.ansi/misc/opendir.c deleted file mode 100644 index 7e3842055..000000000 --- a/lang/cem/libcc.ansi/misc/opendir.c +++ /dev/null @@ -1,67 +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/misc/popen.c b/lang/cem/libcc.ansi/misc/popen.c deleted file mode 100644 index b0dd8d400..000000000 --- a/lang/cem/libcc.ansi/misc/popen.c +++ /dev/null @@ -1,110 +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/misc/putw.c b/lang/cem/libcc.ansi/misc/putw.c deleted file mode 100644 index a195a2d32..000000000 --- a/lang/cem/libcc.ansi/misc/putw.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * putw - write an word on a stream - */ -/* $Id$ */ - -#include - -int -putw(int w, register FILE *stream) -{ - register int cnt = sizeof(int); - register char *p = (char *) &w; - - while (cnt--) { - putc(*p++, stream); - } - 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 deleted file mode 100644 index 2497e4673..000000000 --- a/lang/cem/libcc.ansi/misc/readdir.c +++ /dev/null @@ -1,47 +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/misc/rewinddir.c b/lang/cem/libcc.ansi/misc/rewinddir.c deleted file mode 100644 index 6186153cd..000000000 --- a/lang/cem/libcc.ansi/misc/rewinddir.c +++ /dev/null @@ -1,37 +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/misc/seekdir.c b/lang/cem/libcc.ansi/misc/seekdir.c deleted file mode 100644 index b162a3346..000000000 --- a/lang/cem/libcc.ansi/misc/seekdir.c +++ /dev/null @@ -1,109 +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/misc/sleep.c b/lang/cem/libcc.ansi/misc/sleep.c deleted file mode 100644 index 4bc8f2d57..000000000 --- a/lang/cem/libcc.ansi/misc/sleep.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * sleep - suspend current process for a number of seconds - */ -/* $Id$ */ - -#include -#include - -int _alarm(int n); -void _pause(void); - -static jmp_buf setjmpbuf; - -static void -alfun(int sig) -{ - longjmp(setjmpbuf, 1); -} /* used with sleep() below */ - -void -sleep(int n) -{ -/* 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)) { - signal(SIGALRM, oldsig); - _alarm(oldalarm); - return; - } - oldalarm = _alarm(5000); /* Who cares how long, as long - * as it is long enough - */ - if (oldalarm > n) oldalarm -= n; - else if (oldalarm) { - n = oldalarm; - oldalarm = 1; - } - oldsig = signal(SIGALRM, alfun); - _alarm(n); - for (;;) { - /* allow for other handlers ... */ - _pause(); - } -} diff --git a/lang/cem/libcc.ansi/misc/telldir.c b/lang/cem/libcc.ansi/misc/telldir.c deleted file mode 100644 index d96d78c62..000000000 --- a/lang/cem/libcc.ansi/misc/telldir.c +++ /dev/null @@ -1,34 +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 ); -} 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 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/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/doprnt.c b/lang/cem/libcc.ansi/stdio/doprnt.c deleted file mode 100644 index 395c45704..000000000 --- a/lang/cem/libcc.ansi/stdio/doprnt.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * doprnt.c - print formatted output - */ -/* $Id$ */ - -#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) -{ - register int i, c; - - if (*f == '*') { - *ip = va_arg((*app), int); - f++; - } else { - i = 0; - while ((c = *f - '0') >= 0 && c <= 9) { - i = i*10 + c; - f++; - } - *ip = i; - } - return f; -} - -#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 */ -#endif - -#define PUTC(c) \ - do { \ - int i = putc(c, stream); \ - 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) -{ - long signed_val; - unsigned long unsigned_val; - 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; - } - - if (is_signed) { - if (signed_val < 0) { - *s++ = '-'; - signed_val = -signed_val; - } 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) - return s; - } 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; - } - - s = _i_compute(unsigned_val, base, s, precision); - - if (c == 'X') - while (old_s != s) { - *old_s = toupper(*old_s); - old_s++; - } - - return s; -} - -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]; - - while (c = *fmt++) { - if (c != '%') { -#ifdef CPM - if (c == '\n') { - PUTC('\r'); - } -#endif - PUTC(c); - nrchars++; - 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; - } - fmt++; - } while(!(flags & FL_NOMORE)); - - oldfmt = fmt; - fmt = gnum(fmt, &width, &ap); - if (fmt != oldfmt) flags |= FL_WIDTHSPEC; - - if (*fmt == '.') { - fmt++; oldfmt = fmt; - fmt = gnum(fmt, &precision, &ap); - if (precision >= 0) flags |= FL_PRECSPEC; - } - - if ((flags & FL_WIDTHSPEC) && width < 0) { - width = -width; - flags |= FL_LJUST; - } - if (!(flags & FL_WIDTHSPEC)) width = 0; - - 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 (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); - /* 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; -#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; - - 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; - } - zfill = ' '; - if (flags & FL_ZEROFILL) zfill = '0'; - j = s - s1; - - /* between_fill is true under the following conditions: - * 1- the fill character is '0' - * and - * 2a- the number is of the form 0x... or 0X... - * or - * 2b- the number contains a sign or space - */ - between_fill = 0; - if ((flags & FL_ZEROFILL) - && (((c == 'x' || c == 'X') && (flags & FL_ALT)) - || (c == 'p') - || ((flags & FL_SIGNEDCONV) - && ( *s1 == '+' || *s1 == '-' || *s1 == ' ')))) - between_fill++; - - if ((i = width - j) > 0) - 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++); - } - } - do { - PUTC(zfill); - } while (--i); - } - - nrchars += j; - while (--j >= 0) { - PUTC(*s1++); - } - - if (i > 0) nrchars += i; - while (--i >= 0) - PUTC(zfill); - } - return nrchars; -} diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/stdio/doscan.c deleted file mode 100644 index eb93a4029..000000000 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ /dev/null @@ -1,450 +0,0 @@ -/* - * doscan.c - scan formatted input - */ -/* $Id$ */ - -#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) -#else -#error garbage pointer size -#define set_pointer(flags) /* compilation might continue */ -#endif - -#define NUMLEN 512 -#define NR_CHARS 256 - -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 - * first 1 or 2 characters. This means that the base must be adjusted - * 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) -{ - 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; - } - - if (c == '-' || c == '+') { - *bufp++ = c; - if (--width) - c = getc(stream); - } - - 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) { - *bufp++ = c; - if (--width) - c = getc(stream); - } - } - else if (type == 'i') base = 10; - - while (width) { - if (((base == 10) && isdigit(c)) - || ((base == 16) && isxdigit(c)) - || ((base == 8) && isdigit(c) && (c < '8')) - || ((base == 2) && isdigit(c) && (c < '2'))) { - *bufp++ = c; - if (--width) - c = getc(stream); - } - else break; - } - - if (width && c != EOF) ungetc(c, stream); - if (type == 'i') base = 0; - *basep = base; - *bufp = '\0'; - return bufp - 1; -} - -#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 - * that 1.el leaves the 'l' in the input queue. Since all detection of - * format errors is done here, _doscan() doesn't call strtod() when it's - * 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) -{ - register char *bufp = inp_buf; - int digit_seen = 0; - - if (c == '-' || c == '+') { - *bufp++ = c; - if (--width) - c = getc(stream); - } - - 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')) { - *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); - *bufp = '\0'; - return bufp - 1; -} -#endif /* ACKCONF_NO_STDIO_FLOAT */ - - -/* - * the routine that does the scanning - */ - -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; -#endif - - if (!*format) return 0; - - while (1) { - if (isspace(*format)) { - while (isspace(*format)) - format++; /* skip whitespace */ - ic = getc(stream); - nrchars++; - while (isspace (ic)) { - ic = getc(stream); - nrchars++; - } - if (ic != EOF) ungetc(ic,stream); - nrchars--; - } - if (!*format) break; /* end of format */ - - if (*format != '%') { - ic = getc(stream); - nrchars++; - if (ic != *format++) { - if (ic != EOF) ungetc(ic,stream); - nrchars--; - break; /* error */ - } - continue; - } - format++; - if (*format == '%') { - ic = getc(stream); - nrchars++; - if (ic == '%') { - format++; - continue; - } - else break; - } - flags = 0; - if (*format == '*') { - format++; - flags |= FL_NOASSIGN; - } - if (isdigit (*format)) { - flags |= FL_WIDTHSPEC; - 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; - } - kind = *format; - 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 %[ */ - ic = getc(stream); - 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); - /* 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; - - 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; - - 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 (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)) { - 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; - - 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++; - } - 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; - - 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 */ - conv++; - 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 deleted file mode 100644 index 9a15b5cde..000000000 --- a/lang/cem/libcc.ansi/stdio/ecvt.c +++ /dev/null @@ -1,33 +0,0 @@ -/* $Id$ */ - -#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); - -static char * -cvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag) -{ - struct EXTEND e; - - _dbl_ext_cvt(value, &e); - return _ext_str_cvt(&e, ndigit, decpt, sign, ecvtflag); -} - -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) -{ - return cvt(value, ndigit, decpt, sign, 0); -} - -#endif /* ACKCONF_NO_STDIO_FLOAT */ diff --git a/lang/cem/libcc.ansi/stdio/fdopen.c b/lang/cem/libcc.ansi/stdio/fdopen.c deleted file mode 100644 index a665ddd3f..000000000 --- a/lang/cem/libcc.ansi/stdio/fdopen.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * fdopen - convert a (UNIX) file descriptor into a FILE pointer - */ -/* $Id$ */ - -#include -#include -#include "../stdio/loc_incl.h" - -FILE * -fdopen(int fd, const char *mode) -{ - register int i; - 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; - - 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 ((flags & _IOREAD) && (flags & _IOWRITE)) - flags &= ~(_IOREADING | _IOWRITING); - - stream->_count = 0; - stream->_fd = fd; - stream->_flags = flags; - stream->_buf = NULL; - __iotab[i] = stream; - return stream; -} diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c deleted file mode 100644 index 573764fd4..000000000 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * fflush.c - flush stream(s) - */ -/* $Id$ */ - -#include -#include -#include -#include "loc_incl.h" - -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->_buf - || (!io_testflag(stream, _IOREADING) - && !io_testflag(stream, _IOWRITING))) - return 0; - if (io_testflag(stream, _IOREADING)) { - /* (void) fseek(stream, 0L, SEEK_CUR); */ - int adjust = 0; - if (stream->_buf && !io_testflag(stream,_IONBF)) - adjust = stream->_count; - stream->_count = 0; - 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; - - if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */ - stream->_flags &= ~_IOWRITING; - - count = stream->_ptr - stream->_buf; - stream->_ptr = stream->_buf; - - if ( count <= 0 ) - return 0; - - 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); - - stream->_count = 0; - - if ( count == c1 ) - return 0; - - stream->_flags |= _IOERR; - return EOF; -} - -void -__cleanup(void) -{ - register int i; - - for(i= 0; i < FOPEN_MAX; i++) - if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING)) - (void) fflush(__iotab[i]); -} diff --git a/lang/cem/libcc.ansi/stdio/fgets.c b/lang/cem/libcc.ansi/stdio/fgets.c deleted file mode 100644 index c5476429d..000000000 --- a/lang/cem/libcc.ansi/stdio/fgets.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * fgets.c - get a string from a file - */ -/* $Id$ */ - -#include - -char * -fgets(char *s, register int n, register FILE *stream) -{ - register int ch; - register char *ptr; - - ptr = s; - while (--n > 0 && (ch = getc(stream)) != EOF) { - *ptr++ = ch; - if ( ch == '\n') - break; - } - 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/fltpr.c b/lang/cem/libcc.ansi/stdio/fltpr.c deleted file mode 100644 index ad8e16d46..000000000 --- a/lang/cem/libcc.ansi/stdio/fltpr.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * fltpr.c - print floating point numbers - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -#ifndef ACKCONF_NO_STDIO_FLOAT - -static char * -_pfloat(long double r, register char *s, int n, int flags) -{ - register char *s1; - int sign, dp; - register int i; - - s1 = _fcvt(r, n, &dp, &sign); - if (sign) - *s++ = '-'; - else if (flags & FL_SIGN) - *s++ = '+'; - else if (flags & FL_SPACE) - *s++ = ' '; - - 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)) - *s++ = '.'; - while (++dp <= 0) { - if (--i<0) - break; - *s++ = '0'; - } - while (--i >= 0) - if (*s1) *s++ = *s1++; - else *s++ = '0'; - return s; -} - -static char * -_pscien(long double r, register char *s, int n, int flags) -{ - int sign, dp; - register char *s1; - - s1 = _ecvt(r, n + 1, &dp, &sign); - if (sign) - *s++ = '-'; - else if (flags & FL_SIGN) - *s++ = '+'; - else if (flags & FL_SPACE) - *s++ = ' '; - - *s++ = *s1++; - if ((n > 0) || (flags & FL_ALT)) - *s++ = '.'; - while (--n >= 0) - if (*s1) *s++ = *s1++; - else *s++ = '0'; - *s++ = 'e'; - if ( r != 0 ) --dp ; - if ( dp<0 ) { - *s++ = '-' ; dp= -dp ; - } else { - *s++ = '+' ; - } - if (dp >= 100) { - *s++ = '0' + (dp / 100); - dp %= 100; - } - *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)) - -static char * -_gcvt(long double value, int ndigit, char *s, int flags) -{ - int sign, dp; - register char *s1, *s2; - register int i; - register int nndigit = ndigit; - - s1 = _ecvt(value, ndigit, &dp, &sign); - s2 = s; - if (sign) *s2++ = '-'; - else if (flags & FL_SIGN) - *s2++ = '+'; - else if (flags & FL_SPACE) - *s2++ = ' '; - - if (!(flags & FL_ALT)) - for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) - nndigit--; - - if (USE_EXP(dp,ndigit)) { - /* Use E format */ - dp--; - *s2++ = *s1++; - if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.'; - while (--nndigit > 0) *s2++ = *s1++; - *s2++ = 'e'; - if (dp < 0) { - *s2++ = '-'; - dp = -dp; - } - else *s2++ = '+'; - s2 += NDIGINEXP(dp); - *s2 = 0; - for (i = NDIGINEXP(dp); i > 0; i--) { - *--s2 = dp % 10 + '0'; - dp /= 10; - } - return s; - } - /* Use f format */ - if (dp <= 0) { - if (*s1 != '0') { - /* otherwise the whole number is 0 */ - *s2++ = '0'; - *s2++ = '.'; - } - while (dp < 0) { - dp++; - *s2++ = '0'; - } - } - for (i = 1; i <= nndigit; i++) { - *s2++ = *s1++; - if (i == dp) *s2++ = '.'; - } - if (i <= dp) { - while (i++ <= dp) *s2++ = '0'; - *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) -{ - 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); - - 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'; - } - return s; -} -#endif /* ACKCONF_NO_STDIO_FLOAT */ diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c deleted file mode 100644 index 22340e2e3..000000000 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * flushbuf.c - flush a buffer - */ -/* $Id$ */ - -#include -#include -#include -#include "loc_incl.h" - -extern void (*_clean)(void); - -static int -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) { - nbytes -= c; - buf += c; - } - return c > 0; -} - -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; - - 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))) { - stream->_flags |= _IONBF; - } else { - stream->_flags |= _IOLBF|_IOMYBUF; - stream->_bufsiz = BUFSIZ; - stream->_count = -1; - } - } else { - if (!(stream->_buf = - (unsigned char *) malloc(BUFSIZ))) { - stream->_flags |= _IONBF; - } else { - stream->_flags |= _IOMYBUF; - stream->_bufsiz = BUFSIZ; - if (!io_testflag(stream, _IOLBF)) - stream->_count = BUFSIZ - 1; - else stream->_count = -1; - } - } - stream->_ptr = stream->_buf; - } - } - - if (io_testflag(stream, _IONBF)) { - char c1 = c; - - stream->_count = 0; - 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) { - stream->_flags |= _IOERR; - return EOF; - } - 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) { - int count = -stream->_count; - - stream->_ptr = stream->_buf; - stream->_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)) { - stream->_flags |= _IOERR; - return EOF; - } - } - } 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) { - stream->_flags |= _IOERR; - return EOF; - } - } - if (! do_write(fileno(stream), (char *)stream->_buf, count)) { - *(stream->_buf) = c; - stream->_flags |= _IOERR; - return EOF; - } - } - *(stream->_buf) = c; - } - return (unsigned char) c; -} diff --git a/lang/cem/libcc.ansi/stdio/fprintf.c b/lang/cem/libcc.ansi/stdio/fprintf.c deleted file mode 100644 index 6caeee311..000000000 --- a/lang/cem/libcc.ansi/stdio/fprintf.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * fprintf - write output on a stream - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -int -fprintf(FILE *stream, const char *format, ...) -{ - va_list ap; - int retval; - - va_start(ap, format); - - retval = _doprnt (format, ap, stream); - - va_end(ap); - - return retval; -} diff --git a/lang/cem/libcc.ansi/stdio/fputs.c b/lang/cem/libcc.ansi/stdio/fputs.c deleted file mode 100644 index cd1ce3362..000000000 --- a/lang/cem/libcc.ansi/stdio/fputs.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * fputs - print a string - */ -/* $Id$ */ - -#include - -int -fputs(register const char *s, register FILE *stream) -{ - register int i = 0; - - while (*s) - if (putc(*s++, stream) == EOF) return EOF; - else i++; - - return i; -} diff --git a/lang/cem/libcc.ansi/stdio/freopen.c b/lang/cem/libcc.ansi/stdio/freopen.c deleted file mode 100644 index b51acba83..000000000 --- a/lang/cem/libcc.ansi/stdio/freopen.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * freopen.c - open a file and associate a stream with it - */ -/* $Id$ */ - -#include -#include -#include -#include -#include "loc_incl.h" - -#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) -{ - 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)); - - 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; - } - break; - } - - if ((rwflags & O_TRUNC) - || (((fd = open(name, rwmode)) < 0) - && (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]) { - __iotab[i] = 0; - break; - } - } - if (stream != stdin && stream != stdout && stream != stderr) - free((void *)stream); - return (FILE *)NULL; - } - - stream->_count = 0; - stream->_fd = fd; - stream->_flags = flags; - return stream; -} diff --git a/lang/cem/libcc.ansi/stdio/gets.c b/lang/cem/libcc.ansi/stdio/gets.c deleted file mode 100644 index 74595a153..000000000 --- a/lang/cem/libcc.ansi/stdio/gets.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * gets.c - read a line from a stream - */ -/* $Id$ */ - -#include - -char * -gets(char *s) -{ - register FILE *stream = stdin; - register int ch; - 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; - } - - *ptr = '\0'; - return s; -} diff --git a/lang/cem/libcc.ansi/stdio/isatty.c b/lang/cem/libcc.ansi/stdio/isatty.c deleted file mode 100644 index 10b2bdb36..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/stdio/perror.c b/lang/cem/libcc.ansi/stdio/perror.c deleted file mode 100644 index f7329f6dc..000000000 --- a/lang/cem/libcc.ansi/stdio/perror.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * perror.c - print an error message on the standard error output - */ -/* $Id$ */ - -#include -#include -#include - -void -perror(const char *s) -{ - if (s && *s) { - (void) fputs(s, stderr); - (void) fputs(": ", stderr); - } - (void) fputs(strerror(errno), stderr); - (void) fputs("\n", stderr); -} diff --git a/lang/cem/libcc.ansi/stdio/puts.c b/lang/cem/libcc.ansi/stdio/puts.c deleted file mode 100644 index 99dfc8db8..000000000 --- a/lang/cem/libcc.ansi/stdio/puts.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * puts.c - print a string onto the standard output stream - */ -/* $Id$ */ - -#include - -int -puts(register const char *s) -{ - register FILE *file = stdout; - register int i = 0; - - while (*s) { - if (putc(*s++, file) == EOF) return EOF; - else i++; - } - if (putc('\n', file) == EOF) return EOF; - return i + 1; -} diff --git a/lang/cem/libcc.ansi/stdio/rename.c b/lang/cem/libcc.ansi/stdio/rename.c deleted file mode 100644 index ff177ccd5..000000000 --- a/lang/cem/libcc.ansi/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 diff --git a/lang/cem/libcc.ansi/stdio/setbuf.c b/lang/cem/libcc.ansi/stdio/setbuf.c deleted file mode 100644 index aafacdbf6..000000000 --- a/lang/cem/libcc.ansi/stdio/setbuf.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * setbuf.c - control buffering of a stream - */ -/* $Id$ */ - -#include -#include "loc_incl.h" - -void -setbuf(register FILE *stream, char *buf) -{ - (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 deleted file mode 100644 index 2c5e769df..000000000 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * setbuf.c - control buffering of a stream - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -extern void (*_clean)(void); - -int -setvbuf(register FILE *stream, char *buf, int mode, size_t size) -{ - int retval = 0; - - _clean = __cleanup; - if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) - return EOF; - - 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) { - retval = EOF; - } else { - stream->_flags |= _IOMYBUF; - } - } - - stream->_buf = (unsigned char *) buf; - - stream->_count = 0; - stream->_flags |= mode; - stream->_ptr = stream->_buf; - - if (!buf) { - stream->_bufsiz = 1; - } else { - stream->_bufsiz = size; - } - - return retval; -} diff --git a/lang/cem/libcc.ansi/stdio/snprintf.c b/lang/cem/libcc.ansi/stdio/snprintf.c deleted file mode 100644 index 7d428118c..000000000 --- a/lang/cem/libcc.ansi/stdio/snprintf.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * sprintf - print formatted output on an array - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -int -snprintf(char * s, size_t len, const char *format, ...) -{ - va_list ap; - int retval; - FILE tmp_stream; - - 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; - - retval = _doprnt(format, ap, &tmp_stream); - putc('\0',&tmp_stream); - - va_end(ap); - - return retval; -} diff --git a/lang/cem/libcc.ansi/stdio/sprintf.c b/lang/cem/libcc.ansi/stdio/sprintf.c deleted file mode 100644 index 6e52bce4a..000000000 --- a/lang/cem/libcc.ansi/stdio/sprintf.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * sprintf - print formatted output on an array - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -int -sprintf(char * s, const char *format, ...) -{ - va_list ap; - int retval; - FILE tmp_stream; - - 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; - - retval = _doprnt(format, ap, &tmp_stream); - putc('\0',&tmp_stream); - - va_end(ap); - - return retval; -} diff --git a/lang/cem/libcc.ansi/stdio/sscanf.c b/lang/cem/libcc.ansi/stdio/sscanf.c deleted file mode 100644 index b352db03e..000000000 --- a/lang/cem/libcc.ansi/stdio/sscanf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * sscanf - read formatted output from a string - */ -/* $Id$ */ - -#include -#include -#include -#include "loc_incl.h" - -int sscanf(const char *s, const char *format, ...) -{ - va_list ap; - int retval; - FILE tmp_stream; - - 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); - - retval = _doscan(&tmp_stream, format, ap); - - va_end(ap); - - return retval; -} diff --git a/lang/cem/libcc.ansi/stdio/ungetc.c b/lang/cem/libcc.ansi/stdio/ungetc.c deleted file mode 100644 index 6e832d67b..000000000 --- a/lang/cem/libcc.ansi/stdio/ungetc.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * ungetc.c - push a character back onto an input stream - */ -/* $Id$ */ - -#include -#include "loc_incl.h" - -int -ungetc(int ch, FILE *stream) -{ - unsigned char *p; - - if (ch == EOF || !io_testflag(stream,_IOREADING)) - return EOF; - if (stream->_ptr == stream->_buf) { - if (stream->_count != 0) return EOF; - stream->_ptr++; - } - stream->_count++; - p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */ - /* ungetc() in sscanf() shouldn't write in rom */ - 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 deleted file mode 100644 index 96dcea9f5..000000000 --- a/lang/cem/libcc.ansi/stdio/vfprintf.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * vfprintf - formatted output without ellipsis - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -int -vfprintf(FILE *stream, const char *format, va_list arg) -{ - return _doprnt (format, arg, stream); -} diff --git a/lang/cem/libcc.ansi/stdio/vsnprintf.c b/lang/cem/libcc.ansi/stdio/vsnprintf.c deleted file mode 100644 index 870e23df2..000000000 --- a/lang/cem/libcc.ansi/stdio/vsnprintf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * vsprintf - print formatted output without ellipsis on an array - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -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; - - retval = _doprnt(format, arg, &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 deleted file mode 100644 index b4ae4ed74..000000000 --- a/lang/cem/libcc.ansi/stdio/vsprintf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * vsprintf - print formatted output without ellipsis on an array - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -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; - - retval = _doprnt(format, arg, &tmp_stream); - putc('\0',&tmp_stream); - - return retval; -} 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/stdlib/abort.c b/lang/cem/libcc.ansi/stdlib/abort.c deleted file mode 100644 index d5ceff27c..000000000 --- a/lang/cem/libcc.ansi/stdlib/abort.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#if defined(_POSIX_SOURCE) -#include -#endif -#include -#include - -extern void (*_clean)(void); - -void -abort(void) -{ - if (_clean) _clean(); /* flush all output files */ - raise(SIGABRT); -} - diff --git a/lang/cem/libcc.ansi/stdlib/atexit.c b/lang/cem/libcc.ansi/stdlib/atexit.c deleted file mode 100644 index 77e343336..000000000 --- a/lang/cem/libcc.ansi/stdlib/atexit.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $Id$ */ - -#include - -#define NEXITS 32 - -extern void (*__functab[NEXITS])(void); -extern int __funccnt; - -int -atexit(void (*func)(void)) -{ - if (__funccnt >= NEXITS) - return 1; - __functab[__funccnt++] = func; - return 0; -} diff --git a/lang/cem/libcc.ansi/stdlib/bsearch.c b/lang/cem/libcc.ansi/stdlib/bsearch.c deleted file mode 100644 index 0958e3d78..000000000 --- a/lang/cem/libcc.ansi/stdlib/bsearch.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#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 *)) -{ - register const void *mid_point; - register int cmp; - - 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; - nmemb = (nmemb - 1) >> 1; - } else - nmemb >>= 1; - } - return (void *)NULL; -} diff --git a/lang/cem/libcc.ansi/stdlib/ext_comp.c b/lang/cem/libcc.ansi/stdlib/ext_comp.c deleted file mode 100644 index 2133e64bd..000000000 --- a/lang/cem/libcc.ansi/stdlib/ext_comp.c +++ /dev/null @@ -1,744 +0,0 @@ -/* - (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands. - See the copyright notice in the ACK home directory, in the file "Copyright". -*/ - -/* $Id$ */ - -/* extended precision arithmetic for the strtod() and cvt() routines */ - -/* This may require some more work when long doubles get bigger than 8 - bytes. In this case, these routines may become obsolete. ??? -*/ - -#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 -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 unsigned short *pres; - - /* first save the sign (XOR) */ - e3->sign = e1->sign ^ e2->sign; - - /* compute new exponent */ - e3->exp = e1->exp + e2->exp + 1; - - /* check for overflow/underflow ??? */ - - /* 128 bit multiply of mantissas */ - - /* assign unknown long formats */ - /* to known unsigned word formats */ - mp[0] = e1->m1 >> 16; - mp[1] = (unsigned short) e1->m1; - mp[2] = e1->m2 >> 16; - mp[3] = (unsigned short) e1->m2; - mc[0] = e2->m1 >> 16; - mc[1] = (unsigned short) e2->m1; - mc[2] = e2->m2 >> 16; - 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; - } - pres[-1] = k; - } - - if (! (result[0] & 0x8000)) { - e3->exp--; - for (i = 0; i <= 3; i++) { - 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) { - e3->m1 = 0x80000000; - e3->exp++; - } - } - } -} - -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 - */ - struct EXTEND ce2; - int diff; - - if ((e2->m1 | e2->m2) == 0L) { - *e3 = *e1; - return; - } - if ((e1->m1 | e1->m2) == 0L) { - *e3 = *e2; - return; - } - ce2 = *e2; - *e3 = *e1; - e1 = &ce2; - - /* adjust mantissas to equal power */ - diff = e3->exp - e1->exp; - if (diff < 0) { - diff = -diff; - e3->exp += diff; - b64_sft(&(e3->mantissa), diff); - } - else if (diff > 0) { - e1->exp += diff; - b64_sft(&(e1->mantissa), diff); - } - 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 ((e3->m2 | e3->m1) != 0L) { - /* normalize */ - if (e3->m1 == 0L) { - e3->m1 = e3->m2; e3->m2 = 0L; e3->exp -= 32; - } - if (!(e3->m1 & 0x80000000)) { - unsigned long l = 0x40000000; - int cnt = -1; - - while (! (l & e3->m1)) { - l >>= 1; cnt--; - } - e3->exp += cnt; - b64_sft(&(e3->mantissa), cnt); - } - } -} - -static int -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; -} - -static -b64_sft(struct mantissa *e1, int n) -{ - if (n > 0) { - if (n > 63) { - e1->l_32 = 0; - e1->h_32 = 0; - return; - } - if (n >= 32) { - e1->l_32 = e1->h_32; - e1->h_32 = 0; - n -= 32; - } - if (n > 0) { - e1->l_32 >>= n; - if (e1->h_32 != 0) { - e1->l_32 |= (e1->h_32 << (32 - n)); - e1->h_32 >>= n; - } - } - return; - } - n = -n; - if (n > 0) { - if (n > 63) { - e1->l_32 = 0; - e1->h_32 = 0; - return; - } - if (n >= 32) { - e1->h_32 = e1->l_32; - e1->l_32 = 0; - n -= 32; - } - if (n > 0) { - e1->h_32 <<= n; - if (e1->l_32 != 0) { - e1->h_32 |= (e1->l_32 >> (32 - n)); - e1->l_32 <<= n; - } - } - } -} - -static int -b64_add(struct mantissa *e1, struct mantissa *e2) - /* - * pointers to 64 bit 'registers' - */ -{ - register int overflow; - int carry; - - /* 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); - e1->l_32 += e2->l_32; - if ((carry) && (++e1->h_32 == 0)) - return(1); /* had a 64 bit overflow */ - else - return(overflow); /* return status from higher add */ -} - -/* The following tables can be computed with the following bc(1) - program: - -obase=16 -scale=0 -define t(x){ - auto a, b, c - a=2;b=1;c=2^32;n=1 - while(asign = 0; - e->exp = 0; - e->m1 = e->m2 = 0; - - c = *s; - switch(c) { - case '-': - e->sign = 1; - case '+': - s++; - } - while (c = *s++, isdigit(c) || (c == '.' && ! dotseen++)) { - if (c == '.') continue; - digitseen = 1; - if (e->m1 <= (unsigned long)(0xFFFFFFFF)/10) { - struct mantissa a1; - - a1 = e->mantissa; - b64_sft(&(e->mantissa), -3); - b64_sft(&a1, -1); - b64_add(&(e->mantissa), &a1); - a1.h_32 = 0; - a1.l_32 = c - '0'; - b64_add(&(e->mantissa), &a1); - } - else exp++; - if (dotseen) exp--; - } - if (! digitseen) return; - - if (ss) *ss = (char *)s - 1; - - if (c == 'E' || c == 'e') { - int exp1 = 0; - int sign = 1; - int exp_overflow = 0; - - switch(*s) { - case '-': - sign = -1; - case '+': - s++; - } - if (c = *s, isdigit(c)) { - do { - int tmp; - - exp1 = 10 * exp1 + (c - '0'); - if ((tmp = sign * exp1 + exp) > MAX_EXP || - tmp < -MAX_EXP) { - exp_overflow = 1; - } - } while (c = *++s, isdigit(c)); - if (ss) *ss = (char *)s; - } - exp += sign * exp1; - if (exp_overflow) { - exp = sign * MAX_EXP; - if (e->m1 != 0 || e->m2 != 0) errno = ERANGE; - } - } - if (e->m1 == 0 && e->m2 == 0) return; - e->exp = 63; - while (! (e->m1 & 0x80000000)) { - b64_sft(&(e->mantissa),-1); - e->exp--; - } - add_exponent(e, exp); -} - -#include - -static -ten_mult(struct EXTEND *e) -{ - struct EXTEND e1 = *e; - - e1.exp++; - e->exp += 3; - add_ext(e, &e1, e); -} - -#define NDIGITS 128 -#define NSIGNIFICANT 19 - -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]; - struct EXTEND m; - register char *p = buf; - register char *pe; - int findex = 0; - - if (ndigit < 0) ndigit = 0; - if (ndigit > NDIGITS) ndigit = NDIGITS; - pe = &buf[ndigit]; - buf[0] = '\0'; - - *sign = 0; - if (e->sign) { - *sign = 1; - e->sign = 0; - } - - *decpt = 0; - if (e->m1 != 0) { - register struct EXTEND *pp = &big_ten_powers[1]; - - while(cmp_ext(e,pp) >= 0) { - pp++; - findex = pp - big_ten_powers; - if (findex >= BTP) break; - } - pp--; - findex = pp - big_ten_powers; - 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++; - pp--; - findex = pp - ten_powers; - *decpt += findex; - - if (cmp_ext(e, &ten_powers[0]) < 0) { - pp = &r_big_ten_powers[1]; - while(cmp_ext(e,pp) < 0) pp++; - pp--; - findex = pp - r_big_ten_powers; - mul_ext(e, &big_ten_powers[findex], e); - *decpt -= findex * TP; - /* here, value >= 10 ** -28 */ - ten_mult(e); - (*decpt)--; - pp = &r_ten_powers[0]; - 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) */ - } - if (! ecvtflag) { - /* for fcvt() we need ndigit digits behind the dot */ - pe += *decpt; - if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS]; - } - m.exp = -62; - m.sign = 0; - m.m1 = 0xA0000000; - m.m2 = 0; - while (p <= pe) { - struct EXTEND oneminm; - - if (p - pe > NSIGNIFICANT) { - findex = 0; - e->m1 = 0; - } - if (findex) { - struct EXTEND tc, oldtc; - int count = 0; - - oldtc.exp = 0; - oldtc.sign = 0; - oldtc.m1 = 0; - oldtc.m2 = 0; - tc = ten_powers[findex]; - while (cmp_ext(e, &tc) >= 0) { - oldtc = tc; - add_ext(&tc, &ten_powers[findex], &tc); - count++; - } - *p++ = count + '0'; - oldtc.sign = 1; - add_ext(e, &oldtc, e); - findex--; - continue; - } - if (e->m1) { - m.sign = 1; - add_ext(&ten_powers[0], &m, &oneminm); - m.sign = 0; - if (e->exp >= 0) { - struct EXTEND x; - - x.m2 = 0; x.exp = e->exp; - x.sign = 1; - x.m1 = e->m1>>(31-e->exp); - *p++ = (x.m1) + '0'; - x.m1 = x.m1 << (31-e->exp); - add_ext(e, &x, e); - } - 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; - e->m1 = 0; - continue; - } - ten_mult(&m); - ten_mult(e); - } - else *p++ = '0'; - } - if (pe >= buf) { - p = pe; - *p += 5; /* round of at the end */ - while (*p > '9') { - *p = '0'; - if (p > buf) ++*--p; - else { - *p = '1'; - ++*decpt; - if (! ecvtflag) { - /* maybe add another digit at the end, - because the point was shifted right - */ - if (pe > buf) *pe = '0'; - pe++; - } - } - } - *pe = '\0'; - } - return buf; -} - -_dbl_ext_cvt(double value, struct EXTEND *e) -{ - /* Convert double to extended - */ - int exponent; - - value = frexp(value, &exponent); - e->sign = value < 0.0; - if (e->sign) value = -value; - e->exp = exponent - 1; - value *= 4294967296.0; - e->m1 = value; - value -= e->m1; - value *= 4294967296.0; - e->m2 = value; -} - -static struct EXTEND max_d; - -double -_ext_dbl_cvt(struct EXTEND *e) -{ - /* Convert extended to double - */ - double f; - int sign = e->sign; - - e->sign = 0; - if (e->m1 == 0 && e->m2 == 0) { - return 0.0; - } - if (max_d.exp == 0) { - _dbl_ext_cvt(DBL_MAX, &max_d); - } - 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)) { - errno = ERANGE; - } - return f; -} 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 -}; - diff --git a/lang/cem/libcc.ansi/stdlib/setenv.c b/lang/cem/libcc.ansi/stdlib/setenv.c deleted file mode 100644 index 086b2118d..000000000 --- a/lang/cem/libcc.ansi/stdlib/setenv.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#include -#include - -extern char* _findenv(const char* name, int* offset); -extern char **environ; - -/* - * setenv(name,value,rewrite) - * Set the value of the environmental variable "name" to be - * "value". If rewrite is set, replace any current value. - */ -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; - - 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); -} - -/* - * unsetenv(name) -- - * Delete environmental variable "name". - */ -int -unsetenv(const char* name) -{ - register char **P; - int offset; - - while (_findenv(name,&offset)) /* if set multiple times */ - for (P = &environ[offset];;++P) - if (!(*P = *(P + 1))) - break; - - return 0; -} - diff --git a/lang/cem/libcc.ansi/stdlib/strtod.c b/lang/cem/libcc.ansi/stdlib/strtod.c deleted file mode 100644 index 222a744b9..000000000 --- a/lang/cem/libcc.ansi/stdlib/strtod.c +++ /dev/null @@ -1,20 +0,0 @@ -/* $Id$ */ - -#include -#include "ext_fmt.h" - -#ifndef ACKCONF_NO_STDIO_FLOAT - -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) -{ - struct EXTEND e; - - _str_ext_cvt(p, pp, &e); - return _ext_dbl_cvt(&e); -} - -#endif diff --git a/lang/cem/libcc.ansi/stdlib/strtol.c b/lang/cem/libcc.ansi/stdlib/strtol.c deleted file mode 100644 index ad9a5166c..000000000 --- a/lang/cem/libcc.ansi/stdlib/strtol.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#include -#include -#include -#include - -static unsigned long -string2long(register const char *nptr, char **endptr, - int base, int is_signed); - -long int -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) -{ - return (unsigned long)string2long(nptr, endptr, base, 0); -} - -static unsigned long -string2long(register const char *nptr, char ** const endptr, - int base, int is_signed) -{ - register unsigned int v; - register unsigned long val = 0; - register int c; - int ovfl = 0, sign = 1; - const char *startnptr = nptr, *nrstart; - - if (endptr) *endptr = (char *)nptr; - while (isspace(*nptr)) nptr++; - c = *nptr; - - if (c == '-' || c == '+') { - if (c == '-') sign = -1; - nptr++; - } - 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') { - base = 16; - nptr++; - } - 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) { - 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; - } - nptr++; - } - if (endptr) { - if (nrstart == nptr) *endptr = (char *)startnptr; - else *endptr = (char *)nptr; - } - - 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++; - } - - if (ovfl) { - errno = ERANGE; - if (is_signed) - 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 deleted file mode 100644 index 99a8d6e6a..000000000 --- a/lang/cem/libcc.ansi/stdlib/system.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $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); - -#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 */ - }; - -int -system(const char *str) -{ - int pid, exitstatus, waitval; - int i; - - if ((pid = _fork()) < 0) return str ? -1 : 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); - /* get here if execve fails ... */ - _exit(FAIL); /* see manual page */ - } - while ((waitval = _wait(&exitstatus)) != pid) { - if (waitval == -1) break; - } - if (waitval == -1) { - /* no child ??? or maybe interrupted ??? */ - exitstatus = -1; - } - if (!str) { - if (exitstatus == FAIL << 8) /* execve() failed */ - exitstatus = 0; - else exitstatus = 1; /* /bin/sh exists */ - } - return exitstatus; -} 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 diff --git a/lang/cem/libcc.ansi/string/memchr.c b/lang/cem/libcc.ansi/string/memchr.c deleted file mode 100644 index 067776b4b..000000000 --- a/lang/cem/libcc.ansi/string/memchr.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#include - -void * -memchr(const void *s, register int c, register size_t n) -{ - register const unsigned char *s1 = s; - - c = (unsigned char) c; - if (n) { - n++; - while (--n > 0) { - if (*s1++ != c) continue; - return (void *) --s1; - } - } - return NULL; -} diff --git a/lang/cem/libcc.ansi/string/strcmp.c b/lang/cem/libcc.ansi/string/strcmp.c deleted file mode 100644 index bfe801905..000000000 --- a/lang/cem/libcc.ansi/string/strcmp.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#include - -int -strcmp(register const char *s1, register const char *s2) -{ - 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; -} diff --git a/lang/cem/libcc.ansi/string/strncpy.c b/lang/cem/libcc.ansi/string/strncpy.c deleted file mode 100644 index 0c0bfd625..000000000 --- a/lang/cem/libcc.ansi/string/strncpy.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Id$ */ - -#include - -char * -strncpy(char *ret, register const char *s2, register size_t n) -{ - register char *s1 = ret; - - if (n>0) { - while((*s1++ = *s2++) && --n > 0) - /* EMPTY */ ; - if ((*--s2 == '\0') && --n > 0) { - do { - *s1++ = '\0'; - } while(--n > 0); - } - } - return ret; -} 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/sys/exit/atexit.c b/lang/cem/libcc.ansi/sys/exit/atexit.c new file mode 100644 index 000000000..2cb16da9f --- /dev/null +++ b/lang/cem/libcc.ansi/sys/exit/atexit.c @@ -0,0 +1,12 @@ +/* $Id$ */ + +#include +#include "atexits.h" + +int atexit(void (*func)(void)) +{ + if (__funccnt >= NEXITS) + return 1; + __functab[__funccnt++] = func; + return 0; +} 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 56% rename from lang/cem/libcc.ansi/stdlib/exit.c rename to lang/cem/libcc.ansi/sys/exit/exit.c index 16be42f4d..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) +void exit(int status) { - register int i = __funccnt; - /* "Called in reversed order of their registration" */ - while (--i >= 0) - (*__functab[i])(); -} + while (__funccnt >= 0) + (*__functab[__funccnt])(); -void -exit(int status) -{ - _calls(); - if (_clean) _clean(); - _exit(status) ; + _exit(status); } diff --git a/lang/cem/libcc.ansi/sys/malloc/calloc.c b/lang/cem/libcc.ansi/sys/malloc/calloc.c new file mode 100644 index 000000000..e21c5266a --- /dev/null +++ b/lang/cem/libcc.ansi/sys/malloc/calloc.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +#if ACKCONF_WANT_MALLOC + +void* calloc(size_t nmemb, size_t size) +{ + 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; + + 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 95% rename from lang/cem/libcc.ansi/malloc/malloc.c rename to lang/cem/libcc.ansi/sys/malloc/malloc.c index 7eaaacaba..ea1381600 100644 --- a/lang/cem/libcc.ansi/malloc/malloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/malloc.c @@ -3,7 +3,9 @@ #include #include "malloc.h" -block_t __mem_root = {&__mem_root, 0}; +#if ACKCONF_WANT_MALLOC + +block_t __mem_root = { &__mem_root, 0 }; block_t* __mem_freelist = &__mem_root; /* Pulls more memory from the system. */ @@ -57,7 +59,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 +69,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 +86,7 @@ void* malloc(size_t size) } } -void free(void *ptr) +void free(void* ptr) { block_t* h = BLOCKOF(ptr); block_t* p; @@ -118,7 +120,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) @@ -149,3 +151,4 @@ void free(void *ptr) __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 89% rename from lang/cem/libcc.ansi/malloc/realloc.c rename to lang/cem/libcc.ansi/sys/malloc/realloc.c index 7e6dfbb70..6e2b4c924 100644 --- a/lang/cem/libcc.ansi/malloc/realloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/realloc.c @@ -4,7 +4,9 @@ #include #include "malloc.h" -void* realloc(void *ptr, size_t size) +#if ACKCONF_WANT_MALLOC + +void* realloc(void* ptr, size_t size) { block_t* h; size_t nblocks; @@ -25,7 +27,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; @@ -39,3 +41,5 @@ void* realloc(void *ptr, size_t size) free(ptr); return newptr; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/misc/clock.c b/lang/cem/libcc.ansi/sys/misc/clock.c new file mode 100644 index 000000000..f41e12dd4 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/clock.c @@ -0,0 +1,17 @@ +/* + * clock - determine the processor time used + */ +/* $Id$ */ + +#include +#include + +clock_t +clock(void) +{ + struct tms tms; + + times(&tms); + /* Assume that time_t can be converted to clock_t for Sys5 */ + return tms.tms_utime; +} diff --git a/lang/cem/libcc.ansi/sys/misc/getpass.c b/lang/cem/libcc.ansi/sys/misc/getpass.c new file mode 100644 index 000000000..a24c65dfd --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/getpass.c @@ -0,0 +1,72 @@ +/* + * getpass - ask for a password + */ +/* $Id$ */ + +#include +#include +#include +#include + +#if ACKCONF_WANT_TERMIOS + +#include +static int intr; + +static void catch(int sig) +{ + 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/sys/misc/isatty.c b/lang/cem/libcc.ansi/sys/misc/isatty.c new file mode 100644 index 000000000..a2d3f78e2 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/isatty.c @@ -0,0 +1,18 @@ +/* + * isatty - check if a file descriptor is associated with a terminal + */ +/* $Id$ */ + +#include + +#if ACKCONF_WANT_TERMIOS + +#include +int isatty(int fd) +{ + struct termios dummy; + + return(tcgetattr(fd, &dummy) == 0); +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/misc/mktemp.c b/lang/cem/libcc.ansi/sys/misc/mktemp.c new file mode 100644 index 000000000..41b72e5ef --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/mktemp.c @@ -0,0 +1,34 @@ +/* $Id$ */ +/* mktemp - make a name for a temporary file; only here for backwards compat */ +/* no _-protected system-calls? */ + +#include +#include + +char* mktemp(char* template) +{ + 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 */ + + /* 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; + } + } + return ("/"); +} 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/stdio/remove.c b/lang/cem/libcc.ansi/sys/misc/remove.c similarity index 63% rename from lang/cem/libcc.ansi/stdio/remove.c rename to lang/cem/libcc.ansi/sys/misc/remove.c index 204c4a25d..4c442df94 100644 --- a/lang/cem/libcc.ansi/stdio/remove.c +++ b/lang/cem/libcc.ansi/sys/misc/remove.c @@ -7,7 +7,11 @@ #include #include -int -remove(const char *filename) { +#if ACKCONF_WANT_EMULATED_REMOVE + +int remove(const char* filename) +{ return unlink(filename); } + +#endif diff --git a/lang/cem/libcc.ansi/sys/misc/sleep.c b/lang/cem/libcc.ansi/sys/misc/sleep.c new file mode 100644 index 000000000..97db561de --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/sleep.c @@ -0,0 +1,54 @@ +/* + * sleep - suspend current process for a number of seconds + */ +/* $Id$ */ + +#include +#include +#include +#include + +#if ACKCONF_WANT_EMULATED_SLEEP + +static jmp_buf setjmpbuf; + +static void +alfun(int sig) +{ + longjmp(setjmpbuf, 1); +} /* used with sleep() below */ + +void sleep(int n) +{ + /* 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)) + { + signal(SIGALRM, oldsig); + alarm(oldalarm); + return; + } + oldalarm = alarm(5000); /* Who cares how long, as long + * as it is long enough + */ + if (oldalarm > n) + oldalarm -= n; + else if (oldalarm) + { + n = oldalarm; + oldalarm = 1; + } + oldsig = signal(SIGALRM, alfun); + alarm(n); + for (;;) + { + /* allow for other handlers ... */ + pause(); + } +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/misc/system.c b/lang/cem/libcc.ansi/sys/misc/system.c new file mode 100644 index 000000000..8ed21d405 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/misc/system.c @@ -0,0 +1,62 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Id$ */ + +#include +#include +#include +#include + +#if ACKCONF_WANT_EMULATED_SYSTEM + +#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 */ +}; + +int system(const char* str) +{ + int pid, exitstatus, waitval; + int i; + + if ((pid = fork()) < 0) + return str ? -1 : 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", (char* const*)exec_tab, (char* const*)environ); + /* get here if execve fails ... */ + _exit(FAIL); /* see manual page */ + } + while ((waitval = wait(&exitstatus)) != pid) + { + if (waitval == -1) + break; + } + if (waitval == -1) + { + /* no child ??? or maybe interrupted ??? */ + exitstatus = -1; + } + if (!str) + { + if (exitstatus == FAIL << 8) /* execve() failed */ + exitstatus = 0; + else + exitstatus = 1; /* /bin/sh exists */ + } + return exitstatus; +} + +#endif diff --git a/lang/cem/libcc.ansi/time/time.c b/lang/cem/libcc.ansi/sys/misc/time.c similarity index 74% rename from lang/cem/libcc.ansi/time/time.c rename to lang/cem/libcc.ansi/sys/misc/time.c index f4def4c98..813cd2a30 100644 --- a/lang/cem/libcc.ansi/time/time.c +++ b/lang/cem/libcc.ansi/sys/misc/time.c @@ -8,16 +8,16 @@ #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; 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/stdio/clearerr.c b/lang/cem/libcc.ansi/sys/stdio/clearerr.c similarity index 57% rename from lang/cem/libcc.ansi/stdio/clearerr.c rename to lang/cem/libcc.ansi/sys/stdio/clearerr.c index 3455229a2..df673423b 100644 --- a/lang/cem/libcc.ansi/stdio/clearerr.c +++ b/lang/cem/libcc.ansi/sys/stdio/clearerr.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -void -(clearerr)(FILE *stream) +#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 57% rename from lang/cem/libcc.ansi/stdio/data.c rename to lang/cem/libcc.ansi/sys/stdio/data.c index 92be83b11..ccf1664ce 100644 --- a/lang/cem/libcc.ansi/stdio/data.c +++ b/lang/cem/libcc.ansi/sys/stdio/data.c @@ -3,26 +3,30 @@ */ /* $Id$ */ -#include +#include + +#if ACKCONF_WANT_STDIO 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, 0 }; + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/doprnt.c b/lang/cem/libcc.ansi/sys/stdio/doprnt.c new file mode 100644 index 000000000..9f74c7659 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/doprnt.c @@ -0,0 +1,399 @@ +/* + * doprnt.c - print formatted output + */ +/* $Id$ */ + +#include +#include +#include +#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) +{ + register int i, c; + + if (*f == '*') + { + *ip = va_arg((*app), int); + f++; + } + else + { + i = 0; + while ((c = *f - '0') >= 0 && c <= 9) + { + i = i * 10 + c; + f++; + } + *ip = i; + } + return f; +} + +#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 */ +#endif + +#define PUTC(c) \ + do \ + { \ + int i = putc(c, stream); \ + 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) +{ + long signed_val; + unsigned long unsigned_val; + 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; + } + + if (is_signed) + { + if (signed_val < 0) + { + *s++ = '-'; + signed_val = -signed_val; + } + 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) + return s; + } + 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; + } + + s = _i_compute(unsigned_val, base, s, precision); + + if (c == 'X') + while (old_s != s) + { + *old_s = toupper(*old_s); + old_s++; + } + + return s; +} + +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]; + + while (c = *fmt++) + { + if (c != '%') + { +#ifdef CPM + if (c == '\n') + { + PUTC('\r'); + } +#endif + PUTC(c); + nrchars++; + 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; + } + fmt++; + } while (!(flags & FL_NOMORE)); + + oldfmt = fmt; + fmt = gnum(fmt, &width, &ap); + if (fmt != oldfmt) + flags |= FL_WIDTHSPEC; + + if (*fmt == '.') + { + fmt++; + oldfmt = fmt; + fmt = gnum(fmt, &precision, &ap); + if (precision >= 0) + flags |= FL_PRECSPEC; + } + + if ((flags & FL_WIDTHSPEC) && width < 0) + { + width = -width; + flags |= FL_LJUST; + } + if (!(flags & FL_WIDTHSPEC)) + width = 0; + + 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 (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); + /* 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; +#if ACKCONF_WANT_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; + + if (precision >= sizeof(buf)) + precision = sizeof(buf) - 1; + + flags |= FL_SIGNEDCONV; + s = _f_print(&ap, flags, s, c, precision); + break; +#endif + case 'r': + ap = va_arg(ap, va_list); + fmt = va_arg(ap, char*); + continue; + } + zfill = ' '; + if (flags & FL_ZEROFILL) + zfill = '0'; + j = s - s1; + + /* between_fill is true under the following conditions: + * 1- the fill character is '0' + * and + * 2a- the number is of the form 0x... or 0X... + * or + * 2b- the number contains a sign or space + */ + between_fill = 0; + if ((flags & FL_ZEROFILL) + && (((c == 'x' || c == 'X') && (flags & FL_ALT)) + || (c == 'p') + || ((flags & FL_SIGNEDCONV) + && (*s1 == '+' || *s1 == '-' || *s1 == ' ')))) + between_fill++; + + if ((i = width - j) > 0) + 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++); + } + } + do + { + PUTC(zfill); + } while (--i); + } + + nrchars += j; + while (--j >= 0) + { + PUTC(*s1++); + } + + if (i > 0) + nrchars += i; + while (--i >= 0) + PUTC(zfill); + } + return nrchars; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/doscan.c b/lang/cem/libcc.ansi/sys/stdio/doscan.c new file mode 100644 index 000000000..3a1076bad --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/doscan.c @@ -0,0 +1,546 @@ +/* + * doscan.c - scan formatted input + */ +/* $Id$ */ + +#include +#include +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +#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 */ +#endif + +#define NUMLEN 512 +#define NR_CHARS 256 + +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 + * first 1 or 2 characters. This means that the base must be adjusted + * 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) +{ + 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; + } + + if (c == '-' || c == '+') + { + *bufp++ = c; + if (--width) + c = getc(stream); + } + + 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) + { + *bufp++ = c; + if (--width) + c = getc(stream); + } + } + else if (type == 'i') + base = 10; + + while (width) + { + if (((base == 10) && isdigit(c)) + || ((base == 16) && isxdigit(c)) + || ((base == 8) && isdigit(c) && (c < '8')) + || ((base == 2) && isdigit(c) && (c < '2'))) + { + *bufp++ = c; + if (--width) + c = getc(stream); + } + else + break; + } + + if (width && c != EOF) + ungetc(c, stream); + if (type == 'i') + base = 0; + *basep = base; + *bufp = '\0'; + return bufp - 1; +} + +#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 + * that 1.el leaves the 'l' in the input queue. Since all detection of + * format errors is done here, _doscan() doesn't call strtod() when it's + * 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) +{ + register char* bufp = inp_buf; + int digit_seen = 0; + + if (c == '-' || c == '+') + { + *bufp++ = c; + if (--width) + c = getc(stream); + } + + 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')) + { + *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); + *bufp = '\0'; + return bufp - 1; +} +#endif + +/* + * the routine that does the scanning + */ + +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 */ +#if ACKCONF_WANT_STDIO_FLOAT + long double ld_val; +#endif + + if (!*format) + return 0; + + while (1) + { + if (isspace(*format)) + { + while (isspace(*format)) + format++; /* skip whitespace */ + ic = getc(stream); + nrchars++; + while (isspace(ic)) + { + ic = getc(stream); + nrchars++; + } + if (ic != EOF) + ungetc(ic, stream); + nrchars--; + } + if (!*format) + break; /* end of format */ + + if (*format != '%') + { + ic = getc(stream); + nrchars++; + if (ic != *format++) + { + if (ic != EOF) + ungetc(ic, stream); + nrchars--; + break; /* error */ + } + continue; + } + format++; + if (*format == '%') + { + ic = getc(stream); + nrchars++; + if (ic == '%') + { + format++; + continue; + } + else + break; + } + flags = 0; + if (*format == '*') + { + format++; + flags |= FL_NOASSIGN; + } + if (isdigit(*format)) + { + flags |= FL_WIDTHSPEC; + 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; + } + kind = *format; + 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 %[ */ + ic = getc(stream); + 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); + /* 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; + + 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; + + 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 (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)) + { + 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; + + 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++; + } + 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; +#if ACKCONF_WANT_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; + + 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 */ + conv++; + if (!(flags & FL_NOASSIGN) && kind != 'n') + done++; + format++; + } + 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 53% rename from lang/cem/libcc.ansi/stdio/fclose.c rename to lang/cem/libcc.ansi/sys/stdio/fclose.c index 0003535a7..9a56b4cfe 100644 --- a/lang/cem/libcc.ansi/stdio/fclose.c +++ b/lang/cem/libcc.ansi/sys/stdio/fclose.c @@ -8,23 +8,29 @@ #include #include "loc_incl.h" -int -fclose(FILE *fp) +#if ACKCONF_WANT_STDIO + +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; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fdopen.c b/lang/cem/libcc.ansi/sys/stdio/fdopen.c new file mode 100644 index 000000000..084d39c14 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fdopen.c @@ -0,0 +1,69 @@ +/* + * fdopen - convert a (UNIX) file descriptor into a FILE pointer + */ +/* $Id$ */ + +#include +#include +#include "../stdio/loc_incl.h" + +#if ACKCONF_WANT_STDIO + +FILE* fdopen(int fd, const char* mode) +{ + register int i; + 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; + + 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 ((flags & _IOREAD) && (flags & _IOWRITE)) + flags &= ~(_IOREADING | _IOWRITING); + + stream->_count = 0; + stream->_fd = fd; + stream->_flags = flags; + stream->_buf = NULL; + __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 54% rename from lang/cem/libcc.ansi/stdio/feof.c rename to lang/cem/libcc.ansi/sys/stdio/feof.c index 5c7d4a74c..71451ee0f 100644 --- a/lang/cem/libcc.ansi/stdio/feof.c +++ b/lang/cem/libcc.ansi/sys/stdio/feof.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(feof)(FILE *stream) +#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 56% rename from lang/cem/libcc.ansi/stdio/ferror.c rename to lang/cem/libcc.ansi/sys/stdio/ferror.c index 44880785d..f346ca791 100644 --- a/lang/cem/libcc.ansi/stdio/ferror.c +++ b/lang/cem/libcc.ansi/sys/stdio/ferror.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(ferror)(FILE *stream) +#if ACKCONF_WANT_STDIO + +int(ferror)(FILE* stream) { return ferror(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fflush.c b/lang/cem/libcc.ansi/sys/stdio/fflush.c new file mode 100644 index 000000000..f0f53bb25 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fflush.c @@ -0,0 +1,92 @@ +/* + * fflush.c - flush stream(s) + */ +/* $Id$ */ + +#include +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +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->_buf + || (!io_testflag(stream, _IOREADING) + && !io_testflag(stream, _IOWRITING))) + return 0; + if (io_testflag(stream, _IOREADING)) + { + /* (void) fseek(stream, 0L, SEEK_CUR); */ + int adjust = 0; + if (stream->_buf && !io_testflag(stream, _IONBF)) + adjust = stream->_count; + stream->_count = 0; + 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; + + if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */ + stream->_flags &= ~_IOWRITING; + + count = stream->_ptr - stream->_buf; + stream->_ptr = stream->_buf; + + if (count <= 0) + return 0; + + 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); + + stream->_count = 0; + + if (count == c1) + return 0; + + stream->_flags |= _IOERR; + return EOF; +} + +static void cleanup(void) +{ + register int i; + + for (i = 0; i < FOPEN_MAX; i++) + 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); + } +} + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fgetc.c b/lang/cem/libcc.ansi/sys/stdio/fgetc.c similarity index 58% rename from lang/cem/libcc.ansi/stdio/fgetc.c rename to lang/cem/libcc.ansi/sys/stdio/fgetc.c index 9e3df5016..1b153c7f9 100644 --- a/lang/cem/libcc.ansi/stdio/fgetc.c +++ b/lang/cem/libcc.ansi/sys/stdio/fgetc.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -fgetc(FILE *stream) +#if ACKCONF_WANT_STDIO + +int fgetc(FILE* stream) { return getc(stream); } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fgets.c b/lang/cem/libcc.ansi/sys/stdio/fgets.c new file mode 100644 index 000000000..14ecc488a --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fgets.c @@ -0,0 +1,36 @@ +/* + * fgets.c - get a string from a file + */ +/* $Id$ */ + +#include + +#if ACKCONF_WANT_STDIO + +char* fgets(char* s, register int n, register FILE* stream) +{ + register int ch; + register char* ptr; + + ptr = s; + while (--n > 0 && (ch = getc(stream)) != EOF) + { + *ptr++ = ch; + if (ch == '\n') + break; + } + if (ch == EOF) + { + if (feof(stream)) + { + if (ptr == s) + return NULL; + } + else + return NULL; + } + *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 54% rename from lang/cem/libcc.ansi/stdio/fileno.c rename to lang/cem/libcc.ansi/sys/stdio/fileno.c index b36b7cf29..e42608845 100644 --- a/lang/cem/libcc.ansi/stdio/fileno.c +++ b/lang/cem/libcc.ansi/sys/stdio/fileno.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(fileno)(FILE *stream) +#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 58% rename from lang/cem/libcc.ansi/stdio/fillbuf.c rename to lang/cem/libcc.ansi/sys/stdio/fillbuf.c index d01e208bf..75187edac 100644 --- a/lang/cem/libcc.ansi/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fillbuf.c @@ -8,57 +8,69 @@ #include #include "loc_incl.h" -int -__fillbuf(register FILE *stream) +#if ACKCONF_WANT_STDIO + +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; @@ -67,3 +79,5 @@ __fillbuf(register FILE *stream) return *stream->_ptr++; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fltpr.c b/lang/cem/libcc.ansi/sys/stdio/fltpr.c new file mode 100644 index 000000000..3fdc80852 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fltpr.c @@ -0,0 +1,212 @@ +/* + * fltpr.c - print floating point numbers + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT + +static char* +_pfloat(long double r, register char* s, int n, int flags) +{ + register char* s1; + int sign, dp; + register int i; + + s1 = _fcvt(r, n, &dp, &sign); + if (sign) + *s++ = '-'; + else if (flags & FL_SIGN) + *s++ = '+'; + else if (flags & FL_SPACE) + *s++ = ' '; + + 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)) + *s++ = '.'; + while (++dp <= 0) + { + if (--i < 0) + break; + *s++ = '0'; + } + while (--i >= 0) + if (*s1) + *s++ = *s1++; + else + *s++ = '0'; + return s; +} + +static char* +_pscien(long double r, register char* s, int n, int flags) +{ + int sign, dp; + register char* s1; + + s1 = _ecvt(r, n + 1, &dp, &sign); + if (sign) + *s++ = '-'; + else if (flags & FL_SIGN) + *s++ = '+'; + else if (flags & FL_SPACE) + *s++ = ' '; + + *s++ = *s1++; + if ((n > 0) || (flags & FL_ALT)) + *s++ = '.'; + while (--n >= 0) + if (*s1) + *s++ = *s1++; + else + *s++ = '0'; + *s++ = 'e'; + if (r != 0) + --dp; + if (dp < 0) + { + *s++ = '-'; + dp = -dp; + } + else + { + *s++ = '+'; + } + if (dp >= 100) + { + *s++ = '0' + (dp / 100); + dp %= 100; + } + *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)) + +static char* +_gcvt(long double value, int ndigit, char* s, int flags) +{ + int sign, dp; + register char *s1, *s2; + register int i; + register int nndigit = ndigit; + + s1 = _ecvt(value, ndigit, &dp, &sign); + s2 = s; + if (sign) + *s2++ = '-'; + else if (flags & FL_SIGN) + *s2++ = '+'; + else if (flags & FL_SPACE) + *s2++ = ' '; + + if (!(flags & FL_ALT)) + for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) + nndigit--; + + if (USE_EXP(dp, ndigit)) + { + /* Use E format */ + dp--; + *s2++ = *s1++; + if ((nndigit > 1) || (flags & FL_ALT)) + *s2++ = '.'; + while (--nndigit > 0) + *s2++ = *s1++; + *s2++ = 'e'; + if (dp < 0) + { + *s2++ = '-'; + dp = -dp; + } + else + *s2++ = '+'; + s2 += NDIGINEXP(dp); + *s2 = 0; + for (i = NDIGINEXP(dp); i > 0; i--) + { + *--s2 = dp % 10 + '0'; + dp /= 10; + } + return s; + } + /* Use f format */ + if (dp <= 0) + { + if (*s1 != '0') + { + /* otherwise the whole number is 0 */ + *s2++ = '0'; + *s2++ = '.'; + } + while (dp < 0) + { + dp++; + *s2++ = '0'; + } + } + for (i = 1; i <= nndigit; i++) + { + *s2++ = *s1++; + if (i == dp) + *s2++ = '.'; + } + if (i <= dp) + { + while (i++ <= dp) + *s2++ = '0'; + *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) +{ + 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); + + 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'; + } + return s; +} +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/flushbuf.c b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c new file mode 100644 index 000000000..81325d3a6 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c @@ -0,0 +1,154 @@ +/* + * flushbuf.c - flush a buffer + */ +/* $Id$ */ + +#include +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +static int +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) + { + nbytes -= c; + buf += c; + } + return c > 0; +} + +int __flushbuf(int c, FILE* stream) +{ + __register_stdio_cleanup(); + 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))) + { + stream->_flags |= _IONBF; + } + else + { + stream->_flags |= _IOLBF | _IOMYBUF; + stream->_bufsiz = BUFSIZ; + stream->_count = -1; + } + } + else + { + if (!(stream->_buf = (unsigned char*)malloc(BUFSIZ))) + { + stream->_flags |= _IONBF; + } + else + { + stream->_flags |= _IOMYBUF; + stream->_bufsiz = BUFSIZ; + if (!io_testflag(stream, _IOLBF)) + stream->_count = BUFSIZ - 1; + else + stream->_count = -1; + } + } + stream->_ptr = stream->_buf; + } + } + + if (io_testflag(stream, _IONBF)) + { + char c1 = c; + + stream->_count = 0; + 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) + { + stream->_flags |= _IOERR; + return EOF; + } + 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) + { + int count = -stream->_count; + + stream->_ptr = stream->_buf; + stream->_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)) + { + stream->_flags |= _IOERR; + return EOF; + } + } + } + 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) + { + stream->_flags |= _IOERR; + return EOF; + } + } + if (!do_write(fileno(stream), (char*)stream->_buf, count)) + { + *(stream->_buf) = c; + stream->_flags |= _IOERR; + return EOF; + } + } + *(stream->_buf) = c; + } + 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 59% rename from lang/cem/libcc.ansi/stdio/fopen.c rename to lang/cem/libcc.ansi/sys/stdio/fopen.c index a0bd9f40c..ce8c5634e 100644 --- a/lang/cem/libcc.ansi/stdio/fopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/fopen.c @@ -10,7 +10,9 @@ #include #include "loc_incl.h" -#define PMODE 0666 +#if ACKCONF_WANT_STDIO + +#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 +33,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 +86,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; @@ -107,3 +114,5 @@ fopen(const char *name, const char *mode) __iotab[i] = stream; return stream; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fprintf.c b/lang/cem/libcc.ansi/sys/stdio/fprintf.c new file mode 100644 index 000000000..3085bf96a --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fprintf.c @@ -0,0 +1,26 @@ +/* + * fprintf - write output on a stream + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int fprintf(FILE* stream, const char* format, ...) +{ + va_list ap; + int retval; + + va_start(ap, format); + + retval = _doprnt(format, ap, stream); + + va_end(ap); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fputc.c b/lang/cem/libcc.ansi/sys/stdio/fputc.c similarity index 52% rename from lang/cem/libcc.ansi/stdio/fputc.c rename to lang/cem/libcc.ansi/sys/stdio/fputc.c index 334a34151..cf67ca421 100644 --- a/lang/cem/libcc.ansi/stdio/fputc.c +++ b/lang/cem/libcc.ansi/sys/stdio/fputc.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -fputc(int c, FILE *stream) +#if ACKCONF_WANT_STDIO + +int fputc(int c, FILE* stream) { return putc(c, stream); } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fputs.c b/lang/cem/libcc.ansi/sys/stdio/fputs.c new file mode 100644 index 000000000..5c4ea7caa --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/fputs.c @@ -0,0 +1,23 @@ +/* + * fputs - print a string + */ +/* $Id$ */ + +#include + +#if ACKCONF_WANT_STDIO + +int fputs(register const char* s, register FILE* stream) +{ + register int i = 0; + + while (*s) + if (putc(*s++, stream) == EOF) + return EOF; + else + i++; + + return i; +} + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fread.c b/lang/cem/libcc.ansi/sys/stdio/fread.c similarity index 62% rename from lang/cem/libcc.ansi/stdio/fread.c rename to lang/cem/libcc.ansi/sys/stdio/fread.c index f4ac6b9d4..5bdcf41ac 100644 --- a/lang/cem/libcc.ansi/stdio/fread.c +++ b/lang/cem/libcc.ansi/sys/stdio/fread.c @@ -3,20 +3,24 @@ */ /* $Id$ */ -#include +#include + +#if ACKCONF_WANT_STDIO 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 @@ -27,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/sys/stdio/freopen.c b/lang/cem/libcc.ansi/sys/stdio/freopen.c new file mode 100644 index 000000000..255e04cb6 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/freopen.c @@ -0,0 +1,98 @@ +/* + * freopen.c - open a file and associate a stream with it + */ +/* $Id$ */ + +#include +#include +#include +#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 + * does not exist. The reason is given in fopen.c. + */ + +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)); + + 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; + } + break; + } + + if ((rwflags & O_TRUNC) + || (((fd = open(name, rwmode)) < 0) + && (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]) + { + __iotab[i] = 0; + break; + } + } + if (stream != stdin && stream != stdout && stream != stderr) + free((void*)stream); + return (FILE*)NULL; + } + + stream->_count = 0; + stream->_fd = fd; + 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 57% rename from lang/cem/libcc.ansi/stdio/fscanf.c rename to lang/cem/libcc.ansi/sys/stdio/fscanf.c index 25349b24e..b06d47253 100644 --- a/lang/cem/libcc.ansi/stdio/fscanf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fscanf.c @@ -3,12 +3,13 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -fscanf(FILE *stream, const char *format, ...) +#if ACKCONF_WANT_STDIO + +int fscanf(FILE* stream, const char* format, ...) { va_list ap; int retval; @@ -21,3 +22,5 @@ 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 66% rename from lang/cem/libcc.ansi/stdio/fseek.c rename to lang/cem/libcc.ansi/sys/stdio/fseek.c index 83d7640a3..c1ecd5650 100644 --- a/lang/cem/libcc.ansi/stdio/fseek.c +++ b/lang/cem/libcc.ansi/sys/stdio/fseek.c @@ -8,8 +8,9 @@ #include #include "loc_incl.h" -int -fseek(FILE *stream, long int offset, int whence) +#if ACKCONF_WANT_STDIO + +int fseek(FILE* stream, long int offset, int whence) { int adjust = 0; long pos; @@ -17,16 +18,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)) @@ -35,3 +40,5 @@ 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 54% rename from lang/cem/libcc.ansi/stdio/ftell.c rename to lang/cem/libcc.ansi/sys/stdio/ftell.c index 54c266c38..8053a1de2 100644 --- a/lang/cem/libcc.ansi/stdio/ftell.c +++ b/lang/cem/libcc.ansi/sys/stdio/ftell.c @@ -6,26 +6,31 @@ #include #include #include -#include "loc_incl.h" +#include "loc_incl.h" -long ftell(FILE *stream) +#if ACKCONF_WANT_STDIO + +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; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/fwrite.c b/lang/cem/libcc.ansi/sys/stdio/fwrite.c similarity index 50% rename from lang/cem/libcc.ansi/stdio/fwrite.c rename to lang/cem/libcc.ansi/sys/stdio/fwrite.c index ed9a89f66..02112e76a 100644 --- a/lang/cem/libcc.ansi/stdio/fwrite.c +++ b/lang/cem/libcc.ansi/sys/stdio/fwrite.c @@ -3,27 +3,32 @@ */ /* $Id$ */ -#include +#include + +#if ACKCONF_WANT_STDIO 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; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/getc.c b/lang/cem/libcc.ansi/sys/stdio/getc.c similarity index 53% rename from lang/cem/libcc.ansi/stdio/getc.c rename to lang/cem/libcc.ansi/sys/stdio/getc.c index bd5e8cb77..b69ecf9d6 100644 --- a/lang/cem/libcc.ansi/stdio/getc.c +++ b/lang/cem/libcc.ansi/sys/stdio/getc.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(getc)(FILE *stream) +#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 60% rename from lang/cem/libcc.ansi/stdio/getchar.c rename to lang/cem/libcc.ansi/sys/stdio/getchar.c index 8c2955ba4..79f6764ab 100644 --- a/lang/cem/libcc.ansi/stdio/getchar.c +++ b/lang/cem/libcc.ansi/sys/stdio/getchar.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(getchar)(void) +#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 53% rename from lang/cem/libcc.ansi/stdio/icompute.c rename to lang/cem/libcc.ansi/sys/stdio/icompute.c index 78c63580f..9b48d51a4 100644 --- a/lang/cem/libcc.ansi/stdio/icompute.c +++ b/lang/cem/libcc.ansi/sys/stdio/icompute.c @@ -3,19 +3,22 @@ */ /* $Id$ */ -#include "loc_incl.h" +#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) +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; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/sys/stdio/loc_incl.h similarity index 93% rename from lang/cem/libcc.ansi/stdio/loc_incl.h rename to lang/cem/libcc.ansi/sys/stdio/loc_incl.h index 126a31faf..b30d3272a 100644 --- a/lang/cem/libcc.ansi/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/sys/stdio/loc_incl.h @@ -14,15 +14,16 @@ 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); -#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/stdio/printf.c b/lang/cem/libcc.ansi/sys/stdio/printf.c similarity index 59% rename from lang/cem/libcc.ansi/stdio/printf.c rename to lang/cem/libcc.ansi/sys/stdio/printf.c index da49b2efc..6b118c859 100644 --- a/lang/cem/libcc.ansi/stdio/printf.c +++ b/lang/cem/libcc.ansi/sys/stdio/printf.c @@ -3,12 +3,13 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -printf(const char *format, ...) +#if ACKCONF_WANT_STDIO + +int printf(const char* format, ...) { va_list ap; int retval; @@ -21,3 +22,5 @@ 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 53% rename from lang/cem/libcc.ansi/stdio/putc.c rename to lang/cem/libcc.ansi/sys/stdio/putc.c index cf79939b2..ed8d1e519 100644 --- a/lang/cem/libcc.ansi/stdio/putc.c +++ b/lang/cem/libcc.ansi/sys/stdio/putc.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(putc)(int c, FILE *stream) +#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 62% rename from lang/cem/libcc.ansi/stdio/putchar.c rename to lang/cem/libcc.ansi/sys/stdio/putchar.c index 2cddd5e10..73f0e3a01 100644 --- a/lang/cem/libcc.ansi/stdio/putchar.c +++ b/lang/cem/libcc.ansi/sys/stdio/putchar.c @@ -3,10 +3,13 @@ */ /* $Id$ */ -#include +#include -int -(putchar)(int c) +#if ACKCONF_WANT_STDIO + +int(putchar)(int c) { return putchar(c); } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/puts.c b/lang/cem/libcc.ansi/sys/stdio/puts.c new file mode 100644 index 000000000..3592e7cfe --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/puts.c @@ -0,0 +1,27 @@ +/* + * puts.c - print a string onto the standard output stream + */ +/* $Id$ */ + +#include + +#if ACKCONF_WANT_STDIO + +int puts(register const char* s) +{ + register FILE* file = stdout; + register int i = 0; + + while (*s) + { + if (putc(*s++, file) == EOF) + return EOF; + else + i++; + } + if (putc('\n', file) == EOF) + return EOF; + return i + 1; +} + +#endif diff --git a/lang/cem/libcc.ansi/stdio/scanf.c b/lang/cem/libcc.ansi/sys/stdio/scanf.c similarity index 62% rename from lang/cem/libcc.ansi/stdio/scanf.c rename to lang/cem/libcc.ansi/sys/stdio/scanf.c index 2157419db..d52788084 100644 --- a/lang/cem/libcc.ansi/stdio/scanf.c +++ b/lang/cem/libcc.ansi/sys/stdio/scanf.c @@ -3,12 +3,13 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -scanf(const char *format, ...) +#if ACKCONF_WANT_STDIO + +int scanf(const char* format, ...) { va_list ap; int retval; @@ -22,4 +23,4 @@ scanf(const char *format, ...) return retval; } - +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/setbuf.c b/lang/cem/libcc.ansi/sys/stdio/setbuf.c new file mode 100644 index 000000000..5ac3e8ece --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/setbuf.c @@ -0,0 +1,16 @@ +/* + * setbuf.c - control buffering of a stream + */ +/* $Id$ */ + +#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/sys/stdio/setvbuf.c b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c new file mode 100644 index 000000000..1dfc6a0be --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c @@ -0,0 +1,57 @@ +/* + * setbuf.c - control buffering of a stream + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int setvbuf(register FILE* stream, char* buf, int mode, size_t size) +{ + int retval = 0; + + __register_stdio_cleanup(); + if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) + return EOF; + + 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) + { + retval = EOF; + } + else + { + stream->_flags |= _IOMYBUF; + } + } + + stream->_buf = (unsigned char*)buf; + + stream->_count = 0; + stream->_flags |= mode; + stream->_ptr = stream->_buf; + + if (!buf) + { + stream->_bufsiz = 1; + } + else + { + stream->_bufsiz = size; + } + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/snprintf.c b/lang/cem/libcc.ansi/sys/stdio/snprintf.c new file mode 100644 index 000000000..4ee372faa --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/snprintf.c @@ -0,0 +1,34 @@ +/* + * sprintf - print formatted output on an array + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int snprintf(char* s, size_t len, const char* format, ...) +{ + va_list ap; + int retval; + FILE tmp_stream; + + 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; + + retval = _doprnt(format, ap, &tmp_stream); + putc('\0', &tmp_stream); + + va_end(ap); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/sprintf.c b/lang/cem/libcc.ansi/sys/stdio/sprintf.c new file mode 100644 index 000000000..3a116c0f4 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/sprintf.c @@ -0,0 +1,34 @@ +/* + * sprintf - print formatted output on an array + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int sprintf(char* s, const char* format, ...) +{ + va_list ap; + int retval; + FILE tmp_stream; + + 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; + + retval = _doprnt(format, ap, &tmp_stream); + putc('\0', &tmp_stream); + + va_end(ap); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/sscanf.c b/lang/cem/libcc.ansi/sys/stdio/sscanf.c new file mode 100644 index 000000000..bd39100bd --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/sscanf.c @@ -0,0 +1,34 @@ +/* + * sscanf - read formatted output from a string + */ +/* $Id$ */ + +#include +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int sscanf(const char* s, const char* format, ...) +{ + va_list ap; + int retval; + FILE tmp_stream; + + 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); + + retval = _doscan(&tmp_stream, format, ap); + + va_end(ap); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/stdio/tmpfile.c b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c similarity index 53% rename from lang/cem/libcc.ansi/stdio/tmpfile.c rename to lang/cem/libcc.ansi/sys/stdio/tmpfile.c index 19c91593d..e50fd0d35 100644 --- a/lang/cem/libcc.ansi/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c @@ -9,20 +9,26 @@ #include #include "loc_incl.h" -FILE * -tmpfile(void) { - static char name_buffer[L_tmpnam] = "/tmp/tmp." ; - static char *name = NULL; - FILE *file; +#if ACKCONF_WANT_STDIO - if (!name) { +FILE* tmpfile(void) +{ + static char name_buffer[L_tmpnam] = "/tmp/tmp."; + static char* name = NULL; + FILE* file; + + 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; } + +#endif diff --git a/lang/cem/libcc.ansi/stdio/tmpnam.c b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c similarity index 64% rename from lang/cem/libcc.ansi/stdio/tmpnam.c rename to lang/cem/libcc.ansi/sys/stdio/tmpnam.c index 9c6bc6be5..89fb9a4e3 100644 --- a/lang/cem/libcc.ansi/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c @@ -9,20 +9,28 @@ #include #include "loc_incl.h" -char * -tmpnam(char *s) { +#if ACKCONF_WANT_STDIO + +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; } + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/ungetc.c b/lang/cem/libcc.ansi/sys/stdio/ungetc.c new file mode 100644 index 000000000..a53cc1cf9 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/ungetc.c @@ -0,0 +1,31 @@ +/* + * ungetc.c - push a character back onto an input stream + */ +/* $Id$ */ + +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +int ungetc(int ch, FILE* stream) +{ + unsigned char* p; + + if (ch == EOF || !io_testflag(stream, _IOREADING)) + return EOF; + if (stream->_ptr == stream->_buf) + { + if (stream->_count != 0) + return EOF; + stream->_ptr++; + } + stream->_count++; + p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */ + /* ungetc() in sscanf() shouldn't write in rom */ + if (*p != (unsigned char)ch) + *p = (unsigned char)ch; + return ch; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/vfprintf.c b/lang/cem/libcc.ansi/sys/stdio/vfprintf.c new file mode 100644 index 000000000..02b473dd6 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/vfprintf.c @@ -0,0 +1,17 @@ +/* + * vfprintf - formatted output without ellipsis + */ +/* $Id$ */ + +#include +#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 50% rename from lang/cem/libcc.ansi/stdio/vprintf.c rename to lang/cem/libcc.ansi/sys/stdio/vprintf.c index bc25f7363..5cc6b837f 100644 --- a/lang/cem/libcc.ansi/stdio/vprintf.c +++ b/lang/cem/libcc.ansi/sys/stdio/vprintf.c @@ -3,12 +3,15 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include "loc_incl.h" -int -vprintf(const char *format, va_list arg) +#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/sys/stdio/vsnprintf.c b/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c new file mode 100644 index 000000000..d973b8066 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c @@ -0,0 +1,29 @@ +/* + * vsprintf - print formatted output without ellipsis on an array + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +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; + + retval = _doprnt(format, arg, &tmp_stream); + putc('\0', &tmp_stream); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/vsprintf.c b/lang/cem/libcc.ansi/sys/stdio/vsprintf.c new file mode 100644 index 000000000..00065bec0 --- /dev/null +++ b/lang/cem/libcc.ansi/sys/stdio/vsprintf.c @@ -0,0 +1,29 @@ +/* + * vsprintf - print formatted output without ellipsis on an array + */ +/* $Id$ */ + +#include +#include +#include "loc_incl.h" + +#if ACKCONF_WANT_STDIO + +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; + + retval = _doprnt(format, arg, &tmp_stream); + putc('\0', &tmp_stream); + + return retval; +} + +#endif 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 diff --git a/lang/cem/libcc.ansi/time/asctime.c b/lang/cem/libcc.ansi/time/asctime.c deleted file mode 100644 index 2b0adc9ad..000000000 --- a/lang/cem/libcc.ansi/time/asctime.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * asctime - print a date - */ -/* $Id$ */ - -#include -#include -#include "loc_time.h" - -#define DATE_STR "??? ??? ?? ??:??:?? ????\n" - -static char * -two_digits(register char *pb, int i, int nospace) -{ - *pb = (i / 10) % 10 + '0'; - if (!nospace && *pb == '0') *pb = ' '; - pb++; - *pb++ = (i % 10) + '0'; - return ++pb; -} - -static char * -four_digits(register char *pb, int i) -{ - i %= 10000; - *pb++ = (i / 1000) + '0'; - i %= 1000; - *pb++ = (i / 100) + '0'; - i %= 100; - *pb++ = (i / 10) + '0'; - *pb++ = (i % 10) + '0'; - return ++pb; -} - -char *asctime(const struct tm *timeptr) -{ - static char buf[26]; - 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++; - pb++; - ps = _months[timeptr->tm_mon]; - n = ABB_LEN; - 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); - - 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 deleted file mode 100644 index 3c7f81d37..000000000 --- a/lang/cem/libcc.ansi/time/clock.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * clock - determine the processor time used - */ -/* $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 - -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); - /* 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 deleted file mode 100644 index 00da98fa4..000000000 --- a/lang/cem/libcc.ansi/time/misc.c +++ /dev/null @@ -1,496 +0,0 @@ -/* - * misc - data and miscellaneous routines - */ -/* $Id$ */ - -#include -#include -#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 -#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 */ - -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) -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 }; - -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 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 } - }; - -#if !defined(_POSIX_SOURCE) && !defined(__USG) -#define USE_TABLE 1 -#endif - -#if USE_TABLE -static int usetable = 1; - -typedef struct table { - const char *tz_name; - const int daylight; - const long zoneoffset; -} TABLE; - -#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 } -}; - -/* - * The function ZoneFromTable() searches the table for the current - * timezone. It saves the last one found in ntstr or dststr, depending on - * wheter the name is for daylight-saving-time or not. - * Both ntstr and dststr are TZ_LEN + 1 chars. - */ -static void -ZoneFromTable(long timezone) -{ - register TABLE *tptr = TimezoneTable; - - 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); - dststr[TZ_LEN] = '\0'; - } - } - tptr++; - } -} -#endif /* USE_TABLE */ - -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 (n < TZ_LEN) - *buf++ = *p; - p++; - n++; - } - if (n < 3) return NULL; /* error */ - *buf = '\0'; - return p; -} - -static const char * -parseTime(register long *tm, const char *p, register struct dsttype *dst) -{ - register int n = 0; - register const char *q = p; - char ds_type = (dst ? dst->ds_type : '\0'); - - if (dst) dst->ds_type = 'U'; - - *tm = 0; - 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; - *tm = n * 60 * 60; - if (*p == ':') { - p++; - n = 0; - while(*p >= '0' && *p <= '9') { - n = 10 * n + (*p++ - '0'); - } - if (q == p) return NULL; /* format error */ - if (n < 0 || n >= 60) return NULL; - *tm += n * 60; - if (*p == ':') { - p++; - n = 0; - while(*p >= '0' && *p <= '9') { - n = 10 * n + (*p++ - '0'); - } - if (q == p) return NULL; /* format error */ - if (n < 0 || n >= 60) return NULL; - *tm += n; - } - } - 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) -{ - register const char *q; - register int n = 0; - int cnt = 0; - const int bnds[3][2] = { { 1, 12 }, - { 1, 5 }, - { 0, 6} - }; - char ds_type; - - if (*p != 'M') { - if (*p == 'J') { - *buf++ = *p++; - ds_type = 'J'; - } - else ds_type = 'Z'; - q = p; - 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; - dstinfo->ds_type = ds_type; - dstinfo->ds_date[0] = n; - return p; - } - ds_type = 'M'; - do { - *buf++ = *p++; - q = p; - n = 0; - 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; - dstinfo->ds_date[cnt] = n; - cnt++; - } while (cnt < 3 && *p == '.'); - 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) -{ - long tim; - register const char *q; - - if (!(p = parseDate(buf, p, &dststart))) return NULL; - buf += strlen(buf); - if (*p == '/') { - q = ++p; - if (!(p = parseTime(&tim, p, &dststart))) return NULL; - while( p != q) *buf++ = *q++; - } - if (*p != ',') return NULL; - p++; - if (!(p = parseDate(buf, p, &dstend))) return NULL; - buf += strlen(buf); - if (*p == '/') { - q = ++p; - if (!(p = parseTime(&tim, p, &dstend))) return NULL; - while(*buf++ = *q++); - } - if (*p) return NULL; - return p; -} - -/* The following routine parses timezone information in POSIX-format. For - * the requirements, see IEEE Std 1003.1-1988 section 8.1.1. - * The function returns as soon as it spots an error. - */ -static void -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 USE_TABLE - usetable = 0; -#endif - if (*p == ':') { - /* - * According to POSIX, this is implementation defined. - * Since it depends on the particular operating system, we - * can do nothing. - */ - return; - } - - if (!strcmp(lastTZ, p)) return; /* nothing changed */ - - *_tzname[0] = '\0'; - *_tzname[1] = '\0'; - dststart.ds_type = 'U'; - dststart.ds_sec = 2 * 60 * 60; - dstend.ds_type = 'U'; - dstend.ds_sec = 2 * 60 * 60; - - if (strlen(p) > 2 * RULE_LEN) return; - strcpy(lastTZ, p); - - if (!(p = parseZoneName(buffer, p))) return; - - if (*p == '-') { - sign = -1; - p++; - } else if (*p == '+') p++; - - if (!(p = parseTime(&tz, p, NULL))) return; - tz *= sign; - _timezone = tz; - strncpy(_tzname[0], buffer, TZ_LEN); - - if (!(_daylight = (*p != '\0'))) return; - - buffer[0] = '\0'; - 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; - p++; - if (strlen(p) > RULE_LEN) return; - if (!(p = parseRule(buffer, p))) return; - } -} - -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 -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; - return day - (day - first) % 7; -} - -static int -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); - } - day = 0; - month = 1; - 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; - return day; -} - -/* - * The default dst transitions are those for Western Europe (except Great - * Britain). - */ -unsigned -_dstget(register struct tm *timep) -{ - int begindst, enddst; - register struct dsttype *dsts = &dststart, *dste = &dstend; - int do_dst = 0; - - if (_daylight == -1) - _tzset(); - - timep->tm_isdst = _daylight; - if (!_daylight) return 0; - - if (dsts->ds_type != 'U') - begindst = date_of(dsts, timep); - 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 */ - - /* assume begindst != enddst (otherwise it would be no use) */ - if (begindst < enddst) { /* northern hemisphere */ - if (timep->tm_yday > begindst && timep->tm_yday < enddst) - do_dst = 1; - } 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 */ - long cursec; - - if (timep->tm_yday == begindst) - dsttranssec = dsts->ds_sec; - else dsttranssec = dste->ds_sec; - cursec = ((timep->tm_hour * 60) + timep->tm_min) * 60L - + 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); -#endif - if (do_dst) return _dst_off; - timep->tm_isdst = 0; - return 0; -} diff --git a/lang/cem/libcc.ansi/time/strftime.c b/lang/cem/libcc.ansi/time/strftime.c deleted file mode 100644 index c002d3179..000000000 --- a/lang/cem/libcc.ansi/time/strftime.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * strftime - convert a structure to a string, controlled by an argument - */ -/* $Id$ */ - -#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) -{ - while (width > 0 || (width < 0 && *str)) { - if (!maxsize) break; - *s++ = *str++; - maxsize--; - width--; - } - return s; -} - -static char * -u_prnt(char *s, size_t maxsize, unsigned val, int width) -{ - int c; - - c = val % 10; - 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'; - return s; -} - -size_t -strftime(char *s, size_t maxsize, - const char *format, const struct tm *timeptr) -{ - size_t n; - char *firsts, *olds; - - if (!format) return 0; - - _tzset(); /* for %Z conversion */ - firsts = s; - while (maxsize && *format) { - while (maxsize && *format && *format != '%') { - *s++ = *format++; - maxsize--; - } - 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, - (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; - } - - } - if (maxsize) { - *s = '\0'; - return s - firsts; - } - return 0; /* The buffer is full */ -} 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... - */ diff --git a/plat/cpm/include/ack/config.h b/plat/cpm/include/ack/config.h deleted file mode 100644 index ebd5c1198..000000000 --- a/plat/cpm/include/ack/config.h +++ /dev/null @@ -1,19 +0,0 @@ -/* $Source$ - * $State$ - * $Revision$ - */ - -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H - -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -#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/pc86/include/ack/config.h b/plat/cpm/include/ack/plat.h similarity index 67% rename from plat/pc86/include/ack/config.h rename to plat/cpm/include/ack/plat.h index dac9af4c1..321dadf18 100644 --- a/plat/pc86/include/ack/config.h +++ b/plat/cpm/include/ack/plat.h @@ -3,12 +3,12 @@ * $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. */ -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/cpm/include/build.lua b/plat/cpm/include/build.lua index b6f713684..9820e3e09 100644 --- a/plat/cpm/include/build.lua +++ b/plat/cpm/include/build.lua @@ -8,9 +8,9 @@ local function addheader(h) packagemap["$(PLATIND)/cpm/include/"..h] = "./"..h end -addheader("ack/config.h") +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..6a0c3d3db --- /dev/null +++ b/plat/cpm/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/cpm/include/unistd.h b/plat/cpm/include/unistd.h deleted file mode 100644 index 99f1fb2d4..000000000 --- a/plat/cpm/include/unistd.h +++ /dev/null @@ -1,72 +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 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/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; diff --git a/plat/em/include/ack/plat.h b/plat/em/include/ack/plat.h new file mode 100644 index 000000000..8506e8781 --- /dev/null +++ b/plat/em/include/ack/plat.h @@ -0,0 +1,7 @@ +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_EMULATED_TIME 0 +#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/ack/config.h b/plat/em22/include/ack/config.h deleted file mode 100644 index 2618ad74c..000000000 --- a/plat/em22/include/ack/config.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H - -#define ACKCONF_TIME_IS_A_SYSCALL - -#endif diff --git a/plat/em22/include/build.lua b/plat/em22/include/build.lua index 298f9b033..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/config.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" } } - - diff --git a/plat/linux/include/ack/fcntl.h b/plat/linux/include/ack/fcntl.h new file mode 100644 index 000000000..361fad97a --- /dev/null +++ b/plat/linux/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 = 00000100, + O_TRUNC = 00001000, + O_APPEND = 00002000 +}; + +#endif diff --git a/plat/linux/include/ack/plat.h b/plat/linux/include/ack/plat.h new file mode 100644 index 000000000..f0ad12797 --- /dev/null +++ b/plat/linux/include/ack/plat.h @@ -0,0 +1,12 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_STANDARD_O 0 +#define ACKCONF_WANT_STANDARD_SIGNALS 0 + +#endif diff --git a/plat/linuxppc/include/unistd.h b/plat/linux/include/ack/signal.h similarity index 66% rename from plat/linuxppc/include/unistd.h rename to plat/linux/include/ack/signal.h index f57705365..55c0f3a04 100644 --- a/plat/linuxppc/include/unistd.h +++ b/plat/linux/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 = 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 */ +/* Signal constants. */ typedef int sig_atomic_t; @@ -140,12 +71,4 @@ struct sigaction { #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 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/linux/include/sys/types.h b/plat/linux/include/sys/types.h new file mode 100644 index 000000000..b706026ef --- /dev/null +++ b/plat/linux/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 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/config.h b/plat/linux386/include/ack/config.h deleted file mode 100644 index af4a90ed2..000000000 --- a/plat/linux386/include/ack/config.h +++ /dev/null @@ -1,14 +0,0 @@ -/* $Source$ - * $State$ - * $Revision$ - */ - -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_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/linux386/include/build.lua b/plat/linux386/include/build.lua index ce1f2adc6..c26cdf067 100644 --- a/plat/linux386/include/build.lua +++ b/plat/linux386/include/build.lua @@ -4,13 +4,15 @@ 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/config.h") +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/unistd.h b/plat/linux386/include/unistd.h deleted file mode 100644 index 8c8637c09..000000000 --- a/plat/linux386/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 = 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 */ - -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 diff --git a/plat/linux68k/include/ack/config.h b/plat/linux68k/include/ack/config.h deleted file mode 100644 index 77ac5528d..000000000 --- a/plat/linux68k/include/ack/config.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_CONFIG_H -#define _ACK_CONFIG_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 291fa0c36..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/config.h") +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 diff --git a/plat/linuxppc/include/ack/config.h b/plat/linuxppc/include/ack/config.h deleted file mode 100644 index 7c3c147b3..000000000 --- a/plat/linuxppc/include/ack/config.h +++ /dev/null @@ -1,18 +0,0 @@ -/* $Source: /cvsroot/tack/Ack/plat/linux386/include/ack/config.h,v $ - * $State: Exp $ - * $Revision: 1.1 $ - */ - -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_H - -/* We're providing a time() system call rather than wanting a wrapper around - * gettimeofday() in the libc. */ - -/* #define ACKCONF_TIME_IS_A_SYSCALL */ - -/* We don't support floating point right now. */ - -/* #define ACKCONF_NO_STDIO_FLOAT */ - -#endif diff --git a/plat/linuxppc/include/build.lua b/plat/linuxppc/include/build.lua index 27325b43d..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/config.h") +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/osx/include/ack/config.h b/plat/osx/include/ack/config.h deleted file mode 100644 index 9f58a3941..000000000 --- a/plat/osx/include/ack/config.h +++ /dev/null @@ -1,14 +0,0 @@ -/* $Source$ - * $State$ - * $Revision$ - */ - -#ifndef _ACK_CONFIG_H -#define _ACK_CONFIG_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/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 new file mode 100644 index 000000000..f0ad12797 --- /dev/null +++ b/plat/osx/include/ack/plat.h @@ -0,0 +1,12 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#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 ff7c87a4d..78ac3246f 100644 --- a/plat/osx/include/build.lua +++ b/plat/osx/include/build.lua @@ -8,12 +8,14 @@ local function addheader(h) packagemap["$(PLATIND)/osx/include/"..h] = "plat/osx/include/"..h end -addheader("ack/config.h") +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 diff --git a/plat/pc86/include/ack/plat.h b/plat/pc86/include/ack/plat.h new file mode 100644 index 000000000..e8c2251a0 --- /dev/null +++ b/plat/pc86/include/ack/plat.h @@ -0,0 +1,11 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_EMULATED_TIME 0 + +#endif diff --git a/plat/pc86/include/build.lua b/plat/pc86/include/build.lua index 6ae120358..3ae81836a 100644 --- a/plat/pc86/include/build.lua +++ b/plat/pc86/include/build.lua @@ -8,8 +8,8 @@ local function addheader(h) packagemap["$(PLATIND)/pc86/include/"..h] = "./"..h end -addheader("ack/config.h") -addheader("unistd.h") +addheader("ack/plat.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; 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/ack/config.h b/plat/pdpv7/include/ack/plat.h similarity index 55% rename from plat/pdpv7/include/ack/config.h rename to plat/pdpv7/include/ack/plat.h index 73dbbc34d..da2767148 100644 --- a/plat/pdpv7/include/ack/config.h +++ b/plat/pdpv7/include/ack/plat.h @@ -5,12 +5,9 @@ * 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. */ - -#define ACKCONF_TIME_IS_A_SYSCALL +#define ACKCONF_WANT_EMULATED_TIME 0 #endif diff --git a/plat/pdpv7/include/build.lua b/plat/pdpv7/include/build.lua index c0334a341..f785644b4 100644 --- a/plat/pdpv7/include/build.lua +++ b/plat/pdpv7/include/build.lua @@ -8,10 +8,10 @@ local function addheader(h) packagemap["$(PLATIND)/pdpv7/include/"..h] = "./"..h end -addheader("ack/config.h") +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< +#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;