X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse.c;h=58d446db099c46f408a3c27d35bdfec99e249d40;hb=feec55504084baf022517d39e72431b4d361a217;hp=1a8e3ba6113064fb71a8273483941678f814df8c;hpb=5c4cc39c56470b0a01274e69be703f0d4fc3080b;p=ext%2Fsubsurface.git diff --git a/parse.c b/parse.c index 1a8e3ba..58d446d 100644 --- a/parse.c +++ b/parse.c @@ -222,11 +222,10 @@ static void depth(char *buffer, void *_depth) union int_or_float val; switch (integer_or_float(buffer, &val)) { - /* Integer values are probably in feet */ + /* All values are probably in meters */ case INTEGER: - depth->mm = 304.8 * val.i; - break; - /* Float? Probably meters.. */ + val.fp = val.i; + /* fallthrough */ case FLOAT: depth->mm = val.fp * 1000; break; @@ -391,10 +390,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)", + 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; } @@ -421,9 +444,18 @@ static void sample_start(void) static void sample_end(void) { - sample = NULL; if (!dive) return; + + if (sample->time.seconds > dive->duration.seconds) { + if (sample->depth.mm) + dive->duration = sample->time; + } + + if (sample->depth.mm > dive->maxdepth.mm) + dive->maxdepth.mm = sample->depth.mm; + + sample = NULL; dive->samples++; }