date and time created 81/03/02 21:27:50 by peter
[unix-history] / usr / src / usr.bin / pascal / pc3 / pc3.c
index 9fe0a7e..fc72a5c 100644 (file)
@@ -1,6 +1,6 @@
     /* Copyright (c) 1980 Regents of the University of California */
 
     /* Copyright (c) 1980 Regents of the University of California */
 
-static char sccsid[] = "@(#)pc3.c 1.1 %G%";
+static char sccsid[] = "@(#)pc3.c 1.6 %G%";
 
     /*
      *      Pc3 is a pass in the Berkeley Pascal compilation
 
     /*
      *      Pc3 is a pass in the Berkeley Pascal compilation
@@ -28,7 +28,7 @@ static        char sccsid[] = "@(#)pc3.c 1.1 %G%";
      * is:
      * 
      *    - the name of the symbol;
      * is:
      * 
      *    - the name of the symbol;
-     *    - a type specifier;
+     *    - a subtype descriptor;
      *    - for file symbols, their last modify time;
      *    - the file which logically contains the declaration of
      *      the symbol (not an include file);
      *    - for file symbols, their last modify time;
      *    - the file which logically contains the declaration of
      *      the symbol (not an include file);
@@ -61,7 +61,7 @@ static        char sccsid[] = "@(#)pc3.c 1.1 %G%";
      * function is not resolved at least once.
      */
 \f
      * function is not resolved at least once.
      */
 \f
-char   program[] = "pc3";
+char   program[] = "pc";
 
 #include <sys/types.h>
 #include <ar.h>
 
 #include <sys/types.h>
 #include <ar.h>
@@ -71,7 +71,7 @@ char  program[] = "pc3";
 #include <stab.h>
 #include <pagsiz.h>
 #include <stat.h>
 #include <stab.h>
 #include <pagsiz.h>
 #include <stat.h>
-#include "/usr/src/new/pc0/p.a.out.h"
+#include "pstab.h"
 #include "pc3.h"
 
 int    errors = 0;
 #include "pc3.h"
 
 int    errors = 0;
@@ -85,15 +85,12 @@ main( argc , argv )
     {
        struct fileinfo ofile;
 
     {
        struct fileinfo ofile;
 
-       argc--;
-       argv++;
-       while ( argc-- ) {
+       while ( ++argv , --argc ) {
 #          ifdef DEBUG
                fprintf( stderr , "[main] *argv = %s\n" , *argv );
 #          endif DEBUG
            ofile.name = *argv;
            checkfile( &ofile );
 #          ifdef DEBUG
                fprintf( stderr , "[main] *argv = %s\n" , *argv );
 #          endif DEBUG
            ofile.name = *argv;
            checkfile( &ofile );
-           argv++;
        }
        exit( errors );
     }
        }
        exit( errors );
     }
