9b9d03e3ce717ed1728b6069c969c23754f7eb01
[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 #include <windows.h>
45 #define NTOS_MODE_USER
46 #include <ndk/umtypes.h>
47 #include <ndk/extypes.h>
48 #include <ndk/rtlfuncs.h>
49
50 #define NDEBUG
51 #include <internal/debug.h>
52
53 //#include "wine/debug.h"
54
55 #define WARN DPRINT1
56
57 //WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
58
59 extern FILE _iob[];
60
61 /* helper function for *scanf. Returns the value of character c in the
62 * given base, or -1 if the given character is not a digit of the base.
63 */
64 static int char2digit(char c, int base) {
65 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
66 if (base<=10) return -1;
67 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
68 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
69 return -1;
70 }
71
72 /* helper function for *wscanf. Returns the value of character c in the
73 * given base, or -1 if the given character is not a digit of the base.
74 */
75 static int wchar2digit(wchar_t c, int base) {
76 if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');
77 if (base<=10) return -1;
78 if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);
79 if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);
80 return -1;
81 }
82
83 /* vfscanf */
84 #undef WIDE_SCANF
85 #undef CONSOLE
86 #undef STRING
87 #include "scanf.h"
88
89 /* vfwscanf */
90 #define WIDE_SCANF 1
91 #undef CONSOLE
92 #undef STRING
93 #include "scanf.h"
94
95 /* vsscanf */
96 #undef WIDE_SCANF
97 #undef CONSOLE
98 #define STRING 1
99 #include "scanf.h"
100
101 /* vswscanf */
102 #define WIDE_SCANF 1
103 #undef CONSOLE
104 #define STRING 1
105 #include "scanf.h"
106
107 /* vcscanf */
108 #undef WIDE_SCANF
109 #define CONSOLE 1
110 #undef STRING
111 #include "scanf.h"
112
113
114 /*********************************************************************
115 * fscanf (MSVCRT.@)
116 */
117 int fscanf(FILE *file, const char *format, ...)
118 {
119 va_list valist;
120 int res;
121
122 va_start(valist, format);
123 res = vfscanf(file, format, valist);
124 va_end(valist);
125 return res;
126 }
127
128 /*********************************************************************
129 * scanf (MSVCRT.@)
130 */
131 int scanf(const char *format, ...)
132 {
133 va_list valist;
134 int res;
135
136 va_start(valist, format);
137 res = vfscanf(stdin, format, valist);
138 va_end(valist);
139 return res;
140 }
141
142 /*********************************************************************
143 * fwscanf (MSVCRT.@)
144 */
145 int fwscanf(FILE *file, const wchar_t *format, ...)
146 {
147 va_list valist;
148 int res;
149
150 va_start(valist, format);
151 res = vfwscanf(file, format, valist);
152 va_end(valist);
153 return res;
154 }
155
156
157 /*********************************************************************
158 * wscanf (MSVCRT.@)
159 */
160 int wscanf(const wchar_t *format, ...)
161 {
162 va_list valist;
163 int res;
164
165 va_start(valist, format);
166 res = vfwscanf(stdin, format, valist);
167 va_end(valist);
168 return res;
169 }
170
171
172 /*********************************************************************
173 * sscanf (MSVCRT.@)
174 */
175 int crt_sscanf(const char *str, const char *format, ...)
176 {
177 va_list valist;
178 int res;
179
180 va_start(valist, format);
181 res = vsscanf(str, format, valist);
182 va_end(valist);
183 return res;
184 }
185
186
187 /*********************************************************************
188 * swscanf (MSVCRT.@)
189 */
190 int swscanf(const wchar_t *str, const wchar_t *format, ...)
191 {
192 va_list valist;
193 int res;
194
195 va_start(valist, format);
196 res = vswscanf(str, format, valist);
197 va_end(valist);
198 return res;
199 }
200
201
202 /*********************************************************************
203 * _cscanf (MSVCRT.@)
204 */
205 int _cscanf(/*const*/ char *format, ...)
206 {
207 va_list valist;
208 int res;
209
210 va_start(valist, format);
211 res = vcscanf(format, valist);
212 va_end(valist);
213 return res;
214 }