void buildSimpleTree() { addTransaction(1, {0, false, 16}); addTransaction(3, {1, false, 4}); addTransaction(5, {1, false, 4}); addTransaction(7, {1, false, 8}); addTransaction(9, {5, false, 8}); }
void buildSimpleTree() { addTransaction(1, {0, false, 15}); addTransaction(3, {1, false, 3}); addTransaction(5, {1, false, 3}); addTransaction(7, {1, false, 7}); addTransaction(9, {5, false, 7}); }
TEST_F(QueueTest, UpdateWeightNotEnqueued) { addTransaction(1, {0, false, 7}); addTransaction(3, {0, false, 7}); signalEgress(1, false); signalEgress(3, false); updatePriority(1, {3, false, 7}); dump(); EXPECT_EQ(nodes_, IDList({{3, 100}, {1, 100}})); }
void TransactionDialog::AddTransaction() { if (addTransaction()) { emit refreshTray(); } }
void populateRows(int start, int end) { if(start > ROWS_TO_REFRESH) return; if(!prepare()) return; if (end > ROWS_TO_REFRESH) end = ROWS_TO_REFRESH; QVariantList transactions; while(start <= end) { if(visibleTransactions.first() == "*"||visibleTransactions.contains(ttm->index(start, TransactionTableModel::Type).data().toString())) transactions.append(addTransaction(start)); start++; } if(!transactions.isEmpty()) emitTransactions(transactions); running = false; }
static void dumpXLog(char* fname) { char *fnamebase; printf("\n%s:\n\n", fname); /* * Extract logfile id and segment from file name */ fnamebase = strrchr(fname, '/'); if (fnamebase) fnamebase++; else fnamebase = fname; if (sscanf(fnamebase, "%8x%8x%8x", &logTLI, &logId, &logSeg) != 3) { fprintf(stderr, "Can't recognize logfile name '%s'\n", fnamebase); logTLI = logId = logSeg = 0; } logPageOff = -XLOG_BLCKSZ; /* so 1st increment in readXLogPage gives 0 */ logRecOff = 0; while (ReadRecord()) { if(!transactions) dumpXLogRecord((XLogRecord *) readRecordBuf, false); else addTransaction((XLogRecord *) readRecordBuf); prevRecPtr = curRecPtr; } if(transactions) dumpTransactions(); }
void TransactionDialog::AddTransactionAndClose() { if (addTransaction()) { emit refreshTray(); this->close(); } }
TEST_F(QueueTest, AddUnknown) { buildSimpleTree(); addTransaction(11, {75, false, 16}); dump(); EXPECT_EQ(nodes_, IDList({ {1, 50}, {3, 25}, {5, 25}, {9, 100}, {7, 50}, {11, 50} })); }
TEST_F(QueueTest, ExclusiveAdd) { buildSimpleTree(); addTransaction(11, {1, true, 100}); dump(); EXPECT_EQ(nodes_, IDList({ {1, 100}, {11, 100}, {3, 25}, {5, 25}, {9, 100}, {7, 50} })); }
/// class HTTP2PriorityQueue void HTTP2PriorityQueue::addOrUpdatePriorityNode(HTTPCodec::StreamID id, http2::PriorityUpdate pri) { auto handle = find(id); if (handle) { // already added CHECK(handle->getTransaction() == nullptr); updatePriority(handle, pri); } else { // brand new addTransaction(id, pri, nullptr, false /* not permanent */); } }
IncrementalParser::ParseResultTransaction IncrementalParser::endTransaction(Transaction* T) { assert(T && "Null transaction!?"); assert(T->getState() == Transaction::kCollecting); #ifndef NDEBUG if (T->hasNestedTransactions()) { for(Transaction::const_nested_iterator I = T->nested_begin(), E = T->nested_end(); I != E; ++I) assert((*I)->isCompleted() && "Nested transaction not completed!?"); } #endif T->setState(Transaction::kCompleted); DiagnosticsEngine& Diag = getCI()->getSema().getDiagnostics(); //TODO: Make the enum orable. EParseResult ParseResult = kSuccess; assert((Diag.hasFatalErrorOccurred() ? Diag.hasErrorOccurred() : true) && "Diag.hasFatalErrorOccurred without Diag.hasErrorOccurred !"); if (Diag.hasErrorOccurred() || T->getIssuedDiags() == Transaction::kErrors) { T->setIssuedDiags(Transaction::kErrors); ParseResult = kFailed; } else if (Diag.getNumWarnings() > 0) { T->setIssuedDiags(Transaction::kWarnings); ParseResult = kSuccessWithWarnings; } // Empty transaction, send it back to the pool. if (T->empty()) { assert((!m_Consumer->getTransaction() || (m_Consumer->getTransaction() == T)) && "Cannot release different T"); // If a nested transaction the active one should be its parent // from now on. FIXME: Merge conditional with commitTransaction if (T->isNestedTransaction()) m_Consumer->setTransaction(T->getParent()); else m_Consumer->setTransaction((Transaction*)0); m_TransactionPool->releaseTransaction(T); return ParseResultTransaction(nullptr, ParseResult); } addTransaction(T); return ParseResultTransaction(T, ParseResult); }
void ImageWindow::resizeImage() { QDialog dialog; Ui::ResizeDialog ui; ui.setupUi(&dialog); ui.widthSpinBox->setValue(imageLabel->pixmap()->width()); ui.heightSpinBox->setValue(imageLabel->pixmap()->height()); if (dialog.exec()) { QSize newSize(ui.widthSpinBox->value(), ui.heightSpinBox->value()); addTransaction(new ResizeTransaction(newSize)); } }
TEST_F(QueueTest, nextEgressExclusiveAddWithEgress) { buildSimpleTree(); // clear all egress, except 3 signalEgress(1, false); signalEgress(5, false); signalEgress(7, false); signalEgress(9, false); // Add a transaction with exclusive dependency, clear its egress addTransaction(11, {1, true, 100}); signalEgress(11, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{3, 100}})); }
size_t ICoreStub::addChain(const std::vector<const CryptoNote::IBlock*>& chain) { size_t blocksCounter = 0; for (const CryptoNote::IBlock* block : chain) { for (size_t txNumber = 0; txNumber < block->getTransactionCount(); ++txNumber) { const CryptoNote::Transaction& tx = block->getTransaction(txNumber); Crypto::Hash txHash = CryptoNote::NULL_HASH; size_t blobSize = 0; getObjectHash(tx, txHash, blobSize); addTransaction(tx); } addBlock(block->getBlock()); ++blocksCounter; } return blocksCounter; }
void Interface::createButtonsLayout(QHBoxLayout *buttonsLayout) { QPushButton *addItem = new QPushButton(this); QPushButton *removeItem = new QPushButton(this); QPushButton *analyze = new QPushButton(this); addItem->setText("Add"); removeItem->setText("Remove"); analyze->setText("Analyze"); buttonsLayout->addWidget(addItem); buttonsLayout->addWidget(removeItem); buttonsLayout->addWidget(analyze); connect(addItem, SIGNAL(clicked()), this, SLOT(addTransaction())); }
TEST_F(QueueTest, nextEgressExclusiveAdd) { buildSimpleTree(); // clear all egress signalEgress(1, false); signalEgress(3, false); signalEgress(5, false); signalEgress(7, false); signalEgress(9, false); // Add a transaction with exclusive dependency, clear its egress addTransaction(11, {1, true, 100}); signalEgress(11, false); // signal egress for a child that got moved via exclusive dep signalEgress(3, true); nextEgress(); EXPECT_EQ(nodes_, IDList({{3, 100}})); }
void ModelBackendOneFile::remove( const BookInfo* book ) { qDebug() << "--->" << Q_FUNC_INFO << " Removing " << book->path; TBooks::iterator it = m_books->find(book->path); if(it != m_books->end()) { QFile::remove(book->path); QFile::remove(book->thumbnail); qDebug() << "--->" << Q_FUNC_INFO << " book " << book->path << " removed"; QString path = book->path; if(book->m_type == BookInfo::BOOKINFO_TYPE_DEMO && book->path.contains("private")) addTransaction(book->isbn, true); m_books->take(book->path); delete *it; *it = NULL; messDir(path, UPDATE_FULL);// TODO: Path is temporary, and the parameter is const QString&!! } }
void populatePage() { if(!prepare(false)) return; QVariantList transactions; int row = -1; running = true; while(++row < numRows && ttm->index(row, 0).isValid()) if(visibleTransactions.first() == "*"||visibleTransactions.contains(ttm->index(row, TransactionTableModel::Type).data().toString())) transactions.append(addTransaction(row)); if(!transactions.isEmpty()) emitTransactions(transactions); running = false; }
TEST_F(QueueTest, nextEgress) { buildSimpleTree(); nextEgress(); EXPECT_EQ(nodes_, IDList({{1, 100}})); addTransaction(11, {7, false, 15}); signalEgress(1, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {5, 25}})); signalEgress(5, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {9, 25}})); signalEgress(5, true); signalEgress(3, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 66}, {5, 33}})); signalEgress(5, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 66}, {9, 33}})); signalEgress(7, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{11, 66}, {9, 33}})); signalEgress(9, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{11, 100}})); signalEgress(3, true); signalEgress(7, true); signalEgress(9, true); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {9, 25}})); }
int main(int argc, char **argv) { GWEN_DB_NODE *db; const char *cmd; int rv; AB_BANKING *ab; GWEN_GUI *gui; int nonInteractive=0; int acceptValidCerts=0; const char *pinFile; const char *cfgDir; const char *s; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "cfgdir", /* name */ 0, /* minnum */ 1, /* maxnum */ "D", /* short option */ "cfgdir", /* long option */ I18S("Specify the configuration folder"), I18S("Specify the configuration folder") }, { 0, /* flags */ GWEN_ArgsType_Int, /* type */ "nonInteractive", /* name */ 0, /* minnum */ 1, /* maxnum */ "n", /* short option */ "noninteractive", /* long option */ "Select non-interactive mode",/* short description */ "Select non-interactive mode.\n" /* long description */ "This automatically returns a confirmative answer to any non-critical\n" "message." }, { 0, /* flags */ GWEN_ArgsType_Int, /* type */ "acceptValidCerts", /* name */ 0, /* minnum */ 1, /* maxnum */ "A", /* short option */ "acceptvalidcerts", /* long option */ "Automatically accept all valid TLS certificate", "Automatically accept all valid TLS certificate" }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "charset", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "charset", /* long option */ "Specify the output character set", /* short description */ "Specify the output character set" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "pinfile", /* name */ 0, /* minnum */ 1, /* maxnum */ "P", /* short option */ "pinfile", /* long option */ "Specify the PIN file", /* short description */ "Specify the PIN file" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", I18S("Show this help screen. For help on commands, " "run aqbanking-cli <COMMAND> --help."), I18S("Show this help screen. For help on commands, run aqbanking-cli <COMMAND> --help.") } }; rv=GWEN_Init(); if (rv) { fprintf(stderr, "ERROR: Unable to init Gwen.\n"); exit(2); } GWEN_Logger_Open(0, "aqbanking-cli", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User); GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Warning); rv=GWEN_I18N_BindTextDomain_Dir(PACKAGE, LOCALEDIR); if (rv) { DBG_ERROR(0, "Could not bind textdomain (%d)", rv); } else { rv=GWEN_I18N_BindTextDomain_Codeset(PACKAGE, "UTF-8"); if (rv) { DBG_ERROR(0, "Could not set codeset (%d)", rv); } } db=GWEN_DB_Group_new("arguments"); rv=GWEN_Args_Check(argc, argv, 1, GWEN_ARGS_MODE_ALLOW_FREEPARAM | GWEN_ARGS_MODE_STOP_AT_FREEPARAM, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments main\n"); GWEN_DB_Group_free(db); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); GWEN_Buffer_AppendString(ubuf, I18N("This is version ")); GWEN_Buffer_AppendString(ubuf, AQHBCI_VERSION_STRING "\n"); GWEN_Buffer_AppendString(ubuf, I18N("Usage: ")); GWEN_Buffer_AppendString(ubuf, argv[0]); GWEN_Buffer_AppendString(ubuf, I18N(" [GLOBAL OPTIONS] COMMAND " "[LOCAL OPTIONS]\n")); GWEN_Buffer_AppendString(ubuf, I18N("\nGlobal Options:\n")); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); GWEN_DB_Group_free(db); return 1; } GWEN_Buffer_AppendString(ubuf, I18N("\nCommands:\n")); cmdAddHelpStr(ubuf, "senddtazv", I18N("Sends a DTAZV file to the bank")); cmdAddHelpStr(ubuf, "listaccs", I18N("Prints the list of accounts")); cmdAddHelpStr(ubuf, "listbal", I18N("Export balances from a context file.")); cmdAddHelpStr(ubuf, "listtrans", I18N("Export transactions from a context file.")); cmdAddHelpStr(ubuf, "listtransfers", I18N("Export transactions from a context file which match certain status.")); cmdAddHelpStr(ubuf, "request", I18N("Requests transactions, balances, standing orders etc.")); cmdAddHelpStr(ubuf, "chkacc", I18N("Check a combination of bank id and account number")); cmdAddHelpStr(ubuf, "chkiban", I18N("Check an IBAN")); cmdAddHelpStr(ubuf, "import", I18N("Import a file into an import context file")); cmdAddHelpStr(ubuf, "transfer", I18N("Issue a single transfer (data from command line)")); cmdAddHelpStr(ubuf, "transfers", I18N("Issue a number of transfers (data from a file)")); cmdAddHelpStr(ubuf, "sepatransfer", I18N("Issue a single SEPA transfer (data from command line)")); cmdAddHelpStr(ubuf, "sepatransfers", I18N("Issue a number of SEPA transfers (data from a file)")); cmdAddHelpStr(ubuf, "debitnote", I18N("Issue a single debit note (data from command line)")); cmdAddHelpStr(ubuf, "debitnotes", I18N("Issue a number of debit notes (data from a file)")); cmdAddHelpStr(ubuf, "sepadebitnote", I18N("Issue a single SEPA debit note (data from command line)")); cmdAddHelpStr(ubuf, "sepaflashdebitnote", I18N("Issue a single flash SEPA debit note COR1 (data from command line)")); cmdAddHelpStr(ubuf, "sepadebitnotes", I18N("Issue a number of SEPA debit notes (data from a file)")); cmdAddHelpStr(ubuf, "addtrans", I18N("Add a transfer to an existing import context file")); cmdAddHelpStr(ubuf, "addsepadebitnote", I18N("Add a SEPA debit note to an existing import context file")); cmdAddHelpStr(ubuf, "sepasto", I18N("Manage SEPA standing orders")); cmdAddHelpStr(ubuf, "fillgaps", I18N("Fill gaps in an import context file from configuration settings")); cmdAddHelpStr(ubuf, "updateconf", I18N("Update configuration from previous AqBanking versions")); cmdAddHelpStr(ubuf, "listprofiles", I18N("Print existing profiles")); cmdAddHelpStr(ubuf, "versions", I18N("Print the program and library versions")); GWEN_Buffer_AppendString(ubuf, "\n"); fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); GWEN_DB_Group_free(db); return 0; } if (rv) { argc-=rv-1; argv+=rv-1; } nonInteractive=GWEN_DB_GetIntValue(db, "nonInteractive", 0, 0); acceptValidCerts=GWEN_DB_GetIntValue(db, "acceptValidCerts", 0, 0); cfgDir=GWEN_DB_GetCharValue(db, "cfgdir", 0, 0); cmd=GWEN_DB_GetCharValue(db, "params", 0, 0); if (!cmd) { fprintf(stderr, "ERROR: Command needed.\n"); GWEN_DB_Group_free(db); return 1; } gui=GWEN_Gui_CGui_new(); s=GWEN_DB_GetCharValue(db, "charset", 0, NULL); if (s && *s) GWEN_Gui_SetCharSet(gui, s); if (nonInteractive) GWEN_Gui_AddFlags(gui, GWEN_GUI_FLAGS_NONINTERACTIVE); else GWEN_Gui_SubFlags(gui, GWEN_GUI_FLAGS_NONINTERACTIVE); if (acceptValidCerts) GWEN_Gui_AddFlags(gui, GWEN_GUI_FLAGS_ACCEPTVALIDCERTS); else GWEN_Gui_SubFlags(gui, GWEN_GUI_FLAGS_ACCEPTVALIDCERTS); pinFile=GWEN_DB_GetCharValue(db, "pinFile", 0, NULL); if (pinFile) { GWEN_DB_NODE *dbPins; dbPins=GWEN_DB_Group_new("pins"); if (GWEN_DB_ReadFile(dbPins, pinFile, GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_CREATE_GROUP)) { fprintf(stderr, "Error reading pinfile \"%s\"\n", pinFile); GWEN_DB_Group_free(dbPins); GWEN_DB_Group_free(db); return 2; } GWEN_Gui_SetPasswordDb(gui, dbPins, 1); } GWEN_Gui_SetGui(gui); ab=AB_Banking_new("aqbanking-cli", cfgDir, 0); AB_Gui_Extend(gui, ab); if (strcasecmp(cmd, "senddtazv")==0) { rv=sendDtazv(ab, db, argc, argv); } else if (strcasecmp(cmd, "listaccs")==0) { rv=listAccs(ab, db, argc, argv); } else if (strcasecmp(cmd, "listbal")==0) { rv=listBal(ab, db, argc, argv); } else if (strcasecmp(cmd, "listtrans")==0) { rv=listTrans(ab, db, argc, argv); } else if (strcasecmp(cmd, "listtransfers")==0) { rv=listTransfers(ab, db, argc, argv); } else if (strcasecmp(cmd, "request")==0) { rv=request(ab, db, argc, argv); } else if (strcasecmp(cmd, "chkacc")==0) { rv=chkAcc(ab, db, argc, argv); } else if (strcasecmp(cmd, "chkiban")==0) { rv=chkIban(ab, db, argc, argv); } else if (strcasecmp(cmd, "import")==0) { rv=import(ab, db, argc, argv); } else if (strcasecmp(cmd, "transfer")==0) { rv=transfer(ab, db, argc, argv); } else if (strcasecmp(cmd, "transfers")==0) { rv=transfers(ab, db, argc, argv); } else if (strcasecmp(cmd, "sepatransfer")==0) { rv=sepaTransfer(ab, db, argc, argv); } else if (strcasecmp(cmd, "sepatransfers")==0) { rv=sepaMultiJobs(ab, db, argc, argv, AQBANKING_TOOL_SEPA_TRANSFERS); } else if (strcasecmp(cmd, "debitnote")==0) { rv=debitNote(ab, db, argc, argv); } else if (strcasecmp(cmd, "debitnotes")==0) { rv=debitNotes(ab, db, argc, argv); } else if (strcasecmp(cmd, "sepadebitnote")==0) { rv=sepaDebitNote(ab, db, argc, argv, 0); } else if (strcasecmp(cmd, "sepaFlashDebitNote")==0) { rv=sepaDebitNote(ab, db, argc, argv, 1); } else if (strcasecmp(cmd, "sepadebitnotes")==0) { rv=sepaMultiJobs(ab, db, argc, argv, AQBANKING_TOOL_SEPA_DEBITNOTES); } else if (strcasecmp(cmd, "addtrans")==0) { rv=addTransaction(ab, db, argc, argv); } else if (strcasecmp(cmd, "addsepadebitnote")==0) { rv=addSepaDebitNote(ab, db, argc, argv); } else if (strcasecmp(cmd, "sepasto")==0) { rv=sepaRecurTransfer(ab, db, argc, argv); } else if (strcasecmp(cmd, "fillgaps")==0) { rv=fillGaps(ab, db, argc, argv); } else if (strcasecmp(cmd, "updateconf")==0) { rv=updateConf(ab, db, argc, argv); } else if (strcasecmp(cmd, "listprofiles")==0) { rv=listProfiles(ab, db, argc, argv); } else if (strcasecmp(cmd, "versions")==0) { rv=versions(ab, db, argc, argv); } else { fprintf(stderr, "ERROR: Unknown command \"%s\".\n", cmd); rv=1; } GWEN_DB_Group_free(db); return rv; }
void ModelBackendOneFile::archive (const BookInfo * book) { qDebug() << "--->" << Q_FUNC_INFO; addTransaction(book->isbn, true); update(book); }
TEST_F(QueueTest, AddMax) { addTransaction(1, {0, false, 255}); nextEgress(); EXPECT_EQ(nodes_, IDList({{1, 100}})); }
void ImageWindow::flipHorizontally() { addTransaction(new FlipTransaction(Qt::Horizontal)); }
void ImageWindow::flipVertically() { addTransaction(new FlipTransaction(Qt::Vertical)); }
void ImageWindow::convertTo32Bit() { addTransaction(new ConvertDepthTransaction(32)); }
int addTransactionWizard(char* wallet) { Transaction tx; tx.date.year = getCurrentYear(); tx.date.month = getCurrentMonth(); tx.date.day = getCurrentDay(); tx.time.hour = getCurrentHour(); tx.time.minute = getCurrentMinute(); tx.time.second = getCurrentSecond(); strcpy(tx.description, (char*)""); int curstep = 0; while(1) { SetBackGround(0x0A); drawScreenTitle("Add transaction"); // < (first label), SELECT of on date step, and Next or Finish (last label) drawFkeyLabels(curstep>0 ? 0x036F : -1, curstep == 2 ? 0x000F : 0, 0, 0, 0, curstep==4 ? 0x04A4 : 0x04A3); if(curstep == 0) { MenuItem menuitems[5]; menuitems[0].text = (char*)"Debit"; menuitems[1].text = (char*)"Credit"; Menu menu; menu.items=menuitems; menu.type=MENUTYPE_FKEYS; menu.numitems=2; menu.height=2; menu.startY=3; menu.pBaRtR=1; int inloop=1; while(inloop) { // this must be here, inside this loop: SetBackGround(0x0A); drawScreenTitle("Add transaction", "Select type:"); drawFkeyLabels(-1, -1, -1, -1, -1, 0x04A3); int res = doMenu(&menu); if(res == MENU_RETURN_EXIT) return 0; else if(res == KEY_CTRL_F6 || res == MENU_RETURN_SELECTION) { tx.credit = menu.selection == 2; curstep++; break; } } } else if(curstep == 1) { drawScreenTitle(NULL, "Amount:"); char samount[20] = ""; if(tx.amount.val) { currencyToString(samount, &tx.amount); } textInput input; input.charlimit=12; input.acceptF6=1; input.symbols = 0; // allow the decimal separator input.forcetext = 1; input.buffer = (char*)samount; input.type = INPUTTYPE_NUMERIC; while(1) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) return 0; // user aborted else if (res==INPUT_RETURN_CONFIRM) { if(!stringToCurrency(&tx.amount, samount)) { if(!tx.amount.val) { AUX_DisplayErrorMessage(0x4B); } else { curstep++; } break; } else AUX_DisplayErrorMessage(0x43); } else if (res==INPUT_RETURN_KEYCODE && input.key == KEY_CTRL_F1) { curstep--; break; } } } else if(curstep == 2) { drawScreenTitle(NULL, "Date:"); mPrintXY(7, 4, getInputDateFormatHint(), TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK); textInput input; input.x=7; input.width=8; input.charlimit=8; input.acceptF6=1; input.type=INPUTTYPE_DATE; char datebuffer[15]; fillInputDate(&tx.date, datebuffer); input.buffer = (char*)datebuffer; while(1) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) return 0; // user aborted else if (res==INPUT_RETURN_CONFIRM) { int len = strlen(datebuffer); if(len == input.charlimit) { int yr,m,d; stringToDate(datebuffer, &yr, &m, &d); if(isDateValid(yr, m, d)) { tx.date.year = yr; tx.date.month = m; tx.date.day = d; curstep++; break; // continue to next step } else invalidFieldMsg(0); } else invalidFieldMsg(0); } else if (res==INPUT_RETURN_KEYCODE) { if(input.key==KEY_CTRL_F1) { curstep=curstep-1; break; } else if(input.key==KEY_CTRL_F2) { int ey=0, em=0, ed=0; if(!selectDateScreen(&ey, &em, &ed, (char*)"Select transaction date:", NULL, 1)) { tx.date.year = ey; tx.date.month = em; tx.date.day = ed; curstep++; break; // continue to next step } break; //redraw } } } } else if(curstep == 3) { drawScreenTitle(NULL, "Time:"); mPrintXY(8, 4, "HHMMSS", TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK); textInput input; input.x=8; input.width=6; input.charlimit=6; input.acceptF6=1; input.type=INPUTTYPE_TIME; char tbuffer[15]; fillInputTime(&tx.time, tbuffer); input.buffer = (char*)tbuffer; while(1) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) return 0; // user aborted else if (res==INPUT_RETURN_CONFIRM) { if((int)strlen(tbuffer) == input.charlimit) { int h, m, s; stringToTime(tbuffer, &h, &m, &s); if(isTimeValid(h, m, s)) { tx.time.hour = h; tx.time.minute = m; tx.time.second = s; curstep++; break; // continue to next step } else invalidFieldMsg(1); } else invalidFieldMsg(1); } else if (res==INPUT_RETURN_KEYCODE && input.key==KEY_CTRL_F1) { curstep--; break; } } } else if(curstep == 4) { drawScreenTitle(NULL, "Description:"); textInput input; input.charlimit=128; input.acceptF6=1; input.buffer = (char*)tx.description; int inloop = 1; while(inloop) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) return 0; // user aborted else if (res==INPUT_RETURN_CONFIRM) inloop = 0; // all fields complete, continue with transaction adding else if (res==INPUT_RETURN_KEYCODE && input.key == KEY_CTRL_F1) { curstep--; break; } } if(!inloop) break; } } addTransaction(&tx, wallet); return 1; }
int main (int argc, char **argv){ char *fileName; char *client_id; if(argc != 3){ fprintf(stderr, "Wrong number of parameters. Expected 2, found %d\n", (argc - 1)); return EXIT_FAILURE; } fileName = argv[1]; client_id = argv[2]; for(int i = 0; i < strlen(client_id); i++){ if(!isdigit(*(client_id + i))){ fprintf(stderr, "Account number %s must be integer\n", client_id); return EXIT_FAILURE; } } FILE *transactionFile = fopen(fileName, "r"); if(transactionFile == NULL){ perror("fopen()"); fprintf(stderr, "failed in file %s at line# %d\n", __FILE__, __LINE__-4); return EXIT_FAILURE; } char *line = malloc((LINE_SIZE + 1) * sizeof (char)); if(line == NULL){ fprintf(stderr, "Insufficient memory at line #%d\n", __LINE__); fclose(transactionFile); return EXIT_FAILURE; } size_t lineNumber = 0; Transaction *transactions; if(fgets(line, (LINE_SIZE + 1), transactionFile) != NULL){ lineNumber++; trim(line); transactions = createTransaction(line); if(transactions == NULL){ fprintf(stderr, "Transaction in line %zu could not be created\n", lineNumber); free(line); fclose(transactionFile); return EXIT_FAILURE; } while(fgets(line, (LINE_SIZE + 1), transactionFile) != NULL){ lineNumber++; trim(line); Transaction *transaction = createTransaction(line); if(transaction == NULL){ fprintf(stderr, "Transaction in line %zu could not be created\n", lineNumber); freeTransactions(transactions); free(line); fclose(transactionFile); return EXIT_FAILURE; } addTransaction(transactions, transaction); } } if(ferror(transactionFile)){ fprintf(stderr, "fgets() failed in file %s at line # %d\n", __FILE__, __LINE__); freeTransactions(transactions); free(line); return EXIT_FAILURE; } saveTransactions(transactions, client_id); printTransactionError(transactions); freeTransactions(transactions); fclose(transactionFile); return EXIT_SUCCESS; }