MinGW32 compatibility
authordeba
Fri, 31 Mar 2006 12:51:44 +0000
changeset 2028d0e8a86a1ff2
parent 2027 119db4e6ab2c
child 2029 e00114f165f5
MinGW32 compatibility
lemon/bits/mingw32_time.h
lemon/graph_to_eps.h
lemon/time_measure.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/mingw32_time.h	Fri Mar 31 12:51:44 2006 +0000
     1.3 @@ -0,0 +1,137 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef LEMON_BITS_MINGW32_TIME_H
    1.23 +#define LEMON_BITS_MINGW32_TIME_H
    1.24 +
    1.25 +#ifdef WIN32
    1.26 +
    1.27 +#include <windows.h>
    1.28 +#include <time.h>
    1.29 +#include "dos.h"
    1.30 +
    1.31 +static const char days[] = 
    1.32 +"Sun Mon Tue Wed Thu Fri Sat ";
    1.33 +static const char months[] = 
    1.34 +"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
    1.35 +
    1.36 +inline void num2str(char *c,int i) {
    1.37 +  c[0]=i/10+'0';
    1.38 +  c[1]=i%10+'0';
    1.39 +}
    1.40 +
    1.41 +inline char *asctime_r(const struct tm *t, char *buf) {
    1.42 +  /* "Wed Jun 30 21:49:08 1993\n" */
    1.43 +  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
    1.44 +  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
    1.45 +  num2str(buf+8,t->tm_mday);
    1.46 +  if (buf[8]=='0') buf[8]=' ';
    1.47 +  buf[10]=' ';
    1.48 +  num2str(buf+11,t->tm_hour);
    1.49 +  buf[13]=':';
    1.50 +  num2str(buf+14,t->tm_min);
    1.51 +  buf[16]=':';
    1.52 +  num2str(buf+17,t->tm_sec);
    1.53 +  buf[19]=' ';
    1.54 +  num2str(buf+20,(t->tm_year+1900)/100);
    1.55 +  num2str(buf+22,(t->tm_year+1900)%100);
    1.56 +  buf[24]='\n'; buf[25]='\0';
    1.57 +  return buf;
    1.58 +}
    1.59 +
    1.60 +inline struct tm * localtime_r (const time_t *t, struct tm *tm) {
    1.61 +  struct tm *tmp;
    1.62 +  
    1.63 +  if ((tmp = localtime(t)) && tm)
    1.64 +    *tm = *tmp;
    1.65 +  else
    1.66 +    return 0;
    1.67 +  
    1.68 +  return tm;
    1.69 +}
    1.70 +
    1.71 +inline char *ctime_r(const time_t * tim_p , char * result) {
    1.72 +  struct tm tm;
    1.73 +  return asctime_r (localtime_r (tim_p, &tm), result);
    1.74 +}
    1.75 +
    1.76 +
    1.77 +inline int gettimeofday(struct timeval * tp, struct timezone *) {
    1.78 +  SYSTEMTIME systime;
    1.79 +
    1.80 +  if (tp) {
    1.81 +    struct tm tmrec;
    1.82 +    time_t theTime = time(NULL);
    1.83 +    
    1.84 +    
    1.85 +    tmrec = *localtime(&theTime);
    1.86 +    tp->tv_sec = mktime(&tmrec);
    1.87 +    GetLocalTime(&systime); /* system time */
    1.88 +
    1.89 +    tp->tv_usec = systime.wMilliseconds * 1000;
    1.90 +  }
    1.91 +  return 0;
    1.92 +}
    1.93 +
    1.94 +
    1.95 +struct tms {
    1.96 +  long	tms_utime;
    1.97 +  long	tms_stime;
    1.98 +  long	tms_cutime;
    1.99 +  long	tms_cstime;
   1.100 +};
   1.101 +
   1.102 +inline long filetime_to_clock(FILETIME *ft)
   1.103 +{
   1.104 +  __int64 qw = ft->dwHighDateTime;
   1.105 +  qw <<= 32;
   1.106 +  qw |= ft->dwLowDateTime;
   1.107 +  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
   1.108 +  return (long) qw;
   1.109 +
   1.110 +}
   1.111 +
   1.112 +inline int times(struct tms *tmbuf)
   1.113 +{
   1.114 +  FILETIME create, exit, kernel, user;
   1.115 +  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
   1.116 +    tmbuf->tms_utime = filetime_to_clock(&user);
   1.117 +    tmbuf->tms_stime = filetime_to_clock(&kernel);
   1.118 +    tmbuf->tms_cutime = 0;
   1.119 +    tmbuf->tms_cstime = 0;
   1.120 +  }
   1.121 +  else {
   1.122 +    tmbuf->tms_utime = clock();
   1.123 +    tmbuf->tms_stime = 0;
   1.124 +    tmbuf->tms_cutime = 0;
   1.125 +    tmbuf->tms_cstime = 0;
   1.126 +  }
   1.127 +  return 0;
   1.128 +}
   1.129 +
   1.130 +#define _SC_CLK_TCK 1
   1.131 +
   1.132 +inline int sysconf(int)
   1.133 +{
   1.134 +  return 1;
   1.135 +}
   1.136 +
   1.137 +#endif
   1.138 +
   1.139 +
   1.140 +#endif
     2.1 --- a/lemon/graph_to_eps.h	Fri Mar 31 12:12:06 2006 +0000
     2.2 +++ b/lemon/graph_to_eps.h	Fri Mar 31 12:51:44 2006 +0000
     2.3 @@ -21,6 +21,10 @@
     2.4  
     2.5  #include <sys/time.h>
     2.6  
     2.7 +#ifdef WIN32
     2.8 +#include <lemon/bits/mingw32_time.h>
     2.9 +#endif
    2.10 +
    2.11  #include<iostream>
    2.12  #include<fstream>
    2.13  #include<sstream>
     3.1 --- a/lemon/time_measure.h	Fri Mar 31 12:12:06 2006 +0000
     3.2 +++ b/lemon/time_measure.h	Fri Mar 31 12:51:44 2006 +0000
     3.3 @@ -25,73 +25,7 @@
     3.4  
     3.5  
     3.6  #ifdef WIN32
     3.7 -
     3.8 -#include <windows.h>
     3.9 -#include <time.h>
    3.10 -#include "dos.h"
    3.11 -
    3.12 -int gettimeofday(struct timeval * tp, struct timezone *) {
    3.13 -  SYSTEMTIME      systime;
    3.14 -
    3.15 -  if (tp) {
    3.16 -
    3.17 -    struct tm tmrec;
    3.18 -    time_t theTime = time(NULL);
    3.19 -
    3.20 -    tmrec = *localtime(&theTime);
    3.21 -    tp->tv_sec = mktime(&tmrec);
    3.22 -    GetLocalTime(&systime); /* system time */
    3.23 -
    3.24 -    tp->tv_usec = systime.wMilliseconds * 1000;
    3.25 -
    3.26 -  }
    3.27 -
    3.28 -  return 0;
    3.29 -
    3.30 -}
    3.31 -
    3.32 -struct tms {
    3.33 -  long	tms_utime;
    3.34 -  long	tms_stime;
    3.35 -  long	tms_cutime;
    3.36 -  long	tms_cstime;
    3.37 -};
    3.38 -
    3.39 -static long filetime_to_clock(FILETIME *ft)
    3.40 -{
    3.41 -  __int64 qw = ft->dwHighDateTime;
    3.42 -  qw <<= 32;
    3.43 -  qw |= ft->dwLowDateTime;
    3.44 -  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
    3.45 -  return (long) qw;
    3.46 -
    3.47 -}
    3.48 -
    3.49 -int times(struct tms *tmbuf)
    3.50 -{
    3.51 -  FILETIME create, exit, kernel, user;
    3.52 -  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
    3.53 -    tmbuf->tms_utime = filetime_to_clock(&user);
    3.54 -    tmbuf->tms_stime = filetime_to_clock(&kernel);
    3.55 -    tmbuf->tms_cutime = 0;
    3.56 -    tmbuf->tms_cstime = 0;
    3.57 -  }
    3.58 -  else {
    3.59 -    tmbuf->tms_utime = clock();
    3.60 -    tmbuf->tms_stime = 0;
    3.61 -    tmbuf->tms_cutime = 0;
    3.62 -    tmbuf->tms_cstime = 0;
    3.63 -  }
    3.64 -  return 0;
    3.65 -}
    3.66 -
    3.67 -#define _SC_CLK_TCK 1
    3.68 -
    3.69 -int sysconf(int)
    3.70 -{
    3.71 -  return 1;
    3.72 -}
    3.73 -
    3.74 +#include <lemon/bits/mingw32_time.h>
    3.75  #else
    3.76  #include <sys/times.h>
    3.77  #endif
    3.78 @@ -141,8 +75,10 @@
    3.79      rtms &getTms() {return ts;}
    3.80      const rtms &getTms() const {return ts;}
    3.81  
    3.82 -    void _reset() 
    3.83 -    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
    3.84 +    void _reset() { 
    3.85 +      ts.tms_utime = ts.tms_stime = ts.tms_cutime = ts.tms_cstime = 0; 
    3.86 +      real_time = 0;
    3.87 +    }
    3.88  
    3.89    public:
    3.90