void * consume(void *arg) { printf("at=started-consum\n"); list *l = (list *)arg; while(1) { char buf[32]; listDeleteFirst(l); } printf("at=finished-consum\n"); return 0; }
int main() { TTable table; tableInit(&table); printf("\nTabulka by mela byt prazdna: \n"); tablePrintOrder(table); printf("\n----------------------------\n"); tableInsertFunction(&table, strCreateString("func1")); functionInsertVar(table.lastAddedFunc, strCreateString("var1func1")); functionInsertVar(table.lastAddedFunc, strCreateString("var2func1")); functionInsertVar(table.lastAddedFunc, strCreateString("var3func1")); printf("\nJedna funkce: \n"); tablePrintOrder(table); printf("\n----------------------------\n"); tableInsertFunction(&table, strCreateString("func2")); functionInsertVar(table.lastAddedFunc, strCreateString("var1func2")); functionInsertVar(table.lastAddedFunc, strCreateString("var2func2")); functionInsertVar(table.lastAddedFunc, strCreateString("var3func2")); printf("\nDve funkce: \n"); tablePrintOrder(table); printf("\n----------------------------\n"); tableInsertFunction(&table, strCreateString("func3")); functionInsertVar(table.lastAddedFunc, strCreateString("var1func3")); functionInsertVar(table.lastAddedFunc, strCreateString("var2func3")); functionInsertVar(table.lastAddedFunc, strCreateString("var3func3")); printf("\nVsechny: \n"); tablePrintOrder(table); printf("\n----------------------------\n"); // test heldani { TFunction *fceSearch; printf("\nObsahuje tabulka funkci %s? \t", "func1"); fceSearch = tableSearchFunction(&table, strCreateString("func1")); if(fceSearch != NULL) { printf("ANO\n"); printf(" Obsahuje funkce promenou %s?\t", "var1func1"); if(functionSearchVar(fceSearch, strCreateString("var1func1")) != NULL) printf("ANO"); else printf("NE"); } else printf("NE\n"); printf("\nObsahuje tabulka funkci %s? \t", "funcX"); fceSearch = tableSearchFunction(&table, strCreateString("funcX")); if(fceSearch != NULL) { printf("ANO\n"); printf(" Obsahuje funkce promenou %s?\t", "var1func1"); if(functionSearchVar(fceSearch, strCreateString("var1func1")) != NULL) printf("ANO"); else printf("NE"); } else printf("NE\n"); printf("\n----------------------------\n"); } // test zásobníku: printf("TEST ZASOBNIKU:\n"); printf("----------------------------\n"); TStack s; stackInit(&s); prazdnyStack(s); TFunction *fce = tableSearchFunction(&table, strCreateString("func2")); TVar *id = functionSearchVar(fce, strCreateString("var1func2")); stackPush(&s, (void*)id); prazdnyStack(s); tiskniStack(&s); id = functionSearchVar(fce, strCreateString("var2func2")); stackPush(&s, (void*)id); tiskniStack(&s); id = functionSearchVar(fce, strCreateString("var3func2")); stackPush(&s, (void*)id); tiskniStack(&s); id = functionSearchVar(fce, strCreateString("var1func2")); stackPush(&s, (void*)id); tiskniStack(&s); TVar *data = (TVar*)stackTopPop(&s); if (data != NULL) printf("Vybráno ze zásobníku: %s\n",data->name); else printf("Ukazatel je nulový! \n"); prazdnyStack(s); data = (TVar*)stackTopPop(&s); if (data != NULL) printf("Vybráno ze zásobníku: %s\n",data->name); else printf("Ukazatel je nulový! \n"); prazdnyStack(s); data = (TVar*)stackTopPop(&s); if (data != NULL) printf("Vybráno ze zásobníku: %s\n",data->name); else printf("Ukazatel je nulový! \n"); prazdnyStack(s); tiskniStack(&s); stackDelete (&s); prazdnyStack(s); tiskniStack(&s); data = (TVar*)stackTopPop(&s); if (data != NULL) printf("Vybráno ze zásobníku: %s\n",data->name); else printf("Ukazatel je nulový! \n"); printf("----------------------------\n"); // test seznamu: printf("TEST SEZNAMU:\n"); printf("----------------------------\n"); TList L; listInit (&L); id = functionSearchVar(fce, strCreateString("var1func2")); TLItem *uk2 = listGetActive (&L); listSetActive(&L, uk2); aktivniList(L); listInsertLast(&L, id); tiskniList(&L); void *uk4 = listCopyLast(&L); printf("Zkopírováno: %s\n",((TVar*)uk4)->name); aktivniList(L); listFirst(&L); tiskniList(&L); listLast(&L); tiskniList(&L); id = functionSearchVar(fce, strCreateString("var2func2")); listPostInsert(&L, id); tiskniList(&L); id = functionSearchVar(fce, strCreateString("var3func2")); listInsertLast(&L, id); tiskniList(&L); id = functionSearchVar(fce, strCreateString("var1func2")); listInsertLast(&L, id); tiskniList(&L); listFirst(&L); listSucc(&L); TLItem *uk = listGetActive (&L); tiskniList(&L); listLast(&L); tiskniList(&L); listSetActive(&L, uk); tiskniList(&L); aktivniList(L); listDeleteFirst(&L); tiskniList(&L); void *uk3 = listCopyLast(&L); printf("Zkopírováno: %s\n",((TVar*)uk3)->name); listSucc(&L); tiskniList(&L); listActualize(&L, uk3); tiskniList(&L); listDispose (&L); printf("----------------------------\n"); // konec testu seznamu printf("\nSmazu: \n"); tableClear(&table); tablePrintOrder(table); printf("\n----------------------------\n"); }