nsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
143a4e4e6f
commit
b6775d1c9b
4 changed files with 15 additions and 11 deletions
|
@ -235,7 +235,11 @@ struct castr {
|
|||
int ca_flags;
|
||||
};
|
||||
|
||||
/* variables using the above */
|
||||
/* Is CA an array? */
|
||||
#define CA_IS_ARRAY(ca) ((ca)->ca_type != NSC_STRINGY && (ca)->ca_len != 0)
|
||||
|
||||
/* If CA is an array, return its length, else zero */
|
||||
#define CA_ARRAY_LEN(ca) ((ca)->ca_type != NSC_STRINGY ? (ca)->ca_len : 0)
|
||||
|
||||
extern struct castr ichr_ca[];
|
||||
extern struct castr pchr_ca[];
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Ron Koenderink, 2005
|
||||
* Markus Armbruster, 2006-2013
|
||||
* Markus Armbruster, 2006-2014
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -56,7 +56,7 @@ verify_fail(int type, int row, struct castr *ca, int idx, char *fmt, ...)
|
|||
ef_nameof(type), row);
|
||||
if (ca) {
|
||||
fprintf(stderr, " field %s", ca->ca_name);
|
||||
if (ca->ca_type != NSC_STRINGY && ca->ca_len != 0)
|
||||
if (CA_IS_ARRAY(ca))
|
||||
fprintf(stderr, "(%d)", idx);
|
||||
}
|
||||
fprintf(stderr, ": ");
|
||||
|
@ -163,7 +163,7 @@ verify_row(int type, int row)
|
|||
for (i = 0; ca[i].ca_name; ++i) {
|
||||
if (ca[i].ca_get)
|
||||
continue; /* virtual */
|
||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
||||
n = CA_ARRAY_LEN(&ca[i]);
|
||||
j = 0;
|
||||
do {
|
||||
if (ca[i].ca_table == EF_BAD)
|
||||
|
|
|
@ -244,7 +244,7 @@ xdflds(struct xdstr *xd, 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;
|
||||
n = CA_ARRAY_LEN(&ca[i]);
|
||||
j = 0;
|
||||
do {
|
||||
xdeval(&val, xd, &ca[i], ptr, j);
|
||||
|
@ -287,7 +287,7 @@ xdcolhdr(struct xdstr *xd, struct castr ca[])
|
|||
continue;
|
||||
if (ca[i].ca_flags & NSC_EXTRA)
|
||||
continue;
|
||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
||||
n = CA_ARRAY_LEN(&ca[i]);
|
||||
if (n) {
|
||||
for (j = 0; j < n; j++) {
|
||||
xd->pr("%s%s(%d)", sep, ca[i].ca_name, j);
|
||||
|
|
|
@ -436,7 +436,7 @@ xufld(FILE *fp, int i)
|
|||
case '\n':
|
||||
CANT_HAPPEN(i > nflds);
|
||||
if (i < nflds) {
|
||||
if (fldca[i]->ca_type != NSC_STRINGY && fldca[i]->ca_len)
|
||||
if (CA_IS_ARRAY(fldca[i]))
|
||||
return gripe("Field %s(%d) missing",
|
||||
fldca[i]->ca_name, fldidx[i]);
|
||||
return gripe("Field %s missing", fldca[i]->ca_name);
|
||||
|
@ -534,7 +534,7 @@ deffld(int fldno, char *name, int idx)
|
|||
res == M_NOTUNIQUE ? "ambiguous" : "unknown");
|
||||
if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
|
||||
return gripe("Extraneous header %s in field %d", name, fldno + 1);
|
||||
if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
|
||||
if (CA_IS_ARRAY(&ca[res])) {
|
||||
if (idx < 0)
|
||||
return gripe("Header %s requires an index in field %d",
|
||||
ca[res].ca_name, fldno + 1);
|
||||
|
@ -614,7 +614,7 @@ chkflds(void)
|
|||
cafldsmax = MAX(caflds[i], cafldspp[i]);
|
||||
if (ca[i].ca_flags & NSC_EXTRA)
|
||||
continue;
|
||||
len = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
||||
len = CA_ARRAY_LEN(&ca[i]);
|
||||
if (!len && !cafldsmax)
|
||||
res = gripe("Header field %s missing", ca[i].ca_name);
|
||||
else if (len && cafldsmax == len - 1)
|
||||
|
@ -1012,7 +1012,7 @@ xufldhdr(FILE *fp, struct castr ca[])
|
|||
for (i = 0; ca[i].ca_name; i++) {
|
||||
if ((ca[i].ca_flags & NSC_EXTRA))
|
||||
continue;
|
||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
||||
n = CA_ARRAY_LEN(&ca[i]);
|
||||
j = 0;
|
||||
do {
|
||||
*fca++ = &ca[i];
|
||||
|
@ -1094,7 +1094,7 @@ xundump(FILE *fp, char *file, int *plno, int expected_table)
|
|||
for (i = 0; ca[i].ca_name; i++) {
|
||||
nca++;
|
||||
if (!(ca[i].ca_flags & NSC_EXTRA)) {
|
||||
nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0);
|
||||
nf += MAX(1, CA_ARRAY_LEN(&ca[i]));
|
||||
if (ca[i].ca_flags & NSC_CONST)
|
||||
may_omit_id = may_trunc = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue