summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c67
1 files changed, 21 insertions, 46 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 2a10792f8..da150d27e 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -156,7 +156,8 @@ const struct units IMPERIAL_units = {
/*
* Dive info as it is being built up..
*/
-static struct dive *cur_dive, *cur_trip = NULL;
+static struct dive *cur_dive;
+static dive_trip_t *cur_trip = NULL;
static struct sample *cur_sample;
static struct {
int active;
@@ -175,40 +176,10 @@ static enum import_source {
UDDF,
} import_source;
-time_t utc_mktime(struct tm *tm)
-{
- static const int mdays[] = {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
- };
- int year = tm->tm_year;
- int month = tm->tm_mon;
- int day = tm->tm_mday;
-
- /* First normalize relative to 1900 */
- if (year < 70)
- year += 100;
- else if (year > 1900)
- year -= 1900;
-
- /* Normalized to Jan 1, 1970: unix time */
- year -= 70;
-
- if (year < 0 || year > 129) /* algo only works for 1970-2099 */
- return -1;
- if (month < 0 || month > 11) /* array bounds */
- return -1;
- if (month < 2 || (year + 2) % 4)
- day--;
- if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0)
- return -1;
- return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +
- tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec;
-}
-
static void divedate(char *buffer, void *_when)
{
int d,m,y;
- time_t *when = _when;
+ timestamp_t *when = _when;
int success = 0;
success = cur_tm.tm_sec | cur_tm.tm_min | cur_tm.tm_hour;
@@ -234,7 +205,7 @@ static void divedate(char *buffer, void *_when)
static void divetime(char *buffer, void *_when)
{
int h,m,s = 0;
- time_t *when = _when;
+ timestamp_t *when = _when;
if (sscanf(buffer, "%d:%d:%d", &h, &m, &s) >= 2) {
cur_tm.tm_hour = h;
@@ -251,7 +222,7 @@ static void divedatetime(char *buffer, void *_when)
{
int y,m,d;
int hr,min,sec;
- time_t *when = _when;
+ timestamp_t *when = _when;
if (sscanf(buffer, "%d-%d-%d %d:%d:%d",
&y, &m, &d, &hr, &min, &sec) == 6) {
@@ -542,8 +513,10 @@ static void get_tripflag(char *buffer, void *_tf)
*tf = TF_NONE;
for (i = NO_TRIP; i < NUM_TRIPFLAGS; i++)
- if(! strcmp(buffer, tripflag_names[i]))
+ if(! strcmp(buffer, tripflag_names[i])) {
*tf = i;
+ break;
+ }
}
static void centibar(char *buffer, void *_pressure)
@@ -822,7 +795,7 @@ static void uemis_date_unit(char *buffer, void *_unused)
/* Modified julian day, yay! */
static void uemis_date_time(char *buffer, void *_when)
{
- time_t *when = _when;
+ timestamp_t *when = _when;
union int_or_float val;
switch (integer_or_float(buffer, &val)) {
@@ -847,7 +820,7 @@ 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;
+ timestamp_t *when = _when;
signed char tz = atoi(buffer);
*when += tz * 3600;
@@ -857,7 +830,7 @@ static void uemis_time_zone(char *buffer, void *_when)
static void uemis_ts(char *buffer, void *_when)
{
struct tm tm;
- time_t *when = _when;
+ timestamp_t *when = _when;
memset(&tm, 0, sizeof(tm));
sscanf(buffer,"%d-%d-%dT%d:%d:%d",
@@ -983,7 +956,7 @@ static void uddf_datetime(char *buffer, void *_when)
{
char c;
int y,m,d,hh,mm,ss;
- time_t *when = _when;
+ timestamp_t *when = _when;
struct tm tm = { 0 };
int i;
@@ -1152,21 +1125,23 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
}
/* We're in the top-level trip xml. Try to convert whatever value to a trip value */
-static void try_to_fill_trip(struct dive **divep, const char *name, char *buf)
+static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char *buf)
{
int len = strlen(name);
start_match("trip", name, buf);
- struct dive *dive = *divep;
+ dive_trip_t *dive_trip = *dive_trip_p;
- if (MATCH(".date", divedate, &dive->when))
+ if (MATCH(".date", divedate, &dive_trip->when))
return;
- if (MATCH(".time", divetime, &dive->when))
+ if (MATCH(".time", divetime, &dive_trip->when)) {
+ dive_trip->when_from_file = dive_trip->when;
return;
- if (MATCH(".location", utf8_string, &dive->location))
+ }
+ if (MATCH(".location", utf8_string, &dive_trip->location))
return;
- if (MATCH(".notes", utf8_string, &dive->notes))
+ if (MATCH(".notes", utf8_string, &dive_trip->notes))
return;
nonmatch("trip", name, buf);
@@ -1212,7 +1187,7 @@ static void trip_start(void)
{
if (cur_trip)
return;
- cur_trip = alloc_dive();
+ cur_trip = calloc(sizeof(dive_trip_t),1);
memset(&cur_tm, 0, sizeof(cur_tm));
}