Skip to content

Commit

Permalink
Replace variadic functions like sb_append and contains_str with varia…
Browse files Browse the repository at this point in the history
…dic macros without a sentinel.

darcs-hash:20070928213227-75c98-2e7b06242acfd5fd0bf02ce77c41d52374f2363a.gz
  • Loading branch information
liljencrantz committed Sep 28, 2007
1 parent 50f5941 commit 0e71676
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 95 deletions.
22 changes: 11 additions & 11 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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);
Expand All @@ -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++ )
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );
}
Expand Down
6 changes: 3 additions & 3 deletions builtin_commandline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion builtin_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions builtin_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}

/**
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions builtin_ulimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 2 additions & 7 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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..
Expand Down
18 changes: 8 additions & 10 deletions complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"\'" ) );
}
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"'",
Expand All @@ -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"'",
Expand Down
6 changes: 3 additions & 3 deletions highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) );

}
}
Expand All @@ -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" ) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ const wchar_t *input_mapping_get( const wchar_t *sequence )
}
return 0;
}

/**
Add all terminfo mappings
*/
Expand Down
4 changes: 2 additions & 2 deletions kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
/*
Expand Down Expand Up @@ -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 );
}
Expand Down
Loading

0 comments on commit 0e71676

Please sign in to comment.