static void bcg_fini(Int exitcode) { struct write_file output; Char buf[128]; int x; struct hash_entry *he; unsigned long magic; x = 0; do { x++; VG_(sprintf)(buf, "callgraph%d.dat", x); } while (open_write_file(&output, buf) != 0); magic = 0xaabbccddeeff; write_file(&output, &magic, sizeof(magic)); for (x = 0; x < NR_HASH_HEADS; x++) { for (he = hash_heads[x]; he; he = he->next) { tl_assert(he->nr_entries > 0); write_file(&output, &he->src, sizeof(he->src)); write_file(&output, &he->nr_entries, sizeof(he->nr_entries)); write_file(&output, he->dest, sizeof(he->dest[0]) * he->nr_entries); } } close_write_file(&output); }
void file_inf() { int ok; FILE *fp; char filename[256]; sprintf(filename,"%s.pars",this_file); ping(); if(!file_selector("Save info",filename,"*.pars*"))return; /* if(new_string("Filename: ",filename)==0)return; */ open_write_file(&fp,filename,&ok); if(!ok)return; redraw_params(); do_info(fp); fclose(fp); }
int accept_handler(http_conf *g, http_connect_t *con, struct epoll_event *ev) { con->in = (request *)request_init(con->p); con->out = (response *)request_init(con->p); read_header(con); parse_header(con); epoll_edit_fd(g->epfd, ev, EPOLL_W); epoll_del_fd(g->epfd, ev); if(con->in->http_method == _PUT) { open_write_file(con); con->next_handle = write_file_content; } /*close(con->fd); pool_destroy(con->p);*/ return 0; }
bool SaveData::save(const std::string& filename) { char filler[50] = "GTLGTLGTLGTLGTLGTLGTLGTLGTLGTLGTLGTLGTLGTL"; // for RESERVED SDL_RWops *outfile; char temp_filename[80]; char savedgame[41]; memset(savedgame, 0, 41); char temp_campaign[41]; memset(temp_campaign, 0, 41); char temptext[10] = "GTL"; char temp_version = 9; Uint32 newcash = totalcash; Uint32 newscore = totalscore; // short numguys; short listsize; short i; char guyname[12] = "JOE"; char temp_order, temp_family; short temp_str, temp_dex, temp_con; short temp_short, temp_arm, temp_lev; unsigned char numplayers = this->numplayers; Uint32 temp_exp; short temp_kills; Sint32 temp_level_kills; Sint32 temp_td, temp_th, temp_ts; short temp_teamnum; short temp_allied; short temp_registered; // Format of a team list file is: // 3-byte header: 'GTL' // 1-byte version number // 2-bytes Registered or not // Version 7+ // 40-bytes saved-game name, dummy here // 40-bytes current campaign ID // Version 8+ // 2-bytes (short) = scenario number // 4-bytes (Sint32)= cash (unsigned) // 4-bytes (Sint32)= score (unsigned) // 4-bytes (Sint32)= cash-B (unsigned) // All alternate scores // 4-bytes (Sint32)= score-B (unsigned) // version 6+ // 4-bytes (Sint32)= cash-C (unsigned) // 4-bytes (Sint32)= score-C (unsigned) // 4-bytes (Sint32)= cash-D (unsigned) // 4-bytes (Sint32)= score-D (unsigned) // 2-bytes allied setting // Version 7+ // 2-bytes (short) = # of team members in list // 1-byte number of players // 31-bytes RESERVED // List of n objects, each of 58-bytes of form: // 1-byte ORDER // 1-byte FAMILY // 12-byte name // 2-bytes strength // 2-bytes dexterity // 2-bytes constitution // 2-bytes intelligence // 2-bytes armor // 2-bytes level // Does not include upgraded stats in versions 8 or lower // 4-bytes Uint32 experience // 2-bytes # kills, v.3+ // 4-bytes # total levels killed, v.3+ // 4-bytes total damage delt, v.4+ // 4-bytes total hits inflicted, v.4+ // 4-bytes total shots made, v.4+ // 2-bytes team number, v.5+ // 2*4 = 8 bytes RESERVED // List of 500 (max scenarios) 1-byte scenario-level status // Versions 1-7 // 2-bytes Number of campaigns in list // Version 8+ // List of n campaigns // Version 8+ // 40-bytes Campaign ID string // 2-bytes Current level in this campaign // 2-bytes Number of level indices in list // List of n level indices // 2-bytes Level index //strcpy(temp_filename, scen_directory); Log("Saving save: %s\n", filename.c_str()); strcpy(temp_filename, filename.c_str()); strcat(temp_filename, ".gtl"); // gladiator team list if ( (outfile = open_write_file("save/", temp_filename)) == NULL ) // open for write { //gotoxy(1, 22); Log("Error in writing team file %s\n", filename.c_str()); return 0; } // Write id header SDL_RWwrite(outfile, temptext, 3, 1); // Write version number SDL_RWwrite(outfile, &temp_version, 1, 1); // Versions 7+ include a mark for registered or not temp_registered = 1; SDL_RWwrite(outfile, &temp_registered, 2, 1); // Write the name strncpy(savedgame, save_name.c_str(), 40); SDL_RWwrite(outfile, savedgame, 40, 1); // Write current campaign Log("Saving campaign status: %s\n", current_campaign.c_str()); strncpy(temp_campaign, current_campaign.c_str(), 40); SDL_RWwrite(outfile, temp_campaign, 40, 1); // Write scenario number short temp_scenario = scen_num; SDL_RWwrite(outfile, &temp_scenario, 2, 1); // Write cash SDL_RWwrite(outfile, &newcash, 4, 1); // Write score SDL_RWwrite(outfile, &newscore, 4, 1); // Versions 6+ have a score for each possible team for (i=0; i < 4; i++) { newcash = m_totalcash[i]; SDL_RWwrite(outfile, &newcash, 4, 1); newscore = m_totalscore[i]; SDL_RWwrite(outfile, &newscore, 4, 1); } // Versions 7+ include the allied mode information temp_allied = allied_mode; SDL_RWwrite(outfile, &temp_allied, 2, 1); // Determine size of team list ... listsize = team_size; //gotoxy(1, 22); //Log("Team size: %d ", listsize); SDL_RWwrite(outfile, &listsize, 2, 1); SDL_RWwrite(outfile, &numplayers, 1, 1); // Write the reserved area, 31 bytes SDL_RWwrite(outfile, filler, 31, 1); // Okay, we've written header .. now dump the data .. for(int i = 0; i < team_size; i++) { guy* temp_guy = team_list[i]; // Get temp values to be saved temp_order = ORDER_LIVING; temp_family= temp_guy->family; // Write name of current guy... strcpy(guyname, temp_guy->name); // Set any chars under 12 not used to 0 .. for (int j = strlen(guyname); j < 12; j++) guyname[j] = 0; temp_str = temp_guy->strength; temp_dex = temp_guy->dexterity; temp_con = temp_guy->constitution; temp_short = temp_guy->intelligence; temp_arm = temp_guy->armor; temp_lev = temp_guy->get_level(); temp_exp = temp_guy->exp; // Version 3+ below here temp_kills = temp_guy->kills; temp_level_kills = temp_guy->level_kills; // Version 4+ below here temp_td = temp_guy->total_damage; temp_th = temp_guy->total_hits; temp_ts = temp_guy->total_shots; // Version 5+ below here temp_teamnum = temp_guy->teamnum; // Now write all those values SDL_RWwrite(outfile, &temp_order, 1, 1); SDL_RWwrite(outfile, &temp_family,1, 1); SDL_RWwrite(outfile, guyname, 12, 1); SDL_RWwrite(outfile, &temp_str, 2, 1); SDL_RWwrite(outfile, &temp_dex, 2, 1); SDL_RWwrite(outfile, &temp_con, 2, 1); SDL_RWwrite(outfile, &temp_short, 2, 1); SDL_RWwrite(outfile, &temp_arm, 2, 1); SDL_RWwrite(outfile, &temp_lev, 2, 1); SDL_RWwrite(outfile, &temp_exp, 4, 1); SDL_RWwrite(outfile, &temp_kills, 2, 1); SDL_RWwrite(outfile, &temp_level_kills, 4, 1); SDL_RWwrite(outfile, &temp_td, 4, 1); SDL_RWwrite(outfile, &temp_th, 4, 1); SDL_RWwrite(outfile, &temp_ts, 4, 1); SDL_RWwrite(outfile, &temp_teamnum, 2, 1); // And the filler SDL_RWwrite(outfile, filler, 8, 1); } // Write the completed levels // Make sure our current level is saved std::map<std::string, int>::iterator cur = current_levels.find(current_campaign); if(cur != current_levels.end()) { cur->second = scen_num; } else current_levels.insert(std::make_pair(current_campaign, scen_num)); // Number of campaigns short num_campaigns = completed_levels.size(); SDL_RWwrite(outfile, &num_campaigns, 2, 1); for(std::map<std::string, std::set<int> >::const_iterator e = completed_levels.begin(); e != completed_levels.end(); e++) { // Campaign ID char campaign[41]; memset(campaign, 0, 41); strcpy(campaign, e->first.c_str()); SDL_RWwrite(outfile, campaign, 1, 40); short index = 1; std::map<std::string, int>::const_iterator g = current_levels.find(e->first); if(g != current_levels.end()) index = g->second; SDL_RWwrite(outfile, &index, 2, 1); // Number of levels short num_levels = e->second.size(); SDL_RWwrite(outfile, &num_levels, 2, 1); for(std::set<int>::const_iterator f = e->second.begin(); f != e->second.end(); f++) { // Level index index = *f; SDL_RWwrite(outfile, &index, 2, 1); } } SDL_RWclose(outfile); return 1; }
int main(int argc, char **argv){ // perform sanity check on arguments if(argc < 3 || argc > 6){ print_help(argv[0]); return 1; } // process argument options int c = 3; while(c < argc){ if(strcmp(argv[c], WARN_FLAG) == 0) warnings = 1; else if(strcmp(argv[c], SYST_FLAG) == 0) print_tables = 1; else if(strcmp(argv[c], COMP_INFO) == 0) print_comp_i = 1; else if(strcmp(argv[c], HELP_FLAG) == 0) print_help(argv[0]); else if(strcmp(argv[c], FAST_FLAG) == 0) make_fast = 1; else{ print_asterisk(RED_C, stderr); fprintf(stderr, "Unknown flag '%s'.\n\n", argv[c]); print_help(argv[0]); return 1; } c++; } // try to open/create the files the user wants us to use FILE *input_file = fopen(argv[1], "r"); FILE *out_file = 0; if(!input_file){ print_asterisk(RED_C, stderr); fprintf(stderr, "Error: Unable to open '%s' for " "reading, exiting.\n", argv[1]); return 2; } out_file = open_write_file(argv[2]); if(!out_file){ print_asterisk(RED_C, stderr); fprintf(stderr, "Error: Unable to open '%s' for writing, exiting.\n", argv[2]); return 2; } // print banner if(print_comp_i){ printf( "\t\t=== Hartz Translator ===\n" "Machine Constraints\n" "\t%d Bytes of Memory\n" "\t%d Registers\n" "\t%d Bytes of Cache\n\n" "Compiler Constraints\n" "\tMax Line Length of %d Bytes\n" "\tMax One Instruction Per Line\n\n", MAX_MEMORY, MAX_REGS, MAX_CACHE, MAX_LINE_LEN); } // setup our program struct to store some data struct program *program = (struct program*) malloc(sizeof(struct program)); memset(program, 0, sizeof(struct program)); program->out = out_file; program->input = argv[1]; program->in = input_file; if(make_fast){ write_instruc_str(HALT, 0, 0, 0, 0, program); fclose(input_file); fclose(out_file); return 0; } // create the symbol table struct symbol_table *tbl = (struct symbol_table*) malloc( sizeof(struct symbol_table)); memset(tbl, 0, sizeof(struct symbol_table)); program->tbl = tbl; // Create the table for constants struct symbol_table *const_tbl = (struct symbol_table*) malloc( sizeof(struct symbol_table)); memset(const_tbl, 0, sizeof(struct symbol_table)); program->const_tbl = const_tbl; // start processing file process_input_program(program); fclose(input_file); fclose(out_file); if(print_tables){ printf("\n"); print_symbols(program->tbl); print_symbols(program->const_tbl); printf("\n"); } if(program->error_code){ print_asterisk(RED_C, stderr); fprintf(stderr, "Stopped processing because of an error.\n"); } else{ print_asterisk(GRN_C, stdout); printf("Done!\n"); } }