9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.56.19; author jromine; state Exp;
19 date 92.01.31.22.24.08; author jromine; state Exp;
24 date 90.04.05.14.59.16; author sources; state Exp;
29 date 90.03.17.09.49.14; author sources; state Exp;
34 date 90.02.08.13.46.35; author sources; state Exp;
39 date 90.02.06.13.27.36; author sources; state Exp;
44 date 90.02.05.15.02.29; author sources; state Exp;
49 date 90.01.29.16.10.46; author sources; state Exp;
63 @/* prompter.c - prompting editor front-end */
65 static char ident[] = "@@(#)$Id: prompter.c,v 1.8 1992/11/04 00:56:19 jromine Exp jromine $";
74 #include <sys/types.h>
77 #include <sys/ioctl.h>
92 #endif /* not CKILL */
95 #endif /* not CERASE */
99 static struct swit switches[] = {
137 #define ERASE sg.sg_erase
138 #define KILL sg.sg_kill
139 static struct sgttyb sg;
141 #define INTR tc.t_intrc
142 static struct tchars tc;
144 #define ERASE sg.c_cc[VERASE]
145 #define KILL sg.c_cc[VKILL]
146 #define INTR sg.c_cc[VINTR]
147 static struct termio sg;
151 static TYPESIG intrser ();
153 static int wtuser = 0;
154 static int sigint = 0;
157 static jmp_buf sigenv;
190 setlocale(LC_ALL, "");
192 invo_name = r1bindex (argv[0], '/');
193 if ((cp = m_find (invo_name)) != NULL) {
194 ap = brkstring (cp = getcpy (cp), " ", "\n");
195 ap = copyip (ap, arguments);
199 (void) copyip (argv + 1, ap);
206 switch (smatch (++cp, switches)) {
208 ambigsw (cp, switches);
211 adios (NULLCP, "-%s unknown", cp);
213 (void) sprintf (buffer, "%s [switches] file", invo_name);
214 help (buffer, switches);
218 if (!(erasep = *argp++) || *erasep == '-')
219 adios (NULLCP, "missing argument to %s", argp[-2]);
222 if (!(killp = *argp++) || *killp == '-')
223 adios (NULLCP, "missing argument to %s", argp[-2]);
261 adios (NULLCP, "usage: %s [switches] file", invo_name);
262 if ((in = fopen (drft, "r")) == NULL)
263 adios (drft, "unable to open");
265 (void) strcpy (tmpfil, m_tmpfil (invo_name));
266 if ((out = fopen (tmpfil, "w")) == NULL)
267 adios (tmpfil, "unable to create");
268 (void) chmod (tmpfil, 0600);
270 if (killp || erasep) {
280 (void) ioctl (0, TIOCGETP, (char *) &sg);
281 (void) ioctl (0, TIOCGETC, (char *) &tc);
283 (void) ioctl(0, TCGETA, &sg);
287 KILL = killp ? chrcnv (killp) : skill;
288 ERASE = erasep ? chrcnv (erasep) : serase;
290 (void) ioctl (0, TIOCSETN, (char *) &sg);
292 (void) ioctl(0, TCSETAW, &sg);
295 chrdsp ("erase", ERASE);
296 chrdsp (", kill", KILL);
297 chrdsp (", intr", INTR);
298 (void) putchar ('\n');
299 (void) fflush (stdout);
308 setsig (SIGINT, intrser);
310 for (state = FLD;;) {
311 switch (state = m_getfld (state, name, field, sizeof field, in)) {
315 for (cp = field; *cp; cp++)
316 if (*cp != ' ' && *cp != '\t')
318 if (*cp++ != '\n' || *cp != 0) {
319 printf ("%s:%s", name, field);
320 fprintf (out, "%s:%s", name, field);
321 while (state == FLDPLUS) {
323 m_getfld (state, name, field, sizeof field, in);
324 printf ("%s", field);
325 fprintf (out, "%s", field);
329 printf ("%s: ", name);
330 (void) fflush (stdout);
331 i = getln (field, sizeof field);
336 (void) ioctl (0, TIOCSETN, (char *) &sg);
338 (void) ioctl (0, TCSETA, &sg);
340 (void) unlink (tmpfil);
343 if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
344 fprintf (out, "%s:", name);
346 if (field[0] != ' ' && field[0] != '\t')
347 (void) putc (' ', out);
348 fprintf (out, "%s", field);
350 && (i = getln (field, sizeof field)) >= 0);
355 if (state == FLDEOF) {/* moby hack */
356 fprintf (out, "--------\n");
357 printf ("--------\n");
369 fprintf (out, "--------\n");
370 if (field[0] == 0 || !prepend)
371 printf ("--------\n");
373 if (prepend && body) {
374 printf ("\n--------Enter initial text\n\n");
375 (void) fflush (stdout);
377 (void) getln (buffer, sizeof buffer);
378 if (doteof && buffer[0] == '.' && buffer[1] == '\n')
382 fprintf (out, "%s", buffer);
387 fprintf (out, "%s", field);
388 if (!rapid && !sigint)
389 printf ("%s", field);
390 } while (state == BODY &&
391 (state = m_getfld (state, name, field, sizeof field, in)));
392 if (prepend || !body)
395 printf ("\n--------Enter additional text\n\n");
398 (void) fflush (stdout);
400 (void) getln (field, sizeof field);
401 if (doteof && field[0] == '.' && field[1] == '\n')
405 fprintf (out, "%s", field);
410 adios (NULLCP, "skeleton is poorly formatted");
416 printf ("--------\n");
417 (void) fflush (stdout);
422 (void) signal (SIGINT, SIG_IGN);
428 (void) ioctl (0, TIOCSETN, (char *) &sg);
430 (void) ioctl (0, TCSETAW, &sg);
433 if ((fdi = open (tmpfil, 0)) == NOTOK)
434 adios (tmpfil, "unable to re-open");
435 if ((fdo = creat (drft, m_gmprot ())) == NOTOK)
436 adios (drft, "unable to write");
437 cpydata (fdi, fdo, tmpfil, drft);
440 (void) unlink (tmpfil);
462 switch (setjmp (sigenv)) {
478 switch (c = getchar ()) {
482 return (errno != EINTR ? 0 : NOTOK);
485 longjmp (sigenv, DONE);
489 if (cp[-1] == QUOTE) {
510 static TYPESIG intrser (i)
514 (void) signal (SIGINT, intrser);
519 longjmp (sigenv, NOTOK);
528 return (*cp != QUOTE ? *cp : m_atoi (++cp));
537 if (c < ' ' || c == 0177)
538 printf ("^%c", c ^ 0100);
553 static char ident[] = "@@(#)$Id: prompter.c,v 1.7 1992/01/31 22:24:08 jromine Exp jromine $";
638 static char ident[] = "@@(#)$Id: prompter.c,v 1.6 1990/04/05 14:59:16 sources Exp jromine $";
642 static int intrser ();
646 static int intrser (i)
657 static char ident[] = "@@(#)$Id:$";
663 if (*cp++ != '\n' || *cp != NULL) {
666 if (i != 0 || (field[0] != '\n' && field[0] != NULL)) {
669 if (field[0] == NULL || !prepend)
672 if (buffer[0] == NULL)
675 if (field[0] == NULL)
690 @fix for -nobody from jeff honig
699 @let "." terminate prompter.
723 @*** empty log message ***