OpenCOBOL 1.1pre-rel
|
#include "config.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cobc.h"
#include "config.def"
Go to the source code of this file.
Defines | |
#define | CB_CONFIG_ANY(type, var, name) type var; |
#define | CB_CONFIG_INT(var, name) int var; |
#define | CB_CONFIG_STRING(var, name) const char *var; |
#define | CB_CONFIG_BOOLEAN(var, name) int var; |
#define | CB_CONFIG_SUPPORT(var, name) enum cb_support var; |
#define | CB_CONFIG_ANY(type, var, name) {ANY, name, &var, NULL}, |
#define | CB_CONFIG_INT(var, name) {INT, name, &var, NULL}, |
#define | CB_CONFIG_STRING(var, name) {STRING, name, &var, NULL}, |
#define | CB_CONFIG_BOOLEAN(var, name) {BOOLEAN, name, &var, NULL}, |
#define | CB_CONFIG_SUPPORT(var, name) {SUPPORT, name, &var, NULL}, |
Enumerations | |
enum | cb_config_type { ANY, INT, STRING, BOOLEAN, SUPPORT } |
Functions | |
int | cb_load_std (const char *name) |
int | cb_load_conf (const char *fname, const int check_nodef, const int prefix_dir) |
Variables | |
struct noreserve * | norestab = NULL |
#define CB_CONFIG_SUPPORT | ( | var, | |
name | |||
) | enum cb_support var; |
enum cb_config_type |
int cb_load_conf | ( | const char * | fname, |
const int | check_nodef, | ||
const int | prefix_dir | ||
) |
Definition at line 112 of file config.c.
{ 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]; /* initialize the config table */ 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; } /* open the config file */ fp = fopen (name, "r"); if (fp == NULL) { perror (name); return -1; } /* read the config file */ ret = 0; line = 0; while (fgets (buff, COB_SMALL_BUFF, fp)) { line++; /* skip comments */ if (buff[0] == '#') { continue; } /* skip blank lines */ for (s = buff; *s; s++) { if (isgraph (*s)) { break; } } if (!*s) { continue; } /* get the tag */ s = strpbrk (buff, " \t:="); if (!s) { fprintf (stderr, "%s:%d: invalid line\n", fname, line); ret = -1; continue; } *s = 0; /* find the entry */ 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; } /* get the value */ 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; /* set the value */ 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) { /* include another conf file */ 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); /* checks for no definition */ 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; }
int cb_load_std | ( | const char * | name | ) |
Definition at line 106 of file config.c.
{ return cb_load_conf (name, 1, 1); }
enum cb_config_type type |