Improve description handling - handle symbolic link loops, handle description functions returning strings without a separator, and handle testing of un-stat:able files

darcs-hash:20060112144903-ac50b-9766abfa212b2eaf61509a65499df0018562b5d9.gz
This commit is contained in:
axel 2006-01-13 00:49:03 +10:00
parent 10fec8abb6
commit 16cb9dfa05
3 changed files with 47 additions and 39 deletions

View file

@ -89,6 +89,10 @@
Description for Rotten symlink
*/
#define COMPLETE_ROTTEN_SYMLINK_DESC _( L"Rotten symbolic link" )
/**
Description for symlink loop
*/
#define COMPLETE_LOOP_SYMLINK_DESC _( L"Symbolic link loop" )
/**
Description for socket
*/
@ -938,7 +942,16 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
break;
default:
wperror( L"stat" );
if( errno == ELOOP )
{
sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_LOOP_SYMLINK_DESC );
}
/*
Some kind of broken symlink. We ignore it
here, and it will get a 'file' description,
or one based on suffix.
*/
break;
}
}
@ -954,21 +967,6 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
}
}
/* else
{
switch( errno )
{
case EACCES:
break;
default:
fprintf( stderr, L"The following error happened on file %ls\n", filename );
wperror( L"lstat" );
break;
}
}
*/
if( wcslen((wchar_t *)get_desc_buff->buff) == 0 )
{
@ -1332,16 +1330,19 @@ static void complete_cmd( const wchar_t *cmd,
{
wchar_t *nxt = (wchar_t *)al_get( &tmp, i );
wchar_t *desc = wcsrchr( nxt, COMPLETE_SEP )+1;
int is_valid = (desc && (wcscmp(desc,
COMPLETE_DIRECTORY_DESC)==0));
if( is_valid )
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);
}
}
}
}

View file

@ -43,7 +43,7 @@ if status --is-login
end
if test -f /etc/sysconfig/i18n
eval (cat /etc/sysconfig/i18n |sed -ne 's/^\([a-zA-Z]*\)=\(.*\)$/set -gx \1 \2;/')
eval (cat /etc/sysconfig/i18n |sed -ne 's/^\([a-zA-Z]*\)=\(.*\)$/set -gx \1 \2;/p')
end
end

View file

@ -150,27 +150,34 @@ static int wildcard_complete_internal( const wchar_t *orig,
sep = wcschr(new, PROG_COMPLETE_SEP );
*sep = COMPLETE_SEP;
}
else if( desc_func )
{
/*
A descripton generating function is specified, use it
*/
new = wcsdupcat2( str, COMPLETE_SEP_STR, desc_func( orig ), (void *)0);
}
else
{
wchar_t *this_desc = desc;
if( desc_func )
{
/*
A descripton generating function is specified, call
it. If it returns something, use that as the
description.
*/
wchar_t *func_desc = desc_func( orig );
if( func_desc )
this_desc = func_desc;
}
/*
Append generic description to item, if the description exists
Append description to item, if a description exists
*/
if( desc && wcslen(desc) )
if( this_desc && wcslen(this_desc) )
{
/*
Check if the description already contains a separator character, if not, prepend it
*/
if( wcschr( desc, COMPLETE_SEP ) )
new = wcsdupcat2( str, desc, (void *)0 );
if( wcschr( this_desc, COMPLETE_SEP ) )
new = wcsdupcat2( str, this_desc, (void *)0 );
else
new = wcsdupcat2( str, COMPLETE_SEP_STR, desc, (void *)0 );
new = wcsdupcat2( str, COMPLETE_SEP_STR, this_desc, (void *)0 );
}
else
new = wcsdup( str );
@ -328,7 +335,7 @@ static int test_flags( wchar_t *filename,
struct stat buf;
if( wstat( filename, &buf ) == -1 )
{
return 1;
return 0;
}
if( S_IFDIR & buf.st_mode )