Skip to content

Commit ba50127

Browse files
t4imest31
authored andcommittedAug 20, 2016
Move generation from settingtypes out of dlg_settings_advanced
Avoids unreachable code linter warning by moving generation code (of minetest.conf.example and settings_translation_file.cpp) out of dlg_settings_advanced. Due to passing the settings, also it avoids reading the settings file twice. Instead of activating the code by changing the active if-clauses, its activation is now done by uncommenting the loadfile() statement.
1 parent a496224 commit ba50127

File tree

2 files changed

+101
-99
lines changed

2 files changed

+101
-99
lines changed
 

Diff for: ‎builtin/mainmenu/dlg_settings_advanced.lua

+2-99
Original file line numberDiff line numberDiff line change
@@ -659,102 +659,5 @@ function create_adv_settings_dlg()
659659
return dlg
660660
end
661661

662-
local function create_minetest_conf_example()
663-
local result = "# This file contains a list of all available settings and their default value for minetest.conf\n" ..
664-
"\n" ..
665-
"# By default, all the settings are commented and not functional.\n" ..
666-
"# Uncomment settings by removing the preceding #.\n" ..
667-
"\n" ..
668-
"# minetest.conf is read by default from:\n" ..
669-
"# ../minetest.conf\n" ..
670-
"# ../../minetest.conf\n" ..
671-
"# Any other path can be chosen by passing the path as a parameter\n" ..
672-
"# to the program, eg. \"minetest.exe --config ../minetest.conf.example\".\n" ..
673-
"\n" ..
674-
"# Further documentation:\n" ..
675-
"# http://wiki.minetest.net/\n" ..
676-
"\n"
677-
678-
local settings = parse_config_file(true, false)
679-
for _, entry in ipairs(settings) do
680-
if entry.type == "category" then
681-
if entry.level == 0 then
682-
result = result .. "#\n# " .. entry.name .. "\n#\n\n"
683-
else
684-
for i = 1, entry.level do
685-
result = result .. "#"
686-
end
687-
result = result .. "# " .. entry.name .. "\n\n"
688-
end
689-
else
690-
if entry.comment ~= "" then
691-
for _, comment_line in ipairs(entry.comment:split("\n", true)) do
692-
result = result .."# " .. comment_line .. "\n"
693-
end
694-
end
695-
result = result .. "# type: " .. entry.type
696-
if entry.min then
697-
result = result .. " min: " .. entry.min
698-
end
699-
if entry.max then
700-
result = result .. " max: " .. entry.max
701-
end
702-
if entry.values then
703-
result = result .. " values: " .. table.concat(entry.values, ", ")
704-
end
705-
if entry.possible then
706-
result = result .. " possible values: " .. entry.possible:gsub(",", ", ")
707-
end
708-
result = result .. "\n"
709-
local append = ""
710-
if entry.default ~= "" then
711-
append = " " .. entry.default
712-
end
713-
result = result .. "# " .. entry.name .. " =" .. append .. "\n\n"
714-
end
715-
end
716-
return result
717-
end
718-
719-
local function create_translation_file()
720-
local result = "// This file is automatically generated\n" ..
721-
"// It conatins a bunch of fake gettext calls, to tell xgettext about the strings in config files\n" ..
722-
"// To update it, refer to the bottom of builtin/mainmenu/tab_settings.lua\n\n" ..
723-
"fake_function() {\n"
724-
725-
local settings = parse_config_file(true, false)
726-
for _, entry in ipairs(settings) do
727-
if entry.type == "category" then
728-
local name_escaped = entry.name:gsub("\"", "\\\"")
729-
result = result .. "\tgettext(\"" .. name_escaped .. "\");\n"
730-
else
731-
if entry.readable_name then
732-
local readable_name_escaped = entry.readable_name:gsub("\"", "\\\"")
733-
result = result .. "\tgettext(\"" .. readable_name_escaped .. "\");\n"
734-
end
735-
if entry.comment ~= "" then
736-
local comment_escaped = entry.comment:gsub("\n", "\\n")
737-
comment_escaped = comment_escaped:gsub("\"", "\\\"")
738-
result = result .. "\tgettext(\"" .. comment_escaped .. "\");\n"
739-
end
740-
end
741-
end
742-
result = result .. "}\n"
743-
return result
744-
end
745-
746-
if false then
747-
local file = io.open("minetest.conf.example", "w")
748-
if file then
749-
file:write(create_minetest_conf_example())
750-
file:close()
751-
end
752-
end
753-
754-
if false then
755-
local file = io.open("src/settings_translation_file.cpp", "w")
756-
if file then
757-
file:write(create_translation_file())
758-
file:close()
759-
end
760-
end
662+
-- generate minetest.conf.example and settings_translation_file.cpp:
663+
--assert(loadfile(core.get_mainmenu_path()..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false))

