1/*
2  Copyright (C) 2009  Andreas Gruenbacher <agruen@suse.de>
3
4  This program is free software: you can redistribute it and/or modify it
5  under the terms of the GNU Lesser General Public License as published by
6  the Free Software Foundation, either version 2.1 of the License, or
7  (at your option) any later version.
8
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  GNU General Public License for more details.
13
14  You should have received a copy of the GNU General Public License
15  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __ERROR_CONTEXT_T
19#define __ERROR_CONTEXT_T
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25struct error_context {
26	/* Process an error message */
27	void (*error) (struct error_context *, const char *, ...);
28
29	/* Quote a file name for including in an error message */
30	const char *(*quote) (struct error_context *, const char *);
31
32	/* Free a quoted name */
33	void (*quote_free) (struct error_context *, const char *);
34};
35
36#ifdef ERROR_CONTEXT_MACROS
37# define error(ctx, args...) do { \
38	if ((ctx) && (ctx)->error) \
39		(ctx)->error((ctx), args); \
40	} while(0)
41# define quote(ctx, name) \
42	( ((ctx) && (ctx)->quote) ? (ctx)->quote((ctx), (name)) : (name) )
43# define quote_free(ctx, name) do { \
44	if ((ctx) && (ctx)->quote_free) \
45		(ctx)->quote_free((ctx), (name)); \
46	} while(0)
47#endif
48
49#ifdef __cplusplus
50}
51#endif
52
53#endif  /* __ERROR_CONTEXT_T */
54