#!/usr/bin/perl

print "makeFMStyle - converts standard pcsc-lite package sources\n \
       to Apple framework style for use with Project Builder\n\n";

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

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

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

printf "Adding PCSC/ to 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 =~ /bundleparser\.l/ ) {
    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 "Removing wintypes.h from pcsclite.h\n\n";

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

