diff --git a/builtin.c b/builtin.c index 7b1dac54f..2dc81d8fc 100644 --- a/builtin.c +++ b/builtin.c @@ -1026,7 +1026,6 @@ typedef struct function_data wchar_t *name; wchar_t *description; int is_binding; - int do_save; array_list_t *events; } function_data_t; @@ -1043,7 +1042,6 @@ static int builtin_function( wchar_t **argv ) int res=0; wchar_t *desc=0; int is_binding=0; - int do_save=0; array_list_t *events; int i; @@ -1083,10 +1081,6 @@ static int builtin_function( wchar_t **argv ) L"help", no_argument, 0, 'h' } , - { - L"save", no_argument, 0, 'S' - } - , { 0, 0, 0, 0 } @@ -1099,7 +1093,7 @@ static int builtin_function( wchar_t **argv ) int opt = wgetopt_long( argc, argv, - L"bd:s:j:p:v:hS", + L"bd:s:j:p:v:h", long_options, &opt_index ); if( opt == -1 ) @@ -1253,11 +1247,6 @@ static int builtin_function( wchar_t **argv ) break; } - case 'S': - do_save = 1; - break; - - case 'h': builtin_print_help( argv[0], sb_out ); return 0; @@ -1344,7 +1333,6 @@ static int builtin_function( wchar_t **argv ) d->description=desc?halloc_wcsdup( current_block, desc):0; d->is_binding = is_binding; d->events = events; - d->do_save = do_save; for( i=0; itok_pos, - parser_get_job_pos()-current_block->tok_pos ); + wchar_t *def = wcsndup( parser_get_buffer()+current_block->tok_pos, + parser_get_job_pos()-current_block->tok_pos ); + function_add( d->name, def, @@ -2559,178 +2545,7 @@ static void builtin_end_add_function_def( function_data_t *d ) d->events, d->is_binding ); - if( d->do_save ) - { - wchar_t *func_path; - array_list_t func_path_list; - - func_path = env_get( L"fish_function_path" ); - - if( !func_path ) - { - sb_printf( sb_err, - _(L"%ls: Can't save the function '%ls' because the function path is undefined. Define the variable $fish_function_path to a suitable directory and retry"), - L"function", - d->name ); - - } - else - { - wchar_t *target_dir=0; - int i; - struct stat buf; - - al_init( &func_path_list ); - - tokenize_variable_array( func_path, &func_path_list ); - - for( i=0; i= 0; j-- ) - { - wchar_t *cre = (wchar_t *)al_get( subdirs, j); - if( wmkdir( cre, 0700 ) ) - { - create_err = 1; - break; - } - - } - - if( !create_err ) - target_dir = dir; - - - break; - } - else - { - break; - } - - } - else - { - if( errno != ENOENT ) - { - break; - } - } - - if( wcslen( dir_copy ) <= 1 ) - break; - - } - - if( target_dir ) - break; - } - - } - - - } - - //debug( 0, L"target directory is %ls", target_dir ); - - if( target_dir ) - { - int err=0; - string_buffer_t filename; - FILE *out; - wchar_t *efunc = L"unknown"; - - - sb_init( &filename ); - - sb_printf( &filename, - L"%ls/%ls.fish", - target_dir, - d->name ); - - if( (out = wfopen( (wchar_t *)filename.buff, "w" ))) - { - string_buffer_t *tmp = sb_halloc( context ); - functions_def( d->name, tmp ); - - fwprintf( out, L"%ls", (wchar_t *)tmp->buff ); - if( fclose( out ) ) - { - efunc = L"fclose"; - err = 1; - } - } - else - { - efunc = L"wfopen"; - err=1; - } - - sb_destroy( &filename ); - - if( err ) - { - sb_printf( sb_err, - _(L"%ls: Unexpected error while saving function %ls\n"), - L"function", - d->name ); - builtin_wperror( efunc ); - - } - - } - - - al_foreach( &func_path_list, &free ); - al_destroy( &func_path_list ); - } - - } - - halloc_free( context ); + free( def ); }