Skip to content

Commit

Permalink
update some error
Browse files Browse the repository at this point in the history
  • Loading branch information
a1henu committed May 1, 2024
1 parent 1995569 commit 172b72d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int main(int argc, char** argv) {
std::exit(1);
}

// check if the input file is stdin
std::istream* input;
if (inputFile == "-") {
input = &std::cin;
Expand All @@ -105,13 +106,17 @@ int main(int argc, char** argv) {
while(std::getline(*input, line)) {
outputBuf << line << std::endl;

// check if brackets are balanced
for (char c : line) {
if (c == '[') {
// left bracket means a new citation
++bracketCount;
} else if (c == ']') {
// right bracket means the end of a citation
--bracketCount;
}

// if bracketCount is negative, it means there are more right brackets than left brackets
if (bracketCount < 0) {
std::exit(1);
}
Expand All @@ -125,6 +130,7 @@ int main(int argc, char** argv) {
}
}

// if bracketCount is not 0, it means the number of left brackets is not equal to the number of right brackets
if (bracketCount != 0) {
std::exit(1);
}
Expand All @@ -138,11 +144,10 @@ int main(int argc, char** argv) {
}
outputBuf << "\nReferences:\n";
for (auto id : citationIDs) {
try{
outputBuf << citations[id]->toString() << std::endl;
} catch(...) {
if (citations.find(id) == citations.end()) {
std::exit(1);
}
outputBuf << citations[id]->toString() << std::endl;
}

if (argc == 4) {
Expand Down

0 comments on commit 172b72d

Please sign in to comment.