Reindent expandMacro() to common rpm style

This huge and scary looking diff is strictly whitespace-only change.
This commit is contained in:
Panu Matilainen 2017-01-19 11:26:52 +02:00
parent 34c4609df3
commit e3e99e929a
1 changed files with 185 additions and 187 deletions

View File

@ -972,15 +972,15 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
/* Copy text until next macro */ /* Copy text until next macro */
switch(c) { switch(c) {
case '%': case '%':
if (*s) { /* Ensure not end-of-string. */ if (*s) { /* Ensure not end-of-string. */
if (*s != '%') if (*s != '%')
break; break;
s++; /* skip first % in %% */ s++; /* skip first % in %% */
} }
default: default:
mbAppend(mb, c); mbAppend(mb, c);
continue; continue;
break; break;
} }
/* Expand next macro */ /* Expand next macro */
@ -993,188 +993,185 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
chkexist = 0; chkexist = 0;
switch ((c = *s)) { switch ((c = *s)) {
default: /* %name substitution */ default: /* %name substitution */
while (*s != '\0' && strchr("!?", *s) != NULL) { while (*s != '\0' && strchr("!?", *s) != NULL) {
switch(*s++) { switch(*s++) {
case '!': case '!':
negate = ((negate + 1) % 2); negate = ((negate + 1) % 2);
break;
case '?':
chkexist++;
break;
}
}
f = se = s;
if (*se == '-')
se++;
while((c = *se) && (risalnum(c) || c == '_'))
se++;
/* Recognize non-alnum macros too */
switch (*se) {
case '*':
se++;
if (*se == '*') se++;
break; break;
case '#': case '?':
se++; chkexist++;
break;
default:
break; break;
} }
fe = se; }
/* For "%name " macros ... */ f = se = s;
if ((c = *fe) && isblank(c)) if (*se == '-')
if ((lastc = strchr(fe,'\n')) == NULL) se++;
lastc = strchr(fe, '\0'); while((c = *se) && (risalnum(c) || c == '_'))
se++;
/* Recognize non-alnum macros too */
switch (*se) {
case '*':
se++;
if (*se == '*') se++;
break; break;
case '#':
se++;
break;
default:
break;
}
fe = se;
/* For "%name " macros ... */
if ((c = *fe) && isblank(c))
if ((lastc = strchr(fe,'\n')) == NULL)
lastc = strchr(fe, '\0');
break;
case '(': /* %(...) shell escape */ case '(': /* %(...) shell escape */
if ((se = matchchar(s, c, ')')) == NULL) { if ((se = matchchar(s, c, ')')) == NULL) {
rpmlog(RPMLOG_ERR, rpmlog(RPMLOG_ERR, _("Unterminated %c: %s\n"), (char)c, s);
_("Unterminated %c: %s\n"), (char)c, s); rc = 1;
rc = 1;
continue;
}
if (mb->macro_trace)
printMacro(mb, s, se+1);
s++; /* skip ( */
rc = doShellEscape(mb, s, (se - s));
se++; /* skip ) */
s = se;
continue; continue;
break; }
if (mb->macro_trace)
printMacro(mb, s, se+1);
s++; /* skip ( */
rc = doShellEscape(mb, s, (se - s));
se++; /* skip ) */
s = se;
continue;
break;
case '{': /* %{...}/%{...:...} substitution */ case '{': /* %{...}/%{...:...} substitution */
if ((se = matchchar(s, c, '}')) == NULL) { if ((se = matchchar(s, c, '}')) == NULL) {
rpmlog(RPMLOG_ERR, rpmlog(RPMLOG_ERR, _("Unterminated %c: %s\n"), (char)c, s);
_("Unterminated %c: %s\n"), (char)c, s); rc = 1;
rc = 1; continue;
continue; }
} f = s+1;/* skip { */
f = s+1;/* skip { */ se++; /* skip } */
se++; /* skip } */ while (strchr("!?", *f) != NULL) {
while (strchr("!?", *f) != NULL) { switch(*f++) {
switch(*f++) { case '!':
case '!': negate = ((negate + 1) % 2);
negate = ((negate + 1) % 2); break;
break; case '?':
case '?': chkexist++;
chkexist++; break;
break;
}
}
for (fe = f; (c = *fe) && !strchr(" :}", c);)
fe++;
switch (c) {
case ':':
g = fe + 1;
ge = se - 1;
break;
case ' ':
lastc = se-1;
break;
default:
break;
} }
}
for (fe = f; (c = *fe) && !strchr(" :}", c);)
fe++;
switch (c) {
case ':':
g = fe + 1;
ge = se - 1;
break; break;
case ' ':
lastc = se-1;
break;
default:
break;
}
break;
} }
/* XXX Everything below expects fe > f */ /* XXX Everything below expects fe > f */
fn = (fe - f); fn = (fe - f);
gn = (ge - g); gn = (ge - g);
if ((fe - f) <= 0) { if ((fe - f) <= 0) {
/* XXX Process % in unknown context */ /* XXX Process % in unknown context */
c = '%'; /* XXX only need to save % */ c = '%'; /* XXX only need to save % */
mbAppend(mb, c); mbAppend(mb, c);
#if 0 #if 0
rpmlog(RPMLOG_ERR, rpmlog(RPMLOG_ERR,
_("A %% is followed by an unparseable macro\n")); _("A %% is followed by an unparseable macro\n"));
#endif #endif
s = se; s = se;
continue; continue;
} }
if (mb->macro_trace) if (mb->macro_trace)
printMacro(mb, s, se); printMacro(mb, s, se);
/* Expand builtin macros */ /* Expand builtin macros */
if (STREQ("load", f, fn)) { if (STREQ("load", f, fn)) {
char *arg = NULL; char *arg = NULL;
if (g && gn > 0 && expandThis(mb, g, gn, &arg) == 0) { if (g && gn > 0 && expandThis(mb, g, gn, &arg) == 0) {
/* Print failure iff %{load:...} or %{!?load:...} */ /* Print failure iff %{load:...} or %{!?load:...} */
if (loadMacroFile(mb->mc, arg) && chkexist == negate) { if (loadMacroFile(mb->mc, arg) && chkexist == negate) {
rpmlog(RPMLOG_ERR, rpmlog(RPMLOG_ERR, _("failed to load macro file %s"), arg);
_("failed to load macro file %s"), arg);
}
} }
free(arg); }
s = se; free(arg);
continue; s = se;
continue;
} }
if (STREQ("global", f, fn)) { if (STREQ("global", f, fn)) {
s = doDefine(mb, se, slen - (se - s), RMIL_GLOBAL, 1); s = doDefine(mb, se, slen - (se - s), RMIL_GLOBAL, 1);
continue; continue;
} }
if (STREQ("define", f, fn)) { if (STREQ("define", f, fn)) {
s = doDefine(mb, se, slen - (se - s), mb->depth, 0); s = doDefine(mb, se, slen - (se - s), mb->depth, 0);
continue; continue;
} }
if (STREQ("undefine", f, fn)) { if (STREQ("undefine", f, fn)) {
s = doUndefine(mb->mc, se, slen - (se - s)); s = doUndefine(mb->mc, se, slen - (se - s));
continue; continue;
} }
if (STREQ("echo", f, fn) || if (STREQ("echo", f, fn) ||
STREQ("warn", f, fn) || STREQ("warn", f, fn) ||
STREQ("error", f, fn)) { STREQ("error", f, fn)) {
int waserror = 0; int waserror = 0;
if (STREQ("error", f, fn)) if (STREQ("error", f, fn))
waserror = 1; waserror = 1;
if (g != NULL && g < ge) if (g != NULL && g < ge)
doOutput(mb, waserror, g, gn); doOutput(mb, waserror, g, gn);
else else
doOutput(mb, waserror, f, fn); doOutput(mb, waserror, f, fn);
s = se; s = se;
continue; continue;
} }
if (STREQ("trace", f, fn)) { if (STREQ("trace", f, fn)) {
/* XXX TODO restore expand_trace/macro_trace to 0 on return */ /* XXX TODO restore expand_trace/macro_trace to 0 on return */
mb->expand_trace = mb->macro_trace = (negate ? 0 : mb->depth); mb->expand_trace = mb->macro_trace = (negate ? 0 : mb->depth);
if (mb->depth == 1) { if (mb->depth == 1) {
print_macro_trace = mb->macro_trace; print_macro_trace = mb->macro_trace;
print_expand_trace = mb->expand_trace; print_expand_trace = mb->expand_trace;
} }
s = se; s = se;
continue; continue;
} }
if (STREQ("dump", f, fn)) { if (STREQ("dump", f, fn)) {
rpmDumpMacroTable(mb->mc, NULL); rpmDumpMacroTable(mb->mc, NULL);
while (iseol(*se)) while (iseol(*se))
se++; se++;
s = se; s = se;
continue; continue;
} }
#ifdef WITH_LUA #ifdef WITH_LUA
if (STREQ("lua", f, fn)) { if (STREQ("lua", f, fn)) {
rpmlua lua = NULL; /* Global state. */ rpmlua lua = NULL; /* Global state. */
char *scriptbuf = xmalloc(gn + 1); char *scriptbuf = xmalloc(gn + 1);
char *printbuf; char *printbuf;
if (g != NULL && gn > 0) if (g != NULL && gn > 0)
memcpy(scriptbuf, g, gn); memcpy(scriptbuf, g, gn);
scriptbuf[gn] = '\0'; scriptbuf[gn] = '\0';
rpmluaPushPrintBuffer(lua); rpmluaPushPrintBuffer(lua);
if (rpmluaRunScript(lua, scriptbuf, NULL) == -1) if (rpmluaRunScript(lua, scriptbuf, NULL) == -1)
rc = 1; rc = 1;
printbuf = rpmluaPopPrintBuffer(lua); printbuf = rpmluaPopPrintBuffer(lua);
if (printbuf) { if (printbuf) {
mbAppendStr(mb, printbuf); mbAppendStr(mb, printbuf);
free(printbuf); free(printbuf);
} }
free(scriptbuf); free(scriptbuf);
s = se; s = se;
continue; continue;
} }
#endif #endif
@ -1191,11 +1188,12 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
STREQ("getconfdir", f, fn) || STREQ("getconfdir", f, fn) ||
STREQ("S", f, fn) || STREQ("S", f, fn) ||
STREQ("P", f, fn) || STREQ("P", f, fn) ||
STREQ("F", f, fn)) { STREQ("F", f, fn))
/* FIX: verbose may be set */ {
doFoo(mb, negate, f, fn, g, gn); /* FIX: verbose may be set */
s = se; doFoo(mb, negate, f, fn, g, gn);
continue; s = se;
continue;
} }
/* Expand defined macros */ /* Expand defined macros */
@ -1208,66 +1206,66 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
/* XXX Special processing for flags */ /* XXX Special processing for flags */
if (*f == '-') { if (*f == '-') {
if ((me == NULL && !negate) || /* Without -f, skip %{-f...} */ if ((me == NULL && !negate) || /* Without -f, skip %{-f...} */
(me != NULL && negate)) { /* With -f, skip %{!-f...} */ (me != NULL && negate)) { /* With -f, skip %{!-f...} */
s = se;
continue;
}
if (g && g < ge) { /* Expand X in %{-f:X} */
rc = expandMacro(mb, g, gn);
} else
if (me && me->body && *me->body) {/* Expand %{-f}/%{-f*} */
rc = expandMacro(mb, me->body, 0);
}
s = se; s = se;
continue; continue;
}
if (g && g < ge) { /* Expand X in %{-f:X} */
rc = expandMacro(mb, g, gn);
} else
if (me && me->body && *me->body) {/* Expand %{-f}/%{-f*} */
rc = expandMacro(mb, me->body, 0);
}
s = se;
continue;
} }
/* XXX Special processing for macro existence */ /* XXX Special processing for macro existence */
if (chkexist) { if (chkexist) {
if ((me == NULL && !negate) || /* Without -f, skip %{?f...} */ if ((me == NULL && !negate) || /* Without -f, skip %{?f...} */
(me != NULL && negate)) { /* With -f, skip %{!?f...} */ (me != NULL && negate)) { /* With -f, skip %{!?f...} */
s = se;
continue;
}
if (g && g < ge) { /* Expand X in %{?f:X} */
rc = expandMacro(mb, g, gn);
} else
if (me && me->body && *me->body) { /* Expand %{?f}/%{?f*} */
rc = expandMacro(mb, me->body, 0);
}
s = se; s = se;
continue; continue;
}
if (g && g < ge) { /* Expand X in %{?f:X} */
rc = expandMacro(mb, g, gn);
} else
if (me && me->body && *me->body) { /* Expand %{?f}/%{?f*} */
rc = expandMacro(mb, me->body, 0);
}
s = se;
continue;
} }
if (me == NULL) { /* leave unknown %... as is */ if (me == NULL) { /* leave unknown %... as is */
/* XXX hack to permit non-overloaded %foo to be passed */ /* XXX hack to permit non-overloaded %foo to be passed */
c = '%'; /* XXX only need to save % */ c = '%'; /* XXX only need to save % */
mbAppend(mb, c); mbAppend(mb, c);
continue; continue;
} }
/* Setup args for "%name " macros with opts */ /* Setup args for "%name " macros with opts */
if (me && me->opts != NULL) { if (me && me->opts != NULL) {
if (lastc != NULL) { if (lastc != NULL) {
se = grabArgs(mb, me, fe, lastc); se = grabArgs(mb, me, fe, lastc);
} else { } else {
pushMacro(mb->mc, "**", NULL, "", mb->depth, ME_AUTO); pushMacro(mb->mc, "**", NULL, "", mb->depth, ME_AUTO);
pushMacro(mb->mc, "*", NULL, "", mb->depth, ME_AUTO); pushMacro(mb->mc, "*", NULL, "", mb->depth, ME_AUTO);
pushMacro(mb->mc, "#", NULL, "0", mb->depth, ME_AUTO); pushMacro(mb->mc, "#", NULL, "0", mb->depth, ME_AUTO);
pushMacro(mb->mc, "0", NULL, me->name, mb->depth, ME_AUTO); pushMacro(mb->mc, "0", NULL, me->name, mb->depth, ME_AUTO);
} }
} }
/* Recursively expand body of macro */ /* Recursively expand body of macro */
if (me->body && *me->body) { if (me->body && *me->body) {
rc = expandMacro(mb, me->body, 0); rc = expandMacro(mb, me->body, 0);
} }
/* Free args for "%name " macros with opts */ /* Free args for "%name " macros with opts */
if (me->opts != NULL) if (me->opts != NULL)
freeArgs(mb, 1); freeArgs(mb, 1);
s = se; s = se;
} }