/
main.cpp
72 lines (61 loc) · 1.46 KB
/
main.cpp
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
#include <QCoreApplication>
#include "application.h"
#include <QDebug>
int parseTime(QString time);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if(argc < 3)
{
qDebug() << "To few arguments!";
qDebug() << "Usage: cmdtimeout [00h][00m]00[s] command [argumentlist]";
}
int msec = parseTime(QString(argv[1]));
QStringList lst;
for(int idx=0; idx < argc-3; idx++)
{
QString tmpString(argv[idx+3]);
lst += tmpString;
}
QString cmd(argv[2]);
Application app(cmd,lst,msec);
return a.exec();
}
int parseTime(QString time)
{
int res = 0;
int tmp = 0;
for(int idx=0; idx<time.length(); idx++)
{
if(time[idx].isDigit())
{
tmp *= 10;
tmp += time[idx].digitValue();
}
else
{
switch(time[idx].toLower().toLatin1())
{
case 'h':
tmp *= 3600000;
res += tmp;
tmp = 0;
break;
case 'm':
tmp *= 60000;
res += tmp;
tmp = 0;
break;
case 's':
tmp *= 1000;
res += tmp;
tmp = 0;
break;
default:
return res;
}
}
}
res += tmp * 1000;
return res;
}