diff options
Diffstat (limited to 'firmware/common/sscanf.c')
-rw-r--r-- | firmware/common/sscanf.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/firmware/common/sscanf.c b/firmware/common/sscanf.c index a63a384456..c710a10349 100644 --- a/firmware/common/sscanf.c +++ b/firmware/common/sscanf.c | |||
@@ -82,6 +82,18 @@ static int parse_hex(int (*peek)(void *userp), | |||
82 | return n; | 82 | return n; |
83 | } | 83 | } |
84 | 84 | ||
85 | static int skip_spaces(int (*peek)(void *userp), | ||
86 | void (*pop)(void *userp), | ||
87 | void *userp) | ||
88 | { | ||
89 | int n = 0; | ||
90 | while (isspace((*peek)(userp))) { | ||
91 | n++; | ||
92 | (*pop)(userp); | ||
93 | } | ||
94 | return n; | ||
95 | } | ||
96 | |||
85 | static int scan(int (*peek)(void *userp), | 97 | static int scan(int (*peek)(void *userp), |
86 | void (*pop)(void *userp), | 98 | void (*pop)(void *userp), |
87 | void *userp, | 99 | void *userp, |
@@ -103,14 +115,10 @@ static int scan(int (*peek)(void *userp), | |||
103 | { | 115 | { |
104 | ch = *fmt++; | 116 | ch = *fmt++; |
105 | 117 | ||
106 | while (isspace((*peek)(userp))) { | ||
107 | n_chars++; | ||
108 | (*pop)(userp); | ||
109 | } | ||
110 | |||
111 | switch (ch) | 118 | switch (ch) |
112 | { | 119 | { |
113 | case 'x': | 120 | case 'x': |
121 | n_chars += skip_spaces(peek, pop, userp); | ||
114 | if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) | 122 | if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) |
115 | { | 123 | { |
116 | *(va_arg(ap, unsigned int *)) = ulval; | 124 | *(va_arg(ap, unsigned int *)) = ulval; |
@@ -121,6 +129,7 @@ static int scan(int (*peek)(void *userp), | |||
121 | return n; | 129 | return n; |
122 | break; | 130 | break; |
123 | case 'd': | 131 | case 'd': |
132 | n_chars += skip_spaces(peek, pop, userp); | ||
124 | if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) | 133 | if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) |
125 | { | 134 | { |
126 | *(va_arg(ap, int *)) = lval; | 135 | *(va_arg(ap, int *)) = lval; |
@@ -135,6 +144,7 @@ static int scan(int (*peek)(void *userp), | |||
135 | n++; | 144 | n++; |
136 | break; | 145 | break; |
137 | case 'l': | 146 | case 'l': |
147 | n_chars += skip_spaces(peek, pop, userp); | ||
138 | ch = *fmt++; | 148 | ch = *fmt++; |
139 | switch (ch) | 149 | switch (ch) |
140 | { | 150 | { |
@@ -176,10 +186,7 @@ static int scan(int (*peek)(void *userp), | |||
176 | 186 | ||
177 | if (literal) | 187 | if (literal) |
178 | { | 188 | { |
179 | while (isspace((*peek)(userp))) { | 189 | n_chars += skip_spaces(peek, pop, userp); |
180 | (*pop)(userp); | ||
181 | n_chars++; | ||
182 | } | ||
183 | if ((*peek)(userp) != ch) | 190 | if ((*peek)(userp) != ch) |
184 | return n; | 191 | return n; |
185 | else | 192 | else |