From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/zstd/contrib/linux-kernel/kernelize.sh | 110 +++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 src/zstd/contrib/linux-kernel/kernelize.sh (limited to 'src/zstd/contrib/linux-kernel/kernelize.sh') diff --git a/src/zstd/contrib/linux-kernel/kernelize.sh b/src/zstd/contrib/linux-kernel/kernelize.sh new file mode 100755 index 000000000..21aa2ecdc --- /dev/null +++ b/src/zstd/contrib/linux-kernel/kernelize.sh @@ -0,0 +1,110 @@ +#!/bin/sh +set -e + +# Constants +SED_COMMANDS="commands.tmp" +CLANG_FORMAT="clang-format-3.9" +INCLUDE='include/linux/' +LIB='lib/zstd/' +SPACES=' ' +TAB=$'\t' +TMP="replacements.tmp" + +function prompt() { + while true; do + read -p "$1 [Y/n]" yn + case $yn in + '' ) yes='yes'; break;; + [Yy]* ) yes='yes'; break;; + [Nn]* ) yes=''; break;; + * ) echo "Please answer yes or no.";; + esac +done +} + +function check_not_present() { + grep "$1" $INCLUDE*.h ${LIB}*.{h,c} && exit 1 || true +} + +function check_not_present_in_file() { + grep "$1" "$2" && exit 1 || true +} + +function check_present_in_file() { + grep "$1" "$2" > /dev/null 2> /dev/null || exit 1 +} + +echo "Files: " $INCLUDE*.h $LIB*.{h,c} + +prompt "Do you wish to replace 4 spaces with a tab?" +if [ ! -z "$yes" ] +then + # Check files for existing tabs + grep "$TAB" $INCLUDE*.h $LIB*.{h,c} && exit 1 || true + # Replace the first tab on every line + sed -i '' "s/^$SPACES/$TAB/" $INCLUDE*.h $LIB*.{h,c} + + # Execute once and then execute as long as replacements are happening + more_work="yes" + while [ ! -z "$more_work" ] + do + rm -f $TMP + # Replaces $SPACES that directly follow a $TAB with a $TAB. + # $TMP will be non-empty if any replacements took place. + sed -i '' "s/$TAB$SPACES/$TAB$TAB/w $TMP" $INCLUDE*.h $LIB*.{h,c} + more_work=$(cat "$TMP") + done + rm -f $TMP +fi + +prompt "Do you wish to replace '{ ' with a tab?" +if [ ! -z "$yes" ] +then + sed -i '' "s/$TAB{ /$TAB{$TAB/g" $INCLUDE*.h $LIB*.{h,c} +fi + +rm -f $SED_COMMANDS +cat > $SED_COMMANDS <