2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * ef_verify.c: Verify game configuration
30 * Known contributors to this file:
31 * Ron Koenderink, 2005
39 #include "prototypes.h"
43 static void verify_fail(int, int, struct castr *, char *, ...)
44 ATTRIBUTE((format (printf, 4, 5)));
47 verify_fail(int type, int row, struct castr *ca, char *fmt, ...)
52 /* Find base table of view, if any */
53 for (i = 0; empfile[i].cache == empfile[type].cache; i++) ;
55 fprintf(stderr, "%s %s uid %d field %s: ",
56 EF_IS_GAME_STATE(i) ? "File" : "Config",
57 ef_nameof(type), row, ca->ca_name);
59 vfprintf(stderr, fmt, ap);
65 verify_row(int type, int row)
67 struct castr *ca = ef_cadef(type);
73 int in_mem = (ef_flags(type) & EFF_MEM) != 0;
76 row_ref = ef_ptr(type, row);
78 row_ref = malloc(empfile[type].size);
79 ef_read(type, row, row_ref);
82 for (i = 0; ca[i].ca_name; ++i) {
83 if (ca[i].ca_flags & NSC_EXTRA)
85 n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
88 if (ca[i].ca_table == EF_BAD)
90 /* FIXME use xdeval() */
91 val.val_type = ca[i].ca_type;
92 val.val_cat = NSC_OFF;
93 val.val_as.sym.off = ca[i].ca_off;
94 val.val_as.sym.len = ca[i].ca_len;
95 val.val_as.sym.idx = j;
96 nstr_exec_val(&val, 0, row_ref, NSC_NOTYPE);
97 if (val.val_type != NSC_LONG && val.val_type != NSC_TYPEID)
99 ca_sym = ef_cadef(ca[i].ca_table);
100 if (ca[i].ca_flags & NSC_BITS) {
102 if (CANT_HAPPEN(ca_sym != symbol_ca)) {
106 for (k = 0; k < (int)sizeof(long) * 8; k++) {
107 if (val.val_as.lng & (1L << k))
108 if (!symbol_by_value(1L << k,
109 ef_ptr(ca[i].ca_table, 0))) {
110 verify_fail(type, row, &ca[i],
111 "bit %d is not in symbol table %s",
112 k, ef_nameof(ca[i].ca_table));
116 } else if (ca[i].ca_table == type && i == 0) {
118 if (val.val_as.lng != row) {
119 verify_fail(type, row, &ca[i],
120 "value is %ld instead of %d",
121 val.val_as.lng, row);
125 } else if (ca_sym == symbol_ca) {
127 if (!symbol_by_value(val.val_as.lng,
128 ef_ptr(ca[i].ca_table, 0))) {
129 verify_fail(type, row, &ca[i],
130 "value %ld is not in symbol table %s",
131 val.val_as.lng, ef_nameof(ca[i].ca_table));
136 if (val.val_as.lng >= ef_nelem(ca[i].ca_table)
137 || val.val_as.lng < -1) {
138 verify_fail(type, row, &ca[i],
139 "value %ld indexes table %s out of bounds 0..%d",
140 val.val_as.lng, ef_nameof(ca[i].ca_table),
141 ef_nelem(ca[i].ca_table));
159 for (ep = empfile; ep->name; ep++) {
160 if (!ef_cadef(ep->uid))
162 for (i = 0; i < ef_nelem(ep->uid); i++) {
163 retval += verify_row(ep->uid, i);