1 #ifndef _H_MACRO_
2 #define	_H_MACRO_
3 
4 /** \ingroup rpmio
5  * \file rpmio/rpmmacro.h
6  *
7  * Macro API
8  */
9 
10 #include <stdio.h>
11 #include <stddef.h>
12 
13 #include <rpm/rpmutil.h>
14 #include <rpm/rpmfileutil.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef struct rpmMacroEntry_s * rpmMacroEntry;
21 
22 typedef struct rpmMacroContext_s * rpmMacroContext;
23 
24 extern rpmMacroContext rpmGlobalMacroContext;
25 
26 extern rpmMacroContext rpmCLIMacroContext;
27 
28 /** \ingroup rpmrc
29  * List of macro files to read when configuring rpm.
30  * This is a colon separated list of files. URI's are permitted as well,
31  * identified by the token '://', so file paths must not begin with '//'.
32  */
33 extern const char * macrofiles;
34 
35 /**
36  * Markers for sources of macros added throughout rpm.
37  */
38 #define	RMIL_DEFAULT	-15
39 #define	RMIL_MACROFILES	-13
40 #define	RMIL_RPMRC	-11
41 
42 #define	RMIL_CMDLINE	-7
43 #define	RMIL_TARBALL	-5
44 #define	RMIL_SPEC	-3
45 #define	RMIL_OLDSPEC	-1
46 #define	RMIL_GLOBAL	0
47 
48 /* Deprecated compatibility wrappers */
49 #define addMacro(_mc, _n, _o, _b, _l) rpmPushMacro(_mc, _n, _o, _b, _l)
50 #define delMacro(_mc, _n) rpmPopMacro(_mc, _n)
51 
52 /* rpm expression parser flags */
53 #define RPMEXPR_EXPAND		(1 << 0)	/*!< expand primary terms */
54 
55 typedef enum rpmMacroFlags_e {
56     RPMMACRO_DEFAULT	= 0,
57     RPMMACRO_LITERAL	= (1 << 0),		/*!< do not expand body of macro */
58 } rpmMacroFlags;
59 
60 /** \ingroup rpmmacro
61  * Print macros to file stream.
62  * @param mc		macro context (NULL uses global context).
63  * @param fp		file stream (NULL uses stderr).
64  */
65 void	rpmDumpMacroTable	(rpmMacroContext mc,
66 					FILE * fp);
67 
68 /** \ingroup rpmmacro
69  * Expand macro into buffer.
70  * @param mc		macro context (NULL uses global context).
71  * @param sbuf		input macro to expand
72  * @param obuf		macro expansion (malloc'ed)
73  * @param flags		flags (currently unused)
74  * @return		negative on failure
75  */
76 int	rpmExpandMacros	(rpmMacroContext mc, const char * sbuf,
77 				char ** obuf, int flags);
78 
79 /** \ingroup rpmmacro
80  * Push macro to context.
81  * @param mc		macro context (NULL uses global context).
82  * @param n		macro name
83  * @param o		macro parameters
84  * @param b		macro body
85  * @param level		macro recursion level (0 is entry API)
86  * @return		0 on success
87  */
88 int	rpmPushMacro	(rpmMacroContext mc, const char * n,
89 				const char * o,
90 				const char * b, int level);
91 
92 /** \ingroup rpmmacro
93  * Push macro to context.
94  * @param mc		macro context (NULL uses global context).
95  * @param n		macro name
96  * @param o		macro parameters
97  * @param b		macro body
98  * @param level		macro recursion level (0 is entry API)
99  * @param flags		macro flags
100  * @return		0 on success
101  */
102 int	rpmPushMacroFlags	(rpmMacroContext mc, const char * n,
103 					const char * o,
104 					const char * b, int level,
105 					rpmMacroFlags flags);
106 
107 /** \ingroup rpmmacro
108  * Pop macro from context.
109  * @param mc		macro context (NULL uses global context).
110  * @param n		macro name
111  * @return		0 on success
112  */
113 int	rpmPopMacro	(rpmMacroContext mc, const char * n);
114 
115 /** \ingroup rpmmacro
116  * Define macro in context.
117  * @param mc		macro context (NULL uses global context).
118  * @param macro		macro name, options, body
119  * @param level		macro recursion level (0 is entry API)
120  * @return		0 on success (always)
121  */
122 int	rpmDefineMacro	(rpmMacroContext mc, const char * macro,
123 				int level);
124 
125 /*
126  * Test whether a macro is defined
127  * @param mc		macro context (NULL uses global context).
128  * @param n		macro name
129  * @return		1 if defined, 0 if not
130  */
131 int rpmMacroIsDefined(rpmMacroContext mc, const char *n);
132 
133 /*
134  * Test whether a macro is parametric (ie takes arguments)
135  * @param mc		macro context (NULL uses global context).
136  * @param n		macro name
137  * @return		1 if parametric, 0 if not
138  */
139 int rpmMacroIsParametric(rpmMacroContext mc, const char *n);
140 
141 /** \ingroup rpmmacro
142  * Load macros from specific context into global context.
143  * @param mc		macro context (NULL does nothing).
144  * @param level		macro recursion level (0 is entry API)
145  */
146 void	rpmLoadMacros	(rpmMacroContext mc, int level);
147 
148 /** \ingroup rpmmacro
149  * Load macro context from a macro file.
150  * @param mc		(unused)
151  * @param fn		macro file name
152  */
153 int	rpmLoadMacroFile(rpmMacroContext mc, const char * fn);
154 
155 /** \ingroup rpmmacro
156  * Initialize macro context from set of macrofile(s).
157  * @param mc		macro context
158  * @param macrofiles	colon separated list of macro files (NULL does nothing)
159  */
160 void	rpmInitMacros	(rpmMacroContext mc, const char * macrofiles);
161 
162 /** \ingroup rpmmacro
163  * Destroy macro context.
164  * @param mc		macro context (NULL uses global context).
165  */
166 void	rpmFreeMacros	(rpmMacroContext mc);
167 
168 /** \ingroup rpmmacro
169  * Return (malloc'ed) concatenated macro expansion(s).
170  * @param arg		macro(s) to expand (NULL terminates list)
171  * @return		macro expansion (malloc'ed)
172  */
173 char * rpmExpand	(const char * arg, ...) RPM_GNUC_NULL_TERMINATED;
174 
175 /** \ingroup rpmmacro
176  * Return macro expansion as a numeric value.
177  * Boolean values ('Y' or 'y' returns 1, 'N' or 'n' returns 0)
178  * are permitted as well. An undefined macro returns 0.
179  * @param arg		macro to expand
180  * @return		numeric value
181  */
182 int	rpmExpandNumeric (const char * arg);
183 
184 /** \ingroup rpmmacro
185  * Return rpm configuration base directory.
186  * If RPM_CONFIGDIR environment variable is set, it's value will be used.
187  * Otherwise the configuration directory is the one set at build time,
188  * typically /usr/lib/rpm. The value of rpmConfigDir() is determined
189  * on first call to this function and is guaranteed to remain the same
190  * on subsequent calls.
191  * @return		rpm configuration directory name
192  */
193 const char *rpmConfigDir(void);
194 
195 /** \ingroup rpmmacro
196  * Evaluate boolean expression.
197  * @param expr		expression to parse
198  * @param flags		parser flags
199  * @return
200  */
201 int rpmExprBoolFlags(const char * expr, int flags);
202 
203 /** \ingroup rpmmacro
204  * Evaluate string expression.
205  * @param expr		expression to parse
206  * @param flags		parser flags
207  * @return
208  */
209 char * rpmExprStrFlags(const char * expr, int flags);
210 
211 /** \ingroup rpmmacro
212  * Evaluate boolean expression.
213  * @param expr		expression to parse
214  * @return
215  */
216 int rpmExprBool(const char * expr);
217 
218 /** \ingroup rpmmacro
219  * Evaluate string expression.
220  * @param expr		expression to parse
221  * @return
222  */
223 char * rpmExprStr(const char * expr);
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif	/* _H_ MACRO_ */
230