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;
|
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 ichr_ca[];
|
||||||
extern struct castr pchr_ca[];
|
extern struct castr pchr_ca[];
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ron Koenderink, 2005
|
* Ron Koenderink, 2005
|
||||||
* Markus Armbruster, 2006-2013
|
* Markus Armbruster, 2006-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -56,7 +56,7 @@ verify_fail(int type, int row, struct castr *ca, int idx, char *fmt, ...)
|
||||||
ef_nameof(type), row);
|
ef_nameof(type), row);
|
||||||
if (ca) {
|
if (ca) {
|
||||||
fprintf(stderr, " field %s", ca->ca_name);
|
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, "(%d)", idx);
|
||||||
}
|
}
|
||||||
fprintf(stderr, ": ");
|
fprintf(stderr, ": ");
|
||||||
|
@ -163,7 +163,7 @@ verify_row(int type, int row)
|
||||||
for (i = 0; ca[i].ca_name; ++i) {
|
for (i = 0; ca[i].ca_name; ++i) {
|
||||||
if (ca[i].ca_get)
|
if (ca[i].ca_get)
|
||||||
continue; /* virtual */
|
continue; /* virtual */
|
||||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
n = CA_ARRAY_LEN(&ca[i]);
|
||||||
j = 0;
|
j = 0;
|
||||||
do {
|
do {
|
||||||
if (ca[i].ca_table == EF_BAD)
|
if (ca[i].ca_table == EF_BAD)
|
||||||
|
|
|
@ -244,7 +244,7 @@ xdflds(struct xdstr *xd, struct castr ca[], void *ptr)
|
||||||
continue;
|
continue;
|
||||||
if (ca[i].ca_flags & NSC_EXTRA)
|
if (ca[i].ca_flags & NSC_EXTRA)
|
||||||
continue;
|
continue;
|
||||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
n = CA_ARRAY_LEN(&ca[i]);
|
||||||
j = 0;
|
j = 0;
|
||||||
do {
|
do {
|
||||||
xdeval(&val, xd, &ca[i], ptr, j);
|
xdeval(&val, xd, &ca[i], ptr, j);
|
||||||
|
@ -287,7 +287,7 @@ xdcolhdr(struct xdstr *xd, struct castr ca[])
|
||||||
continue;
|
continue;
|
||||||
if (ca[i].ca_flags & NSC_EXTRA)
|
if (ca[i].ca_flags & NSC_EXTRA)
|
||||||
continue;
|
continue;
|
||||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
n = CA_ARRAY_LEN(&ca[i]);
|
||||||
if (n) {
|
if (n) {
|
||||||
for (j = 0; j < n; j++) {
|
for (j = 0; j < n; j++) {
|
||||||
xd->pr("%s%s(%d)", sep, ca[i].ca_name, j);
|
xd->pr("%s%s(%d)", sep, ca[i].ca_name, j);
|
||||||
|
|
|
@ -436,7 +436,7 @@ xufld(FILE *fp, int i)
|
||||||
case '\n':
|
case '\n':
|
||||||
CANT_HAPPEN(i > nflds);
|
CANT_HAPPEN(i > nflds);
|
||||||
if (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",
|
return gripe("Field %s(%d) missing",
|
||||||
fldca[i]->ca_name, fldidx[i]);
|
fldca[i]->ca_name, fldidx[i]);
|
||||||
return gripe("Field %s missing", fldca[i]->ca_name);
|
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");
|
res == M_NOTUNIQUE ? "ambiguous" : "unknown");
|
||||||
if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
|
if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
|
||||||
return gripe("Extraneous header %s in field %d", name, fldno + 1);
|
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)
|
if (idx < 0)
|
||||||
return gripe("Header %s requires an index in field %d",
|
return gripe("Header %s requires an index in field %d",
|
||||||
ca[res].ca_name, fldno + 1);
|
ca[res].ca_name, fldno + 1);
|
||||||
|
@ -614,7 +614,7 @@ chkflds(void)
|
||||||
cafldsmax = MAX(caflds[i], cafldspp[i]);
|
cafldsmax = MAX(caflds[i], cafldspp[i]);
|
||||||
if (ca[i].ca_flags & NSC_EXTRA)
|
if (ca[i].ca_flags & NSC_EXTRA)
|
||||||
continue;
|
continue;
|
||||||
len = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
len = CA_ARRAY_LEN(&ca[i]);
|
||||||
if (!len && !cafldsmax)
|
if (!len && !cafldsmax)
|
||||||
res = gripe("Header field %s missing", ca[i].ca_name);
|
res = gripe("Header field %s missing", ca[i].ca_name);
|
||||||
else if (len && cafldsmax == len - 1)
|
else if (len && cafldsmax == len - 1)
|
||||||
|
@ -1012,7 +1012,7 @@ xufldhdr(FILE *fp, struct castr ca[])
|
||||||
for (i = 0; ca[i].ca_name; i++) {
|
for (i = 0; ca[i].ca_name; i++) {
|
||||||
if ((ca[i].ca_flags & NSC_EXTRA))
|
if ((ca[i].ca_flags & NSC_EXTRA))
|
||||||
continue;
|
continue;
|
||||||
n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
|
n = CA_ARRAY_LEN(&ca[i]);
|
||||||
j = 0;
|
j = 0;
|
||||||
do {
|
do {
|
||||||
*fca++ = &ca[i];
|
*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++) {
|
for (i = 0; ca[i].ca_name; i++) {
|
||||||
nca++;
|
nca++;
|
||||||
if (!(ca[i].ca_flags & NSC_EXTRA)) {
|
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)
|
if (ca[i].ca_flags & NSC_CONST)
|
||||||
may_omit_id = may_trunc = 0;
|
may_omit_id = may_trunc = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue