xref: /openbsd-src/usr.bin/make/varname.h (revision dba68890dc2f821a2767fe1773a14cfff3b41f2a)
1*dba68890Sespie /*	$OpenBSD: varname.h,v 1.4 2010/07/19 19:30:38 espie Exp $	*/
2f7923656Sespie #ifndef VARNAME_H
3f7923656Sespie #define VARNAME_H
4f7923656Sespie /*
5f7923656Sespie  * Copyright (c) 2001 Marc Espie.
6f7923656Sespie  *
7f7923656Sespie  * Redistribution and use in source and binary forms, with or without
8f7923656Sespie  * modification, are permitted provided that the following conditions
9f7923656Sespie  * are met:
10f7923656Sespie  * 1. Redistributions of source code must retain the above copyright
11f7923656Sespie  *    notice, this list of conditions and the following disclaimer.
12f7923656Sespie  * 2. Redistributions in binary form must reproduce the above copyright
13f7923656Sespie  *    notice, this list of conditions and the following disclaimer in the
14f7923656Sespie  *    documentation and/or other materials provided with the distribution.
15f7923656Sespie  *
16f7923656Sespie  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
17f7923656Sespie  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18f7923656Sespie  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19f7923656Sespie  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
20f7923656Sespie  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21f7923656Sespie  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22f7923656Sespie  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23f7923656Sespie  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24f7923656Sespie  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25f7923656Sespie  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26f7923656Sespie  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27f7923656Sespie  */
28f7923656Sespie 
29f7923656Sespie /* varname -
30f7923656Sespie  * 	Handles variable names in recursive situations, e.g.,
31f7923656Sespie  *	to expand ${A${BC}}.
32f7923656Sespie  */
33f7923656Sespie 
34f7923656Sespie /* Used to store temporary names, e.g., after $ expansion. */
35f7923656Sespie struct Name {
36f7923656Sespie 	const char 	*s;		/* Start of name. */
37f7923656Sespie 	const char 	*e;		/* End of name. */
38f7923656Sespie 	bool		tofree;		/* Needs freeing after use ? */
39f7923656Sespie };
40f7923656Sespie 
41f7923656Sespie /* endpos = VarName_Get(startpos, &name, ctxt, undef_is_bad, cont_function);
42f7923656Sespie  *	Gets a variable name from startpos, storing the result into name.
43f7923656Sespie  *	Recursive names are expanded from context ctxt. Boolean
44f7923656Sespie  *	undef_is_bad governs whether undefined variables should trigger a
45f7923656Sespie  *	parse error.  To parse its argument efficiently, VarName_Get
46f7923656Sespie  *	uses cont_function(pos), which should return the position of the
47f7923656Sespie  *	next $ in string, or the position where the variable spec ends (as
48f7923656Sespie  *	differing modules have different requirements wrt variable spec
49f7923656Sespie  *	endings). Returns the position where the variable spec finally
50f7923656Sespie  *	ends. Name result might be a copy, or not. */
51f7923656Sespie extern const char *VarName_Get(const char *, struct Name *, SymTable *,
52f7923656Sespie     bool, const char *(*)(const char *));
53f7923656Sespie /* VarName_Free(name);
54f7923656Sespie  *	Frees a variable name filled by VarName_Get(). */
55f7923656Sespie extern void VarName_Free(struct Name *);
56f7923656Sespie 
57f7923656Sespie #endif
58