blob: 50b94dd66abce5518601d3d7b86b0f7e207054b8 (
plain) (
tree)
|
|
#!/bin/bash
if (($# != 1)); then
>&2 echo "Usage: $0 <identifier>";
exit 1;
fi;
function grepc_macro_simple()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "define\s+$1\b[^(]" \
| sort \
| xargs pcregrep -Mn "(?s)define\s+$1\b[^(].*?[^\\\\]$" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_macro_func()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "define\s+$1\(" \
| sort \
| xargs pcregrep -Mn "(?s)define\s+$1\(.*?[^\\\\]$" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_macro()
{
grepc_macro_simple "$1";
grepc_macro_func "$1";
}
function grepc_enum_constant()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\b$1\s*[,=]" \
| sort \
| xargs pcregrep -Mn \
"(?s)\benum\b\s*[\w\s[\]]*{[^}]*\b$1\s*[=,].*?^}.*?;" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_func_decl()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\b$1\s*\(" \
| sort \
| xargs pcregrep -Mn \
"(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_func_def()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\b$1\s*\(" \
| sort \
| xargs pcregrep -Mn \
"(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)\s*{.*?^}" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_func()
{
grepc_func_decl "$1";
grepc_func_def "$1";
}
function grepc_syscall_decl()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\bsys_$1\s*\(" \
| sort \
| xargs pcregrep -Mn \
"(?s)^asmlinkage\s+[\w\s]+\**sys_$1\s*\(.*?\)" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_syscall_def()
{
find . -type f \
| grep '\.c$' \
| xargs grep -lP "SYSCALL_DEFINE.\($1\b" \
| sort \
| xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\($1\b.*?^}" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_syscall()
{
grepc_syscall_decl "$1";
grepc_syscall_def "$1";
}
function grepc_type_struct_union_enum()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\b(struct|union|enum)\s+$1\b" \
| sort \
| xargs pcregrep -Mn \
"(?s)^([\w[][\w\s(,)[:\]*]+\s+)?\b(struct|union|enum)\s+$1\b\s*[\w\s[\]]*{.*?^}.*?;" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_type_typedef_simple()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "\b$1;" \
| sort \
| xargs pcregrep -Mn "(?s)^typedef\s+[^;]+$1;" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_type_typedef_struct_union_enum()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -lP "^}\s*$1;" \
| sort \
| xargs pcregrep -Mn "(?s)^typedef\s(?:(?!^}).)*^}\s*$1;" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
function grepc_type_typedef_underlying_struct_union_enum()
{
find . -type f \
| grep '\.[ch]$' \
| xargs grep -hP "^typedef\s+.*\b$1;" \
| sed -E -e 's/^typedef\s+//' -e "s/\s*\**\b$1;.*//" \
| sed -E -e 's/^struct\s+//' -e 's/^union\s+//' -e 's/^enum\s+//' \
| while read t; do
test "$1" != "$t" \
&& grepc_type_struct_union_enum "$t";
done;
}
function grepc_type_typedef()
{
grepc_type_typedef_simple "$1";
grepc_type_typedef_struct_union_enum "$1";
grepc_type_typedef_underlying_struct_union_enum "$1";
}
function grepc_type()
{
grepc_type_struct_union_enum "$1";
grepc_type_typedef "$1";
}
function main()
{
grepc_macro "$1";
grepc_enum_constant "$1";
grepc_func "$1";
grepc_syscall "$1";
grepc_type "$1";
}
main "$1";
|