#!/usr/bin/env perl
$^W = 1;
#
# $Id: pp2html,v 1.21 2001/12/19 21:04:43 lorenz Exp $
# $Revision: 1.21 $ - Patches 01 (reverted), 02-08 + 10 + 11 by JSTENZEL
# - Patch 14 by JC and JSTENZEL,
# - Patch 15-23 by JSTENZEL.
# $Date: 2001/12/19 21:04:43 $
#
# $Author: lorenz $
#
# Revision History: See end of file
#===================================================================
# declare script package
package PerlPoint::Converter::pp2html;
use Cwd;
# BEGIN {eval join('', "use PAR '", cwd(), "/PerlPointCD/PerlPoint-0.39.par'");} # JSTENZEL, patch 1.01-21 (for PerlPointCD)
use Pod::Text;
use Getopt::ArgvFile qw(argvFile);
use Getopt::Long;
#use Data::Dumper;
use POSIX qw(strftime); # JSTENZEL, 1.01-??
use Storable qw(nstore retrieve); # JSTENZEL, 1.01-20
# pragmata
use strict;
use subs "flush", "push_page", "pp_warn";
use vars qw (%OPT);
# load modules
use Carp;
use Digest::MD5 qw(md5_hex); # ste
use File::Basename;
use File::Copy;
use File::Path;
use Safe;
use PerlPoint::Constants 0.15;
use PerlPoint::Tags;
use PerlPoint::Tags::Basic;
use PerlPoint::Tags::HTML;
use PerlPoint::Tags::LaTeX;
use PerlPoint::Backend;
use PerlPoint::Parser 0.39;
use PerlPoint::Converters qw(replace_keywords copy_file update_file
relative_path return_abs_path is_abs_path);
#
my $me = basename($0);
my $VERSION = sprintf("%d.%02d", q/$Revision: 1.21 $/ =~ /(\d+)\.(\d+)/);
my $PACK_VERSION = $PerlPoint::Converters::VERSION;
$main::VERSION = $VERSION;
my $nix = ""; # for using RCS keys in Usage, ...
my $Date = "Date ";
my $lcnt = 0; #TODO Sanieren
my %TR = ( # Translation Table
"\334" => "Ü",
"\374" => "ü",
"\326" => "Ö",
"\366" => "ö",
"\304" => "Ä",
"\344" => "ä",
"\337" => "ß",
); #
# Bullets for the masses ...
my @BULLETS=("DUMMY");
my $default_li_start = "
";
my $default_li_end = "\n";
#============================================================= Usage
sub Usage { #---------------------------------------------------
no strict;
my $tmpdir = "/tmp";
$^W = 0;
#my $parser = Pod::Text->new (sentence => 0, loose => 0, width => 78);
if (defined $ENV{TMP}){
$tmpdir = $ENV{TMP};
} elsif (defined $ENV{TEMP}) {
$tmpdir = $ENV{TEMP};
}
my $tmpfile = "$tmpdir/$me.$$"."_help";
$SIG{INT} =
$SIG{QUIT} =
$SIG{HUP} =
$SIG{ABRT} =
$SIG{PIPE} = sub { unlink $tmpfile };
open(ME, "< $0") or die "Can't open $me: $!\n";
open(TMP, "> $tmpfile") or die "Can't open $tmpfile: $!\n";
my $skip = 1;
while(){
if (/^=cut/){
$skip = 1 ;
print TMP $_;
next;
}
$skip = 0 if /^=/;
next if $skip;
s/PROGRAM/$me/g;
s/P_VERSION/$VERSION/g;
print TMP $_;
}
close(TMP);
#$parser->parse_from_file( $tmpfile );
pod2text($tmpfile );
unlink $tmpfile;
exit;
} # Usage
#==================================================== Parameter Loop
my %OPT_MAIN;
my %OPT_STYLE;
%OPT = ( #
define => [],
no_contents_indent => 0,
contents_indent => 0,
alinkcolor => "#FF0000",
top_alinkcolor => "#FF0000",
bot_alinkcolor => "#FF0000",
toc_alinkcolor => "#FF0000",
idx_alinkcolor => "#FF0000",
contents_target => "Index",
contents_table_widht => 0,
contents_css_id_index => '', # patch 1.01-17, JSTENZEL
contents_css_id_start => '', # patch 1.01-17, JSTENZEL
bgcolor => "#FFFFFF",
idx_bgcolor => "#FFFFFF",
idx_fgcolor => "#000000",
top_bgcolor => "#FFFFFF",
top_fgcolor => "#000000",
bot_bgcolor => "#FFFFFF",
bot_fgcolor => "#000000",
toc_bgcolor => "#FFFFFF",
toc_fgcolor => "#000000",
back_image => "",
top_back_image => "",
bot_back_image => "",
toc_back_image => "",
idx_back_image => "",
bottom_template => "",
box_color => "#E5E5E5",
boxtext_bold => "ON",
boxtext_color => "#000000",
center_headers => 0,
hide_headers => 0, # ste, patch 1.01-06
contents_header => "Contents",
fgcolor => "#000000",
frame_set => "",
frame_start => "frame_set.html",
index_bot => 2,
index_dat => 1,
index_header => "Index",
index_top => 0,
java_script_navigation => 1,
java_script_controls => 0,
linear_mode => 0,
linkcolor => "#0000CC",
top_linkcolor => "#0000CC",
bot_linkcolor => "#0000CC",
toc_linkcolor => "#0000CC",
idx_linkcolor => "#0000CC",
no_index => 0,
num_headers => 0,
trailing_point => 0,
slide_dir => ".",
style_dir => ["."],
slide_prefix => "slide",
slide_suffix => "htm",
start_page => "index.htm",
title => "XXXXX",
top_template => "",
trans_table => "",
tree_app_height => 500,
tree_app_width => 250,
tree_applet => 0,
headline_shortcuts => 0, # JSTENZEL, patch 1.01-07
label_next => "Next",
label_prev => "Previous",
label_index => "Index",
label_contents => "Contents",
vlinkcolor => "#AAAAAA",
top_vlinkcolor => "#AAAAAA",
bot_vlinkcolor => "#AAAAAA",
toc_vlinkcolor => "#AAAAAA",
idx_vlinkcolor => "#AAAAAA",
base_left_txt => "BASE_LEFT_TXT",
base_right_txt => "BASE_RIGHT_TXT",
base_middle_txt => "BASE_MIDDLE_TXT",
bullets_align_middle => 0,
bot_left_txt => "BOT_LEFT_TXT",
bot_right_txt => "BOT_RIGHT_TXT",
bot_middle_txt => "BOT_MIDDLE_TXT",
top_left_txt => "TOP_LEFT_TXT",
top_right_txt => "TOP_RIGHT_TXT",
top_middle_txt => "TOP_MIDDLE_TXT",
logo_image_filename => "LOGO_IMAGE_FILENAME",
mv2targetdir => 0, # patch 1.01-09, JSTENZEL
charset => 'iso-8859-1', # patch 1.01-10, JSTENZEL
use_css_for_toc => 0,
); ## END DEFAULTS
if (defined $ARGV[0] and $ARGV[0] eq "-h") { Usage() }
argvFile( home => 1, default => 1);
if (defined $ARGV[0] and $ARGV[0] =~ /-v$/){
@ARGV =("-version"); # to avoid ambiguities
}
my $verbose = 1;
## NOTE: The comments in the @OPTIONS parameter list are used for
## creating the menues in the interactive config file editor
## (which will soon be available :-)
my @OPTIONS = ( #
## ------------------------- General
"activeContents",
"cache",
"cacheCleanup",
"safeOpcode=s@",
"set=s@",
"trans_table=s",
"filter=s",
"nocopyright",
"noinfo",
"nowarn",
"mv2targetdir",
"quiet",
"count_only",
"streamBuffer=s", # patch 1.01-20: stream caching
"reloadStream", # and stream reload (JSTENZEL)
## ------------------------- document (added by JSTENZEL, patch 10, 15, 16)
"title=s", # (moved)
"author=s",
"description=s",
"charset=s",
"norobots",
"nosmarttags",
"linknavigation",
"bootstrapaddress=s",
"validate",
"startaddress=s",
"no_html_header",
"no_html_bodytags",
"includelib=s@",
"critical_semantics",
## ------------------------- Colors
"define=s@", # generic color definition for options file and templates
"box_color=s",
"boxtext_color=s",
"fgcolor=s",
"bgcolor=s",
"idx_fgcolor=s",
"idx_bgcolor=s",
"toc_fgcolor=s",
"toc_bgcolor=s",
"top_fgcolor=s",
"top_bgcolor=s",
"bot_fgcolor=s",
"bot_bgcolor=s",
"back_image=s",
"toc_back_image=s",
"idx_back_image=s",
"top_back_image=s",
"bot_back_image=s",
## ------------------------- Link Colors
"linkcolor=s",
"top_linkcolor=s",
"bot_linkcolor=s",
"toc_linkcolor=s",
"idx_linkcolor=s",
"vlinkcolor=s",
"top_vlinkcolor=s",
"bot_vlinkcolor=s",
"toc_vlinkcolor=s",
"idx_vlinkcolor=s",
"alinkcolor=s",
"top_alinkcolor=s",
"bot_alinkcolor=s",
"toc_alinkcolor=s",
"idx_alinkcolor=s",
## ------------------------- Templates
"top_template=s",
"top_idx_template=s",
"top_toc_template=s",
"bottom_template=s",
"bottom_idx_template=s",
"bottom_toc_template=s",
"nav_template=s",
"nav_top_template=s",
"nav_bottom_template=s",
## ------------------------- Layout
"contents_header=s",
"contents_table_width=s",
"contents_css_id_index=s", # patch 1.01-17, JSTENZEL
"contents_css_id_start=s", # patch 1.01-17, JSTENZEL
"index_header=s",
"style=s",
"style_dir=s@",
"label_next=s",
"label_prev=s",
"label_index=s",
"label_contents=s",
"bullet=s@",
"bullets_align_middle",
"box_border=s",
"box_width=s",
"boxtext_bold=s",
"contents_target=s",
"contents_indent=i",
"no_contents", # JSTENZEL, 1-20
"no_contents_indent",
"no_contents_bullets",
"block_indent=i",
"no_index",
"linear_mode",
"num_headers",
"trailing_point",
"nonum_headers",
"center_headers",
"hide_headers",
"headline_shortcuts",
## ------------------------- Layout2
"style_sheet=s",
"base_left_txt=s",
"base_right_txt=s",
"base_middle_txt=s",
"bot_left_txt=s",
"bot_right_txt=s",
"bot_middle_txt=s",
"top_left_txt=s",
"top_right_txt=s",
"top_middle_txt=s",
"logo_image_filename=s",
## ------------------------- Directories, Filenames
"start_page=s",
"frame_set=s",
"frame_start=s",
"slide_dir=s",
"target_dir=s",
"slide_prefix=s",
"slide_suffix=s",
"image_dir=s",
"image_ref=s",
"applet_dir=s",
"applet_ref=s",
"slide_md5",
"reverse_order",
"index_bot=s",
"index_dat=s",
"index_top=s",
"use_css_for_toc",
## ------------------------ Tree Applet
"tree_applet",
"tree_app_height=s",
"tree_app_width=s",
"tree_base=s",
"java_script_navigation=s",
"java_script_controls=s",
## ------------------------ Special
"debug",
"trace:i",
"help",
"version",
); ##----------- END OPTIONS
die unless GetOptions( \%OPT_MAIN,
@OPTIONS
);
# build and configure a Safe object
my $safe = new Safe;
if (exists $OPT_MAIN{safeOpcode}){
unless (grep($_ eq 'ALL', @{$OPT_MAIN{safeOpcode}})) {
# configure compartment
$safe->permit(@{$OPT_MAIN{safeOpcode}});
} else {
# simply flag that we want to execute active contents
$safe=1;
}
}
delete $OPT_MAIN{safeOpcode}; # der Mohr hat seine Schuldigkeit getan!
# if we do not delete this option we will get warnings in the
# subsequent call to GetOptions ...
# propagate options as necessary
@OPT_MAIN{qw(nocopyright noinfo nowarn)}=(1,1,1) if exists $OPT_MAIN{quiet};
$OPT_MAIN{trace}=$ENV{SCRIPTDEBUG} if not exists $OPT_MAIN{trace} and exists $ENV{SCRIPTDEBUG};
#======================================================= Script Body
Usage(1) if ($OPT_MAIN{help});
print STDERR "This is $me, build $VERSION from PerlPoint::Converters $PACK_VERSION (patches 01-16)\n" unless $OPT_MAIN{quiet};
print STDERR "$Date: 2002/11/15 13:02:15 $nix\n" unless $OPT_MAIN{quiet};
print STDERR "(c) Lorenz Domke 2002.\n\n" unless $OPT_MAIN{nocopyright};
exit if $OPT_MAIN{version};
$verbose = 0 if ($OPT_MAIN{quiet} or $OPT_MAIN{noinfo});
# handle define options:
my %OPT_DEFINE;
# check slide dir and create it if necessary:
# TODO test on Win9X and NT systems (problems with path names?)
if (defined $OPT_MAIN{define}){
#use Data::Dumper;
#print Dumper $OPT_MAIN{define};
foreach my $define (@{$OPT_MAIN{define}}) {
# add this color option:
if ($define =~ /^\s*(\w+)\s+(\S+)\s*$/){
$OPT_DEFINE{$1} = $2;
print " found define: $1 --> $2\n";
}
}
} # define options
if ($OPT_MAIN{target_dir}) {
$OPT_MAIN{slide_dir} = $OPT_MAIN{target_dir};
}
$OPT_MAIN{slide_dir} = defined $OPT_MAIN{slide_dir} ? $OPT_MAIN{slide_dir} : ".";
if (! -d $OPT_MAIN{slide_dir}) {
print STDERR "creating slide dir $OPT_MAIN{slide_dir} ...\n" if $verbose;
mkpath($OPT_MAIN{slide_dir}, 1, oct(755)) or die "Cannot creat $OPT_MAIN{slide_dir}: $!\n";
}
$OPT_MAIN{image_dir} = $OPT_MAIN{slide_dir} unless defined $OPT_MAIN{image_dir};
if(! defined $OPT_MAIN{image_ref}){
if ($OPT_MAIN{image_dir} eq $OPT_MAIN{slide_dir}){
$OPT_MAIN{image_ref} = "."; # images are in the slides dir
} else {
if ( is_abs_path($OPT_MAIN{image_dir}) ){
$OPT_MAIN{image_ref} = $OPT_MAIN{image_dir}; # absolute path name
} else {
### we must figure out, where the image_dir is relative to the slide_dir !!!
$OPT_MAIN{image_ref} = relative_path($OPT_MAIN{image_dir}, $OPT_MAIN{slide_dir});
#TODO: remove abs_path if relative path works
$OPT_MAIN{image_ref} = return_abs_path($OPT_MAIN{image_dir});
}
}
}
$OPT_MAIN{applet_dir} = $OPT_MAIN{slide_dir} unless defined $OPT_MAIN{applet_dir};
if(! defined $OPT_MAIN{applet_ref}){
if ($OPT_MAIN{applet_dir} eq $OPT_MAIN{slide_dir}){
$OPT_MAIN{applet_ref} = "."; # applets are in the slides dir
} else {
if ( is_abs_path($OPT_MAIN{applet_dir}) ){
$OPT_MAIN{applet_ref} = $OPT_MAIN{applet_dir}; # absolute path name
} else {
### we must figure out, where the applet_dir is relative to the slide_dir !!!
#TODO: remove abs_path if relative path works
$OPT_MAIN{applet_ref} = relative_path($OPT_MAIN{applet_dir}, $OPT_MAIN{slide_dir});
$OPT_MAIN{applet_ref} = return_abs_path($OPT_MAIN{applet_dir});
}
}
}
my $style_dir = ".";
## handle style options; in this case we must load additional
## options files ...
if (defined $OPT_MAIN{style}){
# try to find the style directory
print STDERR "using style $OPT_MAIN{style}\n" if $verbose;
my $style = $OPT_MAIN{style};
my $found = 0;
foreach my $mstyle_dir (@{$OPT_MAIN{style_dir}}) {
if (-e "$mstyle_dir/$style/$style.cfg"){
$style_dir = $mstyle_dir;
$found = 1;
last;
}
}
if (! $found){
die "*** ERROR: style directory $style not found ...\n";
}
# load the options file from the style directory:
my $style_opts = "$style_dir/$style/$style.cfg";
if (! -e $style_opts) {
die "*** ERROR: cannot find options file $style_opts !\n";
}
{ local @ARGV = ( "\@$style_opts" );
argvFile();
die unless GetOptions( \%OPT_STYLE, # get new options from style
@OPTIONS
);
# merge main options into style options
# (main options have higher priority !!)
@OPT{ keys %OPT_STYLE } = values %OPT_STYLE if %OPT_STYLE;
@OPT{ keys %OPT_MAIN } = values %OPT_MAIN;
$OPT{txt_contents} = $OPT{contents_header};
$OPT{txt_index} = $OPT{index_header};
}
$style_dir = "$style_dir/$style"; ## used as prefix for all template files !!
# now copy all images from the style dir to target_dir (slide_dir):
opendir(STYLE, "$style_dir") or die "Can't open directory $style_dir: $!\n";
foreach my $img (readdir(STYLE)){
if ($img =~ /\.jpg$|\.gif$|\.png$/i) {
update_file("$style_dir/$img", "$OPT_MAIN{image_dir}/$img", $verbose, \%OPT, 0);
}
if ($img =~ /\.htm$|\.html$|\.css$/i) {
update_file("$style_dir/$img", "$OPT_MAIN{slide_dir}/$img", $verbose, \%OPT, 0);
}
}
closedir(STYLE);
} # end --style option
else {
# merge main options into %OPT
@OPT{ keys %OPT_MAIN } = values %OPT_MAIN;
$OPT{txt_contents} = $OPT{contents_header};
$OPT{txt_index} = $OPT{index_header};
}
# merge define options:
@OPT{ keys %OPT_DEFINE } = values %OPT_DEFINE;
if ($OPT{tree_applet}){ #--------------------- TreeApplet
# now update tree applet files in target directory
# first find tree applet sources
# There MUST be a subdirectoy called "applet_src" in one of the style directories
my $applet_source_dir;
foreach my $mstyle_dir (@{$OPT{style_dir}}) {
if (-d "$mstyle_dir/applet_src"){
$applet_source_dir = "$mstyle_dir/applet_src";
last;
}
}
# now update:
if (! defined $applet_source_dir){
die "*** ERROR: TreeApplet source directory not found!\n" .
" Perhaps you have not specified a --style_dir option.\n" .
" This is now mandatory if you use the tree applet.\n" .
" There must be a directory called 'applet_src' in one of your\n" .
" style collections (i. e. one of the directories which are \n" .
" specified with the --style_dir option).\n"
;
}
opendir(TR, $applet_source_dir) or die "cannot open $applet_source_dir:$!\n";
foreach my $f (readdir(TR)){
next unless $f =~ /\.class$/;
update_file("$applet_source_dir/$f", "$OPT{applet_dir}/$f", $verbose, \%OPT, 0);
}
# fix the tree_base
if (! defined $OPT{tree_base}){
$OPT{tree_base} = $OPT{applet_ref};
}
} # tree_applet
my $block_width = ""; # width for code block tables
if(exists $OPT{box_width}){
$block_width = " WIDTH=$OPT{box_width}";
}
my $box_border = "";
if(exists $OPT{box_border}){
$box_border = " BORDER=$OPT{box_border}";
}
my $java_script_src = "java_navigation.js"; # script for java script navigation
my $LIST;
my ($li_start, $li_end) = ($default_li_start, $default_li_end);
my ($lo_start, $lo_end) = ($li_start, $li_end);
my $pwd = cwd;
my $shift_level = 0;
my $missing_bullets_cnt = 0;
my $img_dir = return_abs_path($OPT{image_dir});
# set up @BULLEST array and copy bullet images to target dir {{{ ------------------------------
foreach my $bull (@{$OPT{bullet}}) {
$shift_level++;
if ($bull !~ /^";
pp_warn "Image file for bullet not found: $bull ...\n";
$missing_bullets_cnt ++;
} else {
## copy bullet image to target dir
my $bull_basename = basename($bull);
update_file($bull,"$img_dir/$bull_basename", $verbose, \%OPT, 0);
$BULLETS[$shift_level] = $bull_basename;
}
chdir $pwd or die "cannot cd back to working directory $pwd: $!\n";
}
} else {
$BULLETS[$shift_level] = "";
}
}
$shift_level = 1;
#print STDERR "@BULLETS\n";
#}}}
# check for existence of back images:
my $missing_backgrounds_cnt = 0;
if ($OPT{back_image} or
$OPT{toc_back_image} or
$OPT{idx_back_image} or
$OPT{top_back_image} or
$OPT{bot_back_image}
){
chdir $OPT{slide_dir} or die "cannot cd back to slide directory $OPT{slide_dir}: $!\n";
if ($OPT{back_image} and ! -e "$OPT{back_image}"){
pp_warn "Image file for slide background: $OPT{back_image} ...\n";
$missing_backgrounds_cnt ++;
$OPT{back_image} = "";
}
if ($OPT{toc_back_image} and ! -e "$OPT{toc_back_image}"){
pp_warn "Image file for toc background: $OPT{toc_back_image} ...\n";
$missing_backgrounds_cnt ++;
$OPT{toc_back_image} = "";
}
if ($OPT{idx_back_image} and ! -e "$OPT{idx_back_image}"){
pp_warn "Image file for index background: $OPT{idx_back_image} ...\n";
$missing_backgrounds_cnt ++;
$OPT{idx_back_image} = "";
}
if ($OPT{top_back_image} and ! -e "$OPT{top_back_image}"){
pp_warn "Image file for top background: $OPT{top_back_image} ...\n";
$missing_backgrounds_cnt ++;
$OPT{top_back_image} = "";
}
if ($OPT{bot_back_image} and ! -e "$OPT{bot_back_image}"){
pp_warn "Image file for bottom background: $OPT{bot_back_image} ...\n";
$missing_backgrounds_cnt ++;
$OPT{bot_back_image} = "";
}
chdir $pwd or die "cannot cd back to working directory $pwd: $!\n";
} # handle background image options
if ($OPT{trans_table}) #
{
# remove defaults
%TR = ();
# open translation table:
open(K, "< $OPT{trans_table}") or
die "Can't open translation table $OPT{trans_table}: $!\n";
print "reading translation table $OPT{trans_table} ...\n";
# read translation table:
while()
{
# skip empty and comment lines
next if /^\s*$/ or /^\s*#/;
# remove leading and trailing whitespaces
chomp;
s/^\s+//;
# extract and store translation data
my @fields=split;
$TR{$fields[0]}=$fields[1] if @fields>=2;
}
} # end if $OPT{trans_table)
if ( ! $OPT{frame_set}){
$OPT{java_script_navigation} = 0; # in this case we do NOT need java script navigation
}
if (! defined($OPT{top_idx_template})){
$OPT{top_idx_template} = $OPT{top_template}
}
if (! defined($OPT{top_toc_template})){
$OPT{top_toc_template} = $OPT{top_template}
}
if (! defined($OPT{bottom_idx_template})){
$OPT{bottom_idx_template} = $OPT{bottom_template}
}
if (! defined($OPT{bottom_toc_template})){
$OPT{bottom_toc_template} = $OPT{bottom_template}
}
my ($block_indent_0, $block_indent_1) = ("","");
if (defined($OPT{block_indent})){
for (my $i=0; $i < $OPT{block_indent}; $i++){
$block_indent_0 .= "";
}
}
if ($OPT{frame_set} ne "") {
print "Creating frame set ...\n";
my $fset = "$style_dir/$OPT{frame_set}";
if (! -e $fset or -d $fset) {
die "*** ERROR: frame set template $fset does not exist or is a directory!\n";
}
copy_file($fset, "$OPT{slide_dir}/$OPT{frame_start}", $verbose, \%OPT);
copy_file($fset, "$OPT{slide_dir}/$OPT{start_page}", $verbose, \%OPT) if $OPT{start_page};
}
my $embedded_html = 0;
##
## disable options if noxxx options are set:
if (defined $OPT{nonum_headers}){
$OPT{num_headers} = 0; # allows overwriting of style option by main option `nonum_headers'
}
# declare variables
# Data Structures
# 000000000000000
my (@streamData, %variables); # ste: added %variables
my $page_ref; # pointer to current page buffer
my @PAGES; # Array of pointers to PAGE structures
# PAGES[0] is table of contents
# $PAGES[ $m ] = {
# BODY => [ ... ],
# LEVEL => ...,
# NUMBER => ...,
# HD => ...,
# FILENAME => ...,
# PREV => ...,
# NEXT => ...,
# UP => ...,
# DOWN => ...,
# FIRST => ...,
# LAST => ...,
# LOC => ...,
# }
$OPT{page_cnt} = 0;
my $imge_cnt = 0;
my $idx_page_cnt = 1;
$PAGES[0] -> {HD} = $OPT{contents_header};
$PAGES[0] -> {FILENAME} = "$OPT{slide_prefix}0000.$OPT{slide_suffix}";
$PAGES[0] -> {LEVEL} = 0;
$PAGES[0] -> {NUMBER} = "0";
$PAGES[0] -> {UP} = -1;
$PAGES[0] -> {DOWN} = 1;
$PAGES[0] -> {PREV} = -1;
$PAGES[0] -> {NEXT} = 1;
$PAGES[0] -> {FIRST} = 0;
$PAGES[0] -> {LAST} = 0;
my @TABLE_COLUMN_ALIGN; # alignmen for table columns
my $table_column; # index of table column
my $xref_open = 0; # for images in XREFs ...
my @image_buffer;
my ($f0, $f1, $f2) =
($OPT{index_top}, $OPT{index_dat}, $OPT{index_bot}); # window indices for javascript
my %ANCHOR; # $ANCHOR{a_name} = $OPT{page_cnt}
my (@HEADLINE_PATH, @HEADLINE_PATHS); # ste: headline path parts (first element unused!), modified again for patch 1.01-08
my %INDEX; # index entries
my %IDX_; # index entries available
my $idx_cnt = 0;
my ($center_header_start, $center_header_end) = ("","");
my $table_hl_bgcolor="";
my $td_was_empty = 0; # set to 1 if an empty table entry is detected
if ($OPT{center_headers}){
$center_header_start = "";
$center_header_end = "";
}
my @PG_COLOR;
# can we reload a stream?
if (exists $OPT{reloadStream} && exists $OPT{streamBuffer})
{
warn "\n[Info] Loading cached stream.\n" if $verbose;
@streamData=@{retrieve($OPT{streamBuffer})};
}
else
{
# build parser
my ($parser)=new PerlPoint::Parser;
# and call it
$parser->run( #
stream => \@streamData,
files => \@ARGV,
safe => exists $OPT{activeContents} ? $safe : undef,
filter => exists $OPT{filter} ? $OPT{filter} : "html|perl",
exists $OPT{critical_semantics} ? (criticalSemanticErrors => 1) : (),
activeBaseData => {
targetLanguage => 'HTML',
userSettings => {map {$_=>1} exists $OPT{set} ? @{$OPT{set}} : ()},
},
vispro => 1,
nestedTables => 1,
var2stream => 1,
predeclaredVars => {
CONVERTER_NAME => basename($0),
CONVERTER_VERSION => $main::VERSION,
},
headlineLinks => 1,
trace => TRACE_NOTHING
+ ((exists $OPT{trace} and $OPT{trace} & 1) ? TRACE_PARAGRAPHS : 0)
+ ((exists $OPT{trace} and $OPT{trace} & 2) ? TRACE_LEXER : 0)
+ ((exists $OPT{trace} and $OPT{trace} & 4) ? TRACE_PARSER : 0)
+ ((exists $OPT{trace} and $OPT{trace} & 8) ? TRACE_SEMANTIC : 0)
+ ((exists $OPT{trace} and $OPT{trace} & 16) ? TRACE_ACTIVE : 0),
display => DISPLAY_ALL
+ (exists $OPT{noinfo} ? DISPLAY_NOINFO : 0)
+ (exists $OPT{nowarn} ? DISPLAY_NOWARN : 0),
cache => (exists $OPT{cache} ? CACHE_ON : CACHE_OFF)
+ (exists $OPT{cacheCleanup} ? CACHE_CLEANUP : 0),
exists $OPT{includelib} ? (libpath => $OPT{includelib}) : (),
) or exit 1; #
# store new stream data, if required
nstore(\@streamData, $OPT{streamBuffer}) if exists $OPT{streamBuffer};
}
# build a backend
my $backend=new PerlPoint::Backend( #
name => $me,
trace => TRACE_NOTHING,
display => DISPLAY_ALL
+ (exists $OPT{noinfo} ? DISPLAY_NOINFO : 0)
+ (exists $OPT{nowarn} ? DISPLAY_NOWARN : 0),
vispro => 1); #
# register backend handlers
$backend->register(DIRECTIVE_BLOCK, \&handleBlock);
$backend->register(DIRECTIVE_COMMENT, \&handleComment);
$backend->register(DIRECTIVE_DOCUMENT, \&handleDocument);
$backend->register(DIRECTIVE_HEADLINE, \&handleHeadline);
$backend->register(DIRECTIVE_LIST_LSHIFT, \&handleLShift);
$backend->register(DIRECTIVE_LIST_RSHIFT, \&handleRShift);
$backend->register(DIRECTIVE_ULIST, \&handleList);
$backend->register(DIRECTIVE_UPOINT, \&handlePoint);
$backend->register(DIRECTIVE_OLIST, \&handleList);
$backend->register(DIRECTIVE_OPOINT, \&handlePoint);
$backend->register(DIRECTIVE_DLIST, \&handleList);
$backend->register(DIRECTIVE_DPOINT, \&handleDPoint);
$backend->register(DIRECTIVE_DPOINT_ITEM, \&handleDPointItem);
$backend->register(DIRECTIVE_SIMPLE, \&handleSimple);
$backend->register(DIRECTIVE_TAG, \&handleTag);
$backend->register(DIRECTIVE_TEXT, \&handleText);
$backend->register(DIRECTIVE_VARRESET, \&handleVarReset); # ste
$backend->register(DIRECTIVE_VARSET, \&handleVarSet); # ste
$backend->register(DIRECTIVE_VERBATIM , \&handleVerbatim);
#
my @BUFFER; # buffer for current text
my @ERRBUFFER; # buffer for context of error
my $box_bg_color= "blue";
my $box_fg_color= "white";
if (defined $OPT{box_color}){
$box_bg_color = $OPT{box_color};
}
if (defined $OPT{boxtext_color}){
$box_fg_color= $OPT{boxtext_color};
}
my $default_box_bg_color= $box_bg_color;
my $default_box_fg_color= $box_fg_color;
my $cellpadding = 5;
# and run it
$backend->run(\@streamData);
gen_navigation();
reverse_order() if $OPT{reverse_order} and ! $OPT{slide_md5};
if ($OPT{debug}){
pr_navigation_table();
# exit;
}
if ($idx_cnt and ! $OPT{no_index}) {
# define last page as index page:
$idx_page_cnt = $OPT{page_cnt} +1;
$PAGES[$idx_page_cnt] -> {HD} = $OPT{index_header};
$PAGES[$idx_page_cnt] -> {FILENAME} = "$OPT{slide_prefix}_idx.$OPT{slide_suffix}";
$PAGES[$idx_page_cnt] -> {LEVEL} = 0;
$PAGES[$idx_page_cnt] -> {NUMBER} = "idx";
$PAGES[$idx_page_cnt] -> {UP} = 0;
$PAGES[$idx_page_cnt] -> {DOWN} = -1;
$PAGES[$idx_page_cnt] -> {PREV} = 0;
$PAGES[$idx_page_cnt] -> {NEXT} = 1;
$PAGES[$idx_page_cnt] -> {FIRST} = 0;
$PAGES[$idx_page_cnt] -> {LAST} = -1;
#
} # init index page
## Now do your job: output the pages ...
if ($OPT{java_script_navigation}){
# create java script navigation file
open(JS, "> $OPT{slide_dir}/$java_script_src") or die "Cannot open $java_script_src: $!\n";
print JS <{FILENAME};
$slide = "$OPT{slide_dir}/$slide";
if ($OPT{count_only}){
printf STDERR "\r ... creating slide %4d/%d", $i, $OPT{page_cnt} if $verbose;
} else {
print STDERR " creating $slide ..." if $verbose;
print STDERR " Level ",
$PAGES[$i]->{LEVEL}, " ===> ",
$PAGES[$i]->{HD},
, " <===\n" if $verbose;
}
# open file
open(SLIDE, "> $slide") or die "Can't open file $slide: $!\n";
# include header template and replace KEYWORDS
print_HTML_HEAD(*SLIDE, $i) unless exists $OPT{no_html_header}; # JSTENZEL, 1.01-15
my $gl_fgcolor = defined $PG_COLOR[$i]{fgcolor} ?
$PG_COLOR[$i]{fgcolor} : $OPT{fgcolor};
my $gl_bgcolor = defined $PG_COLOR[$i]{bgcolor} ?
$PG_COLOR[$i]{bgcolor} : $OPT{bgcolor};
my $gl_linkcolor = defined $PG_COLOR[$i]{linkcolor} ?
$PG_COLOR[$i]{linkcolor} : $OPT{linkcolor};
my $gl_alinkcolor = defined $PG_COLOR[$i]{alinkcolor} ?
$PG_COLOR[$i]{alinkcolor} : $OPT{alinkcolor};
my $gl_vlinkcolor = defined $PG_COLOR[$i]{vlinkcolor} ?
$PG_COLOR[$i]{vlinkcolor} : $OPT{vlinkcolor};
print_HTML_BODY(*SLIDE, $i, $OPT{back_image},
$gl_bgcolor,
$gl_fgcolor,
$gl_linkcolor, $gl_alinkcolor, $gl_vlinkcolor,
) unless exists $OPT{no_html_bodytags}; # JSTENZEL, 1.01-15
if ($OPT{frame_set}){
if ($OPT{java_script_navigation}){
create_top_page($i);
}
} else {
insert_template(*SLIDE, $i, $OPT{top_template});
}
if ($OPT{nav_top_template}){
insert_template(*SLIDE, $i, $OPT{nav_top_template});
}
elsif ($OPT{nav_template}){
insert_template(*SLIDE, $i, $OPT{nav_template});
}
# print page body
foreach my $line ( @{$PAGES[$i]->{BODY}} ){
# number the headers if option is set
if ($OPT{num_headers}){
my $num= $PAGES[$i] -> {NUMBER};
my $point = $OPT{trailing_point} ? "." : "";
$line =~ s/_PG_NUM_/$num$point /;
} else {
$line =~ s/_PG_NUM_//;
}
# Replace _INTERNAL_SECTION with correct hyperlink
$line = replace_internal_links($line, "_INTERN_SECTION", "HD");
# Replace _INTERNAL_PAGE with correct hyperlink
$line = replace_internal_links($line, "_INTERN_PAGE","NUMBER");
# Replace _INTERNAL_XREF with correct hyperlink
$line = replace_internal_links($line, "_INTERN_XREF");
print SLIDE $line;
} # loop over body lines
if ($OPT{nav_bottom_template}){
insert_template(*SLIDE, $i, $OPT{nav_bottom_template});
}
elsif ($OPT{nav_template}){
insert_template(*SLIDE, $i, $OPT{nav_template});
}
# include footer template and replace KEYWORDS (navigation ...)
if ($OPT{frame_set}){
if ($OPT{java_script_navigation}){
create_bot_page($i);
}
} else {
insert_template(*SLIDE, $i, $OPT{bottom_template});
}
print SLIDE "