test-ly-files: Display symlink creation, add `-v` to `ln`
[sunny256-utils.git] / rcs-extract
blob3359826630c9fbee8a59becaaae0e598605ade0b
1 #!/usr/bin/env perl
3 #===============================================================
4 # rcs-extract
5 # File ID: 26d14f32-5d43-11df-8375-90e6ba3022ac
6 # Extracts the last checkin from RCS files.
7 # Reads file names of the ,v files from stdin and stores the
8 # extracted data under Extracted/ with the same file structure
9 # it’s found. Example:
10 # find -name '*,v' -type f | rcs-extract
12 # Character set: UTF-8
13 # License: GNU General Public License version 2 or later
14 # ©opyleft 2004 Øyvind A. Holm <sunny@sunbase.org>
15 #===============================================================
17 use strict;
18 use warnings;
19 use File::Path;
21 $| = 1;
23 my $Pref = ".Extracted/";
25 while (<>) {
26 chomp;
27 my $File = $_;
28 my $end_found = 0;
29 print("Opening $File...");
30 if (open(FromFP, "<$File")) {
31 binmode(FromFP);
32 my $Dir = "";
33 my $dest_dir = "$Pref";
34 if ($File =~ m/^(.*)\//) {
35 $Dir = $1;
36 $dest_dir = "$Pref$Dir";
37 D("[\$dest_dir = \"$dest_dir\"]");
38 # -d $dest_dir || mkpath($dest_dir, 1) || warn("$dest_dir: Couldn’t create path: $!\n");
40 mkpath($dest_dir, 1);
41 while (<>) {
42 last if /^text$/;
44 $Pref =~ s#//#/#g;
45 my $to_file = "$Pref$File";
46 $to_file =~ s/^(.*),v$/$1/;
47 if (-e $to_file) {
48 my $Rand = ".rand.$$." . substr(random(), 0, 5);
49 warn("$to_file: File already exists, adding random extension: $Rand");
50 $to_file .= $Rand;
52 if (open(ToFP, ">$to_file")) {
53 binmode(ToFP);
54 my $Line = "";
55 while (<FromFP>) {
56 if (s/([^@])(@)([^@])/$1$3/g) {
57 print(STDERR "[Found end]");
58 $end_found = 1;
60 s/@@/@/g;
61 $end_found && s/^\@$//;
62 print(ToFP $_);
63 $end_found && last;
65 close(ToFP);
66 close(FromFP);
67 } else {
68 warn("$to_file: Unable to open file for write: $!");
70 } else {
71 warn("$File: Unable to open file for read: $!\n");
75 sub D {
76 print(STDERR @_);
79 __END__
81 =pod
83 =head1 LICENCE
85 This program is free software; you can redistribute it and/or modify it
86 under the terms of the GNU General Public License as published by the
87 Free Software Foundation; either version 2 of the License, or (at your
88 option) any later version.
90 This program is distributed in the hope that it will be useful, but
91 WITHOUT ANY WARRANTY; without even the implied warranty of
92 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
93 See the GNU General Public License for more details.
95 You should have received a copy of the GNU General Public License along
96 with this program; if not, write to the Free Software Foundation, Inc.,
97 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
99 =cut
101 # vim: set fileencoding=UTF-8 filetype=perl foldmethod=marker foldlevel=0 :
102 # End of file rcs-extract