aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/bada/sscanf.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2011-10-19 05:03:46 -0700
committerEugene Sandulenko2011-10-19 05:03:46 -0700
commit19134ecf7e543600fda7e9855ee4b3aa6822548c (patch)
treeae2f3917075cceb3ce74c34013bd48459f384c9d /backends/platform/bada/sscanf.cpp
parent84bc5651271f70e470099a19ab197ef038ef4a3b (diff)
parented07b99b22c2cf092f207dc15b26801c502534ac (diff)
downloadscummvm-rg350-19134ecf7e543600fda7e9855ee4b3aa6822548c.tar.gz
scummvm-rg350-19134ecf7e543600fda7e9855ee4b3aa6822548c.tar.bz2
scummvm-rg350-19134ecf7e543600fda7e9855ee4b3aa6822548c.zip
Merge pull request #106 from chrisws/branch-1-4-c
BADA: Misc changes merged from appstore release
Diffstat (limited to 'backends/platform/bada/sscanf.cpp')
-rw-r--r--backends/platform/bada/sscanf.cpp49
1 files changed, 40 insertions, 9 deletions
diff --git a/backends/platform/bada/sscanf.cpp b/backends/platform/bada/sscanf.cpp
index 4ef964b47e..b5e5b88cb5 100644
--- a/backends/platform/bada/sscanf.cpp
+++ b/backends/platform/bada/sscanf.cpp
@@ -31,17 +31,32 @@
//
bool scanInt(const char **in, va_list *ap, int max) {
- while (**in && (**in == ' ' || **in == '0')) {
+ // skip leading space characters
+ while (**in && **in == ' ') {
+ (*in)++;
+ }
+
+ // number optionally preceeded with a + or - sign.
+ bool negate = false;
+ if (**in == '-') {
+ (*in)++;
+ negate = true;
+ }
+
+ if (**in == '+') {
(*in)++;
}
int *arg = va_arg(*ap, int*);
char *end;
- long n = strtol(*in, &end, 0);
+ long n = strtol(*in, &end, 10);
+ if (negate) {
+ n = -n;
+ }
bool err = false;
if (end == *in || (max > 0 && (end - *in) > max)) {
- err = true;
+ err = true;
} else {
*arg = (int)n;
*in = end;
@@ -162,21 +177,37 @@ extern "C" int simple_sscanf(const char *input, const char *format, ...) {
#if defined(TEST)
int main(int argc, char *pArgv[]) {
- int x,y,h;
+ int x,y,xx,yy,h;
char buffer[100];
unsigned u;
char c;
strcpy(buffer, "hello");
char *b = buffer;
- // strcpy(buffer, "in the buffer something");
- if (simple_sscanf("CAT 123x-10 0x100 FONT large 1 enough\n 123456.AUD $",
- "CAT %dx%d %x FONT %[^\n] %06u.AUD %c",
- &x, &y, &h, b, &u, &c) != 6) {
+ if (simple_sscanf("BBX 00009 -1 +10 000",
+ "BBX %d %d %d %d",
+ &x, &y, &xx, &yy) != 4) {
+ printf("Failed\n");
+ } else {
+ printf("Success %d %d %d %d\n", x, y, xx, yy);
+ }
+
+ if (simple_sscanf("CAT 123x-10 0x100h 123456.AUD $ ",
+ "CAT %dx%d %xh %06u.AUD %c",
+ &x, &y, &h, &u, &c) != 5) {
+ printf("Failed\n");
+ } else {
+ printf("Success %d %d %d %d '%c' \n", x, y, h, u, c);
+ }
+
+ if (simple_sscanf("COPYRIGHT \"Copyright (c) 1984, 1987 Foo Systems Incorporated",
+ "COPYRIGHT \"%[^\"]",
+ b) != 1) {
printf("Failed\n");
} else {
- printf("Success %d %d %d %s %d '%c'\n", x, y, h, buffer, u, c);
+ printf("Success %s\n", buffer);
}
+
return 0;
}
#endif