mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Minor edits to builtin_set.c
darcs-hash:20060519085813-ac50b-67b6772ac7723e13312e444944cc4b077ba23479.gz
This commit is contained in:
parent
db459f869a
commit
b52fe0feb6
1 changed files with 22 additions and 27 deletions
|
@ -26,10 +26,24 @@ Functions used for implementing the set builtin.
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "translate.h"
|
#include "translate.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error message for invalid path operations
|
||||||
|
*/
|
||||||
#define BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n"
|
#define BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Hint for invalid path operation with a colon
|
||||||
|
*/
|
||||||
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
|
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error for mismatch between index count and elements
|
||||||
|
*/
|
||||||
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
|
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Test if the specified variable should be subject to path validation
|
||||||
|
*/
|
||||||
static int is_path_variable( const wchar_t *env )
|
static int is_path_variable( const wchar_t *env )
|
||||||
{
|
{
|
||||||
return contains_str( env,
|
return contains_str( env,
|
||||||
|
@ -82,13 +96,14 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
L"set",
|
L"set",
|
||||||
dir,
|
dir,
|
||||||
key );
|
key );
|
||||||
|
|
||||||
colon = wcschr( dir, L':' );
|
colon = wcschr( dir, L':' );
|
||||||
|
|
||||||
if( colon && *(colon+1) )
|
if( colon && *(colon+1) )
|
||||||
{
|
{
|
||||||
show_hint = 1;
|
show_hint = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( show_perror )
|
if( show_perror )
|
||||||
|
@ -184,7 +199,7 @@ static int parse_index( array_list_t *indexes,
|
||||||
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = src-src_orig;
|
len = src-src_orig;
|
||||||
|
|
||||||
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
||||||
|
@ -233,7 +248,8 @@ static int parse_index( array_list_t *indexes,
|
||||||
indexes. The previous entries at the specidied position will be
|
indexes. The previous entries at the specidied position will be
|
||||||
free'd.
|
free'd.
|
||||||
|
|
||||||
\return The number of elements in the list after the modifications have been made
|
\return The number of elements in the list after the modifications
|
||||||
|
have been made
|
||||||
*/
|
*/
|
||||||
static int update_values( array_list_t *list,
|
static int update_values( array_list_t *list,
|
||||||
array_list_t *indexes,
|
array_list_t *indexes,
|
||||||
|
@ -266,7 +282,7 @@ static int al_contains_int( array_list_t *list,
|
||||||
for (i = 0; i < al_get_count(list); i++)
|
for (i = 0; i < al_get_count(list); i++)
|
||||||
{
|
{
|
||||||
int *current = (int *) al_get(list, i);
|
int *current = (int *) al_get(list, i);
|
||||||
if (current != 0 && *current == val)
|
if( current != 0 && *current == val )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -304,27 +320,6 @@ static void erase_values(array_list_t *list, array_list_t *indexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Fill a string buffer with values from a list, using ARRAY_SEP_STR to separate them
|
|
||||||
*/
|
|
||||||
static int fill_buffer_from_list(string_buffer_t *sb, array_list_t *list)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < al_get_count(list); i++)
|
|
||||||
{
|
|
||||||
wchar_t *v = (wchar_t *) al_get(list, i);
|
|
||||||
if (v != 0)
|
|
||||||
{
|
|
||||||
sb_append(sb, v);
|
|
||||||
}
|
|
||||||
if (i < al_get_count(list) - 1)
|
|
||||||
sb_append(sb, ARRAY_SEP_STR);
|
|
||||||
}
|
|
||||||
return al_get_count(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Print the names of all environment variables in the scope, with or without values,
|
Print the names of all environment variables in the scope, with or without values,
|
||||||
with or without escaping
|
with or without escaping
|
||||||
|
@ -364,9 +359,9 @@ static void print_variables(int include_values, int esc, int scope)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The set builtin. Creates, updates and erases environment variables and environemnt variable arrays.
|
The set builtin. Creates, updates and erases environment variables
|
||||||
|
and environemnt variable arrays.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int builtin_set( wchar_t **argv )
|
int builtin_set( wchar_t **argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue