Skip to content

Commit

Permalink
Yet another accumulated round of tweaks and cleanups
Browse files Browse the repository at this point in the history
Notable changes:

src/cmd/ksh93/bltins/{print,read}.c:
- Eliminate some duplicate code in coprocess handling.

src/cmd/ksh93/bltins/whence.c:
- A 'whence -t' tweak analogous to efa18c8 (no behaviour change).

src/cmd/ksh93/{data/lexstates.c,include/lexstates.h}:
- Remove unused e_lexlabignore message (re: 66b6ce4).

src/cmd/ksh93/sh/xec.c: sh_exec(): case T_FORK:
- Remove redundant job.parent assignment; it is already done in the
  next if statement.

src/cmd/ksh93/tests/pty.sh:
- Add missing regression test for d195f57.

src/cmd/ksh93/fun/dirs:
- Do not exit with status 1. This fixes 'pushd' and 'popd' as well,
  as they call 'dirs' before returning. (re: a566596)

README.md:
- Update policy to match actual current practice.
- Briefly document 'bin/package quiet make' and 'bin/package use'.
  • Loading branch information
McDutchie committed May 31, 2023
1 parent 4fdb6ad commit cfba37d
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 43 deletions.
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ksh 93u+m general copyright notice
# K. Eugene Carlson <[email protected]> #
# Anuradha Weeraman <[email protected]> #
# Lev Kujawski <[email protected]> #
# atheik <[email protected]> #
# Phi <[email protected]> #
# atheik <[email protected]> #
# Ryan Schmidt <[email protected]> #
# Harald van Dijk <[email protected]> #
# Chase <[email protected]> #
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.

- Fixed multiple bugs causing incorrect output for relative date specifications
given as arguments to printf %(dateformat)T. For example, something like
printf '%(%Y-%m-%d %H:%M)' 'exact 9 weeks ago'
printf '%(%Y-%m-%d %H:%M)T\n' 'exact 9 weeks ago'
will now produce the correct output, which is the same as GNU date:
date '+%Y-%m-%d %H:%M' '9 weeks ago'

Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ To see what's left to fix, see [the issue tracker](https://github.com/ksh93/ksh/

## Policy

