diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings.c | 148 |
1 files changed, 147 insertions, 1 deletions
diff --git a/apps/settings.c b/apps/settings.c index a627cce65b..bc6f066e22 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -19,6 +19,12 @@ | |||
19 | * KIND, either express or implied. | 19 | * KIND, either express or implied. |
20 | * | 20 | * |
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | /* Define LOGF_ENABLE to enable logf output in this file */ | ||
23 | /*#define LOGF_ENABLE*/ | ||
24 | /*Define DEBUG_AVAIL_SETTINGS to get a list of all available settings and flags */ | ||
25 | /*#define DEBUG_AVAIL_SETTINGS*/ /* Needs (LOGF_ENABLE) */ | ||
26 | #include "logf.h" | ||
27 | |||
22 | #include <stdio.h> | 28 | #include <stdio.h> |
23 | #include <stddef.h> | 29 | #include <stddef.h> |
24 | #include <stdlib.h> | 30 | #include <stdlib.h> |
@@ -102,6 +108,12 @@ struct system_status global_status; | |||
102 | #else /* creates temp files on save, renames next load, saves old file if desired */ | 108 | #else /* creates temp files on save, renames next load, saves old file if desired */ |
103 | #define CONFIGFILE_TEMP CONFIGFILE".new" | 109 | #define CONFIGFILE_TEMP CONFIGFILE".new" |
104 | #define NVRAM_FILE_TEMP NVRAM_FILE".new" | 110 | #define NVRAM_FILE_TEMP NVRAM_FILE".new" |
111 | |||
112 | #ifdef LOGF_ENABLE | ||
113 | static char *debug_get_flags(uint32_t flags); | ||
114 | #endif | ||
115 | static void debug_available_settings(void); | ||
116 | |||
105 | static void rename_temp_file(const char *tempfile, | 117 | static void rename_temp_file(const char *tempfile, |
106 | const char *file, | 118 | const char *file, |
107 | const char *oldfile) | 119 | const char *oldfile) |
@@ -228,6 +240,9 @@ static void write_nvram_data(void) | |||
228 | */ | 240 | */ |
229 | void settings_load(int which) | 241 | void settings_load(int which) |
230 | { | 242 | { |
243 | logf("\r\n%s()\r\n", __func__); | ||
244 | debug_available_settings(); | ||
245 | |||
231 | if (which & SETTINGS_RTC) | 246 | if (which & SETTINGS_RTC) |
232 | read_nvram_data(); | 247 | read_nvram_data(); |
233 | if (which & SETTINGS_HD) | 248 | if (which & SETTINGS_HD) |
@@ -318,6 +333,7 @@ bool copy_filename_setting(char *buf, size_t buflen, const char *input, | |||
318 | 333 | ||
319 | bool settings_load_config(const char* file, bool apply) | 334 | bool settings_load_config(const char* file, bool apply) |
320 | { | 335 | { |
336 | logf("%s()\r\n", __func__); | ||
321 | const struct settings_list *setting; | 337 | const struct settings_list *setting; |
322 | int index; | 338 | int index; |
323 | int fd; | 339 | int fd; |
@@ -346,17 +362,22 @@ bool settings_load_config(const char* file, bool apply) | |||
346 | { | 362 | { |
347 | case F_T_CUSTOM: | 363 | case F_T_CUSTOM: |
348 | setting->custom_setting->load_from_cfg(setting->setting, value); | 364 | setting->custom_setting->load_from_cfg(setting->setting, value); |
365 | logf("Val: %s\r\n",value); | ||
349 | break; | 366 | break; |
350 | case F_T_INT: | 367 | case F_T_INT: |
351 | case F_T_UINT: | 368 | case F_T_UINT: |
352 | #ifdef HAVE_LCD_COLOR | 369 | #ifdef HAVE_LCD_COLOR |
353 | if (setting->flags & F_RGB) | 370 | if (setting->flags & F_RGB) |
371 | { | ||
354 | hex_to_rgb(value, (int*)setting->setting); | 372 | hex_to_rgb(value, (int*)setting->setting); |
373 | logf("Val: %s\r\n", value); | ||
374 | } | ||
355 | else | 375 | else |
356 | #endif | 376 | #endif |
357 | if (setting->cfg_vals == NULL) | 377 | if (setting->cfg_vals == NULL) |
358 | { | 378 | { |
359 | *(int*)setting->setting = atoi(value); | 379 | *(int*)setting->setting = atoi(value); |
380 | logf("Val: %s\r\n",value); | ||
360 | } | 381 | } |
361 | else | 382 | else |
362 | { | 383 | { |
@@ -368,10 +389,17 @@ bool settings_load_config(const char* file, bool apply) | |||
368 | *v = setting->table_setting->values[temp]; | 389 | *v = setting->table_setting->values[temp]; |
369 | else | 390 | else |
370 | *v = temp; | 391 | *v = temp; |
392 | logf("Val: %d\r\n", *v); | ||
371 | } | 393 | } |
372 | else if (setting->flags & F_ALLOW_ARBITRARY_VALS) | 394 | else if (setting->flags & F_ALLOW_ARBITRARY_VALS) |
373 | { | 395 | { |
374 | *v = atoi(value); | 396 | *v = atoi(value); |
397 | logf("Val: %s\r\n",value); | ||
398 | } | ||
399 | else | ||
400 | { | ||
401 | logf("Error: %s: Not Found! [%s]\r\n", | ||
402 | setting->cfg_name, value); | ||
375 | } | 403 | } |
376 | } | 404 | } |
377 | break; | 405 | break; |
@@ -379,9 +407,14 @@ bool settings_load_config(const char* file, bool apply) | |||
379 | { | 407 | { |
380 | int temp; | 408 | int temp; |
381 | if (cfg_string_to_int(setting, &temp, value)) | 409 | if (cfg_string_to_int(setting, &temp, value)) |
410 | { | ||
382 | *(bool*)setting->setting = !!temp; | 411 | *(bool*)setting->setting = !!temp; |
412 | logf("Val: %s\r\n", value); | ||
413 | } | ||
383 | if (setting->bool_setting->option_callback) | 414 | if (setting->bool_setting->option_callback) |
415 | { | ||
384 | setting->bool_setting->option_callback(!!temp); | 416 | setting->bool_setting->option_callback(!!temp); |
417 | } | ||
385 | break; | 418 | break; |
386 | } | 419 | } |
387 | /* these can be plain text, filenames, or dirnames */ | 420 | /* these can be plain text, filenames, or dirnames */ |
@@ -391,6 +424,7 @@ bool settings_load_config(const char* file, bool apply) | |||
391 | const struct filename_setting *fs = setting->filename_setting; | 424 | const struct filename_setting *fs = setting->filename_setting; |
392 | copy_filename_setting((char*)setting->setting, | 425 | copy_filename_setting((char*)setting->setting, |
393 | fs->max_len, value, fs); | 426 | fs->max_len, value, fs); |
427 | logf("Val: %s\r\n", value); | ||
394 | break; | 428 | break; |
395 | } | 429 | } |
396 | } | 430 | } |
@@ -544,6 +578,7 @@ static bool is_changed(const struct settings_list *setting) | |||
544 | 578 | ||
545 | static bool settings_write_config(const char* filename, int options) | 579 | static bool settings_write_config(const char* filename, int options) |
546 | { | 580 | { |
581 | logf("%s\r\n", __func__); | ||
547 | int i; | 582 | int i; |
548 | int fd; | 583 | int fd; |
549 | char value[MAX_PATH]; | 584 | char value[MAX_PATH]; |
@@ -583,8 +618,9 @@ static bool settings_write_config(const char* filename, int options) | |||
583 | continue; | 618 | continue; |
584 | break; | 619 | break; |
585 | } | 620 | } |
586 | |||
587 | cfg_to_string(setting, value, MAX_PATH); | 621 | cfg_to_string(setting, value, MAX_PATH); |
622 | logf("Written: '%s: %s'\r\n",setting->cfg_name, value); | ||
623 | |||
588 | fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value); | 624 | fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value); |
589 | } /* for(...) */ | 625 | } /* for(...) */ |
590 | close(fd); | 626 | close(fd); |
@@ -631,6 +667,7 @@ void status_save(void) | |||
631 | 667 | ||
632 | int settings_save(void) | 668 | int settings_save(void) |
633 | { | 669 | { |
670 | logf("%s", __func__); | ||
634 | update_runtime(); | 671 | update_runtime(); |
635 | register_storage_idle_func(flush_config_block_callback); | 672 | register_storage_idle_func(flush_config_block_callback); |
636 | return 0; | 673 | return 0; |
@@ -772,6 +809,7 @@ void sound_settings_apply(void) | |||
772 | 809 | ||
773 | void settings_apply(bool read_disk) | 810 | void settings_apply(bool read_disk) |
774 | { | 811 | { |
812 | logf("%s", __func__); | ||
775 | int rc; | 813 | int rc; |
776 | CHART(">set_codepage"); | 814 | CHART(">set_codepage"); |
777 | set_codepage(global_settings.default_codepage); | 815 | set_codepage(global_settings.default_codepage); |
@@ -1114,18 +1152,22 @@ const struct settings_list* find_setting(const void* variable, int *id) | |||
1114 | } | 1152 | } |
1115 | return NULL; | 1153 | return NULL; |
1116 | } | 1154 | } |
1155 | |||
1117 | const struct settings_list* find_setting_by_cfgname(const char* name, int *id) | 1156 | const struct settings_list* find_setting_by_cfgname(const char* name, int *id) |
1118 | { | 1157 | { |
1119 | int i; | 1158 | int i; |
1159 | logf("Searching for Setting: '%s'",name); | ||
1120 | for (i=0; i<nb_settings; i++) | 1160 | for (i=0; i<nb_settings; i++) |
1121 | { | 1161 | { |
1122 | if (settings[i].cfg_name && | 1162 | if (settings[i].cfg_name && |
1123 | !strcasecmp(settings[i].cfg_name, name)) | 1163 | !strcasecmp(settings[i].cfg_name, name)) |
1124 | { | 1164 | { |
1165 | logf("Found, flags: %s", debug_get_flags(settings[i].flags)); | ||
1125 | if (id) *id = i; | 1166 | if (id) *id = i; |
1126 | return &settings[i]; | 1167 | return &settings[i]; |
1127 | } | 1168 | } |
1128 | } | 1169 | } |
1170 | logf("Setting: '%s' Not Found!",name); | ||
1129 | return NULL; | 1171 | return NULL; |
1130 | } | 1172 | } |
1131 | 1173 | ||
@@ -1282,3 +1324,107 @@ void set_file(const char* filename, char* setting, const int maxlen) | |||
1282 | strmemccpy(setting, fptr, len); | 1324 | strmemccpy(setting, fptr, len); |
1283 | settings_save(); | 1325 | settings_save(); |
1284 | } | 1326 | } |
1327 | |||
1328 | #ifdef LOGF_ENABLE | ||
1329 | static char *debug_get_flags(uint32_t flags) | ||
1330 | { | ||
1331 | static char buf[256] = {0}; | ||
1332 | uint32_t ftype = flags & F_T_MASK; /* the variable type for the setting */ | ||
1333 | flags &= ~F_T_MASK; | ||
1334 | switch (ftype) | ||
1335 | { | ||
1336 | case F_T_CUSTOM: | ||
1337 | strlcpy(buf, "[Type CUSTOM] ", sizeof(buf)); | ||
1338 | break; | ||
1339 | case F_T_INT: | ||
1340 | strlcpy(buf, "[Type INT] ", sizeof(buf)); | ||
1341 | break; | ||
1342 | case F_T_UINT: | ||
1343 | strlcpy(buf, "[Type UINT] ", sizeof(buf)); | ||
1344 | break; | ||
1345 | case F_T_BOOL: | ||
1346 | strlcpy(buf, "[Type BOOL] ", sizeof(buf)); | ||
1347 | break; | ||
1348 | case F_T_CHARPTR: | ||
1349 | strlcpy(buf, "[Type CHARPTR] ", sizeof(buf)); | ||
1350 | break; | ||
1351 | case F_T_UCHARPTR: | ||
1352 | strlcpy(buf, "[Type UCHARPTR] ", sizeof(buf)); | ||
1353 | break; | ||
1354 | } | ||
1355 | |||
1356 | #define SETTINGFLAGS(n) \ | ||
1357 | if(flags & n) { \ | ||
1358 | flags &= ~n; \ | ||
1359 | strlcat(buf, "["#n"]", sizeof(buf));} | ||
1360 | |||
1361 | SETTINGFLAGS(F_T_SOUND); | ||
1362 | SETTINGFLAGS(F_BOOL_SETTING); | ||
1363 | SETTINGFLAGS(F_RGB); | ||
1364 | SETTINGFLAGS(F_FILENAME); | ||
1365 | SETTINGFLAGS(F_INT_SETTING); | ||
1366 | SETTINGFLAGS(F_CHOICE_SETTING); | ||
1367 | SETTINGFLAGS(F_CHOICETALKS); | ||
1368 | SETTINGFLAGS(F_TABLE_SETTING); | ||
1369 | SETTINGFLAGS(F_ALLOW_ARBITRARY_VALS); | ||
1370 | SETTINGFLAGS(F_CB_ON_SELECT_ONLY); | ||
1371 | SETTINGFLAGS(F_MIN_ISFUNC); | ||
1372 | SETTINGFLAGS(F_MAX_ISFUNC); | ||
1373 | SETTINGFLAGS(F_DEF_ISFUNC); | ||
1374 | SETTINGFLAGS(F_CUSTOM_SETTING); | ||
1375 | SETTINGFLAGS(F_TIME_SETTING); | ||
1376 | SETTINGFLAGS(F_THEMESETTING); | ||
1377 | SETTINGFLAGS(F_RECSETTING); | ||
1378 | SETTINGFLAGS(F_EQSETTING); | ||
1379 | SETTINGFLAGS(F_SOUNDSETTING); | ||
1380 | SETTINGFLAGS(F_TEMPVAR); | ||
1381 | SETTINGFLAGS(F_PADTITLE); | ||
1382 | SETTINGFLAGS(F_NO_WRAP); | ||
1383 | SETTINGFLAGS(F_BANFROMQS); | ||
1384 | SETTINGFLAGS(F_DEPRECATED); | ||
1385 | #undef SETTINGFLAGS | ||
1386 | |||
1387 | if (flags & F_NVRAM_BYTES_MASK) | ||
1388 | { | ||
1389 | flags &= ~F_NVRAM_BYTES_MASK; | ||
1390 | strlcat(buf, "[NVRAM]", sizeof(buf)); | ||
1391 | } | ||
1392 | /* anything left is unknown */ | ||
1393 | if (flags) | ||
1394 | { | ||
1395 | strlcat(buf, "[UNKNOWN FLAGS]", sizeof(buf)); | ||
1396 | size_t len = strlen(buf); | ||
1397 | if (len < sizeof(buf)) | ||
1398 | snprintf(buf + len, sizeof(buf) - len - 1, "[%x]", flags); | ||
1399 | } | ||
1400 | return buf; | ||
1401 | } | ||
1402 | #endif | ||
1403 | static void debug_available_settings(void) | ||
1404 | { | ||
1405 | #if defined(DEBUG_AVAIL_SETTINGS) && defined(LOGF_ENABLE) | ||
1406 | logf("\r\nAvailable Settings:"); | ||
1407 | for (int i=0; i<nb_settings; i++) | ||
1408 | { | ||
1409 | uint32_t flags = settings[i].flags; | ||
1410 | const char *name; | ||
1411 | if (settings[i].cfg_name) | ||
1412 | name = settings[i].cfg_name; | ||
1413 | else if (settings[i].RESERVED == NULL) | ||
1414 | { | ||
1415 | name = "SYS (NVRAM?)"; | ||
1416 | if (flags & F_NVRAM_BYTES_MASK) | ||
1417 | { | ||
1418 | flags &= ~F_NVRAM_BYTES_MASK; | ||
1419 | flags |= 0x80000; /* unused by other flags */ | ||
1420 | } | ||
1421 | } | ||
1422 | else | ||
1423 | { | ||
1424 | name = "?? UNKNOWN NAME ?? "; | ||
1425 | } | ||
1426 | logf("'%s' flags: %s",name, debug_get_flags(flags)); | ||
1427 | } | ||
1428 | logf("End Available Settings\r\n"); | ||
1429 | #endif | ||
1430 | } | ||