summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-04-10 23:11:15 -0400
committerOri Bernstein <ori@eigenstate.org>2013-04-10 23:11:15 -0400
commit174d472f8efa1f2cbf10ff36bcdd80dd87bbdcb9 (patch)
treea0d35ef76b22d3f54b5cbbe8aece424d0d1110a4
parent3b80bdf127a0e3d1551a4393008f702ca022f2b3 (diff)
downloadmc-174d472f8efa1f2cbf10ff36bcdd80dd87bbdcb9.tar.gz
Renamings.
Rename members in the optctx struct.
-rw-r--r--libstd/optparse.myr42
1 files changed, 23 insertions, 19 deletions
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 0f3b68a..c06c6f5 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -9,35 +9,39 @@ use "utf.use"
pkg std =
type optctx = struct
- /* data passed in */
- opts : byte[:]
+ /* public variables */
args : byte[:][:]
+ /* data passed in */
+ optstr : byte[:]
+ optargs : byte[:][:]
+
/* state */
optdone : bool /* if we've seen '--', everything's an arg */
- done : bool /* if we've processed all the args */
+ finished : bool /* if we've processed all theoptargs */
argidx : size
curarg : byte[:]
- arglist : byte[:][:]
;;
- const optinit : (opts : byte[:], args : byte[:][:] -> optctx#)
+ const optinit : (optstr: byte[:],optargs : byte[:][:] -> optctx#)
const optnext : (ctx : optctx# -> [char, byte[:]])
const optdone : (ctx : optctx# -> bool)
;;
-const optinit = {opts, args
+const optinit = {optstr, optargs
var ctx
ctx = alloc()
- ctx.opts = opts
- ctx.args = args
+ ctx.optstr= optstr
+ ctx.optargs =optargs
ctx.optdone = false
- ctx.done = false
+ ctx.finished = false
ctx.argidx = 0
- ctx.arglist = [][:]
ctx.curarg = [][:]
+
+ ctx.args = [][:]
+
next(ctx)
-> ctx
}
@@ -58,8 +62,8 @@ const optnext = {ctx
elif tryarg && ctx.curarg.len > 0
arg = ctx.curarg
ctx.curarg = ctx.curarg[ctx.curarg.len:]
- elif tryarg && ctx.argidx < (ctx.args.len - 1)
- arg = ctx.args[ctx.argidx + 1]
+ elif tryarg && ctx.argidx < (ctx.optargs.len - 1)
+ arg = ctx.optargs[ctx.argidx + 1]
ctx.argidx++
next(ctx)
elif needarg
@@ -77,14 +81,14 @@ const optnext = {ctx
}
const optdone = {ctx
- -> !ctx.curarg.len && ctx.done
+ -> !ctx.curarg.len && ctx.finished
}
const optinfo = {ctx, arg
var s
var c
- s = ctx.opts
+ s = ctx.optstr
while s.len != 0
(c, s) = striter(s)
if c == arg
@@ -107,17 +111,17 @@ const optinfo = {ctx, arg
const next = {ctx
var i
- for i = ctx.argidx + 1; i < ctx.args.len; i++
- if !ctx.optdone && decode(ctx.args[i]) == '-'
+ for i = ctx.argidx + 1; i < ctx.optargs.len; i++
+ if !ctx.optdone && decode(ctx.optargs[i]) == '-'
goto foundopt
else
- ctx.arglist = slappend(ctx.arglist, ctx.args[i])
+ ctx.args = slappend(ctx.args, ctx.optargs[i])
;;
;;
- ctx.done = true
+ ctx.finished = true
-> false
:foundopt
ctx.argidx = i
- ctx.curarg = ctx.args[i][1:]
+ ctx.curarg = ctx.optargs[i][1:]
-> true
}