user: Added fast A->W mapping for EM_GETLINE.
[wine] / dlls / msvcrt / 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 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "msvcrt.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36
37 extern MSVCRT_FILE MSVCRT__iob[];
38
39 /* helper function for *scanf.  Returns the value of character c in the
40  * given base, or -1 if the given character is not a digit of the base.
41  */
42 static int char2digit(char c, int base) {
43     if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
44     if (base<=10) return -1;
45     if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
46     if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
47     return -1;
48 }
49
50 /* helper function for *wscanf.  Returns the value of character c in the
51  * given base, or -1 if the given character is not a digit of the base.
52  */
53 static int wchar2digit(MSVCRT_wchar_t c, int base) {
54     if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');
55     if (base<=10) return -1;
56     if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);
57     if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);
58     return -1;
59 }
60
61 /* vfscanf */
62 #undef WIDE_SCANF
63 #undef CONSOLE
64 #undef STRING
65 #include "scanf.h"
66
67 /* vfwscanf */
68 #define WIDE_SCANF 1
69 #undef CONSOLE
70 #undef STRING
71 #include "scanf.h"
72
73 /* vsscanf */
74 #undef WIDE_SCANF
75 #undef CONSOLE
76 #define STRING 1
77 #include "scanf.h"
78
79 /* vswscanf */
80 #define WIDE_SCANF 1
81 #undef CONSOLE
82 #define STRING 1
83 #include "scanf.h"
84
85 /* vcscanf */
86 #undef WIDE_SCANF
87 #define CONSOLE 1
88 #undef STRING
89 #include "scanf.h"
90
91
92 /*********************************************************************
93  *              fscanf (MSVCRT.@)
94  */
95 int MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
96 {
97     va_list valist;
98     int res;
99
100     va_start(valist, format);
101     res = MSVCRT_vfscanf(file, format, valist);
102     va_end(valist);
103     return res;
104 }
105
106 /*********************************************************************
107  *              scanf (MSVCRT.@)
108  */
109 int MSVCRT_scanf(const char *format, ...)
110 {
111     va_list valist;
112     int res;
113
114     va_start(valist, format);
115     res = MSVCRT_vfscanf(MSVCRT_stdin, format, valist);
116     va_end(valist);
117     return res;
118 }
119
120 /*********************************************************************
121  *              fwscanf (MSVCRT.@)
122  */
123 int MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
124 {
125     va_list valist;
126     int res;
127
128     va_start(valist, format);
129     res = MSVCRT_vfwscanf(file, format, valist);
130     va_end(valist);
131     return res;
132 }
133
134
135 /*********************************************************************
136  *              wscanf (MSVCRT.@)
137  */
138 int MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
139 {
140     va_list valist;
141     int res;
142
143     va_start(valist, format);
144     res = MSVCRT_vfwscanf(MSVCRT_stdin, format, valist);
145     va_end(valist);
146     return res;
147 }
148
149
150 /*********************************************************************
151  *              sscanf (MSVCRT.@)
152  */
153 int MSVCRT_sscanf(const char *str, const char *format, ...)
154 {
155     va_list valist;
156     int res;
157
158     va_start(valist, format);
159     res = MSVCRT_vsscanf(str, format, valist);
160     va_end(valist);
161     return res;
162 }
163
164
165 /*********************************************************************
166  *              swscanf (MSVCRT.@)
167  */
168 int MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
169 {
170     va_list valist;
171     int res;
172
173     va_start(valist, format);
174     res = MSVCRT_vswscanf(str, format, valist);
175     va_end(valist);
176     return res;
177 }
178
179
180 /*********************************************************************
181  *              _cscanf (MSVCRT.@)
182  */
183 int _cscanf(const char *format, ...)
184 {
185     va_list valist;
186     int res;
187
188     va_start(valist, format);
189     res = MSVCRT_vcscanf(format, valist);
190     va_end(valist);
191     return res;
192 }