X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fwhom.c;h=e61dc62327e8f0686d09dfa76362fa5dca3d6957;hp=0451699b545de152d0337fd8330887739ac3c44f;hb=cf1205b5cbea2f0cd6ea710ec16c637df85b647c;hpb=204c305913a20d207cba063ec2da8d0275d2da5d diff --git a/uip/whom.c b/uip/whom.c index 0451699..e61dc62 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include static struct swit switches[] = { #define VERSIONSW 0 @@ -85,20 +87,20 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(1); + exit(EX_USAGE); case UNKWNSW: - adios(NULL, "-%s unknown", cp); + adios(EX_USAGE, NULL, "-%s unknown", cp); case HELPSW: snprintf(buf, sizeof(buf), "%s [switches] file ...", invo_name); print_help(buf, switches, 1); - done(1); + exit(argc == 2 ? EX_OK : EX_USAGE); case VERSIONSW: print_version(invo_name); - done(1); + exit(argc == 2 ? EX_OK : EX_USAGE); case TOCCSW: toccsw = 1; @@ -123,7 +125,7 @@ main(int argc, char **argv) } } if (filep > NFILES) { - adios(NULL, "too many files (more than %d)", + adios(EX_USAGE, NULL, "too many files (more than %d)", NFILES); } else { files[filep++] = cp; @@ -131,10 +133,10 @@ main(int argc, char **argv) } files[filep] = NULL; if (!filep) { - adios(NULL, "usage: %s [switches] file ...", invo_name); + adios(EX_USAGE, NULL, "usage: %s [switches] file ...", invo_name); } if (!toccsw && !bccsw) { - adios(NULL, "give -tocc or -bcc or both to produce output"); + adios(EX_USAGE, NULL, "give -tocc or -bcc or both to produce output"); } for (filep=0; files[filep]; filep++) { process(files[filep]); @@ -143,7 +145,7 @@ main(int argc, char **argv) cmd = add("ali -list", NULL); if ((n=print()) && alisw) { if (!(in = popen(cmd, "r"))) { - adios("popen", "unable to"); + adios(EX_IOERR, "popen", "unable to"); } while (fgets(buf, sizeof buf, in)) { fputs(buf, stdout); @@ -153,14 +155,10 @@ main(int argc, char **argv) free(cmd); naddrs += n; - if (toccsw && bccsw) { - puts(separator); - } - cmd = add("ali -list", NULL); if ((n=printbcc()) && alisw) { if (!(in = popen(cmd, "r"))) { - adios("popen", "unable to"); + adios(EX_IOERR, "popen", "unable to"); } while (fgets(buf, sizeof buf, in)) { fputs(buf, stdout); @@ -177,13 +175,13 @@ static int process(char *file) { int state, compnum; - char *cp; + char *cp = NULL; char buf[BUFSIZ], name[NAMESZ]; FILE *in; if ((in = fopen(file, "r")) == NULL) { - adios(file, "unable to open"); + adios(EX_IOERR, file, "unable to open"); } for (compnum = 1, state = FLD;;) { @@ -211,11 +209,11 @@ process(char *file) case LENERR: case FMTERR: - adios(NULL, "message format error in component #%d", + adios(EX_DATAERR, NULL, "message format error in component #%d", compnum); default: - adios(NULL, "getfld() returned %d", state); + adios(EX_SOFTWARE, NULL, "getfld() returned %d", state); } break; } @@ -267,7 +265,7 @@ proc_hdr(char *name, char *val) while ((cp = getname(val))) { if (!(mp->m_next = getm(cp, NULL, 0, AD_NAME, NULL))) { - adios(NULL, "illegal address: %s", cp); + adios(EX_DATAERR, NULL, "illegal address: %s", cp); } mp = mp->m_next; if (mp->m_type == BADHOST) { @@ -314,6 +312,9 @@ printbcc(void) continue; } if (mp->m_type & HBCC) { + if (!naddrs && toccsw) { + puts(separator); + } naddrs++; printone(mp); }