Commit | Line | Data |
---|---|---|
0f4556f1 | 1 | char *xxxvers[] = "\n@(#) XF77 DRIVER, VERSION 0.04.1, 1983 MAY 12\n"; |
47621762 BJ |
2 | #include <stdio.h> |
3 | #include <ctype.h> | |
0f4556f1 C |
4 | #include "defines.h" |
5 | #include "machdefs.h" | |
6 | #include "drivedefs.h" | |
7 | #include "version.h" | |
47621762 BJ |
8 | #include <signal.h> |
9 | ||
10 | static FILEP diagfile = {stderr} ; | |
11 | static int pid; | |
12 | static int sigivalue = 0; | |
13 | static int sigqvalue = 0; | |
14 | static int sighvalue = 0; | |
15 | static int sigtvalue = 0; | |
16 | ||
17 | static char *pass1name = PASS1NAME ; | |
18 | static char *pass2name = PASS2NAME ; | |
0f4556f1 | 19 | static char *pass2opt = PASS2OPT ; |
47621762 BJ |
20 | static char *asmname = ASMNAME ; |
21 | static char *ldname = LDNAME ; | |
22 | static char *footname = FOOTNAME; | |
23 | static char *proffoot = PROFFOOT; | |
24 | static char *macroname = "m4"; | |
25 | static char *shellname = "/bin/sh"; | |
0f4556f1 | 26 | static char *cppname = "/lib/cpp"; |
47621762 | 27 | static char *aoutname = "a.out" ; |
31cef89c | 28 | static char *temppref = TEMPPREF; |
47621762 BJ |
29 | |
30 | static char *infname; | |
4b9ccde7 C |
31 | static char textfname[44]; |
32 | static char asmfname[44]; | |
33 | static char asmpass2[44]; | |
34 | static char initfname[44]; | |
35 | static char sortfname[44]; | |
36 | static char prepfname[44]; | |
37 | static char objfdefault[44]; | |
38 | static char optzfname[44]; | |
39 | static char setfname[44]; | |
47621762 BJ |
40 | |
41 | static char fflags[50] = "-"; | |
31cef89c BJ |
42 | static char cflags[50] = "-c"; |
43 | #if TARGET == GCOS | |
44 | static char eflags[30] = "system=gcos "; | |
45 | #else | |
46 | static char eflags[30] = "system=unix "; | |
47 | #endif | |
47621762 BJ |
48 | static char rflags[30] = ""; |
49 | static char lflag[3] = "-x"; | |
50 | static char *fflagp = fflags+1; | |
51 | static char *cflagp = cflags+2; | |
31cef89c | 52 | static char *eflagp = eflags+12; |
47621762 | 53 | static char *rflagp = rflags; |
0f4556f1 C |
54 | static char *cppflags = ""; |
55 | static char **cppargs; | |
47621762 BJ |
56 | static char **loadargs; |
57 | static char **loadp; | |
58 | ||
59 | static flag erred = NO; | |
60 | static flag loadflag = YES; | |
61 | static flag saveasmflag = NO; | |
62 | static flag profileflag = NO; | |
63 | static flag optimflag = NO; | |
64 | static flag debugflag = NO; | |
65 | static flag verbose = NO; | |
66 | static flag nofloating = NO; | |
67 | static flag fortonly = NO; | |
68 | static flag macroflag = NO; | |
31cef89c BJ |
69 | static flag sdbflag = NO; |
70 | ||
0f4556f1 | 71 | static int ncpp; |
47621762 BJ |
72 | |
73 | \f | |
74 | main(argc, argv) | |
75 | int argc; | |
76 | char **argv; | |
77 | { | |
78 | int i, c, status; | |
0f4556f1 | 79 | char *setdoto(), *lastchar(), *lastfield(), *copys(), *argvtos(); |
47621762 BJ |
80 | ptr ckalloc(); |
81 | register char *s; | |
82 | char fortfile[20], *t; | |
83 | char buff[100]; | |
84 | int intrupt(); | |
85 | ||
86 | sigivalue = (int) signal(SIGINT, SIG_IGN) & 01; | |
87 | sigqvalue = (int) signal(SIGQUIT,SIG_IGN) & 01; | |
88 | sighvalue = (int) signal(SIGHUP, SIG_IGN) & 01; | |
89 | sigtvalue = (int) signal(SIGTERM,SIG_IGN) & 01; | |
90 | enbint(intrupt); | |
91 | ||
92 | pid = getpid(); | |
93 | crfnames(); | |
94 | ||
0f4556f1 | 95 | cppargs = (char **) ckalloc( argc * sizeof(*cppargs) ); |
47621762 BJ |
96 | loadargs = (char **) ckalloc( (argc+20) * sizeof(*loadargs) ); |
97 | loadargs[1] = "-X"; | |
98 | loadargs[2] = "-u"; | |
99 | #if HERE==PDP11 || HERE==VAX | |
0f4556f1 | 100 | loadargs[3] = "_MAIN_"; |
47621762 BJ |
101 | #endif |
102 | #if HERE == INTERDATA | |
103 | loadargs[3] = "main"; | |
104 | #endif | |
105 | loadp = loadargs + 4; | |
106 | ||
107 | --argc; | |
108 | ++argv; | |
109 | ||
110 | while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0') | |
111 | { | |
112 | for(s = argv[0]+1 ; *s ; ++s) switch(*s) | |
113 | { | |
114 | case 'T': /* use special passes */ | |
115 | switch(*++s) | |
116 | { | |
117 | case '1': | |
118 | pass1name = s+1; goto endfor; | |
119 | case '2': | |
120 | pass2name = s+1; goto endfor; | |
0f4556f1 C |
121 | case 'p': |
122 | pass2opt = s+1; goto endfor; | |
47621762 BJ |
123 | case 'a': |
124 | asmname = s+1; goto endfor; | |
125 | case 'l': | |
126 | ldname = s+1; goto endfor; | |
127 | case 'F': | |
128 | footname = s+1; goto endfor; | |
129 | case 'm': | |
130 | macroname = s+1; goto endfor; | |
31cef89c BJ |
131 | case 't': |
132 | temppref = s+1; goto endfor; | |
47621762 BJ |
133 | default: |
134 | fatali("bad option -T%c", *s); | |
135 | } | |
136 | break; | |
137 | ||
138 | case '6': | |
139 | if(s[1]=='6') | |
140 | { | |
141 | *fflagp++ = *s++; | |
142 | goto copyfflag; | |
143 | } | |
144 | else { | |
145 | fprintf(diagfile, "invalid flag 6%c\n", s[1]); | |
146 | done(1); | |
147 | } | |
148 | ||
149 | case 'w': | |
150 | if(s[1]=='6' && s[2]=='6') | |
151 | { | |
152 | *fflagp++ = *s++; | |
153 | *fflagp++ = *s++; | |
154 | } | |
155 | ||
156 | copyfflag: | |
157 | case 'u': | |
158 | case 'U': | |
47621762 BJ |
159 | case '1': |
160 | case 'C': | |
47621762 BJ |
161 | *fflagp++ = *s; |
162 | break; | |
163 | ||
164 | case 'O': | |
165 | optimflag = YES; | |
166 | #if TARGET == INTERDATA | |
167 | *loadp++ = "-r"; | |
168 | *loadp++ = "-d"; | |
169 | #endif | |
170 | *fflagp++ = 'O'; | |
47621762 BJ |
171 | break; |
172 | ||
173 | case 'N': | |
174 | *fflagp++ = 'N'; | |
175 | if( oneof(*++s, "qxscn") ) | |
176 | *fflagp++ = *s++; | |
177 | else { | |
178 | fprintf(diagfile, "invalid flag -N%c\n", *s); | |
179 | done(1); | |
180 | } | |
181 | while( isdigit(*s) ) | |
182 | *fflagp++ = *s++; | |
183 | *fflagp++ = 'X'; | |
184 | goto endfor; | |
185 | ||
186 | case 'm': | |
187 | if(s[1] == '4') | |
188 | ++s; | |
189 | macroflag = YES; | |
190 | break; | |
191 | ||
192 | case 'S': | |
31cef89c | 193 | strcat(cflags, " -S"); |
47621762 BJ |
194 | saveasmflag = YES; |
195 | ||
196 | case 'c': | |
197 | loadflag = NO; | |
198 | break; | |
199 | ||
200 | case 'v': | |
201 | verbose = YES; | |
0f4556f1 C |
202 | fprintf(diagfile,"\nBerkeley F77, version %s\n", |
203 | VERSIONNUMBER); | |
47621762 BJ |
204 | break; |
205 | ||
206 | case 'd': | |
207 | debugflag = YES; | |
0f4556f1 C |
208 | *fflagp++ = 'd'; |
209 | s++; | |
210 | while( isdigit(*s) || *s == ',' ) | |
211 | *fflagp++ = *s++; | |
212 | *fflagp++ = 'X'; | |
213 | goto endfor; | |
47621762 | 214 | |
31cef89c BJ |
215 | case 'M': |
216 | *loadp++ = "-M"; | |
217 | break; | |
218 | ||
219 | case 'g': | |
220 | strcat(cflags," -g"); | |
221 | sdbflag = YES; | |
222 | goto copyfflag; | |
223 | ||
47621762 BJ |
224 | case 'p': |
225 | profileflag = YES; | |
31cef89c | 226 | strcat(cflags," -p"); |
e804469b C |
227 | *fflagp++ = 'p'; |
228 | if(s[1] == 'g') | |
229 | { | |
230 | proffoot = GPRFFOOT; | |
231 | s++; | |
232 | } | |
233 | break; | |
47621762 BJ |
234 | |
235 | case 'o': | |
236 | if( ! strcmp(s, "onetrip") ) | |
237 | { | |
238 | *fflagp++ = '1'; | |
239 | goto endfor; | |
240 | } | |
241 | aoutname = *++argv; | |
242 | --argc; | |
243 | break; | |
244 | ||
245 | #if TARGET == PDP11 | |
246 | case 'f': | |
247 | nofloating = YES; | |
248 | pass2name = NOFLPASS2; | |
249 | break; | |
250 | #endif | |
251 | ||
252 | case 'F': | |
253 | fortonly = YES; | |
254 | loadflag = NO; | |
255 | break; | |
0f4556f1 | 256 | case 'D': |
47621762 | 257 | case 'I': |
0f4556f1 C |
258 | cppargs[ncpp++] = *argv; |
259 | goto endfor; | |
260 | ||
261 | case 'i': | |
262 | if(s[1]=='2' || s[1]=='4') | |
47621762 BJ |
263 | { |
264 | *fflagp++ = *s++; | |
265 | goto copyfflag; | |
266 | } | |
0f4556f1 | 267 | fprintf(diagfile, "invalid flag -i%c\n", s[1]); |
47621762 BJ |
268 | done(1); |
269 | ||
270 | case 'l': /* letter ell--library */ | |
271 | s[-1] = '-'; | |
272 | *loadp++ = s-1; | |
273 | goto endfor; | |
274 | ||
275 | case 'E': /* EFL flag argument */ | |
276 | while( *eflagp++ = *++s) | |
277 | ; | |
278 | *eflagp++ = ' '; | |
279 | goto endfor; | |
280 | case 'R': | |
281 | while( *rflagp++ = *++s ) | |
282 | ; | |
283 | *rflagp++ = ' '; | |
284 | goto endfor; | |
285 | default: | |
286 | lflag[1] = *s; | |
287 | *loadp++ = copys(lflag); | |
288 | break; | |
289 | } | |
290 | endfor: | |
291 | --argc; | |
292 | ++argv; | |
293 | } | |
294 | ||
295 | *fflagp = '\0'; | |
296 | ||
0f4556f1 C |
297 | if (ncpp > 0) |
298 | cppflags = argvtos (ncpp,cppargs); | |
299 | ||
47621762 BJ |
300 | loadargs[0] = ldname; |
301 | #if TARGET == PDP11 | |
302 | if(nofloating) | |
303 | *loadp++ = (profileflag ? NOFLPROF : NOFLFOOT); | |
304 | else | |
305 | #endif | |
306 | *loadp++ = (profileflag ? proffoot : footname); | |
307 | ||
308 | for(i = 0 ; i<argc ; ++i) | |
309 | switch(c = dotchar(infname = argv[i]) ) | |
310 | { | |
311 | case 'r': /* Ratfor file */ | |
312 | case 'e': /* EFL file */ | |
313 | if( unreadable(argv[i]) ) | |
314 | { | |
315 | erred = YES; | |
316 | break; | |
317 | } | |
318 | s = fortfile; | |
319 | t = lastfield(argv[i]); | |
320 | while( *s++ = *t++) | |
321 | ; | |
322 | s[-2] = 'f'; | |
323 | ||
324 | if(macroflag) | |
325 | { | |
326 | sprintf(buff, "%s %s >%s", macroname, infname, prepfname); | |
327 | if( sys(buff) ) | |
328 | { | |
329 | rmf(prepfname); | |
330 | erred = YES; | |
331 | break; | |
332 | } | |
333 | infname = prepfname; | |
334 | } | |
335 | ||
336 | if(c == 'e') | |
337 | sprintf(buff, "efl %s %s >%s", eflags, infname, fortfile); | |
338 | else | |
339 | sprintf(buff, "ratfor %s %s >%s", rflags, infname, fortfile); | |
340 | status = sys(buff); | |
341 | if(macroflag) | |
342 | rmf(infname); | |
343 | if(status) | |
344 | { | |
345 | erred = YES; | |
346 | rmf(fortfile); | |
347 | break; | |
348 | } | |
349 | ||
350 | if( ! fortonly ) | |
351 | { | |
352 | infname = argv[i] = lastfield(argv[i]); | |
353 | *lastchar(infname) = 'f'; | |
354 | ||
355 | if( dofort(argv[i]) ) | |
356 | erred = YES; | |
357 | else { | |
358 | if( nodup(t = setdoto(argv[i])) ) | |
359 | *loadp++ = t; | |
360 | rmf(fortfile); | |
361 | } | |
362 | } | |
363 | break; | |
364 | ||
0f4556f1 C |
365 | case 'F': /* C preprocessor -> Fortran file */ |
366 | if( unreadable(argv[i]) ) | |
367 | { | |
368 | erred = YES; | |
369 | break; | |
370 | } | |
371 | s = fortfile; | |
372 | t = lastfield(argv[i]); | |
373 | while( *s++ = *t++) | |
374 | ; | |
375 | s[-2] = 'f'; | |
376 | sprintf(buff,"%s %s %s >%s", cppname, cppflags, infname, fortfile); | |
377 | status = sys(buff); | |
378 | if(status) | |
379 | { | |
380 | erred = YES; | |
381 | rmf(fortfile); | |
382 | break; | |
383 | } | |
384 | ||
385 | if( ! fortonly ) | |
386 | { | |
387 | infname = argv[i] = lastfield(argv[i]); | |
388 | *lastchar(infname) = 'f'; | |
389 | ||
390 | if ( dofort(argv[i]) ) | |
391 | erred = YES; | |
392 | else { | |
393 | if (nodup(t = setdoto(argv[i])) ) | |
394 | *loadp++ = t; | |
395 | rmf(fortfile); | |
396 | } | |
397 | } | |
398 | break; | |
399 | ||
47621762 | 400 | case 'f': /* Fortran file */ |
47621762 BJ |
401 | if( unreadable(argv[i]) ) |
402 | erred = YES; | |
403 | else if( dofort(argv[i]) ) | |
404 | erred = YES; | |
405 | else if( nodup(t=setdoto(argv[i])) ) | |
406 | *loadp++ = t; | |
407 | break; | |
408 | ||
409 | case 'c': /* C file */ | |
410 | case 's': /* Assembler file */ | |
411 | if( unreadable(argv[i]) ) | |
412 | { | |
413 | erred = YES; | |
414 | break; | |
415 | } | |
416 | #if HERE==PDP11 || HERE==VAX | |
417 | fprintf(diagfile, "%s:\n", argv[i]); | |
418 | #endif | |
31cef89c | 419 | sprintf(buff, "cc %s %s", cflags, argv[i] ); |
47621762 BJ |
420 | if( sys(buff) ) |
421 | erred = YES; | |
422 | else | |
423 | if( nodup(t = setdoto(argv[i])) ) | |
424 | *loadp++ = t; | |
425 | break; | |
426 | ||
427 | case 'o': | |
428 | if( nodup(argv[i]) ) | |
429 | *loadp++ = argv[i]; | |
430 | break; | |
431 | ||
432 | default: | |
433 | if( ! strcmp(argv[i], "-o") ) | |
434 | aoutname = argv[++i]; | |
435 | else | |
436 | *loadp++ = argv[i]; | |
437 | break; | |
438 | } | |
439 | ||
440 | if(loadflag && !erred) | |
441 | doload(loadargs, loadp); | |
442 | done(erred); | |
443 | } | |
0f4556f1 C |
444 | |
445 | ||
446 | ||
447 | /* | |
448 | * argvtos() copies a list of arguments contained in an array of character | |
449 | * strings to a single dynamically allocated string. Each argument is | |
450 | * separated by one blank space. Returns a pointer to the string or null | |
451 | * if out of memory. | |
452 | */ | |
453 | #define SBUFINCR 1024 | |
454 | #define SBUFMAX 10240 | |
455 | ||
456 | char * | |
457 | argvtos(argc, argv) | |
458 | char **argv; | |
459 | int argc; | |
460 | { | |
461 | register char *s; /* string pointer */ | |
462 | register int i; /* string buffer pointer */ | |
463 | char *malloc(); /* memory allocator */ | |
464 | char *realloc(); /* increase size of storage */ | |
465 | char *sbuf; /* string buffer */ | |
466 | int nbytes; /* bytes of memory required */ | |
467 | int nu; /* no. of SBUFINCR units required */ | |
468 | int sbufsize; /* current size of sbuf */ | |
469 | int strlen(); /* string length */ | |
470 | ||
471 | sbufsize = SBUFINCR; | |
472 | if ((sbuf = malloc((unsigned)sbufsize)) == NULL) | |
473 | { | |
474 | fatal("out of memory (argvtos)"); | |
475 | /* NOTREACHED */ | |
476 | } | |
477 | ||
478 | for (i = 0; argc-- > 0; ++argv) | |
479 | { | |
480 | if ((nbytes = (i+strlen(*argv)+1-sbufsize)) > 0) | |
481 | { | |
482 | nu = (nbytes+SBUFINCR-1)/SBUFINCR; | |
483 | sbufsize += nu * SBUFINCR; | |
484 | if (sbufsize > SBUFMAX) | |
485 | { | |
486 | fatal("argument length exceeded (argvtos)"); | |
487 | /* NOTREACHED */ | |
488 | } | |
489 | if ((sbuf = realloc(sbuf, (unsigned)sbufsize)) == NULL) | |
490 | { | |
491 | fatal("out of memory (argvtos)"); | |
492 | /* NOTREACHED */ | |
493 | } | |
494 | } | |
495 | for (s = *argv; *s != '\0'; i++, s++) | |
496 | sbuf[i] = *s; | |
497 | sbuf[i++] = ' '; | |
498 | } | |
499 | sbuf[--i] = '\0'; | |
500 | return(sbuf); | |
501 | } | |
47621762 BJ |
502 | \f |
503 | dofort(s) | |
504 | char *s; | |
505 | { | |
506 | int retcode; | |
507 | char buff[200]; | |
508 | ||
509 | infname = s; | |
510 | sprintf(buff, "%s %s %s %s %s %s", | |
511 | pass1name, fflags, s, asmfname, initfname, textfname); | |
512 | switch( sys(buff) ) | |
513 | { | |
514 | case 1: | |
515 | goto error; | |
516 | case 0: | |
517 | break; | |
518 | default: | |
519 | goto comperror; | |
520 | } | |
521 | ||
47621762 BJ |
522 | if( dopass2() ) |
523 | goto comperror; | |
524 | doasm(s); | |
525 | retcode = 0; | |
526 | ||
527 | ret: | |
528 | rmf(asmfname); | |
529 | rmf(initfname); | |
530 | rmf(textfname); | |
531 | return(retcode); | |
532 | ||
533 | error: | |
534 | fprintf(diagfile, "\nError. No assembly.\n"); | |
535 | retcode = 1; | |
536 | goto ret; | |
537 | ||
538 | comperror: | |
539 | fprintf(diagfile, "\ncompiler error.\n"); | |
540 | retcode = 2; | |
541 | goto ret; | |
542 | } | |
543 | ||
544 | ||
545 | ||
546 | ||
547 | dopass2() | |
548 | { | |
549 | char buff[100]; | |
550 | ||
551 | if(verbose) | |
552 | fprintf(diagfile, "PASS2."); | |
553 | ||
554 | #if FAMILY==DMR | |
555 | sprintf(buff, "%s %s - %s", pass2name, textfname, asmpass2); | |
556 | return( sys(buff) ); | |
557 | #endif | |
558 | ||
0f4556f1 | 559 | |
47621762 BJ |
560 | #if FAMILY == PCC |
561 | # if TARGET==INTERDATA | |
562 | sprintf(buff, "%s -A%s <%s >%s", pass2name, setfname, textfname, asmpass2); | |
563 | # else | |
31cef89c | 564 | sprintf(buff, "%s %s >%s", pass2name, textfname, asmpass2); |
47621762 BJ |
565 | # endif |
566 | return( sys(buff) ); | |
567 | #endif | |
568 | } | |
569 | ||
570 | ||
571 | ||
572 | ||
573 | doasm(s) | |
574 | char *s; | |
575 | { | |
576 | register char *lastc; | |
577 | char *obj; | |
578 | char buff[200]; | |
31cef89c | 579 | char *lastchar(), *setdoto(); |
47621762 BJ |
580 | |
581 | if(*s == '\0') | |
582 | s = objfdefault; | |
583 | lastc = lastchar(s); | |
584 | obj = setdoto(s); | |
585 | ||
586 | #if TARGET==PDP11 || TARGET==VAX | |
587 | # ifdef PASS2OPT | |
588 | if(optimflag) | |
589 | { | |
0f4556f1 | 590 | sprintf(buff, "%s %s %s", pass2opt, asmpass2, optzfname); |
47621762 BJ |
591 | if( sys(buff) ) |
592 | rmf(optzfname); | |
593 | else | |
594 | { | |
595 | sprintf(buff,"mv %s %s", optzfname, asmpass2); | |
596 | sys(buff); | |
597 | } | |
598 | } | |
599 | # endif | |
600 | #endif | |
601 | ||
602 | if(saveasmflag) | |
603 | { | |
604 | *lastc = 's'; | |
605 | #if TARGET == INTERDATA | |
0f4556f1 C |
606 | sprintf(buff, "cat %s %s %s %s >%s",asmfname, initfname, |
607 | setfname, asmpass2, obj); | |
47621762 | 608 | #else |
0f4556f1 C |
609 | #if TARGET == VAX |
610 | sprintf(buff, "cat %s %s %s >%s", asmfname, asmpass2, initfname, obj); | |
47621762 | 611 | #else |
0f4556f1 C |
612 | sprintf(buff, "cat %s %s %s >%s", asmfname, initfname, asmpass2, obj); |
613 | #endif | |
47621762 BJ |
614 | #endif |
615 | sys(buff); | |
616 | *lastc = 'o'; | |
617 | } | |
618 | else | |
619 | { | |
620 | if(verbose) | |
621 | fprintf(diagfile, " ASM."); | |
622 | #if TARGET == INTERDATA | |
0f4556f1 C |
623 | sprintf(buff, "%s -o %s %s %s %s %s", asmname, obj, asmfname, |
624 | initfname, setfname, asmpass2); | |
47621762 BJ |
625 | #endif |
626 | ||
627 | #if TARGET == VAX | |
628 | /* vax assembler currently accepts only one input file */ | |
0f4556f1 | 629 | sprintf(buff, "cat %s %s >>%s", asmpass2, initfname, asmfname); |
47621762 | 630 | sys(buff); |
0f4556f1 C |
631 | #ifdef UCBVAXASM |
632 | sprintf(buff, "%s -J -o %s %s", asmname, obj, asmfname); | |
633 | #else | |
47621762 BJ |
634 | sprintf(buff, "%s -o %s %s", asmname, obj, asmfname); |
635 | #endif | |
0f4556f1 | 636 | #endif |
47621762 BJ |
637 | |
638 | #if TARGET == PDP11 | |
639 | sprintf(buff, "%s -u -o %s %s %s", asmname, obj, asmfname, asmpass2); | |
640 | #endif | |
641 | ||
642 | #if TARGET!=INTERDATA && TARGET!=PDP11 && TARGET!=VAX | |
643 | sprintf(buff, "%s -o %s %s %s", asmname, obj, asmfname, asmpass2); | |
644 | #endif | |
645 | ||
646 | if( sys(buff) ) | |
647 | fatal("assembler error"); | |
648 | if(verbose) | |
649 | fprintf(diagfile, "\n"); | |
650 | #if HERE==PDP11 && TARGET!=PDP11 | |
651 | rmf(obj); | |
652 | #endif | |
653 | } | |
654 | ||
655 | rmf(asmpass2); | |
656 | } | |
657 | ||
658 | ||
659 | ||
660 | doload(v0, v) | |
661 | register char *v0[], *v[]; | |
662 | { | |
663 | char **p; | |
664 | int waitpid; | |
665 | ||
31cef89c BJ |
666 | if(sdbflag) |
667 | *v++ = "-lg"; | |
0f4556f1 C |
668 | if (profileflag) |
669 | { | |
670 | for(p = p_liblist ; *p ; *v++ = *p++) | |
671 | ; | |
672 | } | |
673 | else { | |
674 | for(p = liblist ; *p ; *v++ = *p++) | |
675 | ; | |
676 | } | |
47621762 BJ |
677 | |
678 | *v++ = "-o"; | |
679 | *v++ = aoutname; | |
680 | *v = NULL; | |
681 | ||
682 | if(verbose) | |
683 | fprintf(diagfile, "LOAD."); | |
684 | if(debugflag) | |
685 | { | |
686 | for(p = v0 ; p<v ; ++p) | |
687 | fprintf(diagfile, "%s ", *p); | |
688 | fprintf(diagfile, "\n"); | |
689 | } | |
690 | ||
691 | #if HERE==PDP11 || HERE==INTERDATA || HERE==VAX | |
692 | if( (waitpid = fork()) == 0) | |
693 | { | |
694 | enbint(SIG_DFL); | |
695 | execv(ldname, v0); | |
696 | fatalstr("couldn't load %s", ldname); | |
697 | } | |
698 | await(waitpid); | |
699 | #endif | |
700 | ||
701 | #if HERE==INTERDATA | |
702 | if(optimflag) | |
703 | { | |
704 | char buff1[100], buff2[100]; | |
705 | sprintf(buff1, "nopt %s -o junk.%d", aoutname, pid); | |
706 | sprintf(buff2, "mv junk.%d %s", pid, aoutname); | |
707 | if( sys(buff1) || sys(buff2) ) | |
708 | err("bad optimization"); | |
709 | } | |
710 | #endif | |
711 | ||
712 | if(verbose) | |
713 | fprintf(diagfile, "\n"); | |
714 | } | |
715 | \f | |
716 | /* Process control and Shell-simulating routines */ | |
717 | ||
718 | sys(str) | |
719 | char *str; | |
720 | { | |
721 | register char *s, *t; | |
722 | char *argv[100], path[100]; | |
723 | char *inname, *outname; | |
724 | int append; | |
725 | int waitpid; | |
726 | int argc; | |
727 | ||
728 | ||
729 | if(debugflag) | |
730 | fprintf(diagfile, "%s\n", str); | |
731 | inname = NULL; | |
732 | outname = NULL; | |
733 | argv[0] = shellname; | |
734 | argc = 1; | |
735 | ||
736 | t = str; | |
737 | while( isspace(*t) ) | |
738 | ++t; | |
739 | while(*t) | |
740 | { | |
741 | if(*t == '<') | |
742 | inname = t+1; | |
743 | else if(*t == '>') | |
744 | { | |
745 | if(t[1] == '>') | |
746 | { | |
747 | append = YES; | |
748 | outname = t+2; | |
749 | } | |
750 | else { | |
751 | append = NO; | |
752 | outname = t+1; | |
753 | } | |
754 | } | |
755 | else | |
756 | argv[argc++] = t; | |
757 | while( !isspace(*t) && *t!='\0' ) | |
758 | ++t; | |
759 | if(*t) | |
760 | { | |
761 | *t++ = '\0'; | |
762 | while( isspace(*t) ) | |
763 | ++t; | |
764 | } | |
765 | } | |
766 | ||
767 | if(argc == 1) /* no command */ | |
768 | return(-1); | |
769 | argv[argc] = 0; | |
770 | ||
771 | s = path; | |
772 | t = "/usr/bin/"; | |
773 | while(*t) | |
774 | *s++ = *t++; | |
775 | for(t = argv[1] ; *s++ = *t++ ; ) | |
776 | ; | |
777 | if((waitpid = fork()) == 0) | |
778 | { | |
779 | if(inname) | |
780 | freopen(inname, "r", stdin); | |
781 | if(outname) | |
782 | freopen(outname, (append ? "a" : "w"), stdout); | |
783 | enbint(SIG_DFL); | |
784 | ||
785 | texec(path+9, argv); /* command */ | |
786 | texec(path+4, argv); /* /bin/command */ | |
787 | texec(path , argv); /* /usr/bin/command */ | |
788 | ||
789 | fatalstr("Cannot load %s",path+9); | |
790 | } | |
791 | ||
792 | return( await(waitpid) ); | |
793 | } | |
794 | ||
795 | ||
796 | ||
797 | ||
798 | ||
799 | #include "errno.h" | |
800 | ||
801 | /* modified version from the Shell */ | |
802 | texec(f, av) | |
803 | char *f; | |
804 | char **av; | |
805 | { | |
806 | extern int errno; | |
807 | ||
808 | execv(f, av+1); | |
809 | ||
810 | if (errno==ENOEXEC) | |
811 | { | |
812 | av[1] = f; | |
813 | execv(shellname, av); | |
814 | fatal("No shell!"); | |
815 | } | |
816 | if (errno==ENOMEM) | |
817 | fatalstr("%s: too large", f); | |
818 | } | |
819 | ||
820 | ||
821 | ||
822 | ||
823 | ||
824 | ||
825 | done(k) | |
826 | int k; | |
827 | { | |
828 | static int recurs = NO; | |
829 | ||
830 | if(recurs == NO) | |
831 | { | |
832 | recurs = YES; | |
833 | rmfiles(); | |
834 | } | |
835 | exit(k); | |
836 | } | |
837 | ||
838 | ||
839 | ||
840 | ||
841 | ||
842 | ||
843 | enbint(k) | |
844 | int (*k)(); | |
845 | { | |
846 | if(sigivalue == 0) | |
847 | signal(SIGINT,k); | |
848 | if(sigqvalue == 0) | |
849 | signal(SIGQUIT,k); | |
850 | if(sighvalue == 0) | |
851 | signal(SIGHUP,k); | |
852 | if(sigtvalue == 0) | |
853 | signal(SIGTERM,k); | |
854 | } | |
855 | ||
856 | ||
857 | ||
858 | ||
859 | intrupt() | |
860 | { | |
861 | done(2); | |
862 | } | |
863 | ||
864 | ||
865 | ||
866 | await(waitpid) | |
867 | int waitpid; | |
868 | { | |
869 | int w, status; | |
870 | ||
871 | enbint(SIG_IGN); | |
872 | while ( (w = wait(&status)) != waitpid) | |
873 | if(w == -1) | |
874 | fatal("bad wait code"); | |
875 | enbint(intrupt); | |
876 | if(status & 0377) | |
877 | { | |
878 | if(status != SIGINT) | |
0f4556f1 | 879 | fprintf(diagfile, "Termination code %d\n", status); |
47621762 BJ |
880 | done(3); |
881 | } | |
882 | return(status>>8); | |
883 | } | |
884 | \f | |
885 | /* File Name and File Manipulation Routines */ | |
886 | ||
887 | unreadable(s) | |
888 | register char *s; | |
889 | { | |
890 | register FILE *fp; | |
891 | ||
892 | if(fp = fopen(s, "r")) | |
893 | { | |
894 | fclose(fp); | |
895 | return(NO); | |
896 | } | |
897 | ||
898 | else | |
899 | { | |
900 | fprintf(diagfile, "Error: Cannot read file %s\n", s); | |
901 | return(YES); | |
902 | } | |
903 | } | |
904 | ||
905 | ||
906 | ||
907 | clf(p) | |
908 | FILEP *p; | |
909 | { | |
910 | if(p!=NULL && *p!=NULL && *p!=stdout) | |
911 | { | |
912 | if(ferror(*p)) | |
913 | fatal("writing error"); | |
914 | fclose(*p); | |
915 | } | |
916 | *p = NULL; | |
917 | } | |
918 | ||
919 | rmfiles() | |
920 | { | |
921 | rmf(textfname); | |
922 | rmf(asmfname); | |
923 | rmf(initfname); | |
924 | rmf(asmpass2); | |
925 | #if TARGET == INTERDATA | |
926 | rmf(setfname); | |
927 | #endif | |
928 | } | |
929 | ||
930 | ||
931 | ||
932 | ||
933 | ||
934 | ||
935 | ||
936 | ||
937 | /* return -1 if file does not exist, 0 if it is of zero length | |
938 | and 1 if of positive length | |
939 | */ | |
940 | content(filename) | |
941 | char *filename; | |
942 | { | |
943 | #ifdef VERSION6 | |
944 | struct stat | |
945 | { | |
946 | char cjunk[9]; | |
947 | char size0; | |
948 | int size1; | |
949 | int ijunk[12]; | |
950 | } buf; | |
951 | #else | |
952 | # include <sys/types.h> | |
953 | # include <sys/stat.h> | |
954 | struct stat buf; | |
955 | #endif | |
956 | ||
957 | if(stat(filename,&buf) < 0) | |
958 | return(-1); | |
959 | #ifdef VERSION6 | |
960 | return(buf.size0 || buf.size1); | |
961 | #else | |
962 | return( buf.st_size > 0 ); | |
963 | #endif | |
964 | } | |
965 | ||
966 | ||
967 | ||
968 | ||
969 | crfnames() | |
970 | { | |
971 | fname(textfname, "x"); | |
972 | fname(asmfname, "s"); | |
973 | fname(asmpass2, "a"); | |
974 | fname(initfname, "d"); | |
975 | fname(sortfname, "S"); | |
976 | fname(objfdefault, "o"); | |
977 | fname(prepfname, "p"); | |
978 | fname(optzfname, "z"); | |
979 | fname(setfname, "A"); | |
980 | } | |
981 | ||
982 | ||
983 | ||
984 | ||
985 | rmf(fn) | |
986 | register char *fn; | |
987 | { | |
0f4556f1 C |
988 | /* if(!debugflag && fn!=NULL && *fn!='\0') */ |
989 | ||
990 | if(fn!=NULL && *fn!='\0') | |
47621762 BJ |
991 | unlink(fn); |
992 | } | |
993 | ||
994 | ||
995 | ||
996 | ||
997 | ||
998 | LOCAL fname(name, suff) | |
999 | char *name, *suff; | |
1000 | { | |
4b9ccde7 | 1001 | sprintf(name, "/tmp/%s%d.%s", temppref, pid, suff); |
47621762 BJ |
1002 | } |
1003 | ||
1004 | ||
1005 | ||
1006 | ||
1007 | dotchar(s) | |
1008 | register char *s; | |
1009 | { | |
1010 | for( ; *s ; ++s) | |
1011 | if(s[0]=='.' && s[1]!='\0' && s[2]=='\0') | |
1012 | return( s[1] ); | |
1013 | return(NO); | |
1014 | } | |
1015 | ||
1016 | ||
1017 | ||
1018 | char *lastfield(s) | |
1019 | register char *s; | |
1020 | { | |
1021 | register char *t; | |
1022 | for(t = s; *s ; ++s) | |
1023 | if(*s == '/') | |
1024 | t = s+1; | |
1025 | return(t); | |
1026 | } | |
1027 | ||
1028 | ||
1029 | ||
1030 | char *lastchar(s) | |
1031 | register char *s; | |
1032 | { | |
1033 | while(*s) | |
1034 | ++s; | |
1035 | return(s-1); | |
1036 | } | |
1037 | ||
1038 | char *setdoto(s) | |
1039 | register char *s; | |
1040 | { | |
1041 | *lastchar(s) = 'o'; | |
1042 | return( lastfield(s) ); | |
1043 | } | |
1044 | ||
1045 | ||
1046 | ||
1047 | badfile(s) | |
1048 | char *s; | |
1049 | { | |
1050 | fatalstr("cannot open intermediate file %s", s); | |
1051 | } | |
1052 | ||
1053 | ||
1054 | ||
1055 | ptr ckalloc(n) | |
1056 | int n; | |
1057 | { | |
1058 | ptr p, calloc(); | |
1059 | ||
1060 | if( p = calloc(1, (unsigned) n) ) | |
1061 | return(p); | |
1062 | ||
1063 | fatal("out of memory"); | |
1064 | /* NOTREACHED */ | |
1065 | } | |
1066 | ||
1067 | ||
1068 | ||
1069 | ||
1070 | ||
31cef89c | 1071 | char *copyn(n, s) |
47621762 BJ |
1072 | register int n; |
1073 | register char *s; | |
1074 | { | |
1075 | register char *p, *q; | |
1076 | ||
1077 | p = q = (char *) ckalloc(n); | |
1078 | while(n-- > 0) | |
1079 | *q++ = *s++; | |
1080 | return(p); | |
1081 | } | |
1082 | ||
1083 | ||
1084 | ||
31cef89c | 1085 | char *copys(s) |
47621762 BJ |
1086 | char *s; |
1087 | { | |
1088 | return( copyn( strlen(s)+1 , s) ); | |
1089 | } | |
1090 | ||
1091 | ||
1092 | ||
1093 | ||
1094 | ||
1095 | oneof(c,s) | |
1096 | register c; | |
1097 | register char *s; | |
1098 | { | |
1099 | while( *s ) | |
1100 | if(*s++ == c) | |
1101 | return(YES); | |
1102 | return(NO); | |
1103 | } | |
1104 | ||
1105 | ||
1106 | ||
1107 | nodup(s) | |
1108 | char *s; | |
1109 | { | |
1110 | register char **p; | |
1111 | ||
1112 | for(p = loadargs ; p < loadp ; ++p) | |
1113 | if( !strcmp(*p, s) ) | |
1114 | return(NO); | |
1115 | ||
1116 | return(YES); | |
1117 | } | |
1118 | ||
1119 | ||
1120 | ||
1121 | static fatal(t) | |
1122 | char *t; | |
1123 | { | |
1124 | fprintf(diagfile, "Compiler error in file %s: %s\n", infname, t); | |
1125 | if(debugflag) | |
1126 | abort(); | |
1127 | done(1); | |
1128 | exit(1); | |
1129 | } | |
1130 | ||
1131 | ||
1132 | ||
1133 | ||
1134 | static fatali(t,d) | |
1135 | char *t; | |
1136 | int d; | |
1137 | { | |
1138 | char buff[100]; | |
1139 | sprintf(buff, t, d); | |
1140 | fatal(buff); | |
1141 | } | |
1142 | ||
1143 | ||
1144 | ||
1145 | ||
1146 | static fatalstr(t, s) | |
1147 | char *t, *s; | |
1148 | { | |
1149 | char buff[100]; | |
1150 | sprintf(buff, t, s); | |
1151 | fatal(buff); | |
1152 | } | |
1153 | err(s) | |
1154 | char *s; | |
1155 | { | |
1156 | fprintf(diagfile, "Error in file %s: %s\n", infname, s); | |
1157 | } | |
47621762 | 1158 |