aboutsummaryrefslogtreecommitdiffhomepage
path: root/expand.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-07-20 23:02:46 +1000
committerGravatar axel <axel@liljencrantz.se>2006-07-20 23:02:46 +1000
commit5c8d9bd13c82c66fcb0b15d2844359dc3c306d96 (patch)
tree26624c5003f1467b4411b453c775e8b229de3223 /expand.c
parent1c9a173b3dbb2f89658ad26cc6ede6fe9afed706 (diff)
Minor duplicate code removal
darcs-hash:20060720130246-ac50b-b41daebb302e1cbadf2a4cf812d936edbda85926.gz
Diffstat (limited to 'expand.c')
-rw-r--r--expand.c102
1 files changed, 65 insertions, 37 deletions
diff --git a/expand.c b/expand.c
index a83dcfa3..84bee780 100644
--- a/expand.c
+++ b/expand.c
@@ -47,6 +47,26 @@ parameter expansion.
#include "halloc_util.h"
/**
+ Error issued on invalid variable name
+*/
+#define COMPLETE_VAR_DESC _( L"The '$' character begins a variable name. The character '%lc', which directly followed a '$', is not allowed as a part of a variable name, and variable names may not be zero characters long. To learn more about variable expansion in fish, type 'help expand-variable'.")
+
+/**
+ Error issued on invalid variable name
+*/
+#define COMPLETE_VAR_NULL_DESC _( L"The '$' begins a variable name. It was given at the end of an argument. Variable names may not be zero characters long. To learn more about variable expansion in fish, type 'help expand-variable'.")
+
+/**
+ Error issued on invalid variable name
+*/
+#define COMPLETE_VAR_BRACKET_DESC _( L"Did you mean {$VARIABLE}? The '$' character begins a variable name. A bracket, which directly followed a '$', is not allowed as a part of a variable name, and variable names may not be zero characters long. To learn more about variable expansion in fish, type 'help expand-variable'." )
+
+/**
+ Error issued on invalid variable name
+*/
+#define COMPLETE_VAR_PARAN_DESC _( L"Did you mean (COMMAND)? In fish, the '$' character is only used for accessing variables. To learn more about command substitution in fish, type 'help expand-command-substitution'.")
+
+/**
Description for child process
*/
#define COMPLETE_CHILD_PROCESS_DESC _( L"Child process")
@@ -649,6 +669,49 @@ static int expand_pid( wchar_t *in,
return 1;
}
+
+void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
+{
+ int stop_pos = token_pos+1;
+
+ switch( token[stop_pos] )
+ {
+ case BRACKET_BEGIN:
+ {
+ error( SYNTAX_ERROR,
+ error_pos,
+ COMPLETE_VAR_BRACKET_DESC );
+ break;
+ }
+
+ case INTERNAL_SEPARATOR:
+ {
+ error( SYNTAX_ERROR,
+ error_pos,
+ COMPLETE_VAR_PARAN_DESC );
+ break;
+ }
+
+ case 0:
+ {
+ error( SYNTAX_ERROR,
+ error_pos,
+ COMPLETE_VAR_NULL_DESC );
+ break;
+ }
+
+ default:
+ {
+ error( SYNTAX_ERROR,
+ error_pos,
+ COMPLETE_VAR_DESC,
+ token[stop_pos] );
+ break;
+ }
+ }
+}
+
+
/**
Expand all environment variables in the string *ptr.
@@ -735,43 +798,8 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
if( var_len == 0 )
{
- switch( in[stop_pos] )
- {
- case BRACKET_BEGIN:
- {
- error( SYNTAX_ERROR,
- -1,
- COMPLETE_VAR_BRACKET_DESC );
- break;
- }
-
- case INTERNAL_SEPARATOR:
- {
- error( SYNTAX_ERROR,
- -1,
- COMPLETE_VAR_PARAN_DESC );
- break;
- }
-
- case 0:
- {
- error( SYNTAX_ERROR,
- -1,
- COMPLETE_VAR_NULL_DESC );
- break;
- }
-
- default:
- {
- error( SYNTAX_ERROR,
- -1,
- COMPLETE_VAR_DESC,
- in[stop_pos] );
- break;
- }
- }
-
-
+ expand_variable_error( in, stop_pos-1, -1 );
+
is_ok = 0;
break;
}