Fix occasional duplicate stack trace, reported by Mike Roberts. Also make fish less likely to print huge amounts of help in non-interactive mode, as per suggestion from Mike Roberts.

darcs-hash:20070131160317-ac50b-8354948f55a1478515ebfe7ddb6db14b6775dd18.gz
This commit is contained in:
axel 2007-02-01 02:03:17 +10:00
parent 55af8e4966
commit ba6661e9df
5 changed files with 26 additions and 35 deletions

View file

@ -241,7 +241,8 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b )
{ {
const wchar_t *h; const wchar_t *h;
int is_short = 0;
if( b == sb_err ) if( b == sb_err )
{ {
sb_append( sb_err, sb_append( sb_err,
@ -257,7 +258,7 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b )
if( str ) if( str )
{ {
if( is_interactive && !builtin_out_redirect && b==sb_err) if( b==sb_err )
{ {
/* /*
@ -269,12 +270,14 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b )
screen_height = common_get_height(); screen_height = common_get_height();
lines = count_char( str, L'\n' ); lines = count_char( str, L'\n' );
if( lines > 2*screen_height/3 ) if( !is_interactive || (lines > 2*screen_height/3) )
{ {
wchar_t *pos; wchar_t *pos;
int cut=0; int cut=0;
int i; int i;
is_short = 1;
/* /*
First move down 4 lines First move down 4 lines
*/ */
@ -338,6 +341,11 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b )
} }
sb_append( b, str ); sb_append( b, str );
if( is_short )
{
sb_printf( b, _(L"%ls: Type 'help %ls' for related documentation\n\n"), cmd, cmd );
}
free( str ); free( str );
} }
} }
@ -351,8 +359,6 @@ static void builtin_unknown_option( const wchar_t *cmd, const wchar_t *opt )
BUILTIN_ERR_UNKNOWN, BUILTIN_ERR_UNKNOWN,
cmd, cmd,
opt ); opt );
sb_append( sb_err,
parser_current_line() );
builtin_print_help( cmd, sb_err ); builtin_print_help( cmd, sb_err );
} }
@ -1646,8 +1652,7 @@ static int builtin_read( wchar_t **argv )
{ {
sb_printf( sb_err, sb_printf( sb_err,
BUILTIN_ERR_EXPUNEXP, BUILTIN_ERR_EXPUNEXP,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
@ -1658,8 +1663,7 @@ static int builtin_read( wchar_t **argv )
{ {
sb_printf( sb_err, sb_printf( sb_err,
BUILTIN_ERR_GLOCAL, BUILTIN_ERR_GLOCAL,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
@ -1683,7 +1687,7 @@ static int builtin_read( wchar_t **argv )
if( (!iswalnum(*src)) && (*src != L'_' ) ) if( (!iswalnum(*src)) && (*src != L'_' ) )
{ {
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *src ); sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *src );
sb_append2(sb_err, parser_current_line(), L"\n", (void *)0 ); builtin_print_help( argv[0], sb_err );
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
} }

View file

@ -35,12 +35,12 @@ enum
/** /**
Error message on multiple scope levels for variables Error message on multiple scope levels for variables
*/ */
#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n%ls\n" ) #define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n" )
/** /**
Error message for specifying both export and unexport to set/read Error message for specifying both export and unexport to set/read
*/ */
#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n%ls\n" ) #define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n" )
/** /**
Error message for unknown switch Error message for unknown switch

View file

@ -408,9 +408,6 @@ static int builtin_complete( wchar_t **argv )
BUILTIN_ERR_UNKNOWN, BUILTIN_ERR_UNKNOWN,
argv[0], argv[0],
long_options[opt_index].name ); long_options[opt_index].name );
sb_append( sb_err,
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
@ -574,8 +571,6 @@ static int builtin_complete( wchar_t **argv )
sb_printf( sb_err, sb_printf( sb_err,
_( L"%ls: Too many arguments\n" ), _( L"%ls: Too many arguments\n" ),
argv[0] ); argv[0] );
sb_append( sb_err,
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
res = 1; res = 1;

View file

@ -222,8 +222,6 @@ static int builtin_jobs( wchar_t **argv )
argv[0], argv[0],
long_options[opt_index].name ); long_options[opt_index].name );
sb_append( sb_err,
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );

View file

@ -560,9 +560,8 @@ static int builtin_set( wchar_t **argv )
if( query && (erase || list || global || local || universal || export || unexport ) ) if( query && (erase || list || global || local || universal || export || unexport ) )
{ {
sb_printf(sb_err, sb_printf(sb_err,
BUILTIN_ERR_COMBO2, BUILTIN_ERR_COMBO,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
return 1; return 1;
@ -573,9 +572,8 @@ static int builtin_set( wchar_t **argv )
if( erase && list ) if( erase && list )
{ {
sb_printf(sb_err, sb_printf(sb_err,
BUILTIN_ERR_COMBO2, BUILTIN_ERR_COMBO,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
return 1; return 1;
@ -588,8 +586,7 @@ static int builtin_set( wchar_t **argv )
{ {
sb_printf( sb_err, sb_printf( sb_err,
BUILTIN_ERR_GLOCAL, BUILTIN_ERR_GLOCAL,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
return 1; return 1;
} }
@ -601,8 +598,7 @@ static int builtin_set( wchar_t **argv )
{ {
sb_printf( sb_err, sb_printf( sb_err,
BUILTIN_ERR_EXPUNEXP, BUILTIN_ERR_EXPUNEXP,
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
return 1; return 1;
} }
@ -692,8 +688,7 @@ static int builtin_set( wchar_t **argv )
{ {
sb_printf( sb_err, sb_printf( sb_err,
_(L"%ls: Erase needs a variable name\n%ls\n"), _(L"%ls: Erase needs a variable name\n%ls\n"),
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
retcode = 1; retcode = 1;
@ -850,9 +845,8 @@ static int builtin_set( wchar_t **argv )
if( woptind != argc ) if( woptind != argc )
{ {
sb_printf( sb_err, sb_printf( sb_err,
_(L"%ls: Values cannot be specfied with erase\n%ls\n"), _(L"%ls: Values cannot be specfied with erase\n"),
argv[0], argv[0] );
parser_current_line() );
builtin_print_help( argv[0], sb_err ); builtin_print_help( argv[0], sb_err );
retcode=1; retcode=1;
} }