summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-13 05:12:25 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-13 05:14:29 (GMT)
commit6106c0520946131f654b0a2e863a28f1c8c2a458 (patch)
tree1b22a6a8b1573db5018122a87ae560889f76db21 /meme
parent9363fb4b1c34582025d4ef4bd6f8e9021ae31134 (diff)
downloadmisc-6106c0520946131f654b0a2e863a28f1c8c2a458.zip
misc-6106c0520946131f654b0a2e863a28f1c8c2a458.tar.gz
misc-6106c0520946131f654b0a2e863a28f1c8c2a458.tar.bz2
meme/main.c: convert to using getopt
Diffstat (limited to 'meme')
-rw-r--r--meme/main.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/meme/main.c b/meme/main.c
index 175160b..dcd782b 100644
--- a/meme/main.c
+++ b/meme/main.c
@@ -1,8 +1,8 @@
/*
* main.c - Measmesh command-line processing and setup
*
- * Written 2014 by Werner Almesberger
- * Copyright 2014 by Werner Almesberger
+ * Written 2014-2015 by Werner Almesberger
+ * Copyright 2014-2015 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
#include "time.h"
#include "mesh.h"
@@ -43,24 +44,31 @@ static unsigned count_edges(void)
static void usage(const char *name)
{
- fprintf(stderr, "usage: %s\n", name);
+ fprintf(stderr, "usage: %s [file.stl]\n", name);
exit(1);
}
int main(int argc, char **argv)
{
+ int c;
struct time t_load;
- switch (argc) {
- case 1:
+ while ((c = getopt(argc, argv, "")) != EOF)
+ switch (c) {
+ default:
+ usage(*argv);
+ }
+
+ switch (argc - optind) {
+ case 0:
time_start(&t_load);
stl_load_file(stdin);
time_stop(&t_load);
break;
- case 2:
+ case 1:
time_start(&t_load);
- stl_load(argv[1]);
+ stl_load(argv[optind]);
time_stop(&t_load);
break;
default: