package xm::listing;
use strict;
use xm::o;
use xm::sub;

sub DESC
{"
  will look for all texts that are inside <whateverListing>-markups
  and replace the inner with their xm::off version of being
  purely literal as a whole.
"}

sub DO
{
    my $in = shift;

    my $x = sub { 
	my ($a,$b) = @_;
	if ($b !~ m/<CPRE>\s*\#\s*include\b/s)  
	{  
	    return $a.$b;
	}else{  
	    return $a."<ITEMINCL>".$b."</ITEMINCL>";
	}
    };

    # whateverListing
    $in =~ s{(<(\w+Listing)(?:\s[^<>]*)?>(?!</?\2[\s>]))
		 ( (?:.(?!</?\2[\s>]))*. )(</\2[\s>])
		     } 
         { 
	     $1.&xm::sub::off($3).$4
	 }gsex;
    # whateverLISTING
    $in =~ s{(<(\w+LISTING)(?:\s[^<>]*)?>(?!</?\2[\s>]))
		 ( (?:.(?!</?\2[\s>]))*. )(</\2[\s>])
		     } 
         { 
	     $1.&xm::sub::off($3).$4
	 }gsex;
    return $in;
} 

sub ARGS { return    xm::o::args_stdin(@_, DESC); }
sub main { return DO(xm::o::args_stdin(@_, DESC)); }

1;