Skip to content

Commit d0e28cb

Browse files
committed
Error behaviour better fits expected behaviour
Errors now return a non-zero value, and errors are printed to std::cerr instead of std::cout.
1 parent 6e39aa0 commit d0e28cb

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/unicode_cpp_generator.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ int main(int argc, const char **argv) {
9191
}
9292

9393
if (input_file == "") {
94-
std::cout << "Error: No input file given. Type --help for help." << std::endl;
95-
return 0;
94+
std::cerr << "Error: No input file given. Type --help for help." << std::endl;
95+
return 1;
9696
}
9797

9898
// In order to parse a file, we need to load the whole thing into memory.
9999
std::ifstream in_file(input_file.c_str(), std::ifstream::in);
100100
if (!in_file.is_open()) {
101-
std::cout << "Error: Failed to open file " << input_file << std::endl;
102-
return 0;
101+
std::cerr << "Error: Failed to open file " << input_file << std::endl;
102+
return 1;
103103
}
104104
// Seek to the end.
105105
in_file.seekg(0, std::ifstream::end);
@@ -125,9 +125,9 @@ int main(int argc, const char **argv) {
125125
// Only base-level node should be <ucd>
126126
rapidxml::xml_node<> *ucdNode = unicode_doc.first_node("ucd");
127127
if (ucdNode == nullptr) {
128-
std::cout << "Error: No <ucd> base-level tag found. Invalid Unicode Block XML file."
128+
std::cerr << "Error: No <ucd> base-level tag found. Invalid Unicode Block XML file."
129129
<< std::endl;
130-
return 0;
130+
return 1;
131131
}
132132

133133
/// Get the Unicode Version
@@ -144,8 +144,8 @@ int main(int argc, const char **argv) {
144144
// Search for Blocks
145145
rapidxml::xml_node<> *blockNode = ucdNode->first_node("blocks");
146146
if (blockNode == nullptr) {
147-
std::cout << "Error: No Unicode Blocks described in file." << std::endl;
148-
return 0;
147+
std::cerr << "Error: No Unicode Blocks described in file." << std::endl;
148+
return 1;
149149
}
150150

151151
/// Collect Block Data
@@ -179,8 +179,8 @@ int main(int argc, const char **argv) {
179179
std::ofstream out_file(output_dir + "unicode_blocks_" + unicode_vers + ".hpp",
180180
std::ofstream::out);
181181
if (!out_file.is_open()) {
182-
std::cout << "Failed to open header for writing: " << output_dir << "unicode_blocks.h";
183-
return 0;
182+
std::cerr << "Error: Failed to open header for writing: " << output_dir << "unicode_blocks_" << unicode_vers << ".hpp";
183+
return 1;
184184
}
185185

186186
// First, write the license disclaimer.

0 commit comments

Comments
 (0)