File: mafread.tcl

package info (click to toggle)
srt 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,804 kB
  • sloc: cpp: 52,175; ansic: 5,746; tcl: 1,183; sh: 318; python: 99; makefile: 38
file content (58 lines) | stat: -rwxr-xr-x 1,214 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/tclsh

proc is-section line {
	return [regexp {^[A-Z ]+$} $line]
}

# First argument is Manifest file, others are sections.
set sections [lassign $argv maffile]

if { $sections == "" } {
	puts stderr "Usage: [file tail $argv0] <MAF file> <section name>"
	exit 1
}

# NOTE: If the file doesn't exist, simply print nothing.
# If there's no manifest file under this name, it means that
# there are no files that satisfy given manifest and section.
if { [catch {set fd [open $maffile r]}] } {
	exit
}

set extracted ""
set insection 0

while { [gets $fd line] >= 0 } {
	set oline [string trim $line]
	if { $oline == "" } {
		continue
	}

	if { [string index $oline 0] == "#" } {
		continue
	}

	if { !$insection } {
		# An opportunity to see if this is a section name
		if { ![is-section $line] } {
			continue
		}

		# If it is, then check if this is OUR section
		if { $oline in $sections } {
			set insection 1
			continue
		}
	} else {
		# We are inside the interesting section, so collect filenames
		# Check if this is a next section name - if it is, stop reading.
		if { [is-section $line] } {
			continue
		}

		# Otherwise read the current filename
		lappend extracted $oline
	}
}

puts $extracted