xdump: Make meta-type numbers portable, get rid of meta-type "c"

The xdump field data types are abstract symbols "d", "f", "s" and "c".
However, the abstraction leaks: we dump the enum nsc_type ca_type
values verbatim in meta table field "type", and have symbol table
meta-type map all integer types to "d", and both floating-point types
to "f".  Not a problem for well-behaved clients, since all they do
with the dumped value is referencing table meta-type.  It is a problem
for version-test: since the integer type compatible with an
enumeration type is implementation-defined, the type value of
selectors of enumeration type can vary between compilers.  It also
makes table meta-type a somewhat ugly exception to the rule that a
symbol table maps integers to names 1:1.

Virtual selectors let us seal the abstraction: dump the promoted
ca_type value.

The integer types get all promoted to NSC_LONG.  This takes care of
version-test.

The floating-point types get all promoted to NSC_DOUBLE.  Makes sense.

NSC_STRINGY gets promoted to NSC_STRING.  This changes all field data
types "c" to "s".  Getting rid of "c" is a welcome simplification,
because now the meaning of meta type field "len" no longer depends on
"type", but always means that the array is dumped as that many fields.
We lose string length limit information, though.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-26 08:00:20 +02:00
parent 6e9f256c68
commit 89a06ec2d4
5 changed files with 671 additions and 696 deletions

View file

@ -253,7 +253,7 @@ of xdump meta T are:
- "d", field uses intnum syntax - "d", field uses intnum syntax
- "g", field uses flonum syntax - "g", field uses flonum syntax
- "s", field uses string syntax - "s", field uses string syntax
- "c", field uses string syntax - "c", field uses string syntax (only until version 4.3.33)
* flags: The field's flags, a symbol set. Flags are: * flags: The field's flags, a symbol set. Flags are:
- "deity", field visible only to deities - "deity", field visible only to deities
@ -263,9 +263,10 @@ of xdump meta T are:
enabled. Masked values are replaced by -1. enabled. Masked values are replaced by -1.
* len: If non-zero, then the record encodes an array with that many * len: If non-zero, then the record encodes an array with that many
elements. If field type encodes symbol "c", it is a character elements. The array is dumped as len fields.
array, which is dumped as a single string field. Else, the array is
dumped as len fields. Only until version 4.3.33: if field type encodes symbol "c", it is a
character array, and is dumped as a single string field.
* table: Key for xdump table. Unless -1, it defines the table * table: Key for xdump table. Unless -1, it defines the table
referenced by the field value. Field type must encode symbol "d" referenced by the field value. Field type must encode symbol "d"
@ -312,12 +313,12 @@ its meta-data, and to make sense of that table, we need meta-meta
data. So we start with that: data. So we start with that:
[3:640] Command : xdump meta meta [3:640] Command : xdump meta meta
XDUMP meta meta 1464554085 XDUMP meta meta 1466920477
"name" 3 0 0 -1 "name" 3 0 0 -1
"type" 8 0 0 33 "type" 1 0 0 33
"flags" 8 8 0 32 "flags" 1 8 0 32
"len" 7 0 0 -1 "len" 1 0 0 -1
"table" 8 0 0 26 "table" 1 0 0 26
/5 /5
To interpret this table, we have to know the field names and their To interpret this table, we have to know the field names and their
@ -341,8 +342,8 @@ know, namely the table of tables. Let's dump that next, starting with
its meta-data: its meta-data:
[3:640] Command : xdump meta table [3:640] Command : xdump meta table
XDUMP meta table 1464554085 XDUMP meta table 1466920477
"uid" 8 0 0 26 "uid" 1 0 0 26
"name" 3 0 0 -1 "name" 3 0 0 -1
/2 /2
@ -353,7 +354,7 @@ table itself. Indeed, its value matches the one we got in xdump meta
meta. Let's try to dump the table: meta. Let's try to dump the table:
[5:640] Command : xdump 26 * [5:640] Command : xdump 26 *
XDUMP table 1464554085 XDUMP table 1466920477
0 "sect" 0 "sect"
1 "ship" 1 "ship"
[...] [...]
@ -364,7 +365,7 @@ meta. Let's try to dump the table:
[...] [...]
26 "table" 26 "table"
[...] [...]
/47 /48
It worked! It worked!
@ -372,37 +373,26 @@ Now dump the two symbol tables we postponed. Because xdump accepts
table IDs as well as names, we don't have to know their names: table IDs as well as names, we don't have to know their names:
[5:640] Command : xdump meta 33 [5:640] Command : xdump meta 33
xdump meta 33 XDUMP meta meta-type 1466920477
XDUMP meta meta-type 1464554085 "value" 1 0 0 -1
"value" 8 0 0 -1
"name" 3 0 0 -1 "name" 3 0 0 -1
/2 /2
[6:640] Command : xdump 33 * [6:640] Command : xdump 33 *
XDUMP meta-type 1464554085 XDUMP meta-type 1466920477
1 "d" 1 "d"
2 "g" 2 "g"
3 "s" 3 "s"
4 "d" /3
5 "d"
6 "d"
7 "d"
8 "d"
9 "d"
10 "d"
11 "d"
12 "g"
13 "c"
/13
[7:640] Command : xdump meta 32 [7:640] Command : xdump meta 32
XDUMP meta meta-flags 1464554085 XDUMP meta meta-flags 1466920477
"value" 8 0 0 -1 "value" 1 0 0 -1
"name" 3 0 0 -1 "name" 3 0 0 -1
/2 /2
[7:640] Command : xdump 32 * [7:640] Command : xdump 32 *
XDUMP meta-flags 1464554085 XDUMP meta-flags 1466920477
1 "deity" 1 "deity"
8 "bits" 8 "bits"
16 "hidden" 16 "hidden"
@ -422,11 +412,11 @@ Dumping the remaining tables is easy: just walk the table of tables.
Here's the first one: Here's the first one:
[7:640] Command : xdump meta 0 [7:640] Command : xdump meta 0
XDUMP meta sect 1464554085 XDUMP meta sect 1466920477
"owner" 5 0 0 8 "owner" 1 0 0 8
"xloc" 9 0 0 -1 "xloc" 1 0 0 -1
"yloc" 10 0 0 -1 "yloc" 1 0 0 -1
"des" 4 0 0 18 "des" 1 0 0 18
[...] [...]
/78 /78

