add the -t flag to use temporary files elsewhere.
[unix-history] / usr / src / usr.bin / pascal / pc / pc.c
index 583861f..f39a7e2 100644 (file)
@@ -1,7 +1,9 @@
-static char sccsid[] = "@(#)pc.c 3.9 %G%";
+static char sccsid[] = "@(#)pc.c 3.22 %G%";
+
 #include <stdio.h>
 #include <signal.h>
 #include <wait.h>
 #include <stdio.h>
 #include <signal.h>
 #include <wait.h>
+#include <sys/param.h>
 
 /*
  * Pc - front end for Pascal compiler.
 
 /*
  * Pc - front end for Pascal compiler.
@@ -16,14 +18,17 @@ char        *as = "/bin/as";
 char   *lpc = "-lpc";
 char   *crt0 = "/lib/crt0.o";
 char   *mcrt0 = "/lib/mcrt0.o";
 char   *lpc = "-lpc";
 char   *crt0 = "/lib/crt0.o";
 char   *mcrt0 = "/lib/mcrt0.o";
+char   *gcrt0 = "/usr/lib/gcrt0.o";
 
 char   *mktemp();
 
 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, cflag, gflag, pflag;
+int    Jflag, Sflag, Oflag, Tlflag, cflag, gflag, pflag, wflag, tflag;
 int    debug;
 
 #define        NARGS   512
 int    debug;
 
 #define        NARGS   512
@@ -38,8 +43,46 @@ 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,
+       "Hangup",
+       "Interrupt",    
+       "Quit",
+       "Illegal instruction",
+       "Trace/BPT trap",
+       "IOT trap",
+       "EMT trap",
+       "Floating exception",
+       "Killed",
+       "Bus error",
+       "Segmentation fault",
+       "Bad system call",
+       "Broken pipe",
+       "Alarm clock",
+       "Terminated",
+       "Signal 16",
+       "Stopped (signal)",
+       "Stopped",
+       "Continued",
+       "Child exited",
+       "Stopped (tty input)",
+       "Stopped (tty output)",
+       "Tty input interrupt",
+       "Cputime limit exceeded",
+       "Filesize limit exceeded",
+       "Signal 26",
+       "Signal 27",
+       "Signal 28",
+       "Signal 29",
+       "Signal 30",
+       "Signal 31",
+       "Signal 32"
+};
 
 /*
  * If the number of .p arguments (np) is 1, and the number of .o arguments
 
 /*
  * If the number of .p arguments (np) is 1, and the number of .o arguments
@@ -106,6 +149,15 @@ 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);
+                       }
+                       tmpdir = argv[i];
+                       tflag = 1;
+                       continue;
                case 'O':
                        Oflag = 1;
                        continue;
                case 'O':
                        Oflag = 1;
                        continue;
@@ -119,19 +171,35 @@ main(argc, argv)
                        switch (argp[2]) {
 
                        case '0':
                        switch (argp[2]) {
 
                        case '0':
-                               pc0 = "/usr/src/cmd/pc0/a.out";
+                               pc0 = "/usr/src/ucb/pascal/pc0/a.out";
+                               if (argp[3] != '\0') {
+                                       pc0 = &argp[3];
+                               }
                                continue;
                        case '1':
                                continue;
                        case '1':
-                               pc1 = "/usr/src/cmd/pcc/pc1";
+                               pc1 = "/usr/src/lib/pcc/fort";
+                               if (argp[3] != '\0') {
+                                       pc1 = &argp[3];
+                               }
                                continue;
                        case '2':
                                continue;
                        case '2':
-                               pc2 = "/usr/src/cmd/pc2/a.out";
+                               pc2 = "/usr/src/ucb/pascal/utilities/pc2";
+                               if (argp[3] != '\0') {
+                                       pc2 = &argp[3];
+                               }
                                continue;
                        case '3':
                                continue;
                        case '3':
-                               pc3 = "/usr/src/cmd/pc3/a.out";
+                               pc3 = "/usr/src/ucb/pascal/utilities/pc3";
+                               if (argp[3] != '\0') {
+                                       pc3 = &argp[3];
+                               }
                                continue;
                        case 'l':
                                continue;
                        case 'l':
-                               lpc = "/usr/src/lib/libpc/libpc";
+                               Tlflag = 1;
+                               lpc = "/usr/src/usr.lib/libpc/libpc";
+                               if (argp[3] != '\0') {
+                                       lpc = &argp[3];
+                               }
                                continue;
                        }
                        continue;
                                continue;
                        }
                        continue;
@@ -143,21 +211,27 @@ main(argc, argv)
                                continue;
                        /* fall into ... */
                case 'b':
                                continue;
                        /* fall into ... */
                case 'b':
