5 * \file rpmio/rpmmacro.h
11 #include <rpm/rpmutil.h>
12 #include <rpm/rpmfileutil.h>
18 typedef struct rpmMacroEntry_s * rpmMacroEntry;
20 typedef struct rpmMacroContext_s * rpmMacroContext;
22 extern rpmMacroContext rpmGlobalMacroContext;
24 extern rpmMacroContext rpmCLIMacroContext;
27 * List of macro files to read when configuring rpm.
28 * This is a colon separated list of files. URI's are permitted as well,
29 * identified by the token '://', so file paths must not begin with '//'.
31 extern const char * macrofiles;
34 * Markers for sources of macros added throughout rpm.
36 #define RMIL_DEFAULT -15
37 #define RMIL_MACROFILES -13
38 #define RMIL_RPMRC -11
40 #define RMIL_CMDLINE -7
41 #define RMIL_TARBALL -5
43 #define RMIL_OLDSPEC -1
47 * Print macros to file stream.
48 * @param mc macro context (NULL uses global context).
49 * @param fp file stream (NULL uses stderr).
51 void rpmDumpMacroTable (rpmMacroContext mc,
55 * Expand macro into buffer.
56 * @deprecated Use rpmExpand().
57 * @todo Eliminate from API.
58 * @param spec cookie (unused)
59 * @param mc macro context (NULL uses global context).
60 * @retval sbuf input macro to expand, output expansion
61 * @param slen size of buffer
62 * @return 0 on success
64 int expandMacros (void * spec, rpmMacroContext mc,
69 * Add macro to context.
70 * @deprecated Use rpmDefineMacro().
71 * @param mc macro context (NULL uses global context).
73 * @param o macro paramaters
75 * @param level macro recursion level (0 is entry API)
77 void addMacro (rpmMacroContext mc, const char * n,
79 const char * b, int level);
82 * Delete macro from context.
83 * @param mc macro context (NULL uses global context).
86 void delMacro (rpmMacroContext mc, const char * n);
89 * Define macro in context.
90 * @param mc macro context (NULL uses global context).
91 * @param macro macro name, options, body
92 * @param level macro recursion level (0 is entry API)
93 * @return 0 on success (always)
95 int rpmDefineMacro (rpmMacroContext mc, const char * macro,
99 * Load macros from specific context into global context.
100 * @param mc macro context (NULL does nothing).
101 * @param level macro recursion level (0 is entry API)
103 void rpmLoadMacros (rpmMacroContext mc, int level);
105 /** \ingroup rpmmacro
106 * Load macro context from a macro file.
108 * @param fn macro file name
110 int rpmLoadMacroFile(rpmMacroContext mc, const char * fn);
112 /** \ingroup rpmmacro
113 * Initialize macro context from set of macrofile(s).
114 * @param mc macro context
115 * @param macrofiles colon separated list of macro files (NULL does nothing)
117 void rpmInitMacros (rpmMacroContext mc, const char * macrofiles);
119 /** \ingroup rpmmacro
120 * Destroy macro context.
121 * @param mc macro context (NULL uses global context).
123 void rpmFreeMacros (rpmMacroContext mc);
125 /** \ingroup rpmmacro
126 * Return (malloc'ed) concatenated macro expansion(s).
127 * @param arg macro(s) to expand (NULL terminates list)
128 * @return macro expansion (malloc'ed)
130 char * rpmExpand (const char * arg, ...) RPM_GNUC_NULL_TERMINATED;
132 /** \ingroup rpmmacro
133 * Return macro expansion as a numeric value.
134 * Boolean values ('Y' or 'y' returns 1, 'N' or 'n' returns 0)
135 * are permitted as well. An undefined macro returns 0.
136 * @param arg macro to expand
137 * @return numeric value
139 int rpmExpandNumeric (const char * arg);
141 /** \ingroup rpmmacro
142 * Return rpm configuration base directory.
143 * If RPM_CONFIGDIR environment variable is set, it's value will be used.
144 * Otherwise the configuration directory is the one set at build time,
145 * typically /usr/lib/rpm. The value of rpmConfigDir() is determined
146 * on first call to this function and is guaranteed to remain the same
147 * on subsequent calls.
148 * @return rpm configuration directory name
150 const char *rpmConfigDir(void);
156 #endif /* _H_ MACRO_ */