Unify builtin macro calling now that we can
Now that both types use identical function signature, we can trivially unify the calling code for both, simplifying things somewhat, make the non-braced syntax for built-in macros work, and regain type safety.
This commit is contained in:
parent
1c964243b5
commit
cfaf1c6292
|
@ -46,13 +46,16 @@ enum macroFlags_e {
|
||||||
#define ME_ARGFUNC (ME_FUNC|ME_HAVEARG)
|
#define ME_ARGFUNC (ME_FUNC|ME_HAVEARG)
|
||||||
#define ME_ARGPARSE (ME_PARSE|ME_HAVEARG)
|
#define ME_ARGPARSE (ME_PARSE|ME_HAVEARG)
|
||||||
|
|
||||||
|
typedef struct MacroBuf_s *MacroBuf;
|
||||||
|
typedef size_t (*macroFunc)(MacroBuf mb, rpmMacroEntry me, ARGV_t argv);
|
||||||
|
|
||||||
/*! The structure used to store a macro. */
|
/*! The structure used to store a macro. */
|
||||||
struct rpmMacroEntry_s {
|
struct rpmMacroEntry_s {
|
||||||
struct rpmMacroEntry_s *prev;/*!< Macro entry stack. */
|
struct rpmMacroEntry_s *prev;/*!< Macro entry stack. */
|
||||||
const char *name; /*!< Macro name. */
|
const char *name; /*!< Macro name. */
|
||||||
const char *opts; /*!< Macro parameters (a la getopt) */
|
const char *opts; /*!< Macro parameters (a la getopt) */
|
||||||
const char *body; /*!< Macro body. */
|
const char *body; /*!< Macro body. */
|
||||||
void *func; /*!< Macro function (builtin macros) */
|
macroFunc func; /*!< Macro function (builtin macros) */
|
||||||
int flags; /*!< Macro state bits. */
|
int flags; /*!< Macro state bits. */
|
||||||
int level; /*!< Scoping level. */
|
int level; /*!< Scoping level. */
|
||||||
char arena[]; /*!< String arena. */
|
char arena[]; /*!< String arena. */
|
||||||
|
@ -101,7 +104,7 @@ static void initLocks(void)
|
||||||
/**
|
/**
|
||||||
* Macro expansion state.
|
* Macro expansion state.
|
||||||
*/
|
*/
|
||||||
typedef struct MacroBuf_s {
|
struct MacroBuf_s {
|
||||||
char * buf; /*!< Expansion buffer. */
|
char * buf; /*!< Expansion buffer. */
|
||||||
size_t tpos; /*!< Current position in expansion buffer */
|
size_t tpos; /*!< Current position in expansion buffer */
|
||||||
size_t nb; /*!< No. bytes remaining in expansion buffer. */
|
size_t nb; /*!< No. bytes remaining in expansion buffer. */
|
||||||
|
@ -114,7 +117,7 @@ typedef struct MacroBuf_s {
|
||||||
rpmMacroEntry me; /*!< Current macro (or NULL if anonymous) */
|
rpmMacroEntry me; /*!< Current macro (or NULL if anonymous) */
|
||||||
ARGV_t args; /*!< Current macro arguments (or NULL) */
|
ARGV_t args; /*!< Current macro arguments (or NULL) */
|
||||||
rpmMacroContext mc;
|
rpmMacroContext mc;
|
||||||
} * MacroBuf;
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expansion data for a scoping level
|
* Expansion data for a scoping level
|
||||||
|
@ -134,9 +137,6 @@ static int print_macro_trace = _PRINT_MACRO_TRACE;
|
||||||
#define _PRINT_EXPAND_TRACE 0
|
#define _PRINT_EXPAND_TRACE 0
|
||||||
static int print_expand_trace = _PRINT_EXPAND_TRACE;
|
static int print_expand_trace = _PRINT_EXPAND_TRACE;
|
||||||
|
|
||||||
typedef size_t (*macroFunc)(MacroBuf mb, rpmMacroEntry me, ARGV_t argv);
|
|
||||||
typedef size_t (*parseFunc)(MacroBuf mb, rpmMacroEntry me, ARGV_t argv);
|
|
||||||
|
|
||||||
/* forward ref */
|
/* forward ref */
|
||||||
static int expandMacro(MacroBuf mb, const char *src, size_t slen);
|
static int expandMacro(MacroBuf mb, const char *src, size_t slen);
|
||||||
static void pushMacro(rpmMacroContext mc,
|
static void pushMacro(rpmMacroContext mc,
|
||||||
|
@ -1255,7 +1255,7 @@ static size_t doTrace(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
|
||||||
|
|
||||||
static struct builtins_s {
|
static struct builtins_s {
|
||||||
const char * name;
|
const char * name;
|
||||||
void *func;
|
macroFunc func;
|
||||||
int flags;
|
int flags;
|
||||||
} const builtinmacros[] = {
|
} const builtinmacros[] = {
|
||||||
{ "P", doSP, ME_ARGFUNC },
|
{ "P", doSP, ME_ARGFUNC },
|
||||||
|
@ -1357,15 +1357,9 @@ doExpandThisMacro(MacroBuf mb, rpmMacroEntry me, ARGV_t args, size_t *parsed)
|
||||||
_("argument expected") : _("unexpected argument"));
|
_("argument expected") : _("unexpected argument"));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (me->flags & ME_PARSE) {
|
size_t np = me->func(mb, me, args);
|
||||||
parseFunc parse = me->func;
|
|
||||||
size_t np = parse(mb, me, args);
|
|
||||||
if (parsed)
|
if (parsed)
|
||||||
*parsed = np;
|
*parsed += np;
|
||||||
} else {
|
|
||||||
macroFunc func = me->func;
|
|
||||||
func(mb, me, args);
|
|
||||||
}
|
|
||||||
} else if (me->body && *me->body) {
|
} else if (me->body && *me->body) {
|
||||||
/* Setup args for "%name " macros with opts */
|
/* Setup args for "%name " macros with opts */
|
||||||
if (args != NULL)
|
if (args != NULL)
|
||||||
|
@ -1639,7 +1633,7 @@ static int doExpandMacros(rpmMacroContext mc, const char *src, int flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pushMacroAny(rpmMacroContext mc,
|
static void pushMacroAny(rpmMacroContext mc,
|
||||||
const char * n, const char * o, const char * b, void * f,
|
const char * n, const char * o, const char * b, macroFunc f,
|
||||||
int level, int flags)
|
int level, int flags)
|
||||||
{
|
{
|
||||||
/* new entry */
|
/* new entry */
|
||||||
|
|
|
@ -303,6 +303,8 @@ runroot rpm --eval "%{dirname}"
|
||||||
runroot rpm --eval "%{dirname:}"
|
runroot rpm --eval "%{dirname:}"
|
||||||
runroot rpm --eval "%{dirname:dir}"
|
runroot rpm --eval "%{dirname:dir}"
|
||||||
runroot rpm --eval "%{dirname dir}"
|
runroot rpm --eval "%{dirname dir}"
|
||||||
|
runroot rpm --eval "%dirname"
|
||||||
|
runroot rpm --eval "%dirname dir"
|
||||||
runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}'
|
runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}'
|
||||||
runroot rpm --eval "%{uncompress}"
|
runroot rpm --eval "%{uncompress}"
|
||||||
runroot rpm --eval "%{uncompress:}"
|
runroot rpm --eval "%{uncompress:}"
|
||||||
|
@ -317,11 +319,13 @@ runroot rpm --eval "%{dump:foo}"
|
||||||
[
|
[
|
||||||
dir
|
dir
|
||||||
dir
|
dir
|
||||||
|
dir
|
||||||
/hello/%%
|
/hello/%%
|
||||||
|
|
||||||
bar
|
bar
|
||||||
],
|
],
|
||||||
[error: %dirname: argument expected
|
[error: %dirname: argument expected
|
||||||
|
error: %dirname: argument expected
|
||||||
error: %uncompress: argument expected
|
error: %uncompress: argument expected
|
||||||
error: %getncpus: unexpected argument
|
error: %getncpus: unexpected argument
|
||||||
error: %getncpus: unexpected argument
|
error: %getncpus: unexpected argument
|
||||||
|
|
Loading…
Reference in New Issue