Skip to content

Instantly share code, notes, and snippets.

@cdlm
Last active September 10, 2020 09:39
Show Gist options
  • Save cdlm/10d5872f6a310586188bcb559743215e to your computer and use it in GitHub Desktop.
Save cdlm/10d5872f6a310586188bcb559743215e to your computer and use it in GitHub Desktop.
Resolve C includes and header files.
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function list-headers() {
local source="${1:--}"
cc -E -H "$source" 2>&1 1>/dev/null \
| sed '
# ignore recursive includes
/^\.\./d
# remove depth indication from 1st level includes
s/^\. \(.*\)/\1/
'
}
list-headers "$@"
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function find-include() {
local include="${1?Missing include name}"
echo "#include <${include}>" | headers -
}
find-include "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment