···
int main(int argc, char **argv) {
19
-
string filename = "../test/OT.txt";
20
+
string inputFilename = "../test/OT.txt";
21
+
string outputFilename = "build/verses.txt";
24
+
string normalizedBook;
// get path to OT.txt if provided otherwise use default path
29
+
// and then do the same for the verses.txt
30
+
if (argc >= 2) inputFilename = argv[1];
31
+
if (argc >= 3) outputFilename = argv[2];
33
+
OT.open(inputFilename);
32
-
cout << filename << ": failed to open file";
36
+
cout << inputFilename << ": failed to open file";
···
44
+
for (int i = 0; i < book.length(); i++)
45
+
normalizedBook += toupper(book[i]);
50
-
cout << book << " " << chapter << ":" << verse;
55
+
bool foundBook = false;
56
+
bool foundChapter = false;
57
+
bool foundVerse = false;
64
+
if (input != "THE") continue;
65
+
OT >> input; // BOOK
66
+
if (input != "BOOK") continue;
68
+
if (input != "OF") continue;
70
+
OT.ignore(); // skip the single space
72
+
getline(OT, input); // handle multi word books
74
+
if (input == normalizedBook) {
77
+
getline(OT, input); // discard empty line
81
+
if (!foundChapter) {
83
+
if (input != "CHAPTER") {
84
+
if (input == "THE") break;
89
+
if (input == to_string(chapter)) {
90
+
foundChapter = true;
96
+
if (input == "CHAPTER") break;
98
+
if (input == to_string(verse)) {
100
+
OT.ignore(); // ignore space
101
+
getline(OT, verseString);
109
+
cout << verse << " " << verseString << endl;
111
+
OF.open(outputFilename);
113
+
if (!OF.is_open()) {
114
+
cout << outputFilename << ": error saving file" << endl;
118
+
OF << verse << " " << verseString << endl;
123
+
cout << book << " does not exist in the Old Testament";
125
+
if (!foundChapter) {
126
+
cout << "Chapter " << chapter << " does not exist in " << book;
127
+
} else if (!foundVerse) {
128
+
cout << "Verse " << verse << " does not exist in " << book << " " << chapter;