Annotation of coherent/a/tmp/smail/getpath.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char    *sccsid="@(#)getpath.c  2.5 (smail) 9/15/87";
                      3: #endif
                      4: 
                      5: # include      <stdio.h>
                      6: # include      <sys/types.h>
                      7: # include      <ctype.h>
                      8: # include      "defs.h"
                      9: 
                     10: extern enum edebug debug;      /* how verbose we are           */ 
                     11: extern char *pathfile;         /* location of path database    */
                     12: 
                     13: /*
                     14: **
                     15: ** getpath(): look up key in ascii sorted path database.
                     16: **
                     17: */
                     18: 
                     19: getpath( key, path , cost)
                     20: char *key;             /* what we are looking for */
                     21: char *path;            /* where the path results go */
                     22: int *cost;             /* where the cost results go */
                     23: {
                     24:        char *getline();
                     25: 
                     26:        int lineno;
                     27:        char    *next_line,     /* Next line read by getline().  */
                     28:                *line_key,      /* Key extracted by strtok() from next_line.  */
                     29:                *line_cost;     /* Cost extracted by strtok() from next_line.  */
                     30:        FILE *file;
                     31: 
                     32: DEBUG("getpath: looking for '%s'\n", key);
                     33: 
                     34:        lineno = 0;
                     35: 
                     36:        if((file = fopen(pathfile, "r")) == NULL) {
                     37:                (void) printf("can't access %s.\n", pathfile);
                     38:                return( EX_OSFILE );
                     39:        }
                     40: 
                     41:        /* Linear search for key "path" in file stream "file".  */
                     42: 
                     43:        while (NULL != (next_line = getline(file, &lineno))) {
                     44:                line_key = strtok(next_line, WS);
                     45: 
                     46:                /*
                     47:                 * If we have a match, copy the path; copy the
                     48:                 * cost if there is one.
                     49:                 */
                     50:                if (strcmpic(key, line_key) == 0) {
                     51:                        strcpy(path, strtok(NULL, WS));
                     52: 
                     53:                        if (NULL != (line_cost = strtok(NULL, WS)) ) {
                     54:                                *cost = atoi(line_cost);
                     55:                        } else {
                     56:                                *cost = DEFCOST;
                     57:                        }
                     58:                        break;
                     59:                }
                     60:        }
                     61: 
                     62:        if (NULL == next_line) {
                     63:                fclose(file);
                     64:                return(EX_NOHOST);
                     65:        }
                     66: 
                     67:        fclose(file);
                     68:        return (EX_OK);
                     69: }

unix.superglobalmegacorp.com

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