summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>1998-12-14 22:49:47 +0000
committerwtc%netscape.com <devnull@localhost>1998-12-14 22:49:47 +0000
commit692e49b9fb03653d576aaf5c9a8b02d74e7593e0 (patch)
tree2145d4f68ecb96d9f2722d1d6cae55516f01f945
parentd9f34dbfdb96c554f2ca465c66bcb06e1390cab9 (diff)
downloadnspr-hg-692e49b9fb03653d576aaf5c9a8b02d74e7593e0.tar.gz
Minor cleanup/fix in DoScanf.
-rw-r--r--pr/src/io/prscanf.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/pr/src/io/prscanf.c b/pr/src/io/prscanf.c
index 96530bf6..833d2763 100644
--- a/pr/src/io/prscanf.c
+++ b/pr/src/io/prscanf.c
@@ -387,6 +387,7 @@ GetFloat(ScanfState *state)
/*
* Convert, and return the end of the conversion spec.
+ * Return NULL on error.
*/
static const char *
@@ -544,6 +545,7 @@ DoScanf(ScanfState *state, const char *fmt)
cPtr = fmt;
while (1) {
if (isspace(*cPtr)) {
+ /* white space: skip */
do {
cPtr++;
} while (isspace(*cPtr));
@@ -551,20 +553,12 @@ DoScanf(ScanfState *state, const char *fmt)
ch = GET(state);
} while (isspace(ch));
UNGET(state, ch);
- } else if (*cPtr != '%') {
- if (*cPtr == '\0') {
- return nConverted;
- }
- ch = GET(state);
- if (ch != *cPtr) {
- UNGET(state, ch);
- return nConverted;
- }
- cPtr++;
- } else {
+ } else if (*cPtr == '%') {
+ /* format spec: convert */
cPtr++;
state->assign = PR_TRUE;
if (*cPtr == '*') {
+ cPtr++;
state->assign = PR_FALSE;
}
for (state->width = 0; isdigit(*cPtr); cPtr++) {
@@ -594,6 +588,17 @@ DoScanf(ScanfState *state, const char *fmt)
nConverted++;
}
cPtr++;
+ } else {
+ /* others: must match */
+ if (*cPtr == '\0') {
+ return nConverted;
+ }
+ ch = GET(state);
+ if (ch != *cPtr) {
+ UNGET(state, ch);
+ return nConverted;
+ }
+ cPtr++;
}
}
}