Annotation of researchv10dc/cmd/icon/src/icont/ixhdr.c, revision 1.1.1.1

1.1       root        1: #include "../h/config.h"
                      2: #include "../h/cpuconf.h"
                      3: #include "../h/header.h"
                      4: #ifndef NoHeader
                      5: #include <sys/types.h>
                      6: #include <sys/stat.h>
                      7: #include "../h/paths.h"
                      8: #ifndef Iconx
                      9: #define Iconx IconxPath
                     10: #endif Iconx
                     11: #define MaxArgs 500
                     12: char *pptr;
                     13: main(argc,argv)
                     14: int argc;
                     15: char **argv;
                     16:    {
                     17: 
                     18:    char *path, *getenv();
                     19:    char file[256];
                     20:    char *name;
                     21:    char *argvx[MaxArgs];
                     22:    
                     23:    name = argv[0];
                     24:    do 
                     25:       argvx[argc+1] = argv[argc];
                     26:    while (argc--);
                     27:    argv = argvx;
                     28:    /*
                     29:     * If the name contains any slashes we skip the path search and
                     30:     *  just try to run the file.
                     31:     */
                     32:    if (index(name,'/'))
                     33:       doiconx(argv,name);
                     34:    
                     35:    pptr = path = getenv("PATH");
                     36:    if (index(path,'.') == 0) {
                     37:       if (canrun(name))
                     38:          doiconx(argv,name);
                     39:       }
                     40:    while (trypath(name,file)) {
                     41:       if (canrun(file))
                     42:          doiconx(argv,file);
                     43:       }
                     44:    /*
                     45:     * If we can't find it, we assume that it must exist somewhere
                     46:     *  and infer that it's in the current directory.
                     47:     */
                     48:    if (canrun(name))
                     49:       doiconx(argv,name);
                     50:    exit(100);
                     51:    }
                     52: canrun(file)
                     53: char *file;
                     54:    {
                     55:    struct stat statb;
                     56:    if (access(file,5) == 0) {
                     57:       stat(file,&statb);
                     58:       if (statb.st_mode & S_IFREG)
                     59:          return 1;
                     60:       }
                     61:    return 0;
                     62:    }
                     63: doiconx(av,file)
                     64: char **av; char *file;
                     65:    {
                     66:    av[0] = "-iconx";
                     67:    av[1] = file;
                     68:    execv(Iconx,av);
                     69:    exit(200);
                     70:    }
                     71: trypath(name,file)
                     72: char *name, *file;
                     73:    {
                     74:    char c;
                     75:    
                     76:    while (*pptr == ':')
                     77:       pptr++;
                     78:    if (!*pptr)
                     79:       return 0;
                     80:    do {
                     81:       c = (*file++ = *pptr++);
                     82:       } while (c != ':' && c);
                     83:    pptr--;
                     84:    file--;
                     85:    
                     86:    *file++ = '/';
                     87:    while (*file++ = *name++);
                     88:    *file = 0;
                     89:    return 1;
                     90:    }
                     91: exit(c)
                     92:    {
                     93:    _exit(c);
                     94:    }
                     95: #else NoHeader
                     96: main()
                     97:    {
                     98:    }
                     99: #endif NoHeader

unix.superglobalmegacorp.com

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