-#!/usr/bin/env bash
+#!/bin/sh
-if (($# != 1)); then
+if [ $# -ne 1 ]; then
>&2 echo "Usage: $0 <identifier>";
exit 1;
fi;
-function grepc_find_files()
+grepc_find_files()
{
files="$(mktemp -t 'grepc.XXXXXX')";
}
-function grepc_helper()
+grepc_helper()
{
xargs grep -lPI "$1" <"$files" \
| xargs grep -lP "$2" \
}
-function grepc_macro_simple()
+grepc_macro_simple()
{
grepc_helper \
"#\s*define\s+$1\b[^(]" \
}
-function grepc_macro_func()
+grepc_macro_func()
{
grepc_helper \
"#\s*define\s+$1\(" \
}
-function grepc_macro()
+grepc_macro()
{
grepc_macro_simple "$1";
grepc_macro_func "$1";
}
-function grepc_enum_constant()
+grepc_enum_constant()
{
grepc_helper \
'^enum\s' \
}
-function grepc_func_decl()
+grepc_func_decl()
{
grepc_helper \
"\b$1\s*\(" \
}
-function grepc_func_def()
+grepc_func_def()
{
grepc_helper \
"\b$1\s*\(" \
}
-function grepc_func()
+grepc_func()
{
grepc_func_decl "$1";
grepc_func_def "$1";
}
-function grepc_linux_syscall_decl()
+grepc_linux_syscall_decl()
{
grepc_helper \
"^asmlinkage\s+[\w\s]+\**sys_$1\s*\(" \
}
-function grepc_linux_syscall_def()
+grepc_linux_syscall_def()
{
grepc_helper \
"SYSCALL_DEFINE.\($1\b" \
}
-function grepc_linux()
+grepc_linux()
{
grepc_linux_syscall_decl "$1";
grepc_linux_syscall_def "$1";
}
-function grepc_glibc_math()
+grepc_glibc_math()
{
grepc_func_def "M_DECL_FUNC \(__$1\)";
}
-function grepc_glibc()
+grepc_glibc()
{
grepc_glibc_math "$1";
}
-function grepc_type_struct_union_enum()
+grepc_type_struct_union_enum()
{
grepc_helper \
"\b(struct|union|enum)\s+$1\b" \
}
-function grepc_type_typedef_simple()
+grepc_type_typedef_simple()
{
grepc_helper \
'^[ \t]*typedef\s' \
}
-function grepc_type_typedef_struct_union_enum()
+grepc_type_typedef_struct_union_enum()
{
grepc_helper \
'^[ \t]*typedef\s+(struct|union|enum)\b[^;]*$' \
}
-function grepc_type_typedef_underlying_struct_union_enum()
+grepc_type_typedef_underlying_struct_union_enum()
{
xargs grep -hP "^\s*typedef\s+(struct|union|enum)\s+.*\b$1;" <"$files" \
| sed -E -e 's/^\s*typedef\s+//' -e "s/\s*\**\b$1;.*//" \
}
-function grepc_type_typedef()
+grepc_type_typedef()
{
grepc_type_typedef_simple "$1";
grepc_type_typedef_struct_union_enum "$1";
}
-function grepc_type()
+grepc_type()
{
grepc_type_struct_union_enum "$1";
grepc_type_typedef "$1";
}
-function main()
+main()
{
grepc_find_files "$1";