BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / src / nl.c
index 302c04b..589844c 100644 (file)
@@ -1,6 +1,39 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*-
+ * Copyright (c) 1980 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 sccsid[] = "@(#)nl.c 1.12 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)nl.c       5.2 (Berkeley) 4/16/91";
+#endif /* not lint */
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -273,13 +306,13 @@ initnl()
 #endif
        ntab[0].nls_low = nl;
        ntab[0].nls_high = &nl[INL];
 #endif
        ntab[0].nls_low = nl;
        ntab[0].nls_high = &nl[INL];
-       defnl ( 0 , 0 , 0 , 0 );
+       (void) defnl ( (char *) 0 , 0 , NLNIL , 0 );
 
        /*
         *      Types
         */
        for ( cp = in_types ; *cp != 0 ; cp ++ )
 
        /*
         *      Types
         */
        for ( cp = in_types ; *cp != 0 ; cp ++ )
-           hdefnl ( *cp , TYPE , nlp , 0 );
+           (void) hdefnl ( *cp , TYPE , nlp , 0 );
 
        /*
         *      Ranges
 
        /*
         *      Ranges
@@ -287,7 +320,7 @@ initnl()
        lp = in_ranges;
        for ( ip = in_rclasses ; *ip != 0 ; ip ++ )
            {
        lp = in_ranges;
        for ( ip = in_rclasses ; *ip != 0 ; ip ++ )
            {
-               np = defnl ( 0 , RANGE , nl+(*ip) , 0 );
+               np = defnl ( (char *) 0 , RANGE , nl+(*ip) , 0 );
                nl[*ip].type = np;
                np -> range[0] = *lp ++ ;
                np -> range[1] = *lp ++ ;
                nl[*ip].type = np;
                np -> range[0] = *lp ++ ;
                np -> range[1] = *lp ++ ;
@@ -302,32 +335,32 @@ initnl()
        /*
         *      Boolean = boolean;
         */
        /*
         *      Boolean = boolean;
         */
-       hdefnl ( *cp++ , TYPE , nl+T1BOOL , 0 );
+       (void) hdefnl ( *cp++ , TYPE , (struct nl *) (nl+T1BOOL) , 0 );
 
        /*
         *      intset = set of 0 .. 127;
         */
 
        /*
         *      intset = set of 0 .. 127;
         */
-       intset = *cp++;
-       hdefnl( intset , TYPE , nlp+1 , 0 );
-       defnl ( 0 , SET , nlp+1 , 0 );
-       np = defnl ( 0 , RANGE , nl+TINT , 0 );
+       intset = ((struct nl *) *cp++);
+       (void) hdefnl( (char *) intset , TYPE , nlp+1 , 0 );
+       (void) defnl ( (char *) 0 , SET , nlp+1 , 0 );
+       np = defnl ( (char *) 0 , RANGE , nl+TINT , 0 );
        np -> range[0] = 0L;
        np -> range[1] = 127L;
 
        /*
         *      alfa = array [ 1 .. 10 ] of char;
         */
        np -> range[0] = 0L;
        np -> range[1] = 127L;
 
        /*
         *      alfa = array [ 1 .. 10 ] of char;
         */
-       np = defnl ( 0 , RANGE , nl+TINT , 0 );
+       np = defnl ( (char *) 0 , RANGE , nl+TINT , 0 );
        np -> range[0] = 1L;
        np -> range[1] = 10L;
        np -> range[0] = 1L;
        np -> range[1] = 10L;
-       defnl ( 0 , ARRAY , nl+T1CHAR , 1 ) -> chain = np;
-       hdefnl ( *cp++ , TYPE , nlp-1 , 0 );
+       defnl ( (char *) 0 , ARRAY , nl+T1CHAR , 1 ) -> chain = np;
+       (void) hdefnl ( *cp++ , TYPE , nlp-1 , 0 );
 
        /*
         *      text = file of char;
         */
 
        /*
         *      text = file of char;
         */
