File: c2html

package info (click to toggle)
eb 4.4.3-14.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,060 kB
  • sloc: ansic: 22,725; sh: 10,130; perl: 1,114; makefile: 706
file content (51 lines) | stat: -rwxr-xr-x 736 bytes parent folder | download | duplicates (10)
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|&|&amp;|g;
    s|<|&lt;|g;
    s|>|&gt;|g;
    print;
}

print "</pre>\n";
print "</blockquote>\n";