Files
kunlun/tools/add_cpp_def.sh

47 lines
1.5 KiB
Bash
Raw Normal View History

2024-09-28 14:37:24 +08:00
#!/bin/sh
echo "add _cplusplus tools"
_cpp_head="\n#ifdef __cplusplus\nextern \"C\" {\n#endif"
_cpp_tail="\n#ifdef __cplusplus\n}\n#endif\n"
FILES=`find ./ -name "*.h" | grep -v "dtest" | grep -v "rom" | \
grep -v "inc/hw/reg/" | grep -v "mfgtool" | grep -v "dbglogparser_tool" | \
grep -v "import" | grep -v "deprecated_definitions.h" |
grep -v "iot_config.h" | grep -v "encoding.h"`
for file in ${FILES}
do
file_name=${file##*/}
# if define _cplusplus
is_cpp=`grep "_cplusplus" $file -r`
if [ "$is_cpp" != "" ]; then
echo "[INFO]"$file" is defined by _cplusplus"
continue
fi
# get cpp header insert line number
head_line=`grep -n "#include" ./$file | tail -1 | cut -d ":" -f 1`
if [ "$head_line" == "" ]; then
head_line=`grep -n "#ifndef\ .*_H" ./$file | tail -1 | cut -d ":" -f 1`
if [ "$head_line" == "" ]; then
echo "[ERROR]"$file" is unexpected head format"
continue
fi
head_line=`expr $((head_line)) + 1`
fi
# insert _cplusplus head
sed -i "${head_line}a\\$_cpp_head" ./$file
# get cpp tail insert line number
tail_line=`grep -n "#endif" ./$file | tail -1 | cut -d ":" -f 1`
tail_line=`expr $((tail_line)) - 1`
if [ "$tail_line" == "" ]; then
echo "[ERROR]"$file" is unexpected tail format"
fi
echo "file: "$file",head: "$head_line", tail: "$tail_line
# insert _cplusplus tail
sed -i "${tail_line}a\\$_cpp_tail" ./$file
#echo $file
done