X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/2b83f27e1980a6c5de752bd55c0ff76f53ec15f6..ec173fd2c:/uip/prompter.c?ds=sidebyside diff --git a/uip/prompter.c b/uip/prompter.c index 3a51dbe3..de8b67a8 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -5,11 +5,22 @@ * complete copyright information. */ -#include +#include "h/mh.h" +#include "sbr/m_gmprot.h" +#include "sbr/m_getfld.h" +#include "sbr/getarguments.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 "h/signals.h" #include "h/done.h" -#include +#include "h/utils.h" #include "sbr/m_mktemp.h" #include @@ -41,8 +52,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; /* @@ -57,8 +68,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]; @@ -67,7 +81,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; @@ -79,7 +93,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", @@ -92,39 +106,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 { @@ -133,12 +147,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()); } /* @@ -177,7 +191,7 @@ main (int argc, char **argv) tio.c_cc[VERASE] = save_erase; } - sigint = 0; + sigint = false; SIGNAL2 (SIGINT, intrser); /* @@ -280,7 +294,7 @@ abort: break; default: - adios (NULL, "skeleton is poorly formatted"); + die("skeleton is poorly formatted"); } break; } @@ -318,21 +332,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; } @@ -342,27 +356,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; @@ -379,7 +393,7 @@ intrser (int i) if (wtuser) longjmp (sigenv, NOTOK); - sigint++; + sigint = true; }