Commit 6dbf9acb authored by Brooks Davis's avatar Brooks Davis
Browse files

Update vendor/tcsh to git 83c5be0:

Upstream changes:
5. PR/113: Sobomax: avoid infinite loops for -c commands when stdout is
   not a tty.
4. Avoid infinite loops during history loads when merging, print a better
   error for errors during history load.
3. PR/88: Preserve empty arguments in :q
2. PR/94: Small apple issues (SAVESIGVEC, HOSTTYPE)
1. PR/81: Fix range matching issue where we were comparing with the
   range character instead of the start of range. [l-z]* would match foo

Reported by:	sobomax
parent 320f2946
5. PR/113: Sobomax: avoid infinite loops for -c commands when stdout is
not a tty.
4. Avoid infinite loops during history loads when merging, print a better
error for errors during history load.
3. PR/88: Preserve empty arguments in :q
2. PR/94: Small apple issues (SAVESIGVEC, HOSTTYPE)
1. PR/81: Fix range matching issue where we were comparing with the
range character instead of the start of range. [l-z]* would match foo
12. V6.21.00 - 20190508
11. Abort history loading on words and lines too long
https://bugzilla.redhat.com/show_bug.cgi?id=1598502
......
# Tcsh
# TCSH
*C shell with file name completion and command line editing*
......@@ -14,10 +14,10 @@ PLEASE file any bug reports, fixes, and code for new features at:
> https://bugs.astron.com/
Comments, questions, etc. (even flames) are welcome via email to
the Tcsh Bugs mailing list:
the tcsh mailing list:
> tcsh-bugs@astron.com
> https://mailman.astron.com/
> tcsh@astron.com
> https://mailman.astron.com/mailman/listinfo/tcsh
[![Build Status][status]][travis]
......
......@@ -100,7 +100,7 @@ static int Lstat (const char *, struct stat *);
static int Stat (const char *, struct stat *sb);
static Char *Strchr (Char *, int);
#ifdef DEBUG
static void qprintf (const Char *);
static void qprintf (const char *, const Char *);
#endif
#define DOLLAR '$'
......@@ -254,19 +254,20 @@ Strchr(Char *str, int ch)
#ifdef DEBUG
static void
qprintf(const Char *s)
qprintf(const char *pre, const Char *s)
{
const Char *p;
xprintf("%s", pre);
for (p = s; *p; p++)
printf("%c", *p & 0xff);
printf("\n");
xprintf("%c", *p & 0xff);
xprintf("\n%s", pre);
for (p = s; *p; p++)
printf("%c", *p & M_PROTECT ? '"' : ' ');
printf("\n");
xprintf("%c", *p & M_PROTECT ? '"' : ' ');
xprintf("\n%s", pre);
for (p = s; *p; p++)
printf("%c", *p & M_META ? '_' : ' ');
printf("\n");
xprintf("%c", *p & M_META ? '_' : ' ');
xprintf("\n");
}
#endif /* DEBUG */
......@@ -410,7 +411,7 @@ glob(const char *pattern, int flags, int (*errfunc) (const char *, int),
}
*bufnext = EOS;
#ifdef DEBUG
qprintf(patbuf);
qprintf("patbuf=", patbuf);
#endif
if ((err = glob1(patbuf, pglob, no_match)) != 0) {
......@@ -707,7 +708,7 @@ match(const char *name, const Char *pat, const Char *patend, int m_not)
while (pat < patend || *name) {
size_t lwk, pwk;
__Char wc, wk;
__Char wc, wk, wc1;
c = *pat; /* Only for M_MASK bits */
if (*name == EOS)
......@@ -742,18 +743,20 @@ match(const char *name, const Char *pat, const Char *patend, int m_not)
pat += pwk;
pwk = One_Char_mbtowc(&wc, pat, MB_LEN_MAX);
}
wc1 = wc;
while ((*pat & M_MASK) != M_END) {
if ((*pat & M_MASK) == M_RNG) {
__Char wc2;
pat += pwk;
pwk = One_Char_mbtowc(&wc2, pat, MB_LEN_MAX);
if (globcharcoll(wc, wk, 0) <= 0 &&
if (globcharcoll(wc1, wk, 0) <= 0 &&
globcharcoll(wk, wc2, 0) <= 0)
ok = 1;
} else if (wc == wk)
ok = 1;
pat += pwk;
wc1 = wc;
pwk = One_Char_mbtowc(&wc, pat, MB_LEN_MAX);
}
pat += pwk;
......
......@@ -854,9 +854,9 @@ enddef :
newdef : defined(APPLE) && defined(MACH)
comment : OS X
vendor : : "apple"
hosttype: defined(i386) : "intel-pc"
hosttype: defined(i386) : "intel-mac"
hosttype: defined(ppc) : "powermac"
hosttype: defined(M_amd64) : "amd"
hosttype: defined(M_amd64) : "intel-mac"
ostype : : "darwin"
machtype: defined(i386) : "i386"
machtype: defined(M_amd64) : "x86_64"
......
......@@ -237,6 +237,7 @@ main(int argc, char **argv)
int nofile = 0;
volatile int nverbose = 0;
volatile int rdirs = 0;
volatile int exitcode = 0;
int quitit = 0;
Char *cp;
#ifdef AUTOLOGOUT
......@@ -1390,6 +1391,12 @@ main(int argc, char **argv)
if (targinp) {
/* If this -c command caused an error before, skip processing */
if (reenter && arginp) {
exitcode = 1;
goto done;
}
arginp = SAVE(targinp);
/*
* we put the command into a variable
......@@ -1422,6 +1429,7 @@ main(int argc, char **argv)
*/
process(setintr);
done:
/*
* Mop-up.
*/
......@@ -1443,7 +1451,7 @@ main(int argc, char **argv)
}
record();
exitstat();
return (0);
return exitcode;
}
void
......
......@@ -43,6 +43,7 @@
#endif
char *seterr = NULL; /* Holds last error if there was one */
extern int enterhist;
#define ERR_FLAGS 0xf0000000
#define ERR_NAME 0x10000000
......@@ -630,6 +631,8 @@ stderror(unsigned int id, ...)
*/
flush();/*FIXRESET*/
haderr = 1; /* Now to diagnostic output */
if (enterhist)
xprintf("Can't load history: ");/*FIXRESET*/
if (flags & ERR_NAME)
xprintf("%s: ", bname);/*FIXRESET*/
if ((flags & ERR_OLD)) {
......
......@@ -682,13 +682,27 @@ EXTERN int OLDSTD IZERO; /* Old standard input (def for cmds) */
*/
#ifdef SIGSETJMP
typedef struct { sigjmp_buf j; } jmp_buf_t;
# define setexit() sigsetjmp(reslab.j, 1)
# define _reset() siglongjmp(reslab.j, 1)
typedef struct { const char *f; size_t l; sigjmp_buf j; } jmp_buf_t;
# define tcsh_setjmp() sigsetjmp(reslab.j, 1)
# define tcsh_longjmp() siglongjmp(reslab.j, 1)
# define setexit() (reslab.f = __func__, \
reslab.l = __LINE__, \
sigsetjmp(reslab.j, 1))
# define _reset() siglongjmp(reslab.j, 1)
#else
typedef struct { jmp_buf j; } jmp_buf_t;
# define setexit() setjmp(reslab.j)
# define _reset() longjmp(reslab.j, 1)
typedef struct { const char *f; size_t l; jmp_buf j; } jmp_buf_t;
# define tcsh_setjmp() setjmp(reslab.j)
# define tcsh_longjmp() longjmp(reslab.j, 1)
#endif
#define setexit() (reslab.f = __func__, \
reslab.l = __LINE__, \
tcsh_setjmp())
#ifdef SETJMP_DEBUG
# define _reset() xprintf("reset %s %zu\n", reslab.f, reslab.l), \
flush(), tcsh_longjmp()
#else
# define _reset() tcsh_longjmp()
#endif
#define getexit(a) (void) ((a) = reslab)
......
......@@ -1281,6 +1281,7 @@ rechist(Char *fname, int ref)
}
if (merge) {
jmp_buf_t osetexit;
if (lock) {
#ifndef WINNT_NATIVE
char *lockpath = strsave(short2str(fname));
......@@ -1290,7 +1291,10 @@ rechist(Char *fname, int ref)
cleanup_push(lockpath, dotlock_cleanup);
#endif
}
loadhist(fname, 1);
getexit(osetexit);
if (setexit())
loadhist(fname, 1);
resexit(osetexit);
}
}
rs = randsuf();
......
......@@ -1020,8 +1020,10 @@ domod(Char *cp, Char type)
switch (type) {
case 'x':
case 'q':
case 'x':
if (*cp == '\0')
return Strsave(STRQNULL);
wp = Strsave(cp);
for (xp = wp; (c = *xp) != 0; xp++)
if ((c != ' ' && c != '\t') || type == 'q')
......
......@@ -253,10 +253,10 @@ Char STRnormal[] = { 'n', 'o', 'r', 'm', 'a', 'l', '\0' };
Char STRsldtlogout[] = { '/', '.', 'l', 'o', 'g', 'o', 'u', 't', '\0' };
Char STRjobs[] = { 'j', 'o', 'b', 's', '\0' };
Char STRdefprompt[] = { '%', '#', ' ', '\0' };
Char STRmquestion[] = { '%', 'R', '?' | QUOTE, ' ', '\0' };
Char STRmquestion[] = { '%', 'R', (Char)('?' | QUOTE), ' ', '\0' };
Char STRKCORRECT[] = { 'C', 'O', 'R', 'R', 'E', 'C', 'T', '>', '%', 'R',
' ', '(', 'y', '|', 'n', '|', 'e', '|', 'a', ')',
'?' | QUOTE, ' ', '\0' };
(Char)('?' | QUOTE), ' ', '\0' };
Char STRunalias[] = { 'u', 'n', 'a', 'l', 'i', 'a', 's', '\0' };
Char STRalias[] = { 'a', 'l', 'i', 'a', 's', '\0' };
Char STRprecmd[] = { 'p', 'r', 'e', 'c', 'm', 'd', '\0' };
......@@ -380,7 +380,7 @@ Char STRlistmaxrows[] = { 'l', 'i', 's', 't', 'm', 'a', 'x', 'r', 'o', 'w',
Char STRlistmax[] = { 'l', 'i', 's', 't', 'm', 'a', 'x', '\0' };
Char STRlistlinks[] = { 'l', 'i', 's', 't', 'l', 'i', 'n', 'k', 's', '\0' };
Char STRDING[] = { 'D', 'I', 'N', 'G', '!', '\0' };
Char STRQNULL[] = { '\0' | QUOTE, '\0' };
Char STRQNULL[] = { (Char)('\0' | QUOTE), '\0' };
Char STRcorrect[] = { 'c', 'o', 'r', 'r', 'e', 'c', 't', '\0' };
Char STRcmd[] = { 'c', 'm', 'd', '\0' };
Char STRall[] = { 'a', 'l', 'l', '\0' };
......
......@@ -42,7 +42,7 @@
# include <sys/signal.h>
#endif /* SYSVREL > 0 */
#if defined(__APPLE__) || defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK))
#if defined(SUNOS4) || defined(DGUX) || defined(hp800) || (SYSVREL > 3 && defined(VFORK))
# define SAVESIGVEC
#endif /* SUNOS4 || DGUX || hp800 || SVR4 & VFORK */
......
......@@ -391,7 +391,7 @@ variants; see
.Sx FILES .
.Ss Editing
We first describe
.Sx The command-line editor"
.Sx The command-line editor
The
.Sx Completion and listing
and
......@@ -402,7 +402,7 @@ Finally,
.Sx Editor commands
lists and describes
the editor commands specific to the shell and their default bindings.
.It Sx The command-line editor (+)
.Ss The command-line editor (+)
Command-line input can be edited using key sequences much like those used in
.Xr emacs 1
or
......@@ -684,9 +684,8 @@ If the
.Va complete
shell variable is set to
.Sq enhance ,
completion
1) ignores case and 2) considers periods, hyphens and underscores
.Sq ( . ,
completion 1) ignores case and 2) considers periods, hyphens and underscores
.Sq ( \&. ,
.Sq \&-
and
.Sq _ )
......@@ -727,7 +726,7 @@ hyphens or underscores.
If the
.Va complete
shell variable is set to
.Sq enhance ,
.Sq Enhance ,
completion
ignores case and differences between a hyphen and an underscore word
separator only when the user types a lowercase character or a hyphen.
......@@ -1093,17 +1092,20 @@ must be bound to a
single character for this to work) or one of the following special characters
may be typed:
.Pp
.Sq ^W
.Bl -tag -width indent -compact
.It ^W
Appends the rest of the word under the cursor to the search pattern.
delete (or any character bound to
.It delete
(or any character bound to
.Ic backward-delete-char )
Undoes the effect of the last character typed and deletes a character
from the search pattern if appropriate.
.Sq ^G
.It ^G
If the previous search was successful, aborts the entire search.
If not, goes back to the last successful search.
escape
.It escape
Ends the search, leaving the current line in the input buffer.
.El
.Pp
Any other character not bound to
.Ic self-insert-command
......@@ -1664,6 +1666,7 @@ The words of an input line are
numbered from 0, the first (usually command) word being 0, the second word
(first argument) being 1, etc.
The basic word designators are:
.Pp
.Bl -tag -width XXXX -offset indent -compact
.It Ar 0
The first (command) word
......@@ -2021,7 +2024,7 @@ cause an error.
.Pp
Some aliases are referred to by the shell; see
.Va Special aliases
.Sx Variable substitution
.Ss Variable substitution
The shell maintains a list of variables, each of which has as value a list of
zero or more words.
The values of shell variables can be displayed and changed with the
......@@ -2219,7 +2222,7 @@ The following substitutions can not be modified with
.Sq \&:
modifiers.
.Pp
.Bl -tag -width XXXXXXXX -offset indent -compact
.Bl -tag -width XXXXXXXXXX -offset indent -compact
.It Ar $?name
.It Ar ${?name}
Substitutes the string
......@@ -2238,27 +2241,21 @@ if it is not.
Always
.Sq 0
in interactive shells.
.It Ar
$#name
${#name}
.It Ar $#name
.It Ar ${#name}
Substitutes the number of words in
.Va name
.It Ar
$#
.It Ar $#
Equivalent to
.Sq $#argv
(+)
.It Ar
$%
.Va name
.It Ar $%name
.It Ar ${%name}
Substitutes the number of characters in
.Va name
(+)
.Pp
$%
.Va number
.TP 8
.It Ar $%number
.It Ar ${%number}
Substitutes the number of characters in
.Va $argv[number] .
......@@ -2749,7 +2746,7 @@ file to it on standard input.
The standard input and standard output of a command may be redirected with the
following syntax:
.Pp
.Bl -tag -width XXXXXX -offset indent -compact
.Bl -tag -width XXXXXXXXX -offset indent -compact
.It Ar < name
Open file
.Va name
......@@ -3143,63 +3140,47 @@ They have the same format as before;
.Va op
may be one of
.Pp
.PD 0
.RS +4
.TP 8
.B A
.Bl -tag -width XXX -offset indent -compact
.It Ar A
Last file access time, as the number of seconds since the epoch
.TP 8
.B A:
.It Ar A:
Like
.Va A
.Va Ar A
, but in timestamp format, e.g.,
.Sq Fri May 14 16:36:10 1993
.TP 8
.B M
.It Ar M
Last file modification time
.TP 8
.B M:
.It Ar M:
Like
.Va M
, but in timestamp format
.TP 8
.B C
.It Ar C
Last inode modification time
.TP 8
.B C:
.It Ar C:
Like
.Va C
, but in timestamp format
.TP 8
.B D
.It Ar D
Device number
.TP 8
.B I
.It Ar I
Inode number
.TP 8
.B F
.It Ar F
Composite
.Va f
ile identifier, in the form
.Va device
:
.Va device :
.Va inode
.TP 8
.B L
.It Ar L
The name of the file pointed to by a symbolic link
.TP 8
.B N
.It Ar N
Number of (hard) links
.TP 8
.B P
.It Ar P
Permissions, in octal, without leading zero
.TP 8
.B P:
.It Ar P:
Like
.Va P
, with leading zero
.TP 8
.B P\fImode
.It Ar P<mode>
Equivalent to
.Sq \-P
.Va file
......@@ -3217,28 +3198,22 @@ if by group only,
and
.Sq 0
if by neither
.TP 8
.B P\fImode\fB:
Like \fBP
.It Ar P<mode>:
Like
.Ar BP
.Va mode
, with leading zero
.TP 8
.B U
.It Ar U
Numeric userid
.TP 8
.B U:
.It Ar U:
Username, or the numeric userid if the username is unknown
.TP 8
.B G
.It Ar G
Numeric groupid
.TP 8
.B G:
.It Ar G:
Groupname, or the numeric groupid if the groupname is unknown
.TP 8
.B Z
.It Ar Z
Size, in bytes
.RE
.PD
.El
.Pp
Only one of these operators may appear in a multiple-operator test, and it
must be the last.
......@@ -3791,45 +3766,24 @@ The next sections of this manual describe all of the available
and
.Va Special shell variables
.Ss "Builtin commands"
.TP 8
.B %\fIjob
.Bl -tag -width XXXXXXX -offset indent
.It Ar %job
A synonym for the
.Va fg
builtin command.
.TP 8
.B %\fIjob \fB&
.It Ar %job \&&
A synonym for the
.Va bg
builtin command.
.TP 8
.B :
.It Ar \&:
Does nothing, successfully.
.Pp
.B @
.br
.B @ \fIname\fB = \fIexpr
.br
.B @
.Va name
[
.Va index
]\fB = \fIexpr
.br
.B @ \fIname
.Va ++
|\fB--
.PD 0
.TP 8
.B @
.Va name
[
.Va index
]
.Va ++
|\fB--
.It Ar @
.It Ar @ name = expr
.It Ar @ name[index] = expr
.It Ar @ name++|--
.It Ar @name[index]++|--
The first form prints the values of all shell variables.
.PD
.RS +8
.Pp
The second form assigns the value of
.Va expr
......@@ -3875,7 +3829,10 @@ has nothing to do with that described
under
.Va Expressions
.Pp
The fourth and fifth forms increment (`++') or decrement (`\-\-')
The fourth and fifth forms increment (
.Sq ++ )
or decrement
.Sq ( -- )
.Va name
or its
.Va index
......@@ -3898,14 +3855,7 @@ are optional.
Components of
.Va expr
must be separated by spaces.
.RE
.PD
.TP 8
.B alias \fR[
.Va name
[
.Va wordlist
]]
.It Ar alias[name[wordlist]]
Without arguments, prints all aliases.
With
.Va name
......@@ -3928,8 +3878,7 @@ or
See also the
.Va unalias
builtin command.
.TP 8
.B alloc
.It Ar alloc
Shows the amount of dynamic memory acquired, broken down into used and free
memory.
With an argument shows the number of free and used blocks in each size
......@@ -3939,9 +3888,7 @@ This
command's output may vary across system types, because systems other than the VAX
may use a different memory allocator.
.TP 8
.B bg \fR[\fB%
.Va job
...]
.It Ar bg[%job...]
Puts the specified jobs (or, without arguments, the current job)
into the background, continuing each if it is stopped.
.Va job
......@@ -3957,35 +3904,10 @@ as described
under
.Va Jobs
.Pp
.B bindkey \fR[
.Fl l\fR|
.Fl d\fR|
.Fl e\fR|
.Fl v\fR|
.Fl u\fR] (+)
.br
.Va bindkey
[
.Fl a\fR] [
.Fl b\fR] [
.Fl k\fR] [
.Fl r\fR] [
.Fl \-\fR]
.Va key
(+)
.PD 0
.TP 8
.Va bindkey
[
.Fl a\fR] [
.Fl b\fR] [
.Fl k\fR] [
.Fl c\fR|
.Fl s\fR] [