* The 'source' ex command now works if command input comes from a pipe or

regular file.
This commit is contained in:
Gunnar Ritter 2005-02-17 16:03:03 +00:00
parent 124bd15ee6
commit 50bf5781f9
4 changed files with 28 additions and 9 deletions

View File

@ -35,6 +35,8 @@ Release ...
the command now succeeds and prints a "[New file]" message. 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 * If standard output is not a terminal, no '\r' is written at the end of
printed lines anymore. printed lines anymore.
* The 'source' ex command now works if command input comes from a pipe or
regular file.
Release 1/19/05 Release 1/19/05
* The last release erroneously made 'X' work like 'x' in visual mode. It now * The last release erroneously made 'X' work like 'x' in visual mode. It now

6
ex.h
View File

@ -72,7 +72,7 @@
* *
* from ex.h 7.7.1.1 (Berkeley) 8/12/86 * 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 char *input; /* Current position in cmd line input buffer */
var bool intty; /* Input is a tty */ var bool intty; /* Input is a tty */
var short io; /* General i/o unit (auto-closed on error!) */ 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 bool laste; /* Last command was an "e" (or "rec") */
var char lastmac; /* Last macro called for ** */ var char lastmac; /* Last macro called for ** */
var char lasttag[TAGSIZE]; /* Last argument to a tag command */ 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 */ var short oprompt; /* Saved during source */
extern unsigned short ospeed; /* Output speed (from gtty) */ extern unsigned short ospeed; /* Output speed (from gtty) */
var int otchng; /* Backup tchng to find changes in macros */ 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 char *pkill[2]; /* Trim for put with ragged (LISP) delete */
var bool pfast; /* Have stty -nl'ed to go faster */ var bool pfast; /* Have stty -nl'ed to go faster */
var pid_t pid; /* Process id of child */ var pid_t pid; /* Process id of child */

View File

@ -73,7 +73,7 @@
#ifndef lint #ifndef lint
#ifdef DOSCCS #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
#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. * we have different flavors of routines which do/don't return such.
*/ */
static bool junkbs; static bool junkbs;
short lastc = '\n'; int lastc = '\n';
void void
ignchar(void) ignchar(void)

25
ex_io.c
View File

@ -73,7 +73,7 @@
#ifndef lint #ifndef lint
#ifdef DOSCCS #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
#endif #endif
@ -964,14 +964,19 @@ source(char *fil, bool okfail)
{ {
JMP_BUF osetexit; JMP_BUF osetexit;
register int saveinp, ointty, oerrno; register int saveinp, ointty, oerrno;
char *saveglobp; char *saveglobp, *saveinput;
short savepeekc; char saveinline[BUFSIZ];
int savepeekc, savelastc;
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
saveinp = dup(0); saveinp = dup(0);
savepeekc = peekc; savepeekc = peekc;
savelastc = lastc;
saveglobp = globp; saveglobp = globp;
peekc = 0; globp = 0; saveinput = input;
if (input)
strcpy(saveinline, input);
peekc = 0; lastc = 0; globp = 0; input = 0;
if (saveinp < 0) if (saveinp < 0)
error(catgets(catd, 1, 119, "Too many nested sources")); error(catgets(catd, 1, 119, "Too many nested sources"));
if (slevel <= 0) if (slevel <= 0)
@ -982,6 +987,10 @@ source(char *fil, bool okfail)
setrupt(); setrupt();
dup(saveinp); dup(saveinp);
close(saveinp); close(saveinp);
input = saveinput;
if (input)
strcpy(input, saveinline);
lastc = savelastc;
errno = oerrno; errno = oerrno;
if (!okfail) if (!okfail)
filioerr(fil); filioerr(fil);
@ -1000,6 +1009,10 @@ source(char *fil, bool okfail)
close(0); close(0);
dup(saveinp); dup(saveinp);
close(saveinp); close(saveinp);
input = saveinput;
if (input)
strcpy(input, saveinline);
lastc = savelastc;
slevel--; slevel--;
resexit(osetexit); resexit(osetexit);
reset(); reset();
@ -1010,7 +1023,11 @@ source(char *fil, bool okfail)
dup(saveinp); dup(saveinp);
close(saveinp); close(saveinp);
globp = saveglobp; globp = saveglobp;
input = saveinput;
if (input)
strcpy(input, saveinline);
peekc = savepeekc; peekc = savepeekc;
lastc = savelastc;
slevel--; slevel--;
resexit(osetexit); resexit(osetexit);
} }