3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <_printf.h> /* fnptr_t */
22 #include <string.h> /* strlen() */
23 #include <stdarg.h> /* va_list, va_arg() */
27 static int scanf_getint (int *n
)
29 char *str
= (char *) malloc (sizeof (char) * 128);
44 if (c
== '\n' || i
> 127)
74 /* TODO: implement real floatint point format */
75 static int scanf_getfloat (float *n
)
77 char *str
= (char *) malloc (sizeof (char) * 128);
92 if (c
== '\n' || i
> 127)
115 *n
= (float) atoi (str
);
122 static int scanf_gethex (int *n
)
124 char *str
= (char *) malloc (sizeof (char) * 128);
139 if (c
== '\n' || i
> 127)
164 *n
= strtol (str
, &endptr
, 16);
171 static int scanf_getstring (unsigned char *n
)
207 static int scanf_getchar (unsigned char *n
)
242 int vscanf (const char *fmt
, va_list args
)
247 unsigned char *buf
= 0;
249 for (; *fmt
; fmt
++) {
250 /* probably argument is here */
257 if (*fmt
== 'd' || *fmt
== 'i' || *fmt
== 'u') {
258 num
= va_arg (args
, int *);
260 if (scanf_getint (num
))
266 if (*fmt
== 'x' || *fmt
== 'X') {
267 num
= va_arg (args
, int *);
269 if (scanf_gethex (num
))
276 buf
= va_arg (args
, unsigned char *);
278 if (scanf_getchar (buf
))
285 fp
= va_arg (args
, float *);
287 if (scanf_getfloat (fp
))
294 buf
= va_arg (args
, unsigned char *);
296 if (scanf_getstring (buf
))