#!/usr/bin/env perl # # $Id: //guest/daniel_kionka/save-opened/save-opened.pl#1 $ # # Copyright (c) 2005 Daniel P. Kionka; all rights reserved # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # use strict; use warnings; use File::Basename; use File::Path; use File::Spec; use Getopt::Std; #----------- # variables #----------- # constants my $PROG = basename($0); my @reqP4 = qw(P4CLIENT P4PORT); # for config file my %configOpts; # p4 client values my %hashClient; # command line options my $verbose = 0; #----------- # functions #----------- # # Message about this program and how to use it # sub usage() { print STDERR << "EOF"; This program saves all open files in the p4 client. usage: $0 [-dhv] [-c client] -c client : override P4CLIENT -d : print debugging messages to stderr -h : this (help) message -v : verbose output EOF exit 1; } # # set command line options # sub setOptions() { my %opt; my $opt_string = 'c:dhv'; getopts( "$opt_string", \%opt ) || usage(); usage() if $opt{h}; foreach my $arg (@ARGV) { print "arg = $arg\n"; } # set global flags $verbose = $opt{v}; } sub verbose($) { my ($message) = @_; print "$PROG: $message\n" if ($verbose); } # # read configuration # sub readP4Set() { # start with p4 set values verbose("reading p4 set..."); open P4SET, "p4 set |" || die "Bad can not run p4 set."; while (defined(my $line = )) { my ($key, $val) = ($line =~ m/^(\S+)=(\S+)/); die "Bad p4 set line: $line" if (! defined($val)); verbose("$key = $val"); $configOpts{$key} = $val; } close P4SET; } sub verifyP4Set() { # verify p4 variables are set verbose("p4 values:"); foreach my $key (@reqP4) { $ENV{$key} = $configOpts{$key} if (defined($configOpts{$key})); die "Missing p4 variable: $key" if (! defined($ENV{$key})); verbose("$key = $ENV{$key}"); } } # # do the build-boot-strap # sub doSave() { return 0; } #---------- # mainline #---------- readP4Set(); setOptions(); verifyP4Set(); my $err = doSave(); printf("$PROG: %s\n", ($err ? "Failed" : "Succeeded")); exit $err;