* util.c (name_quote): Don't quote ':', '~' and '@'. Quote '#'

and '~' only if it's the first character.
This commit is contained in:
Pavel Roskin 2003-01-28 22:52:04 +00:00
parent 5cecc135e1
commit 2edd447426
2 changed files with 46 additions and 38 deletions

View File

@ -1,5 +1,8 @@
2003-01-28 Pavel Roskin <proski@gnu.org>
* 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.

View File

@ -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;
}