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

@ -26,73 +26,76 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../fgame/gamecvars.h"
#include "../qcommon/mem_tempalloc.h"
MEM_TempAlloc parsetree_allocator;
MEM_TempAlloc parsetree_allocator;
yyparsedata parsedata;
sval_u node_none = {0};
yyparsedata parsedata;
sval_u node_none = { 0 };
char *str_replace(char *orig, const char *rep, const char *with)
{
char *result; // the return string
char *ins; // the next insert point
char *tmp; // varies
size_t len_rep; // length of rep
size_t len_with; // length of with
size_t len_front; // distance between rep and end of last rep
int count; // number of replacements
char* str_replace(char* orig, const char* rep, const char* with) {
char* result; // the return string
char* ins; // the next insert point
char* tmp; // varies
size_t len_rep; // length of rep
size_t len_with; // length of with
size_t len_front; // distance between rep and end of last rep
int count; // number of replacements
if (!orig) {
return NULL;
}
if (!rep) {
rep = "";
}
len_rep = strlen(rep);
if (!with) {
with = "";
}
len_with = strlen(with);
if (!orig)
return NULL;
if (!rep)
rep = "";
len_rep = strlen(rep);
if (!with)
with = "";
len_with = strlen(with);
ins = orig;
for (count = 0; (tmp = strstr(ins, rep)) != nullptr; ++count) {
ins = tmp + len_rep;
}
ins = orig;
for (count = 0; (tmp = strstr(ins, rep)) != nullptr; ++count) {
ins = tmp + len_rep;
}
// first time through the loop, all the variable are set correctly
// from here on,
// tmp points to the end of the result string
// ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep"
tmp = result = (char *)parsetree_allocator.Alloc(strlen(orig) + (len_with - len_rep) * count + 1);
// first time through the loop, all the variable are set correctly
// from here on,
// tmp points to the end of the result string
// ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep"
tmp = result = (char*)parsetree_allocator.Alloc(strlen(orig) + (len_with - len_rep) * count + 1);
if (!result) {
return NULL;
}
if (!result)
return NULL;
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
}
strcpy(tmp, orig);
return result;
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
}
strcpy(tmp, orig);
return result;
}
void parsetree_freeall()
{
parsetree_allocator.FreeAll();
parsetree_allocator.FreeAll();
if (g_showopcodes->integer)
{
gi.DPrintf("%d bytes freed\n", parsedata.total_length);
}
if (g_showopcodes->integer) {
gi.DPrintf("%d bytes freed\n", parsedata.total_length);
}
}
void parsetree_init()
{
parsedata.total_length = 0;
parsedata.total_length = 0;
}
size_t parsetree_length()
{
return parsedata.total_length;
return parsedata.total_length;
}
#if 0
@ -129,216 +132,213 @@ char* parsetree_string(const char* string)
extern size_t yyleng;
extern size_t prev_yyleng;
char* parsetree_malloc(size_t s)
char *parsetree_malloc(size_t s)
{
parsedata.total_length += s;
return (char*)parsetree_allocator.Alloc(s);
parsedata.total_length += s;
return (char *)parsetree_allocator.Alloc(s);
}
sval_u append_lists(sval_u val1, sval_u val2)
{
val1.node[1].node[1] = val2.node[0];
val1.node[1] = val2.node[1];
val1.node[1].node[1] = val2.node[0];
val1.node[1] = val2.node[1];
return val1;
return val1;
}
sval_u append_node(sval_u val1, sval_u val2)
{
sval_u* node;
sval_u *node;
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
node[1].node = NULL;
node[0] = val2;
node[1].node = NULL;
node[0] = val2;
val1.node[1].node[1].node = node;
val1.node[1].node = node;
val1.node[1].node[1].node = node;
val1.node[1].node = node;
return val1;
return val1;
}
sval_u prepend_node(sval_u val1, sval_u val2)
{
sval_u* node;
sval_u *node;
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
node[0] = val1;
node[1] = val2;
node[0] = val1;
node[1] = val2;
val2.node = node;
val2.node = node;
return val2;
return val2;
}
sval_u linked_list_end(sval_u val)
{
sval_u* node;
sval_u end;
sval_u *node;
sval_u end;
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
node[0] = val;
node[1].node = NULL;
node[0] = val;
node[1].node = NULL;
end.node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
end.node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
end.node[0].node = node;
end.node[1].node = node;
end.node[0].node = node;
end.node[1].node = node;
return end;
return end;
}
sval_u node1_(int val1)
{
sval_u val;
sval_u val;
val.intValue = val1;
val.intValue = val1;
return val;
return val;
}
sval_u node1b(int val1)
{
sval_u val;
sval_u val;
val.byteValue = val1;
val.byteValue = val1;
return val;
return val;
}
sval_u node_pos(unsigned int pos)
{
sval_u val;
sval_u val;
val.sourcePosValue = pos;
val.sourcePosValue = pos;
return val;
return val;
}
sval_u node_string(char* text)
sval_u node_string(char *text)
{
sval_u val;
sval_u val;
val.stringValue = text;
val.stringValue = text;
return val;
return val;
}
sval_u node0(int type)
{
sval_u val;
sval_u val;
if (type == sval_none)
{
// memory optimization
val.node = &node_none;
}
else
{
val.node = (sval_u*)parsetree_malloc(sizeof(sval_u));
if (type == sval_none) {
// memory optimization
val.node = &node_none;
} else {
val.node = (sval_u *)parsetree_malloc(sizeof(sval_u));
val.node[0].node = NULL;
val.node[0].type = type;
}
val.node[0].node = NULL;
val.node[0].type = type;
}
return val;
return val;
}
sval_u node1(int type, sval_u val1)
{
sval_u val;
sval_u val;
val.node = (sval_u*)parsetree_malloc(sizeof(sval_u[2]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_u[2]));
val.node[0].type = type;
val.node[1] = val1;
val.node[0].type = type;
val.node[1] = val1;
return val;
return val;
}
sval_u node2(int type, sval_u val1, sval_u val2)
{
sval_u val;
sval_u val;
assert(type != sval_none);
assert(type != sval_none);
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[3]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[3]));
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
return val;
return val;
}
sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3)
{
sval_u val;
sval_u val;
assert(type != sval_none);
assert(type != sval_none);
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[4]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[4]));
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
return val;
return val;
}
sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4)
{
sval_u val;
sval_u val;
assert(type != sval_none);
assert(type != sval_none);
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[5]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[5]));
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
return val;
return val;
}
sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5)
{
sval_u val;
sval_u val;
assert(type != sval_none);
assert(type != sval_none);
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[6]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[6]));
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
val.node[5] = val5;
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
val.node[5] = val5;
return val;
return val;
}
sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6)
{
sval_u val;
sval_u val;
assert(type != sval_none);
assert(type != sval_none);
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[7]));
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[7]));
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
val.node[5] = val5;
val.node[6] = val6;
val.node[0].type = type;
val.node[1] = val1;
val.node[2] = val2;
val.node[3] = val3;
val.node[4] = val4;
val.node[5] = val5;
val.node[6] = val6;
return val;
return val;
}