File: find-ids.rb

package info (click to toggle)
freecell-solver 3.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,332 kB
  • sloc: ansic: 29,493; perl: 8,911; xml: 5,162; python: 1,124; sh: 777; ruby: 358; cpp: 304; makefile: 150
file content (47 lines) | stat: -rw-r--r-- 1,403 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ignore_list = IO.read("scripts/ids-whitelist.txt").split(/\s+/)

ignore = Hash.new
for s in ignore_list do
    ignore[s] = 1
end

col = Hash.new
ARGV.each do |fn|
    if fn == "test_inline.c"
        next
    end
    File.open(fn, "r") do |file|
        line_num = 1
        while (l = file.gets)
            l.gsub!(/\/\*.*?\*\//m, "");
            l.gsub!(/(?:"([^\\]|\\.)*?")|(?:'[^'']+?')/m, " ");
            if (m = /\A(.*?)((?:\/\*)|\z)/m.match(l))
                before = m[1]
                open_comment = m[2]
                before.scan(/\b([a-zA-Z_]\w+)/).each{
                    |s| id = s[0]; col[id] ||= Array.new; col[id] << [fn, line_num]
                }
                if (open_comment == "/*")
                    found_line = false
                    while (l = file.gets)
                        line_num += 1
                        if (l.gsub!(/\A.*?\*\//, ""))
                            found_line = true
                            break
                        end
                    end
                    if (found_line)
                        redo
                    end
                else
                    line_num += 1
                end
            end
        end
    end
end

puts col.keys.select { |id| !ignore[id] }. \
    sort_by { |x| [col[x].length,x] }. \
    map{ |x| col[x].map { |arr| arr[0] + ":" + arr[1].to_s + ":" + x }}. \
    flatten