PyObject* PyCOMPS_toxml_f(PyObject *self, PyObject *args, PyObject *kwds) { const char *errors = NULL; char *tmps, *fname = NULL; int i; signed char genret; COMPS_XMLOptions *xml_options = NULL; COMPS_DefaultsOptions *def_options = NULL; COMPS_HSListItem *it; PyObject *ret, *tmp; char* keywords[] = {"fname", "xml_options", "def_options", NULL}; PyCOMPS *self_comps = (PyCOMPS*)self; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&O&", keywords, &fname, __pycomps_dict_to_xml_opts, &xml_options, __pycomps_dict_to_def_opts, &def_options)) { PyErr_SetString(PyExc_TypeError, "function accept string and optional xml_options dict " "and def_options dict"); return NULL; } if (!self_comps->comps_doc->encoding) self_comps->comps_doc->encoding = comps_str("UTF-8"); comps_hslist_clear(self_comps->comps_doc->log->entries); genret = comps2xml_f(self_comps->comps_doc, fname, 0, xml_options, def_options); if (xml_options) free(xml_options); if (def_options) free(def_options); if (genret == -1) { PyErr_SetString(PyCOMPSExc_XMLGenError, "Error during generating xml"); } //free(fname); for (i = 0, it = self_comps->comps_doc->log->entries->first; it != NULL; it = it->next, i++); ret = PyList_New(i); for (i = 0, it = self_comps->comps_doc->log->entries->first; it != NULL; it = it->next, i++) { tmps = comps_log_entry_str(it->data); tmp = PyUnicode_DecodeUTF8(tmps, strlen(tmps), errors); PyList_SetItem(ret, i, tmp); free(tmps); } return ret; }
inline void comps_set_clear(COMPS_Set *set) { comps_hslist_clear(set->data); }
void comps_mrtree_unset(COMPS_MRTree * rt, const char * key) { COMPS_HSList * subnodes; COMPS_HSListItem * it; COMPS_MRTreeData * rtdata; unsigned int offset, len, x; char found, ended; COMPS_HSList * path; struct Relation { COMPS_HSList * parent_nodes; COMPS_HSListItem * child_it; } *relation; path = comps_hslist_create(); comps_hslist_init(path, NULL, NULL, &free); len = strlen(key); offset = 0; subnodes = rt->subnodes; while (offset != len) { found = 0; for (it = subnodes->first; it != NULL; it=it->next) { if (((COMPS_MRTreeData*)it->data)->key[0] == key[offset]) { found = 1; break; } } if (!found) { comps_hslist_destroy(&path); return; } rtdata = (COMPS_MRTreeData*)it->data; for (x=1; ;x++) { ended=0; if (rtdata->key[x] == 0) ended += 1; if (x == len - offset) ended += 2; if (ended != 0) break; if (key[offset+x] != rtdata->key[x]) break; } if (ended == 3) { /* remove node from tree only if there's no descendant*/ if (rtdata->subnodes->last == NULL) { printf("removing all\n"); comps_hslist_remove(subnodes, it); comps_mrtree_data_destroy(rtdata); free(it); } else { printf("removing data only\n"); comps_hslist_clear(rtdata->data); rtdata->is_leaf = 0; } if (path->last == NULL) { comps_hslist_destroy(&path); return; } rtdata = (COMPS_MRTreeData*) ((struct Relation*)path->last->data)->child_it->data; /*remove all predecessor of deleted node (recursive) with no childs*/ while (rtdata->subnodes->last == NULL) { printf("removing '%s'\n", rtdata->key); comps_mrtree_data_destroy(rtdata); comps_hslist_remove( ((struct Relation*)path->last->data)->parent_nodes, ((struct Relation*)path->last->data)->child_it); free(((struct Relation*)path->last->data)->child_it); it = path->last; comps_hslist_remove(path, path->last); free(it); rtdata = (COMPS_MRTreeData*) ((struct Relation*)path->last->data)->child_it->data; } comps_hslist_destroy(&path); return; } else if (ended == 1) offset+=x; else { comps_hslist_destroy(&path); return; } if ((relation = malloc(sizeof(struct Relation))) == NULL) { comps_hslist_destroy(&path); return; } subnodes = ((COMPS_MRTreeData*)it->data)->subnodes; relation->parent_nodes = subnodes; relation->child_it = it; comps_hslist_append(path, (void*)relation, 0); } comps_hslist_destroy(&path); return; }