From a1447b807b302e48beeb85a61a1f036db2f5ff77 Mon Sep 17 00:00:00 2001 From: Daniel Santos Date: Sat, 12 Mar 2022 16:32:13 +0000 Subject: static program name (macro) * make program name into the macro PROG_NAME * add program name into all error messages Signed-off-by: Daniel Santos --- numericx.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/numericx.c b/numericx.c index 2870b13..b8c0254 100644 --- a/numericx.c +++ b/numericx.c @@ -4,6 +4,8 @@ #include #include +#define PROG_NAME "numericx" + #ifndef DEBUG #define DEBUG false #endif @@ -39,8 +41,6 @@ typedef struct NumeralPtr struct NumeralPtr *previous; } numeral_ptr; -char* program_name = NULL; - /* * Creates new digit for numeral_ptr * Return pointer to new numeral_ptr @@ -52,7 +52,7 @@ new_digit(numeral_ptr* last_numeral, char const* to_first) numeral_ptr* starting_point = malloc(sizeof(numeral_ptr)); if(starting_point == NULL) { - fprintf(stderr, "error: %s: %s!", program_name, strerror(ENOMEM)); + fprintf(stderr, "error: %s: %s!", PROG_NAME, strerror(ENOMEM)); return NULL; } @@ -210,12 +210,10 @@ free_numeral(numeral_ptr* numeral) int main(int argc, char* argv[]) { - program_name = argv[0]; - /* argument processing */ if( !(argc == 2) ) { - fprintf(stderr, "usage: %s \n", program_name); + fprintf(stderr, "usage: %s \n", PROG_NAME); exit(EXIT_FAILURE); } @@ -234,7 +232,7 @@ main(int argc, char* argv[]) { free(from); free(to); - fprintf(stderr, "error: %s.\n", strerror(EDOM)); + fprintf(stderr, "error: %s: %s.\n", PROG_NAME, strerror(EDOM)); exit(EDOM); } @@ -272,7 +270,7 @@ main(int argc, char* argv[]) free(to); free_numeral(counting); free_numeral(result); - fprintf(stderr, "error: unrepresentable void number\n"); + fprintf(stderr, "error: %s: unrepresentable void number\n", PROG_NAME); exit(EXIT_FAILURE); } decrement_number_string(number, from_first, from_last, from_first); -- cgit 1.4.1-2-gfad0