-       hdefnl ( *cp++ , TYPE , nlp+1 , 0 );
-       np = defnl ( 0 , FILET , nl+T1CHAR , 0 );
+       (void) hdefnl ( *cp++ , TYPE , nlp+1 , 0 );
+       np = defnl ( (char *) 0 , FILET , nl+T1CHAR , 0 );
        np -> nl_flags |= NFILES;
 
        /*
        np -> nl_flags |= NFILES;
 
        /*
@@ -361,10 +394,10 @@ initnl()
                (nl + TBOOL)->chain = fp;
        hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MININT;
        hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MAXINT;
                (nl + TBOOL)->chain = fp;
        hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MININT;
        hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MAXINT;
-       hdefnl ( *cp++ , CONST , nl + T1CHAR , 0 );
-       hdefnl ( *cp++ , CONST , nl + T1CHAR , 127 );
-       hdefnl ( *cp++ , CONST , nl + T1CHAR , '\007' );
-       hdefnl ( *cp++ , CONST , nl + T1CHAR , '\t' );
+       (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , 0 );
+       (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , 127 );
+       (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , '\007' );
+       (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , '\t' );
 
        /*
         * Built-in functions and procedures
 
        /*
         * Built-in functions and procedures
@@ -372,15 +405,15 @@ initnl()
 #ifndef PI0
        ip = in_fops;
        for ( cp = in_funcs ; *cp != 0 ; cp ++ )
 #ifndef PI0
        ip = in_fops;
        for ( cp = in_funcs ; *cp != 0 ; cp ++ )
-           hdefnl ( *cp , FUNC , 0 , * ip ++ );
+           (void) hdefnl ( *cp , FUNC , NLNIL , * ip ++ );
        ip = in_pops;
        for ( cp = in_procs ; *cp != 0 ; cp ++ )
        ip = in_pops;
        for ( cp = in_procs ; *cp != 0 ; cp ++ )
-           hdefnl ( *cp , PROC , 0 , * ip ++ );
+           (void) hdefnl ( *cp , PROC , NLNIL , * ip ++ );
 #else
        for ( cp = in_funcs ; *cp != 0 ; cp ++ )
 #else
        for ( cp = in_funcs ; *cp != 0 ; cp ++ )
-           hdefnl ( *cp , FUNC , 0 , 0 );
+           (void) hdefnl ( *cp , FUNC , NLNIL , 0 );
        for ( cp = in_procs ; *cp != 0 , cp ++ )
        for ( cp = in_procs ; *cp != 0 , cp ++ )
-           hdefnl ( *cp , PROC , 0 , 0 );
+           (void) hdefnl ( *cp , PROC , NLNIL , 0 );
 #endif
 #      ifdef PTREE
            pTreeInit();
 #endif
 #      ifdef PTREE
            pTreeInit();
@@ -389,16 +422,20 @@ initnl()
 
 struct nl *
 hdefnl(sym, cls, typ, val)
 
 struct nl *
 hdefnl(sym, cls, typ, val)
+    char *sym;
+    int  cls;
+    struct nl *typ;
+    int val;
 {
        register struct nl *p;
 
 #ifndef PI1
        if (sym)
 {
        register struct nl *p;
 
 #ifndef PI1
        if (sym)
-               hash(sym, 0);
+               (void) hash(sym, 0);
 #endif
        p = defnl(sym, cls, typ, val);
        if (sym)
 #endif
        p = defnl(sym, cls, typ, val);
        if (sym)
-               enter(p);
+               (void) enter(p);
        return (p);
 }
 
        return (p);
 }
 
@@ -414,7 +451,7 @@ nlfree(p)
 
        nlp = p;
        while (nlact->nls_low > nlp || nlact->nls_high < nlp) {
 
        nlp = p;
        while (nlact->nls_low > nlp || nlact->nls_high < nlp) {
-               free(nlact->nls_low);
+               free((char *) nlact->nls_low);
                nlact->nls_low = NIL;
                nlact->nls_high = NIL;
                --nlact;
                nlact->nls_low = NIL;
                nlact->nls_high = NIL;
                --nlact;
@@ -425,7 +462,11 @@ nlfree(p)
 #endif PI
 \f
 
 #endif PI
 \f
 
+#ifndef PC
+#ifndef OBJ
 char   *VARIABLE       = "variable";
 char   *VARIABLE       = "variable";
+#endif PC
+#endif OBJ
 
 char   *classes[ ] = {
        "undefined",
 
 char   *classes[ ] = {
        "undefined",
@@ -455,7 +496,11 @@ char       *classes[ ] = {
        "formal function"
 };
 
        "formal function"
 };
 
+#ifndef PC
+#ifndef OBJ
 char   *snark  = "SNARK";
 char   *snark  = "SNARK";
+#endif
+#endif
 
 #ifdef PI
 #ifdef DEBUG
 
 #ifdef PI
 #ifdef DEBUG
@@ -485,7 +530,8 @@ char        *ctext[] =
        "IMPROPER",
        "VARNT",
        "FPROC",
        "IMPROPER",
        "VARNT",
        "FPROC",
-       "FFUNC"
+       "FFUNC",
+       "CRANGE"
 };
 
 char   *stars  = "\t***";
 };
 
 char   *stars  = "\t***";
@@ -496,13 +542,13 @@ char      *stars  = "\t***";
  * All the namelist is dumped if
  * to is NIL.
  */
  * All the namelist is dumped if
  * to is NIL.
  */
