From 50bf5781f9284b7147e19f132d2557df8119860b Mon Sep 17 00:00:00 2001 From: Gunnar Ritter Date: Thu, 17 Feb 2005 16:03:03 +0000 Subject: [PATCH] * The 'source' ex command now works if command input comes from a pipe or regular file. --- Changes | 2 ++ ex.h | 6 +++--- ex_get.c | 4 ++-- ex_io.c | 25 +++++++++++++++++++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index 850db08..3c85401 100644 --- a/Changes +++ b/Changes @@ -35,6 +35,8 @@ Release ... the command now succeeds and prints a "[New file]" message. * If standard output is not a terminal, no '\r' is written at the end of printed lines anymore. +* The 'source' ex command now works if command input comes from a pipe or + regular file. Release 1/19/05 * The last release erroneously made 'X' work like 'x' in visual mode. It now diff --git a/ex.h b/ex.h index 5aa2f97..078b198 100644 --- a/ex.h +++ b/ex.h @@ -72,7 +72,7 @@ * * from ex.h 7.7.1.1 (Berkeley) 8/12/86 * - * @(#)ex.h 1.51 (gritter) 2/15/05 + * @(#)ex.h 1.52 (gritter) 2/17/05 */ /* @@ -398,7 +398,7 @@ var bool inopen; /* Inside open or visual */ var char *input; /* Current position in cmd line input buffer */ var bool intty; /* Input is a tty */ var short io; /* General i/o unit (auto-closed on error!) */ -extern short lastc; /* Last character ret'd from cmd input */ +extern int lastc; /* Last character ret'd from cmd input */ var bool laste; /* Last command was an "e" (or "rec") */ var char lastmac; /* Last macro called for ** */ var char lasttag[TAGSIZE]; /* Last argument to a tag command */ @@ -417,7 +417,7 @@ var shand oldxfsz; /* Previous SIGXFSZ handler */ var short oprompt; /* Saved during source */ extern unsigned short ospeed; /* Output speed (from gtty) */ var int otchng; /* Backup tchng to find changes in macros */ -var short peekc; /* Peek ahead character (cmd mode input) */ +var int peekc; /* Peek ahead character (cmd mode input) */ var char *pkill[2]; /* Trim for put with ragged (LISP) delete */ var bool pfast; /* Have stty -nl'ed to go faster */ var pid_t pid; /* Process id of child */ diff --git a/ex_get.c b/ex_get.c index 8645748..f2325b9 100644 --- a/ex_get.c +++ b/ex_get.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_get.c 1.16 (gritter) 11/24/04"; +static char sccsid[] = "@(#)ex_get.c 1.17 (gritter) 2/17/05"; #endif #endif @@ -88,7 +88,7 @@ static char sccsid[] = "@(#)ex_get.c 1.16 (gritter) 11/24/04"; * we have different flavors of routines which do/don't return such. */ static bool junkbs; -short lastc = '\n'; +int lastc = '\n'; void ignchar(void) diff --git a/ex_io.c b/ex_io.c index 4d9c3db..8769a9d 100644 --- a/ex_io.c +++ b/ex_io.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_io.c 1.39 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_io.c 1.40 (gritter) 2/17/05"; #endif #endif @@ -964,14 +964,19 @@ source(char *fil, bool okfail) { JMP_BUF osetexit; register int saveinp, ointty, oerrno; - char *saveglobp; - short savepeekc; + char *saveglobp, *saveinput; + char saveinline[BUFSIZ]; + int savepeekc, savelastc; signal(SIGINT, SIG_IGN); saveinp = dup(0); savepeekc = peekc; + savelastc = lastc; saveglobp = globp; - peekc = 0; globp = 0; + saveinput = input; + if (input) + strcpy(saveinline, input); + peekc = 0; lastc = 0; globp = 0; input = 0; if (saveinp < 0) error(catgets(catd, 1, 119, "Too many nested sources")); if (slevel <= 0) @@ -982,6 +987,10 @@ source(char *fil, bool okfail) setrupt(); dup(saveinp); close(saveinp); + input = saveinput; + if (input) + strcpy(input, saveinline); + lastc = savelastc; errno = oerrno; if (!okfail) filioerr(fil); @@ -1000,6 +1009,10 @@ source(char *fil, bool okfail) close(0); dup(saveinp); close(saveinp); + input = saveinput; + if (input) + strcpy(input, saveinline); + lastc = savelastc; slevel--; resexit(osetexit); reset(); @@ -1010,7 +1023,11 @@ source(char *fil, bool okfail) dup(saveinp); close(saveinp); globp = saveglobp; + input = saveinput; + if (input) + strcpy(input, saveinline); peekc = savepeekc; + lastc = savelastc; slevel--; resexit(osetexit); }