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

Contents of /swprojs/trunk/projs/20120418_blackjacksim/source/bjcceval/charfunc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations) (download)
Fri Oct 7 03:35:12 2016 UTC (6 years, 3 months ago) by dashley
File MIME type: text/plain
File size: 11307 byte(s)
Commit of Blackjack simulation project.
1 //----------------------------------------------------------------------------------------------------
2 //$Header: /home/dashley/cvsrep/e3ft_gpl01/e3ft_gpl01/dtaipubs/cron/2010/blackjack_201010/source/bjcceval/charfunc.c,v 1.6 2012/03/30 00:58:36 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_CHARFUNC
29
30 #include <string.h>
31
32 #include "cassert.h"
33 #include "charfunc.h"
34
35
36 int CHARFUNC_is_digit(char c)
37 {
38 switch (c)
39 {
40 case '0': return(1);
41 break;
42 case '1': return(1);
43 break;
44 case '2': return(1);
45 break;
46 case '3': return(1);
47 break;
48 case '4': return(1);
49 break;
50 case '5': return(1);
51 break;
52 case '6': return(1);
53 break;
54 case '7': return(1);
55 break;
56 case '8': return(1);
57 break;
58 case '9': return(1);
59 break;
60 default: return(0);
61 break;
62 }
63 }
64
65
66 int CHARFUNC_is_letter_lc(char c)
67 {
68 switch (c)
69 {
70 case 'a':
71 return(1);
72 break;
73 case 'b':
74 return(1);
75 break;
76 case 'c':
77 return(1);
78 break;
79 case 'd':
80 return(1);
81 break;
82 case 'e':
83 return(1);
84 break;
85 case 'f':
86 return(1);
87 break;
88 case 'g':
89 return(1);
90 break;
91 case 'h':
92 return(1);
93 break;
94 case 'i':
95 return(1);
96 break;
97 case 'j':
98 return(1);
99 break;
100 case 'k':
101 return(1);
102 break;
103 case 'l':
104 return(1);
105 break;
106 case 'm':
107 return(1);
108 break;
109 case 'n':
110 return(1);
111 break;
112 case 'o':
113 return(1);
114 break;
115 case 'p':
116 return(1);
117 break;
118 case 'q':
119 return(1);
120 break;
121 case 'r':
122 return(1);
123 break;
124 case 's':
125 return(1);
126 break;
127 case 't':
128 return(1);
129 break;
130 case 'u':
131 return(1);
132 break;
133 case 'v':
134 return(1);
135 break;
136 case 'w':
137 return(1);
138 break;
139 case 'x':
140 return(1);
141 break;
142 case 'y':
143 return(1);
144 break;
145 case 'z':
146 return(1);
147 break;
148 default:
149 return(0);
150 break;
151 }
152 }
153
154
155 int CHARFUNC_is_letter_uc(char c)
156 {
157 switch (c)
158 {
159 case 'A':
160 return(1);
161 break;
162 case 'B':
163 return(1);
164 break;
165 case 'C':
166 return(1);
167 break;
168 case 'D':
169 return(1);
170 break;
171 case 'E':
172 return(1);
173 break;
174 case 'F':
175 return(1);
176 break;
177 case 'G':
178 return(1);
179 break;
180 case 'H':
181 return(1);
182 break;
183 case 'I':
184 return(1);
185 break;
186 case 'J':
187 return(1);
188 break;
189 case 'K':
190 return(1);
191 break;
192 case 'L':
193 return(1);
194 break;
195 case 'M':
196 return(1);
197 break;
198 case 'N':
199 return(1);
200 break;
201 case 'O':
202 return(1);
203 break;
204 case 'P':
205 return(1);
206 break;
207 case 'Q':
208 return(1);
209 break;
210 case 'R':
211 return(1);
212 break;
213 case 'S':
214 return(1);
215 break;
216 case 'T':
217 return(1);
218 break;
219 case 'U':
220 return(1);
221 break;
222 case 'V':
223 return(1);
224 break;
225 case 'W':
226 return(1);
227 break;
228 case 'X':
229 return(1);
230 break;
231 case 'Y':
232 return(1);
233 break;
234 case 'Z':
235 return(1);
236 break;
237 default:
238 return(0);
239 break;
240 }
241 }
242
243
244 int CHARFUNC_is_whitespace(char c)
245 {
246 if ((c==' ') || (c=='\t') || (c=='\n'))
247 return(1);
248 else
249 return(0);
250 }
251
252
253 int CHARFUNC_digit_to_val(char digit)
254 {
255 switch (digit)
256 {
257 case '0': return(0);
258 break;
259 case '1': return(1);
260 break;
261 case '2': return(2);
262 break;
263 case '3': return(3);
264 break;
265 case '4': return(4);
266 break;
267 case '5': return(5);
268 break;
269 case '6': return(6);
270 break;
271 case '7': return(7);
272 break;
273 case '8': return(8);
274 break;
275 case '9': return(9);
276 break;
277 default: return(-1);
278 break;
279 }
280 }
281
282
283 char CHARFUNC_nibble_to_lc_hex_digit(int nibble)
284 {
285 switch (nibble & 0x0F)
286 {
287 case 0:
288 return('0');
289 break;
290 case 1:
291 return('1');
292 break;
293 case 2:
294 return('2');
295 break;
296 case 3:
297 return('3');
298 break;
299 case 4:
300 return('4');
301 break;
302 case 5:
303 return('5');
304 break;
305 case 6:
306 return('6');
307 break;
308 case 7:
309 return('7');
310 break;
311 case 8:
312 return('8');
313 break;
314 case 9:
315 return('9');
316 break;
317 case 10:
318 return('a');
319 break;
320 case 11:
321 return('b');
322 break;
323 case 12:
324 return('c');
325 break;
326 case 13:
327 return('d');
328 break;
329 case 14:
330 return('e');
331 break;
332 case 15:
333 return('f');
334 break;
335 default:
336 #ifdef P_CASSERT
337 CASSERT_Assert(0, __FILE__, __LINE__);
338 #endif
339 return('?');
340 break;
341 }
342 }
343
344
345 void CHARFUNC_int_to_lc_hex_rev(int arg, char *s)
346 {
347 int i;
348
349 #ifdef P_CASSERT
350 CASSERT_Assert(s != NULL, __FILE__, __LINE__);
351 #endif
352
353 for (i=0; i<8; i++)
354 {
355 s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg);
356 arg >>= 4;
357 }
358 }
359
360
361 char CHARFUNC_to_upper(char c)
362 {
363 switch (c)
364 {
365 case 'a':
366 return('A');
367 break;
368 case 'b':
369 return('B');
370 break;
371 case 'c':
372 return('C');
373 break;
374 case 'd':
375 return('D');
376 break;
377 case 'e':
378 return('E');
379 break;
380 case 'f':
381 return('F');
382 break;
383 case 'g':
384 return('G');
385 break;
386 case 'h':
387 return('H');
388 break;
389 case 'i':
390 return('I');
391 break;
392 case 'j':
393 return('J');
394 break;
395 case 'k':
396 return('K');
397 break;
398 case 'l':
399 return('L');
400 break;
401 case 'm':
402 return('M');
403 break;
404 case 'n':
405 return('N');
406 break;
407 case 'o':
408 return('O');
409 break;
410 case 'p':
411 return('P');
412 break;
413 case 'q':
414 return('Q');
415 break;
416 case 'r':
417 return('R');
418 break;
419 case 's':
420 return('S');
421 break;
422 case 't':
423 return('T');
424 break;
425 case 'u':
426 return('U');
427 break;
428 case 'v':
429 return('V');
430 break;
431 case 'w':
432 return('W');
433 break;
434 case 'x':
435 return('X');
436 break;
437 case 'y':
438 return('Y');
439 break;
440 case 'z':
441 return('Z');
442 break;
443 default:
444 return(c);
445 break;
446 }
447 }
448
449
450 char CHARFUNC_to_lower(char c)
451 {
452 switch (c)
453 {
454 case 'A':
455 return('a');
456 break;
457 case 'B':
458 return('b');
459 break;
460 case 'C':
461 return('c');
462 break;
463 case 'D':
464 return('d');
465 break;
466 case 'E':
467 return('e');
468 break;
469 case 'F':
470 return('f');
471 break;
472 case 'G':
473 return('g');
474 break;
475 case 'H':
476 return('h');
477 break;
478 case 'I':
479 return('i');
480 break;
481 case 'J':
482 return('j');
483 break;
484 case 'K':
485 return('k');
486 break;
487 case 'L':
488 return('l');
489 break;
490 case 'M':
491 return('m');
492 break;
493 case 'N':
494 return('n');
495 break;
496 case 'O':
497 return('o');
498 break;
499 case 'P':
500 return('p');
501 break;
502 case 'Q':
503 return('q');
504 break;
505 case 'R':
506 return('r');
507 break;
508 case 'S':
509 return('s');
510 break;
511 case 'T':
512 return('t');
513 break;
514 case 'U':
515 return('u');
516 break;
517 case 'V':
518 return('v');
519 break;
520 case 'W':
521 return('w');
522 break;
523 case 'X':
524 return('x');
525 break;
526 case 'Y':
527 return('y');
528 break;
529 case 'Z':
530 return('z');
531 break;
532 default:
533 return(c);
534 break;
535 }
536 }
537
538 char CHARFUNC_int_to_lower(int arg)
539 {
540 static const char *ref = "abcdefghijklmnopqrstuvwxyz";
541
542 if ((arg >= 0) && ((unsigned)arg < strlen(ref)))
543 {
544 return(ref[arg]);
545 } else
546 {
547 return('?');
548 }
549 }
550
551
552 const char *CHARFUNC_Vcinfo_C(void)
553 {
554 return("$Revision: 1.6 $");
555 }
556
557
558 const char *CHARFUNC_Vcinfo_H(void)
559 {
560 return(CHARFUNC_VCINFO_H);
561 }
562
563
564 //----------------------------------------------------------------------------------------------------
565 //$Log: charfunc.c,v $
566 //Revision 1.6 2012/03/30 00:58:36 dashley
567 //Edits.
568 //
569 //Revision 1.5 2012/03/29 23:44:00 dashley
570 //Edits.
571 //
572 //Revision 1.4 2012/03/29 00:42:06 dashley
573 //Edits.
574 //
575 //Revision 1.3 2012/03/28 23:58:42 dashley
576 //Edits.
577 //
578 //Revision 1.2 2012/03/15 23:38:08 dashley
579 //License text enhanced.
580 //
581 //Revision 1.1 2012/03/12 02:54:25 dashley
582 //Initial checkin.
583 //----------------------------------------------------------------------------------------------------
584 //End of $RCSfile: charfunc.c,v $
585 //----------------------------------------------------------------------------------------------------

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25