summaryrefslogtreecommitdiff
path: root/muse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-10-05 15:24:10 -0400
committerOri Bernstein <ori@eigenstate.org>2014-10-05 15:24:10 -0400
commit87b4515f7e065029ec88eca6f6133f53223def8a (patch)
treedc1a3cf29a29dc693a071af9833fb09b98eb662f /muse
parenta8359030735219db18bc48b4e481c67ad6e48484 (diff)
downloadmc-87b4515f7e065029ec88eca6f6133f53223def8a.tar.gz
Write my own option parsing.
getopt() isn't really portable: it has different and annoying behaviors on OSX, and doesn't actually exist on plan9.
Diffstat (limited to 'muse')
-rw-r--r--muse/muse.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/muse/muse.c b/muse/muse.c
index 2cc54ac..2391005 100644
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -86,12 +86,13 @@ static void mergeuse(char *path)
int main(int argc, char **argv)
{
+ Optctx ctx;
+ size_t i;
FILE *f;
- int opt;
- int i;
- while ((opt = getopt(argc, argv, "d::hmo:I:")) != -1) {
- switch (opt) {
+ optinit(&ctx, "d:hmo:I:", argv, argc);
+ while (!optdone(&ctx)) {
+ switch (optnext(&ctx)) {
case 'h':
usage(argv[0]);
exit(0);
@@ -100,15 +101,15 @@ int main(int argc, char **argv)
merge = 1;
break;
case 'o':
- outfile = optarg;
+ outfile = ctx.optarg;
break;
case 'd':
debug = 1;
- while (optarg && *optarg)
- debugopt[*optarg++ & 0x7f] = 1;
+ while (ctx.optarg && *ctx.optarg)
+ debugopt[*ctx.optarg++ & 0x7f] = 1;
break;
case 'I':
- lappend(&incpaths, &nincpaths, optarg);
+ lappend(&incpaths, &nincpaths, ctx.optarg);
break;
default:
usage(argv[0]);
@@ -129,22 +130,22 @@ int main(int argc, char **argv)
file->file.globls = mkstab();
updatens(file->file.exports, outfile);
tyinit(file->file.globls);
- for (i = optind; i < argc; i++)
- mergeuse(argv[i]);
+ for (i = 0; i < ctx.nargs; i++)
+ mergeuse(ctx.args[i]);
infer(file);
tagexports(file->file.exports, 1);
f = fopen(outfile, "w");
writeuse(f, file);
fclose(f);
} else {
- for (i = optind; i < argc; i++) {
- file = mkfile(argv[i]);
+ for (i = 0; i < ctx.nargs; i++) {
+ file = mkfile(ctx.args[i]);
file->file.exports = mkstab();
file->file.globls = mkstab();
if (debugopt['s'])
- dumpuse(argv[i]);
+ dumpuse(ctx.args[i]);
else
- genuse(argv[i]);
+ genuse(ctx.args[i]);
}
}