Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: make zsh print errors like a well-behaved compiler



This will change the error given when running a script
from something like

/tmp/brokenscript: command not found: badcommand [5]
/tmp/brokenscript:5: command not found: badcommand

This makes it parsable for emacs's compile-goto-error
and all sorts of other fun software that can now
be led to believe that zsh is a compiler.

It also makes 5 look more like a line number instead
of a possible error code.

--- Src/utils.c	1999/11/05 15:49:30	1.1.1.42
+++ Src/utils.c	1999/11/25 17:05:29
@@ -76,7 +76,7 @@
      */
     nicezputs((isset(SHINSTDIN) && !locallevel) ? "zsh" :
 	      scriptname ? scriptname : argzero, stderr);
-    fputs(": ", stderr);
+    fputc((unsigned char)':', stderr);
     zerrmsg(fmt, str, num);
 }
 
@@ -89,11 +89,11 @@
     trashzle();
     if (unset(SHINSTDIN) || locallevel) {
 	nicezputs(scriptname ? scriptname : argzero, stderr);
-	fputs(": ", stderr);
+	fputc((unsigned char)':', stderr);
     }
     if (cmd) {
 	nicezputs(cmd, stderr);
-	fputs(": ", stderr);
+	fputc((unsigned char)':', stderr);
     }
     zerrmsg(fmt, str, num);
 }
@@ -102,6 +102,11 @@
 void
 zerrmsg(const char *fmt, const char *str, int num)
 {
+    if ((unset(SHINSTDIN) || locallevel) && lineno)
+	fprintf(stderr, "%ld: ", (long)lineno);
+    else
+	fputc((unsigned char)' ', stderr);
+
     while (*fmt)
 	if (*fmt == '%') {
 	    fmt++;
@@ -149,10 +154,7 @@
 	    putc(*fmt == Meta ? *++fmt ^ 32 : *fmt, stderr);
 	    fmt++;
 	}
-    if ((unset(SHINSTDIN) || locallevel) && lineno)
-	fprintf(stderr, " [%ld]\n", (long)lineno);
-    else
-	putc('\n', stderr);
+    putc('\n', stderr);
     fflush(stderr);
 }



Messages sorted by: Reverse Date, Date, Thread, Author