mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 00:33:24 +00:00
Add event parsing to the git object tree loader
This makes us parse everything we save, and I can load my XML file, save it as a git file, load that git file, save it as a new XML file, and the end result is identical. Well... *ALMOST* identical. We currently don't save the dive computer nickname and serial/firmware information in the git repository, so that does get lost in translation. But all the actual dive data is there. NOTE! I have currently only worked with my own dive files. They are reasonably complex and complete, and do have a lot of the interesting cases covered (like multiple dive computers etc), but there's no CCR information, and all the dives are in trips, so this does need more testing. It's at the very least very close. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6ef38967ff
commit
6f3be56d8d
1 changed files with 42 additions and 2 deletions
44
load-git.c
44
load-git.c
|
@ -503,9 +503,49 @@ static void parse_dc_time(char *line, struct membuffer *str, void *_dc)
|
|||
static void parse_dc_watertemp(char *line, struct membuffer *str, void *_dc)
|
||||
{ struct divecomputer *dc = _dc; dc->watertemp = get_temperature(line); }
|
||||
|
||||
/* FIXME! Events not parsed */
|
||||
static void parse_event_keyvalue(void *_event, const char *key, const char *value)
|
||||
{
|
||||
struct event *event = _event;
|
||||
int val = atoi(value);
|
||||
|
||||
if (!strcmp(key, "type")) {
|
||||
event->type = val;
|
||||
} else if (!strcmp(key, "flags")) {
|
||||
event->flags = val;
|
||||
} else if (!strcmp(key, "value")) {
|
||||
event->value = val;
|
||||
} else if (!strcmp(key, "name")) {
|
||||
/* We get the name from the string handling */
|
||||
} else
|
||||
report_error("Unexpected event key/value pair (%s/%s)", key, value);
|
||||
}
|
||||
|
||||
static void parse_dc_event(char *line, struct membuffer *str, void *_dc)
|
||||
{ }
|
||||
{
|
||||
int m, s;
|
||||
const char *name;
|
||||
struct divecomputer *dc = _dc;
|
||||
struct event event = { 0 };
|
||||
|
||||
m = strtol(line, &line, 10);
|
||||
if (*line == ':')
|
||||
s = strtol(line+1, &line, 10);
|
||||
event.time.seconds = m*60+s;
|
||||
|
||||
for (;;) {
|
||||
char c;
|
||||
while (isspace(c = *line))
|
||||
line++;
|
||||
if (!c)
|
||||
break;
|
||||
line = parse_keyvalue_entry(parse_event_keyvalue, &event, line);
|
||||
}
|
||||
|
||||
name = "";
|
||||
if (str->len)
|
||||
name = mb_cstring(str);
|
||||
add_event(dc, event.time.seconds, event.type, event.flags, event.value, name);
|
||||
}
|
||||
|
||||
static void parse_trip_date(char *line, struct membuffer *str, void *_trip)
|
||||
{ dive_trip_t *trip = _trip; update_date(&trip->when, line); }
|
||||
|
|
Loading…
Add table
Reference in a new issue