2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * xdump.c: Experimental extended dump
30 * Known contributors to this file:
31 * Markus Armbruster, 2004
44 * Dump everything under the sun
46 * Static game data (configuration):
47 * - Item characteristics: ichr[]
48 * - Land unit characteristics: lchr[]
49 * - Nuke characteristics: nchr[]
50 * - Plane characteristics: plchr[]
51 * - Product characteristics: pchr[]
52 * - Sector designation characteristics: dchr[]
53 * - Sector infrastructure characteristics: intrchr[]
54 * - Ship characteristics: mchr[]
56 * - News item characteristics: rpt[]
57 * - News page headings: page_headings[] (TODO)
58 * - Commands: player_coms[] (TODO)
59 * - Options: Options[]
60 * - Configuration: configkeys[]
63 * - Sectors: EF_SECTOR, sect_ca[] (already have dump)
64 * - Land units: EF_LAND, land_ca[] (already have ldump)
65 * - Lost: EF_LOST, lost_ca[] (already have lost)
66 * - Nukes: EF_NUKE, nuke_ca[] (already have ndump)
67 * - Planes: EF_PLANE, plane_ca[] (already have pdump)
68 * - Ships: EF_SHIP, ship_ca[] (already have sdump)
69 * - News: EF_NEWS, news_ca[]
70 * - Treaties: EF_TREATY, treaty_ca[]
72 * - Nations: EF_NATION, nat_ca[]
73 * - Loans: EF_LOAN, loan_ca[]
74 * - Map: EF_MAP (TODO)
75 * - Bmap: EF_BMAP (TODO)
76 * - Market: EF_COMM, commodity_ca[]
79 /* FIXME document dump format */
80 /* FIXME don't dump stuff that's useless due to options */
83 * Evaluate a attribute of an object into VAL, return VAL.
84 * TYPE is the attribute's type.
85 * PTR points to the context object.
86 * The attribute is stored there at offset OFF + IDX * S, where S is
89 static struct valstr *
90 xdeval(struct valstr *val, nsc_type type, void *ptr, ptrdiff_t off, int idx)
93 val->val_cat = NSC_OFF;
94 val->val_as.sym.off = off;
95 val->val_as.sym.idx = idx;
96 nstr_exec_val(val, player->cnum, ptr, NSC_NOTYPE);
97 return val; /* FIXME nstr_exec_val() should return VAL */
100 /* Dump VAL prefixed with SEP, return " ". */
102 xdprval(struct valstr *val, char *sep)
104 unsigned char *s, *e, *l;
106 switch (val->val_type) {
109 pr("%s%ld", sep, val->val_as.lng);
112 pr("%s%#g", sep, val->val_as.dbl);
115 s = (unsigned char *)val->val_as.str.base;
118 l = s + val->val_as.str.maxsz;
119 /* FIXME maxsz == INT_MAX ! */
121 for (e=s; e<l && *e != '"' && *e != '\\' && isgraph(*e); ++e) ;
122 pr("%.*s", (int)(e-s), s);
134 CANT_HAPPEN("Bad VAL type");
141 * Dump field values of a context object.
142 * CA[] describes fields.
143 * PTR points to context object.
146 xdflds(struct castr ca[], void *ptr)
152 for (i = 0; ca[i].ca_name; ++i) {
153 if (ca[i].ca_flags & NSC_DEITY && !player->god)
155 if (ca[i].ca_flags & NSC_EXTRA)
157 n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
160 xdeval(&val, ca[i].ca_type, ptr, ca[i].ca_off, j);
161 sep = xdprval(&val, sep);
166 /* Dump first line of header for dump NAME. */
168 xdhdr(char *name, int meta)
170 pr("XDUMP %s%s %ld\n", meta ? "meta " : "", name, (long)time(NULL));
173 /* Dump footer for a dump that dumped N objects. */
181 * Dump items of type TYPE selected by ARG.
182 * Return RET_OK on success, RET_SYN on error.
185 xditem(int type, char *arg)
187 int check_owner = !player->god && (ef_flags(type) & EFF_OWNER) != 0;
191 char buf[2048]; /* FIXME buffer size? */
197 if (!snxtitem(&ni, type, arg))
200 xdhdr(ef_nameof(type), 0);
203 while (nxtitem(&ni, buf)) {
204 if (check_owner && ((struct genitem *)buf)->own != player->cnum)
217 * Dump meta-data for items of type TYPE.
223 struct castr *ca = ef_cadef(type);
230 xdhdr(ef_nameof(type), 1);
232 for (i = 0; ca[i].ca_name; i++) {
233 if (ca[i].ca_flags & NSC_DEITY && !player->god)
235 if (ca[i].ca_flags & NSC_EXTRA)
237 xdflds(mdchr_ca, &ca[i]);
247 /* Dump Options[], return RET_OK. */
257 for (i = 0; Options[i].opt_key; ++i) {
258 ca.ca_type = NSC_INT;
262 ca.ca_name = Options[i].opt_key;
263 ca.ca_table = EF_BAD;
264 xdflds(mdchr_ca, &ca);
274 for (i = 0; Options[i].opt_key; ++i) {
275 pr("%s%d", sep, *Options[i].opt_valuep);
297 for (kp = configkeys; kp->km_key; ++kp) {
298 if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
299 ca.ca_type = kp->km_type;
303 ca.ca_name = kp->km_key;
304 ca.ca_table = EF_BAD;
305 xdflds(mdchr_ca, &ca);
317 for (kp = configkeys; kp->km_key; ++kp) {
318 if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
319 xdeval(&val, kp->km_type, kp->km_data, 0, 0);
320 sep = xdprval(&val, sep);
330 /* Experimental extended dump command */
339 if (!opt_GUINEA_PIGS) {
340 pr("You are not a guinea pig!\n");
344 p = getstarg(player->argp[1], "What? ", buf);
345 if (p && strcmp(p, "meta") == 0) {
347 p = getstarg(player->argp[2], "What? ", buf);
357 return xditem(type, player->argp[2]);
358 } else if (!strncmp(p, "opt", strlen(p))) {
360 } else if (!strncmp(p, "ver", strlen(p))) {