]> OCCT Git - occt-wok.git/commitdiff
No comments
authorcas <cas@opencascade.com>
Wed, 30 Aug 2000 18:30:40 +0000 (18:30 +0000)
committercas <cas@opencascade.com>
Wed, 30 Aug 2000 18:30:40 +0000 (18:30 +0000)
src/WOKTclLib/wutils.tcl

index 67676f9ae374a0231ff770bdc8db04c31745cbf0..90e4812a7e1a5ec41bc11eb2fc9798f63f8bca9f 100755 (executable)
@@ -458,7 +458,7 @@ proc wokUtils:FILES:AppendListToFile { liste path } {
     } 
 }
 #
-# Replace s1 by s2 in f and write result in g
+# Replace s1 by s2 in fin and write result in fout
 # return 1 if substitution was performed.
 #
 proc wokUtils:EASY:replace { fin fout s1 s2  } {
@@ -483,6 +483,35 @@ proc wokUtils:EASY:replace { fin fout s1 s2  } {
     }
 }
 #
+# Same as Replace but l is a list of couple {s1 s2}
+# return 1 if at least one substitution has been done.
+# This proc differs of the above one for lazyness purpose.
+#
+proc wokUtils:EASY:lreplace { fin fout ls1s2 } {
+    if { [catch { set in [ open $fin r ] } errin] == 0 } {
+       if { [catch { set out [ open $fout w ] } errout] == 0 } {
+           set strin [read $in [file size $fin]]
+           close $in
+           foreach [list s1 s2] $ls1s2 {
+               set done 0
+               if { [set nbsub [regsub -all -- $s1 $strin $s2 strout]] != 0 } {
+                   set done 1
+               }
+               set strin $strout
+           }
+           puts $out $strout
+           close $out
+           return $done
+       } else {
+           puts stderr "Error: $errout"
+           return 0
+       }
+    } else {
+           puts stderr "Error: $errin"
+       return 0
+    }
+}
+#
 # Compares 2 full pathes for TEXT ASCII files. Returs 1 if identicals 0 ifnot
 #
 proc wokUtils:FILES:AreSame { f1 f2 } {