forked from knizhnik/ptoc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpaslib.cpp
More file actions
159 lines (127 loc) · 2.8 KB
/
paslib.cpp
File metadata and controls
159 lines (127 loc) · 2.8 KB
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
#include <time.h>
#include "ptoc.h"
void timestamp(integer* day, integer* month, integer* year, integer* hour, integer* min, integer* sec)
{
time_t ctime;
struct tm* tmp;
time(&ctime);
tmp = localtime(&ctime);
*day = tmp->tm_mday;
*month = tmp->tm_mon + 1;
*year = 1900 + tmp->tm_year;
*hour = tmp->tm_hour;
*min = tmp->tm_min;
*sec = tmp->tm_sec;
}
real get_realtime()
{
time_t ctime;
struct tm* tmp;
time(&ctime);
tmp = localtime(&ctime);
return (real)(tmp->tm_hour + tmp->tm_min / 60.0);
}
/*integer round(real x)
{
return x >= 0 ? trunc(x + 0.5) : trunc(x - 0.5);
}*/
#define CIRCULAR_BUFFER_SIZE 4096
char* lpsz(int low, int high, const char* str)
{
static char buffer[CIRCULAR_BUFFER_SIZE];
static int pos = 0;
int size;
char* ptr;
while (high >= low && str[high - low] == ' ') {
high -= 1;
}
size = high - low + 1;
if (pos + size >= sizeof(buffer)) {
pos = 0;
}
ptr = &buffer[pos];
pos += size + 1;
memcpy(ptr, str, size);
ptr[size] = '\0';
return ptr;
}
unsigned randseed;
const unsigned modulus = 2147483647;
const unsigned factor = 397204094;
void Randomize()
{
randseed = time(NULL);
}
unsigned randint(unsigned range)
{
randseed = randseed * factor % modulus;
return range ? randseed % range : 0;
}
double randreal()
{
randseed = randseed * factor % modulus;
return (double)randseed / modulus;
}
char* get_date()
{
static char buf[16];
time_t ctime;
struct tm* tmp;
time(&ctime);
tmp = localtime(&ctime);
sprintf(buf, "%02d.%02d.%4d", tmp->tm_mday, tmp->tm_mon + 1, 1900 + tmp->tm_year);
return buf;
}
char* get_time()
{
static char buf[8];
time_t ctime;
struct tm* tmp;
time(&ctime);
tmp = localtime(&ctime);
sprintf(buf, "%d:%d", tmp->tm_hour, tmp->tm_min);
return buf;
}
constexpr auto CONV_BUF = 20;
// converts int Value to string
string IntToStr(int Value)
{
char buf[CONV_BUF];
sprintf(buf, "%d", Value);
return buf;
}
// converts unsigned int Value to string
string IntToStr(unsigned int Value)
{
char buf[CONV_BUF];
sprintf(buf, "%u", Value);
return buf;
}
//converts unsigned long Value to string
string IntToStr(unsigned long Value)
{
char buf[CONV_BUF];
sprintf(buf, "%lu", Value);
return buf;
}
//converts long Value to string
string IntToStr(long Value)
{
char buf[CONV_BUF];
sprintf(buf, "%ld", Value);
return buf;
}
//converts long long Value to string
string IntToStr(long long Value)
{
char buf[CONV_BUF];
sprintf(buf, "%lld", Value);
return buf;
}
//converts unsigned long long Value to string
string IntToStr(unsigned long long Value)
{
char buf[CONV_BUF];
sprintf(buf, "%llu", Value);
return buf;
}