2
0

find-unused-errs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /bin/bash
  2. # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # Find unused error function-names and reason-codes, and edit them
  9. # out of the source. Doesn't handle line-wrapping, might have to do
  10. # some manual cleanups to fix compile errors.
  11. export X1=/tmp/f.1.$$
  12. export X2=/tmp/f.2.$$
  13. case "$1" in
  14. -f)
  15. PAT='_F_'
  16. echo Functions only
  17. ;;
  18. -[er])
  19. PAT='_R_'
  20. echo Reason codes only
  21. ;;
  22. "")
  23. PAT='_[FR]_'
  24. echo Function and reasons
  25. ;;
  26. *)
  27. echo "Usage error; one of -[efr] required."
  28. exit 1;
  29. ;;
  30. esac
  31. cd include/openssl || exit 1
  32. grep "$PAT" * | grep -v ERR_FATAL_ERROR | awk '{print $3;}' | sort -u >$X1
  33. cd ../..
  34. for F in `cat $X1` ; do
  35. git grep -l --full-name -F $F >$X2
  36. NUM=`wc -l <$X2`
  37. test $NUM -gt 2 && continue
  38. if grep -q $F crypto/err/openssl.ec ; then
  39. echo Possibly unused $F found in openssl.ec
  40. continue
  41. fi
  42. echo $F
  43. for FILE in `cat $X2` ; do
  44. grep -v -w $F <$FILE >$FILE.new
  45. mv $FILE.new $FILE
  46. done
  47. done
  48. rm $X1 $X2