summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-04-04 13:07:46 -0400
committerOri Bernstein <ori@eigenstate.org>2013-04-04 13:07:46 -0400
commit03af679a2a685afe93242d2751ea1a94d9c17569 (patch)
treef9eb1715c253851d5dc8eb98de9979f739d9eb57
parent231b0fd0e1e70376bcf747a797a76b07521987b7 (diff)
downloadmc-03af679a2a685afe93242d2751ea1a94d9c17569.tar.gz
Shuffle and improve the command line option parser.
It's still incomplete and broken.
-rw-r--r--libstd/Makefile1
-rw-r--r--libstd/optparse.myr18
2 files changed, 11 insertions, 8 deletions
diff --git a/libstd/Makefile b/libstd/Makefile
index 07cdf65..3482cab 100644
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -7,6 +7,7 @@ MYRSRC= \
fmt.myr \
optparse.myr \
rand.myr \
+ slappend.myr \
slurp.myr \
sys.myr \
types.myr \
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 0bd1cfa..8fba4b2 100644
--- 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 @@ const optinit = {opts, args
ctx.args = args
ctx.argidx = 0
ctx.arglist = [][:]
- nextopt(ctx)
+ ctx.curarg = [][:]
+ next(ctx)
-> ctx
}
@@ -36,7 +39,7 @@ const optnext = {ctx
var c
if !ctx.curarg.len
- if !nextopt(ctx)
+ if !next(ctx)
-> Badchar
;;
;;
@@ -53,22 +56,21 @@ const optarg = {ctx
elif ctx.argidx > ctx.args.len
arg = ctx.args[ctx.argidx + 1]
ctx.argidx++
- nextopt(ctx)
+ next(ctx)
else
die("Arg needed")
;;
-> arg
}
-const nextopt = {ctx
+const next = {ctx
var i
for i = ctx.argidx + 1; i < ctx.args.len; i++
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