head 1.9; access; symbols; locks; strict; comment @ * @; 1.9 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.8; 1.8 date 92.11.04.00.56.19; author jromine; state Exp; branches; next 1.7; 1.7 date 92.01.31.22.24.08; author jromine; state Exp; branches; next 1.6; 1.6 date 90.04.05.14.59.16; author sources; state Exp; branches; next 1.5; 1.5 date 90.03.17.09.49.14; author sources; state Exp; branches; next 1.4; 1.4 date 90.02.08.13.46.35; author sources; state Exp; branches; next 1.3; 1.3 date 90.02.06.13.27.36; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.05.15.02.29; author sources; state Exp; branches; next 1.1; 1.1 date 90.01.29.16.10.46; author sources; state Exp; branches; next ; desc @@ 1.9 log @endif sugar @ text @/* prompter.c - prompting editor front-end */ #ifndef lint static char ident[] = "@@(#)$Id: prompter.c,v 1.8 1992/11/04 00:56:19 jromine Exp jromine $"; #endif /* lint */ #include "../h/mh.h" #include #include #ifndef SYS5 #include #else /* SYS5 */ #include #include #ifndef NOIOCTLH #include #endif /* NOIOCTLH */ #endif /* SYS5 */ #ifdef BSD42 #include #endif /* BSD42 */ #include #ifdef LOCALE #include #endif #define QUOTE '\\' #ifndef CKILL #define CKILL '@@' #endif /* not CKILL */ #ifndef CERASE #define CERASE '#' #endif /* not CERASE */ /* */ 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 HELPSW 10 "help", 4, NULL, 0 }; /* */ extern int errno; #ifndef SYS5 #define ERASE sg.sg_erase #define KILL sg.sg_kill static struct sgttyb sg; #define INTR tc.t_intrc static struct tchars tc; #else /* SYS5 */ #define ERASE sg.c_cc[VERASE] #define KILL sg.c_cc[VKILL] #define INTR sg.c_cc[VINTR] static struct termio sg; #endif /* SYS5 */ static TYPESIG intrser (); static int wtuser = 0; static int sigint = 0; #ifdef BSD42 static jmp_buf sigenv; #endif /* BSD42 */ /* */ /* ARGSUSED */ main (argc, argv) int argc; char *argv[]; { int body = 1, prepend = 1, rapid = 0, doteof = 0, fdi, fdo, i, state; char *cp, *drft = NULL, *erasep = NULL, *killp = NULL, name[NAMESZ], field[BUFSIZ], buffer[BUFSIZ], tmpfil[BUFSIZ], **ap, *arguments[MAXARGS], **argp; FILE *in, *out; #ifdef LOCALE setlocale(LC_ALL, ""); #endif invo_name = r1bindex (argv[0], '/'); if ((cp = m_find (invo_name)) != NULL) { ap = brkstring (cp = getcpy (cp), " ", "\n"); ap = copyip (ap, arguments); } else ap = arguments; (void) copyip (argv + 1, ap); argp = arguments; /* */ while (cp = *argp++) if (*cp == '-') switch (smatch (++cp, switches)) { case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: adios (NULLCP, "-%s unknown", cp); case HELPSW: (void) sprintf (buffer, "%s [switches] file", invo_name); help (buffer, switches); done (1); case ERASESW: if (!(erasep = *argp++) || *erasep == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case KILLSW: if (!(killp = *argp++) || *killp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case PREPSW: prepend++; continue; case NPREPSW: prepend = 0; continue; case RAPDSW: rapid++; continue; case NRAPDSW: rapid = 0; continue; case BODYSW: body++; continue; case NBODYSW: body = 0; continue; case DOTSW: doteof++; continue; case NDOTSW: doteof = 0; continue; } else if (!drft) drft = cp; /* */ if (!drft) adios (NULLCP, "usage: %s [switches] file", invo_name); if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open"); (void) strcpy (tmpfil, m_tmpfil (invo_name)); if ((out = fopen (tmpfil, "w")) == NULL) adios (tmpfil, "unable to create"); (void) chmod (tmpfil, 0600); if (killp || erasep) { #ifndef SYS5 int serase, skill; #else /* SYS5 */ char serase, skill; #endif /* SYS5 */ #ifndef SYS5 (void) ioctl (0, TIOCGETP, (char *) &sg); (void) ioctl (0, TIOCGETC, (char *) &tc); #else /* SYS5 */ (void) ioctl(0, TCGETA, &sg); #endif /* SYS5 */ skill = KILL; serase = ERASE; KILL = killp ? chrcnv (killp) : skill; ERASE = erasep ? chrcnv (erasep) : serase; #ifndef SYS5 (void) ioctl (0, TIOCSETN, (char *) &sg); #else /* SYS5 */ (void) ioctl(0, TCSETAW, &sg); #endif /* SYS5 */ chrdsp ("erase", ERASE); chrdsp (", kill", KILL); chrdsp (", intr", INTR); (void) putchar ('\n'); (void) fflush (stdout); KILL = skill; ERASE = serase; } /* */ sigint = 0; setsig (SIGINT, intrser); for (state = FLD;;) { switch (state = m_getfld (state, name, field, sizeof field, in)) { case FLD: case FLDEOF: case FLDPLUS: for (cp = field; *cp; cp++) if (*cp != ' ' && *cp != '\t') break; if (*cp++ != '\n' || *cp != 0) { printf ("%s:%s", name, field); fprintf (out, "%s:%s", name, field); while (state == FLDPLUS) { state = m_getfld (state, name, field, sizeof field, in); printf ("%s", field); fprintf (out, "%s", field); } } else { printf ("%s: ", name); (void) fflush (stdout); i = getln (field, sizeof field); if (i == -1) { abort: ; if (killp || erasep) #ifndef SYS5 (void) ioctl (0, TIOCSETN, (char *) &sg); #else /* SYS5 */ (void) ioctl (0, TCSETA, &sg); #endif /* SYS5 */ (void) unlink (tmpfil); done (1); } if (i != 0 || (field[0] != '\n' && field[0] != 0)) { fprintf (out, "%s:", name); do { if (field[0] != ' ' && field[0] != '\t') (void) putc (' ', out); fprintf (out, "%s", field); } while (i == 1 && (i = getln (field, sizeof field)) >= 0); if (i == -1) goto abort; } } if (state == FLDEOF) {/* moby hack */ fprintf (out, "--------\n"); printf ("--------\n"); if (!body) break; goto no_body; } continue; case BODY: case BODYEOF: case FILEEOF: if (!body) break; fprintf (out, "--------\n"); if (field[0] == 0 || !prepend) printf ("--------\n"); if (field[0]) { if (prepend && body) { printf ("\n--------Enter initial text\n\n"); (void) fflush (stdout); for (;;) { (void) getln (buffer, sizeof buffer); if (doteof && buffer[0] == '.' && buffer[1] == '\n') break; if (buffer[0] == 0) break; fprintf (out, "%s", buffer); } } do { fprintf (out, "%s", field); if (!rapid && !sigint) printf ("%s", field); } while (state == BODY && (state = m_getfld (state, name, field, sizeof field, in))); if (prepend || !body) break; else printf ("\n--------Enter additional text\n\n"); } no_body: ; (void) fflush (stdout); for (;;) { (void) getln (field, sizeof field); if (doteof && field[0] == '.' && field[1] == '\n') break; if (field[0] == 0) break; fprintf (out, "%s", field); } break; default: adios (NULLCP, "skeleton is poorly formatted"); } break; } if (body) printf ("--------\n"); (void) fflush (stdout); (void) fclose (in); (void) fclose (out); (void) signal (SIGINT, SIG_IGN); /* */ if (killp || erasep) #ifndef SYS5 (void) ioctl (0, TIOCSETN, (char *) &sg); #else /* SYS5 */ (void) ioctl (0, TCSETAW, &sg); #endif /* SYS5 */ if ((fdi = open (tmpfil, 0)) == NOTOK) adios (tmpfil, "unable to re-open"); if ((fdo = creat (drft, m_gmprot ())) == NOTOK) adios (drft, "unable to write"); cpydata (fdi, fdo, tmpfil, drft); (void) close (fdi); (void) close (fdo); (void) unlink (tmpfil); m_update (); done (0); } /* */ getln (buffer, n) char *buffer; int n; { int c; char *cp; cp = buffer; *cp = 0; #ifndef BSD42 wtuser = 1; #else /* BSD42 */ switch (setjmp (sigenv)) { case OK: wtuser = 1; break; case DONE: wtuser = 0; return 0; default: wtuser = 0; return NOTOK; } #endif /* BSD42 */ for (;;) switch (c = getchar ()) { case EOF: #ifndef BSD42 wtuser = 0; return (errno != EINTR ? 0 : NOTOK); #else /* BSD42 */ clearerr (stdin); longjmp (sigenv, DONE); #endif /* BSD42 */ case '\n': if (cp[-1] == QUOTE) { cp[-1] = c; wtuser = 0; return 1; } *cp++ = c; *cp = 0; wtuser = 0; return 0; default: if (cp < buffer + n) *cp++ = c; *cp = 0; } } /* */ /* ARGSUSED */ static TYPESIG intrser (i) int i; { #ifndef BSD42 (void) signal (SIGINT, intrser); if (!wtuser) sigint++; #else /* BSD42 */ if (wtuser) longjmp (sigenv, NOTOK); sigint++; #endif /* BSD42 */ } chrcnv (cp) register char *cp; { return (*cp != QUOTE ? *cp : m_atoi (++cp)); } chrdsp (s, c) char *s, c; { printf ("%s ", s); if (c < ' ' || c == 0177) printf ("^%c", c ^ 0100); else printf ("%c", c); } @ 1.8 log @LOCALE TYPESIG @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: prompter.c,v 1.7 1992/01/31 22:24:08 jromine Exp jromine $"; #endif lint d11 1 a11 1 #else SYS5 d16 2 a17 2 #endif NOIOCTLH #endif SYS5 d20 1 a20 1 #endif BSD42 d30 1 a30 1 #endif not CKILL d33 1 a33 1 #endif not CERASE d81 1 a81 1 #else SYS5 d86 1 a86 1 #endif SYS5 d96 1 a96 1 #endif BSD42 d212 1 a212 1 #else SYS5 d215 1 a215 1 #endif SYS5 d220 1 a220 1 #else SYS5 d222 1 a222 1 #endif SYS5 d229 1 a229 1 #else SYS5 d231 1 a231 1 #endif SYS5 d275 1 a275 1 #else SYS5 d277 1 a277 1 #endif SYS5 d367 1 a367 1 #else SYS5 d369 1 a369 1 #endif SYS5 d399 1 a399 1 #else BSD42 d413 1 a413 1 #endif BSD42 d421 1 a421 1 #else BSD42 d424 1 a424 1 #endif BSD42 d455 1 a455 1 #else BSD42 d459 1 a459 1 #endif BSD42 @ 1.7 log @kerberos @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: prompter.c,v 1.6 1990/04/05 14:59:16 sources Exp jromine $"; d22 3 d89 1 a89 1 static int intrser (); d127 3 d448 1 a448 1 static int intrser (i) @ 1.6 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d63 1 a63 1 NULL, NULL d250 1 a250 1 if (*cp++ != '\n' || *cp != NULL) { d275 1 a275 1 if (i != 0 || (field[0] != '\n' && field[0] != NULL)) { d302 1 a302 1 if (field[0] == NULL || !prepend) d312 1 a312 1 if (buffer[0] == NULL) d335 1 a335 1 if (field[0] == NULL) d389 1 a389 1 *cp = NULL; d427 1 a427 1 *cp = NULL; d434 1 a434 1 *cp = NULL; @ 1.5 log @fix for -nobody from jeff honig @ text @d2 3 @ 1.4 log @let "." terminate prompter. @ text @d296 2 @ 1.3 log @ANSI Compilance @ text @d52 6 a57 1 #define HELPSW 8 d103 1 d175 7 d305 2 d328 2 @ 1.2 log @*** empty log message *** @ text @d78 1 a78 1 int intrser (); @ 1.1 log @Initial revision @ text @d11 1 d13 1 @