X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;h=cecfbb30417b9a167371540e6f67fae36599c926;hb=b35e1bad8e19b52f4a1da66118bea4e998fb84f6;hp=d17f7a8eed4d77ed0f8e862bb73b754dff0a4726;hpb=afffcdbc0d6402e3dfee421f86938b98e12fb550;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index d17f7a8..cecfbb3 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -16,7 +16,7 @@ struct dive_table dive_table; /* * Add a dive into the dive_table array */ -static void record_dive(struct dive *dive) +void record_dive(struct dive *dive) { int nr = dive_table.nr, allocated = dive_table.allocated; struct dive **dives = dive_table.dives; @@ -90,7 +90,6 @@ const struct units IMPERIAL_units = { /* * Dive info as it is being built up.. */ -static int alloc_samples; static struct dive *dive; static struct sample *sample; static struct tm tm; @@ -105,7 +104,7 @@ static enum import_source { UDDF, } import_source; -static time_t utc_mktime(struct tm *tm) +time_t utc_mktime(struct tm *tm) { static const int mdays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 @@ -653,6 +652,7 @@ static int divinglog_dive_match(struct dive *dive, const char *name, int len, ch MATCH(".tanksize", cylindersize, &dive->cylinder[0].type.size) || MATCH(".presw", pressure, &dive->cylinder[0].type.workingpressure) || MATCH(".comments", utf8_string, &dive->notes) || + MATCH(".buddy.names", utf8_string, &dive->buddy) || MATCH(".country.name", utf8_string, &country) || MATCH(".city.name", utf8_string, &city) || MATCH(".place.name", divinglog_place, &dive->location) || @@ -954,6 +954,10 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) return; if (MATCH(".notes", utf8_string, &dive->notes)) return; + if (MATCH(".divemaster", utf8_string, &dive->divemaster)) + return; + if (MATCH(".buddy", utf8_string, &dive->buddy)) + return; if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cylinder_index].type.size)) return; @@ -984,17 +988,9 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) */ static void dive_start(void) { - unsigned int size; - if (dive) return; - - alloc_samples = 5; - size = dive_size(alloc_samples); - dive = malloc(size); - if (!dive) - exit(1); - memset(dive, 0, size); + dive = alloc_dive(); memset(&tm, 0, sizeof(tm)); } @@ -1143,22 +1139,7 @@ static void cylinder_end(void) static void sample_start(void) { - int nr; - - if (!dive) - return; - nr = dive->samples; - if (nr >= alloc_samples) { - unsigned int size; - - alloc_samples = (alloc_samples * 3)/2 + 10; - size = dive_size(alloc_samples); - dive = realloc(dive, size); - if (!dive) - return; - } - sample = dive->sample + nr; - memset(sample, 0, sizeof(*sample)); + sample = prepare_sample(&dive); event_index = 0; } @@ -1167,8 +1148,8 @@ static void sample_end(void) if (!dive) return; + finish_sample(dive, sample); sample = NULL; - dive->samples++; } static void entry(const char *name, int size, const char *raw)