]>
Commit | Line | Data |
---|---|---|
2a06115d FC |
1 | #!/usr/bin/perl |
2 | # | |
f70aedc4 | 3 | ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
2a06115d FC |
4 | ## |
5 | ## Squid software is distributed under GPLv2+ license and includes | |
6 | ## contributions from numerous individuals and organizations. | |
7 | ## Please see the COPYING and CONTRIBUTORS files for details. | |
8 | ## | |
9 | ||
10 | use strict; | |
11 | use warnings; | |
12 | ||
13 | my $current_source_section=''; | |
14 | while (<>) { | |
15 | chomp; | |
16 | if (m!^#!) { | |
17 | print "$_\n"; | |
18 | next; | |
19 | } | |
20 | # accumulate files and prep for sorting | |
21 | my %files = (); | |
22 | if (/^(\S+_SOURCES)\s*(\+?=)\s*(.*[^\\])$/ ) { | |
23 | my @parts = split(/\s+/, $3); | |
24 | if ($#parts == 0) { # one file only specified on same line as SOURCES | |
25 | print "$1 $2 $3\n"; | |
26 | next; | |
27 | } | |
28 | foreach my $file (@parts) { | |
29 | &addfile(\%files, $file, $1); | |
30 | } | |
31 | print "$1 $2 \\\n"; | |
32 | &print_files(\%files); | |
33 | next; | |
34 | } | |
35 | if (/^(\S+_SOURCES)\s*(\+?=)\s*(.*?)\s*\\$/) { | |
36 | $current_source_section=$1; | |
37 | print "$1 $2 \\\n"; | |
38 | if (defined $3) { | |
39 | foreach my $file (split(/\s+/, $3)) { | |
40 | &addfile(\%files, $file, $current_source_section); | |
41 | } | |
42 | } | |
43 | } else { | |
44 | print "$_\n"; | |
45 | next; | |
46 | } | |
47 | while (<>) { | |
48 | chomp; | |
49 | m!^\s+(.*?)\s*\\?$!; | |
50 | foreach my $file (split(/\s+/, $1)) { | |
51 | &addfile(\%files, $file, $current_source_section) if (length $file); | |
52 | } | |
53 | if (! /\\$/ ) { # last line in the list | |
54 | &print_files(\%files); | |
55 | last; | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | exit 0; | |
61 | ||
62 | # arg: ref to hash to add the file to, filename | |
63 | sub addfile | |
64 | { | |
65 | my $files = shift @_; | |
66 | my $fn = shift @_; | |
67 | my $current_source_section = shift @_; | |
68 | ||
69 | $fn =~ m!\s*(tests/stub_|tests/test)?(\S+)(\s+\\\s*)?$! || die "no parse"; | |
70 | my $prefix = (defined $1) ? $1 : ''; | |
71 | my $filename = (defined $2) ? $2 : ''; | |
72 | ||
73 | print STDERR "WARNING: duplicate $prefix$filename ". | |
74 | "detected in $current_source_section\n" | |
75 | if exists($files->{"$filename.$prefix"}); | |
76 | ||
77 | $files->{"$filename.$prefix"}="$prefix$filename"; | |
78 | } | |
79 | ||
80 | # arg is hash ref, print values in order of key | |
81 | sub print_files | |
82 | { | |
83 | my %files=%{$_[0]}; | |
84 | my @q=(); | |
85 | foreach my $k (sort keys %files) { | |
86 | push @q, "\t".$files{$k}; | |
87 | } | |
88 | print join(" \\\n", @q)."\n"; | |
89 | } |