use Win32;
use Win32::Clipboard;

$clip = Win32::Clipboard;

# print "Clipboard Content:\n\n", $clip->Get, "\n";
@pressepapier = split("\n", $clip->Get);
$nlignes = 0;
foreach $ligne (@pressepapier) {
   print "$ligne\n";
   $nlignes++;
}
print "---------------------------------------------------------------------\n";
print "nombre de lignes a transformer =  $nlignes\n";
print "---------------------------------------------------------------------\n";

# $clip->Empty();
# $clip->Set("ciao mondo!\nSalut le monde.");




$retour = MsgBox("JavaScriptToPHP", "Transformation du contenu du presse papier\nsensé contenir du JavaScript en PHP\nnombre de lignes a transformer =  $nlignes\n", 16+4);
if ($retour eq "Yes") {
    $margegauche = "\t\t\t\t";
    open ($F, "> $ENV{'HOMEDRIVE'}$ENV{'HOMEPATH'}\\Bureau\\JAVASCRIPT_TO_PHP.php") || die;
    print $F "\n<?php\n";
    print $F $margegauche . "# Script généré à partir d'un code JavaScript par JavascriptToPhp.pl\n";
    print $F $margegauche . "#-------------------------------------------------------------------\n";
    $nlignes2 = 0;
    foreach $ligne (@pressepapier) {
    	 $lg = length($ligne);
    	 if ($nlignes2 < $nlignes-1) { $lg = $lg - 1; }
    	 $ligne2 = substr($ligne,0,$lg);
    	 # REMPLACE LES "\" par "\\"
    	 $ligne2 =~ s/\\/\\\\/g;
    	 # REMPLACE LES " par \"
    	 $ligne2 =~ s/\"/\\\"/g;
	 print $F $margegauche."print \"" . $ligne2 . " \\n\";\n";
	 print "$ligne2\n";
	 $nlignes2++;
    }
    print $F "\n?>\n";
    close($F);
    MsgBox("JavaScriptToPHP", "Le fichier est généré sur le bureau\n( JAVASCRIPT_TO_PHP.PHP )", 48);
}
exit;


sub MsgBox {
    my ($caption, $message, $icon_buttons) = @_;
    my @return = qw/- Ok Cancel Abort Retry Ignore Yes No/;
    my $result = Win32::MsgBox($message, $icon_buttons, $caption);
    return $return[$result];
}