1
#!/usr/bin/ruby
2
3
puts "File: #{$*[0]}"
4
5
includes = {}
6
7
File.readlines($*[0]).each do |line|
8
    incre = Regexp.new('#include <((K|Q)[a-zA-z\d]*)>')
9
    incmatch = incre.match(line)
10
    if incmatch and not incmatch[1] == "QtDebug" and not incmatch[1] == "KLocale"
11
        puts "Match: #{incmatch[1]}"
12
        includes[incmatch[1]] = 0
13
    else
14
        incre2 = Regexp.new('#include <.*/((K|Q).*)>')
15
        incmatch2 = incre2.match(line)
16
        if incmatch2
17
            puts "Match2: #{incmatch2[1]}"
18
            includes[incmatch2[1]] = 0
19
        else
20
            includes.each_key do |kmatch|
21
                linere = Regexp.new(kmatch.to_s)
22
                linematch = linere.match(line)
23
                if linematch
24
                    includes[kmatch] = includes[kmatch] + 1
25
                end
26
            end
27
        end
28
    end
29
end
30
31
includes.each_key do |key|
32
    puts "Include #{key} count: #{includes[key].to_s}"
33
end
34
35
#puts "Fixing..."
36
37
if not includes.has_value?(0)
38
    exit
39
end
40
41
puts "Making changes in #{$*}..."
42
puts
43
44
includes.delete_if {|key, value| value > 0}
45
46
thefile = File.readlines($*[0])
47
48
newfile = Array.new
49
50
thefile.each do |line|
51
    filere = Regexp.new('#include <((K|Q).*)>')
52
    filematch = filere.match(line)
53
    if filematch
54
        if not includes.has_key?(filematch[1])
55
            newfile.push(line)
56
        end
57
    else
58
        filere = Regexp.new('#include <.*/((K|Q).*)>')
59
        filematch = filere.match(line)
60
        if filematch
61
            if not includes.has_key?(filematch[1])
62
                newfile.push(line)
63
            end
64
        else
65
            newfile.push(line)
66
        end
67
    end
68
end
69
70
if not newfile.last == "\n"
71
    newfile.push("\n")
72
end
73
74
File.open($*[0], File::CREAT | File::RDWR | File::TRUNC) do |file|
75
    file.puts newfile
76
end