Remove sindex() and replace with strstr().

Windows: allow users to set SHELL to cmd.exe and have it behave as if no
UNIX shell were found.
This commit is contained in:
Paul Smith 2004-09-21 12:07:12 +00:00
parent 9714e501fb
commit 704c60cec0
7 changed files with 61 additions and 49 deletions

View file

@ -1,3 +1,23 @@
2004-09-21 Paul D. Smith <psmith@gnu.org>
* misc.c: Removed the sindex() function. All instances of this
function were trivially replaceable by the standard strstr()
function, and that function will always have better (or certainly
no worse) performance than the very simple-minded algorithm
sindex() used. This can matter with complex makefiles.
* make.h: Remove the prototype for sindex().
* function.c (subst_expand): Convert sindex() call to strstr().
This means we no longer need to track the TLEN value so remove that.
(func_findstring): Convert sindex() to strstr().
* commands.c (chop_commands): Convert sindex() calls to strstr().
Suggested by: Markus Mauhart <qwe123@chello.at>.
* main.c (find_and_set_default_shell) [WINDOWS32]: Implement the
idea behind Savannah Patch #3144 from david.baird@homemail.com.
If SHELL is set to CMD.EXE then assume it's batch-mode and
non-unixy. I wrote the code differently from the patch, though,
to make it safer.
2004-09-20 Paul D. Smith <psmith@gnu.org>
* expand.c (variable_expand_string): Modify to invoke

View file

@ -346,13 +346,11 @@ chop_commands (struct commands *cmds)
flags |= COMMANDS_NOERROR;
break;
}
if (!(flags & COMMANDS_RECURSE))
{
unsigned int len = strlen (p);
if (sindex (p, len, "$(MAKE)", 7) != 0
|| sindex (p, len, "${MAKE}", 7) != 0)
flags |= COMMANDS_RECURSE;
}
/* If no explicit '+' was given, look for MAKE variable references. */
if (!(flags & COMMANDS_RECURSE)
&& (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
flags |= COMMANDS_RECURSE;
cmds->lines_flags[idx] = flags;
cmds->any_recurse |= flags & COMMANDS_RECURSE;

View file

@ -79,13 +79,12 @@ subst_expand (char *o, char *text, char *subst, char *replace,
unsigned int slen, unsigned int rlen, int by_word)
{
char *t = text;
unsigned int tlen = strlen (text);
char *p;
if (slen == 0 && !by_word)
{
/* The first occurrence of "" in any string is its end. */
o = variable_buffer_output (o, t, tlen);
o = variable_buffer_output (o, t, strlen (t));
if (rlen > 0)
o = variable_buffer_output (o, replace, rlen);
return o;
@ -99,11 +98,11 @@ subst_expand (char *o, char *text, char *subst, char *replace,
p = end_of_token (next_token (t));
else
{
p = sindex (t, tlen, subst, slen);
p = strstr (t, subst);
if (p == 0)
{
/* No more matches. Output everything left on the end. */
o = variable_buffer_output (o, t, tlen);
o = variable_buffer_output (o, t, strlen (t));
return o;
}
}
@ -124,10 +123,9 @@ subst_expand (char *o, char *text, char *subst, char *replace,
/* Output the replacement string. */
o = variable_buffer_output (o, replace, rlen);
/* Advance T past the string to be replaced; adjust tlen. */
/* Advance T past the string to be replaced. */
{
char *nt = p + slen;
tlen -= nt - t;
t = nt;
}
} while (*t != '\0');
@ -786,9 +784,8 @@ static char*
func_findstring (char *o, char **argv, const char *funcname UNUSED)
{
/* Find the first occurrence of the first string in the second. */
int i = strlen (argv[0]);
if (sindex (argv[1], 0, argv[0], i) != 0)
o = variable_buffer_output (o, argv[0], i);
if (strstr (argv[1], argv[0]) != 0)
o = variable_buffer_output (o, argv[0], strlen (argv[0]));
return o;
}

24
main.c
View file

@ -699,7 +699,8 @@ int
find_and_set_default_shell (char *token)
{
int sh_found = 0;
char* search_token;
char *search_token;
char *tokend;
PATH_VAR(sh_path);
extern char *default_shell;
@ -708,8 +709,25 @@ find_and_set_default_shell (char *token)
else
search_token = token;
if (!no_default_sh_exe &&
(token == NULL || !strcmp(search_token, default_shell))) {
/* If the user explicitly requests the DOS cmd shell, obey that request.
However, make sure that's what they really want by requiring the value
of SHELL either equal, or have a final path element of, "cmd" or
"cmd.exe" case-insensitive. */
tokend = search_token + strlen (search_token) - 3;
if (((tokend == search_token
|| (tokend > search_token
&& (tokend[-1] == '/' || tokend[-1] == '\\')))
&& strcmpi (tokend, "cmd"))
|| ((tokend - 4 == search_token
|| (tokend - 4 > search_token
&& (tokend[-5] == '/' || tokend[-5] == '\\')))
&& strcmpi (tokend - 4, "cmd.exe"))) {
batch_mode_shell = 1;
unixy_shell = 0;
sh_found = 0;
} else if (!no_default_sh_exe &&
(token == NULL || !strcmp (search_token, default_shell))) {
/* no new information, path already set or known */
sh_found = 1;
} else if (file_exists_p(search_token)) {

2
make.h
View file

@ -423,8 +423,6 @@ extern char *next_token PARAMS ((const char *));
extern char *end_of_token PARAMS ((char *));
extern void collapse_continuations PARAMS ((char *));
extern void remove_comments PARAMS((char *));
extern char *sindex PARAMS ((const char *, unsigned int, \
const char *, unsigned int));
extern char *lindex PARAMS ((const char *, const char *, int));
extern int alpha_compare PARAMS ((const void *, const void *));
extern void print_spaces PARAMS ((unsigned int));

28
misc.c
View file

@ -412,34 +412,6 @@ savestring (const char *str, unsigned int length)
return out;
}
/* Search string BIG (length BLEN) for an occurrence of
string SMALL (length SLEN). Return a pointer to the
beginning of the first occurrence, or return nil if none found. */
char *
sindex (const char *big, unsigned int blen,
const char *small, unsigned int slen)
{
if (!blen)
blen = strlen (big);
if (!slen)
slen = strlen (small);
if (slen && blen >= slen)
{
register unsigned int b;
/* Quit when there's not enough room left for the small string. */
--slen;
blen -= slen;
for (b = 0; b < blen; ++b, ++big)
if (*big == *small && strneq (big + 1, small + 1, slen))
return (char *)big;
}
return 0;
}
/* Limited INDEX:
Search through the string STRING, which ends at LIMIT, for the character C.

View file

@ -1,3 +1,12 @@
2004-09-21 Paul D. Smith <psmith@gnu.org>
* run_make_tests.pl (run_make_test): Enhance to allow the make
string to be undef: in that case it reuses the previous make
string. Allows multiple tests on the same makefile.
* scripts/variables/flavors: Add some tests for prefix characters
interacting with define/endef variables.
2004-09-20 Paul D. Smith <psmith@gnu.org>
* scripts/functions/substitution: Rewrite to use run_make_test()