home *** CD-ROM | disk | FTP | other *** search
- # ~/icase/small_library.tcl
- #
- # Created: 15 april 1996
- # Updated: 18 april 1996
- # Version: 1.2
- # Purpose: To make some functions globally platform independent available
- # like an as user friendly as possible file selection.
- # Notes on V1.1: Made use of the standard otk FileChooser
- # Notes on V1.2: Made use of system to make it MS DOS compatible
-
-
- #puts "Using ~/icase/small_library.tcl"
-
- # -------------------------
- # get the require procedure
- # -------------------------
- source [m4_path_name tcl libocl.tcl]
-
-
- # --------------------------------
- # to get the global variable win95
- # --------------------------------
- require platform.tcl
-
-
- # ------------------------------------------
- # Like the UNIX command date without options
- # ------------------------------------------
- proc date { } {
- return [fmtclock [getclock]]
- }
-
-
- proc get_user_name { } {
- # --------------------------------------------------------------------
- # The unix and pc version differ, in the future test with others (DEC)
- # --------------------------------------------------------------------
- #if { $win95 } {
- # return [lindex [get_comm_name] 2]
- #} else {
- # return [exec logname]
- #}
- return [M4Login::getUserName]
- }
-
-
- # -------------------------------------
- # could be not available on windows '95
- # -------------------------------------
- proc get_host_name { } {
- # --------------------------------------------------------------------
- # The unix and pc version differ, in the future test with others (DEC)
- # --------------------------------------------------------------------
- if { $win95 } {
- return $env(COMPUTERNAME)
- } else {
- return [exec uname -n]
- }
- }
-
-
- # -----------------------------------
- # To retrieve the user home directory
- # -----------------------------------
- proc get_home_directory { } {
- # --------------------------------------------------
- # an elaborate method to remain platform independent
- # --------------------------------------------------
- #set directory [pwd] ; # retrieve currect working directory
- #cd ; # change work directory to home directory
- #set home_directory [pwd] ; # remember the home directory
- #cd $directory ; # set working directory to original one
- #return $home_directory ; # return the found home directory
-
- # ---------------------------------------------
- # The simple version, also platform independent
- # ---------------------------------------------
- return [glob ~]
- }
-
-
- # --------------------------------------------------------
- # The 'user friendly' fileselect with the otk file_chooser
- # binding with otk via temporary files.
- # --------------------------------------------------------
- proc FileSelect { } {
- set file_name ""
- set icase_directory [path_name concat [lindex [glob ~] 0] icase]
- set file_chooser [path_name concat $icase_directory file_chooser.tcl]
- set otk [m4_path_name bin otk$EXE_EXT]
-
- # --------------------------------
- # try the standard otk FileChooser
- # --------------------------------
- if { [file exists $file_chooser] } {
- set file_name ""
- if { $win95 } {
- # ------------------------------------------------------
- # an elaborate construction to make it MS DOS compatible
- # ------------------------------------------------------
- set tmp_file [args_file {}]
- system "$otk $file_chooser -- $tmp_file"
- set fd [open $tmp_file "r+"]
- gets $fd file_name
- close $fd
- } else {
- set file_name [exec $otk $file_chooser]
- }
- return [lindex $file_name 0]
- }
-
- # -----------------------------------------
- # try the file selector on unix if possible
- # -----------------------------------------
- if { ! $win95 } {
- # ---------------------------------------------------
- # Check to see if the command FileSelect is available
- # ---------------------------------------------------
- set location "[exec which FileSelect]"
- if { [llength $location] == 1 } {
- set file_name "[exec FileSelect]"
- return $file_name
- }
- }
-
- # ------------------------------
- # Use the shell input facilities
- # ------------------------------
- puts -nonewline "Enter a name please: "
- gets stdin file_name
- return $file_name
- }
-
-
- proc execute { command } {
- set tmp_file [args_file {}]
- system "$command >$tmp_file"
- set fd [open $tmp_file "r+"]
-
- set output ""
- while { [gets $fd line] >= 0 } {
- set output "$output\n$line"
- }
-
- close $fd
- system "rm $tmp_file"
-
- return $output
- }
-