]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Generate a default name for a dive, if it doesn't have one already
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 03:54:43 +0000 (20:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 03:54:43 +0000 (20:54 -0700)
The name is a string containint date, time, depth and length.  So it's
useful even with nothing else going on.

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

diff --git a/dive.h b/dive.h
index 53ecdfe00efc9d5ac41305bf488dd441551f7804..ba9f66882baefa1d5a18a46de0ceff2bd7472d19 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -101,6 +101,7 @@ struct sample {
 };
 
 struct dive {
+       const char *name;
        time_t when;
        depth_t maxdepth, meandepth;
        duration_t duration, surfacetime;
diff --git a/parse.c b/parse.c
index 1a8e3ba6113064fb71a8273483941678f814df8c..f90c16ce12fbf05fde39ce39e9840ffd8536c211 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -391,10 +391,34 @@ static void dive_start(void)
        memset(&tm, 0, sizeof(tm));
 }
 
+static char *generate_name(struct dive *dive)
+{
+       int len;
+       struct tm *tm;
+       char buffer[256], *p;
+
+       tm = gmtime(&dive->when);
+
+       len = snprintf(buffer, sizeof(buffer),
+               "%04d-%02d-%02d "
+               "%02d:%02d:%02d "
+               "(%d ft, %d min)\n",
+               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
+               tm->tm_hour, tm->tm_min, tm->tm_sec,
+               to_feet(dive->maxdepth), dive->duration.seconds / 60);
+       p = malloc(len+1);
+       if (!p)
+               exit(1);
+       memcpy(p, buffer, len+1);
+       return p;
+}
+
 static void dive_end(void)
 {
        if (!dive)
                return;
+       if (!dive->name)
+               dive->name = generate_name(dive);
        record_dive(dive);
        dive = NULL;
 }