static void test_basics(void) { Queue *q = QueueNew(free); assert_int_equal(0, QueueCount(q)); assert_true(QueueIsEmpty(q)); QueueEnqueue(q, xstrdup("hello")); assert_int_equal(1, QueueCount(q)); assert_false(QueueIsEmpty(q)); assert_string_equal("hello", QueueHead(q)); QueueEnqueue(q, xstrdup("world")); assert_int_equal(2, QueueCount(q)); assert_string_equal("hello", QueueHead(q)); char *head = QueueDequeue(q); assert_string_equal("hello", head); free(head); assert_string_equal("world", QueueHead(q)); head = QueueDequeue(q); assert_string_equal("world", head); free(head); QueueDestroy(q); }
static int preprocess_batch(BATCH batch ) { int iStatus; int count; static char * this_func = "preprocess_batch"; char szSet[256]; (void)arb_put_state(dbproc,ARB_STATUS_PREPROC); /* Lock files */ sprintf(szSet, " SET dispatch_status = %d ", BID_IN_PROGRESS); count = set_bill_files(szSet, NULL, batch->batch_id, bid_hold_flag, bid_error_flag, RERUN ? BID_COMPLETE : BID_NOT_STARTED); if (count < 0) return(count); if (0 == count) { emit(BIDMOD,BID_NO_FILES,this_func); return(BID_NO_FILES); } /* Lock all available devices for BID that PRINTs */ /* Don't need to lock devices for BID that FTPs LLT */ if (!BID_ftp) { get_all_devices(bid_queueDevices); /* depends on DISPATCH_TYPE */ if (0 >= QueueCount(bid_queueDevices)) { emit(BIDMOD,BID_NO_FIND_DEV_TYPE,this_func,DISPATCH_TYPE); return(-1); } lock_all_devices(); /* result -->> bid_queueDevicesLocked */ if (0 >= QueueCount(bid_queueDevicesLocked)) { emit(BIDMOD,BID_NO_LOCK_DEV_TYPE,this_func,DISPATCH_TYPE); return(-1); } } /* Get list of files in this batch. -->> bid_queueFiles */ if (SUCCESS != (iStatus = get_file_list(bid_queueFiles, batch->batch_id, bid_hold_flag, bid_error_flag))) return(iStatus); count = QueueCount(bid_queueFiles); emit(BIDMOD,BID_NUM_FILES_BATCH,this_func,count); if (count) return(SUCCESS); else return(NO_BILL_FILES); }
static int postprocess_batch(BATCH batch ) { int count; static char * this_func = "postprocess_batch"; (void)arb_put_state(dbproc,ARB_STATUS_POSTPROC); /* Devices are lock for BID that PRINTs but not for BID that FTPs LLT */ if (!BID_ftp) { unlock_all_devices(); /* all devices moved back to bid_queueDevices */ count = QueueCount(bid_queueDevicesLocked); /* still locked */ if (0 < count) { emit(BIDMOD,BID_UNLOCK_DEV_FAIL,this_func, count); return(-1); } } finalize_all_files(batch); /* Generate and print control report(s), including FAXNO report */ return(SUCCESS); }
/* ** MapQueueMove ** ** Applies a function to each element in a queue. If the function returns ** moveVal, it enqueues the element to q2, otherwise it requeues it to ** the original queue. */ int MapQueueMove(QUEUE q, int (*pFunc)(void *, void**), void **argv, int moveVal, QUEUE q2) { void *item; int count = QueueCount(q); int status = SUCCESS; TypeCheck(q,TYPE_QUEUE); TypeCheck(q2,TYPE_QUEUE); assert(! IS_ERROR(moveVal)); while (count--) { item = DeQueue(q); if (NULL == item) return(-1); status = (*pFunc)(item,argv); if (IS_ERROR(status)) return(status); if (status == moveVal) status = EnQueue(q2,item); else status = EnQueue(q,item); if (IS_ERROR(status)) return(status); } return(status); }
int DeleteList(int argc, char *argv[]) { char buf[BUFSIZ]; struct mqelem *top, *list; int status; Bool one_list; list = NULL; switch ((status = do_mr_query("get_list_info", 1, argv + 1, StoreInfo, &list))) { case MR_SUCCESS: break; case MR_NO_MATCH: case MR_LIST: Put_message("There is no list that matches that name."); return DM_NORMAL; default: com_err(program_name, status, " in DeleteList (get_list_info)."); return DM_NORMAL; } top = list = QueueTop(list); one_list = (QueueCount(list) == 1); while (list) { char **info = list->q_data; if (one_list) { sprintf(buf, "Are you sure that you want to delete the list %s", info[L_NAME]); if (Confirm(buf)) AttemptToDeleteList(info, TRUE); } else { sprintf(buf, "Delete the list %s", info[L_NAME]); switch (YesNoQuestion(buf, FALSE)) { case TRUE: AttemptToDeleteList(info, TRUE); break; case FALSE: break; default: Put_message("Aborting..."); FreeQueue(top); return DM_QUIT; } } list = list->q_forw; } FreeQueue(top); return DM_NORMAL; }
static void test_destroy(void) { Queue *q = QueueNew(free); QueueEnqueue(q, xstrdup("1")); QueueEnqueue(q, xstrdup("2")); QueueEnqueue(q, xstrdup("3")); assert_int_equal(3, QueueCount(q)); QueueDestroy(q); }
/////////////////////////////////////////////////////////////////////////////// // ReqMgrResume // // Description: // Continues (and completes if possible) a pending request for objects, // if any. // // Inputs: // pReqMgr - Pointer to a request manager. // // Outputs: // pCount - Number of objects available for a resuming request. // ppfnCallback - Contains the callback function pointer as provided // in the ReqMgrGet function. // pContext1 - Contains the Context1 value for the resuming request, // as provided in the ReqMgrGet function. // pContext2 - Contains the Context2 value for the resuming request, // as provided in the ReqMgrGet function. // // Returns: // FSUCCESS - A request was completed. // FNOT_DONE - There were no pending requests. // FINSUFFICIENT_RESOURCES - There were not enough resources to complete a // pending request. // FPENDING - A request was continued, but not completed. // // Remarks: // At most one requset is resumed. // /////////////////////////////////////////////////////////////////////////////// FSTATUS ReqMgrResume( IN REQ_MGR* const pReqMgr, OUT uint32* const pCount, OUT REQ_CALLBACK* const ppfnCallback, OUT void** const pContext1, OUT void** const pContext2 ) { uint32 AvailableCount; REQUEST_OBJECT *pQueuedRequest; ASSERT( pReqMgr ); ASSERT( pReqMgr->m_Initialized ); // If no requests are pending, there's nothing to return. if( !QueueCount( &pReqMgr->m_RequestQueue ) ) return FNOT_DONE; // Get the item at the head of the request queue, but do not remove it yet. pQueuedRequest = (REQUEST_OBJECT*) QueueGetHead( &pReqMgr->m_RequestQueue ); // If no requests are pending, there's nothing to return. if (pQueuedRequest == NULL) return FNOT_DONE; *ppfnCallback = pQueuedRequest->pfnCallback; *pContext1 = pQueuedRequest->Context1; *pContext2 = pQueuedRequest->Context2; AvailableCount = pReqMgr->m_pfnGetCount( pReqMgr->m_GetContext ); // See if the request can be fulfilled. if( pQueuedRequest->Count > AvailableCount ) { if( !pQueuedRequest->PartialOk ) return( FINSUFFICIENT_RESOURCES ); pQueuedRequest->Count -= AvailableCount; *pCount = AvailableCount; return( FPENDING ); } *pCount = pQueuedRequest->Count; // The entire request can be met. Remove it from the request queue // and return. QueueRemove( &pReqMgr->m_RequestQueue ); // Return the internal request object to the free stack. GrowPoolPut( &pReqMgr->m_RequestPool, pQueuedRequest ); return( FSUCCESS ); }
int CheckIfAce(char *name, char *type, Bool verbose) { char *args[2], buf[BUFSIZ], **info; struct mqelem *local, *elem; int status; elem = NULL; args[0] = type; args[1] = name; switch ((status = do_mr_query("get_ace_use", 2, args, StoreInfo, &elem))) { case MR_NO_MATCH: return DM_NORMAL; case MR_SUCCESS: local = elem = QueueTop(elem); info = local->q_data; if (QueueCount(elem) == 1 && !strcmp(info[0], "LIST") && !strcmp(info[1], name)) { FreeQueue(elem); return DM_NORMAL; } if (verbose) { sprintf(buf, "%s %s %s", type, name, "is the ACE for the following data objects:"); Put_message(buf); Put_message(""); for (; local != NULL; local = local->q_forw) { info = local->q_data; if (!strcmp(info[0], "LIST") && !strcmp(info[1], name)) continue; Print(CountArgs(info), info, NULL); } Put_message(""); Put_message("The ACE for each of these items must be changed before"); sprintf(buf, "the %s %s can be deleted.\n", type, name); Put_message(buf); } break; default: com_err(program_name, status, " in CheckIfAce (get_ace_use)."); return SUB_ERROR; } FreeQueue(elem); return SUB_ERROR; }
int AddFSToGroup(int argc, char **argv) { int stat, count; struct mqelem *elem = NULL; char buf[BUFSIZ], *args[5], *bufp; if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo, &elem))) { if (stat != MR_NO_MATCH) com_err(program_name, stat, " in AddFSToGroup"); } if (elem == NULL) { args[0] = argv[1]; args[1] = argv[2]; args[2] = "M"; stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL); if (stat) com_err(program_name, stat, " in AddFSToGroup"); return DM_NORMAL; } elem = QueueTop(elem); fsgCount = 1; Loop(elem, PrintFSGMembers); sprintf(buf, "%d", QueueCount(elem)); bufp = strdup(buf); if (GetValueFromUser("Enter number of filesystem it should follow " "(0 to make it first):", &bufp) == SUB_ERROR) return DM_NORMAL; count = atoi(bufp); free(bufp); args[2] = SortAfter(elem, count); FreeQueue(QueueTop(elem)); args[0] = argv[1]; args[1] = argv[2]; stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL); if (stat == MR_EXISTS) { Put_message("That filesystem is already a member of the group."); Put_message("Use the order command if you want to change the " "sorting order."); } else if (stat) com_err(program_name, stat, " in AddFSToGroup"); return DM_NORMAL; }
static char *GetUidNumberFromName(void) { char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; int status; struct mqelem *top = NULL; if (!Prompt_input("First Name: ", first, BUFSIZ)) return NULL; if (!Prompt_input("Last Name: ", last, BUFSIZ)) return NULL; FixCase(first); FixCase(last); args[0] = first; args[1] = last; switch ((status = do_mr_query("get_user_account_by_name", 2, args, StoreInfo, &top))) { case MR_SUCCESS: break; case MR_NO_MATCH: Put_message("There is no user in the database with that name."); return NULL; default: com_err(program_name, status, " in get_account_user_by_name."); return NULL; } top = QueueTop(top); if (QueueCount(top) == 1) /* This is a unique name. */ { char **info = top->q_data; Put_message("User ID Number retrieved for the user: "******""); PrintUserName(info); uid = strdup(info[U_UID]); FreeQueue(top); return strdup(uid); } Put_message("That name is not unique, choose the user that you want."); uid = ChooseUser(top); FreeQueue(top); return uid; }
/////////////////////////////////////////////////////////////////////////////// // ReqMgrGet // // Description: // Retrieves a number of objects, either synchronously or asynchronously. // // Inputs: // pReqMgr - Pointer to a request manager. // pCount - Contains the number of objects to retrieve. // ReqType - Type of get operation. Can be ReqGetSync, ReqGetAsync, or // ReqGetAsyncPartialOk. // pfnCallback - Pointer to a callback function to store for the request. // Context1 - First of two contexts passed to the request callback. // Context2 - Second of two contexts passed to the request callback. // // Outputs: // pCount - Contains the number of objects available. // // Returns: // FSUCCESS - The request callback has been invoked with elements to // satisfy the request. If the request allowed partial // completions, all elements are guaranteed to have been returned. // FPENDING - The request could not complete in it's entirety. If the // request allowed partial completion, some elements may have been // already returned. // FINSUFFICIENT_RESOURCES - There were not enough objects for the request to // succeed. // FINSUFFICIENT_MEMORY - There was not enough memory to process the // request (including queuing the request). // /////////////////////////////////////////////////////////////////////////////// FSTATUS ReqMgrGet( IN REQ_MGR* const pReqMgr, IN OUT uint32* const pCount, IN const REQ_MGR_TYPE ReqType, IN REQ_CALLBACK pfnCallback, IN void* const Context1, IN void* const Context2 ) { uint32 AvailableCount; uint32 Count; REQUEST_OBJECT *pRequest; ASSERT( pReqMgr ); ASSERT( pReqMgr->m_Initialized ); ASSERT( pCount ); ASSERT( *pCount ); // Get the number of available objects in the grow pool. AvailableCount = pReqMgr->m_pfnGetCount( pReqMgr->m_GetContext ); // Check to see if there is nothing on the queue, and there are // enough items to satisfy the whole request. if( !QueueCount( &pReqMgr->m_RequestQueue ) && *pCount <= AvailableCount ) return( FSUCCESS ); if( ReqType == ReqGetSync ) return( FINSUFFICIENT_RESOURCES ); // We need a request object to place on the request queue. pRequest = (REQUEST_OBJECT*)GrowPoolGet( &pReqMgr->m_RequestPool ); if( !pRequest ) return( FINSUFFICIENT_MEMORY ); // We can return the available number of objects but we still need // to queue a request for the remainder. if( ReqType == ReqGetAsyncPartialOk && !QueueCount( &pReqMgr->m_RequestQueue ) ) { Count = *pCount - AvailableCount; *pCount = AvailableCount; pRequest->PartialOk = TRUE; } else { // We cannot return any objects. We queue a request for all of them. Count = *pCount; *pCount = 0; pRequest->PartialOk = FALSE; } // Set the request fields and enqueue it. pRequest->pfnCallback = pfnCallback; pRequest->Context1 = Context1; pRequest->Context2 = Context2; pRequest->Count = Count; if( !QueueInsert( &pReqMgr->m_RequestQueue, pRequest ) ) { // We could not queue the request. Return the request to the pool. GrowPoolPut( &pReqMgr->m_RequestPool, pRequest ); return( FINSUFFICIENT_MEMORY ); } return( FPENDING ); }
int RemoveMembersOfList(char *name, Bool verbose) { char buf[BUFSIZ], *args[10]; struct mqelem *local, *elem = NULL; int status, members; /* * Get the members of this list. */ status = do_mr_query("get_members_of_list", 1, &name, StoreInfo, &elem); if (status == MR_NO_MATCH) return SUB_NORMAL; if (status) { com_err(program_name, status, " in DeleteList (get_members_of_list)."); return SUB_ERROR; } /* * If verbose mode, then ask the user if we should delete. */ local = elem = QueueTop(elem); if (!(members = QueueCount(elem))) return SUB_NORMAL; if (verbose) { sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem), ((members == 1) ? "" : "s")); Put_message(buf); Put_message(" "); /* Blank Line. */ while (local) { char **info = local->q_data; Print(CountArgs(info), info, NULL); local = local->q_forw; } Put_message(" "); /* Blank Line. */ sprintf(buf, "Remove th%s member%s from list %s? ", ((members == 1) ? "is" : "ese"), ((members == 1) ? "" : "s"), name); if (YesNoQuestion(buf, FALSE) != TRUE) { Put_message("Aborting..."); FreeQueue(elem); return SUB_ERROR; } } /* * Perform The Removal. */ local = elem; args[0] = name; while (local) { char **info = local->q_data; args[1] = info[0]; args[2] = info[1]; if ((status = do_mr_query("delete_member_from_list", 3, args, NULL, NULL))) { com_err(program_name, status, " in delete_member\nAborting\n"); FreeQueue(elem); return SUB_ERROR; } local = local->q_forw; } return SUB_NORMAL; }
int RemoveItemFromLists(char *name, char *type, struct mqelem **elem, int verbose) { struct mqelem *local; char *args[10], temp_buf[BUFSIZ]; int lists; int status; args[0] = type; args[1] = name; *elem = NULL; /* * Get all list of which this item is a member, and store them in a queue. */ status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, elem); if (status == MR_NO_MATCH) return SUB_NORMAL; if (status != MR_SUCCESS) { com_err(program_name, status, " in DeleteList (get_lists_of_member)."); return SUB_ERROR; } /* * If verbose mode, ask user of we should remove our list from * all these lists. */ local = *elem = QueueTop(*elem); lists = QueueCount(*elem); if (lists == 0) return SUB_NORMAL; if (verbose) { sprintf(temp_buf, "%s %s is a member of %d other list%s.\n", type, name, lists, ((lists == 1) ? "" : "s")); Put_message(temp_buf); while (local) { char **info = local->q_data; Print(1, &info[GLOM_NAME], (char *) NULL); local = local->q_forw; } Put_message(" "); /* Blank Line. */ sprintf(temp_buf, "Remove %s %s from these lists? ", type, name); if (YesNoQuestion(temp_buf, FALSE) != TRUE) { Put_message("Aborting..."); FreeQueue(*elem); *elem = NULL; return SUB_ERROR; } } /* * Remove this list from all lists that it is a member of. */ local = *elem; args[DM_MEMBER] = name; args[DM_TYPE] = type; while (local) { char **info = local->q_data; args[DM_LIST] = info[GLOM_NAME]; if ((status = do_mr_query("delete_member_from_list", 3, args, NULL, NULL))) { com_err(program_name, status, " in delete_member\nAborting\n"); FreeQueue(*elem); return SUB_ERROR; } local = local->q_forw; } return SUB_NORMAL; }
int main(void) { QUEUE Queue = {0}; CASHIER *Cashier = NULL; CASHIER EmptyCashier = {0}; CUSTOMER Customer = {0}; CUSTOMER EmptyCustomer = {0}; int CustomerNumber = 0; int TotalItems = 0; int TotalItemsSold = 0; int SatisfiedCustomers = 0; long TotalWaitTime = 0; double Balance; int NumCashiers; unsigned long TempCashiers; long CurrentSecond; char Buff[10]; char *endp; double p; int i; int NumCustomers = 0; srand((unsigned)time(NULL)); /* get data from user */ printf("Welcome to ShopSim!\n\n"); printf("Your goal is to maximise profit.\n"); printf("Income is number of items processed * %f.\n", PROFIT_PER_ITEM); printf("Customers wander in at random, on average %f" " per second.\n", CHANCE_OF_CUSTOMER); printf("Expenditure is %f per cashier.\n", CASHIER_WAGE); printf("You choose the number of cashiers.\n\n"); printf("Dissatisfied customers cost you goodwill.\n"); do { printf("How many cashiers today?\n"); if(NULL == fgets(Buff, sizeof Buff, stdin)) { printf("Program aborted.\n"); exit(EXIT_FAILURE); } TempCashiers = strtoul(Buff, &endp, 10); /* On some platforms, unsigned long is longer than int, * so we use a temp to catch strtoul's value. */ if(endp == Buff || 0 == TempCashiers || TempCashiers > (unsigned long)INT_MAX) { printf("Ahem. %s? Try again!\n\n", Buff); } else { NumCashiers = (int)TempCashiers; Cashier = malloc(NumCashiers * sizeof *Cashier); if(NULL == Cashier) { printf("Hmm. Not enough RAM for " "that many cashiers. Try again.\n"); } } } while(NULL == Cashier); for(i = 0; i < NumCashiers; i++) { Cashier[i] = EmptyCashier; } /* Run simulation from 9am till 5pm (28800 seconds) */ assert(OPENING_TIME < CLOSING_TIME); for(CurrentSecond = OPENING_TIME; CurrentSecond < CLOSING_TIME; CurrentSecond++) { p = RandomP(); if(p < CHANCE_OF_CUSTOMER) { Customer = EmptyCustomer; Customer.Index = CustomerNumber++; Customer.JoinedQueue = CurrentSecond; TotalItems += DoShopping(&Customer); /* Customer is now set up. Let's add * him to the queue. */ if(QUEUE_SUCCESS != QueueAdd(&Queue, 0, &Customer, sizeof Customer)) { printf("Insufficient memory.\n"); exit(EXIT_FAILURE); } } for(i = 0; i < NumCashiers; i++) { /* Deal with current customers */ if(Cashier[i].TimeRemaining > 0) { --Cashier[i].TimeRemaining; if(0 == Cashier[i].TimeRemaining) { printf("%s: Cashier %d has served customer %d\n", GetTime(CurrentSecond), i, Cashier[i].CustomerIndex); } } else { /* Deal with new customer, if any */ if(QueueCount(&Queue) > 0) { QueueRemove(&Customer, &Queue); Cashier[i].TimeRemaining = (int)(Customer.NumItems * SECONDS_PER_ITEM); printf("Cashier %d busy for %d seconds\n", i, Cashier[i].TimeRemaining); Cashier[i].CustomerIndex = Customer.Index; TotalWaitTime += CurrentSecond; TotalWaitTime -= Customer.JoinedQueue; ++SatisfiedCustomers; ++Cashier[i].NumCustomersSeen; Cashier[i].NumItemsProcessed += Customer.NumItems; TotalItemsSold += Customer.NumItems; printf("%s: Cashier %d is serving customer %d\n", GetTime(CurrentSecond), i, Cashier[i].CustomerIndex); printf("Customer %d waiting time: %s\n", Customer.Index, GetTime(CurrentSecond - Customer.JoinedQueue)); } } } } printf("%s: Simulation ended.\n", GetTime(CurrentSecond)); printf("Items sold :%9d ", TotalItemsSold); printf("Items picked up:%9d ", TotalItems); printf("Difference :%9d\n", TotalItems - TotalItemsSold); printf("Satisfied customers:%9d ", SatisfiedCustomers); printf("Dissatisfied customers:%9d\n", CustomerNumber - SatisfiedCustomers); if(TotalWaitTime > 0) { printf("Average wait time " "(satisfied customers only): %s\n", GetTime((long)(TotalWaitTime / (double)SatisfiedCustomers))); } printf("\n\nCashier Report\n\n"); for(i = 0; i < NumCashiers; i++) { printf("Cashier %2d saw %d customers ", i, Cashier[i].NumCustomersSeen); printf("and dealt with %d items.\n", Cashier[i].NumItemsProcessed); } Balance = TotalItemsSold * PROFIT_PER_ITEM; printf("Total profit : %12.2f\n", Balance); printf("Less cashier wages: %12.2f\n", NumCashiers * CASHIER_WAGE); Balance -= NumCashiers * CASHIER_WAGE; printf("Balance : %12.2f\n", Balance); printf("Goodwill Penalty : %12.2f\n", (CustomerNumber - SatisfiedCustomers) * GOODWILL_PENALTY); Balance -= (CustomerNumber - SatisfiedCustomers) * GOODWILL_PENALTY; printf("End Balance : %12.2f\n", Balance); printf("You %s.\n", Balance > 0 ? "win" : "lose"); QueueDestroy(&Queue); free(Cashier); return 0; }
static int finalize_all_files(BATCH batch ) { int status = SUCCESS; int rows; Arb_date dispatch_date; char * this_func = "finalize_all_files"; char szSetClause[256]; char szTransaction[4 + sizeof batch->batch_id]; /* Move image files from ready_dir to done_dir */ /* BID that prints: bid_queueFileProcessed have been moved to bid_queueFilesDone */ /* in check_print_q_file in bid_dispatch.c; */ /* BID that ftps: bid_queueFileProcessed havent't been moved */ if (BID_ftp) status = MapQueueMove(bid_queueFilesProcessed, move_image_file, NULL, SUCCESS, bid_queueFilesDone); else status = MapQueue(bid_queueFilesDone, move_image_file, NULL); if (SUCCESS != status) return(status); sprintf(szTransaction, "BID%s", batch->batch_id); if (arb_begin_tran(dbproc, szTransaction) != SUCCESS) { emit(BIDMOD, BID_BEGIN_TRAN_FAIL, this_func, batch->batch_id); return(FAILURE); } if (get_server_date(dbproc, &dispatch_date) == FAILURE) { if(arb_rollback_tran(dbproc, szTransaction) != SUCCESS) emit(BIDMOD, BID_RLLBAK_TRAN_FAIL, this_func, batch->batch_id); emit(BIDMOD, BID_GET_DATE_FAIL, this_func); return(FAILURE); } rows = update_bill_invoices(batch->batch_id, bid_hold_flag, bid_error_flag, &dispatch_date); if (0 >= rows) { if(arb_rollback_tran(dbproc, szTransaction) != SUCCESS) emit(BIDMOD, BID_RLLBAK_TRAN_FAIL, this_func, batch->batch_id); emit(BIDMOD,BID_UPD_DISPCNT_ERR,this_func); return(FAILURE); } /* Mark the files as complete in the table */ /* At this point the files are all in the 'done' directory */ sprintf(szSetClause, " SET dispatch_status=%d, dispatch_task = '%s'" ", dispatch_date='%%t', dispatch_count=dispatch_count+1", BID_COMPLETE, bid_taskname); rows = set_bill_files(szSetClause, &dispatch_date, batch->batch_id, bid_hold_flag, bid_error_flag,BID_IN_PROGRESS); if (QueueCount(bid_queueFilesDone) != rows) { if(arb_rollback_tran(dbproc, szTransaction) != SUCCESS) emit(BIDMOD, BID_RLLBAK_TRAN_FAIL, this_func, batch->batch_id); emit(BIDMOD,BID_DONE_STAT_FAIL,this_func); return(FAILURE); } if (arb_commit_tran(dbproc) != SUCCESS) { emit(BIDMOD, BID_COMMIT_TRAN_FAIL, this_func, batch->batch_id); return(FAILURE); } else return(SUCCESS); }
void main(void) { while(1) { char chc; printf("(1)Linked List, (2)Queue: "); scanf("%c", &chc); if(chc == '1') { LinkedListHeader list; LinkedListContruct(&list); bool quit = false; char keuze; while(1) { fflush(stdin); printf("1 = count, 2 = add front, 3 = add rear, 4 = find index, 5 = print all, 6 = quit: , 7 = Deep Copy"); scanf("%c", &keuze); switch(keuze) { case '1': printf("%d", LinkedListCount(&list)); break; case '2': { LinkedListNode *eerst = (LinkedListNode*)malloc(sizeof(LinkedListNode)); printf("Waarde die je wilt invoegen: "); scanf("%d", &eerst->data); LinkedListAddFront(&list, eerst); } break; case '3': { LinkedListNode *laatst = (LinkedListNode*)malloc(sizeof(LinkedListNode)); printf("Waarde die je wilt invoegen: "); scanf("%d", &laatst->data); LinkedListAddRear(&list, laatst); } break; case '4': { int index = 0; printf("index: "); scanf("%d", &index); LinkedListNode *node = LinkedListItem(&list, index); if(node != NULL) printf("Index %d heeft als waarde %d", index, node->data); } break; case '5': { int cnt = 1; while(1) { LinkedListNode *node = LinkedListItem(&list, cnt); if(node != NULL) { printf("Op index %d is het getal %d\n", cnt, node->data); cnt++; } else break; } } break; case '6': quit = true; break; case '7': { LinkedListHeader copiedHeader = {0}; LinkedListContruct(&copiedHeader); LinkedListDeepCopy(&list, &copiedHeader); //Gekopieerd. _getch() wordt aangeroepen om te kijken of het ook werkt _getch(); } break; default: break; } printf("\n"); if(quit) { LinkedListDestruct(&list); break; } } } if(chc == '2') { QueueHeader header = {0}; QueueInit(&header); bool quit = false; char keuze; while(1) { fflush(stdin); printf("1=enqueue, 2=dequeue, 3=peek, 4=isempty, 5=count,6=quit: "); scanf("%c", &keuze); switch(keuze) { case '1': { QueueNode *node = (QueueNode*)malloc(sizeof(QueueNode)); int num = 0; printf("Getal om te queuen: "); scanf("%d", &num); node->number = num; QueueEnqueue(&header, node); } break; case '2': { QueueNode node = QueueDequeue(&header); if(!node.isEmpty) printf("Het volgende deel van de queue is %d" , node.number); else printf("De queue is leeg!"); } break; case '3': { QueueNode node = QueuePeek(&header); if(!node.isEmpty) printf("Na het spieken blijkt dat het volgend nummer %d is" , node.number); else printf("de queue is leeg!"); } break; case '4': if(QueueIsEmpty(&header)) printf("ja"); else printf("nee"); break; case '5': { int num = 0; if(QueueCount(&header, &num)) printf("Er staan %d nummers in de rij", num); else printf("Er staan geen nummers meer in de rij"); } break; case '6': quit = true; break; default: break; } printf("\n"); if(quit) { QueueDestruct(&header); break; } } } } }