diff options
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/parse-xml.c b/parse-xml.c index 8cf2b0c2a..698b31171 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -10,14 +10,9 @@ #include <libxml/parser.h> #include <libxml/parserInternals.h> #include <libxml/tree.h> -#ifdef XSLT #include <libxslt/transform.h> -#endif #include <glib/gi18n.h> - -#ifdef SQLITE3 #include<sqlite3.h> -#endif #include "dive.h" #include "device.h" @@ -200,6 +195,28 @@ static void divedatetime(char *buffer, void *_when) } } +static void divetags(char *buffer, void *_tags) +{ + int *tags = _tags; + int i; + + for (i = 0; i < DTAG_NR; i++) { + if (strstr(buffer, dtag_names[i])) { + /* stupidly we have 'cave' and 'cavern' */ + if (1 << i == DTAG_CAVE) { + char *cave = strstr(buffer, "cave"); + while (cave && !strncmp(cave, "cavern", strlen("cavern"))) { + cave++; + cave = strstr(cave, "cave"); + } + if (!cave) + continue; + } + *tags |= (1 << i); + } + } +} + enum number_type { NEITHER, FLOAT @@ -1033,6 +1050,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) if (MATCH(".number", get_index, &dive->number)) return; + if (MATCH(".tags", divetags, &dive->dive_tags)) + return; if (MATCH(".tripflag", get_tripflag, &dive->tripflag)) return; if (MATCH(".date", divedate, &dive->when)) @@ -1577,15 +1596,12 @@ void parse_xml_buffer(const char *url, const char *buffer, int size, } reset_all(); dive_start(); -#ifdef XSLT doc = test_xslt_transforms(doc, error); -#endif traverse(xmlDocGetRootElement(doc)); dive_end(); xmlFreeDoc(doc); } -#ifdef SQLITE3 extern int dm4_events(void *handle, int columns, char **data, char **column) { event_start(); @@ -1674,8 +1690,6 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) float *profileBlob; unsigned char *tempBlob; int *pressureBlob; - time_t when; - struct tm *tm; char *err = NULL; char get_events_template[] = "select * from Mark where DiveId = %d"; char get_events[64]; @@ -1683,15 +1697,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) dive_start(); cur_dive->number = atoi(data[0]); - /* Suunto saves time in 100 nano seconds, we'll need the time in - * seconds. - */ - when = (time_t)(atol(data[1]) / 10000000); - tm = localtime(&when); - - /* Suunto starts counting time in year 1, we need epoch */ - tm->tm_year -= 1969; - cur_dive->when = mktime(tm); + cur_dive->when = (time_t)(atol(data[1])); if (data[2]) utf8_string(data[2], &cur_dive->notes); @@ -1702,8 +1708,10 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) * Duration = data[3] * DiveTime = data[15] */ + if (data[3]) + cur_dive->duration.seconds = atoi(data[3]); if (data[15]) - cur_dive->duration.seconds = atoi(data[15]); + cur_dive->dc.duration.seconds = atoi(data[15]); /* * TODO: the deviceid hash should be calculated here. @@ -1720,11 +1728,11 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) settings_end(); if (data[6]) - cur_dive->maxdepth.mm = atof(data[6]) * 1000; + cur_dive->dc.maxdepth.mm = atof(data[6]) * 1000; if (data[8]) - cur_dive->airtemp.mkelvin = (atoi(data[8]) + 273.15) * 1000; + cur_dive->dc.airtemp.mkelvin = (atoi(data[8]) + 273.15) * 1000; if (data[9]) - cur_dive->watertemp.mkelvin = (atoi(data[9]) + 273.15) * 1000; + cur_dive->dc.watertemp.mkelvin = (atoi(data[9]) + 273.15) * 1000; /* * TODO: handle multiple cylinders @@ -1749,7 +1757,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) cylinder_end(); if (data[14]) - cur_dive->surface_pressure.mbar = (atoi(data[14]) * 1000); + cur_dive->dc.surface_pressure.mbar = (atoi(data[14]) * 1000); interval = data[16] ? atoi(data[16]) : 0; profileBlob = (float *)data[17]; @@ -1761,7 +1769,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) if (profileBlob) cur_sample->depth.mm = profileBlob[i] * 1000; else - cur_sample->depth.mm = cur_dive->maxdepth.mm; + cur_sample->depth.mm = cur_dive->dc.maxdepth.mm; if (tempBlob) cur_sample->temperature.mkelvin = (tempBlob[i] + 273.15) * 1000; @@ -1792,18 +1800,18 @@ extern int dm4_dive(void *param, int columns, char **data, char **column) */ return SQLITE_OK; } -#endif int parse_dm4_buffer(const char *url, const char *buffer, int size, struct dive_table *table, GError **error) { -#ifdef SQLITE3 int retval; char *err = NULL; sqlite3 *handle; target_table = table; - char get_dives[] = "select D.DiveId,StartTime,Note,Duration,SourceSerialNumber,Source,MaxDepth,SampleInterval,StartTemperature,BottomTemperature,D.StartPressure,D.EndPressure,Size,CylinderWorkPressure,SurfacePressure,DiveTime,SampleInterval,ProfileBlob,TemperatureBlob,PressureBlob,Oxygen,Helium,MIX.StartPressure,MIX.EndPressure FROM Dive AS D JOIN DiveMixture AS MIX ON D.DiveId=MIX.DiveId"; + /* StartTime is converted from Suunto's nano seconds to standard + * time. We also need epoch, not seconds since year 1. */ + char get_dives[] = "select D.DiveId,StartTime/10000000-62135596800,Note,Duration,SourceSerialNumber,Source,MaxDepth,SampleInterval,StartTemperature,BottomTemperature,D.StartPressure,D.EndPressure,Size,CylinderWorkPressure,SurfacePressure,DiveTime,SampleInterval,ProfileBlob,TemperatureBlob,PressureBlob,Oxygen,Helium,MIX.StartPressure,MIX.EndPressure FROM Dive AS D JOIN DiveMixture AS MIX ON D.DiveId=MIX.DiveId"; retval = sqlite3_open(url,&handle); @@ -1820,7 +1828,6 @@ int parse_dm4_buffer(const char *url, const char *buffer, int size, } sqlite3_close(handle); -#endif return 0; } @@ -1834,8 +1841,6 @@ void parse_xml_exit(void) xmlCleanupParser(); } -#ifdef XSLT - /* Maybe we'll want a environment variable that can override this.. */ static const char *xslt_path = XSLT ":xslt:."; @@ -1936,4 +1941,3 @@ static xmlDoc *test_xslt_transforms(xmlDoc *doc, GError **error) } return doc; } -#endif |