X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/96a2a03a1473522669e8848959c3aa380cf3d4eb..1e03ea3338cc5ccd9ddf4feaaacfeda1998689cc:/uip/prompter.c diff --git a/uip/prompter.c b/uip/prompter.c index fc7b2c63..d91173f2 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -5,10 +5,19 @@ * complete copyright information. */ -#include +#include "h/mh.h" +#include "sbr/smatch.h" +#include "sbr/cpydata.h" +#include "sbr/m_atoi.h" +#include "sbr/context_save.h" +#include "sbr/ambigsw.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/error.h" #include -#include -#include +#include "h/signals.h" +#include "h/done.h" +#include "h/utils.h" #include "sbr/m_mktemp.h" #include @@ -40,8 +49,8 @@ DEFINE_SWITCH_ARRAY(PROMPTER, switches); static struct termios tio; -static int wtuser = 0; -static int sigint = 0; +static bool wtuser; +static bool sigint; static jmp_buf sigenv; /* @@ -56,8 +65,11 @@ static void intrser (int); int main (int argc, char **argv) { - int body = 1, prepend = 1, rapid = 0; - int doteof = 0, fdi, fdo, i, state; + bool body = true; + bool prepend = true; + bool rapid = false; + bool doteof = false; + int fdi, fdo, i, state; char *cp, *drft = NULL, *erasep = NULL; char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ]; char buffer[BUFSIZ]; @@ -66,7 +78,7 @@ main (int argc, char **argv) char *tmpfil; m_getfld_state_t gstate; - if (nmh_init(argv[0], 2)) { return 1; } + if (nmh_init(argv[0], true, false)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -78,7 +90,7 @@ main (int argc, char **argv) ambigsw (cp, switches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (buffer, sizeof(buffer), "%s [switches] file", @@ -91,39 +103,39 @@ main (int argc, char **argv) case ERASESW: if (!(erasep = *argp++) || *erasep == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case KILLSW: if (!(killp = *argp++) || *killp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case PREPSW: - prepend++; + prepend = true; continue; case NPREPSW: - prepend = 0; + prepend = false; continue; case RAPDSW: - rapid++; + rapid = true; continue; case NRAPDSW: - rapid = 0; + rapid = false; continue; case BODYSW: - body++; + body = true; continue; case NBODYSW: - body = 0; + body = false; continue; case DOTSW: - doteof++; + doteof = true; continue; case NDOTSW: - doteof = 0; + doteof = false; continue; } } else { @@ -132,12 +144,12 @@ main (int argc, char **argv) } if (!drft) - adios (NULL, "usage: %s [switches] file", invo_name); + die("usage: %s [switches] file", invo_name); if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open"); if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) { - adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + die("unable to create temporary file in %s", get_temp_dir()); } /* @@ -176,7 +188,7 @@ main (int argc, char **argv) tio.c_cc[VERASE] = save_erase; } - sigint = 0; + sigint = false; SIGNAL2 (SIGINT, intrser); /* @@ -279,7 +291,7 @@ abort: break; default: - adios (NULL, "skeleton is poorly formatted"); + die("skeleton is poorly formatted"); } break; } @@ -317,21 +329,21 @@ getln (char *buffer, int n) { int c; char *cp; - static int quoting = 0; + static bool quoting; *buffer = 0; switch (setjmp (sigenv)) { case OK: - wtuser = 1; + wtuser = true; break; case DONE: - wtuser = 0; + wtuser = false; return 0; default: - wtuser = 0; + wtuser = false; return NOTOK; } @@ -341,27 +353,27 @@ getln (char *buffer, int n) for (;;) { switch (c = getchar ()) { case EOF: - quoting = 0; + quoting = false; clearerr (stdin); longjmp (sigenv, DONE); case '\n': if (quoting) { *(cp - 1) = c; - quoting = 0; - wtuser = 0; + quoting = false; + wtuser = false; return 1; } *cp++ = c; *cp = 0; - wtuser = 0; + wtuser = false; return 0; default: if (c == QUOTE) { - quoting = 1; + quoting = true; } else { - quoting = 0; + quoting = false; } if (cp < buffer + n) *cp++ = c; @@ -378,7 +390,7 @@ intrser (int i) if (wtuser) longjmp (sigenv, NOTOK); - sigint++; + sigint = true; }