Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:38

0001 #!/bin/sh
0002 # -*- Tcl -*- the next line restarts using tclsh \
0003 exec tclsh "$0" ${1+"$@"}
0004 
0005 proc print_usage {} {
0006     puts stderr ""
0007     puts stderr "Usage: [file tail [info script]] file_name line_number_1 line_number_2 ..."
0008     puts stderr ""
0009     return
0010 }
0011 
0012 # Check the input arguments
0013 if {$argc < 2} {
0014     print_usage
0015     exit 1
0016 }
0017 
0018 # Parse the arguments
0019 set fname [lindex $argv 0]
0020 if {![file readable $fname]} {
0021     puts stderr "Error: file \"$fname\" does not exist (or unreadable)"
0022     exit 1
0023 }
0024 
0025 proc file_contents {filename} {
0026     set chan [open $filename "r"]
0027     set contents [read $chan [file size $filename]]
0028     close $chan
0029     return $contents
0030 }
0031 
0032 set lines [split [file_contents $fname] "\n"]
0033 set nlines [llength $lines]
0034 
0035 set line_numbers [list]
0036 foreach inp [lrange $argv 1 end] {
0037     if {![string is integer -strict $inp]} {
0038         puts stderr "Argument \"$inp\" does not represent a valid line number"
0039         exit 1
0040     }
0041     if {$inp <= 0 || $inp > $nlines} {
0042         puts stderr "Line number $inp is out of range"
0043         exit 1
0044     }
0045     lappend line_numbers [expr {$inp - 1}]
0046 }
0047 
0048 foreach l $line_numbers {
0049     puts [lindex $lines $l]
0050 }
0051 
0052 exit 0