]> diplodocus.org Git - nmh/blobdiff - uip/ali.c
Support for selectable Content-Transfer-Encoding.
[nmh] / uip / ali.c
index 7cffc5043192ea460bae79188dda4a09cd335328..e7c865befee983e6f8ef98e6763b65454aff9402 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -2,42 +2,34 @@
 /*
  * ali.c -- list nmh mail aliases
  *
 /*
  * 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/mh.h>
 #include <h/addrsbr.h>
 #include <h/aliasbr.h>
 #include <h/mts.h>
  */
 
 #include <h/mh.h>
 #include <h/addrsbr.h>
 #include <h/aliasbr.h>
 #include <h/mts.h>
-
-/*
- * maximum number of names
- */
-#define        NVEC 50
-
-static struct swit switches[] = {
-#define        ALIASW                0
-    { "alias aliasfile", 0 },
-#define        NALIASW               1
-    { "noalias", -7 },
-#define        LISTSW                2
-    { "list", 0 },
-#define        NLISTSW               3
-    { "nolist", 0 },
-#define        NORMSW                4
-    { "normalize", 0 },
-#define        NNORMSW               5
-    { "nonormalize", 0 },
-#define        USERSW                6
-    { "user", 0 },
-#define        NUSERSW               7
-    { "nouser", 0 },
-#define VERSIONSW             8
-    { "version", 0 },
-#define        HELPSW                9
-    { "help", 0 },
-    { NULL, 0 }
-};
+#include <h/utils.h>
+
+#define ALI_SWITCHES \
+    X("alias aliasfile", 0, ALIASW) \
+    X("noalias", -7, NALIASW) \
+    X("list", 0, LISTSW) \
+    X("nolist", 0, NLISTSW) \
+    X("user", 0, USERSW) \
+    X("nouser", 0, NUSERSW) \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(ALI);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(ALI, switches);
+#undef X
 
 static int pos = 1;
 
 
 static int pos = 1;
 
@@ -46,26 +38,22 @@ extern struct aka *akahead;
 /*
  * prototypes
  */
 /*
  * 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
 main (int argc, char **argv)
 {
     int i, vecp = 0, inverted = 0, list = 0;
 
 
 int
 main (int argc, char **argv)
 {
     int i, vecp = 0, inverted = 0, list = 0;
-    int noalias = 0, normalize = AD_NHST;
+    int noalias = 0;
     char *cp, **ap, **argp, buf[BUFSIZ];
     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;
 
     struct aka *ak;
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -84,10 +72,10 @@ main (int argc, char **argv)
                    snprintf (buf, sizeof(buf), "%s [switches] aliases ...",
                        invo_name);
                    print_help (buf, switches, 1);
                    snprintf (buf, sizeof(buf), "%s [switches] aliases ...",
                        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 ALIASW: 
                    if (!(cp = *argp++) || *cp == '-')
 
                case ALIASW: 
                    if (!(cp = *argp++) || *cp == '-')
@@ -106,13 +94,6 @@ main (int argc, char **argv)
                    list = 0;
                    continue;
 
                    list = 0;
                    continue;
 
-               case NORMSW: 
-                   normalize = AD_HOST;
-                   continue;
-               case NNORMSW: 
-                   normalize = AD_NHST;
-                   continue;
-
                case USERSW: 
                    inverted++;
                    continue;
                case USERSW: 
                    inverted++;
                    continue;
@@ -121,7 +102,14 @@ main (int argc, char **argv)
                    continue;
            }
        }
                    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) {
     }
 
     if (!noalias) {
@@ -147,28 +135,28 @@ main (int argc, char **argv)
                   invo_name);
 
        for (i = 0; i < vecp; i++)
                   invo_name);
 
        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);
+           print_usr (vec[i], list);
     } else {
     } 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;
 print_aka (char *p, int list, int margin)
 {
     char c;
@@ -208,8 +196,8 @@ print_aka (char *p, int list, int margin)
     pos = 1;
 }
 
     pos = 1;
 }
 
-void
-print_usr (char *s, int list, int norm)
+static void
+print_usr (char *s, int list)
 {
     register char *cp, *pp, *vp;
     register struct aka *ak;
 {
     register char *cp, *pp, *vp;
     register struct aka *ak;
@@ -217,7 +205,7 @@ print_usr (char *s, int list, int norm)
 
     if ((pp = getname (s)) == NULL)
        adios (NULL, "no address in \"%s\"", s);
 
     if ((pp = getname (s)) == NULL)
        adios (NULL, "no address in \"%s\"", s);
-    if ((mp = getm (pp, NULL, 0, norm, NULL)) == NULL)
+    if ((mp = getm (pp, NULL, 0, NULL, 0)) == NULL)
        adios (NULL, "bad address \"%s\"", s);
     while (getname (""))
        continue;
        adios (NULL, "bad address \"%s\"", s);
     while (getname (""))
        continue;
@@ -226,10 +214,12 @@ print_usr (char *s, int list, int norm)
     for (ak = akahead; ak; ak = ak->ak_next) {
        pp = akresult (ak);
        while ((cp = getname (pp))) {
     for (ak = akahead; ak; ak = ak->ak_next) {
        pp = akresult (ak);
        while ((cp = getname (pp))) {
-           if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL)
+           if ((np = getm (cp, NULL, 0, NULL, 0)) == NULL)
                continue;
                continue;
-           if (!strcasecmp (mp->m_host, np->m_host)
-                   && !strcasecmp (mp->m_mbox, np->m_mbox)) {
+           if (!strcasecmp (mp->m_host ? mp->m_host : "",
+                            np->m_host ? np->m_host : "")  &&
+               !strcasecmp (mp->m_mbox ? mp->m_mbox : "",
+                            np->m_mbox ? np->m_mbox : "")) {
                vp = vp ? add (ak->ak_name, add (",", vp))
                    : getcpy (ak->ak_name);
                mnfree (np);
                vp = vp ? add (ak->ak_name, add (",", vp))
                    : getcpy (ak->ak_name);
                mnfree (np);
@@ -242,12 +232,7 @@ print_usr (char *s, int list, int norm)
     }
     mnfree (mp);
 
     }
     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);
     print_aka (vp ? vp : s, list, 0);
-#endif
 
     if (vp)
        free (vp);
 
     if (vp)
        free (vp);