#!/usr/bin/env perl
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Reformat files which are not excluded. This is interesting if the
# clang-format version or config changes.
# -n allows just listing the formatted files.

use strict;
use warnings;
use lib "solenv/clang-format";
use ClangFormat;

my $clang_format = ClangFormat::find() . ' -i ';
my $re_ext = '\.('. ClangFormat::get_extension_regex() .')$';
my $excluded_list_names = ClangFormat::get_excludelist();

my $dry_run = $ARGV[0] eq '-n';

# Get a list of files.
open (FILES, 'git ls-files |') or  die 'Cannot run git ls-files.';

my @filenames = grep { chomp $_;  /$re_ext/ and !exists($excluded_list_names->{$_}) } <FILES>;

foreach my $filename (@filenames)
{
    print($filename, "\n");
    if (!$dry_run)
    {
        system($clang_format . $filename) == 0 or die qq(failed to execute "$clang_format $filename": $?);
    }
}

# vim: set shiftwidth=4 softtabstop=4 expandtab:
