summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-16 15:44:34 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-16 15:44:34 (GMT)
commit7a36d4f5b214d62268a085dad665b09c41f2b3c7 (patch)
tree9a5934c45ccae9d15cc346a10061ad04001953ef /meme
parent542ea751bc0d739ac4ff8490abd66726dd7c08ee (diff)
downloadmisc-7a36d4f5b214d62268a085dad665b09c41f2b3c7.zip
misc-7a36d4f5b214d62268a085dad665b09c41f2b3c7.tar.gz
misc-7a36d4f5b214d62268a085dad665b09c41f2b3c7.tar.bz2
meme/, vispcb/: separate paths from "struct overlay"
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c12
-rw-r--r--meme/gui.h2
-rw-r--r--meme/meme.c4
-rw-r--r--meme/overlay.c27
-rw-r--r--meme/overlay.h8
5 files changed, 27 insertions, 26 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 847fb4b..056912b 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -1198,7 +1198,7 @@ static void delayed_motion(void *user)
static bool event_loop(SDL_Surface **surf, const char *logfile,
- const struct overlay *const *overlays, unsigned n_overlays)
+ const struct overlay overlays[], unsigned n_overlays)
{
SDL_Surface *s = *surf;
SDL_Event event;
@@ -1253,15 +1253,15 @@ static bool event_loop(SDL_Surface **surf, const char *logfile,
return 1;
case SDLK_1:
if (n_overlays)
- overlay = overlays[0];
+ overlay = overlays + 0;
return 0;
case SDLK_2:
if (n_overlays > 1)
- overlay = overlays[1];
+ overlay = overlays + 1;
return 0;
case SDLK_3:
if (n_overlays > 2)
- overlay = overlays[2];
+ overlay = overlays + 2;
return 0;
default:
break;
@@ -1301,7 +1301,7 @@ static bool event_loop(SDL_Surface **surf, const char *logfile,
void gui(const char *logfile,
- const struct overlay *const *overlays, unsigned n_overlays)
+ const struct overlay overlays[], unsigned n_overlays)
{
SDL_Surface *surf;
@@ -1328,7 +1328,7 @@ void gui(const char *logfile,
auto_scale();
if (n_overlays)
- overlay = overlays[0];
+ overlay = overlays;
while (1) {
struct time t;
diff --git a/meme/gui.h b/meme/gui.h
index 49b9e9c..cc99a05 100644
--- a/meme/gui.h
+++ b/meme/gui.h
@@ -17,6 +17,6 @@
void gui(const char *logfile,
- const struct overlay *const *overlays, unsigned n_overlays);
+ const struct overlay overlays[], unsigned n_overlays);
#endif /* !GUI_H */
diff --git a/meme/meme.c b/meme/meme.c
index 2a8d11b..57e906a 100644
--- a/meme/meme.c
+++ b/meme/meme.c
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
const char *logfile = NULL;
const char *slice = NULL;
bool needle = 0;
- const struct overlay *overlays[N_OVERLAYS];
+ struct overlay overlays[N_OVERLAYS];
unsigned n_overlays = 0;
struct time t_load;
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
fprintf(stderr, "too many overlays\n");
exit(1);
}
- overlays[n_overlays] = overlay_load(optarg,
+ overlay_load(overlays + n_overlays, optarg,
overlay_xform);
n_overlays++;
break;
diff --git a/meme/overlay.c b/meme/overlay.c
index 70bf4e2..24c006f 100644
--- a/meme/overlay.c
+++ b/meme/overlay.c
@@ -23,9 +23,9 @@ struct point {
struct point *next;
};
-struct overlay {
+struct path {
struct point *points;
- struct overlay *next;
+ struct path *next;
};
@@ -33,10 +33,10 @@ void overlay_draw(const struct overlay *overlay,
void (*moveto)(void *user, int x, int y),
void (*lineto)(void *user, int x, int y), void *user)
{
- const struct overlay *path;
+ const struct path *path;
const struct point *p;
- for (path = overlay; path; path = path->next) {
+ for (path = overlay->paths; path; path = path->next) {
p = path->points;
moveto(user, p->x, p->y);
for (p = p->next; p; p = p->next)
@@ -45,17 +45,17 @@ void overlay_draw(const struct overlay *overlay,
}
-static struct overlay *overlay_load_file(FILE *file,
+static void overlay_load_file(struct overlay *overlay, FILE *file,
void (*xform)(float x, float y, float *res_x, float *res_y))
{
- struct overlay *over = NULL;
- struct overlay *path = NULL;
+ struct path *path = NULL;
struct point *p;
int lineno = 0;
char buf[1024];
int n;
double x, y, z;
+ overlay->paths = NULL;
while (fgets(buf, sizeof(buf), file)) {
lineno++;
if (*buf == '#')
@@ -75,10 +75,10 @@ static struct overlay *overlay_load_file(FILE *file,
}
if (!path) {
- path = alloc_type(struct overlay);
- path->next = over;
+ path = alloc_type(struct path);
+ path->next = overlay->paths;
path->points = NULL;
- over = path;
+ overlay->paths = path;
}
p = alloc_type(struct point);
if (xform) {
@@ -90,22 +90,19 @@ static struct overlay *overlay_load_file(FILE *file,
p->next = path->points;
path->points = p;
}
- return over;
}
-struct overlay *overlay_load(const char *name,
+void overlay_load(struct overlay *overlay, const char *name,
void (*xform)(float x, float y, float *res_x, float *res_y))
{
FILE *file;
- struct overlay *over;
file = fopen(name, "r");
if (!file) {
perror(name);
exit(1);
}
- over = overlay_load_file(file, xform);
+ overlay_load_file(overlay, file, xform);
fclose(file);
- return over;
}
diff --git a/meme/overlay.h b/meme/overlay.h
index 2439608..bec5a09 100644
--- a/meme/overlay.h
+++ b/meme/overlay.h
@@ -14,13 +14,17 @@
#ifndef OVERLAY_H
#define OVERLAY_H
-struct overlay;
+struct path;
+
+struct overlay {
+ struct path *paths;
+};
void overlay_draw(const struct overlay *overlay,
void (*moveto)(void *user, int x, int y),
void (*lineto)(void *user, int x, int y), void *user);
-struct overlay *overlay_load(const char *name,
+void overlay_load(struct overlay *overlay, const char *name,
void (*xform)(float x, float y, float *res_x, float *res_y));
#endif /* !OVERLAY_H */