| File: | config/auto/format.pm |
| Coverage: | 97.2% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2003, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 11 | =head1 NAME config/auto/format.pm - Sprintf Formats =head1 DESCRIPTION Figures out what formats should be used for C<sprintf()>. =cut | ||||
| 12 | |||||
| 13 | package auto::format; | ||||
| 14 | |||||
| 15 | 2 2 2 | use strict; | |||
| 16 | 2 2 2 | use warnings; | |||
| 17 | |||||
| 18 | 2 2 2 | use base qw(Parrot::Configure::Step); | |||
| 19 | |||||
| 20 | 2 2 2 | use Parrot::Configure::Step; | |||
| 21 | |||||
| 22 | |||||
| 23 | sub _init { | ||||
| 24 | 2 | my $self = shift; | |||
| 25 | 2 | my %data; | |||
| 26 | 2 | $data{description} = q{What formats should be used for sprintf}; | |||
| 27 | 2 | $data{result} = q{}; | |||
| 28 | 2 | return \%data; | |||
| 29 | } | ||||
| 30 | |||||
| 31 | sub runstep { | ||||
| 32 | 2 | my ( $self, $conf ) = @_; | |||
| 33 | |||||
| 34 | 2 | _set_intvalfmt($conf); | |||
| 35 | |||||
| 36 | 2 | _set_floatvalfmt_nvsize($conf); | |||
| 37 | |||||
| 38 | 2 | return 1; | |||
| 39 | } | ||||
| 40 | |||||
| 41 | sub _set_intvalfmt { | ||||
| 42 | 8 | my $conf = shift; | |||
| 43 | 8 | my $ivformat; | |||
| 44 | 8 | my $iv = $conf->data->get(qw(iv)); | |||
| 45 | |||||
| 46 | 8 | if ( $iv eq "int" ) { | |||
| 47 | 1 | $ivformat = "%d"; | |||
| 48 | } | ||||
| 49 | elsif ( ( $iv eq "long" ) || ( $iv eq "long int" ) ) { | ||||
| 50 | 4 | $ivformat = "%ld"; | |||
| 51 | } | ||||
| 52 | elsif ( ( $iv eq "long long" ) || ( $iv eq "long long int" ) ) { | ||||
| 53 | 2 | $ivformat = "%lld"; | |||
| 54 | } | ||||
| 55 | else { | ||||
| 56 | 1 | die qq{Configure.pl: Can't find a printf-style format specifier for type '$iv'\n}; | |||
| 57 | } | ||||
| 58 | 7 | $conf->data->set( intvalfmt => $ivformat ); | |||
| 59 | } | ||||
| 60 | |||||
| 61 | sub _set_floatvalfmt_nvsize { | ||||
| 62 | 5 | my $conf = shift; | |||
| 63 | 5 | my ( $nv, $floatsize, $doublesize, $ldsize ) = | |||
| 64 | $conf->data->get(qw(nv floatsize doublesize hugefloatvalsize)); | ||||
| 65 | 5 | my ( $nvformat, $nvsize ); | |||
| 66 | 5 | $nvsize = $floatsize; | |||
| 67 | 5 | if ( $nv eq "double" ) { | |||
| 68 | 3 | $nvsize = $doublesize; | |||
| 69 | 3 | $nvformat = "%.15g"; | |||
| 70 | } | ||||
| 71 | elsif ( $nv eq "long double" ) { | ||||
| 72 | |||||
| 73 | # Stay way from long double for now (it may be 64 or 80 bits) | ||||
| 74 | # die "long double not supported at this time, use double."; | ||||
| 75 | 1 | $nvsize = $ldsize; | |||
| 76 | 1 | my $spri = $conf->data->get('sPRIgldbl_provisional'); | |||
| 77 | 1 | if ( defined $spri ) { | |||
| 78 | 1 | $nvformat = "%.15" . $spri; | |||
| 79 | 1 | $nvformat =~ s/"//g; # Perl 5's Config value has embedded double quotes | |||
| 80 | } | ||||
| 81 | else { | ||||
| 82 | 0 | die qq{Configure.pl: Can't find a printf-style format specifier for type '$nv'\n}; | |||
| 83 | } | ||||
| 84 | } | ||||
| 85 | else { | ||||
| 86 | 1 | die qq{Configure.pl: Can't find a printf-style format specifier for type '$nv'\n}; | |||
| 87 | } | ||||
| 88 | |||||
| 89 | 4 | $conf->data->set( | |||
| 90 | floatvalfmt => $nvformat, | ||||
| 91 | nvsize => $nvsize | ||||
| 92 | ); | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | 1; | ||||
| 96 | |||||
| 97 | # Local Variables: | ||||
| 98 | # mode: cperl | ||||
| 99 | # cperl-indent-level: 4 | ||||
| 100 | # fill-column: 100 | ||||
| 101 | # End: | ||||
| 102 | # vim: expandtab shiftwidth=4: | ||||