Improve error and warning output

Improve error messages generated by `errx()`, `warnx()` and similar.

Set `progname` to a static string with the name of the program so that
the path of the binary isn't included in error messages.

Signed-off-by: AntonioND <antonio_nd@outlook.com>
This commit is contained in:
AntonioND
2017-04-03 21:16:00 +01:00
parent e4b4e427f1
commit 25be5c6561
5 changed files with 24 additions and 10 deletions

View File

@@ -298,7 +298,7 @@ main(int argc, char *argv[])
if (argc == 1) if (argc == 1)
usage(); usage();
progname = argv[0]; progname = "rgbasm";
/* yydebug=1; */ /* yydebug=1; */

26
src/extern/err.c vendored
View File

@@ -30,30 +30,44 @@ extern char *progname;
void rgbds_vwarn(const char *fmt, va_list ap) void rgbds_vwarn(const char *fmt, va_list ap)
{ {
fprintf (stderr, "%s: ", progname); fprintf (stderr, "%s:warning", progname);
if (fmt) { if (fmt) {
fputs (":", stderr);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
fputs (": ", stderr);
} }
putc('\n', stderr);
perror(0); perror(0);
} }
void rgbds_vwarnx(const char *fmt, va_list ap) void rgbds_vwarnx(const char *fmt, va_list ap)
{ {
fprintf (stderr, "%s: ", progname); fprintf (stderr, "%s:warning", progname);
if (fmt) vfprintf(stderr, fmt, ap); if (fmt) {
fputs (":", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr); putc('\n', stderr);
} }
noreturn void rgbds_verr(int status, const char *fmt, va_list ap) noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
{ {
vwarn(fmt, ap); fprintf (stderr, "%s:error", progname);
if (fmt) {
fputs (":", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
exit(status); exit(status);
} }
noreturn void rgbds_verrx(int status, const char *fmt, va_list ap) noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
{ {
vwarnx(fmt, ap); fprintf (stderr, "%s:error", progname);
if (fmt) {
fputs (":", stderr);
vfprintf(stderr, fmt, ap);
}
putc('\n', stderr);
exit(status); exit(status);
} }

View File

@@ -71,7 +71,7 @@ main(int argc, char *argv[])
int version; /* mask ROM version number */ int version; /* mask ROM version number */
int padvalue; /* to pad the rom with if it changes size */ int padvalue; /* to pad the rom with if it changes size */
progname = argv[0]; progname = "rgbfix";
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) { while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) {
switch (ch) { switch (ch) {

View File

@@ -41,7 +41,7 @@ main(int argc, char *argv[])
char *ext; char *ext;
const char *errmsg = "Warning: The PNG's %s setting is not the same as the setting defined on the command line."; const char *errmsg = "Warning: The PNG's %s setting is not the same as the setting defined on the command line.";
progname = argv[0]; progname = "rgbgfx";
if (argc == 1) { if (argc == 1) {
usage(); usage();

View File

@@ -54,7 +54,7 @@ main(int argc, char *argv[])
if (argc == 1) if (argc == 1)
usage(); usage();
progname = argv[0]; progname = "rgblink";
while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:tw")) != -1) { while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:tw")) != -1) {
switch (ch) { switch (ch) {