develooper Front page | perl.perl5.porters | Postings from January 2004

RE: [perl #24774] eval + format - \n = pp_ctl.c assertion

From:
LAUN Wolfgang
Date:
January 2, 2004 04:15
Subject:
RE: [perl #24774] eval + format - \n = pp_ctl.c assertion
Message ID:
DF27CDCBD2581D4B88431901094E4B4D02B0C4B4@attmsx1
Hi Merijn, just a quick answer:

> -----Original Message-----
> From: H.Merijn Brand [mailto:h.m.brand@hccnet.nl]
> Sent: Friday, January 02, 2004 12:19 PM
> To: LAUN Wolfgang
> Cc: Perl 5 Porters
> Subject: Re: [perl #24774] eval + format - \n = pp_ctl.c assertion
>  
> On Fri 02 Jan 2004 11:31, LAUN Wolfgang 
> 
> Wolfgang, can I please have your comments on this:
> 
> On Mon 27 Oct 2003 19:36, "H.Merijn Brand" 
> <h.m.brand@hccnet.nl> wrote:
> > The last paragraph of perlform sais
> > 
> > --8<---
> >       Inside of an expression, the whitespace characters \n, \t and \f are
> >       considered to be equivalent to a single space.  Thus, you could think
> >       of this filter being applied to each value in the format:
> > 
> >        $value =~ tr/\n\t\f/ /;
> > 
> >       The remaining whitespace character, \r, forces the printing of a new
> >       line if allowed by the picture line.
> > -->8---
> > 
> > I know nobody cares, but why is \e treated as whitespace? It's not in these
> > docs, and I cannot think of a valid reason to strip escapes, other than ...
> > way back when we had paper terminals ...

Well, even then you'd want to keep escapes.

> > 
> > l1:/pro/3gl/CPAN/perl-current 157 > perl5.8.0 -MO=Deparse merijn/fmt.pl
> > $_ = "\eE";
> > format STDOUT =
> > @<<<<<<<<<<<<<<
> > $_
> > .
> > write;
> > merijn/fmt.pl syntax OK
> > l1:/pro/3gl/CPAN/perl-current 160 > perl5.8.0 merijn/fmt.pl | cat -ve
> >  E$
> > l1:/pro/3gl/CPAN/perl-current 161 >
> > 
> > enterwrite calls S_doprint which calls CvSTART where I'm lost
> > I don't see the point (yet) where the \n\r\t\e are tr'd to space
> 

These things happen in pp_ctl.c, and not just to ESC either. It seems
that all *control* characters are converted to space (except on EBCDIC
in the first loop, where the destination pointer is incremented twice).

THIS PATCH IS UNTESTED! I'll be back.
Wolfgang

> -- 
> H.Merijn Brand        Amsterdam Perl Mongers 

--- pp_ctl.c.new	Fri Jan  2 12:45:32 2004
+++ pp_ctl.c	Fri Jan  2 12:50:13 2004
@@ -621,23 +621,15 @@
 		*t = '\0';
 		sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
 		for (; t < SvEND(PL_formtarget); t++) {
-#ifdef EBCDIC
-		    int ch = *t++ = *s++;
-		    if (iscntrl(ch))
-#else
-		    if (!(*t & ~31))
-#endif
+		    int ch = *t = *s++;
+		    if (isSPACE(ch))
 			*t = ' ';
 		}
 		break;
 	    }
 	    while (arg--) {
-#ifdef EBCDIC
 		int ch = *t++ = *s++;
-		if (iscntrl(ch))
-#else
-		if ( !((*t++ = *s++) & ~31) )
-#endif
+		if (isSPACE(ch))
 		    t[-1] = ' ';
 	    }
 	    break;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About