Annotation of researchv10no/cmd/basic/bite/src/pathopen.c, revision 1.1.1.1

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     /////////////////////////////////////
                      4:  *     /////////////////////////////////////
                      5:  *     //// SEARCH PATHS AND OPEN FILE /////
                      6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
                      7:  *     ///// Wed Sep 12 11:18:06 1979 //////
                      8:  *     /////////////////////////////////////
                      9:  *     /////////////////////////////////////
                     10: 
                     11:  * call format:
                     12:  * FILE *pathopen(),*fp;
                     13:  *     fp = pathopen(filestring);
                     14:  *
                     15:  * Search paths specified in bpath for file. If found,
                     16:  * open the filename pointed to by filestring and return filepointer fp.
                     17:  * If search fails return 0.
                     18:  * Same convention as fopen().
                     19:  */
                     20: /*   "@(#) pathopen.c:  V 1.2  3/14/81" */
                     21: #include "bas.h"
                     22: char bpath[100] = ":./:/usr/lib/bites:";
                     23: 
                     24: FILE *
                     25: pathopen(name)
                     26: char   name[];
                     27: {
                     28:        FILE *fopen(),*fp;
                     29:        char    *getpath();
                     30:        char filpath[80];
                     31:        register char *p;
                     32:        p = bpath;      /* start with first entry in paths */
                     33: 
                     34:        while((p = getpath(filpath,p)) != 0)
                     35:        {
                     36:                strcat(filpath,"/");
                     37:                strcat(filpath,name);
                     38:                if((fp = fopen(filpath,"r")) != 0) /* if open succeeds */
                     39:                        break;
                     40:        }
                     41:        if(fp == 0)     /* if open did not succeed */
                     42:        {
                     43:                error(inst.thing.linno,4);
                     44:                return(0);
                     45:        }
                     46:        return(fp);
                     47: }
                     48: 
                     49: /*
                     50:  * SCAN PATH STRING
                     51:  */
                     52: char *
                     53: getpath(field,s)
                     54: char   *s;
                     55: char   field[];
                     56: {
                     57:        int     i;
                     58:        char    *p;
                     59: 
                     60:        i = 0;
                     61:        p = s;
                     62:        if(*p == ':') *p++;     /* bump past delim */
                     63:        while(*p != '\0' && *p != ':')
                     64:        {
                     65:                field[i++] = *p++;
                     66:        }
                     67:        field[i] = '\0'; /* null terminate */
                     68: 
                     69:        if(p != s)
                     70:                return(p);
                     71: 
                     72:        return(0);
                     73: }

unix.superglobalmegacorp.com

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