#!/bin/sh

# Quit out if anything fails.
set -e

# Clean out patent-or-otherwise-encumbered code.
# IDEA:  5,214,703 07/01/2012
# EC:    ????????? ??/??/2020

for c in `find crypto/idea -name "*.c" -type f` ; do	
	echo Destroying $c
	> $c
done

for c in `find crypto/evp -name "*_idea.c"`; do
	echo Destroying $c
	> $c
done

for c in `find crypto/bn -name "*gf2m.c"`; do
	echo Destroying $c
	> $c
done

for c in `find crypto/ec -name "ec2*.c" -o -name "ec_curve.c"`; do
	echo Destroying $c
	> $c
done

for a in idea ec; do
  for c in `find test -name "${a}test.c" -type f` ; do
	echo Destroying $c
	> $c
  done
done

for h in `find crypto ssl apps test -name "*.h"` ; do
	echo Removing IDEA and EC2M references from $h
	cat $h | \
	awk    'BEGIN {ech=1;} \
	    /^#[ \t]*ifndef.*NO_IDEA/ {ech--; next;} \
		/^#[ \t]*ifndef.*NO_EC2M/ {ech--; next;} \
                /^#[ \t]*if/ {if(ech < 1) ech--;} \
		{if(ech>0) {;print $0};} \
		/^#[ \t]*endif/ {if(ech < 1) ech++;}' > $h.hobbled && \
	mv $h.hobbled $h
done
