1 // Prototypes for functions for executing builtin functions. 2 #ifndef FISH_BUILTIN_H 3 #define FISH_BUILTIN_H 4 5 #include <stddef.h> 6 7 #include <vector> 8 9 #include "common.h" 10 11 class completion_t; 12 class parser_t; 13 class proc_status_t; 14 class output_stream_t; 15 struct io_streams_t; 16 using completion_list_t = std::vector<completion_t>; 17 18 /// Data structure to describe a builtin. 19 struct builtin_data_t { 20 // Name of the builtin. 21 const wchar_t *name; 22 // Function pointer to the builtin implementation. 23 maybe_t<int> (*func)(parser_t &parser, io_streams_t &streams, const wchar_t **argv); 24 // Description of what the builtin does. 25 const wchar_t *desc; 26 27 bool operator<(const wcstring &) const; 28 bool operator<(const builtin_data_t *) const; 29 }; 30 31 /// The default prompt for the read command. 32 #define DEFAULT_READ_PROMPT L"set_color green; echo -n read; set_color normal; echo -n \"> \"" 33 34 /// Error message on missing argument. 35 #define BUILTIN_ERR_MISSING _(L"%ls: Expected argument for option %ls\n") 36 37 /// Error message on missing man page. 38 #define BUILTIN_ERR_MISSING_HELP \ 39 _(L"fish: Missing man page for '%ls'. Did you install the documentation?\n`help '%ls'` will " \ 40 L"open the online version.\n") 41 42 /// Error message on invalid combination of options. 43 #define BUILTIN_ERR_COMBO _(L"%ls: Invalid combination of options\n") 44 45 /// Error message on invalid combination of options. 46 #define BUILTIN_ERR_COMBO2 _(L"%ls: Invalid combination of options,\n%ls\n") 47 48 /// Error message on multiple scope levels for variables. 49 #define BUILTIN_ERR_GLOCAL \ 50 _(L"%ls: Variable scope can only be one of universal, global and local\n") 51 52 /// Error message for specifying both export and unexport to set/read. 53 #define BUILTIN_ERR_EXPUNEXP _(L"%ls: Variable can't be both exported and unexported\n") 54 55 /// Error message for unknown switch. 56 #define BUILTIN_ERR_UNKNOWN _(L"%ls: Unknown option '%ls'\n") 57 58 /// Error message for unexpected args. 59 #define BUILTIN_ERR_ARG_COUNT0 _(L"%ls: Expected an argument\n") 60 #define BUILTIN_ERR_ARG_COUNT1 _(L"%ls: Expected %d args, got %d\n") 61 #define BUILTIN_ERR_ARG_COUNT2 _(L"%ls %ls: Expected %d args, got %d\n") 62 #define BUILTIN_ERR_MIN_ARG_COUNT1 _(L"%ls: Expected at least %d args, got %d\n") 63 #define BUILTIN_ERR_MAX_ARG_COUNT1 _(L"%ls: Expected at most %d args, got %d\n") 64 65 /// Error message for invalid variable name. 66 #define BUILTIN_ERR_VARNAME _(L"%ls: Variable name '%ls' is not valid. See `help identifiers`.\n") 67 68 /// Error message for invalid bind mode name. 69 #define BUILTIN_ERR_BIND_MODE _(L"%ls: mode name '%ls' is not valid. See `help identifiers`.\n") 70 71 /// Error message when too many arguments are supplied to a builtin. 72 #define BUILTIN_ERR_TOO_MANY_ARGUMENTS _(L"%ls: Too many arguments\n") 73 74 /// Error message when integer expected 75 #define BUILTIN_ERR_NOT_NUMBER _(L"%ls: Argument '%ls' is not a valid integer\n") 76 77 /// Command that requires a subcommand was invoked without a recognized subcommand. 78 #define BUILTIN_ERR_MISSING_SUBCMD _(L"%ls: Expected a subcommand to follow the command\n") 79 #define BUILTIN_ERR_INVALID_SUBCMD _(L"%ls: Subcommand '%ls' is not valid\n") 80 81 /// The send stuff to foreground message. 82 #define FG_MSG _(L"Send job %d, '%ls' to foreground\n") 83 84 void builtin_init(); 85 bool builtin_exists(const wcstring &cmd); 86 87 proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_streams_t &streams); 88 89 wcstring_list_t builtin_get_names(); 90 void builtin_get_names(completion_list_t *list); 91 const wchar_t *builtin_get_desc(const wcstring &name); 92 93 wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd); 94 95 void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name, 96 wcstring *error_message = nullptr); 97 int builtin_count_args(const wchar_t *const *argv); 98 99 void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar_t *cmd, 100 const wchar_t *opt); 101 102 void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd, 103 const wchar_t *opt, bool print_hints = true); 104 105 void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wchar_t *cmd); 106 107 void builtin_wperror(const wchar_t *s, io_streams_t &streams); 108 109 struct help_only_cmd_opts_t { 110 bool print_help = false; 111 }; 112 int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc, 113 const wchar_t **argv, parser_t &parser, io_streams_t &streams); 114 #endif 115