From: Michael Wiebusch Date: Wed, 14 Aug 2013 09:21:38 +0000 (+0200) Subject: changed value range check behaviour in jtageditor X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ebb2d3ffa625b4d5a7e462ba73245de225793b58;p=mvdsensorcontrol.git changed value range check behaviour in jtageditor --- diff --git a/tools/Common.pm b/tools/Common.pm index 1cccb2f..ca5e379 100644 --- a/tools/Common.pm +++ b/tools/Common.pm @@ -94,6 +94,21 @@ sub any2dec { # converts numeric expressions 0x, 0b or decimal to decimal } } +sub numBase { + + my $argument = $_[0]; + + if ( $argument =~ m/^\s*0[xX]/) { + return "hex"; + } elsif ( $argument =~ m/^\s*0[bB]/) { + return "bin"; + } else { + return "dec"; + } + + +} + sub stripLeadingZeros{ my $string = $_[0]; $string =~ s/^0+//; diff --git a/tools/jtageditor.pl b/tools/jtageditor.pl index bef9e7c..2549cb7 100755 --- a/tools/jtageditor.pl +++ b/tools/jtageditor.pl @@ -2,25 +2,24 @@ print "Content-type: text/html\n\n"; # TODO -# correct size in tooltip -# implement a hex/bin/dec converter that is easy to use -# remove CGI processing routines that are now in xmlOperation.pl -# still there but commented out +# --- critical --- -# substitute selectedConfigFile() with "$configFileName" inside print_registers and print_fieldsi -# outsource print_registers and print_fields to xmlOperations # make jtageditor callable with config file name as CGI # argument, so editor opens specified config file - +# be able to accept long hex strings # what happens when files are not writable? + +# --- would be nice, not critical ---- # make sure that error fields are hidden as well! +# substitute selectedConfigFile() with "$configFileName" inside print_registers and print_fieldsi +# outsource print_registers and print_fields to xmlOperations +# implement a hex/bin/dec converter that is easy to use -# correct size in tooltip @@ -29,6 +28,12 @@ print "Content-type: text/html\n\n"; # DONE + + +# remove CGI processing routines that are now in xmlOperation.pl +# still there but commented out + +# correct size in tooltip # build ancestry without ancestry tree outside # do not include wrong type, different specfile # whine, wenn specfile/setfiles not found @@ -111,42 +116,7 @@ if ( defined $cgiHash{'debuginput'} ) { print $cgiHash{'debuginput'}; } -# # obsolete -# if ( defined $cgiHash{'action'} ) { -# -# printHash( \%cgiHash ); -# if ( $cgiHash{'action'} eq 'save' ) { -# parseConfigFile( $cgiHash{'configFile'} ); -# save( $cgiHash{'register'}, $cgiHash{'field'}, $cgiHash{'value'} ); -# writeConfigFile(); -# } -# if ( $cgiHash{'action'} eq 'delete' ) { -# parseConfigFile( $cgiHash{'configFile'} ); -# del( $cgiHash{'register'}, $cgiHash{'field'} ); -# writeConfigFile(); -# } -# if ( $cgiHash{'action'} eq 'copyDefaultRegister' ) { -# parseConfigAndSpec( $cgiHash{'configFile'} ); -# del( $cgiHash{'register'}, "" ); # delete existing register from setfile -# copyDefaultRegister( $cgiHash{'register'} ); -# writeConfigFile(); -# } -# if ( $cgiHash{'action'} eq 'createFile' ) { -# createConfigFile( $cgiHash{'configFile'}, $cgiHash{'specFile'} ); -# writeConfigFile(); -# } -# -# if ( $cgiHash{'action'} eq 'deleteFile' ) { -# deleteFile( $cgiHash{'configFile'} ); -# } -# -# if ( $cgiHash{'action'} eq 'changeAncestor' ) { -# parseConfigFile( $cgiHash{'configFile'} ); -# changeAncestor( $cgiHash{'newAncestor'} ); -# writeConfigFile(); -# } -# -# } + #################### SUBLAND ###################### @@ -367,12 +337,25 @@ sub print_fields { ) || "n/a" ); - - my $maxFieldVal = 2**$fieldSize-1; - my $sizeInfo = + + my $sizeInfo; + my $maxFieldVal = 2**32-1; + if ($fieldSize <=32){ # if Field size smaller than 32 you could be interested + # in a decimal value range info + + $maxFieldVal = 2**$fieldSize-1; + $sizeInfo = sprintf( - "Field contains %d bits, possible values: 0-%d (0x0-0x%x)\n\n", + "Field contains %d bits, possible values: 0-%d (0x0-0x%X)\n\n", $fieldSize, $maxFieldVal, $maxFieldVal ); + } else { + + $sizeInfo = + sprintf( + "Field contains %d bits, hex representation would be %d digits long.\n\n", + $fieldSize, ceil($fieldSize/4)); + + } $fieldDescr = $sizeInfo . $fieldDescr; @@ -424,14 +407,31 @@ EOF } } print ""; - if ( ( any2dec($fieldValue) < 0 ) - or ( any2dec($fieldValue) > $maxFieldVal ) ) + +##### check if range was exceeded ###### + if ($fieldSize <= 32) { # 32 bit is the region where we want to allow decimal input + + my $decFieldValue = any2dec($fieldValue); + + if ( ($decFieldValue < 0 ) or ( $decFieldValue > $maxFieldVal ) ) { print "!!!Above value not in allowed range!!!" ; # just debug } + + } else { # field size exceeds the region where we want to accept decimal input + + if ( numBase($fieldValue) eq "dec" ) { + unless( $fieldValue eq "0") { # a zero would be okay + print "!!!please don't enter decimal numbers for fields longer than 32 bit!!!"; + } + } + + } +### end of range check #### } + print ""; } @@ -568,22 +568,6 @@ sub read_input { } -# already in Common.pm - -# sub any2dec { # converts numeric expressions 0x, 0b or decimal to decimal -# -# my $argument = $_[0]; -# -# #print "any2dec input argument $argument\n"; -# -# if ( $argument =~ m/0[bxBX]/ ) { -# return oct $argument; -# } -# else { -# return $argument; -# } -# } - sub printJavaScripts { ####### javascript function land ################