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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* def.h
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __DEF_H__
#define __DEF_H__
//***************************************************************************
// Includes
//***************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // memset
#include <time.h>
#include <ctype.h> // isdigit
//***************************************************************************
// Public Declarations
//***************************************************************************
enum Misc
{
success = 0,
done = success,
fail = -1,
ignore = -1,
na = -1,
yes = 1,
no = 0,
TB = 1
};
enum Eloquence
{
eloOff, // 0
eloNormal, // 1
eloAlways = eloNormal, // 1 historical ;)
eloDetail, // 2
eloDebug, // 3
eloDebug1 = eloDebug, // 3
eloDebug2, // 4
eloDebug3 // 5
};
enum Sizes
{
sizeStamp = 14,
sizeTime = 6,
sizeDate = 8,
sizeHHMM = 4
};
enum TimeFact
{
// Defintion
tfMonthsPerYear = 12,
tfWeeksPerYear = 52,
tfDaysPerYear = 365,
tfDaysPerWeek = 7,
tfHoursPerDay = 24,
tfMinutesPerHour = 60,
tfSecondsPerMinute = 60,
// Calculation
tfSecondsPerHour = tfMinutesPerHour * tfSecondsPerMinute,
tfSecondsPerDay = tfHoursPerDay * tfSecondsPerHour,
tfSecondsPerYear = tfDaysPerYear * tfSecondsPerDay,
tfSecondsPerWeek = tfDaysPerWeek * tfSecondsPerDay,
};
//***************************************************************************
// Tell
//***************************************************************************
extern int logLevel;
int tell(int eloquence, const char* format, ...);
//***************************************************************************
// Date Time
//***************************************************************************
class DT
{
public:
typedef tm STime;
static long lNow()
{
long lt = time(0);
STime st;
localtime_r(<, &st);
lt = mktime(&st);
lt -= timezone; // care timezone
lt += st.tm_isdst ? tfSecondsPerHour : 0; // care daylightsavingtime
return lt;
}
static char* int2Hhmm(long lt, char* ct)
{
STime st;
memset(&st, 0, sizeof(STime));
gmtime_r(<, &st);
sprintf(ct, "%2.2d%2.2d", st.tm_hour, st.tm_min);
return ct;
}
static long hhmm2Int(const char* c)
{
long lt = 0;
char ct[sizeHHMM+TB];
if (strlen(c) != 4)
return na;
strcpy(ct, c);
lt = atoi(ct+2) * 60;
ct[2] = 0;
lt += atoi(ct) * 60 * 60;
return lt;
}
};
//***************************************************************************
// String
//***************************************************************************
class Str
{
public:
static const char* stripHotKey(const char* text)
{
static char buffer[64];
const char* p = text;
while (*p)
{
if (*p == ' ')
p++;
else if (isdigit(*p) && isdigit(*(p+1)))
p++;
else if (isdigit(*p) && *(p+1) == ' ')
{
p++;
while (*p == ' ') p++;
break;
}
else
{
p = text;
break;
}
}
strcpy(buffer, p);
return buffer;
}
};
//***************************************************************************
#endif // __DEF_H__
|