From 71f221d810298dd22eabc3cf7f5c9ca824a01e8a Mon Sep 17 00:00:00 2001 From: Marc Teitelbaum Date: Fri, 22 Jul 1988 00:31:57 -0800 Subject: [PATCH] date and time created 88/07/21 17:31:57 by marc SCCS-vsn: local/toolchest/ksh/getopts 1.1 --- usr/src/local/toolchest/ksh/getopts | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 usr/src/local/toolchest/ksh/getopts diff --git a/usr/src/local/toolchest/ksh/getopts b/usr/src/local/toolchest/ksh/getopts new file mode 100644 index 0000000000..aea614b9f3 --- /dev/null +++ b/usr/src/local/toolchest/ksh/getopts @@ -0,0 +1,55 @@ +# for compatibility with the S5R3 /bin/sh getopts builtin +function _getopts # [ arg ] ... optstring name +{ + OPTIND=${OPTIND:-1} + integer n=$#-1 + eval typeset opstring=['$'$n] name='$'{$#} balance + typeset -L1 c d + shift OPTIND-1 + if test X"$_arg" = X + then if (($# > 0)) + then _arg=$1 + shift + else return 1 + fi + fi + case $_arg in + --) + _arg= + return 1 + ;; + -*) + c=${_arg#-} + case $c in + $opstring) + d=${opstring#*$c} + balance=${_arg#*$c} + if test X"$balance" = X + then if test X$d = X: + then OPTARG=$1 + let OPTIND=OPTIND+2 + else let OPTIND=OPTIND+1 + fi + _arg= + else if test X$d = X: + then OPTARG=$balance _arg= + let OPTIND=OPTIND+1 + else _arg=-$balance + fi + fi + eval $name=$c + return 0 + ;; + *) echo $0: bad option + eval $name=? + return 1 + ;; + esac + ;; + *) + _arg= + return 1 + ;; + esac +} +alias getopts='_getopts "$@"' -- 2.20.1