mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Generate a default name for a dive, if it doesn't have one already
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>
This commit is contained in:
parent
0ca546b31e
commit
3aa02ccba9
2 changed files with 25 additions and 0 deletions
1
dive.h
1
dive.h
|
@ -101,6 +101,7 @@ struct sample {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dive {
|
struct dive {
|
||||||
|
const char *name;
|
||||||
time_t when;
|
time_t when;
|
||||||
depth_t maxdepth, meandepth;
|
depth_t maxdepth, meandepth;
|
||||||
duration_t duration, surfacetime;
|
duration_t duration, surfacetime;
|
||||||
|
|
24
parse.c
24
parse.c
|
@ -391,10 +391,34 @@ static void dive_start(void)
|
||||||
memset(&tm, 0, sizeof(tm));
|
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)
|
static void dive_end(void)
|
||||||
{
|
{
|
||||||
if (!dive)
|
if (!dive)
|
||||||
return;
|
return;
|
||||||
|
if (!dive->name)
|
||||||
|
dive->name = generate_name(dive);
|
||||||
record_dive(dive);
|
record_dive(dive);
|
||||||
dive = NULL;
|
dive = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue