コード例 #1
0
//----------------------------------------------------------------------------//
void System::cleanupXMLParser()
{
    // bail out if no parser
    if (!d_xmlParser)
        return;

    // get parser object to do whatever cleanup it needs to
    d_xmlParser->cleanup();

    // exit if we did not create this parser object
    if (!d_ourXmlParser)
        return;

    // if parser module loaded, destroy the parser object & cleanup module
    if (d_parserModule)
    {
        // get pointer to parser deletion function
        void(*deleteFunc)(XMLParser*) = (void(*)(XMLParser*))d_parserModule->
            getSymbolAddress("destroyParser");
        // cleanup the xml parser object
        deleteFunc(d_xmlParser);

        // delete the dynamic module for the xml parser
        delete d_parserModule;
        d_parserModule = 0;
    }
#ifdef CEGUI_STATIC
    else
        //Static Linking Call
        destroyParser(d_xmlParser);
#endif

    d_xmlParser = 0;
}
コード例 #2
0
/*
    Funcao: deleteFunc()
    Deleta funcionario (apenas da arvore)
    Parametros:
        tree: ponteiro pra ponteiro da raiz
        mat: matricula do funcionario a ser excluido
*/
void deleteFunc(tArvoreBB **tree, int mat)
{
    tArvoreBB *p;
    
    if(*tree != NULL)
    {
        if(mat < (*tree)->mat)
        {
            deleteFunc(&(*tree)->esq, mat);
        }
        else if(mat > (*tree)->mat)
        {
            deleteFunc(&(*tree)->dir, mat);
        }
        else
        {
            if((*tree)->dir == NULL && (*tree)->esq == NULL)
            {
                free(*tree);
                *tree = NULL;
            }
            else if((*tree)->dir == NULL)
            {
                p = *tree;
                *tree = (*tree)->esq;
                free(p);
            }
            else if((*tree)->esq == NULL)
            {
                p = *tree;
                *tree = (*tree)->dir;
                free(p);
            }
            else
            {
                p = (*tree)->esq;
                while(p->dir != NULL)
                    p = p->dir;
                (*tree)->mat = p->mat;
                (*tree)->index = p->index;
                p->mat = mat;
                deleteFunc(&(*tree)->esq, mat);
            }
        }
    }
}
コード例 #3
0
ファイル: my_util.c プロジェクト: yangtao8571/wavy
GQueue * 		my_util_delete_queue_element	(GQueue *queue,
											 MyQueueDeleteFunc deleteFunc,
											 gpointer user_data) {
	
	guint i, len;
	GQueue *tmpQ;
	gpointer data;
	tmpQ = g_queue_new();
	// 双队列实现删除
	for (i = 0, len = g_queue_get_length (queue); i < len; i++){
		data = g_queue_peek_nth (queue, i);
		if (deleteFunc (data, user_data)) {
			my_debug ("deleting data %#x", data);
		} else {
			g_queue_push_tail (tmpQ, data);
		}
	}
	return tmpQ;
}
コード例 #4
0
ファイル: BST.c プロジェクト: IIITD2015/MY-DSA
int main(int argc,char *argv[]){
	char *tok,line[MAX],*filename=argv[1],*initTree="InitTree",*insert="Insert",*delete="Delete",*find="Find",*height="Height",*printTree="PrintTree";	
	BST **T=(BST**)malloc(sizeof(BST*));
	int numOper=2,numLines=0;

	//FILE *fileCountLines=fopen(filename,"r");
	//while(fgets(line,sizeof line,fileCountLines)!=NULL){
	//	numLines++;
	//}
	//fclose(fileCountLines);

	numOper=numLines-1;
	
	FILE *file=fopen(filename,"r");
	while(fgets(line,sizeof line,file)!=NULL){
		
		trim(line);
		tok=strtok(line," ");

		if(strcmp(line,initTree)==0){
			char *initTreeParam;

                        tok=strtok(NULL," ");
			initTreeParam=tok;
                        *T=initTreeFunc(initTreeParam);
			tok=strtok(NULL," ");
		}
		
		else if(strcmp(line,insert)==0){
			char *insertParam;
			tok=strtok(NULL," ");
			insertParam=tok;
			insertFunc(insertParam,T);
			tok=strtok(NULL," ");
		}
		
		else if(strcmp(line,delete)==0){
			char *deleteParam;
			tok=strtok(NULL," ");
			deleteParam=tok;
			deleteFunc(deleteParam,T);
			tok=strtok(NULL," ");
		}
			
		else if(strcmp(line,find)==0){
			char *findParam;
			tok=strtok(NULL," ");
			findParam=tok;
			findFunc(findParam,(*T));
			tok=strtok(NULL," ");
		}
		
		else if(strcmp(line,height)==0){
           		int height=heightFunc(*T);
			printf("%d\n",height);
                        tok=strtok(NULL," ");
                }
		
		else if(strcmp(line,printTree)==0){
                        int printTreeParam;
                        tok=strtok(NULL," ");
                        printTreeParam=atoi(tok);
                        printTreeFunc(*T,printTreeParam);
                        tok=strtok(NULL," ");
			printf("\n");
                }
	}
コード例 #5
0
void socketMode(tArvoreBB **tree, FILE **arq)
{
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2), &wsaData);
    
    SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
    char buf[32] = {0}, op = 1;
    
    
    
    if(sock != INVALID_SOCKET)
    {
        struct sockaddr_in serv_addr = {0};

        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = INADDR_ANY;
        serv_addr.sin_port = htons(PORT);

        if(bind(sock, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) == 0)
        {
            int len;
            struct sockaddr_in cli_addr;
            SOCKET newsock;
            
            listen(sock, BACKLOG);
            len = sizeof(struct sockaddr_in);
            newsock = accept(sock, (struct sockaddr *) &cli_addr, &len);
            // if (newsock != INVALID_SOCKET)
            //    printf("Nova conexao: %s:%d\n", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
            while(op != 0)
            {
                if (newsock != INVALID_SOCKET)
                {
                    while(recv(newsock, buf, sizeof(buf)-1, 0) <=0);
                    //printf("received: %s\n", buf);
                    op = buf[strlen(buf)-1] - 48;
                    
                    tfunc func;
                    char buffer[30]={0};
                        
                    strncpy(buffer, buf, 3);
                    buffer[3] = '\0';
                    func.mat = atoi(buffer);
                    strncpy(func.nome,buf+3,20);
                    func.nome[20] = '\0';
                    strncpy(buffer,buf+23,7);
                    buffer[7] = '\0';
                    func.sal = atof(buffer);
                    
                    switch(op)
                    {
                        
                        case 1:
                        {
                            insertFunc(*arq, tree, func);
                            break;
                        }
                        case 2:
                        {
                            alterSalary(arq, *tree, func.mat, func.sal);
                            break;
                        }
                        case 3:
                        {
                            deleteFunc(tree,func.mat);
                            break;
                        }
                        case 4:
                        {
                            listFunc(*arq, *tree, func.mat);  
                            break;
                        }
                        case 5:
                            listAll(*arq, *tree);
                            break;
                        case 6:
                            listStruct(*tree);
                            break;
                        case 7:
                            reindex(arq, tree);
                            break;
                        case 8:
                            deleteAll(tree, arq);
                            break;
                    }
                    
                }
                else
                {
                    printf("Erro ao conectar\n");
                }
            }
        }
        else
        {
            printf("Erro no bind()\n");
        }
    }
    
}
コード例 #6
0
ファイル: hash-pari.c プロジェクト: IIITD2015/MY-DSA
/**
** main function to start the execution 
**/   
int main(int argc, char *argv[]){

	printf("\n\t"
        "*********************************************** \n\t"
        "      Program to implement a hast-table.  \n\t"
        "(Values inserted from the mentioned input file) \n\t"
        "*********************************************** \n \n");
		
	char *filename="input", line[MAX], *tok, *name;
	int foundHashSize=0, key, userSelectedOption, isExit=0, searchKey;

	/* Just to calculate the size of HashTable */	
	FILE *file=fopen(filename, "r");
	while(fgets(line, sizeof line, file) != NULL){
		
		/* fetching the size of hashTable and breaking */
		if(!foundHashSize){
                        hashSize=atoi(line);
                        foundHashSize=1;
                        break;
                }
	}
	fclose(file);

	/* Creating the hashTable with the userDefined Size */
	foundHashSize=0;
	struct myHashTable hashTable[hashSize];	
	
	/* Initializing the Bucket with NULL */
	int index;
	for(index=0;index<hashSize;index++)
		hashTable[index].first=NULL;

	/* Insert operation of hashtable, is a mandatory operation */
	FILE *fileRem=fopen(filename, "r");

	printf("\tFollowing elements are inserted with their corresponding bucket number.\n\tCalculated from the hashfunction:- Marks mod %d \n\n",hashSize);
	printf("\tHash\n\t");
	while(fgets(line, sizeof line, file) != NULL){
		
		/* Skipping the very first line, sice this is just the size of hashTable */
		if(!foundHashSize){
			foundHashSize=1;
			continue;
		}
		else{
			/* tokenizing the line with colon (:) */
			tok=strtok(line, ":");
			name=tok;
			tok=strtok(NULL, " ");
			key=atoi(tok);
			tok=strtok(NULL, " ");

			/* inserting the tokenized values i.e name and key of the student */
			insertFunc(hashTable, name, key);	
		}
	}
	fclose(fileRem);	
	printf("NULL\n\n");

	do{
		printf("\t"
		"Please choose anyone of the options below:- \n\t"
		"1] Delete any element. \n\t"
		"2] Print the hashTable. \n\t"
		"3] Do you want to exit?? \n");
		printf("\n\tYour option number: ");
		scanf("%d",&userSelectedOption);
		printf("\n");
	
		switch(userSelectedOption){
			case 1:{
				printf("\tPlease enter the key to search: ");
				scanf("%d",&searchKey);
				deleteFunc(hashTable,searchKey,hashSize);
			}
			break;
		
			case 2:{
				printHashFunc(hashTable,hashSize);
				printf("\n\n");
                        }
                        break;
	
			case 3:
				isExit=1;
				break;
			
			default:
				printf("Please choose a valid option!!!");
				break;		
		}
	}while(!isExit);
	return 0;
}