diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/array.cpp | 6 | ||||
| -rw-r--r-- | src/config.h | 1 | ||||
| -rw-r--r-- | src/definitions.h | 3 | ||||
| -rw-r--r-- | src/image.cpp | 8 | ||||
| -rw-r--r-- | src/main.cpp | 41 | ||||
| -rw-r--r-- | src/platform.h | 2 | ||||
| -rw-r--r-- | src/search.cpp | 17 | ||||
| -rw-r--r-- | src/search.h | 10 | ||||
| -rw-r--r-- | src/windows/main_windows.cpp | 8 |
9 files changed, 41 insertions, 55 deletions
diff --git a/src/array.cpp b/src/array.cpp index a0b5863..4eb50bd 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -131,9 +131,9 @@ void ts_array_remove_at(ts_array *ts_array, int at) void ts_array_remove(ts_array *ts_array, void *ptr) { ts_mutex_lock(&ts_array->mutex); - int offset = (char*)ptr - (char*)ts_array->data; - int at = offset / ts_array->entry_size; - ts_array_remove_at(ts_array, at); + size_t offset = (char*)ptr - (char*)ts_array->data; + size_t at = offset / ts_array->entry_size; + ts_array_remove_at(ts_array, (int)at); ts_mutex_unlock(&ts_array->mutex); } diff --git a/src/config.h b/src/config.h index 5255c1a..f6cff36 100644 --- a/src/config.h +++ b/src/config.h @@ -8,7 +8,6 @@ #define MAX_ERROR_MESSAGE_LENGTH (MAX_INPUT_LENGTH) #define FILE_RESERVE_COUNT 1000 -#define ERROR_RESERVE_COUNT 100 #include "../imgui/imgui.h" #include "../utf8.h" diff --git a/src/definitions.h b/src/definitions.h index f023e84..51e42d8 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -12,9 +12,6 @@ extern unsigned char _binary_LICENSE_end[]; extern unsigned char _binary_imgui_LICENSE_start[]; extern unsigned char _binary_imgui_LICENSE_end[]; -extern unsigned char _binary_imspinner_LICENSE_start[]; -extern unsigned char _binary_imspinner_LICENSE_end[]; - extern unsigned char _binary_imfiledialog_LICENSE_start[]; extern unsigned char _binary_imfiledialog_LICENSE_end[]; diff --git a/src/image.cpp b/src/image.cpp index 0755055..cf5e12d 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -10,12 +10,12 @@ ts_image img_search; ts_image img_folder; // Simple helper function to load an image into a OpenGL texture with common settings -static bool _ts_load_texture(unsigned char* data, unsigned long size, GLuint* out_texture, int* out_width, int* out_height) +static bool _ts_load_texture(unsigned char* data, size_t size, GLuint* out_texture, int* out_width, int* out_height) { // Load from file int image_width = 0; int image_height = 0; - unsigned char* image_data = stbi_load_from_memory(data, size, &image_width, &image_height, NULL, 4); + unsigned char* image_data = stbi_load_from_memory(data, (int)size, &image_width, &image_height, NULL, 4); if (image_data == NULL) { printf("Failed to load %s\n", stbi_failure_reason()); return false; @@ -44,7 +44,7 @@ static bool _ts_load_texture(unsigned char* data, unsigned long size, GLuint* ou return true; } -static ts_image _ts_load_image(unsigned char* data, unsigned long size) { +static ts_image _ts_load_image(unsigned char* data, size_t size) { int w = 0; int h = 0; GLuint id = 0; @@ -54,7 +54,7 @@ static ts_image _ts_load_image(unsigned char* data, unsigned long size) { } void ts_load_images() { - int size = _binary_misc_logo_64_png_end - _binary_misc_logo_64_png_start; + size_t size = _binary_misc_logo_64_png_end - _binary_misc_logo_64_png_start; unsigned char* data = (unsigned char *)_binary_misc_logo_64_png_start; img_logo = _ts_load_image(data, size); diff --git a/src/main.cpp b/src/main.cpp index fd88a50..e40bd93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "../imgui/imgui.h" #include "../imgui/imgui_spectrum.h" #include "../imgui/imgui_impl_opengl3_loader.h" -#include "../imspinner/imspinner.h" #include "../imfiledialog/imFileDialog.h" #include "../utf8.h" #include "definitions.h" @@ -16,7 +15,7 @@ bool open_settings_window = false; bool open_about_window = false; -char* help_text = +const char* help_text = "1. Search directory\n" " - The absolute path to the folder to search.\n" "2. File filter\n" @@ -62,8 +61,8 @@ static void _ts_create_popups() { if (ImGui::BeginPopupModal("About Text-Search", &open_about_window, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove)) { ImGui::SetWindowSize({600, 420}); - char* name = "Text-Search"; - char* link = "created by Aldrik Ramaekers <aldrik.ramaekers@gmail.com>"; + const char* name = "Text-Search"; + const char* link = "created by Aldrik Ramaekers <aldrik.ramaekers@gmail.com>"; ImGui::SetCursorPosX((ImGui::GetWindowWidth() - 64) / 2.0f); ImGui::Image((void*)(intptr_t)img_logo.id, {64, 64}); @@ -77,7 +76,7 @@ static void _ts_create_popups() { if (ImGui::CollapsingHeader("License")) { char* license = (char*)_binary_LICENSE_start; - int license_length = _binary_LICENSE_end - _binary_LICENSE_start; + int64_t license_length = _binary_LICENSE_end - _binary_LICENSE_start; ImGui::Text("%.*s", license_length, license); } @@ -85,21 +84,14 @@ static void _ts_create_popups() { { if (ImGui::TreeNode("https://github.com/ocornut/imgui")) { char* license = (char*)_binary_imgui_LICENSE_start; - int license_length = _binary_imgui_LICENSE_end - _binary_imgui_LICENSE_start; - ImGui::Text("%.*s", license_length, license); - ImGui::TreePop(); - } - - if (ImGui::TreeNode("https://github.com/dalerank/imspinner")) { - char* license = (char*)_binary_imspinner_LICENSE_start; - int license_length = _binary_imspinner_LICENSE_end - _binary_imspinner_LICENSE_start; + int64_t license_length = _binary_imgui_LICENSE_end - _binary_imgui_LICENSE_start; ImGui::Text("%.*s", license_length, license); ImGui::TreePop(); } if (ImGui::TreeNode("https://github.com/dfranx/ImFileDialog")) { char* license = (char*)_binary_imfiledialog_LICENSE_start; - int license_length = _binary_imfiledialog_LICENSE_end - _binary_imfiledialog_LICENSE_start; + int64_t license_length = _binary_imfiledialog_LICENSE_end - _binary_imfiledialog_LICENSE_start; ImGui::Text("%.*s", license_length, license); ImGui::TreePop(); } @@ -281,8 +273,6 @@ void _ts_create_text_match_rows() { } void ts_create_gui(int window_w, int window_h) { - static float f = 0.0f; - static int counter = 0; int window_pad = 50; int textbox_area_height = 80; int statusbar_area_height = 30; @@ -297,11 +287,10 @@ void ts_create_gui(int window_w, int window_h) { ImGuiWindowFlags_MenuBar); ImGui::PopStyleVar(); - float menu_bar_h = _ts_create_menu(); + int menu_bar_h = _ts_create_menu(); float pos_y = 0; - - pos_y += menu_bar_h + 15; + pos_y += menu_bar_h + 15.0f; { // Search boxes ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(5, 5)); @@ -310,7 +299,7 @@ void ts_create_gui(int window_w, int window_h) { float separator_w = 10.0f; float frame_w = window_w/2.5f - offset - separator_w/2.0f; ImGui::SetNextWindowPos({offset, pos_y}); - ImGui::BeginChild("search-boxes", ImVec2(frame_w, textbox_area_height), false); + ImGui::BeginChild("search-boxes", ImVec2((float)frame_w, (float)textbox_area_height), false); { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushItemWidth(-1); @@ -333,7 +322,7 @@ void ts_create_gui(int window_w, int window_h) { ImGui::EndChild(); ImGui::SetNextWindowPos({offset + frame_w + separator_w, pos_y}); - ImGui::BeginChild("search-boxes2", ImVec2(frame_w, textbox_area_height), false); + ImGui::BeginChild("search-boxes2", ImVec2((float)frame_w, (float)textbox_area_height), false); { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); if (ImGui::ImageButton("Folder", (void*)(intptr_t)img_folder.id, ImVec2(18.0f, 18.0f))) { @@ -357,7 +346,7 @@ void ts_create_gui(int window_w, int window_h) { ImGui::PopStyleVar(); if (current_search_result && !current_search_result->search_completed) { - ImSpinner::SpinnerIncScaleDots("Spinner", 10.0f, 2.0f, ImColor(70,70,70), 5.0f); + ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); } else { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); @@ -380,9 +369,9 @@ void ts_create_gui(int window_w, int window_h) { if (ImGui::BeginTable("results-table", 3, ImGuiTableFlags_BordersH|ImGuiTableFlags_ScrollY|ImGuiTableFlags_RowBg|ImGuiTableFlags_SizingFixedFit, {(float)window_w-7.0f, (float)result_area_height})) { - int nr_w = 50; - int line_w = 180; - int file_w = ImGui::GetWindowWidth() - line_w - nr_w; + float nr_w = 50.0f; + float line_w = 180.0f; + float file_w = ImGui::GetWindowWidth() - line_w - nr_w; ImGui::TableSetupColumn("", ImGuiTableColumnFlags_NoHeaderLabel, nr_w); ImGui::TableSetupColumn("File", 0, file_w); ImGui::TableSetupColumn("Match", 0, line_w); @@ -417,7 +406,7 @@ void ts_create_gui(int window_w, int window_h) { ImGui::SetNextWindowPos({0, pos_y}); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 6)); - ImGui::BeginChild("search-statusbar", ImVec2(window_w, statusbar_area_height), ImGuiChildFlags_None, ImGuiWindowFlags_None); + ImGui::BeginChild("search-statusbar", ImVec2((float)window_w, (float)statusbar_area_height), ImGuiChildFlags_None, ImGuiWindowFlags_None); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 7.0f); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10.0f); if (current_search_result) { diff --git a/src/platform.h b/src/platform.h index b9a9e9c..fbcffc9 100644 --- a/src/platform.h +++ b/src/platform.h @@ -8,7 +8,7 @@ typedef struct t_ts_file_content { - int content_length; + size_t content_length; void *content; int file_error; } ts_file_content; diff --git a/src/search.cpp b/src/search.cpp index ed6c1ee..ed1efa1 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -58,7 +58,7 @@ int ts_string_match(utf8_int8_t *first, utf8_int8_t *second) return 0; } -int ts_filter_matches(ts_array *filters, char *string, char **matched_filter) +size_t ts_filter_matches(ts_array *filters, char *string, char **matched_filter) { for (int i = 0; i < filters->length; i++) { @@ -142,11 +142,10 @@ bool ts_string_contains(char *text_to_search, utf8_int8_t *text_to_find, ts_arra utf8_int32_t text_to_search_ch = 0; utf8_int32_t text_to_find_ch = 0; - size_t text_to_find_char_len = utf8len(text_to_find); int line_nr_val = 1; - int word_offset_val = 0; - int word_match_len_val = 0; + size_t word_offset_val = 0; + size_t word_match_len_val = 0; char *line_start_ptr = text_to_search; int index = 0; @@ -248,7 +247,7 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear if (content.content && !content.file_error) { ts_array text_matches = ts_array_create(sizeof(ts_text_match)); - int search_len = strlen(result->search_text); + size_t search_len = strlen(result->search_text); if (ts_string_contains((char *)content.content, result->search_text, &text_matches)) { ts_mutex_lock(&result->matches.mutex); @@ -268,8 +267,8 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear int text_pad_lr = 35; if (file_match.word_match_offset > text_pad_lr) { - int bytes_to_trim = (file_match.word_match_offset - text_pad_lr); - int bytes_trimmed = 0; + size_t bytes_to_trim = (file_match.word_match_offset - text_pad_lr); + size_t bytes_trimmed = 0; utf8_int8_t* line_start_before_trim = m->line_start; for (int i = 0; i < bytes_to_trim; i++) { utf8_int32_t ch; @@ -277,11 +276,11 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear bytes_trimmed = (m->line_start - line_start_before_trim); if (bytes_trimmed >= bytes_to_trim) break; } - file_match.word_match_offset = file_match.word_match_offset - bytes_trimmed; + file_match.word_match_offset = (size_t)(file_match.word_match_offset - bytes_trimmed); } // Copy relevant line part. - int total_len = text_pad_lr + search_len + text_pad_lr; + size_t total_len = text_pad_lr + search_len + text_pad_lr; if (total_len > MAX_INPUT_LENGTH) total_len = MAX_INPUT_LENGTH; utf8ncpy(file_match.line_info, m->line_start, total_len); diff --git a/src/search.h b/src/search.h index a8aaf90..b56e007 100644 --- a/src/search.h +++ b/src/search.h @@ -44,16 +44,16 @@ typedef struct t_ts_file_match { ts_found_file* file; int line_nr; - int word_match_offset; // nr of bytes, not codepoints. - int word_match_length; // nr of bytes, not codepoints. + size_t word_match_offset; // nr of bytes, not codepoints. + size_t word_match_length; // nr of bytes, not codepoints. utf8_int8_t *line_info; } ts_file_match; typedef struct t_ts_text_match { int line_nr; - int word_offset; - int word_match_len; + size_t word_offset; + size_t word_match_len; utf8_int8_t *line_start; utf8_int8_t *line_info; } ts_text_match; @@ -61,7 +61,7 @@ typedef struct t_ts_text_match extern ts_search_result* current_search_result; ts_array ts_get_filters(utf8_int8_t *pattern); -int ts_filter_matches(ts_array *filters, utf8_int8_t *string, utf8_int8_t **matched_filter); +size_t ts_filter_matches(ts_array *filters, utf8_int8_t *string, utf8_int8_t **matched_filter); int ts_string_match(utf8_int8_t *first, utf8_int8_t *second); ts_search_result* ts_create_empty_search_result(); bool ts_string_contains(utf8_int8_t *text_to_search, utf8_int8_t *text_to_find, ts_array *text_matches); diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp index cb59d9d..74c1e86 100644 --- a/src/windows/main_windows.cpp +++ b/src/windows/main_windows.cpp @@ -241,9 +241,11 @@ ts_file_content ts_platform_read_file(char *path, const char *mode) const size_t cSize = strlen(mode)+1; wchar_t* wc = new wchar_t[cSize]; - mbstowcs (wc, mode, cSize); + size_t outSize; + mbstowcs_s(&outSize, wc, cSize, mode, cSize); - FILE *file = _wfopen(wchar_buffer, wc); + FILE *file; + _wfopen_s(&file, wchar_buffer, wc); if (!file) { if (errno == EMFILE) @@ -281,7 +283,7 @@ ts_file_content ts_platform_read_file(char *path, const char *mode) if (!result.content) goto done; memset(result.content, 0, length); - int read_result = fread(result.content, 1, length, file); + size_t read_result = fread(result.content, 1, length, file); if (read_result == 0 && length != 0) { free(result.content); |
