From aada6fd740fbed39de68ec1fb2f9b3421715ac39 Mon Sep 17 00:00:00 2001 From: Gunnar Ritter Date: Thu, 17 Feb 2005 17:00:56 +0000 Subject: [PATCH] * Ex does not exit on errors immediately anymore if standard input is not a terminal but a pipe or regular file. --- Changes | 6 ++++-- ex.h | 3 ++- ex_cmds.c | 10 +++++++--- ex_cmds2.c | 7 ++++--- ex_cmdsub.c | 6 +++++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index 3c85401..64af4b4 100644 --- a/Changes +++ b/Changes @@ -17,8 +17,8 @@ Release ... * The argument to the -w option is correctly recognized now. * If the SHELL environment variable is set to the empty string, it is now ignored. -* A non-null exit status is now returned if a file could not be opened, or - if an invalid address is given for a command. +* A non-null exit status is now returned if a file could not be opened, if + an invalid address is given for a command, or if a tag is not found. * If the match for a substitution is of length zero, a line overflow is now avoided when compiled with the 'UNIX(R) Regular Expression Library'. * When moving left while the cursor is positioned over a multicolumn @@ -37,6 +37,8 @@ Release ... printed lines anymore. * The 'source' ex command now works if command input comes from a pipe or regular file. +* Ex does not exit on errors immediately anymore if standard input is not + a terminal but 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 078b198..51ae267 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.52 (gritter) 2/17/05 + * @(#)ex.h 1.53 (gritter) 2/17/05 */ /* @@ -438,6 +438,7 @@ var JMP_BUF vreslab; /* For error throws to a visual catch */ var bool writing; /* 1 if in middle of a file write */ var int xchng; /* Suppresses multiple "No writes" in !cmd */ var int failed; /* exit with a non-zero status */ +var int exitoneof; /* exit command loop on EOF */ /* * Macros diff --git a/ex_cmds.c b/ex_cmds.c index c7491a5..784134c 100644 --- a/ex_cmds.c +++ b/ex_cmds.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_cmds.c 1.18 (gritter) 1/2/05"; +static char sccsid[] = "@(#)ex_cmds.c 1.20 (gritter) 2/17/05"; #endif #endif @@ -97,7 +97,7 @@ int poffset; * processing and call command routines to do the real work. */ void -commands(int noprompt, int exitoneof) +commands(int noprompt, int _exitoneof) { register line *addr; register int c; @@ -110,6 +110,7 @@ commands(int noprompt, int exitoneof) resetflav(); nochng(); for (;;) { + exitoneof = _exitoneof; /* * If dot at last command * ended up at zero, advance to one if there is a such. @@ -834,8 +835,11 @@ wq: c = getchar(); if (c=='\n' || c=='\r') ungetchar(c); - if (any(c, "@*\n\r")) + if (any(c, "@*\n\r")) { c = lastmac; + if (c == 0) + failed = 1; + } if (isupper(c)) c = tolower(c); if (!islower(c)) diff --git a/ex_cmds2.c b/ex_cmds2.c index 1b0253b..8d822bd 100644 --- a/ex_cmds2.c +++ b/ex_cmds2.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_cmds2.c 1.17 (gritter) 12/1/04"; +static char sccsid[] = "@(#)ex_cmds2.c 1.18 (gritter) 2/17/05"; #endif #endif @@ -157,7 +157,7 @@ error0(void) dingdong(); return; } - if (input) { + if (input && exitoneof) { input = strend(input) - 1; if (*input == '\n') setlastchar('\n'); @@ -218,7 +218,8 @@ error1(char *str) putNFL(); if (die) exitex(1); - lseek(0, (off_t)0, SEEK_END); + if (exitoneof) + lseek(0, (off_t)0, SEEK_END); if (inglobal) setlastchar('\n'); while (lastchar() != '\n' && lastchar() != EOF) diff --git a/ex_cmdsub.c b/ex_cmdsub.c index aa94e0e..11fadb5 100644 --- a/ex_cmdsub.c +++ b/ex_cmdsub.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_cmdsub.c 1.27 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_cmdsub.c 1.28 (gritter) 2/17/05"; #endif #endif @@ -561,6 +561,7 @@ tagfind(bool quick) char *fn, *fne; struct stat sbuf; char *savefirstpat = NULL; + int ofailed; #ifdef FASTTAG int ft_iof; char ft_iofbuf[MAXBSIZE]; @@ -570,6 +571,8 @@ tagfind(bool quick) omagic = value(MAGIC); owrapscan = value(WRAPSCAN); + ofailed = failed; + failed = 1; if (!skipend()) { register char *lp = lasttag; @@ -752,6 +755,7 @@ badtags: if (tflag) value(WRAPSCAN) = 1; commands(1, 1); + failed = ofailed; peekc = d; globp = oglobp; value(MAGIC) = omagic;