ntdll:
authorGunnar Dalsnes <hardon@online.no>
Wed, 16 Feb 2005 22:30:50 +0000 (22:30 +0000)
committerGunnar Dalsnes <hardon@online.no>
Wed, 16 Feb 2005 22:30:50 +0000 (22:30 +0000)
-critical.c: catch (more) invalid use
-impl. sscanf (stolen from wine)
crt:
-use native mingw headers and not private copies of them
-converted some routines to using tchar == impl. many missing unicode routines
-impl. sscanf and friends correctly (stolen from wine)
tchar.h:
-added lotsa missin stuff

svn path=/trunk/; revision=13609

reactos/lib/crtdll/crtdll.def
reactos/lib/crtdll/dllmain.c
reactos/lib/msvcrt/dllmain.c
reactos/lib/msvcrt/msvcrt.def
reactos/lib/ntdll/rtl/critical.c
reactos/lib/ntdll/stdio/scanf.h [new file with mode: 0644]
reactos/lib/ntdll/stdio/sscanf.c
reactos/lib/ntdll/stdlib/bsearch.c
reactos/lib/ntdll/stdlib/lfind.c

index 22c89ef..f184df9 100644 (file)
@@ -145,7 +145,7 @@ _findnext
 _finite
 _flsbuf
 _flushall
-_fmode_dll=__fmode DATA
+_fmode_dll=_fmode DATA
 _fpclass
 _fpieee_flt
 _fpreset
index 3607c4b..0b38ee0 100644 (file)
@@ -22,7 +22,7 @@
 \r
 #include "precomp.h"\r
 #include <msvcrt/internal/tls.h>\r
-#include <msvcrt/stdlib.h>\r
+#include <stdlib.h>\r
 #include <msvcrt/wine/msvcrt.h>\r
 #include <sys/stat.h>\r
 \r
index 091f5eb..5c32a1f 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "precomp.h"
 #include <msvcrt/internal/tls.h>
-#include <msvcrt/stdlib.h>
+#include <stdlib.h>
 #include <msvcrt/wine/msvcrt.h>
 
 #define NDEBUG
