2016-04-19 02:25:12 +00:00
|
|
|
// Prototypes for functions for executing builtin functions.
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_BUILTIN_H
|
|
|
|
#define FISH_BUILTIN_H
|
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
#include <stddef.h>
|
2017-02-14 04:37:27 +00:00
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2012-01-16 16:56:47 +00:00
|
|
|
#include "common.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2015-07-25 15:14:25 +00:00
|
|
|
class completion_t;
|
2012-01-16 20:10:08 +00:00
|
|
|
class parser_t;
|
2016-04-21 06:00:54 +00:00
|
|
|
class output_stream_t;
|
|
|
|
struct io_streams_t;
|
2012-01-16 20:10:08 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Data structure to describe a builtin.
|
|
|
|
struct builtin_data_t {
|
|
|
|
// Name of the builtin.
|
2018-09-29 04:22:24 +00:00
|
|
|
const wchar_t *name;
|
|
|
|
// Function pointer tothe builtin implementation.
|
2016-08-16 22:30:49 +00:00
|
|
|
int (*func)(parser_t &parser, io_streams_t &streams, wchar_t **argv);
|
|
|
|
// Description of what the builtin does.
|
2018-09-29 04:22:24 +00:00
|
|
|
const wchar_t *desc;
|
2016-08-16 22:30:49 +00:00
|
|
|
|
2018-09-29 04:22:24 +00:00
|
|
|
bool operator<(const wcstring &) const;
|
|
|
|
bool operator<(const builtin_data_t *) const;
|
2016-08-16 22:30:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// The default prompt for the read command.
|
|
|
|
#define DEFAULT_READ_PROMPT L"set_color green; echo -n read; set_color normal; echo -n \"> \""
|
|
|
|
|
2016-04-19 02:25:12 +00:00
|
|
|
enum { COMMAND_NOT_BUILTIN, BUILTIN_REGULAR, BUILTIN_FUNCTION };
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on missing argument.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_MISSING _(L"%ls: Expected argument for option %ls\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on invalid combination of options.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_COMBO _(L"%ls: Invalid combination of options\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on invalid combination of options.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_COMBO2 _(L"%ls: Invalid combination of options,\n%ls\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on multiple scope levels for variables.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_GLOCAL \
|
|
|
|
_(L"%ls: Variable scope can only be one of universal, global and local\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for specifying both export and unexport to set/read.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_EXPUNEXP _(L"%ls: Variable can't be both exported and unexported\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for unknown switch.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_UNKNOWN _(L"%ls: Unknown option '%ls'\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for unexpected args.
|
2017-07-20 03:22:34 +00:00
|
|
|
#define BUILTIN_ERR_ARG_COUNT1 _(L"%ls: Expected %d args, got %d\n")
|
|
|
|
#define BUILTIN_ERR_ARG_COUNT2 _(L"%ls %ls: Expected %d args, got %d\n")
|
2017-07-12 00:15:11 +00:00
|
|
|
#define BUILTIN_ERR_MIN_ARG_COUNT1 _(L"%ls: Expected at least %d args, got only %d\n")
|
|
|
|
#define BUILTIN_ERR_MAX_ARG_COUNT1 _(L"%ls: Expected at most %d args, got %d\n")
|
2016-07-14 05:33:50 +00:00
|
|
|
|
2017-04-20 06:43:02 +00:00
|
|
|
/// Error message for invalid variable name.
|
|
|
|
#define BUILTIN_ERR_VARNAME _(L"%ls: Variable name '%ls' is not valid. See `help identifiers`.\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2017-04-23 03:33:56 +00:00
|
|
|
/// Error message for invalid bind mode name.
|
|
|
|
#define BUILTIN_ERR_BIND_MODE _(L"%ls: mode name '%ls' is not valid. See `help identifiers`.\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message when too many arguments are supplied to a builtin.
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_TOO_MANY_ARGUMENTS _(L"%ls: Too many arguments\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message when number expected
|
2016-04-19 02:25:12 +00:00
|
|
|
#define BUILTIN_ERR_NOT_NUMBER _(L"%ls: Argument '%ls' is not a number\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2017-06-20 04:05:34 +00:00
|
|
|
/// Command that requires a subcommand was invoked without a recognized subcommand.
|
|
|
|
#define BUILTIN_ERR_MISSING_SUBCMD _(L"%ls: Expected a subcommand to follow the command\n")
|
|
|
|
#define BUILTIN_ERR_INVALID_SUBCMD _(L"%ls: Subcommand '%ls' is not valid\n")
|
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// The send stuff to foreground message.
|
|
|
|
#define FG_MSG _(L"Send job %d, '%ls' to foreground\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
void builtin_init();
|
|
|
|
bool builtin_exists(const wcstring &cmd);
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2018-08-18 23:56:01 +00:00
|
|
|
int builtin_run(parser_t &parser, int job_pgrp, wchar_t **argv, io_streams_t &streams);
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2015-07-28 01:45:47 +00:00
|
|
|
wcstring_list_t builtin_get_names();
|
|
|
|
void builtin_get_names(std::vector<completion_t> *list);
|
2012-11-19 00:30:30 +00:00
|
|
|
wcstring builtin_get_desc(const wcstring &b);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Support for setting and removing transient command lines. This is used by
|
|
|
|
/// 'complete -C' in order to make the commandline builtin operate on the string
|
|
|
|
/// to complete instead of operating on whatever is to be completed. It's also
|
|
|
|
/// used by completion wrappers, to allow a command to appear as the command
|
|
|
|
/// being wrapped for the purposes of completion.
|
|
|
|
///
|
|
|
|
/// Instantiating an instance of builtin_commandline_scoped_transient_t pushes
|
|
|
|
/// the command as the new transient commandline. The destructor removes it. It
|
|
|
|
/// will assert if construction/destruction does not happen in a stack-like
|
|
|
|
/// (LIFO) order.
|
2016-04-19 02:25:12 +00:00
|
|
|
class builtin_commandline_scoped_transient_t {
|
2014-08-16 01:14:36 +00:00
|
|
|
size_t token;
|
2016-04-19 02:25:12 +00:00
|
|
|
|
|
|
|
public:
|
2016-02-28 03:38:15 +00:00
|
|
|
explicit builtin_commandline_scoped_transient_t(const wcstring &cmd);
|
2014-08-16 01:14:36 +00:00
|
|
|
~builtin_commandline_scoped_transient_t();
|
|
|
|
};
|
2006-01-30 16:51:50 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
|
2006-06-13 13:43:28 +00:00
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
|
|
|
output_stream_t &b);
|
|
|
|
int builtin_count_args(const wchar_t *const *argv);
|
|
|
|
|
|
|
|
void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
|
|
|
const wchar_t *opt);
|
|
|
|
|
|
|
|
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
|
|
|
const wchar_t *opt);
|
|
|
|
|
|
|
|
void builtin_wperror(const wchar_t *s, io_streams_t &streams);
|
2017-06-15 01:25:51 +00:00
|
|
|
|
2017-06-17 03:42:33 +00:00
|
|
|
struct help_only_cmd_opts_t {
|
2017-06-15 01:25:51 +00:00
|
|
|
bool print_help = false;
|
|
|
|
};
|
2017-06-17 03:42:33 +00:00
|
|
|
int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
|
2017-06-15 01:25:51 +00:00
|
|
|
parser_t &parser, io_streams_t &streams);
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|