<commit_before>#! /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/.
#

# Usage: update_pch.sh [precompiled_xxx.hxx]

root=`dirname $0`
root=`cd $root/../.. && pwd`

if test -z "$1"; then
    headers=`ls $root/*/inc/pch/precompiled_*.hxx`
else
    headers="$1"
fi

for x in $headers; do
    header=$x
    echo updating `echo $header | sed -e s%$root/%%`
    module=`readlink -f $header | sed -e s%$root/%% -e s%/.*%%`
    name=`echo $header | sed -e s/.*precompiled_// -e s/\.hxx//`
    makefile="Library_$name.mk"

    tmpfile=`mktemp`

    cat "$root/$module/$makefile" | sed 's#\\$##' | \
        (
        inobjects=
        ifstack=0
        while read line ; do
            if test "$line" = "))" ; then
                inobjects=
            elif echo $line | grep -q -e add_exception_objects -e add_noexception_objects -e add_cxxobject -e add_cxxobjects ; then
                inobjects=1
                if test $ifstack -ne 0 ; then
                    echo Sources in a conditional, ignoring for now. >&2
                fi
            elif echo $line | grep -q ^if ; then
                ifstack=$((ifstack + 1))
            elif echo $line | grep -q ^endif ; then
                ifstack=$((ifstack - 1))
            elif test -n "$inobjects" -a $ifstack -eq 0; then
                file=$line
                if echo $line | grep -q ", "; then
                    true # $if() probably, or something similar
                elif ! test -f "$root/$file".cxx ; then
                    echo No file $file in $module/$makefile >&2
                else

function list_file_includes()
(
    ifdepth=0
    # filter out only preprocessor lines, get the first and second "words" after the #,
    # also replace " with @ (would cause trouble when doing echo of the line)
    cat "$1" | grep '^\s*#' | sed 's/^\s*#/#/' | sed 's/^\(#\w*\s+\w*\)\s+.*/\1/' | sed 's/"/@/g' | \
        while read line; do
            # skip everything surrounded by any #if
            if echo "$line" | grep -q "#if" ; then
                ifdepth=$((ifdepth + 1))
                lastif="$line"
            elif echo "$line" | grep -q "#endif" ; then
                ifdepth=$((ifdepth - 1))
                lastif="#if"
            elif echo "$line" | grep -q "#include"; then
                if test $ifdepth -eq 0; then
                    echo $line | sed 's/@/"/g'
                else
                    echo "#include in $lastif : $line" | sed 's/@/"/g' >&2
                fi
            fi
        done
)

                    list_file_includes "$root/$file".cxx | sed 's/\(#include [<@][^>@]*[>@]\).*/\1/' | sed 's#\.\./##g#' >>$tmpfile
                fi
            fi
        done
        )

    cat >$header <<EOF
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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/.
 */

EOF

    # Library_svx needs this (sendreportw32.cxx)
    if test "$makefile" = Library_svx.mk ; then
        cat >>$header <<EOF
#ifdef WNT
#define UNICODE
#define _UNICODE
#endif

EOF
    fi
<commit_msg>mention that temporary edits in autogenerated pch headers are ok<commit_after>#! /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/.
#

# Usage: update_pch.sh [precompiled_xxx.hxx]

root=`dirname $0`
root=`cd $root/../.. && pwd`

if test -z "$1"; then
    headers=`ls $root/*/inc/pch/precompiled_*.hxx`
else
    headers="$1"
fi

for x in $headers; do
    header=$x
    echo updating `echo $header | sed -e s%$root/%%`
    module=`readlink -f $header | sed -e s%$root/%% -e s%/.*%%`
    name=`echo $header | sed -e s/.*precompiled_// -e s/\.hxx//`
    makefile="Library_$name.mk"

    tmpfile=`mktemp`

    cat "$root/$module/$makefile" | sed 's#\\$##' | \
        (
        inobjects=
        ifstack=0
        while read line ; do
            if test "$line" = "))" ; then
                inobjects=
            elif echo $line | grep -q -e add_exception_objects -e add_noexception_objects -e add_cxxobject -e add_cxxobjects ; then
                inobjects=1
                if test $ifstack -ne 0 ; then
                    echo Sources in a conditional, ignoring for now. >&2
                fi
            elif echo $line | grep -q ^if ; then
                ifstack=$((ifstack + 1))
            elif echo $line | grep -q ^endif ; then
                ifstack=$((ifstack - 1))
            elif test -n "$inobjects" -a $ifstack -eq 0; then
                file=$line
                if echo $line | grep -q ", "; then
                    true # $if() probably, or something similar
                elif ! test -f "$root/$file".cxx ; then
                    echo No file $file in $module/$makefile >&2
                else

function list_file_includes()
(
    ifdepth=0
    # filter out only preprocessor lines, get the first and second "words" after the #,
    # also replace " with @ (would cause trouble when doing echo of the line)
    cat "$1" | grep '^\s*#' | sed 's/^\s*#/#/' | sed 's/^\(#\w*\s+\w*\)\s+.*/\1/' | sed 's/"/@/g' | \
        while read line; do
            # skip everything surrounded by any #if
            if echo "$line" | grep -q "#if" ; then
                ifdepth=$((ifdepth + 1))
                lastif="$line"
            elif echo "$line" | grep -q "#endif" ; then
                ifdepth=$((ifdepth - 1))
                lastif="#if"
            elif echo "$line" | grep -q "#include"; then
                if test $ifdepth -eq 0; then
                    echo $line | sed 's/@/"/g'
                else
                    echo "#include in $lastif : $line" | sed 's/@/"/g' >&2
                fi
            fi
        done
)

                    list_file_includes "$root/$file".cxx | sed 's/\(#include [<@][^>@]*[>@]\).*/\1/' | sed 's#\.\./##g#' >>$tmpfile
                fi
            fi
        done
        )

    cat >$header <<EOF
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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/.
 */

/*
 This file has been autogenerated by update_pch.sh . It is possible to edit it
 manually (such as when an include file has been moved/renamed/removed. All such
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).
*/

EOF

    # Library_svx needs this (sendreportw32.cxx)
    if test "$makefile" = Library_svx.mk ; then
        cat >>$header <<EOF
#ifdef WNT
#define UNICODE
#define _UNICODE
#endif

EOF
    fi

{'fraction_non_alphanumeric': 0.14131474648079814, 'fraction_numerical': 0.008473418067514008, 'mean_word_length': 1.7521624670928921, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040746', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2268, 'n_words': 807}