#! /usr/local/bin/perl # (C) 2001 Mark Bergman # mbergman@pliva.hr # # # Wrapper to ci... # The wrapper will: # attempt to make the RCS subdirectory # check in the file # start the user's $EDITOR or specified editor or default on the file # check in the file # eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; $running_under_some_shell="/dev/null"; # Shut up the -w option! $DEBUG=0; use diagnostics; use integer; # PROGNAME -- # Command line: # PROGNAME [-VV|-L] # PROGNAME -i # # -v atomic report program version # -L atomic report program limits # ########## # Variables # ######## $|=1; # Flush output #################### START OF STANDARD SUBROUTINES $RCSversion='$Header: /usr/local/src/RCS/rcsedit,v 1.1 2001/12/14 12:53:29 mbergman Exp mbergman $'; ($NAME=$0)=~s#^.*/##; sub version { # Display the version number and date of modification extracted from # the RCS header. $RCSversion=~s/\S+\s\S+\s(\S+\s\S+).*/$1/; print $0 . ": " . $RCSversion . "\n"; exit 0 } sub limits { print "$NAME: No internal limits beyond perl.\n"; exit 0; } sub usage { print "\t$NAME [-V|-L] [-e editor] [-c] file file file...\n"; print "\t$NAME -i\n"; print "\t\t-v atomic report program version\n"; print "\t\t-L atomic report program limits\n"; print "\n"; print "\t\t-e editor\tspecify the editor (default: \$EDITOR)\n"; print "\t\t-c create the file if it does not exist\n"; print "\t@_\n"; exit 1; } sub debug { # Handle debugging. The debug routine depends on the presence of # the variable "DEBUG", which should be set as follows: # =\d only print debug statements that exactly match # the specified level # # \d print debug statements at or less than the level local($level,$statement)=@_; my $debug=$DEBUG; if ( $DEBUG !~ /=\d+/ ) { if ( $debug >= $level ) { print STDERR $statement; } } else { $debug=~s/=//; if ( $debug == $level ) { print STDERR $statement; } } } sub prompt { local($question,$default)=@_; local($answer); print $question; while() { chop; if ( ( $default ne "" ) && ($_ eq "" ) ) { $answer=$default; } else { # ($answer) = split(); $answer = $_; } last; } return $answer; } sub myGetopts { # Usage: # do Getopts('a:bc'); # -a takes arg. -b & -c not. Sets opt_* as a # # side effect. local($argumentative) = @_; local(@args,$_,$first,$rest); local($errs) = 0; @args = split( / */, $argumentative ); while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) { ($first,$rest) = ($1,$2); $pos = index($argumentative,$first); if($pos >= 0) { if($pos < $#args && $args[$pos+1] eq ':') { shift(@ARGV); if($rest eq '') { ++$errs unless @ARGV; $rest = shift(@ARGV); } ${"opt_$first"} = $rest; } else { ${"opt_$first"} = 1; if($rest eq '') { shift(@ARGV); } else { $ARGV[0] = "-$rest"; } } } else { return(1); ++$errs; if($rest ne '') { $ARGV[0] = "-$rest"; } else { shift(@ARGV); } } } return(0); } sub parse { if ( myGetopts("VLce:") != 0 ) { usage("Invalid option"); } if ( defined($opt_V) && $opt_V == 1 ) { &version(); } if ( defined($opt_L) && $opt_L == 1 ) { &limits(); } if ( defined($opt_c) && $opt_c == 1 ) { $CREATE="YES"; } if ( defined($opt_e) && $opt_e ne "1" ) { $EDITOR=$opt_e; } } sub systemplus { # Pass arguments to system() and deal w. any errors local $returnval=""; $returnval = 0xffff & system @_; if ($returnval == 0) { # print "ran with normal exit\n"; return(0); } printf "system(%s) returned %#04x: ", "@_", $returnval; if ($returnval == 0xff00) { print "command failed: $!\n"; } if (($returnval & 0xff) == 0) { $returnval >>= 8; print "ran with non-zero exit status $returnval\n"; } else { print "ran with "; if ($returnval & 0x80) { $returnval &= ~0x80; print "coredump from "; } print "signal $returnval\n" } return($returnval); } #################### END OF STANDARD SUBROUTINES @TARGETFILES=(); @TARGETDIRS=(); $EDITOR="/usr/bin/vi"; # Default $REAL_CI="/usr/bin/ci"; @CI_ARGS=("-I","-l","-q"); $CREATE="NO"; parse(); if ( $#ARGV == -1 ) { usage("Name of file to edit is required."); } if ( defined( $ENV{'EDITOR'}) ) { $EDITOR= $ENV{'EDITOR'}; } # Extract the file/directory names from ARGV foreach $arg ( @ARGV ) { # We may have a file/directory if ( -f $arg ) { push(@TARGETFILES,$arg); } else { if ( $CREATE eq "YES" ) { # The named file doesn't exist...try to touch it so that the # initial ci won't fail open(FILE,">$arg") || die "Cannot create $arg $!"; close(FILE) || die "Whoops! Cannot close $arg $!"; push(@TARGETFILES,$arg); } else { usage("$arg: No such file."); } } if ( $arg !~ qq/\// ) { push(@TARGETDIRS,"."); } else { $arg=~s,/[^/]*$,,; push(@TARGETDIRS,$arg); } } # Make the RCS subdirectories, if possible foreach $dir ( @TARGETDIRS ) { $dir=$dir . "/RCS"; if ( ! -d "$dir" ) { # It's safe to die if the mkdir() fails, since the user # also wouldn't have permissions to create the ",v" file. mkdir($dir) || die "Could not make $dir: $!"; } } foreach $file ( @TARGETFILES ) { $err=systemplus($REAL_CI,@CI_ARGS,$file); if ( $err != 0 ) { exit($err); } $err=systemplus($EDITOR,$file); if ( $err != 0 ) { exit($err); } $err=systemplus($REAL_CI,@CI_ARGS,$file); if ( $err != 0 ) { exit($err); } }