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