Various code polish, including minor rearangement of builtin code to export fewer functions, a few additional input checks, and removal of the unneeded, exported error_max variable

darcs-hash:20060620212016-ac50b-f76c10eea23fab14a648ea83ed0c83a171b8fef9.gz
This commit is contained in:
axel 2006-06-21 07:20:16 +10:00
parent 51c6c5ea49
commit 7268a4a4e0
7 changed files with 70 additions and 73 deletions

View File

@ -66,12 +66,7 @@
#include "parse_util.h"
#include "expand.h"
#include "builtin_help.c"
#include "builtin_set.c"
#include "builtin_commandline.c"
#include "builtin_complete.c"
#include "builtin_ulimit.c"
#include "builtin_jobs.c"
/**
The default prompt for the read command
@ -139,7 +134,11 @@ static int builtin_stdin;
*/
static hash_table_t *desc=0;
int builtin_count_args( wchar_t **argv )
/**
Counts the number of non null pointers in the specified array
*/
static int builtin_count_args( wchar_t **argv )
{
int argc = 1;
while( argv[argc] != 0 )
@ -149,8 +148,13 @@ int builtin_count_args( wchar_t **argv )
return argc;
}
/**
This function works like wperror, but it prints its result into
the sb_err string_buffer_t instead of to stderr. Used by the builtin
commands.
*/
void builtin_wperror( const wchar_t *s)
static void builtin_wperror( const wchar_t *s)
{
if( s != 0 )
{
@ -178,26 +182,18 @@ static int count_char( const wchar_t *str, wchar_t c )
return res;
}
/*
Here follows the definition of all builtin commands. The function
names are all on the form builtin_NAME where NAME is the name of the
builtin. so the function name for the builtin 'fg' is
'builtin_fg'.
/**
Print help for the specified builtin. If \c b is sb_err, also print
the line information
A few builtins, including 'while', 'command' and 'builtin' are not
defined here as they are handled directly by the parser. (They are
not parsed as commands, instead they only alter the parser state)
The builtins 'break' and 'continue' are so closely related that they
share the same implementation, namely 'builtin_break_continue.
Several other builtins, including jobs, ulimit and set are so big
that they have been given their own file. These files are all named
'builtin_NAME.c', where NAME is the name of the builtin.
If \c b is the buffer representing standard error, and the help
message is about to be printed to an interactive screen, it may be
shortened to fit the screen.
*/
void builtin_print_help( wchar_t *cmd, string_buffer_t *b )
static void builtin_print_help( wchar_t *cmd, string_buffer_t *b )
{
const char *h;
@ -260,6 +256,35 @@ void builtin_print_help( wchar_t *cmd, string_buffer_t *b )
free( str );
}
}
/*
Here follows the definition of all builtin commands. The function
names are all on the form builtin_NAME where NAME is the name of the
builtin. so the function name for the builtin 'fg' is
'builtin_fg'.
A few builtins, including 'while', 'command' and 'builtin' are not
defined here as they are handled directly by the parser. (They are
not parsed as commands, instead they only alter the parser state)
The builtins 'break' and 'continue' are so closely related that they
share the same implementation, namely 'builtin_break_continue.
Several other builtins, including jobs, ulimit and set are so big
that they have been given their own file. These files are all named
'builtin_NAME.c', where NAME is the name of the builtin.
*/
#include "builtin_help.c"
#include "builtin_set.c"
#include "builtin_commandline.c"
#include "builtin_complete.c"
#include "builtin_ulimit.c"
#include "builtin_jobs.c"
/**
The bind builtin, used for setting character sequences
*/

View File

@ -136,22 +136,6 @@ void builtin_pop_io();
*/
const wchar_t *builtin_get_desc( const wchar_t *b );
/**
Counts the number of non null pointers in the specified array
*/
int builtin_count_args( wchar_t **argv );
/**
Print help for the specified builtin. If \c b is sb_err, also print
the line information
If \c b is the buffer representing standard error, and the help
message is about to be printed to an interactive screen, it may be
shortened to fit the screen.
*/
void builtin_print_help( wchar_t *cmd, string_buffer_t *b );
/**
Slightly kludgy function used with 'complete -C' in order to make
@ -160,12 +144,6 @@ void builtin_print_help( wchar_t *cmd, string_buffer_t *b );
*/
const wchar_t *builtin_complete_get_temporary_buffer();
/**
This function works like wperror, but it prints its result into
the sb_err string_buffer_t instead of to stderr. Used by the builtin
commands.
*/
void builtin_wperror( const wchar_t *s);
/**
Return the help text for the specified builtin command. Use

View File

@ -179,7 +179,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
\param indexes the list to insert the new indexes into
\param src the source string to parse
\param name the name of the element. Return null if the name in \c src does not match this name
\param the number of elements in the array to parse.
\param var_count the number of elements in the array to parse.
\return the total number of indexes parsed, or -1 on error
*/

View File

@ -74,8 +74,6 @@ parts of fish.
struct termios shell_modes;
int error_max=1;
wchar_t ellipsis_char;
char *profile=0;

View File

@ -51,11 +51,6 @@ extern struct termios shell_modes;
*/
extern wchar_t ellipsis_char;
/**
The maximum number of charset convertion errors to report
*/
extern int error_max;
/**
The verbosity of fish
*/

View File

@ -1776,12 +1776,12 @@ static void complete_param_expand( wchar_t *str,
{
comp_str = str;
}
/*
debug( 3,
L"expand_string( \"%ls\", comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls );",
comp_str,
do_file?L"0":L"EXPAND_SKIP_WILDCARDS" );
*/
expand_string( 0,
wcsdup(comp_str),
comp_out,
@ -1974,7 +1974,6 @@ void complete( const wchar_t *cmd,
int on_command=0;
int pos;
int old_error_max = error_max;
int done=0;
int cursor_pos = wcslen(cmd );
@ -1985,8 +1984,6 @@ void complete( const wchar_t *cmd,
return;
}
error_max=0;
/**
If we are completing a variable name or a tilde expansion user
name, we do that and return. No need for any other competions.
@ -2135,7 +2132,6 @@ void complete( const wchar_t *cmd,
free( current_command );
free( prev_token );
error_max=old_error_max;
condition_cache_clear();
}

View File

@ -70,6 +70,12 @@ static void al_push_check( array_list_t *l, const wchar_t *new )
int wildcard_has( const wchar_t *str, int internal )
{
wchar_t prev=0;
if( !str )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return 0;
}
if( internal )
{
for( ; *str; str++ )
@ -162,19 +168,7 @@ static int wildcard_complete_internal( const wchar_t *orig,
const wchar_t *(*desc_func)(const wchar_t *),
array_list_t *out )
{
if( !wc )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return 0;
}
if( !str )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return 0;
}
if( !orig )
if( !wc || !str || !orig)
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return 0;
@ -318,6 +312,11 @@ static void get_desc( wchar_t *fn, string_buffer_t *sb, int is_cmd )
}
;
if( !fn || !sb )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return;
}
sb_clear( sb );
@ -437,6 +436,12 @@ int wildcard_expand( const wchar_t *wc,
// debug( 3, L"WILDCARD_EXPAND %ls in %ls", wc, base_dir );
if( !wc || !base_dir || !out)
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
return 0;
}
if( flags & ACCEPT_INCOMPLETE )
{
/*