mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-07 08:08:48 +00:00
command_line, markup, profiling...
This commit is contained in:
Vendored
+2
-1
@@ -44,7 +44,8 @@
|
|||||||
"intrin.h": "c",
|
"intrin.h": "c",
|
||||||
"stddef.h": "c",
|
"stddef.h": "c",
|
||||||
"wmmintrin.h": "c",
|
"wmmintrin.h": "c",
|
||||||
"thread": "c"
|
"thread": "c",
|
||||||
|
"cmath": "c"
|
||||||
},
|
},
|
||||||
"workbench.colorCustomizations": {
|
"workbench.colorCustomizations": {
|
||||||
"activityBar.activeBackground": "#713fb8",
|
"activityBar.activeBackground": "#713fb8",
|
||||||
|
|||||||
+262
-198
@@ -8,22 +8,11 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ NOTE(rjf): Command Line Option Parsing
|
//~ NOTE(rjf): Command Line Option Parsing
|
||||||
|
|
||||||
internal U64
|
|
||||||
cmd_line_hash_from_string(String8 string)
|
|
||||||
{
|
|
||||||
U64 result = 5381;
|
|
||||||
for(U64 i = 0; i < string.size; i += 1)
|
|
||||||
{
|
|
||||||
result = ((result << 5) + result) + string.str[i];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal CmdLineOpt **
|
CmdLineOpt**
|
||||||
cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
|
cmd_line_slot_from_string(CmdLine* cmd_line, String8 string) {
|
||||||
{
|
CmdLineOpt** slot = 0;
|
||||||
CmdLineOpt **slot = 0;
|
if (cmd_line->option_table_size != 0)
|
||||||
if(cmd_line->option_table_size != 0)
|
|
||||||
{
|
{
|
||||||
U64 hash = cmd_line_hash_from_string(string);
|
U64 hash = cmd_line_hash_from_string(string);
|
||||||
U64 bucket = hash % cmd_line->option_table_size;
|
U64 bucket = hash % cmd_line->option_table_size;
|
||||||
@@ -32,14 +21,12 @@ cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal CmdLineOpt *
|
CmdLineOpt*
|
||||||
cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string)
|
cmd_line_opt_from_slot(CmdLineOpt** slot, String8 string) {
|
||||||
{
|
CmdLineOpt* result = 0;
|
||||||
CmdLineOpt *result = 0;
|
for (CmdLineOpt* var = *slot; var; var = var->hash_next)
|
||||||
for(CmdLineOpt *var = *slot; var; var = var->hash_next)
|
|
||||||
{
|
{
|
||||||
if(str8_match(string, var->string, 0))
|
if (str8_match(string, var->string, 0)) {
|
||||||
{
|
|
||||||
result = var;
|
result = var;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -47,190 +34,267 @@ cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
CmdLineOpt*
|
||||||
cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var)
|
cmd_line_insert_opt(Arena* arena, CmdLine* cmd_line, String8 string, String8List values)
|
||||||
{
|
{
|
||||||
SLLQueuePush(list->first, list->last, var);
|
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||||
list->count += 1;
|
CmdLineOpt *var = 0;
|
||||||
|
CmdLineOpt **slot = cmd_line_slot_from_string(cmd_line, string);
|
||||||
|
CmdLineOpt *existing_var = cmd_line_opt_from_slot(slot, string);
|
||||||
|
if(existing_var != 0)
|
||||||
|
{
|
||||||
|
var = existing_var;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var = push_array(arena, CmdLineOpt, 1);
|
||||||
|
var->hash_next = *slot;
|
||||||
|
var->hash = cmd_line_hash_from_string(string);
|
||||||
|
var->string = push_str8_copy(arena, string);
|
||||||
|
var->value_strings = values;
|
||||||
|
|
||||||
|
StringJoin join = {0};
|
||||||
|
join.pre = str8_lit("");
|
||||||
|
join.sep = str8_lit(",");
|
||||||
|
join.post = str8_lit("");
|
||||||
|
var->value_string = str8_list_join(arena, &var->value_strings, &join);
|
||||||
|
*slot = var;
|
||||||
|
cmd_line_push_opt(&cmd_line->options, var);
|
||||||
|
}
|
||||||
|
return var;
|
||||||
|
#else
|
||||||
|
return cmd_line_insert_opt_alloc(arena_allocator(arena), cmd_line, string, values);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
internal CmdLineOpt *
|
CmdLineOpt*
|
||||||
cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List values)
|
cmd_line_insert_opt_alloc(AllocatorInfo ainfo, CmdLine* cmd_line, String8 string, String8List values)
|
||||||
{
|
{
|
||||||
CmdLineOpt *var = 0;
|
CmdLineOpt *var = 0;
|
||||||
CmdLineOpt **slot = cmd_line_slot_from_string(cmd_line, string);
|
CmdLineOpt **slot = cmd_line_slot_from_string(cmd_line, string);
|
||||||
CmdLineOpt *existing_var = cmd_line_opt_from_slot(slot, string);
|
CmdLineOpt *existing_var = cmd_line_opt_from_slot(slot, string);
|
||||||
if(existing_var != 0)
|
if(existing_var != 0)
|
||||||
{
|
{
|
||||||
var = existing_var;
|
var = existing_var;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var = push_array(arena, CmdLineOpt, 1);
|
var = alloc_array(ainfo, CmdLineOpt, 1);
|
||||||
var->hash_next = *slot;
|
var->hash_next = *slot;
|
||||||
var->hash = cmd_line_hash_from_string(string);
|
var->hash = cmd_line_hash_from_string(string);
|
||||||
var->string = push_str8_copy(arena, string);
|
var->string = str8_copy(ainfo, string);
|
||||||
var->value_strings = values;
|
var->value_strings = values;
|
||||||
StringJoin join = {0};
|
|
||||||
join.pre = str8_lit("");
|
StringJoin join = {0};
|
||||||
join.sep = str8_lit(",");
|
join.pre = str8_lit("");
|
||||||
join.post = str8_lit("");
|
join.sep = str8_lit(",");
|
||||||
var->value_string = str8_list_join(arena, &var->value_strings, &join);
|
join.post = str8_lit("");
|
||||||
*slot = var;
|
|
||||||
cmd_line_push_opt(&cmd_line->options, var);
|
var->value_string = str8_list_join_alloc(ainfo, &var->value_strings, &join);
|
||||||
}
|
*slot = var;
|
||||||
return var;
|
cmd_line_push_opt(&cmd_line->options, var);
|
||||||
|
}
|
||||||
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal CmdLine
|
CmdLine
|
||||||
cmd_line_from_string_list(Arena *arena, String8List command_line)
|
cmd_line_from_string_list(Arena* arena, String8List command_line)
|
||||||
{
|
{
|
||||||
CmdLine parsed = {0};
|
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||||
parsed.exe_name = command_line.first->string;
|
CmdLine parsed = {0};
|
||||||
|
parsed.exe_name = command_line.first->string;
|
||||||
// NOTE(rjf): Set up config option table.
|
|
||||||
{
|
// NOTE(rjf): Set up config option table.
|
||||||
parsed.option_table_size = 4096;
|
{
|
||||||
parsed.option_table = push_array(arena, CmdLineOpt *, parsed.option_table_size);
|
parsed.option_table_size = 4096;
|
||||||
}
|
parsed.option_table = push_array(arena, CmdLineOpt*, parsed.option_table_size);
|
||||||
|
}
|
||||||
// NOTE(rjf): Parse command line.
|
|
||||||
B32 after_passthrough_option = 0;
|
// NOTE(rjf): Parse command line.
|
||||||
B32 first_passthrough = 1;
|
B32 after_passthrough_option = 0;
|
||||||
for(String8Node *node = command_line.first->next, *next = 0; node != 0; node = next)
|
B32 first_passthrough = 1;
|
||||||
{
|
for (String8Node* node = command_line.first->next, *next = 0; node != 0; node = next)
|
||||||
next = node->next;
|
{
|
||||||
String8 option_name = node->string;
|
next = node->next;
|
||||||
|
String8 option_name = node->string;
|
||||||
// NOTE(rjf): Look at -- or - at the start of an argument to determine if it's
|
|
||||||
// a flag option. All arguments after a single "--" (with no trailing string
|
// NOTE(rjf): Look at -- or - at the start of an argument to determine if it's
|
||||||
// on the command line will be considered as input files.
|
// a flag option. All arguments after a single "--" (with no trailing string
|
||||||
B32 is_option = 1;
|
// on the command line will be considered as input files.
|
||||||
if(after_passthrough_option == 0)
|
B32 is_option = 1;
|
||||||
{
|
if(after_passthrough_option == 0)
|
||||||
if(str8_match(node->string, str8_lit("--"), 0))
|
{
|
||||||
{
|
if (str8_match(node->string, str8_lit("--"), 0)) {
|
||||||
after_passthrough_option = 1;
|
after_passthrough_option = 1;
|
||||||
is_option = 0;
|
is_option = 0;
|
||||||
}
|
}
|
||||||
else if(str8_match(str8_prefix(node->string, 2), str8_lit("--"), 0))
|
else if (str8_match(str8_prefix(node->string, 2), str8_lit("--"), 0)) {
|
||||||
{
|
option_name = str8_skip(option_name, 2);
|
||||||
option_name = str8_skip(option_name, 2);
|
}
|
||||||
}
|
else if (str8_match(str8_prefix(node->string, 1), str8_lit("-"), 0)) {
|
||||||
else if(str8_match(str8_prefix(node->string, 1), str8_lit("-"), 0))
|
option_name = str8_skip(option_name, 1);
|
||||||
{
|
}
|
||||||
option_name = str8_skip(option_name, 1);
|
else {
|
||||||
}
|
is_option = 0;
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
is_option = 0;
|
else
|
||||||
}
|
{
|
||||||
}
|
is_option = 0;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
is_option = 0;
|
// NOTE(rjf): This string is an option.
|
||||||
}
|
if(is_option)
|
||||||
|
{
|
||||||
// NOTE(rjf): This string is an option.
|
B32 has_arguments = 0;
|
||||||
if(is_option)
|
U64 arg_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
|
||||||
{
|
U64 arg_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
|
||||||
B32 has_arguments = 0;
|
U64 arg_signifier_position = min(arg_signifier_position1, arg_signifier_position2);
|
||||||
U64 arg_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
|
String8 arg_portion_this_string = str8_skip(option_name, arg_signifier_position+1);
|
||||||
U64 arg_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
|
if (arg_signifier_position < option_name.size) {
|
||||||
U64 arg_signifier_position = Min(arg_signifier_position1, arg_signifier_position2);
|
has_arguments = 1;
|
||||||
String8 arg_portion_this_string = str8_skip(option_name, arg_signifier_position+1);
|
}
|
||||||
if(arg_signifier_position < option_name.size)
|
option_name = str8_prefix(option_name, arg_signifier_position);
|
||||||
{
|
|
||||||
has_arguments = 1;
|
String8List arguments = {0};
|
||||||
}
|
|
||||||
option_name = str8_prefix(option_name, arg_signifier_position);
|
// NOTE(rjf): Parse arguments.
|
||||||
|
if (has_arguments)
|
||||||
String8List arguments = {0};
|
{
|
||||||
|
for (String8Node* n = node; n; n = n->next)
|
||||||
// NOTE(rjf): Parse arguments.
|
{
|
||||||
if(has_arguments)
|
next = n->next;
|
||||||
{
|
|
||||||
for(String8Node *n = node; n; n = n->next)
|
String8 string = n->string;
|
||||||
{
|
if (n == node) {
|
||||||
next = n->next;
|
string = arg_portion_this_string;
|
||||||
|
}
|
||||||
String8 string = n->string;
|
|
||||||
if(n == node)
|
U8 splits[] = { ',' };
|
||||||
{
|
String8List args_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
|
||||||
string = arg_portion_this_string;
|
for (String8Node* sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) {
|
||||||
}
|
str8_list_push(arena, &arguments, sub_arg->string);
|
||||||
|
}
|
||||||
U8 splits[] = { ',' };
|
if ( !str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) && (n != node || arg_portion_this_string.size != 0)) {
|
||||||
String8List args_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
|
break;
|
||||||
for(String8Node *sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next)
|
}
|
||||||
{
|
}
|
||||||
str8_list_push(arena, &arguments, sub_arg->string);
|
}
|
||||||
}
|
|
||||||
if(!str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) &&
|
// NOTE(rjf): Register config variable.
|
||||||
(n != node || arg_portion_this_string.size != 0))
|
cmd_line_insert_opt(arena, &parsed, option_name, arguments);
|
||||||
{
|
}
|
||||||
break;
|
|
||||||
}
|
// NOTE(rjf): Default path, treat as a passthrough config option to be
|
||||||
}
|
// handled by tool-specific code.
|
||||||
}
|
else if ( !str8_match(node->string, str8_lit("--"), 0) || !first_passthrough) {
|
||||||
|
str8_list_push(arena, &parsed.inputs, node->string);
|
||||||
// NOTE(rjf): Register config variable.
|
after_passthrough_option = 1;
|
||||||
cmd_line_insert_opt(arena, &parsed, option_name, arguments);
|
first_passthrough = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// NOTE(rjf): Default path, treat as a passthrough config option to be
|
|
||||||
// handled by tool-specific code.
|
return parsed;
|
||||||
else if(!str8_match(node->string, str8_lit("--"), 0) || !first_passthrough)
|
#else
|
||||||
{
|
return cmd_line_from_string_list_alloc(arena_allocator(arena), command_line);
|
||||||
str8_list_push(arena, &parsed.inputs, node->string);
|
#endif
|
||||||
after_passthrough_option = 1;
|
|
||||||
first_passthrough = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal CmdLineOpt *
|
CmdLine
|
||||||
cmd_line_opt_from_string(CmdLine *cmd_line, String8 name)
|
cmd_line_from_string_list_alloc(AllocatorInfo ainfo, String8List command_line)
|
||||||
{
|
{
|
||||||
return cmd_line_opt_from_slot(cmd_line_slot_from_string(cmd_line, name), name);
|
CmdLine parsed = {0};
|
||||||
}
|
parsed.exe_name = command_line.first->string;
|
||||||
|
|
||||||
internal String8List
|
// NOTE(rjf): Set up config option table.
|
||||||
cmd_line_strings(CmdLine *cmd_line, String8 name)
|
{
|
||||||
{
|
parsed.option_table_size = 4096;
|
||||||
String8List result = {0};
|
parsed.option_table = alloc_array(ainfo, CmdLineOpt*, parsed.option_table_size);
|
||||||
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
|
}
|
||||||
if(var != 0)
|
|
||||||
{
|
// NOTE(rjf): Parse command line.
|
||||||
result = var->value_strings;
|
B32 after_passthrough_option = 0;
|
||||||
}
|
B32 first_passthrough = 1;
|
||||||
return result;
|
for (String8Node* node = command_line.first->next, *next = 0; node != 0; node = next)
|
||||||
}
|
{
|
||||||
|
next = node->next;
|
||||||
internal String8
|
String8 option_name = node->string;
|
||||||
cmd_line_string(CmdLine *cmd_line, String8 name)
|
|
||||||
{
|
// NOTE(rjf): Look at -- or - at the start of an argument to determine if it's
|
||||||
String8 result = {0};
|
// a flag option. All arguments after a single "--" (with no trailing string
|
||||||
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
|
// on the command line will be considered as input files.
|
||||||
if(var != 0)
|
B32 is_option = 1;
|
||||||
{
|
if(after_passthrough_option == 0)
|
||||||
result = var->value_string;
|
{
|
||||||
}
|
if (str8_match(node->string, str8_lit("--"), 0)) {
|
||||||
return result;
|
after_passthrough_option = 1;
|
||||||
}
|
is_option = 0;
|
||||||
|
}
|
||||||
internal B32
|
else if (str8_match(str8_prefix(node->string, 2), str8_lit("--"), 0)) {
|
||||||
cmd_line_has_flag(CmdLine *cmd_line, String8 name)
|
option_name = str8_skip(option_name, 2);
|
||||||
{
|
}
|
||||||
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
|
else if (str8_match(str8_prefix(node->string, 1), str8_lit("-"), 0)) {
|
||||||
return(var != 0);
|
option_name = str8_skip(option_name, 1);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
internal B32
|
is_option = 0;
|
||||||
cmd_line_has_argument(CmdLine *cmd_line, String8 name)
|
}
|
||||||
{
|
}
|
||||||
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
|
else
|
||||||
return(var != 0 && var->value_strings.node_count > 0);
|
{
|
||||||
|
is_option = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(rjf): This string is an option.
|
||||||
|
if(is_option)
|
||||||
|
{
|
||||||
|
B32 has_arguments = 0;
|
||||||
|
U64 arg_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
|
||||||
|
U64 arg_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
|
||||||
|
U64 arg_signifier_position = min(arg_signifier_position1, arg_signifier_position2);
|
||||||
|
String8 arg_portion_this_string = str8_skip(option_name, arg_signifier_position+1);
|
||||||
|
if (arg_signifier_position < option_name.size) {
|
||||||
|
has_arguments = 1;
|
||||||
|
}
|
||||||
|
option_name = str8_prefix(option_name, arg_signifier_position);
|
||||||
|
|
||||||
|
String8List arguments = {0};
|
||||||
|
|
||||||
|
// NOTE(rjf): Parse arguments.
|
||||||
|
if (has_arguments)
|
||||||
|
{
|
||||||
|
for (String8Node* n = node; n; n = n->next)
|
||||||
|
{
|
||||||
|
next = n->next;
|
||||||
|
|
||||||
|
String8 string = n->string;
|
||||||
|
if (n == node) {
|
||||||
|
string = arg_portion_this_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
U8 splits[] = { ',' };
|
||||||
|
String8List args_in_this_string = str8_split_alloc(ainfo, string, splits, ArrayCount(splits), 0);
|
||||||
|
for (String8Node* sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) {
|
||||||
|
str8_list_alloc(ainfo, &arguments, sub_arg->string);
|
||||||
|
}
|
||||||
|
if ( !str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) && (n != node || arg_portion_this_string.size != 0)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(rjf): Register config variable.
|
||||||
|
cmd_line_insert_opt_alloc(ainfo, &parsed, option_name, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(rjf): Default path, treat as a passthrough config option to be
|
||||||
|
// handled by tool-specific code.
|
||||||
|
else if ( !str8_match(node->string, str8_lit("--"), 0) || !first_passthrough) {
|
||||||
|
str8_list_alloc(ainfo, &parsed.inputs, node->string);
|
||||||
|
after_passthrough_option = 1;
|
||||||
|
first_passthrough = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-25
@@ -12,43 +12,78 @@
|
|||||||
typedef struct CmdLineOpt CmdLineOpt;
|
typedef struct CmdLineOpt CmdLineOpt;
|
||||||
struct CmdLineOpt
|
struct CmdLineOpt
|
||||||
{
|
{
|
||||||
CmdLineOpt* next;
|
CmdLineOpt* next;
|
||||||
CmdLineOpt* hash_next;
|
CmdLineOpt* hash_next;
|
||||||
U64 hash;
|
U64 hash;
|
||||||
String8 string;
|
String8 string;
|
||||||
String8List value_strings;
|
String8List value_strings;
|
||||||
String8 value_string;
|
String8 value_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct CmdLineOptList CmdLineOptList;
|
typedef struct CmdLineOptList CmdLineOptList;
|
||||||
struct CmdLineOptList
|
struct CmdLineOptList
|
||||||
{
|
{
|
||||||
U64 count;
|
U64 count;
|
||||||
CmdLineOpt* first;
|
CmdLineOpt* first;
|
||||||
CmdLineOpt* last;
|
CmdLineOpt* last;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct CmdLine CmdLine;
|
typedef struct CmdLine CmdLine;
|
||||||
struct CmdLine
|
struct CmdLine
|
||||||
{
|
{
|
||||||
String8 exe_name;
|
String8 exe_name;
|
||||||
CmdLineOptList options;
|
CmdLineOptList options;
|
||||||
String8List inputs;
|
String8List inputs;
|
||||||
U64 option_table_size;
|
U64 option_table_size;
|
||||||
CmdLineOpt** option_table;
|
CmdLineOpt** option_table;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ NOTE(rjf): Command Line Option Parsing
|
//~ NOTE(rjf): Command Line Option Parsing
|
||||||
|
|
||||||
internal U64 cmd_line_hash_from_string(String8 string);
|
U64 cmd_line_hash_from_string(String8 string);
|
||||||
internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string);
|
MD_API CmdLineOpt** cmd_line_slot_from_string(CmdLine* cmd_line, String8 string);
|
||||||
internal CmdLineOpt* cmd_line_opt_from_slot (CmdLineOpt **slot, String8 string);
|
MD_API CmdLineOpt* cmd_line_opt_from_slot (CmdLineOpt** slot, String8 string);
|
||||||
internal void cmd_line_push_opt (CmdLineOptList *list, CmdLineOpt *var);
|
void cmd_line_push_opt (CmdLineOptList* list, CmdLineOpt* var);
|
||||||
internal CmdLineOpt* cmd_line_insert_opt (Arena *arena, CmdLine *cmd_line, String8 string, String8List values);
|
|
||||||
internal CmdLine cmd_line_from_string_list(Arena *arena, String8List arguments);
|
CmdLineOpt* cmd_line_opt_from_string (CmdLine* cmd_line, String8 name);
|
||||||
internal CmdLineOpt* cmd_line_opt_from_string (CmdLine *cmd_line, String8 name);
|
String8List cmd_line_strings (CmdLine* cmd_line, String8 name);
|
||||||
internal String8List cmd_line_strings (CmdLine *cmd_line, String8 name);
|
String8 cmd_line_string (CmdLine* cmd_line, String8 name);
|
||||||
internal String8 cmd_line_string (CmdLine *cmd_line, String8 name);
|
B32 cmd_line_has_flag (CmdLine* cmd_line, String8 name);
|
||||||
internal B32 cmd_line_has_flag (CmdLine *cmd_line, String8 name);
|
B32 cmd_line_has_argument (CmdLine* cmd_line, String8 name);
|
||||||
internal B32 cmd_line_has_argument (CmdLine *cmd_line, String8 name);
|
|
||||||
|
MD_API CmdLineOpt* cmd_line_insert_opt (Arena* arena, CmdLine* cmd_line, String8 string, String8List values);
|
||||||
|
MD_API CmdLineOpt* cmd_line_insert_opt_alloc (AllocatorInfo ainfo, CmdLine* cmd_line, String8 string, String8List values);
|
||||||
|
MD_API CmdLine cmd_line_from_string_list (Arena* arena, String8List arguments);
|
||||||
|
MD_API CmdLine cmd_line_from_string_list_alloc(AllocatorInfo ainfo, String8List arguments);
|
||||||
|
|
||||||
|
inline U64
|
||||||
|
cmd_line_hash_from_string(String8 string) {
|
||||||
|
U64 result = 5381;
|
||||||
|
for(U64 i = 0; i < string.size; i += 1) {
|
||||||
|
result = ((result << 5) + result) + string.str[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CmdLineOpt* cmd_line_opt_from_string(CmdLine *cmd_line, String8 name) { return cmd_line_opt_from_slot(cmd_line_slot_from_string(cmd_line, name), name); }
|
||||||
|
inline B32 cmd_line_has_flag (CmdLine *cmd_line, String8 name) { CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name); return(var != 0); }
|
||||||
|
inline B32 cmd_line_has_argument (CmdLine *cmd_line, String8 name) { CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name); return(var != 0 && var->value_strings.node_count > 0); }
|
||||||
|
|
||||||
|
inline String8List
|
||||||
|
cmd_line_strings(CmdLine *cmd_line, String8 name) {
|
||||||
|
String8List result = {0};
|
||||||
|
CmdLineOpt* var = cmd_line_opt_from_string(cmd_line, name);
|
||||||
|
if (var != 0) { result = var->value_strings; }
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline String8
|
||||||
|
cmd_line_string(CmdLine *cmd_line, String8 name) {
|
||||||
|
String8 result = {0};
|
||||||
|
CmdLineOpt* var = cmd_line_opt_from_string(cmd_line, name);
|
||||||
|
if (var != 0) { result = var->value_string; }
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void cmd_line_push_opt(CmdLineOptList* list, CmdLineOpt* var) { sll_queue_push(list->first, list->last, var); list->count += 1; }
|
||||||
|
|||||||
+5
-17
@@ -1,25 +1,13 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# include "markup.h"
|
# include "markup.h"
|
||||||
|
# include "os/os.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
internal void
|
void
|
||||||
set_thread_name(String8 string)
|
set_thread_name(String8 string) {
|
||||||
{
|
ProfThreadName("%.*s", str8_varg(string));
|
||||||
ProfThreadName("%.*s", str8_varg(string));
|
os_set_thread_name(string);
|
||||||
os_set_thread_name(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
set_thread_namef(char *fmt, ...)
|
|
||||||
{
|
|
||||||
Temp scratch = scratch_begin(0, 0);
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
String8 string = push_str8fv(scratch.arena, fmt, args);
|
|
||||||
set_thread_name(string);
|
|
||||||
va_end(args);
|
|
||||||
scratch_end(scratch);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-4
@@ -7,7 +7,21 @@
|
|||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
internal void set_thread_name(String8 string);
|
MD_API void set_thread_name(String8 string);
|
||||||
internal void set_thread_namef(char *fmt, ...);
|
|
||||||
#define ThreadNameF(...) (set_thread_namef(__VA_ARGS__))
|
inline void
|
||||||
#define ThreadName(str) (set_thread_name(str))
|
set_thread_namef(char *fmt, ...)
|
||||||
|
{
|
||||||
|
TempArena scratch = scratch_begin(0, 0);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
String8 string = push_str8fv(scratch.arena, fmt, args);
|
||||||
|
set_thread_name(string);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
scratch_end(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define thread_namef(...) (set_thread_namef(__VA_ARGS__))
|
||||||
|
#define thraed_name(str) (set_thread_name(str))
|
||||||
|
|||||||
+41
-37
@@ -1,5 +1,6 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
|
# include "macros.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
@@ -9,65 +10,68 @@
|
|||||||
//~ rjf: Zero Settings
|
//~ rjf: Zero Settings
|
||||||
|
|
||||||
#if !defined(PROFILE_TELEMETRY)
|
#if !defined(PROFILE_TELEMETRY)
|
||||||
# define PROFILE_TELEMETRY 0
|
# define PROFILE_TELEMETRY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MARKUP_LAYER_COLOR)
|
#if !defined(MARKUP_LAYER_COLOR)
|
||||||
# define MARKUP_LAYER_COLOR 1.00f, 0.00f, 1.00f
|
# define MARKUP_LAYER_COLOR 1.00f, 0.00f, 1.00f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Third Party Includes
|
//~ rjf: Third Party Includes
|
||||||
|
|
||||||
#if PROFILE_TELEMETRY
|
#if PROFILE_TELEMETRY
|
||||||
# include "rad_tm.h"
|
# include "rad_tm.h"
|
||||||
# if OS_WINDOWS
|
# if OS_WINDOWS
|
||||||
# pragma comment(lib, "rad_tm_win64.lib")
|
# pragma comment(lib, "rad_tm_win64.lib")
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Telemetry Profile Defines
|
//~ rjf: Telemetry Profile Defines
|
||||||
|
|
||||||
#if PROFILE_TELEMETRY
|
#if PROFILE_TELEMETRY
|
||||||
# define ProfBegin(...) tmEnter(0, 0, __VA_ARGS__)
|
# define prof_begin(...) tmEnter(0, 0, __VA_ARGS__)
|
||||||
# define ProfBeginDynamic(...) (TM_API_PTR ? TM_API_PTR->_tmEnterZoneV_Core(0, 0, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
# define prof_begin_dynamic(...) (TM_API_PTR ? TM_API_PTR->_tmEnterZoneV_Core(0, 0, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
||||||
# define ProfEnd(...) (TM_API_PTR ? TM_API_PTR->_tmLeaveZone(0) : (void)0)
|
# define prof_end(...) (TM_API_PTR ? TM_API_PTR->_tmLeaveZone(0) : (void)0)
|
||||||
# define ProfTick(...) tmTick(0)
|
# define prof_tick(...) tmTick(0)
|
||||||
# define ProfIsCapturing(...) tmRunning()
|
# define prof_is_capturing(...) tmRunning()
|
||||||
# define ProfBeginCapture(...) tmOpen(0, __VA_ARGS__, __DATE__, "localhost", TMCT_TCP, TELEMETRY_DEFAULT_PORT, TMOF_INIT_NETWORKING|TMOF_CAPTURE_CONTEXT_SWITCHES, 100)
|
# define prof_begin_capture(...) tmOpen(0, __VA_ARGS__, __DATE__, "localhost", TMCT_TCP, TELEMETRY_DEFAULT_PORT, TMOF_INIT_NETWORKING|TMOF_CAPTURE_CONTEXT_SWITCHES, 100)
|
||||||
# define ProfEndCapture(...) tmClose(0)
|
# define prof_end_capture(...) tmClose(0)
|
||||||
# define ProfThreadName(...) (TM_API_PTR ? TM_API_PTR->_tmThreadName(0, 0, __VA_ARGS__) : (void)0)
|
# define prof_thread_name(...) (TM_API_PTR ? TM_API_PTR->_tmThreadName(0, 0, __VA_ARGS__) : (void)0)
|
||||||
# define ProfMsg(...) (TM_API_PTR ? TM_API_PTR->_tmMessageV_Core(0, TMMF_ICON_NOTE, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
# define prof_msg(...) (TM_API_PTR ? TM_API_PTR->_tmMessageV_Core(0, TMMF_ICON_NOTE, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
|
||||||
# define ProfBeginLockWait(...) tmStartWaitForLock(0, 0, __VA_ARGS__)
|
# define prof_begin_lock_wait(...) tmStartWaitForLock(0, 0, __VA_ARGS__)
|
||||||
# define ProfEndLockWait(...) tmEndWaitForLock(0)
|
# define prof_end_lock_wait(...) tmEndWaitForLock(0)
|
||||||
# define ProfLockTake(...) tmAcquiredLock(0, 0, __VA_ARGS__)
|
# define prof_lock_take(...) tmAcquiredLock(0, 0, __VA_ARGS__)
|
||||||
# define ProfLockDrop(...) tmReleasedLock(0, __VA_ARGS__)
|
# define prof_lock_drop(...) tmReleasedLock(0, __VA_ARGS__)
|
||||||
# define ProfColor(color) tmZoneColorSticky(color)
|
# define prof_color(color) tmZoneColorSticky(color)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO(Ed): Support spall?
|
||||||
|
// TODO(Ed): Support tracey?
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Zeroify Undefined Defines
|
//~ rjf: Zeroify Undefined Defines
|
||||||
|
|
||||||
#if !defined(ProfBegin)
|
#if !defined(prof_begin)
|
||||||
# define ProfBegin(...) (0)
|
# define prof_begin(...) (0)
|
||||||
# define ProfBeginDynamic(...) (0)
|
# define prof_begin_dynamic(...) (0)
|
||||||
# define ProfEnd(...) (0)
|
# define prof_end(...) (0)
|
||||||
# define ProfTick(...) (0)
|
# define prof_tick(...) (0)
|
||||||
# define ProfIsCapturing(...) (0)
|
# define prof_is_capturing(...) (0)
|
||||||
# define ProfBeginCapture(...) (0)
|
# define prof_begin_capture(...) (0)
|
||||||
# define ProfEndCapture(...) (0)
|
# define prof_end_capture(...) (0)
|
||||||
# define ProfThreadName(...) (0)
|
# define prof_thread_name(...) (0)
|
||||||
# define ProfMsg(...) (0)
|
# define prof_msg(...) (0)
|
||||||
# define ProfBeginLockWait(...) (0)
|
# define prof_end_lock_wait(...) (0)
|
||||||
# define ProfEndLockWait(...) (0)
|
# define prof_end_lock_wait(...) (0)
|
||||||
# define ProfLockTake(...) (0)
|
# define prof_lock_take(...) (0)
|
||||||
# define ProfLockDrop(...) (0)
|
# define prof_lock_drop(...) (0)
|
||||||
# define ProfColor(...) (0)
|
# define prof_color(...) (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Helper Wrappers
|
//~ rjf: Helper Wrappers
|
||||||
|
|
||||||
#define ProfBeginFunction(...) ProfBegin(this_function_name)
|
#define prof_begin_function(...) prof_begin(this_function_name)
|
||||||
#define ProfScope(...) DeferLoop(ProfBeginDynamic(__VA_ARGS__), ProfEnd())
|
#define prof_scope(...) defer_loop(prof_begin_dynamic(__VA_ARGS__), ProfEnd())
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "base/linkage.h"
|
#include "base/linkage.h"
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/generic_macros.h"
|
#include "base/generic_macros.h"
|
||||||
|
#include "base/profiling.h"
|
||||||
#include "base/namespace.h"
|
#include "base/namespace.h"
|
||||||
|
|
||||||
MD_NS_BEGIN
|
MD_NS_BEGIN
|
||||||
@@ -25,6 +26,8 @@ MD_NS_BEGIN
|
|||||||
#include "base/math.h"
|
#include "base/math.h"
|
||||||
#include "base/toolchain.h"
|
#include "base/toolchain.h"
|
||||||
#include "base/strings.h"
|
#include "base/strings.h"
|
||||||
|
#include "base/command_line.h"
|
||||||
|
#include "base/markup.h"
|
||||||
|
|
||||||
MD_NS_END
|
MD_NS_END
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "context_cracking.h"
|
# include "base/context_cracking.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(OS_FEATURE_GRAPHICAL)
|
#if !defined(OS_FEATURE_GRAPHICAL)
|
||||||
|
|||||||
Reference in New Issue
Block a user