1. Fixing bugs is main focus of the 1.x series.
Major feature development is for future versions (2.x and up).
1. Fixing bugs is main focus of the 1.0 series.
Major feature development is for future versions (1.1 and up).
2. No major rewrites. No refactoring code that is not fully understood.
3. No changes in documented behaviour, except if required for compliance with the
3. Maintain documented behaviour. Changes required for compliance with the
[POSIX shell language standard](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html)
which David Korn [intended](http://www.kornshell.com/info/) for ksh to follow.
are implemented for the `posix` mode only to avoid breaking legacy scripts.
4. No 100% bug compatibility. Broken and undocumented behaviour gets fixed.
5. No bureaucracy, no formalities. Just fix it, or report it: create issues,
send pull requests. Every interested party is invited to contribute.
Expand Down Expand Up @@ -71,6 +71,7 @@ Then `cd` to the top directory and run:
```sh
bin/package make
```
To suppress compiler output, use `quiet make` instead of `make`.
In some non-POSIX shells you might need to prepend `sh` to all calls to `bin/package`.

The compiled binaries are stored in the `arch` directory, in a subdirectory
Expand Down Expand Up @@ -120,6 +121,11 @@ Start by reading the information printed by:
```sh
bin/shtests --man
```
To hand-test ksh (as well as the utilities and the autoloadable functions
that come with it) without installing, run:
```sh
bin/package use
```

### Install

Expand Down
7 changes: 2 additions & 5 deletions src/cmd/ksh93/bltins/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
nflag++;
break;
case 'p':
coprocess:
fd = sh.coutpipe;
msg = e_query;
break;
Expand Down Expand Up @@ -230,11 +231,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
break;
case 'u':
if(opt_info.arg[0]=='p' && opt_info.arg[1]==0)
{
fd = sh.coutpipe;
msg = e_query;
break;
}
goto coprocess;
fd = (int)strtol(opt_info.arg,&opt_info.arg,10);
if(*opt_info.arg)
fd = -1;
Expand Down
10 changes: 4 additions & 6 deletions src/cmd/ksh93/bltins/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
{
Sfdouble_t sec;
char *prompt;
const char *msg = e_file+4;
int r, flags=0, fd=0;
ssize_t len=0;
long timeout = 1000*sh.st.tmout;
Expand Down Expand Up @@ -108,11 +109,8 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
break;
case 'p':
coprocess:
if((fd = sh.cpipe[0])<=0)
{
errormsg(SH_DICT,ERROR_exit(1),e_query);
UNREACHABLE();
}
fd = sh.cpipe[0];
msg = e_query;
break;
case 'n': case 'N':
flags &= ((1<<D_FLAG)-1);
Expand Down Expand Up @@ -158,7 +156,7 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
r = sh_iocheckfd(fd);
if(fd<0 || !(r&IOREAD))
{
errormsg(SH_DICT,ERROR_system(1),e_file+4);
errormsg(SH_DICT,ERROR_system(1),msg);
UNREACHABLE();
}
/* look for prompt */
Expand Down
5 changes: 1 addition & 4 deletions src/cmd/ksh93/bltins/whence.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ static int whence(char **argv, int flags)
{
if(flags&Q_FLAG)
continue;
if(!(flags&T_FLAG))
sfputr(sfstdout,name,-1);
sfputr(sfstdout, flags&T_FLAG?"function":name, -1);
if(flags&V_FLAG)
{
if(nv_isnull(np))
Expand All @@ -224,8 +223,6 @@ static int whence(char **argv, int flags)
else
sfprintf(sfstdout,sh_translate(is_function));
}
else if(flags&T_FLAG)
sfprintf(sfstdout,"function");
sfputc(sfstdout,'\n');
if(!aflag)
continue;
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/data/lexstates.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ const char e_lexsyntax4[] = "syntax error at line %d: invalid reference list";
const char e_lexsyntax5[] = "syntax error at line %d: `<<%s' here-document not contained within command substitution";
const char e_lexwarnvar[] = "line %d: in '((%s))', using '$' as in '$%.*s' is slower and can introduce rounding errors";
const char e_lexarithwarn[] = "line %d: %s is slower than ((%.*s%s";
const char e_lexlabignore[] = "line %d: label %s ignored";
const char e_lexlabunknown[] = "line %d: %s unknown label";
const char e_lexobsolete1[] = "line %d: `...` obsolete, use $(...)";
const char e_lexobsolete2[] = "line %d: -a obsolete, use -e";
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/ksh93/fun/dirs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# #
# David Korn <[email protected]> #
# Martijn Dekker <[email protected]> #
# K. Eugene Carlson <[email protected]> #
# #
########################################################################
#
Expand Down Expand Up @@ -39,4 +40,7 @@ function dirs
select i in "$dir" "${_push_stack[@]}"
do :
done < /dev/null
# The select loop will exit with status 1 as there is no input
# to read, but 'dirs' should not pass down that exit status.
return 0
}
1 change: 0 additions & 1 deletion src/cmd/ksh93/include/lexstates.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ extern const char *sh_lexrstates[ST_NONE];
extern const char e_lexversion[];
extern const char e_lexspace[];
extern const char e_lexslash[];
extern const char e_lexlabignore[];
extern const char e_lexlabunknown[];
extern const char e_lexsyntax1[];
extern const char e_lexsyntax2[];
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/ksh93/sh/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
int fd= -1;
struct stat statb;
Pathcomp_t *nextpp;

if(!pp && !sh.pathlist)
pathinit();
if(!fun && strchr(name,'/'))
Expand All @@ -462,7 +461,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
UNREACHABLE();
}
}

nextpp = pp;
do
{
Expand All @@ -483,7 +481,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
}
}
while(fd<0 && nextpp);

