Add "shellescape" built-in function.

This commit is contained in:
Dianne Skoll
2021-09-08 09:33:47 -04:00
parent 8e3ddb96b3
commit 5ceffddd5b
7 changed files with 78 additions and 17 deletions

View File

@@ -9,7 +9,11 @@
/* */
/***************************************************************/
static char const DontEscapeMe[] =
"1234567890_-=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.,/";
#include "config.h"
#include "err.h"
#include <string.h>
#include <stdio.h>
@@ -146,3 +150,15 @@ int _private_unminus_overflow(int a, int b)
if (a < 0 && b < 0) return 1;
return 0;
}
int
ShellEscape(char const *in, DynamicBuffer *out)
{
while(*in) {
if (!strchr(DontEscapeMe, *in)) {
if (DBufPutc(out, '\\') != OK) return E_NO_MEM;
}
if (DBufPutc(out, *in++) != OK) return E_NO_MEM;
}
return OK;
}