From: Christian Heller Date: Wed, 14 Aug 2013 09:35:12 +0000 (+0200) Subject: Move checking for error results into exit_err(), out of conditionals in the remaining... X-Git-Tag: tce~1098 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/day_todos?a=commitdiff_plain;h=a974cdd6664ac23668baf50cdafe80b8c8838b1c;p=plomrogue Move checking for error results into exit_err(), out of conditionals in the remaining code. --- diff --git a/src/rexit.c b/src/rexit.c index f7bb3f2..223c79b 100644 --- a/src/rexit.c +++ b/src/rexit.c @@ -59,8 +59,12 @@ extern void exit_game(struct World * world) -extern void exit_err(struct World * world, char * msg) +extern void exit_err(unsigned char fail, struct World * world, char * msg) { + if (0 == fail) + { + return; + } cleanup(world); printf(msg); exit(EXIT_FAILURE); diff --git a/src/rexit.h b/src/rexit.h index 8a5444f..d4b19d7 100644 --- a/src/rexit.h +++ b/src/rexit.h @@ -29,10 +29,16 @@ extern void set_cleanup_flag(enum cleanup_flag flag); -/* Exit orderly without message or on error with an error message ("msg"). - */ +/* Exit orderly, clean up. */ extern void exit_game(struct World * world); -extern void exit_err(struct World * world, char * msg); + + + +/* If fail != 0, exit with an error message "msg" and clean up. (For "fail", + * pass the result of functions that return non-zero as an error status and + * thereby avoid bloating up the code with if-error-conditionals.) + */ +extern void exit_err(unsigned char fail, struct World * world, char * msg);