blob: 8fcd27c7e8e8205dbf387d84dfcd1096604729d2 (
plain) (
blame)
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
69
70
|
#!/usr/bin/lua
TYPE_INT = 1
TYPE_STR = 2
TYPE_FILE = 3
consts = require('consts')
debug_mode = false
--check if version is supported
--why 5.3? utf8 and 64bit support
if (_VERSION ~= "Lua 5.3" ) then
print "Wrong lua versions"
print "Supported 5.3 only"
os.exit(1)
end
config_file = nil
output_file = nil
for k,v in ipairs( arg ) do
if v == "-c" then
config_file = arg[k+1]
elseif v == "-o" then
output_file = arg[k+1]
end
end
if (config_file == nil) or (output_file == nil) then
print("I need at leas one argument")
os.exit(1)
end
print("Config file " .. config_file .. " loaded")
cfg = require( config_file )
of = io.open( output_file .. ".c", "w" )
of:write( consts.implement_start( output_file .. ".h" ) )
--generate list of params
local getopt_p = ""
for k,v in ipairs( cfg.params_list ) do
if v ~= nil then
getopt_p = getopt_p .. v.shortopt
end
end
of:write( consts.getopt_start( getopt_p ) )
for k,v in ipairs( cfg.params_list ) do
if v.type == TYPE_INT then
of:write( consts.getopt_int( v ) )
elseif v.type == TYPE_STR then
of:write( consts.getopt_string( v ))
elseif v.type == TYPE_FILE then
of:write( consts.getopt_file( v ))
end
end
of:write( consts.getopt_end() )
of:write( consts.implement_end() )
of:close()
hf = io.open( output_file .. ".h", "w")
hf:write( consts.header_def_start( string.upper( cfg.project_name ) ) )
hf:write( consts.header_def_end( ) )
hf:close()
|