This file is indexed.

/usr/share/tcltk/stubs/genframe.tcl is in critcl 3.1.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# -*- tcl -*-
# STUBS handling -- Code generation framework.
#
# (c) 2011 Andreas Kupries http://wiki.tcl.tk/andreas%20kupries

# A stubs table is represented by a dictionary value.
# A gen is a variable holding a stubs table value.

# # ## ### ##### ######## #############
## Requisites

package require Tcl 8.4
package require stubs::container

namespace eval ::stubs::gen::c {
    namespace import ::stubs::container::*
}

# # ## ### ##### ######## #############
## Implementation.

proc ::stubs::gen::warn {cmdprefix} {
    variable warnCmd $cmdprefix
    return
}

proc ::stubs::gen::uncap {text} {
    return [string tolower [string index $text 0]][string range $text 1 end]
}

proc ::stubs::gen::cap {text} {
    return [string toupper [string index $text 0]][string range $text 1 end]
}

proc ::stubs::gen::forall {table name emitCmd onAll {skipString {}}} {
    if {$skipString eq {}} {
	#checker exclude warnArgWrite
	set skipString "/* Slot @@ is reserved */\n"
    }

    set platforms [c::platforms $table $name]

    if {[lsearch -exact $platforms "generic"] >= 0} {
	# Emit integrated stubs block
	set lastNum [MAX [c::lastof $table $name]]

	for {set i 0} {$i <= $lastNum} {incr i} {

	    set slots [c::slotplatforms $table $name $i]
	    set emit 0
	    if {[lsearch -exact $slots "generic"] >= 0} {
		if {[llength $slots] > 1} {
		    WARN {conflicting generic and platform entries: $name $i}
		}

		append text [CALL generic $i]
		set emit 1

	    } elseif {[llength $slots] > 0} {

		array set slot {unix 0 x11 0 win 0 macosx 0 aqua 0}
		foreach s $slots { set slot($s) 1 }
		# "aqua", "macosx" and "x11" are special cases:
		# "macosx" implies "unix", "aqua" implies "macosx" and "x11"
		# implies "unix", so we need to be careful not to emit
		# duplicate stubs entries:
		if {($slot(unix) && $slot(macosx)) ||
		    (($slot(unix) || $slot(macosx)) &&
		     ($slot(x11)  || $slot(aqua)))} {
		    WARN {conflicting platform entries: $name $i}
		}
		## unix ##
		set temp {}
		set plat unix
		if {!$slot(aqua) && !$slot(x11)} {
		    if {$slot($plat)} {
			append temp [CALL $plat $i]
		    } elseif {$onAll} {
			append temp [SKIP]
		    }
		}
		if {$temp ne ""} {
		    append text [AddPlatformGuard $plat $temp]
		    set emit 1
		}
		## x11 ##
		set temp {}
		set plat x11
		if {!$slot(unix) && !$slot(macosx)} {
		    if {$slot($plat)} {
			append temp [CALL $plat $i]
		    } elseif {$onAll} {
			append temp [SKIP]
		    }
		}
		if {$temp ne ""} {
		    append text [AddPlatformGuard $plat $temp]
		    set emit 1
		}
		## win ##
		set temp {}
		set plat win
		if {$slot($plat)} {
		    append temp [CALL $plat $i]
		} elseif {$onAll} {
		    append temp [SKIP]
		}
		if {$temp ne ""} {
		    append text [AddPlatformGuard $plat $temp]
		    set emit 1
		}
		## macosx ##
		set temp {}
		set plat macosx
		if {!$slot(aqua) && !$slot(x11)} {
		    if {$slot($plat)} {
			append temp [CALL $plat $i]
		    } elseif {$slot(unix)} {
			append temp [CALL unix $i]
		    } elseif {$onAll} {
			append temp [SKIP]
		    }
		}
		if {$temp ne ""} {
		    append text [AddPlatformGuard $plat $temp]
		    set emit 1
		}
		## aqua ##
		set temp {}
		set plat aqua
		if {!$slot(unix) && !$slot(macosx)} {
		    if {[string range $skipString 0 1] ne "/*"} {
			# The code previously had a bug here causing
			# it to erroneously generate both a unix entry
			# and an aqua entry for a given stubs table
			# slot. To preserve backwards compatibility,
			# generate a dummy stubs entry before every
			# aqua entry (note that this breaks the
			# correspondence between emitted entry number
			# and actual position of the entry in the
			# stubs table, e.g.  TkIntStubs entry 113 for
			# aqua is in fact at position 114 in the
			# table, entry 114 at position 116 etc).
			append temp [SKIP]
			CHOP temp
			append temp " /*\
				Dummy entry for stubs table backwards\
				compatibility */\n"
		    }
		    if {$slot($plat)} {
			append temp [CALL $plat $i]
		    } elseif {$onAll} {
			append temp [SKIP]
		    }
		}
		if {$temp ne ""} {
		    append text [AddPlatformGuard $plat $temp]
		    set emit 1
		}
	    }
	    if {!$emit} {
		append text [SKIP]
	    }
	}
    } else {
	# Emit separate stubs blocks per platform
	array set block {unix 0 x11 0 win 0 macosx 0 aqua 0}
	foreach s $platforms { set block($s) 1 }

	## unix ##
	if {$block(unix) && !$block(x11)} {
	    set temp {}
	    set plat unix

	    # (1) put into helper method
	    set lastNum [c::lastof $table $name $plat]
	    for {set i 0} {$i <= $lastNum} {incr i} {
		if {[c::slot? $table $name $plat $i]} {
		    append temp [CALL $plat $i]
		} else {
		    append temp [SKIP]
		}
	    }
	    append text [AddPlatformGuard $plat $temp]
	}
	## win ##
	if {$block(win)} {
	    set temp {}
	    set plat win

	    # (1) put into helper method
	    set lastNum [c::lastof $table $name $plat]
	    for {set i 0} {$i <= $lastNum} {incr i} {
		if {[c::slot? $table $name $plat $i]} {
		    append temp [CALL $plat $i]
		} else {
		    append temp [SKIP]
		}
	    }
	    append text [AddPlatformGuard $plat $temp]
	}
	## macosx ##
	if {$block(macosx) && !$block(aqua) && !$block(x11)} {
	    set temp {}
	    set lastNum [MAX [list \
				  [c::lastof $table $name unix] \
				  [c::lastof $table $name macosx]]]

	    for {set i 0} {$i <= $lastNum} {incr i} {
		set emit 0
		foreach plat {unix macosx} {
		    if {[c::slot? $table $name $plat $i]} {
			append temp [CALL $plat $i]
			set emit 1
			break
		    }
		}
		if {!$emit} {
		    append temp [SKIP]
		}
	    }
	    append text [AddPlatformGuard macosx $temp]
	}
	## aqua ##
	if {$block(aqua)} {
	    set temp {}
	    set lastNum [MAX [list \
				  [c::lastof $table $name unix] \
				  [c::lastof $table $name macosx] \
				  [c::lastof $table $name aqua]]]

	    for {set i 0} {$i <= $lastNum} {incr i} {
		set emit 0
		foreach plat {unix macosx aqua} {
		    if {[c::slot? $table $name $plat $i]} {
			append temp [CALL $plat $i]
			set emit 1
			break
		    }
		}
		if {!$emit} {
		    append temp [SKIP]
		}
	    }
	    append text [AddPlatformGuard aqua $temp]
	}
	## x11 ##
	if {$block(x11)} {
	    set temp {}
	    set lastNum [MAX [list \
				  [c::lastof $table $name unix] \
				  [c::lastof $table $name macosx] \
				  [c::lastof $table $name x11]]]

	    for {set i 0} {$i <= $lastNum} {incr i} {
		set emit 0
		foreach plat {unix macosx x11} {
		    if {[c::slot? $table $name $plat $i]} {
			if {$plat ne "macosx"} {
			    append temp [CALL $plat $i]
			} else {
			    append temp [AddPlatformGuard $plat \
					     [CALL $plat $i] \
					     [SKIP]]
			}
			set emit 1
			break
		    }
		}
		if {!$emit} {
		    append temp [SKIP]
		}
	    }
	    append text [AddPlatformGuard x11 $temp]
	}
    }

    return $text
}

proc ::stubs::gen::rewrite {path newcode} {
    if {![file exists $path]} {
	return -code error "Cannot find file: $path"
    }

    set in  [open ${path}     r]
    set out [open ${path}.new w]

    # Hardwired use of unix line-endings in the output.
    fconfigure $out -translation lf

    # Copy the file header before the code section.
    while {![eof $in]} {
	set line [gets $in]
	if {[string match "*!BEGIN!*" $line]} break
	puts $out $line
    }

    puts $out "/* !BEGIN!: Do not edit below this line. */"

    # Insert the new code.
    puts $out $newcode

    # Skip over the input until the end of the code section.
    while {![eof $in]} {
	set line [gets $in]
	if {[string match "*!END!*" $line]} break
    }

    # Copy the trailer after the code section. This can be done fast,
    # as searching is not required anymore.
    puts $out "/* !END!: Do not edit above this line. */"
    puts -nonewline $out [read $in]

    # Close and commit to the changes (atomic rename).
    close $in
    close $out
    file rename -force -- ${path}.new ${path}
    return
}

# # ## ### #####
## Internal helpers.

proc ::stubs::gen::CALL {platform index} {
    upvar 1 table table name name emitCmd emitCmd
    set decl [c::slot $table $name $platform $index]
    return [uplevel \#0 [linsert $emitCmd end $name $decl $index]]
}

proc ::stubs::gen::WARN {text} {
    variable warnCmd
    if {$warnCmd eq {}} return
    return [uplevel \#0 [linsert $warnCmd end [uplevel 1 [list ::subst $text]]]]
}

proc ::stubs::gen::SKIP {} {
    upvar 1 skipString skipString i i
    #puts stderr SKIP/$i/[string map [list {$i} $i] $skipString]
    return [string map [list @@ $i] $skipString]
}

proc ::stubs::gen::CHOP {textvar} {
    upvar 1 $textvar text
    set text [string range $text 0 end-1]
    return
}

proc ::stubs::gen::AddPlatformGuard {platform iftext {elsetext {}}} {
    variable guard_begin
    variable guard_else
    variable guard_end

    set prefix [expr {![info exists guard_begin($platform)] ? "" : $guard_begin($platform)}]
    set middle [expr {![info exists guard_else($platform)]  ? "" : $guard_else($platform)}]
    set suffix [expr {![info exists guard_end($platform)]   ? "" : $guard_end($platform)}]

    return $prefix$iftext[expr {($elsetext eq "")
				? ""
				: "$middle$elsetext"}]$suffix
}

if {[package vsatisfies [package present Tcl] 8.5]} {
    #checker exclude warnRedefine
    proc ::stubs::gen::MAX {list} {
	return [tcl::mathfunc::max {*}$list]
    }
} else {
    #checker exclude warnRedefine
    proc ::stubs::gen::MAX {list} {
	set max {}
	foreach a $list {
	    if {($max ne {}) && ($max >= $a)} continue
	    set max $a
	}
	return $a
    }
}

# # ## ### #####

namespace eval ::stubs::gen {
    #checker -scope block exclude warnShadowVar
    variable guard_begin
    variable guard_else
    variable guard_end

    array set guard_begin {
	win    "#ifdef __WIN32__ /* WIN */\n"
	unix   "#if !defined(__WIN32__) && !defined(MAC_OSX_TCL) /* UNIX */\n"
	macosx "#ifdef MAC_OSX_TCL /* MACOSX */\n"
	aqua   "#ifdef MAC_OSX_TK /* AQUA */\n"
	x11    "#if !(defined(__WIN32__) || defined(MAC_OSX_TK)) /* X11 */\n"
    }
    array set guard_else {
	win    "#else /* WIN */\n"
	unix   "#else /* UNIX */\n"
	macosx "#else /* MACOSX */\n"
	aqua   "#else /* AQUA */\n"
	x11    "#else /* X11 */\n"
    }
    array set guard_end {
	win    "#endif /* WIN */\n"
	unix   "#endif /* UNIX */\n"
	macosx "#endif /* MACOSX */\n"
	aqua   "#endif /* AQUA */\n"
	x11    "#endif /* X11 */\n"
    }

    # Default command to report conflict and other warnings.
    variable warnCmd {puts stderr}

    namespace export forall rewrite warn cap uncap
}

# # ## ### #####
package provide stubs::gen 1
return