#include <h/addrsbr.h>
#include <h/fmt_scan.h>
#include <h/utils.h>
+#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERSIONSW 0
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;
}
}
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;
}
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]);
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);
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);
if ((in = fopen(file, "r")) == NULL) {
- adios(file, "unable to open");
+ adios(EX_IOERR, file, "unable to open");
}
for (compnum = 1, state = FLD;;) {
case FLDPLUS:
compnum++;
- cp = add(buf, cp);
+ cp = getcpy(buf);
while (state == FLDPLUS) {
state = m_getfld(state, name, buf,
sizeof(buf), in);
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;
}
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) {