%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% module #include "dk4conf.h" #include "dk4types.h" #include "dk4app.h" #include "dk4pref.h" #include "dk4strd.h" #include "dk4appi.c" #include "dk4mem.h" #include "dk4enc.h" $!trace-include /** Names of system preferences to process immediately. */ static const dkChar * const dk4apref_names[] = { $!string-table macro=dkT # # 0 Language # ui.language # # 1 Region # ui.region # # 2 Log level required for logging to stderr # log.stderr.level # # 3 Log level required for logging to file # log.file.level # # 4 Log level required to keep log level # log.file.keep # # 5 Input encoding expected on stdin # input.encoding # # 6 Input encoding expected when reading files. # input.file.encoding # # 7 8 Write timestamps before writing log messages. # log.stderr.time log.file.time # # 9 Alias for [5] # input.encoding.stdin # # 10 For backward compatibility # ui.lang $!end }; /** Log level names. */ static const dkChar * const dk4apref_log_level_names[] = { $!string-table macro=dkT none panic fatal error warning info progress debug ignore $!end }; void dk4app_pref_apply( dk4_app_t *app, dk4_app_error_t *ae, const dkChar *pn, const dkChar *pv ) { dkChar *newval; int pi; int ll; int bom; $? "+ dk4app_pref_apply" if ((NULL != app) && (NULL != ae) && (NULL != pn) && (NULL != pv)) { pi = dk4str_array_index(dk4apref_names, pn, 1); if (-1 < pi) { switch (pi) { case 0: { $? ". language" newval = dk4str_dup(pv, NULL); if (NULL != newval) { dk4mem_release(app->language); app->language = newval; } else { if (0 == ae->error_found) { ae->error_found = E_MEMORY; } } } break; case 1: { $? ". region" newval = dk4str_dup(pv, NULL); if (NULL != newval) { dk4mem_release(app->region); app->region = newval; } else { if (0 == ae->error_found) { ae->error_found = E_MEMORY; } } } break; case 2: { $? ". log level stderr" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_stderr = ll; } } break; case 3: { $? ". log level file" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_file = ll; } } break; case 4: { $? ". log keep file" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_file_keep = ll; } } break; case 5: case 9: { $? ". encoding stdin" ll = app->enc_in_std; bom = 0; if (dk4enc_find(&ll, &bom, pv, NULL)) { app->enc_in_std = ll; } } break; case 6: { $? ". encoding file" ll = app->enc_in_file; bom = 0; if (dk4enc_find(&ll, &bom, pv, NULL)) { app->enc_in_file = ll; } } break; case 7: { $? ". log stderr time" if (dk4str_is_on(pv)) { app->log_stderr_time = 1; } else { app->log_stderr_time = 0; } } break; case 8: { $? ". log file time" if (dk4str_is_on(pv)) { app->log_file_time = 1; } else { app->log_file_time = 0; } } break; case 10: { $? ". ui lang" if (NULL != pv) { dkChar *plang; dkChar *preg; dkChar *nlang; dkChar *nreg; /* Remove encoding stuff */ plang = dk4str_chr(pv, dkT('.')); if (NULL != plang) { *plang = dkT('\0'); } plang = dk4str_start(pv, NULL); if (NULL != plang) { preg = dk4str_chr(plang, dkT('_')); if (NULL != preg) { *(preg++) = dkT('\0'); preg = dk4str_start(preg, NULL); } nlang = dk4str_dup(plang, NULL); if (NULL != nlang) { dk4mem_release(app->language); app->language = nlang; } else { if (0 == ae->error_found) { ae->error_found = E_MEMORY; } } if (NULL != preg) { nreg = dk4str_dup(preg, NULL); if (NULL != nreg) { dk4mem_release(app->region); app->region = nreg; } else { if (0 == ae->error_found) { ae->error_found = E_MEMORY; } } } } } } break; } } } $? "- dk4app_pref_apply" }