X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;h=6bb78fdf6077e1db2a85ee6ee194e5793c8ae802;hb=3a6652634b2152352f6f5a2b9ee3d549140ae337;hp=8e64b1e21f35463aa19eb3393588bcc138b28478;hpb=27ed16072f3b49b07e0af495fed10f883de90c82;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index 8e64b1e..6bb78fd 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 @@ -423,7 +422,7 @@ static void water_pressure(char *buffer, void *_depth) * atm to cm. Why not mm? The precision just isn't * there. */ - cm = 100 * (atm - 1) + 0.5; + cm = 100 * atm + 0.5; if (cm > 0) { depth->mm = 10 * (long)cm; break; @@ -488,6 +487,16 @@ static int uemis_fill_sample(struct sample *sample, const char *name, int len, c * Divinglog is crazy. The temperatures are in celsius. EXCEPT * for the sample temperatures, that are in Fahrenheit. * WTF? + * + * Oh, and I think Diving Log *internally* probably kept them + * in celsius, because I'm seeing entries like + * + * 32.0 + * + * in there. Which is freezing, aka 0 degC. I bet the "0" is + * what Diving Log uses for "no temperature". + * + * So throw away crap like that. */ static void fahrenheit(char *buffer, void *_temperature) { @@ -496,6 +505,9 @@ static void fahrenheit(char *buffer, void *_temperature) switch (integer_or_float(buffer, &val)) { case FLOAT: + /* Floating point equality is evil, but works for small integers */ + if (val.fp == 32.0) + break; temperature->mkelvin = (val.fp + 459.67) * 5000/9; break; default: @@ -509,7 +521,7 @@ static void fahrenheit(char *buffer, void *_temperature) * pressures are in PSI. But the tank working pressure is in * bar. WTF^2? * - * Crazy stuff like this is why diveclog has everything in + * Crazy stuff like this is why subsurface has everything in * these inconvenient typed structures, and you have to say * "pressure->mbar" to get the actual value. Exactly so that * you can never have unit confusion. @@ -640,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) || @@ -941,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; @@ -971,21 +988,13 @@ 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)); } -static void sanitize_gasmix(gasmix_t *mix) +static void sanitize_gasmix(struct gasmix *mix) { unsigned int o2, he; @@ -1130,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; } @@ -1154,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) @@ -1363,7 +1357,7 @@ void parse_xml_file(const char *filename, GError **error) fprintf(stderr, "Failed to parse '%s'.\n", filename); if (error != NULL) { - *error = g_error_new(g_quark_from_string("divelog"), + *error = g_error_new(g_quark_from_string("subsurface"), DIVE_ERROR_PARSE, "Failed to parse '%s'", filename);