#!/usr/bin/perl sub Attributes { local $_ = shift; my $H; while(/\s*([^=]+)=\"([^\"]+)\"\s*/g) { $H->{lc($1)} = $2; } return $H; } sub Tag { my $Tag = shift; my $Attributes = shift; return "<$Tag " . join(' ', map { "$_=\"$$Attributes{$_}\"" } sort keys %$Attributes ) . "/>"; } sub Cat { local $_ = `cat $_[0]`; s/[\r\n]*//sg; return $_; } sub TEXVC { my $tex = shift; print STDERR ": texvc /tmp /tmp \"$tex\" iso-8859-1 2>/dev/null\n" if $DEBUG; return `texvc /tmp /tmp "$tex" iso-8859-1 2>/dev/null`; } sub PutTEXInPlace { my $Source = shift; my $Dest = shift; `mv /tmp/$Source $Dest`; } sub HTMLToTemplate { s/]+)>/do { my $Attributes = &Attributes($1); my $TeXfilename = $Attributes->{'src'}; $TeXfilename =~ s|(img.*?)\.png|tex\/$1.tex|s; $Attributes->{'tex'} = &Cat($TeXfilename); $Attributes->{'texfilename'} = $TeXfilename if $DEBUG; $Attributes->{'src'} =~ s|(img.*?)\.png||s; &Tag('img', $Attributes); }/iegs; print; } sub TemplateToHTML { my $Args = shift; s//do { my $DollarAmpersand = $&; my $Attributes = &Attributes($1); $Attributes->{'src'} = $Args->{'src'} if defined $Args->{'src'}; my $tex = $Attributes->{'tex'}; my $texvc = &TEXVC($tex); my $file; print STDERR "HTML: $DollarAmpersand => "; if( $texvc =~ m|[SEF\-]$| ) { print STDERR "!!! TEXVC ERROR '$&' !!!\x7\n"; } elsif( ($file) = $texvc =~ m|^[\+cmlCMLX]([0-9a-f]{32})|si ) { print STDERR "\ntexvc: $texvc\n" if $DEBUG; print STDERR "img src=\"$file.png\"\n"; &PutTEXInPlace("$file.png", $Attributes->{'src'}); } else { print STDERR "!!!! UNKNOWN ERROR !!!!\n"; } $Attributes->{'alt'} = $Attributes->{'title'} = $tex; $Attributes->{'src'} .= $file . '.png'; delete $Attributes->{'tex'}; &Tag('img', $Attributes); }/iegs; print; } my $Args = {}; if($ARGV[0] =~ /^-debug$/si) { shift @ARGV; $DEBUG = 1; } if($ARGV[0] =~ /^-src/si) { shift @ARGV; $Args->{'src'} = shift @ARGV; $Args->{'src'} =~ s/([^\/])$/$1\//s; } if($ARGV[0] =~ /\.html$/) { undef $/; $_ = <>; &HTMLToTemplate(); exit(0); } if($ARGV[0] =~ /\.thtml$/) { undef $/; $_ = <>; &TemplateToHTML( $Args ); exit(0); } print STDERR "Usage: $0: [-debug] [ | [-src ] ]\n\n"; 1;