mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Update input validation. Always use the magic CHECK macro, which prints an error message including instructions on how to report this problem.
darcs-hash:20060621004836-ac50b-a47f296634eda0c469eb39034603015b1ad7ab5c.gz
This commit is contained in:
parent
7268a4a4e0
commit
b016438c08
12 changed files with 139 additions and 224 deletions
26
builtin.c
26
builtin.c
|
@ -3015,11 +3015,7 @@ void builtin_destroy()
|
|||
|
||||
int builtin_exists( wchar_t *cmd )
|
||||
{
|
||||
if( !cmd )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( cmd, 0 );
|
||||
|
||||
/*
|
||||
Count is not a builtin, but it's help is handled internally by
|
||||
|
@ -3052,11 +3048,8 @@ int builtin_run( wchar_t **argv )
|
|||
{
|
||||
int (*cmd)(wchar_t **argv)=0;
|
||||
|
||||
if( !argv || !argv[0] )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( argv, 1 );
|
||||
CHECK( argv[0], 1 );
|
||||
|
||||
cmd = (int (*)(wchar_t **))hash_get( &builtin, argv[0] );
|
||||
|
||||
|
@ -3087,23 +3080,14 @@ int builtin_run( wchar_t **argv )
|
|||
|
||||
void builtin_get_names( array_list_t *list )
|
||||
{
|
||||
if( !list )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( list, );
|
||||
|
||||
hash_get_keys( &builtin, list );
|
||||
}
|
||||
|
||||
const wchar_t *builtin_get_desc( const wchar_t *b )
|
||||
{
|
||||
if( !b )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CHECK( b, 0 );
|
||||
|
||||
if( !desc )
|
||||
{
|
||||
|
|
25
common.c
25
common.c
|
@ -495,11 +495,7 @@ int contains_str( const wchar_t *a, ... )
|
|||
va_list va;
|
||||
int res = 0;
|
||||
|
||||
if( !a )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( a, 0 );
|
||||
|
||||
va_start( va, a );
|
||||
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
||||
|
@ -546,11 +542,7 @@ void debug( int level, const wchar_t *msg, ... )
|
|||
string_buffer_t sb;
|
||||
string_buffer_t sb2;
|
||||
|
||||
if( !msg )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( msg, );
|
||||
|
||||
if( level > debug_level )
|
||||
return;
|
||||
|
@ -578,11 +570,8 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff )
|
|||
int tok_width = 0;
|
||||
int screen_width = common_get_width();
|
||||
|
||||
if( !msg || !buff )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( msg, );
|
||||
CHECK( buff, );
|
||||
|
||||
if( screen_width )
|
||||
{
|
||||
|
@ -799,11 +788,7 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
wchar_t prev=0;
|
||||
wchar_t *in;
|
||||
|
||||
if( !orig )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( orig, 0 );
|
||||
|
||||
len = wcslen( orig );
|
||||
in = wcsdup( orig );
|
||||
|
|
20
common.h
20
common.h
|
@ -67,6 +67,26 @@ extern char *profile;
|
|||
*/
|
||||
extern wchar_t *program_name;
|
||||
|
||||
/**
|
||||
This macro is used to check that an input argument is not null. It
|
||||
is a bit lika a non-fatal form of assert. Instead of exit-ing on
|
||||
failiure, the current function is ended at once. The second
|
||||
parameter is the exit status of the current function on failiure.
|
||||
*/
|
||||
#define CHECK( arg, retval ) \
|
||||
if( !(arg) ) \
|
||||
{ \
|
||||
debug( 1, \
|
||||
L"function %s called with null value for argument %s. " \
|
||||
L"This is a bug. " \
|
||||
L"If you can reproduce it, please send a bug report to %s.", \
|
||||
__func__, \
|
||||
#arg, \
|
||||
PACKAGE_BUGREPORT ); \
|
||||
return retval; \
|
||||
} \
|
||||
|
||||
|
||||
/**
|
||||
Take an array_list_t containing wide strings and converts them to a
|
||||
single null-terminated wchar_t **. The array is allocated using
|
||||
|
|
32
complete.c
32
complete.c
|
@ -389,11 +389,7 @@ void complete_add( const wchar_t *cmd,
|
|||
complete_entry *c;
|
||||
complete_entry_opt *opt;
|
||||
|
||||
if( !cmd )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( cmd, );
|
||||
|
||||
c = complete_find_exact_entry( cmd, cmd_type );
|
||||
|
||||
|
@ -461,11 +457,7 @@ void complete_remove( const wchar_t *cmd,
|
|||
{
|
||||
complete_entry *e, *eprev=0, *enext=0;
|
||||
|
||||
if( !cmd )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( cmd, );
|
||||
|
||||
for( e = first_entry; e; e=enext )
|
||||
{
|
||||
|
@ -615,11 +607,8 @@ int complete_is_valid_option( const wchar_t *str,
|
|||
|
||||
void *context;
|
||||
|
||||
if( !str || !opt )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( str, 0 );
|
||||
CHECK( opt, 0 );
|
||||
|
||||
/*
|
||||
Check some generic things like -- and - options.
|
||||
|
@ -942,11 +931,7 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
|
|||
{
|
||||
struct stat buf;
|
||||
|
||||
if( !filename )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( filename, 0 );
|
||||
|
||||
if( !get_desc_buff )
|
||||
{
|
||||
|
@ -1978,11 +1963,8 @@ void complete( const wchar_t *cmd,
|
|||
|
||||
int cursor_pos = wcslen(cmd );
|
||||
|
||||
if( !cmd || !comp )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( cmd, );
|
||||
CHECK( comp, );
|
||||
|
||||
/**
|
||||
If we are completing a variable name or a tilde expansion user
|
||||
|
|
24
env.c
24
env.c
|
@ -627,11 +627,7 @@ int env_set( const wchar_t *key,
|
|||
event_t ev;
|
||||
int is_universal = 0;
|
||||
|
||||
if( !key )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return ENV_INVALID;
|
||||
}
|
||||
CHECK( key, ENV_INVALID );
|
||||
|
||||
if( (var_mode & ENV_USER ) &&
|
||||
hash_get( &env_read_only, key ) )
|
||||
|
@ -877,11 +873,7 @@ int env_remove( const wchar_t *key, int var_mode )
|
|||
env_node_t *first_node;
|
||||
int erased = 0;
|
||||
|
||||
if( !key )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( key, 1 );
|
||||
|
||||
if( (var_mode & ENV_USER ) &&
|
||||
hash_get( &env_read_only, key ) )
|
||||
|
@ -941,11 +933,7 @@ wchar_t *env_get( const wchar_t *key )
|
|||
env_node_t *env = top;
|
||||
wchar_t *item;
|
||||
|
||||
if( !key )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( key, 0 );
|
||||
|
||||
if( wcscmp( key, L"history" ) == 0 )
|
||||
{
|
||||
|
@ -1045,11 +1033,7 @@ int env_exist( const wchar_t *key, int mode )
|
|||
env_node_t *env;
|
||||
wchar_t *item=0;
|
||||
|
||||
if( !key )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( key, 0 );
|
||||
|
||||
/*
|
||||
Read only variables all exist, and they are all global. A local
|
||||
|
|
6
exec.c
6
exec.c
|
@ -652,11 +652,7 @@ void exec( job_t *j )
|
|||
*/
|
||||
int exec_error=0;
|
||||
|
||||
if( !j )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( j, );
|
||||
|
||||
if( no_exec )
|
||||
return;
|
||||
|
|
11
expand.c
11
expand.c
|
@ -101,6 +101,8 @@ int expand_is_clean( const wchar_t *in )
|
|||
|
||||
const wchar_t * str = in;
|
||||
|
||||
CHECK( in, 1 );
|
||||
|
||||
/*
|
||||
Test characters that have a special meaning in the first character position
|
||||
*/
|
||||
|
@ -161,6 +163,8 @@ wchar_t *expand_escape_variable( const wchar_t *in )
|
|||
array_list_t l;
|
||||
string_buffer_t buff;
|
||||
|
||||
CHECK( in, 0 );
|
||||
|
||||
al_init( &l );
|
||||
tokenize_variable_array( in, &l );
|
||||
sb_init( &buff );
|
||||
|
@ -1316,6 +1320,8 @@ static wchar_t * expand_tilde_internal( wchar_t *in )
|
|||
|
||||
wchar_t *expand_tilde( wchar_t *in)
|
||||
{
|
||||
CHECK( in, 0 );
|
||||
|
||||
if( in[0] == L'~' )
|
||||
{
|
||||
in[0] = HOME_DIRECTORY;
|
||||
|
@ -1374,6 +1380,9 @@ int expand_string( void *context,
|
|||
int res = EXPAND_OK;
|
||||
int start_count = al_get_count( end_out );
|
||||
|
||||
CHECK( str, EXPAND_ERROR );
|
||||
CHECK( end_out, EXPAND_ERROR );
|
||||
|
||||
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( str ) )
|
||||
{
|
||||
halloc_register( context, str );
|
||||
|
@ -1620,6 +1629,8 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
|
|||
int res;
|
||||
wchar_t *one;
|
||||
|
||||
CHECK( string, 0 );
|
||||
|
||||
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) )
|
||||
{
|
||||
halloc_register( context, string );
|
||||
|
|
59
function.c
59
function.c
|
@ -176,12 +176,8 @@ void function_add( const wchar_t *name,
|
|||
wchar_t *cmd_end;
|
||||
function_data_t *d;
|
||||
|
||||
|
||||
if( !name || !val )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( name, );
|
||||
CHECK( val, );
|
||||
|
||||
function_remove( name );
|
||||
|
||||
|
@ -212,11 +208,7 @@ void function_add( const wchar_t *name,
|
|||
int function_exists( const wchar_t *cmd )
|
||||
{
|
||||
|
||||
if( !cmd )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( cmd, 0 );
|
||||
|
||||
if( parser_is_reserved(cmd) )
|
||||
return 0;
|
||||
|
@ -232,11 +224,7 @@ void function_remove( const wchar_t *name )
|
|||
function_data_t *d;
|
||||
event_t ev;
|
||||
|
||||
if( !name )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( name, );
|
||||
|
||||
hash_remove( &function,
|
||||
name,
|
||||
|
@ -259,11 +247,7 @@ const wchar_t *function_get_definition( const wchar_t *argv )
|
|||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( argv, 0 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
|
@ -275,11 +259,8 @@ const wchar_t *function_get_definition( const wchar_t *argv )
|
|||
const wchar_t *function_get_desc( const wchar_t *argv )
|
||||
{
|
||||
function_data_t *data;
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
CHECK( argv, 0 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
|
@ -292,11 +273,9 @@ const wchar_t *function_get_desc( const wchar_t *argv )
|
|||
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
||||
{
|
||||
function_data_t *data;
|
||||
if( !name || !desc )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK( name, );
|
||||
CHECK( desc, );
|
||||
|
||||
load( name );
|
||||
data = (function_data_t *)hash_get( &function, name );
|
||||
|
@ -355,11 +334,7 @@ static void get_names_internal_all( void *key,
|
|||
|
||||
void function_get_names( array_list_t *list, int get_hidden )
|
||||
{
|
||||
if( !list )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( list, );
|
||||
|
||||
autoload_names( list, get_hidden );
|
||||
|
||||
|
@ -378,11 +353,7 @@ const wchar_t *function_get_definition_file( const wchar_t *argv )
|
|||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( argv, 0 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
|
@ -397,11 +368,7 @@ int function_get_definition_offset( const wchar_t *argv )
|
|||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return -1;
|
||||
}
|
||||
CHECK( argv, -1 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
|
|
|
@ -533,13 +533,8 @@ void highlight_shell( wchar_t * buff,
|
|||
void *context;
|
||||
wchar_t *cmd=0;
|
||||
|
||||
if( !buff || !color )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CHECK( buff, );
|
||||
CHECK( color, );
|
||||
|
||||
len = wcslen(buff);
|
||||
|
||||
|
|
14
parse_util.c
14
parse_util.c
|
@ -53,6 +53,9 @@ int parse_util_lineno( const wchar_t *str, int len )
|
|||
static int i2 = 0;
|
||||
static int res2 = 1;
|
||||
|
||||
CHECK( str, 0 );
|
||||
|
||||
|
||||
if( str != prev_str || i>len )
|
||||
{
|
||||
if( prev_str2 == str && i2 <= len )
|
||||
|
@ -100,6 +103,8 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
|||
|
||||
wchar_t *paran_begin=0, *paran_end=0;
|
||||
|
||||
CHECK( in, 0 );
|
||||
|
||||
for( pos = (wchar_t *)in; *pos; pos++ )
|
||||
{
|
||||
if( prev != '\\' )
|
||||
|
@ -176,14 +181,13 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
|||
wchar_t *begin, *end;
|
||||
wchar_t *pos;
|
||||
|
||||
CHECK( buff, );
|
||||
|
||||
if( a )
|
||||
*a=0;
|
||||
if( b )
|
||||
*b = 0;
|
||||
|
||||
if( !buff )
|
||||
return;
|
||||
|
||||
pos = (wchar_t *)buff;
|
||||
|
||||
while( 1 )
|
||||
|
@ -243,6 +247,8 @@ static void job_or_process_extent( const wchar_t *buff,
|
|||
|
||||
tokenizer tok;
|
||||
|
||||
CHECK( buff, );
|
||||
|
||||
if( a )
|
||||
*a=0;
|
||||
if( b )
|
||||
|
@ -342,6 +348,8 @@ void parse_util_token_extent( const wchar_t *buff,
|
|||
|
||||
wchar_t *a, *b, *pa, *pb;
|
||||
|
||||
CHECK( buff, );
|
||||
|
||||
assert( cursor_pos >= 0 );
|
||||
|
||||
|
||||
|
|
37
parser.c
37
parser.c
|
@ -758,11 +758,7 @@ wchar_t *parser_get_filename( void *context, const wchar_t *cmd )
|
|||
{
|
||||
wchar_t *path;
|
||||
|
||||
if( !cmd )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
CHECK( cmd, 0 );
|
||||
|
||||
debug( 3, L"parser_get_filename( '%ls' )", cmd );
|
||||
|
||||
|
@ -1022,11 +1018,8 @@ int eval_args( const wchar_t *line, array_list_t *args )
|
|||
int previous_pos=current_tokenizer_pos;
|
||||
int do_loop=1;
|
||||
|
||||
if( !line || !args )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( line, 1 );
|
||||
CHECK( args, 1 );
|
||||
|
||||
proc_push_interactive(0);
|
||||
current_tokenizer = &tok;
|
||||
|
@ -1103,11 +1096,7 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
|
|||
/*
|
||||
Validate input
|
||||
*/
|
||||
if( !buff )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
CHECK( buff, );
|
||||
|
||||
/*
|
||||
Check if we should end the recursion
|
||||
|
@ -2738,11 +2727,7 @@ static int parser_test_argument( const wchar_t *arg, string_buffer_t *out, const
|
|||
wchar_t *arg_cpy;
|
||||
int do_loop = 1;
|
||||
|
||||
if( !arg )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( arg, 1 );
|
||||
|
||||
arg_cpy = wcsdup( arg );
|
||||
|
||||
|
@ -2910,11 +2895,7 @@ int parser_test_args(const wchar_t * buff,
|
|||
int do_loop = 1;
|
||||
int err = 0;
|
||||
|
||||
if( !buff )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( buff, 1 );
|
||||
|
||||
current_tokenizer = &tok;
|
||||
|
||||
|
@ -3008,11 +2989,7 @@ int parser_test( const wchar_t * buff,
|
|||
int arg_count=0;
|
||||
wchar_t *cmd=0;
|
||||
|
||||
if( !buff )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 1;
|
||||
}
|
||||
CHECK( buff, 1 );
|
||||
|
||||
context = halloc( 0, 0 );
|
||||
current_tokenizer = &tok;
|
||||
|
|
42
tokenizer.c
42
tokenizer.c
|
@ -29,18 +29,16 @@
|
|||
Error string for unexpected end of string
|
||||
*/
|
||||
#define EOL_ERROR _( L"Unexpected end of token" )
|
||||
|
||||
/**
|
||||
Error string for mismatched parenthesis
|
||||
*/
|
||||
#define PARAN_ERROR _( L"Parenthesis mismatch" )
|
||||
|
||||
/**
|
||||
Error string for invalid redirections
|
||||
*/
|
||||
#define REDIRECT_ERROR _( L"Invalid redirection" )
|
||||
/**
|
||||
Error string for invalid input
|
||||
*/
|
||||
#define INPUT_ERROR _( L"Invalid input" )
|
||||
|
||||
/**
|
||||
Error string for when trying to pipe from fd 0
|
||||
|
@ -118,8 +116,9 @@ static void tok_error( tokenizer *tok, const wchar_t *err )
|
|||
|
||||
void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
||||
{
|
||||
// fwprintf( stderr, L"CREATE: \'%ls\'\n", b );
|
||||
|
||||
CHECK( tok, );
|
||||
CHECK( b, );
|
||||
|
||||
memset( tok, 0, sizeof( tokenizer) );
|
||||
|
||||
|
@ -127,17 +126,6 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
|||
tok->show_comments = flags & TOK_SHOW_COMMENTS;
|
||||
tok->has_next=1;
|
||||
|
||||
/*
|
||||
Before we copy the buffer we need to check that it is not
|
||||
null. But before that, we need to init the tokenizer far enough
|
||||
so that errors can be properly flagged
|
||||
*/
|
||||
if( !b )
|
||||
{
|
||||
tok_error( tok, INPUT_ERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
tok->has_next = (*b != L'\0');
|
||||
tok->orig_buff = tok->buff = (wchar_t *)(b);
|
||||
|
||||
|
@ -165,6 +153,8 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
|||
|
||||
void tok_destroy( tokenizer *tok )
|
||||
{
|
||||
CHECK( tok, );
|
||||
|
||||
free( tok->last );
|
||||
if( tok->free_orig )
|
||||
free( tok->orig_buff );
|
||||
|
@ -172,11 +162,15 @@ void tok_destroy( tokenizer *tok )
|
|||
|
||||
int tok_last_type( tokenizer *tok )
|
||||
{
|
||||
CHECK( tok, 0 );
|
||||
|
||||
return tok->last_type;
|
||||
}
|
||||
|
||||
wchar_t *tok_last( tokenizer *tok )
|
||||
{
|
||||
CHECK( tok, 0 );
|
||||
|
||||
return tok->last;
|
||||
}
|
||||
|
||||
|
@ -470,6 +464,8 @@ static void read_redirect( tokenizer *tok, int fd )
|
|||
|
||||
wchar_t tok_last_quote( tokenizer *tok )
|
||||
{
|
||||
CHECK( tok, 0 );
|
||||
|
||||
return tok->last_quote;
|
||||
}
|
||||
|
||||
|
@ -488,14 +484,18 @@ static int my_iswspace( wchar_t c )
|
|||
|
||||
const wchar_t *tok_get_desc( int type )
|
||||
{
|
||||
|
||||
if( type < 0 || type >= sizeof( tok_desc ) )
|
||||
{
|
||||
return _(L"Invalid token type");
|
||||
}
|
||||
return _(tok_desc[type]);
|
||||
}
|
||||
|
||||
|
||||
void tok_next( tokenizer *tok )
|
||||
{
|
||||
// fwprintf( stderr, L"tok_next on %ls (prev=%ls)\n", tok->orig_buff, tok_desc[tok->last_type] );
|
||||
|
||||
CHECK( tok, );
|
||||
|
||||
if( tok_last_type( tok ) == TOK_ERROR )
|
||||
{
|
||||
|
@ -619,6 +619,8 @@ wchar_t *tok_first( const wchar_t *str )
|
|||
tokenizer t;
|
||||
wchar_t *res=0;
|
||||
|
||||
CHECK( str, 0 );
|
||||
|
||||
tok_init( &t, str, 0 );
|
||||
|
||||
switch( tok_last_type( &t ) )
|
||||
|
@ -638,12 +640,16 @@ wchar_t *tok_first( const wchar_t *str )
|
|||
|
||||
int tok_get_pos( tokenizer *tok )
|
||||
{
|
||||
CHECK( tok, 0 );
|
||||
|
||||
return tok->last_pos + (tok->free_orig?1:0);
|
||||
}
|
||||
|
||||
|
||||
void tok_set_pos( tokenizer *tok, int pos )
|
||||
{
|
||||
CHECK( tok, );
|
||||
|
||||
tok->buff = tok->orig_buff + pos;
|
||||
tok->has_next = 1;
|
||||
tok_next( tok );
|
||||
|
|
Loading…
Reference in a new issue