X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;h=173314dd42161ff28af7c7374bdf80e23ee6a706;hb=ed1ce8ebc8590533291a9c5d6460f8d1c9f857dd;hp=e920a11f6f0d798b18900ccb23317c95c8ec5162;hpb=81fddfa67e779c8d378eee4c57fd9f201e15f96f;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index e920a11..173314d 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -39,6 +39,65 @@ void record_dive(struct dive *dive) dive_table.nr = nr+1; } +static void delete_dive_renumber(struct dive **dives, int i, int nr) +{ + struct dive *dive = dives[i]; + int number = dive->number, j; + + if (!number) + return; + + /* + * Check that all numbered dives after the deleted + * ones are consecutive, return without renumbering + * if that is not the case. + */ + for (j = i+1; j < nr; j++) { + struct dive *next = dives[j]; + if (!next->number) + break; + number++; + if (next->number != number) + return; + } + + /* + * Ok, we hit the end of the dives or a unnumbered + * dive - renumber. + */ + for (j = i+1 ; j < nr; j++) { + struct dive *next = dives[j]; + if (!next->number) + break; + next->number--; + } +} + +/* + * Remove a dive from the dive_table array + */ +void delete_dive(struct dive *dive) +{ + int nr = dive_table.nr, i; + struct dive **dives = dive_table.dives; + + /* + * Stupid. We know the dive table is sorted by date, + * we could do a binary lookup. Sue me. + */ + for (i = 0; i < nr; i++) { + struct dive *d = dives[i]; + if (d != dive) + continue; + /* should we re-number? */ + delete_dive_renumber(dives, i, nr); + memmove(dives+i, dives+i+1, sizeof(struct dive *)*(nr-i-1)); + dives[nr] = NULL; + dive_table.nr = nr-1; + break; + } +} + static void start_match(const char *type, const char *name, char *buffer) { if (verbose > 2) @@ -588,6 +647,7 @@ static int uddf_fill_sample(struct sample *sample, const char *name, int len, ch return MATCH(".divetime", sampletime, &sample->time) || MATCH(".depth", depth, &sample->depth) || MATCH(".temperature", temperature, &sample->temperature) || + MATCH(".tankpressure", pressure, &sample->cylinderpressure) || 0; } @@ -1040,6 +1100,10 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf) return; if (MATCH(".location", utf8_string, &dive->location)) return; + if (MATCH(".suit", utf8_string, &dive->suit)) + return; + if (MATCH(".divesuit", utf8_string, &dive->suit)) + return; if (MATCH(".notes", utf8_string, &dive->notes)) return; if (MATCH(".divemaster", utf8_string, &dive->divemaster)) @@ -1403,7 +1467,11 @@ static xsltStylesheetPtr try_get_stylesheet(const char *path, int len, const cha static xsltStylesheetPtr get_stylesheet(const char *name) { - const char *path = xslt_path, *next; + const char *path, *next; + + path = getenv("SUBSURFACE_XSLT_PATH"); + if (!path) + path = xslt_path; do { int len;