home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pxp / yymain.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  159 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pi - Pascal interpreter code translator
  5.  *
  6.  * Charles Haley, Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  *
  9.  *
  10.  * pxp - Pascal execution profiler
  11.  *
  12.  * Bill Joy UCB
  13.  * Version 1.2 January 1979
  14.  */
  15.  
  16. #include "0.h"
  17. #include "yy.h"
  18.  
  19. int    line 1;
  20.  
  21. /*
  22.  * Yymain initializes each of the utility
  23.  * clusters and then starts the processing
  24.  * by calling yyparse.
  25.  */
  26. yymain()
  27. {
  28.  
  29.     /*
  30.      * Initialize the scanner
  31.      */
  32. #ifdef PXP
  33.     if (bracket == 0) {
  34. #endif
  35.         if (getline() == -1) {
  36.             Perror(filename, "No lines in file");
  37.             pexit(NOSTART);
  38.         }
  39. #ifdef PXP
  40.     } else
  41.         yyline = 0;
  42. #endif
  43.  
  44. #ifdef PI
  45.     magic();
  46.  
  47. #endif
  48.     /*
  49.      * Initialize the clusters
  50.      *
  51.     initstring();
  52.      */
  53.     inithash();
  54.     inittree();
  55. #ifdef PI
  56.     initnl();
  57. #endif
  58.  
  59.     /*
  60.      * Process the input
  61.      */
  62.     yyparse();
  63. #ifdef PI
  64.     magic2();
  65. #ifdef DEBUG
  66.     dumpnl(0);
  67. #endif
  68. #endif
  69. #ifdef PXP
  70.     prttab();
  71.     if (onefile) {
  72.         extern int outcol;
  73.  
  74.         if (outcol)
  75.             putchar('\n');
  76.         flush();
  77.         if (eflg) {
  78.             writef(2, "File not rewritten because of errors\n");
  79.             pexit(ERRS);
  80.         }
  81.         signal(1, 1);
  82.         signal(2, 1);
  83.         copyfile();
  84.     }
  85. #endif
  86.     pexit(eflg ? ERRS : AOK);
  87. }
  88.  
  89. #ifdef PXP
  90. copyfile()
  91. {
  92.     extern int fout[];
  93.     register int c;
  94.  
  95.     close(1);
  96.     if (creat(firstname, 0644) != 1) {
  97.         perror(firstname);
  98.         pexit(ERRS);
  99.     }
  100.     seek(fout[0], 0, 0);
  101.     while ((c = read(fout[0], &fout[3], 512)) > 0) {
  102.         if (write(1, &fout[3], c) != c) {
  103.             perror(firstname);
  104.             pexit(ERRS);
  105.         }
  106.     }
  107. }
  108. #endif
  109.  
  110. static
  111. struct {
  112.     int magic;
  113.     int txt_size;
  114.     int data_size;
  115. } header;
  116.  
  117. #ifdef PI
  118. magic()
  119. {
  120.     int buf[512];
  121.     register int hf, i;
  122.  
  123.     hf = open("/usr/lib/npx_header", 0);
  124.     if (hf >= 0 && read(hf, buf, 1024) > 16) {
  125.         header.magic = buf[0];
  126.         header.txt_size = buf[1];
  127.         header.data_size = buf[2];
  128.         for (i = 0; i < 512; i++)
  129.             word(buf[i]);
  130.     }
  131.     close(hf);
  132.     word(0404);
  133. }
  134.  
  135. magic2()
  136. {
  137.     int i;
  138.  
  139.     if (header.magic != 0407)
  140.         return;
  141.     pflush();
  142.     seek(ofil, 0, 0);
  143.     header.data_size = lc - header.txt_size;
  144.     header.data_size =- 16;
  145.     write(ofil, &header, sizeof header);
  146.     seek(ofil, 1022, 0);
  147.     i = ((int) lc) - 1024;
  148.     write(ofil, &i, 2);
  149. }
  150. #endif
  151.  
  152. #ifdef PXP
  153. writef(i, cp)
  154. {
  155.  
  156.     write(i, cp, strlen(cp));
  157. }
  158. #endif
  159.