1 /* Find file command for the Midnight Commander
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
4 Written 1995 by Miguel de Icaza
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
30 #include <mhl/types.h>
31 #include <mhl/memory.h>
32 #include <mhl/string.h>
41 /* Dialog manager and widgets */
46 #include "panel.h" /* current_panel */
47 #include "main.h" /* do_cd, try_to_select */
49 #include "cmd.h" /* view_file_at_line */
53 /* Size of the find parameters window */
55 static int FIND_X
= 50;
57 /* Size of the find window */
58 #define FIND2_Y (LINES - 4)
60 static int FIND2_X
= 64;
61 #define FIND2_X_USE (FIND2_X - 20)
63 /* A couple of extra messages we need */
78 /* List of directories to be ignored, separated by ':' */
79 char *find_ignore_dirs
= 0;
81 static WInput
*in_start
; /* Start path */
82 static WInput
*in_name
; /* Pattern to search */
83 static WInput
*in_with
; /* Text inside filename */
84 static WCheck
*case_sense
; /* "case sensitive" checkbox */
85 static WCheck
*find_regex_cbox
; /* [x] find regular expression */
87 static int running
= 0; /* nice flag */
88 static char *find_pattern
; /* Pattern to search */
89 static char *content_pattern
; /* pattern to search inside files; if
90 find_regex_flag is true, it contains the
91 regex pattern, else the search string. */
92 static int count
; /* Number of files displayed */
93 static int matches
; /* Number of matches */
94 static int is_start
; /* Status of the start/stop toggle button */
97 /* Where did we stop */
102 static Dlg_head
*find_dlg
; /* The dialog */
104 static WButton
*stop_button
; /* pointer to the stop button */
105 static WLabel
*status_label
; /* Finished, Searching etc. */
106 static WListbox
*find_list
; /* Listbox with the file list */
108 /* This keeps track of the directory stack */
109 typedef struct dir_stack
{
111 struct dir_stack
*prev
;
114 static dir_stack
*dir_stack_base
= 0;
118 int len
; /* length including space and brackets */
121 { N_("&Suspend"), 11, 29 },
122 { N_("Con&tinue"), 12, 29 },
123 { N_("&Chdir"), 11, 3 },
124 { N_("&Again"), 9, 17 },
125 { N_("&Quit"), 8, 43 },
126 { N_("Pane&lize"), 12, 3 },
127 { N_("&View - F3"), 13, 20 },
128 { N_("&Edit - F4"), 13, 38 }
131 static inline char * add_to_list (const char *text
, void *data
) {
132 return listbox_add_item (find_list
, 0, 0, text
, data
);
134 static inline void stop_idle (void *data
) {
135 set_idle_proc (data
, 0);
137 static inline void status_update (const char *text
) {
138 label_set_text (status_label
, text
);
140 static void get_list_info (char **file
, char **dir
) {
141 listbox_get_current (find_list
, file
, dir
);
144 /* FIXME: r should be local variable */
145 static regex_t
*r
; /* Pointer to compiled content_pattern */
147 static int case_sensitive
= 1;
148 static gboolean find_regex_flag
= TRUE
;
149 static int find_recursively
= 1;
152 * Callback for the parameter dialog.
153 * Validate regex, prevent closing the dialog if it's invalid.
156 find_parm_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
162 if ((h
->ret_value
!= B_ENTER
) || !in_with
->buffer
[0]
163 || !(find_regex_cbox
->state
& C_BOOL
))
166 flags
= REG_EXTENDED
| REG_NOSUB
;
168 if (!(case_sense
->state
& C_BOOL
))
171 if (regcomp (r
, in_with
->buffer
, flags
)) {
172 message (D_ERROR
, MSG_ERROR
, _(" Malformed regular expression "));
173 dlg_select_widget (in_with
);
174 h
->running
= 1; /* Don't stop the dialog */
179 return default_dlg_callback (h
, msg
, parm
);
184 * find_parameters: gets information from the user
186 * If the return value is true, then the following holds:
188 * START_DIR and PATTERN are pointers to char * and upon return they
189 * contain the information provided by the user.
191 * CONTENT holds a strdup of the contents specified by the user if he
192 * asked for them or 0 if not (note, this is different from the
193 * behavior for the other two parameters.
197 find_parameters (char **start_dir
, char **pattern
, char **content
)
201 static const char *case_label
= N_("case &Sensitive");
202 static const char *recurs_label
= N_("&Find recursively");
204 WCheck
*recursively_cbox
;
206 static char *in_contents
= NULL
;
207 static char *in_start_dir
= NULL
;
208 static char *in_start_name
= NULL
;
210 static const char *labs
[] =
211 { N_("Start at:"), N_("Filename:"), N_("Content: ") };
212 static const char *buts
[] = { N_("&OK"), N_("&Tree"), N_("&Cancel") };
213 static int ilen
= 30, istart
= 14;
214 static int b0
= 3, b1
= 16, b2
= 36;
217 static int i18n_flag
= 0;
220 register int i
= sizeof (labs
) / sizeof (labs
[0]);
224 l1
= strlen (labs
[i
] = _(labs
[i
]));
228 i
= maxlen
+ ilen
+ 7;
232 for (i
= sizeof (buts
) / sizeof (buts
[0]), l1
= 0; i
--;) {
233 l1
+= strlen (buts
[i
] = _(buts
[i
]));
239 ilen
= FIND_X
- 7 - maxlen
; /* for the case of very long buttons :) */
240 istart
= FIND_X
- 3 - ilen
;
242 b1
= b0
+ strlen (buts
[0]) + 7;
243 b2
= FIND_X
- (strlen (buts
[2]) + 6);
246 case_label
= _(case_label
);
247 recurs_label
= _(recurs_label
);
249 #endif /* ENABLE_NLS */
253 in_start_dir
= g_strdup (".");
255 in_start_name
= g_strdup (easy_patterns
? "*" : ".");
257 in_contents
= g_strdup ("");
260 create_dlg (0, 0, FIND_Y
, FIND_X
, dialog_colors
,
261 find_parm_callback
, "[Find File]", _("Find File"),
262 DLG_CENTER
| DLG_REVERSE
);
264 add_widget (find_dlg
,
265 button_new (12, b2
, B_CANCEL
, NORMAL_BUTTON
, buts
[2], 0));
266 add_widget (find_dlg
,
267 button_new (12, b1
, B_TREE
, NORMAL_BUTTON
, buts
[1], 0));
268 add_widget (find_dlg
,
269 button_new (12, b0
, B_ENTER
, DEFPUSH_BUTTON
, buts
[0], 0));
272 check_new (6, istart
, find_recursively
, recurs_label
);
274 find_regex_cbox
= check_new (10, istart
, find_regex_flag
, _("&Regular expression"));
275 add_widget (find_dlg
, find_regex_cbox
);
277 case_sense
= check_new (9, istart
, case_sensitive
, case_label
);
278 add_widget (find_dlg
, case_sense
);
281 input_new (8, istart
, INPUT_COLOR
, ilen
, in_contents
, "content", INPUT_COMPLETE_DEFAULT
);
282 add_widget (find_dlg
, in_with
);
284 add_widget (find_dlg
, recursively_cbox
);
286 input_new (5, istart
, INPUT_COLOR
, ilen
, in_start_name
, "name", INPUT_COMPLETE_DEFAULT
);
287 add_widget (find_dlg
, in_name
);
290 input_new (3, istart
, INPUT_COLOR
, ilen
, in_start_dir
, "start", INPUT_COMPLETE_DEFAULT
);
291 add_widget (find_dlg
, in_start
);
293 add_widget (find_dlg
, label_new (8, 3, labs
[2]));
294 add_widget (find_dlg
, label_new (5, 3, labs
[1]));
295 add_widget (find_dlg
, label_new (3, 3, labs
[0]));
297 dlg_select_widget (in_name
);
301 switch (find_dlg
->ret_value
) {
307 temp_dir
= g_strdup (in_start
->buffer
);
308 case_sensitive
= case_sense
->state
& C_BOOL
;
309 find_regex_flag
= find_regex_cbox
->state
& C_BOOL
;
310 find_recursively
= recursively_cbox
->state
& C_BOOL
;
311 destroy_dlg (find_dlg
);
312 g_free (in_start_dir
);
313 if (strcmp (temp_dir
, ".") == 0) {
315 temp_dir
= g_strdup (current_panel
->cwd
);
317 in_start_dir
= tree_box (temp_dir
);
321 in_start_dir
= temp_dir
;
322 /* Warning: Dreadful goto */
327 g_free (in_contents
);
328 if (in_with
->buffer
[0]) {
329 *content
= g_strdup (in_with
->buffer
);
330 in_contents
= g_strdup (*content
);
332 *content
= in_contents
= NULL
;
336 case_sensitive
= case_sense
->state
& C_BOOL
;
337 find_regex_flag
= find_regex_cbox
->state
& C_BOOL
;
338 find_recursively
= recursively_cbox
->state
& C_BOOL
;
340 *start_dir
= g_strdup (in_start
->buffer
);
341 *pattern
= g_strdup (in_name
->buffer
);
343 g_free (in_start_dir
);
344 in_start_dir
= g_strdup (*start_dir
);
345 g_free (in_start_name
);
346 in_start_name
= g_strdup (*pattern
);
349 destroy_dlg (find_dlg
);
355 push_directory (const char *dir
)
359 new = g_new (dir_stack
, 1);
360 new->name
= mhl_str_dir_plus_file (dir
, NULL
);
361 new->prev
= dir_stack_base
;
362 dir_stack_base
= new;
372 name
= dir_stack_base
->name
;
373 next
= dir_stack_base
->prev
;
374 g_free (dir_stack_base
);
375 dir_stack_base
= next
;
382 insert_file (const char *dir
, const char *file
)
385 static char *dirname
;
387 while (dir
[0] == PATH_SEP
&& dir
[1] == PATH_SEP
)
391 if (strcmp (old_dir
, dir
)){
393 old_dir
= g_strdup (dir
);
394 dirname
= add_to_list (dir
, NULL
);
397 old_dir
= g_strdup (dir
);
398 dirname
= add_to_list (dir
, NULL
);
401 tmp_name
= g_strconcat (" ", file
, (char *) NULL
);
402 add_to_list (tmp_name
, dirname
);
407 find_add_match (Dlg_head
*h
, const char *dir
, const char *file
)
409 int p
= ++matches
& 7;
413 insert_file (dir
, file
);
417 listbox_select_last (find_list
, 1);
419 listbox_select_last (find_list
, 0);
420 /* Updates the current listing */
421 send_message (&find_list
->widget
, WIDGET_DRAW
, 0);
429 * Returns malloced null-terminated line from file file_fd.
430 * Input is buffered in buf_size long buffer.
431 * Current pos in buf is stored in pos.
432 * n_read - number of read chars.
433 * has_newline - is there newline ?
436 get_line_at (int file_fd
, char *buf
, int *pos
, int *n_read
, int buf_size
,
445 if (*pos
>= *n_read
) {
447 if ((*n_read
= mc_read (file_fd
, buf
, buf_size
)) <= 0)
453 /* skip possible leading zero(s) */
460 if (i
>= buffer_size
- 1) {
461 buffer
= g_realloc (buffer
, buffer_size
+= 80);
470 *has_newline
= ch
? 1 : 0;
479 static FindProgressStatus
480 check_find_events(Dlg_head
*h
)
485 c
= get_event (&event
, h
->mouse_status
== MOU_REPEAT
, 0);
487 dlg_process_event (h
, c
, &event
);
488 if (h
->ret_value
== B_ENTER
489 || h
->ret_value
== B_CANCEL
490 || h
->ret_value
== B_AGAIN
491 || h
->ret_value
== B_PANELIZE
) {
492 /* dialog terminated */
495 if (!(h
->flags
& DLG_WANT_IDLE
)) {
496 /* searching suspended */
507 * Search the global (FIXME) regexp compiled content_pattern string in the
508 * DIRECTORY/FILE. It will add the found entries to the find listbox.
510 * returns 0 if do_search should look for another file
511 * 1 if do_search should exit and proceed to the event handler
514 search_content (Dlg_head
*h
, const char *directory
, const char *filename
)
517 char buffer
[BUF_SMALL
];
522 fname
= mhl_str_dir_plus_file (directory
, filename
);
524 if (mc_stat (fname
, &s
) != 0 || !S_ISREG (s
.st_mode
)){
529 file_fd
= mc_open (fname
, O_RDONLY
);
535 g_snprintf (buffer
, sizeof (buffer
), _("Grepping in %s"), name_trunc (filename
, FIND2_X_USE
));
537 status_update (buffer
);
540 enable_interrupt_key ();
550 typedef const char * (*search_fn
) (const char *, const char *);
551 search_fn search_func
;
554 /* We've been previously suspended, start from the previous position */
560 search_func
= (case_sensitive
) ? cstrstr
: cstrcasestr
;
562 while ((p
= get_line_at (file_fd
, buffer
, &pos
, &n_read
, sizeof (buffer
), &has_newline
)) && (ret_val
== 0)){
563 if (found
== 0){ /* Search in binary line once */
564 if (find_regex_flag
) {
565 if (regexec (r
, p
, 1, 0, 0) == 0){
567 p
= g_strdup_printf ("%d:%s", line
, filename
);
568 find_add_match (h
, directory
, p
);
572 if (search_func (p
, content_pattern
) != NULL
) {
573 char *match
= g_strdup_printf("%d:%s", line
, filename
);
574 find_add_match (h
, directory
, match
);
585 if ((line
& 0xff) == 0) {
586 FindProgressStatus res
;
587 res
= check_find_events(h
);
606 disable_interrupt_key ();
612 do_search (struct Dlg_head
*h
)
614 static struct dirent
*dp
= 0;
615 static DIR *dirp
= 0;
616 static char *directory
;
617 struct stat tmp_stat
;
619 static int subdirs_left
= 0;
621 if (!h
) { /* someone forces me to close dirp */
642 attrset (REVERSE_COLOR
);
644 tmp
= pop_directory ();
647 status_update (_("Finished"));
651 if (find_ignore_dirs
){
653 char *temp_dir
= g_strconcat (":", tmp
, ":", (char *) NULL
);
655 found
= strstr (find_ignore_dirs
, temp_dir
) != 0;
669 char buffer
[BUF_SMALL
];
671 g_snprintf (buffer
, sizeof (buffer
), _("Searching %s"),
672 name_trunc (directory
, FIND2_X_USE
));
673 status_update (buffer
);
675 /* mc_stat should not be called after mc_opendir
676 because vfs_s_opendir modifies the st_nlink
678 if (!mc_stat (directory
, &tmp_stat
))
679 subdirs_left
= tmp_stat
.st_nlink
- 2;
682 /* Commented out as unnecessary
683 if (subdirs_left < 0)
684 subdirs_left = MAXINT;
686 dirp
= mc_opendir (directory
);
687 } /* while (!dirp) */
688 dp
= mc_readdir (dirp
);
691 if (strcmp (dp
->d_name
, ".") == 0 ||
692 strcmp (dp
->d_name
, "..") == 0){
693 dp
= mc_readdir (dirp
);
697 if (subdirs_left
&& find_recursively
&& directory
) { /* Can directory be NULL ? */
698 char *tmp_name
= mhl_str_dir_plus_file (directory
, dp
->d_name
);
699 if (!mc_lstat (tmp_name
, &tmp_stat
)
700 && S_ISDIR (tmp_stat
.st_mode
)) {
701 push_directory (tmp_name
);
707 if (regexp_match (find_pattern
, dp
->d_name
, match_file
)){
708 if (content_pattern
) {
709 if (search_content (h
, directory
, dp
->d_name
)) {
713 find_add_match (h
, directory
, dp
->d_name
);
716 dp
= mc_readdir (dirp
);
718 /* Displays the nice dot */
721 /* For nice updating */
722 const char *rotating_dash
= "|/-\\";
726 attrset (DLG_NORMALC (h
));
727 dlg_move (h
, FIND2_Y
-6, FIND2_X
- 4);
728 addch (rotating_dash
[pos
]);
732 goto do_search_begin
;
737 init_find_vars (void)
746 /* Remove all the items in the stack */
747 while ((dir
= pop_directory ()) != NULL
)
752 make_fullname (const char *dirname
, const char *filename
)
755 if (strcmp(dirname
, ".") == 0 || strcmp(dirname
, "."PATH_SEP_STR
) == 0)
756 return g_strdup (filename
);
757 if (strncmp(dirname
, "."PATH_SEP_STR
, 2) == 0)
758 return mhl_str_dir_plus_file (dirname
+ 2, filename
);
759 return mhl_str_dir_plus_file (dirname
, filename
);
763 find_do_view_edit (int unparsed_view
, int edit
, char *dir
, char *file
)
766 const char *filename
;
769 if (content_pattern
){
770 filename
= strchr (file
+ 4, ':') + 1;
771 line
= atoi (file
+ 4);
777 fullname
= make_fullname (dir
, filename
);
779 do_edit_at_line (fullname
, line
);
781 view_file_at_line (fullname
, unparsed_view
, use_internal_view
, line
);
786 view_edit_currently_selected_file (int unparsed_view
, int edit
)
788 WLEntry
*entry
= find_list
->current
;
792 return MSG_NOT_HANDLED
;
796 if (!entry
->text
|| !dir
)
797 return MSG_NOT_HANDLED
;
799 find_do_view_edit (unparsed_view
, edit
, dir
, entry
->text
);
804 find_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
808 if (parm
== KEY_F (3) || parm
== KEY_F (13)) {
809 int unparsed_view
= (parm
== KEY_F (13));
810 return view_edit_currently_selected_file (unparsed_view
, 0);
812 if (parm
== KEY_F (4)) {
813 return view_edit_currently_selected_file (0, 1);
815 return MSG_NOT_HANDLED
;
822 return default_dlg_callback (h
, msg
, parm
);
826 /* Handles the Stop/Start button in the find window */
828 start_stop (int button
)
833 set_idle_proc (find_dlg
, running
);
834 is_start
= !is_start
;
836 status_update (is_start
? _("Stopped") : _("Searching"));
837 button_set_text (stop_button
, fbuts
[is_start
].text
);
842 /* Handle view command, when invoked as a button */
844 find_do_view_file (int button
)
848 view_edit_currently_selected_file (0, 0);
852 /* Handle edit command, when invoked as a button */
854 find_do_edit_file (int button
)
858 view_edit_currently_selected_file (0, 1);
866 static int i18n_flag
= 0;
868 register int i
= sizeof (fbuts
) / sizeof (fbuts
[0]);
870 fbuts
[i
].len
= strlen (fbuts
[i
].text
= _(fbuts
[i
].text
)) + 3;
871 fbuts
[2].len
+= 2; /* DEFPUSH_BUTTON */
874 #endif /* ENABLE_NLS */
877 * Dynamically place buttons centered within current window size
880 int l0
= max (fbuts
[0].len
, fbuts
[1].len
);
881 int l1
= fbuts
[2].len
+ fbuts
[3].len
+ l0
+ fbuts
[4].len
;
882 int l2
= fbuts
[5].len
+ fbuts
[6].len
+ fbuts
[7].len
;
887 /* Check, if both button rows fit within FIND2_X */
888 if (l1
+ 9 > FIND2_X
)
890 if (l2
+ 8 > FIND2_X
)
893 /* compute amount of space between buttons for each row */
894 r1
= (FIND2_X
- 4 - l1
) % 5;
895 l1
= (FIND2_X
- 4 - l1
) / 5;
896 r2
= (FIND2_X
- 4 - l2
) % 4;
897 l2
= (FIND2_X
- 4 - l2
) / 4;
899 /* ...and finally, place buttons */
900 fbuts
[2].x
= 2 + r1
/ 2 + l1
;
901 fbuts
[3].x
= fbuts
[2].x
+ fbuts
[2].len
+ l1
;
902 fbuts
[0].x
= fbuts
[3].x
+ fbuts
[3].len
+ l1
;
903 fbuts
[4].x
= fbuts
[0].x
+ l0
+ l1
;
904 fbuts
[5].x
= 2 + r2
/ 2 + l2
;
905 fbuts
[6].x
= fbuts
[5].x
+ fbuts
[5].len
+ l2
;
906 fbuts
[7].x
= fbuts
[6].x
+ fbuts
[6].len
+ l2
;
910 create_dlg (0, 0, FIND2_Y
, FIND2_X
, dialog_colors
, find_callback
,
911 "[Find File]", _("Find File"), DLG_CENTER
| DLG_REVERSE
);
913 add_widget (find_dlg
,
914 button_new (FIND2_Y
- 3, fbuts
[7].x
, B_VIEW
, NORMAL_BUTTON
,
915 fbuts
[7].text
, find_do_edit_file
));
916 add_widget (find_dlg
,
917 button_new (FIND2_Y
- 3, fbuts
[6].x
, B_VIEW
, NORMAL_BUTTON
,
918 fbuts
[6].text
, find_do_view_file
));
919 add_widget (find_dlg
,
920 button_new (FIND2_Y
- 3, fbuts
[5].x
, B_PANELIZE
,
921 NORMAL_BUTTON
, fbuts
[5].text
, 0));
923 add_widget (find_dlg
,
924 button_new (FIND2_Y
- 4, fbuts
[4].x
, B_CANCEL
,
925 NORMAL_BUTTON
, fbuts
[4].text
, 0));
927 button_new (FIND2_Y
- 4, fbuts
[0].x
, B_STOP
, NORMAL_BUTTON
,
928 fbuts
[0].text
, start_stop
);
929 add_widget (find_dlg
, stop_button
);
930 add_widget (find_dlg
,
931 button_new (FIND2_Y
- 4, fbuts
[3].x
, B_AGAIN
,
932 NORMAL_BUTTON
, fbuts
[3].text
, 0));
933 add_widget (find_dlg
,
934 button_new (FIND2_Y
- 4, fbuts
[2].x
, B_ENTER
,
935 DEFPUSH_BUTTON
, fbuts
[2].text
, 0));
937 status_label
= label_new (FIND2_Y
- 6, 4, _("Searching"));
938 add_widget (find_dlg
, status_label
);
941 listbox_new (2, 2, FIND2_X
- 4, FIND2_Y
- 9, 0);
942 add_widget (find_dlg
, find_list
);
949 set_idle_proc (find_dlg
, 1);
951 return find_dlg
->ret_value
;
957 set_idle_proc (find_dlg
, 0);
958 destroy_dlg (find_dlg
);
962 find_file (char *start_dir
, char *pattern
, char *content
, char **dirname
,
965 int return_value
= 0;
967 char *dir_tmp
, *file_tmp
;
971 /* FIXME: Need to cleanup this, this ought to be passed non-globaly */
972 find_pattern
= pattern
;
973 content_pattern
= content
;
976 push_directory (start_dir
);
978 return_value
= run_process ();
980 /* Remove all the items in the stack */
981 while ((dir
= pop_directory ()) != NULL
)
984 get_list_info (&file_tmp
, &dir_tmp
);
987 *dirname
= g_strdup (dir_tmp
);
989 *filename
= g_strdup (file_tmp
);
991 if (return_value
== B_PANELIZE
&& *filename
) {
992 int status
, link_to_dir
, stale_link
;
996 WLEntry
*entry
= find_list
->list
;
997 dir_list
*list
= ¤t_panel
->dir
;
1000 for (i
= 0; entry
&& i
< find_list
->count
;
1001 entry
= entry
->next
, i
++) {
1002 const char *filename
;
1004 if (!entry
->text
|| !entry
->data
)
1007 if (content_pattern
)
1008 filename
= strchr (entry
->text
+ 4, ':') + 1;
1010 filename
= entry
->text
+ 4;
1012 name
= make_fullname (entry
->data
, filename
);
1014 handle_path (list
, name
, &st
, next_free
, &link_to_dir
,
1025 /* don't add files more than once to the panel */
1026 if (content_pattern
&& next_free
> 0) {
1027 if (strcmp (list
->list
[next_free
- 1].fname
, name
) == 0) {
1033 if (!next_free
) /* first turn i.e clean old list */
1034 panel_clean_dir (current_panel
);
1035 list
->list
[next_free
].fnamelen
= strlen (name
);
1036 list
->list
[next_free
].fname
= name
;
1037 list
->list
[next_free
].f
.marked
= 0;
1038 list
->list
[next_free
].f
.link_to_dir
= link_to_dir
;
1039 list
->list
[next_free
].f
.stale_link
= stale_link
;
1040 list
->list
[next_free
].f
.dir_size_computed
= 0;
1041 list
->list
[next_free
].st
= st
;
1043 if (!(next_free
& 15))
1047 current_panel
->count
= next_free
;
1048 current_panel
->is_panelized
= 1;
1049 /* Done by panel_clean_dir a few lines above
1050 current_panel->dirs_marked = 0;
1051 current_panel->marked = 0;
1052 current_panel->total = 0;
1053 current_panel->top_file = 0;
1054 current_panel->selected = 0; */
1056 if (start_dir
[0] == PATH_SEP
) {
1057 strcpy (current_panel
->cwd
, PATH_SEP_STR
);
1058 chdir (PATH_SEP_STR
);
1064 do_search (0); /* force do_search to release resources */
1068 return return_value
;
1074 char *start_dir
= NULL
, *pattern
= NULL
, *content
= NULL
;
1075 char *filename
, *dirname
;
1076 int v
, dir_and_file_set
;
1077 regex_t rx
; /* Compiled content_pattern to search inside files */
1079 for (r
= &rx
; find_parameters (&start_dir
, &pattern
, &content
); r
= &rx
){
1081 dirname
= filename
= NULL
;
1083 v
= find_file (start_dir
, pattern
, content
, &dirname
, &filename
);
1086 if (find_regex_flag
&& r
)
1090 if (dirname
|| filename
){
1092 do_cd (dirname
, cd_exact
);
1094 try_to_select (current_panel
, filename
+ (content
?
1095 (strchr (filename
+ 4, ':') - filename
+ 1) : 4) );
1096 } else if (filename
)
1097 do_cd (filename
, cd_exact
);
1098 select_item (current_panel
);
1105 dir_and_file_set
= dirname
&& filename
;
1111 if (v
== B_PANELIZE
){
1112 if (dir_and_file_set
){
1113 try_to_select (current_panel
, NULL
);
1114 panel_re_sort (current_panel
);
1115 try_to_select (current_panel
, NULL
);