📄 manage_test.cpp
字号:
while (true) { int ch = message_box(msg, "Question"); if (ch == 'y') break; if (ch == 'n') return; } char conf_section[STRING_MAX_LEN]; sprintf(conf_section, "%s.general", probname); conf.delsection(conf_section); sprintf(conf_section, "%s.points", probname); conf.delsection(conf_section); int np; if (!conf.read("general", "problems_num", np)) { report_err("Fail to read @problems_num.\n", __PRETTY_FUNCTION__, __LINE__); return; } for (int i = prob; i < np - 1; i ++) { sprintf(conf_item, "problem_%d_name", i + 1); char tmp[STRING_MAX_LEN + 1]; if (!conf.read("general", conf_item, tmp, STRING_MAX_LEN)) { report_err("Fail to read configuration file.\n", __PRETTY_FUNCTION__, __LINE__); return; } sprintf(conf_item, "problem_%d_name", i); conf.write("general", conf_item, tmp); } sprintf(conf_item, "problem_%d_name", np - 1); conf.delitem("general", conf_item); np --; conf.write("general", "problems_num", np);}void modify_problem(Conf &conf, int prob){ const char *OPERATION_REMINDER = "Press 'h' for help."; static const int WIN_POINTS_WIDTH = 10; int opr_nlines = get_str_nlines(OPERATION_REMINDER); Window main_win; Window win_info(get_nlines() - opr_nlines, get_ncols() - WIN_POINTS_WIDTH, opr_nlines, WIN_POINTS_WIDTH); Menu menu; bool done = false; static const int key_allowable[] = {'h', 'a', 'd', ENTER, 'n', 'r', 0}; Problem_conf pconf(conf, prob); while (!done) { int npoints = pconf.points.size(); char **menu_items = new char*[npoints + 2]; menu_items[0] = new char[STRING_MAX_LEN]; strcpy(menu_items[0], "general"); for (int i = 1; i <= npoints; i ++) { menu_items[i] = new char[STRING_MAX_LEN]; sprintf(menu_items[i], "%d", i); } menu_items[npoints + 1] = NULL; menu.set_arg(main_win, menu_items, key_allowable, OPERATION_REMINDER, 0, WIN_POINTS_WIDTH, opr_nlines, 0); while (true) { win_info.clean(); int cur = menu.get_choice(); if (cur == 0) { win_info.printf("Input file name: %s\n", pconf.input); win_info.printf("Output file name: %s\n", pconf.output); win_info.printf("Source file name: %s\n", pconf.source); }else { cur --; win_info.printf("Input file path: %s\n", pconf.points[cur].input); win_info.printf("Output file path: %s\n", pconf.points[cur].output); win_info.printf("Time limit[s]: %d\n", pconf.points[cur].time); win_info.printf("Score: %f\n", pconf.points[cur].score); } update(); int ch; if (menu.wait_move_key(ch)) continue; if (ch == 'h') { static const char *HELP = "\KEY DESCRIPTION \n\ a add new test points manually\n\ d delete a subsistent test point \n\ENTER modify a subsistent test point(or general options) \n\ n autamatically add new test points \n\ (standard input and output data files should be put in the \n\ directory \"data/<problem name>\", and there should not be \n\ any other file in that directory) \n\ r return to the last menu"; message_box(HELP, "HELP"); continue; } if (ch == 'r') { done = true; break; } if (ch == 'a') { add_new_test_points(pconf.points, pconf.name); break; } if (ch == ENTER) { cur = menu.get_choice(); if (cur == 0) { char input[STRING_MAX_LEN]; read_input("Please enter a new input file name: ", pconf.input, NULL, pconf.input); read_input("Please enter a new output file name: ", pconf.output, NULL, pconf.output); read_input("Please enter a new source file name: ", pconf.source, NULL, pconf.source); } else { cur --; modify_test_point(pconf.points[cur]); } continue; } else if (ch == 'd') { int cur = menu.get_choice(); if (cur > 0) { cur --; Test_point_array::iterator i = pconf.points.begin(); i += cur; pconf.points.erase(i); break; }else { message_box("Oh, you can not do so..."); continue; } } else if (ch == 'n') { auto_add_prob_points(pconf, conf.get_file_path()); break; } } for (int i = 0; i <= npoints; i ++) delete []menu_items[i]; delete []menu_items; } pconf.write_conf(conf);}void modify_test_point(Test_point &tp){ Window win_mtp(10, 90); const char *OPERATION_REMINDER = "Press ENTER to modify a value, or 'r' to accept changes and return to the last menu."; char *menu_items[5]; menu_items[4] = NULL; for (int i = 0; i < 4; i ++) menu_items[i] = new char[STRING_MAX_LEN]; static const int key_allowable[] = {ENTER, 'r', 0}; Menu menu; while (true) { sprintf(menu_items[0], "Input file path: %s", tp.input); sprintf(menu_items[1], "Output file path: %s", tp.output); sprintf(menu_items[2], "Time limit: %d", tp.time); sprintf(menu_items[3], "Score: %f", tp.score); menu.set_arg(win_mtp, menu_items, key_allowable, OPERATION_REMINDER); int key_pressed = menu.wait_key(); if (key_pressed == 'r') break; if (key_pressed == ENTER) { int choice = menu.get_choice(); char data[STRING_MAX_LEN]; int old_i; double old_d; switch (choice) { case 0 : read_input("Please enter a new input file path: ", tp.input, NULL, tp.input); break; case 1 : read_input("Please enter a new output file path: ", tp.output, NULL, tp.output); break; case 2 : read_input("Please enter a new time limit[s]: ", data); old_i = tp.time; if (sscanf(data, "%d", &tp.time) == EOF) tp.time = old_i; break; case 3 : read_input("Please enter a new score: ", data); old_d = tp.score; if (sscanf(data, "%lf", &tp.score) == EOF) tp.score = old_d; break; } } } for (int i = 0; i < 4; i ++) delete []menu_items[i];}void modify_contest_opt(Contest_option &co){ if (co.compiler_ext.size() != co.compiler_command.size()) { report_err("Strang error occurred.\n", __PRETTY_FUNCTION__, __LINE__); return; } Window main_win; const char *OPERATION_REMINDER = "Press 'a' to add a new compiler, 'd' to delete a subsistent compiler, ENTER to modify a subsistent compiler or a option, or 'r' to return to the last menu.\n"; static const int key_allowable[] = {'a', 'd', ENTER, 'r', 0}; Menu menu; while (true) { char **menu_items = new char*[co.compiler_ext.size() + 3]; menu_items[0] = new char[STRING_MAX_LEN]; sprintf(menu_items[0], "the name of the contest: %s", co.contest_name); menu_items[1] = new char[STRING_MAX_LEN]; sprintf(menu_items[1], "source file directory: %s", co.source_path); for (Str_array::size_type i = 0; i < co.compiler_ext.size(); i ++) { menu_items[i + 2] = new char[STRING_MAX_LEN]; sprintf(menu_items[i+ 2], "%s : %s", co.compiler_ext[i].c_str(), co.compiler_command[i].c_str()); } menu_items[co.compiler_ext.size() + 2] = NULL; menu.set_arg(main_win, menu_items, key_allowable, OPERATION_REMINDER); int ch, key_pressed; do { key_pressed = menu.wait_key(); ch = menu.get_choice(); } while (key_pressed == 'd' && ch < 2); for (unsigned int i = 0; i < co.compiler_ext.size(); i ++) delete []menu_items[i]; delete []menu_items; if (key_pressed == 'a') { char tmp[STRING_MAX_LEN]; read_input("Please enter the extand part of the file: ", tmp); co.compiler_ext.push_back(tmp); read_input("Please enter the command to run the compiler: ", tmp); co.compiler_command.push_back(tmp); continue; } if (key_pressed == 'd') { co.compiler_ext.erase(co.compiler_ext.begin() + ch); co.compiler_command.erase(co.compiler_command.begin() + ch); continue; } if (key_pressed == ENTER) { char tmp[STRING_MAX_LEN]; if (ch >= 2) { read_input("Please enter the command to run the compiler: ", tmp, NULL, co.compiler_command[ch - 2].c_str()); co.compiler_command[ch - 2] = tmp; continue; }else if (ch == 0) { read_input("Please enter a new name for the contest: ", tmp); strcpy(co.contest_name, tmp); continue; } else { read_input("Please enter the path of the source file directory: ", tmp); strcpy(co.source_path, tmp); continue; } } break; }}void func3(const char *path){ static const char *OPERATION_REMINDER = "Press ENTER to see the details, 'e' to export the result as a HTML file, or 'r' to return to the main menu.\n [SCORE] [TIME(s)] [CONTESTANT]"; Conf conf(path); Str_array probnames; Conr_array conr; init_contestant_result(probnames, conr, conf, path); if (conr.size() == 0) { message_box("No judge result to print.", "ERROR"); return; } char **menu_items = new char *[conr.size() + 1]; for (Conr_array::size_type i = 0; i < conr.size(); i ++) { menu_items[i] = new char[STRING_MAX_LEN]; sprintf(menu_items[i], "%-10.2f %-10.3f %s", conr[i].total_score, conr[i].total_time / 1e+6, conr[i].name.c_str()); } menu_items[conr.size()] = NULL; static const int key_allowable[] = {ENTER, 'r', 'e', 0}; Window main_win; Menu menu; menu.set_arg(main_win, menu_items, key_allowable, OPERATION_REMINDER); while (true) { int key_pressed = menu.wait_key(); if (key_pressed == 'r') break; if (key_pressed == ENTER) show_contestant_detail(probnames, conr[menu.get_choice()]); else { char filename[STRING_MAX_LEN]; read_input("Please enter the path of the HTML file:", filename, "result.htm"); if (!save_html(filename, conr, conf, probnames)) report_err("Failed to export the result.", __PRETTY_FUNCTION__, __LINE__); } } for (Conr_array::size_type i = 0; i < conr.size(); i ++) delete []menu_items[i]; delete []menu_items;}void init_contestant_result(Str_array &probnames, Conr_array &conr, const Conf &conf, const char *conf_path){ probnames.clear(); conr.clear(); int nproblems; if (!conf.read("general", "problems_num", nproblems)) { report_err("Failed to read @nproblems.", __PRETTY_FUNCTION__, __LINE__); return; } for (int i = 0; i < nproblems; i ++) { char conf_item[STRING_MAX_LEN], tmp[STRING_MAX_LEN + 1]; sprintf(conf_item, "problem_%d_name", i); if (!conf.read("general", conf_item, tmp, STRING_MAX_LEN)) { report_err("Failed to read the name of a problem.", __PRETTY_FUNCTION__, __LINE__); return; } probnames.push_back(tmp); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -