mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Removed halloc from highlight.cpp
This commit is contained in:
parent
7e52523541
commit
b2e5809180
1 changed files with 15 additions and 29 deletions
|
@ -31,8 +31,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "complete.h"
|
#include "complete.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "halloc.h"
|
|
||||||
#include "halloc_util.h"
|
|
||||||
#include "wildcard.h"
|
#include "wildcard.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
|
@ -535,7 +533,7 @@ static int has_expand_reserved( const wchar_t *str )
|
||||||
|
|
||||||
|
|
||||||
// PCA DOES_IO
|
// PCA DOES_IO
|
||||||
void tokenize( const wchar_t * const buff, int * const color, const int pos, array_list_t *error, void *context, const env_vars &vars) {
|
static void tokenize( const wchar_t * const buff, int * const color, const int pos, array_list_t *error, const env_vars &vars) {
|
||||||
ASSERT_IS_BACKGROUND_THREAD();
|
ASSERT_IS_BACKGROUND_THREAD();
|
||||||
|
|
||||||
wcstring cmd;
|
wcstring cmd;
|
||||||
|
@ -806,21 +804,21 @@ void tokenize( const wchar_t * const buff, int * const color, const int pos, arr
|
||||||
|
|
||||||
if( target != 0 )
|
if( target != 0 )
|
||||||
{
|
{
|
||||||
wchar_t *dir = halloc_wcsdup( context, target );
|
wcstring dir = target;
|
||||||
wchar_t *dir_end = wcsrchr( dir, L'/' );
|
size_t slash_idx = dir.find(L'/');
|
||||||
struct stat buff;
|
struct stat buff;
|
||||||
/*
|
/*
|
||||||
If file is in directory other than '.', check
|
If file is in directory other than '.', check
|
||||||
that the directory exists.
|
that the directory exists.
|
||||||
*/
|
*/
|
||||||
if( dir_end != 0 )
|
if( slash_idx != wcstring::npos )
|
||||||
{
|
{
|
||||||
*dir_end = 0;
|
dir.resize(slash_idx);
|
||||||
if( wstat( dir, &buff ) == -1 )
|
if( wstat( dir.c_str(), &buff ) == -1 )
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
if( error )
|
if( error )
|
||||||
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
|
al_push( error, wcsdupcat( L"Directory \'", dir.c_str(), L"\' does not exist" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -909,15 +907,13 @@ void tokenize( const wchar_t * const buff, int * const color, const int pos, arr
|
||||||
|
|
||||||
|
|
||||||
// PCA DOES_IO (calls is_potential_path, path_get_path, maybe others)
|
// PCA DOES_IO (calls is_potential_path, path_get_path, maybe others)
|
||||||
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 * const buff, int *color, int pos, array_list_t *error, const env_vars &vars )
|
||||||
{
|
{
|
||||||
ASSERT_IS_BACKGROUND_THREAD();
|
ASSERT_IS_BACKGROUND_THREAD();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
int last_val;
|
int last_val;
|
||||||
|
|
||||||
void *context;
|
|
||||||
|
|
||||||
CHECK( buff, );
|
CHECK( buff, );
|
||||||
CHECK( color, );
|
CHECK( color, );
|
||||||
|
@ -927,30 +923,24 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
|
||||||
if( !len )
|
if( !len )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
context = halloc( 0, 0 );
|
|
||||||
|
|
||||||
for( i=0; buff[i] != 0; i++ )
|
for( i=0; buff[i] != 0; i++ )
|
||||||
color[i] = -1;
|
color[i] = -1;
|
||||||
|
|
||||||
/* Tokenize the string */
|
/* Tokenize the string */
|
||||||
tokenize(buff, color, pos, error, context, vars);
|
tokenize(buff, color, pos, error, vars);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Locate and syntax highlight cmdsubsts recursively
|
Locate and syntax highlight cmdsubsts recursively
|
||||||
*/
|
*/
|
||||||
|
|
||||||
wchar_t *buffcpy = halloc_wcsdup( context, buff );
|
const wchar_t * subpos=buff;
|
||||||
wchar_t *subpos=buffcpy;
|
|
||||||
int done=0;
|
int done=0;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
|
|
||||||
if( parse_util_locate_cmdsubst( subpos,
|
if( parse_util_locate_cmdsubst(subpos, &begin, &end, 1) <= 0)
|
||||||
&begin,
|
|
||||||
&end,
|
|
||||||
1) <= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -960,8 +950,8 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
|
||||||
else
|
else
|
||||||
*end=0;
|
*end=0;
|
||||||
|
|
||||||
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error, vars );
|
highlight_shell( begin+1, color +(begin-buff)+1, -1, error, vars );
|
||||||
color[end-buffcpy]=HIGHLIGHT_OPERATOR;
|
color[end-buff]=HIGHLIGHT_OPERATOR;
|
||||||
|
|
||||||
if( done )
|
if( done )
|
||||||
break;
|
break;
|
||||||
|
@ -991,13 +981,11 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
|
||||||
if( pos >= 0 && pos <= len )
|
if( pos >= 0 && pos <= len )
|
||||||
{
|
{
|
||||||
|
|
||||||
const wchar_t *tok_begin, *tok_end, *token;
|
const wchar_t *tok_begin, *tok_end;
|
||||||
|
|
||||||
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
|
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
|
||||||
if( tok_begin && tok_end )
|
if( tok_begin && tok_end )
|
||||||
{
|
{
|
||||||
token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin );
|
const wcstring token(tok_begin, tok_end-tok_begin);
|
||||||
|
|
||||||
if( is_potential_path( token ) )
|
if( is_potential_path( token ) )
|
||||||
{
|
{
|
||||||
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
|
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
|
||||||
|
@ -1021,8 +1009,6 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
|
||||||
color[i]=0;
|
color[i]=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue