Switch to relying on string_push and string_push_copy everywhere

master
Allen Webster 2018-11-29 12:55:53 -08:00
parent 89516d827b
commit 4db6beddd0
8 changed files with 37 additions and 87 deletions

View File

@ -1623,7 +1623,7 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c
// Values
Temp_Memory temp2 = begin_temp_memory(scratch);
String space = push_string(scratch, partition_remaining(scratch));
String space = string_push(scratch, partition_remaining(scratch));
{
config_feedback_string(&space, "user_name", config->user_name);

View File

@ -1320,40 +1320,6 @@ dump_file_search_up_path(Partition *arena, String path, String file_name){
return(result);
}
static String
push_string(Partition *arena, int32_t cap){
char *mem = push_array(arena, char, cap);
String result = {};
if (mem != 0){
result = make_string_cap(mem, 0, cap);
}
return(result);
}
static String
push_string_copy(Partition *arena, String str){
String result = {};
if (str.str != 0){
result = push_string(arena, str.size + 1);
push_align(arena, 8);
if (result.str != 0){
copy(&result, str);
terminate_with_null(&result);
}
}
return(result);
}
static String
push_string_copy(Partition *arena, char *str, int32_t size){
return(push_string_copy(arena, make_string(str, size)));
}
static String
push_string_copy(Partition *arena, char *str){
return(push_string_copy(arena, make_string_slowly(str)));
}
static void
sort_pairs_by_key__quick(Sort_Pair_i32 *pairs, int32_t first, int32_t one_past_last){
int32_t dif = one_past_last - first;

View File

@ -556,7 +556,7 @@ generate_hot_directory_file_list(Application_Links *app, Partition *arena, Liste
info < one_past_last;
info += 1){
if (info->folder) continue;
String file_name = push_string_copy(arena, make_string(info->filename, info->filename_len));
String file_name = string_push_copy(arena, make_string(info->filename, info->filename_len));
char *is_loaded = "";
char *status_flag = "";

View File

@ -17,7 +17,7 @@ get_pattern_array_from_cstring_array(Partition *arena, CString_Array list){
array.count = count;
for (int32_t i = 0; i < count; ++i){
String base_str = make_string_slowly(list.strings[i]);
String str = push_string(arena, base_str.size + 3);
String str = string_push(arena, base_str.size + 3);
append(&str, "*.");
append(&str, base_str);
terminate_with_null(&str);
@ -259,18 +259,18 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config
Config_Compound *compound = 0;
if (config_compound_var(parsed, fkey_command_name, j, &compound)){
command->name = push_string(arena, 4);
command->name = string_push(arena, 4);
append_int_to_str(&command->name, j);
terminate_with_null(&command->name);
String cmd = {};
if (config_compound_string_member(parsed, compound, "cmd", 0, &cmd)){
command->cmd = push_string_copy(arena, cmd);
command->cmd = string_push_copy(arena, cmd);
}
String out = {};
if (config_compound_string_member(parsed, compound, "out", 1, &out)){
command->out = push_string_copy(arena, out);
command->out = string_push_copy(arena, out);
}
bool32 footer_panel = false;
@ -284,7 +284,7 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config
}
}
else{
command->name = push_string(arena, 4);
command->name = string_push(arena, 4);
append_int_to_str(&command->name, j);
terminate_with_null(&command->name);
}
@ -309,7 +309,7 @@ parse_project__extract_pattern_array(Partition *arena, Config *parsed,
for (Config_Get_Result_Node *node = list.first;
node != 0;
node = node->next, i += 1){
String str = push_string_copy(arena, node->result.string);
String str = string_push_copy(arena, node->result.string);
get_absolutes(str, &array_out->patterns[i].absolutes, false, false);
}
}
@ -337,7 +337,7 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config
// Set new project directory
{
int32_t cap = root_dir.size + 1;
project->dir = push_string(arena, cap);
project->dir = string_push(arena, cap);
copy(&project->dir, root_dir);
terminate_with_null(&project->dir);
}
@ -346,7 +346,7 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config
{
String str = {};
if (config_string_var(parsed, "project_name", 0, &str)){
project->name = push_string_copy(arena, str);
project->name = string_push_copy(arena, str);
}
else{
project->name = make_lit_string("");
@ -413,7 +413,7 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config
String str = {};
if (config_compound_string_member(parsed, src, "path", 0, &str)){
dst->path = push_string_copy(arena, str);
dst->path = string_push_copy(arena, str);
}
config_compound_bool_member(parsed, src, "recursive", 1, &dst->recursive);
@ -513,9 +513,9 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config
config_compound_bool_member(parsed, src, "cursor_at_end", 5,
&cursor_at_end);
dst->name = push_string_copy(arena, name);
dst->cmd = push_string_copy(arena, cmd_str);
dst->out = push_string_copy(arena, out);
dst->name = string_push_copy(arena, name);
dst->cmd = string_push_copy(arena, cmd_str);
dst->out = string_push_copy(arena, out);
dst->footer_panel = footer_panel;
dst->save_dirty_files = save_dirty_files;
dst->cursor_at_end = cursor_at_end;
@ -652,7 +652,7 @@ project_deep_copy__pattern_array(Partition *arena, Project_File_Pattern_Array *s
int32_t abs_count = src->absolutes.count;
dst->absolutes.count = abs_count;
for (int32_t j = 0; j < abs_count; ++j){
dst->absolutes.a[j] = push_string_copy(arena, src->absolutes.a[j]);
dst->absolutes.a[j] = string_push_copy(arena, src->absolutes.a[j]);
if (dst->absolutes.a[j].str == 0){
return(false);
}
@ -666,12 +666,12 @@ static Project
project_deep_copy__inner(Partition *arena, Project *project){
Project result = {};
result.dir = push_string_copy(arena, project->dir);
result.dir = string_push_copy(arena, project->dir);
if (result.dir.str == 0){
return(result);
}
result.name = push_string_copy(arena, project->name);
result.name = string_push_copy(arena, project->name);
if (result.name.str == 0){
return(result);
}
@ -694,7 +694,7 @@ project_deep_copy__inner(Partition *arena, Project *project){
Project_File_Load_Path *dst = result.load_path_array.paths;
Project_File_Load_Path *src = project->load_path_array.paths;
for (int32_t i = 0; i < path_count; ++i, ++dst, ++src){
dst->path = push_string_copy(arena, src->path);
dst->path = string_push_copy(arena, src->path);
if (dst->path.str == 0){
return(result);
}
@ -716,19 +716,19 @@ project_deep_copy__inner(Partition *arena, Project *project){
for (int32_t i = 0; i < command_count; ++i, ++dst, ++src){
memset(dst, 0, sizeof(*dst));
if (src->name.str != 0){
dst->name = push_string_copy(arena, src->name);
dst->name = string_push_copy(arena, src->name);
if (dst->name.str == 0){
return(result);
}
}
if (src->cmd.str != 0){
dst->cmd = push_string_copy(arena, src->cmd);
dst->cmd = string_push_copy(arena, src->cmd);
if (dst->cmd.str == 0){
return(result);
}
}
if (src->out.str != 0){
dst->out = push_string_copy(arena, src->out);
dst->out = string_push_copy(arena, src->out);
if (dst->out.str == 0){
return(result);
}
@ -922,7 +922,7 @@ set_current_project(Application_Links *app, Partition *scratch, Project *project
}
else{
Temp_Memory temp2 = begin_temp_memory(scratch);
String space = push_string(scratch, partition_remaining(scratch));
String space = string_push(scratch, partition_remaining(scratch));
{
config_feedback_string(&space, "'root_directory'", project->dir);
@ -1218,9 +1218,9 @@ project_generate_bat_script(Partition *scratch, String opts, String compiler,
Temp_Memory temp = begin_temp_memory(scratch);
String cf = push_string_copy(scratch, code_file);
String od = push_string_copy(scratch, output_dir);
String bf = push_string_copy(scratch, binary_file);
String cf = string_push_copy(scratch, code_file);
String od = string_push_copy(scratch, output_dir);
String bf = string_push_copy(scratch, binary_file);
replace_char(&cf, '/', '\\');
replace_char(&od, '/', '\\');
@ -1309,8 +1309,8 @@ project_generate_project_4coder_file(Partition *scratch,
String od = output_dir;
String bf = binary_file;
String od_win = push_string(scratch, od.size*2);
String bf_win = push_string(scratch, bf.size*2);
String od_win = string_push(scratch, od.size*2);
String bf_win = string_push(scratch, bf.size*2);
append(&od_win, od);
append(&bf_win, bf);
@ -1539,8 +1539,8 @@ CUSTOM_DOC("Open a lister of all commands in the currently loaded project.")
int32_t option_count = current_project.command_array.count;
Lister_Option *options = push_array(arena, Lister_Option, option_count);
for (int32_t i = 0; i < current_project.command_array.count; i += 1){
String string = push_string_copy(arena, current_project.command_array.commands[i].name);
String status = push_string_copy(arena, current_project.command_array.commands[i].cmd);
String string = string_push_copy(arena, current_project.command_array.commands[i].name);
String status = string_push_copy(arena, current_project.command_array.commands[i].cmd);
options[i].string = string.str;
options[i].status = status.str;
options[i].user_data = IntAsPtr(i);

View File

@ -451,7 +451,7 @@ lister_add_item(Partition *arena, Lister *lister,
void *user_data, int32_t extra_space){
return(lister_add_item(arena, lister,
string,
lister_prealloced(push_string_copy(arena, status)),
lister_prealloced(string_push_copy(arena, status)),
user_data, extra_space));
}
@ -460,7 +460,7 @@ lister_add_item(Partition *arena, Lister *lister,
String string, Lister_Prealloced_String status,
void *user_data, int32_t extra_space){
return(lister_add_item(arena, lister,
lister_prealloced(push_string_copy(arena, string)),
lister_prealloced(string_push_copy(arena, string)),
status,
user_data, extra_space));
}
@ -470,8 +470,8 @@ lister_add_item(Partition *arena, Lister *lister,
String string, String status,
void *user_data, int32_t extra_space){
return(lister_add_item(arena, lister,
lister_prealloced(push_string_copy(arena, string)),
lister_prealloced(push_string_copy(arena, status)),
lister_prealloced(string_push_copy(arena, string)),
lister_prealloced(string_push_copy(arena, status)),
user_data, extra_space));
}
@ -496,7 +496,7 @@ lister_add_ui_item(Partition *arena, Lister *lister,
String string, int32_t index,
void *user_data, int32_t extra_space){
return(lister_add_ui_item(arena, lister,
lister_prealloced(push_string_copy(arena, string)),
lister_prealloced(string_push_copy(arena, string)),
index,
user_data, extra_space));
}

View File

@ -185,11 +185,6 @@ set_token(Parse_Context *context, Cpp_Token *token){
return(result);
}
internal String
str_alloc(Partition *part, i32 cap){
return(make_string_cap(push_array(part, char, cap), 0, cap));
}
internal Item_Set
allocate_item_set(Partition *part, i32 count){
Item_Set item_set = {};

View File

@ -73,18 +73,18 @@ generate_custom_headers(Partition *part){
String *macro = &func_4ed_names.names[i].macro;
String *public_name = &func_4ed_names.names[i].public_name;
*macro = str_alloc(part, name_string.size+4);
*macro = string_push(part, name_string.size + 4);
to_upper(macro, name_string);
append(macro, make_lit_string("_SIG"));
*public_name = str_alloc(part, name_string.size);
*public_name = string_push(part, name_string.size);
to_lower(public_name, name_string);
push_align(part, 8);
}
// NOTE(allen): Output
String out = str_alloc(part, 10 << 20);
String out = string_push(part, 10 << 20);
// NOTE(allen): Custom API headers
append(&out, "struct Application_Links;\n");

View File

@ -1,11 +0,0 @@
@echo off
pushd ..\4coder-non-source\test_data
set run_path=%cd%\sample_files
set data_path=%cd%\input_data
popd
pushd ..\build
set build=%cd%
popd
pushd %run_path%
%build%\4ed -T %data_path%\test_load_rome_txt.4id
popd