-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (67 loc) · 2.13 KB
/
main.cpp
File metadata and controls
87 lines (67 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <map>
#define FILE_NAME "./book.bk"
#define DEBUG
#include "commands.h"
#include "model.h"
#include "util.h"
#include "parser.h"
#include "table.h"
#include "statement.h"
#include "ui.h"
int main()
{
std::vector<Journal> journalList;
std::vector<Entry> entryList;
std::vector<Ledger> ledgerList;
std::map<std::string, std::string> metaDataMap;
printCredit();
std::ifstream ifs(FILE_NAME);
std::string input;
std::ifstream infile(FILE_NAME);
if(!infile.good()) { // first time setup
ui::setupDatabase(&entryList, &ledgerList, &metaDataMap);
}
else { // not first time
input.assign((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
// parser::parse(input, &journalList, &metaDataMap);
parser::parse(input, &entryList, &ledgerList, &journalList, &metaDataMap);
}
// Read–eval–print loop
while(true) {
std::cout << "> ";
std::string input = getInput();
// exit
if(input == EXIT)
return EXIT_SUCCESS;
// add journal entry
else if(input == CREATE_JOURNAL)
ui::addJournalEntry(&entryList, &ledgerList, &journalList, &metaDataMap);
// view journals
else if(input == VIEW_JOURNALS)
statement::journalEntries(&journalList, &metaDataMap, 0, timestampNow());
// view journals using dates
else if(input == VIEW_JOURNALS_FOR_THE_PERIOD)
ui::viewJournalEntries(&journalList, &metaDataMap);
// view trial balance "for the period ended on"/"as on date"
else if(input == VIEW_TRIAL_BALANCE)
ui::viewTrialBalance(&journalList, &metaDataMap);
// create ledger
else if(input == CREATE_LEDGER)
ui::createLedger(&entryList, &ledgerList, &metaDataMap);
// view ledger using dates
else if(input == VIEW_LEDGER)
ui::viewLedger(&journalList, &ledgerList, &metaDataMap);
// view list of ledgers
else if(input == VIEW_LEDGER_LIST)
ui::viewLedgerList(&ledgerList);
// clear screen
else if (input == CLEAR_SCREEN) {
clearScreen();
}
// invalid
else std::cout << "Unknown command." << std::endl;
}
return EXIT_SUCCESS;
}