]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/xdump.c
Update copyright notice.
[empserver] / src / lib / commands / xdump.c
index ed271d2ea0fa28cd6b287770bd2101da3e3538d4..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
@@ -37,6 +37,7 @@
 #include "match.h"
 #include "news.h"
 #include "nsc.h"
+#include "optlist.h"
 
 /*
  * Dump everything under the sun
@@ -138,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"},
@@ -240,19 +242,19 @@ struct camap {
 
 /* Table of characteristics tables */
 static struct camap chr_camap[] = {
-    {"sector chr", dchr_ca, dchr, sizeof(dchr[0])},
-    {"item", ichr_ca, ichr, sizeof(ichr[0])},
-    {"infrastructure", intrchr_ca, intrchr, sizeof(intrchr[0])},
-    {"product", pchr_ca, pchr, sizeof(pchr[0])},
-#if 0
-    /* FIXME rpt[] lacks sentinel, xdchr() doesn't terminate */
-    {"news", rpt_ca, rpt, sizeof(rpt[0])},
-#endif
-    {"treaty", tchr_ca, tchr, sizeof(tchr[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}
 };
 
@@ -269,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
@@ -291,7 +293,7 @@ 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:
@@ -302,17 +304,19 @@ 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");
@@ -329,7 +333,7 @@ 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 = "";
 
@@ -338,11 +342,12 @@ xdflds(struct castr ca[], void *ptr)
            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);
     }
 }
 
@@ -359,18 +364,24 @@ xdfldnam(struct castr ca[])
        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 header for dump NAME with fields described by CA[].  */
+/* Dump first line of header for dump NAME.  */
 static void
-xdhdr(char *name, struct castr ca[])
+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[])
+{
+    xdhdr1(name);
     xdfldnam(ca);
     pr("\n");
 }
@@ -455,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)
@@ -472,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;