diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/command_line.c | 265 | ||||
| -rw-r--r-- | src/command_line.h | 12 | ||||
| -rw-r--r-- | src/settings.c | 313 | ||||
| -rw-r--r-- | src/settings.h | 60 |
4 files changed, 0 insertions, 650 deletions
diff --git a/src/command_line.c b/src/command_line.c deleted file mode 100644 index b1718f9..0000000 --- a/src/command_line.c +++ /dev/null @@ -1,265 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#if 0 -void find_text_in_files(search_result *search_result); -s32 prepare_search_directory_path(char *path, s32 len); -search_result *create_empty_search_result(); -void do_search(); -bool export_results(search_result *result); - -static void print_license_message() -{ - time_t t = time(0); - struct tm *now = localtime(&t); - - printf("BSD 2-Clause License\n" - "\n" - "Copyright (c) %d, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com\n" - "All rights reserved.\n" - "\n" - "Redistribution and use in source and binary forms, with or without\n" - "modification, are permitted provided that the following conditions are met:\n" - "\n" - "1. Redistributions of source code must retain the above copyright notice, this\n" - "list of conditions and the following disclaimer.\n" - "\n" - "2. Redistributions in binary form must reproduce the above copyright notice,\n" - "this list of conditions and the following disclaimer in the documentation\n" - "and/or other materials provided with the distribution.\n" - "\n" - "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n" - "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n" - "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" - "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n" - "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n" - "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n" - "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n" - "CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n" - "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" - "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n", now->tm_year+1900); - - printf("The following parts of the Software are separately licensed:\n" - "- The Liberation font family is licensed under the SIL Open Font License" "(version 2 onwards)\n\n"); -} - -static void print_help_message() -{ -#define explain_required_argument(c,e) printf(" %-18s%-18s%s\n", c, "REQUIRED", e); -#define explain_other_argument(c,e) printf(" %-18s%-18s%s\n", c, " ", e); -#define explain_optional_argument(c,d,e) printf(" %-18s%-18s%s\n", c, d, e); -#define DEFAULT(d) "default=\""d"\"" - - printf("Usage: text-search [OPTION] ... [OPTION] ...\n"); - printf("Example: text-search " - "--directory \"/home/john/Documents\" --text \"homework\" --recursive 0\n"); - printf("Text-search, search for files and text within files.\n"); - printf("Matches will be printed to console in format: [path]:[line]:[filter]\n\n"); - - printf("Available arguments:\n"); - explain_required_argument("--directory", "The directory to search"); - explain_optional_argument("--text", DEFAULT("*"), "The text to search for within files, supports wildcards '*' and '?'"); - explain_optional_argument("--filter", DEFAULT("*"), "Used to filter on specific files, supports wildcards '*' and '?'"); - explain_optional_argument("--recursive", DEFAULT("1"), "Recursively search through directories"); - explain_optional_argument("--max-file-size", DEFAULT("0"), "The maximum size, in kb, a file will be searched through for matching text. 0 for no limit"); - explain_optional_argument("--threads", DEFAULT("10"), "The number of threads used for searching, minimum of 1 thread."); - explain_optional_argument("--locale", DEFAULT("en"), "The language errors will be reported in. Available locales are: 'en', 'nl'"); - explain_optional_argument("--export", DEFAULT(""), "Export the results to a file in json format"); - - printf("\nOther arguments:\n"); - explain_other_argument("--help", "Display this help message"); - explain_other_argument("--license", "Display the license"); -} - -static bool is_valid_argument(char *arg) -{ - if (string_equals(arg, "--directory")) return true; - if (string_equals(arg, "--text")) return true; - if (string_equals(arg, "--filter")) return true; - if (string_equals(arg, "--recursive")) return true; - if (string_equals(arg, "--max-file-size")) return true; - if (string_equals(arg, "--threads")) return true; - if (string_equals(arg, "--locale")) return true; - if (string_equals(arg, "--export")) return true; - - return false; -} -#endif -void handle_command_line_arguments(int argc, char **argv) -{ -#if 0 - load_available_localizations(); - set_locale("en"); - - s32 current_arg_index = 1; - bool is_help_request = string_equals(argv[current_arg_index], "--help"); - bool is_license_request = string_equals(argv[current_arg_index], "--license"); - - if (is_help_request) - { - print_help_message(); - return; - } - else if (is_license_request) - { - print_license_message(); - return; - } - - char directory[MAX_INPUT_LENGTH]; - string_copyn(directory, "", MAX_INPUT_LENGTH); - - char text[MAX_INPUT_LENGTH]; - string_copyn(text, "*", MAX_INPUT_LENGTH); - - char filter[MAX_INPUT_LENGTH]; - string_copyn(filter, "*", MAX_INPUT_LENGTH); - - bool recursive = true; - s32 max_file_size = 0; - s32 threads = 10; - - char locale[MAX_INPUT_LENGTH]; - string_copyn(locale, "en", MAX_INPUT_LENGTH); - - char export_path[MAX_INPUT_LENGTH]; - string_copyn(export_path, "", MAX_INPUT_LENGTH); - - bool expect_argument_name = true; - for (s32 i = current_arg_index; i < argc; i++) - { - if (expect_argument_name && !is_valid_argument(argv[i])) - { - printf("%s: %s\n", localize("invalid_argument"), argv[i]); - } - - if (!expect_argument_name) - { - if (string_equals(argv[i-1], "--directory")) - { - string_copyn(directory, argv[i], MAX_INPUT_LENGTH); - } - if (string_equals(argv[i-1], "--text")) - { - string_copyn(text, argv[i], MAX_INPUT_LENGTH); - } - if (string_equals(argv[i-1], "--filter")) - { - string_copyn(filter, argv[i], MAX_INPUT_LENGTH); - } - if (string_equals(argv[i-1], "--recursive")) - { - recursive = string_to_u32(argv[i]); - } - if (string_equals(argv[i-1], "--max-file-size")) - { - max_file_size = string_to_u32(argv[i]); - } - if (string_equals(argv[i-1], "--threads")) - { - threads = string_to_u32(argv[i]); - } - if (string_equals(argv[i-1], "--locale")) - { - string_copyn(locale, argv[i], MAX_INPUT_LENGTH); - } - if (string_equals(argv[i-1], "--export")) - { - string_copyn(export_path, argv[i], MAX_INPUT_LENGTH); - } - } - - expect_argument_name = !expect_argument_name; - } - - // input validation - if (!set_locale(locale)) - { - printf(localize("warning_locale_not_available"), locale); - printf("\n"); - } - - if (string_equals(directory, "")) - { - printf("%s", localize("error_directory_not_specified")); - printf("\n"); - return; - } - - if (!platform_directory_exists(directory)) - { - printf(localize("error_directory_not_found"), directory); - printf("\n"); - return; - } - - if (string_equals(text, "")) - { - printf("%s", localize("error_text_argument_empty")); - printf("\n"); - return; - } - - if (string_equals(filter, "")) - { - printf("%s", localize("error_filter_argument_empty")); - printf("\n"); - return; - } - - if (threads < 1) - { - printf("%s", localize("error_threads_too_low")); - printf("\n"); - return; - } - - if (!string_equals(export_path, "")) - { - char dir_buffer[MAX_INPUT_LENGTH]; - get_directory_from_path(dir_buffer, export_path); - - if (!platform_directory_exists(dir_buffer)) - { - printf(localize("error_invalid_export_path"), dir_buffer); - printf("\n"); - return; - } - } - - search_result *result = create_empty_search_result(); - string_copyn(result->directory_to_search, directory, MAX_INPUT_LENGTH); - string_copyn(result->file_filter, filter, MAX_INPUT_LENGTH); - string_copyn(result->text_to_find, text, MAX_INPUT_LENGTH); - string_copyn(result->export_path, export_path, MAX_INPUT_LENGTH); - result->max_thread_count = threads; - result->max_file_size = max_file_size; - result->is_recursive = recursive; - result->is_command_line_search = true; - - - // begin search (code below is equal to code in text_search.c) - result->walking_file_system = true; - result->done_finding_matches = false; - - result->search_result_source_dir_len = strlen(result->directory_to_search); - result->search_result_source_dir_len = prepare_search_directory_path(result->directory_to_search, - result->search_result_source_dir_len); - result->start_time = platform_get_time(TIME_FULL, TIME_US); - - platform_list_files(&result->files, result->directory_to_search, result->file_filter, result->is_recursive, &result->mem_bucket, - &result->cancel_search, - &result->done_finding_files); - find_text_in_files(result); - - while(!result->threads_closed) { thread_sleep(1000); } - - if (!string_equals(export_path, "")) - { - export_results(result); - } -#endif -}
\ No newline at end of file diff --git a/src/command_line.h b/src/command_line.h deleted file mode 100644 index 74daa8d..0000000 --- a/src/command_line.h +++ /dev/null @@ -1,12 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#ifndef INCLUDE_COMMAND_LINE -#define INCLUDE_COMMAND_LINE - -void handle_command_line_arguments(int argc, char **argv); - -#endif
\ No newline at end of file diff --git a/src/settings.c b/src/settings.c deleted file mode 100644 index b379470..0000000 --- a/src/settings.c +++ /dev/null @@ -1,313 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -void reset_status_text(); -void set_status_text_to_finished_search(); - -void settings_page_create() -{ - global_settings_page.active = false; - global_settings_page.font_small = assets_load_font(_binary____data_fonts_mono_ttf_start, - _binary____data_fonts_mono_ttf_end, 16); - global_settings_page.logo_img = assets_load_image(_binary____data_imgs_logo_64_png_start, - _binary____data_imgs_logo_64_png_end, true); - global_settings_page.keyboard = keyboard_input_create(); - global_settings_page.mouse = mouse_input_create(); - - camera cam; - cam.x = 0; - cam.y = 0; - cam.rotation = 0; - - global_settings_page.camera = cam; - - global_settings_page.btn_close = ui_create_button(); - global_settings_page.btn_save = ui_create_button(); - global_settings_page.dropdown_language = ui_create_dropdown(); - global_settings_page.dropdown_doubleclick = ui_create_dropdown(); - global_settings_page.textbox_max_file_size = ui_create_textbox(9); - global_settings_page.textbox_max_thread_count = ui_create_textbox(5); - global_settings_page.checkbox_parallelize_search = ui_create_checkbox(false); -} - -static void load_current_settings_into_ui() -{ - if (global_settings_page.max_thread_count != 0) - snprintf(global_settings_page.textbox_max_thread_count.buffer, global_settings_page.textbox_max_thread_count.max_len, "%d",global_settings_page.max_thread_count); - - if (global_settings_page.max_file_size != 0) - snprintf(global_settings_page.textbox_max_file_size.buffer, global_settings_page.textbox_max_file_size.max_len, "%d", global_settings_page.max_file_size); -} - -void settings_page_update_render() -{ - if (global_settings_page.active) - { - platform_window_make_current(&global_settings_page.window); - platform_handle_events(&global_settings_page.window, &global_settings_page.mouse, &global_settings_page.keyboard); - platform_set_cursor(&global_settings_page.window, CURSOR_DEFAULT); - - render_clear(); - - camera_apply_transformations(&global_settings_page.window, &global_settings_page.camera); - - global_ui_context.layout.active_window = &global_settings_page.window; - global_ui_context.keyboard = &global_settings_page.keyboard; - global_ui_context.mouse = &global_settings_page.mouse; - - ui_begin(3); - { - ui_begin_menu_bar(); - { - if (ui_push_menu(localize("general"))) - { - global_settings_page.selected_tab_index = 0; - } - if (ui_push_menu(localize("interface"))) - { - global_settings_page.selected_tab_index = 1; - } - } - ui_end_menu_bar(); - - ui_push_separator(); - - if (global_settings_page.selected_tab_index == 0) - { - ///////////////////////////////////// - // max file size - ///////////////////////////////////// - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_text(localize("max_file_size")); - ui_push_text(localize("zero_for_no_limit")); - } - ui_block_end(); - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_textbox(&global_settings_page.textbox_max_file_size, "0")) - { - keyboard_set_input_mode(&global_settings_page.keyboard, INPUT_NUMERIC); - } - ui_push_text("KB"); - } - ui_block_end(); - - ///////////////////////////////////// - // max threads - ///////////////////////////////////// - global_ui_context.layout.offset_y += 10; - - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_text(localize("max_threads")); - ui_push_text(localize("minimum_of_1")); - } - ui_block_end(); - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_textbox(&global_settings_page.textbox_max_thread_count, "0")) - { - keyboard_set_input_mode(&global_settings_page.keyboard, INPUT_NUMERIC); - } - ui_push_text("Threads"); - - } - ui_block_end(); - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_hypertext_link(localize("copy_config_path"))) - { - char buffer[PATH_MAX]; - platform_set_clipboard(main_window, get_config_save_location(buffer)); - } - } - ui_block_end(); - } - else if (global_settings_page.selected_tab_index == 1) - { - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_text(localize("language")); - } - ui_block_end(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_dropdown(&global_settings_page.dropdown_language, locale_get_name())) - { - for (s32 i = 0; i < global_localization.mo_files.length; i++) - { - mo_file *file = array_at(&global_localization.mo_files, i); - - if (ui_push_dropdown_item(file->icon, file->locale_full, i)) - { - set_locale(file->locale_id); - } - } - } - } - ui_block_end(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_text(localize("double_click_action")); - } - ui_block_end(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - char* available_options[OPTION_RESULT+1] = { - localize("double_click_action_1"), - localize("double_click_action_2"), - localize("double_click_action_3"), - localize("double_click_action_4"), - }; - - if (ui_push_dropdown(&global_settings_page.dropdown_doubleclick, available_options[global_settings_page.current_double_click_selection_option])) - { - for (s32 i = 0; i < OPTION_RESULT+1; i++) - { - if (ui_push_dropdown_item(0, available_options[i], i)) - { - global_settings_page.current_double_click_selection_option = i; - } - } - } - } - ui_block_end(); - -#if 0 - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_text("Style"); - } - ui_block_end(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_color_button("Light", global_ui_context.style.id == UI_STYLE_LIGHT, rgb(250, 250, 250))) - { - ui_set_style(UI_STYLE_LIGHT); - } - if (ui_push_color_button("Dark", global_ui_context.style.id == UI_STYLE_DARK, rgb(50, 50, 50))) - { - ui_set_style(UI_STYLE_DARK); - } - } - ui_block_end(); -#endif - } - - global_ui_context.layout.offset_y = global_settings_page.window.height - 33; - - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_button(&global_settings_page.btn_close, localize("close"))) - { - global_settings_page.textbox_max_thread_count.buffer[0] = 0; - global_settings_page.textbox_max_file_size.buffer[0] = 0; - ui_set_style(global_settings_page.current_style); - global_settings_page.current_double_click_selection_option = global_settings_page.selected_double_click_selection_option; - global_settings_page.active = false; - set_locale(global_settings_page.current_locale_id); - settings_page_hide(); - - return; - } - if (ui_push_button(&global_settings_page.btn_close, localize("save"))) - { - global_settings_page.current_style = global_ui_context.style.id; - global_settings_page.max_thread_count = string_to_s32(global_settings_page.textbox_max_thread_count.buffer); - if (global_settings_page.max_thread_count < 1) - global_settings_page.max_thread_count = DEFAULT_THREAD_COUNT; - - global_settings_page.max_file_size = string_to_s32(global_settings_page.textbox_max_file_size.buffer); - - global_settings_page.textbox_max_thread_count.buffer[0] = 0; - global_settings_page.textbox_max_file_size.buffer[0] = 0; - global_settings_page.selected_double_click_selection_option = global_settings_page.current_double_click_selection_option; - - global_settings_page.active = false; - settings_page_hide(); - return; - } - } - ui_block_end(); - } - ui_end(); - - if (!global_settings_page.window.is_open) - { - global_settings_page.active = false; - settings_page_hide(); - return; - } - - platform_window_swap_buffers(&global_settings_page.window); - } -} - -void settings_page_show() -{ - if (platform_window_is_valid(&global_settings_page.window)) return; - - load_current_settings_into_ui(); - - global_settings_page.window = platform_open_window(localize("text_search_settings"), - 450, 280, 450, 280, 450, 280); - - settings_window = &global_settings_page.window; - - global_settings_page.active = true; - global_settings_page.selected_tab_index = 0; - global_settings_page.current_locale_id = locale_get_id(); - global_settings_page.current_double_click_selection_option = global_settings_page.selected_double_click_selection_option; - - platform_set_icon(&global_settings_page.window, global_settings_page.logo_img); -} - -void settings_page_hide() -{ - if (platform_window_is_valid(&global_settings_page.window)) - { - settings_window = 0; - - platform_destroy_window(&global_settings_page.window); - - global_settings_page.btn_close.state = false; - global_settings_page.btn_save.state = false; - global_settings_page.active = false; - - global_settings_page.mouse.x = -1; - global_settings_page.mouse.y = -1; - } -} - -void settings_page_hide_without_save() -{ - if (platform_window_is_valid(&global_settings_page.window)) - { - global_settings_page.textbox_max_thread_count.buffer[0] = 0; - global_settings_page.textbox_max_file_size.buffer[0] = 0; - - global_settings_page.active = false; - set_locale(global_settings_page.current_locale_id); - settings_page_hide(); - } -} - -void settings_page_destroy() -{ - keyboard_input_destroy(&global_settings_page.keyboard); - ui_destroy_textbox(&global_settings_page.textbox_max_file_size); - ui_destroy_textbox(&global_settings_page.textbox_max_thread_count); - assets_destroy_font(global_settings_page.font_small); - assets_destroy_image(global_settings_page.logo_img); - - if (platform_window_is_valid(&global_settings_page.window)) - platform_destroy_window(&global_settings_page.window); -} diff --git a/src/settings.h b/src/settings.h deleted file mode 100644 index 11ab307..0000000 --- a/src/settings.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#ifndef INCLUDE_SETTINGS -#define INCLUDE_SETTINGS - -typedef enum t_double_click_option -{ - OPTION_PATH, - OPTION_PATH_LINE, - OPTION_PATH_LINE_FILTER, - OPTION_RESULT, -} double_click_option; - -typedef struct t_settings_page -{ - platform_window window; - keyboard_input keyboard; - mouse_input mouse; - camera camera; - bool active; - - font *font_small; - image *logo_img; - - button_state btn_close; - button_state btn_save; - dropdown_state dropdown_language; - dropdown_state dropdown_doubleclick; - textbox_state textbox_max_file_size; - textbox_state textbox_max_thread_count; - checkbox_state checkbox_parallelize_search; - s32 selected_tab_index; - - char *current_locale_id; - s32 max_thread_count; - s32 max_file_size; - u16 current_style; - u16 selected_double_click_selection_option; // saved state - u16 current_double_click_selection_option; // unsaved state -} settings_page; - -#define DEFAULT_THREAD_COUNT 10 -#define DEFAULT_MAX_FILE_SIZE 0 -#define DEFAULT_RECURSIVE_STATE 1 -#define DEFAULT_STYLE 1 - -settings_page global_settings_page; - -void settings_page_create(); -void settings_page_hide_without_save(); -void settings_page_update_render(); -void settings_page_show(); -void settings_page_hide(); -void settings_page_destroy(); - -#endif
\ No newline at end of file |
