1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Remove SHOPT_BASH; keep &> redir operator, '-o posix' option

On 16 June there was a call for volunteers to fix the bash
compatibility mode; it has never successfully compiled in 93u+.
Since no one showed up, it is now removed due to lack of interest.

A couple of things are kept, which are now globally enabled:

1. The &>file redirection shorthand (for >file 2>&1). As a matter
   of fact, ksh93 already supported this natively, but only while
   running rc/profile/login scripts, and it issued a warning. This
   makse it globally available and removes the warning, bringing
   ksh93 in line with mksh, bash and zsh.

2. The '-o posix' standard compliance option. It is now enabled on
   startup if ksh is invoked as 'sh' or if the POSIXLY_CORRECT
   variable exists in the environment. To begin with, it disables
   the aforementioned &> redirection shorthand. Further compliance
   tweaks will be added in subsequent commits. The differences will
   be fairly minimal as ksh93 is mostly compliant already.

In all changed files, code was removed that was compiled (more
precisely, failed to compile/link) if the SHOPT_BASH preprocessor
identifier was defined. Below are other changes worth mentioning:

src/cmd/ksh93/sh/bash.c,
src/cmd/ksh93/data/bash_pre_rc.sh:
- Removed.

src/cmd/ksh93/data/lexstates.c,
src/cmd/ksh93/include/shlex.h,
src/cmd/ksh93/sh/lex.c:
- Globally enable &> redirection operator if SH_POSIX not active.
- Remove warning that was issued when &> was used in rc scripts.

src/cmd/ksh93/data/options.c,
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/sh/args.c:
- Keep SH_POSIX option (-o posix).
- Replace SH_TYPE_BASH shell type by SH_TYPE_POSIX.

src/cmd/ksh93/sh/init.c:
- sh_type(): Return SH_TYPE_POSIX shell type if ksh was invoked
  as sh (or rsh, restricted sh).
- sh_init(): Enable posix option if the SH_TYPE_POSIX shell type
  was detected, or if the CONFORMANCE ast config variable was set
  to "standard" (which libast sets on init if POSIXLY_CORRECT
  exists in the environment).

src/cmd/ksh93/tests/options.sh,
src/cmd/ksh93/tests/io.sh:
- Replace regression tests for &> and move to io.sh. Since &> is
  now for general use, no longer test in an rc script, and don't
  check that a warning is issued.

Closes: #9
Progresses: #20
This commit is contained in:
Martijn Dekker 2020-09-01 06:19:19 +01:00
parent 84331a96fc
commit 921bbcaeb7
25 changed files with 95 additions and 1148 deletions

View file