@@ -66,7 +66,8 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
     {
     case DLL_PROCESS_ATTACH://1
         /* initialize version info */
-        DPRINT("Attach %d\n", nAttachCount);
+        //DPRINT1("Process Attach %d\n", nAttachCount);
+        //DPRINT1("Process Attach\n");
         _osver = GetVersion();
         _winmajor = (_osver >> 8) & 0xFF;
         _winminor = _osver & 0xFF;
@@ -110,7 +111,8 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
         break;
 
     case DLL_PROCESS_DETACH://0
-        DPRINT("Detach %d\n", nAttachCount);
+        //DPRINT1("Detach %d\n", nAttachCount);
+        //DPRINT("Detach\n");
         /* FIXME: more cleanup... */
         _fcloseall();
 
index cc17d63..1156b11 100644 (file)
@@ -92,24 +92,24 @@ _Gettnames
 _HUGE DATA
 _Strftime
 _XcptFilter
-;__CxxCallUnwindDtor
+__CxxCallUnwindDtor=stub
 __CxxDetectRethrow
-;__CxxExceptionFilter
+__CxxExceptionFilter=stub
 __CxxFrameHandler
-;__CxxLongjmpUnwind
+__CxxLongjmpUnwind=stub
 __CxxQueryExceptionSize
-;__CxxRegisterExceptionObject
-;__CxxUnregisterExceptionObject
-;__DestructExceptionObject
+__CxxRegisterExceptionObject=stub
+__CxxUnregisterExceptionObject=stub
+__DestructExceptionObject=stub
 __RTCastToVoid=MSVCRT___RTCastToVoid
 __RTDynamicCast=MSVCRT___RTDynamicCast
 __RTtypeid=MSVCRT___RTtypeid
-;__STRINGTOLD
+__STRINGTOLD=stub
 __argc DATA
 __argv DATA
 __badioinfo DATA
-;__crtCompareStringA ;=NTDLL.RtlCompareString
-;__crtGetLocaleInfoW
+__crtCompareStringA
+__crtGetLocaleInfoW
 __crtLCMapStringA
 __dllonexit
 __doserrno
@@ -122,37 +122,37 @@ __iscsymf
 __lc_codepage
 __lc_collate_cp
 __lc_handle
-;__lconv_init
+__lconv_init
 __mb_cur_max DATA
 __p___argc
 __p___argv
-;__p___wargv
+__p___wargv
 __p___initenv
 __p___mb_cur_max
 __p___winitenv
 __p__acmdln
-;__p__amblksiz
+__p__amblksiz
 __p__commode
-;__p__daylight
-;__p__dstbias
+__p__daylight
+__p__dstbias
 __p__environ
-;__p__fileinfo
+__p__fileinfo=stub
 __p__fmode
 __p__iob
-;__p__mbcasemap
-;__p__mbctype
+__p__mbcasemap=stub
+__p__mbctype=stub
 __p__osver
 __p__pctype
 __p__pgmptr
 __p__pwctype
-;__p__timezone
-;__p__tzname
-;__p__wcmdln
+__p__timezone
+__p__tzname=stub
+__p__wcmdln=stub
 __p__wenviron
 __p__winmajor
 __p__winminor
 __p__winver
-;__p__wpgmptr
+__p__wpgmptr=stub
 __pioinfo
 __pxcptinfoptrs
 __set_app_type
@@ -161,65 +161,65 @@ __setusermatherr
 __threadhandle
 __threadid
 __toascii
-;__unDName
-;__unDNameEx
+__unDName=stub
+__unDNameEx=stub
 __unguarded_readlc_active DATA
 __wargv
 __wgetmainargs
 __winitenv
-;___lc_codepage_func
-;___lc_handle_func
-;___mb_cur_max_func
-;___setlc_active_func
-;___unguarded_readlc_active_add_func
-;__crtCompareStringW
-;__crtGetStringTypeW
-;__crtLCMapStringW
-;__iob_func
-;__pctype_func
-;__uncaught_exception
-;__wcserror
+___lc_codepage_func=stub
+___lc_handle_func=stub
+___mb_cur_max_func=stub
+___setlc_active_func=stub
+___unguarded_readlc_active_add_func=stub
+__crtCompareStringW=stub
+__crtGetStringTypeW=stub
+__crtLCMapStringW=stub
+__iob_func=stub
+__pctype_func=stub
+__uncaught_exception=stub
+__wcserror=stub
 _abnormal_termination
 _access
 _acmdln DATA
-;_adj_fdiv_m16i
+_adj_fdiv_m16i=stub
 _adj_fdiv_m32 = _adj_fdiv_m32@4
 _adj_fdiv_m32i = _adj_fdiv_m32i@4
 _adj_fdiv_m64 = _adj_fdiv_m64@8
 _adj_fdiv_r
-;_adj_fdivr_m16i
+_adj_fdivr_m16i=stub
 _adj_fdivr_m32 = _adj_fdivr_m32@4
 _adj_fdivr_m32i = _adj_fdivr_m32i@4
 _adj_fdivr_m64 = _adj_fdivr_m64@8
 _adj_fpatan
-;_adj_fprem
-;_adj_fprem1
-;_adj_fptan
+_adj_fprem=stub
+_adj_fprem1=stub
+_adj_fptan=stub
 _adjust_fdiv DATA
 _aexit_rtn
-;_aligned_free
-;_aligned_malloc
-;_aligned_offset_malloc
-;_aligned_offset_realloc
-;_aligned_realloc
+_aligned_free=stub
+_aligned_malloc=stub
+_aligned_offset_malloc=stub
+_aligned_offset_realloc=stub
+_aligned_realloc=stub
 _amsg_exit
 _assert
-;_atodbl
+_atodbl=stub
 _atoi64
-;_atoldbl
+_atoldbl=stub
 _beep
 _beginthread
 _beginthreadex
 _c_exit
 _cabs
-;_callnewh
+_callnewh=stub
 _cexit
 _cgets
-;_cgetws
+_cgetws=stub
 _chdir
 _chdrive
 _chgsign
-;_chkesp
+_chkesp=stub
 _chmod
 _chsize
 _clearfp
@@ -231,22 +231,22 @@ _controlfp
 _copysign
 _cprintf
 _cputs
-;_cputws
+_cputws=stub
 _creat
 _cscanf
-;_ctime64
+_ctime64=stub
 _ctype DATA
 _cwait
-;_cwprintf
-;_cwscanf
+_cwprintf=stub
+_cwscanf=stub
 _daylight DATA
-;_dstbias
+_dstbias=stub
 _dup
 _dup2
 _ecvt
 _endthread
 _endthreadex
-;_environ
+_environ=stub
 _eof
 _errno
 _except_handler2
@@ -267,21 +267,21 @@ _fdopen
 _fgetchar
 _fgetwchar
 _filbuf
-;_fileinfo DATA
+_fileinfo=stub DATA
 _filelength
 _filelengthi64
 _fileno
 _findclose
 _findfirst
-;_findfirst64
+_findfirst64=stub
 _findfirsti64
 _findnext
-;_findnext64
+_findnext64=stub
 _findnexti64
 _finite
 _flsbuf
 _flushall
-_fmode=__fmode DATA
+_fmode DATA
 _fpclass
 _fpieee_flt
 _fpreset
@@ -289,17 +289,17 @@ _fputchar
 _fputwchar
 _fsopen
 _fstat
-;_fstat64
+_fstat64=stub
 _fstati64
 _ftime
-;_ftime64
+_ftime64=stub
 _ftol=NTDLL._ftol
 _fullpath
 _futime
-;_futime64
+_futime64=stub
 _gcvt
 _get_osfhandle
-;_get_sbh_threshold
+_get_sbh_threshold=stub
 _getch
 _getche
 _getcwd
@@ -308,29 +308,30 @@ _getdiskfree
 _getdllprocaddr
 _getdrive
 _getdrives
-;_getmaxstdio
-;_getmbcp
+_get_heap_handle=stub
+_getmaxstdio=stub
+_getmbcp=stub
 _getpid
 _getsystime
 _getw
-;_getwch
-;_getwche
-;_getws
-;_gmtime64
+_getwch=stub
+_getwche=stub
+_getws=stub
+_gmtime64=stub
 _global_unwind2
 _heapadd
 _heapchk
 _heapmin
 _heapset
-;_heapused
+_heapused=stub
 _heapwalk
 _hypot
 _i64toa
 _i64tow
 _initterm
-;_inp
-;_inpd
-;_inpw
+_inp=stub
+_inpd=stub
+_inpw=stub
 _iob
 _isatty
 _isctype
@@ -339,7 +340,7 @@ _ismbbalpha
 _ismbbgraph
 _ismbbkalnum
 _ismbbkana
-;_ismbbkprint
+_ismbbkprint=stub
 _ismbbkpunct
 _ismbblead
 _ismbbprint
@@ -348,7 +349,7 @@ _ismbbtrail
 _ismbcalnum
 _ismbcalpha
 _ismbcdigit
-;_ismbcgraph
+_ismbcgraph=stub
 _ismbchira
 _ismbckata
 _ismbcl0
@@ -357,7 +358,7 @@ _ismbcl2
 _ismbclegal
 _ismbclower
 _ismbcprint
-;_ismbcpunct
+_ismbcpunct=stub
 _ismbcspace
 _ismbcsymbol
 _ismbcupper
@@ -370,13 +371,14 @@ _j0
 _j1
 _jn
 _kbhit
+_localtime64=stub
 _lfind
 _loaddll
 _local_unwind2
 _lock
 _locking
 _logb
-;_longjmpex
+_longjmpex=stub
 _lrotl
 _lrotr
 _lsearch
@@ -387,7 +389,7 @@ _ltow
 _makepath
 _mbbtombc
 _mbbtype
-;_mbcasemap
+_mbcasemap=stub
 _mbccpy
 _mbcjistojms
 _mbcjmstojis
@@ -444,17 +446,17 @@ _memccpy
 _memicmp
 _mkdir
 _mktemp
-;_mktime64
+_mktime64=stub
 _msize
 _nextafter
 _onexit
 _open
 _open_osfhandle
 _osver DATA
-;_osplatform
-;_outp
-;_outpd
-;_outpw
+_osplatform=stub
+_outp=stub
+_outpd=stub
+_outpw=stub
 _pclose
 _pctype DATA
 _pgmptr DATA
@@ -464,38 +466,38 @@ _purecall
 _putch
 _putenv
 _putw
-;_putwch
+_putwch=stub
 _putws
 _pwctype DATA
 _read
-;_resetstkoflw
+_resetstkoflw=stub
 _rmdir
 _rmtmp
 _rotl
 _rotr
-;_safe_fdiv
-;_safe_fdivr
-;_safe_fprem
-;_safe_fprem1
+_safe_fdiv=stub
+_safe_fdivr=stub
+_safe_fprem=stub
+_safe_fprem1=stub
 _scalb
-;_scprintf
-;_scwprintf
+_scprintf=stub
+_scwprintf=stub
 _searchenv
 _seh_longjmp_unwind=_seh_longjmp_unwind@4
-;_set_error_mode
-;_set_SSE2_enable
-;_set_sbh_threshold
+_set_error_mode=stub
+_set_SSE2_enable=stub
+_set_sbh_threshold=stub
 _seterrormode
 _setjmp
 _setjmp3
-;_setmaxstdio
+_setmaxstdio=stub
 _setmbcp
 _setmode
 _setsystime
 _sleep
 _snprintf
-;_snscanf
-;_snwscanf
+_snscanf=stub
+_snwscanf=stub
 _snwprintf
 _sopen
 _spawnl
@@ -508,7 +510,7 @@ _spawnvp
 _spawnvpe
 _splitpath
 _stat
-;_stat64
+_stat64=stub
 _stati64
 _statusfp
 _strcmpi
@@ -525,8 +527,8 @@ _strnset
 _strrev
 _strset
 _strtime
-;_strtoi64
-;_strtoui64
+_strtoi64=stub
+_strtoui64=stub
 _strupr
 _swab
 _sys_errlist DATA
@@ -534,7 +536,7 @@ _sys_nerr DATA
 _tell
 _telli64
 _tempnam
-;_time64
+_time64=stub
 _timezone DATA
 _tolower
 _toupper
@@ -546,14 +548,13 @@ _ultoa
 _ultow
 _umask
 _ungetch
-;_ungetwch
 _unlink
 _unloaddll
 _unlock
 _utime
-;_utime64
-;_vscprintf
-;_vscwprintf
+_utime64=stub
+_vscprintf=stub
+_vscwprintf=stub
 _vsnprintf
 _vsnwprintf
 _waccess
@@ -563,7 +564,7 @@ _wchmod
 _wcmdln
 _wcreat
 _wcsdup
-;_wcserror
+_wcserror=stub
 _wcsicmp
 _wcsicoll
 _wcslwr
@@ -573,26 +574,26 @@ _wcsnicoll
 _wcsnset
 _wcsrev
 _wcsset
-;_wcstoi64
-;_wcstoui64
-;_wctime64
+_wcstoi64=stub
+_wcstoui64=stub
+_wctime64=stub
 _wcsupr
 _wctime
-;_wenviron
-;_wexecl
-;_wexecle
-;_wexeclp
-;_wexeclpe
-;_wexecv
-;_wexecve
-;_wexecvp
-;_wexecvpe
+_wenviron=stub
+_wexecl
+_wexecle
+_wexeclp
+_wexeclpe
+_wexecv
+_wexecve
+_wexecvp
+_wexecvpe
 _wfdopen
 _wfindfirst
-;_wfindfirst64
+_wfindfirst64=stub
 _wfindfirsti64
 _wfindnext
-;_wfindnext64
+_wfindnext64=stub
 _wfindnexti64
 _wfopen
 _wfreopen
@@ -609,7 +610,7 @@ _wmkdir
 _wmktemp
 _wopen
 _wperror
-;_wpgmptr DATA
+_wpgmptr=stub DATA
 _wpopen
 _wputenv
 _wremove
@@ -617,32 +618,32 @@ _wrename
 _write
 _wrmdir
 _wsearchenv
-;_wsetlocale
+_wsetlocale=stub
 _wsopen
-;_wspawnl
-;_wspawnle
-;_wspawnlp
-;_wspawnlpe
-;_wspawnv
-;_wspawnve
-;_wspawnvp
-;_wspawnvpe
+_wspawnl
+_wspawnle
+_wspawnlp
+_wspawnlpe
+_wspawnv
+_wspawnve
+_wspawnvp
+_wspawnvpe
 _wsplitpath
 _wstat
-;_wstat64
+_wstat64=stub
 _wstati64
 _wstrdate
 _wstrtime
-;_wsystem
+_wsystem=stub
 _wtempnam
 _wtmpnam
-;_wtof
+_wtof=stub
 _wtoi
 _wtoi64
 _wtol
 _wunlink
 _wutime
-;_wutime64
+_wutime64=stub
 _y0
 _y1
 _yn
index 6da74fc..50f01d4 100644 (file)
@@ -148,6 +148,13 @@ RtlEnterCriticalSection(
             CriticalSection->RecursionCount++;
             return STATUS_SUCCESS;
         }
+        else if (CriticalSection->OwningThread == (HANDLE)0)
+        {
+            /* No one else owns it either! */
+            DPRINT1("Critical section not initialized (guess)!\n");
+            /* FIXME: raise exception */
+            return STATUS_INVALID_PARAMETER;            
+        }
         
         /* We don't own it, so we must wait for it */
         RtlpWaitForCriticalSection(CriticalSection);
@@ -293,7 +300,16 @@ NTSTATUS
 STDCALL
 RtlLeaveCriticalSection(
     PRTL_CRITICAL_SECTION CriticalSection)
-{     
+{   
+    HANDLE Thread = (HANDLE)NtCurrentTeb()->Cid.UniqueThread;
+    
+    if (Thread != CriticalSection->OwningThread)
+    {
+       DPRINT1("Releasing critical section not owned!\n");
+       /* FIXME: raise exception */
+       return STATUS_INVALID_PARAMETER;
+    }
+   
     /* Decrease the Recursion Count */    
     if (--CriticalSection->RecursionCount) {
     
diff --git a/reactos/lib/ntdll/stdio/scanf.h b/reactos/lib/ntdll/stdio/scanf.h
new file mode 100644 (file)
index 0000000..a8dcde7
--- /dev/null
@@ -0,0 +1,537 @@
+/*\r
+ * general implementation of scanf used by scanf, sscanf, fscanf,\r
+ * _cscanf, wscanf, swscanf and fwscanf\r
+ *\r
+ * Copyright 1996,1998 Marcus Meissner\r
+ * Copyright 1996 Jukka Iivonen\r
+ * Copyright 1997,2000, 2003 Uwe Bonnes\r
+ * Copyright 2000 Jon Griffiths\r
+ * Copyright 2002 Daniel Gudbjartsson\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#ifdef WIDE_SCANF\r
+#define _CHAR_ wchar_t\r
+#define _EOF_ WEOF\r
+#define _EOF_RET WEOF\r
+#define _ISSPACE_(c) iswspace(c)\r
+#define _ISDIGIT_(c) iswdigit(c)\r
+#define _WIDE2SUPPORTED_(c) c /* No conversion needed (wide to wide) */\r
+#define _CHAR2SUPPORTED_(c) c /* FIXME: convert char to wide char */\r
+#define _CHAR2DIGIT_(c, base) wchar2digit((c), (base))\r
+#define _BITMAPSIZE_ 256*256\r
+#else /* WIDE_SCANF */\r
+#define _CHAR_ char\r
+#define _EOF_ EOF\r
+#define _EOF_RET EOF\r
+#define _ISSPACE_(c) isspace(c)\r
+#define _ISDIGIT_(c) isdigit(c)\r
+#define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */\r
+#define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */\r
+#define _CHAR2DIGIT_(c, base) char2digit((c), (base))\r
+#define _BITMAPSIZE_ 256\r
+#endif /* WIDE_SCANF */\r
+\r
+#ifdef CONSOLE\r
+#define _GETC_(file) (consumed++, _getch())\r
+#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)\r
+#define _FUNCTION_ int vcscanf(const char *format, va_list ap)\r
+#else\r
+#ifdef STRING\r
+#undef _EOF_\r
+#define _EOF_ 0\r
+#define _GETC_(file) (consumed++, *file++)\r
+#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)\r
+#ifdef WIDE_SCANF\r
+#define _FUNCTION_ int vswscanf(const wchar_t *file, const wchar_t *format, va_list ap)\r
+#else /* WIDE_SCANF */\r
+#define _FUNCTION_ int vsscanf(const char *file, const char *format, va_list ap)\r
+#endif /* WIDE_SCANF */\r
+#else /* STRING */\r
+#ifdef WIDE_SCANF\r
+#define _GETC_(file) (consumed++, fgetwc(file))\r
+#define _UNGETC_(nch, file) do { ungetwc(nch, file); consumed--; } while(0)\r
+#define _FUNCTION_ int vfwscanf(FILE* file, const wchar_t *format, va_list ap)\r
+#else /* WIDE_SCANF */\r
+#define _GETC_(file) (consumed++, fgetc(file))\r
+#define _UNGETC_(nch, file) do { ungetc(nch, file); consumed--; } while(0)\r
+#define _FUNCTION_ int vfscanf(FILE* file, const char *format, va_list ap)\r
+#endif /* WIDE_SCANF */\r
+#endif /* STRING */\r
+#endif /* CONSOLE */\r
+\r
+/*********************************************************************\r
+ * Implemented based on\r
+ * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_format_specification_fields_.2d_.scanf_and_wscanf_functions.asp\r
+ * Extended by C. Scott Ananian <cananian@alumni.princeton.edu> to handle\r
+ * more types of format spec.\r
+ */\r
+_FUNCTION_ {\r
+    int rd = 0, consumed = 0;\r
+    int nch;\r
+    if (!*format) return 0;\r
+#ifndef WIDE_SCANF\r
+#ifdef CONSOLE\r
+    TRACE("(%s): \n", debugstr_a(format));\r
+#else /* CONSOLE */\r
+#ifdef STRING\r
+    TRACE("%s (%s)\n", file, debugstr_a(format));\r
+#else /* STRING */\r
+    TRACE("%p (%s)\n", file, debugstr_a(format));\r
+#endif /* STRING */\r
+#endif /* CONSOLE */\r
+#endif /* WIDE_SCANF */\r
+    nch = _GETC_(file);\r
+    if (nch == _EOF_) return _EOF_RET;\r
+\r
+    while (*format) {\r
+       /* a whitespace character in the format string causes scanf to read,\r
+        * but not store, all consecutive white-space characters in the input\r
+        * up to the next non-white-space character.  One white space character\r
+        * in the input matches any number (including zero) and combination of\r
+        * white-space characters in the input. */\r
+       if (_ISSPACE_(*format)) {\r
+            /* skip whitespace */\r
+            while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                nch = _GETC_(file);\r
+        }\r
+       /* a format specification causes scanf to read and convert characters\r
+        * in the input into values of a specified type.  The value is assigned\r
+        * to an argument in the argument list.  Format specifications have\r
+        * the form %[*][width][{h | l | I64 | L}]type */\r
+        else if (*format == '%') {\r
+            int st = 0; int suppress = 0; int width = 0;\r
+           int base, number_signed;\r
+           int h_prefix = 0;\r
+           int l_prefix = 0;\r
+           int L_prefix = 0;\r
+           int w_prefix = 0;\r
+           int prefix_finished = 0;\r
+           int I64_prefix = 0;\r
+            format++;\r
+           /* look for leading asterisk, which means 'suppress assignment of\r
+            * this field'. */\r
+           if (*format=='*') {\r
+               format++;\r
+               suppress=1;\r
+           }\r
+           /* look for width specification */\r
+           while (_ISDIGIT_(*format)) {\r
+               width*=10;\r
+               width+=*format++ - '0';\r
+           }\r
+           if (width==0) width=-1; /* no width spec seen */\r
+           /* read prefix (if any) */\r
+           while (!prefix_finished) {\r
+               switch(*format) {\r
+               case 'h': h_prefix = 1; break;\r
+               case 'l': l_prefix = 1; break;\r
+               case 'w': w_prefix = 1; break;\r
+               case 'L': L_prefix = 1; break;\r
+               case 'I':\r
+                   if (*(format + 1) == '6' &&\r
+                       *(format + 2) == '4') {\r
+                       I64_prefix = 1;\r
+                       format += 2;\r
+                   }\r
+                   break;\r
+               default:\r
+                   prefix_finished = 1;\r
+               }\r
+               if (!prefix_finished) format++;\r
+           }\r
+           /* read type */\r
+            switch(*format) {\r
+           case 'x':\r
+           case 'X': /* hexadecimal integer. */\r
+               base = 16; number_signed = 0;\r
+               goto number;\r
+           case 'o': /* octal integer */\r
+               base = 8; number_signed = 0;\r
+               goto number;\r
+           case 'u': /* unsigned decimal integer */\r
+               base = 10; number_signed = 0;\r
+               goto number;\r
+           case 'd': /* signed decimal integer */\r
+               base = 10; number_signed = 1;\r
+               goto number;\r
+           case 'i': /* generic integer */\r
+               base = 10; number_signed = 1;\r
+           number: {\r
+                   /* read an integer */\r
+                   ULONGLONG cur = 0;\r
+                   int negative = 0;\r
+                   int seendigit=0;\r
+                    /* skip initial whitespace */\r
+                    while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                        nch = _GETC_(file);\r
+                    /* get sign */\r
+                    if (number_signed && (nch == '-' ||\r
+                                         nch == '+')) {\r
+                       negative = (nch=='-');\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                    }\r
+                   /* look for leading indication of base */\r
+                   if (width!=0 && nch == '0') {\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                       seendigit=1;\r
+                       if (width!=0 && (nch=='x' || nch=='X')) {\r
+                           if (base==0)\r
+                               base=16;\r
+                           if (base==16) {\r
+                               nch = _GETC_(file);\r
+                               if (width>0) width--;\r
+                               seendigit=0;\r
+                           }\r
+                       } else if (base==0)\r
+                           base = 8;\r
+                   }\r
+                   /* throw away leading zeros */\r
+                   while (width!=0 && nch=='0') {\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                       seendigit=1;\r
+                   }\r
+                   if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) {\r
+                       cur = _CHAR2DIGIT_(nch, base);\r
+                       nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                       seendigit=1;\r
+                   }\r
+                    /* read until no more digits */\r
+                    while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) {\r
+                        cur = cur*base + _CHAR2DIGIT_(nch, base);\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                       seendigit=1;\r
+                    }\r
+                   /* okay, done! */\r
+                   if (!seendigit) break; /* not a valid number */\r
+                    st = 1;\r
+                    if (!suppress) {\r
+#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur\r
+                       if (number_signed) {\r
+                           if (I64_prefix) _SET_NUMBER_(LONGLONG);\r
+                           else if (l_prefix) _SET_NUMBER_(long int);\r
+                           else if (h_prefix) _SET_NUMBER_(short int);\r
+                           else _SET_NUMBER_(int);\r
+                       } else {\r
+                           if (negative) {\r
+                               WARN("Dropping sign in reading a negative number into an unsigned value");\r
+                               negative = 0;\r
+                           }\r
+                           if (I64_prefix) _SET_NUMBER_(ULONGLONG);\r
+                           else if (l_prefix) _SET_NUMBER_(unsigned long int);\r
+                           else if (h_prefix)\r
+                               _SET_NUMBER_(unsigned short int);\r
+                           else _SET_NUMBER_(unsigned int);\r
+                       }\r
+                   }\r
+                }\r
+                break;\r
+           case 'e':\r
+           case 'E':\r
+           case 'f':\r
+           case 'g':\r
+            case 'G': { /* read a float */\r
+                    long double cur = 0;\r
+                   int negative = 0;\r
+                    /* skip initial whitespace */\r
+                    while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                        nch = _GETC_(file);\r
+                   /* get sign. */\r
+                    if (nch == '-' || nch == '+') {\r
+                       negative = (nch=='-');\r
+                       if (width>0) width--;\r
+                       if (width==0) break;\r
+                        nch = _GETC_(file);\r
+                    }\r
+                   /* get first digit. */\r
+                   if ('.' != nch) {\r
+                     if (!_ISDIGIT_(nch)) break;\r
+                     cur = (nch - '0');\r
+                     nch = _GETC_(file);\r
+                     if (width>0) width--;\r
+                     /* read until no more digits */\r
+                     while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {\r
+                        cur = cur*10 + (nch - '0');\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                     }\r
+                   } else {\r
+                     cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */\r
+                   }\r
+                   /* handle decimals */\r
+                    if (width!=0 && nch == '.') {\r
+                        float dec = 1;\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                        while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {\r
+                            dec /= 10;\r
+                            cur += dec * (nch - '0');\r
+                            nch = _GETC_(file);\r
+                           if (width>0) width--;\r
+                        }\r
+                    }\r
+                   /* handle exponent */\r
+                   if (width!=0 && (nch == 'e' || nch == 'E')) {\r
+                       int exponent = 0, negexp = 0;\r
+                       float expcnt;\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                       /* possible sign on the exponent */\r
+                       if (width!=0 && (nch=='+' || nch=='-')) {\r
+                           negexp = (nch=='-');\r
+                            nch = _GETC_(file);\r
+                           if (width>0) width--;\r
+                       }\r
+                       /* exponent digits */\r
+                       while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {\r
+                           exponent *= 10;\r
+                           exponent += (nch - '0');\r
+                            nch = _GETC_(file);\r
+                           if (width>0) width--;\r
+                        }\r
+                       /* update 'cur' with this exponent. */\r
+                       expcnt =  negexp ? .1 : 10;\r
+                       while (exponent!=0) {\r
+                           if (exponent&1)\r
+                               cur*=expcnt;\r
+                           exponent/=2;\r
+                           expcnt=expcnt*expcnt;\r
+                       }\r
+                   }\r
+                    st = 1;\r
+                    if (!suppress) {\r
+                       if (L_prefix) _SET_NUMBER_(long double);\r
+                       else if (l_prefix) _SET_NUMBER_(double);\r
+                       else _SET_NUMBER_(float);\r
+                   }\r
+                }\r
+                break;\r
+               /* According to\r
+                * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_scanf_type_field_characters.asp\r
+                * 's' reads a character string in a call to fscanf\r
+                * and 'S' a wide character string and vice versa in a\r
+                * call to fwscanf. The 'h', 'w' and 'l' prefixes override\r
+                * this behaviour. 'h' forces reading char * but 'l' and 'w'\r
+                * force reading WCHAR. */\r
+           case 's':\r
+                   if (w_prefix || l_prefix) goto widecharstring;\r
+                   else if (h_prefix) goto charstring;\r
+#ifdef WIDE_SCANF\r
+                   else goto widecharstring;\r
+#else /* WIDE_SCANF */\r
+                   else goto charstring;\r
+#endif /* WIDE_SCANF */\r
+           case 'S':\r
+                   if (w_prefix || l_prefix) goto widecharstring;\r
+                   else if (h_prefix) goto charstring;\r
+#ifdef WIDE_SCANF\r
+                   else goto charstring;\r
+#else /* WIDE_SCANF */\r
+                   else goto widecharstring;\r
+#endif /* WIDE_SCANF */\r
+           charstring: { /* read a word into a char */\r
+                   char*str = suppress ? NULL : va_arg(ap, char*);\r
+                    char*sptr = str;\r
+                    /* skip initial whitespace */\r
+                    while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                        nch = _GETC_(file);\r
+                    /* read until whitespace */\r
+                    while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {\r
+                        if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);\r
+                       st++;\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                    }\r
+                    /* terminate */\r
+                    if (!suppress) *sptr = 0;\r
+                }\r
+                break;\r
+           widecharstring: { /* read a word into a wchar_t* */\r
+                   wchar_t*str =\r
+                       suppress ? NULL : va_arg(ap, wchar_t*);\r
+                    wchar_t*sptr = str;\r
+                    /* skip initial whitespace */\r
+                    while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                        nch = _GETC_(file);\r
+                    /* read until whitespace */\r
+                    while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {\r
+                        if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch);\r
+                       st++;\r
+                        nch = _GETC_(file);\r
+                       if (width>0) width--;\r
+                    }\r
+                    /* terminate */\r
+                    if (!suppress) *sptr = 0;\r
+                }\r
+                break;\r
+            /* 'c' and 'C work analogously to 's' and 'S' as described\r
+            * above */\r
+           case 'c':\r
+                   if (w_prefix || l_prefix) goto widecharacter;\r
+                   else if (h_prefix) goto character;\r
+#ifdef WIDE_SCANF\r
+                   else goto widecharacter;\r
+#else /* WIDE_SCANF */\r
+                   else goto character;\r
+#endif /* WIDE_SCANF */\r
+           case 'C':\r
+                   if (w_prefix || l_prefix) goto widecharacter;\r
+                   else if (h_prefix) goto character;\r
+#ifdef WIDE_SCANF\r
+                   else goto character;\r
+#else /* WIDE_SCANF */\r
+                   else goto widecharacter;\r
+#endif /* WIDE_SCANF */\r
+         character: { /* read single character into char */\r
+                    if (nch!=_EOF_) {\r
+                        if (!suppress) {\r
+                            char*c = va_arg(ap, char*);\r
+                            *c = _CHAR2SUPPORTED_(nch);\r
+                        }\r
+                        st = 1;\r
+                        nch = _GETC_(file);\r
+                    }\r
+                }\r
+               break;\r
+         widecharacter: { /* read single character into a wchar_t */\r
+                    if (nch!=_EOF_) {\r
+                        if (!suppress) {\r
+                            wchar_t*c = va_arg(ap, wchar_t*);\r
+                            *c = _WIDE2SUPPORTED_(nch);\r
+                        }\r
+                        nch = _GETC_(file);\r
+                        st = 1;\r
+                    }\r
+               }\r
+               break;\r
+           case 'n': {\r
+                   if (!suppress) {\r
+                       int*n = va_arg(ap, int*);\r
+                       *n = consumed - (nch!=_EOF_);\r
+                   }\r
+               }\r
+               break;\r
+           case '[': {\r
+                    _CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*);\r
+                    _CHAR_ *sptr = str;\r
+                   RTL_BITMAP bitMask;\r
+                    ULONG *Mask;\r
+                   int invert = 0; /* Set if we are NOT to find the chars */\r
+\r
+                   /* Init our bitmap */\r
+          Mask = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);\r
+                   RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_);\r
+\r
+                   /* Read the format */\r
+                   format++;\r
+                   if(*format == '^') {\r
+                       invert = 1;\r
+                       format++;\r
+                   }\r
+                   if(*format == ']') {\r
+                       RtlSetBits(&bitMask, ']', 1);\r
+                       format++;\r
+                   }\r
+                    while(*format && (*format != ']')) {\r
+                       /* According to:\r
+                        * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp\r
+                        * "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */\r
+                       if((*format == '-') && (*(format + 1) != ']')) {\r
+                           if ((*(format - 1)) < *(format + 1))\r
+                               RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1));\r
+                           else\r
+                               RtlSetBits(&bitMask, *(format + 1)    , *(format - 1) - *(format + 1));                       \r
+                           format++;\r
+                       } else\r
+                           RtlSetBits(&bitMask, *format, 1);\r
+                       format++;\r
+                   }\r
+                    /* read until char is not suitable */\r
+                    while ((width != 0) && (nch != _EOF_)) {\r
+                       if(!invert) {\r
+                           if(RtlAreBitsSet(&bitMask, nch, 1)) {\r
+                               if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);\r
+                           } else\r
+                               break;\r
+                       } else {\r
+                           if(RtlAreBitsClear(&bitMask, nch, 1)) {\r
+                               if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);\r
+                           } else\r
+                               break;\r
+                       }\r
+                        st++;\r
+                        nch = _GETC_(file);\r
+                        if (width>0) width--;\r
+                    }\r
+                    /* terminate */\r
+                    if (!suppress) *sptr = 0;\r
+                   RtlFreeHeap(RtlGetProcessHeap(), 0, Mask);\r
+                }\r
+                break;\r
+            default:\r
+               /* From spec: "if a percent sign is followed by a character\r
+                * that has no meaning as a format-control character, that\r
+                * character and the following characters are treated as\r
+                * an ordinary sequence of characters, that is, a sequence\r
+                * of characters that must match the input.  For example,\r
+                * to specify that a percent-sign character is to be input,\r
+                * use %%." */\r
+                while ((nch!=_EOF_) && _ISSPACE_(nch))\r
+                    nch = _GETC_(file);\r
+                if (nch==*format) {\r
+                    suppress = 1; /* whoops no field to be read */\r
+                    st = 1; /* but we got what we expected */\r
+                    nch = _GETC_(file);\r
+                }\r
+                break;\r
+            }\r
+            if (st && !suppress) rd++;\r
+            else if (!st) break;\r
+        }\r
+       /* a non-white-space character causes scanf to read, but not store,\r
+        * a matching non-white-space character. */\r
+        else {\r
+            /* check for character match */\r
+            if (nch == *format) {\r
+               nch = _GETC_(file);\r
+            } else break;\r
+        }\r
+        format++;\r
+    }\r
+    if (nch!=_EOF_) {\r
+       _UNGETC_(nch, file);\r
+    }\r
+    TRACE("returning %d\n", rd);\r
+    return rd;\r
+}\r
+\r
+#undef _CHAR_\r
+#undef _EOF_\r
+#undef _EOF_RET\r
+#undef _ISSPACE_\r
+#undef _ISDIGIT_\r
+#undef _CHAR2SUPPORTED_\r
+#undef _WIDE2SUPPORTED_\r
+#undef _CHAR2DIGIT_\r
+#undef _GETC_\r
+#undef _UNGETC_\r
+#undef _FUNCTION_\r
+#undef _BITMAPSIZE_\r
index a28d82f..88b7b2a 100644 (file)
@@ -1,10 +1,43 @@
 /**/
 
-#include <msvcrt/stdio.h>
+#include <stdio.h>
+#include <ddk/ntddk.h>
+#include <ntos/heap.h>
 
-int sscanf(const char* szReadFrom, const char* szFormat, ...)
+#define NDEBUG
+#include <ntdll/ntdll.h>
+
+
+/* helper function for *scanf.  Returns the value of character c in the
+ * given base, or -1 if the given character is not a digit of the base.
+ */
+static int char2digit(char c, int base) {
+    if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
+    if (base<=10) return -1;
+    if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
+    if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
+    return -1;
+}
+
+#define debugstr_a(a) (a)
+#define TRACE DPRINT
+#define WARN DPRINT1
+
+/* vsscanf */
+#undef WIDE_SCANF
+#undef CONSOLE
+#define STRING 1
+#include "scanf.h"
+
+int sscanf(const char *str, const char *format, ...)
 {
-  return 0;
+    va_list valist;
+    int res;
+
+    va_start(valist, format);
+    res = vsscanf(str, format, valist);
+    va_end(valist);
+    return res;
 }
 
 /*EOF */
index 7efbdbd..e1e4f11 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
-#include <msvcrt/stdlib.h>
+#include <stdlib.h>
 
 /*
  * @implemented
index 2000fec..2e6e43b 100644 (file)
@@ -1,5 +1,5 @@
-#include <msvcrt/search.h>
-#include <msvcrt/stdlib.h>
+#include <search.h>
+#include <stdlib.h>
 
 
 /*