avoid struct name clashes

Running the tests on travis revealed that some compilers (or at least
with some options) call the wrong struct constructor if there is more
than one struct with the same name but differing definitions.
This commit is contained in:
Kurtis Rader 2017-06-15 17:57:37 -07:00
parent a114492223
commit 37b8cfaeba
17 changed files with 171 additions and 171 deletions

View File

@ -102,9 +102,6 @@ class builtin_commandline_scoped_transient_t {
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
const wcstring &contents, int definition_line_offset, wcstring *out_err);
void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
output_stream_t &b);
int builtin_count_args(const wchar_t *const *argv);

View File

@ -38,7 +38,7 @@ static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) {
int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts_help_only opts;
cmd_opts_help_only opts;
int optind;
int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);

View File

@ -19,15 +19,14 @@
#include "wutil.h" // IWYU pragma: keep
enum { BIND_INSERT, BIND_ERASE, BIND_KEY_NAMES, BIND_FUNCTION_NAMES };
struct cmd_opts {
int mode = BIND_INSERT;
int res = STATUS_CMD_OK;
bool all = false;
bool use_terminfo = false;
const wchar_t *bind_mode = DEFAULT_BIND_MODE;
struct bind_cmd_opts_t {
bool print_help = false;
bool bind_mode_given = false;
bool list_modes = false;
bool print_help = false;
bool all = false;
bool use_terminfo = false;
int mode = BIND_INSERT;
const wchar_t *bind_mode = DEFAULT_BIND_MODE;
const wchar_t *sets_bind_mode = L"";
};
@ -212,16 +211,16 @@ static bool builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int
return res;
}
static bool builtin_bind_insert(struct cmd_opts *opts, int optind, int argc, wchar_t **argv,
static bool builtin_bind_insert(bind_cmd_opts_t &opts, int optind, int argc, wchar_t **argv,
io_streams_t &streams) {
wchar_t *cmd = argv[0];
int arg_count = argc - optind;
if (arg_count == 0) {
builtin_bind_list(opts->bind_mode_given ? opts->bind_mode : NULL, streams);
builtin_bind_list(opts.bind_mode_given ? opts.bind_mode : NULL, streams);
} else if (arg_count == 1) {
wcstring seq;
if (opts->use_terminfo) {
if (opts.use_terminfo) {
if (!get_terminfo_sequence(argv[optind], &seq, streams)) {
// get_terminfo_sequence already printed the error.
return true;
@ -230,9 +229,9 @@ static bool builtin_bind_insert(struct cmd_opts *opts, int optind, int argc, wch
seq = argv[optind];
}
if (!builtin_bind_list_one(seq, opts->bind_mode, streams)) {
if (!builtin_bind_list_one(seq, opts.bind_mode, streams)) {
wcstring eseq = escape_string(argv[optind], 0);
if (opts->use_terminfo) {
if (opts.use_terminfo) {
streams.err.append_format(_(L"%ls: No binding found for key '%ls'\n"), cmd,
eseq.c_str());
} else {
@ -243,7 +242,7 @@ static bool builtin_bind_insert(struct cmd_opts *opts, int optind, int argc, wch
}
} else {
if (builtin_bind_add(argv[optind], argv + (optind + 1), argc - (optind + 1),
opts->bind_mode, opts->sets_bind_mode, opts->use_terminfo, streams)) {
opts.bind_mode, opts.sets_bind_mode, opts.use_terminfo, streams)) {
return true;
}
}
@ -267,7 +266,7 @@ static void builtin_bind_list_modes(io_streams_t &streams) {
}
}
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"aehkKfM:Lm:";
@ -287,27 +286,27 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case L'a': {
opts->all = true;
opts.all = true;
break;
}
case L'e': {
opts->mode = BIND_ERASE;
opts.mode = BIND_ERASE;
break;
}
case L'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case L'k': {
opts->use_terminfo = true;
opts.use_terminfo = true;
break;
}
case L'K': {
opts->mode = BIND_KEY_NAMES;
opts.mode = BIND_KEY_NAMES;
break;
}
case L'f': {
opts->mode = BIND_FUNCTION_NAMES;
opts.mode = BIND_FUNCTION_NAMES;
break;
}
case L'M': {
@ -315,8 +314,8 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
streams.err.append_format(BUILTIN_ERR_BIND_MODE, cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
opts->bind_mode = w.woptarg;
opts->bind_mode_given = true;
opts.bind_mode = w.woptarg;
opts.bind_mode_given = true;
break;
}
case L'm': {
@ -324,11 +323,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
streams.err.append_format(BUILTIN_ERR_BIND_MODE, cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
opts->sets_bind_mode = w.woptarg;
opts.sets_bind_mode = w.woptarg;
break;
}
case L'L': {
opts->list_modes = true;
opts.list_modes = true;
return STATUS_CMD_OK;
}
case L'?': {
@ -350,10 +349,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
bind_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.list_modes) {
@ -375,7 +374,7 @@ int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
break;
}
case BIND_INSERT: {
if (builtin_bind_insert(&opts, optind, argc, argv, streams)) {
if (builtin_bind_insert(opts, optind, argc, argv, streams)) {
return STATUS_CMD_ERROR;
}
break;

View File

@ -14,13 +14,13 @@
#include "wutil.h" // IWYU pragma: keep
enum { UNSET, GLOBAL, LOCAL };
struct cmd_opts {
struct block_cmd_opts_t {
int scope = UNSET;
bool erase = false;
bool print_help = false;
};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"eghl";
@ -35,19 +35,19 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case 'g': {
opts->scope = GLOBAL;
opts.scope = GLOBAL;
break;
}
case 'l': {
opts->scope = LOCAL;
opts.scope = LOCAL;
break;
}
case 'e': {
opts->erase = true;
opts.erase = true;
break;
}
case '?': {
@ -69,10 +69,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
block_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -14,7 +14,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct builtin_cmd_opts_t {
bool print_help = false;
bool list_names = false;
};
@ -22,7 +22,7 @@ static const wchar_t *short_options = L"hn";
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'}, {L"names", no_argument, NULL, 'n'}, {NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -30,11 +30,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case 'n': {
opts->list_names = true;
opts.list_names = true;
break;
}
case '?': {
@ -58,10 +58,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
builtin_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -12,7 +12,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct command_cmd_opts_t {
bool print_help = false;
bool find_path = false;
bool quiet = false;
@ -23,7 +23,7 @@ static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{L"search", no_argument, NULL, 's'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -31,16 +31,16 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case 'q': {
opts->quiet = true;
opts.quiet = true;
break;
}
case 's': // -s and -v are aliases
case 'v': {
opts->find_path = true;
opts.find_path = true;
break;
}
case '?': {
@ -63,10 +63,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
command_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -12,7 +12,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct contains_cmd_opts_t {
bool print_help = false;
bool print_index = false;
};
@ -20,7 +20,7 @@ static const wchar_t *short_options = L"+hi";
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'}, {L"index", no_argument, NULL, 'i'}, {NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -28,11 +28,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case 'i': {
opts->print_index = true;
opts.print_index = true;
break;
}
case '?': {
@ -55,10 +55,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
contains_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -12,7 +12,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct echo_cmd_opts_t {
bool print_help = false;
bool print_newline = true;
bool print_spaces = true;
@ -21,7 +21,7 @@ struct cmd_opts {
static const wchar_t *short_options = L"+Eens";
static const struct woption *long_options = NULL;
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
UNUSED(parser);
UNUSED(streams);
@ -30,19 +30,19 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'n': {
opts->print_newline = false;
opts.print_newline = false;
break;
}
case 'e': {
opts->interpret_special_chars = true;
opts.interpret_special_chars = true;
break;
}
case 's': {
opts->print_spaces = false;
opts.print_spaces = false;
break;
}
case 'E': {
opts->interpret_special_chars = false;
opts.interpret_special_chars = false;
break;
}
case '?': {
@ -175,9 +175,9 @@ static bool builtin_echo_parse_numeric_sequence(const wchar_t *str, size_t *cons
int builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
echo_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
// The special character \c can be used to indicate no more output.

View File

@ -14,14 +14,14 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct exit_cmd_opts_t {
bool print_help = false;
};
static const wchar_t *short_options = L"h";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
UNUSED(parser);
UNUSED(streams);
@ -31,7 +31,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) { //!OCLINT(too few branches)
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case '?': {
@ -56,10 +56,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_exit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
exit_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -24,10 +24,10 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct function_cmd_opts_t {
bool print_help = false;
bool shadow_scope = true;
wchar_t *desc = NULL;
wcstring description = L"";
std::vector<event_t> events;
wcstring_list_t named_arguments;
wcstring_list_t inherit_vars;
@ -51,7 +51,7 @@ static const struct woption long_options[] = {
{L"inherit-variable", required_argument, NULL, 'V'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams,
wcstring *out_err) {
wchar_t *cmd = argv[0];
@ -60,7 +60,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'd': {
opts->desc = w.woptarg;
opts.description = w.woptarg;
break;
}
case 's': {
@ -69,7 +69,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
append_format(*out_err, _(L"%ls: Unknown signal '%ls'"), cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
opts->events.push_back(event_t::signal_event(sig));
opts.events.push_back(event_t::signal_event(sig));
break;
}
case 'v': {
@ -78,11 +78,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
return STATUS_INVALID_ARGS;
}
opts->events.push_back(event_t::variable_event(w.woptarg));
opts.events.push_back(event_t::variable_event(w.woptarg));
break;
}
case 'e': {
opts->events.push_back(event_t::generic_event(w.woptarg));
opts.events.push_back(event_t::generic_event(w.woptarg));
break;
}
case 'j':
@ -127,19 +127,19 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
e.type = EVENT_EXIT;
e.param1.pid = (opt == 'j' ? -1 : 1) * abs(pid);
}
opts->events.push_back(e);
opts.events.push_back(e);
break;
}
case 'a': {
opts->named_arguments.push_back(w.woptarg);
opts.named_arguments.push_back(w.woptarg);
break;
}
case 'S': {
opts->shadow_scope = false;
opts.shadow_scope = false;
break;
}
case 'w': {
opts->wrap_targets.push_back(w.woptarg);
opts.wrap_targets.push_back(w.woptarg);
break;
}
case 'V': {
@ -147,11 +147,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
append_format(*out_err, BUILTIN_ERR_VARNAME, cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
opts->inherit_vars.push_back(w.woptarg);
opts.inherit_vars.push_back(w.woptarg);
break;
}
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case ':': {
@ -217,7 +217,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
wcstring function_name;
struct cmd_opts opts;
function_cmd_opts_t opts;
// A valid function name has to be the first argument.
int retval = validate_function_name(argc, argv, function_name, cmd, out_err);
@ -226,7 +226,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
argc--;
int optind;
retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams, out_err);
retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams, out_err);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
@ -249,7 +249,8 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
// We have what we need to actually define the function.
function_data_t d;
d.name = function_name;
if (opts.desc) d.description = opts.desc;
if (!opts.description.empty()) d.description = opts.description;
//d.description = opts.description;
d.events.swap(opts.events);
d.shadow_scope = opts.shadow_scope;
d.named_arguments.swap(opts.named_arguments);

View File

@ -2,8 +2,11 @@
#ifndef FISH_BUILTIN_FUNCTION_H
#define FISH_BUILTIN_FUNCTION_H
#include "common.h"
class parser_t;
struct io_streams_t;
int builtin_function(parser_t &parser, io_streams_t &streams, wchar_t **argv);
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
const wcstring &contents, int definition_line_offset, wcstring *out_err);
#endif

View File

@ -26,7 +26,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct functions_cmd_opts_t {
bool print_help = false;
bool erase = false;
bool list = false;
@ -45,8 +45,7 @@ static const struct woption long_options[] = {
{L"copy", no_argument, NULL, 'c'}, {L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts,
int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -54,39 +53,39 @@ static int parse_cmd_opts(struct cmd_opts *opts,
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 'v': {
opts->verbose = true;
opts.verbose = true;
break;
}
case 'e': {
opts->erase = true;
opts.erase = true;
break;
}
case 'D': {
opts->report_metadata = true;
opts.report_metadata = true;
break;
}
case 'd': {
opts->description = w.woptarg;
opts.description = w.woptarg;
break;
}
case 'n': {
opts->list = true;
opts.list = true;
break;
}
case 'a': {
opts->show_hidden = true;
opts.show_hidden = true;
break;
}
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case 'q': {
opts->query = true;
opts.query = true;
break;
}
case 'c': {
opts->copy = true;
opts.copy = true;
break;
}
case '?': {
@ -257,10 +256,10 @@ static int report_function_metadata(const wchar_t *funcname, bool verbose, io_st
int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
functions_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -27,7 +27,7 @@ const enum_map<hist_cmd_t> hist_enum_map[] = {{HIST_CLEAR, L"clear"}, {HIST_DE
{HIST_SEARCH, L"search"}, {HIST_UNDEF, NULL}};
#define hist_enum_map_len (sizeof hist_enum_map / sizeof *hist_enum_map)
struct cmd_opts {
struct history_cmd_opts_t {
bool print_help = false;
hist_cmd_t hist_cmd = HIST_UNDEF;
history_search_type_t search_type = (history_search_type_t)-1;
@ -92,7 +92,7 @@ static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t su
break; \
}
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -100,60 +100,60 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 1: {
if (!set_hist_cmd(cmd, &opts->hist_cmd, HIST_DELETE, streams)) {
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_DELETE, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 2: {
if (!set_hist_cmd(cmd, &opts->hist_cmd, HIST_SEARCH, streams)) {
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_SEARCH, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 3: {
if (!set_hist_cmd(cmd, &opts->hist_cmd, HIST_SAVE, streams)) {
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_SAVE, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 4: {
if (!set_hist_cmd(cmd, &opts->hist_cmd, HIST_CLEAR, streams)) {
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_CLEAR, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 5: {
if (!set_hist_cmd(cmd, &opts->hist_cmd, HIST_MERGE, streams)) {
if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_MERGE, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'C': {
opts->case_sensitive = true;
opts.case_sensitive = true;
break;
}
case 'p': {
opts->search_type = HISTORY_SEARCH_TYPE_PREFIX;
opts->history_search_type_defined = true;
opts.search_type = HISTORY_SEARCH_TYPE_PREFIX;
opts.history_search_type_defined = true;
break;
}
case 'c': {
opts->search_type = HISTORY_SEARCH_TYPE_CONTAINS;
opts->history_search_type_defined = true;
opts.search_type = HISTORY_SEARCH_TYPE_CONTAINS;
opts.history_search_type_defined = true;
break;
}
case 'e': {
opts->search_type = HISTORY_SEARCH_TYPE_EXACT;
opts->history_search_type_defined = true;
opts.search_type = HISTORY_SEARCH_TYPE_EXACT;
opts.history_search_type_defined = true;
break;
}
case 't': {
opts->show_time_format = w.woptarg ? w.woptarg : L"# %c%n";
opts.show_time_format = w.woptarg ? w.woptarg : L"# %c%n";
break;
}
case 'n': {
opts->max_items = fish_wcstol(w.woptarg);
opts.max_items = fish_wcstol(w.woptarg);
if (errno) {
streams.err.append_format(_(L"%ls: max value '%ls' is not a valid number\n"),
cmd, w.woptarg);
@ -162,11 +162,11 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
break;
}
case 'z': {
opts->null_terminate = true;
opts.null_terminate = true;
break;
}
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case ':': {
@ -175,7 +175,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
}
case '?': {
// Try to parse it as a number; e.g., "-123".
opts->max_items = fish_wcstol(argv[w.woptind - 1] + 1);
opts.max_items = fish_wcstol(argv[w.woptind - 1] + 1);
if (errno) {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
@ -198,10 +198,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
history_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -29,7 +29,7 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct read_cmd_opts_t {
bool print_help = false;
int place = ENV_USER;
wcstring prompt_cmd;
@ -64,7 +64,7 @@ static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'
{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -72,47 +72,47 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case L'x': {
opts->place |= ENV_EXPORT;
opts.place |= ENV_EXPORT;
break;
}
case L'g': {
opts->place |= ENV_GLOBAL;
opts.place |= ENV_GLOBAL;
break;
}
case L'l': {
opts->place |= ENV_LOCAL;
opts.place |= ENV_LOCAL;
break;
}
case L'U': {
opts->place |= ENV_UNIVERSAL;
opts.place |= ENV_UNIVERSAL;
break;
}
case L'u': {
opts->place |= ENV_UNEXPORT;
opts.place |= ENV_UNEXPORT;
break;
}
case L'p': {
opts->prompt = w.woptarg;
opts.prompt = w.woptarg;
break;
}
case L'P': {
opts->prompt_str = w.woptarg;
opts.prompt_str = w.woptarg;
break;
}
case L'R': {
opts->right_prompt = w.woptarg;
opts.right_prompt = w.woptarg;
break;
}
case L'c': {
opts->commandline = w.woptarg;
opts.commandline = w.woptarg;
break;
}
case L'm': {
opts->mode_name = w.woptarg;
opts.mode_name = w.woptarg;
break;
}
case L'n': {
opts->nchars = fish_wcstoi(w.woptarg);
opts.nchars = fish_wcstoi(w.woptarg);
if (errno) {
if (errno == ERANGE) {
streams.err.append_format(_(L"%ls: Argument '%ls' is out of range\n"), cmd,
@ -129,23 +129,23 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
break;
}
case 's': {
opts->shell = true;
opts.shell = true;
break;
}
case 'a': {
opts->array = true;
opts.array = true;
break;
}
case L'i': {
opts->silent = true;
opts.silent = true;
break;
}
case L'z': {
opts->split_null = true;
opts.split_null = true;
break;
}
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case ':': {
@ -321,10 +321,10 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int argc = builtin_count_args(argv);
wcstring buff;
int exit_res = STATUS_CMD_OK;
struct cmd_opts opts;
read_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -14,14 +14,14 @@
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
struct return_cmd_opts_t {
bool print_help = false;
};
static const wchar_t *short_options = L"h";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
UNUSED(parser);
UNUSED(streams);
@ -31,7 +31,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) { //!OCLINT(too few branches)
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case '?': {
@ -56,10 +56,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_return(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
return_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {

View File

@ -70,7 +70,7 @@ int job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd, io_streams_t &str
return -1;
}
struct cmd_opts {
struct status_cmd_opts_t {
bool print_help = false;
status_cmd_t status_cmd = STATUS_UNDEF;
int new_job_control_mode = -1;
@ -96,11 +96,11 @@ static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
/// Remember the status subcommand and disallow selecting more than one status subcommand.
static bool set_status_cmd(wchar_t *const cmd, status_cmd_t *status_cmd, status_cmd_t sub_cmd,
static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd,
io_streams_t &streams) {
if (*status_cmd != STATUS_UNDEF) {
if (opts.status_cmd != STATUS_UNDEF) {
wchar_t err_text[1024];
const wchar_t *subcmd_str1 = enum_to_str(*status_cmd, status_enum_map);
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),
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
@ -109,11 +109,11 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_t *status_cmd, status_
return false;
}
*status_cmd = sub_cmd;
opts.status_cmd = sub_cmd;
return true;
}
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
@ -121,78 +121,78 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 1: {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_FULL_JOB_CTRL, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_FULL_JOB_CTRL, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 2: {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_INTERACTIVE_JOB_CTRL,
if (!set_status_cmd(cmd, opts, STATUS_IS_INTERACTIVE_JOB_CTRL,
streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 3: {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_NO_JOB_CTRL, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_NO_JOB_CTRL, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'c': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_COMMAND_SUB, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_COMMAND_SUB, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'b': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_BLOCK, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_BLOCK, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'i': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_INTERACTIVE, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_INTERACTIVE, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'l': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_IS_LOGIN, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_IS_LOGIN, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'f': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_CURRENT_FILENAME, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_CURRENT_FILENAME, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'n': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_CURRENT_LINE_NUMBER, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_CURRENT_LINE_NUMBER, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'j': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_SET_JOB_CONTROL, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_SET_JOB_CONTROL, streams)) {
return STATUS_CMD_ERROR;
}
opts->new_job_control_mode = job_control_str_to_mode(w.woptarg, cmd, streams);
if (opts->new_job_control_mode == -1) {
opts.new_job_control_mode = job_control_str_to_mode(w.woptarg, cmd, streams);
if (opts.new_job_control_mode == -1) {
return STATUS_CMD_ERROR;
}
break;
}
case 't': {
if (!set_status_cmd(cmd, &opts->status_cmd, STATUS_PRINT_STACK_TRACE, streams)) {
if (!set_status_cmd(cmd, opts, STATUS_PRINT_STACK_TRACE, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 'h': {
opts->print_help = true;
opts.print_help = true;
break;
}
case ':': {
@ -218,10 +218,10 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
struct cmd_opts opts;
status_cmd_opts_t opts;
int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
@ -234,7 +234,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (optind < argc) {
status_cmd_t subcmd = str_to_enum(argv[optind], status_enum_map, status_enum_map_len);
if (subcmd != STATUS_UNDEF) {
if (!set_status_cmd(cmd, &opts.status_cmd, subcmd, streams)) {
if (!set_status_cmd(cmd, opts, subcmd, streams)) {
return STATUS_CMD_ERROR;
}
optind++;

View File

@ -24,6 +24,7 @@
#include <vector>
#include "builtin.h"
#include "builtin_function.h"
#include "common.h"
#include "complete.h"
#include "env.h"