]> git.tdb.fi Git - ext/subsurface.git/blobdiff - parse-xml.c
Add the ugliest 'delete dive' model ever
[ext/subsurface.git] / parse-xml.c
index e920a11f6f0d798b18900ccb23317c95c8ec5162..552786b7aa58e3f780e08ce45bd87e80f1cfbbcf 100644 (file)
@@ -39,6 +39,29 @@ void record_dive(struct dive *dive)
        dive_table.nr = nr+1;
 }
 
+/*
+ * Remove a dive from the dive_table array
+ */
+void delete_dive(struct dive *dive)
+{
+       int nr = dive_table.nr, i;
+       struct dive **dives = dive_table.dives;
+
+       /*
+        * Stupid. We know the dive table is sorted by date,
+        * we could do a binary lookup. Sue me.
+        */
+       for (i = 0; i < nr; i++) {
+               struct dive *d = dives[i];
+               if (d != dive)
+                       continue;
+               memmove(dives+i, dives+i+1, sizeof(struct dive *)*(nr-i-1));
+               dives[nr] = NULL;
+               dive_table.nr = nr-1;
+               break;
+       }
+}
+
 static void start_match(const char *type, const char *name, char *buffer)
 {
        if (verbose > 2)