tools: cleanup up printf

Make all tools output to stdout (pw-mon mostly) so that we can pipe the
output around.
Send errors to stderr.
fprintf(stdout, ...)  -> printf(...)
setlinebuf for stdout so that pipe works better.

See #2110
This commit is contained in:
Wim Taymans 2022-02-07 17:03:46 +01:00
parent a16cd95593
commit afc88a12e5
12 changed files with 349 additions and 334 deletions

View file

@ -1458,9 +1458,9 @@ static void do_quit(void *data, int signal_number)
pw_main_loop_quit(d->loop);
}
static void show_help(struct data *data, const char *name)
static void show_help(struct data *data, const char *name, bool error)
{
fprintf(stdout, "%s [options] [<id>]\n"
fprintf(error ? stderr : stdout, "%s [options] [<id>]\n"
" -h, --help Show this help\n"
" --version Show version\n"
" -r, --remote Remote daemon name\n"
@ -1492,14 +1492,15 @@ int main(int argc, char *argv[])
data.out = stdout;
if (isatty(fileno(data.out)) && getenv("NO_COLOR") == NULL)
colors = true;
setlinebuf(data.out);
while ((c = getopt_long(argc, argv, "hVr:mNC", long_options, NULL)) != -1) {
switch (c) {
case 'h' :
show_help(&data, argv[0]);
show_help(&data, argv[0], false);
return 0;
case 'V' :
fprintf(stdout, "%s\n"
printf("%s\n"
"Compiled with libpipewire %s\n"
"Linked with libpipewire %s\n",
argv[0],
@ -1524,12 +1525,13 @@ int main(int argc, char *argv[])
else if (!strcmp(optarg, "always"))
colors = true;
else {
show_help(&data, argv[0]);
fprintf(stderr, "Unknown color: %s\n", optarg);
show_help(&data, argv[0], true);
return -1;
}
break;
default:
show_help(&data, argv[0]);
show_help(&data, argv[0], true);
return -1;
}
}