rpmio/macro.c -
#include 'system.h'
#include <stdarg.h>
#include 'rpmio_internal.h'
#include 'rpmmessages.h'
#include 'rpmerr.h'
#include 'rpmmacro.h'
#include 'debug.h'
struct MacroBuf_s
Macro expansion state.
#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 MACRO_CHUNK_SIZE 16
#define SKIPBLANK(_s, _c)
#define SKIPNONBLANK(_s, _c)
#define COPYNAME(_ne, _s, _c)
#define COPYOPTS(_oe, _s, _c)
#define COPYBODY(_be, _s, _c)
typedef MacroBuf_s * MacroBuf
Macro expansion state.
int expandMacro (MacroBuf mb)
The main macro recursion loop.
void * _free (const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int compareMacroName (const void *ap, const void *bp)
Compare macro entries by name (qsort/bsearch).
void expandMacroTable (MacroContext mc)
Enlarge macro table.
void sortMacroTable (MacroContext mc)
Sort entries in macro table.
void rpmDumpMacroTable (MacroContext mc, FILE *fp)
Print macros to file stream.
MacroEntry * findEntry (MacroContext mc, const char *name, size_t namelen)
Find entry in macro table.
char * rdcl (char *buf, size_t size, FD_t fd, int escapes)
fgets(3) analogue that reads \ continuations.
const char * matchchar (const char *p, char pl, char pr)
Return text between pl and matching pr characters.
void printMacro (MacroBuf mb, const char *s, const char *se)
Pre-print macro expression to be expanded.
void printExpansion (MacroBuf mb, const char *t, const char *te)
Post-print expanded macro expression.
int expandT (MacroBuf mb, const char *f, size_t flen)
Save source and expand field into target.
int expandU (MacroBuf mb, char *u, size_t ulen)
Save source/target and expand macro in u.
int doShellEscape (MacroBuf mb, const char *cmd, size_t clen)
Expand output of shell command into target buffer.
const char * doDefine (MacroBuf mb, const char *se, int level, int expandbody)
Parse (and execute) new macro definition.
const char * doUndefine (MacroContext mc, const char *se)
Parse (and execute) macro undefinition.
void pushMacro (MacroEntry *mep, const char *n, const char *o, const char *b, int level)
Push new macro definition onto macro entry stack.
void popMacro (MacroEntry *mep)
Pop macro definition from macro entry stack.
void freeArgs (MacroBuf mb)
Free parsed arguments for parameterized macro.
const char * grabArgs (MacroBuf mb, const MacroEntry me, const char *se, char lastc)
Parse arguments (to next new line) for parameterized macro.
void doOutput (MacroBuf mb, int waserror, const char *msg, size_t msglen)
Perform macro message output.
void doFoo (MacroBuf mb, int negate, const char *f, size_t fn, const char *g, size_t gn)
Execute macro primitives.
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.
void rpmInitMacros (MacroContext mc, const char *macrofiles)
Initialize global 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.
int _debug = 0
MacroContext_s rpmGlobalMacroContext_s
MacroContext rpmGlobalMacroContext = &rpmGlobalMacroContext_s
MacroContext_s rpmCLIMacroContext_s
MacroContext rpmCLIMacroContext = &rpmCLIMacroContext_s
int max_macro_depth = 16
int print_macro_trace = 0
int print_expand_trace = 0
Value:
{ while(((_c) = *(_s)) && !iseol(_c)) { if ((_c) == '\') (_s)++; *(_be)++ = *(_s)++; } *(_be) = ' '; }
Definition at line 448 of file macro.c.
Value:
{ SKIPBLANK(_s,_c); while(((_c) = *(_s)) && (xisalnum(_c) || (_c) == '_')) *(_ne)++ = *(_s)++; *(_ne) = ' '; }
Definition at line 435 of file macro.c.
Referenced by doDefine(), and doUndefine().
Value:
{ while(((_c) = *(_s)) && (_c) != ')') *(_oe)++ = *(_s)++; *(_oe) = ' '; }
Definition at line 442 of file macro.c.
Definition at line 12 of file macro.c.
Referenced by doDefine(), doFoo(), expandMacro(), and grabArgs().
Definition at line 14 of file macro.c.
Referenced by doDefine(), doShellEscape(), doUndefine(), expandMacro(), printExpansion(), printMacro(), and rdcl().
Definition at line 104 of file macro.c.
Referenced by expandMacroTable().
Definition at line 87 of file macro.c.
Definition at line 83 of file macro.c.
Referenced by doShellEscape(), and expandMacro().
Value:
while (((_c) = *(_s)) && isblank(_c)) (_s)++;
Definition at line 427 of file macro.c.
Referenced by doDefine(), and rpmInitMacros().
Value:
while (((_c) = *(_s)) && !(isblank(_c) || iseol(_c))) (_s)++;
Definition at line 431 of file macro.c.
Definition at line 16 of file macro.c.
Referenced by doFoo(), and expandMacro().
Macro expansion state.
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Parameters:
Return values:
Definition at line 121 of file macro.c.
Add macro to context.
Deprecated: Use rpmDefineMacro().
Parameters:
Definition at line 1490 of file macro.c.
References expandMacroTable(), findEntry(), MacroContext_s::firstFree, MacroContext_s::macrosAllocated, MacroContext_s::macroTable, pushMacro(), rpmGlobalMacroContext, and sortMacroTable().
Referenced by addSource(), buildForTarget(), do_verifyGPGSignature(), doAddMacro(), doDefine(), doReadRC(), doScript(), doSetupMacro(), expandMacro(), generateDepends(), grabArgs(), handlePreambleTag(), main(), makeGPGSignature(), makePGPSignature(), parseSpec(), rpmInstallLoadMacros(), rpmLoadMacros(), rpmRebuildTargetVars(), setVar(), setVarDefault(), and verifyPGPSignature().
Compare macro entries by name (qsort/bsearch).
Parameters:
Returns: result of comparison
Definition at line 137 of file macro.c.
References MacroEntry_s::name.
Referenced by findEntry(), and sortMacroTable().
Delete macro from context.
Parameters:
Definition at line 1516 of file macro.c.
References findEntry(), popMacro(), rpmGlobalMacroContext, and sortMacroTable().
Referenced by doDelMacro(), doScript(), doUndefine(), generateDepends(), handlePreambleTag(), makeGPGSignature(), makePGPSignature(), parseSpec(), rpmRebuildTargetVars(), and verifyPGPSignature().
Parse (and execute) new macro definition.
Parameters:
Returns: address to continue parsing
Definition at line 600 of file macro.c.
References _, addMacro(), COPYBODY, COPYNAME, COPYOPTS, expandU(), isblank, iseol, matchchar(), RPMERR_BADSPEC, rpmError, SKIPBLANK, and xisalpha().
Referenced by expandMacro(), and rpmDefineMacro().
Execute macro primitives.
Parameters:
Definition at line 1026 of file macro.c.
References COMPRESSED_OTHER, expandT(), expandU(), isblank, isCompressed(), rpmCompressedMagic, rpmIsVerbose, STREQ, urlPath(), and xisdigit().
Perform macro message output.
Parameters:
Definition at line 999 of file macro.c.
References expandU(), RPMERR_BADSPEC, and rpmError.
Expand output of shell command into target buffer.
Parameters:
Returns: result of expansion
Definition at line 560 of file macro.c.
References expandU(), iseol, and SAVECHAR.
Parse (and execute) macro undefinition.
Parameters:
Returns: address to continue parsing
Definition at line 696 of file macro.c.
References _, COPYNAME, delMacro(), iseol, RPMERR_BADSPEC, rpmError, and xisalpha().
The main macro recursion loop.
Todo: Dynamically reallocate target buffer.
Parameters:
Returns: 0 on success, 1 on failure
Definition at line 1126 of file macro.c.
References _, addMacro(), MacroEntry_s::body, doDefine(), doFoo(), doOutput(), doShellEscape(), doUndefine(), expandT(), findEntry(), freeArgs(), grabArgs(), isblank, iseol, matchchar(), max_macro_depth, MacroEntry_s::name, MacroEntry_s::opts, print_expand_trace, print_macro_trace, printExpansion(), printMacro(), RMIL_GLOBAL, rpmDumpMacroTable(), RPMERR_BADSPEC, rpmError, SAVECHAR, STREQ, MacroEntry_s::used, and xisalnum().
Referenced by expandMacros(), expandT(), and expandU().
Expand macro into buffer.
Deprecated: Use rpmExpand().
Todo: Eliminate from API.
Parameters:
Return values:
Parameters:
Returns: 0 on success
Definition at line 1451 of file macro.c.
References _, alloca(), MacroBuf_s::depth, MacroBuf_s::expand_trace, expandMacro(), MacroBuf_s::macro_trace, MacroBuf_s::mc, MacroBuf_s::nb, print_expand_trace, print_macro_trace, RPMERR_BADSPEC, rpmError, rpmGlobalMacroContext, MacroBuf_s::s, MacroBuf_s::spec, and MacroBuf_s::t.
Referenced by addFileToTagAux(), copyNextLine(), processPackageFiles(), rpmExpand(), and rpmGetPath().
Enlarge macro table.
Parameters:
Definition at line 157 of file macro.c.
References MACRO_CHUNK_SIZE, xmalloc(), and xrealloc().
Save source and expand field into target.
Parameters:
Returns: result of expansion
Definition at line 465 of file macro.c.
References alloca(), and expandMacro().
Referenced by doFoo(), and expandMacro().
Save source/target and expand macro in u.
Parameters:
Returns: result of expansion
Definition at line 520 of file macro.c.
References alloca(), and expandMacro().
Referenced by doDefine(), doFoo(), doOutput(), doShellEscape(), and grabArgs().
Find entry in macro table.
Parameters:
Returns: address of slot in macro table with name (or NULL)
Definition at line 241 of file macro.c.
References compareMacroName(), MacroEntry_s::name, and rpmGlobalMacroContext.
Referenced by addMacro(), delMacro(), expandMacro(), headerAddI18NString(), headerAddOrAppendEntry(), headerAppendEntry(), headerFindI18NString(), headerGetRawEntry(), headerIsEntry(), headerModifyEntry(), headerRemoveEntry(), htGetEntry(), htHasEntry(), and intGetEntry().
Free parsed arguments for parameterized macro.
Parameters:
Definition at line 801 of file macro.c.
References _, MacroEntry_s::body, MacroContext_s::firstFree, MacroEntry_s::level, MacroContext_s::macroTable, MacroEntry_s::name, popMacro(), RPMERR_BADSPEC, rpmError, sortMacroTable(), and MacroEntry_s::used.
Parse arguments (to next new line) for parameterized macro.
Todo: Use popt rather than getopt to parse args.
Parameters:
Returns: address to continue parsing
Definition at line 852 of file macro.c.
References _, addMacro(), alloca(), expandU(), isblank, RPMERR_BADSPEC, rpmError, and stpcpy().
Return type of compression used in file.
Parameters:
Return values:
Returns: 0 on success, 1 on I/O error
Definition at line 1668 of file macro.c.
References _, COMPRESSED_BZIP2, COMPRESSED_NOT, COMPRESSED_OTHER, COMPRESSED_ZIP, Fclose(), Ferror(), Fopen(), Fread(), Fstrerror(), rpmCompressedMagic, RPMERR_BADSPEC, and rpmError.
Referenced by buildForTarget(), doFoo(), doPatch(), and doUntar().
Return text between pl and matching pr characters.
Parameters:
Returns: address of last char before pr (or NULL)
Definition at line 320 of file macro.c.
Referenced by doDefine(), and expandMacro().
Pop macro definition from macro entry stack.
Parameters:
Definition at line 779 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.
Parameters:
Definition at line 390 of file macro.c.
References _, and iseol.
Pre-print macro expression to be expanded.
Parameters:
Definition at line 346 of file macro.c.
References _, and iseol.
Push new macro definition onto macro entry stack.
Parameters:
Definition at line 750 of file macro.c.
References _free(), MacroEntry_s::body, MacroEntry_s::level, MacroEntry_s::name, MacroEntry_s::opts, MacroEntry_s::prev, MacroEntry_s::used, xmalloc(), and xstrdup().
fgets(3) analogue that reads \ continuations.
Last newline always trimmed.
Definition at line 277 of file macro.c.
References fdGetFILE, and iseol.
Referenced by rpmInitMacros().
Canonicalize file path.
Parameters:
Returns: canonicalized path (malloc'ed)
Definition at line 1768 of file macro.c.
References begin.
Referenced by doLookup(), openDatabase(), rpmdbMoveDatabase(), rpmdbRemoveDatabase(), rpmGetPath(), and rpmQueryVerify().
Define macro in context.
Parameters:
Returns:
Todo:
Document.
Definition at line 1532 of file macro.c.
References alloca(), doDefine(), MacroBuf_s::mc, and rpmGlobalMacroContext.
Referenced by main(), rpmdbRebuild(), and rpmInitMacros().
Print macros to file stream.
Parameters:
Definition at line 200 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.
Referenced by expandMacro(), and rpmShowRC().
Return (malloc'ed) concatenated macro expansion(s).
Parameters:
Returns: macro expansion (malloc'ed)
Definition at line 1718 of file macro.c.
References expandMacros(), stpcpy(), and xstrdup().
Referenced by checkForValidArchitectures(), checkPassPhrase(), cpio_doio(), dbiTagsInit(), do_verifyGPGSignature(), do_wait_for_lock(), doPrimary(), doScript(), doSetupMacro(), fillOutMainPackage(), generateDepends(), i18nTag(), ignoreDep(), main(), makeGPGSignature(), makePGPSignature(), newRpmdb(), packageBinaries(), parseForRegexLang(), parseForRegexMultiLib(), parseSpec(), processPackageFiles(), rdToken(), readLine(), rpmdbSetIteratorRE(), rpmExpandNumeric(), rpmGetPassPhrase(), rpmLookupSignatureType(), rpmReadConfigFiles(), rpmRollback(), runScript(), skipFiles(), urlFind(), verifyGPGSignature(), verifyPGPSignature(), and writeRPM().
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.
Parameters:
Returns: numeric value
Definition at line 1741 of file macro.c.
References _free(), and rpmExpand().
Referenced by dbiOpen(), genCpioListAndHeader(), main(), newRpmdb(), openDatabase(), parseRCPOT(), parseSpec(), processPackageFiles(), rpmdbInit(), rpmdbOpen(), rpmdbRebuild(), rpmdbVerify(), rpmLeadVersion(), and skipFiles().
Destroy macro context.
Parameters:
Definition at line 1641 of file macro.c.
References _free(), MacroEntry_s::body, MacroContext_s::firstFree, MacroContext_s::macroTable, MacroEntry_s::name, MacroEntry_s::opts, MacroEntry_s::prev, and rpmGlobalMacroContext.
Referenced by build(), and main().
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.
Parameters:
Returns: expanded, merged, canonicalized path (malloc'ed)
Definition at line 1887 of file macro.c.
References _free(), alloca(), rpmGetPath(), URL_IS_DASH, and urlPath().
Referenced by buildForTarget(), db1close(), db1open(), db3close(), db3open(), db_init(), doScript(), doSetupMacro(), generateDepends(), handlePreambleTag(), makeTempFile(), parsePreamble(), processBinaryFile(), processPackageFiles(), psmStage(), rpmInstall(), and rpmInstallSourcePackage().
Return (malloc'ed) expanded, canonicalized, file path.
Parameters:
Returns: canonicalized path (malloc'ed)
Definition at line 1856 of file macro.c.
References expandMacros(), rpmCleanPath(), stpcpy(), and xstrdup().
Referenced by addFileToTagAux(), addSource(), buildForTarget(), checkSpec(), db3close(), db3open(), doPatch(), doReadRC(), doRmSource(), doUntar(), newRpmdb(), packageBinaries(), packageSources(), parseFiles(), parseForSimple(), parseSpec(), processPackageFiles(), processSourceFiles(), psmStage(), readIcon(), rpmdbRebuild(), rpmDetectPGPVersion(), rpmErase(), rpmGenPath(), rpmGetFilesystemUsage(), rpmInstall(), and verifyPGPSignature().
Initialize global macro context from set of macrofile(s).
Parameters:
Definition at line 1568 of file macro.c.
References _free(), Fclose(), Ferror(), Fopen(), getenv(), max_macro_depth, rdcl(), RMIL_CMDLINE, RMIL_MACROFILES, rpmCLIMacroContext, rpmDefineMacro(), rpmGlobalMacroContext, rpmLoadMacros(), SKIPBLANK, and xstrdup().
Load macros from specific context into global context.
Parameters:
Definition at line 1547 of file macro.c.
References addMacro(), MacroEntry_s::body, MacroContext_s::firstFree, MacroContext_s::macroTable, MacroEntry_s::name, MacroEntry_s::opts, and rpmGlobalMacroContext.
Referenced by rpmInitMacros().
Sort entries in macro table.
Parameters:
Definition at line 179 of file macro.c.
References compareMacroName().
Referenced by addMacro(), delMacro(), and freeArgs().
Definition at line 6 of file macro.c.
Definition at line 89 of file macro.c.
Referenced by expandMacro(), and rpmInitMacros().
Definition at line 100 of file macro.c.
Referenced by expandMacro(), and expandMacros().
Definition at line 98 of file macro.c.
Referenced by expandMacro(), and expandMacros().
Definition at line 66 of file macro.c.
Referenced by rpmInitMacros().
Definition at line 64 of file macro.c.
Definition at line 61 of file macro.c.
Referenced by addMacro(), delMacro(), expandMacros(), findEntry(), rpmDefineMacro(), rpmDumpMacroTable(), rpmFreeMacros(), rpmInitMacros(), and rpmLoadMacros().
Definition at line 59 of file macro.c.
Generated automatically by Doxygen for rpm from the source code.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |