Updated exit status codes
This commit is contained in:
parent
5efba4141f
commit
19862342b1
|
@ -16,7 +16,7 @@ bool polonius::pl_window::is_initialized() {
|
|||
|
||||
void polonius::pl_window::handle_force_quit(sig_atomic_t signal) {
|
||||
close();
|
||||
exit(1);
|
||||
exit(EXIT_INTERRUPT);
|
||||
}
|
||||
|
||||
void polonius::pl_window::handle_suspend(sig_atomic_t signal) {
|
||||
|
|
|
@ -57,14 +57,14 @@ int main(int argc, char* argv[]) {
|
|||
case 'i':
|
||||
if (received_filename) {
|
||||
cerr << program_name + ": Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_path = optarg;
|
||||
received_filename = true;
|
||||
break;
|
||||
case 'h':
|
||||
cout << helpstring;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ int main(int argc, char* argv[]) {
|
|||
for (option_index = optind; option_index < argc; option_index++) {
|
||||
if (received_filename) {
|
||||
cerr << program_name + ": Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_path = argv[option_index];
|
||||
received_filename = true;
|
||||
|
@ -98,5 +98,5 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
// cout << polonius::command::exec("polonius-reader -i " + file_path);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@
|
|||
#include "../../shared/remove_leading_whitespace.cpp"
|
||||
#endif
|
||||
|
||||
/* Shared definitions */
|
||||
#include "../../shared/definitions.h"
|
||||
|
||||
/* Contains the 'meat' of the program */
|
||||
#include "namespace_editor.h"
|
||||
|
|
|
@ -75,7 +75,7 @@ int main(int argc, char* argv[]) {
|
|||
case 'i':
|
||||
if (received_filename) {
|
||||
cerr << "polonius-editor: Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_to_edit = optarg;
|
||||
received_filename = true;
|
||||
|
@ -94,7 +94,7 @@ int main(int argc, char* argv[]) {
|
|||
block_size = parse_block_units(optarg);
|
||||
if (block_size == -1) {
|
||||
cerr << program_name << ": Block size '" << optarg << "' is not understood" << endl << "Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADARG;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -108,18 +108,18 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
case 'V':
|
||||
cout << program_version << endl;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
cout << helpstring;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (optopt == 'i' || optopt == 's' || optopt == 'a' || optopt == 'b') {
|
||||
cerr << program_name << ": Option -" << (char)optopt << " requires an argument" << endl << "Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADOPT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ int main(int argc, char* argv[]) {
|
|||
for (option_index = optind; option_index < argc; option_index++) {
|
||||
if (received_filename) {
|
||||
cerr << "polonius-editor: Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_to_edit = argv[option_index];
|
||||
received_filename = true;
|
||||
|
@ -136,14 +136,14 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
if (!received_filename) {
|
||||
cerr << program_name << ": No input file given. Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
|
||||
editor::file document(file_to_edit, block_size, verbose);
|
||||
|
||||
if (!document.is_initialized()) {
|
||||
cerr << program_name << ": " << document.get_error_message() << endl;
|
||||
return 1;
|
||||
return EXIT_OTHER;
|
||||
}
|
||||
|
||||
for (int i = 0; i < instructions_to_add.size(); i++) {
|
||||
|
@ -154,7 +154,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
if (!document.add_instruction(instructions_to_add[i])) {
|
||||
cerr << program_name << ": " << instructions_to_add[i].get_error_message() << endl;
|
||||
return 1;
|
||||
return EXIT_BADARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,6 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
/* Close file */
|
||||
document.close();
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* Shared definitions */
|
||||
#include "../../shared/definitions.h"
|
||||
|
||||
/* inline bool is_number(const std::string &s) returns true if all chars in string are digits */
|
||||
#include "../../shared/is_number.cpp"
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ int main(int argc, char* argv[]) {
|
|||
case 'i':
|
||||
if (received_filename) {
|
||||
cerr << "polonius-reader: Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_to_read = optarg;
|
||||
received_filename = true;
|
||||
|
@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
|
|||
case 's':
|
||||
if (!is_number(optarg)) {
|
||||
cerr << program_name << ": '" << optarg << "' is not an integer" << endl << "Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADARG;
|
||||
}
|
||||
start_position = (int64_t)atol(optarg);
|
||||
break;
|
||||
|
@ -72,25 +72,25 @@ int main(int argc, char* argv[]) {
|
|||
case 'l':
|
||||
if (!is_number(optarg)) {
|
||||
cerr << program_name << ": '" << optarg << "' is not an integer" << endl << "Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADARG;
|
||||
}
|
||||
amount_to_read = (int64_t)atol(optarg);
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
cout << program_version << endl;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
cout << helpstring;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (optopt == 'i' || optopt == 's' || optopt == 'l') {
|
||||
cerr << program_name << ": Option -" << (char)optopt << " requires an argument" << endl << "Use -h for help" << endl;
|
||||
return 1;
|
||||
return EXIT_BADOPT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ int main(int argc, char* argv[]) {
|
|||
for (option_index = optind; option_index < argc; option_index++) {
|
||||
if (received_filename) {
|
||||
cerr << "polonius-reader: Error: Multiple files specified" << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
file_to_read = argv[option_index];
|
||||
received_filename = true;
|
||||
|
@ -108,14 +108,14 @@ int main(int argc, char* argv[]) {
|
|||
// Make sure we got an input file
|
||||
if (!received_filename) {
|
||||
cerr << helpstring;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
|
||||
reader::file the_file;
|
||||
|
||||
if (!the_file.init(file_to_read)) {
|
||||
cerr << program_name << ": " << the_file.get_init_error_message() << endl;
|
||||
return 1;
|
||||
return EXIT_BADFILE;
|
||||
}
|
||||
|
||||
// If -l / --length wasn't set, just set it to the full length of the file
|
||||
|
@ -125,5 +125,5 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
cout << the_file.read(start_position, amount_to_read);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1 +1,10 @@
|
|||
#define KEY_FRESH 0X4FE
|
||||
|
||||
// Exit codes:
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_BADFILE 1
|
||||
#define EXIT_BADARG 2
|
||||
#define EXIT_BADOPT 3
|
||||
#define EXIT_OTHER 4
|
||||
#define EXIT_INTERRUPT 5
|
||||
|
|
Loading…
Reference in a new issue