more builtin style cleanup

This commit is contained in:
Kurtis Rader 2017-06-14 22:12:29 -07:00
parent b480b117a9
commit ffdabace5e
19 changed files with 97 additions and 292 deletions

View File

@ -98,33 +98,27 @@ HAVE_DOXYGEN=@HAVE_DOXYGEN@
# #
# All objects that the system needs to build fish, except fish.o # All objects that the system needs to build fish, except fish.o
# #
FISH_OBJS := obj/autoload.o obj/builtin.o obj/builtin_bind.o obj/builtin_block.o \ FISH_OBJS := obj/autoload.o obj/builtin.o obj/builtin_bg.o obj/builtin_bind.o obj/builtin_block.o \
obj/builtin_commandline.o obj/builtin_emit.o obj/builtin_functions.o \ obj/builtin_builtin.o obj/builtin_cd.o obj/builtin_command.o obj/builtin_commandline.o \
obj/builtin_bg.o obj/builtin_fg.o obj/builtin_return.o obj/builtin_exit.o \ obj/builtin_complete.o obj/builtin_contains.o obj/builtin_disown.o obj/builtin_echo.o \
obj/builtin_realpath.o \ obj/builtin_emit.o obj/builtin_exit.o obj/builtin_fg.o obj/builtin_function.o \
obj/builtin_history.o obj/builtin_status.o obj/builtin_read.o obj/builtin_pwd.o \ obj/builtin_functions.o obj/builtin_history.o obj/builtin_jobs.o obj/builtin_printf.o \
obj/builtin_source.o obj/builtin_random.o obj/builtin_echo.o \ obj/builtin_pwd.o obj/builtin_random.o obj/builtin_read.o obj/builtin_realpath.o \
obj/builtin_cd.o obj/builtin_disown.o obj/builtin_function.o \ obj/builtin_return.o obj/builtin_set.o obj/builtin_set_color.o obj/builtin_source.o \
obj/builtin_builtin.o obj/builtin_command.o obj/builtin_contains.o \ obj/builtin_status.o obj/builtin_string.o obj/builtin_test.o obj/builtin_ulimit.o \
obj/builtin_complete.o obj/builtin_jobs.o obj/builtin_printf.o \ obj/color.o obj/common.o obj/complete.o obj/env.o obj/env_universal_common.o obj/event.o \
obj/builtin_set.o obj/builtin_set_color.o obj/builtin_string.o \ obj/exec.o obj/expand.o obj/fallback.o obj/fish_version.o obj/function.o obj/highlight.o \
obj/builtin_test.o obj/builtin_ulimit.o obj/color.o obj/common.o \ obj/history.o obj/input.o obj/input_common.o obj/intern.o obj/io.o obj/iothread.o \
obj/complete.o obj/env.o obj/env_universal_common.o obj/event.o \ obj/kill.o obj/output.o obj/pager.o obj/parse_execution.o obj/parse_productions.o \
obj/exec.o obj/expand.o obj/fallback.o obj/fish_version.o \ obj/parse_tree.o obj/parse_util.o obj/parser.o obj/parser_keywords.o obj/path.o \
obj/function.o obj/highlight.o obj/history.o obj/input.o \ obj/postfork.o obj/proc.o obj/reader.o obj/sanity.o obj/screen.o obj/signal.o \
obj/input_common.o obj/intern.o obj/io.o obj/iothread.o obj/kill.o \ obj/tokenizer.o obj/utf8.o obj/util.o obj/wcstringutil.o obj/wgetopt.o obj/wildcard.o \
obj/output.o obj/pager.o obj/parse_execution.o \ obj/wutil.o
obj/parse_productions.o obj/parse_tree.o obj/parse_util.o \
obj/parser.o obj/parser_keywords.o obj/path.o obj/postfork.o \
obj/proc.o obj/reader.o obj/sanity.o obj/screen.o obj/signal.o \
obj/tokenizer.o obj/utf8.o obj/util.o obj/wcstringutil.o \
obj/wgetopt.o obj/wildcard.o obj/wutil.o
FISH_INDENT_OBJS := obj/fish_indent.o obj/print_help.o $(FISH_OBJS) FISH_INDENT_OBJS := obj/fish_indent.o obj/print_help.o $(FISH_OBJS)
FISH_KEYREAD_OBJS := obj/fish_key_reader.o obj/print_help.o $(FISH_OBJS) FISH_KEYREAD_OBJS := obj/fish_key_reader.o obj/print_help.o $(FISH_OBJS)
# #
# All objects that the system needs to build fish_tests # All objects that the system needs to build fish_tests
# #
@ -455,7 +449,7 @@ lexicon.txt: doc_src/commands.hdr $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES
-e "s|'\(.*\)'|func \1|p"; -e "s|'\(.*\)'|func \1|p";
$v $(SED) <share/functions/__fish_config_interactive.fish >>lexicon.tmp -n \ $v $(SED) <share/functions/__fish_config_interactive.fish >>lexicon.tmp -n \
-e '/set_default/s/.*\(fish_[a-z][a-z_]*\).*$$/clrv \1/p'; \ -e '/set_default/s/.*\(fish_[a-z][a-z_]*\).*$$/clrv \1/p'; \
$(SED) <lexicon_filter.in >>lexicon.tmp -n \ $(SED) <lexicon_filter.in >>lexicon.tmp -n \
-e '/^#.!#/s/^#.!# \(.... [a-z][a-z_]*\)/\1/p'; -e '/^#.!#/s/^#.!# \(.... [a-z][a-z_]*\)/\1/p';
$v mv lexicon.tmp lexicon.txt; rm -f lexicon_catalog.tmp lexicon_catalog.txt; $v mv lexicon.tmp lexicon.txt; rm -f lexicon_catalog.tmp lexicon_catalog.txt;
@ -896,7 +890,7 @@ style-all:
# #
distclean: clean distclean: clean
-$v test ! -f $(PCRE2_DIR)/Makefile || \ -$v test ! -f $(PCRE2_DIR)/Makefile || \
$(MAKE) V=$(V) -C $(PCRE2_DIR) distclean $(MAKE) V=$(V) -C $(PCRE2_DIR) distclean
$v rm -rf config.status config.log config.h Makefile autom4te.cache aclocal.m4 $v rm -rf config.status config.log config.h Makefile autom4te.cache aclocal.m4
.PHONY: distclean .PHONY: distclean
@ -914,11 +908,11 @@ clean:
# send all output to /dev/null - unless there's an error, in which case run it again not silenced. # send all output to /dev/null - unless there's an error, in which case run it again not silenced.
ifeq ($(V), 0 ) ifeq ($(V), 0 )
-@test ! -f $(PCRE2_DIR)/Makefile || \ -@test ! -f $(PCRE2_DIR)/Makefile || \
$(MAKE) -C $(PCRE2_DIR) clean $(MAKE) -C $(PCRE2_DIR) clean
else else
-@test ! -f $(PCRE2_DIR)/Makefile || \ -@test ! -f $(PCRE2_DIR)/Makefile || \
$(MAKE) -s -C $(PCRE2_DIR) clean > /dev/null || \ $(MAKE) -s -C $(PCRE2_DIR) clean > /dev/null || \
$(MAKE) -s -C $(PCRE2_DIR) clean $(MAKE) -s -C $(PCRE2_DIR) clean
endif endif
$v rm -f obj/*.o *.o doc.h doc.tmp $v rm -f obj/*.o *.o doc.h doc.tmp
$v rm -f doc_src/*.doxygen doc_src/*.cpp doc_src/*.o doc_src/commands.hdr $v rm -f doc_src/*.doxygen doc_src/*.cpp doc_src/*.o doc_src/commands.hdr
@ -951,31 +945,37 @@ v = $(V$(V))
obj/autoload.o: config.h src/autoload.h src/common.h src/fallback.h obj/autoload.o: config.h src/autoload.h src/common.h src/fallback.h
obj/autoload.o: src/signal.h src/lru.h src/env.h src/exec.h src/wutil.h obj/autoload.o: src/signal.h src/lru.h src/env.h src/exec.h src/wutil.h
obj/builtin.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin.o: src/signal.h src/builtin_bind.h src/builtin_block.h obj/builtin.o: src/signal.h src/builtin_bg.h src/builtin_bind.h
obj/builtin.o: src/builtin_builtin.h src/builtin_cd.h src/builtin_command.h obj/builtin.o: src/builtin_block.h src/builtin_builtin.h src/builtin_cd.h
obj/builtin.o: src/builtin_commandline.h src/builtin_complete.h obj/builtin.o: src/builtin_command.h src/builtin_commandline.h
obj/builtin.o: src/builtin_contains.h src/builtin_disown.h src/builtin_echo.h obj/builtin.o: src/builtin_complete.h src/builtin_contains.h
obj/builtin.o: src/builtin_emit.h src/builtin_functions.h obj/builtin.o: src/builtin_disown.h src/builtin_echo.h src/builtin_emit.h
obj/builtin.o: src/builtin_exit.h src/builtin_fg.h src/builtin_functions.h
obj/builtin.o: src/builtin_history.h src/builtin_jobs.h src/builtin_printf.h obj/builtin.o: src/builtin_history.h src/builtin_jobs.h src/builtin_printf.h
obj/builtin.o: src/builtin_random.h src/builtin_read.h src/builtin_set.h obj/builtin.o: src/builtin_pwd.h src/builtin_random.h src/builtin_read.h
obj/builtin.o: src/builtin_realpath.h src/builtin_return.h src/builtin_set.h
obj/builtin.o: src/builtin_set_color.h src/builtin_source.h obj/builtin.o: src/builtin_set_color.h src/builtin_source.h
obj/builtin.o: src/builtin_status.h src/builtin_string.h src/builtin_test.h obj/builtin.o: src/builtin_status.h src/builtin_string.h src/builtin_test.h
obj/builtin.o: src/builtin_ulimit.h src/complete.h src/env.h src/exec.h obj/builtin.o: src/builtin_ulimit.h src/complete.h src/exec.h src/intern.h
obj/builtin.o: src/intern.h src/io.h src/parse_constants.h src/parse_util.h obj/builtin.o: src/io.h src/parse_constants.h src/parse_util.h
obj/builtin.o: src/tokenizer.h src/parser.h src/event.h src/expand.h obj/builtin.o: src/tokenizer.h src/parser.h src/event.h src/expand.h
obj/builtin.o: src/parse_tree.h src/proc.h src/reader.h src/highlight.h obj/builtin.o: src/parse_tree.h src/proc.h src/reader.h src/highlight.h
obj/builtin.o: src/color.h src/wgetopt.h src/wutil.h obj/builtin.o: src/color.h src/env.h src/wgetopt.h src/wutil.h
obj/builtin_bg.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_bg.o: src/signal.h src/builtin_bg.h src/io.h src/proc.h
obj/builtin_bg.o: src/parse_tree.h src/parse_constants.h src/tokenizer.h
obj/builtin_bg.o: src/wutil.h
obj/builtin_bind.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_bind.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_bind.o: src/signal.h src/builtin_bind.h src/input.h src/env.h obj/builtin_bind.o: src/signal.h src/builtin_bind.h src/input.h src/io.h
obj/builtin_bind.o: src/io.h src/wgetopt.h src/wutil.h obj/builtin_bind.o: src/wgetopt.h src/wutil.h
obj/builtin_block.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_block.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_block.o: src/signal.h src/builtin_block.h src/event.h src/io.h obj/builtin_block.o: src/signal.h src/builtin_block.h src/event.h src/io.h
obj/builtin_block.o: src/parser.h src/expand.h src/parse_constants.h obj/builtin_block.o: src/parser.h src/expand.h src/parse_constants.h
obj/builtin_block.o: src/parse_tree.h src/tokenizer.h src/proc.h obj/builtin_block.o: src/parse_tree.h src/tokenizer.h src/proc.h
obj/builtin_block.o: src/wgetopt.h src/wutil.h obj/builtin_block.o: src/wgetopt.h src/wutil.h
obj/builtin_builtin.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_builtin.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_builtin.o: src/signal.h src/builtin_builtin.h src/io.h src/path.h obj/builtin_builtin.o: src/signal.h src/builtin_builtin.h src/io.h
obj/builtin_builtin.o: src/env.h src/wgetopt.h src/wutil.h obj/builtin_builtin.o: src/wgetopt.h src/wutil.h
obj/builtin_cd.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_cd.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_cd.o: src/signal.h src/builtin_cd.h src/env.h src/io.h obj/builtin_cd.o: src/signal.h src/builtin_cd.h src/env.h src/io.h
obj/builtin_cd.o: src/parser.h src/event.h src/expand.h src/parse_constants.h obj/builtin_cd.o: src/parser.h src/event.h src/expand.h src/parse_constants.h
@ -986,11 +986,11 @@ obj/builtin_command.o: src/signal.h src/builtin_command.h src/io.h src/path.h
obj/builtin_command.o: src/env.h src/wgetopt.h src/wutil.h obj/builtin_command.o: src/env.h src/wgetopt.h src/wutil.h
obj/builtin_commandline.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_commandline.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_commandline.o: src/signal.h src/input.h src/builtin_bind.h obj/builtin_commandline.o: src/signal.h src/input.h src/builtin_bind.h
obj/builtin_commandline.o: src/env.h src/io.h src/parse_util.h obj/builtin_commandline.o: src/io.h src/parse_util.h src/parse_constants.h
obj/builtin_commandline.o: src/parse_constants.h src/tokenizer.h src/proc.h obj/builtin_commandline.o: src/tokenizer.h src/proc.h src/parse_tree.h
obj/builtin_commandline.o: src/parse_tree.h src/reader.h src/complete.h obj/builtin_commandline.o: src/reader.h src/complete.h src/highlight.h
obj/builtin_commandline.o: src/highlight.h src/color.h src/util.h obj/builtin_commandline.o: src/color.h src/env.h src/util.h src/wgetopt.h
obj/builtin_commandline.o: src/wgetopt.h src/wutil.h obj/builtin_commandline.o: src/wutil.h
obj/builtin_complete.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_complete.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_complete.o: src/signal.h src/complete.h src/env.h src/io.h obj/builtin_complete.o: src/signal.h src/complete.h src/env.h src/io.h
obj/builtin_complete.o: src/parse_constants.h src/parse_util.h obj/builtin_complete.o: src/parse_constants.h src/parse_util.h
@ -1011,6 +1011,16 @@ obj/builtin_echo.o: src/wutil.h
obj/builtin_emit.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_emit.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_emit.o: src/signal.h src/builtin_emit.h src/event.h src/io.h obj/builtin_emit.o: src/signal.h src/builtin_emit.h src/event.h src/io.h
obj/builtin_emit.o: src/wgetopt.h src/wutil.h obj/builtin_emit.o: src/wgetopt.h src/wutil.h
obj/builtin_exit.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_exit.o: src/signal.h src/builtin_exit.h src/io.h src/proc.h
obj/builtin_exit.o: src/parse_tree.h src/parse_constants.h src/tokenizer.h
obj/builtin_exit.o: src/reader.h src/complete.h src/highlight.h src/color.h
obj/builtin_exit.o: src/env.h src/wgetopt.h src/wutil.h
obj/builtin_fg.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_fg.o: src/signal.h src/builtin_fg.h src/env.h src/io.h src/proc.h
obj/builtin_fg.o: src/parse_tree.h src/parse_constants.h src/tokenizer.h
obj/builtin_fg.o: src/reader.h src/complete.h src/highlight.h src/color.h
obj/builtin_fg.o: src/wutil.h
obj/builtin_function.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_function.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_function.o: src/signal.h src/builtin_function.h src/complete.h obj/builtin_function.o: src/signal.h src/builtin_function.h src/complete.h
obj/builtin_function.o: src/event.h src/function.h src/env.h src/io.h obj/builtin_function.o: src/event.h src/function.h src/env.h src/io.h
@ -1034,6 +1044,9 @@ obj/builtin_jobs.o: src/parse_constants.h src/tokenizer.h src/wgetopt.h
obj/builtin_jobs.o: src/wutil.h obj/builtin_jobs.o: src/wutil.h
obj/builtin_printf.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_printf.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_printf.o: src/signal.h src/io.h src/wutil.h obj/builtin_printf.o: src/signal.h src/io.h src/wutil.h
obj/builtin_pwd.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_pwd.o: src/signal.h src/builtin_pwd.h src/event.h src/io.h
obj/builtin_pwd.o: src/wgetopt.h src/wutil.h
obj/builtin_random.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_random.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_random.o: src/signal.h src/builtin_random.h src/io.h obj/builtin_random.o: src/signal.h src/builtin_random.h src/io.h
obj/builtin_random.o: src/wgetopt.h src/wutil.h obj/builtin_random.o: src/wgetopt.h src/wutil.h
@ -1043,6 +1056,14 @@ obj/builtin_read.o: src/event.h src/expand.h src/parse_constants.h
obj/builtin_read.o: src/highlight.h src/color.h src/io.h src/proc.h obj/builtin_read.o: src/highlight.h src/color.h src/io.h src/proc.h
obj/builtin_read.o: src/parse_tree.h src/tokenizer.h src/reader.h obj/builtin_read.o: src/parse_tree.h src/tokenizer.h src/reader.h
obj/builtin_read.o: src/wcstringutil.h src/wgetopt.h src/wutil.h obj/builtin_read.o: src/wcstringutil.h src/wgetopt.h src/wutil.h
obj/builtin_realpath.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_realpath.o: src/signal.h src/builtin_realpath.h src/io.h
obj/builtin_realpath.o: src/wutil.h
obj/builtin_return.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_return.o: src/signal.h src/builtin_return.h src/io.h src/parser.h
obj/builtin_return.o: src/event.h src/expand.h src/parse_constants.h
obj/builtin_return.o: src/parse_tree.h src/tokenizer.h src/proc.h
obj/builtin_return.o: src/wgetopt.h src/wutil.h
obj/builtin_set.o: config.h src/builtin.h src/common.h src/fallback.h obj/builtin_set.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_set.o: src/signal.h src/env.h src/expand.h src/parse_constants.h obj/builtin_set.o: src/signal.h src/env.h src/expand.h src/parse_constants.h
obj/builtin_set.o: src/io.h src/proc.h src/parse_tree.h src/tokenizer.h obj/builtin_set.o: src/io.h src/proc.h src/parse_tree.h src/tokenizer.h

View File

@ -296,7 +296,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
} }
case L'h': { case L'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case L'k': { case L'k': {
opts->use_terminfo = true; opts->use_terminfo = true;

View File

@ -36,7 +36,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
switch (opt) { switch (opt) {
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case 'g': { case 'g': {
opts->scope = GLOBAL; opts->scope = GLOBAL;

View File

@ -31,7 +31,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
switch (opt) { switch (opt) {
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case 'n': { case 'n': {
opts->list_names = true; opts->list_names = true;

View File

@ -3,7 +3,6 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include "builtin.h" #include "builtin.h"
#include "builtin_cd.h" #include "builtin_cd.h"
@ -14,42 +13,8 @@
#include "parser.h" #include "parser.h"
#include "path.h" #include "path.h"
#include "proc.h" #include "proc.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
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_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
wgetopter_t w;
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;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// The cd builtin. Changes the current directory to the one specified or to $HOME if none is /// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
/// specified. The directory can be relative to any directory in the CDPATH variable. /// specified. The directory can be relative to any directory in the CDPATH variable.
/// The cd builtin. Changes the current directory to the one specified or to $HOME if none is /// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
@ -57,9 +22,9 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -32,7 +32,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
switch (opt) { switch (opt) {
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case 'q': { case 'q': {
opts->quiet = true; opts->quiet = true;

View File

@ -29,7 +29,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t
switch (opt) { switch (opt) {
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case 'i': { case 'i': {
opts->print_index = true; opts->print_index = true;

View File

@ -3,7 +3,6 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stddef.h>
#include <set> #include <set>
@ -14,43 +13,8 @@
#include "io.h" #include "io.h"
#include "parser.h" #include "parser.h"
#include "proc.h" #include "proc.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
struct cmd_opts {
bool print_help = false;
};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, 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) {
switch (opt) { //!OCLINT(too few branches)
case 'h': {
opts->print_help = true;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// Helper for builtin_disown. /// Helper for builtin_disown.
static int disown_job(const wchar_t *cmd, parser_t &parser, io_streams_t &streams, job_t *j) { static int disown_job(const wchar_t *cmd, parser_t &parser, io_streams_t &streams, job_t *j) {
if (j == 0) { if (j == 0) {
@ -75,10 +39,10 @@ static int disown_job(const wchar_t *cmd, parser_t &parser, io_streams_t &stream
int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -1,58 +1,22 @@
// Implementation of the emit builtin. // Implementation of the emit builtin.
#include "config.h" // IWYU pragma: keep #include "config.h" // IWYU pragma: keep
#include <stddef.h>
#include "builtin.h" #include "builtin.h"
#include "builtin_emit.h" #include "builtin_emit.h"
#include "common.h" #include "common.h"
#include "event.h" #include "event.h"
#include "fallback.h" // IWYU pragma: keep #include "fallback.h" // IWYU pragma: keep
#include "io.h" #include "io.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
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_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;
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;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// Implementation of the builtin emit command, used to create events. /// Implementation of the builtin emit command, used to create events.
int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -32,7 +32,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
switch (opt) { //!OCLINT(too few branches) switch (opt) { //!OCLINT(too few branches)
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case '?': { case '?': {
// We would normally invoke builtin_unknown_option() and return an error. // We would normally invoke builtin_unknown_option() and return an error.

View File

@ -152,7 +152,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
} }
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case ':': { case ':': {
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]);

View File

@ -37,19 +37,18 @@ struct cmd_opts {
bool verbose = false; bool verbose = false;
wchar_t *description = NULL; wchar_t *description = NULL;
}; };
static const wchar_t *short_options = L"Dacehnqv";
static const struct woption long_options[] = {
{L"erase", no_argument, NULL, 'e'}, {L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'}, {L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'}, {L"query", no_argument, NULL, 'q'},
{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, static int parse_cmd_opts(struct cmd_opts *opts,
int *optind, //!OCLINT(high ncss method) int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"Dacehnqv";
static const struct woption long_options[] = {
{L"erase", no_argument, NULL, 'e'}, {L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'}, {L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'}, {L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'}, {L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}};
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) {
@ -80,7 +79,7 @@ static int parse_cmd_opts(struct cmd_opts *opts,
} }
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case 'q': { case 'q': {
opts->query = true; opts->query = true;

View File

@ -167,7 +167,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
} }
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case ':': { case ':': {
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]);

View File

@ -1,60 +1,22 @@
// Implementation of the pwd builtin. // Implementation of the pwd builtin.
#include "config.h" // IWYU pragma: keep #include "config.h" // IWYU pragma: keep
#include <stddef.h>
#include "builtin.h" #include "builtin.h"
#include "builtin_pwd.h" #include "builtin_pwd.h"
#include "common.h" #include "common.h"
#include "event.h"
#include "fallback.h" // IWYU pragma: keep #include "fallback.h" // IWYU pragma: keep
#include "io.h" #include "io.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
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_cmd_opts(struct cmd_opts *opts, int *optind,
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
wgetopter_t w;
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;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// The pwd builtin. We don't respect -P to resolve symbolic links because we /// The pwd builtin. We don't respect -P to resolve symbolic links because we
/// try to always resolve them. /// try to always resolve them.
int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
UNUSED(parser); UNUSED(parser);
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -2,7 +2,6 @@
#include "config.h" // IWYU pragma: keep #include "config.h" // IWYU pragma: keep
#include <errno.h> #include <errno.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <wchar.h> #include <wchar.h>
@ -14,51 +13,16 @@
#include "common.h" #include "common.h"
#include "fallback.h" // IWYU pragma: keep #include "fallback.h" // IWYU pragma: keep
#include "io.h" #include "io.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
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_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;
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;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// The random builtin generates random numbers. /// The random builtin generates random numbers.
int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -146,7 +146,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
} }
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case ':': { case ':': {
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]);

View File

@ -32,7 +32,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
switch (opt) { //!OCLINT(too few branches) switch (opt) { //!OCLINT(too few branches)
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case '?': { case '?': {
// We would normally invoke builtin_unknown_option() and return an error. // We would normally invoke builtin_unknown_option() and return an error.

View File

@ -16,51 +16,17 @@
#include "parser.h" #include "parser.h"
#include "proc.h" #include "proc.h"
#include "reader.h" #include "reader.h"
#include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
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_cmd_opts(struct cmd_opts *opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt;
wgetopter_t w;
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;
return STATUS_CMD_OK;
}
case '?': {
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
}
default: {
DIE("unexpected retval from wgetopt_long");
break;
}
}
}
*optind = w.woptind;
return STATUS_CMD_OK;
}
/// The source builtin, sometimes called `.`. Evaluates the contents of a file in the current /// The source builtin, sometimes called `.`. Evaluates the contents of a file in the current
/// context. /// context.
int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct cmd_opts opts; struct cmd_opts_help_only opts;
int optind; int optind;
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View File

@ -193,7 +193,7 @@ static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high nc
} }
case 'h': { case 'h': {
opts->print_help = true; opts->print_help = true;
return STATUS_CMD_OK; break;
} }
case ':': { case ':': {
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);