1*f7923656Sespie #ifndef LOWPARSE_H 2*f7923656Sespie #define LOWPARSE_H 3*f7923656Sespie 404ed836eSespie /* $OpenPackages$ */ 5*f7923656Sespie /* $OpenBSD: lowparse.h,v 1.4 2001/05/23 12:34:45 espie Exp $ */ 6d368bdefSespie 7d368bdefSespie /* 8d368bdefSespie * Copyright (c) 1999 Marc Espie. 9d368bdefSespie * 10d368bdefSespie * Extensive code changes for the OpenBSD project. 11d368bdefSespie * 12d368bdefSespie * Redistribution and use in source and binary forms, with or without 13d368bdefSespie * modification, are permitted provided that the following conditions 14d368bdefSespie * are met: 15d368bdefSespie * 1. Redistributions of source code must retain the above copyright 16d368bdefSespie * notice, this list of conditions and the following disclaimer. 17d368bdefSespie * 2. Redistributions in binary form must reproduce the above copyright 18d368bdefSespie * notice, this list of conditions and the following disclaimer in the 19d368bdefSespie * documentation and/or other materials provided with the distribution. 20d368bdefSespie * 21d368bdefSespie * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 22d368bdefSespie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23d368bdefSespie * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24d368bdefSespie * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 25d368bdefSespie * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26d368bdefSespie * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27d368bdefSespie * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28d368bdefSespie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29d368bdefSespie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30d368bdefSespie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31d368bdefSespie * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32d368bdefSespie */ 33*f7923656Sespie /* low-level parsing module: 34*f7923656Sespie * select input stream to parse, and do high-speed processing of 35*f7923656Sespie * lines: skipping comments, handling continuation lines, or skipping 36*f7923656Sespie * over dead conditionals. 37*f7923656Sespie * 38*f7923656Sespie * Basic template: 39*f7923656Sespie * 40*f7923656Sespie * Parse_Fromxxx(source); 41*f7923656Sespie * do { 42*f7923656Sespie * while ((line = Parse_ReadNormalLine(&buf)) != NULL) { 43*f7923656Sespie * handle line, use Parse_Fromxxx to push includes, 44*f7923656Sespie * Parse_ReadNextConditional to get over non-conditional lines. 45*f7923656Sespie * or Parse_ReadUnparsedLine to handle special cases manually. 46*f7923656Sespie * } 47*f7923656Sespie * } while (Parse_NextFile()); 48*f7923656Sespie */ 49*f7923656Sespie 50*f7923656Sespie /* Initialization and cleanup */ 51d368bdefSespie #ifdef CLEANUP 5204ed836eSespie extern void LowParse_Init(void); 5304ed836eSespie extern void LowParse_End(void); 54*f7923656Sespie #else 55*f7923656Sespie #define LowParse_Init() 56*f7923656Sespie #define LowParse_End() 57d368bdefSespie #endif 58*f7923656Sespie 59*f7923656Sespie /* Selection of input stream */ 60*f7923656Sespie /* Parse_FromFile(filename, filehandle); 61*f7923656Sespie * Push given filehandle on the input stack, using filename for diagnostic 62*f7923656Sespie * messages. The module assumes ownership of the filehandle and of 63*f7923656Sespie * the filename: provide copies if necessary. */ 64*f7923656Sespie extern void Parse_FromFile(const char *, FILE *); 65*f7923656Sespie /* Parse_FromString(str, lineno); 66*f7923656Sespie * Push expanded string str on the input stack, assuming it starts at 67*f7923656Sespie * lineno in the current file. This is used to reparse .for loops 68*f7923656Sespie * after the variable has been expanded, hence no need to respecify 69*f7923656Sespie * the filename. The module assumes ownership of the string: provide a 70*f7923656Sespie * copy if necessary. */ 71*f7923656Sespie extern void Parse_FromString(char *, unsigned long); 72*f7923656Sespie 73*f7923656Sespie /* Error reporting, and tagging of read structures. */ 74*f7923656Sespie /* lineno = Parse_Getlineno(); 75*f7923656Sespie * Returns the current lineno. */ 76*f7923656Sespie extern unsigned long Parse_Getlineno(void); 77*f7923656Sespie /* name = Parse_Getfilename(); 78*f7923656Sespie * Returns the current filename. Safe to keep without copying. */ 79*f7923656Sespie extern const char *Parse_Getfilename(void); 80*f7923656Sespie 81*f7923656Sespie /* continue = Parse_NextFile(); 82*f7923656Sespie * Advance parsing to the next file in the input stack. Returns true 83*f7923656Sespie * if there is parsing left to do. 84*f7923656Sespie */ 85*f7923656Sespie extern bool Parse_NextFile(void); 86*f7923656Sespie 87*f7923656Sespie 88*f7923656Sespie /* line = Parse_ReadNormalLine(buf); 89*f7923656Sespie * Reads next line into buffer and return its contents. Handles line 90*f7923656Sespie * continuation, remove extra blanks, and skip trivial comments. tabs at 91*f7923656Sespie * beginning of line are left alone, to be able to recognize target 92*f7923656Sespie * lines. */ 93*f7923656Sespie extern char *Parse_ReadNormalLine(Buffer); 94*f7923656Sespie 95*f7923656Sespie /* line = ParseReadNextConditionalLine(buf); 96*f7923656Sespie * Returns next conditional line, skipping over everything else. */ 97*f7923656Sespie extern char *Parse_ReadNextConditionalLine(Buffer); 98*f7923656Sespie /* line = ParseReadUnparsedLine(buf, type); 99*f7923656Sespie * Reads line without parsing anything beyond continuations. 100*f7923656Sespie * Handle special cases such as conditional lines, or lines that 101*f7923656Sespie * need a reparse (loops). */ 102*f7923656Sespie extern char *Parse_ReadUnparsedLine(Buffer, const char *); 103*f7923656Sespie /* Parse_ReportErrors(); 104*f7923656Sespie * At end of parsing, report on fatal errors. 105*f7923656Sespie */ 106*f7923656Sespie extern void Parse_ReportErrors(void); 107d368bdefSespie #endif 108