~ubuntu-branches/ubuntu/karmic/pmake/karmic

« back to all changes in this revision

Viewing changes to str.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar (Debian packages)
  • Date: 2004-03-12 13:14:27 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040312131427-us94ehmatt3kxhm8
Tags: 1.98-3
* mk/bsd.man.mk:
  + Use symlinks instead of hard links when using the MLINKS directive
    to link manual pages, courtesy of Robert Millan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $     */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1988, 1989, 1990, 1993
5
5
 *      The Regents of the University of California.  All rights reserved.
 
6
 *
 
7
 * This code is derived from software contributed to Berkeley by
 
8
 * Adam de Boor.
 
9
 *
 
10
 * Redistribution and use in source and binary forms, with or without
 
11
 * modification, are permitted provided that the following conditions
 
12
 * are met:
 
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.
 
21
 *
 
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
 
32
 * SUCH DAMAGE.
 
33
 */
 
34
 
 
35
/*-
6
36
 * Copyright (c) 1989 by Berkeley Softworks
7
37
 * All rights reserved.
8
38
 *
39
69
 */
40
70
 
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 $";
43
73
#else
44
74
#include <sys/cdefs.h>
45
75
#ifndef lint
46
76
#if 0
47
77
static char     sccsid[] = "@(#)str.c   5.8 (Berkeley) 6/1/90";
48
78
#else
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 $");
50
80
#endif
51
81
#endif                          /* not lint */
52
82
#endif
62
92
 *      the resulting string in allocated space.
63
93
 */
64
94
char *
65
 
str_concat(s1, s2, flags)
66
 
        char *s1, *s2;
67
 
        int flags;
 
95
str_concat(const char *s1, const char *s2, int flags)
68
96
{
69
 
        register int len1, len2;
70
 
        register char *result;
 
97
        int len1, len2;
 
98
        char *result;
71
99
 
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);
93
121
 
94
 
        /* free original strings */
95
 
        if (flags & STR_DOFREE) {
96
 
                (void)free(s1);
97
 
                (void)free(s2);
98
 
        }
99
122
        return(result);
100
123
}
101
124
 
106
129
 *      are ignored.
107
130
 *
108
131
 * returns --
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.
111
133
 */
112
134
char **
113
 
brk_string(str, store_argc, expand, buffer)
114
 
        register char *str;
115
 
        int *store_argc;
116
 
        Boolean expand;
117
 
        char **buffer;
 
135
brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
118
136
{
119
 
        register int argc, ch;
120
 
        register char inquote, *p, *start, *t;
 
137
        int argc, ch;
 
138
        char inquote, *start, *t;
 
139
        const char *p;
121
140
        int len;
122
141
        int argmax = 50, curlen = 0;
123
142
        char **argv = (char **)emalloc((argmax + 1) * sizeof(char *));
233
252
/*
234
253
 * Str_FindSubstring -- See if a string contains a particular substring.
235
254
 *
 
255
 * Input:
 
256
 *      string          String to search.
 
257
 *      substring       Substring to find in string.
 
258
 *
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.
242
265
 */
243
266
char *
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)
247
268
{
248
 
        register char *a, *b;
 
269
        const char *a, *b;
249
270
 
250
271
        /*
251
272
         * First scan quickly through the two strings looking for a single-
259
280
                a = string;
260
281
                for (;;) {
261
282
                        if (*b == 0)
262
 
                                return(string);
 
283
                                return UNCONST(string);
263
284
                        if (*a++ != *b++)
264
285
                                break;
265
286
                }
266
287
                b = substring;
267
288
        }
268
 
        return((char *) NULL);
 
289
        return NULL;
269
290
}
270
291
 
271
292
/*
280
301
 * Side effects: None.
281
302
 */
282
303
int
283
 
Str_Match(string, pattern)
284
 
        register char *string;          /* String */
285
 
        register char *pattern;         /* Pattern */
 
304
Str_Match(const char *string, const char *pattern)
286
305
{
287
306
        char c2;
288
307
 
375
394
 * Str_SYSVMatch --
376
395
 *      Check word against pattern for a match (% is wild),
377
396
 *
 
397
 * Input:
 
398
 *      word            Word to examine
 
399
 *      pattern         Pattern to examine against
 
400
 *      len             Number of characters to substitute
 
401
 *
378
402
 * Results:
379
403
 *      Returns the beginning position of a match or null. The number
380
404
 *      of characters matched is returned in len.
385
409
 *-----------------------------------------------------------------------
386
410
 */
387
411
char *
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)
392
413
{
393
 
    char *p = pattern;
394
 
    char *w = word;
395
 
    char *m;
 
414
    const char *p = pattern;
 
415
    const char *w = word;
 
416
    const char *m;
396
417
 
397
418
    if (*p == '\0') {
398
419
        /* Null pattern is the whole string */
399
420
        *len = strlen(w);
400
 
        return w;
 
421
        return UNCONST(w);
401
422
    }
402
423
 
403
424
    if ((m = strchr(p, '%')) != NULL) {
411
432
        if (*++p == '\0') {
412
433
            /* No more pattern, return the rest of the string */
413
434
            *len = strlen(w);
414
 
            return w;
 
435
            return UNCONST(w);
415
436
        }
416
437
    }
417
438
 
421
442
    do
422
443
        if (strcmp(p, w) == 0) {
423
444
            *len = w - m;
424
 
            return m;
 
445
            return UNCONST(m);
425
446
        }
426
447
    while (*w++ != '\0');
427
448
 
445
466
 *-----------------------------------------------------------------------
446
467
 */
447
468
void
448
 
Str_SYSVSubst(buf, pat, src, len)
449
 
    Buffer buf;
450
 
    char *pat;
451
 
    char *src;
452
 
    int   len;
 
469
Str_SYSVSubst(Buffer buf, char *pat, char *src, int len)
453
470
{
454
471
    char *m;
455
472