#include <h/mh.h>
#include <fcntl.h>
#include <h/signals.h>
-#include <errno.h>
-#include <signal.h>
#include <setjmp.h>
#include <termios.h>
# define CERASE '#'
#endif
-static struct swit switches[] = {
-#define ERASESW 0
- { "erase chr", 0 },
-#define KILLSW 1
- { "kill chr", 0 },
-#define PREPSW 2
- { "prepend", 0 },
-#define NPREPSW 3
- { "noprepend", 0 },
-#define RAPDSW 4
- { "rapid", 0 },
-#define NRAPDSW 5
- { "norapid", 0 },
-#define BODYSW 6
- { "body", -4 },
-#define NBODYSW 7
- { "nobody", -6 },
-#define DOTSW 8
- { "doteof", 0 },
-#define NDOTSW 9
- { "nodoteof", 0 },
-#define VERSIONSW 10
- { "version", 0 },
-#define HELPSW 11
- { "help", 0 },
- { NULL, 0 }
-};
+#define PROMPTER_SWITCHES \
+ X("erase chr", 0, ERASESW) \
+ X("kill chr", 0, KILLSW) \
+ X("prepend", 0, PREPSW) \
+ X("noprepend", 0, NPREPSW) \
+ X("rapid", 0, RAPDSW) \
+ X("norapid", 0, NRAPDSW) \
+ X("body", -4, BODYSW) \
+ X("nobody", -6, NBODYSW) \
+ X("doteof", 0, DOTSW) \
+ X("nodoteof", 0, NDOTSW) \
+ X("version", 0, VERSIONSW) \
+ X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(PROMPTER);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(PROMPTER, switches);
+#undef X
static struct termios tio;
char **arguments, **argp;
FILE *in, *out;
char *tfile = NULL;
+ m_getfld_state_t gstate = 0;
#ifdef LOCALE
setlocale(LC_ALL, "");
/*
* Loop through the lines of the draft skeleton.
*/
- for (state = FLD;;) {
+ for (;;) {
int fieldsz = sizeof field;
- switch (state = m_getfld (state, name, field, &fieldsz, in)) {
+ switch (state = m_getfld (&gstate, name, field, &fieldsz, in)) {
case FLD:
case FLDPLUS:
/*
fprintf (out, "%s:%s", name, field);
while (state == FLDPLUS) {
fieldsz = sizeof field;
- state = m_getfld (state, name, field, &fieldsz, in);
+ state = m_getfld (&gstate, name, field, &fieldsz, in);
printf ("%s", field);
fprintf (out, "%s", field);
}
printf ("%s", field);
} while (state == BODY &&
(fieldsz = sizeof field,
- state = m_getfld (state, name, field, &fieldsz, in)));
+ state = m_getfld (&gstate, name, field, &fieldsz, in)));
if (prepend || !body)
break;
else
}
break;
}
+ m_getfld_state_destroy (&gstate);
if (body)
printf ("--------\n");