From a78acc722ec26be2be20f22f74e98329d57008b1 Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 5 Oct 2005 19:02:19 +0000 Subject: grep etc --- src/GF/Shell.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/GF/Shell.hs') diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs index 8ae01017c..6e3b241c0 100644 --- a/src/GF/Shell.hs +++ b/src/GF/Shell.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/07/01 08:16:32 $ +-- > CVS $Date: 2005/10/05 20:02:19 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.42 $ +-- > CVS $Revision: 1.43 $ -- -- GF shell command interpreter. ----------------------------------------------------------------------------- @@ -51,7 +51,7 @@ import GF.Grammar.PrGrammar import Control.Monad (foldM,liftM) import System (system) import System.Random (newStdGen) ---- -import Data.List (nub) +import Data.List (nub,isPrefixOf) import GF.Data.Zipper ---- import GF.Data.Operations @@ -269,6 +269,8 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of CSystemCommand s -> justOutput opts (system s >> return ()) sa CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa ----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa + CGrep ms -> changeArg (AString . unlines . filter (grep ms) . lines . prCommandArg) sa + CSetFlag -> changeState (addGlobalOptions opts0) sa ---- deprec! CSetLocalFlag lang -> changeState (addLocalOptions lang opts0) sa @@ -327,6 +329,11 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of then (putStrLn ("Warning: discontinuous category" +++ prt_ c)) else (return ()) + grep ms s = (if oElem beVerbose opts then not else id) $ grepv ms s --- -v + grepv ms s = case s of + _:cs -> isPrefixOf ms s || grepv ms cs + _ -> isPrefixOf ms s + -- commands either change the state or process the argument, but not both -- some commands just do output -- cgit v1.2.3