MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / _splitpath

Function _splitpath

scripts/linux_lib.cpp:21–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19#include <cstring>
20
21void _splitpath(const char *srcPath, char *drive, char *path, char *filename, char *ext) {
22 int pathStart = -1;
23 int pathEnd = -1;
24 int fileStart = -1;
25 int fileEnd = -1;
26 int extStart = -1;
27 int extEnd = -1;
28
29 int totalLen = strlen(srcPath);
30
31 if (drive)
32 *drive = '\0';
33
34 // Check for an extension
35 ///////////////////////////////////////
36 int t = totalLen - 1;
37 while ((srcPath[t] != '.') && (srcPath[t] != '/') && (t >= 0))
38 t--;
39 // see if we are at an extension
40 if ((t >= 0) && (srcPath[t] == '.')) {
41 // we have an extension
42 extStart = t;
43 extEnd = totalLen - 1;
44 if (ext) {
45 strncpy(ext, &(srcPath[extStart]), extEnd - extStart + 1);
46 ext[extEnd - extStart + 1] = '\0';
47 }
48 } else {
49 // no extension
50 if (ext)
51 ext[0] = '\0';
52 }
53
54 // Check for file name
55 ////////////////////////////////////
56 int temp = (extStart != -1) ? (extStart) : (totalLen - 1);
57 while ((srcPath[temp] != '/') && (temp >= 0))
58 temp--;
59 if (temp < 0)
60 temp = 0;
61 if (srcPath[temp] == '/') {
62 // we have a file
63 fileStart = temp + 1;
64 if (extStart != -1)
65 fileEnd = extStart - 1;
66 else
67 fileEnd = totalLen - 1;
68 if (filename) {
69 strncpy(filename, &(srcPath[fileStart]), fileEnd - fileStart + 1);
70 filename[fileEnd - fileStart + 1] = '\0';
71 }
72 pathStart = 0;
73 pathEnd = fileStart - 2;
74 // Copy the rest into the path name
75 if (path) {
76 strncpy(path, &(srcPath[pathStart]), pathEnd - pathStart + 1);
77 path[pathEnd - pathStart + 1] = 0;
78 }

Callers 15

dd_SplitPathFunction · 0.85
CopyHelpFilesFunction · 0.85
ddio_SplitPathFunction · 0.85
GetFileTypeMethod · 0.85
UpdateTitleMethod · 0.85
LoadDocumentMethod · 0.85
SaveDocumentMethod · 0.85
AddFileMethod · 0.85
CreateFilenameListMethod · 0.85
NewHogFileFunction · 0.85
create_new_libraryFunction · 0.85

Calls

no outgoing calls

Tested by 2

InitializeDLLFunction · 0.68
InitializeDLLFunction · 0.68