-               case 'g':
                case 's':
                case 's':
-               case 'w':
                case 'z':
                case 'C':
                        pc0args[pc0argx++] = argp;
                case 'z':
                case 'C':
                        pc0args[pc0argx++] = argp;
-                       if (argp[1] == 'g')
-                               gflag = 1;
                        continue;
                        continue;
-               case 't':
-                       fprintf(stderr, "pc: -t is default; -C for checking\n");
+               case 'w':
+                       wflag = 1;
+                       pc0args[pc0argx++] = argp;
+                       continue;
+               case 'g':
+                       gflag = 1;
+                       pc0args[pc0argx++] = argp;
                        continue;
                case 'p':
                        continue;
                case 'p':
-                       crt0 = mcrt0;
-                       pflag++;
+                       if (argp[2] == 'g')
+                               crt0 = gcrt0;
+                       else
+                               crt0 = mcrt0;
+                       if (!Tlflag)
+                               lpc = "-lpc_p";
+                       pflag = 1;
                        continue;
                }
        }
                        continue;
                }
        }
@@ -165,8 +239,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];
@@ -176,6 +252,12 @@ main(argc, argv)
                        asargx = 1;
                        if (Jflag)
                                asargs[asargx++] = "-J";
                        asargx = 1;
                        if (Jflag)
                                asargs[asargx++] = "-J";
+#                      ifdef vax
+                               if (tflag) {
+                                       asargs[asargx++] = "-t";
+                                       asargs[asargx++] = tmpdir;
+                               }
+#                      endif vax
                        asargs[asargx++] = argp;
                        asargs[asargx++] = "-o";
                        tfile[1] = setsuf(argp, 'o');
                        asargs[asargx++] = argp;
                        asargs[asargx++] = "-o";
                        tfile[1] = setsuf(argp, 'o');
@@ -202,25 +284,20 @@ main(argc, argv)
                if (dosys(pc1, pc1args, 0, tfile[1]))
                        continue;
                unlink(tfile[0]);
                if (dosys(pc1, pc1args, 0, tfile[1]))
                        continue;
                unlink(tfile[0]);
-               if (Sflag && !Oflag)
+               tfile[0] = tname[0];
+               if (Oflag) {
+                       if (dosys(c2, c2args, tfile[1], tfile[0]))
+                               continue;
+                       unlink(tfile[1]);
+                       tfile[1] = tfile[0];
+                       tfile[0] = tname[1];
+               }
+               if (Sflag)
                        tfile[0] = setsuf(argp, 's');
                        tfile[0] = setsuf(argp, 's');
-               else
-                       tfile[0] = tname[0];
                if (dosys(pc2, pc2args, tfile[1], tfile[0]))
                        continue;
                unlink(tfile[1]);
                tfile[1] = 0;
                if (dosys(pc2, pc2args, tfile[1], tfile[0]))
                        continue;
                unlink(tfile[1]);
                tfile[1] = 0;
-               if (Oflag) {
-                       if (Sflag)
-                               tfile[1] = setsuf(argp, 's');
-                       else
-                               tfile[1] = tname[1];
-                       if (dosys(c2, c2args, tfile[0], tfile[1]))
-                               continue;
-                       unlink(tfile[0]);
-                       tfile[0] = tfile[1];
-                       tfile[1] = 0;
-               }
                if (Sflag) {
                        tfile[0] = 0;
                        continue;
                if (Sflag) {
                        tfile[0] = 0;
                        continue;
@@ -228,6 +305,12 @@ main(argc, argv)
                asargx = 1;
                if (Jflag)
                        asargs[asargx++] = "-J";
                asargx = 1;
                if (Jflag)
                        asargs[asargx++] = "-J";
+#              ifdef vax
+                       if (tflag) {
+                               asargs[asargx++] = "-t";
+                               asargs[asargx++] = tmpdir;
+                       }
+#              endif vax
                asargs[asargx++] = tfile[0];
                asargs[asargx++] = "-o";
                tfile[1] = setsuf(argp, 'o');
                asargs[asargx++] = tfile[0];
                asargs[asargx++] = "-o";
                tfile[1] = setsuf(argp, 'o');
@@ -242,6 +325,9 @@ main(argc, argv)
                done();
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
        pc3args[0] = "pc3";
                done();
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
        pc3args[0] = "pc3";
+       if (wflag)
+               pc3args[pc3argx++] = "-w";
+       pc3args[pc3argx++] = "/usr/lib/pcexterns.o";
        for (i = 0; i < argc; i++) {
                argp = argv[i];
                if (!strcmp(argp, "-o"))
        for (i = 0; i < argc; i++) {
                argp = argv[i];
                if (!strcmp(argp, "-o"))
@@ -263,8 +349,9 @@ main(argc, argv)
                }
        }
        pc3args[pc3argx] = 0;
                }
        }
        pc3args[pc3argx] = 0;
-       if (dosys(pc3, pc3args, 0, 0))
+       if (dosys(pc3, pc3args, 0, 0) > 1)
                done();
                done();
+       errs = 0;
 /* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
        ldargs[0] = "ld";
        ldargs[1] = "-X";
 /* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
        ldargs[0] = "ld";
        ldargs[1] = "-X";
@@ -311,6 +398,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':
@@ -332,8 +422,13 @@ duplicate:
        ldargs[ldargx++] = lpc;
        if (gflag)
                ldargs[ldargx++] = "-lg";
        ldargs[ldargx++] = lpc;
        if (gflag)
                ldargs[ldargx++] = "-lg";
-       ldargs[ldargx++] = "-lnm";
-       ldargs[ldargx++] = "-lc";
+       if (pflag) {
+               ldargs[ldargx++] = "-lm_p";
+               ldargs[ldargx++] = "-lc_p";
+       } else {
+               ldargs[ldargx++] = "-lm";
+               ldargs[ldargx++] = "-lc";
+       }
        ldargs[ldargx] = 0;
        if (dosys(ld, ldargs, 0, 0)==0 && np == 1 && nxo == 0)
                unlink(onepso);
        ldargs[ldargx] = 0;
        if (dosys(ld, ldargs, 0, 0)==0 && np == 1 && nxo == 0)
                unlink(onepso);
@@ -386,8 +481,12 @@ dosys(cmd, argv, in, out)
        while (wait(&status) != pid)
                ;
        if (WIFSIGNALED(status)) {
        while (wait(&status) != pid)
                ;
        if (WIFSIGNALED(status)) {
-               if (status.w_termsig != SIGINT)
-                       fprintf(stderr, "Fatal error in %s\n", cmd);
+               if (status.w_termsig != SIGINT) {
+                       fprintf(stderr, "%s: %s", cmd, mesg[status.w_termsig]);
+                       if (status.w_coredump)
+                               fprintf(stderr, " (core dumped)");
+                       fprintf(stderr, "\n");
+               }
                errs = 100;
                done();
                /*NOTREACHED*/
                errs = 100;
                done();
                /*NOTREACHED*/