Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function search-includes()
- {
- IFS=$'\n'
- SEARCH="$1"
- if test -n "$2";
- then
- if test "$2" == "DEBUG"
- then
- DEBUG="TRUE"
- else
- SEARCHED="$2";
- fi
- fi
- if test -n "$3";
- then
- TABS="$3"
- fi
- if test -n "$4";
- then
- DEBUG="TRUE"
- fi
- if test $DEBUG == "TRUE";
- then
- echo -e $TABS"Searching file $SEARCH for includes"
- fi
- if test -n "$SEARCH";
- then
- grep -iE "#[ ]{0,}include" "$SEARCH"
- BASESEARCH=`basename $SEARCH`;
- for d in `grep -iE "#[ ]{0,}include" "$SEARCH" | \
- grep -v "$BASESEARCH" | \
- grep -Po "(\<|\"){1}.*\.h(\>|\"){1}" | \
- cut -c2- | rev | cut -c2- | rev | \
- sort | uniq`;
- do
- LOCATION=`slocate $d | grep "^\/usr\/include\/" | head -n1`;
- if test $DEBUG == "TRUE";
- then
- echo -e $TABS"Search file $LOCATION for error codes";
- fi
- grep -Pi "^#[]{0,}define( |\t){1,}E{1}[A-Za-z0-9]*[0-9]{1,3}" "$LOCATION";
- if test $DEBUG == "TRUE";
- then
- echo -e $TABS"Testing if $LOCATION has previously been searched, previous searches were $SEARCHED";
- fi
- if test -z $SEARCHED || test -n `echo "$LOCATION" | grep -viE "($(exec echo $SEARCHED))"`;
- then
- if test $DEBUG == "TRUE";
- then
- echo -e $TABS"Searching sub includes"
- fi
- TABS="$TABS\t"
- if test -z $SEARCHED;
- then
- SEARCHED="$LOCATION"
- else
- SEARCHED="$SEARCHED|$LOCATION"
- fi
- search-includes "$LOCATION" "$SEARCHED" "$TABS" "DEBUG"
- fi
- done
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement