Remove some ancient debug messages, drop two warnings, add some braces and other minor code tweaks

darcs-hash:20060219181932-ac50b-2d032e7a64257a6ca0db078ea9c81ae04a01120f.gz
This commit is contained in:
axel 2006-02-20 04:19:32 +10:00
parent 7dc3934997
commit 7740035d14
3 changed files with 120 additions and 114 deletions

View file

@ -325,7 +325,6 @@ void complete_init()
void complete_destroy()
{
complete_entry *i=first_entry, *prev;
wchar_t *path;
while( i )
{
@ -382,8 +381,10 @@ void complete_add( const wchar_t *cmd,
if( c == 0 )
{
if( !(c = malloc( sizeof(complete_entry) )))
{
die_mem();
}
c->next = first_entry;
first_entry = c;
@ -396,8 +397,10 @@ void complete_add( const wchar_t *cmd,
/* wprintf( L"Add completion to option (short %lc, long %ls)\n", short_opt, long_opt );*/
if( !(opt = malloc( sizeof( complete_entry_opt ) )))
{
die_mem();
}
opt->next = c->first_option;
c->first_option = opt;
c->authorative = authorative;
@ -410,9 +413,11 @@ void complete_add( const wchar_t *cmd,
wcsncat( c->short_opt_str,
&short_opt, 1 );
if( len == 2 )
{
wcscat( c->short_opt_str, L":" );
}
}
opt->short_opt = short_opt;
opt->result_mode = result_mode;
opt->old_mode=old_mode;
@ -426,7 +431,9 @@ void complete_add( const wchar_t *cmd,
opt->desc = intern( desc );
}
else
{
opt->desc = L"";
}
}
void complete_remove( const wchar_t *cmd,
@ -435,6 +442,7 @@ void complete_remove( const wchar_t *cmd,
const wchar_t *long_opt )
{
complete_entry *e, *eprev=0, *enext=0;
for( e = first_entry; e; e=enext )
{
enext=e->next;
@ -461,9 +469,9 @@ void complete_remove( const wchar_t *cmd,
{
wchar_t *pos;
/* fwprintf( stderr,
L"remove option -%lc --%ls\n",
o->short_opt?o->short_opt:L' ',
o->long_opt );
L"remove option -%lc --%ls\n",
o->short_opt?o->short_opt:L' ',
o->long_opt );
*/
if( o->short_opt )
{
@ -538,10 +546,14 @@ static void parse_cmd_string( const wchar_t *str,
/* Make sure the path is not included in the command */
cmd = wcsrchr( str, L'/' );
if( cmd != 0 )
{
cmd++;
}
else
{
cmd = (wchar_t *)str;
}
*pathp=path;
*cmdp=cmd;
}
@ -550,24 +562,20 @@ int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
array_list_t *errors )
{
complete_entry *i;
complete_entry_opt *o;
wchar_t *cmd, *path;
int found_match = 0;
int authorative = 1;
int opt_found=0;
hash_table_t gnu_match_hash;
int is_gnu_opt=0;
int is_old_opt=0;
int is_short_opt=0;
int is_gnu_exact=0;
int gnu_opt_len=0;
char *short_validated;
/*
Check some generic things like -- and - options.
*/
@ -575,22 +583,31 @@ int complete_is_valid_option( const wchar_t *str,
{
case 0:
{
return 1;
}
case 1:
{
return opt[0] == L'-';
}
case 2:
{
if( wcscmp( L"--", opt ) == 0 )
{
return 1;
}
break;
}
}
if( opt[0] != L'-' )
{
if( errors )
{
al_push( errors, wcsdup(L"Option does not begin with a '-'") );
}
return 0;
}
@ -610,13 +627,15 @@ int complete_is_valid_option( const wchar_t *str,
{
wchar_t *opt_end = wcschr(opt, L'=' );
if( opt_end )
{
gnu_opt_len = (opt_end-opt)-2;
}
else
{
gnu_opt_len = wcslen(opt)-2;
// fwprintf( stderr, L"Length %d optend %d\n", gnu_opt_len, opt_end );
}
}
parse_cmd_string( str, &path, &cmd );
/*
@ -648,10 +667,9 @@ int complete_is_valid_option( const wchar_t *str,
{
if( o->old_mode )
continue;
//fwprintf( stderr, L"Compare \'%ls\' against \'%ls\'\n", &opt[2], o->long_opt );
if( wcsncmp( &opt[2], o->long_opt, gnu_opt_len )==0)
{
//fwprintf( stderr, L"Found gnu match %ls\n", o->long_opt );
hash_put( &gnu_match_hash, o->long_opt, L"" );
if( (wcsncmp( &opt[2],
o->long_opt,
@ -671,7 +689,6 @@ int complete_is_valid_option( const wchar_t *str,
if( wcscmp( &opt[1], o->long_opt )==0)
{
// fwprintf( stderr, L"Found old match %ls\n", o->long_opt );
opt_found = 1;
is_old_opt = 1;
break;
@ -701,22 +718,16 @@ int complete_is_valid_option( const wchar_t *str,
nopt[1]=opt[1];
nopt[2]=L'\0';
//fwprintf( stderr, L"Pos %d, shortopt %lc has argument\n", a-opt, *a );
short_validated[a-opt] =
complete_is_valid_argument( str, nopt, &opt[2]);
}
else
{
// fwprintf( stderr, L"Pos %d, shortopt %lc is ok\n", a-opt, *a );
short_validated[a-opt]=1;
}
}
}
}
}
free( path );
@ -736,7 +747,6 @@ int complete_is_valid_option( const wchar_t *str,
{
if ( !short_validated[j])
{
// fwprintf( stderr, L"Pos %d, shortopt %lc is not ok\n", j, opt[j] );
if( errors )
{
wchar_t str[2];
@ -755,7 +765,6 @@ int complete_is_valid_option( const wchar_t *str,
if( is_gnu_opt )
{
// fwprintf( stderr, L"Found %d matches\n", hash_get_count( &gnu_match_hash ) );
opt_found = is_gnu_exact || (hash_get_count( &gnu_match_hash )==1);
if( errors && !opt_found )
{
@ -792,11 +801,14 @@ int complete_is_valid_argument( const wchar_t *str,
static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
{
int len = wcslen(suff_orig );
int len;
wchar_t *suff;
wchar_t *pos;
wchar_t *tmp;
wchar_t *desc;
len = wcslen(suff_orig );
if( len == 0 )
return COMPLETE_FILE_DESC;
@ -819,20 +831,17 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
}
}
wchar_t *tmp = escape( suff, 1 );
tmp = escape( suff, 1 );
free(suff);
suff = tmp;
wchar_t *desc = (wchar_t *)hash_get( suffix_hash, suff );
desc = (wchar_t *)hash_get( suffix_hash, suff );
if( !desc )
{
wchar_t *cmd = wcsdupcat( SUFFIX_CMD_STR, suff );
if( cmd )
{
array_list_t l;
al_init( &l );
@ -1000,7 +1009,7 @@ static void copy_strings_with_prefix( array_list_t *comp_out,
wchar_t *wc, *tmp;
tmp = expand_one( 0,
wcsdup(wc_escaped), EXPAND_SKIP_SUBSHELL | EXPAND_SKIP_WILDCARDS);
wcsdup(wc_escaped), EXPAND_SKIP_SUBSHELL | EXPAND_SKIP_WILDCARDS);
if(!tmp)
return;
@ -1012,12 +1021,9 @@ static void copy_strings_with_prefix( array_list_t *comp_out,
wc = parse_util_unescape_wildcards( tmp );
free(tmp);
// int str_len = wcslen( str );
for( i=0; i<al_get_count( possible_comp ); i++ )
{
wchar_t *next_str = (wchar_t *)al_get( possible_comp, i );
// fwprintf( stderr, L"try wc %ls against %ls\n", wc, next_str );
wildcard_complete( next_str, wc, desc, desc_func, comp_out );
}
@ -1262,59 +1268,59 @@ static void complete_cmd( const wchar_t *cmd,
}
// fwprintf( stderr, L"cdpath %ls\n", cdpath_cpy );
/*
Tab complete implicit cd for directories in CDPATH
*/
if( cmd[0] != L'/' && ( wcsncmp( cmd, L"./", 2 )!=0) )
{
for( nxt_path = wcstok( cdpath_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
int i;
array_list_t tmp;
wchar_t *nxt_completion=
wcsdupcat2( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
0 );
if( ! nxt_completion )
continue;
al_init( &tmp );
if( expand_string( 0,
nxt_completion,
&tmp,
ACCEPT_INCOMPLETE | DIRECTORIES_ONLY ) != EXPAND_ERROR )
for( nxt_path = wcstok( cdpath_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
for( i=0; i<al_get_count(&tmp); i++ )
int i;
array_list_t tmp;
wchar_t *nxt_completion=
wcsdupcat2( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
0 );
if( ! nxt_completion )
{
wchar_t *nxt = (wchar_t *)al_get( &tmp, i );
continue;
}
al_init( &tmp );
wchar_t *desc = wcsrchr( nxt, COMPLETE_SEP );
if( desc )
if( expand_string( 0,
nxt_completion,
&tmp,
ACCEPT_INCOMPLETE | DIRECTORIES_ONLY ) != EXPAND_ERROR )
{
for( i=0; i<al_get_count(&tmp); i++ )
{
int is_valid = desc && (wcscmp(desc+1,
COMPLETE_DIRECTORY_DESC)==0);
if( is_valid )
wchar_t *nxt = (wchar_t *)al_get( &tmp, i );
wchar_t *desc = wcsrchr( nxt, COMPLETE_SEP );
if( desc )
{
al_push( comp, nxt );
}
else
{
free(nxt);
int is_valid = desc && (wcscmp(desc+1,
COMPLETE_DIRECTORY_DESC)==0);
if( is_valid )
{
al_push( comp, nxt );
}
else
{
free(nxt);
}
}
}
}
}
al_destroy( &tmp );
}
al_destroy( &tmp );
}
}
@ -1493,8 +1499,6 @@ static int complete_param( wchar_t *cmd_orig,
if( ( (!wildcard_match( match, i->cmd ) ) ) )
continue;
/* wprintf( L"Found matching command %ls\n", i->cmd ); */
use_common=1;
if( str[0] == L'-' )
{
@ -1505,8 +1509,6 @@ static int complete_param( wchar_t *cmd_orig,
wchar_t *arg;
if( (arg=param_match2( o, str ))!=0 && condition_test( o->condition ))
{
/* wprintf( L"Use option with desc %ls\n", o->desc ); */
use_common &= ((o->result_mode & NO_COMMON )==0);
use_files &= ((o->result_mode & NO_FILES )==0);
complete_from_args( arg, o->comp, o->desc, comp_out );
@ -1583,7 +1585,6 @@ static int complete_param( wchar_t *cmd_orig,
if( (o->short_opt == L'\0' ) && (o->long_opt[0]==L'\0'))
{
use_files &= ((o->result_mode & NO_FILES )==0);
// debug( 0, L"Running argument command %ls", o->comp );
complete_from_args( str, o->comp, o->desc, comp_out );
}
@ -1629,21 +1630,23 @@ static int complete_param( wchar_t *cmd_orig,
if( o->old_mode || !(o->result_mode & NO_COMMON ) )
{
al_push( comp_out,
wcsdupcat2(&((wchar_t *)whole_opt.buff)[wcslen(str)], COMPLETE_SEP_STR, o->desc, (void *)0) );
// fwprintf( stderr, L"Add without param %ls\n", o->long_opt );
wcsdupcat2( &((wchar_t *)whole_opt.buff)[wcslen(str)],
COMPLETE_SEP_STR,
o->desc,
(void *)0) );
}
if( !o->old_mode && ( wcslen(o->comp) || (o->result_mode & NO_COMMON ) ) )
{
al_push( comp_out,
wcsdupcat2(&((wchar_t *)whole_opt.buff)[wcslen(str)], L"=", COMPLETE_SEP_STR, o->desc, (void *)0) );
// fwprintf( stderr, L"Add with param %ls\n", o->long_opt );
wcsdupcat2( &((wchar_t *)whole_opt.buff)[wcslen(str)],
L"=",
COMPLETE_SEP_STR,
o->desc,
(void *)0) );
}
// fwprintf( stderr, L"Matching long option %ls\n", o->long_opt );
}
sb_destroy( &whole_opt );
}
}
}
@ -1661,13 +1664,16 @@ static void complete_param_expand( wchar_t *str,
int do_file )
{
wchar_t *comp_str;
if( (wcsncmp( str, L"--", 2 )) == 0 && (comp_str = wcschr(str, L'=' ) ) )
{
comp_str++;
}
else
{
comp_str = str;
}
debug( 2,
L"expand_string( \"%ls\", comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls );",
comp_str,
@ -1692,13 +1698,12 @@ static int complete_variable( const wchar_t *var,
array_list_t names;
al_init( &names );
env_get_names( &names, 0 );
/* wprintf( L"Search string %ls\n", var );*/
/* wprintf( L"Got %d variables\n", al_get_count( &names ) );*/
for( i=0; i<al_get_count( &names ); i++ )
{
wchar_t *name = (wchar_t *)al_get( &names, i );
int namelen = wcslen( name );
if( varlen > namelen )
continue;
@ -1726,7 +1731,10 @@ static int complete_variable( const wchar_t *var,
}
/**
Search the specified string for the \$ sign, try to complete as an environment variable
Search the specified string for the \$ sign. If found, try to
complete as an environment variable.
\return 0 if unable to complete, 1 otherwise
*/
static int try_complete_variable( const wchar_t *cmd,
array_list_t *comp )
@ -1752,9 +1760,11 @@ static int try_complete_variable( const wchar_t *cmd,
}
/**
Try to complete the specified string as a username. This is used by ~USER type expansion.
*/
Try to complete the specified string as a username. This is used by
~USER type expansion.
\return 0 if unable to complete, 1 otherwise
*/
static int try_complete_user( const wchar_t *cmd,
array_list_t *comp )
{
@ -1763,7 +1773,6 @@ static int try_complete_user( const wchar_t *cmd,
int mode = 0;
int res = 0;
for( p=cmd; *p; p++ )
{
switch( mode )
@ -1822,13 +1831,10 @@ static int try_complete_user( const wchar_t *cmd,
struct passwd *pw;
int name_len = wcslen( user_name );
/* wprintf( L"Complete name \'%ls\'\n", user_name );*/
setpwent();
while((pw=getpwent()) != 0)
{
/* wprintf( L"Try %ls\n", pw->pw_name );*/
wchar_t *pw_name = str2wcs( pw->pw_name );
if( pw_name )
{

View file

@ -302,7 +302,6 @@ int writech( wint_t ch )
static mbstate_t out_state;
char buff[MB_CUR_MAX];
size_t bytes = wcrtomb( buff, ch, &out_state );
int err;
int i;
for( i=0; i<bytes; i++ )

View file

@ -36,10 +36,16 @@ static hash_table_t *all_loaded=0;
int parse_util_lineno( const wchar_t *str, int len )
{
static int res = 1;
static int i=0;
/**
First cached state
*/
static const wchar_t *prev_str = 0;
static int i=0;
static int res = 1;
/**
Second cached state
*/
static const wchar_t *prev_str2 = 0;
static int i2 = 0;
static int res2 = 1;
@ -111,7 +117,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
{
if(( paran_count == 0)&&(paran_begin==0))
paran_begin = pos;
paran_count++;
}
else if( *pos == ')' )
@ -241,7 +247,6 @@ static void job_or_process_extent( const wchar_t *buff,
return;
pos = cursor_pos - (begin - buff);
// fwprintf( stderr, L"Subshell extent: %d %d %d\n", begin-buff, end-buff, pos );
if( a )
{
@ -259,14 +264,12 @@ static void job_or_process_extent( const wchar_t *buff,
{
die_mem();
}
// fwprintf( stderr, L"Strlen: %d\n", wcslen(buffcpy ) );
for( tok_init( &tok, buffcpy, TOK_ACCEPT_UNFINISHED );
tok_has_next( &tok ) && !finished;
tok_next( &tok ) )
{
int tok_begin = tok_get_pos( &tok );
// fwprintf( stderr, L".");
switch( tok_last_type( &tok ) )
{
@ -277,8 +280,6 @@ static void job_or_process_extent( const wchar_t *buff,
case TOK_END:
case TOK_BACKGROUND:
{
// fwprintf( stderr, L"New cmd at %d\n", tok_begin );
if( tok_begin >= pos )
{
@ -297,7 +298,6 @@ static void job_or_process_extent( const wchar_t *buff,
}
}
// fwprintf( stderr, L"Res: %d %d\n", *a-buff, *b-buff );
free( buffcpy);
tok_destroy( &tok );
@ -593,7 +593,8 @@ int parse_util_load( const wchar_t *cmd,
free( esc );
on_load(cmd );
if( on_load )
on_load(cmd );
/*
Source the completion file for the specified completion