BSD 4_3_Tahoe release
[unix-history] / usr / src / ucb / pascal / utilities / pc.c
index 14371e3..35fd11e 100644 (file)
@@ -1,8 +1,23 @@
-static char sccsid[] = "@(#)pc.c 3.20 2/3/83";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)pc.c       5.3 (Berkeley) 5/8/87";
+#endif not lint
 
 #include <stdio.h>
 #include <signal.h>
 
 #include <stdio.h>
 #include <signal.h>
-#include <wait.h>
+#include <sys/param.h>
+#include <sys/wait.h>
 
 /*
  * Pc - front end for Pascal compiler.
 
 /*
  * Pc - front end for Pascal compiler.
@@ -20,12 +35,14 @@ char        *mcrt0 = "/lib/mcrt0.o";
 char   *gcrt0 = "/usr/lib/gcrt0.o";
 
 char   *mktemp();
 char   *gcrt0 = "/usr/lib/gcrt0.o";
 
 char   *mktemp();
+char   *tmpdir = "/tmp";
+char   tmp0[MAXPATHLEN], tmp1[MAXPATHLEN];
 char   *tname[2];
 char   *tfile[2];
 
 char   *setsuf(), *savestr();
 
 char   *tname[2];
 char   *tfile[2];
 
 char   *setsuf(), *savestr();
 
-int    Jflag, Sflag, Oflag, Tlflag, cflag, gflag, pflag, wflag;
+int    Jflag, Sflag, Oflag, Tlflag, cflag, gflag, pflag, wflag, tflag;
 int    debug;
 
 #define        NARGS   512
 int    debug;
 
 #define        NARGS   512
@@ -40,8 +57,10 @@ int  pc3argx = 1;
 #define        ldargs  pc0args
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
 /* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
 #define        ldargs  pc0args
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
 /* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
+
+                               /* as -J -t tmpdir -o objfile srcfile \0 */
 int    asargx;
 int    asargx;
-char   *asargs[6] =            { "as", 0, };
+char   *asargs[8] =            { "as", 0, };
 
 char *mesg[] = {
        0,
 
 char *mesg[] = {
        0,
@@ -144,6 +163,23 @@ main(argc, argv)
                                exit(1);
                        }
                        continue;
                                exit(1);
                        }
                        continue;
+               case 't':
+                       i++;
+                       if (i == argc) {
+                               fprintf(stderr, "pc: -t but no directory\n");
+                               exit(1);
+                       }
+                       if (argp[2] != '\0') {
+                               fprintf(stderr, "pc: bad -t option\n");
+                               exit(1);
+                       }
+                       tmpdir = argv[i];
+                       if (tmpdir[0] == '-') {
+                               fprintf(stderr, "pc: bad -t option\n");
+                               exit(1);
+                       }
+                       tflag = 1;
+                       continue;
                case 'O':
                        Oflag = 1;
                        continue;
                case 'O':
                        Oflag = 1;
                        continue;
@@ -210,9 +246,6 @@ main(argc, argv)
                        gflag = 1;
                        pc0args[pc0argx++] = argp;
                        continue;
                        gflag = 1;
                        pc0args[pc0argx++] = argp;
                        continue;
-               case 't':
-                       fprintf(stderr, "pc: -t is default; -C for checking\n");
-                       continue;
                case 'p':
                        if (argp[2] == 'g')
                                crt0 = gcrt0;
                case 'p':
                        if (argp[2] == 'g')
                                crt0 = gcrt0;
@@ -228,8 +261,10 @@ main(argc, argv)
                fprintf(stderr, "pc: warning: -g overrides -O\n");
                Oflag = 0;
        }
                fprintf(stderr, "pc: warning: -g overrides -O\n");
                Oflag = 0;
        }
