]> diplodocus.org Git - nmh/blobdiff - uip/ap.c
Ignore the sign mismatch warning when sbr/dtimep.c is built with
[nmh] / uip / ap.c
index b0934fbcebbb035a1f3c54825fb38b4b0451b816..c42d732c858c49ac659b3acf30d8e92eef19c56e 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
 
 #define        FORMAT  "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
 
 
 #define        FORMAT  "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
 
-static struct swit switches[] = {
-#define        FORMSW  0
-    { "form formatfile", 0 },
-#define        FMTSW   1
-    { "format string", 5 },
-#define        NORMSW  2
-    { "normalize", 0 },
-#define        NNORMSW 3
-    { "nonormalize", 0 },
-#define        WIDTHSW 4
-    { "width columns", 0 },
-#define VERSIONSW 5
-    { "version", 0 },
-#define        HELPSW  6
-    { "help", 0 },
-    { NULL, 0 }
-};
+#define AP_SWITCHES \
+    X("form formatfile", 0, FORMSW) \
+    X("format string", 5, FMTSW) \
+    X("normalize", 0, NORMSW) \
+    X("nonormalize", 0, NNORMSW) \
+    X("width columns", 0, WIDTHSW) \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(AP);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(AP, switches);
+#undef X
 
 static struct format *fmt;
 
 
 static struct format *fmt;
 
@@ -82,10 +81,10 @@ main (int argc, char **argv)
                    snprintf (buf, sizeof(buf), "%s [switches] addrs ...",
                        invo_name);
                    print_help (buf, switches, 1);
                    snprintf (buf, sizeof(buf), "%s [switches] addrs ...",
                        invo_name);
                    print_help (buf, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version (invo_name);
                case VERSIONSW:
                    print_version (invo_name);
-                   done (1);
+                   done (0);
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
@@ -133,7 +132,7 @@ main (int argc, char **argv)
     if (width > WBUFSIZ)
        width = WBUFSIZ;
     fmt_norm = normalize;
     if (width > WBUFSIZ)
        width = WBUFSIZ;
     fmt_norm = normalize;
-    fmt_compile (nfs, &fmt);
+    fmt_compile (nfs, &fmt, 1);
 
     dat[0] = 0;
     dat[1] = 0;
 
     dat[0] = 0;
     dat[1] = 0;
@@ -144,6 +143,7 @@ main (int argc, char **argv)
     for (addrp = 0; addrs[addrp]; addrp++)
        status += process (addrs[addrp], width, normalize);
 
     for (addrp = 0; addrs[addrp]; addrp++)
        status += process (addrs[addrp], width, normalize);
 
+    fmt_free (fmt, 1);
     done (status);
     return 1;
 }
     done (status);
     return 1;
 }
@@ -183,17 +183,26 @@ process (char *arg, int length, int norm)
     }
 
     for (p = pq.pq_next; p; p = q) {
     }
 
     for (p = pq.pq_next; p; p = q) {
-       FINDCOMP (cptr, "text");
-       if (cptr)
+       cptr = fmt_findcomp ("text");
+       if (cptr) {
+           if (cptr->c_text)
+               free(cptr->c_text);
            cptr->c_text = p->pq_text;
            cptr->c_text = p->pq_text;
-       FINDCOMP (cptr, "error");
-       if (cptr)
+           p->pq_text = NULL;
+       }
+       cptr = fmt_findcomp ("error");
+       if (cptr) {
+           if (cptr->c_text)
+               free(cptr->c_text);
            cptr->c_text = p->pq_error;
            cptr->c_text = p->pq_error;
+           p->pq_error = NULL;
+       }
 
 
-       fmt_scan (fmt, buffer, length, dat);
+       fmt_scan (fmt, buffer, sizeof buffer - 1, length, dat, NULL);
        fputs (buffer, stdout);
 
        fputs (buffer, stdout);
 
-       free (p->pq_text);
+       if (p->pq_text)
+           free (p->pq_text);
        if (p->pq_error)
            free (p->pq_error);
        q = p->pq_next;
        if (p->pq_error)
            free (p->pq_error);
        q = p->pq_next;