rpm 5.3.12
Data Structures | Defines | Typedefs | Functions | Variables
rpmio/macro.c File Reference
#include "system.h"
#include <stdarg.h>
#include <rpmio_internal.h>
#include <rpmlog.h>
#include <mire.h>
#include <rpmaug.h>
#include <rpmficl.h>
#include <rpmjs.h>
#include <rpmperl.h>
#include <rpmpython.h>
#include <rpmruby.h>
#include <rpmsm.h>
#include <rpmsquirrel.h>
#include <rpmsql.h>
#include <rpmtcl.h>
#include <rpmuuid.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)   ((char)(_c) == ' ' || (char)(_c) == '\t')
#define iseol(_c)   ((char)(_c) == '\n' || (char)(_c) == '\r')
#define STREQ(_t, _f, _fn)   ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn)))
#define _RPMAUG_INTERNAL
#define _MACRO_INTERNAL
#define SAVECHAR(_mb, _c)   { *(_mb)->t = (char) (_c), (_mb)->t++, (_mb)->nb--; }
#define _MAX_MACRO_DEPTH   16
#define _PRINT_MACRO_TRACE   0
#define _PRINT_EXPAND_TRACE   0
#define _MAX_LOAD_DEPTH   2
#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 struct MacroBuf_sMacroBuf

Functions

static int expandMacro (MacroBuf mb)
 Parse args and string for PHP like %{foo <args> : <string> } syntax.
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.
static char * dupMacroEntry (MacroEntry me)
void rpmDumpMacroTable (MacroContext mc, FILE *fp)
 Print macros to file stream.
int rpmGetMacroEntries (MacroContext mc, void *_mire, int used, const char ***avp)
 Return macro entries as string array.
static MacroEntryfindEntry (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 expandFIFO (MacroBuf mb, MacroEntry me, const char *g, size_t gn)
static int XpoptDupArgv (int argc, char **argv, int *argcPtr, char ***argvPtr)
static int XpoptParseArgvString (const char *s, int *argcPtr, char ***argvPtr)
int rpmSecuritySaneFile (const char *filename)
 Check whether configuration file is moderately secure to load.
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.
int rpmUndefineMacro (MacroContext mc, const char *macro)
 Undefine macro in context.
void rpmLoadMacros (MacroContext mc, int level)
 Load macros from specific context into global context.
int rpmLoadMacroFile (MacroContext mc, const char *fn, int nesting)
 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).
char * rpmMCExpand (MacroContext mc, const char *arg,...)
 Return (malloc'ed) concatenated macro expansion(s) in a context.
int rpmExpandNumeric (const char *arg)
 Return macro expansion as a numeric value.
char * rpmCleanPath (char *path)
 Canonicalize file path.
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
int _max_load_depth = 2
static size_t _macro_BUFSIZ = 16 * 1024
static int _debug = 0

Detailed Description

Definition in file macro.c.


Define Documentation

#define _MACRO_INTERNAL

Definition at line 96 of file macro.c.

#define _MAX_LOAD_DEPTH   2

Definition at line 163 of file macro.c.

#define _MAX_MACRO_DEPTH   16

Definition at line 151 of file macro.c.

Referenced by rpmLoadMacroFile().

#define _PRINT_EXPAND_TRACE   0

Definition at line 159 of file macro.c.

#define _PRINT_MACRO_TRACE   0

Definition at line 155 of file macro.c.

#define _RPMAUG_INTERNAL

Definition at line 73 of file macro.c.

#define _suffix (   _s,
  _x 
)    (slen >= sizeof(_x) && !strcmp((_s)+slen-(sizeof(_x)-1), (_x)))
#define COPYNAME (   _ne,
  _s,
  _c 
)
Value:
{       SKIPBLANK(_s,_c);       \
        while(((_c) = (int) *(_s)) && (xisalnum(_c) || (_c) == (int) '_')) \
                *(_ne)++ = *(_s)++; \
        *(_ne) = '\0';          \
    }

Definition at line 586 of file macro.c.

Referenced by doDefine(), and doUndefine().

#define COPYOPTS (   _oe,
  _s,
  _c 
)
Value:
{   while(((_c) = (int) *(_s)) && (_c) != (int) ')') \
                *(_oe)++ = *(_s)++; \
        *(_oe) = '\0';          \
    }

Definition at line 593 of file macro.c.

Referenced by doDefine().

