/** * \brief Saves the data into a Lua file. * \param[in] file_name Path of the file to save. * The file will be encoded in UTF-8. * \return \c true in case of success, \c false if the data * could not be exported. */ bool LuaData::export_to_file(const std::string& file_name) const { // Work on a temporary file to keep the initial one intact in case of failure. std::string tmp_file_name = file_name + ".solarus_tmp"; std::ofstream tmp_out(tmp_file_name); if (!tmp_out) { return false; } if (!export_to_lua(tmp_out)) { std::remove(tmp_file_name.c_str()); return false; } tmp_out.flush(); tmp_out.close(); std::ifstream in(tmp_file_name); if (!in) { return false; } std::ofstream out(file_name); if (!out) { return false; } out << in.rdbuf(); in.close(); std::remove(tmp_file_name.c_str()); out.flush(); return true; }
void assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x, rtx_reuse_manager *reuse_manager) { named_temp_file tmp_out (".rtl"); FILE *outfile = fopen (tmp_out.get_filename (), "w"); rtx_writer w (outfile, 0, false, true, reuse_manager); w.print_rtl (x); fclose (outfile); char *dump = read_file (SELFTEST_LOCATION, tmp_out.get_filename ()); ASSERT_STREQ_AT (loc, expected_dump, dump); free (dump); }
void generate_input_file(Configuration &conf) { init_output_folder(conf); int in_start_line=1,in_end_line=1; int out_start_line=1,out_end_line=1; /**< Multi_Test_Case */ if(conf.Multi_Test_Case) { in_start_line=2,in_end_line=2; out_start_line=1,out_end_line=1; } int current_file_number=1; ofstream in_fout; ofstream out_fout; ofstream slice_fout; char current_in_file_name[100]; char current_out_file_name[100]; char current_slice_file_name[100]; sprintf(current_in_file_name,"..\\output\\%d.in",current_file_number); sprintf(current_out_file_name,"..\\output\\%d.out",current_file_number); sprintf(current_slice_file_name,"..\\output\\%d.slice",current_file_number); in_fout.open(current_in_file_name); /**< Multi_Test_Case */ if(conf.Multi_Test_Case) { in_fout<<conf.CAPACITY_NUM<<endl; } out_fout.open(current_out_file_name); slice_fout.open(current_slice_file_name); string data_line; puts("------------------------------ Generating Data ----------------------------"); for(int i=0; i<conf.TEST_CASE_NUM; ++i) { ofstream tmp_in_fout("..\\bin\\tmp.in"); create_one_test_case(tmp_in_fout); tmp_in_fout.close(); create_tmp_out(); if(i!=0 && i%conf.CAPACITY_NUM==0) // change to next file { printf("[successful] generate data : %2d\n",current_file_number); // close current file in_fout.close(); out_fout.close(); slice_fout.close(); current_file_number++; in_start_line=1,in_end_line=1; out_start_line=1,out_start_line=1; /**< Multi_Test_Case */ if(conf.Multi_Test_Case) { in_start_line=2,in_end_line=2; out_start_line=1,out_end_line=1; } sprintf(current_in_file_name,"..\\output\\%d.in",current_file_number); sprintf(current_out_file_name,"..\\output\\%d.out",current_file_number); sprintf(current_slice_file_name,"..\\output\\%d.slice",current_file_number); in_fout.open(current_in_file_name); /**< Multi_Test_Case */ if(conf.Multi_Test_Case) { in_fout<<conf.CAPACITY_NUM<<endl; } out_fout.open(current_out_file_name); slice_fout.open(current_slice_file_name); } // write data to *.in , *.out , *.slice ifstream tmp_in("..\\bin\\tmp.in"); ifstream tmp_out("..\\bin\\tmp.out"); int cnt_tmp_in=0; int cnt_tmp_out=0; while(getline(tmp_in,data_line)) { in_fout<<data_line<<endl; ++cnt_tmp_in; } while(getline(tmp_out,data_line)) { out_fout<<data_line<<endl; ++cnt_tmp_out; } in_end_line=in_start_line+cnt_tmp_in-1; out_end_line=out_start_line+cnt_tmp_out-1; slice_fout<<in_start_line<<" "<<in_end_line<<" "<<out_start_line<<" "<<out_end_line<<endl; in_start_line=in_end_line+1; out_start_line=out_end_line+1; tmp_in.close(); tmp_out.close(); } printf("[successful] generate data : %2d\n",current_file_number); in_fout.close(); out_fout.close(); slice_fout.close(); puts("-----------------------------------------------------------------------------"); }