mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 21:18:53 +00:00
restyle builtin module to match project style
Reduces lint errors from 271 to 215 (-21%). Line count from 4304 to 3242 (-25%). Another step in resolving issue #2902.
This commit is contained in:
parent
61c0ca9dd9
commit
a10a79c6d0
2 changed files with 1435 additions and 2497 deletions
3772
src/builtin.cpp
3772
src/builtin.cpp
File diff suppressed because it is too large
Load diff
160
src/builtin.h
160
src/builtin.h
|
@ -1,144 +1,100 @@
|
||||||
/** \file builtin.h
|
// Prototypes for functions for executing builtin functions.
|
||||||
Prototypes for functions for executing builtin functions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FISH_BUILTIN_H
|
#ifndef FISH_BUILTIN_H
|
||||||
#define FISH_BUILTIN_H
|
#define FISH_BUILTIN_H
|
||||||
|
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "io.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
class completion_t;
|
class completion_t;
|
||||||
class parser_t;
|
class parser_t;
|
||||||
|
|
||||||
enum
|
enum { COMMAND_NOT_BUILTIN, BUILTIN_REGULAR, BUILTIN_FUNCTION };
|
||||||
{
|
|
||||||
COMMAND_NOT_BUILTIN,
|
|
||||||
BUILTIN_REGULAR,
|
|
||||||
BUILTIN_FUNCTION
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
// Error message on missing argument.
|
||||||
Error message on missing argument
|
#define BUILTIN_ERR_MISSING _(L"%ls: Expected argument for option %ls\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_MISSING _( L"%ls: Expected argument for option %ls\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message on invalid combination of options.
|
||||||
Error message on invalid combination of options
|
#define BUILTIN_ERR_COMBO _(L"%ls: Invalid combination of options\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_COMBO _( L"%ls: Invalid combination of options\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message on invalid combination of options.
|
||||||
Error message on invalid combination of options
|
#define BUILTIN_ERR_COMBO2 _(L"%ls: Invalid combination of options,\n%ls\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_COMBO2 _( L"%ls: Invalid combination of options,\n%ls\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message on multiple scope levels for variables.
|
||||||
Error message on multiple scope levels for variables
|
#define BUILTIN_ERR_GLOCAL \
|
||||||
*/
|
_(L"%ls: Variable scope can only be one of universal, global and local\n")
|
||||||
#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message for specifying both export and unexport to set/read.
|
||||||
Error message for specifying both export and unexport to set/read
|
#define BUILTIN_ERR_EXPUNEXP _(L"%ls: Variable can't be both exported and unexported\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message for unknown switch.
|
||||||
Error message for unknown switch
|
#define BUILTIN_ERR_UNKNOWN _(L"%ls: Unknown option '%ls'\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_UNKNOWN _( L"%ls: Unknown option '%ls'\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message for invalid character in variable name.
|
||||||
Error message for invalid character in variable name
|
#define BUILTIN_ERR_VARCHAR \
|
||||||
*/
|
_(L"%ls: Invalid character '%lc' in variable name. Only alphanumerical characters and " \
|
||||||
#define BUILTIN_ERR_VARCHAR _( L"%ls: Invalid character '%lc' in variable name. Only alphanumerical characters and underscores are valid in a variable name.\n" )
|
L"underscores are valid in a variable name.\n")
|
||||||
|
|
||||||
/**
|
// Error message for invalid (empty) variable name.
|
||||||
Error message for invalid (empty) variable name
|
#define BUILTIN_ERR_VARNAME_ZERO _(L"%ls: Variable name can not be the empty string\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_VARNAME_ZERO _( L"%ls: Variable name can not be the empty string\n" )
|
|
||||||
|
|
||||||
/**
|
// Error message when too many arguments are supplied to a builtin.
|
||||||
Error message when too many arguments are supplied to a builtin
|
#define BUILTIN_ERR_TOO_MANY_ARGUMENTS _(L"%ls: Too many arguments\n")
|
||||||
*/
|
|
||||||
#define BUILTIN_ERR_TOO_MANY_ARGUMENTS _( L"%ls: Too many arguments\n" )
|
|
||||||
|
|
||||||
#define BUILTIN_ERR_NOT_NUMBER _( L"%ls: Argument '%ls' is not a number\n" )
|
#define BUILTIN_ERR_NOT_NUMBER _(L"%ls: Argument '%ls' is not a number\n")
|
||||||
|
|
||||||
/**
|
// Initialize builtin data.
|
||||||
Initialize builtin data.
|
|
||||||
*/
|
|
||||||
void builtin_init();
|
void builtin_init();
|
||||||
|
|
||||||
/**
|
// Destroy builtin data.
|
||||||
Destroy builtin data.
|
|
||||||
*/
|
|
||||||
void builtin_destroy();
|
void builtin_destroy();
|
||||||
|
|
||||||
/**
|
// Is there a builtin command with the given name?
|
||||||
Is there a builtin command with the given name?
|
|
||||||
*/
|
|
||||||
int builtin_exists(const wcstring &cmd);
|
int builtin_exists(const wcstring &cmd);
|
||||||
|
|
||||||
/**
|
// Execute a builtin command
|
||||||
Execute a builtin command
|
//
|
||||||
|
// \param parser The parser being used
|
||||||
|
// \param argv Array containing the command and parameters of the builtin. The list is terminated
|
||||||
|
// by a null pointer. This syntax resembles the syntax for exec.
|
||||||
|
// \param io the io redirections to perform on this builtin.
|
||||||
|
//
|
||||||
|
// \return the exit status of the builtin command
|
||||||
|
int builtin_run(parser_t &parser, const wchar_t *const *argv, io_streams_t &streams);
|
||||||
|
|
||||||
\param parser The parser being used
|
// Returns a list of all builtin names.
|
||||||
\param argv Array containing the command and parameters
|
|
||||||
of the builtin. The list is terminated by a
|
|
||||||
null pointer. This syntax resembles the syntax
|
|
||||||
for exec.
|
|
||||||
\param io the io redirections to perform on this builtin.
|
|
||||||
|
|
||||||
\return the exit status of the builtin command
|
|
||||||
*/
|
|
||||||
int builtin_run(parser_t &parser, const wchar_t * const *argv, io_streams_t &streams);
|
|
||||||
|
|
||||||
/** Returns a list of all builtin names */
|
|
||||||
wcstring_list_t builtin_get_names();
|
wcstring_list_t builtin_get_names();
|
||||||
|
|
||||||
/** Insert all builtin names into list. */
|
// Insert all builtin names into list.
|
||||||
void builtin_get_names(std::vector<completion_t> *list);
|
void builtin_get_names(std::vector<completion_t> *list);
|
||||||
|
|
||||||
/**
|
// Return a one-line description of the specified builtin.
|
||||||
Return a one-line description of the specified builtin.
|
|
||||||
*/
|
|
||||||
wcstring builtin_get_desc(const wcstring &b);
|
wcstring builtin_get_desc(const wcstring &b);
|
||||||
|
|
||||||
|
// 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
|
||||||
/** Support for setting and removing transient command lines.
|
// whatever is to be completed. It's also used by completion wrappers, to allow a command to appear
|
||||||
This is used by 'complete -C' in order to make
|
// as the command being wrapped for the purposes of completion.
|
||||||
the commandline builtin operate on the string to complete instead
|
//
|
||||||
of operating on whatever is to be completed. It's also used by
|
// Instantiating an instance of builtin_commandline_scoped_transient_t pushes the command as the new
|
||||||
completion wrappers, to allow a command to appear as the command
|
// transient commandline. The destructor removes it. It will assert if construction/destruction does
|
||||||
being wrapped for the purposes of completion.
|
// not happen in a stack-like (LIFO) order.
|
||||||
|
class builtin_commandline_scoped_transient_t {
|
||||||
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;
|
size_t token;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
explicit builtin_commandline_scoped_transient_t(const wcstring &cmd);
|
explicit builtin_commandline_scoped_transient_t(const wcstring &cmd);
|
||||||
~builtin_commandline_scoped_transient_t();
|
~builtin_commandline_scoped_transient_t();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Run the __fish_print_help function to obtain the help information for the specified command.
|
||||||
/**
|
|
||||||
Run the __fish_print_help function to obtain the help information
|
|
||||||
for the specified command.
|
|
||||||
*/
|
|
||||||
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
|
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
|
||||||
|
|
||||||
/** Defines a function, like builtin_function. Returns 0 on success. args should NOT contain 'function' as the first argument. */
|
// Defines a function, like builtin_function. Returns 0 on success. args should NOT contain
|
||||||
int define_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args, const wcstring &contents, int definition_line_offset, wcstring *out_err);
|
// 'function' as the first argument.
|
||||||
|
int define_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
|
||||||
|
const wcstring &contents, int definition_line_offset, wcstring *out_err);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue