/* * Process the user configuration looking for the TAG_FIND. If it is * null then look for DEBUG_VALUE in the file and copy the token found * into TOKEN of TOKEN_SIZE. Routine returns the new debug value * matching tag. */ static long find_tag(const long debug_value, const char *tag_find, char *token, const int token_size) { char path[1024], *path_p; default_t *def_p; const char *home_p; int ret; long new_debug = 0; /* do we need to have a home variable? */ if (inpath == NULL) { /* first we try to read the RC file from the current directory */ ret = read_rc_file(DEFAULT_CONFIG, debug_value, tag_find, &new_debug, token, token_size); /* did we find the correct value in the file? */ if (ret == TOKEN_FOUND) { return new_debug; } /* if we did not find the file, check the home directory */ if (ret == FILE_FOUND) { path_p = DEFAULT_CONFIG; } else { /* find our home directory */ home_p = getenv(HOME_ENVIRON); if (home_p == NULL) { (void)fprintf(stderr, "%s: could not find variable '%s'\n", argv_program, HOME_ENVIRON); exit(1); } (void)loc_snprintf(path, sizeof(path), "%s/%s", home_p, DEFAULT_CONFIG); /* read in the file from our home directory */ ret = read_rc_file(path, debug_value, tag_find, &new_debug, token, token_size); /* did we find the correct value in the file? */ if (ret == TOKEN_FOUND) { return new_debug; } if (ret == FILE_FOUND) { path_p = path; } else { path_p = NULL; } } } else { /* read in the specified file */ ret = read_rc_file(inpath, debug_value, tag_find, &new_debug, token, token_size); /* did we find the correct value in the file? */ if (ret == TOKEN_FOUND) { return new_debug; } /* if the specified was not found, return error */ if (ret != FILE_FOUND) { (void)fprintf(stderr, "%s: could not read '%s': ", argv_program, inpath); perror(""); exit(1); } path_p = inpath; } /* if tag-find is NULL we assume we are looking for a debug-value */ if (tag_find == NULL) { /* now look for the value in the default token list */ if (token != NULL) { for (def_p = defaults; def_p->de_string != NULL; def_p++) { if (def_p->de_flags == debug_value) { (void)loc_snprintf(token, token_size, "internal token: %s", def_p->de_string); new_debug = def_p->de_flags; break; } } if (def_p->de_string == NULL) { (void)loc_snprintf(token, token_size, "unknown token"); new_debug = 0; } } } else { /* now look for the token in the default token list */ for (def_p = defaults; def_p->de_string != NULL; def_p++) { if (strcmp(tag_find, def_p->de_string) == 0) { new_debug = def_p->de_flags; break; } } /* did we not find the token? */ if (def_p->de_string == NULL) { if (path_p == NULL) { (void)fprintf(stderr, "%s: unknown tag '%s'\n", argv_program, tag_find); } else { (void)fprintf(stderr, "%s: could not find tag '%s' in '%s'\n", argv_program, tag_find, path_p); } exit(1); } } return new_debug; }
int PingusMain::run(int argc, char** argv) { g_logger.set_log_level(Logger::kWarning); tinygettext::Log::set_log_info_callback(0); try { // FIXME force set language using System::get_language() to get it from env dictionary_manager.set_language(tinygettext::Language::from_env(System::get_language())); parse_args(argc, argv); // here language and po dir isn't set, no traslation in command line init_path_finder(); // here init language path read_rc_file(); // here set language if ~/.pingus/config exist and language value is set apply_args(); // here set language if arg -l is specified print_greeting_message(); // init the display FramebufferType fbtype = SDL_FRAMEBUFFER; if (cmd_options.framebuffer_type.is_set()) { fbtype = cmd_options.framebuffer_type.get(); } bool fullscreen = cmd_options.fullscreen.is_set() ? cmd_options.fullscreen.get() : false; bool resizable = cmd_options.resizable.is_set() ? cmd_options.resizable.get() : true; Size screen_size(800, 600); if (fullscreen) { if (cmd_options.fullscreen_resolution.is_set()) { screen_size = cmd_options.fullscreen_resolution.get(); } } else { if (cmd_options.geometry.is_set()) { screen_size = cmd_options.geometry.get(); } } SDLSystem system; try { system.create_window(fbtype, screen_size, fullscreen, resizable); } catch(const std::exception& err) { if (fbtype == SDL_FRAMEBUFFER) { throw; } else { log_error("couldn't create window, falling back to SDL: " << err.what()); system.create_window(SDL_FRAMEBUFFER, screen_size, fullscreen, resizable); config_manager.set_renderer(SDL_FRAMEBUFFER); } } // init other components SavegameManager savegame_manager("savegames/savegames.scm"); StatManager stat_manager("savegames/variables.scm"); // FIXME: turn these into RAII Resource::init(); Fonts::init(); Sound::PingusSound::init(); config_manager.apply(cmd_options); // start and run the actual game start_game(); } catch (const std::bad_alloc&) { std::cout << _("Pingus: Out of memory!") << std::endl; } catch (const std::exception& a) { std::cout << _("Pingus: Standard exception caught!:\n") << a.what() << std::endl; } catch (...) { std::cout << _("Pingus: Unknown throw caught!") << std::endl; } Sound::PingusSound::deinit(); Fonts::deinit(); WorldObjFactory::deinit(); Resource::deinit(); return 0; }