File: findsrc.rb

package info (click to toggle)
liblastfm 0.4.0~git20090710-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 808 kB
  • sloc: cpp: 7,614; ruby: 397; ansic: 108; makefile: 49; sh: 5
file content (33 lines) | stat: -rwxr-xr-x 1,034 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/ruby
require 'find'
require "#{File.dirname __FILE__}/platform"

def findsrc dir='.'
  excludes = ['.svn','.git','_include','tests','_build']
  case Platform::IMPL
    when :macosx then excludes<<'win'
    when :mswin, :cygwin then excludes<<'mac'
    else excludes<<'win'<<'mac'
  end
  
  Find.find dir do |path|
    next if path == dir # oddly neccessary
    path.sub! %r[^\./], ''
    if File.directory? path
      Find.prune if excludes.include? File.basename(path)
      #don't recurse into dirs with pro files in
      Find.prune if Dir["#{path}/*.pro"].length > 0 and $findsrc_prune_pro
    elsif File.file? path
      case Platform::IMPL
        when :macosx then next if /_mac\.cpp$/.match path
        when :mswin, :cygwin then next if /_win\.cpp$/.match path
      end
      yield( path, File.extname( path ) ) unless File.basename(path) == 'EXAMPLE.cpp'
    end
  end
end

if $0 == __FILE__
  extnames=ARGV.collect {|extname| ".#{extname}"}
  findsrc {|path,extname| puts path if extnames.include? extname}
end