From 8345f29bee6dc779223d4805edfc48e7c533b3a7 Mon Sep 17 00:00:00 2001 From: harti Date: Fri, 3 Dec 2004 08:02:52 +0000 Subject: Change the algorithm that matches the builtin shells from the name keyword of the .SHELL target. Formerly it used to select the shell with the longest common trailing substring, so that bash would select sh, but pocsh would select csh. Now an exact match is required so that specifying bash without also giving a path and the other keywords will give an error. PR: Submitted by: Reviewed by: ru Approved by: Obtained from: MFC after: --- usr.bin/make/job.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 6e8db76..c21107d 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -2389,7 +2389,7 @@ Job_Empty(void) * Find a matching shell in 'shells' given its final component. * * Results: - * A pointer to a freshly allocated Shell structure with is a copy + * A pointer to a freshly allocated Shell structure with a copy * of the static structure or NULL if no shell with the given name * is found. * @@ -2402,45 +2402,29 @@ static Shell * JobMatchShell(const char *name) { const struct CShell *sh; /* Pointer into shells table */ - const struct CShell *match; /* Longest-matching shell */ struct Shell *nsh; - const char *cp1; - const char *cp2; - const char *eoname; - eoname = name + strlen(name); - - match = NULL; + for (sh = shells; sh < shells + sizeof(shells) / sizeof(shells[0]); sh++) + if (strcmp(sh->name, name) == 0) + break; - for (sh = shells; sh < shells + sizeof(shells) / sizeof(shells[0]); sh++) { - for (cp1 = eoname - strlen(sh->name), cp2 = sh->name; - *cp1 != '\0' && *cp1 == *cp2; - cp1++, cp2++) { - continue; - } - if (*cp1 != *cp2) { - continue; - } else if (match == NULL || strlen(match->name) < strlen(sh->name)) { - match = sh; - } - } - if (match == NULL) + if (sh == shells + sizeof(shells) / sizeof(shells[0])) return (NULL); /* make a copy */ nsh = emalloc(sizeof(*nsh)); - nsh->name = estrdup(match->name); - nsh->echoOff = estrdup(match->echoOff); - nsh->echoOn = estrdup(match->echoOn); - nsh->hasEchoCtl = match->hasEchoCtl; - nsh->noPrint = estrdup(match->noPrint); - nsh->noPLen = match->noPLen; - nsh->hasErrCtl = match->hasErrCtl; - nsh->errCheck = estrdup(match->errCheck); - nsh->ignErr = estrdup(match->ignErr); - nsh->echo = estrdup(match->echo); - nsh->exit = estrdup(match->exit); + nsh->name = estrdup(sh->name); + nsh->echoOff = estrdup(sh->echoOff); + nsh->echoOn = estrdup(sh->echoOn); + nsh->hasEchoCtl = sh->hasEchoCtl; + nsh->noPrint = estrdup(sh->noPrint); + nsh->noPLen = sh->noPLen; + nsh->hasErrCtl = sh->hasErrCtl; + nsh->errCheck = estrdup(sh->errCheck); + nsh->ignErr = estrdup(sh->ignErr); + nsh->echo = estrdup(sh->echo); + nsh->exit = estrdup(sh->exit); return (nsh); } -- cgit v1.1