X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0a032eea07f6d77ac6ea4d5a39c9491c34358058..8699f1cc:/uip/prompter.c?ds=inline diff --git a/uip/prompter.c b/uip/prompter.c index 03b3dc09..3a51dbe3 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -1,5 +1,4 @@ -/* - * 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 @@ -9,20 +8,15 @@ #include #include #include +#include "h/done.h" +#include +#include "sbr/m_mktemp.h" #include #include #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) \ @@ -45,11 +39,7 @@ DEFINE_SWITCH_ENUM(PROMPTER); 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; @@ -58,7 +48,7 @@ static jmp_buf sigenv; /* * prototypes */ -int getln (char *, int); +static int getln (char *, int); static int chrcnv (char *); static void chrdsp (char *, char); static void intrser (int); @@ -70,12 +60,12 @@ main (int argc, char **argv) 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; } @@ -161,20 +151,20 @@ main (int argc, char **argv) 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); @@ -183,8 +173,8 @@ main (int argc, char **argv) * 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; @@ -193,9 +183,10 @@ main (int argc, char **argv) /* * 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: /* @@ -212,7 +203,7 @@ main (int argc, char **argv) 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); } @@ -253,7 +244,7 @@ abort: 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)); @@ -271,11 +262,10 @@ abort: 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); @@ -323,7 +313,7 @@ abort: } -int +static int getln (char *buffer, int n) { int c; @@ -396,7 +386,7 @@ intrser (int i) static int chrcnv (char *cp) { - return (*cp != QUOTE ? *cp : m_atoi (++cp)); + return *cp != QUOTE ? *cp : m_atoi(++cp); }