From: Linus Torvalds Date: Sun, 11 Sep 2011 18:36:33 +0000 (-0700) Subject: Save and restore a "dive number" X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6538e5bba00b51a7253b6cff927c8774f1b39e2b;p=ext%2Fsubsurface.git Save and restore a "dive number" 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 --- diff --git a/dive.h b/dive.h index 6191b60..3b5e5ab 100644 --- 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; diff --git a/parse-xml.c b/parse-xml.c index 4fd4dcf..a71ff23 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -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)) diff --git a/save-xml.c b/save-xml.c index c93a828..e47092e 100644 --- a/save-xml.c +++ b/save-xml.c @@ -205,9 +205,14 @@ static void save_dive(FILE *f, struct dive *dive) int i; struct tm *tm = gmtime(&dive->when); - fprintf(f, "\n", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, + fputs("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);