- split out non-game specific CCMDs into their own file.

This commit is contained in:
Christoph Oelckers 2020-04-11 18:10:34 +02:00
commit a712866219
7 changed files with 335 additions and 287 deletions

View file

@ -37,12 +37,6 @@
#include <stdio.h>
#include <errno.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include "version.h"
#include "c_console.h"
#include "c_dispatch.h"
@ -102,16 +96,6 @@ bool CheckCheatmode (bool printmsg)
}
}
CCMD (quit)
{
if (!insave) throw CExitEvent(0);
}
CCMD (exit)
{
if (!insave) throw CExitEvent(0);
}
/*
==================
Cmd_God
@ -448,73 +432,6 @@ CCMD(setinv)
}
CCMD (gameversion)
{
Printf ("%s @ %s\nCommit %s\n", GetVersionString(), GetGitTime(), GetGitHash());
}
CCMD (print)
{
if (argv.argc() != 2)
{
Printf ("print <name>: Print a string from the string table\n");
return;
}
const char *str = GStrings[argv[1]];
if (str == NULL)
{
Printf ("%s unknown\n", argv[1]);
}
else
{
Printf ("%s\n", str);
}
}
UNSAFE_CCMD (exec)
{
if (argv.argc() < 2)
return;
for (int i = 1; i < argv.argc(); ++i)
{
if (!C_ExecFile(argv[i]))
{
Printf ("Could not exec \"%s\"\n", argv[i]);
break;
}
}
}
void execLogfile(const char *fn, bool append)
{
if ((Logfile = fopen(fn, append? "a" : "w")))
{
const char *timestr = myasctime();
Printf("Log started: %s\n", timestr);
}
else
{
Printf("Could not start log\n");
}
}
UNSAFE_CCMD (logfile)
{
if (Logfile)
{
const char *timestr = myasctime();
Printf("Log stopped: %s\n", timestr);
fclose (Logfile);
Logfile = NULL;
}
if (argv.argc() >= 2)
{
execLogfile(argv[1], argv.argc() >=3? !!argv[2]:false);
}
}
CCMD (puke)
{
@ -642,119 +559,7 @@ CCMD (special)
}
}
CCMD (error)
{
if (argv.argc() > 1)
{
I_Error ("%s", argv[1]);
}
else
{
Printf ("Usage: error <error text>\n");
}
}
UNSAFE_CCMD (error_fatal)
{
if (argv.argc() > 1)
{
I_FatalError ("%s", argv[1]);
}
else
{
Printf ("Usage: error_fatal <error text>\n");
}
}
//==========================================================================
//
// CCMD crashout
//
// Debugging routine for testing the crash logger.
// Useless in a win32 debug build, because that doesn't enable the crash logger.
//
//==========================================================================
#if !defined(_WIN32) || !defined(_DEBUG)
UNSAFE_CCMD (crashout)
{
*(volatile int *)0 = 0;
}
#endif
UNSAFE_CCMD (dir)
{
FString dir, path;
char curdir[256];
const char *match;
findstate_t c_file;
void *file;
if (!getcwd (curdir, countof(curdir)))
{
Printf ("Current path too long\n");
return;
}
if (argv.argc() > 1)
{
path = NicePath(argv[1]);
if (chdir(path))
{
match = path;
dir = ExtractFilePath(path);
if (dir[0] != '\0')
{
match += dir.Len();
}
else
{
dir = "./";
}
if (match[0] == '\0')
{
match = "*";
}
if (chdir (dir))
{
Printf ("%s not found\n", dir.GetChars());
return;
}
}
else
{
match = "*";
dir = path;
}
}
else
{
match = "*";
dir = curdir;
}
if (dir[dir.Len()-1] != '/')
{
dir += '/';
}
if ( (file = I_FindFirst (match, &c_file)) == ((void *)(-1)))
Printf ("Nothing matching %s%s\n", dir.GetChars(), match);
else
{
Printf ("Listing of %s%s:\n", dir.GetChars(), match);
do
{
if (I_FindAttr (&c_file) & FA_DIREC)
Printf (PRINT_BOLD, "%s <dir>\n", I_FindName (&c_file));
else
Printf ("%s\n", I_FindName (&c_file));
} while (I_FindNext (file, &c_file) == 0);
I_FindClose (file);
}
chdir (curdir);
}
//==========================================================================
//
@ -833,35 +638,6 @@ UNSAFE_CCMD (save)
G_SaveGame (fname, argv.argc() > 2 ? argv[2] : argv[1]);
}
//==========================================================================
//
// CCMD wdir
//
// Lists the contents of a loaded wad file.
//
//==========================================================================
CCMD (wdir)
{
if (argv.argc() != 2)
{
Printf ("usage: wdir <wadfile>\n");
return;
}
int wadnum = fileSystem.CheckIfResourceFileLoaded (argv[1]);
if (wadnum < 0)
{
Printf ("%s must be loaded to view its directory.\n", argv[1]);
return;
}
for (int i = 0; i < fileSystem.GetNumEntries(); ++i)
{
if (fileSystem.GetFileContainer(i) == wadnum)
{
Printf ("%s\n", fileSystem.GetFileFullName(i));
}
}
}
//-----------------------------------------------------------------------------
//
@ -1308,43 +1084,3 @@ CCMD(r_showcaps)
}
//==========================================================================
//
// CCMD md5sum
//
// Like the command-line tool, because I wanted to make sure I had it right.
//
//==========================================================================
CCMD (md5sum)
{
if (argv.argc() < 2)
{
Printf("Usage: md5sum <file> ...\n");
}
for (int i = 1; i < argv.argc(); ++i)
{
FileReader fr;
if (!fr.OpenFile(argv[i]))
{
Printf("%s: %s\n", argv[i], strerror(errno));
}
else
{
MD5Context md5;
uint8_t readbuf[8192];
size_t len;
while ((len = fr.Read(readbuf, sizeof(readbuf))) > 0)
{
md5.Update(readbuf, (unsigned int)len);
}
md5.Final(readbuf);
for(int j = 0; j < 16; ++j)
{
Printf("%02x", readbuf[j]);
}
Printf(" *%s\n", argv[i]);
}
}
}