lemon/bits/mingw32_time.cc
author deba
Fri, 03 Nov 2006 14:20:24 +0000
changeset 2290 f30867b359a8
child 2391 14a343be7a5a
permissions -rw-r--r--
GraphCopy and UGraphCopy modifications
Preliminary support for static graphs
=> cloning graphs

Added BpUGraphCopy

Tests for graph copies
deba@2035
     1
#ifdef WIN32
deba@2035
     2
deba@2035
     3
#include <lemon/bits/mingw32_time.h>
deba@2035
     4
deba@2035
     5
#include <windows.h>
deba@2035
     6
#include <ctime>
deba@2035
     7
#include "dos.h"
deba@2035
     8
deba@2035
     9
static const char days[] = 
deba@2035
    10
"Sun Mon Tue Wed Thu Fri Sat ";
deba@2035
    11
static const char months[] = 
deba@2035
    12
"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
deba@2035
    13
deba@2035
    14
void num2str(char *c,int i) {
deba@2035
    15
  c[0]=i/10+'0';
deba@2035
    16
  c[1]=i%10+'0';
deba@2035
    17
}
deba@2035
    18
deba@2035
    19
char *asctime_r(const struct tm *t, char *buf) {
deba@2035
    20
  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
deba@2035
    21
  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
deba@2035
    22
  num2str(buf+8,t->tm_mday);
deba@2035
    23
  if (buf[8]=='0') buf[8]=' ';
deba@2035
    24
  buf[10]=' ';
deba@2035
    25
  num2str(buf+11,t->tm_hour);
deba@2035
    26
  buf[13]=':';
deba@2035
    27
  num2str(buf+14,t->tm_min);
deba@2035
    28
  buf[16]=':';
deba@2035
    29
  num2str(buf+17,t->tm_sec);
deba@2035
    30
  buf[19]=' ';
deba@2035
    31
  num2str(buf+20,(t->tm_year+1900)/100);
deba@2035
    32
  num2str(buf+22,(t->tm_year+1900)%100);
deba@2035
    33
  buf[24]='\n'; buf[25]='\0';
deba@2035
    34
  return buf;
deba@2035
    35
}
deba@2035
    36
deba@2035
    37
struct tm * localtime_r (const time_t *t, struct tm *tm) {
deba@2035
    38
  struct tm *tmp;
deba@2035
    39
  
deba@2035
    40
  if ((tmp = localtime(t)) && tm)
deba@2035
    41
    *tm = *tmp;
deba@2035
    42
  else
deba@2035
    43
    return 0;
deba@2035
    44
  
deba@2035
    45
  return tm;
deba@2035
    46
}
deba@2035
    47
deba@2035
    48
char *ctime_r(const time_t * tim_p , char * result) {
deba@2035
    49
  struct tm tm;
deba@2035
    50
  return asctime_r (localtime_r (tim_p, &tm), result);
deba@2035
    51
}
deba@2035
    52
deba@2035
    53
deba@2035
    54
int gettimeofday(struct timeval * tp, struct timezone *) {
deba@2035
    55
  SYSTEMTIME systime;
deba@2035
    56
deba@2035
    57
  if (tp) {
deba@2035
    58
    struct tm tmrec;
deba@2035
    59
    time_t theTime = time(NULL);
deba@2035
    60
    
deba@2035
    61
    
deba@2035
    62
    tmrec = *localtime(&theTime);
deba@2035
    63
    tp->tv_sec = mktime(&tmrec);
deba@2035
    64
    GetLocalTime(&systime); /* system time */
deba@2035
    65
deba@2035
    66
    tp->tv_usec = systime.wMilliseconds * 1000;
deba@2035
    67
  }
deba@2035
    68
  return 0;
deba@2035
    69
}
deba@2035
    70
deba@2035
    71
long filetime_to_clock(FILETIME *ft)
deba@2035
    72
{
deba@2035
    73
  __int64 qw = ft->dwHighDateTime;
deba@2035
    74
  qw <<= 32;
deba@2035
    75
  qw |= ft->dwLowDateTime;
deba@2035
    76
  qw /= 10000;  
deba@2035
    77
  return (long) qw;
deba@2035
    78
deba@2035
    79
}
deba@2035
    80
deba@2035
    81
int times(struct tms *tmbuf)
deba@2035
    82
{
deba@2035
    83
  FILETIME create, exit, kernel, user;
deba@2035
    84
  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
deba@2035
    85
    tmbuf->tms_utime = filetime_to_clock(&user);
deba@2035
    86
    tmbuf->tms_stime = filetime_to_clock(&kernel);
deba@2035
    87
    tmbuf->tms_cutime = 0;
deba@2035
    88
    tmbuf->tms_cstime = 0;
deba@2035
    89
  }
deba@2035
    90
  else {
deba@2035
    91
    tmbuf->tms_utime = clock();
deba@2035
    92
    tmbuf->tms_stime = 0;
deba@2035
    93
    tmbuf->tms_cutime = 0;
deba@2035
    94
    tmbuf->tms_cstime = 0;
deba@2035
    95
  }
deba@2035
    96
  return 0;
deba@2035
    97
}
deba@2035
    98
deba@2035
    99
int sysconf(int)
deba@2035
   100
{
deba@2035
   101
  return 1;
deba@2035
   102
}
deba@2035
   103
deba@2035
   104
#endif