24 #include "config_auto.h"
27 #ifndef GRAPHICS_DISABLED
44 #define VARDIR "configs/"
45 #define MAX_ITEMS_IN_SUBMENU 30
51 static std::map<int, ParamContent*> vcMap;
52 static int nrParams = 0;
53 static int writeCommands[2];
97 void ParamsEditor::GetFirstWords(
102 int full_length = strlen(s);
104 const char *next_word = s;
106 while ((n > 0) && reqd_len < full_length) {
107 reqd_len += strcspn(next_word,
"_") + 1;
108 next_word += reqd_len;
111 strncpy(t, s, reqd_len);
122 return "ERROR: ParamContent::GetName()";
163 std::stringstream stream(val);
165 stream.imbue(std::locale::classic());
176 void ParamsEditor::GetPrefixes(
const char* s,
STRING* level_one,
179 std::unique_ptr<char[]> p(
new char[1024]);
180 GetFirstWords(s, 1, p.get());
181 *level_one = p.get();
182 GetFirstWords(s, 2, p.get());
183 *level_two = p.get();
184 GetFirstWords(s, 3, p.get());
185 *level_three = p.get();
190 const ParamContent* one = *static_cast<const ParamContent* const*>(v1);
191 const ParamContent* two = *static_cast<const ParamContent* const*>(v2);
200 ParamContent_LIST vclist;
201 ParamContent_IT vc_it(&vclist);
204 std::map<const char*, int> amount;
208 int num_iterations = (tess->
params() ==
nullptr) ? 1 : 2;
209 for (v = 0; v < num_iterations; ++v) {
211 for (i = 0; i < vec->
int_params.size(); ++i) {
226 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
232 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
233 amount[tag.
c_str()]++;
234 amount[tag2.c_str()]++;
235 amount[tag3.
c_str()]++;
243 vc_it.move_to_first();
244 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
249 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
251 if (amount[tag.
c_str()] == 1) {
257 (amount[tag2.c_str()] <= 1)) {
275 WriteParams(param,
false);
276 }
else if (sve->
command_id == writeCommands[1]) {
277 WriteParams(param,
true);
294 const char* name =
"ParamEditorMAIN";
295 sv =
new ScrollView(name, 1, 1, 200, 200, 300, 200);
303 SVMenuNode* svMenuRoot = BuildListOfAllLeaves(tess);
308 paramfile +=
"edited";
312 writeCommands[0] = nrParams+1;
313 std_menu->
AddChild(
"All Parameters", writeCommands[0],
314 paramfile.
c_str(),
"Config file name?");
316 writeCommands[1] = nrParams+2;
317 std_menu->
AddChild (
"changed_ Parameters Only", writeCommands[1],
318 paramfile.
c_str(),
"Config file name?");
325 void ParamsEditor::WriteParams(
char *filename,
330 if ((fp = fopen (filename,
"rb")) !=
nullptr) {
332 sprintf (msg_str,
"Overwrite file " "%s" "? (Y/N)", filename);
340 fp = fopen (filename,
"wb");
343 "Can't write to file "
349 for (
auto& iter : vcMap) {
352 fprintf(fp,
"%-25s %-12s # %s\n",
358 #endif // GRAPHICS_DISABLED