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