#include "config.h"
#include <stdlib.h>
#include <wchar.h>
#include <string.h>
#include <stdio.h>
#include <locale.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <ncurses.h>
#include <termio.h>
#include <term.h>
#include <libintl.h>
#include <errno.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "proc.h"
#include "common.h"
#include "env.h"
#include "sanity.h"
#include "expand.h"
#include "history.h"
#include "reader.h"
#include "parser.h"
#include "env_universal.h"
#include "input_common.h"
#include "event.h"
#include "path.h"
#include "halloc.h"
#include "halloc_util.h"
#include "complete.h"
Data Structures | |
| struct | env_node |
| Struct representing one level in the function variable stack. More... | |
| struct | var_entry |
| A variable entry. More... | |
Defines | |
| #define | FISHD_CMD L"fishd ^/tmp/fishd.log.%s" |
| Command used to start fishd. | |
| #define | ENV_NULL L"\x1d" |
| Value denoting a null string. | |
Typedefs | |
| typedef struct env_node | env_node_t |
| Struct representing one level in the function variable stack. | |
| typedef struct var_entry | var_entry_t |
| A variable entry. | |
Functions | |
| static void | clear_hash_entry (void *key, void *data) |
| Free hash key and hash value. | |
| static void | start_fishd () |
| When fishd isn't started, this function is provided to env_universal as a callback, it tries to start up fishd. | |
| static mode_t | get_umask () |
| Return the current umask value. | |
| static int | is_locale (const wchar_t *key) |
| Checks if the specified variable is a locale variable. | |
| static void | handle_locale () |
| Properly sets all locale information. | |
| static void | universal_callback (int type, const wchar_t *name, const wchar_t *val) |
| Universal variable callback function. | |
| static void | setup_path () |
| Make sure the PATH variable contains the essaential directories. | |
| int | env_set_pwd () |
| Update the PWD variable directory. | |
| static void | env_set_defaults () |
| Set up default values for various variables if not defined. | |
| void | env_init () |
| Initialize environment variable data. | |
| void | env_destroy () |
| Destroy environment variable data. | |
| static env_node_t * | env_get_node (const wchar_t *key) |
| Search all visible scopes in order for the specified key. | |
| int | env_set (const wchar_t *key, const wchar_t *val, int var_mode) |
| Set the value of the environment variable whose name matches key to val. | |
| static int | try_remove (env_node_t *n, const wchar_t *key, int var_mode) |
| Attempt to remove/free the specified key/value pair from the specified hash table. | |
| int | env_remove (const wchar_t *key, int var_mode) |
| Remove environemnt variable. | |
| wchar_t * | env_get (const wchar_t *key) |
| Return the value of the variable with the specified name. | |
| int | env_exist (const wchar_t *key, int mode) |
| Returns 1 if the specified key exists. | |
| static int | local_scope_exports (env_node_t *n) |
| Returns true if the specified scope or any non-shadowed non-global subscopes contain an exported variable. | |
| void | env_push (int new_scope) |
| Push the variable stack. | |
| void | env_pop () |
| Pop the variable stack. | |
| static void | add_key_to_hash (void *key, void *data, void *aux) |
| Function used with hash_foreach to insert keys of one table into another. | |
| static void | add_to_hash (void *k, void *aux) |
| Add key to hashtable. | |
| static void | add_key_to_list (void *key, void *val, void *aux) |
| Add key to list. | |
| void | env_get_names (array_list_t *l, int flags) |
| Insert all variable names into l. | |
| static void | export_func1 (void *k, void *v, void *aux) |
| Function used by env_export_arr to iterate over hashtable of variables. | |
| static void | get_exported (env_node_t *n, hash_table_t *h) |
| Get list of all exported variables. | |
| static void | export_func2 (void *k, void *v, void *aux) |
| Function used by env_export_arr to iterate over hashtable of variables. | |
| char ** | env_export_arr (int recalc) |
| Returns an array containing all exported variables in a format suitable for execv. | |
Variables | |
| char ** | environ |
| At init, we read all the environment variables from this array. | |
| char ** | __environ |
This should be the same thing as environ, but it is possible only one of the two work. | |
| static env_node_t * | top = 0 |
| Top node on the function stack. | |
| static env_node_t * | global_env = 0 |
| Bottom node on the function stack. | |
| static hash_table_t * | global |
| Table for global variables. | |
| static hash_table_t | env_read_only |
| Table of variables that may not be set using the set command. | |
| static hash_table_t | env_electric |
| Table of variables whose value is dynamically calculated, such as umask, status, etc. | |
| static char ** | export_arr = 0 |
| Exported variable array used by execv. | |
| static buffer_t | export_buffer |
| Buffer used for storing string contents for export_arr. | |
| static int | has_changed = 1 |
| Flag for checking if we need to regenerate the exported variable array. | |
| static string_buffer_t | dyn_var |
| This stringbuffer is used to store the value of dynamically generated variables, such as history. | |
| static int | get_names_show_exported |
| Variable used by env_get_names to communicate auxiliary information to add_key_to_hash. | |
| static int | get_names_show_unexported |
| Variable used by env_get_names to communicate auxiliary information to add_key_to_hash. | |
| static const wchar_t * | locale_variable [] |
| List of all locale variable names. | |
| typedef struct var_entry var_entry_t |
A variable entry.
Stores the value of a variable and whether it should be exported. Obviously, it needs to be allocated large enough to fit the value string.
| int env_exist | ( | const wchar_t * | key, | |
| int | mode | |||
| ) |
Returns 1 if the specified key exists.
This can't be reliably done using env_get, since env_get returns null for 0-element arrays
| key | The name of the variable to remove | |
| mode | the scope to search in. All scopes are searched if unset |
References CHECK, env_node::env, ENV_GLOBAL, ENV_LOCAL, ENV_UNIVERSAL, env_universal_barrier(), hash_get(), env_node::new_scope, env_node::next, and proc_had_barrier.
Referenced by builtin_set().
| wchar_t* env_get | ( | const wchar_t * | key | ) |
Return the value of the variable with the specified name.
Returns 0 if the key does not exist. The returned string should not be modified or freed. The returned string is only guaranteed to be valid until the next call to env_get(), env_set(), env_push() or env_pop() takes place.
References ARRAY_SEP_STR, buffer::buff, CHECK, common_get_height(), common_get_width(), env_node::env, ENV_NULL, env_universal_barrier(), get_umask(), hash_get(), history_get(), env_node::new_scope, env_node::next, proc_get_last_status(), proc_had_barrier, reader_get_buffer(), sb_append, sb_clear(), sb_printf(), and var_entry::val.
Referenced by autoload_names(), builtin_cd(), builtin_read(), builtin_set(), calc_prompt_width(), complete_cmd(), complete_variable(), env_init(), env_set_defaults(), exec_subshell(), expand_tilde_internal(), expand_var(), handle_locale(), highlight_get_color(), input_init(), kill_add(), kill_check_x_buffer(), parse_job(), parse_util_load(), path_get_cdpath(), path_get_config(), path_get_path(), print_variables(), reader_write_title(), and setup_path().
| void env_get_names | ( | array_list_t * | l, | |
| int | flags | |||
| ) |
Insert all variable names into l.
These are not copies of the strings and should not be freed after use.
References add_key_to_hash(), add_key_to_list(), add_to_hash(), al_destroy(), al_foreach2(), al_init(), al_push(), CHECK, env_node::env, ENV_EXPORT, ENV_GLOBAL, ENV_LOCAL, ENV_UNEXPORT, ENV_UNIVERSAL, get_names_show_exported, get_names_show_unexported, hash_destroy(), hash_foreach2(), hash_get_keys(), hash_init(), hash_wcs_cmp(), hash_wcs_func(), env_node::new_scope, and env_node::next.
Referenced by complete_variable(), and print_variables().
| static env_node_t* env_get_node | ( | const wchar_t * | key | ) | [static] |
Search all visible scopes in order for the specified key.
Return the first scope in which it was found.
References env_node::env, hash_get(), env_node::new_scope, and env_node::next.
Referenced by env_set().
| void env_pop | ( | ) |
Pop the variable stack.
Used for implementing local variables for functions and for-loops.
References _, clear_hash_entry(), debug(), env_node::env, env_node::export, handle_locale(), has_changed, hash_destroy(), hash_foreach(), hash_get(), killme, local_scope_exports(), locale_variable, env_node::new_scope, env_node::next, and sanity_lose().
Referenced by builtin_else(), env_destroy(), and parser_push_block().
| void env_push | ( | int | new_scope | ) |
Push the variable stack.
Used for implementing local variables for functions and for-loops.
References env_node::env, env_node::export, has_changed, hash_init(), hash_wcs_cmp(), hash_wcs_func(), local_scope_exports(), env_node::new_scope, and env_node::next.
Referenced by builtin_else(), and parser_push_block().
| int env_remove | ( | const wchar_t * | key, | |
| int | mode | |||
| ) |
Remove environemnt variable.
| key | The name of the variable to remove | |
| mode | should be ENV_USER if this is a remove request from the user, 0 otherwise. If this is a user request, read-only variables can not be removed. The mode may also specify the scope of the variable that should be erased. |
References al_destroy(), al_init(), al_push(), event_t::arguments, CHECK, ENV_GLOBAL, ENV_LOCAL, ENV_UNIVERSAL, ENV_USER, event_fire(), EVENT_VARIABLE, event_t::function_name, handle_locale(), hash_get(), is_locale(), event_t::param1, try_remove(), event_t::type, and event_t::variable.
Referenced by builtin_set().
| int env_set | ( | const wchar_t * | key, | |
| const wchar_t * | val, | |||
| int | mode | |||
| ) |
Set the value of the environment variable whose name matches key to val.
Memory policy: All keys and values are copied, the parameters can and should be freed by the caller afterwards
| key | The key | |
| val | The value | |
| mode | The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL, ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed. |
ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable. ENV_INVALID, the variable name or mode was invalid
References al_destroy(), al_init(), al_push(), event_t::arguments, CHECK, contains, DIE_MEM, env_node::env, ENV_EXPORT, env_get_node(), ENV_GLOBAL, ENV_LOCAL, ENV_NULL, env_set(), ENV_UNEXPORT, ENV_UNIVERSAL, env_universal_barrier(), ENV_USER, event_fire(), EVENT_VARIABLE, env_node::export, var_entry::export, event_t::function_name, halloc(), halloc_free(), handle_locale(), has_changed, hash_get(), hash_put(), hash_remove(), is_locale(), env_node::new_scope, env_node::next, event_t::param1, proc_had_barrier, var_entry::size, event_t::type, var_entry::val, and event_t::variable.
Referenced by builtin_end(), builtin_fg(), builtin_for(), builtin_read(), env_init(), env_set(), env_set_defaults(), env_set_pwd(), main(), my_env_set(), parse_util_set_argv(), reader_interactive_init(), reader_run_command(), and setup_path().
| static void start_fishd | ( | ) | [static] |
When fishd isn't started, this function is provided to env_universal as a callback, it tries to start up fishd.
It's implementation is a bit of a hack, since it evaluates a bit of shellscript, and it might be used at times when that might not be the best idea.
References _, buffer::buff, debug(), eval(), FISHD_CMD, sb_destroy(), sb_init(), sb_printf(), and TOP.
Referenced by env_init().
| static int try_remove | ( | env_node_t * | n, | |
| const wchar_t * | key, | |||
| int | var_mode | |||
| ) | [static] |
Attempt to remove/free the specified key/value pair from the specified hash table.
References env_node::env, ENV_LOCAL, var_entry::export, has_changed, hash_remove(), env_node::new_scope, and env_node::next.
Referenced by env_remove().
| static void universal_callback | ( | int | type, | |
| const wchar_t * | name, | |||
| const wchar_t * | val | |||
| ) | [static] |
Universal variable callback function.
This function makes sure the proper events are triggered when an event occurs.
References al_destroy(), al_init(), al_push(), event_t::arguments, event_fire(), EVENT_VARIABLE, event_t::function_name, handle_locale(), has_changed, is_locale(), event_t::param1, event_t::type, and event_t::variable.
Referenced by env_init().
| char** __environ |
This should be the same thing as environ, but it is possible only one of the two work.
..
Referenced by env_init().
const wchar_t* locale_variable[] [static] |
Initial value:
{
L"LANG",
L"LC_ALL",
L"LC_COLLATE",
L"LC_CTYPE",
L"LC_MESSAGES",
L"LC_MONETARY",
L"LC_NUMERIC",
L"LC_TIME",
(void *)0
}
Referenced by env_pop(), handle_locale(), and is_locale().
1.5.6