smart-config.sh 486 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh --
  2. set -ue
  3. EXE="${1:?}"
  4. COMPONENTS="${2:?}"
  5. find_file() {
  6. found=0
  7. func="${1:?}"
  8. pattern="s/.*\(${func}\)\s*([^)]\+)\s*{.*/\1/p"
  9. for file in "${COMPONENTS}"/*.c; do
  10. [ -z "$(sed -zn "${pattern}" "${file}")" ] || {
  11. found=1
  12. echo "${file##*/}"
  13. break
  14. }
  15. done
  16. [ "${found}" -eq 1 ] || 1>&2 echo "${func} not found"
  17. }
  18. for func in $("${EXE}" | sort | uniq); do
  19. case "${func}" in
  20. file:*) echo "${func#file:}";;
  21. *) find_file "${func}";;
  22. esac
  23. done | sort | uniq