/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
*
* Known contributors to this file:
* Ron Koenderink, 2005
- * Markus Armbruster, 2005-2014
+ * Markus Armbruster, 2005-2016
*/
/*
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include "file.h"
#include "match.h"
#include "nat.h"
#include "nsc.h"
{
struct castr *ca = ef_cadef(type);
- return ca[0].ca_table == type && !(ca[0].ca_flags & NSC_EXTRA);
+ return ca[0].ca_table == type && ca[0].ca_dump <= CA_DUMP_CONST;
}
/*
}
/*
- * Is table @type's @id-th record @obj redundant for xundump()
+ * Is table @type's @id-th record @obj redundant for xundump()?
*/
int
xundump_redundant(int type, int id, void *obj)
return -1;
}
-/* Make TYPE the current table. */
+/* Make TYPE the current table. */
static void
tbl_start(int type)
{
idgap_len = 0;
}
-/* End the current table. */
+/* End the current table. */
static void
tbl_end(void)
{
/*
* Seek to current table's @id-th object.
* Extend the table if necessary.
- * Save @id in cur_id.
+ * Save @id in @cur_id.
* Return the object on success, NULL on failure.
*/
static void *
/*
* Get the current row's object.
* Extend the table if necessary.
- * Save ID in cur_id.
+ * Save ID in @cur_id.
* Return the object on success, NULL on failure.
*/
static void *
* it's for a const selector, unless the object is still blank, or
* it was already given in a previous part of a split table.
*/
- return (cur_id < old_nelem && (fldca[fldno]->ca_flags & NSC_CONST))
+ return (cur_id < old_nelem && (fldca[fldno]->ca_dump == CA_DUMP_CONST))
|| fldidx[fldno] < cafldspp[i];
}
return gripe("%s header '%s' in field %d",
res == M_NOTUNIQUE ? "ambiguous" : "unknown",
name, fldno + 1);
- if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
+ if (ca[res].ca_dump > CA_DUMP_CONST || CANT_HAPPEN(ca[res].ca_get))
return gripe("extraneous header '%s' in field %d", name, fldno + 1);
if (CA_IS_ARRAY(&ca[res])) {
if (idx < 0)
/* Check for missing fields */
for (i = 0; ca[i].ca_name; i++) {
cafldsmax = MAX(caflds[i], cafldspp[i]);
- if (ca[i].ca_flags & NSC_EXTRA)
+ if (ca[i].ca_dump > CA_DUMP_CONST)
continue;
len = CA_ARRAY_LEN(&ca[i]);
if (!len && !cafldsmax)
return gripe("expected table '%s', not '%s'",
ef_nameof(expected_table), name);
- if (!empfile[type].file
- || !ef_cadef(type) || !(ef_flags(type) & EFF_MEM)) {
+ if (!xundumpable(type)) {
CANT_HAPPEN(expected_table != EF_BAD);
return gripe("table '%s' is not permitted here", name);
}
return type;
}
+/*
+ * Can table @type be xundumped?
+ */
+int
+xundumpable(int type)
+{
+ return empfile[type].file && ef_cadef(type)
+ && (ef_flags(type) & EFF_MEM);
+}
+
/*
* Find fields in this xdump.
* If reading human-readable syntax, read a field header line from @fp.
fidx = fldidx;
for (i = 0; ca[i].ca_name; i++) {
- if ((ca[i].ca_flags & NSC_EXTRA))
+ if (ca[i].ca_dump > CA_DUMP_CONST)
continue;
n = CA_ARRAY_LEN(&ca[i]);
j = 0;
nca = nf = 0;
for (i = 0; ca[i].ca_name; i++) {
nca++;
- if (!(ca[i].ca_flags & NSC_EXTRA))
+ if (ca[i].ca_dump <= CA_DUMP_CONST)
nf += MAX(1, CA_ARRAY_LEN(&ca[i]));
}
fldca = malloc(nf * sizeof(*fldca));