#define isblank (   _c)    ((char)(_c) == ' ' || (char)(_c) == '\t')

Definition at line 9 of file macro.c.

Referenced by doDefine(), doFoo(), expandMacro(), and grabArgs().

#define iseol (   _c)    ((char)(_c) == '\n' || (char)(_c) == '\r')

Definition at line 11 of file macro.c.

Referenced by doDefine(), doShellEscape(), doUndefine(), expandMacro(), printExpansion(), printMacro(), and rdcl().

#define MACRO_CHUNK_SIZE   16

Definition at line 168 of file macro.c.

Referenced by expandMacroTable().

#define POPT_ARGV_ARRAY_GROW_DELTA   5

Definition at line 1473 of file macro.c.

Referenced by XpoptParseArgvString().

#define POPT_ERROR_BADQUOTE   -15

error in paramter quoting

Definition at line 1470 of file macro.c.

Referenced by XpoptParseArgvString().

#define POPT_ERROR_MALLOC   -21

memory allocation failed

Definition at line 1471 of file macro.c.

Referenced by XpoptDupArgv(), and XpoptParseArgvString().

#define POPT_ERROR_NOARG   -10

missing argument

Definition at line 1469 of file macro.c.

Referenced by XpoptDupArgv().

#define SAVECHAR (   _mb,
  _c 
)    { *(_mb)->t = (char) (_c), (_mb)->t++, (_mb)->nb--; }

Definition at line 147 of file macro.c.

Referenced by doShellEscape(), and expandMacro().

#define SKIPBLANK (   _s,
  _c 
)
Value:
/*@-globs@*/    /* FIX: __ctype_b */ \
        while (((_c) = (int) *(_s)) && isblank(_c)) \
                (_s)++;         \

Definition at line 574 of file macro.c.

Referenced by doDefine(), and rpmLoadMacroFile().

#define SKIPNONBLANK (   _s,
  _c 
)
Value:
/*@-globs@*/    /* FIX: __ctype_b */ \
        while (((_c) = (int) *(_s)) && !(isblank(_c) || iseol(_c))) \
                (_s)++;         \

Definition at line 580 of file macro.c.

#define STREQ (   _t,
  _f,
  _fn 
)    ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn)))

Definition at line 13 of file macro.c.

Referenced by doFoo(), and expandMacro().


Typedef Documentation

typedef struct MacroBuf_s * MacroBuf

Function Documentation

void addMacro ( MacroContext  mc,
const char *  n,
const char *  o,
const char *  b,
int  level 
)

Add macro to context.

Deprecated:
Use rpmDefineMacro().
Parameters:
mcmacro context (NULL uses global context).
nmacro name
omacro paramaters
bmacro body
levelmacro recursion level (0 is entry API)

Definition at line 2638 of file macro.c.

References _, expandMacroTable(), findEntry(), name, pushMacro(), rpmGlobalMacroContext, rpmlog(), RPMLOG_ERR, and sortMacroTable().

Referenced by addMacroDefault(), addSource(), doDefine(), doSetupMacro(), expandMacro(), grabArgs(), handlePreambleTag(), headerMacrosLoad(), makeGPGSignature(), parsePreamble(), parseSpec(), rpmcliInstall(), rpmLoadMacros(), rpmPlatform(), rpmRebuildTargetVars(), rpmtsOpenSDB(), setDefaults(), and setPathDefault().

static int compareMacroName ( const void *  ap,
const void *  bp 
) [static]

Compare macro entries by name (qsort/bsearch).

Parameters:
ap1st macro entry
bp2nd macro entry
Returns:
result of comparison

Definition at line 192 of file macro.c.

Referenced by findEntry(), and sortMacroTable().

void delMacro ( MacroContext  mc,
const char *  n 
)

Delete macro from context.

Parameters:
mcmacro context (NULL uses global context).
nmacro name

Definition at line 2677 of file macro.c.

References findEntry(), popMacro(), rpmGlobalMacroContext, and sortMacroTable().

Referenced by doUndefine(), handlePreambleTag(), headerMacrosUnload(), makeGPGSignature(), parseSpec(), rpmcliInstall(), rpmRebuildTargetVars(), and rpmtsOpenSDB().

static const char* doDefine ( MacroBuf  mb,
const char *  se,
int  level,
int  expandbody 
) [static]

Parse (and execute) new macro definition.

Parameters:
mbmacro expansion state
semacro definition to parse
levelmacro recursion level
expandbodyshould body be expanded?
Returns:
address to continue parsing

Definition at line 736 of file macro.c.

References _, _macro_BUFSIZ, addMacro(), alloca(), COPYNAME, COPYOPTS, expandU(), isblank, iseol, matchchar(), MacroBuf_s::mc, rpmlog(), RPMLOG_ERR, SKIPBLANK, and xisalpha().

Referenced by expandMacro(), and rpmDefineMacro().

static void doFoo ( MacroBuf  mb,
int  negate,
const char *  f,
size_t  fn,
const char *  g,
size_t  gn 
) [static]

Execute macro primitives.

Parameters:
mbmacro expansion state
negateshould logic be inverted?
fbeginning of field f
fnlength of field f
gbeginning of field g
gnlength of field g

Definition at line 1231 of file macro.c.

References _macro_BUFSIZ, alloca(), COMPRESSED_OTHER, expandT(), expandU(), getenv(), isblank, isCompressed(), PATH_MAX, realpath(), rpmlog(), RPMLOG_ERR, RPMLOG_INFO, RPMLOG_MASK, rpmlogSetMask(), rpmuuidMake(), stpcpy(), stpncpy(), STREQ, urlPath(), uuid_ns, uuid_version, xisdigit(), and xisspace().

Referenced by expandMacro().

static void doOutput ( MacroBuf  mb,
int  waserror,
const char *  msg,
size_t  msglen 
) [static]

Perform macro message output.

Parameters:
mbmacro expansion state
waserroruse rpmError()?
msgmessage to ouput
msglenno. of bytes in message

Definition at line 1205 of file macro.c.

References _macro_BUFSIZ, alloca(), expandU(), rpmlog(), and RPMLOG_ERR.

Referenced by expandMacro().

static int doShellEscape ( MacroBuf  mb,
const char *  cmd,
size_t  clen 
) [static]

Expand output of shell command into target buffer.

Parameters:
mbmacro expansion state
cmdshell command
clenno. bytes in shell command
Returns:
result of expansion

Definition at line 697 of file macro.c.

References _macro_BUFSIZ, alloca(), expandU(), iseol, MacroBuf_s::nb, SAVECHAR, and MacroBuf_s::t.

Referenced by expandMacro().

static const char* doUndefine ( MacroContext  mc,
const char *  se 
) [static]

Parse (and execute) macro undefinition.

Parameters:
mcmacro context
semacro name to undefine
Returns:
address to continue parsing

Definition at line 871 of file macro.c.

References _, _macro_BUFSIZ, alloca(), COPYNAME, delMacro(), iseol, rpmlog(), RPMLOG_ERR, and xisalpha().

Referenced by expandMacro(), and rpmUndefineMacro().

static char* dupMacroEntry ( MacroEntry  me) [static]

Definition at line 256 of file macro.c.

References stpcpy(), and xmalloc().

Referenced by rpmGetMacroEntries().

static int expandFIFO ( MacroBuf  mb,
MacroEntry  me,
const char *  g,
size_t  gn 
) [static]

Definition at line 1449 of file macro.c.

References expandT().

Referenced by expandMacro().

static int expandMacro ( MacroBuf  mb) [static]
int expandMacros ( void *  spec,
MacroContext  mc,
char *  sbuf,
size_t  slen 
)

Expand macro into buffer.

Deprecated:
Use rpmExpand().
Todo:
Eliminate from API.
Parameters:
speccookie (unused)
mcmacro context (NULL uses global context).
Return values:
sbufinput macro to expand, output expansion
Parameters:
slensize of buffer
Returns:
0 on success

Definition at line 2603 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, rpmGlobalMacroContext, rpmlog(), RPMLOG_ERR, MacroBuf_s::s, MacroBuf_s::spec, and MacroBuf_s::t.

Referenced by addFileToTagAux(), copyNextLineFromOFI(), processPackageFiles(), rpmExpand(), rpmGetPath(), and rpmMCExpand().

static void expandMacroTable ( MacroContext  mc) [static]

Enlarge macro table.

Parameters:
mcmacro context

Definition at line 212 of file macro.c.

References MACRO_CHUNK_SIZE, xmalloc(), and xrealloc().

Referenced by addMacro().

static int expandT ( MacroBuf  mb,
const char *  f,
size_t  flen 
) [static]

Save source and expand field into target.

