]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Save and restore a "dive number"
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 11 Sep 2011 18:36:33 +0000 (11:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 11 Sep 2011 18:36:33 +0000 (11:36 -0700)
Some people want to know how many dives they have under their belt, so
let's save and restore the dive number if it exists.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
dive.h
parse-xml.c
save-xml.c

diff --git a/dive.h b/dive.h
index 6191b60b9179d2fcde0847cde6efcdbf36ead229..3b5e5abd75a0e9b757aaa2f0582be802a3ebbe40 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -128,6 +128,7 @@ struct sample {
 #define MAX_CYLINDERS (8)
 
 struct dive {
+       int nr;
        time_t when;
        char *location;
        char *notes;
index 4fd4dcfe6415f1495c414b05a69785579355a821..a71ff235b4043bef4b9a8c296f3b91721f7e1f68 100644 (file)
@@ -609,7 +609,8 @@ static void divinglog_place(char *place, void *_location)
 
 static int divinglog_dive_match(struct dive *dive, const char *name, int len, char *buf)
 {
-       return  MATCH(".divedate", divedate, &dive->when) ||
+       return  MATCH(".id", get_index, &dive->nr) ||
+               MATCH(".divedate", divedate, &dive->when) ||
                MATCH(".entrytime", divetime, &dive->when) ||
                MATCH(".depth", depth, &dive->maxdepth) ||
                MATCH(".tanksize", cylindersize, &dive->cylinder[0].type.size) ||
@@ -876,6 +877,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
                break;
        }
 
+       if (MATCH(".nr", get_index, &dive->nr))
+               return;
        if (MATCH(".date", divedate, &dive->when))
                return;
        if (MATCH(".time", divetime, &dive->when))
index c93a828cc54f8fa5b1c29eb28bf7b42762fe034e..e47092ebcb9d9dee241e08f1a1396446edbcfb21 100644 (file)
@@ -205,9 +205,14 @@ static void save_dive(FILE *f, struct dive *dive)
        int i;
        struct tm *tm = gmtime(&dive->when);
 
-       fprintf(f, "<dive date='%04u-%02u-%02u' time='%02u:%02u:%02u' duration='%u:%02u min'>\n",
-               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
-               tm->tm_hour, tm->tm_min, tm->tm_sec,
+       fputs("<dive", f);
+       if (dive->nr)
+               fprintf(f, " nr='%d'", dive->nr);
+       fprintf(f, " date='%04u-%02u-%02u'",
+               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
+       fprintf(f, " time='%02u:%02u:%02u'",
+               tm->tm_hour, tm->tm_min, tm->tm_sec);
+       fprintf(f, " duration='%u:%02u min'>\n",
                FRACTION(dive->duration.seconds, 60));
        save_overview(f, dive);
        save_cylinder_info(f, dive);