diff options
-rw-r--r-- | divelist.c | 4 | ||||
-rw-r--r-- | parse-xml.c | 63 | ||||
-rw-r--r-- | xslt/jdivelog2subsurface.xslt | 99 |
3 files changed, 126 insertions, 40 deletions
diff --git a/divelist.c b/divelist.c index f664cde49..86e7daf57 100644 --- a/divelist.c +++ b/divelist.c @@ -292,6 +292,8 @@ static gint nitrox_sort_func(GtkTreeModel *model, return a_he - b_he; } +#define UTF8_ELLIPSIS "\xE2\x80\xA6" + static void nitrox_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, @@ -315,7 +317,7 @@ static void nitrox_data_func(GtkTreeViewColumn *col, if (o2 == o2low) snprintf(buffer, sizeof(buffer), "%d", o2); else - snprintf(buffer, sizeof(buffer), "%d-%d", o2low, o2); + snprintf(buffer, sizeof(buffer), "%d" UTF8_ELLIPSIS "%d", o2low, o2); else strcpy(buffer, "air"); diff --git a/parse-xml.c b/parse-xml.c index 82b10a47e..4d8568997 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -4,6 +4,8 @@ #include <stdlib.h> #include <errno.h> #include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> #define __USE_XOPEN #include <time.h> #include <libxml/parser.h> @@ -1417,11 +1419,70 @@ static void reset_all(void) import_source = UNKNOWN; } +struct memblock { + void *buffer; + size_t size; +}; + +static int readfile(const char *filename, struct memblock *mem) +{ + int ret, fd = open(filename, O_RDONLY); + struct stat st; + + mem->buffer = NULL; + mem->size = 0; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return fd; + ret = fstat(fd, &st); + if (ret < 0) + goto out; + ret = -EINVAL; + if (!S_ISREG(st.st_mode)) + goto out; + ret = 0; + if (!st.st_size) + goto out; + mem->buffer = malloc(st.st_size); + ret = -1; + errno = ENOMEM; + if (!mem->buffer) + goto out; + mem->size = st.st_size; + ret = read(fd, mem->buffer, mem->size); + if (ret < 0) + goto free; + if (ret == mem->size) + goto out; + errno = EIO; + ret = -1; +free: + free(mem->buffer); + mem->buffer = NULL; + mem->size = 0; +out: + close(fd); + return ret; +} + void parse_xml_file(const char *filename, GError **error) { xmlDoc *doc; + struct memblock mem; + + if (readfile(filename, &mem) < 0) { + fprintf(stderr, "Failed to read '%s'.\n", filename); + if (error) { + *error = g_error_new(g_quark_from_string("subsurface"), + DIVE_ERROR_PARSE, + "Failed to read '%s'", + filename); + } + return; + } - doc = xmlReadFile(filename, NULL, 0); + doc = xmlReadMemory(mem.buffer, mem.size, filename, NULL, 0); if (!doc) { fprintf(stderr, "Failed to parse '%s'.\n", filename); if (error != NULL) diff --git a/xslt/jdivelog2subsurface.xslt b/xslt/jdivelog2subsurface.xslt index 73b4590fb..e2f40c560 100644 --- a/xslt/jdivelog2subsurface.xslt +++ b/xslt/jdivelog2subsurface.xslt @@ -66,13 +66,10 @@ <notes> <xsl:if test="DiveActivity != ''"> - <xsl:value-of select="DiveActivity"/> +Diveactivity: <xsl:value-of select="DiveActivity"/> </xsl:if> - <xsl:if test="Comment != ''"> - <xsl:if test="DiveActivity != ''"> - <xsl:value-of select="': '"/> - </xsl:if> - <xsl:value-of select="Comment"/> + <xsl:if test="DiveType != ''"> +Divetype: <xsl:value-of select="DiveType"/> </xsl:if> <xsl:if test="Equipment/Visibility != ''"> Visibility: <xsl:value-of select="Equipment/Visibility"/> @@ -86,41 +83,51 @@ Gloves: <xsl:value-of select="Equipment/Gloves"/> <xsl:if test="Equipment/Weight != ''"> Weight: <xsl:value-of select="Equipment/Weight"/> </xsl:if> + <xsl:if test="Comment != ''"> +Comment: <xsl:value-of select="Comment"/> + </xsl:if> </notes> <!-- cylinder --> - <xsl:variable name="o2"> - <xsl:choose> - <xsl:when test="DIVE/GASES/MIX/O2 != ''"> - <xsl:value-of select="concat(DIVE/GASES/MIX/O2*100, '%')"/> - </xsl:when> - <xsl:otherwise>21.0%</xsl:otherwise> - </xsl:choose> - </xsl:variable> - <xsl:variable name="size"> - <xsl:choose> - <xsl:when test="Equipment/Tanks/Tank/MIX/TANK/TANKVOLUME != ''"> - <xsl:value-of select="concat(Equipment/Tanks/Tank/MIX/TANK/TANKVOLUME * 1000, ' l')"/> - </xsl:when> - <xsl:otherwise>0 l</xsl:otherwise> - </xsl:choose> - </xsl:variable> - <xsl:variable name="start"> - <xsl:variable name="number" select="Equipment/Tanks/Tank/MIX/TANK/PSTART"/> - <xsl:call-template name="pressure"> - <xsl:with-param name="number" select="$number"/> - <xsl:with-param name="units" select="$units"/> - </xsl:call-template> - </xsl:variable> - <xsl:variable name="end"> - <xsl:variable name="number" select="Equipment/Tanks/Tank/MIX/TANK/PEND"/> - <xsl:call-template name="pressure"> - <xsl:with-param name="number" select="$number"/> - <xsl:with-param name="units" select="$units"/> - </xsl:call-template> - </xsl:variable> - - <cylinder o2="{$o2}" size="{$size}" start="{$start}" end="{$end}"/> + <xsl:for-each select="Equipment/Tanks/Tank"> + <cylinder> + <xsl:attribute name="o2"> + <xsl:choose> + <xsl:when test="MIX/O2 != ''"> + <xsl:value-of select="concat(MIX/O2*100, '%')"/> + </xsl:when> + <xsl:otherwise>21.0%</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <xsl:if test="MIX/HE != '0.0'"> + <xsl:attribute name="he"> + <xsl:value-of select="concat(MIX/HE*100, '%')"/> + </xsl:attribute> + </xsl:if> + <xsl:attribute name="size"> + <xsl:choose> + <xsl:when test="MIX/TANK/TANKVOLUME != ''"> + <xsl:value-of select="concat(MIX/TANK/TANKVOLUME * 1000, ' l')"/> + </xsl:when> + <xsl:otherwise>0 l</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <xsl:attribute name="start"> + <xsl:variable name="number" select="MIX/TANK/PSTART"/> + <xsl:call-template name="pressure"> + <xsl:with-param name="number" select="$number"/> + <xsl:with-param name="units" select="$units"/> + </xsl:call-template> + </xsl:attribute> + <xsl:attribute name="end"> + <xsl:variable name="number" select="MIX/TANK/PEND"/> + <xsl:call-template name="pressure"> + <xsl:with-param name="number" select="$number"/> + <xsl:with-param name="units" select="$units"/> + </xsl:call-template> + </xsl:attribute> + </cylinder> + </xsl:for-each> <!-- end cylinder --> <!-- DELTA is the sample interval --> @@ -156,6 +163,22 @@ Weight: <xsl:value-of select="Equipment/Weight"/> </xsl:for-each> <!-- end events --> + <!-- gas change --> + <xsl:for-each select="DIVE/SAMPLES/SWITCH"> + <event name="gaschange"> + <xsl:attribute name="time"> + <xsl:call-template name="timeConvert"> + <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/> + <xsl:with-param name="units" select="'si'"/> + </xsl:call-template> + </xsl:attribute> + <xsl:attribute name="value"> + <xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2 * 100" /> + </xsl:attribute> + </event> + </xsl:for-each> + <!-- end gas change --> + <!-- dive sample - all the depth and temp readings --> <xsl:for-each select="DIVE/SAMPLES/D"> <xsl:variable name="timeSec" select="(position() - 1) * $delta"/> |