1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#ifndef _H_MACRO_
#define _H_MACRO_
/** \ingroup rpmio
* \file rpmio/rpmmacro.h
*/
/*! The structure used to store a macro. */
typedef /*@abstract@*/ struct MacroEntry_s {
struct MacroEntry_s *prev;/*!< Macro entry stack. */
const char *name; /*!< Macro name. */
const char *opts; /*!< Macro parameters (a la getopt) */
const char *body; /*!< Macro body. */
int used; /*!< No. of expansions. */
int level; /*!< Scoping level. */
} * MacroEntry;
/*! The structure used to store the set of macros in a context. */
typedef /*@abstract@*/ struct MacroContext_s {
/*@owned@*//*@null@*/ MacroEntry *macroTable; /*!< Macro entry table for context. */
int macrosAllocated;/*!< No. of allocated macros. */
int firstFree; /*!< No. of macros. */
} * MacroContext;
/**
* Markers for sources of macros added throughout rpm.
*/
#define RMIL_DEFAULT -15
#define RMIL_MACROFILES -13
#define RMIL_RPMRC -11
#define RMIL_CMDLINE -7
#define RMIL_TARBALL -5
#define RMIL_SPEC -3
#define RMIL_OLDSPEC -1
#define RMIL_GLOBAL 0
#ifdef __cplusplus
extern "C" {
#endif
/**
* Print macros to file stream.
* @param mc macro context (NULL uses global context).
* @param fp file stream (NULL uses stderr).
*/
void rpmDumpMacroTable (/*@null@*/ MacroContext mc,
/*@null@*/ FILE * fp)
/*@modifies *fp, fileSystem @*/;
/**
* Expand macro into buffer.
* @deprecated Use rpmExpand().
* @todo Eliminate from API.
* @param spec cookie (unused)
* @param mc macro context (NULL uses global context).
* @retval sbuf input macro to expand, output expansion
* @param sbuflen size of buffer
* @return 0 on success
*/
int expandMacros (/*@null@*/ void * spec, /*@null@*/ MacroContext mc,
/*@in@*/ /*@out@*/ char * sbuf,
size_t sbuflen)
/*@modifies *sbuf, internalState @*/;
/**
* Add macro to context.
* @deprecated Use rpmDefineMacro().
* @param mc macro context (NULL uses global context).
* @param n macro name
* @param o macro paramaters
* @param b macro body
* @param level macro recursion level (0 is entry API)
*/
void addMacro (/*@null@*/ MacroContext mc, const char * n,
/*@null@*/ const char * o,
/*@null@*/ const char * b, int level)
/*@modifies mc, internalState @*/;
/**
* Delete macro from context.
* @param mc macro context (NULL uses global context).
* @param n macro name
*/
void delMacro (/*@null@*/ MacroContext mc, const char * n)
/*@modifies mc, internalState @*/;
/**
* Define macro in context.
* @param mc macro context (NULL uses global context).
* @param n macro name, options, body
* @param level macro recursion level (0 is entry API)
* @return @todo Document.
*/
int rpmDefineMacro (/*@null@*/ MacroContext mc, const char * macro,
int level)
/*@modifies mc, internalState @*/;
/**
* Load macros from context into global context.
* @param mc macro context (NULL does nothing).
* @param level macro recursion level (0 is entry API)
*/
void rpmLoadMacros (/*@null@*/ MacroContext mc, int level)
/*@modifies mc, internalState @*/;
/**
* Initialize macro context from set of macrofile(s).
* @param mc macro context (NULL uses global context).
* @param macrofiles colon separated list of macro files (NULL does nothing)
*/
void rpmInitMacros (/*@null@*/ MacroContext mc, const char * macrofiles)
/*@modifies mc, internalState, fileSystem @*/;
/**
* Destroy macro context.
* @param mc macro context (NULL uses global context).
*/
void rpmFreeMacros (/*@null@*/ MacroContext mc)
/*@modifies mc, internalState @*/;
typedef enum rpmCompressedMagic_e {
COMPRESSED_NOT = 0, /*!< not compressed */
COMPRESSED_OTHER = 1, /*!< gzip can handle */
COMPRESSED_BZIP2 = 2, /*!< bzip2 can handle */
COMPRESSED_ZIP = 3 /*!< unzip can handle */
} rpmCompressedMagic;
/**
* Return type of compression used in file.
* @param file name of file
* @retval compressed address of compression type
* @return 0 on success, 1 on I/O error
*/
int isCompressed (const char * file,
/*@out@*/ rpmCompressedMagic * compressed)
/*@modifies *compressed, fileSystem @*/;
/**
* Return (malloc'ed) concatenated macro expansion(s).
* @param arg macro(s) to expand (NULL terminates list)
* @return macro expansion (malloc'ed)
*/
char * rpmExpand (/*@null@*/ const char * arg, ...)
/*@*/;
/**
* Canonicalize file path.
* @param path path to canonicalize (in-place)
* @return canonicalized path (malloc'ed)
*/
/*@null@*/ char * rpmCleanPath (/*@null@*/ char * path)
/*@modifies *path @*/;
/**
* Return (malloc'ed) expanded, canonicalized, file path.
* @param path macro(s) to expand (NULL terminates list)
* @return canonicalized path (malloc'ed)
*/
/*@-redecl@*/
const char * rpmGetPath (/*@null@*/ const char * path, ...)
/*@*/;
/*@=redecl@*/
/**
* Merge 3 args into path, any or all of which may be a url.
* The leading part of the first URL encountered is used
* for the result, other URL's are discarded, permitting
* a primitive form of inheiritance.
* @param root root URL (often path to chroot, or NULL)
* @param mdir directory URL (often a directory, or NULL)
* @param file file URL (often a file, or NULL)
* @return expanded, merged, canonicalized path (malloc'ed)
*/
/*@-redecl@*/
const char * rpmGenPath (/*@null@*/ const char * root,
/*@null@*/ const char * mdir,
/*@null@*/ const char * file)
/*@*/;
/*@=redecl@*/
/**
* Return macro expansion as a numeric value.
* Boolean values ('Y' or 'y' returns 1, 'N' or 'n' returns 0)
* are permitted as well. An undefined macro returns 0.
* @param arg macro to expand
* @return numeric value
*/
int rpmExpandNumeric (const char * arg)
/*@*/;
#ifdef __cplusplus
}
#endif
#endif /* _H_ MACRO_ */
|