package xm::cdefs;
use xm::o;

sub DESC
{"
  will look for a CBLKs and their preceding names and comments.
  Just mark these as CDEFs for later parsing...
"}

sub DO
{
    my $in = shift;
    
    $in =~ s{ ( (?: <CDOC(?:\s[^<>]*)?> 
		 (?:(?:.(?!</?CDOC[\s>]))*.?) 
		 </CDOC(?:\s[^<>]*)?> \ *\s?\ * )* )
	      ( \w[\s\w\[\*\]\(\,\)\:\=\.]* )                    # the header
              ( (?: <CDOC(?:\s[^<>]*)?> (?:(?:.(?!</?CDOC[\s>]))*.?) 
		 </CDOC(?:\s[^<>]*)?> \ *\s?\ * )* )
              ( <CBLK(?:\s[^<>]*)?> (?:(?:.(?!</?CBLK[\s>]))*.?) 
		</CBLK(?:\s[^<>]*)?> ) 
            }
            { "<ITEMCDEF>"
	      .$1                             # change: no extra markup anymore
              .(length $2 ? "<CDCL>".$2."</CDCL>" : "")
              .$3                             # change: no extra markup anymore
              .$4                             # stick to <CBLK>
              ."</ITEMCDEF>" 
            }gsex;
    $in =~ s{ (</ITEMCDEF>) (\s*\; | \s*\**\s*[\w\[\]]+ \s*\**\s*\;) }
            {$2.$1}gsex; # expand tail
    $in =~ s{ (\s*) ([\w\[\*\]\s]*) (<ITEMCDEF>)}
            {$1.$3.$2}gsex; # expand head (quick version)
    
    return $in;
} 

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

1;