1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#! /usr/bin/perl
require 5.005;
use Getopt::Std;
#
# Usage
#
my $usage = "Usage: $0 [-t tab-width] [input-file...]\n";
#
# Variables
#
my $tab_width = 8;
my $out_file_name = '-';
#
# Parse command line arguments.
#
getopts(':t:', \%options) or die $usage;
$tab_width = $options{t} if (defined($options{t}));
#
# Convert C to HTML.
#
print "<blockquote>\n";
print "<pre>\n";
while (<>) {
s/^([ \t]*)//;
my $spaces = $1;
my $col = 0;
foreach my $c (unpack('C*', $spaces)) {
if ($c eq ord(' ')) {
$col++;
} else {
$col = ($col + $tab_width) - ($col % $tab_width);
}
}
print ' ' x $col;
s|&|&|g;
s|<|<|g;
s|>|>|g;
print;
}
print "</pre>\n";
print "</blockquote>\n";
|