From ed084664644cfbd0ea5e1795f0af1cf5449c9476 Mon Sep 17 00:00:00 2001 From: Boudewijn Dekker Date: Wed, 14 Apr 1999 21:27:02 +0000 Subject: [PATCH] Added various files. --> failed to pass test printing a simple string svn path=/trunk/; revision=380 --- reactos/lib/crtdll/conio/cscanf.c | 4 +- reactos/lib/crtdll/crt_specs | 4 +- reactos/lib/crtdll/crtdll.def | 170 +--- reactos/lib/crtdll/direct/chdir.c | 9 +- reactos/lib/crtdll/direct/getcwd.c | 6 - reactos/lib/crtdll/direct/getdcwd.c | 22 + reactos/lib/crtdll/direct/mkdir.c | 6 +- reactos/lib/crtdll/direct/rmdir.c | 6 +- reactos/lib/crtdll/except/unwind.c | 11 + reactos/lib/crtdll/float/isnan.c | 17 +- reactos/lib/crtdll/makefile | 6 +- reactos/lib/crtdll/math/modf.c | 11 + reactos/lib/crtdll/mbstring/hanzen.c | 19 + reactos/lib/crtdll/mbstring/islead.c | 7 + reactos/lib/crtdll/mbstring/ismblead.c | 29 + reactos/lib/crtdll/mbstring/ismbtrail.c | 29 + reactos/lib/crtdll/mbstring/mbbtombc.c | 29 + reactos/lib/crtdll/mbstring/mbbtype.c | 48 + reactos/lib/crtdll/mbstring/mbccpy.c | 9 + reactos/lib/crtdll/mbstring/mbclen.c | 19 + reactos/lib/crtdll/mbstring/mbscat.c | 4 + reactos/lib/crtdll/mbstring/mbschr.c | 4 + reactos/lib/crtdll/mbstring/mbscmp.c | 6 + reactos/lib/crtdll/mbstring/mbscoll.c | 16 + reactos/lib/crtdll/mbstring/mbscpy.c | 5 + reactos/lib/crtdll/mbstring/mbscspn.c | 4 + reactos/lib/crtdll/mbstring/mbsdec.c | 6 + reactos/lib/crtdll/mbstring/mbsdup.c | 4 + reactos/lib/crtdll/mbstring/mbsicmp.c | 4 + reactos/lib/crtdll/mbstring/mbsicoll.c | 4 + reactos/lib/crtdll/mbstring/mbsinc.c | 7 + reactos/lib/crtdll/mbstring/mbslen.c | 11 + reactos/lib/crtdll/mbstring/mbslwr.c | 18 + reactos/lib/crtdll/mbstring/mbsncat.c | 56 ++ reactos/lib/crtdll/mbstring/mbsnccnt.c | 15 + reactos/lib/crtdll/mbstring/mbsncmp.c | 47 + reactos/lib/crtdll/mbstring/mbsncoll.c | 42 + reactos/lib/crtdll/mbstring/mbsncpy.c | 43 + reactos/lib/crtdll/mbstring/mbsninc.c | 11 + reactos/lib/crtdll/mbstring/mbsnset.c | 66 ++ reactos/lib/crtdll/mbstring/mbsrchr.c | 41 + reactos/lib/crtdll/mbstring/mbsrev.c | 4 + reactos/lib/crtdll/mbstring/mbsset.c | 35 + reactos/lib/crtdll/mbstring/mbsstr.c | 4 + reactos/lib/crtdll/mbstring/mbstok.c | 4 + reactos/lib/crtdll/mbstring/mbsupr.c | 18 + reactos/lib/crtdll/misc/amsg.c | 13 + reactos/lib/crtdll/misc/initter.c | 7 + reactos/lib/crtdll/misc/initterm.c | 21 + reactos/lib/crtdll/misc/setnew.cc | 5 +- reactos/lib/crtdll/process/dll.c | 10 + reactos/lib/crtdll/process/spawnve.c | 267 +++++- reactos/lib/crtdll/process/thread.c | 26 + reactos/lib/crtdll/setjmp/setjmp.c | 143 +++ reactos/lib/crtdll/signal/signal.c | 5 +- reactos/lib/crtdll/signal/xcptfil.c | 10 + reactos/lib/crtdll/signal/xcptinfo.c | 4 + reactos/lib/crtdll/stdio/clearerr.c | 4 + reactos/lib/crtdll/stdio/doprnt.c | 320 ------- reactos/lib/crtdll/stdio/fclose.c | 15 +- reactos/lib/crtdll/stdio/fdopen.c | 3 + reactos/lib/crtdll/stdio/fgetc.c | 4 +- reactos/lib/crtdll/stdio/filbuf.c | 27 +- reactos/lib/crtdll/stdio/flsbuf.c | 16 +- reactos/lib/crtdll/stdio/fprintf.c | 4 +- reactos/lib/crtdll/stdio/fputc.c | 7 +- reactos/lib/crtdll/stdio/fread.c | 1 - reactos/lib/crtdll/stdio/fscanf.c | 69 +- reactos/lib/crtdll/stdio/fseek.c | 1 - reactos/lib/crtdll/stdio/getc.c | 24 +- reactos/lib/crtdll/stdio/printf.c | 52 +- reactos/lib/crtdll/stdio/putc.c | 49 +- reactos/lib/crtdll/stdio/scanf.c | 82 +- reactos/lib/crtdll/stdio/setvbuf.c | 1 - reactos/lib/crtdll/stdio/sprintf.c | 2 +- reactos/lib/crtdll/stdio/sscanf.c | 94 +- reactos/lib/crtdll/stdio/stdhnd.c | 12 +- reactos/lib/crtdll/stdio/ungetc.c | 24 +- reactos/lib/crtdll/stdio/vfprintf.c | 904 ++++++++++++++++++- reactos/lib/crtdll/stdio/vfscanf.c | 1081 +++++++++++++++++++++++ reactos/lib/crtdll/stdio/vprintf.c | 38 +- reactos/lib/crtdll/stdio/vscanf.c | 35 + reactos/lib/crtdll/stdio/vsprintf.c | 3 +- reactos/lib/crtdll/stdio/vsscanf.c | 57 ++ reactos/lib/crtdll/stdlib/malloc.c | 20 +- reactos/lib/crtdll/stdlib/rot.c | 56 ++ reactos/lib/crtdll/string/strcoll.c | 18 +- reactos/lib/crtdll/string/strxfrm.c | 33 +- reactos/lib/crtdll/sys_stat/futime.c | 16 + reactos/lib/crtdll/wchar/wcscat.c | 16 +- reactos/lib/crtdll/wchar/wcscoll.c | 18 +- reactos/lib/crtdll/wchar/wcsdup.c | 6 +- reactos/lib/crtdll/wchar/wcslen.c | 2 + reactos/lib/crtdll/wchar/wcsncat.c | 31 +- reactos/lib/crtdll/wchar/wcsncpy.c | 2 +- reactos/lib/crtdll/wchar/wcspbrk.c | 5 + reactos/lib/crtdll/wchar/wcsset.c | 27 + reactos/lib/crtdll/wchar/wcsspn.c | 2 +- reactos/lib/crtdll/wchar/wcstod.c | 6 + reactos/lib/crtdll/wchar/wcstok.c | 2 +- reactos/lib/crtdll/wchar/wcstombs.c | 8 +- reactos/lib/crtdll/wchar/wcsxfrm.c | 21 +- 102 files changed, 3878 insertions(+), 791 deletions(-) create mode 100644 reactos/lib/crtdll/direct/getdcwd.c create mode 100644 reactos/lib/crtdll/except/unwind.c create mode 100644 reactos/lib/crtdll/mbstring/hanzen.c create mode 100644 reactos/lib/crtdll/mbstring/islead.c create mode 100644 reactos/lib/crtdll/mbstring/ismblead.c create mode 100644 reactos/lib/crtdll/mbstring/ismbtrail.c create mode 100644 reactos/lib/crtdll/mbstring/mbbtombc.c create mode 100644 reactos/lib/crtdll/mbstring/mbbtype.c create mode 100644 reactos/lib/crtdll/mbstring/mbccpy.c create mode 100644 reactos/lib/crtdll/mbstring/mbclen.c create mode 100644 reactos/lib/crtdll/mbstring/mbscat.c create mode 100644 reactos/lib/crtdll/mbstring/mbschr.c create mode 100644 reactos/lib/crtdll/mbstring/mbscmp.c create mode 100644 reactos/lib/crtdll/mbstring/mbscoll.c create mode 100644 reactos/lib/crtdll/mbstring/mbscpy.c create mode 100644 reactos/lib/crtdll/mbstring/mbscspn.c create mode 100644 reactos/lib/crtdll/mbstring/mbsdec.c create mode 100644 reactos/lib/crtdll/mbstring/mbsdup.c create mode 100644 reactos/lib/crtdll/mbstring/mbsicmp.c create mode 100644 reactos/lib/crtdll/mbstring/mbsicoll.c create mode 100644 reactos/lib/crtdll/mbstring/mbsinc.c create mode 100644 reactos/lib/crtdll/mbstring/mbslen.c create mode 100644 reactos/lib/crtdll/mbstring/mbslwr.c create mode 100644 reactos/lib/crtdll/mbstring/mbsncat.c create mode 100644 reactos/lib/crtdll/mbstring/mbsnccnt.c create mode 100644 reactos/lib/crtdll/mbstring/mbsncmp.c create mode 100644 reactos/lib/crtdll/mbstring/mbsncoll.c create mode 100644 reactos/lib/crtdll/mbstring/mbsncpy.c create mode 100644 reactos/lib/crtdll/mbstring/mbsninc.c create mode 100644 reactos/lib/crtdll/mbstring/mbsnset.c create mode 100644 reactos/lib/crtdll/mbstring/mbsrchr.c create mode 100644 reactos/lib/crtdll/mbstring/mbsrev.c create mode 100644 reactos/lib/crtdll/mbstring/mbsset.c create mode 100644 reactos/lib/crtdll/mbstring/mbsstr.c create mode 100644 reactos/lib/crtdll/mbstring/mbstok.c create mode 100644 reactos/lib/crtdll/mbstring/mbsupr.c create mode 100644 reactos/lib/crtdll/misc/amsg.c create mode 100644 reactos/lib/crtdll/misc/initter.c create mode 100644 reactos/lib/crtdll/misc/initterm.c create mode 100644 reactos/lib/crtdll/process/thread.c create mode 100644 reactos/lib/crtdll/setjmp/setjmp.c create mode 100644 reactos/lib/crtdll/signal/xcptfil.c create mode 100644 reactos/lib/crtdll/signal/xcptinfo.c delete mode 100644 reactos/lib/crtdll/stdio/doprnt.c create mode 100644 reactos/lib/crtdll/stdio/vfscanf.c create mode 100644 reactos/lib/crtdll/stdio/vscanf.c create mode 100644 reactos/lib/crtdll/stdio/vsscanf.c create mode 100644 reactos/lib/crtdll/stdlib/rot.c create mode 100644 reactos/lib/crtdll/sys_stat/futime.c create mode 100644 reactos/lib/crtdll/wchar/wcspbrk.c create mode 100644 reactos/lib/crtdll/wchar/wcsset.c create mode 100644 reactos/lib/crtdll/wchar/wcstod.c diff --git a/reactos/lib/crtdll/conio/cscanf.c b/reactos/lib/crtdll/conio/cscanf.c index 9950519a28d..9382011771d 100644 --- a/reactos/lib/crtdll/conio/cscanf.c +++ b/reactos/lib/crtdll/conio/cscanf.c @@ -19,8 +19,8 @@ _scan_ungetch(int c, FILE *fp) int _cscanf(const char *fmt, ...) { - return(_doscan_low(NULL, _scan_getche, _scan_ungetch, - fmt, (void **) unconst( ((&fmt)+1), char ** ))); +// return(_doscan_low(NULL, _scan_getche, _scan_ungetch, +// fmt, (void **) unconst( ((&fmt)+1), char ** ))); } diff --git a/reactos/lib/crtdll/crt_specs b/reactos/lib/crtdll/crt_specs index 21561c2bed3..81539eee5ca 100644 --- a/reactos/lib/crtdll/crt_specs +++ b/reactos/lib/crtdll/crt_specs @@ -38,10 +38,10 @@ -Di386 -D_WIN32 -DWIN32 -D__WIN32__ -D__MINGW32__ -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) _D_stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386) *cross_compile: -1 +0 *version: -egcs-2.91.57 +egcs-2.8.2 *multilib: . ; diff --git a/reactos/lib/crtdll/crtdll.def b/reactos/lib/crtdll/crtdll.def index 43826217acb..5cab39c4767 100644 --- a/reactos/lib/crtdll/crtdll.def +++ b/reactos/lib/crtdll/crtdll.def @@ -17,9 +17,9 @@ ; DISCLAMED. This includes but is not limited to warrenties of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ; -; $Revision: 1.6 $ -; $Author: dwelch $ -; $Date: 1999/04/14 00:51:18 $ +; $Revision: 1.7 $ +; $Author: ariadne $ +; $Date: 1999/04/14 21:26:48 $ ; ; These three functions appear to be name mangled in some way, so GCC is ; probably not going to be able to use them in any case. @@ -35,170 +35,6 @@ ; _set_new_handler__FPFUi_i ; ; -; These are functions for which I have not yet written prototypes or -; otherwise set up (they are still included below though unlike those -; first three). -; -; _CIacos -; _CIasin -; _CIatan -; _CIatan2 -; _CIcos -; _CIcosh -; _CIexp -; _CIfmod -; _CIlog -; _CIlog10 -; _CIpow -; _CIsin -; _CIsinh -; _CIsqrt -; _CItan -; _CItanh -; __dllonexit -; __mb_cur_max_dll -; __threadhandle -; __threadid -; _abnormal_termination -; _acmdln_dll -; _aexit_rtn_dll -; _amsg_exit -; _commit -; _commode_dll -; _cpumode_dll -; _ctype -; _daylight_dll -; _environ_dll -; _expand -; _fcloseall -; _filbuf -; _fileinfo_dll -; _flsbuf -; _flushall -; _fmode_dll -; _fpieee_flt -; _fsopen -; _ftol -; _getdiskfree -; _getdllprocaddr -; _getdrive -; _getdrives -; _getsystime -; _getw -; _initterm -; _ismbbalnum -; _ismbbalpha -; _ismbbgraph -; _ismbbkalnum -; _ismbbkana -; _ismbbkpunct -; _ismbblead -; _ismbbprint -; _ismbbpunct -; _ismbbtrail -; _ismbcalpha -; _ismbcdigit -; _ismbchira -; _ismbckata -; _ismbcl0 -; _ismbcl1 -; _ismbcl2 -; _ismbclegal -; _ismbclower -; _ismbcprint -; _ismbcspace -; _ismbcsymbol -; _ismbcupper -; _ismbslead -; _ismbstrail -; _lfind -; _loaddll -; _lrotl -; _lrotr -; _lsearch -; _makepath -; _matherr -; _mbbtombc -; _mbbtype -; _mbccpy -; _mbcjistojms -; _mbcjmstojis -; _mbclen -; _mbctohira -; _mbctokata -; _mbctolower -; _mbctombb -; _mbctoupper -; _mbctype -; _mbsbtype -; _mbscat -; _mbscmp -; _mbscpy -; _mbscspn -; _mbsdec -; _mbsdup -; _mbsicmp -; _mbsinc -; _mbslen -; _mbslwr -; _mbsnbcat -; _mbsnbcmp -; _mbsnbcnt -; _mbsnbcpy -; _mbsnbicmp -; _mbsnbset -; _mbsnccnt -; _mbsncmp -; _mbsncpy -; _mbsnextc -; _mbsnicmp -; _mbsninc -; _mbsnset -; _mbspbrk -; _mbsrchr -; _mbsrev -; _mbsset -; _mbsspn -; _mbsspnp -; _mbsstr -; _mbstrlen -; _mbsupr -; _onexit -; _osver_dll -; _osversion_dll -; _pctype_dll -; _purecall -; _putw -; _pwctype_dll -; _rmtmp -; _rotl -; _rotr -; _setsystime -; _snprintf -; _snwprintf -; _splitpath -; _strdate -; _strdec -; _strinc -; _strncnt -; _strnextc -; _strninc -; _strspnp -; _strtime -; _tempnam -; _timezone_dll -; _tzname -; _tzset -; _ultoa -; _unloaddll -; _vsnprintf -; _vsnwprintf -; _winmajor_dll -; _winminor_dll -; _winver_dll -; _wtoi -; _wtol -; EXPORTS ;__builtin_new ;__builtin_delete diff --git a/reactos/lib/crtdll/direct/chdir.c b/reactos/lib/crtdll/direct/chdir.c index d3898bcff66..8c195e57a82 100644 --- a/reactos/lib/crtdll/direct/chdir.c +++ b/reactos/lib/crtdll/direct/chdir.c @@ -1,15 +1,8 @@ -#include #include +#include #include -char _SetCurrentDirectory(char *dir); -int _GetCurrentDirectory(int count,char *buffer); -#undef chdir -int chdir( const char *_path ) -{ - return _chdir(_path); -} int _chdir( const char *_path ) { diff --git a/reactos/lib/crtdll/direct/getcwd.c b/reactos/lib/crtdll/direct/getcwd.c index b81446c550d..6da0b8cadc3 100644 --- a/reactos/lib/crtdll/direct/getcwd.c +++ b/reactos/lib/crtdll/direct/getcwd.c @@ -4,12 +4,6 @@ -#undef getcwd -char *getcwd( char *buffer, int maxlen ) -{ - return _getcwd(buffer,maxlen); -} - char *_getcwd( char *buffer, int maxlen ) { char *cwd; diff --git a/reactos/lib/crtdll/direct/getdcwd.c b/reactos/lib/crtdll/direct/getdcwd.c new file mode 100644 index 00000000000..f25386d55fe --- /dev/null +++ b/reactos/lib/crtdll/direct/getdcwd.c @@ -0,0 +1,22 @@ +#include + +char* _getdcwd (int nDrive, char* caBuffer, int nBufLen) +{ + int i =0; + int dr = getdrive(); + + if ( nDrive < 1 || nDrive > 26 ) + return NULL; + + if ( dr != nDrive ) + chdrive(nDrive); + + i = GetCurrentDirectory(nBufLen,caBuffer); + if ( i == nBufLen ) + return NULL; + + if ( dr != nDrive ) + chdrive(dr); + + return caBuffer; +} diff --git a/reactos/lib/crtdll/direct/mkdir.c b/reactos/lib/crtdll/direct/mkdir.c index b814ee02bf8..19191f809f5 100644 --- a/reactos/lib/crtdll/direct/mkdir.c +++ b/reactos/lib/crtdll/direct/mkdir.c @@ -1,11 +1,7 @@ #include #include -#undef mkdir -int mkdir( const char *_path ) -{ - return _mkdir(_path); -} + int _mkdir( const char *_path ) { if (!CreateDirectoryA(_path,NULL)) diff --git a/reactos/lib/crtdll/direct/rmdir.c b/reactos/lib/crtdll/direct/rmdir.c index c9979a9f45a..c6736deb172 100644 --- a/reactos/lib/crtdll/direct/rmdir.c +++ b/reactos/lib/crtdll/direct/rmdir.c @@ -1,11 +1,7 @@ #include #include -#undef rmdir -int rmdir( const char *_path ) -{ - return _rmdir(_path); -} + int _rmdir( const char *_path ) { diff --git a/reactos/lib/crtdll/except/unwind.c b/reactos/lib/crtdll/except/unwind.c new file mode 100644 index 00000000000..d5d34bf51f7 --- /dev/null +++ b/reactos/lib/crtdll/except/unwind.c @@ -0,0 +1,11 @@ +void _global_unwind2( PEXCEPTION_FRAME frame ) +{ + //RtlUnwind( frame, 0, NULL, 0 ); +} + + +void _local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr ) +{ + //TRACE(crtdll,"(%p,%ld)\n",endframe,nr); + return; +} diff --git a/reactos/lib/crtdll/float/isnan.c b/reactos/lib/crtdll/float/isnan.c index 30e2e7ec11d..8e0fb24be5d 100644 --- a/reactos/lib/crtdll/float/isnan.c +++ b/reactos/lib/crtdll/float/isnan.c @@ -1,12 +1,21 @@ #include #include -int isnan(double x) + +int _isnan(double x) { if ( x>= 0.0 && x < HUGE_VAL ) - return FALSE; + return 0; else if ( x <= 0.0 && x > HUGE_VAL ) - return FALSE; + return 0; - return TRUE; + return 1; +} + +int _isinf(double x) +{ + if ( fabs(x) == HUGE_VAL ) + return 1; + + return 0; } \ No newline at end of file diff --git a/reactos/lib/crtdll/makefile b/reactos/lib/crtdll/makefile index e4c56f9a491..1619e767cd7 100644 --- a/reactos/lib/crtdll/makefile +++ b/reactos/lib/crtdll/makefile @@ -46,7 +46,7 @@ WCHAR_OBJECTS = wchar/wcscat.o wchar/wcschr.o wchar/wcscmp.o \ wchar/wcslwr.o wchar/wcsncat.o wchar/wcsncmp.o \ wchar/wcsncpy.o -STDIO_OBJECTS = stdio/getenv.o stdio/doprnt.o stdio/doscan.o stdio/filbuf.o \ +STDIO_OBJECTS = stdio/getenv.o stdio/filbuf.o \ stdio/fclose.o stdio/feof.o stdio/ferror.o stdio/fileno.o\ stdio/fflush.o stdio/fgetc.o stdio/fgetpos.o stdio/fgets.o stdio/flsbuf.o \ stdio/fopen.o stdio/fprintf.o stdio/fputc.o stdio/fputs.o \ @@ -113,9 +113,9 @@ OLD_OBJECTS = $(MISC_OBJECTS) stdlib/malloc.o stdlib/abort.o \ stdlib/_exit.o stdlib/atexit.o stdio/fileno.o io/fmode.o \ float/fpreset.o stdio/stdhnd.o io/setmode.o io/open.o \ stdio/vsprintf.o $(CTYPE_OBJECTS) stdlib/atoi.o stdlib/strtol.o \ - stdio/flsbuf.o stdio/putc.o stdio/doprnt.o $(STRING_OBJECTS)\ + stdio/flsbuf.o stdio/putc.o stdio/vfprintf.o $(STRING_OBJECTS)\ io/write.o io/isatty.o sys_stat/fstat.o misc/dllmain.o \ - stdlib/errno.o + stdlib/errno.o stdio/printf.o stdio/vprintf.o OBJECTS = $(MISC_OBJECTS) $(STDLIB_OBJECTS) $(IO_OBJECTS) \ $(FLOAT_OBJECTS) $(ASSERT_OBJECTS) $(PROCESS_OBJECTS) \ diff --git a/reactos/lib/crtdll/math/modf.c b/reactos/lib/crtdll/math/modf.c index 9912564b379..8de426b8137 100644 --- a/reactos/lib/crtdll/math/modf.c +++ b/reactos/lib/crtdll/math/modf.c @@ -2,9 +2,20 @@ #include +long double modfl(long double x,long double *pint); + /* Slooow version. */ double modf(double x,double *pint) +{ + if (x >= 0) + *pint = floor(x); + else + *pint = ceil(x); + return x - *pint; +} + +long double modfl(long double x,long double *pint) { if (x >= 0) *pint = floor(x); diff --git a/reactos/lib/crtdll/mbstring/hanzen.c b/reactos/lib/crtdll/mbstring/hanzen.c new file mode 100644 index 00000000000..f9c6fbccd9c --- /dev/null +++ b/reactos/lib/crtdll/mbstring/hanzen.c @@ -0,0 +1,19 @@ +unsigned int _mbcjistojms( unsigned int c ) +{ + return c; +} + +unsigned int _mbcjmstojis( unsigned int c ) +{ + return c; +} + +unsigned int _mbctohira( unsigned int c ) +{ + return c; +} + +unsigned int _mbctokata( unsigned int c ) +{ + return c; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/islead.c b/reactos/lib/crtdll/mbstring/islead.c new file mode 100644 index 00000000000..e40745b5723 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/islead.c @@ -0,0 +1,7 @@ +#include +#include + +int isleadbyte(char *mbstr) +{ + return IsDBCSLeadByteEx(0,*c); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/ismblead.c b/reactos/lib/crtdll/mbstring/ismblead.c new file mode 100644 index 00000000000..9a7bf8563c4 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/ismblead.c @@ -0,0 +1,29 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ismblead.c + * PURPOSE: Checks for a lead byte + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _ismbblead(unsigned int byte) +{ + + return (int)IsDBCSLeadByte(byte) +} + +int _ismbslead( const unsigned char *str, const unsigned char *t) +{ + char *s = str; + while(*s != 0 && s != t) + { + + s+= mblen(*s); + } + return ismbblead( *s) +} + diff --git a/reactos/lib/crtdll/mbstring/ismbtrail.c b/reactos/lib/crtdll/mbstring/ismbtrail.c new file mode 100644 index 00000000000..4b26a6ee088 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/ismbtrail.c @@ -0,0 +1,29 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ismblead.c + * PURPOSE: Checks for a trailing byte + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _ismbbtrail( unsigned int b) +{ + return ((b >= 0x40 && b <= 0x7e ) || (b >= 0x80 && b <= 0xfc ) ); +} + + +int _ismbstrail( const unsigned char *str, const unsigned char *t) +{ + char *s = str; + while(*s != 0 && s != t) + { + + s+= mblen(*s); + } + + return _ismbbtrail( *s) +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbbtombc.c b/reactos/lib/crtdll/mbstring/mbbtombc.c new file mode 100644 index 00000000000..6bfd11dba02 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbbtombc.c @@ -0,0 +1,29 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ismblead.c + * PURPOSE: Converts a multi byte byte to a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +char _mbctype[256]; + +// multibyte byte to multibyte character ???? +unsigned int _mbbtombc(unsigned int c) +{ + if (( c > = 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) { + // convert + } + return c; +} + +unsigned int _mbctombb( unsigned int c ) +{ + return c; +} + + diff --git a/reactos/lib/crtdll/mbstring/mbbtype.c b/reactos/lib/crtdll/mbstring/mbbtype.c new file mode 100644 index 00000000000..76c4e1bea3f --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbbtype.c @@ -0,0 +1,48 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbbtype.c + * PURPOSE: Determines the type of a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _mbbtype(unsigned char c , int type) +{ + if ( type == 1 ) { + if ((b >= 0x40 && b <= 0x7e ) || (b >= 0x80 && b <= 0xfc ) ) + { + return _MBC_TRAIL; + } + else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || + ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) ) + return _MBC_ILLEGAL; + else + return 0; + + } + else { + if (( c > = 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) { + return _MBC_SINGLE; + } + else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) ) + return _MBC_LEAD; + else if else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || + ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) ) + return _MBC_ILLEGAL; + else + return 0; + + } + + + return 0; +} + +int _mbsbtype( const unsigned char *str, size_t n ) +{ + return 0; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbccpy.c b/reactos/lib/crtdll/mbstring/mbccpy.c new file mode 100644 index 00000000000..e8ae46d5bbd --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbccpy.c @@ -0,0 +1,9 @@ +#include + +void _mbccpy(unsigned char *dst, const unsigned char *src) +{ + if (!_ismbblead(*src) ) + return; + + memcpy(dst,src,mbclen(*src)); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbclen.c b/reactos/lib/crtdll/mbstring/mbclen.c new file mode 100644 index 00000000000..dface99aaca --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbclen.c @@ -0,0 +1,19 @@ +//#include + +#include + + +size_t _mbclen(const unsigned char *s) +{ +// return _ismbblead(s) ? 2 : 1; + return 1; +} + + +int mblen( const char *mbstr, size_t count ) +{ + return 1; +} + + + diff --git a/reactos/lib/crtdll/mbstring/mbscat.c b/reactos/lib/crtdll/mbstring/mbscat.c new file mode 100644 index 00000000000..c7461d9b65f --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbscat.c @@ -0,0 +1,4 @@ +unsigned char * _mbscat(unsigned char *dst, const unsigned char *src) +{ + return strcat(dst,src); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbschr.c b/reactos/lib/crtdll/mbstring/mbschr.c new file mode 100644 index 00000000000..caf9b969146 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbschr.c @@ -0,0 +1,4 @@ +unsigned char * _mbschr(const unsigned char *str, unsigned int c) +{ + return strchr(str,c); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbscmp.c b/reactos/lib/crtdll/mbstring/mbscmp.c new file mode 100644 index 00000000000..6baf040372d --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbscmp.c @@ -0,0 +1,6 @@ +#include + +int _mbscmp(const unsigned char *str1, const unsigned char *str2) +{ + return strcmp(str1,str2); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbscoll.c b/reactos/lib/crtdll/mbstring/mbscoll.c new file mode 100644 index 00000000000..e9a3ed93600 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbscoll.c @@ -0,0 +1,16 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbscoll.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _mbscoll(const unsigned char *str1, const unsigned char *str2) +{ + return strcoll(str1,str2); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbscpy.c b/reactos/lib/crtdll/mbstring/mbscpy.c new file mode 100644 index 00000000000..1d3f60621b2 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbscpy.c @@ -0,0 +1,5 @@ + +unsigned char * _mbscpy(unsigned char *dst, const unsigned char *str) +{ + return strcpy(dst,str); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbscspn.c b/reactos/lib/crtdll/mbstring/mbscspn.c new file mode 100644 index 00000000000..4ee3f211ab0 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbscspn.c @@ -0,0 +1,4 @@ +size_t _mbscspn(const unsigned char *str, const unsigned char *set) +{ + return strcspn(str,set); +} diff --git a/reactos/lib/crtdll/mbstring/mbsdec.c b/reactos/lib/crtdll/mbstring/mbsdec.c new file mode 100644 index 00000000000..fd20b44a189 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsdec.c @@ -0,0 +1,6 @@ +#include + +unsigned char * _mbsdec(const unsigned char *str, const unsigned char *cur) +{ + return strdec(str,cur); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsdup.c b/reactos/lib/crtdll/mbstring/mbsdup.c new file mode 100644 index 00000000000..07e8307fc47 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsdup.c @@ -0,0 +1,4 @@ +unsigned char * _mbsdup(const unsigned char *str) +{ + return strdup(str); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsicmp.c b/reactos/lib/crtdll/mbstring/mbsicmp.c new file mode 100644 index 00000000000..01f7213ab46 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsicmp.c @@ -0,0 +1,4 @@ +int _mbsicmp(const unsigned char *str1, const unsigned char *str2) +{ + return stricmp(str1,str2); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsicoll.c b/reactos/lib/crtdll/mbstring/mbsicoll.c new file mode 100644 index 00000000000..45e16270085 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsicoll.c @@ -0,0 +1,4 @@ +int _mbsicoll(const unsigned char *dest, const unsigned char *src) +{ + return stricoll(dest,src); +} diff --git a/reactos/lib/crtdll/mbstring/mbsinc.c b/reactos/lib/crtdll/mbstring/mbsinc.c new file mode 100644 index 00000000000..ab93ebf8c99 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsinc.c @@ -0,0 +1,7 @@ +#include + +unsigned char * _mbsinc(const unsigned char *s) +{ + unsigned char *c = (unsigned char *)s; + return c + (unsigned char *)mbclen(*c); +} diff --git a/reactos/lib/crtdll/mbstring/mbslen.c b/reactos/lib/crtdll/mbstring/mbslen.c new file mode 100644 index 00000000000..f182711408b --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbslen.c @@ -0,0 +1,11 @@ +size_t _mbslen(const unsigned char *str) +{ + int i = 0; + unsigned char *s; + + if (str == 0) + return 0; + + for (s = (unsigned char *)str; *s; s+=mbclen(*s),i++); + return i; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbslwr.c b/reactos/lib/crtdll/mbstring/mbslwr.c new file mode 100644 index 00000000000..c5cf9f9c8eb --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbslwr.c @@ -0,0 +1,18 @@ +unsigned int _mbctolower(unsigned int c) +{ + if (!_ismbblead(c) ) + return tolower(c); + return c; +} + + +unsigned char * _mbslwr(unsigned char *x) +{ + char *y=x; + + while (*y) { + *y=_mbctolower(*y); + y++; + } + return x; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsncat.c b/reactos/lib/crtdll/mbstring/mbsncat.c new file mode 100644 index 00000000000..2e1196f2e56 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsncat.c @@ -0,0 +1,56 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsset.c + * PURPOSE: Concatenate two multi byte string to maximum of n characters or bytes + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + + +unsigned char * _mbsncat(unsigned char *dst, const unsigned char *src, size_t n) +{ + char *d; + const char *s = src; + if (n != 0) { + d = dst + strlen(dst); // get the end of string + d += mblen(*d); // move 1 or 2 up + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + if (!_ismbblead(*s1) ) + n--; + } while (n > 0); + } + return dst; +} + +unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n) +{ + char *d; + const char *s = src; + if (n != 0) { + d = dst + strlen(dst); // get the end of string + d += mblen(*d); // move 1 or 2 up + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + if ( !(n==1 && _ismbblead(*s1)) ) + n--; + } while (n > 0); + } + return dst; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsnccnt.c b/reactos/lib/crtdll/mbstring/mbsnccnt.c new file mode 100644 index 00000000000..e47cda5ad3b --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsnccnt.c @@ -0,0 +1,15 @@ +size_t _mbsnccnt(const unsigned char *str, size_t n) +{ +} + +size_t _mbsnbcnt(const unsigned char *str, size_t n) +{ + unsigned char *s = str; + while(*s != 0 && n > 0) + if (!_ismbblead(*s) ) + n--; + s++; + } + + return (size_t)(s - str); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsncmp.c b/reactos/lib/crtdll/mbstring/mbsncmp.c new file mode 100644 index 00000000000..e5269b3d23f --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsncmp.c @@ -0,0 +1,47 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncmp.c + * PURPOSE: Compares two strings to a maximum of n bytes or characters + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _mbsncmp(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1; + unsigned char *s2; + if (n == 0) + return 0; + do { + if (*s1 != *s2++) + return *(unsigned const char *)s1 - *(unsigned const char *)--s2; + if (*s1++ == 0) + break; + + if (!_ismbblead(*s1) ) + n--; + } while (n > 0); + return 0; +} + +int _mbsnbcmp(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1; + unsigned char *s2; + if (n == 0) + return 0; + do { + if (*s1 != *s2++) + return *(unsigned const char *)s1 - *(unsigned const char *)--s2; + if (*s1++ == 0) + break; + + if (!(n == 1 && _ismbblead(*s)) ) + n--; + } while (n > 0); + return 0; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsncoll.c b/reactos/lib/crtdll/mbstring/mbsncoll.c new file mode 100644 index 00000000000..86bfefee49b --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsncoll.c @@ -0,0 +1,42 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncoll.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include + +int _mbsncoll(const unsigned char *, const unsigned char *, size_t) +{ + int l1, l2; + int ret; + + l1 = mbslen(str1); + l2 = mbslen(str2); + ret = CompareStringA(LOCALE_USER_DEFAULT,0,str1,min(l1,n),str2,min(l2,n)); + + if ( ret != 0 ) + + return ret -2; + + return 0; +} + +int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + int l1, l2; + int ret; + + l1 = strlen(str1); + l2 = strlen(str2); + ret = CompareStringA(LOCALE_USER_DEFAULT,0,str1,min(l1,n),str2,min(l2,n)); + + if ( ret != 0 ) + + return ret -2; + + return 0; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsncpy.c b/reactos/lib/crtdll/mbstring/mbsncpy.c new file mode 100644 index 00000000000..ba3481d1a38 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsncpy.c @@ -0,0 +1,43 @@ +#include + +unsigned char * _mbsncpy(unsigned char *dst, const unsigned char *src, size_t n) +{ + unsigned char *d = dst; + const unsigned char *s = src; + + if (n != 0) { + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) { + *d++ = 0; + } + break; + } + if (!_ismbblead(*s) ) + n--; + } while (n > 0); + } + return dst; +} + +unsigned char * _mbsnbcpy(unsigned char *src, const unsigned char *dst, size_t n) +{ + unsigned char *d = dst; + const unsigned char *s = src; + + if (n != 0) { + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) { + *d++ = 0; + } + break; + } + if (!(n == 1 && _ismbblead(*s)) ) + n--; + } while (n > 0); + } + return dst; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsninc.c b/reactos/lib/crtdll/mbstring/mbsninc.c new file mode 100644 index 00000000000..043344ad8ad --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsninc.c @@ -0,0 +1,11 @@ +unsigned char * _mbsninc(const unsigned char *str, size_t n) +{ + unsigned char *s = str; + while(*s != 0 && count > 0) + if (!_ismbblead(*s1) ) + n--; + s++; + } + + return s; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsnset.c b/reactos/lib/crtdll/mbstring/mbsnset.c new file mode 100644 index 00000000000..3789bb7405b --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsnset.c @@ -0,0 +1,66 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsset.c + * PURPOSE: Fills a string with a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include + +unsigned char * _mbsnset(unsigned char *src, unsigned int val, size_t count) +{ + + + unsigned char *char_s = src; + unsigned short *short_s = src; + + if ( c >> 8 == 0 ) { + + while(*s != 0 && count > 0) { + *char_src = val; + char_src++; + count--; + } + *char_src = 0; + } + else { + while(*s != 0 && count > 0) { + *short_src = val; + short_src++; + count-=2; + } + *short_src = 0; + } + + return src; + +} + +unsigned char * _mbsnbset(unsigned char *src, unsigned int val, size_t count) +{ + + unsigned char *char_s = src; + unsigned short *short_s = src; + + if ( c >> 8 == 0 ) { + + while(*s != 0 && count > 0) { + *char_src = val; + char_src++; + count--; + } + *char_src = 0; + } + else { + while(*s != 0 && count > 0) { + *short_src = val; + short_src++; + count--; + } + *short_src = 0; + } + + return src; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsrchr.c b/reactos/lib/crtdll/mbstring/mbsrchr.c new file mode 100644 index 00000000000..bb9aa729ddd --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsrchr.c @@ -0,0 +1,41 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsrchr.c + * PURPOSE: Searches for a character in reverse + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +unsigned char * _mbsrchr(const unsigned char *str, unsigned int c) +{ + + unsigned char *s = str; + + int count = mbblen(s); + + s += count; + if ( c >> 8 == 0 ) { + + while( count > 0 ) { + if ( *s == c ) + return s; + count--; + s--; + } + } + else { + while( count > 0 ) { + if ( *((short *)s) == c ) + return s; + count--; + s--; + } + } + + return src; + +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsrev.c b/reactos/lib/crtdll/mbstring/mbsrev.c new file mode 100644 index 00000000000..1532c593fd9 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsrev.c @@ -0,0 +1,4 @@ +unsigned char * _mbsrev(unsigned char *str) +{ + return strrev(str); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsset.c b/reactos/lib/crtdll/mbstring/mbsset.c new file mode 100644 index 00000000000..ef0157a5209 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsset.c @@ -0,0 +1,35 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsset.c + * PURPOSE: Fills a string with a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +unsigned char * _mbsset(unsigned char *str, unsigned int c) +{ + unsigned char *char_s = src; + unsigned short *short_s = src; + + if ( c >> 8 == 0 ) { + + while(*s != 0) { + *char_src = val; + char_src++; + } + *char_src = 0; + } + else { + while(*s != 0) { + *short_src = val; + short_src++; + } + *short_src = 0; + } + + return src; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsstr.c b/reactos/lib/crtdll/mbstring/mbsstr.c new file mode 100644 index 00000000000..6bb56d72f82 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsstr.c @@ -0,0 +1,4 @@ +unsigned char * _mbsstr(const unsigned char *str1, const unsigned char *str2) +{ + return strstr(str1,str2); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbstok.c b/reactos/lib/crtdll/mbstring/mbstok.c new file mode 100644 index 00000000000..a5eb8d002e7 --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbstok.c @@ -0,0 +1,4 @@ +unsigned char * _mbstok(unsigned char *x, const unsigned char *y) +{ + return strtok(x,y); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/mbstring/mbsupr.c b/reactos/lib/crtdll/mbstring/mbsupr.c new file mode 100644 index 00000000000..baf762b3fee --- /dev/null +++ b/reactos/lib/crtdll/mbstring/mbsupr.c @@ -0,0 +1,18 @@ +unsigned int _mbctoupper(unsigned int c) +{ + if (!_ismbblead(c) ) + return toupper(c); + + return c; +} + +unsigned char * _mbsupr(unsigned char *str) +{ + char *y=x; + + while (*y) { + *y=_mbctoupper(*y); + y++; + } + return x; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/misc/amsg.c b/reactos/lib/crtdll/misc/amsg.c new file mode 100644 index 00000000000..79a904dff12 --- /dev/null +++ b/reactos/lib/crtdll/misc/amsg.c @@ -0,0 +1,13 @@ +include + +int _aexit_rtn_dll(int exitcode) +{ + _exit(exitcode); +} + +void _amsg_exit (int errnum) +{ + fprintf(stdout,strerror(errnum)); + _aexit_rtn_dll(-1); +} + diff --git a/reactos/lib/crtdll/misc/initter.c b/reactos/lib/crtdll/misc/initter.c new file mode 100644 index 00000000000..a185e708fa2 --- /dev/null +++ b/reactos/lib/crtdll/misc/initter.c @@ -0,0 +1,7 @@ + +typedef void(*atexit_t)(void); + +void _initterm(atexit_t *, atexit_t *) +{ + return; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/misc/initterm.c b/reactos/lib/crtdll/misc/initterm.c new file mode 100644 index 00000000000..390175f563a --- /dev/null +++ b/reactos/lib/crtdll/misc/initterm.c @@ -0,0 +1,21 @@ +#include + + +void _initterm ( + void (* fStart[])(void), + void (* fEnd[])(void) + ) +{ + int i = 0; + + + if ( fStart == NULL || fEnd == NULL ) + return; + + while ( &fStart[i] < fEnd ) + { + if ( fStart[i] != NULL ) + (*fStart[i])(); + i++; + } +} diff --git a/reactos/lib/crtdll/misc/setnew.cc b/reactos/lib/crtdll/misc/setnew.cc index 1d37123bdb5..78715bc7b8b 100644 --- a/reactos/lib/crtdll/misc/setnew.cc +++ b/reactos/lib/crtdll/misc/setnew.cc @@ -5,6 +5,7 @@ typedef int (* new_handler_t)( size_t ); new_handler_t new_handler; +#undef _set_new_handler new_handler_t _set_new_handler(new_handler_t hnd) { new_handler_t old = new_handler; @@ -14,15 +15,15 @@ new_handler_t _set_new_handler(new_handler_t hnd) return old; } +#undef delete void operator delete(void* m) { if ( m != NULL ) free( m ); } +#undef new void * operator new( unsigned int s ) { - if ( s == 0 ) - s = 1; return malloc( s ); } diff --git a/reactos/lib/crtdll/process/dll.c b/reactos/lib/crtdll/process/dll.c index 64e7938a396..71a33b1d521 100644 --- a/reactos/lib/crtdll/process/dll.c +++ b/reactos/lib/crtdll/process/dll.c @@ -1,3 +1,13 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/process/dll.c + * PURPOSE: Dll support routines + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 04/03/99: Created + */ + #include #include diff --git a/reactos/lib/crtdll/process/spawnve.c b/reactos/lib/crtdll/process/spawnve.c index 00aec7fbd7c..eb1da5bb253 100644 --- a/reactos/lib/crtdll/process/spawnve.c +++ b/reactos/lib/crtdll/process/spawnve.c @@ -1,42 +1,247 @@ -#include -#include +/* Copyright (C) 1998 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 + #include +#include +#include +#include +//#include +#include +#include +#include -int _p_overlay = 2; +#ifndef F_OK + #define F_OK 0x01 +#endif +#ifndef R_OK + #define R_OK 0x02 +#endif +#ifndef W_OK + #define W_OK 0x04 +#endif +#ifndef X_OK + #define X_OK 0x08 +#endif +#ifndef D_OK + #define D_OK 0x10 +#endif -int _spawnve(int nMode, const char* szPath, char* const* szaArgv, char* const* szaEnv) + +static int +direct_exec_tail(const char *program, const char *args, + char * const envp[]) { - char ApplicationName[MAX_PATH]; - char CommandLine[1024]; - PROCESS_INFORMATION ProcessInformation; - STARTUPINFO StartupInfo; - - int i = 0; - CommandLine[0] = 0; - while(szaArgv[i] != NULL ) { - strcat(CommandLine,szaArgv[i]); - strcat(CommandLine," "); - i++; - } - strcpy(ApplicationName,szaArgv[0]); - - fflush(stdout); /* just in case */ - StartupInfo.cb = sizeof(STARTUPINFO); - StartupInfo.lpReserved= NULL; - StartupInfo.dwFlags = 0; + static PROCESS_INFORMATION ProcessInformation; + static STARTUPINFO StartupInfo; + + StartupInfo.cb = sizeof(STARTUPINFO); + StartupInfo.lpReserved= NULL; + StartupInfo.dwFlags = 0; + StartupInfo.wShowWindow = SW_SHOWDEFAULT; + StartupInfo.lpReserved2 = NULL; + StartupInfo.cbReserved2 = 0; - if ( CreateProcessA(ApplicationName,CommandLine,NULL,NULL,TRUE,CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS,NULL,*szaEnv,&StartupInfo,&ProcessInformation) ) { - return -1; - } + if ( CreateProcessA((char *)program,(char *)args,NULL,NULL,FALSE,0,(char **)envp,NULL,&StartupInfo,&ProcessInformation) ) { + return -1; + } - - // if (nMode == P_OVERLAY) - // _exit(i); - -// _P_NOWAIT or _P_NOWAITO - return (int )ProcessInformation.hProcess; + return ProcessInformation.dwProcessId; } + +static int vdm_exec(const char *program, char **argv, char **envp) +{ + static char args[1024]; + int i = 0; + args[0] = 0; + + strcpy(args,"vdm.exe "); + while(argv[i] != NULL ) { + strcat(args,argv[i]); + strcat(args," "); + i++; + } + + return direct_exec_tail(program,args,envp); +} + +static int go32_exec(const char *program, char **argv, char **envp) +{ + + + static char args[1024]; + int i = 0; + + + args[0] = 0; + + while(argv[i] != NULL ) { + strcat(args,envp[i]); + strcat(args," "); + i++; + } + printf("%s \n %s\n",args, GetEnvironmentStrings()); + args[0] = 0; + i = 0; + while(argv[i] != NULL ) { + strcat(args,argv[i]); + strcat(args," "); + i++; + } + + return direct_exec_tail(program,args,envp); +} + +int +command_exec(const char *program, char **argv, char **envp) +{ + static char args[1024]; + int i = 0; + + + + args[0] = 0; + + strcpy(args,"cmd.exe /c "); + while(argv[i] != NULL ) { + strcat(args,argv[i]); + strcat(args," "); + i++; + } + + return direct_exec_tail(program,args,envp); + +} + +static int script_exec(const char *program, char **argv, char **envp) +{ + return 0; +} + + +/* Note: the following list is not supposed to mention *every* + possible extension of an executable file. It only mentions + those extensions that can be *omitted* when you invoke the + executable from one of the shells used on MSDOS. */ +static struct { + const char *extension; + int (*interp)(const char *, char **, char **); +} interpreters[] = { + { ".com", vdm_exec }, + { ".exe", go32_exec }, + { ".bat", command_exec }, + { ".btm", command_exec }, + { ".sh", script_exec }, /* for compatibility with ms_sh */ + { ".ksh", script_exec }, + { ".pl", script_exec }, /* Perl */ + { ".sed", script_exec }, + { "", go32_exec }, + { 0, script_exec }, /* every extension not mentioned above calls it */ + { 0, 0 }, +}; + +/* This is the index into the above array of the interpreter + which is called when the program filename has no extension. */ +#define INTERP_NO_EXT (sizeof(interpreters)/sizeof(interpreters[0]) - 3) + +/*-------------------------------------------------*/ + + + + +int _spawnve(int mode, const char *path, char *const argv[], char *const envp[]) +{ + /* This is the one that does the work! */ + union { char *const *x; char **p; } u; + int i = -1; + char **argvp; + char **envpp; + char rpath[FILENAME_MAX], *rp, *rd=0; + int e = errno; + int is_dir = 0; + int found = 0; + + if (path == 0 || argv[0] == 0) + { + errno = EINVAL; + return -1; + } + if (strlen(path) > FILENAME_MAX - 1) + { + errno = ENAMETOOLONG; + return -1; + } + + u.x = argv; argvp = u.p; + u.x = envp; envpp = u.p; + + fflush(stdout); /* just in case */ + for (rp=rpath; *path; *rp++ = *path++) + { + if (*path == '.') + rd = rp; + if (*path == '\\' || *path == '/') + rd = 0; + } + *rp = 0; + + /* If LFN is supported on the volume where rpath resides, we + might have something like foo.bar.exe or even foo.exe.com. + If so, look for RPATH.ext before even trying RPATH itself. */ + if (!rd) + { + for (i=0; interpreters[i].extension; i++) + { + strcpy(rp, interpreters[i].extension); + if (_access(rpath, F_OK) == 0 && !(is_dir = (_access(rpath, D_OK) == 0))) + { + found = 1; + break; + } + } + } + + if (!found) + { + const char *rpath_ext; + + if (rd) + { + i = 0; + rpath_ext = rd; + } + else + { + i = INTERP_NO_EXT; + rpath_ext = ""; + } + for ( ; interpreters[i].extension; i++) + if (_stricmp(rpath_ext, interpreters[i].extension) == 0 + && _access(rpath, F_OK) == 0 + && !(is_dir = (_access(rpath, D_OK) == 0))) + { + found = 1; + break; + } + } + if (!found) + { + errno = is_dir ? EISDIR : ENOENT; + return -1; + } + errno = e; + i = interpreters[i].interp(rpath, argvp, envpp); + if (mode == P_OVERLAY) + exit(i); + return i; +} + + + + + diff --git a/reactos/lib/crtdll/process/thread.c b/reactos/lib/crtdll/process/thread.c new file mode 100644 index 00000000000..06e2816cf90 --- /dev/null +++ b/reactos/lib/crtdll/process/thread.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + + +unsigned long + _beginthread (void (*pfuncStart)(void *), + unsigned unStackSize, void* pArgList) +{ + DWORD ThreadId; + HANDLE hThread; + if ( pfuncStart == NULL ) + __set_errno(EINVAL); + + hThread = CreateThread( NULL,unStackSize,(LPTHREAD_START_ROUTINE)pfuncStart,pArgList,0, &ThreadId); + if (hThread == NULL ) { + __set_errno(EAGAIN); + return -1; + } + return (unsigned long)hThread; +} +void _endthread(void) +{ + ExitThread(0); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/setjmp/setjmp.c b/reactos/lib/crtdll/setjmp/setjmp.c new file mode 100644 index 00000000000..dc0d5faad21 --- /dev/null +++ b/reactos/lib/crtdll/setjmp/setjmp.c @@ -0,0 +1,143 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +/* modified by Boudewijn Dekker */ +/* ms uses a smaller jmp_buf structure */ +/* might do a realloc in setjmp */ + +typedef struct { + unsigned int __eax, __ebx, __ecx, __edx, __esi; + unsigned int __edi, __ebp, __esp, __eip, __eflags; + unsigned short __cs, __ds, __es, __fs, __gs, __ss; + unsigned long __sigmask; /* for POSIX signals only */ + unsigned long __signum; /* for expansion */ + unsigned long __exception_ptr; /* pointer to previous exception */ + unsigned char __fpu_state[108]; /* for future use */ +} jmp_buf[1]; + + +/* jumps back to position specified in jmp_buf */ + +int longjmp( jmp_buf env, int value ) +{ + //push ebp generated by the compiler + //mov ebp, esp + + __asm__ __volatile__ ( + "movl 8(%ebp),%edi\n\t" /* get jmp_buf */ + "movl 12(%ebp),%eax\n\t" /* store retval in j->eax */ + "movl %eax,0(%edi)\n\t" + + "movw 46(%edi),%fs\n\t" + "movw 48(%edi),%gs\n\t" + "movl 4(%edi),%ebx\n\t" + "movl 8(%edi),%ecx\n\t" + "movl 12(%edi),%edx\n\t" + "movl 24(%edi),%ebp\n\t" + + /* Now for some uglyness. The jmp_buf structure may be ABOVE the + point on the new SS:ESP we are moving to. We don't allow overlap, + but do force that it always be valid. We will use ES:ESI for + our new stack before swapping to it. */ + + "movw 50(%edi),%es\n\t" + "movl 28(%edi),%esi\n\t" + "subl $28,%esi\n\t" /* We need 7 working longwords on stack */ + + "movl 60(%edi),%eax\n\t" + "es\n\t" + "movl %eax,(%esi)\n\t" /* Exception pointer */ + + "movzwl 42(%edi),%eax\n\t" + "es\n\t" + "movl %eax,4(%esi)\n\t" /* DS */ + + "movl 20(%edi),%eax\n\t" + "es\n\t" + "movl %eax,8(%esi)\n\t" /* EDI */ + + "movl 16(%edi),%eax\n\t" + "es\n\t" + "movl %eax,12(%esi)\n\t" /* ESI */ + + "movl 32(%edi),%eax\n\t" + "es\n\t" + "movl %eax,16(%esi)\n\t" /* EIP - start of IRET frame */ + + "movl 40(%edi),%eax\n\t" + "es\n\t" + "movl %eax,20(%esi)\n\t" /* CS */ + + "movl 36(%edi),%eax\n\t" + "es\n\t" + "movl %eax,24(%esi)\n\t" /* EFLAGS */ + + "movl 0(%edi),%eax\n\t" + "movw 44(%edi),%es\n\t" + + "movw 50(%edi),%ss\n\t" + "movl %esi,%esp\n\t" + + //"popl ___djgpp_exception_state_ptr\n\t" + "popl %edi\n\t" // dummy popl instead of djgpp_exception_state_ptr + "popl %ds\n\t" + "popl %edi\n\t" + "popl %esi\n\t" + + "iret\n\t" /* actually jump to new cs:eip loading flags */ + ); + + return value; // dummy return never reached +} + + + +int _setjmp( jmp_buf env ) +{ + //push ebp generated by the compiler + //mov ebp, esp + + __asm__ __volatile__ ( + + "pushl %edi\n\t" + "movl 8(%ebp),%edi\n\t" + + "movl %eax, (%edi)\n\t" + "movl %ebx,4(%edi)\n\t" + "movl %ecx,8(%edi)\n\t" + "movl %edx,12(%edi)\n\t" + "movl %esi,16(%edi)\n\t" + + "movl -4(%ebp),%eax\n\t" + "movl %eax,20(%edi)\n\t" + + "movl (%ebp),%eax\n\t" + "movl %eax,24(%edi)\n\t" + + "movl %esp,%eax\n\t" + "addl $12,%eax\n\t" + "movl %eax,28(%edi)\n\t" + + "movl 4(%ebp),%eax\n\t" + "movl %eax,32(%edi)\n\t" + + "pushfl\n\t" + "popl 36(%edi)\n\t" + + "movw %cs, 40(%edi)\n\t" + "movw %ds, 42(%edi)\n\t" + "movw %es, 44(%edi)\n\t" + "movw %fs, 46(%edi)\n\t" + "movw %gs, 48(%edi)\n\t" + "movw %ss, 50(%edi)\n\t" + + //movl ___djgpp_exception_state_ptr, %eax + //movl %eax, 60(%edi) + + "popl %edi\n\t" + ); + + + + + + return 0; +} diff --git a/reactos/lib/crtdll/signal/signal.c b/reactos/lib/crtdll/signal/signal.c index 9283dff4958..affd626c9e6 100644 --- a/reactos/lib/crtdll/signal/signal.c +++ b/reactos/lib/crtdll/signal/signal.c @@ -5,7 +5,7 @@ #include #include -extern unsigned end __asm__ ("end"); +//extern unsigned end __asm__ ("end"); void __djgpp_traceback_exit(int); @@ -28,6 +28,7 @@ _p_sig_fn_t signal(int sig, _p_sig_fn_t func) int raise(int sig) { +#if 0 _p_sig_fn_t temp; if(sig <= 0) @@ -47,6 +48,8 @@ raise(int sig) } else temp(sig); + +#endif return 0; } diff --git a/reactos/lib/crtdll/signal/xcptfil.c b/reactos/lib/crtdll/signal/xcptfil.c new file mode 100644 index 00000000000..59d935d821e --- /dev/null +++ b/reactos/lib/crtdll/signal/xcptfil.c @@ -0,0 +1,10 @@ +#include + + +int _XcptFilter ( + DWORD ExceptionCode, + struct _EXCEPTION_POINTERS * ExceptionInfo + ) +{ + return UnhandledExceptionFilter(ExceptionInfo); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/signal/xcptinfo.c b/reactos/lib/crtdll/signal/xcptinfo.c new file mode 100644 index 00000000000..0711c76dde7 --- /dev/null +++ b/reactos/lib/crtdll/signal/xcptinfo.c @@ -0,0 +1,4 @@ +void **__pxcptinfoptrs (void) +{ + return NULL; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/stdio/clearerr.c b/reactos/lib/crtdll/stdio/clearerr.c index 5244620031b..e05529ca3bd 100644 --- a/reactos/lib/crtdll/stdio/clearerr.c +++ b/reactos/lib/crtdll/stdio/clearerr.c @@ -10,5 +10,9 @@ void clearerr(FILE *stream); void clearerr(FILE *f) { + if (!f) { + __set_errno (EINVAL); + return; + } f->_flag &= ~(_IOERR|_IOEOF); } diff --git a/reactos/lib/crtdll/stdio/doprnt.c b/reactos/lib/crtdll/stdio/doprnt.c deleted file mode 100644 index 8a25c20ec50..00000000000 --- a/reactos/lib/crtdll/stdio/doprnt.c +++ /dev/null @@ -1,320 +0,0 @@ - - - - -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -/* - * Appropiated for the reactos kernel, March 1998 -- David Welch - */ - -#include - -//#include -#include -#include -#include -#include - -static int skip_atoi(const char **s) -{ - int i=0; - - while (isdigit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ - - -static int __res; - -int do_div(int *n,int base) { - -__res = ((unsigned long) *n) % (unsigned) base; -*n = ((unsigned long) *n) / (unsigned) base; -return __res; -} - -static char * number(FILE * f, long num, int base, int size, int precision - ,int type) -{ - char c,sign,tmp[66]; - const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; - int i; - - if (type & LARGE) - digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div((int *)&num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) - while(size-->0) - putc( ' ',f); - if (sign) - putc( sign,f); - if (type & SPECIAL) { - if (base==8) { - putc( '0',f); - } - else if (base==16) { - putc( '0', f); - putc( digits[33],f); - } - } - if (!(type & LEFT)) { - while (size-- > 0) - putc( c,f); - } - while (i < precision--) - putc( '0', f); - while (i-- > 0) - putc( tmp[i],f); - while (size-- > 0) - putc( ' ', f); - __res = 0; - return 0; -} - -int _doprnt(const char *fmt, va_list args, FILE *f) -{ - int len; - unsigned long num; - int i, base; - - const char *s; - const short int* sw; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - - for (; *fmt ; ++fmt) { - if (*fmt != '%') { - putc(*fmt,f); - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (isdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (isdigit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { - qualifier = *fmt; - ++fmt; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': - if (!(flags & LEFT)) - while (--field_width > 0) - putc(' ',f); - putc((unsigned char) va_arg(args, int),f); - while (--field_width > 0) - putc( ' ',f); - continue; - - case 'w': - sw = va_arg(args,short int *); -// DPRINT("L %x\n",sw); - if (sw==NULL) - { -// CHECKPOINT; - s = ""; - while ((*s)!=0) - { - putc( *s++,f); - } -// CHECKPOINT; -// DbgPrint("str %x\n",str); - } - else - { - while ((*sw)!=0) - { - putc( (char)(*sw++),f); - } - } -// CHECKPOINT; - continue; - - case 's': - s = va_arg(args, char *); - if (!s) - s = ""; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) - while (len < field_width--) - putc( ' ', f); - for (i = 0; i < len; ++i) - putc( *s++,f); - while (len < field_width--) - putc( ' ', f); - continue; - - case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - number(f, - (unsigned long) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - - case 'n': - if (qualifier == 'l') { - long * ip; - ip = va_arg(args, long *); - //*ip = (str - buf); - } else { - int * ip; - ip = va_arg(args, int *); - //*ip = (str - buf); - } - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'b': - base = 2; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - case 'f': - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - if (*fmt != '%') - putc( '%', f); - if (*fmt) - putc( *fmt, f); - else - --fmt; - continue; - } - if (qualifier == 'l') - num = va_arg(args, unsigned long); - else if (qualifier == 'h') { - if (flags & SIGN) - num = va_arg(args, short); - else - num = va_arg(args, unsigned short); - } - else if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - number(f, num, base, field_width, precision, flags); - } - //putc('\0',f); - return 0; -} - - - diff --git a/reactos/lib/crtdll/stdio/fclose.c b/reactos/lib/crtdll/stdio/fclose.c index 98caf7621e8..5b20fc972ee 100644 --- a/reactos/lib/crtdll/stdio/fclose.c +++ b/reactos/lib/crtdll/stdio/fclose.c @@ -1,18 +1,13 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include + #include #include #include #include #include -//#include +#include #include -#if 0 -#ifndef __dj_include_stdio_h_ -#define _name_to_remove _tmpfname -#endif -#endif int fclose(FILE *f) @@ -20,8 +15,12 @@ fclose(FILE *f) int r; r = EOF; - if (!f) + if (!f) { + __set_errno (EINVAL); return r; + } +// flush only if stream was opened for writing + if (f->_flag & (_IOREAD|_IOWRT|_IORW) && !(f->_flag&_IOSTRG)) { diff --git a/reactos/lib/crtdll/stdio/fdopen.c b/reactos/lib/crtdll/stdio/fdopen.c index 5af8085fc2d..dc815528e34 100644 --- a/reactos/lib/crtdll/stdio/fdopen.c +++ b/reactos/lib/crtdll/stdio/fdopen.c @@ -1,4 +1,7 @@ #include +#include + +FILE * __alloc_file(void); FILE *_fdopen(int handle, char *mode) { diff --git a/reactos/lib/crtdll/stdio/fgetc.c b/reactos/lib/crtdll/stdio/fgetc.c index 2c123c76030..33ed518c486 100644 --- a/reactos/lib/crtdll/stdio/fgetc.c +++ b/reactos/lib/crtdll/stdio/fgetc.c @@ -18,8 +18,8 @@ fgetc(FILE *f) return getc(f); } -int +wint_t fgetwc(FILE *f) { - return getc(f); + return getwc(f); } diff --git a/reactos/lib/crtdll/stdio/filbuf.c b/reactos/lib/crtdll/stdio/filbuf.c index b551aa0987a..19e5c5e305a 100644 --- a/reactos/lib/crtdll/stdio/filbuf.c +++ b/reactos/lib/crtdll/stdio/filbuf.c @@ -8,6 +8,7 @@ #include #include #include +#include /* Note: We set _fillsize to 512, and use that for reading instead of _bufsize, for performance reasons. We double _fillsize each time @@ -20,8 +21,7 @@ int _filbuf(FILE *f) { - int size =0; - //int fillsize = 0; + int size, fillsize; char c; if (f->_flag & _IORW) @@ -44,7 +44,7 @@ _filbuf(FILE *f) { f->_flag |= _IOMYBUF; f->_bufsiz = size; - //f->_fillsize = 512; + f->_fillsize = 512; } } @@ -59,22 +59,22 @@ _filbuf(FILE *f) } /* don't read too much! */ - //if (f->_fillsize > f->_bufsiz) - // f->_fillsize = f->_bufsiz; + if (f->_fillsize > f->_bufsiz) + f->_fillsize = f->_bufsiz; /* This next bit makes it so that the cumulative amount read always aligns with file cluster boundaries; i.e. 512, then 2048 (512+1536), then 4096 (2048+2048) etc. */ - //fillsize = f->_fillsize; - //if (fillsize == 1024 && f->_bufsiz >= 1536) - // fillsize = 1536; + fillsize = f->_fillsize; + if (fillsize == 1024 && f->_bufsiz >= 1536) + fillsize = 1536; f->_cnt = _read(fileno(f), f->_base, - f->_flag & _IONBF ? 1 : size); + f->_flag & _IONBF ? 1 : fillsize); /* Read more next time, if we don't seek */ - //if (f->_fillsize < f->_bufsiz) - // f->_fillsize *= 2; + if (f->_fillsize < f->_bufsiz) + f->_fillsize *= 2; if(__is_text_file(f) && f->_cnt>0) { @@ -102,3 +102,8 @@ _filbuf(FILE *f) } return *f->_ptr++ & 0377; } + +wint_t _filwbuf(FILE *fp) +{ + return (wint_t )_filbuf(fp); +} diff --git a/reactos/lib/crtdll/stdio/flsbuf.c b/reactos/lib/crtdll/stdio/flsbuf.c index b667a40c9be..4fbc6fd2ec4 100644 --- a/reactos/lib/crtdll/stdio/flsbuf.c +++ b/reactos/lib/crtdll/stdio/flsbuf.c @@ -1,18 +1,17 @@ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include + #include +#include #include #include -//#include -//#include #include #include int _flsbuf(int c, FILE *f) { - char *base; + char *base; int n, rn; char c1; int size; @@ -29,8 +28,7 @@ _flsbuf(int c, FILE *f) /* if the buffer is not yet allocated, allocate it */ if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0) { -// size = _go32_info_block.size_of_transfer_buffer; - size = 512; + size = 512; if ((f->_base = base = malloc (size)) == NULL) { f->_flag |= _IONBF; @@ -98,3 +96,9 @@ _flsbuf(int c, FILE *f) } return c; } + +wint_t _flswbuf(wchar_t c,FILE *fp) +{ + return (wint_t )_flsbuf((int)c,fp); +} + diff --git a/reactos/lib/crtdll/stdio/fprintf.c b/reactos/lib/crtdll/stdio/fprintf.c index 13be50e5d8c..88ab33c67ca 100644 --- a/reactos/lib/crtdll/stdio/fprintf.c +++ b/reactos/lib/crtdll/stdio/fprintf.c @@ -16,7 +16,7 @@ fprintf(register FILE *iop, const char *fmt, ...) iop->_flag &= ~_IONBF; iop->_ptr = iop->_base = localbuf; iop->_bufsiz = BUFSIZ; - len = _doprnt(fmt,a, iop); + len = vfprintf(iop,fmt,a); fflush(iop); iop->_flag |= _IONBF; iop->_base = NULL; @@ -24,6 +24,6 @@ fprintf(register FILE *iop, const char *fmt, ...) iop->_cnt = 0; } else - len = _doprnt(fmt, a, iop); + len = vfprintf(iop, fmt, a); return ferror(iop) ? EOF : len; } diff --git a/reactos/lib/crtdll/stdio/fputc.c b/reactos/lib/crtdll/stdio/fputc.c index 715469cd954..c63635a154b 100644 --- a/reactos/lib/crtdll/stdio/fputc.c +++ b/reactos/lib/crtdll/stdio/fputc.c @@ -9,8 +9,9 @@ fputc(int c, FILE *fp) return putc(c, fp); } -int +wint_t fputwc(wchar_t c, FILE *fp) -{ - return putc(c, fp); +{ + return fputwc(c,fp); } + diff --git a/reactos/lib/crtdll/stdio/fread.c b/reactos/lib/crtdll/stdio/fread.c index fc44146d612..0f10098a586 100644 --- a/reactos/lib/crtdll/stdio/fread.c +++ b/reactos/lib/crtdll/stdio/fread.c @@ -6,7 +6,6 @@ #include #include -#define _fillsize _bufsiz size_t fread(void *vptr, size_t size, size_t count, FILE *iop) diff --git a/reactos/lib/crtdll/stdio/fscanf.c b/reactos/lib/crtdll/stdio/fscanf.c index bf278be839f..5634cc24385 100644 --- a/reactos/lib/crtdll/stdio/fscanf.c +++ b/reactos/lib/crtdll/stdio/fscanf.c @@ -1,26 +1,59 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include +/* Copyright (C) 1991 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + + #include -#include +#include +#include +#include -int -fscanf(FILE *f, const char *fmt, ...) +int __vfscanf (FILE *s, const char *format, va_list argptr); +/* Read formatted input from STREAM according to the format string FORMAT. */ +/* VARARGS2 */ +int fscanf(FILE *stream,const char *format, ...) { - int r; - va_list a=0; - va_start(a, fmt); - r = _doscan(f, fmt, a); - va_end(a); - return r; + va_list arg; + int done; + + va_start(arg, format); + done = __vfscanf(stream, format, arg); + va_end(arg); + + return done; } int -fwscanf(FILE *f, const wchar_t *fmt, ...) +fwscanf(FILE *stream, const wchar_t *fmt, ...) { - int r; - va_list a=0; - va_start(a, fmt); - r = _dowscan(f, fmt,(void *) a); - va_end(a); - return r; + va_list arg; + int done; + char *cf; + int i,len = wcslen(fmt); + + cf = alloca(len+1); + for(i=0;i #include -#define _fillsize _bufsiz int fseek(FILE *f, long offset, int ptrname) diff --git a/reactos/lib/crtdll/stdio/getc.c b/reactos/lib/crtdll/stdio/getc.c index 28cfb259508..afca093097d 100644 --- a/reactos/lib/crtdll/stdio/getc.c +++ b/reactos/lib/crtdll/stdio/getc.c @@ -1,5 +1,6 @@ -#include #include +#include +#include #include @@ -15,4 +16,25 @@ int getc(FILE *fp) return -1; } +// not exported + +wint_t getwc(FILE *fp) +{ + + // might check on multi bytes if text mode + + if(fp->_cnt > 0) { + fp->_cnt -= sizeof(wchar_t); + return (wint_t )*((wchar_t *)(fp->_ptr))++; + } + else { + return _filwbuf(fp); + } + + // never reached + return -1; +} + + + diff --git a/reactos/lib/crtdll/stdio/printf.c b/reactos/lib/crtdll/stdio/printf.c index 10cf68c9ed3..a215d78d7e1 100644 --- a/reactos/lib/crtdll/stdio/printf.c +++ b/reactos/lib/crtdll/stdio/printf.c @@ -1,21 +1,41 @@ -/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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. + + The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include #include -#include - -int printf(const char *fmt, ...) +/* Write formatted output to stdout from the format string FORMAT. */ +/* VARARGS1 */ +int +printf (const char *format, ...) { - int len; - va_list a; - - va_start( a, fmt ); - len = _doprnt(fmt, a, stdout); + va_list arg; + int done; - /* People were confused when printf() didn't flush stdout, - so we'll do it to reduce confusion */ - if (stdout->_flag & _IOLBF) - fflush(stdout); - - return ferror(stdout) ? EOF : len; + va_start (arg, format); + done = vprintf (format, arg); + va_end (arg); + return done; } + +#ifdef USE_IN_LIBIO +# undef _IO_printf +/* This is for libg++. */ +strong_alias (printf, _IO_printf); +#endif + diff --git a/reactos/lib/crtdll/stdio/putc.c b/reactos/lib/crtdll/stdio/putc.c index 464eb061266..2d5197a3182 100644 --- a/reactos/lib/crtdll/stdio/putc.c +++ b/reactos/lib/crtdll/stdio/putc.c @@ -1,20 +1,41 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include #include +#include +#include #include -#include - int putc(int c, FILE *fp) -{ - if (fp->_cnt > 0 ) - { - fp->_cnt--; - *(fp)->_ptr++ = (char)c; - return (int)c; - } - else - return _flsbuf(c,fp); - - return -1; +{ + if ( c == 0 ) + c = ' '; + + if (fp->_cnt > 0 ) { + fp->_cnt--; + *(fp)->_ptr++ = (char)c; + *(fp)->_ptr = 0; + return (int)c; + } + else { + return _flsbuf(c,fp); + } + + + return -1; +} + +wint_t putwc(wchar_t c, FILE *fp) +{ + // might check on multi bytes if text mode + + if (fp->_cnt > 0 ) { + fp->_cnt-= sizeof(wchar_t); + *((wchar_t *)(fp->_ptr))++ = c; + return (wint_t)c; + } + else + return _flswbuf(c,fp); + + return -1; + + } diff --git a/reactos/lib/crtdll/stdio/scanf.c b/reactos/lib/crtdll/stdio/scanf.c index ab74a588117..6bc0832a662 100644 --- a/reactos/lib/crtdll/stdio/scanf.c +++ b/reactos/lib/crtdll/stdio/scanf.c @@ -1,27 +1,75 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include -#include -#include +/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include + +/* The function `vscanf' is not defined in ISO C. Therefore we must + use the protected form here. In stdio it is called `__vscanf' and + in libio `_IO_vscanf'. */ +#ifdef USE_IN_LIBIO +# include +# define VSCANF _IO_vscanf +#else +# define VSCANF __vscanf +#endif + +int __vscanf (const char *format, va_list arg); + +/* Read formatted input from stdin according to the format string FORMAT. */ +/* VARARGS1 */ int -scanf(const char *fmt, ...) +scanf (const char *format, ...) { - int r; - va_list a=0; - va_start(a, fmt); - r = _doscan(stdin, fmt, a); - va_end(a); - return r; + va_list arg; + int done; + + va_start (arg, format); + done = VSCANF (format, arg); + va_end (arg); + + return done; } + int wscanf(const wchar_t *fmt, ...) { - int r; - va_list a=0; - va_start(a, fmt); - r = _dowscan(stdin, fmt, a); - va_end(a); - return r; + va_list arg; + int done; + char *f; + int i, len = wcslen(fmt); + + f = alloca(len+1); + for(i=0;i +void *alloca(size_t x) +{ + return malloc(x); +} diff --git a/reactos/lib/crtdll/stdio/setvbuf.c b/reactos/lib/crtdll/stdio/setvbuf.c index dee56849052..b8421eb843b 100644 --- a/reactos/lib/crtdll/stdio/setvbuf.c +++ b/reactos/lib/crtdll/stdio/setvbuf.c @@ -6,7 +6,6 @@ #include #include -#define _fillsize _bufsiz int setvbuf(FILE *f, char *buf, int type, size_t len) { diff --git a/reactos/lib/crtdll/stdio/sprintf.c b/reactos/lib/crtdll/stdio/sprintf.c index 45de8f43495..e3bf4ba9cad 100644 --- a/reactos/lib/crtdll/stdio/sprintf.c +++ b/reactos/lib/crtdll/stdio/sprintf.c @@ -15,7 +15,7 @@ sprintf(char *str, const char *fmt, ...) _strbuf._flag = _IOWRT|_IOSTRG; _strbuf._ptr = str; _strbuf._cnt = INT_MAX; - len = _doprnt(fmt, a, &_strbuf); + len = vfprintf(&_strbuf, fmt, a); *_strbuf._ptr = 0; return len; } diff --git a/reactos/lib/crtdll/stdio/sscanf.c b/reactos/lib/crtdll/stdio/sscanf.c index 782cff28af5..34751b25daa 100644 --- a/reactos/lib/crtdll/stdio/sscanf.c +++ b/reactos/lib/crtdll/stdio/sscanf.c @@ -1,47 +1,75 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include +/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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. + + The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + #include -#include -//#include +#include +#include +#include +int __vsscanf (const char *s,const char *format,va_list arg); + +/* Read formatted input from S, according to the format string FORMAT. */ +/* VARARGS2 */ int -sscanf(const char *str, const char *fmt, ...) +sscanf (const char *s,const char *format, ...) { - int r; - va_list a=0; - FILE _strbuf; + va_list arg; + int done; - va_start(a, fmt); + va_start (arg, format); + done = __vsscanf (s, format, arg); + va_end (arg); - _strbuf._flag = _IOREAD|_IOSTRG; - _strbuf._ptr = (char *)str; - _strbuf._base = (char *)str; - _strbuf._cnt = 0; - while (*str++) - _strbuf._cnt++; - _strbuf._bufsiz = _strbuf._cnt; - r = _doscan(&_strbuf, fmt, a); - va_end(a); - return r; + return done; } +#ifdef USE_IN_LIBIO +# undef _IO_sscanf +/* This is for libg++. */ +strong_alias (sscanf, _IO_sscanf) +#endif + + + int swscanf(const wchar_t *str, const wchar_t *fmt, ...) { - int r; - va_list a=0; - FILE _strbuf; + va_list arg; + int done; + char *f , *s; + int i,len = wcslen(fmt); + + f = alloca(len+1); + for(i=0;i_flag & (_IOREAD|_IORW)) == 0 + || f->_ptr == NULL + || f->_base == NULL) + return EOF; + + if (f->_ptr == f->_base) + { + if (f->_cnt == 0) + f->_ptr+=sizeof(wchar_t); + else + return EOF; + } + + f->_cnt+=sizeof(wchar_t); + f->_ptr-=sizeof(wchar_t); + + f->_flag |= _IOUNGETC; + *((wchar_t *)(f->_ptr)) = c; + + return c; } \ No newline at end of file diff --git a/reactos/lib/crtdll/stdio/vfprintf.c b/reactos/lib/crtdll/stdio/vfprintf.c index c7494bc9d37..67d801745eb 100644 --- a/reactos/lib/crtdll/stdio/vfprintf.c +++ b/reactos/lib/crtdll/stdio/vfprintf.c @@ -3,6 +3,13 @@ #include #include +#define isascii __isascii + + + +int +__vfprintf (FILE *fp, const char *fmt0, va_list argp); + int vfprintf(FILE *f, const char *fmt, va_list ap) { @@ -14,7 +21,7 @@ vfprintf(FILE *f, const char *fmt, va_list ap) f->_flag &= ~_IONBF; f->_ptr = f->_base = localbuf; f->_bufsiz = BUFSIZ; - len = _doprnt(fmt, ap, f); + len = __vfprintf(f,fmt, ap); (void)fflush(f); f->_flag |= _IONBF; f->_base = NULL; @@ -22,6 +29,899 @@ vfprintf(FILE *f, const char *fmt, va_list ap) f->_cnt = 0; } else - len = _doprnt(fmt, ap, f); + len = __vfprintf(f,fmt, ap); return (ferror(f) ? EOF : len); } + + +/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +//#include +#include +#include +#include +#include +//#include +#include +#include +#include +//#include +//#include +//#include + +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) + +// adjustedn llong remove from first +#define ARG(basetype) _ulonglong = \ + flags&LONGDBL ? va_arg(argp, basetype) : \ + flags&LONGINT ? va_arg(argp, long basetype) : \ + flags&SHORTINT ? (short basetype)va_arg(argp, int) : \ + va_arg(argp, int) + +// changed name of nan due to conflict with cygwin math header +static int _nan = 0; + +#define MODFL modf +typedef double ldouble; +typedef long llong; +typedef unsigned long ullong; + +ldouble modfl(ldouble x,ldouble *pint); + +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 /* ldouble */ +#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 int cvtl(ldouble number, int prec, int flags, char *signp, + unsigned char fmtch, char *startp, char *endp); +static char *roundl(ldouble fract, int *expv, char *start, char *end, + char ch, char *signp); +static char *exponentl(char *p, int expv, unsigned char fmtch); +//#ifdef __GO32__ +static int isspeciall(ldouble d, char *bufp); +//#endif + +static char NULL_REP[] = "(null)"; + +int +__vfprintf (FILE *fp, const char *fmt0, va_list argp) +{ + const char *fmt; /* format string */ + int ch; /* character from fmt */ + int cnt; /* return value accumulator */ + int n; /* random handy integer */ + char *t; /* buffer pointer */ + ldouble _ldouble; /* double and ldouble precision arguments + %L.[eEfgG] */ + ullong _ulonglong=0; /* 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 = 0; /* `extra' floating precision in [eEfgG] */ + int prec = 0; /* precision from format (%.3d), or -1 */ + int realsz; /* field size expanded by decimal precision */ + int size = 0; /* 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] */ + int neg_ldouble = 0; /* non-zero if _ldouble is negative */ + + //decimal = localeconv()->decimal_point[0]; + decimal = '.'; + + 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) + { + while ((ch = *fmt) && ch != '%') + { + PUTC (ch); + fmt++; + cnt++; + } + 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': + if (flags&LONGINT) + flags |= LONGDBL; /* for 'll' - llong */ + else + 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 ((llong)_ulonglong < 0) + { + _ulonglong = -_ulonglong; + sign = '-'; + } + base = 10; + goto number; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (flags & LONGDBL) + _ldouble = va_arg(argp, ldouble); + else + _ldouble = (ldouble)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; + neg_ldouble = 1; + } + else + { + softsign = 0; + neg_ldouble = 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 = 0; + size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf, + buf + sizeof(buf)); + /* + * If the format specifier requested an explicit sign, + * we print a negative sign even if no significant digits + * will be shown, and we also print a sign for a NaN. In + * other words, "%+f" might print -0.000000, +NaN and -NaN. + */ + if (softsign || (sign == '+' && (neg_ldouble || _nan == -1))) + sign = '-'; + _nan = 0; + t = *buf ? buf : buf + 1; + goto pforw; + case 'n': + if (flags & LONGDBL) + *va_arg(argp, llong *) = cnt; + else 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 */ + _ulonglong = (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 && _ulonglong != 0) + flags |= HEXPREFIX; + + nosign: + /* unsigned conversions */ + sign = '\0'; + number: + /* + * ``... diouXx conversions ... if a precision is + * specified, the 0 flag will be ignored.'' + * -- ANSI X3J11 + */ + 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 (_ulonglong != 0 || prec != 0) + { + /* conversion is done separately since operations + with llong are much slower */ +#define CONVERT(type) \ + { \ + register type _n = (type)_ulonglong; \ + do { \ + *--t = digs[_n % base]; \ + _n /= base; \ + } while (_n); \ + } + if (flags&LONGDBL) + CONVERT(ullong) /* no ; */ + else + CONVERT(unsigned long) /* no ; */ +#undef CONVERT + if (flags & ALT && base == 8 && *t != '0') + *--t = '0'; /* octal leading 0 */ + } + + digs = "0123456789abcdef"; + 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 */ + for (n = size; n > 0; n--) + 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 ldouble pten[] = +{ + 1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L +}; + +// 1e512L, 1e1024L, 1e2048L, 1e4096L + +static ldouble 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 ldouble INVPREC = P; +static ldouble 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(ldouble number, int prec, int flags, char *signp, unsigned char fmtch, + char *startp, char *endp) +{ + char *p, *t; + ldouble fract=0; + int dotrim, expcnt, gformat; + int doextradps=0; /* Do extra decimal places if the precision needs it */ + int doingzero=0; /* We're displaying 0.0 */ + ldouble 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 + ldouble 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); + /* If integer is zero then we need to look at where the sig figs are */ + if (integer<1) { + /* If fract is zero the zero before the decimal point is a sig fig */ + if (fract==0.0) doingzero=1; + /* If fract is non-zero all sig figs are in fractional part */ + else doextradps=1; + } + /* + * 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((ldouble)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 + ldouble 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': + if (prec) { + /* If doing zero and precision is greater than 0 count the + * 0 before the decimal place */ + if (doingzero) --prec; + } + else { + /* a precision of 0 is treated as precision of 1 unless doing zero */ + if (!doingzero) ++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); + /* If we're not adding 0s + * or we are but they're sig figs: + * decrement the precision */ + if ((doextradps!=1) || ((int)tmp!=0)) { + doextradps=0; + 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(ldouble fract, int *expv, char *start, char *end, char ch, + char *signp) +{ + ldouble 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(ldouble d, char *bufp) +{ + struct IEEExp { + unsigned manl:32; + unsigned manh:32; + unsigned exp:15; + unsigned sign:1; + } *ip = (struct IEEExp *)&d; + + _nan = 0; /* don't assume the static is 0 (emacs) */ + if (ip->exp != 0x7fff) + return(0); + if ((ip->manh & 0x7fffffff) || ip->manl) + { + strcpy(bufp, "NaN"); + _nan = ip->sign ? -1 : 1; /* kludge: we don't need the sign, it's not nice + but it should work */ + } + else + (void)strcpy(bufp, "Inf"); + return(3); +} + + + diff --git a/reactos/lib/crtdll/stdio/vfscanf.c b/reactos/lib/crtdll/stdio/vfscanf.c new file mode 100644 index 00000000000..207a7847dcf --- /dev/null +++ b/reactos/lib/crtdll/stdio/vfscanf.c @@ -0,0 +1,1081 @@ +/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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. + + The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* The internal entry points for `strtoX' take an extra flag argument + saying whether or not to parse locale-dependent number grouping. */ + +double __strtod_internal (const char *__nptr,char **__endptr, int __group); +float __strtof_internal (const char *__nptr, char **__endptr,int __group); +long double __strtold_internal (const char *__nptr,char **__endptr, int __group); +long int __strtol_internal (const char *__nptr, char **__endptr, int __base, int __group); +unsigned long int __strtoul_internal (const char *__nptr, char **__endptr, int __base, int __group); + + + +#ifdef __GNUC__ +#define HAVE_LONGLONG +#define LONGLONG long long +#else +#define LONGLONG long +#endif + +/* Those are flags in the conversion format. */ +# define LONG 0x001 /* l: long or double */ +# define LONGDBL 0x002 /* L: long long or long double */ +# define SHORT 0x004 /* h: short */ +# define SUPPRESS 0x008 /* *: suppress assignment */ +# define POINTER 0x010 /* weird %p pointer (`fake hex') */ +# define NOSKIP 0x020 /* do not skip blanks */ +# define WIDTH 0x040 /* width was given */ +# define GROUP 0x080 /* ': group numbers */ +# define MALLOC 0x100 /* a: malloc strings */ + +# define TYPEMOD (LONG|LONGDBL|SHORT) + + + +# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s)) +# define inchar() ((c = getc (s)), (void) (c != EOF && ++read_in), c) +# define encode_error() do { \ + funlockfile (s); \ + __set_errno (EILSEQ); \ + return done; \ + } while (0) +# define conv_error() do { \ + funlockfile (s); \ + return done; \ + } while (0) +# define input_error() do { \ + funlockfile (s); \ + return done ? 0 : EOF; \ + } while (0) +# define memory_error() do { \ + funlockfile (s); \ + __set_errno (ENOMEM); \ + return EOF; \ + } while (0) +# define ARGCHECK(s, format) \ + do \ + { \ + /* Check file argument for consistence. */ \ + if (!__validfp (s) || !s->__mode.__read) \ + { \ + __set_errno (EBADF); \ + return EOF; \ + } \ + else if (format == NULL) \ + { \ + __set_errno (EINVAL); \ + return EOF; \ + } \ + } while (0) + +# define flockfile(S) /* nothing */ +# define funlockfile(S) /* nothing */ + +int __vfscanf (FILE *s, const char *format, va_list argptr) +{ + va_list arg; + register const char *f = format; + register unsigned char fc; /* Current character of the format. */ + register size_t done = 0; /* Assignments done. */ + register size_t read_in = 0; /* Chars read in. */ + register int c = 0; /* Last char read. */ + register int width; /* Maximum field width. */ + register int flags; /* Modifiers for current format element. */ + + /* Status for reading F-P nums. */ + char got_dot, got_e, negative; + /* If a [...] is a [^...]. */ + char not_in; + /* Base for integral numbers. */ + int base; + /* Signedness for integral numbers. */ + int number_signed; + /* Decimal point character. */ + wchar_t decimal = '.'; + /* The thousands character of the current locale. */ + wchar_t thousands = ','; + /* Integral holding variables. */ + union + { + long long int q; + unsigned long long int uq; + long int l; + unsigned long int ul; + } num; + /* Character-buffer pointer. */ + char *str = NULL; + wchar_t *wstr = NULL; + char **strptr = NULL; + size_t strsize = 0; + /* We must not react on white spaces immediately because they can + possibly be matched even if in the input stream no character is + available anymore. */ + int skip_space = 0; + /* Workspace. */ + char *tw; /* Temporary pointer. */ + char *wp = NULL; /* Workspace. */ + size_t wpmax = 0; /* Maximal size of workspace. */ + size_t wpsize; /* Currently used bytes in workspace. */ +#define ADDW(Ch) \ + do \ + { \ + if (wpsize == wpmax) \ + { \ + char *old = wp; \ + wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax; \ + wp = (char *) alloca (wpmax); \ + if (old != NULL) \ + memcpy (wp, old, wpsize); \ + } \ + wp[wpsize++] = (Ch); \ + } \ + while (0) + +#ifdef __va_copy + __va_copy (arg, argptr); +#else + arg = (va_list) argptr; +#endif + + + + /* Run through the format string. */ + while (*f != '\0') + { + unsigned int argpos; + /* Extract the next argument, which is of type TYPE. + For a %N$... spec, this is the Nth argument from the beginning; + otherwise it is the next argument after the state now in ARG. */ +#define ARG(type) va_arg(argptr,type) + + if (!isascii (*f)) + { + /* Non-ASCII, may be a multibyte. */ + int len = mblen (f, strlen (f)); + if (len > 0) + { + do + { + c = inchar (); + if (c == EOF) + input_error (); + else if (c != *f++) + { + ungetc (c, s); + conv_error (); + } + } + while (--len > 0); + continue; + } + } + + fc = *f++; + if (fc != '%') + { + /* Remember to skip spaces. */ + if (isspace (fc)) + { + skip_space = 1; + continue; + } + + /* Read a character. */ + c = inchar (); + + /* Characters other than format specs must just match. */ + if (c == EOF) + input_error (); + + /* We saw white space char as the last character in the format + string. Now it's time to skip all leading white space. */ + if (skip_space) + { + while (isspace (c)) + if (inchar () == EOF && errno == EINTR) + conv_error (); + skip_space = 0; + } + + if (c != fc) + { + ungetc (c, s); + conv_error (); + } + + continue; + } + + /* This is the start of the conversion string. */ + flags = 0; + + /* Initialize state of modifiers. */ + argpos = 0; + + /* Prepare temporary buffer. */ + wpsize = 0; + + /* Check for a positional parameter specification. */ + if (isdigit (*f)) + { + argpos = *f++ - '0'; + while (isdigit (*f)) + argpos = argpos * 10 + (*f++ - '0'); + if (*f == '$') + ++f; + else + { + /* Oops; that was actually the field width. */ + width = argpos; + flags |= WIDTH; + argpos = 0; + goto got_width; + } + } + + /* Check for the assignment-suppressing and the number grouping flag. */ + while (*f == '*' || *f == '\'') + switch (*f++) + { + case '*': + flags |= SUPPRESS; + break; + case '\'': + flags |= GROUP; + break; + } + + /* We have seen width. */ + if (isdigit (*f)) + flags |= WIDTH; + + /* Find the maximum field width. */ + width = 0; + while (isdigit (*f)) + { + width *= 10; + width += *f++ - '0'; + } + got_width: + if (width == 0) + width = -1; + + /* Check for type modifiers. */ + while (*f == 'h' || *f == 'l' || *f == 'L' || *f == 'a' || *f == 'q') + switch (*f++) + { + case 'h': + /* int's are short int's. */ + if (flags & TYPEMOD) + /* Signal illegal format element. */ + conv_error (); + flags |= SHORT; + break; + case 'l': + if (flags & (SHORT|LONGDBL)) + conv_error (); + else if (flags & LONG) + { + /* A double `l' is equivalent to an `L'. */ + flags &= ~LONG; + flags |= LONGDBL; + } + else + /* int's are long int's. */ + flags |= LONG; + break; + case 'q': + case 'L': + /* double's are long double's, and int's are long long int's. */ + if (flags & TYPEMOD) + /* Signal illegal format element. */ + conv_error (); + flags |= LONGDBL; + break; + case 'a': + if (flags & TYPEMOD) + /* Signal illegal format element. */ + conv_error (); + /* String conversions (%s, %[) take a `char **' + arg and fill it in with a malloc'd pointer. */ + flags |= MALLOC; + break; + } + + /* End of the format string? */ + if (*f == '\0') + conv_error (); + + /* We must take care for EINTR errors. */ + if (c == EOF && errno == EINTR) + input_error (); + + /* Find the conversion specifier. */ + fc = *f++; + if (skip_space || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n')) + { + /* Eat whitespace. */ + do + if (inchar () == EOF && errno == EINTR) + input_error (); + while (isspace (c)); + ungetc (c, s); + skip_space = 0; + } + + switch (fc) + { + case '%': /* Must match a literal '%'. */ + c = inchar (); + if (c != fc) + { + ungetc (c, s); + conv_error (); + } + break; + + case 'n': /* Answer number of assignments done. */ + /* Corrigendum 1 to ISO C 1990 describes the allowed flags + with the 'n' conversion specifier. */ + if (!(flags & SUPPRESS)) + { + /* Don't count the read-ahead. */ + if (flags & LONGDBL) + *ARG (long int *) = read_in; + else if (flags & LONG) + *ARG (long int *) = read_in; + else if (flags & SHORT) + *ARG (short int *) = read_in; + else + *ARG (int *) = read_in; + +#ifdef NO_BUG_IN_ISO_C_CORRIGENDUM_1 + /* We have a severe problem here. The ISO C standard + contradicts itself in explaining the effect of the %n + format in `scanf'. While in ISO C:1990 and the ISO C + Amendement 1:1995 the result is described as + + Execution of a %n directive does not effect the + assignment count returned at the completion of + execution of the f(w)scanf function. + + in ISO C Corrigendum 1:1994 the following was added: + + Subclause 7.9.6.2 + Add the following fourth example: + In: + #include + int d1, d2, n1, n2, i; + i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2); + the value 123 is assigned to d1 and the value3 to n1. + Because %n can never get an input failure the value + of 3 is also assigned to n2. The value of d2 is not + affected. The value 3 is assigned to i. + + We go for now with the historically correct code fro ISO C, + i.e., we don't count the %n assignments. When it ever + should proof to be wrong just remove the #ifdef above. */ + ++done; +#endif + } + break; + + case 'c': /* Match characters. */ + if ((flags & LONG) == 0) + { + if (!(flags & SUPPRESS)) + { + str = ARG (char *); + if (str == NULL) + conv_error (); + } + + c = inchar (); + if (c == EOF) + input_error (); + + if (width == -1) + width = 1; + + if (!(flags & SUPPRESS)) + { + do + *str++ = c; + while (--width > 0 && inchar () != EOF); + } + else + while (--width > 0 && inchar () != EOF); + + if (width > 0) + /* I.e., EOF was read. */ + --read_in; + + if (!(flags & SUPPRESS)) + ++done; + + break; + } + /* FALLTHROUGH */ + case 'C': + /* Get UTF-8 encoded wide character. Here we assume (as in + other parts of the libc) that we only have to handle + UTF-8. */ + { + wint_t val; + size_t cnt = 0; + int first = 1; + + if (!(flags & SUPPRESS)) + { + wstr = ARG (wchar_t *); + if (str == NULL) + conv_error (); + } + + do + { +#define NEXT_WIDE_CHAR(First) \ + c = inchar (); \ + if (c == EOF) { \ + /* EOF is only an error for the first character. */ \ + if (First) { \ + input_error (); \ + } \ + else \ + { \ + --read_in; \ + break; \ + } \ + } \ + val = c; \ + if (val >= 0x80) \ + { \ + if ((c & 0xc0) == 0x80 || (c & 0xfe) == 0xfe) \ + encode_error (); \ + if ((c & 0xe0) == 0xc0) \ + { \ + /* We expect two bytes. */ \ + cnt = 1; \ + val &= 0x1f; \ + } \ + else if ((c & 0xf0) == 0xe0) \ + { \ + /* We expect three bytes. */ \ + cnt = 2; \ + val &= 0x0f; \ + } \ + else if ((c & 0xf8) == 0xf0) \ + { \ + /* We expect four bytes. */ \ + cnt = 3; \ + val &= 0x07; \ + } \ + else if ((c & 0xfc) == 0xf8) \ + { \ + /* We expect five bytes. */ \ + cnt = 4; \ + val &= 0x03; \ + } \ + else \ + { \ + /* We expect six bytes. */ \ + cnt = 5; \ + val &= 0x01; \ + } \ + \ + do \ + { \ + c = inchar (); \ + if (c == EOF \ + || (c & 0xc0) == 0x80 || (c & 0xfe) == 0xfe) \ + encode_error (); \ + val <<= 6; \ + val |= c & 0x3f; \ + } \ + while (--cnt > 0); \ + } \ + \ + if (!(flags & SUPPRESS)) \ + *wstr++ = val; \ + first = 0 + + NEXT_WIDE_CHAR (first); + } + while (--width > 0); + + if (width > 0) + /* I.e., EOF was read. */ + --read_in; + + if (!(flags & SUPPRESS)) + ++done; + } + break; + + case 's': /* Read a string. */ + if (flags & LONG) + /* We have to process a wide character string. */ + goto wide_char_string; + +#define STRING_ARG(Str, Type) \ + if (!(flags & SUPPRESS)) \ + { \ + if (flags & MALLOC) \ + { \ + /* The string is to be stored in a malloc'd buffer. */ \ + strptr = ARG (char **); \ + if (strptr == NULL) \ + conv_error (); \ + /* Allocate an initial buffer. */ \ + strsize = 100; \ + *strptr = malloc (strsize * sizeof (Type)); \ + Str = (Type *) *strptr; \ + } \ + else \ + Str = ARG (Type *); \ + if (Str == NULL) \ + conv_error (); \ + } + STRING_ARG (str, char); + + c = inchar (); + if (c == EOF) + input_error (); + + do + { + if (isspace (c)) + { + ungetc (c, s); + break; + } +#define STRING_ADD_CHAR(Str, c, Type) \ + if (!(flags & SUPPRESS)) \ + { \ + *Str++ = c; \ + if ((flags & MALLOC) && (char *) Str == *strptr + strsize) \ + { \ + /* Enlarge the buffer. */ \ + Str = realloc (*strptr, strsize * 2 * sizeof (Type)); \ + if (Str == NULL) \ + { \ + /* Can't allocate that much. Last-ditch effort. */\ + Str = realloc (*strptr, \ + (strsize + 1) * sizeof (Type)); \ + if (Str == NULL) \ + { \ + /* We lose. Oh well. \ + Terminate the string and stop converting, \ + so at least we don't skip any input. */ \ + ((Type *) (*strptr))[strsize] = '\0'; \ + ++done; \ + conv_error (); \ + } \ + else \ + { \ + *strptr = (char *) Str; \ + Str = ((Type *) *strptr) + strsize; \ + ++strsize; \ + } \ + } \ + else \ + { \ + *strptr = (char *) Str; \ + Str = ((Type *) *strptr) + strsize; \ + strsize *= 2; \ + } \ + } \ + } + STRING_ADD_CHAR (str, c, char); + } while ((width <= 0 || --width > 0) && inchar () != EOF); + + if (!(flags & SUPPRESS)) + { + *str = '\0'; + ++done; + } + break; + + case 'S': + /* Wide character string. */ + wide_char_string: + { + wint_t val; + int first = 1; + STRING_ARG (wstr, wchar_t); + + do + { + size_t cnt = 0; + NEXT_WIDE_CHAR (first); + + if (iswspace (val)) + { + /* XXX We would have to push back the whole wide char + with possibly many bytes. But since scanf does + not make a difference for white space characters + we can simply push back a simple which is + guaranteed to be in the [:space:] class. */ + ungetc (' ', s); + break; + } + + STRING_ADD_CHAR (wstr, val, wchar_t); + first = 0; + } + while (width <= 0 || --width > 0); + + if (!(flags & SUPPRESS)) + { + *wstr = L'\0'; + ++done; + } + } + break; + + case 'x': /* Hexadecimal integer. */ + case 'X': /* Ditto. */ + base = 16; + number_signed = 0; + goto number; + + case 'o': /* Octal integer. */ + base = 8; + number_signed = 0; + goto number; + + case 'u': /* Unsigned decimal integer. */ + base = 10; + number_signed = 0; + goto number; + + case 'd': /* Signed decimal integer. */ + base = 10; + number_signed = 1; + goto number; + + case 'i': /* Generic number. */ + base = 0; + number_signed = 1; + + number: + c = inchar (); + if (c == EOF) + input_error (); + + /* Check for a sign. */ + if (c == '-' || c == '+') + { + ADDW (c); + if (width > 0) + --width; + c = inchar (); + } + + /* Look for a leading indication of base. */ + if (width != 0 && c == '0') + { + if (width > 0) + --width; + + ADDW (c); + c = inchar (); + + if (width != 0 && tolower (c) == 'x') + { + if (base == 0) + base = 16; + if (base == 16) + { + if (width > 0) + --width; + c = inchar (); + } + } + else if (base == 0) + base = 8; + } + + if (base == 0) + base = 10; + + /* Read the number into workspace. */ + while (c != EOF && width != 0) + { + if (base == 16 ? !isxdigit (c) : + ((!isdigit (c) || c - '0' >= base) && + !((flags & GROUP) && base == 10 && c == thousands))) + break; + ADDW (c); + if (width > 0) + --width; + + c = inchar (); + } + + /* The just read character is not part of the number anymore. */ + ungetc (c, s); + + if (wpsize == 0 || + (wpsize == 1 && (wp[0] == '+' || wp[0] == '-'))) + /* There was no number. */ + conv_error (); + + /* Convert the number. */ + ADDW ('\0'); + if (flags & LONGDBL) + { +// if (number_signed) +// num.q = __strtoq_internal (wp, &tw, base, flags & GROUP); +// else +// num.uq = __strtouq_internal (wp, &tw, base, flags & GROUP); + } + else + { + if (number_signed) + num.l = __strtol_internal (wp, &tw, base, flags & GROUP); + else + num.ul = __strtoul_internal (wp, &tw, base, flags & GROUP); + } + if (wp == tw) + conv_error (); + + if (!(flags & SUPPRESS)) + { + if (! number_signed) + { + if (flags & LONGDBL) { + *ARG (unsigned LONGLONG int *) = num.uq; + } + else if (flags & LONG) + *ARG (unsigned long int *) = num.ul; + else if (flags & SHORT) + *ARG (unsigned short int *) = (unsigned short int) num.ul; + else + *ARG (unsigned int *) = (unsigned int) num.ul; + } + else + { + if (flags & LONGDBL) { + *ARG (LONGLONG int *) = num.q; + } + else if (flags & LONG) + *ARG (long int *) = num.l; + else if (flags & SHORT) + *ARG (short int *) = (short int) num.l; + else + *ARG (int *) = (int) num.l; + } + ++done; + } + break; + + case 'e': /* Floating-point numbers. */ + case 'E': + case 'f': + case 'g': + case 'G': + c = inchar (); + if (c == EOF) + input_error (); + + /* Check for a sign. */ + if (c == '-' || c == '+') + { + negative = c == '-'; + if (inchar () == EOF) + /* EOF is only an input error before we read any chars. */ + conv_error (); + if (width > 0) + --width; + } + else + negative = 0; + + got_dot = got_e = 0; + do + { + if (isdigit (c)) + ADDW (c); + else if (got_e && wp[wpsize - 1] == 'e' + && (c == '-' || c == '+')) + ADDW (c); + else if (wpsize > 0 && !got_e && tolower (c) == 'e') + { + ADDW ('e'); + got_e = got_dot = 1; + } + else if (c == decimal && !got_dot) + { + ADDW (c); + got_dot = 1; + } + else if ((flags & GROUP) && c == thousands && !got_dot) + ADDW (c); + else + { + /* The last read character is not part of the number + anymore. */ + ungetc (c, s); + break; + } + if (width > 0) + --width; + } + while (width != 0 && inchar () != EOF); + + if (wpsize == 0) + conv_error (); + + /* Convert the number. */ + ADDW ('\0'); + if (flags & LONGDBL) + { + long double d = __strtold_internal (wp, &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != wp) + *ARG (long double *) = negative ? -d : d; + } + else if (flags & LONG) + { + double d = __strtod_internal (wp, &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != wp) + *ARG (double *) = negative ? -d : d; + } + else + { + float d = __strtof_internal (wp, &tw, flags & GROUP); + if (!(flags & SUPPRESS) && tw != wp) + *ARG (float *) = negative ? -d : d; + } + + if (tw == wp) + conv_error (); + + if (!(flags & SUPPRESS)) + ++done; + break; + + case '[': /* Character class. */ + if (flags & LONG) + { + STRING_ARG (wstr, wchar_t); + c = '\0'; /* This is to keep gcc quiet. */ + } + else + { + STRING_ARG (str, char); + + c = inchar (); + if (c == EOF) + input_error (); + } + + if (*f == '^') + { + ++f; + not_in = 1; + } + else + not_in = 0; + + /* Fill WP with byte flags indexed by character. + We will use this flag map for matching input characters. */ + if (wpmax < UCHAR_MAX) + { + wpmax = UCHAR_MAX; + wp = (char *) alloca (wpmax); + } + memset (wp, 0, UCHAR_MAX); + + fc = *f; + if (fc == ']' || fc == '-') + { + /* If ] or - appears before any char in the set, it is not + the terminator or separator, but the first char in the + set. */ + wp[fc] = 1; + ++f; + } + + while ((fc = *f++) != '\0' && fc != ']') + { + if (fc == '-' && *f != '\0' && *f != ']' && + (unsigned char) f[-2] <= (unsigned char) *f) + { + /* Add all characters from the one before the '-' + up to (but not including) the next format char. */ + for (fc = f[-2]; fc < *f; ++fc) + wp[fc] = 1; + } + else + /* Add the character to the flag map. */ + wp[fc] = 1; + } + if (fc == '\0') + { + if (!(flags & LONG)) + ungetc (c, s); + conv_error(); + } + + if (flags & LONG) + { + wint_t val; + int first = 1; + + do + { + size_t cnt = 0; + NEXT_WIDE_CHAR (first); + if (val > 255 || wp[val] == not_in) + { + /* XXX We have a problem here. We read a wide + character and this possibly took several + bytes. But we can only push back one single + character. To be sure we don't create wrong + input we push it back only in case it is + representable within one byte. */ + if (val < 0x80) + ungetc (val, s); + break; + } + STRING_ADD_CHAR (wstr, val, wchar_t); + if (width > 0) + --width; + first = 0; + } + while (width != 0); + + if (first) + conv_error (); + + if (!(flags & SUPPRESS)) + { + *wstr = L'\0'; + ++done; + } + } + else + { + num.ul = read_in - 1; /* -1 because we already read one char. */ + do + { + if (wp[c] == not_in) + { + ungetc (c, s); + break; + } + STRING_ADD_CHAR (str, c, char); + if (width > 0) + --width; + } + while (width != 0 && inchar () != EOF); + + if (read_in == num.ul) + conv_error (); + + if (!(flags & SUPPRESS)) + { + *str = '\0'; + ++done; + } + } + break; + + case 'p': /* Generic pointer. */ + base = 16; + /* A PTR must be the same size as a `long int'. */ + flags &= ~(SHORT|LONGDBL); + flags |= LONG; + number_signed = 0; + goto number; + } + } + + /* The last thing we saw int the format string was a white space. + Consume the last white spaces. */ + if (skip_space) + { + do + c = inchar (); + while (isspace (c)); + ungetc (c, s); + } + + + return done; +} + + + +int +xfscanf(FILE *f, const char *fmt, ...) +{ + int r; + va_list a=0; + va_start(a, fmt); + r = __vfscanf(f, fmt, a); + va_end(a); + return r; +} + + +double __strtod_internal (const char *__nptr,char **__endptr, int __group) +{ + return strtod(__nptr,__endptr); +} +float __strtof_internal (const char *__nptr, char **__endptr,int __group) +{ + return strtod(__nptr,__endptr); +} +long double __strtold_internal (const char *__nptr,char **__endptr, int __group) +{ + return strtod(__nptr,__endptr); +// return strtold(__nptr,__endptr); +} +long int __strtol_internal (const char *__nptr, char **__endptr, int __base, int __group) +{ + return strtol(__nptr,__endptr, __base); +} +unsigned long int __strtoul_internal (const char *__nptr, char **__endptr, int __base, int __group) +{ + return strtoul(__nptr,__endptr, __base); +} + + + + + + + + + diff --git a/reactos/lib/crtdll/stdio/vprintf.c b/reactos/lib/crtdll/stdio/vprintf.c index dba04f44db1..a576c44b342 100644 --- a/reactos/lib/crtdll/stdio/vprintf.c +++ b/reactos/lib/crtdll/stdio/vprintf.c @@ -1,13 +1,35 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include +/* Copyright (C) 1991, 1993, 1995 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + #include -#include +#undef __OPTIMIZE__ /* Avoid inline `vprintf' function. */ +#include +#undef vprintf + +/* Write formatted output to stdout according to the + format string FORMAT, using the argument list in ARG. */ int -vprintf(const char *fmt, va_list ap) +vprintf (format, arg) + const char *format; + va_list arg; { - int len; - - len = _doprnt(fmt, ap, stdout); - return (ferror(stdout) ? EOF : len); + int ret = vfprintf (stdout, format, arg); + fflush(stdout); + return ret; } diff --git a/reactos/lib/crtdll/stdio/vscanf.c b/reactos/lib/crtdll/stdio/vscanf.c new file mode 100644 index 00000000000..288e365ec94 --- /dev/null +++ b/reactos/lib/crtdll/stdio/vscanf.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include + +int __vfscanf (FILE *s, const char *format, va_list argptr); + +#undef vscanf + + +/* Read formatted input from stdin according to the format + string in FORMAT, using the argument list in ARG. */ +int +__vscanf (const char *format, va_list arg) +{ + return __vfscanf (stdin, format, arg); +} +//weak_alias (__vscanf, vscanf) \ No newline at end of file diff --git a/reactos/lib/crtdll/stdio/vsprintf.c b/reactos/lib/crtdll/stdio/vsprintf.c index c1b1c4f7b98..7c7e59186f9 100644 --- a/reactos/lib/crtdll/stdio/vsprintf.c +++ b/reactos/lib/crtdll/stdio/vsprintf.c @@ -4,6 +4,7 @@ #include #include +int vsprintf(char *str, const char *fmt, va_list ap) { FILE f; @@ -12,7 +13,7 @@ vsprintf(char *str, const char *fmt, va_list ap) f._flag = _IOWRT|_IOSTRG; f._ptr = str; f._cnt = INT_MAX; - len = _doprnt(fmt, ap, &f); + len = vfprintf(&f,fmt, ap); *f._ptr = 0; return len; } diff --git a/reactos/lib/crtdll/stdio/vsscanf.c b/reactos/lib/crtdll/stdio/vsscanf.c new file mode 100644 index 00000000000..5f0ba7c2bcc --- /dev/null +++ b/reactos/lib/crtdll/stdio/vsscanf.c @@ -0,0 +1,57 @@ +/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include +#include + +#undef vsscanf + +int __vfscanf (FILE *s, const char *format, va_list argptr); + +/* Read formatted input from S according to the format + string FORMAT, using the argument list in ARG. */ +int +__vsscanf (const char *s,const char *format,va_list arg) +{ + FILE f; + + if (s == NULL) + { + __set_errno (EINVAL); + return -1; + } + + memset ((void *) &f, 0, sizeof (f)); + + + + f._flag = _IOREAD; + f._ptr = (char *)s; + f._base = (char *)s; + f._bufsiz = strlen(s); + f._cnt = f._bufsiz; + + + return __vfscanf (&f, format, arg); +} + + +//weak_alias (__vsscanf, vsscanf) \ No newline at end of file diff --git a/reactos/lib/crtdll/stdlib/malloc.c b/reactos/lib/crtdll/stdlib/malloc.c index f1792be6902..582b9b68151 100644 --- a/reactos/lib/crtdll/stdlib/malloc.c +++ b/reactos/lib/crtdll/stdlib/malloc.c @@ -1,33 +1,23 @@ #include #include -//#include -#include + void* malloc(size_t _size) { - return(HeapAlloc(GetProcessHeap(), - 0, - _size)); + return(HeapAlloc(GetProcessHeap(),0,_size)); } void free(void* _ptr) { - HeapFree(GetProcessHeap(), - 0, - _ptr); + HeapFree(GetProcessHeap(),0,_ptr); } void* calloc(size_t _nmemb, size_t _size) { - return(HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - _nmemb*_size)); + return(HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, _nmemb*_size)); } void* realloc(void* _ptr, size_t _size) { - return(HeapReAlloc(GetProcessHeap(), - 0, - _ptr, - _size)); + return(HeapReAlloc(GetProcessHeap(),0,_ptr,_size)); } diff --git a/reactos/lib/crtdll/stdlib/rot.c b/reactos/lib/crtdll/stdlib/rot.c new file mode 100644 index 00000000000..608aa732d92 --- /dev/null +++ b/reactos/lib/crtdll/stdlib/rot.c @@ -0,0 +1,56 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/stdlib/rot.c + * PURPOSE: Performs a bit wise rotation + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 03/04/99: Created + */ + +#include + +unsigned int _rotl( unsigned int value, int shift ) +{ + int max_bits = sizeof(unsigned int)<<3; + if ( shift < 0 ) + return _rotr(value,-shift); + + if ( shift > max_bits ) + shift = shift % max_bits; + return (value << shift) | (value >> (max_bits-shift)); +} + +unsigned int _rotr( unsigned int value, int shift ) +{ + int max_bits = sizeof(unsigned int)<<3; + if ( shift < 0 ) + return _rotl(value,-shift); + + if ( shift > max_bits<<3 ) + shift = shift % max_bits; + return (value >> shift) | (value << (max_bits-shift)); +} + + +unsigned long _lrotl( unsigned long value, int shift ) +{ + int max_bits = sizeof(unsigned long)<<3; + if ( shift < 0 ) + return _lrotr(value,-shift); + + if ( shift > max_bits ) + shift = shift % max_bits; + return (value << shift) | (value >> (max_bits-shift)); +} + +unsigned long _lrotr( unsigned long value, int shift ) +{ + int max_bits = sizeof(unsigned long)<<3; + if ( shift < 0 ) + return _lrotl(value,-shift); + + if ( shift > max_bits ) + shift = shift % max_bits; + return (value >> shift) | (value << (max_bits-shift)); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/string/strcoll.c b/reactos/lib/crtdll/string/strcoll.c index 1d08be51ce6..0751b9d5add 100644 --- a/reactos/lib/crtdll/string/strcoll.c +++ b/reactos/lib/crtdll/string/strcoll.c @@ -1,8 +1,18 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include #include - +/* Compare S1 and S2, returning less than, equal to or + greater than zero if the collated form of S1 is lexicographically + less than, equal to or greater than the collated form of S2. */ int -strcoll(const char *s1, const char *s2) +strcoll (const char *s1,const char *s2) { - return strcmp(s1, s2); + int ret = CompareStringA(LOCALE_USER_DEFAULT,0,s1,strlen(s1),s2,strlen(s2)); + if ( ret == 0 ) + return 0; + + else + return ret - 2; + + return 0; + } diff --git a/reactos/lib/crtdll/string/strxfrm.c b/reactos/lib/crtdll/string/strxfrm.c index 2c2495c4744..65fceca7bec 100644 --- a/reactos/lib/crtdll/string/strxfrm.c +++ b/reactos/lib/crtdll/string/strxfrm.c @@ -1,25 +1,16 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include #include -size_t -strxfrm(char *dst,const char *src, size_t n) +size_t strxfrm( char *dest, const char *src, size_t n ) { - size_t r = 0; - int c; + + int ret = LCMapStringA(LOCALE_USER_DEFAULT,LCMAP_LOWERCASE, + src, strlen(src), + dest, strlen(dest) ); - if (n != 0) { - while ((c = *src++) != 0) - { - r++; - if (--n == 0) - { - while (*src++ != 0) - r++; - break; - } - *dst++ = c; - } - *dst = 0; - } - return r; -} + + if ( ret == 0 ) + return -1; + return ret; + +} \ No newline at end of file diff --git a/reactos/lib/crtdll/sys_stat/futime.c b/reactos/lib/crtdll/sys_stat/futime.c new file mode 100644 index 00000000000..4b1b52786a4 --- /dev/null +++ b/reactos/lib/crtdll/sys_stat/futime.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +int _futime (int nHandle, struct _utimbuf *pTimes) +{ + FILETIME LastAccessTime; + FILETIME LastWriteTime; + UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0); + UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0); + if ( !SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime) ) + return -1; + + return 0; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/wchar/wcscat.c b/reactos/lib/crtdll/wchar/wcscat.c index e2787a8a2b5..dc2a39e18dd 100644 --- a/reactos/lib/crtdll/wchar/wcscat.c +++ b/reactos/lib/crtdll/wchar/wcscat.c @@ -5,15 +5,15 @@ wchar_t * wcscat(wchar_t * dest,const wchar_t * src) { - int i,j; - j=0; - for (i=0; dest[i]!=0; i++); - while (src[j] != 0) + wchar_t *d = dest; + for (; *dest !=0; dest++); + while (*src != 0) { - dest[i+j] = src[j]; - j++; + *dest = *src; + dest++; + src++; } - dest[i+j] = 0; - return dest; + *dest = 0; + return d; } diff --git a/reactos/lib/crtdll/wchar/wcscoll.c b/reactos/lib/crtdll/wchar/wcscoll.c index 5dac0268621..cbebef173f1 100644 --- a/reactos/lib/crtdll/wchar/wcscoll.c +++ b/reactos/lib/crtdll/wchar/wcscoll.c @@ -1,12 +1,4 @@ -/* - * The C RunTime DLL - * - * Implements C run-time functionality as known from UNIX. - * - * Copyright 1996,1998 Marcus Meissner - * Copyright 1996 Jukka Iivonen - * Copyright 1997 Uwe Bonnes - */ + #include @@ -15,3 +7,11 @@ int wcscoll(const wchar_t *a1,const wchar_t *a2) /* FIXME: handle collates */ return wcscmp(a1,a2); } + + +int _wcsicoll(const wchar_t *a1,const wchar_t *a2) +{ + /* FIXME: handle collates */ + return wcscmp(a1,a2); +} + diff --git a/reactos/lib/crtdll/wchar/wcsdup.c b/reactos/lib/crtdll/wchar/wcsdup.c index c6db721bec4..6d9f216b98a 100644 --- a/reactos/lib/crtdll/wchar/wcsdup.c +++ b/reactos/lib/crtdll/wchar/wcsdup.c @@ -1,12 +1,16 @@ #include +#include +#include wchar_t *_wcsdup(const wchar_t *ptr) { wchar_t *dup; dup = malloc((wcslen(ptr) + 1)*sizeof(wchar_t)); - if( dup == NULL ) + if( dup == NULL ) { + __set_errno(ENOMEM); return NULL; + } wcscpy(dup,ptr); return dup; } diff --git a/reactos/lib/crtdll/wchar/wcslen.c b/reactos/lib/crtdll/wchar/wcslen.c index 6c400818529..df294b82a43 100644 --- a/reactos/lib/crtdll/wchar/wcslen.c +++ b/reactos/lib/crtdll/wchar/wcslen.c @@ -19,3 +19,5 @@ size_t wstrlen(const wchar_t *s) } + + diff --git a/reactos/lib/crtdll/wchar/wcsncat.c b/reactos/lib/crtdll/wchar/wcsncat.c index a76fb0f9481..85d0d81718a 100644 --- a/reactos/lib/crtdll/wchar/wcsncat.c +++ b/reactos/lib/crtdll/wchar/wcsncat.c @@ -1,20 +1,21 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -wchar_t * wcsncat(wchar_t * dest,const wchar_t * src,size_t count) +wchar_t *wcsncat(wchar_t *dst, const wchar_t *src, size_t n) { - int i,j; - if ( count != 0 ) { - - for (j=0;dest[j]!=0;j++); + if (n != 0) + { + wchar_t *d = dst; + const wchar_t *s = src; - for (i=0;i -wchar_t * _wcsncpy(wchar_t * dest,const wchar_t *src,size_t count) +wchar_t * wcsncpy(wchar_t * dest,const wchar_t *src,size_t count) { int i; diff --git a/reactos/lib/crtdll/wchar/wcspbrk.c b/reactos/lib/crtdll/wchar/wcspbrk.c new file mode 100644 index 00000000000..8d126bcacf8 --- /dev/null +++ b/reactos/lib/crtdll/wchar/wcspbrk.c @@ -0,0 +1,5 @@ +#include + +wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2) +{ +} \ No newline at end of file diff --git a/reactos/lib/crtdll/wchar/wcsset.c b/reactos/lib/crtdll/wchar/wcsset.c new file mode 100644 index 00000000000..7ff176361f4 --- /dev/null +++ b/reactos/lib/crtdll/wchar/wcsset.c @@ -0,0 +1,27 @@ +#inlcude + +wchar_t* _wcsnset (wchar_t* wsToFill, wchar_t wcFill, size_t sizeMaxFill) +{ + wchar_t *t = wsToFill; + int i = 0; + while( *wsToFill != 0 && i < sizeMaxFill) + { + *wsToFill = wcFill; + wsToFill++; + i++; + + } + return t; +} + +wchar_t* _wcsset (wchar_t* wsToFill, wchar_t wcToFill) +{ + wchar_t *t = wsToFill; + while( *wsToFill != 0 ) + { + *wsToFill = wcFill; + wsToFill++; + + } + return t; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/wchar/wcsspn.c b/reactos/lib/crtdll/wchar/wcsspn.c index 89d420aa3b3..5ae0df0c283 100644 --- a/reactos/lib/crtdll/wchar/wcsspn.c +++ b/reactos/lib/crtdll/wchar/wcsspn.c @@ -1,6 +1,6 @@ #include -size_t _wcsspn(const wchar_t *str,const wchar_t *accept) +size_t wcsspn(const wchar_t *str,const wchar_t *accept) { wchar_t *s; wchar_t *t; diff --git a/reactos/lib/crtdll/wchar/wcstod.c b/reactos/lib/crtdll/wchar/wcstod.c new file mode 100644 index 00000000000..b55c392cce0 --- /dev/null +++ b/reactos/lib/crtdll/wchar/wcstod.c @@ -0,0 +1,6 @@ +#include + +double wcstod(const wchar_t *nptr, wchar_t **endptr) +{ + return 0.0; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/wchar/wcstok.c b/reactos/lib/crtdll/wchar/wcstok.c index 3afd7174d03..19e0e7fe6c1 100644 --- a/reactos/lib/crtdll/wchar/wcstok.c +++ b/reactos/lib/crtdll/wchar/wcstok.c @@ -1,6 +1,6 @@ #include -wchar_t *wcstok(wchar_t *s, const wchar_t *ct) +wchar_t *_wcstok(wchar_t *s, const wchar_t *ct) { const wchar_t *spanp; int c, sc; diff --git a/reactos/lib/crtdll/wchar/wcstombs.c b/reactos/lib/crtdll/wchar/wcstombs.c index a04f53e487f..6cb254ea82b 100644 --- a/reactos/lib/crtdll/wchar/wcstombs.c +++ b/reactos/lib/crtdll/wchar/wcstombs.c @@ -1,6 +1,6 @@ -// copy a wide character string to a multibyte string -size_t __cdecl wcstombs( char *dst, const wchar_t *src, size_t len ) + + +size_t wcstombs( char *dst, const wchar_t *src, size_t len ) { - lstrcpynWtoA( dst, src, len ); - return strlen(dst); /* FIXME: is this right? */ + return 0; } diff --git a/reactos/lib/crtdll/wchar/wcsxfrm.c b/reactos/lib/crtdll/wchar/wcsxfrm.c index f86a2b8712d..0fd6c6bf1f6 100644 --- a/reactos/lib/crtdll/wchar/wcsxfrm.c +++ b/reactos/lib/crtdll/wchar/wcsxfrm.c @@ -1,6 +1,23 @@ #include -size_t wcsxfrm( wchar_t *str1, const wchar_t *str2, size_t len ) +size_t _wcsxfrm(char *dst,const char *src, size_t n) { - return 0; + 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; } \ No newline at end of file