Removed some dead code, all inside #if 0's. I tried to not remove
[mmh] / uip / ali.c
index c600387..880fe21 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -2,8 +2,6 @@
 /*
  * ali.c -- list nmh mail aliases
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
 #include <h/addrsbr.h>
 #include <h/aliasbr.h>
 #include <h/mts.h>
-
-/*
- * maximum number of names
- */
-#define        NVEC 50
+#include <h/utils.h>
 
 static struct swit switches[] = {
 #define        ALIASW                0
@@ -50,8 +44,8 @@ extern struct aka *akahead;
 /*
  * prototypes
  */
-void print_aka (char *, int, int);
-void print_usr (char *, int, int);
+static void print_aka (char *, int, int);
+static void print_usr (char *, int, int);
 
 
 int
@@ -60,7 +54,9 @@ main (int argc, char **argv)
     int i, vecp = 0, inverted = 0, list = 0;
     int noalias = 0, normalize = AD_NHST;
     char *cp, **ap, **argp, buf[BUFSIZ];
-    char *vec[NVEC], **arguments;
+    /* Really only need to allocate for argc-1, but must allocate at least 1,
+       so go ahead and allocate for argc char pointers. */
+    char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
     struct aka *ak;
 
 #ifdef LOCALE
@@ -88,10 +84,10 @@ main (int argc, char **argv)
                    snprintf (buf, sizeof(buf), "%s [switches] aliases ...",
                        invo_name);
                    print_help (buf, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version (invo_name);
-                   done (1);
+                   done (0);
 
                case ALIASW: 
                    if (!(cp = *argp++) || *cp == '-')
@@ -125,7 +121,14 @@ main (int argc, char **argv)
                    continue;
            }
        }
-       vec[vecp++] = cp;
+
+       if (vecp < argc) {
+           vec[vecp++] = cp;
+       } else {
+           /* Should never happen, but try to protect against code changes
+              that could allow it. */
+           adios (NULL, "too many arguments");
+       }
     }
 
     if (!noalias) {
@@ -152,27 +155,27 @@ main (int argc, char **argv)
 
        for (i = 0; i < vecp; i++)
            print_usr (vec[i], list, normalize);
-
-       done (0);
-    }
-
-    if (vecp) {
-       /* print specified aliases */
-       for (i = 0; i < vecp; i++)
-           print_aka (akvalue (vec[i]), list, 0);
     } else {
-       /* print them all */
-       for (ak = akahead; ak; ak = ak->ak_next) {
-           printf ("%s: ", ak->ak_name);
-           pos += strlen (ak->ak_name) + 1;
-           print_aka (akresult (ak), list, pos);
+       if (vecp) {
+           /* print specified aliases */
+           for (i = 0; i < vecp; i++)
+               print_aka (akvalue (vec[i]), list, 0);
+       } else {
+           /* print them all */
+           for (ak = akahead; ak; ak = ak->ak_next) {
+               printf ("%s: ", ak->ak_name);
+               pos += strlen (ak->ak_name) + 1;
+               print_aka (akresult (ak), list, pos);
+           }
        }
     }
 
-    return done (0);
+    free (vec);
+    done (0);
+    return 1;
 }
 
-void
+static void
 print_aka (char *p, int list, int margin)
 {
     char c;
@@ -212,7 +215,7 @@ print_aka (char *p, int list, int margin)
     pos = 1;
 }
 
-void
+static void
 print_usr (char *s, int list, int norm)
 {
     register char *cp, *pp, *vp;
@@ -232,8 +235,8 @@ print_usr (char *s, int list, int norm)
        while ((cp = getname (pp))) {
            if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL)
                continue;
-           if (!strcasecmp (mp->m_host, np->m_host)
-                   && !strcasecmp (mp->m_mbox, np->m_mbox)) {
+           if (!mh_strcasecmp (mp->m_host, np->m_host)
+                   && !mh_strcasecmp (mp->m_mbox, np->m_mbox)) {
                vp = vp ? add (ak->ak_name, add (",", vp))
                    : getcpy (ak->ak_name);
                mnfree (np);
@@ -246,12 +249,7 @@ print_usr (char *s, int list, int norm)
     }
     mnfree (mp);
 
-#if 0
-    printf ("%s: ", s);
-    print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
-#else
     print_aka (vp ? vp : s, list, 0);
-#endif
 
     if (vp)
        free (vp);