#!/usr/bin/perl -w
+#TODO
+# padZeros strangely not working!
+
sub any2hex {
my $argument = $_[0];
}
+
+sub stripBasePrefix{
+ my $argument = $_[0];
+
+ $argument =~ s/^0[xXbB]//;
+ return $argument;
+}
+
sub any2dec { # converts numeric expressions 0x, 0b or decimal to decimal
my $argument = $_[0];
}
+sub zeros{
+ # return a string with [argument] zeros inside :D
+ if($_[0] == 0) { return ""; }
+ return sprintf("%0".$_[0]."d",0);
+}
+
sub getFieldVal {
my $regStr = $_[0]; # pointer!
- my $start = $_[1];
- my $end = $_[2];
+ my $start = $_[1]; # start position
+ my $end = $_[2]; # end position
my $regStrLen = length($$regStr);
}
+sub padZeros{
+ my $string = $_[0]; # pointer!
+ my $paddingGroupSize = $_[1];
+ $$string =~ s/^0+//; # remove leading zeros
+ my $stringLength = length($$string);
+ print "strangeString:".$$string."\n";
+
+ my $neededZeros = ($paddingGroupSize-($stringLength % $paddingGroupSize)) % $paddingGroupSize;
+
+ $$string=zeros($neededZeros).$$string;
+}
+
+sub writeFieldInRegister {
+
+ my $regStr = $_[0]; # pointer!
+ my $newFieldVal = stripLeadingZeros($_[1]); # the new content in form of binary string
+ my $newFieldValLength = length($newFieldVal);
+ my $start = $_[2]; # start position in register
+ my $end = $_[3]; # end position in register
+ my $substrLength = $end-$start+1;
+ #check if everything fits!
+ if($newFieldValLength > $substrLength) {
+ die "the field value is too big for the field size!\n";
+ }
+
+ my $fieldStr = zeros($substrLength); # fill needed length with zeros
+ substr($fieldStr,-$newFieldValLength) = $newFieldVal; # paste the new field val inside the field string
+
+ my $regStrLen = length($$regStr);
+
+ my $substrStart = $regStrLen-1-$end;
+
+ substr($$regStr,$substrStart,$substrLength) = $fieldStr; # paste the field string into the register string
+
+}
1;
}
}
-#sub assignFieldColors {
-#
-# my @fieldColors = (
-# "#CCFFCC", "#CCFFFF", "#CCCCFF", "#FFCCFF",
-# "#FFCCCC", "#FFFFCC", "#FFFFFF"
-# );
-#
-# my @ancestryWithChild;
-# push(@ancestryWithChild,@ancestryList);
-# push(@ancestryWithChild,$configFileName);
-#
-# my $index=0;
-# for my $fileName (reverse(@ancestryWithChild)){
-# $fieldColorHash{$fileName}= $fieldColors[$index];
-# if($index < @fieldColors){
-# $index++;
-# }
-# }
-#
-#}
+
sub print_registers {
my $xmlfile = $_[0];