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