if(fd>=0 && (fd = sh_iomovefd(fd)) > 0)
{
fcntl(fd,F_SETFD,FD_CLOEXEC);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ int sh_exec(const Shnode_t *t, int flags)
if(sh.subshell)
sh_subtmpfile();
if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio))
job.parent=parent=0;
parent = 0;
else
{
#if SHOPT_BGX
Expand Down
10 changes: 6 additions & 4 deletions src/cmd/ksh93/tests/bracket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -162,9 +162,11 @@ if [[ 3x > 4x ]]
then err_exit '3x < 4x'
fi
x='@(bin|dev|?)'
cd /
if [[ $(print $x) != "$x" ]]
then err_exit 'extended pattern matching on command arguments'
: >bin >dev >X
got=$(print $x)
exp=$x
if [[ $got != "$exp" ]]
then err_exit "extended pattern matching on command arguments (expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
if [[ dev != $x ]]
then err_exit 'extended pattern matching not working on variables'
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/ksh93/tests/io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,15 @@ fi
# file descriptor inside of the command substitution.
exp='Foo bar'
{ got=$(echo 'Foo bar' 2>/dev/null); } >&-
[[ $exp == $got ]] || err_exit "BUG_CSUBSTDO: Closing stdout outside of command substitution breaks stdout inside of command substitution" \
[[ $got == "$exp" ]] || err_exit "\$(Comsub) with closed stdout doesn't reopen stdout" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
{ got=${ print 'Foo bar' 2>/dev/null; }; } >&-
[[ $got == "$exp" ]] || err_exit "\${ Comsub; } with closed stdout doesn't reopen stdout" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
{ got=`print 'Foo bar' 2>/dev/null`; } >&-
[[ $got == "$exp" ]] || err_exit "\`Comsub\` with closed stdout doesn't reopen stdout" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# In shcomp, process substitution did not work when used as the file name to a redirection.
Expand Down
18 changes: 13 additions & 5 deletions src/cmd/ksh93/tests/path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,18 @@ fi
ofile=$tmp/command_x_chunks.sh
trap 'sleep_pid=; while kill -9 $pid; do :; done 2>/dev/null; err_exit "'\''command -x'\'' hung"' TERM
trap 'kill $sleep_pid; while kill -9 $pid; do :; done 2>/dev/null; trap - INT; kill -s INT $$"' INT
{ sleep 60; kill $$; } &
( typeset -si i
sleep 5
# if it's slow, display a counter
for ((i=35; i>0; i--))
do printf '\t%s[%d]: command -x: %2ds...\r' "$Command" LINENO i
sleep 1
done
# if this subshell is not killed yet, give up and kill the test by triggering the TERM trap in parent
kill "$$"
) &
sleep_pid=$!
(
export LC_ALL=C
( export LC_ALL=C
unset IFS; set +f
builtin getconf 2> /dev/null
arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; }
Expand All @@ -560,10 +568,10 @@ sleep_pid=$!
' static_argzero "$@" final_static_arg_1 final_static_arg_2
) >$ofile &
pid=$!
{ wait $pid; } 2>/dev/null # wait and suppress signal messages
wait $pid;
e=$?
trap - TERM INT
[[ $sleep_pid ]] && kill $sleep_pid
trap - TERM INT
if [[ ${ kill -l "$e"; } == KILL ]]
then warning "'command -x' test killed, probably due to lack of memory; skipping test"
else if let "e > 0"
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/ksh93/tests/pty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Johnothan King <[email protected]> #
# Govind Kamat <[email protected]> #
# K. Eugene Carlson <[email protected]> #
# Phi <[email protected]> #
# #
########################################################################

Expand Down Expand Up @@ -1230,5 +1231,23 @@ w ls $'~\t
r ^:test-5: ls \\~ab/\r\n$
!

((SHOPT_VSH || SHOPT_ESH)) &&
chmod +x cmd_complete_me >cmd_complete_me &&
PATH=.:$PATH tst $LINENO <<"!"
L command completion after init and after TERM change
# https://github.com/ksh93/ksh/issues/642
d 40
p :test-1:
w cmd_complet\t
r cmd_complete_me \r\n$
# also try after TERM change
p :test-2:
w TERM=ansi
p :test-3:
w cmd_complet\t
r cmd_complete_me \r\n$
!

# ======
exit $((Errors<125?Errors:125))
1 change: 1 addition & 0 deletions src/lib/libast/include/sfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Phong Vo <[email protected]> *
* Martijn Dekker <[email protected]> *
* Johnothan King <[email protected]> *
* Phi <[email protected]> *
* *
***********************************************************************/
#ifndef _SFIO_H
Expand Down
6 changes: 0 additions & 6 deletions src/lib/libast/man/sfio.3
Original file line number Diff line number Diff line change
Expand Up @@ -1989,12 +1989,6 @@ the sort ``\f3FILE*\ f\ =\ stdin;\fP'' would work.
Such applications should use the compile time flag \f3SF_FILE_STRUCT\fP
to achieve the desired effect.
.PP
The binary Stdio-compatibility libraries, \f3libstdio.a\fP and \f3libstdio-mt.a\fP,
provide complete implementations of Stdio functions suitable
for linking applications already compiled with native header \f3stdio.h\fP.
These functions are also slightly altered or extended
as discussed above.
.PP
Below are the supported Stdio functions:
.PP
.nf
Expand Down
1 change: 1 addition & 0 deletions src/lib/libast/sfio/sfvprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Martijn Dekker <[email protected]> *
* Johnothan King <[email protected]> *
* Phi <[email protected]> *
* hyenias <[email protected]> *
* *
***********************************************************************/
#include "sfhdr.h"
Expand Down

0 comments on commit cfba37d

Please sign in to comment.