Add erlcode-find-calls-to-module
[khome.git] / home / bin / erlcode-find-calls-to-module
1 #! /bin/bash
2
3 target_module="$1"
4 shift
5 dirs=$@
6
7 find $dirs -type f -name '*.erl' -exec grep -Hn "\<$target_module\>:" '{}' \; \
8 | sed 's/%.*$//g' \
9 | awk -F "${target_module}:" -v target_module="$target_module" '
10 $1 && $2 {
11 caller_module_file = $1
12 sub(":.*$", "", caller_module_file)
13
14 called_function = $2
15 sub("\\(.*$", "", called_function)
16
17 if (called_function ~ /^[a-z][a-zA-Z_0-9]+$/) {
18 Calls[called_function]++
19 Calls_from[caller_module_file, called_function]++
20 Caller_modules[caller_module_file]++
21 } else {
22 printf \
23 "[WARN] skipped an invalid erlang function name. File: \"%s\", function: \"%s\", original line: \"%s\"\n", \
24 caller_module_file, called_function, $0 \
25 > "/dev/stderr"
26 }
27 }
28
29 END {
30 indent = " "
31 for (caller_module_file in Caller_modules) {
32 print caller_module_file;
33 for (cf in Calls_from) {
34 split(cf, call, SUBSEP);
35 if (call[1] == caller_module_file)
36 printf "%s%s\n", indent, call[2] | "sort";
37 }
38 close("sort")
39 }
40
41 print ""
42 printf "Inferred API of %s:\n", target_module
43 for (called_function in Calls)
44 printf "%s%s\n", indent, called_function | "sort"
45 close("sort")
46 }'
This page took 0.046086 seconds and 4 git commands to generate.