83
//////////////////////////////////////////////////////////////////////
84
// my_ functions for I/O debugging and memory allocation
86
// =======================================================
91
// =======================================================
92
char * my_Tcl_Alloc(int size) {
94
char * buf = Tcl_AttemptAlloc(size);
97
printf("Alloc %u %d\n", (unsigned int) buf, size );
100
Tcl_Eval(currentTclInterp, "tk_messageBox -type ok -icon error -parent . -title \"Scid\" -message \"Out of memory\nScid should crash rather quickly\"");
104
// =======================================================
105
char * my_Tcl_AttemptAlloc(int size){
107
char * buf = Tcl_AttemptAlloc(size);
110
printf("Alloc %u %d\n", (unsigned int) buf, size );
114
// =======================================================
115
char * my_Tcl_Realloc(char * ptr, int size) {
116
char * buf = Tcl_AttemptRealloc(ptr, size);
119
printf("Realloc %u -> %u %d\n", (unsigned int) ptr, (unsigned int) buf, size );
122
Tcl_Eval(currentTclInterp, "tk_messageBox -type ok -icon error -parent . -title \"Scid\" -message \"Out of memory\nScid could crash rather quickly\"");
126
// =======================================================
127
void my_Tcl_Free(char * ptr) {
130
printf("Free %u\n", (unsigned int) ptr );
137
// =======================================================
138
Tcl_Channel my_Tcl_OpenFileChannel (Tcl_Interp * interp, CONST char * fileName, CONST char * modeString, int permissions){
139
Tcl_Channel chan = Tcl_OpenFileChannel (currentTclInterp, fileName, modeString, permissions);
142
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_OpenFileChannel error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
143
Tcl_Eval(currentTclInterp, buf);
147
// =======================================================
148
// interpreter is set to NULL, so in case of any error, it is not appended to current result
149
Tcl_Channel mySilent_Tcl_OpenFileChannel (Tcl_Interp * interp, CONST char * fileName, CONST char * modeString, int permissions){
150
Tcl_Channel chan = Tcl_OpenFileChannel (NULL, fileName, modeString, permissions);
153
// =======================================================
154
int my_Tcl_Close (Tcl_Interp * interp, Tcl_Channel chan) {
155
int res = Tcl_Close (currentTclInterp, chan);
158
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Close error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
159
Tcl_Eval(currentTclInterp, buf);
163
// =======================================================
164
int my_Tcl_Read (Tcl_Channel chan, char * bufPtr, int toRead) {
165
int res = Tcl_Read (chan, bufPtr, toRead);
168
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Read error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
169
Tcl_Eval(currentTclInterp, buf);
173
// =======================================================
174
int my_Tcl_Write (Tcl_Channel chan, CONST char * s, int slen){
176
res = Tcl_Write ( chan, s, slen);
179
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Write error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
180
Tcl_Eval(currentTclInterp, buf);
184
// =======================================================
185
int my_Tcl_Flush (Tcl_Channel chan){
186
int res = Tcl_Flush (chan);
189
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Flush error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
190
Tcl_Eval(currentTclInterp, buf);
194
// =======================================================
195
Tcl_WideInt my_Tcl_Seek (Tcl_Channel chan, Tcl_WideInt offset, int mode){
196
Tcl_WideInt res = Tcl_Seek ( chan, offset, mode);
199
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Seek error %s\"", Tcl_ErrnoMsg(Tcl_GetErrno()));
200
Tcl_Eval(currentTclInterp, buf);
204
// =======================================================
205
Tcl_WideInt my_Tcl_Tell (Tcl_Channel chan){
206
Tcl_WideInt res = Tcl_Tell (chan);
208
Tcl_Eval(currentTclInterp, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_Tell error\"");
212
// =======================================================
213
int my_Tcl_SetChannelOption ( Tcl_Interp * interp, Tcl_Channel chan, CONST char * optionName, CONST char * newValue){
214
int res = Tcl_SetChannelOption ( currentTclInterp, chan, optionName, newValue);
215
if (res == TCL_ERROR) {
217
sprintf(buf, "tk_messageBox -type ok -icon error -parent . -title \"Error\" -message \"Tcl_SetChannelOption %s %s error\"", optionName, newValue);
218
Tcl_Eval(currentTclInterp, buf);
223
// =======================================================
224
int my_Tcl_Eof (Tcl_Channel chan) {
225
return Tcl_Eof (chan);
76
228
//////////////////////////////////////////////////////////////////////
77
229
// ECO Code Routines
1306
1465
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1307
1466
// fileExists():
1308
1467
// Returns true if the file exists, false otherwise.
1310
fileExists (const char * name, const char * suffix)
1313
Tcl_StatBuf statBuf;
1316
strCopy (fname, name);
1317
strAppend (fname, suffix);
1318
// if (my_stat (fname, &statBuf) != 0) {
1319
Tcl_Obj * obj = Tcl_NewStringObj(fname, strlen(fname));
1320
res = Tcl_FSLstat(obj, &statBuf );
1321
Tcl_DecrRefCount(obj);
1326
struct stat statBuf; // Defined in <sys/stat.h>
1328
strCopy (fname, name);
1329
strAppend (fname, suffix);
1330
if (stat (fname, &statBuf) != 0) {
1469
// fileExists (const char * name, const char * suffix)
1472
// Tcl_StatBuf statBuf;
1475
// strCopy (fname, name);
1476
// strAppend (fname, suffix);
1477
// Tcl_Obj * obj = Tcl_NewStringObj(fname, strlen(fname));
1478
// res = Tcl_FSLstat(obj, &statBuf );
1479
// Tcl_DecrRefCount(obj);
1484
// struct stat statBuf; // Defined in <sys/stat.h>
1486
// strCopy (fname, name);
1487
// strAppend (fname, suffix);
1488
// if (stat (fname, &statBuf) != 0) {
1338
1496
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~