From owner-svn-src-all@FreeBSD.ORG Tue Dec 21 20:47:06 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D74AC1065672; Tue, 21 Dec 2010 20:47:06 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C5DB98FC17; Tue, 21 Dec 2010 20:47:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBLKl6ft075075; Tue, 21 Dec 2010 20:47:06 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBLKl61H075068; Tue, 21 Dec 2010 20:47:06 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201012212047.oBLKl61H075068@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 21 Dec 2010 20:47:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216622 - in head/bin/sh: . bltin X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Dec 2010 20:47:07 -0000 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;