Package: mc
Version: 4.6.2~git20080311-1
Severity: wishlist
Hi,
Here is next round of patches fixing mcedit's regexp replace,
please include them in next version:
99a_fix-regex-bol-match.patch fixes matching beginning of line,
previously bol was matched at cursor after starting regexp replace.
99b_fix-regex-pattern-lengths.patch fixes subpattern byte offset
computation, previously mbstrlen function (which chokes on
nonprinting characters) was used and regex substrings that captured
for example tab characters were incorrectly truncated.
99c_fix-regex-newline-match.patch removes multiline matching -
make regexp less suprising because it is usually assumed that '.'
does not match newline. Function edit_find_string already splits
data on newlines before passing it to string_regexp_search,
so multiline matching is already crippled.
I also responded to bugreport http://bugs.debian.org/486676
with corrected patch for previous issues.
Regards,
Michal Pokrywka
Fix regexp matching beginning of line, bol was matched at cursor after
starting regexp replace.
--- mc-4.6.2~git20080311/edit/editcmd.c.orig 2008-06-22 16:58:16.000000000 +0200
+++ mc-4.6.2~git20080311/edit/editcmd.c 2008-06-22 16:58:53.000000000 +0200
@@ -1721,7 +1721,7 @@
int found_start, match_bol, move_win = 0;
while (start + offset < last_byte) {
- match_bol = (offset == 0 || (*get_byte) (data, start + offset - 1) == '\n');
+ match_bol = (start == 0 || (*get_byte) (data, start + offset - 1) == '\n');
if (!move_win) {
p = start + offset;
q = 0;
Fix subpattern byte offsets computation, previously mbstrlen function was used
which chokes on nonprinting characters, regex substrings that captured tab
characters were truncated.
--- mc-4.6.2~git20080311/edit/editcmd.c.orig 2008-06-23 01:48:03.000000000 +0200
+++ mc-4.6.2~git20080311/edit/editcmd.c 2008-06-23 01:58:32.000000000 +0200
@@ -1511,6 +1511,32 @@
sargs[argord[8]], sargs[argord[9]], sargs[argord[10]], sargs[argord[11]], \
sargs[argord[12]], sargs[argord[13]], sargs[argord[14]], sargs[argord[15]]
+#ifdef UTF8
+size_t
+real_mbstrlen (const char *str)
+{
+ if (SLsmg_Is_Unicode) {
+ size_t width = 0;
+
+ for (; *str; str++) {
+ wchar_t c;
+ size_t len;
+
+ len = mbrtowc (&c, str, MB_CUR_MAX, NULL);
+
+ if (len == (size_t)(-1) || len == (size_t)(-2)) break;
+
+ if (len > 0) {
+ width ++;
+ str += len-1;
+ }
+ }
+
+ return width;
+ } else
+ return strlen (str);
+}
+#endif
/* This function is a modification of mc-3.2.10/src/view.c:regexp_view_search() */
/* returns -3 on error in pattern, -1 on not found, found_len = 0 if either */
@@ -1581,7 +1607,7 @@
continue;
tmp = string[pmatch[i].rm_so];
string[pmatch[i].rm_so] = 0;
- new_o = mbstrlen(string);
+ new_o = real_mbstrlen(string);
string[pmatch[i].rm_so] = tmp;
pmatch[i].rm_so = new_o;
@@ -1589,7 +1615,7 @@
continue;
tmp = string[pmatch[i].rm_eo];
string[pmatch[i].rm_eo] = 0;
- new_o = mbstrlen(string);
+ new_o = real_mbstrlen(string);
string[pmatch[i].rm_eo] = tmp;
pmatch[i].rm_eo = new_o;
}
Add REG_NEWLINE flag to regexp replace matching as it is unusual for '.' to
match newline, edit_find_string function already splits data on newlines before
passing it to string_regexp_search so multiline matching is already crippled.
--- mc-4.6.2~git20080311/edit/editcmd.c.orig 2008-06-23 02:22:30.000000000 +0200
+++ mc-4.6.2~git20080311/edit/editcmd.c 2008-06-23 02:23:34.000000000 +0200
@@ -1570,7 +1570,8 @@
g_free (old_pattern);
old_pattern = 0;
}
- if (regcomp (&r, pattern, REG_EXTENDED | (icase ? REG_ICASE : 0))) {
+ if (regcomp (&r, pattern, REG_EXTENDED | (icase ? REG_ICASE : 0) |
+ REG_NEWLINE)) {
*found_len = 0;
return -3;
}