diff --git a/halloc.h b/halloc.h index 33d3dc16e..584ed84cd 100644 --- a/halloc.h +++ b/halloc.h @@ -19,7 +19,7 @@ If \c context is not null, context must be a halloc root block. the resulting memory block is a child context, and must never be explicitly freed, it will be automatically freed whenever the - parent context is freed. Child blocks can never be used as the + parent context is freed. Child blocks can also never be used as the context in calls to halloc_register_function, halloc_free, etc. */ void *halloc( void *context, size_t size ); diff --git a/halloc_util.h b/halloc_util.h index 8ff911bfe..ea7858371 100644 --- a/halloc_util.h +++ b/halloc_util.h @@ -7,29 +7,60 @@ #ifndef FISH_HALLOC_UTIL_H #define FISH_HALLOC_UTIL_H +/** + This pointer is a valid halloc context that will be freed right + before program shutdown. It may be used to allocate memory that + should be freed when the program shuts down. +*/ extern void *global_context; +/** + Create the global_context halloc object +*/ void halloc_util_init(); +/** + Free the global_context halloc object +*/ void halloc_util_destroy(); - +/** + Allocate a array_list_t that will be automatically disposed of when + the specified context is free'd +*/ array_list_t *al_halloc( void *context ); +/** + Allocate a string_buffer_t that will be automatically disposed of + when the specified context is free'd +*/ string_buffer_t *sb_halloc( void *context ); +/** + Register the specified function to run when the specified context + is free'd. This function is related to halloc_register_function, + but the specified function dowes not take an argument. +*/ void halloc_register_function_void( void *context, void (*func)() ); + /** Free the memory pointed to by \c data when the memory pointed to by \c context is free:d. Note that this will _not_ turn the specified memory area into a valid halloc context. Only memory areas created - using a call to halloc() can be used as a context. + using a call to halloc( 0, size ) can be used as a context. */ void *halloc_register( void *context, void *data ); +/** + Make a copy of the specified string using memory allocated using + halloc and the specified context +*/ wchar_t *halloc_wcsdup( void *context, wchar_t *str ); + +/** + Make a copy of the specified substring using memory allocated using + halloc and the specified context +*/ wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c ); - - #endif diff --git a/parse_util.c b/parse_util.c index 0f810b4f5..26c641a61 100644 --- a/parse_util.c +++ b/parse_util.c @@ -1,6 +1,7 @@ /** \file parse_util.c - Various utility functions for parsing a command + Various mostly unrelated utility functions related to parsing, + loading and evaluating fish code. */ #include "config.h" @@ -438,6 +439,9 @@ static void clear_hash_value( const void *key, const void *data ) free( (void *)data ); } +/** + Part of the autoloader cleanup +*/ static void clear_loaded_entry( const void *key, const void *data ) { hash_table_t *loaded = (hash_table_t *)data; @@ -448,6 +452,11 @@ static void clear_loaded_entry( const void *key, const void *data ) free( (void *)key ); } +/** + The autoloader cleanup function. It is run on shutdown and frees + any memory used by the autoloader code to keep track of loaded + files. +*/ static void parse_util_destroy() { if( all_loaded ) diff --git a/parse_util.h b/parse_util.h index c29f93d37..0dcd0edb4 100644 --- a/parse_util.h +++ b/parse_util.h @@ -1,6 +1,7 @@ /** \file parse_util.h - Various utility functions for parsing a command + Various mostly unrelated utility functions related to parsing, + loading and evaluating fish code. */ #ifndef FISH_PARSE_UTIL_H @@ -8,9 +9,8 @@ #include - /** - Locate the first subshell in the specified string. + Find the beginning and end of the first subshell in the specified string. \param in the string to search for subshells \param begin the starting paranthesis of the subshell @@ -26,6 +26,11 @@ int parse_util_locate_cmdsubst( const wchar_t *in, /** Find the beginning and end of the command substitution under the cursor + + \param buff the string to search for subshells + \param cursor_pos the position of the cursor + \param a the start of the searched string + \param b the end of the searched string */ void parse_util_cmdsubst_extent( const wchar_t *buff, int cursor_pos, @@ -34,23 +39,38 @@ void parse_util_cmdsubst_extent( const wchar_t *buff, /** Find the beginning and end of the process definition under the cursor + + \param buff the string to search for subshells + \param cursor_pos the position of the cursor + \param a the start of the searched string + \param b the end of the searched string */ void parse_util_process_extent( const wchar_t *buff, - int pos, + int cursor_pos, const wchar_t **a, const wchar_t **b ); /** Find the beginning and end of the job definition under the cursor + + \param buff the string to search for subshells + \param cursor_pos the position of the cursor + \param a the start of the searched string + \param b the end of the searched string */ void parse_util_job_extent( const wchar_t *buff, - int pos, + int cursor_pos, const wchar_t **a, const wchar_t **b ); /** Find the beginning and end of the token under the cursor + + \param buff the string to search for subshells + \param cursor_pos the position of the cursor + \param a the start of the searched string + \param b the end of the searched string */ void parse_util_token_extent( const wchar_t *buff, int cursor_pos, @@ -79,16 +99,20 @@ int parse_util_load( const wchar_t *cmd, void (*on_load)(const wchar_t *cmd), int reload ); +/** + Reset the loader for the specified path value +*/ void parse_util_load_reset( const wchar_t *path_var ); /** Set the argv environment variable to the specified null-terminated - array of strings + array of strings. */ void parse_util_set_argv( wchar_t **argv ); /** - Make duplicate string, unescape wildcard characters but n ot performing any other character transformation + Make a duplicate of the specified string, unescape wildcard + characters but not performing any other character transformation. */ wchar_t *parse_util_unescape_wildcards( const wchar_t *in ); diff --git a/parser.c b/parser.c index 137a25f5f..b77b79f13 100644 --- a/parser.c +++ b/parser.c @@ -1311,11 +1311,10 @@ static void parse_job_main_loop( process_t *p, while( 1 ) { - /* debug( 2, L"Read token %ls\n", wcsdup(tok_last( tok )) ); */ - switch( tok_last_type( tok ) ) { case TOK_PIPE: + { if( (p->type == INTERNAL_EXEC) ) { error( SYNTAX_ERROR, @@ -1332,19 +1331,20 @@ static void parse_job_main_loop( process_t *p, } tok_next( tok ); - if( !parse_job( p->next, j, tok )) - { - /* - Don't do anything on failiure. parse_job will notice the error flag beeing set - */ + /* + Don't do anything on failiure. parse_job will notice the error flag beeing set + */ + parse_job( p->next, j, tok ); - } is_finished = 1; break; - + } + case TOK_BACKGROUND: + { j->fg = 0; - + } + case TOK_END: { halloc_register( j, p->argv=list_to_char_arr( args ) ); diff --git a/tokenizer.c b/tokenizer.c index ff04f4704..ee9f7eb22 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -403,7 +403,7 @@ static void read_comment( tokenizer *tok ) } /** - Read a FD redirect. + Read a FD redirection. */ static void read_redirect( tokenizer *tok, int fd ) { diff --git a/wildcard.c b/wildcard.c index b51fa61bb..788cacbb6 100644 --- a/wildcard.c +++ b/wildcard.c @@ -41,6 +41,29 @@ wildcards using **. */ #define MAX_FILE_LENGTH 1024 +/** + Push the specified argument to the list if an identical string is + not already in the list. This function iterates over the list, + which is quite slow if the list is large. It might make sense to + use a hashtable for this. +*/ +static void al_push_check( array_list_t *l, const wchar_t *new ) +{ + int i; + + for( i = 0; i < al_get_count(l); i++ ) + { + if( !wcscmp( al_get(l, i), new ) ) + { + free( (void *)new ); + return; + } + } + + al_push( l, new ); +} + + int wildcard_has( const wchar_t *str, int internal ) { wchar_t prev=0; @@ -73,8 +96,6 @@ int wildcard_has( const wchar_t *str, int internal ) \param wc The wildcard. \param is_first Whether files beginning with dots should not be matched against wildcards. */ - - static int wildcard_match2( const wchar_t *str, const wchar_t *wc, int is_first ) @@ -670,18 +691,3 @@ int wildcard_expand( const wchar_t *wc, return res; } -void al_push_check( array_list_t *l, const wchar_t *new ) -{ - int i; - - for( i = 0; i < al_get_count(l); i++ ) - { - if( !wcscmp( al_get(l, i), new ) ) - { - free( (void *)new ); - return; - } - } - - al_push( l, new ); -} diff --git a/wildcard.h b/wildcard.h index 4c3ef7a12..85677b25a 100644 --- a/wildcard.h +++ b/wildcard.h @@ -92,10 +92,4 @@ int wildcard_complete( const wchar_t *str, const wchar_t *(*desc_func)(const wchar_t *), array_list_t *out ); -/** - Push string if not already in list -*/ -void al_push_check( array_list_t *l, const wchar_t *str ); - - #endif