summaryrefslogtreecommitdiff
path: root/usr.bin/make/str.c
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2001-05-23 12:34:58 +0000
committerMarc Espie <espie@cvs.openbsd.org>2001-05-23 12:34:58 +0000
commitdb8e89b77998123612f763908cdd1c46cc7ea24f (patch)
treeaf42f9f2b44b6bae3a6ca23660ff612c49709e27 /usr.bin/make/str.c
parentd0640eab6718b3ff0eeb66e78aa4d5d8a8ed3c24 (diff)
Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules. Put the interface documentation there, and not with the implementation. - light-weight includes for needed concrete types (lst_t.h, timestamp_t.h). - cut out some more logically separate parts: cmd_exec, varname, parsevar, timestamp. - put all error handling functions together, so that we will be able to clean them up. - more systematic naming: functioni to handle interval, function to handle string. - put the init/end code apart to minimize coupling. - kill weird types like ReturnStatus and Boolean. Use standard bool (with a fallback for non-iso systems) - better interface documentation for lots of subsystems. As a result, make compilation goes somewhat faster (5%, even considering the largish BSD copyrights to read). The corresponding preprocessed source goes down from 1,5M to 1M. A few minor code changes as well: Parse_DoVar is no longer destructive. Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an assignment is), a few more interval handling functions. Avoid calling XXX_End when they do nothing, just #define XXX_End to nothing. Parse_DoVar is slightly more general: it will handle compound assignments as long as they make sense, e.g., VAR +!= cmd will work. As a side effect, VAR++=value now triggers an error (two + in assignment). - this stuff doesn't occur in portable Makefiles. - writing VAR++ = value or VAR+ +=value disambiguates it. - this is a good thing, it uncovered a bug in bsd.port.mk. Tested by naddy@. Okayed millert@. I'll handle the fallback if there is any. This went through a full make build anyways, including isakmpd (without mickey's custom binutils, as he didn't see fit to share it with me).
Diffstat (limited to 'usr.bin/make/str.c')
-rw-r--r--usr.bin/make/str.c115
1 files changed, 44 insertions, 71 deletions
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c
index bd01d0c4466..c1f2abec2e0 100644
--- a/usr.bin/make/str.c
+++ b/usr.bin/make/str.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: str.c,v 1.18 2001/05/07 22:54:53 espie Exp $ */
+/* $OpenBSD: str.c,v 1.19 2001/05/23 12:34:49 espie Exp $ */
/* $NetBSD: str.c,v 1.13 1996/11/06 17:59:23 christos Exp $ */
/*-
@@ -40,34 +40,24 @@
* SUCH DAMAGE.
*/
-#include "make.h"
+#include <ctype.h>
+#include <string.h>
+#include "config.h"
+#include "defines.h"
+#include "str.h"
+#include "memory.h"
+#include "buf.h"
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
-#else
-UNUSED
-static char rcsid[] = "$OpenBSD: str.c,v 1.18 2001/05/07 22:54:53 espie Exp $";
-#endif
-#endif /* not lint */
-
-/*-
- * str_concati --
- * concatenate the two strings, possibly inserting a separator
- *
- * returns --
- * the resulting string in allocated space.
- */
char *
-str_concati(s1, s2, e2, sep)
- const char *s1, *s2, *e2;
+Str_concati(s1, e1, s2, e2, sep)
+ const char *s1, *e1, *s2, *e2;
int sep;
{
size_t len1, len2;
char *result;
/* get the length of both strings */
- len1 = strlen(s1);
+ len1 = e1 - s1;
len2 = e2 - s2;
/* space for separator */
@@ -208,15 +198,7 @@ done:
return argv;
}
-/* Iterate through a string word by word,
- * without needing to copy anything.
- * More light-weight than brk_string, handles \ ' " as well.
- *
- * position = s;
- * while ((begin = iterate_words(&position)) != NULL) {
- * do_something_with_word_interval(begin, position);
- * }
- */
+
const char *
iterate_words(end)
const char **end;
@@ -256,18 +238,10 @@ iterate_words(end)
}
}
-/*
- * Str_Matchi --
- *
- * See if a particular string matches a particular pattern.
- *
- * Results: TRUE is returned if string matches pattern, FALSE otherwise. The
- * matching operation permits the following special characters in the
- * pattern: *?\[] (see the man page for details on what these mean).
- */
-Boolean
-Str_Matchi(string, pattern, end)
+bool
+Str_Matchi(string, estring, pattern, end)
const char *string; /* String */
+ const char *estring; /* End of string */
const char *pattern; /* Pattern */
const char *end; /* End of Pattern */
{
@@ -282,52 +256,52 @@ Str_Matchi(string, pattern, end)
* calls only occur on `real' characters. */
while (pattern != end && (*pattern == '?' || *pattern == '*')) {
if (*pattern == '?') {
- if (*string == '\0')
- return FALSE;
+ if (string == estring)
+ return false;
else
string++;
}
pattern++;
}
if (pattern == end)
- return TRUE;
- for (; *string != '\0'; string++)
- if (Str_Matchi(string, pattern, end))
- return TRUE;
- return FALSE;
- } else if (*string == '\0')
- return FALSE;
+ return true;
+ for (; string != estring; string++)
+ if (Str_Matchi(string, estring, pattern, end))
+ return true;
+ return false;
+ } else if (string == estring)
+ return false;
/* Check for a "[" as the next pattern character. It is
* followed by a list of characters that are acceptable, or
* by a range (two characters separated by "-"). */
else if (*pattern == '[') {
pattern++;
if (pattern == end)
- return FALSE;
+ return false;
if (*pattern == '!' || *pattern == '^') {
pattern++;
if (pattern == end)
- return FALSE;
+ return false;
/* Negative match */
for (;;) {
if (*pattern == '\\') {
if (++pattern == end)
- return FALSE;
+ return false;
}
if (*pattern == *string)
- return FALSE;
+ return false;
if (pattern[1] == '-') {
if (pattern + 2 == end)
- return FALSE;
+ return false;
if (*pattern < *string && *string <= pattern[2])
- return FALSE;
+ return false;
if (pattern[2] <= *string && *string < *pattern)
- return FALSE;
+ return false;
pattern += 3;
} else
pattern++;
if (pattern == end)
- return FALSE;
+ return false;
/* The test for ']' is done at the end so that ']'
* can be used at the start of the range without '\' */
if (*pattern == ']')
@@ -337,13 +311,13 @@ Str_Matchi(string, pattern, end)
for (;;) {
if (*pattern == '\\') {
if (++pattern == end)
- return FALSE;
+ return false;
}
if (*pattern == *string)
break;
if (pattern[1] == '-') {
if (pattern + 2 == end)
- return FALSE;
+ return false;
if (*pattern < *string && *string <= pattern[2])
break;
if (pattern[2] <= *string && *string < *pattern)
@@ -354,7 +328,7 @@ Str_Matchi(string, pattern, end)
/* The test for ']' is done at the end so that ']'
* can be used at the start of the range without '\' */
if (pattern == end || *pattern == ']')
- return FALSE;
+ return false;
}
/* Found matching character, skip over rest of class. */
while (*pattern != ']') {
@@ -373,20 +347,20 @@ Str_Matchi(string, pattern, end)
* '\' so we do exact matching on the character that follows. */
if (*pattern == '\\') {
if (++pattern == end)
- return FALSE;
+ return false;
}
/* There's no special character. Just make sure that
* the next characters of each string match. */
if (*pattern != *string)
- return FALSE;
+ return false;
}
pattern++;
string++;
}
- if (*string == '\0')
- return TRUE;
+ if (string == estring)
+ return true;
else
- return FALSE;
+ return false;
}
@@ -468,7 +442,7 @@ Str_SYSVSubst(buf, pat, src, len)
if ((m = strchr(pat, '%')) != NULL) {
/* Copy the prefix. */
- Buf_AddInterval(buf, pat, m);
+ Buf_Addi(buf, pat, m);
/* Skip the %. */
pat = m + 1;
}
@@ -481,7 +455,7 @@ Str_SYSVSubst(buf, pat, src, len)
}
char *
-interval_dup(begin, end)
+Str_dupi(begin, end)
const char *begin;
const char *end;
{
@@ -493,9 +467,8 @@ interval_dup(begin, end)
return s;
}
-/* copy interval, skipping characters in the set. */
char *
-escape_dup(begin, end, set)
+escape_dupi(begin, end, set)
const char *begin;
const char *end;
const char *set;
@@ -520,7 +493,7 @@ escape_dup(begin, end, set)
}
char *
-lastchar(s, e, c)
+Str_rchri(s, e, c)
const char *s;
const char *e;
int c;