#! /usr/bin/perl

# ----------------------------------------------------------------
# John Kerl
# kerl.john.r@gmail.com
# 2000/11/03

# Replaces tabs with the specified number of spaces.
# ----------------------------------------------------------------

$tab_width = 8;
if (@ARGV) {
	if ($ARGV[0] =~ m/^[\/-]/) {
		$tab_width = $ARGV[0];
		$tab_width =~ s/^.//;
		shift @ARGV;
	}
}

while ($line = <>) {
	chomp $line;
	my @chars = split //, $line;

	my $output_char_count = 0;

	for my $input_char_count (0 .. $#chars) {
		my $char= $chars[$input_char_count];

		if ($char eq "\t") {
			print " ";
			$output_char_count++;
			while (($output_char_count % $tab_width) != 0) {
				print " ";
				$output_char_count++;
			}
		}
		else {
			print $char;
			$output_char_count++;
		}
	}
	print "\n";
}
