diff --git a/src/lib/common/xundump.c b/src/lib/common/xundump.c index e18f4103..d04f671c 100644 --- a/src/lib/common/xundump.c +++ b/src/lib/common/xundump.c @@ -58,6 +58,7 @@ enum enum_value { VAL_NOTUSED, VAL_STRING, VAL_SYMBOL, + VAL_SYMBOL_SET, VAL_DOUBLE }; @@ -134,6 +135,26 @@ xuflds(FILE *fp, struct value values[]) values[i].v_type = VAL_STRING; values[i].v_field.v_string = strdup(buf); break; + case '(': + ch = getc(fp); + ch = getc(fp); + if (ch == EOF) + return gripe("Unexpected end of file while reading a symbol set for field %d", i + 1); + if (ch == ')') { + values[i].v_field.v_double = 0.0; + values[i].v_type = VAL_DOUBLE; + sep = getc(fp); + if (sep == EOF) + return gripe("Unexpected end of file while reading a symbol set for field %d", i + 1); + break; + } + ungetc(ch, fp); + ungetc('(', fp); + if (fscanf(fp, "(%1023[^)\n])%c", buf, &sep) != 2) + return gripe("Malformed symbol set in field %d", i + 1); + values[i].v_type = VAL_SYMBOL_SET; + values[i].v_field.v_string = strdup(buf); + break; default: if (fscanf(fp, "%1023[^ \n]%c", buf, &sep) != 2) { return gripe("Junk in field %d", i + 1); @@ -163,15 +184,21 @@ xuflds(FILE *fp, struct value values[]) } static int -xunsymbol(struct castr *ca, char *buf) +xunsymbol(struct castr *ca, char *buf, int symbol_set) { struct symbol *symbol = (struct symbol *)empfile[ca->ca_table].cache; int i; int value = 0; char *token; - if (ca->ca_flags & NSC_BITS) - token = strtok( buf, "|"); + if (symbol_set && !(ca->ca_flags & NSC_BITS)) + return gripe("Symbol Set (%s) was found but the field does not have " + "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 token = buf; @@ -188,7 +215,7 @@ xunsymbol(struct castr *ca, char *buf) else return gripe("Symbol %s was not found for field %s", token, ca->ca_name); - token = strtok(NULL, "|"); + token = strtok(NULL, " "); } return(value); } @@ -238,13 +265,15 @@ xuloadrow(int type, int row, struct value values[]) * factor out NSC_CONST comparsion */ switch (values[j].v_type) { + case VAL_SYMBOL_SET: case VAL_SYMBOL: if (ca[i].ca_table == EF_BAD) return(gripe("Found symbol string %s, but column %s " "is not symbol or symbol sets", values[j].v_field.v_string, ca[i].ca_name)); 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); if (values[j].v_field.v_double < 0.0) return -1; @@ -437,7 +466,7 @@ xundump(FILE *fp, char *file, int expected_table) return gripe("Missing space after table name in header %s", name); name[strlen(name) - 1] = '\0'; - + type = ef_byname(name); if (type < 0) return gripe("Table not found %s", name);