mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
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:
parent
509ce38375
commit
2e9a349dd0
11 changed files with 42 additions and 38 deletions
|
@ -25,7 +25,7 @@
|
||||||
static const int kAutoloadStalenessInterval = 15;
|
static const int kAutoloadStalenessInterval = 15;
|
||||||
|
|
||||||
file_access_attempt_t access_file(const wcstring &path, int mode) {
|
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 = {};
|
file_access_attempt_t result = {};
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if (wstat(path, &statbuf)) {
|
if (wstat(path, &statbuf)) {
|
||||||
|
|
|
@ -608,7 +608,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
|
||||||
param7, param8, param9, param10, param11, param12};
|
param7, param8, param9, param10, param11, param12};
|
||||||
if (!msg) return;
|
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;
|
if (level > debug_level) return;
|
||||||
int errno_old = errno;
|
int errno_old = errno;
|
||||||
|
|
||||||
|
@ -1691,7 +1691,7 @@ bool is_forked_child(void) {
|
||||||
|
|
||||||
bool is_child_of_fork = (getpid() != initial_pid);
|
bool is_child_of_fork = (getpid() != initial_pid);
|
||||||
if (is_child_of_fork) {
|
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);
|
while (1) sleep(10000);
|
||||||
}
|
}
|
||||||
return is_child_of_fork;
|
return is_child_of_fork;
|
||||||
|
|
|
@ -162,11 +162,11 @@ wcstring event_get_desc(const event_t &e) {
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void show_all_handlers(void) {
|
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) {
|
for (event_list_t::const_iterator iter = events.begin(); iter != events.end(); ++iter) {
|
||||||
const event_t *foo = *iter;
|
const event_t *foo = *iter;
|
||||||
wcstring tmp = event_get_desc(foo);
|
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
|
#endif
|
||||||
|
|
|
@ -763,7 +763,7 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
stop_pos++;
|
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;
|
var_len = stop_pos - start_pos;
|
||||||
|
|
||||||
if (var_len == 0) {
|
if (var_len == 0) {
|
||||||
|
|
|
@ -183,7 +183,7 @@ static void output_info_about_char(wchar_t wc) {
|
||||||
static bool output_matching_key_name(wchar_t wc) {
|
static bool output_matching_key_name(wchar_t wc) {
|
||||||
char *name = sequence_name(wc);
|
char *name = sequence_name(wc);
|
||||||
if (name) {
|
if (name) {
|
||||||
wprintf(L"bind -k %s 'do something'\n", name);
|
fwprintf(stdout, L"bind -k %s 'do something'\n", name);
|
||||||
free(name);
|
free(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,9 @@ static int err_count = 0;
|
||||||
static void say(const wchar_t *fmt, ...) {
|
static void say(const wchar_t *fmt, ...) {
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
vwprintf(fmt, va);
|
vfwprintf(stdout, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
wprintf(L"\n");
|
fwprintf(stdout, L"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print formatted error string.
|
/// Print formatted error string.
|
||||||
|
@ -118,8 +118,8 @@ static void err(const wchar_t *blah, ...) {
|
||||||
if (colorize) {
|
if (colorize) {
|
||||||
fputws(L"\e[31m", stdout);
|
fputws(L"\e[31m", stdout);
|
||||||
}
|
}
|
||||||
wprintf(L"Error: ");
|
fwprintf(stdout, L"Error: ");
|
||||||
vwprintf(blah, va);
|
vfwprintf(stdout, blah, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
// Return to normal color.
|
// Return to normal color.
|
||||||
|
@ -127,7 +127,7 @@ static void err(const wchar_t *blah, ...) {
|
||||||
fputws(L"\e[0m", stdout);
|
fputws(L"\e[0m", stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
wprintf(L"\n");
|
fwprintf(stdout, L"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Joins a wcstring_list_t via commas.
|
/// Joins a wcstring_list_t via commas.
|
||||||
|
@ -451,8 +451,8 @@ static void test_tokenizer() {
|
||||||
}
|
}
|
||||||
if (types[i] != token.type) {
|
if (types[i] != token.type) {
|
||||||
err(L"Tokenization error:");
|
err(L"Tokenization error:");
|
||||||
wprintf(L"Token number %zu of string \n'%ls'\n, got token type %ld\n", i + 1, str,
|
fwprintf(stdout, L"Token number %zu of string \n'%ls'\n, got token type %ld\n",
|
||||||
(long)token.type);
|
i + 1, str, (long)token.type);
|
||||||
}
|
}
|
||||||
i++;
|
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);
|
size_t char_idx = (motion == word_motion_left ? idx - 1 : idx);
|
||||||
wchar_t wc = command.at(char_idx);
|
wchar_t wc = command.at(char_idx);
|
||||||
bool will_stop = !sm.consume_char(wc);
|
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);
|
bool expected_stop = (stops.count(idx) > 0);
|
||||||
if (will_stop != expected_stop) {
|
if (will_stop != expected_stop) {
|
||||||
wcstring tmp = command;
|
wcstring tmp = command;
|
||||||
|
@ -2211,14 +2212,14 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command,
|
||||||
bool expects_error = (expected == L"<error>");
|
bool expects_error = (expected == L"<error>");
|
||||||
|
|
||||||
if (comps.empty() && !expects_error) {
|
if (comps.empty() && !expects_error) {
|
||||||
printf("line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
|
fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
|
||||||
command.c_str());
|
command.c_str());
|
||||||
do_test(!comps.empty());
|
do_test(!comps.empty());
|
||||||
return;
|
return;
|
||||||
} else if (!comps.empty() && expects_error) {
|
} else if (!comps.empty() && expects_error) {
|
||||||
printf(
|
fwprintf(stderr,
|
||||||
"line %ld: autosuggest_suggest_special() was expected to fail but did not, for command "
|
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
|
||||||
"%ls\n",
|
L"for command %ls\n",
|
||||||
line, command.c_str());
|
line, command.c_str());
|
||||||
do_test(comps.empty());
|
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);
|
const completion_t &suggestion = comps.at(0);
|
||||||
|
|
||||||
if (suggestion.completion != expected) {
|
if (suggestion.completion != expected) {
|
||||||
printf(
|
fwprintf(
|
||||||
"line %ld: complete() for cd returned the wrong expected string for command %ls\n",
|
stderr,
|
||||||
|
L"line %ld: complete() for cd returned the wrong expected string for command %ls\n",
|
||||||
line, command.c_str());
|
line, command.c_str());
|
||||||
printf(" actual: %ls\n", suggestion.completion.c_str());
|
fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
|
||||||
printf("expected: %ls\n", expected.c_str());
|
fwprintf(stderr, L"expected: %ls\n", expected.c_str());
|
||||||
do_test(suggestion.completion == expected);
|
do_test(suggestion.completion == expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2347,8 +2349,9 @@ static void perform_one_autosuggestion_should_ignore_test(const wcstring &comman
|
||||||
do_test(comps.empty());
|
do_test(comps.empty());
|
||||||
if (!comps.empty()) {
|
if (!comps.empty()) {
|
||||||
const wcstring &suggestion = comps.front().completion;
|
const wcstring &suggestion = comps.front().completion;
|
||||||
printf("line %ld: complete() expected to return nothing for %ls\n", line, command.c_str());
|
fwprintf(stderr, L"line %ld: complete() expected to return nothing for %ls\n", line,
|
||||||
printf(" instead got: %ls\n", suggestion.c_str());
|
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)
|
if (stop >= end)
|
||||||
break;
|
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();
|
hist->clear();
|
||||||
delete hist;
|
delete hist;
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,8 @@ void iothread_drain_all(void) {
|
||||||
}
|
}
|
||||||
#if TIME_DRAIN
|
#if TIME_DRAIN
|
||||||
double after = timef();
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -537,7 +537,7 @@ rgb_color_t parse_color(const wcstring &val, bool is_background) {
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
wcstring desc = result.description();
|
wcstring desc = result.description();
|
||||||
wprintf(L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
|
fwprintf(stdout, L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
|
||||||
is_background ? "background" : "foreground");
|
is_background ? "background" : "foreground");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ void print_jobs(void)
|
||||||
job_iterator_t jobs;
|
job_iterator_t jobs;
|
||||||
job_t *j;
|
job_t *j;
|
||||||
while (j = jobs.next()) {
|
while (j = jobs.next()) {
|
||||||
wprintf("%p -> %ls -> (foreground %d, complete %d, stopped %d, constructed %d)\n",
|
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),
|
j, j->command_wcstr(), job_get_flag(j, JOB_FOREGROUND), job_is_completed(j),
|
||||||
job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED));
|
job_is_stopped(j), job_get_flag(j, JOB_CONSTRUCTED));
|
||||||
}
|
}
|
||||||
|
@ -944,7 +944,7 @@ void job_continue(job_t *j, bool cont) {
|
||||||
// and it is not a short circuited builtin.
|
// and it is not a short circuited builtin.
|
||||||
if ((WIFEXITED(p->status) || WIFSIGNALED(p->status)) && p->pid) {
|
if ((WIFEXITED(p->status) || WIFSIGNALED(p->status)) && p->pid) {
|
||||||
int status = proc_format_status(p->status);
|
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);
|
// )?!status:status, j->command);
|
||||||
proc_set_last_status(job_get_flag(j, JOB_NEGATE) ? !status : status);
|
proc_set_last_status(job_get_flag(j, JOB_NEGATE) ? !status : status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,7 +661,7 @@ static bool test_stuff(screen_t *scr)
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
if (c != EOF) break;
|
if (c != EOF) break;
|
||||||
}
|
}
|
||||||
wprintf(L"Bye\n");
|
fwprintf(stdout, L"Bye\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
while (1) sleep(10000);
|
while (1) sleep(10000);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -489,7 +489,7 @@ void tokenizer_t::tok_next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->has_next) {
|
if (!this->has_next) {
|
||||||
// wprintf( L"EOL\n" );
|
// fwprintf(stdout, L"EOL\n" );
|
||||||
this->last_type = TOK_END;
|
this->last_type = TOK_END;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
|
||||||
s_end
|
s_end
|
||||||
};
|
};
|
||||||
|
|
||||||
// wprintf(L"state %d, consume '%lc'\n", state, c);
|
// fwprintf(stdout, L"state %d, consume '%lc'\n", state, c);
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
while (state != s_end && !consumed) {
|
while (state != s_end && !consumed) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
Loading…
Reference in a new issue