From 59e90123ea03381badf8dcac80aa0ce371c7e579 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Tue, 13 Jun 2017 13:03:32 -0700 Subject: [PATCH] change naming convention for parsing opts --- src/builtin_bind.cpp | 12 ++++++------ src/builtin_block.cpp | 10 +++++----- src/builtin_emit.cpp | 17 ++++++++--------- src/builtin_functions.cpp | 12 ++++++------ src/builtin_history.cpp | 10 +++++----- src/builtin_random.cpp | 10 +++++----- src/builtin_read.cpp | 10 +++++----- src/builtin_status.cpp | 10 +++++----- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/builtin_bind.cpp b/src/builtin_bind.cpp index 60c0d4dea..5d9c7fb00 100644 --- a/src/builtin_bind.cpp +++ b/src/builtin_bind.cpp @@ -19,7 +19,7 @@ #include "wutil.h" // IWYU pragma: keep enum { BIND_INSERT, BIND_ERASE, BIND_KEY_NAMES, BIND_FUNCTION_NAMES }; -struct bind_opts { +struct cmd_opts { int mode = BIND_INSERT; int res = STATUS_CMD_OK; bool all = false; @@ -212,7 +212,7 @@ static bool builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int return res; } -static bool builtin_bind_insert(struct bind_opts *opts, int optind, int argc, wchar_t **argv, +static bool builtin_bind_insert(struct cmd_opts *opts, int optind, int argc, wchar_t **argv, io_streams_t &streams) { wchar_t *cmd = argv[0]; int arg_count = argc - optind; @@ -267,8 +267,8 @@ static void builtin_bind_list_modes(io_streams_t &streams) { } } -static int parse_bind_opts(struct bind_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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:"; static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, @@ -350,10 +350,10 @@ static int parse_bind_opts(struct bind_opts *opts, int *optind, //!OCLINT(high 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 bind_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_bind_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) { diff --git a/src/builtin_block.cpp b/src/builtin_block.cpp index b97e33c29..9abbe3445 100644 --- a/src/builtin_block.cpp +++ b/src/builtin_block.cpp @@ -14,14 +14,14 @@ #include "wutil.h" // IWYU pragma: keep enum { UNSET, GLOBAL, LOCAL }; -struct block_opts { +struct cmd_opts { int scope = UNSET; bool erase = false; bool print_help = false; }; -static int parse_block_opts(struct block_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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"; static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'}, @@ -69,10 +69,10 @@ static int parse_block_opts(struct block_opts *opts, int *optind, //!OCLINT(hig 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 block_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_block_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) { diff --git a/src/builtin_emit.cpp b/src/builtin_emit.cpp index a20cfb4d9..5152c9d3a 100644 --- a/src/builtin_emit.cpp +++ b/src/builtin_emit.cpp @@ -12,17 +12,16 @@ #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep -struct emit_opts { +struct cmd_opts { 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_emit_opts(struct emit_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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"h"; - static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; - int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { @@ -50,10 +49,10 @@ static int parse_emit_opts(struct emit_opts *opts, int *optind, //!OCLINT(high int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct emit_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_emit_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) { diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index dea70b2c5..bde019d6f 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -26,7 +26,7 @@ #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep -struct functions_opts { +struct cmd_opts { bool print_help = false; bool erase = false; bool list = false; @@ -38,9 +38,9 @@ struct functions_opts { wchar_t *description = NULL; }; -static int parse_functions_opts(struct functions_opts *opts, - int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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"Dacehnqv"; static const struct woption long_options[] = { @@ -258,10 +258,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 functions_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_functions_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) { diff --git a/src/builtin_history.cpp b/src/builtin_history.cpp index 104476561..7a28409a7 100644 --- a/src/builtin_history.cpp +++ b/src/builtin_history.cpp @@ -27,7 +27,7 @@ const enum_map 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 history_opts { +struct cmd_opts { bool print_help = false; hist_cmd_t hist_cmd = HIST_UNDEF; history_search_type_t search_type = (history_search_type_t)-1; @@ -92,8 +92,8 @@ static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t su break; \ } -static int parse_history_opts(struct history_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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; wgetopter_t w; @@ -198,10 +198,10 @@ static int parse_history_opts(struct history_opts *opts, int *optind, //!OCLINT 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 history_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_history_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) { diff --git a/src/builtin_random.cpp b/src/builtin_random.cpp index 2f5130fe0..80a00469d 100644 --- a/src/builtin_random.cpp +++ b/src/builtin_random.cpp @@ -17,7 +17,7 @@ #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep -struct random_opts { +struct cmd_opts { bool print_help = false; }; @@ -25,8 +25,8 @@ 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_random_opts(struct random_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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; wgetopter_t w; @@ -55,10 +55,10 @@ static int parse_random_opts(struct random_opts *opts, int *optind, //!OCLINT(h int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct random_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_random_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) { diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 21a33794c..686194b0b 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -29,7 +29,7 @@ #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep -struct read_opts { +struct cmd_opts { bool print_help = false; int place = ENV_USER; wcstring prompt_cmd; @@ -64,8 +64,8 @@ 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_read_opts(struct read_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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; wgetopter_t w; @@ -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 read_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_read_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) { diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index 1808b963f..e39cecc7b 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -70,7 +70,7 @@ int job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd, io_streams_t &str return -1; } -struct status_opts { +struct cmd_opts { bool print_help = false; status_cmd_t status_cmd = STATUS_UNDEF; int new_job_control_mode = -1; @@ -113,8 +113,8 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_t *status_cmd, status_ return true; } -static int parse_status_opts(struct status_opts *opts, int *optind, //!OCLINT(high ncss method) - int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { +static int parse_cmd_opts(struct cmd_opts *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; wgetopter_t w; @@ -218,10 +218,10 @@ static int parse_status_opts(struct status_opts *opts, int *optind, //!OCLINT(h 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 status_opts opts; + struct cmd_opts opts; int optind; - int retval = parse_status_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) {