Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
6 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
6 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
6 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/**** cstring.h --- C string manipulation.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 **** Commentary:
66
 *
67
 ***=== INTRODUCTION =========================================================
68
 *
69
 * This file defines the C string type and specifies some functions that can
70
 * be used to manipulate C strings.
71
 *
72
 ***=== TYPES ================================================================
73
 *
74
 ** Type:	CStringP
75
 ** Repr:	char *
76
 *
77
 * This is the C string type.  It should be used for objects that are
78
 * strings, not for references to character objects.  It is actually defined
79
 * in the file "os-interface.h" to avoid a circularity in the header files
80
 * in this directory, but all files outside of this directory should get the
81
 * type definition by including this file.
82
 *
83
 ***=== FUNCTIONS ============================================================
84
 *
85
 ** Function:	CStringP		cstring_duplicate
6 7u83 86
 *			(CStringP cstring)
2 7u83 87
 ** Exceptions:	XX_dalloc_no_memory
88
 *
89
 * This function returns a dynamically allocated copy of the specified
90
 * cstring.
91
 *
92
 ** Function:	CStringP		cstring_duplicate_prefix
6 7u83 93
 *			(CStringP cstring, unsigned prefix)
2 7u83 94
 ** Exceptions:	XX_dalloc_no_memory
95
 *
96
 * This function returns a dynamically allocated copy of the specified prefix
97
 * of the specified cstring.  If the cstring is shorter than the prefix
98
 * length, then only the cstring is used.
99
 *
100
 ** Function:	unsigned		cstring_hash_value
6 7u83 101
 *			(CStringP cstring)
2 7u83 102
 ** Exceptions:
103
 *
104
 * This function returns the hash value associated with the specified
105
 * cstring.  This value is guaranteed to be identical for all cstrings
106
 * with the same content.
107
 *
108
 ** Function:	unsigned		cstring_length
6 7u83 109
 *			(CStringP cstring)
2 7u83 110
 ** Exceptions:
111
 *
112
 * This function returns the length of the specified cstring.
113
 *
114
 ** Function:	BoolT			cstring_equal
6 7u83 115
 *			(CStringP cstring1, CStringP cstring2)
2 7u83 116
 ** Exceptions:
117
 *
118
 * This function returns true if the specified cstrings have the same
119
 * content, and false otherwise.
120
 *
121
 ** Function:	BoolT			cstring_ci_equal
6 7u83 122
 *			(CStringP cstring1, CStringP cstring2)
2 7u83 123
 ** Exceptions:
124
 *
125
 * This function returns true if the specified cstrings have the same
126
 * content (ignoring differences in case), and false otherwise.
127
 *
128
 ** Function:	BoolT			cstring_to_unsigned
6 7u83 129
 *			(CStringP cstring, unsigned *num_ref)
2 7u83 130
 ** Exceptions:
131
 *
132
 * This function parses an unsigned number in cstring.  If there is a valid
133
 * number in the string, it is assigned to the number pointed to by num_ref,
134
 * and the function returns true; otherwise the function returns false.  The
135
 * function checks for overflow; it will return false if the number is too
136
 * big.
137
 *
138
 ** Function:	BoolT			cstring_contains
6 7u83 139
 *			(CStringP cstring, char c)
2 7u83 140
 ** Exceptions:
141
 *
142
 * This function returns true if the specified cstring contains the character
143
 * c, and false if it doesn't.
144
 *
145
 ** Function:	CStringP		cstring_find
6 7u83 146
 *			(CStringP cstring, char c)
2 7u83 147
 ** Exceptions:
148
 *
149
 * This function returns a pointer to the first occurrence of the specified
150
 * character in the specified cstring, or nil if there is no occurrence.
151
 *
152
 ** Function:	CStringP		cstring_find_reverse
6 7u83 153
 *			(CStringP cstring, char c)
2 7u83 154
 ** Exceptions:
155
 *
156
 * This function returns a pointer to the last occurrence of the specified
157
 * character in the specified cstring, or nil if there is no occurrence.
158
 *
159
 **** Change Log:
160
 * $Log: cstring.h,v $
161
 * Revision 1.2  1998/03/16  11:26:34  release
162
 * Modifications prior to version 4.1.2.
163
 *
164
 * Revision 1.1.1.1  1998/01/17  15:57:45  release
165
 * First version to be checked into rolling release.
166
 *
167
 * Revision 1.2  1994/12/12  11:45:26  smf
168
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
169
 * OSSG C Coding Standards.
170
 *
171
 * Revision 1.1.1.1  1994/07/25  16:06:09  smf
172
 * Initial import of os-interface shared files.
173
 *
174
**/
175
 
176
/****************************************************************************/
177
 
178
#ifndef H_CSTRING
179
#define H_CSTRING
180
 
181
#include "os-interface.h"
182
#include "dalloc.h"
183
 
184
/*--------------------------------------------------------------------------*/
185
 
6 7u83 186
extern CStringP			cstring_duplicate(CStringP);
187
extern CStringP			cstring_duplicate_prefix(CStringP, unsigned);
188
extern unsigned			cstring_hash_value(CStringP);
189
extern unsigned			cstring_length(CStringP);
190
extern BoolT			cstring_equal(CStringP, CStringP);
191
extern BoolT			cstring_ci_equal(CStringP, CStringP);
192
extern BoolT			cstring_to_unsigned(CStringP, unsigned *);
193
extern BoolT			cstring_starts(CStringP, CStringP);
194
extern BoolT			cstring_contains(CStringP, char);
195
extern CStringP			cstring_find(CStringP, char);
196
extern CStringP			cstring_find_reverse(CStringP, char);
197
extern CStringP			cstring_find_basename(CStringP);
2 7u83 198
 
199
/*--------------------------------------------------------------------------*/
200
 
201
#ifdef FS_FAST
6 7u83 202
#define cstring_length(s)		((unsigned)strlen(s))
203
#define cstring_equal(s1, s2)		(strcmp((s1), (s2)) == 0)
204
#define cstring_contains(s, c)		(strchr((s), (c)) != NIL(CStringP))
205
#define cstring_find(s, c)		(strchr((s), (c)))
206
#define cstring_find_reverse(s, c)	(strrchr((s), (c)))
2 7u83 207
#endif /* defined (FS_FAST) */
208
 
209
#endif /* !defined (H_CSTRING) */