Initial revision
This commit is contained in:
Executable
+203
@@ -0,0 +1,203 @@
|
||||
# Makefile for the libraries
|
||||
|
||||
# This makefile runs make in all the subdirectories of the src/lib tree.
|
||||
# See ansi/Makefile for a further explanation.
|
||||
|
||||
MAKE = exec make -$(MAKEFLAGS)
|
||||
|
||||
usage:
|
||||
@echo "Usage: make all" >&2 # Compile all library functions" >&2
|
||||
@echo " make install # Backup /usr/lib/*.a first!" >&2
|
||||
@echo " make clean # Delete .o and .a files" >&2
|
||||
@false
|
||||
|
||||
all:
|
||||
cd ansi && $(MAKE)
|
||||
cd curses && $(MAKE)
|
||||
cd dummy && $(MAKE)
|
||||
cd editline && $(MAKE)
|
||||
cd end && $(MAKE)
|
||||
cd float && $(MAKE)
|
||||
cd fphook && $(MAKE)
|
||||
cd ip && $(MAKE)
|
||||
cd libm2 && $(MAKE)
|
||||
cd libp && $(MAKE)
|
||||
cd liby && $(MAKE)
|
||||
cd math && $(MAKE)
|
||||
cd other && $(MAKE)
|
||||
cd posix && $(MAKE)
|
||||
test `arch` = i86 || { cd regex && $(MAKE); }
|
||||
cd rts && $(MAKE)
|
||||
cd stdio && $(MAKE)
|
||||
cd socket && $(MAKE)
|
||||
cd syscall && $(MAKE)
|
||||
cd syslib && $(MAKE)
|
||||
cd utils && $(MAKE)
|
||||
cd timers && $(MAKE)
|
||||
cd `arch` && $(MAKE)
|
||||
|
||||
install: all
|
||||
$(MAKE) install_`arch`
|
||||
|
||||
# Installation rules for PC Minix.
|
||||
LIB= /usr/lib
|
||||
|
||||
install_i86: \
|
||||
$(LIB)/ncrtso.o \
|
||||
$(LIB)/nm2rtso.o \
|
||||
$(LIB)/nprtso.o \
|
||||
$(LIB)/libc.a \
|
||||
$(LIB)/libd.a \
|
||||
$(LIB)/libe.a \
|
||||
$(LIB)/libfp.a \
|
||||
$(LIB)/libm.a \
|
||||
$(LIB)/libm2.a \
|
||||
$(LIB)/libp.a \
|
||||
$(LIB)/end.a \
|
||||
$(LIB)/libsys.a \
|
||||
$(LIB)/libtimers.a \
|
||||
$(LIB)/utils.a \
|
||||
$(LIB)/libcurses.a \
|
||||
$(LIB)/libedit.a \
|
||||
$(LIB)/liby.a \
|
||||
|
||||
$(LIB)/ncrtso.o: ncrtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/nm2rtso.o: nm2rtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/nprtso.o: nprtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libc.a: libc.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libd.a: libd.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libe.a: libe.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libfp.a: libfp.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libm.a: libm.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libm2.a: libm2.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libp.a: libp.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/end.a: end.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libsys.a: libsys.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libtimers.a: libtimers.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libutils.a: libutils.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libcurses.a: libcurses.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/libedit.a: libedit.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB)/liby.a: liby.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
# Installation rules for Minix-386.
|
||||
LIB386= /usr/lib/i386
|
||||
LIB86= /usr/lib/i86
|
||||
|
||||
install_i386: \
|
||||
$(LIB386)/crtso.o \
|
||||
$(LIB386)/m2rtso.o \
|
||||
$(LIB386)/prtso.o \
|
||||
$(LIB386)/libc.a \
|
||||
$(LIB386)/libd.a \
|
||||
$(LIB386)/libe.a \
|
||||
$(LIB386)/libfp.a \
|
||||
$(LIB386)/libm.a \
|
||||
$(LIB386)/libm2.a \
|
||||
$(LIB386)/libp.a \
|
||||
$(LIB386)/libtimers.a \
|
||||
$(LIB386)/end.a \
|
||||
$(LIB386)/libsys.a \
|
||||
$(LIB386)/libtimers.a \
|
||||
$(LIB386)/libutils.a \
|
||||
$(LIB386)/libcurses.a \
|
||||
$(LIB386)/libedit.a \
|
||||
$(LIB386)/liby.a \
|
||||
$(LIB386)/libsocket.a \
|
||||
# $(LIB86)/libc.a \
|
||||
# $(LIB86)/end.a \
|
||||
|
||||
$(LIB386)/crtso.o: crtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/m2rtso.o: m2rtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/prtso.o: prtso.o
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libc.a: libc.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libd.a: libd.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libe.a: libe.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libfp.a: libfp.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libm.a: libm.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libm2.a: libm2.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libp.a: libp.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/end.a: end.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libsys.a: libsys.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libtimers.a: libtimers.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libutils.a: libutils.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libcurses.a: libcurses.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libedit.a: libedit.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/liby.a: liby.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
$(LIB386)/libsocket.a: libsocket.a
|
||||
install -c -o bin $? $@
|
||||
|
||||
#$(LIB86)/libc.a: libc86.a
|
||||
# install -c -o bin $? $@
|
||||
#
|
||||
#$(LIB86)/end.a: end86.a
|
||||
# install -c -o bin $? $@
|
||||
|
||||
clean:
|
||||
find . -name '*.[oa]' -o -name '*.bak' | xargs rm
|
||||
Executable
+330
@@ -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
|
||||
Executable
+21
@@ -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);
|
||||
}
|
||||
|
||||
Executable
+13
@@ -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;
|
||||
}
|
||||
Executable
+60
@@ -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;
|
||||
}
|
||||
Executable
+14
@@ -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();
|
||||
}
|
||||
Executable
+17
@@ -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;
|
||||
}
|
||||
Executable
+19
@@ -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;
|
||||
}
|
||||
Executable
+14
@@ -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);
|
||||
}
|
||||
Executable
+30
@@ -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;
|
||||
}
|
||||
Executable
+28
@@ -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;
|
||||
}
|
||||
Executable
+19
@@ -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;
|
||||
}
|
||||
|
||||
Executable
+261
@@ -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,
|
||||
};
|
||||
Executable
+15
@@ -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;
|
||||
}
|
||||
Executable
+12
@@ -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));
|
||||
}
|
||||
Executable
+17
@@ -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);
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -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;
|
||||
}
|
||||
Executable
+83
@@ -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]);
|
||||
Executable
+36
@@ -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) ;
|
||||
}
|
||||
Executable
+743
@@ -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;
|
||||
}
|
||||
Executable
+13
@@ -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
|
||||
};
|
||||
|
||||
Executable
+28
@@ -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;
|
||||
}
|
||||
Executable
+41
@@ -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;
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isalnum)(int c) {
|
||||
return isalnum(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isalpha)(int c) {
|
||||
return isalpha(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isascii)(int c) {
|
||||
return isascii(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (iscntrl)(int c) {
|
||||
return iscntrl(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isdigit)(int c) {
|
||||
return isdigit(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isgraph)(int c) {
|
||||
return isgraph(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (islower)(int c) {
|
||||
return islower(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isprint)(int c) {
|
||||
return isprint(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (ispunct)(int c) {
|
||||
return ispunct(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isspace)(int c) {
|
||||
return isspace(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isupper)(int c) {
|
||||
return isupper(c);
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int (isxdigit)(int c) {
|
||||
return isxdigit(c);
|
||||
}
|
||||
Executable
+13
@@ -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;
|
||||
}
|
||||
Executable
+31
@@ -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;
|
||||
}
|
||||
Executable
+26
@@ -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];
|
||||
Executable
+36
@@ -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;
|
||||
}
|
||||
Executable
+34
@@ -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;
|
||||
}
|
||||
Executable
+205
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+18
@@ -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);
|
||||
}
|
||||
Executable
+20
@@ -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;
|
||||
}
|
||||
|
||||
Executable
+17
@@ -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);
|
||||
}
|
||||
Executable
+23
@@ -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;
|
||||
}
|
||||
Executable
+22
@@ -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;
|
||||
}
|
||||
Executable
+23
@@ -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;
|
||||
}
|
||||
Executable
+32
@@ -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;
|
||||
}
|
||||
Executable
+21
@@ -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;
|
||||
}
|
||||
Executable
+410
@@ -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;
|
||||
}
|
||||
Executable
+132
@@ -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;
|
||||
}
|
||||
Executable
+139
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -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);
|
||||
}
|
||||
Executable
+20
@@ -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;
|
||||
}
|
||||
Executable
+28
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable
+39
@@ -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 */
|
||||
Executable
+35
@@ -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);
|
||||
}
|
||||
Executable
+20
@@ -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;
|
||||
}
|
||||
Executable
+18
@@ -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;
|
||||
}
|
||||
Executable
+20
@@ -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;
|
||||
}
|
||||
Executable
+19
@@ -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;
|
||||
}
|
||||
Executable
+18
@@ -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;
|
||||
}
|
||||
Executable
+21
@@ -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;
|
||||
}
|
||||
Executable
+22
@@ -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];
|
||||
}
|
||||
Executable
+172
@@ -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 */
|
||||
}
|
||||
Executable
+18
@@ -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;
|
||||
}
|
||||
Executable
+25
@@ -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;
|
||||
}
|
||||
Executable
+26
@@ -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;
|
||||
}
|
||||
Executable
+24
@@ -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;
|
||||
}
|
||||
Executable
+22
@@ -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;
|
||||
}
|
||||
Executable
+22
@@ -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;
|
||||
}
|
||||
Executable
+21
@@ -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;
|
||||
}
|
||||
Executable
+19
@@ -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;
|
||||
}
|
||||
Executable
+31
@@ -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;
|
||||
}
|
||||
Executable
+101
@@ -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;
|
||||
}
|
||||
Executable
+24
@@ -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;
|
||||
}
|
||||
Executable
+59
@@ -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;
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int tolower(int c) {
|
||||
return isupper(c) ? c - 'A' + 'a' : c ;
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int toupper(int c) {
|
||||
return islower(c) ? c - 'a' + 'A' : c ;
|
||||
}
|
||||
Executable
+15
@@ -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 */
|
||||
}
|
||||
Executable
+21
@@ -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;
|
||||
}
|
||||
Executable
+20
@@ -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;
|
||||
}
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
# Makefile for lib/curses.
|
||||
|
||||
CFLAGS = -O -D_MINIX -D_POSIX_SOURCE
|
||||
CC1 = $(CC) $(CFLAGS) -c
|
||||
|
||||
LIBRARY = ../libcurses.a
|
||||
all: $(LIBRARY)
|
||||
|
||||
OBJECTS = \
|
||||
$(LIBRARY)(beep.o) \
|
||||
$(LIBRARY)(charpick.o) \
|
||||
$(LIBRARY)(curs_set.o) \
|
||||
$(LIBRARY)(cursesio.o) \
|
||||
$(LIBRARY)(endwin.o) \
|
||||
$(LIBRARY)(flash.o) \
|
||||
$(LIBRARY)(initscr.o) \
|
||||
$(LIBRARY)(longname.o) \
|
||||
$(LIBRARY)(move.o) \
|
||||
$(LIBRARY)(mvcursor.o) \
|
||||
$(LIBRARY)(newwin.o) \
|
||||
$(LIBRARY)(options.o) \
|
||||
$(LIBRARY)(overlay.o) \
|
||||
$(LIBRARY)(prntscan.o) \
|
||||
$(LIBRARY)(refresh.o) \
|
||||
$(LIBRARY)(scrreg.o) \
|
||||
$(LIBRARY)(setterm.o) \
|
||||
$(LIBRARY)(tabsize.o) \
|
||||
$(LIBRARY)(termmisc.o) \
|
||||
$(LIBRARY)(unctrl.o) \
|
||||
$(LIBRARY)(update.o) \
|
||||
$(LIBRARY)(waddch.o) \
|
||||
$(LIBRARY)(waddstr.o) \
|
||||
$(LIBRARY)(wbox.o) \
|
||||
$(LIBRARY)(wclear.o) \
|
||||
$(LIBRARY)(wclrtobot.o) \
|
||||
$(LIBRARY)(wclrtoeol.o) \
|
||||
$(LIBRARY)(wdelch.o) \
|
||||
$(LIBRARY)(wdeleteln.o) \
|
||||
$(LIBRARY)(werase.o) \
|
||||
$(LIBRARY)(wgetch.o) \
|
||||
$(LIBRARY)(wgetstr.o) \
|
||||
$(LIBRARY)(windel.o) \
|
||||
$(LIBRARY)(winmove.o) \
|
||||
$(LIBRARY)(winsch.o) \
|
||||
$(LIBRARY)(winscrol.o) \
|
||||
$(LIBRARY)(winsertln.o) \
|
||||
$(LIBRARY)(wintouch.o) \
|
||||
|
||||
$(LIBRARY): $(OBJECTS)
|
||||
aal cr $@ *.o
|
||||
rm *.o
|
||||
|
||||
$(LIBRARY)(beep.o): beep.c
|
||||
$(CC1) beep.c
|
||||
|
||||
$(LIBRARY)(charpick.o): charpick.c
|
||||
$(CC1) charpick.c
|
||||
|
||||
$(LIBRARY)(curs_set.o): curs_set.c
|
||||
$(CC1) curs_set.c
|
||||
|
||||
$(LIBRARY)(cursesio.o): cursesio.c
|
||||
$(CC1) cursesio.c
|
||||
|
||||
$(LIBRARY)(endwin.o): endwin.c
|
||||
$(CC1) endwin.c
|
||||
|
||||
$(LIBRARY)(flash.o): flash.c
|
||||
$(CC1) flash.c
|
||||
|
||||
$(LIBRARY)(initscr.o): initscr.c
|
||||
$(CC1) initscr.c
|
||||
|
||||
$(LIBRARY)(longname.o): longname.c
|
||||
$(CC1) longname.c
|
||||
|
||||
$(LIBRARY)(move.o): move.c
|
||||
$(CC1) move.c
|
||||
|
||||
$(LIBRARY)(mvcursor.o): mvcursor.c
|
||||
$(CC1) mvcursor.c
|
||||
|
||||
$(LIBRARY)(newwin.o): newwin.c
|
||||
$(CC1) newwin.c
|
||||
|
||||
$(LIBRARY)(options.o): options.c
|
||||
$(CC1) options.c
|
||||
|
||||
$(LIBRARY)(overlay.o): overlay.c
|
||||
$(CC1) overlay.c
|
||||
|
||||
$(LIBRARY)(prntscan.o): prntscan.c
|
||||
$(CC1) prntscan.c
|
||||
|
||||
$(LIBRARY)(refresh.o): refresh.c
|
||||
$(CC1) refresh.c
|
||||
|
||||
$(LIBRARY)(scrreg.o): scrreg.c
|
||||
$(CC1) scrreg.c
|
||||
|
||||
$(LIBRARY)(setterm.o): setterm.c
|
||||
$(CC1) setterm.c
|
||||
|
||||
$(LIBRARY)(tabsize.o): tabsize.c
|
||||
$(CC1) tabsize.c
|
||||
|
||||
$(LIBRARY)(termmisc.o): termmisc.c
|
||||
$(CC1) termmisc.c
|
||||
|
||||
$(LIBRARY)(unctrl.o): unctrl.c
|
||||
$(CC1) unctrl.c
|
||||
|
||||
$(LIBRARY)(update.o): update.c
|
||||
$(CC1) update.c
|
||||
|
||||
$(LIBRARY)(waddch.o): waddch.c
|
||||
$(CC1) waddch.c
|
||||
|
||||
$(LIBRARY)(waddstr.o): waddstr.c
|
||||
$(CC1) waddstr.c
|
||||
|
||||
$(LIBRARY)(wbox.o): wbox.c
|
||||
$(CC1) wbox.c
|
||||
|
||||
$(LIBRARY)(wclear.o): wclear.c
|
||||
$(CC1) wclear.c
|
||||
|
||||
$(LIBRARY)(wclrtobot.o): wclrtobot.c
|
||||
$(CC1) wclrtobot.c
|
||||
|
||||
$(LIBRARY)(wclrtoeol.o): wclrtoeol.c
|
||||
$(CC1) wclrtoeol.c
|
||||
|
||||
$(LIBRARY)(wdelch.o): wdelch.c
|
||||
$(CC1) wdelch.c
|
||||
|
||||
$(LIBRARY)(wdeleteln.o): wdeleteln.c
|
||||
$(CC1) wdeleteln.c
|
||||
|
||||
$(LIBRARY)(werase.o): werase.c
|
||||
$(CC1) werase.c
|
||||
|
||||
$(LIBRARY)(wgetch.o): wgetch.c
|
||||
$(CC1) wgetch.c
|
||||
|
||||
$(LIBRARY)(wgetstr.o): wgetstr.c
|
||||
$(CC1) wgetstr.c
|
||||
|
||||
$(LIBRARY)(windel.o): windel.c
|
||||
$(CC1) windel.c
|
||||
|
||||
$(LIBRARY)(winmove.o): winmove.c
|
||||
$(CC1) winmove.c
|
||||
|
||||
$(LIBRARY)(winsch.o): winsch.c
|
||||
$(CC1) winsch.c
|
||||
|
||||
$(LIBRARY)(winscrol.o): winscrol.c
|
||||
$(CC1) winscrol.c
|
||||
|
||||
$(LIBRARY)(winsertln.o): winsertln.c
|
||||
$(CC1) winsertln.c
|
||||
|
||||
$(LIBRARY)(wintouch.o): wintouch.c
|
||||
$(CC1) wintouch.c
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
#include <termcap.h>
|
||||
|
||||
extern char *bl, *vb;
|
||||
|
||||
/* Beep() sounds the terminal bell. */
|
||||
void beep()
|
||||
{
|
||||
if (bl)
|
||||
tputs(bl, 1, outc);
|
||||
else if (vb)
|
||||
tputs(vb, 1, outc);
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Winch(win) returns the character at the current position in */
|
||||
/* Window 'win'. */
|
||||
/****************************************************************/
|
||||
|
||||
int winch(win)
|
||||
WINDOW *win;
|
||||
{
|
||||
return((win->_line[win->_cury][win->_curx]) & 0xff);
|
||||
} /* winch */
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvinch() moves the stdscr cursor to a new position, then */
|
||||
/* Returns the character at that position. */
|
||||
/****************************************************************/
|
||||
|
||||
int mvinch(y, x)
|
||||
int y;
|
||||
int x;
|
||||
{
|
||||
if (wmove(stdscr, y, x) == ERR) return(ERR);
|
||||
return((stdscr->_line[stdscr->_cury][stdscr->_curx]) & 0xff);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvwinch() moves the cursor of window 'win' to a new posi- */
|
||||
/* Tion, then returns the character at that position. */
|
||||
/****************************************************************/
|
||||
|
||||
int mvwinch(win, y, x)
|
||||
WINDOW *win;
|
||||
int y;
|
||||
int x;
|
||||
{
|
||||
if (wmove(win, y, x) == ERR) return(ERR);
|
||||
return((win->_line[win->_cury][win->_curx]) & 0xff);
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
#include <termcap.h>
|
||||
|
||||
extern char *vi, *ve, *vs;
|
||||
|
||||
/* Sets cursor visibility to unvisible=0; normal visible=1 or very good
|
||||
* visible=2.
|
||||
*/
|
||||
void curs_set(visibility)
|
||||
int visibility;
|
||||
{
|
||||
switch (visibility) {
|
||||
case 0:
|
||||
if (vi) tputs(vi, 1, outc);
|
||||
break;
|
||||
case 1:
|
||||
if (ve) tputs(ve, 1, outc);
|
||||
break;
|
||||
case 2:
|
||||
if (vs)
|
||||
tputs(vs, 1, outc);
|
||||
else if (ve)
|
||||
tputs(ve, 1, outc);
|
||||
}
|
||||
}
|
||||
Executable
+223
@@ -0,0 +1,223 @@
|
||||
#include <stdlib.h>
|
||||
#include <termcap.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
struct termios _orig_tty, _tty;
|
||||
cursv _cursvar;
|
||||
|
||||
WINDOW *stdscr, *curscr;
|
||||
int LINES, COLS;
|
||||
bool NONL;
|
||||
|
||||
char termcap[1024]; /* termcap buffer */
|
||||
char tc[200]; /* area to hold string capabilities */
|
||||
char *ttytype; /* terminal type from env */
|
||||
static char *arp; /* pointer for use in tgetstr */
|
||||
char *cp; /* character pointer */
|
||||
|
||||
char *cl; /* clear screen capability */
|
||||
char *cm; /* cursor motion capability */
|
||||
char *so; /* start standout capability */
|
||||
char *se; /* end standout capability */
|
||||
char *mr; /* start of reverse */
|
||||
char *me; /* revert to normal */
|
||||
char *mb; /* start of blink */
|
||||
char *md; /* start of bold */
|
||||
char *us; /* start of underscore */
|
||||
char *ue; /* end of underscore */
|
||||
char *vi; /* cursor invisible */
|
||||
char *ve; /* cursor normal */
|
||||
char *vs; /* cursor good visible */
|
||||
char *as; /* alternative charset start */
|
||||
char *ae; /* alternative charset end */
|
||||
char *bl; /* ring the bell */
|
||||
char *vb; /* visual bell */
|
||||
|
||||
/* fatal - report error and die. Never returns */
|
||||
void fatal(s)
|
||||
char *s;
|
||||
{
|
||||
(void) fprintf(stderr, "curses: %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Outc - call putchar, necessary because putchar is a macro. */
|
||||
void outc(c)
|
||||
int c;
|
||||
{
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
/* Move cursor to r,c */
|
||||
void poscur(r, c)
|
||||
int r, c;
|
||||
{
|
||||
tputs(tgoto(cm, c, r), 1, outc);
|
||||
}
|
||||
|
||||
/* Clear the screen */
|
||||
void clrscr()
|
||||
{
|
||||
tputs(cl, 1, outc);
|
||||
}
|
||||
|
||||
/* This are terminal independent characters which can be used in curses */
|
||||
|
||||
unsigned int ACS_ULCORNER;
|
||||
unsigned int ACS_LLCORNER;
|
||||
unsigned int ACS_URCORNER;
|
||||
unsigned int ACS_LRCORNER;
|
||||
unsigned int ACS_RTEE;
|
||||
unsigned int ACS_LTEE;
|
||||
unsigned int ACS_BTEE;
|
||||
unsigned int ACS_TTEE;
|
||||
unsigned int ACS_HLINE;
|
||||
unsigned int ACS_VLINE;
|
||||
unsigned int ACS_PLUS;
|
||||
unsigned int ACS_S1;
|
||||
unsigned int ACS_S9;
|
||||
unsigned int ACS_DIAMOND;
|
||||
unsigned int ACS_CKBOARD;
|
||||
unsigned int ACS_DEGREE;
|
||||
unsigned int ACS_PLMINUS;
|
||||
unsigned int ACS_BULLET;
|
||||
unsigned int ACS_LARROW;
|
||||
unsigned int ACS_RARROW;
|
||||
unsigned int ACS_DARROW;
|
||||
unsigned int ACS_UARROW;
|
||||
unsigned int ACS_BOARD;
|
||||
unsigned int ACS_LANTERN;
|
||||
unsigned int ACS_BLOCK;
|
||||
|
||||
/* These defines describe the full set of grafic block characters which
|
||||
* can be defined via termcap.
|
||||
*/
|
||||
|
||||
#define RIGHTARROW 0
|
||||
#define LEFTARROW 1
|
||||
#define DOWNARROW 2
|
||||
#define UPARROW 3
|
||||
#define FULLSQUARE 4
|
||||
#define GREYSQUARE 5
|
||||
#define EMPTYSQUARE 6
|
||||
#define LATERN 7
|
||||
#define DIAMOND 8
|
||||
#define DEGREE 9
|
||||
#define PLUSMINUS 10
|
||||
#define DOWNRIGHT 11
|
||||
#define UPRIGHT 12
|
||||
#define UPLEFT 13
|
||||
#define DOWNLEFT 14
|
||||
#define CROSS 15
|
||||
#define UPLINE 16
|
||||
#define UPMIDLINE 17
|
||||
#define MIDLINE 18
|
||||
#define DOMIDLINE 19
|
||||
#define DOWNLINE 20
|
||||
#define TEELEFT 21
|
||||
#define TEERIGHT 22
|
||||
#define TEEHEAD 23
|
||||
#define TEENORMAL 24
|
||||
#define VERTLINE 25
|
||||
#define PARAGRAPH 26
|
||||
|
||||
unsigned int _cursgraftable[27] =
|
||||
{
|
||||
'>', '<', 'v', '^', '#', ':', ' ', '#', '+', '\'', '#', '+', '+',
|
||||
'+', '+', '+', '-', ' ', '-', ' ', '_', '+', '+', '+', '+', '|'
|
||||
};
|
||||
char _cursident[28] = "+,.-0ahI`fgjklmnopqrstuvwx~";
|
||||
|
||||
int setterm(type)
|
||||
char *type;
|
||||
{
|
||||
unsigned char *ac;
|
||||
int i;
|
||||
#ifdef TIOCGWINSZ
|
||||
struct winsize wsize;
|
||||
#endif
|
||||
|
||||
if (tgetent(termcap, type) != 1) return ERR;
|
||||
|
||||
#ifdef TIOCGWINSZ
|
||||
if (ioctl(0, TIOCGWINSZ, &wsize) == 0) {
|
||||
LINES = wsize.ws_row != 0 ? wsize.ws_row : tgetnum("li");
|
||||
COLS = wsize.ws_col != 0 ? wsize.ws_col : tgetnum("co");
|
||||
} else {
|
||||
#endif
|
||||
LINES = tgetnum("li");
|
||||
COLS = tgetnum("co");
|
||||
#ifdef TIOCGWINSZ
|
||||
}
|
||||
#endif
|
||||
arp = tc;
|
||||
cl = tgetstr("cl", &arp);
|
||||
so = tgetstr("so", &arp);
|
||||
se = tgetstr("se", &arp);
|
||||
cm = tgetstr("cm", &arp);
|
||||
mr = tgetstr("mr", &arp);
|
||||
me = tgetstr("me", &arp);
|
||||
mb = tgetstr("mb", &arp);
|
||||
md = tgetstr("md", &arp);
|
||||
us = tgetstr("us", &arp);
|
||||
ue = tgetstr("ue", &arp);
|
||||
vi = tgetstr("vi", &arp);
|
||||
ve = tgetstr("ve", &arp);
|
||||
vs = tgetstr("vs", &arp);
|
||||
as = tgetstr("as", &arp);
|
||||
ae = tgetstr("ae", &arp);
|
||||
ac = (unsigned char *) tgetstr("ac", &arp);
|
||||
bl = tgetstr("bl", &arp);
|
||||
vb = tgetstr("vb", &arp);
|
||||
|
||||
if (ac) {
|
||||
while (*ac) {
|
||||
i = 0;
|
||||
while (*ac != _cursident[i]) i++;
|
||||
_cursgraftable[i] = *++ac | A_ALTCHARSET;
|
||||
ac++;
|
||||
}
|
||||
}
|
||||
|
||||
ACS_ULCORNER = _cursgraftable[UPLEFT];
|
||||
ACS_LLCORNER = _cursgraftable[DOWNLEFT];
|
||||
ACS_URCORNER = _cursgraftable[UPRIGHT];
|
||||
ACS_LRCORNER = _cursgraftable[DOWNRIGHT];
|
||||
ACS_RTEE = _cursgraftable[TEERIGHT];
|
||||
ACS_LTEE = _cursgraftable[TEELEFT];
|
||||
ACS_BTEE = _cursgraftable[TEEHEAD];
|
||||
ACS_TTEE = _cursgraftable[TEENORMAL];
|
||||
ACS_HLINE = _cursgraftable[MIDLINE];
|
||||
ACS_VLINE = _cursgraftable[VERTLINE];
|
||||
ACS_PLUS = _cursgraftable[CROSS];
|
||||
ACS_S1 = _cursgraftable[UPLINE];
|
||||
ACS_S9 = _cursgraftable[DOWNLINE];
|
||||
ACS_DIAMOND = _cursgraftable[DIAMOND];
|
||||
ACS_CKBOARD = _cursgraftable[GREYSQUARE];
|
||||
ACS_DEGREE = _cursgraftable[DEGREE];
|
||||
ACS_PLMINUS = _cursgraftable[PLUSMINUS];
|
||||
ACS_BULLET = 'o'; /* where the hell is a bullet defined in
|
||||
* termcap ??? */
|
||||
ACS_LARROW = _cursgraftable[LEFTARROW];
|
||||
ACS_RARROW = _cursgraftable[RIGHTARROW];
|
||||
ACS_DARROW = _cursgraftable[DOWNARROW];
|
||||
ACS_UARROW = _cursgraftable[UPARROW];
|
||||
ACS_BOARD = _cursgraftable[EMPTYSQUARE];
|
||||
ACS_LANTERN = _cursgraftable[LATERN];
|
||||
ACS_BLOCK = _cursgraftable[FULLSQUARE];
|
||||
/* Wow, I got it! */
|
||||
return OK;
|
||||
}
|
||||
|
||||
void gettmode()
|
||||
{
|
||||
tcgetattr(0, &_orig_tty);
|
||||
tcgetattr(0, &_tty);
|
||||
_cursvar.echoit = (_tty.c_lflag & ECHO) != 0;
|
||||
_cursvar.rawmode = (_tty.c_lflag & (ICANON|ISIG)) == 0;
|
||||
_cursvar.cbrkmode = (_tty.c_lflag & (ICANON|ISIG)) == ISIG;
|
||||
NONL = (_tty.c_iflag & ICRNL) != 0;
|
||||
}
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
/* Constants */
|
||||
#define _SUBWIN 1 /* window is a subwindow */
|
||||
#define _ENDLINE 2 /* last winline is last screen line */
|
||||
#define _FULLWIN 4 /* window fills screen */
|
||||
#define _SCROLLWIN 8 /* window lwr rgt is screen lwr rgt */
|
||||
|
||||
#define _NO_CHANGE -1 /* flags line edge unchanged */
|
||||
#define _BREAKCHAR 0x03 /* ^C character */
|
||||
#define _DCCHAR 0x08 /* Delete Char char (BS) */
|
||||
#define _DLCHAR 0x1b /* Delete Line char (ESC) */
|
||||
#define _GOCHAR 0x11 /* ^Q character */
|
||||
#define _PRINTCHAR 0x10 /* ^P character */
|
||||
#define _STOPCHAR 0x13 /* ^S character */
|
||||
#define NUNGETCH 10 /* max # chars to ungetch() */
|
||||
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
/* Character mask definitions. */
|
||||
#define CHR_MSK ((int) 0x00ff) /* ASCIIZ character mask */
|
||||
#define ATR_MSK ((int) 0xff00) /* attribute mask */
|
||||
#define ATR_NRM ((int) 0x0000) /* no special attributes */
|
||||
|
||||
/* Type declarations. */
|
||||
|
||||
typedef struct {
|
||||
WINDOW *tmpwin; /* window used for updates */
|
||||
int cursrow; /* position of physical cursor */
|
||||
int curscol;
|
||||
bool rawmode;
|
||||
bool cbrkmode;
|
||||
bool echoit;
|
||||
} cursv;
|
||||
|
||||
/* External variables */
|
||||
extern cursv _cursvar; /* curses variables */
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
#include <termcap.h>
|
||||
|
||||
int endwin()
|
||||
{
|
||||
extern char *me;
|
||||
|
||||
curs_set(1);
|
||||
poscur(LINES - 1, 0);
|
||||
refresh();
|
||||
tputs(me, 1, outc);
|
||||
delwin(stdscr);
|
||||
delwin(curscr);
|
||||
delwin(_cursvar.tmpwin);
|
||||
resetty();
|
||||
return(OK);
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
#include <termcap.h>
|
||||
|
||||
extern char *bl, *vb;
|
||||
|
||||
/* Flash() flashes the terminal screen. */
|
||||
void flash()
|
||||
{
|
||||
if (vb)
|
||||
tputs(vb, 1, outc);
|
||||
else if (bl)
|
||||
tputs(bl, 1, outc);
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
/* initscr.c - initialize the curses library */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
WINDOW *initscr()
|
||||
{
|
||||
char *term;
|
||||
|
||||
if ((term = getenv("TERM")) == NULL) return NULL;
|
||||
setterm(term);
|
||||
gettmode();
|
||||
if ((_cursvar.tmpwin = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
|
||||
if ((curscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
|
||||
if ((stdscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
|
||||
clearok(curscr, TRUE);
|
||||
return(stdscr);
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Longname() returns a pointer to a string describing the */
|
||||
/* User terminal. */
|
||||
/****************************************************************/
|
||||
|
||||
char *longname()
|
||||
{
|
||||
return("not implemented");
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Wmove() moves the cursor in window 'win' to position (x,y). */
|
||||
/****************************************************************/
|
||||
|
||||
int wmove(win, y, x)
|
||||
WINDOW *win;
|
||||
int y;
|
||||
int x;
|
||||
{
|
||||
if ((x<0) || (x>win->_maxx) || (y<win->_regtop) || (y>win->_regbottom))
|
||||
return(ERR);
|
||||
win->_curx = x;
|
||||
win->_cury = y;
|
||||
return(OK);
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvcur(oldy,oldx,newy,newx) the display cursor to <newy,newx> */
|
||||
/****************************************************************/
|
||||
|
||||
int mvcur(oldy, oldx, newy, newx)
|
||||
int oldy;
|
||||
int oldx;
|
||||
int newy;
|
||||
int newx;
|
||||
{
|
||||
if ((newy >= LINES) || (newx >= COLS) || (newy < 0) || (newx < 0))
|
||||
return(ERR);
|
||||
poscur(newy, newx);
|
||||
_cursvar.cursrow = newy;
|
||||
_cursvar.curscol = newx;
|
||||
return(OK);
|
||||
}
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
#include <stdlib.h>
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Makenew() allocates all data for a new window except the */
|
||||
/* Actual lines themselves. */
|
||||
/****************************************************************/
|
||||
|
||||
_PROTOTYPE(static WINDOW *makenew, (int nlines, int ncols, int begy,int begx));
|
||||
|
||||
static WINDOW *makenew(num_lines, num_columns, begy, begx)
|
||||
int num_lines, num_columns, begy, begx;
|
||||
{
|
||||
int i;
|
||||
WINDOW *win;
|
||||
|
||||
/* Allocate the window structure itself */
|
||||
if ((win = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
|
||||
return((WINDOW *) ERR);
|
||||
|
||||
/* Allocate the line pointer array */
|
||||
if ((win->_line = (int **) calloc(num_lines, sizeof(int *))) == NULL) {
|
||||
free(win);
|
||||
return((WINDOW *) ERR);
|
||||
}
|
||||
|
||||
/* Allocate the minchng and maxchng arrays */
|
||||
if ((win->_minchng = (int *) calloc(num_lines, sizeof(int))) == NULL) {
|
||||
free(win);
|
||||
free(win->_line);
|
||||
return((WINDOW *) ERR);
|
||||
}
|
||||
if ((win->_maxchng = (int *) calloc(num_lines, sizeof(int))) == NULL) {
|
||||
free(win);
|
||||
free(win->_line);
|
||||
free(win->_minchng);
|
||||
return((WINDOW *) ERR);
|
||||
}
|
||||
|
||||
/* Initialize window variables */
|
||||
win->_curx = 0;
|
||||
win->_cury = 0;
|
||||
win->_maxy = num_lines - 1;
|
||||
win->_maxx = num_columns - 1;
|
||||
win->_begy = begy;
|
||||
win->_begx = begx;
|
||||
win->_flags = 0;
|
||||
win->_attrs = ATR_NRM;
|
||||
win->_tabsize = 8;
|
||||
win->_clear = FALSE;
|
||||
win->_leave = FALSE;
|
||||
win->_scroll = FALSE;
|
||||
win->_nodelay = FALSE;
|
||||
win->_keypad = FALSE;
|
||||
win->_regtop = 0;
|
||||
win->_regbottom = num_lines - 1;
|
||||
|
||||
/* Init to say window unchanged */
|
||||
for (i = 0; i < num_lines; i++) {
|
||||
win->_minchng[i] = 0;
|
||||
win->_maxchng[i] = num_columns - 1;
|
||||
}
|
||||
|
||||
/* Set flags for window properties */
|
||||
if ((begy + num_lines) == LINES) {
|
||||
win->_flags |= _ENDLINE;
|
||||
if ((begx == 0) && (num_columns == COLS) && (begy == 0))
|
||||
win->_flags |= _FULLWIN;
|
||||
} /* if */
|
||||
if (((begy + num_lines) == LINES) && ((begx + num_columns) == COLS))
|
||||
win->_flags |= _SCROLLWIN;
|
||||
return(win);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Newwin() creates a new window with size num_lines * num_co- */
|
||||
/* Lumns, and origin begx,begy relative to the SCREEN. Special */
|
||||
/* Case: if num_lines and/or num_columns is 0, the remainder of */
|
||||
/* The screen is used. */
|
||||
/****************************************************************/
|
||||
WINDOW *newwin(num_lines, num_columns, begy, begx)
|
||||
int num_lines, num_columns, begy, begx;
|
||||
{
|
||||
WINDOW *win;
|
||||
int *ptr;
|
||||
int i, j;
|
||||
|
||||
if (num_lines == 0) num_lines = LINES - begy;
|
||||
if (num_columns == 0) num_columns = COLS - begx;
|
||||
if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR)
|
||||
return((WINDOW *) ERR);
|
||||
for (i = 0; i < num_lines; i++) { /* make and clear the lines */
|
||||
if ((win->_line[i] = (int *)calloc(num_columns, sizeof(int))) == NULL){
|
||||
for (j = 0; j < i; j++) /* if error, free all the data */
|
||||
free(win->_line[j]);
|
||||
free(win->_minchng);
|
||||
free(win->_maxchng);
|
||||
free(win->_line);
|
||||
free(win);
|
||||
return((WINDOW *) ERR);
|
||||
} else {
|
||||
for (ptr = win->_line[i]; ptr < win->_line[i] + num_columns;)
|
||||
*ptr++ = ' ' | ATR_NRM;
|
||||
}
|
||||
}
|
||||
return(win);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Subwin() creates a sub-window in the 'orig' window, with */
|
||||
/* Size num_lines * num_columns, and with origin begx, begy */
|
||||
/* Relative to the SCREEN. Special case: if num_lines and/or */
|
||||
/* Num_columns is 0, the remainder of the original window is */
|
||||
/* Used. The subwindow uses the original window's line buffers */
|
||||
/* To store it's own lines. */
|
||||
/****************************************************************/
|
||||
WINDOW *subwin(orig, num_lines, num_columns, begy, begx)
|
||||
WINDOW *orig;
|
||||
int num_lines, num_columns, begy, begx;
|
||||
{
|
||||
WINDOW *win;
|
||||
int i, j, k;
|
||||
|
||||
/* Make sure window fits inside the original one */
|
||||
if (begy < orig->_begy || begx < orig->_begx ||
|
||||
(begy + num_lines) > (orig->_begy + orig->_maxy) ||
|
||||
(begx + num_columns) > (orig->_begx + orig->_maxx) )
|
||||
return((WINDOW *) ERR);
|
||||
|
||||
if (num_lines == 0) num_lines = orig->_maxy - (begy - orig->_begy);
|
||||
if (num_columns == 0) num_columns = orig->_maxx - (begx - orig->_begx);
|
||||
if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR)
|
||||
return((WINDOW *) ERR);
|
||||
|
||||
/* Set line pointers the same as in the original window */
|
||||
j = begy - orig->_begy;
|
||||
k = begx - orig->_begx;
|
||||
for (i = 0; i < num_lines; i++) win->_line[i] = (orig->_line[j++]) + k;
|
||||
win->_flags |= _SUBWIN;
|
||||
return(win);
|
||||
}
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
static bool hasold = FALSE; /* for remembering old cursor type */
|
||||
static int oldmode;
|
||||
|
||||
/****************************************************************/
|
||||
/* Idlok() is used to set flag for using the terminal insert/ */
|
||||
/* Delete line capabilities. This is not relevant for the PC */
|
||||
/* Version of curses, and thus nothing is done. */
|
||||
/****************************************************************/
|
||||
void idlok(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Clearok() marks window 'win' to cause screen clearing and */
|
||||
/* Redraw the next time a refresh is done. */
|
||||
/****************************************************************/
|
||||
void clearok(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
if (win == curscr)
|
||||
_cursvar.tmpwin->_clear = flag;
|
||||
else
|
||||
win->_clear = flag;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Leaveok() marks window 'win' to allow the update routines */
|
||||
/* To leave the hardware cursor where it happens to be at the */
|
||||
/* End of update. Usually used in combination with cursoff(). */
|
||||
/****************************************************************/
|
||||
|
||||
void leaveok(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
win->_leave = flag;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Scrollok() marks window 'win' to allow the scrolling region */
|
||||
/* Of it to actually scroll. */
|
||||
/****************************************************************/
|
||||
void scrollok(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
win->_scroll = flag;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Nodelay() marks the window to make character input non- */
|
||||
/* Waiting, i.e. if there is no character to get, -1 will be */
|
||||
/* Returned. */
|
||||
/****************************************************************/
|
||||
void nodelay(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
win->_nodelay = flag;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Keypad() marks window 'win' to use the special keypad mode. */
|
||||
/****************************************************************/
|
||||
void keypad(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
win->_keypad = flag;
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Meta() allows use of any alternate character set allowed by */
|
||||
/* The terminal. We always allow this on the PC, so this one */
|
||||
/* Does nothing. */
|
||||
/****************************************************************/
|
||||
void meta(win, flag)
|
||||
WINDOW *win;
|
||||
bool flag;
|
||||
{
|
||||
}
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
/****************************************************************/
|
||||
/* Overlay() and overwrite() functions of the PCcurses package */
|
||||
/* */
|
||||
/****************************************************************/
|
||||
/* This version of curses is based on ncurses, a curses version */
|
||||
/* Originally written by Pavel Curtis at Cornell University. */
|
||||
/* I have made substantial changes to make it run on IBM PC's, */
|
||||
/* And therefore consider myself free to make it public domain. */
|
||||
/* Bjorn Larsson (...mcvax!enea!infovax!bl) */
|
||||
/****************************************************************/
|
||||
/* 1.0: Release: 870515 */
|
||||
/****************************************************************/
|
||||
/* Modified to run under the MINIX operating system by Don Cope */
|
||||
/* These changes are also released into the public domain. */
|
||||
/* 900906 */
|
||||
/****************************************************************/
|
||||
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Overlay() overwrites 'win1' upon 'win2', with origins alig- */
|
||||
/* Ned. Overlay is transparent; blanks from 'win1' are not */
|
||||
/* Copied to 'win2'. */
|
||||
/****************************************************************/
|
||||
void overlay(win1, win2)
|
||||
WINDOW *win1, *win2;
|
||||
{
|
||||
int *minchng;
|
||||
int *maxchng;
|
||||
int *w1ptr;
|
||||
int *w2ptr;
|
||||
int attrs;
|
||||
int col;
|
||||
int line;
|
||||
int last_line;
|
||||
int last_col;
|
||||
|
||||
last_col = min(win1->_maxx, win2->_maxx);
|
||||
last_line = min(win1->_maxy, win2->_maxy);
|
||||
attrs = win2->_attrs & ATR_MSK;
|
||||
minchng = win2->_minchng;
|
||||
maxchng = win2->_maxchng;
|
||||
|
||||
for (line = 0; line <= last_line; line++) {
|
||||
register short fc, lc = 0;
|
||||
w1ptr = win1->_line[line];
|
||||
w2ptr = win2->_line[line];
|
||||
fc = _NO_CHANGE;
|
||||
for (col = 0; col <= last_col; col++) {
|
||||
if ((*w1ptr & CHR_MSK) != ' ') {
|
||||
*w2ptr = (*w1ptr & CHR_MSK) | attrs;
|
||||
if (fc == _NO_CHANGE) fc = col;
|
||||
lc = col;
|
||||
}
|
||||
w1ptr++;
|
||||
w2ptr++;
|
||||
}
|
||||
|
||||
if (*minchng == _NO_CHANGE) {
|
||||
*minchng = fc;
|
||||
*maxchng = lc;
|
||||
} else if (fc != _NO_CHANGE) {
|
||||
if (fc < *minchng) *minchng = fc;
|
||||
if (lc > *maxchng) *maxchng = lc;
|
||||
}
|
||||
minchng++;
|
||||
maxchng++;
|
||||
} /* for */
|
||||
} /* overlay */
|
||||
|
||||
/****************************************************************/
|
||||
/* Overwrite() overwrites 'win1' upon 'win2', with origins */
|
||||
/* Aligned. Overwrite is non-transparent; blanks from 'win1' */
|
||||
/* Are copied to 'win2'. */
|
||||
/****************************************************************/
|
||||
void overwrite(win1, win2)
|
||||
WINDOW *win1, *win2;
|
||||
{
|
||||
int *minchng;
|
||||
int *maxchng;
|
||||
int *w1ptr;
|
||||
int *w2ptr;
|
||||
int attrs;
|
||||
int col;
|
||||
int line;
|
||||
int last_line;
|
||||
int last_col;
|
||||
|
||||
last_col = min(win1->_maxx, win2->_maxx);
|
||||
last_line = min(win1->_maxy, win2->_maxy);
|
||||
attrs = win2->_attrs & ATR_MSK;
|
||||
minchng = win2->_minchng;
|
||||
maxchng = win2->_maxchng;
|
||||
|
||||
for (line = 0; line <= last_line; line++) {
|
||||
register short fc, lc = 0;
|
||||
|
||||
w1ptr = win1->_line[line];
|
||||
w2ptr = win2->_line[line];
|
||||
fc = _NO_CHANGE;
|
||||
|
||||
for (col = 0; col <= last_col; col++) {
|
||||
if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK)) {
|
||||
*w2ptr = (*w1ptr & CHR_MSK) | attrs;
|
||||
|
||||
if (fc == _NO_CHANGE) fc = col;
|
||||
lc = col;
|
||||
}
|
||||
w1ptr++;
|
||||
w2ptr++;
|
||||
} /* for */
|
||||
|
||||
if (*minchng == _NO_CHANGE) {
|
||||
*minchng = fc;
|
||||
*maxchng = lc;
|
||||
} else if (fc != _NO_CHANGE) {
|
||||
if (fc < *minchng) *minchng = fc;
|
||||
if (lc > *maxchng) *maxchng = lc;
|
||||
}
|
||||
minchng++;
|
||||
maxchng++;
|
||||
}
|
||||
}
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
#include <string.h>
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
static char printscanbuf[513]; /* buffer used during I/O */
|
||||
|
||||
/****************************************************************/
|
||||
/* Wprintw(win,fmt,args) does a printf() in window 'win'. */
|
||||
/****************************************************************/
|
||||
int wprintw(WINDOW *win, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsprintf(printscanbuf, fmt, args);
|
||||
if (waddstr(win, printscanbuf) == ERR) return(ERR);
|
||||
return(strlen(printscanbuf));
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Printw(fmt,args) does a printf() in stdscr. */
|
||||
/****************************************************************/
|
||||
int printw(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsprintf(printscanbuf, fmt, args);
|
||||
if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
|
||||
return(strlen(printscanbuf));
|
||||
} /* printw */
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */
|
||||
/* tion, then does a printf() in stdscr. */
|
||||
/****************************************************************/
|
||||
int mvprintw(int y, int x, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
if (wmove(stdscr, y, x) == ERR) return(ERR);
|
||||
vsprintf(printscanbuf, fmt, args);
|
||||
if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
|
||||
return(strlen(printscanbuf));
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */
|
||||
/* A new position, then does a printf() in window 'win'. */
|
||||
/****************************************************************/
|
||||
int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
if (wmove(win, y, x) == ERR) return(ERR);
|
||||
vsprintf(printscanbuf, fmt, args);
|
||||
if (waddstr(win, printscanbuf) == ERR) return(ERR);
|
||||
return(strlen(printscanbuf));
|
||||
} /* mvwprintw */
|
||||
|
||||
/****************************************************************/
|
||||
/* Wscanw(win,fmt,args) gets a string via window 'win', then */
|
||||
/* Scans the string using format 'fmt' to extract the values */
|
||||
/* And put them in the variables pointed to the arguments. */
|
||||
/****************************************************************/
|
||||
int wscanw(WINDOW *win, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
wrefresh(win); /* set cursor */
|
||||
if (wgetstr(win, printscanbuf) == ERR) /* get string */
|
||||
return(ERR);
|
||||
return(vsscanf(printscanbuf, fmt, args));
|
||||
} /* wscanw */
|
||||
|
||||
/****************************************************************/
|
||||
/* Scanw(fmt,args) gets a string via stdscr, then scans the */
|
||||
/* String using format 'fmt' to extract the values and put them */
|
||||
/* In the variables pointed to the arguments. */
|
||||
/****************************************************************/
|
||||
int scanw(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
wrefresh(stdscr); /* set cursor */
|
||||
if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
|
||||
return(ERR);
|
||||
return(vsscanf(printscanbuf, fmt, args));
|
||||
} /* scanw */
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */
|
||||
/* Tion, then gets a string via stdscr and scans the string */
|
||||
/* Using format 'fmt' to extract the values and put them in the */
|
||||
/* Variables pointed to the arguments. */
|
||||
/****************************************************************/
|
||||
int mvscanw(int y, int x, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
if (wmove(stdscr, y, x) == ERR) return(ERR);
|
||||
wrefresh(stdscr); /* set cursor */
|
||||
if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
|
||||
return(ERR);
|
||||
return(vsscanf(printscanbuf, fmt, args));
|
||||
} /* mvscanw */
|
||||
|
||||
/****************************************************************/
|
||||
/* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */
|
||||
/* New position, then gets a string via 'win' and scans the */
|
||||
/* String using format 'fmt' to extract the values and put them */
|
||||
/* In the variables pointed to the arguments. */
|
||||
/****************************************************************/
|
||||
int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
if (wmove(win, y, x) == ERR) return(ERR);
|
||||
wrefresh(win); /* set cursor */
|
||||
if (wgetstr(win, printscanbuf) == ERR) /* get string */
|
||||
return(ERR);
|
||||
return(vsscanf(printscanbuf, fmt, args));
|
||||
} /* mvwscanw */
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
/* refresh.c */
|
||||
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/* Wrefresh() updates window win's area of the physical screen. */
|
||||
void wrefresh(win)
|
||||
WINDOW *win;
|
||||
{
|
||||
if (win == curscr)
|
||||
curscr->_clear = TRUE;
|
||||
else
|
||||
wnoutrefresh(win);
|
||||
doupdate();
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Wnoutrefresh() updates the image of the desired screen, */
|
||||
/* Without doing physical update (copies window win's image to */
|
||||
/* The _cursvar.tmpwin window, which is hidden from the user). */
|
||||
/****************************************************************/
|
||||
|
||||
void wnoutrefresh(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int *dst; /* start destination in temp window */
|
||||
register int *end; /* end destination in temp window */
|
||||
register int *src; /* source in user window */
|
||||
register int first; /* first changed char on line */
|
||||
register int last; /* last changed char on line */
|
||||
WINDOW *nscr;
|
||||
int begy; /* window's place on screen */
|
||||
int begx;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
nscr = _cursvar.tmpwin;
|
||||
begy = win->_begy;
|
||||
begx = win->_begx;
|
||||
|
||||
for (i = 0, j = begy; i <= win->_maxy; i++, j++) {
|
||||
if (win->_minchng[i] != _NO_CHANGE) {
|
||||
first = win->_minchng[i];
|
||||
last = win->_maxchng[i];
|
||||
dst = &(nscr->_line[j][begx + first]);
|
||||
end = &(nscr->_line[j][begx + last]);
|
||||
src = &(win->_line[i][first]);
|
||||
|
||||
while (dst <= end) /* copy user line to temp window */
|
||||
*dst++ = *src++;
|
||||
|
||||
first += begx; /* nscr's min/max change positions */
|
||||
last += begx;
|
||||
|
||||
if ((nscr->_minchng[j] == _NO_CHANGE) || (nscr->_minchng[j] > first))
|
||||
nscr->_minchng[j] = first;
|
||||
if (last > nscr->_maxchng[j]) nscr->_maxchng[j] = last;
|
||||
|
||||
win->_minchng[i] = _NO_CHANGE; /* updated now */
|
||||
} /* if */
|
||||
win->_maxchng[i] = _NO_CHANGE; /* updated now */
|
||||
} /* for */
|
||||
|
||||
if (win->_clear) {
|
||||
win->_clear = FALSE;
|
||||
nscr->_clear = TRUE;
|
||||
} /* if */
|
||||
if (!win->_leave) {
|
||||
nscr->_cury = win->_cury + begy;
|
||||
nscr->_curx = win->_curx + begx;
|
||||
} /* if */
|
||||
} /* wnoutrefresh */
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
/****************************************************************/
|
||||
/* Wsetscrreg() routine of the PCcurses package */
|
||||
/* */
|
||||
/****************************************************************/
|
||||
/* This version of curses is based on ncurses, a curses version */
|
||||
/* Originally written by Pavel Curtis at Cornell University. */
|
||||
/* I have made substantial changes to make it run on IBM PC's, */
|
||||
/* And therefore consider myself free to make it public domain. */
|
||||
/* Bjorn Larsson (...mcvax!enea!infovax!bl) */
|
||||
/****************************************************************/
|
||||
/* 1.0: Release: 870515 */
|
||||
/****************************************************************/
|
||||
/* Modified to run under the MINIX operating system by Don Cope */
|
||||
/* These changes are also released into the public domain. */
|
||||
/* 900906 */
|
||||
/****************************************************************/
|
||||
|
||||
#include <curses.h>
|
||||
#include "curspriv.h"
|
||||
|
||||
/****************************************************************/
|
||||
/* Wsetscrreg() set the scrolling region of window 'win' to in- */
|
||||
/* Clude all lines between 'top' and 'bottom'. */
|
||||
/****************************************************************/
|
||||
|
||||
int wsetscrreg(win, top, bottom)
|
||||
WINDOW *win;
|
||||
int top;
|
||||
int bottom;
|
||||
{
|
||||
if ((0 <= top) &&
|
||||
(top <= win->_cury)
|
||||
&&
|
||||
(win->_cury <= bottom)
|
||||
&&
|
||||
(bottom <= win->_maxy)
|
||||
) {
|
||||
win->_regtop = top;
|
||||
win->_regbottom = bottom;
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* If */
|
||||
else
|
||||
return(ERR);
|
||||
} /* wsetscrreg */
|
||||
|
||||
/****************************************************************/
|
||||
/* Setscrreg() set the scrolling region of stdscr to include */
|
||||
/* All lines between 'top' and 'bottom'. */
|
||||
/****************************************************************/
|
||||
|
||||
int setscrreg(top, bottom)
|
||||
int top;
|
||||
int bottom;
|
||||
{
|
||||
return(wsetscrreg(stdscr, top, bottom));
|
||||
} /* setscrreg */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user