Deleted Added
full compact
str.c (105826) str.c (106106)
1/*-
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)str.c 5.8 (Berkeley) 6/1/90
39 */
40
41#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)str.c 5.8 (Berkeley) 6/1/90
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/usr.bin/make/str.c 105826 2002-10-23 23:16:43Z jmallett $");
42__FBSDID("$FreeBSD: head/usr.bin/make/str.c 106106 2002-10-28 23:33:57Z jmallett $");
43
44#include "make.h"
45
46static char **argv, *buffer;
47static int argmax, curlen;
48
49/*
50 * str_init --

--- 197 unchanged lines hidden (view full) ---

248 *t++ = (char) ch;
249 }
250done: argv[argc] = (char *)NULL;
251 *store_argc = argc;
252 return(argv);
253}
254
255/*
43
44#include "make.h"
45
46static char **argv, *buffer;
47static int argmax, curlen;
48
49/*
50 * str_init --

--- 197 unchanged lines hidden (view full) ---

248 *t++ = (char) ch;
249 }
250done: argv[argc] = (char *)NULL;
251 *store_argc = argc;
252 return(argv);
253}
254
255/*
256 * Str_FindSubstring -- See if a string contains a particular substring.
257 *
258 * Results: If string contains substring, the return value is the location of
259 * the first matching instance of substring in string. If string doesn't
260 * contain substring, the return value is NULL. Matching is done on an exact
261 * character-for-character basis with no wildcards or special characters.
262 *
263 * Side effects: None.
264 *
265 * XXX should be strstr(3).
266 */
267char *
268Str_FindSubstring(char *string, char *substring)
269{
270 char *a, *b;
271
272 /*
273 * First scan quickly through the two strings looking for a single-
274 * character match. When it's found, then compare the rest of the
275 * substring.
276 */
277
278 for (b = substring; *string != 0; string += 1) {
279 if (*string != *b)
280 continue;
281 a = string;
282 for (;;) {
283 if (*b == 0)
284 return(string);
285 if (*a++ != *b++)
286 break;
287 }
288 b = substring;
289 }
290 return((char *) NULL);
291}
292
293/*
294 * Str_Match --
295 *
296 * See if a particular string matches a particular pattern.
297 *
298 * Results: Non-zero is returned if string matches pattern, 0 otherwise. The
299 * matching operation permits the following special characters in the
300 * pattern: *?\[] (see the man page for details on what these mean).
301 *
302 * Side effects: None.
303 */
304int
256 * Str_Match --
257 *
258 * See if a particular string matches a particular pattern.
259 *
260 * Results: Non-zero is returned if string matches pattern, 0 otherwise. The
261 * matching operation permits the following special characters in the
262 * pattern: *?\[] (see the man page for details on what these mean).
263 *
264 * Side effects: None.
265 */
266int
305Str_Match(char *string, char *pattern)
267Str_Match(const char *string, const char *pattern)
306{
307 char c2;
308
309 for (;;) {
310 /*
311 * See if we're at the end of both the pattern and the
312 * string. If, we succeeded. If we're at the end of the
313 * pattern but not at the end of the string, we failed.

--- 85 unchanged lines hidden (view full) ---

399 * Returns the beginning position of a match or null. The number
400 * of characters matched is returned in len.
401 *
402 * Side Effects:
403 * None
404 *
405 *-----------------------------------------------------------------------
406 */
268{
269 char c2;
270
271 for (;;) {
272 /*
273 * See if we're at the end of both the pattern and the
274 * string. If, we succeeded. If we're at the end of the
275 * pattern but not at the end of the string, we failed.

--- 85 unchanged lines hidden (view full) ---

361 * Returns the beginning position of a match or null. The number
362 * of characters matched is returned in len.
363 *
364 * Side Effects:
365 * None
366 *
367 *-----------------------------------------------------------------------
368 */
407char *
408Str_SYSVMatch(char *word, char *pattern, int *len)
369const char *
370Str_SYSVMatch(const char *word, const char *pattern, int *len)
409{
371{
410 char *p = pattern;
411 char *w = word;
412 char *m;
372 const char *m, *p, *w;
413
373
374 p = pattern;
375 w = word;
376
414 if (*w == '\0') {
415 /* Zero-length word cannot be matched against */
416 *len = 0;
417 return NULL;
418 }
419
420 if (*p == '\0') {
421 /* Null pattern is the whole string */

--- 41 unchanged lines hidden (view full) ---

463 * None
464 *
465 * Side Effects:
466 * Places result on buf
467 *
468 *-----------------------------------------------------------------------
469 */
470void
377 if (*w == '\0') {
378 /* Zero-length word cannot be matched against */
379 *len = 0;
380 return NULL;
381 }
382
383 if (*p == '\0') {
384 /* Null pattern is the whole string */

--- 41 unchanged lines hidden (view full) ---

426 * None
427 *
428 * Side Effects:
429 * Places result on buf
430 *
431 *-----------------------------------------------------------------------
432 */
433void
471Str_SYSVSubst(Buffer buf, char *pat, char *src, int len)
434Str_SYSVSubst(Buffer buf, const char *pat, const char *src, int len)
472{
435{
473 char *m;
436 const char *m;
474
475 if ((m = strchr(pat, '%')) != NULL) {
476 /* Copy the prefix */
477 Buf_AddBytes(buf, m - pat, (Byte *) pat);
478 /* skip the % */
479 pat = m + 1;
480 }
481
482 /* Copy the pattern */
483 Buf_AddBytes(buf, len, (Byte *) src);
484
485 /* append the rest */
486 Buf_AddBytes(buf, strlen(pat), (Byte *) pat);
487}
437
438 if ((m = strchr(pat, '%')) != NULL) {
439 /* Copy the prefix */
440 Buf_AddBytes(buf, m - pat, (Byte *) pat);
441 /* skip the % */
442 pat = m + 1;
443 }
444
445 /* Copy the pattern */
446 Buf_AddBytes(buf, len, (Byte *) src);
447
448 /* append the rest */
449 Buf_AddBytes(buf, strlen(pat), (Byte *) pat);
450}