diff --git a/rpmio/macro.c b/rpmio/macro.c index 68229afdfb..bb0bb6594c 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef HAVE_GETOPT_H #include #else @@ -864,6 +865,28 @@ doFoo(MacroBuf mb, int negate, const char * f, size_t fn, if ((b = strrchr(buf, '/')) != NULL) *b = '\0'; b = buf; + } else if (STREQ("shrink", f, fn)) { + /* + * shrink body by removing all leading and trailing whitespaces and + * reducing intermediate whitespaces to a single space character. + */ + int i, j, k, was_space = 0; + for (i = 0, j = 0, k = (int)strlen(buf); i < k; ) { + if (isspace((int)(buf[i]))) { + was_space = 1; + i++; + continue; + } + else if (was_space) { + was_space = 0; + if (j > 0) /* remove leading blanks at all */ + buf[j++] = ' '; + /* fallthrough */ + } + buf[j++] = buf[i++]; + } + buf[j] = '\0'; + b = buf; } else if (STREQ("suffix", f, fn)) { if ((b = strrchr(buf, '.')) != NULL) b++; @@ -1197,6 +1220,7 @@ expandMacro(MacroBuf mb, const char *src, size_t slen) /* XXX necessary but clunky */ if (STREQ("basename", f, fn) || STREQ("dirname", f, fn) || + STREQ("shrink", f, fn) || STREQ("suffix", f, fn) || STREQ("expand", f, fn) || STREQ("verbose", f, fn) ||