(xuflds, xunsymbol, xuloadrow): Split VAL_SYMBOL into
VAL_SYMBOL and VAL_SYMBOL_SET. Identify SYMBOL_SET by the '(' and ')'. Switch SYMBOL_SET separator from '|' to a space.
This commit is contained in:
parent
125af4b338
commit
bf94174f88
1 changed files with 35 additions and 6 deletions
|
@ -58,6 +58,7 @@ enum enum_value {
|
||||||
VAL_NOTUSED,
|
VAL_NOTUSED,
|
||||||
VAL_STRING,
|
VAL_STRING,
|
||||||
VAL_SYMBOL,
|
VAL_SYMBOL,
|
||||||
|
VAL_SYMBOL_SET,
|
||||||
VAL_DOUBLE
|
VAL_DOUBLE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -134,6 +135,26 @@ xuflds(FILE *fp, struct value values[])
|
||||||
values[i].v_type = VAL_STRING;
|
values[i].v_type = VAL_STRING;
|
||||||
values[i].v_field.v_string = strdup(buf);
|
values[i].v_field.v_string = strdup(buf);
|
||||||
break;
|
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:
|
default:
|
||||||
if (fscanf(fp, "%1023[^ \n]%c", buf, &sep) != 2) {
|
if (fscanf(fp, "%1023[^ \n]%c", buf, &sep) != 2) {
|
||||||
return gripe("Junk in field %d", i + 1);
|
return gripe("Junk in field %d", i + 1);
|
||||||
|
@ -163,15 +184,21 @@ xuflds(FILE *fp, struct value values[])
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
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 (ca->ca_flags & NSC_BITS)
|
if (symbol_set && !(ca->ca_flags & NSC_BITS))
|
||||||
token = strtok( buf, "|");
|
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
|
else
|
||||||
token = buf;
|
token = buf;
|
||||||
|
|
||||||
|
@ -188,7 +215,7 @@ xunsymbol(struct castr *ca, char *buf)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -238,13 +265,15 @@ 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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue