]> git.pond.sub.org Git - empserver/blob - src/lib/commands/xdump.c
(keymatch): Replace member km_func by km_type. Initializers adapted.
[empserver] / src / lib / commands / xdump.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  xdump.c: Experimental extended dump
29  * 
30  *  Known contributors to this file:
31  *     Markus Armbruster, 2004
32  */
33
34 #include <stddef.h>
35 #include "misc.h"
36 #include "file.h"
37 #include "match.h"
38 #include "news.h"
39 #include "nsc.h"
40 #include "optlist.h"
41
42 /*
43  * Dump everything under the sun
44  *
45  * Static game data (configuration):
46  * - Item characteristics: ichr[]
47  * - Land unit characteristics: lchr[]
48  * - Nuke characteristics: nchr[]
49  * - Plane characteristics: plchr[]
50  * - Product characteristics: pchr[]
51  * - Sector designation characteristics: dchr[]
52  * - Sector infrastructure characteristics: intrchr[]
53  * - Ship characteristics: mchr[]
54  * Less important:
55  * - News item characteristics: rpt[]
56  * - Treaty clause characteristics: tchr[]
57  * - Commands: coms[]
58  * - Options: Options[]
59  * - Configuration: configkeys[]
60  *
61  * Dynamic game data:
62  * - Sectors: EF_SECTOR, sect_ca[] (already have dump)
63  * - Land units: EF_LAND, land_ca[] (already have ldump)
64  * - Lost: EF_LOST, lost_ca[] (already have lost)
65  * - Nukes: EF_NUKE, nuke_ca[] (already have ndump)
66  * - Planes: EF_PLANE, plane_ca[] (already have pdump)
67  * - Ships: EF_SHIP, ship_ca[] (already have sdump)
68  * - News: EF_NEWS, news_ca[]
69  * - Treaties: EF_TREATY, treaty_ca[]
70  * - Power: EF_POWER
71  * - Nations: EF_NATION, nat_ca[]
72  * - Loans: EF_LOAN, loan_ca[]
73  * - Map: EF_MAP
74  * - Bmap: EF_BMAP
75  * - Market: EF_COMM, commodity_ca[]
76  */
77
78 /* FIXME document dump format */
79
80 /* Selector descriptors for characteristics tables */
81 /* FIXME belongs into src/lib/global/ */
82
83 static struct castr dchr_ca[] = {
84     {NSC_STRING, 0, 0, offsetof(struct dchrstr, d_name), "name"},
85     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_mnem), "mnem"},
86     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_prd), "prd"},
87     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_mcst), "mcst"},
88     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_flg), "flg"},
89     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_pkg), "pkg"},
90     {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_ostr), "ostr"},
91     {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_dstr), "dstr"},
92     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_value), "value"},
93     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_cost), "cost"},
94     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_build), "build"},
95     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_lcms), "lcms"},
96     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_hcms), "hcms"},
97     {NSC_NOTYPE, 0, 0, 0, NULL}
98 };
99
100 static struct castr ichr_ca[] = {
101     {NSC_STRING, 0, 0, offsetof(struct ichrstr, i_name), "name"},
102     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_mnem), "mnem"},
103     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_vtype), "vtype"},
104     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_value), "value"},
105     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_sell), "sell"},
106     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_lbs), "lbs"},
107     {NSC_INT, 0, NUMPKG, offsetof(struct ichrstr, i_pkg), "pkg"},
108     {NSC_NOTYPE, 0, 0, 0, NULL}
109 };
110
111 static struct castr intrchr_ca[] = {
112     {NSC_STRING, 0, 0, offsetof(struct sctintrins, in_name), "name"},
113     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_lcms), "lcms"},
114     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_hcms), "hcms"},
115     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_dcost), "dcost"},
116     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_mcost), "mcost"},
117     {NSC_NOTYPE, 0, 0, 0, NULL}
118 };
119
120 static struct castr rpt_ca[] = {
121     {NSC_STRING, 0, NUM_RPTS, offsetof(struct rptstr, r_newstory), "newstory"},
122     {NSC_INT, 0, 0, offsetof(struct rptstr, r_good_will), "good_will"},
123     {NSC_INT, 0, 0, offsetof(struct rptstr, r_newspage), "newspage"},
124     {NSC_NOTYPE, 0, 0, 0, NULL}
125 };
126
127 static struct castr tchr_ca[] = {
128     {NSC_STRING, 0, 0, offsetof(struct tchrstr, t_name), "name"},
129     {NSC_INT, 0, 0, offsetof(struct tchrstr, t_cond), "cond"},
130     {NSC_NOTYPE, 0, 0, 0, NULL}
131 };
132
133 static struct castr mchr_ca[] = {
134     {NSC_STRING, 0, 0, offsetof(struct mchrstr, m_name), "name"},
135     {NSC_USHORT, 0, I_MAX+1, offsetof(struct mchrstr, m_item), "item"},
136     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_lcm), "lcm"},
137     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_hcm), "hcm"},
138     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_armor), "armor"},
139     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_speed), "speed"},
140     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_visib), "visib"},
141     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_vrnge), "vrnge"},
142     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_glim), "glim"},
143     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nxlight), "nxlight"},
144     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nchoppers), "nchoppers"},
145     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_fuelc), "fuelc"},
146     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_fuelu), "fuelu"},
147     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_tech), "tech"},
148     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_cost), "cost"},
149     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_flags), "flags"},
150     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nplanes), "nplanes"},
151     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nland), "nland"},
152     {NSC_NOTYPE, 0, 0, 0, NULL}
153 };
154
155 static struct castr pchr_ca[] = {
156     {NSC_STRING, 0, 0, offsetof(struct pchrstr, p_name), "name"},
157     {NSC_STRING, 0, 0, offsetof(struct pchrstr, p_sname), "sname"},
158     {NSC_UCHAR, 0, MAXPRCON, offsetof(struct pchrstr, p_ctype), "ctype"},
159     {NSC_USHORT, 0, MAXPRCON, offsetof(struct pchrstr, p_camt), "camt"},
160     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_type), "type"},
161     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_level), "level"},
162     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_cost), "cost"},
163     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nrndx), "nrndx"},
164     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nrdep), "nrdep"},
165     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nlndx), "nlndx"},
166     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nlmin), "nlmin"},
167     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nllag), "nllag"},
168     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_effic), "effic"},
169     {NSC_NOTYPE, 0, 0, 0, NULL}
170 };
171
172 static struct castr plchr_ca[] = {
173     {NSC_STRING, 0, 0, offsetof(struct plchrstr, pl_name), "name"},
174     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_lcm), "lcm"},
175     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_hcm), "hcm"},
176     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_cost), "cost"},
177     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_tech), "tech"},
178     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_acc), "acc"},
179     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_load), "load"},
180     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_att), "att"},
181     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_def), "def"},
182     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_range), "range"},
183     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_crew), "crew"},
184     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_fuel), "fuel"},
185     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_stealth), "stealth"},
186     {NSC_INT, 0, 0, offsetof(struct plchrstr, pl_flags), "flags"},
187     {NSC_NOTYPE, 0, 0, 0, NULL}
188 };
189
190 static struct castr lchr_ca[] = {
191     {NSC_STRING, 0, 0, offsetof(struct lchrstr, l_name), "name"},
192     {NSC_USHORT, 0, I_MAX+1, offsetof(struct mchrstr, m_item), "item"},
193     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_lcm), "lcm"},
194     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_hcm), "hcm"},
195     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_gun), "gun"},
196     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_shell), "shell"},
197     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_tech), "tech"},
198     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_cost), "cost"},
199     {NSC_FLOAT, 0, 0, offsetof(struct lchrstr, l_att), "att"},
200     {NSC_FLOAT, 0, 0, offsetof(struct lchrstr, l_def), "def"},
201     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_vul), "vul"},
202     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_spd), "spd"},
203     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_vis), "vis"},
204     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_spy), "spy"},
205     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_rad), "rad"},
206     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_frg), "frg"},
207     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_acc), "acc"},
208     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_dam), "dam"},
209     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_ammo), "ammo"},
210     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_aaf), "aaf"},
211     {NSC_UCHAR, 0, 0, offsetof(struct lchrstr, l_fuelc), "fuelc"},
212     {NSC_UCHAR, 0, 0, offsetof(struct lchrstr, l_fuelu), "fuelu"},
213     {NSC_UCHAR, 0, 0, offsetof(struct lchrstr, l_nxlight), "nxlight"},
214     {NSC_UCHAR, 0, 0, offsetof(struct lchrstr, l_mxland), "mxland"},
215     {NSC_INT, 0, 0, offsetof(struct lchrstr, l_flags), "flags"},
216     {NSC_NOTYPE, 0, 0, 0, NULL}
217 };
218
219 static struct castr nchr_ca[] = {
220     {NSC_STRING, 0, 0, offsetof(struct nchrstr, n_name), "name"},
221     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_lcm), "lcm"},
222     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_hcm), "hcm"},
223     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_oil), "oil"},
224     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_rad), "rad"},
225     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_blast), "blast"},
226     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_dam), "dam"},
227     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_cost), "cost"},
228     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_tech), "tech"},
229     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_weight), "weight"},
230     {NSC_INT, 0, 0, offsetof(struct nchrstr, n_flags), "flags"},
231     {NSC_NOTYPE, 0, 0, 0, NULL}
232 };
233
234 /* Characteristics table meta data */
235 struct camap {
236     char *name;                 /* name for lookup */
237     struct castr *ca;           /* selector descriptors */
238     void *chr;                  /* characteristics table */
239     size_t size;                /* size of characteristics table element */
240 };
241
242 /* Table of characteristics tables */
243 static struct camap chr_camap[] = {
244     {"sect chr", dchr_ca, dchr, sizeof(dchr[0])},
245     {"ship chr", mchr_ca, mchr, sizeof(mchr[0])},
246     {"plane chr", plchr_ca, plchr, sizeof(plchr[0])},
247     {"land chr", lchr_ca, lchr, sizeof(lchr[0])},
248     {"nuke chr", nchr_ca, nchr, sizeof(nchr[0])},
249 #if 0
250     /* FIXME rpt[] lacks sentinel, xdchr() doesn't terminate */
251     {"news chr", rpt_ca, rpt, sizeof(rpt[0])},
252 #endif
253     {"treaty chr", tchr_ca, tchr, sizeof(tchr[0])},
254     {"item", ichr_ca, ichr, sizeof(ichr[0])},
255     {"infrastructure", intrchr_ca, intrchr, sizeof(intrchr[0])},
256     {"product", pchr_ca, pchr, sizeof(pchr[0])},
257     {NULL, NULL, NULL, 0}
258 };
259
260 /*
261  * Search chr_camap[] for element named NAME, return its index.
262  * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
263  * several.
264  */
265 static int
266 chridx_by_name(char *name)
267 {
268     return stmtch(name, chr_camap, offsetof(struct camap, name),
269                   sizeof(chr_camap[0]));
270 }
271
272 /*
273  * Evaluate a attribute of an object into VAL.
274  * TYPE is the attribute's type.
275  * PTR points to the context object.
276  * The attribute is stored there at offset OFF + IDX * S, where S is
277  * its size.
278  */
279 static struct valstr *
280 xdeval(struct valstr *val, nsc_type type, void *ptr, ptrdiff_t off, int idx)
281 {
282     val->val_type = type;
283     val->val_cat = NSC_OFF;
284     val->val_as_type = -1;
285     val->val_as.sym.off = off;
286     val->val_as.sym.idx = idx;
287     nstr_exec_val(val, player->cnum, ptr, NSC_NOTYPE);
288     return val;                 /* FIXME nstr_exec_val() should return VAL */
289 }
290
291 /* Dump VAL prefixed with SEP, return " ".  */
292 static char *
293 xdprval(struct valstr *val, char *sep)
294 {
295     char *s, *e;
296
297     switch (val->val_type) {
298     case NSC_TYPEID:
299     case NSC_LONG:
300         pr("%s%ld", sep, val->val_as.lng);
301         break;
302     case NSC_DOUBLE:
303         pr("%s%g", sep, val->val_as.dbl);
304         break;
305     case NSC_STRING:
306         s = val->val_as.str;
307         if (s) {
308             pr("%s\"", sep);
309             while (*s) {
310                 for (e = s; *e != '"' && *e != '\\' && isprint(*e); ++e) ;
311                 pr("%.*s", (int)(e-s), s);
312                 if (*e)
313                     pr("\\%03o", *e++);
314                 s = e;
315             }
316             prnf("\"");
317         } else
318             pr("%snil", sep);
319         break;
320     default:
321         CANT_HAPPEN("Bad VAL type");
322         pr("0");
323     }
324     return " ";
325 }
326
327 /*
328  * Dump field values of a context object.
329  * CA[] describes fields.
330  * PTR points to context object.
331  */
332 static void
333 xdflds(struct castr ca[], void *ptr)
334 {
335     int i, j, n;
336     struct valstr val;
337     char *sep = "";
338
339     for (i = 0; ca[i].ca_name; ++i) {
340         if (ca[i].ca_flags & NSC_DEITY && !player->god)
341             continue;
342         if (ca[i].ca_flags & NSC_EXTRA)
343             continue;
344         n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
345         j = 0;
346         do {
347             xdeval(&val, ca[i].ca_type, ptr, ca[i].ca_off, j);
348             sep = xdprval(&val, sep);
349         } while (++j < n);
350     }
351 }
352
353 /* Dump field names; CA[] describes fields.  */
354 static void
355 xdfldnam(struct castr ca[])
356 {
357     int i;
358     char *sep = "";
359
360     for (i = 0; ca[i].ca_name; ++i) {
361         if (ca[i].ca_flags & NSC_DEITY && !player->god)
362             continue;
363         if (ca[i].ca_flags & NSC_EXTRA)
364             continue;
365         pr("%s%s", sep, ca[i].ca_name);
366         if (ca[i].ca_len && ca[i].ca_type != NSC_STRINGY)
367             pr(" %d", ca[i].ca_len);
368         sep = " ";
369     }
370 }
371
372 /* Dump first line of header for dump NAME.  */
373 static void
374 xdhdr1(char *name)
375 {
376     pr("XDUMP %s %ld\n", name, (long)time(NULL));
377 }
378
379 /* Dump header for dump NAME with fields described by CA[].  */
380 static void
381 xdhdr(char *name, struct castr ca[])
382 {
383     xdhdr1(name);
384     xdfldnam(ca);
385     pr("\n");
386 }
387
388 /* Dump footer for a dump that dumped N objects.  */
389 static void
390 xdftr(int n)
391 {
392     pr("dumped %d\n", n);
393 }
394
395 /*
396  * Dump items of type TYPE selected by ARG.
397  * Return RET_OK on success, RET_SYN on error.
398  */
399 static int
400 xditem(int type, char *arg)
401 {
402     struct castr *ca;
403     struct nstr_item ni;
404     int n;
405     s_char buf[2048];           /* FIXME buffer size? */
406
407     ca = ef_cadef(type);
408     if (!ca)
409         return RET_SYN;
410
411     if (!snxtitem(&ni, type, arg))
412         return RET_SYN;
413
414     xdhdr(ef_nameof(type), ca);
415
416     n = 0;
417     while (nxtitem(&ni, buf)) {
418         if (!player->owner)
419             continue;
420         ++n;
421         xdflds(ca, buf);
422         pr("\n");
423     }
424
425     xdftr(n);
426
427     return RET_OK;
428 }
429
430 /*
431  * Dump characteristics described by chr_camap[IDX].
432  * Return RET_OK on success, RET_SYN if IDX < 0.
433  */
434 static int
435 xdchr(int chridx)
436 {
437     struct camap *cm;
438     char *p;
439     struct valstr val;
440     int n;
441
442     if (chridx < 0)
443         return RET_SYN;
444     cm = &chr_camap[chridx];
445
446     xdhdr(cm->name, cm->ca);
447
448     n = 0;
449     for (p = cm->chr; ; p += cm->size) {
450         val.val_type = cm->ca[0].ca_type;
451         val.val_cat = NSC_OFF;
452         val.val_as_type = -1;
453         val.val_as.sym.off = cm->ca[0].ca_off;
454         val.val_as.sym.idx = 0;
455         nstr_exec_val(&val, player->cnum, p, NSC_STRING);
456         if (!val.val_as.str || !*val.val_as.str)
457             break;
458         ++n;
459         xdflds(cm->ca, p);
460         pr("\n");
461     }
462
463     xdftr(n);
464
465     return RET_OK;
466 }
467
468 /* Dump Options[], return RET_OK.  */
469 static int
470 xdopt(void)
471 {
472     int i;
473     char *sep;
474
475     xdhdr1("options");
476
477     sep = "";
478     for (i = 0; Options[i].opt_key; ++i) {
479         pr("%s%s", sep, Options[i].opt_key);
480         sep = " ";
481     }
482     pr("\n");
483     
484     sep = "";
485     for (i = 0; Options[i].opt_key; ++i) {
486         pr("%s%d", sep, *Options[i].opt_valuep);
487         sep = " ";
488     }
489     pr("\n");
490
491     return RET_OK;
492 }
493
494 static int
495 xdver(void)
496 {
497     struct keymatch *kp;
498     char *sep;
499     struct valstr val;
500
501     xdhdr1("version");
502
503     sep = "";
504     for (kp = configkeys; kp->km_key; ++kp) {
505         if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
506             pr("%s%s", sep, kp->km_key);
507             sep = " ";
508         }
509     }
510     pr("\n");
511     
512     sep = "";
513     for (kp = configkeys; kp->km_key; ++kp) {
514         if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
515             xdeval(&val, kp->km_type, kp->km_data, 0, 0);
516             sep = xdprval(&val, sep);
517         }
518     }
519     pr("\n");
520
521     return RET_OK;
522 }
523
524 /* Experimental extended dump command */
525 int
526 xdump(void)
527 {
528     s_char *p;
529     char buf[1024];
530     int type;
531
532     p = getstarg(player->argp[1], "What? ", buf);
533     if (!p)
534         return RET_SYN;
535
536     type = ef_byname(p);
537     if (type >= 0) {
538         return xditem(type, player->argp[2]);
539     } else if (!strncmp(p, "chr", strlen(p)) && player->argp[2]) {
540         return xdchr(chridx_by_name(player->argp[2]));
541     } else if (!strncmp(p, "opt", strlen(p))) {
542         return xdopt();
543     } else if (!strncmp(p, "ver", strlen(p))) {
544         return xdver();
545     }
546
547     return RET_SYN;
548 }