/*delete menu*/ int DeleteMenu(tMenu *pMenu) { if(pMenu == NULL) { return FAILURE; } if(!DeleteLinkTable(pMenu->pMenuHead)) { printf("Delete menu success!\n\n"); free(pMenu); return SUCCESS; } else { printf("Delete menu failed!\n\n"); return FAILURE; } }
int main() { int i; tLinkTable * pLinkTable = CreateLinkTable(); /* init menu whih the common item, help, version, and exit */ InitMenuItem(pLinkTable); /* Add new item to the exist menu dynamicly */ AddMenuItem(pLinkTable, "add1", "add menu1", add1); AddMenuItem(pLinkTable, "add2", "add menu2", add1); /* cmd line begins */ while(1) { char cmd[CMD_MAX_LEN]; printf("Input a cmd > "); scanf("%s", cmd); /* call the func to run the menu */ RunMenu(pLinkTable, cmd); } DeleteLinkTable(pLinkTable); }
int main() { int i; tLinkTable * pLinkTable = CreateLinkTable(); for(i = 0; i < 10; i++) { tNode* pNode = (tNode*)malloc(sizeof(tNode)); pNode->data = i; debug("AddLinkTableNode\n"); AddLinkTableNode(pLinkTable,(tLinkTableNode *)pNode); } /* search by callback */ debug("SearchLinkTableNode\n"); tNode* pTempNode = (tNode*)SearchLinkTableNode(pLinkTable,SearchConditon); printf("%d\n",pTempNode->data); /* search one by one */ pTempNode = Search(pLinkTable); printf("%d\n",pTempNode->data); debug("DelLinkTableNode\n"); DelLinkTableNode(pLinkTable,(tLinkTableNode *)pTempNode); free(pTempNode); DeleteLinkTable(pLinkTable); }
int Exit(tLinkTable * pLinkTable) { DeleteLinkTable(pLinkTable); exit(0); return 0; }