Return EXIT_FAILURE instead of exit(1)

This commit is contained in:
Unknown 2018-05-21 13:26:37 +02:00
parent 01f4dfcddf
commit fb15df2f4a

View File

@ -165,7 +165,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "'; expected 'force' or nothing." << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "'; expected 'force' or nothing." << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
else { else {
@ -185,7 +185,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
break; break;
@ -203,7 +203,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
break; break;
@ -217,7 +217,7 @@ int Mapper::start(int argc, char *argv[]) {
if (!isdigit(optarg[0])) { if (!isdigit(optarg[0])) {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': must be a positive number" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': must be a positive number" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
int size = atoi(optarg); int size = atoi(optarg);
@ -253,7 +253,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
break; break;
case OPT_HEIGHT_LEVEL0: case OPT_HEIGHT_LEVEL0:
@ -264,7 +264,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
break; break;
case OPT_BLOCKCOLOR: case OPT_BLOCKCOLOR:
@ -303,7 +303,7 @@ int Mapper::start(int argc, char *argv[]) {
std::cerr << "Invalid parameter to '" << long_options[option_index].name std::cerr << "Invalid parameter to '" << long_options[option_index].name
<< "': '" << optarg << "' (expected: left,top)" << std::endl; << "': '" << optarg << "' (expected: left,top)" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
else { else {
@ -324,7 +324,7 @@ int Mapper::start(int argc, char *argv[]) {
std::cerr << "Invalid parameter to '" << long_options[option_index].name std::cerr << "Invalid parameter to '" << long_options[option_index].name
<< "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl; << "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
arg >> std::ws >> sep >> std::ws; arg >> std::ws >> sep >> std::ws;
if (!arg.fail()) { if (!arg.fail()) {
@ -332,14 +332,14 @@ int Mapper::start(int argc, char *argv[]) {
std::cerr << "Invalid parameter to '" << long_options[option_index].name std::cerr << "Invalid parameter to '" << long_options[option_index].name
<< "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl; << "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
arg >> minor; arg >> minor;
if (minor < 0) { if (minor < 0) {
std::cerr << "Invalid parameter to '" << long_options[option_index].name std::cerr << "Invalid parameter to '" << long_options[option_index].name
<< "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl; << "': '" << optarg << "' (expected: <major>[,<minor>]" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
else { else {
@ -349,7 +349,7 @@ int Mapper::start(int argc, char *argv[]) {
if (major % minor) { if (major % minor) {
std::cerr << long_options[option_index].name << ": Cannot divide major interval in " std::cerr << long_options[option_index].name << ": Cannot divide major interval in "
<< minor << " subintervals (not divisible)" << std::endl; << minor << " subintervals (not divisible)" << std::endl;
exit(1); return EXIT_FAILURE;
} }
minor = major / minor; minor = major / minor;
} }
@ -363,7 +363,7 @@ int Mapper::start(int argc, char *argv[]) {
} }
else { else {
std::cerr << "Internal error: option " << long_options[option_index].name << " not handled" << std::endl; std::cerr << "Internal error: option " << long_options[option_index].name << " not handled" << std::endl;
exit(1); return EXIT_FAILURE;
} }
} }
break; break;
@ -392,7 +392,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid flag to '" << long_options[option_index].name << "': '" << flag << "'" << std::endl; std::cerr << "Invalid flag to '" << long_options[option_index].name << "': '" << flag << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
iss >> flag; iss >> flag;
} }
@ -433,7 +433,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl; std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
break; break;
case OPT_DRAWAIR: case OPT_DRAWAIR:
@ -463,7 +463,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid " << long_options[option_index].name << " flag '" << flag << "'" << std::endl; std::cerr << "Invalid " << long_options[option_index].name << " flag '" << flag << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
iss >> flag; iss >> flag;
} }
@ -506,7 +506,7 @@ int Mapper::start(int argc, char *argv[]) {
if (iss.fail() || size < 0) { if (iss.fail() || size < 0) {
std::cerr << "Invalid chunk size (" << optarg << ")" << std::endl; std::cerr << "Invalid chunk size (" << optarg << ")" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
generator.setChunkSize(size); generator.setChunkSize(size);
} }
@ -520,18 +520,18 @@ int Mapper::start(int argc, char *argv[]) {
arg >> one >> std::ws; arg >> one >> std::ws;
if (arg.fail() || one != 1) { if (arg.fail() || one != 1) {
std::cerr << "Invalid scale factor specification (" << optarg << ") - expected: 1:<n>" << std::endl; std::cerr << "Invalid scale factor specification (" << optarg << ") - expected: 1:<n>" << std::endl;
exit(1); return EXIT_FAILURE;
} }
if (!arg.eof()) { if (!arg.eof()) {
arg >> colon >> factor >> std::ws; arg >> colon >> factor >> std::ws;
if (arg.fail() || colon != ':' || factor<0 || !arg.eof()) { if (arg.fail() || colon != ':' || factor<0 || !arg.eof()) {
std::cerr << "Invalid scale factor specification (" << optarg << ") - expected: 1:<n>" << std::endl; std::cerr << "Invalid scale factor specification (" << optarg << ") - expected: 1:<n>" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
if (factor != 1 && factor != 2 && factor != 4 && factor != 8 && factor != 16) { if (factor != 1 && factor != 2 && factor != 4 && factor != 8 && factor != 16) {
std::cerr << "Scale factor must be 1:1, 1:2, 1:4, 1:8 or 1:16" << std::endl; std::cerr << "Scale factor must be 1:1, 1:2, 1:4, 1:8 or 1:16" << std::endl;
exit(1); return EXIT_FAILURE;
} }
} }
generator.setScaleFactor(factor); generator.setScaleFactor(factor);
@ -555,7 +555,7 @@ int Mapper::start(int argc, char *argv[]) {
if (tilesize.fail() || size<0) { if (tilesize.fail() || size<0) {
std::cerr << "Invalid tile size specification (" << optarg << ")" << std::endl; std::cerr << "Invalid tile size specification (" << optarg << ")" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
generator.setTileSize(size, size); generator.setTileSize(size, size);
tilesize >> c >> border; tilesize >> c >> border;
@ -563,7 +563,7 @@ int Mapper::start(int argc, char *argv[]) {
if (c != '+' || border < 1) { if (c != '+' || border < 1) {
std::cerr << "Invalid tile border size specification (" << optarg << ")" << std::endl; std::cerr << "Invalid tile border size specification (" << optarg << ")" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
generator.setTileBorderSize(border); generator.setTileBorderSize(border);
} }
@ -606,7 +606,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid " << long_options[option_index].name << " parameter (" << optarg << ")" << std::endl; std::cerr << "Invalid " << long_options[option_index].name << " parameter (" << optarg << ")" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
} }
} }
@ -643,7 +643,7 @@ int Mapper::start(int argc, char *argv[]) {
else { else {
std::cerr << "Invalid geometry mode flag '" << flag << "'" << std::endl; std::cerr << "Invalid geometry mode flag '" << flag << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
if (flag == "fixed" || flag == "shrink") if (flag == "fixed" || flag == "shrink")
setFixedOrShrinkGeometry = true; setFixedOrShrinkGeometry = true;
@ -666,7 +666,7 @@ int Mapper::start(int argc, char *argv[]) {
if (!parseMapGeometry(iss, coord1, coord2, legacy, center)) { if (!parseMapGeometry(iss, coord1, coord2, legacy, center)) {
std::cerr << "Invalid geometry specification '" << optarg << "'" << std::endl; std::cerr << "Invalid geometry specification '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
// Set defaults // Set defaults
if (!foundGeometrySpec) { if (!foundGeometrySpec) {
@ -720,7 +720,7 @@ int Mapper::start(int argc, char *argv[]) {
std::cerr << "Internal error: unrecognised object (" std::cerr << "Internal error: unrecognised object ("
<< long_options[option_index].name << long_options[option_index].name
<< ")" << std::endl; << ")" << std::endl;
exit(1); return EXIT_FAILURE;
break; break;
} }
@ -742,7 +742,7 @@ int Mapper::start(int argc, char *argv[]) {
<< long_options[option_index].name << long_options[option_index].name
<< " '" << optarg << "'" << std::endl; << " '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
bool haveCoord2 = coord2.dimension[0] != NodeCoord::Invalid bool haveCoord2 = coord2.dimension[0] != NodeCoord::Invalid
&& coord2.dimension[1] != NodeCoord::Invalid; && coord2.dimension[1] != NodeCoord::Invalid;
@ -786,7 +786,7 @@ int Mapper::start(int argc, char *argv[]) {
<< long_options[option_index].name << long_options[option_index].name
<< " '" << optarg << "'" << std::endl; << " '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
drawObject.color = colorStr; drawObject.color = colorStr;
@ -799,7 +799,7 @@ int Mapper::start(int argc, char *argv[]) {
<< long_options[option_index].name << long_options[option_index].name
<< " '" << optarg << "'" << std::endl; << " '" << optarg << "'" << std::endl;
usage(); usage();
exit(1); return EXIT_FAILURE;
} }
drawObject.text = localizedText; drawObject.text = localizedText;
} }
@ -809,7 +809,7 @@ int Mapper::start(int argc, char *argv[]) {
if (drawObject.haveCenter) { if (drawObject.haveCenter) {
std::cerr << "Arrow cannot use a centered dimension." std::cerr << "Arrow cannot use a centered dimension."
<< " Specify at least one corner." << std::endl; << " Specify at least one corner." << std::endl;
exit(1); return EXIT_FAILURE;
} }
bool useDimensions = drawObject.haveDimensions; bool useDimensions = drawObject.haveDimensions;
@ -836,7 +836,7 @@ int Mapper::start(int argc, char *argv[]) {
generator.setBackend(strlower(optarg)); generator.setBackend(strlower(optarg));
break; break;
default: default:
exit(1); return EXIT_FAILURE;
} }
} }
} }