* complete copyright information.
*/
-#include <h/mh.h>
+#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 <fcntl.h>
-#include <h/signals.h>
+#include "h/signals.h"
#include "h/done.h"
-#include <h/utils.h>
+#include "h/utils.h"
#include "sbr/m_mktemp.h"
#include <setjmp.h>
static struct termios tio;
-static int wtuser = 0;
-static int sigint = 0;
+static bool wtuser;
+static bool sigint;
static jmp_buf sigenv;
/*
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];
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;
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",
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 {
}
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());
}
/*
tio.c_cc[VERASE] = save_erase;
}
- sigint = 0;
+ sigint = false;
SIGNAL2 (SIGINT, intrser);
/*
break;
default:
- adios (NULL, "skeleton is poorly formatted");
+ die("skeleton is poorly formatted");
}
break;
}
{
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;
}
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;
if (wtuser)
longjmp (sigenv, NOTOK);
- sigint++;
+ sigint = true;
}