diff options
author | Tomasz Malesinski <tomal@rockbox.org> | 2006-02-03 23:39:12 +0000 |
---|---|---|
committer | Tomasz Malesinski <tomal@rockbox.org> | 2006-02-03 23:39:12 +0000 |
commit | 91f08b5a24283827c15baec98e55d15d31c5a678 (patch) | |
tree | 2da1b577c00bc932f2098b88c36cef62250b076e /firmware | |
parent | c4d24a07abe2e6adce3cb4ba28d6e60438db89a2 (diff) |
Made %n not eat white space.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8557 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-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), return n; } +static int skip_spaces(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp) +{ + int n = 0; + while (isspace((*peek)(userp))) { + n++; + (*pop)(userp); + } + return n; +} + static int scan(int (*peek)(void *userp), void (*pop)(void *userp), void *userp, @@ -103,14 +115,10 @@ static int scan(int (*peek)(void *userp), { ch = *fmt++; - while (isspace((*peek)(userp))) { - n_chars++; - (*pop)(userp); - } - switch (ch) { case 'x': + n_chars += skip_spaces(peek, pop, userp); if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) { *(va_arg(ap, unsigned int *)) = ulval; @@ -121,6 +129,7 @@ static int scan(int (*peek)(void *userp), return n; break; case 'd': + n_chars += skip_spaces(peek, pop, userp); if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) { *(va_arg(ap, int *)) = lval; @@ -135,6 +144,7 @@ static int scan(int (*peek)(void *userp), n++; break; case 'l': + n_chars += skip_spaces(peek, pop, userp); ch = *fmt++; switch (ch) { @@ -176,10 +186,7 @@ static int scan(int (*peek)(void *userp), if (literal) { - while (isspace((*peek)(userp))) { - (*pop)(userp); - n_chars++; - } + n_chars += skip_spaces(peek, pop, userp); if ((*peek)(userp) != ch) return n; else |