summaryrefslogtreecommitdiff
path: root/tix/tools/makescript.tcl
blob: 06840abcc74f159ffa33f308f3b5ac91043ef3ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

set dir [lindex $argv 0]

proc CheckDep {file dep} {
    global $file $dep

    if [info exist $file\($dep\)] {
	return 1
    } else {
	foreach dd [array names $file] {
	    if [CheckDep $dd $dep] {
		return 1
	    }
	}
	return 0
    }
}

proc PrintDep {file dep} {
    global $file $dep

    if [info exist $file\($dep\)] {
	return "$file"
    } else {
	foreach dd [array names $file] {
	    set list [PrintDep $dd $dep]
	    if {$list != {}} {
		return "$file -> $list"
	    }
	}
	return {}
    }
}


foreach line [split [exec cat $dir/tclIndex] \n] {
    regsub auto_index $line a line
    regsub "\"source \{\\\$dir/" $line "" line
    regsub "\}\"" $line "" line

    if [regexp :: $line] {
	continue
    }

    eval $line
}

set fake(Compat.tcl,FileBox.tcl)	1
set fake(Compat.tcl,ComboBox.tcl)	1
set fake(Compat.tcl,WinFile.tcl)	1
set fake(Compat.tcl,UnixFile.tcl)	1
set fake(FileCmpt.tcl,Tix.tcl)		1
set fake(DefSchm.tcl,Tix.tcl)		1
set fake(Tix.tcl,Balloon.tcl)		1
set fake(FileCmpt.tcl,Tix.tcl)		1
set fake(Tix.tcl,FileDlg.tcl)		1
set fake(Tix.tcl,Shell.tcl)		1
set fake(FileBox.tcl,FileDlg.tcl)	1
set fake(UnixFile.tcl,WinFile.tcl)	1
set fake(WinFile.tcl,UnixFile.tcl)	1
set fake(UnixFile.tcl,Tix.tcl)		1
set fake(WinFile.tcl,Tix.tcl)		1
set fake(WinFile.tcl,Compat.tcl)	1


set fake(Tix.tcl,Balloon.tcl)		1
set fake(Tix.tcl,Shell.tcl)		1
set fake(Tix.tcl,FileDlg.tcl)		1
set fake(Utils.tcl,FileDlg.tcl)		1
set fake(ComboBox.tcl,FileBox.tcl)	1

cd ../library

if 1 {
    set TH [glob *.tcl]
} else {
    set TH {Compat.tcl FileBox.tcl Tix.tcl FileCmpt.tcl Tree.tcl Verify.tcl}
}

set hasError 0

foreach file [lsort $TH] {
    set files($file) 1
    set data [exec cat $file]
    foreach proc [array names a] {
	set otherFile $a($proc)

	if {$a($proc) == $file} {
	    continue
	}
	if [info exist $file\($otherFile\)] {
	    continue
	}
	if [regexp $proc $data] {
	    if [info exists fake($file,$otherFile)] {
		puts stderr "\t(ignored) FAKE dependence $file -> $otherFile"
		continue
	    } elseif [CheckDep $otherFile $file] {
		puts stderr "\t(error) CIRCULAR dependence $file -> $otherFile"
		puts stderr "\t$file -> [PrintDep $otherFile $file]"
		set hasError 1
	    } else {
 		set $file\($otherFile\) 1
		puts stderr  "$file -> $otherFile"
	    }
	}
    }
}

if {$hasError} {
    puts stderr "Error occurred"
    exit -1
} else {
    puts stderr "All dependencies resolved. Proceeding ..."
}

proc Load {file} {
    global loaded dir

    if [info exists loaded($file)] {
	return
    } else {
	global $file
	if [info exists $file] {
	    foreach n [array names $file] {
		Load $n
	    }
	}
	puts "    ET_INCLUDE( $dir/$file );"
	set loaded($file) 1
    }
}

proc LoadFiles {} {
    global files loaded
    catch {
	unset loaded
    }

    foreach f [array names files] {
	Load $f
    }
}

LoadFiles

puts stderr Done