source: trunk/xmlwf.c @ 1619

Last change on this file since 1619 was 878, checked in by lindanl, 8 years ago

Well-formedness checking.

File size: 6.6 KB
Line 
1/*  markup_stats.c - parabix demo program
2    Copyright (c) 2007, Robert D. Cameron.
3    Licensed to the public under the Open Software License 3.0.
4    Licensed to International Characters, Inc., under the Academic
5    Free License 3.0.
6
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <errno.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <string>
16#include <iostream>
17using namespace std;
18
19#include "lib/perflib/perfsec.h"
20
21#ifdef BUFFER_PROFILING
22        BOM_Table * parser_timer;
23#endif
24
25#define ON 1
26#define OFF 2
27
28#define TEMPLATED_SIMD_LIB
29
30
31#define VALIDATION_MODE OFF
32
33//#include "src/ilax.h"
34#include "src/engine.h"
35
36#ifndef REPEAT_RUNS
37#define REPEAT_RUNS 10
38#endif
39
40/* Internals */
41#include "src/xmlmodel.h"
42#include "src/xml_error.h"
43#include "src/bitplex.h"
44#include "src/byteplex.h"
45#include "src/xmldecl.h"
46#include "src/bitlex.h"
47
48
49#include "src/xmlmodel.c"
50#include "src/xml_error.c"
51#include "src/bitplex.c"
52#include "src/byteplex.c"
53#include "src/xmldecl.c"
54#include "src/bitlex.c"
55#include "src/engine.c"
56#include "src/symtab.c"
57
58/* Global declarations of parsing engine. */
59Parser_Interface<UTF_8> * parser;
60
61/* Global declarations for statistics. */
62
63
64/* Action routine for an XML comment in "<!--"  "-->" brackets. */
65template<>
66inline void Parser_Interface<UTF_8>::Comment_action(unsigned char * item, int lgth) {
67
68}
69
70/* Action routine called upon recognizing "<![CDATA[" to start a CDATA section. */
71template<>
72inline void Parser_Interface<UTF_8>::CDATA_start_action(unsigned char * CDATA_ptr){
73
74}
75
76/* Action routine called upon recognizing "]]>" to end a CDATA section. */
77template<>
78inline void Parser_Interface<UTF_8>::CDATA_end_action(unsigned char * CDATA_end_ptr) {
79
80}
81
82/* Action routine for an XML processing instruction enclosed in "<?" and "?>" brackets. */
83template<>
84inline void Parser_Interface<UTF_8>::PI_action(unsigned char * item, int lgth) {
85
86}
87
88/* Action routine for an empty element enclosed in "<" and "/>" brackets. */
89template<>
90inline void Parser_Interface<UTF_8>::EmptyElement_action(unsigned char * item, int lgth) {
91
92}
93
94/* Action routine for a start tag enclosed in "<" and ">" brackets. */
95template<>
96inline void Parser_Interface<UTF_8>::StartTag_action(unsigned char * item, int lgth) {
97
98}
99
100/* Action routine for an end tag enclosed in "</" and ">" brackets. */
101template<>
102inline void Parser_Interface<UTF_8>::EndTag_action(unsigned char * item, int lgth) {
103
104}
105
106/* Action routine for an error item */
107template<>
108inline void Parser_Interface<UTF_8>::Error_action(unsigned char * item, int lgth) {
109        fprintf(stderr, "Error: illegal markup of length %i.\n", lgth);
110}
111
112/* Action routine for a text item */
113template<>
114inline void Parser_Interface<UTF_8>::Text_action(unsigned char * item, int lgth, bool more) {
115
116}
117
118template<>
119inline void Parser_Interface<UTF_8>::Reference_action(unsigned char * item, int lgth) {
120
121}
122
123
124
125
126/* Three action routines for markup components are defined as follows.
127|ElementName_action| is the action routine called upon recognition of
128an element name immediately after the opening angle bracket of a start
129tag or empty element tag.  {\bf OR MAYBE THIS SHOULD BE DEFERRED UNTIL
130AFTER ATTRIBUTE PROCESSING SO THAT NAMESPACES ARE SET?}
131It is called with two parameters identifying the
132first and last character positions of the expected XML_name.
133Similarly, |PI_Target_action| is the action routine called upon recognition
134of the XML Name that occurs immediately after the opening "<?"
135delimiter of a processing instruction.
136
137 The third action routine for markup components is Attribute_Value_action,
138which takes three parameters rather than two.  {\bf OR POSSIBLY JUST
139THE QUOTE MARK ITEMS, RELYING ON THE END OF THE LAST COMPONENT PROCESSED
140TO MARK THE SPACE BEFORE THE ATT NAME.- REQUIRES ELEMENT_NAME_ACTION}
141*/
142
143/* Semantic action routines for markup components. */
144/* Action routine for an element name occurring immediately after the
145   opening "<" of a start tag or empty element tag. */
146template<>
147inline void Parser_Interface<UTF_8>::ElementName_action(unsigned char * item, int lgth) {
148}
149
150/* Action routine for a processing instruction target name occurring immediately
151   after the opening "<?" of a processing instruction. */
152template<>
153inline void Parser_Interface<UTF_8>::PI_Target_action(unsigned char * item, int lgth) {
154}
155
156/* Action routine for an individual attribute/value pair occurring in
157   a element start tag or an empty element tag. */
158template<>
159inline void Parser_Interface<UTF_8>::AttributeValue_action(unsigned char * name, int name_lgth,
160                                 unsigned char * val, int val_lgth) {
161
162}
163
164/* Action routine for an individual attribute/value pair occurring in
165   a element start tag or an empty element tag. */
166template<>
167inline void Parser_Interface<UTF_8>::Namespace_action(unsigned char * name, int name_lgth,
168                             unsigned char * URI, int URI_lgth) {
169
170}
171
172
173template<>
174void Parser_Interface<UTF_8>::FinalizeBuffer_action() {
175
176
177}
178
179
180template<>
181inline void Parser_Interface<UTF_8>::DocumentStart_action() {
182
183}
184
185template<>
186inline void Parser_Interface<UTF_8>::DocumentEnd_action() {
187
188}
189
190template<>
191inline void Parser_Interface<UTF_8>::Doctype_action(unsigned char * item, int lgth) {
192
193}
194
195template<>
196inline void Parser_Interface<UTF_8>::PEReference_action(unsigned char * item, int lgth) {
197}
198
199
200template<>
201inline void Parser_Interface<UTF_8>::ExtSubsetDecl_action(unsigned char * item, int lgth) {
202
203}
204
205template<>
206inline void Parser_Interface<UTF_8>::Prolog_action(unsigned char * item, int lgth) {
207
208}
209
210#include <sched.h>
211
212int
213main(int argc, char * argv[]) {
214
215        if (argc != 2) {
216        printf("Usage: %s <filename>\n", argv[0]);
217                exit(-1);
218        }
219
220        char * src_filename = argv[1];
221        char * cmdline = new char[strlen(argv[0]) + strlen(argv[1]) +1 +1];
222        strcat(cmdline, argv[0]);
223        strcat(cmdline," ");
224        strcat(cmdline,argv[1]);
225
226
227        // Read the entire file into a memory buffer
228        FILE * src_file;
229        struct stat fileinfo;
230        int src_filesize;
231
232        // open file and fstat
233        src_file = fopen ( src_filename , "rb" );
234        if (!src_file) {
235                fprintf(stderr, "Cannot open '%s'. Terminating the process ...\n", src_filename);
236                exit(-1);
237        }
238        if(fstat(fileno(src_file), &fileinfo)!=0) {
239                fprintf(stderr, "Cannot fstat '%s'. Terminating the process ...\n", src_filename);
240                exit(-1);
241        }
242
243        src_filesize = fileinfo.st_size;
244
245        fclose (src_file);
246
247        PERF_SEC_INIT(parser_timer);
248
249        for (int run = 0; run < REPEAT_RUNS; run++) {
250
251
252                parser = Parser_Interface<UTF_8>::ParserFactory(src_filename);
253
254                PERF_SEC_START(parser_timer);
255
256                parser->Parse_Prolog();
257                parser->Parse_DocumentContent();
258
259                PERF_SEC_END(parser_timer, src_filesize);
260
261                delete parser;
262//              printf("Run %i complete.\n", run);
263
264        }
265
266        PERF_SEC_DUMP(parser_timer);
267
268        PERF_SEC_DESTROY(parser_timer);
269
270        return(0);
271}
Note: See TracBrowser for help on using the repository browser.