Avoid potential negative array index access to cached text.
[LibreOffice.git] / solenv / clang-format / reformat-formatted-files
bloba3a670f83a7711afb552db771adb305a0c246cd3
1 #!/usr/bin/env perl
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # Reformat files which are not excluded. This is interesting if the
9 # clang-format version or config changes.
10 # -n allows just listing the formatted files.
12 use strict;
13 use warnings;
14 use lib "solenv/clang-format";
15 use ClangFormat;
17 my $clang_format = ClangFormat::find();
18 my $src = ClangFormat::get_extension_regex();
19 my $excluded_list_names = ClangFormat::get_excludelist();
20 my @filenames = ();
21 my $dry_run = 0;
23 # Get a list of files.
24 open (FILES, "git ls-files |") || die "Cannot run git ls-files.";
25 while (my $filename = <FILES>)
27 chomp $filename;
28 if ($filename =~ /\.($src)$/ and !exists($excluded_list_names->{$filename}))
30 push @filenames, $filename;
34 if ($#ARGV ge 0 && $ARGV[0] eq "-n")
36 $dry_run = 1;
39 foreach my $filename (@filenames)
41 my $command = $clang_format . " -i " . $filename;
42 print($filename . "\n");
43 if (!$dry_run)
45 system($command) == 0 or die "failed to execute \"$command\": $?";
49 # vim: set shiftwidth=4 softtabstop=4 expandtab: