mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
Add better debbuging information when writembs is called with null value.
darcs-hash:20070909140436-75c98-b6c925c441ebaa349f998b95314295296fb36252.gz
This commit is contained in:
parent
370aeec44d
commit
76bb8e79b2
153
fish_pager.c
153
fish_pager.c
|
@ -253,8 +253,8 @@ static int try_sequence( char *seq )
|
|||
wint_t c=0;
|
||||
|
||||
for( j=0;
|
||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||
j++ )
|
||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||
j++ )
|
||||
;
|
||||
|
||||
if( seq[j] == '\0' )
|
||||
|
@ -408,8 +408,8 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
|||
int desc_all = c->desc_width?c->desc_width+4:0;
|
||||
|
||||
comp_width = maxi( mini( c->comp_width,
|
||||
2*(width-4)/3 ),
|
||||
width - desc_all );
|
||||
2*(width-4)/3 ),
|
||||
width - desc_all );
|
||||
if( c->desc_width )
|
||||
desc_width = width-comp_width-4;
|
||||
else
|
||||
|
@ -438,7 +438,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
|||
}
|
||||
written += print_max( L"(", 1, 0 );
|
||||
set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ),
|
||||
FISH_COLOR_IGNORE );
|
||||
FISH_COLOR_IGNORE );
|
||||
written += print_max( c->desc, desc_width, 0 );
|
||||
written += print_max( L")", 1, 0 );
|
||||
}
|
||||
|
@ -467,12 +467,12 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
|||
*/
|
||||
|
||||
static void completion_print( int cols,
|
||||
int *width,
|
||||
int row_start,
|
||||
int row_stop,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l)
|
||||
int *width,
|
||||
int row_start,
|
||||
int row_stop,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l)
|
||||
{
|
||||
|
||||
int rows = (al_get_count( l )-1)/cols+1;
|
||||
|
@ -520,9 +520,9 @@ static void completion_print( int cols,
|
|||
*/
|
||||
|
||||
static int completion_try_print( int cols,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l )
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l )
|
||||
{
|
||||
/*
|
||||
The calculated preferred width of each column
|
||||
|
@ -578,9 +578,9 @@ static int completion_try_print( int cols,
|
|||
min += 2;
|
||||
}
|
||||
min_width[j] = maxi( min_width[j],
|
||||
min );
|
||||
min );
|
||||
pref_width[j] = maxi( pref_width[j],
|
||||
pref );
|
||||
pref );
|
||||
}
|
||||
min_tot_width += min_width[j];
|
||||
pref_tot_width += pref_width[j];
|
||||
|
@ -614,8 +614,8 @@ static int completion_try_print( int cols,
|
|||
pref_tot_width-termsize.ws_col );
|
||||
*/
|
||||
if( min_tot_width < termsize.ws_col &&
|
||||
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
||||
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
||||
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
||||
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
||||
{
|
||||
/*
|
||||
Terminal almost wide enough, or squeezing makes the
|
||||
|
@ -676,12 +676,12 @@ static int completion_try_print( int cols,
|
|||
writembs(enter_ca_mode);
|
||||
|
||||
completion_print( cols,
|
||||
width,
|
||||
0,
|
||||
termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l);
|
||||
width,
|
||||
0,
|
||||
termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l);
|
||||
/*
|
||||
List does not fit on screen. Print one screenfull and
|
||||
leave a scrollable interface
|
||||
|
@ -692,12 +692,12 @@ static int completion_try_print( int cols,
|
|||
sb_init( &msg );
|
||||
|
||||
set_color( FISH_COLOR_BLACK,
|
||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||
sb_printf( &msg,
|
||||
_(L" %d to %d of %d \r"),
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
rows );
|
||||
_(L" %d to %d of %d \r"),
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
rows );
|
||||
|
||||
writestr((wchar_t *)msg.buff);
|
||||
sb_destroy( &msg );
|
||||
|
@ -715,14 +715,14 @@ static int completion_try_print( int cols,
|
|||
writembs(tparm( cursor_address, 0, 0));
|
||||
writembs(scroll_reverse);
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
writembs( tparm( cursor_address,
|
||||
termsize.ws_row-1, 0) );
|
||||
termsize.ws_row-1, 0) );
|
||||
writembs(clr_eol );
|
||||
|
||||
}
|
||||
|
@ -736,12 +736,12 @@ static int completion_try_print( int cols,
|
|||
{
|
||||
pos++;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos+termsize.ws_row-2,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos+termsize.ws_row-2,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -750,17 +750,17 @@ static int completion_try_print( int cols,
|
|||
{
|
||||
|
||||
npos = mini( rows - termsize.ws_row+1,
|
||||
pos + termsize.ws_row-1 );
|
||||
pos + termsize.ws_row-1 );
|
||||
if( npos != pos )
|
||||
{
|
||||
pos = npos;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -774,18 +774,18 @@ static int completion_try_print( int cols,
|
|||
case PAGE_UP:
|
||||
{
|
||||
npos = maxi( 0,
|
||||
pos - termsize.ws_row+1 );
|
||||
pos - termsize.ws_row+1 );
|
||||
|
||||
if( npos != pos )
|
||||
{
|
||||
pos = npos;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1008,8 +1008,8 @@ static void init( int mangle_descriptors, int out )
|
|||
struct sigaction act;
|
||||
|
||||
static struct termios pager_modes;
|
||||
|
||||
|
||||
char *term;
|
||||
|
||||
if( mangle_descriptors )
|
||||
{
|
||||
|
||||
|
@ -1076,22 +1076,23 @@ static void init( int mangle_descriptors, int out )
|
|||
|
||||
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
||||
memcpy( &saved_modes,
|
||||
&pager_modes,
|
||||
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
||||
&pager_modes,
|
||||
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
||||
|
||||
pager_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
||||
pager_modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
||||
pager_modes.c_cc[VMIN]=1;
|
||||
pager_modes.c_cc[VTIME]=0;
|
||||
pager_modes.c_cc[VMIN]=1;
|
||||
pager_modes.c_cc[VTIME]=0;
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||
{
|
||||
wperror(L"tcsetattr");
|
||||
exit(1);
|
||||
}
|
||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||
{
|
||||
wperror(L"tcsetattr");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
||||
{
|
||||
|
@ -1099,6 +1100,14 @@ static void init( int mangle_descriptors, int out )
|
|||
exit(1);
|
||||
}
|
||||
|
||||
term = getenv("TERM");
|
||||
if( term )
|
||||
{
|
||||
wchar_t *wterm = str2wcs(term);
|
||||
output_set_term( wterm );
|
||||
free( wterm );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1137,7 +1146,7 @@ static void read_array( FILE* file, array_list_t *comp )
|
|||
|
||||
while( 1 )
|
||||
{
|
||||
c = getc( file );
|
||||
c = getc( file );
|
||||
if( c == EOF )
|
||||
{
|
||||
break;
|
||||
|
@ -1265,10 +1274,10 @@ int main( int argc, char **argv )
|
|||
int opt_index = 0;
|
||||
|
||||
int opt = getopt_long( argc,
|
||||
argv,
|
||||
GETOPT_STRING,
|
||||
long_options,
|
||||
&opt_index );
|
||||
argv,
|
||||
GETOPT_STRING,
|
||||
long_options,
|
||||
&opt_index );
|
||||
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
|
2
input.c
2
input.c
|
@ -1435,6 +1435,8 @@ int input_init()
|
|||
debug( 0, _( L"Could not set up terminal" ) );
|
||||
exit(1);
|
||||
}
|
||||
output_set_term( env_get( L"TERM" ) );
|
||||
|
||||
hash_init( &all_mappings, &hash_wcs_func, &hash_wcs_cmp );
|
||||
|
||||
/*
|
||||
|
|
17
output.c
17
output.c
|
@ -121,6 +121,9 @@ static char *writestr_buff = 0;
|
|||
|
||||
static int (*out)(char c) = &writeb_internal;
|
||||
|
||||
static wchar_t *current_term = 0;
|
||||
|
||||
|
||||
/**
|
||||
Cleanup function. Run automatically through halloc
|
||||
*/
|
||||
|
@ -366,7 +369,7 @@ int writeb( tputs_arg_t b )
|
|||
return 0;
|
||||
}
|
||||
|
||||
int writembs( char *str )
|
||||
int writembs_internal( char *str )
|
||||
{
|
||||
CHECK( str, 1 );
|
||||
|
||||
|
@ -580,3 +583,15 @@ int output_color_code( const wchar_t *val )
|
|||
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
||||
|
||||
}
|
||||
|
||||
void output_set_term( wchar_t *term )
|
||||
{
|
||||
current_term = halloc_wcsdup(global_context, term);
|
||||
}
|
||||
|
||||
wchar_t *output_get_term()
|
||||
{
|
||||
return current_term ? current_term : L"<unknown>";
|
||||
}
|
||||
|
||||
|
||||
|
|
26
output.h
26
output.h
|
@ -73,13 +73,34 @@ enum
|
|||
|
||||
void set_color( int c, int c2 );
|
||||
|
||||
|
||||
#define writembs( mbs ) \
|
||||
{ \
|
||||
char *tmp = mbs; \
|
||||
if( tmp ) \
|
||||
{ \
|
||||
writembs_internal( tmp ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
debug( 0, \
|
||||
_(L"Tried to use terminfo string %s on line %d of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"), \
|
||||
#mbs, \
|
||||
__LINE__, \
|
||||
__FILE__, \
|
||||
output_get_term(), \
|
||||
PACKAGE_BUGREPORT); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Write a char * narrow string to FD 1, needed for the terminfo
|
||||
strings. This is usually just a wrapper aound tputs, using writeb
|
||||
as the sending function. But a weird bug on PPC Linux means that on
|
||||
this platform, write is instead used directly.
|
||||
*/
|
||||
int writembs( char *str );
|
||||
int writembs_internal( char *str );
|
||||
|
||||
/**
|
||||
Write a wide character using the output method specified using output_set_writer().
|
||||
|
@ -126,4 +147,7 @@ void output_set_writer( int (*writer)(char) );
|
|||
|
||||
int (*output_get_writer())(char) ;
|
||||
|
||||
void output_set_term( wchar_t *term );
|
||||
wchar_t *output_get_term();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user