This file is indexed.

/usr/share/saods9/src/catvot.tcl is in saods9-data 7.3.2+repack-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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#  Copyright (C) 1999-2014
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

proc CATVOTParse {t token} {
    upvar #0 $t T
    global $t
    global debug

    if {$debug(tcl,cat)} {
	set fp [open debug.xml w]
	puts $fp [http::data $token]
	close $fp
    }

    set xml [xml::parser \
		 -characterdatacommand [list CATVOTCharCB $t] \
		 -elementstartcommand [list CATVOTElemStartCB $t] \
		 -elementendcommand [list CATVOTElemEndCB $t] \
		 -ignorewhitespace 1 \
		]

    set T(tree,state) {}
    set T(tree,prev) {}
    if [catch {$xml parse [http::data $token]} err] {
	if {$debug(tcl,cat)} {
	    puts stderr "CATVOTParse: $err"
	}
    }

    $xml free
}

proc CATVOTRead {t fn} {
    upvar #0 $t T
    global $t

    global debug
    if {$debug(tcl,cat)} {
	puts stderr "CATVOTRead"
    }

    if {$fn == {}} {
	return
    }

    catch {
	set fp [open $fn r]

	set xml [xml::parser \
		     -characterdatacommand [list CATVOTCharCB $t]\
		     -elementstartcommand [list CATVOTElemStartCB $t] \
		     -elementendcommand [list CATVOTElemEndCB $t] \
		     -ignorewhitespace 1 \
		    ]

	set T(tree,state) {}
	set T(tree,prev) {}
	if {[catch {$xml parse [read $fp]} err]} {
	    if {$debug(tcl,cat)} {
		puts stderr "CATVOTRead: $err"
	    }
	}
	
	$xml free

	close $fp
    }
}

