external/mksh
修订版 | 8cd2fbe92f4e6a4df6d6ff47942dce2160bdbf0f (tree) |
---|---|
时间 | 2019-04-03 03:30:20 |
作者 | Bill Rassieur <rassb@goog...> |
Commiter | Bill Rassieur |
Merge master@5428150 into git_qt-dev-plus-aosp.
Change-Id: I30afca794eaa5447375ca5464546a1ecadfb16a6
BUG: 129345239
@@ -107,7 +107,7 @@ cc_defaults { | ||
107 | 107 | "-DHAVE_SYS_ERRLIST_DECL=0", |
108 | 108 | "-DHAVE_SYS_SIGLIST_DECL=1", |
109 | 109 | "-DHAVE_PERSISTENT_HISTORY=0", |
110 | - "-DMKSH_BUILD_R=563", | |
110 | + "-DMKSH_BUILD_R=571", | |
111 | 111 | |
112 | 112 | // Additional flags |
113 | 113 | "-DMKSH_DEFAULT_PROFILEDIR=\"/system/etc\"", |
@@ -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 | |
3 | 4 | @@ -103,7 +103,9 @@ |
4 | 5 | {Tsgbreak, c_brkcont}, |
5 | 6 | {T__builtin, c_builtin}, |
@@ -31,11 +32,12 @@ | ||
31 | 32 | #ifdef __MirBSD__ |
32 | 33 | /* alias to "true" for historical reasons */ |
33 | 34 | {"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(); | |
39 | 41 | |
40 | 42 | + /* override default PATH regardless of environment */ |
41 | 43 | +#ifdef MKSH_DEFPATH_OVERRIDE |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #!/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 $' | |
3 | 3 | #- |
4 | 4 | # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
5 | 5 | # 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
@@ -418,6 +418,7 @@ ac_flags() { | ||
418 | 418 | #include <unistd.h> |
419 | 419 | int main(void) { return (isatty(0)); } |
420 | 420 | EOF |
421 | + #' | |
421 | 422 | fi |
422 | 423 | eval fv=\$HAVE_CAN_`upper $vn` |
423 | 424 | if test -n "$fl"; then |
@@ -1060,11 +1061,12 @@ AIX) | ||
1060 | 1061 | Darwin) |
1061 | 1062 | vv '|' "hwprefs machine_type os_type os_class >&2" |
1062 | 1063 | vv '|' "sw_vers >&2" |
1063 | - vv '|' "system_profiler SPSoftwareDataType SPHardwareDataType >&2" | |
1064 | + vv '|' "system_profiler -detailLevel mini SPSoftwareDataType SPHardwareDataType >&2" | |
1064 | 1065 | vv '|' "/bin/sh --version >&2" |
1065 | 1066 | vv '|' "xcodebuild -version >&2" |
1066 | 1067 | 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" | |
1068 | 1070 | ;; |
1069 | 1071 | IRIX*) |
1070 | 1072 | vv '|' "uname -a >&2" |
@@ -2427,7 +2429,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c | ||
2427 | 2429 | addsrcs USE_PRINTF_BUILTIN printf.c |
2428 | 2430 | test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN |
2429 | 2431 | test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" |
2430 | -add_cppflags -DMKSH_BUILD_R=563 | |
2432 | +add_cppflags -DMKSH_BUILD_R=571 | |
2431 | 2433 | |
2432 | 2434 | $e $bi$me: Finished configuration testing, now producing output.$ao |
2433 | 2435 |
@@ -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 $ | |
2 | 2 | # -*- mode: sh -*- |
3 | 3 | #- |
4 | 4 | # 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 | |
6 | 7 | # mirabilos <m@mirbsd.org> |
7 | 8 | # |
8 | 9 | # Provided that these terms and disclaimer and all copyright notices |
@@ -30,7 +31,7 @@ | ||
30 | 31 | # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date |
31 | 32 | |
32 | 33 | expected-stdout: |
33 | - @(#)MIRBSD KSH R56 2018/01/14 | |
34 | + @(#)MIRBSD KSH R57 2019/03/01 | |
34 | 35 | description: |
35 | 36 | Check base version of full shell |
36 | 37 | stdin: |
@@ -39,7 +40,7 @@ name: KSH_VERSION | ||
39 | 40 | category: !shell:legacy-yes |
40 | 41 | --- |
41 | 42 | expected-stdout: |
42 | - @(#)LEGACY KSH R56 2018/01/14 | |
43 | + @(#)LEGACY KSH R57 2019/03/01 | |
43 | 44 | description: |
44 | 45 | Check base version of legacy shell |
45 | 46 | stdin: |
@@ -162,6 +163,38 @@ stdin: | ||
162 | 163 | expected-stdout: |
163 | 164 | ; |
164 | 165 | --- |
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 | +--- | |
165 | 198 | name: alias-1 |
166 | 199 | description: |
167 | 200 | Check that recursion is detected/avoided in aliases. |
@@ -2455,7 +2488,7 @@ expected-stdout: | ||
2455 | 2488 | name: glob-range-3 |
2456 | 2489 | description: |
2457 | 2490 | 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) | |
2459 | 2492 | # breaks on Cygwin 1.7 (files are now UTF-16 or something) |
2460 | 2493 | # breaks on QNX 6.4.1 (says RT) |
2461 | 2494 | category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2,!os:os390 |
@@ -3033,6 +3066,19 @@ expected-stdout: | ||
3033 | 3066 | got four on fd#4 |
3034 | 3067 | got five on fd#5 |
3035 | 3068 | --- |
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 | +--- | |
3036 | 3082 | name: heredoc-comsub-1 |
3037 | 3083 | description: |
3038 | 3084 | Tests for here documents in COMSUB, taken from Austin ML |
@@ -3526,6 +3572,25 @@ stdin: | ||
3526 | 3572 | expected-stdout: |
3527 | 3573 | 'blah 1' |
3528 | 3574 | --- |
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 | +--- | |
3529 | 3594 | name: history-basic |
3530 | 3595 | description: |
3531 | 3596 | See if we can test history at all |
@@ -6835,6 +6900,21 @@ expected-stdout: | ||
6835 | 6900 | 3 10 . |
6836 | 6901 | 4 -2147483646 . |
6837 | 6902 | --- |
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 | +--- | |
6838 | 6918 | name: readonly-0 |
6839 | 6919 | description: |
6840 | 6920 | Ensure readonly is honoured for assignments and unset |
@@ -7065,7 +7145,7 @@ stdin: | ||
7065 | 7145 | print =4 |
7066 | 7146 | (exec lq) |
7067 | 7147 | 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/ | |
7069 | 7149 | --- |
7070 | 7150 | name: exec-ksh88 |
7071 | 7151 | description: |
@@ -7086,7 +7166,7 @@ stdin: | ||
7086 | 7166 | print =4 |
7087 | 7167 | (exec lq) |
7088 | 7168 | 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/ | |
7090 | 7170 | --- |
7091 | 7171 | name: xxx-what-do-you-call-this-1 |
7092 | 7172 | stdin: |
@@ -7179,6 +7259,32 @@ expected-stdout: | ||
7179 | 7259 | HI |
7180 | 7260 | 2 4 |
7181 | 7261 | --- |
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 | +--- | |
7182 | 7288 | name: xxx-set-option-1 |
7183 | 7289 | description: |
7184 | 7290 | Check option parsing in set |
@@ -7280,6 +7386,28 @@ expected-stdout: | ||
7280 | 7386 | trap: 4 |
7281 | 7387 | exit: 4 |
7282 | 7388 | --- |
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 | +--- | |
7283 | 7411 | name: xxx-clean-chars-1 |
7284 | 7412 | description: |
7285 | 7413 | Check MAGIC character is stuffed correctly |
@@ -7836,6 +7964,23 @@ expected-stdout: | ||
7836 | 7964 | EXtrap |
7837 | 7965 | = noeval-undef 1 . |
7838 | 7966 | --- |
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 | +--- | |
7839 | 7984 | name: exit-trap-interactive |
7840 | 7985 | description: |
7841 | 7986 | Check that interactive shell doesn't exit via EXIT trap on syntax error |
@@ -8444,12 +8589,32 @@ stdin: | ||
8444 | 8589 | expected-stdout: |
8445 | 8590 | <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1> |
8446 | 8591 | --- |
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 | +--- | |
8447 | 8612 | name: utf8bom-1 |
8448 | 8613 | description: |
8449 | 8614 | Check that the UTF-8 Byte Order Mark is ignored as the first |
8450 | 8615 | multibyte character of the shell input (with -c, from standard |
8451 | 8616 | 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) | |
8453 | 8618 | category: !os:darwin,!shell:ebcdic-yes |
8454 | 8619 | stdin: |
8455 | 8620 | mkdir foo |
@@ -10328,7 +10493,7 @@ expected-stdout: | ||
10328 | 10493 | --- |
10329 | 10494 | name: integer-base-one-3Ws |
10330 | 10495 | description: |
10331 | - some sample code for hexdumping Unicode | |
10496 | + some sample code for hexdumping UCS-2 | |
10332 | 10497 | not NUL safe; input lines must be NL terminated |
10333 | 10498 | stdin: |
10334 | 10499 | set -U |
@@ -10496,7 +10661,7 @@ expected-stdout: | ||
10496 | 10661 | --- |
10497 | 10662 | name: integer-base-one-3Wr |
10498 | 10663 | description: |
10499 | - some sample code for hexdumping Unicode; NUL and binary safe | |
10664 | + some sample code for hexdumping UCS-2; NUL and binary safe | |
10500 | 10665 | stdin: |
10501 | 10666 | set -U |
10502 | 10667 | { |
@@ -10616,7 +10781,7 @@ expected-stdout: | ||
10616 | 10781 | --- |
10617 | 10782 | name: integer-base-one-5A |
10618 | 10783 | description: |
10619 | - Check to see that we’re NUL and Unicode safe | |
10784 | + Check to see that we’re NUL and UCS safe | |
10620 | 10785 | category: !shell:ebcdic-yes |
10621 | 10786 | stdin: |
10622 | 10787 | set +U |
@@ -10630,7 +10795,7 @@ expected-stdout: | ||
10630 | 10795 | --- |
10631 | 10796 | name: integer-base-one-5E |
10632 | 10797 | description: |
10633 | - Check to see that we’re NUL and Unicode safe | |
10798 | + Check to see that we’re NUL and UCS safe | |
10634 | 10799 | category: !shell:ebcdic-no |
10635 | 10800 | stdin: |
10636 | 10801 | set +U |
@@ -10644,7 +10809,7 @@ expected-stdout: | ||
10644 | 10809 | --- |
10645 | 10810 | name: integer-base-one-5W |
10646 | 10811 | description: |
10647 | - Check to see that we’re NUL and Unicode safe | |
10812 | + Check to see that we’re NUL and UCS safe | |
10648 | 10813 | stdin: |
10649 | 10814 | set -U |
10650 | 10815 | print 'a\0b€c' >x |
@@ -11139,6 +11304,34 @@ stdin: | ||
11139 | 11304 | expected-stdout: |
11140 | 11305 | Fowl |
11141 | 11306 | --- |
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 | +--- | |
11142 | 11335 | name: comsub-1a |
11143 | 11336 | description: |
11144 | 11337 | COMSUB are now parsed recursively, so this works |
@@ -28,7 +28,7 @@ | ||
28 | 28 | |
29 | 29 | #ifndef MKSH_NO_CMDLINE_EDITING |
30 | 30 | |
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 $"); | |
32 | 32 | |
33 | 33 | /* |
34 | 34 | * in later versions we might use libtermcap for this, but since external |
@@ -3831,7 +3831,7 @@ vi_hook(int ch) | ||
3831 | 3831 | vs = save_es; |
3832 | 3832 | |
3833 | 3833 | i = (unsigned)srchlen; |
3834 | - while (--i >= n) | |
3834 | + while (i-- > n) | |
3835 | 3835 | vs->linelen -= char_len(locpat[i]); |
3836 | 3836 | srchlen = (int)n; |
3837 | 3837 | vs->cursor = vs->linelen; |
@@ -2,7 +2,8 @@ | ||
2 | 2 | |
3 | 3 | /*- |
4 | 4 | * 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 | |
6 | 7 | * mirabilos <m@mirbsd.org> |
7 | 8 | * |
8 | 9 | * Provided that these terms and disclaimer and all copyright notices |
@@ -23,7 +24,7 @@ | ||
23 | 24 | |
24 | 25 | #include "sh.h" |
25 | 26 | |
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 $"); | |
27 | 28 | |
28 | 29 | #ifndef MKSH_DEFAULT_EXECSHELL |
29 | 30 | #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" |
@@ -429,6 +430,12 @@ execute(struct op * volatile t, | ||
429 | 430 | up = makenv(); |
430 | 431 | restoresigs(); |
431 | 432 | 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 */ | |
432 | 439 | { |
433 | 440 | union mksh_ccphack cargs; |
434 | 441 |
@@ -820,7 +827,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, | ||
820 | 827 | if (!(tp->flag&ISSET)) { |
821 | 828 | if (tp->u2.errnov == ENOENT) { |
822 | 829 | rv = 127; |
823 | - warningf(true, Tf_sD_s, cp, Tnot_found); | |
830 | + warningf(true, Tf_sD_s_s, cp, | |
831 | + "inaccessible or", Tnot_found); | |
824 | 832 | } else { |
825 | 833 | rv = 126; |
826 | 834 | 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, | ||
862 | 870 | Leave: |
863 | 871 | if (flags & XEXEC) { |
864 | 872 | exstat = rv & 0xFF; |
865 | - unwind(LLEAVE); | |
873 | + unwind(LEXIT); | |
866 | 874 | } |
867 | 875 | return (rv); |
868 | 876 | } |
@@ -886,7 +894,7 @@ scriptexec(struct op *tp, const char **ap) | ||
886 | 894 | *tp->args-- = tp->str; |
887 | 895 | |
888 | 896 | #ifndef MKSH_SMALL |
889 | - if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) { | |
897 | + if ((fd = binopen2(tp->str, O_RDONLY | O_MAYEXEC)) >= 0) { | |
890 | 898 | unsigned char *cp; |
891 | 899 | #ifndef MKSH_EBCDIC |
892 | 900 | unsigned short m; |
@@ -1011,7 +1019,7 @@ scriptexec(struct op *tp, const char **ap) | ||
1011 | 1019 | cap.ro = ap; |
1012 | 1020 | execve(args.rw[0], args.rw, cap.rw); |
1013 | 1021 | |
1014 | - /* report both the programme that was run and the bogus interpreter */ | |
1022 | + /* report both the program that was run and the bogus interpreter */ | |
1015 | 1023 | errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno)); |
1016 | 1024 | } |
1017 | 1025 |
@@ -1485,9 +1493,11 @@ iosetup(struct ioword *iop, struct tbl *tp) | ||
1485 | 1493 | afree(sp, ATEMP); |
1486 | 1494 | return (-1); |
1487 | 1495 | } |
1488 | - if (u == (int)iop->unit) | |
1496 | + if (u == (int)iop->unit) { | |
1489 | 1497 | /* "dup from" == "dup to" */ |
1498 | + iop->ioflag |= IODUPSELF; | |
1490 | 1499 | return (0); |
1500 | + } | |
1491 | 1501 | break; |
1492 | 1502 | } |
1493 | 1503 | } |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
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 $"); | |
27 | 27 | |
28 | 28 | #define EXPRTOK_DEFNS |
29 | 29 | #include "exprtok.h" |
@@ -885,7 +885,7 @@ static int mb_ucsbsearch(const struct mb_ucsrange arr[], size_t elems, | ||
885 | 885 | unsigned int val) MKSH_A_PURE; |
886 | 886 | |
887 | 887 | /* |
888 | - * Generated from the Unicode Character Database, Version 10.0.0, by | |
888 | + * Generated from the UCD 11.0.0 by | |
889 | 889 | * MirOS: contrib/code/Snippets/eawparse,v 1.12 2017/09/06 16:05:45 tg Exp $ |
890 | 890 | */ |
891 | 891 |
@@ -909,12 +909,13 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
909 | 909 | { 0x0730, 0x074A }, |
910 | 910 | { 0x07A6, 0x07B0 }, |
911 | 911 | { 0x07EB, 0x07F3 }, |
912 | + { 0x07FD, 0x07FD }, | |
912 | 913 | { 0x0816, 0x0819 }, |
913 | 914 | { 0x081B, 0x0823 }, |
914 | 915 | { 0x0825, 0x0827 }, |
915 | 916 | { 0x0829, 0x082D }, |
916 | 917 | { 0x0859, 0x085B }, |
917 | - { 0x08D4, 0x08E1 }, | |
918 | + { 0x08D3, 0x08E1 }, | |
918 | 919 | { 0x08E3, 0x0902 }, |
919 | 920 | { 0x093A, 0x093A }, |
920 | 921 | { 0x093C, 0x093C }, |
@@ -927,6 +928,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
927 | 928 | { 0x09C1, 0x09C4 }, |
928 | 929 | { 0x09CD, 0x09CD }, |
929 | 930 | { 0x09E2, 0x09E3 }, |
931 | + { 0x09FE, 0x09FE }, | |
930 | 932 | { 0x0A01, 0x0A02 }, |
931 | 933 | { 0x0A3C, 0x0A3C }, |
932 | 934 | { 0x0A41, 0x0A42 }, |
@@ -953,6 +955,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
953 | 955 | { 0x0BC0, 0x0BC0 }, |
954 | 956 | { 0x0BCD, 0x0BCD }, |
955 | 957 | { 0x0C00, 0x0C00 }, |
958 | + { 0x0C04, 0x0C04 }, | |
956 | 959 | { 0x0C3E, 0x0C40 }, |
957 | 960 | { 0x0C46, 0x0C48 }, |
958 | 961 | { 0x0C4A, 0x0C4D }, |
@@ -1072,6 +1075,7 @@ static const struct mb_ucsrange mb_ucs_combining[] = { | ||
1072 | 1075 | { 0xA825, 0xA826 }, |
1073 | 1076 | { 0xA8C4, 0xA8C5 }, |
1074 | 1077 | { 0xA8E0, 0xA8F1 }, |
1078 | + { 0xA8FF, 0xA8FF }, | |
1075 | 1079 | { 0xA926, 0xA92D }, |
1076 | 1080 | { 0xA947, 0xA951 }, |
1077 | 1081 | { 0xA980, 0xA982 }, |
@@ -1173,7 +1177,7 @@ mb_ucsbsearch(const struct mb_ucsrange arr[], size_t elems, unsigned int val) | ||
1173 | 1177 | return (0); |
1174 | 1178 | } |
1175 | 1179 | |
1176 | -/* Unix column width of a wide character (Unicode code point, really) */ | |
1180 | +/* Unix column width of a wide character (UCS code point, really) */ | |
1177 | 1181 | int |
1178 | 1182 | utf_wcwidth(unsigned int wc) |
1179 | 1183 | { |
@@ -38,7 +38,7 @@ | ||
38 | 38 | #endif |
39 | 39 | #endif |
40 | 40 | |
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 $"); | |
42 | 42 | |
43 | 43 | #if HAVE_KILLPG |
44 | 44 | /* |
@@ -499,7 +499,7 @@ c_print(const char **wp) | ||
499 | 499 | Xput(xs, xp, '\\'); |
500 | 500 | } |
501 | 501 | } else if ((unsigned int)c > 0xFF) { |
502 | - /* generic function returned Unicode */ | |
502 | + /* generic function returned UCS */ | |
503 | 503 | po.ts[utf_wctomb(po.ts, c - 0x100)] = 0; |
504 | 504 | c = 0; |
505 | 505 | do { |
@@ -2970,6 +2970,37 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, | ||
2970 | 2970 | case TO_STGT: |
2971 | 2971 | return (strcmp(opnd1, opnd2) > 0); |
2972 | 2972 | |
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 | + | |
2973 | 3004 | /* -eq */ |
2974 | 3005 | case TO_INTEQ: |
2975 | 3006 | /* -ne */ |
@@ -3006,37 +3037,6 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, | ||
3006 | 3037 | break; |
3007 | 3038 | } |
3008 | 3039 | /* 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; | |
3040 | 3040 | } |
3041 | 3041 | (*te->error)(te, 0, "internal error: unknown op"); |
3042 | 3042 | return (1); |
@@ -3,7 +3,7 @@ | ||
3 | 3 | |
4 | 4 | /*- |
5 | 5 | * 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 | |
7 | 7 | * mirabilos <m@mirbsd.org> |
8 | 8 | * |
9 | 9 | * Provided that these terms and disclaimer and all copyright notices |
@@ -27,7 +27,7 @@ | ||
27 | 27 | #include <sys/file.h> |
28 | 28 | #endif |
29 | 29 | |
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 $"); | |
31 | 31 | |
32 | 32 | Trap sigtraps[ksh_NSIG + 1]; |
33 | 33 | static struct sigaction Sigact_ign; |
@@ -879,7 +879,8 @@ hist_persist_init(void) | ||
879 | 879 | } |
880 | 880 | } |
881 | 881 | 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; | |
883 | 884 | hist_init_tail: |
884 | 885 | mksh_unlkfd(histfd); |
885 | 886 | } |
@@ -962,8 +963,9 @@ writehistfile(int lno, const char *cmd) | ||
962 | 963 | unsigned char *base, *news; |
963 | 964 | |
964 | 965 | 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) { | |
967 | 969 | /* the file has shrunk; trust it just appending the new data */ |
968 | 970 | /* well, for now, anyway… since mksh strdups all into memory */ |
969 | 971 | /* we can use a nicer approach some time later… */ |
@@ -998,7 +1000,8 @@ writehistfile(int lno, const char *cmd) | ||
998 | 1000 | hist_finish(); |
999 | 1001 | return; |
1000 | 1002 | } |
1001 | - histfsize = lseek(histfd, (off_t)0, SEEK_END); | |
1003 | + if ((histfsize = lseek(histfd, (off_t)0, SEEK_END)) < 0) | |
1004 | + goto bad; | |
1002 | 1005 | mksh_unlkfd(histfd); |
1003 | 1006 | } |
1004 | 1007 |
@@ -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 | +} |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
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 $"); | |
27 | 27 | |
28 | 28 | #if HAVE_KILLPG |
29 | 29 | #define mksh_killpg killpg |
@@ -169,12 +169,6 @@ static void tty_init_state(void); | ||
169 | 169 | void |
170 | 170 | j_init(void) |
171 | 171 | { |
172 | -#ifndef MKSH_UNEMPLOYED | |
173 | - bool mflagset = Flag(FMONITOR) != 127; | |
174 | - | |
175 | - Flag(FMONITOR) = 0; | |
176 | -#endif | |
177 | - | |
178 | 172 | #ifndef MKSH_NOPROSPECTOFWORK |
179 | 173 | (void)sigemptyset(&sm_default); |
180 | 174 | sigprocmask(SIG_SETMASK, &sm_default, NULL); |
@@ -190,8 +184,8 @@ j_init(void) | ||
190 | 184 | #endif |
191 | 185 | |
192 | 186 | #ifndef MKSH_UNEMPLOYED |
193 | - if (!mflagset && Flag(FTALKING)) | |
194 | - Flag(FMONITOR) = 1; | |
187 | + if (Flag(FMONITOR) == 127) | |
188 | + Flag(FMONITOR) = Flag(FTALKING); | |
195 | 189 | |
196 | 190 | /* |
197 | 191 | * shl_j is used to do asynchronous notification (used in |
@@ -1932,7 +1926,7 @@ tty_init_talking(void) | ||
1932 | 1926 | break; |
1933 | 1927 | case 2: |
1934 | 1928 | #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, | |
1936 | 1930 | cstrerror(errno)); |
1937 | 1931 | #endif |
1938 | 1932 | break; |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
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 $"); | |
27 | 27 | |
28 | 28 | /* |
29 | 29 | * states while lexing word |
@@ -77,12 +77,17 @@ typedef struct lex_state { | ||
77 | 77 | short nparen; |
78 | 78 | /* type of this state */ |
79 | 79 | uint8_t type; |
80 | + /* extra flags */ | |
81 | + uint8_t ls_flags; | |
80 | 82 | } Lex_state; |
81 | 83 | #define ls_base u.base |
82 | 84 | #define ls_start u.start |
83 | 85 | #define ls_bool u.abool |
84 | 86 | #define ls_adelim u.adelim |
85 | 87 | |
88 | +/* ls_flags */ | |
89 | +#define LS_HEREDOC BIT(0) | |
90 | + | |
86 | 91 | typedef struct { |
87 | 92 | Lex_state *base; |
88 | 93 | Lex_state *end; |
@@ -147,9 +152,11 @@ getsc_r(int c) | ||
147 | 152 | #define STATE_BSIZE 8 |
148 | 153 | |
149 | 154 | #define PUSH_STATE(s) do { \ |
155 | + uint8_t state_flags = statep->ls_flags; \ | |
150 | 156 | if (++statep == state_info.end) \ |
151 | 157 | statep = push_state_i(&state_info, statep); \ |
152 | 158 | state = statep->type = (s); \ |
159 | + statep->ls_flags = state_flags; \ | |
153 | 160 | } while (/* CONSTCOND */ 0) |
154 | 161 | |
155 | 162 | #define POP_STATE() do { \ |
@@ -242,6 +249,7 @@ yylex(int cf) | ||
242 | 249 | |
243 | 250 | /* Initial state: one of SWORD SLETPAREN SHEREDELIM SBASE */ |
244 | 251 | statep->type = state; |
252 | + statep->ls_flags = (cf & HEREDOC) ? LS_HEREDOC : 0; | |
245 | 253 | |
246 | 254 | /* collect non-special or quoted characters to form word */ |
247 | 255 | while (!((c = getsc()) == 0 || |
@@ -319,7 +327,7 @@ yylex(int cf) | ||
319 | 327 | break; |
320 | 328 | case ORD('\''): |
321 | 329 | open_ssquote_unless_heredoc: |
322 | - if ((cf & HEREDOC)) | |
330 | + if ((statep->ls_flags & LS_HEREDOC)) | |
323 | 331 | goto store_char; |
324 | 332 | *wp++ = OQUOTE; |
325 | 333 | ignore_backslash_newline++; |
@@ -357,7 +365,7 @@ yylex(int cf) | ||
357 | 365 | c = getsc(); |
358 | 366 | switch (c) { |
359 | 367 | case ORD('"'): |
360 | - if ((cf & HEREDOC)) | |
368 | + if ((statep->ls_flags & LS_HEREDOC)) | |
361 | 369 | goto heredocquote; |
362 | 370 | /* FALLTHROUGH */ |
363 | 371 | case ORD('\\'): |
@@ -388,6 +396,8 @@ yylex(int cf) | ||
388 | 396 | if ((unsigned int)c == ORD('(' /*)*/)) { |
389 | 397 | *wp++ = EXPRSUB; |
390 | 398 | PUSH_SRETRACE(SASPAREN); |
399 | + /* unneeded? */ | |
400 | + /*statep->ls_flags &= ~LS_HEREDOC;*/ | |
391 | 401 | statep->nparen = 2; |
392 | 402 | *retrace_info->xp++ = '('; |
393 | 403 | } else { |
@@ -434,6 +444,8 @@ yylex(int cf) | ||
434 | 444 | *wp++ = ADELIM; |
435 | 445 | *wp++ = ':'; |
436 | 446 | PUSH_STATE(SBRACE); |
447 | + /* perhaps unneeded? */ | |
448 | + statep->ls_flags &= ~LS_HEREDOC; | |
437 | 449 | PUSH_STATE(SADELIM); |
438 | 450 | statep->ls_adelim.delimiter = ':'; |
439 | 451 | statep->ls_adelim.num = 1; |
@@ -449,6 +461,8 @@ yylex(int cf) | ||
449 | 461 | } |
450 | 462 | ungetsc(c); |
451 | 463 | PUSH_STATE(SBRACE); |
464 | + /* perhaps unneeded? */ | |
465 | + statep->ls_flags &= ~LS_HEREDOC; | |
452 | 466 | PUSH_STATE(SADELIM); |
453 | 467 | statep->ls_adelim.delimiter = ':'; |
454 | 468 | statep->ls_adelim.num = 2; |
@@ -466,6 +480,8 @@ yylex(int cf) | ||
466 | 480 | } else |
467 | 481 | ungetsc(c); |
468 | 482 | PUSH_STATE(SBRACE); |
483 | + /* perhaps unneeded? */ | |
484 | + statep->ls_flags &= ~LS_HEREDOC; | |
469 | 485 | PUSH_STATE(SADELIM); |
470 | 486 | statep->ls_adelim.delimiter = '/'; |
471 | 487 | statep->ls_adelim.num = 1; |
@@ -489,6 +505,8 @@ yylex(int cf) | ||
489 | 505 | PUSH_STATE(STBRACEBOURNE); |
490 | 506 | else |
491 | 507 | PUSH_STATE(STBRACEKORN); |
508 | + /* single-quotes-in-heredoc-trim */ | |
509 | + statep->ls_flags &= ~LS_HEREDOC; | |
492 | 510 | } else { |
493 | 511 | ungetsc(c); |
494 | 512 | if (state == SDQUOTE || |
@@ -496,6 +514,8 @@ yylex(int cf) | ||
496 | 514 | PUSH_STATE(SQBRACE); |
497 | 515 | else |
498 | 516 | PUSH_STATE(SBRACE); |
517 | + /* here no LS_HEREDOC removal */ | |
518 | + /* single-quotes-in-heredoc-braces */ | |
499 | 519 | } |
500 | 520 | } else if (ctype(c, C_ALPHX)) { |
501 | 521 | *wp++ = OSUBST; |
@@ -601,7 +621,8 @@ yylex(int cf) | ||
601 | 621 | case SSQUOTE: |
602 | 622 | if ((unsigned int)c == ORD('\'')) { |
603 | 623 | POP_STATE(); |
604 | - if ((cf & HEREDOC) || state == SQBRACE) | |
624 | + if ((statep->ls_flags & LS_HEREDOC) || | |
625 | + state == SQBRACE) | |
605 | 626 | goto store_char; |
606 | 627 | *wp++ = CQUOTE; |
607 | 628 | ignore_backslash_newline--; |
@@ -1155,7 +1176,7 @@ readhere(struct ioword *iop) | ||
1155 | 1176 | /* Newline terminates here document marker */ |
1156 | 1177 | goto heredoc_found_terminator; |
1157 | 1178 | } |
1158 | - } else if (c == *eofp++) | |
1179 | + } else if ((unsigned int)c == ord(*eofp++)) | |
1159 | 1180 | /* store; then read and compare next character */ |
1160 | 1181 | goto heredoc_store_and_loop; |
1161 | 1182 | /* nope, mismatch; read until end of line */ |
@@ -1338,7 +1359,7 @@ getsc_line(Source *s) | ||
1338 | 1359 | { |
1339 | 1360 | char *xp = Xstring(s->xs, xp), *cp; |
1340 | 1361 | 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; | |
1342 | 1363 | |
1343 | 1364 | /* Done here to ensure nothing odd happens when a timeout occurs */ |
1344 | 1365 | XcheckN(s->xs, xp, LINE); |
@@ -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 $ | |
2 | 2 | .\"- |
3 | -.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017 | |
3 | +.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017, 2018 | |
4 | 4 | .\" mirabilos <m@mirbsd.org> |
5 | 5 | .\" |
6 | 6 | .\" Provided that these terms and disclaimer and all copyright notices |
@@ -74,7 +74,7 @@ | ||
74 | 74 | .\" with -mandoc, it might implement .Mx itself, but we want to |
75 | 75 | .\" use our own definition. And .Dd must come *first*, always. |
76 | 76 | .\" |
77 | -.Dd $Mdocdate: April 2 2017 $ | |
77 | +.Dd $Mdocdate: December 25 2018 $ | |
78 | 78 | .\" |
79 | 79 | .\" Check which macro package we use, and do other -mdoc setup. |
80 | 80 | .\" |
@@ -82,6 +82,7 @@ | ||
82 | 82 | . if \*[.T]utf8 .tr \[la]\*(Lt |
83 | 83 | . if \*[.T]utf8 .tr \[ra]\*(Gt |
84 | 84 | . ie d volume-ds-1 .ds tT gnu |
85 | +. el .ie d doc-volume-ds-1 .ds tT gnp | |
85 | 86 | . el .ds tT bsd |
86 | 87 | .\} |
87 | 88 | .el .ds tT ucb |
@@ -94,7 +95,7 @@ | ||
94 | 95 | . nr curr-font \n[.f] |
95 | 96 | . nr curr-size \n[.ps] |
96 | 97 | . 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] | |
98 | 99 | . if !\n[arg-limit] \ |
99 | 100 | . if \n[.$] \{\ |
100 | 101 | . ds macro-name Mx |
@@ -120,19 +121,51 @@ | ||
120 | 121 | . ds sP \s0 |
121 | 122 | . ds tN \*[Tn-font-size] |
122 | 123 | .\} |
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 | +.\} | |
123 | 156 | .el \{\ |
124 | 157 | . de Mx |
125 | 158 | . nr cF \\n(.f |
126 | 159 | . nr cZ \\n(.s |
127 | 160 | . ds aa \&\f\\n(cF\s\\n(cZ |
128 | 161 | . if \\n(aC==0 \{\ |
129 | -. ie \\n(.$==0 \&MirOS\\*(aa | |
162 | +. ie \\n(.$==0 \&MirBSD\\*(aa | |
130 | 163 | . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 |
131 | 164 | . \} |
132 | 165 | . if \\n(aC>\\n(aP \{\ |
133 | 166 | . nr aP \\n(aP+1 |
134 | 167 | . ie \\n(C\\n(aP==2 \{\ |
135 | -. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa | |
168 | +. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa | |
136 | 169 | . ie \\n(aC>\\n(aP \{\ |
137 | 170 | . nr aP \\n(aP+1 |
138 | 171 | . nR |
@@ -140,7 +173,7 @@ | ||
140 | 173 | . el .aZ |
141 | 174 | . \} |
142 | 175 | . el \{\ |
143 | -. as b1 \&MirOS\\*(aa | |
176 | +. as b1 \&MirBSD\\*(aa | |
144 | 177 | . nR |
145 | 178 | . \} |
146 | 179 | . \} |
@@ -304,9 +337,11 @@ is not exactly specified. | ||
304 | 337 | .Pp |
305 | 338 | Talk to the |
306 | 339 | .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 | |
310 | 345 | .Li \&#\&!/bin/mksh |
311 | 346 | .Pq or Li \&#ksh |
312 | 347 | IRC channel at |
@@ -5,7 +5,8 @@ | ||
5 | 5 | |
6 | 6 | /*- |
7 | 7 | * 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 | |
9 | 10 | * mirabilos <m@mirbsd.org> |
10 | 11 | * |
11 | 12 | * Provided that these terms and disclaimer and all copyright notices |
@@ -34,7 +35,7 @@ | ||
34 | 35 | #include <locale.h> |
35 | 36 | #endif |
36 | 37 | |
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 $"); | |
38 | 39 | |
39 | 40 | #ifndef MKSHRC_PATH |
40 | 41 | #define MKSHRC_PATH "~/.mkshrc" |
@@ -463,7 +464,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) | ||
463 | 464 | /* Set this before parsing arguments */ |
464 | 465 | Flag(FPRIVILEGED) = (kshuid != ksheuid || kshgid != kshegid) ? 2 : 0; |
465 | 466 | |
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) */ | |
467 | 468 | #ifndef MKSH_UNEMPLOYED |
468 | 469 | Flag(FMONITOR) = 127; |
469 | 470 | #endif |
@@ -519,7 +520,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) | ||
519 | 520 | #else |
520 | 521 | s->file = argv[argi++]; |
521 | 522 | #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, | |
523 | 524 | SHF_MAPHI | SHF_CLEXEC); |
524 | 525 | if (s->u.shf == NULL) { |
525 | 526 | shl_stdout_ok = false; |
@@ -719,7 +720,7 @@ include(const char *name, int argc, const char **argv, bool intr_ok) | ||
719 | 720 | volatile int old_argc; |
720 | 721 | int i; |
721 | 722 | |
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); | |
723 | 724 | if (shf == NULL) |
724 | 725 | return (-1); |
725 | 726 |
@@ -1965,7 +1966,7 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool forread) | ||
1965 | 1966 | /* OSF/1 processes lnext when ~icanon */ |
1966 | 1967 | cb.c_cc[VLNEXT] = _POSIX_VDISABLE; |
1967 | 1968 | #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 */ | |
1969 | 1970 | #if defined(VDISCARD) && defined(_POSIX_VDISABLE) |
1970 | 1971 | cb.c_cc[VDISCARD] = _POSIX_VDISABLE; |
1971 | 1972 | #endif |
@@ -2061,6 +2062,7 @@ void | ||
2061 | 2062 | recheck_ctype(void) |
2062 | 2063 | { |
2063 | 2064 | const char *ccp; |
2065 | + uint8_t old_utfmode = UTFMODE; | |
2064 | 2066 | |
2065 | 2067 | ccp = str_val(global("LC_ALL")); |
2066 | 2068 | if (ccp == null) |
@@ -2078,7 +2080,7 @@ recheck_ctype(void) | ||
2078 | 2080 | UTFMODE = 1; |
2079 | 2081 | #endif |
2080 | 2082 | |
2081 | - if (Flag(FPOSIX)) | |
2083 | + if (Flag(FPOSIX) && UTFMODE && !old_utfmode) | |
2082 | 2084 | warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompliant"); |
2083 | 2085 | } |
2084 | 2086 | #endif |
@@ -32,7 +32,7 @@ | ||
32 | 32 | #include <grp.h> |
33 | 33 | #endif |
34 | 34 | |
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 $"); | |
36 | 36 | |
37 | 37 | #define KSH_CHVT_FLAG |
38 | 38 | #ifdef MKSH_SMALL |
@@ -1346,7 +1346,14 @@ print_value_quoted(struct shf *shf, const char *s) | ||
1346 | 1346 | const unsigned char *p = (const unsigned char *)s; |
1347 | 1347 | bool inquote = true; |
1348 | 1348 | |
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 */ | |
1350 | 1357 | while (rtt2asc(c = *p++) >= 32) |
1351 | 1358 | if (ctype(c, C_QUOTE | C_SPC)) |
1352 | 1359 | inquote = false; |
@@ -2449,7 +2456,7 @@ getrusage(int what, struct rusage *ru) | ||
2449 | 2456 | * and fp (put back a char) for backslash escapes, |
2450 | 2457 | * assuming the first call to *fg gets the char di- |
2451 | 2458 | * 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 | |
2453 | 2460 | * escape sequence was found |
2454 | 2461 | */ |
2455 | 2462 | int |
@@ -2531,9 +2538,9 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int)) | ||
2531 | 2538 | /** |
2532 | 2539 | * x: look for a hexadecimal number with up to |
2533 | 2540 | * two (C style: arbitrary) digits; convert |
2534 | - * to raw octet (C style: Unicode if >0xFF) | |
2541 | + * to raw octet (C style: UCS if >0xFF) | |
2535 | 2542 | * 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 | |
2537 | 2544 | */ |
2538 | 2545 | wc = 0; |
2539 | 2546 | n = 0; |
@@ -2555,7 +2562,7 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int)) | ||
2555 | 2562 | if (!n) |
2556 | 2563 | goto unknown_escape; |
2557 | 2564 | if ((cstyle && wc > 0xFF) || fc != 'x') |
2558 | - /* Unicode marker */ | |
2565 | + /* UCS marker */ | |
2559 | 2566 | wc += 0x100; |
2560 | 2567 | break; |
2561 | 2568 | case '\'': |
@@ -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 $ | |
2 | 2 | .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ |
3 | 3 | .\"- |
4 | 4 | .\" 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 | |
6 | 7 | .\" mirabilos <m@mirbsd.org> |
7 | 8 | .\" |
8 | 9 | .\" Provided that these terms and disclaimer and all copyright notices |
@@ -76,7 +77,7 @@ | ||
76 | 77 | .\" with -mandoc, it might implement .Mx itself, but we want to |
77 | 78 | .\" use our own definition. And .Dd must come *first*, always. |
78 | 79 | .\" |
79 | -.Dd $Mdocdate: August 16 2017 $ | |
80 | +.Dd $Mdocdate: March 1 2019 $ | |
80 | 81 | .\" |
81 | 82 | .\" Check which macro package we use, and do other -mdoc setup. |
82 | 83 | .\" |
@@ -84,6 +85,7 @@ | ||
84 | 85 | . if \*[.T]utf8 .tr \[la]\*(Lt |
85 | 86 | . if \*[.T]utf8 .tr \[ra]\*(Gt |
86 | 87 | . ie d volume-ds-1 .ds tT gnu |
88 | +. el .ie d doc-volume-ds-1 .ds tT gnp | |
87 | 89 | . el .ds tT bsd |
88 | 90 | .\} |
89 | 91 | .el .ds tT ucb |
@@ -96,7 +98,7 @@ | ||
96 | 98 | . nr curr-font \n[.f] |
97 | 99 | . nr curr-size \n[.ps] |
98 | 100 | . 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] | |
100 | 102 | . if !\n[arg-limit] \ |
101 | 103 | . if \n[.$] \{\ |
102 | 104 | . ds macro-name Mx |
@@ -122,19 +124,51 @@ | ||
122 | 124 | . ds sP \s0 |
123 | 125 | . ds tN \*[Tn-font-size] |
124 | 126 | .\} |
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 | +.\} | |
125 | 159 | .el \{\ |
126 | 160 | . de Mx |
127 | 161 | . nr cF \\n(.f |
128 | 162 | . nr cZ \\n(.s |
129 | 163 | . ds aa \&\f\\n(cF\s\\n(cZ |
130 | 164 | . if \\n(aC==0 \{\ |
131 | -. ie \\n(.$==0 \&MirOS\\*(aa | |
165 | +. ie \\n(.$==0 \&MirBSD\\*(aa | |
132 | 166 | . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 |
133 | 167 | . \} |
134 | 168 | . if \\n(aC>\\n(aP \{\ |
135 | 169 | . nr aP \\n(aP+1 |
136 | 170 | . ie \\n(C\\n(aP==2 \{\ |
137 | -. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa | |
171 | +. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa | |
138 | 172 | . ie \\n(aC>\\n(aP \{\ |
139 | 173 | . nr aP \\n(aP+1 |
140 | 174 | . nR |
@@ -142,7 +176,7 @@ | ||
142 | 176 | . el .aZ |
143 | 177 | . \} |
144 | 178 | . el \{\ |
145 | -. as b1 \&MirOS\\*(aa | |
179 | +. as b1 \&MirBSD\\*(aa | |
146 | 180 | . nR |
147 | 181 | . \} |
148 | 182 | . \} |
@@ -1046,7 +1080,7 @@ and | ||
1046 | 1080 | .Dq Li \eu#### , |
1047 | 1081 | .Dq # |
1048 | 1082 | 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. | |
1050 | 1084 | Furthermore, |
1051 | 1085 | .Dq Li \eE |
1052 | 1086 | and |
@@ -1082,7 +1116,7 @@ and yield raw octets; hexadecimal sequences | ||
1082 | 1116 | greedily eat up as many hexadecimal digits |
1083 | 1117 | .Dq # |
1084 | 1118 | 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. | |
1086 | 1120 | The sequence |
1087 | 1121 | .Dq Li \ec# , |
1088 | 1122 | where |
@@ -1364,6 +1398,10 @@ or | ||
1364 | 1398 | where |
1365 | 1399 | .Ar name |
1366 | 1400 | 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 . | |
1367 | 1405 | Substitution of all array elements with |
1368 | 1406 | .Pf ${ Ns Ar name Ns \&[*]} |
1369 | 1407 | and |
@@ -1519,11 +1557,7 @@ on it; if | ||
1519 | 1557 | .Ar word |
1520 | 1558 | is not needed, it is not evaluated. |
1521 | 1559 | .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: | |
1527 | 1561 | .Pp |
1528 | 1562 | .Bl -tag -width Ds -compact |
1529 | 1563 | .It Pf ${# Ns Ar name Ns \&} |
@@ -1823,10 +1857,10 @@ built-in command will display the resulting directory when a match is found | ||
1823 | 1857 | in any search path other than the empty path. |
1824 | 1858 | .It Ev COLUMNS |
1825 | 1859 | 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 | |
1828 | 1862 | .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 | |
1830 | 1864 | .Ev LINES . |
1831 | 1865 | This parameter is used by the interactive line editing modes and by the |
1832 | 1866 | .Ic select , |
@@ -1995,7 +2029,7 @@ The line number of the function or shell script that is currently being | ||
1995 | 2029 | executed. |
1996 | 2030 | .It Ev LINES |
1997 | 2031 | 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. | |
1999 | 2033 | See |
2000 | 2034 | .Ev COLUMNS . |
2001 | 2035 | .It Ev OLDPWD |
@@ -2651,7 +2685,8 @@ as required by the standard), as that's unsafe to do. | ||
2651 | 2685 | As a special |
2652 | 2686 | .Nm mksh |
2653 | 2687 | 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 | |
2655 | 2690 | .Ic utf8\-mode |
2656 | 2691 | flag (current setting). |
2657 | 2692 | The |
@@ -2664,7 +2699,7 @@ instead of | ||
2664 | 2699 | is also supported. |
2665 | 2700 | Note that NUL bytes (integral value of zero) cannot be used. |
2666 | 2701 | 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 | |
2668 | 2703 | OPTU-8, which is in the PUA and has been assigned by CSUR for this use. |
2669 | 2704 | If more than one octet in ASCII mode, or a sequence of more than one |
2670 | 2705 | 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. | ||
2903 | 2938 | The |
2904 | 2939 | .Dq export |
2905 | 2940 | attribute of functions is currently not used. |
2906 | -In the original Korn shell, | |
2907 | -exported functions are visible to shell scripts that are executed. | |
2908 | 2941 | .Pp |
2909 | 2942 | Since functions are executed in the current shell environment, parameter |
2910 | 2943 | 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 | ||
4667 | 4700 | (time spent running in kernel mode). |
4668 | 4701 | Times are reported to standard error; the format of the output is: |
4669 | 4702 | .Pp |
4670 | -.Dl "0m0.00s real 0m0.00s user 0m0.00s system" | |
4703 | +.Dl "0m0.03s real 0m0.02s user 0m0.01s system" | |
4671 | 4704 | .Pp |
4672 | 4705 | If the |
4673 | 4706 | .Fl p |
4674 | 4707 | option is given the output is slightly longer: |
4675 | 4708 | .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 | |
4679 | 4712 | .Ed |
4680 | 4713 | .Pp |
4681 | 4714 | It is an error to specify the |
@@ -4700,8 +4733,8 @@ Print the accumulated user and system times used both by the shell | ||
4700 | 4733 | and by processes that the shell started which have exited. |
4701 | 4734 | The format of the output is: |
4702 | 4735 | .Bd -literal -offset indent |
4703 | -0m0.00s 0m0.00s | |
4704 | -0m0.00s 0m0.00s | |
4736 | +0m0.01s 0m0.00s | |
4737 | +0m0.04s 0m0.02s | |
4705 | 4738 | .Ed |
4706 | 4739 | .Pp |
4707 | 4740 | .It Ic trap Ar n Op Ar signal ... |
@@ -4932,9 +4965,9 @@ when used with the | ||
4932 | 4965 | .Fl i |
4933 | 4966 | option which meant upper case letters would never be used for bases greater |
4934 | 4967 | than 10. |
4935 | -See the | |
4968 | +See | |
4936 | 4969 | .Fl U |
4937 | -option.) | |
4970 | +above.) | |
4938 | 4971 | .Pp |
4939 | 4972 | For functions, |
4940 | 4973 | .Fl u |
@@ -4944,9 +4977,9 @@ See | ||
4944 | 4977 | above for the implications of this. |
4945 | 4978 | .It Fl x |
4946 | 4979 | 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 . | |
4950 | 4983 | .It Fl Z Ns Op Ar n |
4951 | 4984 | Zero fill attribute. |
4952 | 4985 | If not combined with |
@@ -4954,7 +4987,7 @@ If not combined with | ||
4954 | 4987 | this is the same as |
4955 | 4988 | .Fl R , |
4956 | 4989 | 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. | |
4958 | 4991 | .El |
4959 | 4992 | .Pp |
4960 | 4993 | If any of the |
@@ -5211,14 +5244,12 @@ or | ||
5211 | 5244 | .Ic set Fl o Ic monitor ) , |
5212 | 5245 | as it is for interactive shells, the processes of a job are placed in their |
5213 | 5246 | 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 | |
5217 | 5250 | .Ic fg |
5218 | 5251 | 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 . | |
5222 | 5253 | .Pp |
5223 | 5254 | Note that only commands that create processes (e.g. asynchronous commands, |
5224 | 5255 | subshell commands and non-built-in, non-function commands) can be stopped; |
@@ -5332,6 +5363,17 @@ If another attempt | ||
5332 | 5363 | is immediately made to exit the shell, the running jobs are sent a |
5333 | 5364 | .Dv SIGHUP |
5334 | 5365 | 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. | |
5335 | 5377 | .Ss POSIX mode |
5336 | 5378 | Entering |
5337 | 5379 | .Ic set Fl o Ic posix |
@@ -6650,7 +6692,7 @@ locale. | ||
6650 | 6692 | .Ic utf8\-mode |
6651 | 6693 | .Em must |
6652 | 6694 | 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 | |
6654 | 6696 | raw octets into the U+EF80..U+EFFF wide character range; compare |
6655 | 6697 | .Sx Arithmetic expressions . |
6656 | 6698 | The following |
@@ -6671,7 +6713,24 @@ case ${KSH_VERSION:\-} in | ||
6671 | 6713 | esac ;; |
6672 | 6714 | esac |
6673 | 6715 | .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 | |
6675 | 6734 | .Pp |
6676 | 6735 | See also the FAQ below. |
6677 | 6736 | .Sh BUGS |
@@ -6697,7 +6756,7 @@ for the in-memory portion of the history is slow, should use | ||
6697 | 6756 | .Xr memmove 3 . |
6698 | 6757 | .Pp |
6699 | 6758 | This document attempts to describe |
6700 | -.Nm mksh\ R56 | |
6759 | +.Nm mksh\ R57 | |
6701 | 6760 | and up, |
6702 | 6761 | .\" with vendor patches from insert-your-name-here, |
6703 | 6762 | compiled without any options impacting functionality, such as |
@@ -6713,10 +6772,11 @@ for an operating environment supporting all of its advanced needs. | ||
6713 | 6772 | .Pp |
6714 | 6773 | Please report bugs in |
6715 | 6774 | .Nm |
6716 | -to the | |
6775 | +to the public development mailing list at | |
6717 | 6776 | .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 | |
6720 | 6780 | .Li \&#\&!/bin/mksh |
6721 | 6781 | .Pq or Li \&#ksh |
6722 | 6782 | IRC channel at |
@@ -6782,6 +6842,10 @@ Run the shell in POSIX mode (and possibly | ||
6782 | 6842 | instead of |
6783 | 6843 | .Nm mksh ) : |
6784 | 6844 | .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. | |
6785 | 6849 | .Ss "My prompt from <some other shell> does not work!" |
6786 | 6850 | Contact us on the mailing list or on IRC, we'll convert it for you. |
6787 | 6851 | .Ss "Something is going wrong with my while...read loop" |
@@ -182,9 +182,9 @@ | ||
182 | 182 | #endif |
183 | 183 | |
184 | 184 | #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 $"); | |
186 | 186 | #endif |
187 | -#define MKSH_VERSION "R56 2018/01/14" | |
187 | +#define MKSH_VERSION "R57 2019/03/01" | |
188 | 188 | |
189 | 189 | /* arithmetic types: C implementation */ |
190 | 190 | #if !HAVE_CAN_INTTYPES |
@@ -491,6 +491,10 @@ extern int __cdecl setegid(gid_t); | ||
491 | 491 | #define O_BINARY 0 |
492 | 492 | #endif |
493 | 493 | |
494 | +#ifndef O_MAYEXEC | |
495 | +#define O_MAYEXEC 0 | |
496 | +#endif | |
497 | + | |
494 | 498 | #ifdef MKSH__NO_SYMLINK |
495 | 499 | #undef S_ISLNK |
496 | 500 | #define S_ISLNK(m) (/* CONSTCOND */ 0) |
@@ -643,7 +647,7 @@ char *ucstrstr(char *, const char *); | ||
643 | 647 | #endif |
644 | 648 | #endif |
645 | 649 | |
646 | -#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 563) | |
650 | +#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 571) | |
647 | 651 | #error Must run Build.sh to compile this. |
648 | 652 | extern void thiswillneverbedefinedIhope(void); |
649 | 653 | int |
@@ -783,7 +787,7 @@ enum sh_flag { | ||
783 | 787 | }; |
784 | 788 | |
785 | 789 | #define Flag(f) (shell_flags[(int)(f)]) |
786 | -#define UTFMODE Flag(FUNICODE) | |
790 | +#define UTFMODE Flag(FUNNYCODE) | |
787 | 791 | |
788 | 792 | /* |
789 | 793 | * parsing & execution environment |
@@ -1950,10 +1954,11 @@ struct ioword { | ||
1950 | 1954 | #define IOSKIP BIT(5) /* <<-, skip ^\t* */ |
1951 | 1955 | #define IOCLOB BIT(6) /* >|, override -o noclobber */ |
1952 | 1956 | #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 (<<) */ | |
1957 | 1962 | |
1958 | 1963 | /* execute/exchild flags */ |
1959 | 1964 | #define XEXEC BIT(0) /* execute without forking */ |
@@ -2637,7 +2642,7 @@ const char *wdscan(const char *, int); | ||
2637 | 2642 | #define WDS_TPUTS BIT(0) /* tputS (dumpwdvar) mode */ |
2638 | 2643 | char *wdstrip(const char *, int); |
2639 | 2644 | void tfree(struct op *, Area *); |
2640 | -void dumpchar(struct shf *, int); | |
2645 | +void dumpchar(struct shf *, unsigned char); | |
2641 | 2646 | void dumptree(struct shf *, struct op *); |
2642 | 2647 | void dumpwdvar(struct shf *, const char *); |
2643 | 2648 | void dumpioact(struct shf *shf, struct op *t); |
@@ -21,7 +21,7 @@ | ||
21 | 21 | |
22 | 22 | #ifndef SHFLAGS_OPTCS |
23 | 23 | #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 $"); | |
25 | 25 | #elif defined(SHFLAGS_ENUMS) |
26 | 26 | #define FN(sname,cname,flags,ochar) cname, |
27 | 27 | #define F0(sname,cname,flags,ochar) cname = 0, |
@@ -77,7 +77,7 @@ FN("sh", FSH, OF_ANY, 0) | ||
77 | 77 | FN("stdin", FSTDIN, OF_CMDLINE, 's') |
78 | 78 | #endif |
79 | 79 | FN("trackall", FTRACKALL, OF_ANY, 'h') |
80 | -FN("utf8-mode", FUNICODE, OF_ANY, 'U') | |
80 | +FN("utf8-mode", FUNNYCODE, OF_ANY, 'U') | |
81 | 81 | FN("verbose", FVERBOSE, OF_ANY, 'v') |
82 | 82 | #ifndef MKSH_NO_CMDLINE_EDITING |
83 | 83 | FN("vi", FVI, OF_ANY, 0) |
@@ -19,7 +19,7 @@ | ||
19 | 19 | */ |
20 | 20 | |
21 | 21 | @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 $"); | |
23 | 23 | @SHFLAGS_ENUMS |
24 | 24 | #define FN(sname,cname,flags,ochar) cname, |
25 | 25 | #define F0(sname,cname,flags,ochar) cname = 0, |
@@ -153,7 +153,7 @@ FN("trackall", FTRACKALL, OF_ANY | ||
153 | 153 | |
154 | 154 | /* -U enable UTF-8 processing (non-standard) */ |
155 | 155 | >U| |
156 | -FN("utf8-mode", FUNICODE, OF_ANY | |
156 | +FN("utf8-mode", FUNNYCODE, OF_ANY | |
157 | 157 | |
158 | 158 | /* -v echo input */ |
159 | 159 | >v| |
@@ -27,7 +27,7 @@ | ||
27 | 27 | |
28 | 28 | #include "sh.h" |
29 | 29 | |
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 $"); | |
31 | 31 | |
32 | 32 | /* flags to shf_emptybuf() */ |
33 | 33 | #define EB_READSW 0x01 /* about to switch to reading */ |
@@ -1304,7 +1304,7 @@ ebcdic_init(void) | ||
1304 | 1304 | * and the C1 control characters other than NEL are |
1305 | 1305 | * hopeless, but we map EBCDIC NEL to ASCII LF so we |
1306 | 1306 | * 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 | |
1308 | 1308 | * an unsigned int, and or the raw unconverted EBCDIC |
1309 | 1309 | * values with 0x01000000 instead. |
1310 | 1310 | */ |
@@ -23,7 +23,7 @@ | ||
23 | 23 | |
24 | 24 | #include "sh.h" |
25 | 25 | |
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 $"); | |
27 | 27 | |
28 | 28 | #define INDENT 8 |
29 | 29 |
@@ -808,7 +808,7 @@ vistree(char *dst, size_t sz, struct op *t) | ||
808 | 808 | c = ksh_unctrl(c); |
809 | 809 | } else if (UTFMODE && rtt2asc(c) > 0x7F) { |
810 | 810 | /* 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 */ | |
812 | 812 | c = ORD('?'); |
813 | 813 | } |
814 | 814 | *dst++ = c; |
@@ -821,7 +821,7 @@ vistree(char *dst, size_t sz, struct op *t) | ||
821 | 821 | |
822 | 822 | #ifdef DEBUG |
823 | 823 | void |
824 | -dumpchar(struct shf *shf, int c) | |
824 | +dumpchar(struct shf *shf, unsigned char c) | |
825 | 825 | { |
826 | 826 | if (ksh_isctrl(c)) { |
827 | 827 | /* C0 or C1 control character or DEL */ |
@@ -28,7 +28,7 @@ | ||
28 | 28 | #include <sys/sysctl.h> |
29 | 29 | #endif |
30 | 30 | |
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 $"); | |
32 | 32 | |
33 | 33 | /*- |
34 | 34 | * Variables |
@@ -54,7 +54,7 @@ static int special(const char *); | ||
54 | 54 | static void unspecial(const char *); |
55 | 55 | static void getspec(struct tbl *); |
56 | 56 | static void setspec(struct tbl *); |
57 | -static void unsetspec(struct tbl *); | |
57 | +static void unsetspec(struct tbl *, bool); | |
58 | 58 | static int getint(struct tbl *, mksh_ari_u *, bool); |
59 | 59 | static const char *array_index_calc(const char *, bool *, uint32_t *); |
60 | 60 |
@@ -105,7 +105,7 @@ popblock(void) | ||
105 | 105 | if ((vq = global(vp->name))->flag & ISSET) |
106 | 106 | setspec(vq); |
107 | 107 | else |
108 | - unsetspec(vq); | |
108 | + unsetspec(vq, false); | |
109 | 109 | } |
110 | 110 | if (l->flags & BF_DOGETOPTS) |
111 | 111 | user_opt = l->getopts_state; |
@@ -707,7 +707,7 @@ formatstr(struct tbl *vp, const char *s) | ||
707 | 707 | if (vp->flag & ZEROFIL) |
708 | 708 | while (*s == '0') |
709 | 709 | s++; |
710 | - shf_snprintf(p, nlen + 1, "%-*.*s", | |
710 | + shf_snprintf(p, psiz, "%-*.*s", | |
711 | 711 | vp->u2.field, vp->u2.field, s); |
712 | 712 | } |
713 | 713 | } else |
@@ -1054,7 +1054,7 @@ unset(struct tbl *vp, int flags) | ||
1054 | 1054 | vp->flag &= SPECIAL | ((flags & 1) ? 0 : ARRAY|DEFINED); |
1055 | 1055 | if (vp->flag & SPECIAL) |
1056 | 1056 | /* responsible for 'unspecial'ing var */ |
1057 | - unsetspec(vp); | |
1057 | + unsetspec(vp, true); | |
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | /* |
@@ -1441,7 +1441,7 @@ setspec(struct tbl *vp) | ||
1441 | 1441 | } |
1442 | 1442 | |
1443 | 1443 | static void |
1444 | -unsetspec(struct tbl *vp) | |
1444 | +unsetspec(struct tbl *vp, bool dounset) | |
1445 | 1445 | { |
1446 | 1446 | /* |
1447 | 1447 | * AT&T ksh man page says OPTIND, OPTARG and _ lose special |
@@ -1466,13 +1466,13 @@ unsetspec(struct tbl *vp) | ||
1466 | 1466 | #endif |
1467 | 1467 | case V_IFS: |
1468 | 1468 | set_ifs(TC_IFSWS); |
1469 | - break; | |
1469 | + return; | |
1470 | 1470 | case V_PATH: |
1471 | 1471 | afree(path, APERM); |
1472 | 1472 | strdupx(path, def_path, APERM); |
1473 | 1473 | /* clear tracked aliases */ |
1474 | 1474 | flushcom(true); |
1475 | - break; | |
1475 | + return; | |
1476 | 1476 | #ifndef MKSH_NO_CMDLINE_EDITING |
1477 | 1477 | case V_TERM: |
1478 | 1478 | x_initterm(null); |
@@ -1484,14 +1484,14 @@ unsetspec(struct tbl *vp) | ||
1484 | 1484 | afree(tmpdir, APERM); |
1485 | 1485 | tmpdir = NULL; |
1486 | 1486 | } |
1487 | - break; | |
1487 | + return; | |
1488 | 1488 | case V_LINENO: |
1489 | 1489 | case V_RANDOM: |
1490 | 1490 | case V_SECONDS: |
1491 | 1491 | case V_TMOUT: |
1492 | 1492 | /* AT&T ksh leaves previous value in place */ |
1493 | 1493 | unspecial(vp->name); |
1494 | - break; | |
1494 | + return; | |
1495 | 1495 | #ifdef MKSH_EARLY_LOCALE_TRACKING |
1496 | 1496 | case V_LANG: |
1497 | 1497 | case V_LC_ALL: |
@@ -1499,6 +1499,12 @@ unsetspec(struct tbl *vp) | ||
1499 | 1499 | recheck_ctype(); |
1500 | 1500 | return; |
1501 | 1501 | #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; | |
1502 | 1508 | } |
1503 | 1509 | } |
1504 | 1510 |
@@ -1617,6 +1623,9 @@ set_array(const char *var, bool reset, const char **vals) | ||
1617 | 1623 | unset(vp, 1); |
1618 | 1624 | /* allocate-by-access the [0] element to keep in scope */ |
1619 | 1625 | arraysearch(vp, 0); |
1626 | + /* honour set -o allexport */ | |
1627 | + if (Flag(FEXPORT)) | |
1628 | + typeset(ccp, EXPORT, 0, 0, 0); | |
1620 | 1629 | } |
1621 | 1630 | /* |
1622 | 1631 | * TODO: would be nice for assignment to completely succeed or |