X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fali.c;h=d4c6c7fb20e98371bc1ac9a43d66c82f40610fb9;hp=a4ab2950650960e599fde1c25233786d43d5e171;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=240013872c392fe644bd4f79382d9f5314b4ea60 diff --git a/uip/ali.c b/uip/ali.c index a4ab295..d4c6c7f 100644 --- a/uip/ali.c +++ b/uip/ali.c @@ -9,8 +9,9 @@ #include #include #include -#include #include +#include +#include /* ** maximum number of names @@ -18,29 +19,29 @@ #define NVEC 50 static struct swit switches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define NALIASW 1 - { "noalias", -7 }, -#define LISTSW 2 +#define FILESW 0 + { "file aliasfile", 0 }, +#define LISTSW 1 { "list", 0 }, -#define NLISTSW 3 - { "nolist", 0 }, -#define NORMSW 4 +#define NLISTSW 2 + { "nolist", 2 }, +#define NORMSW 3 { "normalize", 0 }, -#define NNORMSW 5 - { "nonormalize", 0 }, -#define USERSW 6 +#define NNORMSW 4 + { "nonormalize", 2 }, +#define USERSW 5 { "user", 0 }, -#define NUSERSW 7 - { "nouser", 0 }, -#define VERSIONSW 8 - { "version", 0 }, -#define HELPSW 9 +#define NUSERSW 6 + { "nouser", 2 }, +#define VERSIONSW 7 + { "Version", 0 }, +#define HELPSW 8 { "help", 0 }, { NULL, 0 } }; +char *version=VERSION; + static int pos = 1; extern struct aka *akahead; @@ -56,88 +57,86 @@ int main(int argc, char **argv) { int i, vecp = 0, inverted = 0, list = 0; - int noalias = 0, normalize = AD_NHST; + int deffiles = 1, normalize = AD_NHST; char *cp, **ap, **argp, buf[BUFSIZ]; char *vec[NVEC], **arguments; struct aka *ak; -#ifdef LOCALE setlocale(LC_ALL, ""); -#endif invo_name = mhbasename(argv[0]); /* read user profile/context */ context_read(); - mts_init(invo_name); arguments = getarguments(invo_name, argc, argv, 1); argp = arguments; while ((cp = *argp++)) { if (*cp == '-') { switch (smatch(++cp, switches)) { - case AMBIGSW: - ambigsw(cp, switches); - done(1); - case UNKWNSW: - adios(NULL, "-%s unknown", cp); - - case HELPSW: - snprintf(buf, sizeof(buf), "%s [switches] aliases ...", - invo_name); - print_help(buf, switches, 1); - done(1); - case VERSIONSW: - print_version(invo_name); - done(1); - - case ALIASW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", argp[-2]); - if ((i = alias(cp)) != AK_OK) - adios(NULL, "aliasing error in %s - %s", cp, akerror(i)); - continue; - case NALIASW: - noalias++; - continue; + case AMBIGSW: + ambigsw(cp, switches); + exit(EX_USAGE); + case UNKWNSW: + adios(EX_USAGE, NULL, "-%s unknown", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [switches] aliases ...", + invo_name); + print_help(buf, switches, 1); + exit(argc == 2 ? EX_OK : EX_USAGE); + case VERSIONSW: + print_version(invo_name); + exit(argc == 2 ? EX_OK : EX_USAGE); + + case FILESW: + if (!(cp = *argp++) || *cp == '-') { + adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]); + } + if ((i = alias(cp)) != AK_OK) + adios(EX_USAGE, NULL, "aliasing error in %s: %s", cp, akerror(i)); + deffiles = 0; + continue; - case LISTSW: - list++; - continue; - case NLISTSW: - list = 0; - continue; + case LISTSW: + list++; + continue; + case NLISTSW: + list = 0; + continue; - case NORMSW: - normalize = AD_HOST; - continue; - case NNORMSW: - normalize = AD_NHST; - continue; + case NORMSW: + normalize = AD_HOST; + continue; + case NNORMSW: + normalize = AD_NHST; + continue; - case USERSW: - inverted++; - continue; - case NUSERSW: - inverted = 0; - continue; + case USERSW: + inverted++; + continue; + case NUSERSW: + inverted = 0; + continue; } } vec[vecp++] = cp; } - if (!noalias) { - /* allow Aliasfile: profile entry */ - if ((cp = context_find("Aliasfile"))) { - char *dp = NULL; + /* process default Aliasfile: profile entry */ + if (deffiles && (cp = context_find("Aliasfile"))) { + char *dp = NULL; - for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) - if ((i = alias(*ap)) != AK_OK) - adios(NULL, "aliasing error in %s - %s", *ap, akerror(i)); - if (dp) - free(dp); + for (ap = brkstring(dp=mh_xstrdup(cp), " ", "\n"); + ap && *ap; ap++) { + if ((i = alias(etcpath(*ap))) != AK_OK) { + adios(EX_DATAERR, NULL, "aliasing error in %s: %s", + *ap, akerror(i)); + } + } + if (dp) { + mh_free0(&dp); } - alias(AliasFile); } /* @@ -145,13 +144,13 @@ main(int argc, char **argv) */ if (inverted) { if (vecp == 0) - adios(NULL, "usage: %s -user addresses ... (you forgot the addresses)", + adios(EX_USAGE, NULL, "usage: %s -user addresses ... (you forgot the addresses)", invo_name); for (i = 0; i < vecp; i++) print_usr(vec[i], list, normalize); - done(0); + exit(EX_OK); } if (vecp) { @@ -167,8 +166,7 @@ main(int argc, char **argv) } } - done(0); - return 1; + return EX_OK; } static void @@ -183,27 +181,27 @@ print_aka(char *p, int list, int margin) while ((c = *p++)) { switch (c) { - case ',': - if (*p) { - if (list) - printf("\n%*s", margin, ""); - else { - if (pos >= 68) { - printf(",\n "); - pos = 2; - } else { - printf(", "); - pos += 2; - } + case ',': + if (*p) { + if (list) + printf("\n%*s", margin, ""); + else { + if (pos >= 68) { + printf(",\n "); + pos = 2; + } else { + printf(", "); + pos += 2; } } + } - case 0: - break; + case 0: + break; - default: - pos++; - putchar(c); + default: + pos++; + putchar(c); } } @@ -214,14 +212,14 @@ print_aka(char *p, int list, int margin) static void print_usr(char *s, int list, int norm) { - register char *cp, *pp, *vp; - register struct aka *ak; - register struct mailname *mp, *np; + char *cp, *pp, *vp; + struct aka *ak; + struct mailname *mp, *np; if ((pp = getname(s)) == NULL) - adios(NULL, "no address in \"%s\"", s); + adios(EX_DATAERR, NULL, "no address in \"%s\"", s); if ((mp = getm(pp, NULL, 0, norm, NULL)) == NULL) - adios(NULL, "bad address \"%s\"", s); + adios(EX_DATAERR, NULL, "bad address \"%s\"", s); while (getname("")) continue; @@ -234,7 +232,7 @@ print_usr(char *s, int list, int norm) 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); + : mh_xstrdup(ak->ak_name); mnfree(np); while (getname("")) continue; @@ -245,13 +243,8 @@ 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); + mh_free0(&vp); }