/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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "asm-xml.h"

#include "tools.h"

#define chunkSize 16777216

AXClassContext  classContext;
AXElementClass* docClass;

inline double walker_process_node(AXElement *cur_node, int siblings) {
    AXElement *node;
    int i, size;
    double res = 0;

/*
    printf("Node: %i\nSubnodes: ", cur_node->id);
    for (i=0,node = cur_node->firstChild; node; node = node->nextSibling) {
	printf("%i ", node->id);
    }
    printf("= %i\n", i);
*/
    switch (cur_node->id) {
	case 1:
	    if (siblings<4) return 0;
	    size = 2;
	break;
	case 2:
	case 3:
	    size = 4;
	break;
	default:
	    return 0;
    }

//    printf("Node: %i, size: %i, siblings: %i\n", cur_node->id, size, siblings);

    for (i=0; i<size; i++) {
//	char tmp[256];
//	int len = cur_node->attributes[i].limit - cur_node->attributes[i].begin;
//	printf("%p %p %i\n", cur_node->attributes[i].begin, cur_node->attributes[i].limit, len);
	res += get_value_0(cur_node->attributes[i].begin, cur_node->attributes[i].limit - cur_node->attributes[i].begin);
//	strncpy(tmp, cur_node->attributes[i].begin, len);tmp[len]=0;
//	puts(tmp);
    }
    
    return res;
}

double walker(AXElement *node) {
    int i = 0;
    double res = 0;
    AXElement *cur_node;

    for (cur_node = node; cur_node; cur_node = cur_node->nextSibling) {
	if (++i>3) break;
    }

//    printf("Node %i Subnodes: %i\n", node->id, i);

    for (cur_node = node; cur_node; cur_node = cur_node->nextSibling) {
	if (cur_node->id) {
	    res += walker_process_node(cur_node,i);
	}
	if (cur_node->firstChild) {
	    res += walker(cur_node->firstChild);
	}
    }
    return res;
}


const char *schema_file = NULL;
void initXML(struct TestData *td) {
    struct stat st;
    char *schema = NULL;
    
    if (!strcmp(td->fn, "xmlgen")) {
	schema = ReadFile("../xml.files/generated.schema");
    } else if (schema_file) {
	if (walk_tree) {
	    printf("Asmxml needs custom code for each schema, therefore nothing but xmlgen is supported\n");
	    exit(1);
	}
	schema = ReadFile(schema_file);
    }

    if (!schema) {
        printf("Schema file is not found\n");
        exit(1);
    }
    
    ax_initialize((void*)malloc, (void*)free);

    int res = ax_initializeClassParser(&classContext);
    if (res) {
	printf("Initialization failed: %i\n", res);
	exit(1);
    }
    
    docClass = ax_classFromString(schema+sizeof(unsigned long), &classContext);
    if( docClass == NULL ) {
	printf("Schema parse is failed\n");
	exit(1);
    }

    free(schema);

}



void releaseXML(struct TestData *td) {
    ax_releaseClassParser(&classContext);
}


void parseXML(struct TestData *td, unsigned long iter) {
    AXParseContext parseContext;
    AXElement *root;
    
    int res = ax_initializeParser(&parseContext, chunkSize);
    if( res != 0 ) {
	printf("Parser initialization is failed\n");
	exit(1);
    }

    root = ax_parse(&parseContext, td->xml, docClass, 1);
    if( root == NULL ) {
	printf("Parsing is failed\n");
	exit(1);
    }
    
    if (walk_tree) {
	double res = walker(root);
//	printf("Sum: %lf\n", res);
    }
    
    ax_releaseParser(&parseContext);
}

int main(int argc, char *argv[]) {
    if (argc > 3) schema_file = argv[3];
    
    return Test(argc,argv);
}