summaryrefslogtreecommitdiff
path: root/meme/overlay.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-16 16:02:24 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-16 16:02:24 (GMT)
commit3401e143f56f0871f95759443ddec8e9c59fbdc9 (patch)
tree1a33116985a497bc0ae809c7f42abe9b8469e6ad /meme/overlay.c
parent7a36d4f5b214d62268a085dad665b09c41f2b3c7 (diff)
downloadmisc-3401e143f56f0871f95759443ddec8e9c59fbdc9.zip
misc-3401e143f56f0871f95759443ddec8e9c59fbdc9.tar.gz
misc-3401e143f56f0871f95759443ddec8e9c59fbdc9.tar.bz2
meme/overlay.c, overlay.h (overlay_reload): reload overlay from file
Diffstat (limited to 'meme/overlay.c')
-rw-r--r--meme/overlay.c57
1 files changed, 52 insertions, 5 deletions
diff --git a/meme/overlay.c b/meme/overlay.c
index 24c006f..7dfca37 100644
--- a/meme/overlay.c
+++ b/meme/overlay.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "util.h"
#include "overlay.h"
@@ -93,16 +94,62 @@ static void overlay_load_file(struct overlay *overlay, FILE *file,
}
-void overlay_load(struct overlay *overlay, const char *name,
- void (*xform)(float x, float y, float *res_x, float *res_y))
+
+
+static void overlay_do_load(struct overlay *overlay)
{
FILE *file;
- file = fopen(name, "r");
+ file = fopen(overlay->name, "r");
if (!file) {
- perror(name);
+ perror(overlay->name);
exit(1);
}
- overlay_load_file(overlay, file, xform);
+ overlay_load_file(overlay, file, overlay->xform);
fclose(file);
}
+
+
+static void free_points(struct path *path)
+{
+ struct point *p, *next;
+
+ for (p = path->points; p; p = next) {
+ next = p->next;
+ free(p);
+ }
+ path->points = NULL;
+}
+
+
+static void free_paths(struct overlay *overlay)
+{
+ struct path *path, *next;
+
+ for (path = overlay->paths; path; path = next) {
+ next = path->next;
+ free_points(path);
+ free(path);
+ }
+ overlay->paths = NULL;
+}
+
+
+void overlay_reload(struct overlay *overlay)
+{
+ free_paths(overlay);
+ overlay_do_load(overlay);
+}
+
+
+void overlay_load(struct overlay *overlay, const char *name,
+ void (*xform)(float x, float y, float *res_x, float *res_y))
+{
+ overlay->name = strdup(name);
+ if (!overlay->name) {
+ perror("strdup");
+ exit(1);
+ }
+ overlay->xform = xform;
+ overlay_do_load(overlay);
+}