mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 19:31:14 -03:00
Remove duplicate line counting code. Make the remaining implementation have a two element cache.
darcs-hash:20060205131035-ac50b-885c6ba87a6d16aa48dfa7ee4608ae8891c71724.gz
This commit is contained in:
32
function.c
32
function.c
@@ -18,6 +18,7 @@
|
||||
#include "intern.h"
|
||||
#include "event.h"
|
||||
#include "reader.h"
|
||||
#include "parse_util.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,18 +66,6 @@ void function_destroy()
|
||||
hash_destroy( &function );
|
||||
}
|
||||
|
||||
static int count_lineno( const wchar_t *str, int len )
|
||||
{
|
||||
int res = 0;
|
||||
int i;
|
||||
for( i=0; i<len; i++ )
|
||||
{
|
||||
if( str[i] == L'\n' )
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void function_add( const wchar_t *name,
|
||||
const wchar_t *val,
|
||||
@@ -88,13 +77,12 @@ void function_add( const wchar_t *name,
|
||||
wchar_t *cmd_end;
|
||||
function_data_t *d;
|
||||
|
||||
if( function_exists( name ) )
|
||||
function_remove( name );
|
||||
function_remove( name );
|
||||
|
||||
d = malloc( sizeof( function_data_t ) );
|
||||
d->definition_offset = count_lineno( parser_get_buffer(), current_block->tok_pos );
|
||||
d->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos );
|
||||
d->cmd = wcsdup( val );
|
||||
|
||||
|
||||
cmd_end = d->cmd + wcslen(d->cmd)-1;
|
||||
while( (cmd_end>d->cmd) && wcschr( L"\n\r\t ", *cmd_end ) )
|
||||
{
|
||||
@@ -103,7 +91,7 @@ void function_add( const wchar_t *name,
|
||||
|
||||
d->desc = desc?wcsdup( desc ):0;
|
||||
d->is_binding = is_binding;
|
||||
d->definition_file = reader_current_filename()?intern(reader_current_filename()):0;
|
||||
d->definition_file = intern(reader_current_filename());
|
||||
|
||||
hash_put( &function, intern(name), d );
|
||||
|
||||
@@ -125,18 +113,18 @@ void function_remove( const wchar_t *name )
|
||||
function_data_t *d;
|
||||
event_t ev;
|
||||
|
||||
ev.type=EVENT_ANY;
|
||||
ev.function_name=name;
|
||||
event_remove( &ev );
|
||||
|
||||
hash_remove( &function,
|
||||
name,
|
||||
(const void **) &key,
|
||||
(const void **)&d );
|
||||
|
||||
if( !d )
|
||||
if( !key )
|
||||
return;
|
||||
|
||||
ev.type=EVENT_ANY;
|
||||
ev.function_name=name;
|
||||
event_remove( &ev );
|
||||
|
||||
clear_function_entry( key, d );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user