#!/bin/sh


for FILE in $*
do
echo "%%%%%%%%%%%%%%%%%%% Processing $FILE"


cat $FILE | gawk -v FILE=$FILE '

# enlever  .if . \{ une ligne avant .SH BUG
#/\.if . \\/ {go=1; mal=NR ; SAVE=$0; next}
##/^[\t ]*$/  {if (go) next}
#/\.SH BUG/ {if (go) 
#		if (NR==(mal+1))
#		    {
#		    SAVE="";
##		    printf("%s:%d\n", FILE , mal);
#		}
#	    }
#		{if (go) print SAVE ; print; go=0}	    
#

# remplacer .SH BUG.... par .so
#BEGIN           { go = 1; }
#
#/\.SH BUG/   { go = 0;
#                 printf( ".so man1/alc_origin.1\n" );
#                 next;
#                }
#
#/\.SH/          { go = 1; }
#
#		{if (go) print}
 
# remplacer .TH
#.TH TAS 1 "September 30 1997" "Release 5.20" "cao\-vlsi reference manual"
#/^\.TH/          {printf(".TH %s %s \"October 1 1997\" %s %s", $2, $3, $5, $6 )  ; next; }
BEGIN		{FS="\"";
		 gsub (/\./, " " , FILE); 
		FILE=toupper(FILE);}
/^\.TH/          {printf(".TH %s \"October 1, 1997\" \"ASIM/LIP6\" \"%s\"\n", FILE, $(NF-1))  ;next; }
		{ print }
	    
' > tmp_file.tmp 

#sed -e "s/$1/$2/g" $FILE > tmp_file.tmp 
cp tmp_file.tmp $FILE
rm tmp_file.tmp
done
