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