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