BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / pascal / src / main.c
index 1823b45..9159cbb 100644 (file)
@@ -1,60 +1,89 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*-
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
 
 
-static char sccsid[] = "@(#)main.c 1.2 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)main.c     8.2 (Berkeley) 5/24/94";
+#endif /* not lint */
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
+#include "tree_ty.h"           /* must be included for yy.h */
 #include "yy.h"
 #include <signal.h>
 #include "objfmt.h"
 #include "yy.h"
 #include <signal.h>
 #include "objfmt.h"
+#include "config.h"
 
 /*
  * This version of pi has been in use at Berkeley since May 1977
 
 /*
  * This version of pi has been in use at Berkeley since May 1977
- * and is very stable, except for the syntactic error recovery which
- * has just been written.  Please report any problems with the error
+ * and is very stable. Please report any problems with the error
  * recovery to the second author at the address given in the file
  * READ_ME.  The second author takes full responsibility for any bugs
  * in the syntactic error recovery.
  */
 
 char   piusage[]       = "pi [ -blnpstuw ] [ -i file ... ] name.p";
  * recovery to the second author at the address given in the file
  * READ_ME.  The second author takes full responsibility for any bugs
  * in the syntactic error recovery.
  */
 
 char   piusage[]       = "pi [ -blnpstuw ] [ -i file ... ] name.p";
-char   pixusage[]      = "pix [ -blnpstuw ] [ -i file ... ] name.p [ arg ... ]";
-char   pcusage[]       = "pc [ options ] [ -o file ] [ -i file ... ] name.p";
 
 char   *usageis        = piusage;
 
 
 char   *usageis        = piusage;
 
-char   *errfile = ERR_STRNGS;
-
 #ifdef OBJ
 #ifdef OBJ
-    char       *obj    = "obj";
+
+char   pixusage[]      = "pix [ -blnpstuw ] [ -i file ... ] name.p [ arg ... ]";
+char   *obj    = "obj";
+
 #endif OBJ
 #endif OBJ
+
 #ifdef PC
 #ifdef PC
-    char       *pcname = "pc.pc1";
+
+char   *pcname = "pc.pc0";
+char   pcusage[]       = "pc [ options ] [ -o file ] [ -i file ... ] name.p";
+FILE   *pcstream = NULL;
+
 #endif PC
 #ifdef PTREE
     char       *pTreeName = "pi.pTree";
 #endif PTREE
 
 #endif PC
 #ifdef PTREE
     char       *pTreeName = "pi.pTree";
 #endif PTREE
 
-/*
- * Be careful changing errfile and howfile.
- * There are the "magic" constants 9 and 15 immediately below.
- * errfile is now defined by ERR_STRNGS, in objfmt.h,
- * and its leading path name length is ERR_PATHLEN long.
- * this for executing out of the current directory if running as `a.something'.
- */
-#ifdef OBJ
-char   *howfile        = "/usr/lib/how_pi\0";
-#endif OBJ
-#ifdef PC
-char   *howfile        = "/usr/lib/how_pc";
-#endif PC
-
 int    onintr();
 
 extern char *lastname;
 
 FILE   *ibuf;
 int    onintr();
 
 extern char *lastname;
 
 FILE   *ibuf;
