summaryrefslogtreecommitdiff
path: root/bin/fixincludeguards.sh
blob: 2655534aa41687d278533db976455a9a86768623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# 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/.

# corrects include guards for hxx/h files automatically by its path.

# Usage:
# a) fixincludeguards.sh header.hxx
# b) find . -name *.hxx -or -name *.h | xargs bash ./bin/fixincludeguards.sh

# TODO: This doesn't fix wrong #endif comments, like:
# #ifndef FOO_BAR_HXX
# #define FOO_BAR_HXX
# ...
# #endif // OTHER_BAR_HXX

# TODO: Make this portable. As it is now, it likely only works on Linux, or
# other platforms with a purely GNU toolset.

guard_prefix="INCLUDED_"

for fn in "$@"; do
    # remove leading ./, if invoked with find
    fn=`echo "$fn" | sed 's/^.\///g'`

    # global header in include/ top level dir:
    # drop the project dir
    fnfixed=`echo $fn | sed 's,include/,,g'`
    # add examples prefix to headers in odk/examples
    fnfixed=`echo $fnfixed | sed 's,odk/examples/\(cpp\|DevelopersGuide\|OLE\)/,examples_,g'`

    # convert file path to header guard
    guard=`echo "$fnfixed" | sed 's/[\/\.-]/_/g' | tr 'a-z' 'A-Z'`

    if [ aa"`git grep -h "^\s*#ifndef ${guard_prefix}$guard" "$fn" | wc -l`" != "aa1" ] ||
       [ aa"`git grep -h "^\s*#define ${guard_prefix}$guard" "$fn" | wc -l`" != "aa1" ]; then

        # pattern which identifies guards, common one look like
        # _MODULE_FILE_HXX, FILE_H, FILE_INC
        pattern=".*\(_HXX\|_H\|_INC\|_hxx\|_h\|_inc\)"

        ### extract guard definition
        # head to take only the first match
        old_guard=`git grep -h "#ifndef $pattern" "$fn" | head -n1 | sed "s/.*\s\($pattern.*\)/\1/"`

        if [ aa"$old_guard" == aa"" ]; then
            echo -e "$fn: \e[00;31mwarning:\e[00m guard not detectable"
            continue
        fi


        if [ aa"`git grep -w "$old_guard" | cut -d ':' -f1 | sort -u | wc -l `" != aa"1" ]; then
            echo -e "$fn: \e[00;31mwarning:\e[00m $old_guard guard definition used in other files"
            continue
        fi

        ### skip some special files...

        # skip this comphelper stuff:
        # INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14
        if [ aa"INCLUDED_COMPHELPER_IMPLBASE_" == aa"`echo $old_guard | sed "s/VAR_HXX_[0-9]\+//g"`" ]; then
            continue
        fi

        # skip files like xmloff/source/forms/elementimport_impl.hxx
        if [ aa"`git grep -h "#error.*directly" "$fn" | wc -l`" != "aa0" ]; then
            continue
        fi


        ### replace old guard with new scheme guard
        echo "$fn: $old_guard"

        # includes leading whitespace removal
        sed -i "s/\s*${old_guard}/ ${guard_prefix}${guard}/g" "$fn"


        ### clean up endif
        sed -i "s/#endif\s*\(\/\/\|\/\*\)\s*\#\?\(ifndef\)\?\s*!\?\s*\(${guard_prefix}${guard}\).*/#endif \/\/ \3/g" "$fn"

    fi
done
table but doesn't have a Library until now. Also, for the immediate use case it would have sufficed to only break DbgGetCaughtException, exceptionToString, TOOLS_WARN_EXCEPTION, TOOLS_WARN_EXCEPTION_IF, and TOOLS_INFO_EXCEPTION out of include/tools/diagnose_ex.h into an additional new include/comphelper/diagnose_ex.hxx, but its probably easier overall to just move the complete include file as is.) Change-Id: I9f3222d4ccf1a9ac29d7eb9ba1530d53e2affaee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138451 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> 2022-04-29use more string_view in INetURLObjectNoel Grandin Change-Id: I4462f7cf4740fa4d1b129d76a0775f4250f41bbd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133555 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2021-10-31Prepare for removal of non-const operator[] from Sequence in svtoolsMike Kaganski Change-Id: I614a97e5e2328c787ce19612a88839e234d54382 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124396 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> 2020-12-11Adapt the remaining OUString functions to std string_viewStephan Bergmann ...for LIBO_INTERNAL_ONLY. These had been missed by 1b43cceaea2084a0489db68cd0113508f34b6643 "Make many OUString functions take std::u16string_view parameters" because they did not match the multi-overload pattern that was addressed there, but they nevertheless benefit from being changed just as well (witness e.g. the various resulting changes from copy() to subView()). This showed a conversion from OStringChar to std::string_view to be missing (while the corresponding conversion form OUStringChar to std::u16string_view was already present). The improvement to loplugin:stringadd became necessary to fix > [CPT] compilerplugins/clang/test/stringadd.cxx > error: 'error' diagnostics expected but not seen: > File ~/lo/core/compilerplugins/clang/test/stringadd.cxx Line 43 (directive at ~/lo/core/compilerplugins/clang/test/stringadd.cxx:42): simplify by merging with the preceding assignment [loplugin:stringadd] > File ~/lo/core/compilerplugins/clang/test/stringadd.cxx Line 61 (directive at ~/lo/core/compilerplugins/clang/test/stringadd.cxx:60): simplify by merging with the preceding assignment [loplugin:stringadd] > 2 errors generated. Change-Id: Ie40de0616a66e60e289c1af0ca60aed6f9ecc279 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107602 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> 2020-12-01tdf#42949 Fix new IWYU warnings in directories s*Gabor Kelemen Except recently checked sc, sd, svx, sw Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: Ice1b86628e4f22a39f307b9c5fa567b6ab9d5acb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106917 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> 2020-05-21use for-range on Sequence in sfx2..swNoel Grandin Change-Id: I09806869f2fdbae61f4c5d5c9db6859202bb63b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94609 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2020-03-25Remove unused using declarations in oox...xmlsecurityGabor Kelemen Found by: run-clang-tidy-10 -checks=-*,misc-unused-using-decls Change-Id: I3e95791e223ef01e140a6217e29a9efae428a784 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90876 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> 2020-01-15tdf#88205 Adapt uses of css::uno::Sequence to use initializer_list ctorMesut Çifci Change-Id: Ib58c66590c60175d7984af55d23b7c55a6a2383e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86828 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> 2019-09-20drop newly unnecessary OGenericUnoDialog::DialogCaolán McNamara Change-Id: If047d08cea93fdfacff9ee00c69cf57ba08c916c Reviewed-on: https://gerrit.libreoffice.org/78972 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-09-20make WizardShell use RoadmapWizardMachineCaolán McNamara Change-Id: Id7e1e163f17cd4866c37bbd6cad73b8c721f4dae Reviewed-on: https://gerrit.libreoffice.org/78969 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-09-19tdf#42949 Fix IWYU warnings in svtools/Gabor Kelemen Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: Ifc70900022efcd089c0874bd46e0aacaef0efb72 Reviewed-on: https://gerrit.libreoffice.org/78767 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> 2019-07-31Improved loplugin:stringconstant (now that GCC 7 supports it): svtoolsStephan Bergmann Change-Id: I4d42441adf5408e0281577078b0d5537acb02513 Reviewed-on: https://gerrit.libreoffice.org/76641 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> 2019-07-15Simplify Sequence iterations in svtoolsArkadiy Illarionov Use range-based loops, STL and comphelper functions Change-Id: I4197b5083327998169a39389b968e1ff99f13339 Reviewed-on: https://gerrit.libreoffice.org/75440 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com> 2019-05-03Use hasElements to check Sequence emptiness in sfx2..svxArkadiy Illarionov Similar to clang-tidy readability-container-size-empty Change-Id: Icabd773f3b924d465b33e8581175f1fcf70c282e Reviewed-on: https://gerrit.libreoffice.org/71704 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2018-10-06make OGenericUnoDialog take an awt::XWindowCaolán McNamara Change-Id: I7c63397d0579306f4ade1947ce5bf9e1866bf876 Reviewed-on: https://gerrit.libreoffice.org/61469 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2018-06-05tdf#42949 remove unused compheler includes ..Jochen Nitschke and fix the fallout Change-Id: I15bc5d626f4d157cbc69a87392078b41e621d14e Reviewed-on: https://gerrit.libreoffice.org/54882 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> 2018-03-21support both vcl and weld in genericunodialog for interimCaolán McNamara Change-Id: Ife85dd7a4bd27260514b390ca3928152db0d688f Reviewed-on: https://gerrit.libreoffice.org/51699 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>