2
0

mafread.tcl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/tclsh
  2. proc is-section line {
  3. return [regexp {^[A-Z ]+$} $line]
  4. }
  5. # First argument is Manifest file, others are sections.
  6. set sections [lassign $argv maffile]
  7. if { $sections == "" } {
  8. puts stderr "Usage: [file tail $argv0] <MAF file> <section name>"
  9. exit 1
  10. }
  11. # NOTE: If the file doesn't exist, simply print nothing.
  12. # If there's no manifest file under this name, it means that
  13. # there are no files that satisfy given manifest and section.
  14. if { [catch {set fd [open $maffile r]}] } {
  15. exit
  16. }
  17. set extracted ""
  18. set insection 0
  19. while { [gets $fd line] >= 0 } {
  20. set oline [string trim $line]
  21. if { $oline == "" } {
  22. continue
  23. }
  24. if { [string index $oline 0] == "#" } {
  25. continue
  26. }
  27. if { !$insection } {
  28. # An opportunity to see if this is a section name
  29. if { ![is-section $line] } {
  30. continue
  31. }
  32. # If it is, then check if this is OUR section
  33. if { $oline in $sections } {
  34. set insection 1
  35. continue
  36. }
  37. } else {
  38. # We are inside the interesting section, so collect filenames
  39. # Check if this is a next section name - if it is, stop reading.
  40. if { [is-section $line] } {
  41. continue
  42. }
  43. # Otherwise read the current filename
  44. lappend extracted $oline
  45. }
  46. }
  47. puts $extracted