home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / src / yymain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  4.8 KB  |  216 lines

  1. /*-
  2.  * Copyright (c) 1980 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)yymain.c    5.2 (Berkeley) 4/16/91";
  36. #endif /* not lint */
  37.  
  38. #include "whoami.h"
  39. #include "0.h"
  40. #include "tree_ty.h"    /* must be included for yy.h */
  41. #include "yy.h"
  42. #include <a.out.h>
  43. #include "objfmt.h"
  44. #include <signal.h>
  45. #include "config.h"
  46.  
  47. /*
  48.  * Yymain initializes each of the utility
  49.  * clusters and then starts the processing
  50.  * by calling yyparse.
  51.  */
  52. yymain()
  53. {
  54.  
  55. #ifdef OBJ
  56. /*
  57.  * initialize symbol table temp files
  58.  */
  59.     startnlfile();
  60. #endif
  61.     /*
  62.      * Initialize the scanner
  63.      */
  64. #ifdef PXP
  65.     if (bracket == 0) {
  66. #endif
  67.         if (getline() == -1) {
  68.             Perror(filename, "No lines in file");
  69.             pexit(NOSTART);
  70.         }
  71. #ifdef PXP
  72.     } else
  73.         yyline = 0;
  74. #endif
  75.  
  76. #ifdef PI
  77. #   ifdef OBJ
  78.     magic();
  79. #   endif OBJ
  80. #endif
  81.     line = 1;
  82.     errpfx = 'E';
  83.     /*
  84.      * Initialize the clusters
  85.      *
  86.     initstring();
  87.      */
  88.     inithash();
  89.     inittree();
  90. #ifdef PI
  91.     initnl();
  92. #endif
  93.  
  94.     /*
  95.      * Process the input
  96.      */
  97.     yyparse();
  98. #ifdef PI
  99. #   ifdef OBJ
  100.  
  101.     /*
  102.      * save outermost block of namelist
  103.      */
  104.     savenl(NLNIL);
  105.  
  106.     magic2();
  107. #   endif OBJ
  108. #   ifdef DEBUG
  109.     dumpnl(NLNIL);
  110. #   endif
  111. #endif
  112.  
  113. #ifdef PXP
  114.     prttab();
  115.     if (onefile) {
  116.         extern int outcol;
  117.  
  118.         if (outcol)
  119.             pchr('\n');
  120.         flush();
  121.         if (eflg) {
  122.             writef(2, "File not rewritten because of errors\n");
  123.             pexit(ERRS);
  124.         }
  125.         (void) signal(SIGHUP, SIG_IGN);
  126.         (void) signal(SIGINT, SIG_IGN);
  127.         copyfile();
  128.     }
  129. #endif
  130.     pexit(eflg ? ERRS : AOK);
  131. }
  132.  
  133. #ifdef PXP
  134. copyfile()
  135. {
  136.     extern int fout[];
  137.     register int c;
  138.  
  139.     (void) close(1);
  140.     if (creat(firstname, 0644) != 1) {
  141.         perror(firstname);
  142.         pexit(ERRS);
  143.     }
  144.     (void) lseek(fout[0], 0l, 0);
  145.     while ((c = read(fout[0], &fout[3], 512)) > 0) {
  146.         if (write(1, &fout[3], c) != c) {
  147.             perror(firstname);
  148.             pexit(ERRS);
  149.         }
  150.     }
  151. }
  152. #endif
  153.  
  154.  
  155. #ifdef PI
  156. #ifdef OBJ
  157.  
  158. static
  159. struct exec magichdr;
  160.  
  161. magic()
  162. {
  163.  
  164.     short        buf[HEADER_BYTES / sizeof ( short )];
  165.     unsigned    *ubuf = (unsigned *) buf;
  166.     register int    hf, i;
  167.  
  168.     hf = open(px_header,0);
  169.     if (hf >= 0 && read(hf, (char *) buf, HEADER_BYTES) > sizeof(struct exec)) {
  170.         magichdr.a_magic = ubuf[0];
  171.         magichdr.a_text = ubuf[1];
  172.         magichdr.a_data = ubuf[2];
  173.         magichdr.a_bss = ubuf[3];
  174.         magichdr.a_syms = ubuf[4];
  175.         magichdr.a_entry = ubuf[5];
  176.         magichdr.a_trsize = ubuf[6];
  177.         magichdr.a_drsize = ubuf[7];
  178.         for (i = 0; i < HEADER_BYTES / sizeof ( short ); i++)
  179.             word(buf[i]);
  180.     }
  181.     (void) close(hf);
  182. }
  183. #endif OBJ
  184.  
  185. #ifdef OBJ
  186. magic2()
  187. {
  188.     struct pxhdr pxhd;
  189.     extern long lseek();
  190.  
  191.     if  (magichdr.a_magic != 0407)
  192.         panic ( "magic2" );
  193.     pflush();
  194.     magichdr.a_data = ( unsigned ) lc - magichdr.a_text;
  195.     magichdr.a_data -= sizeof (struct exec);
  196.     pxhd.objsize = ( ( unsigned ) lc) - HEADER_BYTES;
  197.     pxhd.symtabsize = nlhdrsize();
  198.     magichdr.a_data += pxhd.symtabsize;
  199.     (void) time((long *) (&pxhd.maketime));
  200.     pxhd.magicnum = MAGICNUM;
  201.     (void) lseek(ofil, 0l, 0);
  202.     write(ofil, (char *) (&magichdr), sizeof(struct exec));
  203.     (void) lseek(ofil, ( long ) ( HEADER_BYTES - sizeof ( pxhd ) ) , 0);
  204.     write(ofil, (char *) (&pxhd), sizeof (pxhd));
  205. }
  206. #endif OBJ
  207. #endif
  208.  
  209. #ifdef PXP
  210. writef(i, cp)
  211. {
  212.  
  213.     write(i, cp, strlen(cp));
  214. }
  215. #endif
  216.