OSDN Git Service

modified: Makefile
[eos/hostdependX86LINUX64ICC.git] / lib / fileUtil.wish
1 #
2 #
3 #
4 proc fileCanBeOverwritten { filename } {
5         global flagFileCanBeOverwritten
6
7         if { [file exists $filename ] } {
8                 set t [ toplevel .overwriteChecker ] 
9                 label  $t.label -text "$filename Can be overwritten ?"
10                 button $t.ok -text Yes -command { set flagFileCanBeOverwritten yes }
11                 button $t.no -text No -command  { set flagFileCanBeOverwritten no }
12                 pack $t.label $t.ok $t.no -side top 
13                 tkwait variable flagFileCanBeOverwritten
14                 destroy $t
15         } else {
16                 set flagFileCanBeOverwritten yes 
17         }
18         return $flagFileCanBeOverwritten
19 }
20
21 #
22 # Get Relative Pathname 
23 #
24
25 proc relativePathGet { absDir absPath } {
26         if { [ file exists $absPath ] } {
27                 set listOfabsPath [ split [ file dirname $absPath ] / ] 
28                 set path          [ file tail $absPath ]        
29         } else {
30                 set listOfabsPath [ split [ file dirname $absPath ] / ] 
31                 set path          [ file tail $absPath ]        
32         }
33         if { [ file isdirectory $absDir ] } {
34                 if { 0 == [ string compare $absDir / ] } {
35                         set listOfabsDir  [ split $absDir / ]
36                 } else {
37                         set listOfabsDir  [ split [ string trimright $absDir / ] / ] 
38                 }
39         } else {
40                 puts "Something wrong as for absDir in relativePathGet"
41                 return {}
42         }
43
44         set nOfabsPath [ llength $listOfabsPath ] 
45         set nOfabsDir  [ llength $listOfabsDir  ]
46
47
48         for { set i 0 } { $i < $nOfabsPath && $i < $nOfabsDir } { incr i } {
49                 if { 0 != [ string compare [ lindex $listOfabsPath $i ] \
50                                                                    [ lindex $listOfabsDir  $i ] ] } {
51                         break;
52                 }
53         }
54
55         set relPath {}
56
57         for { set j $i } { $j < $nOfabsDir } { incr j } {
58                 if { 0 == [ string length [ lindex $listOfabsDir $j ] ]  } {
59                         append relPath /
60                 } else {
61                         append relPath ../
62                 }
63         }
64         for { set j $i } { $j < $nOfabsPath } { incr j } {
65                 append relPath [ lindex $listOfabsPath $j ]
66                 append relPath /
67         }
68         
69         append relPath $path 
70
71         return $relPath
72 }
73