summaryrefslogtreecommitdiff
path: root/meme/meme.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-13 05:50:43 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-13 05:50:43 (GMT)
commit6a7b99db7751a7b7bceb2e79d7b11f68a2ad226a (patch)
treedba375b8afe2413991d046d7ab27290fcef3ef9a /meme/meme.c
parentc8177f08319285773a532b5745a0915e12c29a0a (diff)
downloadmisc-6a7b99db7751a7b7bceb2e79d7b11f68a2ad226a.zip
misc-6a7b99db7751a7b7bceb2e79d7b11f68a2ad226a.tar.gz
misc-6a7b99db7751a7b7bceb2e79d7b11f68a2ad226a.tar.bz2
meme/main.c: rename to meme.c
Diffstat (limited to 'meme/meme.c')
-rw-r--r--meme/meme.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/meme/meme.c b/meme/meme.c
new file mode 100644
index 0000000..fcafdb9
--- /dev/null
+++ b/meme/meme.c
@@ -0,0 +1,88 @@
+/*
+ * meme.c - Measmesh command-line processing and setup
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "time.h"
+#include "mesh.h"
+#include "stl.h"
+
+
+extern void gui(const char *logfile);
+
+
+static bool count_edge(const struct vertex *a, const struct vertex *b,
+ void *user)
+{
+ unsigned *count = user;
+
+ (*count)++;
+ return 0;
+}
+
+
+static unsigned count_edges(void)
+{
+ unsigned count = 0;
+
+ edge_foreach(count_edge, &count);
+ return count;
+}
+
+
+static void usage(const char *name)
+{
+ fprintf(stderr, "usage: %s [file.stl]\n", name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ int c;
+ const char *logfile = 0;
+ struct time t_load;
+
+ while ((c = getopt(argc, argv, "l:")) != EOF)
+ switch (c) {
+ case 'l':
+ logfile = optarg;
+ break;
+ default:
+ usage(*argv);
+ }
+
+ switch (argc - optind) {
+ case 0:
+ time_start(&t_load);
+ stl_load_file(stdin);
+ time_stop(&t_load);
+ break;
+ case 1:
+ time_start(&t_load);
+ stl_load(argv[optind]);
+ time_stop(&t_load);
+ break;
+ default:
+ usage(*argv);
+ }
+
+ fprintf(stderr, "STL loaded in %.3f s\n", time_ms(&t_load)/1000.0);
+ fprintf(stderr, "%u edges\n", count_edges());
+
+ gui(logfile);
+
+ return 0;
+}