commit | author | age
|
8c1bb1
|
1 |
#include <stdio.h> |
SP |
2 |
#include <string.h> |
|
3 |
#include <stdlib.h> |
|
4 |
#include <libxml/xmlmemory.h> |
|
5 |
#include <libxml/parser.h> |
|
6 |
#include <general.h> |
|
7 |
#include <restore.h> |
|
8 |
#include <snapshot.h> |
|
9 |
#include <zlib.h> |
|
10 |
#include "vesicle.h" |
|
11 |
ts_bool parseDump(char *dumpfname) { |
|
12 |
xmlDocPtr doc; |
|
13 |
xmlNodePtr cur; |
|
14 |
ts_vesicle *vesicle; |
|
15 |
|
|
16 |
doc = xmlParseFile(dumpfname); |
|
17 |
|
|
18 |
if (doc == NULL ) { |
|
19 |
fatal("Dump file could not be found or parsed. It is correct file?",1); |
|
20 |
} |
|
21 |
|
|
22 |
cur = xmlDocGetRootElement(doc); |
|
23 |
|
|
24 |
if (cur == NULL) { |
|
25 |
fatal("Dump file is empty.",1); |
|
26 |
} |
|
27 |
|
|
28 |
if (xmlStrcmp(cur->name, (const xmlChar *) "VTKFile")) { |
|
29 |
fatal("document of the wrong type, root node != story",1); |
|
30 |
} |
|
31 |
|
|
32 |
cur = cur->xmlChildrenNode; |
|
33 |
while (cur != NULL) { |
|
34 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"trisurf"))){ |
3c772b
|
35 |
vesicle=parseTrisurfTag(doc, cur); |
8c1bb1
|
36 |
} |
SP |
37 |
|
|
38 |
cur = cur->next; |
|
39 |
} |
|
40 |
|
|
41 |
xmlFreeDoc(doc); |
|
42 |
fprintf(stderr,"Restoration completed\n"); |
|
43 |
exit(0); |
3c772b
|
44 |
vesicle_free(vesicle); |
8c1bb1
|
45 |
return TS_SUCCESS; |
SP |
46 |
} |
|
47 |
|
|
48 |
ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur){ |
|
49 |
fprintf(stderr,"Parsing trisurf tag\n"); |
|
50 |
/* base64decode */ |
|
51 |
size_t cLen; |
|
52 |
/*size_t tLen; |
|
53 |
const unsigned char test[]="Test"; |
|
54 |
char *cTest=base64_encode(test, 4,&tLen); |
|
55 |
unsigned char *cuTest=base64_decode((char *)cTest,tLen,&tLen); |
|
56 |
cuTest[tLen]=0; |
|
57 |
fprintf(stderr,"%s\n",cuTest); |
|
58 |
*/ |
|
59 |
xmlChar *b64=xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
60 |
unsigned char *compressed=base64_decode((char *)b64,strlen((char *)b64)-1,&cLen); |
|
61 |
/* uncompress */ |
|
62 |
unsigned char *subtree=(unsigned char *)malloc(512000*sizeof(unsigned char)); /* TODO: again, the uncompressed string must not exceed this */ |
|
63 |
z_stream infstream; |
|
64 |
infstream.zalloc = Z_NULL; |
|
65 |
infstream.zfree = Z_NULL; |
|
66 |
infstream.opaque = Z_NULL; |
|
67 |
infstream.avail_in = (ts_uint)cLen; // size of input |
|
68 |
infstream.next_in = compressed; // input char array |
|
69 |
infstream.avail_out = (ts_uint)512000; // size of output |
|
70 |
infstream.next_out = subtree; // output char array |
|
71 |
|
|
72 |
// the actual DE-compression work. |
|
73 |
inflateInit(&infstream); |
|
74 |
inflate(&infstream, Z_NO_FLUSH); |
|
75 |
inflateEnd(&infstream); |
|
76 |
fprintf(stderr,"%lu\n",cLen); |
|
77 |
subtree[infstream.total_out]='\0'; //zero terminate string |
|
78 |
fprintf(stderr,"%s\n",subtree); |
|
79 |
|
|
80 |
free(subtree); |
|
81 |
/*parse xml subtree */ |
|
82 |
xmlChar *nvtx, *npoly, *nfono; |
|
83 |
nvtx = xmlGetProp(cur, (xmlChar *)"nvtx"); |
|
84 |
npoly=xmlGetProp(cur, (xmlChar *)"npoly"); |
|
85 |
nfono=xmlGetProp(cur, (xmlChar *)"nfono"); |
|
86 |
fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx)); |
|
87 |
ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),10,10,10,0.1); |
|
88 |
//vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle); |
|
89 |
xmlFree(nvtx); |
|
90 |
xmlFree(npoly); |
|
91 |
xmlFree(nfono); |
|
92 |
return vesicle; |
|
93 |
} |