package script architecture names cleaned up; added code extensions to config file

This commit is contained in:
Allen Webster 2017-02-26 16:44:40 -05:00
parent 18d19fb9fa
commit c4358ab179
6 changed files with 121 additions and 62 deletions

View File

@ -208,6 +208,42 @@ static char *default_extensions[] = {
"cc"
};
struct Extension_List{
char extension_space[256];
char *extensions[94];
int32_t extension_count;
};
static void
set_extensions(Extension_List *extension_list, String src){
int32_t mode = 0;
int32_t j = 0, k = 0;
for (int32_t i = 0; i < src.size; ++i){
switch (mode){
case 0:
{
if (src.str[i] == '.'){
mode = 1;
extension_list->extensions[k++] = &extension_list->extension_space[j];
}
}break;
case 1:
{
if (src.str[i] == '.'){
extension_list->extension_space[j++] = 0;
extension_list->extensions[k++] = &extension_list->extension_space[j];
}
else{
extension_list->extension_space[j++] = src.str[i];
}
}break;
}
}
extension_list->extension_space[j++] = 0;
extension_list->extension_count = k;
}
struct Fkey_Command{
char command[128];
char out[128];
@ -220,10 +256,7 @@ struct Project{
char *dir;
int32_t dir_len;
char extension_space[256];
char *extensions[94];
int32_t extension_count;
Extension_List extension_list;
Fkey_Command fkey_commands[16];
bool32 close_all_code_when_this_project_closes;
@ -232,46 +265,16 @@ struct Project{
bool32 open_recursively;
};
static Project null_project = {};
static Project current_project = {};
static void
set_project_extensions(Project *project, String src){
int32_t mode = 0;
int32_t j = 0, k = 0;
for (int32_t i = 0; i < src.size; ++i){
switch (mode){
case 0:
{
if (src.str[i] == '.'){
mode = 1;
project->extensions[k++] = &project->extension_space[j];
}
}break;
case 1:
{
if (src.str[i] == '.'){
project->extension_space[j++] = 0;
project->extensions[k++] = &project->extension_space[j];
}
else{
project->extension_space[j++] = src.str[i];
}
}break;
}
}
project->extension_space[j++] = 0;
project->extension_count = k;
}
static Project null_project = {0};
static Project current_project = {0};
static char**
get_current_code_extensions(int32_t *extension_count_out){
get_current_project_extensions(int32_t *extension_count_out){
char **extension_list = default_extensions;
int32_t extension_count = ArrayCount(default_extensions);
if (current_project.dir != 0){
extension_list = current_project.extensions;
extension_count = current_project.extension_count;
extension_list = current_project.extension_list.extensions;
extension_count = current_project.extension_list.extension_count;
}
*extension_count_out = extension_count;
return(extension_list);
@ -616,6 +619,8 @@ static String default_font_name = make_fixed_width_string(default_font_name_spac
static char user_name_space[256] = {0};
static String user_name = make_fixed_width_string(user_name_space);
static Extension_List treat_as_code_exts = {0};
static bool32
get_current_name(char **name_out, int32_t *len_out){
bool32 result = false;
@ -646,6 +651,18 @@ get_default_font_name(){
return(str);
}
static char**
get_current_code_extensions(int32_t *extension_count_out){
char **extension_list = default_extensions;
int32_t extension_count = ArrayCount(default_extensions);
if (treat_as_code_exts.extensions != 0){
extension_list = treat_as_code_exts.extensions;
extension_count = treat_as_code_exts.extension_count;
}
*extension_count_out = extension_count;
return(extension_list);
}
// TODO(allen): Stop handling files this way! My own API should be able to do this!!?!?!?!!?!?!!!!?
// NOTE(allen): Actually need binary buffers for some stuff to work, but not this parsing thing here.
#include <stdio.h>
@ -723,6 +740,21 @@ process_config_file(Application_Links *app){
config_string_var(item, "default_theme_name", 0, &default_theme_name);
config_string_var(item, "default_font_name", 0, &default_font_name);
config_string_var(item, "user_name", 0, &user_name);
{
char str_space[512];
String str = make_fixed_width_string(str_space);
if (config_string_var(item, "treat_as_code", 0, &str)){
if (str.size < sizeof(treat_as_code_exts.extension_space)){
set_extensions(&treat_as_code_exts, str);
print_message(app, str.str, str.size);
print_message(app, "\n", 1);
}
else{
print_message(app, literal("STRING TOO LONG!\n"));
}
}
}
}
}
adjust_all_buffer_wrap_widths(app, new_wrap_width, new_min_base_width);

View File

@ -77,13 +77,16 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
int32_t treat_as_code = false;
int32_t wrap_lines = true;
int32_t extension_count = 0;
char **extension_list = get_current_code_extensions(&extension_count);
if (buffer.file_name != 0 && buffer.size < (16 << 20)){
String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match_ss(ext, make_lit_string("cpp")) ||
match_ss(ext, make_lit_string("h")) ||
match_ss(ext, make_lit_string("c")) ||
match_ss(ext, make_lit_string("hpp"))){
for (int32_t i = 0; i < extension_count; ++i){
if (match(ext, extension_list[i])){
treat_as_code = true;
break;
}
}
}
@ -121,6 +124,9 @@ OPEN_FILE_HOOK_SIG(default_new_file){
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessOpen);
char str[] = "/*\nNew File\n*/\n\n\n";
buffer_replace_range(app, &buffer, 0, 0, str, sizeof(str)-1);
// no meaning for return
return(0);
}
OPEN_FILE_HOOK_SIG(default_file_save){

View File

@ -156,19 +156,19 @@ open_all_files_with_extension(Application_Links *app, Partition *scratch_part, c
// NOTE(allen|a4.0.14): open_all_code and close_all_code now use the extensions set in the loaded project. If there is no project loaded the extensions ".cpp.hpp.c.h.cc" are used.
CUSTOM_COMMAND_SIG(open_all_code){
int32_t extension_count = 0;
char **extension_list = get_current_code_extensions(&extension_count);
char **extension_list = get_current_project_extensions(&extension_count);
open_all_files_with_extension(app, &global_part, extension_list, extension_count, false);
}
CUSTOM_COMMAND_SIG(open_all_code_recursive){
int32_t extension_count = 0;
char **extension_list = get_current_code_extensions(&extension_count);
char **extension_list = get_current_project_extensions(&extension_count);
open_all_files_with_extension(app, &global_part, extension_list, extension_count, true);
}
CUSTOM_COMMAND_SIG(close_all_code){
int32_t extension_count = 0;
char **extension_list = get_current_code_extensions(&extension_count);
char **extension_list = get_current_project_extensions(&extension_count);
close_all_files_with_extension(app, &global_part, extension_list, extension_count);
}
@ -234,8 +234,8 @@ CUSTOM_COMMAND_SIG(load_project){
char str_space[512];
String str = make_fixed_width_string(str_space);
if (config_string_var(item, "extensions", 0, &str)){
if (str.size < sizeof(current_project.extension_space)){
set_project_extensions(&current_project, str);
if (str.size < sizeof(current_project.extension_list.extension_space)){
set_extensions(&current_project.extension_list, str);
print_message(app, str.str, str.size);
print_message(app, "\n", 1);
}

View File

@ -1693,8 +1693,6 @@ App_Step_Sig(app_step){
if (get_canon_name(system, &canon, make_string(buffer, size))){
Editing_File *file = working_set_canon_contains(working_set, canon.name);
if (file){
Application_Links *app = &models->app_links;
if (file->state.ignore_behind_os == 0){
file_mark_behind_os(file);
}

View File

@ -790,7 +790,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
if (!using_actual_filename && file->canon.name.str != 0){
char space[512];
u32 length = str_size(filename);
u32 canon_length = system->get_canonical(filename, length, space, sizeof(space));
system->get_canonical(filename, length, space, sizeof(space));
char *source_path = file->canon.name.str;
if (match(space, source_path)){

View File

@ -510,12 +510,15 @@ site_build(char *cdir, u32 flags){
#define PACK_DIR "../distributions"
static void
get_4coder_dist_name(String *zip_file, i32 OS_specific, char *tier, char *ext){
get_4coder_dist_name(String *zip_file, b32 OS_specific, char *folder, char *tier, char *arch, char *ext){
zip_file->size = 0;
append_sc(zip_file, PACK_DIR"/");
append_sc(zip_file, tier);
append_sc(zip_file, "/4coder-");
if (folder != 0){
append_sc(zip_file, folder);
append_sc(zip_file, "/");
}
append_sc(zip_file, "4coder-");
if (OS_specific){
#if defined(IS_WINDOWS)
@ -534,10 +537,14 @@ get_4coder_dist_name(String *zip_file, i32 OS_specific, char *tier, char *ext){
append_int_to_str (zip_file, MINOR);
append_sc (zip_file, "-");
append_int_to_str (zip_file, PATCH);
if (!match_cc(tier, "alpha")){
if (tier != 0){
append_sc (zip_file, "-");
append_sc (zip_file, tier);
}
if (arch != 0){
append_sc (zip_file, "-");
append_sc (zip_file, arch);
}
append_sc (zip_file, ".");
append_sc (zip_file, ext);
terminate_with_null(zip_file);
@ -591,6 +598,13 @@ package(char *cdir){
"alpha_x86",
};
char *tier = "alpha";
char *archs[] = {
"x64",
"x86",
};
Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs));
u32 count = ArrayCount(dest_dirs);
@ -604,6 +618,7 @@ package(char *cdir){
char *dir = dest_dirs[i];
char *par_dir = dest_par_dirs[i];
char *zip_dir = zip_dirs[i];
char *arch = archs[i];
build_main(cdir, base_flags | flags[i]);
@ -617,7 +632,7 @@ package(char *cdir){
copy_file(0, "TODO.txt", dir, 0, 0);
copy_file(data_dir, "release-config.4coder", dir, 0, "config.4coder");
get_4coder_dist_name(&str, 1, zip_dir, "zip");
get_4coder_dist_name(&str, true, zip_dir, tier, arch, "zip");
zip(par_dir, "4coder", str.str);
}
}
@ -649,6 +664,13 @@ package(char *cdir){
"super_x86",
};
char *tier = "super";
char *archs[] = {
"x64",
"x86",
};
Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs));
u32 count = ArrayCount(dest_dirs);
@ -662,6 +684,7 @@ package(char *cdir){
char *dir = dest_dirs[i];
char *par_dir = dest_par_dirs[i];
char *zip_dir = zip_dirs[i];
char *arch = archs[i];
build_main(cdir, base_flags | flags[i]);
do_buildsuper(cdir, Custom_Default, flags[i]);
@ -712,12 +735,12 @@ package(char *cdir){
copy_all(d, "*", str.str);
}
get_4coder_dist_name(&str, 1, zip_dir, "zip");
get_4coder_dist_name(&str, true, zip_dir, tier, arch, "zip");
zip(par_dir, "4coder", str.str);
}
make_folder_if_missing(pack_dir, "super-docs");
get_4coder_dist_name(&str, 0, "API", "html");
get_4coder_dist_name(&str, false, "super-docs", "API", 0, "html");
str2 = front_of_directory(str);
copy_file(site_dir, "custom_docs.html", pack_dir, "super-docs", str2.str);
}
@ -733,7 +756,7 @@ package(char *cdir){
make_folder_if_missing(pack_dir, "power");
copy_all("power", "*", pack_power_dir);
get_4coder_dist_name(&str, 0, "power", "zip");
get_4coder_dist_name(&str, 0, "power", 0, 0, "zip");
zip(pack_power_par_dir, "power", str.str);
}