shithub: rgbds

Download patch

ref: 25be5c65611d99bfc9809010c4e4b2a9b9ee2507
parent: e4b4e427f12769fd309792c37bbbc1daf7908add
author: AntonioND <[email protected]>
date: Mon Apr 3 17:16:00 EDT 2017

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 <[email protected]>

--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -298,7 +298,7 @@
 	if (argc == 1)
 		usage();
 
-	progname = argv[0];
+	progname = "rgbasm";
 
 	/* yydebug=1; */
 
--- a/src/extern/err.c
+++ b/src/extern/err.c
@@ -30,30 +30,44 @@
 
 void rgbds_vwarn(const char *fmt, va_list ap)
 {
-	fprintf (stderr, "%s: ", progname);
+	fprintf (stderr, "%s:warning", progname);
 	if (fmt) {
+		fputs (":", stderr);
 		vfprintf(stderr, fmt, ap);
-		fputs (": ", stderr);
 	}
+	putc('\n', stderr);
 	perror(0);
 }
 
 void rgbds_vwarnx(const char *fmt, va_list ap)
 {
-	fprintf (stderr, "%s: ", progname);
-	if (fmt) vfprintf(stderr, fmt, ap);
+	fprintf (stderr, "%s:warning", progname);
+	if (fmt) {
+		fputs (":", stderr);
+		vfprintf(stderr, fmt, ap);
+	}
 	putc('\n', stderr);
 }
 
 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);
 }
 
 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);
 }
 
--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -71,7 +71,7 @@
 	int version;   /* mask ROM version number */
 	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) {
 		switch (ch) {
--- a/src/gfx/main.c
+++ b/src/gfx/main.c
@@ -41,7 +41,7 @@
 	char *ext;
 	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) {
 		usage();
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -54,7 +54,7 @@
 	if (argc == 1)
 		usage();
 
-	progname = argv[0];
+	progname = "rgblink";
 
 	while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:tw")) != -1) {
 		switch (ch) {