mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Fix broken method for sorting output of builtin commands 'functions', 'set' and others
darcs-hash:20060514094721-ac50b-9f1d8b6a2e8b4438e6a655de61af54d15cd4f537.gz
This commit is contained in:
parent
ff1c5e058f
commit
92ecc01baa
3 changed files with 32 additions and 45 deletions
51
builtin.c
51
builtin.c
|
@ -497,27 +497,24 @@ static int builtin_builtin( wchar_t **argv )
|
|||
if( list )
|
||||
{
|
||||
array_list_t names;
|
||||
wchar_t **names_arr;
|
||||
int i;
|
||||
|
||||
al_init( &names );
|
||||
builtin_get_names( &names );
|
||||
names_arr = list_to_char_arr( &names );
|
||||
qsort( names_arr,
|
||||
al_get_count( &names ),
|
||||
sizeof(wchar_t *),
|
||||
(int (*)(const void *, const void *))&wcsfilecmp );
|
||||
sort_list( &names );
|
||||
|
||||
for( i=0; i<al_get_count( &names ); i++ )
|
||||
{
|
||||
if( wcscmp( names_arr[i], L"count" ) == 0 )
|
||||
wchar_t *el = (wchar_t *)al_get( &names, i );
|
||||
|
||||
if( wcscmp( el, L"count" ) == 0 )
|
||||
continue;
|
||||
|
||||
sb_append2( sb_out,
|
||||
names_arr[i],
|
||||
el,
|
||||
L"\n",
|
||||
(void *)0 );
|
||||
}
|
||||
free( names_arr );
|
||||
al_destroy( &names );
|
||||
}
|
||||
return 0;
|
||||
|
@ -677,7 +674,6 @@ static int builtin_functions( wchar_t **argv )
|
|||
wchar_t *desc=0;
|
||||
|
||||
array_list_t names;
|
||||
wchar_t **names_arr;
|
||||
|
||||
int argc=builtin_count_args( argv );
|
||||
int list=0;
|
||||
|
@ -820,11 +816,7 @@ static int builtin_functions( wchar_t **argv )
|
|||
|
||||
al_init( &names );
|
||||
function_get_names( &names, show_hidden );
|
||||
names_arr = list_to_char_arr( &names );
|
||||
qsort( names_arr,
|
||||
al_get_count( &names ),
|
||||
sizeof(wchar_t *),
|
||||
(int (*)(const void *, const void *))&wcsfilecmp );
|
||||
sort_list( &names );
|
||||
if( is_screen )
|
||||
{
|
||||
string_buffer_t buff;
|
||||
|
@ -833,12 +825,12 @@ static int builtin_functions( wchar_t **argv )
|
|||
for( i=0; i<al_get_count( &names ); i++ )
|
||||
{
|
||||
sb_append2( &buff,
|
||||
names_arr[i],
|
||||
al_get(&names, i),
|
||||
L", ",
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
write_screen( (wchar_t *)buff.buff );
|
||||
write_screen( (wchar_t *)buff.buff, sb_out );
|
||||
sb_destroy( &buff );
|
||||
}
|
||||
else
|
||||
|
@ -846,13 +838,12 @@ static int builtin_functions( wchar_t **argv )
|
|||
for( i=0; i<al_get_count( &names ); i++ )
|
||||
{
|
||||
sb_append2( sb_out,
|
||||
names_arr[i],
|
||||
al_get(&names, i),
|
||||
L"\n",
|
||||
(void *)0 );
|
||||
}
|
||||
}
|
||||
|
||||
free( names_arr );
|
||||
al_destroy( &names );
|
||||
return 0;
|
||||
}
|
||||
|
@ -865,16 +856,13 @@ static int builtin_functions( wchar_t **argv )
|
|||
sb_append( sb_out, _( L"Current function definitions are:\n\n" ) );
|
||||
al_init( &names );
|
||||
function_get_names( &names, show_hidden );
|
||||
names_arr = list_to_char_arr( &names );
|
||||
qsort( names_arr,
|
||||
al_get_count( &names ),
|
||||
sizeof(wchar_t *),
|
||||
(int (*)(const void *, const void *))&wcsfilecmp );
|
||||
sort_list( &names );
|
||||
|
||||
for( i=0; i<al_get_count( &names ); i++ )
|
||||
{
|
||||
functions_def( names_arr[i] );
|
||||
functions_def( (wchar_t *)al_get( &names, i ) );
|
||||
}
|
||||
free( names_arr );
|
||||
|
||||
al_destroy( &names );
|
||||
break;
|
||||
}
|
||||
|
@ -1170,7 +1158,6 @@ static int builtin_function( wchar_t **argv )
|
|||
{
|
||||
int i;
|
||||
array_list_t names;
|
||||
wchar_t **names_arr;
|
||||
int chars=0;
|
||||
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
@ -1180,14 +1167,11 @@ static int builtin_function( wchar_t **argv )
|
|||
|
||||
al_init( &names );
|
||||
function_get_names( &names, 0 );
|
||||
names_arr = list_to_char_arr( &names );
|
||||
qsort( names_arr,
|
||||
al_get_count( &names ),
|
||||
sizeof(wchar_t *),
|
||||
(int (*)(const void *, const void *))&wcsfilecmp );
|
||||
sort_list( &names );
|
||||
|
||||
for( i=0; i<al_get_count( &names ); i++ )
|
||||
{
|
||||
wchar_t *nxt = names_arr[i];
|
||||
wchar_t *nxt = (wchar_t *)al_get( &names, i );
|
||||
int l = wcslen( nxt + 2 );
|
||||
if( chars+l > common_get_width() )
|
||||
{
|
||||
|
@ -1198,7 +1182,6 @@ static int builtin_function( wchar_t **argv )
|
|||
sb_append2( sb_err,
|
||||
nxt, L" ", (void *)0 );
|
||||
}
|
||||
free( names_arr );
|
||||
al_destroy( &names );
|
||||
sb_append( sb_err, L"\n" );
|
||||
|
||||
|
|
20
common.c
20
common.c
|
@ -545,23 +545,27 @@ void debug( int level, const wchar_t *msg, ... )
|
|||
{
|
||||
va_list va;
|
||||
string_buffer_t sb;
|
||||
string_buffer_t sb2;
|
||||
|
||||
if( level > debug_level )
|
||||
return;
|
||||
|
||||
sb_init( &sb );
|
||||
sb_init( &sb2 );
|
||||
va_start( va, msg );
|
||||
|
||||
sb_printf( &sb, L"%ls: ", program_name );
|
||||
sb_vprintf( &sb, msg, va );
|
||||
va_end( va );
|
||||
|
||||
write_screen( (wchar_t *)sb.buff );
|
||||
write_screen( (wchar_t *)sb.buff, &sb2 );
|
||||
fwprintf( stderr, L"%ls", sb2.buff );
|
||||
|
||||
sb_destroy( &sb );
|
||||
sb_destroy( &sb2 );
|
||||
}
|
||||
|
||||
void write_screen( const wchar_t *msg )
|
||||
void write_screen( const wchar_t *msg, string_buffer_t *buff )
|
||||
{
|
||||
const wchar_t *start, *pos;
|
||||
int line_width = 0;
|
||||
|
@ -611,8 +615,8 @@ void write_screen( const wchar_t *msg )
|
|||
*/
|
||||
wchar_t *token = wcsndup( start, pos-start );
|
||||
if( line_width != 0 )
|
||||
putwc( L'\n', stderr );
|
||||
fwprintf( stderr, L"%ls-\n", token );
|
||||
sb_append_char( buff, L'\n' );
|
||||
sb_printf( buff, L"%ls-\n", token );
|
||||
free( token );
|
||||
line_width=0;
|
||||
}
|
||||
|
@ -624,10 +628,10 @@ void write_screen( const wchar_t *msg )
|
|||
wchar_t *token = wcsndup( start, pos-start );
|
||||
if( (line_width + (line_width!=0?1:0) + tok_width) > screen_width )
|
||||
{
|
||||
putwc( L'\n', stderr );
|
||||
sb_append_char( buff, L'\n' );
|
||||
line_width=0;
|
||||
}
|
||||
fwprintf( stderr, L"%ls%ls", line_width?L" ":L"", token );
|
||||
sb_printf( buff, L"%ls%ls", line_width?L" ":L"", token );
|
||||
free( token );
|
||||
line_width += (line_width!=0?1:0) + tok_width;
|
||||
}
|
||||
|
@ -642,9 +646,9 @@ void write_screen( const wchar_t *msg )
|
|||
}
|
||||
else
|
||||
{
|
||||
fwprintf( stderr, L"%ls", msg );
|
||||
sb_printf( buff, L"%ls", msg );
|
||||
}
|
||||
putwc( L'\n', stderr );
|
||||
sb_append_char( buff, L'\n' );
|
||||
}
|
||||
|
||||
wchar_t *escape( const wchar_t *in,
|
||||
|
|
6
common.h
6
common.h
|
@ -287,10 +287,10 @@ int common_get_height();
|
|||
void common_handle_winch( int signal );
|
||||
|
||||
/**
|
||||
Write paragraph of output to screen. Ignore newlines in message and
|
||||
perform internal line-breaking.
|
||||
Write paragraph of output to the specified stringbuffer, and redo
|
||||
the linebreaks to fit the current screen.
|
||||
*/
|
||||
void write_screen( const wchar_t *msg );
|
||||
void write_screen( const wchar_t *msg, string_buffer_t *buff );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue