normalize use of stdio functions taking a stream

We should never use stdio functions that use stdout implicitly. Saving a
few characters isn't worth the inconsistency. Too, using the forms such
as `fwprintf()` which take an explicit stream makes it easier to find
the places we write to stdout versus stderr.

Fixes #3728
This commit is contained in:
Kurtis Rader 2017-01-13 20:34:15 -08:00
parent 509ce38375
commit 2e9a349dd0
11 changed files with 42 additions and 38 deletions

View file

@ -25,7 +25,7 @@
static const int kAutoloadStalenessInterval = 15;
file_access_attempt_t access_file(const wcstring &path, int mode) {
// wprintf(L"Touch %ls\n", path.c_str());
// fwprintf(stderr, L"Touch %ls\n", path.c_str());
file_access_attempt_t result = {};
struct stat statbuf;
if (wstat(path, &statbuf)) {

View file

@ -608,7 +608,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
param7, param8, param9, param10, param11, param12};
if (!msg) return;
// Can't call wprintf, that may allocate memory Just call write() over and over.
// Can't call fwprintf, that may allocate memory Just call write() over and over.
if (level > debug_level) return;
int errno_old = errno;
@ -1691,7 +1691,7 @@ bool is_forked_child(void) {
bool is_child_of_fork = (getpid() != initial_pid);
if (is_child_of_fork) {
wprintf(L"Uh-oh: %d\n", getpid());
debug(0, L"Uh-oh: getpid() != initial_pid: %d != %d\n", getpid(), initial_pid);
while (1) sleep(10000);
}
return is_child_of_fork;

View file

@ -162,11 +162,11 @@ wcstring event_get_desc(const event_t &e) {
#if 0
static void show_all_handlers(void) {
wprintf(L"event handlers:\n");
fwprintf(stdout, L"event handlers:\n");
for (event_list_t::const_iterator iter = events.begin(); iter != events.end(); ++iter) {
const event_t *foo = *iter;
wcstring tmp = event_get_desc(foo);
wprintf(L" handler now %ls\n", tmp.c_str());
fwprintf(stdout, L" handler now %ls\n", tmp.c_str());
}
}
#endif

View file

@ -763,7 +763,7 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
stop_pos++;
}
// wprintf(L"Stop for '%c'\n", in[stop_pos]);
// fwprintf(stdout, L"Stop for '%c'\n", in[stop_pos]);
var_len = stop_pos - start_pos;
if (var_len == 0) {

View file

@ -183,7 +183,7 @@ static void output_info_about_char(wchar_t wc) {
static bool output_matching_key_name(wchar_t wc) {
char *name = sequence_name(wc);
if (name) {
wprintf(L"bind -k %s 'do something'\n", name);
fwprintf(stdout, L"bind -k %s 'do something'\n", name);
free(name);
return true;
}

View file

@ -100,9 +100,9 @@ static int err_count = 0;
static void say(const wchar_t *fmt, ...) {
va_list va;
va_start(va, fmt);
vwprintf(fmt, va);
vfwprintf(stdout, fmt, va);
va_end(va);
wprintf(L"\n");
fwprintf(stdout, L"\n");
}
/// Print formatted error string.
@ -118,8 +118,8 @@ static void err(const wchar_t *blah, ...) {
if (colorize) {
fputws(L"\e[31m", stdout);
}
wprintf(L"Error: ");
vwprintf(blah, va);
fwprintf(stdout, L"Error: ");
vfwprintf(stdout, blah, va);
va_end(va);
// Return to normal color.
@ -127,7 +127,7 @@ static void err(const wchar_t *blah, ...) {
fputws(L"\e[0m", stdout);
}
wprintf(L"\n");
fwprintf(stdout, L"\n");
}
/// Joins a wcstring_list_t via commas.
@ -451,8 +451,8 @@ static void test_tokenizer() {
}
if (types[i] != token.type) {
err(L"Tokenization error:");
wprintf(L"Token number %zu of string \n'%ls'\n, got token type %ld\n", i + 1, str,
(long)token.type);
fwprintf(stdout, L"Token number %zu of string \n'%ls'\n, got token type %ld\n",
i + 1, str, (long)token.type);
}
i++;
}
@ -1726,7 +1726,8 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style,
size_t char_idx = (motion == word_motion_left ? idx - 1 : idx);
wchar_t wc = command.at(char_idx);
bool will_stop = !sm.consume_char(wc);
// wprintf(L"idx %lu, looking at %lu (%c): %d\n", idx, char_idx, (char)wc, will_stop);
// fwprintf(stdout, L"idx %lu, looking at %lu (%c): %d\n", idx, char_idx, (char)wc,
// will_stop);
bool expected_stop = (stops.count(idx) > 0);
if (will_stop != expected_stop) {
wcstring tmp = command;
@ -2211,15 +2212,15 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command,
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
printf("line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
do_test(!comps.empty());
return;
} else if (!comps.empty() && expects_error) {
printf(
"line %ld: autosuggest_suggest_special() was expected to fail but did not, for command "
"%ls\n",
line, command.c_str());
fwprintf(stderr,
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
do_test(comps.empty());
}
@ -2228,11 +2229,12 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command,
const completion_t &suggestion = comps.at(0);
if (suggestion.completion != expected) {
printf(
"line %ld: complete() for cd returned the wrong expected string for command %ls\n",
fwprintf(
stderr,
L"line %ld: complete() for cd returned the wrong expected string for command %ls\n",
line, command.c_str());
printf(" actual: %ls\n", suggestion.completion.c_str());
printf("expected: %ls\n", expected.c_str());
fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
fwprintf(stderr, L"expected: %ls\n", expected.c_str());
do_test(suggestion.completion == expected);
}
}
@ -2347,8 +2349,9 @@ static void perform_one_autosuggestion_should_ignore_test(const wcstring &comman
do_test(comps.empty());
if (!comps.empty()) {
const wcstring &suggestion = comps.front().completion;
printf("line %ld: complete() expected to return nothing for %ls\n", line, command.c_str());
printf(" instead got: %ls\n", suggestion.c_str());
fwprintf(stderr, L"line %ld: complete() expected to return nothing for %ls\n", line,
command.c_str());
fwprintf(stderr, L" instead got: %ls\n", suggestion.c_str());
}
}
@ -3136,7 +3139,7 @@ void history_tests_t::test_history_speed(void)
if (stop >= end)
break;
}
printf("%lu items - %.2f msec per item\n", (unsigned long)count, (stop - start) * 1E6 / count);
fwprintf(stdout, L"%lu items - %.2f msec per item\n", (unsigned long)count, (stop - start) * 1E6 / count);
hist->clear();
delete hist;
}

View file

@ -275,7 +275,8 @@ void iothread_drain_all(void) {
}
#if TIME_DRAIN
double after = timef();
wprintf(L"(Waited %.02f msec for %d thread(s) to drain)\n", 1000 * (after - now), thread_count);
fwprintf(stdout, L"(Waited %.02f msec for %d thread(s) to drain)\n", 1000 * (after - now),
thread_count);
#endif
}

View file

@ -537,8 +537,8 @@ rgb_color_t parse_color(const wcstring &val, bool is_background) {
#if 0
wcstring desc = result.description();
wprintf(L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
is_background ? "background" : "foreground");
fwprintf(stdout, L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
is_background ? "background" : "foreground");
#endif
return result;

View file

@ -80,9 +80,9 @@ void print_jobs(void)
job_iterator_t jobs;
job_t *j;
while (j = jobs.next()) {
wprintf("%p -> %ls -> (foreground %d, complete %d, stopped %d, constructed %d)\n",
j, j->command_wcstr(), job_get_flag(j, JOB_FOREGROUND), job_is_completed(j),
job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED));
fwprintf(stdout, L"%p -> %ls -> (foreground %d, complete %d, stopped %d, constructed %d)\n",
j, j->command_wcstr(), job_get_flag(j, JOB_FOREGROUND), job_is_completed(j),
job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED));
}
}
#endif
@ -944,7 +944,7 @@ void job_continue(job_t *j, bool cont) {
// and it is not a short circuited builtin.
if ((WIFEXITED(p->status) || WIFSIGNALED(p->status)) && p->pid) {
int status = proc_format_status(p->status);
// wprintf(L"setting status %d for %ls\n", job_get_flag( j, JOB_NEGATE
// fwprintf(stdout, L"setting status %d for %ls\n", job_get_flag( j, JOB_NEGATE
// )?!status:status, j->command);
proc_set_last_status(job_get_flag(j, JOB_NEGATE) ? !status : status);
}

View file

@ -661,7 +661,7 @@ static bool test_stuff(screen_t *scr)
int c = getchar();
if (c != EOF) break;
}
wprintf(L"Bye\n");
fwprintf(stdout, L"Bye\n");
exit(0);
while (1) sleep(10000);
return true;

View file

@ -489,7 +489,7 @@ void tokenizer_t::tok_next() {
}
if (!this->has_next) {
// wprintf( L"EOL\n" );
// fwprintf(stdout, L"EOL\n" );
this->last_type = TOK_END;
return;
}
@ -666,7 +666,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
s_end
};
// wprintf(L"state %d, consume '%lc'\n", state, c);
// fwprintf(stdout, L"state %d, consume '%lc'\n", state, c);
bool consumed = false;
while (state != s_end && !consumed) {
switch (state) {