ref: 03af679a2a685afe93242d2751ea1a94d9c17569
parent: 231b0fd0e1e70376bcf747a797a76b07521987b7
author: Ori Bernstein <[email protected]>
date: Thu Apr 4 09:07:46 EDT 2013
Shuffle and improve the command line option parser. It's still incomplete and broken.
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -7,6 +7,7 @@
fmt.myr \
optparse.myr \
rand.myr \
+ slappend.myr \
slurp.myr \
sys.myr \
types.myr \
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -1,7 +1,9 @@
-use "types.use"
use "alloc.use"
-use "utf.use"
use "die.use"
+use "extremum.use"
+use "slappend.use"
+use "types.use"
+use "utf.use"
pkg std =
type optctx = struct
@@ -28,7 +30,8 @@
ctx.args = args
ctx.argidx = 0
ctx.arglist = [][:]
- nextopt(ctx)
+ ctx.curarg = [][:]
+ next(ctx)
-> ctx
}
@@ -36,7 +39,7 @@
var c
if !ctx.curarg.len
- if !nextopt(ctx)
+ if !next(ctx)
-> Badchar
;;
;;
@@ -53,7 +56,7 @@
elif ctx.argidx > ctx.args.len
arg = ctx.args[ctx.argidx + 1]
ctx.argidx++
- nextopt(ctx)
+ next(ctx)
else
die("Arg needed")
;;
@@ -60,7 +63,7 @@
-> arg
}
-const nextopt = {ctx
+const next = {ctx
var i
for i = ctx.argidx + 1; i < ctx.args.len; i++
@@ -67,8 +70,7 @@
if decode(ctx.args[i]) == '-'
goto foundopt
else
- /* FIXME: implement slappend */
- /* ctx.args = slappend(ctx.args, ctx.args[i]) */
+ ctx.args = slappend(ctx.args, ctx.args[i])
;;
;;
-> false