packages feed

cgrep 6.6.24 → 6.6.25

raw patch · 5 files changed

+47/−27 lines, 5 filesdep +exceptions

Dependencies added: exceptions

Files

README.md view
@@ -7,7 +7,7 @@ Usage ----- -Cgrep 6.6.24. Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.6.25. Usage: cgrep [OPTION] [PATTERN] files...  cgrep [OPTIONS] [ITEM] 
cgrep.cabal view
@@ -1,6 +1,6 @@ Name:                cgrep Description:         Cgrep: a context-aware grep for source codes-Version:             6.6.24+Version:             6.6.25 Synopsis:            Command line tool Homepage:            http://awgn.github.io/cgrep/ License:             GPL-2@@ -10,7 +10,6 @@ Category:            Utils Build-type:          Simple  Stability:           Experimental-Build-type:          Simple Extra-source-files:  README.md Cabal-version:       >=1.10 @@ -77,6 +76,7 @@                        transformers,                        process,                        aeson,-                       yaml+                       yaml,+                       exceptions   Ghc-options:         -O2 -Wall -threaded -rtsopts -with-rtsopts=-N   Default-language:    Haskell2010
src/CGrep/CGrep.hs view
@@ -30,7 +30,11 @@ import qualified CGrep.Strategy.Generic.Semantic as Semantic  import Control.Monad.Trans.Reader+import Control.Monad.Catch+import Control.Monad.IO.Class +import System.IO+ import CGrep.Lang import CGrep.Common import CGrep.Output@@ -39,6 +43,7 @@ import Data.Maybe import Options import Reader+import Config  hasLanguage :: FilePath -> Options -> [Lang] -> Bool hasLanguage path opt xs = isJust $ getFileLang opt path >>= (`elemIndex` xs)@@ -73,14 +78,22 @@ isRegexp :: Options -> Bool isRegexp opt = regex_posix opt || regex_pcre opt -runCgrep :: FilePath -> [Text8] -> OptionT IO [Output]-runCgrep filename patterns = do-    opt <- reader snd-    case () of-        _ | (not . isRegexp) opt && not (hasTokenizerOpt opt) && not (semantic opt) && edit_dist opt -> Levenshtein.search filename patterns-          | (not . isRegexp) opt && not (hasTokenizerOpt opt) && not (semantic opt)                  -> BoyerMoore.search filename patterns-          | (not . isRegexp) opt && semantic opt && hasLanguage filename opt [C,Cpp]                 -> CppSemantic.search filename patterns-          | (not . isRegexp) opt && semantic opt                                                     -> Semantic.search filename patterns-          | (not . isRegexp) opt                                                                     -> CppTokenizer.search filename patterns-          | isRegexp opt                                                                             -> Regex.search filename patterns-          | otherwise                                                                                -> undefined+runCgrep :: Config -> Options -> FilePath -> [Text8] -> OptionT IO [Output]+runCgrep conf opts filename patterns =+    catch ( do+        opt <- reader snd+        case () of+            _ | (not . isRegexp) opt && not (hasTokenizerOpt opt) && not (semantic opt) && edit_dist opt -> Levenshtein.search filename patterns+              | (not . isRegexp) opt && not (hasTokenizerOpt opt) && not (semantic opt)                  -> BoyerMoore.search filename patterns+              | (not . isRegexp) opt && semantic opt && hasLanguage filename opt [C,Cpp]                 -> CppSemantic.search filename patterns+              | (not . isRegexp) opt && semantic opt                                                     -> Semantic.search filename patterns+              | (not . isRegexp) opt                                                                     -> CppTokenizer.search filename patterns+              | isRegexp opt                                                                             -> Regex.search filename patterns+              | otherwise                                                                                -> undefined+    )+    (\e -> let msg = show (e :: SomeException) in+        liftIO $ do+            hPutStrLn stderr $ showFileName conf opts filename ++ ": exception: " ++ takeN 80 msg+            return [ ]+    )+
src/CGrep/Common.hs view
@@ -24,7 +24,8 @@                     , expandMultiline                     , ignoreCase                     , trim-                    , trim8) where+                    , trim8+                    , takeN) where  import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Search as SC@@ -37,6 +38,11 @@ import Options import Reader import Util+++takeN :: Int -> String -> String+takeN n xs | length xs > n = take n xs ++ "..."+          | otherwise     = xs   trim :: String -> String
src/Main.hs view
@@ -138,22 +138,23 @@     in_chan  <- liftIO newTChanIO     out_chan <- liftIO newTChanIO +     -- launch worker threads...      forM_ [1 .. jobs opts] $ \_ -> liftIO . forkIO $         void $ runExceptT . forever $ do             fs <- lift $ atomically $ readTChan in_chan-            lift $ E.catch (case fs of-                    [] -> atomically $ writeTChan out_chan []-                    xs -> void $ (if asynch opts then flip mapConcurrently-                                                 else forM) xs $ \x -> do-                            out <- fmap (take (max_count opts)) (runReaderT (runCgrep x patterns) (conf,sanitizeOptions x opts))-                            unless (null out) $ atomically $ writeTChan out_chan out)-                   (\e -> let msg = show (e :: SomeException) in-                        hPutStrLn stderr (showFileName conf opts (getTargetName (head fs))-                            ++ ": exception: " ++ if length msg > 80-                                                    then take 80 msg ++ "..."-                                                    else msg))+            lift $+                E.catch (+                    case fs of+                        [] -> atomically $ writeTChan out_chan []+                        xs -> void $ (if asynch opts then flip mapConcurrently+                                                     else forM) xs $ \x -> do+                                out <- fmap (take (max_count opts)) (runReaderT (runCgrep conf opts x patterns) (conf, sanitizeOptions x opts))+                                unless (null out) $ atomically $ writeTChan out_chan out)+                       (\e -> let msg = show (e :: SomeException) in+                            hPutStrLn stderr (showFileName conf opts (getTargetName (head fs))+                                ++ ": exception: " ++ takeN 80 msg))             when (null fs) $ throwE ()