{
char *s;
char *e;
const char *name;
const char *val;
void *var;
FILE *fp;
char *nores;
struct noreserve *noresptr;
int i;
int j;
int ret;
int saveret;
int line;
char buff[COB_SMALL_BUFF];
if (check_nodef) {
for (i = 0; config_table[i].name; i++) {
config_table[i].val = NULL;
}
}
if (prefix_dir) {
snprintf (buff, COB_SMALL_MAX, "%s/%s", cob_config_dir, fname);
name = buff;
} else {
name = fname;
}
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
return -1;
}
ret = 0;
line = 0;
while (fgets (buff, COB_SMALL_BUFF, fp)) {
line++;
if (buff[0] == '#') {
continue;
}
for (s = buff; *s; s++) {
if (isgraph (*s)) {
break;
}
}
if (!*s) {
continue;
}
s = strpbrk (buff, " \t:=");
if (!s) {
fprintf (stderr, "%s:%d: invalid line\n", fname, line);
ret = -1;
continue;
}
*s = 0;
for (i = 0; config_table[i].name; i++) {
if (strcmp (buff, config_table[i].name) == 0) {
break;
}
}
if (!config_table[i].name) {
fprintf (stderr, "%s:%d: unknown tag '%s'\n", fname, line, buff);
ret = -1;
continue;
}
for (s++; *s && strchr (" \t:=", *s); s++) {
;
}
e = s + strlen (s) - 1;
for (; e >= s && strchr (" \t\r\n", *e); e--) {
;
}
e[1] = 0;
config_table[i].val = s;
name = config_table[i].name;
var = config_table[i].var;
val = config_table[i].val;
switch (config_table[i].type) {
case ANY:
if (strcmp (name, "assign-clause") == 0) {
if (strcmp (val, "cobol2002") == 0) {
unsupported_value (fname, line, val);
ret = -1;
} else if (strcmp (val, "mf") == 0) {
cb_assign_clause = CB_ASSIGN_MF;
} else if (strcmp (val, "ibm") == 0) {
cb_assign_clause = CB_ASSIGN_IBM;
} else {
invalid_value (fname, line, name);
ret = -1;
}
} else if (strcmp (name, "binary-size") == 0) {
if (strcmp (val, "2-4-8") == 0) {
cb_binary_size = CB_BINARY_SIZE_2_4_8;
} else if (strcmp (val, "1-2-4-8") == 0) {
cb_binary_size = CB_BINARY_SIZE_1_2_4_8;
} else if (strcmp (val, "1--8") == 0) {
cb_binary_size = CB_BINARY_SIZE_1__8;
} else {
invalid_value (fname, line, name);
ret = -1;
}
} else if (strcmp (name, "binary-byteorder") == 0) {
if (strcmp (val, "native") == 0) {
cb_binary_byteorder = CB_BYTEORDER_NATIVE;
} else if (strcmp (val, "big-endian") == 0) {
cb_binary_byteorder = CB_BYTEORDER_BIG_ENDIAN;
} else {
invalid_value (fname, line, name);
ret = -1;
}
}
break;
case INT:
for (j = 0; val[j]; j++) {
if (!isdigit (val[j])) {
invalid_value (fname, line, name);
ret = -1;
break;
}
}
*((int *)var) = atoi (val);
break;
case STRING:
val = read_string (val);
if (strcmp (name, "include") == 0) {
saveret = ret;
if (cb_load_conf (val, 0, 1) != 0) {
return -1;
}
ret = saveret;
} else if (strcmp (name, "not-reserved") == 0) {
nores = read_string (val);
noresptr = cobc_malloc (sizeof (struct noreserve));
noresptr->noresword = cobc_malloc (strlen (nores) + 1);
strcpy (noresptr->noresword, nores);
noresptr->next = norestab;
norestab = noresptr;
} else {
*((const char **)var) = val;
}
break;
case BOOLEAN:
if (strcmp (val, "yes") == 0) {
*((int *)var) = 1;
} else if (strcmp (val, "no") == 0) {
*((int *)var) = 0;
} else {
invalid_value (fname, line, name);
ret = -1;
}
break;
case SUPPORT:
if (strcmp (val, "ok") == 0) {
*((enum cb_support *)var) = CB_OK;
} else if (strcmp (val, "warning") == 0) {
*((enum cb_support *)var) = CB_WARNING;
} else if (strcmp (val, "archaic") == 0) {
*((enum cb_support *)var) = CB_ARCHAIC;
} else if (strcmp (val, "obsolete") == 0) {
*((enum cb_support *)var) = CB_OBSOLETE;
} else if (strcmp (val, "skip") == 0) {
*((enum cb_support *)var) = CB_SKIP;
} else if (strcmp (val, "ignore") == 0) {
*((enum cb_support *)var) = CB_IGNORE;
} else if (strcmp (val, "error") == 0) {
*((enum cb_support *)var) = CB_ERROR;
} else if (strcmp (val, "unconformable") == 0) {
*((enum cb_support *)var) = CB_UNCONFORMABLE;
} else {
invalid_value (fname, line, name);
ret = -1;
}
break;
default:
fprintf (stderr, _("%s:%d: invalid type for '%s'\n"),
fname, line, name);
ret = -1;
break;
}
}
fclose (fp);
if (check_nodef) {
for (i = 2; config_table[i].name; i++) {
if (config_table[i].val == NULL) {
fprintf (stderr, "%s: no definition of '%s'\n",
fname, config_table[i].name);
ret = -1;
}
}
}
return ret;
}