home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cayenne Software Inc. 1997
- #
- # File: @(#)vcm_compat.tcl /main/hindenburg/9
- # Author: Lex Warners
- # Description: VCM integration file
- #---------------------------------------------------------------------------
- # SccsId = @(#)vcm_compat.tcl /main/hindenburg/9 6 Jun 1997 Copyright 1997 Cayenne Software Inc.
-
- # proc to avoid extensive change in titanic code
- proc require_module_file {file {module ""}} {
- require $file
- }
-
- require platform.tcl
-
- # old tcl version does not support file split and file join
-
- proc file_split { path } {
- if $win95 {
- set pathSep "\\"
- } else {
- set pathSep "/"
- }
- if { [string index $path 0] == "$pathSep" } {
- return [concat [list $pathSep] [split $path $pathSep]]
- }
- return [split $path $pathSep]
- }
-
- proc file_join { path } {
- if $win95 {
- set pathSep "\\"
- } else {
- set pathSep "/"
- }
- if { [lindex $path 0] == "$pathSep" } {
- return [join [lrange $path 1 end] $pathSep]
- }
- return [join $path $pathSep]
- }
-
- if $win95 {
- # the following exec_simul does not like newlines in arguments
- # translate in appropriate way: write multi line string to file
- # and change argument
- global commandOptionDict
- set commandOptionDict [Dictionary new]
- $commandOptionDict set "\-c" "-cfile"
- $commandOptionDict set "/c" "/cf"
- }
-
- # old tcl cannot do 'exec' on Windows
- proc exec_simul {args} {
- global commandOptionDict
- set tmpFile ""
- foreach e $args {
- # replace arguments with newlines with temporary file
- # equivalent
- if [regexp "\n" $e] {
- set prevArgIndex [expr [llength $newargs] -1]
- set newOpt [$commandOptionDict set [lindex $newargs $prevArgIndex]]
- if { $newOpt != "" } {
- set newargs [lreplace $newargs $prevArgIndex $prevArgIndex $newOpt]
- set tmpFile [BasicFS::tmpFile]
- append newargs " $tmpFile"
- BasicFS::writeFile $tmpFile $e
- continue
- }
- }
-
- # prevent loss of quotes
- regsub -all {\"} $e "\\\"" e
-
- # quote arguments that would otherwise become lists:
- # with spaces and backslashes
- # also quote empty arguments
- if { [regexp {[ \\]} $e] || ($e == "") } {
- append newargs " \"$e\""
- } else {
- append newargs " $e"
- }
- }
- set file [BasicFS::tmpFile]
- set errors [BasicFS::tmpFile]
-
- # command may already contain redirection
- set destFile ""
- if [regexp {(.*) > (.*)} $newargs dummy newCommand destFile] {
- set newargs $newCommand
- set file $destFile
- }
-
- # redirect errors
- global systemCommand
- set status [$systemCommand "cmd.exe /c$newargs 2>$errors >$file"]
-
- if { $tmpFile != "" } {
- BasicFS::removeFile $tmpFile
- }
-
- set fd [open $errors]
- set errorOutput [read -nonewline $fd]
- close $fd
- unlink $errors
-
- # if destFile is set the output is already in a safe place (redirection),
- # otherwise put in command output
- if { $destFile == "" } {
- set fd [open $file]
- set commandOutput [read -nonewline $fd]
- close $fd
- unlink $file
- } else {
- set commandOutput ""
- }
-
- # check errors and throw an exception if errors occurred
- # like tcl7.6 exec returns all output
- if { $errorOutput != "" } {
- set message "$errorOutput"
- if { $commandOutput != "" } {
- set message "$commandOutput$errorOutput"
- }
- error $message
- }
- return $commandOutput
- }
-
- if $win95 {
- rename exec exec_org
- rename exec_simul exec
- }
-
-
-