]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'docs' of git://git.hohndel.org/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 24 Dec 2011 04:23:04 +0000 (20:23 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 24 Dec 2011 04:23:04 +0000 (20:23 -0800)
* 'docs' of git://git.hohndel.org/subsurface:
  Version 0.0.6 of user manual

divelist.c
parse-xml.c
xslt/jdivelog2subsurface.xslt

index f664cde49cf6f0c8f725a8d3f681402a277a7abc..86e7daf571052104710ce8060ace9af34c11a17f 100644 (file)
@@ -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");
 
index 82b10a47e741113428f20e7c671ee595e1442885..4d8568997d835205e8624dd9becef1f6c8f04362 100644 (file)
@@ -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)
index 73b4590fbb6b163c54f0f500917161ea0f8e6905..e2f40c560c5d7fcc4eb135781835d8cbecc39cc6 100644 (file)
 
       <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"/>