ReactOS 0.4.15-dev-7674-gc0b4db1
scanf.c
Go to the documentation of this file.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <stdarg.h>
27#include <limits.h>
28
29#include <wine/winternl.h>
30#include <wine/debug.h>
31
32#include "winesup.h"
33
35
36//extern FILE _iob[];
37
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.
40 */
41static 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;
47}
48
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.
51 */
52static int wchar2digit(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;
58}
59
60#ifndef _LIBCNT_
61/* vfscanf_l */
62#undef WIDE_SCANF
63#undef CONSOLE
64#undef STRING
65#undef SECURE
66#include "scanf.h"
67
68/* vfwscanf_l */
69#define WIDE_SCANF 1
70#undef CONSOLE
71#undef STRING
72#undef SECURE
73#include "scanf.h"
74#endif /* !_LIBCNT_ */
75
76/* vsscanf_l */
77#undef WIDE_SCANF
78#undef CONSOLE
79#define STRING 1
80#undef SECURE
81#include "scanf.h"
82
83/* vswscanf_l */
84#define WIDE_SCANF 1
85#undef CONSOLE
86#define STRING 1
87#undef SECURE
88#include "scanf.h"
89
90/* vsnscanf_l */
91#undef WIDE_SCANF
92#undef CONSOLE
93#define STRING 1
94#define STRING_LEN 1
95#undef SECURE
96#include "scanf.h"
97
98/* vsnwscanf_l */
99#define WIDE_SCANF 1
100#undef CONSOLE
101#define STRING 1
102#define STRING_LEN 1
103#undef SECURE
104#include "scanf.h"
105
106#ifndef _LIBCNT_
107/* vcscanf_l */
108#undef WIDE_SCANF
109#define CONSOLE 1
110#undef STRING
111#undef SECURE
112#include "scanf.h"
113
114
115/*********************************************************************
116 * fscanf (MSVCRT.@)
117 */
118int CDECL fscanf(FILE *file, const char *format, ...)
119{
121 int res;
122
124 res = vfscanf_l(file, format, NULL, valist);
126 return res;
127}
128
129/*********************************************************************
130 * scanf (MSVCRT.@)
131 */
132int CDECL scanf(const char *format, ...)
133{
135 int res;
136
138 res = vfscanf_l(stdin, format, NULL, valist);
140 return res;
141}
142
143/*********************************************************************
144 * fwscanf (MSVCRT.@)
145 */
146int CDECL fwscanf(FILE *file, const wchar_t *format, ...)
147{
149 int res;
150
152 res = vfwscanf_l(file, format, NULL, valist);
154 return res;
155}
156
157
158/*********************************************************************
159 * wscanf (MSVCRT.@)
160 */
161int CDECL wscanf(const wchar_t *format, ...)
162{
164 int res;
165
167 res = vfwscanf_l(stdin, format, NULL, valist);
169 return res;
170}
171#endif /* !_LIBCNT_ */
172
173
174/*********************************************************************
175 * sscanf (MSVCRT.@)
176 */
177int CDECL sscanf(const char *str, const char *format, ...)
178{
180 int res;
181
183 res = vsscanf_l(str, format, NULL, valist);
185 return res;
186}
187
188
189/*********************************************************************
190 * swscanf (MSVCRT.@)
191 */
192int CDECL swscanf(const wchar_t *str, const wchar_t *format, ...)
193{
195 int res;
196
198 res = vswscanf_l(str, format, NULL, valist);
200 return res;
201}
202
203#ifndef _LIBCNT_
204/*********************************************************************
205 * _cscanf (MSVCRT.@)
206 */
207int CDECL _cscanf(const char *format, ...)
208{
210 int res;
211
213 res = vcscanf_l(format, NULL, valist);
215 return res;
216}
217#endif
218
219/*********************************************************************
220 * _snwscanf (MSVCRT.@)
221 */
222int WINAPIV _snwscanf(const wchar_t *input, size_t length,
223 const wchar_t *format, ...)
224{
226 int res;
227
229 res = vsnwscanf_l(input, length, format, NULL, valist);
231 return res;
232}
233
234/*********************************************************************
235 * _snscanf (MSVCRT.@)
236 */
237int CDECL _snscanf(const char *input, size_t length, const char *format, ...)
238{
240 int res;
241
243 res = vsnscanf_l(input, length, format, NULL, valist);
245 return res;
246}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define NULL
Definition: types.h:112
#define CDECL
Definition: compat.h:29
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLuint res
Definition: glext.h:9613
const GLubyte * c
Definition: glext.h:8905
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum GLenum GLenum input
Definition: glext.h:9031
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
_Check_return_ _CRTIMP int __cdecl scanf(_In_z_ _Scanf_format_string_ const char *_Format,...)
#define stdin
Definition: stdio.h:98
static __ms_va_list valist
Definition: printf.c:66
const WCHAR * str
#define WINAPIV
Definition: sdbpapi.h:64
int CDECL fscanf(FILE *file, const char *format,...)
Definition: scanf.c:118
int WINAPIV _snwscanf(const wchar_t *input, size_t length, const wchar_t *format,...)
Definition: scanf.c:222
static int wchar2digit(wchar_t c, int base)
Definition: scanf.c:52
int CDECL wscanf(const wchar_t *format,...)
Definition: scanf.c:161
static int char2digit(char c, int base)
Definition: scanf.c:41
int CDECL _snscanf(const char *input, size_t length, const char *format,...)
Definition: scanf.c:237
int CDECL sscanf(const char *str, const char *format,...)
Definition: scanf.c:177
int CDECL _cscanf(const char *format,...)
Definition: scanf.c:207
int CDECL fwscanf(FILE *file, const wchar_t *format,...)
Definition: scanf.c:146
Definition: fci.c:127
#define __ms_va_list
Definition: windef.h:456
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457