diff --git a/src/builtin_bind.cpp b/src/builtin_bind.cpp index 5d9c7fb00..9bbbf0d5d 100644 --- a/src/builtin_bind.cpp +++ b/src/builtin_bind.cpp @@ -332,7 +332,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc return STATUS_CMD_OK; } case L'?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { diff --git a/src/builtin_builtin.cpp b/src/builtin_builtin.cpp index 3b933e928..f4b0aec73 100644 --- a/src/builtin_builtin.cpp +++ b/src/builtin_builtin.cpp @@ -1,14 +1,16 @@ // Implementation of the builtin builtin. #include "config.h" // IWYU pragma: keep -#include +#include + +#include +#include #include "builtin.h" #include "builtin_builtin.h" #include "common.h" #include "fallback.h" // IWYU pragma: keep #include "io.h" -#include "path.h" #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep @@ -69,7 +71,7 @@ int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (opts.list_names) { wcstring_list_t names = builtin_get_names(); - sort(names.begin(), names.end()); + std::sort(names.begin(), names.end()); for (size_t i = 0; i < names.size(); i++) { const wchar_t *el = names.at(i).c_str(); diff --git a/src/builtin_cd.cpp b/src/builtin_cd.cpp index 380d06b83..854c04e6b 100644 --- a/src/builtin_cd.cpp +++ b/src/builtin_cd.cpp @@ -36,7 +36,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t return STATUS_CMD_OK; } case '?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { @@ -64,7 +64,7 @@ int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (opts.print_help) { builtin_print_help(parser, streams, cmd, streams.out); - return STATUS_INVALID_ARGS; + return STATUS_CMD_OK; } env_var_t dir_in; diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index b46f7b857..1bd5640b1 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -167,6 +167,7 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs /// The commandline builtin. It is used for specifying a new value for the commandline. int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) { + wchar_t *cmd = argv[0]; int buffer_part = 0; int cut_at_cursor = 0; @@ -205,7 +206,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) streams.err.append(argv[0]); streams.err.append(L": Can not set commandline in non-interactive mode\n"); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_CMD_ERROR; } @@ -299,11 +300,11 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) break; } case 'h': { - builtin_print_help(parser, streams, argv[0], streams.out); + builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } case L'?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { @@ -320,13 +321,13 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode || paging_mode) { streams.err.append_format(BUILTIN_ERR_COMBO, argv[0]); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } if (argc == w.woptind) { streams.err.append_format(BUILTIN_ERR_MISSING, argv[0]); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } @@ -337,9 +338,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) // the queue of unused keypresses. input_queue_ch(c); } else { - streams.err.append_format(_(L"%ls: Unknown input function '%ls'"), argv[0], - argv[i]); - builtin_print_help(parser, streams, argv[0], streams.err); + streams.err.append_format(_(L"%ls: Unknown input function '%ls'"), cmd, argv[i]); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } } @@ -359,30 +359,30 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) // Check for invalid switch combinations. if ((search_mode || line_mode || cursor_mode || paging_mode) && (argc - w.woptind > 1)) { streams.err.append_format(L"%ls: Too many arguments", argv[0]); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode || paging_mode)) { streams.err.append_format(BUILTIN_ERR_COMBO, argv[0]); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } if ((tokenize || cut_at_cursor) && (argc - w.woptind)) { streams.err.append_format( - BUILTIN_ERR_COMBO2, argv[0], + BUILTIN_ERR_COMBO2, cmd, L"--cut-at-cursor and --tokenize can not be used when setting the commandline"); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } if (append_mode && !(argc - w.woptind)) { streams.err.append_format( - BUILTIN_ERR_COMBO2, argv[0], + BUILTIN_ERR_COMBO2, cmd, L"insertion mode switches can not be used when not in insertion mode"); - builtin_print_help(parser, streams, argv[0], streams.err); + builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } @@ -399,8 +399,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) if (argc - w.woptind) { long new_pos = fish_wcstol(argv[w.woptind]); if (errno) { - streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, argv[0], argv[w.woptind]); - builtin_print_help(parser, streams, argv[0], streams.err); + streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[w.woptind]); + builtin_print_help(parser, streams, cmd, streams.err); } current_buffer = reader_get_buffer(); diff --git a/src/builtin_contains.cpp b/src/builtin_contains.cpp index 9d9b27171..0766e18a1 100644 --- a/src/builtin_contains.cpp +++ b/src/builtin_contains.cpp @@ -63,7 +63,7 @@ int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (opts.print_help) { builtin_print_help(parser, streams, cmd, streams.out); - return STATUS_INVALID_ARGS; + return STATUS_CMD_OK; } wchar_t *needle = argv[optind]; diff --git a/src/builtin_emit.cpp b/src/builtin_emit.cpp index 5152c9d3a..f0c9da005 100644 --- a/src/builtin_emit.cpp +++ b/src/builtin_emit.cpp @@ -31,7 +31,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc return STATUS_CMD_OK; } case '?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { @@ -57,11 +57,11 @@ int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (opts.print_help) { builtin_print_help(parser, streams, cmd, streams.out); - return STATUS_INVALID_ARGS; + return STATUS_CMD_OK; } if (!argv[optind]) { - streams.err.append_format(L"%ls: expected event name\n", argv[0]); + streams.err.append_format(L"%ls: expected event name\n", cmd); return STATUS_INVALID_ARGS; } diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index 3ccdd5a4f..a1438417e 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -3,11 +3,11 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include #include "builtin.h" #include "builtin_function.h" @@ -19,6 +19,8 @@ #include "io.h" #include "parser.h" #include "parser_keywords.h" +#include "proc.h" +#include "signal.h" #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index 06aa3f376..eb5d71c0b 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -109,6 +109,7 @@ static void builtin_jobs_print(const job_t *j, int mode, int header, io_streams_ /// The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c. int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { + wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); int found = 0; int mode = JOBS_DEFAULT; @@ -141,11 +142,11 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { break; } case 'h': { - builtin_print_help(parser, streams, argv[0], streams.out); + builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } case '?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { @@ -173,7 +174,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { for (i = w.woptind; i < argc; i++) { int pid = fish_wcstoi(argv[i]); if (errno || pid < 0) { - streams.err.append_format(_(L"%ls: '%ls' is not a job\n"), argv[0], argv[i]); + streams.err.append_format(_(L"%ls: '%ls' is not a job\n"), cmd, argv[i]); return STATUS_INVALID_ARGS; } @@ -183,7 +184,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { builtin_jobs_print(j, mode, false, streams); found = 1; } else { - streams.err.append_format(_(L"%ls: No suitable job: %d\n"), argv[0], pid); + streams.err.append_format(_(L"%ls: No suitable job: %d\n"), cmd, pid); return STATUS_CMD_ERROR; } } diff --git a/src/builtin_random.cpp b/src/builtin_random.cpp index 80a00469d..6ada8bf9c 100644 --- a/src/builtin_random.cpp +++ b/src/builtin_random.cpp @@ -37,7 +37,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc return STATUS_CMD_OK; } case '?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 686194b0b..660a7d351 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -153,7 +153,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc return STATUS_INVALID_ARGS; } case L'?': { - builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { diff --git a/src/builtin_source.cpp b/src/builtin_source.cpp index 46df593d6..412f09a44 100644 --- a/src/builtin_source.cpp +++ b/src/builtin_source.cpp @@ -65,7 +65,7 @@ int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (opts.print_help) { builtin_print_help(parser, streams, cmd, streams.out); - return STATUS_INVALID_ARGS; + return STATUS_CMD_OK; } int fd; diff --git a/src/input.h b/src/input.h index 862b28bac..c1df12acd 100644 --- a/src/input.h +++ b/src/input.h @@ -9,7 +9,6 @@ #include "builtin_bind.h" #include "common.h" -#include "env.h" #define FISH_BIND_MODE_VAR L"fish_bind_mode"