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