Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4972 → Rev 4973

/programs/develop/libraries/menuetlibc/src/Make.rules
0,0 → 1,64
include $(MENUETDEV)/osrules.mak
 
.SUFFIXES: .asm;
 
AS = as
NASM = nasm
CPP = cpp
 
DEBUG = 0
 
.c.o:
$(MGCC) $*.c $*.o $(CFLAGS) $(GCC32OPT)
 
.cpp.o:
$(MGPP) $*.cpp $*.o $(CPPFLAGS) $(GCC32OPT)
 
.asm.o:
$(NASM) $*.asm -o $*.o -f $(ASMFMT)
.s.o:
$(CPP) -nostdinc -I$(MENUETDEV)/include $*.s -o $*.sx $(CSFLAGS) -DMENUETDEV=$(MENUETDEV) -D__DEV_CONFIG_H=\"$(MENUETDEV)/config.h\"
as $*.sx $(AS32OPT) -o $*.o
$(RM) $*.sx
 
ATHIS_LIBC_OBJS += $(subst .c,.o,$(filter %.c,$(THIS_SRCS))) \
$(subst .s,.o,$(filter %.s,$(THIS_SRCS))) \
$(subst .cpp,.o,$(filter %.cpp,$(THIS_SRCS)))
 
THIS_LIBC_OBJS = $(addprefix $(CURDIR)/,$(ATHIS_LIBC_OBJS))
 
export MENUET_LIBC_OBJS += $(THIS_LIBC_OBJS)
 
all: making check_ldepend $(ATHIS_LIBC_OBJS)
@$(MENUET_LIBC_TOPDIR)/m_echo $(MENUET_LIBC_TOPDIR)/tmp_make $(THIS_LIBC_OBJS)
making:
@echo --- Making in $(CURDIR) ---
 
clean:
$(RM) $(ATHIS_LIBC_OBJS)
ifdef ON_MINGW
@echo # nothing> ./ldepend
else
@echo "# nothing" > ./ldepend
endif
 
ifdef DJDIR
depend:
echo $(THIS_SRCS) > __tmp.1
$(MMKDEP) @__tmp.1 > ./ldepend
$(RM) __tmp.1
else
depend:
$(MMKDEP) $(THIS_SRCS) > ./ldepend
endif
 
ifeq ($(wildcard ./ldepend),)
check_ldepend:
echo Warning: ldepend not present in $(CURDIR)
else
check_ldepend:
 
include ldepend
endif
/programs/develop/libraries/menuetlibc/src/Makefile
0,0 → 1,48
include $(MENUETDEV)/osrules.mak
 
MENUET_LIBC_OBJS :=
MENUET_LIBC_TOPDIR := $(CURDIR)
 
export MENUET_LIBC_OBJS
export MENUET_LIBC_TOPDIR
 
all: m_echo$(EXESUFFIX) mks$(EXESUFFIX)
make -C libc
make -C libcon2 mk_lib
make -C libcpp mk_lib
make -C libm mk_lib
make -C libmgfx mk_lib
make -C libmcoff
$(RM) m_echo$(EXESUFFIX)
$(RM) tmp_make
$(RM) mks$(EXESUFFIX)
@echo ---------------------------------------------------------
@echo Libraries for MenuetOS/KolibriOS were successfully built
@echo ---------------------------------------------------------
 
dll: m_echo
make -C libcon2 dll
make -C libcpp dll
make -C libm dll
make -C libmgfx dll
 
m_echo$(EXESUFFIX): m_echo.c
gcc m_echo.c -o m_echo$(EXESUFFIX) -s -O2 -fomit-frame-pointer
mks$(EXESUFFIX): mks.c
gcc mks.c -o mks$(EXESUFFIX) -s -O2 -fomit-frame-pointer
 
clean:
make -C libc clean
make -C libcon2 clean
make -C libcpp clean
make -C libm clean
make -C libmgfx clean
make -C libmcoff clean
$(RM) tmp_make m_echo$(EXESUFFIX) mks$(EXESUFFIX)
 
depend:
make -C libc depend
make -C libcon2 depend
make -C libcpp depend
make -C libm depend
make -C libmgfx depend
/programs/develop/libraries/menuetlibc/src/libc/Makefile
0,0 → 1,53
include $(MENUETDEV)/osrules.mak
 
all: process_subdirs
make -f Makefile-link OUTFILE="libc.a"
ifdef ON_MINGW
copy libc.a $(MENUETDEV)\lib
del libc.a
else
mv libc.a $(MENUETDEV)/lib
endif
 
process_subdirs:
@$(D_ECHO) > ../tmp_make
make -C ansi
make -C ansif
make -C compat
make -C crt0
make -C dos
make -C fsext
make -C menuetos
make -C net
make -C pc_hw
make -C posix
make -C termios
make -C emu_layer
 
clean:
make -C ansi clean
make -C ansif clean
make -C compat clean
make -C crt0 clean
make -C dos clean
make -C fsext clean
make -C menuetos clean
make -C net clean
make -C pc_hw clean
make -C posix clean
make -C termios clean
make -C emu_layer clean
 
depend:
make -C ansi depend
make -C ansif depend
make -C compat depend
make -C crt0 depend
make -C dos depend
make -C fsext depend
make -C menuetos depend
make -C net depend
make -C pc_hw depend
make -C posix depend
make -C termios depend
make -C emu_layer depend
/programs/develop/libraries/menuetlibc/src/libc/Makefile-link
0,0 → 1,10
include $(MENUETDEV)/osrules.mak
 
all:
ifdef ON_MINGW
..\mks $(OUTFILE) < ..\tmp_make > tmp_make.ars
else
../mks $(OUTFILE) < ../tmp_make > tmp_make.ars
endif
ar -M < tmp_make.ars
$(RM) tmp_make.ars
/programs/develop/libraries/menuetlibc/src/libc/ansi/Makefile
0,0 → 1,40
SUBDIRS = assert ctype errno locale math setjmp stdio stdlib string time
 
all: process_subdirs
 
process_subdirs:
make -C assert
make -C ctype
make -C errno
make -C locale
make -C math
make -C setjmp
make -C stdio
make -C stdlib
make -C string
make -C time
 
 
clean:
make -C assert clean
make -C ctype clean
make -C errno clean
make -C locale clean
make -C math clean
make -C setjmp clean
make -C stdio clean
make -C stdlib clean
make -C string clean
make -C time clean
 
depend:
make -C assert depend
make -C ctype depend
make -C errno depend
make -C locale depend
make -C math depend
make -C setjmp depend
make -C stdio depend
make -C stdlib depend
make -C string depend
make -C time depend
/programs/develop/libraries/menuetlibc/src/libc/ansi/assert/Makefile
0,0 → 1,3
THIS_SRCS = assert.c unimplemented.c debug.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/assert/assert.c
0,0 → 1,11
#include<assert.h>
#include<menuet/os.h>
#include <stdlib.h>
 
void __dj_assert(const char *msg, const char *file, int line)
{
__libclog_printf("Assertion failed at line %u in file %s\n",
line,file);
__libclog_printf("Assertion: '%s'\n",msg);
exit(-1);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/assert/debug.c
0,0 → 1,45
#include<menuet/os.h>
#include<stdlib.h>
#include<stdarg.h>
#include<stdio.h>
 
static inline int vdprintf_help(char c)
{
int d0;
if(c=='\n')
{
c='\r';
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
c='\n';
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
return 0;
}
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
return 0 ;
}
 
static char log_buf[1024];
 
static char xputs(char * s)
{
for(;*s;s++) vdprintf_help(*s);
}
 
int __libclog_vprintf(const char *fmt, va_list args)
{
int ret_val;
ret_val = vsprintf(log_buf,fmt,args);
xputs(log_buf);
__menuet__delay100(1);
return ret_val;
}
 
int __libclog_printf(const char * fmt,...)
{
int v;
va_list ap;
va_start(ap,fmt);
v=__libclog_vprintf(fmt,ap);
__menuet__delay100(1);
return v;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/assert/unimplemented.c
0,0 → 1,9
#include<assert.h>
#include<menuet/os.h>
 
void __dj_unimp(const char *fn)
{
__libclog_printf(fn);
exit(-1);
for(;;);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/Makefile
0,0 → 1,5
THIS_SRCS = ct_flags.c ct_lower.c ct_upper.c isalnum.c isalpha.c isascii.c \
iscntrl.c isdigit.c isgraph.c islower.c isprint.c ispunct.c \
isspace.c isupper.c isxdigit.c toascii.c tolower.c toupper.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/ct_flags.c
0,0 → 1,263
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
unsigned short __dj_ctype_flags[] = {
0, /* CTRL+?, 0xffff */
__dj_ISCNTRL, /* CTRL+@, 0x00 */
__dj_ISCNTRL, /* CTRL+A, 0x01 */
__dj_ISCNTRL, /* CTRL+B, 0x02 */
__dj_ISCNTRL, /* CTRL+C, 0x03 */
__dj_ISCNTRL, /* CTRL+D, 0x04 */
__dj_ISCNTRL, /* CTRL+E, 0x05 */
__dj_ISCNTRL, /* CTRL+F, 0x06 */
__dj_ISCNTRL, /* CTRL+G, 0x07 */
__dj_ISCNTRL, /* CTRL+H, 0x08 */
__dj_ISCNTRL | __dj_ISSPACE, /* CTRL+I, 0x09 */
__dj_ISCNTRL | __dj_ISSPACE, /* CTRL+J, 0x0a */
__dj_ISCNTRL | __dj_ISSPACE, /* CTRL+K, 0x0b */
__dj_ISCNTRL | __dj_ISSPACE, /* CTRL+L, 0x0c */
__dj_ISCNTRL | __dj_ISSPACE, /* CTRL+M, 0x0d */
__dj_ISCNTRL, /* CTRL+N, 0x0e */
__dj_ISCNTRL, /* CTRL+O, 0x0f */
__dj_ISCNTRL, /* CTRL+P, 0x10 */
__dj_ISCNTRL, /* CTRL+Q, 0x11 */
__dj_ISCNTRL, /* CTRL+R, 0x12 */
__dj_ISCNTRL, /* CTRL+S, 0x13 */
__dj_ISCNTRL, /* CTRL+T, 0x14 */
__dj_ISCNTRL, /* CTRL+U, 0x15 */
__dj_ISCNTRL, /* CTRL+V, 0x16 */
__dj_ISCNTRL, /* CTRL+W, 0x17 */
__dj_ISCNTRL, /* CTRL+X, 0x18 */
__dj_ISCNTRL, /* CTRL+Y, 0x19 */
__dj_ISCNTRL, /* CTRL+Z, 0x1a */
__dj_ISCNTRL, /* CTRL+[, 0x1b */
__dj_ISCNTRL, /* CTRL+\, 0x1c */
__dj_ISCNTRL, /* CTRL+], 0x1d */
__dj_ISCNTRL, /* CTRL+^, 0x1e */
__dj_ISCNTRL, /* CTRL+_, 0x1f */
__dj_ISPRINT | __dj_ISSPACE, /* ` ', 0x20 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `!', 0x21 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* 0x22 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `#', 0x23 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `$', 0x24 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `%', 0x25 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `&', 0x26 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* 0x27 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `(', 0x28 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `)', 0x29 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `*', 0x2a */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `+', 0x2b */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `,', 0x2c */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `-', 0x2d */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `.', 0x2e */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `/', 0x2f */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `0', 0x30 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `1', 0x31 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `2', 0x32 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `3', 0x33 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `4', 0x34 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `5', 0x35 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `6', 0x36 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `7', 0x37 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `8', 0x38 */
__dj_ISALNUM | __dj_ISDIGIT | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISXDIGIT, /* `9', 0x39 */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `:', 0x3a */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `;', 0x3b */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `<', 0x3c */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `=', 0x3d */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `>', 0x3e */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `?', 0x3f */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `@', 0x40 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `A', 0x41 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `B', 0x42 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `C', 0x43 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `D', 0x44 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `E', 0x45 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER | __dj_ISXDIGIT, /* `F', 0x46 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `G', 0x47 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `H', 0x48 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `I', 0x49 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `J', 0x4a */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `K', 0x4b */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `L', 0x4c */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `M', 0x4d */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `N', 0x4e */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `O', 0x4f */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `P', 0x50 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `Q', 0x51 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `R', 0x52 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `S', 0x53 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `T', 0x54 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `U', 0x55 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `V', 0x56 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `W', 0x57 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `X', 0x58 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `Y', 0x59 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER, /* `Z', 0x5a */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `[', 0x5b */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* 0x5c */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `]', 0x5d */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `^', 0x5e */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `_', 0x5f */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* 0x60 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `a', 0x61 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `b', 0x62 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `c', 0x63 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `d', 0x64 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `e', 0x65 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT | __dj_ISXDIGIT, /* `f', 0x66 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `g', 0x67 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `h', 0x68 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `i', 0x69 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `j', 0x6a */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `k', 0x6b */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `l', 0x6c */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `m', 0x6d */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `n', 0x6e */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `o', 0x6f */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `p', 0x70 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `q', 0x71 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `r', 0x72 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `s', 0x73 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `t', 0x74 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `u', 0x75 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `v', 0x76 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `w', 0x77 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `x', 0x78 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `y', 0x79 */
__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISLOWER | __dj_ISPRINT, /* `z', 0x7a */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `{', 0x7b */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `|', 0x7c */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `}', 0x7d */
__dj_ISGRAPH | __dj_ISPRINT | __dj_ISPUNCT, /* `~', 0x7e */
__dj_ISCNTRL, /* 0x7f */
0, /* 0x80 */
0, /* 0x81 */
0, /* 0x82 */
0, /* 0x83 */
0, /* 0x84 */
0, /* 0x85 */
0, /* 0x86 */
0, /* 0x87 */
0, /* 0x88 */
0, /* 0x89 */
0, /* 0x8a */
0, /* 0x8b */
0, /* 0x8c */
0, /* 0x8d */
0, /* 0x8e */
0, /* 0x8f */
0, /* 0x90 */
0, /* 0x91 */
0, /* 0x92 */
0, /* 0x93 */
0, /* 0x94 */
0, /* 0x95 */
0, /* 0x96 */
0, /* 0x97 */
0, /* 0x98 */
0, /* 0x99 */
0, /* 0x9a */
0, /* 0x9b */
0, /* 0x9c */
0, /* 0x9d */
0, /* 0x9e */
0, /* 0x9f */
0, /* 0xa0 */
0, /* 0xa1 */
0, /* 0xa2 */
0, /* 0xa3 */
0, /* 0xa4 */
0, /* 0xa5 */
0, /* 0xa6 */
0, /* 0xa7 */
0, /* 0xa8 */
0, /* 0xa9 */
0, /* 0xaa */
0, /* 0xab */
0, /* 0xac */
0, /* 0xad */
0, /* 0xae */
0, /* 0xaf */
0, /* 0xb0 */
0, /* 0xb1 */
0, /* 0xb2 */
0, /* 0xb3 */
0, /* 0xb4 */
0, /* 0xb5 */
0, /* 0xb6 */
0, /* 0xb7 */
0, /* 0xb8 */
0, /* 0xb9 */
0, /* 0xba */
0, /* 0xbb */
0, /* 0xbc */
0, /* 0xbd */
0, /* 0xbe */
0, /* 0xbf */
0, /* 0xc0 */
0, /* 0xc1 */
0, /* 0xc2 */
0, /* 0xc3 */
0, /* 0xc4 */
0, /* 0xc5 */
0, /* 0xc6 */
0, /* 0xc7 */
0, /* 0xc8 */
0, /* 0xc9 */
0, /* 0xca */
0, /* 0xcb */
0, /* 0xcc */
0, /* 0xcd */
0, /* 0xce */
0, /* 0xcf */
0, /* 0xd0 */
0, /* 0xd1 */
0, /* 0xd2 */
0, /* 0xd3 */
0, /* 0xd4 */
0, /* 0xd5 */
0, /* 0xd6 */
0, /* 0xd7 */
0, /* 0xd8 */
0, /* 0xd9 */
0, /* 0xda */
0, /* 0xdb */
0, /* 0xdc */
0, /* 0xdd */
0, /* 0xde */
0, /* 0xdf */
0, /* 0xe0 */
0, /* 0xe1 */
0, /* 0xe2 */
0, /* 0xe3 */
0, /* 0xe4 */
0, /* 0xe5 */
0, /* 0xe6 */
0, /* 0xe7 */
0, /* 0xe8 */
0, /* 0xe9 */
0, /* 0xea */
0, /* 0xeb */
0, /* 0xec */
0, /* 0xed */
0, /* 0xee */
0, /* 0xef */
0, /* 0xf0 */
0, /* 0xf1 */
0, /* 0xf2 */
0, /* 0xf3 */
0, /* 0xf4 */
0, /* 0xf5 */
0, /* 0xf6 */
0, /* 0xf7 */
0, /* 0xf8 */
0, /* 0xf9 */
0, /* 0xfa */
0, /* 0xfb */
0, /* 0xfc */
0, /* 0xfd */
0, /* 0xfe */
0, /* 0xff */
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/ct_lower.c
0,0 → 1,39
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
unsigned char __dj_ctype_tolower[] = {
0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/ct_upper.c
0,0 → 1,39
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
unsigned char __dj_ctype_toupper[] = {
0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isalnum.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isalnum)(int c)
{
return isalnum(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isalpha.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isalpha)(int c)
{
return isalpha(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isascii.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <ctype.h>
#include <inlines/ctype.hd>
 
int (isascii)(int c)
{
return isascii(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/iscntrl.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (iscntrl)(int c)
{
return iscntrl(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isdigit.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isdigit)(int c)
{
return isdigit(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isgraph.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isgraph)(int c)
{
return isgraph(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/islower.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (islower)(int c)
{
return islower(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isprint.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isprint)(int c)
{
return isprint(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/ispunct.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (ispunct)(int c)
{
return ispunct(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isspace.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isspace)(int c)
{
return isspace(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isupper.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isupper)(int c)
{
return isupper(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/isxdigit.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (isxdigit)(int c)
{
return isxdigit(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/toascii.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <ctype.h>
#include <inlines/ctype.hd>
 
int (toascii)(int c)
{
return toascii(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/tolower.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (tolower)(int c)
{
return tolower(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/ctype/toupper.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <inlines/ctype.ha>
 
int (toupper)(int c)
{
return toupper(c);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/errno/Makefile
0,0 → 1,3
THIS_SRCS = errno.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/errno/errno.c
0,0 → 1,6
int errno;
 
int __isatty(int _fd)
{
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/Makefile
0,0 → 1,4
THIS_SRCS = lconv.c mbcurmax.c mblen.c mbstowcs.c mbtowc.c setlocal.c \
wcstombs.c wctomb.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/lconv.c
0,0 → 1,32
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <locale.h>
#include <limits.h>
 
static char ESTR[] = "";
static char DSTR[] = ".";
 
static struct lconv __lconv_ = {
ESTR,
DSTR,
ESTR,
ESTR,
ESTR,
ESTR,
ESTR,
ESTR,
ESTR,
ESTR,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX,
CHAR_MAX
};
 
struct lconv *localeconv()
{
return &__lconv_;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/mbcurmax.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int __dj_mb_cur_max = 1;
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/mblen.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int
mblen(const char *s, size_t n)
{
if (s)
{
if (n == 0 || *s == 0)
return 0;
return 1;
}
else
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/mbstowcs.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
size_t
mbstowcs(wchar_t *wcs, const char *s, size_t n)
{
int i;
for (i=0; s[i] && (i<n-1); i++)
wcs[i] = s[i];
wcs[i] = 0;
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/mbtowc.c
0,0 → 1,17
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int
mbtowc(wchar_t *pwc, const char *s, size_t n)
{
int x = 0;
if (s == 0)
return 0;
if (*s)
x = 1;
 
if (pwc)
*pwc = *s;
 
return x;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/setlocal.c
0,0 → 1,13
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <locale.h>
#include <string.h>
 
char *setlocale(int category, const char *locale)
{
static char CLOCALE[] = "C";
if (locale == 0)
return CLOCALE;
if (strcmp(locale, CLOCALE) && strcmp(locale, "POSIX") && locale[0])
return 0;
return CLOCALE;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/wcstombs.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
size_t
wcstombs(char *s, const wchar_t *wcs, size_t n)
{
int i;
for (i=0; wcs[i] && (i<n-1); i++)
s[i] = wcs[i];
s[i] = 0;
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/locale/wctomb.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int
wctomb(char *s, wchar_t wchar)
{
if (s)
s[0] = wchar;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/Makefile
0,0 → 1,6
THIS_SRCS = acosh.c acos.s asinh.c asin.s atan2.s atanh.c atan.s \
ceil.s cosh.c cos.s exp.s fabs.s floor.s fmod.s frexp.c huge_val.c \
hypot.c ldexp.c log.s modfl.s modf.s pow10.s pow2.s pow.s sinh.c \
sin.s sqrt.s tanh.c tan.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/acos.s
0,0 → 1,22
#include<libc/asm.h>
 
.text
LC0:
.double 0d1.00000000000000000000e+00
 
MK_C_SYM(acos)
fldl 4(%esp)
fld1
fsubp %st(0),%st(1)
fsqrt
 
fldl 4(%esp)
fld1
faddp %st(0),%st(1)
fsqrt
 
fpatan
 
fld %st(0)
faddp
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/acosh.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
acosh(double x)
{
return log(x + sqrt(x*x - 1));
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/asin.s
0,0 → 1,14
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(asin)
fldl 4(%esp)
fld %st(0)
fmulp
fld1
fsubp
fsqrt
fldl 4(%esp)
fxch %st(1)
fpatan
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/asinh.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
asinh(double x)
{
return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x);
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/atan.s
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(atan)
fldl 4(%esp)
fld1
fpatan
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/atan2.s
0,0 → 1,35
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
 
.data
.align 2
nan:
.long 0xffffffff
.byte 0xff
.byte 0xff
.byte 0xff
.byte 0x7f
 
.text
MK_C_SYM(atan2)
fldl 4(%esp)
fldl 12(%esp)
ftst
fnstsw %ax
sahf
jne doit
fxch %st(1)
ftst
fnstsw %ax
sahf
je isanan
fxch %st(1)
doit:
fpatan
ret
isanan:
movl $1,C_SYM(errno)
fstp %st(0)
fstp %st(0)
fldl nan
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/atanh.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
atanh(double x)
{
return log((1+x)/(1-x)) / 2.0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/ceil.s
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(ceil)
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
andw $0xf3ff,%ax
orw $0x0800,%ax
movw %ax,-2(%ebp)
fldcw -2(%ebp)
 
fldl 8(%ebp)
frndint
 
fldcw -4(%ebp)
 
movl %ebp,%esp
popl %ebp
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/cos.s
0,0 → 1,15
#include<libc/asm.h>
L0:
.quad 0xffffffffffffffff
 
MK_C_SYM(cos)
fldl 4(%esp)
fcos
fstsw
sahf
jnp L1
fstp %st(0)
fldl L0
L1:
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/cosh.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double cosh(double x)
{
const double ebig = exp(fabs(x));
return (ebig + 1.0/ebig) / 2.0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/exp.s
0,0 → 1,31
#include<libc/asm.h>
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
 
.text
 
MK_C_SYM(exp)
fldl 4(%esp)
fldl2e
fmulp
fstcw LCW1
fstcw LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcw LCW2
fldl %st(0)
frndint
fldcw LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/fabs.s
0,0 → 1,6
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(fabs)
fldl 4(%esp)
fabs
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/floor.s
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(floor)
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
andw $0xf3ff,%ax
orw $0x0400,%ax
movw %ax,-2(%ebp)
fldcw -2(%ebp)
 
fldl 8(%ebp)
frndint
 
fldcw -4(%ebp)
 
movl %ebp,%esp
popl %ebp
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/fmod.s
0,0 → 1,29
#include<libc/asm.h>
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.data
LCW1:
.word 0
.align 4
 
.text
 
MK_C_SYM(fmod)
fldl 4(%esp)
fldl 12(%esp)
ftst
fnstsw %ax
fxch %st(1)
sahf
jnz next
fstpl %st(0)
jmp out
next:
fprem
fnstsw %ax
sahf
jpe next
fstpl %st(1)
out:
ret
 
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/frexp.c
0,0 → 1,26
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
frexp(double x, int *exptr)
{
union {
double d;
unsigned char c[8];
} u;
 
u.d = x;
/*
* The format of the number is:
* Sign, 12 exponent bits, 51 mantissa bits
* The exponent is 1023 biased and there is an implicit zero.
* We get the exponent from the upper bits and set the exponent
* to 0x3fe (1022).
*/
*exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
u.c[7] &= 0x80;
u.c[7] |= 0x3f;
u.c[6] &= 0x0f;
u.c[6] |= 0xe0;
return u.d;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/huge_val.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
double_t __dj_huge_val = { 0x00000, 0x00000, 0x7ff, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/hypot.c
0,0 → 1,100
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* hypot() function for DJGPP.
*
* hypot() computes sqrt(x^2 + y^2). The problem with the obvious
* naive implementation is that it might fail for very large or
* very small arguments. For instance, for large x or y the result
* might overflow even if the value of the function should not,
* because squaring a large number might trigger an overflow. For
* very small numbers, their square might underflow and will be
* silently replaced by zero; this won't cause an exception, but might
* have an adverse effect on the accuracy of the result.
*
* This implementation tries to avoid the above pitfals, without
* inflicting too much of a performance hit.
*
*/
#include <float.h>
#include <math.h>
#include <errno.h>
/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers
between these two shouldn't neither overflow nor underflow
when squared. */
#define __SQRT_DBL_MAX 1.3e+154
#define __SQRT_DBL_MIN 2.3e-162
double
hypot(double x, double y)
{
double abig = fabs(x), asmall = fabs(y);
double ratio;
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
if (abig < asmall)
{
double temp = abig;
abig = asmall;
asmall = temp;
}
/* Trivial case. */
if (asmall == 0.)
return abig;
/* Scale the numbers as much as possible by using its ratio.
For example, if both ABIG and ASMALL are VERY small, then
X^2 + Y^2 might be VERY inaccurate due to loss of
significant digits. Dividing ASMALL by ABIG scales them
to a certain degree, so that accuracy is better. */
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
return abig * sqrt(1.0 + ratio*ratio);
else
{
/* Slower but safer algorithm due to Moler and Morrison. Never
produces any intermediate result greater than roughly the
larger of X and Y. Should converge to machine-precision
accuracy in 3 iterations. */
double r = ratio*ratio, t, s, p = abig, q = asmall;
do {
t = 4. + r;
if (t == 4.)
break;
s = r / t;
p += 2. * s * p;
q *= s;
r = (q / p) * (q / p);
} while (1);
return p;
}
}
#ifdef TEST
#include <stdio.h>
int
main(void)
{
printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.));
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150));
printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306));
printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n",
hypot(3.e-320, 4.e-320));
printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n",
hypot(0.7*DBL_MAX, 0.7*DBL_MAX));
printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0));
printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX));
printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX));
return 0;
}
#endif
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/ldexp.c
0,0 → 1,32
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
ldexp(double v, int e)
{
double two = 2.0;
 
if (e < 0)
{
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0) return 0.0;
while (e > 0)
{
if (e & 1) v /= two;
two *= two;
e >>= 1;
}
}
else if (e > 0)
{
while (e > 0)
{
if (e & 1) v *= two;
two *= two;
e >>= 1;
}
}
return v;
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/log.s
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(log)
fldln2
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/modf.s
0,0 → 1,33
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
.text
#include<libc/asm.h>
MK_C_SYM(modf)
pushl %ebp
movl %esp,%ebp
subl $16,%esp
pushl %ebx
fnstcw -4(%ebp)
fwait
movw -4(%ebp),%ax
orw $0x0c3f,%ax
movw %ax,-8(%ebp)
fldcw -8(%ebp)
fwait
fldl 8(%ebp)
frndint
fstpl -16(%ebp)
fwait
movl -16(%ebp),%edx
movl -12(%ebp),%ecx
movl 16(%ebp),%ebx
movl %edx,(%ebx)
movl %ecx,4(%ebx)
fldl 8(%ebp)
fsubl -16(%ebp)
leal -20(%ebp),%esp
fclex
fldcw -4(%ebp)
fwait
popl %ebx
leave
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/modfl.s
0,0 → 1,21
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(__modfl)
pushl %ebp
movl %esp,%ebp
subl $4,%esp
fldt 8(%ebp)
movl 20(%ebp),%eax
fnstcw -2(%ebp)
movw -2(%ebp),%dx
orb $0x0c,%dh
movw %dx,-4(%ebp)
fldcw -4(%ebp)
fld %st(0)
frndint
fldcw -2(%ebp)
fld %st(0)
fstpt (%eax)
fsubrp %st,%st(1)
leave
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/pow.s
0,0 → 1,86
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.data
yint:
.word 0,0
LCW1:
.word 0
LCW2:
.word 0
 
.text
LC0:
.double 0d1.0e+00
 
frac:
fstcw LCW1
fstcw LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcw LCW2
fldl %st(0)
frndint
fldcw LCW1
fxch %st(1)
fsub %st(1),%st
ret
 
Lpow2:
call frac
f2xm1
faddl LC0
fscale
fstp %st(1)
ret
 
MK_C_SYM(pow)
fldl 12(%esp)
fldl 4(%esp)
ftst
fnstsw %ax
sahf
jbe xltez
fyl2x
jmp Lpow2
xltez:
jb xltz
fstp %st(0)
ftst
fnstsw %ax
sahf
ja ygtz
jb error
fstp %st(0)
fld1
fchs
error:
fsqrt
ret
ygtz:
fstp %st(0)
fldz
ret
xltz:
fabs
fxch %st(1)
call frac
ftst
fnstsw %ax
fstp %st(0)
sahf
je yisint
fstp %st(0)
fchs
jmp error
yisint:
fistl yint
fxch %st(1)
fyl2x
call Lpow2
andl $1,yint
jz yeven
fchs
yeven:
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/pow10.s
0,0 → 1,32
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
 
.text
 
MK_C_SYM(__pow10)
fldl 4(%esp)
fldl2t
fmulp
fstcw LCW1
fstcw LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcw LCW2
fldl %st(0)
frndint
fldcw LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/pow2.s
0,0 → 1,30
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.data
LCW1:
.word 0
LCW2:
.word 0
LC0:
.double 0d1.0e+00
 
.text
 
MK_C_SYM(__pow2)
fldl 4(%esp)
fstcw LCW1
fstcw LCW2
fwait
andw $0xf3ff,LCW2
orw $0x0400,LCW2
fldcw LCW2
fldl %st(0)
frndint
fldcw LCW1
fxch %st(1)
fsub %st(1),%st
f2xm1
faddl LC0
fscale
fstp %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/sin.s
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
L0:
.quad 0xffffffffffffffff
 
MK_C_SYM(sin)
fldl 4(%esp)
fsin
fstsw
sahf
jnp L1
fstp %st(0)
fldl L0
L1:
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/sinh.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double sinh(double x)
{
if(x >= 0.0)
{
const double epos = exp(x);
return (epos - 1.0/epos) / 2.0;
}
else
{
const double eneg = exp(-x);
return (1.0/eneg - eneg) / 2.0;
}
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/sqrt.s
0,0 → 1,6
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(sqrt)
fldl 4(%esp)
fsqrt
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/tan.s
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
L0:
.quad 0xffffffffffffffff
 
MK_C_SYM(tan)
fldl 4(%esp)
fptan
fstsw
fstp %st(0)
sahf
jnp L1
/* fstp %st(0) - if exception, there is nothing on the stack */
fldl L0
L1:
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/math/tanh.c
0,0 → 1,17
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double tanh(double x)
{
if (x > 50)
return 1;
else if (x < -50)
return -1;
else
{
const double ebig = exp(x);
const double esmall = 1.0/ebig;
return (ebig - esmall) / (ebig + esmall);
}
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/setjmp/Makefile
0,0 → 1,3
THIS_SRCS = longjmp.s setjmp.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/setjmp/longjmp.s
0,0 → 1,64
# 1 "longjmp.s"
#include<libc/asm.h>
MK_C_SYM(longjmp)
movl 4(%esp),%edi
movl 8(%esp),%eax
movl %eax,0(%edi)
 
movw 46(%edi),%fs
movw 48(%edi),%gs
movl 4(%edi),%ebx
movl 8(%edi),%ecx
movl 12(%edi),%edx
movl 24(%edi),%ebp
 
movw 50(%edi),%es
movl 28(%edi),%esi
subl $28,%esi
 
movl 60(%edi),%eax
es
movl %eax,(%esi)
 
movzwl 42(%edi),%eax
es
movl %eax,4(%esi)
 
movl 20(%edi),%eax
es
movl %eax,8(%esi)
 
movl 16(%edi),%eax
es
movl %eax,12(%esi)
 
movl 32(%edi),%eax
es
movl %eax,16(%esi)
 
movl 40(%edi),%eax
es
movl %eax,20(%esi)
 
movl 36(%edi),%eax
es
movl %eax,24(%esi)
 
movl 0(%edi),%eax
movw 44(%edi),%es
 
movw 50(%edi),%ss
movl %esi,%esp
 
popl C_SYM(__djgpp_exception_state_ptr)
popl %ds
popl %edi
popl %esi
 
iret
 
MK_C_SYM(__djgpp_exception_state_ptr)
.word 0
.word 0
.word 0
.word 0
/programs/develop/libraries/menuetlibc/src/libc/ansi/setjmp/setjmp.s
0,0 → 1,44
#include<libc/asm.h>
MK_C_SYM(setjmp)
pushl %ebp
movl %esp,%ebp
 
pushl %edi
movl 8(%ebp),%edi
 
movl %eax, (%edi)
movl %ebx,4(%edi)
movl %ecx,8(%edi)
movl %edx,12(%edi)
movl %esi,16(%edi)
 
movl -4(%ebp),%eax
movl %eax,20(%edi)
 
movl (%ebp),%eax
movl %eax,24(%edi)
 
movl %esp,%eax
addl $12,%eax
movl %eax,28(%edi)
movl 4(%ebp),%eax
movl %eax,32(%edi)
 
pushfl
popl 36(%edi)
 
movw %cs, 40(%edi)
movw %ds, 42(%edi)
movw %es, 44(%edi)
movw %fs, 46(%edi)
movw %gs, 48(%edi)
movw %ss, 50(%edi)
movl C_SYM(__djgpp_exception_state_ptr), %eax
movl %eax, 60(%edi)
 
popl %edi
xorl %eax,%eax
popl %ebp
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/Makefile
0,0 → 1,11
THIS_SRCS = allocfil.c clearerr.c doprnt.c doscan.c fclose.c feof.c \
ferror.c fflush.c fgetc.c fgetpos.c fgets.c filbuf.c flsbuf.c \
fopen.c fprintf.c fputc.c fputs.c fread.c freopen.c frlist.c \
fscanf.c fseek.c fsetpos.c ftell.c fwalk.c fwrite.c getc.c getchar.c \
gets.c getw.c perror.c printf.c putc.c putchar.c puts.c putw.c \
remove.c _rename.c rename.c rewind.c scanf.c setbuf.c setbuffe.c \
setlineb.c setvbuf.c sprintf.c sscanf.c stdaux.c stderr.c stdin.c \
stdiohk.c stdout.c stdprn.c tmpfile.c tmpnam.c ungetc.c vfprintf.c \
vprintf.c vsprintf.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/_rename.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <errno.h>
#include <libc/dosio.h>
#include<assert.h>
 
int _rename(const char *old, const char *new)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/allocfil.c
0,0 → 1,49
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/stdiohk.h>
 
FILE *__alloc_file(void)
{
__file_rec *fr = __file_rec_list;
__file_rec **last_fr = &__file_rec_list;
FILE *rv=0;
int i;
 
/* Try to find an empty slot */
while (fr)
{
last_fr = &(fr->next);
 
/* If one of the existing slots is available, return it */
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag == 0)
return fr->files[i];
 
/* If this one is full, go to the next */
if (fr->count == __FILE_REC_MAX)
fr = fr->next;
else
/* it isn't full, we can add to it */
break;
}
if (!fr)
{
/* add another one to the end, make it empty */
fr = *last_fr = (__file_rec *)malloc(sizeof(__file_rec));
if (fr == 0)
return 0;
fr->next = 0;
fr->count = 0;
}
/* fr is a pointer to a rec with empty slots in it */
rv = fr->files[fr->count] = (FILE *)malloc(sizeof(FILE));
if (rv == 0)
return 0;
memset(rv, 0, sizeof(FILE));
fr->count ++;
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/clearerr.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef clearerr
void
clearerr(FILE *f)
{
f->_flag &= ~(_IOERR|_IOEOF);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/doprnt.c
0,0 → 1,840
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
#include <libc/local.h>
 
static char decimal = '.';
 
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
#define MAXEXP 308
#define MAXEXPLD 4952 /* this includes subnormal numbers */
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
#define MAXFRACT 39
 
#define DEFPREC 6
#define DEFLPREC 6
 
#define BUF (MAXEXPLD+MAXFRACT+1) /* + decimal point */
 
#define PUTC(ch) (void) putc(ch, fp)
 
#define ARG(basetype) \
_ulong = flags&LONGINT ? va_arg(argp, long basetype) : \
flags&SHORTINT ? (short basetype)va_arg(argp, int) : \
va_arg(argp, int)
 
static int nan2 = 0;
 
static __inline__ int todigit(char c)
{
if (c<='0') return 0;
if (c>='9') return 9;
return c-'0';
}
static __inline__ char tochar(int n)
{
if (n>=9) return '9';
if (n<=0) return '0';
return n+'0';
}
 
/* have to deal with the negative buffer count kludge */
 
#define LONGINT 0x01 /* long integer */
#define LONGDBL 0x02 /* long double */
#define SHORTINT 0x04 /* short integer */
#define ALT 0x08 /* alternate form */
#define LADJUST 0x10 /* left adjustment */
#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
 
static cvtl(long double number, int prec, int flags, char *signp,
unsigned char fmtch, char *startp, char *endp);
static char *roundl(long double fract, int *expv, char *start, char *end,
char ch, char *signp);
static char *exponentl(char *p, int expv, unsigned char fmtch);
static int isspeciall(long double d, char *bufp);
 
static char NULL_REP[] = "(null)";
 
int
_doprnt(const char *fmt0, va_list argp, FILE *fp)
{
const char *fmt; /* format string */
int ch; /* character from fmt */
int cnt; /* return value accumulator */
int n; /* random handy integer */
char *t; /* buffer pointer */
long double _ldouble; /* double and long double precision arguments
%L.[eEfgG] */
unsigned long _ulong; /* integer arguments %[diouxX] */
int base; /* base for [diouxX] conversion */
int dprec; /* decimal precision in [diouxX] */
int fieldsz; /* field size expanded by sign, etc */
int flags; /* flags as above */
int fpprec; /* `extra' floating precision in [eEfgG] */
int prec; /* precision from format (%.3d), or -1 */
int realsz; /* field size expanded by decimal precision */
int size; /* size of converted field or string */
int width; /* width from format (%8d), or 0 */
char sign; /* sign prefix (' ', '+', '-', or \0) */
char softsign; /* temporary negative sign for floats */
const char *digs; /* digits for [diouxX] conversion */
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
 
decimal = localeconv()->decimal_point[0];
 
if (fp->_flag & _IORW)
{
fp->_flag |= _IOWRT;
fp->_flag &= ~(_IOEOF|_IOREAD);
}
if ((fp->_flag & _IOWRT) == 0)
return (EOF);
 
fmt = fmt0;
digs = "0123456789abcdef";
for (cnt = 0;; ++fmt)
{
n = fp->_cnt;
for (t = (char *)fp->_ptr; (ch = *fmt) && ch != '%';
++cnt, ++fmt)
if ((--n < 0
&& (!(fp->_flag & _IOLBF) || -n >= fp->_bufsiz))
|| (ch == '\n' && fp->_flag & _IOLBF))
{
fp->_cnt = n;
fp->_ptr = t;
(void) _flsbuf((unsigned char)ch, fp);
n = fp->_cnt;
t = (char *)fp->_ptr;
}
else
*t++ = ch;
fp->_cnt = n;
fp->_ptr = t;
if (!ch)
return cnt;
flags = 0; dprec = 0; fpprec = 0; width = 0;
prec = -1;
sign = '\0';
rflag:
switch (*++fmt)
{
case ' ':
/*
* ``If the space and + flags both appear, the space
* flag will be ignored.''
* -- ANSI X3J11
*/
if (!sign)
sign = ' ';
goto rflag;
case '#':
flags |= ALT;
goto rflag;
case '*':
/*
* ``A negative field width argument is taken as a
* - flag followed by a positive field width.''
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
if ((width = va_arg(argp, int)) >= 0)
goto rflag;
width = -width;
/* FALLTHROUGH */
case '-':
flags |= LADJUST;
goto rflag;
case '+':
sign = '+';
goto rflag;
case '.':
if (*++fmt == '*')
n = va_arg(argp, int);
else
{
n = 0;
while (isascii(*fmt) && isdigit(*fmt))
n = 10 * n + todigit(*fmt++);
--fmt;
}
prec = n < 0 ? -1 : n;
goto rflag;
case '0':
/*
* ``Note that 0 is taken as a flag, not as the
* beginning of a field width.''
* -- ANSI X3J11
*/
flags |= ZEROPAD;
goto rflag;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
do {
n = 10 * n + todigit(*fmt);
} while (isascii(*++fmt) && isdigit(*fmt));
width = n;
--fmt;
goto rflag;
case 'L':
flags |= LONGDBL;
goto rflag;
case 'h':
flags |= SHORTINT;
goto rflag;
case 'l':
flags |= LONGINT;
goto rflag;
case 'c':
*(t = buf) = va_arg(argp, int);
size = 1;
sign = '\0';
goto pforw;
case 'D':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'd':
case 'i':
ARG(int);
if ((long)_ulong < 0)
{
_ulong = -_ulong;
sign = '-';
}
base = 10;
goto number;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
if (flags & LONGDBL)
_ldouble = va_arg(argp, long double);
else
_ldouble = (long double)va_arg(argp, double);
/*
* don't do unrealistic precision; just pad it with
* zeroes later, so buffer size stays rational.
*/
if (prec > MAXFRACT)
{
if (*fmt != 'g' && (*fmt != 'G' || (flags&ALT)))
fpprec = prec - MAXFRACT;
prec = MAXFRACT;
}
else if (prec == -1)
{
if (flags&LONGINT)
prec = DEFLPREC;
else
prec = DEFPREC;
}
/*
* softsign avoids negative 0 if _double is < 0 and
* no significant digits will be shown
*/
if (_ldouble < 0)
{
softsign = '-';
_ldouble = -_ldouble;
}
else
softsign = 0;
/*
* cvt may have to round up past the "start" of the
* buffer, i.e. ``intf("%.2f", (double)9.999);'';
* if the first char isn't NULL, it did.
*/
*buf = NULL;
size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf,
buf + sizeof(buf));
if (softsign && !nan2)
sign = '-';
nan2 = 0;
t = *buf ? buf : buf + 1;
goto pforw;
case 'n':
if (flags & LONGINT)
*va_arg(argp, long *) = cnt;
else if (flags & SHORTINT)
*va_arg(argp, short *) = cnt;
else
*va_arg(argp, int *) = cnt;
break;
case 'O':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
ARG(unsigned);
base = 8;
goto nosign;
case 'p':
/*
* ``The argument shall be a pointer to void. The
* value of the pointer is converted to a sequence
* of printable characters, in an implementation-
* defined manner.''
* -- ANSI X3J11
*/
/* NOSTRICT */
_ulong = (unsigned long)va_arg(argp, void *);
base = 16;
goto nosign;
case 's':
if (!(t = va_arg(argp, char *)))
t = NULL_REP;
if (prec >= 0)
{
/*
* can't use strlen; can only look for the
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
char *p /*, *memchr() */;
 
if ((p = memchr(t, 0, prec)))
{
size = p - t;
if (size > prec)
size = prec;
}
else
size = prec;
}
else
size = strlen(t);
sign = '\0';
goto pforw;
case 'U':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
ARG(unsigned);
base = 10;
goto nosign;
case 'X':
digs = "0123456789ABCDEF";
/* FALLTHROUGH */
case 'x':
ARG(unsigned);
base = 16;
/* leading 0x/X only if non-zero */
if (flags & ALT && _ulong != 0)
flags |= HEXPREFIX;
 
/* unsigned conversions */
nosign: sign = '\0';
/*
* ``... diouXx conversions ... if a precision is
* specified, the 0 flag will be ignored.''
* -- ANSI X3J11
*/
number: if ((dprec = prec) >= 0)
flags &= ~ZEROPAD;
 
/*
* ``The result of converting a zero value with an
* explicit precision of zero is no characters.''
* -- ANSI X3J11
*/
t = buf + BUF;
if (_ulong != 0 || prec != 0)
{
do {
*--t = digs[_ulong % base];
_ulong /= base;
} while (_ulong);
digs = "0123456789abcdef";
if (flags & ALT && base == 8 && *t != '0')
*--t = '0'; /* octal leading 0 */
}
size = buf + BUF - t;
 
pforw:
/*
* All reasonable formats wind up here. At this point,
* `t' points to a string which (if not flags&LADJUST)
* should be padded out to `width' places. If
* flags&ZEROPAD, it should first be prefixed by any
* sign or other prefix; otherwise, it should be blank
* padded before the prefix is emitted. After any
* left-hand padding and prefixing, emit zeroes
* required by a decimal [diouxX] precision, then print
* the string proper, then emit zeroes required by any
* leftover floating precision; finally, if LADJUST,
* pad with blanks.
*/
 
/*
* compute actual size, so we know how much to pad
* fieldsz excludes decimal prec; realsz includes it
*/
fieldsz = size + fpprec;
realsz = dprec > fieldsz ? dprec : fieldsz;
if (sign)
realsz++;
if (flags & HEXPREFIX)
realsz += 2;
 
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
for (n = realsz; n < width; n++)
PUTC(' ');
/* prefix */
if (sign)
PUTC(sign);
if (flags & HEXPREFIX)
{
PUTC('0');
PUTC((char)*fmt);
}
/* right-adjusting zero padding */
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
for (n = realsz; n < width; n++)
PUTC('0');
/* leading zeroes from decimal precision */
for (n = fieldsz; n < dprec; n++)
PUTC('0');
 
/* the string or number proper */
n = size;
if (fp->_cnt - n >= 0 && (fp->_flag & _IOLBF) == 0)
{
fp->_cnt -= n;
memcpy((char *)fp->_ptr, t, n);
fp->_ptr += n;
}
else
while (--n >= 0)
PUTC(*t++);
/* trailing f.p. zeroes */
while (--fpprec >= 0)
PUTC('0');
/* left-adjusting padding (always blank) */
if (flags & LADJUST)
for (n = realsz; n < width; n++)
PUTC(' ');
/* finally, adjust cnt */
cnt += width > realsz ? width : realsz;
break;
case '\0': /* "%?" prints ?, unless ? is NULL */
return cnt;
default:
PUTC((char)*fmt);
cnt++;
}
}
/* NOTREACHED */
}
 
static long double pten[] =
{
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L,
1e512L, 1e1024L, 1e2048L, 1e4096L
};
 
static long double ptenneg[] =
{
1e-1L, 1e-2L, 1e-4L, 1e-8L, 1e-16L, 1e-32L, 1e-64L, 1e-128L, 1e-256L,
1e-512L, 1e-1024L, 1e-2048L, 1e-4096L
};
 
#define MAXP 4096
#define NP 12
#define P (4294967296.0L * 4294967296.0L * 2.0L) /* 2^65 */
static long double INVPREC = P;
static long double PREC = 1.0L/P;
#undef P
/*
* Defining FAST_LDOUBLE_CONVERSION results in a little bit faster
* version, which might be less accurate (about 1 bit) for long
* double. For 'normal' double it doesn't matter.
*/
/* #define FAST_LDOUBLE_CONVERSION */
 
static int
cvtl(long double number, int prec, int flags, char *signp, unsigned char fmtch,
char *startp, char *endp)
{
char *p, *t;
long double fract;
int dotrim, expcnt, gformat;
long double integer, tmp;
 
if ((expcnt = isspeciall(number, startp)))
return(expcnt);
 
dotrim = expcnt = gformat = 0;
/* fract = modfl(number, &integer); */
integer = number;
 
/* get an extra slot for rounding. */
t = ++startp;
 
p = endp - 1;
if (integer)
{
int i, lp=NP, pt=MAXP;
#ifndef FAST_LDOUBLE_CONVERSION
long double oint = integer, dd=1.0L;
#endif
if (integer > INVPREC)
{
integer *= PREC;
while(lp >= 0) {
if (integer >= pten[lp])
{
expcnt += pt;
integer *= ptenneg[lp];
#ifndef FAST_LDOUBLE_CONVERSION
dd *= pten[lp];
#endif
}
pt >>= 1;
lp--;
}
#ifndef FAST_LDOUBLE_CONVERSION
integer = oint/dd;
#else
integer *= INVPREC;
#endif
}
/*
* Do we really need this ?
*/
for (i = 0; i < expcnt; i++)
*p-- = '0';
}
number = integer;
fract = modfl(number, &integer);
/*
* get integer portion of number; put into the end of the buffer; the
* .01 is added for modf(356.0 / 10, &integer) returning .59999999...
*/
for (; integer; ++expcnt)
{
tmp = modfl(integer * 0.1L , &integer);
*p-- = tochar((int)((tmp + .01L) * 10));
}
switch(fmtch)
{
case 'f':
/* reverse integer into beginning of buffer */
if (expcnt)
for (; ++p < endp; *t++ = *p);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point.
*/
if (prec || flags&ALT)
*t++ = decimal;
/* if requires more precision and some fraction left */
if (fract)
{
if (prec)
do {
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
} while (--prec && fract);
if (fract)
startp = roundl(fract, (int *)NULL, startp,
t - 1, (char)0, signp);
}
for (; prec--; *t++ = '0');
break;
case 'e':
case 'E':
eformat:
if (expcnt)
{
*t++ = *++p;
if (prec || flags&ALT)
*t++ = decimal;
/* if requires more precision and some integer left */
for (; prec && ++p < endp; --prec)
*t++ = *p;
/*
* if done precision and more of the integer component,
* round using it; adjust fract so we don't re-round
* later.
*/
if (!prec && ++p < endp)
{
fract = 0;
startp = roundl((long double)0.0L, &expcnt,
startp, t - 1, *p, signp);
}
/* adjust expcnt for digit in front of decimal */
--expcnt;
}
/* until first fractional digit, decrement exponent */
else if (fract)
{
int lp=NP, pt=MAXP;
#ifndef FAST_LDOUBLE_CONVERSION
long double ofract = fract, dd=1.0L;
#endif
expcnt = -1;
if (fract < PREC)
{
fract *= INVPREC;
while(lp >= 0)
{
if (fract <= ptenneg[lp])
{
expcnt -= pt;
fract *= pten[lp];
#ifndef FAST_LDOUBLE_CONVERSION
dd *= pten[lp];
#endif
}
pt >>= 1;
lp--;
}
#ifndef FAST_LDOUBLE_CONVERSION
fract = ofract*dd;
#else
fract *= PREC;
#endif
}
/* adjust expcnt for digit in front of decimal */
for ( /* expcnt = -1 */ ;; --expcnt)
{
fract = modfl(fract * 10.0L, &tmp);
if (tmp)
break;
}
*t++ = tochar((int)tmp);
if (prec || flags&ALT)
*t++ = decimal;
}
else
{
*t++ = '0';
if (prec || flags&ALT)
*t++ = decimal;
}
/* if requires more precision and some fraction left */
if (fract)
{
if (prec)
do {
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
} while (--prec && fract);
if (fract)
startp = roundl(fract, &expcnt, startp,
t - 1, (char)0, signp);
}
/* if requires more precision */
for (; prec--; *t++ = '0');
 
/* unless alternate flag, trim any g/G format trailing 0's */
if (gformat && !(flags&ALT))
{
while (t > startp && *--t == '0');
if (*t == decimal)
--t;
++t;
}
t = exponentl(t, expcnt, fmtch);
break;
case 'g':
case 'G':
/* a precision of 0 is treated as a precision of 1. */
if (!prec)
++prec;
/*
* ``The style used depends on the value converted; style e
* will be used only if the exponent resulting from the
* conversion is less than -4 or greater than the precision.''
* -- ANSI X3J11
*/
if (expcnt > prec || (!expcnt && fract && fract < .0001))
{
/*
* g/G format counts "significant digits, not digits of
* precision; for the e/E format, this just causes an
* off-by-one problem, i.e. g/G considers the digit
* before the decimal point significant and e/E doesn't
* count it as precision.
*/
--prec;
fmtch -= 2; /* G->E, g->e */
gformat = 1;
goto eformat;
}
/*
* reverse integer into beginning of buffer,
* note, decrement precision
*/
if (expcnt)
for (; ++p < endp; *t++ = *p, --prec);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point. If no digits yet, add in leading 0.
*/
if (prec || flags&ALT)
{
dotrim = 1;
*t++ = decimal;
}
else
dotrim = 0;
/* if requires more precision and some fraction left */
while (prec && fract)
{
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
prec--;
}
if (fract)
startp = roundl(fract, (int *)NULL, startp, t - 1,
(char)0, signp);
/* alternate format, adds 0's for precision, else trim 0's */
if (flags&ALT)
for (; prec--; *t++ = '0');
else if (dotrim)
{
while (t > startp && *--t == '0');
if (*t != decimal)
++t;
}
}
return t - startp;
}
 
static char *
roundl(long double fract, int *expv, char *start, char *end, char ch,
char *signp)
{
long double tmp;
 
if (fract)
{
if (fract == 0.5L)
{
char *e = end;
if (*e == '.')
e--;
if (*e == '0' || *e == '2' || *e == '4'
|| *e == '6' || *e == '8')
{
tmp = 3.0;
goto start;
}
}
(void)modfl(fract * 10.0L, &tmp);
}
else
tmp = todigit(ch);
start:
if (tmp > 4)
for (;; --end)
{
if (*end == decimal)
--end;
if (++*end <= '9')
break;
*end = '0';
if (end == start)
{
if (expv)
{ /* e/E; increment exponent */
*end = '1';
++*expv;
}
else
{ /* f; add extra digit */
*--end = '1';
--start;
}
break;
}
}
/* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
else if (*signp == '-')
for (;; --end)
{
if (*end == decimal)
--end;
if (*end != '0')
break;
if (end == start)
*signp = 0;
}
return start;
}
 
static char *
exponentl(char *p, int expv, unsigned char fmtch)
{
char *t;
char expbuf[MAXEXPLD];
 
*p++ = fmtch;
if (expv < 0)
{
expv = -expv;
*p++ = '-';
}
else
*p++ = '+';
t = expbuf + MAXEXPLD;
if (expv > 9)
{
do {
*--t = tochar(expv % 10);
} while ((expv /= 10) > 9);
*--t = tochar(expv);
for (; t < expbuf + MAXEXPLD; *p++ = *t++);
}
else
{
*p++ = '0';
*p++ = tochar(expv);
}
return p;
}
 
static int
isspeciall(long double d, char *bufp)
{
struct IEEExp {
unsigned manl:32;
unsigned manh:32;
unsigned exp:15;
unsigned sign:1;
} *ip = (struct IEEExp *)&d;
 
nan2 = 0; /* don't assume the static is 0 (emacs) */
if (ip->exp != 0x7fff)
return(0);
if ((ip->manh & 0x7fffffff) || ip->manl)
{
strcpy(bufp, "NaN");
nan2 = 1; /* kludge: we don't need the sign, it's not nice
but it should work */
}
else
(void)strcpy(bufp, "Inf");
return(3);
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/doscan.c
0,0 → 1,360
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <libc/file.h>
#include <libc/local.h>
#include <stdarg.h>
 
#define SPC 01
#define STP 02
 
#define SHORT 0
#define REGULAR 1
#define LONG 2
#define LONGDOUBLE 4
#define INT 0
#define FLOAT 1
 
static int _innum(void *ptr, int type, int len, int size, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
int *eofptr);
static int _instr(char *ptr, int type, int len, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
int *eofptr);
static const char *_getccl(const unsigned char *s);
 
static char _sctab[256] = {
0,0,0,0,0,0,0,0,
0,SPC,SPC,SPC,SPC,SPC,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
SPC,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,
};
 
static int nchars = 0;
 
int
_doscan(FILE *iop, const char *fmt, va_list argp)
{
return(_doscan_low(iop, fgetc, ungetc, fmt, argp));
}
 
int
_doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
const char *fmt, va_list argp)
{
register int ch;
int nmatch, len, ch1;
void* ptr;
int fileended, size;
 
nchars = 0;
nmatch = 0;
fileended = 0;
for (;;) switch (ch = *fmt++) {
case '\0':
return (nmatch);
case '%':
if ((ch = *fmt++) == '%')
goto def;
if (ch == 'n')
{
int* arg = va_arg(argp, int*);
*arg = nchars;
break;
}
if (fileended)
return(nmatch? nmatch: -1);
ptr = 0;
if (ch != '*')
ptr = va_arg(argp, void*);
else
ch = *fmt++;
len = 0;
size = REGULAR;
while (isdigit(ch)) {
len = len*10 + ch - '0';
ch = *fmt++;
}
if (len == 0)
len = 30000;
if (ch=='l') {
size = LONG;
ch = *fmt++;
} else if (ch=='h') {
size = SHORT;
ch = *fmt++;
} else if (ch=='L') {
size = LONGDOUBLE;
ch = *fmt++;
} else if (ch=='[')
fmt = _getccl((const unsigned char *)fmt);
if (isupper(ch)) {
/* ch = tolower(ch);
gcc gives warning: ANSI C forbids braced
groups within expressions */
ch += 'a' - 'A';
size = LONG;
}
if (ch == '\0')
return(-1);
if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
&fileended) && ptr)
nmatch++;
/* breaks %n */
/* if (fileended) {
return(nmatch? nmatch: -1);
} */
break;
case ' ':
case '\n':
case '\t':
case '\r':
case '\f':
case '\v':
while (((nchars++, ch1 = scan_getc(iop))!=EOF) && (_sctab[ch1] & SPC))
;
if (ch1 != EOF)
{
scan_ungetc(ch1, iop);
}
nchars--;
break;
 
default:
def:
ch1 = scan_getc(iop);
if (ch1 != EOF) nchars++;
if (ch1 != ch) {
if (ch1==EOF)
return(-1);
scan_ungetc(ch1, iop);
nchars--;
return(nmatch);
}
}
}
 
static int
_innum(void *ptr, int type, int len, int size, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr)
{
register char *np;
char numbuf[64];
register c, base;
int expseen, scale, negflg, c1, ndigit;
long lcval;
int cpos;
 
if (type=='c' || type=='s' || type=='[')
return(_instr(ptr, type, len,
iop, scan_getc, scan_ungetc, eofptr));
lcval = 0;
ndigit = 0;
scale = INT;
if (type=='e'||type=='f'||type=='g')
scale = FLOAT;
base = 10;
if (type=='o')
base = 8;
else if (type=='x')
base = 16;
np = numbuf;
expseen = 0;
negflg = 0;
while (((nchars++, c = scan_getc(iop)) != EOF) && (_sctab[c] & SPC))
;
if (c == EOF) nchars--;
if (c=='-') {
negflg++;
*np++ = c;
c = scan_getc(iop);
nchars++;
len--;
} else if (c=='+') {
len--;
c = scan_getc(iop);
nchars++;
}
cpos = 0;
for ( ; --len>=0; *np++ = c, c = scan_getc(iop), nchars++) {
cpos++;
if (c == '0' && cpos == 1 && type == 'i')
base = 8;
if ((c == 'x' || c == 'X') && (type == 'i' || type == 'x')
&& cpos == 2 && lcval == 0)
{
base = 16;
continue;
}
if (isdigit(c)
|| (base==16 && (('a'<=c && c<='f') || ('A'<=c && c<='F')))) {
ndigit++;
if (base==8)
lcval <<=3;
else if (base==10)
lcval = ((lcval<<2) + lcval)<<1;
else
lcval <<= 4;
c1 = c;
if (isdigit(c))
c -= '0';
else if ('a'<=c && c<='f')
c -= 'a'-10;
else
c -= 'A'-10;
lcval += c;
c = c1;
continue;
} else if (c=='.') {
if (base!=10 || scale==INT)
break;
ndigit++;
continue;
} else if ((c=='e'||c=='E') && expseen==0) {
if (base!=10 || scale==INT || ndigit==0)
break;
expseen++;
*np++ = c;
c = scan_getc(iop);
nchars++;
if (c!='+'&&c!='-'&&('0'>c||c>'9'))
break;
} else
break;
}
if (negflg)
lcval = -lcval;
if (c != EOF) {
scan_ungetc(c, iop);
*eofptr = 0;
} else
*eofptr = 1;
nchars--;
if (ptr==NULL || np==numbuf || (negflg && np==numbuf+1) ) /* gene dykes*/
return(0);
*np++ = 0;
switch((scale<<4) | size) {
 
case (FLOAT<<4) | SHORT:
case (FLOAT<<4) | REGULAR:
*(float *)ptr = atof(numbuf);
break;
 
case (FLOAT<<4) | LONG:
*(double *)ptr = atof(numbuf);
break;
 
case (FLOAT<<4) | LONGDOUBLE:
*(long double *)ptr = _atold(numbuf);
break;
 
case (INT<<4) | SHORT:
*(short *)ptr = (short)lcval;
break;
 
case (INT<<4) | REGULAR:
*(int *)ptr = (int)lcval;
break;
 
case (INT<<4) | LONG:
case (INT<<4) | LONGDOUBLE:
*(long *)ptr = lcval;
break;
}
return(1);
}
 
static int
_instr(char *ptr, int type, int len, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr)
{
register ch;
register char *optr;
int ignstp;
 
*eofptr = 0;
optr = ptr;
if (type=='c' && len==30000)
len = 1;
ignstp = 0;
if (type=='s')
ignstp = SPC;
while ((nchars++, ch = scan_getc(iop)) != EOF && _sctab[ch] & ignstp)
;
ignstp = SPC;
if (type=='c')
ignstp = 0;
else if (type=='[')
ignstp = STP;
while (ch!=EOF && (_sctab[ch]&ignstp)==0) {
if (ptr)
*ptr++ = ch;
if (--len <= 0)
break;
ch = scan_getc(iop);
nchars++;
}
if (ch != EOF) {
if (len > 0)
{
scan_ungetc(ch, iop);
nchars--;
}
*eofptr = 0;
} else
{
nchars--;
*eofptr = 1;
}
if (ptr && ptr!=optr) {
if (type!='c')
*ptr++ = '\0';
return(1);
}
return(0);
}
 
static const char *
_getccl(const unsigned char *s)
{
register c, t;
 
t = 0;
if (*s == '^') {
t++;
s++;
}
for (c = 0; c < (sizeof _sctab / sizeof _sctab[0]); c++)
if (t)
_sctab[c] &= ~STP;
else
_sctab[c] |= STP;
if ((c = *s) == ']' || c == '-') { /* first char is special */
if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
s++;
}
while ((c = *s++) != ']') {
if (c==0)
return((const char *)--s);
else if (c == '-' && *s != ']' && s[-2] < *s) {
for (c = s[-2] + 1; c < *s; c++)
if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
} else if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
}
return((const char *)s);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fclose.c
0,0 → 1,39
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int fclose(FILE *f)
{
int r;
 
r = EOF;
if (!f)
return r;
if (f->_flag & (_IOREAD|_IOWRT|_IORW)
&& !(f->_flag&_IOSTRG))
{
r = fflush(f);
if (close(fileno(f)) < 0)
r = EOF;
if (f->_flag&_IOMYBUF)
free(f->_base);
}
if (f->_flag & _IORMONCL && f->_name_to_remove)
{
remove(f->_name_to_remove);
free(f->_name_to_remove);
f->_name_to_remove = 0;
}
f->_cnt = 0;
f->_base = 0;
f->_ptr = 0;
f->_bufsiz = 0;
f->_flag = 0;
f->_file = -1;
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/feof.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef feof
int
feof(FILE *stream)
{
return stream->_flag & _IOEOF;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ferror.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef ferror
int ferror(FILE *stream)
{
return stream->_flag & _IOERR;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fflush.c
0,0 → 1,41
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int fflush(FILE *f)
{
char *base;
int n, rn;
if(!f) return 0;
if(f->std_ops && STM_OP(f,flush))
return STM_OP(f,flush)(f);
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base = f->_base) != NULL
&& (rn = n = f->_ptr - base) > 0)
{
f->_ptr = base;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
do {
n = write(fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
} while (rn > 0);
_dosemu_flush(fileno(f));
}
if (f->_flag & _IORW)
{
f->_cnt = 0;
f->_flag &= ~(_IOWRT|_IOREAD);
f->_ptr = f->_base;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgetc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int fgetc(FILE *f)
{
return __getc(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgetpos.c
0,0 → 1,14
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <errno.h>
 
int fgetpos(FILE *stream, fpos_t *pos)
{
if (stream && pos)
{
*pos = (fpos_t)ftell(stream);
return 0;
}
errno = EFAULT;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgets.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
char * fgets(char *s, int n, FILE *f)
{
int c=0;
char *cs;
cs = s;
while (--n>0 && (c = __getc(f)) != EOF)
{
*cs++ = c;
if (c == '\n') break;
}
if (c == EOF && cs == s) return NULL;
*cs++ = '\0';
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/filbuf.c
0,0 → 1,62
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
int _filbuf(FILE *f)
{
int size;
char c;
 
if (f->_flag & _IORW)
f->_flag |= _IOREAD;
 
if ((f->_flag&_IOREAD) == 0)
return EOF;
if (f->_flag&(_IOSTRG|_IOEOF))
return EOF;
tryagain:
if (f->_base==NULL) {
if (f->_flag&_IONBF) {
f->_base = &c;
goto tryagain;
}
size = 512;
if ((f->_base = malloc(size)) == NULL) {
f->_flag |= _IONBF;
goto tryagain;
}
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
}
if (f == stdin) {
if (stdout->_flag&_IOLBF)
fflush(stdout);
if (stderr->_flag&_IOLBF)
fflush(stderr);
}
if(f->std_ops && STM_OP(f,read))
{
f->_cnt=STM_OP(f,read)(f,f->_base,f->_flag & _IONBF ? 1 : f->_bufsiz);
} else {
f->_cnt = read(fileno(f), f->_base,f->_flag & _IONBF ? 1 : f->_bufsiz);
}
f->_ptr = f->_base;
if (f->_flag & _IONBF && f->_base == &c)
f->_base = NULL;
if (--f->_cnt < 0) {
if (f->_cnt == -1) {
f->_flag |= _IOEOF;
if (f->_flag & _IORW)
f->_flag &= ~_IOREAD;
} else
f->_flag |= _IOERR;
f->_cnt = 0;
return EOF;
}
return *f->_ptr++ & 0377;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/flsbuf.c
0,0 → 1,98
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int
_flsbuf(int c, FILE *f)
{
char *base;
int n, rn;
char c1;
int size;
 
if (f->_flag & _IORW)
{
f->_flag |= _IOWRT;
f->_flag &= ~(_IOEOF|_IOREAD);
}
 
if ((f->_flag&_IOWRT)==0)
return EOF;
 
tryagain:
if (f->_flag&_IOLBF)
{
base = f->_base;
*f->_ptr++ = c;
if ((rn = f->_ptr - base) >= f->_bufsiz || c == '\n')
{
f->_ptr = base;
f->_cnt = 0;
}
else
{
/* we got here because _cnt is wrong, so fix it */
f->_cnt = -rn;
rn = n = 0;
}
}
else
if (f->_flag&_IONBF)
{
c1 = c;
rn = 1;
base = &c1;
f->_cnt = 0;
}
else
{
if ((base=f->_base)==NULL)
{
size = 512;
if ((f->_base=base=malloc(size)) == NULL)
{
f->_flag |= _IONBF;
goto tryagain;
}
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
if (f==stdout)
{
f->_flag |= _IOLBF;
f->_ptr = base;
goto tryagain;
}
rn = n = 0;
}
else
rn = f->_ptr - base;
f->_ptr = base;
f->_cnt = f->_bufsiz;
}
while (rn > 0)
{
if(f->std_ops && STM_OP(f,write))
{
n=STM_OP(f,write)(f,base,rn);
} else {
n = write(fileno(f), base, rn);
}
if (n <= 0)
{
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
}
if ((f->_flag&(_IOLBF|_IONBF)) == 0)
{
f->_cnt--;
*f->_ptr++ = c;
}
return c;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fopen.c
0,0 → 1,74
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/dosio.h>
 
FILE * fopen(const char *file, const char *mode)
{
FILE *f;
int fd, rw, oflags = 0;
char tbchar;
 
if (file == 0)
return 0;
if (mode == 0)
return 0;
 
f = __alloc_file();
if (f == NULL)
return NULL;
 
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
 
switch (*mode)
{
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
 
fd = open(file, oflags, 0666);
if (fd < 0)
return NULL;
 
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
 
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IORW;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
 
f->_base = f->_ptr = NULL;
f->std_ops=NULL;
// __libclog_printf("fopen: return=%x\n",f);
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fprintf.c
0,0 → 1,28
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fprintf(register FILE *iop, const char *fmt, ...)
{
int len;
char localbuf[BUFSIZ];
va_list va;
va_start(va, fmt);
if (iop->_flag & _IONBF)
{
iop->_flag &= ~_IONBF;
iop->_ptr = iop->_base = localbuf;
iop->_bufsiz = BUFSIZ;
len = _doprnt(fmt, va, iop);
fflush(iop);
iop->_flag |= _IONBF;
iop->_base = NULL;
iop->_bufsiz = NULL;
iop->_cnt = 0;
}
else
len = _doprnt(fmt, va, iop);
va_end(va);
return ferror(iop) ? EOF : len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fputc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int fputc(int c, FILE *fp)
{
return __putc(c, fp);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fputs.c
0,0 → 1,34
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fputs(const char *s, FILE *f)
{
int r = 0;
int c;
int unbuffered;
char localbuf[BUFSIZ];
 
unbuffered = f->_flag & _IONBF;
if (unbuffered)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = localbuf;
f->_bufsiz = BUFSIZ;
}
 
while ((c = *s++))
r = __putc(c, f);
 
if (unbuffered)
{
fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = NULL;
f->_cnt = 0;
}
 
return(r);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fread.c
0,0 → 1,39
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
{
char *ptr = (char *)vptr;
int s;
int c;
 
// __libclog_printf("fread(%x,%u,%u,%x)\n",vptr,size,count,iop);
 
s = size * count;
while (s > 0) {
if (iop->_cnt < s) {
if (iop->_cnt > 0) {
memcpy(ptr, iop->_ptr, iop->_cnt);
ptr += iop->_cnt;
s -= iop->_cnt;
}
/*
* filbuf clobbers _cnt & _ptr,
* so don't waste time setting them.
*/
if ((c = _filbuf(iop)) == EOF)
break;
*ptr++ = c;
s--;
}
if (iop->_cnt >= s) {
memcpy(ptr, iop->_ptr, s);
iop->_ptr += s;
iop->_cnt -= s;
return count;
}
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/freopen.c
0,0 → 1,66
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/dosio.h>
 
FILE *
freopen(const char *file, const char *mode, FILE *f)
{
int fd, rw, oflags=0;
char tbchar;
 
if (file == 0 || mode == 0 || f == 0)
return 0;
 
rw = (mode[1] == '+');
 
fclose(f);
 
switch (*mode) {
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return NULL;
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
 
fd = open(file, oflags, 0666);
if (fd < 0)
return NULL;
 
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
 
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IORW;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
 
f->_base = f->_ptr = NULL;
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/frlist.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/local.h>
 
static __file_rec __initial_file_rec = {
0,
3,
{ stdin, stdout, stderr }
};
 
__file_rec *__file_rec_list = &__initial_file_rec;
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fscanf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
fscanf(FILE *f, const char *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _doscan(f, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fseek.c
0,0 → 1,40
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
#include <fcntl.h>
#include <libc/dosio.h>
 
int
fseek(FILE *f, long offset, int ptrname)
{
long p = -1; /* can't happen? */
if(f && f->std_ops && STM_OP(f,seek))
return STM_OP(f,seek)(f,offset,ptrname);
f->_flag &= ~_IOEOF;
if (f->_flag & _IOREAD)
{
if ((ptrname == SEEK_CUR) && f->_base && !(f->_flag & _IONBF))
{
offset += ftell(f);
ptrname = SEEK_SET;
}
 
if (f->_flag & _IORW)
{
f->_ptr = f->_base;
f->_flag &= ~_IOREAD;
}
p = lseek(fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
}
else if (f->_flag & (_IOWRT|_IORW))
{
p = fflush(f);
return lseek(fileno(f), offset, ptrname) == -1 || p == EOF ?
-1 : 0;
}
return p==-1 ? -1 : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fsetpos.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <errno.h>
 
int
fsetpos(FILE *stream, const fpos_t *pos)
{
if (stream && pos)
{
fseek(stream, (long)(*pos), SEEK_SET);
return 0;
}
errno = EFAULT;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ftell.c
0,0 → 1,67
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
#include <fcntl.h>
#include <libc/dosio.h>
 
long
ftell(FILE *f)
{
long tres;
int adjust=0;
int idx;
 
if (f->_cnt < 0)
f->_cnt = 0;
if (f->_flag&_IOREAD)
{
/* When reading files, the file position known by `lseek' is
at the end of the buffered portion of the file. So `adjust'
is negative (current buf position is BEFORE the one returned
by `lseek') and, for TEXT files, it gets decremented (larger
in absolute value) for every NL from current pos to the end
of the buffer, to account for stripped CR characters. */
adjust = - f->_cnt;
 
if (__file_handle_modes[f->_file] & O_TEXT) /* if a text file */
{
if (f->_cnt)
{
char *cp;
 
/* For every char in buf AFTER current pos... */
for (cp=f->_ptr + f->_cnt - 1; cp >= f->_ptr; cp--)
if (*cp == '\n') /* ...if it's LF... */
adjust--; /* ...there was a CR also */
}
}
}
else if (f->_flag&(_IOWRT|_IORW))
{
/* When writing a file, the current file position known by `lseek'
is at the beginning of the buffered portion of the file. We
have to adjust it by our offset from the beginning of the buffer,
and account for the CR characters which will be added by `write'. */
if (f->_flag&_IOWRT && f->_base && (f->_flag&_IONBF)==0)
{
int lastidx = adjust = f->_ptr - f->_base;
 
if (__file_handle_modes[f->_file] & O_TEXT)
for (idx=0; idx < lastidx; idx++)
if (f->_base[idx] == '\n')
adjust++;
}
}
else
return -1;
if(f && f->std_ops && STM_OP(f,seek))
tres=STM_OP(f,seek)(f,0,1);
else
tres = lseek(fileno(f), 0L, 1);
if (tres<0)
return tres;
tres += adjust;
return tres;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fwalk.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/local.h>
 
void
_fwalk(void (*func)(FILE *))
{
__file_rec *fr;
int i;
 
for (fr=__file_rec_list; fr; fr=fr->next)
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag)
func(fr->files[i]);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fwrite.c
0,0 → 1,45
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libc/file.h>
 
size_t
fwrite(const void *vptr, size_t size, size_t count, FILE *f)
{
const char *ptr = (const char *)vptr;
register int s;
 
s = size * count;
 
// __libclog_printf("fwrite(%x,%u,%u,%u)\n",vptr,size,count,f->_file);
 
if (f->_flag & _IOLBF)
while (s > 0) {
if (--f->_cnt > -f->_bufsiz && *(const char *)ptr != '\n')
*f->_ptr++ = *(const char *)ptr++;
else if (_flsbuf(*(const char *)ptr++, f) == EOF)
break;
s--;
}
else while (s > 0) {
if (f->_cnt < s) {
if (f->_cnt > 0) {
memcpy(f->_ptr, ptr, f->_cnt);
ptr += f->_cnt;
f->_ptr += f->_cnt;
s -= f->_cnt;
}
if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
s--;
}
if (f->_cnt >= s) {
memcpy(f->_ptr, ptr, s);
f->_ptr += s;
f->_cnt -= s;
return count;
}
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int getc(FILE *f)
{
return fgetc(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getchar.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef getchar
int getchar(void)
{
return fgetc(stdin);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/gets.c
0,0 → 1,17
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
char *
gets(char *s)
{
int c;
char *cs;
 
cs = s;
while ((c = getchar()) != '\n' && c != EOF)
*cs++ = c;
if (c == EOF && cs==s)
return NULL;
*cs++ = '\0';
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getw.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
getw(FILE *f)
{
int i;
char *p;
int w;
 
p = (char *)&w;
for (i=sizeof(int); --i>=0;)
*p++ = getc(f);
if (feof(f))
return EOF;
return w;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/perror.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <errno.h>
 
void
perror(const char *s)
{
fprintf(stderr, "%s: %s\n", s, strerror(errno));
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/printf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
printf(const char *fmt, ...)
{
int len;
va_list va;
va_start(va, fmt);
 
len = _doprnt(fmt, va, stdout);
va_end(va);
return ferror(stdout) ? EOF : len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int putc(int c, FILE *fp)
{
return fputc(c, fp);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putchar.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef putchar
int
putchar(int c)
{
return fputc(c, stdout);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/puts.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
int
puts(const char *s)
{
int c;
 
while ((c = *s++))
putchar(c);
return putchar('\n');
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putw.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
putw(int w, FILE *f)
{
char *p;
int i;
 
p = (char *)&w;
for (i=sizeof(int); --i>=0;)
putc(*p++, f);
return ferror(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/remove.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
#include <stdio.h>
#include <errno.h>
#include <libc/dosio.h>
#include <menuet/os.h>
 
int remove(const char *fn)
{
struct systree_info2 inf;
int res;
_fixpath(fn,inf.name);
inf.command = 8;
inf.file_offset_low = inf.file_offset_high = 0;
inf.size = inf.data_pointer = 0;
res = __kolibri__system_tree_access2(&inf);
if (res == 0) return 0;
if (res == 5) errno = ENOENT;
else errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/rename.c
0,0 → 1,74
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* ------------------------- rename() for DJGPP -------------------------- */
 
/*
* An implementation of rename() which can move both files AND
* directories on the same filesystem (in the DOS world this means
* the same logical drive). Most cases are simply passed to the
* DOS Int 21h/AH=56h function. Special treatment is required for
* renaming (moving) directories which don't share their parent
* directory, because DOS won't allow this. This is called ``Prune
* and graft'' operation. Most of the code below handles this
* special case. It recursively creates subdirectories at the
* target path, moves regular files there, then deletes the (empty)
* directories at the source.
*
* An alternative (and much faster) implementation would be to access
* the parent directories of the source and the target at the disk
* sector level and rewrite them with BIOS calls. However, this won't
* work for networked drives and will leave the file system in an
* inconsistent state, should the machine crash before the operation
* is completed. (A hybrid approach which uses the fast method when
* possible and the slow one otherwise, is left as an exercise for the
* ambitious readers. ;-)
*/
 
#include <libc/stubs.h>
#include <libc/bss.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <io.h>
#include <sys/stat.h>
#include <dir.h>
#include <fcntl.h>
 
// \begin{diamond}[23.02.2007]
// this is the only solution allowed by existing Kolibri system functions
// it is better than nothing :)
// But renaming of large files will be time-consuming operation...
// and renaming of directories is impossible...
 
int rename(const char *old, const char *new)
{
int f1,f2;
char* data;
int bytes;
f1 = dosemu_open(old,O_RDONLY);
if (f1 < 0) {errno = ENOENT; return -1;}
f2 = dosemu_open(new,O_WRONLY|O_CREAT|O_EXCL);
if (f2 < 0) {dosemu_close(f1); errno = EACCES; return -1;}
data = malloc(32768);
if (!data) {dosemu_close(f2); dosemu_close(f1); errno = ENOMEM; return -1;}
do
{
bytes = dosemu_read(f1, data, 32768);
if (bytes >= 0)
bytes = dosemu_write(f2, data, bytes);
} while (bytes == 32768);
free(data);
dosemu_close(f2);
dosemu_close(f1);
if (bytes == -1)
{
errno = EACCES;
return -1;
}
remove(old);
return 0;
}
 
// \end{diamond}[23.02.2007]
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/rewind.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
 
void rewind(FILE *f)
{
fflush(f);
lseek(fileno(f), 0L, SEEK_SET);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~(_IOERR|_IOEOF);
if (f->_flag & _IORW)
f->_flag &= ~(_IOREAD|_IOWRT);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/scanf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
scanf(const char *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _doscan(stdin, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setbuf.c
0,0 → 1,13
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
void
setbuf(FILE *f, char *buf)
{
if (buf)
setvbuf(f, buf, _IOFBF, BUFSIZ);
else
setvbuf(f, 0, _IONBF, BUFSIZ);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setbuffe.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <stdlib.h>
 
void setbuffer(FILE *f, void *buf, int size)
{
if (buf)
setvbuf(f, buf, _IOFBF, size);
else
setvbuf(f, 0, _IONBF, 0);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setlineb.c
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
void setlinebuf(FILE *f)
{
setvbuf(f, 0, _IOLBF, BUFSIZ);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setvbuf.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
int setvbuf(FILE *f, char *buf, int type, size_t len)
{
int mine=0;
if (!f)
return -1;
fflush(f);
switch (type)
{
case _IOFBF:
case _IOLBF:
if (len <= 0)
return -1;
if (buf == 0)
{
buf = (char *)malloc(len);
if (buf == 0)
return -1;
mine = 1;
}
case _IONBF:
if (f->_base != NULL && f->_flag & _IOMYBUF)
free(f->_base);
f->_cnt = 0;
 
f->_flag &= ~(_IONBF|_IOFBF|_IOLBF);
f->_flag |= type;
if (type != _IONBF)
{
if (mine)
f->_flag |= _IOMYBUF;
f->_ptr = f->_base = buf;
f->_bufsiz = len;
}
else
{
f->_base = 0;
f->_bufsiz = 0;
}
return 0;
default:
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/sprintf.c
0,0 → 1,21
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <limits.h>
#include <libc/file.h>
 
int
sprintf(char *str, const char *fmt, ...)
{
FILE _strbuf;
int len;
va_list va;
va_start(va, fmt);
 
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = INT_MAX;
len = _doprnt(fmt, va, &_strbuf);
va_end(va);
*_strbuf._ptr = 0;
return len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/sscanf.c
0,0 → 1,25
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
#include <libc/unconst.h>
 
int
sscanf(const char *str, const char *fmt, ...)
{
int r;
va_list a=0;
FILE _strbuf;
 
va_start(a, fmt);
 
_strbuf._flag = _IOREAD|_IOSTRG;
_strbuf._ptr = _strbuf._base = unconst(str, char *);
_strbuf._cnt = 0;
while (*str++)
_strbuf._cnt++;
_strbuf._bufsiz = _strbuf._cnt;
r = _doscan(&_strbuf, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdaux.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdaux = {
0, 0, 0, 0,
_IORW | _IONBF,
4
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stderr.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stderr = {
0, 0, 0, 0,
_IOWRT | _IONBF,
2
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdin.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdin = {
0, 0, 0, 0,
_IOREAD | _IOLBF,
0
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdiohk.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/local.h>
 
static void fcloseall_helper(FILE *f)
{
fflush(f);
if (fileno(f) > 2)
fclose(f);
}
 
void __stdio_cleanup_proc(void)
{
_fwalk(fcloseall_helper);
}
 
void (*__stdio_cleanup_hook)(void) = __stdio_cleanup_proc;
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdout.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdout = {
0, 0, 0, 0,
_IOWRT | _IOFBF,
1
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdprn.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdprn = {
0, 0, 0, 0,
_IOWRT | _IOLBF,
3
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/tmpfile.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <libc/file.h>
 
FILE *
tmpfile(void)
{
FILE *f;
char *temp_name;
char *n_t_r;
 
temp_name = tmpnam(0);
if (temp_name == 0)
return 0;
 
n_t_r = (char *)malloc(strlen(temp_name)+1);
if (!n_t_r)
return 0;
 
f = fopen(temp_name, (_fmode & O_TEXT) ? "wt+" : "wb+");
if (f)
{
f->_flag |= _IORMONCL;
f->_name_to_remove = n_t_r;
strcpy(f->_name_to_remove, temp_name);
}
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/tmpnam.c
0,0 → 1,71
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <libc/bss.h>
 
static char *tmp_dir;
static int tmp_len;
static int tmp_bss_count = -1;
 
static void
try(const char *var)
{
static char buf[L_tmpnam];
 
char *t = getenv(var);
if (t == 0)
return;
 
tmp_len = strlen(t);
strcpy(buf, t);
if (buf[tmp_len - 1] != '/' && buf[tmp_len - 1] != '\\')
buf[tmp_len++] = '/', buf[tmp_len] = 0;
 
if (access(buf, D_OK))
return;
 
tmp_dir = buf;
}
 
char *
tmpnam(char *s)
{
static char static_buf[L_tmpnam];
static char tmpcount[] = "dj000000";
int i;
 
if (tmp_bss_count != __bss_count)
{
tmp_bss_count = __bss_count;
 
if (tmp_dir == 0) try("TMPDIR");
if (tmp_dir == 0) try("TEMP");
if (tmp_dir == 0) try("TMP");
if (tmp_dir == 0)
{
static char def[] = "c:/";
tmp_dir = def;
tmp_len = 3;
}
}
 
if (!s)
s = static_buf;
strcpy(s, tmp_dir);
 
do {
/* increment the "count" starting at the first digit (backwards order) */
for (i=2; tmpcount[i] == '9' && i < 8; tmpcount[i] = '0', i++);
if (i < 8)
tmpcount[i]++;
 
strcpy(s+tmp_len, tmpcount);
 
} while (access(s, F_OK)==0); /* until file doesn't exist */
 
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ungetc.c
0,0 → 1,26
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
ungetc(int c, FILE *f)
{
if (c == EOF
|| (f->_flag & (_IOREAD|_IORW)) == 0
|| f->_ptr == NULL
|| f->_base == NULL)
return EOF;
 
if (f->_ptr == f->_base)
{
if (f->_cnt == 0)
f->_ptr++;
else
return EOF;
}
 
f->_cnt++;
*--f->_ptr = c;
 
return c;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vfprintf.c
0,0 → 1,27
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
vfprintf(FILE *f, const char *fmt, va_list ap)
{
int len;
char localbuf[BUFSIZ];
 
if (f->_flag & _IONBF)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = localbuf;
f->_bufsiz = BUFSIZ;
len = _doprnt(fmt, ap, f);
(void)fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = 0;
f->_cnt = 0;
}
else
len = _doprnt(fmt, ap, f);
return (ferror(f) ? EOF : len);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vprintf.c
0,0 → 1,13
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
vprintf(const char *fmt, va_list ap)
{
int len;
 
len = _doprnt(fmt, ap, stdout);
return (ferror(stdout) ? EOF : len);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vsprintf.c
0,0 → 1,19
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <libc/file.h>
 
int
vsprintf(char *str, const char *fmt, va_list ap)
{
FILE f;
int len;
 
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = INT_MAX;
len = _doprnt(fmt, ap, &f);
*f._ptr = 0;
return len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/Makefile
0,0 → 1,5
THIS_SRCS = abort.c abs.c atexit.c atof.c atoi.c atol.c atold.c bsearch.c \
calloc.c div.c exit.c getenv.c labs.c ldiv.c malloc.c qsort.c \
rand.c strtod.c strtol.c strtold.c strtoul.c system.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/abort.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <unistd.h>
#include <io.h>
#include <assert.h>
 
static char msg[] = "Abort!\n";
 
void abort()
{
__libclog_printf(msg);
exit(-1);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/abs.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int
abs(int j)
{
return j<0 ? -j : j;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/atexit.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <libc/atexit.h>
 
int
atexit(void (*a)(void))
{
struct __atexit *ap;
if (a == 0)
return -1;
ap = (struct __atexit *)malloc(sizeof(struct __atexit));
if (!ap)
return -1;
ap->__next = __atexit_ptr;
ap->__function = a;
__atexit_ptr = ap;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/atof.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
double
atof(const char *ascii)
{
return strtod(ascii, 0);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/atoi.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
int
atoi(const char *str)
{
return (int)strtol(str, 0, 10);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/atol.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
long
atol(const char *str)
{
return strtol(str, 0, 10);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/atold.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
long double
_atold(const char *ascii)
{
return _strtold(ascii, 0);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/bsearch.c
0,0 → 1,26
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <libc/unconst.h>
 
void *
bsearch(const void *key, const void *base0, size_t nelem,
size_t size, int (*cmp)(const void *ck, const void *ce))
{
char *base = unconst(base0, char *);
int lim, cmpval;
void *p;
 
for (lim = nelem; lim != 0; lim >>= 1)
{
p = base + (lim >> 1) * size;
cmpval = (*cmp)(key, p);
if (cmpval == 0)
return p;
if (cmpval > 0)
{ /* key > p: move right */
base = (char *)p + size;
lim--;
} /* else move left */
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/calloc.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
 
void *
calloc(size_t size, size_t nelem)
{
void *rv = malloc(size*nelem);
if (rv)
memset(rv, 0, size*nelem);
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/div.c
0,0 → 1,24
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
div_t
div(int num, int denom)
{
div_t r;
 
if (num > 0 && denom < 0) {
num = -num;
denom = -denom;
}
r.quot = num / denom;
r.rem = num % denom;
if (num < 0 && denom > 0)
{
if (r.rem > 0)
{
r.quot++;
r.rem -= denom;
}
}
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/exit.c
0,0 → 1,37
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <dos.h>
#include <io.h>
#include <libc/atexit.h>
 
struct __atexit *__atexit_ptr = 0;
 
extern void (*__stdio_cleanup_hook)(void);
 
/* typedef void (*FUNC)(void);
extern FUNC djgpp_first_dtor[] __asm__("djgpp_first_dtor");
extern FUNC djgpp_last_dtor[] __asm__("djgpp_last_dtor"); */
 
int keypress_at_exit=0;
 
void exit(int status)
{
int i;
struct __atexit *a = __atexit_ptr;
// dosemu_atexit(); // <- this function is already in atexit list
// (see crt1.c). - diamond
/* if(keypress_at_exit) while(!__menuet__getkey()); */
while (a)
{
(a->__function)();
a = a->__next;
}
/* if (__stdio_cleanup_hook)
__stdio_cleanup_hook();
for (i=0; i<djgpp_last_dtor-djgpp_first_dtor; i++)
djgpp_first_dtor[i]();*/
_exit(status);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/getenv.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
 
extern char * __libc_getenv(const char *name); // from crt0/env.c
char * getenv(const char *name)
{
return __libc_getenv(name);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/labs.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
long
labs(long j)
{
return j<0 ? -j : j;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/ldiv.c
0,0 → 1,25
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
ldiv_t
ldiv(long num, long denom)
{
ldiv_t r;
 
if (num > 0 && denom < 0)
{
num = -num;
denom = -denom;
}
r.quot = num / denom;
r.rem = num % denom;
if (num < 0 && denom > 0)
{
if (r.rem > 0)
{
r.quot++;
r.rem -= denom;
}
}
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/malloc.c
0,0 → 1,358
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
 
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <menuet/sem.h>
 
typedef struct BLOCK {
size_t size;
struct BLOCK *next;
int bucket;
} BLOCK;
 
#define BEFORE(bp) ((BLOCK *)((char *)bp - *(int *)((char *)bp - 4) - 8))
#define BEFSZ(bp) (*(size_t *)((char *)bp - 4))
#define ENDSZ(bp) (*(size_t *)((char *)bp + bp->size + 4))
#define AFTER(bp) ((BLOCK *)((char *)bp + bp->size + 8))
#define DATA(bp) ((char *)&(bp->next))
 
#define NUMSMALL 0
#define ALIGN 8
#define SMALL (NUMSMALL*ALIGN)
 
DECLARE_STATIC_SEM(malloc_mutex)
 
static BLOCK *slop = 0;
static BLOCK *freelist[30];
#if NUMSMALL
static BLOCK *smallblocks[NUMSMALL];
#endif
 
static inline void malloc_lock(void)
{
sem_lock(&malloc_mutex);
}
 
static inline void malloc_unlock(void)
{
sem_unlock(&malloc_mutex);
}
 
#define MIN_SAVE_EXTRA 64
#define BIG_BLOCK 4096
 
#define DEBUG 0
 
#if DEBUG
static void
check(BLOCK *b)
{
printf("check %08x %d %08x %d\n", b, b->size, &(ENDSZ(b)), ENDSZ(b));
}
#define CHECK(p) do { check(p); assert(p->size == ENDSZ(p)); consistency(); } while (0)
#define CHECK1(p) do { check(p); assert(p->size == ENDSZ(p)); } while (0)
static void
consistency()
{
#if 0
int b;
BLOCK *bl;
if (slop)
CHECK1(slop);
for (b=0; b<32; b++)
for (bl=freelist[b]; bl; bl=bl->next)
CHECK1(bl);
#endif
}
#else
#define CHECK(p)
#endif
 
static inline int
size2bucket(size_t size)
{
int rv=0;
size>>=2;
while (size)
{
rv++;
size>>=1;
}
return rv;
}
 
static inline int
b2bucket(BLOCK *b)
{
if (b->bucket == -1)
b->bucket = size2bucket(b->size);
return b->bucket;
}
 
static inline BLOCK *
split_block(BLOCK *b, size_t size)
{
BLOCK *rv = (BLOCK *)((char *)b + size+8);
#if DEBUG
printf(" split %u/%08x to %u/%08x, %u/%08x\n",
b->size, b, size, b, b->size - size - 8, rv);
#endif
rv->size = b->size - size - 8;
rv->bucket = -1;
b->size = size;
ENDSZ(b) = b->size;
ENDSZ(rv) = rv->size;
CHECK(b);
CHECK(rv);
return rv;
}
 
#define RET(rv) CHECK(rv); ENDSZ(rv) |= 1; rv->size |= 1; return DATA(rv)
 
void * malloc(size_t size)
{
int b, chunk_size;
BLOCK *rv, **prev;
static BLOCK *expected_sbrk = 0;
 
if (size<ALIGN) size = ALIGN;
size = (size+(ALIGN-1))&~(ALIGN-1);
#if DEBUG
printf("malloc(%u)\n", size);
#endif
#if NUMSMALL
if (size < SMALL)
{
rv = smallblocks[size/ALIGN];
if (rv)
{
smallblocks[size/ALIGN] = rv->next;
return DATA(rv);
}
}
#endif
 
if (slop && slop->size >= size)
{
rv = slop;
#if DEBUG
printf(" using slop %u/%08x\n", slop->size, slop);
#endif
if (slop->size >= size+MIN_SAVE_EXTRA)
{
slop = split_block(slop, size);
#if DEBUG
printf(" remaining slop %u/%08x\n", slop->size, slop);
#endif
}
else
slop = 0;
RET(rv);
}
 
b = size2bucket(size);
prev = &(freelist[b]);
for (rv=freelist[b]; rv; prev=&(rv->next), rv=rv->next)
{
if (rv->size >= size && rv->size < size+size/4)
{
*prev = rv->next;
RET(rv);
}
}
 
while (b < 30)
{
prev = &(freelist[b]);
#if DEBUG
printf(" checking bucket %d\n", b);
#endif
for (rv=freelist[b]; rv; prev=&(rv->next), rv=rv->next)
if (rv->size >= size)
{
#if DEBUG
printf(" found size %d/%08x\n", rv->size, rv);
#endif
*prev = rv->next;
if (rv->size >= size+MIN_SAVE_EXTRA)
{
#if DEBUG
printf(" enough to save\n");
#endif
if (slop)
{
b = b2bucket(slop);
#if DEBUG
printf(" putting old slop %u/%08x on free list %d\n",
slop->size, slop, b);
#endif
slop->next = freelist[b];
freelist[b] = slop;
}
slop = split_block(rv, size);
#if DEBUG
printf(" slop size %u/%08x\n", slop->size, slop);
#endif
}
RET(rv);
}
b++;
}
 
chunk_size = size+16; /* two ends plus two placeholders */
rv = (BLOCK *)sbrk(chunk_size);
if (rv == (BLOCK *)(-1))
return 0;
#if DEBUG
printf("sbrk(%d) -> %08x, expected %08x\n", chunk_size, rv, expected_sbrk);
#endif
if (rv == expected_sbrk)
{
expected_sbrk = (BLOCK *)((char *)rv + chunk_size);
/* absorb old end-block-marker */
#if DEBUG
printf(" got expected sbrk\n");
#endif
rv = (BLOCK *)((char *)rv - 4);
}
else
{
expected_sbrk = (BLOCK *)((char *)rv + chunk_size);
#if DEBUG
printf(" disconnected sbrk\n");
#endif
/* build start-block-marker */
rv->size = 1;
rv = (BLOCK *)((char *)rv + 4);
chunk_size -= 8;
}
rv->size = chunk_size - 8;
ENDSZ(rv) = rv->size;
AFTER(rv)->size = 1;
CHECK(rv);
 
RET(rv);
}
 
static inline BLOCK *
merge(BLOCK *a, BLOCK *b, BLOCK *c)
{
int bu;
BLOCK *bp, **bpp;
 
#if DEBUG
printf(" merge %u/%08x + %u/%08x = %u\n",
a->size, a, b->size, b, a->size+b->size+8);
#endif
 
CHECK(a);
CHECK(b);
CHECK(c);
if (c == slop)
{
#if DEBUG
printf(" snipping slop %u/%08x\n", slop->size, slop);
#endif
slop = 0;
}
bu = b2bucket(c);
#if DEBUG
printf("bucket for %u/%08x is %d\n", c->size, c, bu);
#endif
bpp = freelist+bu;
for (bp=freelist[bu]; bp; bpp=&(bp->next), bp=bp->next)
{
#if DEBUG
printf(" %08x", bp);
#endif
if (bp == c)
{
#if DEBUG
printf("\n snipping %u/%08x from freelist[%d]\n", bp->size, bp, bu);
#endif
*bpp = bp->next;
break;
}
}
CHECK(c);
 
a->size += b->size + 8;
a->bucket = -1;
ENDSZ(a) = a->size;
 
CHECK(a);
return a;
}
 
void
free(void *ptr)
{
int b;
BLOCK *block;
if (ptr == 0)
return;
block = (BLOCK *)((char *)ptr-4);
 
#if NUMSMALL
if (block->size < SMALL)
{
block->next = smallblocks[block->size/ALIGN];
smallblocks[block->size/ALIGN] = block;
return;
}
#endif
 
block->size &= ~1;
ENDSZ(block) &= ~1;
block->bucket = -1;
#if DEBUG
printf("free(%u/%08x)\n", block->size, block);
#endif
 
CHECK(block);
if (! (AFTER(block)->size & 1))
{
CHECK(AFTER(block));
}
if (! (BEFSZ(block) & 1))
{
CHECK(BEFORE(block));
block = merge(BEFORE(block), block, BEFORE(block));
}
CHECK(block);
if (! (AFTER(block)->size & 1))
{
CHECK(AFTER(block));
block = merge(block, AFTER(block), AFTER(block));
}
CHECK(block);
b = b2bucket(block);
block->next = freelist[b];
freelist[b] = block;
CHECK(block);
}
 
void * realloc(void *ptr, size_t size)
{
BLOCK *b;
char *newptr;
size_t copysize;
if (ptr == 0) return malloc(size);
b = (BLOCK *)((char *)ptr-4);
copysize = b->size & ~1;
if (size <= copysize)
{
return ptr;
copysize = size;
}
newptr = (char *)malloc(size);
if (!newptr) return NULL;
memcpy(newptr, ptr, copysize);
free(ptr);
return newptr;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/qsort.c
0,0 → 1,238
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
/*-
* Copyright (c) 1980, 1983 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
/*
* qsort.c:
* Our own version of the system qsort routine which is faster by an average
* of 25%, with lows and highs of 10% and 50%.
* The THRESHold below is the insertion sort threshold, and has been adjusted
* for records of size 48 bytes.
* The MTHREShold is where we stop finding a better median.
*/
 
#define THRESH 4 /* threshold for insertion */
#define MTHRESH 6 /* threshold for median */
 
static int (*qcmp)(const void *, const void *); /* the comparison routine */
static int qsz; /* size of each record */
static int thresh; /* THRESHold in chars */
static int mthresh; /* MTHRESHold in chars */
 
/*
* qst:
* Do a quicksort
* First, find the median element, and put that one in the first place as the
* discriminator. (This "median" is just the median of the first, last and
* middle elements). (Using this median instead of the first element is a big
* win). Then, the usual partitioning/swapping, followed by moving the
* discriminator into the right place. Then, figure out the sizes of the two
* partions, do the smaller one recursively and the larger one via a repeat of
* this code. Stopping when there are less than THRESH elements in a partition
* and cleaning up with an insertion sort (in our caller) is a huge win.
* All data swaps are done in-line, which is space-losing but time-saving.
* (And there are only three places where this is done).
*/
 
static void
qst(char *base, char *max)
{
char c, *i, *j, *jj;
int ii;
char *mid, *tmp;
int lo, hi;
 
/*
* At the top here, lo is the number of characters of elements in the
* current partition. (Which should be max - base).
* Find the median of the first, last, and middle element and make
* that the middle element. Set j to largest of first and middle.
* If max is larger than that guy, then it's that guy, else compare
* max with loser of first and take larger. Things are set up to
* prefer the middle, then the first in case of ties.
*/
lo = max - base; /* number of elements as chars */
do {
mid = i = base + qsz * ((lo / qsz) >> 1);
if (lo >= mthresh)
{
j = (qcmp((jj = base), i) > 0 ? jj : i);
if (qcmp(j, (tmp = max - qsz)) > 0)
{
/* switch to first loser */
j = (j == jj ? i : jj);
if (qcmp(j, tmp) < 0)
j = tmp;
}
if (j != i)
{
ii = qsz;
do {
c = *i;
*i++ = *j;
*j++ = c;
} while (--ii);
}
}
/*
* Semi-standard quicksort partitioning/swapping
*/
for (i = base, j = max - qsz; ; )
{
while (i < mid && qcmp(i, mid) <= 0)
i += qsz;
while (j > mid)
{
if (qcmp(mid, j) <= 0)
{
j -= qsz;
continue;
}
tmp = i + qsz; /* value of i after swap */
if (i == mid)
{
/* j <-> mid, new mid is j */
mid = jj = j;
}
else
{
/* i <-> j */
jj = j;
j -= qsz;
}
goto swap;
}
if (i == mid)
{
break;
}
else
{
/* i <-> mid, new mid is i */
jj = mid;
tmp = mid = i; /* value of i after swap */
j -= qsz;
}
swap:
ii = qsz;
do {
c = *i;
*i++ = *jj;
*jj++ = c;
} while (--ii);
i = tmp;
}
/*
* Look at sizes of the two partitions, do the smaller
* one first by recursion, then do the larger one by
* making sure lo is its size, base and max are update
* correctly, and branching back. But only repeat
* (recursively or by branching) if the partition is
* of at least size THRESH.
*/
i = (j = mid) + qsz;
if ((lo = j - base) <= (hi = max - i))
{
if (lo >= thresh)
qst(base, j);
base = i;
lo = hi;
}
else
{
if (hi >= thresh)
qst(i, max);
max = j;
}
} while (lo >= thresh);
}
 
/*
* qsort:
* First, set up some global parameters for qst to share. Then, quicksort
* with qst(), and then a cleanup insertion sort ourselves. Sound simple?
* It's not...
*/
 
void
qsort(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *))
{
char *base = (char *)base0;
char c, *i, *j, *lo, *hi;
char *min, *max;
 
if (n <= 1)
return;
qsz = size;
qcmp = compar;
thresh = qsz * THRESH;
mthresh = qsz * MTHRESH;
max = base + n * qsz;
if (n >= THRESH)
{
qst(base, max);
hi = base + thresh;
}
else
{
hi = max;
}
/*
* First put smallest element, which must be in the first THRESH, in
* the first position as a sentinel. This is done just by searching
* the first THRESH elements (or the first n if n < THRESH), finding
* the min, and swapping it into the first position.
*/
for (j = lo = base; (lo += qsz) < hi; )
if (qcmp(j, lo) > 0)
j = lo;
if (j != base)
{
/* swap j into place */
for (i = base, hi = base + qsz; i < hi; )
{
c = *j;
*j++ = *i;
*i++ = c;
}
}
/*
* With our sentinel in place, we now run the following hyper-fast
* insertion sort. For each remaining element, min, from [1] to [n-1],
* set hi to the index of the element AFTER which this one goes.
* Then, do the standard insertion sort shift on a character at a time
* basis for each element in the frob.
*/
for (min = base; (hi = min += qsz) < max; )
{
while (qcmp(hi -= qsz, min) > 0)
/* void */;
if ((hi += qsz) != min) {
for (lo = min + qsz; --lo >= min; )
{
c = *lo;
for (i = j = lo; (j -= qsz) >= hi; i = j)
*i = *j;
*i = c;
}
}
}
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/rand.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
static unsigned long long next = 0;
 
int
rand(void)
{
next = next * 1103515245L + 12345;
next = (next<<15) ^ (next >> 27);
return (int)((next >> 4) & RAND_MAX);
}
 
void
srand(unsigned seed)
{
next = seed;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/strtod.c
0,0 → 1,96
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
#include <stdlib.h>
#include <libc/unconst.h>
 
double
strtod(const char *s, char **sret)
{
long double r; /* result */
int e; /* exponent */
long double d; /* scale */
int sign; /* +- 1.0 */
int esign;
int i;
int flags=0;
 
r = 0.0;
sign = 1.0;
e = 0;
esign = 1;
 
while ((*s == ' ') || (*s == '\t'))
s++;
 
if (*s == '+')
s++;
else if (*s == '-')
{
sign = -1;
s++;
}
 
while ((*s >= '0') && (*s <= '9'))
{
flags |= 1;
r *= 10.0;
r += *s - '0';
s++;
}
 
if (*s == '.')
{
d = 0.1L;
s++;
while ((*s >= '0') && (*s <= '9'))
{
flags |= 2;
r += d * (*s - '0');
s++;
d *= 0.1L;
}
}
 
if (flags == 0)
{
if (sret)
*sret = unconst(s, char *);
return 0;
}
 
if ((*s == 'e') || (*s == 'E'))
{
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
s++;
esign = -1;
}
if ((*s < '0') || (*s > '9'))
{
if (sret)
*sret = unconst(s, char *);
return r;
}
 
while ((*s >= '0') && (*s <= '9'))
{
e *= 10;
e += *s - '0';
s++;
}
}
 
if (esign < 0)
for (i = 1; i <= e; i++)
r *= 0.1L;
else
for (i = 1; i <= e; i++)
r *= 10.0;
 
if (sret)
*sret = unconst(s, char *);
return r * sign;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/strtol.c
0,0 → 1,91
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <libc/unconst.h>
 
long
strtol(const char *nptr, char **endptr, int base)
{
const char *s = nptr;
unsigned long acc;
int c;
unsigned long cutoff;
int neg = 0, any, cutlim;
 
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-')
{
neg = 1;
c = *s++;
}
else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
 
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else
{
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0)
{
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
}
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
return acc;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/strtold.c
0,0 → 1,120
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <ctype.h>
#include <libc/unconst.h>
 
static long double powten[] =
{
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L,
1e512L, 1e1024L, 1e2048L, 1e4096L
};
 
long double
_strtold(const char *s, char **sret)
{
long double r; /* result */
int e, ne; /* exponent */
int sign; /* +- 1.0 */
int esign;
int flags=0;
int l2powm1;
 
r = 0.0L;
sign = 1;
e = ne = 0;
esign = 1;
 
while(*s && isspace(*s))
s++;
 
if (*s == '+')
s++;
else if (*s == '-')
{
sign = -1;
s++;
}
 
while ((*s >= '0') && (*s <= '9'))
{
flags |= 1;
r *= 10.0L;
r += *s - '0';
s++;
}
 
if (*s == '.')
{
s++;
while ((*s >= '0') && (*s <= '9'))
{
flags |= 2;
r *= 10.0L;
r += *s - '0';
s++;
ne++;
}
}
if (flags == 0)
{
if (sret)
*sret = unconst(s, char *);
return 0.0L;
}
 
if ((*s == 'e') || (*s == 'E'))
{
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
s++;
esign = -1;
}
while ((*s >= '0') && (*s <= '9'))
{
e *= 10;
e += *s - '0';
s++;
}
}
if (esign < 0)
{
esign = -esign;
e = -e;
}
e = e - ne;
if (e < -4096)
{
/* possibly subnormal number, 10^e would overflow */
r *= 1.0e-2048L;
e += 2048;
}
if (e < 0)
{
e = -e;
esign = -esign;
}
if (e >= 8192)
e = 8191;
if (e)
{
long double d = 1.0L;
l2powm1 = 0;
while (e)
{
if (e & 1)
d *= powten[l2powm1];
e >>= 1;
l2powm1++;
}
if (esign > 0)
r *= d;
else
r /= d;
}
if (sret)
*sret = unconst(s, char *);
return r * sign;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/strtoul.c
0,0 → 1,75
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <libc/unconst.h>
 
/*
* Convert a string to an unsigned long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long
strtoul(const char *nptr, char **endptr, int base)
{
const char *s = nptr;
unsigned long acc;
int c;
unsigned long cutoff;
int neg = 0, any, cutlim;
 
/*
* See strtol for comments as to the logic used.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-')
{
neg = 1;
c = *s++;
}
else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0)
{
acc = ULONG_MAX;
errno = ERANGE;
}
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
return acc;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdlib/system.c
0,0 → 1,18
#include <libc/stubs.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <process.h>
#include <libc/dosexec.h>
#include <libc/unconst.h>
#include <assert.h>
 
int system (const char *cmdline)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/Makefile
0,0 → 1,6
THIS_SRCS = memchr.c memcmp.c memcpy.c memmove.s memset.s strcat.c \
strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strerror.c \
strlen.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c \
strspn.c strstr.c strtok.c strxfrm.c syserr1.c syserr2.c syserr3.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/memchr.c
0,0 → 1,18
#include<string.h>
#include<libc/unconst.h>
#include<assert.h>
 
void * memchr(const void *s, int c, size_t n)
{
int d0;
register void * __res;
if (!n) return NULL;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"je 1f\n\t"
"movl $1,%0\n"
"1:\tdecl %0"
:"=D" (__res), "=&c" (d0) : "a" (c),"0" (s),"1" (n));
return __res;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/memcmp.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <assert.h>
 
int
memcmp(const void *s1, const void *s2, size_t n)
{
if (n != 0)
{
const unsigned char *p1 = s1, *p2 = s2;
 
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/memcpy.c
0,0 → 1,23
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
void * memcpy(void * _dest, const void *_src, size_t _n)
{
int d0, d1, d2;
__asm__ __volatile__(
"jcxz 1f\n\t"
"rep ; movsl\n\t"
"1:\t"
"testb $2,%b4\n\t"
"je 1f\n\t"
"movsw\n"
"1:\ttestb $1,%b4\n\t"
"je 2f\n\t"
"movsb\n"
"2:"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
:"0" (_n/4), "q" (_n),"1" ((long)_dest),"2" ((long)_src)
: "memory");
return (_dest);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/memmove.s
0,0 → 1,33
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.file "memmove.s"
#include<libc/asm.h>
MK_C_SYM(memmove)
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
jecxz L2
cld
cmpl %esi,%edi
jb L3
 
std
addl %ecx,%esi
addl %ecx,%edi
decl %esi
decl %edi
L3:
rep
movsb
 
L2:
cld
popl %edi
popl %esi
movl 8(%ebp),%eax
leave
ret
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/memset.s
0,0 → 1,51
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.file "memset.s"
.text
.align 4
MK_C_SYM(memset)
pushl %ebp
movl %esp,%ebp
pushl %edi
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
cld
 
# We will handle memsets of <= 15 bytes one byte at a time.
# This avoids some extra overhead for small memsets, and
# knowing we are setting > 15 bytes eliminates some annoying
# checks in the "long move" case.
cmpl $15,%ecx
jle L3
 
# Otherwise, tile the byte value out into %eax.
# 0x41 -> 0x41414141, etc.
movb %al,%ah
movl %eax,%edx
sall $16,%eax
movw %dx,%ax
jmp L2
 
# Handle any cruft necessary to get %edi long-aligned.
L1: stosb
decl %ecx
L2: testl $3,%edi
jnz L1
 
# Now slam out all of the longs.
movl %ecx,%edx
shrl $2,%ecx
rep
stosl
 
# Finally, handle any trailing cruft. We know the high three bytes
# of %ecx must be zero, so just put the "slop count" in the low byte.
movb %dl,%cl
andb $3,%cl
L3: rep
stosb
popl %edi
movl 8(%ebp),%eax
leave
ret
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strcat.c
0,0 → 1,17
#include <string.h>
 
char * strcat(char *s, const char *append)
{
int d0, d1, d2, d3;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"decl %1\n"
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
: "0" (append),"1"(s),"2"(0),"3" (0xffffffff):"memory");
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strchr.c
0,0 → 1,20
#include <string.h>
#include <libc/unconst.h>
 
char * strchr(const char *s, int c)
{
int d0;
register char * __res;
__asm__ __volatile__(
"movb %%al,%%ah\n"
"1:\tlodsb\n\t"
"cmpb %%ah,%%al\n\t"
"je 2f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"movl $1,%1\n"
"2:\tmovl %1,%0\n\t"
"decl %0"
:"=a" (__res), "=&S" (d0) : "1" (s),"0" (c));
return __res;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strcmp.c
0,0 → 1,21
#include <string.h>
 
int strcmp(const char *s1, const char *s2)
{
int d0, d1;
register int __res;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"scasb\n\t"
"jne 2f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n\t"
"jmp 3f\n"
"2:\tsbbl %%eax,%%eax\n\t"
"orb $1,%%al\n"
"3:"
:"=a" (__res), "=&S" (d0), "=&D" (d1)
:"1" (s1),"2" (s2));
return __res;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strcoll.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
int
strcoll(const char *s1, const char *s2)
{
return strcmp(s1, s2);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strcpy.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char * strcpy(char *to, const char *from)
{
int d0, d1, d2;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S" (d0), "=&D" (d1), "=&a" (d2)
:"0" (from),"1" (to) : "memory");
return to;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strcspn.c
0,0 → 1,20
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t
strcspn(const char *s1, const char *s2)
{
const char *p, *spanp;
char c, sc;
 
for (p = s1;;)
{
c = *p++;
spanp = s2;
do {
if ((sc = *spanp++) == c)
return p - 1 - s1;
} while (sc != 0);
}
/* NOTREACHED */
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strerror.c
0,0 → 1,37
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <libc/unconst.h>
 
char *
strerror(int errnum)
{
static char ebuf[40]; /* 64-bit number + slop */
char *cp;
int v=1000000, lz=0;
 
if (errnum >= 0 && errnum < __sys_nerr)
return(unconst(__sys_errlist[errnum], char *));
 
strcpy(ebuf, "Unknown error: ");
cp = ebuf + 15;
if (errnum < 0)
{
*cp++ = '-';
errnum = -errnum;
}
while (v)
{
int d = errnum / v;
if (d || lz || (v == 1))
{
*cp++ = d+'0';
lz = 1;
}
errnum %= v;
v /= 10;
}
 
return ebuf;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strlen.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t strlen(const char *str)
{
int d0;
register int __res;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
:"=c" (__res), "=&D" (d0) :"1" (str),"a" (0), "0" (0xffffffff));
return __res;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strncat.c
0,0 → 1,24
#include <string.h>
 
char *
strncat(char *dst, const char *src, size_t n)
{
int d0, d1, d2, d3;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"decl %1\n\t"
"movl %8,%3\n"
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n"
"2:\txorl %2,%2\n\t"
"stosb"
: "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
: "0" (src),"1" (dst),"2" (0),"3" (0xffffffff), "g" (n)
: "memory");
return dst;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strncmp.c
0,0 → 1,24
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
int strncmp(const char *s1, const char *s2, size_t n)
{
register int __res;
int d0, d1, d2;
__asm__ __volatile__(
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"scasb\n\t"
"jne 3f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n"
"2:\txorl %%eax,%%eax\n\t"
"jmp 4f\n"
"3:\tsbbl %%eax,%%eax\n\t"
"orb $1,%%al\n"
"4:"
:"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
:"1" (s1),"2" (s2),"3" (n));
return __res;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strncpy.c
0,0 → 1,20
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char * strncpy(char *dst, const char *src, size_t n)
{
int d0, d1, d2, d3;
__asm__ __volatile__(
"1:\tdecl %2\n\t"
"js 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"rep\n\t"
"stosb\n"
"2:"
: "=&S" (d0), "=&D" (d1), "=&c" (d2), "=&a" (d3)
:"0" (src),"1" (dst),"2" (n) : "memory");
return dst;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strpbrk.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <libc/unconst.h>
 
char *
strpbrk(const char *s1, const char *s2)
{
const char *scanp;
int c, sc;
 
while ((c = *s1++) != 0)
{
for (scanp = s2; (sc = *scanp++) != 0;)
if (sc == c)
return unconst(s1 - 1, char *);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strrchr.c
0,0 → 1,21
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <libc/unconst.h>
 
char *
strrchr(const char *s, int c)
{
char cc = c;
const char *sp=(char *)0;
while (*s)
{
if (*s == cc)
sp = s;
s++;
}
if (cc == 0)
sp = s;
return unconst(sp, char *);
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strspn.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t
strspn(const char *s1, const char *s2)
{
const char *p = s1, *spanp;
char c, sc;
 
cont:
c = *p++;
for (spanp = s2; (sc = *spanp++) != 0;)
if (sc == c)
goto cont;
return (p - 1 - s1);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strstr.c
0,0 → 1,23
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <libc/unconst.h>
 
char *
strstr(const char *s, const char *find)
{
char c, sc;
size_t len;
 
if ((c = *find++) != 0)
{
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
return 0;
} while (sc != c);
} while (strncmp(s, find, len) != 0);
s--;
}
return unconst(s, char *);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strtok.c
0,0 → 1,51
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char *
strtok(char *s, const char *delim)
{
const char *spanp;
int c, sc;
char *tok;
static char *last;
 
 
if (s == NULL && (s = last) == NULL)
return (NULL);
 
/*
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
*/
cont:
c = *s++;
for (spanp = delim; (sc = *spanp++) != 0;) {
if (c == sc)
goto cont;
}
 
if (c == 0) { /* no non-delimiter characters */
last = NULL;
return (NULL);
}
tok = s - 1;
 
/*
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
* Note that delim must have one NUL; we stop if we see that, too.
*/
for (;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
last = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/strxfrm.c
0,0 → 1,28
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t
strxfrm(dst, src, n)
char *dst;
const char *src;
size_t n;
{
size_t r = 0;
int c;
 
if (n != 0) {
while ((c = *src++) != 0)
{
r++;
if (--n == 0)
{
while (*src++ != 0)
r++;
break;
}
*dst++ = c;
}
*dst = 0;
}
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/syserr1.c
0,0 → 1,42
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include "syserr1.h"
 
char __syserr00[] = "No Error";
char __syserr01[] = "Input to function out of range (EDOM)";
char __syserr02[] = "Output of function out of range (ERANGE)";
char __syserr03[] = "Argument list too long (E2BIG)";
char __syserr04[] = "Permission denied (EACCES)";
char __syserr05[] = "Resource temporarily unavailable (EAGAIN)";
char __syserr06[] = "Bad file descriptor (EBADF)";
char __syserr07[] = "Resource busy (EBUSY)";
char __syserr08[] = "No child processes (ECHILD)";
char __syserr09[] = "Resource deadlock avoided (EDEADLK)";
char __syserr10[] = "File exists (EEXIST)";
char __syserr11[] = "Bad address (EFAULT)";
char __syserr12[] = "File too large (EFBIG)";
char __syserr13[] = "Interrupted system call (EINTR)";
char __syserr14[] = "Invalid argument (EINVAL)";
char __syserr15[] = "Input or output error (EIO)";
char __syserr16[] = "Is a directory (EISDIR)";
char __syserr17[] = "Too many open files (EMFILE)";
char __syserr18[] = "Too many links (EMLINK)";
char __syserr19[] = "File name too long (ENAMETOOLONG)";
char __syserr20[] = "Too many open files in system (ENFILE)";
char __syserr21[] = "No such device (ENODEV)";
char __syserr22[] = "No such file or directory (ENOENT)";
char __syserr23[] = "Unable to execute file (ENOEXEC)";
char __syserr24[] = "No locks available (ENOLCK)";
char __syserr25[] = "Not enough memory (ENOMEM)";
char __syserr26[] = "No space left on drive (ENOSPC)";
char __syserr27[] = "Function not implemented (ENOSYS)";
char __syserr28[] = "Not a directory (ENOTDIR)";
char __syserr29[] = "Directory not empty (ENOTEMPTY)";
char __syserr30[] = "Inappropriate I/O control operation (ENOTTY)";
char __syserr31[] = "No such device or address (ENXIO)";
char __syserr32[] = "Operation not permitted (EPERM)";
char __syserr33[] = "Broken pipe (EPIPE)";
char __syserr34[] = "Read-only file system (EROFS)";
char __syserr35[] = "Invalid seek (ESPIPE)";
char __syserr36[] = "No such process (ESRCH)";
char __syserr37[] = "Improper link (EXDEV)";
char __syserr38[] = "No more files (ENMFILE)";
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/syserr1.h
0,0 → 1,40
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
extern char __syserr00[];
extern char __syserr01[];
extern char __syserr02[];
extern char __syserr03[];
extern char __syserr04[];
extern char __syserr05[];
extern char __syserr06[];
extern char __syserr07[];
extern char __syserr08[];
extern char __syserr09[];
extern char __syserr10[];
extern char __syserr11[];
extern char __syserr12[];
extern char __syserr13[];
extern char __syserr14[];
extern char __syserr15[];
extern char __syserr16[];
extern char __syserr17[];
extern char __syserr18[];
extern char __syserr19[];
extern char __syserr20[];
extern char __syserr21[];
extern char __syserr22[];
extern char __syserr23[];
extern char __syserr24[];
extern char __syserr25[];
extern char __syserr26[];
extern char __syserr27[];
extern char __syserr28[];
extern char __syserr29[];
extern char __syserr30[];
extern char __syserr31[];
extern char __syserr32[];
extern char __syserr33[];
extern char __syserr34[];
extern char __syserr35[];
extern char __syserr36[];
extern char __syserr37[];
extern char __syserr38[];
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/syserr2.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include "syserr1.h"
 
const char *__sys_errlist[] = {
__syserr00, __syserr01, __syserr02, __syserr03, __syserr04,
__syserr05, __syserr06, __syserr07, __syserr08, __syserr09,
__syserr10, __syserr11, __syserr12, __syserr13, __syserr14,
__syserr15, __syserr16, __syserr17, __syserr18, __syserr19,
__syserr20, __syserr21, __syserr22, __syserr23, __syserr24,
__syserr25, __syserr26, __syserr27, __syserr28, __syserr29,
__syserr30, __syserr31, __syserr32, __syserr33, __syserr34,
__syserr35, __syserr36, __syserr37, __syserr38
};
 
int __sys_nerr = sizeof(__sys_errlist) / sizeof(__sys_errlist[0]);
/programs/develop/libraries/menuetlibc/src/libc/ansi/string/syserr3.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include "syserr1.h"
 
char *sys_errlist[] = {
__syserr00, __syserr01, __syserr02, __syserr03, __syserr04,
__syserr05, __syserr06, __syserr07, __syserr08, __syserr09,
__syserr10, __syserr11, __syserr12, __syserr13, __syserr14,
__syserr15, __syserr16, __syserr17, __syserr18, __syserr19,
__syserr20, __syserr21, __syserr22, __syserr23, __syserr24,
__syserr25, __syserr26, __syserr27, __syserr28, __syserr29,
__syserr30, __syserr31, __syserr32, __syserr33, __syserr34,
__syserr35, __syserr36, __syserr37, __syserr38
};
 
int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]);
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/Makefile
0,0 → 1,4
THIS_SRCS = ctime.c difftime.c strftime.c time.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/ctime.c
0,0 → 1,1197
#include <libc/stubs.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tzfile.h>
#include <libc/unconst.h>
#include "posixrul.h"
 
#define P(s) s
#define alloc_size_t size_t
#define qsort_size_t size_t
#define fread_size_t size_t
#define fwrite_size_t size_t
 
#define ACCESS_MODE O_RDONLY|O_BINARY
#define OPEN_MODE O_RDONLY|O_BINARY
 
static char WILDABBR[] = " ";
 
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif /* !defined TRUE */
 
static const char GMT[] = "GMT";
 
struct ttinfo { /* time type information */
long tt_gmtoff; /* GMT offset in seconds */
int tt_isdst; /* used to set tm_isdst */
int tt_abbrind; /* abbreviation list index */
int tt_ttisstd; /* TRUE if transition is std time */
};
 
struct lsinfo { /* leap second information */
time_t ls_trans; /* transition time */
long ls_corr; /* correction to apply */
};
 
struct state {
int leapcnt;
int timecnt;
int typecnt;
int charcnt;
time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
char chars[(TZ_MAX_CHARS + 1 > sizeof GMT) ? TZ_MAX_CHARS + 1 : sizeof GMT];
struct lsinfo lsis[TZ_MAX_LEAPS];
};
 
struct rule {
int r_type; /* type of rule--see below */
int r_day; /* day number of rule */
int r_week; /* week number of rule */
int r_mon; /* month number of rule */
long r_time; /* transition time of rule */
};
 
#define JULIAN_DAY 0 /* Jn - Julian day */
#define DAY_OF_YEAR 1 /* n - day of year */
#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
 
/*
** Prototypes for static functions.
*/
 
static long detzcode P((const char * codep));
static const char * getzname P((const char * strp));
static const char * getnum P((const char * strp, int * nump, int min,
int max));
static const char * getsecs P((const char * strp, long * secsp));
static const char * getoffset P((const char * strp, long * offsetp));
static const char * getrule P((const char * strp, struct rule * rulep));
static void gmtload P((struct state * sp));
static void gmtsub P((const time_t * timep, long offset,
struct tm * tmp));
static void localsub P((const time_t * timep, long offset,
struct tm * tmp));
static void normalize P((int * tensptr, int * unitsptr, int base));
static void settzname P((void));
static time_t time1 P((struct tm * tmp, void (* funcp)(const time_t * const, const long, struct tm * const),
long offset));
static time_t time2 P((struct tm *tmp, void (* funcp)(const time_t * const, const long, struct tm * const),
long offset, int * okayp));
static void timesub P((const time_t * timep, long offset,
const struct state * sp, struct tm * tmp));
static int tmcomp P((const struct tm * atmp,
const struct tm * btmp));
static time_t transtime P((time_t janfirst, int year,
const struct rule * rulep, long offset));
static int tzparse P((const char * name, struct state * sp,
int lastditch));
//static void tzsetwall(void);
 
#ifdef ALL_STATE
static struct state *lclptr;
static struct state *gmtptr;
#endif /* defined ALL_STATE */
 
#ifndef ALL_STATE
static struct state lclmem;
static struct state gmtmem;
#define lclptr (&lclmem)
#define gmtptr (&gmtmem)
#endif /* State Farm */
 
static int lcl_is_set;
static int gmt_is_set;
 
char * tzname[2] = {
WILDABBR,
WILDABBR
};
 
static long
detzcode(const char * const codep)
{
long result;
int i;
 
result = 0;
for (i = 0; i < 4; ++i)
result = (result << 8) | (codep[i] & 0xff);
return result;
}
 
static void
settzname(void)
{
const struct state * const sp = lclptr;
int i;
 
tzname[0] = WILDABBR;
tzname[1] = WILDABBR;
#ifdef ALL_STATE
if (sp == NULL)
{
tzname[0] = tzname[1] = GMT;
return;
}
#endif /* defined ALL_STATE */
for (i = 0; i < sp->typecnt; ++i)
{
register const struct ttinfo * const ttisp = &sp->ttis[i];
 
tzname[ttisp->tt_isdst] =
unconst(&sp->chars[ttisp->tt_abbrind], char *);
#if 0
if (ttisp->tt_isdst)
_daylight = 1;
if (i == 0 || !ttisp->tt_isdst)
_timezone = -(ttisp->tt_gmtoff);
if (i == 0 || ttisp->tt_isdst)
_altzone = -(ttisp->tt_gmtoff);
#endif
}
/*
** And to get the latest zone names into tzname. . .
*/
for (i = 0; i < sp->timecnt; ++i)
{
const struct ttinfo * const ttisp = &sp->ttis[sp->types[i]];
 
tzname[ttisp->tt_isdst] = unconst(&sp->chars[ttisp->tt_abbrind], char *);
}
}
 
static const int mon_lengths[2][MONSPERYEAR] = {
{ 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 int year_lengths[2] = {
DAYSPERNYEAR, DAYSPERLYEAR
};
 
/*
** Given a pointer into a time zone string, scan until a character that is not
** a valid character in a zone name is found. Return a pointer to that
** character.
*/
 
static const char *
getzname(const char *strp)
{
char c;
 
while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
c != '+')
++strp;
return strp;
}
 
/*
** Given a pointer into a time zone string, extract a number from that string.
** Check that the number is within a specified range; if it is not, return
** NULL.
** Otherwise, return a pointer to the first character not part of the number.
*/
 
static const char *
getnum(const char *strp, int * const nump, const int min, const int max)
{
char c;
int num;
 
if (strp == NULL || !isdigit(*strp))
return NULL;
num = 0;
while ((c = *strp) != '\0' && isdigit(c))
{
num = num * 10 + (c - '0');
if (num > max)
return NULL;
++strp;
}
if (num < min)
return NULL;
*nump = num;
return strp;
}
 
/*
** Given a pointer into a time zone string, extract a number of seconds,
** in hh[:mm[:ss]] form, from the string.
** If any error occurs, return NULL.
** Otherwise, return a pointer to the first character not part of the number
** of seconds.
*/
 
static const char *
getsecs(const char *strp, long * const secsp)
{
int num;
 
strp = getnum(strp, &num, 0, HOURSPERDAY);
if (strp == NULL)
return NULL;
*secsp = num * SECSPERHOUR;
if (*strp == ':')
{
++strp;
strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
if (strp == NULL)
return NULL;
*secsp += num * SECSPERMIN;
if (*strp == ':')
{
++strp;
strp = getnum(strp, &num, 0, SECSPERMIN - 1);
if (strp == NULL)
return NULL;
*secsp += num;
}
}
return strp;
}
 
/*
** Given a pointer into a time zone string, extract an offset, in
** [+-]hh[:mm[:ss]] form, from the string.
** If any error occurs, return NULL.
** Otherwise, return a pointer to the first character not part of the time.
*/
 
static const char *
getoffset(const char *strp, long * const offsetp)
{
int neg;
 
if (*strp == '-')
{
neg = 1;
++strp;
}
else if (isdigit(*strp) || *strp++ == '+')
neg = 0;
else
return NULL; /* illegal offset */
strp = getsecs(strp, offsetp);
if (strp == NULL)
return NULL; /* illegal time */
if (neg)
*offsetp = -*offsetp;
return strp;
}
 
/*
** Given a pointer into a time zone string, extract a rule in the form
** date[/time]. See POSIX section 8 for the format of "date" and "time".
** If a valid rule is not found, return NULL.
** Otherwise, return a pointer to the first character not part of the rule.
*/
 
static const char *
getrule(const char *strp, struct rule * const rulep)
{
if (*strp == 'J')
{
/*
** Julian day.
*/
rulep->r_type = JULIAN_DAY;
++strp;
strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
}
else if (*strp == 'M')
{
/*
** Month, week, day.
*/
rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
++strp;
strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
if (strp == NULL)
return NULL;
if (*strp++ != '.')
return NULL;
strp = getnum(strp, &rulep->r_week, 1, 5);
if (strp == NULL)
return NULL;
if (*strp++ != '.')
return NULL;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
}
else if (isdigit(*strp))
{
/*
** Day of year.
*/
rulep->r_type = DAY_OF_YEAR;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
}
else
return NULL; /* invalid format */
if (strp == NULL)
return NULL;
if (*strp == '/')
{
/*
** Time specified.
*/
++strp;
strp = getsecs(strp, &rulep->r_time);
}
else
rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
return strp;
}
 
/*
** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
** year, a rule, and the offset from GMT at the time that rule takes effect,
** calculate the Epoch-relative time that rule takes effect.
*/
 
static time_t
transtime(const time_t janfirst, const int year, const struct rule * const rulep, const long offset)
{
int leapyear;
time_t value=0;
int i;
int d, m1, yy0, yy1, yy2, dow;
 
leapyear = isleap(year);
switch (rulep->r_type)
{
 
case JULIAN_DAY:
/*
** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
** years.
** In non-leap years, or if the day number is 59 or less, just
** add SECSPERDAY times the day number-1 to the time of
** January 1, midnight, to get the day.
*/
value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
if (leapyear && rulep->r_day >= 60)
value += SECSPERDAY;
break;
 
case DAY_OF_YEAR:
/*
** n - day of year.
** Just add SECSPERDAY times the day number to the time of
** January 1, midnight, to get the day.
*/
value = janfirst + rulep->r_day * SECSPERDAY;
break;
 
case MONTH_NTH_DAY_OF_WEEK:
/*
** Mm.n.d - nth "dth day" of month m.
*/
value = janfirst;
for (i = 0; i < rulep->r_mon - 1; ++i)
value += mon_lengths[leapyear][i] * SECSPERDAY;
 
/*
** Use Zeller's Congruence to get day-of-week of first day of
** month.
*/
m1 = (rulep->r_mon + 9) % 12 + 1;
yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
yy1 = yy0 / 100;
yy2 = yy0 % 100;
dow = ((26 * m1 - 2) / 10 +
1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
if (dow < 0)
dow += DAYSPERWEEK;
 
/*
** "dow" is the day-of-week of the first day of the month. Get
** the day-of-month (zero-origin) of the first "dow" day of the
** month.
*/
d = rulep->r_day - dow;
if (d < 0)
d += DAYSPERWEEK;
for (i = 1; i < rulep->r_week; ++i)
{
if (d + DAYSPERWEEK >=
mon_lengths[leapyear][rulep->r_mon - 1])
break;
d += DAYSPERWEEK;
}
 
/*
** "d" is the day-of-month (zero-origin) of the day we want.
*/
value += d * SECSPERDAY;
break;
}
 
/*
** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
** question. To get the Epoch-relative time of the specified local
** time on that day, add the transition time and the current offset
** from GMT.
*/
return value + rulep->r_time + offset;
}
 
/*
** Given a POSIX section 8-style TZ string, fill in the rule tables as
** appropriate.
*/
static int tzload (const char * name, struct state * sp)
{
return -1;
}
 
static int
tzparse(const char *name, struct state * const sp, const int lastditch)
{
const char * stdname;
const char * dstname=0;
int stdlen;
int dstlen;
long stdoffset;
long dstoffset;
time_t * atp;
unsigned char * typep;
char * cp;
int load_result;
 
stdname = name;
if (lastditch)
{
stdlen = strlen(name); /* length of standard zone name */
name += stdlen;
if (stdlen >= sizeof sp->chars)
stdlen = (sizeof sp->chars) - 1;
}
else
{
name = getzname(name);
stdlen = name - stdname;
if (stdlen < 3)
return -1;
}
if (*name == '\0')
return -1;
else
{
name = getoffset(name, &stdoffset);
if (name == NULL)
return -1;
}
load_result = tzload(TZDEFRULES, sp);
if (load_result != 0)
sp->leapcnt = 0; /* so, we're off a little */
if (*name != '\0')
{
dstname = name;
name = getzname(name);
dstlen = name - dstname; /* length of DST zone name */
if (dstlen < 3)
return -1;
if (*name != '\0' && *name != ',' && *name != ';')
{
name = getoffset(name, &dstoffset);
if (name == NULL)
return -1;
}
else
dstoffset = stdoffset - SECSPERHOUR;
if (*name == ',' || *name == ';')
{
struct rule start;
struct rule end;
int year;
time_t janfirst;
time_t starttime;
time_t endtime;
 
++name;
if ((name = getrule(name, &start)) == NULL)
return -1;
if (*name++ != ',')
return -1;
if ((name = getrule(name, &end)) == NULL)
return -1;
if (*name != '\0')
return -1;
sp->typecnt = 2; /* standard time and DST */
/*
** Two transitions per year, from EPOCH_YEAR to 2037.
*/
sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
if (sp->timecnt > TZ_MAX_TIMES)
return -1;
sp->ttis[0].tt_gmtoff = -dstoffset;
sp->ttis[0].tt_isdst = 1;
sp->ttis[0].tt_abbrind = stdlen + 1;
sp->ttis[1].tt_gmtoff = -stdoffset;
sp->ttis[1].tt_isdst = 0;
sp->ttis[1].tt_abbrind = 0;
atp = sp->ats;
typep = sp->types;
janfirst = 0;
for (year = EPOCH_YEAR; year <= 2037; ++year)
{
starttime = transtime(janfirst, year, &start,
stdoffset);
endtime = transtime(janfirst, year, &end,
dstoffset);
if (starttime > endtime)
{
*atp++ = endtime;
*typep++ = 1; /* DST ends */
*atp++ = starttime;
*typep++ = 0; /* DST begins */
}
else
{
*atp++ = starttime;
*typep++ = 0; /* DST begins */
*atp++ = endtime;
*typep++ = 1; /* DST ends */
}
janfirst +=
year_lengths[isleap(year)] * SECSPERDAY;
}
}
else
{
int sawstd;
int sawdst;
long stdfix;
long dstfix;
long oldfix;
int isdst;
int i;
 
if (*name != '\0')
return -1;
if (load_result != 0)
return -1;
/*
** Compute the difference between the real and
** prototype standard and summer time offsets
** from GMT, and put the real standard and summer
** time offsets into the rules in place of the
** prototype offsets.
*/
sawstd = FALSE;
sawdst = FALSE;
stdfix = 0;
dstfix = 0;
for (i = 0; i < sp->typecnt; ++i)
{
if (sp->ttis[i].tt_isdst)
{
oldfix = dstfix;
dstfix =
sp->ttis[i].tt_gmtoff + dstoffset;
if (sawdst && (oldfix != dstfix))
return -1;
sp->ttis[i].tt_gmtoff = -dstoffset;
sp->ttis[i].tt_abbrind = stdlen + 1;
sawdst = TRUE;
}
else
{
oldfix = stdfix;
stdfix =
sp->ttis[i].tt_gmtoff + stdoffset;
if (sawstd && (oldfix != stdfix))
return -1;
sp->ttis[i].tt_gmtoff = -stdoffset;
sp->ttis[i].tt_abbrind = 0;
sawstd = TRUE;
}
}
/*
** Make sure we have both standard and summer time.
*/
if (!sawdst || !sawstd)
return -1;
/*
** Now correct the transition times by shifting
** them by the difference between the real and
** prototype offsets. Note that this difference
** can be different in standard and summer time;
** the prototype probably has a 1-hour difference
** between standard and summer time, but a different
** difference can be specified in TZ.
*/
isdst = FALSE; /* we start in standard time */
for (i = 0; i < sp->timecnt; ++i)
{
const struct ttinfo * ttisp;
 
/*
** If summer time is in effect, and the
** transition time was not specified as
** standard time, add the summer time
** offset to the transition time;
** otherwise, add the standard time offset
** to the transition time.
*/
ttisp = &sp->ttis[sp->types[i]];
sp->ats[i] +=
(isdst && !ttisp->tt_ttisstd) ?
dstfix : stdfix;
isdst = ttisp->tt_isdst;
}
}
}
else
{
dstlen = 0;
sp->typecnt = 1; /* only standard time */
sp->timecnt = 0;
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = 0;
sp->ttis[0].tt_abbrind = 0;
}
sp->charcnt = stdlen + 1;
if (dstlen != 0)
sp->charcnt += dstlen + 1;
if (sp->charcnt > sizeof sp->chars)
return -1;
cp = sp->chars;
(void) strncpy(cp, stdname, stdlen);
cp += stdlen;
*cp++ = '\0';
if (dstlen != 0)
{
(void) strncpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
return 0;
}
 
static void
gmtload(struct state * const sp)
{
if (tzload(GMT, sp) != 0)
(void) tzparse(GMT, sp, TRUE);
}
 
void
tzset(void)
{
const char * name;
 
name = getenv("TZ");
if (name == NULL)
{
tzsetwall();
return;
}
lcl_is_set = TRUE;
#ifdef ALL_STATE
if (lclptr == NULL)
{
lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL)
{
settzname(); /* all we can do */
return;
}
}
#endif /* defined ALL_STATE */
if (*name == '\0')
{
/*
** User wants it fast rather than right.
*/
lclptr->leapcnt = 0; /* so, we're off a little */
lclptr->timecnt = 0;
lclptr->ttis[0].tt_gmtoff = 0;
lclptr->ttis[0].tt_abbrind = 0;
(void) strcpy(lclptr->chars, GMT);
}
else if (tzload(name, lclptr) != 0)
if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
gmtload(lclptr);
settzname();
}
 
void
tzsetwall(void)
{
lcl_is_set = TRUE;
#ifdef ALL_STATE
if (lclptr == NULL)
{
lclptr = (struct state *) malloc(sizeof *lclptr);
if (lclptr == NULL)
{
settzname(); /* all we can do */
return;
}
}
#endif /* defined ALL_STATE */
if (tzload((char *) NULL, lclptr) != 0)
gmtload(lclptr);
settzname();
}
 
/*
** The easy way to behave "as if no library function calls" localtime
** is to not call it--so we drop its guts into "localsub", which can be
** freely called. (And no, the PANS doesn't require the above behavior--
** but it *is* desirable.)
**
** The unused offset argument is for the benefit of mktime variants.
*/
 
/*ARGSUSED*/
static void
localsub(const time_t * const timep, const long offset, struct tm * const tmp)
{
const struct state * sp;
const struct ttinfo * ttisp;
int i;
const time_t t = *timep;
 
if (!lcl_is_set)
tzset();
sp = lclptr;
#ifdef ALL_STATE
if (sp == NULL)
{
gmtsub(timep, offset, tmp);
return;
}
#endif /* defined ALL_STATE */
if (sp->timecnt == 0 || t < sp->ats[0])
{
i = 0;
while (sp->ttis[i].tt_isdst)
if (++i >= sp->typecnt)
{
i = 0;
break;
}
}
else
{
for (i = 1; i < sp->timecnt; ++i)
if (t < sp->ats[i])
break;
i = sp->types[i - 1];
}
ttisp = &sp->ttis[i];
/*
** To get (wrong) behavior that's compatible with System V Release 2.0
** you'd replace the statement below with
** t += ttisp->tt_gmtoff;
** timesub(&t, 0L, sp, tmp);
*/
timesub(&t, ttisp->tt_gmtoff, sp, tmp);
tmp->tm_isdst = ttisp->tt_isdst;
tzname[tmp->tm_isdst] = unconst(&sp->chars[ttisp->tt_abbrind], char *);
tmp->tm_zone = unconst(&sp->chars[ttisp->tt_abbrind], char *);
}
 
struct tm *
localtime(const time_t * const timep)
{
static struct tm tm;
 
localsub(timep, 0L, &tm);
return &tm;
}
 
/*
** gmtsub is to gmtime as localsub is to localtime.
*/
 
static void
gmtsub(const time_t * const timep, const long offset, struct tm * const tmp)
{
if (!gmt_is_set)
{
gmt_is_set = TRUE;
#ifdef ALL_STATE
gmtptr = (struct state *) malloc(sizeof *gmtptr);
if (gmtptr != NULL)
#endif /* defined ALL_STATE */
gmtload(gmtptr);
}
timesub(timep, offset, gmtptr, tmp);
/*
** Could get fancy here and deliver something such as
** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
** but this is no time for a treasure hunt.
*/
if (offset != 0)
tmp->tm_zone = WILDABBR;
else
{
#ifdef ALL_STATE
if (gmtptr == NULL)
tmp->TM_ZONE = GMT;
else
tmp->TM_ZONE = gmtptr->chars;
#endif /* defined ALL_STATE */
#ifndef ALL_STATE
tmp->tm_zone = gmtptr->chars;
#endif /* State Farm */
}
}
 
struct tm *
gmtime(const time_t * const timep)
{
static struct tm tm;
 
gmtsub(timep, 0L, &tm);
return &tm;
}
 
static void
timesub(const time_t * const timep, const long offset, const struct state * const sp, struct tm * const tmp)
{
const struct lsinfo * lp;
long days;
long rem;
int y;
int yleap;
const int * ip;
long corr;
int hit;
int i;
 
corr = 0;
hit = FALSE;
#ifdef ALL_STATE
i = (sp == NULL) ? 0 : sp->leapcnt;
#endif /* defined ALL_STATE */
#ifndef ALL_STATE
i = sp->leapcnt;
#endif /* State Farm */
while (--i >= 0)
{
lp = &sp->lsis[i];
if (*timep >= lp->ls_trans)
{
if (*timep == lp->ls_trans)
hit = ((i == 0 && lp->ls_corr > 0) ||
lp->ls_corr > sp->lsis[i - 1].ls_corr);
corr = lp->ls_corr;
break;
}
}
days = *timep / SECSPERDAY;
rem = *timep % SECSPERDAY;
#ifdef mc68k
if (*timep == 0x80000000)
{
/*
** A 3B1 muffs the division on the most negative number.
*/
days = -24855;
rem = -11648;
}
#endif /* mc68k */
rem += (offset - corr);
while (rem < 0)
{
rem += SECSPERDAY;
--days;
}
while (rem >= SECSPERDAY)
{
rem -= SECSPERDAY;
++days;
}
tmp->tm_hour = (int) (rem / SECSPERHOUR);
rem = rem % SECSPERHOUR;
tmp->tm_min = (int) (rem / SECSPERMIN);
tmp->tm_sec = (int) (rem % SECSPERMIN);
if (hit)
/*
** A positive leap second requires a special
** representation. This uses "... ??:59:60".
*/
++(tmp->tm_sec);
tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
if (tmp->tm_wday < 0)
tmp->tm_wday += DAYSPERWEEK;
y = EPOCH_YEAR;
if (days >= 0)
for ( ; ; )
{
yleap = isleap(y);
if (days < (long) year_lengths[yleap])
break;
++y;
days = days - (long) year_lengths[yleap];
}
else
do {
--y;
yleap = isleap(y);
days = days + (long) year_lengths[yleap];
} while (days < 0);
tmp->tm_year = y - TM_YEAR_BASE;
tmp->tm_yday = (int) days;
ip = mon_lengths[yleap];
for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
days = days - (long) ip[tmp->tm_mon];
tmp->tm_mday = (int) (days + 1);
tmp->tm_isdst = 0;
tmp->tm_gmtoff = offset;
}
 
/*
** A la X3J11
*/
 
char *
asctime(const struct tm *timeptr)
{
static const char wday_name[DAYSPERWEEK][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char mon_name[MONSPERYEAR][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static char result[26];
 
(void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
wday_name[timeptr->tm_wday],
mon_name[timeptr->tm_mon],
timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec,
TM_YEAR_BASE + timeptr->tm_year);
return result;
}
 
char *
ctime(const time_t * const timep)
{
return asctime(localtime(timep));
}
 
/*
** Adapted from code provided by Robert Elz, who writes:
** The "best" way to do mktime I think is based on an idea of Bob
** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
** It does a binary search of the time_t space. Since time_t's are
** just 32 bits, its a max of 32 iterations (even at 64 bits it
** would still be very reasonable).
*/
 
#ifndef WRONG
#define WRONG (-1)
#endif /* !defined WRONG */
 
static void
normalize(int * const tensptr, int * const unitsptr, const int base)
{
if (*unitsptr >= base)
{
*tensptr += *unitsptr / base;
*unitsptr %= base;
}
else if (*unitsptr < 0)
{
--*tensptr;
*unitsptr += base;
if (*unitsptr < 0)
{
*tensptr -= 1 + (-*unitsptr) / base;
*unitsptr = base - (-*unitsptr) % base;
}
}
}
 
static int
tmcomp(const struct tm * const atmp, const struct tm * const btmp)
{
int result;
 
if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
(result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
(result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
(result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
(result = (atmp->tm_min - btmp->tm_min)) == 0)
result = atmp->tm_sec - btmp->tm_sec;
return result;
}
 
static time_t
time2(struct tm *tmp, void (*const funcp)(const time_t *const,const long,struct tm *), const long offset, int * const okayp)
{
const struct state * sp;
int dir;
int bits;
int i, j ;
int saved_seconds;
time_t newt;
time_t t;
struct tm yourtm, mytm;
 
*okayp = FALSE;
yourtm = *tmp;
if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0)
normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN);
normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR);
normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY);
normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR);
while (yourtm.tm_mday <= 0)
{
--yourtm.tm_year;
yourtm.tm_mday +=
year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)];
}
for ( ; ; )
{
i = mon_lengths[isleap(yourtm.tm_year +
TM_YEAR_BASE)][yourtm.tm_mon];
if (yourtm.tm_mday <= i)
break;
yourtm.tm_mday -= i;
if (++yourtm.tm_mon >= MONSPERYEAR)
{
yourtm.tm_mon = 0;
++yourtm.tm_year;
}
}
saved_seconds = yourtm.tm_sec;
yourtm.tm_sec = 0;
/*
** Calculate the number of magnitude bits in a time_t
** (this works regardless of whether time_t is
** signed or unsigned, though lint complains if unsigned).
*/
for (bits = 0, t = 1; t > 0; ++bits, t <<= 1)
;
/*
** If time_t is signed, then 0 is the median value,
** if time_t is unsigned, then 1 << bits is median.
*/
t = (time_t) 1 << bits;
for ( ; ; )
{
(*funcp)(&t, offset, &mytm);
dir = tmcomp(&mytm, &yourtm);
if (dir != 0)
{
if (bits-- < 0)
return WRONG;
if (bits < 0)
--t;
else if (dir > 0)
t -= (time_t) 1 << bits;
else t += (time_t) 1 << bits;
continue;
}
if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
break;
/*
** Right time, wrong type.
** Hunt for right time, right type.
** It's okay to guess wrong since the guess
** gets checked.
*/
sp = (const struct state *)
((funcp == localsub) ? lclptr : gmtptr);
#ifdef ALL_STATE
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
for (i = 0; i < sp->typecnt; ++i)
{
if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
continue;
for (j = 0; j < sp->typecnt; ++j)
{
if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
continue;
newt = t + sp->ttis[j].tt_gmtoff -
sp->ttis[i].tt_gmtoff;
(*funcp)(&newt, offset, &mytm);
if (tmcomp(&mytm, &yourtm) != 0)
continue;
if (mytm.tm_isdst != yourtm.tm_isdst)
continue;
/*
** We have a match.
*/
t = newt;
goto label;
}
}
return WRONG;
}
label:
t += saved_seconds;
(*funcp)(&t, offset, tmp);
*okayp = TRUE;
return t;
}
 
static time_t
time1(struct tm * const tmp, void (*const funcp)(const time_t * const, const long, struct tm *), const long offset)
{
time_t t;
const struct state * sp;
int samei, otheri;
int okay;
 
if (tmp->tm_isdst > 1)
tmp->tm_isdst = 1;
t = time2(tmp, funcp, offset, &okay);
if (okay || tmp->tm_isdst < 0)
return t;
/*
** We're supposed to assume that somebody took a time of one type
** and did some math on it that yielded a "struct tm" that's bad.
** We try to divine the type they started from and adjust to the
** type they need.
*/
sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr);
#ifdef ALL_STATE
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
for (samei = 0; samei < sp->typecnt; ++samei)
{
if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
continue;
for (otheri = 0; otheri < sp->typecnt; ++otheri)
{
if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
continue;
tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
sp->ttis[samei].tt_gmtoff;
tmp->tm_isdst = !tmp->tm_isdst;
t = time2(tmp, funcp, offset, &okay);
if (okay)
return t;
tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
sp->ttis[samei].tt_gmtoff;
tmp->tm_isdst = !tmp->tm_isdst;
}
}
return WRONG;
}
 
time_t
mktime(struct tm * tmp)
{
return time1(tmp, localsub, 0L);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/difftime.c
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
 
double difftime(time_t time1, time_t time0)
{
return time1-time0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/posixrul.h
0,0 → 1,49
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* generated with bin2h from DJGPP/zoneinfo/posixrules */
 
unsigned char _posixrules_data[] = {
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,2,0,0,0,0,0,
0,1,16,0,0,0,2,0,0,0,8,0,151,254,240,1,135,225,224,2,119,224,240,3,112,254,96,4,96,253,112,5,80,
224,96,6,64,223,112,7,48,194,96,7,141,25,112,9,16,164,96,9,173,148,240,10,240,134,96,11,224,133,112,12,217,162,
224,13,192,103,112,14,185,132,224,15,169,131,240,16,153,102,224,17,137,101,240,18,121,72,224,19,105,71,240,20,89,42,224,
21,73,41,240,22,57,12,224,23,41,11,240,24,34,41,96,25,8,237,240,26,2,11,96,26,242,10,112,27,225,237,96,28,
209,236,112,29,193,207,96,30,177,206,112,31,161,177,96,32,118,0,240,33,129,147,96,34,85,226,240,35,106,175,224,36,53,
196,240,37,74,145,224,38,21,166,240,39,42,115,224,39,254,195,112,41,10,85,224,41,222,165,112,42,234,55,224,43,190,135,
112,44,211,84,96,45,158,105,112,46,179,54,96,47,126,75,112,48,147,24,96,49,103,103,240,50,114,250,96,51,71,73,240,
52,82,220,96,53,39,43,240,54,50,190,96,55,7,13,240,56,27,218,224,56,230,239,240,57,251,188,224,58,198,209,240,59,
219,158,224,60,175,238,112,61,187,128,224,62,143,208,112,63,155,98,224,64,111,178,112,65,132,127,96,66,79,148,112,67,100,
97,96,68,47,118,112,69,68,67,96,70,15,88,112,71,36,37,96,71,248,116,240,73,4,7,96,73,216,86,240,74,227,233,
96,75,184,56,240,76,205,5,224,77,152,26,240,78,172,231,224,79,119,252,240,80,140,201,224,81,97,25,112,82,108,171,224,
83,64,251,112,84,76,141,224,85,32,221,112,86,44,111,224,87,0,191,112,88,21,140,96,88,224,161,112,89,245,110,96,90,
192,131,112,91,213,80,96,92,169,159,240,93,181,50,96,94,137,129,240,95,149,20,96,96,105,99,240,97,126,48,224,98,73,
69,240,99,94,18,224,100,41,39,240,101,61,244,224,102,18,68,112,103,29,214,224,103,242,38,112,104,253,184,224,105,210,8,
112,106,221,154,224,107,177,234,112,108,198,183,96,109,145,204,112,110,166,153,96,111,113,174,112,112,134,123,96,113,90,202,240,
114,102,93,96,115,58,172,240,116,70,63,96,117,26,142,240,118,47,91,224,118,250,112,240,120,15,61,224,120,218,82,240,121,
239,31,224,122,186,52,240,123,207,1,224,124,163,81,112,125,174,227,224,126,131,51,112,127,142,197,224,128,99,21,112,129,119,
226,96,130,66,247,112,131,87,196,96,132,34,217,112,133,55,166,96,134,11,245,240,135,23,136,96,135,235,215,240,136,247,106,
96,137,203,185,240,138,215,76,96,139,171,155,240,140,192,104,224,141,139,125,240,142,160,74,224,143,107,95,240,144,128,44,224,
145,84,124,112,146,96,14,224,147,52,94,112,148,63,240,224,149,20,64,112,150,41,13,96,150,244,34,112,152,8,239,96,152,
212,4,112,153,232,209,96,154,189,32,240,155,200,179,96,156,157,2,240,157,168,149,96,158,124,228,240,159,136,119,96,160,92,
198,240,161,113,147,224,162,60,168,240,163,81,117,224,164,28,138,240,165,49,87,224,166,5,167,112,167,17,57,224,167,229,137,
112,168,241,27,224,169,197,107,112,170,218,56,96,171,165,77,112,172,186,26,96,173,133,47,112,174,153,252,96,175,101,17,112,
176,121,222,96,177,78,45,240,178,89,192,96,179,46,15,240,180,57,162,96,181,13,241,240,182,34,190,224,182,237,211,240,184,
2,160,224,184,205,181,240,185,226,130,224,186,182,210,112,187,194,100,224,188,150,180,112,189,162,70,224,190,118,150,112,191,130,
40,224,192,86,120,112,193,107,69,96,194,54,90,112,195,75,39,96,196,22,60,112,197,43,9,96,197,255,88,240,199,10,235,
96,199,223,58,240,200,234,205,96,201,191,28,240,202,211,233,224,203,158,254,240,204,179,203,224,205,126,224,240,206,147,173,224,
207,103,253,112,208,115,143,224,209,71,223,112,210,83,113,224,211,39,193,112,212,51,83,224,213,7,163,112,214,28,112,96,214,
231,133,112,215,252,82,96,216,199,103,112,217,220,52,96,218,176,131,240,219,188,22,96,220,144,101,240,221,155,248,96,222,112,
71,240,223,133,20,224,224,80,41,240,225,100,246,224,226,48,11,240,227,68,216,224,228,15,237,240,229,36,186,224,229,249,10,
112,231,4,156,224,231,216,236,112,232,228,126,224,233,184,206,112,234,205,155,96,235,152,176,112,236,173,125,96,237,120,146,112,
238,141,95,96,239,97,174,240,240,109,65,96,241,65,144,240,242,77,35,96,243,33,114,240,244,45,5,96,245,1,84,240,246,
22,33,224,246,225,54,240,247,246,3,224,248,193,24,240,249,213,229,224,250,160,250,240,251,181,199,224,252,138,23,112,253,149,
169,224,254,105,249,112,255,117,139,224,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,255,255,199,192,1,0,255,255,185,176,0,4,69,68,84,
0,69,83,84,0,0,0
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/strftime.c
0,0 → 1,226
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <time.h>
 
#define TM_YEAR_BASE 1900
 
static const char *afmt[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
};
static const char *Afmt[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday",
};
static const char *bfmt[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec",
};
static const char *Bfmt[] = {
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December",
};
 
static size_t gsize;
static char *pt;
 
static int
_add(const char *str)
{
for (;; ++pt, --gsize)
{
if (!gsize)
return 0;
if (!(*pt = *str++))
return 1;
}
}
 
static int
_conv(int n, int digits, char pad)
{
static char buf[10];
char *p;
 
for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
*p-- = n % 10 + '0';
while (p > buf && digits-- > 0)
*p-- = pad;
return _add(++p);
}
 
static size_t
_fmt(const char *format, const struct tm *t)
{
for (; *format; ++format)
{
if (*format == '%')
switch(*++format)
{
case '\0':
--format;
break;
case 'A':
if (t->tm_wday < 0 || t->tm_wday > 6)
return 0;
if (!_add(Afmt[t->tm_wday]))
return 0;
continue;
case 'a':
if (t->tm_wday < 0 || t->tm_wday > 6)
return 0;
if (!_add(afmt[t->tm_wday]))
return 0;
continue;
case 'B':
if (t->tm_mon < 0 || t->tm_mon > 11)
return 0;
if (!_add(Bfmt[t->tm_mon]))
return 0;
continue;
case 'b':
case 'h':
if (t->tm_mon < 0 || t->tm_mon > 11)
return 0;
if (!_add(bfmt[t->tm_mon]))
return 0;
continue;
case 'C':
if (!_fmt("%a %b %e %H:%M:%S %Y", t))
return 0;
continue;
case 'c':
if (!_fmt("%m/%d/%y %H:%M:%S", t))
return 0;
continue;
case 'e':
if (!_conv(t->tm_mday, 2, ' '))
return 0;
continue;
case 'D':
if (!_fmt("%m/%d/%y", t))
return 0;
continue;
case 'd':
if (!_conv(t->tm_mday, 2, '0'))
return 0;
continue;
case 'H':
if (!_conv(t->tm_hour, 2, '0'))
return 0;
continue;
case 'I':
if (!_conv(t->tm_hour % 12 ?
t->tm_hour % 12 : 12, 2, '0'))
return 0;
continue;
case 'j':
if (!_conv(t->tm_yday + 1, 3, '0'))
return 0;
continue;
case 'k':
if (!_conv(t->tm_hour, 2, ' '))
return 0;
continue;
case 'l':
if (!_conv(t->tm_hour % 12 ?
t->tm_hour % 12 : 12, 2, ' '))
return 0;
continue;
case 'M':
if (!_conv(t->tm_min, 2, '0'))
return 0;
continue;
case 'm':
if (!_conv(t->tm_mon + 1, 2, '0'))
return 0;
continue;
case 'n':
if (!_add("\n"))
return 0;
continue;
case 'p':
if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
return 0;
continue;
case 'R':
if (!_fmt("%H:%M", t))
return 0;
continue;
case 'r':
if (!_fmt("%I:%M:%S %p", t))
return 0;
continue;
case 'S':
if (!_conv(t->tm_sec, 2, '0'))
return 0;
continue;
case 'T':
case 'X':
if (!_fmt("%H:%M:%S", t))
return 0;
continue;
case 't':
if (!_add("\t"))
return 0;
continue;
case 'U':
if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
2, '0'))
return 0;
continue;
case 'W':
if (!_conv((t->tm_yday + 7 -
(t->tm_wday ? (t->tm_wday - 1) : 6))
/ 7, 2, '0'))
return 0;
continue;
case 'w':
if (!_conv(t->tm_wday, 1, '0'))
return 0;
continue;
case 'x':
if (!_fmt("%m/%d/%y", t))
return 0;
continue;
case 'y':
if (!_conv((t->tm_year + TM_YEAR_BASE)
% 100, 2, '0'))
return 0;
continue;
case 'Y':
if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
return 0;
continue;
case 'Z':
if (!t->tm_zone || !_add(t->tm_zone))
return 0;
continue;
case '%':
/*
* X311J/88-090 (4.12.3.5): if conversion char is
* undefined, behavior is undefined. Print out the
* character itself as printf(3) does.
*/
default:
break;
}
if (!gsize--)
return 0;
*pt++ = *format;
}
return gsize;
}
 
size_t
strftime(char *s, size_t maxsize, const char *format, const struct tm *t)
{
pt = s;
if ((gsize = maxsize) < 1)
return 0;
if (_fmt(format, t))
{
*pt = '\0';
return maxsize - gsize;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/time/time.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
 
time_t time(time_t *t)
{
struct timeval tt;
 
if (gettimeofday(&tt, 0) < 0)
return(-1);
if (t)
*t = tt.tv_sec;
return tt.tv_sec;
}
/programs/develop/libraries/menuetlibc/src/libc/ansif/Makefile
0,0 → 1,4
THIS_SRCS = float_de.c float_dm.c float_dx.c float_fe.c float_fm.c \
float_fx.c float_le.c float_lm.c float_lx.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_de.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
double_t __dj_double_epsilon = { 0x00000000, 0x00000, 0x3cb, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_dm.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
double_t __dj_double_min = { 0x00000000, 0x00000, 0x001, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_dx.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
double_t __dj_double_max = { 0xffffffffU, 0xfffff, 0x7fe, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_fe.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
float_t __dj_float_epsilon = { 0x000000, 0x68, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_fm.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
float_t __dj_float_min = { 0x000000, 0x01, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_fx.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
float_t __dj_float_max = { 0x7fffff, 0xfe, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_le.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
long_double_t __dj_long_double_epsilon = { 0x00000000, 0x80000000U, 0x3fc0, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_lm.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
long_double_t __dj_long_double_min = { 0x00000000, 0x80000000U, 0x0001, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/ansif/float_lx.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/ieee.h>
 
long_double_t __dj_long_double_max = { 0xffffffffU, 0xffffffffU, 0x7ffe, 0x0 };
/programs/develop/libraries/menuetlibc/src/libc/compat/Makefile
0,0 → 1,50
all:
make -C bsd
make -C io
make -C math
make -C mman
make -C mntent
make -C search
make -C stdio
make -C stdlib
make -C string
make -C sys
make -C time
make -C unistd
make -C v1
make -C signal
make -C termios
 
clean:
make -C bsd clean
make -C io clean
make -C math clean
make -C mman clean
make -C mntent clean
make -C search clean
make -C stdio clean
make -C stdlib clean
make -C string clean
make -C sys clean
make -C time clean
make -C unistd clean
make -C v1 clean
make -C signal clean
make -C termios clean
 
depend:
make -C bsd depend
make -C io depend
make -C math depend
make -C mman depend
make -C mntent depend
make -C search depend
make -C stdio depend
make -C stdlib depend
make -C string depend
make -C sys depend
make -C time depend
make -C unistd depend
make -C v1 depend
make -C signal depend
make -C termios depend
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/Makefile
0,0 → 1,3
THIS_SRCS = bcmp.c bcopy.c bzero.c index.s rindex.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bcmp.c
0,0 → 1,26
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bcmp
 
int
bcmp(const void *ptr1, const void *ptr2, int length)
{
if (ptr1 == ptr2)
return 0;
 
if (ptr1 == 0 || ptr2 == 0)
return -1;
 
const char* arg1 = ptr1;
const char* arg2 = ptr2;
 
while (length)
{
if (*arg1++ != *arg2++)
return length;
length--;
}
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bcopy.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bcopy
 
void *
bcopy(const void *a, void *b, size_t len)
{
return memmove(b, a, len);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bzero.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bzero
 
void *
bzero(void *a, size_t b)
{
return memset(a,0,b);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/index.s
0,0 → 1,6
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
MK_C_SYM(index)
jmp C_SYM(strchr)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/rindex.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
MK_C_SYM(rindex)
jmp C_SYM(strrchr)
/programs/develop/libraries/menuetlibc/src/libc/compat/io/Makefile
0,0 → 1,3
THIS_SRCS = chsize.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/io/chsize.c
0,0 → 1,9
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <unistd.h>
 
int
chsize(int handle, long size)
{
return ftruncate(handle, size);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/math/Makefile
0,0 → 1,3
THIS_SRCS= cbrt.s exmp1.s exp2.s log10.s log2.s sincos.s log1p.s powi.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/math/cbrt.s
0,0 → 1,145
#include<libc/asm.h>
 
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
.data
pinf:
.long 0xFF800000
 
NaN:
.long 0xFFC00000
 
temp:
.long 0, 0
 
onethird:
.long 1431655765
 
two54:
.long 0x5A800000
 
a0:
.float +1.87277957900533E+00
 
a1:
.float -1.87243905326548E+00
 
a2:
.float +1.60286399719912E+00
 
a3:
.float -7.46198924594210E-01
 
a4:
.float +1.42994392730009E-01
 
b0:
.float 14.
 
b1:
.float -7.
 
b2:
.float +2.
 
one9th:
.tfloat +0.11111111111111111111
 
.text
MK_C_SYM(cbrt)
 
movl 8(%esp), %eax
movl %eax, %ecx /* Save sign */
 
andl $0x7FFFFFFF, %eax /* fabs */
movl %eax, 8(%esp)
 
cmpl $0x7FF00000, %eax /* Control flows straight through for */
jae abarg /* normal args: 0 < fabs(x) < +inf */
testl $0x7FF00000, %eax
jz verysmall
 
mull onethird
addl $0x2A9F7893, %edx
movl %edx, temp+4 /* First approximation good */
/* to 5.5 bits */
 
have55:
fldl 4(%esp)
fld1
fdivp /* recip */
 
fldl temp /* Load approximation */
/* 4rd-order minimax to 24 bits */
fld %st(0) /* x x recip */
fmul %st(1) /* x^2 x recip */
fmul %st(1) /* x^3 x recip */
fmul %st(2) /* y x recip */
fld %st(0) /* y y x recip */
fmuls a4 /* P1' y x recip */
fadds a3 /* P1 y x recip */
fmul %st(1) /* P2' y x recip */
fadds a2 /* P2 y x recip */
fmul %st(1) /* P3' y x recip */
fadds a1 /* P3 y x recip */
fmulp /* P4' x recip */
fadds a0 /* P4 x recip */
fmulp /* x' recip */
/* 2nd-order Taylor to 64 bits */
fld %st(0) /* x x recip */
fmul %st(1) /* x^2 x recip */
fmul %st(1) /* x^3 x recip */
fmul %st(2) /* y x recip */
ffree %st(2) /* y x */
fld %st(0) /* y y x */
fmuls b2
fadds b1
fmulp /* ccc x */
fadds b0 /* P(y) x */
fmulp /* x'' */
fldt one9th
fmulp
 
cleanup: /* Restore sign */
testl %ecx, %ecx
jns end
fchs
 
end:
ret
 
verysmall: /* Exponent is 0 */
movl 8(%esp), %eax
testl %eax, %eax
jnz denormal
movl 4(%esp), %eax
testl %eax, %eax
jz special /* x = 0 */
denormal:
fldl 4(%esp)
fmuls two54 /* Multiply by 2^54 to normalize */
fstpl temp
 
movl temp+4, %eax
mull onethird
addl $0x297F7893, %edx /* Undo 2^54 multiplier */
movl %edx, temp+4 /* First approximation to 5.5 bits */
movl $0, temp
 
jmp have55
 
abarg: /* x = inf, or NaN */
testl $0x000FFFFF, %eax
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jz special
 
badarg: /* arg is negative or NaN */
movl $1, C_SYM(errno)
flds NaN
ret
 
special:
fldl 4(%esp) /* x = 0 or inf: just load x */
jmp cleanup
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exmp1.s
0,0 → 1,79
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
pinf:
.long 0x7F800000
 
NaN:
.long 0xFFC00000
 
 
MK_C_SYM(expm1)
movl 8(%esp), %eax /* Test for special cases. */
andl $0x7FFFFFFF, %eax
cmpl $0x40862E42, %eax
jge bigarg /* normal args: */
/* 0 < |x| <= log(DBL_MAX) */
argok: /* N.B. */
/* log(DBL_MAX) = 0x40862E42FEFA39EF */
fldl 4(%esp)
fldl2e /* log2(e) x */
fmulp /* xs */
fld %st /* xs xs */
frndint /* nint(xs) xs */
fxch %st(1) /* xs nint */
fsub %st(1),%st /* fract nint */
f2xm1 /* exps-1 nint */
fxch %st(1) /* nint exps-1 */
fld1 /* 1 nint exps-1 */
fscale /* scale nint exps-1 */
fld1 /* 1 scale nint exps-1 */
/* Should be fsubp %st,%st(1) (gas bug) */
.byte 0xDE, 0xE9 /* scale-1 nint exps-1 */
fxch %st(2) /* exps-1 nint scale-1 */
fscale /* expm nint scale-1 */
fstp %st(1) /* exp scale-1 */
faddp /* exp-1 */
ret
 
bigarg:
je edge
andl $0x7FF00000, %eax /* |x| > log(DBL_MAX) */
cmpl $0x7FF00000, %eax
je abarg
 
posneg:
testl $0x80000000, 8(%esp)
jnz argok /* Large negative -- OK */
movl $2, C_SYM(errno) /* |x| is really big, but finite */
jmp argok
 
edge: /* |x| is nearly log(DBL_MAX) */
cmpl $0xFEFA39EF, 4(%esp)
jbe argok
jmp posneg
 
abarg: /* x = +/-inf, or +NaN */
testl $0x000FFFFF, 8(%esp)
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jnz badarg
 
infarg: /* |x| = inf */
testl $0x80000000, 8(%esp)
jz posinf
 
neginf:
fld1
fchs
ret
 
posinf:
movl $2, C_SYM(errno)
flds pinf
ret
 
badarg: /* arg is NaN */
movl $1, C_SYM(errno)
flds NaN
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exp10.s
0,0 → 1,6
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.file "exp10.s"
MK_C_SYM(exp10)
jmp C_SYM(__pow10)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exp2.s
0,0 → 1,5
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(exp2)
jmp C_SYM(__pow2)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log10.s
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(log10)
fldlg2
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log1p.s
0,0 → 1,65
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
NaN:
.long 0xFFC00000
 
ninf:
.long 0xFF800000
 
pinf:
.long 0x7F800000
 
.text
MK_C_SYM(log1p) /* ln(1.+x) */
/* log1p(x) */
movl 8(%esp), %eax
movl %eax, %edx
 
cmpl $0xBFF00000,%eax /* x <= -1 ? */
jae nonpos
 
andl $0x7FF00000,%eax
cmpl $0x7FF00000,%eax
je abarg /* x == +inf or +NaN */
 
movl %edx, %eax
andl $0x7FFFFFFF,%eax
cmpl $0x3FD2BEC3,%eax /* 1 - sqrt(0.5) */
fldln2 /* ln(2) */
jbe 1f
fld1
faddl 4(%esp)
fyl2x /* logi(x) */
ret
1: /* log1pi(x) */
fldl 4(%esp)
fyl2xp1
ret
 
nonpos:
cmpl $0xBFF00000,%eax
ja badarg /* x == -1 ? */
movl 4(%esp), %eax
testl %eax, %eax
jz negone
 
badarg:
movl $1, C_SYM(errno)
flds NaN
ret
 
negone:
movl $2, C_SYM(errno)
flds ninf /* arg == -1; load -inf. */
ret
 
abarg:
movl %edx, %eax
testl $0x000FFFFF, %eax
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jnz badarg
 
flds pinf /* arg = +inf */
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log2.s
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(log2)
fld1
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/powi.s
0,0 → 1,34
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.text
MK_C_SYM(powi)
/* double powi(double x, int iy) = x^iy */
 
fldl 4(%esp) /* x2p = x; */
movl 12(%esp), %eax
 
testl %eax, %eax /* if (iy < 0) { */
jge Endif1
negl %eax /* iy = -iy; */
fld1 /* x = 1./x; */
/* Should be fdivrp %st, %st(1) (gas bug) */
.byte 0xDE, 0xF1
Endif1: /* } */
 
fld1 /* result = 1.; */
fxch %st(1)
 
jmp Test
.balign 16,,7
Loop:
testb $1, %al /* if (iy & 1) result *= x2p; */
je Endif2
fmul %st, %st(1)
Endif2:
shrl $1, %eax /* (unsigned) iy >>= 1; */
fmul %st(0), %st /* x2p *= x2p; */
Test:
testl %eax, %eax /* } */
jne Loop
fstp %st(0)
ret /* return result; */
/programs/develop/libraries/menuetlibc/src/libc/compat/math/sincos.s
0,0 → 1,43
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
 
NaN:
.long 0x00000000, 0xFFF80000
 
MK_C_SYM(sincos)
 
/* void sincos(double *cosine, double *sine, double x); */
 
movl 16(%esp), %ecx
 
movl 4(%esp), %eax /* Point to cosine. */
movl 8(%esp), %edx /* Point to sine. */
 
andl $0x7FF00000, %ecx /* Examine exponent of x. */
cmpl $0x43E00000, %ecx /* |x| >= 2^63 */
jae bigarg
 
fldl 12(%esp)
fsincos
fstpl (%eax) /* cos */
fstpl (%edx) /* sin */
ret
 
bigarg:
cmpl $0x7FF00000, %ecx /* x is INF or NaN. */
jb finite
movl NaN, %ecx /* Return -NaN */
movl %ecx, (%eax)
movl %ecx, (%edx)
movl NaN+4, %ecx
movl %ecx, 4(%eax)
movl %ecx, 4(%edx)
movl $1, C_SYM(errno)
ret
 
finite:
fld1
fstpl (%eax) /* cos = 1. */
fldz
fstpl (%edx) /* sin = 0. */
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/mman/Makefile
0,0 → 1,3
THIS_SRCS = mprotect.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/mman/mprotect.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <assert.h>
 
int mprotect(void *addr, size_t len, int prot)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/mntent/Makefile
0,0 → 1,3
THIS_SRCS = mntent.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/mntent/mntent.c
0,0 → 1,232
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is implementation of getmntent() and friends for DJGPP v2.x.
*
* Copyright (c) 1995-96 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
* ---------------------------------------------------------------------
*
* The primary motivation for these functions was the GNU df program,
* which lists all the mounted filesystems with a summary of the disk
* space available on each one of them. However, they are also useful
* on their own right.
*
* Unlike Unix, where all mountable filesystems can be found on special
* file (and thus implementing these function boils down to reading that
* file), with MS-DOS it's a mess. Every type of drive has its own
* interface; there are JOINed and SUBSTed pseudo-drives and RAM disks;
* different network redirectors hook DOS in a plethora of incompatible
* ways; a single drive A: can be mapped to either A: or B:, etc. That
* is why this implementation uses almost every trick in the book to get
* at the intimate details of every drive. Some places where you might
* find these tricks are: ``Undocumented DOS, 2nd ed.'' by Schulman et al
* and Ralf Brown's Interrupt List.
*
*/
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <mntent.h>
#include <dir.h>
#include <libc/farptrgs.h>
#include <sys/movedata.h>
#include <libc/unconst.h>
#include <assert.h>
 
/* Macro to convert a segment and an offset to a "far offset" suitable
for _farxxx() functions of DJGPP. */
#ifndef MK_FOFF
#define MK_FOFF(s,o) ((int)((((unsigned long)(s)) << 4) + (unsigned short)(o)))
#endif
 
#define CDS_JOIN 0x2000
#define CDS_VALID 0xc000
#define REMOVABLE 0
#define FIXED 1
 
/* Static variables. */
 
static char drive_number = -1;
static char skip_drive_b = 0;
static char drive_a_mapping = 0;
static char cds_drives = 0;
static unsigned long cds_address;
static int cds_elsize;
static unsigned short dos_mem_base, our_mem_base;
static struct mntent mntent;
static unsigned char drive_string[128];
static char *mnt_type;
static unsigned char mnt_dir[128];
static unsigned char mnt_fsname[128];
static char dev_opts[] = "r ,dev= ";
 
static char NAME_dblsp[] = "dblsp";
static char NAME_stac[] = "stac";
static char NAME_ram[] = "ram";
static char NAME_cdrom[] = "cdrom";
static char NAME_net[] = "net";
static char NAME_fd[] = "fd";
static char NAME_hd[] = "hd";
static char NAME_subst[] = "subst";
static char NAME_join[] = "join";
 
int _is_remote_drive(int);
 
/* Static helper functions. */
 
/*
* Get the entry for this disk in the DOS Current Directory Structure
* (CDS). In case of success, return this drive's attribute word; or
* 0 in case of failure. Fill the buffer at CURRDIR with the current
* directory on that drive.
* The pointer to the CDS array and the size of the array element
* (which are DOS version-dependent) are computed when setmntent() is
* called.
*/
static int
get_cds_entry(int drive_num, char *currdir)
{
unsigned long cds_entry_address;
if (!cds_address)
{
*currdir = '\0';
return 0;
}
 
/* The address of the CDS element for this drive. */
cds_entry_address = cds_address + (drive_num - 1)*cds_elsize;
/* The current directory: 67-byte ASCIIZ string at the beginning
of the CDS structure for our drive. */
movedata(dos_mem_base, (cds_entry_address & 0xfffff),
our_mem_base, (unsigned int)currdir, 0x43);
 
/* The drive attribute word is at the offset 43h, right after the
current directory string. */
return _farpeekw(dos_mem_base, cds_entry_address + 0x43);
}
 
/*
* For a PC with a single floppy drive, that drive can be referenced
* as both A: and B:. This function returns the logical drive number
* which was last used to reference a physical drive, or 0 if the
* drive has only one logical drive assigned to it (which means there
* are two floppies in this system).
*/
static int assigned_to(int drive_num)
{
return drive_num;
}
 
/*
* Check if the drive is compressed with DoubleSpace. If it is,
* get the host drive on which the Compressed Volume File (CVF)
* resides, put the name of that CVF into MNT_FSNAME[] and return
* non-zero.
*/
static int get_doublespace_info(int drive_num)
{
return 0;
}
 
static int get_stacker_info(int drive_num)
{
return 0;
}
 
/*
* Get the network name which corresponds to a drive DRIVE_NUM.
* Ideally, _truename() (Int 21h/AH=60h) should return the same
* string, but some network redirectors don't put a full UNC
* name into the CDS, and others bypass the CDS altogether.
*/
static int get_netredir_entry(int drive_num)
{
return 0;
}
 
/*
* Return 1 if this drive is a CD-ROM drive, 0 otherwise. Works
* with MSCDEX 2.x, but what about other CD-ROM device drivers?
*/
static int is_cdrom_drive(int drive_num)
{
return 0;
}
 
/*
* Return 1 if a CD-ROM drive DRIVE_NUM is ready, i.e. there is a
* disk in the drive and that disk is a data (not AUDIO) disk.
*/
static int cdrom_drive_ready(int drive_num)
{
return 0;
}
 
/*
* Detect a RAM disk. We do this by checking if the number of FAT
* copies (in the Device Parameter Block) is 1, which is typical of
* RAM disks. [This doesn't _have_ to be so, but if it's good
* enough for Andrew Schulman et al (Undocumented DOS, 2nd edition),
* we can use this as well.]
*/
static int is_ram_drive(int drive_num)
{
return -1;
}
 
/*
* Check if the media in this disk drive is fixed or removable.
* Should only be called after we're sure this ain't CD-ROM or
* RAM disk, since these might fool you with this call.
*/
static int media_type(int drive_num)
{
return 0;
}
 
/* Exported library functions. */
 
FILE * setmntent(char *filename, char *type)
{
return NULL;
}
 
static char NAME_unknown[] = "???";
struct mntent * getmntent(FILE *filep)
{
mntent.mnt_fsname = "FAT";
mntent.mnt_dir = "/";
mntent.mnt_freq = -1;
mntent.mnt_passno = -1;
mntent.mnt_time = -1;
}
 
int addmntent(FILE *filep, struct mntent *mnt)
{
unimpl();
}
 
char * hasmntopt(struct mntent *mnt, char *opt)
{
return strstr(mnt->mnt_opts, opt);
}
 
int endmntent(FILE *filep)
{
if (filep != (FILE *)1)
{
errno = EBADF; /* fake errno for invalid handle */
return NULL;
}
drive_number = 0;
skip_drive_b = 0;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/search/Makefile
0,0 → 1,3
THIS_SRCS= insque.c remque.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/search/insque.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <search.h>
 
void
insque(struct qelem *e, struct qelem *p)
{
if (!e || !p)
return;
e->q_back = p;
e->q_forw = p->q_forw;
p->q_forw->q_back = e;
p->q_forw = e;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/search/remque.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <search.h>
 
void
remque(struct qelem *e)
{
if (!e)
return;
if (e->q_forw)
e->q_forw->q_back = e->q_back;
if (e->q_back)
e->q_back->q_forw = e->q_forw;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/Makefile
0,0 → 1,3
THIS_SRCS= psignal.c siglist.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/psignal.c
0,0 → 1,16
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
 
#include <signal.h>
#include <stdio.h>
 
extern char *sys_siglist[];
 
void
psignal (int sig, const char *msg)
{
if (sig >= 0 && sig < NSIG)
__libclog_printf( "%s: %s\n", msg, sys_siglist[sig]);
else
__libclog_printf( "%s: signal %d\n", msg, sig);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/siglist.c
0,0 → 1,97
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
 
#include <signal.h>
#include <string.h>
#include <stdlib.h>
 
char *sys_siglist[NSIG + 1]; /* initially all-zero */
 
static const char *known_signal[] = {
"Abort termination",
"Floating-point exception",
"Illegal instruction",
"Segmentation violation",
"Software termination signal",
"Alarm clock",
"Hangup",
"Interrupt",
"Kill",
"Write on pipe with no one to read it",
"Quit",
"User-defined signal 1",
"User-defined signal 2",
"Floating-point co-processor not present",
"Debugger/Breakpoint instruction",
"Timer tick signal",
"Profiler signal"
};
 
static char unknown_signal[] = "Unknown signal";
 
static void
put_hex_digits (char *str, int num, size_t idx)
{
static char xdigits[] = "0123456789ABCDEF";
 
str[idx] = xdigits[num / 16];
str[idx + 1] = xdigits[num & 15];
}
 
static char *
xstrdup (const char *src)
{
if (src)
{
size_t src_size = strlen (src) + 1;
char *new = (char *)malloc (src_size);
 
if (new)
{
memcpy (new, src, src_size);
return new;
}
}
 
return NULL;
}
 
static int signum;
 
static void
fill_dull_names (const char *template, size_t tpl_size, int count)
{
int i;
 
for (i = 0; i < count; i++)
{
char *signame = (char *)malloc (tpl_size);
 
memcpy (signame, template, tpl_size);
put_hex_digits (signame, i, tpl_size - 3);
sys_siglist[signum++] = signame;
}
}
 
static void __attribute__((constructor))
init_sys_siglist (void)
{
static char int_name[] = "Interrupt XXh";
static size_t int_size = sizeof(int_name);
static char excpt_name[] = "Exception XXh";
static size_t excpt_size = sizeof(excpt_name);
int i;
 
signum = 0;
 
fill_dull_names (int_name, int_size, 256);
fill_dull_names (excpt_name, excpt_size, 32);
 
for (i = 0; i < 17; i++)
sys_siglist[signum++] = xstrdup (known_signal[i]);
 
for (i = 305; i < 320; i++)
sys_siglist[signum++] = xstrdup (unknown_signal);
 
sys_siglist[signum] = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/Makefile
0,0 → 1,3
THIS_SRCS = mkstemp.c mktemp.c tempnam.c vscanf.c vsscanf.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mkstemp.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
 
int
mkstemp (char *_template)
{
if (mktemp (_template))
return creat (_template, 0666);
else {
errno = ENOENT;
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mktemp.c
0,0 → 1,69
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/bss.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
 
static int mktemp_count = -1;
 
char *
mktemp (char *_template)
{
static int count = 0;
char *cp, *dp;
int i, len, xcount, loopcnt;
 
/* Reinitialize counter if we were restarted (emacs). */
if (__bss_count != mktemp_count)
{
mktemp_count = __bss_count;
count = 0;
}
 
len = strlen (_template);
cp = _template + len;
 
xcount = 0;
while (xcount < 6 && cp > _template && cp[-1] == 'X')
xcount++, cp--;
 
if (xcount) {
dp = cp;
while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':')
dp--;
 
/* Keep the first characters of the template, but turn the rest into
Xs. */
while (cp > dp + 8 - xcount) {
*--cp = 'X';
xcount = (xcount >= 6) ? 6 : 1 + xcount;
}
 
/* If dots occur too early -- squash them. */
while (dp < cp) {
if (*dp == '.') *dp = 'a';
dp++;
}
 
/* Try to add ".tmp" to the filename. Truncate unused Xs. */
if (cp + xcount + 3 < _template + len)
strcpy (cp + xcount, ".tmp");
else
cp[xcount] = 0;
 
/* This loop can run up to 2<<(5*6) times, or about 10^9 times. */
for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) {
int c = count++;
for (i = 0; i < xcount; i++, c >>= 5)
cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f];
if (!__file_exists(_template))
return _template;
}
}
 
/* Failure: truncate the template and return NULL. */
*_template = 0;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/tempnam.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
 
char * tempnam(const char *_dir, const char *_prefix)
{
return tmpnam(0);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vscanf.c
0,0 → 1,9
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
 
int
vscanf(const char *fmt, va_list ap)
{
return _doscan(stdin, fmt, ap);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vsscanf.c
0,0 → 1,20
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
#include <libc/unconst.h>
 
int
vsscanf(const char *str, const char *fmt, va_list ap)
{
FILE _strbuf;
 
_strbuf._flag = _IOREAD|_IOSTRG|_IONTERM;
_strbuf._ptr = _strbuf._base = unconst(str, char *);
_strbuf._cnt = 0;
while (*str++)
_strbuf._cnt++;
_strbuf._bufsiz = _strbuf._cnt;
return _doscan(&_strbuf, fmt, ap);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/Makefile
0,0 → 1,4
THIS_SRCS = alloca.c cfree.c getlongp.c getpass.c itoa.c putenv.c \
random.c swab.c xfree.c xmalloc.c xrealloc.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/alloca.c
0,0 → 1,128
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
 
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
 
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
 
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
 
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
 
#include <stdlib.h>
 
#ifdef alloca
#undef alloca
#endif
 
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
 
#define ADDRESS_FUNCTION(arg) &(arg)
 
#define NULL 0
 
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
 
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
 
#define STACK_DIRECTION -1
 
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
 
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
 
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
 
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
#endif
 
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
 
static header *last_alloca_header = NULL; /* -> last alloca header. */
 
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
 
void *
alloca(size_t size)
{
char probe; /* Probes stack depth: */
char *depth = &probe;
/* Reclaim garbage, defined as all alloca storage that
was allocated from deeper in the stack than currently. */
{
header *hp; /* Traverses linked list. */
 
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
header *np = hp->h.next;
 
free ((void *) hp); /* Collect garbage. */
 
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
 
last_alloca_header = hp; /* -> last valid storage. */
}
 
if (size == 0)
return NULL; /* No allocation required. */
 
/* Allocate combined header + user data storage. */
 
{
void * newp = malloc (sizeof (header) + size);
if (newp == 0)
abort();
/* Address of header. */
 
((header *) newp)->h.next = last_alloca_header;
((header *) newp)->h.deep = depth;
 
last_alloca_header = (header *) newp;
 
/* User storage begins just after header. */
 
return (void *) ((char *) newp + sizeof (header));
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/cfree.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void
cfree(void *_ptr)
{
free(_ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/getlongp.c
0,0 → 1,58
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <pc.h>
 
int
getlongpass(const char *prompt, char *password, int max_length)
{
char *p = password;
int c, count = 0;
 
fflush(stdout);
/* If we can't prompt, abort */
if (fputs(prompt, stderr) < 0)
{
*p = '\0';
return -1;
}
 
while (1)
{
/* Get a character with no echo */
c = getkey();
 
/* Exit on interrupt (^c or ^break) */
if (c == '\003' || c == 0x100)
exit(1);
 
/* Terminate on end of line or file (^j, ^m, ^d, ^z) */
if (c == '\r' || c == '\n' || c == '\004' || c == '\032')
break;
 
/* Back up on backspace */
if (c == '\b')
{
if (count)
count--;
else if (p > password)
p--;
continue;
}
 
/* Ignore DOS extended characters */
if ((c & 0xff) != c)
continue;
 
/* Add to password if it isn't full */
if (p < password + max_length - 1)
*p++ = c;
else
count++;
}
*p = '\0';
 
fputc('\n', stderr);
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/getpass.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
char *
getpass(const char *prompt)
{
static char password_buffer[9];
 
if (getlongpass(prompt, password_buffer, 9) < 0)
return 0;
return password_buffer;
}
 
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/itoa.c
0,0 → 1,46
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stdlib.h>
 
char *
itoa(int value, char *string, int radix)
{
char tmp[33];
char *tp = tmp;
int i;
unsigned v;
int sign;
char *sp;
 
if (radix > 36 || radix <= 1)
{
errno = EDOM;
return 0;
}
 
sign = (radix == 10 && value < 0);
if (sign)
v = -value;
else
v = (unsigned)value;
while (v || tp == tmp)
{
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
}
 
if (string == 0)
string = (char *)malloc((tp-tmp)+sign+1);
sp = string;
 
if (sign)
*sp++ = '-';
while (tp > tmp)
*sp++ = *--tp;
*sp = 0;
return string;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/putenv.c
0,0 → 1,11
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <libc/bss.h>
 
int putenv(const char *val)
{
return __libc_putenv(val);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/random.c
0,0 → 1,365
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file RANDOM.C */
/* This file may have been modified by DJ Delorie (Jan 1995). If so,
** these modifications are Coyright (C) 1993 DJ Delorie, 24 Kirsten Ave,
** Rochester NH, 03867-2954, USA.
*/
 
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
#include <stdlib.h>
 
/*
* random.c:
* An improved random number generation package. In addition to the standard
* rand()/srand() like interface, this package also has a special state info
* interface. The initstate() routine is called with a seed, an array of
* bytes, and a count of how many bytes are being passed in; this array is then
* initialized to contain information for random number generation with that
* much state information. Good sizes for the amount of state information are
* 32, 64, 128, and 256 bytes. The state can be switched by calling the
* setstate() routine with the same array as was initiallized with initstate().
* By default, the package runs with 128 bytes of state information and
* generates far better random numbers than a linear congruential generator.
* If the amount of state information is less than 32 bytes, a simple linear
* congruential R.N.G. is used.
* Internally, the state information is treated as an array of longs; the
* zeroeth element of the array is the type of R.N.G. being used (small
* integer); the remainder of the array is the state information for the
* R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
* state information, which will allow a degree seven polynomial. (Note: the
* zeroeth word of state information also has some other information stored
* in it -- see setstate() for details).
* The random number generation technique is a linear feedback shift register
* approach, employing trinomials (since there are fewer terms to sum up that
* way). In this approach, the least significant bit of all the numbers in
* the state table will act as a linear feedback shift register, and will have
* period 2^deg - 1 (where deg is the degree of the polynomial being used,
* assuming that the polynomial is irreducible and primitive). The higher
* order bits will have longer periods, since their values are also influenced
* by pseudo-random carries out of the lower bits. The total period of the
* generator is approximately deg*(2**deg - 1); thus doubling the amount of
* state information has a vast influence on the period of the generator.
* Note: the deg*(2**deg - 1) is an approximation only good for large deg,
* when the period of the shift register is the dominant factor. With deg
* equal to seven, the period is actually much longer than the 7*(2**7 - 1)
* predicted by this formula.
*/
 
 
 
/*
* For each of the currently supported random number generators, we have a
* break value on the amount of state information (you need at least this
* many bytes of state info to support this random number generator), a degree
* for the polynomial (actually a trinomial) that the R.N.G. is based on, and
* the separation between the two lower order coefficients of the trinomial.
*/
 
#define TYPE_0 0 /* linear congruential */
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
 
#define TYPE_1 1 /* x**7 + x**3 + 1 */
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
 
#define TYPE_2 2 /* x**15 + x + 1 */
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
 
#define TYPE_3 3 /* x**31 + x**3 + 1 */
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
 
#define TYPE_4 4 /* x**63 + x + 1 */
#define BREAK_4 256
#define DEG_4 63
#define SEP_4 1
 
 
/*
* Array versions of the above information to make code run faster -- relies
* on fact that TYPE_i == i.
*/
 
#define MAX_TYPES 5 /* max number of types above */
static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
 
/*
* Initially, everything is set up as if from :
* initstate( 1, &randtbl, 128 );
* Note that this initialization takes advantage of the fact that srandom()
* advances the front and rear pointers 10*rand_deg times, and hence the
* rear pointer which starts at 0 will also end up at zero; thus the zeroeth
* element of the state information, which contains info about the current
* position of the rear pointer is just
* MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3.
*/
 
static unsigned long randtbl[DEG_3 + 1] = { TYPE_3,
0x9a319039U, 0x32d9c024U, 0x9b663182U, 0x5da1f342U,
0xde3b81e0U, 0xdf0a6fb5U, 0xf103bc02U, 0x48f340fbU,
0x7449e56bU, 0xbeb1dbb0U, 0xab5c5918U, 0x946554fdU,
0x8c2e680fU, 0xeb3d799fU, 0xb11ee0b7U, 0x2d436b86U,
0xda672e2aU, 0x1588ca88U, 0xe369735dU, 0x904f35f7U,
0xd7158fd6U, 0x6fa6f051U, 0x616e6b96U, 0xac94efdcU,
0x36413f93U, 0xc622c298U, 0xf5a42ab8U, 0x8a88d77bU,
0xf5ad9d0eU, 0x8999220bU, 0x27fb47b9U };
 
/*
* fptr and rptr are two pointers into the state info, a front and a rear
* pointer. These two pointers are always rand_sep places aparts, as they cycle
* cyclically through the state information. (Yes, this does mean we could get
* away with just one pointer, but the code for random() is more efficient this
* way). The pointers are left positioned as they would be from the call
* initstate( 1, randtbl, 128 )
* (The position of the rear pointer, rptr, is really 0 (as explained above
* in the initialization of randtbl) because the state table pointer is set
* to point to randtbl[1] (as explained below).
*/
 
static long *fptr = &randtbl[ SEP_3 + 1 ];
static long *rptr = &randtbl[ 1 ];
 
/*
* The following things are the pointer to the state information table,
* the type of the current generator, the degree of the current polynomial
* being used, and the separation between the two pointers.
* Note that for efficiency of random(), we remember the first location of
* the state information, not the zeroeth. Hence it is valid to access
* state[-1], which is used to store the type of the R.N.G.
* Also, we remember the last location, since this is more efficient than
* indexing every time to find the address of the last element to see if
* the front and rear pointers have wrapped.
*/
 
static long *state = &randtbl[ 1 ];
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
static long *end_ptr = &randtbl[ DEG_3 + 1 ];
 
/*
* srandom:
* Initialize the random number generator based on the given seed. If the
* type is the trivial no-state-information type, just remember the seed.
* Otherwise, initializes state[] based on the given "seed" via a linear
* congruential generator. Then, the pointers are set to known locations
* that are exactly rand_sep places apart. Lastly, it cycles the state
* information a given number of times to get rid of any initial dependencies
* introduced by the L.C.R.N.G.
* Note that the initialization of randtbl[] for default usage relies on
* values produced by this routine.
*/
 
int
srandom(int x)
{
int i, j;
 
if (rand_type == TYPE_0)
{
state[ 0 ] = x;
}
else
{
j = 1;
state[ 0 ] = x;
for (i = 1; i < rand_deg; i++)
{
state[i] = 1103515245*state[i - 1] + 12345;
}
fptr = &state[rand_sep];
rptr = &state[0];
for( i = 0; i < 10*rand_deg; i++ )
random();
}
return 0;
}
 
/*
* initstate:
* Initialize the state information in the given array of n bytes for
* future random number generation. Based on the number of bytes we
* are given, and the break values for the different R.N.G.'s, we choose
* the best (largest) one we can and set things up for it. srandom() is
* then called to initialize the state information.
* Note that on return from srandom(), we set state[-1] to be the type
* multiplexed with the current value of the rear pointer; this is so
* successive calls to initstate() won't lose this information and will
* be able to restart with setstate().
* Note: the first thing we do is save the current state, if any, just like
* setstate() so that it doesn't matter when initstate is called.
* Returns a pointer to the old state.
*/
 
char *
initstate (unsigned seed, char *arg_state, int n)
{
char *ostate = (char *)(&state[ -1 ]);
 
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
if (n < BREAK_1)
{
if (n < BREAK_0)
return 0;
rand_type = TYPE_0;
rand_deg = DEG_0;
rand_sep = SEP_0;
}
else
{
if (n < BREAK_2)
{
rand_type = TYPE_1;
rand_deg = DEG_1;
rand_sep = SEP_1;
}
else
{
if (n < BREAK_3)
{
rand_type = TYPE_2;
rand_deg = DEG_2;
rand_sep = SEP_2;
}
else
{
if (n < BREAK_4)
{
rand_type = TYPE_3;
rand_deg = DEG_3;
rand_sep = SEP_3;
}
else
{
rand_type = TYPE_4;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
}
}
}
state = &(((long *)arg_state)[1]); /* first location */
end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
srandom(seed);
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
return ostate;
}
 
/*
* setstate:
* Restore the state from the given state array.
* Note: it is important that we also remember the locations of the pointers
* in the current state information, and restore the locations of the pointers
* from the old state information. This is done by multiplexing the pointer
* location into the zeroeth word of the state information.
* Note that due to the order in which things are done, it is OK to call
* setstate() with the same state as the current state.
* Returns a pointer to the old state information.
*/
 
char *
setstate(char *arg_state)
{
long *new_state = (long *)arg_state;
int type = new_state[0]%MAX_TYPES;
int rear = new_state[0]/MAX_TYPES;
char *ostate = (char *)( &state[ -1 ] );
 
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
switch (type)
{
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
rand_type = type;
rand_deg = degrees[ type ];
rand_sep = seps[ type ];
break;
}
state = &new_state[ 1 ];
if (rand_type != TYPE_0)
{
rptr = &state[rear];
fptr = &state[(rear + rand_sep)%rand_deg];
}
end_ptr = &state[rand_deg]; /* set end_ptr too */
return ostate;
}
 
/*
* random:
* If we are using the trivial TYPE_0 R.N.G., just do the old linear
* congruential bit. Otherwise, we do our fancy trinomial stuff, which is the
* same in all ther other cases due to all the global variables that have been
* set up. The basic operation is to add the number at the rear pointer into
* the one at the front pointer. Then both pointers are advanced to the next
* location cyclically in the table. The value returned is the sum generated,
* reduced to 31 bits by throwing away the "least random" low bit.
* Note: the code takes advantage of the fact that both the front and
* rear pointers can't wrap on the same call by not testing the rear
* pointer if the front one has wrapped.
* Returns a 31-bit random number.
*/
 
long
random(void)
{
long i;
if (rand_type == TYPE_0)
{
i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff;
}
else
{
*fptr += *rptr;
i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */
if (++fptr >= end_ptr )
{
fptr = state;
++rptr;
}
else
{
if (++rptr >= end_ptr)
rptr = state;
}
}
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/swab.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void
swab(const void *from, void *to, int n)
{
unsigned long temp;
const char* fromc = from;
char* toc = to;
 
n >>= 1; n++;
#define STEP temp = *fromc++,*toc++ = *fromc++,*toc++ = temp
/* round to multiple of 8 */
while ((--n) & 07)
STEP;
n >>= 3;
while (--n >= 0) {
STEP; STEP; STEP; STEP;
STEP; STEP; STEP; STEP;
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xfree.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void xfree(void *_ptr);
void
xfree(void *_ptr)
{
if (_ptr)
free(_ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xmalloc.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <io.h>
#include <unistd.h>
 
static char msg[] = "Fatal: malloc returned NULL\r\n";
 
void * xmalloc(size_t _sz);
void *
xmalloc(size_t _sz)
{
void *rv = malloc(_sz?_sz:1);
if (rv == 0)
{
__libclog_printf(msg);
_exit(1);
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xrealloc.c
0,0 → 1,26
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <io.h>
#include <unistd.h>
 
static char msg[] = "Fatal: xrealloc would have returned NULL\r\n";
 
void * xrealloc(void *ptr, size_t _sz);
void *
xrealloc(void *ptr, size_t _sz)
{
void *rv;
 
if (ptr == 0)
rv = malloc(_sz?_sz:1);
else
rv = realloc(ptr, _sz?_sz:1);
 
if (rv == 0)
{
__libclog_printf(msg);
_exit(1);
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/Makefile
0,0 → 1,4
THIS_SRCS = ffs.s memccpy.c stpcpy.c strcasec.s strdup.c stricmp.c \
strlwr.c strncase.s strnicmp.c strsep.c strupr.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/string/ffs.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(ffs)
bsfl 4(%esp), %eax
jnz .Lzero
movl $0,%eax
.Lzero:
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/string/memccpy.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
void *
memccpy(void *t, const void *f, int c, size_t n)
{
c &= 0xff;
if (n)
{
unsigned char *tt = (unsigned char *)t;
const unsigned char *ff = (const unsigned char *)f;
 
do {
if ((*tt++ = *ff++) == c)
return tt;
} while (--n != 0);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/stpcpy.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char *
stpcpy(char *_dest, const char *_src)
{
if (!_dest || !_src)
return 0;
while ((*_dest++ = *_src++));
return --_dest;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strcasec.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(strcasecmp)
jmp C_SYM(stricmp)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strdup.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <stdlib.h>
 
char *
strdup(const char *_s)
{
char *rv;
if (_s == 0)
return 0;
rv = (char *)malloc(strlen(_s) + 1);
if (rv == 0)
return 0;
strcpy(rv, _s);
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/stricmp.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <ctype.h>
 
int
stricmp(const char *s1, const char *s2)
{
while (tolower(*s1) == tolower(*s2))
{
if (*s1 == 0)
return 0;
s1++;
s2++;
}
return (int)tolower(*s1) - (int)tolower(*s2);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strlwr.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <string.h>
 
char *
strlwr(char *_s)
{
char *rv = _s;
while (*_s)
{
*_s = tolower(*_s);
_s++;
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strncase.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(strncasecmp)
jmp C_SYM(strnicmp)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strnicmp.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <ctype.h>
 
int
strnicmp(const char *s1, const char *s2, size_t n)
{
 
if (n == 0)
return 0;
do {
if (tolower(*s1) != tolower(*s2++))
return (int)tolower(*s1) - (int)tolower(*--s2);
if (*s1++ == 0)
break;
} while (--n != 0);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strsep.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char *
strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
 
if ((s = *stringp) == 0)
return 0;
 
tok = s;
while (1)
{
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c)
{
if (c == 0)
s = 0;
else
s[-1] = 0;
*stringp = s;
return tok;
}
} while (sc != 0);
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strupr.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <string.h>
 
char *
strupr(char *_s)
{
char *rv = _s;
while (*_s)
{
*_s = toupper(*_s);
_s++;
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/Makefile
0,0 → 1,14
all:
make -C resource
make -C stat
make -C vfs
 
clean:
make -C resource clean
make -C stat clean
make -C vfs clean
 
depend:
make -C resource depend
make -C stat depend
make -C vfs depend
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/Makefile
0,0 → 1,3
THIS_SRCS = resource.c gtrlimit.c strlimit.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/gtrlimit.c
0,0 → 1,56
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/resource.h>
#include <libc/bss.h>
 
extern unsigned int _stklen;
extern struct rlimit __libc_limits[];
 
static int rlimit_count = -1;
struct rlimit __libc_limits[RLIM_NLIMITS];
 
static void
__limits_initialize (void)
{
int i;
 
/* set hard limit */
__libc_limits[RLIMIT_CPU].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_FSIZE].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_DATA].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_STACK].rlim_max = (long) _stklen;
__libc_limits[RLIMIT_CORE].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_RSS].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_MEMLOCK].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_NPROC].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_NOFILE].rlim_max = sysconf (_SC_OPEN_MAX);
 
/* copy all hard limit to soft limit */
for (i = 0; i < RLIM_NLIMITS; i++)
__libc_limits[i].rlim_cur = __libc_limits[i].rlim_max;
}
 
int
getrlimit (int rltype, struct rlimit *rlimitp)
{
/* check argument range */
if (rltype < 0 || rltype >= RLIM_NLIMITS || rlimitp == NULL)
{
errno = EINVAL;
return -1;
}
 
/* initialize */
if (rlimit_count != __bss_count)
{
rlimit_count = __bss_count;
__limits_initialize ();
}
 
/* copy limit value */
*rlimitp = __libc_limits[rltype];
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/resource.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/resource.h>
 
int getrusage(int _who, struct rusage *_rusage)
{
clock_t q;
if (_rusage == 0)
{
errno = EFAULT;
return -1;
}
if (_who != RUSAGE_SELF && _who != RUSAGE_CHILDREN)
{
errno = EINVAL;
return -1;
}
memset(_rusage, 0, sizeof(struct rusage));
q = clock();
_rusage->ru_utime.tv_sec = q / CLOCKS_PER_SEC;
_rusage->ru_utime.tv_usec = q % CLOCKS_PER_SEC * 1000000 / CLOCKS_PER_SEC;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/strlimit.c
0,0 → 1,38
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <sys/resource.h>
 
extern struct rlimit __libc_limits[];
 
int
setrlimit (int rltype, const struct rlimit *rlimitp)
{
/* check argument range */
if (rlimitp->rlim_cur > rlimitp->rlim_max || rlimitp == NULL)
{
errno = EINVAL;
return -1;
}
 
switch (rltype)
{
case RLIMIT_CPU:
case RLIMIT_FSIZE:
case RLIMIT_DATA:
case RLIMIT_STACK:
case RLIMIT_CORE:
case RLIMIT_RSS:
case RLIMIT_MEMLOCK:
case RLIMIT_NPROC:
case RLIMIT_NOFILE:
/* not supported */
errno = EPERM;
return -1;
default:
errno = EINVAL;
return -1;
}
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/stat/Makefile
0,0 → 1,3
THIS_SRCS = mknod.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/stat/mknod.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
 
/* ARGSUSED */
int
mknod(const char *path, mode_t mode, dev_t dev)
{
errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/vfs/Makefile
0,0 → 1,3
THIS_SRCS = statfs.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/vfs/statfs.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <sys/vfs.h>
#include <ctype.h>
 
int statfs(const char *path, struct statfs *buf)
{
buf->f_bavail = 0xFFFFFFFF;
buf->f_bfree = 0xFFFFFFFF;
buf->f_blocks = 0xFFFF;
buf->f_bsize = 512;
buf->f_ffree = 0xFFFF;
buf->f_files = 0xFFFF;
buf->f_type = 0;
buf->f_fsid[0] = 0;
buf->f_fsid[1] = MOUNT_UFS;
buf->f_magic = FS_MAGIC;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/Makefile
0,0 → 1,4
THIS_SRCS = cfmakraw.c cfstspd.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/cfmakraw.c
0,0 → 1,25
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <termios.h>
#include <sys/exceptn.h>
 
void cfmakeraw (struct termios *termiosp)
{
/* check arguments */
if (termiosp == NULL)
{
errno = EINVAL;
return;
}
termiosp->c_iflag &= ~(BRKINT|ICRNL|IGNBRK|IGNCR|INLCR|ISTRIP|PARMRK|IXON);
#if defined (IMAXBEL)
termiosp->c_iflag &= ~IMAXBEL;
#endif
termiosp->c_oflag &= ~OPOST;
termiosp->c_lflag &= ~(ECHONL|ICANON|IEXTEN|ISIG);
termiosp->c_cflag &= ~(CSIZE|PARENB);
termiosp->c_cflag |= CS8;
termiosp->c_cc[VMIN] = 1;
termiosp->c_cc[VTIME] = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/cfstspd.c
0,0 → 1,21
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <termios.h>
 
int
cfsetspeed (struct termios *termiosp, speed_t speed)
{
/* check arguments */
if (termiosp == NULL)
{
errno = EINVAL;
return -1;
}
 
/* set input and output speed */
termiosp->c_ispeed = speed;
termiosp->c_ospeed = speed;
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/Makefile
0,0 → 1,4
THIS_SRCS = rawclock.c select.c settimeo.c utimes.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/compat/time/rawclock.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <libc/farptrgs.h>
#include <menuet/os.h>
 
unsigned long rawclock(void)
{
static unsigned long base = 0;
unsigned long rv;
rv=__menuet__getsystemclock();
if (base == 0)
base = rv;
return rv - base;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/select.c
0,0 → 1,206
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* An implementation of select()
 
Copyright 1995 by Morten Welinder
This file maybe freely distributed and modified as long as the
copyright notice remains.
 
Notes: In a single process system as Dos this really boils down to
something that can check whether a character from standard input
is ready. However, the code is organised in a way to make it easy
to extend to multi process systems like WinNT and OS/2. */
 
#include <libc/stubs.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
 
inline static int fp_output_ready(FILE *fp)
{
return !ferror(fp);
}
 
/* This is as close as we get, I think. For a file connected to a printer
we could of course go ask the BIOS, but this should be enough. */
 
inline static int fp_except_ready(FILE *fp)
{
return ferror (fp);
}
 
inline static int fp_input_ready (FILE *fp)
{
/* I think if there is something in the buffer, we should return
``ready'', even if some error was encountered. Let him consume
the buffered characters, *then* return ``not ready''. */
if (fp->_cnt)
return 1;
 
/* The `feof' part is only correct in a single-tasked environment. */
if (ferror (fp) || feof (fp))
return 0;
 
/* There is nothing in the buffer (perhaps because we read unbuffered).
We don't know if we are ready. Return ``ready'' anyway and let
read() or write() tell the truth. */
return 1;
}
 
/* The Dos call 4407 always returns TRUE for disk files. So the
following really is meaningful for character devices only... */
 
inline static int fd_output_ready(int fd)
{
return 0;
}
 
inline static int fd_input_ready(int fd)
{
return 0;
}
 
int select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,
struct timeval *timeout)
{
int ready;
fd_set oread, owrite, oexcept;
struct timeval now, then;
 
if (nfds > FD_SETSIZE)
{
errno = EINVAL;
return -1;
}
 
FD_ZERO (&oread);
FD_ZERO (&owrite);
FD_ZERO (&oexcept);
ready = 0;
 
if (timeout)
{
if (timeout->tv_usec < 0)
{
errno = EINVAL;
return -1;
}
gettimeofday (&now, 0);
then.tv_usec = timeout->tv_usec + now.tv_usec;
then.tv_sec = timeout->tv_sec + now.tv_sec + then.tv_usec / 1000000;
then.tv_usec %= 1000000;
}
 
do {
int i;
int fd0 = 0;
__file_rec *fr = __file_rec_list;
FILE *fp;
 
/* First, check the file handles with low-level DOS calls. */
for (i = 0; i < nfds; i++)
{
register int ioctl_result;
__FSEXT_Function *func = __FSEXT_get_function(i);
int fsext_ready = -1;
 
if (func)
func(__FSEXT_ready, &fsext_ready, &i);
 
if (readfds && FD_ISSET (i, readfds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_read)
ready++, FD_SET(i, &oread);
}
else if ((ioctl_result = fd_input_ready (i)) == -1)
return -1;
else if (ioctl_result)
ready++, FD_SET (i, &oread);
}
if (writefds && FD_ISSET (i, writefds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_write)
ready++, FD_SET(i, &owrite);
}
else if ((ioctl_result = fd_output_ready (i)) == -1)
return -1;
else if (ioctl_result)
ready++, FD_SET (i, &owrite);
}
if (exceptfds && FD_ISSET (i, exceptfds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_error)
ready++, FD_SET(i, &oexcept);
}
}
}
 
/* Now look at the table of FILE ptrs and reset the bits for file
descriptors which we *thought* are ready, but for which the flags
say they're NOT ready. */
for (i = 0; fr; i++)
{
if (i >= fd0 + fr->count) /* done with this subtable, go to next */
{
fd0 += fr->count;
fr = fr->next;
}
if (fr)
{
fp = fr->files[i - fd0];
if (fp->_flag)
{
int this_fd = fileno(fp);
 
if (this_fd < nfds)
{
if (readfds && FD_ISSET (this_fd, readfds) &&
FD_ISSET (this_fd, &oread) && !fp_input_ready (fp))
ready--, FD_CLR (this_fd, &oread);
if (writefds && FD_ISSET (this_fd, writefds) &&
FD_ISSET (this_fd, &owrite) && !fp_output_ready (fp))
ready--, FD_CLR (this_fd, &owrite);
 
/* For exceptional conditions, ferror() is the only one
which can tell us an exception is pending. */
if (exceptfds && FD_ISSET (this_fd, exceptfds) &&
fp_except_ready (fp))
ready++, FD_SET (this_fd, &oexcept);
}
}
}
}
 
/* Exit if we found what we were waiting for. */
if (ready > 0)
{
if (readfds)
*readfds = oread;
if (writefds)
*writefds = owrite;
if (exceptfds)
*exceptfds = oexcept;
return ready;
}
 
/* Exit if we hit the time limit. */
if (timeout)
{
gettimeofday (&now, 0);
if (now.tv_sec > then.tv_sec
|| (now.tv_sec = then.tv_sec && now.tv_usec >= then.tv_usec))
return 0;
}
} while (1);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/settimeo.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <assert.h>
#include <errno.h>
 
int settimeofday(struct timeval *_tp, ...)
{
return -EPERM;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/utimes.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/time.h>
#include <utime.h>
 
int
utimes(const char *file, struct timeval tvp[2])
{
struct utimbuf utb;
utb.actime = tvp[0].tv_sec;
utb.modtime = tvp[1].tv_sec;
return utime(file, &utb);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/Makefile
0,0 → 1,4
THIS_SRCS= fsync.c ftruncat.c getdtabl.c gethostn.c getpages.c getwd.c \
nice.c sync.c truncate.c usleep.c vfork.c basename.c dirname.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/basename.c
0,0 → 1,28
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <libc/unconst.h>
 
char *
basename (const char *fname)
{
const char *base = fname;
 
if (fname && *fname)
{
if (fname[1] == ':')
{
fname += 2;
base = fname;
}
 
while (*fname)
{
if (*fname == '\\' || *fname == '/')
base = fname + 1;
fname++;
}
}
 
return unconst (base, char *);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/dirname.c
0,0 → 1,62
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
char *
dirname (const char *fname)
{
const char *p = fname;
const char *slash = NULL;
 
if (fname)
{
size_t dirlen;
char * dirpart;
 
if (*fname && fname[1] == ':')
{
slash = fname + 1;
p += 2;
}
 
/* Find the rightmost slash. */
while (*p)
{
if (*p == '/' || *p == '\\')
slash = p;
p++;
}
 
if (slash == NULL)
{
fname = ".";
dirlen = 1;
}
else
{
/* Remove any trailing slashes. */
while (slash > fname && (slash[-1] == '/' || slash[-1] == '\\'))
slash--;
 
/* How long is the directory we will return? */
dirlen = slash - fname + (slash == fname || slash[-1] == ':');
if (*slash == ':' && dirlen == 1)
dirlen += 2;
}
 
dirpart = (char *)malloc (dirlen + 1);
if (dirpart != NULL)
{
strncpy (dirpart, fname, dirlen);
if (slash && *slash == ':' && dirlen == 3)
dirpart[2] = '.'; /* for "x:foo" return "x:." */
dirpart[dirlen] = '\0';
}
 
return dirpart;
}
 
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/fsync.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
 
int fsync(int _fd)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/ftruncat.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <io.h>
#include <errno.h>
 
int ftruncate(int fd, off_t where)
{
int res = dosemu_truncate(fd, where);
if (res) {errno = res; return -1;}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getdtabl.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
int getdtablesize(void)
{
return 255;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/gethostn.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
 
static char pc_n[]= "pc";
 
int gethostname (char *buf, int size)
{
strcpy(buf,"MenuetOS");
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getpages.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
int
getpagesize(void)
{
return 4096;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getwd.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <limits.h>
 
extern char* __get_curdir(void);
char * getwd(char *buffer)
{
if (buffer == 0)
return 0;
char * p=__get_curdir();
sprintf(buffer,"%s",p);
return buffer;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/nice.c
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
/* The references disagree on the values of these. Higher value
means less important process. */
#define NICE_MIN -20
#define NICE_MAX +20
#define NICE_USER 0
 
static int nice_val = NICE_USER;
 
int nice (int incr)
{
if (incr < 0 && getuid () != 0) {
errno = EPERM;
return -1;
}
 
nice_val += incr;
if (nice_val < NICE_MIN) nice_val = NICE_MIN;
if (nice_val > NICE_MAX) nice_val = NICE_MAX;
 
/* This is braindead by design! If -1 returned you don't know
if you had an error! Luckily you can ignore errors for a
function like this. */
errno = 0;
return (nice_val - NICE_USER);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/sync.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
 
int
sync(void)
{
int i;
/* Update files with handles 0 thru 254 (incl). */
for (i = 0; i < 255; i++)
fsync (i);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/truncate.c
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <fcntl.h>
#include <io.h>
#include <assert.h>
 
int truncate(const char *fn, off_t where)
{
int fd = open(fn, O_WRONLY);
if (fd < 0)
return -1;
if (lseek(fd, where, 0) < 0)
{
close(fd);
return -1;
}
if (_write(fd, 0, 0) < 0)
{
close(fd);
return -1;
}
return close(fd);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/usleep.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <time.h>
 
unsigned int usleep(unsigned int _useconds)
{
clock_t cl_time;
clock_t start_time = clock();
_useconds >>= 10;
cl_time = _useconds * CLOCKS_PER_SEC / 977;
while (1)
{
clock_t elapsed = clock() - start_time;
if (elapsed >= cl_time) break;
__menuet__delay100(1);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/vfork.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
 
pid_t
vfork(void)
{
errno = ENOMEM; /* The only other choice is EAGAIN, and we don't want that */
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/Makefile
0,0 → 1,3
THIS_SRCS = _bcopy.s fpurge.c setenv.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/_bcopy.s
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(_bcopy)
jmp C_SYM(bcopy)
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/fpurge.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fpurge(FILE *f)
{
char *base;
 
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base = f->_base) != NULL
&& (f->_ptr - base) > 0)
{
f->_ptr = base;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/setenv.c
0,0 → 1,33
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
 
int
setenv (const char *var, const char *val, int replace)
{
char *prev;
 
if (var == (char *)0 || val == (char *)0)
return -1;
 
if ((prev = getenv (var)) && !replace)
return 0;
else
{
size_t l_var = strlen (var);
char *envstr = (char *)alloca (l_var + strlen (val) + 2);
char *peq = strchr (var, '=');
 
if (*val == '=')
++val;
if (peq)
l_var = peq - var;
 
strncpy (envstr, var, l_var);
envstr[l_var++] = '=';
strcpy (envstr + l_var, val);
 
return putenv (envstr);
}
}
/programs/develop/libraries/menuetlibc/src/libc/copying
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/programs/develop/libraries/menuetlibc/src/libc/copying.dj
0,0 → 1,48
This is the file "copying.dj". It does NOT apply to any sources or
binaries copyrighted by UCB Berkeley, the Free Software Foundation, or
any other agency besides DJ Delorie and others who have agreed to
allow their sources to be distributed under these terms.
 
Copyright Information for sources and executables that are marked
Copyright (C) DJ Delorie
7 Kim Lane
Rochester NH 03867-2954
 
This document is Copyright (C) DJ Delorie and may be distributed
verbatim, but changing it is not allowed.
 
Source code copyright DJ Delorie is distributed under the terms of the
GNU General Public Licence, with the following exceptions:
 
* Sources used to build crt0.o, gcrt0.o, libc.a, libdbg.a, and
libemu.a are distributed under the terms of the GNU Library General
Public License, rather than the GNU GPL.
 
* Any existing copyright or authorship information in any given source
file must remain intact. If you modify a source file, a notice to that
effect must be added to the authorship information in the source file.
 
* Runtime binaries, as provided by DJ in DJGPP, may be distributed
without sources ONLY if the recipient is given sufficient information
to obtain a copy of djgpp themselves. This primarily applies to
go32-v2.exe, emu387.dxe, and stubedit.exe.
 
* Runtime objects and libraries, as provided by DJ in DJGPP, when
linked into an application, may be distributed without sources ONLY
if the recipient is given sufficient information to obtain a copy of
djgpp themselves. This primarily applies to crt0.o and libc.a.
 
-----
 
Changes to source code copyright BSD, FSF, or others, by DJ Delorie
fall under the terms of the original copyright. Such files usually
have multiple copyright notices in them.
 
A copy of the files "COPYING" and "COPYING.LIB" are included with this
document. If you did not receive a copy of these files, you may
obtain one from whence this document was obtained, or by writing:
 
Free Software Foundation
59 Temple Place - Suite 330
Boston, MA 02111-1307
USA
/programs/develop/libraries/menuetlibc/src/libc/copying.lib
0,0 → 1,481
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
 
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
 
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
 
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
 
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
 
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
 
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
 
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
 
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
 
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
 
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
 
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
 
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
 
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
 
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) The modified work must itself be a software library.
 
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
 
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
 
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
 
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
 
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
 
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
 
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
 
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
 
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
 
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
 
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
 
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
 
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
 
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
 
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
 
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
 
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
 
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
 
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
 
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
 
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
 
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
 
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
 
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
 
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
 
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
 
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
 
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
 
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
 
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
 
NO WARRANTY
 
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
 
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
 
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
 
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
 
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
 
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
 
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
 
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
 
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
 
That's all there is to it!
/programs/develop/libraries/menuetlibc/src/libc/crt0/Makefile
0,0 → 1,4
THIS_SRCS= brk.c c1loadef.c c1pglob.c crt0.c crt1.c _main.c \
env.c nullcall.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/crt0/_main.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/internal.h>
#include <libc/bss.h>
 
typedef void (*FUNC)(void);
extern FUNC djgpp_first_ctor[] __asm__("djgpp_first_ctor");
extern FUNC djgpp_last_ctor[] __asm__("djgpp_last_ctor");
 
void
__main(void)
{
static int been_there_done_that = -1;
int i;
if (been_there_done_that == __bss_count)
return;
been_there_done_that = __bss_count;
for (i=0; i<djgpp_last_ctor-djgpp_first_ctor; i++)
djgpp_first_ctor[i]();
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/brk.c
0,0 → 1,135
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
 
static void * ___brk_addr = 0;
extern char end[];
static unsigned long min_brk,max_brk,cur_brk;
extern unsigned long __menuet__memsize;
static void* cur_dynamic_area;
static unsigned cur_total_size;
 
static inline void heap_init(void)
{
__asm__("int $0x40" :: "a"(68),"b"(11));
}
 
static inline void* heap_alloc(unsigned size)
{
void* res;
__asm__("int $0x40" : "=a"(res) : "a"(68),"b"(12),"c"(size));
return res;
}
 
static inline void heap_free(void* ptr)
{
__asm__("int $0x40" :: "a"(68),"b"(13),"c"(ptr));
}
 
void init_brk(void)
{
cur_brk=min_brk=(((unsigned long)&end)+0xfff)&~0xfff;
max_brk=(__menuet__memsize-32768)&~0xfff;
___brk_addr=(void *)min_brk;
cur_dynamic_area = NULL;
cur_total_size = max_brk;
heap_init();
}
 
/*static int sys_brk(unsigned long end_data_seg)
{
if(!end_data_seg) return cur_brk;
if (end_data_seg >= min_brk &&
end_data_seg < max_brk)
cur_brk = end_data_seg;
return cur_brk;
}*/
 
/*int brk(void *_heaptop)
{
return sys_brk((unsigned long)_heaptop);
}
 
static int __init_brk (void)
{
if (___brk_addr == 0)
{
___brk_addr=(void *)sys_brk(0);
if (___brk_addr == 0)
{
errno = ENOMEM;
return -1;
}
}
return 0;
}*/
 
void * sbrk(int increment)
{
/* if (__init_brk () == 0)
{
void * tmp = ___brk_addr+increment;
___brk_addr=(void *)sys_brk((unsigned long)tmp);
if (___brk_addr == tmp) return tmp-increment;
errno = ENOMEM;
return ((void *) -1);
}
return ((void *) -1);*/
void* res;
unsigned long tmp;
if (increment <= 0)
{
/* release memory */
while (cur_dynamic_area && increment)
{
tmp = cur_brk - (unsigned long)cur_dynamic_area -
3*sizeof(void*);
if (tmp > increment)
tmp = increment;
cur_brk -= tmp;
increment -= tmp;
if (cur_brk == (unsigned long)cur_dynamic_area + 3*sizeof(void*))
{
cur_brk = (unsigned long)((void**)cur_dynamic_area)[1];
max_brk = (unsigned long)((void**)cur_dynamic_area)[2];
res = cur_dynamic_area;
cur_dynamic_area = ((void**)cur_dynamic_area)[0];
heap_free(res);
}
}
if (!cur_dynamic_area)
{
cur_brk += increment;
if (cur_brk < min_brk)
cur_brk = min_brk;
}
return (void*)cur_brk;
}
/* allocate memory */
if (cur_brk + increment <= max_brk)
{
/* We have memory in current block, so use it */
res = (void*)cur_brk;
cur_brk += increment;
return res;
}
tmp = 65536;
/* We do not have memory in current block, so allocate new one */
if (increment > 65536 - 3*sizeof(void*))
tmp = (increment + 3*sizeof(void*) + 0xFFF) & ~0xFFF;
res = heap_alloc(tmp);
if (!res)
{
errno = ENOMEM;
return (void*)-1;
}
((void**)res)[0] = cur_dynamic_area;
((void**)res)[1] = (void*)cur_brk;
((void**)res)[2] = (void*)max_brk;
cur_dynamic_area = res;
cur_brk = (unsigned long)res + 3*sizeof(void*);
max_brk = (unsigned long)res + tmp;
res = (void*)cur_brk;
cur_brk += increment;
return (void*)res;
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/c1loadef.c
0,0 → 1,159
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <crt0.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
 
void __crt0_load_environment_file(char *app_name)
{
int djgpp_env;
char *djgpp_var = getenv("DJGPP");
 
if (djgpp_var)
{
djgpp_env = _open(djgpp_var, O_RDONLY);
if (djgpp_env >= 0)
{
char *file;
char base[120], *bp, *a0p, *tb;
int this_prog = 1;
int fsize = lseek(djgpp_env, 0L, SEEK_END);
 
file = (char *)malloc(fsize+2);
if (file == 0)
return;
lseek(djgpp_env, 0L, 0);
_read(djgpp_env, file, fsize);
_close(djgpp_env);
if (file[fsize-1] == '\n')
{
file[fsize] = 0;
}
else
{
file[fsize] = '\n';
file[fsize+1] = 0;
}
tb = file;
 
base[0] = '[';
bp = app_name;
for (a0p = bp; *a0p; a0p++)
if (strchr("\\/:", *a0p))
bp = a0p+1;
for (a0p=base+1; *bp && *bp != '.';)
*a0p++ = tolower(*bp++);
*a0p++ = ']';
*a0p++ = 0;
 
bp = tb;
while (1)
{
tb = bp;
while (*tb && (*tb == '\n' || *tb == '\r'))
tb++;
bp = tb;
while (*bp && *bp != '\n' && *bp != '\r')
bp++;
if (*bp == 0)
break;
*bp++ = 0;
if (tb[0] == 0 || tb[0] == '#')
continue;
if (tb[0] == '[')
{
if (strcmp(tb, base) == 0)
this_prog = 1;
else
this_prog = 0;
}
else
{
if (this_prog)
{
char *buf = alloca(fsize);
char *tb2 = buf;
char *sp=tb, *dp=tb2;
while (*sp != '=')
*dp++ = *sp++;
if (*tb2 == '+') /* non-overriding */
{
*dp = 0;
tb2++;
if (getenv(tb2))
continue; /* while scanning bytes */
}
*dp++ = *sp++; /* copy the '=' */
while (*sp)
{
if (*sp == '%')
{
char *pp;
if (sp[1] == '%')
{
*dp++ = '%';
sp += 2;
}
else
{
char ps, *e, *dirend;
int dirpart=0, apsemi=0;
int mapup=0, maplow=0, mapfs=0, mapbs=0;
while (strchr(":;/\\<>", sp[1]))
{
switch (sp[1])
{
case ':': dirpart=1; break;
case ';': apsemi=1; break;
case '/': mapfs=1; break;
case '\\': mapbs=1; break;
case '<': mapup=1; break;
case '>': maplow=1; break;
}
sp++;
}
for (pp=sp+1; *pp && *pp != '%'; pp++);
ps = *pp;
*pp = 0;
e = getenv(sp+1);
dirend = dp;
if (e)
{
while (*e)
{
char ec = *e++;
if (strchr("\\/:", ec))
dirend=dp;
if (mapup) ec = toupper(ec);
if (maplow) ec = tolower(ec);
if (mapfs && ec == '\\') ec = '/';
if (mapbs && ec == '/') ec = '\\';
*dp++ = ec;
}
}
if (dirpart)
dp = dirend;
if (apsemi && e)
*dp++ = ';';
if (ps == 0)
break;
sp = pp+1;
}
}
else
*dp++ = *sp++;
}
*dp++ = 0;
putenv(tb2);
}
}
}
free(file);
}
}
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/c1pglob.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <crt0.h>
#include <glob.h>
 
char ** __crt0_glob_function(char *arg)
{
char **rv;
glob_t g;
if (glob(arg, GLOB_NOCHECK, 0, &g) != 0)
return 0;
rv = g.gl_pathv;
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/crt0.c
0,0 → 1,401
#include<menuet/os.h>
#include<unistd.h>
 
void _exit(int code)
{
__asm__ __volatile__("int $0x40"::"a"(-1));
for(;;);
}
 
#include <libc/stubs.h>
#include <io.h>
#include <unistd.h>
#include <stdlib.h>
#include <crt0.h>
#include <libc/farptrgs.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
 
#define ds _my_ds()
 
 
extern char __menuet__app_param_area[];
extern char __menuet__app_path_area[];
 
static void * c1xmalloc(size_t s)
{
void *q = malloc(s);
if (q == 0)
{
#define err(x)
err("No memory to gather arguments\r\n");
_exit(1);
}
return q;
}
 
static int atohex(char *s)
{
int rv = 0;
while (*s)
{
int v = *s - '0';
if (v > 9)
v -= 7;
v &= 15; /* in case it's lower case */
rv = rv*16 + v;
s++;
}
return rv;
}
 
typedef struct Arg {
char *arg;
char **arg_globbed;
struct ArgList *arg_file;
struct Arg *next;
int was_quoted;
} Arg;
 
typedef struct ArgList {
int argc;
Arg **argv;
} ArgList;
 
static Arg *new_arg(void)
{
Arg *a = (Arg *)c1xmalloc(sizeof(Arg));
memset(a, 0, sizeof(Arg));
return a;
}
 
static void delete_arglist(ArgList *al);
 
static void delete_arg(Arg *a)
{
if (a->arg) free(a->arg);
if (a->arg_globbed)
{
int i;
for (i=0; a->arg_globbed[i]; i++)
free(a->arg_globbed[i]);
free(a->arg_globbed);
}
if (a->arg_file)
delete_arglist(a->arg_file);
free(a);
}
 
static ArgList * new_arglist(int count)
{
ArgList *al = (ArgList *)c1xmalloc(sizeof(ArgList));
al->argc = count;
al->argv = (Arg **)c1xmalloc((count+1)*sizeof(Arg *));
memset(al->argv, 0, (count+1)*sizeof(Arg *));
return al;
}
 
static void delete_arglist(ArgList *al)
{
int i;
for (i=0; i<al->argc; i++)
delete_arg(al->argv[i]);
free(al->argv);
free(al);
}
 
static char * parse_arg(char *bp, char *last, int unquote, size_t *len, int *was_quoted)
{
char *ep = bp, *epp = bp;
int quote=0;
 
while ((quote || !isspace(*(unsigned char *)ep)) && ep < last)
{
if (quote && *ep == quote)
{
quote = 0;
if (!unquote)
*epp++ = *ep;
ep++;
}
else if (!quote && (*ep == '\'' || *ep == '"'))
{
quote = *ep++;
if (!unquote)
*epp++ = quote;
}
else if (*ep == '\\' && strchr("'\"", ep[1]) && ep < last-1)
{
if (!unquote)
*epp++ = *ep;
ep++;
*epp++ = *ep++;
/* *was_quoted = 1; - This makes no sense. */
}
else
{
if ((quote && (strchr("[?*", *ep) || strncmp(ep, "...", 3) == 0))
&& unquote)
*was_quoted = 1;
*epp++ = *ep++;
}
}
 
*len = epp - bp;
return ep;
}
 
static ArgList * parse_bytes(char *bytes, int length, int unquote)
{
int largc, i;
Arg *a, **anext, *afirst;
ArgList *al;
char *bp=bytes, *ep, *last=bytes+length;
 
anext = &afirst;
largc = 0;
while (bp<last)
{
size_t arg_len;
while (isspace(*(unsigned char *)bp) && bp < last)
bp++;
if (bp == last)
break;
*anext = a = new_arg();
ep = parse_arg(bp, last, unquote, &arg_len, &(a->was_quoted));
anext = &(a->next);
largc++;
a->arg = (char *)c1xmalloc(arg_len+1);
memcpy(a->arg, bp, arg_len);
a->arg[arg_len] = 0;
bp = ep+1;
}
al = new_arglist(largc);
for (i=0, a=afirst; i<largc; i++, a=a->next)
al->argv[i] = a;
return al;
}
 
static ArgList * parse_print0(char *bytes, int length)
{
int largc, i;
Arg *a, **anext, *afirst;
ArgList *al;
char *bp=bytes, *ep, *last=bytes+length;
 
anext = &afirst;
largc = 0;
while (bp<last)
{
size_t arg_len = strlen(bp);
ep = bp;
bp += arg_len + 1;
*anext = a = new_arg();
a->was_quoted = 1;
anext = &(a->next);
largc++;
a->arg = (char *)c1xmalloc(arg_len+1);
memcpy(a->arg, ep, arg_len);
a->arg[arg_len] = 0;
}
al = new_arglist(largc);
for (i=0, a=afirst; i<largc; i++, a=a->next)
al->argv[i] = a;
return al;
}
 
static int count_args(ArgList *al)
{
int i, r=0;
for (i=0; i<al->argc; i++)
{
int j;
if (al->argv[i]->arg_globbed)
{
for (j=0; al->argv[i]->arg_globbed[j]; j++);
r += j;
}
else if (al->argv[i]->arg_file)
{
r += count_args(al->argv[i]->arg_file);
}
else
{
r++;
}
}
return r;
}
 
static char ** fill_args(char **largv, ArgList *al)
{
int i;
for (i=0; i<al->argc; i++)
{
int j;
if (al->argv[i]->arg_globbed)
{
for (j=0; al->argv[i]->arg_globbed[j]; j++)
{
*largv++ = al->argv[i]->arg_globbed[j];
al->argv[i]->arg_globbed[j] = 0;
}
}
else if (al->argv[i]->arg_file)
{
largv = fill_args(largv, al->argv[i]->arg_file);
}
else
{
*largv++ = al->argv[i]->arg;
al->argv[i]->arg = 0;
}
}
return largv;
}
 
static void expand_response_files(ArgList *al)
{
int i, f;
for (i=0; i<al->argc; i++)
{
if (! al->argv[i]->was_quoted && al->argv[i]->arg[0] == '@')
if ((f = _open(al->argv[i]->arg+1, O_RDONLY)) >= 0)
{
char *bytes;
int len, st_size;
st_size = lseek(f, 0L, SEEK_END);
lseek(f, 0L, SEEK_SET);
if (st_size < 0)
st_size = 0;
bytes = (char *)c1xmalloc(st_size+1);
len = _read(f, bytes, st_size);
if (len < 0)
len = 0;
_close(f);
/* if the last character is ^Z, remove it */
if (len > 0 && bytes[len-1] == 0x1a)
len--;
/* assume 'find -print0' if the last char is a '\0' */
if (len > 0 && bytes[len-1] == '\0')
al->argv[i]->arg_file = parse_print0(bytes, len);
else
al->argv[i]->arg_file = parse_bytes(bytes, len, (_crt0_startup_flags & _CRT0_FLAG_KEEP_QUOTES) == 0);
expand_response_files(al->argv[i]->arg_file);
free(bytes);
}
}
}
 
static void expand_wildcards(ArgList *al)
{
int i;
for (i=0; i<al->argc; i++)
{
if (al->argv[i]->arg_file)
expand_wildcards(al->argv[i]->arg_file);
else if (!(al->argv[i]->was_quoted))
{
al->argv[i]->arg_globbed = __crt0_glob_function(al->argv[i]->arg);
}
}
}
 
static void add_arg(const char* arg, const char* end)
{
char* res;
__crt0_argv = realloc(__crt0_argv, 4*(++__crt0_argc));
res = malloc(end-arg+1);
if (!__crt0_argv || !res) _exit(1);
__crt0_argv[__crt0_argc-1] = res;
while (arg < end)
{
if (arg[0] == '"' && arg[1] == '"') ++arg;
*res++ = *arg++;
}
*res = 0;
}
 
void __crt0_setup_arguments(void)
{
#if 0
// ­¥ ¡ã¤¥¬ áâà ¤ âì 䨣­ñ©...
ArgList *arglist;
char *argv0;
int prepend_argv0 = 1;
int should_expand_wildcards = 1;
char *proxy_v = 0;
argv0="menuet.app";
/*
** Next, scan dos's command line.
*/
{
char doscmd[128];
memcpy(doscmd+1,__menuet__app_param_area,128);
arglist = parse_bytes(doscmd+1, doscmd[0] & 0x7f,
(_crt0_startup_flags & _CRT0_FLAG_KEEP_QUOTES) == 0);
}
 
/*
** Now, expand response files
*/
if (!(_crt0_startup_flags & _CRT0_FLAG_DISALLOW_RESPONSE_FILES))
expand_response_files(arglist);
 
/*
** Now, expand wildcards
*/
 
if (should_expand_wildcards)
expand_wildcards(arglist);
 
__crt0_argc = prepend_argv0 + count_args(arglist);
__crt0_argv = (char **)c1xmalloc((__crt0_argc+1) * sizeof(char *));
if (prepend_argv0)
__crt0_argv[0] = argv0;
*fill_args(__crt0_argv+prepend_argv0, arglist) = 0;
#else
// ...  ¯à®áâ® à §¡¥àñ¬ ª®¬ ­¤­ãî áâபã. - diamond
char* ptr;
char* cur_arg=NULL;
int bInQuote=0;
add_arg(__menuet__app_path_area,
__menuet__app_path_area + strlen(__menuet__app_path_area));
for (ptr=__menuet__app_param_area;*ptr && ptr<__menuet__app_param_area+256;ptr++)
{
if (*ptr == ' ' || *ptr == '\t')
{
if (cur_arg && !bInQuote)
{
add_arg(cur_arg,ptr);
cur_arg = NULL;
}
continue;
}
if (*ptr == '"')
{
if (ptr[1] == '"')
{if (!cur_arg) cur_arg=ptr;ptr++;}
else
{
if (cur_arg)
{
add_arg(cur_arg,ptr);
if (bInQuote)
{
bInQuote = 0;
cur_arg = NULL;
continue;
}
}
bInQuote = 1;
cur_arg = ptr+1;
}
continue;
}
if (!cur_arg) cur_arg = ptr;
}
if (cur_arg) add_arg(cur_arg,ptr);
#endif
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/crt1.c
0,0 → 1,49
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <crt0.h>
#include <string.h>
#include <libc/internal.h>
#include <stdlib.h>
#include <libc/farptrgs.h>
#include <pc.h>
#include <libc/bss.h>
#include <menuet/os.h>
 
/* Global variables */
 
#define ds _my_ds()
 
int __bss_count = 1;
 
char **environ;
int _crt0_startup_flags; /* default to zero unless app overrides them */
int __crt0_argc=0;
char ** __crt0_argv=NULL;
 
char * __dos_argv0;
 
extern __u32 __menuet__getmemsize(void);
 
extern void __main(void);
extern int main(int, char **);
extern void _crt0_init_mcount(void); /* For profiling */
void __crt0_setup_arguments(void);
extern char __menuet__app_param_area[];
 
//void dosemu_atexit(void);
 
void __crt1_startup(void)
{
init_brk();
if(__menuet__app_param_area[0]!='\0')
__crt0_setup_arguments();
dosemu_inithandles();
init_dir_stack();
// atexit(dosemu_atexit);
__main();
{
int stat=main(__crt0_argc,__crt0_argv);
exit(stat);
}
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/env.c
0,0 → 1,16
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
 
static char **SDL_env = (char **)0;
 
int __libc_putenv(const char *variable)
{
return -1;
}
 
char * __libc_getenv(const char *name)
{
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/nullcall.c
0,0 → 1,14
struct __frame
{
unsigned long ebp,edi,esi,edx,ecx,ebx,eax,eip;
};
 
void __libc_null_call(volatile struct __frame frame)
{
__libclog_printf("Bad call occured from EIP=%x\n",frame.eip);
__libclog_printf("EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n",
frame.eax,frame.ebx,frame.ecx,frame.edx);
__libclog_printf("ESI=%08x EDI=%08x EBP=%08x\n",
frame.esi,frame.edi,frame.ebp);
_exit(1);
}
/programs/develop/libraries/menuetlibc/src/libc/crt0/thread.c
0,0 → 1,130
#include<menuet/os.h>
#include<stdlib.h>
#include<string.h>
#include<menuet/sem.h>
#include<menuet/thread.h>
#include<assert.h>
 
#define MAX_THREADS 128
 
typedef struct
{
int flags;
void (* fn_ptr)(void);
void * thr_stack;
int pid;
} thread_t;
 
static thread_t * thr[MAX_THREADS];
DECLARE_STATIC_SEM(thr_list_sem);
 
static void do_thr_atexit(void);
 
void init_threads(void)
{
register int i;
sem_lock(&thr_list_sem);
for(i=0;i<MAX_THREADS;i++) thr[i]=NULL;
sem_unlock(&thr_list_sem);
atexit(do_thr_atexit);
}
 
int get_thread_pid(int tid)
{
sem_lock(&thr_list_sem);
if(tid>=0 && tid<MAX_THREADS && thr[tid])
{
sem_unlock(&thr_list_sem);
return thr[tid]->pid;
}
sem_unlock(&thr_list_sem);
return -1;
}
 
int get_thread_tid(int pid)
{
register int i;
sem_lock(&thr_list_sem);
for(i=0;i<MAX_THREADS;i++)
{
if(thr[i] && thr[i]->pid==pid)
{
sem_unlock(&thr_list_sem);
return i;
}
}
sem_unlock(&thr_list_sem);
return -1;
}
 
static void do_thr_atexit(void)
{
register int i;
sem_lock(&thr_list_sem);
for(i=0;i<MAX_THREADS;i++)
{
if(thr[i] && (thr[i]->flags & THR_ATEXIT))
{
__asm__ __volatile__("int $0x40"::"a"(18),"b"(2),"c"(thr[i]->pid));
free(thr[i]->thr_stack);
free(thr[i]);
thr[i]=NULL;
}
}
sem_unlock(&thr_list_sem);
}
 
int create_thread(void (* fn)(void),int stacksize,int flags,void ** rstackp)
{
int i;
if(stacksize<4096) stacksize=4096;
sem_lock(&thr_list_sem);
for(i=0;i<MAX_THREADS;i++)
{
if(!thr[i])
{
thr[i]=(thread_t *)malloc(sizeof(thread_t));
thr[i]->thr_stack=malloc(stacksize);
if(!thr[i]->thr_stack)
{
free(thr[i]);
thr[i]=NULL;
sem_unlock(&thr_list_sem);
return -1;
}
thr[i]->flags=flags;
thr[i]->fn_ptr=fn;
__asm__ __volatile__("int $0x40":"=a"(thr[i]->pid)
:"a"(51),"b"(1),"c"(fn),"d"(thr[i]->thr_stack+stacksize)
);
if(thr[i]->pid==-1)
{
free(thr[i]);
thr[i]=NULL;
sem_unlock(&thr_list_sem);
return -1;
}
sem_unlock(&thr_list_sem);
return i;
}
}
sem_unlock(&thr_list_sem);
return -1;
}
 
void kill_thread(int tid)
{
assert(tid<0);
assert(tid>=MAX_THREADS);
assert(get_thread_pid(tid)<0);
assert(!thr[tid]);
sem_lock(&thr_list_sem);
if(thr[tid]->flags & THR_KILLER)
{
thr[tid]->flags=0;
sem_unlock(&thr_list_sem);
do_thr_atexit();
exit(0);
}
__asm__ __volatile__("int $0x40"::"a"(18),"b"(2),"c"(thr[tid]->pid));
}
/programs/develop/libraries/menuetlibc/src/libc/dos/Makefile
0,0 → 1,29
all:
make -C compat
make -C dir
make -C dos
make -C dos_emu
make -C errno
make -C io
make -C process
make -C sys
 
clean:
make -C compat clean
make -C dir clean
make -C dos clean
make -C dos_emu clean
make -C errno clean
make -C io clean
make -C process clean
make -C sys clean
 
depend:
make -C compat depend
make -C dir depend
make -C dos depend
make -C dos_emu depend
make -C errno depend
make -C io depend
make -C process depend
make -C sys depend
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/Makefile
0,0 → 1,6
THIS_SRCS = d_close.c d_commit.c d_creat.c d_creatn.c d_exterr.c d_findf.c \
d_findn.c d_getdat.c d_getdf.c d_getdrv.c d_getfa.c d_getftm.c \
d_gettim.c d_open.c d_read.c d_setdat.c d_setdrv.c d_setfa.c d_setftm.c \
d_settim.c d_write.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_close.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CLOSE.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_close(int handle)
{
return dosemu_close(handle);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_commit.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_COMMIT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_commit(int handle)
{
_dosemu_flush(handle);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_creat.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CREAT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include <unistd.h>
#include <fcntl.h>
 
static char buf[1];
 
unsigned int _dos_creat(const char *filename, unsigned int attr, int *handle)
{
int i;
i=dosemu_open(filename,attr|O_CREAT);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_creatn.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CREATN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include<unistd.h>
#include <fcntl.h>
 
static char buf[1];
 
unsigned int _dos_creatnew(const char *filename, unsigned int attr, int *handle)
{
int i;
i=dosemu_open(filename,attr|O_CREAT|O_EXCL);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_exterr.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_EXTERR.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
int _dosexterr(struct _DOSERROR *p_error)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_findf.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_FINDF.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <string.h>
#include <dos.h>
 
unsigned int _dos_findfirst(char *name, unsigned int attr, struct _find_t *result)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_findn.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_FINDN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_findnext(struct _find_t *result)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdat.c
0,0 → 1,17
#include <errno.h>
#include <dos.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void _dos_getdate(struct _dosdate_t *date)
{
unsigned long tmp;
__asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29));
date->year=2000+(tmp&0xff);
date->month=(tmp>>8)&0xff;
date->day= (tmp>>16)&0xff;
date->dayofweek=0; /* xxx - how to do it correctly ? */
BCD_TO_BIN(date->year);
BCD_TO_BIN(date->month);
BCD_TO_BIN(date->day);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdf.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETDF.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
#include <errno.h>
 
unsigned int _dos_getdiskfree(unsigned int drive, struct _diskfree_t *diskspace)
{
diskspace->sectors_per_cluster = 1;
diskspace->avail_clusters = 0xFFFF;
diskspace->bytes_per_sector = 512;
diskspace->total_clusters = 0xFFFF;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdrv.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETDRV.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
void _dos_getdrive(unsigned int *p_drive)
{
*p_drive = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getfa.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETFA.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_getfileattr(const char *filename, unsigned int *p_attr)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getftm.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETFTM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_getftime(int handle, unsigned int *p_date, unsigned int *p_time)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_gettim.c
0,0 → 1,15
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
#include <dos.h>
 
void _dos_gettime(struct _dostime_t *time)
{
unsigned long tmp=__menuet__getsystemclock();
time->hour=tmp&0xff;
time->minute=(tmp>>8)&0xff;
time->second=(tmp>>16)&0xff;
time->hsecond=0;
BCD_TO_BIN(time->hour);
BCD_TO_BIN(time->minute);
BCD_TO_BIN(time->second);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_open.c
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_OPEN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include<menuet/os.h>
 
unsigned int _dos_open(const char *filename, unsigned int mode, int *handle)
{
int i;
i=dosemu_open(filename,mode);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_read.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_READ.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#define FSLAYER
#include<menuet/os.h>
 
unsigned int _dos_read(int handle, void *buffer, unsigned int count, unsigned int *result)
{
int p;
p=dosemu_read(handle,buffer,count);
if(p==-1) return p;
if(result) *result=p;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setdat.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETDAT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setdate(struct _dosdate_t *date)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setdrv.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETDRV.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
void _dos_setdrive(unsigned int drive, unsigned int *p_drives)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setfa.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETFA.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setfileattr(const char *filename, unsigned int attr)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setftm.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETFTM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setftime(int handle, unsigned int date, unsigned int time)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_settim.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETTIM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_settime(struct _dostime_t *time)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_write.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_WITE.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_write(int handle, const void *buffer, unsigned int count, unsigned int *result)
{
int p;
p=dosemu_write(handle,buffer,count);
if(p==-1) return p;
if(result) *result=p;
return 0;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/Makefile
0,0 → 1,4
THIS_SRCS = findfirs.c findnext.c fnmerge.c fnsplit.c ftreewlk.c \
ftw.c getdisk.c setdisk.c srchpath.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findfirs.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findnext.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findnext(struct ffblk *ffblk)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnmerge.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <string.h>
 
void
fnmerge (char *path, const char *drive, const char *dir,
const char *name, const char *ext)
{
*path = '\0';
if (drive && *drive)
{
path[0] = drive[0];
path[1] = ':';
path[2] = 0;
}
if (dir && *dir)
{
char last_dir_char = dir[strlen(dir) - 1];
 
strcat(path, dir);
if (last_dir_char != '/' && last_dir_char != '\\')
strcat(path, strchr(dir, '\\') ? "\\" : "/");
}
if (name)
strcat(path, name);
if (ext && *ext)
{
if (*ext != '.')
strcat(path, ".");
strcat(path, ext);
}
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnsplit.c
0,0 → 1,120
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <ctype.h>
#include <string.h>
 
static char *
max_ptr(char *p1, char *p2)
{
if (p1 > p2)
return p1;
else
return p2;
}
 
int
fnsplit (const char *path, char *drive, char *dir,
char *name, char *ext)
{
int flags = 0, len;
const char *pp, *pe;
 
if (drive)
*drive = '\0';
if (dir)
*dir = '\0';
if (name)
*name = '\0';
if (ext)
*ext = '\0';
 
pp = path;
 
if ((isalpha(*pp) || strchr("[\\]^_`", *pp)) && (pp[1] == ':'))
{
flags |= DRIVE;
if (drive)
{
strncpy(drive, pp, 2);
drive[2] = '\0';
}
pp += 2;
}
 
pe = max_ptr(strrchr(pp, '\\'), strrchr(pp, '/'));
if (pe)
{
flags |= DIRECTORY;
pe++;
len = pe - pp;
if (dir)
{
strncpy(dir, pp, len);
dir[len] = '\0';
}
pp = pe;
}
else
pe = pp;
 
/* Special case: "c:/path/." or "c:/path/.."
These mean FILENAME, not EXTENSION. */
while (*pp == '.')
++pp;
if (pp > pe)
{
flags |= FILENAME;
if (name)
{
len = pp - pe;
strncpy(name, pe, len);
name[len] = '\0';
}
}
 
pe = strrchr(pp, '.');
if (pe)
{
flags |= EXTENSION;
if (ext)
strcpy(ext, pe);
}
else
pe = strchr( pp, '\0');
 
if (pp != pe)
{
flags |= FILENAME;
len = pe - pp;
if (name)
{
strncpy(name, pp, len);
name[len] = '\0';
}
}
 
if (strcspn(path, "*?[") < strlen(path))
flags |= WILDCARDS;
 
return flags;
}
 
#ifdef TEST
 
#include <stdio.h>
 
int
main(void)
{
char arg[81], drive[81], dir[81], fname[81], ext[81];
 
fputs("> ", stdout); fflush(stdout);
gets(arg);
 
printf("`%s' (%x): `%s' `%s' `%s' `%s'\n", arg,
fnsplit(arg, drive, dir, fname, ext), drive, dir, fname, ext);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftreewlk.c
0,0 → 1,171
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy. We cannot
* use ftw(), because it uses some non-ANSI functions which
* will pollute ANSI namespace, while we need this function
* in some ANSI functions (e.g., rename()). Thus, this function
* is closely modeled on ftw(), but uses DOS directory search
* functions and structures instead of opendir()/readdir()/stat().
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <dir.h>
 
#define FA_ALL (FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC|FA_ARCH)
 
int
__file_tree_walk(const char *dir,
int (*func)(const char *, const struct ffblk *))
{
struct ffblk ff;
unsigned char searchspec[FILENAME_MAX];
unsigned char found[FILENAME_MAX], *dir_end;
int e = errno;
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
/* Construct the search spec for findfirst(). Treat ``d:'' as ``d:.''. */
strcpy(searchspec, dir);
dir_end = searchspec + strlen(searchspec) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
*++dir_end = '\0';
}
else if (*dir_end == '/' || *dir_end == '\\')
*dir_end = '\0';
else
++dir_end;
strcpy(dir_end, "/*.*");
 
/* Prepare the buffer where the full pathname of the found files
will be placed. */
strcpy(found, dir);
dir_end = found + strlen(found) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
dir_end[1] = '\0';
}
if (*dir_end != '/' && *dir_end != '\\')
{
/* Try to preserve user's forward/backward slash style. */
*++dir_end = strchr(found, '\\') == 0 ? '/': '\\';
*++dir_end = '\0';
}
else
++dir_end;
 
if (findfirst(searchspec, &ff, FA_ALL))
return -1;
 
do
{
int func_result;
unsigned char *p = dir_end;
 
/* Skip `.' and `..' entries. */
if (ff.ff_name[0] == '.' &&
(ff.ff_name[1] == '\0' || ff.ff_name[1] == '.'))
continue;
 
/* Construct full pathname in FOUND[]. */
strcpy(dir_end, ff.ff_name);
 
/* Convert name of found file to lower-case. Cannot use
strlwr() because it's non-ANSI. Sigh... */
while (*p)
*p++ = tolower(*p);
 
/* Invoke FUNC() on this file. */
if ((func_result = (*func)(found, &ff)) != 0)
return func_result;
 
/* If this is a directory, walk its siblings. */
if (ff.ff_attrib & 0x10)
{
int subwalk_result;
 
if ((subwalk_result = __file_tree_walk(found, func)) != 0)
return subwalk_result;
}
} while (findnext(&ff) == 0);
 
if (errno == ENMFILE) /* normal case: tree exhausted */
{
errno = e; /* restore errno from previous syscall */
return 0;
}
 
return -1; /* error; errno set by findnext() */
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ff_walker(const char *path, const struct ffblk *ff)
{
printf("%s:\t%lu\t", path, ff->ff_fsize);
if (ff->ff_attrib & 1)
printf("R");
if (ff->ff_attrib & 2)
printf("H");
if (ff->ff_attrib & 4)
printf("S");
if (ff->ff_attrib & 8)
printf("V");
if (ff->ff_attrib & 0x10)
printf("D");
if (ff->ff_attrib & 0x20)
printf("A");
printf("\n");
 
if (strcmp(ff->ff_name, "XXXXX") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
file_tree_walk(argv[1], ff_walker));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftw.c
0,0 → 1,220
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* ftw() for DJGPP.
*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy.
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <io.h>
#include <ftw.h>
 
static int
walk_dir(char *path, int (*func)(const char *, struct stat *, int))
{
DIR *dp;
struct dirent *de;
struct stat stbuf;
int flag;
int e = errno;
int pathlen = strlen(path);
 
if ((dp = opendir(path)) == 0)
return -1;
 
for (errno = 0; (de = readdir(dp)) != 0; errno = 0)
{
int func_result;
char lastc = de->d_name[de->d_namlen - 1];
 
/* Skip `.' and `..' entries. Checking the last char is enough,
because readdir will never return a filename which ends with
a dot. */
if (lastc == '.')
continue;
 
/* Append found name to directory path. */
if (pathlen + de->d_namlen + 1 > FILENAME_MAX)
{
(void)closedir(dp);
errno = ENAMETOOLONG;
return -1;
}
if (path[pathlen-1] == '/' || path[pathlen-1] == '\\')
pathlen--;
path[pathlen] = '/';
strcpy(path + pathlen + 1, de->d_name);
 
if (stat(path, &stbuf) < 0)
flag = FTW_NS;
else if (S_ISDIR(stbuf.st_mode))
flag = FTW_D;
else if (S_ISLABEL(stbuf.st_mode))
flag = FTW_VL;
else
flag = FTW_F;
 
/* Invoke FUNC() on this object. */
errno = e;
if ((func_result = (*func)(path, &stbuf, flag)) != 0)
{
(void)closedir(dp);
return func_result;
}
 
/* If this is a directory, walk its siblings. */
if (flag == FTW_D)
{
int subwalk_result;
 
errno = e;
if ((subwalk_result = walk_dir(path, func)) != 0)
{
(void)closedir(dp);
return subwalk_result;
}
}
 
/* Erase D_NAME[] from PATH. */
path[pathlen] = '\0';
}
 
(void)closedir(dp);
if (errno == 0) /* normal case: this subtree exhausted */
{
errno = e;/* restore errno from previous syscall */
return 0;
}
else
return -1; /* with whatever errno was set by readdir() */
}
 
int
ftw(const char *dir, int (*func)(const char *, struct stat *, int),
int ignored)
{
int flag;
unsigned char pathbuf[FILENAME_MAX];
int dirattr;
int len;
int e = errno;
 
ignored = ignored; /* pacify -Wall */
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
strcpy(pathbuf, dir);
len = strlen(pathbuf);
if (pathbuf[len-1] == ':')
{
pathbuf[len++] = '.';
pathbuf[len] = '\0';
}
 
/* Fail for non-directories. */
errno = 0;
dirattr = _chmod(pathbuf, 0, 0);
if (errno == ENOENT)
return -1;
else if ((dirattr & 0x10) != 0x10)
{
errno = ENOTDIR;
return -1;
}
else
{
int func_result;
struct stat stbuf;
 
if (stat(pathbuf, &stbuf) < 0)
flag = FTW_NS;
else
flag = FTW_D;
errno = e;
if ((func_result = (*func)(pathbuf, &stbuf, flag)) != 0)
return func_result;
return walk_dir(pathbuf, func);
}
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ftw_walker(const char *path, struct stat *sb, int flag)
{
char *base;
 
printf("%s:\t%u\t", path, sb->st_size);
if (S_ISLABEL(sb->st_mode))
printf("V");
if (S_ISDIR(sb->st_mode))
printf("D");
if (S_ISCHR(sb->st_mode))
printf("C");
if (sb->st_mode & S_IRUSR)
printf("r");
if (sb->st_mode & S_IWUSR)
printf("w");
if (sb->st_mode & S_IXUSR)
printf("x");
 
if (flag == FTW_NS)
printf(" !!no_stat!!");
printf("\n");
 
base = strrchr(path, '/');
if (base == 0)
base = strrchr(path, '\\');
if (base == 0)
base = strrchr(path, ':');
if (strcmp(base == 0 ? path : base + 1, "xxxxx") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
ftw(argv[1], ftw_walker, 0));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/getdisk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <dir.h>
 
int getdisk(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/setdisk.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
 
int setdisk(int _drive)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/srchpath.c
0,0 → 1,92
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <limits.h>
#include <dir.h>
/* Search PATH for FILE.
If successful, store the full pathname in static buffer and return a
pointer to it.
If not sucessful, return NULL.
This is what the Borland searchpath() library function does.
*/
char *
searchpath(const char *file)
{
static char found[PATH_MAX];
static char *path;
 
memset(found, 0, sizeof(found));
/* Get the PATH and store it for reuse. */
if (path == 0)
{
char *p = getenv("PATH");
path = (char *)calloc(p ? strlen(p) + 3 : 2, sizeof(char));
if (path == (char *)0)
return (char *)0;
/* Prepend `.' to the PATH, so current directory
is always searched. */
path[0] = '.';
if (p)
{
register char *s;
path[1] = ';';
strcpy(path+2, p);
/* Convert to more plausible form. */
for (s = path; *s; ++s)
{
if (*s == '\\')
*s = '/';
if (isupper(*s))
*s = tolower(*s);
}
}
else
path[1] = 0;
}
if (strpbrk (file, "/\\:") != 0)
{
strcpy(found, file);
return found;
}
else
{
char *test_dir = path;
do {
char *dp;
dp = strchr(test_dir, ';');
if (dp == (char *)0)
dp = test_dir + strlen(test_dir);
if (dp == test_dir)
strcpy(found, file);
else
{
strncpy(found, test_dir, dp - test_dir);
found[dp - test_dir] = '/';
strcpy(found + (dp - test_dir) + 1, file);
}
 
if (__file_exists(found))
return found;
 
if (*dp == 0)
break;
test_dir = dp + 1;
} while (*test_dir != 0);
}
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/Makefile
0,0 → 1,6
THIS_SRCS = bdos.c bdosptr.s delay.c fexistp.c getcbrk.c getdate.c getdfree.c \
getdinfo.c getdos_v.c getftime.c gettime.c gettimeo.c \
osflavor.c osmajor.c osminor.c remotdrv.c \
remothdl.c setcbrk.c setdate.c setftime.c settime.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/bdos.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int bdos(int func, unsigned dx, unsigned al)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/bdosptr.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(bdosptr)
jmp C_SYM(bdos)
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/delay.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <menuet/os.h>
 
void delay(unsigned msec)
{
__menuet__delay100(msec);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/fexistp.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <stdio.h>
 
int __file_exists(const char *fn)
{
FILE * f;
f=fopen(fn,"r");
if(!f) return 0;
fclose(f);
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getcbrk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int getcbrk(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdate.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void getdate( struct date *dateblk)
{
unsigned long tmp;
__asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29));
dateblk->da_year=2000+(tmp&0xff);
dateblk->da_mon=(tmp>>8)&0xff;
dateblk->da_day=(tmp>>16)&0xff;
BCD_TO_BIN(dateblk->da_year);
BCD_TO_BIN(dateblk->da_mon);
BCD_TO_BIN(dateblk->da_day);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdfree.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <errno.h>
#include <assert.h>
 
void getdfree(unsigned char drive, struct dfree *dtable)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdinfo.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file GETDINFO.C */
/*
* Get device info word by calling IOCTL Function 0.
*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
 
short _get_dev_info(int);
 
short _get_dev_info(int fhandle)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdos_v.c
0,0 → 1,62
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file GETDOS_V.C
*
* Copyright (c) 1994,95 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/bss.h>
#include <dos.h>
 
/* Return OS version number, either true or ``simulated'' one.
Global variables _OSMAJOR and _OSMINOR are ALWAYS set to whatever
INT 21h/AX=30h returns. Global _OS_FLAVOR is set to a string
which identifies the OEM of DOS.
*/
 
/* From Ralph Brown's interrupt list, v.45.
Note: some OEMs, like Novell NDOS 7, Compaq DOS 3.31 and possibly
others return 0 OEM code, like IBM PC-DOS. There is nothing
I can do to overcome this.
*/
static struct _oem_info {
unsigned char oem_num;
const char * oem_name;
} dos_flavors[] = {
{0, "IBM PC-DOS"},
{1, "Compaq DOS"},
{2, "Microsoft DOS"},
{4, "AT&T DOS"},
{5, "Zenith DOS"},
{6, "Hewlett-Packard DOS"},
{7, "Groupe Bull DOS"},
{0xd, "Packard-Bell DOS"},
{0x16, "DEC DOS"},
{0x23, "Olivetti DOS"},
{0x28, "Texas Instruments DOS"},
{0x29, "Toshiba DOS"},
{0x33, "Novell Win3 device ID"},
{0x34, "MS Multimedia Win3 device ID"},
{0x35, "MS Multimedia Win3 device ID"},
{0x4d, "Hewlett-Packard DOS"},
{0x5e, "RxDOS"},
{0x66, "PTS-DOS"},
{0x99, "GenSoft Embedded DOS"},
{0xee, "DR-DOS"},
{0xef, "Novell DOS"},
{0xff, "Microsoft MS-DOS"},
{0, (char *)0}
};
 
static int getdosv_count = -1;
 
unsigned short
_get_dos_version(int true_version)
{
return 0x0500;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getftime.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <libc/dosio.h>
#include <errno.h>
#include <assert.h>
 
int getftime(int handle, struct ftime *ft)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/gettime.c
0,0 → 1,16
#include <dos.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void gettime( struct time *tp)
{
unsigned long tmp=__menuet__getsystemclock();
tp->ti_hour=tmp&0xff;
tp->ti_min=(tmp>>8)&0xff;
tp->ti_sec=(tmp>>16)&0xff;
tp->ti_hund=0;
BCD_TO_BIN(tp->ti_hour);
BCD_TO_BIN(tp->ti_min);
BCD_TO_BIN(tp->ti_sec);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/gettimeo.c
0,0 → 1,35
#include <time.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
struct tm tmblk;
struct timeval tv_tmp;
unsigned long xtmp;
if (!tv) tv = &tv_tmp;
tv->tv_usec=0;
xtmp=__menuet__getsystemclock();
tmblk.tm_sec = (xtmp>>16)&0xff;
tmblk.tm_min = (xtmp>>8)&0xff;
tmblk.tm_hour = xtmp&0xff;
BCD_TO_BIN(tmblk.tm_sec);
BCD_TO_BIN(tmblk.tm_min);
BCD_TO_BIN(tmblk.tm_hour);
__asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29));
tmblk.tm_mday = (xtmp>>16)&0xff;
tmblk.tm_mon = ((xtmp>>8)&0xff)-1;
tmblk.tm_year = ((xtmp&0xff)+2000)-1900;
tmblk.tm_wday = tmblk.tm_yday = tmblk.tm_gmtoff = 0;
tmblk.tm_zone = 0;
tmblk.tm_isdst = -1;
tv->tv_sec = mktime(&tmblk);
if(tz)
{
struct tm *tmloc = localtime(&(tv->tv_sec));
tz->tz_minuteswest = - tmloc->tm_gmtoff / 60;
tz->tz_dsttime = tmloc->tm_isdst;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osflavor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
const char *_os_flavor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osmajor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
unsigned short _osmajor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osminor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
unsigned short _osminor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/remotdrv.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file REMOTDRV.C
*
* Copyright (c) 1994, 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
#include <errno.h>
#include <dos.h>
#include <libc/dosio.h>
int _is_remote_drive(int c)
{
return 0;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/remothdl.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file REMOTHDL.C */
/*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <errno.h>
#include <libc/dosio.h>
 
int _is_remote_handle(int);
 
int
_is_remote_handle(int fhandle)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setcbrk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int setcbrk(int v)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setdate.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
void setdate( struct date *dateblk)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setftime.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <libc/dosio.h>
#include <errno.h>
#include <assert.h>
 
int setftime(int handle, struct ftime *ft)
{
return -EPERM;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/settime.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
void settime( struct time *tp)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/Makefile
0,0 → 1,3
THIS_SRCS = dosemu.c curdir.c emu_init.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/curdir.c
0,0 → 1,73
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
extern char __curdir_buf[1024];
 
char* __get_curdir(void) {return __curdir_buf;}
 
static void ___chdir(char* dest, const char* src)
{
// handle absolute paths
if (src[0]=='/')
{
strcpy(dest,src);
return;
}
// handle relative paths
char* ptr = dest + strlen(dest);
while (*src)
{
if (src[0] == '.' && src[1] == 0)
break;
if (src[0] == '.' && src[1] == '/')
{++src;++src;continue;}
if (src[0] == '.' && src[1] == '.' &&
(src[2] == 0 || src[2] == '/'))
{
while (ptr > dest && ptr[-1] != '/')
--ptr;
++src;++src;
if (*src == 0) break;
++src;
continue;
}
*ptr++ = '/';
if (*src == '/') ++src;
while (*src && *src!='/') *ptr++ = *src++;
}
*ptr = 0;
}
 
void __chdir(const char* path)
{
___chdir(__curdir_buf,path);
}
 
static char __libc_combine_buffer[1024];
char* __libc_combine_path(const char* c)
{
strcpy(__libc_combine_buffer,__curdir_buf);
___chdir(__libc_combine_buffer,c);
return __libc_combine_buffer;
}
 
 
#ifdef __TEST_IN_DOS__
 
int main(void)
{
init_dir_stack();
printf("|%s|\n",__get_curdir());
__chdir("jp/1/2/3");
printf("|%s|\n",__get_curdir());
__chdir("/jp/1/2/3");
printf("|%s|\n",__get_curdir());
__chdir("../4");
printf("|%s|\n",__get_curdir());
__chdir("./../..");
printf("|%s|\n",__get_curdir());
printf("Combined=|%s|\n",combine_path("./abc/def/../../../rd/2"));
return 0;
}
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/dosemu.c
0,0 → 1,238
#include "dosemuin.h"
#include <errno.h>
 
static char _io_filename[256];
 
static inline int sys_systree(struct systree_info * i,int * EBX)
{
int d0,d1;
__asm__ __volatile__("int $0x40"
:"=a"(d0),"=b"(d1)
:"0"(70),"1"((unsigned long)i)
:"memory");
if(EBX) *EBX=d1;
return d0;
}
 
int dosemu_file_exists(const char * filename)
{
struct systree_info finf;
struct bdfe_item attr;
finf.command = 5;
finf.file_offset_low = 0;
finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = (__u32)&attr;
finf._zero = 0;
finf.nameptr = filename;
if (sys_systree(&finf,NULL)!=0)
return -1;
return (int)attr.filesize_low;
}
 
int dosemu_createtrunc(const char * filename)
{
struct systree_info finf;
finf.command = 2;
finf.file_offset_low = finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = 0;
finf._zero = 0;
finf.nameptr = filename;
if (sys_systree(&finf,NULL))
return -1;
return 0;
}
 
_io_struct * dosemu_getiostruct(int handle)
{
if(handle<0 || handle>=_MAX_HANDLES) return NULL;
if(_io_handles[handle].oflags==-1) return NULL;
return _io_handles+handle;
}
 
int dosemu_allochandle(void)
{
int i;
for(i=0;i<_MAX_HANDLES;i++)
if(_io_handles[i].oflags==-1) return i;
return -1;
}
 
int dosemu_freehandle(int i)
{
if(i<0) return;
_io_handles[i].oflags=-1;
}
 
int dosemu_fileread(_io_struct * sh,char * buffer,int count)
{
struct systree_info finf;
int res,ebx;
finf.command = 0;
finf.file_offset_low = sh->pointer;
finf.file_offset_high = 0;
finf.size = count;
finf.data_pointer = (__u32)buffer;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,&ebx);
if (res != 0 && res != 6)
return -1;
sh->pointer += ebx;
return ebx;
}
 
int dosemu_filewrite(_io_struct * sh,char * buffer,int count)
{
struct systree_info finf;
int res,ebx;
finf.command = 3;
finf.file_offset_low = sh->pointer;
finf.file_offset_high = 0;
finf.size = count;
finf.data_pointer = (__u32)buffer;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,&ebx);
if (res != 0 && res != 6)
return -1;
sh->pointer += ebx;
if (sh->size < sh->pointer)
sh->size = sh->pointer;
return ebx;
}
 
int dosemu_iosize(int handle)
{
_io_struct * sh=dosemu_getiostruct(handle);
if(!sh) return -1;
return sh->size;
}
 
int dosemu_filesize(char * filename)
{
return dosemu_file_exists(filename);
}
 
static char fn_buf[256];
 
int dosemu_open(char * filename,int oflags)
{
int baseflags,h,fsize;
_fixpath(filename,_io_filename);
baseflags=oflags&(O_RDONLY|O_WRONLY|O_RDWR);
h=dosemu_allochandle();
fsize=dosemu_file_exists(_io_filename);
if(oflags & O_CREAT)
{
int creatflags=oflags & (O_EXCL|O_TRUNC);
if(creatflags & O_EXCL)
{
if(fsize>=0)
{
dosemu_freehandle(h);
return -1;
}
}
if(fsize<0 || (creatflags&O_TRUNC))
{
if(dosemu_createtrunc(_io_filename)<0)
{
dosemu_freehandle(h);
return -1;
}
fsize=0;
}
}
else if (fsize<0)
{
dosemu_freehandle(h);
return -1;
}
_io_handles[h].oflags=oflags;
_io_handles[h].size=fsize;
_io_handles[h].pointer=0;
switch (baseflags)
{
case O_RDONLY:_io_handles[h].flags=_IO_READ;break;
case O_WRONLY:_io_handles[h].flags=_IO_WRITE;break;
case O_RDWR:_io_handles[h].flags=_IO_READ|_IO_WRITE;break;
default:dosemu_freehandle(h);return -1;
}
strcpy(_io_handles[h].filename,_io_filename);
return h;
}
 
int dosemu_tell(int handle)
{
_io_struct * sh=dosemu_getiostruct(handle);
if(!sh) return -1;
return sh->pointer;
}
int dosemu_lseek(int handle,long offset,int origin)
{
int newpointer=0;
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
if(handle==0 || handle==1 || handle==2 || handle==3) return -1;
switch(origin)
{
case SEEK_SET: newpointer=offset;break;
case SEEK_CUR: newpointer=sh->pointer+offset;break;
case SEEK_END: newpointer=sh->size+offset;break;
}
if(newpointer<0)return -1;
sh->pointer=newpointer;
return newpointer;
}
 
int dosemu_read( int handle, void *buffer, unsigned int count )
{
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
if(!(sh->flags&_IO_READ)) return -1;
return dosemu_fileread(sh,buffer,count);
}
 
int dosemu_write( int handle, void *buffer, unsigned int count )
{
_io_struct *sh=dosemu_getiostruct(handle);
int k;
if(!sh)return -1;
if(!(sh->flags&_IO_WRITE)) return -1;
return dosemu_filewrite(sh,buffer,count);
}
 
int dosemu_close( int handle )
{
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
dosemu_freehandle(handle);
return 0;
}
 
void _dosemu_flush(int handle)
{}
 
int dosemu_truncate(int fd, off_t where)
{
struct systree_info finf;
int res;
_io_struct* sh = dosemu_getiostruct(fd);
if (!sh) return EBADF;
if (!(sh->flags & _IO_WRITE)) return EBADF;
finf.command = 4;
finf.file_offset_low = where;
finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = 0;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,NULL);
if (res == 8) return ENOSPC;
if (res) return EACCES;
sh->size = where;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/dosemuin.h
0,0 → 1,26
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<menuet/os.h>
 
#define _MAX_HANDLES 64
 
#define _IO_READ 1
#define _IO_WRITE 2
#define _IO_BUFDIRTY 4
 
#define IODEBUG(x...) /* */
 
typedef struct
{
int size;
int oflags;
int flags;
int pointer;
char filename[512];
} _io_struct;
 
extern _io_struct _io_handles[_MAX_HANDLES];
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/emu_init.c
0,0 → 1,32
#include "dosemuin.h"
 
_io_struct _io_handles[_MAX_HANDLES];
 
void dosemu_inithandles(void)
{
int i;
for(i=0;i<_MAX_HANDLES;i++)
_io_handles[i].oflags=-1;
_io_handles[0].oflags=1;
_io_handles[1].oflags=1;
_io_handles[2].oflags=1;
_io_handles[3].oflags=1;
}
 
/* If you want to do some actions for closing handles,
you must add it to this function
and uncomment call to atexit(dosemu_atexit) in crt1.c.
In this case I recommend to implement all referenced functions
here (and not in dosemu.c) to avoid linking dosemu.o
in programs which do not use I/O system. - diamond */
//void dosemu_atexit()
//{}
 
char __curdir_buf[1024];
extern char __menuet__app_path_area[];
 
void init_dir_stack(void)
{
strcpy(__curdir_buf,__menuet__app_path_area);
*strrchr(__curdir_buf,'/') = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/fslayer.c
0,0 → 1,287
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<menuet/os.h>
 
struct systree_blk
{
unsigned long cmd,pos,blks;
void * data,* work;
char name[256];
} __attribute__((packed));
 
typedef struct EMU_FILE
{
int handle;
unsigned long size;
unsigned long pos;
unsigned long mode;
unsigned long current_sector;
unsigned long size_sectors;
char * write_buf;
unsigned long write_bufsize;
char rd_buffer[512];
char name[256];
unsigned char dirty;
} EMU_FILE;
 
#define _MAX_HANDLES 64
 
static EMU_FILE * EMU_file_table[_MAX_HANDLES];
static char systree_work_area[16384+512];
static volatile struct systree_blk sblk;
static volatile int S_eax,S_ebx;
 
static inline int EMU_alloc_handle(void)
{
register int i;
for(i=0;i<_MAX_HANDLES;i++)
if(!EMU_file_table[i])
{
EMU_file_table[i]=(EMU_FILE *)malloc(sizeof(EMU_FILE));
if(!EMU_file_table[i]) return -ENOMEM;
return i;
}
return -EAGAIN;
}
 
static inline int EMU_systree_cmd(void)
{
__asm__ __volatile__("int $0x40"
:"=a"(S_eax),"=b"(S_ebx)
:"0"(58),"1"((void *)&sblk));
return S_eax;
}
 
static int EMU_loadsector(EMU_FILE * filp)
{
sblk.cmd=0;
sblk.pos=filp->current_sector;
sblk.blks=1;
sblk.data=filp->rd_buffer;
sblk.work=systree_work_area;
memcpy((void *)&sblk.name,(const void *)filp->name,strlen(filp->name)+1);
return EMU_systree_cmd();
}
 
static int EMU_fsync(EMU_FILE * filp)
{
if(filp->mode==O_RDONLY) return 0;
if(!filp->dirty) return 0;
filp->dirty=0;
sblk.cmd=1;
sblk.pos=0;
sblk.blks=filp->size;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)filp->name,strlen(filp->name)+1);
return EMU_systree_cmd();
}
 
static inline int EMU_realloc_buf(EMU_FILE * filp,unsigned long newsize)
{
char * n;
newsize=(newsize+511)&~511;
if(filp->write_bufsize==newsize) return 0;
n=(char *)realloc(filp->write_buf,newsize);
if(!n) return -ENOSPC;
filp->write_buf=n;
filp->write_bufsize=newsize;
filp->dirty=1;
return 0;
}
 
static int EMU_createtrunc(char * fname)
{
sblk.cmd=1;
sblk.pos=0;
sblk.blks=0;
sblk.data=sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
return EMU_systree_cmd();
}
 
static int EMU_getfsize(char * fname,unsigned long * sizep)
{
sblk.cmd=0;
sblk.pos=0;
sblk.blks=1;
sblk.data=systree_work_area+16384;
sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
if(EMU_systree_cmd()!=0) return -EINVAL;
if(sizep) *sizep=(unsigned long)S_ebx;
return 0;
}
 
static int EMU_open(char * fname,int mode)
{
EMU_FILE * filp;
register int hid;
unsigned long iomode;
hid=EMU_alloc_handle();
if(hid<0) return hid;
filp=EMU_file_table[hid];
filp->handle=hid;
iomode=mode&(O_RDONLY|O_WRONLY|O_RDWR);
memcpy((void *)filp->name,(const void *)fname,strlen(fname)+1);
strupr(filp->name);
filp->mode=iomode;
if(mode&O_CREAT)
{
int createflags=mode&(O_TRUNC|O_EXCL);
if(createflags&O_EXCL)
{
unsigned long psz=0;
if(EMU_getfsize(filp->name,&psz)==0)
{
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -EEXIST;
}
}
if(createflags&O_TRUNC)
{
EMU_createtrunc(filp->name);
}
}
if(iomode==O_RDONLY)
{
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=0;
if(EMU_loadsector(filp)<0) filp->current_sector=-1UL;
filp->mode=O_RDONLY;
filp->size_sectors=(filp->size+511)/512;
filp->write_bufsize=0;
filp->dirty=0;
return filp->handle;
}
if(iomode==O_WRONLY)
{
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
BAD_WRO:
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=-1UL;
filp->mode=O_WRONLY;
filp->size_sectors=0;
filp->write_bufsize=(filp->size+511)&~511;
filp->write_buf=(char *)malloc(filp->write_bufsize);
if(!filp->write_buf)
{
free(filp->write_buf);
goto BAD_WRO;
}
sblk.cmd=0;
sblk.pos=0;
sblk.blks=filp->write_bufsize/512;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
return filp->handle;
}
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
BAD_WRO1:
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=-1UL;
filp->mode=O_RDWR;
filp->size_sectors=0;
filp->write_bufsize=(filp->size+511)&~511;
filp->write_buf=(char *)malloc(filp->write_bufsize);
if(!filp->write_buf)
{
free(filp->write_buf);
goto BAD_WRO1;
}
sblk.cmd=0;
sblk.pos=0;
sblk.blks=filp->write_bufsize/512;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
return filp->handle;
}
 
static int EMU_close(EMU_FILE * filp)
{
int hid;
if(!filp) return -ENOENT;
if(EMU_file_table[hid=filp->handle]!=filp) return -EBADF;
if(filp->write_buf) free(filp->write_buf);
free(filp);
EMU_file_table[hid]=NULL;
return 0;
}
 
static int EMU_lseek(EMU_FILE * filp,unsigned long off,int whence)
{
unsigned long newpos;
switch(whence)
{
case SEEK_SET:
newpos=off;
break;
case SEEK_CUR:
newpos=filp->pos+off;
break;
case SEEK_END:
newpos=filp->size+off-1;
break;
}
if(newpos>=filp->size) return -1;
filp->pos=newpos;
return filp->pos;
}
 
static int EMU_read(EMU_FILE * filp,unsigned long size,void * buf)
{
int icount,curr_sector,curr_sector_ofs,n;
int nbufbytes,totalremaining;
if(filp->pos+count>filp->size)
count=filp->size-filp->pos;
if(filp->mode==O_RDWR)
{
memcpy(buffer,filp->write_buf+filp->pos,count);
filp->pos+=count;
return count;
}
icount=count;
while(count>0)
{
if(filp->pos>=filp->size) return icount=count;
curr_sector=sh->pointer>>9;
curr_sector_ofs=sh->pointer&511;
n=count;
if(sh->bufsector==-1 || curr_sector!=sh->bufsector)
{
if(dosemu_loadcurrsector(sh)==-1) return -1;
}
nbufbytes=512-curr_sector_ofs;
totalremaining=sh->size-sh->pointer;
if(nbufbytes>totalremaining) nbufbytes=totalremaining;
if(n>nbufbytes) n=nbufbytes;
memcpy(buffer,&sh->buf[curr_sector_ofs],n);
buffer+=n;
count-=n;
sh->pointer+=n;
}
return icount;
}
}
/programs/develop/libraries/menuetlibc/src/libc/dos/errno/Makefile
0,0 → 1,3
THIS_SRCS = doserr2e.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/errno/doserr2e.c
0,0 → 1,28
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <libc/dosio.h>
 
static unsigned char map[] = {
/* 00-07 */ 0, EINVAL, ENOENT, ENOENT, ENFILE, EACCES, EBADF, EFAULT,
/* 08-0f */ ENOMEM, EFAULT, EFAULT, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV,
/* 10-17 */ EBUSY, EXDEV, ENMFILE, EROFS, ENXIO, ENODEV, EINVAL, EINVAL,
/* 18-1f */ EINVAL, EIO, EIO, EIO, EIO, EIO, EIO, EPERM,
/* 20-27 */ EACCES, EACCES, ENXIO, EBADF, ENOLCK, EINVAL, EIO, ENOSPC,
/* 28-2f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 30-37 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
/* 38-3f */ EINVAL, EIO, EIO, EIO, EIO, EAGAIN, EINVAL, ENOSPC,
/* 40-47 */ EINVAL, EACCES, ENXIO, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
/* 48-4f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 50-57 */ EEXIST, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 57-5f */ EINVAL, ENOSYS, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 60-67 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV, EINVAL, EINVAL,
/* 68-6f */ ENODEV, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL
};
 
int
__doserr_to_errno(int doserr)
{
if (doserr >= 0 && doserr < sizeof(map)/sizeof(map[0]))
return map[doserr];
return EINVAL;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/Makefile
0,0 → 1,6
THIS_SRCS = _chmod.c _close.c _creat.c crlf2nl.c dosio.c doslock.c \
dosunloc.c fmode.c lock.c _open.c putpath.c _read.c setmode.c \
tell.c unlock.c _write.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_chmod.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
int _chmod(const char *filename, int func, ...)
{
int i;
i=open(filename,O_RDONLY);
if(i<0) return -1;
close(i);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_close.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
 
#include <menuet/os.h>
 
int _close(int handle)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_close, &rv, &handle))
{
__FSEXT_set_function(handle, 0);
return rv;
}
__FSEXT_set_function(handle, 0);
}
return dosemu_close(handle);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_creat.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <fcntl.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
 
int _creat(const char* filename, int attrib)
{
return _open(filename,attrib|O_CREAT);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_open.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
#define FSLAYER
#include <menuet/os.h>
 
int _open(const char* filename, int oflag)
{
int rv;
if (__FSEXT_call_open_handlers(__FSEXT_open, &rv, &filename))
return rv;
return dosemu_open(filename,oflag);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_read.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
#define FSLAYER
#include <menuet/os.h>
 
int _read(int handle, void* buffer, size_t count)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_read, &rv, &handle)) return rv;
}
return dosemu_read(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_write.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
#define FSLAYER
#include <menuet/os.h>
 
int _write(int handle, const void* buffer, size_t count)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_write, &rv, &handle)) return rv;
}
return dosemu_write(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/crlf2nl.c
0,0 → 1,20
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
 
ssize_t
crlf2nl(char *buf, ssize_t len)
{
char *bp = buf;
int i=0;
while (len--)
{
if (*bp != 13)
{
*buf++ = *bp;
i++;
}
bp++;
}
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/dosio.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
 
#include <libc/dosio.h>
#include <libc/bss.h>
 
static char init_file_handle_modes[20] = {
O_TEXT,
O_TEXT,
O_TEXT,
O_BINARY,
O_BINARY
};
 
static int dosio_bss_count = -1;
static size_t count=20; /* DOS default limit */
 
char *__file_handle_modes = init_file_handle_modes;
 
void
__file_handle_set(int fd, int mode)
{
/* Fill in the value */
__file_handle_modes[fd] = mode;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/doslock.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <assert.h>
 
int _dos_lock(int _fd, long _offset, long _length)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/dosunloc.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <assert.h>
 
int _dos_unlock(int _fd, long _offset, long _length)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/fmode.c
0,0 → 1,5
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <fcntl.h>
#include <io.h>
 
int _fmode = O_TEXT;
/programs/develop/libraries/menuetlibc/src/libc/dos/io/lock.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <errno.h>
#include <assert.h>
 
int
lock(int fd, long offset, long length)
{
unimpl();
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/putpath.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/dosio.h>
#include <libc/farptrgs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
 
void
_put_path(const char *path)
{
_put_path2(path, 0);
}
 
void
_put_path2(const char *path, int offset)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/setmode.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/exceptn.h>
#include <errno.h>
#include <fcntl.h>
#include <io.h>
 
#include <libc/dosio.h>
#include <assert.h>
 
void (*__setmode_stdio_hook)(int fd, int mode); /* BSS to zero */
 
int setmode(int handle, int mode)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/tell.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <errno.h>
#include <io.h>
#include <unistd.h>
 
off_t tell(int _file)
{
return dosemu_tell(_file);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/unlock.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <errno.h>
#include <assert.h>
 
int
unlock(int fd, long offset, long length)
{
unimpl();
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/process/Makefile
0,0 → 1,4
THIS_SRCS = chkv2prg.c dosexec.c spawnl.c spawnle.c spawnlp.c spawnlpe.c \
spawnv.c spawnvp.c spawnvpe.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/process/chkv2prg.c
0,0 → 1,137
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <sys/system.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
 
#define STUB_INFO_MAGIC "StubInfoMagic!!"
 
static _v2_prog_type type;
static int type_initialized = 0;
 
static
const _v2_prog_type *_check_v2_prog_internal (int pf);
 
const _v2_prog_type *_check_v2_prog(const char *program, int pf)
{
const _v2_prog_type *prog_type;
 
if (type_initialized && type.stubinfo)
free(type.stubinfo);
type_initialized = 1;
 
memset(&type, 0, sizeof(type));
 
if (program)
{
pf = open(program, O_RDONLY|O_BINARY);
if (pf < 0)
return &type;
}
 
prog_type = _check_v2_prog_internal(pf);
 
if (program)
close(pf);
 
if (prog_type)
type.valid = 1;
return &type;
}
 
static
const _v2_prog_type *_check_v2_prog_internal (int pf)
{
unsigned short header[5];
lseek(pf, 0, SEEK_SET);
if (read(pf, header, sizeof(header)) != sizeof(header))
return NULL;
if (header[0] == 0x010b || header[0] == 0x014c)
{
unsigned char firstbytes[1];
unsigned long coffhdr[40];
 
/* Seems to be an unstubbed COFF. See what the first opcode
is to determine if it's v1.x or v2 COFF (or an impostor).
 
FIXME: the code here assumes that any COFF that's not a V1
can only be V2. What about other compilers that use COFF? */
type.object_format = _V2_OBJECT_FORMAT_COFF;
if (lseek(pf, 2, 1) < 0
|| read(pf, coffhdr, sizeof(coffhdr)) != sizeof(coffhdr)
|| lseek(pf, coffhdr[10 + 5], 0) < 0
|| read(pf, firstbytes, 1) != 1) /* scnptr */
/* "Aha! An impostor!" (The Adventure game) */
type.object_format = _V2_OBJECT_FORMAT_UNKNOWN;
else if (firstbytes[0] != 0xa3) /* opcode of movl %eax, 0x12345678 (V1) */
type.version.v.major = 2;
else
type.version.v.major = 1;
type.exec_format = _V2_EXEC_FORMAT_COFF;
}
else if (header[0] == 0x5a4d) /* "MZ" */
{
char go32stub[9];
unsigned long coff_start = (unsigned long)header[2]*512L;
unsigned long exe_start;
type.exec_format = _V2_EXEC_FORMAT_EXE;
if (header[1])
coff_start += (long)header[1] - 512L;
exe_start = (unsigned long)header[4]*16L;
if (lseek(pf, exe_start, SEEK_SET) != exe_start)
return NULL;
if (read(pf, go32stub, 8) != 8)
return NULL;
go32stub[8] = 0;
if (strcmp(go32stub, "go32stub") == 0)
{
type.version.v.major = 2;
type.object_format = _V2_OBJECT_FORMAT_COFF;
type.exec_format = _V2_EXEC_FORMAT_STUBCOFF;
}
else
{
int stub_offset;
char magic[16];
int struct_length;
unsigned short coff_id;
type.version.v.major = 1;
if (lseek(pf, coff_start - 4, SEEK_SET) != coff_start-4)
return NULL;
if (read(pf, &stub_offset, 4) != 4)
return NULL;
if (read(pf, &coff_id, 2) != 2)
return NULL;
if (coff_id == 0x010b || coff_id == 0x014c)
{
type.object_format = _V2_OBJECT_FORMAT_COFF;
type.exec_format = _V2_EXEC_FORMAT_STUBCOFF;
}
if (lseek(pf, stub_offset, 0) != stub_offset)
return NULL;
if (read(pf, magic, 16) != 16)
return NULL;
if (memcmp(STUB_INFO_MAGIC, magic, 16) == 0)
{
if (read(pf, &struct_length, 4) != 4)
return NULL;
type.stubinfo = (_v1_stubinfo *)malloc(struct_length);
memcpy(type.stubinfo->magic, magic, 16);
type.stubinfo->struct_length = struct_length;
if (read(pf, type.stubinfo->go32, struct_length - 20)
!= struct_length - 20)
return NULL;
type.has_stubinfo = 1;
}
}
}
else if (header[0] == 0x2123) /* "#!" */
{
type.exec_format = _V2_EXEC_FORMAT_UNIXSCRIPT;
}
return &type;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/process/dosexec.c
0,0 → 1,102
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <menuet/os.h>
#include <sys/stat.h>
 
int _dos_exec(const char *program, const char *args, char * const envp[])
{
return -1;
}
 
 
int _is_unixy_shell (const char *shellpath)
{
return -1;
}
 
int _is_dos_shell (const char *shellpath)
{
return -1;
}
 
int __dosexec_command_exec(const char *program, char **argv, char **envp)
{
return -1;
}
 
char * __dosexec_find_on_path(const char *program, char *envp[], char *buf)
{
return NULL;
}
 
 
static void build_args(char * dstbuf,char * const argv[],int argc)
{
int i,j;
for(i=0;i<argc;i++)
{
j=strlen(argv[i]);
if(i==(argc-1))
sprintf(dstbuf,"%s",argv[i]);
else
sprintf(dstbuf,"%s ",argv[i]);
dstbuf+=j;
}
}
 
int __spawnve(int mode, const char *path, char *const argv[], char *const envp[])
{
char * buffer_for_args;
int ap,asz;
struct systree_info st_info;
int res;
fflush(stdout);
if(!path)
{
errno=EINVAL;
return -1;
}
if(strlen(path)>FILENAME_MAX-1)
{
errno = ENAMETOOLONG;
return -1;
}
for(ap=0,asz=10;argv[ap]!=NULL;ap++)
{
asz+=strlen(argv[ap])+1;
}
if(ap)
{
buffer_for_args=malloc(asz);
if(!buffer_for_args)
{
errno=ENOMEM;
return -1;
}
memset(buffer_for_args,0,asz);
build_args(buffer_for_args,argv,ap);
} else buffer_for_args=NULL;
st_info.command = 7;
st_info.file_offset_low = 0;
st_info.file_offset_high = (__u32)buffer_for_args;
st_info.size = 0;
st_info.data_pointer = 0;
st_info._zero = 0;
//_fix_path(path,st_info.name);
st_info.nameptr = path;
res = __kolibri__system_tree_access(&st_info);
if (res == -5)
errno = ENOENT;
else if (res == -31)
errno = ENOEXEC;
else if (res == -30 || res == -32)
errno = ENOMEM;
else if (res < 0)
errno = EINVAL;
free(buffer_for_args);
if(mode==0x1BADB002) exit(0);
return (res>0)?res:-1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnl.c
0,0 → 1,12
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
 
extern char **environ;
 
int spawnl(int mode, const char *path, const char *argv0, ...)
{
return spawnve(mode, path, unconst(&argv0,char * const *), environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnle.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
#include <libc/dosexec.h>
 
int spawnle(int mode, const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnve(mode, path, unconst(&argv0,char * const *),
unconst(ptr,char * const *));
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnlp.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
 
extern char **environ;
 
int spawnlp(int mode, const char *path, const char *argv0, ...)
{
return spawnvpe(mode, path, unconst(&argv0,char * const *),
(char * const *)environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnlpe.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
#include <libc/dosexec.h>
 
int spawnlpe(int mode, const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnvpe(mode, path, unconst(&argv0,char * const *),
unconst(ptr,char * const *));
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnv.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
 
extern char **environ;
 
int spawnv(int mode, const char *path, char *const argv[])
{
return spawnve(mode, path, (char * const *)argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnvp.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
 
extern char **environ;
 
int spawnvp(int mode, const char *path, char *const argv[])
{
return spawnvpe(mode, path, (char * const *)argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnvpe.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
#include <errno.h>
#include <libc/unconst.h>
#include <libc/dosexec.h>
 
int spawnvpe(int mode, const char *path, char *const argv[], char *const envp[])
{
char rpath[300];
union { char * const *cpcp; char **cpp; } u;
u.cpcp = envp;
 
if (!__dosexec_find_on_path(path, u.cpp, rpath))
{
errno = ENOENT;
return -1;
}
else
return spawnve(mode, rpath, argv, envp);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/Makefile
0,0 → 1,8
all:
make -C timeb
 
depend:
make -C timeb depend
 
clean:
make -C timeb clean
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/timeb/Makefile
0,0 → 1,3
THIS_SRCS = ftime.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/timeb/ftime.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <time.h>
#include <sys/timeb.h>
 
int
ftime(struct timeb *tp)
{
struct timeval tv;
struct timezone tz;
 
if (gettimeofday(&tv, &tz) < 0)
return -1;
 
tp->time = tv.tv_sec;
tp->millitm = tv.tv_usec / 1000;
tp->timezone = tz.tz_minuteswest;
tp->dstflag = tz.tz_dsttime;
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/emu_layer/Makefile
0,0 → 1,9
SUBDIRS =
 
all: process_subdirs
 
process_subdirs:
 
clean:
 
depend:
/programs/develop/libraries/menuetlibc/src/libc/fsext/Makefile
0,0 → 1,4
THIS_SRCS = fse_open.c fsext.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/fsext/fse_open.c
0,0 → 1,33
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <sys/fsext.h>
 
typedef struct FuncList {
struct FuncList *next;
__FSEXT_Function *function;
} FuncList;
 
static FuncList *func_list = 0;
 
int
__FSEXT_add_open_handler(__FSEXT_Function *_function)
{
FuncList *new_func_list = (FuncList *)malloc(sizeof(FuncList));
if (new_func_list == 0)
return 1;
new_func_list->next = func_list;
func_list = new_func_list;
func_list->function = _function;
return 0;
}
 
int
__FSEXT_call_open_handlers(__FSEXT_Fnumber _function_number,
int *rv, /*va_list*/void* _args)
{
FuncList *f;
for (f=func_list; f; f=f->next)
if (f->function(_function_number, rv, _args))
return 1;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/fsext/fsext.c
0,0 → 1,62
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/fsext.h>
#include <libc/bss.h>
#include <libc/dosio.h>
 
static int num_fds;
static __FSEXT_Function **func_list;
static int tmp_ext=0xF000;
 
static void
init(void)
{
static int init_count = -1;
if (init_count == __bss_count)
return;
init_count = __bss_count;
num_fds = 0;
func_list = 0;
}
 
int __FSEXT_alloc_fd(__FSEXT_Function *_function)
{
int fd;
init();
fd=tmp_ext++;
__FSEXT_set_function(fd, _function);
return fd;
}
 
int
__FSEXT_set_function(int _fd, __FSEXT_Function *_function)
{
init();
 
if (_fd < 0)
return 1;
 
if (num_fds <= _fd)
{
int old_fds = num_fds, i;
num_fds = (_fd+256) & ~255;
func_list = (__FSEXT_Function **)realloc(func_list, num_fds * sizeof(__FSEXT_Function *));
if (func_list == 0)
return 1;
for (i=old_fds; i<num_fds; i++)
func_list[i] = 0;
}
func_list[_fd] = _function;
return 0;
}
 
__FSEXT_Function *
__FSEXT_get_function(int _fd)
{
init();
if (_fd < 0 || _fd >= num_fds)
return 0;
return func_list[_fd];
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/Makefile
0,0 → 1,7
THIS_SRCS = backgr.c bar.c button.c clock.c date.c delay.c dga.c \
event.c exit.c file.c image.c ipc.c irq.c keyb.c line.c \
mpu401.c param.c pixel.c process.c screen.c sound.c systree.c \
text.c thread.c window.c pci.c alloca.s cofflib.c debug.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/menuetos/alloca.s
0,0 → 1,6
#include <libc/asm.h>
MK_C_SYM(_alloca)
sub %eax, %esp
mov (%esp,%eax),%eax
mov %eax, (%esp)
ret
/programs/develop/libraries/menuetlibc/src/libc/menuetos/backgr.c
0,0 → 1,26
#include<menuet/os.h>
 
void __menuet__set_background_size(__u32 xsz,__u32 ysz)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(1),"c"(xsz),"d"(ysz));
}
 
void __menuet__write_background_mem(__u32 pos,__u32 color)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(2),"c"(pos),"d"(color));
}
 
void __menuet__draw_background(void)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3));
}
 
void __menuet__set_background_draw_type(int type)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3),"c"(type));
}
 
void __menuet__background_blockmove(char * src_ptr,__u32 bgr_dst,__u32 count)
{
__asm__ __volatile__("int $0x40"::"a"(15),"b"(3),"c"(src_ptr),"d"(bgr_dst),"S"(count));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/bar.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__bar(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,__u32 color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(13),"b"(a),"c"(b),"d"(color));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/button.c
0,0 → 1,17
#include<menuet/os.h>
 
void __menuet__make_button(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
int id,__u32 color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(8),"b"(a),"c"(b),"d"(id),"S"(color));
}
 
int __menuet__get_button_id(void)
{
__u16 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(17));
if((__ret & 0xFF)==0) return (__ret>>8)&0xFF; else return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/clock.c
0,0 → 1,8
#include<menuet/os.h>
 
__u32 __menuet__getsystemclock(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(3));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/cofflib.c
0,0 → 1,14
#include <menuet/os.h>
#include <stdio.h>
 
IMP_TABLE __kolibri__cofflib_load(const char* name){
__asm__ __volatile__("int $0x40"::"a"(68L),"b"(19L),"c"((__u32)name));
}
 
__u32 __kolibri__cofflib_getproc(IMP_TABLE lib, const char* name){
if(!name || !name[0]) return NULL;
int i;
for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++);
if(lib[i].name) return (__u32)lib[i].pointer;
else return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/date.c
0,0 → 1,8
#include<menuet/os.h>
 
__u32 __menuet__get_date(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(29));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/debug.c
0,0 → 1,5
#include <menuet/os.h>
void __menuet__debug_out(const char* str){
while(*str)
__menuet__debug_out_byte(*str++);
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/delay.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__delay100(int m)
{
__asm__ __volatile__("int $0x40"::"a"(5),"b"(m));
}
 
void __menuet__idle(void)
{
__menuet__delay100(10);
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/dga.c
0,0 → 1,19
#include<menuet/os.h>
 
void __menuet__dga_get_caps(int * xres,int * yres,int * bpp,int * bpscan)
{
int p;
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(1));
if(xres) *xres=(p>>16)&0xFFFF;
if(yres) *yres=p & 0xFFFF;
if(bpp)
{
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(2));
*bpp=p;
}
if(bpscan)
{
__asm__ __volatile__("int $0x40":"=a"(p):"0"(61),"b"(3));
*bpscan=p;
}
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/event.c
0,0 → 1,20
#include<menuet/os.h>
 
int __menuet__wait_for_event(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(10));
return __ret;
}
 
int __menuet__check_for_event(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(11));
return __ret;
}
 
void __menuet__set_bitfield_for_wanted_events(__u16 ev)
{
__asm__ __volatile__("int $0x40"::"a"(40),"b"(ev));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/exit.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__sys_exit(void)
{
__asm__ __volatile__("int $0x40"::"a"(0xFFFFFFFF));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/file.c
0,0 → 1,44
#include<menuet/os.h>
#include<stdio.h>
#include<stdarg.h>
 
__u32 __menuet__open(char * name,char * data)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(6),"b"((__u32)name),"c"(0),"d"(0xFFFFFFFF),"S"((__u32)data));
return __ret;
}
 
void __menuet__save(char * name,char * data,__u32 count)
{
__asm__ __volatile__("int $0x40"::"a"(33),"b"((__u32)name),"c"((__u32)data),"d"(count),"S"(0));
}
 
void __menuet__exec_ramdisk(char * filename,char * args,...)
{
va_list argz;
char buffer[1024];
memset(buffer,0,1024);
if(args)
{
va_start(argz,args);
vsprintf(buffer,args,argz);
}
va_end(argz);
__asm__ __volatile__("int $0x40"::"a"(19),"b"(filename),"c"((args ? buffer : NULL)));
}
 
void __menuet__exec_hd(char * filename,char * args,...)
{
va_list argz;
char buffer[1024];
char work_area[0xFFFF];
memset(buffer,0,1024);
if(args)
{
va_start(argz,args);
vsprintf(buffer,args,argz);
}
va_end(argz);
__asm__ __volatile__("int $0x40"::"a"(19),"b"(filename),"c"(args ? buffer : NULL),"d"(work_area));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/image.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__putimage(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,char * image)
{
__u32 a,b;
a=(xsize<<16)|ysize;
b=(x1<<16)|y1;
__asm__ __volatile__("int $0x40"::"a"(7),"b"(image),"c"(a),"d"(b));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/ipc.c
0,0 → 1,11
#include<menuet/os.h>
 
void send_message(int pid,void * msg_ptr,int message_size)
{
__asm__ __volatile__("int $0x40"::"a"(60),"b"(2),"c"(pid),"d"(msg_ptr),"S"(message_size));
}
 
void define_receive_area(msgrcva_t * rcva_ptr,int size)
{
__asm__ __volatile__("int $0x40"::"a"(60),"b"(1),"c"(rcva_ptr),"d"(size));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/irq.c
0,0 → 1,62
#include<menuet/os.h>
 
__u32 __menuet__get_irq_owner(__u32 irq)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(41),"b"(irq));
return __ret;
}
 
int __menuet__get_data_read_by_irq(__u32 irq,__u32 * num_bytes_in_buf,__u8 * data)
{
__u32 a,b,c;
__asm__ __volatile__("int $0x40":"=a"(a),"=b"(b),"=c"(c):"0"(42),"1"(irq));
if(num_bytes_in_buf) *num_bytes_in_buf=a;
if(data) *data=b & 0xFF;
return c;
}
 
int __menuet__send_data_to_device(__u16 port,__u8 val)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(43),"b"(port),"c"(val));
return __ret;
}
 
void __menuet__program_irq(void * intr_table,__u32 irq_num)
{
__asm__ __volatile__("int $0x40"::"a"(44),"b"(intr_table),"c"(irq_num));
}
 
int __menuet__reserve_irq(int irqno)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(45),"b"(0),"c"(irqno));
return __ret;
}
 
int __menuet__free_irq(int irqno)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(45),"b"(1),"c"(irqno));
return __ret;
}
 
int __menuet__reserve_port_area(__u32 start,__u32 end)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(45),"b"(0),"c"(start),"d"(end));
return __ret;
}
 
int __menuet__free_port_area(__u32 start,__u32 end)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(45),"b"(1),"c"(start),"d"(end));
return __ret;
}
 
void __menuet__define_app_internal_intrs(void * intr_table)
{
__asm__("int $0x40"::"a"(49),"b"(0),"c"(intr_table));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/keyb.c
0,0 → 1,8
#include<menuet/os.h>
 
int __menuet__getkey(void)
{
__u16 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(2));
if(!(__ret & 0xFF)) return (__ret>>8)&0xFF; else return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/line.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__line(__u16 x1,__u16 y1,__u16 x2,__u16 y2,__u32 color)
{
__u32 b,c;
b=(x1<<16)|x1;
c=(y1<<16)|y2;
__asm__ __volatile__("int $0x40"::"a"(38),"b"(b),"c"(c),"d"(color));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/mpu401.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__reset_mpu401(void)
{
__asm__ __volatile__("int $0x40"::"a"(20),"b"(1));
}
 
void __menuet__write_mpu401(__u8 d)
{
__asm__ __volatile__("int $0x40"::"a"(20),"b"(2),"c"(d));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/param.c
0,0 → 1,7
#include<menuet/os.h>
 
#define APP_PARAM_SZ (1024)
#define APP_PATH_SZ (1024)
 
char __menuet__app_param_area[APP_PARAM_SZ];
char __menuet__app_path_area[APP_PATH_SZ];
/programs/develop/libraries/menuetlibc/src/libc/menuetos/pci.c
0,0 → 1,50
#include<menuet/os.h>
 
#define PCI_FN 62
 
void get_pci_version(__u8 * major,__u8 * minor)
{
int r;
__asm__ __volatile__("int $0x40":"=a"(r):"0"(PCI_FN),"b"(0));
*minor=r&0xFF;
*major=(r>>8)&0xFF;
}
 
void pci_get_last_bus(__u8 * last_bus)
{
__asm__ __volatile__("int $0x40":"=a"(*last_bus):"0"(PCI_FN),"b"(1));
}
 
void get_pci_access_mechanism(__u8 * mechanism)
{
__asm__ __volatile__("int $0x40":"=a"(*mechanism):"0"(PCI_FN),"b"(2));
}
 
#define read_config(x,c,bits) \
__u##bits pci_read_config_##x (__u8 bus,__u8 dev,__u8 fn,__u8 reg) \
{ \
__u##bits __ret; \
__u16 cx; \
__u16 bx; \
cx=(((fn&7)|(((dev)&~7)<<3))<<8)|reg; \
bx=(bus<<8)|(c); \
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(PCI_FN),"b"(bx),"c"(cx)); \
return __ret; \
}
 
#define write_config(x,c,bits) \
void pci_write_config_##x (__u8 bus,__u8 dev,__u8 fn,__u8 reg,__u##bits val) \
{ \
__u16 cx,bx; \
cx=(((fn&7)|(((dev)&~7)<<3))<<8)|reg; \
bx=(bus<<8)|(c); \
__asm__ __volatile__("int $0x40"::"a"(PCI_FN),"b"(bx),"c"(cx),"d"(val)); \
}
 
#define rw_config(x,c,bits) \
read_config(x,4+c,bits) \
write_config(x,7+c,bits)
rw_config(byte,0,8)
rw_config(word,1,16)
rw_config(dword,2,32)
/programs/develop/libraries/menuetlibc/src/libc/menuetos/pixel.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__putpixel(__u32 x,__u32 y,__u32 color)
{
__asm__ __volatile__("int $0x40"::"a"(1),"b"(x),"c"(y),"d"(color));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/process.c
0,0 → 1,8
#include<menuet/os.h>
 
int __menuet__get_process_table(struct process_table_entry * proctab,int pid)
{
int __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(9),"b"((__u32)proctab),"c"(pid));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/screen.c
0,0 → 1,9
#include<menuet/os.h>
 
void __menuet__get_screen_max(__u16 * x,__u16 * y)
{
__u32 v;
__asm__ __volatile__("int $0x40":"=a"(v):"0"(14));
if(x) *x=v>>16;
if(y) *y=v & 0xFFFF;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/sound.c
0,0 → 1,11
#include<menuet/os.h>
 
void __menuet__sound_load_block(char * blockptr)
{
__asm__ __volatile__("int $0x40"::"a"(55),"b"(0),"c"(blockptr));
}
 
void __menuet__sound_play_block(void)
{
__asm__ __volatile__("int $0x40"::"a"(55),"b"(1));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/systree.c
0,0 → 1,16
#include<menuet/os.h>
 
int __kolibri__system_tree_access(struct systree_info * info)
{
int __ret;
int d0;
__asm__ __volatile__("int $0x40":"=a"(__ret),"=&b"(d0):"0"(70),"1"((__u32)info));
return __ret;
}
int __kolibri__system_tree_access2(struct systree_info2 * info)
{
int __ret;
int d0;
__asm__ __volatile__("int $0x40":"=a"(__ret),"=&b"(d0):"0"(70),"1"((__u32)info));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/text.c
0,0 → 1,6
#include<menuet/os.h>
 
void __menuet__write_text(__u16 x,__u16 y,__u32 color,char * text,int len)
{
__asm__ __volatile__("int $0x40"::"a"(4),"b"((x<<16)|y),"c"(color),"d"((__u32)text),"S"(len));
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/thread.c
0,0 → 1,12
#include<menuet/os.h>
#include<stdio.h>
#include<stdlib.h>
 
void * __menuet__exec_thread(void (* func_ptr)(void),__u32 stack_size,int * retp)
{
void * __stk, * __ret;
__ret=__stk=malloc(stack_size);
__stk+=stack_size-1;
__asm__ __volatile__("int $0x40":"=a"(*retp):"0"(51L),"b"(1L),"c"((__u32)func_ptr),"d"((__u32)__stk));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/menuetos/window.c
0,0 → 1,16
#include<menuet/os.h>
 
void __menuet__define_window(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
__u32 body_color,__u32 grab_color,__u32 frame_color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(0),"b"(a),"c"(b),"d"(body_color),"S"(grab_color),
"D"(frame_color));
}
 
void __menuet__window_redraw(int status)
{
__asm__ __volatile__("int $0x40"::"a"(12),"b"(status));
}
/programs/develop/libraries/menuetlibc/src/libc/net/Makefile
0,0 → 1,3
THIS_SRCS = socket.c stack.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/net/socket.c
0,0 → 1,83
#include<menuet/net.h>
 
__u32 __menuet__open_UDP_socket(__u32 local_port,__u32 remote_port,__u32 remote_ip)
{
__u32 __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_open_UDP),
"c"(local_port),"d"(remote_port),"S"(remote_ip));
return __ret;
}
 
__u32 __menuet__open_TCP_socket(__u32 local_port,__u32 remote_port,__u32 remote_ip,int mode)
{
__u32 __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_open_TCP),
"c"(local_port),"d"(remote_port),"S"(remote_ip),"D"(mode));
return __ret;
}
 
int __menuet__close_UDP_socket(int socket)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_close_UDP),
"c"(socket));
return __ret;
}
 
int __menuet__close_TCP_socket(int socket)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_close_TCP),
"c"(socket));
return __ret;
}
 
int __menuet__poll_socket(int sock)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_poll),
"c"(sock));
return __ret;
}
 
int __menuet__read_socket(int sock,__u8 * return_data)
{
int data_remaining;
__u8 data_byte;
__asm__("int $0x40":"=a"(data_remaining),"=b"(data_byte):"a"(__NET_socket),
"b"(__NET_sock_poll),"c"(sock));
if(return_data) *return_data=data_byte;
return data_remaining;
}
 
int __menuet__get_TCP_socket_status(int sock)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_get_status),
"c"(sock));
return __ret;
}
 
int __menuet__write_UDP_socket(int sock,int count,void * buffer)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_write_UDP),
"c"(sock),"d"(count),"S"((__u32)buffer));
return __ret;
}
 
int __menuet__write_TCP_socket(int sock,int count,void * buffer)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_write_TCP),
"c"(sock),"d"(count),"S"((__u32)buffer));
return __ret;
}
 
int __menuet__check_net_port_availability(int port)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_socket),"b"(__NET_sock_check_port),
"c"(port));
return __ret;
}
/programs/develop/libraries/menuetlibc/src/libc/net/stack.c
0,0 → 1,26
#include<menuet/net.h>
 
int __menuet__get_stack_config_word(void)
{
int __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_stack),"b"(__NET_stack_rd_cfg_word));
return __ret;
}
 
__u32 __menuet__get_my_IP(void)
{
__u32 __ret;
__asm__("int $0x40":"=a"(__ret):"a"(__NET_stack),"b"(__NET_stack_get_ip));
return __ret;
}
 
void __menuet__set_stack_config_word(int cfg)
{
__asm__("int $0x40"::"a"(__NET_stack),"b"(__NET_stack_wr_cfg_word),
"c"(cfg));
}
 
void __menuet__set_my_IP(__u32 my_IP)
{
__asm__("int $0x40"::"a"(__NET_stack),"b"(__NET_stack_put_ip),"c"(my_IP));
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/Makefile
0,0 → 1,33
all:
make -C cpu
make -C endian
make -C farptr
make -C fpu
make -C hwint
make -C kb
make -C sound
make -C mem
make -C timer
 
clean:
make -C cpu clean
make -C endian clean
make -C farptr clean
make -C fpu clean
make -C hwint clean
make -C kb clean
make -C sound clean
make -C mem clean
make -C timer clean
 
depend:
make -C cpu depend
make -C endian depend
make -C farptr depend
make -C fpu depend
make -C hwint depend
make -C kb depend
make -C sound depend
make -C mem depend
make -C timer depend
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/cpu/Makefile
0,0 → 1,3
THIS_SRCS = my_cs.s my_ds.s my_ss.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/cpu/my_cs.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(_my_cs)
movw %cs,%ax
movzwl %ax,%eax
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/cpu/my_ds.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
 
#include<libc/asm.h>
MK_C_SYM(_my_ds)
movw %ds,%ax
movzwl %ax,%eax
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/cpu/my_ss.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
 
#include<libc/asm.h>
MK_C_SYM(_my_ss)
movw %ss,%ax
movzwl %ax,%eax
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/endian/Makefile
0,0 → 1,3
THIS_SRCS = htonl.s htons.s ntohl.s ntohs.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/endian/htonl.s
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
 
#include<libc/asm.h>
MK_C_SYM(htonl)
 
movl 4(%esp), %eax
xchgb %ah, %al
rorl $16, %eax
xchgb %ah, %al
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/endian/htons.s
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(htons)
 
movl 4(%esp), %eax
xchgb %ah, %al
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/endian/ntohl.s
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(ntohl)
 
movl 4(%esp), %eax
xchgb %ah, %al
rorl $16, %eax
xchgb %ah, %al
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/endian/ntohs.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(ntohs)
movl 4(%esp), %eax
xchgb %ah, %al
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/farptr/Makefile
0,0 → 1,3
THIS_SRCS = farptr.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/farptr/farptr.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#define extern
#define __inline__
#include <sys/farptr.h>
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/fpu/Makefile
0,0 → 1,3
THIS_SRCS = clear87.s cntrl87.s fpreset.s stat87.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/fpu/clear87.s
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
MK_C_SYM(clear87)
 
fstsw %ax
movzwl %ax, %eax
fclex
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/fpu/cntrl87.s
0,0 → 1,29
#include<libc/asm.h>
.text
 
MK_C_SYM(control87)
pushl %ebp
movl %esp,%ebp
 
pushl %eax
fstcw (%esp)
fwait
popl %eax
andl $0xffff, %eax
 
movl 12(%ebp) , %ecx
notl %ecx
andl %eax, %ecx
 
movl 12(%ebp) , %edx
andl 8(%ebp) , %edx
 
orl %ecx, %edx
pushl %edx
fldcw (%esp)
popl %edx
 
movl %ebp,%esp
popl %ebp
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/fpu/fpreset.s
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
.text
 
MK_C_SYM(fpreset)
 
fninit
ret
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/fpu/stat87.s
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
.text
 
#include<libc/asm.h>
MK_C_SYM(status87)
 
fstsw %ax
movzwl %ax, %eax
ret
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/hwint/Makefile
0,0 → 1,4
THIS_SRCS = disable.c enable.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/hwint/disable.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int disable(void)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/hwint/enable.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int enable(void)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/kb/Makefile
0,0 → 1,4
THIS_SRCS = getkey.c getxkey.c kbhit.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/kb/getkey.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>
#include <menuet/os.h>
 
int getkey(void)
{
if(!kbhit()) return -1;
return __menuet__getkey();
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/kb/getxkey.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>
 
int getxkey(void)
{
return getkey();
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/kb/kbhit.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>
#include <libc/farptrgs.h>
#include <menuet/os.h>
 
int kbhit(void)
{
int i;
i=__menuet__check_for_event();
if(i==2) return 1; else return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/Makefile
0,0 → 1,3
THIS_SRCS = djmdr.s djmd.s mdb.s mdl.s md.s mdw.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/djmd.s
0,0 → 1,40
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
# This routine moves %ecx bytes from %ds:%esi to %es:%edi. It clobbers
# %eax, %ecx, %esi, %edi, and eflags. The memory ranges must not overlap,
# unless %esi >= %edi.
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
.file "djmd.s"
.text
.balign 16,,7
 
MK_C_SYM(__dj_movedata)
cmpl $15,%ecx
jle small_move
jmp mod_4_check
# Transfer bytes until either %esi or %edi is aligned % 4
align_mod_4:
movsb
decl %ecx
mod_4_check:
testl $3,%esi
jz big_move
testl $3,%edi
jnz align_mod_4
 
big_move:
movb %cl,%al # We will store leftover count in %al
shrl $2,%ecx
andb $3,%al
rep
movsl
 
# %ecx known to be zero here, so insert the leftover count in %al
movb %al,%cl
small_move:
rep
movsb
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/djmdr.s
0,0 → 1,58
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* Modified by SET to copy in reverse order */
# This routine moves %ecx bytes from %ds:%esi to %es:%edi. It clobbers
# %eax, %ecx, %esi, %edi, and eflags.
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
.file "djmdr.s"
.text
.balign 16,,7
MK_C_SYM(__dj_movedata_rev)
std
# Add the counter to the index
addl %ecx,%edi
addl %ecx,%esi
decl %esi
decl %edi
 
cmpl $15,%ecx
jle small_move
jmp mod_4_check
# Transfer bytes until either %esi or %edi is aligned % 3
align_mod_4:
movsb
decl %ecx
mod_4_check:
movl %esi,%eax
andl $3,%eax
cmpl $3,%eax
jz big_move
movl %edi,%eax
andl $3,%eax
cmpl $3,%eax
jnz align_mod_4
 
big_move:
movb %cl,%al # We will store leftover count in %al
shrl $2,%ecx
andb $3,%al
# Now retrocess the index 3 positions
subl $3,%edi
subl $3,%esi
rep
movsl
 
# %ecx known to be zero here, so insert the leftover count in %al
movb %al,%cl
 
# advance the index by 3
addl $3,%edi
addl $3,%esi
 
small_move:
rep
movsb
ret
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/md.s
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#define USE_ESI
#define USE_EDI
#include <libc/asmdefs.h>
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(__movedata) /* src_sel, src_ofs, dest_sel, dest_ofs, len */
ENTER
 
pushw %ds
pushw %es
 
movw ARG1,%ds
movw ARG3,%es
 
movl ARG2,%esi
movl ARG4,%edi
movl ARG5,%ecx
 
call C_SYM(__dj_movedata)
 
popw %es
popw %ds
 
LEAVE
 
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/mdb.s
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#define USE_ESI
#define USE_EDI
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(_movedatab) /* src_sel, src_ofs, dest_sel, dest_ofs, len */
ENTER
 
pushw %ds
pushw %es
 
movl ARG1,%eax
movw %ax,%ds
movl ARG2,%esi
 
movl ARG3,%eax
movw %ax,%es
movl ARG4,%edi
 
movl ARG5,%ecx
cld
rep
movsb
 
popw %es
popw %ds
 
LEAVE
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/mdl.s
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#define USE_ESI
#define USE_EDI
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(_movedatal) /* src_sel, src_ofs, dest_sel, dest_ofs, len */
ENTER
 
pushw %ds
pushw %es
 
movl ARG1,%eax
movw %ax,%ds
movl ARG2,%esi
 
movl ARG3,%eax
movw %ax,%es
movl ARG4,%edi
 
movl ARG5,%ecx
cld
rep
movsl
 
popw %es
popw %ds
 
LEAVE
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/mem/mdw.s
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#define USE_ESI
#define USE_EDI
#include <libc/asmdefs.h>
#include<libc/asm.h>
 
MK_C_SYM(_movedataw) /* src_sel, src_ofs, dest_sel, dest_ofs, len */
ENTER
 
pushw %ds
pushw %es
 
movl ARG1,%eax
movw %ax,%ds
movl ARG2,%esi
 
movl ARG3,%eax
movw %ax,%es
movl ARG4,%edi
 
movl ARG5,%ecx
cld
rep
movsw
 
popw %es
popw %ds
 
LEAVE
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/sound/Makefile
0,0 → 1,3
THIS_SRCS = sound.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/sound/sound.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>
#include <assert.h>
 
void sound(int freq)
{
int scale;
if (freq == 0)
{
outportb(0x61, inportb(0x61) & ~3);
return;
}
scale = 1193046 / freq;
outportb(0x43, 0xb6);
outportb(0x42, scale & 0xff);
outportb(0x42, scale >> 8);
outportb(0x61, inportb(0x61) | 3);
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/timer/Makefile
0,0 → 1,3
THIS_SRCS = clock.c uclock.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/timer/clock.c
0,0 → 1,10
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <libc/farptrgs.h>
#include <libc/bss.h>
 
clock_t clock(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/timer/uclock.c
0,0 → 1,13
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <errno.h>
#include <pc.h>
#include <libc/farptrgs.h>
#include <libc/bss.h>
 
uclock_t uclock(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/Makefile
0,0 → 1,47
all:
make -C dirent
make -C fcntl
make -C fnmatch
make -C glob
make -C grp
make -C pwd
make -C regex
make -C setjmp
make -C signal
make -C stdio
make -C sys
make -C unistd
make -C utime
make -C utsname
 
clean:
make -C dirent clean
make -C fcntl clean
make -C fnmatch clean
make -C glob clean
make -C grp clean
make -C pwd clean
make -C regex clean
make -C setjmp clean
make -C signal clean
make -C stdio clean
make -C sys clean
make -C unistd clean
make -C utime clean
make -C utsname clean
 
depend:
make -C dirent depend
make -C fcntl depend
make -C fnmatch depend
make -C glob depend
make -C grp depend
make -C pwd depend
make -C regex depend
make -C setjmp depend
make -C signal depend
make -C stdio depend
make -C sys depend
make -C unistd depend
make -C utime depend
make -C utsname depend
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/Makefile
0,0 → 1,4
THIS_SRCS = closedir.c odflags.c opendir.c readdir.c rewinddi.c seekdir.c \
telldir.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/closedir.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <dirent.h>
#include "dirstruc.h"
 
int
closedir(DIR *dir)
{
free(dir);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/dirstruc.h
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
 
struct __dj_DIR {
int num_read;
char *name;
int flags;
struct ffblk ff;
struct dirent de;
};
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/odflags.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <dirent.h>
 
int __opendir_flags = 0;
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/opendir.c
0,0 → 1,43
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include "dirstruc.h"
 
DIR *
opendir(const char *name)
{
int res;
DIR* dir = (DIR*)malloc(sizeof(DIR));
if (!dir)
return NULL;
_fixpath(name, dir->fileinfo.name);
struct bdfe_item attr;
dir->fileinfo.command = 5;
dir->fileinfo.file_offset_low = 0;
dir->fileinfo.file_offset_high = 0;
dir->fileinfo.size = 0;
dir->fileinfo.data_pointer = (__u32)&attr;
res = __kolibri__system_tree_access2(&dir->fileinfo);
if (res!=0 && res!=2)
{
free(dir);
return NULL;
}
if (res==0 && (attr.attr & 0x10)==0)
{
free(dir);
return NULL;
}
dir->fileinfo.command = 1;
dir->fileinfo.size = 1;
dir->fileinfo.data_pointer = (__u32)dir->bdfeheader;
dir->fileinfo.file_offset_low = (__u32)-1;
return dir;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/readdir.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <ctype.h>
#include "dirstruc.h"
 
struct dirent *
readdir(DIR *dir)
{
dir->fileinfo.file_offset_low++;
if (__kolibri__system_tree_access2(&dir->fileinfo))
return NULL;
dir->entry.d_namlen = strlen(dir->bdfename);
strcpy(dir->entry.d_name, dir->bdfename);
return &dir->entry;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/rewinddi.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <dirent.h>
#include "dirstruc.h"
 
void
rewinddir(DIR *dir)
{
// dir->num_read = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/seekdir.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <dirent.h>
 
void
seekdir(DIR *dir, long loc)
{
/* int i;
rewinddir(dir);
for (i=0; i<loc; i++)
readdir(dir);*/
}
/programs/develop/libraries/menuetlibc/src/libc/posix/dirent/telldir.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <dirent.h>
#include "dirstruc.h"
 
long
telldir(DIR *dir)
{
// return dir->num_read;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/fcntl/Makefile
0,0 → 1,3
THIS_SRCS = creat.c fcntl.c open.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/fcntl/creat.c
0,0 → 1,7
#include <fcntl.h>
 
int
creat(const char *path, mode_t mode)
{
return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/fcntl/fcntl.c
0,0 → 1,22
#include <unistd.h>
#include <fcntl.h>
 
int
fcntl(int fd, int cmd, ...)
{
switch (cmd)
{
case F_DUPFD:
return dup(fd);
case F_GETFD:
case F_SETFD:
case F_GETFL:
case F_SETFL:
return 0;
case F_GETLK:
case F_SETLK:
case F_SETLKW:
return -1;
}
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/fcntl/open.c
0,0 → 1,31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <io.h>
 
#include <libc/dosio.h>
 
int open(const char* filename, int oflag, ...)
{
/* int fd, dmode, bintext;
bintext = oflag & (O_TEXT | O_BINARY);
if (!bintext) bintext = _fmode & (O_TEXT | O_BINARY);
if (!bintext) bintext = O_BINARY;
oflag &= ~(O_TEXT | O_BINARY);
dmode = (*((&oflag)+1) & S_IWUSR) ? 1 : 0;
fd = _open(filename, oflag & 0xff);
if (fd == -1 && oflag & O_CREAT)
fd = _creat(filename, dmode);
if (fd == -1) return fd;
if (oflag & O_TRUNC)
if (_write(fd, 0, 0) < 0)
return -1;
if(oflag & O_APPEND)
lseek(fd, 0, SEEK_END);
return fd;*/
return dosemu_open(filename, oflag);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/fnmatch/Makefile
0,0 → 1,3
THIS_SRCS = fnmatch.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/fnmatch/fnmatch.c
0,0 → 1,143
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <fnmatch.h>
 
#define EOS '\0'
 
static const char *rangematch(const char *pattern, char test, int nocase);
 
#define isslash(c) ((c) == '\\' || (c) == '/')
 
static const char *
find_slash(const char *s)
{
while (*s)
{
if (isslash(*s))
return s;
s++;
}
return 0;
}
 
static const char *
rangematch(const char *pattern, char test, int nocase)
{
char c, c2;
int negate, ok;
 
if ((negate = (*pattern == '!')))
++pattern;
 
for (ok = 0; (c = *pattern++) != ']';)
{
if (c == 0)
return 0; /* illegal pattern */
if (*pattern == '-' && (c2 = pattern[1]) != 0 && c2 != ']')
{
if (c <= test && test <= c2)
ok = 1;
if (nocase && toupper(c) <= toupper(test) && toupper(test) <= toupper(c2))
ok = 1;
pattern += 2;
}
else if (c == test)
ok = 1;
else if (nocase && (toupper(c) == toupper(test)))
ok = 1;
}
return ok == negate ? NULL : pattern;
}
 
int
fnmatch(const char *pattern, const char *string, int flags)
{
char c;
char test;
 
for (;;)
switch ((c = *pattern++))
{
case 0:
return *string == 0 ? 0 : FNM_NOMATCH;
case '?':
if ((test = *string++) == 0 ||
(isslash(test) && (flags & FNM_PATHNAME)))
return(FNM_NOMATCH);
break;
case '*':
c = *pattern;
/* collapse multiple stars */
while (c == '*')
c = *++pattern;
 
/* optimize for pattern with * at end or before / */
if (c == 0)
if (flags & FNM_PATHNAME)
return find_slash(string) ? FNM_NOMATCH : 0;
else
return 0;
else if (isslash(c) && flags & FNM_PATHNAME)
{
if ((string = find_slash(string)) == NULL)
return FNM_NOMATCH;
break;
}
 
/* general case, use recursion */
while ((test = *string) != 0)
{
if (fnmatch(pattern, string, flags) == 0)
return(0);
if (isslash(test) && flags & FNM_PATHNAME)
break;
++string;
}
return FNM_NOMATCH;
case '[':
if ((test = *string++) == 0 ||
(isslash(test) && flags & FNM_PATHNAME))
return FNM_NOMATCH;
if ((pattern = rangematch(pattern, test, flags & FNM_NOCASE)) == NULL)
return FNM_NOMATCH;
break;
case '\\':
if (!(flags & FNM_NOESCAPE) && pattern[1] && strchr("*?[\\", pattern[1]))
{
if ((c = *pattern++) == 0)
{
c = '\\';
--pattern;
}
if (c != *string++)
return FNM_NOMATCH;
break;
}
/* FALLTHROUGH */
default:
if (isslash(c) && isslash(*string))
{
string++;
break;
}
if (flags & FNM_NOCASE)
{
if (toupper(c) != toupper(*string++))
return FNM_NOMATCH;
}
else
{
if (c != *string++)
return FNM_NOMATCH;
}
break;
}
}
/programs/develop/libraries/menuetlibc/src/libc/posix/glob/Makefile
0,0 → 1,3
THIS_SRCS = glob.c globfree.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/glob/glob.c
0,0 → 1,341
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <fnmatch.h>
#include <dir.h>
#include <glob.h>
 
typedef struct Save {
struct Save *prev;
char *entry;
} Save;
 
static Save *save_list;
static int save_count;
static int flags;
static int (*errfunc)(const char *epath, int eerno);
static char *pathbuf;
static int wildcard_nesting;
static char use_lower_case;
static char slash;
 
static int glob2(const char *pattern, char *epathbuf);
static int add(const char *path);
static int str_compare(const void *va, const void *vb);
 
static int
add(const char *path)
{
Save *sp;
for (sp=save_list; sp; sp=sp->prev)
if (strcmp(sp->entry, path) == 0)
return 0;
sp = (Save *)malloc(sizeof(Save));
if (sp == 0)
return 1;
sp->entry = (char *)malloc(strlen(path)+1);
if (sp->entry == 0)
{
free(sp);
return 1;
}
/* printf("add: `%s'\n", path); */
strcpy(sp->entry, path);
sp->prev = save_list;
save_list = sp;
save_count++;
return 0;
}
 
static int
glob_dirs(const char *rest, char *epathbuf, int first) /* rest is ptr to null or ptr after slash, bp after slash */
{
struct ffblk ff;
int done;
 
/* printf("glob_dirs[%d]: rest=`%s' %c epathbuf=`%s' %c pathbuf=`%s'\n",
wildcard_nesting, rest, *rest, epathbuf, *epathbuf, pathbuf); */
 
if (first)
{
if (*rest)
{
glob2(rest, epathbuf);
}
else
{
char sl = epathbuf[-1];
*epathbuf = 0;
/* printf("end, checking `%s'\n", pathbuf); */
if (epathbuf == pathbuf)
{
epathbuf[0] = '.';
epathbuf[1] = 0;
}
else
epathbuf[-1] = 0;
if (__file_exists(pathbuf))
add(pathbuf);
epathbuf[-1] = sl;
}
}
 
strcpy(epathbuf, "*.*");
done = findfirst(pathbuf, &ff, FA_DIREC);
while (!done)
{
if ((ff.ff_name[0] != '.') && (ff.ff_attrib & FA_DIREC))
{
int i;
char *tp;
if (use_lower_case)
for (i=0; ff.ff_name[i] && i<13; i++)
ff.ff_name[i] = tolower(ff.ff_name[i]);
 
/* printf("found `%s' `%s'\n", pathbuf, ff.ff_name); */
 
strcpy(epathbuf, ff.ff_name);
tp = epathbuf + strlen(epathbuf);
*tp++ = slash;
*tp = 0;
 
wildcard_nesting++;
if (*rest)
{
glob2(rest, tp);
}
else
{
if (!(flags & GLOB_MARK))
tp[-1] = 0;
add(pathbuf);
tp[-1] = slash;
}
*tp = 0;
glob_dirs(rest, tp, 0);
wildcard_nesting--;
}
done = findnext(&ff);
}
return 0;
}
 
static int
glob2(const char *pattern, char *epathbuf) /* both point *after* the slash */
{
const char *pp, *pslash;
char *bp;
struct ffblk ff;
char *my_pattern;
int done;
 
if (strcmp(pattern, "...") == 0)
{
return glob_dirs(pattern+3, epathbuf, 1);
}
if (strncmp(pattern, "...", 3) == 0 && (pattern[3] == '\\' || pattern[3] == '/'))
{
slash = pattern[3];
return glob_dirs(pattern+4, epathbuf, 1);
}
 
*epathbuf = 0;
/* copy as many non-wildcard segments as possible */
pp = pattern;
bp = epathbuf;
pslash = bp-1;
while (1)
{
if (*pp == ':' || *pp == '\\' || *pp == '/')
{
pslash = bp;
if (strcmp(pp+1, "...") == 0
|| (strncmp(pp+1, "...", 3) == 0 && (pp[4] == '/' || pp[4] == '\\')))
{
if (*pp != ':')
slash = *pp;
/* printf("glob2: dots at `%s'\n", pp); */
*bp++ = *pp++;
break;
}
}
 
else if (*pp == '*' || *pp == '?' || *pp == '[')
{
if (pslash > pathbuf)
strncpy(epathbuf, pattern, pslash - pathbuf);
pp = pattern + (pslash - epathbuf) + 1;
bp = epathbuf + (pslash - epathbuf) + 1;
break;
}
 
else if (*pp == 0)
{
break;
}
 
else if (islower(*pp))
use_lower_case = 1;
else if (isupper(*pp))
use_lower_case = 0;
 
*bp++ = *pp++;
}
*bp = 0;
 
if (*pp == 0) /* end of pattern? */
{
if (wildcard_nesting==0 || __file_exists(pathbuf))
add(pathbuf);
return 0;
}
/* printf("glob2: initial segment is `%s'\n", pathbuf); */
if (wildcard_nesting)
{
char s = bp[-1];
bp[-1] = 0;
if (!__file_exists(pathbuf))
return 0;
bp[-1] = s;
}
 
for (pslash = pp; *pslash && *pslash != '\\' && *pslash != '/'; pslash++)
{
if (islower(*pslash))
use_lower_case = 1;
else if (isupper(*pslash))
use_lower_case = 0;
}
if (*pslash)
slash = *pslash;
my_pattern = (char *)alloca(pslash - pp + 1);
if (my_pattern == 0)
return 0;
strncpy(my_pattern, pp, pslash - pp);
my_pattern[pslash-pp] = 0;
 
/* printf("glob2: `%s' `%s'\n", pathbuf, my_pattern); */
 
if (strcmp(my_pattern, "...") == 0)
{
glob_dirs(*pslash ? pslash+1 : pslash, bp, 1);
return 0;
}
 
strcpy(bp, "*.*");
 
done = findfirst(pathbuf, &ff, FA_RDONLY|FA_SYSTEM|FA_DIREC|FA_ARCH);
while (!done)
{
int i;
if (ff.ff_name[0] != '.')
{
if (use_lower_case)
for (i=0; ff.ff_name[i] && i<13; i++)
ff.ff_name[i] = tolower(ff.ff_name[i]);
if (fnmatch(my_pattern, ff.ff_name, FNM_NOESCAPE|FNM_PATHNAME|FNM_NOCASE) == 0)
{
strcpy(bp, ff.ff_name);
if (*pslash)
{
char *tp = bp + strlen(bp);
*tp++ = *pslash;
*tp = 0;
/* printf("nest: `%s' `%s'\n", pslash+1, pathbuf); */
wildcard_nesting++;
glob2(pslash+1, tp);
wildcard_nesting--;
}
else
{
/* printf("ffmatch: `%s' matching `%s', add `%s'\n",
ff.ff_name, my_pattern, pathbuf); */
if (ff.ff_attrib & FA_DIREC & (flags & GLOB_MARK))
{
bp[strlen(bp)] = slash;
bp[strlen(bp)+1] = 0;
}
add(pathbuf);
}
}
}
done = findnext(&ff);
}
 
return 0;
}
 
static int
str_compare(const void *va, const void *vb)
{
return strcmp(*(char * const *)va, *(char * const *)vb);
}
 
int
glob(const char *_pattern, int _flags, int (*_errfunc)(const char *_epath, int _eerrno), glob_t *_pglob)
{
char path_buffer[2000];
int l_ofs, l_ptr;
 
pathbuf = path_buffer+1;
flags = _flags;
errfunc = _errfunc;
wildcard_nesting = 0;
save_count = 0;
save_list = 0;
use_lower_case = 1;
slash = '/';
 
glob2(_pattern, pathbuf);
 
if (save_count == 0)
{
if (flags & GLOB_NOCHECK)
add(_pattern);
else
return GLOB_NOMATCH;
}
 
if (flags & GLOB_DOOFFS)
l_ofs = _pglob->gl_offs;
else
l_ofs = 0;
 
if (flags & GLOB_APPEND)
{
_pglob->gl_pathv = (char **)realloc(_pglob->gl_pathv, (l_ofs + _pglob->gl_pathc + save_count + 1) * sizeof(char *));
if (_pglob->gl_pathv == 0)
return GLOB_ERR;
l_ptr = l_ofs + _pglob->gl_pathc;
}
else
{
_pglob->gl_pathv = (char* *)malloc((l_ofs + save_count + 1) * sizeof(char *));
if (_pglob->gl_pathv == 0)
return GLOB_ERR;
l_ptr = l_ofs;
if (l_ofs)
memset(_pglob->gl_pathv, 0, l_ofs * sizeof(char *));
}
 
l_ptr += save_count;
_pglob->gl_pathv[l_ptr] = 0;
while (save_list)
{
Save *s = save_list;
l_ptr --;
_pglob->gl_pathv[l_ptr] = save_list->entry;
save_list = save_list->prev;
free(s);
}
if (!(flags & GLOB_NOSORT))
qsort(_pglob->gl_pathv + l_ptr, save_count, sizeof(char *), str_compare);
 
_pglob->gl_pathc = l_ptr + save_count;
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/glob/globfree.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <glob.h>
 
void globfree(glob_t *_pglob)
{
int i;
if (!_pglob->gl_pathv)
return;
for (i=0; i<_pglob->gl_pathc; i++)
if (_pglob->gl_pathv[i])
free(_pglob->gl_pathv[i]);
free(_pglob->gl_pathv);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/grp/Makefile
0,0 → 1,3
THIS_SRCS = getgrent.c getgrgid.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/grp/getgrent.c
0,0 → 1,35
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <grp.h>
#include <unistd.h>
 
static int tag = 0;
 
struct group *
getgrent(void)
{
if (tag == 0)
{
tag = 1;
return getgrgid(getgid());
}
return 0;
}
 
/* ARGSUSED */
struct group *
fgetgrent(void *f)
{
return getgrent();
}
 
void
setgrent(void)
{
tag = 0;
}
 
void
endgrent(void)
{
tag = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/grp/getgrgid.c
0,0 → 1,68
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
 
static int init = 0;
static char *grp = 0;
static struct group g;
static char *mem[2];
static char def_name[] = "user";
static char def_grp[] = "dos";
 
static void
grp_init(void)
{
char *p;
p = getenv("USER");
if (p == 0)
p = getenv("LOGNAME");
if (p)
{
mem[0] = (char *)malloc(strlen(p) + 1);
if (mem[0] == 0)
mem[0] = def_name;
else
strcpy(mem[0], p);
}
else
mem[0] = def_name;
mem[1] = 0;
 
p = getenv("GROUP");
if (p)
{
grp = (char *)malloc(strlen(p)+1);
if (grp == 0)
grp = def_grp;
else
strcpy(grp, p);
}
else
grp = def_grp;
 
g.gr_gid = getgid();
g.gr_mem = mem;
g.gr_name = grp;
}
 
struct group *
getgrgid(gid_t gid)
{
if (gid != getgid())
return 0;
if (init == 0)
grp_init();
return &g;
}
 
struct group *
getgrnam(const char *name)
{
if (init == 0)
grp_init();
if (strcmp(name, grp))
return 0;
return &g;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/pwd/Makefile
0,0 → 1,3
THIS_SRCS = getpwnam.c getpwuid.c pwent.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/pwd/getpwnam.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pwd.h>
#include <unistd.h>
#include <stdlib.h>
 
static char slash[] = "/";
static char shell[] = "sh";
 
struct passwd *
getpwnam(const char *name)
{
static struct passwd rv;
rv.pw_name = getlogin();
if (strcmp(rv.pw_name, name) != 0)
return 0;
rv.pw_uid = getuid();
rv.pw_gid = getgid();
rv.pw_dir = getenv("HOME");
if (rv.pw_dir == 0)
rv.pw_dir = slash;
rv.pw_shell = getenv("SHELL");
if (rv.pw_shell == 0)
rv.pw_shell = getenv("COMSPEC");
if (rv.pw_shell == 0)
rv.pw_shell = shell;
return &rv;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/pwd/getpwuid.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pwd.h>
#include <unistd.h>
#include <stdlib.h>
 
static char slash[] = "/";
static char shell[] = "sh";
 
struct passwd *
getpwuid(uid_t uid)
{
static struct passwd rv;
rv.pw_uid = getuid();
if (uid != rv.pw_uid)
return 0;
rv.pw_name = getlogin();
rv.pw_gid = getgid();
rv.pw_dir = getenv("HOME");
if (rv.pw_dir == 0)
rv.pw_dir = slash;
rv.pw_shell = getenv("SHELL");
if (rv.pw_shell == 0)
rv.pw_shell = getenv("COMSPEC");
if (rv.pw_shell == 0)
rv.pw_shell = shell;
return &rv;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/pwd/pwent.c
0,0 → 1,28
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pwd.h>
#include <unistd.h>
 
static int count=0;
 
void
setpwent(void)
{
count=0;
}
 
struct passwd *
getpwent(void)
{
if (count == 0)
{
count++;
return getpwuid(getuid());
}
return 0;
}
 
void
endpwent(void)
{
count=0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/Makefile
0,0 → 1,4
THIS_SRCS = debug.c regcomp.c regerror.c regexec.c regfree.c \
split.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/cclass.h
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* character-class table */
static struct cclass {
char *name;
char *chars;
char *multis;
} cclasses[] = {
"alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789", "",
"alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"",
"blank", " \t", "",
"cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
\25\26\27\30\31\32\33\34\35\36\37\177", "",
"digit", "0123456789", "",
"graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
"",
"lower", "abcdefghijklmnopqrstuvwxyz",
"",
"print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
"",
"punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
"",
"space", "\t\n\v\f\r ", "",
"upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"",
"xdigit", "0123456789ABCDEFabcdef",
"",
NULL, 0, ""
};
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/cname.h
0,0 → 1,103
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* character-name table */
static struct cname {
char *name;
char code;
} cnames[] = {
"NUL", '\0',
"SOH", '\001',
"STX", '\002',
"ETX", '\003',
"EOT", '\004',
"ENQ", '\005',
"ACK", '\006',
"BEL", '\007',
"alert", '\007',
"BS", '\010',
"backspace", '\b',
"HT", '\011',
"tab", '\t',
"LF", '\012',
"newline", '\n',
"VT", '\013',
"vertical-tab", '\v',
"FF", '\014',
"form-feed", '\f',
"CR", '\015',
"carriage-return", '\r',
"SO", '\016',
"SI", '\017',
"DLE", '\020',
"DC1", '\021',
"DC2", '\022',
"DC3", '\023',
"DC4", '\024',
"NAK", '\025',
"SYN", '\026',
"ETB", '\027',
"CAN", '\030',
"EM", '\031',
"SUB", '\032',
"ESC", '\033',
"IS4", '\034',
"FS", '\034',
"IS3", '\035',
"GS", '\035',
"IS2", '\036',
"RS", '\036',
"IS1", '\037',
"US", '\037',
"space", ' ',
"exclamation-mark", '!',
"quotation-mark", '"',
"number-sign", '#',
"dollar-sign", '$',
"percent-sign", '%',
"ampersand", '&',
"apostrophe", '\'',
"left-parenthesis", '(',
"right-parenthesis", ')',
"asterisk", '*',
"plus-sign", '+',
"comma", ',',
"hyphen", '-',
"hyphen-minus", '-',
"period", '.',
"full-stop", '.',
"slash", '/',
"solidus", '/',
"zero", '0',
"one", '1',
"two", '2',
"three", '3',
"four", '4',
"five", '5',
"six", '6',
"seven", '7',
"eight", '8',
"nine", '9',
"colon", ':',
"semicolon", ';',
"less-than-sign", '<',
"equals-sign", '=',
"greater-than-sign", '>',
"question-mark", '?',
"commercial-at", '@',
"left-square-bracket", '[',
"backslash", '\\',
"reverse-solidus", '\\',
"right-square-bracket", ']',
"circumflex", '^',
"circumflex-accent", '^',
"underscore", '_',
"low-line", '_',
"grave-accent", '`',
"left-brace", '{',
"left-curly-bracket", '{',
"vertical-line", '|',
"right-brace", '}',
"right-curly-bracket", '}',
"tilde", '~',
"DEL", '\177',
NULL, 0,
};
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/debug.c
0,0 → 1,243
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/types.h>
#include <regex.h>
 
#include "utils.h"
#include "regex2.h"
#include "debug.ih"
 
/*
- regprint - print a regexp for debugging
== void regprint(regex_t *r, FILE *d);
*/
void
regprint(r, d)
regex_t *r;
FILE *d;
{
register struct re_guts *g = r->re_g;
register int i;
register int c;
register int last;
int nincat[NC];
 
fprintf(d, "%ld states, %d categories", (long)g->nstates,
g->ncategories);
fprintf(d, ", first %ld last %ld", (long)g->firststate,
(long)g->laststate);
if (g->iflags&USEBOL)
fprintf(d, ", USEBOL");
if (g->iflags&USEEOL)
fprintf(d, ", USEEOL");
if (g->iflags&BAD)
fprintf(d, ", BAD");
if (g->nsub > 0)
fprintf(d, ", nsub=%ld", (long)g->nsub);
if (g->must != NULL)
fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen,
g->must);
if (g->backrefs)
fprintf(d, ", backrefs");
if (g->nplus > 0)
fprintf(d, ", nplus %ld", (long)g->nplus);
fprintf(d, "\n");
s_print(g, d);
for (i = 0; i < g->ncategories; i++) {
nincat[i] = 0;
for (c = CHAR_MIN; c <= CHAR_MAX; c++)
if (g->categories[c] == i)
nincat[i]++;
}
fprintf(d, "cc0#%d", nincat[0]);
for (i = 1; i < g->ncategories; i++)
if (nincat[i] == 1) {
for (c = CHAR_MIN; c <= CHAR_MAX; c++)
if (g->categories[c] == i)
break;
fprintf(d, ", %d=%s", i, regchar(c));
}
fprintf(d, "\n");
for (i = 1; i < g->ncategories; i++)
if (nincat[i] != 1) {
fprintf(d, "cc%d\t", i);
last = -1;
for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */
if (c <= CHAR_MAX && g->categories[c] == i) {
if (last < 0) {
fprintf(d, "%s", regchar(c));
last = c;
}
} else {
if (last >= 0) {
if (last != c-1)
fprintf(d, "-%s",
regchar(c-1));
last = -1;
}
}
fprintf(d, "\n");
}
}
 
/*
- s_print - print the strip for debugging
== static void s_print(register struct re_guts *g, FILE *d);
*/
static void
s_print(g, d)
register struct re_guts *g;
FILE *d;
{
register sop *s;
register cset *cs;
register int i;
register int done = 0;
register sop opnd;
register int col = 0;
register int last;
register sopno offset = 2;
# define GAP() { if (offset % 5 == 0) { \
if (col > 40) { \
fprintf(d, "\n\t"); \
col = 0; \
} else { \
fprintf(d, " "); \
col++; \
} \
} else \
col++; \
offset++; \
}
 
if (OP(g->strip[0]) != OEND)
fprintf(d, "missing initial OEND!\n");
for (s = &g->strip[1]; !done; s++) {
opnd = OPND(*s);
switch (OP(*s)) {
case OEND:
fprintf(d, "\n");
done = 1;
break;
case OCHAR:
if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL)
fprintf(d, "\\%c", (char)opnd);
else
fprintf(d, "%s", regchar((char)opnd));
break;
case OBOL:
fprintf(d, "^");
break;
case OEOL:
fprintf(d, "$");
break;
case OBOW:
fprintf(d, "\\{");
break;
case OEOW:
fprintf(d, "\\}");
break;
case OANY:
fprintf(d, ".");
break;
case OANYOF:
fprintf(d, "[(%ld)", (long)opnd);
cs = &g->sets[opnd];
last = -1;
for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */
if (CHIN(cs, i) && i < g->csetsize) {
if (last < 0) {
fprintf(d, "%s", regchar(i));
last = i;
}
} else {
if (last >= 0) {
if (last != i-1)
fprintf(d, "-%s",
regchar(i-1));
last = -1;
}
}
fprintf(d, "]");
break;
case OBACK_:
fprintf(d, "(\\<%ld>", (long)opnd);
break;
case O_BACK:
fprintf(d, "<%ld>\\)", (long)opnd);
break;
case OPLUS_:
fprintf(d, "(+");
if (OP(*(s+opnd)) != O_PLUS)
fprintf(d, "<%ld>", (long)opnd);
break;
case O_PLUS:
if (OP(*(s-opnd)) != OPLUS_)
fprintf(d, "<%ld>", (long)opnd);
fprintf(d, "+)");
break;
case OQUEST_:
fprintf(d, "(?");
if (OP(*(s+opnd)) != O_QUEST)
fprintf(d, "<%ld>", (long)opnd);
break;
case O_QUEST:
if (OP(*(s-opnd)) != OQUEST_)
fprintf(d, "<%ld>", (long)opnd);
fprintf(d, "?)");
break;
case OLPAREN:
fprintf(d, "((<%ld>", (long)opnd);
break;
case ORPAREN:
fprintf(d, "<%ld>))", (long)opnd);
break;
case OCH_:
fprintf(d, "<");
if (OP(*(s+opnd)) != OOR2)
fprintf(d, "<%ld>", (long)opnd);
break;
case OOR1:
if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_)
fprintf(d, "<%ld>", (long)opnd);
fprintf(d, "|");
break;
case OOR2:
fprintf(d, "|");
if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH)
fprintf(d, "<%ld>", (long)opnd);
break;
case O_CH:
if (OP(*(s-opnd)) != OOR1)
fprintf(d, "<%ld>", (long)opnd);
fprintf(d, ">");
break;
default:
fprintf(d, "!%d(%d)!", OP(*s), opnd);
break;
}
if (!done)
GAP();
}
}
 
/*
- regchar - make a character printable
== static char *regchar(int ch);
*/
static char * /* -> representation */
regchar(ch)
int ch;
{
static char buf[10];
 
if (isprint(ch) || ch == ' ')
sprintf(buf, "%c", ch);
else
sprintf(buf, "\\%o", ch);
return(buf);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/debug.ih
0,0 → 1,14
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
 
/* === debug.c === */
void regprint (regex_t *r, FILE *d);
static void s_print (register struct re_guts *g, FILE *d);
static char *regchar (int ch);
 
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/engine.c
0,0 → 1,1019
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* The matching engine and friends. This file is #included by regexec.c
* after suitable #defines of a variety of macros used herein, so that
* different state representations can be used without duplicating masses
* of code.
*/
 
#ifdef SNAMES
#define matcher smatcher
#define fast sfast
#define slow sslow
#define dissect sdissect
#define backref sbackref
#define step sstep
#define print sprint
#define at sat
#define match smat
#endif
#ifdef LNAMES
#define matcher lmatcher
#define fast lfast
#define slow lslow
#define dissect ldissect
#define backref lbackref
#define step lstep
#define print lprint
#define at lat
#define match lmat
#endif
 
/* another structure passed up and down to avoid zillions of parameters */
struct match {
struct re_guts *g;
int eflags;
regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
char *offp; /* offsets work from here */
char *beginp; /* start of string -- virtual NUL precedes */
char *endp; /* end of string -- virtual NUL here */
char *coldp; /* can be no match starting before here */
char **lastpos; /* [nplus+1] */
STATEVARS;
states st; /* current states */
states fresh; /* states for a fresh start */
states tmp; /* temporary */
states empty; /* empty set of states */
};
 
#include "engine.ih"
 
#ifdef REDEBUG
#define SP(t, s, c) print(m, t, s, c, stdout)
#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
#define NOTE(str) { if (m->eflags&REG_TRACE) printf("=%s\n", (str)); }
#else
#define SP(t, s, c) /* nothing */
#define AT(t, p1, p2, s1, s2) /* nothing */
#define NOTE(s) /* nothing */
#endif
 
/*
- matcher - the actual matching engine
== static int matcher(register struct re_guts *g, char *string, \
== size_t nmatch, regmatch_t pmatch[], int eflags);
*/
static int /* 0 success, REG_NOMATCH failure */
matcher(g, string, nmatch, pmatch, eflags)
register struct re_guts *g;
char *string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
{
register char *endp;
register int i;
struct match mv;
register struct match *m = &mv;
register char *dp;
const register sopno gf = g->firststate+1; /* +1 for OEND */
const register sopno gl = g->laststate;
char *start;
char *stop;
 
/* simplify the situation where possible */
if (g->cflags&REG_NOSUB)
nmatch = 0;
if (eflags&REG_STARTEND) {
start = string + pmatch[0].rm_so;
stop = string + pmatch[0].rm_eo;
} else {
start = string;
stop = start + strlen(start);
}
if (stop < start)
return(REG_INVARG);
 
/* prescreening; this does wonders for this rather slow code */
if (g->must != NULL) {
for (dp = start; dp < stop; dp++)
if (*dp == g->must[0] && stop - dp >= g->mlen &&
memcmp(dp, g->must, (size_t)g->mlen) == 0)
break;
if (dp == stop) /* we didn't find g->must */
return(REG_NOMATCH);
}
 
/* match struct setup */
m->g = g;
m->eflags = eflags;
m->pmatch = NULL;
m->lastpos = NULL;
m->offp = string;
m->beginp = start;
m->endp = stop;
STATESETUP(m, 4);
SETUP(m->st);
SETUP(m->fresh);
SETUP(m->tmp);
SETUP(m->empty);
CLEAR(m->empty);
 
/* this loop does only one repetition except for backrefs */
for (;;) {
endp = fast(m, start, stop, gf, gl);
if (endp == NULL) { /* a miss */
STATETEARDOWN(m);
return(REG_NOMATCH);
}
if (nmatch == 0 && !g->backrefs)
break; /* no further info needed */
 
/* where? */
assert(m->coldp != NULL);
for (;;) {
NOTE("finding start");
endp = slow(m, m->coldp, stop, gf, gl);
if (endp != NULL)
break;
assert(m->coldp < m->endp);
m->coldp++;
}
if (nmatch == 1 && !g->backrefs)
break; /* no further info needed */
 
/* oh my, he wants the subexpressions... */
if (m->pmatch == NULL)
m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
sizeof(regmatch_t));
if (m->pmatch == NULL) {
STATETEARDOWN(m);
return(REG_ESPACE);
}
for (i = 1; i <= m->g->nsub; i++)
m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
if (!g->backrefs && !(m->eflags&REG_BACKR)) {
NOTE("dissecting");
dp = dissect(m, m->coldp, endp, gf, gl);
} else {
if (g->nplus > 0 && m->lastpos == NULL)
m->lastpos = (char **)malloc((g->nplus+1) *
sizeof(char *));
if (g->nplus > 0 && m->lastpos == NULL) {
free(m->pmatch);
STATETEARDOWN(m);
return(REG_ESPACE);
}
NOTE("backref dissect");
dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
}
if (dp != NULL)
break;
 
/* uh-oh... we couldn't find a subexpression-level match */
assert(g->backrefs); /* must be back references doing it */
assert(g->nplus == 0 || m->lastpos != NULL);
for (;;) {
if (dp != NULL || endp <= m->coldp)
break; /* defeat */
NOTE("backoff");
endp = slow(m, m->coldp, endp-1, gf, gl);
if (endp == NULL)
break; /* defeat */
/* try it on a shorter possibility */
#ifndef NDEBUG
for (i = 1; i <= m->g->nsub; i++) {
assert(m->pmatch[i].rm_so == -1);
assert(m->pmatch[i].rm_eo == -1);
}
#endif
NOTE("backoff dissect");
dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
}
assert(dp == NULL || dp == endp);
if (dp != NULL) /* found a shorter one */
break;
 
/* despite initial appearances, there is no match here */
NOTE("false alarm");
start = m->coldp + 1; /* recycle starting later */
assert(start <= stop);
}
 
/* fill in the details if requested */
if (nmatch > 0) {
pmatch[0].rm_so = m->coldp - m->offp;
pmatch[0].rm_eo = endp - m->offp;
}
if (nmatch > 1) {
assert(m->pmatch != NULL);
for (i = 1; i < nmatch; i++)
if (i <= m->g->nsub)
pmatch[i] = m->pmatch[i];
else {
pmatch[i].rm_so = -1;
pmatch[i].rm_eo = -1;
}
}
 
if (m->pmatch != NULL)
free((char *)m->pmatch);
if (m->lastpos != NULL)
free((char *)m->lastpos);
STATETEARDOWN(m);
return(0);
}
 
/*
- dissect - figure out what matched what, no back references
== static char *dissect(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
*/
static char * /* == stop (success) always */
dissect(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
{
register int i;
register sopno ss; /* start sop of current subRE */
register sopno es; /* end sop of current subRE */
register char *sp; /* start of string matched by it */
register char *stp; /* string matched by it cannot pass here */
register char *rest; /* start of rest of string */
register char *tail; /* string unmatched by rest of RE */
register sopno ssub; /* start sop of subsubRE */
register sopno esub; /* end sop of subsubRE */
register char *ssp; /* start of string matched by subsubRE */
register char *sep; /* end of string matched by subsubRE */
register char *oldssp; /* previous ssp */
register char *dp;
 
AT("diss", start, stop, startst, stopst);
sp = start;
for (ss = startst; ss < stopst; ss = es) {
/* identify end of subRE */
es = ss;
switch (OP(m->g->strip[es])) {
case OPLUS_:
case OQUEST_:
es += OPND(m->g->strip[es]);
break;
case OCH_:
while (OP(m->g->strip[es]) != O_CH)
es += OPND(m->g->strip[es]);
break;
}
es++;
 
/* figure out what it matched */
switch (OP(m->g->strip[ss])) {
case OEND:
assert(nope);
break;
case OCHAR:
sp++;
break;
case OBOL:
case OEOL:
case OBOW:
case OEOW:
break;
case OANY:
case OANYOF:
sp++;
break;
case OBACK_:
case O_BACK:
assert(nope);
break;
/* cases where length of match is hard to find */
case OQUEST_:
stp = stop;
for (;;) {
/* how long could this one be? */
rest = slow(m, sp, stp, ss, es);
assert(rest != NULL); /* it did match */
/* could the rest match the rest? */
tail = slow(m, rest, stop, es, stopst);
if (tail == stop)
break; /* yes! */
/* no -- try a shorter match for this one */
stp = rest - 1;
assert(stp >= sp); /* it did work */
}
ssub = ss + 1;
esub = es - 1;
/* did innards match? */
if (slow(m, sp, rest, ssub, esub) != NULL) {
dp = dissect(m, sp, rest, ssub, esub);
assert(dp == rest);
} else /* no */
assert(sp == rest);
sp = rest;
break;
case OPLUS_:
stp = stop;
for (;;) {
/* how long could this one be? */
rest = slow(m, sp, stp, ss, es);
assert(rest != NULL); /* it did match */
/* could the rest match the rest? */
tail = slow(m, rest, stop, es, stopst);
if (tail == stop)
break; /* yes! */
/* no -- try a shorter match for this one */
stp = rest - 1;
assert(stp >= sp); /* it did work */
}
ssub = ss + 1;
esub = es - 1;
ssp = sp;
oldssp = ssp;
for (;;) { /* find last match of innards */
sep = slow(m, ssp, rest, ssub, esub);
if (sep == NULL || sep == ssp)
break; /* failed or matched null */
oldssp = ssp; /* on to next try */
ssp = sep;
}
if (sep == NULL) {
/* last successful match */
sep = ssp;
ssp = oldssp;
}
assert(sep == rest); /* must exhaust substring */
assert(slow(m, ssp, sep, ssub, esub) == rest);
dp = dissect(m, ssp, sep, ssub, esub);
assert(dp == sep);
sp = rest;
break;
case OCH_:
stp = stop;
for (;;) {
/* how long could this one be? */
rest = slow(m, sp, stp, ss, es);
assert(rest != NULL); /* it did match */
/* could the rest match the rest? */
tail = slow(m, rest, stop, es, stopst);
if (tail == stop)
break; /* yes! */
/* no -- try a shorter match for this one */
stp = rest - 1;
assert(stp >= sp); /* it did work */
}
ssub = ss + 1;
esub = ss + OPND(m->g->strip[ss]) - 1;
assert(OP(m->g->strip[esub]) == OOR1);
for (;;) { /* find first matching branch */
if (slow(m, sp, rest, ssub, esub) == rest)
break; /* it matched all of it */
/* that one missed, try next one */
assert(OP(m->g->strip[esub]) == OOR1);
esub++;
assert(OP(m->g->strip[esub]) == OOR2);
ssub = esub + 1;
esub += OPND(m->g->strip[esub]);
if (OP(m->g->strip[esub]) == OOR2)
esub--;
else
assert(OP(m->g->strip[esub]) == O_CH);
}
dp = dissect(m, sp, rest, ssub, esub);
assert(dp == rest);
sp = rest;
break;
case O_PLUS:
case O_QUEST:
case OOR1:
case OOR2:
case O_CH:
assert(nope);
break;
case OLPAREN:
i = OPND(m->g->strip[ss]);
assert(0 < i && i <= m->g->nsub);
m->pmatch[i].rm_so = sp - m->offp;
break;
case ORPAREN:
i = OPND(m->g->strip[ss]);
assert(0 < i && i <= m->g->nsub);
m->pmatch[i].rm_eo = sp - m->offp;
break;
default: /* uh oh */
assert(nope);
break;
}
}
 
assert(sp == stop);
return(sp);
}
 
/*
- backref - figure out what matched what, figuring in back references
== static char *backref(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst, sopno lev);
*/
static char * /* == stop (success) or NULL (failure) */
backref(m, start, stop, startst, stopst, lev)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
sopno lev; /* PLUS nesting level */
{
register int i;
register sopno ss; /* start sop of current subRE */
register char *sp; /* start of string matched by it */
register sopno ssub; /* start sop of subsubRE */
register sopno esub; /* end sop of subsubRE */
register char *ssp; /* start of string matched by subsubRE */
register char *dp;
register size_t len;
register int hard;
register sop s;
register regoff_t offsave;
register cset *cs;
 
AT("back", start, stop, startst, stopst);
sp = start;
 
/* get as far as we can with easy stuff */
hard = 0;
for (ss = startst; !hard && ss < stopst; ss++)
switch (OP(s = m->g->strip[ss])) {
case OCHAR:
if (sp == stop || *sp++ != (char)OPND(s))
return(NULL);
break;
case OANY:
if (sp == stop)
return(NULL);
sp++;
break;
case OANYOF:
cs = &m->g->sets[OPND(s)];
if (sp == stop || !CHIN(cs, *sp++))
return(NULL);
break;
case OBOL:
if ( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
(sp < m->endp && *(sp-1) == '\n' &&
(m->g->cflags&REG_NEWLINE)) )
{ /* yes */ }
else
return(NULL);
break;
case OEOL:
if ( (sp == m->endp && !(m->eflags&REG_NOTEOL)) ||
(sp < m->endp && *sp == '\n' &&
(m->g->cflags&REG_NEWLINE)) )
{ /* yes */ }
else
return(NULL);
break;
case OBOW:
if (( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
(sp < m->endp && *(sp-1) == '\n' &&
(m->g->cflags&REG_NEWLINE)) ||
(sp > m->beginp &&
!ISWORD(*(sp-1))) ) &&
(sp < m->endp && ISWORD(*sp)) )
{ /* yes */ }
else
return(NULL);
break;
case OEOW:
if (( (sp == m->endp && !(m->eflags&REG_NOTEOL)) ||
(sp < m->endp && *sp == '\n' &&
(m->g->cflags&REG_NEWLINE)) ||
(sp < m->endp && !ISWORD(*sp)) ) &&
(sp > m->beginp && ISWORD(*(sp-1))) )
{ /* yes */ }
else
return(NULL);
break;
case O_QUEST:
break;
case OOR1: /* matches null but needs to skip */
ss++;
s = m->g->strip[ss];
do {
assert(OP(s) == OOR2);
ss += OPND(s);
} while (OP(s = m->g->strip[ss]) != O_CH);
/* note that the ss++ gets us past the O_CH */
break;
default: /* have to make a choice */
hard = 1;
break;
}
if (!hard) { /* that was it! */
if (sp != stop)
return(NULL);
return(sp);
}
ss--; /* adjust for the for's final increment */
 
/* the hard stuff */
AT("hard", sp, stop, ss, stopst);
s = m->g->strip[ss];
switch (OP(s)) {
case OBACK_: /* the vilest depths */
i = OPND(s);
assert(0 < i && i <= m->g->nsub);
if (m->pmatch[i].rm_eo == -1)
return(NULL);
assert(m->pmatch[i].rm_so != -1);
len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
assert(stop - m->beginp >= len);
if (sp > stop - len)
return(NULL); /* not enough left to match */
ssp = m->offp + m->pmatch[i].rm_so;
if (memcmp(sp, ssp, len) != 0)
return(NULL);
while (m->g->strip[ss] != SOP(O_BACK, i))
ss++;
return(backref(m, sp+len, stop, ss+1, stopst, lev));
break;
case OQUEST_: /* to null or not */
dp = backref(m, sp, stop, ss+1, stopst, lev);
if (dp != NULL)
return(dp); /* not */
return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev));
break;
case OPLUS_:
assert(m->lastpos != NULL);
assert(lev+1 <= m->g->nplus);
m->lastpos[lev+1] = sp;
return(backref(m, sp, stop, ss+1, stopst, lev+1));
break;
case O_PLUS:
if (sp == m->lastpos[lev]) /* last pass matched null */
return(backref(m, sp, stop, ss+1, stopst, lev-1));
/* try another pass */
m->lastpos[lev] = sp;
dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev);
if (dp == NULL)
return(backref(m, sp, stop, ss+1, stopst, lev-1));
else
return(dp);
break;
case OCH_: /* find the right one, if any */
ssub = ss + 1;
esub = ss + OPND(s) - 1;
assert(OP(m->g->strip[esub]) == OOR1);
for (;;) { /* find first matching branch */
dp = backref(m, sp, stop, ssub, esub, lev);
if (dp != NULL)
return(dp);
/* that one missed, try next one */
if (OP(m->g->strip[esub]) == O_CH)
return(NULL); /* there is none */
esub++;
assert(OP(m->g->strip[esub]) == OOR2);
ssub = esub + 1;
esub += OPND(m->g->strip[esub]);
if (OP(m->g->strip[esub]) == OOR2)
esub--;
else
assert(OP(m->g->strip[esub]) == O_CH);
}
break;
case OLPAREN: /* must undo assignment if rest fails */
i = OPND(s);
assert(0 < i && i <= m->g->nsub);
offsave = m->pmatch[i].rm_so;
m->pmatch[i].rm_so = sp - m->offp;
dp = backref(m, sp, stop, ss+1, stopst, lev);
if (dp != NULL)
return(dp);
m->pmatch[i].rm_so = offsave;
return(NULL);
break;
case ORPAREN: /* must undo assignment if rest fails */
i = OPND(s);
assert(0 < i && i <= m->g->nsub);
offsave = m->pmatch[i].rm_eo;
m->pmatch[i].rm_eo = sp - m->offp;
dp = backref(m, sp, stop, ss+1, stopst, lev);
if (dp != NULL)
return(dp);
m->pmatch[i].rm_eo = offsave;
return(NULL);
break;
default: /* uh oh */
assert(nope);
break;
}
 
/* "can't happen" */
assert(nope);
/* NOTREACHED */
}
 
/*
- fast - step through the string at top speed
== static char *fast(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
*/
static char * /* where tentative match ended, or NULL */
fast(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
{
register states st = m->st;
register states fresh = m->fresh;
register states tmp = m->tmp;
register char *p = start;
register int c = (start == m->beginp) ? OUT : *(start-1);
register int lastc; /* previous c */
register int flagch;
register int i;
register char *coldp; /* last p after which no match was underway */
 
CLEAR(st);
SET1(st, startst);
st = step(m->g, startst, stopst, st, NOTHING, st);
ASSIGN(fresh, st);
SP("start", st, *p);
coldp = NULL;
for (;;) {
/* next character */
lastc = c;
c = (p == m->endp) ? OUT : *p;
if (EQ(st, fresh))
coldp = p;
 
/* is there an EOL and/or BOL between lastc and c? */
flagch = '\0';
i = 0;
if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
flagch = BOL;
i = m->g->nbol;
}
if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
flagch = (flagch == BOL) ? BOLEOL : EOL;
i += m->g->neol;
}
if (i != 0) {
for (; i > 0; i--)
st = step(m->g, startst, stopst, st, flagch, st);
SP("boleol", st, c);
}
 
/* how about a word boundary? */
if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
(c != OUT && ISWORD(c)) ) {
flagch = BOW;
}
if ( (lastc != OUT && ISWORD(lastc)) &&
(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
flagch = EOW;
}
if (flagch == BOW || flagch == EOW) {
st = step(m->g, startst, stopst, st, flagch, st);
SP("boweow", st, c);
}
 
/* are we done? */
if (ISSET(st, stopst) || p == stop)
break; /* NOTE BREAK OUT */
 
/* no, we must deal with this character */
ASSIGN(tmp, st);
ASSIGN(st, fresh);
assert(c != OUT);
st = step(m->g, startst, stopst, tmp, c, st);
SP("aft", st, c);
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
p++;
}
 
assert(coldp != NULL);
m->coldp = coldp;
if (ISSET(st, stopst))
return(p+1);
else
return(NULL);
}
 
/*
- slow - step through the string more deliberately
== static char *slow(register struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
*/
static char * /* where it ended */
slow(m, start, stop, startst, stopst)
register struct match *m;
char *start;
char *stop;
sopno startst;
sopno stopst;
{
register states st = m->st;
register states empty = m->empty;
register states tmp = m->tmp;
register char *p = start;
register int c = (start == m->beginp) ? OUT : *(start-1);
register int lastc; /* previous c */
register int flagch;
register int i;
register char *matchp; /* last p at which a match ended */
 
AT("slow", start, stop, startst, stopst);
CLEAR(st);
SET1(st, startst);
SP("sstart", st, *p);
st = step(m->g, startst, stopst, st, NOTHING, st);
matchp = NULL;
for (;;) {
/* next character */
lastc = c;
c = (p == m->endp) ? OUT : *p;
 
/* is there an EOL and/or BOL between lastc and c? */
flagch = '\0';
i = 0;
if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
flagch = BOL;
i = m->g->nbol;
}
if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
flagch = (flagch == BOL) ? BOLEOL : EOL;
i += m->g->neol;
}
if (i != 0) {
for (; i > 0; i--)
st = step(m->g, startst, stopst, st, flagch, st);
SP("sboleol", st, c);
}
 
/* how about a word boundary? */
if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
(c != OUT && ISWORD(c)) ) {
flagch = BOW;
}
if ( (lastc != OUT && ISWORD(lastc)) &&
(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
flagch = EOW;
}
if (flagch == BOW || flagch == EOW) {
st = step(m->g, startst, stopst, st, flagch, st);
SP("sboweow", st, c);
}
 
/* are we done? */
if (ISSET(st, stopst))
matchp = p;
if (EQ(st, empty) || p == stop)
break; /* NOTE BREAK OUT */
 
/* no, we must deal with this character */
ASSIGN(tmp, st);
ASSIGN(st, empty);
assert(c != OUT);
st = step(m->g, startst, stopst, tmp, c, st);
SP("saft", st, c);
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
p++;
}
 
return(matchp);
}
 
 
/*
- step - map set of states reachable before char to set reachable after
== static states step(register struct re_guts *g, sopno start, sopno stop, \
== register states bef, int ch, register states aft);
== #define BOL (OUT+1)
== #define EOL (BOL+1)
== #define BOLEOL (BOL+2)
== #define NOTHING (BOL+3)
== #define BOW (BOL+4)
== #define EOW (BOL+5)
== #define CODEMAX (BOL+5) // highest code used
== #define NONCHAR(c) ((c) > CHAR_MAX)
== #define NNONCHAR (CODEMAX-CHAR_MAX)
*/
static states
step(g, start, stop, bef, ch, aft)
register struct re_guts *g;
sopno start; /* start state within strip */
sopno stop; /* state after stop state within strip */
register states bef; /* states reachable before */
int ch; /* character or NONCHAR code */
register states aft; /* states already known reachable after */
{
register cset *cs;
register sop s;
register sopno pc;
register onestate here; /* note, macros know this name */
register sopno look;
register int i;
 
for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
s = g->strip[pc];
switch (OP(s)) {
case OEND:
assert(pc == stop-1);
break;
case OCHAR:
/* only characters can match */
assert(!NONCHAR(ch) || ch != (char)OPND(s));
if (ch == (char)OPND(s))
FWD(aft, bef, 1);
break;
case OBOL:
if (ch == BOL || ch == BOLEOL)
FWD(aft, bef, 1);
break;
case OEOL:
if (ch == EOL || ch == BOLEOL)
FWD(aft, bef, 1);
break;
case OBOW:
if (ch == BOW)
FWD(aft, bef, 1);
break;
case OEOW:
if (ch == EOW)
FWD(aft, bef, 1);
break;
case OANY:
if (!NONCHAR(ch))
FWD(aft, bef, 1);
break;
case OANYOF:
cs = &g->sets[OPND(s)];
if (!NONCHAR(ch) && CHIN(cs, ch))
FWD(aft, bef, 1);
break;
case OBACK_: /* ignored here */
case O_BACK:
FWD(aft, aft, 1);
break;
case OPLUS_: /* forward, this is just an empty */
FWD(aft, aft, 1);
break;
case O_PLUS: /* both forward and back */
FWD(aft, aft, 1);
i = ISSETBACK(aft, OPND(s));
BACK(aft, aft, OPND(s));
if (!i && ISSETBACK(aft, OPND(s))) {
/* oho, must reconsider loop body */
pc -= OPND(s) + 1;
INIT(here, pc);
}
break;
case OQUEST_: /* two branches, both forward */
FWD(aft, aft, 1);
FWD(aft, aft, OPND(s));
break;
case O_QUEST: /* just an empty */
FWD(aft, aft, 1);
break;
case OLPAREN: /* not significant here */
case ORPAREN:
FWD(aft, aft, 1);
break;
case OCH_: /* mark the first two branches */
FWD(aft, aft, 1);
assert(OP(g->strip[pc+OPND(s)]) == OOR2);
FWD(aft, aft, OPND(s));
break;
case OOR1: /* done a branch, find the O_CH */
if (ISSTATEIN(aft, here)) {
for (look = 1;
OP(s = g->strip[pc+look]) != O_CH;
look += OPND(s))
assert(OP(s) == OOR2);
FWD(aft, aft, look);
}
break;
case OOR2: /* propagate OCH_'s marking */
FWD(aft, aft, 1);
if (OP(g->strip[pc+OPND(s)]) != O_CH) {
assert(OP(g->strip[pc+OPND(s)]) == OOR2);
FWD(aft, aft, OPND(s));
}
break;
case O_CH: /* just empty */
FWD(aft, aft, 1);
break;
default: /* ooooops... */
assert(nope);
break;
}
}
 
return(aft);
}
 
#ifdef REDEBUG
/*
- print - print a set of states
== #ifdef REDEBUG
== static void print(struct match *m, char *caption, states st, \
== int ch, FILE *d);
== #endif
*/
static void
print(m, caption, st, ch, d)
struct match *m;
char *caption;
states st;
int ch;
FILE *d;
{
register struct re_guts *g = m->g;
register int i;
register int first = 1;
 
if (!(m->eflags&REG_TRACE))
return;
 
fprintf(d, "%s", caption);
if (ch != '\0')
fprintf(d, " %s", pchar(ch));
for (i = 0; i < g->nstates; i++)
if (ISSET(st, i)) {
fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
first = 0;
}
fprintf(d, "\n");
}
 
/*
- at - print current situation
== #ifdef REDEBUG
== static void at(struct match *m, char *title, char *start, char *stop, \
== sopno startst, sopno stopst);
== #endif
*/
static void
at(m, title, start, stop, startst, stopst)
struct match *m;
char *title;
char *start;
char *stop;
sopno startst;
sopno stopst;
{
if (!(m->eflags&REG_TRACE))
return;
 
printf("%s %s-", title, pchar(*start));
printf("%s ", pchar(*stop));
printf("%ld-%ld\n", (long)startst, (long)stopst);
}
 
#ifndef PCHARDONE
#define PCHARDONE /* never again */
/*
- pchar - make a character printable
== #ifdef REDEBUG
== static char *pchar(int ch);
== #endif
*
* Is this identical to regchar() over in debug.c? Well, yes. But a
* duplicate here avoids having a debugging-capable regexec.o tied to
* a matching debug.o, and this is convenient. It all disappears in
* the non-debug compilation anyway, so it doesn't matter much.
*/
static char * /* -> representation */
pchar(ch)
int ch;
{
static char pbuf[10];
 
if (isprint(ch) || ch == ' ')
sprintf(pbuf, "%c", ch);
else
sprintf(pbuf, "\\%o", ch);
return(pbuf);
}
#endif
#endif
 
#undef matcher
#undef fast
#undef slow
#undef dissect
#undef backref
#undef step
#undef print
#undef at
#undef match
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/engine.ih
0,0 → 1,35
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
 
/* === engine.c === */
static int matcher (register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
static char *dissect (register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static char *backref (register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
static char *fast (register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static char *slow (register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static states step (register struct re_guts *g, sopno start, sopno stop, register states bef, int ch, register states aft);
#define BOL (OUT+1)
#define EOL (BOL+1)
#define BOLEOL (BOL+2)
#define NOTHING (BOL+3)
#define BOW (BOL+4)
#define EOW (BOL+5)
#define CODEMAX (BOL+5) /* highest code used */
#define NONCHAR(c) ((c) > CHAR_MAX)
#define NNONCHAR (CODEMAX-CHAR_MAX)
#ifdef REDEBUG
static void print (struct match *m, char *caption, states st, int ch, FILE *d);
#endif
#ifdef REDEBUG
static void at (struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
#endif
#ifdef REDEBUG
static char *pchar (int ch);
#endif
 
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/main.c
0,0 → 1,511
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include <assert.h>
 
#include "main.ih"
 
char *progname;
int debug = 0;
int line = 0;
int status = 0;
 
int copts = REG_EXTENDED;
int eopts = 0;
regoff_t startoff = 0;
regoff_t endoff = 0;
 
 
extern int split();
extern void regprint();
 
/*
- main - do the simple case, hand off to regress() for regression
*/
main(argc, argv)
int argc;
char *argv[];
{
regex_t re;
# define NS 10
regmatch_t subs[NS];
char erbuf[100];
int err;
size_t len;
int c;
int errflg = 0;
register int i;
extern int optind;
extern char *optarg;
 
progname = argv[0];
 
while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF)
switch (c) {
case 'c': /* compile options */
copts = options('c', optarg);
break;
case 'e': /* execute options */
eopts = options('e', optarg);
break;
case 'S': /* start offset */
startoff = (regoff_t)atoi(optarg);
break;
case 'E': /* end offset */
endoff = (regoff_t)atoi(optarg);
break;
case 'x': /* Debugging. */
debug++;
break;
case '?':
default:
errflg++;
break;
}
if (errflg) {
fprintf(stderr, "usage: %s ", progname);
fprintf(stderr, "[-c copt][-C][-d] [re]\n");
exit(2);
}
 
if (optind >= argc) {
regress(stdin);
exit(status);
}
 
err = regcomp(&re, argv[optind++], copts);
if (err) {
len = regerror(err, &re, erbuf, sizeof(erbuf));
fprintf(stderr, "error %s, %d/%d `%s'\n",
eprint(err), len, sizeof(erbuf), erbuf);
exit(status);
}
regprint(&re, stdout);
 
if (optind >= argc) {
regfree(&re);
exit(status);
}
 
if (eopts&REG_STARTEND) {
subs[0].rm_so = startoff;
subs[0].rm_eo = strlen(argv[optind]) - endoff;
}
err = regexec(&re, argv[optind], (size_t)NS, subs, eopts);
if (err) {
len = regerror(err, &re, erbuf, sizeof(erbuf));
fprintf(stderr, "error %s, %d/%d `%s'\n",
eprint(err), len, sizeof(erbuf), erbuf);
exit(status);
}
if (!(copts&REG_NOSUB)) {
len = (int)(subs[0].rm_eo - subs[0].rm_so);
if (subs[0].rm_so != -1) {
if (len != 0)
printf("match `%.*s'\n", len,
argv[optind] + subs[0].rm_so);
else
printf("match `'@%.1s\n",
argv[optind] + subs[0].rm_so);
}
for (i = 1; i < NS; i++)
if (subs[i].rm_so != -1)
printf("(%d) `%.*s'\n", i,
(int)(subs[i].rm_eo - subs[i].rm_so),
argv[optind] + subs[i].rm_so);
}
exit(status);
}
 
/*
- regress - main loop of regression test
== void regress(FILE *in);
*/
void
regress(in)
FILE *in;
{
char inbuf[1000];
# define MAXF 10
char *f[MAXF];
int nf;
int i;
char erbuf[100];
size_t ne;
char *badpat = "invalid regular expression";
# define SHORT 10
char *bpname = "REG_BADPAT";
regex_t re;
 
while (fgets(inbuf, sizeof(inbuf), in) != NULL) {
line++;
if (inbuf[0] == '#' || inbuf[0] == '\n')
continue; /* NOTE CONTINUE */
inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
if (debug)
fprintf(stdout, "%d:\n", line);
nf = split(inbuf, f, MAXF, "\t\t");
if (nf < 3) {
fprintf(stderr, "bad input, line %d\n", line);
exit(1);
}
for (i = 0; i < nf; i++)
if (strcmp(f[i], "\"\"") == 0)
f[i] = "";
if (nf <= 3)
f[3] = NULL;
if (nf <= 4)
f[4] = NULL;
try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]));
if (opt('&', f[1])) /* try with either type of RE */
try(f[0], f[1], f[2], f[3], f[4],
options('c', f[1]) &~ REG_EXTENDED);
}
 
ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) {
fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n",
erbuf, badpat);
status = 1;
}
ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT);
if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' ||
ne != strlen(badpat)+1) {
fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n",
erbuf, SHORT-1, badpat);
status = 1;
}
ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) {
fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n",
erbuf, bpname);
status = 1;
}
re.re_endp = bpname;
ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf));
if (atoi(erbuf) != (int)REG_BADPAT) {
fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n",
erbuf, (long)REG_BADPAT);
status = 1;
} else if (ne != strlen(erbuf)+1) {
fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n",
erbuf, (long)REG_BADPAT);
status = 1;
}
}
 
/*
- try - try it, and report on problems
== void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
*/
void
try(f0, f1, f2, f3, f4, opts)
char *f0;
char *f1;
char *f2;
char *f3;
char *f4;
int opts; /* may not match f1 */
{
regex_t re;
# define NSUBS 10
regmatch_t subs[NSUBS];
# define NSHOULD 15
char *should[NSHOULD];
int nshould;
char erbuf[100];
int err;
int len;
char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE";
register int i;
char *grump;
char f0copy[1000];
char f2copy[1000];
 
strcpy(f0copy, f0);
re.re_endp = (opts&REG_PEND) ? f0copy + strlen(f0copy) : NULL;
fixstr(f0copy);
err = regcomp(&re, f0copy, opts);
if (err != 0 && (!opt('C', f1) || err != efind(f2))) {
/* unexpected error or wrong error */
len = regerror(err, &re, erbuf, sizeof(erbuf));
fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n",
line, type, eprint(err), len,
sizeof(erbuf), erbuf);
status = 1;
} else if (err == 0 && opt('C', f1)) {
/* unexpected success */
fprintf(stderr, "%d: %s should have given REG_%s\n",
line, type, f2);
status = 1;
err = 1; /* so we won't try regexec */
}
 
if (err != 0) {
regfree(&re);
return;
}
 
strcpy(f2copy, f2);
fixstr(f2copy);
 
if (options('e', f1)&REG_STARTEND) {
if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL)
fprintf(stderr, "%d: bad STARTEND syntax\n", line);
subs[0].rm_so = strchr(f2, '(') - f2 + 1;
subs[0].rm_eo = strchr(f2, ')') - f2;
}
err = regexec(&re, f2copy, NSUBS, subs, options('e', f1));
 
if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) {
/* unexpected error or wrong error */
len = regerror(err, &re, erbuf, sizeof(erbuf));
fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n",
line, type, eprint(err), len,
sizeof(erbuf), erbuf);
status = 1;
} else if (err != 0) {
/* nothing more to check */
} else if (f3 == NULL) {
/* unexpected success */
fprintf(stderr, "%d: %s exec should have failed\n",
line, type);
status = 1;
err = 1; /* just on principle */
} else if (opts&REG_NOSUB) {
/* nothing more to check */
} else if ((grump = check(f2, subs[0], f3)) != NULL) {
fprintf(stderr, "%d: %s %s\n", line, type, grump);
status = 1;
err = 1;
}
 
if (err != 0 || f4 == NULL) {
regfree(&re);
return;
}
 
for (i = 1; i < NSHOULD; i++)
should[i] = NULL;
nshould = split(f4, should+1, NSHOULD-1, ",");
if (nshould == 0) {
nshould = 1;
should[1] = "";
}
for (i = 1; i < NSUBS; i++) {
grump = check(f2, subs[i], should[i]);
if (grump != NULL) {
fprintf(stderr, "%d: %s $%d %s\n", line,
type, i, grump);
status = 1;
err = 1;
}
}
 
regfree(&re);
}
 
/*
- options - pick options out of a regression-test string
== int options(int type, char *s);
*/
int
options(type, s)
int type; /* 'c' compile, 'e' exec */
char *s;
{
register char *p;
register int o = (type == 'c') ? copts : eopts;
register char *legal = (type == 'c') ? "bisnmp" : "^$#tl";
 
for (p = s; *p != '\0'; p++)
if (strchr(legal, *p) != NULL)
switch (*p) {
case 'b':
o &= ~REG_EXTENDED;
break;
case 'i':
o |= REG_ICASE;
break;
case 's':
o |= REG_NOSUB;
break;
case 'n':
o |= REG_NEWLINE;
break;
case 'm':
o &= ~REG_EXTENDED;
o |= REG_NOSPEC;
break;
case 'p':
o |= REG_PEND;
break;
case '^':
o |= REG_NOTBOL;
break;
case '$':
o |= REG_NOTEOL;
break;
case '#':
o |= REG_STARTEND;
break;
case 't': /* trace */
o |= REG_TRACE;
break;
case 'l': /* force long representation */
o |= REG_LARGE;
break;
case 'r': /* force backref use */
o |= REG_BACKR;
break;
}
return(o);
}
 
/*
- opt - is a particular option in a regression string?
== int opt(int c, char *s);
*/
int /* predicate */
opt(c, s)
int c;
char *s;
{
return(strchr(s, c) != NULL);
}
 
/*
- fixstr - transform magic characters in strings
== void fixstr(register char *p);
*/
void
fixstr(p)
register char *p;
{
if (p == NULL)
return;
 
for (; *p != '\0'; p++)
if (*p == 'N')
*p = '\n';
else if (*p == 'T')
*p = '\t';
else if (*p == 'S')
*p = ' ';
else if (*p == 'Z')
*p = '\0';
}
 
/*
- check - check a substring match
== char *check(char *str, regmatch_t sub, char *should);
*/
char * /* NULL or complaint */
check(str, sub, should)
char *str;
regmatch_t sub;
char *should;
{
register int len;
register int shlen;
register char *p;
static char grump[500];
register char *at = NULL;
 
if (should != NULL && strcmp(should, "-") == 0)
should = NULL;
if (should != NULL && should[0] == '@') {
at = should + 1;
should = "";
}
 
/* check rm_so and rm_eo for consistency */
if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) ||
(sub.rm_so != -1 && sub.rm_eo == -1) ||
(sub.rm_so != -1 && sub.rm_so < 0) ||
(sub.rm_eo != -1 && sub.rm_eo < 0) ) {
sprintf(grump, "start %ld end %ld", (long)sub.rm_so,
(long)sub.rm_eo);
return(grump);
}
 
/* check for no match */
if (sub.rm_so == -1 && should == NULL)
return(NULL);
if (sub.rm_so == -1)
return("did not match");
 
/* check for in range */
if (sub.rm_eo > strlen(str)) {
sprintf(grump, "start %ld end %ld, past end of string",
(long)sub.rm_so, (long)sub.rm_eo);
return(grump);
}
 
len = (int)(sub.rm_eo - sub.rm_so);
shlen = (int)strlen(should);
p = str + sub.rm_so;
 
/* check for not supposed to match */
if (should == NULL) {
sprintf(grump, "matched `%.*s'", len, p);
return(grump);
}
 
/* check for wrong match */
if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) {
sprintf(grump, "matched `%.*s' instead", len, p);
return(grump);
}
if (shlen > 0)
return(NULL);
 
/* check null match in right place */
if (at == NULL)
return(NULL);
shlen = strlen(at);
if (shlen == 0)
shlen = 1; /* force check for end-of-string */
if (strncmp(p, at, shlen) != 0) {
sprintf(grump, "matched null at `%.20s'", p);
return(grump);
}
return(NULL);
}
 
/*
- eprint - convert error number to name
== static char *eprint(int err);
*/
static char *
eprint(err)
int err;
{
static char epbuf[100];
size_t len;
 
len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf));
assert(len <= sizeof(epbuf));
return(epbuf);
}
 
/*
- efind - convert error name to number
== static int efind(char *name);
*/
static int
efind(name)
char *name;
{
static char efbuf[100];
size_t n;
regex_t re;
 
sprintf(efbuf, "REG_%s", name);
assert(strlen(efbuf) < sizeof(efbuf));
re.re_endp = efbuf;
(void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf));
return(atoi(efbuf));
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/main.ih
0,0 → 1,19
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
 
/* === main.c === */
void regress (FILE *in);
void try (char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
int options (int type, char *s);
int opt (int c, char *s);
void fixstr (register char *p);
char *check (char *str, regmatch_t sub, char *should);
static char *eprint (int err);
static int efind (char *name);
 
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regcomp.c
0,0 → 1,1606
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <regex.h>
 
#include "utils.h"
#include "regex2.h"
 
#include "cclass.h"
#include "cname.h"
 
/*
* parse structure, passed up and down to avoid global variables and
* other clumsinesses
*/
struct parse {
char *next; /* next character in RE */
char *end; /* end of string (-> NUL normally) */
int error; /* has an error been seen? */
sop *strip; /* malloced strip */
sopno ssize; /* malloced strip size (allocated) */
sopno slen; /* malloced strip length (used) */
int ncsalloc; /* number of csets allocated */
struct re_guts *g;
# define NPAREN 10 /* we need to remember () 1-9 for back refs */
sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
sopno pend[NPAREN]; /* -> ) ([0] unused) */
};
 
#include "regcomp.ih"
 
static char nuls[10]; /* place to point scanner in event of error */
 
/*
* macros for use with parse structure
* BEWARE: these know that the parse structure is named `p' !!!
*/
#define PEEK() (*p->next)
#define PEEK2() (*(p->next+1))
#define MORE() (p->next < p->end)
#define MORE2() (p->next+1 < p->end)
#define SEE(c) (MORE() && PEEK() == (c))
#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
#define NEXT() (p->next++)
#define NEXT2() (p->next += 2)
#define NEXTn(n) (p->next += (n))
#define GETNEXT() (*p->next++)
#define SETERROR(e) seterr(p, (e))
#define REQUIRE(co, e) ((co) || SETERROR(e))
#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
#define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
#define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
#define HERE() (p->slen)
#define THERE() (p->slen - 1)
#define THERETHERE() (p->slen - 2)
#define DROP(n) (p->slen -= (n))
 
#ifndef NDEBUG
static int never = 0; /* for use in asserts; shuts lint up */
#else
#define never 0 /* some <assert.h>s have bugs too */
#endif
 
/*
- regcomp - interface for parser and compilation
= extern int regcomp(regex_t *, const char *, int);
= #define REG_BASIC 0000
= #define REG_EXTENDED 0001
= #define REG_ICASE 0002
= #define REG_NOSUB 0004
= #define REG_NEWLINE 0010
= #define REG_NOSPEC 0020
= #define REG_PEND 0040
= #define REG_DUMP 0200
*/
int /* 0 success, otherwise REG_something */
regcomp(preg, pattern, cflags)
regex_t *preg;
const char *pattern;
int cflags;
{
struct parse pa;
register struct re_guts *g;
register struct parse *p = &pa;
register int i;
register size_t len;
#ifdef REDEBUG
# define GOODFLAGS(f) (f)
#else
# define GOODFLAGS(f) ((f)&~REG_DUMP)
#endif
 
cflags = GOODFLAGS(cflags);
if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
return(REG_INVARG);
 
if (cflags&REG_PEND) {
if (preg->re_endp < pattern)
return(REG_INVARG);
len = preg->re_endp - pattern;
} else
len = strlen((char *)pattern);
 
/* do the mallocs early so failure handling is easy */
g = (struct re_guts *)malloc(sizeof(struct re_guts) +
(NC-1)*sizeof(cat_t));
if (g == NULL)
return(REG_ESPACE);
p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
p->strip = (sop *)malloc(p->ssize * sizeof(sop));
p->slen = 0;
if (p->strip == NULL) {
free((char *)g);
return(REG_ESPACE);
}
 
/* set things up */
p->g = g;
p->next = (char *)pattern; /* convenience; we do not modify it */
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
for (i = 0; i < NPAREN; i++) {
p->pbegin[i] = 0;
p->pend[i] = 0;
}
g->csetsize = NC;
g->sets = NULL;
g->setbits = NULL;
g->ncsets = 0;
g->cflags = cflags;
g->iflags = 0;
g->nbol = 0;
g->neol = 0;
g->must = NULL;
g->mlen = 0;
g->nsub = 0;
g->ncategories = 1; /* category 0 is "everything else" */
g->categories = &g->catspace[-(CHAR_MIN)];
(void) memset((char *)g->catspace, 0, NC*sizeof(cat_t));
g->backrefs = 0;
 
/* do it */
EMIT(OEND, 0);
g->firststate = THERE();
if (cflags&REG_EXTENDED)
p_ere(p, OUT);
else if (cflags&REG_NOSPEC)
p_str(p);
else
p_bre(p, OUT, OUT);
EMIT(OEND, 0);
g->laststate = THERE();
 
/* tidy up loose ends and fill things in */
categorize(p, g);
stripsnug(p, g);
findmust(p, g);
g->nplus = pluscount(p, g);
g->magic = MAGIC2;
preg->re_nsub = g->nsub;
preg->re_g = g;
preg->re_magic = MAGIC1;
#ifndef REDEBUG
/* not debugging, so can't rely on the assert() in regexec() */
if (g->iflags&BAD)
SETERROR(REG_ASSERT);
#endif
 
/* win or lose, we're done */
if (p->error != 0) /* lose */
regfree(preg);
return(p->error);
}
 
/*
- p_ere - ERE parser top level, concatenation and alternation
== static void p_ere(register struct parse *p, int stop);
*/
static void
p_ere(p, stop)
register struct parse *p;
int stop; /* character this ERE should end at */
{
register char c;
register sopno prevback;
register sopno prevfwd;
register sopno conc;
register int first = 1; /* is this the first alternative? */
 
for (;;) {
/* do a bunch of concatenated expressions */
conc = HERE();
while (MORE() && (c = PEEK()) != '|' && c != stop)
p_ere_exp(p);
REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
 
if (!EAT('|'))
break; /* NOTE BREAK OUT */
 
if (first) {
INSERT(OCH_, conc); /* offset is wrong */
prevfwd = conc;
prevback = conc;
first = 0;
}
ASTERN(OOR1, prevback);
prevback = THERE();
AHEAD(prevfwd); /* fix previous offset */
prevfwd = HERE();
EMIT(OOR2, 0); /* offset is very wrong */
}
 
if (!first) { /* tail-end fixups */
AHEAD(prevfwd);
ASTERN(O_CH, prevback);
}
 
assert(!MORE() || SEE(stop));
}
 
/*
- p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
== static void p_ere_exp(register struct parse *p);
*/
static void
p_ere_exp(p)
register struct parse *p;
{
register char c;
register sopno pos;
register int count;
register int count2;
register sopno subno;
int wascaret = 0;
 
assert(MORE()); /* caller should have ensured this */
c = GETNEXT();
 
pos = HERE();
switch (c) {
case '(':
REQUIRE(MORE(), REG_EPAREN);
p->g->nsub++;
subno = p->g->nsub;
if (subno < NPAREN)
p->pbegin[subno] = HERE();
EMIT(OLPAREN, subno);
if (!SEE(')'))
p_ere(p, ')');
if (subno < NPAREN) {
p->pend[subno] = HERE();
assert(p->pend[subno] != 0);
}
EMIT(ORPAREN, subno);
MUSTEAT(')', REG_EPAREN);
break;
#ifndef POSIX_MISTAKE
case ')': /* happens only if no current unmatched ( */
/*
* You may ask, why the ifndef? Because I didn't notice
* this until slightly too late for 1003.2, and none of the
* other 1003.2 regular-expression reviewers noticed it at
* all. So an unmatched ) is legal POSIX, at least until
* we can get it fixed.
*/
SETERROR(REG_EPAREN);
break;
#endif
case '^':
EMIT(OBOL, 0);
p->g->iflags |= USEBOL;
p->g->nbol++;
wascaret = 1;
break;
case '$':
EMIT(OEOL, 0);
p->g->iflags |= USEEOL;
p->g->neol++;
break;
case '|':
SETERROR(REG_EMPTY);
break;
case '*':
case '+':
case '?':
SETERROR(REG_BADRPT);
break;
case '.':
if (p->g->cflags&REG_NEWLINE)
nonnewline(p);
else
EMIT(OANY, 0);
break;
case '[':
p_bracket(p);
break;
case '\\':
REQUIRE(MORE(), REG_EESCAPE);
c = GETNEXT();
ordinary(p, c);
break;
case '{': /* okay as ordinary except if digit follows */
REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
/* FALLTHROUGH */
default:
ordinary(p, c);
break;
}
 
if (!MORE())
return;
c = PEEK();
/* we call { a repetition if followed by a digit */
if (!( c == '*' || c == '+' || c == '?' ||
(c == '{' && MORE2() && isdigit(PEEK2())) ))
return; /* no repetition, we're done */
NEXT();
 
REQUIRE(!wascaret, REG_BADRPT);
switch (c) {
case '*': /* implemented as +? */
/* this case does not require the (y|) trick, noKLUDGE */
INSERT(OPLUS_, pos);
ASTERN(O_PLUS, pos);
INSERT(OQUEST_, pos);
ASTERN(O_QUEST, pos);
break;
case '+':
INSERT(OPLUS_, pos);
ASTERN(O_PLUS, pos);
break;
case '?':
/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
INSERT(OCH_, pos); /* offset slightly wrong */
ASTERN(OOR1, pos); /* this one's right */
AHEAD(pos); /* fix the OCH_ */
EMIT(OOR2, 0); /* offset very wrong... */
AHEAD(THERE()); /* ...so fix it */
ASTERN(O_CH, THERETHERE());
break;
case '{':
count = p_count(p);
if (EAT(',')) {
if (isdigit(PEEK())) {
count2 = p_count(p);
REQUIRE(count <= count2, REG_BADBR);
} else /* single number with comma */
count2 = INFINITY;
} else /* just a single number */
count2 = count;
repeat(p, pos, count, count2);
if (!EAT('}')) { /* error heuristics */
while (MORE() && PEEK() != '}')
NEXT();
REQUIRE(MORE(), REG_EBRACE);
SETERROR(REG_BADBR);
}
break;
}
 
if (!MORE())
return;
c = PEEK();
if (!( c == '*' || c == '+' || c == '?' ||
(c == '{' && MORE2() && isdigit(PEEK2())) ) )
return;
SETERROR(REG_BADRPT);
}
 
/*
- p_str - string (no metacharacters) "parser"
== static void p_str(register struct parse *p);
*/
static void
p_str(p)
register struct parse *p;
{
REQUIRE(MORE(), REG_EMPTY);
while (MORE())
ordinary(p, GETNEXT());
}
 
/*
- p_bre - BRE parser top level, anchoring and concatenation
== static void p_bre(register struct parse *p, register int end1, \
== register int end2);
* Giving end1 as OUT essentially eliminates the end1/end2 check.
*
* This implementation is a bit of a kludge, in that a trailing $ is first
* taken as an ordinary character and then revised to be an anchor. The
* only undesirable side effect is that '$' gets included as a character
* category in such cases. This is fairly harmless; not worth fixing.
* The amount of lookahead needed to avoid this kludge is excessive.
*/
static void
p_bre(p, end1, end2)
register struct parse *p;
register int end1; /* first terminating character */
register int end2; /* second terminating character */
{
register sopno start = HERE();
register int first = 1; /* first subexpression? */
register int wasdollar = 0;
 
if (EAT('^')) {
EMIT(OBOL, 0);
p->g->iflags |= USEBOL;
p->g->nbol++;
}
while (MORE() && !SEETWO(end1, end2)) {
wasdollar = p_simp_re(p, first);
first = 0;
}
if (wasdollar) { /* oops, that was a trailing anchor */
DROP(1);
EMIT(OEOL, 0);
p->g->iflags |= USEEOL;
p->g->neol++;
}
 
REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
}
 
/*
- p_simp_re - parse a simple RE, an atom possibly followed by a repetition
== static int p_simp_re(register struct parse *p, int starordinary);
*/
static int /* was the simple RE an unbackslashed $? */
p_simp_re(p, starordinary)
register struct parse *p;
int starordinary; /* is a leading * an ordinary character? */
{
register int c;
register int count;
register int count2;
register sopno pos;
register int i;
register sopno subno;
# define BACKSL (1<<CHAR_BIT)
 
pos = HERE(); /* repetion op, if any, covers from here */
 
assert(MORE()); /* caller should have ensured this */
c = GETNEXT();
if (c == '\\') {
REQUIRE(MORE(), REG_EESCAPE);
c = BACKSL | (unsigned char)GETNEXT();
}
switch (c) {
case '.':
if (p->g->cflags&REG_NEWLINE)
nonnewline(p);
else
EMIT(OANY, 0);
break;
case '[':
p_bracket(p);
break;
case BACKSL|'{':
SETERROR(REG_BADRPT);
break;
case BACKSL|'(':
p->g->nsub++;
subno = p->g->nsub;
if (subno < NPAREN)
p->pbegin[subno] = HERE();
EMIT(OLPAREN, subno);
/* the MORE here is an error heuristic */
if (MORE() && !SEETWO('\\', ')'))
p_bre(p, '\\', ')');
if (subno < NPAREN) {
p->pend[subno] = HERE();
assert(p->pend[subno] != 0);
}
EMIT(ORPAREN, subno);
REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
break;
case BACKSL|')': /* should not get here -- must be user */
case BACKSL|'}':
SETERROR(REG_EPAREN);
break;
case BACKSL|'1':
case BACKSL|'2':
case BACKSL|'3':
case BACKSL|'4':
case BACKSL|'5':
case BACKSL|'6':
case BACKSL|'7':
case BACKSL|'8':
case BACKSL|'9':
i = (c&~BACKSL) - '0';
assert(i < NPAREN);
if (p->pend[i] != 0) {
assert(i <= p->g->nsub);
EMIT(OBACK_, i);
assert(p->pbegin[i] != 0);
assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
assert(OP(p->strip[p->pend[i]]) == ORPAREN);
(void) dupl(p, p->pbegin[i]+1, p->pend[i]);
EMIT(O_BACK, i);
} else
SETERROR(REG_ESUBREG);
p->g->backrefs = 1;
break;
case '*':
REQUIRE(starordinary, REG_BADRPT);
/* FALLTHROUGH */
default:
ordinary(p, c &~ BACKSL);
break;
}
 
if (EAT('*')) { /* implemented as +? */
/* this case does not require the (y|) trick, noKLUDGE */
INSERT(OPLUS_, pos);
ASTERN(O_PLUS, pos);
INSERT(OQUEST_, pos);
ASTERN(O_QUEST, pos);
} else if (EATTWO('\\', '{')) {
count = p_count(p);
if (EAT(',')) {
if (MORE() && isdigit(PEEK())) {
count2 = p_count(p);
REQUIRE(count <= count2, REG_BADBR);
} else /* single number with comma */
count2 = INFINITY;
} else /* just a single number */
count2 = count;
repeat(p, pos, count, count2);
if (!EATTWO('\\', '}')) { /* error heuristics */
while (MORE() && !SEETWO('\\', '}'))
NEXT();
REQUIRE(MORE(), REG_EBRACE);
SETERROR(REG_BADBR);
}
} else if (c == (unsigned char)'$') /* $ (but not \$) ends it */
return(1);
 
return(0);
}
 
/*
- p_count - parse a repetition count
== static int p_count(register struct parse *p);
*/
static int /* the value */
p_count(p)
register struct parse *p;
{
register int count = 0;
register int ndigits = 0;
 
while (MORE() && isdigit(PEEK()) && count <= DUPMAX) {
count = count*10 + (GETNEXT() - '0');
ndigits++;
}
 
REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
return(count);
}
 
/*
- p_bracket - parse a bracketed character list
== static void p_bracket(register struct parse *p);
*
* Note a significant property of this code: if the allocset() did SETERROR,
* no set operations are done.
*/
static void
p_bracket(p)
register struct parse *p;
{
register char c;
register cset *cs = allocset(p);
register int invert = 0;
 
/* Dept of Truly Sickening Special-Case Kludges */
if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
EMIT(OBOW, 0);
NEXTn(6);
return;
}
if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
EMIT(OEOW, 0);
NEXTn(6);
return;
}
 
if (EAT('^'))
invert++; /* make note to invert set at end */
if (EAT(']'))
CHadd(cs, ']');
else if (EAT('-'))
CHadd(cs, '-');
while (MORE() && PEEK() != ']' && !SEETWO('-', ']'))
p_b_term(p, cs);
if (EAT('-'))
CHadd(cs, '-');
MUSTEAT(']', REG_EBRACK);
 
if (p->error != 0) /* don't mess things up further */
return;
 
if (p->g->cflags&REG_ICASE) {
register int i;
register int ci;
 
for (i = p->g->csetsize - 1; i >= 0; i--)
if (CHIN(cs, i) && isalpha(i)) {
ci = othercase(i);
if (ci != i)
CHadd(cs, ci);
}
if (cs->multis != NULL)
mccase(p, cs);
}
if (invert) {
register int i;
 
for (i = p->g->csetsize - 1; i >= 0; i--)
if (CHIN(cs, i))
CHsub(cs, i);
else
CHadd(cs, i);
if (p->g->cflags&REG_NEWLINE)
CHsub(cs, '\n');
if (cs->multis != NULL)
mcinvert(p, cs);
}
 
assert(cs->multis == NULL); /* xxx */
 
if (nch(p, cs) == 1) { /* optimize singleton sets */
ordinary(p, firstch(p, cs));
freeset(p, cs);
} else
EMIT(OANYOF, freezeset(p, cs));
}
 
/*
- p_b_term - parse one term of a bracketed character list
== static void p_b_term(register struct parse *p, register cset *cs);
*/
static void
p_b_term(p, cs)
register struct parse *p;
register cset *cs;
{
register char c;
register char start, finish;
register int i;
 
/* classify what we've got */
switch ((MORE()) ? PEEK() : '\0') {
case '[':
c = (MORE2()) ? PEEK2() : '\0';
break;
case '-':
SETERROR(REG_ERANGE);
return; /* NOTE RETURN */
break;
default:
c = '\0';
break;
}
 
switch (c) {
case ':': /* character class */
NEXT2();
REQUIRE(MORE(), REG_EBRACK);
c = PEEK();
REQUIRE(c != '-' && c != ']', REG_ECTYPE);
p_b_cclass(p, cs);
REQUIRE(MORE(), REG_EBRACK);
REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
break;
case '=': /* equivalence class */
NEXT2();
REQUIRE(MORE(), REG_EBRACK);
c = PEEK();
REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
p_b_eclass(p, cs);
REQUIRE(MORE(), REG_EBRACK);
REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
break;
default: /* symbol, ordinary character, or range */
/* xxx revision needed for multichar stuff */
start = p_b_symbol(p);
if (SEE('-') && MORE2() && PEEK2() != ']') {
/* range */
NEXT();
if (EAT('-'))
finish = '-';
else
finish = p_b_symbol(p);
} else
finish = start;
/* xxx what about signed chars here... */
REQUIRE(start <= finish, REG_ERANGE);
for (i = start; i <= finish; i++)
CHadd(cs, i);
break;
}
}
 
/*
- p_b_cclass - parse a character-class name and deal with it
== static void p_b_cclass(register struct parse *p, register cset *cs);
*/
static void
p_b_cclass(p, cs)
register struct parse *p;
register cset *cs;
{
register char *sp = p->next;
register struct cclass *cp;
register size_t len;
register char *u;
register char c;
 
while (MORE() && isalpha(PEEK()))
NEXT();
len = p->next - sp;
for (cp = cclasses; cp->name != NULL; cp++)
if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
break;
if (cp->name == NULL) {
/* oops, didn't find it */
SETERROR(REG_ECTYPE);
return;
}
 
u = cp->chars;
while ((c = *u++) != '\0')
CHadd(cs, c);
for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
MCadd(p, cs, u);
}
 
/*
- p_b_eclass - parse an equivalence-class name and deal with it
== static void p_b_eclass(register struct parse *p, register cset *cs);
*
* This implementation is incomplete. xxx
*/
static void
p_b_eclass(p, cs)
register struct parse *p;
register cset *cs;
{
register char c;
 
c = p_b_coll_elem(p, '=');
CHadd(cs, c);
}
 
/*
- p_b_symbol - parse a character or [..]ed multicharacter collating symbol
== static char p_b_symbol(register struct parse *p);
*/
static char /* value of symbol */
p_b_symbol(p)
register struct parse *p;
{
register char value;
 
REQUIRE(MORE(), REG_EBRACK);
if (!EATTWO('[', '.'))
return(GETNEXT());
 
/* collating symbol */
value = p_b_coll_elem(p, '.');
REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
return(value);
}
 
/*
- p_b_coll_elem - parse a collating-element name and look it up
== static char p_b_coll_elem(register struct parse *p, int endc);
*/
static char /* value of collating element */
p_b_coll_elem(p, endc)
register struct parse *p;
int endc; /* name ended by endc,']' */
{
register char *sp = p->next;
register struct cname *cp;
register int len;
register char c;
 
while (MORE() && !SEETWO(endc, ']'))
NEXT();
if (!MORE()) {
SETERROR(REG_EBRACK);
return(0);
}
len = p->next - sp;
for (cp = cnames; cp->name != NULL; cp++)
if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
return(cp->code); /* known name */
if (len == 1)
return(*sp); /* single character */
SETERROR(REG_ECOLLATE); /* neither */
return(0);
}
 
/*
- othercase - return the case counterpart of an alphabetic
== static char othercase(int ch);
*/
static char /* if no counterpart, return ch */
othercase(ch)
int ch;
{
assert(isalpha(ch));
if (isupper(ch))
return(tolower(ch));
else if (islower(ch))
return(toupper(ch));
else /* peculiar, but could happen */
return(ch);
}
 
/*
- bothcases - emit a dualcase version of a two-case character
== static void bothcases(register struct parse *p, int ch);
*
* Boy, is this implementation ever a kludge...
*/
static void
bothcases(p, ch)
register struct parse *p;
int ch;
{
register char *oldnext = p->next;
register char *oldend = p->end;
char bracket[3];
 
assert(othercase(ch) != ch); /* p_bracket() would recurse */
p->next = bracket;
p->end = bracket+2;
bracket[0] = ch;
bracket[1] = ']';
bracket[2] = '\0';
p_bracket(p);
assert(p->next == bracket+2);
p->next = oldnext;
p->end = oldend;
}
 
/*
- ordinary - emit an ordinary character
== static void ordinary(register struct parse *p, register int ch);
*/
static void
ordinary(p, ch)
register struct parse *p;
register int ch;
{
register cat_t *cap = p->g->categories;
 
if ((p->g->cflags&REG_ICASE) && isalpha(ch) && othercase(ch) != ch)
bothcases(p, ch);
else {
EMIT(OCHAR, (unsigned char)ch);
if (cap[ch] == 0)
cap[ch] = p->g->ncategories++;
}
}
 
/*
- nonnewline - emit REG_NEWLINE version of OANY
== static void nonnewline(register struct parse *p);
*
* Boy, is this implementation ever a kludge...
*/
static void
nonnewline(p)
register struct parse *p;
{
register char *oldnext = p->next;
register char *oldend = p->end;
char bracket[4];
 
p->next = bracket;
p->end = bracket+3;
bracket[0] = '^';
bracket[1] = '\n';
bracket[2] = ']';
bracket[3] = '\0';
p_bracket(p);
assert(p->next == bracket+3);
p->next = oldnext;
p->end = oldend;
}
 
/*
- repeat - generate code for a bounded repetition, recursively if needed
== static void repeat(register struct parse *p, sopno start, int from, int to);
*/
static void
repeat(p, start, from, to)
register struct parse *p;
sopno start; /* operand from here to end of strip */
int from; /* repeated from this number */
int to; /* to this number of times (maybe INFINITY) */
{
register sopno finish = HERE();
# define N 2
# define INF 3
# define REP(f, t) ((f)*8 + (t))
# define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
register sopno copy;
 
if (p->error != 0) /* head off possible runaway recursion */
return;
 
assert(from <= to);
 
switch (REP(MAP(from), MAP(to))) {
case REP(0, 0): /* must be user doing this */
DROP(finish-start); /* drop the operand */
break;
case REP(0, 1): /* as x{1,1}? */
case REP(0, N): /* as x{1,n}? */
case REP(0, INF): /* as x{1,}? */
/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
INSERT(OCH_, start); /* offset is wrong... */
repeat(p, start+1, 1, to);
ASTERN(OOR1, start);
AHEAD(start); /* ... fix it */
EMIT(OOR2, 0);
AHEAD(THERE());
ASTERN(O_CH, THERETHERE());
break;
case REP(1, 1): /* trivial case */
/* done */
break;
case REP(1, N): /* as x?x{1,n-1} */
/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
INSERT(OCH_, start);
ASTERN(OOR1, start);
AHEAD(start);
EMIT(OOR2, 0); /* offset very wrong... */
AHEAD(THERE()); /* ...so fix it */
ASTERN(O_CH, THERETHERE());
copy = dupl(p, start+1, finish+1);
assert(copy == finish+4);
repeat(p, copy, 1, to-1);
break;
case REP(1, INF): /* as x+ */
INSERT(OPLUS_, start);
ASTERN(O_PLUS, start);
break;
case REP(N, N): /* as xx{m-1,n-1} */
copy = dupl(p, start, finish);
repeat(p, copy, from-1, to-1);
break;
case REP(N, INF): /* as xx{n-1,INF} */
copy = dupl(p, start, finish);
repeat(p, copy, from-1, to);
break;
default: /* "can't happen" */
SETERROR(REG_ASSERT); /* just in case */
break;
}
}
 
/*
- seterr - set an error condition
== static int seterr(register struct parse *p, int e);
*/
static int /* useless but makes type checking happy */
seterr(p, e)
register struct parse *p;
int e;
{
if (p->error == 0) /* keep earliest error condition */
p->error = e;
p->next = nuls; /* try to bring things to a halt */
p->end = nuls;
return(0); /* make the return value well-defined */
}
 
/*
- allocset - allocate a set of characters for []
== static cset *allocset(register struct parse *p);
*/
static cset *
allocset(p)
register struct parse *p;
{
register int no = p->g->ncsets++;
register size_t nc;
register size_t nbytes;
register cset *cs;
register size_t css = (size_t)p->g->csetsize;
register int i;
 
if (no >= p->ncsalloc) { /* need another column of space */
p->ncsalloc += CHAR_BIT;
nc = p->ncsalloc;
assert(nc % CHAR_BIT == 0);
nbytes = nc / CHAR_BIT * css;
if (p->g->sets == NULL)
p->g->sets = (cset *)malloc(nc * sizeof(cset));
else
p->g->sets = (cset *)realloc((char *)p->g->sets,
nc * sizeof(cset));
if (p->g->setbits == NULL)
p->g->setbits = (uch *)malloc(nbytes);
else {
p->g->setbits = (uch *)realloc((char *)p->g->setbits,
nbytes);
/* xxx this isn't right if setbits is now NULL */
for (i = 0; i < no; i++)
p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
}
if (p->g->sets != NULL && p->g->setbits != NULL)
(void) memset((char *)p->g->setbits + (nbytes - css),
0, css);
else {
no = 0;
SETERROR(REG_ESPACE);
/* caller's responsibility not to do set ops */
}
}
 
assert(p->g->sets != NULL); /* xxx */
cs = &p->g->sets[no];
cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
cs->mask = 1 << ((no) % CHAR_BIT);
cs->hash = 0;
cs->smultis = 0;
cs->multis = NULL;
 
return(cs);
}
 
/*
- freeset - free a now-unused set
== static void freeset(register struct parse *p, register cset *cs);
*/
static void
freeset(p, cs)
register struct parse *p;
register cset *cs;
{
register int i;
register cset *top = &p->g->sets[p->g->ncsets];
register size_t css = (size_t)p->g->csetsize;
 
for (i = 0; i < css; i++)
CHsub(cs, i);
if (cs == top-1) /* recover only the easy case */
p->g->ncsets--;
}
 
/*
- freezeset - final processing on a set of characters
== static int freezeset(register struct parse *p, register cset *cs);
*
* The main task here is merging identical sets. This is usually a waste
* of time (although the hash code minimizes the overhead), but can win
* big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash
* is done using addition rather than xor -- all ASCII [aA] sets xor to
* the same value!
*/
static int /* set number */
freezeset(p, cs)
register struct parse *p;
register cset *cs;
{
register uch h = cs->hash;
register int i;
register cset *top = &p->g->sets[p->g->ncsets];
register cset *cs2;
register size_t css = (size_t)p->g->csetsize;
 
/* look for an earlier one which is the same */
for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
if (cs2->hash == h && cs2 != cs) {
/* maybe */
for (i = 0; i < css; i++)
if (!!CHIN(cs2, i) != !!CHIN(cs, i))
break; /* no */
if (i == css)
break; /* yes */
}
 
if (cs2 < top) { /* found one */
freeset(p, cs);
cs = cs2;
}
 
return((int)(cs - p->g->sets));
}
 
/*
- firstch - return first character in a set (which must have at least one)
== static int firstch(register struct parse *p, register cset *cs);
*/
static int /* character; there is no "none" value */
firstch(p, cs)
register struct parse *p;
register cset *cs;
{
register int i;
register size_t css = (size_t)p->g->csetsize;
 
for (i = 0; i < css; i++)
if (CHIN(cs, i))
return((char)i);
assert(never);
return(0); /* arbitrary */
}
 
/*
- nch - number of characters in a set
== static int nch(register struct parse *p, register cset *cs);
*/
static int
nch(p, cs)
register struct parse *p;
register cset *cs;
{
register int i;
register size_t css = (size_t)p->g->csetsize;
register int n = 0;
 
for (i = 0; i < css; i++)
if (CHIN(cs, i))
n++;
return(n);
}
 
/*
- mcadd - add a collating element to a cset
== static void mcadd(register struct parse *p, register cset *cs, \
== register char *cp);
*/
static void
mcadd(p, cs, cp)
register struct parse *p;
register cset *cs;
register char *cp;
{
register size_t oldend = cs->smultis;
 
cs->smultis += strlen(cp) + 1;
if (cs->multis == NULL)
cs->multis = malloc(cs->smultis);
else
cs->multis = realloc(cs->multis, cs->smultis);
if (cs->multis == NULL) {
SETERROR(REG_ESPACE);
return;
}
 
(void) strcpy(cs->multis + oldend - 1, cp);
cs->multis[cs->smultis - 1] = '\0';
}
 
/*
- mcsub - subtract a collating element from a cset
== static void mcsub(register cset *cs, register char *cp);
*/
static void
mcsub(cs, cp)
register cset *cs;
register char *cp;
{
register char *fp = mcfind(cs, cp);
register size_t len = strlen(fp);
 
assert(fp != NULL);
(void) memmove(fp, fp + len + 1,
cs->smultis - (fp + len + 1 - cs->multis));
cs->smultis -= len;
 
if (cs->smultis == 0) {
free(cs->multis);
cs->multis = NULL;
return;
}
 
cs->multis = realloc(cs->multis, cs->smultis);
assert(cs->multis != NULL);
}
 
/*
- mcin - is a collating element in a cset?
== static int mcin(register cset *cs, register char *cp);
*/
static int
mcin(cs, cp)
register cset *cs;
register char *cp;
{
return(mcfind(cs, cp) != NULL);
}
 
/*
- mcfind - find a collating element in a cset
== static char *mcfind(register cset *cs, register char *cp);
*/
static char *
mcfind(cs, cp)
register cset *cs;
register char *cp;
{
register char *p;
 
if (cs->multis == NULL)
return(NULL);
for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
if (strcmp(cp, p) == 0)
return(p);
return(NULL);
}
 
/*
- mcinvert - invert the list of collating elements in a cset
== static void mcinvert(register struct parse *p, register cset *cs);
*
* This would have to know the set of possibilities. Implementation
* is deferred.
*/
static void
mcinvert(p, cs)
register struct parse *p;
register cset *cs;
{
assert(cs->multis == NULL); /* xxx */
}
 
/*
- mccase - add case counterparts of the list of collating elements in a cset
== static void mccase(register struct parse *p, register cset *cs);
*
* This would have to know the set of possibilities. Implementation
* is deferred.
*/
static void
mccase(p, cs)
register struct parse *p;
register cset *cs;
{
assert(cs->multis == NULL); /* xxx */
}
 
/*
- isinsets - is this character in any sets?
== static int isinsets(register struct re_guts *g, int c);
*/
static int /* predicate */
isinsets(g, c)
register struct re_guts *g;
int c;
{
register uch *col;
register int i;
register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
register unsigned uc = (unsigned char)c;
 
for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
if (col[uc] != 0)
return(1);
return(0);
}
 
/*
- samesets - are these two characters in exactly the same sets?
== static int samesets(register struct re_guts *g, int c1, int c2);
*/
static int /* predicate */
samesets(g, c1, c2)
register struct re_guts *g;
int c1;
int c2;
{
register uch *col;
register int i;
register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
register unsigned uc1 = (unsigned char)c1;
register unsigned uc2 = (unsigned char)c2;
 
for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
if (col[uc1] != col[uc2])
return(0);
return(1);
}
 
/*
- categorize - sort out character categories
== static void categorize(struct parse *p, register struct re_guts *g);
*/
static void
categorize(p, g)
struct parse *p;
register struct re_guts *g;
{
register cat_t *cats = g->categories;
register int c;
register int c2;
register cat_t cat;
 
/* avoid making error situations worse */
if (p->error != 0)
return;
 
for (c = CHAR_MIN; c <= CHAR_MAX; c++)
if (cats[c] == 0 && isinsets(g, c)) {
cat = g->ncategories++;
cats[c] = cat;
for (c2 = c+1; c2 <= CHAR_MAX; c2++)
if (cats[c2] == 0 && samesets(g, c, c2))
cats[c2] = cat;
}
}
 
/*
- dupl - emit a duplicate of a bunch of sops
== static sopno dupl(register struct parse *p, sopno start, sopno finish);
*/
static sopno /* start of duplicate */
dupl(p, start, finish)
register struct parse *p;
sopno start; /* from here */
sopno finish; /* to this less one */
{
register sopno ret = HERE();
register sopno len = finish - start;
 
assert(finish >= start);
if (len == 0)
return(ret);
enlarge(p, p->ssize + len); /* this many unexpected additions */
assert(p->ssize >= p->slen + len);
(void) memcpy((char *)(p->strip + p->slen),
(char *)(p->strip + start), (size_t)len*sizeof(sop));
p->slen += len;
return(ret);
}
 
/*
- doemit - emit a strip operator
== static void doemit(register struct parse *p, sop op, size_t opnd);
*
* It might seem better to implement this as a macro with a function as
* hard-case backup, but it's just too big and messy unless there are
* some changes to the data structures. Maybe later.
*/
static void
doemit(p, op, opnd)
register struct parse *p;
sop op;
size_t opnd;
{
/* avoid making error situations worse */
if (p->error != 0)
return;
 
/* deal with oversize operands ("can't happen", more or less) */
assert(opnd < 1<<OPSHIFT);
 
/* deal with undersized strip */
if (p->slen >= p->ssize)
enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */
assert(p->slen < p->ssize);
 
/* finally, it's all reduced to the easy case */
p->strip[p->slen++] = SOP(op, opnd);
}
 
/*
- doinsert - insert a sop into the strip
== static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos);
*/
static void
doinsert(p, op, opnd, pos)
register struct parse *p;
sop op;
size_t opnd;
sopno pos;
{
register sopno sn;
register sop s;
register int i;
 
/* avoid making error situations worse */
if (p->error != 0)
return;
 
sn = HERE();
EMIT(op, opnd); /* do checks, ensure space */
assert(HERE() == sn+1);
s = p->strip[sn];
 
/* adjust paren pointers */
assert(pos > 0);
for (i = 1; i < NPAREN; i++) {
if (p->pbegin[i] >= pos) {
p->pbegin[i]++;
}
if (p->pend[i] >= pos) {
p->pend[i]++;
}
}
 
memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
(HERE()-pos-1)*sizeof(sop));
p->strip[pos] = s;
}
 
/*
- dofwd - complete a forward reference
== static void dofwd(register struct parse *p, sopno pos, sop value);
*/
static void
dofwd(p, pos, value)
register struct parse *p;
register sopno pos;
sop value;
{
/* avoid making error situations worse */
if (p->error != 0)
return;
 
assert(value < 1<<OPSHIFT);
p->strip[pos] = OP(p->strip[pos]) | value;
}
 
/*
- enlarge - enlarge the strip
== static void enlarge(register struct parse *p, sopno size);
*/
static void
enlarge(p, size)
register struct parse *p;
register sopno size;
{
register sop *sp;
 
if (p->ssize >= size)
return;
 
sp = (sop *)realloc(p->strip, size*sizeof(sop));
if (sp == NULL) {
SETERROR(REG_ESPACE);
return;
}
p->strip = sp;
p->ssize = size;
}
 
/*
- stripsnug - compact the strip
== static void stripsnug(register struct parse *p, register struct re_guts *g);
*/
static void
stripsnug(p, g)
register struct parse *p;
register struct re_guts *g;
{
g->nstates = p->slen;
g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
if (g->strip == NULL) {
SETERROR(REG_ESPACE);
g->strip = p->strip;
}
}
 
/*
- findmust - fill in must and mlen with longest mandatory literal string
== static void findmust(register struct parse *p, register struct re_guts *g);
*
* This algorithm could do fancy things like analyzing the operands of |
* for common subsequences. Someday. This code is simple and finds most
* of the interesting cases.
*
* Note that must and mlen got initialized during setup.
*/
static void
findmust(p, g)
struct parse *p;
register struct re_guts *g;
{
register sop *scan;
sop *start;
register sop *newstart;
register sopno newlen;
register sop s;
register char *cp;
register sopno i;
 
/* avoid making error situations worse */
if (p->error != 0)
return;
 
/* find the longest OCHAR sequence in strip */
newlen = 0;
scan = g->strip + 1;
do {
s = *scan++;
switch (OP(s)) {
case OCHAR: /* sequence member */
if (newlen == 0) /* new sequence */
newstart = scan - 1;
newlen++;
break;
case OPLUS_: /* things that don't break one */
case OLPAREN:
case ORPAREN:
break;
case OQUEST_: /* things that must be skipped */
case OCH_:
scan--;
do {
scan += OPND(s);
s = *scan;
/* assert() interferes w debug printouts */
if (OP(s) != O_QUEST && OP(s) != O_CH &&
OP(s) != OOR2) {
g->iflags |= BAD;
return;
}
} while (OP(s) != O_QUEST && OP(s) != O_CH);
/* fallthrough */
default: /* things that break a sequence */
if (newlen > g->mlen) { /* ends one */
start = newstart;
g->mlen = newlen;
}
newlen = 0;
break;
}
} while (OP(s) != OEND);
 
if (g->mlen == 0) /* there isn't one */
return;
 
/* turn it into a character string */
g->must = malloc((size_t)g->mlen + 1);
if (g->must == NULL) { /* argh; just forget it */
g->mlen = 0;
return;
}
cp = g->must;
scan = start;
for (i = g->mlen; i > 0; i--) {
while (OP(s = *scan++) != OCHAR)
continue;
assert(cp < g->must + g->mlen);
*cp++ = (char)OPND(s);
}
assert(cp == g->must + g->mlen);
*cp++ = '\0'; /* just on general principles */
}
 
/*
- pluscount - count + nesting
== static sopno pluscount(register struct parse *p, register struct re_guts *g);
*/
static sopno /* nesting depth */
pluscount(p, g)
struct parse *p;
register struct re_guts *g;
{
register sop *scan;
register sop s;
register sopno plusnest = 0;
register sopno maxnest = 0;
 
if (p->error != 0)
return(0); /* there may not be an OEND */
 
scan = g->strip + 1;
do {
s = *scan++;
switch (OP(s)) {
case OPLUS_:
plusnest++;
break;
case O_PLUS:
if (plusnest > maxnest)
maxnest = plusnest;
plusnest--;
break;
}
} while (OP(s) != OEND);
if (plusnest != 0)
g->iflags |= BAD;
return(maxnest);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regcomp.ih
0,0 → 1,51
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
 
/* === regcomp.c === */
static void p_ere (register struct parse *p, int stop);
static void p_ere_exp (register struct parse *p);
static void p_str (register struct parse *p);
static void p_bre (register struct parse *p, register int end1, register int end2);
static int p_simp_re (register struct parse *p, int starordinary);
static int p_count (register struct parse *p);
static void p_bracket (register struct parse *p);
static void p_b_term (register struct parse *p, register cset *cs);
static void p_b_cclass (register struct parse *p, register cset *cs);
static void p_b_eclass (register struct parse *p, register cset *cs);
static char p_b_symbol (register struct parse *p);
static char p_b_coll_elem (register struct parse *p, int endc);
static char othercase (int ch);
static void bothcases (register struct parse *p, int ch);
static void ordinary (register struct parse *p, register int ch);
static void nonnewline (register struct parse *p);
static void repeat (register struct parse *p, sopno start, int from, int to);
static int seterr (register struct parse *p, int e);
static cset *allocset (register struct parse *p);
static void freeset (register struct parse *p, register cset *cs);
static int freezeset (register struct parse *p, register cset *cs);
static int firstch (register struct parse *p, register cset *cs);
static int nch (register struct parse *p, register cset *cs);
static void mcadd (register struct parse *p, register cset *cs, register char *cp);
static void mcsub (register cset *cs, register char *cp);
static int mcin (register cset *cs, register char *cp);
static char *mcfind (register cset *cs, register char *cp);
static void mcinvert (register struct parse *p, register cset *cs);
static void mccase (register struct parse *p, register cset *cs);
static int isinsets (register struct re_guts *g, int c);
static int samesets (register struct re_guts *g, int c1, int c2);
static void categorize (struct parse *p, register struct re_guts *g);
static sopno dupl (register struct parse *p, sopno start, sopno finish);
static void doemit (register struct parse *p, sop op, size_t opnd);
static void doinsert (register struct parse *p, sop op, size_t opnd, sopno pos);
static void dofwd (register struct parse *p, sopno pos, sop value);
static void enlarge (register struct parse *p, sopno size);
static void stripsnug (register struct parse *p, register struct re_guts *g);
static void findmust (register struct parse *p, register struct re_guts *g);
static sopno pluscount (register struct parse *p, register struct re_guts *g);
 
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regerror.c
0,0 → 1,127
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include <regex.h>
 
#include "utils.h"
#include "regerror.ih"
 
/*
= #define REG_NOMATCH 1
= #define REG_BADPAT 2
= #define REG_ECOLLATE 3
= #define REG_ECTYPE 4
= #define REG_EESCAPE 5
= #define REG_ESUBREG 6
= #define REG_EBRACK 7
= #define REG_EPAREN 8
= #define REG_EBRACE 9
= #define REG_BADBR 10
= #define REG_ERANGE 11
= #define REG_ESPACE 12
= #define REG_BADRPT 13
= #define REG_EMPTY 14
= #define REG_ASSERT 15
= #define REG_INVARG 16
= #define REG_ATOI 255 // convert name to number (!)
= #define REG_ITOA 0400 // convert number to name (!)
*/
static struct rerr {
int code;
char *name;
char *explain;
} rerrs[] = {
REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match",
REG_BADPAT, "REG_BADPAT", "invalid regular expression",
REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element",
REG_ECTYPE, "REG_ECTYPE", "invalid character class",
REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)",
REG_ESUBREG, "REG_ESUBREG", "invalid backreference number",
REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced",
REG_EPAREN, "REG_EPAREN", "parentheses not balanced",
REG_EBRACE, "REG_EBRACE", "braces not balanced",
REG_BADBR, "REG_BADBR", "invalid repetition count(s)",
REG_ERANGE, "REG_ERANGE", "invalid character range",
REG_ESPACE, "REG_ESPACE", "out of memory",
REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid",
REG_EMPTY, "REG_EMPTY", "empty (sub)expression",
REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug",
REG_INVARG, "REG_INVARG", "invalid argument to regex routine",
0, "", "*** unknown regexp error code ***",
};
 
/*
- regerror - the interface to error numbers
= extern size_t regerror(int, const regex_t *, char *, size_t);
*/
/* ARGSUSED */
size_t
regerror(errcode, preg, errbuf, errbuf_size)
int errcode;
const regex_t *preg;
char *errbuf;
size_t errbuf_size;
{
register struct rerr *r;
register size_t len;
register int target = errcode &~ REG_ITOA;
register char *s;
char convbuf[50];
 
if (errcode == REG_ATOI)
s = regatoi(preg, convbuf);
else {
for (r = rerrs; r->code != 0; r++)
if (r->code == target)
break;
if (errcode&REG_ITOA) {
if (r->code != 0)
(void) strcpy(convbuf, r->name);
else
sprintf(convbuf, "REG_0x%x", target);
assert(strlen(convbuf) < sizeof(convbuf));
s = convbuf;
} else
s = r->explain;
}
 
len = strlen(s) + 1;
if (errbuf_size > 0) {
if (errbuf_size > len)
(void) strcpy(errbuf, s);
else {
(void) strncpy(errbuf, s, errbuf_size-1);
errbuf[errbuf_size-1] = '\0';
}
}
 
return(len);
}
 
/*
- regatoi - internal routine to implement REG_ATOI
== static char *regatoi(const regex_t *preg, char *localbuf);
*/
static char *
regatoi(preg, localbuf)
const regex_t *preg;
char *localbuf;
{
register struct rerr *r;
register size_t siz;
register char *p;
 
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)
break;
if (r->code == 0)
return("0");
 
sprintf(localbuf, "%d", r->code);
return(localbuf);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regerror.ih
0,0 → 1,12
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
 
/* === regerror.c === */
static char *regatoi (const regex_t *preg, char *localbuf);
 
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regex2.h
0,0 → 1,135
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* First, the stuff that ends up in the outside-world include file
= typedef off_t regoff_t;
= typedef struct {
= int re_magic;
= size_t re_nsub; // number of parenthesized subexpressions
= const char *re_endp; // end pointer for REG_PEND
= struct re_guts *re_g; // none of your business :-)
= } regex_t;
= typedef struct {
= regoff_t rm_so; // start of match
= regoff_t rm_eo; // end of match
= } regmatch_t;
*/
/*
* internals of regex_t
*/
#define MAGIC1 ((('r'^0200)<<8) | 'e')
 
/*
* The internal representation is a *strip*, a sequence of
* operators ending with an endmarker. (Some terminology etc. is a
* historical relic of earlier versions which used multiple strips.)
* Certain oddities in the representation are there to permit running
* the machinery backwards; in particular, any deviation from sequential
* flow must be marked at both its source and its destination. Some
* fine points:
*
* - OPLUS_ and O_PLUS are *inside* the loop they create.
* - OQUEST_ and O_QUEST are *outside* the bypass they create.
* - OCH_ and O_CH are *outside* the multi-way branch they create, while
* OOR1 and OOR2 are respectively the end and the beginning of one of
* the branches. Note that there is an implicit OOR2 following OCH_
* and an implicit OOR1 preceding O_CH.
*
* In state representations, an operator's bit is on to signify a state
* immediately *preceding* "execution" of that operator.
*/
typedef unsigned long sop; /* strip operator */
typedef long sopno;
#define OPRMASK 0xf8000000
#define OPDMASK 0x07ffffff
#define OPSHIFT ((unsigned)27)
#define OP(n) ((n)&OPRMASK)
#define OPND(n) ((n)&OPDMASK)
#define SOP(op, opnd) ((op)|(opnd))
/* operators meaning operand */
/* (back, fwd are offsets) */
#define OEND (1<<OPSHIFT) /* endmarker - */
#define OCHAR (2<<OPSHIFT) /* character unsigned char */
#define OBOL (3<<OPSHIFT) /* left anchor - */
#define OEOL (4<<OPSHIFT) /* right anchor - */
#define OANY (5<<OPSHIFT) /* . - */
#define OANYOF (6<<OPSHIFT) /* [...] set number */
#define OBACK_ (7<<OPSHIFT) /* begin \d paren number */
#define O_BACK (8<<OPSHIFT) /* end \d paren number */
#define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */
#define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */
#define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */
#define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */
#define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */
#define ORPAREN (14<<OPSHIFT) /* ) back to ( */
#define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */
#define OOR1 (16<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
#define OOR2 (17<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
#define O_CH (18<<OPSHIFT) /* end choice back to OOR1 */
#define OBOW (19<<OPSHIFT) /* begin word - */
#define OEOW (20<<OPSHIFT) /* end word - */
 
/*
* Structure for [] character-set representation. Character sets are
* done as bit vectors, grouped 8 to a byte vector for compactness.
* The individual set therefore has both a pointer to the byte vector
* and a mask to pick out the relevant bit of each byte. A hash code
* simplifies testing whether two sets could be identical.
*
* This will get trickier for multicharacter collating elements. As
* preliminary hooks for dealing with such things, we also carry along
* a string of multi-character elements, and decide the size of the
* vectors at run time.
*/
typedef struct {
uch *ptr; /* -> uch [csetsize] */
uch mask; /* bit within array */
uch hash; /* hash code */
size_t smultis;
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
} cset;
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
#define MCin(p, cs, cp) mcin(p, cs, cp)
 
/* stuff for character categories */
typedef unsigned char cat_t;
 
/*
* main compiled-expression structure
*/
struct re_guts {
int magic;
# define MAGIC2 ((('R'^0200)<<8)|'E')
sop *strip; /* malloced area for strip */
int csetsize; /* number of bits in a cset vector */
int ncsets; /* number of csets in use */
cset *sets; /* -> cset [ncsets] */
uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
int cflags; /* copy of regcomp() cflags argument */
sopno nstates; /* = number of sops */
sopno firststate; /* the initial OEND (normally 0) */
sopno laststate; /* the final OEND */
int iflags; /* internal flags */
# define USEBOL 01 /* used ^ */
# define USEEOL 02 /* used $ */
# define BAD 04 /* something wrong */
int nbol; /* number of ^ used */
int neol; /* number of $ used */
int ncategories; /* how many character categories */
cat_t *categories; /* ->catspace[-CHAR_MIN] */
char *must; /* match must contain this string */
int mlen; /* length of must */
size_t nsub; /* copy of re_nsub */
int backrefs; /* does it use back references? */
sopno nplus; /* how deep does it nest +s? */
/* catspace must be last */
cat_t catspace[1]; /* actually [NC] */
};
 
/* misc utilities */
#define OUT (CHAR_MAX+1) /* a non-character value */
#define ISWORD(c) (isalnum(c) || (c) == '_')
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regexec.c
0,0 → 1,139
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* the outer shell of regexec()
*
* This file includes engine.c *twice*, after muchos fiddling with the
* macros that code uses. This lets the same code operate on two different
* representations for state sets.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <regex.h>
 
#include "utils.h"
#include "regex2.h"
 
static int nope = 0; /* for use in asserts; shuts lint up */
 
/* macros for manipulating states, small version */
#define states long
#define states1 states /* for later use in regexec() decision */
#define CLEAR(v) ((v) = 0)
#define SET0(v, n) ((v) &= ~(1 << (n)))
#define SET1(v, n) ((v) |= 1 << (n))
#define ISSET(v, n) ((v) & (1 << (n)))
#define ASSIGN(d, s) ((d) = (s))
#define EQ(a, b) ((a) == (b))
#define STATEVARS int dummy /* dummy version */
#define STATESETUP(m, n) /* nothing */
#define STATETEARDOWN(m) /* nothing */
#define SETUP(v) ((v) = 0)
#define onestate int
#define INIT(o, n) ((o) = (unsigned)1 << (n))
#define INC(o) ((o) <<= 1)
#define ISSTATEIN(v, o) ((v) & (o))
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n))
#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
/* function names */
#define SNAMES /* engine.c looks after details */
 
#include "engine.c"
 
/* now undo things */
#undef states
#undef CLEAR
#undef SET0
#undef SET1
#undef ISSET
#undef ASSIGN
#undef EQ
#undef STATEVARS
#undef STATESETUP
#undef STATETEARDOWN
#undef SETUP
#undef onestate
#undef INIT
#undef INC
#undef ISSTATEIN
#undef FWD
#undef BACK
#undef ISSETBACK
#undef SNAMES
 
/* macros for manipulating states, large version */
#define states char *
#define CLEAR(v) memset(v, 0, m->g->nstates)
#define SET0(v, n) ((v)[n] = 0)
#define SET1(v, n) ((v)[n] = 1)
#define ISSET(v, n) ((v)[n])
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
#define STATEVARS int vn; char *space
#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
if ((m)->space == NULL) return(REG_ESPACE); \
(m)->vn = 0; }
#define STATETEARDOWN(m) { free((m)->space); }
#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
#define onestate int
#define INIT(o, n) ((o) = (n))
#define INC(o) ((o)++)
#define ISSTATEIN(v, o) ((v)[o])
/* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */
#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
#define ISSETBACK(v, n) ((v)[here - (n)])
/* function names */
#define LNAMES /* flag */
 
#include "engine.c"
 
/*
- regexec - interface for matching
= extern int regexec(const regex_t *, const char *, size_t, \
= regmatch_t [], int);
= #define REG_NOTBOL 00001
= #define REG_NOTEOL 00002
= #define REG_STARTEND 00004
= #define REG_TRACE 00400 // tracing of execution
= #define REG_LARGE 01000 // force large representation
= #define REG_BACKR 02000 // force use of backref code
*
* We put this here so we can exploit knowledge of the state representation
* when choosing which matcher to call. Also, by this point the matchers
* have been prototyped.
*/
int /* 0 success, REG_NOMATCH failure */
regexec(preg, string, nmatch, pmatch, eflags)
const regex_t *preg;
const char *string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
{
register struct re_guts *g = preg->re_g;
#ifdef REDEBUG
# define GOODFLAGS(f) (f)
#else
# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
#endif
 
if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
return(REG_BADPAT);
assert(!(g->iflags&BAD));
if (g->iflags&BAD) /* backstop for no-debug case */
return(REG_BADPAT);
eflags = GOODFLAGS(eflags);
 
if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/regfree.c
0,0 → 1,38
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
 
#include "utils.h"
#include "regex2.h"
 
/*
- regfree - free everything
= extern void regfree(regex_t *);
*/
void
regfree(preg)
regex_t *preg;
{
register struct re_guts *g;
 
if (preg->re_magic != MAGIC1) /* oops */
return; /* nice to complain, but hard */
 
g = preg->re_g;
if (g == NULL || g->magic != MAGIC2) /* oops again */
return;
preg->re_magic = 0; /* mark it invalid */
g->magic = 0; /* mark it invalid */
 
if (g->strip != NULL)
free((char *)g->strip);
if (g->sets != NULL)
free((char *)g->sets);
if (g->setbits != NULL)
free((char *)g->setbits);
if (g->must != NULL)
free(g->must);
free((char *)g);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/split.c
0,0 → 1,317
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
 
/*
- split - divide a string into fields, like awk split()
= int split(char *string, char *fields[], int nfields, char *sep);
*/
int /* number of fields, including overflow */
split(string, fields, nfields, sep)
char *string;
char *fields[]; /* list is not NULL-terminated */
int nfields; /* number of entries available in fields[] */
char *sep; /* "" white, "c" single char, "ab" [ab]+ */
{
register char *p = string;
register char c; /* latest character */
register char sepc = sep[0];
register char sepc2;
register int fn;
register char **fp = fields;
register char *sepp;
register int trimtrail;
 
/* white space */
if (sepc == '\0') {
while ((c = *p++) == ' ' || c == '\t')
continue;
p--;
trimtrail = 1;
sep = " \t"; /* note, code below knows this is 2 long */
sepc = ' ';
} else
trimtrail = 0;
sepc2 = sep[1]; /* now we can safely pick this up */
 
/* catch empties */
if (*p == '\0')
return(0);
 
/* single separator */
if (sepc2 == '\0') {
fn = nfields;
for (;;) {
*fp++ = p;
fn--;
if (fn == 0)
break;
while ((c = *p++) != sepc)
if (c == '\0')
return(nfields - fn);
*(p-1) = '\0';
}
/* we have overflowed the fields vector -- just count them */
fn = nfields;
for (;;) {
while ((c = *p++) != sepc)
if (c == '\0')
return(fn);
fn++;
}
/* not reached */
}
 
/* two separators */
if (sep[2] == '\0') {
fn = nfields;
for (;;) {
*fp++ = p;
fn--;
while ((c = *p++) != sepc && c != sepc2)
if (c == '\0') {
if (trimtrail && **(fp-1) == '\0')
fn++;
return(nfields - fn);
}
if (fn == 0)
break;
*(p-1) = '\0';
while ((c = *p++) == sepc || c == sepc2)
continue;
p--;
}
/* we have overflowed the fields vector -- just count them */
fn = nfields;
while (c != '\0') {
while ((c = *p++) == sepc || c == sepc2)
continue;
p--;
fn++;
while ((c = *p++) != '\0' && c != sepc && c != sepc2)
continue;
}
/* might have to trim trailing white space */
if (trimtrail) {
p--;
while ((c = *--p) == sepc || c == sepc2)
continue;
p++;
if (*p != '\0') {
if (fn == nfields+1)
*p = '\0';
fn--;
}
}
return(fn);
}
 
/* n separators */
fn = 0;
for (;;) {
if (fn < nfields)
*fp++ = p;
fn++;
for (;;) {
c = *p++;
if (c == '\0')
return(fn);
sepp = sep;
while ((sepc = *sepp++) != '\0' && sepc != c)
continue;
if (sepc != '\0') /* it was a separator */
break;
}
if (fn < nfields)
*(p-1) = '\0';
for (;;) {
c = *p++;
sepp = sep;
while ((sepc = *sepp++) != '\0' && sepc != c)
continue;
if (sepc == '\0') /* it wasn't a separator */
break;
}
p--;
}
 
/* not reached */
}
 
#ifdef TEST_SPLIT
 
 
/*
* test program
* pgm runs regression
* pgm sep splits stdin lines by sep
* pgm str sep splits str by sep
* pgm str sep n splits str by sep n times
*/
int
main(argc, argv)
int argc;
char *argv[];
{
char buf[512];
register int n;
# define MNF 10
char *fields[MNF];
 
if (argc > 4)
for (n = atoi(argv[3]); n > 0; n--) {
(void) strcpy(buf, argv[1]);
}
else if (argc > 3)
for (n = atoi(argv[3]); n > 0; n--) {
(void) strcpy(buf, argv[1]);
(void) split(buf, fields, MNF, argv[2]);
}
else if (argc > 2)
dosplit(argv[1], argv[2]);
else if (argc > 1)
while (fgets(buf, sizeof(buf), stdin) != NULL) {
buf[strlen(buf)-1] = '\0'; /* stomp newline */
dosplit(buf, argv[1]);
}
else
regress();
 
exit(0);
}
 
dosplit(string, seps)
char *string;
char *seps;
{
# define NF 5
char *fields[NF];
register int nf;
 
nf = split(string, fields, NF, seps);
print(nf, NF, fields);
}
 
print(nf, nfp, fields)
int nf;
int nfp;
char *fields[];
{
register int fn;
register int bound;
 
bound = (nf > nfp) ? nfp : nf;
printf("%d:\t", nf);
for (fn = 0; fn < bound; fn++)
printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n");
}
 
#define RNF 5 /* some table entries know this */
struct {
char *str;
char *seps;
int nf;
char *fi[RNF];
} tests[] = {
"", " ", 0, { "" },
" ", " ", 2, { "", "" },
"x", " ", 1, { "x" },
"xy", " ", 1, { "xy" },
"x y", " ", 2, { "x", "y" },
"abc def g ", " ", 5, { "abc", "def", "", "g", "" },
" a bcd", " ", 4, { "", "", "a", "bcd" },
"a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
" a b c d ", " ", 6, { "", "a", "b", "c", "d " },
 
"", " _", 0, { "" },
" ", " _", 2, { "", "" },
"x", " _", 1, { "x" },
"x y", " _", 2, { "x", "y" },
"ab _ cd", " _", 2, { "ab", "cd" },
" a_b c ", " _", 5, { "", "a", "b", "c", "" },
"a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" },
" a b c d ", " _", 6, { "", "a", "b", "c", "d " },
 
"", " _~", 0, { "" },
" ", " _~", 2, { "", "" },
"x", " _~", 1, { "x" },
"x y", " _~", 2, { "x", "y" },
"ab _~ cd", " _~", 2, { "ab", "cd" },
" a_b c~", " _~", 5, { "", "a", "b", "c", "" },
"a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" },
"~a b c d ", " _~", 6, { "", "a", "b", "c", "d " },
 
"", " _~-", 0, { "" },
" ", " _~-", 2, { "", "" },
"x", " _~-", 1, { "x" },
"x y", " _~-", 2, { "x", "y" },
"ab _~- cd", " _~-", 2, { "ab", "cd" },
" a_b c~", " _~-", 5, { "", "a", "b", "c", "" },
"a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" },
"~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " },
 
"", " ", 0, { "" },
" ", " ", 2, { "", "" },
"x", " ", 1, { "x" },
"xy", " ", 1, { "xy" },
"x y", " ", 2, { "x", "y" },
"abc def g ", " ", 4, { "abc", "def", "g", "" },
" a bcd", " ", 3, { "", "a", "bcd" },
"a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
" a b c d ", " ", 6, { "", "a", "b", "c", "d " },
 
"", "", 0, { "" },
" ", "", 0, { "" },
"x", "", 1, { "x" },
"xy", "", 1, { "xy" },
"x y", "", 2, { "x", "y" },
"abc def g ", "", 3, { "abc", "def", "g" },
"\t a bcd", "", 2, { "a", "bcd" },
" a \tb\t c ", "", 3, { "a", "b", "c" },
"a b c d e ", "", 5, { "a", "b", "c", "d", "e" },
"a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" },
" a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " },
 
NULL, NULL, 0, { NULL },
};
 
regress()
{
char buf[512];
register int n;
char *fields[RNF+1];
register int nf;
register int i;
register int printit;
register char *f;
 
for (n = 0; tests[n].str != NULL; n++) {
(void) strcpy(buf, tests[n].str);
fields[RNF] = NULL;
nf = split(buf, fields, RNF, tests[n].seps);
printit = 0;
if (nf != tests[n].nf) {
printf("split `%s' by `%s' gave %d fields, not %d\n",
tests[n].str, tests[n].seps, nf, tests[n].nf);
printit = 1;
} else if (fields[RNF] != NULL) {
printf("split() went beyond array end\n");
printit = 1;
} else {
for (i = 0; i < nf && i < RNF; i++) {
f = fields[i];
if (f == NULL)
f = "(NULL)";
if (strcmp(f, tests[n].fi[i]) != 0) {
printf("split `%s' by `%s', field %d is `%s', not `%s'\n",
tests[n].str, tests[n].seps,
i, fields[i], tests[n].fi[i]);
printit = 1;
}
}
}
if (printit)
print(nf, RNF, fields);
}
}
#endif
/programs/develop/libraries/menuetlibc/src/libc/posix/regex/utils.h
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* utility definitions */
#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */
#define INFINITY (DUPMAX + 1)
#define NC (CHAR_MAX - CHAR_MIN + 1)
typedef unsigned char uch;
 
/* switch off assertions (if not already off) if no REDEBUG */
#ifndef REDEBUG
#ifndef NDEBUG
#define NDEBUG /* no assertions please */
#endif
#endif
#include <assert.h>
 
/* for old systems with bcopy() but no memmove() */
#ifdef USEBCOPY
#define memmove(d, s, c) bcopy(s, d, c)
#endif
/programs/develop/libraries/menuetlibc/src/libc/posix/setjmp/Makefile
0,0 → 1,3
THIS_SRCS = siglongj.s sigsetjm.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/setjmp/siglongj.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(siglongjmp)
jmp C_SYM(longjmp)
/programs/develop/libraries/menuetlibc/src/libc/posix/setjmp/sigsetjm.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(sigsetjmp)
jmp C_SYM(setjmp)
 
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/Makefile
0,0 → 1,4
THIS_SRCS = itimer.c kill.c sigaddse.c sigdelse.c sigempty.c sigfills.c \
sigismem.c sigpendi.c sigprocm.c sigsuspe.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/itimer.c
0,0 → 1,24
/* Copyright (C) 1995 Charles Sandmann (sandmann@clio.rice.edu)
setitimer implmentation - used for profiling and alarm
BUGS: ONLY ONE AT A TIME, first pass code
This software may be freely distributed, no warranty. */
 
#include <libc/stubs.h>
#include <sys/time.h>
#include <errno.h>
#include <signal.h>
#include <assert.h>
 
static struct itimerval real, prof;
 
/* not right, should compute from current tic count. Do later */
int getitimer(int which, struct itimerval *value)
{
errno = EINVAL;
return -1;
}
 
int setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
{
return -EPERM;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/kill.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <signal.h>
#include <unistd.h>
 
int kill(pid_t pid, int sig)
{
if(pid==-1) __menuet__sys_exit();
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigaddse.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <signal.h>
 
int
sigaddset(sigset_t *_set, int _signo)
{
if (_set == 0)
{
errno = EINVAL;
return -1;
}
if (_signo < 0 || _signo >= 320)
{
errno = EINVAL;
return -1;
}
_set->__bits[_signo>>5] |= (1U << (_signo&31));
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigdelse.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <signal.h>
 
int
sigdelset(sigset_t *_set, int _signo)
{
if (_set == 0)
{
errno = EINVAL;
return -1;
}
if (_signo < 0 || _signo >= 320)
{
errno = EINVAL;
return -1;
}
_set->__bits[_signo>>5] &= ~(1U << (_signo&31));
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigempty.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <signal.h>
 
int
sigemptyset(sigset_t *_set)
{
int i;
if (_set == 0)
{
errno = EINVAL;
return -1;
}
for (i=0; i<10; i++)
_set->__bits[i] = 0;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigfills.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <signal.h>
 
int
sigfillset(sigset_t *_set)
{
if (_set == 0)
{
errno = EINVAL;
return -1;
}
sigemptyset(_set);
_set->__bits[9] = 0x7fff; /* SIGABRT (288) .. SIGTRAP (302) */
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigismem.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <signal.h>
 
int
sigismember(const sigset_t *_set, int _signo)
{
if (_set == 0)
{
errno = EINVAL;
return -1;
}
if (_signo < 0 || _signo >= 320)
return 0;
return _set->__bits[_signo >> 5] & (1U<<(_signo&31)) ? 1 : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigpendi.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <signal.h>
 
int
sigpending(sigset_t *_set)
{
return sigemptyset(_set);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigprocm.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <signal.h>
 
/* ARGSUSED */
int
sigprocmask(int _how, const sigset_t *_set, sigset_t *_oset)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/signal/sigsuspe.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <signal.h>
 
/* ARGSUSED */
int
sigsuspend(const sigset_t *_set)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/stdio/Makefile
0,0 → 1,3
THIS_SRCS = fdopen.c fileno.c popen.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/stdio/fdopen.c
0,0 → 1,67
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <io.h>
#include <libc/file.h>
#include <libc/local.h>
 
FILE *
fdopen(int fildes, const char *mode)
{
FILE *f;
int rw, oflags = 0;
char tbchar;
 
f = __alloc_file();
if (f == NULL)
return NULL;
 
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
 
switch (*mode)
{
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
 
if (*mode == 'a')
lseek(fildes, 0, SEEK_END);
 
f->_cnt = 0;
f->_file = fildes;
f->_bufsiz = 0;
if (rw)
f->_flag = _IORW;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
 
f->_base = f->_ptr = NULL;
 
setmode(fildes, oflags & (O_TEXT|O_BINARY));
 
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/stdio/fileno.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef fileno
int
fileno(FILE *stream)
{
return stream ? stream->_file : -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/stdio/popen.c
0,0 → 1,220
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
This is popen() and pclose() for MSDOS. They were developed using
Microsoft C, but should port easily to DOS C any compiler.
Original author: pacetti@fl-ngnet.army.mil
 
These routines are hacks, that is they SIMULATE thier UNIX
counterparts. Since MSDOS and won't allow concurrent process spawning,
you can't really pipe. I came up with this nearly stupid way around
piping because I wanted to have some portability between UNIX and MSDOS.
I'm probably not the first person to have this idea or implement it, but
I think I'm the first to give it away for free (no points?!).
 
The functions simulate popen() and pclose() by redirecting stdin or
stdout, then spawning a child processes via system().
 
If you popen() for read, the stdout is redirected to a temporary
file, and the child is spawned. The stdout is reopened via dup2(), the
temporary file is opened for read and a file pointer to it is returned.
 
If you popen() for write, a temporary file is opened for write, and
a file pointer to it is returned. When you pclose(), the stdin is
redirected to the temporary file and the child is spawned.
 
In both cases, pclose() closes and unlinks the temporary file.
 
A static linked list of C structures is built to store necessary
info for all popen()ed files so you can popen() more than one file at
a time.
 
The popen() function will return NULL on an error, or a valid FILE
*pointer on a successful open. The pclose() function will return
negative one (-1) on an error or zero (0) on a successful close.
 
The function prototypes are:
 
FILE *popen(command, mode)
char *command, char *mode;
 
int pclose(pp)
FILE *pp;
 
Where command is a character string equivilant to a MSDOS command
line, mode is "r" for read or "w" for write, and pp is a pointer to a
file opened through popen().
 
A main() function has been included for testing purposes, to compile
it define the preprocessor token TEST at compile time.
*/
 
#include <libc/stubs.h>
#include <io.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libc/file.h>
 
/* hold file pointer, descriptor, command, mode, temporary file name */
struct pipe_list {
FILE *fp;
int fd;
char *command, mode[10], temp_name[FILENAME_MAX];
struct pipe_list *next;
};
 
/* static, global list pointer */
static struct pipe_list *pl = NULL;
 
FILE *
popen (const char *cm, const char *md) /* program name, pipe mode */
{
struct pipe_list *l1, *l2;
static char *tn = NULL; /* temporary file basename */
 
if (!tn)
if ((tn = tmpnam(0)) == NULL)
return NULL;
 
/* make new node */
if ((l1 = (struct pipe_list *) malloc (sizeof (struct pipe_list))) == NULL)
return NULL;
 
/* zero out elements to we'll get here */
l1->fd = 0;
l1->fp = NULL;
l1->next = NULL;
 
/* if empty list - just grab new node */
if (!pl)
pl = l1;
else
{
/* otherwise, find last node in list */
++(l1->fd);
l2 = pl;
while (l2->next)
{
++(l1->fd);
l2 = l2->next;
};
/* add new node to list */
l2->next = l1;
}
 
/* stick in elements we know already */
strcpy (l1->mode, md);
sprintf (l1->temp_name, "%s.%d", tn, l1->fd);
 
/* if can save the program name, build temp file */
if ((l1->command = malloc(strlen(cm)+1)))
{
strcpy(l1->command, cm);
/* if caller wants to read */
if (l1->mode[0] == 'r')
{
/* dup stdout */
if ((l1->fd = dup (fileno (stdout))) == EOF)
l1->fp = NULL;
else if (!(l1->fp = freopen (l1->temp_name, "wb", stdout)))
l1->fp = NULL;
else
/* exec cmd */
if (system (cm) == EOF)
l1->fp = NULL;
/* reopen real stdout */
if (dup2 (l1->fd, fileno (stdout)) == EOF)
{
l1->fp = NULL;
close(l1->fd);
}
else
/* open file for reader */
l1->fp = fopen (l1->temp_name, l1->mode);
}
else
/* if caller wants to write */
if (l1->mode[0] == 'w')
/* open temp file */
l1->fp = fopen (l1->temp_name, l1->mode);
else
/* unknown mode */
l1->fp = NULL;
}
return l1->fp; /* return == NULL ? ERROR : OK */
}
 
int
pclose (FILE *pp)
{
struct pipe_list *l1, *l2; /* list pointers */
int retval=0; /* function return value */
 
/* if pointer is first node */
if (pl->fp == pp)
{
/* save node and take it out the list */
l1 = pl;
pl = l1->next;
}
else
/* if more than one node in list */
if (pl->next)
{
/* find right node */
for (l2 = pl, l1 = pl->next; l1; l2 = l1, l1 = l2->next)
if (l1->fp == pp)
break;
 
/* take node out of list */
l2->next = l1->next;
}
else
return -1;
 
/* if FILE not in list - return error */
if (l1->fp == pp)
{
/* close the (hopefully) popen()ed file */
fclose (l1->fp);
 
/* if pipe was opened to write */
if (l1->mode[0] == 'w')
{
/* dup stdin */
if ((l1->fd = dup (fileno (stdin))) == EOF)
retval = -1;
else
/* open temp stdin */
if (!(l1->fp = freopen (l1->temp_name, "rb", stdin)))
retval = -1;
else
/* exec cmd */
if (system (l1->command) == EOF)
retval = -1;
else
{
/* reopen stdin */
if (dup2 (l1->fd, fileno (stdin)) == EOF)
retval = -1;
close(l1->fd);
}
}
else
/* if pipe was opened to read */
if (l1->mode[0] == 'r')
retval = 0;
else
/* invalid mode */
retval = -1;
}
remove (l1->temp_name); /* remove temporary file */
free (l1->command); /* dealloc memory */
free (l1); /* dealloc memory */
l1 = NULL; /* make pointer bogus */
 
return retval; /* retval==0 ? OK : ERROR */
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/Makefile
0,0 → 1,14
all:
make -C stat
make -C times
make -C wait
 
clean:
make -C stat clean
make -C times clean
make -C wait clean
 
depend:
make -C stat depend
make -C times depend
make -C wait depend
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/Makefile
0,0 → 1,4
THIS_SRCS = chmod.c filelen.c fixpath.c fstat.c is_exec.c mkdir.c mkfifo.c \
stat.c st_loss.c umask.c xstat.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/chmod.c
0,0 → 1,26
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/stat.h>
#include <io.h>
int
chmod(const char *filename, int pmode)
{
int dmode;
unsigned attr = _chmod(filename, 0, 0);
if (attr == -1)
return -1;
if(pmode & S_IWUSR) /* Only implemented toggle is write/nowrite */
dmode = 0; /* Normal file */
else
dmode = 1; /* Readonly file */
/* Must clear the directory and volume bits, otherwise 214301 fails.
Unused bits left alone (some network redirectors use them). */
if (_chmod(filename, 1, (attr & 0xffe6) | dmode) == -1)
return -1;
return 0;
}
 
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/filelen.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file FILELEN.C */
/*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <errno.h>
#include <libc/dosio.h>
 
long __filelength(int);
 
long __filelength(int fhandle)
{
return dosemu_iosize(fhandle);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/fixpath.c
0,0 → 1,41
#include <libc/stubs.h>
#include <stdio.h> /* For FILENAME_MAX */
#include <errno.h> /* For errno */
#include <string.h> /* For strlen() */
#include <sys/stat.h>
#include <libc/dosio.h>
 
static inline int is_slash(char c)
{
return c=='/' || c=='\\';
}
 
void fix_slashes(char * in,char * out)
{
int slash_count;
for(slash_count=1;in && out && *in;in++)
{
if(is_slash(*in))
{
slash_count++;
continue;
} else {
if(slash_count)
{
slash_count=0;
*out++='/';
}
*out++=*in;
}
}
*out='\0';
}
 
char * __libc_combine_path(char * c);
 
void _fixpath(const char *in, char *out)
{
char * combined;
combined=__libc_combine_path((char *)in);
fix_slashes(combined,out);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/fstat.c
0,0 → 1,26
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <libc/farptrgs.h>
#include <libc/bss.h>
#include <menuet/os.h>
 
#include "../../../dos/dos_emu/dosemuin.h"
 
#include "xstat.h"
 
int fstat(int handle, struct stat *statbuf)
{
if (handle < 0 || handle >= _MAX_HANDLES)
{
errno = EBADF;
return -1;
}
return stat(_io_handles[handle].filename, statbuf);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/is_exec.c
0,0 → 1,125
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* IS_EXEC.C
*
* Given a filename or a file handle, and the extension of the file,
* determine if the file is executable.
* First, the file extension is checked in case it uniquely identifies
* the file as either an executable or not. Failing this, the first
* two bytes of the file are tested for known signatures of executable
* files.
*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <libc/farptrgs.h>
#include <libc/dosio.h>
 
extern unsigned short _djstat_flags;
unsigned short _get_magic(const char *, int);
int _is_executable(const char *, int, const char *);
 
/*
* Read a MAGIC NUMBER from a given file. These are the first
* two bytes of the file, if we look at them as an unsigned short. */
 
#define _STAT_EXEC_EXT 2 /* get execute bits from file extension? */
#define _STAT_EXEC_MAGIC 4 /* get execute bits from magic signature? */
 
unsigned short _get_magic(const char *s, int fh)
{
}
 
/* A list of extensions which designate executable files. These
are NOT tested for the magic number. */
static char executables[] = "|EXE|COM|BAT|BTM|DLL|VXD|";
 
/* A list of extensions which belong to files known to NEVER be
executables. These exist to minimize read()'ing files while
detecting executables by magic number. You are welcome to
add to this list, but remember: only extensions which could
NEVER be present in executables should go here. */
static char non_executables[] = "\
|A|A01|A02|A03|A04|A05|ADL|ARC|ARJ|ASC|ASM|AUX|AWK\
|BAS|BIB|BGI|BMP\
|C|CC|CFG|CGZ|CH3|CHR|CI|CLP|CMF|CPI|CPP|CXX\
|DAT|DBF|DIZ|DOC|DVI\
|E|EL|ELC\
|F77|FN3\
|GIF|GZ\
|H|HLP|HPP|HXX\
|ICO|IN|INC|INF|INI\
|JPG\
|L|LEX|LF|LIB|LOG|LST|LZH\
|M|MAK|MAP|MF|MID|MPG\
|O|OBJ\
|PAK|PAS|PBM|PCD|PCX|PDS|PIC|PIF|PN3|PRJ|PS\
|RAS|RGB|RLE\
|S|SND|SY3\
|TAR|TAZ|TEX|TGA|TGZ|TIF|TXH|TXI|TXT\
|VOC\
|WAV|WK1|WK3|WKB|WQ1|WQ3|WQ4|WQ5|WQ6|WQ!\
|XBM\
|Y\
|ZIP|ZOO|";
 
int _is_executable(const char *filename, int fhandle, const char *extension)
{
if (!extension && filename)
{
const char *cp, *ep=0;
for (cp=filename; *cp; cp++)
{
if (*cp == '.')
ep = cp;
if (*cp == '/' || *cp == '\\' || *cp == ':')
ep = 0;
}
extension = ep;
}
if ((_djstat_flags & _STAT_EXEC_EXT) == 0
&& extension
&& *extension
&& strlen(extension) <= ((extension[0]=='.') ? 4 : 3))
{
/* Search the list of extensions in executables[]. */
char tmp_buf[6];
 
tmp_buf[0] = '|';
strcpy(tmp_buf+1, *extension == '.' ? extension + 1 : extension);
strcat(tmp_buf, "|");
if (strstr(non_executables, tmp_buf))
return 0;
else if (strstr(executables, tmp_buf))
return 1;
}
 
/* No extension, or extension doesn't define execute
bits unambiguously. We are in for some dirty work.
Read the first two bytes of the file and see if they
are any of the known magic numbers which designate
executable files.
Unix-like shells, which have executable shell scripts
without extensions and DON'T have "#!" as their FIRST
TWO CHARACTERS, lose here. Sorry, folks. */
if ( (_djstat_flags & _STAT_EXEC_MAGIC) == 0 )
{
switch (_get_magic(filename, fhandle))
{
case 0x5a4d: /* "MZ" */
case 0x010b:
case 0x014c:
case 0x2123: /* "#!" */
return 1;
}
}
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/mkdir.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libc/dosio.h>
int mkdir(const char *dirname, mode_t mode)
{
return -1;
}
 
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/mkfifo.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/stat.h>
#include <errno.h>
 
int
mkfifo(const char *path, mode_t mode)
{
errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/st_loss.c
0,0 → 1,68
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file ST_LOSS.C
*
* Function to print a human-readable description of _DJSTAT_FAIL_BITS
* variable, for debugging purposes. A string which contains description
* of every fail bit set is printed to the stream given by FP, or to
* stderr if FP is NULL.
*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as the above copyright
* notice is left intact. There is no warranty on this software.
*
*/
 
#include <stdio.h>
#include "xstat.h"
 
/* List of messages describing possible failures. There is a message
for every bit in the _DJSTAT_FAIL_BITS variable, plus a success
message, which is printed if no bits are set.
*/
static const char *stfail_message[] = {
"Everything checks out OK",
"Get DOS SDA call (INT 21h/AX=5D06h/0Dh) failed",
"Unsupported DOS version: less than 3.10 (for stat), or 1.x (for fstat)",
"Cannot find SDA entry which corresponds to pathname (bad SDA pointer?)",
"Get TrueName call (INT 21h/AX=6000h) failed",
"Failed to get starting cluster number; inode defaults to hashing\n"
"(if no other messages were printed, then this is either an empty\n"
"file on a local disk drive, or a file on a networked drive, or\n"
"you run under some kind of DOS clone)",
"Root directory has no volume label required to get its time fields",
"Get SDA call returned preposterously large or negative number of SDAs",
"Write access bit required, but cannot be figured out",
"Failed to get drive letter for handle (Novell NetWare 3.x?)",
"SFT entry found, but is inconsistent with file size and time stamp",
"Negative index into SFT: might be bad handle table in PSP",
"File entry not found in SFT array (bad SFT index, or Novell 3.x)"
};
 
/* Number of used bits we know about in _djstat_fail_bits. */
static const int used_bits = sizeof(stfail_message)/sizeof(stfail_message[0]);
 
void
_djstat_describe_lossage(FILE *fp)
{
int i = 0;
unsigned long bits = _djstat_fail_bits; /* so we don't have side effects */
 
if (fp == 0)
fp = stderr; /* default: print to stderr */
 
while (bits && i < used_bits)
{
i++;
if (bits & 1) /* print message for this bit, if set */
fprintf(fp, "%s\n", stfail_message[i]);
 
bits >>= 1; /* get next bit */
}
 
/* Did we see any bit set? */
if (i == 0)
fprintf(fp, "%s\n", stfail_message[0]);
 
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/stat.c
0,0 → 1,80
#include <libc/stubs.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dos.h>
#include <dir.h>
#include <libc/farptrgs.h>
#include <libc/bss.h>
 
#include "xstat.h"
 
int stat(const char *path, struct stat *statbuf)
{
int nslash=0;
const char* p;
char* q;
struct systree_info2 finf;
struct bdfe_item attr;
 
memset(statbuf,0,sizeof(*statbuf));
// "/<base>/<number>" is special case
for (p=path;*p;p++) if (*p=='/') ++nslash;
while (p>path && p[-1]=='/') {--nslash;--p;}
if (nslash <= 2)
{
statbuf->st_mode = S_IFDIR;
return 0;
}
finf.command = 5;
finf.file_offset_low = 0;
finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = (__u32)&attr;
_fixpath(path,finf.name);
for (q=finf.name+strlen(finf.name)-1;q>=finf.name && *q=='/';q--) ;
q[1]=0;
if (__kolibri__system_tree_access2(&finf))
{
errno = EFAULT;
return -1;
}
memset(statbuf,0,sizeof(*statbuf));
statbuf->st_size = attr.filesize_low;
if (attr.attr & 0x10)
statbuf->st_mode = S_IFDIR;
struct tm time;
time.tm_sec = attr.atime.seconds;
time.tm_min = attr.atime.minutes;
time.tm_hour = attr.atime.hours;
time.tm_mday = attr.adate.day;
time.tm_mon = attr.adate.month;
time.tm_year = attr.adate.year - 1900;
time.tm_isdst = -1;
statbuf->st_atime = mktime(&time);
time.tm_sec = attr.ctime.seconds;
time.tm_min = attr.ctime.minutes;
time.tm_hour = attr.ctime.hours;
time.tm_mday = attr.cdate.day;
time.tm_mon = attr.cdate.month;
time.tm_year = attr.cdate.year - 1900;
time.tm_isdst = -1;
statbuf->st_ctime = mktime(&time);
time.tm_sec = attr.mtime.seconds;
time.tm_min = attr.mtime.minutes;
time.tm_hour = attr.mtime.hours;
time.tm_mday = attr.mdate.day;
time.tm_mon = attr.mdate.month;
time.tm_year = attr.mdate.year - 1900;
time.tm_isdst = -1;
statbuf->st_mtime = mktime(&time);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/umask.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <sys/stat.h>
 
mode_t
umask(mode_t newmask)
{
static mode_t the_mask = 022;
mode_t old_mask = the_mask;
the_mask = newmask;
return old_mask;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/xstat.c
0,0 → 1,262
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file XSTAT.C
*
* Internal assist functions which are common to stat() and fstat().
*
*
* Copyright (c) 1994-96 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as the above copyright
* notice is left intact. There is no warranty on this software.
*
*/
 
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <limits.h>
#include <time.h>
#include <errno.h>
#include <dos.h>
#include <libc/farptrgs.h>
#include <libc/dosio.h>
#include <libc/bss.h>
 
#include "xstat.h"
 
static int xstat_count = -1;
 
/* Some fields of struct stat are expensive to compute under DOS,
because they require multiple disk accesses. Fortunately, many
DOS programs don't care about these. To leave both pedants (like
me) and performance-oriented guys happy, a variable is provided
which controls which expensive fields should be computed. To get
the fastest stat() for your program, clear the bits for only those
features you need and set the others.
 
This improvement was suggested by Charles Sandmann
<sandmann@clio.rice.edu> and DJ Delorie <dj@delorie.com>. */
 
#define _STAT_INODE 1 /* should we bother getting inode numbers? */
#define _STAT_EXEC_EXT 2 /* get execute bits from file extension? */
#define _STAT_EXEC_MAGIC 4 /* get execute bits from magic signature? */
#define _STAT_DIRSIZE 8 /* compute directory size? */
#define _STAT_ROOT_TIME 0x10 /* try to get root dir time stamp? */
#define _STAT_WRITEBIT 0x20 /* fstat() needs write bit? */
 
/* Should we bother about executables at all? */
#define _STAT_EXECBIT (_STAT_EXEC_EXT | _STAT_EXEC_MAGIC)
 
/* By default, all the bits are reset (including as yet unused ones), so
people who don't care will transparently have the full version. */
unsigned short _djstat_flags;
 
/* As we depend on undocumented DOS features, we could fail in some
incompatible environment or future DOS versions. If we do, the
following variable will have some of its bits set. Each bit
describes a single feature which we tried to use and failed.
The function _djstat_describe_lossage() may be called to print a
human-readable description of the bits which were set by the last
call to f?stat(). This should make debugging f?stat() failures
in an unanticipated environment a lot easier.
 
This improvement was suggested by Charles Sandmann
<sandmann@clio.rice.edu>. */
 
unsigned short _djstat_fail_bits;
 
/* ----------------------------------------------------------------------- */
 
/* Convert file date and time to time_t value suitable for
struct stat fields. */
 
time_t
_file_time_stamp(unsigned int dos_ftime)
{
struct tm file_tm;
 
memset(&file_tm, 0, sizeof(struct tm));
file_tm.tm_isdst = -1; /* let mktime() determine if DST is in effect */
 
file_tm.tm_sec = (dos_ftime & 0x1f) * 2;
file_tm.tm_min = (dos_ftime >> 5) & 0x3f;
file_tm.tm_hour = (dos_ftime >> 11) & 0x1f;
file_tm.tm_mday = (dos_ftime >> 16) & 0x1f;
file_tm.tm_mon = ((dos_ftime >> 21) & 0x0f) - 1; /* 0 = January */
file_tm.tm_year = (dos_ftime >> 25) + 80;
 
return mktime(&file_tm);
}
 
/* Get time stamp of a DOS file packed as a 32-bit int.
* This does what Borland's getftime() does, except it doesn't
* pollute the application namespace and returns an int instead
* of struct ftime with packed bit-fields.
*/
 
 
int
_getftime(int fhandle, unsigned int *dos_ftime)
{
return -1;
}
 
/* Invent an inode number for those files which don't have valid DOS
* cluster number. These could be: devices like /dev/nul; empty
* files which were not allocated disk space yet; or files on
* networked drives, for which the redirector doesn't bring the
* cluster number.
*
* To ensure proper operation of this function, you must call it
* with a filename in some canonical form. E.g., with a name
* returned by truename(), or that returned by _fixpath(). The
* point here is that the entire program MUST abide by these
* conventions through its operation, or else you risk getting
* different inode numbers for the same file.
*
* This function is due to Eric Backus and was taken with minor
* modifications from stat.c, as included in DJGPP 1.11m5.
* The function now returns 0 instead of -1 if it can't allocate
* memory for a new name, so that f?stat() won't fail if the inode
* is unavailable, but return zero inode instead.
*/
 
/*
(c) Copyright 1992 Eric Backus
 
This software may be used freely so long as this copyright notice is
left intact. There is no warranty on this software.
*/
 
struct name_list
{
struct name_list *next;
char *name;
unsigned mtime;
unsigned long size;
long inode;
};
 
ino_t
_invent_inode(const char *name, unsigned time_stamp, unsigned long fsize)
{
static struct name_list *name_list[256];
 
/* If the st_inode is wider than a short int, we will count up
* from USHRT_MAX+1 and thus ensure there will be no clashes with
* actual cluster numbers.
* Otherwise, we must count downward from USHRT_MAX, which could
* yield two files with identical inode numbers: one from actual
* DOS cluster number, and another from this function. In the
* latter case, we still have at least 80 inode numbers before
* we step into potentially used numbers, because some FAT entries
* are reserved to mean EOF, unused entry and other special codes,
* and the FAT itself uses up some clusters which aren't counted.
*/
static int dir = (sizeof(ino_t) > 2 ? 1 : -1);
 
/* INODE_COUNT is declared LONG and not ino_t, because some DOS-based
* compilers use short or unsigned short for ino_t.
*/
static long inode_count = (sizeof(ino_t) > 2
? (long)USHRT_MAX + 1L
: USHRT_MAX);
 
struct name_list *name_ptr, *prev_ptr;
const char *p;
int hash;
 
/* Force initialization in restarted programs (emacs). */
if (xstat_count != __bss_count)
{
xstat_count = __bss_count;
inode_count = (sizeof(ino_t) > 2 ? (long)USHRT_MAX + 1L : USHRT_MAX);
memset (name_list, 0, sizeof name_list);
}
 
if (!name)
return 0;
 
/* Skip over device and leading slash. This will allow for less
* inode numbers to be used, because there is nothing bad in generating
* identical inode for two files which belong to different drives.
*/
if (*name && name[1] == ':' && (name[2] == '\\' || name[2] == '/'))
{
/* If this is a root directory, return inode = 1. This is compatible
with the code on stat.c which deals with root directories. */
if (name[3] == 0)
return (ino_t)1;
 
name += 3;
}
 
/* If the passed name is empty, invent a new inode unconditionally.
* This is for those unfortunate circumstances where we couldn't
* get a name (e.g., fstat() under Novell). For these we want at
* least to ensure that no two calls will get the same inode number.
* The lossage here is that you get different inodes even if you call
* twice with the same file. Sigh...
*/
if (!*name)
{
ino_t retval = inode_count;
 
inode_count += dir;
return retval;
}
 
/* We could probably use a better hash than this */
p = name;
hash = 0;
while (*p != '\0')
hash += *p++;
hash &= 0xff;
 
/* Have we seen this string? */
name_ptr = name_list[hash];
prev_ptr = name_ptr;
while (name_ptr)
{
if (strcmp(name, name_ptr->name) == 0 &&
name_ptr->mtime == time_stamp &&
name_ptr->size == fsize)
break;
prev_ptr = name_ptr;
name_ptr = name_ptr->next;
}
 
if (name_ptr)
/* Same string, time stamp, and size, so same inode */
return name_ptr->inode;
else
{
ino_t retval;
/* New string with same hash code */
name_ptr = (struct name_list *)malloc(sizeof *name_ptr);
if (name_ptr == 0)
return 0;
name_ptr->next = (struct name_list *)0;
name_ptr->name = (char *)malloc(strlen(name)+1);
if (name_ptr->name == 0)
{
free(name_ptr);
return 0;
}
strcpy(name_ptr->name, name);
name_ptr->mtime = time_stamp;
name_ptr->size = fsize;
name_ptr->inode = inode_count;
if (prev_ptr)
prev_ptr->next = name_ptr;
else
name_list[hash] = name_ptr;
retval = inode_count;
inode_count += dir; /* increment or decrement as appropriate */
 
return retval;
}
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/stat/xstat.h
0,0 → 1,72
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* Header for internal stat()/fstat() assist functions.
*
*/
 
#ifndef __XSTAT_H
#define __XSTAT_H
 
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
 
/* Some errno.h headers do not define EFAULT. Here the value is
taken from POSIX IEEE 1003.1. */
#include <errno.h>
#ifndef EFAULT
#define EFAULT 14
#endif
 
/* Under MS-DOS, file access permissions are shared by all, except for
Write permission. */
#define READ_ACCESS (S_IRUSR | S_IRGRP | S_IROTH)
#define WRITE_ACCESS S_IWUSR
#define EXEC_ACCESS (S_IXUSR | S_IXGRP | S_IXOTH)
 
/* Macro to convert a segment and an offset to a "far offset" suitable
for _farxxx() functions of DJGPP. */
#ifndef MK_FOFF
#define MK_FOFF(s,o) ((int)((((unsigned long)(s)) << 4) + (unsigned short)(o)))
#endif
 
/* Ralph Brown's Interrupt List says this should be the length
of the buffer for INT 21H AX=6000H. */
#define MAX_TRUE_NAME 128
 
extern unsigned short _osmajor, _osminor;
extern const char * _os_flavor;
 
/* Bits to flag f?stat() failed to use individual undocumented features. */
#define _STFAIL_SDA 1 /* Get SDA call failed */
#define _STFAIL_OSVER 2 /* Unsupported DOS version */
#define _STFAIL_BADSDA 4 /* Bad pointer to SDA */
#define _STFAIL_TRUENAME 8 /* _truename() failed */
#define _STFAIL_HASH 0x10 /* inode defaults to hashing */
#define _STFAIL_LABEL 0x20 /* Root dir, but no volume label */
#define _STFAIL_DCOUNT 0x40 /* dirent_count ridiculously large */
#define _STFAIL_WRITEBIT 0x80 /* fstat() failed to get write access bit */
#define _STFAIL_DEVNO 0x100 /* fstat() failed to get device number */
#define _STFAIL_BADSFT 0x200 /* SFT entry found, but can't be trusted */
#define _STFAIL_SFTIDX 0x400 /* bad SFT index in JFT */
#define _STFAIL_SFTNF 0x800 /* file entry not found in SFT array */
 
extern unsigned short _djstat_fail_bits;
 
extern unsigned short _djstat_flags;
 
extern time_t _file_time_stamp(unsigned int);
extern ino_t _invent_inode(const char *, unsigned, unsigned long);
extern unsigned short _get_magic(const char *, int);
extern unsigned short _get_dos_version(int);
extern char * _truename(const char *, char *);
extern int _is_remote_drive(int);
extern int _is_executable(const char *, int, const char *);
extern short _get_dev_info(int);
extern long __filelength(int);
extern int _is_remote_handle(int);
extern void _djstat_describe_lossage(FILE *);
extern int _getftime(int, unsigned int *);
 
#endif /* __XSTAT_H */
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/times/Makefile
0,0 → 1,3
THIS_SRCS = times.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/times/times.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <sys/times.h>
#include <time.h>
 
clock_t
times(struct tms *buffer)
{
if (buffer == 0)
{
errno = EINVAL;
return (clock_t)(-1);
}
buffer->tms_utime = clock();
buffer->tms_stime = 0;
buffer->tms_cutime = 0;
buffer->tms_cstime = 0;
return buffer->tms_utime;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/wait/Makefile
0,0 → 1,3
THIS_SRCS = wait.c waitpid.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/wait/wait.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/wait.h>
#include <errno.h>
 
/* ARGSUSED */
pid_t
wait(int *stat_loc)
{
errno = ECHILD;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/wait/waitpid.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/wait.h>
#include <errno.h>
 
/* ARGSUSED */
pid_t
waitpid(pid_t pid, int *stat_loc, int options)
{
errno = ECHILD;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/Makefile
0,0 → 1,8
THIS_SRCS = access.c alarm.c chdir.c chown.c close.c ctermid.c dup2.c \
dup.c execl.c execle.c execlp.c execlpe.c execv.c execve.c execvp.c \
execvpe.c fork.c fpathcon.c getcwd.c getegid.c geteuid.c getgid.c \
getgroup.c getlogin.c getopt.c getpgrp.c getpid.c getppid.c getuid.c \
isatty.c link.c lseek.c pathconf.c pause.c pipe.c read.c rmdir.c setgid.c \
setpgid.c setsid.c setuid.c sleep.c sysconf.c ttyname.c unlink.s write.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/access.c
0,0 → 1,59
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <io.h>
#include <dirent.h>
#include <errno.h>
 
int access(const char *fn, int flags)
{
unsigned attr = _chmod(fn, 0);
 
if (attr == -1) {
char fixed_path[FILENAME_MAX];
const char* p;
int nums = 0;
DIR* d;
 
/* Root directories on some non-local drives (e.g. CD-ROM)
might fail `_chmod'. `findfirst' to the rescue. */
_fixpath(fn, fixed_path);
for (p=fixed_path;*p;p++) if (*p == '/') ++nums;
if (nums <= 2)
{
d = opendir(fn);
if (d) {closedir(d);return 0;}
}
 
errno = ENOENT;
return -1;
}
if (attr & 0x10) /* directory? */
return 0; /* directories always OK */
if (flags & D_OK)
{
errno = EACCES;
return -1; /* not a directory */
}
 
if ((flags & W_OK) && (attr & 1))
{
errno = EACCES;
return -1; /* not writable */
}
 
if (flags & X_OK)
{
if (!_is_executable(fn, 0, 0))
{
errno = EACCES;
return -1;
}
}
 
return 0; /* everything else is OK */
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/alarm.c
0,0 → 1,12
/* Copyright (C) 1995 Charles Sandmann (sandmann@clio.rice.edu)
alarm() implmentation using setitimer
This software may be freely distributed, no warranty. */
 
#include <libc/stubs.h>
#include <unistd.h>
#include <sys/time.h>
 
unsigned int alarm(unsigned int seconds)
{
return seconds;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/chdir.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <libc/dosio.h>
 
void __chdir(char * path);
 
int chdir (const char *dirname)
{
__chdir((char *)dirname);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/chown.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
/* MS-DOS couldn't care less about file ownerships, so we could
always succeed. At least fail for non-existent files
and for devices. */
int chown(const char *path, uid_t owner, gid_t group)
{
errno = ENOENT;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/close.c
0,0 → 1,6
#include<menuet/os.h>
 
int close(int handle)
{
return dosemu_close(handle);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/ctermid.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <string.h>
 
static char def_termid[] = "con";
 
char *
ctermid(char *_s)
{
if (!_s)
return def_termid;
strcpy(_s, def_termid);
return _s;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/dup.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
 
int dup(int fd)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/dup2.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
 
int
dup2(int fd, int newfd)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execl.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
 
extern char *const *environ;
 
int execl(const char *path, const char *argv0, ...)
{
return spawnve(P_OVERLAY, path, (char *const*)&argv0, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execle.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
#include <libc/dosexec.h>
 
int execle(const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnve(P_OVERLAY, path, (char *const *)&argv0, (char *const *)ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execlp.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
#include <libc/dosexec.h>
 
extern char * const *environ;
 
int execlp(const char *path, const char *argv0, ...)
{
return spawnvpe(P_OVERLAY, path, (char * const *)&argv0, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execlpe.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
#include <libc/dosexec.h>
 
int execlpe(const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnvpe(P_OVERLAY, path, (char * const *)&argv0, (char * const *)ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execv.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
 
extern char * const *environ;
 
int execv(const char *path, char * const *argv)
{
return spawnve(P_OVERLAY, path, argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execve.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
 
int execve(const char *path, char * const argv[], char * const envp[])
{
return spawnve(P_OVERLAY, path, argv, envp);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execvp.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
 
extern char *const *environ;
 
int execvp(const char *path, char * const argv[])
{
return spawnvpe(P_OVERLAY, path, argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/execvpe.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <process.h>
 
int execvpe(const char *path, char * const argv[], char * const envp[])
{
return spawnvpe(P_OVERLAY, path, argv, envp);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/fork.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
 
pid_t fork(void)
{
errno = ENOMEM; /* The only other choice is EAGAIN, and we don't want that */
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/fpathcon.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
#include <limits.h>
 
/* ARGSUSED */
long fpathconf(int fildes, int name)
{
return pathconf("/", name);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getcwd.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <libc/farptrgs.h>
#include <libc/dosio.h>
 
static char * __cur_cwd;
 
extern char* __get_curdir(void);
char * getcwd(char *buf, size_t size)
{
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
size_t k;
__cur_cwd=__get_curdir();
k=min(size,strlen(__cur_cwd));
memcpy(buf,__cur_cwd,k+1);
return buf;
}
 
void __libc_set_cwd(char * p)
{
__chdir(p);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getegid.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
gid_t
getegid(void)
{
return 42;
}
 
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/geteuid.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
uid_t
geteuid(void)
{
return 42;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getgid.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
gid_t getgid(void)
{
return 42;
}
 
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getgroup.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
/* ARGSUSED */
int
getgroups(int _size, gid_t *grouplist)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getlogin.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <stdlib.h>
 
char * getlogin(void)
{
return "root";
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getopt.c
0,0 → 1,85
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libc/unconst.h>
 
int opterr = 1, optind = 1, optopt = 0;
char *optarg = 0;
 
#define BADCH (int)'?'
#define EMSG ""
 
int
getopt(int nargc, char *const nargv[], const char *ostr)
{
static const char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
char *p;
 
if (!*place)
{
if (optind >= nargc || *(place = nargv[optind]) != '-')
{
place = EMSG;
return(EOF);
}
if (place[1] && *++place == '-')
{
++optind;
place = EMSG;
return(EOF);
}
}
 
if ((optopt = (int)*place++) == (int)':'
|| !(oli = strchr(ostr, optopt)))
{
/*
* if the user didn't specify '-' as an option,
* assume it means EOF.
*/
if (optopt == (int)'-')
return EOF;
if (!*place)
++optind;
if (opterr)
{
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
fprintf(stderr, "%s: illegal option -- %c\n", p, optopt);
}
return BADCH;
}
if (*++oli != ':')
{ /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else
{ /* need an argument */
if (*place) /* no white space */
optarg = unconst(place, char *);
else if (nargc <= ++optind)
{ /* no arg */
place = EMSG;
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
if (opterr)
fprintf(stderr, "%s: option requires an argument -- %c\n",
p, optopt);
return BADCH;
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return optopt; /* dump back option letter */
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getpgrp.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
pid_t
getpgrp(void)
{
return getpid();
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getpid.c
0,0 → 1,17
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <libc/farptrgs.h>
#include <libc/bss.h>
#include <menuet/os.h>
 
static int pid_count = -1;
static pid_t my_pid;
 
static struct process_table_entry __tmp_proctab;
 
pid_t getpid(void)
{
__menuet__get_process_table(&__tmp_proctab,PID_WHOAMI);
return __tmp_proctab.pid;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getppid.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
pid_t getppid(void)
{
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/getuid.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
uid_t getuid(void)
{
return 42;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/isatty.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
 
int isatty(int fd)
{
if(fd==0 || fd==1) return 1;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/link.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/stat.h> /* For stat() */
#include <fcntl.h> /* For O_RDONLY, etc. */
#include <unistd.h> /* For read(), write(), etc. */
#include <limits.h> /* For PATH_MAX */
#include <utime.h> /* For utime() */
#include <errno.h> /* For errno */
 
int link(const char *path1, const char *path2)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/lseek.c
0,0 → 1,9
#include <unistd.h>
#include <errno.h>
 
#include <libc/dosio.h>
 
off_t lseek(int handle, off_t offset, int whence)
{
return dosemu_lseek(handle,offset,whence);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/pathconf.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
#include <limits.h>
 
long
pathconf(const char *path, int name)
{
switch (name)
{
case _PC_LINK_MAX: return LINK_MAX;
case _PC_MAX_CANON: return MAX_CANON;
case _PC_MAX_INPUT: return MAX_INPUT;
case _PC_NAME_MAX: return NAME_MAX;
case _PC_PATH_MAX: return PATH_MAX;
case _PC_PIPE_BUF: return PIPE_BUF;
case _PC_CHOWN_RESTRICTED: return _POSIX_CHOWN_RESTRICTED;
case _PC_NO_TRUNC: return _POSIX_NO_TRUNC;
case _PC_VDISABLE: return _POSIX_VDISABLE;
 
default:
errno = EINVAL;
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/pause.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
int pause(void)
{
__menuet__delay100(1);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/pipe.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
int
pipe(int _fildes[2])
{
errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/read.c
0,0 → 1,11
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <io.h>
 
#include <libc/dosio.h>
 
ssize_t read(int handle, void* buffer, size_t count)
{
return dosemu_read(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/rmdir.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <errno.h>
#include <unistd.h>
#include <libc/dosio.h>
 
int
rmdir(const char *dirname)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/setgid.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
int
setgid(gid_t _gid)
{
if (_gid != getgid())
{
errno = EPERM;
return -1;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/setpgid.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
/* ARGSUSED */
int
setpgid(pid_t _pid, pid_t _pgid)
{
if (_pgid != getpid())
{
errno = EPERM;
return -1;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/setsid.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
pid_t
setsid(void)
{
return getpid();
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/setuid.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
int
setuid(uid_t uid)
{
if (uid == getuid())
return 0;
errno = EPERM;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/sleep.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <time.h>
#include <menuet/os.h>
 
unsigned int sleep(unsigned int _seconds)
{
for(;_seconds;_seconds--) __menuet__delay100(100);
return _seconds;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/sysconf.c
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
 
long
sysconf(int name)
{
switch (name)
{
case _SC_ARG_MAX: return ARG_MAX;
case _SC_CHILD_MAX: return CHILD_MAX;
case _SC_CLK_TCK: return CLOCKS_PER_SEC;
case _SC_NGROUPS_MAX: return NGROUPS_MAX;
case _SC_OPEN_MAX: return 255;
case _SC_JOB_CONTROL: return -1;
case _SC_SAVED_IDS: return -1;
case _SC_STREAM_MAX: return _POSIX_STREAM_MAX;
case _SC_TZNAME_MAX: return TZNAME_MAX;
case _SC_VERSION: return _POSIX_VERSION;
 
default:
errno = EINVAL;
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/ttyname.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
 
static char dev_con[] = "con";
 
/* ARGSUSED */
char *
ttyname(int fildes)
{
if (isatty(fildes))
return dev_con;
else
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/unlink.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(unlink)
jmp C_SYM(remove)
 
/programs/develop/libraries/menuetlibc/src/libc/posix/unistd/write.c
0,0 → 1,22
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <errno.h>
 
#include <libc/dosio.h>
#include <libc/bss.h>
 
#include<menuet/os.h>
#include<menuet/console.h>
 
static char *sbuf = 0;
static size_t sbuflen = 0;
 
static int write_count = -1;
 
ssize_t write(int handle, const void* buffer, size_t count)
{
return dosemu_write(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/posix/utime/Makefile
0,0 → 1,3
THIS_SRCS = utime.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/utime/utime.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <utime.h> /* For utime() */
#include <time.h> /* For localtime() */
#include <fcntl.h> /* For open() */
#include <unistd.h>
#include <errno.h> /* For errno */
 
/* An implementation of utime() for DJGPP. The utime() function
specifies an access time and a modification time. DOS has only one
time, so we will (arbitrarily) use the modification time. */
int
utime(const char *path, const struct utimbuf *times)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/posix/utsname/Makefile
0,0 → 1,3
THIS_SRCS = uname.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/posix/utsname/uname.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include <errno.h>
#include <dos.h>
 
int uname(struct utsname *u)
{
strncpy(u->sysname, "MenuetOS",8);
u->sysname[sizeof(u->sysname) - 1] = '\0';
sprintf(u->version, "0.47");
sprintf(u->release, "1.0");
strcpy(u->machine, "i386");
strcpy(u->nodename, "(none)");
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/termios/Makefile
0,0 → 1,3
THIS_SRCS = hooks.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/termios/hooks.c
0,0 → 1,7
#include<libc/ttyprvt.h>
 
ssize_t (*__libc_read_termios_hook)(int handle, void *buffer, size_t count,
ssize_t *rv)=NULL;
ssize_t (*__libc_write_termios_hook)(int handle, const void *buffer, size_t count,
ssize_t *rv)=NULL;
// int __libc_termios_hook_common_count;
/programs/develop/libraries/menuetlibc/src/libcon2/Makefile
0,0 → 1,35
THIS_SRCS = textcon.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
mk_lib: gen_tmp all
make -f Makefile-link OUTFILE="libcon2.a"
ifdef ON_MINGW
copy libcon2.a $(MENUETDEV)\lib
del libcon2.a
copy textcon.h $(MENUETDEV)\include\menuet
else
mv -f libcon2.a $(MENUETDEV)/lib
cp textcon.h $(MENUETDEV)/include/menuet
endif
 
dll: _gen_tmp all
make -f Makefile-link-dll OUTFILE="con-2.so"
ifdef ON_MINGW
copy libcon2.a $(MENUETDEV)\lib
del libcon2.a
else
mv con-2.so $(MENUETDEV)/lib
endif
 
_gen_tmp:
@$(D_ECHO) > ../tmp_make
 
gen_tmp:
ifdef ON_MINGW
@echo foo = bar> ..\tmp_make
@..\m_echo ..\tmp_make B_MENUET_LIBC_OBJS =
else
@echo "foo = bar" > ../tmp_make
@../m_echo ../tmp_make B_MENUET_LIBC_OBJS =
endif
/programs/develop/libraries/menuetlibc/src/libcon2/Makefile-link
0,0 → 1,4
include ../tmp_make
 
all:
ar rcs $(OUTFILE) $(B_MENUET_LIBC_OBJS)
/programs/develop/libraries/menuetlibc/src/libcon2/Makefile-link-dll
0,0 → 1,2
all:
ld -r -d -Bdynamic -o $(OUTFILE) @../tmp_make
/programs/develop/libraries/menuetlibc/src/libcon2/textcon.c
0,0 → 1,368
#include<menuet/os.h>
#include<stdlib.h>
#include"textcon.h"
 
console_t * consoles[MAX_CONSOLES];
console_t * visible_console;
 
static unsigned long color_conv_tbl[]=COLOR_CONV_B_2_D;
 
void init_consoles(void)
{
int i;
visible_console=NULL;
for(i=0;i<MAX_CONSOLES;i++)
{
consoles[i]=(console_t *)malloc(sizeof(console_t));
consoles[i]->text_color=7;
consoles[i]->back_color=1;
consoles[i]->id=i+1;
consoles[i]->cur_x=0;
consoles[i]->cur_y=0;
consoles[i]->cur_visible=1;
consoles[i]->cur_color=4;
consoles[i]->esc_seq.esc[0]=0;
consoles[i]->esc_seq.esc[1]=0;
consoles[i]->esc_seq.esc[2]=0;
consoles[i]->esc_seq.esc[3]=0;
fill_empty_sem(&consoles[i]->io_lock);
lcon_clrscr(consoles[i]);
}
visible_console=consoles[0];
lcon_flush_console(visible_console);
}
 
void lcon_flush_console(console_t * con)
{
int x,y;
int ax,ay;
char tbl[2];
unsigned long c1,c2;
if(con!=visible_console) return;
tbl[1]='\0';
for(y=0;y<NR_CHARS_Y;y++)
{
ay=CON_AT_Y+y*CHAR_SIZE_Y;
for(x=0;x<NR_CHARS_X;x++)
{
ax=CON_AT_X+x*CHAR_SIZE_X;
c1=color_conv_tbl[con->char_table[x][y].c_back];
tbl[0]=(char)con->char_table[x][y].c_char&0xFF;
if(con->cur_x==x && con->cur_y==y && con->cur_visible)
{
c2=c1;
c1=color_conv_tbl[con->cur_color];
} else {
c2=color_conv_tbl[con->char_table[x][y].c_color];
}
__menuet__bar(ax,ay,CHAR_SIZE_X,CHAR_SIZE_Y,c1);
__menuet__write_text(ax,ay,c2,tbl,1);
}
}
}
 
void lcon_clrscr(console_t * con)
{
int x,y;
if(!con) return;
for(y=0;y<NR_CHARS_Y;y++)
for(x=0;x<NR_CHARS_X;x++)
{
con->char_table[x][y].c_char=' ';
con->char_table[x][y].c_back=con->back_color;
con->char_table[x][y].c_color=con->text_color;
}
lcon_flush_console(con);
}
 
void lcon_flushxy(console_t * con,int x,int y)
{
char tbl[2];
int ax,ay;
unsigned long c1,c2;
if(con!=visible_console) return;
ay=CON_AT_Y+y*CHAR_SIZE_Y;
ax=CON_AT_X+x*CHAR_SIZE_X;
c1=color_conv_tbl[con->char_table[x][y].c_back];
tbl[0]=(char)con->char_table[x][y].c_char&0xFF;
if(con->cur_x==x && con->cur_y==y && con->cur_visible)
{
c2=c1;
c1=color_conv_tbl[con->cur_color];
} else {
c2=color_conv_tbl[con->char_table[x][y].c_color];
}
__menuet__bar(ax,ay,CHAR_SIZE_X,CHAR_SIZE_Y,c1);
__menuet__write_text(ax,ay,c2,tbl,1);
}
 
void lcon_scroll(console_t * con,int update)
{
int y,x;
for(y=0;y<NR_CHARS_Y-1;y++)
{
for(x=0;x<NR_CHARS_X;x++)
{
memcpy(&con->char_table[x][y],&con->char_table[x][y+1],sizeof(char_info_t));
}
}
for(x=0;x<NR_CHARS_X;x++)
{
con->char_table[x][NR_CHARS_Y-1].c_char=' ';
con->char_table[x][NR_CHARS_Y-1].c_color=con->text_color;
con->char_table[x][NR_CHARS_Y-1].c_back=con->back_color;
}
if(update) lcon_flush_console(con);
}
 
static int __con_update(console_t * con)
{
int m;
m=0;
if(con->cur_x<0 || con->cur_y<0)
{
if(con->cur_x<0)
{
con->cur_x=0;
}
if(con->cur_y<0)
{
con->cur_y=0;
}
m=1;
}
if(con->cur_x>=NR_CHARS_X)
{
con->cur_y++;
con->cur_x=0;
m=1;
if(con->cur_y>=NR_CHARS_Y)
{
con->cur_y=NR_CHARS_Y-1;
lcon_scroll(con,0);
}
}
return m;
}
 
void __lcon_putch_raw(console_t * con,char c)
{
int tx,ty;
__con_update(con);
tx=con->cur_x;
ty=con->cur_y;
if(c=='\r')
{
con->cur_x=0;
} else if(c=='\n')
{
con->cur_x=0;
con->cur_y++;
} else if(c=='\t')
{
con->cur_x=(con->cur_x+8)&~(8-1);
} else if(c=='\b')
{
con->cur_x--;
if(con->cur_x<0)
{
con->cur_y--;
con->cur_x=0;
}
if(con->cur_y<0)
{
con->cur_y=0;
}
} else {
con->char_table[con->cur_x][con->cur_y].c_char=c;
con->char_table[con->cur_x][con->cur_y].c_color=con->text_color;
con->char_table[con->cur_x][con->cur_y].c_back=con->back_color;
con->cur_x++;
}
if(__con_update(con))
{
lcon_flush_console(con);
} else {
lcon_flushxy(con,tx,ty);
if(con->cur_visible) lcon_flushxy(con,con->cur_x,con->cur_y);
}
}
 
void lcon_gotoxy(console_t * con,int x,int y)
{
int ox,oy;
if(x<0 || x>=NR_CHARS_X || y<0 || y>=NR_CHARS_Y) return;
ox=con->cur_x;
oy=con->cur_y;
con->cur_x=x;
con->cur_y=y;
if(con->cur_visible)
{
lcon_flushxy(con,ox,oy);
lcon_flushxy(con,x,y);
}
}
 
void lcon_set_text_color(console_t * con,int color)
{
con->text_color=color&0xFF;
}
 
void lcon_set_back_color(console_t * con,int color)
{
con->back_color=color&0xFF;
}
 
void lcon_switch_to_console(int i)
{
if(i<0 || i>=MAX_CONSOLES || !consoles[i]) return;
visible_console=consoles[i];
lcon_flush_console(visible_console);
}
 
unsigned char lcon_getcxy(console_t * con,int x,int y)
{
if(x<0 || x>=NR_CHARS_X || y<0 || y>=NR_CHARS_Y) return;
return con->char_table[x][y].c_char;
}
 
void lcon_putcxy(console_t * con,int x,int y,unsigned char c)
{
if(x<0 || x>=NR_CHARS_X || y<0 || y>=NR_CHARS_Y) return;
con->char_table[x][y].c_char=c;
con->char_table[x][y].c_color=con->text_color;
con->char_table[x][y].c_back=con->back_color;
}
 
static void lcon_set_attrib(console_t * con,unsigned char Att)
{
static const unsigned ansi_to_vga[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
if(Att>=30 && Att<=37)
{
con->text_color=ansi_to_vga[Att-30];
} else if(Att>=40 && Att<=48)
{
con->back_color=ansi_to_vga[Att-40];
}
}
 
#undef isdigit
#define isdigit(c) ((c)>='0' && (c)<='9')
 
void __lcon_putch_help(console_t * con,unsigned char c)
{
if(con->esc_seq.esc[0]==1)
{
if(c=='[')
{
con->esc_seq.esc[0]++;
con->esc_seq.esc[1]=0;
return;
}
} else if(con->esc_seq.esc[0]==2)
{
if(isdigit(c))
{
con->esc_seq.esc[1]=con->esc_seq.esc[1]*10+c-'0';
return;
} else if(c==';')
{
con->esc_seq.esc[0]++;
con->esc_seq.esc[2]=0;
return;
} else if(c=='J')
{
if(con->esc_seq.esc[1]==2)
{
lcon_clrscr(con);
lcon_gotoxy(con,0,0);
}
} else if(c=='m') lcon_set_attrib(con,con->esc_seq.esc[1]);
con->esc_seq.esc[0]=0;
return;
} else if(con->esc_seq.esc[0]==3)
{
if(isdigit(c))
{
con->esc_seq.esc[2]=(con->esc_seq.esc[2]*10)+c-'0';
return;
} else if(c==';')
{
con->esc_seq.esc[0]++;
con->esc_seq.esc[3]=0;
return;
} else if(c=='H')
{
int nx,ny;
if(con->esc_seq.esc[2]<NR_CHARS_X)
nx=con->esc_seq.esc[2]; else nx=con->cur_x;
if(con->esc_seq.esc[1]<NR_CHARS_Y)
ny=con->esc_seq.esc[1]; else ny=con->cur_y;
lcon_gotoxy(con,nx,ny);
} else if(c=='m')
{
lcon_set_attrib(con,con->esc_seq.esc[1]);
lcon_set_attrib(con,con->esc_seq.esc[2]);
}
con->esc_seq.esc[0]=0;
return;
} else if(con->esc_seq.esc[0]==4)
{
if(isdigit(c))
{
con->esc_seq.esc[3]=con->esc_seq.esc[3]*10+c-'0';
return;
} else if(c=='m')
{
lcon_set_attrib(con,con->esc_seq.esc[1]);
lcon_set_attrib(con,con->esc_seq.esc[2]);
lcon_set_attrib(con,con->esc_seq.esc[3]);
}
con->esc_seq.esc[0]=0;
return;
}
con->esc_seq.esc[0]=0;
if(c==0x1B)
{
con->esc_seq.esc[0]=1;
return;
}
__lcon_putch_raw(con,c);
}
 
void lcon_putch(console_t * con,char c)
{
sem_lock(&con->io_lock);
__lcon_putch_help(con,c);
sem_unlock(&con->io_lock);
}
 
console_t * create_private_console(void)
{
console_t * con=(console_t *)malloc(sizeof(console_t));
if(!con) return NULL;
con->id=MAX_CONSOLES|0x8000;
con->cur_x=0;
con->cur_y=0;
con->cur_visible=0;
con->cur_color=3;
con->text_color=3;
con->back_color=1;
con->esc_seq.esc[0]=0;
con->esc_seq.esc[1]=0;
con->esc_seq.esc[2]=0;
con->esc_seq.esc[3]=0;
fill_empty_sem(&con->io_lock);
lcon_clrscr(con);
return con;
}
 
void free_private_console(console_t * con)
{
if(con)
{
sem_lock(&con->io_lock); /* Wait for lock release and lock it */
sem_unlock(&con->io_lock); /* Unlock immediately */
free((void *)con); /* Free structure */
}
}
/programs/develop/libraries/menuetlibc/src/libcon2/textcon.h
0,0 → 1,91
#ifndef __TEXTCON_H
#define __TEXTCON_H
 
#include<menuet/sem.h>
 
#define COLOR_CONV_B_2_D { \
0x000000, \
0x000080, \
0x800000, \
0x008080, \
0x800000, \
0x808000, \
0x404040, \
0x808080, \
0x606060, \
0x0000FF, \
0x00FF00, \
0x00FFFF, \
0xFF0000, \
0xFFFF00, \
0x00FFFF, \
0xFFFFFF, \
}
 
#define CHAR_SIZE_X 5
#define CHAR_SIZE_Y 8
 
#define NR_CHARS_X 80
#define NR_CHARS_Y 25
 
#define CON_AT_X 10
#define CON_AT_Y 25
 
typedef struct
{
unsigned char c_char;
unsigned char c_back;
unsigned char c_color;
} char_info_t;
 
typedef struct
{
int esc[4];
} esc_info_t;
 
typedef struct
{
unsigned char text_color,back_color;
char_info_t char_table[NR_CHARS_X][NR_CHARS_Y];
int id;
int cur_x,cur_y;
int cur_visible;
unsigned char cur_color;
esc_info_t esc_seq;
DECLARE_SEMAPHORE_S(io_lock);
} console_t;
 
#define MAX_CONSOLES 4
 
extern console_t * consoles[MAX_CONSOLES];
extern console_t * visible_console;
 
void init_consoles(void);
void lcon_clrscr(console_t * con);
void lcon_flush_console(console_t * con);
void lcon_flushxy(console_t * con,int x,int y);
void lcon_scroll(console_t * con,int update);
void lcon_putch(console_t * con,char c);
void lcon_gotoxy(console_t * con,int x,int y);
void lcon_set_text_color(console_t * con,int color);
void lcon_set_back_color(console_t * con,int color);
void lcon_switch_to_console(int i);
unsigned char lcon_getcxy(console_t * con,int x,int y);
void lcon_putcxy(console_t * con,int x,int y,unsigned char c);
 
#define _lcon_clrscr() lcon_clrscr(visible_console)
#define _lcon_flush_console() lcon_flush_console(visible_console)
#define _lcon_flushxy(x,y) lcon_flushxy(visible_console,(x),(y))
#define _lcon_scroll() lcon_scroll(visible_console,1)
#define _lcon_putch(c) lcon_putch(visible_console,(char)(c))
#define _lcon_gotoxy(x,y) lcon_gotoxy(visible_console,(x),(y))
#define _lcon_set_text_color(c) lcon_set_text_color(visible_console,(c)&(1+2+4+8))
#define _lcon_set_back_color(c) lcon_set_back_color(visible_console,(c)&(1+2+4+8))
#define _lcon_switch(i) lcon_switch_to_console((i))
#define _lcon_getcxy(x,y) lcon_getcxy(visible_console,(x),(y))
#define _lcon_putcxy(x,y,c) lcon_putcxy(visible_console,(x),(y),(c))
 
console_t * create_private_console(void);
void free_private_console(console_t * con);
 
#endif
/programs/develop/libraries/menuetlibc/src/libcpp/Makefile
0,0 → 1,38
include $(MENUETDEV)/osrules.mak
ifdef ON_MINGW
THIS_SRCS = new.cpp delete.cpp net\ip_addr.cpp net\udp_socket.cpp
else
THIS_SRCS = new.cpp delete.cpp net/ip_addr.cpp net/udp_socket.cpp
endif
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
mk_lib: gen_tmp all
make -f Makefile-link OUTFILE="libcpp.a"
ifdef ON_MINGW
copy libcpp.a $(MENUETDEV)\lib
del libcpp.a
else
mv -f libcpp.a $(MENUETDEV)/lib
endif
 
dll: _gen_tmp all
make -f Makefile-link-dll OUTFILE="cpp-glue.so"
ifdef ON_MINGW
copy cpp-glue.so $(MENUETDEV)\lib
del cpp-glue.so
else
mv cpp-glue.so $(MENUETDEV)/lib
endif
 
_gen_tmp:
@$(D_ECHO) > ../tmp_make
 
gen_tmp:
ifdef ON_MINGW
@echo foo = bar> ..\tmp_make
@..\m_echo ..\tmp_make B_MENUET_LIBC_OBJS =
else
@echo "foo = bar" > ../tmp_make
@../m_echo ../tmp_make B_MENUET_LIBC_OBJS =
endif
/programs/develop/libraries/menuetlibc/src/libcpp/Makefile-link
0,0 → 1,4
include ../tmp_make
 
all:
ar rcs $(OUTFILE) $(B_MENUET_LIBC_OBJS)
/programs/develop/libraries/menuetlibc/src/libcpp/Makefile-link-dll
0,0 → 1,2
all:
ld -r -d -Bdynamic -o $(OUTFILE) @../tmp_make
/programs/develop/libraries/menuetlibc/src/libcpp/delete.cpp
0,0 → 1,37
extern "C" {
#include<assert.h>
}
 
extern "C" void free(void *);
extern "C" void __menuet__sys_exit(void);
 
void operator delete(void * ptr)
{
free(ptr);
}
 
void operator delete[](void * ptr)
{
free(ptr);
}
 
static bool pure_virtual_call=false;
 
extern "C" {
extern "C" void __menuet__sys_exit();
void __cxa_pure_virtual(void)
{
assert(!pure_virtual_call);
__menuet__sys_exit();
}
void _pure_virtual(void)
{
assert(!pure_virtual_call);
__menuet__sys_exit();
}
void __pure_virtual(void)
{
assert(!pure_virtual_call);
__menuet__sys_exit();
}
}
/programs/develop/libraries/menuetlibc/src/libcpp/net/ip_addr.cpp
0,0 → 1,32
#include<menuet/network.hpp>
 
IP_Address::IP_Address(unsigned long addr)
{
this_ip_inet_fmt=addr;
}
 
IP_Address::IP_Address(__u8 p1,__u8 p2,__u8 p3,__u8 p4)
{
this_ip_inet_fmt=p4;
this_ip_inet_fmt<<=8;
this_ip_inet_fmt|=p3;
this_ip_inet_fmt<<=8;
this_ip_inet_fmt|=p2;
this_ip_inet_fmt<<=8;
this_ip_inet_fmt|=p1;
}
 
IP_Address::~IP_Address()
{
}
 
unsigned long IP_Address::operator = (IP_Address& a)
{
return a.this_ip_inet_fmt;
}
 
IP_Address& IP_Address::operator = (unsigned long a)
{
this->this_ip_inet_fmt=a;
return *this;
}
/programs/develop/libraries/menuetlibc/src/libcpp/net/udp_socket.cpp
0,0 → 1,39
#include<menuet/network.hpp>
 
UDP_Socket::UDP_Socket(__u32 local_port,__u32 remote_port,__u32 remote_ip,bool close_on_delete)
{
this->p[0]=local_port;
this->p[1]=remote_port;
this->p[2]=remote_ip;
this->f=close_on_delete;
}
 
UDP_Socket::~UDP_Socket()
{
if(this->f) this->Close();
}
 
int UDP_Socket::Open()
{
return (sock=__menuet__open_UDP_socket(p[0],p[1],p[2]));
}
 
int UDP_Socket::Close()
{
return __menuet__close_UDP_socket(sock);
}
 
int UDP_Socket::Read(__u8 * data)
{
return __menuet__read_socket(sock,data);
}
 
int UDP_Socket::Write(int count,void * data)
{
return __menuet__write_UDP_socket(sock,count,data);
}
 
int UDP_Socket::Poll()
{
return __menuet__poll_socket(sock);
}
/programs/develop/libraries/menuetlibc/src/libcpp/new.cpp
0,0 → 1,13
#include<sys/types.h>
 
extern "C" void * malloc(unsigned int);
 
void * operator new(unsigned int n)
{
return malloc(n);
}
 
void * operator new[](unsigned int n)
{
return malloc(n);
}
/programs/develop/libraries/menuetlibc/src/libipc/Makefile
0,0 → 1,5
OUTFILE = $(MENUETDEV)/lib/libipc.a
OBJS = hdr.o send.o recv.o
CFLAGS = -O2 -fomit-frame-pointer
 
include $(MENUETDEV)/makefiles/Makefile_for_lib
/programs/develop/libraries/menuetlibc/src/libipc/hdr.c
0,0 → 1,21
#include"ipc.h"
#include<stdlib.h>
 
ipc_hdr_t * create_ipc(unsigned long size)
{
ipc_hdr_t * hdr=(ipc_hdr_t *)malloc(size+sizeof(ipc_hdr_t));
if(!hdr) return NULL;
hdr->lock=0;
hdr->free_ptr=8;
return hdr;
}
 
void register_ipc_mem(ipc_hdr_t * hdr)
{
int d0,d1,d2;
__asm__ __volatile__(
"int $0x40"
:"=a"(d0),"=b"(d1),"=c"(d2)
:"0"(60),"1"(1),"2"(hdr)
:"memory");
}
/programs/develop/libraries/menuetlibc/src/libipc/ipc.h
0,0 → 1,21
#ifndef __MENUETOS_IPC_H
#define __MENUETOS_IPC_H
 
typedef struct {
volatile unsigned long lock;
unsigned long free_ptr;
char __mem[0];
} ipc_hdr_t;
 
typedef struct {
unsigned long sender_pid;
unsigned long msg_length;
char message[0];
} ipc_msg_t;
 
ipc_hdr_t * create_ipc(unsigned long size);
void register_ipc_mem(ipc_hdr_t * hdr);
void ipc_send_message(int dst_pid,ipc_msg_t * msg);
extern inline int ipc_messages_avail(ipc_hdr_t * hdr);
 
#endif
/programs/develop/libraries/menuetlibc/src/libipc/recv.c
0,0 → 1,58
#include"ipc.h"
#include<stdlib.h>
#include<string.h>
 
inline int ipc_messages_avail(ipc_hdr_t * hdr)
{
return hdr->free_ptr!=8;
}
 
static inline void lock_msg_queue(ipc_hdr_t * hdr)
{
int d0;
__asm__ __volatile__(
"2:\t"
"movb $1,%%al\n\t"
"xchgb %%al,%0\n\t"
"andb %%al,%%al\n\t"
"jnz 2b\n\t"
"incb %0"
:"=m"(hdr->lock),"=a"(d0)
:"m"(hdr->lock)
:"memory");
}
 
static inline void unlock_msg_queue(ipc_hdr_t * hdr)
{
__asm__ __volatile__(
"movl $0,%0"
:"=m"(hdr->lock)
:"m"(hdr->lock)
:"memory");
}
 
ipc_msg_t * ipc_receive_msg(ipc_hdr_t * hdr)
{
ipc_msg_t * msg, * tmp;
lock_msg_queue(hdr);
if(!ipc_messages_avail(hdr))
{
unlock_msg_queue(hdr);
return NULL;
}
tmp=(ipc_msg_t *)hdr->__mem;
msg=(ipc_msg_t *)malloc(tmp->msg_length);
if(!msg)
{
unlock_msg_queue(hdr);
return NULL;
}
memcpy(msg,tmp,tmp->msg_length);
if(hdr->free_ptr>(8+tmp->msg_length))
{
memcpy(tmp,tmp+1,hdr->free_ptr-8-tmp->msg_length);
hdr->free_ptr-=tmp->msg_length;
}
unlock_msg_queue(hdr);
return msg;
}
/programs/develop/libraries/menuetlibc/src/libipc/send.c
0,0 → 1,13
#include"ipc.h"
#include<stdlib.h>
 
void ipc_send_message(int dst_pid,ipc_msg_t * msg)
{
int d0,d1,d2,d3,d4;
__asm__ __volatile__(
"addl $4,%%edx\n\t"
"int $0x40"
:"=a"(d0),"=b"(d1),"=c"(d2),"=d"(d3),"=S"(d4)
:"0"(60),"1"(2),"2"(dst_pid),"3"(msg),"4"(msg->msg_length)
:"memory");
}
/programs/develop/libraries/menuetlibc/src/libm/Makefile
0,0 → 1,62
CFLAGS = -D_USE_LIBM_MATH_H
CSFLAGS = $(CFLAGS)
 
THIS_SRCS = e_acosh.c e_acos.s e_asin.s e_atan2.s e_atanh.c e_cosh.c e_exp.s \
ef_acos.c ef_acosh.c ef_asin.c ef_atan2.s ef_atanh.c ef_cosh.c ef_exp.s \
ef_fmod.s ef_gamma.c ef_hypot.c ef_j0.c ef_j1.c ef_jn.c ef_lgamm.c ef_log10.s \
ef_log.s e_fmod.s ef_pow.c ef_remai.s ef_rem_p.c ef_scalb.s ef_sinh.c \
ef_sqrt.s e_gamma.c e_hypot.c e_j0.c e_j1.c e_jn.c e_lgamma.c e_log10.s \
e_log.s e_pow.c e_remain.s e_rem_pi.c erf_gamm.c erf_lgam.c er_gamma.c \
er_lgamm.c e_scalb.s e_sinh.c e_sqrt.s k_cos.c kf_cos.c kf_rem_p.c kf_sin.c \
kf_tan.c k_rem_pi.c k_sin.c k_standa.c k_tan.c s_asinh.c s_atan.s s_cbrt.c \
s_ceil.s s_copysi.s s_cos.s s_erf.c s_expm1.s s_fabs.c sf_asinh.c sf_atan.s \
sf_cbrt.c sf_ceil.s sf_copys.s sf_cos.s sf_erf.c sf_expm1.s sf_fabs.c \
sf_finit.s sf_floor.s sf_frexp.c sf_ilogb.s s_finite.s sf_isinf.c sf_isnan.c \
sf_ldexp.c sf_log1p.s sf_logb.s s_floor.s sf_modf.c sf_nexta.c s_frexp.c \
sf_rint.s sf_scalb.s sf_signi.s sf_sin.s sf_tanh.c sf_tan.s s_ilogb.s s_infini.c \
s_isinf.c s_isnan.c s_ldexp.c s_libver.c s_log1p.s s_logb.s s_mather.c \
s_modf.c s_nextaf.c s_rint.s s_scalbn.s s_signga.c s_signif.s s_sin.s \
s_tanh.c s_tan.s w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c \
w_cabs.c w_cosh.c w_drem.c w_exp.c wf_acos.c wf_acosh.c wf_asin.c \
wf_atan2.c wf_atanh.c wf_cabs.c wf_cosh.c wf_drem.c wf_exp.c wf_fmod.c \
wf_gamma.c wf_hypot.c wf_j0.c wf_j1.c wf_jn.c wf_lgamm.c wf_log10.c wf_log.c \
w_fmod.c wf_pow.c wf_remai.c wf_scalb.c wf_sinh.c wf_sqrt.c w_gamma.c w_hypot.c \
w_j0.c w_j1.c w_jn.c w_lgamma.c w_log10.c w_log.c w_pow.c w_remain.c \
wrf_gamm.c wrf_lgam.c wr_gamma.c wr_lgamm.c w_scalb.c w_sinh.c \
w_sqrt.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
mk_lib: gen_tmp all
make -f Makefile-link OUTFILE="libm.a"
ifdef ON_MINGW
copy libm.a $(MENUETDEV)\lib
del libm.a
else
mv -f libm.a $(MENUETDEV)/lib
endif
 
dll: _gen_tmp all
make -f Makefile-link-dll OUTFILE="libm.so"
ifdef ON_MINGW
copy libm.so $(MENUETDEV)\lib
del libm.so
else
mv -f libm.so $(MENUETDEV)/lib
endif
 
_gen_tmp:
ifdef ON_MINGW
@$(D_ECHO) > ..\tmp_make
else
@$(D_ECHO) > ../tmp_make
endif
 
gen_tmp:
ifdef ON_MINGW
@echo foo = bar> ../tmp_make
@..\m_echo ..\tmp_make B_MENUET_LIBC_OBJS =
else
@echo "foo = bar" > ../tmp_make
@../m_echo ../tmp_make B_MENUET_LIBC_OBJS =
endif
/programs/develop/libraries/menuetlibc/src/libm/Makefile-link
0,0 → 1,4
include ../tmp_make
 
all:
ar rcs $(OUTFILE) $(B_MENUET_LIBC_OBJS)
/programs/develop/libraries/menuetlibc/src/libm/Makefile-link-dll
0,0 → 1,2
all:
ld -r -d -Bdynamic -o $(OUTFILE) @../tmp_make
/programs/develop/libraries/menuetlibc/src/libm/e_acos.s
0,0 → 1,12
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_acos)
fldl 4(%esp)
fst %st(1)
fmul %st(0)
fld1
fsubp
fsqrt
fxch %st(1)
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/e_acosh.c
0,0 → 1,70
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_acosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_acosh.c,v 1.6 1994/08/18 23:04:54 jtc Exp $";
#endif
 
/* __ieee754_acosh(x)
* Method :
* Based on
* acosh(x) = log [ x + sqrt(x*x-1) ]
* we have
* acosh(x) := log(x)+ln2, if x is large; else
* acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
* acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
*
* Special cases:
* acosh(x) is NaN with signal if x<1.
* acosh(NaN) is NaN without signal.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.0,
ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
 
#ifdef __STDC__
double __ieee754_acosh(double x)
#else
double __ieee754_acosh(x)
double x;
#endif
{
double t;
int32_t hx;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
if(hx<0x3ff00000) { /* x < 1 */
return (x-x)/(x-x);
} else if(hx >=0x41b00000) { /* x > 2**28 */
if(hx >=0x7ff00000) { /* x is inf of NaN */
return x+x;
} else
return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
} else if(((hx-0x3ff00000)|lx)==0) {
return 0.0; /* acosh(1) = 0 */
} else if (hx > 0x40000000) { /* 2**28 > x > 2 */
t=x*x;
return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
} else { /* 1<x<2 */
t = x-one;
return log1p(t+sqrt(2.0*t+t*t));
}
}
/programs/develop/libraries/menuetlibc/src/libm/e_asin.s
0,0 → 1,11
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_asin)
fldl 4(%esp)
fst %st(1)
fmul %st(0)
fld1
fsubp
fsqrt
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/e_atan2.s
0,0 → 1,7
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_atan2)
fldl 4(%esp)
fldl 12(%esp)
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/e_atanh.c
0,0 → 1,75
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_atanh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_atanh.c,v 1.6 1994/08/18 23:05:12 jtc Exp $";
#endif
 
/* __ieee754_atanh(x)
* Method :
* 1.Reduced x to positive by atanh(-x) = -atanh(x)
* 2.For x>=0.5
* 1 2x x
* atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
* 2 1 - x 1 - x
*
* For x<0.5
* atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
*
* Special cases:
* atanh(x) is NaN if |x| > 1 with signal;
* atanh(NaN) is that NaN with no signal;
* atanh(+-1) is +-INF with signal.
*
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double one = 1.0, huge = 1e300;
#else
static double one = 1.0, huge = 1e300;
#endif
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_atanh(double x)
#else
double __ieee754_atanh(x)
double x;
#endif
{
double t;
int32_t hx,ix;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
ix = hx&0x7fffffff;
if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
return (x-x)/(x-x);
if(ix==0x3ff00000)
return x/zero;
if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
SET_HIGH_WORD(x,ix);
if(ix<0x3fe00000) { /* x < 0.5 */
t = x+x;
t = 0.5*log1p(t+t*x/(one-x));
} else
t = 0.5*log1p((x+x)/(one-x));
if(hx>=0) return t; else return -t;
}
/programs/develop/libraries/menuetlibc/src/libm/e_cosh.c
0,0 → 1,94
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_cosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_cosh.c,v 1.5 1994/08/18 23:05:15 jtc Exp $";
#endif
 
/* __ieee754_cosh(x)
* Method :
* mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
* 1. Replace x by |x| (cosh(x) = cosh(-x)).
* 2.
* [ exp(x) - 1 ]^2
* 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
* 2*exp(x)
*
* exp(x) + 1/exp(x)
* ln2/2 <= x <= 22 : cosh(x) := -------------------
* 2
* 22 <= x <= lnovft : cosh(x) := exp(x)/2
* lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
* ln2ovft < x : cosh(x) := huge*huge (overflow)
*
* Special cases:
* cosh(x) is |x| if x is +INF, -INF, or NaN.
* only cosh(0)=1 is exact for finite x.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double one = 1.0, half=0.5, huge = 1.0e300;
#else
static double one = 1.0, half=0.5, huge = 1.0e300;
#endif
 
#ifdef __STDC__
double __ieee754_cosh(double x)
#else
double __ieee754_cosh(x)
double x;
#endif
{
double t,w;
int32_t ix;
u_int32_t lx;
 
/* High word of |x|. */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7ff00000) return x*x;
 
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
if(ix<0x3fd62e43) {
t = expm1(fabs(x));
w = one+t;
if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
return one+(t*t)/(w+w);
}
 
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
if (ix < 0x40360000) {
t = __ieee754_exp(fabs(x));
return half*t+half/t;
}
 
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE ||
((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87dU))) {
w = __ieee754_exp(half*fabs(x));
t = half*w;
return t*w;
}
 
/* |x| > overflowthresold, cosh(x) overflow */
return huge*huge;
}
/programs/develop/libraries/menuetlibc/src/libm/e_exp.s
0,0 → 1,15
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_exp)
fldl 4(%esp)
fldl2e
fmulp
fstl %st(1)
frndint
fstl %st(2)
fsubrp
f2xm1
fld1
faddp
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/e_fmod.s
0,0 → 1,10
#include<libc/asm.h>
MK_C_SYM(__ieee754_fmod)
fldl 12(%esp)
fldl 4(%esp)
1: fprem
fstsw %ax
sahf
jp 1b
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/e_gamma.c
0,0 → 1,38
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_gamma.c,v 1.4 1994/08/10 20:30:51 jtc Exp $";
#endif
 
/* __ieee754_gamma(x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_gamma_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
double __ieee754_gamma(double x)
#else
double __ieee754_gamma(x)
double x;
#endif
{
return __ieee754_gamma_r(x,&signgam);
}
/programs/develop/libraries/menuetlibc/src/libm/e_hypot.c
0,0 → 1,129
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_hypot.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_hypot.c,v 1.6 1994/08/18 23:05:24 jtc Exp $";
#endif
 
/* __ieee754_hypot(x,y)
*
* Method :
* If (assume round-to-nearest) z=x*x+y*y
* has error less than sqrt(2)/2 ulp, than
* sqrt(z) has error less than 1 ulp (exercise).
*
* So, compute sqrt(x*x+y*y) with some care as
* follows to get the error below 1 ulp:
*
* Assume x>y>0;
* (if possible, set rounding to round-to-nearest)
* 1. if x > 2y use
* x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y
* where x1 = x with lower 32 bits cleared, x2 = x-x1; else
* 2. if x <= 2y use
* t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
* where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1,
* y1= y with lower 32 bits chopped, y2 = y-y1.
*
* NOTE: scaling may be necessary if some argument is too
* large or too tiny
*
* Special cases:
* hypot(x,y) is INF if x or y is +INF or -INF; else
* hypot(x,y) is NAN if x or y is NAN.
*
* Accuracy:
* hypot(x,y) returns sqrt(x^2+y^2) with error less
* than 1 ulps (units in the last place)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double __ieee754_hypot(double x, double y)
#else
double __ieee754_hypot(x,y)
double x, y;
#endif
{
double a=x,b=y,t1,t2,y1a,y2,w;
int32_t j,k,ha,hb;
 
GET_HIGH_WORD(ha,x);
ha &= 0x7fffffff;
GET_HIGH_WORD(hb,y);
hb &= 0x7fffffff;
if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
SET_HIGH_WORD(a,ha); /* a <- |a| */
SET_HIGH_WORD(b,hb); /* b <- |b| */
if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */
k=0;
if(ha > 0x5f300000) { /* a>2**500 */
if(ha >= 0x7ff00000) { /* Inf or NaN */
u_int32_t low;
w = a+b; /* for sNaN */
GET_LOW_WORD(low,a);
if(((ha&0xfffff)|low)==0) w = a;
GET_LOW_WORD(low,b);
if(((hb^0x7ff00000)|low)==0) w = b;
return w;
}
/* scale a and b by 2**-600 */
ha -= 0x25800000; hb -= 0x25800000; k += 600;
SET_HIGH_WORD(a,ha);
SET_HIGH_WORD(b,hb);
}
if(hb < 0x20b00000) { /* b < 2**-500 */
if(hb <= 0x000fffff) { /* subnormal b or 0 */
u_int32_t low;
GET_LOW_WORD(low,b);
if((hb|low)==0) return a;
t1=0;
SET_HIGH_WORD(t1,0x7fd00000); /* t1=2^1022 */
b *= t1;
a *= t1;
k -= 1022;
} else { /* scale a and b by 2^600 */
ha += 0x25800000; /* a *= 2^600 */
hb += 0x25800000; /* b *= 2^600 */
k -= 600;
SET_HIGH_WORD(a,ha);
SET_HIGH_WORD(b,hb);
}
}
/* medium size a and b */
w = a-b;
if (w>b) {
t1 = 0;
SET_HIGH_WORD(t1,ha);
t2 = a-t1;
w = sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
} else {
a = a+a;
y1a = 0;
SET_HIGH_WORD(y1a,hb);
y2 = b - y1a;
t1 = 0;
SET_HIGH_WORD(t1,ha+0x00100000);
t2 = a - t1;
w = sqrt(t1*y1a-(w*(-w)-(t1*y2+t2*b)));
}
if(k!=0) {
u_int32_t high;
t1 = 1.0;
GET_HIGH_WORD(high,t1);
SET_HIGH_WORD(t1,high+(k<<20));
return t1*w;
} else return w;
}
/programs/develop/libraries/menuetlibc/src/libm/e_j0.c
0,0 → 1,488
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_j0.c,v 1.6 1994/08/18 23:05:29 jtc Exp $";
#endif
 
/* __ieee754_j0(x), __ieee754_y0(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j0(x):
* 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
* 2. Reduce x to |x| since j0(x)=j0(-x), and
* for x in (0,2)
* j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x;
* (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
* for x in (2,inf)
* j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* as follow:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (cos(x) + sin(x))
* sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j0(nan)= nan
* j0(0) = 1
* j0(inf) = 0
*
* Method -- y0(x):
* 1. For x<2.
* Since
* y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
* therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
* We use the following function to approximate y0,
* y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
* where
* U(z) = u00 + u01*z + ... + u06*z^6
* V(z) = 1 + v01*z + ... + v04*z^4
* with absolute approximation error bounded by 2**-72.
* Note: For tiny x, U/V = u0 and j0(x)~1, hence
* y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
* 2. For x>=2.
* y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* by the method mentioned above.
* 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static double pzero(double), qzero(double);
#else
static double pzero(), qzero();
#endif
 
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0, 2.00] */
R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */
S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */
S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */
S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */
S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_j0(double x)
#else
double __ieee754_j0(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v;
int32_t hx,ix;
 
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/(x*x);
x = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*cc-v*ss)/sqrt(x);
}
return z;
}
if(ix<0x3f200000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x3e400000) return one; /* |x|<2**-27 */
else return one - 0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3FF00000) { /* |x| < 1.00 */
return one + z*(-0.25+(r/s));
} else {
u = 0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
 
#ifdef __STDC__
static const double
#else
static double
#endif
u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
 
#ifdef __STDC__
double __ieee754_y0(double x)
#else
double __ieee754_y0(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
int32_t hx,ix,lx;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
}
return z;
}
if(ix<=0x3e400000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_log(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));
}
 
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */
-8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */
-2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */
-2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */
-5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */
};
#ifdef __STDC__
static const double pS8[5] = {
#else
static double pS8[5] = {
#endif
1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */
3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */
4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */
1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */
4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */
};
 
#ifdef __STDC__
static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */
-7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */
-4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */
-6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */
-3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */
-3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */
};
#ifdef __STDC__
static const double pS5[5] = {
#else
static double pS5[5] = {
#endif
6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */
1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */
5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */
9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */
2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */
};
 
#ifdef __STDC__
static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */
-7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */
-2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */
-2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */
-5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */
-3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */
};
#ifdef __STDC__
static const double pS3[5] = {
#else
static double pS3[5] = {
#endif
3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */
3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */
1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */
1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */
1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */
};
 
#ifdef __STDC__
static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */
-7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */
-1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */
-7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */
-1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */
-3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */
};
#ifdef __STDC__
static const double pS2[5] = {
#else
static double pS2[5] = {
#endif
2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */
1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */
2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */
1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */
1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
};
 
#ifdef __STDC__
static double pzero(double x)
#else
static double pzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pR8; q= pS8;}
else if(ix>=0x40122E8B){p = pR5; q= pS5;}
else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
else if(ix>=0x40000000){p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate pzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */
1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */
5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */
8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */
3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */
};
#ifdef __STDC__
static const double qS8[6] = {
#else
static double qS8[6] = {
#endif
1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */
8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */
1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */
8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */
8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */
-3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */
};
 
#ifdef __STDC__
static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */
7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */
5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */
1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */
1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */
1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */
};
#ifdef __STDC__
static const double qS5[6] = {
#else
static double qS5[6] = {
#endif
8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */
2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */
1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */
5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */
3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */
-5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */
};
 
#ifdef __STDC__
static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */
7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */
3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */
4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */
1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */
1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */
};
#ifdef __STDC__
static const double qS3[6] = {
#else
static double qS3[6] = {
#endif
4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */
7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */
3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */
6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */
2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */
-1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */
};
 
#ifdef __STDC__
static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */
7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */
1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */
1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */
3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */
1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */
};
#ifdef __STDC__
static const double qS2[6] = {
#else
static double qS2[6] = {
#endif
3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */
2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */
8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */
8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */
2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */
-5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
};
 
#ifdef __STDC__
static double qzero(double x)
#else
static double qzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qR8; q= qS8;}
else if(ix>=0x40122E8B){p = qR5; q= qS5;}
else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
else if(ix>=0x40000000){p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-.125 + r/s)/x;
}
/programs/develop/libraries/menuetlibc/src/libm/e_j1.c
0,0 → 1,487
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_j1.c,v 1.6 1994/08/18 23:05:33 jtc Exp $";
#endif
 
/* __ieee754_j1(x), __ieee754_y1(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j1(x):
* 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
* 2. Reduce x to |x| since j1(x)=-j1(-x), and
* for x in (0,2)
* j1(x) = x/2 + x*z*R0/S0, where z = x*x;
* (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 )
* for x in (2,inf)
* j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* as follow:
* cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (sin(x) + cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j1(nan)= nan
* j1(0) = 0
* j1(inf) = 0
*
* Method -- y1(x):
* 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
* 2. For x<2.
* Since
* y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
* therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
* We use the following function to approximate y1,
* y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
* where for x in [0,2] (abs err less than 2**-65.89)
* U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
* V(z) = 1 + v0[0]*z + ... + v0[4]*z^5
* Note: For tiny x, 1/x dominate y1 and hence
* y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
* 3. For x>=2.
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* by method mentioned above.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static double pone(double), qone(double);
#else
static double pone(), qone();
#endif
 
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0,2] */
r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */
r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */
r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */
r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */
s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */
s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */
s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */
s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */
s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_j1(double x)
#else
double __ieee754_j1(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v,y;
int32_t hx,ix;
 
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/x;
y = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(y);
c = cos(y);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure y+y not overflow */
z = cos(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(y);
else {
u = pone(y); v = qone(y);
z = invsqrtpi*(u*cc-v*ss)/sqrt(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x3e400000) { /* |x|<2**-27 */
if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*0.5+r/s);
}
 
#ifdef __STDC__
static const double U0[5] = {
#else
static double U0[5] = {
#endif
-1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */
5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */
-1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */
2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */
-9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */
};
#ifdef __STDC__
static const double V0[5] = {
#else
static double V0[5] = {
#endif
1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */
2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */
1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */
6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */
1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
};
 
#ifdef __STDC__
double __ieee754_y1(double x)
#else
double __ieee754_y1(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
int32_t hx,ix,lx;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = cos(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
else {
u = pone(x); v = qone(x);
z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
}
return z;
}
if(ix<=0x3c900000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));
}
 
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
 
#ifdef __STDC__
static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */
1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */
4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */
3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */
7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */
};
#ifdef __STDC__
static const double ps8[5] = {
#else
static double ps8[5] = {
#endif
1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */
3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */
3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */
9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */
3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */
};
 
#ifdef __STDC__
static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */
1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */
6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */
1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */
5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */
5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */
};
#ifdef __STDC__
static const double ps5[5] = {
#else
static double ps5[5] = {
#endif
5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */
9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */
5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */
7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */
1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */
};
 
#ifdef __STDC__
static const double pr3[6] = {
#else
static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */
1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */
3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */
3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */
9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */
4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */
};
#ifdef __STDC__
static const double ps3[5] = {
#else
static double ps3[5] = {
#endif
3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */
3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */
1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */
8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */
1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */
};
 
#ifdef __STDC__
static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */
1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */
2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */
1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */
1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */
5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */
};
#ifdef __STDC__
static const double ps2[5] = {
#else
static double ps2[5] = {
#endif
2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */
1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */
2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */
1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */
8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
};
 
#ifdef __STDC__
static double pone(double x)
#else
static double pone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pr8; q= ps8;}
else if(ix>=0x40122E8B){p = pr5; q= ps5;}
else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
else if(ix>=0x40000000){p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate pone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
 
#ifdef __STDC__
static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */
-1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */
-7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */
-1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */
-4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */
};
#ifdef __STDC__
static const double qs8[6] = {
#else
static double qs8[6] = {
#endif
1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */
7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */
1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */
7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */
6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */
-2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */
};
 
#ifdef __STDC__
static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */
-1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */
-8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */
-1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */
-1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */
-2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */
};
#ifdef __STDC__
static const double qs5[6] = {
#else
static double qs5[6] = {
#endif
8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */
1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */
1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */
4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */
2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */
-4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */
};
 
#ifdef __STDC__
static const double qr3[6] = {
#else
static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */
-1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */
-4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */
-5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */
-2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */
-2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */
};
#ifdef __STDC__
static const double qs3[6] = {
#else
static double qs3[6] = {
#endif
4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */
6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */
3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */
5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */
1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */
-1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */
};
 
#ifdef __STDC__
static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */
-1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */
-2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */
-1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */
-4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */
-2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */
};
#ifdef __STDC__
static const double qs2[6] = {
#else
static double qs2[6] = {
#endif
2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */
2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */
7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */
7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */
1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */
-4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
};
 
#ifdef __STDC__
static double qone(double x)
#else
static double qone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40122E8B){p = qr5; q= qs5;}
else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
else if(ix>=0x40000000){p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (.375 + r/s)/x;
}
/programs/develop/libraries/menuetlibc/src/libm/e_jn.c
0,0 → 1,282
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_jn.c,v 1.6 1994/08/18 23:05:37 jtc Exp $";
#endif
 
/*
* __ieee754_jn(n, x), __ieee754_yn(n, x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
one = 1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */
 
#ifdef __STDC__
static const double zero = 0.00000000000000000000e+00;
#else
static double zero = 0.00000000000000000000e+00;
#endif
 
#ifdef __STDC__
double __ieee754_jn(int n, double x)
#else
double __ieee754_jn(n,x)
int n; double x;
#endif
{
int32_t i,hx,ix,lx, sgn;
double a, b, temp, di;
double z, w;
 
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0(x));
if(n==1) return(__ieee754_j1(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabs(x);
if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */
b = zero;
else if((double)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = cos(x)+sin(x); break;
case 1: temp = -cos(x)+sin(x); break;
case 2: temp = -cos(x)-sin(x); break;
case 3: temp = cos(x)-sin(x); break;
}
b = invsqrtpi*temp/sqrt(x);
} else {
a = __ieee754_j0(x);
b = __ieee754_j1(x);
for(i=1;i<n;i++){
temp = b;
b = b*((double)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
}
} else {
if(ix<0x3e100000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (double)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
double t,v;
double q0,q1,h,tmp; int32_t k,m;
w = (n+n)/(double)x; h = 2.0/(double)x;
q0 = w; z = w+h; q1 = w*z - 1.0; k=1;
while(q1<1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_log(fabs(v*tmp));
if(tmp<7.09782712893383973096e+02) {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>1e100) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
 
#ifdef __STDC__
double __ieee754_yn(int n, double x)
#else
double __ieee754_yn(n,x)
int n; double x;
#endif
{
int32_t i,hx,ix,lx;
int32_t sign;
double a, b, temp;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<2);
}
if(n==0) return(__ieee754_y0(x));
if(n==1) return(sign*__ieee754_y1(x));
if(ix==0x7ff00000) return zero;
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = sin(x)-cos(x); break;
case 1: temp = -sin(x)-cos(x); break;
case 2: temp = -sin(x)+cos(x); break;
case 3: temp = sin(x)+cos(x); break;
}
b = invsqrtpi*temp/sqrt(x);
} else {
u_int32_t high;
a = __ieee754_y0(x);
b = __ieee754_y1(x);
/* quit if b is -inf */
GET_HIGH_WORD(high,b);
for(i=1;i<n&&high!=0xfff00000;i++){
temp = b;
b = ((double)(i+i)/x)*b - a;
GET_HIGH_WORD(high,b);
a = temp;
}
}
if(sign>0) return b; else return -b;
}
/programs/develop/libraries/menuetlibc/src/libm/e_lgamma.c
0,0 → 1,37
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_lgamma.c,v 1.4 1994/08/10 20:31:05 jtc Exp $";
#endif
 
/* __ieee754_lgamma(x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_lgamma_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
double __ieee754_lgamma(double x)
#else
double __ieee754_lgamma(x)
double x;
#endif
{
return __ieee754_lgamma_r(x,&signgam);
}
/programs/develop/libraries/menuetlibc/src/libm/e_log.s
0,0 → 1,7
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_log)
fldln2
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/e_log10.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(__ieee754_log10)
fldlg2
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/e_pow.c
0,0 → 1,309
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_pow.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_pow.c,v 1.6 1994/09/13 00:40:33 jtc Exp $";
#endif
 
/* __ieee754_pow(x,y) return x**y
*
* n
* Method: Let x = 2 * (1+f)
* 1. Compute and return log2(x) in two pieces:
* log2(x) = w1 + w2,
* where w1 has 53-24 = 29 bit trailing zeros.
* 2. Perform y*log2(x) = n+y' by simulating muti-precision
* arithmetic, where |y'|<=0.5.
* 3. Return x**y = 2**n*exp(y'*log2)
*
* Special cases:
* 1. (anything) ** 0 is 1
* 2. (anything) ** 1 is itself
* 3. (anything) ** NAN is NAN
* 4. NAN ** (anything except 0) is NAN
* 5. +-(|x| > 1) ** +INF is +INF
* 6. +-(|x| > 1) ** -INF is +0
* 7. +-(|x| < 1) ** +INF is +0
* 8. +-(|x| < 1) ** -INF is +INF
* 9. +-1 ** +-INF is NAN
* 10. +0 ** (+anything except 0, NAN) is +0
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
* 12. +0 ** (-anything except 0, NAN) is +INF
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
* 15. +INF ** (+anything except 0,NAN) is +INF
* 16. +INF ** (-anything except 0,NAN) is +0
* 17. -INF ** (anything) = -0 ** (-anything)
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
*
* Accuracy:
* pow(x,y) returns x**y nearly rounded. In particular
* pow(integer,integer)
* always returns the correct integer provided it is
* representable.
*
* Constants :
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
zero = 0.0,
one = 1.0,
two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
huge = 1.0e300,
tiny = 1.0e-300,
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
 
#ifdef __STDC__
double __ieee754_pow(double x, double y)
#else
double __ieee754_pow(x,y)
double x, y;
#endif
{
double z,ax,z_h,z_l,p_h,p_l;
double y1,t1,t2,r,s,t,u,v,w;
int32_t i,j,k,yisint,n;
int32_t hx,hy,ix,iy;
u_int32_t lx,ly;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
 
/* y==zero: x**0 = 1 */
if((iy|ly)==0) return one;
 
/* +-NaN return x+y */
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
return x+y;
 
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x43400000) yisint = 2; /* even integer y */
else if(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
if((j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
 
/* special value of y */
if(ly==0) {
if (iy==0x7ff00000) { /* y is +-inf */
if(((ix-0x3ff00000)|lx)==0)
return y - y; /* inf**+-1 is NaN */
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3ff00000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3fe00000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return sqrt(x);
}
}
 
ax = fabs(x);
/* special value of x */
if(lx==0) {
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3ff00000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
}
/* (x<0)**(non-int) is NaN */
if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
 
/* |y| is huge */
if(iy>0x41e00000) { /* if |y| > 2**31 */
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
}
/* over/underflow if x is not close to one */
if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = x-1; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
SET_LOW_WORD(t1,0);
t2 = v-(t1-u);
} else {
double s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(ix<0x00100000)
{ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff;
/* determine interval */
ix = j|0x3ff00000; /* normalize ix */
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00100000;}
SET_HIGH_WORD(ax,ix);
 
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
s = u*v;
s_h = s;
SET_LOW_WORD(s_h,0);
/* t_h=ax+bp[k] High */
t_h = zero;
SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = s*s;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+s);
s2 = s_h*s_h;
t_h = 3.0+s2+r;
SET_LOW_WORD(t_h,0);
t_l = r-((t_h-3.0)-s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*s;
/* 2/(3log2)*(s+...) */
p_h = u+v;
SET_LOW_WORD(p_h,0);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (double)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
SET_LOW_WORD(t1,0);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
 
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
s = -one;/* (-ve)**(odd int) */
 
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
y1 = y;
SET_LOW_WORD(y1,0);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
EXTRACT_WORDS(j,i,z);
if (j>=0x40900000) { /* z >= 1024 */
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
return s*huge*huge; /* overflow */
else {
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
}
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
return s*tiny*tiny; /* underflow */
else {
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
}
/*
* compute 2**(p_h+p_l)
*/
i = j&0x7fffffff;
k = (i>>20)-0x3ff;
n = 0;
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00100000>>(k+1));
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
t = zero;
SET_HIGH_WORD(t,n&~(0x000fffff>>k));
n = ((n&0x000fffff)|0x00100000)>>(20-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
SET_LOW_WORD(t,0);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_HIGH_WORD(j,z);
j += (n<<20);
if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
else SET_HIGH_WORD(z,j);
return s*z;
}
/programs/develop/libraries/menuetlibc/src/libm/e_rem_pi.c
0,0 → 1,159
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_rem_pio2.c,v 1.5 1994/08/18 23:05:56 jtc Exp $";
#endif
 
/* __ieee754_rem_pio2(x,y)
*
* return the remainder of x rem pi/2 in y[0]+y[1]
* use __kernel_rem_pio2()
*/
 
#include "math.h"
#include "math_private.h"
 
/*
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
#ifdef __STDC__
static const int32_t two_over_pi[] = {
#else
static int32_t two_over_pi[] = {
#endif
0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
};
 
#ifdef __STDC__
static const int32_t npio2_hw[] = {
#else
static int32_t npio2_hw[] = {
#endif
0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
0x404858EB, 0x404921FB,
};
 
/*
* invpio2: 53 bits of 2/pi
* pio2_1: first 33 bit of pi/2
* pio2_1t: pi/2 - pio2_1
* pio2_2: second 33 bit of pi/2
* pio2_2t: pi/2 - (pio2_1+pio2_2)
* pio2_3: third 33 bit of pi/2
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
*/
 
#ifdef __STDC__
static const double
#else
static double
#endif
zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
 
#ifdef __STDC__
int32_t __ieee754_rem_pio2(double x, double *y)
#else
int32_t __ieee754_rem_pio2(x,y)
double x,y[];
#endif
{
double z,w,t,r,fn;
double tx[3];
int32_t e0,i,j,nx,n,ix,hx;
u_int32_t low;
 
GET_HIGH_WORD(hx,x); /* high word of x */
ix = hx&0x7fffffff;
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
t = fabs(x);
n = (int32_t) (t*invpio2+half);
fn = (double)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 85 bit */
if(n<32&&ix!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
u_int32_t high;
j = ix>>20;
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>16) { /* 2nd iteration needed, good to 118 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>49) { /* 3rd iteration need, 151 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
/*
* all other (large) arguments
*/
if(ix>=0x7ff00000) { /* x is inf or NaN */
y[0]=y[1]=x-x; return 0;
}
/* set z = scalbn(|x|,ilogb(x)-23) */
GET_LOW_WORD(low,x);
SET_LOW_WORD(z,low);
e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
for(i=0;i<2;i++) {
tx[i] = (double)((int32_t)(z));
z = (z-tx[i])*two24;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--; /* skip zero term */
n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}
/programs/develop/libraries/menuetlibc/src/libm/e_remain.s
0,0 → 1,11
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_remainder)
fldl 12(%esp)
fldl 4(%esp)
1: fprem1
fstsw %ax
sahf
jp 1b
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/e_scalb.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(__ieee754_scalb)
fldl 12(%esp)
fldl 4(%esp)
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/e_sinh.c
0,0 → 1,87
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)e_sinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_sinh.c,v 1.5 1994/08/18 23:06:03 jtc Exp $";
#endif
 
/* __ieee754_sinh(x)
* Method :
* mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
* 1. Replace x by |x| (sinh(-x) = -sinh(x)).
* 2.
* E + E/(E+1)
* 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
* 2
*
* 22 <= x <= lnovft : sinh(x) := exp(x)/2
* lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
* ln2ovft < x : sinh(x) := x*shuge (overflow)
*
* Special cases:
* sinh(x) is |x| if x is +INF, -INF, or NaN.
* only sinh(0)=0 is exact for finite x.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double one = 1.0, shuge = 1.0e307;
#else
static double one = 1.0, shuge = 1.0e307;
#endif
 
#ifdef __STDC__
double __ieee754_sinh(double x)
#else
double __ieee754_sinh(x)
double x;
#endif
{
double t,w,h;
int32_t ix,jx;
u_int32_t lx;
 
/* High word of |x|. */
GET_HIGH_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7ff00000) return x+x;
 
h = 0.5;
if (jx<0) h = -h;
/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
if (ix < 0x40360000) { /* |x|<22 */
if (ix<0x3e300000) /* |x|<2**-28 */
if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
t = expm1(fabs(x));
if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
return h*(t+t/(t+one));
}
 
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d)) {
w = __ieee754_exp(0.5*fabs(x));
t = h*w;
return t*w;
}
 
/* |x| > overflowthresold, sinh(x) overflow */
return x*shuge;
}
/programs/develop/libraries/menuetlibc/src/libm/e_sqrt.s
0,0 → 1,6
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_sqrt)
fldl 4(%esp)
fsqrt
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_acos.c
0,0 → 1,90
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_acosf.c -- float version of e_acos.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_acosf.c,v 1.2 1994/08/18 23:04:53 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
pi = 3.1415925026e+00, /* 0x40490fda */
pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
pS0 = 1.6666667163e-01, /* 0x3e2aaaab */
pS1 = -3.2556581497e-01, /* 0xbea6b090 */
pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */
pS3 = -4.0055535734e-02, /* 0xbd241146 */
pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */
pS5 = 3.4793309169e-05, /* 0x3811ef08 */
qS1 = -2.4033949375e+00, /* 0xc019d139 */
qS2 = 2.0209457874e+00, /* 0x4001572d */
qS3 = -6.8828397989e-01, /* 0xbf303361 */
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
 
#ifdef __STDC__
float __ieee754_acosf(float x)
#else
float __ieee754_acosf(x)
float x;
#endif
{
float z,p,q,r,w,s,c,df;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix==0x3f800000) { /* |x|==1 */
if(hx>0) return 0.0; /* acos(1) = 0 */
else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */
} else if(ix>0x3f800000) { /* |x| >= 1 */
return (x-x)/(x-x); /* acos(|x|>1) is NaN */
}
if(ix<0x3f000000) { /* |x| < 0.5 */
if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
z = x*x;
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
r = p/q;
return pio2_hi - (x - (pio2_lo-x*r));
} else if (hx<0) { /* x < -0.5 */
z = (one+x)*(float)0.5;
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
s = sqrtf(z);
r = p/q;
w = r*s-pio2_lo;
return pi - (float)2.0*(s+w);
} else { /* x > 0.5 */
int32_t idf;
z = (one-x)*(float)0.5;
s = sqrtf(z);
df = s;
GET_FLOAT_WORD(idf,df);
SET_FLOAT_WORD(df,idf&0xfffff000);
c = (z-df*df)/(s+df);
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
r = p/q;
w = r*s+c;
return (float)2.0*(df+w);
}
}
/programs/develop/libraries/menuetlibc/src/libm/ef_acosh.c
0,0 → 1,58
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_acoshf.c -- float version of e_acosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_acoshf.c,v 1.2 1994/08/18 23:04:57 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0,
ln2 = 6.9314718246e-01; /* 0x3f317218 */
 
#ifdef __STDC__
float __ieee754_acoshf(float x)
#else
float __ieee754_acoshf(x)
float x;
#endif
{
float t;
int32_t hx;
GET_FLOAT_WORD(hx,x);
if(hx<0x3f800000) { /* x < 1 */
return (x-x)/(x-x);
} else if(hx >=0x4d800000) { /* x > 2**28 */
if(hx >=0x7f800000) { /* x is inf of NaN */
return x+x;
} else
return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */
} else if (hx==0x3f800000) {
return 0.0; /* acosh(1) = 0 */
} else if (hx > 0x40000000) { /* 2**28 > x > 2 */
t=x*x;
return __ieee754_logf((float)2.0*x-one/(x+sqrtf(t-one)));
} else { /* 1<x<2 */
t = x-one;
return log1pf(t+sqrtf((float)2.0*t+t*t));
}
}
/programs/develop/libraries/menuetlibc/src/libm/ef_asin.c
0,0 → 1,93
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_asinf.c -- float version of e_asin.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_asinf.c,v 1.2 1994/08/18 23:05:05 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
huge = 1.000e+30,
pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
pio4_hi = 7.8539818525e-01, /* 0x3f490fdb */
/* coefficient for R(x^2) */
pS0 = 1.6666667163e-01, /* 0x3e2aaaab */
pS1 = -3.2556581497e-01, /* 0xbea6b090 */
pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */
pS3 = -4.0055535734e-02, /* 0xbd241146 */
pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */
pS5 = 3.4793309169e-05, /* 0x3811ef08 */
qS1 = -2.4033949375e+00, /* 0xc019d139 */
qS2 = 2.0209457874e+00, /* 0x4001572d */
qS3 = -6.8828397989e-01, /* 0xbf303361 */
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
 
#ifdef __STDC__
float __ieee754_asinf(float x)
#else
float __ieee754_asinf(x)
float x;
#endif
{
float t,w,p,q,c,r,s;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix==0x3f800000) {
/* asin(1)=+-pi/2 with inexact */
return x*pio2_hi+x*pio2_lo;
} else if(ix> 0x3f800000) { /* |x|>= 1 */
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
} else if (ix<0x3f000000) { /* |x|<0.5 */
if(ix<0x32000000) { /* if |x| < 2**-27 */
if(huge+x>one) return x;/* return x with inexact if x!=0*/
} else
t = x*x;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
w = p/q;
return x+x*w;
}
/* 1> |x|>= 0.5 */
w = one-fabsf(x);
t = w*(float)0.5;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
s = sqrtf(t);
if(ix>=0x3F79999A) { /* if |x| > 0.975 */
w = p/q;
t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
} else {
int32_t iw;
w = s;
GET_FLOAT_WORD(iw,w);
SET_FLOAT_WORD(w,iw&0xfffff000);
c = (t-w*w)/(s+w);
r = p/q;
p = (float)2.0*s*r-(pio2_lo-(float)2.0*c);
q = pio4_hi-(float)2.0*w;
t = pio4_hi-(p-q);
}
if(hx>0) return t; else return -t;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_atan2.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(__ieee754_atan2f)
flds 4(%esp)
flds 8(%esp)
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_atanh.c
0,0 → 1,59
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_atanhf.c -- float version of e_atanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_atanhf.c,v 1.2 1994/08/18 23:05:14 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float one = 1.0, huge = 1e30;
#else
static float one = 1.0, huge = 1e30;
#endif
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_atanhf(float x)
#else
float __ieee754_atanhf(x)
float x;
#endif
{
float t;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if (ix>0x3f800000) /* |x|>1 */
return (x-x)/(x-x);
if(ix==0x3f800000)
return x/zero;
if(ix<0x31800000&&(huge+x)>zero) return x; /* x<2**-28 */
SET_FLOAT_WORD(x,ix);
if(ix<0x3f000000) { /* x < 0.5 */
t = x+x;
t = (float)0.5*log1pf(t+t*x/(one-x));
} else
t = (float)0.5*log1pf((x+x)/(one-x));
if(hx>=0) return t; else return -t;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_cosh.c
0,0 → 1,72
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_coshf.c -- float version of e_cosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_coshf.c,v 1.2 1994/08/18 23:05:17 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float one = 1.0, half=0.5, huge = 1.0e30;
#else
static float one = 1.0, half=0.5, huge = 1.0e30;
#endif
 
#ifdef __STDC__
float __ieee754_coshf(float x)
#else
float __ieee754_coshf(x)
float x;
#endif
{
float t,w;
int32_t ix;
 
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7f800000) return x*x;
 
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
if(ix<0x3eb17218) {
t = expm1f(fabsf(x));
w = one+t;
if (ix<0x24000000) return w; /* cosh(tiny) = 1 */
return one+(t*t)/(w+w);
}
 
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
if (ix < 0x41b00000) {
t = __ieee754_expf(fabsf(x));
return half*t+half/t;
}
 
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
if (ix < 0x42b17180) return half*__ieee754_expf(fabsf(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
if (ix<=0x42b2d4fc) {
w = __ieee754_expf(half*fabsf(x));
t = half*w;
return t*w;
}
 
/* |x| > overflowthresold, cosh(x) overflow */
return huge*huge;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_exp.s
0,0 → 1,14
#include<libc/asm.h>
MK_C_SYM(__ieee754_expf)
flds 4(%esp)
fldl2e
fmulp
fstl %st(1)
frndint
fstl %st(2)
fsubrp
f2xm1
fld1
faddp
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_fmod.s
0,0 → 1,11
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_fmodf)
flds 8(%esp)
flds 4(%esp)
1: fprem
fstsw %ax
sahf
jp 1b
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_gamma.c
0,0 → 1,40
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_gammaf.c -- float version of e_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_gammaf.c,v 1.1 1994/08/10 20:30:53 jtc Exp $";
#endif
 
/* __ieee754_gammaf(x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_gammaf_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
float __ieee754_gammaf(float x)
#else
float __ieee754_gammaf(x)
float x;
#endif
{
return __ieee754_gammaf_r(x,&signgam);
}
/programs/develop/libraries/menuetlibc/src/libm/ef_hypot.c
0,0 → 1,88
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_hypotf.c -- float version of e_hypot.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_hypotf.c,v 1.2 1994/08/18 23:05:26 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float __ieee754_hypotf(float x, float y)
#else
float __ieee754_hypot(x,y)
float x, y;
#endif
{
float a=x,b=y,t1,t2,y1,y2,w;
int32_t j,k,ha,hb;
 
GET_FLOAT_WORD(ha,x);
ha &= 0x7fffffff;
GET_FLOAT_WORD(hb,y);
hb &= 0x7fffffff;
if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
SET_FLOAT_WORD(a,ha); /* a <- |a| */
SET_FLOAT_WORD(b,hb); /* b <- |b| */
if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
k=0;
if(ha > 0x58800000) { /* a>2**50 */
if(ha >= 0x7f800000) { /* Inf or NaN */
w = a+b; /* for sNaN */
if(ha == 0x7f800000) w = a;
if(hb == 0x7f800000) w = b;
return w;
}
/* scale a and b by 2**-60 */
ha -= 0x5d800000; hb -= 0x5d800000; k += 60;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
if(hb < 0x26800000) { /* b < 2**-50 */
if(hb <= 0x007fffff) { /* subnormal b or 0 */
if(hb==0) return a;
SET_FLOAT_WORD(t1,0x3f000000); /* t1=2^126 */
b *= t1;
a *= t1;
k -= 126;
} else { /* scale a and b by 2^60 */
ha += 0x5d800000; /* a *= 2^60 */
hb += 0x5d800000; /* b *= 2^60 */
k -= 60;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
}
/* medium size a and b */
w = a-b;
if (w>b) {
SET_FLOAT_WORD(t1,ha&0xfffff000);
t2 = a-t1;
w = sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
} else {
a = a+a;
SET_FLOAT_WORD(y1,hb&0xfffff000);
y2 = b - y1;
SET_FLOAT_WORD(t1,ha+0x00800000);
t2 = a - t1;
w = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
}
if(k!=0) {
SET_FLOAT_WORD(t1,0x3f800000+(k<<23));
return t1*w;
} else return w;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_j0.c
0,0 → 1,445
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_j0f.c -- float version of e_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_j0f.c,v 1.2 1994/08/18 23:05:32 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static float pzerof(float), qzerof(float);
#else
static float pzerof(), qzerof();
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0, 2.00] */
R02 = 1.5625000000e-02, /* 0x3c800000 */
R03 = -1.8997929874e-04, /* 0xb947352e */
R04 = 1.8295404516e-06, /* 0x35f58e88 */
R05 = -4.6183270541e-09, /* 0xb19eaf3c */
S01 = 1.5619102865e-02, /* 0x3c7fe744 */
S02 = 1.1692678527e-04, /* 0x38f53697 */
S03 = 5.1354652442e-07, /* 0x3509daa6 */
S04 = 1.1661400734e-09; /* 0x30a045e8 */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_j0f(float x)
#else
float __ieee754_j0f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v;
int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return one/(x*x);
x = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(x);
}
return z;
}
if(ix<0x39000000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x32000000) return one; /* |x|<2**-27 */
else return one - (float)0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3F800000) { /* |x| < 1.00 */
return one + z*((float)-0.25+(r/s));
} else {
u = (float)0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
 
#ifdef __STDC__
static const float
#else
static float
#endif
u00 = -7.3804296553e-02, /* 0xbd9726b5 */
u01 = 1.7666645348e-01, /* 0x3e34e80d */
u02 = -1.3818567619e-02, /* 0xbc626746 */
u03 = 3.4745343146e-04, /* 0x39b62a69 */
u04 = -3.8140706238e-06, /* 0xb67ff53c */
u05 = 1.9559013964e-08, /* 0x32a802ba */
u06 = -3.9820518410e-11, /* 0xae2f21eb */
v01 = 1.2730483897e-02, /* 0x3c509385 */
v02 = 7.6006865129e-05, /* 0x389f65e0 */
v03 = 2.5915085189e-07, /* 0x348b216c */
v04 = 4.4111031494e-10; /* 0x2ff280c2 */
 
#ifdef __STDC__
float __ieee754_y0f(float x)
#else
float __ieee754_y0f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(ix>=0x7f800000) return one/(x+x*x);
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x80000000) z = (invsqrtpi*ss)/sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
if(ix<=0x32000000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_logf(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0f(x)*__ieee754_logf(x)));
}
 
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-7.0312500000e-02, /* 0xbd900000 */
-8.0816707611e+00, /* 0xc1014e86 */
-2.5706311035e+02, /* 0xc3808814 */
-2.4852163086e+03, /* 0xc51b5376 */
-5.2530439453e+03, /* 0xc5a4285a */
};
#ifdef __STDC__
static const float pS8[5] = {
#else
static float pS8[5] = {
#endif
1.1653436279e+02, /* 0x42e91198 */
3.8337448730e+03, /* 0x456f9beb */
4.0597855469e+04, /* 0x471e95db */
1.1675296875e+05, /* 0x47e4087c */
4.7627726562e+04, /* 0x473a0bba */
};
#ifdef __STDC__
static const float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.1412546255e-11, /* 0xad48c58a */
-7.0312492549e-02, /* 0xbd8fffff */
-4.1596107483e+00, /* 0xc0851b88 */
-6.7674766541e+01, /* 0xc287597b */
-3.3123129272e+02, /* 0xc3a59d9b */
-3.4643338013e+02, /* 0xc3ad3779 */
};
#ifdef __STDC__
static const float pS5[5] = {
#else
static float pS5[5] = {
#endif
6.0753936768e+01, /* 0x42730408 */
1.0512523193e+03, /* 0x44836813 */
5.9789707031e+03, /* 0x45bad7c4 */
9.6254453125e+03, /* 0x461665c8 */
2.4060581055e+03, /* 0x451660ee */
};
 
#ifdef __STDC__
static const float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.5470459075e-09, /* 0xb12f081b */
-7.0311963558e-02, /* 0xbd8fffb8 */
-2.4090321064e+00, /* 0xc01a2d95 */
-2.1965976715e+01, /* 0xc1afba52 */
-5.8079170227e+01, /* 0xc2685112 */
-3.1447946548e+01, /* 0xc1fb9565 */
};
#ifdef __STDC__
static const float pS3[5] = {
#else
static float pS3[5] = {
#endif
3.5856033325e+01, /* 0x420f6c94 */
3.6151397705e+02, /* 0x43b4c1ca */
1.1936077881e+03, /* 0x44953373 */
1.1279968262e+03, /* 0x448cffe6 */
1.7358093262e+02, /* 0x432d94b8 */
};
 
#ifdef __STDC__
static const float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.8753431271e-08, /* 0xb3be98b7 */
-7.0303097367e-02, /* 0xbd8ffb12 */
-1.4507384300e+00, /* 0xbfb9b1cc */
-7.6356959343e+00, /* 0xc0f4579f */
-1.1193166733e+01, /* 0xc1331736 */
-3.2336456776e+00, /* 0xc04ef40d */
};
#ifdef __STDC__
static const float pS2[5] = {
#else
static float pS2[5] = {
#endif
2.2220300674e+01, /* 0x41b1c32d */
1.3620678711e+02, /* 0x430834f0 */
2.7047027588e+02, /* 0x43873c32 */
1.5387539673e+02, /* 0x4319e01a */
1.4657617569e+01, /* 0x416a859a */
};
 
#ifdef __STDC__
static float pzerof(float x)
#else
static float pzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pR8; q= pS8;}
else if(ix>=0x40f71c58){p = pR5; q= pS5;}
else if(ix>=0x4036db68){p = pR3; q= pS3;}
else if(ix>=0x40000000){p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate pzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
7.3242187500e-02, /* 0x3d960000 */
1.1768206596e+01, /* 0x413c4a93 */
5.5767340088e+02, /* 0x440b6b19 */
8.8591972656e+03, /* 0x460a6cca */
3.7014625000e+04, /* 0x471096a0 */
};
#ifdef __STDC__
static const float qS8[6] = {
#else
static float qS8[6] = {
#endif
1.6377603149e+02, /* 0x4323c6aa */
8.0983447266e+03, /* 0x45fd12c2 */
1.4253829688e+05, /* 0x480b3293 */
8.0330925000e+05, /* 0x49441ed4 */
8.4050156250e+05, /* 0x494d3359 */
-3.4389928125e+05, /* 0xc8a7eb69 */
};
 
#ifdef __STDC__
static const float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.8408595828e-11, /* 0x2da1ec79 */
7.3242180049e-02, /* 0x3d95ffff */
5.8356351852e+00, /* 0x40babd86 */
1.3511157227e+02, /* 0x43071c90 */
1.0272437744e+03, /* 0x448067cd */
1.9899779053e+03, /* 0x44f8bf4b */
};
#ifdef __STDC__
static const float qS5[6] = {
#else
static float qS5[6] = {
#endif
8.2776611328e+01, /* 0x42a58da0 */
2.0778142090e+03, /* 0x4501dd07 */
1.8847289062e+04, /* 0x46933e94 */
5.6751113281e+04, /* 0x475daf1d */
3.5976753906e+04, /* 0x470c88c1 */
-5.3543427734e+03, /* 0xc5a752be */
};
 
#ifdef __STDC__
static const float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.3774099900e-09, /* 0x3196681b */
7.3241114616e-02, /* 0x3d95ff70 */
3.3442313671e+00, /* 0x405607e3 */
4.2621845245e+01, /* 0x422a7cc5 */
1.7080809021e+02, /* 0x432acedf */
1.6673394775e+02, /* 0x4326bbe4 */
};
#ifdef __STDC__
static const float qS3[6] = {
#else
static float qS3[6] = {
#endif
4.8758872986e+01, /* 0x42430916 */
7.0968920898e+02, /* 0x44316c1c */
3.7041481934e+03, /* 0x4567825f */
6.4604252930e+03, /* 0x45c9e367 */
2.5163337402e+03, /* 0x451d4557 */
-1.4924745178e+02, /* 0xc3153f59 */
};
 
#ifdef __STDC__
static const float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.5044444979e-07, /* 0x342189db */
7.3223426938e-02, /* 0x3d95f62a */
1.9981917143e+00, /* 0x3fffc4bf */
1.4495602608e+01, /* 0x4167edfd */
3.1666231155e+01, /* 0x41fd5471 */
1.6252708435e+01, /* 0x4182058c */
};
#ifdef __STDC__
static const float qS2[6] = {
#else
static float qS2[6] = {
#endif
3.0365585327e+01, /* 0x41f2ecb8 */
2.6934811401e+02, /* 0x4386ac8f */
8.4478375244e+02, /* 0x44533229 */
8.8293585205e+02, /* 0x445cbbe5 */
2.1266638184e+02, /* 0x4354aa98 */
-5.3109550476e+00, /* 0xc0a9f358 */
};
 
#ifdef __STDC__
static float qzerof(float x)
#else
static float qzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = qR8; q= qS8;}
else if(ix>=0x40f71c58){p = qR5; q= qS5;}
else if(ix>=0x4036db68){p = qR3; q= qS3;}
else if(ix>=0x40000000){p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-(float).125 + r/s)/x;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_j1.c
0,0 → 1,445
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_j1f.c -- float version of e_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_j1f.c,v 1.2 1994/08/18 23:05:35 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static float ponef(float), qonef(float);
#else
static float ponef(), qonef();
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0,2] */
r00 = -6.2500000000e-02, /* 0xbd800000 */
r01 = 1.4070566976e-03, /* 0x3ab86cfd */
r02 = -1.5995563444e-05, /* 0xb7862e36 */
r03 = 4.9672799207e-08, /* 0x335557d2 */
s01 = 1.9153760746e-02, /* 0x3c9ce859 */
s02 = 1.8594678841e-04, /* 0x3942fab6 */
s03 = 1.1771846857e-06, /* 0x359dffc2 */
s04 = 5.0463624390e-09, /* 0x31ad6446 */
s05 = 1.2354227016e-11; /* 0x2d59567e */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_j1f(float x)
#else
float __ieee754_j1f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v,y;
int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return one/x;
y = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(y);
c = cosf(y);
ss = -s-c;
cc = s-c;
if(ix<0x7f000000) { /* make sure y+y not overflow */
z = cosf(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
else {
u = ponef(y); v = qonef(y);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x32000000) { /* |x|<2**-27 */
if(huge+x>one) return (float)0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*(float)0.5+r/s);
}
 
#ifdef __STDC__
static const float U0[5] = {
#else
static float U0[5] = {
#endif
-1.9605709612e-01, /* 0xbe48c331 */
5.0443872809e-02, /* 0x3d4e9e3c */
-1.9125689287e-03, /* 0xbafaaf2a */
2.3525259166e-05, /* 0x37c5581c */
-9.1909917899e-08, /* 0xb3c56003 */
};
#ifdef __STDC__
static const float V0[5] = {
#else
static float V0[5] = {
#endif
1.9916731864e-02, /* 0x3ca3286a */
2.0255257550e-04, /* 0x3954644b */
1.3560879779e-06, /* 0x35b602d4 */
6.2274145840e-09, /* 0x31d5f8eb */
1.6655924903e-11, /* 0x2d9281cf */
};
 
#ifdef __STDC__
float __ieee754_y1f(float x)
#else
float __ieee754_y1f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(ix>=0x7f800000) return one/(x+x*x);
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = -s-c;
cc = s-c;
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = cosf(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrtf(x);
else {
u = ponef(x); v = qonef(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
if(ix<=0x24800000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1f(x)*__ieee754_logf(x)-one/x));
}
 
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
 
#ifdef __STDC__
static const float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
1.1718750000e-01, /* 0x3df00000 */
1.3239480972e+01, /* 0x4153d4ea */
4.1205184937e+02, /* 0x43ce06a3 */
3.8747453613e+03, /* 0x45722bed */
7.9144794922e+03, /* 0x45f753d6 */
};
#ifdef __STDC__
static const float ps8[5] = {
#else
static float ps8[5] = {
#endif
1.1420736694e+02, /* 0x42e46a2c */
3.6509309082e+03, /* 0x45642ee5 */
3.6956207031e+04, /* 0x47105c35 */
9.7602796875e+04, /* 0x47bea166 */
3.0804271484e+04, /* 0x46f0a88b */
};
 
#ifdef __STDC__
static const float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.3199052094e-11, /* 0x2d68333f */
1.1718749255e-01, /* 0x3defffff */
6.8027510643e+00, /* 0x40d9b023 */
1.0830818176e+02, /* 0x42d89dca */
5.1763616943e+02, /* 0x440168b7 */
5.2871520996e+02, /* 0x44042dc6 */
};
#ifdef __STDC__
static const float ps5[5] = {
#else
static float ps5[5] = {
#endif
5.9280597687e+01, /* 0x426d1f55 */
9.9140142822e+02, /* 0x4477d9b1 */
5.3532670898e+03, /* 0x45a74a23 */
7.8446904297e+03, /* 0x45f52586 */
1.5040468750e+03, /* 0x44bc0180 */
};
 
#ifdef __STDC__
static const float pr3[6] = {
#else
static float pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.0250391081e-09, /* 0x314fe10d */
1.1718686670e-01, /* 0x3defffab */
3.9329774380e+00, /* 0x407bb5e7 */
3.5119403839e+01, /* 0x420c7a45 */
9.1055007935e+01, /* 0x42b61c2a */
4.8559066772e+01, /* 0x42423c7c */
};
#ifdef __STDC__
static const float ps3[5] = {
#else
static float ps3[5] = {
#endif
3.4791309357e+01, /* 0x420b2a4d */
3.3676245117e+02, /* 0x43a86198 */
1.0468714600e+03, /* 0x4482dbe3 */
8.9081134033e+02, /* 0x445eb3ed */
1.0378793335e+02, /* 0x42cf936c */
};
 
#ifdef __STDC__
static const float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.0771083225e-07, /* 0x33e74ea8 */
1.1717621982e-01, /* 0x3deffa16 */
2.3685150146e+00, /* 0x401795c0 */
1.2242610931e+01, /* 0x4143e1bc */
1.7693971634e+01, /* 0x418d8d41 */
5.0735230446e+00, /* 0x40a25a4d */
};
#ifdef __STDC__
static const float ps2[5] = {
#else
static float ps2[5] = {
#endif
2.1436485291e+01, /* 0x41ab7dec */
1.2529022980e+02, /* 0x42fa9499 */
2.3227647400e+02, /* 0x436846c7 */
1.1767937469e+02, /* 0x42eb5bd7 */
8.3646392822e+00, /* 0x4105d590 */
};
 
#ifdef __STDC__
static float ponef(float x)
#else
static float ponef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pr8; q= ps8;}
else if(ix>=0x40f71c58){p = pr5; q= ps5;}
else if(ix>=0x4036db68){p = pr3; q= ps3;}
else if(ix>=0x40000000){p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate pone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
 
#ifdef __STDC__
static const float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-1.0253906250e-01, /* 0xbdd20000 */
-1.6271753311e+01, /* 0xc1822c8d */
-7.5960174561e+02, /* 0xc43de683 */
-1.1849806641e+04, /* 0xc639273a */
-4.8438511719e+04, /* 0xc73d3683 */
};
#ifdef __STDC__
static const float qs8[6] = {
#else
static float qs8[6] = {
#endif
1.6139537048e+02, /* 0x43216537 */
7.8253862305e+03, /* 0x45f48b17 */
1.3387534375e+05, /* 0x4802bcd6 */
7.1965775000e+05, /* 0x492fb29c */
6.6660125000e+05, /* 0x4922be94 */
-2.9449025000e+05, /* 0xc88fcb48 */
};
 
#ifdef __STDC__
static const float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.0897993405e-11, /* 0xadb7d219 */
-1.0253904760e-01, /* 0xbdd1fffe */
-8.0564479828e+00, /* 0xc100e736 */
-1.8366960144e+02, /* 0xc337ab6b */
-1.3731937256e+03, /* 0xc4aba633 */
-2.6124443359e+03, /* 0xc523471c */
};
#ifdef __STDC__
static const float qs5[6] = {
#else
static float qs5[6] = {
#endif
8.1276550293e+01, /* 0x42a28d98 */
1.9917987061e+03, /* 0x44f8f98f */
1.7468484375e+04, /* 0x468878f8 */
4.9851425781e+04, /* 0x4742bb6d */
2.7948074219e+04, /* 0x46da5826 */
-4.7191835938e+03, /* 0xc5937978 */
};
 
#ifdef __STDC__
static const float qr3[6] = {
#else
static float qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.0783124372e-09, /* 0xb1ae7d4f */
-1.0253783315e-01, /* 0xbdd1ff5b */
-4.6101160049e+00, /* 0xc0938612 */
-5.7847221375e+01, /* 0xc267638e */
-2.2824453735e+02, /* 0xc3643e9a */
-2.1921012878e+02, /* 0xc35b35cb */
};
#ifdef __STDC__
static const float qs3[6] = {
#else
static float qs3[6] = {
#endif
4.7665153503e+01, /* 0x423ea91e */
6.7386511230e+02, /* 0x4428775e */
3.3801528320e+03, /* 0x45534272 */
5.5477290039e+03, /* 0x45ad5dd5 */
1.9031191406e+03, /* 0x44ede3d0 */
-1.3520118713e+02, /* 0xc3073381 */
};
 
#ifdef __STDC__
static const float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.7838172539e-07, /* 0xb43f8932 */
-1.0251704603e-01, /* 0xbdd1f475 */
-2.7522056103e+00, /* 0xc0302423 */
-1.9663616180e+01, /* 0xc19d4f16 */
-4.2325313568e+01, /* 0xc2294d1f */
-2.1371921539e+01, /* 0xc1aaf9b2 */
};
#ifdef __STDC__
static const float qs2[6] = {
#else
static float qs2[6] = {
#endif
2.9533363342e+01, /* 0x41ec4454 */
2.5298155212e+02, /* 0x437cfb47 */
7.5750280762e+02, /* 0x443d602e */
7.3939318848e+02, /* 0x4438d92a */
1.5594900513e+02, /* 0x431bf2f2 */
-4.9594988823e+00, /* 0xc09eb437 */
};
 
#ifdef __STDC__
static float qonef(float x)
#else
static float qonef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40f71c58){p = qr5; q= qs5;}
else if(ix>=0x4036db68){p = qr3; q= qs3;}
else if(ix>=0x40000000){p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return ((float).375 + r/s)/x;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_jn.c
0,0 → 1,213
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_jnf.c -- float version of e_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_jnf.c,v 1.2 1994/08/18 23:05:39 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
two = 2.0000000000e+00, /* 0x40000000 */
one = 1.0000000000e+00; /* 0x3F800000 */
 
#ifdef __STDC__
static const float zero = 0.0000000000e+00;
#else
static float zero = 0.0000000000e+00;
#endif
 
#ifdef __STDC__
float __ieee754_jnf(int n, float x)
#else
float __ieee754_jnf(n,x)
int n; float x;
#endif
{
int32_t i,hx,ix, sgn;
float a, b, temp, di;
float z, w;
 
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if(ix>0x7f800000) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0f(x));
if(n==1) return(__ieee754_j1f(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabsf(x);
if(ix==0||ix>=0x7f800000) /* if x is 0 or inf */
b = zero;
else if((float)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
a = __ieee754_j0f(x);
b = __ieee754_j1f(x);
for(i=1;i<n;i++){
temp = b;
b = b*((float)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
} else {
if(ix<0x30800000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*(float)0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (float)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
float t,v;
float q0,q1,h,tmp; int32_t k,m;
w = (n+n)/(float)x; h = (float)2.0/(float)x;
q0 = w; z = w+h; q1 = w*z - (float)1.0; k=1;
while(q1<(float)1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_logf(fabsf(v*tmp));
if(tmp<(float)8.8721679688e+01) {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>(float)1e10) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0f(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
 
#ifdef __STDC__
float __ieee754_ynf(int n, float x)
#else
float __ieee754_ynf(n,x)
int n; float x;
#endif
{
int32_t i,hx,ix,ib;
int32_t sign;
float a, b, temp;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if(ix>0x7f800000) return x+x;
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<2);
}
if(n==0) return(__ieee754_y0f(x));
if(n==1) return(sign*__ieee754_y1f(x));
if(ix==0x7f800000) return zero;
 
a = __ieee754_y0f(x);
b = __ieee754_y1f(x);
/* quit if b is -inf */
GET_FLOAT_WORD(ib,b);
for(i=1;i<n&&ib!=0xff800000;i++){
temp = b;
b = ((float)(i+i)/x)*b - a;
GET_FLOAT_WORD(ib,b);
a = temp;
}
if(sign>0) return b; else return -b;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_lgamm.c
0,0 → 1,40
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_lgammaf.c -- float version of e_lgamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_lgammaf.c,v 1.1 1994/08/10 20:31:08 jtc Exp $";
#endif
 
/* __ieee754_lgammaf(x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_lgammaf_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
float __ieee754_lgammaf(float x)
#else
float __ieee754_lgammaf(x)
float x;
#endif
{
return __ieee754_lgammaf_r(x,&signgam);
}
/programs/develop/libraries/menuetlibc/src/libm/ef_log.s
0,0 → 1,7
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_logf)
fldln2
flds 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_log10.s
0,0 → 1,7
#include<libc/asm.h>
MK_C_SYM(__ieee754_log10f)
.globl __ieee754_log10f
fldlg2
flds 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_pow.c
0,0 → 1,254
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_powf.c -- float version of e_pow.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_powf.c,v 1.2 1994/08/18 23:05:54 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
zero = 0.0,
one = 1.0,
two = 2.0,
two24 = 16777216.0, /* 0x4b800000 */
huge = 1.0e30,
tiny = 1.0e-30,
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 6.0000002384e-01, /* 0x3f19999a */
L2 = 4.2857143283e-01, /* 0x3edb6db7 */
L3 = 3.3333334327e-01, /* 0x3eaaaaab */
L4 = 2.7272811532e-01, /* 0x3e8ba305 */
L5 = 2.3066075146e-01, /* 0x3e6c3255 */
L6 = 2.0697501302e-01, /* 0x3e53f142 */
P1 = 1.6666667163e-01, /* 0x3e2aaaab */
P2 = -2.7777778450e-03, /* 0xbb360b61 */
P3 = 6.6137559770e-05, /* 0x388ab355 */
P4 = -1.6533901999e-06, /* 0xb5ddea0e */
P5 = 4.1381369442e-08, /* 0x3331bb4c */
lg2 = 6.9314718246e-01, /* 0x3f317218 */
lg2_h = 6.93145752e-01, /* 0x3f317200 */
lg2_l = 1.42860654e-06, /* 0x35bfbe8c */
ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */
cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */
cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */
cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */
ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */
ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/
ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/
 
#ifdef __STDC__
float __ieee754_powf(float x, float y)
#else
float __ieee754_powf(x,y)
float x, y;
#endif
{
float z,ax,z_h,z_l,p_h,p_l;
float y1,t1,t2,r,s,t,u,v,w;
int32_t i,j,k,yisint,n;
int32_t hx,hy,ix,iy,is;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
 
/* y==zero: x**0 = 1 */
if(iy==0) return one;
 
/* +-NaN return x+y */
if(ix > 0x7f800000 ||
iy > 0x7f800000)
return x+y;
 
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x4b800000) yisint = 2; /* even integer y */
else if(iy>=0x3f800000) {
k = (iy>>23)-0x7f; /* exponent */
j = iy>>(23-k);
if((j<<(23-k))==iy) yisint = 2-(j&1);
}
}
 
/* special value of y */
if (iy==0x7f800000) { /* y is +-inf */
if (ix==0x3f800000)
return y - y; /* inf**+-1 is NaN */
else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3f800000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3f000000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return sqrtf(x);
}
 
ax = fabsf(x);
/* special value of x */
if(ix==0x7f800000||ix==0||ix==0x3f800000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3f800000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
/* (x<0)**(non-int) is NaN */
if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
 
/* |y| is huge */
if(iy>0x4d000000) { /* if |y| > 2**27 */
/* over/underflow if x is not close to one */
if(ix<0x3f7ffff8) return (hy<0)? huge*huge:tiny*tiny;
if(ix>0x3f800007) return (hy>0)? huge*huge:tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = x-1; /* t has 20 trailing zeros */
w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25));
u = ivln2_h*t; /* ivln2_h has 16 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
GET_FLOAT_WORD(is,t1);
SET_FLOAT_WORD(t1,is&0xfffff000);
t2 = v-(t1-u);
} else {
float s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(ix<0x00800000)
{ax *= two24; n -= 24; GET_FLOAT_WORD(ix,ax); }
n += ((ix)>>23)-0x7f;
j = ix&0x007fffff;
/* determine interval */
ix = j|0x3f800000; /* normalize ix */
if(j<=0x1cc471) k=0; /* |x|<sqrt(3/2) */
else if(j<0x5db3d7) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00800000;}
SET_FLOAT_WORD(ax,ix);
 
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
s = u*v;
s_h = s;
GET_FLOAT_WORD(is,s_h);
SET_FLOAT_WORD(s_h,is&0xfffff000);
/* t_h=ax+bp[k] High */
SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = s*s;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+s);
s2 = s_h*s_h;
t_h = (float)3.0+s2+r;
GET_FLOAT_WORD(is,t_h);
SET_FLOAT_WORD(t_h,is&0xfffff000);
t_l = r-((t_h-(float)3.0)-s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*s;
/* 2/(3log2)*(s+...) */
p_h = u+v;
GET_FLOAT_WORD(is,p_h);
SET_FLOAT_WORD(p_h,is&0xfffff000);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (float)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
GET_FLOAT_WORD(is,t1);
SET_FLOAT_WORD(t1,is&0xfffff000);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
 
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
s = -one; /* (-ve)**(odd int) */
 
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
GET_FLOAT_WORD(is,y);
SET_FLOAT_WORD(y1,is&0xfffff000);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
GET_FLOAT_WORD(j,z);
if (j>0x43000000) /* if z > 128 */
return s*huge*huge; /* overflow */
else if (j==0x43000000) { /* if z == 128 */
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
}
else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */
return s*tiny*tiny; /* underflow */
else if (j==0xc3160000){ /* z == -150 */
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
/*
* compute 2**(p_h+p_l)
*/
i = j&0x7fffffff;
k = (i>>23)-0x7f;
n = 0;
if(i>0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00800000>>(k+1));
k = ((n&0x7fffffff)>>23)-0x7f; /* new k for n */
SET_FLOAT_WORD(t,n&~(0x007fffff>>k));
n = ((n&0x007fffff)|0x00800000)>>(23-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
GET_FLOAT_WORD(is,t);
SET_FLOAT_WORD(t,is&0xfffff000);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_FLOAT_WORD(j,z);
j += (n<<23);
if((j>>23)<=0) z = scalbnf(z,n); /* subnormal output */
else SET_FLOAT_WORD(z,j);
return s*z;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_rem_p.c
0,0 → 1,172
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_rem_pio2f.c -- float version of e_rem_pio2.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_rem_pio2f.c,v 1.2 1994/08/18 23:05:58 jtc Exp $";
#endif
 
/* __ieee754_rem_pio2f(x,y)
*
* return the remainder of x rem pi/2 in y[0]+y[1]
* use __kernel_rem_pio2f()
*/
 
#include "math.h"
#include "math_private.h"
 
/*
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
#ifdef __STDC__
static const int32_t two_over_pi[] = {
#else
static int32_t two_over_pi[] = {
#endif
0xA2, 0xF9, 0x83, 0x6E, 0x4E, 0x44, 0x15, 0x29, 0xFC,
0x27, 0x57, 0xD1, 0xF5, 0x34, 0xDD, 0xC0, 0xDB, 0x62,
0x95, 0x99, 0x3C, 0x43, 0x90, 0x41, 0xFE, 0x51, 0x63,
0xAB, 0xDE, 0xBB, 0xC5, 0x61, 0xB7, 0x24, 0x6E, 0x3A,
0x42, 0x4D, 0xD2, 0xE0, 0x06, 0x49, 0x2E, 0xEA, 0x09,
0xD1, 0x92, 0x1C, 0xFE, 0x1D, 0xEB, 0x1C, 0xB1, 0x29,
0xA7, 0x3E, 0xE8, 0x82, 0x35, 0xF5, 0x2E, 0xBB, 0x44,
0x84, 0xE9, 0x9C, 0x70, 0x26, 0xB4, 0x5F, 0x7E, 0x41,
0x39, 0x91, 0xD6, 0x39, 0x83, 0x53, 0x39, 0xF4, 0x9C,
0x84, 0x5F, 0x8B, 0xBD, 0xF9, 0x28, 0x3B, 0x1F, 0xF8,
0x97, 0xFF, 0xDE, 0x05, 0x98, 0x0F, 0xEF, 0x2F, 0x11,
0x8B, 0x5A, 0x0A, 0x6D, 0x1F, 0x6D, 0x36, 0x7E, 0xCF,
0x27, 0xCB, 0x09, 0xB7, 0x4F, 0x46, 0x3F, 0x66, 0x9E,
0x5F, 0xEA, 0x2D, 0x75, 0x27, 0xBA, 0xC7, 0xEB, 0xE5,
0xF1, 0x7B, 0x3D, 0x07, 0x39, 0xF7, 0x8A, 0x52, 0x92,
0xEA, 0x6B, 0xFB, 0x5F, 0xB1, 0x1F, 0x8D, 0x5D, 0x08,
0x56, 0x03, 0x30, 0x46, 0xFC, 0x7B, 0x6B, 0xAB, 0xF0,
0xCF, 0xBC, 0x20, 0x9A, 0xF4, 0x36, 0x1D, 0xA9, 0xE3,
0x91, 0x61, 0x5E, 0xE6, 0x1B, 0x08, 0x65, 0x99, 0x85,
0x5F, 0x14, 0xA0, 0x68, 0x40, 0x8D, 0xFF, 0xD8, 0x80,
0x4D, 0x73, 0x27, 0x31, 0x06, 0x06, 0x15, 0x56, 0xCA,
0x73, 0xA8, 0xC9, 0x60, 0xE2, 0x7B, 0xC0, 0x8C, 0x6B,
};
 
/* This array is like the one in e_rem_pio2.c, but the numbers are
single precision and the last 8 bits are forced to 0. */
#ifdef __STDC__
static const int32_t npio2_hw[] = {
#else
static int32_t npio2_hw[] = {
#endif
0x3fc90f00, 0x40490f00, 0x4096cb00, 0x40c90f00, 0x40fb5300, 0x4116cb00,
0x412fed00, 0x41490f00, 0x41623100, 0x417b5300, 0x418a3a00, 0x4196cb00,
0x41a35c00, 0x41afed00, 0x41bc7e00, 0x41c90f00, 0x41d5a000, 0x41e23100,
0x41eec200, 0x41fb5300, 0x4203f200, 0x420a3a00, 0x42108300, 0x4216cb00,
0x421d1400, 0x42235c00, 0x4229a500, 0x422fed00, 0x42363600, 0x423c7e00,
0x4242c700, 0x42490f00
};
 
/*
* invpio2: 24 bits of 2/pi
* pio2_1: first 17 bit of pi/2
* pio2_1t: pi/2 - pio2_1
* pio2_2: second 17 bit of pi/2
* pio2_2t: pi/2 - (pio2_1+pio2_2)
* pio2_3: third 17 bit of pi/2
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
*/
 
#ifdef __STDC__
static const float
#else
static float
#endif
zero = 0.0000000000e+00, /* 0x00000000 */
half = 5.0000000000e-01, /* 0x3f000000 */
two8 = 2.5600000000e+02, /* 0x43800000 */
invpio2 = 6.3661980629e-01, /* 0x3f22f984 */
pio2_1 = 1.5707855225e+00, /* 0x3fc90f80 */
pio2_1t = 1.0804334124e-05, /* 0x37354443 */
pio2_2 = 1.0804273188e-05, /* 0x37354400 */
pio2_2t = 6.0770999344e-11, /* 0x2e85a308 */
pio2_3 = 6.0770943833e-11, /* 0x2e85a300 */
pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
 
#ifdef __STDC__
int32_t __ieee754_rem_pio2f(float x, float *y)
#else
int32_t __ieee754_rem_pio2f(x,y)
float x,y[];
#endif
{
float z,w,t,r,fn;
float tx[3];
int32_t e0,i,j,nx,n,ix,hx;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix<=0x3f490fd8) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */
t = fabsf(x);
n = (int32_t) (t*invpio2+half);
fn = (float)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 40 bit */
if(n<32&&(ix&0xffffff00)!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
u_int32_t high;
j = ix>>23;
y[0] = r-w;
GET_FLOAT_WORD(high,y[0]);
i = j-((high>>23)&0xff);
if(i>8) { /* 2nd iteration needed, good to 57 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
GET_FLOAT_WORD(high,y[0]);
i = j-((high>>23)&0xff);
if(i>25) { /* 3rd iteration need, 74 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
/*
* all other (large) arguments
*/
if(ix>=0x7f800000) { /* x is inf or NaN */
y[0]=y[1]=x-x; return 0;
}
/* set z = scalbn(|x|,ilogb(x)-7) */
e0 = (ix>>23)-134; /* e0 = ilogb(z)-7; */
SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23)));
for(i=0;i<2;i++) {
tx[i] = (float)((int32_t)(z));
z = (z-tx[i])*two8;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--; /* skip zero term */
n = __kernel_rem_pio2f(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_remai.s
0,0 → 1,11
#include<libc/asm.h>
 
MK_C_SYM(__ieee754_remainderf)
flds 8(%esp)
flds 4(%esp)
1: fprem1
fstsw %ax
sahf
jp 1b
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_scalb.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(__ieee754_scalbf)
flds 8(%esp)
flds 4(%esp)
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/ef_sinh.c
0,0 → 1,69
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_sinhf.c -- float version of e_sinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_sinhf.c,v 1.2 1994/08/18 23:06:04 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float one = 1.0, shuge = 1.0e37;
#else
static float one = 1.0, shuge = 1.0e37;
#endif
 
#ifdef __STDC__
float __ieee754_sinhf(float x)
#else
float __ieee754_sinhf(x)
float x;
#endif
{
float t,w,h;
int32_t ix,jx;
 
GET_FLOAT_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7f800000) return x+x;
 
h = 0.5;
if (jx<0) h = -h;
/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
if (ix < 0x41b00000) { /* |x|<22 */
if (ix<0x31800000) /* |x|<2**-28 */
if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
t = expm1f(fabsf(x));
if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one));
return h*(t+t/(t+one));
}
 
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
if (ix < 0x42b17180) return h*__ieee754_expf(fabsf(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
if (ix<=0x42b2d4fc) {
w = __ieee754_expf((float)0.5*fabsf(x));
t = h*w;
return t*w;
}
 
/* |x| > overflowthresold, sinh(x) overflow */
return x*shuge;
}
/programs/develop/libraries/menuetlibc/src/libm/ef_sinh.s
0,0 → 1,8
.file "ef_sinh.c"
.text
.align 4
_one:
.long 1065353216
.align 4
_shuge:
.long 2096152002
/programs/develop/libraries/menuetlibc/src/libm/ef_sqrt.s
0,0 → 1,5
#include<libc/asm.h>
MK_C_SYM(__ieee754_sqrtf)
flds 4(%esp)
fsqrt
ret
/programs/develop/libraries/menuetlibc/src/libm/er_gamma.c
0,0 → 1,36
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)er_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_gamma_r.c,v 1.4 1994/08/10 20:30:52 jtc Exp $";
#endif
 
/* __ieee754_gamma_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method: See __ieee754_lgamma_r
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double __ieee754_gamma_r(double x, int *signgamp)
#else
double __ieee754_gamma_r(x,signgamp)
double x; int *signgamp;
#endif
{
return __ieee754_lgamma_r(x,signgamp);
}
/programs/develop/libraries/menuetlibc/src/libm/er_lgamm.c
0,0 → 1,313
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)er_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_lgamma_r.c,v 1.5 1994/08/10 20:31:07 jtc Exp $";
#endif
 
/* __ieee754_lgamma_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method:
* 1. Argument Reduction for 0 < x <= 8
* Since gamma(1+s)=s*gamma(s), for x in [0,8], we may
* reduce x to a number in [1.5,2.5] by
* lgamma(1+s) = log(s) + lgamma(s)
* for example,
* lgamma(7.3) = log(6.3) + lgamma(6.3)
* = log(6.3*5.3) + lgamma(5.3)
* = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
* 2. Polynomial approximation of lgamma around its
* minimun ymin=1.461632144968362245 to maintain monotonicity.
* On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
* Let z = x-ymin;
* lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
* where
* poly(z) is a 14 degree polynomial.
* 2. Rational approximation in the primary interval [2,3]
* We use the following approximation:
* s = x-2.0;
* lgamma(x) = 0.5*s + s*P(s)/Q(s)
* with accuracy
* |P/Q - (lgamma(x)-0.5s)| < 2**-61.71
* Our algorithms are based on the following observation
*
* zeta(2)-1 2 zeta(3)-1 3
* lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ...
* 2 3
*
* where Euler = 0.5771... is the Euler constant, which is very
* close to 0.5.
*
* 3. For x>=8, we have
* lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
* (better formula:
* lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
* Let z = 1/x, then we approximation
* f(z) = lgamma(x) - (x-0.5)(log(x)-1)
* by
* 3 5 11
* w = w0 + w1*z + w2*z + w3*z + ... + w6*z
* where
* |w - f(z)| < 2**-58.74
*
* 4. For negative x, since (G is gamma function)
* -x*G(-x)*G(x) = pi/sin(pi*x),
* we have
* G(x) = pi/(sin(pi*x)*(-x)*G(-x))
* since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
* Hence, for x<0, signgam = sign(sin(pi*x)) and
* lgamma(x) = log(|Gamma(x)|)
* = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
* Note: one should avoid compute pi*(-x) directly in the
* computation of sin(pi*(-x)).
*
* 5. Special Cases
* lgamma(2+s) ~ s*(1-Euler) for tiny s
* lgamma(1)=lgamma(2)=0
* lgamma(x) ~ -log(x) for tiny x
* lgamma(0) = lgamma(inf) = inf
* lgamma(-integer) = +-inf
*
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
two52= 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
a0 = 7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */
a1 = 3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */
a2 = 6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */
a3 = 2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */
a4 = 7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */
a5 = 2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */
a6 = 1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */
a7 = 5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */
a8 = 2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */
a9 = 1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */
a10 = 2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */
a11 = 4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */
tc = 1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */
tf = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */
/* tt = -(tail of tf) */
tt = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */
t0 = 4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */
t1 = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */
t2 = 6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */
t3 = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */
t4 = 1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */
t5 = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */
t6 = 6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */
t7 = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */
t8 = 2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */
t9 = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */
t10 = 8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */
t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */
t12 = 3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */
t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */
t14 = 3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */
u0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
u1 = 6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */
u2 = 1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */
u3 = 9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */
u4 = 2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */
u5 = 1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */
v1 = 2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */
v2 = 2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */
v3 = 7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */
v4 = 1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */
v5 = 3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */
s0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
s1 = 2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */
s2 = 3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */
s3 = 1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */
s4 = 2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */
s5 = 1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */
s6 = 3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */
r1 = 1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */
r2 = 7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */
r3 = 1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */
r4 = 1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */
r5 = 7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */
r6 = 7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */
w0 = 4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */
w1 = 8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */
w2 = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */
w3 = 7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */
w4 = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */
w5 = 8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */
w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */
 
#ifdef __STDC__
static const double zero= 0.00000000000000000000e+00;
#else
static double zero= 0.00000000000000000000e+00;
#endif
 
#ifdef __STDC__
static double sin_pi(double x)
#else
static double sin_pi(x)
double x;
#endif
{
double y,z;
int n,ix;
 
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
 
if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
y = -x; /* x is assume negative */
 
/*
* argument reduction, make sure inexact flag not raised if input
* is an integer
*/
z = floor(y);
if(z!=y) { /* inexact anyway */
y *= 0.5;
y = 2.0*(y - floor(y)); /* y = |x| mod 2.0 */
n = (int) (y*4.0);
} else {
if(ix>=0x43400000) {
y = zero; n = 0; /* y must be even */
} else {
if(ix<0x43300000) z = y+two52; /* exact */
GET_LOW_WORD(n,z);
n &= 1;
y = n;
n<<= 2;
}
}
switch (n) {
case 0: y = __kernel_sin(pi*y,zero,0); break;
case 1:
case 2: y = __kernel_cos(pi*(0.5-y),zero); break;
case 3:
case 4: y = __kernel_sin(pi*(one-y),zero,0); break;
case 5:
case 6: y = -__kernel_cos(pi*(y-1.5),zero); break;
default: y = __kernel_sin(pi*(y-2.0),zero,0); break;
}
return -y;
}
 
 
#ifdef __STDC__
double __ieee754_lgamma_r(double x, int *signgamp)
#else
double __ieee754_lgamma_r(x,signgamp)
double x; int *signgamp;
#endif
{
double t,y,z,nadj,p,p1,p2,p3,q,r,w;
int i,hx,lx,ix;
 
EXTRACT_WORDS(hx,lx,x);
 
/* purge off +-inf, NaN, +-0, and negative arguments */
*signgamp = 1;
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return x*x;
if((ix|lx)==0) return one/zero;
if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */
if(hx<0) {
*signgamp = -1;
return -__ieee754_log(-x);
} else return -__ieee754_log(x);
}
if(hx<0) {
if(ix>=0x43300000) /* |x|>=2**52, must be -integer */
return one/zero;
t = sin_pi(x);
if(t==zero) return one/zero; /* -integer */
nadj = __ieee754_log(pi/fabs(t*x));
if(t<zero) *signgamp = -1;
x = -x;
}
 
/* purge off 1 and 2 */
if((((ix-0x3ff00000)|lx)==0)||(((ix-0x40000000)|lx)==0)) r = 0;
/* for x < 2.0 */
else if(ix<0x40000000) {
if(ix<=0x3feccccc) { /* lgamma(x) = lgamma(x+1)-log(x) */
r = -__ieee754_log(x);
if(ix>=0x3FE76944) {y = one-x; i= 0;}
else if(ix>=0x3FCDA661) {y= x-(tc-one); i=1;}
else {y = x; i=2;}
} else {
r = zero;
if(ix>=0x3FFBB4C3) {y=2.0-x;i=0;} /* [1.7316,2] */
else if(ix>=0x3FF3B4C4) {y=x-tc;i=1;} /* [1.23,1.73] */
else {y=x-one;i=2;}
}
switch(i) {
case 0:
z = y*y;
p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
p = y*p1+p2;
r += (p-0.5*y); break;
case 1:
z = y*y;
w = z*y;
p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */
p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
p = z*p1-(tt-w*(p2+y*p3));
r += (tf + p); break;
case 2:
p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
r += (-0.5*y + p1/p2);
}
}
else if(ix<0x40200000) { /* x < 8.0 */
i = (int)x;
t = zero;
y = x-(double)i;
p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
r = half*y+p/q;
z = one; /* lgamma(1+s) = log(s) + lgamma(s) */
switch(i) {
case 7: z *= (y+6.0); /* FALLTHRU */
case 6: z *= (y+5.0); /* FALLTHRU */
case 5: z *= (y+4.0); /* FALLTHRU */
case 4: z *= (y+3.0); /* FALLTHRU */
case 3: z *= (y+2.0); /* FALLTHRU */
r += __ieee754_log(z); break;
}
/* 8.0 <= x < 2**58 */
} else if (ix < 0x43900000) {
t = __ieee754_log(x);
z = one/x;
y = z*z;
w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
r = (x-half)*(t-one)+w;
} else
/* 2**58 <= x <= inf */
r = x*(__ieee754_log(x)-one);
if(hx<0) r = nadj - r;
return r;
}
/programs/develop/libraries/menuetlibc/src/libm/erf_gamm.c
0,0 → 1,39
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_gammaf_r.c -- float version of e_gamma_r.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_gammaf_r.c,v 1.1 1994/08/10 20:30:54 jtc Exp $";
#endif
 
/* __ieee754_gammaf_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method: See __ieee754_lgammaf_r
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float __ieee754_gammaf_r(float x, int *signgamp)
#else
float __ieee754_gammaf_r(x,signgamp)
float x; int *signgamp;
#endif
{
return __ieee754_lgammaf_r(x,signgamp);
}
/programs/develop/libraries/menuetlibc/src/libm/erf_lgam.c
0,0 → 1,249
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* e_lgammaf_r.c -- float version of e_lgamma_r.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: e_lgammaf_r.c,v 1.1 1994/08/10 20:31:09 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
two23= 8.3886080000e+06, /* 0x4b000000 */
half= 5.0000000000e-01, /* 0x3f000000 */
one = 1.0000000000e+00, /* 0x3f800000 */
pi = 3.1415927410e+00, /* 0x40490fdb */
a0 = 7.7215664089e-02, /* 0x3d9e233f */
a1 = 3.2246702909e-01, /* 0x3ea51a66 */
a2 = 6.7352302372e-02, /* 0x3d89f001 */
a3 = 2.0580807701e-02, /* 0x3ca89915 */
a4 = 7.3855509982e-03, /* 0x3bf2027e */
a5 = 2.8905137442e-03, /* 0x3b3d6ec6 */
a6 = 1.1927076848e-03, /* 0x3a9c54a1 */
a7 = 5.1006977446e-04, /* 0x3a05b634 */
a8 = 2.2086278477e-04, /* 0x39679767 */
a9 = 1.0801156895e-04, /* 0x38e28445 */
a10 = 2.5214456400e-05, /* 0x37d383a2 */
a11 = 4.4864096708e-05, /* 0x383c2c75 */
tc = 1.4616321325e+00, /* 0x3fbb16c3 */
tf = -1.2148628384e-01, /* 0xbdf8cdcd */
/* tt = -(tail of tf) */
tt = 6.6971006518e-09, /* 0x31e61c52 */
t0 = 4.8383611441e-01, /* 0x3ef7b95e */
t1 = -1.4758771658e-01, /* 0xbe17213c */
t2 = 6.4624942839e-02, /* 0x3d845a15 */
t3 = -3.2788541168e-02, /* 0xbd064d47 */
t4 = 1.7970675603e-02, /* 0x3c93373d */
t5 = -1.0314224288e-02, /* 0xbc28fcfe */
t6 = 6.1005386524e-03, /* 0x3bc7e707 */
t7 = -3.6845202558e-03, /* 0xbb7177fe */
t8 = 2.2596477065e-03, /* 0x3b141699 */
t9 = -1.4034647029e-03, /* 0xbab7f476 */
t10 = 8.8108185446e-04, /* 0x3a66f867 */
t11 = -5.3859531181e-04, /* 0xba0d3085 */
t12 = 3.1563205994e-04, /* 0x39a57b6b */
t13 = -3.1275415677e-04, /* 0xb9a3f927 */
t14 = 3.3552918467e-04, /* 0x39afe9f7 */
u0 = -7.7215664089e-02, /* 0xbd9e233f */
u1 = 6.3282704353e-01, /* 0x3f2200f4 */
u2 = 1.4549225569e+00, /* 0x3fba3ae7 */
u3 = 9.7771751881e-01, /* 0x3f7a4bb2 */
u4 = 2.2896373272e-01, /* 0x3e6a7578 */
u5 = 1.3381091878e-02, /* 0x3c5b3c5e */
v1 = 2.4559779167e+00, /* 0x401d2ebe */
v2 = 2.1284897327e+00, /* 0x4008392d */
v3 = 7.6928514242e-01, /* 0x3f44efdf */
v4 = 1.0422264785e-01, /* 0x3dd572af */
v5 = 3.2170924824e-03, /* 0x3b52d5db */
s0 = -7.7215664089e-02, /* 0xbd9e233f */
s1 = 2.1498242021e-01, /* 0x3e5c245a */
s2 = 3.2577878237e-01, /* 0x3ea6cc7a */
s3 = 1.4635047317e-01, /* 0x3e15dce6 */
s4 = 2.6642270386e-02, /* 0x3cda40e4 */
s5 = 1.8402845599e-03, /* 0x3af135b4 */
s6 = 3.1947532989e-05, /* 0x3805ff67 */
r1 = 1.3920053244e+00, /* 0x3fb22d3b */
r2 = 7.2193557024e-01, /* 0x3f38d0c5 */
r3 = 1.7193385959e-01, /* 0x3e300f6e */
r4 = 1.8645919859e-02, /* 0x3c98bf54 */
r5 = 7.7794247773e-04, /* 0x3a4beed6 */
r6 = 7.3266842264e-06, /* 0x36f5d7bd */
w0 = 4.1893854737e-01, /* 0x3ed67f1d */
w1 = 8.3333335817e-02, /* 0x3daaaaab */
w2 = -2.7777778450e-03, /* 0xbb360b61 */
w3 = 7.9365057172e-04, /* 0x3a500cfd */
w4 = -5.9518753551e-04, /* 0xba1c065c */
w5 = 8.3633989561e-04, /* 0x3a5b3dd2 */
w6 = -1.6309292987e-03; /* 0xbad5c4e8 */
 
#ifdef __STDC__
static const float zero= 0.0000000000e+00;
#else
static float zero= 0.0000000000e+00;
#endif
 
#ifdef __STDC__
static float sin_pif(float x)
#else
static float sin_pif(x)
float x;
#endif
{
float y,z;
int n,ix;
 
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
 
if(ix<0x3e800000) return __kernel_sinf(pi*x,zero,0);
y = -x; /* x is assume negative */
 
/*
* argument reduction, make sure inexact flag not raised if input
* is an integer
*/
z = floorf(y);
if(z!=y) { /* inexact anyway */
y *= (float)0.5;
y = (float)2.0*(y - floorf(y)); /* y = |x| mod 2.0 */
n = (int) (y*(float)4.0);
} else {
if(ix>=0x4b800000) {
y = zero; n = 0; /* y must be even */
} else {
if(ix<0x4b000000) z = y+two23; /* exact */
GET_FLOAT_WORD(n,z);
n &= 1;
y = n;
n<<= 2;
}
}
switch (n) {
case 0: y = __kernel_sinf(pi*y,zero,0); break;
case 1:
case 2: y = __kernel_cosf(pi*((float)0.5-y),zero); break;
case 3:
case 4: y = __kernel_sinf(pi*(one-y),zero,0); break;
case 5:
case 6: y = -__kernel_cosf(pi*(y-(float)1.5),zero); break;
default: y = __kernel_sinf(pi*(y-(float)2.0),zero,0); break;
}
return -y;
}
 
 
#ifdef __STDC__
float __ieee754_lgammaf_r(float x, int *signgamp)
#else
float __ieee754_lgammaf_r(x,signgamp)
float x; int *signgamp;
#endif
{
float t,y,z,nadj,p,p1,p2,p3,q,r,w;
int i,hx,ix;
 
GET_FLOAT_WORD(hx,x);
 
/* purge off +-inf, NaN, +-0, and negative arguments */
*signgamp = 1;
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return x*x;
if(ix==0) return one/zero;
if(ix<0x1c800000) { /* |x|<2**-70, return -log(|x|) */
if(hx<0) {
*signgamp = -1;
return -__ieee754_logf(-x);
} else return -__ieee754_logf(x);
}
if(hx<0) {
if(ix>=0x4b000000) /* |x|>=2**23, must be -integer */
return one/zero;
t = sin_pif(x);
if(t==zero) return one/zero; /* -integer */
nadj = __ieee754_logf(pi/fabsf(t*x));
if(t<zero) *signgamp = -1;
x = -x;
}
 
/* purge off 1 and 2 */
if (ix==0x3f800000||ix==0x40000000) r = 0;
/* for x < 2.0 */
else if(ix<0x40000000) {
if(ix<=0x3f666666) { /* lgamma(x) = lgamma(x+1)-log(x) */
r = -__ieee754_logf(x);
if(ix>=0x3f3b4a20) {y = one-x; i= 0;}
else if(ix>=0x3e6d3308) {y= x-(tc-one); i=1;}
else {y = x; i=2;}
} else {
r = zero;
if(ix>=0x3fdda618) {y=(float)2.0-x;i=0;} /* [1.7316,2] */
else if(ix>=0x3F9da620) {y=x-tc;i=1;} /* [1.23,1.73] */
else {y=x-one;i=2;}
}
switch(i) {
case 0:
z = y*y;
p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
p = y*p1+p2;
r += (p-(float)0.5*y); break;
case 1:
z = y*y;
w = z*y;
p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */
p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
p = z*p1-(tt-w*(p2+y*p3));
r += (tf + p); break;
case 2:
p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
r += (-(float)0.5*y + p1/p2);
}
}
else if(ix<0x41000000) { /* x < 8.0 */
i = (int)x;
t = zero;
y = x-(float)i;
p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
r = half*y+p/q;
z = one; /* lgamma(1+s) = log(s) + lgamma(s) */
switch(i) {
case 7: z *= (y+(float)6.0); /* FALLTHRU */
case 6: z *= (y+(float)5.0); /* FALLTHRU */
case 5: z *= (y+(float)4.0); /* FALLTHRU */
case 4: z *= (y+(float)3.0); /* FALLTHRU */
case 3: z *= (y+(float)2.0); /* FALLTHRU */
r += __ieee754_logf(z); break;
}
/* 8.0 <= x < 2**58 */
} else if (ix < 0x5c800000) {
t = __ieee754_logf(x);
z = one/x;
y = z*z;
w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
r = (x-half)*(t-one)+w;
} else
/* 2**58 <= x <= inf */
r = x*(__ieee754_logf(x)-one);
if(hx<0) r = nadj - r;
return r;
}
/programs/develop/libraries/menuetlibc/src/libm/k_cos.c
0,0 → 1,97
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)k_cos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_cos.c,v 1.6 1994/08/18 23:06:08 jtc Exp $";
#endif
 
/*
* __kernel_cos( x, y )
* kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
*
* Algorithm
* 1. Since cos(-x) = cos(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
* 3. cos(x) is approximated by a polynomial of degree 14 on
* [0,pi/4]
* 4 14
* cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
* where the remez error is
*
* | 2 4 6 8 10 12 14 | -58
* |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
* | |
*
* 4 6 8 10 12 14
* 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
* cos(x) = 1 - x*x/2 + r
* since cos(x+y) ~ cos(x) - sin(x)*y
* ~ cos(x) - x*y,
* a correction term is necessary in cos(x) and hence
* cos(x+y) = 1 - (x*x/2 - (r - x*y))
* For better accuracy when x > 0.3, let qx = |x|/4 with
* the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
* Then
* cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
* Note that 1-qx and (x*x/2-qx) is EXACT here, and the
* magnitude of the latter is at least a quarter of x*x/2,
* thus, reducing the rounding error in the subtraction.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
 
#ifdef __STDC__
double __kernel_cos(double x, double y)
#else
double __kernel_cos(x, y)
double x,y;
#endif
{
double a,hz,z,r,qx;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x3e400000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3FD33333) /* if |x| < 0.3 */
return one - (0.5*z - (z*r - x*y));
else {
if(ix > 0x3fe90000) { /* x > 0.78125 */
qx = 0.28125;
} else {
INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
}
hz = 0.5*z-qx;
a = one-qx;
return a - (hz - (z*r-x*y));
}
}
/programs/develop/libraries/menuetlibc/src/libm/k_rem_pi.c
0,0 → 1,321
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)k_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_rem_pio2.c,v 1.5 1994/08/18 23:06:11 jtc Exp $";
#endif
 
/*
* __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
* double x[],y[]; int e0,nx,prec; int ipio2[];
*
* __kernel_rem_pio2 return the last three digits of N with
* y = x - N*pi/2
* so that |y| < pi/2.
*
* The method is to compute the integer (mod 8) and fraction parts of
* (2/pi)*x without doing the full multiplication. In general we
* skip the part of the product that are known to be a huge integer (
* more accurately, = 0 mod 8 ). Thus the number of operations are
* independent of the exponent of the input.
*
* (2/pi) is represented by an array of 24-bit integers in ipio2[].
*
* Input parameters:
* x[] The input value (must be positive) is broken into nx
* pieces of 24-bit integers in double precision format.
* x[i] will be the i-th 24 bit of x. The scaled exponent
* of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
* match x's up to 24 bits.
*
* Example of breaking a double positive z into x[0]+x[1]+x[2]:
* e0 = ilogb(z)-23
* z = scalbn(z,-e0)
* for i = 0,1,2
* x[i] = floor(z)
* z = (z-x[i])*2**24
*
*
* y[] ouput result in an array of double precision numbers.
* The dimension of y[] is:
* 24-bit precision 1
* 53-bit precision 2
* 64-bit precision 2
* 113-bit precision 3
* The actual value is the sum of them. Thus for 113-bit
* precison, one may have to do something like:
*
* long double t,w,r_head, r_tail;
* t = (long double)y[2] + (long double)y[1];
* w = (long double)y[0];
* r_head = t+w;
* r_tail = w - (r_head - t);
*
* e0 The exponent of x[0]
*
* nx dimension of x[]
*
* prec an integer indicating the precision:
* 0 24 bits (single)
* 1 53 bits (double)
* 2 64 bits (extended)
* 3 113 bits (quad)
*
* ipio2[]
* integer array, contains the (24*i)-th to (24*i+23)-th
* bit of 2/pi after binary point. The corresponding
* floating value is
*
* ipio2[i] * 2^(-24(i+1)).
*
* External function:
* double scalbn(), floor();
*
*
* Here is the description of some local variables:
*
* jk jk+1 is the initial number of terms of ipio2[] needed
* in the computation. The recommended value is 2,3,4,
* 6 for single, double, extended,and quad.
*
* jz local integer variable indicating the number of
* terms of ipio2[] used.
*
* jx nx - 1
*
* jv index for pointing to the suitable ipio2[] for the
* computation. In general, we want
* ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
* is an integer. Thus
* e0-3-24*jv >= 0 or (e0-3)/24 >= jv
* Hence jv = max(0,(e0-3)/24).
*
* jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
*
* q[] double array with integral value, representing the
* 24-bits chunk of the product of x and 2/pi.
*
* q0 the corresponding exponent of q[0]. Note that the
* exponent for q[i] would be q0-24*i.
*
* PIo2[] double precision array, obtained by cutting pi/2
* into 24 bits chunks.
*
* f[] ipio2[] in floating point
*
* iq[] integer array by breaking up q[] in 24-bits chunk.
*
* fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
*
* ih integer. If >0 it indicates q[] is >= 0.5, hence
* it also indicates the *sign* of the result.
*
*/
 
 
/*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
#else
static int init_jk[] = {2,3,4,6};
#endif
 
#ifdef __STDC__
static const double PIo2[] = {
#else
static double PIo2[] = {
#endif
1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
};
 
#ifdef __STDC__
static const double
#else
static double
#endif
zero = 0.0,
one = 1.0,
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
 
#ifdef __STDC__
int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
#else
int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
double x[], y[]; int e0,nx,prec; int32_t ipio2[];
#endif
{
int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
double z,fw,f[20],fq[20],q[20];
 
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
 
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1;
jv = (e0-3)/24; if(jv<0) jv=0;
q0 = e0-24*(jv+1);
 
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
 
/* compute q[0],q[1],...q[jk] */
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
 
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (double)((int32_t)(twon24* z));
iq[i] = (int32_t)(z-two24*fw);
z = q[j-1]+fw;
}
 
/* compute n */
z = scalbn(z,q0); /* actual value of z */
z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
n = (int32_t) z;
z -= (double)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(24-q0)); n += i;
iq[jz-1] -= i<<(24-q0);
ih = iq[jz-1]>>(23-q0);
}
else if(q0==0) ih = iq[jz-1]>>23;
else if(z>=0.5) ih=2;
 
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x1000000- j;
}
} else iq[i] = 0xffffff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7fffff; break;
case 2:
iq[jz-1] &= 0x3fffff; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbn(one,q0);
}
}
 
/* check if recomputation is needed */
if(z==zero) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
 
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (double) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
 
/* chop off zero terms */
if(z==0.0) {
jz -= 1; q0 -= 24;
while(iq[jz]==0) { jz--; q0-=24;}
} else { /* break z into 24-bit if necessary */
z = scalbn(z,-q0);
if(z>=two24) {
fw = (double)((int32_t)(twon24*z));
iq[jz] = (int32_t)(z-two24*fw);
jz += 1; q0 += 24;
iq[jz] = (int32_t) fw;
} else iq[jz] = (int32_t) z ;
}
 
/* convert integer "bit" chunk to floating-point value */
fw = scalbn(one,q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(double)iq[i]; fw*=twon24;
}
 
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
 
/* compress fq[] into y[] */
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}
/programs/develop/libraries/menuetlibc/src/libm/k_sin.c
0,0 → 1,80
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)k_sin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_sin.c,v 1.6 1994/08/18 23:06:14 jtc Exp $";
#endif
 
/* __kernel_sin( x, y, iy)
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
*
* Algorithm
* 1. Since sin(-x) = -sin(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
* 3. sin(x) is approximated by a polynomial of degree 13 on
* [0,pi/4]
* 3 13
* sin(x) ~ x + S1*x + ... + S6*x
* where
*
* |sin(x) 2 4 6 8 10 12 | -58
* |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
* | x |
*
* 4. sin(x+y) = sin(x) + sin'(x')*y
* ~ sin(x) + (1-x*x/2)*y
* For better accuracy, let
* 3 2 2 2 2
* r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
* then 3 2
* sin(x) = x + (S1*x + (x *(r-y/2)+y))
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
 
#ifdef __STDC__
double __kernel_sin(double x, double y, int iy)
#else
double __kernel_sin(x, y, iy)
double x,y; int iy; /* iy=0 if y is zero */
#endif
{
double z,r,v;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* high word of x */
if(ix<0x3e400000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}
/programs/develop/libraries/menuetlibc/src/libm/k_standa.c
0,0 → 1,783
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)k_standard.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_standard.c,v 1.4 1994/08/10 20:31:44 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
#include <errno.h>
 
#ifndef _USE_WRITE
#include <stdio.h> /* fputs(), stderr */
#define WRITE2(u,v) fputs(u, stderr)
#else /* !defined(_USE_WRITE) */
#include <unistd.h> /* write */
#define WRITE2(u,v) write(2, u, v)
#undef fflush
#endif /* !defined(_USE_WRITE) */
 
#ifdef __STDC__
static const double zero = 0.0; /* used as const */
#else
static double zero = 0.0; /* used as const */
#endif
 
/*
* Standard conformance (non-IEEE) on exception cases.
* Mapping:
* 1 -- acos(|x|>1)
* 2 -- asin(|x|>1)
* 3 -- atan2(+-0,+-0)
* 4 -- hypot overflow
* 5 -- cosh overflow
* 6 -- exp overflow
* 7 -- exp underflow
* 8 -- y0(0)
* 9 -- y0(-ve)
* 10-- y1(0)
* 11-- y1(-ve)
* 12-- yn(0)
* 13-- yn(-ve)
* 14-- lgamma(finite) overflow
* 15-- lgamma(-integer)
* 16-- log(0)
* 17-- log(x<0)
* 18-- log10(0)
* 19-- log10(x<0)
* 20-- pow(0.0,0.0)
* 21-- pow(x,y) overflow
* 22-- pow(x,y) underflow
* 23-- pow(0,negative)
* 24-- pow(neg,non-integral)
* 25-- sinh(finite) overflow
* 26-- sqrt(negative)
* 27-- fmod(x,0)
* 28-- remainder(x,0)
* 29-- acosh(x<1)
* 30-- atanh(|x|>1)
* 31-- atanh(|x|=1)
* 32-- scalb overflow
* 33-- scalb underflow
* 34-- j0(|x|>X_TLOSS)
* 35-- y0(x>X_TLOSS)
* 36-- j1(|x|>X_TLOSS)
* 37-- y1(x>X_TLOSS)
* 38-- jn(|x|>X_TLOSS, n)
* 39-- yn(x>X_TLOSS, n)
* 40-- gamma(finite) overflow
* 41-- gamma(-integer)
* 42-- pow(NaN,0.0)
*/
 
 
#ifdef __STDC__
double __kernel_standard(double x, double y, int type)
#else
double __kernel_standard(x,y,type)
double x,y; int type;
#endif
{
struct exception exc;
#ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
 
#ifdef _USE_WRITE
(void) fflush(stdout);
#endif
exc.arg1 = x;
exc.arg2 = y;
switch(type) {
case 1:
case 101:
/* acos(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "acos" : "acosf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if(_LIB_VERSION == _SVID_) {
(void) WRITE2("acos: DOMAIN error\n", 19);
}
errno = EDOM;
}
break;
case 2:
case 102:
/* asin(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "asin" : "asinf";
exc.retval = zero;
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if(_LIB_VERSION == _SVID_) {
(void) WRITE2("asin: DOMAIN error\n", 19);
}
errno = EDOM;
}
break;
case 3:
case 103:
/* atan2(+-0,+-0) */
exc.arg1 = y;
exc.arg2 = x;
exc.type = DOMAIN;
exc.name = type < 100 ? "atan2" : "atan2f";
exc.retval = zero;
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if(_LIB_VERSION == _SVID_) {
(void) WRITE2("atan2: DOMAIN error\n", 20);
}
errno = EDOM;
}
break;
case 4:
case 104:
/* hypot(finite,finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "hypot" : "hypotf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 5:
case 105:
/* cosh(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "cosh" : "coshf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 6:
case 106:
/* exp(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "exp" : "expf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 7:
case 107:
/* exp(finite) underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "exp" : "expf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 8:
case 108:
/* y0(0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "y0" : "y0f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y0: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 9:
case 109:
/* y0(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "y0" : "y0f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y0: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 10:
case 110:
/* y1(0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "y1" : "y1f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y1: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 11:
case 111:
/* y1(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "y1" : "y1f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y1: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 12:
case 112:
/* yn(n,0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "yn" : "ynf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("yn: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 13:
case 113:
/* yn(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "yn" : "ynf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("yn: DOMAIN error\n", 17);
}
errno = EDOM;
}
break;
case 14:
case 114:
/* lgamma(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "lgamma" : "lgammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 15:
case 115:
/* lgamma(-integer) or lgamma(0) */
exc.type = SING;
exc.name = type < 100 ? "lgamma" : "lgammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("lgamma: SING error\n", 19);
}
errno = EDOM;
}
break;
case 16:
case 116:
/* log(0) */
exc.type = SING;
exc.name = type < 100 ? "log" : "logf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log: SING error\n", 16);
}
errno = EDOM;
}
break;
case 17:
case 117:
/* log(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "log" : "logf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log: DOMAIN error\n", 18);
}
errno = EDOM;
}
break;
case 18:
case 118:
/* log10(0) */
exc.type = SING;
exc.name = type < 100 ? "log10" : "log10f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log10: SING error\n", 18);
}
errno = EDOM;
}
break;
case 19:
case 119:
/* log10(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "log10" : "log10f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE_VAL;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log10: DOMAIN error\n", 20);
}
errno = EDOM;
}
break;
case 20:
case 120:
/* pow(0.0,0.0) */
/* error only if _LIB_VERSION == _SVID_ */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = zero;
if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
else if (!matherr(&exc)) {
(void) WRITE2("pow(0,0): DOMAIN error\n", 23);
errno = EDOM;
}
break;
case 21:
case 121:
/* pow(x,y) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_) {
exc.retval = HUGE_VAL;
y *= 0.5;
if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
} else {
exc.retval = HUGE_VAL;
y *= 0.5;
if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
}
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 22:
case 122:
/* pow(x,y) underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 23:
case 123:
/* 0**neg */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
}
errno = EDOM;
}
break;
case 24:
case 124:
/* neg**non-integral */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = zero/zero; /* X/Open allow NaN */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
}
errno = EDOM;
}
break;
case 25:
case 125:
/* sinh(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "sinh" : "sinhf";
if (_LIB_VERSION == _SVID_)
exc.retval = ( (x>zero) ? HUGE_VAL: -HUGE_VAL);
else
exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 26:
case 126:
/* sqrt(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "sqrt" : "sqrtf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("sqrt: DOMAIN error\n", 19);
}
errno = EDOM;
}
break;
case 27:
case 127:
/* fmod(x,0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "fmod" : "fmodf";
if (_LIB_VERSION == _SVID_)
exc.retval = x;
else
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("fmod: DOMAIN error\n", 20);
}
errno = EDOM;
}
break;
case 28:
case 128:
/* remainder(x,0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "remainder" : "remainderf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("remainder: DOMAIN error\n", 24);
}
errno = EDOM;
}
break;
case 29:
case 129:
/* acosh(x<1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "acosh" : "acoshf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("acosh: DOMAIN error\n", 20);
}
errno = EDOM;
}
break;
case 30:
case 130:
/* atanh(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "atanh" : "atanhf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("atanh: DOMAIN error\n", 20);
}
errno = EDOM;
}
break;
case 31:
case 131:
/* atanh(|x|=1) */
exc.type = SING;
exc.name = type < 100 ? "atanh" : "atanhf";
exc.retval = x/zero; /* sign(x)*inf */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("atanh: SING error\n", 18);
}
errno = EDOM;
}
break;
case 32:
case 132:
/* scalb overflow; SVID also returns +-HUGE_VAL */
exc.type = OVERFLOW;
exc.name = type < 100 ? "scalb" : "scalbf";
exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 33:
case 133:
/* scalb underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "scalb" : "scalbf";
exc.retval = copysign(zero,x);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 34:
case 134:
/* j0(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "j0" : "j0f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 35:
case 135:
/* y0(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "y0" : "y0f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 36:
case 136:
/* j1(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "j1" : "j1f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 37:
case 137:
/* y1(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "y1" : "y1f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 38:
case 138:
/* jn(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "jn" : "jnf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 39:
case 139:
/* yn(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "yn" : "ynf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
}
errno = ERANGE;
}
break;
case 40:
case 140:
/* gamma(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "gamma" : "gammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 41:
case 141:
/* gamma(-integer) or gamma(0) */
exc.type = SING;
exc.name = type < 100 ? "gamma" : "gammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE_VAL;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
if (_LIB_VERSION == _SVID_) {
(void) WRITE2("gamma: SING error\n", 18);
}
errno = EDOM;
}
break;
case 42:
case 142:
/* pow(NaN,0.0) */
/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = x;
if (_LIB_VERSION == _IEEE_ ||
_LIB_VERSION == _POSIX_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
break;
}
return exc.retval;
}
/programs/develop/libraries/menuetlibc/src/libm/k_tan.c
0,0 → 1,132
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)k_tan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_tan.c,v 1.6 1994/08/18 23:06:16 jtc Exp $";
#endif
 
/* __kernel_tan( x, y, k )
* kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input k indicates whether tan (if k=1) or
* -1/tan (if k= -1) is returned.
*
* Algorithm
* 1. Since tan(-x) = -tan(x), we need only to consider positive x.
* 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
* 3. tan(x) is approximated by a odd polynomial of degree 27 on
* [0,0.67434]
* 3 27
* tan(x) ~ x + T1*x + ... + T13*x
* where
*
* |tan(x) 2 4 26 | -59.2
* |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
* | x |
*
* Note: tan(x+y) = tan(x) + tan'(x)*y
* ~ tan(x) + (1+x*x)*y
* Therefore, for better accuracy in computing tan(x+y), let
* 3 2 2 2 2
* r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
* then
* 3 2
* tan(x+y) = x + (T1*x + (x *(r+y)+y))
*
* 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
* tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
* = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
*/
 
#include "math.h"
#include "math_private.h"
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
T[] = {
3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
-1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
};
 
#ifdef __STDC__
double __kernel_tan(double x, double y, int iy)
#else
double __kernel_tan(x, y, iy)
double x,y; int iy;
#endif
{
double z,r,v,w,s;
int32_t ix,hx;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x3e300000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
u_int32_t low;
GET_LOW_WORD(low,x);
if(((ix|low)|(iy+1))==0) return one/fabs(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3FE59428) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3FE59428) {
v = (double)iy;
return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
double a,t;
z = w;
SET_LOW_WORD(z,0);
v = r-(z - x); /* z+v = r+x */
t = a = -1.0/w; /* a = -1.0/w */
SET_LOW_WORD(t,0);
s = 1.0+t*z;
return t+a*(s+t*v);
}
}
/programs/develop/libraries/menuetlibc/src/libm/kf_cos.c
0,0 → 1,65
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* k_cosf.c -- float version of k_cos.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_cosf.c,v 1.2 1994/08/18 23:06:10 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3f800000 */
C1 = 4.1666667908e-02, /* 0x3d2aaaab */
C2 = -1.3888889225e-03, /* 0xbab60b61 */
C3 = 2.4801587642e-05, /* 0x37d00d01 */
C4 = -2.7557314297e-07, /* 0xb493f27c */
C5 = 2.0875723372e-09, /* 0x310f74f6 */
C6 = -1.1359647598e-11; /* 0xad47d74e */
 
#ifdef __STDC__
float __kernel_cosf(float x, float y)
#else
float __kernel_cosf(x, y)
float x,y;
#endif
{
float a,hz,z,r,qx;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x32000000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3e99999a) /* if |x| < 0.3 */
return one - ((float)0.5*z - (z*r - x*y));
else {
if(ix > 0x3f480000) { /* x > 0.78125 */
qx = (float)0.28125;
} else {
SET_FLOAT_WORD(qx,ix-0x01000000); /* x/4 */
}
hz = (float)0.5*z-qx;
a = one-qx;
return a - (hz - (z*r-x*y));
}
}
/programs/develop/libraries/menuetlibc/src/libm/kf_rem_p.c
0,0 → 1,214
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* k_rem_pio2f.c -- float version of k_rem_pio2.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_rem_pio2f.c,v 1.2 1994/08/18 23:06:12 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
/* In the float version, the input parameter x contains 8 bit
integers, not 24 bit integers. 113 bit precision is not supported. */
 
#ifdef __STDC__
static const int init_jk[] = {4,7,9}; /* initial value for jk */
#else
static int init_jk[] = {4,7,9};
#endif
 
#ifdef __STDC__
static const float PIo2[] = {
#else
static float PIo2[] = {
#endif
1.5703125000e+00, /* 0x3fc90000 */
4.5776367188e-04, /* 0x39f00000 */
2.5987625122e-05, /* 0x37da0000 */
7.5437128544e-08, /* 0x33a20000 */
6.0026650317e-11, /* 0x2e840000 */
7.3896444519e-13, /* 0x2b500000 */
5.3845816694e-15, /* 0x27c20000 */
5.6378512969e-18, /* 0x22d00000 */
8.3009228831e-20, /* 0x1fc40000 */
3.2756352257e-22, /* 0x1bc60000 */
6.3331015649e-25, /* 0x17440000 */
};
 
#ifdef __STDC__
static const float
#else
static float
#endif
zero = 0.0,
one = 1.0,
two8 = 2.5600000000e+02, /* 0x43800000 */
twon8 = 3.9062500000e-03; /* 0x3b800000 */
 
#ifdef __STDC__
int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const int32_t *ipio2)
#else
int __kernel_rem_pio2f(x,y,e0,nx,prec,ipio2)
float x[], y[]; int e0,nx,prec; int32_t ipio2[];
#endif
{
int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
float z,fw,f[20],fq[20],q[20];
 
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
 
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1;
jv = (e0-3)/8; if(jv<0) jv=0;
q0 = e0-8*(jv+1);
 
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j];
 
/* compute q[0],q[1],...q[jk] */
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
 
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (float)((int32_t)(twon8* z));
iq[i] = (int32_t)(z-two8*fw);
z = q[j-1]+fw;
}
 
/* compute n */
z = scalbnf(z,q0); /* actual value of z */
z -= (float)8.0*floorf(z*(float)0.125); /* trim off integer >= 8 */
n = (int32_t) z;
z -= (float)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(8-q0)); n += i;
iq[jz-1] -= i<<(8-q0);
ih = iq[jz-1]>>(7-q0);
}
else if(q0==0) ih = iq[jz-1]>>8;
else if(z>=(float)0.5) ih=2;
 
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x100- j;
}
} else iq[i] = 0xff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7f; break;
case 2:
iq[jz-1] &= 0x3f; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbnf(one,q0);
}
}
 
/* check if recomputation is needed */
if(z==zero) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
 
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (float) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
 
/* chop off zero terms */
if(z==(float)0.0) {
jz -= 1; q0 -= 8;
while(iq[jz]==0) { jz--; q0-=8;}
} else { /* break z into 8-bit if necessary */
z = scalbnf(z,-q0);
if(z>=two8) {
fw = (float)((int32_t)(twon8*z));
iq[jz] = (int32_t)(z-two8*fw);
jz += 1; q0 += 8;
iq[jz] = (int32_t) fw;
} else iq[jz] = (int32_t) z ;
}
 
/* convert integer "bit" chunk to floating-point value */
fw = scalbnf(one,q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(float)iq[i]; fw*=twon8;
}
 
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
 
/* compress fq[] into y[] */
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}
/programs/develop/libraries/menuetlibc/src/libm/kf_sin.c
0,0 → 1,55
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* k_sinf.c -- float version of k_sin.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_sinf.c,v 1.2 1994/08/18 23:06:15 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
half = 5.0000000000e-01,/* 0x3f000000 */
S1 = -1.6666667163e-01, /* 0xbe2aaaab */
S2 = 8.3333337680e-03, /* 0x3c088889 */
S3 = -1.9841270114e-04, /* 0xb9500d01 */
S4 = 2.7557314297e-06, /* 0x3638ef1b */
S5 = -2.5050759689e-08, /* 0xb2d72f34 */
S6 = 1.5896910177e-10; /* 0x2f2ec9d3 */
 
#ifdef __STDC__
float __kernel_sinf(float x, float y, int iy)
#else
float __kernel_sinf(x, y, iy)
float x,y; int iy; /* iy=0 if y is zero */
#endif
{
float z,r,v;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff; /* high word of x */
if(ix<0x32000000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}
/programs/develop/libraries/menuetlibc/src/libm/kf_tan.c
0,0 → 1,102
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* k_tanf.c -- float version of k_tan.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: k_tanf.c,v 1.2 1994/08/18 23:06:18 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3f800000 */
pio4 = 7.8539812565e-01, /* 0x3f490fda */
pio4lo= 3.7748947079e-08, /* 0x33222168 */
T[] = {
3.3333334327e-01, /* 0x3eaaaaab */
1.3333334029e-01, /* 0x3e088889 */
5.3968254477e-02, /* 0x3d5d0dd1 */
2.1869488060e-02, /* 0x3cb327a4 */
8.8632395491e-03, /* 0x3c11371f */
3.5920790397e-03, /* 0x3b6b6916 */
1.4562094584e-03, /* 0x3abede48 */
5.8804126456e-04, /* 0x3a1a26c8 */
2.4646313977e-04, /* 0x398137b9 */
7.8179444245e-05, /* 0x38a3f445 */
7.1407252108e-05, /* 0x3895c07a */
-1.8558637748e-05, /* 0xb79bae5f */
2.5907305826e-05, /* 0x37d95384 */
};
 
#ifdef __STDC__
float __kernel_tanf(float x, float y, int iy)
#else
float __kernel_tanf(x, y, iy)
float x,y; int iy;
#endif
{
float z,r,v,w,s;
int32_t ix,hx;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x31800000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
if((ix|(iy+1))==0) return one/fabsf(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3f2ca140) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3f2ca140) {
v = (float)iy;
return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
float a,t;
int32_t i;
z = w;
GET_FLOAT_WORD(i,z);
SET_FLOAT_WORD(z,i&0xfffff000);
v = r-(z - x); /* z+v = r+x */
t = a = -(float)1.0/w; /* a = -1.0/w */
GET_FLOAT_WORD(i,t);
SET_FLOAT_WORD(t,i&0xfffff000);
s = (float)1.0+t*z;
return t+a*(s+t*v);
}
}
/programs/develop/libraries/menuetlibc/src/libm/math-pri.h
0,0 → 1,228
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $Id: math_private.h,v 1.2 1994/08/18 23:06:19 jtc Exp $
*/
 
#ifndef _MATH_PRIVATE_H_
#define _MATH_PRIVATE_H_
 
#include <machine/endian.h>
 
#if !defined(__NetBSD__) && !defined(__FreeBSD__)
typedef int int32_t;
typedef unsigned int u_int32_t;
#endif
 
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
ix1 = *((1-n0)+(int*)&x); * low word of x *
to dig two 32 bit words out of the 64 bit IEEE floating point
value. That is non-ANSI, and, moreover, the gcc instruction
scheduler gets it wrong. We instead use the following macros.
Unlike the original code, we determine the endianness at compile
time, not at run time; I don't see much benefit to selecting
endianness at run time. */
 
/* A union which permits us to convert between a double and two 32 bit
ints. */
 
#if BYTE_ORDER == BIG_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
 
#endif
 
#if BYTE_ORDER == LITTLE_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
 
#endif
 
/* Get two 32 bit ints from a double. */
 
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
 
/* Get the more significant 32 bit int from a double. */
 
#define GET_HIGH_WORD(i,d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
 
/* Get the less significant 32 bit int from a double. */
 
#define GET_LOW_WORD(i,d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
 
/* Set a double from two 32 bit ints. */
 
#define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
 
/* Set the more significant 32 bits of a double from an int. */
 
#define SET_HIGH_WORD(d,v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
 
/* Set the less significant 32 bits of a double from an int. */
 
#define SET_LOW_WORD(d,v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)
 
/* A union which permits us to convert between a float and a 32 bit
int. */
 
typedef union
{
float value;
/* FIXME: Assumes 32 bit int. */
unsigned int word;
} ieee_float_shape_type;
 
/* Get a 32 bit int from a float. */
 
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
 
/* Set a float from a 32 bit int. */
 
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
 
/* ieee style elementary functions */
extern double __ieee754_sqrt __P((double));
extern double __ieee754_acos __P((double));
extern double __ieee754_acosh __P((double));
extern double __ieee754_log __P((double));
extern double __ieee754_atanh __P((double));
extern double __ieee754_asin __P((double));
extern double __ieee754_atan2 __P((double,double));
extern double __ieee754_exp __P((double));
extern double __ieee754_cosh __P((double));
extern double __ieee754_fmod __P((double,double));
extern double __ieee754_pow __P((double,double));
extern double __ieee754_lgamma_r __P((double,int *));
extern double __ieee754_gamma_r __P((double,int *));
extern double __ieee754_lgamma __P((double));
extern double __ieee754_gamma __P((double));
extern double __ieee754_log10 __P((double));
extern double __ieee754_sinh __P((double));
extern double __ieee754_hypot __P((double,double));
extern double __ieee754_j0 __P((double));
extern double __ieee754_j1 __P((double));
extern double __ieee754_y0 __P((double));
extern double __ieee754_y1 __P((double));
extern double __ieee754_jn __P((int,double));
extern double __ieee754_yn __P((int,double));
extern double __ieee754_remainder __P((double,double));
extern int __ieee754_rem_pio2 __P((double,double*));
extern double __ieee754_scalb __P((double,double));
 
/* fdlibm kernel function */
extern double __kernel_standard __P((double,double,int));
extern double __kernel_sin __P((double,double,int));
extern double __kernel_cos __P((double,double));
extern double __kernel_tan __P((double,double,int));
extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
 
 
/* ieee style elementary float functions */
extern float __ieee754_sqrtf __P((float));
extern float __ieee754_acosf __P((float));
extern float __ieee754_acoshf __P((float));
extern float __ieee754_logf __P((float));
extern float __ieee754_atanhf __P((float));
extern float __ieee754_asinf __P((float));
extern float __ieee754_atan2f __P((float,float));
extern float __ieee754_expf __P((float));
extern float __ieee754_coshf __P((float));
extern float __ieee754_fmodf __P((float,float));
extern float __ieee754_powf __P((float,float));
extern float __ieee754_lgammaf_r __P((float,int *));
extern float __ieee754_gammaf_r __P((float,int *));
extern float __ieee754_lgammaf __P((float));
extern float __ieee754_gammaf __P((float));
extern float __ieee754_log10f __P((float));
extern float __ieee754_sinhf __P((float));
extern float __ieee754_hypotf __P((float,float));
extern float __ieee754_j0f __P((float));
extern float __ieee754_j1f __P((float));
extern float __ieee754_y0f __P((float));
extern float __ieee754_y1f __P((float));
extern float __ieee754_jnf __P((int,float));
extern float __ieee754_ynf __P((int,float));
extern float __ieee754_remainderf __P((float,float));
extern int __ieee754_rem_pio2f __P((float,float*));
extern float __ieee754_scalbf __P((float,float));
 
/* float versions of fdlibm kernel functions */
extern float __kernel_sinf __P((float,float,int));
extern float __kernel_cosf __P((float,float));
extern float __kernel_tanf __P((float,float,int));
extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
 
#endif /* _MATH_PRIVATE_H_ */
/programs/develop/libraries/menuetlibc/src/libm/math_pri.h
0,0 → 1,228
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $Id: math_private.h,v 1.2 1994/08/18 23:06:19 jtc Exp $
*/
 
#ifndef _MATH_PRIVATE_H_
#define _MATH_PRIVATE_H_
 
#include <machine/endian.h>
 
#if !defined(__NetBSD__) && !defined(__FreeBSD__)
typedef int int32_t;
typedef unsigned int u_int32_t;
#endif
 
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
ix1 = *((1-n0)+(int*)&x); * low word of x *
to dig two 32 bit words out of the 64 bit IEEE floating point
value. That is non-ANSI, and, moreover, the gcc instruction
scheduler gets it wrong. We instead use the following macros.
Unlike the original code, we determine the endianness at compile
time, not at run time; I don't see much benefit to selecting
endianness at run time. */
 
/* A union which permits us to convert between a double and two 32 bit
ints. */
 
#if BYTE_ORDER == BIG_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
 
#endif
 
#if BYTE_ORDER == LITTLE_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
 
#endif
 
/* Get two 32 bit ints from a double. */
 
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
 
/* Get the more significant 32 bit int from a double. */
 
#define GET_HIGH_WORD(i,d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
 
/* Get the less significant 32 bit int from a double. */
 
#define GET_LOW_WORD(i,d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
 
/* Set a double from two 32 bit ints. */
 
#define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
 
/* Set the more significant 32 bits of a double from an int. */
 
#define SET_HIGH_WORD(d,v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
 
/* Set the less significant 32 bits of a double from an int. */
 
#define SET_LOW_WORD(d,v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)
 
/* A union which permits us to convert between a float and a 32 bit
int. */
 
typedef union
{
float value;
/* FIXME: Assumes 32 bit int. */
unsigned int word;
} ieee_float_shape_type;
 
/* Get a 32 bit int from a float. */
 
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
 
/* Set a float from a 32 bit int. */
 
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
 
/* ieee style elementary functions */
extern double __ieee754_sqrt __P((double));
extern double __ieee754_acos __P((double));
extern double __ieee754_acosh __P((double));
extern double __ieee754_log __P((double));
extern double __ieee754_atanh __P((double));
extern double __ieee754_asin __P((double));
extern double __ieee754_atan2 __P((double,double));
extern double __ieee754_exp __P((double));
extern double __ieee754_cosh __P((double));
extern double __ieee754_fmod __P((double,double));
extern double __ieee754_pow __P((double,double));
extern double __ieee754_lgamma_r __P((double,int *));
extern double __ieee754_gamma_r __P((double,int *));
extern double __ieee754_lgamma __P((double));
extern double __ieee754_gamma __P((double));
extern double __ieee754_log10 __P((double));
extern double __ieee754_sinh __P((double));
extern double __ieee754_hypot __P((double,double));
extern double __ieee754_j0 __P((double));
extern double __ieee754_j1 __P((double));
extern double __ieee754_y0 __P((double));
extern double __ieee754_y1 __P((double));
extern double __ieee754_jn __P((int,double));
extern double __ieee754_yn __P((int,double));
extern double __ieee754_remainder __P((double,double));
extern int __ieee754_rem_pio2 __P((double,double*));
extern double __ieee754_scalb __P((double,double));
 
/* fdlibm kernel function */
extern double __kernel_standard __P((double,double,int));
extern double __kernel_sin __P((double,double,int));
extern double __kernel_cos __P((double,double));
extern double __kernel_tan __P((double,double,int));
extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
 
 
/* ieee style elementary float functions */
extern float __ieee754_sqrtf __P((float));
extern float __ieee754_acosf __P((float));
extern float __ieee754_acoshf __P((float));
extern float __ieee754_logf __P((float));
extern float __ieee754_atanhf __P((float));
extern float __ieee754_asinf __P((float));
extern float __ieee754_atan2f __P((float,float));
extern float __ieee754_expf __P((float));
extern float __ieee754_coshf __P((float));
extern float __ieee754_fmodf __P((float,float));
extern float __ieee754_powf __P((float,float));
extern float __ieee754_lgammaf_r __P((float,int *));
extern float __ieee754_gammaf_r __P((float,int *));
extern float __ieee754_lgammaf __P((float));
extern float __ieee754_gammaf __P((float));
extern float __ieee754_log10f __P((float));
extern float __ieee754_sinhf __P((float));
extern float __ieee754_hypotf __P((float,float));
extern float __ieee754_j0f __P((float));
extern float __ieee754_j1f __P((float));
extern float __ieee754_y0f __P((float));
extern float __ieee754_y1f __P((float));
extern float __ieee754_jnf __P((int,float));
extern float __ieee754_ynf __P((int,float));
extern float __ieee754_remainderf __P((float,float));
extern int __ieee754_rem_pio2f __P((float,float*));
extern float __ieee754_scalbf __P((float,float));
 
/* float versions of fdlibm kernel functions */
extern float __kernel_sinf __P((float,float,int));
extern float __kernel_cosf __P((float,float));
extern float __kernel_tanf __P((float,float,int));
extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
 
#endif /* _MATH_PRIVATE_H_ */
/programs/develop/libraries/menuetlibc/src/libm/math_private.h
0,0 → 1,228
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $Id: math_private.h,v 1.2 1994/08/18 23:06:19 jtc Exp $
*/
 
#ifndef _MATH_PRIVATE_H_
#define _MATH_PRIVATE_H_
 
#include <machine/endian.h>
 
#if !defined(__NetBSD__) && !defined(__FreeBSD__)
typedef int int32_t;
typedef unsigned int u_int32_t;
#endif
 
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
ix1 = *((1-n0)+(int*)&x); * low word of x *
to dig two 32 bit words out of the 64 bit IEEE floating point
value. That is non-ANSI, and, moreover, the gcc instruction
scheduler gets it wrong. We instead use the following macros.
Unlike the original code, we determine the endianness at compile
time, not at run time; I don't see much benefit to selecting
endianness at run time. */
 
/* A union which permits us to convert between a double and two 32 bit
ints. */
 
#if BYTE_ORDER == BIG_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
 
#endif
 
#if BYTE_ORDER == LITTLE_ENDIAN
 
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
 
#endif
 
/* Get two 32 bit ints from a double. */
 
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
 
/* Get the more significant 32 bit int from a double. */
 
#define GET_HIGH_WORD(i,d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
 
/* Get the less significant 32 bit int from a double. */
 
#define GET_LOW_WORD(i,d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
 
/* Set a double from two 32 bit ints. */
 
#define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
 
/* Set the more significant 32 bits of a double from an int. */
 
#define SET_HIGH_WORD(d,v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
 
/* Set the less significant 32 bits of a double from an int. */
 
#define SET_LOW_WORD(d,v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)
 
/* A union which permits us to convert between a float and a 32 bit
int. */
 
typedef union
{
float value;
/* FIXME: Assumes 32 bit int. */
unsigned int word;
} ieee_float_shape_type;
 
/* Get a 32 bit int from a float. */
 
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
 
/* Set a float from a 32 bit int. */
 
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
 
/* ieee style elementary functions */
extern double __ieee754_sqrt __P((double));
extern double __ieee754_acos __P((double));
extern double __ieee754_acosh __P((double));
extern double __ieee754_log __P((double));
extern double __ieee754_atanh __P((double));
extern double __ieee754_asin __P((double));
extern double __ieee754_atan2 __P((double,double));
extern double __ieee754_exp __P((double));
extern double __ieee754_cosh __P((double));
extern double __ieee754_fmod __P((double,double));
extern double __ieee754_pow __P((double,double));
extern double __ieee754_lgamma_r __P((double,int *));
extern double __ieee754_gamma_r __P((double,int *));
extern double __ieee754_lgamma __P((double));
extern double __ieee754_gamma __P((double));
extern double __ieee754_log10 __P((double));
extern double __ieee754_sinh __P((double));
extern double __ieee754_hypot __P((double,double));
extern double __ieee754_j0 __P((double));
extern double __ieee754_j1 __P((double));
extern double __ieee754_y0 __P((double));
extern double __ieee754_y1 __P((double));
extern double __ieee754_jn __P((int,double));
extern double __ieee754_yn __P((int,double));
extern double __ieee754_remainder __P((double,double));
extern int __ieee754_rem_pio2 __P((double,double*));
extern double __ieee754_scalb __P((double,double));
 
/* fdlibm kernel function */
extern double __kernel_standard __P((double,double,int));
extern double __kernel_sin __P((double,double,int));
extern double __kernel_cos __P((double,double));
extern double __kernel_tan __P((double,double,int));
extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
 
 
/* ieee style elementary float functions */
extern float __ieee754_sqrtf __P((float));
extern float __ieee754_acosf __P((float));
extern float __ieee754_acoshf __P((float));
extern float __ieee754_logf __P((float));
extern float __ieee754_atanhf __P((float));
extern float __ieee754_asinf __P((float));
extern float __ieee754_atan2f __P((float,float));
extern float __ieee754_expf __P((float));
extern float __ieee754_coshf __P((float));
extern float __ieee754_fmodf __P((float,float));
extern float __ieee754_powf __P((float,float));
extern float __ieee754_lgammaf_r __P((float,int *));
extern float __ieee754_gammaf_r __P((float,int *));
extern float __ieee754_lgammaf __P((float));
extern float __ieee754_gammaf __P((float));
extern float __ieee754_log10f __P((float));
extern float __ieee754_sinhf __P((float));
extern float __ieee754_hypotf __P((float,float));
extern float __ieee754_j0f __P((float));
extern float __ieee754_j1f __P((float));
extern float __ieee754_y0f __P((float));
extern float __ieee754_y1f __P((float));
extern float __ieee754_jnf __P((int,float));
extern float __ieee754_ynf __P((int,float));
extern float __ieee754_remainderf __P((float,float));
extern int __ieee754_rem_pio2f __P((float,float*));
extern float __ieee754_scalbf __P((float,float));
 
/* float versions of fdlibm kernel functions */
extern float __kernel_sinf __P((float,float,int));
extern float __kernel_cosf __P((float,float));
extern float __kernel_tanf __P((float,float,int));
extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
 
#endif /* _MATH_PRIVATE_H_ */
/programs/develop/libraries/menuetlibc/src/libm/s_asinh.c
0,0 → 1,66
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_asinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_asinh.c,v 1.6 1994/08/18 23:06:20 jtc Exp $";
#endif
 
/* asinh(x)
* Method :
* Based on
* asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
* we have
* asinh(x) := x if 1+x*x=1,
* := sign(x)*(log(x)+ln2)) for large |x|, else
* := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
* := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
huge= 1.00000000000000000000e+300;
 
#ifdef __STDC__
double asinh(double x)
#else
double asinh(x)
double x;
#endif
{
double t,w;
int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
if(ix< 0x3e300000) { /* |x|<2**-28 */
if(huge+x>one) return x; /* return x inexact except 0 */
}
if(ix>0x41b00000) { /* |x| > 2**28 */
w = __ieee754_log(fabs(x))+ln2;
} else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
t = fabs(x);
w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t));
} else { /* 2.0 > |x| > 2**-28 */
t = x*x;
w =log1p(fabs(x)+t/(one+sqrt(one+t)));
}
if(hx>0) return w; else return -w;
}
/programs/develop/libraries/menuetlibc/src/libm/s_atan.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(atan)
fldl 4(%esp)
fld1
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/s_cbrt.c
0,0 → 1,94
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_cbrt.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_cbrt.c,v 1.6 1994/08/18 23:06:25 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
/* cbrt(x)
* Return cube root of x
*/
#ifdef __STDC__
static const u_int32_t
#else
static u_int32_t
#endif
B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
 
#ifdef __STDC__
static const double
#else
static double
#endif
C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */
D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */
F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */
G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
 
#ifdef __STDC__
double cbrt(double x)
#else
double cbrt(x)
double x;
#endif
{
int32_t hx;
double r,s,t=0.0,w;
u_int32_t sign;
u_int32_t high,low;
 
GET_HIGH_WORD(hx,x);
sign=hx&0x80000000; /* sign= sign(x) */
hx ^=sign;
if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
GET_LOW_WORD(low,x);
if((hx|low)==0)
return(x); /* cbrt(0) is itself */
 
SET_HIGH_WORD(x,hx); /* x <- |x| */
/* rough cbrt to 5 bits */
if(hx<0x00100000) /* subnormal number */
{SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */
t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2);
}
else
SET_HIGH_WORD(t,hx/3+B1);
 
 
/* new cbrt to 23 bits, may be implemented in single precision */
r=t*t/x;
s=C+r*t;
t*=G+F/(s+E+D/s);
 
/* chopped to 20 bits and make it larger than cbrt(x) */
GET_HIGH_WORD(high,t);
INSERT_WORDS(t,high+0x00000001,0);
 
 
/* one step newton iteration to 53 bits with error less than 0.667 ulps */
s=t*t; /* t*t is exact */
r=x/s;
w=t+t;
r=(r-t)/(w+r); /* r-s is exact */
t=t+t*r;
 
/* retore the sign bit */
GET_HIGH_WORD(high,t);
SET_HIGH_WORD(t,high|sign);
return(t);
}
/programs/develop/libraries/menuetlibc/src/libm/s_ceil.s
0,0 → 1,21
#include<libc/asm.h>
MK_C_SYM(ceil)
 
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -12(%ebp)
movw -12(%ebp),%dx
orw $0x0800,%dx
andw $0xfbff,%dx
movw %dx,-16(%ebp)
fldcw -16(%ebp)
 
fldl 8(%ebp);
frndint
 
fldcw -12(%ebp)
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/s_copysi.s
0,0 → 1,10
#include<libc/asm.h>
MK_C_SYM(copysign)
movl 16(%esp),%edx
andl $0x80000000,%edx
movl 8(%esp),%eax
andl $0x7fffffff,%eax
orl %edx,%eax
movl %eax,8(%esp)
fldl 4(%esp)
ret
/programs/develop/libraries/menuetlibc/src/libm/s_cos.s
0,0 → 1,18
#include<libc/asm.h>
MK_C_SYM(cos)
fldl 4(%esp)
fcos
fnstsw %ax
andw $0x400,%ax
jnz 1f
ret
1: fldpi
fadd %st(0)
fxch %st(1)
2: fprem1
fnstsw %ax
andw $0x400,%ax
jnz 2b
fstp %st(1)
fcos
ret
/programs/develop/libraries/menuetlibc/src/libm/s_erf.c
0,0 → 1,315
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_erf.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_erf.c,v 1.6 1994/08/18 23:06:36 jtc Exp $";
#endif
 
/* double erf(double x)
* double erfc(double x)
* x
* 2 |\
* erf(x) = --------- | exp(-t*t)dt
* sqrt(pi) \|
* 0
*
* erfc(x) = 1-erf(x)
* Note that
* erf(-x) = -erf(x)
* erfc(-x) = 2 - erfc(x)
*
* Method:
* 1. For |x| in [0, 0.84375]
* erf(x) = x + x*R(x^2)
* erfc(x) = 1 - erf(x) if x in [-.84375,0.25]
* = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375]
* where R = P/Q where P is an odd poly of degree 8 and
* Q is an odd poly of degree 10.
* -57.90
* | R - (erf(x)-x)/x | <= 2
*
*
* Remark. The formula is derived by noting
* erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
* and that
* 2/sqrt(pi) = 1.128379167095512573896158903121545171688
* is close to one. The interval is chosen because the fix
* point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
* near 0.6174), and by some experiment, 0.84375 is chosen to
* guarantee the error is less than one ulp for erf.
*
* 2. For |x| in [0.84375,1.25], let s = |x| - 1, and
* c = 0.84506291151 rounded to single (24 bits)
* erf(x) = sign(x) * (c + P1(s)/Q1(s))
* erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0
* 1+(c+P1(s)/Q1(s)) if x < 0
* |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06
* Remark: here we use the taylor series expansion at x=1.
* erf(1+s) = erf(1) + s*Poly(s)
* = 0.845.. + P1(s)/Q1(s)
* That is, we use rational approximation to approximate
* erf(1+s) - (c = (single)0.84506291151)
* Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
* where
* P1(s) = degree 6 poly in s
* Q1(s) = degree 6 poly in s
*
* 3. For x in [1.25,1/0.35(~2.857143)],
* erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1)
* erf(x) = 1 - erfc(x)
* where
* R1(z) = degree 7 poly in z, (z=1/x^2)
* S1(z) = degree 8 poly in z
*
* 4. For x in [1/0.35,28]
* erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
* = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0
* = 2.0 - tiny (if x <= -6)
* erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6, else
* erf(x) = sign(x)*(1.0 - tiny)
* where
* R2(z) = degree 6 poly in z, (z=1/x^2)
* S2(z) = degree 7 poly in z
*
* Note1:
* To compute exp(-x*x-0.5625+R/S), let s be a single
* precision number and s := x; then
* -x*x = -s*s + (s-x)*(s+x)
* exp(-x*x-0.5626+R/S) =
* exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
* Note2:
* Here 4 and 5 make use of the asymptotic series
* exp(-x*x)
* erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
* x*sqrt(pi)
* We use rational approximation to approximate
* g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625
* Here is the error bound for R1/S1 and R2/S2
* |R1/S1 - f(x)| < 2**(-62.57)
* |R2/S2 - f(x)| < 2**(-61.52)
*
* 5. For inf > x >= 28
* erf(x) = sign(x) *(1 - tiny) (raise inexact)
* erfc(x) = tiny*tiny (raise underflow) if x > 0
* = 2 - tiny if x<0
*
* 7. Special case:
* erf(0) = 0, erf(inf) = 1, erf(-inf) = -1,
* erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2,
* erfc/erf(NaN) is NaN
*/
 
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
tiny = 1e-300,
half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
/* c = (float)0.84506291151 */
erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
/*
* Coefficients for approximation to erf on [0,0.84375]
*/
efx = 1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
efx8= 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */
pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */
qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */
qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */
qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */
qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
/*
* Coefficients for approximation to erf in [0.84375,1.25]
*/
pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */
pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */
pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */
pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */
pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */
qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */
qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */
qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */
qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */
qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
/*
* Coefficients for approximation to erfc in [1.25,1/0.35]
*/
ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */
ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */
ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */
ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */
ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */
ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */
sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */
sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */
sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */
sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */
sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */
sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */
sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
/*
* Coefficients for approximation to erfc in [1/.35,28]
*/
rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */
rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */
rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */
rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */
rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */
sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */
sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */
sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */
sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */
sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */
sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */
sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
 
#ifdef __STDC__
double erf(double x)
#else
double erf(x)
double x;
#endif
{
int32_t hx,ix,i;
double R,S,P,Q,s,y,z,r;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) { /* erf(nan)=nan */
i = ((u_int32_t)hx>>31)<<1;
return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */
}
 
if(ix < 0x3feb0000) { /* |x|<0.84375 */
if(ix < 0x3e300000) { /* |x|<2**-28 */
if (ix < 0x00800000)
return 0.125*(8.0*x+efx8*x); /*avoid underflow */
return x + efx*x;
}
z = x*x;
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
y = r/s;
return x + x*y;
}
if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
s = fabs(x)-one;
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
if(hx>=0) return erx + P/Q; else return -erx - P/Q;
}
if (ix >= 0x40180000) { /* inf>|x|>=6 */
if(hx>=0) return one-tiny; else return tiny-one;
}
x = fabs(x);
s = one/(x*x);
if(ix< 0x4006DB6E) { /* |x| < 1/0.35 */
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
ra5+s*(ra6+s*ra7))))));
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
sa5+s*(sa6+s*(sa7+s*sa8)))))));
} else { /* |x| >= 1/0.35 */
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
rb5+s*rb6)))));
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
z = x;
SET_LOW_WORD(z,0);
r = __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S);
if(hx>=0) return one-r/x; else return r/x-one;
}
 
#ifdef __STDC__
double erfc(double x)
#else
double erfc(x)
double x;
#endif
{
int32_t hx,ix;
double R,S,P,Q,s,y,z,r;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) { /* erfc(nan)=nan */
/* erfc(+-inf)=0,2 */
return (double)(((u_int32_t)hx>>31)<<1)+one/x;
}
 
if(ix < 0x3feb0000) { /* |x|<0.84375 */
if(ix < 0x3c700000) /* |x|<2**-56 */
return one-x;
z = x*x;
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
y = r/s;
if(hx < 0x3fd00000) { /* x<1/4 */
return one-(x+x*y);
} else {
r = x*y;
r += (x-half);
return half - r ;
}
}
if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
s = fabs(x)-one;
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
if(hx>=0) {
z = one-erx; return z - P/Q;
} else {
z = erx+P/Q; return one+z;
}
}
if (ix < 0x403c0000) { /* |x|<28 */
x = fabs(x);
s = one/(x*x);
if(ix< 0x4006DB6D) { /* |x| < 1/.35 ~ 2.857143*/
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
ra5+s*(ra6+s*ra7))))));
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
sa5+s*(sa6+s*(sa7+s*sa8)))))));
} else { /* |x| >= 1/.35 ~ 2.857143 */
if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
rb5+s*rb6)))));
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
z = x;
SET_LOW_WORD(z,0);
r = __ieee754_exp(-z*z-0.5625)*
__ieee754_exp((z-x)*(z+x)+R/S);
if(hx>0) return r/x; else return two-r/x;
} else {
if(hx>0) return tiny*tiny; else return two-tiny;
}
}
/programs/develop/libraries/menuetlibc/src/libm/s_expm1.s
0,0 → 1,17
#include<libc/asm.h>
 
MK_C_SYM(expm1)
fldl 4(%esp)
fldl2e
fmulp
fstl %st(1)
frndint
fstl %st(2)
fsubrp
f2xm1
fld1
faddp
fscale
fld1
fsubrp
ret
/programs/develop/libraries/menuetlibc/src/libm/s_fabs.c
0,0 → 1,36
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_fabs.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_fabs.c,v 1.5 1994/08/18 23:06:42 jtc Exp $";
#endif
 
/*
* fabs(x) returns the absolute value of x.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double fabs(double x)
#else
double fabs(x)
double x;
#endif
{
u_int32_t high;
GET_HIGH_WORD(high,x);
SET_HIGH_WORD(x,high&0x7fffffff);
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/s_finite.s
0,0 → 1,8
#include<libc/asm.h>
MK_C_SYM(finite)
movl 8(%esp),%eax
andl $0x7ff00000, %eax
cmpl $0x7ff00000, %eax
setne %al
andl $0x000000ff, %eax
ret
/programs/develop/libraries/menuetlibc/src/libm/s_floor.s
0,0 → 1,20
#include<libc/asm.h>
MK_C_SYM(floor)
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -12(%ebp)
movw -12(%ebp),%dx
orw $0x0400,%dx
andw $0xf7ff,%dx
movw %dx,-16(%ebp)
fldcw -16(%ebp)
 
fldl 8(%ebp);
frndint
 
fldcw -12(%ebp)
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/s_frexp.c
0,0 → 1,61
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_frexp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_frexp.c,v 1.6 1994/08/18 23:06:49 jtc Exp $";
#endif
 
/*
* for non-zero x
* x = frexp(arg,&exp);
* return a double fp quantity x such that 0.5 <= |x| <1.0
* and the corresponding binary exponent "exp". That is
* arg = x*2^exp.
* If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
* with *exp=0.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
 
#ifdef __STDC__
double frexp(double x, int *eptr)
#else
double frexp(x, eptr)
double x; int *eptr;
#endif
{
int32_t hx, ix, lx;
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
*eptr = 0;
if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
if (ix<0x00100000) { /* subnormal */
x *= two54;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
*eptr = -54;
}
*eptr += (ix>>20)-1022;
hx = (hx&0x800fffff)|0x3fe00000;
SET_HIGH_WORD(x,hx);
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/s_ilogb.s
0,0 → 1,15
#include<libc/asm.h>
MK_C_SYM(ilogb)
pushl %esp
movl %esp,%ebp
subl $4,%esp
 
fldl 8(%ebp)
fxtract
fstpl %st
 
fistpl -4(%ebp)
movl -4(%ebp),%eax
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/s_infini.c
0,0 → 1,38
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* Copyright (c) 1994 Winning Strategies, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Winning Strategies, Inc.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <machine/endian.h>
 
#if BYTE_ORDER == LITTLE_ENDIAN
char __infinity[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f };
#else
char __infinity[] = { 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#endif
/programs/develop/libraries/menuetlibc/src/libm/s_isinf.c
0,0 → 1,57
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* Copyright (c) 1994 Winning Strategies, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Winning Strategies, Inc.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_isinf.c,v 1.6 1994/08/18 23:06:54 jtc Exp $";
#endif
 
/*
* isinf(x) returns 1 is x is inf, else 0;
* no branching!
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
int isinf(double x)
#else
int isinf(x)
double x;
#endif
{
int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx ^= 0x7ff00000;
hx |= lx;
return (hx == 0);
}
/programs/develop/libraries/menuetlibc/src/libm/s_isnan.c
0,0 → 1,39
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_isnan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_isnan.c,v 1.6 1994/08/18 23:06:54 jtc Exp $";
#endif
 
/*
* isnan(x) returns 1 is x is nan, else 0;
* no branching!
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
int isnan(double x)
#else
int isnan(x)
double x;
#endif
{
int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (u_int32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return (int)((u_int32_t)(hx))>>31;
}
/programs/develop/libraries/menuetlibc/src/libm/s_ldexp.c
0,0 → 1,33
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_ldexp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_ldexp.c,v 1.4 1994/08/10 20:32:37 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
#include <errno.h>
 
#ifdef __STDC__
double ldexp(double value, int exp)
#else
double ldexp(value, exp)
double value; int exp;
#endif
{
if(!finite(value)||value==0.0) return value;
value = scalbn(value,exp);
if(!finite(value)||value==0.0) errno = ERANGE;
return value;
}
/programs/develop/libraries/menuetlibc/src/libm/s_libver.c
0,0 → 1,40
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_lib_ver.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_lib_version.c,v 1.4 1994/08/10 20:32:40 jtc Exp $";
#endif
 
/*
* MACRO for standards
*/
 
#include "math.h"
#include "math_private.h"
 
/*
* define and initialize _LIB_VERSION
*/
#ifdef _POSIX_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
#else
#ifdef _XOPEN_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_;
#else
#ifdef _SVID3_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _SVID_;
#else /* default _IEEE_MODE */
_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
#endif
#endif
#endif
/programs/develop/libraries/menuetlibc/src/libm/s_log1p.s
0,0 → 1,8
#include<libc/asm.h>
MK_C_SYM(log1p)
fldln2
fldl 4(%esp)
fld1
faddp
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/s_logb.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(logb)
fldl 4(%esp)
fxtract
fstpl %st
ret
/programs/develop/libraries/menuetlibc/src/libm/s_mather.c
0,0 → 1,31
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_matherr.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_matherr.c,v 1.4 1994/08/10 20:32:52 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
int matherr(struct exception *x)
#else
int matherr(x)
struct exception *x;
#endif
{
int n=0;
if(x->arg1!=x->arg1) return 0;
return n;
}
/programs/develop/libraries/menuetlibc/src/libm/s_modf.c
0,0 → 1,84
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_modf.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_modf.c,v 1.6 1994/08/18 23:07:09 jtc Exp $";
#endif
 
/*
* modf(double x, double *iptr)
* return fraction part of x, and return x's integral part in *iptr.
* Method:
* Bit twiddling.
*
* Exception:
* No exception.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double one = 1.0;
#else
static double one = 1.0;
#endif
 
#ifdef __STDC__
double modf(double x, double *iptr)
#else
double modf(x, iptr)
double x,*iptr;
#endif
{
int32_t i0,i1,j0;
u_int32_t i;
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
if(j0<20) { /* integer part in high x */
if(j0<0) { /* |x|<1 */
INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
return x;
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) { /* x is integral */
u_int32_t high;
*iptr = x;
GET_HIGH_WORD(high,x);
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
return x;
} else {
INSERT_WORDS(*iptr,i0&(~i),0);
return x - *iptr;
}
}
} else if (j0>51) { /* no fraction part */
u_int32_t high;
*iptr = x*one;
GET_HIGH_WORD(high,x);
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
return x;
} else { /* fraction part in low x */
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) { /* x is integral */
u_int32_t high;
*iptr = x;
GET_HIGH_WORD(high,x);
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
return x;
} else {
INSERT_WORDS(*iptr,i0,i1&(~i));
return x - *iptr;
}
}
}
/programs/develop/libraries/menuetlibc/src/libm/s_nextaf.c
0,0 → 1,80
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_nextafter.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_nextafter.c,v 1.6 1994/08/18 23:07:13 jtc Exp $";
#endif
 
/* IEEE functions
* nextafter(x,y)
* return the next machine floating-point number of x in the
* direction toward y.
* Special cases:
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double nextafter(double x, double y)
#else
double nextafter(x,y)
double x,y;
#endif
{
int32_t hx,hy,ix,iy;
u_int32_t lx,ly;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; /* |x| */
iy = hy&0x7fffffff; /* |y| */
 
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
return x+y;
if(x==y) return x; /* x=y, return x */
if((ix|lx)==0) { /* x == 0 */
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
y = x*x;
if(y==x) return y; else return x; /* raise underflow flag */
}
if(hx>=0) { /* x > 0 */
if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
if(lx==0) hx -= 1;
lx -= 1;
} else { /* x < y, x += ulp */
lx += 1;
if(lx==0) hx += 1;
}
} else { /* x < 0 */
if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
if(lx==0) hx -= 1;
lx -= 1;
} else { /* x > y, x += ulp */
lx += 1;
if(lx==0) hx += 1;
}
}
hy = hx&0x7ff00000;
if(hy>=0x7ff00000) return x+x; /* overflow */
if(hy<0x00100000) { /* underflow */
y = x*x;
if(y!=x) { /* raise underflow flag */
INSERT_WORDS(y,hx,lx);
return y;
}
}
INSERT_WORDS(x,hx,lx);
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/s_rint.s
0,0 → 1,5
#include<libc/asm.h>
MK_C_SYM(rint)
fldl 4(%esp)
frndint
ret
/programs/develop/libraries/menuetlibc/src/libm/s_scalbn.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(scalbn)
fildl 12(%esp)
fldl 4(%esp)
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/s_signga.c
0,0 → 1,4
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include "math.h"
#include "math_private.h"
int signgam = 0;
/programs/develop/libraries/menuetlibc/src/libm/s_signif.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(significand)
fldl 4(%esp)
fxtract
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/s_sin.s
0,0 → 1,18
#include<libc/asm.h>
MK_C_SYM(sin)
fldl 4(%esp)
fsin
fnstsw %ax
andw $0x400,%ax
jnz 1f
ret
1: fldpi
fadd %st(0)
fxch %st(1)
2: fprem1
fnstsw %ax
andw $0x400,%ax
jnz 2b
fstp %st(1)
fsin
ret
/programs/develop/libraries/menuetlibc/src/libm/s_tan.s
0,0 → 1,20
#include<libc/asm.h>
MK_C_SYM(tan)
fldl 4(%esp)
fptan
fnstsw %ax
andw $0x400,%ax
jnz 1f
fstp %st(0)
ret
1: fldpi
fadd %st(0)
fxch %st(1)
2: fprem1
fstsw %ax
andw $0x400,%ax
jnz 2b
fstp %st(1)
fptan
fstp %st(0)
ret
/programs/develop/libraries/menuetlibc/src/libm/s_tanh.c
0,0 → 1,87
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)s_tanh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_tanh.c,v 1.5 1994/08/18 23:10:22 jtc Exp $";
#endif
 
/* Tanh(x)
* Return the Hyperbolic Tangent of x
*
* Method :
* x -x
* e - e
* 0. tanh(x) is defined to be -----------
* x -x
* e + e
* 1. reduce x to non-negative by tanh(-x) = -tanh(x).
* 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x)
* -t
* 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x)
* t + 2
* 2
* 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x)
* t + 2
* 22.0 < x <= INF : tanh(x) := 1.
*
* Special cases:
* tanh(NaN) is NaN;
* only tanh(0)=0 is exact for finite argument.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double one=1.0, two=2.0, tiny = 1.0e-300;
#else
static double one=1.0, two=2.0, tiny = 1.0e-300;
#endif
 
#ifdef __STDC__
double tanh(double x)
#else
double tanh(x)
double x;
#endif
{
double t,z;
int32_t jx,ix;
 
/* High word of |x|. */
GET_HIGH_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7ff00000) {
if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
else return one/x-one; /* tanh(NaN) = NaN */
}
 
/* |x| < 22 */
if (ix < 0x40360000) { /* |x|<22 */
if (ix<0x3c800000) /* |x|<2**-55 */
return x*(one+x); /* tanh(small) = small */
if (ix>=0x3ff00000) { /* |x|>=1 */
t = expm1(two*fabs(x));
z = one - two/(t+two);
} else {
t = expm1(-two*fabs(x));
z= -t/(t+two);
}
/* |x| > 22, return +-1 */
} else {
z = one - tiny; /* raised inexact flag */
}
return (jx>=0)? z: -z;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_asinh.c
0,0 → 1,58
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_asinhf.c -- float version of s_asinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_asinhf.c,v 1.2 1994/08/18 23:06:21 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
ln2 = 6.9314718246e-01, /* 0x3f317218 */
huge= 1.0000000000e+30;
 
#ifdef __STDC__
float asinhf(float x)
#else
float asinhf(x)
float x;
#endif
{
float t,w;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return x+x; /* x is inf or NaN */
if(ix< 0x31800000) { /* |x|<2**-28 */
if(huge+x>one) return x; /* return x inexact except 0 */
}
if(ix>0x4d800000) { /* |x| > 2**28 */
w = __ieee754_logf(fabsf(x))+ln2;
} else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
t = fabsf(x);
w = __ieee754_logf((float)2.0*t+one/(sqrtf(x*x+one)+t));
} else { /* 2.0 > |x| > 2**-28 */
t = x*x;
w =log1pf(fabsf(x)+t/(one+sqrtf(one+t)));
}
if(hx>0) return w; else return -w;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_atan.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(atanf)
flds 4(%esp)
fld1
fpatan
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_cbrt.c
0,0 → 1,84
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_cbrtf.c -- float version of s_cbrt.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_cbrtf.c,v 1.2 1994/08/18 23:06:27 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
/* cbrtf(x)
* Return cube root of x
*/
#ifdef __STDC__
static const unsigned
#else
static unsigned
#endif
B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
 
#ifdef __STDC__
static const float
#else
static float
#endif
C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */
D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */
F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */
G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */
 
#ifdef __STDC__
float cbrtf(float x)
#else
float cbrtf(x)
float x;
#endif
{
float r,s,t;
int32_t hx;
u_int32_t sign;
u_int32_t high;
 
GET_FLOAT_WORD(hx,x);
sign=hx&0x80000000; /* sign= sign(x) */
hx ^=sign;
if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
if(hx==0)
return(x); /* cbrt(0) is itself */
 
SET_FLOAT_WORD(x,hx); /* x <- |x| */
/* rough cbrt to 5 bits */
if(hx<0x00800000) /* subnormal number */
{SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
}
else
SET_FLOAT_WORD(t,hx/3+B1);
 
 
/* new cbrt to 23 bits */
r=t*t/x;
s=C+r*t;
t*=G+F/(s+E+D/s);
 
/* retore the sign bit */
GET_FLOAT_WORD(high,t);
SET_FLOAT_WORD(t,high|sign);
return(t);
}
/programs/develop/libraries/menuetlibc/src/libm/sf_ceil.s
0,0 → 1,20
#include<libc/asm.h>
MK_C_SYM(ceilf)
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -12(%ebp)
movw -12(%ebp),%dx
orw $0x0800,%dx
andw $0xfbff,%dx
movw %dx,-16(%ebp)
fldcw -16(%ebp)
 
flds 8(%ebp);
frndint
 
fldcw -12(%ebp)
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_copys.s
0,0 → 1,10
#include<libc/asm.h>
MK_C_SYM(copysignf)
movl 8(%esp),%edx
andl $0x80000000,%edx
movl 4(%esp),%eax
andl $0x7fffffff,%eax
orl %edx,%eax
movl %eax,4(%esp)
flds 4(%esp)
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_cos.s
0,0 → 1,5
#include<libc/asm.h>
MK_C_SYM(cosf)
flds 4(%esp)
fcos
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_erf.c
0,0 → 1,224
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_erff.c -- float version of s_erf.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_erff.c,v 1.2 1994/08/18 23:06:38 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
tiny = 1e-30,
half= 5.0000000000e-01, /* 0x3F000000 */
one = 1.0000000000e+00, /* 0x3F800000 */
two = 2.0000000000e+00, /* 0x40000000 */
/* c = (subfloat)0.84506291151 */
erx = 8.4506291151e-01, /* 0x3f58560b */
/*
* Coefficients for approximation to erf on [0,0.84375]
*/
efx = 1.2837916613e-01, /* 0x3e0375d4 */
efx8= 1.0270333290e+00, /* 0x3f8375d4 */
pp0 = 1.2837916613e-01, /* 0x3e0375d4 */
pp1 = -3.2504209876e-01, /* 0xbea66beb */
pp2 = -2.8481749818e-02, /* 0xbce9528f */
pp3 = -5.7702702470e-03, /* 0xbbbd1489 */
pp4 = -2.3763017452e-05, /* 0xb7c756b1 */
qq1 = 3.9791721106e-01, /* 0x3ecbbbce */
qq2 = 6.5022252500e-02, /* 0x3d852a63 */
qq3 = 5.0813062117e-03, /* 0x3ba68116 */
qq4 = 1.3249473704e-04, /* 0x390aee49 */
qq5 = -3.9602282413e-06, /* 0xb684e21a */
/*
* Coefficients for approximation to erf in [0.84375,1.25]
*/
pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */
pa1 = 4.1485610604e-01, /* 0x3ed46805 */
pa2 = -3.7220788002e-01, /* 0xbebe9208 */
pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */
pa4 = -1.1089469492e-01, /* 0xbde31cc2 */
pa5 = 3.5478305072e-02, /* 0x3d1151b3 */
pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */
qa1 = 1.0642088205e-01, /* 0x3dd9f331 */
qa2 = 5.4039794207e-01, /* 0x3f0a5785 */
qa3 = 7.1828655899e-02, /* 0x3d931ae7 */
qa4 = 1.2617121637e-01, /* 0x3e013307 */
qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */
qa6 = 1.1984500103e-02, /* 0x3c445aa3 */
/*
* Coefficients for approximation to erfc in [1.25,1/0.35]
*/
ra0 = -9.8649440333e-03, /* 0xbc21a093 */
ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */
ra2 = -1.0558626175e+01, /* 0xc128f022 */
ra3 = -6.2375331879e+01, /* 0xc2798057 */
ra4 = -1.6239666748e+02, /* 0xc322658c */
ra5 = -1.8460508728e+02, /* 0xc3389ae7 */
ra6 = -8.1287437439e+01, /* 0xc2a2932b */
ra7 = -9.8143291473e+00, /* 0xc11d077e */
sa1 = 1.9651271820e+01, /* 0x419d35ce */
sa2 = 1.3765776062e+02, /* 0x4309a863 */
sa3 = 4.3456588745e+02, /* 0x43d9486f */
sa4 = 6.4538726807e+02, /* 0x442158c9 */
sa5 = 4.2900814819e+02, /* 0x43d6810b */
sa6 = 1.0863500214e+02, /* 0x42d9451f */
sa7 = 6.5702495575e+00, /* 0x40d23f7c */
sa8 = -6.0424413532e-02, /* 0xbd777f97 */
/*
* Coefficients for approximation to erfc in [1/.35,28]
*/
rb0 = -9.8649431020e-03, /* 0xbc21a092 */
rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */
rb2 = -1.7757955551e+01, /* 0xc18e104b */
rb3 = -1.6063638306e+02, /* 0xc320a2ea */
rb4 = -6.3756646729e+02, /* 0xc41f6441 */
rb5 = -1.0250950928e+03, /* 0xc480230b */
rb6 = -4.8351919556e+02, /* 0xc3f1c275 */
sb1 = 3.0338060379e+01, /* 0x41f2b459 */
sb2 = 3.2579251099e+02, /* 0x43a2e571 */
sb3 = 1.5367296143e+03, /* 0x44c01759 */
sb4 = 3.1998581543e+03, /* 0x4547fdbb */
sb5 = 2.5530502930e+03, /* 0x451f90ce */
sb6 = 4.7452853394e+02, /* 0x43ed43a7 */
sb7 = -2.2440952301e+01; /* 0xc1b38712 */
 
#ifdef __STDC__
float erff(float x)
#else
float erff(x)
float x;
#endif
{
int32_t hx,ix,i;
float R,S,P,Q,s,y,z,r;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) { /* erf(nan)=nan */
i = ((u_int32_t)hx>>31)<<1;
return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */
}
 
if(ix < 0x3f580000) { /* |x|<0.84375 */
if(ix < 0x31800000) { /* |x|<2**-28 */
if (ix < 0x04000000)
/*avoid underflow */
return (float)0.125*((float)8.0*x+efx8*x);
return x + efx*x;
}
z = x*x;
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
y = r/s;
return x + x*y;
}
if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */
s = fabsf(x)-one;
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
if(hx>=0) return erx + P/Q; else return -erx - P/Q;
}
if (ix >= 0x40c00000) { /* inf>|x|>=6 */
if(hx>=0) return one-tiny; else return tiny-one;
}
x = fabsf(x);
s = one/(x*x);
if(ix< 0x4036DB6E) { /* |x| < 1/0.35 */
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
ra5+s*(ra6+s*ra7))))));
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
sa5+s*(sa6+s*(sa7+s*sa8)))))));
} else { /* |x| >= 1/0.35 */
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
rb5+s*rb6)))));
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(z,ix&0xfffff000);
r = __ieee754_expf(-z*z-(float)0.5625)*__ieee754_expf((z-x)*(z+x)+R/S);
if(hx>=0) return one-r/x; else return r/x-one;
}
 
#ifdef __STDC__
float erfcf(float x)
#else
float erfcf(x)
float x;
#endif
{
int32_t hx,ix;
float R,S,P,Q,s,y,z,r;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) { /* erfc(nan)=nan */
/* erfc(+-inf)=0,2 */
return (float)(((u_int32_t)hx>>31)<<1)+one/x;
}
 
if(ix < 0x3f580000) { /* |x|<0.84375 */
if(ix < 0x23800000) /* |x|<2**-56 */
return one-x;
z = x*x;
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
y = r/s;
if(hx < 0x3e800000) { /* x<1/4 */
return one-(x+x*y);
} else {
r = x*y;
r += (x-half);
return half - r ;
}
}
if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */
s = fabsf(x)-one;
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
if(hx>=0) {
z = one-erx; return z - P/Q;
} else {
z = erx+P/Q; return one+z;
}
}
if (ix < 0x41e00000) { /* |x|<28 */
x = fabsf(x);
s = one/(x*x);
if(ix< 0x4036DB6D) { /* |x| < 1/.35 ~ 2.857143*/
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
ra5+s*(ra6+s*ra7))))));
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
sa5+s*(sa6+s*(sa7+s*sa8)))))));
} else { /* |x| >= 1/.35 ~ 2.857143 */
if(hx<0&&ix>=0x40c00000) return two-tiny;/* x < -6 */
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
rb5+s*rb6)))));
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(z,ix&0xfffff000);
r = __ieee754_expf(-z*z-(float)0.5625)*
__ieee754_expf((z-x)*(z+x)+R/S);
if(hx>0) return r/x; else return two-r/x;
} else {
if(hx>0) return tiny*tiny; else return two-tiny;
}
}
/programs/develop/libraries/menuetlibc/src/libm/sf_expm1.s
0,0 → 1,16
#include<libc/asm.h>
MK_C_SYM(expm1f)
flds 4(%esp)
fldl2e
fmulp
fstl %st(1)
frndint
fstl %st(2)
fsubrp
f2xm1
fld1
faddp
fscale
fld1
fsubrp
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_fabs.c
0,0 → 1,39
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_fabsf.c -- float version of s_fabs.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_fabsf.c,v 1.2 1994/08/18 23:06:43 jtc Exp $";
#endif
 
/*
* fabsf(x) returns the absolute value of x.
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float fabsf(float x)
#else
float fabsf(x)
float x;
#endif
{
u_int32_t ix;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x7fffffff);
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_finit.s
0,0 → 1,8
#include<libc/asm.h>
MK_C_SYM(finitef)
movl 4(%esp),%eax
andl $0x7ff00000, %eax
cmpl $0x7ff00000, %eax
setne %al
andl $0x000000ff, %eax
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_floor.s
0,0 → 1,20
#include<libc/asm.h>
MK_C_SYM(floorf)
pushl %ebp
movl %esp,%ebp
subl $8,%esp
 
fstcw -12(%ebp)
movw -12(%ebp),%dx
orw $0x0400,%dx
andw $0xf7ff,%dx
movw %dx,-16(%ebp)
fldcw -16(%ebp)
 
flds 8(%ebp);
frndint
 
fldcw -12(%ebp)
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_frexp.c
0,0 → 1,54
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_frexpf.c -- float version of s_frexp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_frexpf.c,v 1.2 1994/08/18 23:06:51 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
two25 = 3.3554432000e+07; /* 0x4c000000 */
 
#ifdef __STDC__
float frexpf(float x, int *eptr)
#else
float frexpf(x, eptr)
float x; int *eptr;
#endif
{
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
*eptr = 0;
if(ix>=0x7f800000||(ix==0)) return x; /* 0,inf,nan */
if (ix<0x00800000) { /* subnormal */
x *= two25;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
*eptr = -25;
}
*eptr += (ix>>23)-126;
hx = (hx&0x807fffff)|0x3f000000;
*(int*)&x = hx;
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_ilogb.s
0,0 → 1,15
#include<libc/asm.h>
MK_C_SYM(ilogbf)
pushl %esp
movl %esp,%ebp
subl $4,%esp
 
flds 8(%ebp)
fxtract
fstpl %st
 
fistpl -4(%ebp)
movl -4(%ebp),%eax
 
leave
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_isinf.c
0,0 → 1,56
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* Copyright (c) 1994 Winning Strategies, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Winning Strategies, Inc.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_isinf.c,v 1.6 1994/08/18 23:06:54 jtc Exp $";
#endif
 
/*
* isinff(x) returns 1 is x is inf, else 0;
* no branching!
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
int isinff(float x)
#else
int isinff(x)
float x;
#endif
{
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
ix ^= 0x7f800000;
return (ix == 0);
}
/programs/develop/libraries/menuetlibc/src/libm/sf_isnan.c
0,0 → 1,41
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_isnanf.c -- float version of s_isnan.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_isnanf.c,v 1.2 1994/08/18 23:06:56 jtc Exp $";
#endif
 
/*
* isnanf(x) returns 1 is x is nan, else 0;
* no branching!
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
int isnanf(float x)
#else
int isnanf(x)
float x;
#endif
{
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
ix = 0x7f800000 - ix;
return (int)(((u_int32_t)(ix))>>31);
}
/programs/develop/libraries/menuetlibc/src/libm/sf_ldexp.c
0,0 → 1,36
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_ldexpf.c -- float version of s_ldexp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_ldexpf.c,v 1.1 1994/08/10 20:32:39 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
#include <errno.h>
 
#ifdef __STDC__
float ldexpf(float value, int exp)
#else
float ldexpf(value, exp)
float value; int exp;
#endif
{
if(!finitef(value)||value==(float)0.0) return value;
value = scalbnf(value,exp);
if(!finitef(value)||value==(float)0.0) errno = ERANGE;
return value;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_log1p.s
0,0 → 1,8
#include<libc/asm.h>
MK_C_SYM(log1pf)
fldln2
flds 4(%esp)
fld1
faddp
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_logb.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(logbf)
flds 4(%esp)
fxtract
fstpl %st
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_modf.c
0,0 → 1,65
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_modff.c -- float version of s_modf.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_modff.c,v 1.2 1994/08/18 23:07:12 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float one = 1.0;
#else
static float one = 1.0;
#endif
 
#ifdef __STDC__
float modff(float x, float *iptr)
#else
float modff(x, iptr)
float x,*iptr;
#endif
{
int32_t i0,j0;
u_int32_t i;
GET_FLOAT_WORD(i0,x);
j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */
if(j0<23) { /* integer part in x */
if(j0<0) { /* |x|<1 */
SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */
return x;
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) { /* x is integral */
u_int32_t ix;
*iptr = x;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
return x;
} else {
SET_FLOAT_WORD(*iptr,i0&(~i));
return x - *iptr;
}
}
} else { /* no fraction part */
u_int32_t ix;
*iptr = x*one;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
return x;
}
}
/programs/develop/libraries/menuetlibc/src/libm/sf_nexta.c
0,0 → 1,71
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_nextafterf.c -- float version of s_nextafter.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_nextafterf.c,v 1.2 1994/08/18 23:07:15 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float nextafterf(float x, float y)
#else
float nextafterf(x,y)
float x,y;
#endif
{
int32_t hx,hy,ix,iy;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
ix = hx&0x7fffffff; /* |x| */
iy = hy&0x7fffffff; /* |y| */
 
if((ix>0x7f800000) || /* x is nan */
(iy>0x7f800000)) /* y is nan */
return x+y;
if(x==y) return x; /* x=y, return x */
if(ix==0) { /* x == 0 */
SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
y = x*x;
if(y==x) return y; else return x; /* raise underflow flag */
}
if(hx>=0) { /* x > 0 */
if(hx>hy) { /* x > y, x -= ulp */
hx -= 1;
} else { /* x < y, x += ulp */
hx += 1;
}
} else { /* x < 0 */
if(hy>=0||hx>hy){ /* x < y, x -= ulp */
hx -= 1;
} else { /* x > y, x += ulp */
hx += 1;
}
}
hy = hx&0x7f800000;
if(hy>=0x7f800000) return x+x; /* overflow */
if(hy<0x00800000) { /* underflow */
y = x*x;
if(y!=x) { /* raise underflow flag */
SET_FLOAT_WORD(y,hx);
return y;
}
}
SET_FLOAT_WORD(x,hx);
return x;
}
/programs/develop/libraries/menuetlibc/src/libm/sf_rint.s
0,0 → 1,112
# 1 "SF_RINT.S"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 1 "c:/djgpp/include/machine/asm.h" 1 3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 37 "SF_RINT.S" 2
 
 
.globl rintf
rintf:
flds 4(%esp)
frndint
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_scalb.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(scalbnf)
fildl 8(%esp)
flds 4(%esp)
fscale
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_signi.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(significandf)
flds 4(%esp)
fxtract
fstpl %st(1)
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_sin.s
0,0 → 1,5
#include<libc/asm.h>
MK_C_SYM(sinf)
flds 4(%esp)
fsin
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_tan.s
0,0 → 1,6
#include<libc/asm.h>
MK_C_SYM(tanf)
flds 4(%esp)
fptan
fstp %st(0)
ret
/programs/develop/libraries/menuetlibc/src/libm/sf_tanh.c
0,0 → 1,65
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* s_tanhf.c -- float version of s_tanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: s_tanhf.c,v 1.2 1994/08/18 23:10:23 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float one=1.0, two=2.0, tiny = 1.0e-30;
#else
static float one=1.0, two=2.0, tiny = 1.0e-30;
#endif
 
#ifdef __STDC__
float tanhf(float x)
#else
float tanhf(x)
float x;
#endif
{
float t,z;
int32_t jx,ix;
 
GET_FLOAT_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(ix>=0x7f800000) {
if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
else return one/x-one; /* tanh(NaN) = NaN */
}
 
/* |x| < 22 */
if (ix < 0x41b00000) { /* |x|<22 */
if (ix<0x24000000) /* |x|<2**-55 */
return x*(one+x); /* tanh(small) = small */
if (ix>=0x3f800000) { /* |x|>=1 */
t = expm1f(two*fabsf(x));
z = one - two/(t+two);
} else {
t = expm1f(-two*fabsf(x));
z= -t/(t+two);
}
/* |x| > 22, return +-1 */
} else {
z = one - tiny; /* raised inexact flag */
}
return (jx>=0)? z: -z;
}
/programs/develop/libraries/menuetlibc/src/libm/staaaaaa
--- libm/w_acos.c (nonexistent)
+++ libm/w_acos.c (revision 4973)
@@ -0,0 +1,44 @@
+/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+/* @(#)w_acos.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(LIBM_SCCS) && !defined(lint)
+static char rcsid[] = "$Id: w_acos.c,v 1.4 1994/08/10 20:33:18 jtc Exp $";
+#endif
+
+/*
+ * wrap_acos(x)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+
+#ifdef __STDC__
+ double acos(double x) /* wrapper acos */
+#else
+ double acos(x) /* wrapper acos */
+ double x;
+#endif
+{
+#ifdef _IEEE_LIBM
+ return __ieee754_acos(x);
+#else
+ double z;
+ z = __ieee754_acos(x);
+ if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+ if(fabs(x)>1.0) {
+ return __kernel_standard(x,x,1); /* acos(|x|>1) */
+ } else
+ return z;
+#endif
+}
/programs/develop/libraries/menuetlibc/src/libm/w_acosh.c
0,0 → 1,43
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_acosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_acosh.c,v 1.4 1994/08/10 20:33:25 jtc Exp $";
#endif
 
/*
* wrapper acosh(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double acosh(double x) /* wrapper acosh */
#else
double acosh(x) /* wrapper acosh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acosh(x);
#else
double z;
z = __ieee754_acosh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<1.0) {
return __kernel_standard(x,x,29); /* acosh(x<1) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_asin.c
0,0 → 1,45
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_asin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_asin.c,v 1.4 1994/08/10 20:33:30 jtc Exp $";
#endif
 
/*
* wrapper asin(x)
*/
 
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double asin(double x) /* wrapper asin */
#else
double asin(x) /* wrapper asin */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_asin(x);
#else
double z;
z = __ieee754_asin(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>1.0) {
return __kernel_standard(x,x,2); /* asin(|x|>1) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_atan2.c
0,0 → 1,44
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_atan2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_atan2.c,v 1.4 1994/08/10 20:33:38 jtc Exp $";
#endif
 
/*
* wrapper atan2(y,x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double atan2(double y, double x) /* wrapper atan2 */
#else
double atan2(y,x) /* wrapper atan2 */
double y,x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atan2(y,x);
#else
double z;
z = __ieee754_atan2(y,x);
if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;
if(x==0.0&&y==0.0) {
return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_atanh.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_atanh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_atanh.c,v 1.4 1994/08/10 20:33:45 jtc Exp $";
#endif
 
/*
* wrapper atanh(x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double atanh(double x) /* wrapper atanh */
#else
double atanh(x) /* wrapper atanh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atanh(x);
#else
double z,y;
z = __ieee754_atanh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
y = fabs(x);
if(y>=1.0) {
if(y>1.0)
return __kernel_standard(x,x,30); /* atanh(|x|>1) */
else
return __kernel_standard(x,x,31); /* atanh(|x|==1) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_cabs.c
0,0 → 1,21
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* cabs() wrapper for hypot().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include <math.h>
 
struct complex {
double x;
double y;
};
 
double
cabs(z)
struct complex z;
{
return hypot(z.x, z.y);
}
/programs/develop/libraries/menuetlibc/src/libm/w_cosh.c
0,0 → 1,43
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_cosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_cosh.c,v 1.4 1994/08/10 20:33:54 jtc Exp $";
#endif
 
/*
* wrapper cosh(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double cosh(double x) /* wrapper cosh */
#else
double cosh(x) /* wrapper cosh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_cosh(x);
#else
double z;
z = __ieee754_cosh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>7.10475860073943863426e+02) {
return __kernel_standard(x,x,5); /* cosh overflow */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_drem.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* drem() wrapper for remainder().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include <math.h>
 
double
drem(x, y)
double x, y;
{
return remainder(x, y);
}
/programs/develop/libraries/menuetlibc/src/libm/w_exp.c
0,0 → 1,54
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_exp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_exp.c,v 1.4 1994/08/10 20:34:00 jtc Exp $";
#endif
 
/*
* wrapper exp(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */
 
#ifdef __STDC__
double exp(double x) /* wrapper exp */
#else
double exp(x) /* wrapper exp */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_exp(x);
#else
double z;
z = __ieee754_exp(x);
if(_LIB_VERSION == _IEEE_) return z;
if(finite(x)) {
if(x>o_threshold)
return __kernel_standard(x,x,6); /* exp overflow */
else if(x<u_threshold)
return __kernel_standard(x,x,7); /* exp underflow */
}
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_fmod.c
0,0 → 1,44
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_fmod.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_fmod.c,v 1.4 1994/08/10 20:34:05 jtc Exp $";
#endif
 
/*
* wrapper fmod(x,y)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double fmod(double x, double y) /* wrapper fmod */
#else
double fmod(x,y) /* wrapper fmod */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_fmod(x,y);
#else
double z;
z = __ieee754_fmod(x,y);
if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
if(y==0.0) {
return __kernel_standard(x,y,27); /* fmod(x,0) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_gamma.c
0,0 → 1,50
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_gamma.c,v 1.4 1994/08/10 20:34:09 jtc Exp $";
#endif
 
/* double gamma(double x)
* Return the logarithm of the Gamma function of x.
*
* Method: call gamma_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
double gamma(double x)
#else
double gamma(x)
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gamma_r(x,&signgam);
#else
double y;
y = __ieee754_gamma_r(x,&signgam);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
return __kernel_standard(x,x,41); /* gamma pole */
else
return __kernel_standard(x,x,40); /* gamma overflow */
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_hypot.c
0,0 → 1,44
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_hypot.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_hypot.c,v 1.4 1994/08/10 20:34:24 jtc Exp $";
#endif
 
/*
* wrapper hypot(x,y)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double hypot(double x, double y)/* wrapper hypot */
#else
double hypot(x,y) /* wrapper hypot */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_hypot(x,y);
#else
double z;
z = __ieee754_hypot(x,y);
if(_LIB_VERSION == _IEEE_) return z;
if((!finite(z))&&finite(x)&&finite(y))
return __kernel_standard(x,y,4); /* hypot overflow */
else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_j0.c
0,0 → 1,70
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_j0.c,v 1.4 1994/08/10 20:34:29 jtc Exp $";
#endif
 
/*
* wrapper j0(double x), y0(double x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double j0(double x) /* wrapper j0 */
#else
double j0(x) /* wrapper j0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0(x);
#else
double z = __ieee754_j0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard(x,x,34); /* j0(|x|>X_TLOSS) */
} else
return z;
#endif
}
 
#ifdef __STDC__
double y0(double x) /* wrapper y0 */
#else
double y0(x) /* wrapper y0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0(x);
#else
double z;
z = __ieee754_y0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard(x,x,8);
else
/* d = zero/(x-x); */
return __kernel_standard(x,x,9);
}
if(x>X_TLOSS) {
return __kernel_standard(x,x,35); /* y0(x>X_TLOSS) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_j1.c
0,0 → 1,71
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_j1.c,v 1.4 1994/08/10 20:34:35 jtc Exp $";
#endif
 
/*
* wrapper of j1,y1
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double j1(double x) /* wrapper j1 */
#else
double j1(x) /* wrapper j1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1(x);
#else
double z;
z = __ieee754_j1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard(x,x,36); /* j1(|x|>X_TLOSS) */
} else
return z;
#endif
}
 
#ifdef __STDC__
double y1(double x) /* wrapper y1 */
#else
double y1(x) /* wrapper y1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1(x);
#else
double z;
z = __ieee754_y1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard(x,x,10);
else
/* d = zero/(x-x); */
return __kernel_standard(x,x,11);
}
if(x>X_TLOSS) {
return __kernel_standard(x,x,37); /* y1(x>X_TLOSS) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_jn.c
0,0 → 1,93
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_jn.c,v 1.4 1994/08/10 20:34:42 jtc Exp $";
#endif
 
/*
* wrapper jn(int n, double x), yn(int n, double x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double jn(int n, double x) /* wrapper jn */
#else
double jn(n,x) /* wrapper jn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jn(n,x);
#else
double z;
z = __ieee754_jn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
} else
return z;
#endif
}
 
#ifdef __STDC__
double yn(int n, double x) /* wrapper yn */
#else
double yn(n,x) /* wrapper yn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_yn(n,x);
#else
double z;
z = __ieee754_yn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard((double)n,x,12);
else
/* d = zero/(x-x); */
return __kernel_standard((double)n,x,13);
}
if(x>X_TLOSS) {
return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_lgamma.c
0,0 → 1,50
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_lgamma.c,v 1.4 1994/08/10 20:34:53 jtc Exp $";
#endif
 
/* double lgamma(double x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_lgamma_r
*/
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
double lgamma(double x)
#else
double lgamma(x)
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgamma_r(x,&signgam);
#else
double y;
y = __ieee754_lgamma_r(x,&signgam);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
return __kernel_standard(x,x,15); /* lgamma pole */
else
return __kernel_standard(x,x,14); /* lgamma overflow */
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_log.c
0,0 → 1,44
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_log.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_log.c,v 1.4 1994/08/10 20:35:09 jtc Exp $";
#endif
 
/*
* wrapper log(x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double log(double x) /* wrapper log */
#else
double log(x) /* wrapper log */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log(x);
#else
double z;
z = __ieee754_log(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;
if(x==0.0)
return __kernel_standard(x,x,16); /* log(0) */
else
return __kernel_standard(x,x,17); /* log(x<0) */
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_log10.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_log10.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_log10.c,v 1.4 1994/08/10 20:35:15 jtc Exp $";
#endif
 
/*
* wrapper log10(X)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double log10(double x) /* wrapper log10 */
#else
double log10(x) /* wrapper log10 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log10(x);
#else
double z;
z = __ieee754_log10(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<=0.0) {
if(x==0.0)
return __kernel_standard(x,x,18); /* log10(0) */
else
return __kernel_standard(x,x,19); /* log10(x<0) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_pow.c
0,0 → 1,62
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
 
 
/* @(#)w_pow.c 5.2 93/10/01 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper pow(x,y) return x**y
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double pow(double x, double y) /* wrapper pow */
#else
double pow(x,y) /* wrapper pow */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_pow(x,y);
#else
double z;
z=__ieee754_pow(x,y);
if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
if(isnan(x)) {
if(y==0.0)
return __kernel_standard(x,y,42); /* pow(NaN,0.0) */
else
return z;
}
if(x==0.0){
if(y==0.0)
return __kernel_standard(x,y,20); /* pow(0.0,0.0) */
if(finite(y)&&y<0.0)
return __kernel_standard(x,y,23); /* pow(0.0,negative) */
return z;
}
if(!finite(z)) {
if(finite(x)&&finite(y)) {
if(isnan(z))
return __kernel_standard(x,y,24); /* pow neg**non-int */
else
return __kernel_standard(x,y,21); /* pow overflow */
}
}
if(z==0.0&&finite(x)&&finite(y))
return __kernel_standard(x,y,22); /* pow underflow */
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_remain.c
0,0 → 1,43
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_remainder.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_remainder.c,v 1.4 1994/08/10 20:35:32 jtc Exp $";
#endif
 
/*
* wrapper remainder(x,p)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double remainder(double x, double y) /* wrapper remainder */
#else
double remainder(x,y) /* wrapper remainder */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_remainder(x,y);
#else
double z;
z = __ieee754_remainder(x,y);
if(_LIB_VERSION == _IEEE_ || isnan(y)) return z;
if(y==0.0)
return __kernel_standard(x,y,28); /* remainder(x,0) */
else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_scalb.c
0,0 → 1,61
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_scalb.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_scalb.c,v 1.4 1994/08/10 20:35:37 jtc Exp $";
#endif
 
/*
* wrapper scalb(double x, double fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
 
#include "math.h"
#include "math_private.h"
 
#include <errno.h>
 
#ifdef __STDC__
#ifdef _SCALB_INT
double scalb(double x, int fn) /* wrapper scalb */
#else
double scalb(double x, double fn) /* wrapper scalb */
#endif
#else
double scalb(x,fn) /* wrapper scalb */
#ifdef _SCALB_INT
double x; int fn;
#else
double x,fn;
#endif
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_scalb(x,fn);
#else
double z;
z = __ieee754_scalb(x,fn);
if(_LIB_VERSION == _IEEE_) return z;
if(!(finite(z)||isnan(z))&&finite(x)) {
return __kernel_standard(x,(double)fn,32); /* scalb overflow */
}
if(z==0.0&&z!=x) {
return __kernel_standard(x,(double)fn,33); /* scalb underflow */
}
#ifndef _SCALB_INT
if(!finite(fn)) errno = ERANGE;
#endif
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_sinh.c
0,0 → 1,43
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_sinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_sinh.c,v 1.4 1994/08/10 20:35:42 jtc Exp $";
#endif
 
/*
* wrapper sinh(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double sinh(double x) /* wrapper sinh */
#else
double sinh(x) /* wrapper sinh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sinh(x);
#else
double z;
z = __ieee754_sinh(x);
if(_LIB_VERSION == _IEEE_) return z;
if(!finite(z)&&finite(x)) {
return __kernel_standard(x,x,25); /* sinh overflow */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/w_sqrt.c
0,0 → 1,43
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)w_sqrt.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_sqrt.c,v 1.4 1994/08/10 20:35:48 jtc Exp $";
#endif
 
/*
* wrapper sqrt(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
double sqrt(double x) /* wrapper sqrt */
#else
double sqrt(x) /* wrapper sqrt */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sqrt(x);
#else
double z;
z = __ieee754_sqrt(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<0.0) {
return __kernel_standard(x,x,26); /* sqrt(negative) */
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_acos.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_acosf.c -- float version of w_acos.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_acosf.c,v 1.1 1994/08/10 20:33:23 jtc Exp $";
#endif
 
/*
* wrap_acosf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float acosf(float x) /* wrapper acosf */
#else
float acosf(x) /* wrapper acosf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acosf(x);
#else
float z;
z = __ieee754_acosf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(fabsf(x)>(float)1.0) {
/* acosf(|x|>1) */
return (float)__kernel_standard((double)x,(double)x,101);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_acosh.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_acoshf.c -- float version of w_acosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_acoshf.c,v 1.1 1994/08/10 20:33:28 jtc Exp $";
#endif
 
/*
* wrapper acoshf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float acoshf(float x) /* wrapper acoshf */
#else
float acoshf(x) /* wrapper acoshf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acoshf(x);
#else
float z;
z = __ieee754_acoshf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(x<(float)1.0) {
/* acosh(x<1) */
return (float)__kernel_standard((double)x,(double)x,129);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_asin.c
0,0 → 1,49
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_asinf.c -- float version of w_asin.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_asinf.c,v 1.1 1994/08/10 20:33:34 jtc Exp $";
#endif
 
/*
* wrapper asinf(x)
*/
 
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float asinf(float x) /* wrapper asinf */
#else
float asinf(x) /* wrapper asinf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_asinf(x);
#else
float z;
z = __ieee754_asinf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(fabsf(x)>(float)1.0) {
/* asinf(|x|>1) */
return (float)__kernel_standard((double)x,(double)x,102);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_atan2.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_atan2f.c -- float version of w_atan2.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_atan2f.c,v 1.1 1994/08/10 20:33:41 jtc Exp $";
#endif
 
/*
* wrapper atan2f(y,x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float atan2f(float y, float x) /* wrapper atan2f */
#else
float atan2f(y,x) /* wrapper atan2 */
float y,x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atan2f(y,x);
#else
float z;
z = __ieee754_atan2f(y,x);
if(_LIB_VERSION == _IEEE_||isnanf(x)||isnanf(y)) return z;
if(x==(float)0.0&&y==(float)0.0) {
/* atan2f(+-0,+-0) */
return (float)__kernel_standard((double)y,(double)x,103);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_atanh.c
0,0 → 1,53
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_atanhf.c -- float version of w_atanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_atanhf.c,v 1.1 1994/08/10 20:33:48 jtc Exp $";
#endif
 
/*
* wrapper atanhf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float atanhf(float x) /* wrapper atanhf */
#else
float atanhf(x) /* wrapper atanhf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atanhf(x);
#else
float z,y;
z = __ieee754_atanhf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
y = fabsf(x);
if(y>=(float)1.0) {
if(y>(float)1.0)
/* atanhf(|x|>1) */
return (float)__kernel_standard((double)x,(double)x,130);
else
/* atanhf(|x|==1) */
return (float)__kernel_standard((double)x,(double)x,131);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_cabs.c
0,0 → 1,22
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* cabsf() wrapper for hypotf().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include "math.h"
#include "math_private.h"
 
struct complex {
float x;
float y;
};
 
float
cabsf(z)
struct complex z;
{
return hypotf(z.x, z.y);
}
/programs/develop/libraries/menuetlibc/src/libm/wf_cosh.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_coshf.c -- float version of w_cosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_coshf.c,v 1.1 1994/08/10 20:33:56 jtc Exp $";
#endif
 
/*
* wrapper coshf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float coshf(float x) /* wrapper coshf */
#else
float coshf(x) /* wrapper coshf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_coshf(x);
#else
float z;
z = __ieee754_coshf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(fabsf(x)>(float)8.9415985107e+01) {
/* cosh overflow */
return (float)__kernel_standard((double)x,(double)x,105);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_drem.c
0,0 → 1,17
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* dremf() wrapper for remainderf().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include "math.h"
#include "math_private.h"
 
float
dremf(x, y)
float x, y;
{
return remainderf(x, y);
}
/programs/develop/libraries/menuetlibc/src/libm/wf_exp.c
0,0 → 1,59
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_expf.c -- float version of w_exp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_expf.c,v 1.1 1994/08/10 20:34:03 jtc Exp $";
#endif
 
/*
* wrapper expf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
o_threshold= 8.8721679688e+01, /* 0x42b17180 */
u_threshold= -1.0397208405e+02; /* 0xc2cff1b5 */
 
#ifdef __STDC__
float expf(float x) /* wrapper expf */
#else
float expf(x) /* wrapper expf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_expf(x);
#else
float z;
z = __ieee754_expf(x);
if(_LIB_VERSION == _IEEE_) return z;
if(finitef(x)) {
if(x>o_threshold)
/* exp overflow */
return (float)__kernel_standard((double)x,(double)x,106);
else if(x<u_threshold)
/* exp underflow */
return (float)__kernel_standard((double)x,(double)x,107);
}
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_fmod.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_fmodf.c -- float version of w_fmod.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_fmodf.c,v 1.1 1994/08/10 20:34:07 jtc Exp $";
#endif
 
/*
* wrapper fmodf(x,y)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float fmodf(float x, float y) /* wrapper fmodf */
#else
float fmodf(x,y) /* wrapper fmodf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_fmodf(x,y);
#else
float z;
z = __ieee754_fmodf(x,y);
if(_LIB_VERSION == _IEEE_ ||isnanf(y)||isnanf(x)) return z;
if(y==(float)0.0) {
/* fmodf(x,0) */
return (float)__kernel_standard((double)x,(double)y,127);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_gamma.c
0,0 → 1,49
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_gammaf.c -- float version of w_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_gammaf.c,v 1.1 1994/08/10 20:34:16 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
float gammaf(float x)
#else
float gammaf(x)
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gammaf_r(x,&signgam);
#else
float y;
y = __ieee754_gammaf_r(x,&signgam);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=(float)0.0)
/* gammaf pole */
return (float)__kernel_standard((double)x,(double)x,141);
else
/* gammaf overflow */
return (float)__kernel_standard((double)x,(double)x,140);
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_hypot.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_hypotf.c -- float version of w_hypot.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_hypotf.c,v 1.1 1994/08/10 20:34:27 jtc Exp $";
#endif
 
/*
* wrapper hypotf(x,y)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float hypotf(float x, float y) /* wrapper hypotf */
#else
float hypotf(x,y) /* wrapper hypotf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_hypotf(x,y);
#else
float z;
z = __ieee754_hypotf(x,y);
if(_LIB_VERSION == _IEEE_) return z;
if((!finitef(z))&&finitef(x)&&finitef(y))
/* hypot overflow */
return (float)__kernel_standard((double)x,(double)y,104);
else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_j0.c
0,0 → 1,75
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_j0f.c -- float version of w_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_j0f.c,v 1.1 1994/08/10 20:34:32 jtc Exp $";
#endif
 
/*
* wrapper j0f(float x), y0f(float x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float j0f(float x) /* wrapper j0f */
#else
float j0f(x) /* wrapper j0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0f(x);
#else
float z = __ieee754_j0f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j0f(|x|>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,134);
} else
return z;
#endif
}
 
#ifdef __STDC__
float y0f(float x) /* wrapper y0f */
#else
float y0f(x) /* wrapper y0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0f(x);
#else
float z;
z = __ieee754_y0f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)x,(double)x,108);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)x,(double)x,109);
}
if(x>(float)X_TLOSS) {
/* y0(x>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,135);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_j1.c
0,0 → 1,76
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_j1f.c -- float version of w_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_j1f.c,v 1.1 1994/08/10 20:34:39 jtc Exp $";
#endif
 
/*
* wrapper of j1f,y1f
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float j1f(float x) /* wrapper j1f */
#else
float j1f(x) /* wrapper j1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1f(x);
#else
float z;
z = __ieee754_j1f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j1(|x|>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,136);
} else
return z;
#endif
}
 
#ifdef __STDC__
float y1f(float x) /* wrapper y1f */
#else
float y1f(x) /* wrapper y1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1f(x);
#else
float z;
z = __ieee754_y1f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)x,(double)x,110);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)x,(double)x,111);
}
if(x>(float)X_TLOSS) {
/* y1(x>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,137);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_jn.c
0,0 → 1,72
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_jnf.c -- float version of w_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_jnf.c,v 1.1 1994/08/10 20:34:47 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float jnf(int n, float x) /* wrapper jnf */
#else
float jnf(n,x) /* wrapper jnf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jnf(n,x);
#else
float z;
z = __ieee754_jnf(n,x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* jn(|x|>X_TLOSS,n) */
return (float)__kernel_standard((double)n,(double)x,138);
} else
return z;
#endif
}
 
#ifdef __STDC__
float ynf(int n, float x) /* wrapper ynf */
#else
float ynf(n,x) /* wrapper ynf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_ynf(n,x);
#else
float z;
z = __ieee754_ynf(n,x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)n,(double)x,112);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)n,(double)x,113);
}
if(x>(float)X_TLOSS) {
/* yn(x>X_TLOSS,n) */
return (float)__kernel_standard((double)n,(double)x,139);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_lgamm.c
0,0 → 1,49
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_lgammaf.c -- float version of w_lgamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_lgammaf.c,v 1.1 1994/08/10 20:35:00 jtc Exp $";
#endif
 
#include "math.h"
#include "math_private.h"
 
extern int signgam;
 
#ifdef __STDC__
float lgammaf(float x)
#else
float lgammaf(x)
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgammaf_r(x,&signgam);
#else
float y;
y = __ieee754_lgammaf_r(x,&signgam);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=(float)0.0)
/* lgamma pole */
return (float)__kernel_standard((double)x,(double)x,115);
else
/* lgamma overflow */
return (float)__kernel_standard((double)x,(double)x,114);
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_log.c
0,0 → 1,49
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_logf.c -- float version of w_log.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_logf.c,v 1.1 1994/08/10 20:35:23 jtc Exp $";
#endif
 
/*
* wrapper logf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float logf(float x) /* wrapper logf */
#else
float logf(x) /* wrapper logf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_logf(x);
#else
float z;
z = __ieee754_logf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) || x > (float)0.0) return z;
if(x==(float)0.0)
/* logf(0) */
return (float)__kernel_standard((double)x,(double)x,116);
else
/* logf(x<0) */
return (float)__kernel_standard((double)x,(double)x,117);
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_log10.c
0,0 → 1,52
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_log10f.c -- float version of w_log10.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_log10f.c,v 1.1 1994/08/10 20:35:20 jtc Exp $";
#endif
 
/*
* wrapper log10f(X)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float log10f(float x) /* wrapper log10f */
#else
float log10f(x) /* wrapper log10f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log10f(x);
#else
float z;
z = __ieee754_log10f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(x<=(float)0.0) {
if(x==(float)0.0)
/* log10(0) */
return (float)__kernel_standard((double)x,(double)x,118);
else
/* log10(x<0) */
return (float)__kernel_standard((double)x,(double)x,119);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_pow.c
0,0 → 1,73
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_powf.c -- float version of w_pow.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_powf.c,v 1.1 1994/08/10 20:35:29 jtc Exp $";
#endif
 
/*
* wrapper powf(x,y) return x**y
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float powf(float x, float y) /* wrapper powf */
#else
float powf(x,y) /* wrapper powf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_powf(x,y);
#else
float z;
z=__ieee754_powf(x,y);
if(_LIB_VERSION == _IEEE_|| isnanf(y)) return z;
if(isnanf(x)) {
if(y==(float)0.0)
/* powf(NaN,0.0) */
return (float)__kernel_standard((double)x,(double)y,142);
else
return z;
}
if(x==(float)0.0){
if(y==(float)0.0)
/* powf(0.0,0.0) */
return (float)__kernel_standard((double)x,(double)y,120);
if(finitef(y)&&y<(float)0.0)
/* powf(0.0,negative) */
return (float)__kernel_standard((double)x,(double)y,123);
return z;
}
if(!finitef(z)) {
if(finitef(x)&&finitef(y)) {
if(isnanf(z))
/* powf neg**non-int */
return (float)__kernel_standard((double)x,(double)y,124);
else
/* powf overflow */
return (float)__kernel_standard((double)x,(double)y,121);
}
}
if(z==(float)0.0&&finitef(x)&&finitef(y))
/* powf underflow */
return (float)__kernel_standard((double)x,(double)y,122);
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_remai.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_remainderf.c -- float version of w_remainder.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_remainderf.c,v 1.1 1994/08/10 20:35:35 jtc Exp $";
#endif
 
/*
* wrapper remainderf(x,p)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float remainderf(float x, float y) /* wrapper remainder */
#else
float remainderf(x,y) /* wrapper remainder */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_remainderf(x,y);
#else
float z;
z = __ieee754_remainderf(x,y);
if(_LIB_VERSION == _IEEE_ || isnanf(y)) return z;
if(y==(float)0.0)
/* remainder(x,0) */
return (float)__kernel_standard((double)x,(double)y,128);
else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_scalb.c
0,0 → 1,66
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_scalbf.c -- float version of w_scalb.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_scalbf.c,v 1.1 1994/08/10 20:35:40 jtc Exp $";
#endif
 
/*
* wrapper scalbf(float x, float fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
 
#include "math.h"
#include "math_private.h"
 
#include <errno.h>
 
#ifdef __STDC__
#ifdef _SCALB_INT
float scalbf(float x, int fn) /* wrapper scalbf */
#else
float scalbf(float x, float fn) /* wrapper scalbf */
#endif
#else
float scalbf(x,fn) /* wrapper scalbf */
#ifdef _SCALB_INT
float x; int fn;
#else
float x,fn;
#endif
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_scalbf(x,fn);
#else
float z;
z = __ieee754_scalbf(x,fn);
if(_LIB_VERSION == _IEEE_) return z;
if(!(finitef(z)||isnanf(z))&&finitef(x)) {
/* scalbf overflow */
return (float)__kernel_standard((double)x,(double)fn,132);
}
if(z==(float)0.0&&z!=x) {
/* scalbf underflow */
return (float)__kernel_standard((double)x,(double)fn,133);
}
#ifndef _SCALB_INT
if(!finitef(fn)) errno = ERANGE;
#endif
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_sinh.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_sinhf.c -- float version of w_sinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_sinhf.c,v 1.1 1994/08/10 20:35:45 jtc Exp $";
#endif
 
/*
* wrapper sinhf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float sinhf(float x) /* wrapper sinhf */
#else
float sinhf(x) /* wrapper sinhf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sinhf(x);
#else
float z;
z = __ieee754_sinhf(x);
if(_LIB_VERSION == _IEEE_) return z;
if(!finitef(z)&&finitef(x)) {
/* sinhf overflow */
return (float)__kernel_standard((double)x,(double)x,125);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wf_sqrt.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_sqrtf.c -- float version of w_sqrt.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_sqrtf.c,v 1.1 1994/08/10 20:35:53 jtc Exp $";
#endif
 
/*
* wrapper sqrtf(x)
*/
 
#include "math.h"
#include "math_private.h"
 
#ifdef __STDC__
float sqrtf(float x) /* wrapper sqrtf */
#else
float sqrt(x) /* wrapper sqrtf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sqrtf(x);
#else
float z;
z = __ieee754_sqrtf(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(x<(float)0.0) {
/* sqrtf(negative) */
return (float)__kernel_standard((double)x,(double)x,126);
} else
return z;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wr_gamma.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)wr_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_gamma_r.c,v 1.4 1994/08/10 20:34:13 jtc Exp $";
#endif
 
/*
* wrapper double gamma_r(double x, int *signgamp)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double gamma_r(double x, int *signgamp) /* wrapper lgamma_r */
#else
double gamma_r(x,signgamp) /* wrapper lgamma_r */
double x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gamma_r(x,signgamp);
#else
double y;
y = __ieee754_gamma_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
return __kernel_standard(x,x,41); /* gamma pole */
else
return __kernel_standard(x,x,40); /* gamma overflow */
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wr_lgamm.c
0,0 → 1,47
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* @(#)wr_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_lgamma_r.c,v 1.4 1994/08/10 20:34:57 jtc Exp $";
#endif
 
/*
* wrapper double lgamma_r(double x, int *signgamp)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
double lgamma_r(double x, int *signgamp) /* wrapper lgamma_r */
#else
double lgamma_r(x,signgamp) /* wrapper lgamma_r */
double x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgamma_r(x,signgamp);
#else
double y;
y = __ieee754_lgamma_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
return __kernel_standard(x,x,15); /* lgamma pole */
else
return __kernel_standard(x,x,14); /* lgamma overflow */
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wrf_gamm.c
0,0 → 1,52
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_gammaf_r.c -- float version of w_gamma_r.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_gammaf_r.c,v 1.1 1994/08/10 20:34:20 jtc Exp $";
#endif
 
/*
* wrapper float gammaf_r(float x, int *signgamp)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float gammaf_r(float x, int *signgamp) /* wrapper lgammaf_r */
#else
float gammaf_r(x,signgamp) /* wrapper lgammaf_r */
float x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gammaf_r(x,signgamp);
#else
float y;
y = __ieee754_gammaf_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=(float)0.0)
/* gammaf pole */
return (float)__kernel_standard((double)x,(double)x,141);
else
/* gamma overflow */
return (float)__kernel_standard((double)x,(double)x,140);
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libm/wrf_lgam.c
0,0 → 1,52
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* w_lgammaf_r.c -- float version of w_lgamma_r.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$Id: w_lgammaf_r.c,v 1.1 1994/08/10 20:35:05 jtc Exp $";
#endif
 
/*
* wrapper float lgammaf_r(float x, int *signgamp)
*/
 
#include "math.h"
#include "math_private.h"
 
 
#ifdef __STDC__
float lgammaf_r(float x, int *signgamp) /* wrapper lgammaf_r */
#else
float lgammaf_r(x,signgamp) /* wrapper lgammaf_r */
float x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgammaf_r(x,signgamp);
#else
float y;
y = __ieee754_lgammaf_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=(float)0.0)
/* lgamma pole */
return (float)__kernel_standard((double)x,(double)x,115);
else
/* lgamma overflow */
return (float)__kernel_standard((double)x,(double)x,114);
} else
return y;
#endif
}
/programs/develop/libraries/menuetlibc/src/libmcoff/Makefile
0,0 → 1,17
include $(MENUETDEV)/osrules.mak
OUTFILE = libmcoff.a
OBJS = loadcoff.o section.o symtab.o relocate.o debug.o
CFLAGS = -O2 -fomit-frame-pointer -fno-common -DMCOFF_MENUETOS=1
 
_all: $(OUTFILE)
ifdef ON_MINGW
del $(MENUETDEV)\lib\$(OUTFILE)
copy $(OUTFILE) $(MENUETDEV)\lib
copy *.h $(MENUETDEV)\include\mcoff
else
rm -f $(MENUETDEV)/lib/$(OUTFILE)
cp $(OUTFILE) $(MENUETDEV)/lib
cp *.h $(MENUETDEV)/include/mcoff
endif
 
include $(MENUETDEV)/makefiles/Makefile_for_lib
/programs/develop/libraries/menuetlibc/src/libmcoff/_coff.h
0,0 → 1,315
#ifndef __MENUET_COFF_H
#define __MENUET_COFF_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
/********************** FILE HEADER **********************/
 
struct external_filehdr {
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
unsigned long f_timdat; /* time & date stamp */
unsigned long f_symptr; /* file pointer to symtab */
unsigned long f_nsyms; /* number of symtab entries */
unsigned short f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */
};
 
/* Bits for f_flags:
* F_RELFLG relocation info stripped from file
* F_EXEC file is executable (no unresolved external references)
* F_LNNO line numbers stripped from file
* F_LSYMS local symbols stripped from file
* F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
*/
 
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
 
#define I386MAGIC 0x14c
#define I386AIXMAGIC 0x175
#define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
 
#define FILHDR struct external_filehdr
#define FILHSZ sizeof(FILHDR)
 
/********************** AOUT "OPTIONAL HEADER" **********************/
 
typedef struct
{
unsigned short magic; /* type of file */
unsigned short vstamp; /* version stamp */
unsigned long tsize; /* text size in bytes, padded to FW bdry*/
unsigned long dsize; /* initialized data " " */
unsigned long bsize; /* uninitialized data " " */
unsigned long entry; /* entry pt. */
unsigned long text_start; /* base of text used for this file */
unsigned long data_start; /* base of data used for this file */
} AOUTHDR;
 
typedef struct gnu_aout {
unsigned long info;
unsigned long tsize;
unsigned long dsize;
unsigned long bsize;
unsigned long symsize;
unsigned long entry;
unsigned long txrel;
unsigned long dtrel;
} GNU_AOUT;
 
#define AOUTSZ (sizeof(AOUTHDR))
 
#define OMAGIC 0404 /* object files, eg as output */
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
#define STMAGIC 0401 /* target shlib */
#define SHMAGIC 0443 /* host shlib */
 
 
/********************** SECTION HEADER **********************/
 
struct external_scnhdr {
char s_name[8]; /* section name */
unsigned long s_paddr; /* physical address, aliased s_nlib */
unsigned long s_vaddr; /* virtual address */
unsigned long s_size; /* section size */
unsigned long s_scnptr; /* file ptr to raw data for section */
unsigned long s_relptr; /* file ptr to relocation */
unsigned long s_lnnoptr; /* file ptr to line numbers */
unsigned short s_nreloc; /* number of relocation entries */
unsigned short s_nlnno; /* number of line number entries*/
unsigned long s_flags; /* flags */
};
 
#define SCNHDR struct external_scnhdr
#define SCNHSZ sizeof(SCNHDR)
 
/*
* names of "special" sections
*/
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _COMMENT ".comment"
#define _LIB ".lib"
 
/*
* s_flags "type"
*/
#define STYP_TEXT (0x0020) /* section contains text only */
#define STYP_DATA (0x0040) /* section contains data only */
#define STYP_BSS (0x0080) /* section contains bss only */
 
/********************** LINE NUMBERS **********************/
 
/* 1 line number entry for every "breakpointable" source line in a section.
* Line numbers are grouped on a per function basis; first entry in a function
* grouping will have l_lnno = 0 and in place of physical address will be the
* symbol table index of the function name.
*/
struct external_lineno {
union {
unsigned long l_symndx __attribute__((packed)); /* function name symbol index, iff l_lnno == 0 */
unsigned long l_paddr __attribute__((packed)); /* (physical) address of line number */
} l_addr;
unsigned short l_lnno; /* line number */
};
 
 
#define LINENO struct external_lineno
#define LINESZ sizeof(LINENO)
 
 
/********************** SYMBOLS **********************/
 
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
 
struct external_syment
{
union {
char e_name[E_SYMNMLEN];
struct {
unsigned long e_zeroes __attribute__((packed));
unsigned long e_offset __attribute__((packed));
} e;
} e;
unsigned long e_value __attribute__((packed));
short e_scnum;
unsigned short e_type;
unsigned char e_sclass;
unsigned char e_numaux;
} __attribute__((packed));
 
#define N_BTMASK (0xf)
#define N_TMASK (0x30)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
union external_auxent
{
struct
{
unsigned long x_tagndx __attribute__((packed)); /* str, un, or enum tag indx */
union
{
struct
{
unsigned short x_lnno; /* declaration line number */
unsigned short x_size; /* str/union/array size */
} x_lnsz;
unsigned long x_fsize __attribute__((packed)); /* size of function */
} x_misc;
union
{
struct
{ /* if ISFCN, tag, or .bb */
unsigned long x_lnnoptr __attribute__((packed)); /* ptr to fcn line # */
unsigned long x_endndx __attribute__((packed)); /* entry ndx past block end */
} x_fcn;
struct { /* if ISARY, up to 4 dimen. */
unsigned short x_dimen[E_DIMNUM];
} x_ary;
} x_fcnary;
unsigned short x_tvndx; /* tv index */
} x_sym;
union
{
char x_fname[E_FILNMLEN];
struct
{
unsigned long x_zeroes __attribute__((packed));
unsigned long x_offset __attribute__((packed));
} x_n;
} x_file;
struct
{
unsigned long x_scnlen __attribute__((packed)); /* section length */
unsigned short x_nreloc; /* # relocation entries */
unsigned short x_nlinno; /* # line numbers */
} x_scn;
struct
{
unsigned long x_tvfill __attribute__((packed)); /* tv fill value */
unsigned short x_tvlen; /* length of .tv */
unsigned short x_tvran[2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
};
 
#define SYMENT struct external_syment
#define SYMESZ sizeof(SYMENT)
#define AUXENT union external_auxent
#define AUXESZ sizeof(AUXENT)
 
#define _ETEXT "etext"
 
/* Relocatable symbols have number of the section in which they are defined,
or one of the following: */
 
#define N_UNDEF ((short)0) /* undefined symbol */
#define N_ABS ((short)-1) /* value of symbol is absolute */
#define N_DEBUG ((short)-2) /* debugging symbol -- value is meaningless */
#define N_TV ((short)-3) /* indicates symbol needs preload transfer vector */
#define P_TV ((short)-4) /* indicates symbol needs postload transfer vector*/
 
/*
* Type of a symbol, in low N bits of the word
*/
#define T_NULL 0
#define T_VOID 1 /* function argument (only used by compiler) */
#define T_CHAR 2 /* character */
#define T_SHORT 3 /* short integer */
#define T_INT 4 /* integer */
#define T_LONG 5 /* long integer */
#define T_FLOAT 6 /* floating point */
#define T_DOUBLE 7 /* double word */
#define T_STRUCT 8 /* structure */
#define T_UNION 9 /* union */
#define T_ENUM 10 /* enumeration */
#define T_MOE 11 /* member of enumeration*/
#define T_UCHAR 12 /* unsigned character */
#define T_USHORT 13 /* unsigned short */
#define T_UINT 14 /* unsigned integer */
#define T_ULONG 15 /* unsigned long */
#define T_LNGDBL 16 /* long double */
 
/*
* derived types, in n_type
*/
#define DT_NON (0) /* no derived type */
#define DT_PTR (1) /* pointer */
#define DT_FCN (2) /* function */
#define DT_ARY (3) /* array */
 
#define BTYPE(x) ((x) & N_BTMASK)
 
#define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
#define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
#define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
#define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
 
/********************** STORAGE CLASSES **********************/
 
/* This used to be defined as -1, but now n_sclass is unsigned. */
#define C_EFCN 0xff /* physical end of function */
#define C_NULL 0
#define C_AUTO 1 /* automatic variable */
#define C_EXT 2 /* external symbol */
#define C_STAT 3 /* static */
#define C_REG 4 /* register variable */
#define C_EXTDEF 5 /* external definition */
#define C_LABEL 6 /* label */
#define C_ULABEL 7 /* undefined label */
#define C_MOS 8 /* member of structure */
#define C_ARG 9 /* function argument */
#define C_STRTAG 10 /* structure tag */
#define C_MOU 11 /* member of union */
#define C_UNTAG 12 /* union tag */
#define C_TPDEF 13 /* type definition */
#define C_USTATIC 14 /* undefined static */
#define C_ENTAG 15 /* enumeration tag */
#define C_MOE 16 /* member of enumeration */
#define C_REGPARM 17 /* register parameter */
#define C_FIELD 18 /* bit field */
#define C_AUTOARG 19 /* auto argument */
#define C_LASTENT 20 /* dummy entry (end of block) */
#define C_BLOCK 100 /* ".bb" or ".eb" */
#define C_FCN 101 /* ".bf" or ".ef" */
#define C_EOS 102 /* end of structure */
#define C_FILE 103 /* file name */
#define C_LINE 104 /* line # reformatted as symbol table entry */
#define C_ALIAS 105 /* duplicate tag */
#define C_HIDDEN 106 /* ext symbol in dmert public lib */
 
/********************** RELOCATION DIRECTIVES **********************/
 
struct external_reloc {
unsigned long r_vaddr __attribute__((packed));
unsigned long r_symndx __attribute__((packed));
unsigned short r_type;
};
 
 
#define RELOC struct external_reloc
#define RELSZ sizeof(RELOC)
 
#define RELOC_REL32 20 /* 32-bit PC-relative address */
#define RELOC_ADDR32 6 /* 32-bit absolute address */
 
#define DEFAULT_DATA_SECTION_ALIGNMENT 4
#define DEFAULT_BSS_SECTION_ALIGNMENT 4
#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
/* For new sections we havn't heard of before */
#define DEFAULT_SECTION_ALIGNMENT 4
 
#ifdef __cplusplus
}
#endif
 
#endif
/programs/develop/libraries/menuetlibc/src/libmcoff/debug.c
0,0 → 1,44
#include<stdio.h>
#include<stdarg.h>
 
#if (MCOFF_MENUETOS==1)
static int vdprintf_help(unsigned c)
{
int d0;
if(c=='\n')
{
c='\r';
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
c='\n';
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
return 0;
}
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c));
return 0 ;
}
 
static void xputs(char * p)
{
for(;*p;p++) vdprintf_help((*p)&0xff);
}
 
static char dbg_buf[1024];
 
void dprintf(const char * fmt,...)
{
va_list ap;
va_start(ap,fmt);
vsprintf(dbg_buf,fmt,ap);
va_end(ap);
xputs(dbg_buf);
}
 
#else
void dprintf(const char * fmt,...)
{
va_list ap;
va_start(ap,fmt);
vfprintf(stderr,fmt,ap);
va_end(ap);
}
#endif
/programs/develop/libraries/menuetlibc/src/libmcoff/loadcoff.c
0,0 → 1,190
#include"mcoff.h"
#include<stdio.h>
#include<stdlib.h>
#include"string.h"
 
#undef MCOFF_MENUETOS
#define MCOFF_MENUETOS 0
 
#if (MCOFF_MENUETOS==1)
struct systree_blk {
unsigned long cmd,pos,blks;
void * data,* work;
char name[128];
} __attribute__((packed));
 
static char systree_work[16384];
static char temp_block[512];
 
static struct systree_blk sblk={
0,
0,
1,
NULL,
systree_work,
};
 
static unsigned long open_on_path(char * pth,char * name)
{
int l;
int d0,d1;
l=strlen(pth);
if(!pth)
{
sprintf(sblk.name,"%s",pth);
} else {
if(pth[l]!='/')
sprintf(sblk.name,"%s/%s",pth,name);
else
sprintf(sblk.name,"%s%s",pth,name);
}
sblk.data=&temp_block;
sblk.cmd=0;
sblk.pos=0;
sblk.blks=1;
sblk.work=systree_work;
__asm__ __volatile__("int $0x40":"=a"(d0),"=b"(d1):"0"(58),"1"((void *)&sblk));
if(d0!=0) return 0;
return d1;
}
#endif
 
coffobj_t * mcoff_load_file(char * fname)
{
coffobj_t * obj;
int i;
#if (MCOFF_MENUETOS==1)
unsigned long sz;
#endif
obj=(coffobj_t *)malloc(sizeof(coffobj_t));
if(!obj)
{
dprintf("malloc error1\n");
return NULL;
}
#if (MCOFF_MENUETOS==0)
FILE * f=fopen(fname,"rb");
if(!f)
{
dprintf("Unable to open file\n");
free(obj);
return NULL;
}
dprintf("File opened\n");
fseek(f,0,SEEK_END);
dprintf("After seek to end\n");
obj->co_filesize=ftell(f);
dprintf("After ftell\n");
fseek(f,0,SEEK_SET);
dprintf("After seek to start\n");
dprintf("File size is %u bytes\n",obj->co_filesize);
#else
/* Special actions for MenuetOS, because it doesn't support relative paths */
/* We just search some paths if it is relative */
if(fname[0]!='/')
{
sz=open_on_path("/RD/1",fname);
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */
sz=open_on_path("/HD/1/MENUETOS",fname);
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */
sz=open_on_path("/HD/1/MENUETOS/DLL",fname);
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */
} else {
dprintf("Opening on std path\n");
sz=open_on_path("",fname);
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */
}
free(obj);
return NULL;
OK:
obj->co_filesize=sz;
dprintf("File size is %u bytes\n",sz);
#endif
obj->co_loadptr=(char *)malloc((obj->co_filesize+511)&~511);
if(!obj->co_loadptr)
{
dprintf("Unable to create file memory\n");
#if (MCOFF_MENUETOS==0)
fclose(f);
#endif
free(obj);
return NULL;
}
dprintf("Memory allocated\n");
#if (MCOFF_MENUETOS==0)
dprintf("Before fread\n");
fread(obj->co_loadptr,1,obj->co_filesize,f);
dprintf("After fread\n");
fclose(f);
dprintf("After fclose\n");
#else
sblk.cmd=0;
sblk.pos=0;
sblk.blks=((sz+511)&~511)/512;
sblk.data=obj->co_loadptr;
sblk.work=systree_work;
{
int d0,d1;
__asm__ __volatile__("int $0x40":"=a"(d0),"=b"(d1):"0"(58),"1"((void *)&sblk));
}
dprintf("Done reading file\n");
#endif
dprintf("Checking file\n");
obj->co_loadaddr=(unsigned long)obj->co_loadptr;
obj->co_filehdr=(FILHDR *)obj->co_loadaddr;
/* Check if file is really COFF */
if(I386BADMAG(*obj->co_filehdr))
{
dprintf("bad magic\n");
NOREL:
free(obj->co_loadptr);
free(obj);
return NULL;
}
/* We don't support files with relocations stripped */
/* if(obj->co_filehdr->f_flags & F_RELFLG)
{
printf("No relocation info\n");
goto NOREL;
} */
/* Get into section table, symbol table and string table */
obj->co_sections=(SCNHDR *)(obj->co_loadaddr+FILHSZ+obj->co_filehdr->f_opthdr);
obj->co_symtab=(SYMENT *)(obj->co_loadaddr+obj->co_filehdr->f_symptr);
obj->co_strtab=(char *)(obj->co_loadaddr+obj->co_filehdr->f_symptr+
SYMESZ*obj->co_filehdr->f_nsyms);
/* Setup .bss section */
{
SCNHDR * h;
h=obj->co_sections;
dprintf("Looking for bss...\n");
for(i=0;i<obj->co_filehdr->f_nscns;i++,h++)
{
unsigned long r;
if((h->s_flags & 0xE0)!=0x80) continue;
r=h->s_size;
obj->co_bssptr=(char *)malloc(r);
obj->co_bsssize=r;
if(!obj->co_bssptr)
{
dprintf("Unable to alloc %u bytes for bss\n",r);
free(obj->co_loadptr);
free(obj);
return NULL;
}
obj->co_bssaddr=(unsigned long)obj->co_bssptr;
h->s_scnptr=obj->co_bssaddr-obj->co_loadaddr;
obj->co_bsssectnum=i+1; /* So we don't have to do it later */
dprintf("BSS size=%u bytes\n",obj->co_bsssize);
}
}
NOBSS:
/* File is COFF. Just return obj */
return obj;
}
 
void unload_coff_file(coffobj_t * obj)
{
if(!obj) return;
free(obj->co_loadptr);
return;
}
/programs/develop/libraries/menuetlibc/src/libmcoff/mcoff.h
0,0 → 1,64
#ifndef __MENUETOS_MCOFF_H
#define __MENUETOS_MCOFF_H
 
#include"_coff.h"
 
typedef struct {
char * co_loadptr;
unsigned long co_loadaddr;
unsigned long co_filesize;
FILHDR * co_filehdr;
SCNHDR * co_sections;
SYMENT * co_symtab;
char * co_strtab;
char * co_bssptr;
unsigned long co_bssaddr;
unsigned long co_bsssize;
unsigned long co_bsssectnum;
} coffobj_t;
 
coffobj_t * mcoff_load_file(char * fname);
void unload_coff_file(coffobj_t * obj);
SCNHDR * find_section(char * name,coffobj_t * obj);
int read_section_data(coffobj_t * obj,SCNHDR * hdr,void ** readp);
SYMENT * find_coff_symbol(coffobj_t * obj,char * objname);
 
typedef int (* symlookupfn_t)(coffobj_t *,unsigned long *,unsigned long *,int);
int relocate_coff_file(coffobj_t * obj,symlookupfn_t lookupfn);
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val,
unsigned long * sym_sect,int index);
unsigned long mcoff_get_ref(coffobj_t * obj,char * symname);
 
/*
Your lookup function can be similar to this:
 
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val,
unsigned long * sym_sect,int index)
{
SYMENT * symtab,* lookup;
char xname[9];
char * symnamep;
symtab=obj->co_symtab+index;
*sym_sect=(unsigned long)symtab->e_scnum;
if(symtab->e_scnum>0)
{
*sym_val=symtab->e_value;
return 0;
}
if(symtab->e.e.e_zeroes==0)
{
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset);
} else {
symnamep=(char *)symtab->e.e_name;
memset(xname,0,9);
memcpy(xname,symnamep,8);
symnamep=xname;
}
lookup=find_coff_symbol(obj,symnamep);
if(!lookup) return -1;
*sym_val=lookup->e_value+obj->co_sections[lookup->e_scnum-1].s_scnptr+obj->co_loadaddr;
return 0;
}
*/
 
#endif
/programs/develop/libraries/menuetlibc/src/libmcoff/relocate.c
0,0 → 1,91
#include"mcoff.h"
#include<stdlib.h>
#include"string.h"
 
static int do_coff_relocation(coffobj_t * obj,unsigned long relno,
SCNHDR * sect,symlookupfn_t lookup_fn)
{
int r_delta,t_delta=0;
unsigned long sym_val,sym_sect;
unsigned long * where;
int err;
RELOC * rel;
r_delta=obj->co_loadaddr+sect->s_scnptr-sect->s_vaddr;
rel=((RELOC *)(obj->co_loadaddr+sect->s_relptr))+relno;
where=(unsigned long *)(r_delta+rel->r_vaddr);
err=lookup_fn(obj,&sym_val,&sym_sect,rel->r_symndx);
if(err!=0)
{
printf("Unable to find symbol relno=%u\n",relno);
return err;
}
if(sym_sect!=0)
{
sect=&obj->co_sections[sym_sect-1];
t_delta=obj->co_loadaddr+sect->s_scnptr-sect->s_vaddr;
}
switch(rel->r_type)
{
case RELOC_ADDR32:
if(!sym_sect)
*where=sym_val;
else
*where+=t_delta;
break;
case RELOC_REL32:
if(!sym_sect)
*where+=sym_val-r_delta;
else
*where+=t_delta-r_delta;
break;
default:
printf("Invalid relocation type\n");
return -1;
}
return 0;
}
 
int relocate_coff_file(coffobj_t * obj,symlookupfn_t lookupfn)
{
int s,r;
for(s=0;s<obj->co_filehdr->f_nscns;s++)
{
for(r=0;r<obj->co_sections[s].s_nreloc;r++)
{
if(do_coff_relocation(
obj,
r,
&obj->co_sections[s],
lookupfn)!=0) return -1;
}
}
return 0;
}
 
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val,
unsigned long * sym_sect,int index)
{
SYMENT * symtab,* lookup;
char xname[9];
char * symnamep;
symtab=obj->co_symtab+index;
*sym_sect=(unsigned long)symtab->e_scnum;
if(symtab->e_scnum>0)
{
*sym_val=symtab->e_value;
return 0;
}
if(symtab->e.e.e_zeroes==0)
{
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset);
} else {
symnamep=(char *)symtab->e.e_name;
memset(xname,0,9);
memcpy(xname,symnamep,8);
symnamep=xname;
}
lookup=find_coff_symbol(obj,symnamep);
if(!lookup) return -1;
*sym_val=lookup->e_value+obj->co_sections[lookup->e_scnum-1].s_scnptr+obj->co_loadaddr;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libmcoff/section.c
0,0 → 1,26
#include"mcoff.h"
#include"string.h"
#include<stdlib.h>
 
SCNHDR * find_section(char * name,coffobj_t * obj)
{
char newname[9];
int i,j;
if(!name || !obj) return NULL;
memset(newname,0,9);
memcpy(newname,name,8);
j=strlen(newname);
for(i=0;i<obj->co_filehdr->f_nscns;i++)
{
if(!strncmp(obj->co_sections[i].s_name,newname,j)) return &obj->co_sections[i];
}
return NULL;
}
 
int read_section_data(coffobj_t * obj,SCNHDR * hdr,void ** readp)
{
*readp=malloc(hdr->s_size);
if(!(*readp)) return -1;
memcpy(*readp,obj->co_loadptr+hdr->s_scnptr,hdr->s_size);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libmcoff/symtab.c
0,0 → 1,48
#include"mcoff.h"
#include<stdlib.h>
#include"string.h"
 
/* static inline void nprintf(char * s,int n)
{
printf("nprintf(%u, '",n);
for(;n;n--)
putch(*s++);
printf("')");
} */
 
SYMENT * find_coff_symbol(coffobj_t * obj,char * objname)
{
int namelen;
int symno;
int xlen;
SYMENT * symtab;
char * symnamep,symnamelen;
symtab=obj->co_symtab;
namelen=strlen(objname);
for(symno=0;symno<obj->co_filehdr->f_nsyms;symno++,symtab++)
{
if(symtab->e.e.e_zeroes==0)
{
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset);
symnamelen=strlen(symnamep);
/* printf("strtab=%u %x %u ",symtab->e.e.e_offset,symnamep,symnamelen); */
} else {
symnamep=(char *)symtab->e.e_name;
symnamelen=strlen(symnamep);
if(symnamelen>E_SYMNMLEN)
symnamelen=E_SYMNMLEN;
}
/* nprintf(symnamep,symnamelen);
printf("\n"); */
if(symtab->e_scnum!=0 && namelen==symnamelen && !strncmp(objname,symnamep,namelen))
return symtab;
}
return NULL;
}
 
unsigned long mcoff_get_ref(coffobj_t * obj,char * symname)
{
SYMENT * sym=find_coff_symbol(obj,symname);
if(!sym) return 0;
return sym->e_value+obj->co_sections[sym->e_scnum-1].s_scnptr+obj->co_loadaddr;
}
/programs/develop/libraries/menuetlibc/src/libmgfx/Makefile
0,0 → 1,38
THIS_SRCS = format.c load_image.c readjpeg.c libinit.c
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
ifdef ON_MINGW
mk_lib: gen_tmp all
make -f Makefile-link OUTFILE="libmgfx.a"
copy libmgfx.a $(MENUETDEV)\lib
del libmgfx.a
 
dll: _gen_tmp all
make -f Makefile-link-dll OUTFILE="mgfx.so"
copy mgfx.so $(MENUETDEV)\lib
del mgfx.so
 
_gen_tmp:
@$(D_ECHO) > ..\tmp_make
 
gen_tmp:
@echo foo = bar> ..\tmp_make
@..\m_echo ..\tmp_make B_MENUET_LIBC_OBJS =
 
else
 
mk_lib: gen_tmp all
make -f Makefile-link OUTFILE="libmgfx.a"
mv -f libmgfx.a $(MENUETDEV)/lib
 
dll: _gen_tmp all
make -f Makefile-link-dll OUTFILE="mgfx.so"
mv -f mgfx.so $(MENUETDEV)/lib
 
_gen_tmp:
@$(D_ECHO) > ../tmp_make
 
gen_tmp:
@echo "foo = bar" > ../tmp_make
@../m_echo ../tmp_make B_MENUET_LIBC_OBJS =
endif
/programs/develop/libraries/menuetlibc/src/libmgfx/Makefile-link
0,0 → 1,4
include ../tmp_make
 
all:
ar rcs $(OUTFILE) $(B_MENUET_LIBC_OBJS)
/programs/develop/libraries/menuetlibc/src/libmgfx/copying
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/programs/develop/libraries/menuetlibc/src/libmgfx/format.c
0,0 → 1,30
#include <string.h>
#include"libmgfx.h"
 
static struct mgfx_image_format * the_fmts=NULL;
 
void register_image_format(struct mgfx_image_format * fmt)
{
fmt->next=the_fmts;
the_fmts=fmt;
}
 
struct mgfx_image_format * get_image_format(char * fname)
{
char * p;
int j;
struct mgfx_image_format * fmt;
if(!the_fmts) return NULL;
p=strstr(fname,".");
if(!p) return NULL;
p++;
j=strlen(p);
if(!j) return NULL;
strlwr(p);
for(fmt=the_fmts;fmt;fmt=fmt->next)
{
if(strlen(fmt->fmt_ext)==j)
if(!strncmp(p,fmt->fmt_ext,j)) return fmt;
}
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libmgfx/libinit.c
0,0 → 1,6
#include"libmgfx.h"
 
void init_mgfx_library(void)
{
mgfx_register_jpeg();
}
/programs/develop/libraries/menuetlibc/src/libmgfx/libmgfx.h
0,0 → 1,48
#ifndef __LIBMGFX_H
#define __LIBMGFX_H
 
#include<menuet/os.h>
#include<stdlib.h>
#include<stdio.h>
/* #include<string.h> */
 
typedef unsigned char byte;
 
typedef struct {
int width,height;
int bpp;
byte * the_image;
byte * pal;
struct mgfx_image_format * fmt;
} mgfx_image_t;
 
struct mgfx_image_format {
char * format_name;
char * fmt_ext;
int (* load_fn)(FILE * f,mgfx_image_t *);
struct mgfx_image_format * next;
};
 
void register_image_format(struct mgfx_image_format * fmt);
struct mgfx_image_format * get_image_format(char * fname);
 
#define _PIC_OK 0
#define _PICERR_NOFILE -1
#define _PICERR_NOMEM -2
#define _PICERR_BADMAGIC -3
#define _PICERR_NOCOLOURMAP -4
#define _PICERR_NOIMAGE -5
#define _PICERR_UNSUPPORTED -6
#define _PICERR_CORRUPT -7
#define _PICERR_SHOWN_ALREADY -8
#define _PICERR_ISRLE -9
 
int load_image(char * fname,mgfx_image_t ** the_img);
void free_image(mgfx_image_t * img);
void paint_image(int x,int y,mgfx_image_t * img);
 
void mgfx_register_jpeg(void);
 
void init_mgfx_library(void);
 
#endif
/programs/develop/libraries/menuetlibc/src/libmgfx/load_image.c
0,0 → 1,62
#include"libmgfx.h"
 
int load_image(char * fname,mgfx_image_t ** the_img)
{
FILE * f;
struct mgfx_image_format * fmt;
mgfx_image_t * img;
int __ret;
if(!(img=(mgfx_image_t *)malloc(sizeof(mgfx_image_t))))
return _PICERR_NOMEM;
if(!(fmt=get_image_format(fname)))
return _PICERR_UNSUPPORTED;
f=fopen(fname,"rb");
if(!f) return _PICERR_NOFILE;
img->fmt=fmt;
__ret=fmt->load_fn(f,img);
if(__ret==_PIC_OK)
{
*the_img=img;
} else {
*the_img=NULL;
free(img);
}
fclose(f);
return __ret;
}
 
int load_image_f(char * fname,FILE * f,mgfx_image_t ** the_img)
{
struct mgfx_image_format * fmt;
mgfx_image_t * img;
int __ret;
if(!(img=(mgfx_image_t *)malloc(sizeof(mgfx_image_t))))
return _PICERR_NOMEM;
if(!(fmt=get_image_format(fname)))
return _PICERR_UNSUPPORTED;
img->fmt=fmt;
__ret=fmt->load_fn(f,img);
if(__ret==_PIC_OK)
{
*the_img=img;
} else {
*the_img=NULL;
free(img);
}
fclose(f);
return __ret;
}
 
void free_image(mgfx_image_t * img)
{
if(img)
{
free(img->the_image);
}
}
 
void paint_image(int x,int y,mgfx_image_t * img)
{
if(!img || img->bpp!=24) return;
__menuet__putimage(x,y,img->width,img->height,img->the_image);
}
/programs/develop/libraries/menuetlibc/src/libmgfx/readjpeg.c
0,0 → 1,137
/* Zgv v2.7 - GIF, JPEG and PBM/PGM/PPM viewer, for VGA PCs running Linux.
* Copyright (C) 1993-1995 Russell Marks. See README for license details.
*
* readjpeg.c - interface to the IJG's JPEG software, derived from
* their example.c.
*/
 
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <setjmp.h>
#include <sys/file.h> /* for open et al */
#include <jpeglib.h>
#include "libmgfx.h"
 
static mgfx_image_t * the_image;
static FILE * global_jpeg_infile;
static struct jpeg_decompress_struct cinfo;
 
struct my_error_mgr
{
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
 
typedef struct my_error_mgr * my_error_ptr;
 
static void jpegerr(char *msgtext)
{
}
 
static void my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr=(my_error_ptr) cinfo->err;
char buf[JMSG_LENGTH_MAX];
(*cinfo->err->format_message)(cinfo,buf);
jpegerr(buf);
longjmp(myerr->setjmp_buffer, 1);
}
 
static void my_output_message(j_common_ptr cinfo)
{
}
 
static void aborted_file_jpeg_cleanup()
{
jpeg_destroy_decompress(&cinfo);
fclose(global_jpeg_infile);
}
 
int read_JPEG_file(FILE * in,mgfx_image_t * img)
{
struct my_error_mgr jerr;
int row_stride;
int tmp,f;
unsigned char *ptr;
the_image=img;
if((img->pal=(byte *)malloc(768))==NULL) return(_PICERR_NOMEM);
cinfo.err=jpeg_std_error(&jerr.pub);
jerr.pub.error_exit=my_error_exit;
jerr.pub.output_message=my_output_message;
if(setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_decompress(&cinfo);
free(img->pal);
return(_PICERR_CORRUPT);
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo,in);
jpeg_read_header(&cinfo,TRUE);
cinfo.dct_method=JDCT_FLOAT;
img->bpp=24;
if(cinfo.jpeg_color_space==JCS_GRAYSCALE)
{
cinfo.out_color_space=JCS_GRAYSCALE;
cinfo.desired_number_of_colors=256;
cinfo.quantize_colors=FALSE;
cinfo.two_pass_quantize=FALSE;
img->bpp=8;
for(f=0;f<256;f++)
img->pal[f]=img->pal[256+f]=img->pal[512+f]=f;
}
img->width=cinfo.image_width;
img->height=cinfo.image_height;
img->the_image=(byte *)malloc(((img->bpp+7)/8)*img->width*img->height);
if(img->the_image==NULL)
{
jpegerr("Out of memory");
longjmp(jerr.setjmp_buffer,1);
}
jpeg_start_decompress(&cinfo);
if(img->bpp==8 && cinfo.jpeg_color_space!=JCS_GRAYSCALE)
for(f=0;f<cinfo.actual_number_of_colors;f++)
{
img->pal[ f]=cinfo.colormap[0][f];
img->pal[256+f]=cinfo.colormap[1][f];
img->pal[512+f]=cinfo.colormap[2][f];
}
ptr=img->the_image;
row_stride=((img->bpp+7)/8)*img->width;
if(img->bpp==8)
while(cinfo.output_scanline<img->height)
{
jpeg_read_scanlines(&cinfo,&ptr,1);
ptr+=row_stride;
}
else
while(cinfo.output_scanline<img->height)
{
jpeg_read_scanlines(&cinfo,&ptr,1);
for(f=0;f<img->width;f++) { tmp=*ptr; *ptr=ptr[2]; ptr[2]=tmp; ptr+=3; }
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return(_PIC_OK);
}
 
static struct mgfx_image_format this_fmt_1={
"JPEG",
"jpg",
read_JPEG_file,
NULL,
};
 
static struct mgfx_image_format this_fmt_2={
"JPEG",
"jpeg",
read_JPEG_file,
NULL,
};
 
void mgfx_register_jpeg(void)
{
register_image_format(&this_fmt_1);
register_image_format(&this_fmt_2);
}
/programs/develop/libraries/menuetlibc/src/libmgfx/readme
0,0 → 1,5
This is file for handling various graphics formats. Most of this stuff
was mercilessly stolen from ZGV image viewer :)))
 
Thanks to:
- Russell Marks for ZGV viewer
/programs/develop/libraries/menuetlibc/src/m_echo.c
0,0 → 1,12
#include<stdio.h>
 
int main(int argc,char * argv[])
{
int i;
FILE * f;
f=fopen(argv[1],"a");
if(!f) return -1;
for(i=2;i<argc;i++) fprintf(f,"%s ",argv[i]);
fclose(f);
return 0;
}
/programs/develop/libraries/menuetlibc/src/mks.c
0,0 → 1,17
#include<stdio.h>
#include<string.h>
 
static char tmp_buf[1024];
 
int main(int argc,char * argv[])
{
printf("CREATE %s\n",argv[1]);
while(!feof(stdin))
{
fscanf(stdin,"%s ",&tmp_buf);
printf("ADDMOD %s\n",tmp_buf);
}
printf("SAVE\n");
printf("END\n");
return 0;
}