/*
 * Filter Utility
 * Copyright (c) Cornell University
 * Department of Computer Science
 * 
 * Kamen Yotov (kamen@yotov.org)
 * 
 * $Source: C:/CVS/kyotov/kyotov/Research/BC/Utilities/Filter/Filter.cs,v $
 * $Revision: 1.3 $
 * $Date: 2002/08/14 04:17:29 $
 */

using System;
using System.Text.RegularExpressions;

namespace Utilities
{
	class Filter
	{
		[STAThread]
		static void Main (string[] a)
		{
			Regex r = new Regex(a[0]);

			string t;

			int c = 0;

			while ((t = Console.ReadLine()) != null)
			{
				Match m = r.Match(t);

				object[] p = new object[m.Captures.Count];

				if (p.Length != 0)
				{
					for (int i = 0; i < p.Length; i++)
						p[i] = m.Captures[i].Value;

					Console.WriteLine(a[1], p);

					c++;
				}
			}

			if (a.Length >= 3 && a[2].ToLower() == "/c")
				Console.Error.WriteLine("{0} lines match!", c);
		}
	}
}
