mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-18 17:29:28 +03:00
Rewrote the shell_escape function in order to make us of GString and g_string_append_c
As we decided to fully switch back to glb we needed to rewrite this function in order to use glib functions. This means in this case mostly that *ptr = c; ptr++; is replaced by something like this: g_string_append(str,c); with str a GString*. Signed-off-by: Patrick Winnertz <winnie@debian.org>
This commit is contained in:
parent
e54f318cef
commit
fe95221f05
24
src/util.c
24
src/util.c
@ -1550,16 +1550,18 @@ Q_ (const char *s)
|
||||
string for escaping
|
||||
|
||||
\returns
|
||||
return escaped string (later need to free)
|
||||
return escaped string (which needs to be freed later)
|
||||
*/
|
||||
char*
|
||||
shell_escape(const char* src)
|
||||
{
|
||||
GString *str;
|
||||
char *result = NULL;
|
||||
|
||||
if ((src==NULL)||(!(*src)))
|
||||
return strdup("");
|
||||
|
||||
char* buffer = calloc(1, strlen(src)*2+2);
|
||||
char* ptr = buffer;
|
||||
str = g_string_new("");
|
||||
|
||||
/* look for the first char to escape */
|
||||
while (1)
|
||||
@ -1568,19 +1570,19 @@ shell_escape(const char* src)
|
||||
/* copy over all chars not to escape */
|
||||
while ((c=(*src)) && shell_escape_nottoesc(c))
|
||||
{
|
||||
*ptr = c;
|
||||
ptr++;
|
||||
g_string_append_c(str,c);
|
||||
src++;
|
||||
}
|
||||
|
||||
/* at this point we either have an \0 or an char to escape */
|
||||
if (!c)
|
||||
return buffer;
|
||||
if (!c) {
|
||||
result = str->str;
|
||||
g_string_free(str,FALSE);
|
||||
return result;
|
||||
}
|
||||
|
||||
*ptr = '\\';
|
||||
ptr++;
|
||||
*ptr = c;
|
||||
ptr++;
|
||||
g_string_append_c(str,'\\');
|
||||
g_string_append_c(str,c);
|
||||
src++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user