diff options
author | jilles <jilles@FreeBSD.org> | 2010-12-21 20:47:06 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-12-21 20:47:06 +0000 |
commit | eb00352e45c46febb8e2b0df1a048451d79de792 (patch) | |
tree | 9100639c6e991583a424211610f1fda83edfd6a2 /bin | |
parent | da7284d25303e2c3a5c54e86ebdd14fd514eb5f9 (diff) | |
download | FreeBSD-src-eb00352e45c46febb8e2b0df1a048451d79de792.zip FreeBSD-src-eb00352e45c46febb8e2b0df1a048451d79de792.tar.gz |
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.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/alias.c | 2 | ||||
-rw-r--r-- | bin/sh/bltin/bltin.h | 6 | ||||
-rw-r--r-- | bin/sh/cd.c | 2 | ||||
-rw-r--r-- | bin/sh/error.c | 28 | ||||
-rw-r--r-- | bin/sh/error.h | 1 | ||||
-rw-r--r-- | bin/sh/trap.c | 2 |
6 files changed, 27 insertions, 14 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c index c815b92..0b7e31a 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -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); diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h index 6618108..f6e7883 100644 --- a/bin/sh/bltin/bltin.h +++ b/bin/sh/bltin/bltin.h @@ -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 diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 068dfb7..041d6b4 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -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); diff --git a/bin/sh/error.c b/bin/sh/error.c index beb75fa..c76a9dc 100644 --- a/bin/sh/error.c +++ b/bin/sh/error.c @@ -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_list ap) 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); } diff --git a/bin/sh/error.h b/bin/sh/error.h index 8b64fe6..bf11c67 100644 --- a/bin/sh/error.h +++ b/bin/sh/error.h @@ -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; diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 3a6803b..e673ef6 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -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; |