]> git.pond.sub.org Git - empserver/commitdiff
nsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 2 Feb 2014 09:13:41 +0000 (10:13 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Feb 2015 15:52:59 +0000 (16:52 +0100)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/nsc.h
src/lib/common/ef_verify.c
src/lib/common/xdump.c
src/lib/common/xundump.c

index e2b4b33c7a17b41c418eac20a70c7c8f111d5edb..3583c9ee86282d651ca7bcf2614947d10be57f40 100644 (file)
@@ -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 pchr_ca[];
 
 extern struct castr ichr_ca[];
 extern struct castr pchr_ca[];
index 17057c598589aafbb3e2082d3e5b2467b4017516..2345efdb731520deb29f27ae4c0ab975a9f51ec8 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
  *
  *  Known contributors to this file:
  *     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);
     if (ca) {
        fprintf(stderr, " field %s", ca->ca_name);
            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, ": ");
            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 */
     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)
        j = 0;
        do {
            if (ca[i].ca_table == EF_BAD)
index ff1ee6deb1616931eab55fc042979f8cea80d8d5..5ed558447d97dc73ad2818ca34ad1e9a072038c3 100644 (file)
@@ -244,7 +244,7 @@ xdflds(struct xdstr *xd, struct castr ca[], void *ptr)
            continue;
        if (ca[i].ca_flags & NSC_EXTRA)
            continue;
            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);
        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;
            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);
        if (n) {
            for (j = 0; j < n; j++) {
                xd->pr("%s%s(%d)", sep, ca[i].ca_name, j);
index 33b726804b8b73d42f90a1e1e39c02e6e3ddf9ec..1b89308ed55fe1e024fe012b44049b38f4239aaf 100644 (file)
@@ -436,7 +436,7 @@ xufld(FILE *fp, int i)
     case '\n':
        CANT_HAPPEN(i > nflds);
        if (i < nflds) {
     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);
                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);
                     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);
        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;
        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)
        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;
        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];
            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)) {
     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;
        }
            if (ca[i].ca_flags & NSC_CONST)
                may_omit_id = may_trunc = 0;
        }