int set_configuration_value(char *key, char* new_unexpanded_value) { int i, return_code, result; char *new_value = NULL; char buf[BUFSIZE]; short color_code; char *endptr; if (key == NULL) return -1; if (new_unexpanded_value != NULL) if ((new_value = expand_configuration_value(new_unexpanded_value)) == NULL) return -1; #ifdef ENABLE_TRACING TRACE_LOG("Setting configuration key \"%s\".\n", key); if (new_value != NULL) { TRACE_LOG("New value: %s at %p.\n", new_value, new_value); } #endif //ENABLE_TRACING i = 0; while (configuration_options[i].name != NULL) { TRACE_LOG("i:%d, name:%s.\n", i, configuration_options[i].name); if (strcmp(configuration_options[i].name, key) == 0) { // Parse option values which cannot be simply copied: if (strcmp(key, "locale") == 0) { TRACE_LOG("Trying to set locale to \"%s\".\n", new_value); return_code = (strcmp(get_configuration_value( "dont-set-locale-from-config"), "true") == 0) ? 0 : set_current_locale_name(new_value); free(new_value); return return_code; } else if (strcmp(key, "random-mode") == 0) { if (new_value == NULL) return -1; else if (strcmp(new_value, "random") == 0) { if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = new_value; seed_random_generator(); return 0; } else if (strcmp(new_value, "predictable") == 0) { if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = new_value; TRACE_LOG("stored value: %p.\n", configuration_options[i].value); seed_random_generator(); return 0; } else return -1; } else if (strcmp(key, "i18n-search-path") == 0) { // Forward to i18n, since this is in tools and cannot access the // "config.c" file. return_code = set_i18n_search_path(new_value); free(new_value); return return_code; } // Options for values which can simply be copied. else if ( (strcmp(key, "z-code-path") == 0) || (strcmp(key, "z-code-root-path") == 0) || (strcmp(key, "autosave-filename") == 0) || (strcmp(key, "savegame-path") == 0) || (strcmp(key, "savegame-default-filename") == 0) || (strcmp(key, "transcript-filename") == 0) || (strcmp(key, "save-text-history-paragraphs") == 0) || (strcmp(key, "input-command-filename") == 0) || (strcmp(key, "record-command-filename") == 0) ) { if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = new_value; return 0; } // Integer values else if ( (strcmp(key, "stream-2-line-width") == 0) || (strcmp(key, "stream-2-left-margin") == 0) || (strcmp(key, "max-undo-steps") == 0) ) { if (new_value == NULL) return -1; if (strlen(new_value) == 0) { free(new_value); return -1; } strtol(new_value, &endptr, 10); if (*endptr != 0) { free(new_value); return -1; } if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = new_value; return 0; } // Color options else if (strcmp(key, "foreground-color") == 0) { if (new_value == NULL) return -1; color_code = color_name_to_z_colour(new_value); free(new_value); if (color_code == -1) return -1; if (snprintf(buf, BUFSIZE, "%d", color_code) >= BUFSIZE) return -1; if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = fizmo_strdup(buf); default_foreground_colour = color_code; return 0; } else if (strcmp(key, "background-color") == 0) { if (new_value == NULL) return -1; color_code = color_name_to_z_colour(new_value); free(new_value); if (color_code == -1) return -1; if (snprintf(buf, BUFSIZE, "%d", color_code) >= BUFSIZE) return -1; if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = fizmo_strdup(buf); default_background_colour = color_code; return 0; } // Boolean options else if ( (strcmp(key, "disable-external-streams") == 0) || (strcmp(key, "disable-restore") == 0) || (strcmp(key, "disable-save") == 0) || (strcmp(key, "disable-sound") == 0) || (strcmp(key, "enable-font3-conversion") == 0) || (strcmp(key, "quetzal-umem") == 0) || (strcmp(key, "random-mode") == 0) || (strcmp(key, "restore-after-save-and-quit-file-before-read") == 0) || (strcmp(key, "save-and-quit-file-before-read") == 0) || (strcmp(key, "set-tandy-flag") == 0) || (strcmp(key, "start-command-recording-when-story-starts") == 0) || (strcmp(key, "start-script-when-story-starts") == 0) || (strcmp(key, "start-file-input-when-story-starts") == 0) || (strcmp(key, "disable-stream-2-hyphenation") == 0) || (strcmp(key, "disable-stream-2-wrap") == 0) || (strcmp(key, "sync-transcript") == 0) || (strcmp(key, "dont-set-locale-from-config") == 0) ) { if ( (new_value == NULL) || (*new_value == 0) || (strcmp(new_value, config_true_value) == 0) ) { if (new_value != NULL) free(new_value); if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = fizmo_strdup(config_true_value); return 0; } else if ((new_value != NULL) && (strcmp(new_value, config_false_value)==0)) { free(new_value); if (configuration_options[i].value != NULL) free(configuration_options[i].value); configuration_options[i].value = fizmo_strdup(config_false_value); return -1; } else { free(new_value); return -1; } } else { i18n_translate_and_exit( libfizmo_module_name, i18n_libfizmo_UNKNOWN_CONFIGURATION_OPTION_P0S, -0x0101, key); } } i++; } if (active_interface != NULL) { result = active_interface->parse_config_parameter(key, new_value); if (result == -1) { i18n_translate_and_exit( libfizmo_module_name, i18n_libfizmo_INVALID_VALUE_P0S_FOR_PARAMETER_P1S, -0x0101, key, new_value); } } if (active_sound_interface == NULL) return -2; else { result = active_sound_interface->parse_config_parameter(key, new_value); if (result == -1) { i18n_translate_and_exit( libfizmo_module_name, i18n_libfizmo_INVALID_VALUE_P0S_FOR_PARAMETER_P1S, -0x0101, key, new_value); } } return result; }
ofxEliza::ofxEliza():linePos(2), m_bNewData(0), m_bMemoryRecall(0), m_nShortInputCount(0),m_bLearning(0), m_nUserRepeatCount(0), m_sUserName("USER") { seed_random_generator(); }