Beispiel #1
0
node* Tree_Delete (node* my_node)
{
	assert (my_node);

	if (my_node -> prev)
		if		(my_node == my_node -> prev -> left  ) my_node -> prev -> left = NULL;
		else if (my_node == my_node -> prev -> right ) my_node -> prev -> right = NULL;
		//else return ERR_NODE_DELETE_PREV_PROBLEM;

	if (my_node -> left)  Tree_Delete (my_node -> left);
	if (my_node -> right) Tree_Delete (my_node -> right);

	my_node -> num = POiSON;
	if (my_node -> word) 
	{
		int word_len = strlen (my_node -> word);
		for (int i = 0; i < word_len; ++i) my_node -> word[i] = STR_POiSON;
		//free (my_token -> word);
	}
	my_node -> op   = POiSON;
	my_node -> type = POiSON;

	node* ret = my_node -> prev;
	free (my_node);
return ret;
}
Beispiel #2
0
// Parse an xml document
// -- Creates and sets up an xml parser context
// -- Parses xml doc body into a DOM tree
// -- Destroys the xml parser context when done
// doc should be a char* to the xml document
// length should be the length of th xml document
// whole doc should be set to true if the entire xml doc is contained in the string pointed to by doc
TreeNode TreeNode_ParseXML(uint8_t* doc, uint32_t length, bool wholeDoc)
{
    TreeNode root = NULL;
    if (doc)
    {
        if (length)
        {
            XMLParser_Context bodyParser = XMLParser_Create();
            XMLParser_SetStartHandler(bodyParser, HTTP_xmlDOMBuilder_StartElementHandler);
            XMLParser_SetCharDataHandler(bodyParser, HTTP_xmlDOMBuilder_CharDataHandler);
            XMLParser_SetEndHandler(bodyParser, HTTP_xmlDOMBuilder_EndElementHandler);
            XMLParser_SetUserData(bodyParser, &root);
            if (XMLParser_Parse(bodyParser, (const char*) doc, length, wholeDoc))
            {
                // Parsed ok
            }
            else
            {
                // Parsing failed
                // Clean up tree
                Tree_Delete(root);
                root = NULL;
            }
            XMLParser_Destroy (bodyParser);
            currentTreeNode = NULL;
        }
    }
    return root;
}
Beispiel #3
0
TreeNode Xml_CreateNodeWithValue(const char * name, const char * format, ...)
{
    va_list args;

    TreeNode node = Xml_CreateNode(name);
    if (node == NULL)
    {
        return NULL;
    }
    va_start(args, format);
    int requiredSize = vsnprintf(NULL, 0, format, args);
    va_end(args);

    char * value = malloc(requiredSize + 1);
    if (value == NULL)
    {
        Tree_Delete(node);
        return NULL;
    }

    memset(value, 0, requiredSize + 1);

    va_start(args, format);
    vsprintf(value, format, args);
    va_end(args);

    TreeNode_SetValue(node, (const uint8_t *)value, strlen(value));

    free(value);

    return node;
}
OperationCommon * OperationCommon_New(const Session * session, SessionType sessionType)
{
    TreeNode objectsTree = ObjectsTree_New();
    OperationCommon * operation = OperationCommon_NewWithExistingObjectsTree(session, sessionType, objectsTree);
    if (operation == NULL)
    {
        Tree_Delete(objectsTree);
    }
    return operation;
}
AwaError ResponseCommon_Free(ResponseCommon ** response)
{
    AwaError result = AwaError_Unspecified;
    if ((response != NULL) && (*response != NULL))
    {
        LogFree("ResponseCommon", *response);
        FreeSimpleMap(&((*response)->PathResults));
        FreeSimpleMap(&((*response)->NulledValues));
        FreeValues(&((*response)->Values));
        Tree_Delete((*response)->ObjectsNode);
        Awa_MemSafeFree(*response);
        *response = NULL;
        result = AwaError_Success;
    }
    else
    {
        result = AwaError_OperationInvalid;
    }
    return result;
}
Beispiel #6
0
int main()
{
	FILE* the_expression = fopen ("the_expression.txt", "r");

	assert (THE_LOG);
	assert (the_expression);

	node* exp_tree = Node_NEW();

	Check_Error (Tree_Read_in (the_expression, exp_tree));

	int nTabs = 0;
	Tree_Dump (exp_tree, nTabs);
	fprintf (THE_LOG, "\n\n\n");
	Tree_Print (exp_tree);

	Tree_Delete (exp_tree);

	fclose (the_expression);
	fclose (THE_LOG);
return 0;
}
Beispiel #7
0
int Tree_Replace_Right (node* tree)
{
	int err_index;
	ASSERT_NODE_OK (tree);

	if (tree -> left) Tree_Delete (tree -> left);
	node* new_tree = tree -> right;
	node* tmp_tree = tree -> prev;

	if (tree == tree -> prev -> left )
	{ 
		Node_Delete (tree);
		Tree_Add_Left (tmp_tree, new_tree);
	}

	else
	{
		Node_Delete (tree);
		Tree_Add_Right (tmp_tree, new_tree);
	}

	ASSERT_NODE_OK (new_tree);
return HAPPY;
}