summaryrefslogtreecommitdiffstats
Unidiff
-rw-r--r--src/load/load_asn.c173
-rw-r--r--src/load/load_asn.h24
-rw-r--r--src/load/load_features.c167
-rw-r--r--src/load/load_features.h12
4 files changed, 376 insertions, 0 deletions
diff --git a/src/load/load_features.c b/src/load/load_features.c
new file mode 100644
index 0000000..b18031a
--- a/dev/null
+++ b/src/load/load_features.c
@@ -0,0 +1,167 @@
1#include "load_features.h"
2#include <libxml/parser.h>
3#include <stdbool.h>
4#include <asn.h>
5#include <objgbseq.h>
6
7/*
8 * An NCBI GBSeq structure to hold the data for the current record.
9 */
10GBSeqPtr g;
11
12bool in_element;
13
14static void
15lf_startDocument (void *ctx ATTRIBUTE_UNUSED)
16{
17 printf ("SAX.startDocument()\n");
18
19 return;
20}
21
22static void
23lf_endDocument (void *ctx ATTRIBUTE_UNUSED)
24{
25 printf ("SAX.endDocument()\n");
26
27 return;
28}
29
30static xmlEntityPtr
31lf_getEntity (void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
32{
33 printf("SAX.getEntity(%s)\n", name);
34
35 return (NULL);
36}
37
38static void
39lf_startElement(void *ctx ATTRIBUTE_UNUSED,
40 const xmlChar *name, const xmlChar **atts)
41{
42 int i;
43
44 fprintf(stdout, "SAX.startElement(%s", (char *) name);
45 if (atts != NULL) {
46 for (i = 0;(atts[i] != NULL);i++) {
47 fprintf(stdout, ", %s='", atts[i++]);
48 if (atts[i] != NULL)
49 fprintf(stdout, "%s'", atts[i]);
50 }
51 }
52 fprintf(stdout, ")\n");
53
54 in_element = true;
55
56 return;
57}
58
59static void
60lf_endElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
61{
62 printf("SAX.endElement(%s)\n", (char *) name);
63 in_element = false;
64
65 return;
66}
67
68static void
69lf_characters(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
70{
71 if (!in_element)
72 return;
73
74 char output[40];
75 int i;
76
77 for (i = 0;(i<len) && (i < 30);i++)
78 output[i] = ch[i];
79 output[i] = 0;
80
81 printf("SAX.characters(%s, %d)\n", output, len);
82}
83
84/*
85 * 1. Parse and load the XML file into memory.
86 * 2. Insert the XML into HDF5.
87 * For an example of parsing XML with libxml2 and SAX see:
88 * [http://git.gnome.org/browse/libxml2/tree/testSAX.c].
89 */
90void
91load_features (hid_t file_id, const char* file_name)
92{
93 g = GBSeqNew ();
94
95 LIBXML_TEST_VERSION;
96
97 in_element = false;
98
99 static xmlSAXHandler emptySAXHandlerStruct = {
100 NULL, /* internalSubset */
101 NULL, /* isStandalone */
102 NULL, /* hasInternalSubset */
103 NULL, /* hasExternalSubset */
104 NULL, /* resolveEntity */
105 lf_getEntity, /* getEntity */
106 NULL, /* entityDecl */
107 NULL, /* notationDecl */
108 NULL, /* attributeDecl */
109 NULL, /* elementDecl */
110 NULL, /* unparsedEntityDecl */
111 NULL, /* setDocumentLocator */
112 lf_startDocument, /* startDocument */
113 lf_endDocument, /* endDocument */
114 lf_startElement, /* startElement */
115 lf_endElement, /* endElement */
116 NULL, /* reference */
117 lf_characters, /* characters */
118 NULL, /* ignorableWhitespace */
119 NULL, /* processingInstruction */
120 NULL, /* comment */
121 NULL, /* xmlParserWarning */
122 NULL, /* xmlParserError */
123 NULL, /* xmlParserError */
124 NULL, /* getParameterEntity */
125 NULL, /* cdataBlock; */
126 NULL, /* externalSubset; */
127 1,
128 NULL,
129 NULL, /* startElementNs */
130 NULL, /* endElementNs */
131 NULL /* xmlStructuredErrorFunc */
132 };
133
134 static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
135
136 FILE *f = fopen (file_name, "r");
137
138 if (f != NULL)
139 {
140 int ret;
141 char chars[10];
142 xmlParserCtxtPtr ctxt;
143
144 ret = fread (chars, 1, 4, f);
145 if (ret > 0)
146 {
147 ctxt = xmlCreatePushParserCtxt (emptySAXHandler, NULL,
148 chars, ret, file_name);
149 while ((ret = fread(chars, 1, 3, f)) > 0)
150 {
151 xmlParseChunk (ctxt, chars, ret, 0);
152 }
153 xmlParseChunk (ctxt, chars, 0, 1);
154 xmlFreeParserCtxt(ctxt);
155 }
156 fclose (f);
157 }
158 else
159 {
160 xmlGenericError (xmlGenericErrorContext,
161 "Cannot read file.");
162 }
163
164 GBSeqFree (g);
165
166 return;
167}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.