Skip to content

Commit cfba37d

Browse files
committed
Yet another accumulated round of tweaks and cleanups
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'.
1 parent 4fdb6ad commit cfba37d

File tree

18 files changed

+72
-43
lines changed

18 files changed

+72
-43
lines changed

COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ ksh 93u+m general copyright notice
2020
# K. Eugene Carlson <[email protected]> #
2121
# Anuradha Weeraman <[email protected]> #
2222
# Lev Kujawski <[email protected]> #
23-
# atheik <[email protected]> #
2423
24+
# atheik <[email protected]> #
2525
# Ryan Schmidt <[email protected]> #
2626
# Harald van Dijk <[email protected]> #
2727
# Chase <[email protected]> #

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
6464

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

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ To see what's left to fix, see [the issue tracker](https://github.com/ksh93/ksh/
1717

1818
## Policy
1919

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

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

124130
### Install
125131

src/cmd/ksh93/bltins/print.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
203203
nflag++;
204204
break;
205205
case 'p':
206+
coprocess:
206207
fd = sh.coutpipe;
207208
msg = e_query;
208209
break;
@@ -230,11 +231,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
230231
break;
231232
case 'u':
232233
if(opt_info.arg[0]=='p' && opt_info.arg[1]==0)
233-
{
234-
fd = sh.coutpipe;
235-
msg = e_query;
236-
break;
237-
}
234+
goto coprocess;
238235
fd = (int)strtol(opt_info.arg,&opt_info.arg,10);
239236
if(*opt_info.arg)
240237
fd = -1;