-FILE   *pcstream = NULL;
 
 /*
  * these are made real variables
 
 /*
  * these are made real variables
@@ -75,15 +104,17 @@ main(argc, argv)
 {
        register char *cp;
        register c;
 {
        register char *cp;
        register c;
+       FILE *fopen();
+       extern char *myctime();
        int i;
 
        if (argv[0][0] == 'a')
        int i;
 
        if (argv[0][0] == 'a')
-               errfile += ERR_PATHLEN , howfile += 9;
+               err_file += err_pathlen , how_file += how_pathlen;
 #      ifdef OBJ
            if (argv[0][0] == '-' && argv[0][1] == 'o') {
                    obj = &argv[0][2];
                    usageis = pixusage;
 #      ifdef OBJ
            if (argv[0][0] == '-' && argv[0][1] == 'o') {
                    obj = &argv[0][2];
                    usageis = pixusage;
-                   howfile[15] = 'x';
+                   how_file[strlen(how_file)] = 'x';
                    ofil = 3;
            } else {
                    ofil = creat(obj, 0755);
                    ofil = 3;
            } else {
                    ofil = creat(obj, 0755);
@@ -99,7 +130,7 @@ main(argc, argv)
                if (i == -1)
                        goto usage;
                if (i == 0) {
                if (i == -1)
                        goto usage;
                if (i == 0) {
-                       execl("/bin/cat", "cat", howfile, 0);
+                       execl("/bin/cat", "cat", how_file, 0);
                        goto usage;
                }
                while (wait(&i) != -1)
                        goto usage;
                }
                while (wait(&i) != -1)
@@ -108,6 +139,10 @@ main(argc, argv)
        }
 #      ifdef OBJ
            opt('p') = opt('t') = opt('b') = 1;
        }
 #      ifdef OBJ
            opt('p') = opt('t') = opt('b') = 1;
+#if defined(vax) || defined(tahoe)
+           /* pdx is currently supported on the vax and the tahoe */
+           opt('g') = 1;
+#endif
            while (argc > 0) {
                    cp = argv[0];
                    if (*cp++ != '-')
            while (argc > 0) {
                    cp = argv[0];
                    if (*cp++ != '-')
@@ -123,15 +158,15 @@ main(argc, argv)
                                    yycosts();
                                    pexit(NOSTART);
                            case 'A':
                                    yycosts();
                                    pexit(NOSTART);
                            case 'A':
-                                   testtrace++;
+                                   testtrace = TRUE;
                            case 'F':
                            case 'F':
-                                   fulltrace++;
+                                   fulltrace = TRUE;
                            case 'E':
                            case 'E':
-                                   errtrace++;
+                                   errtrace = TRUE;
                                    opt('r')++;
                                    continue;
                            case 'U':
                                    opt('r')++;
                                    continue;
                            case 'U':
-                                   yyunique = 0;
+                                   yyunique = FALSE;
                                    continue;
 #endif
                            case 'b':
                                    continue;
 #endif
                            case 'b':
@@ -148,6 +183,7 @@ main(argc, argv)
                                    if (pflstc == 0)
                                            goto usage;
                                    continue;
                                    if (pflstc == 0)
                                            goto usage;
                                    continue;
+                           case 'g':
                            case 'l':
                            case 'n':
                            case 'p':
                            case 'l':
                            case 'n':
                            case 'p':
@@ -158,7 +194,10 @@ main(argc, argv)
                                    togopt(c);
                                    continue;
                            case 'z':
                                    togopt(c);
                                    continue;
                            case 'z':
-                                   monflg++;
+                                   monflg = TRUE;
+                                   continue;
+                           case 'L':
+                                   togopt( 'L' );
                                    continue;
                            default:
     usage:
                                    continue;
                            default:
     usage:
@@ -191,17 +230,17 @@ main(argc, argv)
                            yycosts();
                            pexit(NOSTART);
                    case 'A':
                            yycosts();
                            pexit(NOSTART);
                    case 'A':
-                           testtrace++;
+                           testtrace = TRUE;
                            /* and fall through */
                    case 'F':
                            /* and fall through */
                    case 'F':
-                           fulltrace++;
+                           fulltrace = TRUE;
                            /* and fall through */
                    case 'E':
                            /* and fall through */
                    case 'E':
-                           errtrace++;
+                           errtrace = TRUE;
                            opt('r')++;
                            break;
                    case 'U':
                            opt('r')++;
                            break;
                    case 'U':
-                           yyunique = 0;
+                           yyunique = FALSE;
                            break;
 #endif
                    case 'b':
                            break;
 #endif
                    case 'b':
@@ -229,6 +268,9 @@ main(argc, argv)
                            argc--;
                            pcname = argv[0];
                            break;      
                            argc--;
                            pcname = argv[0];
                            break;      
+                   case 'J':
+                           togopt( 'J' );
+                           break;
                    case 'C':
                                /*
                                 * since -t is an ld switch, use -C
                    case 'C':
                                /*
                                 * since -t is an ld switch, use -C
@@ -252,10 +294,13 @@ main(argc, argv)
                                /*
                                 *      -p on the command line means profile
                                 */
                                /*
                                 *      -p on the command line means profile
                                 */
-                           profflag++;
+                           profflag = TRUE;
                            break;
                    case 'z':
                            break;
                    case 'z':
-                           monflg++;
+                           monflg = TRUE;
+                           break;
+                   case 'L':
+                           togopt( 'L' );
                            break;
                    default:
 usage:
                            break;
                    default:
 usage:
@@ -268,9 +313,9 @@ usage:
 #      endif PC
        if (argc != 1)
                goto usage;
 #      endif PC
        if (argc != 1)
                goto usage;
-       efil = open ( errfile, 0 );
+       efil = open ( err_file, 0 );
        if ( efil < 0 )
        if ( efil < 0 )
-               perror(errfile), pexit(NOSTART);
+               perror(err_file), pexit(NOSTART);
        filename = argv[0];
        if (!dotted(filename, 'p')) {
                Perror(filename, "Name must end in '.p'");
        filename = argv[0];
        if (!dotted(filename, 'p')) {
                Perror(filename, "Name must end in '.p'");
@@ -285,7 +330,7 @@ usage:
                perror( pcname );
                pexit( NOSTART );
            }
                perror( pcname );
                pexit( NOSTART );
            }
-           stabsource( filename );
+           stabsource( filename, TRUE );
 #      endif PC
 #      ifdef PTREE
 #          define      MAXpPAGES       16
 #      endif PC
 #      ifdef PTREE
 #          define      MAXpPAGES       16
@@ -295,7 +340,7 @@ usage:
            }
 #      endif PTREE
        if ( signal( SIGINT , SIG_IGN ) != SIG_IGN )
            }
 #      endif PTREE
        if ( signal( SIGINT , SIG_IGN ) != SIG_IGN )
