Replace variadic functions like sb_append and contains_str with variadic macros without a sentinel.

darcs-hash:20070928213227-75c98-2e7b06242acfd5fd0bf02ce77c41d52374f2363a.gz
This commit is contained in:
liljencrantz 2007-09-29 07:32:27 +10:00
parent 50f5941a82
commit 0e716763d8
22 changed files with 70 additions and 95 deletions

View file

@ -162,13 +162,13 @@ static void builtin_wperror( const wchar_t *s)
{
if( s != 0 )
{
sb_append2( sb_err, s, L": ", (void *)0 );
sb_append( sb_err, s, L": ", (void *)0 );
}
char *err = strerror( errno );
wchar_t *werr = str2wcs( err );
if( werr )
{
sb_append2( sb_err, werr, L"\n", (void *)0 );
sb_append( sb_err, werr, L"\n", (void *)0 );
free( werr );
}
}
@ -944,7 +944,7 @@ static int builtin_builtin( wchar_t **argv )
{
wchar_t *el = (wchar_t *)al_get( &names, i );
sb_append2( sb_out,
sb_append( sb_out,
el,
L"\n",
(void *)0 );
@ -1103,7 +1103,7 @@ static void functions_def( wchar_t *name, string_buffer_t *out )
al_init( &ev );
event_get( &search, &ev );
sb_append2( out,
sb_append( out,
L"function ",
name,
(void *)0);
@ -1112,13 +1112,13 @@ static void functions_def( wchar_t *name, string_buffer_t *out )
{
wchar_t *esc_desc = escape( desc, 1 );
sb_append2( out, L" --description ", esc_desc, (void *)0 );
sb_append( out, L" --description ", esc_desc, (void *)0 );
free( esc_desc );
}
if( !function_get_shadows( name ) )
{
sb_append2( out, L" --no-scope-shadowing", (void *)0 );
sb_append( out, L" --no-scope-shadowing", (void *)0 );
}
for( i=0; i<al_get_count( &ev); i++ )
@ -1357,7 +1357,7 @@ static int builtin_functions( wchar_t **argv )
for( i=0; i<al_get_count( &names ); i++ )
{
sb_append2( &buff,
sb_append( &buff,
al_get(&names, i),
L", ",
(void *)0 );
@ -1370,7 +1370,7 @@ static int builtin_functions( wchar_t **argv )
{
for( i=0; i<al_get_count( &names ); i++ )
{
sb_append2( sb_out,
sb_append( sb_out,
al_get(&names, i),
L"\n",
(void *)0 );
@ -1745,7 +1745,7 @@ static int builtin_function( wchar_t **argv )
sb_append(sb_err, L"\n" );
}
sb_append2( sb_err,
sb_append( sb_err,
nxt, L" ", (void *)0 );
}
al_destroy( &names );
@ -2581,7 +2581,7 @@ static int builtin_cd( wchar_t **argv )
if( !is_interactive )
{
sb_append2( sb_err,
sb_append( sb_err,
parser_current_line(),
(void *)0 );
}
@ -2613,7 +2613,7 @@ static int builtin_cd( wchar_t **argv )
if( !is_interactive )
{
sb_append2( sb_err,
sb_append( sb_err,
parser_current_line(),
(void *)0 );
}

View file

@ -163,7 +163,7 @@ static void write_part( const wchar_t *begin,
case TOK_STRING:
{
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
sb_append2( &out, tmp, L"\n", (void *)0 );
sb_append( &out, tmp, L"\n", (void *)0 );
free( tmp );
break;
}
@ -247,7 +247,7 @@ static int builtin_commandline( wchar_t **argv )
return 1;
}
sb_append2( sb_err,
sb_append( sb_err,
argv[0],
L": Can not set commandline in non-interactive mode\n",
(void *)0 );
@ -478,7 +478,7 @@ static int builtin_commandline( wchar_t **argv )
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
{
sb_append2( sb_err,
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );

View file

@ -96,7 +96,7 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
#ifdef HAVE__PROC_SELF_STAT
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
#endif
sb_append2( sb_out,
sb_append( sb_out,
job_is_stopped(j)?_(L"stopped"):_(L"running"),
L"\t",
j->command,

View file

@ -46,10 +46,9 @@ Functions used for implementing the set builtin.
*/
static int is_path_variable( const wchar_t *env )
{
return contains_str( env,
return contains( env,
L"PATH",
L"CDPATH",
(void *)0 );
L"CDPATH" );
}
/**
@ -388,7 +387,7 @@ static void print_variables(int include_values, int esc, int scope)
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
sb_append2(sb_out, L" ", e_value, (void *)0);
sb_append(sb_out, L" ", e_value, (void *)0);
free(e_value);
if( shorten )

View file

@ -432,7 +432,7 @@ static int builtin_ulimit( wchar_t ** argv )
}
else
{
sb_append2( sb_err,
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
@ -503,7 +503,7 @@ static int builtin_ulimit( wchar_t ** argv )
default:
{
sb_append2( sb_err,
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );

View file

@ -385,12 +385,7 @@ char **wcsv2strv( const wchar_t **in )
}
wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b )
{
return wcsdupcat2( a, b, (void *)0 );
}
wchar_t *wcsdupcat2( const wchar_t *a, ... )
wchar_t *wcsdupcat_internal( const wchar_t *a, ... )
{
int len=wcslen(a);
int pos;
@ -548,7 +543,7 @@ const wchar_t *wsetlocale(int category, const wchar_t *locale)
return (wchar_t *)setlocale_buff->buff;
}
int contains_str( const wchar_t *a, ... )
int contains_internal( const wchar_t *a, ... )
{
wchar_t *arg;
va_list va;

View file

@ -140,7 +140,8 @@ extern wchar_t *program_name;
*/
#define N_(wstr) wstr
#define CONTAINS( str,... ) contains_str( str, __VA_ARGS__, (void *)0 )
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
/*
Print a stack trace to stderr
@ -222,17 +223,12 @@ char **wcsv2strv( const wchar_t **in );
*/
wchar_t **strv2wcsv( const char **in );
/**
Returns a newly allocated concatenation of the specified wide
character strings
*/
wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b );
/**
Returns a newly allocated concatenation of the specified wide
character strings. The last argument must be a null pointer.
*/
__sentinel wchar_t *wcsdupcat2( const wchar_t *a, ... );
__sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
/**
Test if the given string is a valid variable name
@ -304,7 +300,7 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale );
\return zero if needle is not found, of if needle is null, non-zero otherwise
*/
__sentinel int contains_str( const wchar_t *needle, ... );
__sentinel int contains_internal( const wchar_t *needle, ... );
/**
Call read while blocking the SIGCHLD signal. Should only be called
@ -410,7 +406,6 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff );
*/
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
/**
Make sure the specified direcotry exists. If needed, try to create
it and any currently not existing parent directories..

View file

@ -805,7 +805,7 @@ int complete_is_valid_option( const wchar_t *str,
str[0] = opt[j];
str[1]=0;
al_push( errors,
wcsdupcat2(_( L"Unknown option: " ), L"'", str, L"'", (void *)0) );
wcsdupcat(_( L"Unknown option: " ), L"'", str, L"'" ) );
}
opt_found = 0;
@ -823,12 +823,12 @@ int complete_is_valid_option( const wchar_t *str,
if( hash_get_count( &gnu_match_hash )==0)
{
al_push( errors,
wcsdupcat2( _(L"Unknown option: "), L"'", opt, L"\'", (void *)0) );
wcsdupcat( _(L"Unknown option: "), L"'", opt, L"\'" ) );
}
else
{
al_push( errors,
wcsdupcat2( _(L"Multiple matches for option: "), L"'", opt, L"\'", (void *)0) );
wcsdupcat( _(L"Multiple matches for option: "), L"'", opt, L"\'" ) );
}
}
}
@ -1112,10 +1112,9 @@ static void complete_cmd( const wchar_t *cmd,
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
nxt_completion = wcsdupcat2( nxt_path,
nxt_completion = wcsdupcat( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
(void *)0 );
cmd );
if( ! nxt_completion )
continue;
@ -1168,10 +1167,9 @@ static void complete_cmd( const wchar_t *cmd,
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
wchar_t *nxt_completion=
wcsdupcat2( nxt_path,
wcsdupcat( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
(void *)0 );
cmd );
if( ! nxt_completion )
{
continue;
@ -1487,7 +1485,7 @@ static int complete_param( const wchar_t *cmd_orig,
int match=0, match_no_case=0;
string_buffer_t *whole_opt = sb_halloc( context );
sb_append2( whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
sb_append( whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
match = wcsncmp( str, (wchar_t *)whole_opt->buff, wcslen(str) )==0;

4
env.c
View file

@ -466,7 +466,7 @@ static void setup_path()
sb_append( &b, path );
}
sb_append2( &b,
sb_append( &b,
ARRAY_SEP_STR,
path_el[j],
(void *)0 );
@ -713,7 +713,7 @@ int env_set( const wchar_t *key,
CHECK( key, ENV_INVALID );
if( val && CONTAINS( key, L"PWD", L"HOME" ) )
if( val && contains( key, L"PWD", L"HOME" ) )
{
void *context = halloc( 0, 0 );
const wchar_t *val_canonical = path_make_canonical( context, val );

View file

@ -202,7 +202,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
if( wcschr( el, L' ' ) && is_quotable( el ) )
{
sb_append2( &buff,
sb_append( &buff,
L"'",
el,
L"'",
@ -228,7 +228,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
if( is_quotable( el ) )
{
sb_append2( &buff,
sb_append( &buff,
L"'",
el,
L"'",

View file

@ -741,7 +741,7 @@ void highlight_shell( wchar_t * buff,
else
{
if( error )
al_push( error, wcsdupcat2 ( L"Unknown command \'", cmd, L"\'", (void *)0 ));
al_push( error, wcsdupcat ( L"Unknown command \'", cmd, L"\'" ));
color[ tok_get_pos( &tok ) ] = (HIGHLIGHT_ERROR);
}
had_cmd = 1;
@ -815,7 +815,7 @@ void highlight_shell( wchar_t * buff,
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat2( L"Directory \'", dir, L"\' does not exist", (void *)0 ) );
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
}
}
@ -831,7 +831,7 @@ void highlight_shell( wchar_t * buff,
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat2( L"File \'", target, L"\' does not exist", (void *)0 ) );
al_push( error, wcsdupcat( L"File \'", target, L"\' does not exist" ) );
}
}
}

View file

@ -468,7 +468,7 @@ static wchar_t *history_filename( void *context, const wchar_t *name, const wcha
if( !path )
return 0;
res = wcsdupcat2( path, L"/", name, L"_history", suffix?suffix:(void *)0, (void *)0 );
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
halloc_register_function( context, &free, res );
return res;
}

View file

@ -618,6 +618,7 @@ const wchar_t *input_mapping_get( const wchar_t *sequence )
}
return 0;
}
/**
Add all terminfo mappings
*/

4
kill.c
View file

@ -96,7 +96,7 @@ void kill_add( wchar_t *str )
if( (disp = env_get( L"DISPLAY" )) )
{
wchar_t *escaped_str = escape( str, 1 );
wchar_t *cmd = wcsdupcat2(L"echo ", escaped_str, L"|xsel -b",(void *)0);
wchar_t *cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
if( exec_subshell( cmd, 0 ) == -1 )
{
/*
@ -211,7 +211,7 @@ static void kill_check_x_buffer()
else
{
wchar_t *old = new_cut_buffer;
new_cut_buffer= wcsdupcat2( new_cut_buffer, L"\\n", next_line, (void *)0 );
new_cut_buffer= wcsdupcat( new_cut_buffer, L"\\n", next_line );
free( old );
free( next_line );
}

View file

@ -1014,7 +1014,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
struct stat buf;
wchar_t *next = (wchar_t *)al_get( path_list, i );
sb_clear( path );
sb_append2( path, next, L"/", cmd, L".fish", (void *)0 );
sb_append( path, next, L"/", cmd, L".fish", (void *)0 );
if( (wstat( (wchar_t *)path->buff, &buf )== 0) &&
(waccess( (wchar_t *)path->buff, R_OK ) == 0) )

View file

@ -527,7 +527,7 @@ const wchar_t *parser_get_block_desc( int block )
*/
static int parser_is_pipe_forbidden( wchar_t *word )
{
return CONTAINS( word,
return contains( word,
L"exec",
L"case",
L"break",
@ -1008,7 +1008,7 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
for( i=1; b->param2.function_call_process->argv[i]; i++ )
{
sb_append2( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], (void *)0 );
sb_append( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], (void *)0 );
}
sb_printf( buff, _(L"\twith parameter list '%ls'\n"), (wchar_t *)tmp.buff );
@ -1763,7 +1763,7 @@ static int parse_job( process_t *p,
mark = tok_get_pos( tok );
if( CONTAINS( nxt,
if( contains( nxt,
L"command",
L"builtin",
L"not",
@ -2944,7 +2944,7 @@ int parser_test( const wchar_t * buff,
command is needed, such as after 'and' or
'while'
*/
if( CONTAINS( cmd,
if( contains( cmd,
L"end" ) )
{
err=1;
@ -3018,7 +3018,7 @@ int parser_test( const wchar_t * buff,
had_cmd = 0;
}
if( CONTAINS( cmd,
if( contains( cmd,
L"or",
L"and" ) )
{
@ -3152,7 +3152,7 @@ int parser_test( const wchar_t * buff,
/*
Test that break and continue are only used within loop blocks
*/
if( CONTAINS( cmd, L"break", L"continue" ) )
if( contains( cmd, L"break", L"continue" ) )
{
int found_loop=0;
int i;

View file

@ -24,7 +24,7 @@ int parser_keywords_is_switch( const wchar_t *cmd )
int parser_keywords_skip_arguments( const wchar_t *cmd )
{
return CONTAINS( cmd,
return contains( cmd,
L"else",
L"begin" );
}
@ -34,7 +34,7 @@ int parser_keywords_is_subcommand( const wchar_t *cmd )
{
return parser_keywords_skip_arguments( cmd ) ||
CONTAINS( cmd,
contains( cmd,
L"command",
L"builtin",
L"while",
@ -48,7 +48,7 @@ int parser_keywords_is_subcommand( const wchar_t *cmd )
int parser_keywords_is_block( const wchar_t *word)
{
return CONTAINS( word,
return contains( word,
L"for",
L"while",
L"if",
@ -61,7 +61,7 @@ int parser_keywords_is_reserved( const wchar_t *word)
{
return parser_keywords_is_block(word) ||
parser_keywords_is_subcommand( word ) ||
CONTAINS( word,
contains( word,
L"end",
L"case",
L"else",

6
path.c
View file

@ -52,7 +52,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
path = env_get(L"PATH");
if( path == 0 )
{
if( CONTAINS( PREFIX L"/bin", L"/bin", L"/usr/bin" ) )
if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) )
{
path = L"/bin" ARRAY_SEP_STR L"/usr/bin";
}
@ -197,9 +197,9 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
}
whole_path =
wcsdupcat2( expanded_path,
wcsdupcat( expanded_path,
( expanded_path[path_len-1] != L'/' )?L"/":L"",
dir, (void *)0 );
dir );
free(expanded_path );

View file

@ -559,11 +559,11 @@ void reader_write_title()
don't. Since we can't see the underlying terminal below screen
there is no way to fix this.
*/
if( !term || !CONTAINS( term, L"xterm", L"screen", L"nxterm", L"rxvt" ) )
if( !term || !contains( term, L"xterm", L"screen", L"nxterm", L"rxvt" ) )
{
char *n = ttyname( STDIN_FILENO );
if( CONTAINS( term, L"linux" ) )
if( contains( term, L"linux" ) )
{
return;
}
@ -1569,8 +1569,8 @@ static void handle_history( const wchar_t *new_str )
Check if the specified string is contained in the list, using
wcscmp as a comparison function
*/
static int contains( const wchar_t *needle,
array_list_t *haystack )
static int contains_al( const wchar_t *needle,
array_list_t *haystack )
{
int i;
for( i=0; i<al_get_count( haystack ); i++ )
@ -1720,7 +1720,7 @@ static void handle_token_history( int forward, int reset )
}
//debug( 3, L"ok pos" );
if( !contains( tok_last( &tok ), &data->search_prev ) )
if( !contains_al( tok_last( &tok ), &data->search_prev ) )
{
free(str);
data->token_history_pos = tok_get_pos( &tok );

15
util.c
View file

@ -1175,16 +1175,6 @@ string_buffer_t *sb_new()
return res;
}
void sb_append( string_buffer_t *b, const wchar_t * s)
{
CHECK( b, );
CHECK( s, );
b_append( b, s, sizeof(wchar_t)*(wcslen(s)+1) );
b->used -= sizeof(wchar_t);
}
void sb_append_substring( string_buffer_t *b, const wchar_t *s, size_t l )
{
wchar_t tmp=0;
@ -1209,7 +1199,7 @@ void sb_append_char( string_buffer_t *b, wchar_t c )
b->used -= sizeof(wchar_t);
}
void sb_append2( string_buffer_t *b, ... )
void sb_append_internal( string_buffer_t *b, ... )
{
va_list va;
wchar_t *arg;
@ -1219,7 +1209,8 @@ void sb_append2( string_buffer_t *b, ... )
va_start( va, b );
while( (arg=va_arg(va, wchar_t *) )!= 0 )
{
sb_append( b, arg );
b_append( b, arg, sizeof(wchar_t)*(wcslen(arg)+1) );
b->used -= sizeof(wchar_t);
}
va_end( va );
}

8
util.h
View file

@ -598,11 +598,6 @@ void sb_init( string_buffer_t * );
*/
string_buffer_t *sb_new();
/**
Append a string to the buffer
*/
void sb_append( string_buffer_t *, const wchar_t * );
/**
Append a part of a string to the buffer
*/
@ -613,6 +608,7 @@ void sb_append_substring( string_buffer_t *, const wchar_t *, size_t );
*/
void sb_append_char( string_buffer_t *, wchar_t );
#define sb_append( sb,... ) sb_append_internal( sb, __VA_ARGS__, (void *)0 )
/**
Append a null terminated list of strings to the buffer.
@ -622,7 +618,7 @@ void sb_append_char( string_buffer_t *, wchar_t );
Do not forget to cast the last 0 to (void *), or you might encounter errors on 64-bit platforms!
*/
__sentinel void sb_append2( string_buffer_t *, ... );
__sentinel void sb_append_internal( string_buffer_t *, ... );
/**
Append formated string data to the buffer. This function internally

View file

@ -727,7 +727,7 @@ static void wildcard_completion_allocate( array_list_t *list,
}
else
{
sb_append2( sb, desc, L", ", (void *)0 );
sb_append( sb, desc, L", ", (void *)0 );
if( sz < 0 )
{
sb_append( sb, L"unknown" );