X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;h=d53c9b323cc6b49a7cd55d1a1565cfed3ba6ce09;hb=4d19f42a4e0aea4c12b9b05af25c7c0f42ca3a48;hp=8aaeedc9f72d9146b0939042969240c87b7741da;hpb=8197d7f4d4702d18df5b2121b5e0126c61e1b7ea;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index 8aaeedc..d53c9b3 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -70,12 +70,17 @@ static int match(const char *pattern, int plen, static struct units { enum { METERS, FEET } length; enum { LITER, CUFT } volume; - enum { BAR, PSI } pressure; - enum { CELSIUS, FAHRENHEIT } temperature; + enum { BAR, PSI, PASCAL } pressure; + enum { CELSIUS, FAHRENHEIT, KELVIN } temperature; enum { KG, LBS } weight; } units; -/* We're going to default to SI units for input */ +/* + * We're going to default to SI units for input. Yes, + * technically the SI unit for pressure is Pascal, but + * we default to bar (10^5 pascal), which people + * actually use. Similarly, C instead of Kelvin. + */ static const struct units SI_units = { .length = METERS, .volume = LITER, @@ -99,6 +104,7 @@ static enum import_source { SUUNTO, UEMIS, DIVINGLOG, + UDDF, } import_source; static time_t utc_mktime(struct tm *tm) @@ -238,6 +244,9 @@ static void pressure(char *buffer, void *_press) if (!val.fp) break; switch (units.pressure) { + case PASCAL: + mbar = val.fp / 100; + break; case BAR: /* Assume mbar, but if it's really small, it's bar */ mbar = val.fp; @@ -293,6 +302,9 @@ static void temperature(char *buffer, void *_temperature) break; /* Celsius */ switch (units.temperature) { + case KELVIN: + temperature->mkelvin = val.fp * 1000; + break; case CELSIUS: temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5; break; @@ -648,7 +660,7 @@ static void uemis_date_time(char *buffer, void *_when) switch (integer_or_float(buffer, &val)) { case FLOAT: - *when = (val.fp - 40587.5) * 86400; + *when = (val.fp - 40587) * 86400; break; default: fprintf(stderr, "Strange julian date: %s", buffer); @@ -665,10 +677,14 @@ static void uemis_date_time(char *buffer, void *_when) */ static void uemis_time_zone(char *buffer, void *_when) { +#if 0 /* seems like this is only used to display it correctly + * the stored time appears to be UTC */ + time_t *when = _when; signed char tz = atoi(buffer); *when += tz * 3600; +#endif } /* 0 - air ; 1 - nitrox1 ; 2 - nitrox2 ; 3 = nitrox3 */ @@ -1167,6 +1183,14 @@ static void DivingLog_importer(void) units.pressure = PSI; } +static void uddf_importer(void) +{ + import_source = UDDF; + units = SI_units; + units.pressure = PASCAL; + units.temperature = KELVIN; +} + /* * I'm sure this could be done as some fancy DTD rules. * It's just not worth the headache. @@ -1178,6 +1202,7 @@ static struct nesting { { "dive", dive_start, dive_end }, { "Dive", dive_start, dive_end }, { "sample", sample_start, sample_end }, + { "waypoint", sample_start, sample_end }, { "SAMPLE", sample_start, sample_end }, { "reading", sample_start, sample_end }, { "event", event_start, event_end }, @@ -1189,6 +1214,7 @@ static struct nesting { { "SUUNTO", suunto_importer }, { "Divinglog", DivingLog_importer }, { "pre_dive", uemis_importer }, + { "uddf", uddf_importer }, { NULL, } }; @@ -1228,13 +1254,20 @@ static void reset_all(void) import_source = UNKNOWN; } -void parse_xml_file(const char *filename) +void parse_xml_file(const char *filename, GError **error) { xmlDoc *doc; doc = xmlReadFile(filename, NULL, 0); if (!doc) { fprintf(stderr, "Failed to parse '%s'.\n", filename); + if (error != NULL) + { + *error = g_error_new(g_quark_from_string("divelog"), + DIVE_ERROR_PARSE, + "Failed to parse '%s'", + filename); + } return; }