mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-13 05:36:20 +00:00
path separators
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows-opengl (push) Waiting to run
Build coop / build-windows-directx (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows-opengl (push) Waiting to run
Build coop / build-windows-directx (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run
This commit is contained in:
parent
7604ef9297
commit
ba54cbd1d0
8 changed files with 29 additions and 23 deletions
|
|
@ -151,7 +151,7 @@ PackData* DynOS_Pack_Add(const SysPath& aPath) {
|
|||
const char* displayName = aPath.c_str();
|
||||
const char* ctoken = displayName;
|
||||
while (*ctoken != '\0') {
|
||||
if (*ctoken == '/' || *ctoken == '\\') {
|
||||
if (*ctoken == *PATH_SEPARATOR || *ctoken == *PATH_SEPARATOR_ALT) {
|
||||
if (*(ctoken + 1) != '\0') {
|
||||
displayName = (ctoken + 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ void smlua_init(void) {
|
|||
}
|
||||
|
||||
// skip loading scripts in subdirectories
|
||||
if (strchr(file->relativePath, '/') != NULL || strchr(file->relativePath, '\\') != NULL) {
|
||||
if (strchr(file->relativePath, *PATH_SEPARATOR) != NULL || strchr(file->relativePath, *PATH_SEPARATOR_ALT) != NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ static int smlua_custom_require(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (path_ends_with(moduleName, "/") || path_ends_with(moduleName, "\\")) {
|
||||
if (path_ends_with(moduleName, PATH_SEPARATOR) || path_ends_with(moduleName, PATH_SEPARATOR_ALT)) {
|
||||
LOG_LUA_LINE("cannot require a directory");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -849,7 +849,7 @@ void smlua_logline(void) {
|
|||
if (strlen(src) < SYS_MAX_PATH) {
|
||||
int slashCount = 0;
|
||||
for (const char* p = src + strlen(src); p > src; --p) {
|
||||
if (*p == '/' || *p == '\\') {
|
||||
if (*p == *PATH_SEPARATOR || *p == *PATH_SEPARATOR_ALT) {
|
||||
if (++slashCount == 2) {
|
||||
folderStart = p + 1;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -622,8 +622,8 @@ LuaTable get_mod_files(struct Mod* mod, OPTIONAL const char* subDirectory) {
|
|||
normalize_path(normalizedSubDir);
|
||||
|
||||
size_t subDirLen = strlen(normalizedSubDir);
|
||||
if (subDirLen > 0 && subDirLen + 1 < SYS_MAX_PATH && normalizedSubDir[subDirLen - 1] != '/') {
|
||||
strcat(normalizedSubDir, "/");
|
||||
if (subDirLen > 0 && subDirLen + 1 < SYS_MAX_PATH && normalizedSubDir[subDirLen - 1] != *PATH_SEPARATOR) {
|
||||
strcat(normalizedSubDir, PATH_SEPARATOR);
|
||||
subDirLen = strlen(normalizedSubDir);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ bool mod_file_create_directories(struct Mod* mod, struct ModFile* modFile) {
|
|||
char* p = path;
|
||||
u16 index = 0;
|
||||
while (*p != '\0') {
|
||||
if (*p == '/' || *p == '\\') {
|
||||
if (*p == *PATH_SEPARATOR || *p == *PATH_SEPARATOR_ALT) {
|
||||
if (snprintf(tmpPath, index + 1, "%s", path) < 0) { }
|
||||
if (!fs_sys_dir_exists(tmpPath)) {
|
||||
fs_sys_mkdir(tmpPath);
|
||||
|
|
@ -210,11 +210,9 @@ void normalize_path(char* path) {
|
|||
// replace slashes
|
||||
char* p = path;
|
||||
while (*p) {
|
||||
#if defined(_WIN32)
|
||||
if (*p == '/') { *p = '\\'; }
|
||||
#else
|
||||
if (*p == '\\') { *p = '/'; }
|
||||
#endif
|
||||
if (*p == *PATH_SEPARATOR_ALT) {
|
||||
*p = *PATH_SEPARATOR;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
|
@ -227,7 +225,7 @@ char* path_basename(char* path) {
|
|||
char* base = path;
|
||||
while (*path != '\0') {
|
||||
if (*(path + 1) != '\0') {
|
||||
if (*path == '\\' || *path == '/') {
|
||||
if (*path == *PATH_SEPARATOR || *path == *PATH_SEPARATOR_ALT) {
|
||||
base = path + 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -251,7 +249,7 @@ void path_get_folder(char* path, char* outpath) {
|
|||
int path_depth(const char* path) {
|
||||
int depth = 0;
|
||||
for (; *path; path++) {
|
||||
if (*path == '/' || *path == '\\') {
|
||||
if (*path == *PATH_SEPARATOR || *path == *PATH_SEPARATOR_ALT) {
|
||||
depth++;
|
||||
}
|
||||
}
|
||||
|
|
@ -262,7 +260,7 @@ void resolve_relative_path(const char* base, const char* path, char* output) {
|
|||
char combined[SYS_MAX_PATH] = "";
|
||||
|
||||
// If path is absolute, copy as is. Otherwise, combine base and relative path
|
||||
if (path[0] == '/' || path[0] == '\\') {
|
||||
if (path[0] == *PATH_SEPARATOR || path[0] == *PATH_SEPARATOR_ALT) {
|
||||
snprintf(combined, sizeof(combined), "%s", path);
|
||||
} else {
|
||||
snprintf(combined, sizeof(combined), "%s/%s", base, path);
|
||||
|
|
@ -272,7 +270,7 @@ void resolve_relative_path(const char* base, const char* path, char* output) {
|
|||
int tokenCount = 0;
|
||||
|
||||
// Tokenize path by separators
|
||||
char* token = strtok(combined, "/\\");
|
||||
char* token = strtok(combined, PATH_SEPARATOR PATH_SEPARATOR_ALT);
|
||||
while (token && tokenCount < 64) {
|
||||
if (strcmp(token, "..") == 0) {
|
||||
// Pop last token to go up a directory
|
||||
|
|
@ -283,7 +281,7 @@ void resolve_relative_path(const char* base, const char* path, char* output) {
|
|||
tokens[tokenCount++] = token;
|
||||
}
|
||||
|
||||
token = strtok(NULL, "/\\");
|
||||
token = strtok(NULL, PATH_SEPARATOR PATH_SEPARATOR_ALT);
|
||||
}
|
||||
|
||||
output[0] = '\0';
|
||||
|
|
@ -291,7 +289,7 @@ void resolve_relative_path(const char* base, const char* path, char* output) {
|
|||
// Build output path from tokens
|
||||
for (int i = 0; i < tokenCount; i++) {
|
||||
if (i > 0) {
|
||||
strncat(output, "/", SYS_MAX_PATH - strlen(output) - 1);
|
||||
strncat(output, PATH_SEPARATOR, SYS_MAX_PATH - strlen(output) - 1);
|
||||
}
|
||||
strncat(output, tokens[i], SYS_MAX_PATH - strlen(output) - 1);
|
||||
}
|
||||
|
|
@ -308,8 +306,8 @@ bool directory_sanity_check(struct dirent* dir, char* dirPath, char* outPath) {
|
|||
if (!fs_sys_filename_is_portable(dir->d_name)) { return false; }
|
||||
|
||||
// skip anything that contains \ or /
|
||||
if (strchr(dir->d_name, '/') != NULL) { return false; }
|
||||
if (strchr(dir->d_name, '\\') != NULL) { return false; }
|
||||
if (strchr(dir->d_name, *PATH_SEPARATOR) != NULL) { return false; }
|
||||
if (strchr(dir->d_name, *PATH_SEPARATOR_ALT) != NULL) { return false; }
|
||||
|
||||
// skip anything that starts with .
|
||||
if (dir->d_name[0] == '.') { return false; }
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ const char *sys_file_extension(const char *fpath) {
|
|||
}
|
||||
|
||||
const char *sys_file_name(const char *fpath) {
|
||||
const char *sep1 = strrchr(fpath, '/');
|
||||
const char *sep2 = strrchr(fpath, '\\');
|
||||
const char *sep1 = strrchr(fpath, *PATH_SEPARATOR);
|
||||
const char *sep2 = strrchr(fpath, *PATH_SEPARATOR_ALT);
|
||||
const char *sep = sep1 > sep2 ? sep1 : sep2;
|
||||
if (!sep) return fpath;
|
||||
return sep + 1;
|
||||
|
|
@ -325,7 +325,7 @@ const char *sys_user_path(void) {
|
|||
|
||||
// strip the trailing separator
|
||||
const unsigned int len = strlen(path);
|
||||
if (path[len-1] == '/' || path[len-1] == '\\') { path[len-1] = 0; }
|
||||
if (path[len-1] == *PATH_SEPARATOR || path[len-1] == *PATH_SEPARATOR_ALT) { path[len-1] = 0; }
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@
|
|||
|
||||
/* platform-specific functions and whatnot */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATH_SEPARATOR "\\"
|
||||
#define PATH_SEPARATOR_ALT "/"
|
||||
#else
|
||||
#define PATH_SEPARATOR "/"
|
||||
#define PATH_SEPARATOR_ALT "\\"
|
||||
#endif
|
||||
|
||||
#define SYS_MAX_PATH 4096
|
||||
|
||||
// crossplatform impls of misc stuff
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue