separate handling of tilde expansion:
MS Windows MINGW and VC++ versus all the others
This commit is contained in:
parent
26f07e9a62
commit
903b990a10
|
|
@ -14,45 +14,61 @@ Modified: 2002 R. Oktas, <roktas@omu.edu.tr>
|
|||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
#undef BOOLEAN
|
||||
#include <windows.h> /* win32 functions */
|
||||
#include "shlobj.h" /* SHGetFolderPath */
|
||||
#include <shlobj.h> /* SHGetFolderPath */
|
||||
#endif
|
||||
|
||||
/* XXX To prevent a name collision with `readline's `tilde_expand',
|
||||
the original name: `tilde_expand' has changed to `tildexpand'. This
|
||||
situation naturally brings to mind that `tilde_expand' could be used
|
||||
directly from `readline' (since it will already be included if we
|
||||
wish to activate the `readline' support). Following implementation of
|
||||
'tilde expanding' has some problems which constitutes another good
|
||||
reason why it should be replaced: eg. it returns NULL which should
|
||||
not behave this way, IMHO. Anyway... Don't care for the moment, may
|
||||
be in the future. -- ro */
|
||||
|
||||
|
||||
/* For Windows MINGW and Visual Studio: Expand the tilde '~' to the
|
||||
environmental variable HOME, if set by the user. If not set, it
|
||||
expands to the env variable USERPROFILE, that typically returns
|
||||
C:\Users\<user name>. If this is not available, a folder path led
|
||||
to by CSIDL_PERSONAL, i.e. C:\Users\<user name>\Documents.
|
||||
If not MINGW or Visual Studio, and if HAVE_PWD_H is defined,
|
||||
then '~' is expanded to HOME, else string is returned.
|
||||
*/
|
||||
char *
|
||||
tildexpand(char *string)
|
||||
{
|
||||
#ifdef HAVE_PWD_H
|
||||
char buf[BSIZE_SP];
|
||||
char *k, c;
|
||||
#endif
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
char buf2[BSIZE_SP];
|
||||
#endif
|
||||
char *result = NULL;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
string = skip_ws(string);
|
||||
|
||||
if (*string != '~')
|
||||
return copy(string);
|
||||
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
char buf2[BSIZE_SP];
|
||||
string += 1;
|
||||
result = getenv("HOME");
|
||||
if (!result)
|
||||
result = getenv("USERPROFILE");
|
||||
if (!result)
|
||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, buf2))) {
|
||||
if (*string)
|
||||
strcat(buf2, string);
|
||||
return copy(buf2);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
else {
|
||||
strcpy(buf2, result);
|
||||
if (*string)
|
||||
strcat(buf2, string);
|
||||
return copy(buf2);
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef HAVE_PWD_H
|
||||
char buf[BSIZE_SP];
|
||||
char *k, c;
|
||||
#endif
|
||||
|
||||
string += 1;
|
||||
|
||||
if (!*string || *string == '/') {
|
||||
/* First try the environment setting. May also make life easier
|
||||
for non-unix platforms, eg. MS-DOS. -- ro */
|
||||
/* First try the environment setting. */
|
||||
result = getenv("HOME");
|
||||
#ifdef HAVE_PWD_H
|
||||
/* Can't find a result from the environment, let's try
|
||||
|
|
@ -78,31 +94,20 @@ tildexpand(char *string)
|
|||
}
|
||||
if (result) {
|
||||
#ifdef HAVE_PWD_H
|
||||
strcpy(buf, result);
|
||||
if (*string)
|
||||
strcat(buf, string);
|
||||
return copy(buf);
|
||||
|
||||
strcpy(buf, result);
|
||||
if (*string)
|
||||
strcat(buf, string);
|
||||
return copy(buf);
|
||||
} else
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
#else
|
||||
/* Emulate the old behavior to prevent side effects. -- ro */
|
||||
return copy(string);
|
||||
/* Emulate the old behavior to prevent side effects. -- ro */
|
||||
return copy(string);
|
||||
}
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
else if(SUCCEEDED(SHGetFolderPath(NULL,
|
||||
CSIDL_PERSONAL,
|
||||
NULL,
|
||||
0,
|
||||
buf2)))
|
||||
{
|
||||
if (*string)
|
||||
strcat(buf2, string);
|
||||
return copy(buf2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue