Added support for recursive wildcards

darcs-hash:20051123153503-b56f0-6d837388e8bbfdebba9a399f8374b3e8433e5a32.gz
This commit is contained in:
horeah 2005-11-24 01:35:03 +10:00
parent d748e05cb9
commit 279159384e
2 changed files with 41 additions and 4 deletions

View file

@ -79,6 +79,13 @@ static int wildcard_match2( const wchar_t *str,
{ {
if( wildcard_match2( str, wc+1, 0 ) ) if( wildcard_match2( str, wc+1, 0 ) )
return 1; return 1;
if( *wc == ANY_STRING_RECURSIVE
&& ( wildcard_match2(str+1, wc, 0) || wildcard_match2(str+1, wc+1, 0) ) ) {
return 1;
}
} }
while( *(str++) != 0 ); while( *(str++) != 0 );
return 0; return 0;
@ -394,7 +401,7 @@ int wildcard_expand( const wchar_t *wc,
get_desc( long_name, get_desc( long_name,
&sb_desc, &sb_desc,
flags & EXECUTABLES_ONLY ); flags & EXECUTABLES_ONLY );
al_push( out, al_push_check( out,
wcsdupcat(name, (wchar_t *)sb_desc.buff) ); wcsdupcat(name, (wchar_t *)sb_desc.buff) );
} }
@ -407,7 +414,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
@ -478,7 +485,7 @@ int wildcard_expand( const wchar_t *wc,
return 0; return 0;
} }
al_push( out, long_name ); al_push_check( out, long_name );
res = 1; res = 1;
} }
} }
@ -519,6 +526,11 @@ int wildcard_expand( const wchar_t *wc,
} }
wcscpy( new_dir, base_dir ); wcscpy( new_dir, base_dir );
int has_base = 0;
if ( *wc == ANY_STRING_RECURSIVE )
has_base = wildcard_expand( wc_end + 1, base_dir, flags, out );
while( (next=readdir(dir))!=0 ) while( (next=readdir(dir))!=0 )
{ {
wchar_t *name = str2wcs(next->d_name); wchar_t *name = str2wcs(next->d_name);
@ -554,7 +566,14 @@ int wildcard_expand( const wchar_t *wc,
new_len = wcslen( new_dir ); new_len = wcslen( new_dir );
new_dir[new_len] = L'/'; new_dir[new_len] = L'/';
new_dir[new_len+1] = L'\0'; new_dir[new_len+1] = L'\0';
switch( wildcard_expand( wc_end + 1, new_dir, flags, out ) )
int has_entries = 0;
if( *wc == ANY_STRING_RECURSIVE )
has_entries = wildcard_expand( wc, new_dir, flags, out );
else
has_entries = wildcard_expand( wc_end + 1, new_dir, flags, out );
switch( has_entries )
{ {
case 0: case 0:
break; break;
@ -569,6 +588,7 @@ int wildcard_expand( const wchar_t *wc,
free(name); free(name);
} }
} }
res = res || has_base;
free( wc_str ); free( wc_str );
free( new_dir ); free( new_dir );
} }
@ -579,3 +599,14 @@ 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 ) )
return;
al_push( l, new );
}

View file

@ -93,4 +93,10 @@ int wildcard_complete( const wchar_t *str,
const wchar_t *(*desc_func)(const wchar_t *), const wchar_t *(*desc_func)(const wchar_t *),
array_list_t *out ); array_list_t *out );
/**
Push string if not already in list
*/
void al_push_check( array_list_t *l, const wchar_t *str );
#endif #endif