Debian Codegraph @

debian/convert-debian-gcc-diff

raw
1 #!/usr/bin/perl
2
3 use strict;
4
5 sub conv_file($$) {
6 my $d = shift;
7 my $f = shift;
8 open F, "$d/$f" or die "can't open $d/$f";
9 my $in_diff = 0;
10 my $res = "";
11 my @dp;
12 my ($line, $nextline);
13 while ($line = <F>) {
14 if ($line =~ /^#\s*DP:/) {
15 push @dp, $line;
16 next;
17 }
18 $line =~ s/^#//;
19 if ($line =~ /^---/) {
20 $nextline = <F>;
21 $nextline =~ s/^#//;
22 if ($nextline =~ /^\+\+\+\s*(\S+)/) {
23 my $name = $1;
24 while ($name && ! -e $name) {
25 $name =~ s/^[^\/]*\/?//;
26 }
27 if ($name) {
28 $line =~ s|^(---\s*)\S+(.*)$|$1a/$name$2|;
29 $res .= $line;
30 $nextline =~ s|^(\+\+\+\s*)\S+(.*)$|$1b/$name$2|;
31 $res .= $nextline;
32 $in_diff = 1;
33 next;
34 }
35 }
36 $in_diff = 0;
37 }
38 if (!($line =~ /^[-+@ ]/)) {
39 $in_diff = 0;
40 }
41 if ($in_diff) {
42 $res .= $line;
43 }
44 }
45 close F;
46
47 if ($res) {
48 $res = "# DP: This patch was converted from $f\n" .
49 "# DP: Original comment:\n" .
50 "# DP:\n" . join("", @dp) . "\n" . $res;
51 }
52
53 return $res;
54 }
55
56 my $dir = shift;
57 if (! -d $dir) {
58 die "$dir is not a directory";
59 }
60 my @patches;
61 if (! -d "debian/" || ! -e "debian/convert-debian-gcc-diff") {
62 die "Please run this script from top-level directory of gcc-*-doc-non-dfsg package.";
63 }
64 system("rm -f debian/patches/from-debian-gcc-*");
65 for my $file (@ARGV) {
66 my $converted = conv_file($dir, $file);
67 next if (!$converted);
68 my $converted_name = "from-debian-gcc-" . $file;
69 my $full_converted_name = "debian/patches/$converted_name";
70 open F, ">$full_converted_name" or die "failed to open $full_converted_name";
71 print F $converted;
72 close F;
73 push @patches, $converted_name;
74 }
75 open F, "debian/patches/series" or die "failed to open debian/patches/series";
76 while (<F>) {
77 chomp;
78 next if (/^from-debian-gcc-/);
79 push @patches, $_;
80 }
81 close F;
82 open F, ">debian/patches/series" or die "failed to open debian/patches/series";
83 print F $_ . "\n" for (@patches);
84 close F;