-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (65 loc) · 1.74 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <signal.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "paropt/paropt.h"
#include "log/log.h"
#include "tool/tool.h"
#ifdef _WIN32
void Timeproc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime)
{
log_info("time reaching...");
handleMatchFiles(srcdir, dstdir, searchsubdirectories, filepattern, operation, NULL);
}
#else
void signalHandler(int signo)
{
switch (signo) {
case SIGALRM:
log_info("time reaching...");
handleMatchFiles(srcdir, dstdir, searchsubdirectories, filepattern, operation, NULL);
break;
}
}
#endif
int main(int argc, char *argv[])
{
if (parseOption(argc, argv) == 0) {
log_info("log...%d", argc);
#ifdef _WIN32
BOOL bRet;
MSG msg;
UINT uElapse = delaytime;
UINT timerid = SetTimer(NULL, 0, uElapse, (TIMERPROC)Timeproc);
while ((bRet= GetMessage(&msg, NULL, 0, 0)) != 0) {
if (bRet == -1) {
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#else
if (signal(SIGALRM, signalHandler) == SIG_ERR) {
log_error("signal error!");
exit(-1);
}
struct itimerval newValue;
newValue.it_value.tv_sec = delaytime / 1000;
newValue.it_value.tv_usec = (delaytime % 1000) * 1000;
newValue.it_interval.tv_sec = delaytime / 1000;
newValue.it_interval.tv_usec = (delaytime % 1000) * 1000;
if (setitimer(ITIMER_REAL, &newValue, NULL) == -1) {
log_error("setitimer error!");
exit(-1);
}
while (1);
#endif
}
return 0;
}