main(){ scanf("%s",k); LST_STree tree; lst_stree_init(&tree); lst_stree_add_string(&tree,lst_string_fromstr(k)); lst_alg_dfs(&tree,z,NULL); }
static VALUE push(VALUE self, VALUE o) { LST_STree * tree; Data_Get_Struct(self, LST_STree, tree); LST_String * string = lst_string_new( StringValuePtr(o), sizeof(char), RSTRING_LEN(o)); lst_stree_add_string(tree, string); return self; }
static PyObject* st_add(PyObject* self, PyObject* args) { tree_handle_t *handle; LST_String *lststring; char *cstring; long length; if (!PyArg_ParseTuple(args, "ls#:st_add", (long*)&handle, &cstring, &length)) return NULL; lststring = (LST_String*)malloc(sizeof(LST_String)); if (lststring == NULL) { return PyErr_NoMemory(); } lst_string_init(lststring, cstring, 1, length); lst_stringset_add(handle->string_set, lststring); lst_stree_add_string(handle->tree, lststring); handle->numstrings++; handle->annotated = False; Py_INCREF(Py_None); return Py_None; }
static PyObject* st_create(PyObject* self, PyObject* args) { PyObject *pylist = NULL, *pystring = NULL; char *cstring = NULL; int length; tree_handle_t *handle; LST_String *string; /* parse arguments */ if (!PyArg_ParseTuple(args, "O:st_create", &pylist)) return NULL; /* create the tree */ handle = malloc(sizeof(tree_handle_t)); if (handle == NULL) { return PyErr_NoMemory(); } handle->tree = lst_stree_new(NULL); assert(handle != NULL); /* fill in the tree and stringset */ PyObject *iterator = PyObject_GetIter(pylist); handle->string_set = lst_stringset_new(); assert(handle->string_set != NULL); handle->numstrings = 0; while((pystring = PyIter_Next(iterator)) != NULL) { handle->numstrings++; if (PyString_AsStringAndSize(pystring,&cstring,&length)) { Py_DECREF(iterator); lst_stree_free(handle->tree); lst_stringset_free(handle->string_set); free(handle); return NULL; } /* LST_String is pointing back at the python string's data. * python wrapper class keeps a reference to each string added, * so don't keep the reference here. */ Py_DECREF(pystring); /* this is freed when stringset is freed */ string = (LST_String*)malloc(sizeof(LST_String)); if (string == NULL) { Py_DECREF(iterator); lst_stree_free(handle->tree); lst_stringset_free(handle->string_set); free(handle); return PyErr_NoMemory(); } lst_string_init(string, cstring, 1, length); lst_stringset_add(handle->string_set, string); lst_stree_add_string(handle->tree, string); } Py_DECREF(iterator); iterator = NULL; /* not annotated */ handle->annotated = False; // lst_debug_print_tree(handle->tree); /* return pointer to the handle */ return Py_BuildValue("l", (long)handle); }