From 2edd447426db0569b76e565cb6c647d61222eeb2 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 28 Jan 2003 22:52:04 +0000 Subject: [PATCH] * util.c (name_quote): Don't quote ':', '~' and '@'. Quote '#' and '~' only if it's the first character. --- src/ChangeLog | 3 ++ src/util.c | 81 +++++++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ec4d5eff0..886c4b944 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2003-01-28 Pavel Roskin + * util.c (name_quote): Don't quote ':', '~' and '@'. Quote '#' + and '~' only if it's the first character. + * info.c (info_show_info): Cast nlink_t to int to avoid a warning if nlink_t is short. * screen.c (string_file_nlinks): Likewise. diff --git a/src/util.c b/src/util.c index e59d5bf42..6b7cb126d 100644 --- a/src/util.c +++ b/src/util.c @@ -143,53 +143,58 @@ trim (char *s, char *d, int len) return d; } +/* + * Quote the filename for the purpose of inserting it into the command + * line. If quote_percent is 1, replace "%" with "%%" - the percent is + * processed by the mc command line. + */ char * name_quote (const char *s, int quote_percent) { char *ret, *d; - - d = ret = g_malloc (strlen (s)*2 + 2 + 1); + + d = ret = g_malloc (strlen (s) * 2 + 2 + 1); if (*s == '-') { - *d++ = '.'; - *d++ = '/'; + *d++ = '.'; + *d++ = '/'; } for (; *s; s++, d++) { - switch (*s) - { - case '%': - if (quote_percent) - *d++ = '%'; - break; - case '\'': - case '\\': - case '\r': - case '\n': - case '\t': - case '"': - case ':': - case ';': - case ' ': - case '?': - case '|': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - case '`': - case '~': - case '!': - case '@': - case '#': - case '$': - case '^': - case '&': - case '*': - case '(': - case ')': + switch (*s) { + case '%': + if (quote_percent) + *d++ = '%'; + break; + case '\'': + case '\\': + case '\r': + case '\n': + case '\t': + case '"': + case ';': + case ' ': + case '?': + case '|': + case '[': + case ']': + case '{': + case '}': + case '<': + case '>': + case '`': + case '!': + case '$': + case '&': + case '*': + case '(': + case ')': + *d++ = '\\'; + break; + case '~': + case '#': + if (d == ret) *d++ = '\\'; + break; } *d = *s; }