mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Fix M_MkdirEach and M_PathParts
OKAY I didn't test this on Windows before, it was BROKEN AND SHITTY CODE.
This commit is contained in:
parent
66094ec72d
commit
cdce6824f2
1 changed files with 36 additions and 44 deletions
80
src/m_misc.c
80
src/m_misc.c
|
|
@ -2555,26 +2555,25 @@ const char *M_FileError(FILE *fp)
|
||||||
|
|
||||||
/** Return the number of parts of this path.
|
/** Return the number of parts of this path.
|
||||||
*/
|
*/
|
||||||
int M_PathParts(const char *path)
|
int M_PathParts(const char *p)
|
||||||
{
|
{
|
||||||
int n;
|
int parts = 0;
|
||||||
const char *p;
|
|
||||||
const char *t;
|
if (p == NULL)
|
||||||
if (path == NULL)
|
|
||||||
return 0;
|
return 0;
|
||||||
for (n = 0, p = path ;; ++n)
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!strncmp(&p[1], ":\\", 2))
|
||||||
|
p += 3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while (*(p += strspn(p, PATHSEP)))
|
||||||
{
|
{
|
||||||
t = p;
|
parts++;
|
||||||
if (( p = strchr(p, PATHSEP[0]) ))
|
p += strcspn(p, PATHSEP);
|
||||||
p += strspn(p, PATHSEP);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (*t)/* there is something after the final delimiter */
|
|
||||||
n++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return n;
|
|
||||||
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check whether a path is an absolute path.
|
/** Check whether a path is an absolute path.
|
||||||
|
|
@ -2592,50 +2591,43 @@ boolean M_IsPathAbsolute(const char *path)
|
||||||
*/
|
*/
|
||||||
void M_MkdirEachUntil(const char *cpath, int start, int end, int mode)
|
void M_MkdirEachUntil(const char *cpath, int start, int end, int mode)
|
||||||
{
|
{
|
||||||
char path[MAX_WADPATH];
|
char path[256];
|
||||||
char *p;
|
char *p;
|
||||||
char *t;
|
int n;
|
||||||
|
int c;
|
||||||
|
|
||||||
if (end > 0 && end <= start)
|
if (end > 0 && end <= start)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strlcpy(path, cpath, sizeof path);
|
strlcpy(path, cpath, sizeof path);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (strncmp(&path[1], ":\\", 2) == 0)
|
if (!strncmp(&path[1], ":\\", 2))
|
||||||
p = &path[3];
|
p = &path[3];
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
p = path;
|
p = path;
|
||||||
|
|
||||||
if (end > 0)
|
while (end != 0 && *(p += strspn(p, PATHSEP)))
|
||||||
end -= start;
|
|
||||||
|
|
||||||
for (; start > 0; --start)
|
|
||||||
{
|
{
|
||||||
p += strspn(p, PATHSEP);
|
n = strcspn(p, PATHSEP);
|
||||||
if (!( p = strchr(p, PATHSEP[0]) ))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p += strspn(p, PATHSEP);
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (end > 0 && !--end)
|
|
||||||
break;
|
|
||||||
|
|
||||||
t = p;
|
if (start > 0)
|
||||||
if (( p = strchr(p, PATHSEP[0]) ))
|
start--;
|
||||||
{
|
|
||||||
*p = '\0';
|
|
||||||
I_mkdir(path, mode);
|
|
||||||
*p = PATHSEP[0];
|
|
||||||
p += strspn(p, PATHSEP);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*t)
|
c = p[n];
|
||||||
I_mkdir(path, mode);
|
p[n] = '\0';
|
||||||
break;
|
|
||||||
|
I_mkdir(path, mode);
|
||||||
|
|
||||||
|
p[n] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p += n;
|
||||||
|
|
||||||
|
if (end > 0)
|
||||||
|
end--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2697,4 +2689,4 @@ const char * M_Ftrim (double f)
|
||||||
dig[i + 1] = '\0';
|
dig[i + 1] = '\0';
|
||||||
return &dig[1];/* skip the 0 */
|
return &dig[1];/* skip the 0 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue