#!/usr/bin/perl

# The Piper - a simple named pipe [fifo] debugging tool
# Copyright (C) 2006  Joe Reeves
#
# Licensed under the Artistic License
# Please see the LICENSE file included with this distribution
# A copy of this is available on the OSI website at:
# http://www.opensource.org/licenses/artistic-license.php

use Getopt::Std;

getopts('d:p:l:');
unless($opt_d && $opt_p) {
  print "Usage: $0 -d DEBUGLOG -p PIPE [-l LINES]\n";
  print "LINES will default to 1024 if not specified.\n\n";
  exit;
}

my ($debuglog, $sourcepipe, $linelimit) = ($opt_d, $opt_p, $opt_l);

if (!defined($linelimit)) {
  $linelimit = 1024;
}

print "directing $linelimit lines to $debuglog\n";

open (SRCHANDLE, "$sourcepipe");
open (LOGHANDLE, ">$debuglog");

$count = 0;
while(<SRCHANDLE>) {
  while ($count < $linelimit) {
    $line = $_;
    print LOGHANDLE $line;
    $count++;
  }
  exit;
}

