/**
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of MSPSim.
 *
 * $Id: $
 *
 * -----------------------------------------------------------------
 *
 * MiscCommands
 *
 * Author  : Joakim Eriksson
 * Created : 9 mar 2008
 * Updated : $Date:$
 *           $Revision:$
 */
package se.sics.mspsim.cli;

import java.io.PrintStream;

import se.sics.mspsim.util.ComponentRegistry;

/**
 * @author joakim
 *
 */
public class MiscCommands implements CommandBundle {

  public void setupCommands(ComponentRegistry registry, CommandHandler handler) {
    handler.registerCommand("grep", new BasicLineCommand("grep", "<regexp>") {
      private PrintStream out;
      public int executeCommand(CommandContext context) {
        out = context.out;
        return 0;
      }

      public void lineRead(String line) {
        out.println("Grep: " + line);
      }

      public void stopCommand(CommandContext context) {
        context.exit(0);
      }
    });
  }

}

@@ -1916,16 +1916,49 @@
 Stream;%0D
+%0Aimport java.util.regex.Pattern;%0D
 %0A%0D%0Aimpor
@@ -2281,24 +2281,56 @@
 tream out;%0D%0A
+      private Pattern pattern;%0D%0A
       public
@@ -2400,24 +2400,84 @@
 ntext.out;%0D%0A
+        pattern = Pattern.compile(context.getArgument(0));%0D%0A
         retu
@@ -2484,34 +2484,32 @@
 rn 0;%0D%0A      %7D%0D%0A
-%0D%0A
       public voi
@@ -2531,24 +2531,69 @@
 ng line) %7B%0D%0A
+        if (pattern.matcher(line).find())%0D%0A  
         out.
@@ -2604,19 +2604,8 @@
 tln(
-%22Grep: %22 + 
 line
@@ -2617,18 +2617,16 @@
      %7D%0D%0A
-%0D%0A
       pu

implemented grep.