Rev 5725 | Rev 5727 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5725 | serge | 1 | #include "tinyxml/tinyxml.h" |
2 | #include "collection.h" |
||
3 | |||
4 | const char *key_collection = "collection"; |
||
5 | const char *key_package = "package"; |
||
6 | const char *key_name = "name"; |
||
7 | const char *key_version = "version"; |
||
8 | const char *key_description = "description"; |
||
9 | const char *key_title = "title"; |
||
10 | const char *key_release = "release"; |
||
11 | const char *key_file = "file"; |
||
12 | |||
13 | int package_id; |
||
14 | |||
15 | void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup) |
||
16 | { |
||
17 | TiXmlElement *xmlpkg; |
||
18 | TiXmlElement *xmle; |
||
19 | |||
20 | xmlpkg = xmlgroup->FirstChildElement(key_package); |
||
21 | while (xmlpkg) |
||
22 | { |
||
23 | package_t *pkg; |
||
24 | |||
25 | pkg = (package_t*)malloc(sizeof(package_t)); |
||
26 | pkg->id = package_id++; |
||
27 | pkg->name = strdup(xmlpkg->Attribute(key_name)); |
||
28 | pkg->version = strdup(xmlpkg->Attribute(key_version)); |
||
29 | |||
30 | xmle = xmlpkg->FirstChildElement(key_description); |
||
31 | pkg->description = strdup(xmle->Attribute(key_title)); |
||
5726 | serge | 32 | |
5725 | serge | 33 | xmle = xmlpkg->FirstChildElement(key_release); |
5726 | serge | 34 | pkg->filename = strdup(xmle->Attribute(key_file)); |
5725 | serge | 35 | |
5726 | serge | 36 | list_add_tail(&pkg->list, &gr->packages); |
5725 | serge | 37 | xmlpkg = xmlpkg->NextSiblingElement(); |
38 | }; |
||
39 | }; |
||
40 | |||
41 | |||
42 | collection_t* load_collection_file(const char *name) |
||
43 | { |
||
44 | TiXmlDocument doc; |
||
45 | TiXmlElement *col; |
||
46 | collection_t *collection = NULL; |
||
47 | |||
48 | doc.LoadFile(name); |
||
49 | col = doc.FirstChildElement(key_collection); |
||
50 | if (col) |
||
51 | { |
||
52 | collection = (collection_t*)malloc(sizeof(collection_t)); |
||
53 | INIT_LIST_HEAD(&collection->groups); |
||
54 | |||
55 | TiXmlElement* xmlgroup = col->FirstChildElement(); |
||
56 | if (xmlgroup) |
||
57 | { |
||
58 | pkg_group_t *gr; |
||
59 | |||
60 | gr = (pkg_group_t*)malloc(sizeof(pkg_group_t)); |
||
61 | INIT_LIST_HEAD(&gr->list); |
||
62 | INIT_LIST_HEAD(&gr->packages); |
||
63 | |||
64 | gr->name = strdup(xmlgroup->Value()); |
||
65 | list_add_tail(&gr->list, &collection->groups); |
||
66 | parse_group(gr, xmlgroup); |
||
67 | }; |
||
68 | }; |
||
69 | |||
70 | return collection; |
||
71 | } |
||
72 |