Commit 736fb87e authored by Jelte Jansen's avatar Jelte Jansen

[1741] Merge branch 'trac1093' into trac1741

parents 4cee65dd 5a8474bf
...@@ -491,22 +491,22 @@ writeProgramFile(const string& file, const vector<string>& ns_components, ...@@ -491,22 +491,22 @@ writeProgramFile(const string& file, const vector<string>& ns_components,
} }
/// \brief Warn of Duplicate Entries /// \brief Error and exit if there are duplicate entries
/// ///
/// If the input file contained duplicate message IDs, only the first will be /// If the input file contained duplicate message IDs, we print an
/// processed. However, we should warn about it. /// error for each of them, then exit the program with a non-0 value.
/// ///
/// \param reader Message Reader used to read the file /// \param reader Message Reader used to read the file
void void
warnDuplicates(MessageReader& reader) { errorDuplicates(MessageReader& reader) {
// Get the duplicates (the overflow) and, if present, sort them into some // Get the duplicates (the overflow) and, if present, sort them into some
// order and remove those which occur more than once (which mean that they // order and remove those which occur more than once (which mean that they
// occur more than twice in the input file). // occur more than twice in the input file).
MessageReader::MessageIDCollection duplicates = reader.getNotAdded(); MessageReader::MessageIDCollection duplicates = reader.getNotAdded();
if (duplicates.size() > 0) { if (!duplicates.empty()) {
cout << "Warning: the following duplicate IDs were found:\n"; cout << "Error: the following duplicate IDs were found:\n";
sort(duplicates.begin(), duplicates.end()); sort(duplicates.begin(), duplicates.end());
MessageReader::MessageIDCollection::iterator new_end = MessageReader::MessageIDCollection::iterator new_end =
...@@ -515,6 +515,7 @@ warnDuplicates(MessageReader& reader) { ...@@ -515,6 +515,7 @@ warnDuplicates(MessageReader& reader) {
i != new_end; ++i) { i != new_end; ++i) {
cout << " " << *i << "\n"; cout << " " << *i << "\n";
} }
exit(1);
} }
} }
...@@ -580,6 +581,9 @@ main(int argc, char* argv[]) { ...@@ -580,6 +581,9 @@ main(int argc, char* argv[]) {
MessageReader reader(&dictionary); MessageReader reader(&dictionary);
reader.readFile(message_file); reader.readFile(message_file);
// Error (and quit) if there are of any duplicates encountered.
errorDuplicates(reader);
if (doPython) { if (doPython) {
// Warn in case of ignored directives // Warn in case of ignored directives
if (!reader.getNamespace().empty()) { if (!reader.getNamespace().empty()) {
...@@ -604,8 +608,6 @@ main(int argc, char* argv[]) { ...@@ -604,8 +608,6 @@ main(int argc, char* argv[]) {
output_directory); output_directory);
} }
// Finally, warn of any duplicates encountered.
warnDuplicates(reader);
} }
catch (const MessageException& e) { catch (const MessageException& e) {
// Create an error message from the ID and the text // Create an error message from the ID and the text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment