1 /* $Header: /src/pub/tcsh/sh.exec.c,v 3.48 2000/01/14 22:57:27 christos Exp $ */
3 * sh.exec.c: Search, find, and execute a command!
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 RCSID("$Id: sh.exec.c,v 3.48 2000/01/14 22:57:27 christos Exp $")
52 # define FASTHASH /* Fast hashing is the default */
56 * System level search and execute of a command.
57 * We look in each directory for the specified command name.
58 * If the name contains a '/' then we execute only the full path name.
59 * If there is no search path then we execute only full path names.
63 * As we search for the command we note the first non-trivial error
64 * message for presentation to the user. This allows us often
65 * to show that a file has the wrong mode/no access when the file
66 * is not in the last component of the search path, so we must
67 * go on after first detecting the error.
69 static char *exerr; /* Execution error message */
70 static Char *expath; /* Path for exerr */
73 * The two part hash function is designed to let texec() call the
74 * more expensive hashname() only once and the simple hash() several
75 * times (once for each path component checked).
76 * Byte size is assumed to be 8.
78 #define BITS_PER_BYTE 8
82 * xhash is an array of hash buckets which are used to hash execs. If
83 * it is allocated (havhash true), then to tell if ``name'' is
84 * (possibly) presend in the i'th component of the variable path, look
85 * at the [hashname(name)] bucket of size [hashwidth] bytes, in the [i
86 * mod size*8]'th bit. The cache size is defaults to a length of 1024
87 * buckets, each 1 byte wide. This implementation guarantees that
88 * objects n bytes wide will be aligned on n byte boundaries.
92 static unsigned long *xhash = NULL;
93 static unsigned int hashlength = 0, uhashlength = 0;
94 static unsigned int hashwidth = 0, uhashwidth = 0;
95 static int hashdebug = 0;
97 # define hash(a, b) (((a) * HSHMUL + (b)) % (hashlength))
98 # define widthof(t) (sizeof(t) * BITS_PER_BYTE)
99 # define tbit(f, i, t) (((t *) xhash)[(f)] & \
100 (1L << (i & (widthof(t) - 1))))
101 # define tbis(f, i, t) (((t *) xhash)[(f)] |= \
102 (1L << (i & (widthof(t) - 1))))
103 # define cbit(f, i) tbit(f, i, unsigned char)
104 # define cbis(f, i) tbis(f, i, unsigned char)
105 # define sbit(f, i) tbit(f, i, unsigned short)
106 # define sbis(f, i) tbis(f, i, unsigned short)
107 # define ibit(f, i) tbit(f, i, unsigned int)
108 # define ibis(f, i) tbis(f, i, unsigned int)
109 # define lbit(f, i) tbit(f, i, unsigned long)
110 # define lbis(f, i) tbis(f, i, unsigned long)
112 # define bit(f, i) (hashwidth==sizeof(unsigned char) ? cbit(f,i) : \
113 ((hashwidth==sizeof(unsigned short) ? sbit(f,i) : \
114 ((hashwidth==sizeof(unsigned int) ? ibit(f,i) : \
116 # define bis(f, i) (hashwidth==sizeof(unsigned char) ? cbis(f,i) : \
117 ((hashwidth==sizeof(unsigned short) ? sbis(f,i) : \
118 ((hashwidth==sizeof(unsigned int) ? ibis(f,i) : \
122 * Xhash is an array of HSHSIZ bits (HSHSIZ / 8 chars), which are used
123 * to hash execs. If it is allocated (havhash true), then to tell
124 * whether ``name'' is (possibly) present in the i'th component
125 * of the variable path, you look at the bit in xhash indexed by
126 * hash(hashname("name"), i). This is setup automatically
127 * after .login is executed, and recomputed whenever ``path'' is
130 # define HSHSIZ 8192 /* 1k bytes */
131 # define HSHMASK (HSHSIZ - 1)
133 static char xhash[HSHSIZ / BITS_PER_BYTE];
135 # define hash(a, b) (((a) * HSHMUL + (b)) & HSHMASK)
136 # define bit(h, b) ((h)[(b) >> 3] & 1 << ((b) & 7)) /* bit test */
137 # define bis(h, b) ((h)[(b) >> 3] |= 1 << ((b) & 7)) /* bit set */
139 #endif /* FASTHASH */
142 static int hits, misses;
145 /* Dummy search path for just absolute search when no path */
146 static Char *justabs[] = {STRNULL, 0};
148 static void pexerr __P((void));
149 static void texec __P((Char *, Char **));
150 static int hashname __P((Char *));
151 static int iscommand __P((Char *));
155 register struct command *t;
157 register Char *dp, **pv, **av, *sav;
158 register struct varent *v;
160 register int hashval, i;
164 * Glob the command name. We will search $path even if this does something,
165 * as in sh but not in csh. One special case: if there is no PATH, then we
166 * execute only commands which start with '/'.
168 blk[0] = t->t_dcom[0];
170 gflag = 0, tglob(blk);
174 setname(short2str(blk[0]));
175 stderror(ERR_NAME | ERR_NOMATCH);
185 expath = Strsave(pv[0]);
191 if (v == 0 && expath[0] != '/' && expath[0] != '.') {
195 slash = any(short2str(expath), '/');
198 * Glob the argument list, if necessary. Otherwise trim off the quote bits.
207 setname(short2str(expath));
208 stderror(ERR_NAME | ERR_NOMATCH);
216 t->t_dcom = blkspl(pv, av);
222 if (*av == NULL || **av == '\0')
225 xechoit(av); /* Echo command if -x */
228 * Since all internal file descriptors are set to close on exec, we don't
229 * need to close them explicitly here. Just reorient ourselves for error
236 isoutatty = isatty(SHOUT);
237 isdiagatty = isatty(SHDIAG);
239 closech(); /* Close random fd's */
242 * We must do this AFTER any possible forking (like `foo` in glob) so that
243 * this shell can still do subprocesses.
246 (void) sigsetmask((sigmask_t) 0);
248 (void) sigrelse(SIGINT);
249 (void) sigrelse(SIGCHLD);
253 * If no path, no words in path, or a / in the filename then restrict the
256 if (v == 0 || v->vec[0] == 0 || slash)
260 sav = Strspl(STRslash, *av);/* / command name for postpending */
264 hashval = havhash ? hashname(*av) : 0;
272 * Try to save time by looking at the hash table for where this command
273 * could be. If we are doing delayed hashing, then we put the names in
274 * one at a time, as the user enters them. This is kinda like Korn
275 * Shell's "tracked aliases".
277 if (!slash && ABSOLUTEP(pv[0]) && havhash) {
279 if (!bit(hashval, i))
282 int hashval1 = hash(hashval, i);
283 if (!bit(xhash, hashval1))
285 #endif /* FASTHASH */
287 if (pv[0][0] == 0 || eq(pv[0], STRdot)) /* don't make ./xxx */
291 if (t->t_dflg & F_AMPERSAND) {
293 xprintf("set SIGINT to SIG_IGN\n");
294 xprintf("set SIGQUIT to SIG_DFL\n");
295 # endif /* JOBDEBUG */
296 (void) signal(SIGINT,SIG_IGN); /* may not be necessary */
297 (void) signal(SIGQUIT,SIG_DFL);
300 if (gointr && eq(gointr, STRminus)) {
302 xprintf("set SIGINT to SIG_IGN\n");
303 xprintf("set SIGQUIT to SIG_IGN\n");
304 # endif /* JOBDEBUG */
305 (void) signal(SIGINT,SIG_IGN); /* may not be necessary */
306 (void) signal(SIGQUIT,SIG_IGN);
308 #endif /* COHERENT */
313 dp = Strspl(*pv, sav);
319 if ((t->t_dflg & F_AMPERSAND)) {
321 xprintf("set SIGINT to SIG_IGN\n");
322 # endif /* JOBDEBUG */
324 * this is necessary on Coherent or all background
325 * jobs are killed by CTRL-C
326 * (there must be a better fix for this)
328 (void) signal(SIGINT,SIG_IGN);
330 if (gointr && eq(gointr,STRminus)) {
332 xprintf("set SIGINT to SIG_IGN\n");
333 xprintf("set SIGQUIT to SIG_IGN\n");
334 # endif /* JOBDEBUG */
335 (void) signal(SIGINT,SIG_IGN); /* may not be necessary */
336 (void) signal(SIGQUIT,SIG_IGN);
338 #endif /* COHERENT */
364 /* Couldn't find the damn thing */
366 setname(short2str(expath));
370 xfree((ptr_t) expath);
376 stderror(ERR_NAME | ERR_STRING, exerr);
377 stderror(ERR_NAME | ERR_COMMAND);
381 * Execute command f, arg list t.
382 * Record error message if not found.
383 * Also do shell scripts here.
392 register struct varent *v;
399 /* The order for the conversions is significant */
405 errno = 0; /* don't use a previous error */
408 * If we try to execute an nfs mounted directory on the apollo, we
409 * hang forever. So until apollo fixes that..
413 if (stat(f, &stb) == 0 && S_ISDIR(stb.st_mode))
419 #ifdef ISC_POSIX_EXEC_BUG
420 __setostype(0); /* "0" is "__OS_SYSV" in <sys/user.h> */
421 #endif /* ISC_POSIX_EXEC_BUG */
423 #ifdef ISC_POSIX_EXEC_BUG
424 __setostype(1); /* "1" is "__OS_POSIX" in <sys/user.h> */
425 #endif /* ISC_POSIX_EXEC_BUG */
430 blkfree((Char **) t);
438 * From: casper@fwi.uva.nl (Casper H.S. Dik) If we could not execute
439 * it, don't feed it to the shell if it looks like a binary!
441 if ((fd = open(f, O_RDONLY)) != -1) {
443 if ((nread = read(fd, (char *) pref, 2)) == 2) {
444 if (!Isprint(pref[0]) && (pref[0] != '\n' && pref[0] != '\t')) {
447 * We *know* what ENOEXEC means.
449 stderror(ERR_ARCH, f, strerror(errno));
452 else if (nread < 0 && errno != EINTR) {
454 /* need to print error incase the file is migrated */
455 stderror(ERR_SYSTEM, f, strerror(errno));
467 pref[0] != '#' || pref[1] != '!' || hashbang(fd, &vp) == -1) {
468 #endif /* HASHBANG */
470 * If there is an alias for shell, then put the words of the alias in
471 * front of the argument list replacing the command name. Note no
472 * interpretation of the words at this point.
474 v = adrof1(STRshell, &aliases);
477 vp[0] = adrof(STRshell) ? varval(STRshell) : STR_SHELLPATH;
481 # ifndef ISC /* Compatible with ISC's /bin/csh */
490 vp = saveblk(v->vec);
493 #endif /* HASHBANG */
500 st = blkspl(vp, st); /* Splice up the new arglst */
503 /* The order for the conversions is significant */
507 blkfree((Char **) vp);
511 #ifdef ISC_POSIX_EXEC_BUG
512 __setostype(0); /* "0" is "__OS_SYSV" in <sys/user.h> */
513 #endif /* ISC_POSIX_EXEC_BUG */
515 #ifdef ISC_POSIX_EXEC_BUG
516 __setostype(1); /* "1" is "__OS_POSIX" in <sys/user.h> */
517 #endif /* ISC_POSIX_EXEC_BUG */
521 blkfree((Char **) t);
522 /* The sky is falling, the sky is falling! */
523 stderror(ERR_SYSTEM, f, strerror(errno));
527 stderror(ERR_SYSTEM, f, strerror(errno));
531 case 0: /* execv fails and returns 0! */
538 exerr = strerror(errno);
540 xfree((ptr_t) expath);
541 expath = Strsave(sf);
554 register struct command *kp;
556 int saveIN, saveOUT, saveDIAG, saveSTD;
564 #ifndef CLOSE_ON_EXEC
566 #endif /* CLOSE_ON_EXEC */
567 signalfun_t osigint, osigquit, osigterm;
570 if (chkstop == 0 && setintr)
573 * Hmm, we don't really want to do that now because we might
574 * fail, but what is the choice
576 rechist(NULL, adrof(STRsavehist) != NULL);
579 osigint = signal(SIGINT, parintr);
580 osigquit = signal(SIGQUIT, parintr);
581 osigterm = signal(SIGTERM, parterm);
584 #ifndef CLOSE_ON_EXEC
586 #endif /* CLOSE_ON_EXEC */
592 saveIN = dcopy(SHIN, -1);
593 saveOUT = dcopy(SHOUT, -1);
594 saveDIAG = dcopy(SHDIAG, -1);
595 saveSTD = dcopy(OLDSTD, -1);
597 lshift(kp->t_dcom, 1);
601 /* PWP: setjmp/longjmp bugfix for optimizing compilers */
603 my_reenter = 1; /* assume non-zero return val */
604 if (setexit() == 0) {
605 my_reenter = 0; /* Oh well, we were wrong */
607 if ((my_reenter = setexit()) == 0) {
610 SHOUT = dcopy(1, -1);
611 SHDIAG = dcopy(2, -1);
612 #ifndef CLOSE_ON_EXEC
614 #endif /* CLOSE_ON_EXEC */
617 * Decrement the shell level
626 (void) sigset(SIGINT, osigint);
627 (void) sigset(SIGQUIT, osigquit);
628 (void) sigset(SIGTERM, osigterm);
631 #ifndef CLOSE_ON_EXEC
633 #endif /* CLOSE_ON_EXEC */
637 (void) close(SHDIAG);
638 (void) close(OLDSTD);
639 SHIN = dmove(saveIN, oSHIN);
640 SHOUT = dmove(saveOUT, oSHOUT);
641 SHDIAG = dmove(saveDIAG, oSHDIAG);
642 OLDSTD = dmove(saveSTD, oOLDSTD);
646 stderror(ERR_SILENT);
653 if (adrof(STRecho)) {
656 blkpr(t), xputchar('\n');
671 register struct dirent *dp;
673 struct varent *v = adrof(STRpath);
677 int is_windir; /* check if it is the windows directory */
684 uhashlength = atoi(short2str(vv[1]));
686 uhashwidth = atoi(short2str(vv[2]));
687 if ((uhashwidth != sizeof(unsigned char)) &&
688 (uhashwidth != sizeof(unsigned short)) &&
689 (uhashwidth != sizeof(unsigned long)))
692 hashdebug = atoi(short2str(vv[3]));
697 hashwidth = uhashwidth;
700 for (pv = v->vec; *pv; pv++, hashwidth++)
702 if (hashwidth <= widthof(unsigned char))
703 hashwidth = sizeof(unsigned char);
704 else if (hashwidth <= widthof(unsigned short))
705 hashwidth = sizeof(unsigned short);
706 else if (hashwidth <= widthof(unsigned int))
707 hashwidth = sizeof(unsigned int);
709 hashwidth = sizeof(unsigned long);
713 hashlength = uhashlength;
715 hashlength = hashwidth * (8*64);/* "average" files per dir in path */
718 xfree((ptr_t) xhash);
719 xhash = (unsigned long *) xcalloc((size_t) (hashlength * hashwidth),
721 #endif /* FASTHASH */
723 (void) getusername(NULL); /* flush the tilde cashe */
728 for (pv = v->vec; *pv; pv++, i++) {
729 if (!ABSOLUTEP(pv[0]))
731 dirp = opendir(short2str(*pv));
734 #ifdef COMMENT /* this isn't needed. opendir won't open
736 if (fstat(dirp->dd_fd, &stb) < 0 || !S_ISDIR(stb.st_mode)) {
737 (void) closedir(dirp);
742 is_windir = nt_check_if_windir(short2str(*pv));
744 while ((dp = readdir(dirp)) != NULL) {
747 if (dp->d_name[0] == '.' &&
748 (dp->d_name[1] == '\0' ||
749 (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
752 nt_check_name_and_hash(is_windir, dp->d_name, i);
754 #if defined(_UWIN) /* XXX: Add cygwin too */
755 /* Turn foo.{exe,com,bat} into foo since UWIN's readdir returns
756 * the file with the .exe, .com, .bat extension
759 size_t ext = strlen(dp->d_name) - 4;
760 if ((ext > 0) && (strcmp(&dp->d_name[ext], ".exe") == 0 ||
761 strcmp(&dp->d_name[ext], ".bat") == 0 ||
762 strcmp(&dp->d_name[ext], ".com") == 0))
763 dp->d_name[ext] = '\0';
767 hashval = hashname(str2short(dp->d_name));
770 xprintf(CGETS(13, 1, "hash=%-4d dir=%-2d prog=%s\n"),
771 hashname(str2short(dp->d_name)), i, dp->d_name);
772 # else /* OLD HASH */
773 hashval = hash(hashname(str2short(dp->d_name)), i);
775 # endif /* FASTHASH */
776 /* tw_add_comm_name (dp->d_name); */
779 (void) closedir(dirp);
794 xfree((ptr_t) xhash);
797 #endif /* FASTHASH */
809 if (havhash && hashlength && hashwidth)
810 xprintf(CGETS(13, 2, "%d hash buckets of %d bits each\n"),
811 hashlength, hashwidth*8);
813 xprintf(CGETS(13, 3, "debug mask = 0x%08x\n"), hashdebug);
814 #endif /* FASTHASH */
817 xprintf(CGETS(13, 4, "%d hits, %d misses, %d%%\n"),
818 hits, misses, 100 * hits / (hits + misses));
824 * Hash a command name.
830 register unsigned long h;
832 for (h = 0; *cp; cp++)
843 register struct varent *v;
844 register bool slash = any(short2str(name), '/');
845 register int hashval, i;
848 if (v == 0 || v->vec[0] == 0 || slash)
852 sav = Strspl(STRslash, name); /* / command name for postpending */
853 hashval = havhash ? hashname(name) : 0;
856 if (!slash && ABSOLUTEP(pv[0]) && havhash) {
858 if (!bit(hashval, i))
861 int hashval1 = hash(hashval, i);
862 if (!bit(xhash, hashval1))
864 #endif /* FASTHASH */
866 if (pv[0][0] == 0 || eq(pv[0], STRdot)) { /* don't make ./xxx */
867 if (executable(NULL, name, 0)) {
873 if (executable(*pv, sav, 0)) {
887 * Andreas Luik <luik@isaak.isa.de>
888 * I S A GmbH - Informationssysteme fuer computerintegrierte Automatisierung
892 * is the executable() routine below and changes to iscommand().
897 * executable() examines the pathname obtained by concatenating dir and name
898 * (dir may be NULL), and returns 1 either if it is executable by us, or
899 * if dir_ok is set and the pathname refers to a directory.
900 * This is a bit kludgy, but in the name of optimization...
903 executable(dir, name, dir_ok)
908 Char path[MAXPATHLEN + 1];
913 (void) memset(path, 0, sizeof(path));
916 copyn(path, dir, MAXPATHLEN);
917 catn(path, name, MAXPATHLEN);
920 char *ptr = short2str(path);
937 if (!has_ext && (stat(p2, &stbuf) == -1))
938 catn(path, STRdotEXE, MAXPATHLEN);
941 strname = short2str(path);
944 strname = short2str(name);
946 return (stat(strname, &stbuf) != -1 &&
947 ((dir_ok && S_ISDIR(stbuf.st_mode)) ||
948 (S_ISREG(stbuf.st_mode) &&
949 /* save time by not calling access() in the hopeless case */
951 (GetBinaryType(strname,&nt_exetype) ||
952 (stbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR)))
954 (stbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR)) &&
955 access(strname, X_OK) == 0
961 tellmewhat(lexp, str)
962 struct wordent *lexp;
966 register struct biltins *bptr;
967 register struct wordent *sp = lexp->next;
968 bool aliased = 0, found;
969 Char *s0, *s1, *s2, *cmd;
972 if (adrof1(sp->word, &aliases)) {
978 s0 = sp->word; /* to get the memory freeing right... */
980 /* handle quoted alias hack */
981 if ((*(sp->word) & (QUOTE | TRIM)) == QUOTE)
984 /* do quoting, if it hasn't been done */
991 while (*s2 && *s2 != qc)
992 *s1++ = *s2++ | QUOTE;
998 *s1++ = *s2++ | QUOTE;
1005 for (bptr = bfunc; bptr < &bfunc[nbfunc]; bptr++) {
1006 if (eq(sp->word, str2short(bptr->bname))) {
1010 xprintf(CGETS(13, 5, "%S: shell built-in command.\n"),
1015 (void) Strcpy(str, sp->word);
1016 sp->word = s0; /* we save and then restore this */
1021 for (bptr = nt_bfunc; bptr < &nt_bfunc[nt_nbfunc]; bptr++) {
1022 if (eq(sp->word, str2short(bptr->bname))) {
1026 xprintf(CGETS(13, 5, "%S: shell built-in command.\n"),
1031 (void) Strcpy(str, sp->word);
1032 sp->word = s0; /* we save and then restore this */
1038 sp->word = cmd = globone(sp->word, G_IGNORE);
1040 if ((i = iscommand(sp->word)) != 0) {
1042 register struct varent *v;
1043 bool slash = any(short2str(sp->word), '/');
1046 if (v == 0 || v->vec[0] == 0 || slash)
1053 if (pv[0][0] == 0 || eq(pv[0], STRdot)) {
1055 sp->word = Strspl(STRdotsl, sp->word);
1057 xfree((ptr_t) sp->word);
1063 s1 = Strspl(*pv, STRslash);
1064 sp->word = Strspl(s1, sp->word);
1069 (void) Strcpy(str, sp->word);
1070 xfree((ptr_t) sp->word);
1078 xprintf(CGETS(13, 6, "%S: Command not found.\n"), sp->word);
1082 (void) Strcpy(str, sp->word);
1085 sp->word = s0; /* we save and then restore this */
1091 * Builtin to look at and list all places a command may be defined:
1092 * aliases, shell builtins, and the path.
1094 * Marc Horowitz <marc@mit.edu>
1095 * MIT Student Information Processing Board
1107 found &= find_cmd(*v, 1);
1108 /* Make status nonzero if any command is not found. */
1110 set(STRstatus, Strsave(STR1), VAR_READWRITE);
1119 struct biltins *bptr;
1122 int hashval, i, ex, rval = 0;
1124 if (prt && any(short2str(cmd), '/')) {
1125 xprintf(CGETS(13, 7, "where: / in command makes no sense\n"));
1129 /* first, look for an alias */
1131 if (prt && adrof1(cmd, &aliases)) {
1132 if ((var = adrof1(cmd, &aliases)) != NULL) {
1133 xprintf(CGETS(13, 8, "%S is aliased to "), cmd);
1140 /* next, look for a shell builtin */
1142 for (bptr = bfunc; bptr < &bfunc[nbfunc]; bptr++) {
1143 if (eq(cmd, str2short(bptr->bname))) {
1146 xprintf(CGETS(13, 9, "%S is a shell built-in\n"), cmd);
1152 for (bptr = nt_bfunc; bptr < &nt_bfunc[nt_nbfunc]; bptr++) {
1153 if (eq(cmd, str2short(bptr->bname))) {
1156 xprintf(CGETS(13, 9, "%S is a shell built-in\n"), cmd);
1163 /* last, look through the path for the command */
1165 if ((var = adrof(STRpath)) == NULL)
1168 hashval = havhash ? hashname(cmd) : 0;
1170 sv = Strspl(STRslash, cmd);
1172 for (pv = var->vec, i = 0; *pv; pv++, i++) {
1173 if (havhash && !eq(*pv, STRdot)) {
1175 if (!bit(hashval, i))
1178 int hashval1 = hash(hashval, i);
1179 if (!bit(xhash, hashval1))
1181 #endif /* FASTHASH */
1183 ex = executable(*pv, sv, 0);
1185 if (!ex && (hashdebug & 2)) {
1186 xprintf(CGETS(13, 10, "hash miss: "));
1187 ex = 1; /* Force printing */
1189 #endif /* FASTHASH */
1193 xprintf("%S/", *pv);
1194 xprintf("%S\n", cmd);
1206 nt_check_if_windir(path)
1209 char windir[MAX_PATH];
1211 (void)GetWindowsDirectory(windir, sizeof(windir));
1214 return (strstr(path, windir) != NULL);
1218 nt_check_name_and_hash(is_windir, file, i)
1223 char name_only[MAX_PATH];
1224 char *tmp = (char *)strrchr(file, '.');
1225 char uptmp[5], *nameptr, *np2;
1226 int icount, hashval;
1231 for (icount = 0; icount < 4; icount++)
1232 uptmp[icount] = toupper(tmp[icount]);
1236 if((uptmp[1] != 'E') || (uptmp[2] != 'X') || (uptmp[3] != 'E'))
1238 (void) memset(name_only, 0, MAX_PATH);
1241 while(nameptr != tmp) {
1242 *np2++= tolower(*nameptr);
1245 hashval = hashname(str2short(name_only));
1248 hashval = hashname(str2short(file));
1251 int hashval_extern(cp)
1254 return havhash?hashname(cp):0;
1256 int bit_extern(val,i)