summaryrefslogtreecommitdiff
path: root/c_conf_gen/consts.lua
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-02-17 20:00:33 +0900
committerFreeArtMan <dos21h@gmail.com>2015-02-17 20:00:33 +0900
commit670e03997afca107abbfc61a61f89477a9f9ab82 (patch)
treedc6b31a985104ef1180859780379408e1abdb215 /c_conf_gen/consts.lua
parent35a421a727841319d5a998806924205ec6663bc2 (diff)
downloadcode-snippets-670e03997afca107abbfc61a61f89477a9f9ab82.tar.gz
code-snippets-670e03997afca107abbfc61a61f89477a9f9ab82.zip
c_conf_gen lua script that generates getopt code for fast argc,argv parsing. for lazy people
Diffstat (limited to 'c_conf_gen/consts.lua')
-rw-r--r--c_conf_gen/consts.lua121
1 files changed, 121 insertions, 0 deletions
diff --git a/c_conf_gen/consts.lua b/c_conf_gen/consts.lua
new file mode 100644
index 0000000..87e183a
--- /dev/null
+++ b/c_conf_gen/consts.lua
@@ -0,0 +1,121 @@
+local M = {}
+
+--
+local function header_def_start( name )
+ local s = ""
+ local name = string.upper( name )
+ s = s .. "#ifndef __" .. name .. "_H\n"
+ s = s .. "#define __" .. name .. "_H\n"
+ s = s .. "#include <unistd.h>\n"
+ s = s .. "void parse_args( int argc, char **argv, cmd_config *cmd );"
+ return s
+end
+M.header_def_start = header_def_start
+
+
+--
+local function header_def_end( )
+ local s = ""
+ s = s .. [[
+
+#endif
+]]
+ return s
+end
+M.header_def_end = header_def_end
+
+local function implement_start( headername )
+ local s = ""
+ s = s .. [[//auto-generated file no meaning to edit it
+#include "]].. headername .. [["
+]]
+ return s
+end
+M.implement_start = implement_start
+
+local function implement_end()
+ local s = ""
+ return s
+end
+M.implement_end = implement_end
+
+local function config_structure( values )
+ local s = ""
+ return s
+end
+M.config_structure = config_structure
+
+--make as separete function
+--just to make it easy to generate and then embed in code
+-- to not make name coalisions
+local function getopt_start( sup_args )
+ local s = ""
+ if sup_args == nil then
+ sup_args = "\"\""
+ end
+ s = s .. [[ void parse_args( int argc, char **argv, cmd_config *cmd )
+{
+ int c;
+ char *cvalue;
+
+ while ( (c = getopt(argc, argv, "]] .. sup_args .. [[" )) != -1 )
+ switch ( c )
+ {
+]]
+ return s
+end
+M.getopt_start = getopt_start
+
+local function getopt_end()
+ local s = ""
+ s = s .. [[
+ default:
+ printf("Unknown option\n");
+ }
+}
+]]
+ return s
+end
+M.getopt_end = getopt_end
+
+--
+local function getopt_int( param_config )
+ local s = ""
+ s = s .. [[
+ case ']] .. param_config.shortopt .. [[':{
+ ]] .. param_config.name .. [[ = atoi( optarg );
+ }
+]]
+ return s
+end
+M.getopt_int = getopt_int
+
+
+--
+local function getopt_string( param_config )
+ local s = ""
+ s = s .. [[
+ case ']] .. param_config.shortopt .. [[':{
+ ]] .. param_config.name .. [[ = atoi( optarg );
+ }
+]]
+ return s
+end
+M.getopt_string = getopt_string
+
+
+--
+local function getopt_file( param_config )
+ local s = ""
+ s = s .. [[
+ case ']] .. param_config.shortopt .. [[':{
+ ]] .. param_config.name .. [[ = atoi( optarg );
+ }
+]]
+ return s
+end
+M.getopt_file = getopt_file
+
+
+print("cconsts module loaded")
+return M \ No newline at end of file