This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.20/Wx/build/Utils.pm is in libwx-perl 1:0.9923-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package Wx::build::Utils;

use strict;
use Config;
use base 'Exporter';
use File::Spec::Functions qw(curdir catdir catfile updir);
use File::Find qw(find);
use File::Path qw(mkpath);
use File::Basename qw(dirname);
use Carp;

use vars qw(@EXPORT @EXPORT_OK);
@EXPORT_OK = qw(obj_from_src xs_dependencies write_string
                lib_file arch_file arch_auto_file
                path_search files_with_overload files_with_constants
                pipe_stderr read_file write_file);

=head1 NAME

Wx::build::Utils - utility routines

=head1 SUBROUTINES

=head2 xs_dependencies

  my %dependencies = xs_dependencies( $mm_object, [ 'dir1', 'dir2' ] );

=cut

sub _uniq {
    my( %x );
    $x{$_} = 1 foreach @_;
    return sort keys %x;
}

sub xs_dependencies {
  my( $this, $dirs, $top_dir ) = @_;

  my( %depend );
  my( $c, $o, $cinclude, $xsinclude );

  foreach ( keys %{ $this->{XS} } ) {
    ( $cinclude, $xsinclude ) = scan_xs( $_, $dirs, $top_dir );

    $c = $this->{XS}{$_};
    $o = obj_from_src( $c );

    $depend{$c} = $_ . ' ' . join( ' ', _uniq( @$xsinclude ) );
    $depend{$o} = $c . ' ' . join( ' ', _uniq( @$cinclude ) );
  }

  return %depend;
}

=head2 obj_from_src

  my @obj_files = obj_from_src( 'Foo.xs', 'bar.c', 'cpp/bar.cpp' );

Calculates the object file name from the source file name.
In scalar context returns the first file.

=cut

sub obj_from_src {
  my @xs = @_;
  my $obj_ext = $Config{obj_ext} || $Config{_o};

  foreach ( @xs ) { s[\.(?:xs|c|cc|cpp)$][$obj_ext] }

  return wantarray ? @xs : $xs[0];
}

sub src_dir {
  my( $file ) = @_;
  my $d = curdir;

  for ( 1 .. 5 ) {
    return $d if -f catfile( $d, $file );
    $d = catdir( updir, $d );
  }

  confess "Unable to find top level directory ($file)";
}

#
# quick and dirty method for creating dependencies:
# considers files included via #include "...", INCLUDE: or INCLUDE_COMMAND:
# (not #include <...>) and does not take into account preprocessor directives
#
sub scan_xs($$$);

sub scan_xs($$$) {
  my( $xs, $incpath, $top_dir ) = @_;

  local( *IN, $_ );
  my( @cinclude, @xsinclude );

  open IN, $xs;

  my $file;
  my $arr;

  while( defined( $_ = <IN> ) ) {
    undef $file;

    m/^\#\s*include\s+"([^"]*)"\s*$/ and $file = $1 and $arr = \@cinclude;
    m/^\s*INCLUDE:\s+(.*)$/ and $file = $1 and $arr = \@xsinclude;
    m/^\s*INCLUDE_COMMAND:\s+.*\s(\S+\.(?:xsp?|h))\s*/ and $file = $1 and
      $arr = \@xsinclude;
    m/^\s*\%include{([^}]+)}\s*;\s*$/ and $file = $1 and $arr = \@xsinclude;

    if( defined $file ) {
      $file = catfile( split '/', $file );

      foreach my $dir ( @$incpath ) {
        my $f = $dir eq curdir() ? $file : catfile( $dir, $file );
        if( -f $f ) {
          push @$arr, $f;
          my( $cinclude, $xsinclude ) = scan_xs( $f, $incpath, $top_dir );
          push @cinclude, @$cinclude;
          push @xsinclude, @$xsinclude;
          last;
        } elsif(    $file =~ m/ovl_const\.(?:cpp|h)/i
                 || $file =~ m/v_cback_def\.h/i
                 || $file =~ m/ItemContainer(?:Immutable)?\.xs/i
                 || $file =~ m/Var[VH]{0,2}ScrollHelper(?:Base)?\.xs/i ) {
          push @$arr, ( ( $top_dir eq curdir() ) ?
                        $file :
                        catfile( $top_dir, $file ) );
        }
      }
    }
  }

  close IN;

  ( \@cinclude, \@xsinclude );
}