Diff for: ‎builtin/mainmenu/generate_from_settingtypes.lua

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
local settings = ...
2+
3+
local function create_minetest_conf_example()
4+
local result = "# This file contains a list of all available settings and their default value for minetest.conf\n" ..
5+
"\n" ..
6+
"# By default, all the settings are commented and not functional.\n" ..
7+
"# Uncomment settings by removing the preceding #.\n" ..
8+
"\n" ..
9+
"# minetest.conf is read by default from:\n" ..
10+
"# ../minetest.conf\n" ..
11+
"# ../../minetest.conf\n" ..
12+
"# Any other path can be chosen by passing the path as a parameter\n" ..
13+
"# to the program, eg. \"minetest.exe --config ../minetest.conf.example\".\n" ..
14+
"\n" ..
15+
"# Further documentation:\n" ..
16+
"# http://wiki.minetest.net/\n" ..
17+
"\n"
18+
19+
for _, entry in ipairs(settings) do
20+
if entry.type == "category" then
21+
if entry.level == 0 then
22+
result = result .. "#\n# " .. entry.name .. "\n#\n\n"
23+
else
24+
for i = 1, entry.level do
25+
result = result .. "#"
26+
end
27+
result = result .. "# " .. entry.name .. "\n\n"
28+
end
29+
else
30+
if entry.comment ~= "" then
31+
for _, comment_line in ipairs(entry.comment:split("\n", true)) do
32+
result = result .."# " .. comment_line .. "\n"
33+
end
34+
end
35+
result = result .. "# type: " .. entry.type
36+
if entry.min then
37+
result = result .. " min: " .. entry.min
38+
end
39+
if entry.max then
40+
result = result .. " max: " .. entry.max
41+
end
42+
if entry.values then
43+
result = result .. " values: " .. table.concat(entry.values, ", ")
44+
end
45+
if entry.possible then
46+
result = result .. " possible values: " .. entry.possible:gsub(",", ", ")
47+
end
48+
result = result .. "\n"
49+
local append = ""
50+
if entry.default ~= "" then
51+
append = " " .. entry.default
52+
end
53+
result = result .. "# " .. entry.name .. " =" .. append .. "\n\n"
54+
end
55+
end
56+
return result
57+
end
58+
59+
local function create_translation_file()
60+
local result = "// This file is automatically generated\n" ..
61+
"// It conatins a bunch of fake gettext calls, to tell xgettext about the strings in config files\n" ..
62+
"// To update it, refer to the bottom of builtin/mainmenu/tab_settings.lua\n\n" ..
63+
"fake_function() {\n"
64+
65+
for _, entry in ipairs(settings) do
66+
if entry.type == "category" then
67+
local name_escaped = entry.name:gsub("\"", "\\\"")
68+
result = result .. "\tgettext(\"" .. name_escaped .. "\");\n"
69+
else
70+
if entry.readable_name then
71+
local readable_name_escaped = entry.readable_name:gsub("\"", "\\\"")
72+
result = result .. "\tgettext(\"" .. readable_name_escaped .. "\");\n"
73+
end
74+
if entry.comment ~= "" then
75+
local comment_escaped = entry.comment:gsub("\n", "\\n")
76+
comment_escaped = comment_escaped:gsub("\"", "\\\"")
77+
result = result .. "\tgettext(\"" .. comment_escaped .. "\");\n"
78+
end
79+
end
80+
end
81+
result = result .. "}\n"
82+
return result
83+
end
84+
85+
if false then
86+
local file = io.open("minetest.conf.example", "w")
87+
if file then
88+
file:write(create_minetest_conf_example())
89+
file:close()
90+
end
91+
end
92+
93+
if false then
94+
local file = io.open("src/settings_translation_file.cpp", "w")
95+
if file then
96+
file:write(create_translation_file())
97+
file:close()
98+
end
99+
end

0 commit comments

Comments
 (0)
Please sign in to comment.