#!/bin/sh
#
# Usage: ./shadow-patching.sh <ROOT-version>
#
# Loops over files which cause shadow warnings vs. the global namespace,
# in the specified ROOT version.
#
# 20260101  Michael Kelsey

# Ensure that requested ROOT version exists
ROOTVER=$1

if [ -n "$ROOTVER" ]; then
    ROOTDIR=$ROOTVER/include
    if [ ! -d $ROOTDIR ]; then
        1>&2 echo "$0 ERROR ROOT version $ROOTVER not found."
	exit 2
    fi
    echo "$0 Processing $ROOTDIR."
elif [ -r TROOT.h ]; then
    ROOTDIR=.
    echo "$0 Processing current include/ directory."
else
    1>&2 echo "$0 ERROR No ROOT version specified."
fi


# List of files to be processed

files="TApplication.h TAttMarker.h TBranch.h TClass.h TFile.h TGFrame.h \
    TInterpreter.h TMatrixT.h TMatrixTSparse.h TMatrixTSym.h TSocket.h \
    TSystem.h TTree.h TVirtualX.h"

dosed=`dirname $0`/shadow-patching.sed

for f in $files; do
    rf=$ROOTDIR/$f
    [ -w $rf ] && grep -q "clang diagnostic" $rf || $dosed -i .orig $rf
done

