Skip to content

Commit

Permalink
cd/drive expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyg committed Mar 30, 2024
1 parent 0052a4e commit 09e0eb3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions mcsrc/lib/strescape.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ char *strutils_escape (const char *src, gsize src_len, const char *escaped_chars
char *strutils_unescape (const char *src, gsize src_len, const char *unescaped_chars,
gboolean unescape_non_printable);
char *strutils_shell_unescape (const char *text);
char *strutils_shell_unescape_special (const char *text); //WIN32
char *strutils_shell_escape (const char *text);

char *strutils_glob_escape (const char *text);
Expand Down
7 changes: 7 additions & 0 deletions mcsrc/lib/strutil/strescape.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ strutils_shell_unescape (const char *text)
return strutils_unescape (text, -1, ESCAPE_SHELL_CHARS, TRUE);
}


char *
strutils_shell_unescape_special (const char *text)
{
return strutils_unescape (text, -1, ESCAPE_SHELL_CHARS, FALSE);
}

/* --------------------------------------------------------------------------------------------- */

char *
Expand Down
10 changes: 7 additions & 3 deletions mcsrc/src/filemanager/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ examine_cd (const char *_path)
char *p;

/* Tilde expansion */
#if defined(WIN32)
path = strutils_shell_unescape_special (_path); //only escape specials
#else
path = strutils_shell_unescape (_path);
#endif
path_tilde = tilde_expand (path);
g_free (path);

Expand Down Expand Up @@ -182,13 +186,13 @@ handle_cdpath (const char *path)

cdpath = g_strdup (getenv ("CDPATH"));
p = cdpath;
c = (p == NULL) ? '\0' : ':';
c = (p == NULL) ? '\0' : PATH_ENV_SEP;

while (!result && c == ':')
while (!result && c == PATH_ENV_SEP)
{
char *s;

s = strchr (p, ':');
s = strchr (p, PATH_ENV_SEP);
if (s == NULL)
s = strchr (p, '\0');
c = *s;
Expand Down
9 changes: 5 additions & 4 deletions mcwin32/src/win32_utl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,14 +1750,15 @@ tilde_expand(const char *directory)
++directory;
}

if (PATH_SEP == *directory) { /* / ==> x:/ */
if (IS_PATH_SEP(*directory)) { /* '/xxx' ==> 'x:/xxx' */
const char slash = *directory;

if (PATH_SEP != directory[1] || /* preserve URL's (//<server) */
0 == directory[2] || PATH_SEP == directory[2]) {
if (slash != directory[1] || /* preserve URL's (//<server) */
0 == directory[2] || slash == directory[2]) { /* and neither "//" or "///" */
const char *cwd = vfs_get_current_dir ();
char path[WIN32_PATH_MAX];

if ('/' == cwd[0] && 0 == cwd[1]) { /* vfs, possible ftp/sftp */
if (PATH_SEP == cwd[0] && 0 == cwd[1]) { /* vfs, possible ftp/sftp */
if (w32_getcwd (path, sizeof(path))) {
cwd = path; /* apply underlying cwd */
}
Expand Down

0 comments on commit 09e0eb3

Please sign in to comment.