Migrate errors from array_list_t to wcstring_list_t

This commit is contained in:
ridiculousfish 2012-02-10 17:54:21 -08:00
parent 18bb64cd43
commit 9b1930588f
6 changed files with 38 additions and 31 deletions

View file

@ -428,6 +428,15 @@ void complete_remove( const wchar_t *cmd,
}
}
/* Formats an error string by prepending the prefix and then appending the str in single quotes */
static wcstring format_error(const wchar_t *prefix, const wcstring &str) {
wcstring result = prefix;
result.push_back(L'\'');
result.append(str);
result.push_back(L'\'');
return result;
}
/**
Find the full path and commandname from a command string 'str'.
*/
@ -448,7 +457,7 @@ static void parse_cmd_string(const wcstring &str, wcstring &path, wcstring &cmd)
int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
array_list_t *errors,
wcstring_list_t *errors,
bool allow_autoload )
{
wcstring cmd, path;
@ -493,9 +502,7 @@ int complete_is_valid_option( const wchar_t *str,
if( opt[0] != L'-' )
{
if( errors )
{
al_push( errors, wcsdup(L"Option does not begin with a '-'") );
}
errors->push_back(L"Option does not begin with a '-'");
return 0;
}
@ -642,8 +649,7 @@ int complete_is_valid_option( const wchar_t *str,
wchar_t str[2];
str[0] = opt[j];
str[1]=0;
al_push( errors,
wcsdupcat(_( L"Unknown option: " ), L"'", str, L"'" ) );
errors->push_back(format_error(_(L"Unknown option: "), str));
}
opt_found = 0;
@ -658,16 +664,16 @@ int complete_is_valid_option( const wchar_t *str,
opt_found = is_gnu_exact || (gnu_match_set.size() == 1);
if( errors && !opt_found )
{
if( gnu_match_set.empty())
const wchar_t *prefix;
if( gnu_match_set.empty())
{
al_push( errors,
wcsdupcat( _(L"Unknown option: "), L"'", opt, L"\'" ) );
prefix = _(L"Unknown option: ");
}
else
{
al_push( errors,
wcsdupcat( _(L"Multiple matches for option: "), L"'", opt, L"\'" ) );
prefix = _(L"Multiple matches for option: ");
}
errors->push_back(format_error(prefix, opt));
}
}
}

View file

@ -235,7 +235,7 @@ void complete_print( string_buffer_t *out );
*/
int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
array_list_t *errors,
wcstring_list_t *inErrorsOrNull,
bool allow_autoload );
/**

View file

@ -224,7 +224,7 @@ int highlight_get_color( int highlight, bool is_background )
static void highlight_param( const wchar_t * buff,
int *color,
int pos,
array_list_t *error )
wcstring_list_t *error )
{
@ -532,8 +532,8 @@ static int has_expand_reserved( const wchar_t *str )
// PCA DOES_IO
static void tokenize( const wchar_t * const buff, int * const color, const int pos, array_list_t *error, const env_vars &vars) {
// This function does I/O
static void tokenize( const wchar_t * const buff, int * const color, const int pos, wcstring_list_t *error, const env_vars &vars) {
ASSERT_IS_BACKGROUND_THREAD();
wcstring cmd;
@ -728,8 +728,9 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
}
else
{
if( error )
al_push( error, wcsdupcat ( L"Unknown command \'", cmd.c_str(), L"\'" ));
if( error ) {
error->push_back(format_string(L"Unknown command \'%ls\'", cmd.c_str()));
}
color[ tok_get_pos( &tok ) ] = (HIGHLIGHT_ERROR);
}
had_cmd = 1;
@ -755,7 +756,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdup ( L"Redirection without a command" ) );
error->push_back(L"Redirection without a command");
break;
}
@ -787,7 +788,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdup ( L"Invalid redirection" ) );
error->push_back(L"Invalid redirection");
}
}
@ -808,7 +809,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat( L"Directory \'", dir.c_str(), L"\' does not exist" ) );
error->push_back(format_string(L"Directory \'%ls\' does not exist", dir.c_str()));
}
}
@ -824,7 +825,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat( L"File \'", target, L"\' does not exist" ) );
error->push_back(format_string(L"File \'%ls\' does not exist", target));
}
}
if( last_type == TOK_REDIRECT_NOCLOB )
@ -833,7 +834,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat( L"File \'", target, L"\' exists" ) );
error->push_back(format_string(L"File \'%ls\' exists", target));
}
}
}
@ -856,7 +857,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdup ( L"No job to put in background" ) );
error->push_back(L"No job to put in background" );
}
break;
@ -886,7 +887,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
If the tokenizer reports an error, highlight it as such.
*/
if( error )
al_push( error, wcsdup ( tok_last( &tok) ) );
error->push_back(tok_last( &tok));
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
break;
}
@ -897,7 +898,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
// PCA DOES_IO (calls is_potential_path, path_get_path, maybe others)
void highlight_shell( const wchar_t * const buff, int *color, int pos, array_list_t *error, const env_vars &vars )
void highlight_shell( const wchar_t * const buff, int *color, int pos, wcstring_list_t *error, const env_vars &vars )
{
ASSERT_IS_BACKGROUND_THREAD();
@ -1116,7 +1117,7 @@ static void highlight_universal_internal( const wchar_t * buff,
}
}
void highlight_universal( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars )
void highlight_universal( const wchar_t *buff, int *color, int pos, wcstring_list_t *error, const env_vars &vars )
{
int i;

View file

@ -78,7 +78,7 @@
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars );
void highlight_shell( const wchar_t *buff, int *color, int pos, wcstring_list_t *error, const env_vars &vars );
/**
Perform syntax highlighting for the text in buff. Matching quotes and paranthesis are highlighted. The result is
@ -90,7 +90,7 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
void highlight_universal( const wchar_t *buff, int *color, int pos, array_list_t *error, const env_vars &vars );
void highlight_universal( const wchar_t *buff, int *color, int pos, wcstring_list_t *error, const env_vars &vars );
/**
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment

View file

@ -2402,7 +2402,6 @@ static void highlight_complete(void *ctx_ptr, int result) {
static int threaded_highlight(void *ctx_ptr) {
background_highlight_context_t *ctx = (background_highlight_context_t *)ctx_ptr;
array_list_t *error = 0;
const wchar_t *delayer = ctx->vars.get(L"HIGHLIGHT_DELAY");
double secDelay = 0;
if (delayer) {
@ -2411,7 +2410,7 @@ static int threaded_highlight(void *ctx_ptr) {
}
if (secDelay > 0) usleep((useconds_t)(secDelay * 1E6));
//write(0, "Start", 5);
ctx->highlight_function( ctx->string_to_highlight.c_str(), ctx->color, ctx->match_highlight_pos, error, ctx->vars );
ctx->highlight_function( ctx->string_to_highlight.c_str(), ctx->color, ctx->match_highlight_pos, NULL /* error */, ctx->vars );
//write(0, "End", 3);
return 0;
}

View file

@ -14,6 +14,7 @@
#include "util.h"
#include "io.h"
#include "common.h"
class parser_t;
class completion_t;
@ -137,7 +138,7 @@ void reader_set_complete_function( void (*f)( const wchar_t *, std::vector<compl
The type of a highlight function.
*/
class env_vars;
typedef void (*highlight_function_t)( const wchar_t *, int *, int, array_list_t *, const env_vars &vars );
typedef void (*highlight_function_t)( const wchar_t *, int *, int, wcstring_list_t *, const env_vars &vars );
/**
Specify function for syntax highlighting. The function must take these arguments: