/*###### Exit/Interrput routines #######################################*/
// The usual program end -- called only by functions in this section.
-static void bye_bye (int eno, const char *str) NORETURN;
-static void bye_bye (int eno, const char *str)
+static void bye_bye (FILE *fp, int eno, const char *str) NORETURN;
+static void bye_bye (FILE *fp, int eno, const char *str)
{
if (!Batch)
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savedtty);
//#define ATEOJ_REPORT
#ifdef ATEOJ_REPORT
- fprintf(stderr,
+ fprintf(fp,
"\n\tTerminal: %s"
"\n\t device = %s, ncurses = v%s"
"\n\t max_colors = %d, max_pairs = %d"
, Max_lines, Pseudo_size
);
- fprintf(stderr,
+ fprintf(fp,
#ifndef STDOUT_IOLBF
"\n\t Stdout_buf = %d, BUFSIZ = %u"
#endif
, Curwin->rc.sortindx
);
- fprintf(stderr,
+ fprintf(fp,
"\n\tProgram"
"\n\t Linux version = %u.%u.%u, %s"
"\n\t Hertz = %u (%u bytes, %u-bit time)"
#endif
- if (str) {
- if (eno) perror(str);
- else {
- fputs(str, stderr);
- eno = 1;
- }
- }
+ if (str) fputs(str, fp);
exit(eno);
}
static void end_pgm (int dont_care_sig)
{
(void)dont_care_sig;
- bye_bye(0, NULL);
+ bye_bye(stdout, 1, NULL);
}
exit(1);
}
/* not to worry, he'll change our exit code to 1 due to 'buf' */
- bye_bye(0, buf);
+ bye_bye(stderr, 1, buf);
+}
+
+
+ /*
+ * Standard out handler */
+static void std_out (const char *str) NORETURN;
+static void std_out (const char *str)
+{
+ static char buf[SMLBUFSIZ];
+
+ fflush(stdout);
+ /* we'll use our own buffer so callers can still use fmtmk() and, yes the
+ leading tab is not the standard convention, but the standard is wrong
+ -- OUR msg won't get lost in screen clutter, like so many others! */
+ snprintf(buf, sizeof(buf), "\t%s: %s\n", Myname, str);
+ if (!Ttychanged) {
+ fprintf(stdout, "%s\n", buf);
+ exit(0);
+ }
+ bye_bye(stdout, 0, buf);
}
break;
case 'h': case 'H':
case 'v': case 'V':
- std_err(fmtmk("%s\nusage:\t%s%s", procps_version, Myname, usage));
+ std_out(fmtmk("%s\nusage:\t%s%s", procps_version, Myname, usage));
case 'i':
TOGw(Curwin, Show_IDLEPS);
Curwin->rc.maxtasks = 0;