Parameters:
mbmacro expansion state
ffield
flenno. bytes in field
Returns:
result of expansion

Definition at line 607 of file macro.c.

References alloca(), expandMacro(), and MacroBuf_s::s.

Referenced by doFoo(), expandFIFO(), and expandMacro().

static int expandU ( MacroBuf  mb,
char *  u,
size_t  ulen 
) [static]

Save source/target and expand macro in u.

Parameters:
mbmacro expansion state
uinput macro, output expansion
ulenno. bytes in u buffer
Returns:
result of expansion

Definition at line 660 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().

static MacroEntry* findEntry ( MacroContext  mc,
const char *  name,
size_t  namelen 
) [static]

Find entry in macro table.

Parameters:
mcmacro context
namemacro name
namelenno. of bytes
Returns:
address of slot in macro table with name (or NULL)

Definition at line 365 of file macro.c.

References alloca(), compareMacroName(), and rpmGlobalMacroContext.

Referenced by addMacro(), delMacro(), and expandMacro().

static void freeArgs ( MacroBuf  mb) [static]

Free parsed arguments for parameterized macro.

Parameters:
mbmacro expansion state

Definition at line 979 of file macro.c.

References _, MacroBuf_s::depth, MacroBuf_s::mc, popMacro(), rpmlog(), RPMLOG_ERR, and sortMacroTable().

Referenced by expandMacro().

static const char* grabArgs ( MacroBuf  mb,
const MacroEntry  me,
const char *  se,
const char *  lastc 
) [static]

Parse arguments (to next new line) for parameterized macro.

Todo:
Use popt rather than getopt to parse args.
Parameters:
mbmacro expansion state
memacro entry slot
searguments to parse
lastcstop parsing at lastc
Returns:
address to continue parsing

Definition at line 1030 of file macro.c.

References _, _free(), _macro_BUFSIZ, addMacro(), alloca(), MacroBuf_s::depth, expandU(), isblank, MacroBuf_s::mc, rpmlog(), RPMLOG_ERR, stpcpy(), and xcalloc().

Referenced by expandMacro().

int isCompressed ( const char *  file,
rpmCompressedMagic compressed 
)

Return type of compression used in file.

Parameters:
filename of file
Return values:
compressedaddress of compression type
Returns:
0 on success, 1 on I/O error

Definition at line 2939 of file macro.c.

References _, COMPRESSED_BZIP2, COMPRESSED_LZMA, COMPRESSED_LZOP, COMPRESSED_NOT, COMPRESSED_OTHER, COMPRESSED_XZ, COMPRESSED_ZIP, Fclose(), Ferror(), Fopen(), Fread(), Fstrerror(), rpmlog(), and RPMLOG_ERR.

Referenced by doFoo(), doPatch(), and doUntar().

static const char* matchchar ( const char *  p,
char  pl,
char  pr 
) [static]

Return text between pl and matching pr characters.

Parameters:
pstart of text
plleft char, i.e. '[', '(', '{', etc.
prright char, i.e. ']', ')', '}', etc.
Returns:
address of last char before pr (or NULL)

Definition at line 467 of file macro.c.

Referenced by doDefine(), expandMacro(), and rpmLoadMacroFile().

static void popMacro ( MacroEntry mep) [static]

Pop macro definition from macro entry stack.

Parameters:
mepaddress of macro entry slot

Definition at line 957 of file macro.c.

References _free().

Referenced by delMacro(), and freeArgs().

static void printExpansion ( MacroBuf  mb,
const char *  t,
const char *  te 
) [static]

Post-print expanded macro expression.

Parameters:
mbmacro expansion state
tcurrent expansion string result
teend of string

Definition at line 537 of file macro.c.

References _, MacroBuf_s::depth, and iseol.

Referenced by expandMacro().

static void printMacro ( MacroBuf  mb,
const char *  s,
const char *  se 
) [static]

Pre-print macro expression to be expanded.

Parameters:
mbmacro expansion state
scurrent expansion string
seend of string

Definition at line 493 of file macro.c.

References _, MacroBuf_s::depth, and iseol.

Referenced by expandMacro().

static void pushMacro ( MacroEntry mep,
const char *  n,
const char *  o,
const char *  b,
int  level 
) [static]

Push new macro definition onto macro entry stack.

Parameters:
mepaddress of macro entry slot
nmacro name
omacro parameters (NULL if none)
bmacro body (NULL becomes "")
levelmacro recursion level

