summaryrefslogtreecommitdiff
path: root/example/checktools/checktools.lua
blob: 45223b4530333c780543c6929bdd19354846ef1b (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/local/bin/luajit
local flag = 0      -- 0: init;1: script;2: data 
local script_num = 0
local script_list = {}
local data_num = 0
local data_list = {}
TSG = {}
local conf_file = "./checktools.conf"

if arg[1] then
    if arg[1] == "-h" then
        print("usage: checktools.lua [conf] default conf is './checktools.conf'")
    else 
        conf_file = arg[1]
    end
end

local function file_is_exit(path)
    local file = io.open(path)
    if not file then
        return false
    end
    io.close(file)
    return true
end

if not file_is_exit(conf_file) then
    print("error: conf file: ".. conf_file .." not exits.")
    return false
end

for line in io.lines(conf_file) do
    if string.byte(line, 1) == '#' then
        --do nothing
    elseif string.len(line) == 0 then
        --do nothing
    elseif line == "[script]" then
        flag = 1
    elseif line == "[data]" then
        flag = 2
    else
        if flag == 1 then
           script_num = script_num + 1
           script_list[script_num] = line 
       elseif flag == 2 then
           data_num = data_num + 1
           local file = io.open(line, "r")
           if not file then
               print("error: ".. file .." not exits")
           end
           io.input(file)
           data_list[data_num] = io.read("*a")
           io.close(file)
       end
    end
end

for _, script in ipairs(script_list) do
    if not file_is_exit(script) then
        print("error: script: ".. script .." not exits.")
        return false
    end
    for _, data in ipairs(data_list) do
        TSG.data = data
        dofile(script)
    end
end