mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
Let an asbolute path work with -logfile
This commit is contained in:
parent
457e986b75
commit
5fbe77cdda
3 changed files with 56 additions and 21 deletions
18
src/m_misc.c
18
src/m_misc.c
|
@ -2489,11 +2489,15 @@ boolean M_IsPathAbsolute(const char *path)
|
|||
|
||||
/** I_mkdir for each part of the path.
|
||||
*/
|
||||
void M_MkdirEach(const char *cpath, int start, int mode)
|
||||
void M_MkdirEachUntil(const char *cpath, int start, int end, int mode)
|
||||
{
|
||||
char path[MAX_WADPATH];
|
||||
char *p;
|
||||
char *t;
|
||||
|
||||
if (end > 0 && end <= start)
|
||||
return;
|
||||
|
||||
strlcpy(path, cpath, sizeof path);
|
||||
#ifdef _WIN32
|
||||
if (strncmp(&path[1], ":\\", 2) == 0)
|
||||
|
@ -2501,6 +2505,10 @@ void M_MkdirEach(const char *cpath, int start, int mode)
|
|||
else
|
||||
#endif
|
||||
p = path;
|
||||
|
||||
if (end > 0)
|
||||
end -= start;
|
||||
|
||||
for (; start > 0; --start)
|
||||
{
|
||||
p += strspn(p, PATHSEP);
|
||||
|
@ -2510,6 +2518,9 @@ void M_MkdirEach(const char *cpath, int start, int mode)
|
|||
p += strspn(p, PATHSEP);
|
||||
for (;;)
|
||||
{
|
||||
if (end > 0 && !--end)
|
||||
break;
|
||||
|
||||
t = p;
|
||||
if (( p = strchr(p, PATHSEP[0]) ))
|
||||
{
|
||||
|
@ -2526,3 +2537,8 @@ void M_MkdirEach(const char *cpath, int start, int mode)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void M_MkdirEach(const char *path, int start, int mode)
|
||||
{
|
||||
M_MkdirEachUntil(path, start, -1, mode);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ const char *M_FileError(FILE *handle);
|
|||
int M_PathParts (const char *path);
|
||||
boolean M_IsPathAbsolute (const char *path);
|
||||
void M_MkdirEach (const char *path, int start, int mode);
|
||||
void M_MkdirEachUntil (const char *path, int start, int end, int mode);
|
||||
|
||||
// counting bits, for weapon ammo code, usually
|
||||
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
||||
|
|
|
@ -137,6 +137,7 @@ int main(int argc, char **argv)
|
|||
const char *format;
|
||||
const char *reldir;
|
||||
int left;
|
||||
boolean fileabs;
|
||||
|
||||
logdir = D_Home();
|
||||
|
||||
|
@ -144,38 +145,55 @@ int main(int argc, char **argv)
|
|||
timeinfo = localtime(&my_time);
|
||||
|
||||
if (M_CheckParm("-logfile") && M_IsNextParm())
|
||||
{
|
||||
format = M_GetNextParm();
|
||||
fileabs = M_IsPathAbsolute(format);
|
||||
}
|
||||
else
|
||||
{
|
||||
format = "log-%Y-%m-%d_%H-%M-%S.txt";
|
||||
fileabs = false;
|
||||
}
|
||||
|
||||
if (M_CheckParm("-logdir") && M_IsNextParm())
|
||||
reldir = M_GetNextParm();
|
||||
else
|
||||
reldir = "logs";
|
||||
|
||||
if (M_IsPathAbsolute(reldir))
|
||||
if (fileabs)
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"%s"PATHSEP, reldir);
|
||||
strftime(logfile, sizeof logfile, format, timeinfo);
|
||||
|
||||
M_MkdirEachUntil(logfile,
|
||||
M_PathParts(logdir) - 1,
|
||||
M_PathParts(logfile) - 1, 0755);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (M_CheckParm("-logdir") && M_IsNextParm())
|
||||
reldir = M_GetNextParm();
|
||||
else
|
||||
reldir = "logs";
|
||||
|
||||
if (M_IsPathAbsolute(reldir))
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"%s"PATHSEP, reldir);
|
||||
}
|
||||
else
|
||||
#ifdef DEFAULTDIR
|
||||
if (logdir)
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
||||
}
|
||||
else
|
||||
if (logdir)
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
||||
}
|
||||
else
|
||||
#endif/*DEFAULTDIR*/
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"."PATHSEP"%s"PATHSEP, reldir);
|
||||
}
|
||||
{
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"."PATHSEP"%s"PATHSEP, reldir);
|
||||
}
|
||||
#endif/*LOGMESSAGES*/
|
||||
|
||||
M_MkdirEach(logfile, M_PathParts(logdir) - 1, 0755);
|
||||
M_MkdirEach(logfile, M_PathParts(logdir) - 1, 0755);
|
||||
|
||||
strftime(&logfile[left], sizeof logfile - left, format, timeinfo);
|
||||
strftime(&logfile[left], sizeof logfile - left, format, timeinfo);
|
||||
}
|
||||
|
||||
logstream = fopen(logfile, "wt");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue