#!/usr/princeton/bin/perl -w
########################################################################
#
# punstar.pl
#
# Application for creating pure HTML files by removing
# Mappamundi markup (*x, *g, *s, etc) from a file.
# Extracts text between *x marks into separate, hotlinked files.
#
# Copyright (c) Princeton University 1995
#
# Jay Lieske, Jr.
# Instructional Technology Services
# Computer and Information Technology
# Princeton University
#
#
#$usage = << END_USAGE;
#punstar removes Mappamundi markup codes (*g, *x, etc.) from
# its input file. Jay Lieske, 95.07.14
#usage: punstar filename.html
#produces: filename-1.html -- the recoded file
# other html files named in *x markup
#END_USAGE
#require "cgi-lib-jay.pl"; # for EncodeURL()
#!/usr/princeton/bin/perl -w
#
# cgi-lib-jay.pl
# Jay Lieske Jr.
# 4 August 1994
# EncodeURL
# Returns copy of input string encoded for URLs (spaces to plus, etc.)
sub EncodeURL {
local( $_) = @_;
s|\%|%25|g;
s|\!|%21|g;
s|\"|%22|g;
s|\#|%23|g;
s|\$|%24|g;
s|\&|%26|g;
s|\'|%27|g;
s|\*|%2A|g;
s|\+|%2B|g;
s|\/|%2F|g;
s|\?|%3F|g;
s|\@|%40|g;
s|[\000-\037][\200-\377]|'%'.sprintf("%2X", $1)|ge;
s| |+|g;
$_;
}
# End of cgi-lib-jay.pl
#require "FormatStar.pl";
#!/usr/princeton/bin/perl -w
########################################################################
#
# FormatStar.pl
#
# Functions for creating pure HTML files by removing
# Mappamundi markup (*x, *g, *s, etc) from a file.
#
# Copyright (c) Princeton University 1995
#
# Jay Lieske, Jr.
# Instructional Technology Services
# Computer and Information Technology
# Princeton University
#
#
# Usage:
# at top of program,
# require "FormatStar.pl"
#
# to reformat a string of HTML by embedding hotlinks,
# $linkedtext = &LinkStar( $text);
#
# to reformat a string of HTML without hotlinks,
# $plaintext = &StripStar( $text);
#
#require "cgi-lib-jay.pl"; # for EncodeURL()
# Global variables used in module:
if (0) {
$ImageGIF;
$ImageJPEG;
$Table;
$Debug;
$ScriptSlide;
$ScriptGloss;
&FormatStar;
&LinkStar;
&StripStar;
}
########################################################################
# MakeLinkHTML
#
# Generate HTML code for text hotlink to something.
#
# usage: print &MakeLinkHTML( $url, $caption);
#
# Globals: none
#
sub MakeLinkHTML {
local ($url, $caption) = @_;
local ($html) = "";
if ($url !~ /^\s*$/) {
$html = "$caption";
}
$html; # return value
}
########################################################################
# MakeImageHTML
#
# Generate HTML code for thumbnail image hotlinked to hi-res image.
#
# usage: print &MakeImageHTML( $cd, $caption);
#
# Globals: $ImageGIF -- URL to directory where thumbnail images are kept.
# $ImageJPEG -- URL to directory where hi-res images are kept.
#
sub MakeImageHTML {
local ($cd, $caption) = @_;
local ($html) = "";
$caption = "Image" if !defined($caption);
# If $cd is not blank, create an inline and linked image string.
if ($cd !~ /^\s*$/) {
# Chop off leading zeros.
$cd =~ s/^0+([1-9])/\1/;
$cd =~ s/\-0+([1-9])/\-\1/;
$html = ""
. "
";
}
$html; # return value
}
########################################################################
# MakeAudioHTML
#
# Generate HTML code for hotlink to audio.
#
# usage: print &MakeAudioHTML( $sound, $caption);
#
# Globals: none
#
sub MakeAudioHTML {
local ($sound, $caption) = @_;
local ($html) = "";
if ($sound !~ /^\s*$/) {
$html = "$caption";
}
$html; # return value
}
########################################################################
# MakeTextHTML
#
# Generate HTML code for hotlink to external text.
#
# usage: print &MakeTextHTML( $text, $caption);
#
# Globals: none
#
sub MakeTextHTML {
local ($text, $caption) = @_;
local ($html) = "";
if ($text !~ /^\s*$/) {
$html = "$caption";
}
$html; # return value
}
########################################################################
# MakeSlideHTML
#
# Generate HTML code for text hotlink which refers to slide sheet in
# database.
#
# usage: print &MakeSlideHTML( $slide, $text);
#
# Globals: $ScriptSlide -- URL to CGI to display slide page.
# $Table -- the Oracle table from which the slide will be read.
# $Debug -- either "/debug" or "".
#
sub MakeSlideHTML {
local ($id, $text) = @_;
local ($html) = "";
$id =~ s/\s//g;
$id = &EncodeURL( $id);
# A fix in case we are searching the glossary table --bpd
local($table) = $Table;
$table="mappa" if ($table eq "gloss");
$html = "$text";
$html; # return value
}
########################################################################
# MakeGlossHTML
#
# Generate HTML code for text hotlink which refers to glossary page in
# database.
#
# usage: print &MakeGlossHTML( $term, $text);
#
# Globals: $ScriptGloss -- URL to CGI to display glossary page.
# $Debug -- either "/debug" or "".
#
sub MakeGlossHTML {
local ($term, $text) = @_;
local ($html) = "";
$term = &EncodeURL( $term);
$html = "$text";
$html; # return value
}
########################################################################
# FormatStar
#
# Main subroutine to look for star tags in $text and replace them with
# valid HTML. Output code will be hotlinked if $linking is true.
#
# usage: print &FormatStar( $text, $linking);
#
# Globals: none
#
sub FormatStar {
local ($text, $linking) = @_;
local ($out) = "";
local ($this, $display, $search, $star);
local (@stars) = ("g", # glossary word
"s", # slide in database
"l", # URL
"m", # map
"a", # music/audio
"t"); # link to external text
# "x": text to make external not processed here
local ($stars) = join( "", @stars);
# Repeated look over the string, matching each star tag in turn.
# Tags can not be nested.
#
MATCH:
while ($text ne "") {
# Any stars in the text?
if ($text =~ m/\*([$stars])/io) {
# Copy string before *g.
$out .= $`;
# Which tag did we find?
#$star = $&;
$star = $1;
# Advance to after *g.
$text = $';
# Advance to after closing *,
# saving the intervening text.
$text =~ s/^([^*]*)\*//;
$this = $1;
# Chop off leading/trailing spaces.
$this =~ s/^\s+//;
$this =~ s/\s+$//;
# If the text has alternate database and display version, get them.
($search, $display) = split( m!/!, $this, 2);
$display = $search if (!defined($display) || $display =~ /^\s*$/);
# Glossary word:
$star eq "g" && do {
$out .= $linking ? &MakeGlossHTML( $search, $display)
: $display;
next MATCH;
};
# Slide in database:
$star eq "s" && do {
$out .= $linking ? &MakeSlideHTML( $search, $display)
: $display;
next MATCH;
};
# Map or image:
$star eq "m" && do {
$out .= $linking ? &MakeImageHTML( $search, $display)
: $display;
next MATCH;
};
# URL hotlink:
$star eq "m" && do {
$out .= $linking ? &MakeLinkHTML( $search, $display)
: $display;
next MATCH;
};
# Music/audio:
$star eq "a" && do {
$out .= $linking ? &MakeAudioHTML( $search, $display)
: $display;
next MATCH;
};
# Text:
$star eq "t" && do {
$out .= $linking ? &MakeTextHTML( $search, $display)
: $display;
next MATCH;
};
}
else {
# No star: just append text.
$out .= $text;
last MATCH;
}
};
$out;# return value
}
########################################################################
# usage: print &StripStar( $text);
sub StripStar {
return &FormatStar( $_[0], 0);
}
########################################################################
# usage: print &LinkStar( $text);
sub LinkStar {
return &FormatStar( $_[0], 1);
}
1; # successful require
# end of FormatStar.pl
#require "ExtractStar.pl";
#!/usr/princeton/bin/perl -w
########################################################################
#
# ExtractStar.pl
#
# Functions for creating pure HTML files by removing
# Mappamundi markup (*x, *g, *s, etc) from a file.
# Extracts text between *x marks into separate, hotlinked files.
#
# Copyright (c) Princeton University 1995
#
# Jay Lieske, Jr.
# Instructional Technology Services
# Computer and Information Technology
# Princeton University
#
#
# Usage:
# at top of program,
# require "ExtractStar.pl"
#
# to copy HTML from STDIN to STDOUT,
# &ExtractStar( STDIN, STDOUT, "Title");
#
# Global variables used in module:
if (0) {
&ExtractStar;
}
#require "FormatStar.pl";
########################################################################
# MakeHeadHTML
#
# Generate HTML code for
"; } $html; # return value } ######################################################################## # ExtractStar # # Main subroutine to look for *x tags in $text, extract the surrounded # text to a separate file, and insert links to the extracted text file. # Extracted text blocks can be nested, and this function calls itself # recursively. # # The parameters are file names which are also file handles. # The calling subroutine should create the basic HTML structuring # of
... before calling # and after calling. # # usage: &ExtractStar( $infile, $outfile); # # Globals: none # sub ExtractStar { local ($infile, $outfile, $title) = @_; local ($/);# input line separator local ($text); for (;;) { # Scan for *x tag. $/ = "*x"; $text = <$infile>; # Look for a