#!/usr/local/bin/perl # # Gateway script to convert some sample LaTeX files into HTML "on the fly" # using the LaTeX2HTML translator. # # Written by Nikos Drakos (nikos@cbl.leeds.ac.uk) # 26-APR-1994, Computer Based Learning Unit, University of Leeds. # $USER = "/usr/cblelca/nikos"; $LATEX2HTML = "$USER/bin/www94.script/latex2html"; $DEBUG = 0; $OUT_DIR = "$USER/WWW/tmp/examples"; $EXAMPLES_DIR = "$USER/rep/papers/www94/examples"; $INIT = "$EXAMPLES_DIR/latex2html-init"; $LOG = "$OUT_DIR/LOG"; # This is for debugging only... $PRINTENV = '/usr/ucb/printenv'; $| = 1; require("$USER/WWW/cgi-bin/getformargs.pl"); &debug if $DEBUG; &convert; # # FORM FIELDS: # # t - title # address # split # no_navigation - navigation panel # show_section_numbers # ascii_mode # info # example # # GLOBAL VARIABLES # # $result # $example - 2, 3 or 5 # %in - holds the data from the form # $command_line - holds the users choices which are passed on to latex2html sub convert { unless (&busy) { ($ENV{'QUERY_STRING'} ? &GetFormArgs : do {%in = ("t", "my document", "split", "0", "show_section_numbers", "0", "example", "Mathematical Equations", "address", "Me", "no_navigation", "1", "ascii_mode", 1, "info", "hello\n all\nsss")}); $example = "example" . &get_example; &get_command_line; do { print "Content-type: text/plain\n\n\n"; print "$LATEX2HTML -init_file $INIT $command_line -dir $OUT_DIR $EXAMPLES_DIR/$example.tex";} if $DEBUG; #`/usr/bin/X11/xterm -display "cblipca:0.0"`; &redirect_output; system("$LATEX2HTML -init_file $INIT $command_line -dir $OUT_DIR $EXAMPLES_DIR/$example.tex"); &output_back_to_normal; &log; $result = "http://cbl.leeds.ac.uk/nikos/tmp/examples/$example/$example.html\n"; } &print_result; } sub get_command_line { local($_,$key,$val); if ($example eq "example5") { # CHEATING because must start afresh # if -ascii_mode is used $dir = "$OUT_DIR/example5"; ( $in{"ascii_mode"} ? system("cp $dir/images.ascii $dir/images.pl") : system("cp $dir/images.normal $dir/images.pl")); } foreach ("show_section_numbers", "no_navigation", "ascii_mode") { # if they are 0 blow them away otherwise leave them as options # with no arguments ( $in{$_} ? $in{$_} = "" : delete($in{$_})); } foreach ("t", "address", "info") { $in{$_} = &truncate(&clean($in{$_})); delete($in{"$_"}) unless $in{"$_"}; } foreach $key (keys %in) { $command_line .= "-$key ". (($in{$key} ne "") ? "\'$in{$key}\' " : "");} } sub clean { local($_) = @_; # Remove newlines and shell metacharacters s/(\n|\W)/$1 if ($1 eq " ");/eg; $_; } sub truncate { local($_) = @_; local($message) = "
Sorry... The rest was thrown away to make the conversion faster."; s/^(.{0,1000})(.{1001,})/$1 $message/; $_; } sub get_example { local($_); $_ = $in{'example'}; delete $in{'example'}; # Blow it away if (/Structure/) {2} elsif (/Cross/) {3} elsif (/Mathematical/) {5}; } sub busy { local(@count, $count); @count = grep(/perl/, `ps -axur`); $count = @count; # Get number of perl processes running ( ($count > 1) ? $result = "Someone else has beaten you to it!\n" . "Please try again later in 30-60 seconds." : # This will return true (ie busy) 0); # All is OK - Continue } sub print_result { if ($result =~ /nikos/) { print "Location: $result\n\n\n"} else { print "Content-type: text/plain\n\n\n"; print $result; } } sub print_parameters { local($key); foreach $key (keys %in) { print "$key -- $in{$key} \n"; } } sub redirect_output { open(SO, ">&STDOUT"); open(SE, ">&STDERR"); open(STDOUT, ">/tmp/foo$$"); open(STDERR,">&STDOUT"); select(STDERR); $| = 1; select(STDOUT); $| = 1; } sub output_back_to_normal { close(STDOUT); close(STDERR); open(STDOUT, ">&SO"); open(STDERR, ">&SE"); } sub log { open(OUTPUT, ">>$LOG"); print OUTPUT join("\t:\t", $ENV{'REMOTE_HOST'}, $ENV{'REMOTE_ADDR'}, `date`) if $ENV{'QUERY_STRING'}; close OUTPUT; } sub debug { print "Content-type: text/plain\n\n\n"; $_ = `$PRINTENV`; s/ /
/g; print; };