/* Copyright (C) 2015-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4apref.ctr */ /** @file dk4apref.c The dk4apref module. */ #line 9 "dk4apref.ctr" #include "dk4conf.h" #include "dk4types.h" #include "dk4app.h" #include "dk4pref.h" #include "dk4strd.h" #include "dk4appi.c" #include "dk4mem.h" #include "dk4enc.h" #if DK4_HAVE_ASSERT_H #ifndef ASSERT_H_INCLUDED #include #define ASSERT_H_INCLUDED 1 #endif #endif #line 28 "dk4apref.ctr" /** Names of system preferences to process immediately. */ static const dkChar * const dk4apref_names[] = { /* 0 */ dkT("ui.language"), /* 1 */ dkT("ui.region"), /* 2 */ dkT("log.stderr.level"), /* 3 */ dkT("log.file.level"), /* 4 */ dkT("log.file.keep"), /* 5 */ dkT("input.encoding"), /* 6 */ dkT("input.file.encoding"), /* 7 */ dkT("log.stderr.time"), /* 8 */ dkT("log.file.time"), /* 9 */ dkT("input.encoding.stdin"), /* 10 */ dkT("ui.lang"), NULL #line 77 "dk4apref.ctr" }; /** Log level names. */ static const dkChar * const dk4apref_log_level_names[] = { /* 0 */ dkT("none"), /* 1 */ dkT("panic"), /* 2 */ dkT("fatal"), /* 3 */ dkT("error"), /* 4 */ dkT("warning"), /* 5 */ dkT("info"), /* 6 */ dkT("progress"), /* 7 */ dkT("debug"), /* 8 */ dkT("ignore"), NULL #line 95 "dk4apref.ctr" }; void dk4app_pref_apply( dk4_app_t *app, dk4_app_error_t *ae, const dkChar *pn, const dkChar *pv ) { dkChar buf[64]; dkChar *newval; int pi; int ll; int bom; #line 113 "dk4apref.ctr" #if DK4_USE_ASSERT assert(NULL != app); assert(NULL != pn); #endif if ((NULL != app) && (NULL != ae) && (NULL != pn) && (NULL != pv)) { pi = dk4str_array_index(dk4apref_names, pn, 1); if (-1 < pi) { switch (pi) { case 0: { #line 122 "dk4apref.ctr" 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: { #line 131 "dk4apref.ctr" 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: { #line 140 "dk4apref.ctr" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_stderr = ll; } } break; case 3: { #line 146 "dk4apref.ctr" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_file = ll; } } break; case 4: { #line 152 "dk4apref.ctr" ll = dk4str_array_index(dk4apref_log_level_names, pv, 0); if (-1 < ll) { app->ll_file_keep = ll; } } break; case 5: case 9: { #line 158 "dk4apref.ctr" ll = app->enc_in_std; bom = 0; if (dk4enc_find(&ll, &bom, pv, NULL)) { app->enc_in_std = ll; } } break; case 6: { #line 165 "dk4apref.ctr" ll = app->enc_in_file; bom = 0; if (dk4enc_find(&ll, &bom, pv, NULL)) { app->enc_in_file = ll; } } break; case 7: { #line 172 "dk4apref.ctr" if (dk4str_is_on(pv)) { app->log_stderr_time = 1; } else { app->log_stderr_time = 0; } } break; case 8: { #line 179 "dk4apref.ctr" if (dk4str_is_on(pv)) { app->log_file_time = 1; } else { app->log_file_time = 0; } } break; case 10: { #line 186 "dk4apref.ctr" if (NULL != pv) { if (0 != dk4str_cpy_s(buf, DK4_SIZEOF(buf,dkChar), pv, NULL)) { dkChar *plang; dkChar *preg; dkChar *nlang; dkChar *nreg; /* Remove encoding stuff */ plang = dk4str_chr(buf, dkT('.')); if (NULL != plang) { *plang = dkT('\0'); } plang = dk4str_start(buf, 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; } } } } } else { /* ERROR: Buffer too small */ if (0 == ae->error_found) { ae->error_found = E_OPTION_TOO_LONG; } } } } break; } } } #line 228 "dk4apref.ctr" }