]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/xdump.c
Update copyright notice.
[empserver] / src / lib / commands / xdump.c
index dd48e98d332b7f4b455f0984491f9a7111a0d867..9f35f6bc11f92742cc9aa78dee56c41df17ac6da 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -35,7 +35,9 @@
 #include "misc.h"
 #include "file.h"
 #include "match.h"
+#include "news.h"
 #include "nsc.h"
+#include "optlist.h"
 
 /*
  * Dump everything under the sun
 /* Selector descriptors for characteristics tables */
 /* FIXME belongs into src/lib/global/ */
 
+static struct castr dchr_ca[] = {
+    {NSC_STRING, 0, 0, offsetof(struct dchrstr, d_name), "name"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_mnem), "mnem"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_prd), "prd"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_mcst), "mcst"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_flg), "flg"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_pkg), "pkg"},
+    {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_ostr), "ostr"},
+    {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_dstr), "dstr"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_value), "value"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_cost), "cost"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_build), "build"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_lcms), "lcms"},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_hcms), "hcms"},
+    {NSC_NOTYPE, 0, 0, 0, NULL}
+};
+
 static struct castr ichr_ca[] = {
     {NSC_STRING, 0, 0, offsetof(struct ichrstr, i_name), "name"},
     {NSC_INT, 0, 0, offsetof(struct ichrstr, i_mnem), "mnem"},
@@ -89,6 +108,28 @@ static struct castr ichr_ca[] = {
     {NSC_NOTYPE, 0, 0, 0, NULL}
 };
 
+static struct castr intrchr_ca[] = {
+    {NSC_STRING, 0, 0, offsetof(struct sctintrins, in_name), "name"},
+    {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_lcms), "lcms"},
+    {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_hcms), "hcms"},
+    {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_dcost), "dcost"},
+    {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_mcost), "mcost"},
+    {NSC_NOTYPE, 0, 0, 0, NULL}
+};
+
+static struct castr rpt_ca[] = {
+    {NSC_STRING, 0, NUM_RPTS, offsetof(struct rptstr, r_newstory), "newstory"},
+    {NSC_INT, 0, 0, offsetof(struct rptstr, r_good_will), "good_will"},
+    {NSC_INT, 0, 0, offsetof(struct rptstr, r_newspage), "newspage"},
+    {NSC_NOTYPE, 0, 0, 0, NULL}
+};
+
+static struct castr tchr_ca[] = {
+    {NSC_STRING, 0, 0, offsetof(struct tchrstr, t_name), "name"},
+    {NSC_INT, 0, 0, offsetof(struct tchrstr, t_cond), "cond"},
+    {NSC_NOTYPE, 0, 0, 0, NULL}
+};
+
 static struct castr mchr_ca[] = {
     {NSC_STRING, 0, 0, offsetof(struct mchrstr, m_name), "name"},
     {NSC_USHORT, 0, I_MAX+1, offsetof(struct mchrstr, m_item), "item"},
@@ -98,6 +139,7 @@ static struct castr mchr_ca[] = {
     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_speed), "speed"},
     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_visib), "visib"},
     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_vrnge), "vrnge"},
+    {NSC_INT, 0, 0, offsetof(struct mchrstr, m_frnge), "frnge"},
     {NSC_INT, 0, 0, offsetof(struct mchrstr, m_glim), "glim"},
     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nxlight), "nxlight"},
     {NSC_UCHAR, 0, 0, offsetof(struct mchrstr, m_nchoppers), "nchoppers"},
@@ -200,12 +242,19 @@ struct camap {
 
 /* Table of characteristics tables */
 static struct camap chr_camap[] = {
-    {"item", ichr_ca, ichr, sizeof(ichr[0])},
-    {"product", pchr_ca, pchr, sizeof(pchr[0])},
+    {"sect chr", dchr_ca, dchr, sizeof(dchr[0])},
     {"ship chr", mchr_ca, mchr, sizeof(mchr[0])},
     {"plane chr", plchr_ca, plchr, sizeof(plchr[0])},
     {"land chr", lchr_ca, lchr, sizeof(lchr[0])},
     {"nuke chr", nchr_ca, nchr, sizeof(nchr[0])},
+#if 0
+    /* FIXME rpt[] lacks sentinel, xdchr() doesn't terminate */
+    {"news chr", rpt_ca, rpt, sizeof(rpt[0])},
+#endif
+    {"treaty chr", tchr_ca, tchr, sizeof(tchr[0])},
+    {"item", ichr_ca, ichr, sizeof(ichr[0])},
+    {"infrastructure", intrchr_ca, intrchr, sizeof(intrchr[0])},
+    {"product", pchr_ca, pchr, sizeof(pchr[0])},
     {NULL, NULL, NULL, 0}
 };
 
@@ -222,7 +271,7 @@ chridx_by_name(char *name)
 }
 
 /*
- * Evaluate a attribute of an object into VAL.
+ * Evaluate a attribute of an object into VAL, return VAL.
  * TYPE is the attribute's type.
  * PTR points to the context object.
  * The attribute is stored there at offset OFF + IDX * S, where S is
@@ -236,7 +285,7 @@ xdeval(struct valstr *val, nsc_type type, void *ptr, ptrdiff_t off, int idx)
     val->val_as_type = -1;
     val->val_as.sym.off = off;
     val->val_as.sym.idx = idx;
-    nstr_exec_val(val, player->cnum, ptr, 0);
+    nstr_exec_val(val, player->cnum, ptr, NSC_NOTYPE);
     return val;                        /* FIXME nstr_exec_val() should return VAL */
 }
 
@@ -244,9 +293,10 @@ xdeval(struct valstr *val, nsc_type type, void *ptr, ptrdiff_t off, int idx)
 static char *
 xdprval(struct valstr *val, char *sep)
 {
-    char *s, *e;
+    unsigned char *s, *e;
 
     switch (val->val_type) {
+    case NSC_TYPEID:
     case NSC_LONG:
        pr("%s%ld", sep, val->val_as.lng);
        break;
@@ -254,18 +304,23 @@ xdprval(struct valstr *val, char *sep)
        pr("%s%g", sep, val->val_as.dbl);
        break;
     case NSC_STRING:
-       pr("%s\"", sep);
-       s = val->val_as.str;
-       while (s && *s) {
-           for (e = s; *e != '"' && isprint(*e); ++e) ;
-           pr("%*s", (int)(e-s), s);
-           for (; *e && !isprint(*e); ++e) {
-               pr("\\%3o", *e);
+       s = (unsigned char *)val->val_as.str;
+       if (s) {
+           pr("%s\"", sep);
+           while (*s) {
+               for (e = s; *e != '"' && *e != '\\' && isgraph(*e); ++e) ;
+               pr("%.*s", (int)(e-s), s);
+               if (*e)
+                   pr("\\%03o", *e++);
+               s = e;
            }
-           s = e;
-       }
-       prnf("\"");
+           prnf("\"");
+       } else
+           pr("%snil", sep);
        break;
+    default:
+       CANT_HAPPEN("Bad VAL type");
+       pr("0");
     }
     return " ";
 }
@@ -278,18 +333,21 @@ xdprval(struct valstr *val, char *sep)
 static void
 xdflds(struct castr ca[], void *ptr)
 {
-    int i, j;
+    int i, j, n;
     struct valstr val;
     char *sep = "";
 
     for (i = 0; ca[i].ca_name; ++i) {
        if (ca[i].ca_flags & NSC_DEITY && !player->god)
            continue;
+       if (ca[i].ca_flags & NSC_EXTRA)
+           continue;
+       n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
        j = 0;
        do {
            xdeval(&val, ca[i].ca_type, ptr, ca[i].ca_off, j);
            sep = xdprval(&val, sep);
-       } while (++j < ca[i].ca_len);
+       } while (++j < n);
     }
 }
 
@@ -303,20 +361,27 @@ xdfldnam(struct castr ca[])
     for (i = 0; ca[i].ca_name; ++i) {
        if (ca[i].ca_flags & NSC_DEITY && !player->god)
            continue;
+       if (ca[i].ca_flags & NSC_EXTRA)
+           continue;
        pr("%s%s", sep, ca[i].ca_name);
-       if (ca[i].ca_len)
+       if (ca[i].ca_len && ca[i].ca_type != NSC_STRINGY)
            pr(" %d", ca[i].ca_len);
        sep = " ";
     }
 }
 
+/* Dump first line of header for dump NAME.  */
+static void
+xdhdr1(char *name)
+{
+    pr("XDUMP %s %ld\n", name, (long)time(NULL));
+}
+
 /* Dump header for dump NAME with fields described by CA[].  */
 static void
 xdhdr(char *name, struct castr ca[])
 {
-    prdate();
-    pr("DUMP %s %ld\n", name, (long)time(NULL));
-
+    xdhdr1(name);
     xdfldnam(ca);
     pr("\n");
 }
@@ -401,6 +466,62 @@ xdchr(int chridx)
     return RET_OK;
 }
 
+/* Dump Options[], return RET_OK.  */
+static int
+xdopt(void)
+{
+    int i;
+    char *sep;
+
+    xdhdr1("options");
+
+    sep = "";
+    for (i = 0; Options[i].opt_key; ++i) {
+       pr("%s%s", sep, Options[i].opt_key);
+       sep = " ";
+    }
+    pr("\n");
+    
+    sep = "";
+    for (i = 0; Options[i].opt_key; ++i) {
+       pr("%s%d", sep, *Options[i].opt_valuep);
+       sep = " ";
+    }
+    pr("\n");
+
+    return RET_OK;
+}
+
+static int
+xdver(void)
+{
+    struct keymatch *kp;
+    char *sep;
+    struct valstr val;
+
+    xdhdr1("version");
+
+    sep = "";
+    for (kp = configkeys; kp->km_key; ++kp) {
+       if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
+           pr("%s%s", sep, kp->km_key);
+           sep = " ";
+       }
+    }
+    pr("\n");
+    
+    sep = "";
+    for (kp = configkeys; kp->km_key; ++kp) {
+       if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
+           xdeval(&val, kp->km_type, kp->km_data, 0, 0);
+           sep = xdprval(&val, sep);
+       }
+    }
+    pr("\n");
+
+    return RET_OK;
+}
+
 /* Experimental extended dump command */
 int
 xdump(void)
@@ -418,6 +539,10 @@ xdump(void)
        return xditem(type, player->argp[2]);
     } else if (!strncmp(p, "chr", strlen(p)) && player->argp[2]) {
        return xdchr(chridx_by_name(player->argp[2]));
+    } else if (!strncmp(p, "opt", strlen(p))) {
+       return xdopt();
+    } else if (!strncmp(p, "ver", strlen(p))) {
+       return xdver();
     }
 
     return RET_SYN;