View file

@ -67,6 +67,8 @@ static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *);
static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *); static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
static void *nsc_lchr(struct valstr *, struct natstr *, void *); static void *nsc_lchr(struct valstr *, struct natstr *, void *);
static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *); static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *);
static void *nsc_meta_type(struct valstr *, struct natstr *, void *);
static void *nsc_meta_len(struct valstr *, struct natstr *, void *);
/* Ugly hacks to avoid illegibly long lines */ /* Ugly hacks to avoid illegibly long lines */
#define fldoff(fld) offsetof(CURSTR, fld) #define fldoff(fld) offsetof(CURSTR, fld)
@ -737,11 +739,12 @@ struct castr mdchr_ca[] = {
/* name must come first, clients may rely on it */ /* name must come first, clients may rely on it */
{"name", fldoff(ca_name), NSC_STRING, 0, NULL, EF_BAD, 0, {"name", fldoff(ca_name), NSC_STRING, 0, NULL, EF_BAD, 0,
CA_DUMP_CONST}, CA_DUMP_CONST},
{"type", fldoff(ca_type), NSC_SITYPE(enum nsc_type), 0, NULL, {"type", fldoff(ca_type), NSC_LONG, 0, nsc_meta_type,
EF_META_TYPE, 0, CA_DUMP_CONST}, EF_META_TYPE, 0, CA_DUMP_CONST},
{"flags", fldoff(ca_flags), NSC_INT, 0, NULL, {"flags", fldoff(ca_flags), NSC_INT, 0, NULL,
EF_META_FLAGS, NSC_BITS, CA_DUMP_CONST}, EF_META_FLAGS, NSC_BITS, CA_DUMP_CONST},
{"len", fldoff(ca_len), NSC_USHORT, 0, NULL, EF_BAD, 0, CA_DUMP_CONST}, {"len", fldoff(ca_len), NSC_LONG, 0, nsc_meta_len,
EF_BAD, 0, CA_DUMP_CONST},
{"table", fldoff(ca_table), NSC_INT, 0, NULL, EF_TABLE, 0, {"table", fldoff(ca_table), NSC_INT, 0, NULL, EF_TABLE, 0,
CA_DUMP_CONST}, CA_DUMP_CONST},
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP} {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
@ -977,3 +980,19 @@ nsc_nws_timestamp(struct valstr *val, struct natstr *natp, void *ptr)
val->val_as.lng = np->nws_when + np->nws_duration; val->val_as.lng = np->nws_when + np->nws_duration;
return NULL; return NULL;
} }
static void *
nsc_meta_type(struct valstr *val, struct natstr *natp, void *ptr)
{
val->val_as.lng = nstr_promote(((struct castr *)ptr)->ca_type);
return NULL;
}
static void *
nsc_meta_len(struct valstr *val, struct natstr *natp, void *ptr)
{
struct castr *ca = ptr;
val->val_as.lng = ca->ca_type == NSC_STRINGY ? 0 : ca->ca_len;
return NULL;
}

View file

@ -88,16 +88,6 @@ struct symbol meta_type[] = {
{NSC_LONG, "d"}, {NSC_LONG, "d"},
{NSC_DOUBLE, "g"}, {NSC_DOUBLE, "g"},
{NSC_STRING, "s"}, {NSC_STRING, "s"},
{NSC_CHAR, "d"},
{NSC_UCHAR, "d"},
{NSC_SHORT, "d"},
{NSC_USHORT, "d"},
{NSC_INT, "d"},
{NSC_XCOORD, "d"},
{NSC_YCOORD, "d"},
{NSC_TIME, "d"},
{NSC_FLOAT, "g"},
{NSC_STRINGY, "c"},
{NSC_NOTYPE, NULL} {NSC_NOTYPE, NULL}
}; };

View file

@ -116,10 +116,6 @@ while (<>) {
# duration in xdump news (column 4) # duration in xdump news (column 4)
s/^(($xdfld_re ){4})([0-9]+) /${1}0 / s/^(($xdfld_re ){4})([0-9]+) /${1}0 /
if $dump eq 'news'; if $dump eq 'news';
### nsc_type values in xdump
# Can vary between systems, because the width of enumeration types
# is implementation-defined.
# TODO type in xdump meta
### nrndx values in xdump ### nrndx values in xdump
# Encoding depends on the host, see resources[]. Too clever by half; # Encoding depends on the host, see resources[]. Too clever by half;
# perhaps we should change it. # perhaps we should change it.

File diff suppressed because it is too large Load diff