mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
-logdir lets the user change the log directory
This commit is contained in:
parent
c285000c56
commit
457e986b75
3 changed files with 102 additions and 9 deletions
73
src/m_misc.c
73
src/m_misc.c
|
@ -2453,3 +2453,76 @@ const char *M_FileError(FILE *fp)
|
|||
else
|
||||
return "end-of-file";
|
||||
}
|
||||
|
||||
/** Return the number of parts of this path.
|
||||
*/
|
||||
int M_PathParts(const char *path)
|
||||
{
|
||||
int n;
|
||||
const char *p;
|
||||
const char *t;
|
||||
for (n = 0, p = path ;; ++n)
|
||||
{
|
||||
t = p;
|
||||
if (( p = strchr(p, PATHSEP[0]) ))
|
||||
p += strspn(p, PATHSEP);
|
||||
else
|
||||
{
|
||||
if (*t)/* there is something after the final delimiter */
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/** Check whether a path is an absolute path.
|
||||
*/
|
||||
boolean M_IsPathAbsolute(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return ( strncmp(&path[1], ":\\", 2) == 0 );
|
||||
#else
|
||||
return ( path[0] == '/' );
|
||||
#endif
|
||||
}
|
||||
|
||||
/** I_mkdir for each part of the path.
|
||||
*/
|
||||
void M_MkdirEach(const char *cpath, int start, int mode)
|
||||
{
|
||||
char path[MAX_WADPATH];
|
||||
char *p;
|
||||
char *t;
|
||||
strlcpy(path, cpath, sizeof path);
|
||||
#ifdef _WIN32
|
||||
if (strncmp(&path[1], ":\\", 2) == 0)
|
||||
p = &path[3];
|
||||
else
|
||||
#endif
|
||||
p = path;
|
||||
for (; start > 0; --start)
|
||||
{
|
||||
p += strspn(p, PATHSEP);
|
||||
if (!( p = strchr(p, PATHSEP[0]) ))
|
||||
return;
|
||||
}
|
||||
p += strspn(p, PATHSEP);
|
||||
for (;;)
|
||||
{
|
||||
t = p;
|
||||
if (( p = strchr(p, PATHSEP[0]) ))
|
||||
{
|
||||
*p = '\0';
|
||||
I_mkdir(path, mode);
|
||||
*p = PATHSEP[0];
|
||||
p += strspn(p, PATHSEP);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*t)
|
||||
I_mkdir(path, mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,6 +96,10 @@ void M_SetupMemcpy(void);
|
|||
|
||||
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);
|
||||
|
||||
// counting bits, for weapon ammo code, usually
|
||||
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "../doomdef.h"
|
||||
#include "../m_argv.h"
|
||||
#include "../d_main.h"
|
||||
#include "../m_misc.h"/* path shit */
|
||||
#include "../i_system.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -134,6 +135,8 @@ int main(int argc, char **argv)
|
|||
time_t my_time;
|
||||
struct tm * timeinfo;
|
||||
const char *format;
|
||||
const char *reldir;
|
||||
int left;
|
||||
|
||||
logdir = D_Home();
|
||||
|
||||
|
@ -145,24 +148,37 @@ int main(int argc, char **argv)
|
|||
else
|
||||
format = "log-%Y-%m-%d_%H-%M-%S.txt";
|
||||
|
||||
strftime(logfile, sizeof logfile, format, timeinfo);
|
||||
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)
|
||||
{
|
||||
// Create dirs here because D_SRB2Main() is too late.
|
||||
I_mkdir(va("%s%s"DEFAULTDIR, logdir, PATHSEP), 0755);
|
||||
I_mkdir(va("%s%s"DEFAULTDIR"%slogs",logdir, PATHSEP, PATHSEP), 0755);
|
||||
logstream = fopen(va("%s%s"DEFAULTDIR"%slogs%s%s",logdir, PATHSEP, PATHSEP, PATHSEP, logfile), "wt");
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif/*DEFAULTDIR*/
|
||||
{
|
||||
I_mkdir("."PATHSEP"logs"PATHSEP, 0755);
|
||||
logstream = fopen(va("."PATHSEP"logs"PATHSEP"%s", logfile), "wt");
|
||||
left = snprintf(logfile, sizeof logfile,
|
||||
"."PATHSEP"%s"PATHSEP, reldir);
|
||||
}
|
||||
#endif/*LOGMESSAGES*/
|
||||
|
||||
M_MkdirEach(logfile, M_PathParts(logdir) - 1, 0755);
|
||||
|
||||
strftime(&logfile[left], sizeof logfile - left, format, timeinfo);
|
||||
|
||||
logstream = fopen(logfile, "wt");
|
||||
}
|
||||
#endif
|
||||
|
||||
//I_OutputMsg("I_StartupSystem() ...\n");
|
||||
I_StartupSystem();
|
||||
|
|
Loading…
Reference in a new issue