use strict;
use warnings;
use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody);
-use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid unmake_str);
+use Parse::Pidl::Util qw(has_property
+ ParseExpr
+ ParseExprExt
+ print_uuid
+ unmake_str
+ parse_int
+ parse_range);
use Parse::Pidl::CUtil qw(get_pointer_to get_value_of get_array_element);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsPipe is_charset_array);
use Parse::Pidl::Samba4 qw(is_intree choose_header ArrayDynamicallyAllocated);
my $array_size = "size_$e->{NAME}_$l->{LEVEL_INDEX}";
if (my $range = has_property($e, "range")) {
- my ($low, $high) = split(/,/, $range, 2);
+ my ($low, $high) = parse_range($range);
if ($low < 0) {
warning(0, "$low is invalid for the range of an array size");
}
my $array_length = "length_$e->{NAME}_$l->{LEVEL_INDEX}";
if (my $range = has_property($e, "range")) {
- my ($low, $high) = split(/,/, $range, 2);
+ my ($low, $high) = parse_range($range);
if ($low < 0) {
warning(0, "$low is invalid for the range of an array size");
}
if ($range and $pl->{TYPE} ne "ARRAY") {
$var_name = get_value_of($var_name);
my $signed = Parse::Pidl::Typelist::is_signed($l->{DATA_TYPE});
- my ($low, $high) = split(/,/, $range, 2);
+ my ($low, $high) = parse_range($range);
if ($low < 0 and not $signed) {
warning(0, "$low is invalid for the range of an unsigned type");
}
require Exporter;
@ISA = qw(Exporter);
-@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper genpad);
+@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper genpad parse_int parse_range);
use vars qw($VERSION);
$VERSION = '0.01';
return "\t"x($nt)." "x($ns);
}
+=item B<parse_int>
+
+Try to convert hex and octal strings to numbers. If a string doesn't
+look hexish or octish it will be left as is. If the unconverted string
+is actually a decimal number, Perl is likely to handle it correctly.
+
+=cut
+
+sub parse_int {
+ my $s = shift;
+ if ($s =~ /^0[xX][0-9A-Fa-f]+$/) {
+ return hex $s;
+ }
+ if ($s =~ /^0[0-7]+$/) {
+ return oct $s;
+ }
+ return $s;
+}
+
+=item B<parse_range>
+
+Read a range specification that might contain hex or octal numbers,
+and work out what those numbers are.
+
+=cut
+
+sub parse_range {
+ my $range = shift;
+ my ($low, $high) = split(/,/, $range, 2);
+ $low = parse_int($low);
+ $high = parse_int($high);
+ return ($low, $high);
+}
+
+
=back
=cut