|
|
|
@ -35,14 +35,14 @@
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
#include "../src/tty/tty.h"
|
|
|
|
|
#include "../src/skin/skin.h"
|
|
|
|
|
#include "../src/tty/key.h"
|
|
|
|
|
#include "../src/skin/skin.h"
|
|
|
|
|
#include "../src/search/search.h"
|
|
|
|
|
#include "../src/mcconfig/mcconfig.h"
|
|
|
|
|
|
|
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
|
|
|
|
|
|
#include "setup.h"
|
|
|
|
|
#include "find.h"
|
|
|
|
|
#include "setup.h" /* verbose */
|
|
|
|
|
#include "strutil.h"
|
|
|
|
|
#include "dialog.h"
|
|
|
|
|
#include "widget.h"
|
|
|
|
@ -55,6 +55,8 @@
|
|
|
|
|
#include "history.h" /* MC_HISTORY_SHARED_SEARCH */
|
|
|
|
|
#include "layout.h" /* mc_refresh() */
|
|
|
|
|
|
|
|
|
|
#include "find.h"
|
|
|
|
|
|
|
|
|
|
/* Size of the find parameters window */
|
|
|
|
|
#if HAVE_CHARSET
|
|
|
|
|
static int FIND_Y = 16;
|
|
|
|
@ -151,21 +153,89 @@ static struct {
|
|
|
|
|
{ N_("&Edit - F4"), 13, 38 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* find file options */
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
/* file name options */
|
|
|
|
|
gboolean file_case_sens;
|
|
|
|
|
gboolean file_pattern;
|
|
|
|
|
gboolean find_recurs;
|
|
|
|
|
gboolean skip_hidden;
|
|
|
|
|
gboolean file_all_charsets;
|
|
|
|
|
|
|
|
|
|
/* file content options */
|
|
|
|
|
gboolean content_case_sens;
|
|
|
|
|
gboolean content_regexp;
|
|
|
|
|
gboolean content_first_hit;
|
|
|
|
|
gboolean content_whole_words;
|
|
|
|
|
gboolean content_all_charsets;
|
|
|
|
|
} find_file_options_t;
|
|
|
|
|
|
|
|
|
|
static find_file_options_t options =
|
|
|
|
|
{
|
|
|
|
|
TRUE, TRUE, TRUE, FALSE, FALSE,
|
|
|
|
|
TRUE, FALSE, FALSE, FALSE, FALSE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static char *in_start_dir = INPUT_LAST_TEXT;
|
|
|
|
|
|
|
|
|
|
static mc_search_t *search_file_handle = NULL;
|
|
|
|
|
static gboolean skip_hidden_flag = FALSE;
|
|
|
|
|
static gboolean file_pattern_flag = TRUE;
|
|
|
|
|
static gboolean file_all_charsets_flag = FALSE;
|
|
|
|
|
static gboolean file_case_sens_flag = TRUE;
|
|
|
|
|
static gboolean find_recurs_flag = TRUE;
|
|
|
|
|
|
|
|
|
|
static mc_search_t *search_content_handle = NULL;
|
|
|
|
|
static gboolean content_regexp_flag = FALSE;
|
|
|
|
|
static gboolean content_all_charsets_flag = FALSE;
|
|
|
|
|
static gboolean content_case_sens_flag = TRUE;
|
|
|
|
|
static gboolean content_first_hit_flag = FALSE;
|
|
|
|
|
static gboolean content_whole_words = FALSE;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
find_load_options (void)
|
|
|
|
|
{
|
|
|
|
|
static gboolean loaded = FALSE;
|
|
|
|
|
char *ignore_dirs;
|
|
|
|
|
|
|
|
|
|
if (loaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
loaded = TRUE;
|
|
|
|
|
|
|
|
|
|
/* Back compatibility: try load old parameter at first */
|
|
|
|
|
ignore_dirs = mc_config_get_string (mc_main_config, "Misc", "find_ignore_dirs", "");
|
|
|
|
|
if (ignore_dirs [0] != '\0') {
|
|
|
|
|
find_ignore_dirs = g_strconcat (":", ignore_dirs, ":", (char *) NULL);
|
|
|
|
|
mc_config_set_string (mc_main_config, "FindFile", "ignore_dirs", ignore_dirs);
|
|
|
|
|
}
|
|
|
|
|
g_free (ignore_dirs);
|
|
|
|
|
mc_config_del_param (mc_main_config, "Misc", "find_ignore_dirs");
|
|
|
|
|
|
|
|
|
|
/* Then load new parameters */
|
|
|
|
|
ignore_dirs = mc_config_get_string (mc_main_config, "FindFile", "ignore_dirs", "");
|
|
|
|
|
if (ignore_dirs [0] != '\0') {
|
|
|
|
|
g_free (find_ignore_dirs);
|
|
|
|
|
find_ignore_dirs = g_strconcat (":", ignore_dirs, ":", (char *) NULL);
|
|
|
|
|
}
|
|
|
|
|
g_free (ignore_dirs);
|
|
|
|
|
|
|
|
|
|
options.file_case_sens = mc_config_get_bool (mc_main_config, "FindFile", "file_case_sens", TRUE);
|
|
|
|
|
options.file_pattern = mc_config_get_bool (mc_main_config, "FindFile", "file_shell_pattern", TRUE);
|
|
|
|
|
options.find_recurs = mc_config_get_bool (mc_main_config, "FindFile", "file_find_recurs", TRUE);
|
|
|
|
|
options.skip_hidden = mc_config_get_bool (mc_main_config, "FindFile", "file_skip_hidden", FALSE);
|
|
|
|
|
options.file_all_charsets = mc_config_get_bool (mc_main_config, "FindFile", "file_all_charsets", FALSE);
|
|
|
|
|
options.content_case_sens = mc_config_get_bool (mc_main_config, "FindFile", "content_case_sens", TRUE);
|
|
|
|
|
options.content_regexp = mc_config_get_bool (mc_main_config, "FindFile", "content_regexp", FALSE);
|
|
|
|
|
options.content_first_hit = mc_config_get_bool (mc_main_config, "FindFile", "content_first_hit", FALSE);
|
|
|
|
|
options.content_whole_words = mc_config_get_bool (mc_main_config, "FindFile", "content_whole_words", FALSE);
|
|
|
|
|
options.content_all_charsets = mc_config_get_bool (mc_main_config, "FindFile", "content_all_charsets", FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
find_save_options (void)
|
|
|
|
|
{
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "file_case_sens", options.file_case_sens);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "file_shell_pattern", options.file_pattern);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "file_find_recurs", options.find_recurs);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "file_skip_hidden", options.skip_hidden);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "file_all_charsets", options.file_all_charsets);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "content_case_sens", options.content_case_sens);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "content_regexp", options.content_regexp);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "content_first_hit", options.content_first_hit);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "content_whole_words", options.content_whole_words);
|
|
|
|
|
mc_config_set_bool (mc_main_config, "FindFile", "content_all_charsets", options.content_all_charsets);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline char *
|
|
|
|
|
add_to_list (const char *text, void *data)
|
|
|
|
@ -260,7 +330,7 @@ find_parm_callback (Dlg_head *h, Widget *sender,
|
|
|
|
|
/*
|
|
|
|
|
* find_parameters: gets information from the user
|
|
|
|
|
*
|
|
|
|
|
* If the return value is true, then the following holds:
|
|
|
|
|
* If the return value is TRUE, then the following holds:
|
|
|
|
|
*
|
|
|
|
|
* START_DIR and PATTERN are pointers to char * and upon return they
|
|
|
|
|
* contain the information provided by the user.
|
|
|
|
@ -270,10 +340,10 @@ find_parm_callback (Dlg_head *h, Widget *sender,
|
|
|
|
|
* behavior for the other two parameters.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
static gboolean
|
|
|
|
|
find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
{
|
|
|
|
|
int return_value;
|
|
|
|
|
gboolean return_value;
|
|
|
|
|
char *temp_dir = NULL;
|
|
|
|
|
|
|
|
|
|
/* file name */
|
|
|
|
@ -323,7 +393,9 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
b1 = str_term_width1 (buts[1]) + 4;
|
|
|
|
|
b2 = str_term_width1 (buts[2]) + 4;
|
|
|
|
|
|
|
|
|
|
find_par_start:
|
|
|
|
|
find_load_options ();
|
|
|
|
|
|
|
|
|
|
find_par_start:
|
|
|
|
|
if (in_start_dir == NULL)
|
|
|
|
|
in_start_dir = g_strdup (".");
|
|
|
|
|
|
|
|
|
@ -339,38 +411,38 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
|
content_all_charsets_cbox = check_new (11, FIND_X / 2 + 1,
|
|
|
|
|
content_all_charsets_flag, content_all_charsets_label);
|
|
|
|
|
options.content_all_charsets, content_all_charsets_label);
|
|
|
|
|
add_widget (find_dlg, content_all_charsets_cbox);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
content_whole_words_cbox = check_new (10, FIND_X / 2 + 1, content_whole_words, content_whole_words_label);
|
|
|
|
|
content_whole_words_cbox = check_new (10, FIND_X / 2 + 1, options.content_whole_words, content_whole_words_label);
|
|
|
|
|
add_widget (find_dlg, content_whole_words_cbox);
|
|
|
|
|
|
|
|
|
|
content_first_hit_cbox = check_new (9, FIND_X / 2 + 1, content_first_hit_flag, content_first_hit_label);
|
|
|
|
|
content_first_hit_cbox = check_new (9, FIND_X / 2 + 1, options.content_first_hit, content_first_hit_label);
|
|
|
|
|
add_widget (find_dlg, content_first_hit_cbox);
|
|
|
|
|
|
|
|
|
|
content_regexp_cbox = check_new (8, FIND_X / 2 + 1, content_regexp_flag, content_regexp_label);
|
|
|
|
|
content_regexp_cbox = check_new (8, FIND_X / 2 + 1, options.content_regexp, content_regexp_label);
|
|
|
|
|
add_widget (find_dlg, content_regexp_cbox);
|
|
|
|
|
|
|
|
|
|
content_case_sens_cbox = check_new (7, FIND_X / 2 + 1, content_case_sens_flag, content_case_label);
|
|
|
|
|
content_case_sens_cbox = check_new (7, FIND_X / 2 + 1, options.content_case_sens, content_case_label);
|
|
|
|
|
add_widget (find_dlg, content_case_sens_cbox);
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
|
file_all_charsets_cbox = check_new (11, 3,
|
|
|
|
|
file_all_charsets_flag, file_all_charsets_label);
|
|
|
|
|
options.file_all_charsets, file_all_charsets_label);
|
|
|
|
|
add_widget (find_dlg, file_all_charsets_cbox);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
skip_hidden_cbox = check_new (10, 3, skip_hidden_flag, file_skip_hidden_label);
|
|
|
|
|
skip_hidden_cbox = check_new (10, 3, options.skip_hidden, file_skip_hidden_label);
|
|
|
|
|
add_widget (find_dlg, skip_hidden_cbox);
|
|
|
|
|
|
|
|
|
|
recursively_cbox = check_new (9, 3, find_recurs_flag, file_recurs_label);
|
|
|
|
|
recursively_cbox = check_new (9, 3, options.find_recurs, file_recurs_label);
|
|
|
|
|
add_widget (find_dlg, recursively_cbox);
|
|
|
|
|
|
|
|
|
|
file_pattern_cbox = check_new (8, 3, file_pattern_flag, file_pattern_label);
|
|
|
|
|
file_pattern_cbox = check_new (8, 3, options.file_pattern, file_pattern_label);
|
|
|
|
|
add_widget (find_dlg, file_pattern_cbox);
|
|
|
|
|
|
|
|
|
|
file_case_sens_cbox = check_new (7, 3, file_case_sens_flag, file_case_label);
|
|
|
|
|
file_case_sens_cbox = check_new (7, 3, options.file_case_sens, file_case_label);
|
|
|
|
|
add_widget (find_dlg, file_case_sens_cbox);
|
|
|
|
|
|
|
|
|
|
in_with = input_new (6, FIND_X / 2 + 1, INPUT_COLOR, FIND_X / 2 - 4, INPUT_LAST_TEXT,
|
|
|
|
@ -395,22 +467,22 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
|
|
|
|
|
switch (run_dlg (find_dlg)) {
|
|
|
|
|
case B_CANCEL:
|
|
|
|
|
return_value = 0;
|
|
|
|
|
return_value = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case B_TREE:
|
|
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
|
file_all_charsets_flag = file_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
options.file_all_charsets = file_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
options.content_all_charsets = content_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
#endif
|
|
|
|
|
content_case_sens_flag = content_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
content_regexp_flag = content_regexp_cbox->state & C_BOOL;
|
|
|
|
|
content_first_hit_flag = content_first_hit_cbox->state & C_BOOL;
|
|
|
|
|
content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
|
|
|
|
file_pattern_flag = file_pattern_cbox->state & C_BOOL;
|
|
|
|
|
file_case_sens_flag = file_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
find_recurs_flag = recursively_cbox->state & C_BOOL;
|
|
|
|
|
skip_hidden_flag = skip_hidden_cbox->state & C_BOOL;
|
|
|
|
|
options.content_case_sens = content_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
options.content_regexp = content_regexp_cbox->state & C_BOOL;
|
|
|
|
|
options.content_first_hit = content_first_hit_cbox->state & C_BOOL;
|
|
|
|
|
options.content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
|
|
|
|
options.file_pattern = file_pattern_cbox->state & C_BOOL;
|
|
|
|
|
options.file_case_sens = file_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
options.find_recurs = recursively_cbox->state & C_BOOL;
|
|
|
|
|
options.skip_hidden = skip_hidden_cbox->state & C_BOOL;
|
|
|
|
|
|
|
|
|
|
destroy_dlg (find_dlg);
|
|
|
|
|
if (in_start_dir != INPUT_LAST_TEXT)
|
|
|
|
@ -431,17 +503,17 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
|
file_all_charsets_flag = file_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
options.file_all_charsets = file_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
options.content_all_charsets = content_all_charsets_cbox->state & C_BOOL;
|
|
|
|
|
#endif
|
|
|
|
|
content_case_sens_flag = content_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
content_regexp_flag = content_regexp_cbox->state & C_BOOL;
|
|
|
|
|
content_first_hit_flag = content_first_hit_cbox->state & C_BOOL;
|
|
|
|
|
content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
|
|
|
|
find_recurs_flag = recursively_cbox->state & C_BOOL;
|
|
|
|
|
file_pattern_flag = file_pattern_cbox->state & C_BOOL;
|
|
|
|
|
file_case_sens_flag = file_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
skip_hidden_flag = skip_hidden_cbox->state & C_BOOL;
|
|
|
|
|
options.content_case_sens = content_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
options.content_regexp = content_regexp_cbox->state & C_BOOL;
|
|
|
|
|
options.content_first_hit = content_first_hit_cbox->state & C_BOOL;
|
|
|
|
|
options.content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
|
|
|
|
options.find_recurs = recursively_cbox->state & C_BOOL;
|
|
|
|
|
options.file_pattern = file_pattern_cbox->state & C_BOOL;
|
|
|
|
|
options.file_case_sens = file_case_sens_cbox->state & C_BOOL;
|
|
|
|
|
options.skip_hidden = skip_hidden_cbox->state & C_BOOL;
|
|
|
|
|
|
|
|
|
|
*content = (in_with->buffer[0] != '\0') ? g_strdup (in_with->buffer) : NULL;
|
|
|
|
|
*start_dir = g_strdup ((in_start->buffer[0] != '\0') ? in_start->buffer : ".");
|
|
|
|
@ -449,7 +521,10 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
|
if (in_start_dir != INPUT_LAST_TEXT)
|
|
|
|
|
g_free (in_start_dir);
|
|
|
|
|
in_start_dir = g_strdup (*start_dir);
|
|
|
|
|
return_value = 1;
|
|
|
|
|
|
|
|
|
|
find_save_options ();
|
|
|
|
|
|
|
|
|
|
return_value = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
destroy_dlg (find_dlg);
|
|
|
|
@ -704,7 +779,7 @@ search_content (Dlg_head *h, const char *directory, const char *filename)
|
|
|
|
|
}
|
|
|
|
|
g_free (p);
|
|
|
|
|
|
|
|
|
|
if (found && content_first_hit_flag)
|
|
|
|
|
if (found && options.content_first_hit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (has_newline) {
|
|
|
|
@ -763,16 +838,16 @@ do_search (struct Dlg_head *h)
|
|
|
|
|
|
|
|
|
|
search_content_handle = mc_search_new(content_pattern, -1);
|
|
|
|
|
if (search_content_handle) {
|
|
|
|
|
search_content_handle->search_type = (content_regexp_flag) ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL;
|
|
|
|
|
search_content_handle->is_case_sentitive = content_case_sens_flag;
|
|
|
|
|
search_content_handle->whole_words = content_whole_words;
|
|
|
|
|
search_content_handle->is_all_charsets = content_all_charsets_flag;
|
|
|
|
|
search_content_handle->search_type = options.content_regexp ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL;
|
|
|
|
|
search_content_handle->is_case_sentitive = options.content_case_sens;
|
|
|
|
|
search_content_handle->whole_words = options.content_whole_words;
|
|
|
|
|
search_content_handle->is_all_charsets = options.content_all_charsets;
|
|
|
|
|
}
|
|
|
|
|
search_file_handle = mc_search_new(find_pattern, -1);
|
|
|
|
|
search_file_handle->search_type = (file_pattern_flag) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
|
|
|
|
search_file_handle->is_case_sentitive = file_case_sens_flag;
|
|
|
|
|
search_file_handle->is_all_charsets = file_all_charsets_flag;
|
|
|
|
|
search_file_handle->is_entire_line = file_pattern_flag;
|
|
|
|
|
search_file_handle->search_type = options.file_pattern ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
|
|
|
|
search_file_handle->is_case_sentitive = options.file_case_sens;
|
|
|
|
|
search_file_handle->is_all_charsets = options.file_all_charsets;
|
|
|
|
|
search_file_handle->is_entire_line = options.file_pattern;
|
|
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
|
@ -857,10 +932,10 @@ do_search (struct Dlg_head *h)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(skip_hidden_flag && (dp->d_name[0] == '.'))) {
|
|
|
|
|
if (!(options.skip_hidden && (dp->d_name[0] == '.'))) {
|
|
|
|
|
gboolean search_ok;
|
|
|
|
|
|
|
|
|
|
if ((subdirs_left != 0) && find_recurs_flag
|
|
|
|
|
if ((subdirs_left != 0) && options.find_recurs
|
|
|
|
|
&& (directory != NULL)) { /* Can directory be NULL ? */
|
|
|
|
|
char *tmp_name = concat_dir_and_file (directory, dp->d_name);
|
|
|
|
|
if (!mc_lstat (tmp_name, &tmp_stat)
|
|
|
|
|