myshell 2.0.0
Loading...
Searching...
No Matches
msh_internal.cpp File Reference

Internal utilities. More...

Functions

variableget_variable (std::string_view name)
 Get a pointer to an internal variable with the given name.
 
void set_variable (const std::string &name, const std::string &value)
 Set the value of an internal variable with the given name.
 
void msh_init ()
 Initialize the shell.
 
void msh_exit ()
 Perform necessary operations before exiting the shell.
 

Variables

std::vector< variablevariables
 The internal variable table.
 
const std::map< TokenType, int > token_flags
 The internal token flags table.
 

Detailed Description

Internal utilities.

Function Documentation

◆ get_variable()

variable * get_variable ( std::string_view name)

Get a pointer to an internal variable with the given name.

Parameters
nameName of the variable.
Returns
Pointer to the variable, nullptr otherwise

◆ msh_exit()

void msh_exit ( )

Perform necessary operations before exiting the shell.

Saves the history to the file specified by MSH_HISTORY_PATH.

Note
MSH_HISTORY_PATH is set automatically by the build system.
See also
MSH_HISTORY_PATH
write_history
atexit

◆ msh_init()

void msh_init ( )

Initialize the shell.

This function should be called before any other shell functions.

Sets up necessary handlers, job control, and copies the current process environment variables internally.

Sets the SHELL and VERSION to default values specified in msh_internal.h

◆ set_variable()

void set_variable ( const std::string & name,
const std::string & value )

Set the value of an internal variable with the given name.

Parameters
nameName of the variable.
valueValue to set.

Variable Documentation

◆ token_flags

const std::map<TokenType, int> token_flags
Initial value:
= {
{TokenType::EMPTY, 0},
{TokenType::WORD, WORD_LIKE | GLOB_EXPAND | VAR_EXPAND},
{TokenType::COMMAND, WORD_LIKE | VAR_EXPAND},
#ifdef ENABLE_DOUBLE_QUOTE_WILDCARD_SUBSTITUTION
{TokenType::DQSTRING, WORD_LIKE | IS_STRING | VAR_EXPAND | GLOB_EXPAND},
#else
{TokenType::DQSTRING, WORD_LIKE | NO_WORD_SPLIT | VAR_EXPAND},
#endif
{TokenType::SQSTRING, WORD_LIKE | NO_WORD_SPLIT},
{TokenType::VAR_DECL, ASSIGNMENT_WORD},
{TokenType::SUBOPEN, UNSUPPORTED | COMMAND_SEPARATOR},
{TokenType::SUBCLOSE, UNSUPPORTED},
{TokenType::AMP, COMMAND_SEPARATOR},
{TokenType::AND, COMMAND_SEPARATOR},
{TokenType::PIPE, COMMAND_SEPARATOR},
{TokenType::PIPE_AMP, COMMAND_SEPARATOR},
{TokenType::OR, COMMAND_SEPARATOR},
{TokenType::OUT, REDIRECT},
{TokenType::OUT_APPEND,REDIRECT},
{TokenType::IN, REDIRECT},
{TokenType::OUT_AMP, REDIRECT},
{TokenType::IN_AMP, REDIRECT},
{TokenType::AMP_OUT, REDIRECT},
{TokenType::AMP_APPEND,REDIRECT},
{TokenType::SEMICOLON, COMMAND_SEPARATOR},
{TokenType::COM_SUB, WORD_LIKE},
}
constexpr int REDIRECT
This token is a redirect. Used for parsing.
Definition msh_token.h:60
constexpr int COMMAND_SEPARATOR
This token separates simple commands. Used for parsing.
Definition msh_token.h:59
constexpr int GLOB_EXPAND
Tells the parser to expand globs in this kind of token.
Definition msh_token.h:55
constexpr int VAR_EXPAND
Tells the parser to expand variables in this kind of token.
Definition msh_token.h:56
constexpr int NO_WORD_SPLIT
This token is not eligible for word splitting.
Definition msh_token.h:58
constexpr int UNSUPPORTED
Unsupported token. Parser will throw an error if it encounters this.
Definition msh_token.h:54
constexpr int ASSIGNMENT_WORD
This token is an assignment word. Used for parsing.
Definition msh_token.h:61
constexpr int WORD_LIKE
This token is a potential argument/command that will be forwarded to argv.
Definition msh_token.h:57

The internal token flags table.

Maps token types to their corresponding flags.

See also
TokenType
Note
Wildcard expansion is disabled for double quoted strings by default. To enable it, define ENABLE_DOUBLE_QUOTE_WILDCARD_SUBSTITUTION in CMakeLists.txt.
Glob expansion is not performed for COMMAND tokens by default due to requirement We ignore masks in the program name. However, this behavior is unnatural.

◆ variables

std::vector<variable> variables

The internal variable table.

Maps variable names to variable objects.

See also
variable