Added support for the RegisterDlls section (partly based on a patch by
[wine.git] / dlls / msvcrt / scanf.c
blobe7b240b1a32d9795b9b0e4801c79da6f3d55ad70
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "msvcrt.h"
33 #include "msvcrt/conio.h"
34 #include "msvcrt/io.h"
35 #include "msvcrt/stdio.h"
36 #include "msvcrt/wctype.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
41 extern MSVCRT_FILE MSVCRT__iob[];
43 /* helper function for *scanf. Returns the value of character c in the
44 * given base, or -1 if the given character is not a digit of the base.
46 static int char2digit(char c, int base) {
47 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
48 if (base<=10) return -1;
49 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
50 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
51 return -1;
54 /* helper function for *wscanf. Returns the value of character c in the
55 * given base, or -1 if the given character is not a digit of the base.
57 static int wchar2digit(MSVCRT_wchar_t c, int base) {
58 if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');
59 if (base<=10) return -1;
60 if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);
61 if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);
62 return -1;
65 /* vfscanf */
66 #undef WIDE_SCANF
67 #undef CONSOLE
68 #undef STRING
69 #include "scanf.h"
71 /* vfwscanf */
72 #define WIDE_SCANF 1
73 #undef CONSOLE
74 #undef STRING
75 #include "scanf.h"
77 /* vsscanf */
78 #undef WIDE_SCANF
79 #undef CONSOLE
80 #define STRING 1
81 #include "scanf.h"
83 /* vswscanf */
84 #define WIDE_SCANF 1
85 #undef CONSOLE
86 #define STRING 1
87 #include "scanf.h"
89 /* vcscanf */
90 #undef WIDE_SCANF
91 #define CONSOLE 1
92 #undef STRING
93 #include "scanf.h"
96 /*********************************************************************
97 * fscanf (MSVCRT.@)
99 int MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
101 va_list valist;
102 int res;
104 va_start(valist, format);
105 res = MSVCRT_vfscanf(file, format, valist);
106 va_end(valist);
107 return res;
110 /*********************************************************************
111 * scanf (MSVCRT.@)
113 int MSVCRT_scanf(const char *format, ...)
115 va_list valist;
116 int res;
118 va_start(valist, format);
119 res = MSVCRT_vfscanf(MSVCRT_stdin, format, valist);
120 va_end(valist);
121 return res;
124 /*********************************************************************
125 * fwscanf (MSVCRT.@)
127 int MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
129 va_list valist;
130 int res;
132 va_start(valist, format);
133 res = MSVCRT_vfwscanf(file, format, valist);
134 va_end(valist);
135 return res;
139 /*********************************************************************
140 * wscanf (MSVCRT.@)
142 int MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
144 va_list valist;
145 int res;
147 va_start(valist, format);
148 res = MSVCRT_vfwscanf(MSVCRT_stdin, format, valist);
149 va_end(valist);
150 return res;
154 /*********************************************************************
155 * sscanf (MSVCRT.@)
157 int MSVCRT_sscanf(const char *str, const char *format, ...)
159 va_list valist;
160 int res;
162 va_start(valist, format);
163 res = MSVCRT_vsscanf(str, format, valist);
164 va_end(valist);
165 return res;
169 /*********************************************************************
170 * swscanf (MSVCRT.@)
172 int MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ...)
174 va_list valist;
175 int res;
177 va_start(valist, format);
178 res = MSVCRT_vswscanf(str, format, valist);
179 va_end(valist);
180 return res;
184 /*********************************************************************
185 * _cscanf (MSVCRT.@)
187 int _cscanf(const char *format, ...)
189 va_list valist;
190 int res;
192 va_start(valist, format);
193 res = MSVCRT_vcscanf(format, valist);
194 va_end(valist);
195 return res;