annotate TaskManager/Test/test_render/xml.cpp @ 132:e7c80537b6aa

add XML
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 25 Nov 2008 18:19:53 +0900
parents 5c194c71eca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <iostream>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <SDL.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <SDL_opengl.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include <libxml/parser.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "polygon.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 using namespace std;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 char *skip_to_number(char *cont)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10 if (cont == NULL) return(NULL);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 for (;(*cont < '+' || *cont > '9') && (*cont != '\0');cont++) {}
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 if (*cont == '\0')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 fprintf(stderr,"Content data is short\n");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 return(NULL);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 return(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 char *pickup_float(char *cont, float *index)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 int sign=1,exp=1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 float shift=10,val_dec=0,val_int=0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 cont = skip_to_number(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 if (cont == NULL) return(NULL);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 for (;*cont != ' ' && *cont != '\n' && *cont != '\t';cont++)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 if (*cont == '-')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 sign = -1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 else if (*cont == '.')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 shift = 0.1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 else if (*cont >= '0' && *cont <= '9')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 if (shift == 10)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 val_int *= shift;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 val_int += *cont - 48;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46 else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 val_dec += (*cont - 48) * shift;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 shift *= 0.1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 else if (*cont == 'e' || *cont == 'E')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 //cont = pickup_exponent(&exp,cont+1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 if (cont == NULL) return(NULL);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 else if (*cont == '+' || *cont == '/' || *cont == ' ')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 // ignore
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 fprintf(stderr,"Pick up float failed : %c(%d)\n",*cont,*cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 return(NULL);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 *index = sign * (val_int + val_dec) * exp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 cont++;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 return(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 int main(int artc, char *argv[])
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 xmlDocPtr doc;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 xmlNodePtr cur;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 char *cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 doc = xmlParseFile(argv[1]);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 cur = xmlDocGetRootElement(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 for (cur=cur->children; cur; cur=cur->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 if (!xmlStrcmp(cur->name,(xmlChar*)"surface"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 get_data(cur->children);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 xmlFreeDoc(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99 */