From 8940a5ae38d4df5fe4656495ad76b79506d045bc Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 11 Sep 2024 11:22:31 +0300 Subject: [PATCH] Remove unused ddio_CleanPath() --- ddio/ddio.h | 6 -- ddio/lnxfile.cpp | 120 -------------------------------------- ddio/winfile.cpp | 111 ----------------------------------- editor/FilePageAddDlg.cpp | 1 - 4 files changed, 238 deletions(-) diff --git a/ddio/ddio.h b/ddio/ddio.h index 1c50e29d..e590d886 100644 --- a/ddio/ddio.h +++ b/ddio/ddio.h @@ -374,12 +374,6 @@ void ddio_MakePath(char *newPath, const char *absolutePathHeader, const char *su void ddio_DoForeachFile(const std::filesystem::path &search_path, const std::regex ®ex, const std::function &func); -// given a path, it cleans it up (if the path is c:\windows\..\dos it would make it c:\dos) -// srcPath is the original path -// dest is the finished cleaned path. -// dest should be at least _MAX_PATH in size -void ddio_CleanPath(char *dest, const char *srcPath); - // Generates a temporary filename based on the prefix, and basedir // Parameters: // basedir - directory to put the files diff --git a/ddio/lnxfile.cpp b/ddio/lnxfile.cpp index 0fb7aa59..71b2e514 100644 --- a/ddio/lnxfile.cpp +++ b/ddio/lnxfile.cpp @@ -266,126 +266,6 @@ int ddio_GetFileSysRoots(char **roots, int max_roots) { return 1; } -// given a path, it cleans it up (if the path is /usr/lib/../src it would make it /usr/src) -// srcPath is the original path -// dest is the finished cleaned path. -// dest should be at least _MAX_PATH in size -void ddio_CleanPath(char *dest, const char *srcPath) { - // NOTE: we may want to use getcwd() here if we don't want symbolic links - // but I think we do - //////////////////////////////////////////////////////////////////////// - - strcpy(dest, srcPath); - - // break the path into directories - char **directories; - int dirs; - int path_length; - - // make sure the path ends with a / for sanity - path_length = strlen(dest); - - if (dest[path_length - 1] != '/') { - dest[path_length] = '/'; - dest[path_length + 1] = '\0'; - path_length++; - } - - // now divide the full path into separate NULL terminated strings,counting the number - // of directories in the process - dirs = 0; - char *strptr; - if (dest[0] == '/') - strptr = dest + 1; // skip first / of root dir - else - strptr = dest; - - while (*strptr != '\0') { - if (*strptr == '/') { - *strptr = '\0'; - dirs++; - } - strptr++; - } - - // check to make sure we have a directory, if we don't then return the original path given - if (dirs == 0) { - strcpy(dest, srcPath); - return; - } - - // allocate the memory needed for the separate strings of each directory - directories = mem_rmalloc(dirs); - if (!directories) { - strcpy(dest, srcPath); - return; - } - - // now get all the directories, and place into the individual strings - strptr = dest; - int count = 0; - while (count < dirs) { - directories[count] = mem_strdup(strptr); - strptr += strlen(strptr) + 1; - count++; - } - - // now the fun part, figure out the correct order of the directories - int *dir_order; - - dir_order = mem_rmalloc(dirs); - if (!dir_order) { - strcpy(dest, srcPath); - return; - } - - for (count = 0; count < dirs; count++) - dir_order[count] = -1; // a -1 means the end of the sequence - - // now build the order based on the indicies - int curr_index = 0; - for (count = 0; count < dirs; count++) { - - if (!stricmp(directories[count], "..")) { - // we have to back up a directory - curr_index--; // back up - if (curr_index < 0) - curr_index = 0; // can't go further than root - dir_order[curr_index] = -1; // invalidate current slot - } else if (stricmp(directories[count], ".")) { - // we have a normal directory, add its index - dir_order[curr_index] = count; - curr_index++; - } - } - - // now rebuild the correct path for use, when we hit -1, we're done - dest[0] = '\0'; - for (count = 0; count < dirs; count++) { - if (dir_order[count] == -1) - break; - else { - strcat(dest, directories[dir_order[count]]); - strcat(dest, "/"); - } - } - - // now remove trailing / char - path_length = strlen(dest); - if ((path_length > 0) && (dest[path_length - 1] == '/')) - dest[path_length - 1] = '\0'; - - // free up all the allocated memory and we're done - for (count = 0; count < dirs; count++) { - if (directories[count]) - mem_free(directories[count]); - } - if (directories) - mem_free(directories); - if (dir_order) - mem_free(dir_order); -} - // Generates a temporary filename based on the prefix, and basedir // Parameters: // basedir - directory to put the files diff --git a/ddio/winfile.cpp b/ddio/winfile.cpp index 79644656..cd58619b 100644 --- a/ddio/winfile.cpp +++ b/ddio/winfile.cpp @@ -354,117 +354,6 @@ std::vector ddio_GetSysRoots() { return result; }; -// given a path, it cleans it up (if the path is c:\windows\..\dos it would make it c:\dos) -// srcPath is the original path -// dest is the finished cleaned path. -// dest should be at least _MAX_PATH in size -void ddio_CleanPath(char *dest, const char *srcPath) { - strcpy(dest, srcPath); - - // break the path into directories - char **directories; - int dirs; - int path_length; - - // make sure the path ends with a \ for sanity - path_length = strlen(dest); - - if (dest[path_length - 1] != '\\') { - dest[path_length] = '\\'; - dest[path_length + 1] = '\0'; - path_length++; - } - - // now divide the full path into separate NULL terminated strings,counting the number - // of directories in the process - dirs = 0; - char *strptr = dest; - while (*strptr != '\0') { - if (*strptr == '\\') { - *strptr = '\0'; - dirs++; - } - strptr++; - } - - // check to make sure we have a directory, if we don't then return the original path given - if (dirs == 0) { - strcpy(dest, srcPath); - return; - } - - // allocate the memory needed for the separate strings of each directory - directories = mem_rmalloc(dirs); - if (!directories) { - strcpy(dest, srcPath); - return; - } - - // now get all the directories, and place into the individual strings - strptr = dest; - int count = 0; - while (count < dirs) { - directories[count] = mem_strdup(strptr); - strptr += strlen(strptr) + 1; - count++; - } - - // now the fun part, figure out the correct order of the directories - int *dir_order; - - dir_order = mem_rmalloc(dirs); - if (!dir_order) { - strcpy(dest, srcPath); - return; - } - - for (count = 0; count < dirs; count++) - dir_order[count] = -1; // a -1 means the end of the sequence - - // now build the order based on the indicies - int curr_index = 0; - for (count = 0; count < dirs; count++) { - - if (!stricmp(directories[count], "..")) { - // we have to back up a directory - curr_index--; // back up - if (curr_index < 0) - curr_index = 0; // can't go further than root - dir_order[curr_index] = -1; // invalidate current slot - } else if (stricmp(directories[count], ".")) { - // we have a normal directory, add its index - dir_order[curr_index] = count; - curr_index++; - } - } - - // now rebuild the correct path for use, when we hit -1, we're done - dest[0] = '\0'; - for (count = 0; count < dirs; count++) { - if (dir_order[count] == -1) - break; - else { - strcat(dest, directories[dir_order[count]]); - strcat(dest, "\\"); - } - } - - // now remove trailing \ char - path_length = strlen(dest); - if ((path_length > 0) && (dest[path_length - 1] == '\\')) - dest[path_length - 1] = '\0'; - - // free up all the allocated memory and we're done - for (count = 0; count < dirs; count++) { - if (directories[count]) - mem_free(directories[count]); - } - if (directories) - mem_free(directories); - if (dir_order) - mem_free(dir_order); -} - bool ddio_CheckProcess(int pid) { HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid); if (proc) { diff --git a/editor/FilePageAddDlg.cpp b/editor/FilePageAddDlg.cpp index 84799f06..03fbd10d 100644 --- a/editor/FilePageAddDlg.cpp +++ b/editor/FilePageAddDlg.cpp @@ -287,7 +287,6 @@ inline void CFileList::setPath(CString path) { if (!buffer) return; - // ddio_CleanPath(buffer,temp.GetBuffer(0)); strcpy(buffer, temp.GetBuffer(0)); m_csPath = buffer;