#!/usr/bin/env tclsh8.3
#
###############################################################################
#  Copyright 1992-2001 by Jay Sekora.  This file may be freely distributed,   #
#  modified or unmodified, for any purpose, provided that this copyright      #
#  notice is retained verbatim in all copies and no attempt is made to        #
#  obscure the authorship of this file.  If you distribute any modified       #
#  versions, I ask, but do not require, that you clearly mark any changes     #
#  you make as such and that you provide your users with instructions for     #
#  getting the original sources.                                              #
###############################################################################

if {$argc < 2} {
  puts stderr "Usage: $argv0 <regex> <filename>..."
  puts stderr "  where <filename> is a jrt-format file"
  exit 1
}

set pattern [lindex $argv 0]
set argv [lreplace $argv 0 0]

foreach file $argv {
  if {$argc > 2} {
    set prefix $file:
  } else {
    set prefix ""
  }
  
  set f [open $file r]
  set text [lindex [read $f] 0]
  close $f
  foreach line [split $text \n] {
    if [regexp -- $pattern $line] {
      puts stdout "$prefix$line"
    }
  }
}

