Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-mksh: 提交

external/mksh


Commit MetaInfo

修订版8cd2fbe92f4e6a4df6d6ff47942dce2160bdbf0f (tree)
时间2019-04-03 03:30:20
作者Bill Rassieur <rassb@goog...>
CommiterBill Rassieur

Log Message

Merge master@5428150 into git_qt-dev-plus-aosp.

Change-Id: I30afca794eaa5447375ca5464546a1ecadfb16a6
BUG: 129345239

更改概述

差异

--- a/Android.bp
+++ b/Android.bp
@@ -107,7 +107,7 @@ cc_defaults {
107107 "-DHAVE_SYS_ERRLIST_DECL=0",
108108 "-DHAVE_SYS_SIGLIST_DECL=1",
109109 "-DHAVE_PERSISTENT_HISTORY=0",
110- "-DMKSH_BUILD_R=563",
110+ "-DMKSH_BUILD_R=571",
111111
112112 // Additional flags
113113 "-DMKSH_DEFAULT_PROFILEDIR=\"/system/etc\"",
--- a/Android.patch.txt
+++ b/Android.patch.txt
@@ -1,5 +1,6 @@
1---- mksh-R56b/funcs.c 2017-05-05 15:53:55.000000000 -0700
2-+++ src/funcs.c 2017-09-22 16:19:44.327000462 -0700
1+diff -ru mksh-R57/funcs.c src/funcs.c
2+--- mksh-R57/funcs.c 2018-10-20 14:04:55.000000000 -0700
3++++ src/funcs.c 2019-03-26 12:05:23.976821773 -0700
34 @@ -103,7 +103,9 @@
45 {Tsgbreak, c_brkcont},
56 {T__builtin, c_builtin},
@@ -31,11 +32,12 @@
3132 #ifdef __MirBSD__
3233 /* alias to "true" for historical reasons */
3334 {"domainname", c_true},
34---- mksh-R56b/main.c 2017-04-28 04:14:14.000000000 -0700
35-+++ src/main.c 2017-09-22 15:58:14.134149037 -0700
36-@@ -410,6 +410,12 @@
37- }
38- }
35+diff -ru mksh-R57/main.c src/main.c
36+--- mksh-R57/main.c 2019-01-05 05:24:45.000000000 -0800
37++++ src/main.c 2019-03-26 12:05:23.980821764 -0700
38+@@ -399,6 +399,12 @@
39+ /* import environment */
40+ init_environ();
3941
4042 + /* override default PATH regardless of environment */
4143 +#ifdef MKSH_DEFPATH_OVERRIDE
--- a/src/Build.sh
+++ b/src/Build.sh
@@ -1,5 +1,5 @@
11 #!/bin/sh
2-srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.731 2018/01/13 21:38:06 tg Exp $'
2+srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.734 2019/03/01 16:18:13 tg Exp $'
33 #-
44 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
55 # 2011, 2012, 2013, 2014, 2015, 2016, 2017
@@ -418,6 +418,7 @@ ac_flags() {
418418 #include <unistd.h>
419419 int main(void) { return (isatty(0)); }
420420 EOF
421+ #'
421422 fi
422423 eval fv=\$HAVE_CAN_`upper $vn`
423424 if test -n "$fl"; then
@@ -1060,11 +1061,12 @@ AIX)
10601061 Darwin)
10611062 vv '|' "hwprefs machine_type os_type os_class >&2"
10621063 vv '|' "sw_vers >&2"
1063- vv '|' "system_profiler SPSoftwareDataType SPHardwareDataType >&2"
1064+ vv '|' "system_profiler -detailLevel mini SPSoftwareDataType SPHardwareDataType >&2"
10641065 vv '|' "/bin/sh --version >&2"
10651066 vv '|' "xcodebuild -version >&2"
10661067 vv '|' "uname -a >&2"
1067- vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
1068+ vv '|' "sysctl kern.version hw.machine hw.model hw.memsize hw.availcpu hw.ncpu hw.cpufrequency hw.byteorder hw.cpu64bit_capable >&2"
1069+ vv '|' "sysctl hw.cpufrequency hw.byteorder hw.cpu64bit_capable hw.ncpu >&2"
10681070 ;;
10691071 IRIX*)
10701072 vv '|' "uname -a >&2"
@@ -2427,7 +2429,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c
24272429 addsrcs USE_PRINTF_BUILTIN printf.c
24282430 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
24292431 test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
2430-add_cppflags -DMKSH_BUILD_R=563
2432+add_cppflags -DMKSH_BUILD_R=571
24312433
24322434 $e $bi$me: Finished configuration testing, now producing output.$ao
24332435
--- a/src/check.t
+++ b/src/check.t
@@ -1,8 +1,9 @@
1-# $MirOS: src/bin/mksh/check.t,v 1.801 2018/01/14 01:47:33 tg Exp $
1+# $MirOS: src/bin/mksh/check.t,v 1.812 2019/03/01 16:17:29 tg Exp $
22 # -*- mode: sh -*-
33 #-
44 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5-# 2011, 2012, 2013, 2014, 2015, 2016, 2017
5+# 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
6+# 2019
67 # mirabilos <m@mirbsd.org>
78 #
89 # Provided that these terms and disclaimer and all copyright notices
@@ -30,7 +31,7 @@
3031 # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
3132
3233 expected-stdout:
33- @(#)MIRBSD KSH R56 2018/01/14
34+ @(#)MIRBSD KSH R57 2019/03/01
3435 description:
3536 Check base version of full shell
3637 stdin:
@@ -39,7 +40,7 @@ name: KSH_VERSION
3940 category: !shell:legacy-yes
4041 ---
4142 expected-stdout:
42- @(#)LEGACY KSH R56 2018/01/14
43+ @(#)LEGACY KSH R57 2019/03/01
4344 description:
4445 Check base version of legacy shell
4546 stdin:
@@ -162,6 +163,38 @@ stdin:
162163 expected-stdout:
163164 ;
164165 ---
166+name: selftest-tty-absent
167+description:
168+ Check that a controlling tty is not present as regress:no-ctty was used
169+ (if this test fails for you DO NOT PASS regress:no-ctty and fix every
170+ other test that fails: why u use it if u haz ctty?)
171+category: regress:no-ctty
172+env-setup: !ENV=./envf!
173+file-setup: file 644 "envf"
174+ PS1=X
175+arguments: !-i!
176+stdin:
177+ echo ok
178+expected-stdout:
179+ ok
180+expected-stderr-pattern:
181+ /mksh: warning: won't have full job control\nXX/
182+---
183+name: selftest-tty-present
184+description:
185+ Check that a controlling tty is present as regress:no-ctty was not used
186+need-ctty: yes
187+env-setup: !ENV=./envf!
188+file-setup: file 644 "envf"
189+ PS1=X
190+arguments: !-i!
191+stdin:
192+ echo ok
193+expected-stdout:
194+ ok
195+expected-stderr: !
196+ XX
197+---
165198 name: alias-1
166199 description:
167200 Check that recursion is detected/avoided in aliases.
@@ -2455,7 +2488,7 @@ expected-stdout:
24552488 name: glob-range-3
24562489 description:
24572490 Check that globbing matches the right things...
2458-# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2491+# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
24592492 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
24602493 # breaks on QNX 6.4.1 (says RT)
24612494 category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2,!os:os390
@@ -3033,6 +3066,19 @@ expected-stdout:
30333066 got four on fd#4
30343067 got five on fd#5
30353068 ---
3069+name: heredoc-15
3070+description:
3071+ Check high-bit7 separators work
3072+stdin:
3073+ u=ä
3074+ tr a-z A-Z <<-…
3075+ m${u}h
3076+ …
3077+ echo ok
3078+expected-stdout:
3079+ MäH
3080+ ok
3081+---
30363082 name: heredoc-comsub-1
30373083 description:
30383084 Tests for here documents in COMSUB, taken from Austin ML
@@ -3526,6 +3572,25 @@ stdin:
35263572 expected-stdout:
35273573 'blah 1'
35283574 ---
3575+name: single-quotes-in-heredoc-trim
3576+description:
3577+ In some cases, single quotes inside {} in heredoc are not normal
3578+stdin:
3579+ x=notOK
3580+ cat <<EOF
3581+ 1: ${x#not} ${x:+${x#not}}
3582+ 2: ${x#\n\o\t} ${x:+${x#\n\o\t}}
3583+ 3: ${x#"not"} ${x:+${x#"not"}}
3584+ 4: ${x#'not'} ${x:+${x#'not'}}
3585+ 5: ${x#$'not'} ${x:+${x#$'not'}}
3586+ EOF
3587+expected-stdout:
3588+ 1: OK OK
3589+ 2: OK OK
3590+ 3: OK OK
3591+ 4: OK OK
3592+ 5: OK OK
3593+---
35293594 name: history-basic
35303595 description:
35313596 See if we can test history at all
@@ -6835,6 +6900,21 @@ expected-stdout:
68356900 3 10 .
68366901 4 -2147483646 .
68376902 ---
6903+name: export-1
6904+description:
6905+ Check allexport works, basic
6906+stdin:
6907+ qa=1
6908+ set -A qb 2 3
6909+ set -a
6910+ qc=4
6911+ set -A qd 5 6
6912+ export -p | grep '^export q'
6913+expected-stdout:
6914+ export qc=4
6915+ export qd[0]=5
6916+ export qd[1]=6
6917+---
68386918 name: readonly-0
68396919 description:
68406920 Ensure readonly is honoured for assignments and unset
@@ -7065,7 +7145,7 @@ stdin:
70657145 print =4
70667146 (exec lq)
70677147 expected-stdout-pattern:
7068- /=1\none\n=2\ntwo\n=3\n.*: ls: not found\n=4\ntf\n/
7148+ /=1\none\n=2\ntwo\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
70697149 ---
70707150 name: exec-ksh88
70717151 description:
@@ -7086,7 +7166,7 @@ stdin:
70867166 print =4
70877167 (exec lq)
70887168 expected-stdout-pattern:
7089- /=1\n.*: print: not found\n=2\n.*: foo: not found\n=3\n.*: ls: not found\n=4\ntf\n/
7169+ /=1\n.*: print: inaccessible or not found\n=2\n.*: foo: inaccessible or not found\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
70907170 ---
70917171 name: xxx-what-do-you-call-this-1
70927172 stdin:
@@ -7179,6 +7259,32 @@ expected-stdout:
71797259 HI
71807260 2 4
71817261 ---
7262+name: xxx-substitution-eval-order-2
7263+description:
7264+ Check some corner cases
7265+stdin:
7266+ unset var
7267+ i=42
7268+ : ${var+${q[i=777]}} required to be lazy by POSIX
7269+ echo 1=$i
7270+ var=meow
7271+ i=42
7272+ : ${var+${q[i=777]}} eval since var is now set
7273+ echo 2=$i
7274+ unset var
7275+ i=42
7276+ : ${var#${q[i=777]}} pattern is needed even if var is empty
7277+ echo 3=$i
7278+ var=meow
7279+ i=42
7280+ : ${var#${q[i=777]}}
7281+ echo 4=$i
7282+expected-stdout:
7283+ 1=42
7284+ 2=777
7285+ 3=777
7286+ 4=777
7287+---
71827288 name: xxx-set-option-1
71837289 description:
71847290 Check option parsing in set
@@ -7280,6 +7386,28 @@ expected-stdout:
72807386 trap: 4
72817387 exit: 4
72827388 ---
7389+name: xxx-stat-1
7390+description:
7391+ Check that tests on files are consistent
7392+stdin:
7393+ mkdir a
7394+ echo x >a/b
7395+ test -e a/b; echo 1e $? .
7396+ test -f a/b; echo 1f $? .
7397+ chmod 0 a
7398+ test -e a/b; echo 2e $? .
7399+ test -f a/b; echo 2f $? .
7400+ chmod 700 a
7401+ test -e a/b; echo 3e $? .
7402+ test -f a/b; echo 3f $? .
7403+expected-stdout:
7404+ 1e 0 .
7405+ 1f 0 .
7406+ 2e 1 .
7407+ 2f 1 .
7408+ 3e 0 .
7409+ 3f 0 .
7410+---
72837411 name: xxx-clean-chars-1
72847412 description:
72857413 Check MAGIC character is stuffed correctly
@@ -7836,6 +7964,23 @@ expected-stdout:
78367964 EXtrap
78377965 = noeval-undef 1 .
78387966 ---
7967+name: exit-trap-3
7968+description:
7969+ Check that the EXIT trap is run in many places, Debian #910276
7970+stdin:
7971+ fkt() {
7972+ trap -- "echo $1 >&2" EXIT
7973+ }
7974+ fkt shell_exit
7975+ $(fkt fn_exit)
7976+ $(trap -- "echo comsub_exit >&2" EXIT)
7977+ (trap -- "echo subshell_exit >&2" EXIT)
7978+expected-stderr:
7979+ fn_exit
7980+ comsub_exit
7981+ subshell_exit
7982+ shell_exit
7983+---
78397984 name: exit-trap-interactive
78407985 description:
78417986 Check that interactive shell doesn't exit via EXIT trap on syntax error
@@ -8444,12 +8589,32 @@ stdin:
84448589 expected-stdout:
84458590 <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1>
84468591 ---
8592+name: typeset-padding-3
8593+description:
8594+ Check for a regression in which UTF-8 wasn’t left-padded right
8595+stdin:
8596+ set -U
8597+ nl=$'\n'
8598+ typeset -L20 x='. ak'
8599+ typeset -R20 y='. ak'
8600+ print -r -- "<$x> (1$nl<12345678910 345678920$nl<$y> 1)"
8601+ typeset -L20 x='. aẞ'
8602+ typeset -R20 y='. aẞ'
8603+ print -r -- "<$x> (2$nl<12345678910 345678920$nl<$y> 2)"
8604+expected-stdout:
8605+ <. ak > (1
8606+ <12345678910 345678920
8607+ < . ak> 1)
8608+ <. aẞ > (2
8609+ <12345678910 345678920
8610+ < . aẞ> 2)
8611+---
84478612 name: utf8bom-1
84488613 description:
84498614 Check that the UTF-8 Byte Order Mark is ignored as the first
84508615 multibyte character of the shell input (with -c, from standard
84518616 input, as file, or as eval argument), but nowhere else
8452-# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
8617+# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
84538618 category: !os:darwin,!shell:ebcdic-yes
84548619 stdin:
84558620 mkdir foo
@@ -10328,7 +10493,7 @@ expected-stdout:
1032810493 ---
1032910494 name: integer-base-one-3Ws
1033010495 description:
10331- some sample code for hexdumping Unicode
10496+ some sample code for hexdumping UCS-2
1033210497 not NUL safe; input lines must be NL terminated
1033310498 stdin:
1033410499 set -U
@@ -10496,7 +10661,7 @@ expected-stdout:
1049610661 ---
1049710662 name: integer-base-one-3Wr
1049810663 description:
10499- some sample code for hexdumping Unicode; NUL and binary safe
10664+ some sample code for hexdumping UCS-2; NUL and binary safe
1050010665 stdin:
1050110666 set -U
1050210667 {
@@ -10616,7 +10781,7 @@ expected-stdout:
1061610781 ---
1061710782 name: integer-base-one-5A
1061810783 description:
10619- Check to see that we’re NUL and Unicode safe
10784+ Check to see that we’re NUL and UCS safe
1062010785 category: !shell:ebcdic-yes
1062110786 stdin:
1062210787 set +U
@@ -10630,7 +10795,7 @@ expected-stdout:
1063010795 ---
1063110796 name: integer-base-one-5E
1063210797 description:
10633- Check to see that we’re NUL and Unicode safe
10798+ Check to see that we’re NUL and UCS safe
1063410799 category: !shell:ebcdic-no
1063510800 stdin:
1063610801 set +U
@@ -10644,7 +10809,7 @@ expected-stdout:
1064410809 ---
1064510810 name: integer-base-one-5W
1064610811 description:
10647- Check to see that we’re NUL and Unicode safe
10812+ Check to see that we’re NUL and UCS safe
1064810813 stdin:
1064910814 set -U
1065010815 print 'a\0b€c' >x
@@ -11139,6 +11304,34 @@ stdin:
1113911304 expected-stdout:
1114011305 Fowl
1114111306 ---
11307+name: fd-cloexec-3
11308+description:
11309+ Another check for close-on-exec
11310+stdin:
11311+ print '#!'"$__progname" >ts
11312+ cat >>ts <<'EOF'
11313+ s=ERR
11314+ read -rN-1 -u$1 s 2>/dev/null; e=$?
11315+ print -r -- "($1, $((!e)), $s)"
11316+ EOF
11317+ chmod +x ts
11318+ print foo >tx
11319+ runtest() {
11320+ s=$1; shift
11321+ print -r -- $("$__progname" "$@" -c "$s") "$@" .
11322+ }
11323+ runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3'
11324+ runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o posix
11325+ runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o sh
11326+ runtest 'exec 3<tx; ./ts 4 4<&3; ./ts 4 4<&3'
11327+ runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3 3<&3'
11328+expected-stdout:
11329+ (3, 1, foo) (3, 0, ERR) .
11330+ (3, 1, foo) (3, 1, ) -o posix .
11331+ (3, 1, foo) (3, 1, ) -o sh .
11332+ (4, 1, foo) (4, 1, ) .
11333+ (3, 1, foo) (3, 1, ) .
11334+---
1114211335 name: comsub-1a
1114311336 description:
1114411337 COMSUB are now parsed recursively, so this works
--- a/src/edit.c
+++ b/src/edit.c
@@ -28,7 +28,7 @@
2828
2929 #ifndef MKSH_NO_CMDLINE_EDITING
3030
31-__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.342 2018/01/14 00:03:00 tg Exp $");
31+__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.343 2018/07/15 16:16:38 tg Exp $");
3232
3333 /*
3434 * in later versions we might use libtermcap for this, but since external
@@ -3831,7 +3831,7 @@ vi_hook(int ch)
38313831 vs = save_es;
38323832
38333833 i = (unsigned)srchlen;
3834- while (--i >= n)
3834+ while (i-- > n)
38353835 vs->linelen -= char_len(locpat[i]);
38363836 srchlen = (int)n;
38373837 vs->cursor = vs->linelen;
--- a/src/exec.c
+++ b/src/exec.c
@@ -2,7 +2,8 @@
22
33 /*-
44 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5- * 2011, 2012, 2013, 2014, 2015, 2016, 2017
5+ * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
6+ * 2019
67 * mirabilos <m@mirbsd.org>
78 *
89 * Provided that these terms and disclaimer and all copyright notices
@@ -23,7 +24,7 @@
2324
2425 #include "sh.h"
2526
26-__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.201 2017/10/11 21:09:24 tg Exp $");
27+__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.206 2019/03/01 16:17:53 tg Exp $");
2728
2829 #ifndef MKSH_DEFAULT_EXECSHELL
2930 #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@@ -429,6 +430,12 @@ execute(struct op * volatile t,
429430 up = makenv();
430431 restoresigs();
431432 cleanup_proc_env();
433+ /* I/O redirection cleanup to be done in child process */
434+ if (!Flag(FPOSIX) && !Flag(FSH) && t->left->ioact != NULL)
435+ for (iowp = t->left->ioact; *iowp != NULL; iowp++)
436+ if ((*iowp)->ioflag & IODUPSELF)
437+ fcntl((*iowp)->unit, F_SETFD, 0);
438+ /* try to execute */
432439 {
433440 union mksh_ccphack cargs;
434441
@@ -820,7 +827,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
820827 if (!(tp->flag&ISSET)) {
821828 if (tp->u2.errnov == ENOENT) {
822829 rv = 127;
823- warningf(true, Tf_sD_s, cp, Tnot_found);
830+ warningf(true, Tf_sD_s_s, cp,
831+ "inaccessible or", Tnot_found);
824832 } else {
825833 rv = 126;
826834 warningf(true, Tf_sD_sD_s, cp, "can't execute",
@@ -862,7 +870,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
862870 Leave:
863871 if (flags & XEXEC) {
864872 exstat = rv & 0xFF;
865- unwind(LLEAVE);
873+ unwind(LEXIT);
866874 }
867875 return (rv);
868876 }
@@ -886,7 +894,7 @@ scriptexec(struct op *tp, const char **ap)
886894 *tp->args-- = tp->str;
887895
888896 #ifndef MKSH_SMALL
889- if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) {
897+ if ((fd = binopen2(tp->str, O_RDONLY | O_MAYEXEC)) >= 0) {
890898 unsigned char *cp;
891899 #ifndef MKSH_EBCDIC
892900 unsigned short m;
@@ -1011,7 +1019,7 @@ scriptexec(struct op *tp, const char **ap)
10111019 cap.ro = ap;
10121020 execve(args.rw[0], args.rw, cap.rw);
10131021
1014- /* report both the programme that was run and the bogus interpreter */
1022+ /* report both the program that was run and the bogus interpreter */
10151023 errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno));
10161024 }
10171025
@@ -1485,9 +1493,11 @@ iosetup(struct ioword *iop, struct tbl *tp)
14851493 afree(sp, ATEMP);
14861494 return (-1);
14871495 }
1488- if (u == (int)iop->unit)
1496+ if (u == (int)iop->unit) {
14891497 /* "dup from" == "dup to" */
1498+ iop->ioflag |= IODUPSELF;
14901499 return (0);
1500+ }
14911501 break;
14921502 }
14931503 }
--- a/src/expr.c
+++ b/src/expr.c
@@ -23,7 +23,7 @@
2323
2424 #include "sh.h"
2525
26-__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.103 2018/01/14 01:29:47 tg Exp $");
26+__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.105 2018/08/10 02:53:33 tg Exp $");
2727
2828 #define EXPRTOK_DEFNS
2929 #include "exprtok.h"
@@ -885,7 +885,7 @@ static int mb_ucsbsearch(const struct mb_ucsrange arr[], size_t elems,
885885 unsigned int val) MKSH_A_PURE;
886886
887887 /*
888- * Generated from the Unicode Character Database, Version 10.0.0, by
888+ * Generated from the UCD 11.0.0 by
889889 * MirOS: contrib/code/Snippets/eawparse,v 1.12 2017/09/06 16:05:45 tg Exp $
890890 */
891891
@@ -909,12 +909,13 @@ static const struct mb_ucsrange mb_ucs_combining[] = {
909909 { 0x0730, 0x074A },
910910 { 0x07A6, 0x07B0 },
911911 { 0x07EB, 0x07F3 },
912+ { 0x07FD, 0x07FD },
912913 { 0x0816, 0x0819 },
913914 { 0x081B, 0x0823 },
914915 { 0x0825, 0x0827 },
915916 { 0x0829, 0x082D },
916917 { 0x0859, 0x085B },
917- { 0x08D4, 0x08E1 },
918+ { 0x08D3, 0x08E1 },
918919 { 0x08E3, 0x0902 },
919920 { 0x093A, 0x093A },
920921 { 0x093C, 0x093C },
@@ -927,6 +928,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = {
927928 { 0x09C1, 0x09C4 },
928929 { 0x09CD, 0x09CD },
929930 { 0x09E2, 0x09E3 },
931+ { 0x09FE, 0x09FE },
930932 { 0x0A01, 0x0A02 },
931933 { 0x0A3C, 0x0A3C },
932934 { 0x0A41, 0x0A42 },
@@ -953,6 +955,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = {
953955 { 0x0BC0, 0x0BC0 },
954956 { 0x0BCD, 0x0BCD },
955957 { 0x0C00, 0x0C00 },
958+ { 0x0C04, 0x0C04 },
956959 { 0x0C3E, 0x0C40 },
957960 { 0x0C46, 0x0C48 },
958961 { 0x0C4A, 0x0C4D },
@@ -1072,6 +1075,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = {
10721075 { 0xA825, 0xA826 },
10731076 { 0xA8C4, 0xA8C5 },
10741077 { 0xA8E0, 0xA8F1 },
1078+ { 0xA8FF, 0xA8FF },
10751079 { 0xA926, 0xA92D },
10761080 { 0xA947, 0xA951 },
10771081 { 0xA980, 0xA982 },
@@ -1173,7 +1177,7 @@ mb_ucsbsearch(const struct mb_ucsrange arr[], size_t elems, unsigned int val)
11731177 return (0);
11741178 }
11751179
1176-/* Unix column width of a wide character (Unicode code point, really) */
1180+/* Unix column width of a wide character (UCS code point, really) */
11771181 int
11781182 utf_wcwidth(unsigned int wc)
11791183 {
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -38,7 +38,7 @@
3838 #endif
3939 #endif
4040
41-__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.353 2018/01/14 01:26:49 tg Exp $");
41+__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.355 2018/10/20 21:04:28 tg Exp $");
4242
4343 #if HAVE_KILLPG
4444 /*
@@ -499,7 +499,7 @@ c_print(const char **wp)
499499 Xput(xs, xp, '\\');
500500 }
501501 } else if ((unsigned int)c > 0xFF) {
502- /* generic function returned Unicode */
502+ /* generic function returned UCS */
503503 po.ts[utf_wctomb(po.ts, c - 0x100)] = 0;
504504 c = 0;
505505 do {
@@ -2970,6 +2970,37 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
29702970 case TO_STGT:
29712971 return (strcmp(opnd1, opnd2) > 0);
29722972
2973+ /* -nt */
2974+ case TO_FILNT:
2975+ /*
2976+ * ksh88/ksh93 succeed if file2 can't be stated
2977+ * (subtly different from 'does not exist').
2978+ */
2979+ return (stat(opnd1, &b1) == 0 &&
2980+ (((s = stat(opnd2, &b2)) == 0 &&
2981+ b1.st_mtime > b2.st_mtime) || s < 0));
2982+
2983+ /* -ot */
2984+ case TO_FILOT:
2985+ /*
2986+ * ksh88/ksh93 succeed if file1 can't be stated
2987+ * (subtly different from 'does not exist').
2988+ */
2989+ return (stat(opnd2, &b2) == 0 &&
2990+ (((s = stat(opnd1, &b1)) == 0 &&
2991+ b1.st_mtime < b2.st_mtime) || s < 0));
2992+
2993+ /* -ef */
2994+ case TO_FILEQ:
2995+ return (stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&
2996+ b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
2997+
2998+ /* all other cases */
2999+ case TO_NONOP:
3000+ case TO_NONNULL:
3001+ /* throw the error */
3002+ break;
3003+
29733004 /* -eq */
29743005 case TO_INTEQ:
29753006 /* -ne */
@@ -3006,37 +3037,6 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
30063037 break;
30073038 }
30083039 /* NOTREACHED */
3009-
3010- /* -nt */
3011- case TO_FILNT:
3012- /*
3013- * ksh88/ksh93 succeed if file2 can't be stated
3014- * (subtly different from 'does not exist').
3015- */
3016- return (stat(opnd1, &b1) == 0 &&
3017- (((s = stat(opnd2, &b2)) == 0 &&
3018- b1.st_mtime > b2.st_mtime) || s < 0));
3019-
3020- /* -ot */
3021- case TO_FILOT:
3022- /*
3023- * ksh88/ksh93 succeed if file1 can't be stated
3024- * (subtly different from 'does not exist').
3025- */
3026- return (stat(opnd2, &b2) == 0 &&
3027- (((s = stat(opnd1, &b1)) == 0 &&
3028- b1.st_mtime < b2.st_mtime) || s < 0));
3029-
3030- /* -ef */
3031- case TO_FILEQ:
3032- return (stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&
3033- b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
3034-
3035- /* all other cases */
3036- case TO_NONOP:
3037- case TO_NONNULL:
3038- /* throw the error */
3039- break;
30403040 }
30413041 (*te->error)(te, 0, "internal error: unknown op");
30423042 return (1);
--- a/src/histrap.c
+++ b/src/histrap.c
@@ -3,7 +3,7 @@
33
44 /*-
55 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
6- * 2011, 2012, 2014, 2015, 2016, 2017
6+ * 2011, 2012, 2014, 2015, 2016, 2017, 2018
77 * mirabilos <m@mirbsd.org>
88 *
99 * Provided that these terms and disclaimer and all copyright notices
@@ -27,7 +27,7 @@
2727 #include <sys/file.h>
2828 #endif
2929
30-__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.166 2017/08/07 23:25:09 tg Exp $");
30+__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.167 2018/04/28 17:16:54 tg Exp $");
3131
3232 Trap sigtraps[ksh_NSIG + 1];
3333 static struct sigaction Sigact_ign;
@@ -879,7 +879,8 @@ hist_persist_init(void)
879879 }
880880 }
881881 hist_trunc_done:
882- histfsize = lseek(histfd, (off_t)0, SEEK_END);
882+ if ((histfsize = lseek(histfd, (off_t)0, SEEK_END)) < 0)
883+ goto hist_init_fail;
883884 hist_init_tail:
884885 mksh_unlkfd(histfd);
885886 }
@@ -962,8 +963,9 @@ writehistfile(int lno, const char *cmd)
962963 unsigned char *base, *news;
963964
964965 mksh_lockfd(histfd);
965- sizenow = lseek(histfd, (off_t)0, SEEK_END);
966- if (sizenow < histfsize) {
966+ if ((sizenow = lseek(histfd, (off_t)0, SEEK_END)) < 0)
967+ goto bad;
968+ else if (sizenow < histfsize) {
967969 /* the file has shrunk; trust it just appending the new data */
968970 /* well, for now, anyway… since mksh strdups all into memory */
969971 /* we can use a nicer approach some time later… */
@@ -998,7 +1000,8 @@ writehistfile(int lno, const char *cmd)
9981000 hist_finish();
9991001 return;
10001002 }
1001- histfsize = lseek(histfd, (off_t)0, SEEK_END);
1003+ if ((histfsize = lseek(histfd, (off_t)0, SEEK_END)) < 0)
1004+ goto bad;
10021005 mksh_unlkfd(histfd);
10031006 }
10041007
--- /dev/null
+++ b/src/jehanne.c
@@ -0,0 +1,36 @@
1+/*-
2+ * Copyright (c) 2017
3+ * Giacomo Tesio <giacomo@tesio.it>
4+ *
5+ * Provided that these terms and disclaimer and all copyright notices
6+ * are retained or reproduced in an accompanying document, permission
7+ * is granted to deal in this work without restriction, including un-
8+ * limited rights to use, publicly perform, distribute, sell, modify,
9+ * merge, give away, or sublicence.
10+ *
11+ * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12+ * the utmost extent permitted by applicable law, neither express nor
13+ * implied; without malicious intent or gross negligence. In no event
14+ * may a licensor, author or contributor be held liable for indirect,
15+ * direct, other damage, loss, or other issues arising in any way out
16+ * of dealing in the work, even if advised of the possibility of such
17+ * damage or existence of a defect, except proven that it results out
18+ * of said person's immediate fault when using the work as intended.
19+ *-
20+ * Initialisation code for the Jehanne operating system (a Plan 9 de-
21+ * rivative, using GCC)
22+ */
23+
24+static const char __rcsid[] __attribute__((__used__)) =
25+ "$MirOS: src/bin/mksh/jehanne.c,v 1.1 2017/12/22 16:30:00 tg Exp $";
26+
27+#include <u.h>
28+#include <lib9.h>
29+#include <posix.h>
30+
31+void
32+__application_newlib_init(int argc, char *argv[])
33+{
34+ rfork(RFFDG | RFREND | RFNOTEG);
35+ libposix_emulate_SIGCHLD();
36+}
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -23,7 +23,7 @@
2323
2424 #include "sh.h"
2525
26-__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.125 2018/01/05 20:08:34 tg Exp $");
26+__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.127 2018/07/15 16:23:10 tg Exp $");
2727
2828 #if HAVE_KILLPG
2929 #define mksh_killpg killpg
@@ -169,12 +169,6 @@ static void tty_init_state(void);
169169 void
170170 j_init(void)
171171 {
172-#ifndef MKSH_UNEMPLOYED
173- bool mflagset = Flag(FMONITOR) != 127;
174-
175- Flag(FMONITOR) = 0;
176-#endif
177-
178172 #ifndef MKSH_NOPROSPECTOFWORK
179173 (void)sigemptyset(&sm_default);
180174 sigprocmask(SIG_SETMASK, &sm_default, NULL);
@@ -190,8 +184,8 @@ j_init(void)
190184 #endif
191185
192186 #ifndef MKSH_UNEMPLOYED
193- if (!mflagset && Flag(FTALKING))
194- Flag(FMONITOR) = 1;
187+ if (Flag(FMONITOR) == 127)
188+ Flag(FMONITOR) = Flag(FTALKING);
195189
196190 /*
197191 * shl_j is used to do asynchronous notification (used in
@@ -1932,7 +1926,7 @@ tty_init_talking(void)
19321926 break;
19331927 case 2:
19341928 #ifndef MKSH_DISABLE_TTY_WARNING
1935- warningf(false, Tf_sD_s_s, Tcant_find, Ttty_fd,
1929+ warningf(false, Tf_s_sD_s, Tcant_find, Ttty_fd,
19361930 cstrerror(errno));
19371931 #endif
19381932 break;
--- a/src/lex.c
+++ b/src/lex.c
@@ -23,7 +23,7 @@
2323
2424 #include "sh.h"
2525
26-__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.247 2018/01/14 01:44:01 tg Exp $");
26+__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.250 2018/10/20 18:34:14 tg Exp $");
2727
2828 /*
2929 * states while lexing word
@@ -77,12 +77,17 @@ typedef struct lex_state {
7777 short nparen;
7878 /* type of this state */
7979 uint8_t type;
80+ /* extra flags */
81+ uint8_t ls_flags;
8082 } Lex_state;
8183 #define ls_base u.base
8284 #define ls_start u.start
8385 #define ls_bool u.abool
8486 #define ls_adelim u.adelim
8587
88+/* ls_flags */
89+#define LS_HEREDOC BIT(0)
90+
8691 typedef struct {
8792 Lex_state *base;
8893 Lex_state *end;
@@ -147,9 +152,11 @@ getsc_r(int c)
147152 #define STATE_BSIZE 8
148153
149154 #define PUSH_STATE(s) do { \
155+ uint8_t state_flags = statep->ls_flags; \
150156 if (++statep == state_info.end) \
151157 statep = push_state_i(&state_info, statep); \
152158 state = statep->type = (s); \
159+ statep->ls_flags = state_flags; \
153160 } while (/* CONSTCOND */ 0)
154161
155162 #define POP_STATE() do { \
@@ -242,6 +249,7 @@ yylex(int cf)
242249
243250 /* Initial state: one of SWORD SLETPAREN SHEREDELIM SBASE */
244251 statep->type = state;
252+ statep->ls_flags = (cf & HEREDOC) ? LS_HEREDOC : 0;
245253
246254 /* collect non-special or quoted characters to form word */
247255 while (!((c = getsc()) == 0 ||
@@ -319,7 +327,7 @@ yylex(int cf)
319327 break;
320328 case ORD('\''):
321329 open_ssquote_unless_heredoc:
322- if ((cf & HEREDOC))
330+ if ((statep->ls_flags & LS_HEREDOC))
323331 goto store_char;
324332 *wp++ = OQUOTE;
325333 ignore_backslash_newline++;
@@ -357,7 +365,7 @@ yylex(int cf)
357365 c = getsc();
358366 switch (c) {
359367 case ORD('"'):
360- if ((cf & HEREDOC))
368+ if ((statep->ls_flags & LS_HEREDOC))
361369 goto heredocquote;
362370 /* FALLTHROUGH */
363371 case ORD('\\'):
@@ -388,6 +396,8 @@ yylex(int cf)
388396 if ((unsigned int)c == ORD('(' /*)*/)) {
389397 *wp++ = EXPRSUB;
390398 PUSH_SRETRACE(SASPAREN);
399+ /* unneeded? */
400+ /*statep->ls_flags &= ~LS_HEREDOC;*/
391401 statep->nparen = 2;
392402 *retrace_info->xp++ = '(';
393403 } else {
@@ -434,6 +444,8 @@ yylex(int cf)
434444 *wp++ = ADELIM;
435445 *wp++ = ':';
436446 PUSH_STATE(SBRACE);
447+ /* perhaps unneeded? */
448+ statep->ls_flags &= ~LS_HEREDOC;
437449 PUSH_STATE(SADELIM);
438450 statep->ls_adelim.delimiter = ':';
439451 statep->ls_adelim.num = 1;
@@ -449,6 +461,8 @@ yylex(int cf)
449461 }
450462 ungetsc(c);
451463 PUSH_STATE(SBRACE);
464+ /* perhaps unneeded? */
465+ statep->ls_flags &= ~LS_HEREDOC;
452466 PUSH_STATE(SADELIM);
453467 statep->ls_adelim.delimiter = ':';
454468 statep->ls_adelim.num = 2;
@@ -466,6 +480,8 @@ yylex(int cf)
466480 } else
467481 ungetsc(c);
468482 PUSH_STATE(SBRACE);
483+ /* perhaps unneeded? */
484+ statep->ls_flags &= ~LS_HEREDOC;
469485 PUSH_STATE(SADELIM);
470486 statep->ls_adelim.delimiter = '/';
471487 statep->ls_adelim.num = 1;
@@ -489,6 +505,8 @@ yylex(int cf)
489505 PUSH_STATE(STBRACEBOURNE);
490506 else
491507 PUSH_STATE(STBRACEKORN);
508+ /* single-quotes-in-heredoc-trim */
509+ statep->ls_flags &= ~LS_HEREDOC;
492510 } else {
493511 ungetsc(c);
494512 if (state == SDQUOTE ||
@@ -496,6 +514,8 @@ yylex(int cf)
496514 PUSH_STATE(SQBRACE);
497515 else
498516 PUSH_STATE(SBRACE);
517+ /* here no LS_HEREDOC removal */
518+ /* single-quotes-in-heredoc-braces */
499519 }
500520 } else if (ctype(c, C_ALPHX)) {
501521 *wp++ = OSUBST;
@@ -601,7 +621,8 @@ yylex(int cf)
601621 case SSQUOTE:
602622 if ((unsigned int)c == ORD('\'')) {
603623 POP_STATE();
604- if ((cf & HEREDOC) || state == SQBRACE)
624+ if ((statep->ls_flags & LS_HEREDOC) ||
625+ state == SQBRACE)
605626 goto store_char;
606627 *wp++ = CQUOTE;
607628 ignore_backslash_newline--;
@@ -1155,7 +1176,7 @@ readhere(struct ioword *iop)
11551176 /* Newline terminates here document marker */
11561177 goto heredoc_found_terminator;
11571178 }
1158- } else if (c == *eofp++)
1179+ } else if ((unsigned int)c == ord(*eofp++))
11591180 /* store; then read and compare next character */
11601181 goto heredoc_store_and_loop;
11611182 /* nope, mismatch; read until end of line */
@@ -1338,7 +1359,7 @@ getsc_line(Source *s)
13381359 {
13391360 char *xp = Xstring(s->xs, xp), *cp;
13401361 bool interactive = Flag(FTALKING) && s->type == SSTDIN;
1341- bool have_tty = tobool(interactive && (s->flags & SF_TTY));
1362+ bool have_tty = interactive && (s->flags & SF_TTY) && tty_hasstate;
13421363
13431364 /* Done here to ensure nothing odd happens when a timeout occurs */
13441365 XcheckN(s->xs, xp, LINE);
--- a/src/lksh.1
+++ b/src/lksh.1
@@ -1,6 +1,6 @@
1-.\" $MirOS: src/bin/mksh/lksh.1,v 1.23 2017/04/02 13:38:02 tg Exp $
1+.\" $MirOS: src/bin/mksh/lksh.1,v 1.25 2018/12/25 19:38:08 tg Exp $
22 .\"-
3-.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017
3+.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017, 2018
44 .\" mirabilos <m@mirbsd.org>
55 .\"
66 .\" Provided that these terms and disclaimer and all copyright notices
@@ -74,7 +74,7 @@
7474 .\" with -mandoc, it might implement .Mx itself, but we want to
7575 .\" use our own definition. And .Dd must come *first*, always.
7676 .\"
77-.Dd $Mdocdate: April 2 2017 $
77+.Dd $Mdocdate: December 25 2018 $
7878 .\"
7979 .\" Check which macro package we use, and do other -mdoc setup.
8080 .\"
@@ -82,6 +82,7 @@
8282 . if \*[.T]utf8 .tr \[la]\*(Lt
8383 . if \*[.T]utf8 .tr \[ra]\*(Gt
8484 . ie d volume-ds-1 .ds tT gnu
85+. el .ie d doc-volume-ds-1 .ds tT gnp
8586 . el .ds tT bsd
8687 .\}
8788 .el .ds tT ucb
@@ -94,7 +95,7 @@
9495 . nr curr-font \n[.f]
9596 . nr curr-size \n[.ps]
9697 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
97-. ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
98+. ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx]
9899 . if !\n[arg-limit] \
99100 . if \n[.$] \{\
100101 . ds macro-name Mx
@@ -120,19 +121,51 @@
120121 . ds sP \s0
121122 . ds tN \*[Tn-font-size]
122123 .\}
124+.el .ie "\*(tT"gnp" \{\
125+. eo
126+. de Mx
127+. nr doc-curr-font \n[.f]
128+. nr doc-curr-size \n[.ps]
129+. ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u]
130+. ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx]
131+. if !\n[doc-arg-limit] \
132+. if \n[.$] \{\
133+. ds doc-macro-name Mx
134+. doc-parse-args \$@
135+. \}
136+. if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\
137+. nr doc-arg-ptr +1
138+. ie (\n[doc-type\n[doc-arg-ptr]] == 2) \
139+. as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]]
140+. el \
141+. nr doc-arg-ptr -1
142+. \}
143+. ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1]
144+. nr doc-type\n[doc-arg-ptr] 2
145+. ds doc-space\n[doc-arg-ptr] "\*[doc-space]
146+. nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr])
147+. nr doc-arg-limit \n[doc-arg-ptr]
148+. if \n[doc-num-args] \
149+. doc-parse-space-vector
150+. doc-print-recursive
151+..
152+. ec
153+. ds sP \s0
154+. ds tN \*[doc-Tn-font-size]
155+.\}
123156 .el \{\
124157 . de Mx
125158 . nr cF \\n(.f
126159 . nr cZ \\n(.s
127160 . ds aa \&\f\\n(cF\s\\n(cZ
128161 . if \\n(aC==0 \{\
129-. ie \\n(.$==0 \&MirOS\\*(aa
162+. ie \\n(.$==0 \&MirBSD\\*(aa
130163 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
131164 . \}
132165 . if \\n(aC>\\n(aP \{\
133166 . nr aP \\n(aP+1
134167 . ie \\n(C\\n(aP==2 \{\
135-. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
168+. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa
136169 . ie \\n(aC>\\n(aP \{\
137170 . nr aP \\n(aP+1
138171 . nR
@@ -140,7 +173,7 @@
140173 . el .aZ
141174 . \}
142175 . el \{\
143-. as b1 \&MirOS\\*(aa
176+. as b1 \&MirBSD\\*(aa
144177 . nR
145178 . \}
146179 . \}
@@ -304,9 +337,11 @@ is not exactly specified.
304337 .Pp
305338 Talk to the
306339 .Mx
307-development team using the mailing list at
308-.Aq miros\-mksh@mirbsd.org
309-or the
340+development team and users using the mailing list at
341+.Aq Mt miros\-mksh@mirbsd.org
342+(please note the EU-DSGVO/GDPR notice on
343+.Pa http://www.mirbsd.org/rss.htm#lists
344+and in the SMTP banner!) or the
310345 .Li \&#\&!/bin/mksh
311346 .Pq or Li \&#ksh
312347 IRC channel at
--- a/src/main.c
+++ b/src/main.c
@@ -5,7 +5,8 @@
55
66 /*-
77 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
8- * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
8+ * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
9+ * 2019
910 * mirabilos <m@mirbsd.org>
1011 *
1112 * Provided that these terms and disclaimer and all copyright notices
@@ -34,7 +35,7 @@
3435 #include <locale.h>
3536 #endif
3637
37-__RCSID("$MirOS: src/bin/mksh/main.c,v 1.347 2018/01/13 21:45:07 tg Exp $");
38+__RCSID("$MirOS: src/bin/mksh/main.c,v 1.351 2019/01/05 13:24:18 tg Exp $");
3839
3940 #ifndef MKSHRC_PATH
4041 #define MKSHRC_PATH "~/.mkshrc"
@@ -463,7 +464,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
463464 /* Set this before parsing arguments */
464465 Flag(FPRIVILEGED) = (kshuid != ksheuid || kshgid != kshegid) ? 2 : 0;
465466
466- /* this to note if monitor is set on command line (see below) */
467+ /* record if monitor is set on command line (see j_init() in jobs.c) */
467468 #ifndef MKSH_UNEMPLOYED
468469 Flag(FMONITOR) = 127;
469470 #endif
@@ -519,7 +520,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
519520 #else
520521 s->file = argv[argi++];
521522 #endif
522- s->u.shf = shf_open(s->file, O_RDONLY, 0,
523+ s->u.shf = shf_open(s->file, O_RDONLY | O_MAYEXEC, 0,
523524 SHF_MAPHI | SHF_CLEXEC);
524525 if (s->u.shf == NULL) {
525526 shl_stdout_ok = false;
@@ -719,7 +720,7 @@ include(const char *name, int argc, const char **argv, bool intr_ok)
719720 volatile int old_argc;
720721 int i;
721722
722- shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
723+ shf = shf_open(name, O_RDONLY | O_MAYEXEC, 0, SHF_MAPHI | SHF_CLEXEC);
723724 if (shf == NULL)
724725 return (-1);
725726
@@ -1965,7 +1966,7 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool forread)
19651966 /* OSF/1 processes lnext when ~icanon */
19661967 cb.c_cc[VLNEXT] = _POSIX_VDISABLE;
19671968 #endif
1968- /* SunOS 4.1.x & OSF/1 processes discard(flush) when ~icanon */
1969+ /* SunOS 4.1.x and OSF/1 process discard(flush) when ~icanon */
19691970 #if defined(VDISCARD) && defined(_POSIX_VDISABLE)
19701971 cb.c_cc[VDISCARD] = _POSIX_VDISABLE;
19711972 #endif
@@ -2061,6 +2062,7 @@ void
20612062 recheck_ctype(void)
20622063 {
20632064 const char *ccp;
2065+ uint8_t old_utfmode = UTFMODE;
20642066
20652067 ccp = str_val(global("LC_ALL"));
20662068 if (ccp == null)
@@ -2078,7 +2080,7 @@ recheck_ctype(void)
20782080 UTFMODE = 1;
20792081 #endif
20802082
2081- if (Flag(FPOSIX))
2083+ if (Flag(FPOSIX) && UTFMODE && !old_utfmode)
20822084 warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompliant");
20832085 }
20842086 #endif
--- a/src/misc.c
+++ b/src/misc.c
@@ -32,7 +32,7 @@
3232 #include <grp.h>
3333 #endif
3434
35-__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.291 2018/01/14 00:03:03 tg Exp $");
35+__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.293 2018/08/10 02:53:35 tg Exp $");
3636
3737 #define KSH_CHVT_FLAG
3838 #ifdef MKSH_SMALL
@@ -1346,7 +1346,14 @@ print_value_quoted(struct shf *shf, const char *s)
13461346 const unsigned char *p = (const unsigned char *)s;
13471347 bool inquote = true;
13481348
1349- /* first, check whether any quotes are needed */
1349+ /* first, special-case empty strings (for re-entrancy) */
1350+ if (!*s) {
1351+ shf_putc('\'', shf);
1352+ shf_putc('\'', shf);
1353+ return;
1354+ }
1355+
1356+ /* non-empty; check whether any quotes are needed */
13501357 while (rtt2asc(c = *p++) >= 32)
13511358 if (ctype(c, C_QUOTE | C_SPC))
13521359 inquote = false;
@@ -2449,7 +2456,7 @@ getrusage(int what, struct rusage *ru)
24492456 * and fp (put back a char) for backslash escapes,
24502457 * assuming the first call to *fg gets the char di-
24512458 * rectly after the backslash; return the character
2452- * (0..0xFF), Unicode (wc + 0x100), or -1 if no known
2459+ * (0..0xFF), UCS (wc + 0x100), or -1 if no known
24532460 * escape sequence was found
24542461 */
24552462 int
@@ -2531,9 +2538,9 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int))
25312538 /**
25322539 * x: look for a hexadecimal number with up to
25332540 * two (C style: arbitrary) digits; convert
2534- * to raw octet (C style: Unicode if >0xFF)
2541+ * to raw octet (C style: UCS if >0xFF)
25352542 * u/U: look for a hexadecimal number with up to
2536- * four (U: eight) digits; convert to Unicode
2543+ * four (U: eight) digits; convert to UCS
25372544 */
25382545 wc = 0;
25392546 n = 0;
@@ -2555,7 +2562,7 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int))
25552562 if (!n)
25562563 goto unknown_escape;
25572564 if ((cstyle && wc > 0xFF) || fc != 'x')
2558- /* Unicode marker */
2565+ /* UCS marker */
25592566 wc += 0x100;
25602567 break;
25612568 case '\'':
--- a/src/mksh.1
+++ b/src/mksh.1
@@ -1,8 +1,9 @@
1-.\" $MirOS: src/bin/mksh/mksh.1,v 1.451 2017/08/16 21:40:14 tg Exp $
1+.\" $MirOS: src/bin/mksh/mksh.1,v 1.463 2019/03/01 16:17:31 tg Exp $
22 .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
33 .\"-
44 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5-.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
5+.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
6+.\" 2018, 2019
67 .\" mirabilos <m@mirbsd.org>
78 .\"
89 .\" Provided that these terms and disclaimer and all copyright notices
@@ -76,7 +77,7 @@
7677 .\" with -mandoc, it might implement .Mx itself, but we want to
7778 .\" use our own definition. And .Dd must come *first*, always.
7879 .\"
79-.Dd $Mdocdate: August 16 2017 $
80+.Dd $Mdocdate: March 1 2019 $
8081 .\"
8182 .\" Check which macro package we use, and do other -mdoc setup.
8283 .\"
@@ -84,6 +85,7 @@
8485 . if \*[.T]utf8 .tr \[la]\*(Lt
8586 . if \*[.T]utf8 .tr \[ra]\*(Gt
8687 . ie d volume-ds-1 .ds tT gnu
88+. el .ie d doc-volume-ds-1 .ds tT gnp
8789 . el .ds tT bsd
8890 .\}
8991 .el .ds tT ucb
@@ -96,7 +98,7 @@
9698 . nr curr-font \n[.f]
9799 . nr curr-size \n[.ps]
98100 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
99-. ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
101+. ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx]
100102 . if !\n[arg-limit] \
101103 . if \n[.$] \{\
102104 . ds macro-name Mx
@@ -122,19 +124,51 @@
122124 . ds sP \s0
123125 . ds tN \*[Tn-font-size]
124126 .\}
127+.el .ie "\*(tT"gnp" \{\
128+. eo
129+. de Mx
130+. nr doc-curr-font \n[.f]
131+. nr doc-curr-size \n[.ps]
132+. ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u]
133+. ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx]
134+. if !\n[doc-arg-limit] \
135+. if \n[.$] \{\
136+. ds doc-macro-name Mx
137+. doc-parse-args \$@
138+. \}
139+. if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\
140+. nr doc-arg-ptr +1
141+. ie (\n[doc-type\n[doc-arg-ptr]] == 2) \
142+. as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]]
143+. el \
144+. nr doc-arg-ptr -1
145+. \}
146+. ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1]
147+. nr doc-type\n[doc-arg-ptr] 2
148+. ds doc-space\n[doc-arg-ptr] "\*[doc-space]
149+. nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr])
150+. nr doc-arg-limit \n[doc-arg-ptr]
151+. if \n[doc-num-args] \
152+. doc-parse-space-vector
153+. doc-print-recursive
154+..
155+. ec
156+. ds sP \s0
157+. ds tN \*[doc-Tn-font-size]
158+.\}
125159 .el \{\
126160 . de Mx
127161 . nr cF \\n(.f
128162 . nr cZ \\n(.s
129163 . ds aa \&\f\\n(cF\s\\n(cZ
130164 . if \\n(aC==0 \{\
131-. ie \\n(.$==0 \&MirOS\\*(aa
165+. ie \\n(.$==0 \&MirBSD\\*(aa
132166 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
133167 . \}
134168 . if \\n(aC>\\n(aP \{\
135169 . nr aP \\n(aP+1
136170 . ie \\n(C\\n(aP==2 \{\
137-. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
171+. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa
138172 . ie \\n(aC>\\n(aP \{\
139173 . nr aP \\n(aP+1
140174 . nR
@@ -142,7 +176,7 @@
142176 . el .aZ
143177 . \}
144178 . el \{\
145-. as b1 \&MirOS\\*(aa
179+. as b1 \&MirBSD\\*(aa
146180 . nR
147181 . \}
148182 . \}
@@ -1046,7 +1080,7 @@ and
10461080 .Dq Li \eu#### ,
10471081 .Dq #
10481082 means a hexadecimal digit, of which there may be none up to four or eight;
1049-these escapes translate a Unicode codepoint to UTF-8.
1083+these escapes translate a Universal Coded Character Set codepoint to UTF-8.
10501084 Furthermore,
10511085 .Dq Li \eE
10521086 and
@@ -1082,7 +1116,7 @@ and yield raw octets; hexadecimal sequences
10821116 greedily eat up as many hexadecimal digits
10831117 .Dq #
10841118 as they can and terminate with the first non-hexadecimal digit;
1085-these translate a Unicode codepoint to UTF-8.
1119+these translate a Universal Coded Character Set codepoint to UTF-8.
10861120 The sequence
10871121 .Dq Li \ec# ,
10881122 where
@@ -1364,6 +1398,10 @@ or
13641398 where
13651399 .Ar name
13661400 is a parameter name.
1401+Substitutions of an an array in scalar context, i.e. without an
1402+.Ar expr
1403+in the latter form mentioned above, expand the element with the key
1404+.Dq 0 .
13671405 Substitution of all array elements with
13681406 .Pf ${ Ns Ar name Ns \&[*]}
13691407 and
@@ -1519,11 +1557,7 @@ on it; if
15191557 .Ar word
15201558 is not needed, it is not evaluated.
15211559 .Pp
1522-The following forms of parameter substitution can also be used (if
1523-.Ar name
1524-is an array, the element with the key
1525-.Dq 0
1526-will be substituted in scalar context):
1560+The following forms of parameter substitution can also be used:
15271561 .Pp
15281562 .Bl -tag -width Ds -compact
15291563 .It Pf ${# Ns Ar name Ns \&}
@@ -1823,10 +1857,10 @@ built-in command will display the resulting directory when a match is found
18231857 in any search path other than the empty path.
18241858 .It Ev COLUMNS
18251859 Set to the number of columns on the terminal or window.
1826-Always set, defaults to 80, unless the
1827-value as reported by
1860+If never unset and not imported, always set dynamically;
1861+unless the value as reported by
18281862 .Xr stty 1
1829-is non-zero and sane enough (minimum is 12x3); similar for
1863+is non-zero and sane enough (minimum is 12x3), defaults to 80; similar for
18301864 .Ev LINES .
18311865 This parameter is used by the interactive line editing modes and by the
18321866 .Ic select ,
@@ -1995,7 +2029,7 @@ The line number of the function or shell script that is currently being
19952029 executed.
19962030 .It Ev LINES
19972031 Set to the number of lines on the terminal or window.
1998-Always set, defaults to 24.
2032+Defaults to 24; always set, unless imported or unset.
19992033 See
20002034 .Ev COLUMNS .
20012035 .It Ev OLDPWD
@@ -2651,7 +2685,8 @@ as required by the standard), as that's unsafe to do.
26512685 As a special
26522686 .Nm mksh
26532687 extension, numbers to the base of one are treated as either (8-bit
2654-transparent) ASCII or Unicode codepoints, depending on the shell's
2688+transparent) ASCII or Universal Coded Character Set codepoints,
2689+depending on the shell's
26552690 .Ic utf8\-mode
26562691 flag (current setting).
26572692 The
@@ -2664,7 +2699,7 @@ instead of
26642699 is also supported.
26652700 Note that NUL bytes (integral value of zero) cannot be used.
26662701 An unset or empty parameter evaluates to 0 in integer context.
2667-In Unicode mode, raw octets are mapped into the range EF80..EFFF as in
2702+In UTF-8 mode, raw octets are mapped into the range EF80..EFFF as in
26682703 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
26692704 If more than one octet in ASCII mode, or a sequence of more than one
26702705 octet not forming a valid and minimal CESU-8 sequence is passed, the
@@ -2903,8 +2938,6 @@ option is turned on for the function's duration.
29032938 The
29042939 .Dq export
29052940 attribute of functions is currently not used.
2906-In the original Korn shell,
2907-exported functions are visible to shell scripts that are executed.
29082941 .Pp
29092942 Since functions are executed in the current shell environment, parameter
29102943 assignments made inside functions are visible after the function completes.
@@ -4667,15 +4700,15 @@ the user CPU time (time spent running in user mode), and the system CPU time
46674700 (time spent running in kernel mode).
46684701 Times are reported to standard error; the format of the output is:
46694702 .Pp
4670-.Dl "0m0.00s real 0m0.00s user 0m0.00s system"
4703+.Dl "0m0.03s real 0m0.02s user 0m0.01s system"
46714704 .Pp
46724705 If the
46734706 .Fl p
46744707 option is given the output is slightly longer:
46754708 .Bd -literal -offset indent
4676-real 0.00
4677-user 0.00
4678-sys 0.00
4709+real 0.03
4710+user 0.02
4711+sys 0.01
46794712 .Ed
46804713 .Pp
46814714 It is an error to specify the
@@ -4700,8 +4733,8 @@ Print the accumulated user and system times used both by the shell
47004733 and by processes that the shell started which have exited.
47014734 The format of the output is:
47024735 .Bd -literal -offset indent
4703-0m0.00s 0m0.00s
4704-0m0.00s 0m0.00s
4736+0m0.01s 0m0.00s
4737+0m0.04s 0m0.02s
47054738 .Ed
47064739 .Pp
47074740 .It Ic trap Ar n Op Ar signal ...
@@ -4932,9 +4965,9 @@ when used with the
49324965 .Fl i
49334966 option which meant upper case letters would never be used for bases greater
49344967 than 10.
4935-See the
4968+See
49364969 .Fl U
4937-option.)
4970+above.)
49384971 .Pp
49394972 For functions,
49404973 .Fl u
@@ -4944,9 +4977,9 @@ See
49444977 above for the implications of this.
49454978 .It Fl x
49464979 Export attribute.
4947-Parameters (or functions) are placed in the environment of
4948-any executed commands.
4949-Exported functions are not yet implemented.
4980+Parameters are placed in the environment of any executed commands.
4981+Functions cannot be exported for security reasons
4982+.Pq Dq shellshock .
49504983 .It Fl Z Ns Op Ar n
49514984 Zero fill attribute.
49524985 If not combined with
@@ -4954,7 +4987,7 @@ If not combined with
49544987 this is the same as
49554988 .Fl R ,
49564989 except zero padding is used instead of space padding.
4957-For integers, the number instead of the base is padded.
4990+For integers, the number is padded, not the base.
49584991 .El
49594992 .Pp
49604993 If any of the
@@ -5211,14 +5244,12 @@ or
52115244 .Ic set Fl o Ic monitor ) ,
52125245 as it is for interactive shells, the processes of a job are placed in their
52135246 own process group.
5214-Foreground jobs can be stopped by typing the suspend
5215-character from the terminal (normally \*(haZ), jobs can be restarted in either the
5216-foreground or background using the
5247+Foreground jobs can be stopped by typing the suspend character from
5248+the terminal (normally \*(haZ); jobs can be restarted in either the
5249+foreground or background using the commands
52175250 .Ic fg
52185251 and
5219-.Ic bg
5220-commands, and the state of the terminal is saved or restored when a foreground
5221-job is stopped or restarted, respectively.
5252+.Ic bg .
52225253 .Pp
52235254 Note that only commands that create processes (e.g. asynchronous commands,
52245255 subshell commands and non-built-in, non-function commands) can be stopped;
@@ -5332,6 +5363,17 @@ If another attempt
53325363 is immediately made to exit the shell, the running jobs are sent a
53335364 .Dv SIGHUP
53345365 signal and the shell exits.
5366+.Ss Terminal state
5367+The state of the controlling terminal can be modified by a command
5368+executed in the foreground, whether or not job control is enabled, but
5369+the modified terminal state is only kept past the job's lifetime and used
5370+for later command invocations if the command exits successfully (i.e.\&
5371+with an exit status of 0).
5372+When such a job is momentarily stopped or restarted, the terminal state
5373+is saved and restored, respectively, but it will not be kept afterwards.
5374+In interactive mode, when line editing is enabled, the terminal state is
5375+saved before being reconfigured by the shell for the line editor, then
5376+restored before running a command.
53355377 .Ss POSIX mode
53365378 Entering
53375379 .Ic set Fl o Ic posix
@@ -6650,7 +6692,7 @@ locale.
66506692 .Ic utf8\-mode
66516693 .Em must
66526694 be disabled in POSIX mode, and it
6653-only supports the Unicode BMP (Basic Multilingual Plane) and maps
6695+only supports the BMP (Basic Multilingual Plane) of UCS and maps
66546696 raw octets into the U+EF80..U+EFFF wide character range; compare
66556697 .Sx Arithmetic expressions .
66566698 The following
@@ -6671,7 +6713,24 @@ case ${KSH_VERSION:\-} in
66716713 esac ;;
66726714 esac
66736715 .Ed
6674-In near future, (Unicode) locale tracking will be implemented though.
6716+In near future, (UTF-8) locale tracking will be implemented though.
6717+.Pp
6718+Using
6719+.Ic set Fl o Ic pipefail
6720+makes the following construct error out:
6721+.Bd -literal -offset indent
6722+set -e
6723+for x in 1 2; do
6724+ false && echo $x
6725+done \*(Ba cat
6726+.Ed
6727+This is because, while the
6728+.Dq Li &&\&
6729+ensures that the inner command's failure is not taken, it sets
6730+the entire for..done loop's errorlevel, which is passed on by
6731+.Fl o Ic pipefail .
6732+Invert the inner command:
6733+.Li true \*(Ba\*(Ba echo $x
66756734 .Pp
66766735 See also the FAQ below.
66776736 .Sh BUGS
@@ -6697,7 +6756,7 @@ for the in-memory portion of the history is slow, should use
66976756 .Xr memmove 3 .
66986757 .Pp
66996758 This document attempts to describe
6700-.Nm mksh\ R56
6759+.Nm mksh\ R57
67016760 and up,
67026761 .\" with vendor patches from insert-your-name-here,
67036762 compiled without any options impacting functionality, such as
@@ -6713,10 +6772,11 @@ for an operating environment supporting all of its advanced needs.
67136772 .Pp
67146773 Please report bugs in
67156774 .Nm
6716-to the
6775+to the public development mailing list at
67176776 .Aq Mt miros\-mksh@mirbsd.org
6718-mailing list
6719-or in the
6777+(please note the EU-DSGVO/GDPR notice on
6778+.Pa http://www.mirbsd.org/rss.htm#lists
6779+and in the SMTP banner!) or in the
67206780 .Li \&#\&!/bin/mksh
67216781 .Pq or Li \&#ksh
67226782 IRC channel at
@@ -6782,6 +6842,10 @@ Run the shell in POSIX mode (and possibly
67826842 instead of
67836843 .Nm mksh ) :
67846844 .Dl set \-o posix
6845+.Ss "I forbid stat(2) in my SELinux policy, and some things do not work!"
6846+Don't break Unix.
6847+Read up on the GIGO principle.
6848+Duh.
67856849 .Ss "My prompt from <some other shell> does not work!"
67866850 Contact us on the mailing list or on IRC, we'll convert it for you.
67876851 .Ss "Something is going wrong with my while...read loop"
--- a/src/sh.h
+++ b/src/sh.h
@@ -182,9 +182,9 @@
182182 #endif
183183
184184 #ifdef EXTERN
185-__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.858 2018/01/14 01:47:36 tg Exp $");
185+__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.870 2019/03/01 16:18:14 tg Exp $");
186186 #endif
187-#define MKSH_VERSION "R56 2018/01/14"
187+#define MKSH_VERSION "R57 2019/03/01"
188188
189189 /* arithmetic types: C implementation */
190190 #if !HAVE_CAN_INTTYPES
@@ -491,6 +491,10 @@ extern int __cdecl setegid(gid_t);
491491 #define O_BINARY 0
492492 #endif
493493
494+#ifndef O_MAYEXEC
495+#define O_MAYEXEC 0
496+#endif
497+
494498 #ifdef MKSH__NO_SYMLINK
495499 #undef S_ISLNK
496500 #define S_ISLNK(m) (/* CONSTCOND */ 0)
@@ -643,7 +647,7 @@ char *ucstrstr(char *, const char *);
643647 #endif
644648 #endif
645649
646-#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 563)
650+#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 571)
647651 #error Must run Build.sh to compile this.
648652 extern void thiswillneverbedefinedIhope(void);
649653 int
@@ -783,7 +787,7 @@ enum sh_flag {
783787 };
784788
785789 #define Flag(f) (shell_flags[(int)(f)])
786-#define UTFMODE Flag(FUNICODE)
790+#define UTFMODE Flag(FUNNYCODE)
787791
788792 /*
789793 * parsing & execution environment
@@ -1950,10 +1954,11 @@ struct ioword {
19501954 #define IOSKIP BIT(5) /* <<-, skip ^\t* */
19511955 #define IOCLOB BIT(6) /* >|, override -o noclobber */
19521956 #define IORDUP BIT(7) /* x<&y (as opposed to x>&y) */
1953-#define IONAMEXP BIT(8) /* name has been expanded */
1954-#define IOBASH BIT(9) /* &> etc. */
1955-#define IOHERESTR BIT(10) /* <<< (here string) */
1956-#define IONDELIM BIT(11) /* null delimiter (<<) */
1957+#define IODUPSELF BIT(8) /* x>&x (as opposed to x>&y) */
1958+#define IONAMEXP BIT(9) /* name has been expanded */
1959+#define IOBASH BIT(10) /* &> etc. */
1960+#define IOHERESTR BIT(11) /* <<< (here string) */
1961+#define IONDELIM BIT(12) /* null delimiter (<<) */
19571962
19581963 /* execute/exchild flags */
19591964 #define XEXEC BIT(0) /* execute without forking */
@@ -2637,7 +2642,7 @@ const char *wdscan(const char *, int);
26372642 #define WDS_TPUTS BIT(0) /* tputS (dumpwdvar) mode */
26382643 char *wdstrip(const char *, int);
26392644 void tfree(struct op *, Area *);
2640-void dumpchar(struct shf *, int);
2645+void dumpchar(struct shf *, unsigned char);
26412646 void dumptree(struct shf *, struct op *);
26422647 void dumpwdvar(struct shf *, const char *);
26432648 void dumpioact(struct shf *shf, struct op *t);
--- a/src/sh_flags.gen
+++ b/src/sh_flags.gen
@@ -21,7 +21,7 @@
2121
2222 #ifndef SHFLAGS_OPTCS
2323 #if defined(SHFLAGS_DEFNS)
24-__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.5 2017/02/18 02:33:15 tg Exp $");
24+__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.6 2018/08/10 02:53:39 tg Exp $");
2525 #elif defined(SHFLAGS_ENUMS)
2626 #define FN(sname,cname,flags,ochar) cname,
2727 #define F0(sname,cname,flags,ochar) cname = 0,
@@ -77,7 +77,7 @@ FN("sh", FSH, OF_ANY, 0)
7777 FN("stdin", FSTDIN, OF_CMDLINE, 's')
7878 #endif
7979 FN("trackall", FTRACKALL, OF_ANY, 'h')
80-FN("utf8-mode", FUNICODE, OF_ANY, 'U')
80+FN("utf8-mode", FUNNYCODE, OF_ANY, 'U')
8181 FN("verbose", FVERBOSE, OF_ANY, 'v')
8282 #ifndef MKSH_NO_CMDLINE_EDITING
8383 FN("vi", FVI, OF_ANY, 0)
--- a/src/sh_flags.opt
+++ b/src/sh_flags.opt
@@ -19,7 +19,7 @@
1919 */
2020
2121 @SHFLAGS_DEFNS
22-__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.5 2017/02/18 02:33:15 tg Exp $");
22+__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.6 2018/08/10 02:53:39 tg Exp $");
2323 @SHFLAGS_ENUMS
2424 #define FN(sname,cname,flags,ochar) cname,
2525 #define F0(sname,cname,flags,ochar) cname = 0,
@@ -153,7 +153,7 @@ FN("trackall", FTRACKALL, OF_ANY
153153
154154 /* -U enable UTF-8 processing (non-standard) */
155155 >U|
156-FN("utf8-mode", FUNICODE, OF_ANY
156+FN("utf8-mode", FUNNYCODE, OF_ANY
157157
158158 /* -v echo input */
159159 >v|
--- a/src/shf.c
+++ b/src/shf.c
@@ -27,7 +27,7 @@
2727
2828 #include "sh.h"
2929
30-__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.97 2018/01/14 01:28:16 tg Exp $");
30+__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.98 2018/08/10 02:53:39 tg Exp $");
3131
3232 /* flags to shf_emptybuf() */
3333 #define EB_READSW 0x01 /* about to switch to reading */
@@ -1304,7 +1304,7 @@ ebcdic_init(void)
13041304 * and the C1 control characters other than NEL are
13051305 * hopeless, but we map EBCDIC NEL to ASCII LF so we
13061306 * cannot even use C1 NEL.
1307- * If ever we map to Unicode, bump the table width to
1307+ * If ever we map to UCS, bump the table width to
13081308 * an unsigned int, and or the raw unconverted EBCDIC
13091309 * values with 0x01000000 instead.
13101310 */
--- a/src/tree.c
+++ b/src/tree.c
@@ -23,7 +23,7 @@
2323
2424 #include "sh.h"
2525
26-__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.95 2018/01/14 00:03:05 tg Exp $");
26+__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.97 2018/10/20 18:46:00 tg Exp $");
2727
2828 #define INDENT 8
2929
@@ -808,7 +808,7 @@ vistree(char *dst, size_t sz, struct op *t)
808808 c = ksh_unctrl(c);
809809 } else if (UTFMODE && rtt2asc(c) > 0x7F) {
810810 /* better not try to display broken multibyte chars */
811- /* also go easy on the Unicode: no U+FFFD here */
811+ /* also go easy on the UCS: no U+FFFD here */
812812 c = ORD('?');
813813 }
814814 *dst++ = c;
@@ -821,7 +821,7 @@ vistree(char *dst, size_t sz, struct op *t)
821821
822822 #ifdef DEBUG
823823 void
824-dumpchar(struct shf *shf, int c)
824+dumpchar(struct shf *shf, unsigned char c)
825825 {
826826 if (ksh_isctrl(c)) {
827827 /* C0 or C1 control character or DEL */
--- a/src/var.c
+++ b/src/var.c
@@ -28,7 +28,7 @@
2828 #include <sys/sysctl.h>
2929 #endif
3030
31-__RCSID("$MirOS: src/bin/mksh/var.c,v 1.223 2018/01/13 23:55:15 tg Exp $");
31+__RCSID("$MirOS: src/bin/mksh/var.c,v 1.226 2018/07/15 17:21:24 tg Exp $");
3232
3333 /*-
3434 * Variables
@@ -54,7 +54,7 @@ static int special(const char *);
5454 static void unspecial(const char *);
5555 static void getspec(struct tbl *);
5656 static void setspec(struct tbl *);
57-static void unsetspec(struct tbl *);
57+static void unsetspec(struct tbl *, bool);
5858 static int getint(struct tbl *, mksh_ari_u *, bool);
5959 static const char *array_index_calc(const char *, bool *, uint32_t *);
6060
@@ -105,7 +105,7 @@ popblock(void)
105105 if ((vq = global(vp->name))->flag & ISSET)
106106 setspec(vq);
107107 else
108- unsetspec(vq);
108+ unsetspec(vq, false);
109109 }
110110 if (l->flags & BF_DOGETOPTS)
111111 user_opt = l->getopts_state;
@@ -707,7 +707,7 @@ formatstr(struct tbl *vp, const char *s)
707707 if (vp->flag & ZEROFIL)
708708 while (*s == '0')
709709 s++;
710- shf_snprintf(p, nlen + 1, "%-*.*s",
710+ shf_snprintf(p, psiz, "%-*.*s",
711711 vp->u2.field, vp->u2.field, s);
712712 }
713713 } else
@@ -1054,7 +1054,7 @@ unset(struct tbl *vp, int flags)
10541054 vp->flag &= SPECIAL | ((flags & 1) ? 0 : ARRAY|DEFINED);
10551055 if (vp->flag & SPECIAL)
10561056 /* responsible for 'unspecial'ing var */
1057- unsetspec(vp);
1057+ unsetspec(vp, true);
10581058 }
10591059
10601060 /*
@@ -1441,7 +1441,7 @@ setspec(struct tbl *vp)
14411441 }
14421442
14431443 static void
1444-unsetspec(struct tbl *vp)
1444+unsetspec(struct tbl *vp, bool dounset)
14451445 {
14461446 /*
14471447 * AT&T ksh man page says OPTIND, OPTARG and _ lose special
@@ -1466,13 +1466,13 @@ unsetspec(struct tbl *vp)
14661466 #endif
14671467 case V_IFS:
14681468 set_ifs(TC_IFSWS);
1469- break;
1469+ return;
14701470 case V_PATH:
14711471 afree(path, APERM);
14721472 strdupx(path, def_path, APERM);
14731473 /* clear tracked aliases */
14741474 flushcom(true);
1475- break;
1475+ return;
14761476 #ifndef MKSH_NO_CMDLINE_EDITING
14771477 case V_TERM:
14781478 x_initterm(null);
@@ -1484,14 +1484,14 @@ unsetspec(struct tbl *vp)
14841484 afree(tmpdir, APERM);
14851485 tmpdir = NULL;
14861486 }
1487- break;
1487+ return;
14881488 case V_LINENO:
14891489 case V_RANDOM:
14901490 case V_SECONDS:
14911491 case V_TMOUT:
14921492 /* AT&T ksh leaves previous value in place */
14931493 unspecial(vp->name);
1494- break;
1494+ return;
14951495 #ifdef MKSH_EARLY_LOCALE_TRACKING
14961496 case V_LANG:
14971497 case V_LC_ALL:
@@ -1499,6 +1499,12 @@ unsetspec(struct tbl *vp)
14991499 recheck_ctype();
15001500 return;
15011501 #endif
1502+ /* should not become unspecial, but allow unsetting */
1503+ case V_COLUMNS:
1504+ case V_LINES:
1505+ if (dounset)
1506+ unspecial(vp->name);
1507+ return;
15021508 }
15031509 }
15041510
@@ -1617,6 +1623,9 @@ set_array(const char *var, bool reset, const char **vals)
16171623 unset(vp, 1);
16181624 /* allocate-by-access the [0] element to keep in scope */
16191625 arraysearch(vp, 0);
1626+ /* honour set -o allexport */
1627+ if (Flag(FEXPORT))
1628+ typeset(ccp, EXPORT, 0, 0, 0);
16201629 }
16211630 /*
16221631 * TODO: would be nice for assignment to completely succeed or
Show on old repository browser