X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.c;h=c2dec6b29e1b51a3b16bb04f8c31e541979d7993;hb=60900035e6d0309705f2326ee50edc52386305e9;hp=a5af1173347ebdb6e4876aa73308250057b7e010;hpb=cd81270f2b1723e0798f4d6dcaee134f0b4aca7f;p=polyglot.git diff --git a/util.c b/util.c index a5af117..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(); } } @@ -316,6 +324,44 @@ bool my_string_case_equal(const char string_1[], const char string_2[]) { return FALSE; } +// my_strtolower() + +void my_string_tolower(char *dst, const char *src){ + int c; + ASSERT(src!=NULL); + ASSERT(dst!=NULL); + while((c=*(src++))){ + *dst=tolower(c); + dst++; + } + *(dst++)='\0'; +} + +// my_string_case_contains() + +const char* my_string_case_contains(const char string_1[], const char string_2[]){ + + char tmp1[StringSize]; + char tmp2[StringSize]; + char *where; + + + ASSERT(string_1!=NULL); + ASSERT(string_2!=NULL); + + my_string_tolower(tmp1,string_1); + my_string_tolower(tmp2,string_2); + + where=strstr(tmp1,tmp2); + if(where){ + return string_1+(where-tmp1); + } + return NULL; + + +} + + // my_strdup() char * my_strdup(const char string[]) { @@ -355,6 +401,8 @@ void my_string_set(const char * * variable, const char string[]) { *variable = my_strdup(string); } +// now_real() + double now_real() { #ifndef _WIN32 struct timeval tv[1]; @@ -430,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 +}