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
- add _mandir/_infodir macro expansions to docdirs (Tomasz Kloczko).
- add post install configurable dependency checking.
- fix: segfault on --rebuild (#4185).
- - fix: getopt on non-linux requires optind to be saved/restored
- rather than just set to 0 (Benedict Lofstedt, #4220).
+ - 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.
3.0.1 -> 3.0.2
- eliminate armv4 entries from rpmrc (Andrew E. Mileski).
}
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];
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;
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
*/
/* Add unexpanded args as macro */
addMacro(mb->mc, "**", NULL, b, mb->depth);
-#endif
#ifdef NOTYET
/* XXX if macros can be passed as args ... */
}
/* 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 */
int c;
int rc = 0;
int negate;
- int grab;
+ char grab;
int chkexist;
if (++mb->depth > max_macro_depth) {
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 */
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) {
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;
}
/* 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);
}
}
}
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];
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;
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
*/
/* Add unexpanded args as macro */
addMacro(mb->mc, "**", NULL, b, mb->depth);
-#endif
#ifdef NOTYET
/* XXX if macros can be passed as args ... */
}
/* 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 */
int c;
int rc = 0;
int negate;
- int grab;
+ char grab;
int chkexist;
if (++mb->depth > max_macro_depth) {
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 */
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) {
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;
}
/* 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);
}
}