diff --git a/function.c b/function.c index 7d174f367..260df8702 100644 --- a/function.c +++ b/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; idefinition_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 ); } diff --git a/parse_util.c b/parse_util.c index d58af7195..908f46da6 100644 --- a/parse_util.c +++ b/parse_util.c @@ -21,6 +21,51 @@ #include "tokenizer.h" #include "parse_util.h" +int parse_util_lineno( const wchar_t *str, int len ) +{ + static int res = 1; + static int i=0; + static const wchar_t *prev_str = 0; + + static const wchar_t *prev_str2 = 0; + static int i2 = 0; + static int res2 = 1; + + if( str != prev_str || i>len ) + { + if( prev_str2 == str && i2 <= len ) + { + const wchar_t *tmp_str = prev_str; + int tmp_i = i; + int tmp_res = res; + prev_str = prev_str2; + i=i2; + res=res2; + + prev_str2 = tmp_str; + i2 = tmp_i; + res2 = tmp_res; + } + else + { + prev_str2 = prev_str; + i2 = i; + res2=res; + + prev_str = str; + i=0; + res=1; + } + } + + for( ; icurrent_tokenizer_pos ) - { - prev_str = whole_str; - i=0; - lineno = 0; - } - - for( ; i