]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
changed value range check behaviour in jtageditor
authorMichael Wiebusch <stratomaster@gmx.net>
Wed, 14 Aug 2013 09:21:38 +0000 (11:21 +0200)
committerMichael Wiebusch <stratomaster@gmx.net>
Wed, 14 Aug 2013 09:21:38 +0000 (11:21 +0200)
tools/Common.pm
tools/jtageditor.pl

index 1cccb2f11e9a133d6746ec507699a4f9bc229271..ca5e37957a1432902fe03519ff6aa543a738b706 100644 (file)
@@ -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+//;
index bef9e7c250ac924e11d88633aa7ec22c1d795465..2549cb7d56cfd508bec60df9a799da39f7dfb23c 100755 (executable)
@@ -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 "</tr>";
-    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
 "<tr class='fieldError'><td colspan = 4 align='center'>!!!Above value not in allowed range!!!</td></tr>"
         ;    # 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 "<tr class='fieldError'><td colspan = 4 align='center'>!!!please don't enter decimal numbers for fields longer than 32 bit!!!</td></tr>";
+        }
+      }
+    
+    }
+### end of range check ####  
   }
+  
   print "</table>";
 
 }
@@ -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 ################