X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.c;h=32413ab22cc3e3ebb0e8d2aeccf7f510e30b11c0;hb=bb6c47f77f59067c358579a71cefa1ae65180a30;hp=873ed2f2dc78d0bbd082f5444e04abed9595b4dd;hpb=446bfd706349c3e1f19916a16558a2f4f7dc8e54;p=polyglot.git diff --git a/util.c b/util.c index 873ed2f..32413ab 100644 --- a/util.c +++ b/util.c @@ -25,6 +25,10 @@ #include "main.h" #include "util.h" +// macros + +#define StringSize 4096 + // variables static bool Error; @@ -190,7 +194,7 @@ void my_fatal(const char format[], ...) { CONSTRUCT_ARG_STRING(format,string); fprintf(stderr,"%s",string); - if (LogFile != NULL) fprintf(LogFile,"%s",string); + my_log("POLYGLOT %s",string); if (Error) { // recursive error my_log("POLYGLOT *** RECURSIVE ERROR ***\n"); @@ -235,6 +239,32 @@ bool my_file_read_line(FILE * file, char string[], int size) { return TRUE; } +// my_file_join() + +void my_path_join(char *join_path, const char *path, const char *file){ + char separator; +#ifdef _WIN32 + separator='\\'; +#else + separator='/'; +#endif + snprintf(join_path,StringSize,"%s%c%s",path,separator,file); + join_path[StringSize-1]='\0'; +} + +// my_mkdir() + +int my_mkdir(const char *path){ + int ret; +#ifdef _WIN32 + ret=_mkdir(path); +#else + ret=mkdir(path,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); +#endif + return ret; +} + + // my_string_empty() bool my_string_empty(const char string[]) { @@ -286,6 +316,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[]) { @@ -325,6 +393,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]; @@ -339,7 +409,10 @@ double now_real() { return tv->tv_sec + tv->tv_usec * 1E-6; #else - return (double) GetTickCount() / 1000.0; // we can do better here:-) + struct _timeb timeptr; + _ftime(&timeptr); + return(timeptr.time+((double)timeptr.millitm)/1000.0); +// return (double) GetTickCount() / 1000.0; // we can do better here:-) #endif }