home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2734 < prev    next >
Internet Message Format  |  1991-02-09  |  2KB

  1. From: vixie@pa.dec.com (Paul Vixie)
  2. Newsgroups: alt.sources,comp.lang.perl
  3. Subject: mkrcs - perl script to check in a whole tree
  4. Message-ID: <1991Feb9.181603.16589@pa.dec.com>
  5. Date: 9 Feb 91 18:16:03 GMT
  6.  
  7. #! /usr/local/bin/perl
  8.  
  9. # mkrcs - create any missing RCS subdirectories, check in all text files
  10. #    will use "ci -k" if there are RCS keywords in the text.
  11. # 09feb91 vixie@decwrl [written]
  12.  
  13. chop($cwd = `pwd`);
  14. foreach $d (@ARGV) {
  15.     chdir("$cwd/$d") || die "$cwd/$d: $!";
  16.     &mkrcs();
  17. }
  18. exit 0;
  19.  
  20. sub mkrcs {
  21.     local($has_rcs) = 0;
  22.     local(@f) = ();
  23.     local(*d, *f);
  24.     local($k);
  25.  
  26.     print "RCS'ing in ".`pwd`;
  27.     opendir(d, '.') || die "opendir: $!";
  28.     while ($f = readdir(d)) {
  29.         next if ($f =~ /^\./);        # begins with .
  30.         next if (-l $f);        # is a symlink
  31.         if (-f $f) {            # is a plain file
  32.             push(@f, $f);
  33.             next;
  34.         }
  35.         next if (! -d $f);        # isn't a dir
  36.         if ($f eq 'RCS') {        # name is RCS
  37.             $has_rcs++;
  38.             next;
  39.         }
  40.         chdir($f) || die "$f: $!";
  41.         &mkrcs();
  42.         chdir('..') || die "..: $!";
  43.     }
  44.     if (! $has_rcs) {
  45.         mkdir("RCS", 0777) || die "mkdir RCS: $!";
  46.     }
  47.     while ($f = pop(@f)) {
  48.         open(f, "<$f") || die "$f: $!";
  49.         next unless (-T f);            # text file
  50.         next if (-f "$f,v" || -f "RCS/$f,v");    # already in RCS
  51.         $k = '';
  52.         while (<f>) {
  53.             if (/\$(Header|Version):/) {
  54.                 $k = '-k ';
  55.                 last;
  56.             }
  57.         }
  58.         $_ = "ci -u $k -t/dev/null -morig $f";
  59.         print "$_\n";
  60.         system $_;
  61.     } continue {
  62.         close(f);
  63.     }
  64. }
  65.  
  66. --
  67. Paul Vixie
  68. DEC Western Research Lab    <vixie@wrl.dec.com>
  69. Palo Alto, California        ...!decwrl!vixie
  70.