X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fprompter.c;h=0ca1e83a232c584a40ffee4eb68fd94e1e21ad31;hp=2bcd92a2076602bd96c820766707822deda66a02;hb=cf1205b5cbea2f0cd6ea710ec16c637df85b647c;hpb=d254c5e2ad008f26d5fda43c3f24f0a711c7e851 diff --git a/uip/prompter.c b/uip/prompter.c index 2bcd92a..0ca1e83 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -16,6 +16,7 @@ #include #include #include +#include static struct swit switches[] = { #define PREPSW 0 @@ -75,19 +76,20 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - exit(1); + exit(EX_USAGE); case UNKWNSW: - adios(NULL, "-%s unknown", cp); + adios(EX_USAGE, NULL, "-%s unknown", cp); case HELPSW: snprintf(buffer, sizeof(buffer), "%s [switches] file", invo_name); print_help(buffer, switches, 1); - exit(0); + exit(argc == 2 ? EX_OK : EX_USAGE); + case VERSIONSW: print_version(invo_name); - exit(0); + exit(argc == 2 ? EX_OK : EX_USAGE); case PREPSW: prepend++; @@ -115,14 +117,17 @@ main(int argc, char **argv) } } - if (!drft) - adios(NULL, "usage: %s [switches] file", invo_name); - if ((in = fopen(drft, "r")) == NULL) - adios(drft, "unable to open"); + if (!drft) { + adios(EX_USAGE, NULL, "usage: %s [switches] file", invo_name); + } + if ((in = fopen(drft, "r")) == NULL) { + adios(EX_IOERR, drft, "unable to open"); + } tfile = m_mktemp2(NULL, invo_name, NULL, &out); - if (tfile == NULL) - adios("prompter", "unable to create temporary file"); + if (tfile == NULL) { + adios(EX_CANTCREAT, "prompter", "unable to create temporary file"); + } chmod(tmpfil, 0600); strncpy(tmpfil, tfile, sizeof(tmpfil)); @@ -164,8 +169,7 @@ main(int argc, char **argv) if (i == -1) { abort: unlink(tmpfil); - /* sysexits.h EX_DATAERR */ - exit(1); + exit(EX_DATAERR); } if (i || (field[0]!='\n' && field[0]!='\0')) { fprintf(out, "%s:", name); @@ -236,7 +240,7 @@ has_no_body: break; default: - adios(NULL, "skeleton is poorly formatted"); + adios(EX_DATAERR, NULL, "skeleton is poorly formatted"); } break; } @@ -249,17 +253,19 @@ has_no_body: fclose(out); SIGNAL(SIGINT, SIG_IGN); - if ((fdi = open(tmpfil, O_RDONLY)) == NOTOK) - adios(tmpfil, "unable to re-open"); - if ((fdo = creat(drft, m_gmprot())) == NOTOK) - adios(drft, "unable to write"); + if ((fdi = open(tmpfil, O_RDONLY)) == NOTOK) { + adios(EX_IOERR, tmpfil, "unable to re-open"); + } + if ((fdo = creat(drft, m_gmprot())) == NOTOK) { + adios(EX_IOERR, drft, "unable to write"); + } cpydata(fdi, fdo, tmpfil, drft); close(fdi); close(fdo); unlink(tmpfil); context_save(); /* save the context file */ - return 0; + return EX_OK; }