BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / src / put.c
index fdd822c..551bdb4 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[] = "@(#)put.c 1.25 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)put.c      5.4 (Berkeley) 4/16/91";
+#endif /* not lint */
 
 #include "whoami.h"
 #include "opcode.h"
 
 #include "whoami.h"
 #include "opcode.h"
@@ -9,9 +42,9 @@ static char sccsid[] = "@(#)put.c 1.25 %G%";
 #ifdef PC
 #   include    "pc.h"
 #   include    "align.h"
 #ifdef PC
 #   include    "pc.h"
 #   include    "align.h"
-#endif PC
-
-short  *obufp  = obuf;
+#else
+    short      *obufp  = obuf;
+#endif
 
 /*
  * If DEBUG is defined, include the table
 
 /*
  * If DEBUG is defined, include the table
@@ -21,19 +54,24 @@ short       *obufp  = obuf;
 #include "OPnames.h"
 #endif
 
 #include "OPnames.h"
 #endif
 
+char showit[] = "'x'";
+
 #ifdef OBJ
 /*
  * Put is responsible for the interpreter equivalent of code
  * generation.  Since the interpreter is specifically designed
  * for Pascal, little work is required here.
 #ifdef OBJ
 /*
  * Put is responsible for the interpreter equivalent of code
  * generation.  Since the interpreter is specifically designed
  * for Pascal, little work is required here.
+ *
+ * FIXME, this should be converted to use <varargs.h> or <stdarg.h>.
  */
  */
+/*VARARGS*/
 put(a)
 {
        register int *p, i;
        register char *cp;
        register short *sp;
        register long *lp;
 put(a)
 {
        register int *p, i;
        register char *cp;
        register short *sp;
        register long *lp;
-       int n, subop, suboppr, op, oldlc, w;
+       int n, subop, suboppr, op, oldlc;
        char *string;
        static int casewrd;
 
        char *string;
        static int casewrd;
 
@@ -45,7 +83,7 @@ put(a)
         * relational operators could be used
         * etc.
         */
         * relational operators could be used
         * etc.
         */
-       oldlc = lc;
+       oldlc = (int) lc; /* its either this or change put to return a char * */
        if ( !CGENNING )
                /*
                 * code disabled - do nothing
        if ( !CGENNING )
                /*
                 * code disabled - do nothing
@@ -168,7 +206,7 @@ put(a)
                        break;
                case O_CON8:
                    {
                        break;
                case O_CON8:
                    {
-                       short   *sp = &p[1];
+                       short   *sp = (short *) (&p[1]);
 
 #ifdef DEBUG
                        if ( opt( 'k' ) )
 
 #ifdef DEBUG
                        if ( opt( 'k' ) )
@@ -207,7 +245,7 @@ put(a)
                        break;
                case O_CONC:
 #ifdef DEBUG
                        break;
                case O_CONC:
 #ifdef DEBUG
-                       (string = "'x'")[1] = p[1];
+                       (string = showit)[1] = p[1];
 #endif
                        suboppr = 0;
                        op = O_CON1;
 #endif
                        suboppr = 0;
                        op = O_CON1;
@@ -218,7 +256,7 @@ put(a)
                        goto around;
                case O_CONC4:
 #ifdef DEBUG
                        goto around;
                case O_CONC4:
 #ifdef DEBUG
-                       (string = "'x'")[1] = p[1];
+                       (string = showit)[1] = p[1];
 #endif
                        suboppr = 0;
                        op = O_CON14;
 #endif
                        suboppr = 0;
                        op = O_CON14;
@@ -411,7 +449,10 @@ listnames(ap)
        register struct nl *ap;
 {
        struct nl *next;
        register struct nl *ap;
 {
        struct nl *next;
-       register int oldlc, len;
+#ifdef OBJ
+       register int oldlc;
+#endif
+       register int len;
        register unsigned w;
        register char *strptr;
 
        register unsigned w;
        register char *strptr;
 
@@ -425,21 +466,21 @@ listnames(ap)
                return( ap -> value[ NL_ELABEL ] );
        }
 #      ifdef OBJ
                return( ap -> value[ NL_ELABEL ] );
        }
 #      ifdef OBJ
-           oldlc = lc;
-           put(2, O_TRA, lc);
-           ap->value[ NL_ELABEL ] = lc;
+           oldlc = (int) lc; /* same problem as put */
+           (void) put(2, O_TRA, lc);
+           ap->value[ NL_ELABEL ] = (int) lc;
 #      endif OBJ
 #      ifdef PC
            putprintf(" .data", 0);
            aligndot(A_STRUCT);
 #      endif OBJ
 #      ifdef PC
            putprintf(" .data", 0);
            aligndot(A_STRUCT);
-           ap -> value[ NL_ELABEL ] = getlab();
-           putlab( ap -> value[ NL_ELABEL ] );
+           ap -> value[ NL_ELABEL ] = (int) getlab();
+           (void) putlab((char *) ap -> value[ NL_ELABEL ] );
 #      endif PC
        /* number of scalars */
        next = ap->type;
        len = next->range[1]-next->range[0]+1;
 #      ifdef OBJ
 #      endif PC
        /* number of scalars */
        next = ap->type;
        len = next->range[1]-next->range[0]+1;
 #      ifdef OBJ
-           put(2, O_CASE2, len);
+           (void) put(2, O_CASE2, len);
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
@@ -447,7 +488,7 @@ listnames(ap)
        /* offsets of each scalar name */
        len = (len+1)*sizeof(short);
 #      ifdef OBJ
        /* offsets of each scalar name */
        len = (len+1)*sizeof(short);
 #      ifdef OBJ
-           put(2, O_CASE2, len);
+           (void) put(2, O_CASE2, len);
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
@@ -458,7 +499,7 @@ listnames(ap)
                        continue;
                len++;
 #              ifdef OBJ
                        continue;
                len++;
 #              ifdef OBJ
-                   put(2, O_CASE2, len);
+                   (void) put(2, O_CASE2, len);
 #              endif OBJ
 #              ifdef PC
                    putprintf( "        .word %d" , 0 , len );
 #              endif OBJ
 #              ifdef PC
                    putprintf( "        .word %d" , 0 , len );
@@ -482,10 +523,10 @@ listnames(ap)
 #                  endif DEC11
                    if (!*strptr++)
                            strptr = getnext(next, &next);
 #                  endif DEC11
                    if (!*strptr++)
                            strptr = getnext(next, &next);
-                   word(w);
+                   word((int) w);
            } while (next);
            /* jump over the mess */
            } while (next);
            /* jump over the mess */
