)
print $HTMLFILE "\n";
# Print the usual headers.
print $HTMLFILE "\n\n" .
$config->{ "titleprefix" } . " [" . $rcfile .
"]\n\n" .
$config->{ "bodytag" } . "\n";
while ( <$MUTTRC> )
{
# Allow for blocks of lines to be ignored.
if ( /^\s*\#\s*BeginHTMLIgnore/i )
{
++$ignoring;
next;
}
elsif ( /^\s*\#\s*EndHTMLIgnore/i )
{
--$ignoring;
next;
}
elsif ( $ignoring > 0 )
{
next;
}
# Transform the usual characters for HTML (minus one)
s/&/&/g; # Must come first!
s/\</g;
s/\>/>/g;
# Apply comment tags to comments (Many thanks to Vincent for
# this one).
s/^(([^\\\'\"]|\\.|\'([^\\]|\\.)*?\'|\"([^\\]|\\.)*?\")*?)\#(.*)/$1$config->{ "begincomment" }\#$5$config->{ "endcomment" }/;
# If we are going to attempt to link variables to an on-line mutt
# manual... (thanks to Erik Jacobsen for this
# one).
if ( $config->{ "manualvars" } )
{
if ( /^\s*(un){0,1}set\s+(no|inv){0,1}(\w+)/ )
{
my $varname = $3;
my $varlink = "{ "manualvars" } .
"#" . $varname . "\">" . $varname . "";
s/$varname/$varlink/;
}
}
# Now, are we looking at a line that sources in another
# rc file? (this is probably easily fooled).
if ( /^([^\#]*)source(\s+)([^\s\\&]+)(.*)/ )
{
# Looks like we are, split it up.
my ( $one, $two, $three, $four, $five ) =
( $1, $2, $3, $4, $5 );
# Handle undef'd last bit.
$five = "" if !$five;
# If we are not supposed to ignore this file.
if ( !IgnoreFile( $three, $config ) )
{
# Convert that file to HTML.
ConvertToHTML( $three, $config, $seen );
# Re-build the current line.
$_ = $one . "source" . $two .
"".
$three . "" . $four . $five . "\n";
}
else
{
print "Ignoring $three\n" unless $config->{ "silent" };
}
}
print $HTMLFILE $_;
}
close( $MUTTRC );
print $HTMLFILE "\n\n\n";
}
else
{
print "Error opening " . $rcfile . " ($!)\n";
}
close( $HTMLFILE );
}
else
{
print "Error creating " . $htmlfile . " ($!)\n";
}
}
else
{
print "I've seen $rcfile once, skipping...\n" unless $config->{ "silent" };
}
}
######################################################################
sub MakeHTMLName
{
my ( $rcfile ) = @_;
my $htmlfile = basename( $rcfile ) . ".html";
if ( $htmlfile =~ /^\.(.*)$/ )
{
$htmlfile = $1;
}
$htmlfile;
}
######################################################################
sub HandleTilde
{
my ( $file ) = @_;
my ( $home ) = $ENV{ 'HOME' } || ( getpwuid( $< ) )[ 7 ];
# TODO: Handle ~user as well.
if ( $file =~ /^~\/(.*)$/ )
{
$file = $home . "/" . $1;
}
$file;
}
######################################################################
sub IgnoreFile
{
my ( $file, $config ) = @_;
my $ignore = 0;
my $re;
foreach $re ( @{ $config->{ "ignore" } } )
{
if ( $file =~ /$re/ )
{
$ignore = 1;
last;
}
}
$ignore;
}
__END__
=head1 NAME
muttrc2tml - Convert mutt rc files to HTML
=head1 SYNOPSIS
muttrc2html [muttrc-file]
=head1 DESCRIPTION
B is little perl script is a simple attempt at a muttrc to HTML
converter. It could come in handy if you want to publish your muttrc file
on your web pages.
The basic idea behind the script is that it should make comments stand out
and should also allow hypertext links to other rc files that you source
in. There is also some support for linking variable names to an on-line
mutt manual.
Running the script is simply a case of typing 'muttrc2html' at the shell
prompt. By default the script will look for ~/.muttrc and start to convert
it to a HTML file in the current directory. You can change the behaviour
of the script with settings in a file called ~/.muttrc2htmlrc. Valid
settings are:
=head2 muttrc=
=head2 TitlePrefix=
=head2 Ignore=
=head2 Silent=<0|1>
=head2 BeginComment=
=head2 EndComment=
=head2 BodyTag=
=head2 ManualVars=
=head1 OPTIONS
B is the optional name of an rc file you want to process. If not
supplied the file named with the B option in the config file will be
processed.
=head1 BUGS
o It assumes too much about the setup of your system.
o It doesn't handle more than one source statement on any one line.
o A load more issues I've not considered.
=head1 AUTHOR
Dave Pearson