|
|
1.1 root 1: /* @(#)hashserv.c 1.4 */
2: /*
3: * UNIX shell
4: *
5: * Bell Telephone Laboratories
6: *
7: */
8:
9: #include "defs.h"
10: #include <sys/types.h>
11: #include <sys/stat.h>
12: #include <errno.h>
13:
14: #define EXECUTE 01
15:
16: findpath(name)
17: register char *name;
18: {
19: register char *path;
20: register int count = 1;
21:
22: char *p;
23: int ok = 1;
24: int e_code = 1;
25:
26: path = getpath(name);
27:
28: while (path)
29: {
30: path = catpath(path, name);
31: p = curstak();
32:
33: if ((ok = chk_access(p)) == 0)
34: break;
35: else
36: e_code = max(e_code, ok);
37:
38: count++;
39: }
40:
41: return(ok ? -e_code : count);
42: }
43:
44:
45: chk_access(name)
46: register char *name;
47: {
48: struct stat buf;
49:
50: if (access(name, EXECUTE)==0 && stat(name, &buf)==0 && (buf.st_mode&S_IFMT)==S_IFREG)
51: return(0);
52:
53: return(errno == EACCES ? 3 : 1);
54: }
55:
56:
57: pr_path(name, count)
58: register char *name;
59: int count;
60: {
61: register char *path;
62:
63: path = getpath(name);
64:
65: while (--count && path)
66: path = nextpath(path);
67:
68: catpath(path, name);
69: prs_buff(curstak());
70: }
71:
72: what_is(name)
73: register char *name;
74: {
75: struct namnod *n;
76: int cnt;
77: int isparam = 0;
78:
79: if ((n = findnam(name)) && !(n->namval.flg & N_FUNCTN))
80: {
81: printnam(n);
82: isparam = n->namval.val!=0;
83: }
84:
85: if (n && (n->namval.flg & N_FUNCTN))
86: {
87: prs_buff(strf(n));
88: prc_buff(NL);
89: return;
90: }
91:
92: if (syslook(name, commands, no_commands))
93: {
94: prs_2buff("builtin ", name);
95: prc_buff(NL);
96: return;
97: }
98: if ((cnt = findpath(name)) > 0)
99: {
100: pr_path(name, cnt);
101: prc_buff(NL);
102: }
103: else if (!isparam)
104: failed(name, notfound, 0);
105: }
106:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.