0023348: Expression 'ii >= 0' is always true. Unsigned type value is always >= 0.
authorPawel Kowalski <pawel-kowalski@wp.pl>
Fri, 3 Aug 2012 09:28:27 +0000 (13:28 +0400)
committerPawel Kowalski <pawel-kowalski@wp.pl>
Fri, 3 Aug 2012 09:28:27 +0000 (13:28 +0400)
Redesigned the loop to work correctly with unsigned variables.
Treatment of path to source file is rewritten using OSD_Path for more clarity
Command getsourcefile corrected to return its result as Tcl string, and simplified
Error in treatment of optional arguments in substituted puts is fixed in src/DrawResources/TestCommands.tcl
Test case added: demo draw getsource

src/Draw/Draw_Interpretor.cxx
src/DrawResources/StandardCommands.tcl
src/DrawResources/TestCommands.tcl
tests/demo/draw/getsource [new file with mode: 0644]

index 56f475b..8438173 100755 (executable)
@@ -29,6 +29,7 @@
 
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
+#include <OSD_Path.hxx>
 
 #include <string.h>
 #include <tcl.h>
@@ -375,36 +376,23 @@ void Draw_Interpretor::Add(const Standard_CString n,
   if (myInterp==NULL) Init();
 
   CData* C = new CData(f,this);
-  Standard_Size length, num_slashes,  ii,  jj,  kk;
   Tcl_CreateCommand(myInterp,pN,CommandCmd, (ClientData) C, CommandDelete);
 
   // add the help
   Tcl_SetVar2(myInterp,"Draw_Helps",pN,pHelp,TCL_GLOBAL_ONLY);
   Tcl_SetVar2(myInterp,"Draw_Groups",pGroup,pN,
              TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
-  length = strlen(pFileName) ;
-  char * a_string = 
-    new char[length + 1] ;
-  jj = 0 ;
-  num_slashes = 0 ;
-  ii = length ;
-  while (num_slashes < 3 && ii >= 0) {
-    if (file_name[ii] == '/') {
-      num_slashes += 1 ;
-    }
-    ii -= 1 ; 
-  } 
-  jj = 0 ;
-  for (kk = ii+2 , jj =0 ; kk < length ; kk++) {
-     a_string[jj] = file_name[kk] ;
-     jj += 1 ;
-   }
-  a_string[jj] = '\0' ;
-  Tcl_SetVar2(myInterp,"Draw_Files",pN,a_string,TCL_GLOBAL_ONLY);
-
-  delete [] a_string;
 
+  // add path to source file (keep not more than two last subdirectories)
+  OSD_Path aPath (pFileName);
+  Standard_Integer nbTrek = aPath.TrekLength();
+  for (Standard_Integer i = 2; i < nbTrek; i++)
+    aPath.RemoveATrek (1);
+  aPath.SetDisk("");
+  aPath.SetNode("");
+  TCollection_AsciiString aSrcPath;
+  aPath.SystemName (aSrcPath);
+  Tcl_SetVar2(myInterp,"Draw_Files",pN,aSrcPath.ToCString(),TCL_GLOBAL_ONLY);
 }
 
 
index 45a72fb..1d16b4b 100755 (executable)
@@ -96,17 +96,16 @@ proc getsourcefile {{command ""}} {
 
     global Draw_Helps Draw_Groups Draw_Files
 
+    set out {}
     if {$command == ""} {
 
        # help general
        foreach h [lsort [array names Draw_Groups]] {
-           puts ""
-           puts ""
-           puts $h
+           lappend out "" "" "$h"
            set i 0
            foreach f [lsort $Draw_Groups($h)] {
                if {$i == 0} {
-                   puts "  "
+                   lappend out ""
                }
                incr i
 #
@@ -114,18 +113,7 @@ proc getsourcefile {{command ""}} {
 #
                foreach command_that_has_file [array names Draw_Files] {
                    if {($command_that_has_file == $f)} {
-#
-#  compute the length of the string to have the right spacing
-#  with tabs
-#
-                       set ll [string length $f] 
-                       if {($ll >= 1) && ($ll < 8)} {
-                           puts "$f\t\t:  $Draw_Files($f) "
-                       }
-                       if {($ll >= 8)} {
-                           puts "$f\t:  $Draw_Files($f) "
-                       }
-                        
+                       lappend out [format {%-20s %s} $f $Draw_Files($f)]
                    }
                }
            }
@@ -136,17 +124,12 @@ proc getsourcefile {{command ""}} {
        append command "*"
        foreach f [lsort [array names Draw_Files]] {
            if {[string match $command $f]} {
-               puts -nonewline $f
-               for {set j [string length $f]} {$j < 15} {incr j} {
-                   puts -nonewline " "
-               }
-
-               puts "     $Draw_Files($f)"
+                lappend out [format {%-20s %s} $f $Draw_Files($f)]
            }
        }
        
     } 
-    flush stdout
+    return [join $out "\n"]
 }
 
 help getsourcefile {getsourcefile, or getsourcefile command } {DRAW General Commands}
index d29235d..246e520 100644 (file)
@@ -496,8 +496,8 @@ proc _run_test {scriptsdir group gridname casefile} {
 
            # log only output to stdout and stderr, not to file!
            if {[llength $args] > 1} {
-               set optvarg [lindex $args end-1]
-               if { $optarg == stdout || $optarg == stderr || $optarg == -newline } {
+               set optarg [lindex $args end-1]
+               if { $optarg == "stdout" || $optarg == "stderr" || $optarg == "-newline" } {
                    dlog add [lindex $args end]
                }
            } else {
diff --git a/tests/demo/draw/getsource b/tests/demo/draw/getsource
new file mode 100644 (file)
index 0000000..acfe3bb
--- /dev/null
@@ -0,0 +1,10 @@
+# test for command getsource
+
+# check that path returned for command pload is as expected
+set expected src/Draw/Draw_PloadCommands.cxx
+set path [lindex [getsourcefile pload] 1]
+if { [string compare $path $expected] } {
+    puts "Error: command 'getsourcefile pload' returned '$path' while expected '$expected'"
+}
+
+puts "TEST COMPLETED"