#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
#  CONFIGURATION INFORMATION 
#  All config info should be in P4CGI.pm
#
#################################################################
#
#  P4 special file viewer for HTML, JPEG and GIF files
#  View a "special" file
#
#################################################################

# Get type arg
my $type = P4CGI::cgi()->param("TYPE") ;
&P4CGI::bail("No file type specified") unless defined $type ;

# Get file spec argument
my $file = P4CGI::cgi()->param("FSPC") ;
&P4CGI::bail("No file specified") unless defined $file ;

my $revision = P4CGI::cgi()->param("REV") ;
&P4CGI::bail("No revision specified") unless defined $revision ;


if($type eq "HTML") {
    print "Content-type: text/html\n\n" ;

    local *P4 ;
    &P4CGI::p4call( *P4, "print $file#$revision" );
    <P4> ;
    while(<P4>) {
	print ;
    } ;    
}
elsif($type eq "GIF") {
    print "Content-type: image/gif\n\n" ;

    local *P4 ;
    &P4CGI::p4call( *P4, "print $file#$revision" );
    <P4> ;
    while(<P4>) {
	print ;
    } ;    

}
elsif($type eq "JPEG") {
    print "Content-type: image/jpeg\n\n" ;

    local *P4 ;
    &P4CGI::p4call( *P4, "print $file#$revision" );
    <P4> ;
    while(<P4>) {
	print ;
    } ;    

}
else {
   &P4CGI::bail("Unknown type $type!") ; 
} ;

#
# That's it folks
#