From e280d100331842baeb7316b25daa237ea20fb63d Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 21 Jul 2006 11:08:31 +1000 Subject: [PATCH] Minor code edits. Use CHECK instead of a few error messages, add a few comments, etc. darcs-hash:20060721010831-ac50b-e9ad82a3885969f9a43e6219523e2bd1867e26ed.gz --- Makefile.in | 7 ++++--- expand.c | 42 +++++++++++++++++------------------------- fallback.c | 10 +++++++++- parser.c | 36 ++++++++++++++++++++++++++++++++---- wutil.c | 8 ++++---- 5 files changed, 66 insertions(+), 37 deletions(-) diff --git a/Makefile.in b/Makefile.in index 5a4c2c3bf..1f4c3aca2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -47,9 +47,10 @@ docdir = @docdir@ localedir = @localedir@ prefix = @prefix@ -CFLAGS:=@CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\" +MACROS=-DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\" +CFLAGS=@CFLAGS@ $(MACROS) CPPFLAGS=@CPPFLAGS@ -LDFLAGS:= @LIBS@ @LDFLAGS@ +LDFLAGS= @LIBS@ @LDFLAGS@ #etc files to install @@ -198,7 +199,7 @@ Makefile: Makefile.in configure ./config.status debug: - make fish CFLAGS="@CFLAGS@ -O0 -Wno-unused -Werror -g" + make fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g" .PHONY: debug # User documentation, describing the features of the fish shell. diff --git a/expand.c b/expand.c index 289e49009..8648dc54e 100644 --- a/expand.c +++ b/expand.c @@ -595,12 +595,9 @@ static int expand_pid( wchar_t *in, array_list_t *out ) { - if( !in || !out) - { - debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); - return 0; - } - + CHECK( in, 0 ); + CHECK( out, 0 ); + if( *in != PROCESS_EXPAND ) { al_push( out, in ); @@ -771,12 +768,9 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx ) static string_buffer_t *var_tmp = 0; static array_list_t *var_idx_list = 0; - if( !in || !out) - { - debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); - return 0; - } - + CHECK( in, 0 ); + CHECK( out, 0 ); + if( !var_tmp ) { var_tmp = sb_halloc( global_context ); @@ -1064,13 +1058,10 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out ) wchar_t *item_begin; int len1, len2, tot_len; - - if( !in || !out) - { - debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); - return 0; - } + CHECK( in, 0 ); + CHECK( out, 0 ); + for( pos=in; (*pos) && !syntax_error; pos++ ) @@ -1201,12 +1192,9 @@ static int expand_subshell( wchar_t *in, array_list_t *out ) int i, j; const wchar_t *item_begin; - if( !in || !out) - { - debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); - return 0; - } - + CHECK( in, 0 ); + CHECK( out, 0 ); + switch( parse_util_locate_cmdsubst(in, ¶n_begin, ¶n_end, @@ -1308,6 +1296,8 @@ static wchar_t *expand_unescape( const wchar_t * in, int escape_special ) static wchar_t * expand_tilde_internal( wchar_t *in ) { + CHECK( in, 0 ); + if( in[0] == HOME_DIRECTORY ) { int tilde_error = 0; @@ -1394,12 +1384,14 @@ wchar_t *expand_tilde( wchar_t *in) /** Remove any internal separators. Also optionally convert wildcard characters to - regular equivalents. This is done to support EXPAN_SKIP_WILDCARDS. + regular equivalents. This is done to support EXPAND_SKIP_WILDCARDS. */ static void remove_internal_separator( const void *s, int conv ) { wchar_t *in = (wchar_t *)s; wchar_t *out=in; + + CHECK( s, ); while( *in ) { diff --git a/fallback.c b/fallback.c index 32714224a..3167f4608 100644 --- a/fallback.c +++ b/fallback.c @@ -2,6 +2,10 @@ This file only contains fallback implementations of functions which have been found to be missing or broken by the configuration scripts. + + Many of these functions are more or less broken and + incomplete. lrand28_r internally uses the regular (bad) rand_r + function, the gettext function doesn't actually do anything, etc. */ #include "config.h" @@ -65,7 +69,11 @@ int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t)) #ifdef INTERNAL_FWPRINTF -void pad( void (*writer)(wchar_t), int count) +/** + Internal function for the wprintf fallbacks. USed to write the + specified number of spaces. +*/ +static void pad( void (*writer)(wchar_t), int count) { int i; diff --git a/parser.c b/parser.c index 403b2c9fa..36015ec78 100644 --- a/parser.c +++ b/parser.c @@ -1372,7 +1372,8 @@ wchar_t *parser_current_line() // lineno = current_tokenizer_pos; - current_line_width=printed_width(whole_str+current_line_start, current_tokenizer_pos-current_line_start ); + current_line_width=printed_width( whole_str+current_line_start, + current_tokenizer_pos-current_line_start ); if( (function_name = is_function()) ) { @@ -1696,8 +1697,9 @@ static void parse_job_main_loop( process_t *p, tok_last( tok ) ); } + break; } - break; + default: error( SYNTAX_ERROR, tok_get_pos( tok ), @@ -1738,6 +1740,7 @@ static void parse_job_main_loop( process_t *p, break; case TOK_REDIRECT_FD: + { if( wcscmp( target, L"-" ) == 0 ) { new_io->io_mode = IO_CLOSE; @@ -1760,6 +1763,8 @@ static void parse_job_main_loop( process_t *p, } } break; + } + } } @@ -1820,6 +1825,7 @@ static void parse_job_main_loop( process_t *p, } + /** Fully parse a single job. Does not call exec on it, but any command substitutions in the job will be executed. @@ -2065,7 +2071,7 @@ static int parse_job( process_t *p, */ continue; } - + if( use_function && !current_block->skip ) { int nxt_forbidden; @@ -2757,7 +2763,7 @@ static const wchar_t *parser_get_block_command( int type ) /** Test if this argument contains any errors. Detected errors include - syntax errors in command substitutions, imporoper escaped + syntax errors in command substitutions, improperly escaped characters and improper use of the variable expansion operator. */ static int parser_test_argument( const wchar_t *arg, string_buffer_t *out, const wchar_t *prefix, int offset ) @@ -2967,17 +2973,39 @@ int parser_test( const wchar_t * buff, int previous_pos=current_tokenizer_pos; static int block_pos[BLOCK_MAX_COUNT]; static int block_type[BLOCK_MAX_COUNT]; + + /* + Set to 1 if the current command is inside a pipeline + */ int is_pipeline = 0; + /* Set to one if the currently specified process can not be used inside a pipeline */ int forbid_pipeline = 0; + /* Set to one if an additional process specification is needed */ int needs_cmd=0; + + /* + halloc context used for calls to expand() and other memory + allocations. Free'd at end of this function. + */ void *context; + + /* + Counter on the number of arguments this function has encountered + so far. Is set to -1 when the count is unknown, i.e. after + encountering an argument that contains substitutions that can + expand to more/less arguemtns then 1. + */ int arg_count=0; + + /* + The currently validated command. + */ wchar_t *cmd=0; CHECK( buff, 1 ); diff --git a/wutil.c b/wutil.c index 44ad5f59d..6dfeb21ad 100644 --- a/wutil.c +++ b/wutil.c @@ -378,9 +378,9 @@ wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path) wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path) { - char *tmp =wutil_wcs2str(pathname); - char narrow[PATH_MAX]; - char *narrow_res = realpath( tmp, narrow ); + char *tmp = wutil_wcs2str(pathname); + char narrow_buff[PATH_MAX]; + char *narrow_res = realpath( tmp, narrow_buff ); wchar_t *res; if( !narrow_res ) @@ -466,7 +466,7 @@ static void wgettext_init() wgettext_is_init = 1; - for(i=0; i