#!/usr/bin/perl
#
# ddt-output: Dosemu output window handler for DDT.
#
# Copyright (C) 1995 by Pasi Eronen.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Version 0.1 (1995-08-19): initial coding.
#

$regexp = ".";
printf("DDT: Using FIFO %s\n", $ARGV[1]);
printf("DDT: Using regexp %s\n", $regexp);
printf("DDT: Writing pid %s to %s\n", $$, $ARGV[2]);
open(PID, ">$ARGV[2]");
print(PID "pid=$$\n");
close(PID);
open(INPUT, $ARGV[1]);

while (1)
{
  $_ = <INPUT>;
  next if (!$_);
  if (/^__DDT__:r:(.*)\S*$/)
  {
    $regexp = $1;
    if (length($regexp) == 0)
    {
      $regexp = ".";
    }
    printf("DDT: Using regexp \"%s\"\n", $regexp);
  }
  elsif (/^__DDT__:q\S*$/)
  {  
    printf("DDT: Quit\n");
    exit 0;
  }
  else
  {
    print if (/$regexp/i);
  }
}
