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