1
4
5# include "luametatex.h"
6
7
8
9# ifdef _WIN32
10
11 double aux_get_current_time(void) {
12 FILETIME ft;
13 double t;
14 GetSystemTimeAsFileTime(&ft);
15
16 t = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);
17
18 return (t - 11644473600.0);
19 }
20
21# else
22
23 double aux_get_current_time(void) {
24 struct timeval v;
25 gettimeofday(&v, (struct timezone *) NULL);
26
27 return v.tv_sec + v.tv_usec/1.0e6;
28 }
29
30# endif
31
32void aux_set_run_time(void)
33{
34 lmt_main_state.start_time = aux_get_current_time();
35}
36
37double aux_get_run_time(void)
38{
39 return aux_get_current_time() - lmt_main_state.start_time;
40}
41
42
66
67static int start_time = -1;
68
69static int aux_get_start_time(void) {
70 if (start_time < 0) {
71 start_time = (int) time((time_t *) NULL);
72 }
73 return start_time;
74}
75
76
82
83void aux_set_start_time(int s) {
84 if (s >= 0) {
85 start_time = s ;
86 }
87}
88
89
95
96# ifdef _WIN32
97
98
99
100 static BOOL WINAPI catch_interrupt(DWORD arg)
101 {
102 switch (arg) {
103 case CTRL_C_EVENT:
104 case CTRL_BREAK_EVENT:
105 aux_quit_the_program();
106 return 1;
107 default:
108
109 return 0;
110 }
111 }
112
113 void aux_set_interrupt_handler(void)
114 {
115 SetConsoleCtrlHandler(catch_interrupt, TRUE);
116 }
117
118# else
119
120
121
122 static void catch_interrupt(int arg)
123 {
124 (void) arg;
125 aux_quit_the_program();
126 (void) signal(SIGINT, catch_interrupt);
127 }
128
129 void aux_set_interrupt_handler(void)
130 {
131
132 void (*old_handler) (int);
133 old_handler = signal(SIGINT, catch_interrupt);
134 if (old_handler != SIG_DFL) {
135 signal(SIGINT, old_handler);
136 }
137 }
138
139# endif
140
141void aux_get_date_and_time(int *minutes, int *day, int *month, int *year, int *utc)
142{
143 time_t myclock = aux_get_start_time();
144 struct tm *tmptr ;
145 if (*utc) {
146 tmptr = gmtime(&myclock);
147 } else {
148 tmptr = localtime(&myclock);
149 }
150 *minutes = tmptr->tm_hour * 60 + tmptr->tm_min;
151 *day = tmptr->tm_mday;
152 *month = tmptr->tm_mon + 1;
153 *year = tmptr->tm_year + 1900;
154
155}
156 |