Fixed showing the loading progress when in-game.
[cboard.git] / libchess / debug.c
blob5e3c54670980d9b37dd2e2f2a722941c49d3251e
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2002-2011 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdarg.h>
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include "chess.h"
29 #ifdef WITH_DMALLOC
30 #include <dmalloc.h>
31 #endif
33 void write_debug_output(const char *filename, const char *format, ...)
35 FILE *fp = stderr;
36 va_list ap;
37 char *buf;
39 va_start(ap, format);
40 vasprintf(&buf, format, ap);
41 va_end(ap);
43 if (filename) {
44 if ((fp = fopen(filename, "a")) == NULL)
45 return;
48 fprintf(fp, "%s", buf);
49 fflush(fp);
51 if (filename)
52 fclose(fp);
54 free(buf);
55 return;
58 char *debug_board(BOARD b)
60 static char buf[129];
61 char *p = buf;
62 int row, col;
64 for (row = 0; row < 8; row++) {
65 for (col = 0; col < 8; col++) {
66 *p++ = (b[row][col].enpassant) ? 'x' : b[row][col].icon;
68 if (col < 7)
69 *p++ = ' ';
72 *p++ = '\n';
73 *p = 0;
76 *p = 0;
77 return buf;
80 void dump_board(const char *file, BOARD b)
82 write_debug_output(file, "%s", debug_board(b));