/** * bastile_gpg_options_change_vals * * @option: null-terminated array of option names to change * @value: The values to change respective option to * @err: Returns an error value when errors * * Changes the given option in the gpg config file. * If a value is NULL, the option will be deleted. If you want * an empty value, set value to an empty string. * * Returns: TRUE if success, FALSE if not **/ gboolean bastile_gpg_options_change_vals (const gchar *options[], gchar *values[], GError **err) { GError *e = NULL; GArray *lines; g_assert (!err || !*err); if (!err) err = &e; if (!gpg_options_init (err)) return FALSE; lines = read_config_file (err); if (!lines) return FALSE; process_conf_edits (lines, options, values); write_config_file (lines, err); free_string_array (lines); return *err ? FALSE : TRUE; }
void toggle_setting (void) { if (hilite_item == (NUM_SETTINGS - 1)) { write_config_file(); display_options(); return; } switch (hilite_item) { case 0: wireframe ^= 1; break; case 1: anti_alias_gfx ^= 1; break; case 2: planet_render_style = (planet_render_style + 1) % 4; break; case 3: hoopy_casinos ^= 1; break; case 4: instant_dock ^= 1; break; } highlight_setting (hilite_item); }
void toggle_loki_support() { char value[3]; apply_loki_patch.value ^= 1; sprintf(value, "%d", apply_loki_patch.value); write_config_file(PHILZ_SETTINGS_FILE, apply_loki_patch.key, value); // ui_print("Loki Support: %s\n", apply_loki_patch.value ? "Enabled" : "Disabled"); }
// check if we should verify signature during install of zip packages // only called on recovery start void toggle_signature_check() { char value[3]; signature_check_enabled.value = !signature_check_enabled.value; sprintf(value, "%d", signature_check_enabled.value); write_config_file(PHILZ_SETTINGS_FILE, signature_check_enabled.key, value); // ui_print("Signature Check: %s\n", signature_check_enabled.value ? "Enabled" : "Disabled"); }
void close_application (GtkWidget *widget, gpointer user_data) { write_config_file (); stop_recording (TRUE); stop_scripting (TRUE); stop_replaying (TRUE); gtk_main_quit (); applicationExiting = TRUE; }
/* This function is called on exit */ void cleanup(void) { write_config_file(); write_saved_games(); shutdown_audio(); winsys_shutdown(); }
static void finish(char *message) { endwin(); write_config_file(); system("clear"); printf("%s", message); exit(0); }
void test_delete_user() { printf("\nTesting delete_user\n"); char* app_dir = get_app_directory(TEST_ROOT "/local-1", yarn_username, "app_3"); if (mkdirs(app_dir, 0700) != 0) { exit(1); } char buffer[100000]; sprintf(buffer, "%s/test.cfg", app_dir); if (write_config_file(buffer, 1) != 0) { exit(1); } char * dirs[] = {buffer, 0}; int ret = delete_as_user(yarn_username, "file1" , dirs); if (ret == 0) { printf("FAIL: if baseDir is a file, delete_as_user should fail if a subdir is also passed\n"); exit(1); } // Pass a file to delete_as_user in the baseDirs parameter. The file should // be deleted. ret = delete_as_user(yarn_username, "" , dirs); if (ret != 0) { printf("FAIL: delete_as_user could not delete baseDir when baseDir is a file: return code is %d\n", ret); exit(1); } sprintf(buffer, "%s", app_dir); char missing_dir[20]; strcpy(missing_dir, "/some/missing/dir"); char * dirs_with_missing[] = {missing_dir, buffer, 0}; ret = delete_as_user(yarn_username, "" , dirs_with_missing); printf("%d" , ret); if (access(buffer, R_OK) == 0) { printf("FAIL: directory not deleted\n"); exit(1); } sprintf(buffer, "%s/local-1/usercache/%s", TEST_ROOT, yarn_username); if (access(buffer, R_OK) != 0) { printf("FAIL: directory missing before test\n"); exit(1); } if (delete_as_user(yarn_username, buffer, NULL) != 0) { exit(1); } if (access(buffer, R_OK) == 0) { printf("FAIL: directory not deleted\n"); exit(1); } if (access(TEST_ROOT "/local-1", R_OK) != 0) { printf("FAIL: local-1 directory does not exist\n"); exit(1); } free(app_dir); }
int dumpconfig(struct cmd_context *cmd, int argc, char **argv) { const char *file = arg_str_value(cmd, file_ARG, NULL); if (!write_config_file(cmd->cft, file, argc, argv)) { stack; return ECMD_FAILED; } return ECMD_PROCESSED; }
void quit_cb (GtkWidget * widget) { write_filetypes_file (); write_bookmarks_file (); write_user_commands_file (); write_programs_file(); write_config_file (); write_command_mode_file(); write_term_file(); gtk_main_quit (); }
/** * Convert the network_configs file to NetworkManager's keyfile */ int convert_network_configs(char *filename) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; xmlNode *cur_node; /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /*parse the file and get the DOM */ doc = xmlReadFile(filename, NULL, 0); if (doc == NULL) { printf("error: could not parse file %s\n", filename); return 1; } /*Get the root element node */ root_element = xmlDocGetRootElement(doc); for (cur_node = root_element->children; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE && !strcmp((char *)cur_node->name, "configuration")) { struct connection conn; read_connection(&conn, cur_node); write_config_file(&conn); } } /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); return 0; }
void read_config_file() { char config_file[BUFF_LEN]; char config_dir[BUFF_LEN]; clear_config_cache(); if ( get_config_file_name( config_file, sizeof( config_file ) ) != 0 ) { return; } if ( get_config_dir_name( config_dir, sizeof( config_dir ) ) != 0 ) { return; } if ( dir_exists( config_dir ) ) { if ( file_exists( config_file ) ) { /* File exists -- let's try to evaluate it. */ if ( Tcl_EvalFile( g_game.tcl_interp, config_file ) != TCL_OK ) { handle_error( 1, "error evalating %s: %s", config_file, Tcl_GetStringResult( g_game.tcl_interp ) ); } } return; } /* File does not exist -- look for old version */ if ( get_old_config_file_name( config_file, sizeof( config_file ) ) != 0 ) { return; } if ( !file_exists( config_file ) ) { return; } /* Old file exists -- let's try to evaluate it. */ if ( Tcl_EvalFile( g_game.tcl_interp, config_file ) != TCL_OK ) { handle_error( 1, "error evalating deprecated %s: %s", config_file, Tcl_GetStringResult( g_game.tcl_interp ) ); } else { /* Remove old file and save info in new file location */ remove(config_file); write_config_file(); } }
void winsys_exit(const int code) { courseRenderer.cleanup(); Course::cleanup(); if(GameMode::currentMode!=NULL){ //delete GameMode::currentMode; GameMode::currentMode=NULL; } write_config_file(); cleanup_scene_node(); PP_MESSAGE("Quit SDL"); SDL_Quit(); exit(code); }
void GeneralConfig::apply() { ppogl::ListBox<std::string>::Iterator langit = m_langListBox.getSelected(); PPConfig.setString("ui_language", (*langit).data); PPConfig.setBool("ui_snow", m_uiSnowBox.isSelected()); PPConfig.setBool("display_fps", m_fpsBox.isSelected()); PPConfig.setBool("display_course_percentage", m_coursePercentageBox.isSelected()); write_config_file(); ppogl::Translation::getInstance().clear(); std::string data_dir = PPConfig.getString("data_dir"); script.doFile(data_dir+"/translations/"+PPConfig.getString("ui_language")+".nut"); setMode( GameMode::prevmode ); }
int main (int argc, char **argv) { int ret; printf("Hexen II: Hammer of Thyrion Launcher, version %i.%i.%i\n", LAUNCHER_VERSION_MAJ, LAUNCHER_VERSION_MID, LAUNCHER_VERSION_MIN); /* initialize the user interface */ ret = ui_init(&argc, &argv); if (ret != 0) { fprintf (stderr, "Couldn't initialize user interface\n"); exit (ret); } ValidateByteorder (); ret = Sys_GetUserdir(userdir, sizeof(userdir)); if (ret != 0) Sys_Error (ret, "Couldn't determine userspace directory"); memset(basedir, 0, sizeof(basedir)); Sys_FindBinDir (argv[0], basedir); printf ("Basedir : %s\n", basedir); printf ("Userdir : %s\n", userdir); /* go into the binary's directory */ chdir (basedir); cfg_read_basedir(); scan_game_installation(); read_config_file(); /* run the graphical user interface */ ret = ui_main (); if (ret == 0) ret = write_config_file (); return ret; }
void client_shutdown() { console_print("Shutting down...\n"); kill_servers(); kill_download(); kill_key(); kill_openssl(); kill_sound(); kill_game(); kill_network(); kill_render(); // kill_input(); dump_console(); kill_console(); kill_control(); write_config_file(); SDL_Quit(); terminate_process(); }
void server_config_entries_write (GList *entries, const gchar *filename) { GKeyFile* config_file = g_key_file_new (); GList *list = entries; while (list != NULL){ ServerConfigEntry *entry; entry = list->data; if (entry != NULL) { g_key_file_set_value (config_file, entry->name, CONFIG_KEY_HOST, entry->host != NULL ? entry->host : EMPTY_STRING); g_key_file_set_value (config_file, entry->name, CONFIG_KEY_PORT, entry->port != NULL ? entry->port : EMPTY_STRING); g_key_file_set_value (config_file, entry->name, CONFIG_KEY_SSLMODE, entry->sslmode != NULL ? entry->sslmode : EMPTY_STRING); g_key_file_set_value (config_file, entry->name, CONFIG_KEY_DBNAME, entry->dbname != NULL ? entry->dbname : EMPTY_STRING); } list = g_list_next (list); } write_config_file (filename, config_file); g_key_file_free (config_file); }
int main(int argc, char **argv) { LOGFILE = stdout; int my_username = 0; // clean up any junk from previous run system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT); if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) { exit(1); } if (write_config_file(TEST_ROOT "/test.cfg") != 0) { exit(1); } read_config(TEST_ROOT "/test.cfg"); create_tt_roots(); if (getuid() == 0 && argc == 2) { username = argv[1]; } else { username = strdup(getpwuid(getuid())->pw_name); my_username = 1; } set_tasktracker_uid(geteuid(), getegid()); if (set_user(username)) { exit(1); } printf("\nStarting tests\n"); printf("\nTesting get_user_directory()\n"); test_get_user_directory(); printf("\nTesting get_job_directory()\n"); test_get_job_directory(); printf("\nTesting get_attempt_directory()\n"); test_get_attempt_directory(); printf("\nTesting get_task_launcher_file()\n"); test_get_task_launcher_file(); printf("\nTesting get_job_log_dir()\n"); test_get_job_log_dir(); test_check_configuration_permissions(); printf("\nTesting delete_task()\n"); test_delete_task(); printf("\nTesting delete_job()\n"); test_delete_job(); test_delete_user(); test_check_user(); // the tests that change user need to be run in a subshell, so that // when they change user they don't give up our privs run_test_in_child("test_signal_task", test_signal_task); run_test_in_child("test_signal_task_group", test_signal_task_group); // init job and run task can't be run if you aren't testing as root if (getuid() == 0) { // these tests do internal forks so that the change_owner and execs // don't mess up our process. test_init_job(); test_run_task(); } seteuid(0); run("rm -fr " TEST_ROOT); printf("\nFinished tests\n"); if (my_username) { free(username); } free_configurations(); return 0; }
static gint quit_gtuxnes(GtkWidget *w, gpointer data) { write_config_file(config_file_name); gtk_main_quit(); return(FALSE); }
void launch_hexen2_bin (void) { char *args[MAX_ARGS], *ptr; size_t i = 0; memset (string_buf, 0, STRING_BUFSIZE); ptr = &string_buf[0]; /* add the binary name first: */ if (opengl_support) strcpy (string_buf, "gl"); if (destiny == DEST_HW) strcat (string_buf, HW_BINARY_NAME); else strcat (string_buf, H2_BINARY_NAME); string_buf[BINNAME_CHARS-1] = '\0'; args[i] = ptr; while (*ptr) ptr++; if (basedir_nonstd && game_basedir[0]) { args[++i] = "-basedir"; args[++i] = game_basedir; } #if !defined(DEMOBUILD) if (destiny == DEST_H2 && mp_support) args[++i] = "-portals"; #endif /* DEMOBUILD */ args[++i] = (fullscreen) ? "-f" : "-w"; args[++i] = "-width"; args[++i] = resolution_args[resolution][0]; args[++i] = "-height"; args[++i] = resolution_args[resolution][1]; if (opengl_support && use_con && conwidth < resolution) { args[++i] = "-conwidth"; args[++i] = resolution_args[conwidth][0]; } args[++i] = snddrv_names[sound][0]; if (sound != 0) { if (sndrate != 0) { args[++i] = "-sndspeed"; args[++i] = snd_rates[sndrate]; } if (sndbits == 0) /* 16-bit is default already */ { args[++i] = "-sndbits"; args[++i] = "8"; } if (midi == 0) args[++i] = "-nomidi"; if (cdaudio == 0) args[++i] = "-nocdaudio"; } else { /* engine doesn't -nocdaudio upon -nosound, but it simply is what the name implies */ args[++i] = "-nocdaudio"; } #if !defined(DEMOBUILD) if (destiny == DEST_HW && hwgame > 0) { args[++i] = "-game"; args[++i] = hwgame_names[hwgame].dirname; } else if (destiny == DEST_H2 && h2game > 0) { args[++i] = "-game"; args[++i] = h2game_names[h2game].dirname; /* bot matches require -listen */ if (h2game_names[h2game].is_botmatch) { args[++i] = "-listen"; lan = 1; /* -listen can't work with -nolan */ } } #endif /* DEMOBUILD */ if (lan == 0 && destiny == DEST_H2) args[++i] = "-nolan"; if (!mouse) args[++i] = "-nomouse"; if (opengl_support && fxgamma) args[++i] = "-3dfxgamma"; if (opengl_support && is8bit) args[++i] = "-paltex"; if (opengl_support && use_fsaa && aasamples) { args[++i] = "-fsaa"; snprintf (++ptr, AASAMPLES_CHARS, "%i", aasamples); args[++i] = ptr; while (*ptr) ptr++; } if (opengl_support && vsync) args[++i] = "-vsync"; if (opengl_support && use_lm1 == 1) /* -lm_4 is default already */ args[++i] = "-lm_1"; if (gl_nonstd && opengl_support && gllibrary[0]) { args[++i] = "-g"; args[++i] = gllibrary; } if (use_heap && heapsize >= HEAP_MINSIZE) { args[++i] = "-heapsize"; snprintf (++ptr, HEAPSIZE_CHARS, "%i", heapsize); args[++i] = ptr; while (*ptr) ptr++; } if (use_zone && zonesize >= ZONE_MINSIZE) { args[++i] = "-zone"; snprintf (++ptr, ZONESIZE_CHARS, "%i", zonesize); args[++i] = ptr; while (*ptr) ptr++; } if (debug2) args[++i] = "-devlog"; else if (debug) args[++i] = "-condebug"; /* parse the extra user arguments */ if (use_extra && ext_args[0]) { memcpy (++ptr, ext_args, MAX_EXTARGS-1); string_buf[STRING_BUFSIZE-1] = '\0'; while (1) { if (!*ptr || (i+2 >= MAX_ARGS)) break; while (*ptr && isspace(*ptr)) *ptr++ = '\0'; if (*ptr) { args[++i] = ptr; while (*ptr && !isspace(*ptr)) ptr++; } } } /* finish the list of args */ args[++i] = NULL; write_config_file (); ui_quit (); printf ("\nLaunching %s\n", &string_buf[0]); printf ("Command line is :\n "); i = 0; while (args[i]) { printf (" %s", args[i]); i++; } printf ("\n\n"); execv (&string_buf[0], args); exit (0); }
int main(int argc, char **argv) { LOGFILE = stdout; ERRORFILE = stderr; int my_username = 0; // clean up any junk from previous run system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT); if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) { exit(1); } if (write_config_file(TEST_ROOT "/test.cfg") != 0) { exit(1); } read_config(TEST_ROOT "/test.cfg"); local_dirs = (char *) malloc (sizeof(char) * ARRAY_SIZE); strcpy(local_dirs, NM_LOCAL_DIRS); log_dirs = (char *) malloc (sizeof(char) * ARRAY_SIZE); strcpy(log_dirs, NM_LOG_DIRS); create_nm_roots(extract_values(local_dirs)); if (getuid() == 0 && argc == 2) { username = argv[1]; } else { username = strdup(getpwuid(getuid())->pw_name); my_username = 1; } set_nm_uid(geteuid(), getegid()); if (set_user(username)) { exit(1); } printf("\nStarting tests\n"); printf("\nTesting get_user_directory()\n"); test_get_user_directory(); printf("\nTesting get_app_directory()\n"); test_get_app_directory(); printf("\nTesting get_container_directory()\n"); test_get_container_directory(); printf("\nTesting get_container_launcher_file()\n"); test_get_container_launcher_file(); printf("\nTesting get_app_log_dir()\n"); test_get_app_log_dir(); test_check_configuration_permissions(); printf("\nTesting delete_container()\n"); test_delete_container(); printf("\nTesting delete_app()\n"); test_delete_app(); test_delete_user(); test_check_user(); // the tests that change user need to be run in a subshell, so that // when they change user they don't give up our privs run_test_in_child("test_signal_container", test_signal_container); run_test_in_child("test_signal_container_group", test_signal_container_group); // init app and run container can't be run if you aren't testing as root if (getuid() == 0) { // these tests do internal forks so that the change_owner and execs // don't mess up our process. test_init_app(); test_run_container(); } seteuid(0); run("rm -fr " TEST_ROOT); printf("\nFinished tests\n"); if (my_username) { free(username); } free_configurations(); return 0; }
int main(int argc, char *argv[]) { byte keypress; client_init(); if( argc > 1 ) /* Command line arguments */ handle_cl_args(argc, argv); srand( time(NULL) ); calc_lookup_tables(DEGREES); win_init(); entity_init(); if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) { perror("Malloc"); ERR_QUIT("Error allocating ent_img_loaded array", 1); } else { memset(ent_img_loaded, 0, num_entity_types); } /* Load client preferences from file */ read_config_file( &client ); /* Set view dimensions, which are calculated by tile width & heights */ client.view_w = client.x_tiles * TILE_W; client.view_h = client.y_tiles * TILE_H; /* What the client WISHES their dimensions were (this may not be what it actually is, ie in demo's etc */ client.desired_w = client.view_w; client.desired_h = client.view_h; weapon_type_init(); particle_init(); menu_init(); cl_network_init(); client.state = MENU; if( client.demo == DEMO_PLAY ) { cl_network_connect(NULL, 42); client.state = GAME_LOAD; } for( ; ; ) { switch( client.state ) { case MENU: win_ungrab_pointer(); menu_driver(); break; case GAME_LOAD: win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); /* Finished loading, we are ready to play */ cl_change_map(client.map, client.gamemode); break; case GAME_RESUME: /* Resume game from menu */ win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); input_clear(); draw_status_bar(); cl_netmsg_send_ready(); /* Tell server new details */ cl_net_finish(); /* Send the NETMSG_READY to the server */ client.state = GAME_JOIN; break; case GAME_JOIN: win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE ); win_set_cursor( 1 ); if( client.mousemode ) { win_grab_pointer(); } text_buf_clear(); particle_clear(); case GAME_PLAY: cl_net_update(); if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */ draw_crosshair( my_entity ); if( client.map_target_active ) draw_map_target( my_entity ); text_buf_update(); if( client.netstats ) cl_net_stats(); win_update(); /* Keyboard Input */ client.dir = my_entity.dir; keypress = get_input(); cl_netmsg_send_cl_update(keypress, client.dir); } cl_net_finish(); /* Send things that need sending */ cap_fps(client.fps); break; case QUIT: game_close(); image_close(); /* Free all the images */ win_close(); write_config_file(&client); if( ent_img_loaded != NULL ) free(ent_img_loaded); exit(EXIT_SUCCESS); break; } } return EXIT_SUCCESS; }
// verify md5sum of zip file before they are installed void toggle_install_zip_verify_md5() { char value[3]; install_zip_verify_md5.value ^= 1; sprintf(value, "%d", install_zip_verify_md5.value); write_config_file(PHILZ_SETTINGS_FILE, install_zip_verify_md5.key, value); }
// This test is expected to be executed either by a regular // user or by root. If executed by a regular user it doesn't // test all the functions that would depend on changing the // effective user id. If executed by a super-user everything // gets tested. Here are different ways of execing the test binary: // 1. regular user assuming user == yarn user // $ test-container-executor // 2. regular user with a given yarn user // $ test-container-executor yarn_user // 3. super user with a given user and assuming user == yarn user // # test-container-executor user // 4. super user with a given user and a given yarn user // # test-container-executor user yarn_user int main(int argc, char **argv) { LOGFILE = stdout; ERRORFILE = stderr; // clean up any junk from previous run if (system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT)) { exit(1); } if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) { exit(1); } if (write_config_file(TEST_ROOT "/test.cfg", 1) != 0) { exit(1); } read_config(TEST_ROOT "/test.cfg"); local_dirs = extract_values(strdup(NM_LOCAL_DIRS)); log_dirs = extract_values(strdup(NM_LOG_DIRS)); create_nm_roots(local_dirs); // See the description above of various ways this test // can be executed in order to understand the following logic char* current_username = strdup(getpwuid(getuid())->pw_name); if (getuid() == 0 && (argc == 2 || argc == 3)) { username = argv[1]; yarn_username = (argc == 3) ? argv[2] : argv[1]; } else { username = current_username; yarn_username = (argc == 2) ? argv[1] : current_username; } set_nm_uid(geteuid(), getegid()); if (set_user(username)) { exit(1); } printf("\nStarting tests\n"); printf("\nTesting resolve_config_path()\n"); test_resolve_config_path(); printf("\nTesting get_user_directory()\n"); test_get_user_directory(); printf("\nTesting get_app_directory()\n"); test_get_app_directory(); printf("\nTesting get_container_directory()\n"); test_get_container_directory(); printf("\nTesting get_container_launcher_file()\n"); test_get_container_launcher_file(); printf("\nTesting get_app_log_dir()\n"); test_get_app_log_dir(); test_check_configuration_permissions(); printf("\nTesting delete_container()\n"); test_delete_container(); printf("\nTesting delete_app()\n"); test_delete_app(); test_check_user(0); // the tests that change user need to be run in a subshell, so that // when they change user they don't give up our privs run_test_in_child("test_signal_container", test_signal_container); run_test_in_child("test_signal_container_group", test_signal_container_group); // init app and run container can't be run if you aren't testing as root if (getuid() == 0) { // these tests do internal forks so that the change_owner and execs // don't mess up our process. test_init_app(); test_run_container(); } seteuid(0); // test_delete_user must run as root since that's how we use the delete_as_user test_delete_user(); free_configurations(); printf("\nTrying banned default user()\n"); if (write_config_file(TEST_ROOT "/test.cfg", 0) != 0) { exit(1); } read_config(TEST_ROOT "/test.cfg"); username = "******"; test_check_user(1); username = "******"; test_check_user(1); run("rm -fr " TEST_ROOT); printf("\nFinished tests\n"); free(current_username); free_configurations(); return 0; }
int main(int argc, char** argv) { setvbuf(stdout, 0, _IONBF, 0); char* run_name = new char[200]; am_making_movie = true; crash_movie_file_name_global = new char[1000]; double runtime = 0; if (am_debugging_onebound) { printf("turning off am_only_writing_on_crash for onebound-debugging mode\n"); am_only_writing_on_crash = false; } set_input_variables(argc, argv, run_name, &am_making_movie, &runtime); if (runtime == 0 and am_making_movie and not am_only_writing_on_crash) { printf("error,value of am_only_writing: %d\n", (int)am_only_writing_on_crash); printf("Error: run settings would cause indefinite movie data printing and fill up the disk!\n"); exit(EXIT_FAILURE); } if (am_only_writing_on_crash) { struct sigaction new_action; new_action.sa_handler = sig_handler_print_movie_buffer; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction(SIGUSR1, &new_action, NULL); } char *stepping_data_fname = new char[200]; char *stepping_config_fname = new char[200]; char *movie_data_fname = new char[200]; char *movie_config_fname = new char[200]; sprintf(stepping_data_fname, "data/stepping_data_%s.txt", run_name); sprintf(stepping_config_fname, "data/stepping_config_%s.txt", run_name); sprintf(movie_data_fname, "data/stepping_movie_data_%s.txt", run_name); sprintf(movie_config_fname, "data/stepping_movie_config_%s.txt", run_name); //technically only need this if am_only_writing_on_crash is on, but do it just in case we turn it on later on_crash_old_movie_data_global_ptr = new movie_data_struct[MOVIE_BUFFER_SIZE]; on_crash_new_movie_data_global_ptr = new movie_data_struct[MOVIE_BUFFER_SIZE]; zero_movie_struct(on_crash_old_movie_data_global_ptr); sprintf(crash_movie_file_name_global, "data/stepping_movie_data_%s.txt", run_name); write_movie_config(movie_config_fname, iterations*dt); write_config_file(stepping_config_fname, 0, ""); printf("fake_radius_t: %g\n", fake_radius_t); printf("gt should be : %g\n", fake_radius_t*6*M_PI*water_viscosity_mu); printf("gt: %g\n\n", gt); printf("fake_radius_m: %g\n", fake_radius_m); printf("gm should be : %g\n", fake_radius_m*6*M_PI*water_viscosity_mu); printf("gm: %g\n\n", gm); printf("fake_radius_b: %g\n", fake_radius_b); printf("gb should be : %g\n", fake_radius_b*6*M_PI*water_viscosity_mu); printf("gb: %g\n\n", gb); job_msg_t job_msg; job_msg.max_iteration = 0; job_msg.start_time = clock(); job_msg.run_msg = run_name; job_msg.stepping_data_file = fopen(stepping_data_fname, "w"); job_msg.movie_data_file = 0; if (am_making_movie or am_debugging_onebound) { job_msg.movie_data_file = fopen(movie_data_fname, "w"); if (!job_msg.movie_data_file) { printf("Error opening %s!\n", movie_data_fname); exit(1); } setvbuf(job_msg.movie_data_file, NULL, _IOLBF, 0); // turn on line-buffering fprintf(job_msg.movie_data_file, "#State\ttime\tPE_b1\tPE_m1\tPE_t\tPE_m2\tPE_b2\t" "x1\ty1\tx2\ty2\tx3\ty3\tx4\ty4\tx5\ty5\t" "fx1\tfy1\tfx2\tfy2\tfx3\tfy3\tfx4\tfy4\tfx5\tfy5\n"); } fprintf(job_msg.stepping_data_file, "# command line:"); for (int i=0; i<argc; i++) { fprintf(job_msg.stepping_data_file, " %s", argv[i]); } printf("\n\n\n*********%s*********\n", run_name); fprintf(job_msg.stepping_data_file, "\n\n\n\n#********%s********\n", run_name); if (angle_logging_mode) fprintf(job_msg.stepping_data_file, "#state, time, tx displacement, ty displacement, recently bound motor angle, recently bound binding angle\n"); else fprintf(job_msg.stepping_data_file, "#time_unbind, time_bind, nbx_bind, fbx_bind, nmx_unbind, fmx_unbind, nmx_bind, fmx_bind\n"); if (errno) { perror("Error opening stepping data or movie file.\n"); exit(errno); } onebound_equilibrium_angles eq = onebound_post_powerstroke_internal_angles; double init_position[] = {eq.bba, eq.bma - M_PI + eq.bba, eq.ta + eq.bma - M_PI + eq.bba + 0.00001, eq.ta + eq.bma + eq.bba - eq.uma, 0.0, 0.0}; printf("Initial conditions: %g %g %g %g\n", init_position[0], init_position[1], init_position[2], init_position[3]); simulate(runtime, RAND_INIT_SEED, NEARBOUND, init_position, stepping_data_callback, &job_msg, NULL); fclose(job_msg.stepping_data_file); if (job_msg.movie_data_file) fclose(job_msg.movie_data_file); delete[] on_crash_old_movie_data_global_ptr; delete[] on_crash_new_movie_data_global_ptr; return EXIT_SUCCESS; }
int main(int argc, char** argv) { MICROTUBULE_BINDING_DISTANCE = -std::numeric_limits<double>::infinity(); MICROTUBULE_REPULSION_FORCE = 0.0; ONEBOUND_UNBINDING_FORCE = std::numeric_limits<double>::infinity(); T = 100; int iters = iterations / data_generation_skip_iterations; if (argc != 2) { printf("Error, TITLE variable must have underscores, not spaces.\n"); exit(1); } char* f_appended_name = argv[1]; char *config_fname = new char[200]; char *movie_config_fname = new char[200]; char *data_fname = new char[200]; sprintf(data_fname, "data/onebound_data_%s.bin", f_appended_name); sprintf(config_fname, "data/ob_config_%s.txt", f_appended_name); sprintf(movie_config_fname, "data/movie_config_%s.txt", f_appended_name); write_movie_config(movie_config_fname, iterations*dt); write_config_file(config_fname, CONFIG_INCLUDE_SKIPINFO, "Initial state: onebound\nInitial conformation: equilibrium\n"); void* job_msg[4]; job_msg[0] = (double*) &iterations; double current_time = clock(); job_msg[1] = ¤t_time; char run_msg[512]; sprintf(run_msg, "seed = %d", (int) RAND_INIT_SEED); job_msg[2] = run_msg; int data_fd = open(data_fname, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRGRP | S_IROTH); if (errno) { perror("Error creating data file"); exit(errno); } ftruncate(data_fd, iters*sizeof(onebound_data_generate_struct)); if (errno) { perror("Error ftruncating data file"); exit(errno); } void* data_mem = mmap(NULL, iters*sizeof(onebound_data_generate_struct), PROT_WRITE, MAP_SHARED, data_fd, 0); if (data_mem == MAP_FAILED) { perror("Error using mmap: "); exit(EXIT_FAILURE); } job_msg[3] = data_mem; onebound_equilibrium_angles eq = onebound_post_powerstroke_internal_angles; double init_position[] = {eq.bba, eq.bma + eq.bba - M_PI, eq.ta + eq.bma + eq.bba - M_PI, eq.ta + eq.bma + eq.bba - eq.uma, 0, 0}; simulate(iterations*dt, RAND_INIT_SEED, NEARBOUND, init_position, write_onebound_data_callback_with_avging, job_msg, NULL); munmap(data_mem, iters*sizeof(onebound_data_generate_struct)); close(data_fd); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { try{ // used to catch all unhandled Errors and Assertions // print copyright notice std::cout << "PlanetPenguin Racer " VERSION " -- http://racer.planetpenguin.de\n" << "(c) 2004-2006 PlanetPenguin Racer team\n" << "(c) 1999-2001 Jasmin F. Patry\n" << "<*****@*****.**>\n" << "PlanetPenguin Racer comes with ABSOLUTELY NO WARRANTY.\n" << "This is free software,\nand you are welcome to redistribute it under certain conditions.\n" << "See http://www.gnu.org/copyleft/gpl.html for details.\n" << std::endl; // initialize performance test if activated ppogl::initPerftest(); // set current directory to be used as base ppogl::os::setBaseDir(); // set user directory to "~/.ppracer/" ppogl::os::setUserDir(ppogl::os::getHomeDir()+".ppracer/"); // parse comandline options getopts(argc,argv); // set logging to be verbose if possible if(verbose){ init_log(); ppogl::Log::Instance()->setLevel(ppogl::LogUnknown); if(verbose>1){ // set log system to print long messages ppogl::Log::Instance()->setVerbose(true); init_log(); } } // seed the random number generator srand( time(NULL) ); if(GameMode::exp_multiscreen==GameMode::MULTISCREEN_NONE){ GameMgr::getInstance().numPlayers = 1; }else{ GameMgr::getInstance().numPlayers = 2; } ppogl::Config::getInstance().init(&script,"ppconfig"); register_cfile_callbacks(); bool create_cfile=true; if(cfile.empty()){ cfile=get_config_file_name(); } if( !resetConfig && ppogl::os::isFile(cfile) ){ script.doFile(cfile); // check whether the user set the data directory per commandline option if(data_dir.empty()){ data_dir = PPConfig.getString("data_dir"); } PP_MESSAGE("Load config file"); create_cfile=false; }else if(data_dir.empty()){ data_dir = DATA_DIR; } if(ppogl::os::isDirectory(data_dir)==false){ PP_ERROR("Unable to find data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } if(ppogl::os::isFile(data_dir+"/config.nut")==false){ PP_ERROR("Unable to find needed file config.nut in the data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } script.doFile(data_dir+"/config.nut"); PPConfig.setString("data_dir",data_dir); if(create_cfile){ write_config_file(); } /* * Initialize rendering context, create window */ winsys_init(WINDOW_TITLE, WINDOW_TITLE); /* * Initial OpenGL settings */ gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // init compiled_vertex extension gl::EXTcompiledVertexArrayInit(); // print OpenGL debugging information if(verbose) print_gl_info(); /* * Load the game data and initialize game state */ register_key_frame_callbacks(); Course::registerCallbacks(); FogPlane::registerCallbacks(); register_course_light_callbacks(); PartSys::registerCallbacks(); register_course_manager_callbacks(); register_hier_callbacks(); register_tux_callbacks(); // init audio PP_MESSAGE("Init audio"); if(PPConfig.getBool("disable_audio")==false){ bool stereo = PPConfig.getBool("audio_stereo"); ppogl::AudioMgr::Format format; int freq; switch(PPConfig.getInt("audio_format_mode")){ case 0: format = ppogl::AudioMgr::FORMAT_8; break; case 1: format = ppogl::AudioMgr::FORMAT_16; break; default: format = ppogl::AudioMgr::FORMAT_8; } switch(PPConfig.getInt("audio_freq_mode")){ case 0: freq = ppogl::AudioMgr::FQ_11; break; case 1: freq = ppogl::AudioMgr::FQ_22; break; case 2: freq = ppogl::AudioMgr::FQ_44; break; default: freq = ppogl::AudioMgr::FQ_11; } ppogl::AudioMgr::getInstance().init(freq,format,stereo); if(PPConfig.getBool("sound_enabled")==false){ ppogl::AudioMgr::getInstance().enableSound(false); } if(PPConfig.getBool("music_enabled")==false){ ppogl::AudioMgr::getInstance().enableMusic(false); } // set volumes ppogl::AudioMgr::getInstance().setMusicVolume( PPConfig.getInt("music_volume")); ppogl::AudioMgr::getInstance().setSoundVolume( PPConfig.getInt("sound_volume")); } PP_MESSAGE("Load translation: " << PPConfig.getString("ui_language")); // Setup translations script.doFile(data_dir+"/translations/languages.nut"); script.doFile(data_dir+"/translations/"+PPConfig.getString("ui_language")+".nut"); script.doFile(data_dir+"/init.nut"); // load "cached" configuration values GameConfig::update(); fpsCounter.setMaxFPS(PPConfig.getInt("gui_max_fps")); PP_MESSAGE("Init joystick"); GameMode::joystick.init(); init_ui_snow(); for(int i=0; i<GameMgr::getInstance().numPlayers; i++){ // Placeholder name until we give players way to enter name players[i].name = "tux"; players[i].loadData(); players[i].num = i; } GameMode::mode = GameMode::NO_MODE; if(Benchmark::getMode()==Benchmark::NONE){ GameMode::setMode(GameMode::SPLASH); }else{ GameMode::setMode(GameMode::BENCHMARK); } GameMgr::getInstance().difficulty = CourseData::DIFFICULTY_NORMAL; SDL_ShowCursor(false); PP_MESSAGE("Entering event loop"); winsys_process_events(); return 0; }catch(ppogl::Error &e){ /* * It's possible that an exception is thrown outside of main. * In most cases this is a problem with the object * destruction during program termination. * If we see the abort message (see below) we known * that the exception is thrown within main(). */ std::cerr << "Aborting main function :(" << std::endl; abort(); } }
int32_t main(int argc, char *argv[]) { /* Constants */ static const char *DMOCONNECT = "AT+DMOCONNECT"; static const char *DMOSETGROUP = "AT+DMOSETGROUP"; static const char *DMOSETVOLUME = "AT+DMOSETVOLUME"; static const char *SCANFREQ = "S+"; static const char *SETFILTER = "AT+SETFILTER"; /*static const char *SETTAIL = "AT+SETTAIL";*/ static const char *GETRSSI = "RSSI?"; static const char *GETVERSION = "AT+VERSION"; static const char *conf_file = "last.cfg"; int32_t fd; char received[BUFFERSIZE] = {0}; char transmit[BUFFERSIZE] = {0}; bool success = true; /* Check if the last or default config is available */ if (EXIT_FAILURE == check_config(conf_file, &avail_args)) { return EXIT_FAILURE; } /* Get parameters from arguments */ get_parameters_from_args(argc, argv, &avail_args); /* Check if 'serial port' option (-D) is entered, open and configure serial port */ if ((NULL == avail_args.s_portname) && (!debug_flag)) { exit_serial_port_not_specified(); } else { fd = open(avail_args.s_portname, O_RDWR | O_NOCTTY | O_SYNC); } if ((fd < 0) && (!debug_flag)) { printf("Error when opening %s: %s", avail_args.s_portname, strerror (errno)); return -errno; } if (!debug_flag) { /* set speed to 9600 bps, 8n1 (no parity), blocking */ set_interface_attribs(fd, B9600, 0, 1); } printf("Configuring sa818 module, wait...\n\n"); sprintf(transmit, "%s\r\n", DMOCONNECT); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("%s failed!\n", DMOCONNECT); return(EXIT_FAILURE); } if (rssi_flag) { sprintf(transmit, "%s\r\n", GETRSSI); send_command(fd, transmit, received); printf("%s", received); } if (version_flag) { sprintf(transmit, "%s\r\n", GETVERSION); send_command(fd, transmit, received); printf("%s", received); } if (rssi_flag || version_flag) { return EXIT_SUCCESS; } sprintf(transmit, "%s=%d,%3.4f,%3.4f,%s,%d,%s\r\n", DMOSETGROUP, avail_args.bw, \ avail_args.transmit_freq, avail_args.receive_freq, avail_args.tx_subaud, avail_args.squelch, avail_args.rx_subaud); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("%s failed!\n", DMOSETGROUP); success = false; } sprintf(transmit, "%s%3.4f\r\n", SCANFREQ, avail_args.scan_freq); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("Radiochannel at the %3.4f MHz is NOT FOUND!\n", avail_args.scan_freq); } else { printf("Radiochannel at the %3.4f MHz is FOUND!\n", avail_args.scan_freq); } sprintf(transmit, "%s=%d\r\n", DMOSETVOLUME, avail_args.volume); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("%s failed!\n", DMOSETVOLUME); success = false; } sprintf(transmit, "%s=%s\r\n", SETFILTER, avail_args.filter); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("%s failed!\n", SETFILTER); success = false; } /* sprintf(transmit, "%s=%d\r\n", SETTAIL, avail_args.tail); send_command(fd, transmit, received); if (EXIT_SUCCESS != check_command_result(received)) { printf("%s failed!\n", SETTAIL); success = false; } */ if (true == success) { printf("\nsa818-V module configuration successfull!\nWriting configuration to the %s\n", conf_file); write_config_file(conf_file, &avail_args); } close(fd); return EXIT_SUCCESS; }
int main(int argc, gchar * argv[]) { int retval; int num_samples = SCOPE_NUM_SAMPLES_DEFAULT; void *shm_base; /* process and remove any GTK specific command line args */ gtk_init(&argc, &argv); /* process halscope command line args (if any) here */ if(argc > 1) num_samples = atoi(argv[1]); if(num_samples <= 0) num_samples = SCOPE_NUM_SAMPLES_DEFAULT; /* connect to the HAL */ comp_id = hal_init("halscope"); if (comp_id < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "SCOPE: ERROR: hal_init() failed\n"); return -1; } if (!halpr_find_funct_by_name("scope.sample")) { char buf[1000]; sprintf(buf, EMC2_BIN_DIR "/halcmd loadrt scope_rt num_samples=%d", num_samples); if(system(buf) != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "loadrt scope_rt failed\n"); hal_exit(comp_id); exit(1); } } /* set up a shared memory region for the scope data */ shm_id = rtapi_shmem_new(SCOPE_SHM_KEY, comp_id, sizeof(scope_shm_control_t)); if (shm_id < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "SCOPE: ERROR: failed to get shared memory\n"); hal_exit(comp_id); return -1; } retval = rtapi_shmem_getptr(shm_id, &shm_base); if (retval < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "SCOPE: ERROR: failed to map shared memory\n"); rtapi_shmem_delete(shm_id, comp_id); hal_exit(comp_id); return -1; } hal_ready(comp_id); /* register an exit function to cleanup and disconnect from the HAL */ g_atexit(exit_from_hal); /* init control structure */ ctrl_usr = &ctrl_struct; init_usr_control_struct(shm_base); /* init watchdog */ ctrl_shm->watchdog = 10; /* set main window */ define_scope_windows(); /* this makes the application exit when the window is closed */ gtk_signal_connect(GTK_OBJECT(ctrl_usr->main_win), "destroy", GTK_SIGNAL_FUNC(main_window_closed), NULL); gtk_signal_connect(GTK_OBJECT(ctrl_usr->main_win), "focus-in-event", GTK_SIGNAL_FUNC(set_focus), NULL); /* define menu windows */ /* do next level of init */ init_horiz(); init_vert(); init_trig(); init_display(); init_run_mode_window(); /* register signal handlers for ctrl-C and SIGTERM */ signal(SIGINT, quit); signal(SIGTERM, quit); /* The interface is now completely set up */ /* show the window */ gtk_widget_show(ctrl_usr->main_win); /* read the saved config file */ read_config_file(".scope.cfg"); /* arrange for periodic call of heartbeat() */ gtk_timeout_add(100, heartbeat, NULL); /* enter the main loop */ gtk_main(); write_config_file(".scope.cfg"); return (0); }