summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-13 05:26:40 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-13 05:26:40 (GMT)
commitc8177f08319285773a532b5745a0915e12c29a0a (patch)
tree99386ee75d7db64c089237804c9a345901ad3f87 /meme
parent54dbe1c4b48b545e937a31fe0a775491ea55cd01 (diff)
downloadmisc-c8177f08319285773a532b5745a0915e12c29a0a.zip
misc-c8177f08319285773a532b5745a0915e12c29a0a.tar.gz
misc-c8177f08319285773a532b5745a0915e12c29a0a.tar.bz2
meme/: new option "-l logfile" to append marker/measurement data to file
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c31
-rw-r--r--meme/main.c10
2 files changed, 31 insertions, 10 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 9bcb13d..d2ac9d6 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -839,7 +839,22 @@ static void print_marker(FILE *file)
}
-static void set_marker(const struct vertex *v)
+static void log_marker(const char *logfile)
+{
+ FILE *file;
+
+ file = fopen(logfile, "a");
+ if (!file) {
+ perror(logfile);
+ return;
+ }
+ print_marker(file);
+ if (fclose(file) == EOF)
+ perror(logfile);
+}
+
+
+static void set_marker(const struct vertex *v, const char *logfile)
{
if (select_marker(v))
return;
@@ -850,6 +865,8 @@ static void set_marker(const struct vertex *v)
mark_a = cursor;
print_marker(stderr);
+ if (logfile)
+ log_marker(logfile);
}
@@ -940,13 +957,13 @@ static void motion_event(SDL_Surface *s, SDL_MouseMotionEvent *motion)
}
-static void button_event(SDL_MouseButtonEvent *button)
+static void button_event(SDL_MouseButtonEvent *button, const char *logfile)
{
switch (button->button) {
case 1:
if (!cursor)
break;
- set_marker(cursor);
+ set_marker(cursor, logfile);
break;
case 2:
x_orig = mouse_x;
@@ -1126,7 +1143,7 @@ static void delayed_motion(void *user)
}
-static bool event_loop(SDL_Surface **surf)
+static bool event_loop(SDL_Surface **surf, const char *logfile)
{
SDL_Surface *s = *surf;
SDL_Event event;
@@ -1149,7 +1166,7 @@ static bool event_loop(SDL_Surface **surf)
break;
case SDL_MOUSEBUTTONDOWN:
update_mouse_pos(event.button.x, event.button.y);
- button_event(&event.button);
+ button_event(&event.button, logfile);
return 0;
case SDL_VIDEORESIZE:
xres = event.resize.w;
@@ -1210,7 +1227,7 @@ static bool event_loop(SDL_Surface **surf)
}
-void gui(void)
+void gui(const char *logfile)
{
SDL_Surface *surf;
@@ -1258,7 +1275,7 @@ fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
}
apply_changes(surf);
- if (event_loop(&surf))
+ if (event_loop(&surf, logfile))
break;
}
}
diff --git a/meme/main.c b/meme/main.c
index dcd782b..e72514a 100644
--- a/meme/main.c
+++ b/meme/main.c
@@ -20,7 +20,7 @@
#include "stl.h"
-extern void gui(void);
+extern void gui(const char *logfile);
static bool count_edge(const struct vertex *a, const struct vertex *b,
@@ -52,10 +52,14 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
int c;
+ const char *logfile = 0;
struct time t_load;
- while ((c = getopt(argc, argv, "")) != EOF)
+ while ((c = getopt(argc, argv, "l:")) != EOF)
switch (c) {
+ case 'l':
+ logfile = optarg;
+ break;
default:
usage(*argv);
}
@@ -78,7 +82,7 @@ int main(int argc, char **argv)
fprintf(stderr, "STL loaded in %.3f s\n", time_ms(&t_load)/1000.0);
fprintf(stderr, "%u edges\n", count_edges());
- gui();
+ gui(logfile);
return 0;
}