-
-/*
- * prompter.c -- simple prompting editor front-end
+/* prompter.c -- simple prompting editor front-end
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
#include <h/mh.h>
#include <fcntl.h>
#include <h/signals.h>
+#include "h/done.h"
+#include <h/utils.h>
+#include "sbr/m_mktemp.h"
#include <setjmp.h>
#include <termios.h>
#define QUOTE '\\'
-#ifndef CKILL
-# define CKILL '@'
-#endif
-
-#ifndef CERASE
-# define CERASE '#'
-#endif
-
#define PROMPTER_SWITCHES \
X("erase chr", 0, ERASESW) \
X("kill chr", 0, KILLSW) \
DEFINE_SWITCH_ARRAY(PROMPTER, switches);
#undef X
-
static struct termios tio;
-#define ERASE tio.c_cc[VERASE]
-#define KILL tio.c_cc[VKILL]
-#define INTR tio.c_cc[VINTR]
static int wtuser = 0;
static int sigint = 0;
/*
* prototypes
*/
-int getln (char *, int);
+static int getln (char *, int);
static int chrcnv (char *);
static void chrdsp (char *, char);
static void intrser (int);
int body = 1, prepend = 1, rapid = 0;
int doteof = 0, fdi, fdo, i, state;
char *cp, *drft = NULL, *erasep = NULL;
- char *killp = NULL, name[NAMESZ], field[BUFSIZ];
+ char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ];
char buffer[BUFSIZ];
char **arguments, **argp;
FILE *in, *out;
char *tmpfil;
- m_getfld_state_t gstate = 0;
+ m_getfld_state_t gstate;
if (nmh_init(argv[0], 2)) { return 1; }
tcgetattr(0, &tio);
/* save original kill, erase character for later */
- save_kill = KILL;
- save_erase = ERASE;
+ save_kill = tio.c_cc[VKILL];
+ save_erase = tio.c_cc[VERASE];
/* set new kill, erase character in terminal structure */
- KILL = killp ? chrcnv (killp) : save_kill;
- ERASE = erasep ? chrcnv (erasep) : save_erase;
+ tio.c_cc[VKILL] = killp ? chrcnv (killp) : save_kill;
+ tio.c_cc[VERASE] = erasep ? chrcnv (erasep) : save_erase;
/* set the new terminal attributes */
tcsetattr(0, TCSADRAIN, &tio);
/* print out new kill erase characters */
- chrdsp ("erase", ERASE);
- chrdsp (", kill", KILL);
- chrdsp (", intr", INTR);
+ chrdsp ("erase", tio.c_cc[VERASE]);
+ chrdsp (", kill", tio.c_cc[VKILL]);
+ chrdsp (", intr", tio.c_cc[VINTR]);
putchar ('\n');
fflush (stdout);
* setup in terminal structure so we can easily
* restore it upon exit.
*/
- KILL = save_kill;
- ERASE = save_erase;
+ tio.c_cc[VKILL] = save_kill;
+ tio.c_cc[VERASE] = save_erase;
}
sigint = 0;
/*
* Loop through the lines of the draft skeleton.
*/
+ gstate = m_getfld_state_init(in);
for (;;) {
int fieldsz = sizeof field;
- switch (state = m_getfld (&gstate, name, field, &fieldsz, in)) {
+ switch (state = m_getfld2(&gstate, name, field, &fieldsz)) {
case FLD:
case FLDPLUS:
/*
fprintf (out, "%s:%s", name, field);
while (state == FLDPLUS) {
fieldsz = sizeof field;
- state = m_getfld (&gstate, name, field, &fieldsz, in);
+ state = m_getfld2(&gstate, name, field, &fieldsz);
fputs(field, stdout);
fputs(field, out);
}
puts("--------");
if (field[0]) {
if (prepend && body) {
- printf ("\n--------Enter initial text\n\n");
+ puts("\n--------Enter initial text\n");
fflush (stdout);
for (;;) {
getln (buffer, sizeof(buffer));
fputs(field, stdout);
} while (state == BODY &&
(fieldsz = sizeof field,
- state = m_getfld (&gstate, name, field, &fieldsz, in)));
+ state = m_getfld2(&gstate, name, field, &fieldsz)));
if (prepend || !body)
break;
- else
- printf ("\n--------Enter additional text\n\n");
+ puts("\n--------Enter additional text\n");
}
fflush (stdout);
}
-int
+static int
getln (char *buffer, int n)
{
int c;
static int
chrcnv (char *cp)
{
- return (*cp != QUOTE ? *cp : m_atoi (++cp));
+ return *cp != QUOTE ? *cp : m_atoi(++cp);
}