1

Path changes for windows

This commit is contained in:
Alex Yatskov 2021-01-10 16:28:16 -08:00
parent 7c4b1f8c8b
commit cdd6f9e1a9

View File

@ -31,6 +31,8 @@
#include "error.h" #include "error.h"
#include "build-post.h" #include "build-post.h"
#ifndef WIN32
/* /*
* Canonicalize `path_name' (UNIX version). * Canonicalize `path_name' (UNIX version).
* Convert a path name to an absolute path. * Convert a path name to an absolute path.
@ -74,6 +76,104 @@ eb_canonicalize_path_name(char *path_name)
return EB_SUCCESS; return EB_SUCCESS;
} }
#else /* WIN32 */
/*
* Canonicalize `path_name' (DOS version).
* Convert a path name to an absolute path with drive letter unless
* that is an UNC path.
*
* Original version by KSK Jan/30/1998.
* Current version by Motoyuki Kasahara.
*/
EB_Error_Code
eb_canonicalize_path_name(char *path_name)
{
char cwd[EB_MAX_PATH_LENGTH + 1];
char temporary_path_name[EB_MAX_PATH_LENGTH + 1];
char *slash;
char *last_backslash;
/*
* Replace `/' with `\\'.
*/
slash = path_name;
for (;;) {
slash = strchr(slash, '/');
if (slash == NULL)
break;
*slash++ = '\\';
}
if (*path_name == '\\' && *(path_name + 1) == '\\') {
/*
* `path_name' is UNC path. Nothing to be done.
*/
} else if (ASCII_ISALPHA(*path_name) && *(path_name + 1) == ':') {
/*
* `path_name' has a drive letter.
* Nothing to be done if it is an absolute path.
*/
if (*(path_name + 2) != '\\') {
/*
* `path_name' is a relative path.
* Covert the path name to an absolute path.
*/
if (getdcwd(ASCII_TOUPPER(*path_name) - 'A' + 1, cwd,
EB_MAX_PATH_LENGTH + 1) == NULL) {
return EB_ERR_FAIL_GETCWD;
}
if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name + 2))
return EB_ERR_TOO_LONG_FILE_NAME;
sprintf(temporary_path_name, "%s\\%s", cwd, path_name + 2);
strcpy(path_name, temporary_path_name);
}
} else if (*path_name == '\\') {
/*
* `path_name' has no drive letter and is an absolute path.
* Add a drive letter to the path name.
*/
if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL)
return EB_ERR_FAIL_GETCWD;
cwd[1] = '\0';
if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name))
return EB_ERR_TOO_LONG_FILE_NAME;
sprintf(temporary_path_name, "%s:%s", cwd, path_name);
strcpy(path_name, temporary_path_name);
} else {
/*
* `path_name' has no drive letter and is a relative path.
* Add a drive letter and convert it to an absolute path.
*/
if (getcwd(cwd, EB_MAX_PATH_LENGTH + 1) == NULL)
return EB_ERR_FAIL_GETCWD;
if (EB_MAX_PATH_LENGTH < strlen(cwd) + 1 + strlen(path_name))
return EB_ERR_TOO_LONG_FILE_NAME;
sprintf(temporary_path_name, "%s\\%s", cwd, path_name);
strcpy(path_name, temporary_path_name);
}
/*
* Now `path_name' is `X:\...' or `\\...'.
* Unless it is "X:\", eliminate `\' in the tail of the path name.
*/
last_backslash = strrchr(path_name, '\\');
if (ASCII_ISALPHA(*path_name)) {
if (last_backslash != path_name + 2 && *(last_backslash + 1) == '\0')
*last_backslash = '\0';
} else {
if (last_backslash != path_name + 1 && *(last_backslash + 1) == '\0')
*last_backslash = '\0';
}
return EB_SUCCESS;
}
#endif /* WIN32 */
/* /*
* Canonicalize file name. * Canonicalize file name.
@ -175,7 +275,14 @@ eb_fix_path_name_suffix(char *path_name, const char *suffix)
char *dot; char *dot;
char *semicolon; char *semicolon;
#ifndef WIN32
base_name = strrchr(path_name, '/'); base_name = strrchr(path_name, '/');
#else
if (is_ebnet_url(path_name))
base_name = strrchr(path_name, '/');
else
base_name = strrchr(path_name, '\\');
#endif
if (base_name == NULL) if (base_name == NULL)
base_name = path_name; base_name = path_name;
else else
@ -378,10 +485,19 @@ void
eb_compose_path_name(const char *path_name, const char *file_name, eb_compose_path_name(const char *path_name, const char *file_name,
char *composed_path_name) char *composed_path_name)
{ {
#ifndef WIN32
if (strcmp(path_name, "/") == 0) if (strcmp(path_name, "/") == 0)
sprintf(composed_path_name, "%s%s", path_name, file_name); sprintf(composed_path_name, "%s%s", path_name, file_name);
else else
sprintf(composed_path_name, "%s/%s", path_name, file_name); sprintf(composed_path_name, "%s/%s", path_name, file_name);
#else
if (is_ebnet_url(path_name))
sprintf(composed_path_name, "%s/%s", path_name, file_name);
else if (ASCII_ISALPHA(*path_name) && strcmp(path_name + 1, ":\\") == 0)
sprintf(composed_path_name, "%s%s", path_name, file_name);
else
sprintf(composed_path_name, "%s\\%s", path_name, file_name);
#endif
} }
@ -394,6 +510,7 @@ void
eb_compose_path_name2(const char *path_name, const char *sub_directory_name, eb_compose_path_name2(const char *path_name, const char *sub_directory_name,
const char *file_name, char *composed_path_name) const char *file_name, char *composed_path_name)
{ {
#ifndef WIN32
if (strcmp(path_name, "/") == 0) { if (strcmp(path_name, "/") == 0) {
sprintf(composed_path_name, "%s%s/%s", sprintf(composed_path_name, "%s%s/%s",
path_name, sub_directory_name, file_name); path_name, sub_directory_name, file_name);
@ -401,6 +518,19 @@ eb_compose_path_name2(const char *path_name, const char *sub_directory_name,
sprintf(composed_path_name, "%s/%s/%s", sprintf(composed_path_name, "%s/%s/%s",
path_name, sub_directory_name, file_name); path_name, sub_directory_name, file_name);
} }
#else
if (is_ebnet_url(path_name)) {
sprintf(composed_path_name, "%s/%s/%s",
path_name, sub_directory_name, file_name);
} else if (ASCII_ISALPHA(*path_name)
&& strcmp(path_name + 1, ":\\") == 0) {
sprintf(composed_path_name, "%s%s\\%s",
path_name, sub_directory_name, file_name);
} else {
sprintf(composed_path_name, "%s\\%s\\%s",
path_name, sub_directory_name, file_name);
}
#endif
} }
@ -414,6 +544,7 @@ eb_compose_path_name3(const char *path_name, const char *sub_directory_name,
const char *sub2_directory_name, const char *file_name, const char *sub2_directory_name, const char *file_name,
char *composed_path_name) char *composed_path_name)
{ {
#ifndef WIN32
if (strcmp(path_name, "/") == 0) { if (strcmp(path_name, "/") == 0) {
sprintf(composed_path_name, "%s%s/%s/%s", sprintf(composed_path_name, "%s%s/%s/%s",
path_name, sub_directory_name, sub2_directory_name, file_name); path_name, sub_directory_name, sub2_directory_name, file_name);
@ -421,6 +552,19 @@ eb_compose_path_name3(const char *path_name, const char *sub_directory_name,
sprintf(composed_path_name, "%s/%s/%s/%s", sprintf(composed_path_name, "%s/%s/%s/%s",
path_name, sub_directory_name, sub2_directory_name, file_name); path_name, sub_directory_name, sub2_directory_name, file_name);
} }
#else
if (is_ebnet_url(path_name)) {
sprintf(composed_path_name, "%s/%s/%s/%s",
path_name, sub_directory_name, sub2_directory_name, file_name);
} else if (ASCII_ISALPHA(*path_name)
&& strcmp(path_name + 1, ":\\") == 0) {
sprintf(composed_path_name, "%s%s\\%s\\%s",
path_name, sub_directory_name, sub2_directory_name, file_name);
} else {
sprintf(composed_path_name, "%s\\%s\\%s\\%s",
path_name, sub_directory_name, sub2_directory_name, file_name);
}
#endif
} }
@ -590,7 +734,14 @@ eb_path_name_zio_code(const char *path_name, Zio_Code default_zio_code,
const char *base_name; const char *base_name;
const char *dot; const char *dot;
#ifndef WIN32
base_name = strrchr(path_name, '/'); base_name = strrchr(path_name, '/');
#else
if (is_ebnet_url(path_name))
base_name = strrchr(path_name, '/');
else
base_name = strrchr(path_name, '\\');
#endif
if (base_name != NULL) if (base_name != NULL)
base_name++; base_name++;
else else