diff --git a/4coder_string.h b/4coder_string.h index 5fc78e27..11f55dad 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -169,6 +169,10 @@ FSTRING_LINK fstr_bool remove_extension(String *str); FSTRING_LINK fstr_bool remove_last_folder(String *str); FSTRING_LINK fstr_bool string_set_match_table(void *str_set, int32_t item_size, int32_t count, String str, int32_t *match_index); FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index); +FSTRING_LINK String get_first_double_line(String source); +FSTRING_LINK String get_next_double_line(String source, String line); +FSTRING_LINK String get_next_word(String source, String prev_word); +FSTRING_LINK String get_first_word(String source); #endif @@ -1919,6 +1923,84 @@ string_set_match(String *str_set, int32_t count, String str, int32_t *match_inde } #endif +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_double_line(String source){ + String line = {0}; + int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_double_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_word(String source, String prev_word){ + + String word = {0}; + int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; + int32_t pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} +#endif #ifndef FSTRING_EXPERIMENTAL #define FSTRING_EXPERIMENTAL diff --git a/4ed.cpp b/4ed.cpp index 421d208a..5b2f3b89 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -361,6 +361,8 @@ COMMAND_DECL(reopen){ if (buffer){ if (system->load_file(handle, buffer, size)){ + system->load_close(handle); + General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; @@ -395,11 +397,15 @@ COMMAND_DECL(reopen){ file->settings.unwrapped_lines); } } + else{ + system->load_close(handle); + } + } + else{ + system->load_close(handle); } end_temp_memory(temp); - - system->load_close(handle); } } } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 8eeaf17f..20bae7c8 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -1091,6 +1091,7 @@ DOC_SEE(begin_buffer_creation) } if (system->load_file(handle, buffer, size)){ + system->load_close(handle); file = working_set_alloc_always(system, working_set, general); if (file){ buffer_bind_file(system, general, working_set, file, canon.name); @@ -1099,12 +1100,13 @@ DOC_SEE(begin_buffer_creation) fill_buffer_summary(&result, file, cmd); } } + else{ + system->load_close(handle); + } if (in_general_mem){ general_memory_free(system, general, buffer); } - - system->load_close(handle); } else if (!(flags & BufferCreate_NeverNew)){ file = working_set_alloc_always(system, working_set, general); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 290ed873..806cd25c 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -3792,10 +3792,12 @@ view_open_file(System_Functions *system, Models *models, View *view, String file } if (system->load_file(handle, buffer, size)){ + system->load_close(handle); init_normal_file(system, models, file, buffer, size); } - + else{ system->load_close(handle); + } if (gen_buffer){ general_memory_free(system, general, buffer); diff --git a/build.cpp b/build.cpp index 8f2c1d72..c9bfa18c 100644 --- a/build.cpp +++ b/build.cpp @@ -822,17 +822,17 @@ do_buildsuper(char *cdir){ //terminate_with_null(&str); //buildsuper(cdir, BUILD_DIR, str.str); #if defined(IS_WINDOWS) - copy_sc(&str, "../code/internal_4coder_tests.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); + //copy_sc(&str, "../code/internal_4coder_tests.cpp"); + //terminate_with_null(&str); + //buildsuper(cdir, BUILD_DIR, str.str); #else copy_sc(&str, "../code/power/4coder_experiments.cpp"); terminate_with_null(&str); buildsuper(cdir, BUILD_DIR, str.str); #endif - //copy_sc(&str, "../code/power/4coder_casey.cpp"); - //terminate_with_null(&str); - //buildsuper(cdir, BUILD_DIR, str.str); + copy_sc(&str, "../code/power/4coder_casey.cpp"); + terminate_with_null(&str); + buildsuper(cdir, BUILD_DIR, str.str); //copy_sc(&str, "../4vim/4coder_chronal.cpp"); //terminate_with_null(&str); //buildsuper(cdir, BUILD_DIR, str.str); diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 3c35554e..d7672859 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -1799,6 +1799,76 @@ DOC_SEE(match) */{ return(result); } +API_EXPORT FSTRING_LINK String +get_first_double_line(String source){ + String line = {0}; + int32_t pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + int32_t pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} + +API_EXPORT FSTRING_LINK String +get_next_double_line(String source, String line){ + String next = {0}; + int32_t pos = (int32_t)(line.str - source.str) + line.size; + int32_t start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} + +API_EXPORT FSTRING_LINK String +get_next_word(String source, String prev_word){ + + String word = {0}; + int32_t pos0 = (int32_t)(prev_word.str - source.str) + prev_word.size; + int32_t pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} + +API_EXPORT FSTRING_LINK String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} #ifndef FSTRING_EXPERIMENTAL #define FSTRING_EXPERIMENTAL diff --git a/site/4ed_site.ctm b/site/4ed_site.ctm index ff554d87..f0a30ff6 100644 Binary files a/site/4ed_site.ctm and b/site/4ed_site.ctm differ diff --git a/site/abstract_document.cpp b/site/abstract_document.cpp index 12e3828a..832eed5e 100644 --- a/site/abstract_document.cpp +++ b/site/abstract_document.cpp @@ -268,17 +268,64 @@ write_enriched_text_html(String *out, Enriched_Text *text){ append_sc(out, "
"); - append_ss(out, line); + + //append_ss(out, l); + int32_t start = 0, i = 0; + for (; i < l.size; ++i){ + if (l.str[i] == '\\'){ + append_ss(out, substr(l, start, i-start)); + + int32_t command_start = i+1; + int32_t command_end = command_start; + for (; command_end < l.size; ++command_end){ + if (!char_is_alpha_numeric(l.str[command_end])){ + break; + } + } + + if (command_end == command_start){ + if (command_end < l.size && l.str[command_end] == '\\'){ + ++command_end; + } + } + + String command_string = substr(l, command_start, command_end - command_start); + + static String enriched_commands[] = { + make_lit_string("\\"), + make_lit_string("VERSION"), + make_lit_string("CODE_STYLE"), + }; + + int32_t match_index = 0; + if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){ + switch (match_index){ + case 0: append_sc(out, "\\"); break; + case 1: append_sc(out, VERSION); break; + case 2: append_sc(out, " TEST "); break; + } + } + else{ + append_sc(out,"! Doc generator error: unrecognized command !"); + fprintf(stderr, "error: Unrecognized command %.*s\n", command_string.size, command_string.str); + } + + i = command_end; + start = i; + } + } + + if (start != i){ + append_ss(out, substr(l, start, i-start)); + } + append_sc(out, "
"); } -#endif - append_ss(out, source); append_sc(out, "