comparison old/simple_render/xml.cpp @ 507:735f76483bb2

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