BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / pascal / src / main.c
index 07c47df..9159cbb 100644 (file)
@@ -1,15 +1,53 @@
-/* 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.
+ */
 
 
-static char copyright[] =
-           "@(#)Copyright (c) 1979 Regents of the University of California";
+#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.6 %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
@@ -20,43 +58,32 @@ static char sccsid[] = "@(#)main.c 1.6 %G%";
  */
 
 char   piusage[]       = "pi [ -blnpstuw ] [ -i file ... ] name.p";
  */
 
 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.pc0";
+
+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        = HOW_STRNGS;
-#endif OBJ
-#ifdef PC
-char   *howfile        = HOW_STRNGS;
-#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
@@ -77,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 += HOW_PATHLEN;
+               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[HOW_PATHLEN+6] = 'x';
+                   how_file[strlen(how_file)] = 'x';
                    ofil = 3;
            } else {
                    ofil = creat(obj, 0755);
                    ofil = 3;
            } else {
                    ofil = creat(obj, 0755);
@@ -101,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)
@@ -109,7 +138,11 @@ main(argc, argv)
                pexit(NOSTART);
        }
 #      ifdef OBJ
                pexit(NOSTART);
        }
 #      ifdef OBJ
-           opt('g') = opt('p') = opt('t') = opt('b') = 1;
+           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++ != '-')
@@ -133,7 +166,7 @@ main(argc, argv)
                                    opt('r')++;
                                    continue;
                            case 'U':
                                    opt('r')++;
                                    continue;
                            case 'U':
-                                   yyunique = 0;
+                                   yyunique = FALSE;
                                    continue;
 #endif
                            case 'b':
                                    continue;
 #endif
                            case 'b':
@@ -163,6 +196,9 @@ main(argc, argv)
                            case 'z':
                                    monflg = TRUE;
                                    continue;
                            case 'z':
                                    monflg = TRUE;
                                    continue;
+                           case 'L':
+                                   togopt( 'L' );
+                                   continue;
                            default:
     usage:
                                    Perror( "Usage", usageis);
                            default:
     usage:
                                    Perror( "Usage", usageis);
@@ -204,7 +240,7 @@ main(argc, argv)
                            opt('r')++;
                            break;
                    case 'U':
                            opt('r')++;
                            break;
                    case 'U':
-                           yyunique = 0;
+                           yyunique = FALSE;
                            break;
 #endif
                    case 'b':
                            break;
 #endif
                    case 'b':
@@ -232,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
@@ -260,6 +299,9 @@ main(argc, argv)
                    case 'z':
                            monflg = TRUE;
                            break;
                    case 'z':
                            monflg = TRUE;
                            break;
+                   case 'L':
+                           togopt( 'L' );
+                           break;
                    default:
 usage:
                            Perror( "Usage", usageis);
                    default:
 usage:
                            Perror( "Usage", usageis);
@@ -271,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'");
@@ -288,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
@@ -298,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);
@@ -315,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
@@ -385,7 +432,7 @@ pexit(c)
 onintr()
 {
 
 onintr()
 {
 
-       signal( SIGINT , SIG_IGN );
+       (void) signal( SIGINT , SIG_IGN );
        pexit(NOSTART);
 }
 
        pexit(NOSTART);
 }
 
@@ -397,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 );
@@ -412,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
 }