annotate Renderer/test_render/xml.cpp @ 503:516d5c91d5b4 draft double-linked-task-list

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