From 64f1024eb50486466e7c8347de90dc9d7bfda44f Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 22 Jan 2007 00:55:27 +1000 Subject: [PATCH] Make all error messages from options parsin in builtins redirectable darcs-hash:20070121145527-ac50b-1375af219a5eba6167e99d3fe24b26dba60eba2a.gz --- builtin.c | 45 +++++++++++++++++++++++++------------------ builtin_commandline.c | 2 +- builtin_complete.c | 5 +---- builtin_jobs.c | 3 +-- builtin_set.c | 2 +- builtin_ulimit.c | 2 +- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/builtin.c b/builtin.c index ece574a46..4fd0aa1fc 100644 --- a/builtin.c +++ b/builtin.c @@ -139,7 +139,6 @@ static hash_table_t *desc=0; /** Counts the number of non null pointers in the specified array */ - static int builtin_count_args( wchar_t **argv ) { int argc = 1; @@ -237,7 +236,7 @@ wchar_t *builtin_help_get( const wchar_t *name ) } -static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) +static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) { const wchar_t *h; @@ -342,6 +341,20 @@ static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) } } +/** + Perform error reporting for encounter with unknown option +*/ +static void builtin_unknown_option( const wchar_t *cmd, const wchar_t *opt ) +{ + sb_printf( sb_err, + BUILTIN_ERR_UNKNOWN, + cmd, + opt ); + sb_append( sb_err, + parser_current_line() ); + builtin_print_help( cmd, sb_err ); +} + /* 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 @@ -431,8 +444,7 @@ static int builtin_bind( wchar_t **argv ) return STATUS_BUILTIN_OK; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -533,8 +545,7 @@ static int builtin_block( wchar_t **argv ) break; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -666,8 +677,7 @@ static int builtin_builtin( wchar_t **argv ) break; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -752,8 +762,7 @@ static int builtin_generic( wchar_t **argv ) return STATUS_BUILTIN_OK; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -947,8 +956,7 @@ static int builtin_functions( wchar_t **argv ) break; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -1281,7 +1289,7 @@ static int builtin_function( wchar_t **argv ) return STATUS_BUILTIN_OK; case '?': - + builtin_unknown_option( argv[0], argv[woptind-1] ); res = 1; break; @@ -1434,8 +1442,7 @@ static int builtin_random( wchar_t **argv ) break; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -1619,8 +1626,7 @@ static int builtin_read( wchar_t **argv ) return STATUS_BUILTIN_OK; case L'?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -1925,8 +1931,7 @@ static int builtin_status( wchar_t **argv ) break; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; } @@ -3137,6 +3142,8 @@ void builtin_init() int i; + wopterr = 0; + al_init( &io_stack ); hash_init( &builtin, &hash_wcs_func, &hash_wcs_cmp ); diff --git a/builtin_commandline.c b/builtin_commandline.c index 7d29efc56..e10744857 100644 --- a/builtin_commandline.c +++ b/builtin_commandline.c @@ -381,7 +381,7 @@ static int builtin_commandline( wchar_t **argv ) return 0; case L'?': - builtin_print_help( argv[0], sb_err ); + builtin_unknown_option( argv[0], argv[woptind-1] ); return 1; } } diff --git a/builtin_complete.c b/builtin_complete.c index 1717e5dec..9fa4a1a4a 100644 --- a/builtin_complete.c +++ b/builtin_complete.c @@ -474,10 +474,7 @@ static int builtin_complete( wchar_t **argv ) return 0; case '?': - sb_append( sb_err, - parser_current_line() ); - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); res = 1; break; diff --git a/builtin_jobs.c b/builtin_jobs.c index 8b0791399..c4593400c 100644 --- a/builtin_jobs.c +++ b/builtin_jobs.c @@ -253,8 +253,7 @@ static int builtin_jobs( wchar_t **argv ) return 0; case '?': - builtin_print_help( argv[0], sb_err ); - + builtin_unknown_option( argv[0], argv[woptind-1] ); return 1; } diff --git a/builtin_set.c b/builtin_set.c index 084031ce6..e9e1e0600 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -539,7 +539,7 @@ static int builtin_set( wchar_t **argv ) return 0; case '?': - builtin_print_help( argv[0], sb_err ); + builtin_unknown_option( argv[0], argv[woptind-1] ); return 1; default: diff --git a/builtin_ulimit.c b/builtin_ulimit.c index 23ef08047..335484514 100644 --- a/builtin_ulimit.c +++ b/builtin_ulimit.c @@ -419,7 +419,7 @@ static int builtin_ulimit( wchar_t ** argv ) return 0; case L'?': - builtin_print_help( argv[0], sb_err ); + builtin_unknown_option( argv[0], argv[woptind-1] ); return 1; } }