-               signal( SIGINT , onintr );
+               (void) signal( SIGINT , onintr );
        if (opt('l')) {
                opt('n')++;
                yysetfile(filename);
        if (opt('l')) {
                opt('n')++;
                yysetfile(filename);
@@ -312,7 +357,12 @@ pchr(c)
        putc ( c , stdout );
 }
 
        putc ( c , stdout );
 }
 
+#ifdef PC
+char   ugh[]   = "Fatal error in pc\n";
+#endif
+#ifdef OBJ
 char   ugh[]   = "Fatal error in pi\n";
 char   ugh[]   = "Fatal error in pi\n";
+#endif
 /*
  * Exit from the Pascal system.
  * We throw in an ungraceful termination
 /*
  * Exit from the Pascal system.
  * We throw in an ungraceful termination
@@ -336,6 +386,11 @@ pexit(c)
 #                      ifdef OBJ
                            if (ofil > 0)
                                    unlink(obj);
 #                      ifdef OBJ
                            if (ofil > 0)
                                    unlink(obj);
+                       /*
+                        * remove symbol table temp files
+                        */
+                           removenlfile();
+
 #                      endif OBJ
 #                      ifdef PC
                            if ( pcstream != NULL ) {
 #                      endif OBJ
 #                      ifdef PC
                            if ( pcstream != NULL ) {
@@ -346,6 +401,11 @@ pexit(c)
                case AOK:
 #                      ifdef OBJ
                            pflush();
                case AOK:
 #                      ifdef OBJ
                            pflush();
+                       /*
+                        * copy symbol table temp files to obj file
+                        */
+                           copynlfile();
+
 #                      endif OBJ
 #                      ifdef PC
                            puteof();
 #                      endif OBJ
 #                      ifdef PC
                            puteof();
@@ -372,7 +432,7 @@ pexit(c)
 onintr()
 {
 
 onintr()
 {
 
-       signal( SIGINT , SIG_IGN );
+       (void) signal( SIGINT , SIG_IGN );
        pexit(NOSTART);
 }
 
        pexit(NOSTART);
 }
 
@@ -384,14 +444,15 @@ geterr(seekpt, buf)
        char *buf;
 {
 
        char *buf;
 {
 
-       lseek(efil, (long) seekpt, 0);
+       if (lseek(efil, (off_t) seekpt, 0) == -1)
+               perror(err_file), pexit(DIED);
        if (read(efil, buf, 256) <= 0)
        if (read(efil, buf, 256) <= 0)
-               perror(errfile), pexit(DIED);
+               perror(err_file), pexit(DIED);
 }
 
 header()
 {
 }
 
 header()
 {
-       extern char version[];
+       extern char *version;
        static char anyheaders;
 
        gettime( filename );
        static char anyheaders;
 
        gettime( filename );
@@ -399,11 +460,11 @@ header()
                putc( '\f' , stdout );
        anyheaders++;
 #      ifdef OBJ
                putc( '\f' , stdout );
        anyheaders++;
 #      ifdef OBJ
-           printf("Berkeley Pascal PI -- Version 2.0 (%s)\n\n%s  %s\n\n",
-                   version, myctime(&tvec), filename);
+           printf("Berkeley Pascal PI -- Version %s\n\n%s  %s\n\n",
+                   version, myctime((int *) (&tvec)), filename);
 #      endif OBJ
 #      ifdef PC
 #      endif OBJ
 #      ifdef PC
-           printf("Berkeley Pascal PC -- Version 2.0 (%s)\n\n%s  %s\n\n",
-                   version, myctime(&tvec), filename);
+           printf("Berkeley Pascal PC -- Version %s\n\n%s  %s\n\n",
+                   version, myctime((int *) (&tvec)), filename);
 #      endif PC
 }
 #      endif PC
 }