On Wed, Mar 19, 2003 at 11:25:46AM -0500, Pavel Roskin wrote:
> If I apply your patch to the CVS version (this requires some manual
> intervention), 

That's because of Andrew's patch which was later.

> following bug appears.  If the viewer is positioned at the
> beginning of file, regex search cannot find anything, even strings
> without characters with special meaning.  In particular, try opening
> ChangeLog and look for "200" using F6.

0) I really love those disappearing revisions in anon cvs...

1) Silly little typo:

-    for (i = 0; (ch != -1) && (pos > 0); ch = get_byte (view, pos)) {
+    for (i = 0; (ch != -1) && (pos >= 0); ch = get_byte (view, pos)) {

But looks like Andrew has taken this issue into account in his patch
(the 'break' inside the 'for'), so it no longer applies. But the
proper '^' and '$' and 'prev' handling in reverse regexp search still
applies, see my patch.

2) Andrew's patch has broken regexp reverse search... see the usage of
strreverse() - Andrew, please could you fix this and examine/apply
(parts) of my patch? If something is unclear - tell me.

3) Try to create file:
--cut--
000
aaa
--cut--
WITHOUT final newline. Now try to search 'aaa' - not found. 
Fixed in my patch (attached).

Regards
Adam

-- 

  _.|._ |_  _.   :  Adam Byrtek /alpha/
 (_|||_)| |(_|   :  email  alpha@(irc.pl|debian.org)
     |           :  jabber alpha.pl(at)jabber.org, pgp 0xB25952C0
Index: view.c
===================================================================
RCS file: /cvs/gnome/mc/src/view.c,v
retrieving revision 1.117
diff -u -r1.117 view.c
--- view.c      19 Mar 2003 13:39:48 -0000      1.117
+++ view.c      19 Mar 2003 19:13:16 -0000
@@ -1521,46 +1521,40 @@
 get_line_at (WView *view, unsigned long *p, unsigned long *skipped)
 {
     char *buffer = 0;
-    int buffer_size = 0;
-    int usable_size = 0;
-    int ch;
-    int direction = view->direction;
+    int buffer_size = 0, usable_size = 0;
+    int ch, i = 0, prev = 0;
     unsigned long pos = *p;
-    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)
+       if (pos == 0 && view->direction == -1)
            return 0;
-       pos += direction;
+       pos += view->direction;
        i++;
     }
     *skipped = i;
 
-    if (pos) {
-       prev = get_byte (view, pos - 1);
+    if (pos > 0 || view->direction == -1) {
+       prev = get_byte (view, pos - view->direction);
        if ((prev == -1) || (prev == '\n'))
            prev = 0;
+    } else {
+       prev=0;
     }
 
-    for (i = 0; ch != -1; ch = get_byte (view, pos)) {
+    for (i = 1; ch != -1; ch = get_byte (view, pos)) {
 
-       if (i == usable_size) {
+       if (i >= usable_size) {
            buffer = grow_string_buffer (buffer, &buffer_size);
            usable_size = buffer_size - 2;
        }
 
-       i++;
-       buffer[i] = ch;
+       buffer[i++] = ch;
 
-       if (!pos && direction == -1)
+       if (pos == 0 && view->direction == -1)
            break;
 
-       pos += direction;
+       pos += view->direction;
 
        if (ch == '\n' || !ch)
            break;
@@ -1666,15 +1660,13 @@
 
        /* We found the string */
 
-       if (*s && !view->search_start && (search == regexp_view_search)
-           && (*text == '^')) {
-
-           /* We do not want to match a
-            * ^ regexp when not at the real
-            * beginning of some line
-            */
-           continue;
-       }
+       /* Handle ^ and $ in reexp searches when starting at
+        * the middle of the line */
+       if (s[0] && (search == regexp_view_search))
+           if (((text[0] == '^') && (view->direction > 0)) ||
+               ((text[strlen(text)-1] == '$') && (view->direction < 0)))
+               continue;
+       
        /* Record the position used to continue the search */
        if (view->direction == 1)
            t += forward_line_start;

Reply via email to