Definition at line 924 of file macro.c.

References _free(), name, xmalloc(), and xstrdup().

Referenced by addMacro().

static char* rdcl ( char *  buf,
size_t  size,
FD_t  fd 
) [static]

fgets(3) analogue that reads \ continuations.

Last newline always trimmed.

Parameters:
bufinput buffer
sizeinbut buffer size (bytes)
fdfile handle
Returns:
buffer, or NULL on end-of-file

Definition at line 403 of file macro.c.

References fdGetFILE, and iseol.

Referenced by rpmLoadMacroFile().

char* rpmCleanPath ( char *  path)

Canonicalize file path.

Note:
Path canonicalization always removes the pesky trailing '/'.
Parameters:
pathpath to canonicalize (in-place)
Returns:
pointer to path

Definition at line 3152 of file macro.c.

Referenced by db3open(), doLookup(), relocateFileList(), rpmGetPath(), rpmioAccess(), and rpmQueryVerify().

int rpmDefineMacro ( MacroContext  mc,
const char *  macro,
int  level 
)

Define macro in context.

Parameters:
mcmacro context (NULL uses global context).
macromacro name, options, body
levelmacro recursion level (0 is entry API)
Returns:
Todo:
Document.

Definition at line 2693 of file macro.c.

References alloca(), doDefine(), MacroBuf_s::mc, and rpmGlobalMacroContext.

Referenced by ftsCacheUpdate(), main(), rpmcliAllArgCallback(), rpmioAllArgCallback(), and rpmLoadMacroFile().

void rpmDumpMacroTable ( MacroContext  mc,
FILE *  fp 
)

Print macros to file stream.

Parameters:
mcmacro context (NULL uses global context).
fpfile stream (NULL uses stderr).

Definition at line 284 of file macro.c.

References _, and rpmGlobalMacroContext.

Referenced by expandMacro(), and rpmShowRC().

char* rpmExpand ( const char *  arg,
  ... 
)

