00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include <errno.h>
00037 #include <stdio.h>
00038 #include "file.h"
00039 #include "optlist.h"
00040 #include "product.h"
00041 #include "prototypes.h"
00042
00043 static int read_custom_table_file(char *);
00044
00045 int
00046 read_builtin_tables(void)
00047 {
00048 struct empfile *ep;
00049 FILE *fp;
00050 int lineno, res;
00051
00052
00053
00054
00055
00056
00057 for (ep = empfile; ep->name; ep++) {
00058 if (!EF_IS_GAME_STATE(ep->uid) && ep->file) {
00059 if ((fp = fopen(ep->file, "r")) == NULL) {
00060 fprintf(stderr, "Can't open %s for reading (%s)\n",
00061 ep->file, strerror(errno));
00062 return -1;
00063 }
00064 lineno = 1;
00065 res = xundump(fp, ep->file, &lineno, ep->uid);
00066 if (res >= 0 && getc(fp) != EOF) {
00067 fprintf(stderr, "%s: Junk after the table\n",
00068 ep->file);
00069 res = EF_BAD;
00070 }
00071 fclose(fp);
00072 if (res < 0)
00073 return -1;
00074 }
00075 }
00076
00077 return 0;
00078 }
00079
00080
00081
00082
00083
00084 int
00085 read_custom_tables(void)
00086 {
00087 char *tmp = strdup(custom_tables);
00088 char *fname;
00089 int res = 0;
00090
00091 for (fname = strtok(tmp, " \t"); fname; fname = strtok(NULL, " \t")) {
00092 if (read_custom_table_file(fname) < 0)
00093 res = -1;
00094 }
00095
00096 free(tmp);
00097 return res;
00098 }
00099
00100
00101
00102
00103
00104 static int
00105 read_custom_table_file(char *fname)
00106 {
00107 int lineno, res, n;
00108 FILE *fp;
00109
00110 if (!(fp = fopen(fname, "r"))) {
00111 fprintf(stderr, "Can't open config table %s for reading (%s)\n",
00112 fname, strerror(errno));
00113 return -1;
00114 }
00115
00116 lineno = 1;
00117 for (n = 0; (res = xundump(fp, fname, &lineno, EF_BAD)) >= 0; n++)
00118 empfile[res].flags |= EFF_CUSTOM;
00119 if (res != EF_BAD && n == 0)
00120 fprintf(stderr, "Warning: configuration file %s is empty\n", fname);
00121
00122 fclose(fp);
00123 return -(res == EF_BAD);
00124 }