<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
#
use strict;

my $file="";
my $newfile="";
my $newdata="";
my $starttag="# &lt;!--internal--&gt;";
my $endtag="# &lt;!--/internal--&gt;";
my $loglevel=0;

sub usage {
	print &lt;&lt;EOF
Usage: $0 [-s &lt;start-tag&gt;] [-e &lt;end-tag&gt;] &lt;filename&gt; &lt;newfile&gt;
       
       splits out textblocks marked with start and endtag. 
	   Default:
       $starttag
       $endtag

       -s &lt;starttag&gt; : define new start-tag
       -e &lt;endtag&gt;   : define new end-tag

EOF
;
	exit 1;
}

sub LOG {
  my $message = shift;
  my $level   = shift || 0;
#  my $time = localtime(time);
  if ( $level &lt;= $loglevel ) {
#      print LOGFILE "[$time] [$$] $message\n";
	print "$message\n";
  }
}

sub splitInternal {
	my $file=shift;
    my $data;
    open (FILE,"$file") || die ("Can not open $file: $! $?!\n");
    while (&lt;FILE&gt;) {
      chomp;
      if ( $_ =~ /^$starttag/){
		while (&lt;FILE&gt;) {
			chomp;
			last if $_ eq "$endtag";
		}
	  } else {
		  $data .= "$_\n";
	  }
	}
  return $data;			
}

while  (my $param = shift (@ARGV)) {
	if (( $param eq "-h" ) || ( $param eq "--help" )){
        usage();
    }

	if (($param eq "-s" ) || ($param eq "--start-tag")){
		$starttag=shift(@ARGV);
		next;
	}

	if (($param eq "-e" ) || ($param eq "--end-tag")){
		$endtag=shift(@ARGV);
        next;
    }

	if (($param eq "-v" ) || ($param eq "--verbose")){
		$loglevel=2;
		next;
	}

	if ($file eq ""){
		$file=$param;	
		next;
	} 

	$newfile=$param;
}

if ($newfile eq ""){
	die("newfile not defined!\n");
	usage();
}

if ($file eq ""){
    die("filename not defined!\n");
    usage();
}

if (-f $file) {
	$newdata=splitInternal($file);
	LOG ("File $newfile exists - overwriting!\n",1) if (-f $newfile);
	open(NEWFILE, "&gt; $newfile");
		print NEWFILE $newdata;
	close(NEWFILE);
	LOG("New file $newfile written",2);
} else {
	print "File $file not found.\n";
	usage();
}

</pre></body></html>