3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <_printf.h> /* fnptr_t */
21 #include <string.h> /* strlen() */
22 #include <stdarg.h> /* va_list, va_arg() */
27 static int scanf_getint (const char *str
, int *n
)
34 /* TODO: implement real floatint point format */
35 static int scanf_getfloat (const char *str
, float *n
)
37 *n
= (float) atoi (str
);
42 static int scanf_gethex (const char *str
, int *n
)
46 *n
= strtol (str
, &endptr
, 16);
51 static int scanf_getstring (const char *str
, unsigned char *n
)
53 unsigned i
= strlen (str
);
61 static int scanf_getchar (const char *str
, unsigned char *n
)
68 int vsscanf (const char *str
, const char *fmt
, va_list args
)
73 unsigned char *buf
= 0;
76 unsigned s_len
= strlen (str
);
77 char *s
= (char *) malloc (sizeof (char) * s_len
);
84 for (count
= 0; count
< s_len
; count
++) {
85 if (str
[count
] != ' ')
86 s
[count
] = str
[count
];
93 for (; *fmt
; fmt
++) {
94 /* probably argument is here */
101 if (*fmt
== 'd' || *fmt
== 'i' || *fmt
== 'u') {
102 num
= va_arg (args
, int *);
104 if (scanf_getint (s
, num
)) {
112 if (*fmt
== 'x' || *fmt
== 'X') {
113 num
= va_arg (args
, int *);
115 if (scanf_gethex (s
+i
, num
)){
124 buf
= va_arg (args
, unsigned char *);
126 if (scanf_getchar (s
+i
, buf
)) {
135 fp
= va_arg (args
, float *);
137 if (scanf_getfloat (s
+i
, fp
)) {
146 buf
= va_arg (args
, unsigned char *);
148 if (scanf_getstring (s
+i
, buf
)) {