/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(;;); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/ansi/errno/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = errno.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/ansi/errno/errno.c |
---|
0,0 → 1,6 |
int errno; |
int __isatty(int _fd) |
{ |
return 1; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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_; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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'); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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] |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 *); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 *); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)"; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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[]; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]); |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]); |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 }; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/compat/io/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = chsize.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/compat/mman/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = mprotect.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/compat/mntent/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = mntent.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/stat/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = mknod.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/vfs/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = statfs.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 *); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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. |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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! |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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](); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
{ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/dos/errno/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = doserr2e.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 *)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 *)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/timeb/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = ftime.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/emu_layer/Makefile |
---|
0,0 → 1,9 |
SUBDIRS = |
all: process_subdirs |
process_subdirs: |
clean: |
depend: |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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++); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/net/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = socket.c stack.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/farptr/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = farptr.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/pc_hw/sound/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = sound.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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);*/ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/posix/fnmatch/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = fnmatch.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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, "" |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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, |
}; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 ========= */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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®_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®_NOSUB) |
nmatch = 0; |
if (eflags®_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®_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®_NOTBOL)) || |
(sp < m->endp && *(sp-1) == '\n' && |
(m->g->cflags®_NEWLINE)) ) |
{ /* yes */ } |
else |
return(NULL); |
break; |
case OEOL: |
if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || |
(sp < m->endp && *sp == '\n' && |
(m->g->cflags®_NEWLINE)) ) |
{ /* yes */ } |
else |
return(NULL); |
break; |
case OBOW: |
if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || |
(sp < m->endp && *(sp-1) == '\n' && |
(m->g->cflags®_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®_NOTEOL)) || |
(sp < m->endp && *sp == '\n' && |
(m->g->cflags®_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®_NEWLINE) || |
(lastc == OUT && !(m->eflags®_NOTBOL)) ) { |
flagch = BOL; |
i = m->g->nbol; |
} |
if ( (c == '\n' && m->g->cflags®_NEWLINE) || |
(c == OUT && !(m->eflags®_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®_NEWLINE) || |
(lastc == OUT && !(m->eflags®_NOTBOL)) ) { |
flagch = BOL; |
i = m->g->nbol; |
} |
if ( (c == '\n' && m->g->cflags®_NEWLINE) || |
(c == OUT && !(m->eflags®_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®_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®_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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 ========= */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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®_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®_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®_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)®_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®_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)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 ========= */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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®_EXTENDED) && (cflags®_NOSPEC)) |
return(REG_INVARG); |
if (cflags®_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®_EXTENDED) |
p_ere(p, OUT); |
else if (cflags®_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®_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®_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®_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®_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®_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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 ========= */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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®_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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 ========= */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) == '_') |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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®_LARGE)) |
return(smatcher(g, (char *)string, nmatch, pmatch, eflags)); |
else |
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags)); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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]); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/posix/sys/times/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = times.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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"; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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 */ |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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(); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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) |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/posix/utime/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = utime.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/posix/utsname/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = uname.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/programs/develop/libraries/menuetlibc/src/libc/termios/Makefile |
---|
0,0 → 1,3 |
THIS_SRCS = hooks.c |
include $(MENUET_LIBC_TOPDIR)/Make.rules |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/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; |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |