Adopt the builtin prelude

This commit is contained in:
Henrik Hørlück Berg 2023-08-09 00:17:10 +02:00 committed by Johannes Altmanninger
parent 773bafb7c7
commit 131e249b0c
26 changed files with 56 additions and 269 deletions

View file

@ -1,20 +1,10 @@
use super::prelude::*;
use crate::abbrs::{self, Abbreviation, Position};
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_error_trailer, builtin_print_help,
builtin_unknown_option, io_streams_t, BUILTIN_ERR_TOO_MANY_ARGUMENTS, STATUS_CMD_ERROR,
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::common::{escape, escape_string, valid_func_name, EscapeStringStyle};
use crate::env::status::{ENV_NOT_FOUND, ENV_OK};
use crate::env::EnvMode;
use crate::ffi::parser_t;
use crate::re::{regex_make_anchored, to_boxed_chars};
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::wgettext_fmt;
use libc::c_int;
use pcre2::utf32::{Regex, RegexBuilder};
pub use widestring::Utf32String as WString;
const CMD: &wstr = L!("abbr");

View file

@ -1,20 +1,10 @@
use std::collections::HashMap;
use crate::builtins::shared::builtin_print_error_trailer;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
BUILTIN_ERR_MAX_ARG_COUNT1, BUILTIN_ERR_MIN_ARG_COUNT1, BUILTIN_ERR_UNKNOWN, STATUS_CMD_ERROR,
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::env::{EnvMode, EnvStack};
use crate::ffi::parser_t;
use crate::ffi::Repin;
use crate::wchar::{wstr, WString, L};
use crate::wchar_ext::WExt;
use crate::wcstringutil::split_string;
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t, NONOPTION_CHAR_CODE};
use crate::wutil::{fish_iswalnum, fish_wcstol, wgettext_fmt};
use libc::c_int;
use crate::wutil::fish_iswalnum;
const VAR_NAME_PREFIX: &wstr = L!("_flag_");
@ -99,8 +89,6 @@ fn exec_subshell(
) -> Option<c_int> {
use crate::ffi::exec_subshell_ffi;
use crate::wchar_ffi::wcstring_list_ffi_t;
use crate::wchar_ffi::WCharFromFFI;
use crate::wchar_ffi::WCharToFFI;
let mut cmd_output: cxx::UniquePtr<wcstring_list_ffi_t> = wcstring_list_ffi_t::create();
let retval = Some(

View file

@ -2,15 +2,7 @@
use std::pin::Pin;
use super::shared::{builtin_print_help, io_streams_t, STATUS_CMD_ERROR, STATUS_INVALID_ARGS};
use crate::{
builtins::shared::{HelpOnlyCmdOpts, STATUS_CMD_OK},
ffi::{self, parser_t, Repin},
wchar::wstr,
wchar_ffi::{c_str, WCharFromFFI, WCharToFFI},
wutil::{fish_wcstoi, wgettext_fmt},
};
use libc::c_int;
use super::prelude::*;
/// Helper function for builtin_bg().
fn send_to_bg(

View file

@ -1,16 +1,5 @@
// Implementation of the block builtin.
use super::shared::{
builtin_missing_argument, builtin_print_help, io_streams_t, STATUS_CMD_ERROR, STATUS_CMD_OK,
STATUS_INVALID_ARGS,
};
use crate::{
builtins::shared::builtin_unknown_option,
ffi::{parser_t, Repin},
wchar::{wstr, L},
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t},
wutil::wgettext_fmt,
};
use libc::c_int;
use super::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Scope {

View file

@ -1,16 +1,5 @@
use libc::c_int;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
BUILTIN_ERR_COMBO2, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::ffi::parser_t;
use super::prelude::*;
use crate::ffi::{builtin_exists, builtin_get_names_ffi};
use crate::wchar::{wstr, WString, L};
use crate::wchar_ffi::WCharFromFFI;
use crate::wchar_ffi::WCharToFFI;
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::{wgettext, wgettext_fmt};
#[derive(Default)]
struct builtin_cmd_opts_t {

View file

@ -1,18 +1,14 @@
// Implementation of the cd builtin.
use super::shared::{builtin_print_help, io_streams_t, STATUS_CMD_ERROR};
use super::prelude::*;
use crate::{
builtins::shared::{HelpOnlyCmdOpts, STATUS_CMD_OK},
env::{EnvMode, Environment},
fds::{wopen_cloexec, AutoCloseFd},
ffi::{parser_t, Repin},
path::path_apply_cdpath,
wchar::{wstr, WString, L},
wchar_ffi::{WCharFromFFI, WCharToFFI},
wutil::{normalize_path, wgettext_fmt, wperror, wreadlink},
wutil::{normalize_path, wperror, wreadlink},
};
use errno::{self, Errno};
use libc::{c_int, fchdir, EACCES, ELOOP, ENOENT, ENOTDIR, EPERM, O_RDONLY};
use libc::{fchdir, EACCES, ELOOP, ENOENT, ENOTDIR, EPERM, O_RDONLY};
// 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.

View file

@ -1,14 +1,5 @@
use libc::c_int;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
STATUS_CMD_OK, STATUS_CMD_UNKNOWN, STATUS_INVALID_ARGS,
};
use crate::ffi::parser_t;
use super::prelude::*;
use crate::path::{path_get_path, path_get_paths};
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::sprintf;
#[derive(Default)]
struct command_cmd_opts_t {

View file

@ -1,14 +1,5 @@
// Implementation of the contains builtin.
use super::shared::{
builtin_missing_argument, builtin_print_help, io_streams_t, STATUS_CMD_ERROR, STATUS_CMD_OK,
STATUS_INVALID_ARGS,
};
use crate::builtins::shared::builtin_unknown_option;
use crate::ffi::parser_t;
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::wgettext_fmt;
use libc::c_int;
use super::prelude::*;
#[derive(Debug, Clone, Copy, Default)]
struct Options {

View file

@ -1,11 +1,7 @@
//! Implementation of the echo builtin.
use libc::c_int;
use super::shared::{builtin_missing_argument, io_streams_t, STATUS_CMD_OK, STATUS_INVALID_ARGS};
use crate::ffi::parser_t;
use crate::wchar::{encode_byte_to_char, wstr, WString, L};
use crate::wgetopt::{wgetopter_t, woption};
use super::prelude::*;
use crate::wchar::encode_byte_to_char;
#[derive(Debug, Clone, Copy)]
struct Options {

View file

@ -1,10 +1,5 @@
use super::shared::{
builtin_print_help, io_streams_t, HelpOnlyCmdOpts, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::event;
use crate::ffi::parser_t;
use crate::wchar::prelude::*;
use libc::c_int;
#[widestrs]
pub fn emit(

View file

@ -1,9 +1,5 @@
use libc::c_int;
use super::prelude::*;
use super::r#return::parse_return_value;
use super::shared::io_streams_t;
use crate::ffi::parser_t;
use crate::wchar::wstr;
/// Function for handling the exit builtin.
pub fn exit(

View file

@ -1,24 +1,16 @@
use super::shared::{
builtin_missing_argument, builtin_print_error_trailer, builtin_unknown_option, io_streams_t,
truncate_args_on_nul, BUILTIN_ERR_VARNAME, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::ast::BlockStatement;
use crate::builtins::shared::STATUS_CMD_OK;
use crate::common::{valid_func_name, valid_var_name};
use crate::env::environment::Environment;
use crate::event::{self, EventDescription, EventHandler};
use crate::ffi::{self, io_streams_t as io_streams_ffi_t, parser_t, Repin};
use crate::ffi::io_streams_t as io_streams_ffi_t;
use crate::function;
use crate::global_safety::RelaxedAtomicBool;
use crate::parse_tree::NodeRef;
use crate::parse_tree::ParsedSourceRefFFI;
use crate::parser_keywords::parser_keywords_is_reserved;
use crate::signal::Signal;
use crate::wchar::{wstr, WString, L};
use crate::wchar_ffi::{wcstring_list_ffi_t, WCharFromFFI, WCharToFFI};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t, NONOPTION_CHAR_CODE};
use crate::wutil::{fish_wcstoi, wgettext_fmt};
use libc::c_int;
use std::pin::Pin;
use std::sync::Arc;

View file

@ -1,16 +1,9 @@
use libc::c_int;
use std::borrow::Cow;
use super::shared::{
builtin_missing_argument, builtin_print_help, io_streams_t, BUILTIN_ERR_COMBO2,
BUILTIN_ERR_MIN_ARG_COUNT1, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::common::{read_blocked, str2wcstring};
use crate::ffi::parser_t;
use crate::tinyexpr::te_interp;
use crate::wchar::prelude::*;
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::{fish_wcstoi, perror};
use crate::wutil::perror;
/// The maximum number of points after the decimal that we'll print.
const DEFAULT_SCALE: usize = 6;

View file

@ -3,6 +3,7 @@ use std::cmp::Ordering;
use std::os::unix::prelude::{FileTypeExt, MetadataExt};
use std::time::SystemTime;
use super::prelude::*;
use crate::path::path_apply_working_directory;
use crate::util::wcsfilecmp_glob;
use crate::wcstringutil::split_string_tok;
@ -10,23 +11,8 @@ use crate::wutil::{
file_id_for_path, lwstat, normalize_path, waccess, wbasename, wdirname, wrealpath, wstat,
INVALID_FILE_ID,
};
use crate::{
builtins::shared::{
builtin_missing_argument, builtin_print_error_trailer, builtin_print_help, io_streams_t,
Arguments, SplitBehavior, BUILTIN_ERR_ARG_COUNT0, BUILTIN_ERR_INVALID_SUBCMD,
BUILTIN_ERR_MISSING_SUBCMD, BUILTIN_ERR_TOO_MANY_ARGUMENTS, BUILTIN_ERR_UNKNOWN,
STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
},
ffi::{parser_t, separation_type_t},
wchar::{wstr, WString, L},
wchar_ext::{ToWString, WExt},
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t::*, NONOPTION_CHAR_CODE},
wutil::wgettext_fmt,
};
use bitflags::bitflags;
use libc::{
c_int, getegid, geteuid, mode_t, uid_t, F_OK, PATH_MAX, R_OK, S_ISGID, S_ISUID, W_OK, X_OK,
};
use libc::{getegid, geteuid, mode_t, uid_t, F_OK, PATH_MAX, R_OK, S_ISGID, S_ISUID, W_OK, X_OK};
use super::shared::BuiltinCmd;

View file

@ -48,19 +48,17 @@
// This file has been imported from source code of printf command in GNU Coreutils version 6.9.
use libc::c_int;
use num_traits;
use std::result::Result;
use crate::builtins::shared::{io_streams_t, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS};
use crate::ffi::parser_t;
use super::prelude::*;
use crate::locale::{get_numeric_locale, Locale};
use crate::wchar::{encode_byte_to_char, wstr, WExt, WString, L};
use crate::wutil::errors::Error;
use crate::wutil::gettext::{wgettext, wgettext_fmt};
use crate::wutil::wcstod::wcstod;
use crate::wutil::wcstoi::{wcstoi_partial, Options as WcstoiOpts};
use crate::wutil::{sprintf, wstr_offset_in};
use crate::wchar::encode_byte_to_char;
use crate::wutil::{
errors::Error,
wcstod::wcstod,
wcstoi::{wcstoi_partial, Options as WcstoiOpts},
wstr_offset_in,
};
use printf_compat::args::ToArg;
use printf_compat::printf::sprintf_locale;

View file

@ -1,21 +1,8 @@
//! Implementation of the pwd builtin.
use errno::errno;
use libc::c_int;
use crate::{
builtins::shared::{io_streams_t, BUILTIN_ERR_ARG_COUNT1},
env::EnvMode,
ffi::parser_t,
wchar::{wstr, WString, L},
wchar_ffi::{WCharFromFFI, WCharToFFI},
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t::no_argument},
wutil::{wgettext_fmt, wrealpath},
};
use super::shared::{
builtin_print_help, builtin_unknown_option, STATUS_CMD_ERROR, STATUS_CMD_OK,
STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::{env::EnvMode, wutil::wrealpath};
// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default).
const short_options: &wstr = L!("LPh");

View file

@ -1,13 +1,6 @@
use libc::c_int;
use super::prelude::*;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::ffi::parser_t;
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::{self, fish_wcstol, fish_wcstoul, sprintf, wgettext_fmt};
use crate::wutil;
use once_cell::sync::Lazy;
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};

View file

@ -1,20 +1,11 @@
//! Implementation of the realpath builtin.
use errno::errno;
use libc::c_int;
use super::prelude::*;
use crate::{
ffi::parser_t,
path::path_apply_working_directory,
wchar::{wstr, WExt, L},
wchar_ffi::AsWstr,
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t::no_argument},
wutil::{normalize_path, wgettext_fmt, wrealpath},
};
use super::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
BUILTIN_ERR_ARG_COUNT1, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
wutil::{normalize_path, wrealpath},
};
#[derive(Default)]

View file

@ -1,18 +1,8 @@
// Implementation of the return builtin.
use libc::c_int;
use num_traits::abs;
use super::shared::{
builtin_missing_argument, builtin_print_error_trailer, builtin_print_help, io_streams_t,
BUILTIN_ERR_NOT_NUMBER, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::builtins::shared::BUILTIN_ERR_TOO_MANY_ARGUMENTS;
use crate::ffi::parser_t;
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::fish_wcstoi;
use crate::wutil::wgettext_fmt;
use super::prelude::*;
#[derive(Debug, Clone, Copy, Default)]
struct Options {

View file

@ -1,18 +1,10 @@
// Implementation of the set_color builtin.
use super::shared::{
builtin_print_help, builtin_unknown_option, io_streams_t, STATUS_CMD_ERROR, STATUS_CMD_OK,
STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::color::RgbColor;
use crate::common::str2wcstring;
use crate::curses::{self, Term};
use crate::ffi::parser_t;
use crate::output::{self, Outputter};
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::wgettext_fmt;
use libc::c_int;
#[allow(clippy::too_many_arguments)]
fn print_modifiers(

View file

@ -1,26 +1,13 @@
use std::os::unix::prelude::OsStrExt;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
BUILTIN_ERR_ARG_COUNT2, BUILTIN_ERR_COMBO2_EXCLUSIVE, BUILTIN_ERR_INVALID_SUBCMD,
BUILTIN_ERR_NOT_NUMBER, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::common::{get_executable_path, str2wcstring};
use crate::ffi::{
get_job_control_mode, get_login, is_interactive_session, job_control_t, parser_t,
set_job_control_mode, Repin,
get_job_control_mode, get_login, is_interactive_session, job_control_t, set_job_control_mode,
};
use crate::future_feature_flags::{self as features, feature_test};
use crate::wchar::{wstr, L};
use crate::wchar_ffi::{AsWstr, WCharFromFFI};
use crate::wgetopt::{
wgetopter_t, wopt, woption,
woption_argument_t::{no_argument, required_argument},
};
use crate::wutil::{
fish_wcstoi, sprintf, waccess, wbasename, wdirname, wgettext, wgettext_fmt, wrealpath, Error,
};
use libc::{c_int, F_OK};
use crate::wutil::{waccess, wbasename, wdirname, wrealpath, Error};
use libc::F_OK;
use nix::errno::Errno;
use nix::NixPath;
use num_derive::FromPrimitive;

View file

@ -1,20 +1,7 @@
use crate::wcstringutil::fish_wcwidth_visible;
// Forward some imports to make subcmd implementations easier
use crate::{
builtins::shared::{
builtin_missing_argument, builtin_print_error_trailer, builtin_print_help, io_streams_t,
Arguments, SplitBehavior, BUILTIN_ERR_ARG_COUNT0, BUILTIN_ERR_ARG_COUNT1,
BUILTIN_ERR_COMBO2, BUILTIN_ERR_INVALID_SUBCMD, BUILTIN_ERR_MISSING_SUBCMD,
BUILTIN_ERR_NOT_NUMBER, BUILTIN_ERR_TOO_MANY_ARGUMENTS, BUILTIN_ERR_UNKNOWN,
STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
},
ffi::{parser_t, separation_type_t},
wchar::{wstr, WString, L},
wchar_ext::{ToWString, WExt},
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t::*, NONOPTION_CHAR_CODE},
wutil::{wgettext, wgettext_fmt},
};
use libc::c_int;
use super::prelude::*;
use crate::ffi::separation_type_t;
mod collect;
mod escape;

View file

@ -1,19 +1,12 @@
use libc::c_int;
use crate::builtins::shared::{
builtin_print_error_trailer, io_streams_t, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use super::prelude::*;
use crate::common;
use crate::ffi::parser_t;
use crate::ffi::Repin;
use crate::wchar::prelude::*;
use crate::wchar_ffi::AsWstr;
mod test_expressions {
use super::*;
use crate::wutil::{
file_id_for_path, fish_wcstol, fish_wcswidth, lwstat, waccess, wcstod::wcstod, wcstoi_opts,
wstat, Error, Options,
file_id_for_path, fish_wcswidth, lwstat, waccess, wcstod::wcstod, wcstoi_opts, wstat,
Error, Options,
};
use once_cell::sync::Lazy;
use std::collections::HashMap;

View file

@ -1,8 +1,7 @@
use crate::builtins::shared::{io_streams_t, STATUS_CMD_OK, STATUS_INVALID_ARGS};
use crate::builtins::prelude::*;
use crate::builtins::test::test as builtin_test;
use crate::ffi::{make_null_io_streams_ffi, parser_t};
use crate::wchar::prelude::*;
use crate::ffi::make_null_io_streams_ffi;
fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> bool {
let parser: &mut parser_t = unsafe { &mut *parser_t::principal_parser_ffi() };

View file

@ -1,20 +1,11 @@
use libc::c_int;
use libc::isatty;
use libc::STDOUT_FILENO;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
BUILTIN_ERR_COMBO, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::ffi::parser_t;
use crate::ffi::Repin;
use super::prelude::*;
use crate::ffi::{builtin_exists, colorize_shell};
use crate::function;
use crate::path::{path_get_path, path_get_paths};
use crate::wchar::prelude::*;
use crate::wchar_ffi::WCharFromFFI;
use crate::wchar_ffi::WCharToFFI;
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
#[derive(Default)]
struct type_cmd_opts_t {

View file

@ -1,15 +1,10 @@
use libc::{c_int, pid_t};
use libc::pid_t;
use crate::builtins::shared::{
builtin_missing_argument, builtin_print_help, builtin_unknown_option, io_streams_t,
STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::ffi::{job_t, parser_t, proc_wait_any, Repin};
use super::prelude::*;
use crate::ffi::{job_t, parser_t, proc_wait_any};
use crate::signal::SigChecker;
use crate::wait_handle::{WaitHandleRef, WaitHandleStore};
use crate::wchar::{widestrs, wstr};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::{self, fish_wcstoi, wgettext_fmt};
use crate::wutil;
/// \return true if we can wait on a job.
fn can_wait_on_job(j: &cxx::SharedPtr<job_t>) -> bool {