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