mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
Fix broken recursive wildcard patch
darcs-hash:20051130153303-ac50b-3d0973badb50a98fe8038135a031a8ee14e4f894.gz
This commit is contained in:
parent
2789da6a1a
commit
8ff66e718c
1 changed files with 56 additions and 11 deletions
61
wildcard.c
61
wildcard.c
|
@ -27,6 +27,13 @@
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "expand.h"
|
#include "expand.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
This flag is set in the flags parameter of wildcard_expand if the
|
||||||
|
call is part of a recursiv wildcard search. It is used to make sure
|
||||||
|
that the contents of subdirectories are only searched once.
|
||||||
|
*/
|
||||||
|
#define WILDCARD_RECURSIVE 64
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The maximum length of a filename token. This is a fallback value,
|
The maximum length of a filename token. This is a fallback value,
|
||||||
an attempt to find the true value using patchconf is always made.
|
an attempt to find the true value using patchconf is always made.
|
||||||
|
@ -80,20 +87,29 @@ static int wildcard_match2( const wchar_t *str,
|
||||||
{
|
{
|
||||||
/* Ignore hidden file */
|
/* Ignore hidden file */
|
||||||
if( is_first && *str == L'.' )
|
if( is_first && *str == L'.' )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try all submatches */
|
/* Try all submatches */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if( wildcard_match2( str, wc+1, 0 ) )
|
if( wildcard_match2( str, wc+1, 0 ) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
while( *(str++) != 0 );
|
while( *(str++) != 0 );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *wc == ANY_CHAR )
|
if( *wc == ANY_CHAR )
|
||||||
|
{
|
||||||
|
if( is_first && *str == L'.' )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return wildcard_match2( str+1, wc+1, 0 );
|
return wildcard_match2( str+1, wc+1, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
if( *wc == *str )
|
if( *wc == *str )
|
||||||
return wildcard_match2( str+1, wc+1, 0 );
|
return wildcard_match2( str+1, wc+1, 0 );
|
||||||
|
@ -380,6 +396,19 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
wc_recursive = wcschr( wc, ANY_STRING_RECURSIVE );
|
wc_recursive = wcschr( wc, ANY_STRING_RECURSIVE );
|
||||||
is_recursive = ( wc_recursive && (!wc_end || wc_recursive < wc_end));
|
is_recursive = ( wc_recursive && (!wc_end || wc_recursive < wc_end));
|
||||||
|
|
||||||
|
/*
|
||||||
|
This makes sure that the base
|
||||||
|
directory of the recursive search is
|
||||||
|
also searched for matching files.
|
||||||
|
*/
|
||||||
|
if( is_recursive && (wc_end==(wc+1)) && !(flags & WILDCARD_RECURSIVE ) )
|
||||||
|
{
|
||||||
|
wildcard_expand( wc_end + 1,
|
||||||
|
base_dir,
|
||||||
|
flags,
|
||||||
|
out );
|
||||||
|
}
|
||||||
|
|
||||||
if( flags & ACCEPT_INCOMPLETE )
|
if( flags & ACCEPT_INCOMPLETE )
|
||||||
sb_init( &sb_desc );
|
sb_init( &sb_desc );
|
||||||
|
|
||||||
|
@ -430,7 +459,7 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = 1;
|
res = 1;
|
||||||
al_push( out, wcsdup( base_dir ) );
|
al_push_check( out, wcsdup( base_dir ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -483,7 +512,7 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
{
|
{
|
||||||
wchar_t *long_name = make_path( base_dir, name );
|
wchar_t *long_name = make_path( base_dir, name );
|
||||||
|
|
||||||
al_push( out, long_name );
|
al_push_check( out, long_name );
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,11 +523,10 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Wilcard segment is not the last segment.
|
Wilcard segment is not the last segment. Recursively call
|
||||||
Recursively call wildcard_expand for all matching subdirectories.
|
wildcard_expand for all matching subdirectories.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wc_str is the part of the wildcarded string from the
|
wc_str is the part of the wildcarded string from the
|
||||||
beginning to the first slash
|
beginning to the first slash
|
||||||
|
@ -506,7 +534,8 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
wchar_t *wc_str;
|
wchar_t *wc_str;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
new_dir is a scratch area containing the full path to a file/directory we are iterating over
|
new_dir is a scratch area containing the full path to a
|
||||||
|
file/directory we are iterating over
|
||||||
*/
|
*/
|
||||||
wchar_t *new_dir;
|
wchar_t *new_dir;
|
||||||
|
|
||||||
|
@ -603,6 +632,7 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
new_dir,
|
new_dir,
|
||||||
flags,
|
flags,
|
||||||
out );
|
out );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -612,7 +642,7 @@ int wildcard_expand( const wchar_t *wc,
|
||||||
{
|
{
|
||||||
res |= wildcard_expand( wcschr( wc, ANY_STRING_RECURSIVE ),
|
res |= wildcard_expand( wcschr( wc, ANY_STRING_RECURSIVE ),
|
||||||
new_dir,
|
new_dir,
|
||||||
flags,
|
flags | WILDCARD_RECURSIVE,
|
||||||
out );
|
out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -633,3 +663,18 @@ 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( new );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
al_push( l, new );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue