diff options
Diffstat (limited to 'c_conf_gen/cconfgen.lua')
-rw-r--r-- | c_conf_gen/cconfgen.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/c_conf_gen/cconfgen.lua b/c_conf_gen/cconfgen.lua new file mode 100644 index 0000000..8fcd27c --- /dev/null +++ b/c_conf_gen/cconfgen.lua @@ -0,0 +1,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() + + |