diff options
| -rw-r--r-- | src/config.cpp | 17 | ||||
| -rw-r--r-- | src/image.cpp | 2 | ||||
| -rw-r--r-- | src/linux/main_linux.cpp | 8 | ||||
| -rw-r--r-- | src/main.cpp | 28 | ||||
| -rw-r--r-- | src/search.cpp | 4 | ||||
| -rw-r--r-- | src/windows/main_windows.cpp | 2 |
6 files changed, 34 insertions, 27 deletions
diff --git a/src/config.cpp b/src/config.cpp index 216c93d..61e4127 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -14,18 +14,25 @@ int max_file_size = 100; // in MBs static void _ts_config_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) { - ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; uint8_t path[MAX_INPUT_LENGTH]; uint8_t filter[MAX_INPUT_LENGTH]; uint8_t query[MAX_INPUT_LENGTH]; - int threads, maxSize; + int threads = 1, maxSize = 100; - if (sscanf(line, "Path=%s", &path) == 1) { strcpy(path_buffer, (char*)path); } - else if (sscanf(line, "Filter=%s", &filter) == 1) { strcpy(filter_buffer, (char*)filter); } - else if (sscanf(line, "Query=%s", &query) == 1) { strcpy(query_buffer, (char*)query); } +#if defined(_WIN32) + if (sscanf_s(line, "Path=%s", (char*)&path, MAX_INPUT_LENGTH) == 1) { strncpy_s(path_buffer, MAX_INPUT_LENGTH, (char*)path, MAX_INPUT_LENGTH); } + else if (sscanf_s(line, "Filter=%s", (char*)&filter, MAX_INPUT_LENGTH) == 1) { strncpy_s(filter_buffer, MAX_INPUT_LENGTH, (char*)filter, MAX_INPUT_LENGTH); } + else if (sscanf_s(line, "Query=%s", (char*)&query, MAX_INPUT_LENGTH) == 1) { strncpy_s(query_buffer, MAX_INPUT_LENGTH, (char*)query, MAX_INPUT_LENGTH); } + else if (sscanf_s(line, "Threads=%d", &threads) == 1) { ts_thread_count = threads; } + else if (sscanf_s(line, "MaxSize=%d", &maxSize) == 1) { max_file_size = maxSize; } +#elif defined(__linux__) + if (sscanf(line, "Path=%s", (char*)&path) == 1) { strncpy(path_buffer, (char*)path, MAX_INPUT_LENGTH); } + else if (sscanf(line, "Filter=%s", (char*)&filter) == 1) { strncpy(filter_buffer, (char*)filter, MAX_INPUT_LENGTH); } + else if (sscanf(line, "Query=%s", (char*)&query) == 1) { strncpy(query_buffer, (char*)query, MAX_INPUT_LENGTH); } else if (sscanf(line, "Threads=%d", &threads) == 1) { ts_thread_count = threads; } else if (sscanf(line, "MaxSize=%d", &maxSize) == 1) { max_file_size = maxSize; } +#endif } static void _ts_config_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) diff --git a/src/image.cpp b/src/image.cpp index cf5e12d..1203df2 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -48,7 +48,7 @@ static ts_image _ts_load_image(unsigned char* data, size_t size) { int w = 0; int h = 0; GLuint id = 0; - bool ret = _ts_load_texture(data, size, &id, &w, &h); + _ts_load_texture(data, size, &id, &w, &h); return ts_image {id, w, h}; } diff --git a/src/linux/main_linux.cpp b/src/linux/main_linux.cpp index fda8d64..2041c09 100644 --- a/src/linux/main_linux.cpp +++ b/src/linux/main_linux.cpp @@ -32,7 +32,7 @@ static const char* _ts_platform_get_config_file_path(char* buffer) { char* env = getenv("HOME"); char path_buf[MAX_INPUT_LENGTH]; snprintf(path_buf, MAX_INPUT_LENGTH, "%s%s", env, "/text-search/"); - snprintf(buffer, MAX_INPUT_LENGTH, "%s%s", path_buf, "imgui.ini"); + snprintf(buffer, MAX_INPUT_LENGTH, "%.*s%s", MAX_INPUT_LENGTH-10, path_buf, "imgui.ini"); if (!ts_platform_dir_exists(path_buf)) { mkdir(path_buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } @@ -232,10 +232,10 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir) struct dirent *dir; d = opendir(search_dir); if (d) { - chdir(search_dir); + if (chdir(search_dir) != 0) return; while ((dir = readdir(d)) != NULL) { if (result->cancel_search) return; - chdir(search_dir); + if (chdir(search_dir) != 0) continue; if (dir->d_type == DT_DIR) { @@ -254,7 +254,7 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir) else if (dir->d_type == DT_REG || dir->d_type == DT_UNKNOWN) { char *matched_filter = 0; - if (ts_filter_matches(&result->filters, dir->d_name, &matched_filter) == -1) { + if (ts_filter_matches(&result->filters, dir->d_name, &matched_filter) == (size_t)-1) { continue; } (void)matched_filter; diff --git a/src/main.cpp b/src/main.cpp index e40bd93..ed51402 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,15 +69,15 @@ static void _ts_create_popups() { ImGui::Dummy({0, 20}); ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::CalcTextSize(name).x)/2.0f); - ImGui::Text(name); + ImGui::Text("%s", name); ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::CalcTextSize(link).x)/2.0f); - ImGui::Text(link); + ImGui::Text("%s", link); ImGui::Dummy({0, 20}); if (ImGui::CollapsingHeader("License")) { char* license = (char*)_binary_LICENSE_start; int64_t license_length = _binary_LICENSE_end - _binary_LICENSE_start; - ImGui::Text("%.*s", license_length, license); + ImGui::Text("%.*s", (int)license_length, license); } ImGui::SeparatorText("Dependencies"); @@ -85,14 +85,14 @@ static void _ts_create_popups() { if (ImGui::TreeNode("https://github.com/ocornut/imgui")) { char* license = (char*)_binary_imgui_LICENSE_start; int64_t license_length = _binary_imgui_LICENSE_end - _binary_imgui_LICENSE_start; - ImGui::Text("%.*s", license_length, license); + ImGui::Text("%.*s", (int)license_length, license); ImGui::TreePop(); } if (ImGui::TreeNode("https://github.com/dfranx/ImFileDialog")) { char* license = (char*)_binary_imfiledialog_LICENSE_start; int64_t license_length = _binary_imfiledialog_LICENSE_end - _binary_imfiledialog_LICENSE_start; - ImGui::Text("%.*s", license_length, license); + ImGui::Text("%.*s", (int)license_length, license); ImGui::TreePop(); } @@ -194,7 +194,7 @@ void _ts_create_file_match_rows() { } } -utf8_int8_t* _ts_file_error_to_message(ts_file_open_error err) { +const utf8_int8_t* _ts_file_error_to_message(ts_file_open_error err) { switch (err) { case FILE_ERROR_TOO_MANY_OPEN_FILES_PROCESS: return u8"Too many open files"; case FILE_ERROR_TOO_MANY_OPEN_FILES_SYSTEM: return u8"Too many open files"; @@ -207,8 +207,8 @@ utf8_int8_t* _ts_file_error_to_message(ts_file_open_error err) { case FILE_ERROR_STALE: return u8"Server file moved"; case FILE_ERROR_GENERIC: return u8"Failed to open file"; case FILE_ERROR_TOO_BIG: return u8"File too big"; + default: return ""; } - return ""; } void _ts_create_file_error_rows() { @@ -260,9 +260,9 @@ void _ts_create_text_match_rows() { ImGui::Text("#%d", item+1); ImGui::TableNextColumn(); - ImGui::Text("%.*s", file->word_match_offset, file->line_info); + ImGui::Text("%.*s", (int)file->word_match_offset, file->line_info); ImGui::SameLine(0.0f, 0.0f); - ImGui::TextColored({255,0,0,255}, "%.*s", file->word_match_length, file->line_info + file->word_match_offset); + ImGui::TextColored({255,0,0,255}, "%.*s", (int)file->word_match_length, file->line_info + file->word_match_offset); ImGui::SameLine(0.0f, 0.0f); ImGui::TextUnformatted(file->line_info + file->word_match_offset + file->word_match_length); @@ -331,7 +331,7 @@ void ts_create_gui(int window_w, int window_h) { if (ifd::FileDialog::Instance().IsDone("FolderSelectDialog", window_w, window_h)) { if (ifd::FileDialog::Instance().HasResult()) { std::string res = ifd::FileDialog::Instance().GetResult().u8string(); - snprintf(path_buffer, MAX_INPUT_LENGTH, res.c_str()); + snprintf(path_buffer, MAX_INPUT_LENGTH, "%s", res.c_str()); } ifd::FileDialog::Instance().Close(); } @@ -383,12 +383,12 @@ void ts_create_gui(int window_w, int window_h) { if (current_search_result->search_completed && (current_search_result->files.length == 0 || current_search_result->match_count == 0)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::Text(""); + ImGui::Text("%s", ""); ImGui::TableNextColumn(); - char* msg = "No matches found."; + const char* msg = "No matches found."; ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::CalcTextSize(msg).x)/2.0f); - ImGui::TextWrapped(msg); + ImGui::TextWrapped("%s", msg); } ImGui::EndTable(); @@ -398,7 +398,7 @@ void ts_create_gui(int window_w, int window_h) { ImGui::Separator(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 20.0f); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 20.0f); - ImGui::TextWrapped(help_text); + ImGui::TextWrapped("%s", help_text); } pos_y += result_area_height; diff --git a/src/search.cpp b/src/search.cpp index 96f8c32..61f8d54 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -264,13 +264,13 @@ static void _ts_search_file(ts_found_file *ref, ts_file_content content, ts_sear memset(file_match.line_info, 0, MAX_INPUT_LENGTH); // Trim some text infront of match. - int text_pad_lr = 35; + size_t text_pad_lr = 35; if (file_match.word_match_offset > text_pad_lr) { 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++) { + for (size_t i = 0; i < bytes_to_trim; i++) { utf8_int32_t ch; m->line_start = utf8codepoint(m->line_start, &ch); bytes_trimmed = (m->line_start - line_start_before_trim); diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp index 74c1e86..cec7d47 100644 --- a/src/windows/main_windows.cpp +++ b/src/windows/main_windows.cpp @@ -358,7 +358,7 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir) char *matched_filter = 0; utf8_int8_t uni_name[MAX_INPUT_LENGTH]; WideCharToMultiByte(CP_UTF8,0,name,-1,(LPSTR)uni_name,MAX_INPUT_LENGTH, NULL, NULL); - if (ts_filter_matches(&result->filters, uni_name, &matched_filter) == -1) { + if (ts_filter_matches(&result->filters, uni_name, &matched_filter) == (size_t)-1) { continue; } (void)matched_filter; |
