static void parse_config (char *cfgfile) { char *line, *tline, *tmp; FILE *ptr; int len; if ((ptr = fopen (cfgfile, "r")) == NULL) { fprintf (stderr, "%s, can\'t open config file %s, using defaults\n", MyName, "file"); default_config (); return; } line = (char *) safemalloc (MAXLINELENGTH); len = strlen (MyName); while ((tline = fgets (line, MAXLINELENGTH, ptr)) != NULL) { while (isspace (*tline)) tline++; if ((*tline == '*') && (!mystrncasecmp (tline + 1, MyName, len))) { tline += len + 1; if (!mystrncasecmp (tline, "DeskName", 8)) { if (desk_count == 0) desk_names = malloc (sizeof (char *)); else desk_names = realloc (desk_names, sizeof (char *) + desk_count * sizeof (char *)); tmp = tline + 8 + 1; desk_names[desk_count] = (char *) malloc (strlen (tmp) + 1); strcpy (desk_names[desk_count], tmp); desk_count++; } if (!mystrncasecmp (tline, "Pages", 5)) { if (atoi (tline + 5) > 0) { LOG ("PAGING IS ON"); PAGES = True; } } } } if (desk_count == 0) default_config (); free (line); fclose (ptr); }
static errcode_t load_config (config_t * conf) { FILE * cf; char line [CONF_LINE_SIZE]; config_file_context_t context; context.filename = k_conf_file; context.linenum = 0; cf = fopen (context.filename, "r"); if (! cf) { LOG(PHIDGET_LOG_INFO, "mdns: Couldn't open nss_mdns configuration file %s, using default.", context.filename ); return default_config (conf); } while (fgets (line, CONF_LINE_SIZE, cf)) { int errcode; context.linenum++; errcode = process_config_line (conf, line, &context); if (errcode) { // Critical error, give up return errcode; } } return 0; }
static void test_no_search() { cmd_ln_t *config = default_config(); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(ps_start_utt(ps) < 0); ps_free(ps); cmd_ln_free_r(config); }
int s2e_clear (HTTP_INFO *info) { int chan; for (chan = 0; chan < S2E_CHAN_MAX; chan ++) { default_config (chan, &s2e_conf[chan]); write_config (chan, &s2e_conf[chan]); } return 0; }
int s2e_init (HTTP_INFO *info) { int chan; for (chan = 0; chan < S2E_CHAN_MAX; chan ++) { default_config (chan, &s2e_conf[chan]); read_config (chan, &s2e_conf[chan]); } return 0; }
static void test_default_jsgf() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-jsgf", DATADIR "/goforward.gram"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_lm(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_fsg(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
static void test_default_lm() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-lm", MODELDIR "/en-us/en-us.lm.dmp"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_fsg(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_lm(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
void init(int argc, char* argv[]) { // set global data default_config(); default_timeout(); default_systray(); memset(&server, 0, sizeof(Server_global)); #ifdef ENABLE_BATTERY default_battery(); #endif default_clock(); default_launcher(); default_taskbar(); default_tooltip(); default_panel(); // read options for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { DIE("Usage: tinto [-c] <config_file>\n"); } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { DIE("tinto version %s\n", VERSION_STRING); } else if (strcmp(argv[i], "-c") == 0) { if (++i < argc) config_path = strdup(argv[i]); } else if (strcmp(argv[i], "-s") == 0) { if (++i < argc) snapshot_path = strdup(argv[i]); } } // Set signal handler signal_pending = 0; struct sigaction sa = {.sa_handler = signal_handler}; struct sigaction sa_chld = {.sa_handler = SIG_DFL, .sa_flags = SA_NOCLDWAIT}; sigaction(SIGUSR1, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGCHLD, &sa_chld, NULL); // BSD does not support pselect(), therefore we have to use select and hope // that we do not // end up in a race condition there (see 'man select()' on a linux machine for // more information) // block all signals, such that no race conditions occur before pselect in our // main loop // sigset_t block_mask; // sigaddset(&block_mask, SIGINT); // sigaddset(&block_mask, SIGTERM); // sigaddset(&block_mask, SIGHUP); // sigaddset(&block_mask, SIGUSR1); // sigprocmask(SIG_BLOCK, &block_mask, 0); }
static void test_default_fsg() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-hmm", DATADIR "/tidigits/hmm"); cmd_ln_set_str_r(config, "-dict", DATADIR "/tidigits/lm/tidigits.dic"); cmd_ln_set_str_r(config, "-fsg", DATADIR "/tidigits/lm/tidigits.fsg"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_lm(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_fsg(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
static void test_default_lmctl() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-lmctl", DATADIR "/test.lmctl"); cmd_ln_set_str_r(config, "-lmname", "tidigits"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(ps_get_lm(ps, "tidigits")); TEST_ASSERT(ps_get_lm(ps, "turtle")); TEST_ASSERT(!ps_set_search(ps, "turtle")); TEST_ASSERT(!ps_set_search(ps, "tidigits")); ps_free(ps); cmd_ln_free_r(config); }
void load_config(t_data *data) { if ((CONFIG = bunny_malloc(sizeof(t_config))) == NULL) exit(1); if ((CONFIG->ini = bunny_load_ini("files/ini/config.ini")) != NULL) { data->config->fullscreen = my_getnbr((char *)BGF(CONFIG->ini, "config", "fullscreen", 0)); WIDTH = my_getnbr((char *)BGF(CONFIG->ini, "config", "width", 0)); HEIGHT = my_getnbr((char *)BGF(CONFIG->ini, "config", "height", 0)); VOLUME = my_getnbr((char *)BGF(CONFIG->ini, "config", "volume", 0)); CONFIG->fov = my_getnbr((char *)BGF(CONFIG->ini, "config", "fov", 0)); load_input(data); } else default_config(data); }
int s2e_start_chan (int chan) { int rc = 0; if (chan < 0 || chan >= S2E_CHAN_MAX) { return -1; } default_config (chan, &s2e_conf[chan]); read_config (chan, &s2e_conf[chan]); if (s2e_conf[chan].net_mode != 0) { rc = execute (commands[chan]); } return rc; }
static void test_set_search() { cmd_ln_t *config = default_config(); ps_decoder_t *ps = ps_init(config); ps_search_iter_t *itor; jsgf_t *jsgf = jsgf_parse_file(DATADIR "/goforward.gram", NULL); fsg_model_t *fsg = jsgf_build_fsg(jsgf, jsgf_get_rule(jsgf, "goforward.move"), ps->lmath, cmd_ln_int32_r(config, "-lw")); TEST_ASSERT(!ps_set_fsg(ps, "goforward", fsg)); fsg_model_free(fsg); TEST_ASSERT(!ps_set_jsgf_file(ps, "goforward_other", DATADIR "/goforward.gram")); ngram_model_t *lm = ngram_model_read(config, DATADIR "/tidigits/lm/tidigits.lm.dmp", NGRAM_AUTO, ps->lmath); TEST_ASSERT(!ps_set_lm(ps, "tidigits", lm)); ngram_model_free(lm); TEST_ASSERT(!ps_set_search(ps, "tidigits")); TEST_ASSERT(!ps_set_search(ps, "goforward")); itor = ps_search_iter(ps); TEST_EQUAL(0, strcmp("goforward_other", ps_search_iter_val(itor))); itor = ps_search_iter_next(itor); TEST_EQUAL(0, strcmp("tidigits", ps_search_iter_val(itor))); itor = ps_search_iter_next(itor); TEST_EQUAL(0, strcmp("goforward", ps_search_iter_val(itor))); itor = ps_search_iter_next(itor); TEST_EQUAL(0, strcmp("phone_loop", ps_search_iter_val(itor))); itor = ps_search_iter_next(itor); TEST_EQUAL(NULL, itor); TEST_ASSERT(!ps_start_utt(ps)); TEST_ASSERT(!ps_end_utt(ps)); ps_free(ps); cmd_ln_free_r(config); }
int parse_args(int argc, char* argv[], Arguments& args) { const struct option options[] = { {"apkdir", required_argument, 0, 'a'}, {"config", required_argument, 0, 'c'}, {"jarpath", required_argument, 0, 'j'}, {"proguard-config", required_argument, 0, 'p'}, {"seeds", required_argument, 0, 's'}, {"outdir", required_argument, 0, 'o'}, {"warn", required_argument, 0, 'w'}, {nullptr, 0, nullptr, 0}, }; args.out_dir = "."; int c; std::vector<std::string> json_values_from_command_line; std::vector<std::string> string_values_from_command_line; args.config = default_config(); const char* apk_dir = nullptr; while ((c = getopt_long( argc, argv, ":a:c:o:w:p:S::J::", &options[0], nullptr)) != -1) { switch (c) { case 'a': apk_dir = optarg; break; case 'c': if (!parse_config(optarg, args)) { return 0; } break; case 'o': args.out_dir = optarg; break; case 'j': args.jar_paths.emplace(optarg); TRACE(MAIN, 2, "Command line -j option: %s\n", optarg); break; case 'p': args.proguard_config = optarg; break; case 'w': g_warning_level = OptWarningLevel(strtol(optarg, nullptr, 10)); break; case 's': if (optarg) { args.seeds_filename = optarg; } break; case 'S': if (optarg) { std::string value(optarg); string_values_from_command_line.push_back(value); } break; case 'J': if (optarg) { std::string value(optarg); json_values_from_command_line.push_back(value); } break; case ':': fprintf(stderr, "ERROR: %s requires an argument\n", argv[optind - 1]); return 0; case '?': return 0; // getopt_long has printed an error default: abort(); } } // We add these values to the config at the end so that they will always // overwrite values read from the config file regardless of the order of // arguments if (apk_dir) { args.config["apk_dir"] = apk_dir; } for (auto& key_value : json_values_from_command_line) { if (!add_value_to_config(args.config, key_value, true)) { fprintf(stderr, "Error parsing value -J%s\n", key_value.c_str()); } } for (auto& key_value : string_values_from_command_line) { if (!add_value_to_config(args.config, key_value, false)) { fprintf(stderr, "Error parsing value -S%s\n", key_value.c_str()); } } return optind; }
void tinto_init (int argc, char *argv[]) { default_config (); default_timeout (); default_systray(); memset (&server, 0, sizeof (Server_global)); #ifdef ENABLE_BATTERY default_battery (); #endif // ENABLE_BATTERY default_clock (); default_launcher (); default_taskbar (); default_tooltip (); panel_default (); for (int i = 1; i < argc; ++i) { if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0) { tinto_usage (); } else if (strcmp (argv[i], "-v") == 0 || strcmp (argv[i], "--version") == 0) { MSG ("%s version %s\n", PROJECT_NAME, PROJECT_VERSION); exit (EXIT_SUCCESS); } else if (strcmp (argv[i], "-c") == 0 || strcmp (argv[i], "--config-file") == 0) { if (++i < argc) config_path = strdup (argv[i]); } else if (strcmp (argv[i], "-s") == 0 || strcmp (argv[i], "--panel-snapshot") == 0) { if (++i < argc) snapshot_path = strdup (argv[i]); } else { MSG ("Invalid argument!"); tinto_usage (); } } // Isn't this initialization redundant? Since `pending_signal' // is static and all? pending_signal = 0; struct sigaction sa = { .sa_handler = tinto_signal_handler }; struct sigaction sa_chld = { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDWAIT }; sigaction(SIGUSR1, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGCHLD, &sa_chld, NULL); // BSD does not support pselect(), therefore we have to use select and hope that we do not // end up in a race condition there (see 'man select()' on a linux machine for more information) // block all signals, such that no race conditions occur before pselect in our main loop // sigset_t block_mask; // sigaddset(&block_mask, SIGINT); // sigaddset(&block_mask, SIGTERM); // sigaddset(&block_mask, SIGHUP); // sigaddset(&block_mask, SIGUSR1); // sigprocmask(SIG_BLOCK, &block_mask, 0); tinto_init_x11 (); }
static void r_context_configure(void) { gboolean res = TRUE; GError *error = NULL; g_assert_nonnull(context); g_assert_false(context->busy); g_clear_pointer(&context->config, free_config); res = load_config(context->configpath, &context->config, &error); if (!res && error->domain==g_file_error_quark()) { g_debug("system config not found, using default values"); g_clear_error(&error); res = default_config(&context->config); } if (!res) { g_error("failed to initialize context: %s", error->message); g_clear_error(&error); } if (context->config->system_variant_type == R_CONFIG_SYS_VARIANT_DTB) { gchar *compatible = get_system_dtb_compatible(&error); if (!compatible) { g_warning("Failed to read dtb compatible: %s", error->message); g_clear_error(&error); } g_free(context->config->system_variant); context->config->system_variant = compatible; } else if (context->config->system_variant_type == R_CONFIG_SYS_VARIANT_FILE) { gchar *variant = get_variant_from_file(context->config->system_variant, &error); if (!variant) { g_warning("Failed to read system variant from file: %s", error->message); g_clear_error(&error); } g_free(context->config->system_variant); context->config->system_variant = variant; } if (context->config->systeminfo_handler && g_file_test(context->config->systeminfo_handler, G_FILE_TEST_EXISTS)) { GError *ierror = NULL; g_autoptr(GHashTable) vars = NULL; GHashTableIter iter; gchar *key = NULL; gchar *value = NULL; vars = g_hash_table_new(g_str_hash, g_str_equal); g_message("Getting Systeminfo: %s", context->config->systeminfo_handler); res = launch_and_wait_variables_handler(context->config->systeminfo_handler, vars, &ierror); if (!res) { g_error("Failed to read system-info variables: %s", ierror->message); g_clear_error(&ierror); } g_hash_table_iter_init(&iter, vars); while (g_hash_table_iter_next(&iter, (gpointer*) &key, (gpointer*) &value)) { if (g_strcmp0(key, "RAUC_SYSTEM_SERIAL") == 0) r_context_conf()->system_serial = g_strdup(value); } } if (context->bootslot == NULL) { context->bootslot = g_strdup(get_cmdline_bootname()); } if (context->mountprefix) { g_free(context->config->mount_prefix); context->config->mount_prefix = g_strdup(context->mountprefix); } if (context->keyringpath) { context->config->keyring_path = context->keyringpath; } context->pending = FALSE; }
int main(void) { u32 endtime; system_state = SYS_STATE_INIT; wifi_state = 0; reset_uart_init(); default_gpio_init(); check_gotostandby(); int2host_init(); int2host(1); NFC_TAG_INIT(); mxchipInit(); userResetConfig(); reset_uart_deinit(); get_config(); tcpip_init(); emsp_init(); uart_init(); http_init(); #ifndef USE_0302 APP_Verify_Program_Code(); #endif dual_uap_start(); SetTimer(1, main_function_tick, 1); wifi_option_config(); int2host(0); system_is_bootup(); //EMSP_CMD_SYSTEM_BOOTUP while(1) { if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) != Bit_RESET) IWDG_ReloadCounter(); // Reload IWDG counter else reload(); if(NFC_STARTED){ SetTimer(3000,saveNFCConfig,0); NFC_STARTED = 0; //NFC task started NFC_STARTED2 = 1; //NFC task pending } http_tick(); // HTTP Server mxchipTick(); // wifi, network function switch (system_state) { case SYS_STATE_RESET: wait_uart_dma_clean(); NVIC_SystemReset(); break; case SYS_STATE_GOTO_DEFAULT: default_config(); save_config(); NVIC_SystemReset(); break; case SYS_STATE_DELAY_RELOAD: endtime = MS_TIMER+500; while(endtime>MS_TIMER) mxchipTick(); NVIC_SystemReset(); break; case SYS_STATE_WPS: // User pushed WPS PBC, try wps. user_wifi_stop(); wps_pbc_start(); set_sys_state(last_work_state); break; case SYS_STATE_WPS_FAIL: wps_ing = 0; user_wifi_start(); set_sys_state(last_work_state); set_conncetion_status(0); break; case SYS_STATE_WPS_SUCCESS: wps_ing = 0; set_sys_state(last_work_state); save_config(); set_conncetion_status(0); break; default: break; } } }
bool load_config() { default_config(); FILE *file = fopen("settings.cfg", "r"); if(!file) return false; bool can_read = true; while(can_read) { char data[256]; char *check = fgets(data, 256, file); if(check == NULL) can_read = false; else if(data[0] == '#') continue; else if(data[0] < 33) continue; else { char attr[256]; char val[16]; int nval=-1; for(int a=0; a < strlen(data); a++) { if(data[a] == '=') { int pos=0; for(int b=a+1; b < strlen(data); b++) { val[pos] = data[b]; val[pos+1] = 0; pos++; } nval = atoi(val); break; } else if(data[a] > 32 && data[a] < 127) { attr[a] = data[a]; attr[a+1] = 0; } } int cfg = cfg_from_string(attr); if(cfg != -1) config[cfg] = nval; if(cfg == CFG_COLOUR_DEPTH && nval != 16 && nval != 24 && nval != 32) { allegro_message("Erk, invalid colour depth. 16, 24, or 32, please. Setting to 16."); config[CFG_COLOUR_DEPTH] = 16; return false; } } } fclose(file); file = fopen("shipdata.cfg", "r"); if(!file) return false; int s=0; int upto=1; fscanf(file, "Ships=%d", &s); if(s == 31415) upto = 5; else if(s == 92653) upto = 4; else if(s == 58979) upto = 3; else if(s == 32348) upto = 2; else upto = 1; fclose(file); for(int a=0; a < upto; a++) shipdata[a].owned = true; return true; }
/* Set up all details: - ip server name - dns server name - username, passwd - ... Implementation: - load defaults - parse cmd line - assign settings that may change due to cmd line options - check data Note: - if no argument is specified tries to call the cmd line parser with the default cfg file path. */ int get_config_data(ddns_t *ctx, int argc, char *argv[]) { int i; int rc = 0; cmd_desc_t *it; do { TRY(default_config(ctx)); it = cmd_options_table; while (it->option != NULL) { it->handler.context = ctx; ++it; } /* in case of no options, assume the default cfg file may be present */ if (argc == 1) { char *custom_argv[] = { "", DYNDNS_INPUT_FILE_OPT_STRING, DEFAULT_CONFIG_FILE }; int custom_argc = sizeof(custom_argv) / sizeof(char *); if (ctx->dbg.level > 1) logit(LOG_NOTICE, "Using default config file %s", DEFAULT_CONFIG_FILE); if (ctx->cfgfile) free(ctx->cfgfile); ctx->cfgfile = strdup(DEFAULT_CONFIG_FILE); rc = get_cmd_parse_data(custom_argv, custom_argc, cmd_options_table); } else { rc = get_cmd_parse_data(argv, argc, cmd_options_table); } if (rc || ctx->abort) break; /* settings that may change due to cmd line options */ i = 0; do { int port; size_t src_len; ddns_info_t *info = &ctx->info[i]; if (strlen(info->checkip_name.name) == 0) { if (strlen(info->system->checkip_name) > 0) { port = -1; info->checkip_name.port = HTTP_DEFAULT_PORT; if (get_name_and_port(info->system->checkip_name, info->checkip_name.name, sizeof(info->checkip_name.name), &port) == 0) { if (port > 0 && port < 65535) info->checkip_name.port = port; } } src_len = strlen(info->system->checkip_url); if (src_len > 0 && src_len < sizeof(info->checkip_url)) strcpy(info->checkip_url, info->system->checkip_url); } if (strlen(info->server_name.name) == 0) { if (strlen(info->system->server_name) > 0) { port = -1; info->server_name.port = HTTP_DEFAULT_PORT; if (get_name_and_port(info->system->server_name, info->server_name.name, sizeof(info->server_name.name), &port) == 0) { if (port > 0 && port < 65535) info->server_name.port = port; } } src_len = strlen(info->system->server_url); if (src_len > 0 && src_len < sizeof(info->server_url)) strcpy(info->server_url, info->system->server_url); } } while (++i < ctx->info_count); /* Check if the neccessary params have been provided */ TRY(validate_configuration(ctx)); } while (0); return rc; }