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-2006 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
 *
6 7u83 85
 ** Function:	CStringP cstring_duplicate(CStringP cstring)
2 7u83 86
 ** Exceptions:	XX_dalloc_no_memory
87
 *
88
 * This function returns a dynamically allocated copy of the specified
89
 * cstring.
90
 *
6 7u83 91
 ** Function:	CStringP cstring_duplicate_prefix(CStringP cstring,
92
 *						  unsigned prefix)
2 7u83 93
 ** Exceptions:	XX_dalloc_no_memory
94
 *
95
 * This function returns a dynamically allocated copy of the specified prefix
96
 * of the specified cstring.  If the cstring is shorter than the prefix
97
 * length, then only the cstring is used.
98
 *
6 7u83 99
 ** Function:	unsigned cstring_hash_value(CStringP cstring)
2 7u83 100
 ** Exceptions:
101
 *
102
 * This function returns the hash value associated with the specified
103
 * cstring.  This value is guaranteed to be identical for all cstrings
104
 * with the same content.
105
 *
6 7u83 106
 ** Function:	unsigned cstring_length(CStringP cstring)
2 7u83 107
 ** Exceptions:
108
 *
109
 * This function returns the length of the specified cstring.
110
 *
6 7u83 111
 ** Function:	BoolT cstring_equal(CStringP cstring1, CStringP cstring2)
2 7u83 112
 ** Exceptions:
113
 *
114
 * This function returns true if the specified cstrings have the same
115
 * content, and false otherwise.
116
 *
6 7u83 117
 ** Function:	BoolT cstring_ci_equal(CStringP cstring1, CStringP cstring2)
2 7u83 118
 ** Exceptions:
119
 *
120
 * This function returns true if the specified cstrings have the same
121
 * content (ignoring differences in case), and false otherwise.
122
 *
6 7u83 123
 ** Function:	BoolT cstring_to_unsigned(CStringP cstring, unsigned *num_ref)
2 7u83 124
 ** Exceptions:
125
 *
126
 * This function parses an unsigned number in cstring.  If there is a valid
127
 * number in the string, it is assigned to the number pointed to by num_ref,
128
 * and the function returns true; otherwise the function returns false.  The
129
 * function checks for overflow; it will return false if the number is too
130
 * big.
131
 *
6 7u83 132
 ** Function:	BoolT cstring_contains(CStringP cstring, char c)
2 7u83 133
 ** Exceptions:
134
 *
135
 * This function returns true if the specified cstring contains the character
136
 * c, and false if it doesn't.
137
 *
6 7u83 138
 ** Function:	CStringP cstring_find(CStringP cstring, char c)
2 7u83 139
 ** Exceptions:
140
 *
141
 * This function returns a pointer to the first occurrence of the specified
142
 * character in the specified cstring, or nil if there is no occurrence.
143
 *
6 7u83 144
 ** Function:	CStringP cstring_find_reverse(CStringP cstring, char c)
2 7u83 145
 ** Exceptions:
146
 *
147
 * This function returns a pointer to the last occurrence of the specified
148
 * character in the specified cstring, or nil if there is no occurrence.
149
 *
150
 **** Change Log:
151
 * $Log: cstring.h,v $
152
 * Revision 1.1.1.1  1998/01/17  15:57:17  release
153
 * First version to be checked into rolling release.
154
 *
155
 * Revision 1.2  1994/12/12  11:45:26  smf
156
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
157
 * OSSG C Coding Standards.
158
 *
159
 * Revision 1.1.1.1  1994/07/25  16:06:09  smf
160
 * Initial import of os-interface shared files.
161
 *
162
**/
163
 
164
/****************************************************************************/
165
 
166
#ifndef H_CSTRING
167
#define H_CSTRING
168
 
169
#include "os-interface.h"
170
#include "dalloc.h"
171
 
172
/*--------------------------------------------------------------------------*/
173
 
174
extern CStringP			cstring_duplicate
6 7u83 175
(CStringP);
2 7u83 176
extern CStringP			cstring_duplicate_prefix
6 7u83 177
(CStringP, unsigned);
2 7u83 178
extern unsigned			cstring_hash_value
6 7u83 179
(CStringP);
2 7u83 180
extern unsigned			cstring_length
6 7u83 181
(CStringP);
2 7u83 182
extern BoolT			cstring_equal
6 7u83 183
(CStringP, CStringP);
2 7u83 184
extern BoolT			cstring_ci_equal
6 7u83 185
(CStringP, CStringP);
2 7u83 186
extern BoolT			cstring_to_unsigned
6 7u83 187
(CStringP, unsigned *);
2 7u83 188
extern BoolT			cstring_contains
6 7u83 189
(CStringP, char);
2 7u83 190
extern CStringP			cstring_find
6 7u83 191
(CStringP, char);
2 7u83 192
extern CStringP			cstring_find_reverse
6 7u83 193
(CStringP, char);
2 7u83 194
 
195
/*--------------------------------------------------------------------------*/
196
 
197
#ifdef FS_FAST
6 7u83 198
#define cstring_length(s)		((unsigned)strlen(s))
199
#define cstring_equal(s1, s2)		(strcmp((s1), (s2)) == 0)
200
#define cstring_contains(s, c)		(strchr((s), (c)) != NIL(CStringP))
201
#define cstring_find(s, c)		(strchr((s), (c)))
202
#define cstring_find_reverse(s, c)	(strrchr((s), (c)))
2 7u83 203
#endif /* defined (FS_FAST) */
204
 
205
#endif /* !defined (H_CSTRING) */