Applied Ashley Willis's perlbarry package.
[barry/pauldeden.git] / contrib / perlbarry / misc / reipd
blob230f4a6b911456d3bc34ec0afcaf4e671b66f771
1 #!/usr/bin/perl
3 # reipd version 0.1
5 # Copyright (C) 2008, ashley willis <barry@venamous.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.
16 # See the GNU General Public License in the COPYING file at the
17 # root directory of this project for more details.
19 # reconstructs an .ipd file to <BASENAME>.ipd2. Argument to reipd is the
20 # directory containing the .deipd files, or the <BASENAME>.info file. No
21 # argument needed if in the directory containing these files. This will
22 # recreate the original .ipd file byte-for-byte if the data was unchanged.
23 # Alternatively, .deipd files can be given on the command line, with output
24 # to "new.ipd2".
26 use Cwd;
28 if (@ARGV) {
29 if (($count == 1) and !($ARGV[0] =~ /\.deipd2?$/) ) {
30 $arg = $ARGV[0];
31 if ($arg =~ /\.info$/) {
32 open(DBNAMES,"$arg") || die;
33 $basename = $arg;
34 $basename =~ s/\.info$//;
35 $basename =~ s/^(.*)\///g;
36 $dir = $1;
38 else {
39 $arg =~ s/\/$//;
40 $basename = $arg;
41 $basename =~ s/^(.*)\///g;
42 open(DBNAMES,"$arg/$basename.info") || die;
43 $dir = $arg;
45 ($dir) or $dir = ".";
46 print STDERR "dir=\"$dir\"\n";
47 print STDERR "base=\"$basename\"\n";
48 while(<DBNAMES>) {
49 chomp $_;
50 (/^$/) or $dbname[$i++] = $_;
54 else {
55 $dir = ".";
56 $basename = "new";
57 foreach (@ARGV) {
58 s/\.deipd2?$// || die;
59 $dbname[$i++] = $_;
64 else {
66 $dir = cwd();
67 #chomp $dir;
68 $basename = $dir;
69 $basename =~ s/^(.*)\///g;
70 print STDERR "dir=\"$dir\"\n";
71 print STDERR "base=\"$basename\"\n";
73 open(DBNAMES,"$basename.info") || die "$basename.info not found!\n";
74 while(<DBNAMES>) {
75 chomp $_;
76 (/^$/) or $dbname[$i++] = $_;
80 $numOfDB = @dbname;
81 $numOfDBBIN = reverse(dec2Bin($numOfDB,2));
83 open(OUT, ">$basename.ipd2") || die;
84 print OUT "Inter\@ctive Pager Backup/Restore File\n\x02" . $numOfDBBIN . "