Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/ecole_etude_fac_de_pau/licence_2/calculatrice/func.pl

(Deskargatu)
#!/usr/bin/perl -w
#
#
#    This file is part of "CalBinaire".
#
#    Calbinaire is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License.
#
#    Calbinaire is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Foobar; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
##################################################################################/

sub clear()
{
    print "\e[2J";	# clear screen 
    print "\e[1H";	# position 1,1
}


sub menu()
{
$rep = 0;
while($rep ne "6")
{
    print <<_EOF_MENU_;
    

    /\\______________.oOo. \e[1mCalBinaire\e[0m .oO_____________/\\
    |                                                 |
    |   \e[1m1\e[0m     -   Convertir un entier en binaire      |
    |   \e[1m2\e[0m     -   Addition binaire                    |
    |   \e[1m3\e[0m     -   Soustraction binaire                |
    |   \e[1m4\e[0m     -   Multiplication binaire              |
    |   \e[1m5\e[0m     -   Division binaire                    |
    |   \e[1m6\e[0m     -   Sortir                              |    
    \\_________________________________________________/


_EOF_MENU_
affichage($ans);
my $rep = &lecture;
if ($rep) { &programme($rep); }
}
}



sub lecture()
{
    print "Veuillez entrer un choix entre 1 et 6 : ";
    my $entree = <STDIN>;
    chomp($entree);
    while ($entree !~ /^[123456]$/)
    {
	print "Choix incorrect \"$entree\" (de 1 a 6) : Veuillez reentrer un choix.\n";
	$entree = <STDIN>;
        chomp($entree);	
    }
    return $entree;

}


sub programme($)
{
    my $prop = shift;
    $ans = &{$func[$prop]};
}









sub entrer_bin()
{
my $num;
    do
    {
        print "Entrer un entier binaire (sur 32 bits : 1_8_23 ): ";
        $num = <STDIN>;
	chomp($num);	
    }
    until ($num =~ /^[01]{32}$/);
return $num;
}







sub entrer_int()
{
my $num;
    do
    {
        print "Entrer un entier reel: ";
        $num = <STDIN>;
	chomp($num);	
    }
    until ($num =~ /^\-?[0-9]+(?:\.[0-9]+)?$/);
return $num;
}



sub normalise($) # remplie de 0 a gauche ...
{
$num = shift;
my @long = split //,$num;  my $long = scalar @long;
for ($long .. 31) { $num = "0".$num; }
print "FIN $num\n";
return $num;

}







sub affichage($)
{
my $num = shift;
$num =~ /(\d)(\d{8})(\d{23})/ && print "Recu   :\n\t Brut     :   $num\n\t Separe   :   $1 $2 $3\n\n"; 
}




return 1;