Subversion Repositories Kolibri OS

Rev

Rev 5728 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "tinyxml/tinyxml.h"
  2. #include "package.h"
  3.  
  4. // *INDENT-OFF*
  5. const char *key_collection  = "collection";
  6. const char *key_package     = "package";
  7. const char *key_name        = "name";
  8. const char *key_version     = "version";
  9. const char *key_group       = "group";
  10. const char *key_description = "description";
  11. const char *key_title       = "title";
  12. const char *key_release     = "release";
  13. const char *key_file        = "file";
  14. // *INDENT-ON*
  15.  
  16. int package_id;
  17.  
  18. collection_t *
  19. load_collection_file(const char *name)
  20. {
  21.         TiXmlDocument doc;
  22.         TiXmlElement *col;
  23.         collection_t *collection = NULL;
  24.  
  25.         doc.LoadFile(name);
  26.         col = doc.FirstChildElement(key_collection);
  27.         if (col)
  28.         {
  29.                 TiXmlElement *xmlpkg;
  30.                 TiXmlElement *xmle;
  31.  
  32.                 collection = (collection_t *) malloc(sizeof(collection_t));
  33.                 INIT_LIST_HEAD(&collection->packages);
  34.  
  35.                 xmlpkg = col->FirstChildElement(key_package);
  36.  
  37.                 while (xmlpkg)
  38.                 {
  39.                         package_t *pkg;
  40.  
  41.                         pkg = (package_t *) malloc(sizeof(package_t));
  42.  
  43.                         INIT_LIST_HEAD(&pkg->file_list);
  44.  
  45.                         pkg->id = package_id++;
  46.                         pkg->name = strdup(xmlpkg->Attribute(key_name));
  47.                         pkg->version = strdup(xmlpkg->Attribute(key_version));
  48.                         pkg->group = strdup(xmlpkg->Attribute(key_group));
  49.  
  50.                         xmle = xmlpkg->FirstChildElement(key_description);
  51.                         pkg->description = strdup(xmle->Attribute(key_title));
  52.  
  53.                         xmle = xmlpkg->FirstChildElement(key_release);
  54.                         pkg->filename = strdup(xmle->Attribute(key_file));
  55.  
  56.                         list_add_tail(&pkg->list, &collection->packages);
  57.                         xmlpkg = xmlpkg->NextSiblingElement();
  58.                 };
  59.     };
  60.  
  61.     return collection;
  62. };
  63.