Exemple #1
0
signed char comps_doccategory_xml(COMPS_DocCategory *category,
                                  xmlTextWriterPtr writer, COMPS_Log *log,
                                  COMPS_XMLOptions *xml_options,
                                  COMPS_DefaultsOptions *def_options) {
    COMPS_ObjListIt *it;
    COMPS_Object *obj;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;

    static char* props[] = {"id", "name", "name", "desc", "desc", "display_order"};
    static size_t type[] =   {0, 0, offsetof(COMPS_DocCategory, name_by_lang),
                           0, offsetof(COMPS_DocCategory, desc_by_lang), 0};
    static char* aliases[] = {NULL, NULL, NULL, "description", "description", NULL};
    char *str;
    int ret;

    if (category->group_ids->len == 0 && !xml_options->empty_categories) {
        obj = comps_doccategory_get_id(category);
        comps_log_error(log, COMPS_ERR_PKGLIST_EMPTY, 1, obj);
        COMPS_OBJECT_DESTROY(obj);
        return 1;
    }
    ret = xmlTextWriterStartElement(writer, BAD_CAST "category");
    COMPS_XMLRET_CHECK
    if (xml_options->arch_output) {
        obj = (COMPS_Object*)comps_doccategory_arches(category);
        ret = __comps_xml_arch(obj, writer);
        COMPS_OBJECT_DESTROY(obj);
        COMPS_XMLRET_CHECK
    }
signed char comps_docgroup_xml(COMPS_DocGroup *group, xmlTextWriterPtr writer,
                               COMPS_Log *log, COMPS_XMLOptions *xml_options,
                               COMPS_DefaultsOptions *def_options) {
    COMPS_ObjListIt *it;
    COMPS_Object *obj;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;

    static char* props[] = {"id", "name", "name", "desc",
                            "desc", "def", "uservisible", "biarchonly",
                            "display_order", "langonly"};
    static size_t type[] =   {0, 0, offsetof(COMPS_DocGroup, name_by_lang),
                              0, offsetof(COMPS_DocGroup, desc_by_lang), 0,
                              0, 0, 0, 0};
    static char* aliases[] = {NULL, NULL, NULL, "description", "description",
                              "default", NULL, NULL, NULL, NULL};
    static bool explicit[] = {true, true, true, true, true, false, false,
                              false, true, true};
    const char *str_true = "true";
    const char *str_false = "false";
    const char *default_val[] = {NULL, NULL, NULL, NULL, NULL,
                           def_options->default_default?str_true:str_false,
                           def_options->default_uservisible?str_true:str_false,
                           def_options->default_biarchonly?str_true:str_false,
                           NULL, NULL};

    static char*(*tostrf[])(COMPS_Object*) = {&comps_object_tostr,
                                               &comps_object_tostr,
                                               &comps_object_tostr,
                                               &comps_object_tostr,
                                               &comps_object_tostr,
                                               &__comps_num2boolstr,
                                               &__comps_num2boolstr,
                                               &__comps_num2boolstr,
                                               &comps_object_tostr,
                                               &comps_object_tostr};
    char *str;
    int ret;
    explicit[5] = xml_options->default_explicit;
    explicit[6] = xml_options->uservisible_explicit;
    explicit[7] = xml_options->biarchonly_explicit;
    if (group->packages->len == 0 && !xml_options->empty_groups) {
        obj = comps_docgroup_get_id(group);
        comps_log_error(log, COMPS_ERR_PKGLIST_EMPTY, 1, obj);
        COMPS_OBJECT_DESTROY(obj);
        return 1;
    }
    ret = xmlTextWriterStartElement(writer, BAD_CAST "group");
    COMPS_XMLRET_CHECK()
    if (xml_options->arch_output) {
        obj = (COMPS_Object*)comps_docgroup_arches(group);
        ret = __comps_xml_arch(obj, writer);
        COMPS_XMLRET_CHECK()
        COMPS_OBJECT_DESTROY(obj);
    }
    for (int i=0; i<10; i++) {
        //printf("%s\n", props[i]);
        if (!type[i]) {
            obj = comps_objdict_get_x(group->properties, props[i]);
            if (explicit[i]) {
                if (obj) {
                    str = tostrf[i](obj);
                    __comps_xml_prop((aliases[i])?aliases[i]:props[i], str, writer);
                    free(str);
                } else if (default_val[i]){
                    __comps_xml_prop((aliases[i])?aliases[i]:props[i],
                                     (char*)default_val[i], writer);
                }
            } else {
                if (obj) {
                    str = tostrf[i](obj);
                    if (!default_val[i] || (strcmp(str, default_val[i]) != 0)) {
                        __comps_xml_prop((aliases[i])?aliases[i]:props[i], str,
                                         writer);
                    }
                    free(str);
                }
            }
        } else {
            if (*(void**)(((char*)group)+type[i]) == (void*)group->name_by_lang){