This commit changes wchar.h includes to cwchar, and uses std::

for everything it provides.
This commit is contained in:
Aaron Gyes 2019-03-12 14:06:01 -07:00
parent ecfe4acd0c
commit d5ac239f68
72 changed files with 379 additions and 379 deletions

View file

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

View file

@ -21,7 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -76,11 +76,11 @@
#include "wutil.h" // IWYU pragma: keep
bool builtin_data_t::operator<(const wcstring &other) const {
return wcscmp(this->name, other.c_str()) < 0;
return std::wcscmp(this->name, other.c_str()) < 0;
}
bool builtin_data_t::operator<(const builtin_data_t *other) const {
return wcscmp(this->name, other->name) < 0;
return std::wcscmp(this->name, other->name) < 0;
}
/// Counts the number of arguments in the specified null-terminated array
@ -215,7 +215,7 @@ void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t *
// First move down 4 lines.
pos = str;
for (i = 0; (i < 4) && pos && *pos; i++) {
pos = wcschr(pos + 1, L'\n');
pos = std::wcschr(pos + 1, L'\n');
}
if (pos && *pos) {
@ -311,7 +311,7 @@ static int builtin_count(parser_t &parser, io_streams_t &streams, wchar_t **argv
/// This function handles both the 'continue' and the 'break' builtins that are used for loop
/// control.
static int builtin_break_continue(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int is_break = (wcscmp(argv[0], L"break") == 0);
int is_break = (std::wcscmp(argv[0], L"break") == 0);
int argc = builtin_count_args(argv);
if (argc != 1) {
@ -482,7 +482,7 @@ void builtin_init() {
for (size_t i = 0; i < BUILTIN_COUNT; i++) {
const wchar_t *name = builtin_datas[i].name;
intern_static(name);
assert((i == 0 || wcscmp(builtin_datas[i - 1].name, name) < 0) &&
assert((i == 0 || std::wcscmp(builtin_datas[i - 1].name, name) < 0) &&
"builtins are not sorted alphabetically");
}
}

View file

@ -6,7 +6,7 @@
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -316,7 +316,7 @@ static int collect_option_specs(argparse_cmd_opts_t &opts, int *optind, int argc
wchar_t *cmd = argv[0];
while (true) {
if (wcscmp(L"--", argv[*optind]) == 0) {
if (std::wcscmp(L"--", argv[*optind]) == 0) {
++*optind;
break;
}
@ -401,7 +401,7 @@ static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(hig
if (opts.print_help) return STATUS_CMD_OK;
if (argc == w.woptind || wcscmp(L"--", argv[w.woptind - 1]) == 0) {
if (argc == w.woptind || std::wcscmp(L"--", argv[w.woptind - 1]) == 0) {
// The user didn't specify any option specs.
streams.err.append_format(_(L"%ls: No option specs were provided\n"), cmd);
return STATUS_INVALID_ARGS;

View file

@ -4,7 +4,7 @@
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
#include <cwchar>
#include "builtin.h"
#include "common.h"
@ -86,7 +86,7 @@ static void replace_part(const wchar_t *begin, const wchar_t *end, const wchar_t
switch (append_mode) {
case REPLACE_MODE: {
out.append(insert);
out_pos = wcslen(insert) + (begin - buff);
out_pos = std::wcslen(insert) + (begin - buff);
break;
}
case APPEND_MODE: {
@ -99,7 +99,7 @@ static void replace_part(const wchar_t *begin, const wchar_t *end, const wchar_t
out.append(begin, cursor);
out.append(insert);
out.append(begin + cursor, end - begin - cursor);
out_pos += wcslen(insert);
out_pos += std::wcslen(insert);
break;
}
default: {
@ -125,7 +125,7 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs
size_t pos = cursor_pos - (begin - buffer);
if (tokenize) {
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
// std::fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
wcstring out;
wcstring buff(begin, end - begin);
tokenizer_t tok(buff.c_str(), TOK_ACCEPT_UNFINISHED);
@ -267,7 +267,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
}
case 'I': {
current_buffer = w.woptarg;
current_cursor_pos = wcslen(w.woptarg);
current_cursor_pos = std::wcslen(w.woptarg);
break;
}
case 'C': {
@ -424,7 +424,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
switch (buffer_part) {
case STRING_MODE: {
begin = current_buffer;
end = begin + wcslen(begin);
end = begin + std::wcslen(begin);
break;
}
case PROCESS_MODE: {

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_COMMANDLINE_H
#define FISH_BUILTIN_COMMANDLINE_H
#include <wchar.h>
#include <cwchar>
#include <cstring>
class parser_t;

View file

@ -2,7 +2,7 @@
#include "config.h" // IWYU pragma: keep
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -49,7 +49,7 @@ static void builtin_complete_add2(const wchar_t *cmd, int cmd_type, const wchar_
comp, desc, flags);
}
if (old_opt.empty() && gnu_opt.empty() && wcslen(short_opt) == 0) {
if (old_opt.empty() && gnu_opt.empty() && std::wcslen(short_opt) == 0) {
complete_add(cmd, cmd_type, wcstring(), option_type_args_only, result_mode, condition, comp,
desc, flags);
}
@ -274,7 +274,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
return STATUS_INVALID_ARGS;
}
if (condition && wcslen(condition)) {
if (condition && std::wcslen(condition)) {
const wcstring condition_string = condition;
parse_error_list_t errors;
if (parse_util_detect_errors(condition_string, &errors,
@ -289,7 +289,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
}
if (comp && wcslen(comp)) {
if (comp && std::wcslen(comp)) {
wcstring prefix;
prefix.append(cmd);
prefix.append(L": ");

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_COMPLETE_H
#define FISH_BUILTIN_COMPLETE_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -2,7 +2,7 @@
#include "config.h" // IWYU pragma: keep
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include "builtin.h"
#include "builtin_contains.h"
@ -75,7 +75,7 @@ int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.err.append_format(_(L"%ls: Key not specified\n"), cmd);
} else {
for (int i = optind + 1; i < argc; i++) {
if (!wcscmp(needle, argv[i])) {
if (!std::wcscmp(needle, argv[i])) {
if (opts.print_index) streams.out.append_format(L"%d\n", i - optind);
return STATUS_CMD_OK;
}

View file

@ -4,7 +4,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <cwchar>
#include "builtin.h"
#include "builtin_fg.h"
@ -99,7 +99,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
} else {
// If we aren't redirecting, send output to real stderr, since stuff in sb_err won't get
// printed until the command finishes.
fwprintf(stderr, FG_MSG, j->job_id, j->command_wcstr());
std::fwprintf(stderr, FG_MSG, j->job_id, j->command_wcstr());
}
const wcstring ft = tok_first(j->command());

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <map>
@ -247,7 +247,7 @@ static int report_function_metadata(const wchar_t *funcname, bool verbose, io_st
}
if (metadata_as_comments) {
if (wcscmp(path, L"stdin")) {
if (std::wcscmp(path, L"stdin")) {
streams.out.append_format(L"# Defined in %ls @ line %d\n", path, line_number);
}
} else {

View file

@ -4,7 +4,7 @@
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <wchar.h>
#include <cwchar>
#include <string>
#include <vector>
@ -67,7 +67,7 @@ static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t su
wchar_t err_text[1024];
const wchar_t *subcmd_str1 = enum_to_str(*hist_cmd, hist_enum_map);
const wchar_t *subcmd_str2 = enum_to_str(sub_cmd, hist_enum_map);
swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
std::swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, err_text);

View file

@ -40,7 +40,7 @@ static int cpu_use(const job_t *j) {
double t1 = 1000000.0 * p->last_time.tv_sec + p->last_time.tv_usec;
double t2 = 1000000.0 * t.tv_sec + t.tv_usec;
// fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n", t1, t2, jiffies, p->last_jiffies );
// std::fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n", t1, t2, jiffies, p->last_jiffies );
u += ((double)(jiffies - p->last_jiffies)) / (t2 - t1);
}
return u * 1000000;

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_JOBS_H
#define FISH_BUILTIN_JOBS_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -49,7 +49,7 @@ static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
switch (opt) {
case 's': {
// "max" is the special value that tells us to pick the maximum scale.
if (wcscmp(w.woptarg, L"max") == 0) {
if (std::wcscmp(w.woptarg, L"max") == 0) {
opts.scale = 15;
} else {
opts.scale = fish_wcstoi(w.woptarg);
@ -162,7 +162,7 @@ static wcstring format_double(double v, const math_cmd_opts_t &opts) {
while (ret.back() == L'0') {
ret.pop_back();
}
if (!wcschr(digits, ret.back())) {
if (!std::wcschr(digits, ret.back())) {
ret.pop_back();
}
}

View file

@ -59,7 +59,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include "builtin.h"
@ -255,17 +255,17 @@ static T raw_string_to_scalar_type(const wchar_t *s, wchar_t **end);
// #626
template <>
intmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
return wcstoll(s, end, 0);
return std::wcstoll(s, end, 0);
}
template <>
uintmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
return wcstoull(s, end, 0);
return std::wcstoull(s, end, 0);
}
template <>
long double raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
double val = wcstod(s, end);
double val = std::wcstod(s, end);
if (**end == L'\0') return val;
// The conversion using the user's locale failed. That may be due to the string not being a
// valid floating point value. It could also be due to the locale using different separator
@ -358,7 +358,7 @@ long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0) {
++esc_length, ++p)
esc_value = esc_value * 8 + octal_to_bin(*p);
this->append_output(ENCODE_DIRECT_BASE + esc_value % 256);
} else if (*p && wcschr(L"\"\\abcefnrtv", *p)) {
} else if (*p && std::wcschr(L"\"\\abcefnrtv", *p)) {
print_esc_char(*p++);
} else if (*p == L'u' || *p == L'U') {
wchar_t esc_char = *p;

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_PRINTF_H
#define FISH_BUILTIN_PRINTF_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -3,7 +3,7 @@
#include <errno.h>
#include <stdint.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <random>
@ -45,7 +45,7 @@ int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
long long start, end;
unsigned long long step;
bool choice = false;
if (arg_count >= 1 && !wcscmp(argv[optind], L"choice")) {
if (arg_count >= 1 && !std::wcscmp(argv[optind], L"choice")) {
if (arg_count == 1) {
streams.err.append_format(L"%ls: nothing to choose from\n", cmd);
return STATUS_INVALID_ARGS;

View file

@ -8,7 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -222,7 +222,7 @@ static int read_interactive(wcstring &buff, int nchars, bool shell, bool silent,
reader_set_exit_on_interrupt(true);
reader_set_silent_status(silent);
reader_set_buffer(commandline, wcslen(commandline));
reader_set_buffer(commandline, std::wcslen(commandline));
proc_push_interactive(1);
event_fire_generic(L"fish_prompt");
@ -317,7 +317,7 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli
res = (unsigned char)b;
finished = true;
} else {
size_t sz = mbrtowc(&res, &b, 1, &state);
size_t sz = std::mbrtowc(&res, &b, 1, &state);
if (sz == (size_t)-1) {
memset(&state, 0, sizeof(state));
} else if (sz != (size_t)-2) {

View file

@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <cwchar>
#include "builtin.h"
#include "builtin_realpath.h"

View file

@ -7,7 +7,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <iterator>
@ -275,7 +275,7 @@ static bool validate_path_warning_on_colons(const wchar_t *cmd,
continue;
}
const wchar_t *colon = wcschr(dir.c_str(), L':');
const wchar_t *colon = std::wcschr(dir.c_str(), L':');
bool looks_like_colon_sep = colon && colon[1];
if (!looks_like_colon_sep && any_success) {
// Once we have one valid entry, skip the remaining ones unless we might warn.
@ -297,7 +297,7 @@ static bool validate_path_warning_on_colons(const wchar_t *cmd,
streams.err.append_format(BUILTIN_SET_PATH_ERROR, cmd, key, dir.c_str(),
strerror(errno));
streams.err.append_format(BUILTIN_SET_PATH_HINT, cmd, key, key,
wcschr(dir.c_str(), L':') + 1);
std::wcschr(dir.c_str(), L':') + 1);
}
}
return any_success;
@ -365,7 +365,7 @@ static int env_set_reporting_errors(const wchar_t *cmd, const wchar_t *key, int
/// is modified to omit the index expression leaving just the var name.
static int parse_index(std::vector<long> &indexes, wchar_t *src, int scope, io_streams_t &streams,
const environment_t &vars) {
wchar_t *p = wcschr(src, L'[');
wchar_t *p = std::wcschr(src, L'[');
if (!p) return 0; // no slices so nothing for us to do
*p = L'\0'; // split the var name from the indexes/slices
p++;
@ -609,7 +609,7 @@ static int builtin_set_show(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
continue;
}
if (wcschr(arg, L'[')) {
if (std::wcschr(arg, L'[')) {
streams.err.append_format(
_(L"%ls: `set --show` does not allow slices with the var names\n"), cmd);
builtin_print_help(parser, streams, cmd, streams.err);

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_SET_H
#define FISH_BUILTIN_SET_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_SET_COLOR_H
#define FISH_BUILTIN_SET_COLOR_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -4,7 +4,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include "builtin.h"
#include "builtin_source.h"
@ -39,7 +39,7 @@ int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
struct stat buf;
const wchar_t *fn, *fn_intern;
if (argc == optind || wcscmp(argv[optind], L"-") == 0) {
if (argc == optind || std::wcscmp(argv[optind], L"-") == 0) {
// Either a bare `source` which means to implicitly read from stdin or an explicit `-`.
if (argc == optind && isatty(streams.stdin_fd)) {
// Don't implicitly read from the terminal.

View file

@ -2,7 +2,7 @@
#include "config.h" // IWYU pragma: keep
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <string>
@ -77,11 +77,11 @@ const enum_map<status_cmd_t> status_enum_map[] = {
enum { TEST_FEATURE_ON, TEST_FEATURE_OFF, TEST_FEATURE_NOT_RECOGNIZED };
int job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd, io_streams_t &streams) {
if (wcscmp(mode, L"full") == 0) {
if (std::wcscmp(mode, L"full") == 0) {
return JOB_CONTROL_ALL;
} else if (wcscmp(mode, L"interactive") == 0) {
} else if (std::wcscmp(mode, L"interactive") == 0) {
return JOB_CONTROL_INTERACTIVE;
} else if (wcscmp(mode, L"none") == 0) {
} else if (std::wcscmp(mode, L"none") == 0) {
return JOB_CONTROL_NONE;
}
streams.err.append_format(L"%ls: Invalid job control mode '%ls'\n", cmd, mode);
@ -127,7 +127,7 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_c
wchar_t err_text[1024];
const wchar_t *subcmd_str1 = enum_to_str(opts.status_cmd, status_enum_map);
const wchar_t *subcmd_str2 = enum_to_str(sub_cmd, status_enum_map);
swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
std::swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, err_text);

View file

@ -11,7 +11,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -189,13 +189,13 @@ static int handle_flag_1(wchar_t **argv, parser_t &parser, io_streams_t &streams
const wchar_t *cmd = argv[0];
if (opts->style_valid) {
if (wcscmp(w.woptarg, L"script") == 0) {
if (std::wcscmp(w.woptarg, L"script") == 0) {
opts->escape_style = STRING_STYLE_SCRIPT;
} else if (wcscmp(w.woptarg, L"url") == 0) {
} else if (std::wcscmp(w.woptarg, L"url") == 0) {
opts->escape_style = STRING_STYLE_URL;
} else if (wcscmp(w.woptarg, L"var") == 0) {
} else if (std::wcscmp(w.woptarg, L"var") == 0) {
opts->escape_style = STRING_STYLE_VAR;
} else if (wcscmp(w.woptarg, L"regex") == 0) {
} else if (std::wcscmp(w.woptarg, L"regex") == 0) {
opts->escape_style = STRING_STYLE_REGEX;
} else {
string_error(streams, _(L"%ls: Invalid escape style '%ls'\n"), cmd, w.woptarg);
@ -949,7 +949,7 @@ bool literal_replacer_t::replace_matches(const wcstring &arg) {
replacement_occurred = true;
result = arg;
} else {
auto &cmp_func = opts.ignore_case ? wcsncasecmp : wcsncmp;
auto &cmp_func = opts.ignore_case ? wcsncasecmp : std::wcsncmp;
const wchar_t *cur = arg.c_str();
const wchar_t *end = cur + arg.size();
while (cur < end) {
@ -1311,13 +1311,13 @@ int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
return STATUS_INVALID_ARGS;
}
if (wcscmp(argv[1], L"-h") == 0 || wcscmp(argv[1], L"--help") == 0) {
if (std::wcscmp(argv[1], L"-h") == 0 || std::wcscmp(argv[1], L"--help") == 0) {
builtin_print_help(parser, streams, L"string", streams.out);
return STATUS_CMD_OK;
}
const string_subcommand *subcmd = &string_subcommands[0];
while (subcmd->name != 0 && wcscmp(subcmd->name, argv[1]) != 0) {
while (subcmd->name != 0 && std::wcscmp(subcmd->name, argv[1]) != 0) {
subcmd++;
}
if (!subcmd->handler) {

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_STRING_H
#define FISH_BUILTIN_STRING_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -9,7 +9,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <cmath>
@ -817,7 +817,7 @@ int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Whether we are invoked with bracket '[' or not.
wchar_t *program_name = argv[0];
const bool is_bracket = !wcscmp(program_name, L"[");
const bool is_bracket = !std::wcscmp(program_name, L"[");
size_t argc = 0;
while (argv[argc + 1]) argc++;
@ -825,7 +825,7 @@ int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// If we're bracket, the last argument ought to be ]; we ignore it. Note that argc is the number
// of arguments after the command name; thus argv[argc] is the last argument.
if (is_bracket) {
if (!wcscmp(argv[argc], L"]")) {
if (!std::wcscmp(argv[argc], L"]")) {
// Ignore the closing bracket from now on.
argc--;
} else {

View file

@ -2,7 +2,7 @@
#ifndef FISH_BUILTIN_ULIMIT_H
#define FISH_BUILTIN_ULIMIT_H
#include <wchar.h>
#include <cwchar>
#include <cstring>

View file

@ -134,11 +134,11 @@ static bool iswnumeric(const wchar_t *n) {
/// See if the process described by \c proc matches the commandline \c cmd.
static bool match_pid(const wcstring &cmd, const wchar_t *proc) {
// Don't wait for itself
if (wcscmp(proc, L"wait") == 0) return false;
if (std::wcscmp(proc, L"wait") == 0) return false;
// Get the command to match against. We're only interested in the last path component.
const wcstring base_cmd = wbasename(cmd);
return wcscmp(proc, base_cmd.c_str()) == 0;
return std::wcscmp(proc, base_cmd.c_str()) == 0;
}
/// It should search the job list for something matching the given proc.

View file

@ -4,7 +4,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h> // IWYU pragma: keep
#include <cwchar> // IWYU pragma: keep
#include "color.h"
#include "common.h"

View file

@ -19,7 +19,7 @@
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
@ -231,7 +231,7 @@ demangled_backtrace(int max_frames, int skip_levels) {
// if this check is not done.
//
// Hack to avoid showing backtraces in the tester.
// if (program_name && !wcscmp(program_name, L"(ignore)")) return;
// if (program_name && !std::wcscmp(program_name, L"(ignore)")) return;
debug_shared(msg_level, L"Backtrace:");
std::vector<wcstring> bt = demangled_backtrace(frame_count, skip_levels + 2);
@ -254,7 +254,7 @@ int fgetws2(wcstring *s, FILE *f) {
while (1) {
errno = 0;
c = fgetwc(f);
c = std::fgetwc(f);
if (errno == EILSEQ || errno == EINTR) {
continue;
}
@ -309,17 +309,17 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
wchar_t wc = 0;
if ((in[in_pos] & 0xF8) == 0xF8) {
// Protect against broken mbrtowc() implementations which attempt to encode UTF-8
// Protect against broken std::mbrtowc() implementations which attempt to encode UTF-8
// sequences longer than four bytes (e.g., OS X Snow Leopard).
use_encode_direct = true;
} else if (sizeof(wchar_t) == 2 && //!OCLINT(constant if expression)
(in[in_pos] & 0xF8) == 0xF0) {
// Assume we are in a UTF-16 environment (e.g., Cygwin) using a UTF-8 encoding.
// The bits set check will be true for a four byte UTF-8 sequence that requires
// two UTF-16 chars. Something that doesn't work with our simple use of mbrtowc().
// two UTF-16 chars. Something that doesn't work with our simple use of std::mbrtowc().
use_encode_direct = true;
} else {
ret = mbrtowc(&wc, &in[in_pos], in_len - in_pos, &state);
ret = std::mbrtowc(&wc, &in[in_pos], in_len - in_pos, &state);
// Determine whether to encode this character with our crazy scheme.
if (wc >= ENCODE_DIRECT_BASE && wc < ENCODE_DIRECT_BASE + 256) {
use_encode_direct = true;
@ -398,7 +398,7 @@ char *wcs2str(const wchar_t *in, size_t len) {
return out;
}
char *wcs2str(const wchar_t *in) { return wcs2str(in, wcslen(in)); }
char *wcs2str(const wchar_t *in) { return wcs2str(in, std::wcslen(in)); }
char *wcs2str(const wcstring &in) { return wcs2str(in.c_str(), in.length()); }
/// This function is distinguished from wcs2str_internal in that it allows embedded null bytes.
@ -424,7 +424,7 @@ std::string wcs2string(const wcstring &input) {
result.append(converted, 1);
} else {
memset(converted, 0, sizeof converted);
size_t len = wcrtomb(converted, wc, &state);
size_t len = std::wcrtomb(converted, wc, &state);
if (len == (size_t)-1) {
debug(1, L"Wide character U+%4X has no narrow representation", wc);
memset(&state, 0, sizeof(state));
@ -464,7 +464,7 @@ static char *wcs2str_internal(const wchar_t *in, char *out) {
out[out_pos++] = (unsigned char)in[in_pos];
}
} else {
size_t len = wcrtomb(&out[out_pos], in[in_pos], &state);
size_t len = std::wcrtomb(&out[out_pos], in[in_pos], &state);
if (len == (size_t)-1) {
debug(1, L"Wide character U+%4X has no narrow representation", in[in_pos]);
memset(&state, 0, sizeof(state));
@ -484,7 +484,7 @@ static bool can_be_encoded(wchar_t wc) {
char converted[MB_LEN_MAX];
mbstate_t state = {};
return wcrtomb(converted, wc, &state) != (size_t)-1;
return std::wcrtomb(converted, wc, &state) != (size_t)-1;
}
wcstring format_string(const wchar_t *format, ...) {
@ -528,7 +528,7 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) {
// Try printing.
va_list va;
va_copy(va, va_orig);
status = vswprintf(buff, size / sizeof(wchar_t), format, va);
status = std::vswprintf(buff, size / sizeof(wchar_t), format, va);
va_end(va);
}
@ -647,16 +647,16 @@ ssize_t read_loop(int fd, void *buff, size_t count) {
/// like `debug()`. It is only intended to supress diagnostic noise from testing things like the
/// fish parser where we expect a lot of diagnostic messages due to testing error conditions.
bool should_suppress_stderr_for_tests() {
return program_name && !wcscmp(program_name, TESTS_PROGRAM_NAME);
return program_name && !std::wcscmp(program_name, TESTS_PROGRAM_NAME);
}
static void debug_shared(const wchar_t level, const wcstring &msg) {
pid_t current_pid;
if (!is_forked_child()) {
fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str());
std::fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str());
} else {
current_pid = getpid();
fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid,
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid,
msg.c_str());
}
}
@ -810,7 +810,7 @@ wcstring reformat_for_screen(const wcstring &msg) {
int tok_width = 0;
// Tokenize on whitespace, and also calculate the width of the token.
while (*pos && (!wcschr(L" \n\r\t", *pos))) {
while (*pos && (!std::wcschr(L" \n\r\t", *pos))) {
// Check is token is wider than one line. If so we mark it as an overflow and break
// the token.
if ((tok_width + fish_wcwidth(*pos)) > (screen_width - 1)) {
@ -1178,7 +1178,7 @@ wcstring escape_string(const wchar_t *in, escape_flags_t flags, escape_string_st
switch (style) {
case STRING_STYLE_SCRIPT: {
escape_string_script(in, wcslen(in), result, flags);
escape_string_script(in, std::wcslen(in), result, flags);
break;
}
case STRING_STYLE_URL: {
@ -1493,10 +1493,10 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
// Note that this only recognizes %self if the string is literally %self.
// %self/foo will NOT match this.
if (unescape_special && input_position == 0 &&
!wcscmp(input, PROCESS_EXPAND_SELF_STR)) {
!std::wcscmp(input, PROCESS_EXPAND_SELF_STR)) {
to_append_or_none = PROCESS_EXPAND_SELF;
input_position +=
wcslen(PROCESS_EXPAND_SELF_STR) - 1; // skip over 'self' part.
std::wcslen(PROCESS_EXPAND_SELF_STR) - 1; // skip over 'self' part.
}
break;
}
@ -1691,7 +1691,7 @@ bool unescape_string(const wchar_t *input, wcstring *output, unescape_flags_t es
bool success = false;
switch (style) {
case STRING_STYLE_SCRIPT: {
success = unescape_string_internal(input, wcslen(input), output, escape_special);
success = unescape_string_internal(input, std::wcslen(input), output, escape_special);
break;
}
case STRING_STYLE_URL: {
@ -1884,7 +1884,7 @@ bool string_suffixes_string(const wcstring &proposed_suffix, const wcstring &val
}
bool string_suffixes_string(const wchar_t *proposed_suffix, const wcstring &value) {
size_t suffix_size = wcslen(proposed_suffix);
size_t suffix_size = std::wcslen(proposed_suffix);
return suffix_size <= value.size() &&
value.compare(value.size() - suffix_size, suffix_size, proposed_suffix) == 0;
}

View file

@ -272,7 +272,7 @@ inline bool is_whitespace(const wchar_t *input) { return is_whitespace(wcstring(
[[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error);
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g., fwprintf()).
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g., std::fwprintf()).
#define _(wstr) wgettext(wstr).c_str()
/// Noop, used to tell xgettext that a string should be translated. Use this when a string cannot be
@ -555,7 +555,7 @@ inline bool bool_from_string(const std::string &x) {
}
}
inline bool bool_from_string(const wcstring &x) { return !x.empty() && wcschr(L"YTyt1", x.at(0)); }
inline bool bool_from_string(const wcstring &x) { return !x.empty() && std::wcschr(L"YTyt1", x.at(0)); }
wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
char **make_null_terminated_array(const std::vector<std::string> &lst);
@ -933,7 +933,7 @@ static T str_to_enum(const wchar_t *name, const enum_map<T> map[], int len) {
while (left < right) {
size_t mid = left + (right - left) / 2;
int cmp = wcscmp(name, map[mid].str);
int cmp = std::wcscmp(name, map[mid].str);
if (cmp < 0) {
right = mid; // name was smaller than mid
} else if (cmp > 0) {

View file

@ -8,7 +8,7 @@
#include <pthread.h>
#include <pwd.h>
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -203,7 +203,7 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_
if (flags & COMPLETE_AUTO_SPACE) {
new_flags &= ~COMPLETE_AUTO_SPACE;
size_t len = comp.size();
if (len > 0 && (wcschr(L"/=@:", comp.at(len - 1)) != 0)) new_flags |= COMPLETE_NO_SPACE;
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0)) new_flags |= COMPLETE_NO_SPACE;
}
return new_flags;
}
@ -402,7 +402,7 @@ void append_completion(std::vector<completion_t> *completions, wcstring comp, wc
/// after a completion run to make sure that there are no stale completions.
bool completer_t::condition_test(const wcstring &condition) {
if (condition.empty()) {
// fwprintf( stderr, L"No condition specified\n" );
// std::fwprintf( stderr, L"No condition specified\n" );
return true;
}
@ -1238,10 +1238,10 @@ bool completer_t::try_complete_user(const wcstring &str) {
const wchar_t *cmd = str.c_str();
const wchar_t *first_char = cmd;
if (*first_char != L'~' || wcschr(first_char, L'/')) return false;
if (*first_char != L'~' || std::wcschr(first_char, L'/')) return false;
const wchar_t *user_name = first_char + 1;
const wchar_t *name_end = wcschr(user_name, L'~');
const wchar_t *name_end = std::wcschr(user_name, L'~');
if (name_end) return false;
double start_time = timef();
@ -1260,7 +1260,7 @@ bool completer_t::try_complete_user(const wcstring &str) {
}
const wcstring pw_name_str = str2wcstring(pw->pw_name);
const wchar_t *pw_name = pw_name_str.c_str();
if (wcsncmp(user_name, pw_name, name_len) == 0) {
if (std::wcsncmp(user_name, pw_name, name_len) == 0) {
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
// Append a user name
append_completion(&this->completions, &pw_name[name_len], desc, COMPLETE_NO_SPACE);

View file

@ -14,7 +14,7 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#if HAVE_CURSES_H
#include <curses.h>
@ -308,7 +308,7 @@ using string_set_t = const wchar_t *const[];
template <typename T>
bool string_set_contains(const T &set, const wchar_t *val) {
for (const wchar_t *entry : set) {
if (!wcscmp(val, entry)) return true;
if (!std::wcscmp(val, entry)) return true;
}
return false;
}
@ -319,7 +319,7 @@ static bool is_read_only(const wchar_t *val) {
L"PWD", L"SHLVL", L"history", L"pipestatus", L"status", L"version",
L"FISH_VERSION", L"fish_pid", L"hostname", L"_", L"fish_private_mode"};
return string_set_contains(env_read_only, val) ||
(in_private_mode() && wcscmp(L"fish_history", val) == 0);
(in_private_mode() && std::wcscmp(L"fish_history", val) == 0);
}
static bool is_read_only(const wcstring &val) { return is_read_only(val.c_str()); }
@ -443,15 +443,15 @@ static bool does_term_support_setting_title(const environment_t &vars) {
const wcstring term_str = term_var->as_string();
const wchar_t *term = term_str.c_str();
bool recognized = contains(title_terms, term_var->as_string());
if (!recognized) recognized = !wcsncmp(term, L"xterm-", wcslen(L"xterm-"));
if (!recognized) recognized = !wcsncmp(term, L"screen-", wcslen(L"screen-"));
if (!recognized) recognized = !wcsncmp(term, L"tmux-", wcslen(L"tmux-"));
if (!recognized) recognized = !std::wcsncmp(term, L"xterm-", std::wcslen(L"xterm-"));
if (!recognized) recognized = !std::wcsncmp(term, L"screen-", std::wcslen(L"screen-"));
if (!recognized) recognized = !std::wcsncmp(term, L"tmux-", std::wcslen(L"tmux-"));
if (!recognized) {
if (wcscmp(term, L"linux") == 0) return false;
if (wcscmp(term, L"dumb") == 0) return false;
if (std::wcscmp(term, L"linux") == 0) return false;
if (std::wcscmp(term, L"dumb") == 0) return false;
// NetBSD
if (wcscmp(term, L"vt100") == 0) return false;
if (wcscmp(term, L"wsvt25") == 0) return false;
if (std::wcscmp(term, L"vt100") == 0) return false;
if (std::wcscmp(term, L"wsvt25") == 0) return false;
char buf[PATH_MAX];
int retval = ttyname_r(STDIN_FILENO, buf, PATH_MAX);

View file

@ -28,7 +28,7 @@
#include <sys/time.h> // IWYU pragma: keep
#include <sys/types.h> // IWYU pragma: keep
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <atomic>
#include <map>
@ -136,7 +136,7 @@ static bool match(const wchar_t **inout_cursor, const char *cmd) {
static bool is_universal_safe_to_encode_directly(wchar_t c) {
if (c < 32 || c > 128) return false;
return iswalnum(c) || wcschr(L"/_", c);
return iswalnum(c) || std::wcschr(L"/_", c);
}
/// Escape specified string.
@ -850,7 +850,7 @@ static const wchar_t *skip_spaces(const wchar_t *str) {
bool env_universal_t::populate_1_variable(const wchar_t *input, env_var_t::env_var_flags_t flags,
var_table_t *vars, wcstring *storage) {
const wchar_t *str = skip_spaces(input);
const wchar_t *colon = wcschr(str, L':');
const wchar_t *colon = std::wcschr(str, L':');
if (!colon) return false;
// Parse out the value into storage, and decode it into a variable.

View file

@ -191,11 +191,11 @@ wcstring event_get_desc(const event_t &evt) {
#if 0
static void show_all_handlers(void) {
fwprintf(stdout, L"event handlers:\n");
std::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);
fwprintf(stdout, L" handler now %ls\n", tmp.c_str());
std::fwprintf(stdout, L" handler now %ls\n", tmp.c_str());
}
}
#endif

View file

@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#ifdef HAVE_SYS_SYSCTL_H
@ -74,7 +74,7 @@ static bool expand_is_clean(const wcstring &in) {
if (in.empty()) return true;
// Test characters that have a special meaning in the first character position.
if (wcschr(UNCLEAN_FIRST, in.at(0)) != NULL) return false;
if (std::wcschr(UNCLEAN_FIRST, in.at(0)) != NULL) return false;
// Test characters that have a special meaning in any character position.
return in.find_first_of(UNCLEAN) == wcstring::npos;
@ -572,7 +572,7 @@ static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags,
}
length_preceding_braces = (brace_begin - in);
length_following_braces = wcslen(brace_end) - 1;
length_following_braces = std::wcslen(brace_end) - 1;
tot_len = length_preceding_braces + length_following_braces;
item_begin = brace_begin + 1;
for (const wchar_t *pos = (brace_begin + 1); true; pos++) {
@ -1218,7 +1218,7 @@ maybe_t<wcstring> expand_abbreviation(const wcstring &src) {
std::map<wcstring, wcstring> get_abbreviations() {
// TODO: try to make this cheaper
const auto &vars = env_stack_t::principal();
const size_t fish_abbr_len = wcslen(L"_fish_abbr_");
const size_t fish_abbr_len = std::wcslen(L"_fish_abbr_");
auto names = vars.get_names(0);
std::map<wcstring, wcstring> result;
for (const wcstring &name : names) {

View file

@ -18,7 +18,7 @@
#include <sys/stat.h> // IWYU pragma: keep
#include <sys/types.h> // IWYU pragma: keep
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
#if HAVE_GETTEXT
@ -37,7 +37,7 @@
#include <ncurses/term.h>
#endif
#include <signal.h> // IWYU pragma: keep
#include <wchar.h> // IWYU pragma: keep
#include <cwchar> // IWYU pragma: keep
#include "common.h" // IWYU pragma: keep
#include "fallback.h" // IWYU pragma: keep
@ -75,7 +75,7 @@ int fish_mkstemp_cloexec(char *name_template) {
/// are not referenced in this file.
// cppcheck-suppress unusedFunction
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
size_t len = wcslen(in);
size_t len = std::wcslen(in);
wchar_t *out = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
if (out == 0) {
return 0;
@ -397,7 +397,7 @@ int flock(int fd, int op) {
// thread-specific locale.
double fish_compat::wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc) {
locale_t prev_locale = uselocale(loc);
double ret = wcstod(enptr, endptr);
double ret = std::wcstod(enptr, endptr);
uselocale(prev_locale);
return ret;
}

View file

@ -10,7 +10,7 @@
// between the weak linking of `wcsdup` and `wcscasecmp` via `#define`s below and the declarations
// in <wchar.h>. At least on OS X if we don't do this we get compilation errors do to the macro
// substitution if wchar.h is included after this header.
#include <wchar.h> // IWYU pragma: keep
#include <cwchar> // IWYU pragma: keep
/// The column width of ambiguous East Asian characters.
extern int g_fish_ambiguous_width;
@ -137,7 +137,7 @@ wchar_t *wcsndup(const wchar_t *in, size_t c);
#ifndef HAVE_WCSLCPY
/// Copy src to string dst of size siz. At most siz-1 characters will be copied. Always NUL
/// terminates (unless siz == 0). Returns wcslen(src); if retval >= siz, truncation occurred.
/// terminates (unless siz == 0). Returns std::wcslen(src); if retval >= siz, truncation occurred.
///
/// This is the OpenBSD strlcpy function, modified for wide characters, and renamed to reflect this
/// change.

View file

@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -250,7 +250,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
exit(1);
}
break;
@ -285,7 +285,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
break;
}
case 'v': {
fwprintf(stdout, _(L"%s, version %s\n"), PACKAGE_NAME, get_fish_version());
std::fwprintf(stdout, _(L"%s, version %s\n"), PACKAGE_NAME, get_fish_version());
exit(0);
break;
}
@ -299,7 +299,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
debug_stack_frames = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
exit(1);
}
break;

View file

@ -24,9 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <cwchar>
#include <memory>
#include <string>
#include <vector>
@ -55,7 +55,7 @@ static int ret = 0;
static wcstring read_file(FILE *f) {
wcstring result;
while (1) {
wint_t c = fgetwc(f);
wint_t c = std::fgetwc(f);
if (c == WEOF) {
if (ferror(f)) {
@ -157,7 +157,7 @@ static void dump_node(indent_t node_indent, const parse_node_t &node, const wcst
nextc_str[1] = L'c';
nextc_str[2] = nextc + '@';
}
fwprintf(stderr, L"{off %4u, len %4u, indent %2u, kw %ls, %ls} [%ls|%ls|%ls]\n",
std::fwprintf(stderr, L"{off %4u, len %4u, indent %2u, kw %ls, %ls} [%ls|%ls|%ls]\n",
node.source_start, node.source_length, node_indent, keyword_description(node.keyword),
token_type_description(node.type), prevc_str, source_txt.c_str(), nextc_str);
}
@ -252,7 +252,7 @@ static wcstring prettify(const wcstring &src, bool do_indent) {
if (dump_parse_tree) {
const wcstring dump = parse_dump_tree(parse_tree, src);
fwprintf(stderr, L"%ls\n", dump.c_str());
std::fwprintf(stderr, L"%ls\n", dump.c_str());
}
// We may have a forest of disconnected trees on a parse failure. We have to handle all nodes
@ -442,7 +442,7 @@ int main(int argc, char *argv[]) {
break;
}
case 'v': {
fwprintf(stderr, _(L"%ls, version %s\n"), program_name, get_fish_version());
std::fwprintf(stderr, _(L"%ls, version %s\n"), program_name, get_fish_version());
exit(0);
break;
}
@ -472,7 +472,7 @@ int main(int argc, char *argv[]) {
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
exit(1);
}
break;
@ -487,7 +487,7 @@ int main(int argc, char *argv[]) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
debug_stack_frames = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
exit(1);
}
break;
@ -506,7 +506,7 @@ int main(int argc, char *argv[]) {
wcstring src;
if (argc == 0) {
if (output_type == output_type_file) {
fwprintf(stderr, _(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
std::fwprintf(stderr, _(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
program_name);
exit(1);
}
@ -518,11 +518,11 @@ int main(int argc, char *argv[]) {
fclose(fh);
output_location = *argv;
} else {
fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, strerror(errno));
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, strerror(errno));
exit(1);
}
} else {
fwprintf(stderr, _(L"Too many arguments\n"));
std::fwprintf(stderr, _(L"Too many arguments\n"));
exit(1);
}
@ -544,11 +544,11 @@ int main(int argc, char *argv[]) {
case output_type_file: {
FILE *fh = fopen(output_location, "w");
if (fh) {
fputws(output_wtext.c_str(), fh);
std::fputws(output_wtext.c_str(), fh);
fclose(fh);
exit(0);
} else {
fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
strerror(errno));
exit(1);
}
@ -564,6 +564,6 @@ int main(int argc, char *argv[]) {
}
}
fputws(str2wcstring(colored_output).c_str(), stdout);
std::fputws(str2wcstring(colored_output).c_str(), stdout);
return ret;
}

View file

@ -17,7 +17,7 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -54,12 +54,12 @@ static bool should_exit(wchar_t wc) {
recent_chars[3] = c;
if (c == shell_modes.c_cc[VINTR]) {
if (recent_chars[2] == shell_modes.c_cc[VINTR]) return true;
fwprintf(stderr, L"Press [ctrl-%c] again to exit\n", shell_modes.c_cc[VINTR] + 0x40);
std::fwprintf(stderr, L"Press [ctrl-%c] again to exit\n", shell_modes.c_cc[VINTR] + 0x40);
return false;
}
if (c == shell_modes.c_cc[VEOF]) {
if (recent_chars[2] == shell_modes.c_cc[VEOF]) return true;
fwprintf(stderr, L"Press [ctrl-%c] again to exit\n", shell_modes.c_cc[VEOF] + 0x40);
std::fwprintf(stderr, L"Press [ctrl-%c] again to exit\n", shell_modes.c_cc[VEOF] + 0x40);
return false;
}
return memcmp(recent_chars, "exit", 4) == 0 || memcmp(recent_chars, "quit", 4) == 0;
@ -93,41 +93,41 @@ static char *sequence_name(wchar_t wc) {
/// Return true if the character must be escaped when used in the sequence of chars to be bound in
/// a `bind` command.
static bool must_escape(wchar_t wc) { return wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != NULL; }
static bool must_escape(wchar_t wc) { return std::wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != NULL; }
static void ctrl_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
if (ctrl_symbolic_names[wc]) {
if (bind_friendly) {
swprintf(buf, buf_len, L"%ls", ctrl_symbolic_names[wc]);
std::swprintf(buf, buf_len, L"%ls", ctrl_symbolic_names[wc]);
} else {
swprintf(buf, buf_len, L"\\c%c (or %ls)", wc + 0x40, ctrl_symbolic_names[wc]);
std::swprintf(buf, buf_len, L"\\c%c (or %ls)", wc + 0x40, ctrl_symbolic_names[wc]);
}
} else {
swprintf(buf, buf_len, L"\\c%c", wc + 0x40);
std::swprintf(buf, buf_len, L"\\c%c", wc + 0x40);
}
}
static void space_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
if (bind_friendly) {
swprintf(buf, buf_len, L"\\x%X", wc);
std::swprintf(buf, buf_len, L"\\x%X", wc);
} else {
swprintf(buf, buf_len, L"\\x%X (aka \"space\")", wc);
std::swprintf(buf, buf_len, L"\\x%X (aka \"space\")", wc);
}
}
static void del_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
if (bind_friendly) {
swprintf(buf, buf_len, L"\\x%X", wc);
std::swprintf(buf, buf_len, L"\\x%X", wc);
} else {
swprintf(buf, buf_len, L"\\x%X (aka \"del\")", wc);
std::swprintf(buf, buf_len, L"\\x%X (aka \"del\")", wc);
}
}
static void ascii_printable_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) {
if (bind_friendly && must_escape(wc)) {
swprintf(buf, buf_len, L"\\%c", wc);
std::swprintf(buf, buf_len, L"\\%c", wc);
} else {
swprintf(buf, buf_len, L"%c", wc);
std::swprintf(buf, buf_len, L"%c", wc);
}
}
@ -145,9 +145,9 @@ static wchar_t *char_to_symbol(wchar_t wc, bool bind_friendly) {
} else if (wc < 0x80) { // ASCII characters that are not control characters
ascii_printable_to_symbol(buf, sizeof(buf) / sizeof(*buf), wc, bind_friendly);
} else if (wc <= 0xFFFF) { // BMP Unicode chararacter
swprintf(buf, sizeof(buf) / sizeof(*buf), L"\\u%04X", wc);
std::swprintf(buf, sizeof(buf) / sizeof(*buf), L"\\u%04X", wc);
} else { // Non-BMP Unicode chararacter
swprintf(buf, sizeof(buf) / sizeof(*buf), L"\\U%06X", wc);
std::swprintf(buf, sizeof(buf) / sizeof(*buf), L"\\U%06X", wc);
}
return buf;
@ -159,23 +159,23 @@ static void add_char_to_bind_command(wchar_t wc, std::vector<wchar_t> &bind_char
static void output_bind_command(std::vector<wchar_t> &bind_chars) {
if (bind_chars.size()) {
fputws(L"bind ", stdout);
std::fputws(L"bind ", stdout);
for (size_t i = 0; i < bind_chars.size(); i++) {
fputws(char_to_symbol(bind_chars[i], true), stdout);
std::fputws(char_to_symbol(bind_chars[i], true), stdout);
}
fputws(L" 'do something'\n", stdout);
std::fputws(L" 'do something'\n", stdout);
bind_chars.clear();
}
}
static void output_info_about_char(wchar_t wc) {
fwprintf(stderr, L"hex: %4X char: %ls\n", wc, char_to_symbol(wc, false));
std::fwprintf(stderr, L"hex: %4X char: %ls\n", wc, char_to_symbol(wc, false));
}
static bool output_matching_key_name(wchar_t wc) {
char *name = sequence_name(wc);
if (name) {
fwprintf(stdout, L"bind -k %s 'do something'\n", name);
std::fwprintf(stdout, L"bind -k %s 'do something'\n", name);
free(name);
return true;
}
@ -187,11 +187,11 @@ static double output_elapsed_time(double prev_tstamp, bool first_char_seen) {
double now = timef();
long long int delta_tstamp_us = 1000000 * (now - prev_tstamp);
if (delta_tstamp_us >= 200000 && first_char_seen) fputwc(L'\n', stderr);
if (delta_tstamp_us >= 200000 && first_char_seen) std::fputwc(L'\n', stderr);
if (delta_tstamp_us >= 1000000) {
fwprintf(stderr, L" ");
std::fwprintf(stderr, L" ");
} else {
fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000, delta_tstamp_us % 1000);
std::fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000, delta_tstamp_us % 1000);
}
return now;
}
@ -202,7 +202,7 @@ static void process_input(bool continuous_mode) {
double prev_tstamp = 0.0;
std::vector<wchar_t> bind_chars;
fwprintf(stderr, L"Press a key\n\n");
std::fwprintf(stderr, L"Press a key\n\n");
while (keep_running) {
wchar_t wc;
if (reader_test_and_clear_interrupted()) {
@ -226,7 +226,7 @@ static void process_input(bool continuous_mode) {
}
if (should_exit(wc)) {
fwprintf(stderr, L"\nExiting at your request.\n");
std::fwprintf(stderr, L"\nExiting at your request.\n");
break;
}
@ -238,7 +238,7 @@ static void process_input(bool continuous_mode) {
/// Otherwise just report receipt of the signal.
static struct sigaction old_sigactions[32];
static void signal_handler(int signo, siginfo_t *siginfo, void *siginfo_arg) {
fwprintf(stdout, _(L"signal #%d (%ls) received\n"), signo, sig2wcs(signo));
std::fwprintf(stdout, _(L"signal #%d (%ls) received\n"), signo, sig2wcs(signo));
if (signo == SIGHUP || signo == SIGTERM || signo == SIGABRT || signo == SIGSEGV) {
keep_running = false;
}
@ -288,11 +288,11 @@ static void setup_and_process_keys(bool continuous_mode) {
install_our_signal_handlers();
if (continuous_mode) {
fwprintf(stderr, L"\n");
fwprintf(stderr, L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
fwprintf(stderr, L"or press [ctrl-%c] or [ctrl-%c] twice in a row.\n",
std::fwprintf(stderr, L"\n");
std::fwprintf(stderr, L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
std::fwprintf(stderr, L"or press [ctrl-%c] or [ctrl-%c] twice in a row.\n",
shell_modes.c_cc[VINTR] + 0x40, shell_modes.c_cc[VEOF] + 0x40);
fwprintf(stderr, L"\n");
std::fwprintf(stderr, L"\n");
}
process_input(continuous_mode);
@ -308,7 +308,7 @@ static bool parse_debug_level_flag() {
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag\n"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag\n"), optarg);
return false;
}
@ -322,7 +322,7 @@ static bool parse_debug_frames_flag() {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
debug_stack_frames = (int)tmp;
} else {
fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag\n"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag\n"), optarg);
return false;
}
@ -359,7 +359,7 @@ static bool parse_flags(int argc, char **argv, bool *continuous_mode) {
break;
}
case 'v': {
fwprintf(stdout, L"%s\n", get_fish_version());
std::fwprintf(stdout, L"%s\n", get_fish_version());
return false;
}
default: {
@ -374,7 +374,7 @@ static bool parse_flags(int argc, char **argv, bool *continuous_mode) {
argc -= optind;
if (argc != 0) {
fwprintf(stderr, L"Expected no arguments, got %d\n", argc);
std::fwprintf(stderr, L"Expected no arguments, got %d\n", argc);
return false;
}
@ -388,7 +388,7 @@ int main(int argc, char **argv) {
if (!parse_flags(argc, argv, &continuous_mode)) return 1;
if (!isatty(STDIN_FILENO)) {
fwprintf(stderr, L"Stdin must be attached to a tty.\n");
std::fwprintf(stderr, L"Stdin must be attached to a tty.\n");
return 1;
}

View file

@ -23,7 +23,7 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <thread>
@ -114,9 +114,9 @@ static int err_count = 0;
static void say(const wchar_t *fmt, ...) {
va_list va;
va_start(va, fmt);
vfwprintf(stdout, fmt, va);
std::vfwprintf(stdout, fmt, va);
va_end(va);
fwprintf(stdout, L"\n");
std::fwprintf(stdout, L"\n");
}
/// Print formatted error string.
@ -130,18 +130,18 @@ static void err(const wchar_t *blah, ...) {
// Show errors in red.
if (colorize) {
fputws(L"\x1B[31m", stdout);
std::fputws(L"\x1B[31m", stdout);
}
fwprintf(stdout, L"Error: ");
vfwprintf(stdout, blah, va);
std::fwprintf(stdout, L"Error: ");
std::vfwprintf(stdout, blah, va);
va_end(va);
// Return to normal color.
if (colorize) {
fputws(L"\x1B[0m", stdout);
std::fputws(L"\x1B[0m", stdout);
}
fwprintf(stdout, L"\n");
std::fwprintf(stdout, L"\n");
}
/// Joins a wcstring_list_t via commas.
@ -459,8 +459,8 @@ static void test_format() {
wchar_t wbuf1[128], wbuf2[128];
format_long_safe(wbuf1, j);
swprintf(wbuf2, 128, L"%d", j);
do_test(!wcscmp(wbuf1, wbuf2));
std::swprintf(wbuf2, 128, L"%d", j);
do_test(!std::wcscmp(wbuf1, wbuf2));
}
long q = LONG_MIN;
@ -599,12 +599,12 @@ static void test_tokenizer() {
while (t.next(&token)) {
if (i >= sizeof types / sizeof *types) {
err(L"Too many tokens returned from tokenizer");
fwprintf(stdout, L"Got excess token type %ld\n", (long)token.type);
std::fwprintf(stdout, L"Got excess token type %ld\n", (long)token.type);
break;
}
if (types[i] != token.type) {
err(L"Tokenization error:");
fwprintf(stdout,
std::fwprintf(stdout,
L"Token number %zu of string \n'%ls'\n, expected type %ld, got token type "
L"%ld\n",
i + 1, str, (long)types[i], (long)token.type);
@ -1132,29 +1132,29 @@ static void test_parse_util_cmdsubst_extent() {
const wchar_t *begin = NULL, *end = NULL;
parse_util_cmdsubst_extent(a, 0, &begin, &end);
if (begin != a || end != begin + wcslen(begin)) {
if (begin != a || end != begin + std::wcslen(begin)) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
parse_util_cmdsubst_extent(a, 1, &begin, &end);
if (begin != a || end != begin + wcslen(begin)) {
if (begin != a || end != begin + std::wcslen(begin)) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
parse_util_cmdsubst_extent(a, 2, &begin, &end);
if (begin != a || end != begin + wcslen(begin)) {
if (begin != a || end != begin + std::wcslen(begin)) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
parse_util_cmdsubst_extent(a, 3, &begin, &end);
if (begin != a || end != begin + wcslen(begin)) {
if (begin != a || end != begin + std::wcslen(begin)) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
parse_util_cmdsubst_extent(a, 8, &begin, &end);
if (begin != a + wcslen(L"echo (")) {
if (begin != a + std::wcslen(L"echo (")) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
parse_util_cmdsubst_extent(a, 17, &begin, &end);
if (begin != a + wcslen(L"echo (echo (")) {
if (begin != a + std::wcslen(L"echo (echo (")) {
err(L"parse_util_cmdsubst_extent failed on line %ld", (long)__LINE__);
}
}
@ -1864,43 +1864,43 @@ static void test_abbreviations() {
if (!expanded) err(L"Command not expanded on line %ld", (long)__LINE__);
expanded =
reader_expand_abbreviation_in_command(L"gc somebranch", wcslen(L"gc"), vars, &result);
reader_expand_abbreviation_in_command(L"gc somebranch", std::wcslen(L"gc"), vars, &result);
if (!expanded) err(L"gc not expanded");
if (result != L"git checkout somebranch")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Space separation.
expanded =
reader_expand_abbreviation_in_command(L"gx somebranch", wcslen(L"gc"), vars, &result);
reader_expand_abbreviation_in_command(L"gx somebranch", std::wcslen(L"gc"), vars, &result);
if (!expanded) err(L"gx not expanded");
if (result != L"git checkout somebranch")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
expanded = reader_expand_abbreviation_in_command(L"echo hi ; gc somebranch",
wcslen(L"echo hi ; g"), vars, &result);
std::wcslen(L"echo hi ; g"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"echo hi ; git checkout somebranch")
err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
expanded = reader_expand_abbreviation_in_command(
L"echo (echo (echo (echo (gc ", wcslen(L"echo (echo (echo (echo (gc"), vars, &result);
L"echo (echo (echo (echo (gc ", std::wcslen(L"echo (echo (echo (echo (gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"echo (echo (echo (echo (git checkout ")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// If commands should be expanded.
expanded = reader_expand_abbreviation_in_command(L"if gc", wcslen(L"if gc"), vars, &result);
expanded = reader_expand_abbreviation_in_command(L"if gc", std::wcslen(L"if gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"if git checkout")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Others should not be.
expanded = reader_expand_abbreviation_in_command(L"of gc", wcslen(L"of gc"), vars, &result);
expanded = reader_expand_abbreviation_in_command(L"of gc", std::wcslen(L"of gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
// Others should not be.
expanded =
reader_expand_abbreviation_in_command(L"command gc", wcslen(L"command gc"), vars, &result);
reader_expand_abbreviation_in_command(L"command gc", std::wcslen(L"command gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
vars.pop();
@ -2042,10 +2042,10 @@ struct pager_layout_testcase_t {
wcstring text = sd.line(0).to_string();
if (text != expected) {
fwprintf(stderr, L"width %zu got %zu<%ls>, expected %zu<%ls>\n", this->width,
std::fwprintf(stderr, L"width %zu got %zu<%ls>, expected %zu<%ls>\n", this->width,
text.length(), text.c_str(), expected.length(), expected.c_str());
for (size_t i = 0; i < std::max(text.length(), expected.length()); i++) {
fwprintf(stderr, L"i %zu got <%lx> expected <%lx>\n", i,
std::fwprintf(stderr, L"i %zu got <%lx> expected <%lx>\n", i,
i >= text.length() ? 0xffff : text[i],
i >= expected.length() ? 0xffff : expected[i]);
}
@ -2137,7 +2137,7 @@ 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);
// fwprintf(stdout, L"idx %lu, looking at %lu (%c): %d\n", idx, char_idx, (char)wc,
// std::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) {
@ -2384,7 +2384,7 @@ static void test_wcstod() {
auto tod_test = [](const wchar_t *a, const char *b) {
char *narrow_end = nullptr;
wchar_t *wide_end = nullptr;
double val1 = wcstod(a, &wide_end);
double val1 = std::wcstod(a, &wide_end);
double val2 = strtod(b, &narrow_end);
do_test((std::isnan(val1) && std::isnan(val2)) || fabs(val1 - val2) <= __DBL_EPSILON__);
do_test(wide_end - a == narrow_end - b);
@ -2699,7 +2699,7 @@ static void test_1_completion(wcstring line, const wcstring &completion, complet
wcstring result =
completion_apply_to_command_line(completion, flags, line, &cursor_pos, append_only);
if (result != expected) {
fwprintf(stderr, L"line %ld: %ls + %ls -> [%ls], expected [%ls]\n", source_line,
std::fwprintf(stderr, L"line %ld: %ls + %ls -> [%ls], expected [%ls]\n", source_line,
line.c_str(), completion.c_str(), result.c_str(), expected.c_str());
}
do_test(result == expected);
@ -2743,12 +2743,12 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
fwprintf(stderr,
std::fwprintf(stderr,
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
@ -2760,12 +2760,12 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc
const completion_t &suggestion = comps.at(0);
if (suggestion.completion != expected) {
fwprintf(
std::fwprintf(
stderr,
L"line %ld: complete() for cd returned the wrong expected string for command %ls\n",
line, command.c_str());
fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
fwprintf(stderr, L"expected: %ls\n", expected.c_str());
std::fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
std::fwprintf(stderr, L"expected: %ls\n", expected.c_str());
do_test_from(suggestion.completion == expected, line);
}
}
@ -2779,12 +2779,12 @@ static void perform_one_completion_cd_test(const wcstring &command, const wcstri
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
fwprintf(stderr,
std::fwprintf(stderr,
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
@ -2796,12 +2796,12 @@ static void perform_one_completion_cd_test(const wcstring &command, const wcstri
const completion_t &suggestion = comps.at(0);
if (suggestion.completion != expected) {
fwprintf(stderr,
std::fwprintf(stderr,
L"line %ld: complete() for cd tab completion returned the wrong expected "
L"string for command %ls\n",
line, command.c_str());
fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
fwprintf(stderr, L"expected: %ls\n", expected.c_str());
std::fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
std::fwprintf(stderr, L"expected: %ls\n", expected.c_str());
do_test_from(suggestion.completion == expected, line);
}
}
@ -2918,9 +2918,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;
fwprintf(stderr, L"line %ld: complete() expected to return nothing for %ls\n", line,
std::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());
std::fwprintf(stderr, L" instead got: %ls\n", suggestion.c_str());
}
}
@ -3862,7 +3862,7 @@ void history_tests_t::test_history_speed(void)
if (stop >= end)
break;
}
fwprintf(stdout, L"%lu items - %.2f msec per item\n", (unsigned long)count,
std::fwprintf(stdout, L"%lu items - %.2f msec per item\n", (unsigned long)count,
(stop - start) * 1E6 / count);
hist->clear();
}
@ -3945,7 +3945,7 @@ static void test_new_parser_fuzzing() {
bool log_it = true;
unsigned long max_len = 5;
for (unsigned long len = 0; len < max_len; len++) {
if (log_it) fwprintf(stderr, L"%lu / %lu...", len, max_len);
if (log_it) std::fwprintf(stderr, L"%lu / %lu...", len, max_len);
// We wish to look at all permutations of 4 elements of 'fuzzes' (with replacement).
// Construct an int and keep incrementing it.
@ -3954,7 +3954,7 @@ static void test_new_parser_fuzzing() {
&src)) {
parse_tree_from_string(src, parse_flag_continue_after_error, &node_tree, &errors);
}
if (log_it) fwprintf(stderr, L"done (%lu)\n", permutation);
if (log_it) std::fwprintf(stderr, L"done (%lu)\n", permutation);
}
double end = timef();
if (log_it) say(L"All fuzzed in %f seconds!", end - start);
@ -4136,9 +4136,9 @@ static void test_new_parser_errors() {
static wcstring_list_t separate_by_format_specifiers(const wchar_t *format) {
wcstring_list_t result;
const wchar_t *cursor = format;
const wchar_t *end = format + wcslen(format);
const wchar_t *end = format + std::wcslen(format);
while (cursor < end) {
const wchar_t *next_specifier = wcschr(cursor, '%');
const wchar_t *next_specifier = std::wcschr(cursor, '%');
if (next_specifier == NULL) {
next_specifier = end;
}
@ -4157,7 +4157,7 @@ static wcstring_list_t separate_by_format_specifiers(const wchar_t *format) {
cursor++;
// Flag
if (wcschr(L"#0- +'", *cursor)) cursor++;
if (std::wcschr(L"#0- +'", *cursor)) cursor++;
// Minimum field width
while (iswdigit(*cursor)) cursor++;
// Precision
@ -4166,9 +4166,9 @@ static wcstring_list_t separate_by_format_specifiers(const wchar_t *format) {
while (iswdigit(*cursor)) cursor++;
}
// Length modifier
if (!wcsncmp(cursor, L"ll", 2) || !wcsncmp(cursor, L"hh", 2)) {
if (!std::wcsncmp(cursor, L"ll", 2) || !std::wcsncmp(cursor, L"hh", 2)) {
cursor += 2;
} else if (wcschr(L"hljtzqL", *cursor)) {
} else if (std::wcschr(L"hljtzqL", *cursor)) {
cursor++;
}
// The format specifier itself. We allow any character except NUL.
@ -5177,7 +5177,7 @@ int main(int argc, char **argv) {
exit(-1);
}
if (!strcmp(wd, "/")) {
fwprintf(stderr,
std::fwprintf(stderr,
L"Unable to find 'tests' directory, which should contain file test.fish\n");
exit(EXIT_FAILURE);
}

View file

@ -8,7 +8,7 @@
#include <dirent.h>
#include <pthread.h>
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <map>
@ -122,8 +122,8 @@ static void autoload_names(std::unordered_set<wcstring> &names, int get_hidden)
const wchar_t *suffix;
if (!get_hidden && fn[0] == L'_') continue;
suffix = wcsrchr(fn, L'.');
if (suffix && (wcscmp(suffix, L".fish") == 0)) {
suffix = std::wcsrchr(fn, L'.');
if (suffix && (std::wcscmp(suffix, L".fish") == 0)) {
wcstring name(fn, suffix - fn);
names.insert(name);
}

View file

@ -1,6 +1,6 @@
#include "config.h" // IWYU pragma: keep
#include <wchar.h>
#include <cwchar>
#include "future_feature_flags.h"
/// The set of features applying to this instance.
@ -18,7 +18,7 @@ const features_t::metadata_t features_t::metadata[features_t::flag_count] = {
const struct features_t::metadata_t *features_t::metadata_for(const wchar_t *name) {
assert(name && "null flag name");
for (const auto &md : metadata) {
if (!wcscmp(name, md.name)) return &md;
if (!std::wcscmp(name, md.name)) return &md;
}
return nullptr;
}
@ -38,7 +38,7 @@ void features_t::set_from_string(const wcstring &str) {
// A "no-" prefix inverts the sense.
if (string_prefixes_string(L"no-", name)) {
value = false;
name += 3; // wcslen(L"no-")
name += 3; // std::wcslen(L"no-")
}
// Look for a feature with this name. If we don't find it, assume it's a group name and set
// all features whose group contain it. Do nothing even if the string is unrecognized; this
@ -49,7 +49,7 @@ void features_t::set_from_string(const wcstring &str) {
this->set(md->flag, value);
} else {
for (const metadata_t &md : metadata) {
if (wcsstr(md.groups, name) || !wcscmp(name, L"all")) {
if (std::wcsstr(md.groups, name) || !std::wcscmp(name, L"all")) {
this->set(md.flag, value);
}
}

View file

@ -6,7 +6,7 @@
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -532,7 +532,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
// Hacky support for %self which must be an unquoted literal argument.
if (buffstr == PROCESS_EXPAND_SELF_STR) {
std::fill_n(colors, wcslen(PROCESS_EXPAND_SELF_STR), highlight_role_t::operat);
std::fill_n(colors, std::wcslen(PROCESS_EXPAND_SELF_STR), highlight_role_t::operat);
return;
}
@ -554,7 +554,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
if (escaped_char == L'\0') {
fill_end = in_pos;
fill_color = highlight_role_t::error;
} else if (wcschr(L"~%", escaped_char)) {
} else if (std::wcschr(L"~%", escaped_char)) {
if (in_pos == 1) {
fill_end = in_pos + 1;
}
@ -562,12 +562,12 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
if (bracket_count) {
fill_end = in_pos + 1;
}
} else if (wcschr(L"abefnrtv*?$(){}[]'\"<>^ \\#;|&", escaped_char)) {
} else if (std::wcschr(L"abefnrtv*?$(){}[]'\"<>^ \\#;|&", escaped_char)) {
fill_end = in_pos + 1;
} else if (wcschr(L"c", escaped_char)) {
} else if (std::wcschr(L"c", escaped_char)) {
// Like \ci. So highlight three characters.
fill_end = in_pos + 1;
} else if (wcschr(L"uUxX01234567", escaped_char)) {
} else if (std::wcschr(L"uUxX01234567", escaped_char)) {
long long res = 0;
int chars = 2;
int base = 16;
@ -720,7 +720,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
// Backslash
if (in_pos + 1 < buff_len) {
const wchar_t escaped_char = buffstr.at(in_pos + 1);
if (wcschr(L"\\\"\n$", escaped_char)) {
if (std::wcschr(L"\\\"\n$", escaped_char)) {
colors[in_pos] = highlight_role_t::escape; // backslash
colors[in_pos + 1] = highlight_role_t::escape; // escaped char
in_pos += 1; // skip over backslash
@ -1366,9 +1366,9 @@ static void highlight_universal_internal(const wcstring &buffstr,
// Highlight matching parenthesis.
const wchar_t c = buffstr.at(pos);
if (wcschr(L"()[]{}", c)) {
int step = wcschr(L"({[", c) ? 1 : -1;
wchar_t dec_char = *(wcschr(L"()[]{}", c) + step);
if (std::wcschr(L"()[]{}", c)) {
int step = std::wcschr(L"({[", c) ? 1 : -1;
wchar_t dec_char = *(std::wcschr(L"()[]{}", c) + step);
wchar_t inc_char = c;
int level = 0;
bool match_found = false;

View file

@ -16,7 +16,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -422,7 +422,7 @@ static history_item_t decode_item_fish_1_x(const char *begin, size_t length) {
c = (unsigned char)*pos;
res = 1;
} else {
res = mbrtowc(&c, pos, end - pos, &state);
res = std::mbrtowc(&c, pos, end - pos, &state);
}
if (res == (size_t)-1) {

View file

@ -2,7 +2,7 @@
#include "config.h"
#include <errno.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#if HAVE_TERM_H
#include <curses.h>
@ -746,7 +746,7 @@ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq) {
for (size_t i = 0; i < terminfo_mappings.size(); i++) {
const terminfo_mapping_t &m = terminfo_mappings.at(i);
if (!wcscmp(name, m.name)) {
if (!std::wcscmp(name, m.name)) {
res = m.seq;
err = EILSEQ;
break;

View file

@ -11,7 +11,7 @@
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <wchar.h>
#include <cwchar>
#include <deque>
#include <list>
@ -165,7 +165,7 @@ void update_wait_on_escape_ms(const environment_t &vars) {
long tmp = fish_wcstol(escape_time_ms->as_string().c_str());
if (errno || tmp < 10 || tmp >= 5000) {
fwprintf(stderr,
std::fwprintf(stderr,
L"ignoring fish_escape_delay_ms: value '%ls' "
L"is not an integer or is < 10 or >= 5000 ms\n",
escape_time_ms->as_string().c_str());
@ -201,7 +201,7 @@ wchar_t input_common_readch(int timed) {
}
char bb = b;
size_t sz = mbrtowc(&res, &bb, 1, &state);
size_t sz = std::mbrtowc(&res, &bb, 1, &state);
switch (sz) {
case (size_t)(-1): {

View file

@ -2,7 +2,7 @@
#include "config.h" // IWYU pragma: keep
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -12,7 +12,7 @@
#include "fallback.h" // IWYU pragma: keep
#include "intern.h"
bool string_less_than_string(const wchar_t *a, const wchar_t *b) { return wcscmp(a, b) < 0; }
bool string_less_than_string(const wchar_t *a, const wchar_t *b) { return std::wcscmp(a, b) < 0; }
/// The table of intern'd strings.
owning_lock<std::vector<const wchar_t *>> string_table;
@ -25,7 +25,7 @@ static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) {
const wchar_t *result;
auto iter = std::lower_bound(table->begin(), table->end(), in, string_less_than_string);
if (iter != table->end() && wcscmp(*iter, in) == 0) {
if (iter != table->end() && std::wcscmp(*iter, in) == 0) {
result = *iter;
} else {
result = dup ? wcsdup(in) : in;

View file

@ -6,7 +6,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include "common.h"
#include "exec.h"
@ -18,17 +18,17 @@
io_data_t::~io_data_t() = default;
void io_close_t::print() const { fwprintf(stderr, L"close %d\n", fd); }
void io_close_t::print() const { std::fwprintf(stderr, L"close %d\n", fd); }
void io_fd_t::print() const { fwprintf(stderr, L"FD map %d -> %d\n", old_fd, fd); }
void io_fd_t::print() const { std::fwprintf(stderr, L"FD map %d -> %d\n", old_fd, fd); }
void io_file_t::print() const { fwprintf(stderr, L"file (%s)\n", filename_cstr); }
void io_file_t::print() const { std::fwprintf(stderr, L"file (%s)\n", filename_cstr); }
void io_pipe_t::print() const {
fwprintf(stderr, L"pipe {%d} (input: %s)\n", pipe_fd(), is_input_ ? "yes" : "no");
std::fwprintf(stderr, L"pipe {%d} (input: %s)\n", pipe_fd(), is_input_ ? "yes" : "no");
}
void io_bufferfill_t::print() const { fwprintf(stderr, L"bufferfill {%d}\n", write_fd_.fd()); }
void io_bufferfill_t::print() const { std::fwprintf(stderr, L"bufferfill {%d}\n", write_fd_.fd()); }
void io_buffer_t::append_from_stream(const output_stream_t &stream) {
if (stream.empty()) return;
@ -223,21 +223,21 @@ void io_print(const io_chain_t &chain)
{
if (chain.empty())
{
fwprintf(stderr, L"Empty chain %p\n", &chain);
std::fwprintf(stderr, L"Empty chain %p\n", &chain);
return;
}
fwprintf(stderr, L"Chain %p (%ld items):\n", &chain, (long)chain.size());
std::fwprintf(stderr, L"Chain %p (%ld items):\n", &chain, (long)chain.size());
for (size_t i=0; i < chain.size(); i++)
{
const shared_ptr<io_data_t> &io = chain.at(i);
if (io.get() == NULL)
{
fwprintf(stderr, L"\t(null)\n");
std::fwprintf(stderr, L"\t(null)\n");
}
else
{
fwprintf(stderr, L"\t%lu: fd:%d, ", (unsigned long)i, io->fd);
std::fwprintf(stderr, L"\t%lu: fd:%d, ", (unsigned long)i, io->fd);
io->print();
}
}

View file

@ -383,7 +383,7 @@ class output_stream_t {
const separated_buffer_t<wcstring> &buffer() const { return buffer_; }
void append(const wchar_t *s) { append(s, wcslen(s)); }
void append(const wchar_t *s) { append(s, std::wcslen(s)); }
void append(wchar_t s) { append(&s, 1); }

View file

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

View file

@ -2,7 +2,7 @@
#ifndef FISH_LRU_H
#define FISH_LRU_H
#include <wchar.h>
#include <cwchar>
#include <unordered_map>

View file

@ -17,7 +17,7 @@
#include <ncurses/term.h>
#endif
#include <limits.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -379,7 +379,7 @@ int outputter_t::writech(wint_t ch) {
len = 1;
} else {
mbstate_t state = {};
len = wcrtomb(buff, ch, &state);
len = std::wcrtomb(buff, ch, &state);
if (len == (size_t)-1) {
return 1;
}
@ -389,7 +389,7 @@ int outputter_t::writech(wint_t ch) {
}
/// Write a wide character string to stdout. This should not be used to output things like warning
/// messages; just use debug() or fwprintf() for that. It should only be used to output user
/// messages; just use debug() or std::fwprintf() for that. It should only be used to output user
/// supplied strings that might contain literal bytes; e.g., "\342\224\214" from issue #1894. This
/// is needed because those strings may contain chars specially encoded using ENCODE_DIRECT_BASE.
void outputter_t::writestr(const wchar_t *str) {
@ -508,7 +508,7 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background) {
#if 0
wcstring desc = result.description();
fwprintf(stdout, L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
std::fwprintf(stdout, L"Parsed %ls from %ls (%s)\n", desc.c_str(), val.c_str(),
is_background ? "background" : "foreground");
#endif

View file

@ -2,7 +2,7 @@
// IWYU pragma: no_include <cstddef>
#include <stddef.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -852,7 +852,7 @@ void pager_t::set_search_field_shown(bool flag) { this->search_field_shown = fla
bool pager_t::is_search_field_shown() const { return this->search_field_shown; }
size_t pager_t::cursor_position() const {
size_t result = wcslen(SEARCH_FIELD_PROMPT) + this->search_field_line.position;
size_t result = std::wcslen(SEARCH_FIELD_PROMPT) + this->search_field_line.position;
// Clamp it to the right edge.
if (available_term_width > 0 && result + 1 > available_term_width) {
result = available_term_width - 1;

View file

@ -14,7 +14,7 @@
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -628,7 +628,7 @@ parse_execution_result_t parse_execution_context_t::report_errors(
// Print it.
if (!should_suppress_stderr_for_tests()) {
fwprintf(stderr, L"%ls", backtrace_and_desc.c_str());
std::fwprintf(stderr, L"%ls", backtrace_and_desc.c_str());
}
}
return parse_execution_errored;
@ -673,7 +673,7 @@ parse_execution_result_t parse_execution_context_t::handle_command_not_found(
// status to 127, which is the standard number used by other shells like bash and zsh.
const wchar_t *const cmd = cmd_str.c_str();
const wchar_t *const equals_ptr = wcschr(cmd, L'=');
const wchar_t *const equals_ptr = std::wcschr(cmd, L'=');
if (equals_ptr != NULL) {
// Try to figure out if this is a pure variable assignment (foo=bar), or if this appears to
// be running a command (foo=bar ruby...).

View file

@ -4,7 +4,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <string>
@ -407,17 +407,17 @@ class parse_ll_t {
bool logit = false;
if (logit) {
int count = 0;
fwprintf(stderr, L"Applying production:\n");
std::fwprintf(stderr, L"Applying production:\n");
for (int i = 0;; i++) {
production_element_t elem = production[i];
if (!production_element_is_valid(elem)) break; // all done, bail out
parse_token_type_t type = production_element_type(elem);
parse_keyword_t keyword = production_element_keyword(elem);
fwprintf(stderr, L"\t%ls <%ls>\n", token_type_description(type),
std::fwprintf(stderr, L"\t%ls <%ls>\n", token_type_description(type),
keyword_description(keyword));
count++;
}
if (!count) fwprintf(stderr, L"\t<empty>\n");
if (!count) std::fwprintf(stderr, L"\t<empty>\n");
}
// Get the parent index. But we can't get the parent parse node yet, since it may be made
@ -524,9 +524,9 @@ void parse_ll_t::dump_stack(void) const {
}
}
fwprintf(stderr, L"Stack dump (%zu elements):\n", symbol_stack.size());
std::fwprintf(stderr, L"Stack dump (%zu elements):\n", symbol_stack.size());
for (size_t idx = 0; idx < stack_lines.size(); idx++) {
fwprintf(stderr, L" %ls\n", stack_lines.at(idx).c_str());
std::fwprintf(stderr, L" %ls\n", stack_lines.at(idx).c_str());
}
}
#endif

View file

@ -6,7 +6,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -117,7 +117,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
for (pos = const_cast<wchar_t *>(in); *pos; pos++) {
if (prev != '\\') {
if (wcschr(L"\'\"", *pos)) {
if (std::wcschr(L"\'\"", *pos)) {
wchar_t *q_end = quote_end(pos);
if (q_end && *q_end) {
pos = q_end;
@ -165,7 +165,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
}
if (end) {
*end = paran_count ? (wchar_t *)in + wcslen(in) : paran_end;
*end = paran_count ? (wchar_t *)in + std::wcslen(in) : paran_end;
}
return 1;
@ -239,7 +239,7 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc
CHECK(buff, );
const size_t bufflen = wcslen(buff);
const size_t bufflen = std::wcslen(buff);
assert(cursor_pos <= bufflen);
// ap and bp are the beginning and end of the tightest command substitition found so far.
@ -360,7 +360,7 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar
// pos is equivalent to cursor_pos within the range of the command substitution {begin, end}.
size_t offset_within_cmdsubst = cursor_pos - (cmdsubst_begin - buff);
size_t bufflen = wcslen(buff);
size_t bufflen = std::wcslen(buff);
a = cmdsubst_begin + offset_within_cmdsubst;
b = a;
@ -462,7 +462,7 @@ static wchar_t get_quote(const wcstring &cmd_str, size_t len) {
} else {
if (cmd[i] == L'\'' || cmd[i] == L'\"') {
const wchar_t *end = quote_end(&cmd[i]);
// fwprintf( stderr, L"Jump %d\n", end-cmd );
// std::fwprintf( stderr, L"Jump %d\n", end-cmd );
if ((end == 0) || (!*end) || (end > cmd + len)) {
res = cmd[i];
break;
@ -500,7 +500,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
bool finished = cmdlen != 0;
if (finished) {
finished = (quote == NULL);
if (finished && wcschr(L" \t\n\r", cmd_tmp[cmdlen - 1])) {
if (finished && std::wcschr(L" \t\n\r", cmd_tmp[cmdlen - 1])) {
finished = cmdlen > 1 && cmd_tmp[cmdlen - 2] == L'\\';
}
}
@ -509,7 +509,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
if (offset != 0) {
if (finished) {
while ((cmd_tmp[prev_pos] != 0) && (wcschr(L";|", cmd_tmp[prev_pos]) != 0)) prev_pos++;
while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != 0)) prev_pos++;
*offset = prev_pos;
} else {
*offset = pos;
@ -729,7 +729,7 @@ std::vector<int> parse_util_compute_indents(const wcstring &src) {
// indentation level if a new line starts with whitespace.
size_t prev_char_idx = i;
while (prev_char_idx--) {
if (!wcschr(L" \n\t\r", src.at(prev_char_idx))) break;
if (!std::wcschr(L" \n\t\r", src.at(prev_char_idx))) break;
indents.at(prev_char_idx) = last_indent;
}
}
@ -739,7 +739,7 @@ std::vector<int> parse_util_compute_indents(const wcstring &src) {
// indented even if it is empty.
size_t suffix_idx = src_size;
while (suffix_idx--) {
if (!wcschr(L" \n\t\r", src.at(suffix_idx))) break;
if (!std::wcschr(L" \n\t\r", src.at(suffix_idx))) break;
indents.at(suffix_idx) = last_trailing_indent;
}
@ -771,7 +771,7 @@ static int parser_is_pipe_forbidden(const wcstring &word) {
}
bool parse_util_argument_is_help(const wchar_t *s) {
return wcscmp(L"-h", s) == 0 || wcscmp(L"--help", s) == 0;
return std::wcscmp(L"-h", s) == 0 || std::wcscmp(L"--help", s) == 0;
}
/// Check if the first argument under the given node is --help.

View file

@ -2,7 +2,7 @@
#include "config.h" // IWYU pragma: keep
#include <stdio.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <memory>
@ -275,19 +275,19 @@ static void print_profile(const std::vector<std::unique_ptr<profile_item_t>> &it
continue;
}
if (fwprintf(out, L"%d\t%d\t", my_time, me->parse + me->exec) < 0) {
if (std::fwprintf(out, L"%d\t%d\t", my_time, me->parse + me->exec) < 0) {
wperror(L"fwprintf");
return;
}
for (i = 0; i < me->level; i++) {
if (fwprintf(out, L"-") < 0) {
if (std::fwprintf(out, L"-") < 0) {
wperror(L"fwprintf");
return;
}
}
if (fwprintf(out, L"> %ls\n", me->cmd.c_str()) < 0) {
if (std::fwprintf(out, L"> %ls\n", me->cmd.c_str()) < 0) {
wperror(L"fwprintf");
return;
}
@ -301,7 +301,7 @@ void parser_t::emit_profiling(const char *path) const {
if (!f) {
debug(1, _(L"Could not write profiling information to file '%s'"), path);
} else {
if (fwprintf(f, _(L"Time\tSum\tCommand\n"), profile_items.size()) < 0) {
if (std::fwprintf(f, _(L"Time\tSum\tCommand\n"), profile_items.size()) < 0) {
wperror(L"fwprintf");
} else {
print_profile(profile_items, f);
@ -639,7 +639,7 @@ int parser_t::eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_t
this->get_backtrace(cmd, error_list, backtrace_and_desc);
// Print it.
fwprintf(stderr, L"%ls\n", backtrace_and_desc.c_str());
std::fwprintf(stderr, L"%ls\n", backtrace_and_desc.c_str());
return 1;
}
this->eval(ps, io, block_type);

View file

@ -7,7 +7,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>

View file

@ -11,7 +11,7 @@
#if FISH_USE_POSIX_SPAWN
#include <spawn.h>
#endif
#include <wchar.h>
#include <cwchar>
#include "common.h"
#include "exec.h"

View file

@ -11,7 +11,7 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#if HAVE_TERM_H
@ -441,7 +441,7 @@ static wcstring truncate_command(const wcstring &cmd) {
}
// Truncation required.
const size_t ellipsis_length = wcslen(ellipsis_str); // no need for wcwidth
const size_t ellipsis_length = std::wcslen(ellipsis_str); // no need for wcwidth
size_t trunc_length = max_len - ellipsis_length;
// Eat trailing whitespace.
while (trunc_length > 0 && iswspace(cmd.at(trunc_length - 1))) {
@ -547,7 +547,7 @@ static bool process_clean_after_marking(bool allow_interactive) {
// we don't need to.
const wcstring job_number_desc =
only_one_job ? wcstring() : format_string(_(L"Job %d, "), j->job_id);
fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"),
std::fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"),
program_name, job_number_desc.c_str(),
truncate_command(j->command()).c_str(), sig2wcs(s.signal_code()),
signal_get_desc(s.signal_code()));
@ -556,13 +556,13 @@ static bool process_clean_after_marking(bool allow_interactive) {
only_one_job ? wcstring() : format_string(L"from job %d, ", j->job_id);
const wchar_t *fmt =
_(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)");
fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(),
std::fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(),
truncate_command(j->command()).c_str(), sig2wcs(s.signal_code()),
signal_get_desc(s.signal_code()));
}
if (clr_eol) outputter_t::stdoutput().term_puts(clr_eol, 1);
fwprintf(stdout, L"\n");
std::fwprintf(stdout, L"\n");
}
found = false;
// clear status so it is not reported more than once
@ -641,7 +641,7 @@ unsigned long proc_get_jiffies(process_t *p) {
wchan, nswap, cnswap;
char comm[1024];
swprintf(fn, FN_SIZE, L"/proc/%d/stat", p->pid);
std::swprintf(fn, FN_SIZE, L"/proc/%d/stat", p->pid);
FILE *f = wfopen(fn, "r");
if (!f) return 0;

View file

@ -32,7 +32,7 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
@ -564,7 +564,7 @@ wcstring combine_command_and_autosuggestion(const wcstring &cmdline,
parse_util_token_extent(cmd, cmdline.size() - 1, &begin, NULL, NULL, NULL);
bool last_token_contains_uppercase = false;
if (begin) {
const wchar_t *end = begin + wcslen(begin);
const wchar_t *end = begin + std::wcslen(begin);
last_token_contains_uppercase = (std::find_if(begin, end, iswupper) != end);
}
if (!last_token_contains_uppercase) {
@ -884,9 +884,9 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) {
if (exec_subshell(fish_title_command, parser_t::principal_parser(), lst,
false /* ignore exit status */) != -1 &&
!lst.empty()) {
fputws(L"\x1B]0;", stdout);
std::fputws(L"\x1B]0;", stdout);
for (size_t i = 0; i < lst.size(); i++) {
fputws(lst.at(i).c_str(), stdout);
std::fputws(lst.at(i).c_str(), stdout);
}
ignore_result(write(STDOUT_FILENO, "\a", 1));
}
@ -1146,7 +1146,7 @@ bool reader_data_t::insert_string(editable_line_t *el, const wcstring &str,
// space). Expand abbreviations.
if (has_expansion_triggering_char && allow_expand_abbreviations) {
assert(range_end > 0);
assert(wcschr(expansion_triggering_chars, str.at(range_end - 1)));
assert(std::wcschr(expansion_triggering_chars, str.at(range_end - 1)));
expand_abbreviation_as_necessary(1);
}
cursor = range_end;
@ -1330,7 +1330,7 @@ static std::function<autosuggestion_result_t(void)> get_autosuggestion_performer
if (!cursor_at_end && iswspace(last_char)) return nothing;
// On the other hand, if the line ends with a quote, don't go dumping stuff after the quote.
if (wcschr(L"'\"", last_char) && cursor_at_end) return nothing;
if (std::wcschr(L"'\"", last_char) && cursor_at_end) return nothing;
// Try normal completions.
completion_request_flags_t complete_flags = COMPLETION_REQUEST_AUTOSUGGESTION;
@ -1467,7 +1467,7 @@ static bool reader_can_replace(const wcstring &in, int flags) {
// Test characters that have a special meaning in any character position.
while (*str) {
if (wcschr(REPLACE_UNCLEAN, *str)) return false;
if (std::wcschr(REPLACE_UNCLEAN, *str)) return false;
str++;
}
@ -2007,7 +2007,7 @@ parser_test_error_bits_t reader_shell_test(const wcstring &b) {
if (!string_suffixes_string(L"\n", error_desc)) {
error_desc.push_back(L'\n');
}
fwprintf(stderr, L"\n%ls", error_desc.c_str());
std::fwprintf(stderr, L"\n%ls", error_desc.c_str());
}
return res;
}
@ -2204,13 +2204,13 @@ void reader_import_history_if_necessary() {
bool shell_is_exiting() { return s_pending_exit.should_exit(); }
void reader_bg_job_warning() {
fputws(_(L"There are still jobs active:\n"), stdout);
fputws(_(L"\n PID Command\n"), stdout);
std::fputws(_(L"There are still jobs active:\n"), stdout);
std::fputws(_(L"\n PID Command\n"), stdout);
job_iterator_t jobs;
while (job_t *j = jobs.next()) {
if (!j->is_completed()) {
fwprintf(stdout, L"%6d %ls\n", j->processes[0]->pid, j->command_wcstr());
std::fwprintf(stdout, L"%6d %ls\n", j->processes[0]->pid, j->command_wcstr());
}
}
fputws(L"\n", stdout);
@ -2438,7 +2438,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
is_interactive_read = 1;
c = input_readch();
is_interactive_read = was_interactive_read;
// fwprintf(stderr, L"C: %lx\n", (long)c);
// std::fwprintf(stderr, L"C: %lx\n", (long)c);
if (((!fish_reserved_codepoint(c))) && (c > 31) && (c != 127) && can_read(0)) {
wchar_t arr[READAHEAD_MAX + 1];
@ -2499,7 +2499,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
if (command_ends_paging(c, focused_on_search_field)) {
clear_pager();
}
// fwprintf(stderr, L"\n\nchar: %ls\n\n", describe_char(c).c_str());
// std::fwprintf(stderr, L"\n\nchar: %ls\n\n", describe_char(c).c_str());
switch (c) {
// Go to beginning of line.
@ -2618,7 +2618,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
// up to the end of the token we're completing.
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
// fwprintf(stderr, L"Complete (%ls)\n", buffcpy.c_str());
// std::fwprintf(stderr, L"Complete (%ls)\n", buffcpy.c_str());
complete_flags_t complete_flags = COMPLETION_REQUEST_DEFAULT |
COMPLETION_REQUEST_DESCRIPTIONS |
COMPLETION_REQUEST_FUZZY_MATCH;
@ -2727,7 +2727,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
case R_YANK: {
yank_str = kill_yank();
insert_string(active_edit_line(), yank_str);
yank_len = wcslen(yank_str);
yank_len = std::wcslen(yank_str);
break;
}
case R_YANK_POP: {
@ -2736,7 +2736,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
yank_str = kill_yank_rotate();
insert_string(active_edit_line(), yank_str);
yank_len = wcslen(yank_str);
yank_len = std::wcslen(yank_str);
}
break;
}
@ -3476,7 +3476,7 @@ static int read_ni(int fd, const io_chain_t &io) {
} else {
wcstring sb;
parser.get_backtrace(str, errors, sb);
fwprintf(stderr, L"%ls", sb.c_str());
std::fwprintf(stderr, L"%ls", sb.c_str());
res = 1;
}
} else {

View file

@ -13,7 +13,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#if HAVE_CURSES_H
#include <curses.h>
@ -101,12 +101,12 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len
return false;
}
const wchar_t *const screen_name_end_sentinel = L"\x1B\\";
const wchar_t *screen_name_end = wcsstr(&code[2], screen_name_end_sentinel);
const wchar_t *screen_name_end = std::wcsstr(&code[2], screen_name_end_sentinel);
if (screen_name_end == NULL) {
// Consider just <esc>k to be the code.
*resulting_length = 2;
} else {
const wchar_t *escape_sequence_end = screen_name_end + wcslen(screen_name_end_sentinel);
const wchar_t *escape_sequence_end = screen_name_end + std::wcslen(screen_name_end_sentinel);
*resulting_length = escape_sequence_end - code;
}
return true;
@ -403,7 +403,7 @@ static void s_desired_append_char(screen_t *s, wchar_t b, highlight_spec_t c, in
if ((s->desired.cursor.x + cw) > screen_width) {
// Current line is soft wrapped (assuming we support it).
s->desired.line(s->desired.cursor.y).is_soft_wrapped = true;
// fwprintf(stderr, L"\n\n1 Soft wrapping %d\n\n", s->desired.cursor.y);
// std::fwprintf(stderr, L"\n\n1 Soft wrapping %d\n\n", s->desired.cursor.y);
line_no = (int)s->desired.line_count();
s->desired.add_line();
@ -863,7 +863,7 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width,
// Compute the width of the autosuggestion at all possible truncation offsets.
std::vector<size_t> autosuggest_truncated_widths;
autosuggest_truncated_widths.reserve(1 + wcslen(autosuggestion));
autosuggest_truncated_widths.reserve(1 + std::wcslen(autosuggestion));
size_t autosuggest_total_width = 0;
for (size_t i = 0; autosuggestion[i] != L'\0'; i++) {
autosuggest_truncated_widths.push_back(autosuggest_total_width);

View file

@ -12,7 +12,7 @@
#include <stddef.h>
#include <sys/stat.h>
#include <wchar.h>
#include <cwchar>
#include <algorithm>
#include <cstddef>

View file

@ -5,7 +5,7 @@
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <string>
@ -223,7 +223,7 @@ tok_t tokenizer_t::read_string() {
this->buff = end;
} else {
const wchar_t *error_loc = this->buff;
this->buff += wcslen(this->buff);
this->buff += std::wcslen(this->buff);
if ((!this->accept_unfinished)) {
return this->call_error(tokenizer_error_t::unterminated_quote, buff_start,
error_loc);
@ -637,7 +637,7 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c) {
bool move_word_state_machine_t::is_path_component_character(wchar_t c) {
// Always treat separators as first. All this does is ensure that we treat ^ as a string
// character instead of as stderr redirection, which I hypothesize is usually what is desired.
return tok_is_string_character(c, true) && !wcschr(L"/={,}'\"", c);
return tok_is_string_character(c, true) && !std::wcschr(L"/={,}'\"", c);
}
bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
@ -650,7 +650,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
s_end
};
// fwprintf(stdout, L"state %d, consume '%lc'\n", state, c);
// std::fwprintf(stdout, L"state %d, consume '%lc'\n", state, c);
bool consumed = false;
while (state != s_end && !consumed) {
switch (state) {

View file

@ -4,7 +4,7 @@
#include <errno.h>
#include <stddef.h>
#include <sys/time.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include "common.h"
@ -85,7 +85,7 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) {
// names are literally identical because that won't occur given how this function is
// used. And even if it were to occur (due to being reused in some other context) it
// would be so rare that it isn't worth optimizing for.
retval = wcscmp(orig_a, orig_b);
retval = std::wcscmp(orig_a, orig_b);
return retval < 0 ? -1 : retval == 0 ? 0 : 1;
}
return -1; // string a is a prefix of b and b is longer

View file

@ -39,7 +39,7 @@ wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype) {
return input.substr(0, max_len);
}
if (etype == ellipsis_type::Prettiest) {
return input.substr(0, max_len - wcslen(ellipsis_str)).append(ellipsis_str);
return input.substr(0, max_len - std::wcslen(ellipsis_str)).append(ellipsis_str);
}
wcstring output = input.substr(0, max_len - 1);
output.push_back(ellipsis_char);

View file

@ -39,7 +39,7 @@
#include "config.h" // IWYU pragma: keep
#include <stdio.h>
#include <wchar.h>
#include <cwchar>
#include <string.h>
// This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves
@ -159,7 +159,7 @@ int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity)
// The special ARGV-element `--' means premature end of options. Skip it like a null option,
// then exchange with previous non-options as if it were an option, then skip everything
// else like a non-option.
if (woptind != argc && !wcscmp(argv[woptind], L"--")) {
if (woptind != argc && !std::wcscmp(argv[woptind], L"--")) {
woptind++;
if (first_nonopt != last_nonopt && last_nonopt != woptind) {
@ -198,14 +198,14 @@ int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity)
int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
// Look at and handle the next short option-character.
wchar_t c = *nextchar++;
const wchar_t *temp = wcschr(shortopts, c);
const wchar_t *temp = std::wcschr(shortopts, c);
// Increment `woptind' when we start to process its last character.
if (*nextchar == '\0') ++woptind;
if (temp == NULL || c == ':') {
if (wopterr) {
fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
}
woptopt = c;
@ -236,7 +236,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
} else if (woptind == argc) {
if (wopterr) {
// 1003.2 specifies the format of this message.
fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
std::fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
(wint_t)c);
}
woptopt = c;
@ -263,14 +263,14 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
else {
if (wopterr) {
if (argv[woptind - 1][1] == '-') // --option
fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"), argv[0],
std::fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"), argv[0],
pfound->name);
else
// +option or -option
fwprintf(stderr, _(L"%ls: Option '%lc%ls' doesn't allow an argument\n"),
std::fwprintf(stderr, _(L"%ls: Option '%lc%ls' doesn't allow an argument\n"),
argv[0], argv[woptind - 1][0], pfound->name);
}
nextchar += wcslen(nextchar);
nextchar += std::wcslen(nextchar);
*retval = '?';
return;
}
@ -279,15 +279,15 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio
woptarg = argv[woptind++];
else {
if (wopterr)
fwprintf(stderr, _(L"%ls: Option '%ls' requires an argument\n"), argv[0],
std::fwprintf(stderr, _(L"%ls: Option '%ls' requires an argument\n"), argv[0],
argv[woptind - 1]);
nextchar += wcslen(nextchar);
nextchar += std::wcslen(nextchar);
*retval = missing_arg_return_colon ? ':' : '?';
return;
}
}
nextchar += wcslen(nextchar);
nextchar += std::wcslen(nextchar);
if (longind != NULL) *longind = option_index;
if (pfound->flag) {
*(pfound->flag) = pfound->val;
@ -306,7 +306,7 @@ const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption
// Test all long options for either exact match or abbreviated matches.
for (const struct woption *p = longopts; p->name; p++, option_index++) {
if (!wcsncmp(p->name, nextchar, nameend - nextchar)) {
if (!std::wcsncmp(p->name, nextchar, nameend - nextchar)) {
if ((unsigned int)(nameend - nextchar) == (unsigned int)wcslen(p->name)) {
// Exact match found.
pfound = p;
@ -342,9 +342,9 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio
if (ambig && !exact) {
if (wopterr) {
fwprintf(stderr, _(L"%ls: Option '%ls' is ambiguous\n"), argv[0], argv[woptind]);
std::fwprintf(stderr, _(L"%ls: Option '%ls' is ambiguous\n"), argv[0], argv[woptind]);
}
nextchar += wcslen(nextchar);
nextchar += std::wcslen(nextchar);
woptind++;
*retval = '?';
return true;
@ -358,13 +358,13 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio
// Can't find it as a long option. If this is not getopt_long_only, or the option starts
// with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a
// short option.
if (!long_only || argv[woptind][1] == '-' || wcschr(shortopts, *nextchar) == NULL) {
if (!long_only || argv[woptind][1] == '-' || std::wcschr(shortopts, *nextchar) == NULL) {
if (wopterr) {
if (argv[woptind][1] == '-') // --option
fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
std::fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
else
// +option or -option
fwprintf(stderr, _(L"%ls: Unrecognized option '%lc%ls'\n"), argv[0],
std::fwprintf(stderr, _(L"%ls: Unrecognized option '%lc%ls'\n"), argv[0],
argv[woptind][0], nextchar);
}
nextchar = (wchar_t *)L"";
@ -441,7 +441,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
// This distinction seems to be the most useful approach.
if (longopts != NULL &&
(argv[woptind][1] == '-' ||
(long_only && (argv[woptind][2] || !wcschr(shortopts, argv[woptind][1]))))) {
(long_only && (argv[woptind][2] || !std::wcschr(shortopts, argv[woptind][1]))))) {
int retval;
if (_handle_long_opt(argc, argv, longopts, longind, long_only, &retval)) return retval;
}

View file

@ -8,7 +8,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <memory>
#include <string>
@ -82,7 +82,7 @@ static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) {
bool wildcard_has(const wchar_t *str, bool internal) {
assert(str != NULL);
return wildcard_has_impl(str, wcslen(str), internal);
return wildcard_has_impl(str, std::wcslen(str), internal);
}
bool wildcard_has(const wcstring &str, bool internal) {
@ -99,9 +99,9 @@ static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const
bool leading_dots_fail_to_match) {
// Hackish fix for issue #270. Prevent wildcards from matching . or .., but we must still allow
// literal matches.
if (leading_dots_fail_to_match && (!wcscmp(str, L".") || !wcscmp(str, L".."))) {
if (leading_dots_fail_to_match && (!std::wcscmp(str, L".") || !std::wcscmp(str, L".."))) {
// The string is '.' or '..'. Return true if the wildcard exactly matches.
return wcscmp(str, wc) ? fuzzy_match_none : fuzzy_match_exact;
return std::wcscmp(str, wc) ? fuzzy_match_none : fuzzy_match_exact;
}
// Near Linear implementation as proposed here https://research.swtch.com/glob.
@ -235,8 +235,8 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
// If we are not replacing the token, be careful to only store the part of the string after
// the wildcard.
assert(!full_replacement || wcslen(wc) <= wcslen(str));
wcstring out_completion = full_replacement ? params.orig : str + wcslen(wc);
assert(!full_replacement || std::wcslen(wc) <= std::wcslen(str));
wcstring out_completion = full_replacement ? params.orig : str + std::wcslen(wc);
wcstring out_desc = resolve_description(params.orig, &out_completion, params.expand_flags,
params.desc_func);
@ -248,7 +248,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
} else if (next_wc_char_pos > 0) {
// Here we have a non-wildcard prefix. Note that we don't do fuzzy matching for stuff before
// a wildcard, so just do case comparison and then recurse.
if (wcsncmp(str, wc, next_wc_char_pos) == 0) {
if (std::wcsncmp(str, wc, next_wc_char_pos) == 0) {
// Normal match.
return wildcard_complete_internal(str + next_wc_char_pos, wc + next_wc_char_pos, params,
flags, out);
@ -822,8 +822,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
}
// Get the current segment and compute interesting properties about it.
const size_t wc_len = wcslen(wc);
const wchar_t *const next_slash = wcschr(wc, L'/');
const size_t wc_len = std::wcslen(wc);
const wchar_t *const next_slash = std::wcschr(wc, L'/');
const bool is_last_segment = (next_slash == NULL);
const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len;
const wcstring wc_segment = wcstring(wc, wc_segment_len);

View file

@ -19,7 +19,7 @@
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
#include <cwchar>
#include <wctype.h>
#include <string>
@ -260,9 +260,9 @@ int wunlink(const wcstring &file_name) {
void wperror(const wchar_t *s) {
int e = errno;
if (s[0] != L'\0') {
fwprintf(stderr, L"%ls: ", s);
std::fwprintf(stderr, L"%ls: ", s);
}
fwprintf(stderr, L"%s\n", strerror(e));
std::fwprintf(stderr, L"%s\n", strerror(e));
}
int make_fd_nonblocking(int fd) {
@ -604,7 +604,7 @@ int fish_iswgraph(wint_t wc) {
/// Convenience variants on fish_wcwswidth().
///
/// See fallback.h for the normal definitions.
int fish_wcswidth(const wchar_t *str) { return fish_wcswidth(str, wcslen(str)); }
int fish_wcswidth(const wchar_t *str) { return fish_wcswidth(str, std::wcslen(str)); }
/// Convenience variants on fish_wcwswidth().
///
@ -635,7 +635,7 @@ int fish_wcstoi(const wchar_t *str, const wchar_t **endptr, int base) {
errno = 0;
wchar_t *_endptr;
long result = wcstol(str, &_endptr, base);
long result = std::wcstol(str, &_endptr, base);
if (result > INT_MAX) {
result = INT_MAX;
errno = ERANGE;
@ -673,7 +673,7 @@ long fish_wcstol(const wchar_t *str, const wchar_t **endptr, int base) {
errno = 0;
wchar_t *_endptr;
long result = wcstol(str, &_endptr, base);
long result = std::wcstol(str, &_endptr, base);
while (iswspace(*_endptr)) ++_endptr; // skip trailing whitespace
if (!errno && *_endptr) {
if (_endptr == str) {
@ -704,7 +704,7 @@ long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr, int base) {
errno = 0;
wchar_t *_endptr;
long long result = wcstoll(str, &_endptr, base);
long long result = std::wcstoll(str, &_endptr, base);
while (iswspace(*_endptr)) ++_endptr; // skip trailing whitespace
if (!errno && *_endptr) {
if (_endptr == str) {
@ -737,7 +737,7 @@ unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr, int
errno = 0;
wchar_t *_endptr;
unsigned long long result = wcstoull(str, &_endptr, base);
unsigned long long result = std::wcstoull(str, &_endptr, base);
while (iswspace(*_endptr)) ++_endptr; // skip trailing whitespace
if (!errno && *_endptr) {
if (_endptr == str) {
@ -755,7 +755,7 @@ unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr, int
double fish_wcstod(const wchar_t *str, wchar_t **endptr) {
// The "fast path." If we're all ASCII and we fit inline, use strtod().
char narrow[128];
size_t len = wcslen(str);
size_t len = std::wcslen(str);
size_t len_plus_0 = 1 + len;
auto is_digit = [](wchar_t c) { return '0' <= c && c <= '9'; };
if (len_plus_0 <= sizeof narrow && std::all_of(str, str + len, is_digit)) {