Minor code cleanup

darcs-hash:20061004214204-ac50b-e1529fcedb1665f9871a95eba293a4a3c1150464.gz
This commit is contained in:
axel 2006-10-05 07:42:04 +10:00
parent 91c745e4b5
commit 0ea668b260
7 changed files with 76 additions and 62 deletions

View file

@ -2268,9 +2268,20 @@ static int builtin_fg( wchar_t **argv )
since we want to know if this is an ambigous job
specification or if this is an malformed job id
*/
int pid = wcstol( argv[1], 0, 10 );
j = job_get_from_pid( pid );
if( j != 0 )
wchar_t *endptr;
int pid;
int found_job = 0;
errno = 0;
pid = wcstol( argv[1], &endptr, 10 );
if( !( *endptr || errno ) )
{
j = job_get_from_pid( pid );
if( j )
found_job = 1;
}
if( found_job )
{
sb_printf( sb_err,
_( L"%ls: Ambiguous job\n" ),
@ -2283,6 +2294,7 @@ static int builtin_fg( wchar_t **argv )
argv[0],
argv[1] );
}
builtin_print_help( argv[0], sb_err );
j=0;
@ -2291,9 +2303,11 @@ static int builtin_fg( wchar_t **argv )
else
{
wchar_t *end;
int pid = abs(wcstol( argv[1], &end, 10 ));
int pid;
errno = 0;
pid = abs(wcstol( argv[1], &end, 10 ));
if( *end )
if( *end || errno )
{
sb_printf( sb_err,
BUILTIN_ERR_NOT_NUMBER,

View file

@ -1288,40 +1288,44 @@ static void complete_cmd( const wchar_t *cmd,
else
{
path = env_get(L"PATH");
path_cpy = wcsdup( path );
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
if( path )
{
nxt_completion = wcsdupcat2( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
0 );
if( ! nxt_completion )
continue;
al_init( &tmp );
if( expand_string( 0,
nxt_completion,
&tmp,
ACCEPT_INCOMPLETE |
EXECUTABLES_ONLY ) != EXPAND_ERROR )
path_cpy = wcsdup( path );
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
for( i=0; i<al_get_count(&tmp); i++ )
nxt_completion = wcsdupcat2( nxt_path,
(nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
cmd,
0 );
if( ! nxt_completion )
continue;
al_init( &tmp );
if( expand_string( 0,
nxt_completion,
&tmp,
ACCEPT_INCOMPLETE |
EXECUTABLES_ONLY ) != EXPAND_ERROR )
{
al_push( comp, al_get( &tmp, i ) );
for( i=0; i<al_get_count(&tmp); i++ )
{
al_push( comp, al_get( &tmp, i ) );
}
}
al_destroy( &tmp );
}
al_destroy( &tmp );
free( path_cpy );
complete_cmd_desc( cmd, comp );
}
free( path_cpy );
complete_cmd_desc( cmd, comp );
/*
These return the original strings - don't free them
*/
@ -1335,7 +1339,6 @@ static void complete_cmd( const wchar_t *cmd,
copy_strings_with_prefix( comp, cmd, COMPLETE_BUILTIN_DESC, &builtin_get_desc, &possible_comp );
al_destroy( &possible_comp );
}
/*

View file

@ -1290,6 +1290,8 @@ g++, javac, java, gcj, lpr, doxygen, whois, find)
- Saving of the history in intervals to not loose to much on crashes
- Per process output redirection
- Reduce the space of the pager by one line to allow the commandline to remain visible.
- down-arrow could be used to save the current command to the history. Or give the next command in-sequnce. Or both.
- A pretty-printer.
\subsection bugs Known bugs
@ -1297,7 +1299,6 @@ g++, javac, java, gcj, lpr, doxygen, whois, find)
- Yanking weird characters from the clipboard prints Unicode escapes
- Suspending and then resuming pipelines containing a builtin is broken. How should this be handled?
- line wrapping issues on xterm
- The search token is invisible on long commandlines
- xdg stuff expects posix functionality, e.g. strdup
- Reading long history file takes way too much time

View file

@ -125,8 +125,6 @@ static void history_free_node( ll_node_t *n )
unused = n;
}
/**
Load history from file
*/
@ -422,9 +420,9 @@ static void history_destroy_mode( void *name, void *link )
last_loaded = d->last_loaded;
history_count = d->count;
past_end=1;
// fwprintf( stderr, L"Destroy history mode \'%ls\'\n", mode_name );
if( history_last )
{
history_save();
@ -455,7 +453,6 @@ void history_destroy()
&history_destroy_mode );
hash_destroy( &history_table );
}

View file

@ -1390,7 +1390,7 @@ static int interrupt_handler()
/*
Tell the reader an event occured
*/
if( reader_interupted() )
if( reader_interrupted() )
{
/*
Return 3, i.e. the character read by a Control-C.
@ -1654,7 +1654,7 @@ wint_t input_readch()
/*
Clear the interrupted flag
*/
reader_interupted();
reader_interrupted();
/*
Search for sequence in various mapping tables

View file

@ -287,7 +287,7 @@ static pid_t original_pid;
/**
This variable is set to true by the signal handler when ^C is pressed
*/
static int interupted=0;
static int interrupted=0;
/**
Original terminal mode when fish was started
@ -403,8 +403,8 @@ void reader_handle_int( int sig )
c->skip=1;
c=c->outer;
}
interupted = 1;
interrupted = 1;
}
wchar_t *reader_current_filename()
@ -504,11 +504,11 @@ static void remove_duplicates( array_list_t *l )
}
int reader_interupted()
int reader_interrupted()
{
int res=interupted;
int res=interrupted;
if( res )
interupted=0;
interrupted=0;
return res;
}
@ -574,10 +574,7 @@ static void calc_prompt()
*/
if( data->exec_prompt )
{
al_foreach( &prompt_list, &free );
al_truncate( &prompt_list, 0 );
if( data->prompt )
{
proc_push_interactive( 0 );
@ -591,17 +588,20 @@ static void calc_prompt()
}
proc_pop_interactive();
}
data->exec_prompt = 0;
reader_write_title();
sb_clear( &data->prompt_buff );
for( i=0; i<al_get_count( &prompt_list); i++ )
{
sb_append( &data->prompt_buff, (wchar_t *)al_get( &prompt_list, i ) );
}
al_foreach( &prompt_list, &free );
al_truncate( &prompt_list, 0 );
}
}
@ -1287,7 +1287,7 @@ static void reader_interactive_init()
/* Loop until we are in the foreground. */
while (tcgetpgrp( 0 ) != shell_pgid)
{
kill (- shell_pgid, SIGTTIN);
killpg( shell_pgid, SIGTTIN);
}
/* Put ourselves in our own process group. */
@ -1373,8 +1373,6 @@ void reader_replace_current_token( wchar_t *new_token )
if( !begin || !end )
return;
// fwprintf( stderr, L"%d %d, %d\n", begin-data->buff, end-data->buff, data->buff_len );
/*
Make new string
*/
@ -1915,7 +1913,7 @@ void reader_set_test_function( int (*f)( wchar_t * ) )
static void reader_super_highlight_me_plenty( int *color, int match_highlight_pos, array_list_t *error )
{
data->highlight_func( data->buff, color, match_highlight_pos, error );
if( wcslen(data->search_buff) )
if( data->search_buff && wcslen(data->search_buff) )
{
wchar_t * match = wcsstr( data->buff, data->search_buff );
if( match )
@ -2093,6 +2091,7 @@ wchar_t *reader_readline()
while( 1 )
{
c=input_readch();
if( ( (!wchar_private(c))) && (c>31) && (c != 127) )
{
if( can_read(0) )

View file

@ -95,10 +95,10 @@ void reader_set_buffer( wchar_t *b, int p );
int reader_get_cursor_pos();
/**
Return the value of the interupted flag, which is set by the sigint
Return the value of the interrupted flag, which is set by the sigint
handler, and clear it if it was set.
*/
int reader_interupted();
int reader_interrupted();
/**
Read one line of input. Before calling this function, reader_push()
@ -158,7 +158,7 @@ int exit_status();
void reader_replace_current_token( wchar_t *new_token );
/**
The readers interupt signal handler. Cancels all currently running blocks.
The readers interrupt signal handler. Cancels all currently running blocks.
*/
void reader_handle_int( int signal );