/[dtapublic]/projs/trunk/shared_source/c_datd/charfunc.c
ViewVC logotype

Diff of /projs/trunk/shared_source/c_datd/charfunc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 70 by dashley, Sat Oct 29 01:53:01 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components
4  //integrated into many of David T. Ashley's projects.  //integrated into many of David T. Ashley's projects.
5  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
6  //This source code and any program in which it is compiled/used is provided under the MIT License,  //This source code and any program in which it is compiled/used is provided under the MIT License,
7  //reproduced below.  //reproduced below.
8  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
9  //Permission is hereby granted, free of charge, to any person obtaining a copy of  //Permission is hereby granted, free of charge, to any person obtaining a copy of
10  //this software and associated documentation files(the "Software"), to deal in the  //this software and associated documentation files(the "Software"), to deal in the
11  //Software without restriction, including without limitation the rights to use,  //Software without restriction, including without limitation the rights to use,
12  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
13  //Software, and to permit persons to whom the Software is furnished to do so,  //Software, and to permit persons to whom the Software is furnished to do so,
14  //subject to the following conditions :  //subject to the following conditions :
15  //  //
16  //The above copyright notice and this permission notice shall be included in all  //The above copyright notice and this permission notice shall be included in all
17  //copies or substantial portions of the Software.  //copies or substantial portions of the Software.
18  //  //
19  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  //SOFTWARE.  //SOFTWARE.
26  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
27  #define MODULE_CHARFUNC  #define MODULE_CHARFUNC
28    
29  #include <assert.h>  #include <assert.h>
30  #include <stddef.h>  #include <stddef.h>
31    
32  #include "charfunc.h"  #include "charfunc.h"
33    
34    
35  int CHARFUNC_digit_to_val(char digit)  int CHARFUNC_digit_to_val(char digit)
36     {     {
37     switch (digit)     switch (digit)
38        {        {
39        case '0':  return(0);        case '0':  return(0);
40                   break;                   break;
41        case '1':  return(1);        case '1':  return(1);
42                   break;                   break;
43        case '2':  return(2);        case '2':  return(2);
44                   break;                   break;
45        case '3':  return(3);        case '3':  return(3);
46                   break;                   break;
47        case '4':  return(4);        case '4':  return(4);
48                   break;                   break;
49        case '5':  return(5);        case '5':  return(5);
50                   break;                   break;
51        case '6':  return(6);        case '6':  return(6);
52                   break;                   break;
53        case '7':  return(7);        case '7':  return(7);
54                   break;                   break;
55        case '8':  return(8);        case '8':  return(8);
56                   break;                   break;
57        case '9':  return(9);        case '9':  return(9);
58                   break;                   break;
59        default:   return(-1);        default:   return(-1);
60                   break;                   break;
61        }        }
62     }     }
63    
64    
65  char CHARFUNC_nibble_to_lc_hex_digit(int nibble)  char CHARFUNC_nibble_to_lc_hex_digit(int nibble)
66     {     {
67     switch (nibble & 0x0F)     switch (nibble & 0x0F)
68        {        {
69        case  0:        case  0:
70           return('0');           return('0');
71           break;           break;
72        case  1:        case  1:
73           return('1');           return('1');
74           break;           break;
75        case  2:        case  2:
76           return('2');           return('2');
77           break;           break;
78        case  3:        case  3:
79           return('3');           return('3');
80           break;           break;
81        case  4:        case  4:
82           return('4');           return('4');
83           break;           break;
84        case  5:        case  5:
85           return('5');           return('5');
86           break;           break;
87        case  6:        case  6:
88           return('6');           return('6');
89           break;           break;
90        case  7:        case  7:
91           return('7');           return('7');
92           break;           break;
93        case  8:        case  8:
94           return('8');           return('8');
95           break;           break;
96        case  9:        case  9:
97           return('9');           return('9');
98           break;           break;
99        case 10:        case 10:
100           return('a');           return('a');
101           break;           break;
102        case 11:        case 11:
103           return('b');           return('b');
104           break;           break;
105        case 12:        case 12:
106           return('c');           return('c');
107           break;           break;
108        case 13:        case 13:
109           return('d');           return('d');
110           break;           break;
111        case 14:        case 14:
112           return('e');           return('e');
113           break;           break;
114        case 15:        case 15:
115           return('f');           return('f');
116           break;           break;
117        default:        default:
118           assert(0);           assert(0);
119           return('?');           return('?');
120           break;           break;
121        }        }
122     }     }
123    
124    
125  void CHARFUNC_int_to_lc_hex_rev(int arg, char *s)  void CHARFUNC_int_to_lc_hex_rev(int arg, char *s)
126     {     {
127     int i;     int i;
128    
129     assert(s != NULL);     assert(s != NULL);
130    
131     for (i=0; i<8; i++)     for (i=0; i<8; i++)
132        {        {
133        s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg);        s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg);
134        arg >>= 4;        arg >>= 4;
135        }        }
136     }     }
137    
138  const char *CHARFUNC_cvcinfo(void)  const char *CHARFUNC_cvcinfo(void)
139     {     {
140     return("$Header$");     return("$Header$");
141     }     }
142    
143    
144  const char *CHARFUNC_hvcinfo(void)  const char *CHARFUNC_hvcinfo(void)
145     {     {
146     return(CHARFUNC_H_VERSION);     return(CHARFUNC_H_VERSION);
147     }     }
148    
149  //End of charfunc.c.  //End of charfunc.c.

Legend:
Removed from v.70  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25