Use PROGNAME_CPP for the binary name

This commit is contained in:
Pierre Pronchery 2022-04-30 22:20:00 +02:00
parent 45918377c7
commit 35e6a0c428

View File

@ -24,6 +24,10 @@
#include <errno.h>
#include "CPP.h"
#ifndef PROGNAME_CPP
# define PROGNAME_CPP "cpp"
#endif
/* cpp */
/* private */
@ -62,13 +66,13 @@ static int _cpp(Prefs * prefs, int filec, char * filev[])
if(prefs->outfile == NULL)
fp = stdout;
else if((fp = fopen(prefs->outfile, "w")) == NULL)
return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
strerror(errno));
return error_set_print(PROGNAME_CPP, 1, "%s: %s",
prefs->outfile, strerror(errno));
for(i = 0; i < filec; i++)
ret |= _cpp_do(prefs, fp, filev[i]);
if(fclose(fp) != 0)
return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
strerror(errno));
return error_set_print(PROGNAME_CPP, 1, "%s: %s",
prefs->outfile, strerror(errno));
return ret;
}
@ -143,7 +147,7 @@ static void _do_print_token(FILE * fp, Token * token)
/* cpp_error */
static int _cpp_error(void)
{
return error_print("cpp");
return error_print(PROGNAME_CPP);
}
@ -151,7 +155,7 @@ static int _cpp_error(void)
/* FIXME -E prints metadata? */
static int _usage(void)
{
fputs("Usage: cpp [-D name[=value]]...[-I directory][-o file][-t][-U name]... input...\n"
fputs("Usage: " PROGNAME_CPP " [-D name[=value]]...[-I directory][-o file][-t][-U name]... input...\n"
" -D Add a substitution\n"
" -I Add a directory to the search path\n"
" -o Write output to a file\n"
@ -218,7 +222,7 @@ static int _main_add_define(Prefs * prefs, char * define)
value = strtok(define, "=");
if((p = realloc(prefs->defines, sizeof(*p) * (prefs->defines_cnt + 1)))
== NULL)
return error_set_print("cpp", 1, "%s", strerror(errno));
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
prefs->defines = p;
prefs->defines[prefs->defines_cnt++] = define;
return 0;
@ -230,7 +234,7 @@ static int _main_add_path(Prefs * prefs, char const * path)
if((p = realloc(prefs->paths, sizeof(*p) * (prefs->paths_cnt + 1)))
== NULL)
return error_set_print("cpp", 1, "%s", strerror(errno));
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
prefs->paths = p;
prefs->paths[prefs->paths_cnt++] = path;
return 0;
@ -244,7 +248,7 @@ static int _main_add_undefine(Prefs * prefs, char const * undefine)
return 1;
if((p = realloc(prefs->undefines, sizeof(*p)
* (prefs->undefines_cnt + 1))) == NULL)
return error_set_print("cpp", 1, "%s", strerror(errno));
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
prefs->undefines = p;
prefs->undefines[prefs->undefines_cnt++] = undefine;
return 0;