aboutsummaryrefslogtreecommitdiffhomepage
path: root/expand.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-13 05:03:01 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-13 05:03:01 +1000
commiteffe6f47a372d35fa47ab508e7c905d64fbb9b54 (patch)
tree406fb5f1425418cef9af93e69293f9d42adefb06 /expand.c
parent7eb3a5a17dbc1718b65e46e06ceef90db2307c34 (diff)
Minor hallocifications
darcs-hash:20060212190301-ac50b-c15b9a8c6c2897189c4343946d9bd115eefb4972.gz
Diffstat (limited to 'expand.c')
-rw-r--r--expand.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/expand.c b/expand.c
index cdc34102..f2023fb2 100644
--- a/expand.c
+++ b/expand.c
@@ -156,9 +156,6 @@ static wchar_t *expand_var( wchar_t *in )
return env_get( in );
}
-static string_buffer_t *var_tmp = 0;
-static array_list_t *var_idx_list;
-
void expand_variable_array( const wchar_t *val, array_list_t *out )
{
if( val )
@@ -714,8 +711,31 @@ static int expand_pid( wchar_t *in,
return 1;
}
-static void var_tmp_init()
+/**
+ Expand all environment variables in the string *ptr.
+
+ This function is slow, fragile and complicated. There are lots of
+ little corner cases, like $$foo should do a double expansion,
+ $foo$bar should not double expand bar, etc. Also, it's easy to
+ accidentally leak memory on array out of bounds errors an various
+ other situations. All in all, this function should be rewritten,
+ split out into multiple logical units and carefully tested. After
+ that, it can probably be optimized to do fewer memory allocations,
+ fewer string scans and overall just less work. But until that
+ happens, don't edit it unless you know exactly what you are doing,
+ and do proper testing afterwards.
+*/
+static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
{
+ wchar_t c;
+ wchar_t prev_char=0;
+ int i, j;
+ int is_ok= 1;
+ int empty=0;
+
+ static string_buffer_t *var_tmp = 0;
+ static array_list_t *var_idx_list = 0;
+
if( !var_tmp )
{
var_tmp = sb_halloc( global_context );
@@ -737,29 +757,6 @@ static void var_tmp_init()
{
al_truncate( var_idx_list, 0 );
}
-}
-
-/**
- Expand all environment variables in the string *ptr.
-
- This function is slow, fragile and complicated. There are lots of
- little corner cases, like $$foo should do a double expansion,
- $foo$bar should not double expand bar, etc. Also, it's easy to
- accidentally leak memory on array out of bounds errors an various
- other situations. All in all, this function should be rewritten,
- split out into multiple logical units and carefully tested. After
- that, it can probably be optimized to do fewer memory allocations,
- fewer string scans and overall just less work. But until that
- happens, don't edit it unless you know exactly what you are doing,
- and do proper testing afterwards.
-*/
-static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
-{
- wchar_t c;
- wchar_t prev_char=0;
- int i, j;
- int is_ok= 1;
- int empty=0;
for( i=last_idx; (i>=0) && is_ok && !empty; i-- )
{
@@ -836,8 +833,6 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
break;
}
- var_tmp_init();
-
sb_append_substring( var_tmp, &in[start_pos], var_len );
var_val = expand_var( (wchar_t *)var_tmp->buff );