-           patch(oldlc);
+           patch((PTR_DCL) oldlc);
 #      endif OBJ
 #      ifdef PC
            while ( next ) {
 #      endif OBJ
 #      ifdef PC
            while ( next ) {
@@ -504,6 +545,7 @@ listnames(ap)
        return( ap -> value[ NL_ELABEL ] );
 }
 
        return( ap -> value[ NL_ELABEL ] );
 }
 
+char *
 getnext(next, new)
 
        struct nl *next, **new;
 getnext(next, new)
 
        struct nl *next, **new;
@@ -512,7 +554,7 @@ getnext(next, new)
                next = next->chain;
                *new = next;
        }
                next = next->chain;
                *new = next;
        }
-       if (next == NIL)
+       if (next == NLNIL)
                return("");
 #ifdef OBJ
        if (opt('k') && CGENNING )
                return("");
 #ifdef OBJ
        if (opt('k') && CGENNING )
@@ -536,12 +578,12 @@ putspace(n)
                /*
                 * code disabled - do nothing
                 */
                /*
                 * code disabled - do nothing
                 */
-               return(lc);
+               return;
 #ifdef DEBUG
        if (opt('k'))
                printf("%5d\t.=.+%d\n", lc - HEADER_BYTES, n);
 #endif
 #ifdef DEBUG
        if (opt('k'))
                printf("%5d\t.=.+%d\n", lc - HEADER_BYTES, n);
 #endif
-       for (i = even(n); i > 0; i -= 2)
+       for (i = n; i > 0; i -= 2)
                word(0);
 }
 
                word(0);
 }
 
@@ -558,7 +600,7 @@ putstr(sptr, padding)
                /*
                 * code disabled - do nothing
                 */
                /*
                 * code disabled - do nothing
                 */
-               return(lc);
+               return;
 #ifdef DEBUG
        if (opt('k'))
                printf("%5d\t\t\"%s\"\n", lc-HEADER_BYTES, strptr);
 #ifdef DEBUG
        if (opt('k'))
                printf("%5d\t\t\"%s\"\n", lc-HEADER_BYTES, strptr);
@@ -576,7 +618,7 @@ putstr(sptr, padding)
 #                              else
                                    w |= *++strptr;
 #                              endif DEC11
 #                              else
                                    w |= *++strptr;
 #                              endif DEC11
-                       word(w);
+                       word((int) w);
                } while (*strptr++);
        } else {
 #              ifdef DEC11
                } while (*strptr++);
        } else {
 #              ifdef DEC11
@@ -589,7 +631,7 @@ putstr(sptr, padding)
                                            w |= ' ' << 8;
                                            pad--;
                                    }
                                            w |= ' ' << 8;
                                            pad--;
                                    }
