Minor edits, additional comments, etc.

darcs-hash:20060219015438-ac50b-b6346876460912f3c27d1bb4287aeab962260ab6.gz
This commit is contained in:
axel 2006-02-19 11:54:38 +10:00
parent c4e7a7992f
commit 845e15876c
8 changed files with 111 additions and 47 deletions

View file

@ -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 );

View file

@ -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

View file

@ -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 )

View file

@ -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 <wchar.h>
/**
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 );

View file

@ -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 ) );

View file

@ -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 )
{

View file

@ -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 );
}

View file

@ -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