diff options
author | horeah <horeah@gmail.com> | 2005-11-24 01:35:03 +1000 |
---|---|---|
committer | horeah <horeah@gmail.com> | 2005-11-24 01:35:03 +1000 |
commit | 279159384ee35998ba257e95260e4d1477461fd6 (patch) | |
tree | 389cd97ab310bab04413d65e1cff22504bfa777f /wildcard.c | |
parent | d748e05cb9fac64ed68e83bf22acb09518b97591 (diff) |
Added support for recursive wildcards
darcs-hash:20051123153503-b56f0-6d837388e8bbfdebba9a399f8374b3e8433e5a32.gz
Diffstat (limited to 'wildcard.c')
-rw-r--r-- | wildcard.c | 39 |
1 files changed, 35 insertions, 4 deletions
@@ -79,6 +79,13 @@ static int wildcard_match2( const wchar_t *str, { if( wildcard_match2( str, wc+1, 0 ) ) 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 ); return 0; @@ -394,7 +401,7 @@ int wildcard_expand( const wchar_t *wc, get_desc( long_name, &sb_desc, flags & EXECUTABLES_ONLY ); - al_push( out, + al_push_check( out, wcsdupcat(name, (wchar_t *)sb_desc.buff) ); } @@ -407,7 +414,7 @@ int wildcard_expand( const wchar_t *wc, else { res = 1; - al_push( out, wcsdup( base_dir ) ); + al_push_check( out, wcsdup( base_dir ) ); } } else @@ -478,7 +485,7 @@ int wildcard_expand( const wchar_t *wc, return 0; } - al_push( out, long_name ); + al_push_check( out, long_name ); res = 1; } } @@ -518,6 +525,11 @@ int wildcard_expand( const wchar_t *wc, return 0; } 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 ) { @@ -554,7 +566,14 @@ int wildcard_expand( const wchar_t *wc, new_len = wcslen( new_dir ); new_dir[new_len] = L'/'; 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: break; @@ -569,6 +588,7 @@ int wildcard_expand( const wchar_t *wc, free(name); } } + res = res || has_base; free( wc_str ); free( new_dir ); } @@ -579,3 +599,14 @@ int wildcard_expand( const wchar_t *wc, 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 ); +} |