* Copyright (c) 1980 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
static char sccsid
[] = "@(#)yyget.c 5.3 (Berkeley) 4/16/91";
#include "tree_ty.h" /* must be included for yy.h */
* Readch returns the next
* character from the current
* input line or -1 on end-of-file.
* It also maintains yycol for use in
* printing error messages.
if (*bufp
== '\n' && bufp
>= charbuf
) {
yycol
= ((yycol
+ 8) & ~7);
* Definitions of the structures used for the
* include facility. The variable "ibp" points
* to the getc buffer of the current input file.
* There are "inclev + 1" current include files,
* and information in saved in the incs stack
* whenever a new level of include nesting occurs.
* Ibp in the incs structure saves the pointer
* to the previous levels input buffer;
* filename saves the previous file name;
* Printed saves whether the previous file name
* had been printed before this nesting occurred;
* and yyline is the line we were on on the previous file.
* These initializations survive only if
* pxp is asked to pretty print one file.
* Otherwise they are destroyed by the initial
char charbuf
[CBSIZE
] = " program x(output);\n";
* YyLinpt is the seek pointer to the beginning of the
* Getline places the next line
* from the input stream in the
* line buffer, returning -1 at YEOF.
if (opt('l') && yyprtd
== 0)
if (ateof
== 0 && bracket
) {
(void) pstrcpy(charbuf
, "begin end.\n");
error("Input line too long - QUIT");
yyLinpt
= yylinpt
+ cp
- charbuf
;
else if (cp
== &charbuf
[2])
* Check an input line to see if it is a "#include" pseudo-statement.
* We allow arbitrary blanks in the line and the file name
* may be delimited by either 's or "s. A single semicolon
* may be placed after the name, but nothing else is allowed
for (dp
= "include"; *dp
; dp
++)
if (ch
!= '\'' && ch
!= '"') {
* This should be a yerror flagging the place
* but its not worth figuring out the column.
error("Include syntax error - expected ' or \" not found - QUIT");
for (dp
= cp
; *dp
!= ch
; dp
++)
error("Missing closing %c for include file name - QUIT", (char *) ch
);
* error("Garbage after filename in include");
if (!dotted(cp
, 'i') && !dotted(cp
, 'h')) {
error("Include filename must end in .i or .h");
error("Absurdly deep include nesting - QUIT");
* For the debugger pdx, we need to note that we've changed files.
* left over from before stdio
* error("Ran out of memory (include)");
if ( ( ibp
= fopen(filename
, "r" ) ) == NULL
) {
if (inpflist(filename
)) {
* left over from before stdio
stabinclude( filename
, TRUE
);
while (*cp
== ' ' || *cp
== '\t')
* At the end of an include,
* close the file, free the input buffer,
* and restore the environment before
* the "push", including the value of
* the z option for pxp and the l option for pi.
* left over from before stdio: becomes fclose ( ibp )
if (inpflist(filename
)) {
* If we printed out the nested name,
* then we should print all covered names again.
* If we didn't print out the nested name
* we print the uncovered name only if it
* has not been printed before (unstack).
* For the debugger pdx, we need to note that we've changed files.
newfile(filename
, yyline
);
stabinclude( filename
, FALSE
);