5959#include < system_error>
6060#endif
6161
62- // Following codes copied from /usr/include/sysexits.h,
63- // license: https://opensource.org/license/BSD-3-clause/
64- #define EX_OK 0 /* successful termination */
65- #define EX__BASE 64 /* base value for error messages */
66- #define EX_USAGE 64 /* command line usage error */
67- #define EX_DATAERR 65 /* data format error */
68- #define EX_NOINPUT 66 /* cannot open input */
69- #define EX_SOFTWARE 70 /* internal software error */
70- #define EX_CANTCREAT 73 /* can't create (user) output file */
71- #define EX_IOERR 74 /* input/output error */
72- #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
73- #define EX_NOPERM 77 /* permission denied */
74- #define EX_CONFIG 78 /* configuration error */
62+ // Program exit code constants compatible with sysexits.h.
63+ #define EXITCODE_OK 0
64+ #define EXITCODE_COMMAND_LINE_USAGE_ERROR 64
65+ #define EXITCODE_DATA_FORMAT_ERROR 65
66+ #define EXITCODE_NO_INPUT_ERROR 66
7567
7668// Implementation of flag representation for flags in the main() method
7769constexpr int FLAG_FG = 1 ;
@@ -581,11 +573,11 @@ int main(int argc, char *argv[]) {
581573 int columns = 3 ;
582574
583575 std::vector<std::string> file_names;
584- int ret = EX_OK ; // The return code for the program
576+ int ret = EXITCODE_OK ; // The return code for the program
585577
586578 if (argc <= 1 ) {
587579 printUsage ();
588- return EX_USAGE ;
580+ return EXITCODE_COMMAND_LINE_USAGE_ERROR ;
589581 }
590582
591583 for (int i = 1 ; i < argc; i++) {
@@ -597,7 +589,7 @@ int main(int argc, char *argv[]) {
597589 columns = std::stoi (argv[++i]);
598590 } else {
599591 std::cerr << " Error: -c requires a number" << std::endl;
600- ret = EX_USAGE ;
592+ ret = EXITCODE_COMMAND_LINE_USAGE_ERROR ;
601593 }
602594 } else if (arg == " -d" || arg == " --dir" ) {
603595 mode = THUMBNAILS;
@@ -608,7 +600,7 @@ int main(int argc, char *argv[]) {
608600 maxWidth = 4 * std::stoi (argv[++i]), detectSize = false ;
609601 } else {
610602 std::cerr << " Error: -w requires a number" << std::endl;
611- ret = EX_USAGE ;
603+ ret = EXITCODE_COMMAND_LINE_USAGE_ERROR ;
612604 }
613605 } else if (arg == " -h" ) {
614606 if (i < argc - 1 )
@@ -623,7 +615,7 @@ int main(int argc, char *argv[]) {
623615 flags |= FLAG_TELETEXT;
624616 } else if (arg[0 ] == ' -' ) {
625617 std::cerr << " Error: Unrecognized argument: " << arg << std::endl;
626- ret = EX_USAGE ;
618+ ret = EXITCODE_COMMAND_LINE_USAGE_ERROR ;
627619 } else {
628620 // Arguments that will be displayed
629621 if (std::filesystem::is_directory (arg)) {
@@ -638,7 +630,7 @@ int main(int argc, char *argv[]) {
638630 } else {
639631 std::cerr << " Error: Cannot open '" << arg
640632 << " ', permission issue?" << std::endl;
641- ret = EX_NOINPUT ;
633+ ret = EXITCODE_NO_INPUT_ERROR ;
642634 }
643635 }
644636 }
@@ -694,7 +686,7 @@ int main(int argc, char *argv[]) {
694686 } catch (cimg_library::CImgIOException &e) {
695687 std::cerr << " Error: '" << filename
696688 << " ' has an unrecognized file format" << std::endl;
697- ret = EX_DATAERR ;
689+ ret = EXITCODE_DATA_FORMAT_ERROR ;
698690 }
699691 }
700692 } else { // Thumbnail mode
0 commit comments