Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Dec 2010 20:47:06 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r216622 - in head/bin/sh: . bltin
Message-ID:  <201012212047.oBLKl61H075068@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Tue Dec 21 20:47:06 2010
New Revision: 216622
URL: http://svn.freebsd.org/changeset/base/216622

Log:
  sh: Add a function to print warnings (with command name and newline).
  This is like error() but without raising an exception.
  It is particularly useful as a replacement for the warnx macro in
  bltin/bltin.h.

Modified:
  head/bin/sh/alias.c
  head/bin/sh/bltin/bltin.h
  head/bin/sh/cd.c
  head/bin/sh/error.c
  head/bin/sh/error.h
  head/bin/sh/trap.c

Modified: head/bin/sh/alias.c
==============================================================================
--- head/bin/sh/alias.c	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/alias.c	Tue Dec 21 20:47:06 2010	(r216622)
@@ -246,7 +246,7 @@ aliascmd(int argc, char **argv)
 	while ((n = *++argv) != NULL) {
 		if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */
 			if ((ap = lookupalias(n, 0)) == NULL) {
-				outfmt(out2, "alias: %s not found\n", n);
+				warning("%s not found", n);
 				ret = 1;
 			} else
 				printalias(ap);

Modified: head/bin/sh/bltin/bltin.h
==============================================================================
--- head/bin/sh/bltin/bltin.h	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/bltin/bltin.h	Tue Dec 21 20:47:06 2010	(r216622)
@@ -57,11 +57,7 @@
 #define fwrite(ptr, size, nmemb, file) outbin(ptr, (size) * (nmemb), file)
 #define fflush flushout
 #define INITARGS(argv)
-#define warnx(...) do {					\
-	out2fmt_flush("%s: ", commandname);		\
-	out2fmt_flush(__VA_ARGS__);			\
-	out2fmt_flush("\n");				\
-	} while (0)
+#define warnx warning
 #define errx(exitstatus, ...) error(__VA_ARGS__)
 
 #else

Modified: head/bin/sh/cd.c
==============================================================================
--- head/bin/sh/cd.c	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/cd.c	Tue Dec 21 20:47:06 2010	(r216622)
@@ -224,7 +224,7 @@ cdphysical(char *dest)
 	}
 	p = findcwd(NULL);
 	if (p == NULL)
-		out2fmt_flush("cd: warning: failed to get name of current directory\n");
+		warning("warning: failed to get name of current directory");
 	updatepwd(p);
 	INTON;
 	return (0);

Modified: head/bin/sh/error.c
==============================================================================
--- head/bin/sh/error.c	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/error.c	Tue Dec 21 20:47:06 2010	(r216622)
@@ -134,6 +134,26 @@ onint(void)
 }
 
 
+static void
+vwarning(const char *msg, va_list ap)
+{
+	if (commandname)
+		outfmt(out2, "%s: ", commandname);
+	doformat(out2, msg, ap);
+	out2fmt_flush("\n");
+}
+
+
+void
+warning(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vwarning(msg, ap);
+	va_end(ap);
+}
+
+
 /*
  * Exverror is called to raise the error exception.  If the first argument
  * is not NULL then error prints an error message using printf style
@@ -158,12 +178,8 @@ exverror(int cond, const char *msg, va_l
 	else
 		TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
 #endif
-	if (msg) {
-		if (commandname)
-			outfmt(out2, "%s: ", commandname);
-		doformat(out2, msg, ap);
-		out2c('\n');
-	}
+	if (msg)
+		vwarning(msg, ap);
 	flushall();
 	exraise(cond);
 }

Modified: head/bin/sh/error.h
==============================================================================
--- head/bin/sh/error.h	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/error.h	Tue Dec 21 20:47:06 2010	(r216622)
@@ -80,6 +80,7 @@ extern volatile sig_atomic_t intpending;
 
 void exraise(int) __dead2;
 void onint(void);
+void warning(const char *, ...) __printflike(1, 2);
 void error(const char *, ...) __printf0like(1, 2) __dead2;
 void exerror(int, const char *, ...) __printf0like(2, 3) __dead2;
 

Modified: head/bin/sh/trap.c
==============================================================================
--- head/bin/sh/trap.c	Tue Dec 21 19:30:24 2010	(r216621)
+++ head/bin/sh/trap.c	Tue Dec 21 20:47:06 2010	(r216622)
@@ -185,7 +185,7 @@ trapcmd(int argc, char **argv)
 	}
 	while (*argv) {
 		if ((signo = sigstring_to_signum(*argv)) == -1) {
-			out2fmt_flush("trap: bad signal %s\n", *argv);
+			warning("bad signal %s", *argv);
 			errors = 1;
 		}
 		INTOFF;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012212047.oBLKl61H075068>