#include "system.h"
#include <stdarg.h>
#include <rpmio_internal.h>
#include <rpmmessages.h>
#include <rpmerr.h>
#include <rpmmacro.h>
#include "debug.h"
Go to the source code of this file.
Data Structures | |
struct | MacroBuf_s |
Macro expansion state. More... | |
Defines | |
#define | isblank(_c) ((_c) == ' ' || (_c) == '\t') |
#define | iseol(_c) ((_c) == '\n' || (_c) == '\r') |
#define | STREQ(_t, _f, _fn) ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn))) |
#define | SAVECHAR(_mb, _c) { *(_mb)->t = (_c), (_mb)->t++, (_mb)->nb--; } |
#define | _MAX_MACRO_DEPTH 16 |
#define | _PRINT_MACRO_TRACE 0 |
#define | _PRINT_EXPAND_TRACE 0 |
#define | MACRO_CHUNK_SIZE 16 |
#define | SKIPBLANK(_s, _c) |
#define | SKIPNONBLANK(_s, _c) |
#define | COPYNAME(_ne, _s, _c) |
#define | COPYOPTS(_oe, _s, _c) |
#define | POPT_ERROR_NOARG -10 |
#define | POPT_ERROR_BADQUOTE -15 |
#define | POPT_ERROR_MALLOC -21 |
#define | POPT_ARGV_ARRAY_GROW_DELTA 5 |
Typedefs | |
typedef struct MacroBuf_s * | MacroBuf |
Functions | |
static int | expandMacro (MacroBuf mb) |
The main macro recursion loop. | |
static void * | _free (const void *p) |
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. | |
static int | compareMacroName (const void *ap, const void *bp) |
Compare macro entries by name (qsort/bsearch). | |
static void | expandMacroTable (MacroContext mc) |
Enlarge macro table. | |
static void | sortMacroTable (MacroContext mc) |
Sort entries in macro table. | |
void | rpmDumpMacroTable (MacroContext mc, FILE *fp) |
Print macros to file stream. | |
static MacroEntry * | findEntry (MacroContext mc, const char *name, size_t namelen) |
Find entry in macro table. | |
static char * | rdcl (char *buf, size_t size, FD_t fd) |
fgets(3) analogue that reads \ continuations. | |
static const char * | matchchar (const char *p, char pl, char pr) |
Return text between pl and matching pr characters. | |
static void | printMacro (MacroBuf mb, const char *s, const char *se) |
Pre-print macro expression to be expanded. | |
static void | printExpansion (MacroBuf mb, const char *t, const char *te) |
Post-print expanded macro expression. | |
static int | expandT (MacroBuf mb, const char *f, size_t flen) |
Save source and expand field into target. | |
static int | expandU (MacroBuf mb, char *u, size_t ulen) |
Save source/target and expand macro in u. | |
static int | doShellEscape (MacroBuf mb, const char *cmd, size_t clen) |
Expand output of shell command into target buffer. | |
static const char * | doDefine (MacroBuf mb, const char *se, int level, int expandbody) |
Parse (and execute) new macro definition. | |
static const char * | doUndefine (MacroContext mc, const char *se) |
Parse (and execute) macro undefinition. | |
static void | pushMacro (MacroEntry *mep, const char *n, const char *o, const char *b, int level) |
Push new macro definition onto macro entry stack. | |
static void | popMacro (MacroEntry *mep) |
Pop macro definition from macro entry stack. | |
static void | freeArgs (MacroBuf mb) |
Free parsed arguments for parameterized macro. | |
static const char * | grabArgs (MacroBuf mb, const MacroEntry me, const char *se, const char *lastc) |
Parse arguments (to next new line) for parameterized macro. | |
static void | doOutput (MacroBuf mb, int waserror, const char *msg, size_t msglen) |
Perform macro message output. | |
static void | doFoo (MacroBuf mb, int negate, const char *f, size_t fn, const char *g, size_t gn) |
Execute macro primitives. | |
static int | XpoptDupArgv (int argc, const char **argv, int *argcPtr, const char ***argvPtr) |
static int | XpoptParseArgvString (const char *s, int *argcPtr, const char ***argvPtr) |
int | rpmGlob (const char *patterns, int *argcPtr, const char ***argvPtr) |
Return URL path(s) from a (URL prefixed) pattern glob. | |
int | expandMacros (void *spec, MacroContext mc, char *sbuf, size_t slen) |
Expand macro into buffer. | |
void | addMacro (MacroContext mc, const char *n, const char *o, const char *b, int level) |
Add macro to context. | |
void | delMacro (MacroContext mc, const char *n) |
Delete macro from context. | |
int | rpmDefineMacro (MacroContext mc, const char *macro, int level) |
Define macro in context. | |
void | rpmLoadMacros (MacroContext mc, int level) |
Load macros from specific context into global context. | |
int | rpmLoadMacroFile (MacroContext mc, const char *fn) |
Load macro context from a macro file. | |
void | rpmInitMacros (MacroContext mc, const char *macrofiles) |
Initialize macro context from set of macrofile(s). | |
void | rpmFreeMacros (MacroContext mc) |
Destroy macro context. | |
static int | rpmFileHasSuffix (const char *path, const char *suffix) |
int | isCompressed (const char *file, rpmCompressedMagic *compressed) |
Return type of compression used in file. | |
char * | rpmExpand (const char *arg,...) |
Return (malloc'ed) concatenated macro expansion(s). | |
int | rpmExpandNumeric (const char *arg) |
Return macro expansion as a numeric value. | |
char * | rpmCleanPath (char *path) |
Canonicalize file path. | |
const char * | rpmGetPath (const char *path,...) |
Return (malloc'ed) expanded, canonicalized, file path. | |
const char * | rpmGenPath (const char *urlroot, const char *urlmdir, const char *urlfile) |
Merge 3 args into path, any or all of which may be a url. | |
Variables | |
static struct MacroContext_s | rpmGlobalMacroContext_s |
MacroContext | rpmGlobalMacroContext = &rpmGlobalMacroContext_s |
static struct MacroContext_s | rpmCLIMacroContext_s |
MacroContext | rpmCLIMacroContext = &rpmCLIMacroContext_s |
int | max_macro_depth = 16 |
int | print_macro_trace = 0 |
int | print_expand_trace = 0 |
static int | _debug = 0 |
Definition in file macro.c.
#define COPYNAME | ( | _ne, | |||
_s, | |||||
_c | ) |
#define COPYOPTS | ( | _oe, | |||
_s, | |||||
_c | ) |
#define iseol | ( | _c | ) | ((_c) == '\n' || (_c) == '\r') |
#define MACRO_CHUNK_SIZE 16 |
#define SAVECHAR | ( | _mb, | |||
_c | ) | { *(_mb)->t = (_c), (_mb)->t++, (_mb)->nb--; } |
#define SKIPBLANK | ( | _s, | |||
_c | ) |
#define SKIPNONBLANK | ( | _s, | |||
_c | ) |
#define STREQ | ( | _t, | |||
_f, | |||||
_fn | ) | ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn))) |
typedef struct MacroBuf_s * MacroBuf |
static void* _free | ( | const void * | p | ) | [inline, static] |
void addMacro | ( | MacroContext | mc, | |
const char * | n, | |||
const char * | o, | |||
const char * | b, | |||
int | level | |||
) |
Add macro to context.
mc | macro context (NULL uses global context). | |
n | macro name | |
o | macro paramaters | |
b | macro body | |
level | macro recursion level (0 is entry API) |
Definition at line 1873 of file macro.c.
Referenced by addSource(), buildForTarget(), doReadRC(), doScript(), doSetupMacro(), handlePreambleTag(), main(), makeGPGSignature(), makePGPSignature(), parseSpec(), rpmPlatform(), rpmrc_AddMacro(), rpmtsOpenSDB(), setDefaults(), setPathDefault(), and setVarDefault().
static int compareMacroName | ( | const void * | ap, | |
const void * | bp | |||
) | [static] |
Compare macro entries by name (qsort/bsearch).
ap | 1st macro entry | |
bp | 2nd macro entry |
Definition at line 142 of file macro.c.
Referenced by findEntry().
void delMacro | ( | MacroContext | mc, | |
const char * | n | |||
) |
Delete macro from context.
mc | macro context (NULL uses global context). | |
n | macro name |
Definition at line 1899 of file macro.c.
Referenced by doScript(), handlePreambleTag(), makeGPGSignature(), makePGPSignature(), parseSpec(), rpmrc_DelMacro(), and rpmtsOpenSDB().
static const char* doDefine | ( | MacroBuf | mb, | |
const char * | se, | |||
int | level, | |||
int | expandbody | |||
) | [static] |
static void doFoo | ( | MacroBuf | mb, | |
int | negate, | |||
const char * | f, | |||
size_t | fn, | |||
const char * | g, | |||
size_t | gn | |||
) | [static] |
static void doOutput | ( | MacroBuf | mb, | |
int | waserror, | |||
const char * | msg, | |||
size_t | msglen | |||
) | [static] |
Perform macro message output.
mb | macro expansion state | |
waserror | use rpmError()? | |
msg | message to ouput | |
msglen | no. of bytes in message |
static int doShellEscape | ( | MacroBuf | mb, | |
const char * | cmd, | |||
size_t | clen | |||
) | [static] |
static const char* doUndefine | ( | MacroContext | mc, | |
const char * | se | |||
) | [static] |
static int expandMacro | ( | MacroBuf | mb | ) | [static] |
int expandMacros | ( | void * | spec, | |
MacroContext | mc, | |||
char * | sbuf, | |||
size_t | slen | |||
) |
Expand macro into buffer.
spec | cookie (unused) | |
mc | macro context (NULL uses global context). |
sbuf | input macro to expand, output expansion |
slen | size of buffer |
Definition at line 1838 of file macro.c.
Referenced by addFileToTagAux(), copyNextLineFromOFI(), and processPackageFiles().
static void expandMacroTable | ( | MacroContext | mc | ) | [static] |
Enlarge macro table.
mc | macro context |
Definition at line 163 of file macro.c.
References MacroContext_s::firstFree, MACRO_CHUNK_SIZE, MacroContext_s::macrosAllocated, MacroContext_s::macroTable, xmalloc(), and xrealloc().
static int expandT | ( | MacroBuf | mb, | |
const char * | f, | |||
size_t | flen | |||
) | [static] |
static int expandU | ( | MacroBuf | mb, | |
char * | u, | |||
size_t | ulen | |||
) | [static] |
static MacroEntry* findEntry | ( | MacroContext | mc, | |
const char * | name, | |||
size_t | namelen | |||
) | [static] |
Find entry in macro table.
Definition at line 249 of file macro.c.
References alloca(), compareMacroName(), MacroContext_s::firstFree, MacroContext_s::macroTable, MacroEntry_s::name, and rpmGlobalMacroContext.
static void freeArgs | ( | MacroBuf | mb | ) | [static] |
static const char* grabArgs | ( | MacroBuf | mb, | |
const MacroEntry | me, | |||
const char * | se, | |||
const char * | lastc | |||
) | [static] |
int isCompressed | ( | const char * | file, | |
rpmCompressedMagic * | compressed | |||
) |
static const char* matchchar | ( | const char * | p, | |
char | pl, | |||
char | pr | |||
) | [static] |
static void popMacro | ( | MacroEntry * | mep | ) | [static] |
static void printExpansion | ( | MacroBuf | mb, | |
const char * | t, | |||
const char * | te | |||
) | [static] |
static void printMacro | ( | MacroBuf | mb, | |
const char * | s, | |||
const char * | se | |||
) | [static] |
static void pushMacro | ( | MacroEntry * | mep, | |
const char * | n, | |||
const char * | o, | |||
const char * | b, | |||
int | level | |||
) | [static] |
static char* rdcl | ( | char * | buf, | |
size_t | size, | |||
FD_t | fd | |||
) | [static] |
char* rpmCleanPath | ( | char * | path | ) |
Canonicalize file path.
path | path to canonicalize (in-place) |
Definition at line 2183 of file macro.c.
Referenced by doLookup(), relocateFileList(), and rpmQueryVerify().
int rpmDefineMacro | ( | MacroContext | mc, | |
const char * | macro, | |||
int | level | |||
) |
Define macro in context.
mc | macro context (NULL uses global context). | |
macro | macro name, options, body | |
level | macro recursion level (0 is entry API) |
Definition at line 1915 of file macro.c.
Referenced by ftsCacheUpdate(), and rpmcliAllArgCallback().
void rpmDumpMacroTable | ( | MacroContext | mc, | |
FILE * | fp | |||
) |
Print macros to file stream.
mc | macro context (NULL uses global context). | |
fp | file stream (NULL uses stderr). |
Definition at line 207 of file macro.c.
References _, MacroEntry_s::body, MacroContext_s::firstFree, MacroEntry_s::level, MacroContext_s::macroTable, MacroEntry_s::name, MacroEntry_s::opts, rpmGlobalMacroContext, and MacroEntry_s::used.
char* rpmExpand | ( | const char * | arg, | |
... | ||||
) |
Return (malloc'ed) concatenated macro expansion(s).
arg | macro(s) to expand (NULL terminates list) |
Definition at line 2133 of file macro.c.
Referenced by checkForValidArchitectures(), checkPassPhrase(), cpio_doio(), db3New(), defaultMachine(), doPrimary(), doScript(), doSetupMacro(), expandMacro(), initGlobs(), main(), makeGPGSignature(), makePGPSignature(), open_dso(), packageBinaries(), parseForRegexLang(), parseForSimple(), parseSpec(), processSourceFiles(), rdToken(), readLine(), rpmcliAllArgCallback(), rpmcliImportPubkeys(), rpmcliQuery(), rpmfcExec(), rpmfcExpandAppend(), rpmGetPassPhrase(), rpmgiNext(), rpmgiOpen(), rpmLookupSignatureType(), rpmPlatform(), rpmRollback(), rpmts_IDTXglob(), rpmtsFindPubkey(), rpmtsSolve(), skipFiles(), urlFind(), and writeRPM().
int rpmExpandNumeric | ( | const char * | arg | ) |
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.
arg | macro to expand |
Definition at line 2156 of file macro.c.
Referenced by build(), genCpioListAndHeader(), main(), parseRCPOT(), parseSpec(), processPackageFiles(), relocateFileList(), rpmcliQuery(), rpmcliVerify(), rpmdbInit(), rpmErase(), rpmfcELF(), rpmInstall(), rpmLeadVersion(), rpmRollback(), rpmts_Create(), rpmts_init(), rpmtsCreate(), rpmtsOpenSDB(), rpmtsRun(), and skipFiles().
static int rpmFileHasSuffix | ( | const char * | path, | |
const char * | suffix | |||
) | [static] |
void rpmFreeMacros | ( | MacroContext | mc | ) |
const char* rpmGenPath | ( | const char * | urlroot, | |
const char * | urlmdir, | |||
const char * | urlfile | |||
) |
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.
urlroot | root URL (often path to chroot, or NULL) | |
urlmdir | directory URL (often a directory, or NULL) | |
urlfile | file URL (often a file, or NULL) |
Definition at line 2302 of file macro.c.
Referenced by buildForTarget(), db3close(), db3open(), db_init(), doScript(), doSetupMacro(), handlePreambleTag(), makeTempFile(), processPackageFiles(), rpmInstall(), and rpmInstallSourcePackage().
const char* rpmGetPath | ( | const char * | path, | |
... | ||||
) |
Return (malloc'ed) expanded, canonicalized, file path.
path | macro(s) to expand (NULL terminates list) |
Definition at line 2271 of file macro.c.
Referenced by addFileToTagAux(), addSource(), buildForTarget(), db3close(), db3open(), doPatch(), doReadRC(), doRmSource(), doUntar(), genCpioListAndHeader(), main(), packageBinaries(), packageSources(), parseFiles(), parseForSimple(), parseSpec(), processPackageFiles(), processSourceFiles(), readIcon(), rpmDetectPGPVersion(), rpmfiNew(), rpmInstall(), rpmQueryVerify(), rpmsxParse(), rpmts_Run(), rpmtsOpenDB(), rpmtsOpenSDB(), and setPathDefault().
int rpmGlob | ( | const char * | patterns, | |
int * | argcPtr, | |||
const char *** | argvPtr | |||
) |
Return URL path(s) from a (URL prefixed) pattern glob.
patterns | glob pattern |
*argcPtr | no. of paths | |
*argvPtr | array of paths (malloc'd contiguous blob) |
Definition at line 1694 of file macro.c.
References _free(), getenv(), Glob(), Glob_error(), Glob_pattern_p(), Globfree(), setlocale, URL_IS_DASH, URL_IS_FTP, URL_IS_HKP, URL_IS_HTTP, URL_IS_HTTPS, URL_IS_PATH, URL_IS_UNKNOWN, urlPath(), xmalloc(), XpoptParseArgvString(), xrealloc(), and xstrdup().
Referenced by IDTXglob(), rpmgiGlobArgv(), rpmGraph(), rpmInstall(), and rpmReadPackageManifest().
void rpmInitMacros | ( | MacroContext | mc, | |
const char * | macrofiles | |||
) |
int rpmLoadMacroFile | ( | MacroContext | mc, | |
const char * | fn | |||
) |
void rpmLoadMacros | ( | MacroContext | mc, | |
int | level | |||
) |
static void sortMacroTable | ( | MacroContext | mc | ) | [static] |
static int XpoptDupArgv | ( | int | argc, | |
const char ** | argv, | |||
int * | argcPtr, | |||
const char *** | argvPtr | |||
) | [static] |
static int XpoptParseArgvString | ( | const char * | s, | |
int * | argcPtr, | |||
const char *** | argvPtr | |||
) | [static] |
int max_macro_depth = 16 |
int print_expand_trace = 0 |
int print_macro_trace = 0 |
struct MacroContext_s rpmCLIMacroContext_s [static] |
Definition at line 68 of file macro.c.
Referenced by findEntry(), newSpec(), and rpmDumpMacroTable().
struct MacroContext_s rpmGlobalMacroContext_s [static] |