+/*VARARGS*/
 dumpnl(to, rout)
        struct nl *to;
 {
        register struct nl *p;
 dumpnl(to, rout)
        struct nl *to;
 {
        register struct nl *p;
-       register int j;
        struct nls *nlsp;
        struct nls *nlsp;
-       int i, v, head;
+       int v, head;
 
        if (opt('y') == 0)
                return;
 
        if (opt('y') == 0)
                return;
@@ -584,6 +630,10 @@ con:
                        case RANGE:
                                printf("\t%ld..%ld", p->range[0], p->range[1]);
                                break;
                        case RANGE:
                                printf("\t%ld..%ld", p->range[0], p->range[1]);
                                break;
+                       case CRANGE:
+                               printf("\t%s..%s", p->nptr[0]->symbol,
+                                       p->nptr[1]->symbol);
+                               break;
                        case RECORD:
                                printf("\t%d", v);
                                break;
                        case RECORD:
                                printf("\t%d", v);
                                break;
@@ -607,7 +657,7 @@ con:
                                }
                                v = p->value[1];
                        default:
                                }
                                v = p->value[1];
                        default:
-casedef:
+
                                if (v)
                                        printf("\t<%d>", v);
                                else
                                if (v)
                                        printf("\t<%d>", v);
                                else
@@ -700,7 +750,7 @@ defnl(sym, cls, typ, val)
        /*
         * Zero out this entry
         */
        /*
         * Zero out this entry
         */
-       q = p;
+       q = ((int *) p);
        i = (sizeof *p)/(sizeof (int));
        do
                *q++ = 0;
        i = (sizeof *p)/(sizeof (int));
        do
                *q++ = 0;
@@ -728,10 +778,10 @@ defnl(sym, cls, typ, val)
        nlp++;
        if (nlp >= nlact->nls_high) {
                i = NLINC;
        nlp++;
        if (nlp >= nlact->nls_high) {
                i = NLINC;
-               cp = malloc(NLINC * sizeof *nlp);
+               cp = (char *) malloc(NLINC * sizeof *nlp);
                if (cp == 0) {
                        i = NLINC / 2;
                if (cp == 0) {
                        i = NLINC / 2;
-                       cp = malloc((NLINC / 2) * sizeof *nlp);
+                       cp = (char *) malloc((NLINC / 2) * sizeof *nlp);
                }
                if (cp == 0) {
                        error("Ran out of memory (defnl)");
                }
                if (cp == 0) {
                        error("Ran out of memory (defnl)");
@@ -742,7 +792,7 @@ defnl(sym, cls, typ, val)
                        error("Ran out of name list tables");
                        pexit(DIED);
                }
                        error("Ran out of name list tables");
                        pexit(DIED);
                }
-               nlp = cp;
+               nlp = (struct nl *) cp;
                nlact->nls_low = nlp;
                nlact->nls_high = nlact->nls_low + i;
        }
                nlact->nls_low = nlp;
                nlact->nls_high = nlact->nls_low + i;
        }
@@ -759,16 +809,13 @@ struct nl *
 nlcopy(p)
        struct nl *p;
 {
 nlcopy(p)
        struct nl *p;
 {
-       register int *p1, *p2, i;
+       register struct nl *p1, *p2;
 
        p1 = p;
 
        p1 = p;
-       p = p2 = defnl(0, 0, 0, 0);
-       i = (sizeof *p)/(sizeof (int));
-       do
-               *p2++ = *p1++;
-       while (--i);
-       p->chain = NIL;
-       return (p);
+       p2 = defnl((char *) 0, 0, NLNIL, 0);
+       *p2 = *p1;
+       p2->chain = NLNIL;
+       return (p2);
 }
 
 /*
 }
 
 /*
@@ -804,12 +851,13 @@ enter(np)
                if (rp->symbol == input->symbol || rp->symbol == output->symbol)
                        error("Pre-defined files input and output must not be redefined");
 #endif
                if (rp->symbol == input->symbol || rp->symbol == output->symbol)
                        error("Pre-defined files input and output must not be redefined");
 #endif
-       i = rp->symbol;
+       i = (int) rp->symbol;
        i &= 077;
        hp = disptab[i];
        if (rp->class != BADUSE && rp->class != FIELD)
        for (p = hp; p != NIL && (p->nl_block & 037) == cbn; p = p->nl_next)
        i &= 077;
        hp = disptab[i];
        if (rp->class != BADUSE && rp->class != FIELD)
        for (p = hp; p != NIL && (p->nl_block & 037) == cbn; p = p->nl_next)
-               if (p->symbol == rp->symbol && p->class != BADUSE && p->class != FIELD) {
+               if (p->symbol == rp->symbol && p->symbol != NIL &&
+                   p->class != BADUSE && p->class != FIELD) {
 #ifndef PI1
                        error("%s is already defined in this block", rp->symbol);
 #endif
 #ifndef PI1
                        error("%s is already defined in this block", rp->symbol);
 #endif