Subversion Repositories Kolibri OS

Rev

Rev 5727 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "tinyxml/tinyxml.h"
  2. #include "package.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.  
  27.         INIT_LIST_HEAD(&pkg->file_list);
  28.                 pkg->id = package_id++;
  29.         pkg->name = strdup(xmlpkg->Attribute(key_name));
  30.         pkg->version = strdup(xmlpkg->Attribute(key_version));
  31.  
  32.         xmle = xmlpkg->FirstChildElement(key_description);
  33.         pkg->description = strdup(xmle->Attribute(key_title));
  34.  
  35.         xmle = xmlpkg->FirstChildElement(key_release);
  36.         pkg->filename = strdup(xmle->Attribute(key_file));
  37.  
  38.         list_add_tail(&pkg->list, &gr->packages);
  39.                 xmlpkg = xmlpkg->NextSiblingElement();
  40.         };
  41. };
  42.  
  43.  
  44. collection_t* load_collection_file(const char *name)
  45. {
  46.         TiXmlDocument doc;
  47.         TiXmlElement *col;
  48.     collection_t *collection = NULL;
  49.  
  50.         doc.LoadFile(name);
  51.     col = doc.FirstChildElement(key_collection);
  52.         if (col)
  53.         {
  54.         collection = (collection_t*)malloc(sizeof(collection_t));
  55.         INIT_LIST_HEAD(&collection->groups);
  56.  
  57.                 TiXmlElement* xmlgroup = col->FirstChildElement();
  58.                 if (xmlgroup)
  59.                 {
  60.                         pkg_group_t *gr;
  61.  
  62.                         gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
  63.                         INIT_LIST_HEAD(&gr->list);
  64.                         INIT_LIST_HEAD(&gr->packages);
  65.  
  66.             gr->name = strdup(xmlgroup->Value());
  67.             list_add_tail(&gr->list, &collection->groups);
  68.                         parse_group(gr, xmlgroup);
  69.                 };
  70.         };
  71.  
  72.         return collection;
  73. }
  74.  
  75.  
  76.