1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#!@PATH_PERL@
eval 'exec @PATH_PERL@ -S $0 ${1+"$@"}'
if $running_under_some_shell;
##
## map2html -- convert server-side to client-side imagemap
## Copyright (c) 1996-1998,1999 Ralf S. Engelschall, All Rights Reserved.
##
require 5.003;
use lib "@INSTALLPRIVLIB@";
use lib "@INSTALLARCHLIB@";
use lib "/usr/share/wml";
use Getopt::Long ();
#
# process command line
#
sub usage {
print STDERR "Usage: map2html [options] mapfile\n";
print STDERR " where options are\n";
print STDERR " -t type map format: 'ncsa' or 'cern' (default)\n";
print STDERR " -d shape default area shape: 'def' (default) or 'rect'\n";
print STDERR " -n name produce a map called <name> (default is filename)\n";
print STDERR " -o file output file\n";
print STDERR " -h help (this text)\n";
print STDERR " -v version information\n";
exit(1);
}
sub version {
print STDERR "This is MAP2HTML, Version 1.1\n";
exit(0);
}
$opt_v = 0;
$opt_h = 0;
$opt_o = "-";
$opt_t = "ncsa";
$opt_d = "def";
$opt_n = "";
$Getopt::Long::bundling = 1;
$Getopt::Long::getopt_compat = 0;
$rc = Getopt::Long::GetOptions("v|verbose",
"t|type=s",
"d|defshape=s",
"n|name=s",
"o|outputfile=s",
"h|help");
if (not $rc or $opt_h or (!@ARGV)) {
&usage;
}
if ($opt_v) {
&version;
}
$server = $opt_t;
$defshape = $opt_d;
$name = $opt_n;
$default = "";
$lastc = "";
$alt = "";
if ($opt_o eq "-") {
*OUT = *STDOUT;
}
else {
open(OUT, ">$opt_o") || die "Cannot open output file ``$opt_o''";
}
for $file (@ARGV) {
&domap(*OUT, $file, $name);
}
if ($opt_o ne "-") {
close(OUT);
}
sub domap {
local(*OUT, $file, $name) = @_;
local(*IN);
open(IN, "<$file") || warn "Can't open: $file\n", return;
if ($name eq "") {
$name = $file;
}
print OUT "<MAP NAME=\"$name\">\n"; # header
while(<IN>) {
&doline(*OUT, $_);
}
print OUT "$default"; # the default URL must be last
print OUT "</MAP>\n";
close(IN);
return;
}
sub doline {
local(*OUT, $line) = @_;
local(@coords);
local($coords, $href, $type);
$type='dodgy'; # make sure that it doesn't print anything unless it's set
$line =~ s|\n$||;
$line =~ s|
$||;
if ($server =~ m|cern|i) {
if ($line =~ m|^\s*default\s+(\S+)\s*$|i) {
if ($defshape eq "rect") {
$default = "<AREA SHAPE=RECT COORDS=\"0,0,9999,9999\" HREF=\"$1\" ALT=\"DEFAULT\">\n";
}
else {
$default = "<AREA SHAPE=DEFAULT HREF=\"$1\" ALT=\"DEFAULT\">\n";
}
return;
}
elsif ($line =~ m/^\s*(circle|poly|rectangle)\s+([^\000]+)\s+(\S+)\s*$/i) {
$type = $1;
$href = $3;
$coords = $2;
$type =~ s/rectangle/rect/i; # CERN uses rectangle but we want rect
}
elsif ($line =~ m/^\s*#\s+(.+)\s*$/i) {
$lastc = $1;
print OUT "<!-- $1 -->\n";
}
else {
chop($line);
print OUT "<!-- Unrecognized line: $line -->\n";
$lastc = "";
}
} elsif ($server =~ m|ncsa|i) {
if ($line =~ m|^\s*default\s+(\S+)\s*$|i ) {
if ($defshape eq "rect") {
$default = "<AREA SHAPE=RECT COORDS=\"0,0,9999,9999\" HREF=\"$1\" ALT=\"DEFAULT\">\n";
}
else {
$default = "<AREA SHAPE=DEFAULT HREF=\"$1\" ALT=\"DEFAULT\">\n";
}
return;
}
elsif ($line =~ m/^\s*(circle|poly|rect|point)\s+(\S+)\s+([^\000]+)$/i) {
$type = $1;
$href = $2;
$coords = $3;
}
elsif ($line =~ m/^\s*#\s+(.+)\s*$/i) {
$lastc = $1;
print OUT "<!-- $1 -->\n";
}
else {
chop($line);
print OUT "<!-- Unrecognized line: $line -->\n";
$lastc = "";
}
}
else {
print "Dodgy server set!\n";
exit;
}
if ($type =~ m/(circle|poly|rect)/i) {
# convert the coords to a comma separated list of numbers
@coords = ();
$type =~ tr|a-z|A-Z|;
while($coords =~ s|^\D*(\d+)||) {
push(@coords, $1);
}
$coords = join(",", @coords);
if ($lastc ne "") {
$alt = $lastc;
}
print OUT "<AREA SHAPE=$type COORDS=\"$coords\" HREF=\"$href\" ALT=\"$alt\">\n";
$lastc = "";
$alt = "";
}
}
##EOF##
__END__
=head1 NAME
map2html - convert server-side to client-side imagemap
=head1 SYNOPSIS
B<map2html>
[B<-t> I<type>]
[B<-d> I<shape>]
[B<-n> I<name>]
[B<-o> I<outputfile>]
[B<-v>]
[I<inputfile>]
=head1 DESCRIPTION
The F<map2html> program reads I<inputfile> and converts
its contents from a server-side map to a client-side map.
=head1 OPTIONS
=over
=item B<-t> I<type>
Sets the type of the server-side map. Either C<ncsa> (default) or C<cern>.
=item B<-d> I<shape>
Sets the default area shape. Either C<def> (default) or C<rect>.
=item B<-n> I<name>
Produce a map called I<name>. Default is I<inputfile>.
=item B<-o> I<outputfile>
This redirects the output to I<outputfile>. Usually the output will be send to
C<stdout> if no such option is specified or I<outputfile> is "C<->".
=item B<-v>
This sets verbose mode where some processing information will be given on the
console.
=back
=head1 AUTHOR
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
=cut
|