-       tname[0] = mktemp("/tmp/p0XXXXXX");
-       tname[1] = mktemp("/tmp/p1XXXXXX");
+       sprintf(tmp0, "%s/%s", tmpdir, "p0XXXXXX");
+       tname[0] = mktemp(tmp0);
+       sprintf(tmp1, "%s/%s", tmpdir, "p1XXXXXX");
+       tname[1] = mktemp(tmp1);
        savargx = pc0argx;
        for (i = 0; i < argc; i++) {
                argp = argv[i];
        savargx = pc0argx;
        for (i = 0; i < argc; i++) {
                argp = argv[i];
@@ -239,6 +274,12 @@ main(argc, argv)
                        asargx = 1;
                        if (Jflag)
                                asargs[asargx++] = "-J";
                        asargx = 1;
                        if (Jflag)
                                asargs[asargx++] = "-J";
+#                      if defined(vax) || defined(tahoe)
+                               if (tflag) {
+                                       asargs[asargx++] = "-t";
+                                       asargs[asargx++] = tmpdir;
+                               }
+#                      endif vax || tahoe
                        asargs[asargx++] = argp;
                        asargs[asargx++] = "-o";
                        tfile[1] = setsuf(argp, 'o');
                        asargs[asargx++] = argp;
                        asargs[asargx++] = "-o";
                        tfile[1] = setsuf(argp, 'o');
@@ -256,6 +297,8 @@ main(argc, argv)
                pc0argx = savargx;
                if (pflag)
                        pc0args[pc0argx++] = "-p";
                pc0argx = savargx;
                if (pflag)
                        pc0args[pc0argx++] = "-p";
+               if (Jflag)
+                       pc0args[pc0argx++] = "-J";
                pc0args[pc0argx++] = argp;
                pc0args[pc0argx] = 0;
                if (dosys(pc0, pc0args, 0, 0))
                pc0args[pc0argx++] = argp;
                pc0args[pc0argx] = 0;
                if (dosys(pc0, pc0args, 0, 0))
@@ -286,6 +329,12 @@ main(argc, argv)
                asargx = 1;
                if (Jflag)
                        asargs[asargx++] = "-J";
                asargx = 1;
                if (Jflag)
                        asargs[asargx++] = "-J";
+#              if defined(vax) || defined(tahoe)
+                       if (tflag) {
+                               asargs[asargx++] = "-t";
+                               asargs[asargx++] = tmpdir;
+                       }
+#              endif vax || tahoe
                asargs[asargx++] = tfile[0];
                asargs[asargx++] = "-o";
                tfile[1] = setsuf(argp, 'o');
                asargs[asargx++] = tfile[0];
                asargs[asargx++] = "-o";
                tfile[1] = setsuf(argp, 'o');
@@ -373,6 +422,9 @@ duplicate:
                        if (argp[2])
                                ldargs[ldargx++] = argp;
                        continue;
                        if (argp[2])
                                ldargs[ldargx++] = argp;
                        continue;
+               case 't':
+                       i++;
+                       continue;
                case 'c':
                case 'g':
                case 'w':
                case 'c':
                case 'g':
                case 'w':
@@ -398,13 +450,8 @@ duplicate:
                ldargs[ldargx++] = "-lm_p";
                ldargs[ldargx++] = "-lc_p";
        } else {
                ldargs[ldargx++] = "-lm_p";
                ldargs[ldargx++] = "-lc_p";
        } else {
-#ifndef sun
                ldargs[ldargx++] = "-lm";
                ldargs[ldargx++] = "-lc";
                ldargs[ldargx++] = "-lm";
                ldargs[ldargx++] = "-lc";
-#else
-               ldargs[ldargx++] = "-lMm";
-               ldargs[ldargx++] = "-lMc";
-#endif
        }
        ldargs[ldargx] = 0;
        if (dosys(ld, ldargs, 0, 0)==0 && np == 1 && nxo == 0)
        }
        ldargs[ldargx] = 0;
        if (dosys(ld, ldargs, 0, 0)==0 && np == 1 && nxo == 0)
@@ -429,7 +476,11 @@ dosys(cmd, argv, in, out)
                        printf(" >%s", out);
                printf("\n");
        }
                        printf(" >%s", out);
                printf("\n");
        }
-       pid = vfork();
+       /*
+        * warning: vfork doesn't work here, because the call to signal() 
+        * done by the child process destroys the parent's SIGINT handler.
+        */
+       pid = fork();
        if (pid < 0) {
                fprintf(stderr, "pc: No more processes\n");
                done();
        if (pid < 0) {
                fprintf(stderr, "pc: No more processes\n");
                done();