2005-09-20 21:26:39 +08:00
/** \file builtin.h
2012-11-18 18:23:22 +08:00
Prototypes for functions for executing builtin functions .
2005-09-20 21:26:39 +08:00
*/
2005-10-04 23:11:39 +08:00
# ifndef FISH_BUILTIN_H
# define FISH_BUILTIN_H
# include <wchar.h>
# include "util.h"
2007-04-26 02:30:02 +08:00
# include "io.h"
2012-01-17 00:56:47 +08:00
# include "common.h"
2005-09-20 21:26:39 +08:00
2012-01-17 04:10:08 +08:00
class parser_t ;
2005-09-20 21:26:39 +08:00
enum
{
2012-11-19 08:30:30 +08:00
COMMAND_NOT_BUILTIN ,
BUILTIN_REGULAR ,
BUILTIN_FUNCTION
2005-09-20 21:26:39 +08:00
}
;
2005-10-24 23:26:25 +08:00
/**
Error message on missing argument
*/
2006-01-04 20:51:02 +08:00
# define BUILTIN_ERR_MISSING _( L"%ls: Expected argument\n" )
2005-10-24 23:26:25 +08:00
/**
Error message on invalid combination of options
*/
2006-01-04 20:51:02 +08:00
# define BUILTIN_ERR_COMBO _( L"%ls: Invalid combination of options\n" )
/**
Error message on invalid combination of options
*/
# define BUILTIN_ERR_COMBO2 _( L"%ls: Invalid combination of options,\n%ls\n" )
2005-10-24 23:26:25 +08:00
/**
Error message on multiple scope levels for variables
*/
2007-02-01 00:03:17 +08:00
# define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n" )
2005-10-24 23:26:25 +08:00
/**
Error message for specifying both export and unexport to set / read
*/
2007-02-01 00:03:17 +08:00
# define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n" )
2005-10-24 23:26:25 +08:00
/**
Error message for unknown switch
*/
2012-11-18 18:23:22 +08:00
# define BUILTIN_ERR_UNKNOWN _( L"%ls: Unknown option '%ls'\n" )
2005-09-20 21:26:39 +08:00
2006-01-24 04:40:14 +08:00
/**
Error message for invalid character in variable name
*/
2006-01-04 20:51:02 +08:00
# define BUILTIN_ERR_VARCHAR _( L"%ls: Invalid character '%lc' in variable name. Only alphanumerical characters and underscores are valid in a variable name.\n" )
2005-12-08 00:06:47 +08:00
2006-01-24 04:40:14 +08:00
/**
Error message for invalid ( empty ) variable name
*/
2006-01-04 20:51:02 +08:00
# define BUILTIN_ERR_VARNAME_ZERO _( L"%ls: Variable name can not be the empty string\n" )
2005-12-08 00:06:47 +08:00
2006-05-22 06:16:04 +08:00
/**
Error message when second argument to for isn ' t ' in '
*/
# define BUILTIN_FOR_ERR_IN _( L"%ls: Second argument must be 'in'\n" )
2006-09-26 20:41:09 +08:00
/**
2012-11-18 18:23:22 +08:00
Error message for insufficient number of arguments
2006-09-26 20:41:09 +08:00
*/
# define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n")
2006-10-01 23:57:34 +08:00
# define BUILTIN_FOR_ERR_NAME _( L"%ls: '%ls' is not a valid variable name\n" )
2012-09-04 04:24:01 +08:00
/** Error messages for 'else if' */
# define BUILTIN_ELSEIF_ERR_COUNT _( L"%ls: can only take 'if' and then another command as an argument\n")
# define BUILTIN_ELSEIF_ERR_ARGUMENT _( L"%ls: any second argument must be 'if'\n")
2006-06-17 21:07:08 +08:00
/**
Error message when too many arguments are supplied to a builtin
*/
2006-05-26 19:24:02 +08:00
# define BUILTIN_ERR_TOO_MANY_ARGUMENTS _( L"%ls: Too many arguments\n" )
2006-09-06 04:43:47 +08:00
/**
Error message when block types mismatch in the end builtin , e . g . ' begin ; end for '
*/
# define BUILTIN_END_BLOCK_MISMATCH _( L"%ls: Block mismatch: '%ls' vs. '%ls'\n" )
/**
Error message for unknown block type in the end builtin , e . g . ' begin ; end beggin '
*/
# define BUILTIN_END_BLOCK_UNKNOWN _( L"%ls: Unknown block type '%ls'\n" )
2006-10-05 05:39:48 +08:00
# define BUILTIN_ERR_NOT_NUMBER _( L"%ls: Argument '%ls' is not a number\n" )
2012-02-23 02:51:06 +08:00
/** Get the string used to represent stdout and stderr */
const wcstring & get_stdout_buffer ( ) ;
const wcstring & get_stderr_buffer ( ) ;
2005-09-20 21:26:39 +08:00
2012-03-07 17:02:46 +08:00
/** Output an error */
void builtin_show_error ( const wcstring & err ) ;
2005-09-20 21:26:39 +08:00
/**
Kludge . Tells builtins if output is to screen
*/
extern int builtin_out_redirect ;
/**
Kludge . Tells builtins if error is to screen
*/
extern int builtin_err_redirect ;
/**
2012-11-18 18:23:22 +08:00
Initialize builtin data .
2005-09-20 21:26:39 +08:00
*/
void builtin_init ( ) ;
/**
Destroy builtin data .
*/
void builtin_destroy ( ) ;
/**
Is there a builtin command with the given name ?
*/
2012-11-19 08:30:30 +08:00
int builtin_exists ( const wcstring & cmd ) ;
2005-09-20 21:26:39 +08:00
/**
2012-11-18 18:23:22 +08:00
Execute a builtin command
2005-09-20 21:26:39 +08:00
2012-01-17 04:10:08 +08:00
\ param parser The parser being used
2012-11-18 18:23:22 +08:00
\ param argv Array containing the command and parameters
2005-09-20 21:26:39 +08:00
of the builtin . The list is terminated by a
2012-11-18 18:23:22 +08:00
null pointer . This syntax resembles the syntax
2005-09-20 21:26:39 +08:00
for exec .
2008-01-14 00:47:47 +08:00
\ param io the io redirections to perform on this builtin .
2005-09-20 21:26:39 +08:00
\ return the exit status of the builtin command
*/
2012-11-19 08:30:30 +08:00
int builtin_run ( parser_t & parser , const wchar_t * const * argv , const io_chain_t & io ) ;
2005-09-20 21:26:39 +08:00
2012-02-01 11:47:56 +08:00
/** Returns a list of all builtin names */
wcstring_list_t builtin_get_names ( void ) ;
2012-02-01 12:22:25 +08:00
/** Insert all builtin names into list. */
2012-02-01 11:47:56 +08:00
void builtin_get_names ( std : : vector < completion_t > & list ) ;
2012-01-17 00:56:47 +08:00
2005-09-20 21:26:39 +08:00
/**
2012-03-04 14:08:34 +08:00
Pushes a new set of input / output to the stack . The new stdin is supplied , a new set of output strings is created .
2005-09-20 21:26:39 +08:00
*/
2012-11-19 08:30:30 +08:00
void builtin_push_io ( parser_t & parser , int stdin_fd ) ;
2005-09-20 21:26:39 +08:00
/**
2012-03-04 14:08:34 +08:00
Pops a set of input / output from the stack . The output strings are destroued , but the input file is not closed .
2005-09-20 21:26:39 +08:00
*/
2012-01-17 04:10:08 +08:00
void builtin_pop_io ( parser_t & parser ) ;
2005-09-20 21:26:39 +08:00
/**
2012-05-18 10:37:46 +08:00
Return a one - line description of the specified builtin .
2005-09-20 21:26:39 +08:00
*/
2012-11-19 08:30:30 +08:00
wcstring builtin_get_desc ( const wcstring & b ) ;
2005-09-20 21:26:39 +08:00
2014-08-16 09:14:36 +08: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 .
*/
class builtin_commandline_scoped_transient_t
{
size_t token ;
public :
builtin_commandline_scoped_transient_t ( const wcstring & cmd ) ;
~ builtin_commandline_scoped_transient_t ( ) ;
} ;
2006-01-31 00:51:50 +08:00
2005-10-04 23:11:39 +08:00
2006-06-13 21:43:28 +08:00
/**
2007-10-02 18:09:37 +08:00
Run the __fish_print_help function to obtain the help information
2012-02-01 12:22:25 +08:00
for the specified command .
2006-06-13 21:43:28 +08:00
*/
2012-11-19 08:30:30 +08:00
wcstring builtin_help_get ( parser_t & parser , const wchar_t * cmd ) ;
2006-06-13 21:43:28 +08:00
2013-12-27 19:58:42 +08:00
/** Defines a function, like builtin_function. Returns 0 on success. args should NOT contain 'function' as the first argument. */
2014-03-17 07:45:00 +08:00
int define_function ( parser_t & parser , const wcstring_list_t & args , const wcstring & contents , int definition_line_offset , wcstring * out_err ) ;
2013-12-27 17:38:43 +08:00
2005-10-04 23:11:39 +08:00
# endif