Roll back to rev. 1.3 in preparation of a re-engineering of the

changes since then.
This commit is contained in:
Markus Armbruster 2005-12-01 18:56:41 +00:00
parent 65cda58286
commit 33912952bb

View file

@ -58,7 +58,6 @@ enum enum_value {
VAL_NOTUSED, VAL_NOTUSED,
VAL_STRING, VAL_STRING,
VAL_SYMBOL, VAL_SYMBOL,
VAL_SYMBOL_SET,
VAL_DOUBLE VAL_DOUBLE
}; };
@ -108,7 +107,7 @@ xuesc(char *buf)
static int static int
xuflds(FILE *fp, struct value values[]) xuflds(FILE *fp, struct value values[])
{ {
int i, j, ch; int i, ch;
char sep; char sep;
char buf[1024]; char buf[1024];
@ -125,88 +124,15 @@ xuflds(FILE *fp, struct value values[])
values[i].v_type = VAL_DOUBLE; values[i].v_type = VAL_DOUBLE;
break; break;
case '"': case '"':
ch = getc(fp); if (fscanf(fp, "\"%1023[^ \n]%c", buf, &sep) != 2
j = 0; || buf[strlen(buf)-1] != '"')
buf[j] = '\0'; return gripe("Malformed string in field %d", i + 1);
do { buf[strlen(buf)-1] = '\0';
if (j >= 1023) if (!xuesc(buf))
return gripe("Malformed string in field %d", i + 1); return gripe("Invalid escape sequence in field %d",
ch = getc(fp); i + 1);
switch (ch) { values[i].v_type = VAL_STRING;
case '"': values[i].v_field.v_string = strdup(buf);
values[i].v_type = VAL_STRING;
if (!j)
values[i].v_field.v_string = NULL;
else {
buf[j] = '\0';
if (!xuesc(buf))
return gripe("Invalid escape sequence in field %d",
i + 1);
values[i].v_field.v_string = strdup(buf);
}
sep = getc(fp);
if (sep == EOF)
return gripe("Unexpected end of the row");
break;
case EOF:
case '\n':
return gripe("Malformed string in field %d", i + 1);
case ' ':
if (!j)
break;
/*
* fall through
*/
default:
buf[j++] = ch;
break;
}
} while (ch != '"');
break;
case '(':
ch = getc(fp);
j = 0;
buf[j] = '\0';
do {
if (j >= 1023)
return gripe("Malformed string in field %d", i + 1);
ch = getc(fp);
switch (ch) {
case ')':
if (!j) {
values[i].v_type = VAL_DOUBLE;
values[i].v_field.v_double = 0.0;
} else {
buf[j] = '\0';
if (!xuesc(buf))
return gripe("Invalid escape sequence in field %d",
i + 1);
values[i].v_type = VAL_SYMBOL_SET;
values[i].v_field.v_string = strdup(buf);
}
sep = getc(fp);
if (sep == EOF)
return gripe("Unexpected end of the row");
break;
case EOF:
case '\n':
return gripe("Malformed string in field %d", i + 1);
case ' ':
if (!j)
break;
else if (buf[j-1] == ' ')
break;
/*
* fall through
*/
default:
buf[j++] = ch;
break;
}
} while (ch != ')');
break;
case ' ':
ch = getc(fp);
break; break;
default: default:
if (fscanf(fp, "%1023[^ \n]%c", buf, &sep) != 2) { if (fscanf(fp, "%1023[^ \n]%c", buf, &sep) != 2) {
@ -237,21 +163,15 @@ xuflds(FILE *fp, struct value values[])
} }
static int static int
xunsymbol(struct castr *ca, char *buf, int symbol_set) xunsymbol(struct castr *ca, char *buf)
{ {
struct symbol *symbol = (struct symbol *)empfile[ca->ca_table].cache; struct symbol *symbol = (struct symbol *)empfile[ca->ca_table].cache;
int i; int i;
int value = 0; int value = 0;
char *token; char *token;
if (symbol_set && !(ca->ca_flags & NSC_BITS)) if (ca->ca_flags & NSC_BITS)
return gripe("Symbol Set (%s) was found but the field does not have " token = strtok( buf, "|");
"NSC_BITS set for field %s", buf, ca->ca_name);
if (!symbol_set && (ca->ca_flags & NSC_BITS))
return gripe("Symbol (%s) was found but the field was expecting an "
"Symbol Set for field %s", buf, ca->ca_name);
if (symbol_set)
token = strtok(buf, " ");
else else
token = buf; token = buf;
@ -268,7 +188,7 @@ xunsymbol(struct castr *ca, char *buf, int symbol_set)
else else
return gripe("Symbol %s was not found for field %s", token, return gripe("Symbol %s was not found for field %s", token,
ca->ca_name); ca->ca_name);
token = strtok(NULL, " "); token = strtok(NULL, "|");
} }
return(value); return(value);
} }
@ -318,15 +238,13 @@ xuloadrow(int type, int row, struct value values[])
* factor out NSC_CONST comparsion * factor out NSC_CONST comparsion
*/ */
switch (values[j].v_type) { switch (values[j].v_type) {
case VAL_SYMBOL_SET:
case VAL_SYMBOL: case VAL_SYMBOL:
if (ca[i].ca_table == EF_BAD) if (ca[i].ca_table == EF_BAD)
return(gripe("Found symbol string %s, but column %s " return(gripe("Found symbol string %s, but column %s "
"is not symbol or symbol sets", "is not symbol or symbol sets",
values[j].v_field.v_string, ca[i].ca_name)); values[j].v_field.v_string, ca[i].ca_name));
values[j].v_field.v_double = values[j].v_field.v_double =
(double)xunsymbol(&ca[i], values[j].v_field.v_string, (double)xunsymbol(&ca[i], values[j].v_field.v_string);
values[j].v_type == VAL_SYMBOL_SET ? 1 : 0);
free(values[i].v_field.v_string); free(values[i].v_field.v_string);
if (values[j].v_field.v_double < 0.0) if (values[j].v_field.v_double < 0.0)
return -1; return -1;
@ -458,7 +376,6 @@ xuloadrow(int type, int row, struct value values[])
break; break;
case VAL_STRING: case VAL_STRING:
case VAL_SYMBOL: case VAL_SYMBOL:
case VAL_SYMBOL_SET:
return gripe("Extra junk after the last column, read %s", return gripe("Extra junk after the last column, read %s",
values[j].v_field.v_string); values[j].v_field.v_string);
case VAL_DOUBLE: case VAL_DOUBLE:
@ -471,27 +388,6 @@ xuloadrow(int type, int row, struct value values[])
return 0; return 0;
} }
static void
xuskipcommentlines(FILE *fp)
{
int ch;
for (;;) {
ch = getc(fp);
if (ch == EOF)
return;
if (ch == '#') {
do {
ch = getc(fp);
} while (ch != '\n' && ch != EOF);
lineno++;
} else {
ungetc(ch, fp);
return;
}
}
}
int int
xundump(FILE *fp, char *file, int expected_table) xundump(FILE *fp, char *file, int expected_table)
{ {
@ -508,7 +404,6 @@ xundump(FILE *fp, char *file, int expected_table)
} else } else
lineno++; lineno++;
xuskipcommentlines(fp);
if (fscanf(fp, "XDUMP %63[^0123456789]%*d%c", name, &sep) != 2) if (fscanf(fp, "XDUMP %63[^0123456789]%*d%c", name, &sep) != 2)
return gripe("Expected XDUMP header"); return gripe("Expected XDUMP header");
if (sep != '\n') if (sep != '\n')
@ -532,7 +427,6 @@ xundump(FILE *fp, char *file, int expected_table)
fixed_rows = has_const(ef_cadef(type)); fixed_rows = has_const(ef_cadef(type));
for (row = 0; ; row++) { for (row = 0; ; row++) {
xuskipcommentlines(fp);
lineno++; lineno++;
ch = getc(fp); ch = getc(fp);
ungetc(ch, fp); ungetc(ch, fp);
@ -571,6 +465,5 @@ xundump(FILE *fp, char *file, int expected_table)
if (!fixed_rows) if (!fixed_rows)
xuinitrow(type, row); xuinitrow(type, row);
xuskipcommentlines(fp);
return 0; return 0;
} }