MCPcopy Create free account
hub / github.com/assaultcube/AC / path

Function path

source/src/stream.cpp:36–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36char *path(char *s)
37{
38 char *c = s;
39 // skip "<decal>"
40 if(c[0] == '<')
41 {
42 char *enddecal = strrchr(c, '>');
43 if(!enddecal) return s;
44 c = enddecal + 1;
45 }
46 // substitute with single, proper path delimiters
47 for(char *t = c; (t = strpbrk(t, "/\\")); )
48 {
49 *t++ = PATHDIV;
50 size_t d = strspn(t, "/\\");
51 if(d) memmove(t, t + d, strlen(t + d) + 1); // remove multiple path delimiters
52 }
53 // collapse ".."-parts
54 for(char *prevdir = NULL, *curdir = s;;)
55 {
56 prevdir = curdir[0] == PATHDIV ? curdir + 1 : curdir;
57 curdir = strchr(prevdir, PATHDIV);
58 if(!curdir) break;
59 if(prevdir + 1 == curdir && prevdir[0]=='.')
60 { // simply remove "./"
61 memmove(prevdir, curdir + 1, strlen(curdir));
62 curdir = prevdir;
63 }
64 else if(curdir[1] == '.' && curdir[2] == '.' && curdir[3] == PATHDIV)
65 { // collapse "/foo/../" to "/"
66 if(prevdir + 2 == curdir && prevdir[0] == '.' && prevdir[1] == '.') continue; // foo is also ".." -> skip
67 memmove(prevdir, curdir + 4, strlen(curdir + 3));
68 if(prevdir >= c + 2 && prevdir[-1] == PATHDIV)
69 {
70 prevdir -= 2;
71 while(prevdir > c && prevdir[-1] != PATHDIV) --prevdir;
72 }
73 curdir = prevdir;
74 }
75 }
76 return s;
77}
78
79char *unixpath(char *s)
80{

Callers 15

textureloadFunction · 0.85
lookuptextureFunction · 0.85
gettextureoriginFunction · 0.85
openMethod · 0.85
initloggingFunction · 0.85
loadMethod · 0.85
trymapfilesFunction · 0.85
serverwritemapFunction · 0.85
initMethod · 0.85
fixpackagedirFunction · 0.85
listsubdirFunction · 0.85

Calls 1

copystringFunction · 0.85

Tested by

no test coverage detected