#include "system.h"
#include <stdarg.h>
#include <rpmio_internal.h>
#include <rpmmessages.h>
#include <rpmerr.h>
#include <rpmmacro.h>
#include "debug.h"
Include dependency graph for macro.c:
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 |
#define | _suffix(_s, _x) (slen >= sizeof(_x) && !strcmp((_s)+slen-(sizeof(_x)-1), (_x))) |
Typedefs | |
typedef MacroBuf_s * | MacroBuf |
Macro expansion state. | |
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. | |
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 | |
const char * | rpmMacrofiles = MACROFILES |
List of macro files to read when configuring rpm. | |
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.
|
|
|
|
|
|
|
|
|
Value: { SKIPBLANK(_s,_c); \ /*@-boundswrite@*/ \ while(((_c) = *(_s)) && (xisalnum(_c) || (_c) == '_')) \ *(_ne)++ = *(_s)++; \ *(_ne) = '\0'; \ /*@=boundswrite@*/ \ } Definition at line 480 of file macro.c. Referenced by doDefine(), and doUndefine(). |
|
Value: { /*@-boundswrite@*/ \ while(((_c) = *(_s)) && (_c) != ')') \ *(_oe)++ = *(_s)++; \ *(_oe) = '\0'; \ /*@=boundswrite@*/ \ } Definition at line 489 of file macro.c. Referenced by doDefine(). |
|
Definition at line 10 of file macro.c. Referenced by doDefine(), doFoo(), expandMacro(), and grabArgs(). |
|
Definition at line 12 of file macro.c. Referenced by doDefine(), doShellEscape(), doUndefine(), expandMacro(), printExpansion(), printMacro(), and rdcl(). |
|
Definition at line 117 of file macro.c. Referenced by expandMacroTable(). |
|
Definition at line 1594 of file macro.c. Referenced by XpoptParseArgvString(). |
|
error in paramter quoting Definition at line 1591 of file macro.c. Referenced by XpoptParseArgvString(). |
|
memory allocation failed Definition at line 1592 of file macro.c. Referenced by XpoptDupArgv(), and XpoptParseArgvString(). |
|
missing argument Definition at line 1590 of file macro.c. Referenced by XpoptDupArgv(). |
|
Definition at line 100 of file macro.c. Referenced by doShellEscape(), and expandMacro(). |
|
Value: /*@-globs@*/ /* FIX: __ctype_b */ \ while (((_c) = *(_s)) && isblank(_c)) \ (_s)++; \ Definition at line 468 of file macro.c. Referenced by doDefine(), and rpmLoadMacroFile(). |
|
Value: |
|
Definition at line 14 of file macro.c. Referenced by doFoo(), and expandMacro(). |
|
Macro expansion state.
|
|
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
|
|
Add macro to context.
Definition at line 1891 of file macro.c. References _, expandMacroTable(), findEntry(), MacroContext_s::firstFree, MacroEntry_s::flags, MacroContext_s::macrosAllocated, MacroContext_s::macroTable, name, pushMacro(), RPMERR_BADSPEC, rpmError, and sortMacroTable(). Referenced by addSource(), buildForTarget(), doDefine(), doReadRC(), doScript(), doSetupMacro(), expandMacro(), grabArgs(), handlePreambleTag(), headerMacrosLoad(), makeGPGSignature(), makePGPSignature(), parsePreamble(), parseSpec(), rpmLoadMacros(), rpmPlatform(), rpmrc_AddMacro(), rpmRebuildTargetVars(), rpmtsOpenSDB(), setDefaults(), setPathDefault(), and setVarDefault(). |
|
Compare macro entries by name (qsort/bsearch).
Definition at line 148 of file macro.c. References MacroEntry_s::name. Referenced by findEntry(), and sortMacroTable(). |
|
Delete macro from context.
Definition at line 1930 of file macro.c. References findEntry(), popMacro(), and sortMacroTable(). Referenced by doScript(), doUndefine(), handlePreambleTag(), headerMacrosUnload(), makeGPGSignature(), makePGPSignature(), parseSpec(), rpmrc_DelMacro(), rpmRebuildTargetVars(), and rpmtsOpenSDB(). |
|
Parse (and execute) new macro definition.
Definition at line 637 of file macro.c. References _, addMacro(), COPYNAME, COPYOPTS, expandU(), isblank, iseol, matchchar(), MacroBuf_s::mc, RPMERR_BADSPEC, rpmError, SKIPBLANK, and xisalpha(). Referenced by expandMacro(), and rpmDefineMacro(). |
|
Execute macro primitives.
Definition at line 1121 of file macro.c. References COMPRESSED_OTHER, expandT(), expandU(), isblank, isCompressed(), rpmIsVerbose, STREQ, urlPath(), and xisdigit(). Referenced by expandMacro(). |
|
Perform macro message output.
Definition at line 1096 of file macro.c. References expandU(), RPMERR_BADSPEC, and rpmError. Referenced by expandMacro(). |
|
Expand output of shell command into target buffer.
Definition at line 598 of file macro.c. References expandU(), iseol, MacroBuf_s::nb, SAVECHAR, and MacroBuf_s::t. Referenced by expandMacro(). |
|
Parse (and execute) macro undefinition.
Definition at line 774 of file macro.c. References _, COPYNAME, delMacro(), iseol, RPMERR_BADSPEC, rpmError, and xisalpha(). Referenced by expandMacro(). |
|
The main macro recursion loop.
Definition at line 1226 of file macro.c. References _, addMacro(), alloca(), MacroEntry_s::body, MacroBuf_s::depth, doDefine(), doFoo(), doOutput(), doShellEscape(), doUndefine(), MacroBuf_s::expand_trace, expandT(), findEntry(), freeArgs(), grabArgs(), isblank, iseol, MacroBuf_s::macro_trace, matchchar(), max_macro_depth, MacroBuf_s::mc, MacroEntry_s::name, MacroBuf_s::nb, MacroEntry_s::opts, print_expand_trace, print_macro_trace, printExpansion(), printMacro(), RMIL_GLOBAL, rpmDumpMacroTable(), RPMERR_BADSPEC, rpmError, rpmLoadMacroFile(), MacroBuf_s::s, SAVECHAR, STREQ, MacroBuf_s::t, MacroEntry_s::used, xisalnum(), and xmalloc(). Referenced by expandMacros(), expandT(), and expandU(). |
|
Expand macro into buffer.
Definition at line 1855 of file macro.c. References _, alloca(), expandMacro(), print_expand_trace, print_macro_trace, RPMERR_BADSPEC, rpmError, and xmalloc(). Referenced by addFileToTagAux(), copyNextLine(), processPackageFiles(), rpmExpand(), and rpmGetPath(). |
|
Enlarge macro table.
Definition at line 169 of file macro.c. References MacroContext_s::firstFree, MACRO_CHUNK_SIZE, MacroContext_s::macrosAllocated, MacroContext_s::macroTable, xmalloc(), and xrealloc(). Referenced by addMacro(). |
|
Save source and expand field into target.
Definition at line 505 of file macro.c. References alloca(), expandMacro(), and MacroBuf_s::s. Referenced by doFoo(), and expandMacro(). |
|
Save source/target and expand macro in u.
Definition at line 559 of file macro.c. References alloca(), expandMacro(), MacroBuf_s::nb, MacroBuf_s::s, and MacroBuf_s::t. Referenced by doDefine(), doFoo(), doOutput(), doShellEscape(), and grabArgs(). |
|
Find entry in macro table.
Definition at line 255 of file macro.c. References alloca(), compareMacroName(), MacroContext_s::firstFree, and MacroContext_s::macroTable. |
|
Free parsed arguments for parameterized macro.
Definition at line 889 of file macro.c. References _, MacroEntry_s::body, MacroBuf_s::depth, MacroEntry_s::level, MacroContext_s::macroTable, MacroBuf_s::mc, MacroEntry_s::name, popMacro(), RPMERR_BADSPEC, rpmError, sortMacroTable(), and MacroEntry_s::used. Referenced by expandMacro(). |
|
Parse arguments (to next new line) for parameterized macro.
Definition at line 941 of file macro.c. References _, addMacro(), alloca(), MacroBuf_s::depth, expandU(), isblank, MacroBuf_s::mc, MacroEntry_s::name, MacroEntry_s::opts, RPMERR_BADSPEC, rpmError, and stpcpy(). Referenced by expandMacro(). |
|
Return type of compression used in file.
Definition at line 2104 of file macro.c. References _, COMPRESSED_BZIP2, COMPRESSED_LZMA, COMPRESSED_LZOP, COMPRESSED_NOT, COMPRESSED_OTHER, COMPRESSED_ZIP, Fclose(), Ferror(), Fopen(), Fread(), Fstrerror(), RPMERR_BADSPEC, and rpmError. Referenced by buildForTarget(), doFoo(), doPatch(), and doUntar(). |
|
Return text between pl and matching pr characters.
Definition at line 361 of file macro.c. Referenced by doDefine(), and expandMacro(). |
|
Pop macro definition from macro entry stack.
Definition at line 863 of file macro.c. References _free(), MacroEntry_s::body, MacroEntry_s::name, MacroEntry_s::opts, and MacroEntry_s::prev. Referenced by delMacro(), and freeArgs(). |
|
Post-print expanded macro expression.
Definition at line 431 of file macro.c. References _, MacroBuf_s::depth, and iseol. Referenced by expandMacro(). |
|
Pre-print macro expression to be expanded.
Definition at line 387 of file macro.c. References _, MacroBuf_s::depth, and iseol. Referenced by expandMacro(). |
|
Push new macro definition onto macro entry stack.
Definition at line 826 of file macro.c. References _free(), MacroEntry_s::name, name, xmalloc(), and xstrdup(). Referenced by addMacro(). |
|
fgets(3) analogue that reads \ continuations. Last newline always trimmed.
Definition at line 298 of file macro.c. References fdGetFILE, and iseol. Referenced by rpmLoadMacroFile(). |
|
Canonicalize file path.
Definition at line 2237 of file macro.c. Referenced by db3open(), doLookup(), relocateFileList(), rpmdbMoveDatabase(), rpmdbRemoveDatabase(), rpmGetPath(), rpmioAccess(), and rpmQueryVerify(). |
|
Define macro in context.
Definition at line 1946 of file macro.c. References alloca(), and doDefine(). Referenced by rpmcliAllArgCallback(), rpmdbRebuild(), and rpmLoadMacroFile(). |
|
Print macros to file stream.
Definition at line 213 of file macro.c. References _, MacroEntry_s::body, MacroEntry_s::level, MacroContext_s::macroTable, MacroEntry_s::name, MacroEntry_s::opts, and MacroEntry_s::used. Referenced by expandMacro(), and rpmShowRC(). |
|
|
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.
Definition at line 2210 of file macro.c. References _free(), and rpmExpand(). Referenced by addChangelog(), build(), checkFiles(), dbiOpen(), genCpioListAndHeader(), main(), parseSpec(), processPackageFiles(), relocateFileList(), rpmcliQuery(), rpmcliVerify(), rpmdbInit(), rpmdbNew(), rpmdbOpen(), rpmdbRebuild(), rpmdbVerify(), rpmdsELF(), rpmErase(), rpmfcGenerateDepends(), rpmInstall(), rpmLeadVersion(), rpmRollback(), rpmts_Create(), rpmts_init(), rpmtsCreate(), rpmtsOpenSDB(), rpmtsRollback(), rpmtsRun(), skipFiles(), and unsatisfiedDepend(). |
|
Destroy macro context.
Definition at line 2077 of file macro.c. References _free(), MacroEntry_s::body, MacroContext_s::macroTable, MacroEntry_s::name, MacroEntry_s::opts, and MacroEntry_s::prev. Referenced by build(), rpmcliFini(), and rpmspecQuery(). |
|
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.
Definition at line 2359 of file macro.c. References _free(), alloca(), file, rpmGetPath(), URL_IS_DASH, and urlPath(). Referenced by addSource(), db3close(), db3open(), db_init(), doIcon(), doPatch(), doRmSource(), doScript(), doSetupMacro(), doUntar(), handlePreambleTag(), makeTempFile(), prepFetch(), processBinaryFile(), processMetadataFile(), processPackageFiles(), rpmdsNew(), rpmfcGenerateDepends(), rpmInstall(), rpmInstallSourcePackage(), and rpmpsmStage(). |
|
Return (malloc'ed) expanded, canonicalized, file path.
Definition at line 2328 of file macro.c. References expandMacros(), rpmCleanPath(), stpcpy(), and xstrdup(). Referenced by addFileToTagAux(), buildForTarget(), Chroot(), db3close(), db3open(), doPatch(), doReadRC(), doUntar(), genCpioListAndHeader(), initSourceHeader(), packageBinaries(), packageSources(), parseFiles(), parseForSimple(), parseSpec(), processPackageFiles(), rpmdbExportInfo(), rpmdbNew(), rpmdbRebuild(), rpmdbURIPath(), rpmDetectPGPVersion(), rpmdsSysinfo(), rpmfiNew(), rpmGenPath(), rpmGetFilesystemUsage(), rpmInstall(), rpmpsmStage(), rpmQueryVerify(), rpmsxParse(), rpmts_Run(), rpmtsCreate(), rpmtsOpenDB(), rpmtsOpenSDB(), runScript(), setPathDefault(), and unsatisfiedDepend(). |
|
Return URL path(s) from a (URL prefixed) pattern glob.
Definition at line 1712 of file macro.c. References _free(), 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(), processBinaryFile(), rpmgiGlobArgv(), rpmInitMacros(), rpmInstall(), and rpmReadPackageManifest(). |
|
Initialize macro context from set of macrofile(s).
Definition at line 2013 of file macro.c. References _free(), _suffix, RMIL_CMDLINE, rpmGlob(), rpmLoadMacroFile(), rpmLoadMacros(), and xstrdup(). Referenced by rpmReadRC(). |
|
Load macro context from a macro file.
Definition at line 1980 of file macro.c. References Fclose(), Ferror(), Fopen(), max_macro_depth, rdcl(), RMIL_MACROFILES, rpmDefineMacro(), and SKIPBLANK. Referenced by expandMacro(), and rpmInitMacros(). |
|
Load macros from specific context into global context.
Definition at line 1959 of file macro.c. References addMacro(), MacroEntry_s::body, MacroContext_s::macroTable, MacroEntry_s::name, and MacroEntry_s::opts. Referenced by rpmInitMacros(). |
|
Sort entries in macro table.
Definition at line 192 of file macro.c. References compareMacroName(), MacroContext_s::firstFree, and MacroContext_s::macroTable. Referenced by addMacro(), delMacro(), and freeArgs(). |
|
< missing argument < missing argument < memory allocation failed Definition at line 1597 of file macro.c. References POPT_ERROR_MALLOC, and POPT_ERROR_NOARG. Referenced by XpoptParseArgvString(). |
|
< memory allocation failed < error in paramter quoting < error in paramter quoting Definition at line 1641 of file macro.c. References alloca(), POPT_ARGV_ARRAY_GROW_DELTA, POPT_ERROR_BADQUOTE, POPT_ERROR_MALLOC, and XpoptDupArgv(). Referenced by rpmGlob(). |
|
|
|
Definition at line 106 of file macro.c. Referenced by expandMacro(), and rpmLoadMacroFile(). |
|
Definition at line 114 of file macro.c. Referenced by expandMacro(), and expandMacros(). |
|
Definition at line 110 of file macro.c. Referenced by expandMacro(), and expandMacros(). |
|
|
|
|
|
|
|
|