Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/scripts/t8spell_check_and_indent.sh
901 views
1
#! /bin/bash
2
3
# This file is part of t8code.
4
# t8code is a C library to manage a collection (a forest) of multiple
5
# connected adaptive space-trees of general element classes in parallel.
6
#
7
# Copyright (C) 2023 the developers
8
#
9
# t8code is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
13
#
14
# t8code is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with t8code; if not, write to the Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
TYPOS=`which typos 2> /dev/null`
24
if [ -z "$TYPOS" ]
25
then
26
echo "ERROR: typos not found."
27
echo "Please install typos."
28
echo "See https://github.com/crate-ci/typos#install"
29
exit 1
30
fi
31
32
repo_main_dir=`git rev-parse --show-toplevel`
33
(cd $repo_main_dir && typos)
34
35
echo "This script will correct all previously listed typos."
36
echo
37
read -p "Are you sure? ('Y' or 'y' to continue) " -n 1 -r
38
echo
39
if [[ $REPLY =~ ^[Yy]$ ]]
40
then
41
echo Correcting all typos...
42
(cd $repo_main_dir && typos -w)
43
echo done.
44
45
echo
46
echo "Changed files according to git diff:"
47
changed_files=``
48
for file in `(cd $repo_main_dir && git diff --name-only)`
49
do
50
# only check existing files, this is necessary since if we rename or delete
51
# a file it is added to the committed files and we thus would try to indent a
52
# nonexisting file.
53
if [ ! -e $repo_main_dir/$file ]
54
then
55
continue
56
fi
57
# We only indent .c, .cxx, .h and .hxx files
58
#-a ${file: -2} != ".h" ]
59
FILE_ENDING="${file##*.}"
60
if [ $FILE_ENDING = "c" -o $FILE_ENDING = "h" -o $FILE_ENDING = "cxx" -o $FILE_ENDING = "hxx" ]
61
then
62
echo $file
63
changed_files="$changed_files $file"
64
fi
65
done
66
echo
67
echo "Should also all changed (according to git diff) files be indented?"
68
read -p "('Y' or 'y' to continue) " -n 1 -r
69
echo
70
if [[ $REPLY =~ ^[Yy]$ ]]
71
then
72
echo Indenting all files...
73
(cd $repo_main_dir && ./scripts/t8indent.sh $changed_files)
74
echo done.
75
else
76
echo Aborted.
77
fi
78
else
79
echo Aborted.
80
fi
81
82