#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
#include <sys/types.h>
#include <termios.h>
#include <signal.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "builtin.h"
#include "env.h"
#include "expand.h"
#include "common.h"
#include "wgetopt.h"
#include "proc.h"
#include "parser.h"
Defines | |
| #define | BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n" |
| Error message for invalid path operations. | |
| #define | BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n" |
| Hint for invalid path operation with a colon. | |
| #define | BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n" |
| Error for mismatch between index count and elements. | |
Functions | |
| static int | is_path_variable (const wchar_t *env) |
| Test if the specified variable should be subject to path validation. | |
| static int | my_env_set (const wchar_t *key, array_list_t *val, int scope) |
| Call env_set. | |
| static int | parse_index (array_list_t *indexes, const wchar_t *src, const wchar_t *name, int var_count) |
| Extract indexes from a destination argument of the form name[index1 index2. | |
| static int | update_values (array_list_t *list, array_list_t *indexes, array_list_t *values) |
Update a list list by writing copies (using wcsdup) of the values specified by values to the indexes specified by indexes. | |
| static int | al_contains_long (array_list_t *list, long val) |
| Return 1 if an array list of longs contains the specified value, 0 otherwise. | |
| static void | erase_values (array_list_t *list, array_list_t *indexes) |
| Erase from a list values at specified indexes. | |
| static void | print_variables (int include_values, int esc, int scope) |
| Print the names of all environment variables in the scope, with or without values, with or without escaping. | |
| static int | builtin_set (wchar_t **argv) |
| The set builtin. | |
Functions used for implementing the set builtin.
| static int builtin_set | ( | wchar_t ** | argv | ) | [static] |
The set builtin.
Creates, updates and erases environment variables and environemnt variable arrays.
Variables used for parsing the argument list
References _, al_destroy(), al_foreach(), al_get_count(), al_get_long(), al_init(), al_push(), ARRAY_BOUNDS_ERR, builtin_count_args(), BUILTIN_ERR_COMBO, BUILTIN_ERR_EXPUNEXP, BUILTIN_ERR_GLOCAL, BUILTIN_ERR_VARCHAR, BUILTIN_ERR_VARNAME_ZERO, builtin_print_help(), BUILTIN_SET_ARG_COUNT, builtin_unknown_option(), DIE_MEM, env_exist(), ENV_EXPORT, env_get(), ENV_GLOBAL, ENV_LOCAL, env_remove(), ENV_UNEXPORT, ENV_UNIVERSAL, ENV_USER, erase(), erase_values(), global, my_env_set(), no_argument, parse_index(), print_variables(), sb_append, sb_err, sb_out, sb_printf(), tokenize_variable_array(), update_values(), woption::val, wcsvarname(), wgetopt_long(), and woptind.
| static int my_env_set | ( | const wchar_t * | key, | |
| array_list_t * | val, | |||
| int | scope | |||
| ) | [static] |
Call env_set.
If this is a path variable, e.g. PATH, validate the elements. On error, print a description of the problem to stderr.
References _, al_get(), al_get_count(), ARRAY_SEP_STR, buffer::buff, BUILTIN_SET_PATH_ERROR, BUILTIN_SET_PATH_HINT, builtin_wperror(), env_set(), ENV_USER, error, is_path_variable(), sb_append, sb_destroy(), sb_err, sb_init(), sb_printf(), and wstat().
Referenced by builtin_set().
| static int parse_index | ( | array_list_t * | indexes, | |
| const wchar_t * | src, | |||
| const wchar_t * | name, | |||
| int | var_count | |||
| ) | [static] |
Extract indexes from a destination argument of the form name[index1 index2.
..]
| indexes | the list to insert the new indexes into | |
| src | the source string to parse | |
| name | the name of the element. Return null if the name in src does not match this name | |
| var_count | the number of elements in the array to parse. |
References _, al_push_long(), BUILTIN_SET_ARG_COUNT, sb_err, and sb_printf().
Referenced by builtin_set().
| static int update_values | ( | array_list_t * | list, | |
| array_list_t * | indexes, | |||
| array_list_t * | values | |||
| ) | [static] |
Update a list list by writing copies (using wcsdup) of the values specified by values to the indexes specified by indexes.
The previous entries at the specidied position will be free'd.
References al_get(), al_get_count(), al_get_long(), and al_set().
Referenced by builtin_set().
1.5.6