Initial revision
This commit is contained in:
330
lib/ansi/Makefile
Executable file
330
lib/ansi/Makefile
Executable file
@@ -0,0 +1,330 @@
|
||||
# Makefile for lib/ansi.
|
||||
|
||||
# This Makefile compiles part of the C library, the functions required by the
|
||||
# ANSI C standard. This Makefile, and those in the other subdirectories use
|
||||
# a little known feature of make, the ability to refer to a file within a
|
||||
# library. The construct 'libc.a(abs.o)' names the file 'abs.o' contained
|
||||
# in 'libc.a'. So the rule
|
||||
#
|
||||
# libc.a(abs.o): abs.c
|
||||
# cc -c abs.c
|
||||
# aal cr libc.a abs.o
|
||||
# rm abs.o
|
||||
#
|
||||
# compiles abs.c and installs the result abs.o in libc.a if abs.c is newer
|
||||
# than the abs.o in the library. This Makefile does not work like this
|
||||
# precisely, it first compiles all changed source files and than installs
|
||||
# them all in one 'aal' command.
|
||||
|
||||
# Many of the string functions in this directory are not used, because the
|
||||
# have fast assembly implementations.
|
||||
|
||||
CFLAGS = -O -D_MINIX -D_POSIX_SOURCE
|
||||
CC1 = $(CC) $(CFLAGS) -c
|
||||
|
||||
LIBRARY = ../libc.a
|
||||
all: $(LIBRARY)
|
||||
|
||||
OBJECTS = \
|
||||
$(LIBRARY)(abort.o) \
|
||||
$(LIBRARY)(abs.o) \
|
||||
$(LIBRARY)(asctime.o) \
|
||||
$(LIBRARY)(assert.o) \
|
||||
$(LIBRARY)(atexit.o) \
|
||||
$(LIBRARY)(atof.o) \
|
||||
$(LIBRARY)(atoi.o) \
|
||||
$(LIBRARY)(atol.o) \
|
||||
$(LIBRARY)(bsearch.o) \
|
||||
$(LIBRARY)(calloc.o) \
|
||||
$(LIBRARY)(chartab.o) \
|
||||
$(LIBRARY)(clock.o) \
|
||||
$(LIBRARY)(ctime.o) \
|
||||
$(LIBRARY)(difftime.o) \
|
||||
$(LIBRARY)(div.o) \
|
||||
$(LIBRARY)(errlist.o) \
|
||||
$(LIBRARY)(exit.o) \
|
||||
$(LIBRARY)(ext_comp.o) \
|
||||
$(LIBRARY)(getenv.o) \
|
||||
$(LIBRARY)(gmtime.o) \
|
||||
$(LIBRARY)(isalnum.o) \
|
||||
$(LIBRARY)(isalpha.o) \
|
||||
$(LIBRARY)(isascii.o) \
|
||||
$(LIBRARY)(iscntrl.o) \
|
||||
$(LIBRARY)(isdigit.o) \
|
||||
$(LIBRARY)(isgraph.o) \
|
||||
$(LIBRARY)(islower.o) \
|
||||
$(LIBRARY)(isprint.o) \
|
||||
$(LIBRARY)(ispunct.o) \
|
||||
$(LIBRARY)(isspace.o) \
|
||||
$(LIBRARY)(isupper.o) \
|
||||
$(LIBRARY)(isxdigit.o) \
|
||||
$(LIBRARY)(labs.o) \
|
||||
$(LIBRARY)(ldiv.o) \
|
||||
$(LIBRARY)(localeconv.o) \
|
||||
$(LIBRARY)(localtime.o) \
|
||||
$(LIBRARY)(malloc.o) \
|
||||
$(LIBRARY)(mblen.o) \
|
||||
$(LIBRARY)(mbstowcs.o) \
|
||||
$(LIBRARY)(mbtowc.o) \
|
||||
$(LIBRARY)(misc.o) \
|
||||
$(LIBRARY)(mktime.o) \
|
||||
$(LIBRARY)(qsort.o) \
|
||||
$(LIBRARY)(raise.o) \
|
||||
$(LIBRARY)(rand.o) \
|
||||
$(LIBRARY)(setlocale.o) \
|
||||
$(LIBRARY)(sigmisc.o) \
|
||||
$(LIBRARY)(signal.o) \
|
||||
$(LIBRARY)(strcoll.o) \
|
||||
$(LIBRARY)(strcspn.o) \
|
||||
$(LIBRARY)(strerror.o) \
|
||||
$(LIBRARY)(strftime.o) \
|
||||
$(LIBRARY)(strpbrk.o) \
|
||||
$(LIBRARY)(strspn.o) \
|
||||
$(LIBRARY)(strstr.o) \
|
||||
$(LIBRARY)(strtok.o) \
|
||||
$(LIBRARY)(strtol.o) \
|
||||
$(LIBRARY)(strxfrm.o) \
|
||||
$(LIBRARY)(system.o) \
|
||||
$(LIBRARY)(tolower.o) \
|
||||
$(LIBRARY)(toupper.o) \
|
||||
$(LIBRARY)(tzset.o) \
|
||||
$(LIBRARY)(wcstombs.o) \
|
||||
$(LIBRARY)(wctomb.o) \
|
||||
|
||||
$(LIBRARY): $(OBJECTS)
|
||||
aal cr $@ *.o
|
||||
rm *.o
|
||||
|
||||
$(LIBRARY)(abort.o): abort.c
|
||||
$(CC1) abort.c
|
||||
|
||||
$(LIBRARY)(abs.o): abs.c
|
||||
$(CC1) abs.c
|
||||
|
||||
$(LIBRARY)(asctime.o): asctime.c
|
||||
$(CC1) asctime.c
|
||||
|
||||
$(LIBRARY)(assert.o): assert.c
|
||||
$(CC1) assert.c
|
||||
|
||||
$(LIBRARY)(atexit.o): atexit.c
|
||||
$(CC1) atexit.c
|
||||
|
||||
$(LIBRARY)(atof.o): atof.c
|
||||
$(CC1) atof.c
|
||||
|
||||
$(LIBRARY)(atoi.o): atoi.c
|
||||
$(CC1) atoi.c
|
||||
|
||||
$(LIBRARY)(atol.o): atol.c
|
||||
$(CC1) atol.c
|
||||
|
||||
$(LIBRARY)(bsearch.o): bsearch.c
|
||||
$(CC1) bsearch.c
|
||||
|
||||
$(LIBRARY)(calloc.o): calloc.c
|
||||
$(CC1) calloc.c
|
||||
|
||||
$(LIBRARY)(chartab.o): chartab.c
|
||||
$(CC1) chartab.c
|
||||
|
||||
$(LIBRARY)(clock.o): clock.c
|
||||
$(CC1) clock.c
|
||||
|
||||
$(LIBRARY)(ctime.o): ctime.c
|
||||
$(CC1) ctime.c
|
||||
|
||||
$(LIBRARY)(difftime.o): difftime.c
|
||||
$(CC1) difftime.c
|
||||
|
||||
$(LIBRARY)(div.o): div.c
|
||||
$(CC1) div.c
|
||||
|
||||
$(LIBRARY)(errlist.o): errlist.c
|
||||
$(CC1) errlist.c
|
||||
|
||||
$(LIBRARY)(exit.o): exit.c
|
||||
$(CC1) exit.c
|
||||
|
||||
$(LIBRARY)(ext_comp.o): ext_comp.c
|
||||
$(CC1) ext_comp.c
|
||||
|
||||
$(LIBRARY)(getenv.o): getenv.c
|
||||
$(CC1) getenv.c
|
||||
|
||||
$(LIBRARY)(gmtime.o): gmtime.c
|
||||
$(CC1) gmtime.c
|
||||
|
||||
$(LIBRARY)(isalnum.o): isalnum.c
|
||||
$(CC1) isalnum.c
|
||||
|
||||
$(LIBRARY)(isalpha.o): isalpha.c
|
||||
$(CC1) isalpha.c
|
||||
|
||||
$(LIBRARY)(isascii.o): isascii.c
|
||||
$(CC1) isascii.c
|
||||
|
||||
$(LIBRARY)(iscntrl.o): iscntrl.c
|
||||
$(CC1) iscntrl.c
|
||||
|
||||
$(LIBRARY)(isdigit.o): isdigit.c
|
||||
$(CC1) isdigit.c
|
||||
|
||||
$(LIBRARY)(isgraph.o): isgraph.c
|
||||
$(CC1) isgraph.c
|
||||
|
||||
$(LIBRARY)(islower.o): islower.c
|
||||
$(CC1) islower.c
|
||||
|
||||
$(LIBRARY)(isprint.o): isprint.c
|
||||
$(CC1) isprint.c
|
||||
|
||||
$(LIBRARY)(ispunct.o): ispunct.c
|
||||
$(CC1) ispunct.c
|
||||
|
||||
$(LIBRARY)(isspace.o): isspace.c
|
||||
$(CC1) isspace.c
|
||||
|
||||
$(LIBRARY)(isupper.o): isupper.c
|
||||
$(CC1) isupper.c
|
||||
|
||||
$(LIBRARY)(isxdigit.o): isxdigit.c
|
||||
$(CC1) isxdigit.c
|
||||
|
||||
$(LIBRARY)(labs.o): labs.c
|
||||
$(CC1) labs.c
|
||||
|
||||
$(LIBRARY)(ldiv.o): ldiv.c
|
||||
$(CC1) ldiv.c
|
||||
|
||||
$(LIBRARY)(localeconv.o): localeconv.c
|
||||
$(CC1) localeconv.c
|
||||
|
||||
$(LIBRARY)(localtime.o): localtime.c
|
||||
$(CC1) localtime.c
|
||||
|
||||
$(LIBRARY)(malloc.o): malloc.c
|
||||
$(CC1) malloc.c
|
||||
|
||||
$(LIBRARY)(mblen.o): mblen.c
|
||||
$(CC1) mblen.c
|
||||
|
||||
$(LIBRARY)(mbstowcs.o): mbstowcs.c
|
||||
$(CC1) mbstowcs.c
|
||||
|
||||
$(LIBRARY)(mbtowc.o): mbtowc.c
|
||||
$(CC1) mbtowc.c
|
||||
|
||||
$(LIBRARY)(memchr.o): memchr.c
|
||||
$(CC1) memchr.c
|
||||
|
||||
$(LIBRARY)(memcmp.o): memcmp.c
|
||||
$(CC1) memcmp.c
|
||||
|
||||
$(LIBRARY)(memcpy.o): memcpy.c
|
||||
$(CC1) memcpy.c
|
||||
|
||||
$(LIBRARY)(memmove.o): memmove.c
|
||||
$(CC1) memmove.c
|
||||
|
||||
$(LIBRARY)(memset.o): memset.c
|
||||
$(CC1) memset.c
|
||||
|
||||
$(LIBRARY)(misc.o): misc.c
|
||||
$(CC1) misc.c
|
||||
|
||||
$(LIBRARY)(mktime.o): mktime.c
|
||||
$(CC1) mktime.c
|
||||
|
||||
$(LIBRARY)(qsort.o): qsort.c
|
||||
$(CC1) qsort.c
|
||||
|
||||
$(LIBRARY)(raise.o): raise.c
|
||||
$(CC1) raise.c
|
||||
|
||||
$(LIBRARY)(rand.o): rand.c
|
||||
$(CC1) rand.c
|
||||
|
||||
$(LIBRARY)(setlocale.o): setlocale.c
|
||||
$(CC1) setlocale.c
|
||||
|
||||
$(LIBRARY)(sigmisc.o): sigmisc.c
|
||||
$(CC1) sigmisc.c
|
||||
|
||||
$(LIBRARY)(signal.o): signal.c
|
||||
$(CC1) signal.c
|
||||
|
||||
$(LIBRARY)(strcat.o): strcat.c
|
||||
$(CC1) strcat.c
|
||||
|
||||
$(LIBRARY)(strchr.o): strchr.c
|
||||
$(CC1) strchr.c
|
||||
|
||||
$(LIBRARY)(strcmp.o): strcmp.c
|
||||
$(CC1) strcmp.c
|
||||
|
||||
$(LIBRARY)(strcoll.o): strcoll.c
|
||||
$(CC1) strcoll.c
|
||||
|
||||
$(LIBRARY)(strcpy.o): strcpy.c
|
||||
$(CC1) strcpy.c
|
||||
|
||||
$(LIBRARY)(strcspn.o): strcspn.c
|
||||
$(CC1) strcspn.c
|
||||
|
||||
$(LIBRARY)(strerror.o): strerror.c
|
||||
$(CC1) strerror.c
|
||||
|
||||
$(LIBRARY)(strftime.o): strftime.c
|
||||
$(CC1) strftime.c
|
||||
|
||||
$(LIBRARY)(strlen.o): strlen.c
|
||||
$(CC1) strlen.c
|
||||
|
||||
$(LIBRARY)(strncat.o): strncat.c
|
||||
$(CC1) strncat.c
|
||||
|
||||
$(LIBRARY)(strncmp.o): strncmp.c
|
||||
$(CC1) strncmp.c
|
||||
|
||||
$(LIBRARY)(strncpy.o): strncpy.c
|
||||
$(CC1) strncpy.c
|
||||
|
||||
$(LIBRARY)(strpbrk.o): strpbrk.c
|
||||
$(CC1) strpbrk.c
|
||||
|
||||
$(LIBRARY)(strrchr.o): strrchr.c
|
||||
$(CC1) strrchr.c
|
||||
|
||||
$(LIBRARY)(strspn.o): strspn.c
|
||||
$(CC1) strspn.c
|
||||
|
||||
$(LIBRARY)(strstr.o): strstr.c
|
||||
$(CC1) strstr.c
|
||||
|
||||
$(LIBRARY)(strtok.o): strtok.c
|
||||
$(CC1) strtok.c
|
||||
|
||||
$(LIBRARY)(strtol.o): strtol.c
|
||||
$(CC1) strtol.c
|
||||
|
||||
$(LIBRARY)(strxfrm.o): strxfrm.c
|
||||
$(CC1) strxfrm.c
|
||||
|
||||
$(LIBRARY)(system.o): system.c
|
||||
$(CC1) system.c
|
||||
|
||||
$(LIBRARY)(tolower.o): tolower.c
|
||||
$(CC1) tolower.c
|
||||
|
||||
$(LIBRARY)(toupper.o): toupper.c
|
||||
$(CC1) toupper.c
|
||||
|
||||
$(LIBRARY)(tzset.o): tzset.c
|
||||
$(CC1) tzset.c
|
||||
|
||||
$(LIBRARY)(wcstombs.o): wcstombs.c
|
||||
$(CC1) wcstombs.c
|
||||
|
||||
$(LIBRARY)(wctomb.o): wctomb.c
|
||||
$(CC1) wctomb.c
|
||||
21
lib/ansi/abort.c
Executable file
21
lib/ansi/abort.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#if defined(_POSIX_SOURCE)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void (*_clean)(void);
|
||||
|
||||
void
|
||||
abort(void)
|
||||
{
|
||||
if (_clean) _clean(); /* flush all output files */
|
||||
raise(SIGABRT);
|
||||
}
|
||||
|
||||
13
lib/ansi/abs.c
Executable file
13
lib/ansi/abs.c
Executable file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
abs(register int i)
|
||||
{
|
||||
return i >= 0 ? i : -i;
|
||||
}
|
||||
60
lib/ansi/asctime.c
Executable file
60
lib/ansi/asctime.c
Executable file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* asctime - print a date
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#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;
|
||||
}
|
||||
14
lib/ansi/assert.c
Executable file
14
lib/ansi/assert.c
Executable file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* assert.c - diagnostics
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void __bad_assertion(const char *mess) {
|
||||
|
||||
fputs(mess, stderr);
|
||||
abort();
|
||||
}
|
||||
17
lib/ansi/atexit.c
Executable file
17
lib/ansi/atexit.c
Executable file
@@ -0,0 +1,17 @@
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
19
lib/ansi/atof.c
Executable file
19
lib/ansi/atof.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
double
|
||||
atof(const char *nptr)
|
||||
{
|
||||
double d;
|
||||
int e = errno;
|
||||
|
||||
d = strtod(nptr, (char **) NULL);
|
||||
errno = e;
|
||||
return d;
|
||||
}
|
||||
14
lib/ansi/atoi.c
Executable file
14
lib/ansi/atoi.c
Executable file
@@ -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".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
atoi(register const char *nptr)
|
||||
{
|
||||
return strtol(nptr, (char **) NULL, 10);
|
||||
}
|
||||
30
lib/ansi/atol.c
Executable file
30
lib/ansi/atol.c
Executable file
@@ -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".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* We do not use strtol here for backwards compatibility in behaviour on
|
||||
overflow.
|
||||
*/
|
||||
long
|
||||
atol(register const char *nptr)
|
||||
{
|
||||
long total = 0;
|
||||
int minus = 0;
|
||||
|
||||
while (isspace(*nptr)) nptr++;
|
||||
if (*nptr == '+') nptr++;
|
||||
else if (*nptr == '-') {
|
||||
minus = 1;
|
||||
nptr++;
|
||||
}
|
||||
while (isdigit(*nptr)) {
|
||||
total *= 10;
|
||||
total += (*nptr++ - '0');
|
||||
}
|
||||
return minus ? -total : total;
|
||||
}
|
||||
28
lib/ansi/bsearch.c
Executable file
28
lib/ansi/bsearch.c
Executable file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
19
lib/ansi/calloc.c
Executable file
19
lib/ansi/calloc.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/* $Header$ */
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1))
|
||||
|
||||
void *
|
||||
calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
register char *p;
|
||||
register size_t *q;
|
||||
size_t size = ALIGN(nelem * elsize);
|
||||
|
||||
p = malloc(size);
|
||||
if (p == NULL) return NULL;
|
||||
q = (size_t *) (p + size);
|
||||
while ((char *) q > p) *--q = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
261
lib/ansi/chartab.c
Executable file
261
lib/ansi/chartab.c
Executable file
@@ -0,0 +1,261 @@
|
||||
#include <ctype.h>
|
||||
|
||||
char __ctype[] = {
|
||||
0,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C|_S,
|
||||
_C|_S,
|
||||
_C|_S,
|
||||
_C|_S,
|
||||
_C|_S,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_C,
|
||||
_S,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_N,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_U|_X,
|
||||
_U|_X,
|
||||
_U|_X,
|
||||
_U|_X,
|
||||
_U|_X,
|
||||
_U|_X,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_U,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_L|_X,
|
||||
_L|_X,
|
||||
_L|_X,
|
||||
_L|_X,
|
||||
_L|_X,
|
||||
_L|_X,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_L,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_P,
|
||||
_C,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
15
lib/ansi/clock.c
Executable file
15
lib/ansi/clock.c
Executable file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* clock - determine the processor time used
|
||||
*/
|
||||
|
||||
#define times _times
|
||||
#include <time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
clock_t clock(void)
|
||||
{
|
||||
struct tms tms;
|
||||
|
||||
times(&tms);
|
||||
return tms.tms_utime;
|
||||
}
|
||||
12
lib/ansi/ctime.c
Executable file
12
lib/ansi/ctime.c
Executable file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* ctime - convers the calendar time to a string
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
char *
|
||||
ctime(const time_t *timer)
|
||||
{
|
||||
return asctime(localtime(timer));
|
||||
}
|
||||
17
lib/ansi/difftime.c
Executable file
17
lib/ansi/difftime.c
Executable file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* difftime - compute the difference between two calendar times
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
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 {
|
||||
return (double)(time1 - time0);
|
||||
}
|
||||
}
|
||||
31
lib/ansi/div.c
Executable file
31
lib/ansi/div.c
Executable file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static int tmp = -1;
|
||||
|
||||
div_t
|
||||
div(register int numer, register int denom)
|
||||
{
|
||||
div_t r;
|
||||
|
||||
/* The assignment of tmp should not be optimized !! */
|
||||
if (tmp == -1) {
|
||||
tmp = (tmp / 2 == 0);
|
||||
}
|
||||
if (numer == 0) {
|
||||
r.quot = numer / denom; /* might trap if denom == 0 */
|
||||
r.rem = numer % denom;
|
||||
} else if ( !tmp && ((numer < 0) != (denom < 0))) {
|
||||
r.quot = (numer / denom) + 1;
|
||||
r.rem = numer - (numer / denom + 1) * denom;
|
||||
} else {
|
||||
r.quot = numer / denom;
|
||||
r.rem = numer % denom;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
83
lib/ansi/errlist.c
Executable file
83
lib/ansi/errlist.c
Executable file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
static const char unknown[] = "Unknown error";
|
||||
|
||||
const char *_sys_errlist[] = {
|
||||
"Error 0", /* EGENERIC */
|
||||
"Not owner", /* EPERM */
|
||||
"No such file or directory", /* ENOENT */
|
||||
"No such process", /* ESRCH */
|
||||
"Interrupted system call", /* EINTR */
|
||||
"I/O error", /* EIO */
|
||||
"No such device or address", /* ENXIO */
|
||||
"Arg list too long", /* E2BIG */
|
||||
"Exec format error", /* ENOEXEC */
|
||||
"Bad file number", /* EBADF */
|
||||
"No children", /* ECHILD */
|
||||
"Resource temporarily unavailable",/* EAGAIN */
|
||||
"Not enough core", /* ENOMEM */
|
||||
"Permission denied", /* EACCES */
|
||||
"Bad address", /* EFAULT */
|
||||
"Block device required", /* ENOTBLK */
|
||||
"Resource busy", /* EBUSY */
|
||||
"File exists", /* EEXIST */
|
||||
"Cross-device link", /* EXDEV */
|
||||
"No such device", /* ENODEV */
|
||||
"Not a directory", /* ENOTDIR */
|
||||
"Is a directory", /* EISDIR */
|
||||
"Invalid argument", /* EINVAL */
|
||||
"File table overflow", /* ENFILE */
|
||||
"Too many open files", /* EMFILE */
|
||||
"Not a typewriter", /* ENOTTY */
|
||||
"Text file busy", /* ETXTBSY */
|
||||
"File too large", /* EFBIG */
|
||||
"No space left on device", /* ENOSPC */
|
||||
"Illegal seek", /* ESPIPE */
|
||||
"Read-only file system", /* EROFS */
|
||||
"Too many links", /* EMLINK */
|
||||
"Broken pipe", /* EPIPE */
|
||||
"Math argument", /* EDOM */
|
||||
"Result too large", /* ERANGE */
|
||||
"Resource deadlock avoided", /* EDEADLK */
|
||||
"File name too long", /* ENAMETOOLONG */
|
||||
"No locks available", /* ENOLCK */
|
||||
"Function not implemented", /* ENOSYS */
|
||||
"Directory not empty", /* ENOTEMPTY */
|
||||
unknown, /* 40 */
|
||||
unknown, /* 41 */
|
||||
unknown, /* 42 */
|
||||
unknown, /* 43 */
|
||||
unknown, /* 44 */
|
||||
unknown, /* 45 */
|
||||
unknown, /* 46 */
|
||||
unknown, /* 47 */
|
||||
unknown, /* 48 */
|
||||
unknown, /* 49 */
|
||||
"Invalid packet size", /* EPACKSIZE */
|
||||
"Not enough buffers left", /* EOUTOFBUFS */
|
||||
"Illegal ioctl for device", /* EBADIOCTL */
|
||||
"Bad mode for ioctl", /* EBADMODE */
|
||||
"Would block", /* EWOULDBLOCK */
|
||||
"Bad destination address", /* EBADDEST */
|
||||
"Destination not reachable", /* EDSTNOTRCH */
|
||||
"Already connected", /* EISCONN */
|
||||
"Address in use", /* EADDRINUSE */
|
||||
"Connection refused", /* ECONNREFUSED */
|
||||
"Connection reset", /* ECONNRESET */
|
||||
"Connection timed out", /* ETIMEDOUT */
|
||||
"Urgent data present", /* EURG */
|
||||
"No urgent data present", /* ENOURG */
|
||||
"No connection", /* ENOTCONN */
|
||||
"Already shutdown", /* ESHUTDOWN */
|
||||
"No such connection", /* ENOCONN */
|
||||
"Address family not supported", /* EAFNOSUPPORT */
|
||||
"Protocol not supported by AF", /* EPROTONOSUPPORT */
|
||||
};
|
||||
|
||||
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
|
||||
36
lib/ansi/exit.c
Executable file
36
lib/ansi/exit.c
Executable file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NEXITS 32
|
||||
|
||||
void (*__functab[NEXITS])(void);
|
||||
int __funccnt = 0;
|
||||
|
||||
extern void _exit(int);
|
||||
|
||||
/* only flush output buffers when necessary */
|
||||
int (*_clean)(void) = NULL;
|
||||
|
||||
static void
|
||||
_calls(void)
|
||||
{
|
||||
register int i = __funccnt;
|
||||
|
||||
/* "Called in reversed order of their registration" */
|
||||
while (--i >= 0)
|
||||
(*__functab[i])();
|
||||
}
|
||||
|
||||
void
|
||||
exit(int status)
|
||||
{
|
||||
_calls();
|
||||
if (_clean) _clean();
|
||||
_exit(status) ;
|
||||
}
|
||||
743
lib/ansi/ext_comp.c
Executable file
743
lib/ansi/ext_comp.c
Executable file
@@ -0,0 +1,743 @@
|
||||
/*
|
||||
(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 <float.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
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(a<x) {
|
||||
b=a;n+=n;a*=a
|
||||
}
|
||||
n/=2
|
||||
a=b
|
||||
while(b<x) {
|
||||
a=b;b*=c;n+=32
|
||||
}
|
||||
n-=32
|
||||
b=a
|
||||
while(a<x) {
|
||||
b=a;a+=a;n+=1
|
||||
}
|
||||
n-=1
|
||||
x*=16^16
|
||||
b=x%a
|
||||
x/=a
|
||||
if(a<=(2*b)) x+=1
|
||||
obase=10
|
||||
n
|
||||
obase=16
|
||||
return(x)
|
||||
}
|
||||
for (i=1;i<28;i++) {
|
||||
t(10^i)
|
||||
}
|
||||
0
|
||||
for (i=1;i<20;i++) {
|
||||
t(10^(28*i))
|
||||
}
|
||||
0
|
||||
define r(x){
|
||||
auto a, b, c
|
||||
a=2;b=1;c=2^32;n=1
|
||||
while(a<x) {
|
||||
b=a;n+=n;a*=a
|
||||
}
|
||||
n/=2
|
||||
a=b
|
||||
while(b<x) {
|
||||
a=b;b*=c;n+=32
|
||||
}
|
||||
n-=32
|
||||
b=a
|
||||
while(a<x) {
|
||||
b=a;a+=a;n+=1
|
||||
}
|
||||
a=b
|
||||
a*=16^16
|
||||
b=a%x
|
||||
a/=x
|
||||
if(x<=(2*b)) a+=1
|
||||
obase=10
|
||||
-n
|
||||
obase=16
|
||||
return(a)
|
||||
}
|
||||
for (i=1;i<28;i++) {
|
||||
r(10^i)
|
||||
}
|
||||
0
|
||||
for (i=1;i<20;i++) {
|
||||
r(10^(28*i))
|
||||
}
|
||||
0
|
||||
|
||||
*/
|
||||
static struct EXTEND ten_powers[] = { /* representation of 10 ** i */
|
||||
{ 0, 0, 0x80000000, 0 },
|
||||
{ 0, 3, 0xA0000000, 0 },
|
||||
{ 0, 6, 0xC8000000, 0 },
|
||||
{ 0, 9, 0xFA000000, 0 },
|
||||
{ 0, 13, 0x9C400000, 0 },
|
||||
{ 0, 16, 0xC3500000, 0 },
|
||||
{ 0, 19, 0xF4240000, 0 },
|
||||
{ 0, 23, 0x98968000, 0 },
|
||||
{ 0, 26, 0xBEBC2000, 0 },
|
||||
{ 0, 29, 0xEE6B2800, 0 },
|
||||
{ 0, 33, 0x9502F900, 0 },
|
||||
{ 0, 36, 0xBA43B740, 0 },
|
||||
{ 0, 39, 0xE8D4A510, 0 },
|
||||
{ 0, 43, 0x9184E72A, 0 },
|
||||
{ 0, 46, 0xB5E620F4, 0x80000000 },
|
||||
{ 0, 49, 0xE35FA931, 0xA0000000 },
|
||||
{ 0, 53, 0x8E1BC9BF, 0x04000000 },
|
||||
{ 0, 56, 0xB1A2BC2E, 0xC5000000 },
|
||||
{ 0, 59, 0xDE0B6B3A, 0x76400000 },
|
||||
{ 0, 63, 0x8AC72304, 0x89E80000 },
|
||||
{ 0, 66, 0xAD78EBC5, 0xAC620000 },
|
||||
{ 0, 69, 0xD8D726B7, 0x177A8000 },
|
||||
{ 0, 73, 0x87867832, 0x6EAC9000 },
|
||||
{ 0, 76, 0xA968163F, 0x0A57B400 },
|
||||
{ 0, 79, 0xD3C21BCE, 0xCCEDA100 },
|
||||
{ 0, 83, 0x84595161, 0x401484A0 },
|
||||
{ 0, 86, 0xA56FA5B9, 0x9019A5C8 },
|
||||
{ 0, 89, 0xCECB8F27, 0xF4200F3A }
|
||||
};
|
||||
static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */
|
||||
{ 0, 0, 0x80000000, 0 },
|
||||
{ 0, 93, 0x813F3978, 0xF8940984 },
|
||||
{ 0, 186, 0x82818F12, 0x81ED44A0 },
|
||||
{ 0, 279, 0x83C7088E, 0x1AAB65DB },
|
||||
{ 0, 372, 0x850FADC0, 0x9923329E },
|
||||
{ 0, 465, 0x865B8692, 0x5B9BC5C2 },
|
||||
{ 0, 558, 0x87AA9AFF, 0x79042287 },
|
||||
{ 0, 651, 0x88FCF317, 0xF22241E2 },
|
||||
{ 0, 744, 0x8A5296FF, 0xE33CC930 },
|
||||
{ 0, 837, 0x8BAB8EEF, 0xB6409C1A },
|
||||
{ 0, 930, 0x8D07E334, 0x55637EB3 },
|
||||
{ 0, 1023, 0x8E679C2F, 0x5E44FF8F },
|
||||
{ 0, 1116, 0x8FCAC257, 0x558EE4E6 },
|
||||
{ 0, 1209, 0x91315E37, 0xDB165AA9 },
|
||||
{ 0, 1302, 0x929B7871, 0xDE7F22B9 },
|
||||
{ 0, 1395, 0x940919BB, 0xD4620B6D },
|
||||
{ 0, 1488, 0x957A4AE1, 0xEBF7F3D4 },
|
||||
{ 0, 1581, 0x96EF14C6, 0x454AA840 },
|
||||
{ 0, 1674, 0x98678061, 0x27ECE4F5 },
|
||||
{ 0, 1767, 0x99E396C1, 0x3A3ACFF2 }
|
||||
};
|
||||
|
||||
static struct EXTEND r_ten_powers[] = { /* representation of 10 ** -i */
|
||||
{ 0, 0, 0x80000000, 0 },
|
||||
{ 0, -4, 0xCCCCCCCC, 0xCCCCCCCD },
|
||||
{ 0, -7, 0xA3D70A3D, 0x70A3D70A },
|
||||
{ 0, -10, 0x83126E97, 0x8D4FDF3B },
|
||||
{ 0, -14, 0xD1B71758, 0xE219652C },
|
||||
{ 0, -17, 0xA7C5AC47, 0x1B478423 },
|
||||
{ 0, -20, 0x8637BD05, 0xAF6C69B6 },
|
||||
{ 0, -24, 0xD6BF94D5, 0xE57A42BC },
|
||||
{ 0, -27, 0xABCC7711, 0x8461CEFD },
|
||||
{ 0, -30, 0x89705F41, 0x36B4A597 },
|
||||
{ 0, -34, 0xDBE6FECE, 0xBDEDD5BF },
|
||||
{ 0, -37, 0xAFEBFF0B, 0xCB24AAFF },
|
||||
{ 0, -40, 0x8CBCCC09, 0x6F5088CC },
|
||||
{ 0, -44, 0xE12E1342, 0x4BB40E13 },
|
||||
{ 0, -47, 0xB424DC35, 0x095CD80F },
|
||||
{ 0, -50, 0x901D7CF7, 0x3AB0ACD9 },
|
||||
{ 0, -54, 0xE69594BE, 0xC44DE15B },
|
||||
{ 0, -57, 0xB877AA32, 0x36A4B449 },
|
||||
{ 0, -60, 0x9392EE8E, 0x921D5D07 },
|
||||
{ 0, -64, 0xEC1E4A7D, 0xB69561A5 },
|
||||
{ 0, -67, 0xBCE50864, 0x92111AEB },
|
||||
{ 0, -70, 0x971DA050, 0x74DA7BEF },
|
||||
{ 0, -74, 0xF1C90080, 0xBAF72CB1 },
|
||||
{ 0, -77, 0xC16D9A00, 0x95928A27 },
|
||||
{ 0, -80, 0x9ABE14CD, 0x44753B53 },
|
||||
{ 0, -84, 0xF79687AE, 0xD3EEC551 },
|
||||
{ 0, -87, 0xC6120625, 0x76589DDB },
|
||||
{ 0, -90, 0x9E74D1B7, 0x91E07E48 }
|
||||
};
|
||||
|
||||
static struct EXTEND r_big_ten_powers[] = { /* representation of 10 ** -(28*i) */
|
||||
{ 0, 0, 0x80000000, 0 },
|
||||
{ 0, -94, 0xFD87B5F2, 0x8300CA0E },
|
||||
{ 0, -187, 0xFB158592, 0xBE068D2F },
|
||||
{ 0, -280, 0xF8A95FCF, 0x88747D94 },
|
||||
{ 0, -373, 0xF64335BC, 0xF065D37D },
|
||||
{ 0, -466, 0xF3E2F893, 0xDEC3F126 },
|
||||
{ 0, -559, 0xF18899B1, 0xBC3F8CA2 },
|
||||
{ 0, -652, 0xEF340A98, 0x172AACE5 },
|
||||
{ 0, -745, 0xECE53CEC, 0x4A314EBE },
|
||||
{ 0, -838, 0xEA9C2277, 0x23EE8BCB },
|
||||
{ 0, -931, 0xE858AD24, 0x8F5C22CA },
|
||||
{ 0, -1024, 0xE61ACF03, 0x3D1A45DF },
|
||||
{ 0, -1117, 0xE3E27A44, 0x4D8D98B8 },
|
||||
{ 0, -1210, 0xE1AFA13A, 0xFBD14D6E },
|
||||
{ 0, -1303, 0xDF82365C, 0x497B5454 },
|
||||
{ 0, -1396, 0xDD5A2C3E, 0xAB3097CC },
|
||||
{ 0, -1489, 0xDB377599, 0xB6074245 },
|
||||
{ 0, -1582, 0xD91A0545, 0xCDB51186 },
|
||||
{ 0, -1675, 0xD701CE3B, 0xD387BF48 },
|
||||
{ 0, -1768, 0xD4EEC394, 0xD6258BF8 }
|
||||
};
|
||||
|
||||
#define TP (int)(sizeof(ten_powers)/sizeof(ten_powers[0]))
|
||||
#define BTP (int)(sizeof(big_ten_powers)/sizeof(big_ten_powers[0]))
|
||||
#define MAX_EXP (TP * BTP - 1)
|
||||
|
||||
static
|
||||
add_exponent(struct EXTEND *e, int exp)
|
||||
{
|
||||
int neg = exp < 0;
|
||||
int divsz, modsz;
|
||||
struct EXTEND x;
|
||||
|
||||
if (neg) exp = -exp;
|
||||
divsz = exp / TP;
|
||||
modsz = exp % TP;
|
||||
if (neg) {
|
||||
mul_ext(e, &r_ten_powers[modsz], &x);
|
||||
mul_ext(&x, &r_big_ten_powers[divsz], e);
|
||||
}
|
||||
else {
|
||||
mul_ext(e, &ten_powers[modsz], &x);
|
||||
mul_ext(&x, &big_ten_powers[divsz], e);
|
||||
}
|
||||
}
|
||||
|
||||
_str_ext_cvt(const char *s, char **ss, struct EXTEND *e)
|
||||
{
|
||||
/* Like strtod, but for extended precision */
|
||||
register int c;
|
||||
int dotseen = 0;
|
||||
int digitseen = 0;
|
||||
int exp = 0;
|
||||
|
||||
if (ss) *ss = (char *)s;
|
||||
while (isspace(*s)) s++;
|
||||
|
||||
e->sign = 0;
|
||||
e->exp = 0;
|
||||
e->m1 = e->m2 = 0;
|
||||
|
||||
c = *s;
|
||||
switch(c) {
|
||||
case '-':
|
||||
e->sign = 1;
|
||||
case '+':
|
||||
s++;
|
||||
}
|
||||
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 <math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
13
lib/ansi/ext_fmt.h
Executable file
13
lib/ansi/ext_fmt.h
Executable file
@@ -0,0 +1,13 @@
|
||||
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
|
||||
};
|
||||
|
||||
28
lib/ansi/getenv.c
Executable file
28
lib/ansi/getenv.c
Executable file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern const char ***_penviron;
|
||||
|
||||
char *
|
||||
getenv(const char *name)
|
||||
{
|
||||
register const char **v = *_penviron;
|
||||
register const char *p, *q;
|
||||
|
||||
if (v == NULL || name == NULL)
|
||||
return (char *)NULL;
|
||||
while ((p = *v++) != NULL) {
|
||||
q = name;
|
||||
while (*q && (*q == *p++))
|
||||
q++;
|
||||
if (*q || (*p != '='))
|
||||
continue;
|
||||
return (char *)p + 1;
|
||||
}
|
||||
return (char *)NULL;
|
||||
}
|
||||
41
lib/ansi/gmtime.c
Executable file
41
lib/ansi/gmtime.c
Executable file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* gmtime - convert the calendar time into broken down time
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "loc_time.h"
|
||||
|
||||
struct tm *
|
||||
gmtime(register const time_t *timer)
|
||||
{
|
||||
static struct tm br_time;
|
||||
register struct tm *timep = &br_time;
|
||||
time_t time = *timer;
|
||||
register unsigned long dayclock, dayno;
|
||||
int year = EPOCH_YR;
|
||||
|
||||
dayclock = (unsigned long)time % SECS_DAY;
|
||||
dayno = (unsigned long)time / SECS_DAY;
|
||||
|
||||
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)) {
|
||||
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]) {
|
||||
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
|
||||
timep->tm_mon++;
|
||||
}
|
||||
timep->tm_mday = dayno + 1;
|
||||
timep->tm_isdst = 0;
|
||||
|
||||
return timep;
|
||||
}
|
||||
5
lib/ansi/isalnum.c
Executable file
5
lib/ansi/isalnum.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isalnum)(int c) {
|
||||
return isalnum(c);
|
||||
}
|
||||
5
lib/ansi/isalpha.c
Executable file
5
lib/ansi/isalpha.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isalpha)(int c) {
|
||||
return isalpha(c);
|
||||
}
|
||||
5
lib/ansi/isascii.c
Executable file
5
lib/ansi/isascii.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isascii)(int c) {
|
||||
return isascii(c);
|
||||
}
|
||||
5
lib/ansi/iscntrl.c
Executable file
5
lib/ansi/iscntrl.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (iscntrl)(int c) {
|
||||
return iscntrl(c);
|
||||
}
|
||||
5
lib/ansi/isdigit.c
Executable file
5
lib/ansi/isdigit.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isdigit)(int c) {
|
||||
return isdigit(c);
|
||||
}
|
||||
5
lib/ansi/isgraph.c
Executable file
5
lib/ansi/isgraph.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isgraph)(int c) {
|
||||
return isgraph(c);
|
||||
}
|
||||
5
lib/ansi/islower.c
Executable file
5
lib/ansi/islower.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (islower)(int c) {
|
||||
return islower(c);
|
||||
}
|
||||
5
lib/ansi/isprint.c
Executable file
5
lib/ansi/isprint.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isprint)(int c) {
|
||||
return isprint(c);
|
||||
}
|
||||
5
lib/ansi/ispunct.c
Executable file
5
lib/ansi/ispunct.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (ispunct)(int c) {
|
||||
return ispunct(c);
|
||||
}
|
||||
5
lib/ansi/isspace.c
Executable file
5
lib/ansi/isspace.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isspace)(int c) {
|
||||
return isspace(c);
|
||||
}
|
||||
5
lib/ansi/isupper.c
Executable file
5
lib/ansi/isupper.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isupper)(int c) {
|
||||
return isupper(c);
|
||||
}
|
||||
5
lib/ansi/isxdigit.c
Executable file
5
lib/ansi/isxdigit.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isxdigit)(int c) {
|
||||
return isxdigit(c);
|
||||
}
|
||||
13
lib/ansi/labs.c
Executable file
13
lib/ansi/labs.c
Executable file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
long
|
||||
labs(register long l)
|
||||
{
|
||||
return l >= 0 ? l : -l;
|
||||
}
|
||||
31
lib/ansi/ldiv.c
Executable file
31
lib/ansi/ldiv.c
Executable file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static long tmp = -1;
|
||||
|
||||
ldiv_t
|
||||
ldiv(register long numer, register long denom)
|
||||
{
|
||||
ldiv_t r;
|
||||
|
||||
/* The assignment of tmp should not be optimized !! */
|
||||
if (tmp == -1) {
|
||||
tmp = (tmp / 2 == 0);
|
||||
}
|
||||
if (numer == 0) {
|
||||
r.quot = numer / denom; /* might trap if denom == 0 */
|
||||
r.rem = numer % denom;
|
||||
} else if ( !tmp && ((numer < 0) != (denom < 0))) {
|
||||
r.quot = (numer / denom) + 1;
|
||||
r.rem = numer - (numer / denom + 1) * denom;
|
||||
} else {
|
||||
r.quot = numer / denom;
|
||||
r.rem = numer % denom;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
26
lib/ansi/loc_time.h
Executable file
26
lib/ansi/loc_time.h
Executable file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* loc_time.h - some local definitions
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#define YEAR0 1900 /* the first year */
|
||||
#define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
|
||||
#define SECS_DAY (24L * 60L * 60L)
|
||||
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
|
||||
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
|
||||
#define FIRSTSUNDAY(timp) (((timp)->tm_yday - (timp)->tm_wday + 420) % 7)
|
||||
#define FIRSTDAYOF(timp) (((timp)->tm_wday - (timp)->tm_yday + 420) % 7)
|
||||
#define TIME_MAX ULONG_MAX
|
||||
#define ABB_LEN 3
|
||||
|
||||
extern const int _ytab[2][12];
|
||||
extern const char *_days[];
|
||||
extern const char *_months[];
|
||||
|
||||
void _tzset(void);
|
||||
unsigned _dstget(struct tm *timep);
|
||||
|
||||
extern long _timezone;
|
||||
extern long _dst_off;
|
||||
extern int _daylight;
|
||||
extern char *_tzname[2];
|
||||
36
lib/ansi/localeconv.c
Executable file
36
lib/ansi/localeconv.c
Executable file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* localeconv - set components of a struct according to current locale
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
|
||||
extern struct lconv _lc;
|
||||
|
||||
struct lconv *
|
||||
localeconv(void)
|
||||
{
|
||||
register struct lconv *lcp = &_lc;
|
||||
|
||||
lcp->decimal_point = ".";
|
||||
lcp->thousands_sep = "";
|
||||
lcp->grouping = "";
|
||||
lcp->int_curr_symbol = "";
|
||||
lcp->currency_symbol = "";
|
||||
lcp->mon_decimal_point = "";
|
||||
lcp->mon_thousands_sep = "";
|
||||
lcp->mon_grouping = "";
|
||||
lcp->positive_sign = "";
|
||||
lcp->negative_sign = "";
|
||||
lcp->int_frac_digits = CHAR_MAX;
|
||||
lcp->frac_digits = CHAR_MAX;
|
||||
lcp->p_cs_precedes = CHAR_MAX;
|
||||
lcp->p_sep_by_space = CHAR_MAX;
|
||||
lcp->n_cs_precedes = CHAR_MAX;
|
||||
lcp->n_sep_by_space = CHAR_MAX;
|
||||
lcp->p_sign_posn = CHAR_MAX;
|
||||
lcp->n_sign_posn = CHAR_MAX;
|
||||
|
||||
return lcp;
|
||||
}
|
||||
34
lib/ansi/localtime.c
Executable file
34
lib/ansi/localtime.c
Executable file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* localtime - convert a calendar time into broken down time
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <time.h>
|
||||
#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.
|
||||
* This assumes that both must be expressable in multiples of a minute.
|
||||
* 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 *timep;
|
||||
unsigned dst;
|
||||
|
||||
_tzset();
|
||||
timep = gmtime(timer); /* tm->tm_isdst == 0 */
|
||||
timep->tm_min -= _timezone / 60;
|
||||
timep->tm_sec -= _timezone % 60;
|
||||
mktime(timep);
|
||||
|
||||
dst = _dstget(timep);
|
||||
if (dst) {
|
||||
timep->tm_min += dst / 60;
|
||||
timep->tm_sec += dst % 60;
|
||||
mktime(timep);
|
||||
}
|
||||
return timep;
|
||||
}
|
||||
205
lib/ansi/malloc.c
Executable file
205
lib/ansi/malloc.c
Executable file
@@ -0,0 +1,205 @@
|
||||
/* $Header$ */
|
||||
|
||||
/* replace undef by define */
|
||||
#undef DEBUG /* check assertions */
|
||||
#undef SLOWDEBUG /* some extra test loops (requires DEBUG) */
|
||||
|
||||
#ifndef DEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if _EM_WSIZE == _EM_PSIZE
|
||||
#define ptrint int
|
||||
#else
|
||||
#define ptrint long
|
||||
#endif
|
||||
|
||||
#if _EM_PSIZE == 2
|
||||
#define BRKSIZE 1024
|
||||
#else
|
||||
#define BRKSIZE 4096
|
||||
#endif
|
||||
#define PTRSIZE ((int) sizeof(void *))
|
||||
#define Align(x,a) (((x) + (a - 1)) & ~(a - 1))
|
||||
#define NextSlot(p) (* (void **) ((p) - PTRSIZE))
|
||||
#define NextFree(p) (* (void **) (p))
|
||||
|
||||
/*
|
||||
* A short explanation of the data structure and algorithms.
|
||||
* An area returned by malloc() is called a slot. Each slot
|
||||
* contains the number of bytes requested, but preceeded by
|
||||
* an extra pointer to the next the slot in memory.
|
||||
* '_bottom' and '_top' point to the first/last slot.
|
||||
* More memory is asked for using brk() and appended to top.
|
||||
* The list of free slots is maintained to keep malloc() fast.
|
||||
* '_empty' points the the first free slot. Free slots are
|
||||
* linked together by a pointer at the start of the
|
||||
* user visable part, so just after the next-slot pointer.
|
||||
* Free slots are merged together by free().
|
||||
*/
|
||||
|
||||
extern void *_sbrk(int);
|
||||
extern int _brk(void *);
|
||||
static void *_bottom, *_top, *_empty;
|
||||
|
||||
static int grow(size_t len)
|
||||
{
|
||||
register char *p;
|
||||
|
||||
assert(NextSlot((char *)_top) == 0);
|
||||
if ((char *) _top + len < (char *) _top
|
||||
|| (p = (char *)Align((ptrint)_top + len, BRKSIZE)) < (char *) _top ) {
|
||||
errno = ENOMEM;
|
||||
return(0);
|
||||
}
|
||||
if (_brk(p) != 0)
|
||||
return(0);
|
||||
NextSlot((char *)_top) = p;
|
||||
NextSlot(p) = 0;
|
||||
free(_top);
|
||||
_top = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *
|
||||
malloc(size_t size)
|
||||
{
|
||||
register char *prev, *p, *next, *new;
|
||||
register unsigned len, ntries;
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
for (ntries = 0; ntries < 2; ntries++) {
|
||||
if ((len = Align(size, PTRSIZE) + PTRSIZE) < 2 * PTRSIZE) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (_bottom == 0) {
|
||||
if ((p = _sbrk(2 * PTRSIZE)) == (char *) -1)
|
||||
return NULL;
|
||||
p = (char *) Align((ptrint)p, PTRSIZE);
|
||||
p += PTRSIZE;
|
||||
_top = _bottom = p;
|
||||
NextSlot(p) = 0;
|
||||
}
|
||||
#ifdef SLOWDEBUG
|
||||
for (p = _bottom; (next = NextSlot(p)) != 0; p = next)
|
||||
assert(next > p);
|
||||
assert(p == _top);
|
||||
#endif
|
||||
for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
|
||||
next = NextSlot(p);
|
||||
new = p + len; /* easily overflows!! */
|
||||
if (new > next || new <= p)
|
||||
continue; /* too small */
|
||||
if (new + PTRSIZE < next) { /* too big, so split */
|
||||
/* + PTRSIZE avoids tiny slots on free list */
|
||||
NextSlot(new) = next;
|
||||
NextSlot(p) = new;
|
||||
NextFree(new) = NextFree(p);
|
||||
NextFree(p) = new;
|
||||
}
|
||||
if (prev)
|
||||
NextFree(prev) = NextFree(p);
|
||||
else
|
||||
_empty = NextFree(p);
|
||||
return p;
|
||||
}
|
||||
if (grow(len) == 0)
|
||||
break;
|
||||
}
|
||||
assert(ntries != 2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
realloc(void *oldp, size_t size)
|
||||
{
|
||||
register char *prev, *p, *next, *new;
|
||||
char *old = oldp;
|
||||
register size_t len, n;
|
||||
|
||||
if (old == 0)
|
||||
return malloc(size);
|
||||
if (size == 0) {
|
||||
free(old);
|
||||
return NULL;
|
||||
}
|
||||
len = Align(size, PTRSIZE) + PTRSIZE;
|
||||
next = NextSlot(old);
|
||||
n = (int)(next - old); /* old length */
|
||||
/*
|
||||
* extend old if there is any free space just behind it
|
||||
*/
|
||||
for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
|
||||
if (p > next)
|
||||
break;
|
||||
if (p == next) { /* 'next' is a free slot: merge */
|
||||
NextSlot(old) = NextSlot(p);
|
||||
if (prev)
|
||||
NextFree(prev) = NextFree(p);
|
||||
else
|
||||
_empty = NextFree(p);
|
||||
next = NextSlot(old);
|
||||
break;
|
||||
}
|
||||
}
|
||||
new = old + len;
|
||||
/*
|
||||
* Can we use the old, possibly extended slot?
|
||||
*/
|
||||
if (new <= next && new >= old) { /* it does fit */
|
||||
if (new + PTRSIZE < next) { /* too big, so split */
|
||||
/* + PTRSIZE avoids tiny slots on free list */
|
||||
NextSlot(new) = next;
|
||||
NextSlot(old) = new;
|
||||
free(new);
|
||||
}
|
||||
return old;
|
||||
}
|
||||
if ((new = malloc(size)) == NULL) /* it didn't fit */
|
||||
return NULL;
|
||||
memcpy(new, old, n); /* n < size */
|
||||
free(old);
|
||||
return new;
|
||||
}
|
||||
|
||||
void
|
||||
free(void *ptr)
|
||||
{
|
||||
register char *prev, *next;
|
||||
char *p = ptr;
|
||||
|
||||
if (p == 0)
|
||||
return;
|
||||
|
||||
assert(NextSlot(p) > p);
|
||||
for (prev = 0, next = _empty; next != 0; prev = next, next = NextFree(next))
|
||||
if (p < next)
|
||||
break;
|
||||
NextFree(p) = next;
|
||||
if (prev)
|
||||
NextFree(prev) = p;
|
||||
else
|
||||
_empty = p;
|
||||
if (next) {
|
||||
assert(NextSlot(p) <= next);
|
||||
if (NextSlot(p) == next) { /* merge p and next */
|
||||
NextSlot(p) = NextSlot(next);
|
||||
NextFree(p) = NextFree(next);
|
||||
}
|
||||
}
|
||||
if (prev) {
|
||||
assert(NextSlot(prev) <= p);
|
||||
if (NextSlot(prev) == p) { /* merge prev and p */
|
||||
NextSlot(prev) = NextSlot(p);
|
||||
NextFree(prev) = NextFree(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
lib/ansi/mblen.c
Executable file
18
lib/ansi/mblen.c
Executable file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define CHAR_SHIFT 8
|
||||
|
||||
int
|
||||
mblen(const char *s, size_t n)
|
||||
{
|
||||
if (s == (const char *)NULL) return 0; /* no state dependent codings */
|
||||
if (n <= 0) return 0;
|
||||
return (*s != 0);
|
||||
}
|
||||
20
lib/ansi/mbstowcs.c
Executable file
20
lib/ansi/mbstowcs.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
mbstowcs(register wchar_t *pwcs, register const char *s, size_t n)
|
||||
{
|
||||
register int i = n;
|
||||
|
||||
while (--i >= 0) {
|
||||
if (!(*pwcs++ = *s++))
|
||||
return n - i - 1;
|
||||
}
|
||||
return n - i;
|
||||
}
|
||||
|
||||
17
lib/ansi/mbtowc.c
Executable file
17
lib/ansi/mbtowc.c
Executable file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
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;
|
||||
return (*s != 0);
|
||||
}
|
||||
23
lib/ansi/memchr.c
Executable file
23
lib/ansi/memchr.c
Executable file
@@ -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".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
22
lib/ansi/memcmp.c
Executable file
22
lib/ansi/memcmp.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* (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 <string.h>
|
||||
|
||||
int
|
||||
memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
register const unsigned char *p1 = s1, *p2 = s2;
|
||||
|
||||
if (n) {
|
||||
n++;
|
||||
while (--n > 0) {
|
||||
if (*p1++ == *p2++) continue;
|
||||
return *--p1 - *--p2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
23
lib/ansi/memcpy.c
Executable file
23
lib/ansi/memcpy.c
Executable file
@@ -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".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memcpy(void *s1, const void *s2, register size_t n)
|
||||
{
|
||||
register char *p1 = s1;
|
||||
register const char *p2 = s2;
|
||||
|
||||
|
||||
if (n) {
|
||||
n++;
|
||||
while (--n > 0) {
|
||||
*p1++ = *p2++;
|
||||
}
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
32
lib/ansi/memmove.c
Executable file
32
lib/ansi/memmove.c
Executable file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memmove(void *s1, const void *s2, register size_t n)
|
||||
{
|
||||
register char *p1 = s1;
|
||||
register const char *p2 = s2;
|
||||
|
||||
if (n>0) {
|
||||
if (p2 <= p1 && p2 + n > p1) {
|
||||
/* overlap, copy backwards */
|
||||
p1 += n;
|
||||
p2 += n;
|
||||
n++;
|
||||
while (--n > 0) {
|
||||
*--p1 = *--p2;
|
||||
}
|
||||
} else {
|
||||
n++;
|
||||
while (--n > 0) {
|
||||
*p1++ = *p2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
21
lib/ansi/memset.c
Executable file
21
lib/ansi/memset.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memset(void *s, register int c, register size_t n)
|
||||
{
|
||||
register char *s1 = s;
|
||||
|
||||
if (n>0) {
|
||||
n++;
|
||||
while (--n > 0) {
|
||||
*s1++ = c;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
410
lib/ansi/misc.c
Executable file
410
lib/ansi/misc.c
Executable file
@@ -0,0 +1,410 @@
|
||||
/*
|
||||
* misc - data and miscellaneous routines
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__BSD4_2)
|
||||
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* and microseconds */
|
||||
};
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
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 }
|
||||
};
|
||||
|
||||
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 time;
|
||||
register const char *q;
|
||||
|
||||
if (!(p = parseDate(buf, p, &dststart))) return NULL;
|
||||
buf += strlen(buf);
|
||||
if (*p == '/') {
|
||||
q = ++p;
|
||||
if (!(p = parseTime(&time, 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(&time, 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 (*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 time;
|
||||
|
||||
_ftime(&time);
|
||||
_timezone = time.timezone * 60L;
|
||||
_daylight = time.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 (do_dst) return _dst_off;
|
||||
timep->tm_isdst = 0;
|
||||
return 0;
|
||||
}
|
||||
132
lib/ansi/mktime.c
Executable file
132
lib/ansi/mktime.c
Executable file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* mktime - convert local time into calendar time
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
/* Michael A. Temari <temari@ix.netcom.com> 03/01/96 */
|
||||
/* - fixed bug is structure fixup code */
|
||||
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#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)
|
||||
{
|
||||
register long day, year;
|
||||
register int tm_year;
|
||||
int yday, month;
|
||||
register unsigned long seconds;
|
||||
int overflow;
|
||||
unsigned dst;
|
||||
|
||||
timep->tm_min += timep->tm_sec / 60;
|
||||
timep->tm_sec %= 60;
|
||||
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) {
|
||||
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 += 24;
|
||||
day--;
|
||||
}
|
||||
timep->tm_year += timep->tm_mon / 12;
|
||||
timep->tm_mon %= 12;
|
||||
if (timep->tm_mon < 0) {
|
||||
timep->tm_mon += 12;
|
||||
timep->tm_year--;
|
||||
}
|
||||
day += (timep->tm_mday - 1);
|
||||
while (day < 0) {
|
||||
if(--timep->tm_mon < 0) {
|
||||
timep->tm_year--;
|
||||
timep->tm_mon = 11;
|
||||
}
|
||||
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) {
|
||||
timep->tm_mon = 0;
|
||||
timep->tm_year++;
|
||||
}
|
||||
}
|
||||
timep->tm_mday = day + 1;
|
||||
_tzset(); /* set timezone and dst info */
|
||||
year = EPOCH_YR;
|
||||
if (timep->tm_year < year - YEAR0) return (time_t)-1;
|
||||
seconds = 0;
|
||||
day = 0; /* means days since day 0 now */
|
||||
overflow = 0;
|
||||
|
||||
/* 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
|
||||
#endif
|
||||
tm_year = timep->tm_year + YEAR0;
|
||||
|
||||
if (LONG_MAX / 365 < tm_year - year) overflow++;
|
||||
day = (tm_year - year) * 365;
|
||||
if (LONG_MAX - day < (tm_year - year) / 4 + 1) overflow++;
|
||||
day += (tm_year - year) / 4
|
||||
+ ((tm_year % 4) && tm_year % 4 < year % 4);
|
||||
day -= (tm_year - year) / 100
|
||||
+ ((tm_year % 100) && tm_year % 100 < year % 100);
|
||||
day += (tm_year - year) / 400
|
||||
+ ((tm_year % 400) && tm_year % 400 < year % 400);
|
||||
|
||||
yday = month = 0;
|
||||
while (month < timep->tm_mon) {
|
||||
yday += _ytab[LEAPYEAR(tm_year)][month];
|
||||
month++;
|
||||
}
|
||||
yday += (timep->tm_mday - 1);
|
||||
if (day + yday < 0) overflow++;
|
||||
day += yday;
|
||||
|
||||
timep->tm_yday = yday;
|
||||
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++;
|
||||
seconds += day * SECS_DAY;
|
||||
|
||||
/* Now adjust according to timezone and daylight saving time */
|
||||
|
||||
if (((_timezone > 0) && (TIME_MAX - _timezone < seconds))
|
||||
|| ((_timezone < 0) && (seconds < -_timezone)))
|
||||
overflow++;
|
||||
seconds += _timezone;
|
||||
|
||||
if (timep->tm_isdst < 0)
|
||||
dst = _dstget(timep);
|
||||
else if (timep->tm_isdst)
|
||||
dst = _dst_off;
|
||||
else dst = 0;
|
||||
|
||||
if (dst > seconds) overflow++; /* dst is always non-negative */
|
||||
seconds -= dst;
|
||||
|
||||
if (overflow) return (time_t)-1;
|
||||
|
||||
if ((time_t)seconds != seconds) return (time_t)-1;
|
||||
return (time_t)seconds;
|
||||
}
|
||||
139
lib/ansi/qsort.c
Executable file
139
lib/ansi/qsort.c
Executable file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
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 *))
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
static void
|
||||
qsort1(char *a1, char *a2, register size_t width)
|
||||
{
|
||||
register char *left, *right;
|
||||
register char *lefteq, *righteq;
|
||||
int cmp;
|
||||
|
||||
for (;;) {
|
||||
if (a2 <= a1) return;
|
||||
left = a1;
|
||||
right = a2;
|
||||
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
|
||||
bounds of the equals respectively.
|
||||
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) {
|
||||
/* leave it where it is */
|
||||
left += width;
|
||||
}
|
||||
else {
|
||||
/* equal, so exchange with the element to
|
||||
the left of the "equal"-interval.
|
||||
*/
|
||||
lefteq -= width;
|
||||
qexchange(left, lefteq, width);
|
||||
}
|
||||
}
|
||||
while (right > righteq) {
|
||||
if ((cmp = (*qcompar)(right, righteq)) < 0) {
|
||||
/* smaller, should go to left part
|
||||
*/
|
||||
if (left < lefteq) {
|
||||
/* yes, we had a larger one at the
|
||||
left, so we can just exchange
|
||||
*/
|
||||
qexchange(left, right, width);
|
||||
left += width;
|
||||
right -= width;
|
||||
goto again;
|
||||
}
|
||||
/* no more room at the left part, so we
|
||||
move the "equal-interval" one place to the
|
||||
right, and the smaller element to the
|
||||
left of it.
|
||||
This is best expressed as a three-way
|
||||
exchange.
|
||||
*/
|
||||
righteq += width;
|
||||
q3exchange(left, righteq, right, width);
|
||||
lefteq += width;
|
||||
left = lefteq;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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
|
||||
of it.
|
||||
*/
|
||||
lefteq -= width;
|
||||
q3exchange(right, lefteq, left, width);
|
||||
righteq -= width;
|
||||
right = righteq;
|
||||
goto again;
|
||||
}
|
||||
/* now sort the "smaller" part */
|
||||
qsort1(a1, lefteq - width, width);
|
||||
/* and now the larger, saving a subroutine call
|
||||
because of the for(;;)
|
||||
*/
|
||||
a1 = righteq + width;
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static void
|
||||
qexchange(register char *p, register char *q,
|
||||
register size_t n)
|
||||
{
|
||||
register int c;
|
||||
|
||||
while (n-- > 0) {
|
||||
c = *p;
|
||||
*p++ = *q;
|
||||
*q++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
q3exchange(register char *p, register char *q, register char *r,
|
||||
register size_t n)
|
||||
{
|
||||
register int c;
|
||||
|
||||
while (n-- > 0) {
|
||||
c = *p;
|
||||
*p++ = *r;
|
||||
*r++ = *q;
|
||||
*q++ = c;
|
||||
}
|
||||
}
|
||||
21
lib/ansi/raise.c
Executable file
21
lib/ansi/raise.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#if defined(_POSIX_SOURCE)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
int _kill(int pid, int sig);
|
||||
pid_t _getpid(void);
|
||||
|
||||
int
|
||||
raise(int sig)
|
||||
{
|
||||
if (sig < 0 || sig > _NSIG)
|
||||
return -1;
|
||||
return _kill(_getpid(), sig);
|
||||
}
|
||||
20
lib/ansi/rand.c
Executable file
20
lib/ansi/rand.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned long int next = 1;
|
||||
|
||||
int rand(void)
|
||||
{
|
||||
next = next * 1103515245 + 12345;
|
||||
return (unsigned int)(next/(2 * (RAND_MAX +1L)) % (RAND_MAX+1L));
|
||||
}
|
||||
|
||||
void srand(unsigned int seed)
|
||||
{
|
||||
next = seed;
|
||||
}
|
||||
28
lib/ansi/setlocale.c
Executable file
28
lib/ansi/setlocale.c
Executable file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* setlocale - set the programs locale
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
39
lib/ansi/sigmisc.c
Executable file
39
lib/ansi/sigmisc.c
Executable file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* sigmisc.c - used to get a signal mask
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#if defined(_POSIX_SOURCE)
|
||||
|
||||
/* This can't be done in setjmp.e, since SIG_SETMASK is defined in
|
||||
* <signal.h>. This is a C-file, which can't be included.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int _sigprocmask(int, sigset_t *, sigset_t *);
|
||||
|
||||
static 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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__newsigset(sigset_t *p)
|
||||
{
|
||||
/* The SIG_SETMASK is not significant */
|
||||
_sigprocmask(SIG_SETMASK, NULL, p);
|
||||
}
|
||||
|
||||
void
|
||||
__oldsigset(sigset_t *p)
|
||||
{
|
||||
_sigprocmask(SIG_SETMASK, p, NULL);
|
||||
}
|
||||
#endif /* _POSIX_SOURCE */
|
||||
35
lib/ansi/signal.c
Executable file
35
lib/ansi/signal.c
Executable file
@@ -0,0 +1,35 @@
|
||||
/* SYSVR4 and ANSI compatible signal(2). */
|
||||
|
||||
#include <lib.h>
|
||||
#define sigaction _sigaction
|
||||
#define sigemptyset _sigemptyset
|
||||
#include <signal.h>
|
||||
|
||||
PUBLIC sighandler_t signal(sig, disp)
|
||||
int sig; /* signal number */
|
||||
sighandler_t disp; /* signal handler, or SIG_DFL, or SIG_IGN */
|
||||
{
|
||||
struct sigaction sa, osa;
|
||||
|
||||
if (sig <= 0 || sig > _NSIG || sig == SIGKILL) {
|
||||
errno = EINVAL;
|
||||
return(SIG_ERR);
|
||||
}
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
||||
#ifdef WANT_UNRELIABLE_SIGNALS
|
||||
/* Allow the signal being handled to interrupt the signal handler. */
|
||||
sa.sa_flags = SA_NODEFER;
|
||||
|
||||
/* When signal is caught, reset signal handler to SIG_DFL for all but
|
||||
* SIGILL and SIGTRAP.
|
||||
*/
|
||||
if (sig != SIGILL && sig != SIGTRAP) sa.sa_flags |= SA_RESETHAND;
|
||||
#else
|
||||
sa.sa_flags = 0;
|
||||
#endif
|
||||
|
||||
sa.sa_handler = disp;
|
||||
if (sigaction(sig, &sa, &osa) < 0) return(SIG_ERR);
|
||||
return(osa.sa_handler);
|
||||
}
|
||||
20
lib/ansi/strcat.c
Executable file
20
lib/ansi/strcat.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strcat(char *ret, register const char *s2)
|
||||
{
|
||||
register char *s1 = ret;
|
||||
|
||||
while (*s1++ != '\0')
|
||||
/* EMPTY */ ;
|
||||
s1--;
|
||||
while (*s1++ = *s2++)
|
||||
/* EMPTY */ ;
|
||||
return ret;
|
||||
}
|
||||
18
lib/ansi/strchr.c
Executable file
18
lib/ansi/strchr.c
Executable file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strchr(register const char *s, register int c)
|
||||
{
|
||||
c = (char) c;
|
||||
|
||||
while (c != *s) {
|
||||
if (*s++ == '\0') return NULL;
|
||||
}
|
||||
return (char *)s;
|
||||
}
|
||||
20
lib/ansi/strcmp.c
Executable file
20
lib/ansi/strcmp.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* (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 <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
19
lib/ansi/strcoll.c
Executable file
19
lib/ansi/strcoll.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
int
|
||||
strcoll(register const char *s1, register const char *s2)
|
||||
{
|
||||
while (*s1 == *s2++) {
|
||||
if (*s1++ == '\0') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return *s1 - *--s2;
|
||||
}
|
||||
18
lib/ansi/strcpy.c
Executable file
18
lib/ansi/strcpy.c
Executable file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strcpy(char *ret, register const char *s2)
|
||||
{
|
||||
register char *s1 = ret;
|
||||
|
||||
while (*s1++ = *s2++)
|
||||
/* EMPTY */ ;
|
||||
|
||||
return ret;
|
||||
}
|
||||
21
lib/ansi/strcspn.c
Executable file
21
lib/ansi/strcspn.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
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 */ ;
|
||||
if (*s2)
|
||||
break;
|
||||
}
|
||||
return s1 - string;
|
||||
}
|
||||
22
lib/ansi/strerror.c
Executable file
22
lib/ansi/strerror.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* I don't know why, but X3J11 says that strerror() should be in declared
|
||||
* in <string.h>. That is why the function is defined here.
|
||||
*/
|
||||
char *
|
||||
strerror(register int errnum)
|
||||
{
|
||||
extern const char *_sys_errlist[];
|
||||
extern const int _sys_nerr;
|
||||
|
||||
if (errnum < 0 || errnum >= _sys_nerr)
|
||||
return "unknown error";
|
||||
return (char *)_sys_errlist[errnum];
|
||||
}
|
||||
172
lib/ansi/strftime.c
Executable file
172
lib/ansi/strftime.c
Executable file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* strftime - convert a structure to a string, controlled by an argument
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <time.h>
|
||||
#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 */
|
||||
}
|
||||
18
lib/ansi/strlen.c
Executable file
18
lib/ansi/strlen.c
Executable file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strlen(const char *org)
|
||||
{
|
||||
register const char *s = org;
|
||||
|
||||
while (*s++)
|
||||
/* EMPTY */ ;
|
||||
|
||||
return --s - org;
|
||||
}
|
||||
25
lib/ansi/strncat.c
Executable file
25
lib/ansi/strncat.c
Executable file
@@ -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".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strncat(char *ret, register const char *s2, size_t n)
|
||||
{
|
||||
register char *s1 = ret;
|
||||
|
||||
if (n > 0) {
|
||||
while (*s1++)
|
||||
/* EMPTY */ ;
|
||||
s1--;
|
||||
while (*s1++ = *s2++) {
|
||||
if (--n > 0) continue;
|
||||
*s1 = '\0';
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
} else return s1;
|
||||
}
|
||||
26
lib/ansi/strncmp.c
Executable file
26
lib/ansi/strncmp.c
Executable file
@@ -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 <string.h>
|
||||
|
||||
int
|
||||
strncmp(register const char *s1, register const char *s2, register size_t n)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
24
lib/ansi/strncpy.c
Executable file
24
lib/ansi/strncpy.c
Executable file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
22
lib/ansi/strpbrk.c
Executable file
22
lib/ansi/strpbrk.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strpbrk(register const char *string, register const char *brk)
|
||||
{
|
||||
register const char *s1;
|
||||
|
||||
while (*string) {
|
||||
for (s1 = brk; *s1 && *s1 != *string; s1++)
|
||||
/* EMPTY */ ;
|
||||
if (*s1)
|
||||
return (char *)string;
|
||||
string++;
|
||||
}
|
||||
return (char *)NULL;
|
||||
}
|
||||
22
lib/ansi/strrchr.c
Executable file
22
lib/ansi/strrchr.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strrchr(register const char *s, int c)
|
||||
{
|
||||
register const char *result = NULL;
|
||||
|
||||
c = (char) c;
|
||||
|
||||
do {
|
||||
if (c == *s)
|
||||
result = s;
|
||||
} while (*s++ != '\0');
|
||||
|
||||
return (char *)result;
|
||||
}
|
||||
21
lib/ansi/strspn.c
Executable file
21
lib/ansi/strspn.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strspn(const char *string, const char *in)
|
||||
{
|
||||
register const char *s1, *s2;
|
||||
|
||||
for (s1 = string; *s1; s1++) {
|
||||
for (s2 = in; *s2 && *s2 != *s1; s2++)
|
||||
/* EMPTY */ ;
|
||||
if (*s2 == '\0')
|
||||
break;
|
||||
}
|
||||
return s1 - string;
|
||||
}
|
||||
19
lib/ansi/strstr.c
Executable file
19
lib/ansi/strstr.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strstr(register const char *s, register const char *wanted)
|
||||
{
|
||||
register const size_t len = strlen(wanted);
|
||||
|
||||
if (len == 0) return (char *)s;
|
||||
while (*s != *wanted || strncmp(s, wanted, len))
|
||||
if (*s++ == '\0')
|
||||
return (char *)NULL;
|
||||
return (char *)s;
|
||||
}
|
||||
31
lib/ansi/strtok.c
Executable file
31
lib/ansi/strtok.c
Executable file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strtok(register char *string, const char *separators)
|
||||
{
|
||||
register char *s1, *s2;
|
||||
static char *savestring;
|
||||
|
||||
if (string == NULL) {
|
||||
string = savestring;
|
||||
if (string == NULL) return (char *)NULL;
|
||||
}
|
||||
|
||||
s1 = string + strspn(string, separators);
|
||||
if (*s1 == '\0') {
|
||||
savestring = NULL;
|
||||
return (char *)NULL;
|
||||
}
|
||||
|
||||
s2 = strpbrk(s1, separators);
|
||||
if (s2 != NULL)
|
||||
*s2++ = '\0';
|
||||
savestring = s2;
|
||||
return s1;
|
||||
}
|
||||
101
lib/ansi/strtol.c
Executable file
101
lib/ansi/strtol.c
Executable file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#define between(a, c, z) ((unsigned) ((c) - (a)) <= (unsigned) ((z) - (a)))
|
||||
|
||||
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++;
|
||||
|
||||
for (;;) {
|
||||
c = *nptr;
|
||||
if (between('0', c, '9')) {
|
||||
v = c - '0';
|
||||
} else
|
||||
if (between('a', c, 'z')) {
|
||||
v = c - 'a' + 0xa;
|
||||
} else
|
||||
if (between('A', c, 'Z')) {
|
||||
v = c - 'A' + 0xA;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (v >= base) break;
|
||||
if (val > (ULONG_MAX - v) / base) ovfl++;
|
||||
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. */
|
||||
if (is_signed
|
||||
&& ( (sign < 0 && val > -(unsigned long)LONG_MIN)
|
||||
|| (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 (long) sign * val;
|
||||
}
|
||||
24
lib/ansi/strxfrm.c
Executable file
24
lib/ansi/strxfrm.c
Executable file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strxfrm(register char *s1, register const char *save, register size_t n)
|
||||
{
|
||||
register const char *s2 = save;
|
||||
|
||||
while (*s2) {
|
||||
if (n > 1) {
|
||||
n--;
|
||||
*s1++ = *s2++;
|
||||
} else
|
||||
s2++;
|
||||
}
|
||||
if (n > 0)
|
||||
*s1++ = '\0';
|
||||
return s2 - save;
|
||||
}
|
||||
59
lib/ansi/system.c
Executable file
59
lib/ansi/system.c
Executable file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#if defined(_POSIX_SOURCE)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
extern pid_t _fork(void);
|
||||
extern pid_t _wait(int *);
|
||||
extern void _exit(int);
|
||||
extern void _execve(const char *path, const char ** argv, const char ** envp);
|
||||
extern int _close(int);
|
||||
|
||||
#define FAIL 127
|
||||
|
||||
extern const char ***_penviron;
|
||||
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, *_penviron);
|
||||
/* 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;
|
||||
}
|
||||
5
lib/ansi/tolower.c
Executable file
5
lib/ansi/tolower.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int tolower(int c) {
|
||||
return isupper(c) ? c - 'A' + 'a' : c ;
|
||||
}
|
||||
5
lib/ansi/toupper.c
Executable file
5
lib/ansi/toupper.c
Executable file
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int toupper(int c) {
|
||||
return islower(c) ? c - 'a' + 'A' : c ;
|
||||
}
|
||||
15
lib/ansi/tzset.c
Executable file
15
lib/ansi/tzset.c
Executable file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* tzset - set timezone information
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
/* This function is present for System V && POSIX */
|
||||
|
||||
#include <time.h>
|
||||
#include "loc_time.h"
|
||||
|
||||
void
|
||||
tzset(void)
|
||||
{
|
||||
_tzset(); /* does the job */
|
||||
}
|
||||
21
lib/ansi/wcstombs.c
Executable file
21
lib/ansi/wcstombs.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <limits.h>
|
||||
|
||||
size_t
|
||||
wcstombs(register char *s, register const wchar_t *pwcs, size_t n)
|
||||
{
|
||||
register int i = n;
|
||||
|
||||
while (--i >= 0) {
|
||||
if (!(*s++ = *pwcs++))
|
||||
break;
|
||||
}
|
||||
return n - i - 1;
|
||||
}
|
||||
20
lib/ansi/wctomb.c
Executable file
20
lib/ansi/wctomb.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
/* was: wctomb(char *s, wchar_t wchar)
|
||||
* This conflicts with prototype, so it was changed to:
|
||||
*/
|
||||
wctomb(char *s, wchar_t wchar)
|
||||
{
|
||||
if (!s) return 0; /* no state dependent codings */
|
||||
|
||||
*s = wchar;
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user