2008-08-13 Eric Gillespie <epg@pretzelnet.org>
+ * sbr/ambigsw.c: Send print_sw output to stderr. This avoids
+ strange problems with scan `pick -bogus`, not to mention being
+ nicer anyway.
+
+ * sbr/getans.c, sbr/print_help.c, uip/msh.c: Send print_sw output
+ to stdout.
+
+ * h/prototypes.h, sbr/print_sw.c (print_sw): Add FILE * argument
+ and send output there rather than to stdout.
+
+ * test/tests/pick/test-stderr: Add test that error messages don't
+ end up going to stdout.
+
+2008-08-13 Eric Gillespie <epg@pretzelnet.org>
+
* uip/pick.c: Print matching messages immediately, instead of
waiting until the very end to print anything.
Ensure valid sequence name as soon as we parse it from command,
int pidstatus (int, FILE *, char *);
char *pluspath(char *);
void print_help (char *, struct swit *, int);
-void print_sw (char *, struct swit *, char *);
+void print_sw (char *, struct swit *, char *, FILE *);
void print_version (char *);
void push (void);
char *pwd (void);
ambigsw (char *arg, struct swit *swp)
{
advise (NULL, "-%s ambiguous. It matches", arg);
- print_sw (arg, swp, "-");
+ print_sw (arg, swp, "-", stderr);
}
*cp = '\0';
if (ansbuf[0] == '?' || cp == ansbuf) {
printf ("Options are:\n");
- print_sw (ALL, ansp, "");
+ print_sw (ALL, ansp, "", stdout);
continue;
}
cpp = brkstring (ansbuf, " ", NULL);
/* print all the switches */
printf (" switches are:\n");
- print_sw (ALL, swp, "-");
+ print_sw (ALL, swp, "-", stdout);
/*
* check if we should print any profile entries
void
-print_sw (char *substr, struct swit *swp, char *prefix)
+print_sw (char *substr, struct swit *swp, char *prefix, FILE *fp)
{
int len, optno;
register int i;
*cp++ = *cp1++;
*cp++ = ')';
while ((*cp++ = *cp1++));
- printf (" %s%s\n", prefix, buf);
+ fprintf (fp, " %s%s\n", prefix, buf);
} else {
if (!swp->minchars)
- printf(optno ? " %s[no]%s\n" : " %s%s\n", prefix, swp->sw);
+ fprintf(fp, optno ? " %s[no]%s\n" : " %s%s\n",
+ prefix, swp->sw);
}
if (optno)
swp++; /* skip -noswitch */
--- /dev/null
+#!/bin/sh
+######################################################
+#
+# Test that errors are not written to stdout.
+#
+######################################################
+
+expected_err=$MH_TEST_DIR/$$.expected_err
+expected_out=$MH_TEST_DIR/$$.expected_out
+actual_err=$MH_TEST_DIR/$$.actual_err
+actual_out=$MH_TEST_DIR/$$.actual_out
+
+# Error message should go to stderr.
+cat > $expected_err <<EOF
+pick: -a ambiguous. It matches
+ -and
+ -after date
+EOF
+# Nothing should to go stdout.
+cat /dev/null > $expected_out
+
+pick -a > $actual_out 2> $actual_err
+diff -u $expected_err $actual_err
+diff -u $expected_out $actual_out
continue;
if (buffer[0] == '?') {
printf ("commands:\n");
- print_sw (ALL, sw, "");
+ print_sw (ALL, sw, "", stdout);
printf ("type CTRL-D or use ``quit'' to leave %s\n",
invo_name);
continue;
case OK:
printf ("commands:\n");
- print_sw (ALL, sw, "");
+ print_sw (ALL, sw, "", stdout);
printf ("type ``quit'' to leave %s\n", invo_name);
fflush (stdout);
fflush (stderr);