Subversion Repositories DevTools

Rev

Rev 255 | Rev 273 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 263
Line 59... Line 59...
59
    my $class = shift;
59
    my $class = shift;
60
    my $self  = {};
60
    my $self  = {};
61
    $self->{full_path} = 0;
61
    $self->{full_path} = 0;
62
    $self->{recurse}  = 0;
62
    $self->{recurse}  = 0;
63
    $self->{dirs_only}  = 0;
63
    $self->{dirs_only}  = 0;
-
 
64
    $self->{dirs_too} = 0;
64
    $self->{exclude}  = [];
65
    $self->{exclude}  = [];
65
    $self->{include}  = [];
66
    $self->{include}  = [];
66
    $self->{base_dir} = undef;
67
    $self->{base_dir} = undef;
67
    $self->{results}  = [];
68
    $self->{results}  = [];
68
    bless ($self, $class);
69
    bless ($self, $class);
Line 89... Line 90...
89
#                   base_dir
90
#                   base_dir
90
#                   has_filter
91
#                   has_filter
91
#                   results
92
#                   results
92
#                   full_path
93
#                   full_path
93
#                   dirs_only
94
#                   dirs_only
-
 
95
#                   dirs_too                    - Include dirs in the search
94
#
96
#
95
# Description     : Accessor functions
97
# Description     : Accessor functions
96
#
98
#
97
# Inputs          : class
99
# Inputs          : class
98
#                   One argument (optional)
100
#                   One argument (optional)
Line 118... Line 120...
118
    my $self = shift;
120
    my $self = shift;
119
    if (@_) { $self->{dirs_only} = shift }
121
    if (@_) { $self->{dirs_only} = shift }
120
    return $self->{dirs_only};
122
    return $self->{dirs_only};
121
}
123
}
122
 
124
 
-
 
125
sub dirs_too
-
 
126
{
-
 
127
    my $self = shift;
-
 
128
    if (@_) { $self->{dirs_too} = shift }
-
 
129
    return $self->{dirs_too};
-
 
130
}
-
 
131
 
123
sub filter_in
132
sub filter_in
124
{
133
{
125
    my $self = shift;
134
    my $self = shift;
126
    if (@_) { push @{$self->{include}}, glob2pat( shift ) }
135
    if (@_) { push @{$self->{include}}, glob2pat( shift ) }
127
    return $self->{include};
136
    return $self->{include};
Line 205... Line 214...
205
        $self->dirs_only(0);
214
        $self->dirs_only(0);
206
 
215
 
207
    } elsif ( $opt =~ m/^--DirListOnly/ ) {
216
    } elsif ( $opt =~ m/^--DirListOnly/ ) {
208
        $self->dirs_only(1);
217
        $self->dirs_only(1);
209
 
218
 
-
 
219
    } elsif ( $opt =~ m/^--DirsToo/ ) {
-
 
220
        $self->dirs_too(1);
-
 
221
 
210
    } elsif ( $opt =~ m/^--FilterIn=(.+)/ ) {
222
    } elsif ( $opt =~ m/^--FilterIn=(.+)/ ) {
211
        $self->filter_in ( $1 );
223
        $self->filter_in ( $1 );
212
 
224
 
213
    } elsif ( $opt =~ m/^--FilterInRe=(.+)/ ) {
225
    } elsif ( $opt =~ m/^--FilterInRe=(.+)/ ) {
214
        $self->filter_in_re ( $1 );
226
        $self->filter_in_re ( $1 );
Line 240... Line 252...
240
#                   The list is a simple list of file names
252
#                   The list is a simple list of file names
241
#
253
#
242
 
254
 
243
my @search_list;             # Must be global to avoid closure problems
255
my @search_list;             # Must be global to avoid closure problems
244
my $search_len;
256
my $search_len;
-
 
257
my $search_base_dir;
-
 
258
my $search_dirs_too;
245
 
259
 
246
sub search
260
sub search
247
{
261
{
248
    my $self = shift;
262
    my $self = shift;
249
    $self->{base_dir} = $_[0] if (defined $_[0] );
263
    $self->{base_dir} = $_[0] if (defined $_[0] );
Line 276... Line 290...
276
    #
290
    #
277
    if ( -d $self->{base_dir} )
291
    if ( -d $self->{base_dir} )
278
    {
292
    {
279
        if ( $self->{recurse} )
293
        if ( $self->{recurse} )
280
        {
294
        {
-
 
295
            $search_dirs_too = $self->{dirs_too};
-
 
296
            $search_base_dir = $self->{base_dir};
281
            sub find_file_wanted
297
            sub find_file_wanted
282
            {
298
            {
283
                return if ( -d $_ );
299
                return if ( !$search_dirs_too && -d $_ );               # skip if current is dir and we are not including dirs
-
 
300
                return if ( $search_base_dir eq $File::Find::name );    # skip if current is base_dir as we dont include it
284
                my $file = $File::Find::name;
301
                my $file = $File::Find::name;
285
                push @search_list, substr($file, $search_len );
302
                push @search_list, substr($file, $search_len );
286
            }
303
            }
287
 
304
 
288
            #
305
            #
Line 303... Line 320...
303
            opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
320
            opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
304
            foreach ( readdir( DIR ) )
321
            foreach ( readdir( DIR ) )
305
            {
322
            {
306
                next if /^\Q.\E$/;
323
                next if /^\Q.\E$/;
307
                next if /^\Q..\E$/;
324
                next if /^\Q..\E$/;
308
                next if ( -d "$self->{base_dir}/$_" );
325
                next if ( !$self->{dirs_too} && -d "$self->{base_dir}/$_" );
309
                push @search_list, $_;
326
                push @search_list, $_;
310
            }
327
            }
311
            closedir DIR;
328
            closedir DIR;
312
        }
329
        }
313
    }
330
    }