@@ -161,7 +158,7 @@ checknl( ofilep )
     {
     
        long                    red;
     {
     
        long                    red;
-       struct exec             aexec;
+       struct exec             oexec;
        off_t                   symoff;
        long                    numsyms;
        register struct nlist   *nlp;
        off_t                   symoff;
        long                    numsyms;
        register struct nlist   *nlp;
@@ -169,18 +166,18 @@ checknl( ofilep )
        long                    strsize;
        long                    sym;
 
        long                    strsize;
        long                    sym;
 
-       red = fread( (char *) &aexec , 1 , sizeof aexec , ofilep -> file );
-       if ( red != sizeof aexec ) {
+       red = fread( (char *) &oexec , 1 , sizeof oexec , ofilep -> file );
+       if ( red != sizeof oexec ) {
            error( WARNING , "error reading struct exec: %s"
                    , ofilep -> name );
            return;
        }
            error( WARNING , "error reading struct exec: %s"
                    , ofilep -> name );
            return;
        }
-       if ( N_BADMAG( aexec ) ) {
+       if ( N_BADMAG( oexec ) ) {
            return;
        }
            return;
        }
-       symoff = N_SYMOFF( aexec ) - sizeof aexec;
+       symoff = N_SYMOFF( oexec ) - sizeof oexec;
        fseek( ofilep -> file , symoff , 1 );
        fseek( ofilep -> file , symoff , 1 );
-       numsyms = aexec.a_syms / sizeof ( struct nlist );
+       numsyms = oexec.a_syms / sizeof ( struct nlist );
        if ( numsyms == 0 ) {
            error( WARNING , "no name list: %s" , ofilep -> name );
            return;
        if ( numsyms == 0 ) {
            error( WARNING , "no name list: %s" , ofilep -> name );
            return;
@@ -256,65 +253,52 @@ checksymbol( nlp , ofilep )
                fprintf( stderr , "[checksymbol] pfile %s ifile %s\n"
                        , pfilep -> name , ifilep -> name );
            }
                fprintf( stderr , "[checksymbol] pfile %s ifile %s\n"
                        , pfilep -> name , ifilep -> name );
            }
-           fprintf( stderr , "[checksymbol] ->name %s ->n_type %x (%s)\n"
-                   , nlp -> n_un.n_name , nlp -> n_type
-                   , classify( nlp -> n_type ) );
+           fprintf( stderr , "[checksymbol] ->name %s ->n_desc %x (%s)\n"
+                   , nlp -> n_un.n_name , nlp -> n_desc
+                   , classify( nlp -> n_desc ) );
 #      endif DEBUG
 #      endif DEBUG
-       switch ( nlp -> n_type ) {
-           case N_PGLAB:
-           case N_PGCON:
-           case N_PGTYP:
-           case N_PGVAR:
-           case N_PGFUN:
-           case N_PGPRC:
-           case N_PEFUN:
-           case N_PEPRC:
-           case N_PSO:
-           case N_PSOL:
-                   symbolp = entersymbol( nlp -> n_un.n_name );
-                   break;
-           default:
-                       /* don't care about the others */
-                   return;
+       if ( nlp -> n_type != N_PC ) {
+               /* don't care about the others */
+           return;
        }
        }
+       symbolp = entersymbol( nlp -> n_un.n_name );
        if ( symbolp -> lookup == NEW ) {
 #          ifdef DEBUG
                fprintf( stderr , "[checksymbol] ->name %s is NEW\n"
                        , symbolp -> name );
 #          endif DEBUG
        if ( symbolp -> lookup == NEW ) {
 #          ifdef DEBUG
                fprintf( stderr , "[checksymbol] ->name %s is NEW\n"
                        , symbolp -> name );
 #          endif DEBUG
-           symbolp -> type = nlp -> n_type;
-           switch ( symbolp -> type ) {
-               case N_PGLAB:
-               case N_PGCON:
-               case N_PGTYP:
+           symbolp -> desc = nlp -> n_desc;
+           switch ( symbolp -> desc ) {
+               case N_PGLABEL:
+               case N_PGCONST:
+               case N_PGTYPE:
                case N_PGVAR:
                case N_PGVAR:
-               case N_PGFUN:
-               case N_PGPRC:
-                       /* and fall through */
-               case N_PEFUN:
-               case N_PEPRC:
+               case N_PGFUNC:
+               case N_PGPROC:
+                       symbolp -> sym_un.sym_str.rfilep = ifilep;
+                       symbolp -> sym_un.sym_str.rline = nlp -> n_value;
                        symbolp -> sym_un.sym_str.fromp = pfilep;
                        symbolp -> sym_un.sym_str.fromi = ifilep;
                        symbolp -> sym_un.sym_str.iline = nlp -> n_value;
                        symbolp -> sym_un.sym_str.fromp = pfilep;
                        symbolp -> sym_un.sym_str.fromi = ifilep;
                        symbolp -> sym_un.sym_str.iline = nlp -> n_value;
-                       if (  symbolp -> type != N_PEFUN
-                          && symbolp -> type != N_PEPRC ) {
-                           symbolp -> sym_un.sym_str.rfilep = ifilep;
-                           symbolp -> sym_un.sym_str.rline = nlp -> n_value;
-                       } else {
-                           symbolp -> sym_un.sym_str.rfilep = NIL;
-                           symbolp -> sym_un.sym_str.rline = 0;
-                               /*
-                                *      functions can only be declared external
-                                *      in included files.
-                                */
-                           if ( pfilep == ifilep ) {
-                               error( WARNING
-                                       , "%s, line %d: %s %s must be declared in included file"
-                                       , pfilep -> name , nlp -> n_value
-                                       , classify( symbolp -> type )
-                                       , symbolp -> name );
-                           }
+                       return;
+               case N_PEFUNC:
+               case N_PEPROC:
+                       symbolp -> sym_un.sym_str.rfilep = NIL;
+                       symbolp -> sym_un.sym_str.rline = 0;
+                           /*
+                            *  functions can only be declared external
+                            *  in included files.
+                            */
+                       if ( pfilep == ifilep ) {
+                           error( WARNING
+                                   , "%s, line %d: %s %s must be declared in included file"
+                                   , pfilep -> name , nlp -> n_value
+                                   , classify( symbolp -> desc )
+                                   , symbolp -> name );
                        }
                        }
+                       symbolp -> sym_un.sym_str.fromp = pfilep;
+                       symbolp -> sym_un.sym_str.fromi = ifilep;
+                       symbolp -> sym_un.sym_str.iline = nlp -> n_value;
                        return;
                case N_PSO:
                        pfilep = symbolp;
                        return;
                case N_PSO:
                        pfilep = symbolp;
@@ -333,7 +317,7 @@ checksymbol( nlp , ofilep )
                fprintf( stderr , "[checksymbol] ->name %s is OLD\n"
                        , symbolp -> name );
 #          endif DEBUG
                fprintf( stderr , "[checksymbol] ->name %s is OLD\n"
                        , symbolp -> name );
 #          endif DEBUG
-           switch ( symbolp -> type ) {
+           switch ( symbolp -> desc ) {
                case N_PSO:
                            /*
                             *  finding a file again means you are back
                case N_PSO:
                            /*
                             *  finding a file again means you are back
@@ -355,15 +339,15 @@ checksymbol( nlp , ofilep )
                                    , ofilep -> name , symbolp -> name );
                        }
                        return;
                                    , ofilep -> name , symbolp -> name );
                        }
                        return;
-               case N_PEFUN:
-               case N_PEPRC:
+               case N_PEFUNC:
+               case N_PEPROC:
                            /*
                             *  we may see any number of external declarations,
                             *  but they all have to come
                             *  from the same include file.
                             */
                            /*
                             *  we may see any number of external declarations,
                             *  but they all have to come
                             *  from the same include file.
                             */
-                       if (   nlp -> n_type == N_PEFUN
-                           || nlp -> n_type == N_PEPRC ) {
+                       if (   nlp -> n_desc == N_PEFUNC
+                           || nlp -> n_desc == N_PEPROC ) {
                            goto included;
                        }
                            /*
                            goto included;
                        }
                            /*
@@ -372,10 +356,10 @@ checksymbol( nlp , ofilep )
                             *  if the resolving file
                             *  included the external declaration.
                             */
                             *  if the resolving file
                             *  included the external declaration.
                             */
-                       if (    (  symbolp -> type == N_PEFUN
-                               && nlp -> n_type != N_PGFUN )
-                           ||  (  symbolp -> type == N_PEPRC
-                               && nlp -> n_type != N_PGPRC )
+                       if (    (  symbolp -> desc == N_PEFUNC
+                               && nlp -> n_desc != N_PGFUNC )
+                           ||  (  symbolp -> desc == N_PEPROC
+                               && nlp -> n_desc != N_PGPROC )
                            || symbolp -> sym_un.sym_str.fromp != pfilep ) {
                            break;
                        }
                            || symbolp -> sym_un.sym_str.fromp != pfilep ) {
                            break;
                        }
@@ -388,17 +372,17 @@ checksymbol( nlp , ofilep )
                        symbolp -> sym_un.sym_str.rfilep = ifilep;
                        symbolp -> sym_un.sym_str.rline = nlp -> n_value;
                        return;
                        symbolp -> sym_un.sym_str.rfilep = ifilep;
                        symbolp -> sym_un.sym_str.rline = nlp -> n_value;
                        return;
-               case N_PGFUN:
-               case N_PGPRC:
+               case N_PGFUNC:
+               case N_PGPROC:
                            /*
                             *  functions may not be seen more than once.
                             *  the loader will complain about
                             *  `multiply defined', but we can, too.
                             */
                        break;
                            /*
                             *  functions may not be seen more than once.
                             *  the loader will complain about
                             *  `multiply defined', but we can, too.
                             */
                        break;
-               case N_PGLAB:
-               case N_PGCON:
-               case N_PGTYP:
+               case N_PGLABEL:
+               case N_PGCONST:
+               case N_PGTYPE:
                case N_PGVAR:
                            /*
                             *  labels, constants, types, variables
                case N_PGVAR:
                            /*
                             *  labels, constants, types, variables
@@ -408,7 +392,7 @@ checksymbol( nlp , ofilep )
                             *  make it look like they come from this .p file.
                             */
 included:
                             *  make it look like they come from this .p file.
                             */
 included:
-                       if (  nlp -> n_type != symbolp -> type
+                       if (  nlp -> n_desc != symbolp -> desc
                           || symbolp -> sym_un.sym_str.fromi != ifilep ) {
                            break;
                        }
                           || symbolp -> sym_un.sym_str.fromi != ifilep ) {
                            break;
                        }
@@ -433,7 +417,6 @@ included:
      * search is by rehashing within each table,
      * traversing chains to next table if unsuccessful.
      */
      * search is by rehashing within each table,
      * traversing chains to next table if unsuccessful.
      */
-
 struct symbol *
 entersymbol( name )
     char       *name;
 struct symbol *
 entersymbol( name )
     char       *name;
@@ -507,7 +490,6 @@ entersymbol( name )
     /*
      * allocate a symbol from the dynamically allocated symbol table.
      */
     /*
      * allocate a symbol from the dynamically allocated symbol table.
      */
-
 struct symbol *
 symbolalloc()
     {
 struct symbol *
 symbolalloc()
     {
@@ -556,7 +538,6 @@ hashstring( string )
      * search is by rehashing within each table,
      * traversing chains to next table if unsuccessful.
      */
      * search is by rehashing within each table,
      * traversing chains to next table if unsuccessful.
      */
-
 char *
 enterstring( string )
     char       *string;
 char *
 enterstring( string )
     char       *string;
@@ -626,7 +607,6 @@ enterstring( string )
     /*
      * copy a string to the dynamically allocated character table.
      */
     /*
      * copy a string to the dynamically allocated character table.
      */
-
 char *
 charalloc( length )
     register long      length;
 char *
 charalloc( length )
     register long      length;
@@ -714,19 +694,16 @@ time_t
 mtime( filename )
     char       *filename;
     {
 mtime( filename )
     char       *filename;
     {
-       int             file;
        struct stat     filestat;
 
 #      ifdef DEBUG
            fprintf( stderr , "[mtime] filename %s\n"
                    , filename );
 #      endif DEBUG
        struct stat     filestat;
 
 #      ifdef DEBUG
            fprintf( stderr , "[mtime] filename %s\n"
                    , filename );
 #      endif DEBUG
-       file = open( filename , 0 );
-       if ( file == -1 ) {
+       if ( stat( filename , &filestat ) != 0 ) {
            error( WARNING , "%s: cannot open" , filename );
            return ( (time_t) time( 0 ) );
        }
            error( WARNING , "%s: cannot open" , filename );
            return ( (time_t) time( 0 ) );
        }
-       fstat( file , &filestat );
        return filestat.st_mtime;
     }
 
        return filestat.st_mtime;
     }
 
@@ -739,21 +716,21 @@ classify( type )
                return "source file";
            case N_PSOL:
                return "include file";
                return "source file";
            case N_PSOL:
                return "include file";
-           case N_PGLAB:
+           case N_PGLABEL:
                return "label";
                return "label";
-           case N_PGCON:
+           case N_PGCONST:
                return "constant";
                return "constant";
-           case N_PGTYP:
+           case N_PGTYPE:
                return "type";
            case N_PGVAR:
                return "variable";
                return "type";
            case N_PGVAR:
                return "variable";
-           case N_PGFUN:
+           case N_PGFUNC:
                return "function";
                return "function";
-           case N_PGPRC:
+           case N_PGPROC:
                return "procedure";
                return "procedure";
-           case N_PEFUN:
+           case N_PEFUNC:
                return "external function";
                return "external function";
-           case N_PEPRC:
+           case N_PEPROC:
                return "external procedure";
            default:
                return "unknown symbol";
                return "external procedure";
            default:
                return "unknown symbol";