1
/* $NetBSD: str.c,v 1.17 1998/11/06 23:31:09 christos Exp $ */
1
/* $NetBSD: str.c,v 1.21 2003/09/27 21:29:37 sjg Exp $ */
4
4
* Copyright (c) 1988, 1989, 1990, 1993
5
5
* The Regents of the University of California. All rights reserved.
7
* This code is derived from software contributed to Berkeley by
10
* Redistribution and use in source and binary forms, with or without
11
* modification, are permitted provided that the following conditions
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
* 3. Neither the name of the University nor the names of its contributors
19
* may be used to endorse or promote products derived from this software
20
* without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6
36
* Copyright (c) 1989 by Berkeley Softworks
7
37
* All rights reserved.
41
71
#ifdef MAKE_BOOTSTRAP
42
static char rcsid[] = "$NetBSD: str.c,v 1.17 1998/11/06 23:31:09 christos Exp $";
72
static char rcsid[] = "$NetBSD: str.c,v 1.21 2003/09/27 21:29:37 sjg Exp $";
44
74
#include <sys/cdefs.h>
47
77
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
49
__RCSID("$NetBSD: str.c,v 1.17 1998/11/06 23:31:09 christos Exp $");
79
__RCSID("$NetBSD: str.c,v 1.21 2003/09/27 21:29:37 sjg Exp $");
51
81
#endif /* not lint */
62
92
* the resulting string in allocated space.
65
str_concat(s1, s2, flags)
95
str_concat(const char *s1, const char *s2, int flags)
69
register int len1, len2;
70
register char *result;
72
100
/* get the length of both strings */
73
101
len1 = strlen(s1);
91
119
/* copy second string plus EOS into place */
92
120
memcpy(result + len1, s2, len2 + 1);
94
/* free original strings */
95
if (flags & STR_DOFREE) {
109
* Pointer to the array of pointers to the words. To make life easier,
110
* the first word is always the value of the .MAKE variable.
132
* Pointer to the array of pointers to the words.
113
brk_string(str, store_argc, expand, buffer)
135
brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
119
register int argc, ch;
120
register char inquote, *p, *start, *t;
138
char inquote, *start, *t;
122
141
int argmax = 50, curlen = 0;
123
142
char **argv = (char **)emalloc((argmax + 1) * sizeof(char *));
234
253
* Str_FindSubstring -- See if a string contains a particular substring.
256
* string String to search.
257
* substring Substring to find in string.
236
259
* Results: If string contains substring, the return value is the location of
237
260
* the first matching instance of substring in string. If string doesn't
238
261
* contain substring, the return value is NULL. Matching is done on an exact
241
264
* Side effects: None.
244
Str_FindSubstring(string, substring)
245
register char *string; /* String to search. */
246
char *substring; /* Substring to find in string */
267
Str_FindSubstring(const char *string, const char *substring)
248
register char *a, *b;
251
272
* First scan quickly through the two strings looking for a single-
280
301
* Side effects: None.
283
Str_Match(string, pattern)
284
register char *string; /* String */
285
register char *pattern; /* Pattern */
304
Str_Match(const char *string, const char *pattern)
375
394
* Str_SYSVMatch --
376
395
* Check word against pattern for a match (% is wild),
398
* word Word to examine
399
* pattern Pattern to examine against
400
* len Number of characters to substitute
379
403
* Returns the beginning position of a match or null. The number
380
404
* of characters matched is returned in len.
385
409
*-----------------------------------------------------------------------
388
Str_SYSVMatch(word, pattern, len)
389
char *word; /* Word to examine */
390
char *pattern; /* Pattern to examine against */
391
int *len; /* Number of characters to substitute */
412
Str_SYSVMatch(const char *word, const char *pattern, int *len)
414
const char *p = pattern;
415
const char *w = word;
397
418
if (*p == '\0') {
398
419
/* Null pattern is the whole string */
399
420
*len = strlen(w);
403
424
if ((m = strchr(p, '%')) != NULL) {
445
466
*-----------------------------------------------------------------------
448
Str_SYSVSubst(buf, pat, src, len)
469
Str_SYSVSubst(Buffer buf, char *pat, char *src, int len)