-
Notifications
You must be signed in to change notification settings - Fork 0
/
textclock.cpp
86 lines (76 loc) · 1.38 KB
/
textclock.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "clock.h"
#include "fuzzyclock.h"
#include "qlock.h"
#include "strings.h"
#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
bool qlock = false;
string lng = "de";
void printHelp()
{
int i = 0;
cout << "Simple textclock printout, fuzzy mode is default." << endl;
cout << "Usage: textclock <option>" << endl;
cout << " options: -q qlock clock mode" << endl;
cout << " -l set output language." << endl;
cout << " -h print this help" << endl;
cout << " languages: ";
for(i=0; i<MAX_LNG; ++i)
{
cout << languages[i];
if(i+1 < MAX_LNG)
cout << ", ";
}
cout << endl;
exit(0);
}
void parseOpts(int argc, char* argv[])
{
bool foundlng = false;
int opt = 0, i = 0;
while((opt = getopt(argc, argv, "hl:q")) != -1)
{
switch(opt)
{
case 'l':
lng = optarg;
for(i=0; i<MAX_LNG; ++i)
{
if(lng == languages[i])
{
foundlng = true;
break;
}
}
if(!foundlng)
{
cout << "Language \"" << lng << "\" is not yet supported" << endl;
printHelp();
}
break;
case 'q':
qlock = true;
break;
case 'h':
default:
printHelp();
break;
}
}
}
int main(int argc, char* argv[])
{
Clock *now = NULL;
parseOpts(argc, argv);
if(qlock)
now = new Qlock(lng);
else
now = new Fuzzyclock(lng);
if(NULL != now)
{
cout << now->to_string() << endl;
delete now;
}
}