1 |
//$Header: /cvsroot/esrg/sfesrg/esrgnxpj/sfnthcgi0304/auxfuncs.c,v 1.2 2003/04/17 20:02:05 dtashley Exp $ |
//$Header$ |
2 |
// |
// |
3 |
//******************************************************************************** |
//******************************************************************************** |
4 |
//Copyright (C) 2003 David T. Ashley |
//Copyright (C) 2003 David T. Ashley |
5 |
//******************************************************************************** |
//******************************************************************************** |
6 |
//This program or source file is free software; you can redistribute it and/or |
//This program or source file is free software; you can redistribute it and/or |
7 |
//modify it under the terms of the GNU General Public License as published by |
//modify it under the terms of the GNU General Public License as published by |
8 |
//the Free Software Foundation; either version 2 of the License, or (at your |
//the Free Software Foundation; either version 2 of the License, or (at your |
9 |
//option) any later version. |
//option) any later version. |
10 |
// |
// |
11 |
//This program or source file is distributed in the hope that it will |
//This program or source file is distributed in the hope that it will |
12 |
//be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
//be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
//GNU General Public License for more details. |
//GNU General Public License for more details. |
15 |
// |
// |
16 |
//You may have received a copy of the GNU General Public License |
//You may have received a copy of the GNU General Public License |
17 |
//along with this program; if not, write to the Free Software |
//along with this program; if not, write to the Free Software |
18 |
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
//******************************************************************************** |
//******************************************************************************** |
20 |
// |
// |
21 |
#define MODULE_AUXFUNCS |
#define MODULE_AUXFUNCS |
22 |
|
|
23 |
#include <assert.h> |
#include <assert.h> |
24 |
#include <ctype.h> |
#include <ctype.h> |
25 |
#include <stddef.h> |
#include <stddef.h> |
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <string.h> |
#include <string.h> |
28 |
#include <time.h> |
#include <time.h> |
29 |
|
|
30 |
#include "auxfuncs.h" |
#include "auxfuncs.h" |
31 |
|
|
32 |
|
|
33 |
/******************************************************************/ |
/******************************************************************/ |
34 |
/*** CHARACTER CLASSIFICATION FUNCTIONS ************************/ |
/*** CHARACTER CLASSIFICATION FUNCTIONS ************************/ |
35 |
/******************************************************************/ |
/******************************************************************/ |
36 |
int AUXFUNCS_is_digit(char c) |
int AUXFUNCS_is_digit(char c) |
37 |
{ |
{ |
38 |
if ((c >= '0') && (c <= '9')) |
if ((c >= '0') && (c <= '9')) |
39 |
return(1); |
return(1); |
40 |
else |
else |
41 |
return(0); |
return(0); |
42 |
} |
} |
43 |
|
|
44 |
int AUXFUNCS_digit_to_val(char digit) |
int AUXFUNCS_digit_to_val(char digit) |
45 |
{ |
{ |
46 |
switch (digit) |
switch (digit) |
47 |
{ |
{ |
48 |
case '0': return(0); |
case '0': return(0); |
49 |
break; |
break; |
50 |
case '1': return(1); |
case '1': return(1); |
51 |
break; |
break; |
52 |
case '2': return(2); |
case '2': return(2); |
53 |
break; |
break; |
54 |
case '3': return(3); |
case '3': return(3); |
55 |
break; |
break; |
56 |
case '4': return(4); |
case '4': return(4); |
57 |
break; |
break; |
58 |
case '5': return(5); |
case '5': return(5); |
59 |
break; |
break; |
60 |
case '6': return(6); |
case '6': return(6); |
61 |
break; |
break; |
62 |
case '7': return(7); |
case '7': return(7); |
63 |
break; |
break; |
64 |
case '8': return(8); |
case '8': return(8); |
65 |
break; |
break; |
66 |
case '9': return(9); |
case '9': return(9); |
67 |
break; |
break; |
68 |
default: return(-1); |
default: return(-1); |
69 |
break; |
break; |
70 |
} |
} |
71 |
} |
} |
72 |
|
|
73 |
/******************************************************************/ |
/******************************************************************/ |
74 |
/*** INTEGER SIZE_T FUNCTIONS ************************/ |
/*** INTEGER SIZE_T FUNCTIONS ************************/ |
75 |
/******************************************************************/ |
/******************************************************************/ |
76 |
size_t AUXFUNCS_size_t_min(size_t a, size_t b) |
size_t AUXFUNCS_size_t_min(size_t a, size_t b) |
77 |
{ |
{ |
78 |
if (a < b) |
if (a < b) |
79 |
return(a); |
return(a); |
80 |
else |
else |
81 |
return(b); |
return(b); |
82 |
} |
} |
83 |
|
|
84 |
size_t AUXFUNCS_size_t_max(size_t a, size_t b) |
size_t AUXFUNCS_size_t_max(size_t a, size_t b) |
85 |
{ |
{ |
86 |
if (a > b) |
if (a > b) |
87 |
return(a); |
return(a); |
88 |
else |
else |
89 |
return(b); |
return(b); |
90 |
} |
} |
91 |
|
|
92 |
|
|
93 |
/******************************************************************/ |
/******************************************************************/ |
94 |
/*** CONTRACTING STRING FUNCTIONS *******************************/ |
/*** CONTRACTING STRING FUNCTIONS *******************************/ |
95 |
/******************************************************************/ |
/******************************************************************/ |
96 |
void AUXFUNCS_remove_non_digits(char *s) |
void AUXFUNCS_remove_non_digits(char *s) |
97 |
{ |
{ |
98 |
char *src; |
char *src; |
99 |
char *dst; |
char *dst; |
100 |
|
|
101 |
src = s; |
src = s; |
102 |
dst = s; |
dst = s; |
103 |
|
|
104 |
while(*src) |
while(*src) |
105 |
{ |
{ |
106 |
if (AUXFUNCS_is_digit(*src)) |
if (AUXFUNCS_is_digit(*src)) |
107 |
{ |
{ |
108 |
*dst = *src; |
*dst = *src; |
109 |
dst++; |
dst++; |
110 |
} |
} |
111 |
src++; |
src++; |
112 |
} |
} |
113 |
|
|
114 |
*dst = 0; |
*dst = 0; |
115 |
} |
} |
116 |
|
|
117 |
void AUXFUNCS_remove_leading_zeros(char *s) |
void AUXFUNCS_remove_leading_zeros(char *s) |
118 |
{ |
{ |
119 |
char *src; |
char *src; |
120 |
char *dst; |
char *dst; |
121 |
|
|
122 |
src = s; |
src = s; |
123 |
dst = s; |
dst = s; |
124 |
|
|
125 |
while((*src) && (*src == '0')) |
while((*src) && (*src == '0')) |
126 |
{ |
{ |
127 |
src++; |
src++; |
128 |
} |
} |
129 |
|
|
130 |
while(*src) |
while(*src) |
131 |
{ |
{ |
132 |
*dst = *src; |
*dst = *src; |
133 |
src++; |
src++; |
134 |
dst++; |
dst++; |
135 |
} |
} |
136 |
|
|
137 |
*dst = 0; |
*dst = 0; |
138 |
} |
} |
139 |
|
|
140 |
|
|
141 |
/******************************************************************/ |
/******************************************************************/ |
142 |
/*** VERSION CONTROL IDENTITY FUNCTIONS ************************/ |
/*** VERSION CONTROL IDENTITY FUNCTIONS ************************/ |
143 |
/******************************************************************/ |
/******************************************************************/ |
144 |
const char *AUXFUNCS_cvcinfo(void) |
const char *AUXFUNCS_cvcinfo(void) |
145 |
{ |
{ |
146 |
return("$Header: /cvsroot/esrg/sfesrg/esrgnxpj/sfnthcgi0304/auxfuncs.c,v 1.2 2003/04/17 20:02:05 dtashley Exp $"); |
return("$Header$"); |
147 |
} |
} |
148 |
|
|
149 |
const char *AUXFUNCS_hvcinfo(void) |
const char *AUXFUNCS_hvcinfo(void) |
150 |
{ |
{ |
151 |
return(AUXFUNCS_H_VERSION); |
return(AUXFUNCS_H_VERSION); |
152 |
} |
} |
153 |
|
|
154 |
//******************************************************************************** |
//******************************************************************************** |
155 |
// $Log: auxfuncs.c,v $ |
// $Log: auxfuncs.c,v $ |
156 |
// Revision 1.2 2003/04/17 20:02:05 dtashley |
// Revision 1.2 2003/04/17 20:02:05 dtashley |
157 |
// License text for the GPL added. All source files are now under the GPL, |
// License text for the GPL added. All source files are now under the GPL, |
158 |
// after some discussion on the GMP list. |
// after some discussion on the GMP list. |
159 |
// |
// |
160 |
// Revision 1.1 2003/04/13 23:46:06 dtashley |
// Revision 1.1 2003/04/13 23:46:06 dtashley |
161 |
// Initial checkin. |
// Initial checkin. |
162 |
//******************************************************************************** |
//******************************************************************************** |
163 |
// End of AUXFUNCS.C. |
// End of AUXFUNCS.C. |
164 |
//******************************************************************************** |
//******************************************************************************** |