Esempio n. 1
0
void insertBook(BookListHndl L, char * title, int id)
{

	BookNodePtr tempNode;
	char * tempTitle;
	assert (L != NULL);
	tempTitle = malloc(sizeof(char) * 50);
	
	strcpy(tempTitle, title);
	
	if(L->first != NULL)
	{
		L->curr = L->first;
		while (L->curr != NULL)
		{
		/*printf("comparing %s and %s, which gives %d\n", L->curr->title, title, strcmp(L->curr->title, tempTitle) );*/
			if(strcmp(L->curr->title, tempTitle) == 0)
			{
				insertID(L, id);
				L->curr = L->first;
				return;
			}
			L->curr = L->curr->next;
		}
	}
	L->curr = L->first;
	
	tempNode = malloc ( sizeof(struct BookNodeStruct) );

	tempNode->title = malloc ( sizeof(char) * 50 );
	strcpy(tempNode->title, tempTitle);
	tempNode->bookIDs = NewList();
	insertAtFront(tempNode->bookIDs, id);
	tempNode->next = L->first;
	tempNode->prev = NULL;

	if(L->first == NULL)
	/*this means we're adding the first element, meaning L needs to have curr, first, & last assigned.*/
	{ 
		L->first = tempNode;
		L->last = tempNode;
		L->curr = tempNode;
	}
	else
	{
		L->first->prev = tempNode;
		L->first = tempNode;
	}
	L->curr = L->first;
	/*printf("Successfully inserted a new node in the front \n");*/
}
Esempio n. 2
0
/* Method to insert the Program Node */
Node* insertClass(char* id, Node* statements) {
    if(DEBUG)printf("Inserting Class (%s) \n\n",id);
    Node* newClass = (Node*) calloc(sizeof(Node),1);
    if(newClass == NULL) {
        if(DEBUG)printf("Error in malloc [insertClass]\n");
        assert(newClass != NULL);
    }

    //Set the node type
    newClass->n_type = NODE_PROGRAM;
    //Insert the ID of the Program Node
    newClass->id = insertID(newClass, id);
    newClass->next = statements;
    return newClass;
}
Esempio n. 3
0
Node* createCall(char* id, Node *args) {
    Node * newCall = (Node*)calloc(sizeof(Node),1);
    if(newCall == NULL) {
        if(DEBUG)
            printf("newCall: Error Malloc\n");
        assert(newCall != NULL);
    }

    newCall-> n_type = NODE_CALL;
    insertID(newCall, id);
    newCall->n1      = args;
    newCall->next    = NULL;

    return newCall;
}
Esempio n. 4
0
Node* newMethod(int type, char* id, Node* params, Node* varDecl, Node* statements){
    if(DEBUG)printf("Inserting New method(%s)\n",id);
    Node* tmp;
    Node* newMethod = (Node*) calloc(sizeof(Node),1);
    if(newMethod==NULL){
        if(DEBUG)printf("Error in malloc insertClass\n");
        assert(newMethod!=NULL);
    }

    //set the node type
    newMethod->n_type = NODE_METHODDECL;
    newMethod->type   = type;
    newMethod->id     = insertID(newMethod, id);

    tmp = (Node*) calloc(sizeof(Node),1);
    assert(tmp!=NULL);
    tmp->n_type   = NODE_METHODPARAMS;
    newMethod->n1 = tmp;
    tmp->n1       = params;

    tmp = (Node*) calloc(sizeof(Node),1);
    assert(tmp != NULL);
    tmp->n_type = NODE_METHODBODY;
    newMethod->n2 = tmp;
    tmp->n1 = varDecl;
/*    if(params == NULL)
        newMethod->n1 = createNull();
    if(varDecl == NULL)
        newMethod->n2 = createNull();
    if(statements == NULL)
        newMethod->n3 = createNull();*/

    tmp = (Node*) calloc(sizeof(Node),1);
    assert(tmp!=NULL);
    newMethod->n3   = tmp;
    tmp->n_type     = NODE_DONTPRINT;
    tmp->n1         = statements;

    newMethod->next = NULL;
    return newMethod;
}