6370ecd629
"rpmquery rpm" callgrind annotations, previous commit: 86,825,432 PROGRAM TOTALS 33,090,616 ???:0x0000000000033080'2 25,635,193 ???:strcmp 11,530,816 ???:compareMacroName 7,241,913 ???:memcpy 2,008,600 ???:0x0000000000033080 1,734,274 ???:sortMacroTable 774,941 ???:doDefine 642,062 ???:0x00000000000714c0 308,897 ???:0x000000000002a7b0 308,137 ???:do_lookup_x 259,615 ???:0x0000000000070c50 245,388 ???:poptReadConfigFile "rpmquery rpm" callgrind annotations, this commit: 6,249,372 PROGRAM TOTALS 774,941 ???:doDefine 531,291 ???:addMacro 523,434 ???:0x00000000000714c0 388,985 ???:strcmp 308,897 ???:0x000000000002a7b0 308,098 ???:do_lookup_x 245,388 ???:poptReadConfigFile "rpmquery rpm" repeated 100 times (user time), previous commit: 3.78s "rpmquery rpm" repeated 100 times (user time), this commit: 0.40s
234 lines
6.9 KiB
C
234 lines
6.9 KiB
C
#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 macroTableSize; /*!< No. of macros. */
|
|
} * MacroContext;
|
|
|
|
/*@-redecl@*/
|
|
/*@checked@*/
|
|
extern MacroContext rpmGlobalMacroContext;
|
|
|
|
/*@checked@*/
|
|
extern MacroContext rpmCLIMacroContext;
|
|
/*@=redecl@*/
|
|
|
|
/** \ingroup rpmrc
|
|
* List of macro files to read when configuring rpm.
|
|
* This is a colon separated list of files. URI's are permitted as well,
|
|
* identified by the token '://', so file paths must not begin with '//'.
|
|
*/
|
|
/*@-redecl@*/
|
|
/*@observer@*/ /*@unchecked@*/
|
|
extern const char * macrofiles;
|
|
/*@=redecl@*/
|
|
|
|
/**
|
|
* 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)
|
|
/*@globals rpmGlobalMacroContext,
|
|
fileSystem@*/
|
|
/*@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 slen size of buffer
|
|
* @return 0 on success
|
|
*/
|
|
int expandMacros (/*@null@*/ void * spec, /*@null@*/ MacroContext mc,
|
|
/*@in@*/ /*@out@*/ char * sbuf,
|
|
size_t slen)
|
|
/*@globals rpmGlobalMacroContext,
|
|
fileSystem @*/
|
|
/*@modifies *sbuf, rpmGlobalMacroContext, fileSystem @*/;
|
|
|
|
/**
|
|
* 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)
|
|
/*@globals rpmGlobalMacroContext@*/
|
|
/*@modifies mc, rpmGlobalMacroContext @*/;
|
|
|
|
/**
|
|
* Delete macro from context.
|
|
* @param mc macro context (NULL uses global context).
|
|
* @param n macro name
|
|
*/
|
|
void delMacro (/*@null@*/ MacroContext mc, const char * n)
|
|
/*@globals rpmGlobalMacroContext@*/
|
|
/*@modifies mc, rpmGlobalMacroContext @*/;
|
|
|
|
/**
|
|
* Define macro in context.
|
|
* @param mc macro context (NULL uses global context).
|
|
* @param macro 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)
|
|
/*@globals rpmGlobalMacroContext@*/
|
|
/*@modifies mc, rpmGlobalMacroContext @*/;
|
|
|
|
/**
|
|
* Load macros from specific 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)
|
|
/*@globals rpmGlobalMacroContext@*/
|
|
/*@modifies rpmGlobalMacroContext @*/;
|
|
|
|
/**
|
|
* Initialize global macro context from set of macrofile(s).
|
|
* @param mc (unused)
|
|
* @param macrofiles colon separated list of macro files (NULL does nothing)
|
|
*/
|
|
void rpmInitMacros (/*@null@*/ MacroContext mc, const char * macrofiles)
|
|
/*@globals rpmGlobalMacroContext, rpmCLIMacroContext,
|
|
fileSystem @*/
|
|
/*@modifies rpmGlobalMacroContext, fileSystem @*/;
|
|
|
|
/**
|
|
* Destroy macro context.
|
|
* @param mc macro context (NULL uses global context).
|
|
*/
|
|
void rpmFreeMacros (/*@null@*/ MacroContext mc)
|
|
/*@globals rpmGlobalMacroContext@*/
|
|
/*@modifies mc, rpmGlobalMacroContext @*/;
|
|
|
|
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 */
|
|
COMPRESSED_LZMA = 4, /*!< lzma can handle */
|
|
COMPRESSED_XZ = 5 /*!< xz 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)
|
|
/*@globals fileSystem@*/
|
|
/*@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, ...)
|
|
__attribute__ ((sentinel))
|
|
/*@globals rpmGlobalMacroContext @*/
|
|
/*@modifies rpmGlobalMacroContext @*/;
|
|
|
|
/**
|
|
* 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@*/ /* LCL: shrug */
|
|
const char * rpmGetPath (/*@null@*/ const char * path, ...)
|
|
__attribute__ ((sentinel))
|
|
/*@globals rpmGlobalMacroContext @*/
|
|
/*@modifies rpmGlobalMacroContext @*/;
|
|
/*@=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 prefixes are discarded, permitting
|
|
* a primitive form of URL inheiritance.
|
|
* @param urlroot root URL (often path to chroot, or NULL)
|
|
* @param urlmdir directory URL (often a directory, or NULL)
|
|
* @param urlfile file URL (often a file, or NULL)
|
|
* @return expanded, merged, canonicalized path (malloc'ed)
|
|
*/
|
|
/*@-redecl@*/ /* LCL: shrug */
|
|
const char * rpmGenPath (/*@null@*/ const char * urlroot,
|
|
/*@null@*/ const char * urlmdir,
|
|
/*@null@*/ const char * urlfile)
|
|
/*@globals rpmGlobalMacroContext @*/
|
|
/*@modifies rpmGlobalMacroContext @*/;
|
|
/*@=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)
|
|
/*@globals rpmGlobalMacroContext @*/
|
|
/*@modifies rpmGlobalMacroContext @*/;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _H_ MACRO_ */
|