#!/usr/bin/perl -w # -*- perl -*- use P4CGI ; use strict ; # ################################################################# # CONFIGURATION INFORMATION # All config info should be in P4CGI.pm # ################################################################# # # P4 "smart" HTML file viewer (maybe too smart....) # View a HTML file # ################################################################# use viewConfig ; # Get type arg my $type = P4CGI::cgi()->param("TYPE") ; &P4CGI::bail("No file type specified") unless defined $type ; if($type ne "ABOUT") { my $content = "text/html" ; # Get file spec argument my $file = P4CGI::cgi()->param("FSPC") ; &P4CGI::bail("No file specified") unless defined $file ; my $revision = P4CGI::cgi()->param("REV") ; $revision = "#$revision" if defined $revision ; $revision="" unless defined $revision ; my $filename=$file ; $filename =~ s/^.*\///; print "Content-Type: $content\n", "Content-Disposition: filename=$filename\n", "\n" ; my $fileText ; &P4CGI::p4call(\$fileText, "print -q \"$file$revision\"" ); my @file = split(/(<[^>]+>)/,$fileText) ; my $l ; foreach $l (@file) { if($l =~ /^<(\w+)/) { my $fld=uc($1) ; my $prompt ; $prompt = "href" if $fld eq "A" ; $prompt = "src" if $fld eq "FRAME" ; $prompt = "src" if $fld eq "IMG" ; $prompt = "background" if $fld eq "BODY" ; unless(defined $prompt) { print $l ; next ; } if ($l =~ /^(<.*$prompt=\")([^\"]+)(\".*)/i ) { #" my ($s,$url,$e) = ($1,$2,$3) ; if ($url =~ m|^\w+://| or $url =~ m|^/| or $url =~ m|:\d+$|) { print $l ; next ; } ; my $ext = "" ; if($url =~ /.*\.(\w+)$/) { $ext = uc($1) ; } my $dir = $file ; $dir =~ s|[^/]*$|| ; my $lnfile = &P4CGI::fixspaces("$dir$url") ; my @log ; &P4CGI::p4call(\@log, "filelog \"$dir$url\" 2>/dev/null" ); if(@log == 0 or $log[1] =~ /delete on/) { print $l ; next ; } if(exists $viewConfig::ExtensionToType{$ext}) { my $type = $viewConfig::ExtensionToType{$ext} ; my ($nurl,$desc,$content,$about) = @{$viewConfig::TypeData{$type}} ; $url = "$nurl?FSPC=$lnfile&TYPE=$type" ; } else { $url = &P4CGI::FV_URL() . "?FSPC=$lnfile" ; } print "$s$url$e" ; next ; } } print "$l" ; } ; } else { while() { print ; } ; } # # That's it folks # __END__ Content-Type: text/html P4DB: About HTML Viewer
Note about the HTML viewer
The "smart" HTML viewer translate relative links to links to files in the depot.