mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 09:22:44 +08:00
Refactor read_init, it is not meant to fail
This commit is contained in:
parent
af03f2ce6d
commit
bd91497de2
79
src/fish.cpp
79
src/fish.cpp
|
@ -236,7 +236,7 @@ static void source_config_in_directory(parser_t &parser, const wcstring &dir) {
|
|||
}
|
||||
|
||||
/// Parse init files. exec_path is the path of fish executable as determined by argv[0].
|
||||
static int read_init(parser_t &parser, const struct config_paths_t &paths) {
|
||||
static void read_init(parser_t &parser, const struct config_paths_t &paths) {
|
||||
source_config_in_directory(parser, paths.data);
|
||||
source_config_in_directory(parser, paths.sysconf);
|
||||
|
||||
|
@ -247,8 +247,6 @@ static int read_init(parser_t &parser, const struct config_paths_t &paths) {
|
|||
if (path_get_config(config_dir)) {
|
||||
source_config_in_directory(parser, config_dir);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int run_command_list(parser_t &parser, std::vector<std::string> *cmds, const io_chain_t &io) {
|
||||
|
@ -473,48 +471,47 @@ int main(int argc, char **argv) {
|
|||
|
||||
parser_t &parser = parser_t::principal_parser();
|
||||
|
||||
if (read_init(parser, paths)) {
|
||||
// Stomp the exit status of any initialization commands (issue #635).
|
||||
parser.set_last_statuses(statuses_t::just(STATUS_CMD_OK));
|
||||
read_init(parser, paths);
|
||||
// Stomp the exit status of any initialization commands (issue #635).
|
||||
parser.set_last_statuses(statuses_t::just(STATUS_CMD_OK));
|
||||
|
||||
// Run post-config commands specified as arguments, if any.
|
||||
if (!opts.postconfig_cmds.empty()) {
|
||||
res = run_command_list(parser, &opts.postconfig_cmds, {});
|
||||
// Run post-config commands specified as arguments, if any.
|
||||
if (!opts.postconfig_cmds.empty()) {
|
||||
res = run_command_list(parser, &opts.postconfig_cmds, {});
|
||||
}
|
||||
|
||||
if (!opts.batch_cmds.empty()) {
|
||||
// Run the commands specified as arguments, if any.
|
||||
if (get_login()) {
|
||||
// Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds.
|
||||
fish_xdm_login_hack_hack_hack_hack(&opts.batch_cmds, argc - my_optind,
|
||||
argv + my_optind);
|
||||
}
|
||||
|
||||
if (!opts.batch_cmds.empty()) {
|
||||
// Run the commands specified as arguments, if any.
|
||||
if (get_login()) {
|
||||
// Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds.
|
||||
fish_xdm_login_hack_hack_hack_hack(&opts.batch_cmds, argc - my_optind,
|
||||
argv + my_optind);
|
||||
}
|
||||
res = run_command_list(parser, &opts.batch_cmds, {});
|
||||
reader_set_end_loop(false);
|
||||
} else if (my_optind == argc) {
|
||||
// Implicitly interactive mode.
|
||||
res = reader_read(parser, STDIN_FILENO, {});
|
||||
res = run_command_list(parser, &opts.batch_cmds, {});
|
||||
reader_set_end_loop(false);
|
||||
} else if (my_optind == argc) {
|
||||
// Implicitly interactive mode.
|
||||
res = reader_read(parser, STDIN_FILENO, {});
|
||||
} else {
|
||||
const char *file = *(argv + (my_optind++));
|
||||
autoclose_fd_t fd(open_cloexec(file, O_RDONLY));
|
||||
if (!fd.valid()) {
|
||||
perror(file);
|
||||
} else {
|
||||
const char *file = *(argv + (my_optind++));
|
||||
autoclose_fd_t fd(open_cloexec(file, O_RDONLY));
|
||||
if (!fd.valid()) {
|
||||
perror(file);
|
||||
} else {
|
||||
wcstring_list_t list;
|
||||
for (char **ptr = argv + my_optind; *ptr; ptr++) {
|
||||
list.push_back(str2wcstring(*ptr));
|
||||
}
|
||||
parser.vars().set(L"argv", ENV_DEFAULT, std::move(list));
|
||||
wcstring_list_t list;
|
||||
for (char **ptr = argv + my_optind; *ptr; ptr++) {
|
||||
list.push_back(str2wcstring(*ptr));
|
||||
}
|
||||
parser.vars().set(L"argv", ENV_DEFAULT, std::move(list));
|
||||
|
||||
auto &ld = parser.libdata();
|
||||
wcstring rel_filename = str2wcstring(file);
|
||||
scoped_push<const wchar_t *> filename_push{&ld.current_filename,
|
||||
intern(rel_filename.c_str())};
|
||||
res = reader_read(parser, fd.fd(), {});
|
||||
if (res) {
|
||||
FLOGF(warning, _(L"Error while reading file %ls\n"),
|
||||
ld.current_filename ? ld.current_filename : _(L"Standard input"));
|
||||
}
|
||||
auto &ld = parser.libdata();
|
||||
wcstring rel_filename = str2wcstring(file);
|
||||
scoped_push<const wchar_t *> filename_push{&ld.current_filename,
|
||||
intern(rel_filename.c_str())};
|
||||
res = reader_read(parser, fd.fd(), {});
|
||||
if (res) {
|
||||
FLOGF(warning, _(L"Error while reading file %ls\n"),
|
||||
ld.current_filename ? ld.current_filename : _(L"Standard input"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user