Fix indentation and add a few comments to fish_pager

darcs-hash:20070107164336-ac50b-d3cfa100a499d3f0996aac16288c4c892a65c1fe.gz
This commit is contained in:
axel
2007-01-08 02:43:36 +10:00
parent 94fbbb7669
commit 4a2a47666f

View File

@@ -98,7 +98,7 @@ enum
;
/**
The minimum number of columns the terminal may have for fish_pager to not refuse showing the completions
The minimum width (in characters) the terminal may have for fish_pager to not refuse showing the completions
*/
#define PAGER_MIN_WIDTH 16
@@ -112,13 +112,15 @@ enum
*/
#define GETOPT_STRING "c:hr:qvp:"
/**
Error to use when given an invalid file descriptor for reading completions or writing output
*/
#define ERR_NOT_FD _( L"%ls: Argument '%s' is not a valid file descriptor\n" )
/**
This struct should be continually updated by signals as the term
resizes, and as such always contain the correct current size.
*/
static struct winsize termsize;
/**
@@ -616,8 +618,22 @@ static int completion_try_print( int cols,
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
{
/*
Terminal almost wide enough, or squeezing makes the whole list fit on-screen
Terminal almost wide enough, or squeezing makes the
whole list fit on-screen.
This part of the code is really important. People hate
having to scroll through the completion list. In cases
where there are a huge number of completions, it can't
be helped, but it is not uncommon for the completions to
_almost_ fit on one screen. In those cases, it is almost
always desirable to 'squeeze' the completions into a
single page.
If we are using N columns and can get everything to
fit using squeezing, but everything would also fit
using N-1 columns, don't try.
*/
int tot_width = min_tot_width;
width = min_width;
@@ -1205,142 +1221,147 @@ int main( int argc, char **argv )
Third mode
*/
int completion_fd = -1;
FILE *completion_file;
int completion_fd = -1;
FILE *completion_file;
while( 1 )
{
static struct option
long_options[] =
{
{
"result-fd", required_argument, 0, 'r'
}
,
{
"completion-fd", required_argument, 0, 'c'
}
,
{
"prefix", required_argument, 0, 'p'
}
,
{
"is-quoted", no_argument, 0, 'q'
}
,
{
"help", no_argument, 0, 'h'
}
,
{
"version", no_argument, 0, 'v'
}
,
{
0, 0, 0, 0
}
}
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
GETOPT_STRING,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
while( 1 )
{
static struct option
long_options[] =
{
case 0:
{
break;
"result-fd", required_argument, 0, 'r'
}
case 'r':
,
{
result_fd = get_fd( optarg );
break;
"completion-fd", required_argument, 0, 'c'
}
case 'c':
,
{
completion_fd = get_fd( optarg );
break;
"prefix", required_argument, 0, 'p'
}
case 'p':
,
{
prefix = str2wcs(optarg);
break;
"is-quoted", no_argument, 0, 'q'
}
case 'h':
,
{
print_help( argv[0], 1 );
exit(0);
"help", no_argument, 0, 'h'
}
case 'v':
,
{
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
exit( 0 );
"version", no_argument, 0, 'v'
}
case 'q':
{
is_quoted = 1;
,
{
0, 0, 0, 0
}
}
}
if( completion_fd == -1 || result_fd == -1 )
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
GETOPT_STRING,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
debug( 0, _(L"Unspecified file descriptors") );
exit( 1 );
case 0:
{
break;
}
case 'r':
{
result_fd = get_fd( optarg );
break;
}
case 'c':
{
completion_fd = get_fd( optarg );
break;
}
case 'p':
{
prefix = str2wcs(optarg);
break;
}
case 'h':
{
print_help( argv[0], 1 );
exit(0);
}
case 'v':
{
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
exit( 0 );
}
case 'q':
{
is_quoted = 1;
}
}
}
if( completion_fd == -1 || result_fd == -1 )
{
debug( 0, _(L"Unspecified file descriptors") );
exit( 1 );
}
if( (completion_file = fdopen( completion_fd, "r" ) ) )
{
read_array( completion_file, comp );
fclose( completion_file );
}
else
{
debug( 0, _(L"Could not read completions") );
wperror( L"fdopen" );
exit( 1 );
}
if( !prefix )
{
prefix = wcsdup( L"" );
}
if( (completion_file = fdopen( completion_fd, "r" ) ) )
{
read_array( completion_file, comp );
fclose( completion_file );
}
else
{
/*
Second or first mode. These suck, but we need to support
them for backwards compatibility. At least for some
time.
*/
debug( 0, _(L"Could not read completions") );
wperror( L"fdopen" );
exit( 1 );
}
if( !prefix )
{
prefix = wcsdup( L"" );
}
if( argc < 3 )
{
print_help( argv[0], 1 );
exit( 0 );
}
else
{
mangle_descriptors = 1;
}
else
{
/*
Second or first mode. These suck, but we need to support
them for backwards compatibility. At least for some
time.
Third mode was implemented in January 2007, and previous
modes should be considered deprecated from that point
forward. A reasonable time frame for removal of the code
below has yet to be determined.
*/
if( argc < 3 )
{
print_help( argv[0], 1 );
exit( 0 );
}
else
{
mangle_descriptors = 1;
prefix = str2wcs( argv[2] );
is_quoted = strcmp( "1", argv[1] )==0;
@@ -1366,61 +1387,61 @@ int main( int argc, char **argv )
*/
read_array( stdin, comp );
}
}
}
}
// debug( 3, L"prefix is '%ls'", prefix );
init( mangle_descriptors, result_fd );
init( mangle_descriptors, result_fd );
mangle_descriptions( comp );
mangle_descriptions( comp );
if( wcscmp( prefix, L"-" ) == 0 )
join_completions( comp );
if( wcscmp( prefix, L"-" ) == 0 )
join_completions( comp );
mangle_completions( comp, prefix );
mangle_completions( comp, prefix );
/**
Try to print the completions. Start by trying to print the
list in PAGER_MAX_COLS columns, if the completions won't
fit, reduce the number of columns by one. Printing a single
column never fails.
*/
for( i = PAGER_MAX_COLS; i>0; i-- )
/**
Try to print the completions. Start by trying to print the
list in PAGER_MAX_COLS columns, if the completions won't
fit, reduce the number of columns by one. Printing a single
column never fails.
*/
for( i = PAGER_MAX_COLS; i>0; i-- )
{
switch( completion_try_print( i, prefix, is_quoted, comp ) )
{
switch( completion_try_print( i, prefix, is_quoted, comp ) )
{
case PAGER_RETRY:
break;
case PAGER_RETRY:
break;
case PAGER_DONE:
i=0;
break;
case PAGER_DONE:
i=0;
break;
case PAGER_RESIZE:
/*
This means we got a resize event, so we start
over from the beginning. Since it the screen got
bigger, we might be able to fit all completions
on-screen.
*/
i=PAGER_MAX_COLS+1;
break;
case PAGER_RESIZE:
/*
This means we got a resize event, so we start
over from the beginning. Since it the screen got
bigger, we might be able to fit all completions
on-screen.
*/
i=PAGER_MAX_COLS+1;
break;
}
}
}
}
free(prefix );
free(prefix );
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
if( is_ca_mode )
{
writembs(exit_ca_mode);
pager_flush();
}
destroy();
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
if( is_ca_mode )
{
writembs(exit_ca_mode);
pager_flush();
}
destroy();
halloc_util_destroy();