summaryrefslogtreecommitdiff
path: root/rpmio/macro.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2021-09-22 13:56:08 +0300
committerFlorian Festi <ffesti@redhat.com>2021-09-24 14:55:44 +0200
commitf64ad44ccd647403970f56b6e53034568de97634 (patch)
treeaf3d678c9194df51f46f030403cee74d5c0e563d /rpmio/macro.c
parentc495d73449cb707bf8b3a0f47a67bba115c00bcf (diff)
downloadrpm-f64ad44ccd647403970f56b6e53034568de97634.tar.gz
Add %{shescape:...} macro for single quoting with escapes for the shell
This is exactly the same as :shescape query format, hence the name.
Diffstat (limited to 'rpmio/macro.c')
-rw-r--r--rpmio/macro.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index eeeffa2b1..3263e0a91 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -1145,6 +1145,29 @@ static size_t doVerbose(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
return 0;
}
+static size_t doShescape(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
+{
+ char *result, *dst;
+ const char *src = argv[1];
+
+ result = dst = xmalloc(strlen(src) * 4 + 3);
+ *dst++ = '\'';
+ for (; *src != '\0'; src++) {
+ if (*src == '\'') {
+ *dst++ = '\'';
+ *dst++ = '\\';
+ *dst++ = '\'';
+ *dst++ = '\'';
+ } else {
+ *dst++ = *src;
+ }
+ }
+ *dst++ = '\'';
+ *dst = '\0';
+ mbAppendStr(mb, result);
+ return 0;
+}
+
static size_t
doFoo(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
{
@@ -1279,6 +1302,7 @@ static struct builtins_s {
{ "suffix", doFoo, 1, ME_FUNC },
{ "trace", doTrace, 0, ME_FUNC },
{ "u2p", doFoo, 1, ME_FUNC },
+ { "shescape", doShescape, 1, ME_FUNC },
{ "uncompress", doUncompress, 1, ME_FUNC },
{ "undefine", doUndefine, 1, ME_FUNC },
{ "url2path", doFoo, 1, ME_FUNC },