利用shell和awk筛选出所有函数定义和声明的地方,并记录文件名和行号
来源:互联网 发布:堡垒之夜 知乎 编辑:程序博客网 时间:2024/06/03 18:56
Shell script
PROJECT_DIR=~/Documents/Computer_science/Source_code/C/openssh-2.2.0p1/
SOURCE_FILE_LIST=~/Documents/Computer_science/Source_code/Bash/AWK/file_listOUTPUT_FILENAME=/home/Ken/Documents/Computer_science/Source_code/Bash/AWK/output.out
echo -n '' > ${OUTPUT_FILENAME}
if [[ ! -e ${SOURCE_FILE_LIST} ]]
then
echo "CREATING source file list"
find ${PROJECT_DIR} -name '*.[c, h]' > ${SOURCE_FILE_LIST}
fi
while read file_name
do
if [[ ${file_name} =~ ^[[:space:]]*return || ${file_name} =~ ^[[:space:]]*else[[:space:]]+if ]]
then
continue
fi
awk -f const.awk -v OUTPUT_FILE=${OUTPUT_FILENAME} ${file_name}
done < ${SOURCE_FILE_LIST}
~
~
awk script
BEGIN \
{
OFS=":"
}
#patter1:
#in the following line, `\)?' is added only because gawk will complain, if without it
/^\s*extern.*\s+\w+\s*\(\)?.*/ || /^\s*\w+\s+\w+\s*\(\)?/ \
{
if ($1 != "return" && $1 != "typedef" && $1 != "else")
#exclude 'return func_name()', 'typedef void func_ptr()' and 'else if func_name()'
print $0, FILENAME, FNR >> OUTPUT_FILE
}
#patter2:
#for the sake of this type of declaration:
# unsigned int
# hello(int a);
/^(\s*\w+)+$/ \
{
if (index($1, "#") == 0 && $0 !~ /^\s*\/\// && index($0, "*/") == 0 && $1 !~ /\<(if|else|struct|typedef|while|do|\{|\}|return)\>/)
# first one protects against preprocessing directives, second and the third against comments, the last one against some keywords
{
getline
if ($0 ~ /^\s*\w+\s*\(\)?/)
print $0, FILENAME, FNR >> OUTPUT_FILE
}
}
- 利用shell和awk筛选出所有函数定义和声明的地方,并记录文件名和行号
- 打印出当前文件的文件名和当前行号
- 函数的声明和定义
- 函数的声明和定义
- 函数的声明和定义
- 函数的声明和定义
- 函数的声明和定义
- 函数的声明和定义
- 函数声明和定义
- 变量和函数的定义和声明
- 显示当前行号、文件名和函数名
- C++显示调用函数和行号文件名
- C++的声明和定义的出别
- 全局函数的声明和定义
- 内联函数的声明和定义
- 内联函数的声明和定义位置
- 变量,函数的定义和声明
- c_函数的声明和定义
- 菜鸟课堂:简介Java多线程开发中的数据同步
- POJ Ubiquitous Religions
- HDU 5187-zhx's contest(快速乘法+快速幂取模)
- 创建AVD时,OK按钮无法点亮
- 基于GPU的优化处理
- 利用shell和awk筛选出所有函数定义和声明的地方,并记录文件名和行号
- 递归问题之汉诺塔
- java开发相关
- .Net操作Office总结一 - 使用VS2010自带的Office模板进行开发
- P051第一题
- Inside Geometry Instancing(上)
- Lucky Sequence(hash应用)
- hihocoder:
- hihocoder:二分查找