msvcrt: Added _cscanf_l implementation.
[wine.git] / dlls / msvcrt / scanf.c
blob48450198c734945b877dcfd90c5ab97a0e0c806f
1 /*
2 * general implementation of scanf used by scanf, sscanf, fscanf,
3 * _cscanf, wscanf, swscanf and fwscanf
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
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winternl.h"
31 #include "msvcrt.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 extern MSVCRT_FILE MSVCRT__iob[];
38 /* helper function for *scanf. Returns the value of character c in the
39 * given base, or -1 if the given character is not a digit of the base.
41 static int char2digit(char c, int base) {
42 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
43 if (base<=10) return -1;
44 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
45 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
46 return -1;
49 /* helper function for *wscanf. Returns the value of character c in the
50 * given base, or -1 if the given character is not a digit of the base.
52 static int wchar2digit(MSVCRT_wchar_t c, int base) {
53 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
54 if (base<=10) return -1;
55 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
56 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
57 return -1;
60 /* vfscanf_l */
61 #undef WIDE_SCANF
62 #undef CONSOLE
63 #undef STRING
64 #include "scanf.h"
66 /* vfwscanf_l */
67 #define WIDE_SCANF 1
68 #undef CONSOLE
69 #undef STRING
70 #include "scanf.h"
72 /* vsscanf_l */
73 #undef WIDE_SCANF
74 #undef CONSOLE
75 #define STRING 1
76 #include "scanf.h"
78 /* vswscanf_l */
79 #define WIDE_SCANF 1
80 #undef CONSOLE
81 #define STRING 1
82 #include "scanf.h"
84 /* vcscanf_l */
85 #undef WIDE_SCANF
86 #define CONSOLE 1
87 #undef STRING
88 #include "scanf.h"
91 /*********************************************************************
92 * fscanf (MSVCRT.@)
94 int CDECL MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
96 __ms_va_list valist;
97 int res;
99 __ms_va_start(valist, format);
100 res = MSVCRT_vfscanf_l(file, format, NULL, valist);
101 __ms_va_end(valist);
102 return res;
105 /*********************************************************************
106 * _fscanf_l (MSVCRT.@)
108 int CDECL MSVCRT__fscanf_l(MSVCRT_FILE *file, const char *format,
109 MSVCRT__locale_t locale, ...)
111 __ms_va_list valist;
112 int res;
114 __ms_va_start(valist, locale);
115 res = MSVCRT_vfscanf_l(file, format, locale, valist);
116 __ms_va_end(valist);
117 return res;
120 /*********************************************************************
121 * scanf (MSVCRT.@)
123 int CDECL MSVCRT_scanf(const char *format, ...)
125 __ms_va_list valist;
126 int res;
128 __ms_va_start(valist, format);
129 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, NULL, valist);
130 __ms_va_end(valist);
131 return res;
134 /*********************************************************************
135 * _scanf_l (MSVCRT.@)
137 int CDECL MSVCRT__scanf_l(const char *format, MSVCRT__locale_t locale, ...)
139 __ms_va_list valist;
140 int res;
142 __ms_va_start(valist, locale);
143 res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, locale, valist);
144 __ms_va_end(valist);
145 return res;
148 /*********************************************************************
149 * fwscanf (MSVCRT.@)
151 int CDECL MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
153 __ms_va_list valist;
154 int res;
156 __ms_va_start(valist, format);
157 res = MSVCRT_vfwscanf_l(file, format, NULL, valist);
158 __ms_va_end(valist);
159 return res;
162 /*********************************************************************
163 * _fwscanf_l (MSVCRT.@)
165 int CDECL MSVCRT__fwscanf_l(MSVCRT_FILE *file, const MSVCRT_wchar_t *format,
166 MSVCRT__locale_t locale, ...)
168 __ms_va_list valist;
169 int res;
171 __ms_va_start(valist, locale);
172 res = MSVCRT_vfwscanf_l(file, format, locale, valist);
173 __ms_va_end(valist);
174 return res;
177 /*********************************************************************
178 * wscanf (MSVCRT.@)
180 int CDECL MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
182 __ms_va_list valist;
183 int res;
185 __ms_va_start(valist, format);
186 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, NULL, valist);
187 __ms_va_end(valist);
188 return res;
191 /*********************************************************************
192 * _wscanf_l (MSVCRT.@)
194 int CDECL MSVCRT__wscanf_l(const MSVCRT_wchar_t *format,
195 MSVCRT__locale_t locale, ...)
197 __ms_va_list valist;
198 int res;
200 __ms_va_start(valist, locale);
201 res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, locale, valist);
202 __ms_va_end(valist);
203 return res;
206 /*********************************************************************
207 * sscanf (MSVCRT.@)
209 int CDECL MSVCRT_sscanf(const char *str, const char *format, ...)
211 __ms_va_list valist;
212 int res;
214 __ms_va_start(valist, format);
215 res = MSVCRT_vsscanf_l(str, format, NULL, valist);
216 __ms_va_end(valist);
217 return res;
220 /*********************************************************************
221 * _sscanf_l (MSVCRT.@)
223 int CDECL MSVCRT__sscanf_l(const char *str, const char *format,
224 MSVCRT__locale_t locale, ...)
226 __ms_va_list valist;
227 int res;
229 __ms_va_start(valist, locale);
230 res = MSVCRT_vsscanf_l(str, format, locale, valist);
231 __ms_va_end(valist);
232 return res;
235 /*********************************************************************
236 * swscanf (MSVCRT.@)
238 int CDECL MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
240 __ms_va_list valist;
241 int res;
243 __ms_va_start(valist, format);
244 res = MSVCRT_vswscanf_l(str, format, NULL, valist);
245 __ms_va_end(valist);
246 return res;
249 /*********************************************************************
250 * _swscanf_l (MSVCRT.@)
252 int CDECL MSVCRT__swscanf_l(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format,
253 MSVCRT__locale_t locale, ...)
255 __ms_va_list valist;
256 int res;
258 __ms_va_start(valist, locale);
259 res = MSVCRT_vswscanf_l(str, format, locale, valist);
260 __ms_va_end(valist);
261 return res;
264 /*********************************************************************
265 * _cscanf (MSVCRT.@)
267 int CDECL _cscanf(const char *format, ...)
269 __ms_va_list valist;
270 int res;
272 __ms_va_start(valist, format);
273 res = MSVCRT_vcscanf_l(format, NULL, valist);
274 __ms_va_end(valist);
275 return res;
278 /*********************************************************************
279 * _cscanf_l (MSVCRT.@)
281 int CDECL _cscanf_l(const char *format, MSVCRT__locale_t locale, ...)
283 __ms_va_list valist;
284 int res;
286 __ms_va_start(valist, locale);
287 res = MSVCRT_vcscanf_l(format, locale, valist);
288 __ms_va_end(valist);
289 return res;