Esempio n. 1
0
END_TEST

int check_errors(COMPS_Log *log, COMPS_LogEntry ** known_errors,
                  int known_len) {
    COMPS_HSListItem *it;
    int i;

    it = log->entries->first;
    for (i = 0; it != NULL && i != known_len; it = it->next, i++) {
        fail_if(((COMPS_LogEntry*)it->data)->arg_count !=
                known_errors[i]->arg_count,
                "%d err opt_message doesn't match (%d != %d)", i,
                ((COMPS_LogEntry*)it->data)->arg_count,
                known_errors[i]->arg_count);
        fail_if(((COMPS_LogEntry*)it->data)->code !=
                    known_errors[i]->code, "%d. err code different\n (%d != %d)",
                    i, ((COMPS_LogEntry*)it->data)->code,
                    known_errors[i]->code);
        for (int x = 0; x < known_errors[i]->arg_count; x++) {
            char *_x, *_y;
            _x = comps_object_tostr(((COMPS_LogEntry*)it->data)->args[x]);
            _y = comps_object_tostr(known_errors[i]->args[x]);
            fail_if(comps_object_cmp(((COMPS_LogEntry*)it->data)->args[x],
                                     known_errors[i]->args[x]) == 0, "%d. %s != %s",
                                     x, _x, _y);
            free(_x);
            free(_y);
        }
    }
    return i;
}
PyObject* __pycomps_dict_val_out(COMPS_HSListItem *hsit) {
    char *str = comps_object_tostr((COMPS_Object*)hsit->data);
    PyObject *ret;
    ret = PyUnicode_FromString(str);
    free(str);
    return ret;
}
Esempio n. 3
0
long PyCOMPS_hash(PyObject *self) {
    char *cstr = NULL;
    long crc;

    cstr = comps_object_tostr(((PyCompsObject*)self)->c_obj);
    crc = crc32(0, cstr, strlen(cstr));
    free(cstr);
    return crc;
}
Esempio n. 4
0
char* comps_docgroupid_str_u(COMPS_Object* docgroupid) {
    const int len = strlen("<COMPS_DocGroupId name='' default=''>");
    char *name = comps_object_tostr((COMPS_Object*)((COMPS_DocGroupId*)docgroupid)->name);
    char *def = ((COMPS_DocGroupId*)docgroupid)->def?"True":"False";
    char *ret = malloc(sizeof(char)*(len+strlen(name)+strlen(def)+1));
    sprintf(ret, "<COMPS_DocGroupId name='%s' default='%s'>", name, def);
    free(name);
    return ret;
}
Esempio n. 5
0
PyObject* PyCOMPSPack_repr(PyObject *self) {
    char *x;
    COMPS_Object *name;
    PyObject *ret;
    name = comps_docpackage_get_name(((PyCOMPS_Package*)self)->package);
    x = comps_object_tostr(name);
    ret = PyUnicode_FromFormat("<libcomps.Package object '%s' at %p>", x, self);
    free(x);
    comps_object_destroy(name);
    return ret;
}
Esempio n. 6
0
PyObject* PyCOMPSGroup_repr(PyObject *self) {
    char *x;
    COMPS_Object *id;
    PyObject *ret;
    id = comps_docgroup_get_id(((PyCOMPS_Group*)self)->group);
    x = comps_object_tostr(id);
    ret = PyUnicode_FromFormat("<libcomps.Group object '%s' at %p>", x, self);
    free(x);
    comps_object_destroy(id);
    return ret;
}
Esempio n. 7
0
PyObject* PyCOMPSEnv_repr(PyObject *self) {
    char *x;
    COMPS_Object *id;
    PyObject *ret;
    id = comps_docenv_get_id(((PyCOMPS_Env*)self)->c_obj);
    x = comps_object_tostr(id);
    ret = PyUnicode_FromFormat("<libcomps.Environment object '%s' at %p>", x, self);
    free(x);
    comps_object_destroy(id);
    return ret;
}
Esempio n. 8
0
PyObject* PyCOMPSEnv_str(PyObject *self) {
    char *x;
    COMPS_Object *id;
    PyObject *ret;
    id = comps_docenv_get_id(((PyCOMPS_Env*)self)->c_obj);
    x = comps_object_tostr(id);
    ret = PyUnicode_FromFormat("%s", x);
    free(x);
    comps_object_destroy(id);
    return ret;
}
Esempio n. 9
0
int PyCOMPSPack_print(PyObject *self, FILE *f, int flags) {
    #define _package_ ((PyCOMPS_Package*)self)->package
    (void) flags;
    char *str;
    const char *type;
    type = comps_docpackage_type_str(_package_->type);
    str = comps_object_tostr((COMPS_Object*)_package_->name);
    fprintf(f, "<COPMS_Package name='%s' type='%s' ", str, type);
    free(str);
    if (_package_->requires) {
        str = comps_object_tostr((COMPS_Object*)_package_->requires);
        fprintf(f, "requires='%s' ", str);
        free(str);
    }
    if (_package_->basearchonly && _package_->basearchonly->val) {
        str = comps_object_tostr((COMPS_Object*)_package_->basearchonly);
        fprintf(f, "basearchonly='%s' ", str);
        free(str);
    }
    fprintf(f, ">");
    return 0;
}
PyObject* __pycomps_dict_pair_out(COMPS_HSListItem *hsit) {
    PyObject *key, *val, *tuple;
    char *x;

    key = PyUnicode_FromString((char*) ((COMPS_ObjRTreePair*)hsit->data)->key);
    x = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
    val = PyUnicode_FromString(x);
    free(x);
    tuple = PyTuple_Pack(2, key, val);
    Py_DECREF(key);
    Py_DECREF(val);
    return tuple;
}
int PyCOMPSDict_print(PyObject *self, FILE *f, int flags) {
    COMPS_HSList *pairlist;
    COMPS_HSListItem *it;
    char *tmpstr;

    (void)flags;
    fprintf(f, "{");
    pairlist = comps_objdict_pairs(((PyCOMPS_Dict*)self)->dict);
    for (it = pairlist->first; it != pairlist->last; it = it->next) {
        //printf("x\n");
        tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
        fprintf(f, "%s = '%s', ", ((COMPS_RTreePair*)it->data)->key, tmpstr);
        free(tmpstr);
    }
    if (it) {
        tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
        fprintf(f, "%s = '%s'", ((COMPS_RTreePair*)it->data)->key, tmpstr);
        free(tmpstr);
    }
    fprintf(f, "}");
    comps_hslist_destroy(&pairlist);
    return 0;
}
PyObject* PyCOMPSDict_get_(PyObject *self, PyObject *key) {
    char *ckey;
    COMPS_Object* val;
    PyObject *ret;

    if (__pycomps_stringable_to_char(key, &ckey))
        return NULL;

    val = comps_objdict_get(((PyCOMPS_Dict*)self)->dict, ckey);
    if (!val) {
        free(ckey);
        Py_RETURN_NONE;
    }
    else {
        free(ckey);
        ckey = comps_object_tostr(val);
        COMPS_OBJECT_DESTROY(val);
        ret = PyUnicode_FromString(ckey);
        free(ckey);
        return ret;
    }
}
Esempio n. 13
0
int PyCOMPSGroup_print(PyObject *self, FILE *f, int flags) {
    #define _group_ ((PyCOMPS_Group*)self)
    COMPS_ObjListIt *it;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;
    char *id, *name, *desc, *lang, *def, *uservis, *disp_ord;
    COMPS_Object* tmp_prop;

    (void)flags;

    tmp_prop = comps_docgroup_get_id(_group_->group);
    id = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_name(_group_->group);
    name = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_desc(_group_->group);
    desc = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_display_order(_group_->group);
    disp_ord = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_langonly(_group_->group);
    lang = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_def(_group_->group);
    def = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_uservisible(_group_->group);
    uservis = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;


    fprintf(f, "<COMPS_Group: id='%s', name='%s', description='%s',  "
            "default='%s', uservisible='%s', lang_only='%s', display_order=%s ",
            id, name, desc, def, uservis, lang, disp_ord);
    free(id);
    free(name);
    free(desc);
    free(lang);
    free(def);
    free(uservis);
    free(disp_ord);

    fprintf(f, "name_by_lang={");
    pairlist = comps_objrtree_pairs(_group_->group->name_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", desc_by_lang={");
    pairlist = comps_objrtree_pairs(_group_->group->desc_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", packages=[");
    if (_group_->group->packages) {
        for (it = _group_->group->packages->first;
             it != _group_->group->packages->last; it = it->next){
            id = comps_object_tostr(it->comps_obj);
            fprintf(f,"%s, ", id);
            free(id);
        }
        if (it) {
            id = comps_object_tostr(it->comps_obj);
            fprintf(f,"%s", id);
            free(id);
        }
    }
    fprintf(f, "]>");
    return 0;
    #undef _group_
}
Esempio n. 14
0
int PyCOMPSEnv_print(PyObject *self, FILE *f, int flags) {
    COMPS_ObjListIt *it;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;
    char *id, *name, *desc, *display_order;
    COMPS_Object *tmp_prop;

    #define _env_ ((PyCOMPS_Env*)self)->c_obj
    (void)flags;

    tmp_prop = (COMPS_Object*)comps_docenv_get_id(_env_);
    id = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_name(_env_);
    name = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_desc(_env_);
    desc = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_display_order(_env_);
    display_order = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;

    fprintf(f, "<COMPS_Environment: id='%s'"
               "name='%s' description='%s' display_order=%s", id, name, desc,
                display_order);
    free(id);
    free(name);
    free(desc);
    free(display_order);

    fprintf(f, ", name_by_lang={");
    pairlist = comps_objrtree_pairs(_env_->name_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", desc_by_lang={");
    pairlist = comps_objrtree_pairs(_env_->desc_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", group_list=[");
    if (_env_->group_list) {
        for (it = _env_->group_list->first;
             it != _env_->group_list->last; it = it->next){
            id = comps_object_tostr(it->comps_obj);
            fprintf(f, "'%s', ", id);
            free(id);
        }
        if (it) {
            id = comps_object_tostr(it->comps_obj);
            fprintf(f, "'%s'", id);
            free(id);
        }
    }
    fprintf(f, "]");
    fprintf(f, ", option_list=[");
    if (_env_->option_list) {
        for (it = _env_->option_list->first;
             it != _env_->option_list->last; it = it->next){
            id = comps_object_tostr(it->comps_obj);
            fprintf(f, "'%s', ", id);
            free(id);
        }
        if (it) {
            id = comps_object_tostr(it->comps_obj);
            fprintf(f, "'%s'", id);
            free(id);
        }
    }
    fprintf(f, "]>");
    return 0;
    #undef _env_
}
PyObject* PyCOMPSDict_str(PyObject *self) {
    COMPS_HSList *pairlist;
    COMPS_HSListItem *it;
    PyObject *ret, *tmp = NULL, *tmp2 = NULL, *tmpkey = NULL, *tmpval = NULL;
    ret = PyUnicode_FromString("{");
    pairlist = comps_objdict_pairs(((PyCOMPS_Dict*)self)->dict);
    char *tmpstr;

    for (it = pairlist->first; it != pairlist->last; it = it->next) {
        tmp = ret;
        tmpkey = __pycomps_lang_decode(((COMPS_ObjRTreePair*)it->data)->key);
        if (!tmpkey) {
            PyErr_SetString(PyExc_TypeError, "key convert error");
            goto out;
        }
        tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
        tmpval = __pycomps_lang_decode(tmpstr);
        free(tmpstr);
        if (!tmpval) {
            PyErr_SetString(PyExc_TypeError, "val convert error");
            goto out;
        }
        tmp2 = PyUnicode_FromFormat("%U = '%U', ", tmpkey, tmpval);
        ret = PyUnicode_Concat(ret, tmp2);
        Py_XDECREF(tmp);
        Py_XDECREF(tmp2);
        Py_XDECREF(tmpkey);
        Py_XDECREF(tmpval);
    }
    tmp = ret;
    tmpkey = __pycomps_lang_decode(((COMPS_RTreePair*)it->data)->key);
    if (!tmpkey) {
        goto out;
    }
    tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
    tmpval = __pycomps_lang_decode(tmpstr);
    free(tmpstr);
    if (!tmpval) {
        //PyErr_SetString(PyExc_TypeError, "val convert error");
        goto out;
    }
    tmp2 = PyUnicode_FromFormat("%U = '%U'", tmpkey, tmpval);
    ret = PyUnicode_Concat(ret, tmp2);
    Py_XDECREF(tmp);
    Py_XDECREF(tmp2);
    Py_XDECREF(tmpkey);
    Py_XDECREF(tmpval);
    
    tmp = ret;
    tmp2 = PyUnicode_FromString("}");
    ret = PyUnicode_Concat(ret, tmp2);
    Py_XDECREF(tmp);
    Py_XDECREF(tmp2);

    comps_hslist_destroy(&pairlist);
    return ret;

    out:
    Py_XDECREF(tmp);
    Py_XDECREF(tmp2);
    Py_XDECREF(tmpkey);
    Py_XDECREF(tmpval);
    comps_hslist_destroy(&pairlist);
    return NULL;
}