X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.c;h=c2dec6b29e1b51a3b16bb04f8c31e541979d7993;hb=60900035e6d0309705f2326ee50edc52386305e9;hp=32413ab22cc3e3ebb0e8d2aeccf7f510e30b11c0;hpb=bb6c47f77f59067c358579a71cefa1ae65180a30;p=polyglot.git diff --git a/util.c b/util.c index 32413ab..c2dec6b 100644 --- a/util.c +++ b/util.c @@ -24,6 +24,7 @@ #include "main.h" #include "util.h" +#include "gui.h" // macros @@ -150,6 +151,10 @@ void my_log_open(const char file_name[]) { //line buffering doesn't work too well in MSVC and/or windows if (LogFile != NULL) setvbuf(LogFile,NULL,_IOLBF,0); // line buffering #endif + if(LogFile!=NULL){ + my_log("POLYGLOT *** LOGFILE OPENED ***\n"); + } + } // my_log_close() @@ -193,16 +198,19 @@ void my_fatal(const char format[], ...) { CONSTRUCT_ARG_STRING(format,string); - fprintf(stderr,"%s",string); my_log("POLYGLOT %s",string); + // This should be gui_send but this does not work. + // Why? + + printf("tellusererror POLYGLOT: %s",string); if (Error) { // recursive error my_log("POLYGLOT *** RECURSIVE ERROR ***\n"); exit(EXIT_FAILURE); // abort(); } else { - Error = TRUE; - quit(); + Error = TRUE; + quit(); } } @@ -470,4 +478,49 @@ double my_timer_elapsed_real(const my_timer_t * timer) { } +void my_dequote(char *out, const char *in, const char *special){ + const char *p; + char *q; + char c; + p=in; + q=out; + while((c=*(p++))){ + if(c=='\\' && strchr(special,*p)){ + *(q++)=*(p++); + }else{ + *(q++)=c; + } + } + *q='\0'; +} + +void my_quote(char *out, const char *in, const char *special){ + const char *p; + char *q; + char c; + p=in; + q=out; + while(q-out< StringSize-2 && (c=*(p++))){ + if(c=='\\'){ + if(*p!=0 && strchr(special,*p)){ + *(q++)='\\'; + } + }else if(strchr(special,c)){ + *(q++)='\\'; + } + *(q++)=c; + } + *q='\0'; +} + +void my_sleep(int msec){ +#ifndef _WIN32 + struct timespec tm; + tm.tv_sec=msec/1000; + tm.tv_nsec=1000000*(msec%1000); + nanosleep(&tm,NULL); +#else + Sleep(msec); +#endif +}