| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 |  | 
|  | 9 | # Find unused error function-names and reason-codes, and edit them | 
|  | 10 | # out of the source.  Doesn't handle line-wrapping, might have to do | 
|  | 11 | # some manual cleanups to fix compile errors. | 
|  | 12 |  | 
|  | 13 | export X1=/tmp/f.1.$$ | 
|  | 14 | export X2=/tmp/f.2.$$ | 
|  | 15 |  | 
|  | 16 | case "$1" in | 
|  | 17 | -f) | 
|  | 18 | PAT='_F_' | 
|  | 19 | echo Functions only | 
|  | 20 | ;; | 
|  | 21 | -[er]) | 
|  | 22 | PAT='_R_' | 
|  | 23 | echo Reason codes only | 
|  | 24 | ;; | 
|  | 25 | "") | 
|  | 26 | PAT='_[FR]_' | 
|  | 27 | echo Function and reasons | 
|  | 28 | ;; | 
|  | 29 | *) | 
|  | 30 | echo "Usage error; one of -[efr] required." | 
|  | 31 | exit 1; | 
|  | 32 | ;; | 
|  | 33 | esac | 
|  | 34 |  | 
|  | 35 | cd include/openssl || exit 1 | 
|  | 36 | grep "$PAT" *  | grep -v ERR_FATAL_ERROR | awk '{print $3;}' | sort -u >$X1 | 
|  | 37 | cd ../.. | 
|  | 38 |  | 
|  | 39 | for F in `cat $X1` ; do | 
|  | 40 | git grep -l --full-name -F $F >$X2 | 
|  | 41 | NUM=`wc -l <$X2` | 
|  | 42 | test $NUM -gt 2 && continue | 
|  | 43 | if grep -q $F crypto/err/openssl.ec ; then | 
|  | 44 | echo Possibly unused $F found in openssl.ec | 
|  | 45 | continue | 
|  | 46 | fi | 
|  | 47 | echo $F | 
|  | 48 | for FILE in `cat $X2` ; do | 
|  | 49 | grep -v -w $F <$FILE >$FILE.new | 
|  | 50 | mv $FILE.new $FILE | 
|  | 51 | done | 
|  | 52 | done | 
|  | 53 |  | 
|  | 54 | rm $X1 $X2 |