update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:37:53 +08:00
parent bc194baf97
commit 4ad0178879
40 changed files with 61049 additions and 75 deletions
+124
View File
@@ -0,0 +1,124 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
lite_component("mksh") {
features = [
":sh"
]
}
# feature: sh
executable("sh") {
sources = [
"edit.c",
"eval.c",
"exec.c",
"expr.c",
"funcs.c",
"histrap.c",
"jobs.c",
"lalloc.c",
"lex.c",
"main.c",
"misc.c",
"shf.c",
"strlcpy.c",
"syn.c",
"tree.c",
"var.c",
]
include_dirs = [
"./",
]
cflags = [
"-Wall",
"-Wno-deprecated-declarations",
"-fno-asynchronous-unwind-tables",
"-fwrapv",
"-fstack-protector-all",
"-fPIE",
# various options we choose
"-DDEBUG_LEAKS",
"-DMKSH_ASSUME_UTF8",
"-DMKSH_DONT_EMIT_IDSTRING",
# and the defines from middleware file Rebuild.sh.
"-DMKSH_BUILDSH",
"-D_GNU_SOURCE",
"-DSETUID_CAN_FAIL_WITH_EAGAIN",
"-DHAVE_STRING_POOLING=2",
"-DHAVE_ATTRIBUTE_BOUNDED=0",
"-DHAVE_ATTRIBUTE_FORMAT=1",
"-DHAVE_ATTRIBUTE_NORETURN=1",
"-DHAVE_ATTRIBUTE_PURE=1",
"-DHAVE_ATTRIBUTE_UNUSED=1",
"-DHAVE_ATTRIBUTE_USED=1",
"-DHAVE_SYS_TIME_H=1",
"-DHAVE_TIME_H=1",
"-DHAVE_BOTH_TIME_H=1",
"-DHAVE_SYS_BSDTYPES_H=0",
"-DHAVE_SYS_FILE_H=1",
"-DHAVE_SYS_MKDEV_H=0",
"-DHAVE_SYS_MMAN_H=1",
"-DHAVE_SYS_PARAM_H=1",
"-DHAVE_SYS_RESOURCE_H=1",
"-DHAVE_SYS_SELECT_H=1",
"-DHAVE_SYS_SYSMACROS_H=1",
"-DHAVE_BSTRING_H=0",
"-DHAVE_GRP_H=1",
"-DHAVE_IO_H=0",
"-DHAVE_LIBGEN_H=1",
"-DHAVE_LIBUTIL_H=0",
"-DHAVE_PATHS_H=1",
"-DHAVE_STDINT_H=1",
"-DHAVE_STRINGS_H=1",
"-DHAVE_TERMIOS_H=1",
"-DHAVE_ULIMIT_H=1",
"-DHAVE_VALUES_H=1",
"-DHAVE_CAN_INTTYPES=1",
"-DHAVE_CAN_UCBINTS=1",
"-DHAVE_CAN_INT8TYPE=1",
"-DHAVE_CAN_UCBINT8=1",
"-DHAVE_RLIM_T=1",
"-DHAVE_SIG_T=1",
"-DHAVE_SYS_ERRLIST=1",
"-DHAVE_SYS_SIGNAME=0",
"-DHAVE_SYS_SIGLIST=1",
"-DHAVE_FLOCK=1",
"-DHAVE_LOCK_FCNTL=1",
"-DHAVE_GETRUSAGE=1",
"-DHAVE_GETSID=1",
"-DHAVE_GETTIMEOFDAY=1",
"-DHAVE_KILLPG=1",
"-DHAVE_MEMMOVE=1",
"-DHAVE_MKNOD=0",
"-DHAVE_MMAP=1",
"-DHAVE_FTRUNCATE=1",
"-DHAVE_NICE=1",
"-DHAVE_REVOKE=0",
"-DHAVE_SETLOCALE_CTYPE=1",
"-DHAVE_LANGINFO_CODESET=1",
"-DHAVE_SELECT=1",
"-DHAVE_SETRESUGID=1",
"-DHAVE_SETGROUPS=1",
"-DHAVE_STRERROR=1",
"-DHAVE_STRSIGNAL=0",
"-DHAVE_STRLCPY=0",
"-DHAVE_FLOCK_DECL=1",
"-DHAVE_REVOKE_DECL=1",
"-DHAVE_SYS_ERRLIST_DECL=1",
"-DHAVE_SYS_SIGLIST_DECL=1",
"-DHAVE_PERSISTENT_HISTORY=1",
"-DMKSH_BUILD_R=571",
]
ldflags = [
"-pie",
"-Wl,-z,relro",
"-Wl,-z,now",
"-Wl,-z,noexecstack",
]
}
+2791
View File
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
mirabilos <m@mirbsd.org>
Copyright (c) 2009, 2010, 2015, 2016
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
2019
2011, 2012, 2013, 2014, 2016, 2017, 2018
Copyright (c) 2016
Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
2011, 2012, 2014, 2015, 2016, 2017, 2018
Copyright (c) 2017
Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
2012, 2013, 2014, 2015, 2016, 2018
Copyright (c) 2009, 2010, 2011, 2013, 2014, 2016
Copyright © 2011, 2014, 2015
2011, 2012, 2013, 2014, 2015, 2016, 2017
Copyright (c) 2015
Copyright (c) 2015, 2017
Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2012, 2013, 2015, 2016, 2017, 2018
Copyright (c) 2006, 2008, 2009, 2013
Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018
2011, 2012, 2013, 2015, 2016, 2017
Copyright (c) 2009, 2011, 2012, 2016, 2018
+11
View File
@@ -0,0 +1,11 @@
[
{
"Name" : "mksh",
"License" : "MirOS License",
"License File" : "COPYRIGHT",
"Version Number" : "R57",
"Owner" : "maguangyao@huawei.com",
"Upstream URL" : "https://www.mirbsd.org/mksh.htm",
"Description" : "a secure operating system from the BSD family for 32-bit i386 and sparc systems"
}
]
-36
View File
@@ -1,36 +0,0 @@
# third_party_mksh
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
-39
View File
@@ -1,39 +0,0 @@
# third_party_mksh
#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+1363
View File
File diff suppressed because it is too large Load Diff
+13628
View File
File diff suppressed because it is too large Load Diff
+629
View File
@@ -0,0 +1,629 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.121 2017/08/08 21:10:21 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017
# mirabilos <m@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
# is granted to deal in this work without restriction, including un-
# limited rights to use, publicly perform, distribute, sell, modify,
# merge, give away, or sublicence.
#
# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
# the utmost extent permitted by applicable law, neither express nor
# implied; without malicious intent or gross negligence. In no event
# may a licensor, author or contributor be held liable for indirect,
# direct, other damage, loss, or other issues arising in any way out
# of dealing in the work, even if advised of the possibility of such
# damage or existence of a defect, except proven that it results out
# of said person's immediate fault when using the work as intended.
#-
# ${ENV:-~/.mkshrc}: mksh initialisation file for interactive shells
# catch non-mksh, non-lksh, trying to run this file
case ${KSH_VERSION:-} in
*LEGACY\ KSH*|*MIRBSD\ KSH*) ;;
*) \return 0 ;;
esac
# give MidnightBSD's laffer1 a bit of csh feeling
function setenv {
if (( $# )); then
\\builtin eval '\\builtin export "$1"="${2:-}"'
else
\\builtin typeset -x
fi
}
# pager (not control character safe)
smores() (
\\builtin set +m
\\builtin cat "$@" |&
\\builtin trap "rv=\$?; \\\\builtin kill $! >/dev/null 2>&1; \\\\builtin exit \$rv" EXIT
while IFS= \\builtin read -pr line; do
llen=${%line}
(( llen == -1 )) && llen=${#line}
(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
if (( (curlin += llen) >= LINES )); then
\\builtin print -nr -- $'\e[7m--more--\e[0m'
\\builtin read -u1 || \\builtin exit $?
[[ $REPLY = [Qq]* ]] && \\builtin exit 0
curlin=$llen
fi
\\builtin print -r -- "$line"
done
)
# customise your favourite editor here; the first one found is used
for EDITOR in "${EDITOR:-}" jupp jstar mcedit ed vi; do
EDITOR=$(\\builtin whence -p "$EDITOR") || EDITOR=
[[ -n $EDITOR && -x $EDITOR ]] && break
EDITOR=
done
\\builtin alias ls=ls l='ls -F' la='l -a' ll='l -l' lo='l -alo'
\: "${HOSTNAME:=$(\\builtin ulimit -c 0; \\builtin print -r -- $(hostname \
2>/dev/null))}${EDITOR:=/bin/ed}${TERM:=vt100}${USER:=$(\\builtin ulimit \
-c 0; id -un 2>/dev/null)}${USER:=?}"
[[ $HOSTNAME = ?(?(ip6-)localhost?(6)) ]] && HOSTNAME=nil; \\builtin unalias ls
\\builtin export EDITOR HOSTNAME TERM USER
# minimal support for lksh users
if [[ $KSH_VERSION = *LEGACY\ KSH* ]]; then
PS1='$USER@${HOSTNAME%%.*}:$PWD>'
\\builtin return 0
fi
# mksh-specific from here
\: "${MKSH:=$(\\builtin whence -p mksh)}${MKSH:=/bin/mksh}"
\\builtin export MKSH
# prompts
PS4='[$EPOCHREALTIME] '; PS1='#'; (( USER_ID )) && PS1='$'; PS1=$'\001\r''${|
\\builtin typeset e=$?
(( e )) && REPLY+="$e|"
REPLY+=${USER}@${HOSTNAME%%.*}:
\\builtin typeset d=${PWD:-?}/ p=~; [[ $p = ?(*/) ]] || d=${d/#$p\//\~/}
d=${d%/}; \\builtin typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p=
REPLY+=$p$d
\\builtin return $e
} '"$PS1 "
# utilities
\\builtin alias doch='sudo mksh -c "$(\\builtin fc -ln -1)"'
\\builtin command -v rot13 >/dev/null || \\builtin alias rot13='tr \
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \
nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
if \\builtin command -v hd >/dev/null; then
\:
elif \\builtin command -v hexdump >/dev/null; then
function hd {
hexdump -e '"%08.8_ax " 8/1 "%02X " " - " 8/1 "%02X "' \
-e '" |" "%_p"' -e '"|\n"' "$@"
}
else
function hd {
\\builtin cat "$@" | hd_mksh "$@"
}
fi
# NUL-safe and EBCDIC-safe hexdump (from stdin)
function hd_mksh {
\\builtin typeset -Uui16 -Z11 pos=0
\\builtin typeset -Uui16 -Z5 hv=2147483647
\\builtin typeset dasc dn line i
\\builtin set +U
while \\builtin read -arn 512 line; do
\\builtin typeset -i1 'line[*]'
i=0
while (( i < ${#line[*]} )); do
dn=
(( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#}
if (( (pos & 15) == 0 )); then
(( pos )) && \
\\builtin print -r -- "$dasc|"
\\builtin print -nr "${pos#16#} "
dasc=' |'
fi
\\builtin print -nr "${hv#16#} "
if [[ $dn = [[:print:]] ]]; then
dasc+=$dn
else
dasc+=.
fi
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
done
done
while (( pos & 15 )); do
\\builtin print -nr ' '
(( (pos++ & 15) == 7 )) && \
\\builtin print -nr -- '- '
done
(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|"
}
# Berkeley C shell compatible dirs, popd, and pushd functions
# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
DIRSTACKBASE=$(\\builtin realpath ~/. 2>/dev/null || \
\\builtin print -nr -- "${HOME:-/}")
\\builtin set -A DIRSTACK
function chpwd {
DIRSTACK[0]=$(\\builtin realpath . 2>/dev/null || \
\\builtin print -nr -- "$PWD")
[[ $DIRSTACKBASE = ?(*/) ]] || \
DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/\~}
\:
}
\chpwd .
cd() {
\\builtin cd "$@" || \\builtin return $?
\chpwd "$@"
}
function cd_csh {
\\builtin typeset d t=${1/#\~/$DIRSTACKBASE}
if ! d=$(\\builtin cd "$t" 2>&1); then
\\builtin print -ru2 "${1}: ${d##*cd: $t: }."
\\builtin return 1
fi
\cd "$t"
}
function dirs {
\\builtin typeset d dwidth
\\builtin typeset -i fl=0 fv=0 fn=0 cpos=0
while \\builtin getopts ":lvn" d; do
case $d {
(l) fl=1 ;;
(v) fv=1 ;;
(n) fn=1 ;;
(*) \\builtin print -ru2 'Usage: dirs [-lvn].'
\\builtin return 1 ;;
}
done
\\builtin shift $((OPTIND - 1))
if (( $# > 0 )); then
\\builtin print -ru2 'Usage: dirs [-lvn].'
\\builtin return 1
fi
if (( fv )); then
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
(( fl )) && d=${d/#\~/$DIRSTACKBASE}
\\builtin print -r -- "$fv $d"
(( ++fv ))
done
else
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
(( fl )) && d=${d/#\~/$DIRSTACKBASE}
(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) ))
if (( fn && (cpos += dwidth + 1) >= 79 && \
dwidth < 80 )); then
\\builtin print
(( cpos = dwidth + 1 ))
fi
\\builtin print -nr -- "$d "
(( ++fv ))
done
\\builtin print
fi
\\builtin return 0
}
function popd {
\\builtin typeset d fa
\\builtin typeset -i n=1
while \\builtin getopts ":0123456789lvn" d; do
case $d {
(l|v|n) fa+=" -$d" ;;
(+*) n=2
\\builtin break ;;
(*) \\builtin print -ru2 'Usage: popd [-lvn] [+<n>].'
\\builtin return 1 ;;
}
done
\\builtin shift $((OPTIND - n))
n=0
if (( $# > 1 )); then
\\builtin print -ru2 popd: Too many arguments.
\\builtin return 1
elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
\\builtin print -ru2 popd: Directory stack not that deep.
\\builtin return 1
fi
elif [[ -n $1 ]]; then
\\builtin print -ru2 popd: Bad directory.
\\builtin return 1
fi
if (( ${#DIRSTACK[*]} < 2 )); then
\\builtin print -ru2 popd: Directory stack empty.
\\builtin return 1
fi
\\builtin unset DIRSTACK[n]
\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}"
\cd_csh "${DIRSTACK[0]}" || \\builtin return 1
\dirs $fa
}
function pushd {
\\builtin typeset d fa
\\builtin typeset -i n=1
while \\builtin getopts ":0123456789lvn" d; do
case $d {
(l|v|n) fa+=" -$d" ;;
(+*) n=2
\\builtin break ;;
(*) \\builtin print -ru2 'Usage: pushd [-lvn] [<dir>|+<n>].'
\\builtin return 1 ;;
}
done
\\builtin shift $((OPTIND - n))
if (( $# == 0 )); then
if (( ${#DIRSTACK[*]} < 2 )); then
\\builtin print -ru2 pushd: No other directory.
\\builtin return 1
fi
d=${DIRSTACK[1]}
DIRSTACK[1]=${DIRSTACK[0]}
\cd_csh "$d" || \\builtin return 1
elif (( $# > 1 )); then
\\builtin print -ru2 pushd: Too many arguments.
\\builtin return 1
elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
\\builtin print -ru2 pushd: Directory stack not that deep.
\\builtin return 1
fi
while (( n-- )); do
d=${DIRSTACK[0]}
\\builtin unset DIRSTACK[0]
\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}" "$d"
done
\cd_csh "${DIRSTACK[0]}" || \\builtin return 1
else
\\builtin set -A DIRSTACK -- placeholder "${DIRSTACK[@]}"
\cd_csh "$1" || \\builtin return 1
fi
\dirs $fa
}
# base64 encoder and decoder, RFC compliant, NUL safe, not EBCDIC safe
function Lb64decode {
\\builtin set +U
\\builtin typeset c s="$*" t
[[ -n $s ]] || { s=$(\\builtin cat; \\builtin print x); s=${s%x}; }
\\builtin typeset -i i=0 j=0 n=${#s} p=0 v x
\\builtin typeset -i16 o
while (( i < n )); do
c=${s:(i++):1}
case $c {
(=) \\builtin break ;;
([A-Z]) (( v = 1#$c - 65 )) ;;
([a-z]) (( v = 1#$c - 71 )) ;;
([0-9]) (( v = 1#$c + 4 )) ;;
(+) v=62 ;;
(/) v=63 ;;
(*) \\builtin continue ;;
}
(( x = (x << 6) | v ))
case $((p++)) {
(0) \\builtin continue ;;
(1) (( o = (x >> 4) & 255 )) ;;
(2) (( o = (x >> 2) & 255 )) ;;
(3) (( o = x & 255 ))
p=0
;;
}
t+=\\x${o#16#}
(( ++j & 4095 )) && \\builtin continue
\\builtin print -n $t
t=
done
\\builtin print -n $t
}
function Lb64encode {
\\builtin set +U
\\builtin typeset c s t table
\\builtin set -A table -- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /
if (( $# )); then
\\builtin read -raN-1 s <<<"$*"
\\builtin unset s[${#s[*]}-1]
else
\\builtin read -raN-1 s
fi
\\builtin typeset -i i=0 n=${#s[*]} v
while (( i < n )); do
(( v = s[i++] << 16 ))
(( v |= s[i++] << 8 ))
(( v |= s[i++] ))
t+=${table[v >> 18]}${table[v >> 12 & 63]}
c=${table[v >> 6 & 63]}
if (( i <= n )); then
t+=$c${table[v & 63]}
elif (( i == n + 1 )); then
t+=$c=
else
t+===
fi
if (( ${#t} == 76 || i >= n )); then
\\builtin print -r $t
t=
fi
done
}
# Better Avalanche for the Jenkins Hash
\\builtin typeset -Z11 -Uui16 Lbafh_v
function Lbafh_init {
Lbafh_v=0
}
function Lbafh_add {
\\builtin set +U
\\builtin typeset s
if (( $# )); then
\\builtin read -raN-1 s <<<"$*"
\\builtin unset s[${#s[*]}-1]
else
\\builtin read -raN-1 s
fi
\\builtin typeset -i i=0 n=${#s[*]}
while (( i < n )); do
((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 ))
((# Lbafh_v ^= Lbafh_v >> 6 ))
done
}
function Lbafh_finish {
\\builtin typeset -Ui t
((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \
((Lbafh_v << 1) & 0xFEFEFEFE) ))
((# Lbafh_v = t ^ (t ^> 8) ^ (Lbafh_v ^> 8) ^ \
(Lbafh_v ^> 16) ^ (Lbafh_v ^> 24) ))
\:
}
# strip comments (and leading/trailing whitespace if IFS is set) from
# any file(s) given as argument, or stdin if none, and spew to stdout
function Lstripcom {
\\builtin set -o noglob
\\builtin cat "$@" | while \\builtin read _line; do
_line=${_line%%#*}
[[ -n $_line ]] && \\builtin print -r -- $_line
done
}
# toggle built-in aliases and utilities, and aliases and functions from mkshrc
function enable {
\\builtin typeset doprnt=0 mode=1 x y z rv=0
\\builtin typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all
\\builtin set -A b_alias
\\builtin set -A i_alias
\\builtin set -A i_func
# accumulate mksh built-in aliases, in ASCIIbetical order
i_alias[nalias]=autoload; b_alias[nalias++]='\\builtin typeset -fu'
i_alias[nalias]=functions; b_alias[nalias++]='\\builtin typeset -f'
i_alias[nalias]=hash; b_alias[nalias++]='\\builtin alias -t'
i_alias[nalias]=history; b_alias[nalias++]='\\builtin fc -l'
i_alias[nalias]=integer; b_alias[nalias++]='\\builtin typeset -i'
i_alias[nalias]=local; b_alias[nalias++]='\\builtin typeset'
i_alias[nalias]=login; b_alias[nalias++]='\\builtin exec login'
i_alias[nalias]=nameref; b_alias[nalias++]='\\builtin typeset -n'
i_alias[nalias]=nohup; b_alias[nalias++]='nohup '
i_alias[nalias]=r; b_alias[nalias++]='\\builtin fc -e -'
i_alias[nalias]=type; b_alias[nalias++]='\\builtin whence -v'
# accumulate mksh built-in utilities, in definition order, even ifndef
i_func[nfunc++]=.
i_func[nfunc++]=:
i_func[nfunc++]='['
i_func[nfunc++]=alias
i_func[nfunc++]=break
# \\builtin cannot, by design, be overridden
i_func[nfunc++]=builtin
i_func[nfunc++]=cat
i_func[nfunc++]=cd
i_func[nfunc++]=chdir
i_func[nfunc++]=command
i_func[nfunc++]=continue
i_func[nfunc++]=echo
i_func[nfunc++]=eval
i_func[nfunc++]=exec
i_func[nfunc++]=exit
i_func[nfunc++]=export
i_func[nfunc++]=false
i_func[nfunc++]=fc
i_func[nfunc++]=getopts
i_func[nfunc++]=global
i_func[nfunc++]=jobs
i_func[nfunc++]=kill
i_func[nfunc++]=let
i_func[nfunc++]=print
i_func[nfunc++]=pwd
i_func[nfunc++]=read
i_func[nfunc++]=readonly
i_func[nfunc++]=realpath
i_func[nfunc++]=rename
i_func[nfunc++]=return
i_func[nfunc++]=set
i_func[nfunc++]=shift
i_func[nfunc++]=source
i_func[nfunc++]=suspend
i_func[nfunc++]=test
i_func[nfunc++]=times
i_func[nfunc++]=trap
i_func[nfunc++]=true
i_func[nfunc++]=typeset
i_func[nfunc++]=ulimit
i_func[nfunc++]=umask
i_func[nfunc++]=unalias
i_func[nfunc++]=unset
i_func[nfunc++]=wait
i_func[nfunc++]=whence
i_func[nfunc++]=bg
i_func[nfunc++]=fg
i_func[nfunc++]=bind
i_func[nfunc++]=mknod
i_func[nfunc++]=printf
i_func[nfunc++]=sleep
i_func[nfunc++]=domainname
i_func[nfunc++]=extproc
# accumulate aliases from dot.mkshrc, in definition order
i_alias[nalias]=l; b_alias[nalias++]='ls -F'
i_alias[nalias]=la; b_alias[nalias++]='l -a'
i_alias[nalias]=ll; b_alias[nalias++]='l -l'
i_alias[nalias]=lo; b_alias[nalias++]='l -alo'
i_alias[nalias]=doch; b_alias[nalias++]='sudo mksh -c "$(\\builtin fc -ln -1)"'
i_alias[nalias]=rot13; b_alias[nalias++]='tr abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
i_alias[nalias]=cls; b_alias[nalias++]='\\builtin print -n \\ec'
# accumulate functions from dot.mkshrc, in definition order
i_func[nfunc++]=setenv
i_func[nfunc++]=smores
i_func[nfunc++]=hd
i_func[nfunc++]=hd_mksh
i_func[nfunc++]=chpwd
i_func[nfunc++]=cd
i_func[nfunc++]=cd_csh
i_func[nfunc++]=dirs
i_func[nfunc++]=popd
i_func[nfunc++]=pushd
i_func[nfunc++]=Lb64decode
i_func[nfunc++]=Lb64encode
i_func[nfunc++]=Lbafh_init
i_func[nfunc++]=Lbafh_add
i_func[nfunc++]=Lbafh_finish
i_func[nfunc++]=Lstripcom
i_func[nfunc++]=enable
# collect all identifiers, sorted ASCIIbetically
\\builtin set -sA i_all -- "${i_alias[@]}" "${i_func[@]}"
# handle options, we don't do dynamic loading
while \\builtin getopts "adf:nps" x; do
case $x {
(a)
mode=-1
;;
(d)
# deliberately causing an error, like bash-static
;|
(f)
\\builtin print -ru2 enable: dynamic loading not available
\\builtin return 2
;;
(n)
mode=0
;;
(p)
doprnt=1
;;
(s)
\\builtin set -sA i_all -- . : break continue eval \
exec exit export readonly return set shift times \
trap unset
;;
(*)
\\builtin print -ru2 enable: usage: \
"enable [-adnps] [-f filename] [name ...]"
return 2
;;
}
done
\\builtin shift $((OPTIND - 1))
# display builtins enabled/disabled/all/special?
if (( doprnt || ($# == 0) )); then
for x in "${i_all[@]}"; do
y=$(\\builtin alias "$x") || y=
[[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$?
case $mode:$z {
(-1:0|0:0)
\\builtin print -r -- "enable -n $x"
;;
(-1:1|1:1)
\\builtin print -r -- "enable $x"
;;
}
done
\\builtin return 0
fi
for x in "$@"; do
z=0
for y in "${i_alias[@]}" "${i_func[@]}"; do
[[ $x = "$y" ]] || \\builtin continue
z=1
\\builtin break
done
if (( !z )); then
\\builtin print -ru2 enable: "$x": not a shell builtin
rv=1
\\builtin continue
fi
if (( !mode )); then
# disable this
\\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)"
else
# find out if this is an alias or not, first
z=0
y=-1
while (( ++y < nalias )); do
[[ $x = "${i_alias[y]}" ]] || \\builtin continue
z=1
\\builtin break
done
if (( z )); then
# re-enable the original alias body
\\builtin alias "$x=${b_alias[y]}"
else
# re-enable the original utility/function
\\builtin unalias "$x"
fi
fi
done
\\builtin return $rv
}
\: place customisations below this line
# some defaults follow — you are supposed to adjust these to your
# liking; by default we add ~/.etc/bin and ~/bin (whichever exist)
# to $PATH, set $SHELL to mksh, set some defaults for man and less
# and show a few more possible things for users to begin moving in
for p in ~/.etc/bin ~/bin; do
[[ -d $p/. ]] || \\builtin continue
[[ $PATHSEP$PATH$PATHSEP = *"$PATHSEP$p$PATHSEP"* ]] || \
PATH=$p$PATHSEP$PATH
done
\\builtin export SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=-
\\builtin alias cls='\\builtin print -n \\ec'
#\\builtin unset LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_IDENTIFICATION LC_MONETARY \
# LC_NAME LC_NUMERIC LC_TELEPHONE LC_TIME
#p=en_GB.UTF-8
#\\builtin export LANG=C LC_CTYPE=$p LC_MEASUREMENT=$p LC_MESSAGES=$p LC_PAPER=$p
#\\builtin set -U
\\builtin unset p
\: place customisations above this line
+5648
View File
File diff suppressed because it is too large Load Diff
+113
View File
@@ -0,0 +1,113 @@
/*-
* Copyright (c) 2009, 2010, 2015, 2016
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#if defined(EMACSFN_DEFNS)
__RCSID("$MirOS: src/bin/mksh/emacsfn.h,v 1.10 2016/09/01 12:59:09 tg Exp $");
#define FN(cname,sname,flags) static int x_##cname(int);
#elif defined(EMACSFN_ENUMS)
#define FN(cname,sname,flags) XFUNC_##cname,
#define F0(cname,sname,flags) XFUNC_##cname = 0,
#elif defined(EMACSFN_ITEMS)
#define FN(cname,sname,flags) { x_##cname, sname, flags },
#endif
#ifndef F0
#define F0 FN
#endif
F0(abort, "abort", 0)
FN(beg_hist, "beginning-of-history", 0)
FN(cls, "clear-screen", 0)
FN(comment, "comment", 0)
FN(comp_comm, "complete-command", 0)
FN(comp_file, "complete-file", 0)
FN(comp_list, "complete-list", 0)
FN(complete, "complete", 0)
FN(del_back, "delete-char-backward", XF_ARG)
FN(del_bword, "delete-word-backward", XF_ARG)
FN(del_char, "delete-char-forward", XF_ARG)
FN(del_fword, "delete-word-forward", XF_ARG)
FN(del_line, "kill-line", 0)
FN(draw_line, "redraw", 0)
#ifndef MKSH_SMALL
FN(edit_line, "edit-line", XF_ARG)
#endif
FN(end_hist, "end-of-history", 0)
FN(end_of_text, "eot", 0)
FN(enumerate, "list", 0)
FN(eot_del, "eot-or-delete", XF_ARG)
FN(error, "error", 0)
#ifndef MKSH_SMALL
FN(eval_region, "evaluate-region", 0)
#endif
FN(expand, "expand-file", 0)
#ifndef MKSH_SMALL
FN(fold_capitalise, "capitalize-word", XF_ARG)
FN(fold_lower, "downcase-word", XF_ARG)
FN(fold_upper, "upcase-word", XF_ARG)
#endif
FN(goto_hist, "goto-history", XF_ARG)
#ifndef MKSH_SMALL
FN(ins_string, "macro-string", XF_NOBIND)
#endif
FN(insert, "auto-insert", XF_ARG)
FN(kill, "kill-to-eol", XF_ARG)
FN(kill_region, "kill-region", 0)
FN(list_comm, "list-command", 0)
FN(list_file, "list-file", 0)
FN(literal, "quote", 0)
FN(meta1, "prefix-1", XF_PREFIX)
FN(meta2, "prefix-2", XF_PREFIX)
FN(meta3, "prefix-3", XF_PREFIX)
FN(meta_yank, "yank-pop", 0)
FN(mv_back, "backward-char", XF_ARG)
FN(mv_beg, "beginning-of-line", 0)
FN(mv_bword, "backward-word", XF_ARG)
FN(mv_end, "end-of-line", 0)
FN(mv_forw, "forward-char", XF_ARG)
FN(mv_fword, "forward-word", XF_ARG)
FN(newline, "newline", 0)
FN(next_com, "down-history", XF_ARG)
FN(nl_next_com, "newline-and-next", 0)
FN(noop, "no-op", 0)
FN(prev_com, "up-history", XF_ARG)
FN(prev_histword, "prev-hist-word", XF_ARG)
FN(search_char_back, "search-character-backward", XF_ARG)
FN(search_char_forw, "search-character-forward", XF_ARG)
FN(search_hist, "search-history", 0)
#ifndef MKSH_SMALL
FN(search_hist_dn, "search-history-down", 0)
FN(search_hist_up, "search-history-up", 0)
#endif
FN(set_arg, "set-arg", XF_NOBIND)
FN(set_mark, "set-mark-command", 0)
FN(transpose, "transpose-chars", 0)
FN(version, "version", 0)
#ifndef MKSH_SMALL
FN(vt_hack, "vt100-hack", XF_ARG)
#endif
FN(xchg_point_mark, "exchange-point-and-mark", 0)
FN(yank, "yank", 0)
#undef FN
#undef F0
#undef EMACSFN_DEFNS
#undef EMACSFN_ENUMS
#undef EMACSFN_ITEMS
+1961
View File
File diff suppressed because it is too large Load Diff
+1875
View File
File diff suppressed because it is too large Load Diff
+1197
View File
File diff suppressed because it is too large Load Diff
+123
View File
@@ -0,0 +1,123 @@
/*-
* Copyright (c) 2016
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#if defined(EXPRTOK_DEFNS)
__RCSID("$MirOS: src/bin/mksh/exprtok.h,v 1.2 2016/08/12 16:48:05 tg Exp $");
/* see range comment below */
#define IS_ASSIGNOP(op) ((int)(op) >= (int)O_ASN && (int)(op) <= (int)O_BORASN)
#define FN(name, len, prec, enum) /* nothing */
#define F1(enum) /* nothing */
#elif defined(EXPRTOK_ENUM)
#define F0(name, len, prec, enum) enum = 0,
#define FN(name, len, prec, enum) enum,
#define F1(enum) enum,
#define F2(enum) enum,
#define F9(enum) enum
#elif defined(EXPRTOK_NAME)
#define FN(name, len, prec, enum) name,
#define F1(enum) ""
#elif defined(EXPRTOK_LEN)
#define FN(name, len, prec, enum) len,
#define F1(enum) 0
#elif defined(EXPRTOK_PREC)
#define FN(name, len, prec, enum) prec,
#define F1(enum) P_PRIMARY
#endif
#ifndef F0
#define F0 FN
#endif
#ifndef F2
#define F2(enum) /* nothing */
#define F9(enum) /* nothing */
#endif
/* tokens must be ordered so the longest are first (e.g. += before +) */
/* some (long) unary operators */
FN("++", 2, P_PRIMARY, O_PLUSPLUS = 0) /* before + */
FN("--", 2, P_PRIMARY, O_MINUSMINUS) /* before - */
/* binary operators */
FN("==", 2, P_EQUALITY, O_EQ) /* before = */
FN("!=", 2, P_EQUALITY, O_NE) /* before ! */
/* assignments are assumed to be in range O_ASN .. O_BORASN */
FN("=", 1, P_ASSIGN, O_ASN)
FN("*=", 2, P_ASSIGN, O_TIMESASN)
FN("/=", 2, P_ASSIGN, O_DIVASN)
FN("%=", 2, P_ASSIGN, O_MODASN)
FN("+=", 2, P_ASSIGN, O_PLUSASN)
FN("-=", 2, P_ASSIGN, O_MINUSASN)
#ifndef MKSH_LEGACY_MODE
FN("^<=", 3, P_ASSIGN, O_ROLASN) /* before ^< */
FN("^>=", 3, P_ASSIGN, O_RORASN) /* before ^> */
#endif
FN("<<=", 3, P_ASSIGN, O_LSHIFTASN)
FN(">>=", 3, P_ASSIGN, O_RSHIFTASN)
FN("&=", 2, P_ASSIGN, O_BANDASN)
FN("^=", 2, P_ASSIGN, O_BXORASN)
FN("|=", 2, P_ASSIGN, O_BORASN)
/* binary non-assignment operators */
#ifndef MKSH_LEGACY_MODE
FN("^<", 2, P_SHIFT, O_ROL) /* before ^ */
FN("^>", 2, P_SHIFT, O_ROR) /* before ^ */
#endif
FN("<<", 2, P_SHIFT, O_LSHIFT)
FN(">>", 2, P_SHIFT, O_RSHIFT)
FN("<=", 2, P_RELATION, O_LE)
FN(">=", 2, P_RELATION, O_GE)
FN("<", 1, P_RELATION, O_LT)
FN(">", 1, P_RELATION, O_GT)
FN("&&", 2, P_LAND, O_LAND)
FN("||", 2, P_LOR, O_LOR)
FN("*", 1, P_MULT, O_TIMES)
FN("/", 1, P_MULT, O_DIV)
FN("%", 1, P_MULT, O_MOD)
FN("+", 1, P_ADD, O_PLUS)
FN("-", 1, P_ADD, O_MINUS)
FN("&", 1, P_BAND, O_BAND)
FN("^", 1, P_BXOR, O_BXOR)
FN("|", 1, P_BOR, O_BOR)
FN("?", 1, P_TERN, O_TERN)
FN(",", 1, P_COMMA, O_COMMA)
/* things after this aren't used as binary operators */
/* unary that are not also binaries */
FN("~", 1, P_PRIMARY, O_BNOT)
FN("!", 1, P_PRIMARY, O_LNOT)
/* misc */
FN("(", 1, P_PRIMARY, OPEN_PAREN)
FN(")", 1, P_PRIMARY, CLOSE_PAREN)
FN(":", 1, P_PRIMARY, CTERN)
/* things that don't appear in the opinfo[] table */
F1(VAR) /*XXX should be F2 */
F2(LIT)
F2(END)
F9(BAD)
#undef FN
#undef F0
#undef F1
#undef F2
#undef F9
#undef EXPRTOK_DEFNS
#undef EXPRTOK_ENUM
#undef EXPRTOK_NAME
#undef EXPRTOK_LEN
#undef EXPRTOK_PREC
+3635
View File
File diff suppressed because it is too large Load Diff
+1628
View File
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
/*-
* Copyright (c) 2017
* Giacomo Tesio <giacomo@tesio.it>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*-
* Initialisation code for the Jehanne operating system (a Plan 9 de-
* rivative, using GCC)
*/
static const char __rcsid[] __attribute__((__used__)) =
"$MirOS: src/bin/mksh/jehanne.c,v 1.1 2017/12/22 16:30:00 tg Exp $";
#include <u.h>
#include <lib9.h>
#include <posix.h>
void
__application_newlib_init(int argc, char *argv[])
{
rfork(RFFDG | RFREND | RFNOTEG);
libposix_emulate_SIGCHLD();
}
+1951
View File
File diff suppressed because it is too large Load Diff
+193
View File
@@ -0,0 +1,193 @@
/*-
* Copyright (c) 2009, 2010, 2011, 2013, 2014, 2016
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#include "sh.h"
#ifdef MKSH_ALLOC_CATCH_UNDERRUNS
#include <err.h>
#endif
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.26 2016/02/26 21:53:36 tg Exp $");
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
#define remalloc(p,n) ((p) == NULL ? malloc_osi(n) : realloc_osi((p), (n)))
#else
#define remalloc(p,n) realloc_osi((p), (n))
#endif
static struct lalloc_common *findptr(struct lalloc_common **, char *, Area *);
#ifndef MKSH_ALLOC_CATCH_UNDERRUNS
#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % sizeof(struct lalloc_common))
#else
#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) & 4095)
#undef remalloc
#undef free_osimalloc
static void
free_osimalloc(void *ptr)
{
struct lalloc_item *lp = ptr;
if (munmap(lp, lp->len))
err(1, "free_osimalloc");
}
static void *
remalloc(void *ptr, size_t size)
{
struct lalloc_item *lp, *lold = ptr;
size = (size + 4095) & ~(size_t)4095;
if (lold && lold->len >= size)
return (ptr);
if ((lp = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, (off_t)0)) == MAP_FAILED)
err(1, "remalloc: mmap(%zu)", size);
if (ALLOC_ISUNALIGNED(lp))
errx(1, "remalloc: unaligned(%p)", lp);
if (mprotect(((char *)lp) + 4096, 4096, PROT_NONE))
err(1, "remalloc: mprotect");
lp->len = size;
if (lold) {
memcpy(((char *)lp) + 8192, ((char *)lold) + 8192,
lold->len - 8192);
if (munmap(lold, lold->len))
err(1, "remalloc: munmap");
}
return (lp);
}
#endif
void
ainit(Area *ap)
{
#ifdef MKSH_ALLOC_CATCH_UNDERRUNS
if (sysconf(_SC_PAGESIZE) != 4096) {
fprintf(stderr, "mksh: fatal: pagesize %lu not 4096!\n",
sysconf(_SC_PAGESIZE));
fflush(stderr);
abort();
}
#endif
/* area pointer and items share struct lalloc_common */
ap->next = NULL;
}
static struct lalloc_common *
findptr(struct lalloc_common **lpp, char *ptr, Area *ap)
{
void *lp;
#ifndef MKSH_SMALL
if (ALLOC_ISUNALIGNED(ptr))
goto fail;
#endif
/* get address of ALLOC_ITEM from user item */
/*
* note: the alignment of "ptr" to ALLOC_ITEM is checked
* above; the "void *" gets us rid of a gcc 2.95 warning
*/
*lpp = (lp = ptr - sizeof(ALLOC_ITEM));
/* search for allocation item in group list */
while (ap->next != lp)
if ((ap = ap->next) == NULL) {
#ifndef MKSH_SMALL
fail:
#endif
#ifdef DEBUG
internal_warningf("rogue pointer %zX in ap %zX",
(size_t)ptr, (size_t)ap);
/* try to get a coredump */
abort();
#else
internal_errorf("rogue pointer %zX", (size_t)ptr);
#endif
}
return (ap);
}
void *
aresize2(void *ptr, size_t fac1, size_t fac2, Area *ap)
{
if (notoktomul(fac1, fac2))
internal_errorf(Tintovfl, fac1, '*', fac2);
return (aresize(ptr, fac1 * fac2, ap));
}
void *
aresize(void *ptr, size_t numb, Area *ap)
{
struct lalloc_common *lp = NULL;
/* resizing (true) or newly allocating? */
if (ptr != NULL) {
struct lalloc_common *pp;
pp = findptr(&lp, ptr, ap);
pp->next = lp->next;
}
if (notoktoadd(numb, sizeof(ALLOC_ITEM)) ||
(lp = remalloc(lp, numb + sizeof(ALLOC_ITEM))) == NULL
#ifndef MKSH_SMALL
|| ALLOC_ISUNALIGNED(lp)
#endif
)
internal_errorf(Toomem, numb);
/* area pointer and items share struct lalloc_common */
lp->next = ap->next;
ap->next = lp;
/* return user item address */
return ((char *)lp + sizeof(ALLOC_ITEM));
}
void
afree(void *ptr, Area *ap)
{
if (ptr != NULL) {
struct lalloc_common *lp, *pp;
pp = findptr(&lp, ptr, ap);
/* unhook */
pp->next = lp->next;
/* now free ALLOC_ITEM */
free_osimalloc(lp);
}
}
void
afreeall(Area *ap)
{
struct lalloc_common *lp;
/* traverse group (linked list) */
while ((lp = ap->next) != NULL) {
/* make next ALLOC_ITEM head of list */
ap->next = lp->next;
/* free old head */
free_osimalloc(lp);
}
}
+1821
View File
File diff suppressed because it is too large Load Diff
+354
View File
@@ -0,0 +1,354 @@
.\" $MirOS: src/bin/mksh/lksh.1,v 1.25 2018/12/25 19:38:08 tg Exp $
.\"-
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017, 2018
.\" mirabilos <m@mirbsd.org>
.\"
.\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission
.\" is granted to deal in this work without restriction, including un
.\" limited rights to use, publicly perform, distribute, sell, modify,
.\" merge, give away, or sublicence.
.\"
.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
.\" the utmost extent permitted by applicable law, neither express nor
.\" implied; without malicious intent or gross negligence. In no event
.\" may a licensor, author or contributor be held liable for indirect,
.\" direct, other damage, loss, or other issues arising in any way out
.\" of dealing in the work, even if advised of the possibility of such
.\" damage or existence of a defect, except proven that it results out
.\" of said persons immediate fault when using the work as intended.
.\"-
.\" Try to make GNU groff and AT&T nroff more compatible
.\" * ` generates in gnroff, so use \`
.\" * ' generates in gnroff, \' generates ´, so use \*(aq
.\" * - generates in gnroff, \- generates , so .tr it to -
.\" thus use - for hyphens and \- for minus signs and option dashes
.\" * ~ is size-reduced and placed atop in groff, so use \*(TI
.\" * ^ is size-reduced and placed atop in groff, so use \*(ha
.\" * \(en does not work in nroff, so use \*(en
.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
.\" Also make sure to use \& *before* a punctuation char that is to not
.\" be interpreted as punctuation, and especially with two-letter words
.\" but also (after) a period that does not end a sentence (“e.g.\&”).
.\" The section after the "doc" macropackage has been loaded contains
.\" additional code to convene between the UCB mdoc macropackage (and
.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
.\"
.ie \n(.g \{\
. if \*[.T]ascii .tr \-\N'45'
. if \*[.T]latin1 .tr \-\N'45'
. if \*[.T]utf8 .tr \-\N'45'
. ds <= \[<=]
. ds >= \[>=]
. ds Rq \[rq]
. ds Lq \[lq]
. ds sL \(aq
. ds sR \(aq
. if \*[.T]utf8 .ds sL `
. if \*[.T]ps .ds sL `
. if \*[.T]utf8 .ds sR '
. if \*[.T]ps .ds sR '
. ds aq \(aq
. ds TI \(ti
. ds ha \(ha
. ds en \(en
.\}
.el \{\
. ds aq '
. ds TI ~
. ds ha ^
. ds en \(em
.\}
.\"
.\" Implement .Dd with the Mdocdate RCS keyword
.\"
.rn Dd xD
.de Dd
.ie \\$1$Mdocdate: \{\
. xD \\$2 \\$3, \\$4
.\}
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"
.\" .Dd must come before definition of .Mx, because when called
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: December 25 2018 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
.ie \n(.g \{\
. if \*[.T]utf8 .tr \[la]\*(Lt
. if \*[.T]utf8 .tr \[ra]\*(Gt
. ie d volume-ds-1 .ds tT gnu
. el .ie d doc-volume-ds-1 .ds tT gnp
. el .ds tT bsd
.\}
.el .ds tT ucb
.\"
.\" Implement .Mx (MirBSD)
.\"
.ie "\*(tT"gnu" \{\
. eo
. de Mx
. nr curr-font \n[.f]
. nr curr-size \n[.ps]
. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
. ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx]
. if !\n[arg-limit] \
. if \n[.$] \{\
. ds macro-name Mx
. parse-args \$@
. \}
. if (\n[arg-limit] > \n[arg-ptr]) \{\
. nr arg-ptr +1
. ie (\n[type\n[arg-ptr]] == 2) \
. as str-Mx1 \~\*[arg\n[arg-ptr]]
. el \
. nr arg-ptr -1
. \}
. ds arg\n[arg-ptr] "\*[str-Mx1]
. nr type\n[arg-ptr] 2
. ds space\n[arg-ptr] "\*[space]
. nr num-args (\n[arg-limit] - \n[arg-ptr])
. nr arg-limit \n[arg-ptr]
. if \n[num-args] \
. parse-space-vector
. print-recursive
..
. ec
. ds sP \s0
. ds tN \*[Tn-font-size]
.\}
.el .ie "\*(tT"gnp" \{\
. eo
. de Mx
. nr doc-curr-font \n[.f]
. nr doc-curr-size \n[.ps]
. ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u]
. ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx]
. if !\n[doc-arg-limit] \
. if \n[.$] \{\
. ds doc-macro-name Mx
. doc-parse-args \$@
. \}
. if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\
. nr doc-arg-ptr +1
. ie (\n[doc-type\n[doc-arg-ptr]] == 2) \
. as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]]
. el \
. nr doc-arg-ptr -1
. \}
. ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1]
. nr doc-type\n[doc-arg-ptr] 2
. ds doc-space\n[doc-arg-ptr] "\*[doc-space]
. nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr])
. nr doc-arg-limit \n[doc-arg-ptr]
. if \n[doc-num-args] \
. doc-parse-space-vector
. doc-print-recursive
..
. ec
. ds sP \s0
. ds tN \*[doc-Tn-font-size]
.\}
.el \{\
. de Mx
. nr cF \\n(.f
. nr cZ \\n(.s
. ds aa \&\f\\n(cF\s\\n(cZ
. if \\n(aC==0 \{\
. ie \\n(.$==0 \&MirBSD\\*(aa
. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
. \}
. if \\n(aC>\\n(aP \{\
. nr aP \\n(aP+1
. ie \\n(C\\n(aP==2 \{\
. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa
. ie \\n(aC>\\n(aP \{\
. nr aP \\n(aP+1
. nR
. \}
. el .aZ
. \}
. el \{\
. as b1 \&MirBSD\\*(aa
. nR
. \}
. \}
..
.\}
.\"-
.Dt LKSH 1
.Os MirBSD
.Sh NAME
.Nm lksh
.Nd Legacy Korn shell built on mksh
.Sh SYNOPSIS
.Nm
.Bk -words
.Op Fl +abCefhiklmnprUuvXx
.Op Fl +o Ar opt
.Oo
.Fl c Ar string \*(Ba
.Fl s \*(Ba
.Ar file
.Op Ar args ...
.Oc
.Ek
.Sh DESCRIPTION
.Nm
is a command interpreter intended exclusively for running legacy
shell scripts.
It is built on
.Nm mksh ;
refer to its manual page for details on the scripting language.
It is recommended to port scripts to
.Nm mksh
instead of relying on legacy or objectionable POSIX-mandated behaviour,
since the MirBSD Korn Shell scripting language is much more consistent.
.Pp
Do not use
.Nm
as an interactive or login shell; use
.Nm mksh
instead.
.Pp
Note that it's strongly recommended to invoke
.Nm
with
.Fl o Ic posix
to fully enjoy better compatibility to the
.Tn POSIX
standard (which is probably why you use
.Nm
over
.Nm mksh
in the first place);
.Fl o Ic sh
(possibly additionally to the above) may be needed for some legacy scripts.
.Sh LEGACY MODE
.Nm
currently has the following differences from
.Nm mksh :
.Bl -bullet
.It
The
.Ev KSH_VERSION
string identifies
.Nm
as
.Dq Li LEGACY KSH
instead of
.Dq Li MIRBSD KSH .
Note that the rest of the version string is identical between
the two shell flavours, and the behaviour and differences can
change between versions; see the accompanying manual page
.Xr mksh 1
for the versions this document applies to.
.It
.Nm
uses
.Tn POSIX
arithmetic, which has quite a few implications:
The data type for arithmetic operations is the host
.Tn ISO
C
.Vt long
data type.
Signed integer wraparound is Undefined Behaviour; this means that...
.Bd -literal -offset indent
$ echo $((2147483647 + 1))
.Ed
.Pp
\&... is permitted to, e.g. delete all files on your system
(the figure differs for non-32-bit systems, the rule doesn't).
The sign of the result of a modulo operation with at least one
negative operand is unspecified.
Shift operations on negative numbers are unspecified.
Division of the largest negative number by \-1 is Undefined Behaviour.
The compiler is permitted to delete all data and crash the system
if Undefined Behaviour occurs (see above for an example).
.It
The rotation arithmetic operators are not available.
.It
The shift arithmetic operators take all bits of the second operand into
account; if they exceed permitted precision, the result is unspecified.
.It
Unless
.Ic set -o posix
is active,
.Nm
always uses traditional mode for constructs like:
.Bd -literal -offset indent
$ set -- $(getopt ab:c "$@")
$ echo $?
.Ed
.Pp
POSIX mandates this to show 0, but traditional mode
passes through the errorlevel from the
.Xr getopt 1
command.
.It
Functions defined with the
.Ic function
reserved word share the shell options
.Pq Ic set -o
instead of locally scoping them.
.El
.Sh SEE ALSO
.Xr mksh 1
.Pp
.Pa http://www.mirbsd.org/mksh.htm
.Pp
.Pa http://www.mirbsd.org/ksh\-chan.htm
.Sh CAVEATS
To use
.Nm
as
.Pa /bin/sh ,
compilation to enable
.Ic set -o posix
by default if called as
.Nm sh
.Pq adding Dv \-DMKSH_BINSHPOSIX to Dv CPPFLAGS
is highly recommended for better standards compliance.
.Pp
For better compatibility with legacy scripts, such as many
.Tn Debian
maintainer scripts, Upstart and SYSV init scripts, and other
unfixed scripts, also adding the
.Dv \-DMKSH_BINSHREDUCED
compile-time option to enable
.Em both
.Ic set -o posix -o sh
when the shell is run as
.Nm sh ,
as well as integrating the optional disrecommended
.Xr printf 1
builtin, might be necessary.
.Pp
.Nm
tries to make a cross between a legacy bourne/posix compatibl-ish
shell and a legacy pdksh-alike but
.Dq legacy
is not exactly specified.
.Pp
Talk to the
.Mx
development team and users using the mailing list at
.Aq Mt miros\-mksh@mirbsd.org
(please note the EU-DSGVO/GDPR notice on
.Pa http://www.mirbsd.org/rss.htm#lists
and in the SMTP banner!) or the
.Li \&#\&!/bin/mksh
.Pq or Li \&#ksh
IRC channel at
.Pa irc.freenode.net
.Pq Port 6697 SSL, 6667 unencrypted
if you need any further quirks or assistance,
and consider migrating your legacy scripts to work with
.Nm mksh
instead of requiring
.Nm .
+2080
View File
File diff suppressed because it is too large Load Diff
+226
View File
@@ -0,0 +1,226 @@
/*-
* Copyright © 2011, 2014, 2015
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said persons immediate fault when using the work as intended.
*-
* This file provides BAFH (Better Avalanche for the Jenkins Hash) as
* inline macro bodies that operate on “register uint32_t” variables,
* with variants that use their local intermediate registers.
*
* Usage note for BAFH with entropy distribution: input up to 4 bytes
* is best combined into a 32-bit unsigned integer, which is then run
* through BAFHFinish_reg for mixing and then used as context instead
* of 0. Longer input should be handled the same: take the first four
* bytes as IV after mixing then add subsequent bytes the same way.
* This needs counting input bytes and is endian-dependent, thus not,
* for speed reasons, specified for the regular stable hash, but very
* much recommended if the actual output value may differ across runs
* (so is using a random value instead of 0 for the IV).
*-
* Little quote gem:
* We are looking into it. Changing the core
* hash function in PHP isn't a trivial change
* and will take us some time.
* -- Rasmus Lerdorf
*/
#ifndef SYSKERN_MIRHASH_H
#define SYSKERN_MIRHASH_H 1
#define SYSKERN_MIRHASH_BAFH
#include <sys/types.h>
__RCSID("$MirOS: src/bin/mksh/mirhash.h,v 1.6 2015/11/29 17:05:02 tg Exp $");
/*-
* BAFH itself is defined by the following primitives:
*
* • BAFHInit(ctx) initialises the hash context, which consists of a
* sole 32-bit unsigned integer (ideally in a register), to 0.
* It is possible to use any initial value out of [0; 2³²[ which
* is, in fact, recommended if using BAFH for entropy distribution
* but for a regular stable hash, the IV 0 is needed.
*
* • BAFHUpdateOctet(ctx,val) compresses the unsigned 8-bit quantity
* into the hash context. The algorithm used is Jenkins one-at-a-
* time, except that an additional constant 1 is added so that, if
* the context is (still) zero, adding a NUL byte is not ignored.
*
* • BAFHror(eax,cl) evaluates to the unsigned 32-bit integer “eax”,
* rotated right by “cl” ∈ [0; 31] (no casting, be careful!) where
* “eax” must be uint32_t and “cl” an in-range integer.
*
* • BAFHFinish(ctx) avalanches the context around so every sub-byte
* depends on all input octets; afterwards, the context variables
* value is the hash output. BAFH does not use any padding, nor is
* the input length added; this is due to the common use case (for
* quick entropy distribution and use with a hashtable).
* Warning: BAFHFinish uses the MixColumn algorithm of AES which
* is reversible (to avoid introducing funnels and reducing entro
* py), so blinding may need to be employed for some uses, e.g. in
* mksh, after a fork.
*
* The BAFHUpdateOctet and BAFHFinish are available in two flavours:
* suffixed with _reg (assumes the context is in a register) or _mem
* (which doesnt).
*
* The following high-level macros (with _reg and _mem variants) are
* available:
*
* • BAFHUpdateMem(ctx,buf,len) adds a memory block to a context.
* • BAFHUpdateStr(ctx,buf) is equivalent to using len=strlen(buf).
* • BAFHHostMem(ctx,buf,len) calculates the hash of the memory buf
* fer using the first 4 octets (mixed) for IV, as outlined above;
* the result is endian-dependent; “ctx” assumed to be a register.
* • BAFHHostStr(ctx,buf) does the same for C strings.
*
* All macros may use ctx multiple times in their expansion, but all
* other arguments are always evaluated at most once except BAFHror.
*
* To stay portable, never use the BAFHHost*() macros (these are for
* host-local entropy shuffling), and encode numbers using ULEB128.
*/
#define BAFHInit(h) do { \
(h) = 0; \
} while (/* CONSTCOND */ 0)
#define BAFHUpdateOctet_reg(h,b) do { \
(h) += (uint8_t)(b); \
++(h); \
(h) += (h) << 10; \
(h) ^= (h) >> 6; \
} while (/* CONSTCOND */ 0)
#define BAFHUpdateOctet_mem(m,b) do { \
register uint32_t BAFH_h = (m); \
\
BAFHUpdateOctet_reg(BAFH_h, (b)); \
(m) = BAFH_h; \
} while (/* CONSTCOND */ 0)
#define BAFHror(eax,cl) (((eax) >> (cl)) | ((eax) << (32 - (cl))))
#define BAFHFinish_reg(h) do { \
register uint32_t BAFHFinish_v; \
\
BAFHFinish_v = ((h) >> 7) & 0x01010101U; \
BAFHFinish_v += BAFHFinish_v << 1; \
BAFHFinish_v += BAFHFinish_v << 3; \
BAFHFinish_v ^= ((h) << 1) & 0xFEFEFEFEU; \
\
BAFHFinish_v ^= BAFHror(BAFHFinish_v, 8); \
BAFHFinish_v ^= ((h) = BAFHror((h), 8)); \
BAFHFinish_v ^= ((h) = BAFHror((h), 8)); \
(h) = BAFHror((h), 8) ^ BAFHFinish_v; \
} while (/* CONSTCOND */ 0)
#define BAFHFinish_mem(m) do { \
register uint32_t BAFHFinish_v, BAFH_h = (m); \
\
BAFHFinish_v = (BAFH_h >> 7) & 0x01010101U; \
BAFHFinish_v += BAFHFinish_v << 1; \
BAFHFinish_v += BAFHFinish_v << 3; \
BAFHFinish_v ^= (BAFH_h << 1) & 0xFEFEFEFEU; \
\
BAFHFinish_v ^= BAFHror(BAFHFinish_v, 8); \
BAFHFinish_v ^= (BAFH_h = BAFHror(BAFH_h, 8)); \
BAFHFinish_v ^= (BAFH_h = BAFHror(BAFH_h, 8)); \
(m) = BAFHror(BAFH_h, 8) ^ BAFHFinish_v; \
} while (/* CONSTCOND */ 0)
#define BAFHUpdateMem_reg(h,p,z) do { \
register const uint8_t *BAFHUpdate_p; \
register size_t BAFHUpdate_z = (z); \
\
BAFHUpdate_p = (const void *)(p); \
while (BAFHUpdate_z--) \
BAFHUpdateOctet_reg((h), *BAFHUpdate_p++); \
} while (/* CONSTCOND */ 0)
/* meh should have named them _r/m but thats not valid C */
#define BAFHUpdateMem_mem(m,p,z) do { \
register uint32_t BAFH_h = (m); \
\
BAFHUpdateMem_reg(BAFH_h, (p), (z)); \
(m) = BAFH_h; \
} while (/* CONSTCOND */ 0)
#define BAFHUpdateStr_reg(h,s) do { \
register const uint8_t *BAFHUpdate_s; \
register uint8_t BAFHUpdate_c; \
\
BAFHUpdate_s = (const void *)(s); \
while ((BAFHUpdate_c = *BAFHUpdate_s++) != 0) \
BAFHUpdateOctet_reg((h), BAFHUpdate_c); \
} while (/* CONSTCOND */ 0)
#define BAFHUpdateStr_mem(m,s) do { \
register uint32_t BAFH_h = (m); \
\
BAFHUpdateStr_reg(BAFH_h, (s)); \
(m) = BAFH_h; \
} while (/* CONSTCOND */ 0)
#define BAFHHostMem(h,p,z) do { \
register const uint8_t *BAFHUpdate_p; \
register size_t BAFHUpdate_z = (z); \
size_t BAFHHost_z; \
union { \
uint8_t as_u8[4]; \
uint32_t as_u32; \
} BAFHHost_v; \
\
BAFHUpdate_p = (const void *)(p); \
BAFHHost_v.as_u32 = 0; \
BAFHHost_z = BAFHUpdate_z < 4 ? BAFHUpdate_z : 4; \
memcpy(BAFHHost_v.as_u8, BAFHUpdate_p, BAFHHost_z); \
BAFHUpdate_p += BAFHHost_z; \
BAFHUpdate_z -= BAFHHost_z; \
(h) = BAFHHost_v.as_u32; \
BAFHFinish_reg(h); \
while (BAFHUpdate_z--) \
BAFHUpdateOctet_reg((h), *BAFHUpdate_p++); \
BAFHFinish_reg(h); \
} while (/* CONSTCOND */ 0)
#define BAFHHostStr(h,s) do { \
register const uint8_t *BAFHUpdate_s; \
register uint8_t BAFHUpdate_c; \
union { \
uint8_t as_u8[4]; \
uint32_t as_u32; \
} BAFHHost_v; \
\
BAFHUpdate_s = (const void *)(s); \
BAFHHost_v.as_u32 = 0; \
if ((BAFHHost_v.as_u8[0] = *BAFHUpdate_s) != 0) \
++BAFHUpdate_s; \
if ((BAFHHost_v.as_u8[1] = *BAFHUpdate_s) != 0) \
++BAFHUpdate_s; \
if ((BAFHHost_v.as_u8[2] = *BAFHUpdate_s) != 0) \
++BAFHUpdate_s; \
if ((BAFHHost_v.as_u8[3] = *BAFHUpdate_s) != 0) \
++BAFHUpdate_s; \
(h) = BAFHHost_v.as_u32; \
BAFHFinish_reg(h); \
while ((BAFHUpdate_c = *BAFHUpdate_s++) != 0) \
BAFHUpdateOctet_reg((h), BAFHUpdate_c); \
BAFHFinish_reg(h); \
} while (/* CONSTCOND */ 0)
#endif
+2583
View File
File diff suppressed because it is too large Load Diff
+6970
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+575
View File
@@ -0,0 +1,575 @@
/*-
* Copyright (c) 2015, 2017
* KO Myung-Hun <komh@chollian.net>
* Copyright (c) 2017
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#define INCL_DOS
#include <os2.h>
#include "sh.h"
#include <klibc/startup.h>
#include <errno.h>
#include <io.h>
#include <unistd.h>
#include <process.h>
__RCSID("$MirOS: src/bin/mksh/os2.c,v 1.8 2017/12/22 16:41:42 tg Exp $");
static char *remove_trailing_dots(char *);
static int access_stat_ex(int (*)(), const char *, void *);
static int test_exec_exist(const char *, char *);
static void response(int *, const char ***);
static char *make_response_file(char * const *);
static void add_temp(const char *);
static void cleanup_temps(void);
static void cleanup(void);
#define RPUT(x) do { \
if (new_argc >= new_alloc) { \
new_alloc += 20; \
if (!(new_argv = realloc(new_argv, \
new_alloc * sizeof(char *)))) \
goto exit_out_of_memory; \
} \
new_argv[new_argc++] = (x); \
} while (/* CONSTCOND */ 0)
#define KLIBC_ARG_RESPONSE_EXCLUDE \
(__KLIBC_ARG_DQUOTE | __KLIBC_ARG_WILDCARD | __KLIBC_ARG_SHELL)
static void
response(int *argcp, const char ***argvp)
{
int i, old_argc, new_argc, new_alloc = 0;
const char **old_argv, **new_argv;
char *line, *l, *p;
FILE *f;
old_argc = *argcp;
old_argv = *argvp;
for (i = 1; i < old_argc; ++i)
if (old_argv[i] &&
!(old_argv[i][-1] & KLIBC_ARG_RESPONSE_EXCLUDE) &&
old_argv[i][0] == '@')
break;
if (i >= old_argc)
/* do nothing */
return;
new_argv = NULL;
new_argc = 0;
for (i = 0; i < old_argc; ++i) {
if (i == 0 || !old_argv[i] ||
(old_argv[i][-1] & KLIBC_ARG_RESPONSE_EXCLUDE) ||
old_argv[i][0] != '@' ||
!(f = fopen(old_argv[i] + 1, "rt")))
RPUT(old_argv[i]);
else {
long filesize;
fseek(f, 0, SEEK_END);
filesize = ftell(f);
fseek(f, 0, SEEK_SET);
line = malloc(filesize + /* type */ 1 + /* NUL */ 1);
if (!line) {
exit_out_of_memory:
fputs("Out of memory while reading response file\n", stderr);
exit(255);
}
line[0] = __KLIBC_ARG_NONZERO | __KLIBC_ARG_RESPONSE;
l = line + 1;
while (fgets(l, (filesize + 1) - (l - (line + 1)), f)) {
p = strchr(l, '\n');
if (p) {
/*
* if a line ends with a backslash,
* concatenate with the next line
*/
if (p > l && p[-1] == '\\') {
char *p1;
int count = 0;
for (p1 = p - 1; p1 >= l &&
*p1 == '\\'; p1--)
count++;
if (count & 1) {
l = p + 1;
continue;
}
}
*p = 0;
}
p = strdup(line);
if (!p)
goto exit_out_of_memory;
RPUT(p + 1);
l = line + 1;
}
free(line);
if (ferror(f)) {
fputs("Cannot read response file\n", stderr);
exit(255);
}
fclose(f);
}
}
RPUT(NULL);
--new_argc;
*argcp = new_argc;
*argvp = new_argv;
}
static void
init_extlibpath(void)
{
const char *vars[] = {
"BEGINLIBPATH",
"ENDLIBPATH",
"LIBPATHSTRICT",
NULL
};
char val[512];
int flag;
for (flag = 0; vars[flag]; flag++) {
DosQueryExtLIBPATH(val, flag + 1);
if (val[0])
setenv(vars[flag], val, 1);
}
}
void
os2_init(int *argcp, const char ***argvp)
{
response(argcp, argvp);
init_extlibpath();
if (!isatty(STDIN_FILENO))
setmode(STDIN_FILENO, O_BINARY);
if (!isatty(STDOUT_FILENO))
setmode(STDOUT_FILENO, O_BINARY);
if (!isatty(STDERR_FILENO))
setmode(STDERR_FILENO, O_BINARY);
atexit(cleanup);
}
void
setextlibpath(const char *name, const char *val)
{
int flag;
char *p, *cp;
if (!strcmp(name, "BEGINLIBPATH"))
flag = BEGIN_LIBPATH;
else if (!strcmp(name, "ENDLIBPATH"))
flag = END_LIBPATH;
else if (!strcmp(name, "LIBPATHSTRICT"))
flag = LIBPATHSTRICT;
else
return;
/* convert slashes to backslashes */
strdupx(cp, val, ATEMP);
for (p = cp; *p; p++) {
if (*p == '/')
*p = '\\';
}
DosSetExtLIBPATH(cp, flag);
afree(cp, ATEMP);
}
/* remove trailing dots */
static char *
remove_trailing_dots(char *name)
{
char *p = strnul(name);
while (--p > name && *p == '.')
/* nothing */;
if (*p != '.' && *p != '/' && *p != '\\' && *p != ':')
p[1] = '\0';
return (name);
}
#define REMOVE_TRAILING_DOTS(name) \
remove_trailing_dots(memcpy(alloca(strlen(name) + 1), name, strlen(name) + 1))
/* alias of stat() */
extern int _std_stat(const char *, struct stat *);
/* replacement for stat() of kLIBC which fails if there are trailing dots */
int
stat(const char *name, struct stat *buffer)
{
return (_std_stat(REMOVE_TRAILING_DOTS(name), buffer));
}
/* alias of access() */
extern int _std_access(const char *, int);
/* replacement for access() of kLIBC which fails if there are trailing dots */
int
access(const char *name, int mode)
{
/*
* On OS/2 kLIBC, X_OK is set only for executable files.
* This prevents scripts from being executed.
*/
if (mode & X_OK)
mode = (mode & ~X_OK) | R_OK;
return (_std_access(REMOVE_TRAILING_DOTS(name), mode));
}
#define MAX_X_SUFFIX_LEN 4
static const char *x_suffix_list[] =
{ "", ".ksh", ".exe", ".sh", ".cmd", ".com", ".bat", NULL };
/* call fn() by appending executable extensions */
static int
access_stat_ex(int (*fn)(), const char *name, void *arg)
{
char *x_name;
const char **x_suffix;
int rc = -1;
size_t x_namelen = strlen(name) + MAX_X_SUFFIX_LEN + 1;
/* otherwise, try to append executable suffixes */
x_name = alloc(x_namelen, ATEMP);
for (x_suffix = x_suffix_list; rc && *x_suffix; x_suffix++) {
strlcpy(x_name, name, x_namelen);
strlcat(x_name, *x_suffix, x_namelen);
rc = fn(x_name, arg);
}
afree(x_name, ATEMP);
return (rc);
}
/* access()/search_access() version */
int
access_ex(int (*fn)(const char *, int), const char *name, int mode)
{
/*XXX this smells fishy --mirabilos */
return (access_stat_ex(fn, name, (void *)mode));
}
/* stat() version */
int
stat_ex(const char *name, struct stat *buffer)
{
return (access_stat_ex(stat, name, buffer));
}
static int
test_exec_exist(const char *name, char *real_name)
{
struct stat sb;
if (stat(name, &sb) < 0 || !S_ISREG(sb.st_mode))
return (-1);
/* safe due to calculations in real_exec_name() */
memcpy(real_name, name, strlen(name) + 1);
return (0);
}
const char *
real_exec_name(const char *name)
{
char x_name[strlen(name) + MAX_X_SUFFIX_LEN + 1];
const char *real_name = name;
if (access_stat_ex(test_exec_exist, real_name, x_name) != -1)
/*XXX memory leak */
strdupx(real_name, x_name, ATEMP);
return (real_name);
}
/* make a response file to pass a very long command line */
static char *
make_response_file(char * const *argv)
{
char rsp_name_arg[] = "@mksh-rsp-XXXXXX";
char *rsp_name = &rsp_name_arg[1];
int i;
int fd;
char *result;
if ((fd = mkstemp(rsp_name)) == -1)
return (NULL);
/* write all the arguments except a 0th program name */
for (i = 1; argv[i]; i++) {
write(fd, argv[i], strlen(argv[i]));
write(fd, "\n", 1);
}
close(fd);
add_temp(rsp_name);
strdupx(result, rsp_name_arg, ATEMP);
return (result);
}
/* alias of execve() */
extern int _std_execve(const char *, char * const *, char * const *);
/* replacement for execve() of kLIBC */
int
execve(const char *name, char * const *argv, char * const *envp)
{
const char *exec_name;
FILE *fp;
char sign[2];
int pid;
int status;
int fd;
int rc;
int saved_mode;
int saved_errno;
/*
* #! /bin/sh : append .exe
* extproc sh : search sh.exe in PATH
*/
exec_name = search_path(name, path, X_OK, NULL);
if (!exec_name) {
errno = ENOENT;
return (-1);
}
/*-
* kLIBC execve() has problems when executing scripts.
* 1. it fails to execute a script if a directory whose name
* is same as an interpreter exists in a current directory.
* 2. it fails to execute a script not starting with sharpbang.
* 3. it fails to execute a batch file if COMSPEC is set to a shell
* incompatible with cmd.exe, such as /bin/sh.
* And ksh process scripts more well, so let ksh process scripts.
*/
errno = 0;
if (!(fp = fopen(exec_name, "rb")))
errno = ENOEXEC;
if (!errno && fread(sign, 1, sizeof(sign), fp) != sizeof(sign))
errno = ENOEXEC;
if (fp && fclose(fp))
errno = ENOEXEC;
if (!errno &&
!((sign[0] == 'M' && sign[1] == 'Z') ||
(sign[0] == 'N' && sign[1] == 'E') ||
(sign[0] == 'L' && sign[1] == 'X')))
errno = ENOEXEC;
if (errno == ENOEXEC)
return (-1);
/*
* Normal OS/2 programs expect that standard IOs, especially stdin,
* are opened in text mode at the startup. By the way, on OS/2 kLIBC
* child processes inherit a translation mode of a parent process.
* As a result, if stdin is set to binary mode in a parent process,
* stdin of child processes is opened in binary mode as well at the
* startup. In this case, some programs such as sed suffer from CR.
*/
saved_mode = setmode(STDIN_FILENO, O_TEXT);
pid = spawnve(P_NOWAIT, exec_name, argv, envp);
saved_errno = errno;
/* arguments too long? */
if (pid == -1 && saved_errno == EINVAL) {
/* retry with a response file */
char *rsp_name_arg = make_response_file(argv);
if (rsp_name_arg) {
char *rsp_argv[3] = { argv[0], rsp_name_arg, NULL };
pid = spawnve(P_NOWAIT, exec_name, rsp_argv, envp);
saved_errno = errno;
afree(rsp_name_arg, ATEMP);
}
}
/* restore translation mode of stdin */
setmode(STDIN_FILENO, saved_mode);
if (pid == -1) {
cleanup_temps();
errno = saved_errno;
return (-1);
}
/* close all opened handles */
for (fd = 0; fd < NUFILE; fd++) {
if (fcntl(fd, F_GETFD) == -1)
continue;
close(fd);
}
while ((rc = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
/* nothing */;
cleanup_temps();
/* Is this possible? And is this right? */
if (rc == -1)
return (-1);
if (WIFSIGNALED(status))
_exit(ksh_sigmask(WTERMSIG(status)));
_exit(WEXITSTATUS(status));
}
static struct temp *templist = NULL;
static void
add_temp(const char *name)
{
struct temp *tp;
tp = alloc(offsetof(struct temp, tffn[0]) + strlen(name) + 1, APERM);
memcpy(tp->tffn, name, strlen(name) + 1);
tp->next = templist;
templist = tp;
}
/* alias of unlink() */
extern int _std_unlink(const char *);
/*
* Replacement for unlink() of kLIBC not supporting to remove files used by
* another processes.
*/
int
unlink(const char *name)
{
int rc;
rc = _std_unlink(name);
if (rc == -1 && errno != ENOENT)
add_temp(name);
return (rc);
}
static void
cleanup_temps(void)
{
struct temp *tp;
struct temp **tpnext;
for (tpnext = &templist, tp = templist; tp; tp = *tpnext) {
if (_std_unlink(tp->tffn) == 0 || errno == ENOENT) {
*tpnext = tp->next;
afree(tp, APERM);
} else {
tpnext = &tp->next;
}
}
}
static void
cleanup(void)
{
cleanup_temps();
}
int
getdrvwd(char **cpp, unsigned int drvltr)
{
PBYTE cp;
ULONG sz;
APIRET rc;
ULONG drvno;
if (DosQuerySysInfo(QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH,
&sz, sizeof(sz)) != 0) {
errno = EDOOFUS;
return (-1);
}
/* allocate 'X:/' plus sz plus NUL */
checkoktoadd((size_t)sz, (size_t)4);
cp = aresize(*cpp, (size_t)sz + (size_t)4, ATEMP);
cp[0] = ksh_toupper(drvltr);
cp[1] = ':';
cp[2] = '/';
drvno = ksh_numuc(cp[0]) + 1;
/* NUL is part of space within buffer passed */
++sz;
if ((rc = DosQueryCurrentDir(drvno, cp + 3, &sz)) == 0) {
/* success! */
*cpp = cp;
return (0);
}
afree(cp, ATEMP);
*cpp = NULL;
switch (rc) {
case 15: /* invalid drive */
errno = ENOTBLK;
break;
case 26: /* not dos disk */
errno = ENODEV;
break;
case 108: /* drive locked */
errno = EDEADLK;
break;
case 111: /* buffer overflow */
errno = ENAMETOOLONG;
break;
default:
errno = EINVAL;
}
return (-1);
}
+184
View File
@@ -0,0 +1,184 @@
/* +++ GENERATED FILE +++ DO NOT EDIT +++ */
/*-
* Copyright (c) 2013, 2015
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#ifndef RLIMITS_OPTCS
#if defined(RLIMITS_DEFNS)
__RCSID("$MirOS: src/bin/mksh/rlimits.opt,v 1.3 2015/12/12 21:08:44 tg Exp $");
#elif defined(RLIMITS_ITEMS)
#define FN(lname,lid,lfac,lopt) (const struct limits *)(&rlimits_ ## lid),
#endif
#ifndef F0
#define F0 FN
#endif
#ifdef RLIMIT_CPU
FN("time(cpu-seconds)", RLIMIT_CPU, 1, 't')
#endif
#ifdef RLIMIT_FSIZE
FN("file(blocks)", RLIMIT_FSIZE, 512, 'f')
#endif
#ifdef RLIMIT_CORE
FN("coredump(blocks)", RLIMIT_CORE, 512, 'c')
#endif
#ifdef RLIMIT_DATA
FN("data(KiB)", RLIMIT_DATA, 1024, 'd')
#endif
#ifdef RLIMIT_STACK
FN("stack(KiB)", RLIMIT_STACK, 1024, 's')
#endif
#ifdef RLIMIT_MEMLOCK
FN("lockedmem(KiB)", RLIMIT_MEMLOCK, 1024, 'l')
#endif
#ifdef RLIMIT_NOFILE
FN("nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n')
#endif
#ifdef RLIMIT_NPROC
FN("processes", RLIMIT_NPROC, 1, 'p')
#endif
#ifdef RLIMIT_SWAP
FN("swap(KiB)", RLIMIT_SWAP, 1024, 'w')
#endif
#ifdef RLIMIT_TIME
FN("humantime(seconds)", RLIMIT_TIME, 1, 'T')
#endif
#ifdef RLIMIT_NOVMON
FN("vnodemonitors", RLIMIT_NOVMON, 1, 'V')
#endif
#ifdef RLIMIT_SIGPENDING
FN("sigpending", RLIMIT_SIGPENDING, 1, 'i')
#endif
#ifdef RLIMIT_MSGQUEUE
FN("msgqueue(bytes)", RLIMIT_MSGQUEUE, 1, 'q')
#endif
#ifdef RLIMIT_AIO_MEM
FN("AIOlockedmem(KiB)", RLIMIT_AIO_MEM, 1024, 'M')
#endif
#ifdef RLIMIT_AIO_OPS
FN("AIOoperations", RLIMIT_AIO_OPS, 1, 'O')
#endif
#ifdef RLIMIT_TCACHE
FN("cachedthreads", RLIMIT_TCACHE, 1, 'C')
#endif
#ifdef RLIMIT_SBSIZE
FN("sockbufsiz(KiB)", RLIMIT_SBSIZE, 1024, 'B')
#endif
#ifdef RLIMIT_PTHREAD
FN("threadsperprocess", RLIMIT_PTHREAD, 1, 'P')
#endif
#ifdef RLIMIT_NICE
FN("maxnice", RLIMIT_NICE, 1, 'e')
#endif
#ifdef RLIMIT_RTPRIO
FN("maxrtprio", RLIMIT_RTPRIO, 1, 'r')
#endif
#ifdef ULIMIT_M_IS_RSS
FN("resident-set(KiB)", RLIMIT_RSS, 1024, 'm')
#endif
#ifdef ULIMIT_M_IS_VMEM
FN("memory(KiB)", RLIMIT_VMEM, 1024, 'm')
#endif
#ifdef ULIMIT_V_IS_VMEM
FN("virtual-memory(KiB)", RLIMIT_VMEM, 1024, 'v')
#endif
#ifdef ULIMIT_V_IS_AS
FN("address-space(KiB)", RLIMIT_AS, 1024, 'v')
#endif
#undef F0
#undef FN
#undef RLIMITS_DEFNS
#undef RLIMITS_ITEMS
#else
"a"
#ifdef RLIMIT_SBSIZE
"B"
#endif
#ifdef RLIMIT_TCACHE
"C"
#endif
#ifdef RLIMIT_CORE
"c"
#endif
#ifdef RLIMIT_DATA
"d"
#endif
#ifdef RLIMIT_NICE
"e"
#endif
#ifdef RLIMIT_FSIZE
"f"
#endif
"H"
#ifdef RLIMIT_SIGPENDING
"i"
#endif
#ifdef RLIMIT_MEMLOCK
"l"
#endif
#ifdef RLIMIT_AIO_MEM
"M"
#endif
#ifdef ULIMIT_M_IS_RSS
"m"
#endif
#ifdef ULIMIT_M_IS_VMEM
"m"
#endif
#ifdef RLIMIT_NOFILE
"n"
#endif
#ifdef RLIMIT_AIO_OPS
"O"
#endif
#ifdef RLIMIT_PTHREAD
"P"
#endif
#ifdef RLIMIT_NPROC
"p"
#endif
#ifdef RLIMIT_MSGQUEUE
"q"
#endif
#ifdef RLIMIT_RTPRIO
"r"
#endif
"S"
#ifdef RLIMIT_STACK
"s"
#endif
#ifdef RLIMIT_TIME
"T"
#endif
#ifdef RLIMIT_CPU
"t"
#endif
#ifdef RLIMIT_NOVMON
"V"
#endif
#ifdef ULIMIT_V_IS_AS
"v"
#endif
#ifdef ULIMIT_V_IS_VMEM
"v"
#endif
#ifdef RLIMIT_SWAP
"w"
#endif
#undef RLIMITS_OPTCS
#endif
+105
View File
@@ -0,0 +1,105 @@
/*-
* Copyright (c) 2013, 2015
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
@RLIMITS_DEFNS
__RCSID("$MirOS: src/bin/mksh/rlimits.opt,v 1.3 2015/12/12 21:08:44 tg Exp $");
@RLIMITS_ITEMS
#define FN(lname,lid,lfac,lopt) (const struct limits *)(&rlimits_ ## lid),
@@
/* generic options for the ulimit builtin */
<a|
<H|
<S|
/* do not use options -H, -S or -a or change the order */
>t|RLIMIT_CPU
FN("time(cpu-seconds)", RLIMIT_CPU, 1
>f|RLIMIT_FSIZE
FN("file(blocks)", RLIMIT_FSIZE, 512
>c|RLIMIT_CORE
FN("coredump(blocks)", RLIMIT_CORE, 512
>d|RLIMIT_DATA
FN("data(KiB)", RLIMIT_DATA, 1024
>s|RLIMIT_STACK
FN("stack(KiB)", RLIMIT_STACK, 1024
>l|RLIMIT_MEMLOCK
FN("lockedmem(KiB)", RLIMIT_MEMLOCK, 1024
>n|RLIMIT_NOFILE
FN("nofiles(descriptors)", RLIMIT_NOFILE, 1
>p|RLIMIT_NPROC
FN("processes", RLIMIT_NPROC, 1
>w|RLIMIT_SWAP
FN("swap(KiB)", RLIMIT_SWAP, 1024
>T|RLIMIT_TIME
FN("humantime(seconds)", RLIMIT_TIME, 1
>V|RLIMIT_NOVMON
FN("vnodemonitors", RLIMIT_NOVMON, 1
>i|RLIMIT_SIGPENDING
FN("sigpending", RLIMIT_SIGPENDING, 1
>q|RLIMIT_MSGQUEUE
FN("msgqueue(bytes)", RLIMIT_MSGQUEUE, 1
>M|RLIMIT_AIO_MEM
FN("AIOlockedmem(KiB)", RLIMIT_AIO_MEM, 1024
>O|RLIMIT_AIO_OPS
FN("AIOoperations", RLIMIT_AIO_OPS, 1
>C|RLIMIT_TCACHE
FN("cachedthreads", RLIMIT_TCACHE, 1
>B|RLIMIT_SBSIZE
FN("sockbufsiz(KiB)", RLIMIT_SBSIZE, 1024
>P|RLIMIT_PTHREAD
FN("threadsperprocess", RLIMIT_PTHREAD, 1
>e|RLIMIT_NICE
FN("maxnice", RLIMIT_NICE, 1
>r|RLIMIT_RTPRIO
FN("maxrtprio", RLIMIT_RTPRIO, 1
>m|ULIMIT_M_IS_RSS
FN("resident-set(KiB)", RLIMIT_RSS, 1024
>m|ULIMIT_M_IS_VMEM
FN("memory(KiB)", RLIMIT_VMEM, 1024
>v|ULIMIT_V_IS_VMEM
FN("virtual-memory(KiB)", RLIMIT_VMEM, 1024
>v|ULIMIT_V_IS_AS
FN("address-space(KiB)", RLIMIT_AS, 1024
|RLIMITS_OPTCS
+2801
View File
File diff suppressed because it is too large Load Diff
+156
View File
@@ -0,0 +1,156 @@
/* +++ GENERATED FILE +++ DO NOT EDIT +++ */
/*-
* Copyright (c) 2013, 2014, 2015, 2017
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#ifndef SHFLAGS_OPTCS
#if defined(SHFLAGS_DEFNS)
__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.6 2018/08/10 02:53:39 tg Exp $");
#elif defined(SHFLAGS_ENUMS)
#define FN(sname,cname,flags,ochar) cname,
#define F0(sname,cname,flags,ochar) cname = 0,
#elif defined(SHFLAGS_ITEMS)
#define FN(sname,cname,flags,ochar) ((const char *)(&shoptione_ ## cname)) + 2,
#endif
#ifndef F0
#define F0 FN
#endif
F0("allexport", FEXPORT, OF_ANY, 'a')
#if HAVE_NICE
FN("bgnice", FBGNICE, OF_ANY, 0)
#endif
FN("braceexpand", FBRACEEXPAND, OF_ANY, 0)
#ifndef MKSH_NO_CMDLINE_EDITING
FN("emacs", FEMACS, OF_ANY, 0)
#endif
FN("errexit", FERREXIT, OF_ANY, 'e')
#ifndef MKSH_NO_CMDLINE_EDITING
FN("gmacs", FGMACS, OF_ANY, 0)
#endif
FN("ignoreeof", FIGNOREEOF, OF_ANY, 0)
FN("inherit-xtrace", FXTRACEREC, OF_ANY, 0)
#ifndef SHFLAGS_NOT_CMD
FN("interactive", FTALKING, OF_CMDLINE, 'i')
#endif
FN("keyword", FKEYWORD, OF_ANY, 'k')
#ifndef SHFLAGS_NOT_CMD
FN("login", FLOGIN, OF_CMDLINE, 'l')
#endif
FN("markdirs", FMARKDIRS, OF_ANY, 'X')
#ifndef MKSH_UNEMPLOYED
FN("monitor", FMONITOR, OF_ANY, 'm')
#endif
FN("noclobber", FNOCLOBBER, OF_ANY, 'C')
FN("noexec", FNOEXEC, OF_ANY, 'n')
FN("noglob", FNOGLOB, OF_ANY, 'f')
FN("nohup", FNOHUP, OF_ANY, 0)
FN("nolog", FNOLOG, OF_ANY, 0)
#ifndef MKSH_UNEMPLOYED
FN("notify", FNOTIFY, OF_ANY, 'b')
#endif
FN("nounset", FNOUNSET, OF_ANY, 'u')
FN("physical", FPHYSICAL, OF_ANY, 0)
FN("pipefail", FPIPEFAIL, OF_ANY, 0)
FN("posix", FPOSIX, OF_ANY, 0)
FN("privileged", FPRIVILEGED, OF_ANY, 'p')
#ifndef SHFLAGS_NOT_CMD
FN("restricted", FRESTRICTED, OF_CMDLINE, 'r')
#endif
FN("sh", FSH, OF_ANY, 0)
#ifndef SHFLAGS_NOT_CMD
FN("stdin", FSTDIN, OF_CMDLINE, 's')
#endif
FN("trackall", FTRACKALL, OF_ANY, 'h')
FN("utf8-mode", FUNNYCODE, OF_ANY, 'U')
FN("verbose", FVERBOSE, OF_ANY, 'v')
#ifndef MKSH_NO_CMDLINE_EDITING
FN("vi", FVI, OF_ANY, 0)
#endif
#ifndef MKSH_NO_CMDLINE_EDITING
FN("vi-esccomplete", FVIESCCOMPLETE, OF_ANY, 0)
#endif
#ifndef MKSH_NO_CMDLINE_EDITING
FN("vi-tabcomplete", FVITABCOMPLETE, OF_ANY, 0)
#endif
#ifndef MKSH_NO_CMDLINE_EDITING
FN("viraw", FVIRAW, OF_ANY, 0)
#endif
FN("xtrace", FXTRACE, OF_ANY, 'x')
#ifndef SHFLAGS_NOT_CMD
FN("", FCOMMAND, OF_CMDLINE, 'c')
#endif
FN("", FAS_BUILTIN, OF_INTERNAL, 0)
FN("", FTALKING_I, OF_INTERNAL, 0)
#undef F0
#undef FN
#undef SHFLAGS_DEFNS
#undef SHFLAGS_ENUMS
#undef SHFLAGS_ITEMS
#else
#ifndef SHFLAGS_NOT_SET
"A:"
#endif
"a"
#ifndef MKSH_UNEMPLOYED
"b"
#endif
"C"
#ifndef SHFLAGS_NOT_CMD
"c"
#endif
"e"
"f"
"h"
#ifndef SHFLAGS_NOT_CMD
"i"
#endif
"k"
#ifndef SHFLAGS_NOT_CMD
"l"
#endif
#ifndef MKSH_UNEMPLOYED
"m"
#endif
"n"
#ifndef SHFLAGS_NOT_CMD
"o:"
#endif
#ifndef SHFLAGS_NOT_SET
"o;"
#endif
"p"
#ifndef SHFLAGS_NOT_CMD
"r"
#endif
#ifndef SHFLAGS_NOT_CMD
"s"
#endif
#ifndef SHFLAGS_NOT_SET
"s"
#endif
#ifndef SHFLAGS_NOT_CMD
"T:"
#endif
"U"
"u"
"v"
"X"
"x"
#undef SHFLAGS_OPTCS
#endif
+198
View File
@@ -0,0 +1,198 @@
/*-
* Copyright (c) 2013, 2014, 2015, 2017
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
@SHFLAGS_DEFNS
__RCSID("$MirOS: src/bin/mksh/sh_flags.opt,v 1.6 2018/08/10 02:53:39 tg Exp $");
@SHFLAGS_ENUMS
#define FN(sname,cname,flags,ochar) cname,
#define F0(sname,cname,flags,ochar) cname = 0,
@SHFLAGS_ITEMS
#define FN(sname,cname,flags,ochar) ((const char *)(&shoptione_ ## cname)) + 2,
@@
/* special cases */
<o:|!SHFLAGS_NOT_CMD
<T:|!SHFLAGS_NOT_CMD
<A:|!SHFLAGS_NOT_SET
<o;|!SHFLAGS_NOT_SET
<s|!SHFLAGS_NOT_SET
/*
* options are sorted by their longnames
*/
/* -a all new parameters are created with the export attribute */
>a|
F0("allexport", FEXPORT, OF_ANY
/* ./. bgnice */
>| HAVE_NICE
FN("bgnice", FBGNICE, OF_ANY
/* ./. enable {} globbing (non-standard) */
>|
FN("braceexpand", FBRACEEXPAND, OF_ANY
/* ./. Emacs command line editing mode */
>|!MKSH_NO_CMDLINE_EDITING
FN("emacs", FEMACS, OF_ANY
/* -e quit on error */
>e|
FN("errexit", FERREXIT, OF_ANY
/* ./. Emacs command line editing mode, gmacs variant */
>|!MKSH_NO_CMDLINE_EDITING
FN("gmacs", FGMACS, OF_ANY
/* ./. reading EOF does not exit */
>|
FN("ignoreeof", FIGNOREEOF, OF_ANY
/* ./. inherit -x flag */
>|
FN("inherit-xtrace", FXTRACEREC, OF_ANY
/* -i interactive shell */
>i|!SHFLAGS_NOT_CMD
FN("interactive", FTALKING, OF_CMDLINE
/* -k name=value are recognised anywhere */
>k|
FN("keyword", FKEYWORD, OF_ANY
/* -l login shell */
>l|!SHFLAGS_NOT_CMD
FN("login", FLOGIN, OF_CMDLINE
/* -X mark dirs with / in file name completion */
>X|
FN("markdirs", FMARKDIRS, OF_ANY
/* -m job control monitoring */
>m|!MKSH_UNEMPLOYED
FN("monitor", FMONITOR, OF_ANY
/* -C don't overwrite existing files */
>C|
FN("noclobber", FNOCLOBBER, OF_ANY
/* -n don't execute any commands */
>n|
FN("noexec", FNOEXEC, OF_ANY
/* -f don't do file globbing */
>f|
FN("noglob", FNOGLOB, OF_ANY
/* ./. don't kill running jobs when login shell exits */
>|
FN("nohup", FNOHUP, OF_ANY
/* ./. don't save functions in history (no effect) */
>|
FN("nolog", FNOLOG, OF_ANY
/* -b asynchronous job completion notification */
>b|!MKSH_UNEMPLOYED
FN("notify", FNOTIFY, OF_ANY
/* -u using an unset variable is an error */
>u|
FN("nounset", FNOUNSET, OF_ANY
/* ./. don't do logical cds/pwds (non-standard) */
>|
FN("physical", FPHYSICAL, OF_ANY
/* ./. errorlevel of a pipeline is the rightmost nonzero value */
>|
FN("pipefail", FPIPEFAIL, OF_ANY
/* ./. adhere more closely to POSIX even when undesirable */
>|
FN("posix", FPOSIX, OF_ANY
/* -p privileged shell (suid) */
>p|
FN("privileged", FPRIVILEGED, OF_ANY
/* -r restricted shell */
>r|!SHFLAGS_NOT_CMD
FN("restricted", FRESTRICTED, OF_CMDLINE
/* ./. kludge mode for better compat with traditional sh (OS-specific) */
>|
FN("sh", FSH, OF_ANY
/* -s (invocation) parse stdin (pseudo non-standard) */
>s|!SHFLAGS_NOT_CMD
FN("stdin", FSTDIN, OF_CMDLINE
/* -h create tracked aliases for all commands */
>h|
FN("trackall", FTRACKALL, OF_ANY
/* -U enable UTF-8 processing (non-standard) */
>U|
FN("utf8-mode", FUNNYCODE, OF_ANY
/* -v echo input */
>v|
FN("verbose", FVERBOSE, OF_ANY
/* ./. Vi command line editing mode */
>|!MKSH_NO_CMDLINE_EDITING
FN("vi", FVI, OF_ANY
/* ./. enable ESC as file name completion character (non-standard) */
>|!MKSH_NO_CMDLINE_EDITING
FN("vi-esccomplete", FVIESCCOMPLETE, OF_ANY
/* ./. enable Tab as file name completion character (non-standard) */
>|!MKSH_NO_CMDLINE_EDITING
FN("vi-tabcomplete", FVITABCOMPLETE, OF_ANY
/* ./. always read in raw mode (no effect) */
>|!MKSH_NO_CMDLINE_EDITING
FN("viraw", FVIRAW, OF_ANY
/* -x execution trace (display commands as they are run) */
>x|
FN("xtrace", FXTRACE, OF_ANY
/* -c (invocation) execute specified command */
>c|!SHFLAGS_NOT_CMD
FN("", FCOMMAND, OF_CMDLINE
/*
* anonymous flags: used internally by shell only (not visible to user
*/
/* ./. direct builtin call (divined from argv[0] multi-call binary) */
>|
FN("", FAS_BUILTIN, OF_INTERNAL
/* ./. (internal) initial shell was interactive */
>|
FN("", FTALKING_I, OF_INTERNAL
|SHFLAGS_OPTCS
+1321
View File
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
{ "ABRT", 6 },
{ "FPE", 8 },
{ "ILL", 4 },
{ "INT", 2 },
{ "SEGV", 11 },
{ "TERM", 15 },
{ "ALRM", 14 },
{ "BUS", 7 },
{ "CHLD", 17 },
{ "CONT", 18 },
{ "HUP", 1 },
{ "KILL", 9 },
{ "PIPE", 13 },
{ "QUIT", 3 },
{ "STOP", 19 },
{ "TSTP", 20 },
{ "TTIN", 21 },
{ "TTOU", 22 },
{ "USR1", 10 },
{ "USR2", 12 },
{ "POLL", 29 },
{ "PROF", 27 },
{ "SYS", 31 },
{ "TRAP", 5 },
{ "URG", 23 },
{ "VTALRM", 26 },
{ "XCPU", 24 },
{ "XFSZ", 25 },
{ "WINCH", 28 },
{ "PWR", 30 },
{ "STKFLT", 16 },
+53
View File
@@ -0,0 +1,53 @@
/*-
* Copyright (c) 2006, 2008, 2009, 2013
* mirabilos <m@mirbsd.org>
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.10 2015/11/29 17:05:02 tg Exp $");
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
#undef strlcpy
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
const char *s = src;
if (siz == 0)
goto traverse_src;
/* copy as many chars as will fit */
while (--siz && (*dst++ = *s++))
;
/* not enough room in dst */
if (siz == 0) {
/* safe to NUL-terminate dst since we copied <= siz-1 chars */
*dst = '\0';
traverse_src:
/* traverse rest of src */
while (*s++)
;
}
/* count does not include NUL */
return ((size_t)(s - src - 1));
}
+1193
View File
File diff suppressed because it is too large Load Diff
+1176
View File
File diff suppressed because it is too large Load Diff
+2208
View File
File diff suppressed because it is too large Load Diff
+80
View File
@@ -0,0 +1,80 @@
/*-
* Copyright (c) 2009, 2011, 2012, 2016, 2018
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*/
#if defined(VARSPEC_DEFNS)
__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.11 2018/01/13 21:38:10 tg Exp $");
#define FN(name) /* nothing */
#elif defined(VARSPEC_ENUMS)
#define FN(name) V_##name,
#define F0(name) V_##name = 0,
#elif defined(VARSPEC_ITEMS)
#define F0(name) /* nothing */
#define FN(name) #name,
#endif
#ifndef F0
#define F0 FN
#endif
/* NOTE: F0 are skipped for the ITEMS array, only FN generate names */
/* 0 is always V_NONE */
F0(NONE)
/* 1 and up are special variables */
FN(BASHPID)
#ifdef __OS2__
FN(BEGINLIBPATH)
#endif
FN(COLUMNS)
#ifdef __OS2__
FN(ENDLIBPATH)
#endif
FN(EPOCHREALTIME)
#if HAVE_PERSISTENT_HISTORY
FN(HISTFILE)
#endif
FN(HISTSIZE)
FN(IFS)
#ifdef MKSH_EARLY_LOCALE_TRACKING
FN(LANG)
FN(LC_ALL)
FN(LC_CTYPE)
#endif
#ifdef __OS2__
FN(LIBPATHSTRICT)
#endif
FN(LINENO)
FN(LINES)
FN(OPTIND)
FN(PATH)
FN(RANDOM)
FN(SECONDS)
#ifndef MKSH_NO_CMDLINE_EDITING
FN(TERM)
#endif
FN(TMOUT)
FN(TMPDIR)
#undef FN
#undef F0
#undef VARSPEC_DEFNS
#undef VARSPEC_ENUMS
#undef VARSPEC_ITEMS