Fix broken method for sorting output of builtin commands 'functions', 'set' and others

darcs-hash:20060514094721-ac50b-9f1d8b6a2e8b4438e6a655de61af54d15cd4f537.gz
This commit is contained in:
axel 2006-05-14 19:47:21 +10:00
parent ff1c5e058f
commit 92ecc01baa
3 changed files with 32 additions and 45 deletions

View File

@ -497,27 +497,24 @@ static int builtin_builtin( wchar_t **argv )
if( list ) if( list )
{ {
array_list_t names; array_list_t names;
wchar_t **names_arr;
int i; int i;
al_init( &names ); al_init( &names );
builtin_get_names( &names ); builtin_get_names( &names );
names_arr = list_to_char_arr( &names ); sort_list( &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
for( i=0; i<al_get_count( &names ); i++ ) 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; continue;
sb_append2( sb_out, sb_append2( sb_out,
names_arr[i], el,
L"\n", L"\n",
(void *)0 ); (void *)0 );
} }
free( names_arr );
al_destroy( &names ); al_destroy( &names );
} }
return 0; return 0;
@ -677,7 +674,6 @@ static int builtin_functions( wchar_t **argv )
wchar_t *desc=0; wchar_t *desc=0;
array_list_t names; array_list_t names;
wchar_t **names_arr;
int argc=builtin_count_args( argv ); int argc=builtin_count_args( argv );
int list=0; int list=0;
@ -820,11 +816,7 @@ static int builtin_functions( wchar_t **argv )
al_init( &names ); al_init( &names );
function_get_names( &names, show_hidden ); function_get_names( &names, show_hidden );
names_arr = list_to_char_arr( &names ); sort_list( &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
if( is_screen ) if( is_screen )
{ {
string_buffer_t buff; string_buffer_t buff;
@ -833,12 +825,12 @@ static int builtin_functions( wchar_t **argv )
for( i=0; i<al_get_count( &names ); i++ ) for( i=0; i<al_get_count( &names ); i++ )
{ {
sb_append2( &buff, sb_append2( &buff,
names_arr[i], al_get(&names, i),
L", ", L", ",
(void *)0 ); (void *)0 );
} }
write_screen( (wchar_t *)buff.buff ); write_screen( (wchar_t *)buff.buff, sb_out );
sb_destroy( &buff ); sb_destroy( &buff );
} }
else else
@ -846,13 +838,12 @@ static int builtin_functions( wchar_t **argv )
for( i=0; i<al_get_count( &names ); i++ ) for( i=0; i<al_get_count( &names ); i++ )
{ {
sb_append2( sb_out, sb_append2( sb_out,
names_arr[i], al_get(&names, i),
L"\n", L"\n",
(void *)0 ); (void *)0 );
} }
} }
free( names_arr );
al_destroy( &names ); al_destroy( &names );
return 0; return 0;
} }
@ -865,16 +856,13 @@ static int builtin_functions( wchar_t **argv )
sb_append( sb_out, _( L"Current function definitions are:\n\n" ) ); sb_append( sb_out, _( L"Current function definitions are:\n\n" ) );
al_init( &names ); al_init( &names );
function_get_names( &names, show_hidden ); function_get_names( &names, show_hidden );
names_arr = list_to_char_arr( &names ); sort_list( &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
for( i=0; i<al_get_count( &names ); i++ ) 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 ); al_destroy( &names );
break; break;
} }
@ -1170,7 +1158,6 @@ static int builtin_function( wchar_t **argv )
{ {
int i; int i;
array_list_t names; array_list_t names;
wchar_t **names_arr;
int chars=0; int chars=0;
// builtin_print_help( argv[0], sb_err ); // builtin_print_help( argv[0], sb_err );
@ -1180,14 +1167,11 @@ static int builtin_function( wchar_t **argv )
al_init( &names ); al_init( &names );
function_get_names( &names, 0 ); function_get_names( &names, 0 );
names_arr = list_to_char_arr( &names ); sort_list( &names );
qsort( names_arr,
al_get_count( &names ),
sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
for( i=0; i<al_get_count( &names ); i++ ) 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 ); int l = wcslen( nxt + 2 );
if( chars+l > common_get_width() ) if( chars+l > common_get_width() )
{ {
@ -1198,7 +1182,6 @@ static int builtin_function( wchar_t **argv )
sb_append2( sb_err, sb_append2( sb_err,
nxt, L" ", (void *)0 ); nxt, L" ", (void *)0 );
} }
free( names_arr );
al_destroy( &names ); al_destroy( &names );
sb_append( sb_err, L"\n" ); sb_append( sb_err, L"\n" );

View File

@ -545,23 +545,27 @@ void debug( int level, const wchar_t *msg, ... )
{ {
va_list va; va_list va;
string_buffer_t sb; string_buffer_t sb;
string_buffer_t sb2;
if( level > debug_level ) if( level > debug_level )
return; return;
sb_init( &sb ); sb_init( &sb );
sb_init( &sb2 );
va_start( va, msg ); va_start( va, msg );
sb_printf( &sb, L"%ls: ", program_name ); sb_printf( &sb, L"%ls: ", program_name );
sb_vprintf( &sb, msg, va ); sb_vprintf( &sb, msg, va );
va_end( 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( &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; const wchar_t *start, *pos;
int line_width = 0; int line_width = 0;
@ -611,8 +615,8 @@ void write_screen( const wchar_t *msg )
*/ */
wchar_t *token = wcsndup( start, pos-start ); wchar_t *token = wcsndup( start, pos-start );
if( line_width != 0 ) if( line_width != 0 )
putwc( L'\n', stderr ); sb_append_char( buff, L'\n' );
fwprintf( stderr, L"%ls-\n", token ); sb_printf( buff, L"%ls-\n", token );
free( token ); free( token );
line_width=0; line_width=0;
} }
@ -624,10 +628,10 @@ void write_screen( const wchar_t *msg )
wchar_t *token = wcsndup( start, pos-start ); wchar_t *token = wcsndup( start, pos-start );
if( (line_width + (line_width!=0?1:0) + tok_width) > screen_width ) 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; 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 ); free( token );
line_width += (line_width!=0?1:0) + tok_width; line_width += (line_width!=0?1:0) + tok_width;
} }
@ -642,9 +646,9 @@ void write_screen( const wchar_t *msg )
} }
else 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, wchar_t *escape( const wchar_t *in,

View File

@ -287,10 +287,10 @@ int common_get_height();
void common_handle_winch( int signal ); void common_handle_winch( int signal );
/** /**
Write paragraph of output to screen. Ignore newlines in message and Write paragraph of output to the specified stringbuffer, and redo
perform internal line-breaking. 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 #endif