3 local tool_re = "^([%w%.]+)"
4 local test_re = "([%w%./_]+)"
5 local rc_re = "([%a]+)"
6 local time_re = "(%d+m%d+%.%d+s)"
7 local mark_re = "(%d+)"
8 local opt_re = "(gc%-%a+)$"
11 local fmt = "INSERT bench "..
12 "(result, compilation, test, time, timeuser, mark, options) "..
13 "VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s');\n"
15 -- build the huge regex
16 local re = tool_re .. sep .. test_re .. sep .. rc_re .. sep ..
17 time_re .. sep ..time_re .. sep ..time_re .. sep ..
18 mark_re .. sep .. opt_re
20 -- the string to cents of seconds function
22 local _,_,min,sec,cents = string.find(s,"(%d+)m(%d+)%.(%d+)s")
23 return min * 6000 + sec * 100 + cents
26 -- logfile to sql conversion
27 function log2sql(file)
34 local x,_,tool,test,rc,real,user,_,mark,opt = string.find(l,re)
37 error("regex failed on " .. l)
40 -- check the result is valid
41 if tool ~= "matitac" and tool ~= "matitac.opt" then
42 error("unknown tool " .. tool)
44 if tool == "matitac" then tool = "byte" else tool = "opt" end
46 if rc ~= "OK" and rc ~= "FAIL" then
47 error("unknown result " .. rc)
51 if opt ~= "gc-on" and opt ~= "gc-off" then
52 error("unknown option "..opt)
57 -- print the sql statement
58 table.insert(t,string.format(fmt,rc,tool,test,real,user,mark,opt))
60 return table.concat(t)
63 -- call the desired function and print the result
66 f = _G[fun] or error("no " .. fun .. " defined")
67 print(f(unpack(arg)) or "")