File: check-linklist.lua

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (58 lines) | stat: -rwxr-xr-x 1,157 bytes parent folder | download
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
#! /usr/bin/env lua
-- vim:sw=4:sts=4
-- Read a spec.lua file, extract the linklist, and search through the
-- .c source files of the module to verify that all these functions
-- are actually used.
--
-- Note that functions not directly being called from the source files may
-- still be used through macros.
--

require "script.util"
require "lfs"

function read_source(modname)
    local dir, ar, s, f

    dir = "src/" .. modname
    ar = {}

    for name in lfs.dir(dir) do
	if string.sub(name, -2) == ".c" then
	    f = io.open(dir .. "/" .. name)
	    s = f:read"*a"
	    f:close()
	    ar[#ar + 1] = s
	end
    end

    return table.concat(ar)
end

function main()
    if #arg ~= 1 then
	print("Usage: module name")
	os.exit(1)
    end

    fname = string.format("src/%s/spec.lua", arg[1])
    spec = load_spec(fname)
    if not spec.linklist then
	print("This module doesn't define a linklist.")
	os.exit(0)
    end

    code = read_source(arg[1])

    for _, func in ipairs(spec.linklist) do
	if type(func) == "table" then
	    func = func[1]
	end
	if not string.find(code, func) then
	    print("Unused function:", func)
	end
    end
end

main()