add the -t flag to use temporary files elsewhere.
[unix-history] / usr / src / usr.bin / pascal / pc / pc.c
index 975c46d..f39a7e2 100644 (file)
@@ -1,27 +1,34 @@
-static char sccsid[] = "@(#)pc.c 3.1 %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.
  */
  */
-char   *pc0 = "/usr/new/pc0";
-char   *pc1 = "/usr/new/pc1";
-char   *pc2 = "/usr/new/pc2";
-char   *c2 = "/usr/new/c2";
-char   *pc3 = "/usr/new/pc3";
-char   *ld = "/usr/new/ld";
-char   *as = "/usr/new/as";
+char   *pc0 = "/usr/lib/pc0";
+char   *pc1 = "/lib/f1";
+char   *pc2 = "/usr/lib/pc2";
+char   *c2 = "/lib/c2";
+char   *pc3 = "/usr/lib/pc3";
+char   *ld = "/bin/ld";
+char   *as = "/bin/as";
 char   *lpc = "-lpc";
 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    Sflag, Oflag, cflag, gflag;
+int    Jflag, Sflag, Oflag, Tlflag, cflag, gflag, pflag, wflag, tflag;
 int    debug;
 
 #define        NARGS   512
 int    debug;
 
 #define        NARGS   512
@@ -35,8 +42,47 @@ int  pc3argx = 1;
 #define        pc3args pc0args
 #define        ldargs  pc0args
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
 #define        pc3args pc0args
 #define        ldargs  pc0args
 /* char        *pc3args[NARGS] =       { "pc3", 0 }; */
-/* char        *ldargs[NARGS] =        { "ld", "-X", "/usr/new/crt0.o", 0, }; */
-char   *asargs[5] =            { "as", 0, };
+/* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
+
+                               /* as -J -t tmpdir -o objfile srcfile \0 */
+int    asargx;
+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
@@ -103,29 +149,57 @@ 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 'S':
                        Sflag = 1;
                        continue;
                case 'O':
                        Oflag = 1;
                        continue;
                case 'S':
                        Sflag = 1;
                        continue;
+               case 'J':
+                       Jflag = 1;
+                       continue;
                case 'T':
                        switch (argp[2]) {
 
                        case '0':
                case 'T':
                        switch (argp[2]) {
 
                        case '0':
-                               pc0 = "/vb/grad/peter/pc/npc0/src/a.pc";
+                               pc0 = "/usr/src/ucb/pascal/pc0/a.out";
+                               if (argp[3] != '\0') {
+                                       pc0 = &argp[3];
+                               }
                                continue;
                        case '1':
                                continue;
                        case '1':
-                               pc1 = "/usr/src/new/pcc/pc1";
+                               pc1 = "/usr/src/lib/pcc/fort";
+                               if (argp[3] != '\0') {
+                                       pc1 = &argp[3];
+                               }
                                continue;
                        case '2':
                                continue;
                        case '2':
-                               pc2 = "/usr/new/pc2";
+                               pc2 = "/usr/src/ucb/pascal/utilities/pc2";
+                               if (argp[3] != '\0') {
+                                       pc2 = &argp[3];
+                               }
                                continue;
                        case '3':
                                continue;
                        case '3':
-                               pc3 = "/usr/new/pc3";
+                               pc3 = "/usr/src/ucb/pascal/utilities/pc3";
+                               if (argp[3] != '\0') {
+                                       pc3 = &argp[3];
+                               }
                                continue;
                        case 'l':
                                continue;
                        case 'l':
-                               lpc = "-lnpc";
+                               Tlflag = 1;
+                               lpc = "/usr/src/usr.lib/libpc/libpc";
+                               if (argp[3] != '\0') {
+                                       lpc = &argp[3];
+                               }
                                continue;
                        }
                        continue;
                                continue;
                        }
                        continue;
@@ -137,72 +211,111 @@ 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':
-                       fprintf(stderr, "pc: -p (profiling) not implemented\n");
-                       exit(1);
+                       if (argp[2] == 'g')
+                               crt0 = gcrt0;
+                       else
+                               crt0 = mcrt0;
+                       if (!Tlflag)
+                               lpc = "-lpc_p";
+                       pflag = 1;
+                       continue;
                }
        }
        if (gflag && Oflag) {
                fprintf(stderr, "pc: warning: -g overrides -O\n");
                Oflag = 0;
        }
                }
        }
        if (gflag && Oflag) {
                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];
                if (argp[0] == '-')
                        continue;
        savargx = pc0argx;
        for (i = 0; i < argc; i++) {
                argp = argv[i];
                if (argp[0] == '-')
                        continue;
+               if (suffix(argp) == 's') {
+                       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++] = tfile[1];
+                       asargs[asargx] = 0;
+                       if (dosys(as, asargs, 0, 0))
+                               continue;
+                       tfile[1] = 0;
+                       continue;
+               }
                if (suffix(argp) != 'p')
                        continue;
                tfile[0] = tname[0];
                pc0args[2] = tfile[0];
                pc0argx = savargx;
                if (suffix(argp) != 'p')
                        continue;
                tfile[0] = tname[0];
                pc0args[2] = tfile[0];
                pc0argx = savargx;
+               if (pflag)
+                       pc0args[pc0argx++] = "-p";
                pc0args[pc0argx++] = argp;
                pc0args[pc0argx] = 0;
                if (dosys(pc0, pc0args, 0, 0))
                        continue;
                pc1args[1] = tfile[0];
                pc0args[pc0argx++] = argp;
                pc0args[pc0argx] = 0;
                if (dosys(pc0, pc0args, 0, 0))
                        continue;
                pc1args[1] = tfile[0];