-                                   word(w);
+                                   word((int) w);
                            }
                    } while (*strptr++);
 #              else
                            }
                    } while (*strptr++);
 #              else
@@ -626,6 +668,7 @@ putstr(sptr, padding)
 }
 #endif OBJ
 
 }
 #endif OBJ
 
+#ifndef PC
 lenstr(sptr, padding)
 
        char *sptr;
 lenstr(sptr, padding)
 
        char *sptr;
@@ -641,6 +684,7 @@ lenstr(sptr, padding)
        } while (*strptr++);
        return((++cnt) & ~1);
 }
        } while (*strptr++);
        return((++cnt) & ~1);
 }
+#endif
 \f
 /*
  * Patch repairs the branch
 \f
 /*
  * Patch repairs the branch
@@ -651,18 +695,20 @@ lenstr(sptr, padding)
  *     lets here it for two pass assemblers.
  */
 patch(loc)
  *     lets here it for two pass assemblers.
  */
 patch(loc)
+    PTR_DCL loc;
 {
 
 #      ifdef OBJ
            patchfil(loc, (long)(lc-loc-2), 1);
 #      endif OBJ
 #      ifdef PC
 {
 
 #      ifdef OBJ
            patchfil(loc, (long)(lc-loc-2), 1);
 #      endif OBJ
 #      ifdef PC
-           putlab( loc );
+           (void) putlab((char *) loc );
 #      endif PC
 }
 
 #ifdef OBJ
 patch4(loc)
 #      endif PC
 }
 
 #ifdef OBJ
 patch4(loc)
+PTR_DCL loc;
 {
        patchfil(loc, (long)(lc - HEADER_BYTES), 2);
 }
 {
        patchfil(loc, (long)(lc - HEADER_BYTES), 2);
 }
@@ -677,6 +723,7 @@ patchfil(loc, jmploc, words)
        int words;
 {
        register i;
        int words;
 {
        register i;
+       extern long lseek();
        short val;
 
        if ( !CGENNING )
        short val;
 
        if ( !CGENNING )
@@ -699,9 +746,9 @@ patchfil(loc, jmploc, words)
                if (i >= 0 && i < 1024) {
                        obuf[i] = val;
                } else {
                if (i >= 0 && i < 1024) {
                        obuf[i] = val;
                } else {
-                       lseek(ofil, (long) loc+2, 0);
-                       write(ofil, &val, 2);
-                       lseek(ofil, (long) 0, 2);
+                       (void) lseek(ofil, (long) loc+2, 0);
+                       write(ofil, (char *) (&val), 2);
+                       (void) lseek(ofil, (long) 0, 2);
                }
                loc += 2;
 #              ifdef DEC11
                }
                loc += 2;
 #              ifdef DEC11
@@ -733,7 +780,7 @@ pflush()
        register i;
 
        i = (obufp - ( ( short * ) obuf ) ) * 2;
        register i;
 
        i = (obufp - ( ( short * ) obuf ) ) * 2;
-       if (i != 0 && write(ofil, obuf, i) != i)
+       if (i != 0 && write(ofil, (char *) obuf, i) != i)
                perror(obj), pexit(DIED);
        obufp = obuf;
 }
                perror(obj), pexit(DIED);
        obufp = obuf;
 }
@@ -744,6 +791,7 @@ pflush()
  * included here for the eventual code generator.
  *     for PC, thank you!
  */
  * included here for the eventual code generator.
  *     for PC, thank you!
  */
+char *
 getlab()
 {
 #      ifdef OBJ
 getlab()
 {
 #      ifdef OBJ
@@ -753,7 +801,7 @@ getlab()
 #      ifdef PC
            static long lastlabel;
 
 #      ifdef PC
            static long lastlabel;
 
-           return ( ++lastlabel );
+           return ( (char *) ++lastlabel );
 #      endif PC
 }
 
 #      endif PC
 }
 
@@ -761,12 +809,13 @@ getlab()
  * Putlab - lay down a label.
  *     for PC, just print the label name with a colon after it.
  */
  * Putlab - lay down a label.
  *     for PC, just print the label name with a colon after it.
  */
+char *
 putlab(l)
 putlab(l)
-       int l;
+       char *l;
 {
 
 #      ifdef PC
 {
 
 #      ifdef PC
-           putprintf( PREFIXFORMAT , 1 , LABELPREFIX , l );
+           putprintf( PREFIXFORMAT , 1 , (int) LABELPREFIX , (int) l );
            putprintf( ":" , 0 );
 #      endif PC
        return (l);
            putprintf( ":" , 0 );
 #      endif PC
        return (l);