bug in crm script 'match <newend>' statement (+ fix)
"Ger Hobbelt" <[email protected]>
| Newsgroups | gmane.mail.spam.crm114 |
|---|---|
| Message-ID | <[email protected]> |
This wasn't covered by neither vanilla 'megatest', nor GerH 'make
check', but it does not work like you'd expect:
CRM script snippet:
----------------
#
# print text to stderr for verbose display of events
#
:verbosity: (:verbose_text:)
{
match [:verbose:] /SET/
isolate (:verbose_text:)
isolate (:verbose_text_ln:) //
isolate (:verbose_logfile:) <default> //
match [:verbose_text:] <fromstart> //
{
# fetch one line and print; abort when it's an empty '.*' match at
# the end of the content: <fromend newend>
match [:verbose_text:] <fromend newend nomultiline> /.*/
(:verbose_text_ln:)
output <append> [:*:verbose_logfile:] /VERBOSE: :*:verbose_text_ln:\n/
liaf
}
}
return
-------sample use:---------
call /:verbosity:/ [Setting up the forwarding email addresses:\n\
generic reject_address: ':*:general_fails_to:'\n\
fail_priority_mail_to: ':*:general_fails_to:'\n\
fail_blacklist_mail_to ':*:general_fails_to:'\n\
fail_SSM_mail_to: ':*:general_fails_to:'\n\
\n\
fail_classify_mail_to: ':*:general_fails_to:'\n]
----------------
Note: That empty line \n\ in that sample right there is a test bit to
ensure empty lines came through unharmed.
Current crm114 (BOTH vanilla AND GerH) will fail (by keeping on
repeating that very last \n in there FOR EVER.
While reading QUICKREF led me to believe it would work OK.
Anyway, below is the fix required to make this work.
(Reminder to self: should add this one as yet another extra test to
'make check')
--- \\Debbie\ger\prj\1original\crm114\src\crm114.sourceforge.net\src\crm_expr_match.c 2007-11-26
14:10:04.000000000 +-0200
+++ \\Debbie\ger\prj\3actual\crm114\src\crm_expr_match.c 2008-09-30
02:15:21.000000000 +-0200
@@ -322,2 +332,6 @@
- // set up the start/end of the text we're matching against
-
+ // set up the start/end of the text we're matching against:
+ //
+ // IMPORTANT: the order in which the CRM_* flags are processed is important,
+ // so that combo's like CRM_FROMEND | CRM_NEWEND work!
+ //
+
@@ -367,49 +387,55 @@
mtext = &mdw->filetext[textoffset];
i = crm_regexec (&preg, mtext, mtextlen,
nmatches, matches, eflags, NULL);
j = matches[0].rm_eo;
- if (( (textoffset + j) > oldend) && (i == 0)) done = 1;
- };
+ if (((textoffset + j) > oldend) && (i == 0))
+ done = 1;
+ }
- };
+ if (done == 0)
+ {
+ i = REG_NOMATCH;
+ }
+ }
break;
case CRM_BACKWARDS:
{
The code above is dependent on the check following the switch
statement (no shown the diff): now it works just like the other
'cases' when no matches can be found beyond the marker (done = 0 when
all matches that are produced have been checked in the loop).
--
Met vriendelijke groeten / Best regards,
Ger Hobbelt
--------------------------------------------------
web: http://www.hobbelt.com/
http://www.hebbut.net/
mail: [email protected]
mobile: +31-6-11 120 978
--------------------------------------------------
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/