src/cmd/ksh93/bltins/read.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
6363
{
6464
Sfdouble_t sec;
6565
char *prompt;
66+
const char *msg = e_file+4;
6667
int r, flags=0, fd=0;
6768
ssize_t len=0;
6869
long timeout = 1000*sh.st.tmout;
@@ -108,11 +109,8 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
108109
break;
109110
case 'p':
110111
coprocess:
111-
if((fd = sh.cpipe[0])<=0)
112-
{
113-
errormsg(SH_DICT,ERROR_exit(1),e_query);
114-
UNREACHABLE();
115-
}
112+
fd = sh.cpipe[0];
113+
msg = e_query;
116114
break;
117115
case 'n': case 'N':
118116
flags &= ((1<<D_FLAG)-1);
@@ -158,7 +156,7 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
158156
r = sh_iocheckfd(fd);
159157
if(fd<0 || !(r&IOREAD))
160158
{
161-
errormsg(SH_DICT,ERROR_system(1),e_file+4);
159+
errormsg(SH_DICT,ERROR_system(1),msg);
162160
UNREACHABLE();
163161
}
164162
/* look for prompt */

src/cmd/ksh93/bltins/whence.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ static int whence(char **argv, int flags)
208208
{
209209
if(flags&Q_FLAG)
210210
continue;
211-
if(!(flags&T_FLAG))
212-
sfputr(sfstdout,name,-1);
211+
sfputr(sfstdout, flags&T_FLAG?"function":name, -1);
213212
if(flags&V_FLAG)
214213
{
215214
if(nv_isnull(np))
@@ -224,8 +223,6 @@ static int whence(char **argv, int flags)
224223
else
225224
sfprintf(sfstdout,sh_translate(is_function));
226225
}
227-
else if(flags&T_FLAG)
228-
sfprintf(sfstdout,"function");
229226
sfputc(sfstdout,'\n');
230227
if(!aflag)
231228
continue;

src/cmd/ksh93/data/lexstates.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ const char e_lexsyntax4[] = "syntax error at line %d: invalid reference list";
423423
const char e_lexsyntax5[] = "syntax error at line %d: `<<%s' here-document not contained within command substitution";
424424
const char e_lexwarnvar[] = "line %d: in '((%s))', using '$' as in '$%.*s' is slower and can introduce rounding errors";
425425
const char e_lexarithwarn[] = "line %d: %s is slower than ((%.*s%s";
426-
const char e_lexlabignore[] = "line %d: label %s ignored";
427426
const char e_lexlabunknown[] = "line %d: %s unknown label";
428427
const char e_lexobsolete1[] = "line %d: `...` obsolete, use $(...)";
429428
const char e_lexobsolete2[] = "line %d: -a obsolete, use -e";

src/cmd/ksh93/fun/dirs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# #
1313
# David Korn <[email protected]> #
1414
# Martijn Dekker <[email protected]> #
15+
# K. Eugene Carlson <[email protected]> #
1516
# #
1617
########################################################################
1718
#
@@ -39,4 +40,7 @@ function dirs
3940
select i in "$dir" "${_push_stack[@]}"
4041
do :
4142
done < /dev/null
43+
# The select loop will exit with status 1 as there is no input
44+
# to read, but 'dirs' should not pass down that exit status.
45+
return 0
4246
}

src/cmd/ksh93/include/lexstates.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ extern const char *sh_lexrstates[ST_NONE];
129129
extern const char e_lexversion[];
130130
extern const char e_lexspace[];
131131
extern const char e_lexslash[];
132-
extern const char e_lexlabignore[];
133132
extern const char e_lexlabunknown[];
134133
extern const char e_lexsyntax1[];
135134
extern const char e_lexsyntax2[];

src/cmd/ksh93/sh/path.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
451451
int fd= -1;
452452
struct stat statb;
453453
Pathcomp_t *nextpp;
454-
455454
if(!pp && !sh.pathlist)
456455
pathinit();
457456
if(!fun && strchr(name,'/'))
@@ -462,7 +461,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
462461
UNREACHABLE();
463462
}
464463
}
465-
466464
nextpp = pp;
467465
do
468466
{
@@ -483,7 +481,6 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun)
483481
}
484482
}
485483
while(fd<0 && nextpp);
486-
487484
if(fd>=0 && (fd = sh_iomovefd(fd)) > 0)
488485
{
489486
fcntl(fd,F_SETFD,FD_CLOEXEC);

src/cmd/ksh93/sh/xec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ int sh_exec(const Shnode_t *t, int flags)
14601460
if(sh.subshell)
14611461
sh_subtmpfile();
14621462
if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio))
1463-
job.parent=parent=0;
1463+
parent = 0;
14641464
else
14651465
{
14661466
#if SHOPT_BGX

src/cmd/ksh93/tests/bracket.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# #
33
# This software is part of the ast package #
44
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5-
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
5+
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
66
# and is licensed under the #
77
# Eclipse Public License, Version 2.0 #
88
# #
@@ -162,9 +162,11 @@ if [[ 3x > 4x ]]
162162
then err_exit '3x < 4x'
163163
fi
164164
x='@(bin|dev|?)'
165-
cd /
166-
if [[ $(print $x) != "$x" ]]
167-
then err_exit 'extended pattern matching on command arguments'
165+
: >bin >dev >X
166+
got=$(print $x)
167+
exp=$x
168+
if [[ $got != "$exp" ]]
169+
then err_exit "extended pattern matching on command arguments (expected $(printf %q "$exp"), got $(printf %q "$got"))"
168170
fi
169171
if [[ dev != $x ]]
170172
then err_exit 'extended pattern matching not working on variables'

src/cmd/ksh93/tests/io.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,15 @@ fi
857857
# file descriptor inside of the command substitution.
858858
exp='Foo bar'
859859
{ got=$(echo 'Foo bar' 2>/dev/null); } >&-
860-
[[ $exp == $got ]] || err_exit "BUG_CSUBSTDO: Closing stdout outside of command substitution breaks stdout inside of command substitution" \
860+
[[ $got == "$exp" ]] || err_exit "\$(Comsub) with closed stdout doesn't reopen stdout" \
861861
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
862+
{ got=${ print 'Foo bar' 2>/dev/null; }; } >&-
863+
[[ $got == "$exp" ]] || err_exit "\${ Comsub; } with closed stdout doesn't reopen stdout" \
864+
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
865+
{ got=`print 'Foo bar' 2>/dev/null`; } >&-
866+
[[ $got == "$exp" ]] || err_exit "\`Comsub\` with closed stdout doesn't reopen stdout" \
867+
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
868+
862869
863870
# ======
864871
# In shcomp, process substitution did not work when used as the file name to a redirection.

src/cmd/ksh93/tests/path.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,18 @@ fi
530530
ofile=$tmp/command_x_chunks.sh
531531
trap 'sleep_pid=; while kill -9 $pid; do :; done 2>/dev/null; err_exit "'\''command -x'\'' hung"' TERM
532532
trap 'kill $sleep_pid; while kill -9 $pid; do :; done 2>/dev/null; trap - INT; kill -s INT $$"' INT
533-
{ sleep 60; kill $$; } &
533+
( typeset -si i
534+
sleep 5
535+
# if it's slow, display a counter
536+
for ((i=35; i>0; i--))
537+
do printf '\t%s[%d]: command -x: %2ds...\r' "$Command" LINENO i
538+
sleep 1
539+
done
540+
# if this subshell is not killed yet, give up and kill the test by triggering the TERM trap in parent
541+
kill "$$"
542+
) &
534543
sleep_pid=$!
535-
(
536-
export LC_ALL=C
544+
( export LC_ALL=C
537545
unset IFS; set +f
538546
builtin getconf 2> /dev/null
539547
arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; }
@@ -560,10 +568,10 @@ sleep_pid=$!
560568
' static_argzero "$@" final_static_arg_1 final_static_arg_2
561569
) >$ofile &
562570
pid=$!
563-
{ wait $pid; } 2>/dev/null # wait and suppress signal messages
571+
wait $pid;
564572
e=$?
565-
trap - TERM INT
566573
[[ $sleep_pid ]] && kill $sleep_pid
574+
trap - TERM INT
567575
if [[ ${ kill -l "$e"; } == KILL ]]
568576
then warning "'command -x' test killed, probably due to lack of memory; skipping test"
569577
else if let "e > 0"

src/cmd/ksh93/tests/pty.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Johnothan King <[email protected]> #
1616
# Govind Kamat <[email protected]> #
1717
# K. Eugene Carlson <[email protected]> #
18+
1819
# #
1920
########################################################################
2021

@@ -1230,5 +1231,23 @@ w ls $'~\t
12301231
r ^:test-5: ls \\~ab/\r\n$
12311232
!
12321233

1234+
((SHOPT_VSH || SHOPT_ESH)) &&
1235+
chmod +x cmd_complete_me >cmd_complete_me &&
1236+
PATH=.:$PATH tst $LINENO <<"!"
1237+
L command completion after init and after TERM change
1238+
# https://github.com/ksh93/ksh/issues/642
1239+
1240+
d 40
1241+
p :test-1:
1242+
w cmd_complet\t
1243+
r cmd_complete_me \r\n$
1244+
# also try after TERM change
1245+
p :test-2:
1246+
w TERM=ansi
1247+
p :test-3:
1248+
w cmd_complet\t
1249+
r cmd_complete_me \r\n$
1250+
!
1251+
12331252
# ======
12341253
exit $((Errors<125?Errors:125))

src/lib/libast/include/sfio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Phong Vo <[email protected]> *
1616
* Martijn Dekker <[email protected]> *
1717
* Johnothan King <[email protected]> *
18+
1819
* *
1920
***********************************************************************/
2021
#ifndef _SFIO_H

src/lib/libast/man/sfio.3

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,12 +1989,6 @@ the sort ``\f3FILE*\ f\ =\ stdin;\fP'' would work.
19891989
Such applications should use the compile time flag \f3SF_FILE_STRUCT\fP
19901990
to achieve the desired effect.
19911991
.PP
1992-
The binary Stdio-compatibility libraries, \f3libstdio.a\fP and \f3libstdio-mt.a\fP,
1993-
provide complete implementations of Stdio functions suitable
1994-
for linking applications already compiled with native header \f3stdio.h\fP.
1995-
These functions are also slightly altered or extended
1996-
as discussed above.
1997-
.PP
19981992
Below are the supported Stdio functions:
19991993
.PP
20001994
.nf

src/lib/libast/sfio/sfvprintf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Martijn Dekker <[email protected]> *
1717
* Johnothan King <[email protected]> *
1818
19+
* hyenias <[email protected]> *
1920
* *
2021
***********************************************************************/
2122
#include "sfhdr.h"

0 commit comments

Comments
 (0)