Fix minor bugs in parser

darcs-hash:20050924193117-ac50b-eb8ecfe4fec3bca6f89356a9079977802eb4a2c8.gz
This commit is contained in:
axel 2005-09-25 05:31:17 +10:00
parent 62f3b442da
commit f643a4e200
6 changed files with 49 additions and 16 deletions

View file

@ -2,6 +2,13 @@
* reader.c (reader_readline): Quit token search on escape * reader.c (reader_readline): Quit token search on escape
* parser.c (pares_job_main_loop): Make command substitutions for the case command expand properly
* parser.c (pares_job_main_loop): Fix memory leak on parse error in pipeline
* common.h, common.c: Make DEBUG_LEVEL constant into debug_level runtime configurable variable
2005-09-23 Axel Liljencrantz <axel@liljencrantz.se> 2005-09-23 Axel Liljencrantz <axel@liljencrantz.se>
* reader.c (set_signal_handlers): Ignore SIG_PIPE, generated by fishd socket * reader.c (set_signal_handlers): Ignore SIG_PIPE, generated by fishd socket

View file

@ -71,6 +71,9 @@ char *profile=0;
wchar_t *program_name; wchar_t *program_name;
int debug_level=1;
static int block_count=0; static int block_count=0;
void common_destroy() void common_destroy()
@ -761,7 +764,7 @@ void debug( int level, wchar_t *msg, ... )
{ {
va_list va; va_list va;
if( level > DEBUG_LEVEL ) if( level > debug_level )
return; return;
va_start( va, msg ); va_start( va, msg );

View file

@ -18,11 +18,6 @@ typedef char tputs_arg_t;
*/ */
#define MAX_UTF8_BYTES 6 #define MAX_UTF8_BYTES 6
/**
Amount of debug info to show. Higher level means more debug info will be displayed
*/
#define DEBUG_LEVEL 1
/** /**
Color code for set_color. Does not update the color. Color code for set_color. Does not update the color.
*/ */
@ -47,6 +42,11 @@ extern wchar_t ellipsis_char;
*/ */
extern int error_max; extern int error_max;
/**
The verbosity of fish
*/
extern int debug_level;
/** /**
Profiling flag. True if commands should be profiled. Profiling flag. True if commands should be profiled.
*/ */

View file

@ -152,7 +152,14 @@ void parser_push_block( int type )
new->outer = current_block; new->outer = current_block;
new->type = (current_block && current_block->skip)?FAKE:type; new->type = (current_block && current_block->skip)?FAKE:type;
/*
New blocks should be skipped if the outer block is skipped,
except TOP ans SUBST block, which open up new environments
*/
new->skip=current_block?current_block->skip:0; new->skip=current_block?current_block->skip:0;
if( type == TOP || type == SUBST )
new->skip = 0;
new->loop_status=LOOP_NORMAL; new->loop_status=LOOP_NORMAL;
@ -910,23 +917,20 @@ static void parse_job_main_loop( process_t *p,
tok_get_pos( tok ) ); tok_get_pos( tok ) );
return; return;
} }
p->argv = list_to_char_arr( args ); p->argv = list_to_char_arr( args );
p->next = calloc( 1, sizeof( process_t ) ); p->next = calloc( 1, sizeof( process_t ) );
if( p->next == 0 ) if( p->next == 0 )
{ {
die_mem(); die_mem();
} }
tok_next( tok ); tok_next( tok );
if( !parse_job( p->next, j, tok )) if( !parse_job( p->next, j, tok ))
{ {
/* /*
Do not free args content on error - it is Don't do anything on failiure. parse_job will notice the error flag beeing set
already in p->argv and will be freed by job_free
later on.
*/ */
al_truncate( args, 0 );
} }
is_finished = 1; is_finished = 1;
break; break;
@ -950,14 +954,21 @@ static void parse_job_main_loop( process_t *p,
if( current_block->skip ) if( current_block->skip )
{ {
/*
If this command should be skipped, we do not expand the arguments
*/
skip=1; skip=1;
/*
But if this is in fact a case statement, then it should be evaluated
*/
if( (current_block->type == SWITCH) && if( (current_block->type == SWITCH) &&
(wcscmp( al_get( args, 0), L"case" )==0) && (wcscmp( al_get( args, 0), L"case" )==0) &&
p->type ) p->type == INTERNAL_BUILTIN )
{ {
skip=0; skip=0;
} }
} }
if( !skip ) if( !skip )
@ -972,7 +983,7 @@ static void parse_job_main_loop( process_t *p,
p->type = INTERNAL_BUILTIN; p->type = INTERNAL_BUILTIN;
wcscpy( p->actual_cmd, L"count" ); wcscpy( p->actual_cmd, L"count" );
} }
if( !expand_string( wcsdup(tok_last( tok )), if( !expand_string( wcsdup(tok_last( tok )),
args, args,
0 ) 0 )
@ -986,7 +997,6 @@ static void parse_job_main_loop( process_t *p,
tok_last(tok), tok_last(tok),
tok_get_pos( tok ) ); tok_get_pos( tok ) );
} }
} }
} }
@ -1731,6 +1741,9 @@ static void eval_job( tokenizer *tok )
} }
else else
{ {
/*
This job could not be properly parsed. We free it instead.
*/
job_free( j ); job_free( j );
} }
break; break;

7
proc.c
View file

@ -154,12 +154,19 @@ static void free_process( process_t *p )
if( p==0 ) if( p==0 )
return; return;
free_process( p->next ); free_process( p->next );
debug( 3, L"Free process %ls", p->actual_cmd );
free( p->actual_cmd ); free( p->actual_cmd );
if( p->argv != 0 ) if( p->argv != 0 )
{ {
debug( 3, L"Process has argument vector" );
for( arg=p->argv; *arg; arg++ ) for( arg=p->argv; *arg; arg++ )
{
debug( 3, L"Free argument %ls", *arg );
free( *arg ); free( *arg );
}
free(p->argv ); free(p->argv );
} }
free( p ); free( p );

View file

@ -1262,6 +1262,9 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp )
exec_read_io_buffer( out ); exec_read_io_buffer( out );
sb_destroy( &cmd );
int nil=0; int nil=0;
b_append( out->out_buffer, &nil, 1 ); b_append( out->out_buffer, &nil, 1 );