1# for compatibility with the S5R3 /bin/sh getopts builtin 2function _getopts # [ arg ] ... optstring name 3{ 4 OPTIND=${OPTIND:-1} 5 integer n=$#-1 6 eval typeset opstring=['$'$n] name='$'{$#} balance 7 typeset -L1 c d 8 shift OPTIND-1 9 if test X"$_arg" = X 10 then if (($# > 0)) 11 then _arg=$1 12 shift 13 else return 1 14 fi 15 fi 16 case $_arg in 17 --) 18 _arg= 19 return 1 20 ;; 21 -*) 22 c=${_arg#-} 23 case $c in 24 $opstring) 25 d=${opstring#*$c} 26 balance=${_arg#*$c} 27 if test X"$balance" = X 28 then if test X$d = X: 29 then OPTARG=$1 30 let OPTIND=OPTIND+2 31 else let OPTIND=OPTIND+1 32 fi 33 _arg= 34 else if test X$d = X: 35 then OPTARG=$balance _arg= 36 let OPTIND=OPTIND+1 37 else _arg=-$balance 38 fi 39 fi 40 eval $name=$c 41 return 0 42 ;; 43 *) echo $0: bad option 44 eval $name=? 45 return 1 46 ;; 47 esac 48 ;; 49 *) 50 _arg= 51 return 1 52 ;; 53 esac 54} 55alias getopts='_getopts "$@"' 56