From b2d4e85f172fecfba0a0fcd136f6d8178ff9b90c Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 20 Oct 2006 01:47:47 +1000 Subject: [PATCH] Make any character except '/' legal in function names darcs-hash:20061019154747-ac50b-f3ab0df1085b91ec0eadcceddb23f03d5b0247aa.gz --- builtin.c | 2 +- common.c | 6 ++++++ common.h | 8 ++++++++ doc_src/function.txt | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin.c b/builtin.c index 23feee579..7b1dac54f 100644 --- a/builtin.c +++ b/builtin.c @@ -1281,7 +1281,7 @@ static int builtin_function( wchar_t **argv ) argc-woptind ); res=1; } - else if( !(is_binding?wcsbindingname( argv[woptind] ) : !wcsvarname( argv[woptind] ) )) + else if( wcsfuncname( argv[woptind] ) ) { sb_printf( sb_err, _( L"%ls: Illegal function name '%ls'\n" ), diff --git a/common.c b/common.c index ca05b3698..65f73af0c 100644 --- a/common.c +++ b/common.c @@ -421,6 +421,12 @@ wchar_t *wcsvarname( const wchar_t *str ) return 0; } +wchar_t *wcsfuncname( const wchar_t *str ) +{ + return wcschr( str, L'/' ); +} + + int wcsvarchr( wchar_t chr ) { return ( (iswalnum(chr)) || (chr == L'_' )); diff --git a/common.h b/common.h index 5aa6c2769..f6cfcc0ac 100644 --- a/common.h +++ b/common.h @@ -210,6 +210,14 @@ __sentinel wchar_t *wcsdupcat2( const wchar_t *a, ... ); wchar_t *wcsvarname( const wchar_t *str ); +/** + Test if the given string is a valid function name. + + \return null if this is a valid name, and a pointer to the first invalid character otherwise +*/ + +wchar_t *wcsfuncname( const wchar_t *str ); + /** Test if the given string is valid in a variable name diff --git a/doc_src/function.txt b/doc_src/function.txt index 37ed23fc1..75bf9e889 100644 --- a/doc_src/function.txt +++ b/doc_src/function.txt @@ -5,7 +5,7 @@ \subsection function-description Description -- \c -b or \c --key-binding specifies that the function is a key biding. Key binding functions work exactly like regular functions except that they can not be tab-completed, and may contain the '-' character. +- \c -b or \c --key-binding specifies that the function is a key biding. Key binding functions work exactly like regular functions except that they can not be tab-completed. - -d DESCRIPTION or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description - -j PID or --on-job-exit PID tells fish to run this function when the job with group id PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution. - -p PID or --on-process-exit PID tells fish to run this function when the fish child process with process id PID exits