Return (malloc'ed) concatenated macro expansion(s).

Parameters:
argmacro(s) to expand (NULL terminates list)
Returns:
macro expansion (malloc'ed)

Definition at line 3051 of file macro.c.

References _macro_BUFSIZ, expandMacros(), stpcpy(), xmalloc(), xrealloc(), and xstrdup().

Referenced by _GetPass(), addChangelog(), archScore(), checkForValidArchitectures(), checkUnpackagedFiles(), cpio_doio(), dbiTagsInit(), debevrfmtTag(), debmd5sumsTag(), defaultMachine(), doPatch(), doPrimary(), doSetupMacro(), fillOutMainPackage(), Fopen(), formatValue(), getMachineInfo(), headerMacrosLoad(), headerMacrosUnload(), i18nTag(), initGlobs(), initSourceHeader(), lookupPackage(), main(), makeGPGSignature(), Open(), open_dso(), packageBinaries(), parseBuildInstallClean(), parseForRegexLang(), parseForSimple(), parsePreamble(), parseSpec(), prepFetch(), processSourceFiles(), rdToken(), readLine(), Realpath(), rpmCheckPassPhrase(), rpmcliEvalSlurp(), rpmcliImportPubkeys(), rpmcliInstallElementPath(), rpmcliQuery(), rpmdbNew(), rpmdcParseZeroInstall(), rpmdsCpuinfo(), rpmdsGetconf(), rpmdsSysinfo(), rpmEVRmire(), rpmEVRorder(), rpmExpandNumeric(), rpmfcClassify(), rpmfcExec(), rpmfcExpandAppend(), rpmfcExpandRegexps(), rpmfcGenerateDependsHelper(), rpmfcSCRIPT(), rpmgiNext(), rpmgiOpen(), rpmInstallSourcePackage(), rpmioAllArgCallback(), rpmmiAddPattern(), rpmnsArch(), rpmnsParse(), rpmnsProbeSignature(), rpmPlatform(), rpmpsmStage(), rpmReadConfigFiles(), rpmReadRC(), rpmrepoDoRepoMetadata(), rpmrepoInitPopt(), rpmrepoMDExpand(), rpmRollback(), rpmShowProgress(), rpmShowRC(), rpmsqlNew(), rpmsqlRun(), rpmts_IDTXglob(), rpmtsAddInstallElement(), rpmtsAddObsoletes(), rpmtsAddUpgrades(), rpmtsEraseDebuginfo(), rpmtsFindPubkey(), rpmtsOpenSDB(), rpmtsRollback(), rpmtsSkipFiles(), rpmtsSolve(), rpmvtNew(), runImmedTriggers(), runInstScript(), runScript(), runTriggers(), spec_get_buildroot(), statFormat(), strsubFormat(), tagLoadATags(), tagValidate(), unsatisfiedDepend(), urlFind(), urlGetFile(), 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.

Parameters:
argmacro to expand
Returns:
numeric value

Definition at line 3125 of file macro.c.

References _free(), and rpmExpand().

Referenced by _rpmtsRun(), addReqProv(), checkPackageDeps(), checkUnpackagedFiles(), doIcon(), doPatchMacro(), getDigestAlgo(), handleInstInstalledFile(), handleOverlappedFiles(), main(), newSpec(), parseScript(), parseSpec(), processPackageFiles(), relocateFileList(), rpmcliInstall(), rpmcliQuery(), rpmcliVerify(), rpmdbOpen(), rpmErase(), rpmfcGenerateDepends(), rpmfcHelper(), rpmpsmStage(), rpmRollback(), rpmts_new(), rpmtsCreate(), rpmtsOpenSDB(), rpmtsPrepare(), rpmtsRollback(), rpmtsSkipFiles(), unsatisfiedDepend(), and urlGetFile().

void rpmFreeMacros ( MacroContext  mc)

Destroy macro context.

Parameters:
mcmacro context (NULL uses global context).

Definition at line 2912 of file macro.c.

References _free(), and rpmGlobalMacroContext.

Referenced by main(), rpmcliFini(), rpmioFini(), and rpmspecQuery().

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.

Parameters:
urlrootroot URL (often path to chroot, or NULL)
urlmdirdirectory URL (often a directory, or NULL)
urlfilefile URL (often a file, or NULL)
Returns:
expanded, merged, canonicalized path (malloc'ed)

Definition at line 3290 of file macro.c.

References _free(), alloca(), file, rpmGetPath(), URL_IS_DASH, and urlPath().

Referenced by addSource(), createDir(), db3close(), db3open(), db_init(), doIcon(), doPatch(), doScript(), doSetupMacro(), doUntar(), handlePreambleTag(), isSpecFile(), main(), prepFetch(), processBinaryFile(), processMetadataFile(), processPackageFiles(), rpmdsNew(), rpmfcGenerateDepends(), rpmfiNew(), rpmpsmStage(), rpmrepoInitPopt(), rpmTempFile(), sql_close(), sql_initDB(), and sql_open().

int rpmGetMacroEntries ( MacroContext  mc,
void *  _mire,
int  used,
const char ***  avp 
)

Return macro entries as string array.

Parameters:
mcmacro context (NULL uses global context)
_mirepattern to match (NULL disables)
usedmacro usage (<0 all, =0 unused, >=1 used count)
Return values:
*avpmacro definitions
Returns:
no. of entries

Definition at line 318 of file macro.c.

References dupMacroEntry(), mireRegexec(), rpmGlobalMacroContext, xcalloc(), and xrealloc().

Referenced by packageSources(), and rpmtsFini().

char* rpmGetPath ( const char *  path,
  ... 
)
int rpmGlob ( const char *  patterns,
int *  argcPtr,
const char ***  argvPtr 
)

Return URL path(s) from a (URL prefixed) pattern glob.

Parameters:
patternsglob pattern
Return values:
*argcPtrno. of paths
*argvPtrarray of paths (malloc'd contiguous blob)
Returns:
0 on success

Definition at line 2464 of file macro.c.

References _free(), glob_t::gl_pathc, glob_t::gl_pathv, Glob(), Glob_error(), Glob_pattern_p(), GLOB_TILDE, 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(), rpmcliInit(), rpmcliInstallElementPath(), rpmgiGlobArgv(), rpmInitMacros(), rpmioInit(), and rpmReadPackageManifest().

void rpmInitMacros ( MacroContext  mc,
const char *  macrofiles 
)

Initialize macro context from set of macrofile(s).

Parameters:
mcmacro context
macrofilescolon separated list of macro files (NULL does nothing)

Definition at line 2826 of file macro.c.

References _free(), _max_load_depth, _suffix, RMIL_CMDLINE, rpmCLIMacroContext, rpmGlob(), rpmGlobalMacroContext, rpmLoadMacroFile(), rpmLoadMacros(), rpmlog(), RPMLOG_WARNING, rpmSecuritySaneFile(), xmalloc(), and xstrdup().

Referenced by rpmReadRC().

int rpmLoadMacroFile ( MacroContext  mc,
const char *  fn,
int  nesting 
)

Load macro context from a macro file.

Parameters:
mc(unused)
fnmacro file name
nestingmax load recursion depth, 0 disables.

Definition at line 2755 of file macro.c.

References _, _free(), _macro_BUFSIZ, _MAX_MACRO_DEPTH, alloca(), Fclose(), Ferror(), Fopen(), matchchar(), max_macro_depth, rdcl(), RMIL_MACROFILES, rpmDefineMacro(), rpmLoadMacroFile(), rpmlog(), RPMLOG_WARNING, rpmMCExpand(), and SKIPBLANK.

Referenced by expandMacro(), rpmInitMacros(), and rpmLoadMacroFile().

void rpmLoadMacros ( MacroContext  mc,
int  level 
)

Load macros from specific context into global context.

Parameters:
mcmacro context (NULL does nothing).
levelmacro recursion level (0 is entry API)

Definition at line 2715 of file macro.c.

References addMacro(), and rpmGlobalMacroContext.

Referenced by rpmInitMacros().

char* rpmMCExpand ( MacroContext  mc,
const char *  arg,
  ... 
)

Return (malloc'ed) concatenated macro expansion(s) in a context.

Parameters:
mcmacro context
argmacro(s) to expand (NULL terminates list)
Returns:
macro expansion (malloc'ed)

Definition at line 3088 of file macro.c.

References _macro_BUFSIZ, expandMacros(), stpcpy(), xmalloc(), xrealloc(), and xstrdup().

Referenced by rpmLoadMacroFile().

int rpmSecuritySaneFile ( const char *  filename)

Check whether configuration file is moderately secure to load.

Parameters:
filenamefilename to check
Returns:
1 on success, 0 on failure

Definition at line 2441 of file macro.c.

Referenced by rpmcliInit(), rpmInitMacros(), and rpmioInit().

int rpmUndefineMacro ( MacroContext  mc,
const char *  macro 
)

Undefine macro in context.

Parameters:
mcmacro context (NULL uses global context).
macromacro name
Returns:
Todo:
Document.

Definition at line 2707 of file macro.c.

References doUndefine(), and rpmGlobalMacroContext.

Referenced by rpmcliAllArgCallback(), and rpmioAllArgCallback().

static void sortMacroTable ( MacroContext  mc) [static]

Sort entries in macro table.

Parameters:
mcmacro context

Definition at line 234 of file macro.c.

References compareMacroName().

Referenced by addMacro(), delMacro(), and freeArgs().

static int XpoptDupArgv ( int  argc,
char **  argv,
int *  argcPtr,
char ***  argvPtr 
) [static]

< missing argument

< missing argument

< memory allocation failed

Definition at line 1475 of file macro.c.

References POPT_ERROR_MALLOC, POPT_ERROR_NOARG, and xmalloc().

Referenced by XpoptParseArgvString().

static int XpoptParseArgvString ( const char *  s,
int *  argcPtr,
char ***  argvPtr 
) [static]

< memory allocation failed

< error in paramter quoting

< error in paramter quoting

Definition at line 1515 of file macro.c.

References alloca(), POPT_ARGV_ARRAY_GROW_DELTA, POPT_ERROR_BADQUOTE, POPT_ERROR_MALLOC, xmalloc(), and XpoptDupArgv().

Referenced by rpmGlob().


Variable Documentation

int _debug = 0 [static]

Definition at line 2462 of file macro.c.

size_t _macro_BUFSIZ = 16 * 1024 [static]
int _max_load_depth = 2

Definition at line 165 of file macro.c.

Referenced by expandMacro(), and rpmInitMacros().

int max_macro_depth = 16

Definition at line 153 of file macro.c.

Referenced by expandMacro(), and rpmLoadMacroFile().

Definition at line 161 of file macro.c.

Referenced by expandMacro(), and expandMacros().

Definition at line 157 of file macro.c.

Referenced by expandMacro(), and expandMacros().

struct MacroContext_s rpmCLIMacroContext_s [static]

Definition at line 124 of file macro.c.

struct MacroContext_s rpmGlobalMacroContext_s [static]

Definition at line 119 of file macro.c.