#!/usr/bin/perl use strict; use warnings; use POSIX qw(strftime); my $depth = 0; my $section = 1; my $note = 1; my $abstract = 0; my $tag = "content000"; my $nl = 0; my $expand = "cat"; my $last_alpha = 0; my $file_count = 0 ; my $date = ''; my $author = 'Dr. Who '; my $incomment = 0; my $o = '*'; # for Emacs default my $title; my $fh; my $pre; my %content; use Getopt::Std; our($opt_n, $opt_d, $opt_h, $opt_s); getopts('ndhs:'); if ($opt_h) { print <<"EOF"; -h for this -n generate new line -d create file for each section ( for dvd list ) -s separator ( default '-' ) EOF exit; } if ($opt_n) { $nl = 1; } if ($opt_s) { $o = $opt_s; } sub opening { print $fh < RogueRogue # } sub closing { print $fh ""; if (!$opt_d && (keys %content) > 2) { print $fh "\n" if (! $nl); # print $fh "

Content

\n"; print $fh "
    \n"; print $fh "$title\n"; for (sort keys %content ) { print $fh "
  1. ",$content{$_},"\n"; } print $fh "
\n"; } print $fh "\n" if (! $nl); print $fh "
$author / $date\n" ; printf $fh "\n"; } sub open_output { my ($out) = @_; my $arg = $out; $out =~ s/\.ind$//; $out =~ s/\.index$//; if ($opt_d) { $out .= sprintf("_%05d",$file_count++); } $out .= ".html"; open($fh,">",$out); } sub o2html { my($arg, $current) = @_; $arg =~ /^(.*)\/.*?/; my $dir = $1; $dir = "." if (! $dir); $incomment = 0; $title = ''; my $section_title = ''; my $pre = ''; my $paragraph = 0; %content = (); &opening; line: while (<$current>) { chop; # strip record separator if (/^\<\!\-\-\-/) { $incomment = 1; } if (/-\-\-\>/) { $incomment = 0; } if(!/^/\>/g; s%href="([^"]+")\s*([^\s]*)%$2%g; } s/]*>/i) { my $fig = $1; my $alt = $2; &fig($dir, $fig, $alt); } elsif (m/"\s]*)"*[^>]*alt="*([^>"]*)"*[^>]*>/i) { my $fig = $1; my $alt = $2; &fig($dir, $fig, $alt); } elsif (m/
\s*"\s]*)"*[^>]*alt="*([^>"]*)"*[^>]*>\s*<\/center>/i) { my $fig = $1; my $alt = $2; &fig($dir, $fig, $alt); } elsif (m/
\s*"\s]*)"*[^>]*>\s*<\/center>/i) { my $fig = $1; my $alt = $2; &fig($dir, $fig, $alt); } elsif (m/ img not matched $_"; } if( (!/^\s/) && (!/^$/) && $pre) { print $fh "\n" if (! $nl || $last_alpha); print $fh "\n"; $pre = 0; } if (/^\Q$o\E*input: (.*)/o) { open(my $fdbase,"$expand $1|") or die("can't open $!"); # push(@depend,$1); # print STDOUT "$1 "; o2html($arg, $fdbase); next line; } if (/^\Q$o$o\E*title:\s*(.*)/o) { $title = $1; # substr($_, 8, length($_) - 7); &title($title); next line; } if (/^\Q$o$o\E*comment-begin:/o) { while (<$current>) { next line if (/^\Q$o\E*comment-end:/) ; } last line; } if (/^\Q$o$o\E*date:/o) { my $tmp; for ($tmp = 1; substr($_, $tmp, 1) eq $o; $tmp++) { ; } $tmp += 5; # override file date $date = substr($_, $tmp, length($_) - $tmp + 1); next line; } if (/^\Q$o$o\E*number:/o) { # my $tmp; # for ($tmp = 1; substr($_, $tmp, 1) eq $o; $tmp++) { # ; # } # $tmp += 7; # $number = substr($_, $tmp, length($_) - $tmp + 1); next line; } if (/^\Q$o$o\E*note:/o) { $note = 2; print $fh "\n" if (! $nl || $last_alpha); printf $fh "\n"; next line; } if (/^\Q$o$o\E*author:/o) { my $tmp; for ($tmp = 1; substr($_, $tmp, 1) eq $o; $tmp++) { ; } $tmp += 7; $author = substr($_, $tmp, length($_) - $tmp + 1); print $fh "\n" if (! $nl); printf $fh "$author\n"; next line; } if (/^\Q$o$o\E*abstract:/o) { $abstract = 1; print $fh "\n" if (! $nl); printf $fh "\n"; next line; } if (/^\Q$o$o\E*table:\s(.*)/o) { my @buf = (); my $title = $1; while (<$current>) { last if (/^\Q$o$o\E*table-end:/o) ; push(@buf,$_); } &tab2html($title, @buf); last if (eof); next line; } if (/^\Q$o\E/o) { next line if ($incomment); if ($opt_d) { &closing; &open_output($arg); &opening; } if ($abstract == 1) { print $fh "\n" if (! $nl); printf $fh "\n"; $abstract = 0; } if ($note) { if ($note == 2) { print $fh "\n" if (! $nl); printf $fh "\n"; $note = 0; } } for ($depth = 1; substr($_, $depth, 1) eq $o; $depth++) { ; } $section_title = substr($_, $depth, length($_) - $depth + 1); if(! defined($title)) { &title($section_title); } print $fh "\n" if (! $nl); print $fh "
\n"; print $fh "",$section_title, "\n"; $section++; $content{$tag} = " " x $depth . $section_title; $tag++; if (! $title) { &title($section_title); } next line; } elsif (/^\s/) { if(! $pre) { print $fh "\n" if (! $nl); print $fh "
\n";
	    $pre = 1;
	}
	$paragraph = 0;
	print $fh $_,"\n";
    } elsif (/^$/) {
	if(! $pre && ! $paragraph) {
	    print $fh $_;
	    print $fh "\n" if (! $nl);
	    print $fh "

\n"; $paragraph = 1; } } elsif (/^\/i); # no one linier # add link $content{$tag} = " " x $depth . " * ". $_. "\n"; $tag++; } elsif (!/^\Q$o\E/o) { print $fh "\n" if ($nl || $last_alpha); print $fh $_; $paragraph = 0; } } continue { $last_alpha = /[.,!?a-zA-Z0-9]$/; } &closing; } foreach my $arg (@ARGV) { open(my $fdbase,"$expand $arg | nkf -w |") or die("$arg cannot open $!"); my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($arg); die "can't open $arg" if (! defined $mtime); $date = strftime "%a %b %e %H:%M:%S %Y", localtime($mtime); &open_output($arg); &o2html($arg, $fdbase); } sub title { $title = $_[0]; if (! $opt_d) { print $fh <<"EOFEOF"; EOFEOF } else { print $fh <<"EOFEOF"; EOFEOF } print $fh <<"EOFEOF"; $title