Excerpts from mail: (19-Nov-97) if $MATCH starts with a newline by David W
Tamkin
Philip Guenther posted his patch for MATCH to drop an initial newline without
collecting an extra character from the end; the question left open is what to
do when you *want* a leading newline in $MATCH. I can't think of a situation
where anybody would, but that's just the limitation of my imagination.
Hello? Remember the line-by-line processing thread three weeks ago that
brought the whole problem of the leading newline being stripped from $MATCH
into the light?
Perhaps a patch to leave an initial newline in $MATCH (if real, not if
putative) would have been better; then the final results would be under
the control of the person writing the rcfile.
That would be preferable.
Era Eriksson wrote:
(If one actually wanted to match a literal newline, how would that be
accomplished?)
Here's a real-world example:
# If message body is less than LINEBUF in size, put the message body into a
# variable named BODY.
:0B
* $ < ${LINEBUF}
* ^^\/(.*$)+
{
BODY = $MATCH
# Check to see if the body started with a newline and if it did, prepend
# it to $BODY.
:0B
* ^^($)(.*$)*
{
BODY = "
$BODY"
}
}
By the way, here's a patch that gets rid of stripping the leading newline
from $MATCH entirely (I haven't tested to see how this affects putative
newlines, but for my applications it works fine since I usually put the match
operator after "^^"):
*** regexp.c Fri Nov 7 16:15:01 1997
--- regexp.c.new Fri Nov 7 16:17:36 1997
***************
*** 598,605 ****
tmemmove(q=(char*)text,bom,len),q[len]='\0',bom=q;
else
{ char*p;
- if(*bom=='\n')
- bom++; /* strip one leading newline */
primeStdout(amatch);p=realloc(Stdout,(Stdfilled+=len)+1);
tmemmove(q=p+Stdfilled-(int)len,bom,len);retbStdout(p);
}
--- 598,603 ----
Later,
Ed