start moving vizml parsing into a new file
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Feb 2020 19:02:59 +0000 (19:02 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Feb 2020 19:02:59 +0000 (19:02 +0000)
src/output/spv/automake.mk
src/output/spv/spv.c
src/output/spv/vizml-decoder.c [new file with mode: 0644]
src/output/spv/vizml-decoder.h [new file with mode: 0644]

index ed952f254c42b76a92526e2a0ddfe63bbb305bea..cfbe0d4e19e6f02925655af99ba70961ac280efe 100644 (file)
@@ -37,7 +37,9 @@ src_output_liboutput_la_SOURCES += \
        src/output/spv/spvbin-helpers.c \
        src/output/spv/spvbin-helpers.h \
        src/output/spv/spvxml-helpers.c \
-       src/output/spv/spvxml-helpers.h
+       src/output/spv/spvxml-helpers.h \
+       src/output/spv/vizml-decoder.c \
+       src/output/spv/vizml-decoder.h
 
 light_binary_in = \
        src/output/spv/binary-parser-generator \
index 1d347fd1ad981ad0c83f278a2a5393328471cded..c3d8ac6dcd1b9cc3941f893baaea426198aa51ff 100644 (file)
@@ -40,7 +40,7 @@
 #include "output/spv/spv-legacy-decoder.h"
 #include "output/spv/spv-light-decoder.h"
 #include "output/spv/structure-xml-parser.h"
-#include "output/spv/vizml-parser.h"
+#include "output/spv/vizml-decoder.h"
 
 #include "gl/c-ctype.h"
 #include "gl/intprops.h"
@@ -840,7 +840,7 @@ pivot_table_open_legacy (struct spv_item *item)
   struct spvxml_context ctx = SPVXML_CONTEXT_INIT (ctx);
   struct spvdx_visualization *v;
   spvdx_parse_visualization (&ctx, xmlDocGetRootElement (doc), &v);
-  error = spvxml_context_finish (&ctx, &v->node_);
+  error = spvxml_context_finish (&ctx, v ? &v->node_ : NULL);
 
   if (!error)
     error = decode_spvdx_table (v, item->subtype, item->legacy_properties,
@@ -915,10 +915,8 @@ spv_open_graph (struct spv_item *item)
       return error;
     }
 
-  struct spvxml_context ctx = SPVXML_CONTEXT_INIT (ctx);
-  struct vizml_visualization *v;
-  vizml_parse_visualization (&ctx, xmlDocGetRootElement (doc), &v);
-  error = spvxml_context_finish (&ctx, &v->node_);
+  if (!error)
+    error = decode_vizml (xmlDocGetRootElement (doc), &data);
 
   if (error)
     {
@@ -931,7 +929,6 @@ spv_open_graph (struct spv_item *item)
     }
 
   spv_data_uninit (&data);
-  vizml_free_visualization (v);
   if (doc)
     xmlFreeDoc (doc);
 
@@ -1140,7 +1137,7 @@ spv_heading_read (struct spv_reader *spv,
   struct spvxml_context ctx = SPVXML_CONTEXT_INIT (ctx);
   struct spvsx_root_heading *root;
   spvsx_parse_root_heading (&ctx, xmlDocGetRootElement (doc), &root);
-  error = spvxml_context_finish (&ctx, &root->node_);
+  error = spvxml_context_finish (&ctx, root ? &root->node_ : NULL);
 
   if (!error && root->page_setup)
     spv->page_setup = decode_page_setup (root->page_setup, file_name);
diff --git a/src/output/spv/vizml-decoder.c b/src/output/spv/vizml-decoder.c
new file mode 100644 (file)
index 0000000..7bb0ace
--- /dev/null
@@ -0,0 +1,37 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "output/spv/vizml-decoder.h"
+
+#include "output/spv/spvxml-helpers.h"
+#include "output/spv/vizml-parser.h"
+
+char * WARN_UNUSED_RESULT
+decode_vizml (xmlNode *input, struct spv_data *data UNUSED)
+{
+  struct spvxml_context ctx = SPVXML_CONTEXT_INIT (ctx);
+  struct vizml_visualization *v;
+  vizml_parse_visualization (&ctx, input, &v);
+  char *error = spvxml_context_finish (&ctx, v ? &v->node_ : NULL);
+  if (error)
+    return error;
+
+  vizml_free_visualization (v);
+
+  return NULL;
+}
diff --git a/src/output/spv/vizml-decoder.h b/src/output/spv/vizml-decoder.h
new file mode 100644 (file)
index 0000000..9e8d29c
--- /dev/null
@@ -0,0 +1,32 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef OUTPUT_VIZML_DECODER_H
+#define OUTPUT_VIZML_DECODER_H 1
+
+/* Visualization Markup Language (VizML) decoder.
+
+   Used by spv.h, not useful directly. */
+
+#include <libxml/xmlreader.h>
+#include "libpspp/compiler.h"
+
+struct spv_data;
+
+char *decode_vizml (xmlNode *input, struct spv_data *)
+  WARN_UNUSED_RESULT;
+
+#endif /* output/spv/vizml-decoder.h */