From da6295c428271e34a9e03ce7858e12a2892dff44 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 17 May 2012 19:46:08 -0700 Subject: [PATCH] More work towards getting function.h off of shared_ptr --- builtin.cpp | 12 +++++------- complete.cpp | 8 ++------ function.cpp | 9 +++++---- function.h | 7 +++++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index fa187a17f..d26cefb0a 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1085,8 +1085,8 @@ static int builtin_generic( parser_t &parser, wchar_t **argv ) */ static void functions_def( const wcstring &name, wcstring &out ) { - const wchar_t *desc = function_get_desc( name ); - wcstring def; + wcstring desc, def; + function_get_desc(name, &desc); function_get_definition(name, &def); event_t search(EVENT_ANY); @@ -1099,13 +1099,11 @@ static void functions_def( const wcstring &name, wcstring &out ) out.append(L"function "); out.append(name); - if( desc && wcslen(desc) ) + if (! desc.empty()) { - wchar_t *esc_desc = escape( desc, 1 ); - + wcstring esc_desc = escape_string(desc, true); out.append(L" --description "); - out.append( esc_desc ); - free( esc_desc ); + out.append(esc_desc); } if( !function_get_shadows( name ) ) diff --git a/complete.cpp b/complete.cpp index 35e0a5ebf..e4602adb0 100644 --- a/complete.cpp +++ b/complete.cpp @@ -986,14 +986,10 @@ void completer_t::complete_cmd_desc( const wcstring &str ) static wcstring complete_function_desc( const wcstring &fn ) { wcstring result; - - const wchar_t *res = function_get_desc( fn ); - if (res) { - result = res; - } else { + bool has_description = function_get_desc(fn, &result); + if (! has_description) { function_get_definition(fn, &result); } - return result; } diff --git a/function.cpp b/function.cpp index 166d30a55..ff165545b 100644 --- a/function.cpp +++ b/function.cpp @@ -273,14 +273,15 @@ int function_get_shadows( const wcstring &name ) } -const wchar_t *function_get_desc( const wcstring &name ) +bool function_get_desc( const wcstring &name, wcstring *out_desc ) { /* Empty length string goes to NULL */ shared_ptr func = function_get(name); - if (func && func->description.size()) { - return _(func->description.c_str()); + if (out_desc && func && ! func->description.empty()) { + out_desc->assign(_(func->description.c_str())); + return true; } else { - return NULL; + return false; } } diff --git a/function.h b/function.h index 01f5653bc..2ca50255b 100644 --- a/function.h +++ b/function.h @@ -109,9 +109,10 @@ void function_remove( const wcstring &name ); bool function_get_definition( const wcstring &name, wcstring *out_definition ); /** - Returns the description of the function with the name \c name. + Returns by reference the description of the function with the name \c name. + Returns true if the function exists and has a nonempty description, false if it does not. */ -const wchar_t *function_get_desc( const wcstring &name ); +bool function_get_desc( const wcstring &name, wcstring *out_desc ); /** Sets the description of the function with the name \c name. @@ -141,6 +142,8 @@ wcstring_list_t function_get_names( int get_hidden ); This function does not autoload functions, it will only work on functions that have already been defined. + + This returns an intern'd string. */ const wchar_t *function_get_definition_file( const wcstring &name );