version 1.4.39b
[polyglot.git] / util.c
diff --git a/util.c b/util.c
index 8551aca..3016e23 100644 (file)
--- a/util.c
+++ b/util.c
@@ -18,7 +18,9 @@
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <time.h>\r
+#ifndef _MSC_VER\r
 #include <sys/time.h>\r
+#endif\r
 \r
 #include "main.h"\r
 #include "util.h"\r
@@ -29,7 +31,6 @@ static bool Error;
 \r
 FILE * LogFile=NULL;\r
 \r
-\r
 // functions\r
 \r
 // util_init()\r
@@ -158,45 +159,47 @@ void my_log_close() {
 // my_log()\r
 \r
 void my_log(const char format[], ...) {\r
+    \r
+    char string[FormatBufferSize];\r
+    \r
+    ASSERT(format!=NULL);\r
 \r
-   va_list ap;\r
+//  format\r
 \r
-   ASSERT(format!=NULL);\r
+    CONSTRUCT_ARG_STRING(format,string);\r
+    \r
 \r
-   if (LogFile != NULL) {\r
-      fprintf(LogFile,"%.3f ",now_real());\r
-      va_start(ap,format);\r
-\r
-      vfprintf(LogFile,format,ap);\r
-      va_end(ap);\r
+    if (LogFile != NULL) {\r
+        fprintf(LogFile,"%.3f %s",now_real(),string);\r
 #ifdef _WIN32\r
-      fflush(LogFile);\r
+        fflush(LogFile);\r
 #endif\r
-   }\r
+    }\r
 }\r
 \r
 // my_fatal()\r
 \r
 void my_fatal(const char format[], ...) {\r
 \r
-   va_list ap;\r
+    char string[FormatBufferSize];\r
 \r
-   ASSERT(format!=NULL);\r
+    ASSERT(format!=NULL);\r
 \r
-   va_start(ap,format);\r
+// format\r
 \r
-   vfprintf(stderr,format,ap);\r
-   if (LogFile != NULL) vfprintf(LogFile,format,ap);\r
+    CONSTRUCT_ARG_STRING(format,string);\r
+    \r
+    fprintf(stderr,"%s",string);\r
+    my_log("POLYGLOT %s",string);\r
 \r
-   va_end(ap);\r
-   if (Error) { // recursive error\r
-      my_log("POLYGLOT *** RECURSIVE ERROR ***\n");\r
-      exit(EXIT_FAILURE);\r
-      // abort();\r
-   } else {\r
-      Error = TRUE;\r
-      quit();\r
-   }\r
+    if (Error) { // recursive error\r
+        my_log("POLYGLOT *** RECURSIVE ERROR ***\n");\r
+        exit(EXIT_FAILURE);\r
+            // abort();\r
+    } else {\r
+        Error = TRUE;\r
+        quit();\r
+    }\r
 }\r
 \r
 // my_file_read_line()\r
@@ -336,7 +339,10 @@ double now_real() {
 \r
    return tv->tv_sec + tv->tv_usec * 1E-6;\r
 #else\r
-   return (double) GetTickCount() / 1000.0;  // we can do better here:-)\r
+   struct _timeb timeptr;\r
+   _ftime(&timeptr);\r
+   return(timeptr.time+((double)timeptr.millitm)/1000.0);\r
+//   return (double) GetTickCount() / 1000.0;  // we can do better here:-)\r
 #endif\r
 }\r
 \r
@@ -394,19 +400,4 @@ double my_timer_elapsed_real(const my_timer_t * timer) {
 }\r
 \r
 \r
-char * my_getcwd(char *buf, size_t size){\r
-#ifdef _WIN32\r
-    return _getcwd(buf,size);\r
-#else\r
-    return getcwd(buf,size);\r
-#endif\r
-}\r
 \r
-int my_chdir (const char *path){\r
-    ASSERT(path!=NULL);\r
-#ifdef _WIN32\r
-    return _chdir(path);\r
-#else\r
-    return chdir(path);\r
-#endif\r
-}\r