/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <sys/time.h>

#include <vtdGen.h>
#include <vtdNav.h>
#include <autoPilot.h>


#define PREPARE_XML
#include "tools.h"

struct exception_context the_exception_context[1];

int pre_mode = 0;
VTDGen *vg = NULL;
char *idxbuf;
int idxlen;

void initXML(struct TestData *td) {
//    if (getenv("allow_deferring")) deferring_mode = 1;
    if (getenv("allow_preprocessing")) pre_mode = 1;

    vg = createVTDGen();
}

void releaseXML(struct TestData *td) {
    freeVTDGen(vg);
}

void preparseXML(struct TestData *td, unsigned long iter) {
    FILE *f;
    if (pre_mode) {
	setDoc(vg,td->xml,td->xmllen);
	parse(vg,1);
	
	f = fopen("/tmp/vtdxml.test", "w");
	if (!f) {
	    printf("Can't write temporary file\n");
	    exit(1);
	}
	writeIndex(vg, f);
	fclose(f);
	idxbuf = ReadFile("/tmp/vtdxml.test");
	clear(vg);
    }
}

void postparseXML(struct TestData *td, unsigned long iter) {
    if (pre_mode) {
	free(idxbuf);
    }
}


void parseXML(struct TestData *td, unsigned long iter) {
    VTDNav *vn;

    if (pre_mode) {
	vn = loadIndex2(vg, idxbuf + sizeof(unsigned long), (*(unsigned long*)idxbuf));
    } else {
	// This destructs original string
	setDoc(vg,td->xml,td->xmllen);
	parse(vg,1);
	vn = getNav(vg);
    }
    
    freeVTDNav(vn);
    //clear(vg); 	// done by getNav

}


int main(int argc, char *argv[]) {
    return Test(argc,argv);
}