proc CATVOTWrite {t fn} {
    upvar #0 $t T
    global $t

    global debug
    if {$debug(tcl,cat)} {
	puts stderr "CATVOTWriteFile"
    }

    if {$fn == {}} {
	return
    }

    set fp [open $fn w]

    set nr $T(Nrows)
    set nc $T(Ncols)

    puts $fp {<?xml version="1.0" encoding="UTF-8"?>}
    puts $fp {<VOTABLE version="1.1">}
    puts $fp {<RESOURCE>}
    puts $fp {<TABLE>}

    # header
    puts -nonewline $fp {<DESCRIPTION>}
    set nh [expr $T(HLines)-1]
    for {set hh 1} {$hh < $nh} {incr hh} {
	puts $fp [XMLQuote "$T(H_$hh)"]
    }
    puts $fp {</DESCRIPTION>}

    # cols
    for {set cc 1} {$cc <= $nc} {incr cc} {
	puts -nonewline $fp {<FIELD }
	# required
	puts -nonewline $fp "name=\"[XMLQuote [lindex $T(Header) [expr $cc-1]]]\" "
	# required
	if {[info exists ${t}(DataType)]} {
	    puts -nonewline $fp "datatype=\"[XMLQuote [lindex $T(DataType) [expr $cc-1]]]\" "
	} else {
	    puts -nonewline $fp "datatype=\"char\" arraysize=\"*\" "
	}

	if {[info exists ${t}(Id)]} {
	    if {[lindex $T(Id) [expr $cc-1]] != {}} {
		puts -nonewline $fp "ID=\"[XMLQuote [lindex $T(Id) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(ArraySize)]} {
	    if {[lindex $T(ArraySize) [expr $cc-1]] != {}} {
		puts -nonewline $fp "arraysize=\"[XMLQuote [lindex $T(ArraySize) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(Width)]} {
	    if {[lindex $T(Width) [expr $cc-1]] != {}} {
		puts -nonewline $fp "width=\"[XMLQuote [lindex $T(Width) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(Precision)]} {
	    if {[lindex $T(Precision) [expr $cc-1]] != {}} {
		puts -nonewline $fp "precision=\"[XMLQuote [lindex $T(Precision) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(Unit)]} {
	    if {[lindex $T(Unit) [expr $cc-1]] != {}} {
		puts -nonewline $fp "unit=\"[XMLQuote [lindex $T(Unit) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(Ref)]} {
	    if {[lindex $T(Ref) [expr $cc-1]] != {}} {
		puts -nonewline $fp "ref=\"[XMLQuote [lindex $T(Ref) [expr $cc-1]]]\" "
	    }
	}
	if {[info exists ${t}(Ucd)]} {
	    if {[lindex $T(Ucd) [expr $cc-1]] != {}} {
		puts -nonewline $fp "ucd=\"[XMLQuote [lindex $T(Ucd) [expr $cc-1]]]\" "
	    }
	}

	puts $fp {>}

	if {[info exists ${t}(Description)]} {
	    if {[lindex $T(Description) [expr $cc-1]] != {}} {
		puts -nonewline $fp {<DESCRIPTION>}
		puts -nonewline $fp "[XMLQuote [lindex $T(Description) [expr $cc-1]]]"
		puts $fp {</DESCRIPTION>}
	    }
	}

	puts $fp {</FIELD>}
    }

    # data
    puts $fp {<DATA>}
    puts $fp {<TABLEDATA>}

    for {set rr 1} {$rr <= $nr} {incr rr} {
	puts -nonewline $fp {<TR>}
	for {set cc 1} {$cc <= $nc} {incr cc} {
	    puts -nonewline $fp "<TD>[XMLQuote $T($rr,$cc)]</TD>"
	}
	puts $fp {</TR>}
    }

    # clean up
    puts $fp {</TABLEDATA>}
    puts $fp {</DATA>}
    puts $fp {</TABLE>}
    puts $fp {</RESOURCE>}
    puts $fp {</VOTABLE>}

    close $fp
}

# Callbacks

proc CATVOTCharCB {t data} {
    upvar #0 $t T
    global $t
    global debug

    switch -- $T(tree,state) {
	TD {
	    set r $T(Nrows)
	    set c $T(cnt)
	    set T($r,$c) [string trim $data]
	}
	DESCRIPTION {
	    set data [string trim $data]
	    if {$data != {}} {
		switch -- $T(tree,prev) {
		    VOTABLE -
		    RESOURCE -
		    TABLE {
			foreach ll [split [string trim $data] "\n"] {
			    incr ${t}(HLines)
			    set n $T(HLines)
			    if {[string range $ll 0 0] == {#}} {
				set T(H_$n) "$ll"
			    } else {
				set T(H_$n) "# $ll"
			    }
			}
		    }
		    FIELD {
			set T(Description) \
			    [lreplace $T(Description) end end $data]
		    }
		}
	    }
	}
    }

    # sometimes, we get a bogus call, (ignore whitespace does not work)
    set T(tree,state) {}
    return {}
}

proc CATVOTElemStartCB {t name attlist args} {
    upvar #0 $t T
    global $t
    global debug

    switch -- $name {
	VOTABLE {
	    # init db
	    set T(Nrows) 0
	    set T(Ncols) 0
	    set T(Header) {}
	    set T(HLines) 0
	    set T(tree,prev) $name
	}
	FIELD {
	    set fname {}
	    set id {}
	    set datatype {}
	    set arraysize {}
	    set width {}
	    set precision {}
	    set unit {}
	    set ref {}
	    set ucd {}
	    foreach {key value} $attlist {
		switch -- [string tolower $key] {
		    name {set fname "$value"}
		    id {set id "$value"}
		    datatype {set datatype $value}
		    arraysize {set arraysize $value}
		    width {set width $value}
		    precision {set precision $value}
		    unit {set unit "$value"}
		    ref {set ref "$value"}
		    ucd {set ucd "$value"}
		}
	    }
	    lappend ${t}(Header) "$fname"
	    lappend ${t}(Id) "$id"
	    lappend ${t}(DataType) $datatype
	    lappend ${t}(ArraySize) $arraysize
	    lappend ${t}(Width) $width
	    lappend ${t}(Precision) $precision
	    lappend ${t}(Unit) "$unit"
	    lappend ${t}(Ref) "$ref"
	    lappend ${t}(Ucd) "$ucd"

	    # filled in later
	    lappend ${t}(Description) {}

	    set T(tree,prev) $name
	}
	TABLEDATA {
	    # ok, we now need to build the header
	    incr ${t}(HLines)
	    set n $T(HLines)
	    set T(H_$n) [join $T(Header)]

	    set T(Dashes) [regsub -all {[A-Za-z0-9]} $T(H_$n) {-}]
	    set T(Ndshs) [llength $T(Header)]

	    incr ${t}(HLines)
	    set n $T(HLines)
	    set T(H_$n) [join $T(Dashes)]

	    starbase_colmap $t
	}
	TR {
	    incr ${t}(Nrows)
	    set T(cnt) 0
	}
	TD {
	    incr ${t}(cnt)

	    set r $T(Nrows)
	    set c $T(cnt)
	    set T($r,$c) {}
	}

	RESOURCE -
	TABLE {
	    set T(tree,prev) $name
	}

	FIELDref -
	DESCRIPTION -
	COOSYS -
	PARAM -
	PARAMref -
	INFO -
	LINK -
	GROUP -
	DATA -
	BINARY -
	STREAM -
	FITS -
	VALUES -
	MIN -
	MAX -
	OPTION -
	DEFINITIONS {}

	default {return -code error}
    }

    set ${t}(tree,state) $name
    return {}
}

proc CATVOTElemEndCB {t name args} {
    upvar #0 $t T
    global $t
    global debug

    # we can't count on this being called for all end-tags
    switch -- $name {
	TABLEDATA {
	    # ok, we're done
	    return -code break
	}
	VOTABLE -
	FIELD -
	FIELDref -
	TR -
	TD -
	RESOURCE -
	TABLE -
	DESCRIPTION -
	COOSYS -
	PARAM -
	PARAMref -
	INFO -
	LINK -
	GROUP -
	DATA -
	BINARY -
	STREAM -
	FITS -
	VALUES -
	MIN -
	MAX -
	OPTION -
	DEFINITIONS {}

	default {return -code error}
    }
    return {}
}

# SAMP

proc CATVOTURL {url catalog title} {
    if {[string length $url] == 0} {
	return
    }

    ParseURL $url r
    switch -- $r(scheme) {
	ftp {CATVOTFTP $r(authority) $r(path)}
	file {CATVOTFile $r(path)}
	http -
	default {CATVOTHTTP $url $catalog $title}
    }
}

proc CATVOTFTP {host path} {
    global loadParam
    global ds9
    global debug

    set ftp [ftp::Open $host "ftp" "-ds9@" -mode passive]
    if {$ftp > -1} {
	set fn "$ds9(tmpdir)/[file tail $path]"
	set ftp::VERBOSE $debug(tcl,ftp)
	set "ftp::ftp${ftp}(Output)" FTPLog
	ftp::Type $ftp binary
	if [ftp::Get $ftp $path $fn] {
	    CATVOTFile $fn
	}

	ftp::Close $ftp

	if [file exists $fn] {
	    catch {file delete -force $fn}
	}
    }
}

proc CATVOTHTTP {url catalog title} {
    global icat

    CATDialog catvot {} $catalog $title none

    set varname [lindex $icat(cats) end]
    upvar #0 $varname var
    global $varname

    set ${varname}(query) {}
    set ${varname}(url) $url
    set ${varname}(proc,parser) CATVOTParse

    CATLoad $varname
}

proc CATVOTFile {fn} {
    global icat

    CATDialog catvot {} {} {} none
    if {$fn != {}} {
 	CATLoadFn [lindex $icat(cats) end] $fn CATVOTRead
    }
}