@ -1,255 +0,0 @@
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
#
# bash compatibility startup script
#
# Author:
# Karsten Fleischer
# Omnium Software Engineering
# An der Luisenburg 7
# D-51379 Leverkusen
# Germany
#
# <K.Fleischer@omnium.de>
#
alias declare=typeset
nameref FUNCNAME=.sh.fun
integer SHLVL
export SHLVL
SHLVL+=1
if [[ ! $EUID ]]
then EUID=$(id -u)
readonly EUID
fi
if [[ ! $UID ]]
then UID=$(id -u)
readonly UID
fi
readonly SHELLOPTS
if ! shopt -qo restricted; then
IFS=:
for i in $SHELLOPTS
do
[[ -n "$i" ]] && set -o $i
done
unset IFS
fi
function SHELLOPTS.get
{
.sh.value=$(shopt -so)
.sh.value=${.sh.value//+([[:space:]])on*([[:space:]])/:}
.sh.value=${.sh.value%:}
}
set -A GROUPS $(id -G)
function GROUPS.set
{
return 1
}
function GROUPS.unset
{
unset -f GROUPS.set
unset -f GROUPS.unset
}
typeset -A DIRSTACK
function DIRSTACK.get
{
set -A .sh.value $(dirs)
}
function DIRSTACK.set
{
integer index
index=_push_max-.sh.subscript
(( index == _push_max || index < _push_top )) && return
_push_stack[index]=${.sh.value}
}
function DIRSTACK.unset
{
unset -f DIRSTACK.get
unset -f DIRSTACK.set
unset -f DIRSTACK.unset
}
function PS1.set
{
typeset prefix remaining=${.sh.value} var= n= k=
while [[ $remaining ]]
do prefix=${remaining%%'\'*}
remaining=${remaining#$prefix}
var+="$prefix"
case ${remaining:1:1} in
t) var+="\$(printf '%(%H:%M:%S)T')";;
d) var+="\$(printf '%(%a %b:%e)T')";;
n) var+=$'\n';;
s) var+=ksh;;
w) var+="\$(pwd)";;
W) var+="\$(basename \"\$(pwd)\")";;
u) var+=$USER;;
h) var+=$(hostname -s);;
'#') var+=!;;
!) var+=!;;
@) var+="\$(printf '%(%I:%M%p)T')";;
'$') if (( $(id -u) == 0 ))
then var+='#'
else var+='$'
fi;;
'\') var+='\\';;
'['|']') ;;
[0-7]) case ${remaining:1:3} in
[0-7][0-7][0-7])
k=4;;
[0-7][0-7])
k=3;;
*) k=2;;
esac
eval n="\$'"${remaining:0:k}"'"
var+=$n
remaining=${remaining:k}
continue
;;
"") ;;
*) var+='\'${remaining:0:2};;
esac
remaining=${remaining:2}
done
.sh.value=$var
}
function logout
{
if shopt -q login_shell; then
exit
else
print ${BASH##*/}: $0: not login shell: use 'exit' >&2
return 1
fi
}
PS1="bash$ "
function source
{
if ! shopt -qpo posix; then
unset OPATH
typeset OPATH=$PATH
typeset PATH=$PATH
if shopt -q sourcepath; then
PATH=$OPATH:.
else
PATH=.
fi
fi
. "$@"
}
unalias .
alias .=source
alias enable=builtin
function help
{
typeset b cmd usage try_cmd man
function has_help_option
{
[[ $1 == @(''|/*|:|echo|false|true|login|test|'[') ]] && return 1
return 0
}
typeset -A short_use=(
[echo]='Usage: echo [ options ] [arg]...'
[:]='Usage: : ...'
[true]='Usage: true ...'
[false]='Usage: false ...'
[login]='Usage: login [-p] [name]'
['[']='Usage: [ EXPRESSION ] | [ OPTION'
[test]='Usage: test EXPRESSION | test'
)
b=$(builtin)
if (( $# == 0))
then print 'The following is the current list of built-in commands:'
print -r $'Type help *name* for more information about name\n'
for cmd in $b
do if has_help_option $cmd
then usage=$($cmd --short 2>&1)
print -r -- "${usage:7}"
else print -r -- ${short_use[$cmd]:7}
fi
done
return
fi
b=${b/'['/}
man=--man
[[ $1 == -s ]] && man=--short && shift
for try_cmd
do if has_help_option $try_cmd
then if [[ $try_cmd == @(${b//$'\n'/'|'}) ]]
then $try_cmd $man
else man $try_cmd
fi
elif [[ $man == '--short' ]]
then print -r -- ${short_use[$try_cmd]}
else man $try_cmd
fi
done
}
function cd
{
local msg
local args
local i
local a
local ret
if ! shopt -q cdable_vars; then
command cd "$@"
else
msg=$(command cd "$@" 2>&1)
ret=$?
if [[ $ret != 0 ]]; then
for i
do
case $i in
-*) args="$args $i" ;;
*/*) args="$args $i" ;;
*) eval a="$"$i
if [[ -n $a ]]; then args="$args $a"
else args="$args $i"
fi
;;
esac
done
command cd $args
else
print -- $msg
return $ret
fi
fi
}
typeset BASH=$0
! shopt -qo posix && HISTFILE=~/.bash_history
HOSTNAME=$(hostname)
nameref BASH_SUBSHELL=.sh.subshell

View file

@ -54,7 +54,6 @@
/*
* IMPORTANT: The order of these struct members must be synchronous
* with the offsets on the macros defined in include/builtins.h!
* The order up through "local" is significant.
*/
const struct shtable3 shtab_builtins[] =
{
@ -81,9 +80,6 @@ const struct shtable3 shtab_builtins[] =
".", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(dot_cmd),
"source", NV_BLTIN|BLT_ENV, bltin(dot_cmd),
"return", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(return),
#if SHOPT_BASH
"local", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(typeset),
#endif
/*
* Builtins without offset macros in include/builtins.h follow.
*/
@ -220,13 +216,6 @@ const char sh_set[] =
"[+gmacs?Enables/disables \bgmacs\b editing mode. \bgmacs\b "
"editing mode is the same as \bemacs\b editing mode "
"except for the handling of \b^T\b.]"
#if SHOPT_BASH
"[+hashall?Equivalent to \b-h\b and \b-o trackall\b. Available "
"in bash compatibility mode only.]"
"[+history?Enable command history. Available in bash "
"compatibility mode only. On by default in interactive "
"shells.]"
#endif
#if SHOPT_HISTEXPAND
"[+histexpand?Equivalent to \b-H\b.]"
#endif
@ -247,20 +236,12 @@ const char sh_set[] =
"compatibility.]"
"[+notify?Equivalent to \b-b\b.]"
"[+nounset?Equivalent to \b-u\b.]"
#if SHOPT_BASH
"[+onecmd?Equivalent to \b-t\b. Available in bash compatibility "
"mode only.]"
"[+physical?Equivalent to \b-P\b. Available in bash "
"compatibility mode only.]"
"[+posix?Turn on POSIX compatibility. Available in bash "
"compatibility mode only. Bash in POSIX mode is not the "
"same as ksh.]"
#endif
"[+pipefail?A pipeline will not complete until all components "
"of the pipeline have completed, and the exit status "
"of the pipeline will be the value of the last "
"command to exit with non-zero exit status, or will "
"be zero if all commands return zero exit status.]"
"[+posix?Enable POSIX standard compatibility mode.]"
"[+privileged?Equivalent to \b-p\b.]"
"[+rc?Do not run the \b.kshrc\b file for interactive shells.]"
"[+showme?Simple commands preceded by a \b;\b will be traced "
@ -289,9 +270,6 @@ const char sh_set[] =
"[x?Execution trace. The shell will display each command after all "
"expansion and before execution preceded by the expanded value "
"of the \bPS4\b parameter.]"
#if SHOPT_BASH
"\fbash1\f"
#endif
#if SHOPT_BRACEPAT
"[B?Enable {...} group expansion. On by default.]"
#endif
@ -1569,9 +1547,6 @@ USAGE_LICENSE
"[I:regress]:[intercept?Enable the regression test \aintercept\a. Must be "
"the first command line option(s).]"
#endif
#if SHOPT_BASH
"\fbash2\f"
#endif
"\fabc\f"
"?"
"[T?Enable implementation specific test code defined by mask.]#[mask]"

View file

@ -402,7 +402,6 @@ const char e_lexobsolete3[] = "line %d: '=' obsolete, use '=='";
const char e_lexobsolete4[] = "line %d: %s within [[...]] obsolete, use ((...))";
const char e_lexobsolete5[] = "line %d: set %s obsolete";
const char e_lexobsolete6[] = "line %d: `{' instead of `in' is obsolete";
const char e_lexnonstandard[] = "line %d: `&>file' is nonstandard -- interpreted as `>file 2>&1' for profile input only";
const char e_lexusebrace[] = "line %d: use braces to avoid ambiguities with $id[...]";
const char e_lexusequote[] = "line %d: %c within ${} should be quoted";
const char e_lexescape[] = "line %d: escape %c to avoid ambiguities";

View file

@ -187,15 +187,6 @@ const char e_suidprofile[] = "/etc/suid_profile";
#if SHOPT_SYSRC
const char e_sysrc[] = "/etc/ksh.kshrc";
#endif
#if SHOPT_BASH
#if SHOPT_SYSRC
const char e_bash_sysrc[] = "/etc/bash.bashrc";
#endif
const char e_bash_rc[] = "$HOME/.bashrc";
const char e_bash_login[] = "$HOME/.bash_login";
const char e_bash_logout[] = "$HOME/.bash_logout";
const char e_bash_profile[] = "$HOME/.bash_profile";
#endif
const char e_crondir[] = "/usr/spool/cron/atjobs";
const char e_prohibited[] = "login setuid/setgid shells prohibited";
#ifdef BUILD_DTKSH

View file

@ -23,14 +23,6 @@
#include "name.h"
#include "shtable.h"
#if SHOPT_BASH
# define bashopt(a,b) a, b|SH_BASHOPT,
# define bashextra(a,b) a, b|SH_BASHEXTRA,
#else
# define bashopt(a,b)
# define bashextra(a,b)
#endif
/*
* This is the list of invocation and set options
* This list must be in in ascii sorted order
@ -39,83 +31,42 @@
const Shtable_t shtab_options[] =
{
"allexport", SH_ALLEXPORT,
#if SHOPT_BASH
"bash", (SH_BASH|SH_COMMANDLINE),
#endif
"bgnice", SH_BGNICE,
"braceexpand", SH_BRACEEXPAND,
bashopt("cdable_vars", SH_CDABLE_VARS)
bashopt("cdspell", SH_CDSPELL)
bashopt("checkhash", SH_CHECKHASH)
bashopt("checkwinsize", SH_CHECKWINSIZE)
"noclobber", SH_NOCLOBBER,
bashopt("dotglob", SH_DOTGLOB)
"emacs", SH_EMACS,
"errexit", SH_ERREXIT,
"noexec", SH_NOEXEC,
bashopt("execfail", SH_EXECFAIL)
bashopt("expand_aliases", SH_EXPAND_ALIASES)
bashopt("extglob", SH_EXTGLOB)
"noglob", SH_NOGLOB,
"globstar", SH_GLOBSTARS,
"gmacs", SH_GMACS,
bashextra("hashall", SH_TRACKALL)
bashopt("histappend", SH_HISTAPPEND)
#if SHOPT_HISTEXPAND
"histexpand", SH_HISTEXPAND,
#else
bashextra("histexpand", SH_HISTEXPAND)
#endif
bashextra("history", SH_HISTORY2)
bashopt("histreedit", SH_HISTREEDIT)
bashopt("histverify", SH_HISTVERIFY)
bashopt("hostcomplete", SH_HOSTCOMPLETE)
bashopt("huponexit", SH_HUPONEXIT)
"ignoreeof", SH_IGNOREEOF,
"interactive", SH_INTERACTIVE|SH_COMMANDLINE,
bashextra("interactive_comments", SH_INTERACTIVE_COMM)
"keyword", SH_KEYWORD,
"letoctal", SH_LETOCTAL,
bashopt("lithist", SH_LITHIST)
"nolog", SH_NOLOG,
"login_shell", SH_LOGIN_SHELL|SH_COMMANDLINE,
bashopt("mailwarn", SH_MAILWARN)
"markdirs", SH_MARKDIRS,
"monitor", SH_MONITOR,
"multiline", SH_MULTILINE,
bashopt("no_empty_cmd_completion", SH_NOEMPTYCMDCOMPL)
bashopt("nocaseglob", SH_NOCASEGLOB)
"notify", SH_NOTIFY,
bashopt("nullglob", SH_NULLGLOB)
bashextra("onecmd", SH_TFLAG)
"pipefail", SH_PIPEFAIL,
bashextra("physical", SH_PHYSICAL)
bashextra("posix", SH_POSIX)
"posix", SH_POSIX,
"privileged", SH_PRIVILEGED,
#if SHOPT_BASH
"profile", SH_LOGIN_SHELL|SH_COMMANDLINE,
# if SHOPT_PFSH
"pfsh", SH_PFSH|SH_COMMANDLINE,
# endif
#else
# if SHOPT_PFSH
#if SHOPT_PFSH
"profile", SH_PFSH|SH_COMMANDLINE,
# endif
#endif
bashopt("progcomp", SH_PROGCOMP)
bashopt("promptvars", SH_PROMPTVARS)
"rc", SH_RC|SH_COMMANDLINE,
"restricted", SH_RESTRICTED,
bashopt("restricted_shell", SH_RESTRICTED2|SH_COMMANDLINE)
bashopt("shift_verbose", SH_SHIFT_VERBOSE)
"showme", SH_SHOWME,
bashopt("sourcepath", SH_SOURCEPATH)
"trackall", SH_TRACKALL,
"nounset", SH_NOUNSET,
"verbose", SH_VERBOSE,
"vi", SH_VI,
"viraw", SH_VIRAW,
bashopt("xpg_echo", SH_XPG_ECHO)
"xtrace", SH_XTRACE,
"", 0
};