Commit | Line | Data |
---|---|---|
505bf312 KB |
1 | /*- |
2 | * Copyright (c) 1980 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
252367af DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
505bf312 | 10 | "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ |
252367af | 11 | All rights reserved.\n"; |
505bf312 | 12 | #endif /* not lint */ |
2d40c995 | 13 | |
252367af | 14 | #ifndef lint |
505bf312 KB |
15 | static char sccsid[] = "@(#)pix.c 5.2 (Berkeley) %G%"; |
16 | #endif /* not lint */ | |
2d40c995 | 17 | |
134fe9f6 BJ |
18 | /* |
19 | * pix - pi then px | |
20 | * | |
21 | * Bill Joy UCB August 26, 1977 | |
22 | */ | |
134fe9f6 | 23 | |
2d40c995 KM |
24 | #include "whoami.h" |
25 | #include "objfmt.h" | |
aa6c84c4 | 26 | #include "config.h" |
134fe9f6 BJ |
27 | #define ERRS 1 |
28 | ||
29 | char *name; | |
30 | ||
31 | int onintr(); | |
32 | ||
33 | #define ETXTBSY 26 | |
34 | ||
35 | main(argc, argv) | |
36 | int argc; | |
37 | char *argv[]; | |
38 | { | |
39 | register char **av; | |
40 | register int ac; | |
41 | int i, io, pid, status; | |
42 | extern errno; | |
43 | ||
44 | do | |
45 | io = open("/dev/null", 0); | |
46 | while (io >= 0 && io < 3); | |
47 | for (io = 3; io < 15; io++) | |
48 | close(io); | |
49 | if ((signal(2, 1) & 01) == 0) | |
50 | signal(2, onintr); | |
51 | for (ac = 1; ac < argc; ac++) | |
52 | if (dotted(argv[ac], 'p')) { | |
53 | ac++; | |
54 | break; | |
55 | } | |
56 | name = "-o/tmp/pixaXXXXX" + 2; | |
57 | mktemp(name); | |
58 | for (;;) { | |
59 | io = creat(name, 0400); | |
60 | if (io > 0) | |
61 | break; | |
62 | if (name[8] == 'z') { | |
63 | perror(name); | |
64 | exit(1); | |
65 | } | |
66 | name[8]++; | |
67 | } | |
68 | pid = fork(); | |
69 | if (pid == -1) { | |
70 | write(2, "No more processes\n", 18); | |
71 | onintr(); | |
72 | } | |
73 | if (pid == 0) { | |
74 | if (io != 3) { | |
75 | write(2, "Impossible error in pix\n", 24); | |
76 | onintr(); | |
77 | } | |
78 | argv[ac] = 0; | |
79 | argv[0] = name - 2; | |
134fe9f6 | 80 | do |
aa6c84c4 | 81 | execv(pi_comp, argv); |
134fe9f6 BJ |
82 | while (errno == ETXTBSY); |
83 | write(2, "Can't find pi\n", 14); | |
84 | onintr(); | |
85 | } | |
86 | close(io); | |
87 | do | |
88 | i = wait(&status); | |
89 | while (i != pid && i != -1); | |
90 | if (i == -1 || (status & 0377)) | |
91 | onintr(); | |
92 | if (status != 0) { | |
93 | if ((status >> 8) == ERRS) | |
94 | write(2, "Execution suppressed due to compilation errors\n", 47); | |
95 | onintr(); | |
96 | } | |
97 | ac--; | |
b2877e66 KM |
98 | argv[ac] = name; |
99 | ac--; | |
100 | argv[ac] = "pix"; | |
134fe9f6 | 101 | argv[argc] = 0; |
134fe9f6 | 102 | do |
aa6c84c4 | 103 | execv(px_debug, &argv[ac]); |
134fe9f6 BJ |
104 | while (errno == ETXTBSY); |
105 | write(2, "Can't find px\n", 14); | |
106 | onintr(); | |
107 | } | |
108 | ||
109 | dotted(cp, ch) | |
110 | char *cp, ch; | |
111 | { | |
112 | register int i; | |
113 | ||
114 | i = strlen(cp); | |
115 | return (i > 1 && cp[i - 2] == '.' && cp[i - 1] == ch); | |
116 | } | |
117 | ||
118 | onintr() | |
119 | { | |
120 | ||
121 | signal(2, 1); | |
122 | unlink(name); | |
123 | exit(1); | |
124 | } |