summaryrefslogtreecommitdiff
path: root/c_conf_gen/consts.lua
blob: 87e183a5459760fb298bf4cad56897e23d2c9211 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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