=head2 write_string, write_file

  write_string( 'file', $scalar );
  write_file( 'file', $scalar );

Like File::Slurp.

=head2 read_file

  my $string = read_file( 'file' );

=cut

*write_string = \&write_file;

sub write_file {
  my( $file, $string ) = @_;

  mkpath( dirname( $file ) ) if dirname( $file );
  open my $fh, ">", $file or die "open '$file': $!";
  binmode $fh;
  print $fh $string or die "print '$file': $!";
  close $fh or die "close '$file': $!";
}

sub read_file {
  my( $file ) = @_;

  local $/ = wantarray ? $/ : undef;;
  open my $fh, "<", $file or die "open '$file': $!";
  binmode $fh;

  return <$fh>;
}

=head2 lib_file, arch_file, arch_auto_file

  my $file = lib_file( 'Foo.pm' );          # blib/lib/Foo.pm     on *nix
  my $file = lib_file( 'Foo/Bar.pm' );      # blib\lib\Foo\Bar.pm on Win32
  my $file = arch_auto_file( 'My\My.dll' ); # blib\arch\auto\My\My.dll

All input paths must be relative, output paths may be absolute.

=cut

sub _split {
  require File::Spec::Unix;

  my $path = shift;
  my( $volume, $dir, $file ) = File::Spec::Unix->splitpath( $path );
  my @dirs = File::Spec::Unix->splitdir( $dir );

  return ( @dirs, $file );
}

sub lib_file {
  my @split = _split( shift );

  return File::Spec->catfile( 'blib', 'lib', @split );
}

sub arch_file {
  my @split = _split( shift );

  return File::Spec->catfile( 'blib', 'arch', @split );
}

sub arch_auto_file {
  my @split = _split( shift );

  return File::Spec->catfile( 'blib', 'arch', 'auto', @split );
}

=head2 path_search

  my $file = path_search( 'foo.exe' );

Searches PATH for the given executable.

=cut

sub path_search {
  my $file = shift;

  foreach my $d ( File::Spec->path ) {
    my $full = File::Spec->catfile( $d, $file );
    return $full if -f $full;
  }

  return;
}

=head2 files_with_constants

  my @files = files_with_constants;

Finds files containing constants

=cut

sub files_with_constants {
  my @files;

  my $wanted = sub {
    my $name = $File::Find::name;

    m/\.(?:pm|xsp?|cpp|h)$/i && do {
      local *IN;
      my $line;

      open IN, "< $_" || warn "unable to open '$_'";
      while( defined( $line = <IN> ) ) {
        $line =~ m/^\W+\!\w+:/ && do {
          push @files, $name;
          return;
        };
        # for XS++ files containing enums, see comment in Any_OS.pm
        $line =~ m/^\s*enum\b/ && do {
          push @files, $name;
          return;
        };
      };
    };
  };

  find( $wanted, curdir );

  return @files;
}

=head2 files_with_overload

  my @files = files_with_overload;

Finds files containing overloaded XS/Perl subroutines

=cut

sub files_with_overload {
  my @files;

  my $wanted = sub {
    my $name = $File::Find::name;

    m/\.pm$/i && do {
      my $line;
      local *IN;

      open IN, "< $_" || warn "unable to open '$_'";
      while( defined( $line = <IN> ) ) {
        $line =~ m/Wx::_match/ && do {
          push @files, $name;
          return;
        };
      }
    };

    m/\.xsp?$/i && do {
      my $line;
      local *IN;

      open IN, "< $_" || warn "unable to open '$_'";
      while( defined( $line = <IN> ) ) {
        $line =~ m/wxPli_match_arguments|BEGIN_OVERLOAD\(\)/ && do {
          push @files, $name;
          return;
        };
      }
    };
  };

  find( $wanted, curdir );

  return @files;
}

sub pipe_stderr {
  my( $cmd ) = @_;
  my $pipe = File::Spec->catfile( 'script', 'pipe.pl' );

  if( -f $pipe ) {
    return qx{$^X $pipe $cmd};
  } else {
    # fix quoting later if necessary
    return qx[$^X -e "open STDERR, q{>&STDOUT}; exec q{$cmd}"];
  }
}

1;

# local variables:
# mode: cperl
# end: