lowparse.h revision 1.10
1#ifndef LOWPARSE_H
2#define LOWPARSE_H
3
4/* $OpenBSD: lowparse.h,v 1.10 2012/09/21 07:55:20 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
51extern void LowParse_Init(void);
52extern 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.  */
63extern 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.  */
70extern void Parse_FromString(char *, unsigned long);
71
72/* Error reporting, and tagging of read structures. */
73/* lineno = Parse_Getlineno();
74 *	Returns the current lineno. */
75extern unsigned long Parse_Getlineno(void);
76/* name = Parse_Getfilename();
77 *	Returns the current filename.  Safe to keep without copying.  */
78extern const char *Parse_Getfilename(void);
79
80/* Parse_FillLocation(origin)
81 * 	Fill the location pointed by origin with the current location. */
82extern void Parse_FillLocation(Location *);
83
84/* Parse_SetLocation(origin)
85 *	Set the "parse location" to a given origin.
86 *	Used for parse errors that occur during variable expansion at
87 *	runtime.
88 */
89extern void Parse_SetLocation(Location *);
90
91/* continue = Parse_NextFile();
92 *	Advance parsing to the next file in the input stack. Returns true
93 *	if there is parsing left to do.
94 */
95extern bool Parse_NextFile(void);
96
97
98/* line = Parse_ReadNormalLine(buf);
99 *	Reads next line into buffer and return its contents.  Handles line
100 *	continuation, remove extra blanks, and skip trivial comments.  tabs at
101 *	beginning of line are left alone, to be able to recognize target
102 *	lines. */
103extern char *Parse_ReadNormalLine(Buffer);
104
105/* line = ParseReadNextConditionalLine(buf);
106 *	Returns next conditional line, skipping over everything else. */
107extern char *Parse_ReadNextConditionalLine(Buffer);
108/* line = ParseReadUnparsedLine(buf, type);
109 *	Reads line without parsing anything beyond continuations.
110 *	Handle special cases such as conditional lines, or lines that
111 *	need a reparse (loops). */
112extern char *Parse_ReadUnparsedLine(Buffer, const char *);
113/* Parse_ReportErrors();
114 *	At end of parsing, report on fatal errors.
115 */
116extern void Parse_ReportErrors(void);
117
118extern void Parse_setcurdir(const char *);
119#endif
120