mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 02:22:47 +08:00
Minor edits, additional comments, etc.
darcs-hash:20060219015438-ac50b-b6346876460912f3c27d1bb4287aeab962260ab6.gz
This commit is contained in:
parent
c4e7a7992f
commit
845e15876c
2
halloc.h
2
halloc.h
|
@ -19,7 +19,7 @@
|
||||||
If \c context is not null, context must be a halloc root block. the
|
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
|
resulting memory block is a child context, and must never be
|
||||||
explicitly freed, it will be automatically freed whenever the
|
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.
|
context in calls to halloc_register_function, halloc_free, etc.
|
||||||
*/
|
*/
|
||||||
void *halloc( void *context, size_t size );
|
void *halloc( void *context, size_t size );
|
||||||
|
|
|
@ -7,29 +7,60 @@
|
||||||
#ifndef FISH_HALLOC_UTIL_H
|
#ifndef FISH_HALLOC_UTIL_H
|
||||||
#define 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;
|
extern void *global_context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create the global_context halloc object
|
||||||
|
*/
|
||||||
void halloc_util_init();
|
void halloc_util_init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Free the global_context halloc object
|
||||||
|
*/
|
||||||
void halloc_util_destroy();
|
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 );
|
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 );
|
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)() );
|
void halloc_register_function_void( void *context, void (*func)() );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Free the memory pointed to by \c data when the memory pointed to by
|
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
|
\c context is free:d. Note that this will _not_ turn the specified
|
||||||
memory area into a valid halloc context. Only memory areas created
|
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 );
|
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 );
|
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 );
|
wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
11
parse_util.c
11
parse_util.c
|
@ -1,6 +1,7 @@
|
||||||
/** \file parse_util.c
|
/** \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"
|
#include "config.h"
|
||||||
|
@ -438,6 +439,9 @@ static void clear_hash_value( const void *key, const void *data )
|
||||||
free( (void *)data );
|
free( (void *)data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Part of the autoloader cleanup
|
||||||
|
*/
|
||||||
static void clear_loaded_entry( const void *key, const void *data )
|
static void clear_loaded_entry( const void *key, const void *data )
|
||||||
{
|
{
|
||||||
hash_table_t *loaded = (hash_table_t *)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 );
|
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()
|
static void parse_util_destroy()
|
||||||
{
|
{
|
||||||
if( all_loaded )
|
if( all_loaded )
|
||||||
|
|
38
parse_util.h
38
parse_util.h
|
@ -1,6 +1,7 @@
|
||||||
/** \file parse_util.h
|
/** \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
|
#ifndef FISH_PARSE_UTIL_H
|
||||||
|
@ -8,9 +9,8 @@
|
||||||
|
|
||||||
#include <wchar.h>
|
#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 in the string to search for subshells
|
||||||
\param begin the starting paranthesis of the subshell
|
\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
|
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,
|
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
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
|
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,
|
void parse_util_process_extent( const wchar_t *buff,
|
||||||
int pos,
|
int cursor_pos,
|
||||||
const wchar_t **a,
|
const wchar_t **a,
|
||||||
const wchar_t **b );
|
const wchar_t **b );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Find the beginning and end of the job definition under the cursor
|
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,
|
void parse_util_job_extent( const wchar_t *buff,
|
||||||
int pos,
|
int cursor_pos,
|
||||||
const wchar_t **a,
|
const wchar_t **a,
|
||||||
const wchar_t **b );
|
const wchar_t **b );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Find the beginning and end of the token under the cursor
|
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,
|
void parse_util_token_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
|
@ -79,16 +99,20 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
void (*on_load)(const wchar_t *cmd),
|
void (*on_load)(const wchar_t *cmd),
|
||||||
int reload );
|
int reload );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reset the loader for the specified path value
|
||||||
|
*/
|
||||||
void parse_util_load_reset( const wchar_t *path_var );
|
void parse_util_load_reset( const wchar_t *path_var );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the argv environment variable to the specified null-terminated
|
Set the argv environment variable to the specified null-terminated
|
||||||
array of strings
|
array of strings.
|
||||||
*/
|
*/
|
||||||
void parse_util_set_argv( wchar_t **argv );
|
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 );
|
wchar_t *parse_util_unescape_wildcards( const wchar_t *in );
|
||||||
|
|
||||||
|
|
10
parser.c
10
parser.c
|
@ -1311,11 +1311,10 @@ static void parse_job_main_loop( process_t *p,
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
/* debug( 2, L"Read token %ls\n", wcsdup(tok_last( tok )) ); */
|
|
||||||
|
|
||||||
switch( tok_last_type( tok ) )
|
switch( tok_last_type( tok ) )
|
||||||
{
|
{
|
||||||
case TOK_PIPE:
|
case TOK_PIPE:
|
||||||
|
{
|
||||||
if( (p->type == INTERNAL_EXEC) )
|
if( (p->type == INTERNAL_EXEC) )
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
|
@ -1332,18 +1331,19 @@ static void parse_job_main_loop( process_t *p,
|
||||||
}
|
}
|
||||||
tok_next( tok );
|
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;
|
is_finished = 1;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TOK_BACKGROUND:
|
case TOK_BACKGROUND:
|
||||||
|
{
|
||||||
j->fg = 0;
|
j->fg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
case TOK_END:
|
case TOK_END:
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 )
|
static void read_redirect( tokenizer *tok, int fd )
|
||||||
{
|
{
|
||||||
|
|
40
wildcard.c
40
wildcard.c
|
@ -41,6 +41,29 @@ wildcards using **.
|
||||||
*/
|
*/
|
||||||
#define MAX_FILE_LENGTH 1024
|
#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 )
|
int wildcard_has( const wchar_t *str, int internal )
|
||||||
{
|
{
|
||||||
wchar_t prev=0;
|
wchar_t prev=0;
|
||||||
|
@ -73,8 +96,6 @@ int wildcard_has( const wchar_t *str, int internal )
|
||||||
\param wc The wildcard.
|
\param wc The wildcard.
|
||||||
\param is_first Whether files beginning with dots should not be matched against wildcards.
|
\param is_first Whether files beginning with dots should not be matched against wildcards.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static int wildcard_match2( const wchar_t *str,
|
static int wildcard_match2( const wchar_t *str,
|
||||||
const wchar_t *wc,
|
const wchar_t *wc,
|
||||||
int is_first )
|
int is_first )
|
||||||
|
@ -670,18 +691,3 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
return res;
|
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 );
|
|
||||||
}
|
|
||||||
|
|
|
@ -92,10 +92,4 @@ int wildcard_complete( const wchar_t *str,
|
||||||
const wchar_t *(*desc_func)(const wchar_t *),
|
const wchar_t *(*desc_func)(const wchar_t *),
|
||||||
array_list_t *out );
|
array_list_t *out );
|
||||||
|
|
||||||
/**
|
|
||||||
Push string if not already in list
|
|
||||||
*/
|
|
||||||
void al_push_check( array_list_t *l, const wchar_t *str );
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user