date and time created 88/07/21 17:31:57 by marc
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:31:57 +0000 (00:31 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:31:57 +0000 (00:31 -0800)
SCCS-vsn: local/toolchest/ksh/getopts 1.1

usr/src/local/toolchest/ksh/getopts [new file with mode: 0644]

diff --git a/usr/src/local/toolchest/ksh/getopts b/usr/src/local/toolchest/ksh/getopts
new file mode 100644 (file)
index 0000000..aea614b
--- /dev/null
@@ -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 "$@"'