Used clang-format on some common files

This commit is contained in:
smallmodel 2023-07-05 21:23:39 +02:00
parent 37d8938e91
commit 68d48d9889
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
27 changed files with 7275 additions and 8076 deletions

View file

@ -34,52 +34,55 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if defined(GAME_DLL)
#include "../fgame/g_local.h"
# include "../fgame/g_local.h"
#define FILE_FS_FreeFile gi.FS_FreeFile
#define FILE_FS_ReadFile(a, b) gi.FS_ReadFile(a, b, true)
#define FILE_Malloc gi.Malloc
#define FILE_Free gi.Free
#define FILE_Error gi.Error
# define FILE_FS_FreeFile gi.FS_FreeFile
# define FILE_FS_ReadFile(a, b) gi.FS_ReadFile(a, b, true)
# define FILE_Malloc gi.Malloc
# define FILE_Free gi.Free
# define FILE_Error gi.Error
#elif defined(CGAME_DLL)
#define FILE_FS_FreeFile cgi.FS_FreeFile
#define FILE_FS_ReadFile(a, b) cgi.FS_ReadFile(a, b, qtrue)
#define FILE_Malloc cgi.Malloc
#define FILE_Free cgi.Free
#define FILE_Error cgi.Error
# define FILE_FS_FreeFile cgi.FS_FreeFile
# define FILE_FS_ReadFile(a, b) cgi.FS_ReadFile(a, b, qtrue)
# define FILE_Malloc cgi.Malloc
# define FILE_Free cgi.Free
# define FILE_Error cgi.Error
#else
#include "qcommon.h"
# include "qcommon.h"
#define FILE_FS_FreeFile FS_FreeFile
#define FILE_FS_ReadFile(a, b) FS_ReadFile(a, b)
#define FILE_Malloc Z_Malloc
#define FILE_Free Z_Free
#define FILE_Error Com_Error
# define FILE_FS_FreeFile FS_FreeFile
# define FILE_FS_ReadFile(a, b) FS_ReadFile(a, b)
# define FILE_Malloc Z_Malloc
# define FILE_Free Z_Free
# define FILE_Error Com_Error
#endif
typedef unsigned char byte;
CLASS_DECLARATION(Class, Script, NULL){
CLASS_DECLARATION(Class, Script, NULL) {
{NULL, NULL}
};
Script::~Script() { Close(); }
Script::Script(const char* filename /*= 0*/)
Script::~Script()
{
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
length = 0;
Close();
}
Script::Script(const char *filename /*= 0*/)
{
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
length = 0;
releaseBuffer = false;
tokenready = false;
token[0] = 0;
tokenready = false;
token[0] = 0;
if (filename != 0) {
LoadFile(filename);
@ -88,29 +91,29 @@ Script::Script(const char* filename /*= 0*/)
Script::Script()
{
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
length = 0;
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
length = 0;
releaseBuffer = false;
tokenready = false;
token[0] = 0;
tokenready = false;
token[0] = 0;
}
void Script::Close(void)
{
if (releaseBuffer && buffer) {
FILE_Free((void*)buffer);
FILE_Free((void *)buffer);
}
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
buffer = NULL;
script_p = NULL;
end_p = NULL;
line = 0;
releaseBuffer = false;
tokenready = false;
token[0] = 0;
tokenready = false;
token[0] = 0;
// Loop Through the macro container and delete (del33t -hehe) them all
for (int i = 1; i <= macrolist.NumObjects(); i++) {
@ -129,7 +132,10 @@ void Script::Close(void)
==============
*/
const char* Script::Filename(void) { return filename.c_str(); }
const char *Script::Filename(void)
{
return filename.c_str();
}
/*
==============
@ -139,7 +145,10 @@ const char* Script::Filename(void) { return filename.c_str(); }
==============
*/
int Script::GetLineNumber(void) { return line; }
int Script::GetLineNumber(void)
{
return line;
}
/*
==============
@ -151,10 +160,10 @@ int Script::GetLineNumber(void) { return line; }
void Script::Reset(void)
{
script_p = buffer;
line = 1;
script_p = buffer;
line = 1;
tokenready = false;
hasError = false;
hasError = false;
}
/*
@ -165,13 +174,13 @@ void Script::Reset(void)
==============
*/
void Script::MarkPosition(scriptmarker_t* mark)
void Script::MarkPosition(scriptmarker_t *mark)
{
assert(mark);
mark->tokenready = tokenready;
mark->offset = script_p - buffer;
mark->line = line;
mark->offset = script_p - buffer;
mark->line = line;
strcpy(mark->token, token);
}
@ -183,13 +192,13 @@ void Script::MarkPosition(scriptmarker_t* mark)
==============
*/
void Script::RestorePosition(const scriptmarker_t* mark)
void Script::RestorePosition(const scriptmarker_t *mark)
{
assert(mark);
tokenready = mark->tokenready;
script_p = buffer + mark->offset;
line = mark->line;
script_p = buffer + mark->offset;
line = mark->line;
strcpy(token, mark->token);
assert(script_p <= end_p);
@ -232,9 +241,7 @@ qboolean Script::SkipToEOL(void)
void Script::CheckOverflow(void)
{
if (script_p >= end_p) {
FILE_Error(ERR_DROP,
"End of token file reached prematurely reading %s\n",
filename.c_str());
FILE_Error(ERR_DROP, "End of token file reached prematurely reading %s\n", filename.c_str());
}
}
@ -256,8 +263,7 @@ void Script::SkipWhiteSpace(qboolean crossline)
while (*script_p <= TOKENSPACE) {
if (*script_p++ == TOKENEOL) {
if (!crossline) {
FILE_Error(ERR_DROP, "Line %i is incomplete in file %s\n", line,
filename.c_str());
FILE_Error(ERR_DROP, "Line %i is incomplete in file %s\n", line, filename.c_str());
}
line++;
@ -374,7 +380,7 @@ qboolean Script::TokenAvailable(qboolean crossline)
qboolean Script::CommentAvailable(qboolean crossline)
{
const char* searchptr;
const char *searchptr;
searchptr = script_p;
@ -412,7 +418,10 @@ GetToken (false);
==============
*/
void Script::UnGetToken(void) { tokenready = true; }
void Script::UnGetToken(void)
{
tokenready = true;
}
/*
==============
@ -478,11 +487,9 @@ qboolean Script::AtAssignment(qboolean crossline)
//
SkipNonToken(crossline);
return (*script_p == '=') ||
((*script_p == '+') && (*(script_p + 1) == '=')) ||
((*script_p == '-') && (*(script_p + 1) == '=')) ||
((*script_p == '*') && (*(script_p + 1) == '=')) ||
((*script_p == '/') && (*(script_p + 1) == '='));
return (*script_p == '=') || ((*script_p == '+') && (*(script_p + 1) == '='))
|| ((*script_p == '-') && (*(script_p + 1) == '=')) || ((*script_p == '*') && (*(script_p + 1) == '='))
|| ((*script_p == '/') && (*(script_p + 1) == '='));
}
/*
@ -493,10 +500,9 @@ qboolean Script::AtAssignment(qboolean crossline)
==============
*/
const char* Script::GetToken(qboolean crossline)
const char *Script::GetToken(qboolean crossline)
{
str token_p = token;
str token_p = token;
qboolean is_Macro = false;
// is a token already waiting?
@ -510,7 +516,6 @@ const char* Script::GetToken(qboolean crossline)
token_p = GrabNextToken(crossline);
if (is_Macro && (token_p != "$include")) {
// Check to see if we need to add any definitions
while ((token_p == "$define") || (token_p == "$Define")) {
AddMacroDefinition(crossline);
@ -521,8 +526,7 @@ const char* Script::GetToken(qboolean crossline)
}
// Check to see if we need return any defines strings
if (is_Macro && (token_p != "$include") &&
(token_p[token_p.length() - 1] == '$')) {
if (is_Macro && (token_p != "$include") && (token_p[token_p.length() - 1] == '$')) {
return GetMacroString(token_p);
}
}
@ -537,9 +541,9 @@ const char* Script::GetToken(qboolean crossline)
=
==============
*/
const char* Script::GrabNextToken(qboolean crossline)
const char *Script::GrabNextToken(qboolean crossline)
{
char* token_p;
char *token_p;
//
// skip space
@ -583,8 +587,7 @@ const char* Script::GrabNextToken(qboolean crossline)
}
if (token_p == &token[SCRIPT_MAXTOKEN]) {
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n",
line, filename.c_str());
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
}
if (script_p == end_p) {
@ -606,7 +609,7 @@ const char* Script::GrabNextToken(qboolean crossline)
*/
void Script::AddMacroDefinition(qboolean crossline)
{
macro* theMacro;
macro *theMacro;
// Create a new macro structure. This new macro will be deleted in the
// script close()
@ -615,8 +618,7 @@ void Script::AddMacroDefinition(qboolean crossline)
// Grab the macro name
theMacro->macroName = "$";
theMacro->macroName.append(GrabNextToken(crossline));
theMacro->macroName.append(
"$"); //<-- Adding closing ($) to keep formatting consistant
theMacro->macroName.append("$"); //<-- Adding closing ($) to keep formatting consistant
// Grab the macro string
str tmpstr;
@ -638,17 +640,15 @@ void Script::AddMacroDefinition(qboolean crossline)
=
==============
*/
const char* Script::GetMacroString(const char* theMacroName)
const char *Script::GetMacroString(const char *theMacroName)
{
macro* theMacro = 0; // Initialize this puppy
macro *theMacro = 0; // Initialize this puppy
for (int i = 1; i <= macrolist.NumObjects(); i++) {
theMacro = macrolist.ObjectAt(i);
if (!theMacro->macroName.cmp(theMacro->macroName.c_str(),
theMacroName)) {
const char* text = theMacro->macroText.c_str();
if (!theMacro->macroName.cmp(theMacro->macroName.c_str(), theMacroName)) {
const char *text = theMacro->macroText.c_str();
// If our define value is another define...
if (text[0] == '$') {
@ -665,8 +665,7 @@ const char* Script::GetMacroString(const char* theMacroName)
sptr++;
// We didn't find what we were looking for
FILE_Error(ERR_DROP, "No Macro Text found for %s in file %s\n",
theMacroName, filename.c_str());
FILE_Error(ERR_DROP, "No Macro Text found for %s in file %s\n", theMacroName, filename.c_str());
return 0;
}
@ -682,7 +681,7 @@ const char* Script::GetMacroString(const char* theMacroName)
// Returns: None
//
//================================================================
void Script::AddMacro(const char* name, const char* value) {}
void Script::AddMacro(const char *name, const char *value) {}
/*
==============
@ -691,31 +690,31 @@ void Script::AddMacro(const char* name, const char* value) {}
=
==============
*/
char* Script::EvaluateMacroString(const char* theMacroString)
char *Script::EvaluateMacroString(const char *theMacroString)
{
static char evalText[255];
char buffer[255], *bufferptr = buffer, oper = '+', newoper = '+';
bool haveoper = false;
int i;
float value = 0.0f, val = 0.0f;
char buffer[255], *bufferptr = buffer, oper = '+', newoper = '+';
bool haveoper = false;
int i;
float value = 0.0f, val = 0.0f;
memset(buffer, 0, 255);
for (i = 0; i <= strlen(theMacroString); i++) {
if (theMacroString[i] == '+') {
haveoper = true;
newoper = '+';
newoper = '+';
}
if (theMacroString[i] == '-') {
haveoper = true;
newoper = '-';
newoper = '-';
}
if (theMacroString[i] == '*') {
haveoper = true;
newoper = '*';
newoper = '*';
}
if (theMacroString[i] == '/') {
haveoper = true;
newoper = '/';
newoper = '/';
}
if (theMacroString[i] == 0) {
haveoper = true;
@ -729,7 +728,7 @@ char* Script::EvaluateMacroString(const char* theMacroString)
}
value = EvaluateMacroMath(value, val, oper);
oper = newoper;
oper = newoper;
// Reset everything
haveoper = false;
@ -802,10 +801,10 @@ qboolean Script::isMacro(void)
==============
*/
const char* Script::GetLine(qboolean crossline)
const char *Script::GetLine(qboolean crossline)
{
const char* start;
int size;
const char *start;
int size;
// is a token already waiting?
if (tokenready) {
@ -828,8 +827,7 @@ const char* Script::GetLine(qboolean crossline)
memcpy(token, start, size);
token[size] = '\0';
} else {
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
filename.c_str());
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
}
return token;
@ -843,10 +841,10 @@ const char* Script::GetLine(qboolean crossline)
==============
*/
const char* Script::GetRaw(void)
const char *Script::GetRaw(void)
{
const char* start;
int size;
const char *start;
int size;
//
// skip white space
@ -863,8 +861,7 @@ const char* Script::GetRaw(void)
memset(token, 0, sizeof(token));
memcpy(token, start, size);
} else {
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
filename.c_str());
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
}
return token;
@ -878,10 +875,10 @@ const char* Script::GetRaw(void)
==============
*/
const char* Script::GetString(qboolean crossline)
const char *Script::GetString(qboolean crossline)
{
int startline;
char* token_p;
int startline;
char *token_p;
// is a token already waiting?
if (tokenready) {
@ -895,20 +892,16 @@ const char* Script::GetString(qboolean crossline)
SkipNonToken(crossline);
if (*script_p != '"') {
FILE_Error(ERR_DROP, "Expecting string on line %i in file %s\n", line,
filename.c_str());
FILE_Error(ERR_DROP, "Expecting string on line %i in file %s\n", line, filename.c_str());
}
script_p++;
startline = line;
token_p = token;
token_p = token;
while (*script_p != '"') {
if (*script_p == TOKENEOL) {
FILE_Error(
ERR_DROP,
"Line %i is incomplete while reading string in file %s\n", line,
filename.c_str());
FILE_Error(ERR_DROP, "Line %i is incomplete while reading string in file %s\n", line, filename.c_str());
}
if ((*script_p == '\\') && (script_p < (end_p - 1))) {
@ -939,16 +932,18 @@ const char* Script::GetString(qboolean crossline)
}
if (script_p >= end_p) {
FILE_Error(ERR_DROP,
"End of token file reached prematurely while reading "
"string on\n"
"line %d in file %s\n",
startline, filename.c_str());
FILE_Error(
ERR_DROP,
"End of token file reached prematurely while reading "
"string on\n"
"line %d in file %s\n",
startline,
filename.c_str()
);
}
if (token_p == &token[SCRIPT_MAXTOKEN]) {
FILE_Error(ERR_DROP, "String too large on line %i in file %s\n",
line, filename.c_str());
FILE_Error(ERR_DROP, "String too large on line %i in file %s\n", line, filename.c_str());
}
}
@ -968,7 +963,7 @@ const char* Script::GetString(qboolean crossline)
==============
*/
qboolean Script::GetSpecific(const char* string)
qboolean Script::GetSpecific(const char *string)
{
do {
if (!TokenAvailable(true)) {
@ -1072,15 +1067,15 @@ Vector Script::GetVector(qboolean crossline)
*/
int Script::LinesInFile(void)
{
qboolean temp_tokenready;
const char* temp_script_p;
int temp_line;
char temp_token[SCRIPT_MAXTOKEN];
int numentries;
qboolean temp_tokenready;
const char *temp_script_p;
int temp_line;
char temp_token[SCRIPT_MAXTOKEN];
int numentries;
temp_tokenready = tokenready;
temp_script_p = script_p;
temp_line = line;
temp_script_p = script_p;
temp_line = line;
strcpy(temp_token, token);
numentries = 0;
@ -1092,8 +1087,8 @@ int Script::LinesInFile(void)
}
tokenready = temp_tokenready;
script_p = temp_script_p;
line = temp_line;
script_p = temp_script_p;
line = temp_line;
strcpy(token, temp_token);
return numentries;
@ -1107,15 +1102,15 @@ int Script::LinesInFile(void)
==============
*/
void Script::Parse(const char* data, size_t length, const char* name)
void Script::Parse(const char *data, size_t length, const char *name)
{
Close();
buffer = data;
Reset();
this->length = length;
end_p = script_p + length;
filename = name;
end_p = script_p + length;
filename = name;
}
/*
@ -1126,16 +1121,16 @@ void Script::Parse(const char* data, size_t length, const char* name)
==============
*/
void Script::LoadFile(const char* name)
void Script::LoadFile(const char *name)
{
int length;
byte* buffer;
byte* tempbuf;
const char* const_buffer;
int length;
byte *buffer;
byte *tempbuf;
const char *const_buffer;
Close();
length = FILE_FS_ReadFile(name, (void**)&tempbuf);
length = FILE_FS_ReadFile(name, (void **)&tempbuf);
hasError = false;
@ -1145,14 +1140,14 @@ void Script::LoadFile(const char* name)
}
// create our own space
buffer = (byte*)FILE_Malloc(length + 1);
buffer = (byte *)FILE_Malloc(length + 1);
// copy the file over to our space
memcpy(buffer, tempbuf, length);
buffer[length] = 0;
// free the file
FILE_FS_FreeFile(tempbuf);
const_buffer = (char*)buffer;
const_buffer = (char *)buffer;
Parse(const_buffer, length, name);
releaseBuffer = true;
@ -1166,22 +1161,31 @@ void Script::LoadFile(const char* name)
==============
*/
void Script::LoadFile(const char* name, int length, const char* buf)
void Script::LoadFile(const char *name, int length, const char *buf)
{
Close();
// create our own space
this->buffer = (const char*)FILE_Malloc(length);
this->buffer = (const char *)FILE_Malloc(length);
this->length = length;
// copy the file over to our space
memcpy((void*)this->buffer, buf, length);
memcpy((void *)this->buffer, buf, length);
Parse(buffer, this->length, name);
releaseBuffer = true;
}
qboolean Script::isValid() { return !hasError; }
qboolean Script::isValid()
{
return !hasError;
}
qboolean Script::EndOfFile(void) { return script_p >= end_p; }
qboolean Script::EndOfFile(void)
{
return script_p >= end_p;
}
const char* Script::Token(void) { return token; }
const char *Script::Token(void)
{
return token;
}