#!/usr/local/bin/perl5
# -*- perl -*-
use P4CGI ;
use strict ;
#
#####################################################################
##
##  CONFIGURATION INFORMATION 
##  All config info should be in $configFile (see init() in P4CGI.pm)
##
#####################################################################
##
##  DowNLoaD a file
##
#####################################################################

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

my $filename = $file ;
$filename =~ s/.*\/// ;

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

local *P4 ;

&P4CGI::p4call( *P4, "print -q \"$file#$revision\"" );
$file = join('',<P4>) ;
close P4 ;

my $len = length($file) ;

print 
    "Content-type: application/octet-stream\n",
    "Content-Disposition: filename=$filename;size=$len\n",
    "Content-Description: Download file:$filename Rev:$revision\n",
    "\n" ;
print $file ;