#!perl -w # -*- Perl -*- # Copyright 1999 Greg Spencer (greg_spencer@acm.org) package p4Util; BEGIN { # because not all machines do Y2K stuff right... $YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0; @epoch = localtime(0); } ############################################################### # Subroutines ############################################################### # This takes a time integer and creates a simple timestamp from it. # It returns a time string and a date string in a list (in that order). # The date and time are in the local time zone. # I *think* it's Y2K safe, but there is no warranty. sub ShortTimestamp { my $ltime = shift; my $ampm = "am"; my @now = localtime($ltime); if ($now[2]>12 && $now[2]!=24) { $now[2] -= 12; $ampm = "pm"; } elsif ($now[2] == 12) { # fix for "noon" $ampm = "pm"; } elsif ($now[2] == 24) { # fix for "midnight" $ampm = "am"; $now[2] = 12; } # do that Y2K stuff -- yucko. # localtime should just return a four char year... $year = $now[5]; $year += $YearFix if ($now[5] < $epoch[5]); # just in case they do it "right" on some machines. $year -= 1900 if $year > 1900; $year += 1900; return (sprintf ("%2d:%02d:%02d$ampm",$now[2],$now[1],$now[0]), sprintf("%d/%d/%04d",$now[4]+1,$now[3],$year)); } # This collects information about a list of files in the perforce # database. # # It returns a hash of hashes with a number of pieces of information about # the files. # # If the hash doesn't contain a file that was in the input, then that # file could not be found. The hash is indexed by depot name (not # local name). # # Stuff you can get: # clientFile -- local path # depotFile -- name in depot (same as hash key) # headAction -- action at head rev, if in depot # headChange -- head rev type, if in depot # headRev -- head rev #, if in depot # headType -- head rev type, if in depot # headTime -- head rev mod time, if in depot # haveRev -- rev had on client, if on client # action -- open action, if opened # change -- open changelist#, if opened # unresolved -- unresolved integration records # otherOpen -- set if someone else has it open # otherLock -- set if someone else has it locked # ourLock -- set if this user/client has it locked sub GetFileInfo { my @input_files = @_; my %filehash; my $line; my %info; # quote the filenames (in case there are spaces) foreach (@input_files) { chomp; $_ = "\"$_\""; } # open the input pipe if (!open(INPUT,"p4 fstat @input_files 2>&1 |")) { print "Status: 200 OK\n"; print "Content-type: text/html\n\n"; print "
Unable to open p4...\n"; print "