5 SED_COMMANDS
="commands.tmp"
6 CLANG_FORMAT
="clang-format-3.9"
7 INCLUDE
='include/linux/'
11 TMP
="replacements.tmp"
17 '' ) yes='yes'; break;;
18 [Yy
]* ) yes='yes'; break;;
19 [Nn
]* ) yes=''; break;;
20 * ) echo "Please answer yes or no.";;
25 function check_not_present
() {
26 grep "$1" $INCLUDE*.h
${LIB}*.
{h
,c
} && exit 1 || true
29 function check_not_present_in_file
() {
30 grep "$1" "$2" && exit 1 || true
33 function check_present_in_file
() {
34 grep "$1" "$2" > /dev
/null
2> /dev
/null ||
exit 1
37 echo "Files: " $INCLUDE*.h
$LIB*.
{h
,c
}
39 prompt
"Do you wish to replace 4 spaces with a tab?"
42 # Check files for existing tabs
43 grep "$TAB" $INCLUDE*.h
$LIB*.
{h
,c
} && exit 1 || true
44 # Replace the first tab on every line
45 sed -i '' "s/^$SPACES/$TAB/" $INCLUDE*.h
$LIB*.
{h
,c
}
47 # Execute once and then execute as long as replacements are happening
49 while [ ! -z "$more_work" ]
52 # Replaces $SPACES that directly follow a $TAB with a $TAB.
53 # $TMP will be non-empty if any replacements took place.
54 sed -i '' "s/$TAB$SPACES/$TAB$TAB/w $TMP" $INCLUDE*.h
$LIB*.
{h
,c
}
55 more_work
=$
(cat "$TMP")
60 prompt
"Do you wish to replace '{ ' with a tab?"
63 sed -i '' "s/$TAB{ /$TAB{$TAB/g" $INCLUDE*.h
$LIB*.
{h
,c
}
67 cat > $SED_COMMANDS <<EOF
69 s/MEM_STATIC/ZSTD_STATIC/g
70 s/MEM_check/ZSTD_check/g
71 s/MEM_32bits/ZSTD_32bits/g
72 s/MEM_64bits/ZSTD_64bits/g
73 s/MEM_LITTLE_ENDIAN/ZSTD_LITTLE_ENDIAN/g
74 s/MEM_isLittleEndian/ZSTD_isLittleEndian/g
75 s/MEM_read/ZSTD_read/g
76 s/MEM_write/ZSTD_write/g
79 prompt
"Do you wish to run these sed commands $(cat $SED_COMMANDS)?"
82 sed -i '' -f $SED_COMMANDS $LIB*.
{h
,c
}
86 prompt
"Do you wish to clang-format $LIB*.{h,c}?"
89 $CLANG_FORMAT -i ${LIB}*.
{h
,c
}
92 prompt
"Do you wish to run some checks?"
95 check_present_in_file ZSTD_STATIC_ASSERT
${LIB}zstd_internal.h
96 check_not_present_in_file STATIC_ASSERT
${LIB}mem.h
97 check_not_present_in_file
"#define ZSTD_STATIC_ASSERT" ${LIB}compress.c
98 check_not_present MEM_STATIC
99 check_not_present FSE_COMMONDEFS_ONLY
100 check_not_present
"#if 0"
101 check_not_present
"#if 1"
102 check_not_present _MSC_VER
103 check_not_present __cplusplus
104 check_not_present __STDC_VERSION__
105 check_not_present __VMS
106 check_not_present __GNUC__
107 check_not_present __INTEL_COMPILER
108 check_not_present FORCE_MEMORY_ACCESS
109 check_not_present STATIC_LINKING_ONLY