X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=parse-xml.c;h=761cc3b41464ed7188f235a645cdff90c3219816;hb=058b84cca0f876bf2221e248e4854905b0705210;hp=552786b7aa58e3f780e08ce45bd87e80f1cfbbcf;hpb=1cbe2444cc6c0c8da9e730561914986506d83770;p=ext%2Fsubsurface.git diff --git a/parse-xml.c b/parse-xml.c index 552786b..761cc3b 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -39,6 +39,40 @@ 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 */ @@ -55,6 +89,8 @@ void delete_dive(struct dive *dive) 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; @@ -1426,7 +1462,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;