Fixed typo.
[wine.git] / dlls / msvcrt / scanf.c
blob58cd6bca02ecae9ed9dcdefc51d5b5d10b3057b2
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 /* helper function for *scanf. Returns the value of character c in the
42 * given base, or -1 if the given character is not a digit of the base.
44 static int char2digit(char c, int base) {
45 if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
46 if (base<=10) return -1;
47 if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
48 if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
49 return -1;
52 /* helper function for *wscanf. Returns the value of character c in the
53 * given base, or -1 if the given character is not a digit of the base.
55 static int wchar2digit(MSVCRT_wchar_t c, int base) {
56 if ((c>=L'0') && (c<=L'9') && (c<=L'0'+base-1)) return (c-L'0');
57 if (base<=10) return -1;
58 if ((c>=L'A') && (c<=L'Z') && (c<=L'A'+base-11)) return (c-L'A'+10);
59 if ((c>=L'a') && (c<=L'z') && (c<=L'a'+base-11)) return (c-L'a'+10);
60 return -1;
64 /*********************************************************************
65 * fscanf (MSVCRT.@)
67 #undef WIDE_SCANF
68 #undef CONSOLE
69 #undef STRING
70 #include "scanf.h"
72 /*********************************************************************
73 * fwscanf (MSVCRT.@)
75 #define WIDE_SCANF 1
76 #undef CONSOLE
77 #undef STRING
78 #include "scanf.h"
80 /*********************************************************************
81 * sscanf (MSVCRT.@)
83 #undef WIDE_SCANF
84 #undef CONSOLE
85 #define STRING 1
86 #include "scanf.h"
88 /*********************************************************************
89 * swscanf (MSVCRT.@)
91 #define WIDE_SCANF 1
92 #undef CONSOLE
93 #define STRING 1
94 #include "scanf.h"
96 /*********************************************************************
97 * _cscanf (MSVCRT.@)
99 #undef WIDE_SCANF
100 #define CONSOLE 1
101 #undef STRING
102 #include "scanf.h"