Annotation of researchv9/cmd/sh/pathserv.c, revision 1.1.1.1

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, name);
                     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:        short   hashval;
                     78:        int     isparam = 0;
                     79: 
                     80:        if ((n = findnam(name)) && !(n->namval.flg & N_FUNCTN))
                     81:        {
                     82:                printnam(n);
                     83:                isparam = n->namval.val!=0;
                     84:        }
                     85: 
                     86:        if (n && (n->namval.flg & N_FUNCTN))
                     87:        {
                     88:                prs_buff(strf(n));
                     89:                prc_buff(NL);
                     90:                return;
                     91:        }
                     92: 
                     93:        if (syslook(name, commands, no_commands))
                     94:        {
                     95:                prs_2buff("builtin ", name);
                     96:                prc_buff(NL);
                     97:                return;
                     98:        }
                     99:        if ((cnt = findpath(name)) > 0)
                    100:        {
                    101:                pr_path(name, cnt);
                    102:                prc_buff(NL);
                    103:        }
                    104:        else if (!isparam)
                    105:                failed(name, notfound);
                    106: }
                    107: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.