#!/usr/bin/perl

print "makeSTDStyle - converts standard Apple Framework package sources\n \
       to MUSCLE winscard sources using wintypes.h\n\n";

$sedcommand = "sed 's^PCSC/wintypes.h^wintypes.h^g' | \
sed 's^PCSC/winscard.h^winscard.h^g' | sed 's^PCSC/pcsclite.h^pcsclite.h^g'";

$sedpcsclite = "sed 's^\#define PCSC_USE_WINTYPES FALSE^\#include \<wintypes.h\>^g'";

opendir(DIR, ".") || die "Cannot opendir .\n";
@dents = readdir(DIR);
closedir(DIR);

printf "Removing PCSC/ from winscard, wintypes, and pcsclite.h\n";

foreach $dent (@dents) {

 if ( $dent ne "test.c" ) {
  if ( $dent =~ /\.c/ ) {
    system("cat $dent | $sedcommand > tmpfile");
    system("mv tmpfile $dent");
    print "$dent\n"; 
  }

  if ( $dent =~ /configfile\.l/ ) {
    system("cat $dent | $sedcommand > tmpfile");
    system("mv tmpfile $dent");
    print "$dent\n"; 
  }

  if ( $dent =~ /pcsclite\.h/ ) {
    system("cat $dent | $sedcommand > tmpfile");
    system("mv tmpfile $dent");
    print "$dent\n"; 
  }

  if ( $dent =~ /winscard\.h/ ) {
    system("cat $dent | $sedcommand > tmpfile");
    system("mv tmpfile $dent");
    print "$dent\n"; 
  }
 }

}

# Remove include <wintypes.h> from pcsclite.h

    print "Adding wintypes.h to pcsclite.h\n\n";

    system("cat pcsclite.h | $sedpcsclite > tmpfile");
    system("mv tmpfile pcsclite.h");
    print "$dent\n"; 

