BSD 4 release
[unix-history] / usr / src / cmd / pi / yymain.c
index 6da143d..dc193cd 100644 (file)
@@ -1,21 +1,13 @@
 /* Copyright (c) 1979 Regents of the University of California */
 /* Copyright (c) 1979 Regents of the University of California */
-#
-/*
- * pi - Pascal interpreter code translator
- *
- * Charles Haley, Bill Joy UCB
- * Version 1.2 November 1978
- *
- *
- * pxp - Pascal execution profiler
- *
- * Bill Joy UCB
- * Version 1.2 November 1978
- */
 
 
-#include "whoami"
+static char sccsid[] = "@(#)yymain.c 1.1 8/27/80";
+
+#include "whoami.h"
 #include "0.h"
 #include "yy.h"
 #include "0.h"
 #include "yy.h"
+#include <a.out.h>
+#include "objfmt.h"
+#include <signal.h>
 
 short  line = 1;
 
 
 short  line = 1;
 
@@ -43,8 +35,9 @@ yymain()
 #endif
 
 #ifdef PI
 #endif
 
 #ifdef PI
+#   ifdef OBJ
        magic();
        magic();
-
+#   endif OBJ
 #endif
        /*
         * Initialize the clusters
 #endif
        /*
         * Initialize the clusters
@@ -62,10 +55,12 @@ yymain()
         */
        yyparse();
 #ifdef PI
         */
        yyparse();
 #ifdef PI
+#   ifdef OBJ
        magic2();
        magic2();
-#ifdef DEBUG
+#   endif OBJ
+#   ifdef DEBUG
        dumpnl(0);
        dumpnl(0);
-#endif
+#   endif
 #endif
 #ifdef PXP
        prttab();
 #endif
 #ifdef PXP
        prttab();
@@ -79,8 +74,8 @@ yymain()
                        writef(2, "File not rewritten because of errors\n");
                        pexit(ERRS);
                }
                        writef(2, "File not rewritten because of errors\n");
                        pexit(ERRS);
                }
-               signal(1, 1);
-               signal(2, 1);
+               signal(SIGHUP, SIG_IGN);
+               signal(SIGINT, SIG_IGN);
                copyfile();
        }
 #endif
                copyfile();
        }
 #endif
@@ -109,57 +104,53 @@ copyfile()
 #endif
 
 static
 #endif
 
 static
-struct {
-       int             magic;
-       unsigned        txt_size;
-       unsigned        data_size;
-       unsigned        bss_size;
-       unsigned        syms_size;
-       unsigned        entry_point;
-       unsigned        tr_size;
-       unsigned        dr_size;
-} header;
+struct exec magichdr;
 
 #ifdef PI
 
 #ifdef PI
+#ifdef OBJ
 magic()
 {
 
 magic()
 {
 
-       short           buf[PX_HEAD_BYTES / sizeof ( short )];
+       short           buf[HEADER_BYTES / sizeof ( short )];
        unsigned        *ubuf = buf;
        register int    hf, i;
 
        unsigned        *ubuf = buf;
        register int    hf, i;
 
-       hf = open("/usr/lib/px_header", 0);
-       if (hf >= 0 && read(hf, buf, PX_HEAD_BYTES) > sizeof header) {
-               header.magic = ubuf[0];
-               header.txt_size = ubuf[1];
-               header.data_size = ubuf[2];
-               header.bss_size = ubuf[3];
-               header.syms_size = ubuf[4];
-               header.entry_point = ubuf[5];
-               header.tr_size = ubuf[6];
-               header.dr_size = ubuf[7];
-               for (i = 0; i < PX_HEAD_BYTES / sizeof ( short ); i++)
+       hf = open(PX_HEADER,0);
+       if (hf >= 0 && read(hf, buf, HEADER_BYTES) > sizeof(struct exec)) {
+               magichdr.a_magic = ubuf[0];
+               magichdr.a_text = ubuf[1];
+               magichdr.a_data = ubuf[2];
+               magichdr.a_bss = ubuf[3];
+               magichdr.a_syms = ubuf[4];
+               magichdr.a_entry = ubuf[5];
+               magichdr.a_trsize = ubuf[6];
+               magichdr.a_drsize = ubuf[7];
+               for (i = 0; i < HEADER_BYTES / sizeof ( short ); i++)
                        word(buf[i]);
        }
        close(hf);
                        word(buf[i]);
        }
        close(hf);
-       word(0404);
 }
 }
+#endif OBJ
 
 
+#ifdef OBJ
 magic2()
 {
 magic2()
 {
-       int i;
+       struct pxhdr pxhd;
 
 
-       if  (header.magic != 0407)
+       if  (magichdr.a_magic != 0407)
                panic ( "magic2" );
        pflush();
        lseek(ofil, 0l, 0);
                panic ( "magic2" );
        pflush();
        lseek(ofil, 0l, 0);
-       header.data_size = ( unsigned ) lc - header.txt_size;
-       header.data_size =- sizeof header;
-       write(ofil, &header, sizeof header);
-       lseek(ofil, ( long ) ( PX_HEAD_BYTES - sizeof ( int ) ) , 0);
-       i = ( ( unsigned ) lc) - PX_HEAD_BYTES;
-       write(ofil, &i, sizeof (int));
+       magichdr.a_data = ( unsigned ) lc - magichdr.a_text;
+       magichdr.a_data -= sizeof (struct exec);
+       write(ofil, &magichdr, sizeof(struct exec));
+       pxhd.objsize = ( ( unsigned ) lc) - HEADER_BYTES;
+       pxhd.maketime = time(0);
+       pxhd.magicnum = MAGICNUM;
+       lseek(ofil, ( long ) ( HEADER_BYTES - sizeof ( pxhd ) ) , 0);
+       write(ofil, &pxhd, sizeof (pxhd));
 }
 }
+#endif OBJ
 #endif
 
 #ifdef PXP
 #endif
 
 #ifdef PXP