int main(int argc, char * argv[]) { struct PState pstate = {"Unknown", 1, false, "", false, -1}; struct List itemlist = {NULL, NULL}; struct ShoppingCart cart = {NULL, NULL}; char path[PATHSIZE]; struct Item * temp; // printf("Pstate->name: %s, Pstate->amount: %d\n", pstate.itemname, pstate.amount); if (argc > 1) { get_args(argc, argv, &pstate); getFilePath(path, &pstate); if (loadAllItems(&itemlist, path) == EL_FAIL) { printf("Could not read the items.\n"); exit(EXIT_FAILURE); } if (pstate.itemid >= 0) { if (( temp = findItemId(itemlist.head, pstate.itemid)) != NULL) { strcpy(pstate.itemname, temp->name); } } /// If we have a lookup or search request, execute it and exit program if (pstate.search) { printf("Searching for %s.\n", pstate.itemname); searchItem(&itemlist, pstate.itemname); freeItemList(&itemlist); exit(EXIT_SUCCESS); } else if (pstate.lookup) { printf("Looking for %s.\n", pstate.itemname); lookup(&itemlist, pstate.itemname); freeItemList(&itemlist); exit(EXIT_SUCCESS); } printf("\nCalculations for %d %s\n\n", pstate.amount, pstate.itemname); printf("Filling shopping cart.\n\n"); if (buildShoppingList(&itemlist, &cart, pstate.itemname, pstate.amount) == EL_FAIL) { printf("Failure to build shopping list.\n"); exit(EXIT_FAILURE); } printf("\n\nTotals for %d %s\n\n", pstate.amount, pstate.itemname); printShoppingList(cart.head); freeItemList(&itemlist); freeCart(&cart); } else { printf("\nMissing parameters. \nUse: \n\t%s --help\nfor correct syntax\n\n", argv[0]); } return 0; }
void XFE_URLDesktopType::createItemList(int listSize) { if (_numItems>0) freeItemList(); _url=new char*[listSize]; _title=new char*[listSize]; _description=new char*[listSize]; _filename=new char*[listSize]; _numItems=listSize; for (int i=0;i<listSize;i++) { _url[i]=NULL; _title[i]=NULL; _description[i]=NULL; _filename[i]=NULL; } }
XFE_URLDesktopType::~XFE_URLDesktopType() { freeItemList(); }