Hi,
We (Knorrie, andi, and me) realized, that birdc outputs
server errors to stdout much like normal server output.
When scripting birdc, it can be helpful to have those on
stderr instead.
Simple use case:
birdc CMD >/dev/null
If everything is fine, no output at all. If something goes
wrong, output!
There are a few aspects:
1. Is this useful? Hopefully.
If you think this is a studpid idea, pleas explain!
2. Should this be the default (in an upcoming version)?
I don't know, how many non humans depend on *all* output
going to stdout and neglect stderr? Ignoring stderr IMHO
is a design flaw. But well, this is a question of
backward compatibility.
NOTE: Something should be added to the ChangeLog, so
people are not too surprised.
3. If the answer to (2) is "Need backward compatibility":
Do we need some --enable-stderr then?
Cheers
Christian
--
www.cosmokey.com
diff --git a/client/client.c b/client/client.c
index 56d79fc..1dee391 100644
--- a/client/client.c
+++ b/client/client.c
@@ -257,24 +257,31 @@ server_connect(void)
}
-#define PRINTF(LEN, PARGS...) do { if (!skip_input) len = printf(PARGS); } while(0)
+#define PRINTF_FP(LEN, FP, PARGS...) do { if (!skip_input) len = fprintf(FP, PARGS); } while(0)
+#define PRINTF(LEN, PARGS...) PRINTF_FP(LEN, stdout, PARGS)
static void
-server_got_reply(char *x)
+server_got_reply(const char *x)
{
- int code;
+ static int code = 0;
int len = 0;
if (*x == '+') /* Async reply */
PRINTF(len, ">>> %s\n", x+1);
else if (x[0] == ' ') /* Continuation */
- PRINTF(len, "%s%s\n", verbose ? " " : "", x+1);
+ {
+ PRINTF_FP(len, ((code >= 8000) ? stderr : stdout),
+ "%s%s\n", verbose ? " " : "", x+1);
+ }
else if (strlen(x) > 4 &&
sscanf(x, "%d", &code) == 1 && code >= 0 && code < 10000 &&
(x[4] == ' ' || x[4] == '-'))
{
if (code)
- PRINTF(len, "%s\n", verbose ? x : x+5);
+ {
+ PRINTF_FP(len, ((code >= 8000) ? stderr : stdout),
+ "%s\n", verbose ? x : x+5);
+ }
if (x[4] == ' ')
{