Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/algol60/src/utilities/sid/cstring.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**** cstring.c --- C string manipulation.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 **** Commentary:
36
 *
37
 * This file implements the C string manipulation facility specified in the
38
 * file "cstring.h".  See that file for more details.
39
 *
40
 **** Change Log:
41
 * $Log: cstring.c,v $
42
 * Revision 1.3  1998/03/17  11:38:15  release
43
 * Missing ';'.
44
 *
45
 * Revision 1.2  1998/03/16  11:26:34  release
46
 * Modifications prior to version 4.1.2.
47
 *
48
 * Revision 1.1.1.1  1998/01/17  15:57:45  release
49
 * First version to be checked into rolling release.
50
 *
51
 * Revision 1.2  1994/12/12  11:45:24  smf
52
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
53
 * OSSG C Coding Standards.
54
 *
55
 * Revision 1.1.1.1  1994/07/25  16:06:09  smf
56
 * Initial import of os-interface shared files.
57
 *
58
**/
59
 
60
/****************************************************************************/
61
 
62
#include "cstring.h"
63
#include "syntax.h"
64
 
65
/*--------------------------------------------------------------------------*/
66
 
67
CStringP
68
cstring_duplicate PROTO_N ((cstring))
69
		  PROTO_T (CStringP cstring)
70
{
71
    unsigned length = cstring_length (cstring);
72
    CStringP tmp    = ALLOCATE_VECTOR (char, length + 1);
73
 
74
    (void) strcpy (tmp, cstring);
75
    return (tmp);
76
}
77
 
78
CStringP
79
cstring_duplicate_prefix PROTO_N ((cstring, prefix))
80
			 PROTO_T (CStringP cstring X
81
				  unsigned prefix)
82
{
83
    unsigned length = cstring_length (cstring);
84
 
85
    if (length <= prefix) {
86
	CStringP tmp = ALLOCATE_VECTOR (char, length + 1);
87
 
88
	(void) strcpy (tmp, cstring);
89
	return (tmp);
90
    } else {
91
	CStringP tmp = ALLOCATE_VECTOR (char, prefix + 1);
92
 
93
	(void) memcpy ((GenericP) tmp, (GenericP) cstring, (SizeT) prefix);
94
	tmp [prefix] = '\0';
95
	return (tmp);
96
    }
97
}
98
 
99
unsigned
100
cstring_hash_value PROTO_N ((cstring))
101
		   PROTO_T (CStringP cstring)
102
{
103
    unsigned value = 0;
104
 
105
    while (*cstring) {
106
	value += ((unsigned) (*cstring ++));
107
    }
108
    return (value);
109
}
110
 
111
#ifdef FS_FAST
112
#undef cstring_length
113
#endif /* defined (FS_FAST) */
114
unsigned
115
cstring_length PROTO_N ((cstring))
116
	       PROTO_T (CStringP cstring)
117
{
118
    return ((unsigned) strlen (cstring));
119
}
120
#ifdef FS_FAST
121
#define cstring_length(s) ((unsigned) strlen (s))
122
#endif /* defined (FS_FAST) */
123
 
124
#ifdef FS_FAST
125
#undef cstring_equal
126
#endif /* defined (FS_FAST) */
127
BoolT
128
cstring_equal PROTO_N ((cstring1, cstring2))
129
	      PROTO_T (CStringP cstring1 X
130
		       CStringP cstring2)
131
{
132
    return (strcmp (cstring1, cstring2) == 0);
133
}
134
#ifdef FS_FAST
135
#define cstring_equal(s1, s2) (strcmp ((s1), (s2)) == 0)
136
#endif /* defined (FS_FAST) */
137
 
138
BoolT
139
cstring_ci_equal PROTO_N ((cstring1, cstring2))
140
		 PROTO_T (CStringP cstring1 X
141
			  CStringP cstring2)
142
{
143
    char c1;
144
    char c2;
145
 
146
    do {
147
	c1 = syntax_upcase (*cstring1 ++);
148
	c2 = syntax_upcase (*cstring2 ++);
149
    } while ((c1) && (c2) && (c1 == c2));
150
    return (c1 == c2);
151
}
152
 
153
BoolT
154
cstring_to_unsigned PROTO_N ((cstring, num_ref))
155
		    PROTO_T (CStringP  cstring X
156
			     unsigned *num_ref)
157
{
158
    unsigned number = 0;
159
 
160
    if (*cstring == '\0') {
161
	return (FALSE);
162
    }
163
    do {
164
	int value = syntax_value (*cstring);
165
 
166
	if ((value == SYNTAX_NO_VALUE) || (value >= 10) ||
167
	    (((UINT_MAX - (unsigned) value) / (unsigned) 10) < number)) {
168
	    return (FALSE);
169
	}
170
	number *= (unsigned) 10;
171
	number += (unsigned) value;
172
    } while (*++ cstring);
173
    *num_ref = number;
174
    return (TRUE);
175
}
176
 
177
BoolT
178
cstring_starts PROTO_N ((cstring, s))
179
	       PROTO_T (CStringP cstring X
180
			CStringP s)
181
{
182
    return (strncmp (cstring, s, strlen (s)) == 0);
183
}
184
 
185
#ifdef FS_FAST
186
#undef cstring_contains
187
#endif /* defined (FS_FAST) */
188
BoolT
189
cstring_contains PROTO_N ((cstring, c))
190
		 PROTO_T (CStringP cstring X
191
			  char     c)
192
{
193
    return (strchr (cstring, c) != NIL (CStringP));
194
}
195
#ifdef FS_FAST
196
#define cstring_contains(s, c) (strchr ((s), (c)) != NIL (CStringP))
197
#endif /* defined (FS_FAST) */
198
 
199
#ifdef FS_FAST
200
#undef cstring_find
201
#endif /* defined (FS_FAST) */
202
CStringP
203
cstring_find PROTO_N ((cstring, c))
204
	     PROTO_T (CStringP cstring X
205
		      char     c)
206
{
207
    return (strchr (cstring, c));
208
}
209
#ifdef FS_FAST
210
#define cstring_find(s, c) (strchr ((s), (c)))
211
#endif /* defined (FS_FAST) */
212
 
213
#ifdef FS_FAST
214
#undef cstring_find_reverse
215
#endif /* defined (FS_FAST) */
216
CStringP
217
cstring_find_reverse PROTO_N ((cstring, c))
218
		     PROTO_T (CStringP cstring X
219
			      char     c)
220
{
221
    return (strrchr (cstring, c));
222
}
223
#ifdef FS_FAST
224
#define cstring_find_reverse(s, c) (strrchr ((s), (c)))
225
#endif /* defined (FS_FAST) */
226
 
227
CStringP
228
cstring_find_basename PROTO_N ((cstring))
229
		      PROTO_T (CStringP cstring)
230
{
231
    CStringP bstring = cstring_find_reverse (cstring, '/');
232
    if (bstring != NIL (CStringP)) {
233
	cstring = bstring + 1;
234
    }
235
    return (cstring);
236
}