xref: /openbsd/usr.bin/make/str.h (revision 73471bf0)
1 #ifndef STR_H
2 #define STR_H
3 /* $OpenBSD: str.h,v 1.2 2010/07/19 19:46:44 espie Exp $ */
4 /*
5  * Copyright (c) 2001 Marc Espie.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
20  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* pos = Str_rchri(str, end, c);
30  *	strrchr on intervals.  */
31 extern char *Str_rchri(const char *, const char *, int);
32 
33 /* copy = Str_concati(s1, e1, s2, e2, sep);
34  *	Concatenate strings s1/e1 and s2/e2, wedging separator sep if != 0.  */
35 extern char *Str_concati(const char *, const char *, const char *, const char *, int);
36 #define Str_concat(s1, s2, sep) Str_concati(s1, strchr(s1, '\0'), s2, strchr(s2, '\0'), sep)
37 
38 /* copy = Str_dupi(str, end);
39  *	strdup on intervals.  */
40 extern char *Str_dupi(const char *, const char *);
41 
42 /* copy = escape_dupi(str, end, set);
43  *	copy string str/end. All escape sequences such as \c with c in set
44  *	are handled as well.  */
45 extern char *escape_dupi(const char *, const char *, const char *);
46 
47 
48 extern char **brk_string(const char *, int *, char **);
49 
50 
51 /* Iterate through a string word by word,
52  * without copying anything.
53  * More light-weight than brk_string, handles \ ' " as well.
54  *
55  * position = s;
56  * while ((begin = iterate_words(&position)) != NULL) {
57  *   do_something_with_word_interval(begin, position);
58  * }
59  */
60 extern const char *iterate_words(const char **);
61 
62 /* match = Str_Matchi(str, estr, pat, end);
63  *	Checks if string str/estr matches pattern pat/end */
64 extern bool Str_Matchi(const char *, const char *, const char *, const char *);
65 #define Str_Match(string, pattern) \
66 	Str_Matchi(string, strchr(string, '\0'), pattern, strchr(pattern, '\0'))
67 
68 extern const char *Str_SYSVMatch(const char *, const char *, size_t *);
69 extern void Str_SYSVSubst(Buffer, const char *, const char *, size_t);
70 #endif
71