1 #include "includes.h"
2 #include "knightcap.h"
3
4 static FILE *logfile;
5 static FILE *sfile;
6 static FILE *cfile;
7 static FILE *dfile;
8
log_close(void)9 void log_close(void)
10 {
11 fclose(logfile);
12 logfile = NULL;
13 }
14
lprintf(int level,char * format_str,...)15 int lprintf(int level, char *format_str, ...)
16 {
17 va_list ap;
18 char fmt[1024];
19 char *p;
20
21 if (!logfile) {
22 #if APLINUX
23 logfile = fopen("/ddv/data/tridge/knightcap.log","w");
24 #else
25 logfile = fopen("knightcap.log","w");
26 #endif
27 }
28
29 va_start(ap, format_str);
30
31
32 strcpy(fmt, format_str);
33 if (sizeof(short) == sizeof(etype)) {
34 while ((p = strstr(fmt, "%e"))) {
35 p[1] = 'd';
36 }
37 } else {
38 while ((p = strstr(fmt, "%e"))) {
39 p[1] = 'd';
40 }
41 }
42
43
44 if (level == 0) {
45 vfprintf(stdout,fmt,ap);
46 if (fmt[strlen(fmt)-1] == '\n')
47 fflush(stdout);
48 }
49
50 if (logfile) {
51 vfprintf(logfile,fmt,ap);
52 if (level == 0)
53 if (fmt[strlen(fmt)-1] == '\n')
54 fflush(logfile);
55 }
56
57 va_end(ap);
58
59
60 return(0);
61 }
62
status_printf(int rew,char * format_str,...)63 int status_printf(int rew, char *format_str, ...)
64 {
65 va_list ap;
66 char fmt[1024];
67 char *p;
68
69 if (!sfile) {
70 #if USE_APPLET
71 sfile = fopen("/export/pasiphae/status.txt","w");
72 #else
73 sfile = fopen("status.txt","w");
74 #endif
75 }
76
77 if (rew)
78 rewind(sfile);
79
80 va_start(ap, format_str);
81
82
83 strcpy(fmt, format_str);
84 if (sizeof(short) == sizeof(etype)) {
85 while ((p = strstr(fmt, "%e"))) {
86 p[1] = 'd';
87 }
88 } else {
89 while ((p = strstr(fmt, "%e"))) {
90 p[1] = 'd';
91 }
92 }
93
94
95 if (sfile) {
96 vfprintf(sfile,fmt,ap);
97 if (fmt[strlen(fmt)-1] == '\n')
98 fflush(sfile);
99 }
100
101 va_end(ap);
102
103
104 return(0);
105 }
106
lindent(int level,int ply)107 void lindent(int level, int ply)
108 {
109 while (ply--)
110 lprintf(level, "\t");
111 }
112
cprintf(int level,char * format_str,...)113 int cprintf(int level, char *format_str, ...)
114 {
115 va_list ap;
116
117
118 if (!cfile) {
119 cfile = fopen("wnorm.dat", "w");
120 }
121
122 va_start(ap, format_str);
123
124 vfprintf(cfile,format_str,ap);
125 fflush(cfile);
126
127 va_end(ap);
128
129
130 return(0);
131 }
132
ddprintf(int level,char * format_str,...)133 int ddprintf(int level, char *format_str, ...)
134 {
135 va_list ap;
136
137
138 if (!dfile) {
139 dfile = fopen("/usr/local/chess/bad_grad.dat", "a");
140 }
141
142 va_start(ap, format_str);
143
144 vfprintf(dfile,format_str,ap);
145 fflush(dfile);
146
147 va_end(ap);
148
149
150 return(0);
151 }
152