Advertisement
image28

Search includes of the includes for includes and errorcodes

Jul 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function search-includes()
  4. {
  5.     IFS=$'\n'
  6.     SEARCH="$1"
  7.     if test -n "$2";
  8.     then
  9.         if test "$2" == "DEBUG"
  10.         then
  11.             DEBUG="TRUE"
  12.         else
  13.             SEARCHED="$2";
  14.         fi
  15.     fi
  16.  
  17.     if test -n "$3";
  18.     then
  19.         TABS="$3"
  20.     fi
  21.  
  22.     if test -n "$4";
  23.     then
  24.         DEBUG="TRUE"
  25.     fi
  26.  
  27.     if test $DEBUG == "TRUE";
  28.     then
  29.         echo -e $TABS"Searching file $SEARCH for includes"
  30.     fi
  31.  
  32.     if test -n "$SEARCH";
  33.     then
  34.         grep -iE "#[ ]{0,}include" "$SEARCH"
  35.         BASESEARCH=`basename $SEARCH`;
  36.         for d in `grep -iE "#[ ]{0,}include" "$SEARCH" | \
  37.             grep -v "$BASESEARCH" | \
  38.             grep -Po "(\<|\"){1}.*\.h(\>|\"){1}" | \
  39.             cut -c2- | rev | cut -c2- | rev | \
  40.             sort | uniq`;
  41.         do
  42.             LOCATION=`slocate $d | grep "^\/usr\/include\/" | head -n1`;
  43.             if test $DEBUG == "TRUE";
  44.             then           
  45.                 echo -e $TABS"Search file $LOCATION for error codes";
  46.             fi
  47.  
  48.             grep -Pi "^#[]{0,}define( |\t){1,}E{1}[A-Za-z0-9]*[0-9]{1,3}" "$LOCATION";
  49.  
  50.             if test $DEBUG == "TRUE";
  51.             then
  52.                 echo -e $TABS"Testing if $LOCATION has previously been searched, previous searches were $SEARCHED";
  53.             fi
  54.  
  55.             if test -z $SEARCHED || test -n `echo "$LOCATION" | grep -viE "($(exec echo $SEARCHED))"`;
  56.             then
  57.                 if test $DEBUG == "TRUE";
  58.                 then
  59.                     echo -e $TABS"Searching sub includes"
  60.                 fi
  61.  
  62.                 TABS="$TABS\t"
  63.                 if test -z $SEARCHED;
  64.                 then
  65.                     SEARCHED="$LOCATION"
  66.                 else
  67.                     SEARCHED="$SEARCHED|$LOCATION"
  68.                 fi
  69.                 search-includes "$LOCATION" "$SEARCHED" "$TABS" "DEBUG"
  70.             fi
  71.         done
  72.     fi
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement