Backward search in internal viewer



Hi!

This patch adds backward search feature for normal search
in internal viewer. This one is for non gnome edition, sorry.

I want to receive some comments about this patch.

TODO: As far as I know get_line_at () is needed only for regexp search.
do_normal_search should be rewritten without allocating memory for string.

BTW, I can't understand, who need MenuBarEmpty structure in main.c ?

With best regards,
Andrew.

--- ChangeLog-orig	Sat Jun 16 10:46:05 2001
+++ ChangeLog	Sat Jun 16 11:46:37 2001
@@ -8,6 +8,12 @@
 	* tree.c (tree_copy, tree_move): Possible memory leaking fixed.
 	(tree_keymap): Constified.
 
+	* view.c [!HAVE_GNOME]: Implement backward search in "normal" search.
+	(icase_search_p): Add code for backward search.
+	(get_line_at): Likewise.
+	(do_normal_search): Likewise.
+	(search): Fix backward search.
+
 2001-06-15  Pavel Roskin  <proski gnu org>
 
 	* panelize.c: Define DIR_H_INCLUDE_HANDLE_DIRENT earlier, since
Index: view.c
===================================================================
RCS file: /home/sav/.cvsroot/mc/src/view.c,v
retrieving revision 1.46
diff -u -p -r1.46 view.c
--- view.c	2001/05/25 08:20:13	1.46
+++ view.c	2001/05/25 18:41:05
@@ -1368,10 +1378,27 @@ icase_search_p (WView *view, char *text,
 {
     char *q;
     int lng;
+#ifndef	HAVE_GNOME
+    int direction = view->direction;
+
+    if (direction == -1)
+	reverse_string (text);
+
+    q = _icase_search (text, data, &lng);
 
+    if (direction == -1)
+	reverse_string (text);
+
+    if (q != 0) {
+	if (direction > 0)
+	    view->search_start = q - data - lng;
+	else
+	    view->search_start = strlen (data) - (q - data);
+#else
     if ((q = _icase_search (text, data, &lng)) != 0) {
-	view->found_len = lng;
 	view->search_start = q - data - lng;
+#endif
+	view->found_len = lng;
 	return 1;
     }
     return 0;
@@ -1403,8 +1430,13 @@ get_line_at (WView *view, unsigned long 
     long i = 0;
     int  prev = 0;
 
+    if (!pos && direction == -1)
+	return 0;
+
     /* skip over all the possible zeros in the file */
     while ((ch = get_byte (view, pos)) == 0) {
+	if (!pos && direction == -1)
+	    break;
 	pos += direction; i++;
     }
     *skipped = i;
@@ -1422,21 +1454,27 @@ get_line_at (WView *view, unsigned long 
 	    usable_size = buffer_size - 2;
 	}
 
-	pos += direction; i++;
+	i++;
+	buffer [i] = ch;
 
-	if (ch == '\n' || !ch){
+	if (!pos && direction == -1)
 	    break;
-	}
-	buffer [i] = ch;
+
+	pos += direction;
+
+	if (ch == '\n' || !ch)
+	    break;
     }
+
     if (buffer){
 	buffer [0] = prev;
 	buffer [i] = 0;
-
+#ifdef	HAVE_GNOME	
 	/* If we are searching backwards, reverse the string */
 	if (direction < 0) {
 	    reverse_string (buffer + 1);
 	}
+#endif
     }
 
     *p = pos;
@@ -1520,7 +1558,7 @@ search (WView *view, char *text, int (*s
     if (view->direction == 1){
 	p = found_len ? search_start + 1 : search_start;
     } else {
-	p = (found_len ? search_start : view->last) - 1;
+	p = found_len ? (search_start ? search_start - 1 : 0) : search_start;
     }
     beginning = p;
 
@@ -1567,7 +1604,7 @@ search (WView *view, char *text, int (*s
 	if (view->direction == 1)
 	    t += forward_line_start;
 	else
-	    t += reverse_line_start ? reverse_line_start + 3 : 0;
+	    t = reverse_line_start ? reverse_line_start + 2 : 0;
 	view->search_start += t;
 
 	if (t != beginning){
@@ -1983,7 +2016,53 @@ normal_search (WView *view, int directio
 	convert_to_display( exp );
 #endif
 
+#ifndef HAVE_GNOME
+    if (!view->hex_mode) {
+
+    enum {
+	SEARCH_DLG_HEIGHT = 8,
+	SEARCH_DLG_WIDTH  = 58
+    };
+    
+    static int replace_backwards;
+    int treplace_backwards = replace_backwards;
+    char *tsearch_text;
+
+    QuickWidget quick_widgets[] = {
+	{quick_button, 6, 10, 5, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 
+	 0, 0, NULL},
+	{quick_button, 2, 10, 5, SEARCH_DLG_HEIGHT, N_("&Ok"), 0, B_ENTER, 
+	 0, 0, NULL},
+	{quick_checkbox, 3, SEARCH_DLG_WIDTH, 4, SEARCH_DLG_HEIGHT, N_("&Backwards"), 0, 0,
+	 0, 0, NULL},
+	{quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, "", 52, 0, 
+	 0, 0, N_(" Search ")},
+	{quick_label, 2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 
+	 0, 0, 0},
+	{0}
+    };
+
+    quick_widgets[2].result = &treplace_backwards;
+    quick_widgets[3].str_result = &tsearch_text;
+    quick_widgets[3].text = exp;
+
+    {
+	QuickDialog Quick_input = {
+	 SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, 0, N_(" Search "),
+	 "[Input Line Keys]", "quick_input", 0, 0 
+	};
+	Quick_input.widgets = quick_widgets;
+	if (quick_dialog (&Quick_input) == B_CANCEL) {
+	    return;
+	}
+	exp = *(quick_widgets[3].str_result);
+	replace_backwards = treplace_backwards;
+	direction = (replace_backwards) ? -1 : 1;
+    }
+}   else
+#endif	/* !HAVE_GNOME */
     exp = input_dialog (_(" Search "), _(" Enter search string:"), exp);
+
     if ((!exp)){
 	return;
     }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]