]> git.pond.sub.org Git - empserver/blob - src/scripts/ls-sources.pl
Update copyright notice
[empserver] / src / scripts / ls-sources.pl
1 #!/usr/bin/perl
2 #
3 #   Empire - A multi-player, client/server Internet based war game.
4 #   Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
5 #                 Ken Stevens, Steve McClure, Markus Armbruster
6 #
7 #   Empire 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 3 of the License, or
10 #   (at your option) any later version.
11 #
12 #   This program is distributed in the hope that it will be useful,
13 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #   GNU General Public License for more details.
16 #
17 #   You should have received a copy of the GNU General Public License
18 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 #   ---
21 #
22 #   See files README, COPYING and CREDITS in the root of the source
23 #   tree for related information and legal notices.  It is expected
24 #   that future projects/authors will amend these files as needed.
25 #
26 #   ---
27 #
28 #   ls-sources.pl: List source files
29 #
30 #   Known contributors to this file:
31 #      Markus Armbruster, 2015-2016
32 #
33 # Usage: ls-sources.pl DIR REGEX
34 #
35 # List source files in DIR with names matching REGEX.  If DIR is under
36 # version control, list version-controlled files.  Else, list files in
37 # sources.mk.
38
39 use warnings;
40 use strict;
41
42 if ($#ARGV != 1) {
43     print STDERR "Usage: $0 DIR REGEX\n";
44     exit 1;
45 }
46
47 my $dir = $ARGV[0];
48 my $regex = $ARGV[1];
49
50 my $srcdir = $dir;
51 my $subdir = "";
52
53 while (! -d "$srcdir/.git" and ! -r "$srcdir/sources.mk"
54        and $srcdir =~ m,^((.*)/)?([^/]*),) {
55     $srcdir = $2 || ".";
56     $subdir = "$3/$subdir";
57 }
58
59 my @sources;
60 if (-d "$srcdir/.git") {
61     open IN, "cd '$srcdir' && git ls-files '$subdir' | uniq |"
62         or die "can't run git ls-files: $!";
63     while (<IN>) {
64         chomp;
65         push @sources, $_;
66     }
67     close IN;
68 } elsif (-r "$srcdir/sources.mk") {
69     open IN, "<$srcdir/sources.mk"
70         or die "can't open $srcdir/sources.mk: $!";
71     $_ = <IN>;
72     s/.*=//;
73     @sources = grep m,^\Q$subdir\E,, split;
74     close IN;
75 } else {
76     print STDERR "Can't find source tree\n";
77     exit 1;
78 }
79
80 for (grep m/$regex/, @sources) {
81     print "$srcdir/$_\n";
82 }