]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Remember the event names as we encounter them
authorDirk Hohndel <dirk@hohndel.org>
Tue, 25 Oct 2011 07:29:19 +0000 (00:29 -0700)
committerDirk Hohndel <dirk@hohndel.org>
Tue, 25 Oct 2011 08:05:08 +0000 (01:05 -0700)
First step to being able to filter the events that we display in the
profile. We could (in theory) walk all the dives in the divelist when we
need this data, but it seems much more convenient to have them in an array
in one place.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
dive.c
dive.h
profile.c

diff --git a/dive.c b/dive.c
index b57205bc5ff096841cc0d0f3626265a650f9228f..ed3908928a97c3c7ddfabb7c12d003de4b6f2349 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -26,6 +26,7 @@ void add_event(struct dive *dive, int time, int type, int flags, int value, cons
        while (*p)
                p = &(*p)->next;
        *p = ev;
+       remember_event(name);
 }
 
 double get_depth_units(unsigned int mm, int *frac, const char **units)
diff --git a/dive.h b/dive.h
index 7c64c21e25fcf849f848e55ef64db34a8afe9a6e..1008e56bfa5a42776b941d82efff587615569313 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -262,6 +262,7 @@ extern void report_error(GError* error);
 extern void add_cylinder_description(cylinder_type_t *);
 extern void add_people(const char *string);
 extern void add_location(const char *string);
+extern void remember_event(const char *eventname);
 
 extern void dive_list_update_dives(void);
 extern void flush_divelist(struct dive *dive);
index 5dad475bcbc850de7464064afd3acc50e0e38efa..11b01b5035a0e4a1581287cfa3c277cc304f1cf2 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -166,6 +166,37 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t *
        cairo_show_text(cr, buffer);
 }
 
+struct ev_select {
+       char *ev_name;
+       gboolean plot_ev;
+};
+static struct ev_select *ev_namelist;
+static int evn_allocated;
+static int evn_used;
+
+void remember_event(const char *eventname)
+{
+       int i=0, len;
+
+       if (!eventname || (len = strlen(eventname)) == 0)
+               return;
+       while (i < evn_used) {
+               if (!strncmp(eventname,ev_namelist[i].ev_name,len))
+                       return;
+               i++;
+       }
+       if (evn_used == evn_allocated) {
+               evn_allocated += 10;
+               ev_namelist = realloc(ev_namelist, evn_allocated * sizeof(struct ev_select));
+               if (! ev_namelist)
+                       /* we are screwed, but let's just bail out */
+                       return;
+       }
+       ev_namelist[evn_used].ev_name = strdup(eventname);
+       ev_namelist[evn_used].plot_ev = TRUE;
+       evn_used++;
+}
+
 static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event, const text_render_options_t *tro)
 {
        int i, depth = 0;