#!/usr/bin/perl
#
# This is a perl script that can strip uneeded characters from a
# shell script, so that certain shells(bash!) can run it faster.
#
# Copyright 2000 by Adam Heath <doogie@debian.org>
# Licensed under the LGPL
#

$first = 1;
while (<>) {

	#
	# Remove continuation characters.  This is done first
	# incase the script magic below is a continued line.
	#
	if(/\\$/) {
		chop;s/\\$//;
		$_ .= <>;
		redo if not eof;
	};

	#
	# Don't throw away the script magic identifier.
	#
	if(!(defined $first && /^#!/)) {
		#
		# Strip leading whitespace.
		#
		s/[ \t]*//;

		#
		# Skip blank and comment lines.
		#
		next if(/^(#.*|)$/);
	}

	#
	# If a line ends with ;, then combine it with the next
	# line, as the new line character is extraneous.
	#
	chop if(/\;[ \t]*$/);

	print if(/^#!/);
	if(defined $first) {
		print "# This script has been preprocessed prior to installation\n";
		print "# It has had comments, blank lines, and leading spaces\n";
		print "# removed, and \\-style lines combined.  This was done so\n";
		print "# that it could run quicker under some shells.\n"
	}
	print if(! /^#!/);
	undef $first;

}
