-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_xml.c
More file actions
415 lines (359 loc) · 10.7 KB
/
dir_xml.c
File metadata and controls
415 lines (359 loc) · 10.7 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
* dir_xml.c
* (c) 2017-2018, Brian Stephenson
* brian@bstephen.me.uk
*
* A program to test orthodox chess problems of the types:
*
* directmates
* selfmates
* relfexmates
* helpmates
*
* Input is taken from the program options and output is xml on stdout.
*
* This is the module for preparing the xml output for directmates.
*/
#include "sengine.h"
#include "genx.h"
extern bool opt_meson;
extern char* opt_kings;
extern char* opt_gbr;
extern char* opt_pos;
extern enum SOUNDNESS sound;
extern enum STIP opt_stip;
extern enum AIM opt_aim;
extern int opt_moves;
extern int opt_sols;
extern char* opt_castling;
extern char* opt_ep;
extern bool opt_set;
extern bool opt_tries;
extern int opt_refuts;
extern bool opt_trivialtries;
extern bool opt_actual;
extern enum THREATS opt_threats;
extern bool opt_fleck;
extern bool opt_shortvars;
static genxWriter w;
static const unsigned char ms[] = "MesonSolution";
static const unsigned char solvetime[] = "SolvingTime";
static const unsigned char program[] = "Program";
static const unsigned char author[] = "Author";
static const unsigned char soundel[] = "Soundness";
static const unsigned char diag[] = "Diagram";
static const unsigned char keysel[] = "Keys";
static const unsigned char setsel[] = "Sets";
static const unsigned char trysel[] = "Tries";
static const unsigned char optsel[] = "options";
static const unsigned char statsel[] = "stats";
static const unsigned char wmel[] = "wm";
static const unsigned char bmel[] = "bm";
static const unsigned char threl[] = "thr";
static const unsigned char stipel[] = "stip";
static const unsigned char movesel[] = "moves";
static const unsigned char solsel[] = "sols";
static const unsigned char castel[] = "castling";
static const unsigned char epel[] = "ep";
static const unsigned char setel[] = "set";
static const unsigned char triesel[] = "tries";
static const unsigned char refutsel[] = "refuts";
static const unsigned char trivialtriesel[] = "trivialtries";
static const unsigned char actualel[] = "actual";
static const unsigned char threatsel[] = "threats";
static const unsigned char fleckel[] = "fleck";
static const unsigned char shortvarsel[] = "shortvars";
static const unsigned char addedel[] = "hash_added";
static const unsigned char hitnullel[] = "hash_hit_null";
static const unsigned char hitlistel[] = "hash_hit_list";
static const unsigned char compel[] = "compiler";
static const unsigned char platform[] = "platform";
void getWmoveXML(BOARDLIST*);
void getBmoveXML(BOARDLIST*);
void start_dir(void)
{
char progText[200];
w = genxNew(NULL, NULL, NULL);
(void) genxStartDocFile(w, stdout);
(void) genxStartElementLiteral(w, NULL, ms);
(void) genxStartElementLiteral(w, NULL, program);
(void) sprintf(progText, "%s (v. %s, %s)", PROGRAM_NAME, PROGRAM_VERSION,
PROGRAM_YEAR);
(void) genxAddText(w, (unsigned char*) progText);
(void) genxEndElement(w);
if (opt_meson == false) {
(void) genxStartElementLiteral(w, NULL, author);
(void) genxAddText(w, (unsigned char*) PROGRAM_AUTHOR);
(void) genxEndElement(w);
(void) genxStartElementLiteral(w, NULL, compel);
(void) sprintf(progText, "%s (v %s)", COMP, CV);
(void) genxAddText(w, (unsigned char*) progText);
(void) genxEndElement(w);
(void) genxStartElementLiteral(w, NULL, platform);
(void) genxAddText(w, (unsigned char*) PLATFORM);
(void) genxEndElement(w);
}
(void) genxStartElementLiteral(w, NULL, diag);
(void) sprintf(progText, "%s:%s:%s", opt_kings, opt_gbr, opt_pos);
(void) genxAddText(w, (unsigned char*) progText);
(void) genxEndElement(w);
(void) genxStartElementLiteral(w, NULL, soundel);
switch (sound) {
case UNSET:
(void) genxAddText(w, (unsigned char*) "UNSET");
break;
case SHORT_SOLUTION:
(void) genxAddText(w, (unsigned char*) "SHORT_SOLUTION");
break;
case SOUND:
(void) genxAddText(w, (unsigned char*) "SOUND");
break;
case COOKED:
(void) genxAddText(w, (unsigned char*) "COOKED");
break;
case NO_SOLUTION:
(void) genxAddText(w, (unsigned char*) "NO_SOLUTION");
break;
case MISSING_SOLUTION:
(void) genxAddText(w, (unsigned char*) "MISSING_SOLUTION");
break;
default:
(void) fputs("Invalid soundess indicator\n", stderr);
exit(1);
break;
}
(void) genxEndElement(w);
return;
}
void add_dir_set(BOARDLIST* bml)
{
(void) genxStartElementLiteral(w, NULL, setsel);
getBmoveXML(bml);
(void) genxEndElement(w);
return;
}
void add_dir_tries(BOARDLIST* wml)
{
(void) genxStartElementLiteral(w, NULL, trysel);
getWmoveXML(wml);
(void) genxEndElement(w);
return;
}
void getBmoveXML(BOARDLIST* bList)
{
BOARDLIST* wList;
BOARD* brd;
char* ptr;
assert(bList != NULL);
LL_FOREACH(bList->vektor, brd) {
assert(brd != NULL);
(void) genxStartElementLiteral(w, NULL, bmel);
ptr = toStr(brd);
(void) genxAddText(w, (unsigned char*) ptr);
free(ptr);
wList = brd->nextply;
if (wList != NULL) {
getWmoveXML(wList);
}
(void) genxEndElement(w);
}
return;
}
void getWmoveXML(BOARDLIST* wbl)
{
BOARDLIST* thList;
BOARDLIST* bList;
BOARD* brd;
char* ptr;
assert(wbl != NULL);
LL_FOREACH(wbl->vektor, brd) {
assert(brd != NULL);
(void) genxStartElementLiteral(w, NULL, wmel);
ptr = toStr(brd);
(void) genxAddText(w, (unsigned char*) ptr);
free(ptr);
thList = brd->threat;
if (thList != NULL) {
(void) genxStartElementLiteral(w, NULL, threl);
getWmoveXML(thList);
(void) genxEndElement(w);
}
bList = brd->nextply;
if (bList != NULL) {
getBmoveXML(bList);
}
(void) genxEndElement(w);
}
return;
}
void add_dir_keys(BOARDLIST* wml)
{
(void) genxStartElementLiteral(w, NULL, keysel);
getWmoveXML(wml);
(void) genxEndElement(w);
return;
}
void end_dir(void)
{
//( void ) puts( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
(void) genxEndElement(w);
(void) genxEndDocument(w);
genxDispose(w);
printf("\n");
return;
}
void add_dir_options(void)
{
char stip[5];
char moves[2];
char sols[2];
unsigned char on[] = "true";
unsigned char off[] = "false";
(void) genxStartElementLiteral(w, NULL, optsel);
// stip
stip[0] = '\0';
switch (opt_stip) {
case DIRECT:
break;
case HELP:
stip[1] = 'H';
break;
case SELF:
stip[1] = 'S';
break;
case REFLEX:
stip[1] = 'R';
break;
default:
break;
}
(void) strcat(stip, (opt_aim == MATE) ? "#" : "=");
(void) genxStartElementLiteral(w, NULL, stipel);
(void) genxAddText(w, (unsigned char*) stip);
(void) genxEndElement(w);
// moves
(void) genxStartElementLiteral(w, NULL, movesel);
moves[0] = (char) opt_moves + '0';
moves[1] = '\0';
(void) genxAddText(w, (unsigned char*) moves);
(void) genxEndElement(w);
// sols
(void) genxStartElementLiteral(w, NULL, solsel);
sols[0] = (char) opt_sols + '0';
sols[1] = '\0';
(void) genxAddText(w, (unsigned char*) sols);
(void) genxEndElement(w);
// castling
(void) genxStartElementLiteral(w, NULL, castel);
if (opt_castling != NULL) {
(void) genxAddText(w, (unsigned char*) opt_castling);
}
(void) genxEndElement(w);
// ep
(void) genxStartElementLiteral(w, NULL, epel);
if (opt_ep != NULL) {
(void) genxAddText(w, (unsigned char*) opt_ep);
}
(void) genxEndElement(w);
// set
(void) genxStartElementLiteral(w, NULL, setel);
if (opt_set == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
// tries
(void) genxStartElementLiteral(w, NULL, triesel);
if (opt_tries == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
// refuts
(void) genxStartElementLiteral(w, NULL, refutsel);
sols[0] = (char) opt_refuts + '0';
sols[1] = '\0';
(void) genxAddText(w, (unsigned char*) sols);
(void) genxEndElement(w);
// trivialtries
(void) genxStartElementLiteral(w, NULL, trivialtriesel);
if (opt_trivialtries == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
// actual
(void) genxStartElementLiteral(w, NULL, actualel);
if (opt_actual == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
// threats
(void) genxStartElementLiteral(w, NULL, threatsel);
switch (opt_threats) {
case ALL:
(void) genxAddText(w, (unsigned char*) "ALL");
break;
case NONE:
(void) genxAddText(w, (unsigned char*) "NONE");
break;
case SHORTEST:
(void) genxAddText(w, (unsigned char*) "SHORTEST");
break;
default:
(void) genxAddText(w, (unsigned char*) "UNKNOWN");
break;
}
(void) genxEndElement(w);
// fleck
(void) genxStartElementLiteral(w, NULL, fleckel);
if (opt_fleck == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
// shortvars
(void) genxStartElementLiteral(w, NULL, shortvarsel);
if (opt_shortvars == true) {
(void) genxAddText(w, on);
} else {
(void) genxAddText(w, off);
}
(void) genxEndElement(w);
(void) genxEndElement(w);
return;
}
void add_dir_stats(DIR_SOL* dsol)
{
char temp[20];
(void) genxStartElementLiteral(w, NULL, statsel);
(void) genxStartElementLiteral(w, NULL, addedel);
(void) sprintf(temp, "%u", dsol->hash_added);
(void) genxAddText(w, (unsigned char*) temp);
(void) genxEndElement(w);
(void) genxStartElementLiteral(w, NULL, hitnullel);
(void) sprintf(temp, "%u", dsol->hash_hit_null);
(void) genxAddText(w, (unsigned char*) temp);
(void) genxEndElement(w);
(void) genxStartElementLiteral(w, NULL, hitlistel);
(void) sprintf(temp, "%u", dsol->hash_hit_list);
(void) genxAddText(w, (unsigned char*) temp);
(void) genxEndElement(w);
(void) genxEndElement(w);
return;
}
void time_dir(double st)
{
char timeText[50];
(void) genxStartElementLiteral(w, NULL, solvetime);
(void) sprintf(timeText, "%f", st);
(void) genxAddText(w, (unsigned char*) timeText);
(void) genxEndElement(w);
return;
}