home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / lib / rpm-2.5.5 / mkcopyright.pl < prev    next >
Encoding:
Perl Script  |  1998-07-14  |  1.8 KB  |  80 lines

  1. #!/usr/bin/perl -w
  2. # $Id: mkcopyright.pl,v 1.1 1997/11/20 01:15:59 ray Exp $
  3. #use strict;
  4.  
  5. ($C = $0) =~ s%.*/%%;
  6.  
  7. my $In;
  8. my $Out;
  9. my $Mode = 1;
  10.  
  11. my $Help = 0;
  12. my $OptErr = "";
  13. my $verbose = 0;
  14. my $debug = 0;
  15. my $p = 0;
  16.  
  17.  
  18. while ( $#ARGV >= $[ && ($_ = shift, /^-/ || (unshift(@ARGV,$_) && 0)) ) {
  19.   last if /^--$/;
  20.   (/^--mode=(\d+)$/)            && ($Mode = $1, next);
  21.   (/^--verbose$/ || /^-v$/)        && ($verbose ++, next);
  22.   (/^--debug$/ || /^-d$/)        && ($debug ++, $verbose ++, next);
  23.   (/^--?help/ || /^-h/)            && ($Help = 1, next);
  24.   (/^-/)                && ($OptErr .= "$_ ", $_ = "", next);
  25. }
  26.  
  27.  
  28. $OptErr = sprintf( "$C: unkown option: %s\n", $OptErr) if ( $OptErr );
  29.  
  30. if ( $#ARGV < $[ + 1 ) {
  31.   $OptErr .= sprintf( "$C: missing parameter(s)\n");
  32. } elsif ( $#ARGV > $[ + 1 ) {
  33.   $OptErr .= sprintf( "$C: superfluous parameter(s)\n");
  34. } else {
  35.   $In = shift;
  36.   $Out = shift;
  37. }
  38.  
  39. if ( $OptErr || $Help ) {
  40.   print( STDERR $OptErr) if ( $OptErr );
  41.   die( "Usage: $C [options] in out\n");
  42. }
  43.  
  44. open( IN, "<$In") || die("open($In): $!\n");
  45. open( OUT, ">$Out") || die("open($Out): $!\n");
  46. select( OUT);
  47.  
  48. if ( $Mode == 1 ) {
  49.   print( " *\n");
  50.  
  51.   while ( <IN> ) {
  52.     $p = 1 if ( /^ \* Copy/ );
  53.     last if ( /^ \*\// );
  54.     print if ( $p );
  55.     $last = $_;
  56.   }
  57.  
  58.   print( " *\n") unless ( $last =~ /^ \*\s*$/ );
  59. } else {
  60.   unlink $Out;
  61.   print( STDERR "$C: mode $Mode not implemented!\n");
  62.   exit( 1);
  63. }
  64.  
  65. close( OUT);
  66. close( IN);
  67. cpmod( $In, $Out);
  68. exit( 0);
  69.  
  70. sub cpmod($$) {
  71.   my( $Org, $Dup) = @_;
  72.   my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  73.       $atime,$mtime,$ctime,$blksize,$blocks) = stat($Org);
  74.   $mode &= 007777; $mode |= 000200;
  75.   chown( $uid, $gid, $Dup) || die( "$CMD: cannot chown( $uid, $gid, $Dup).\n");
  76.   chmod( $mode, $Dup) || die( "$CMD: cannot chmod( $mode, $Dup).\n");
  77.   utime( $atime, $mtime, $Dup) || die( "$CMD: cannot utime( $Dup).\n");
  78. }
  79.  
  80.