summaryrefslogtreecommitdiff
path: root/scripts/check_config_h.rb
blob: 2619984e42562134b056fbe06b8167c784f33b69 (plain)
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
#!/usr/bin/env ruby
#
# This script verifies that every source includes config.h first.
# This is very important for consistent Large File Support.
#

def check_file(file)
    first = true
    file.each_line do |line|
        if line =~ /^\#include\s+(\S+)/ then
            if $1 == '"config.h"'
                unless first
                    puts "#{file.path}: config.h included too late"
                end
            else
                if first
                    puts "#{file.path}: config.h missing"
                end
            end
            first = false
        end
    end
end

def check_path(path)
    File.open(path) do |file|
        check_file(file)
    end
end

if ARGV.empty?
    Dir["src/*.c"].each do |path|
        check_path(path)
    end

    Dir["src/*/*.c"].each do |path|
        check_path(path)
    end

    Dir["test/*.c"].each do |path|
        check_path(path)
    end
else
    ARGV.each do |path|
        check_path(path)
    end
end