/[dtapublic]/projs/trunk/projs/20120418_blackjacksim/source/bjcceval/timefunc.c
ViewVC logotype

Contents of /projs/trunk/projs/20120418_blackjacksim/source/bjcceval/timefunc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations) (download)
Fri Oct 7 03:35:12 2016 UTC (8 years, 1 month ago) by dashley
Original Path: swprojs/trunk/projs/20120418_blackjacksim/source/bjcceval/timefunc.c
File MIME type: text/plain
File size: 9914 byte(s)
Commit of Blackjack simulation project.
1 //----------------------------------------------------------------------------------------------------
2 //$Header: /home/dashley/cvsrep/e3ft_gpl01/e3ft_gpl01/dtaipubs/cron/2010/blackjack_201010/source/bjcceval/timefunc.c,v 1.2 2012/03/30 01:05:31 dashley Exp $
3 //----------------------------------------------------------------------------------------------------
4 //Copyright (C) 2012, David T. Ashley.
5 //
6 //This file is part of BJCCEVAL, a program that evaluates by simulation
7 //the best basic strategy, card-counting, and other playing strategies
8 //for several variants of the game of Blackjack.
9 //
10 //BJCCEVAL is free software: you can redistribute it and/or modify
11 //it under the terms of the GNU General Public License as published by
12 //the Free Software Foundation, either version 3 of the License, or
13 //(at your option) any later version.
14 //
15 //BJCCEVAL is distributed in the hope that it will be useful,
16 //but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 //GNU General Public License for more details.
19 //
20 //You should have received a copy of the GNU General Public License
21 //along with this program. If not, see <http://www.gnu.org/licenses/>.
22 //(A copy of the GNU General Public License, Version 3 is provided in
23 //the file "COPYING" distributed with BJCCEVAL.)
24 //
25 //David T. Ashley can be contacted at DASHLEY@GMAIL.COM and/or at
26 //P.O. Box 918, Marshall MI 49068.
27 //----------------------------------------------------------------------------------------------------
28 #define MODULE_TIMEFUNC
29
30 #include <assert.h>
31 #include <stdio.h>
32 #include <sys/timeb.h>
33 #include <time.h>
34
35 #include "timefunc.h"
36
37 #include "charfunc.h"
38
39
40 static unsigned TIMEFUNC_ascii_month_to_unsigned(char c1, char c2, char c3)
41 {
42 unsigned rv = 0;
43
44 c1 = CHARFUNC_to_upper(c1);
45 c2 = CHARFUNC_to_upper(c2);
46 c3 = CHARFUNC_to_upper(c3);
47
48 if (c1 == 'J')
49 {
50 if ((c2 == 'A') && (c3 == 'N'))
51 {
52 rv = 1;
53 } else if ((c2 == 'U') && (c3 == 'N'))
54 {
55 rv = 6;
56 } else if ((c2 == 'U') && (c3 == 'L'))
57 {
58 rv = 7;
59 }
60 } else if (c1 == 'F')
61 {
62 if ((c2 == 'E') && (c3 == 'B'))
63 {
64 rv = 2;
65 }
66 } else if (c1 == 'M')
67 {
68 if ((c2 == 'A') && (c3 == 'R'))
69 {
70 rv = 3;
71 } else if ((c2 == 'A') && (c3 == 'Y'))
72 {
73 rv = 5;
74 }
75 } else if (c1 == 'A')
76 {
77 if ((c2 == 'P') && (c3 == 'R'))
78 {
79 rv = 4;
80 } else if ((c2 == 'U') && (c3 == 'G'))
81 {
82 rv = 8;
83 }
84 } else if (c1 == 'S')
85 {
86 if ((c2 == 'E') && (c3 == 'P'))
87 {
88 rv = 9;
89 }
90 } else if (c1 == 'O')
91 {
92 if ((c2 == 'C') && (c3 == 'T'))
93 {
94 rv = 10;
95 }
96 } else if (c1 == 'N')
97 {
98 if ((c2 == 'O') && (c3 == 'V'))
99 {
100 rv = 11;
101 }
102 } else if (c1 == 'D')
103 {
104 if ((c2 == 'E') && (c3 == 'C'))
105 {
106 rv = 12;
107 }
108 }
109
110 return(rv);
111 }
112
113
114 void TIMEFUNC_to_ascii_logstamp(const struct __timeb64 *in_arg, TIMEFUNC_TIME_ASCII_RESULT *out_arg)
115 {
116 __time64_t time64;
117 errno_t error_return;
118 char buffer[100];
119
120 //Be sure we don't have an unbounded string just in case something goes wrong.
121 buffer[0] = 0;
122 buffer[sizeof(buffer) - 1] = 0;
123
124 //Extract the 64-bit time.
125 time64 = in_arg->time;
126
127 //Convert the 64-bit time to a string.
128 error_return = _ctime64_s(buffer, sizeof(buffer), &time64);
129 assert(error_return == 0);
130
131 //The first two digits of the logstamp should be the hour.
132 out_arg->result[0] = buffer[11];
133 out_arg->result[1] = buffer[12];
134
135 //The next two digits should be the minute.
136 out_arg->result[2] = buffer[14];
137 out_arg->result[3] = buffer[15];
138
139 //The next two digits should be the second.
140 out_arg->result[4] = buffer[17];
141 out_arg->result[5] = buffer[18];
142
143 //Then a decimal point.
144 out_arg->result[6] = '.';
145
146 //The next three (7, 8, 9) should be the milliseconds.
147 sprintf_s(&(out_arg->result[7]), 4, "%03d", in_arg->millitm);
148
149 //The tenth should be the terminator. It was probably handled by sprintf() above.
150 out_arg->result[10] = 0;
151
152 //printf("\n0000000000111111111122222222223\n0123456789012345678901234567890\n%s\n", buffer);
153 //printf("\n%s\n", out_arg->result);
154 }
155
156
157 void TIMEFUNC_to_ascii_hr_form(const struct __timeb64 *in_arg, TIMEFUNC_TIME_ASCII_RESULT *out_arg)
158 {
159 //Library function form.
160 //0000000000111111111122222222223
161 //0123456789012345678901234567890
162 //Sun Dec 14 00:36:36 2008
163 //
164 //Target form:
165 //000000000011111111112222222222333
166 //012345678901234567890123456789012
167 //Sun, Dec 14, 2008 at 00:36:36.123
168
169 __time64_t time64;
170 errno_t error_return;
171 char buffer[100];
172
173 //Be sure we don't have an unbounded string just in case something goes wrong.
174 buffer[0] = 0;
175 buffer[sizeof(buffer) - 1] = 0;
176
177 //Extract the 64-bit time.
178 time64 = in_arg->time;
179
180 //Convert the 64-bit time to a string.
181 error_return = _ctime64_s(buffer, sizeof(buffer), &time64);
182 assert(error_return == 0);
183
184 //The first three characters should be the day of the week.
185 out_arg->result[0] = buffer[0];
186 out_arg->result[1] = buffer[1];
187 out_arg->result[2] = buffer[2];
188
189 //Comma and a space.
190 out_arg->result[3] = ',';
191 out_arg->result[4] = ' ';
192
193 //Month
194 out_arg->result[5] = buffer[4];
195 out_arg->result[6] = buffer[5];
196 out_arg->result[7] = buffer[6];
197
198 //Space
199 out_arg->result[8] = ' ';
200
201 //Day of month, perhaps with preceding space.
202 out_arg->result[9] = buffer[8];
203 out_arg->result[10] = buffer[9];
204
205 //Comma and a space.
206 out_arg->result[11] = ',';
207 out_arg->result[12] = ' ';
208
209 //Year
210 out_arg->result[13] = buffer[20];
211 out_arg->result[14] = buffer[21];
212 out_arg->result[15] = buffer[22];
213 out_arg->result[16] = buffer[23];
214
215 //" at "
216 out_arg->result[17] = ' ';
217 out_arg->result[18] = 'a';
218 out_arg->result[19] = 't';
219 out_arg->result[20] = ' ';
220
221 //Hour
222 out_arg->result[21] = buffer[11];
223 out_arg->result[22] = buffer[12];
224
225 //Separating colon.
226 out_arg->result[23] = ':';
227
228 //Minute
229 out_arg->result[24] = buffer[14];
230 out_arg->result[25] = buffer[15];
231
232 //Separating colon.
233 out_arg->result[26] = ':';
234
235 //Integer seconds.
236 out_arg->result[27] = buffer[17];
237 out_arg->result[28] = buffer[18];
238
239 //"." Separator
240 out_arg->result[29] = '.';
241
242 //The next three (30, 31, 32) should be the milliseconds.
243 sprintf_s(&(out_arg->result[30]), 4, "%03d", in_arg->millitm);
244
245 //The tenth should be the terminator. It was probably handled by sprintf() above.
246 out_arg->result[33] = 0;
247
248 //printf("\n0000000000111111111122222222223\n0123456789012345678901234567890\n%s\n", buffer);
249 //printf("\n%s\n", out_arg->result);
250 }
251
252
253 void TIMEFUNC_to_ascii_filename_base(const struct __timeb64 *in_arg, TIMEFUNC_TIME_ASCII_RESULT *out_arg)
254 {
255 //Library function form.
256 //0000000000111111111122222222223
257 //0123456789012345678901234567890
258 //Sun Dec 14 00:36:38 2008
259 //
260 //Target form:
261 //000000000011111
262 //012345678901234
263 //20081214_003638
264
265 __time64_t time64;
266 errno_t error_return;
267 unsigned month;
268 char buffer[100];
269
270 //Be sure we don't have an unbounded string just in case something goes wrong.
271 buffer[0] = 0;
272 buffer[sizeof(buffer) - 1] = 0;
273
274 //Extract the 64-bit time.
275 time64 = in_arg->time;
276
277 //Convert the 64-bit time to a string.
278 error_return = _ctime64_s(buffer, sizeof(buffer), &time64);
279 assert(error_return == 0);
280
281 //Year
282 out_arg->result[0] = buffer[20];
283 out_arg->result[1] = buffer[21];
284 out_arg->result[2] = buffer[22];
285 out_arg->result[3] = buffer[23];
286
287 //Month
288 month = TIMEFUNC_ascii_month_to_unsigned(buffer[4], buffer[5], buffer[6]);
289
290 if (month == 0)
291 {
292 out_arg->result[4] = '?';
293 out_arg->result[5] = '?';
294 } else
295 {
296 sprintf_s(&(out_arg->result[4]), 3, "%02u", month);
297 }
298
299 //Day of month, perhaps with preceding space.
300 out_arg->result[6] = buffer[8];
301 out_arg->result[7] = buffer[9];
302
303 //Underscore.
304 out_arg->result[8] = '_';
305
306 //Hour
307 out_arg->result[9] = buffer[11];
308 out_arg->result[10] = buffer[12];
309
310 //Minute
311 out_arg->result[11] = buffer[14];
312 out_arg->result[12] = buffer[15];
313
314 //Second
315 out_arg->result[13] = buffer[17];
316 out_arg->result[14] = buffer[18];
317
318 //Zero terminator
319 out_arg->result[15] = 0;
320
321 //printf("\n0000000000111111111122222222223\n0123456789012345678901234567890\n%s\n", buffer);
322 //printf("\n%s\n", out_arg->result);
323 }
324
325
326 const char *TIMEFUNC_Vcinfo_C(void)
327 {
328 return("$Revision: 1.2 $");
329 }
330
331
332 const char *TIMEFUNC_Vcinfo_H(void)
333 {
334 return(TIMEFUNC_VCINFO_H);
335 }
336
337
338 //----------------------------------------------------------------------------------------------------
339 //$Log: timefunc.c,v $
340 //Revision 1.2 2012/03/30 01:05:31 dashley
341 //Edits.
342 //
343 //Revision 1.1 2012/03/30 00:59:16 dashley
344 //Initial checkin.
345 //----------------------------------------------------------------------------------------------------
346 //End of $RCSfile: timefunc.c,v $
347 //----------------------------------------------------------------------------------------------------

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25