Commit ac03fb06 authored by Jelte Jansen's avatar Jelte Jansen

[trac1093] change warn on dupes to error in message compiler

- changed the name and output from warn to error
- added exit(1) if there are errors
- move the check so it is called before output is written
parent 9336279b
......@@ -460,22 +460,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
/// processed. However, we should warn about it.
/// If the input file contained duplicate message IDs, we print an
/// error for each of them, then exit the program with a non-0 value.
///
/// \param reader Message Reader used to read the file
void
warnDuplicates(MessageReader& reader) {
errorDuplicates(MessageReader& reader) {
// 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
// occur more than twice in the input file).
MessageReader::MessageIDCollection duplicates = reader.getNotAdded();
if (duplicates.size() > 0) {
cout << "Warning: the following duplicate IDs were found:\n";
cout << "Error: the following duplicate IDs were found:\n";
sort(duplicates.begin(), duplicates.end());
MessageReader::MessageIDCollection::iterator new_end =
......@@ -484,6 +484,7 @@ warnDuplicates(MessageReader& reader) {
i != new_end; ++i) {
cout << " " << *i << "\n";
}
exit(1);
}
}
......@@ -544,6 +545,9 @@ main(int argc, char* argv[]) {
MessageReader reader(&dictionary);
reader.readFile(message_file);
// Error (and quit) if there are of any duplicates encountered.
errorDuplicates(reader);
if (doPython) {
// Warn in case of ignored directives
if (!reader.getNamespace().empty()) {
......@@ -566,8 +570,6 @@ main(int argc, char* argv[]) {
writeProgramFile(message_file, ns_components, dictionary);
}
// Finally, warn of any duplicates encountered.
warnDuplicates(reader);
}
catch (MessageException& e) {
// 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