Don't use ntdll headers in crt, use ndk
[reactos.git] / reactos / lib / crt / wine / scanf.c
1 /*
2 * general implementation of scanf used by scanf, sscanf, fscanf,
3 * _cscanf, wscanf, swscanf and fwscanf
4 *
5 * Copyright 1996,1998 Marcus Meissner
6 * Copyright 1996 Jukka Iivonen
7 * Copyright 1997,2000 Uwe Bonnes
8 * Copyright 2000 Jon Griffiths
9 * Copyright 2002 Daniel Gudbjartsson
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26
27 /*
28 #include <stdarg.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "winternl.h"
34 #include "msvcrt.h"
35 */
36
37 #include <stdarg.h>
38 #include <wchar.h>
39 #include <stdio.h>
40 #include <conio.h>
41 #include <ctype.h>
42 #include <internal/file.h>
43
44 #define NTOS_MODE_USER
45 #include <ndk/ntndk.h>
46
47 #define NDEBUG
48 #include <internal/debug.h>
49
50 //#include "wine/debug.h"
51
52 #define WARN DPRINT1
53
54 //WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
55
56 extern FILE _iob[];
57
58 /* helper function for *scanf. Returns the value of character c in the
59 * given base, or -1 if the given character is not a digit of the base.
60 */
61 static int char2digit(char c, int base) {
62 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
63 if (base<=10) return -1;
64 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
65 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
66 return -1;
67 }
68
69 /* helper function for *wscanf. Returns the value of character c in the
70 * given base, or -1 if the given character is not a digit of the base.
71 */
72 static int wchar2digit(wchar_t c, int base) {
73 if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');
74 if (base<=10) return -1;
75 if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);
76 if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);
77 return -1;
78 }
79
80 /* vfscanf */
81 #undef WIDE_SCANF
82 #undef CONSOLE
83 #undef STRING
84 #include "scanf.h"
85
86 /* vfwscanf */
87 #define WIDE_SCANF 1
88 #undef CONSOLE
89 #undef STRING
90 #include "scanf.h"
91
92 /* vsscanf */
93 #undef WIDE_SCANF
94 #undef CONSOLE
95 #define STRING 1
96 #include "scanf.h"
97
98 /* vswscanf */
99 #define WIDE_SCANF 1
100 #undef CONSOLE
101 #define STRING 1
102 #include "scanf.h"
103
104 /* vcscanf */
105 #undef WIDE_SCANF
106 #define CONSOLE 1
107 #undef STRING
108 #include "scanf.h"
109
110
111 /*********************************************************************
112 * fscanf (MSVCRT.@)
113 */
114 int fscanf(FILE *file, const char *format, ...)
115 {
116 va_list valist;
117 int res;
118
119 va_start(valist, format);
120 res = vfscanf(file, format, valist);
121 va_end(valist);
122 return res;
123 }
124
125 /*********************************************************************
126 * scanf (MSVCRT.@)
127 */
128 int scanf(const char *format, ...)
129 {
130 va_list valist;
131 int res;
132
133 va_start(valist, format);
134 res = vfscanf(stdin, format, valist);
135 va_end(valist);
136 return res;
137 }
138
139 /*********************************************************************
140 * fwscanf (MSVCRT.@)
141 */
142 int fwscanf(FILE *file, const wchar_t *format, ...)
143 {
144 va_list valist;
145 int res;
146
147 va_start(valist, format);
148 res = vfwscanf(file, format, valist);
149 va_end(valist);
150 return res;
151 }
152
153
154 /*********************************************************************
155 * wscanf (MSVCRT.@)
156 */
157 int wscanf(const wchar_t *format, ...)
158 {
159 va_list valist;
160 int res;
161
162 va_start(valist, format);
163 res = vfwscanf(stdin, format, valist);
164 va_end(valist);
165 return res;
166 }
167
168
169 /*********************************************************************
170 * sscanf (MSVCRT.@)
171 */
172 int crt_sscanf(const char *str, const char *format, ...)
173 {
174 va_list valist;
175 int res;
176
177 va_start(valist, format);
178 res = vsscanf(str, format, valist);
179 va_end(valist);
180 return res;
181 }
182
183
184 /*********************************************************************
185 * swscanf (MSVCRT.@)
186 */
187 int swscanf(const wchar_t *str, const wchar_t *format, ...)
188 {
189 va_list valist;
190 int res;
191
192 va_start(valist, format);
193 res = vswscanf(str, format, valist);
194 va_end(valist);
195 return res;
196 }
197
198
199 /*********************************************************************
200 * _cscanf (MSVCRT.@)
201 */
202 int _cscanf(/*const*/ char *format, ...)
203 {
204 va_list valist;
205 int res;
206
207 va_start(valist, format);
208 res = vcscanf(format, valist);
209 va_end(valist);
210 return res;
211 }