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

@ -2054,6 +2054,7 @@ static int yy_get_next_buffer (void)
#else
static int input (void)
#endif
{
int c;
@ -2241,6 +2242,7 @@ static void yy_load_buffer_state (void)
* such as during a yyrestart() or at EOF.
*/
static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
{
int oerrno = errno;

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;
}

View file

@ -26,121 +26,125 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "str.h"
#if defined ( GAME_DLL )
#define showopcodes g_showopcodes
#elif defined( CGAME_DLL )
#define showopcodes cg_showopcodes
#if defined(GAME_DLL)
# define showopcodes g_showopcodes
#elif defined(CGAME_DLL)
# define showopcodes cg_showopcodes
#else
#define showopcodes g_showopcodes
# define showopcodes g_showopcodes
#endif
typedef enum
{
sval_none,
sval_next,
sval_statement_list,
sval_label,
sval_case,
sval_negative,
sval_assignment,
sval_if,
sval_ifelse,
sval_while,
sval_and,
sval_or,
sval_cmd_method,
sval_cmd_method_ret,
sval_cmd,
sval_cmd_default_ret,
sval_field,
sval_store_method,
sval_store_string,
sval_store_integer,
sval_store_float,
sval_calc_vector,
sval_store_null,
sval_store_nil,
sval_func1,
sval_operation,
sval_not,
sval_array,
sval_constarray,
sval_makearray,
sval_catch,
sval_switch,
sval_break,
sval_continue,
sval_do,
sval_privatelabel,
sval_define
typedef enum {
sval_none,
sval_next,
sval_statement_list,
sval_label,
sval_case,
sval_negative,
sval_assignment,
sval_if,
sval_ifelse,
sval_while,
sval_and,
sval_or,
sval_cmd_method,
sval_cmd_method_ret,
sval_cmd,
sval_cmd_default_ret,
sval_field,
sval_store_method,
sval_store_string,
sval_store_integer,
sval_store_float,
sval_calc_vector,
sval_store_null,
sval_store_nil,
sval_func1,
sval_operation,
sval_not,
sval_array,
sval_constarray,
sval_makearray,
sval_catch,
sval_switch,
sval_break,
sval_continue,
sval_do,
sval_privatelabel,
sval_define
} sval_type_e;
typedef union sval_u {
int type;
char *stringValue;
float floatValue;
int intValue;
char charValue;
unsigned char byteValue;
unsigned char *posValue;
int MaxVarStackOffset;
int HasExternal;
union sval_u *node;
unsigned int sourcePosValue;
int type;
char *stringValue;
float floatValue;
int intValue;
char charValue;
unsigned char byteValue;
unsigned char *posValue;
int MaxVarStackOffset;
int HasExternal;
union sval_u *node;
unsigned int sourcePosValue;
} sval_t;
typedef struct {
sval_t val;
unsigned int sourcePos;
sval_t val;
unsigned int sourcePos;
} stype_t;
void parsetree_freeall();
void parsetree_init();
size_t parsetree_length();
char *parsetree_malloc( size_t s );
void parsetree_freeall();
void parsetree_init();
size_t parsetree_length();
char *parsetree_malloc(size_t s);
sval_u append_lists(sval_u val1, sval_u val2);
sval_u append_node(sval_u val1, sval_u val2);
sval_u prepend_node(sval_u val1, sval_u val2);
sval_u append_lists( sval_u val1, sval_u val2 );
sval_u append_node( sval_u val1, sval_u val2 );
sval_u prepend_node( sval_u val1, sval_u val2 );
sval_u linked_list_end(sval_u val);
sval_u linked_list_end( sval_u val );
sval_u node1_(int val1);
sval_u node1b(int val1);
sval_u node_pos(unsigned int pos);
sval_u node_string(char *text);
sval_u node1_( int val1 );
sval_u node1b( int val1 );
sval_u node_pos( unsigned int pos );
sval_u node_string( char *text );
sval_u node0( int type );
sval_u node1( int type, sval_u val1 );
sval_u node2( int type, sval_u val1, sval_u val2 );
sval_u node3( int type, sval_u val1, sval_u val2, sval_u val3 );
sval_u node4( int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4 );
sval_u node5( int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5 );
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 node0(int type);
sval_u node1(int type, sval_u val1);
sval_u node2(int type, sval_u val1, sval_u val2);
sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3);
sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4);
sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5);
sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6);
struct yyexception {
int yylineno;
str yytext;
str yytoken;
int yylineno;
str yytext;
str yytoken;
yyexception() { yylineno = 0; }
yyexception() { yylineno = 0; }
};
struct yyparsedata {
size_t total_length;
size_t total_length;
int braces_count;
int line_count;
unsigned int pos;
sval_t val;
int braces_count;
int line_count;
unsigned int pos;
sval_t val;
char *sourceBuffer;
class GameScript *gameScript;
char *sourceBuffer;
class GameScript *gameScript;
yyexception exc;
yyexception exc;
yyparsedata() { total_length = 0, braces_count = 0, line_count = 0, pos = 0; val = sval_t(); sourceBuffer = NULL; gameScript = NULL; }
yyparsedata()
{
total_length = 0, braces_count = 0, line_count = 0, pos = 0;
val = sval_t();
sourceBuffer = NULL;
gameScript = NULL;
}
};
extern yyparsedata parsedata;