forked from laekov/acejudge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.cc
More file actions
143 lines (131 loc) · 2.47 KB
/
configure.cc
File metadata and controls
143 lines (131 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "acejudge.h"
prob_cfg :: prob_cfg() {
empty = 1;
nofile = 1;
}
void prob_cfg :: load(char *gfn = 0) {
if (!gfn) {
puts("Cfg file name:");
get_str(cfg_name);
}
else
strcpy(cfg_name, gfn);
for (char *g = cfg_name; *g; g ++)
if (*g == 10)
*g = 0;
FILE *ipf = fopen(cfg_name, "r");
if (!ipf) {
ipf = fopen(cfg_name, "w");
fclose(ipf);
nofile = 0;
return file_wrong();
}
else {
fscanf(ipf, "%s", ipt_fmt);
fscanf(ipf, "%s", opt_fmt);
fscanf(ipf, "%d%d%d%d", &beg_num, &end_num, &time_lmt, &mem_lmt);
fscanf(ipf, "%s", prg_name);
fclose(ipf);
empty = 0;
nofile = 0;
}
}
void prob_cfg :: make(char *gfn = 0) {
if (gfn)
strcpy(cfg_name, gfn);
else if (nofile) {
puts("Cfg file name:");
get_str(cfg_name);
}
for (char *g = cfg_name; *g; g ++)
if (*g == 10)
*g = 0;
FILE *opf = fopen(cfg_name, "w");
if (opf) {
fprintf(opf, "%s\n%s\n", ipt_fmt, opt_fmt);
fprintf(opf, "%d %d %d %d\n", beg_num, end_num, time_lmt, mem_lmt);
fprintf(opf, "%s\n", prg_name);
fclose(opf);
nofile = 0;
}
else
file_wrong();
}
void prob_cfg :: show() {
if (empty) {
setcolor(31);
puts("Not set");
}
else {
setcolor(33);
puts("Input data format");
setcolor(32);
puts(ipt_fmt);
setcolor(33);
puts("Output data format");
setcolor(32);
puts(opt_fmt);
setcolor(33);
puts("Begin - End");
setcolor(32);
printf("%d - %d\n", beg_num, end_num);
setcolor(33);
puts("Time limit");
setcolor(32);
printf("%d ms\n", time_lmt);
setcolor(33);
puts("Memory limit");
setcolor(32);
printf("%d MB\n", mem_lmt);
setcolor(33);
puts("Current testing file name");
setcolor(32);
puts(prg_name);
setcolor(0);
}
}
void prob_cfg :: get() {
char fmt[max_path], suf[max_path];
setcolor(33);
fmt[0] = 0;
puts("IO data format");
get_str(fmt);
if (fmt[0]) {
puts("Input data sufix");
get_str(suf);
sprintf(ipt_fmt, "%s%s", fmt, suf);
puts("Output data sufix");
get_str(suf);
sprintf(opt_fmt, "%s%s", fmt, suf);
}
puts("Begin - End");
get_int(beg_num);
get_int(end_num);
puts("Time limit(ms)");
get_int(time_lmt);
puts("Memory limit(MB)");
get_int(mem_lmt);
empty = 0;
}
void config(prob_cfg& c) {
puts("C - Config problem");
puts("L - Show cfg now");
puts("E - Load existing cfg file");
puts("W - Save cfg file");
switch (get_cmd()) {
case 'C':
c. get();
break;
case 'L':
c. show();
break;
case 'E':
c. load();
break;
case 'W':
c. make();
break;
}
if (!c. nofile)
c. make();
}