-               if (Sflag && !Oflag)
-                       tfile[1] = setsuf(argp, 's');
-               else
-                       tfile[1] = tname[1];
+               tfile[1] = tname[1];
                if (dosys(pc1, pc1args, 0, tfile[1]))
                        continue;
                unlink(tfile[0]);
                if (dosys(pc1, pc1args, 0, tfile[1]))
                        continue;
                unlink(tfile[0]);
-               if (dosys(pc2, pc2args, tfile[1], tfile[0]))
-                       continue;
-               unlink(tfile[1]);
-               tfile[1] = 0;
+               tfile[0] = tname[0];
                if (Oflag) {
                if (Oflag) {
-                       if (Sflag)
-                               tfile[1] = setsuf(argp, 's');
-                       else
-                               tfile[1] = tname[0];
-                       if (dosys(c2, c2args, tfile[0], tfile[1]))
+                       if (dosys(c2, c2args, tfile[1], tfile[0]))
                                continue;
                                continue;
-                       unlink(tfile[0]);
-                       tfile[0] = tfile[1];
-                       tfile[1] = 0;
+                       unlink(tfile[1]);
+                       tfile[1] = tfile[0];
+                       tfile[0] = tname[1];
                }
                if (Sflag)
                }
                if (Sflag)
+                       tfile[0] = setsuf(argp, 's');
+               if (dosys(pc2, pc2args, tfile[1], tfile[0]))
+                       continue;
+               unlink(tfile[1]);
+               tfile[1] = 0;
+               if (Sflag) {
+                       tfile[0] = 0;
                        continue;
                        continue;
-               asargs[1] = tfile[0];
-               asargs[2] = "-o";
+               }
+               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');
                tfile[1] = setsuf(argp, 'o');
-               asargs[3] = tfile[1];
+               asargs[asargx++] = tfile[1];
+               asargs[asargx] = 0;
                if (dosys(as, asargs, 0, 0))
                        continue;
                tfile[1] = 0;
                if (dosys(as, asargs, 0, 0))
                        continue;
                tfile[1] = 0;
@@ -212,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"))
@@ -220,12 +336,11 @@ main(argc, argv)
                        continue;
                switch (getsuf(argp)) {
 
                        continue;
                switch (getsuf(argp)) {
 
-               case 'd':
-                       continue;
                case 'o':
                        pc3args[pc3argx++] = argp;
                        nxo++;
                        continue;
                case 'o':
                        pc3args[pc3argx++] = argp;
                        nxo++;
                        continue;
+               case 's':
                case 'p':
                        onepso = pc3args[pc3argx++] =
                            savestr(setsuf(argp, 'o'));
                case 'p':
                        onepso = pc3args[pc3argx++] =
                            savestr(setsuf(argp, 'o'));
@@ -234,18 +349,20 @@ main(argc, argv)
                }
        }
        pc3args[pc3argx] = 0;
                }
        }
        pc3args[pc3argx] = 0;
-       if (dosys(pc3, pc3args, 0, 0))
+       if (dosys(pc3, pc3args, 0, 0) > 1)
                done();
                done();
-/* char        *ldargs[NARGS] =        { "ld", "-X", "/usr/new/crt0.o", 0, }; */
+       errs = 0;
+/* char        *ldargs[NARGS] =        { "ld", "-X", "/lib/crt0.o", 0, }; */
        ldargs[0] = "ld";
        ldargs[1] = "-X";
        ldargs[0] = "ld";
        ldargs[1] = "-X";
-       ldargs[2] = "/usr/new/crt0.o";
+       ldargs[2] = crt0;
        for (i = 0; i < argc; i++) {
                argp = argv[i];
                if (argp[0] != '-') {
                        switch (getsuf(argp)) {
 
                        case 'p':
        for (i = 0; i < argc; i++) {
                argp = argv[i];
                if (argp[0] != '-') {
                        switch (getsuf(argp)) {
 
                        case 'p':
+                       case 's':
                                ldargs[ldargx] = savestr(setsuf(argp, 'o'));
                                break;
                        default:
                                ldargs[ldargx] = savestr(setsuf(argp, 'o'));
                                break;
                        default:
@@ -281,11 +398,15 @@ 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 'p':
                case 'S':
                case 'c':
                case 'g':
                case 'w':
                case 'p':
                case 'S':
+               case 'J':
                case 'T':
                case 'O':
                case 'C':
                case 'T':
                case 'O':
                case 'C':
@@ -301,7 +422,13 @@ duplicate:
        ldargs[ldargx++] = lpc;
        if (gflag)
                ldargs[ldargx++] = "-lg";
        ldargs[ldargx++] = lpc;
        if (gflag)
                ldargs[ldargx++] = "-lg";
-       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);
@@ -354,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*/
@@ -403,20 +534,18 @@ getsuf(cp)
        return (*cp);
 }
 
        return (*cp);
 }
 
-char   sufbuf[BUFSIZ];
-
 char *
 char *
-setsuf(cp, c)
-       char *cp;
+setsuf(as, ch)
+       char *as;
 {
 {
-       register char *dp;
-
-       for (dp = sufbuf; *cp; *dp++ = *cp++)
-               continue;
-       *dp = 0;
-       if (dp-sufbuf > 2 && dp[-2] == '.')
-               dp[-1] = c;
-       return (sufbuf);
+       register char *s, *s1;
+
+       s = s1 = savestr(as);
+       while (*s)
+               if (*s++ == '/')
+                       s1 = s;
+       s[-1] = ch;
+       return (s1);
 }
 
 #define        NSAVETAB        512
 }
 
 #define        NSAVETAB        512