static program name (macro)

* make program name into the macro PROG_NAME
 * add program name into all error messages

Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
Daniel Santos 2022-03-12 16:32:13 +00:00
parent 90c869857b
commit a1447b807b
1 changed files with 6 additions and 8 deletions

View File

@ -4,6 +4,8 @@
#include <stdbool.h>
#include <errno.h>
#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 <number>\n", program_name);
fprintf(stderr, "usage: %s <number>\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);