version 1.20, 2003/06/03 02:56:12 |
version 1.21, 2004/04/07 13:11:36 |
|
|
#include "buf.h" |
#include "buf.h" |
|
|
char * |
char * |
Str_concati(s1, e1, s2, e2, sep) |
Str_concati(const char *s1, const char *e1, const char *s2, const char *e2, |
const char *s1, *e1, *s2, *e2; |
int sep) |
int sep; |
|
{ |
{ |
size_t len1, len2; |
size_t len1, len2; |
char *result; |
char *result; |
|
|
* the first word is always the value of the .MAKE variable. |
* the first word is always the value of the .MAKE variable. |
*/ |
*/ |
char ** |
char ** |
brk_string(str, store_argc, buffer) |
brk_string(const char *str, int *store_argc, char **buffer) |
const char *str; |
|
int *store_argc; |
|
char **buffer; |
|
{ |
{ |
int argc; |
int argc; |
char ch; |
char ch; |
|
|
|
|
|
|
const char * |
const char * |
iterate_words(end) |
iterate_words(const char **end) |
const char **end; |
|
{ |
{ |
const char *start, *p; |
const char *start, *p; |
char state = 0; |
char state = 0; |
|
|
} |
} |
|
|
bool |
bool |
Str_Matchi(string, estring, pattern, end) |
Str_Matchi(const char *string, const char *estring, |
const char *string; /* String */ |
const char *pattern, const char *epattern) |
const char *estring; /* End of string */ |
|
const char *pattern; /* Pattern */ |
|
const char *end; /* End of Pattern */ |
|
{ |
{ |
while (pattern != end) { |
while (pattern != epattern) { |
/* Check for a "*" as the next pattern character. It matches |
/* Check for a "*" as the next pattern character. It matches |
* any substring. We handle this by calling ourselves |
* any substring. We handle this by calling ourselves |
* recursively for each postfix of string, until either we |
* recursively for each postfix of string, until either we |
|
|
pattern++; |
pattern++; |
/* Skip over contiguous sequences of `?*', so that recursive |
/* Skip over contiguous sequences of `?*', so that recursive |
* calls only occur on `real' characters. */ |
* calls only occur on `real' characters. */ |
while (pattern != end && (*pattern == '?' || *pattern == '*')) { |
while (pattern != epattern && |
|
(*pattern == '?' || *pattern == '*')) { |
if (*pattern == '?') { |
if (*pattern == '?') { |
if (string == estring) |
if (string == estring) |
return false; |
return false; |
|
|
} |
} |
pattern++; |
pattern++; |
} |
} |
if (pattern == end) |
if (pattern == epattern) |
return true; |
return true; |
for (; string != estring; string++) |
for (; string != estring; string++) |
if (Str_Matchi(string, estring, pattern, end)) |
if (Str_Matchi(string, estring, pattern, epattern)) |
return true; |
return true; |
return false; |
return false; |
} else if (string == estring) |
} else if (string == estring) |
|
|
* by a range (two characters separated by "-"). */ |
* by a range (two characters separated by "-"). */ |
else if (*pattern == '[') { |
else if (*pattern == '[') { |
pattern++; |
pattern++; |
if (pattern == end) |
if (pattern == epattern) |
return false; |
return false; |
if (*pattern == '!' || *pattern == '^') { |
if (*pattern == '!' || *pattern == '^') { |
pattern++; |
pattern++; |
if (pattern == end) |
if (pattern == epattern) |
return false; |
return false; |
/* Negative match */ |
/* Negative match */ |
for (;;) { |
for (;;) { |
if (*pattern == '\\') { |
if (*pattern == '\\') { |
if (++pattern == end) |
if (++pattern == epattern) |
return false; |
return false; |
} |
} |
if (*pattern == *string) |
if (*pattern == *string) |
return false; |
return false; |
if (pattern[1] == '-') { |
if (pattern[1] == '-') { |
if (pattern + 2 == end) |
if (pattern + 2 == epattern) |
return false; |
return false; |
if (*pattern < *string && *string <= pattern[2]) |
if (*pattern < *string && *string <= pattern[2]) |
return false; |
return false; |
|
|
pattern += 3; |
pattern += 3; |
} else |
} else |
pattern++; |
pattern++; |
if (pattern == end) |
if (pattern == epattern) |
return false; |
return false; |
/* The test for ']' is done at the end so that ']' |
/* The test for ']' is done at the end so that ']' |
* can be used at the start of the range without '\' */ |
* can be used at the start of the range without '\' */ |
|
|
} else { |
} else { |
for (;;) { |
for (;;) { |
if (*pattern == '\\') { |
if (*pattern == '\\') { |
if (++pattern == end) |
if (++pattern == epattern) |
return false; |
return false; |
} |
} |
if (*pattern == *string) |
if (*pattern == *string) |
break; |
break; |
if (pattern[1] == '-') { |
if (pattern[1] == '-') { |
if (pattern + 2 == end) |
if (pattern + 2 == epattern) |
return false; |
return false; |
if (*pattern < *string && *string <= pattern[2]) |
if (*pattern < *string && *string <= pattern[2]) |
break; |
break; |
|
|
pattern++; |
pattern++; |
/* The test for ']' is done at the end so that ']' |
/* The test for ']' is done at the end so that ']' |
* can be used at the start of the range without '\' */ |
* can be used at the start of the range without '\' */ |
if (pattern == end || *pattern == ']') |
if (pattern == epattern || *pattern == ']') |
return false; |
return false; |
} |
} |
/* Found matching character, skip over rest of class. */ |
/* Found matching character, skip over rest of class. */ |
|
|
if (*pattern == '\\') |
if (*pattern == '\\') |
pattern++; |
pattern++; |
/* A non-terminated character class is ok. */ |
/* A non-terminated character class is ok. */ |
if (pattern == end) |
if (pattern == epattern) |
break; |
break; |
pattern++; |
pattern++; |
} |
} |
|
|
/* If the next pattern character is '\', just strip off the |
/* If the next pattern character is '\', just strip off the |
* '\' so we do exact matching on the character that follows. */ |
* '\' so we do exact matching on the character that follows. */ |
if (*pattern == '\\') { |
if (*pattern == '\\') { |
if (++pattern == end) |
if (++pattern == epattern) |
return false; |
return false; |
} |
} |
/* There's no special character. Just make sure that |
/* There's no special character. Just make sure that |
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
const char * |
const char * |
Str_SYSVMatch(word, pattern, len) |
Str_SYSVMatch(const char *word, const char *pattern, size_t *len) |
const char *word; /* Word to examine */ |
|
const char *pattern; /* Pattern to examine against */ |
|
size_t *len; /* Number of characters to substitute */ |
|
{ |
{ |
const char *p = pattern; |
const char *p = pattern; |
const char *w = word; |
const char *w = word; |
|
|
/*- |
/*- |
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
* Str_SYSVSubst -- |
* Str_SYSVSubst -- |
* Substitute '%' on the pattern with len characters from src. |
* Substitute '%' in the pattern with len characters from src. |
* If the pattern does not contain a '%' prepend len characters |
* If the pattern does not contain a '%' prepend len characters |
* from src. |
* from src. |
* |
* |
* Side Effects: |
* Side Effects: |
* Places result on buf |
* Adds result to buf |
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
void |
void |
Str_SYSVSubst(buf, pat, src, len) |
Str_SYSVSubst(Buffer buf, const char *pat, const char *src, size_t len) |
Buffer buf; |
|
const char *pat; |
|
const char *src; |
|
size_t len; |
|
{ |
{ |
const char *m; |
const char *m; |
|
|
|
|
} |
} |
|
|
char * |
char * |
Str_dupi(begin, end) |
Str_dupi(const char *begin, const char *end) |
const char *begin; |
|
const char *end; |
|
{ |
{ |
char *s; |
char *s; |
|
|
|
|
} |
} |
|
|
char * |
char * |
escape_dupi(begin, end, set) |
escape_dupi(const char *begin, const char *end, const char *set) |
const char *begin; |
|
const char *end; |
|
const char *set; |
|
{ |
{ |
char *s, *t; |
char *s, *t; |
|
|
|
|
} |
} |
|
|
char * |
char * |
Str_rchri(s, e, c) |
Str_rchri(const char *begin, const char *end, int c) |
const char *s; |
|
const char *e; |
|
int c; |
|
{ |
{ |
if (s != e) |
if (begin != end) |
do { |
do { |
if (*--e == c) |
if (*--end == c) |
return (char *)e; |
return (char *)end; |
} while (e != s); |
} while (end != begin); |
return NULL; |
return NULL; |
} |
} |