mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
more wgetopt cleanup
This commit is contained in:
parent
cbae738882
commit
5e94650645
7 changed files with 203 additions and 309 deletions
243
src/builtin.cpp
243
src/builtin.cpp
|
@ -589,7 +589,6 @@ static int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
|
|
||||||
/// The block builtin, used for temporarily blocking events.
|
/// The block builtin, used for temporarily blocking events.
|
||||||
static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
|
||||||
enum {
|
enum {
|
||||||
UNSET,
|
UNSET,
|
||||||
GLOBAL,
|
GLOBAL,
|
||||||
|
@ -600,27 +599,17 @@ static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv
|
||||||
int erase = 0;
|
int erase = 0;
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
|
|
||||||
w.woptind = 0;
|
static const wchar_t *short_options = L"eghl";
|
||||||
|
static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'},
|
||||||
static const struct woption long_options[] = {{L"erase", no_argument, 0, 'e'},
|
{L"local", no_argument, NULL, 'l'},
|
||||||
{L"local", no_argument, 0, 'l'},
|
{L"global", no_argument, NULL, 'g'},
|
||||||
{L"global", no_argument, 0, 'g'},
|
{L"help", no_argument, NULL, 'h'},
|
||||||
{L"help", no_argument, 0, 'h'},
|
{NULL, 0, NULL, 0}};
|
||||||
{0, 0, 0, 0}};
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
int opt_index = 0;
|
|
||||||
int opt = w.wgetopt_long(argc, argv, L"elgh", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -642,7 +631,7 @@ static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,25 +697,15 @@ static int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv
|
||||||
static int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
int list = 0;
|
int list = 0;
|
||||||
wgetopter_t w;
|
|
||||||
|
|
||||||
|
static const wchar_t *short_options = L"hn";
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"names", no_argument, 0, 'n'}, {L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
{L"names", no_argument, 0, 'n'}, {L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||||
|
|
||||||
while (1) {
|
int opt;
|
||||||
int opt_index = 0;
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
int opt = w.wgetopt_long(argc, argv, L"nh", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -740,7 +719,7 @@ static int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -762,25 +741,15 @@ static int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
|
|
||||||
/// Implementation of the builtin emit command, used to create events.
|
/// Implementation of the builtin emit command, used to create events.
|
||||||
static int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
|
|
||||||
|
static const wchar_t *short_options = L"h";
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
static const struct woption long_options[] = {{L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||||
|
|
||||||
while (1) {
|
int opt;
|
||||||
int opt_index = 0;
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
int opt = w.wgetopt_long(argc, argv, L"h", long_options, &opt_index);
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
switch (opt) {
|
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -790,7 +759,7 @@ static int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,32 +779,20 @@ static int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
/// Implementation of the builtin 'command'. Actual command running is handled by the parser, this
|
/// Implementation of the builtin 'command'. Actual command running is handled by the parser, this
|
||||||
/// just processes the flags.
|
/// just processes the flags.
|
||||||
static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
bool find_path = false;
|
bool find_path = false;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
|
|
||||||
w.woptind = 0;
|
static const wchar_t *short_options = L"hqsv";
|
||||||
|
|
||||||
static const struct woption long_options[] = {{L"quiet", no_argument, NULL, 'q'},
|
static const struct woption long_options[] = {{L"quiet", no_argument, NULL, 'q'},
|
||||||
{L"search", no_argument, NULL, 's'},
|
{L"search", no_argument, NULL, 's'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, NULL, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
while (1) {
|
int opt;
|
||||||
int opt_index = 0;
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
int opt = w.wgetopt_long(argc, argv, L"qsvh", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -854,7 +811,7 @@ static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -881,7 +838,6 @@ static int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
/// A generic bultin that only supports showing a help message. This is only a placeholder that
|
/// A generic bultin that only supports showing a help message. This is only a placeholder that
|
||||||
/// prints the help message. Useful for commands that live in the parser.
|
/// prints the help message. Useful for commands that live in the parser.
|
||||||
static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
|
|
||||||
// Hackish - if we have no arguments other than the command, we are a "naked invocation" and we
|
// Hackish - if we have no arguments other than the command, we are a "naked invocation" and we
|
||||||
|
@ -891,22 +847,14 @@ static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, 0, 'h'}, {0, 0, 0, 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}};
|
||||||
|
|
||||||
while (1) {
|
int opt;
|
||||||
int opt_index = 0;
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
int opt = w.wgetopt_long(argc, argv, L"h", long_options, &opt_index);
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
switch (opt) {
|
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -916,7 +864,7 @@ static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1088,7 @@ static int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1592,10 +1540,19 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
|
||||||
wcstring_list_t inherit_vars;
|
wcstring_list_t inherit_vars;
|
||||||
wcstring_list_t wrap_targets;
|
wcstring_list_t wrap_targets;
|
||||||
|
|
||||||
|
// A valid function name has to be the first argument.
|
||||||
|
if (validate_function_name(argc, argv, function_name, cmd, out_err) == STATUS_CMD_OK) {
|
||||||
|
argv++;
|
||||||
|
argc--;
|
||||||
|
} else {
|
||||||
|
return STATUS_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
|
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
|
||||||
// This is needed due to the semantics of the -a/--argument-names flag.
|
// This is needed due to the semantics of the -a/--argument-names flag.
|
||||||
const wchar_t *short_options = L"+:a:d:e:hj:p:s:v:w:SV:";
|
static const wchar_t *short_options = L"+:a:d:e:hj:p:s:v:w:SV:";
|
||||||
const struct woption long_options[] = {{L"description", required_argument, NULL, 'd'},
|
static const struct woption long_options[] = {
|
||||||
|
{L"description", required_argument, NULL, 'd'},
|
||||||
{L"on-signal", required_argument, NULL, 's'},
|
{L"on-signal", required_argument, NULL, 's'},
|
||||||
{L"on-job-exit", required_argument, NULL, 'j'},
|
{L"on-job-exit", required_argument, NULL, 'j'},
|
||||||
{L"on-process-exit", required_argument, NULL, 'p'},
|
{L"on-process-exit", required_argument, NULL, 'p'},
|
||||||
|
@ -1608,14 +1565,6 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
|
||||||
{L"inherit-variable", required_argument, NULL, 'V'},
|
{L"inherit-variable", required_argument, NULL, 'V'},
|
||||||
{NULL, 0, NULL, 0}};
|
{NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
// A valid function name has to be the first argument.
|
|
||||||
if (validate_function_name(argc, argv, function_name, cmd, out_err) == STATUS_CMD_OK) {
|
|
||||||
argv++;
|
|
||||||
argc--;
|
|
||||||
} else {
|
|
||||||
return STATUS_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
|
@ -1769,6 +1718,8 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
|
||||||
|
|
||||||
/// The random builtin generates random numbers.
|
/// The random builtin generates random numbers.
|
||||||
static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
int argc = builtin_count_args(argv);
|
||||||
|
|
||||||
static bool seeded = false;
|
static bool seeded = false;
|
||||||
static std::minstd_rand engine;
|
static std::minstd_rand engine;
|
||||||
if (!seeded) {
|
if (!seeded) {
|
||||||
|
@ -1780,24 +1731,14 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
||||||
seeded = true;
|
seeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wgetopter_t w;
|
static const wchar_t *short_options = L"h";
|
||||||
int argc = builtin_count_args(argv);
|
|
||||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
||||||
{NULL, 0, NULL, 0}};
|
{NULL, 0, NULL, 0}};
|
||||||
while (1) {
|
|
||||||
int opt_index = 0;
|
|
||||||
|
|
||||||
int opt = w.wgetopt_long(argc, argv, L"h", long_options, &opt_index);
|
int opt;
|
||||||
if (opt == -1) break;
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) { //!OCLINT(too few branches)
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -1807,7 +1748,7 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2093,8 +2034,8 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
bool silent = false;
|
bool silent = false;
|
||||||
bool split_null = false;
|
bool split_null = false;
|
||||||
|
|
||||||
const wchar_t *short_options = L"ac:ghilm:n:p:suxzP:UR:";
|
static const wchar_t *short_options = L"ac:ghilm:n:p:suxzP:UR:";
|
||||||
const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'},
|
static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'},
|
||||||
{L"global", no_argument, NULL, 'g'},
|
{L"global", no_argument, NULL, 'g'},
|
||||||
{L"local", no_argument, NULL, 'l'},
|
{L"local", no_argument, NULL, 'l'},
|
||||||
{L"universal", no_argument, NULL, 'U'},
|
{L"universal", no_argument, NULL, 'U'},
|
||||||
|
@ -2411,20 +2352,21 @@ static int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
||||||
/// the non-flag subcommand form. While these flags are deprecated they must be supported at
|
/// the non-flag subcommand form. While these flags are deprecated they must be supported at
|
||||||
/// least until fish 3.0 and possibly longer to avoid breaking everyones config.fish and other
|
/// least until fish 3.0 and possibly longer to avoid breaking everyones config.fish and other
|
||||||
/// scripts.
|
/// scripts.
|
||||||
const wchar_t *short_options = L":cbilfnhj:t";
|
static const wchar_t *short_options = L":cbilfnhj:t";
|
||||||
const struct woption long_options[] = {{L"help", no_argument, 0, 'h'},
|
static const struct woption long_options[] = {
|
||||||
{L"is-command-substitution", no_argument, 0, 'c'},
|
{L"help", no_argument, NULL, 'h'},
|
||||||
{L"is-block", no_argument, 0, 'b'},
|
{L"is-command-substitution", no_argument, NULL, 'c'},
|
||||||
{L"is-interactive", no_argument, 0, 'i'},
|
{L"is-block", no_argument, NULL, 'b'},
|
||||||
{L"is-login", no_argument, 0, 'l'},
|
{L"is-interactive", no_argument, NULL, 'i'},
|
||||||
{L"is-full-job-control", no_argument, 0, 1},
|
{L"is-login", no_argument, NULL, 'l'},
|
||||||
{L"is-interactive-job-control", no_argument, 0, 2},
|
{L"is-full-job-control", no_argument, NULL, 1},
|
||||||
{L"is-no-job-control", no_argument, 0, 3},
|
{L"is-interactive-job-control", no_argument, NULL, 2},
|
||||||
{L"current-filename", no_argument, 0, 'f'},
|
{L"is-no-job-control", no_argument, NULL, 3},
|
||||||
{L"current-line-number", no_argument, 0, 'n'},
|
{L"current-filename", no_argument, NULL, 'f'},
|
||||||
{L"job-control", required_argument, 0, 'j'},
|
{L"current-line-number", no_argument, NULL, 'n'},
|
||||||
{L"print-stack-trace", no_argument, 0, 't'},
|
{L"job-control", required_argument, NULL, 'j'},
|
||||||
{0, 0, 0, 0}};
|
{L"print-stack-trace", no_argument, NULL, 't'},
|
||||||
|
{NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
|
@ -2745,31 +2687,18 @@ static int builtin_count(parser_t &parser, io_streams_t &streams, wchar_t **argv
|
||||||
/// Implementation of the builtin contains command, used to check if a specified string is part of
|
/// Implementation of the builtin contains command, used to check if a specified string is part of
|
||||||
/// a list.
|
/// a list.
|
||||||
static int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
static int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
int argc = builtin_count_args(argv);
|
||||||
int argc;
|
|
||||||
argc = builtin_count_args(argv);
|
|
||||||
wchar_t *needle;
|
wchar_t *needle;
|
||||||
bool should_output_index = false;
|
bool should_output_index = false;
|
||||||
|
|
||||||
const struct woption long_options[] = {
|
static const wchar_t *short_options = L"+hi";
|
||||||
{L"help", no_argument, 0, 'h'}, {L"index", no_argument, 0, 'i'}, {0, 0, 0, 0}};
|
static const struct woption long_options[] = {
|
||||||
|
{L"help", no_argument, NULL, 'h'}, {L"index", no_argument, NULL, 'i'}, {NULL, 0, NULL, 0}};
|
||||||
while (1) {
|
|
||||||
int opt_index = 0;
|
|
||||||
|
|
||||||
int opt = w.wgetopt_long(argc, argv, L"+hi", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
assert(opt_index >= 0 &&
|
|
||||||
(size_t)opt_index < sizeof long_options / sizeof *long_options);
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case 'h': {
|
case 'h': {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
@ -2787,7 +2716,7 @@ static int builtin_contains(parser_t &parser, io_streams_t &streams, wchar_t **a
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3255,12 +3184,17 @@ static int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
bool case_sensitive = false;
|
bool case_sensitive = false;
|
||||||
bool null_terminate = false;
|
bool null_terminate = false;
|
||||||
|
|
||||||
|
// Use the default history if we have none (which happens if invoked non-interactively, e.g.
|
||||||
|
// from webconfig.py.
|
||||||
|
history_t *history = reader_get_history();
|
||||||
|
if (!history) history = &history_t::history_with_name(L"fish");
|
||||||
|
|
||||||
/// Note: Do not add new flags that represent subcommands. We're encouraging people to switch to
|
/// Note: Do not add new flags that represent subcommands. We're encouraging people to switch to
|
||||||
/// the non-flag subcommand form. While many of these flags are deprecated they must be
|
/// the non-flag subcommand form. While many of these flags are deprecated they must be
|
||||||
/// supported at least until fish 3.0 and possibly longer to avoid breaking everyones
|
/// supported at least until fish 3.0 and possibly longer to avoid breaking everyones
|
||||||
/// config.fish and other scripts.
|
/// config.fish and other scripts.
|
||||||
const wchar_t *short_options = L":Cmn:epchtz";
|
static const wchar_t *short_options = L":Cmn:epchtz";
|
||||||
const struct woption long_options[] = {{L"prefix", no_argument, NULL, 'p'},
|
static const struct woption long_options[] = {{L"prefix", no_argument, NULL, 'p'},
|
||||||
{L"contains", no_argument, NULL, 'c'},
|
{L"contains", no_argument, NULL, 'c'},
|
||||||
{L"help", no_argument, NULL, 'h'},
|
{L"help", no_argument, NULL, 'h'},
|
||||||
{L"show-time", optional_argument, NULL, 't'},
|
{L"show-time", optional_argument, NULL, 't'},
|
||||||
|
@ -3276,11 +3210,6 @@ static int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **ar
|
||||||
{L"merge", no_argument, NULL, 5},
|
{L"merge", no_argument, NULL, 5},
|
||||||
{NULL, 0, NULL, 0}};
|
{NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
history_t *history = reader_get_history();
|
|
||||||
// Use the default history if we have none (which happens if invoked non-interactively, e.g.
|
|
||||||
// from webconfig.py.
|
|
||||||
if (!history) history = &history_t::history_with_name(L"fish");
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
|
|
|
@ -167,7 +167,6 @@ 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.
|
/// 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) {
|
int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
|
||||||
int buffer_part = 0;
|
int buffer_part = 0;
|
||||||
int cut_at_cursor = 0;
|
int cut_at_cursor = 0;
|
||||||
|
|
||||||
|
@ -210,42 +209,30 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
w.woptind = 0;
|
static const wchar_t *short_options = L"abijpctwforhI:CLSsP";
|
||||||
|
static const struct woption long_options[] = {{L"append", no_argument, NULL, 'a'},
|
||||||
while (1) {
|
{L"insert", no_argument, NULL, 'i'},
|
||||||
static const struct woption long_options[] = {{L"append", no_argument, 0, 'a'},
|
{L"replace", no_argument, NULL, 'r'},
|
||||||
{L"insert", no_argument, 0, 'i'},
|
{L"current-job", no_argument, NULL, 'j'},
|
||||||
{L"replace", no_argument, 0, 'r'},
|
{L"current-process", no_argument, NULL, 'p'},
|
||||||
{L"current-job", no_argument, 0, 'j'},
|
{L"current-token", no_argument, NULL, 't'},
|
||||||
{L"current-process", no_argument, 0, 'p'},
|
{L"current-buffer", no_argument, NULL, 'b'},
|
||||||
{L"current-token", no_argument, 0, 't'},
|
{L"cut-at-cursor", no_argument, NULL, 'c'},
|
||||||
{L"current-buffer", no_argument, 0, 'b'},
|
{L"function", no_argument, NULL, 'f'},
|
||||||
{L"cut-at-cursor", no_argument, 0, 'c'},
|
{L"tokenize", no_argument, NULL, 'o'},
|
||||||
{L"function", no_argument, 0, 'f'},
|
{L"help", no_argument, NULL, 'h'},
|
||||||
{L"tokenize", no_argument, 0, 'o'},
|
{L"input", required_argument, NULL, 'I'},
|
||||||
{L"help", no_argument, 0, 'h'},
|
{L"cursor", no_argument, NULL, 'C'},
|
||||||
{L"input", required_argument, 0, 'I'},
|
{L"line", no_argument, NULL, 'L'},
|
||||||
{L"cursor", no_argument, 0, 'C'},
|
{L"search-mode", no_argument, NULL, 'S'},
|
||||||
{L"line", no_argument, 0, 'L'},
|
{L"selection", no_argument, NULL, 's'},
|
||||||
{L"search-mode", no_argument, 0, 'S'},
|
{L"paging-mode", no_argument, NULL, 'P'},
|
||||||
{L"selection", no_argument, 0, 's'},
|
{NULL, 0, NULL, 0}};
|
||||||
{L"paging-mode", no_argument, 0, 'P'},
|
|
||||||
{0, 0, 0, 0}};
|
|
||||||
|
|
||||||
int opt_index = 0;
|
|
||||||
|
|
||||||
int opt = w.wgetopt_long(argc, argv, L"abijpctwforhI:CLSsP", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
|
|
||||||
return STATUS_CMD_ERROR;
|
|
||||||
}
|
|
||||||
case L'a': {
|
case L'a': {
|
||||||
append_mode = APPEND_MODE;
|
append_mode = APPEND_MODE;
|
||||||
break;
|
break;
|
||||||
|
@ -320,7 +307,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,8 +129,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wcstring_list_t path;
|
wcstring_list_t path;
|
||||||
wcstring_list_t wrap_targets;
|
wcstring_list_t wrap_targets;
|
||||||
|
|
||||||
const wchar_t *short_options = L":a:c:p:s:l:o:d:frxeuAn:C::w:h";
|
static const wchar_t *short_options = L":a:c:p:s:l:o:d:frxeuAn:C::w:h";
|
||||||
const struct woption long_options[] = {{L"exclusive", no_argument, NULL, 'x'},
|
static const struct woption long_options[] = {{L"exclusive", no_argument, NULL, 'x'},
|
||||||
{L"no-files", no_argument, NULL, 'f'},
|
{L"no-files", no_argument, NULL, 'f'},
|
||||||
{L"require-parameter", no_argument, NULL, 'r'},
|
{L"require-parameter", no_argument, NULL, 'r'},
|
||||||
{L"path", required_argument, NULL, 'p'},
|
{L"path", required_argument, NULL, 'p'},
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "config.h" // IWYU pragma: keep
|
#include "config.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stddef.h>
|
||||||
#ifdef HAVE__PROC_SELF_STAT
|
#ifdef HAVE__PROC_SELF_STAT
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,35 +109,21 @@ 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.
|
/// 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) {
|
int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
wgetopter_t w;
|
int argc = builtin_count_args(argv);
|
||||||
int argc = 0;
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int mode = JOBS_DEFAULT;
|
int mode = JOBS_DEFAULT;
|
||||||
int print_last = 0;
|
int print_last = 0;
|
||||||
|
|
||||||
argc = builtin_count_args(argv);
|
static const wchar_t *short_options = L"cghlp";
|
||||||
w.woptind = 0;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
static const struct woption long_options[] = {
|
static const struct woption long_options[] = {
|
||||||
{L"pid", no_argument, 0, 'p'}, {L"command", no_argument, 0, 'c'},
|
{L"pid", no_argument, NULL, 'p'}, {L"command", no_argument, NULL, 'c'},
|
||||||
{L"group", no_argument, 0, 'g'}, {L"last", no_argument, 0, 'l'},
|
{L"group", no_argument, NULL, 'g'}, {L"last", no_argument, NULL, 'l'},
|
||||||
{L"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
int opt_index = 0;
|
|
||||||
|
|
||||||
int opt = w.wgetopt_long(argc, argv, L"pclgh", long_options, &opt_index);
|
|
||||||
if (opt == -1) break;
|
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
wgetopter_t w;
|
||||||
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
if (long_options[opt_index].flag != 0) break;
|
|
||||||
streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
|
|
||||||
long_options[opt_index].name);
|
|
||||||
|
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
case 'p': {
|
case 'p': {
|
||||||
mode = JOBS_PRINT_PID;
|
mode = JOBS_PRINT_PID;
|
||||||
break;
|
break;
|
||||||
|
@ -162,7 +149,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
DIE("unexpected opt");
|
DIE("unexpected retval from wgetopt_long");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,8 +157,9 @@ int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
bool soft = false;
|
bool soft = false;
|
||||||
int what = RLIMIT_FSIZE;
|
int what = RLIMIT_FSIZE;
|
||||||
|
|
||||||
const wchar_t *short_options = L":HSacdflmnstuvh";
|
static const wchar_t *short_options = L":HSacdflmnstuvh";
|
||||||
const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'},
|
static const struct woption long_options[] = {
|
||||||
|
{L"all", no_argument, NULL, 'a'},
|
||||||
{L"hard", no_argument, NULL, 'H'},
|
{L"hard", no_argument, NULL, 'H'},
|
||||||
{L"soft", no_argument, NULL, 'S'},
|
{L"soft", no_argument, NULL, 'S'},
|
||||||
{L"core-size", no_argument, NULL, 'c'},
|
{L"core-size", no_argument, NULL, 'c'},
|
||||||
|
|
|
@ -216,8 +216,8 @@ static int read_init(const struct config_paths_t &paths) {
|
||||||
|
|
||||||
/// Parse the argument list, return the index of the first non-flag arguments.
|
/// Parse the argument list, return the index of the first non-flag arguments.
|
||||||
static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds) {
|
static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds) {
|
||||||
const char *short_opts = "+hilnvc:p:d:D:";
|
static const char *short_opts = "+hilnvc:p:d:D:";
|
||||||
const struct option long_opts[] = {{"command", required_argument, NULL, 'c'},
|
static const struct option long_opts[] = {{"command", required_argument, NULL, 'c'},
|
||||||
{"debug-level", required_argument, NULL, 'd'},
|
{"debug-level", required_argument, NULL, 'd'},
|
||||||
{"debug-stack-frames", required_argument, NULL, 'D'},
|
{"debug-stack-frames", required_argument, NULL, 'D'},
|
||||||
{"interactive", no_argument, NULL, 'i'},
|
{"interactive", no_argument, NULL, 'i'},
|
||||||
|
@ -231,11 +231,6 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds)
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
fwprintf(stderr, _(L"getopt_long() unexpectedly returned zero\n"));
|
|
||||||
exit(127);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'c': {
|
case 'c': {
|
||||||
cmds->push_back(optarg);
|
cmds->push_back(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -372,11 +372,6 @@ int main(int argc, char *argv[]) {
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0: {
|
|
||||||
fwprintf(stderr, _(L"getopt_long() unexpectedly returned zero\n"));
|
|
||||||
exit(127);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'P': {
|
case 'P': {
|
||||||
dump_parse_tree = true;
|
dump_parse_tree = true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue