int main(int argc, char *argv[]) { uint32 loglevel = 1; DEBUG(loglevel = 3); log_setloglevel(loglevel); EditorEngine::RelocateWorkingDir(); // a pity that this has to be done before opening the log file ... log_prepare("editor_log.txt", "w"); EditorEngine::PrintSystemSpecs(); SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); atexit(log_close); atexit(SDL_Quit); mtRandSeed(time(NULL)); EditorEngine editor; editor.HookSignals(); try { editor.InitScreen(320,240,0,SDL_RESIZABLE); editor.SetTitle("Lost Vikings 3 Project - Level Editor"); if(!editor.Setup()) { logerror("Failed to setup editor. Exiting."); editor.UnhookSignals(); return 1; } editor.Run(); } catch(gcn::Exception ex) { editor.UnhookSignals(); logerror("An unhandled gcn::Exception occurred! Infos:"); logerror("File: %s:%u", ex.getFilename().c_str(), ex.getLine()); logerror("Function: %s", ex.getFunction().c_str()); logerror("Message: %s", ex.getMessage().c_str()); } editor.UnhookSignals(); editor.Shutdown(); return 0; }
int main(int argc, char **argv) { SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_JOYSTICK); //Bootstrap::RelocateWorkingDir(); Bootstrap::HookSignals(); log_prepare("game_log.txt", "w"); log_setloglevel(4); Bootstrap::PrintSystemSpecs(); // this should be checked, especially in larger projects if(!ttvfs::checkCompat()) return 1; vfs.LoadFileSysRoot(false); vfs.Prepare(); srand(42); // FIXME: temporary ScriptedEngine that; if(!that.Setup()) { logerror("Failed to setup engine. Exiting."); return 1; } //#ifdef _DEBUG that.InitScreen(800, 600); /*#else const SDL_VideoInfo *info = SDL_GetVideoInfo(); that.InitScreen(info->current_w, info->current_h, 0, 0, true); #endif*/ that.Run(); that.Shutdown(); SDL_Quit(); Bootstrap::UnhookSignals(); return 0; }
int configfile_load_config(const char * filename) { static server_config_directive config_directives[] = { "server.tcp-listen-port", SERVER_CONFIG_TYPE_INT, &g_serverConfig.tcp_listen_port, 0, 1, "server.tcp-listen-host", SERVER_CONFIG_TYPE_STRING, &g_serverConfig.tcp_listen_host, 0, 1, "server.udp-listen-port", SERVER_CONFIG_TYPE_INT, &g_serverConfig.udp_listen_port, 0, 1, "server.udp-listen-host", SERVER_CONFIG_TYPE_STRING, &g_serverConfig.udp_listen_host, 0, 1, "server.daemonize", SERVER_CONFIG_TYPE_INT, &g_serverConfig.daemonize, 0, 0, "log.file", SERVER_CONFIG_TYPE_STRING, &g_serverConfig.log_logfile, 0, 1, "log.level", SERVER_CONFIG_TYPE_INT, &g_serverConfig.log_loglevel, 0, 1, NULL, 0, NULL, 0, 0, }; FILE * pConfigFile; char line[1000]; char * p, *q; char * pKey; char * pValue; int line_counter = 0; server_config_directive * dir; // try to open pConfigFile = fopen(filename, "r"); if( pConfigFile == NULL ) { log_write(ERROR, "FATAL: Config file %s could not be read.", filename); return -1; } // read the file in line by lien while( fgets(line, 1000, pConfigFile) ) { ++line_counter; if( line[0] == '#' || ( line[0] == '/' && line[1] == '/' ) ) continue; // try to find the config key p = strchr( line, '=' ); if( p == NULL ) { /*log_write(ERROR, "FATAL: Config file has a parsing error at line %u.", line_counter); fclose(pConfigFile); return -1;*/ // non-key line continue; } *p = 0; // trim shit before and after the key pKey = line; while( !isalpha(*pKey) ) ++pKey; // trim shit after it q = pKey; while( *q == '.' || isalpha(*q) || *q == '-' ) ++q; *q = 0; // now we have to trim the crap after the equals ++p; while( !isalpha(*p) && !isdigit(*p) && *p != '\'') ++p; // trim the stuff after the value pValue = p; if( *p == '\'' ) { // string, copy until we have a ' ++p; pValue = p; while( *p != '\'' ) ++p; } else { // non-string, follow normal rules while( *p != '\n' && *p != ' ' ) ++p; } // null it *p = 0; if( *pKey == 0 ) { log_write(ERROR, "FATAL: Config file has a parsing error at line %u.", line_counter); fclose(pConfigFile); return -1; } log_write(DEBUG, "CONFIG: %s = %s", pKey, pValue ); // now we have the key and value pair, iterate over possible options for( dir = config_directives; dir->key != NULL; ++dir ) { if( !stricmp( dir->key, pKey ) ) { if( dir->done != 0 ) { log_write(ERROR, "FATAL: Key %s is defined in config file twice.", dir->key); fclose(pConfigFile); return -1; } dir->done = 1; switch( dir->type ) { case SERVER_CONFIG_TYPE_INT: { *(int*)dir->dest = atoi(pValue); }break; case SERVER_CONFIG_TYPE_STRING: { if( *(char**)dir->dest != NULL ) free( *(char**)dir->dest ); *(char**)dir->dest = strdup( pValue ); }break; } break; } } // if we didn't find a key, it's probably invalid if( dir->key == NULL ) { log_write(ERROR, "FATAL: Config file contains invalid key (%s) at line %u", pKey, line_counter); fclose(pConfigFile); return -1; } } // close off the file, EOF fclose(pConfigFile); // make sure we got all the options for( dir = config_directives; dir->key != NULL; ++dir ) { if( dir->done == 0 && dir->required ) { log_write(ERROR, "FATAL: Config file does not define required directive %s.", dir->key); return -1; } } // set the new log level log_setloglevel(g_serverConfig.log_loglevel); log_setlogfile(g_serverConfig.log_logfile); // success return 0; }