summaryrefslogtreecommitdiff
path: root/rpmio/macro.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-07-29 12:36:03 +0000
committerjbj <devnull@localhost>1999-07-29 12:36:03 +0000
commitf9ed8f7bdc2467873142260705782a2910280137 (patch)
treebe519de595fbc1dd9b2be00f6ecf16f9aff76624 /rpmio/macro.c
parent587dab926c4314c71390bd6f6c5844751b8dfd1c (diff)
downloadrpm-f9ed8f7bdc2467873142260705782a2910280137.tar.gz
rpm-f9ed8f7bdc2467873142260705782a2910280137.tar.bz2
rpm-f9ed8f7bdc2467873142260705782a2910280137.zip
macro fixes (Benedict Lofstedt, #4220):
expand %# just like %{#} (and with same value as shell analogues). macro defaults for *, 0, and # if no args specified. getopt on non-linux requires optind to be saved/restored. CVS patchset: 3209 CVS date: 1999/07/29 12:36:03
Diffstat (limited to 'rpmio/macro.c')
-rw-r--r--rpmio/macro.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 64749f044..2dadb8c22 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -579,7 +579,7 @@ freeArgs(MacroBuf *mb)
}
static const char *
-grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se)
+grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se, char lastc)
{
char buf[BUFSIZ], *b, *be;
char aname[16];
@@ -602,20 +602,20 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se)
addMacro(mb->mc, "0", NULL, b, mb->depth);
- /* Copy args into buf until newline */
+ /* Copy args into buf until lastc */
*be++ = ' ';
b = be; /* Save beginning of args */
while ((c = *se) != 0) {
char *a;
se++;
- if (c == '\n')
+ if (c == lastc)
break;
if (isblank(c))
continue;
if (argc > 1)
*be++ = ' ';
a = be;
- while (!(isblank(c) || c == '\n')) {
+ while (!(isblank(c) || c == lastc)) {
*be++ = c;
if ((c = *se) == '\0')
break;
@@ -625,7 +625,6 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se)
argc++;
}
-#if 0
/*
* The macro %* analoguous to the shell's $* means "Pass all non-macro
* parameters." Consequently, there needs to be a macro that means "Pass all
@@ -636,7 +635,6 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se)
*/
/* Add unexpanded args as macro */
addMacro(mb->mc, "**", NULL, b, mb->depth);
-#endif
#ifdef NOTYET
/* XXX if macros can be passed as args ... */
@@ -717,7 +715,7 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se)
}
/* Add arg count as macro */
- sprintf(aname, "%d", (argc - optind + 1));
+ sprintf(aname, "%d", (argc - optind));
addMacro(mb->mc, "#", NULL, aname, mb->depth);
/* Add unexpanded args as macro */
@@ -834,7 +832,7 @@ expandMacro(MacroBuf *mb)
int c;
int rc = 0;
int negate;
- int grab;
+ char grab;
int chkexist;
if (++mb->depth > max_macro_depth) {
@@ -866,7 +864,7 @@ expandMacro(MacroBuf *mb)
if (mb->depth > 1) /* XXX full expansion for outermost level */
t = mb->t; /* save expansion pointer for printExpand */
negate = 0;
- grab = 0;
+ grab = '\0';
chkexist = 0;
switch ((c = *s)) {
default: /* %name substitution */
@@ -885,12 +883,22 @@ expandMacro(MacroBuf *mb)
se++;
while((c = *se) && (isalnum(c) || c == '_'))
se++;
- if (*se == '*')
+ /* Recognize non-alnum macros too */
+ switch (*se) {
+ case '*':
+ se++;
+ if (*se == '*') se++;
+ break;
+ case '#':
se++;
+ break;
+ default:
+ break;
+ }
fe = se;
/* For "%name " macros ... */
if ((c = *fe) && isblank(c))
- grab = 1;
+ grab = '\n';
break;
case '(': /* %(...) shell escape */
if ((se = matchchar(s, c, ')')) == NULL) {
@@ -926,11 +934,18 @@ expandMacro(MacroBuf *mb)
break;
}
}
- for (fe = f; (c = *fe) && !strchr(":}", c);)
+ for (fe = f; (c = *fe) && !strchr(" :}", c);)
fe++;
- if (c == ':') {
+ switch (c) {
+ case ':':
g = fe + 1;
ge = se - 1;
+ break;
+ case ' ':
+ grab = se[-1];
+ break;
+ default:
+ break;
}
break;
}
@@ -1074,10 +1089,13 @@ expandMacro(MacroBuf *mb)
/* Setup args for "%name " macros with opts */
if (me && me->opts != NULL) {
- if (grab)
- se = grabArgs(mb, me, fe);
- else {
- addMacro(mb->mc, "*", NULL, "", mb->depth);
+ if (grab) {
+ se = grabArgs(mb, me, fe, grab);
+ } else {
+ addMacro(mb->mc, "**", NULL, "", mb->depth);
+ addMacro(mb->mc, "*", NULL, "", mb->depth);
+ addMacro(mb->mc, "#", NULL, "0", mb->depth);
+ addMacro(mb->mc, "0", NULL, me->name, mb->depth);
}
}