packages feed

cgrep 6.4.3.1 → 6.4.4

raw patch · 11 files changed

+69/−41 lines, 11 files

Files

README.md view
@@ -4,7 +4,7 @@ Usage ----- -Cgrep 6.4.3 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.4.4 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.4.3.1+Version:             6.4.4 Synopsis:            Command line tool Homepage:            http://awgn.github.io/cgrep/ License:             GPL-2
src/CGrep/Output.hs view
@@ -59,10 +59,10 @@           _  -> (length prc, off - last prc - 1)  -mkOutput :: Options -> FilePath -> Text8 -> [Token] -> [Output]-mkOutput Options { invert_match = invert } f text ts-    | invert    = map (\(n, xs) -> Output f n (ls !! (n-1)) xs) . invertMatchLines (length ls) $ mkMatchLines text ts-    | otherwise = map (\(n, xs) -> Output f n (ls !! (n-1)) xs) $ mkMatchLines text ts+mkOutput :: Options -> FilePath -> Text8 -> Text8 -> [Token] -> [Output]+mkOutput Options { invert_match = invert } f text multi ts+    | invert    = map (\(n, xs) -> Output f n (ls !! (n-1)) xs) . invertMatchLines (length ls) $ mkMatchLines multi ts+    | otherwise = map (\(n, xs) -> Output f n (ls !! (n-1)) xs) $ mkMatchLines multi ts         where ls = C.lines text  
src/CGrep/Strategy/BoyerMoore.hs view
@@ -46,7 +46,7 @@      -- transform text -    let text' = expandMultiline opt . ignoreCase opt $ text+    let text' = ignoreCase opt text      -- quick search... @@ -57,26 +57,32 @@     putStrLevel1 (debug opt) $ "strategy  : running string search on " ++ filename ++ "..."      if maybe False not found-        then return $ mkOutput opt filename text []+        then return $ mkOutput opt filename text text []         else do -            let text'' = contextFilter (getLang opt filename) (mkContextFilter opt) text+            -- context filter +            let text''  = contextFilter (getLang opt filename) (mkContextFilter opt) text'++            -- expand multi-line++            let text''' = expandMultiline opt text''+             -- search for matching tokens -            let tokens  = map (A.second C.unpack) $ ps >>= (\p -> map (\i -> (i,p)) (p `SC.nonOverlappingIndices` text''))+            let tokens  = map (A.second C.unpack) $ ps >>= (\p -> map (\i -> (i,p)) (p `SC.nonOverlappingIndices` text'''))              -- filter exact matching tokens              let tokens' = if word_match opt || prefix_match opt || suffix_match opt-                            then filter (checkToken opt text'') tokens+                            then filter (checkToken opt text''') tokens                             else tokens              putStrLevel2 (debug opt) $ "tokens    : " ++ show tokens             putStrLevel2 (debug opt) $ "tokens'   : " ++ show tokens'-            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---"+            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" -            return $ mkOutput opt filename text tokens'+            return $ mkOutput opt filename text text''' tokens'   checkToken :: Options -> Text8 -> (Offset, String) -> Bool@@ -99,8 +105,4 @@ getLineByOffset :: Offset -> Text8 -> (Text8, Offset) getLineByOffset off xs = last $ takeWhile (\(_,o) -> o <= off) sl         where sl = splitLines xs---- 
src/CGrep/Strategy/Cpp/Semantic.hs view
@@ -48,7 +48,7 @@      -- transform text -    let text' = expandMultiline opt . ignoreCase opt $ text+    let text' = ignoreCase opt text      let filt  = (mkContextFilter opt) { getComment = False } @@ -79,14 +79,20 @@     putStrLevel2 (debug opt) $ "identif   : " ++ show ps'      if maybe False not found-        then return $ mkOutput opt filename text []+        then return $ mkOutput opt filename text text []         else do +            -- context filter+             let text'' = contextFilter (getLang opt filename) filt text' +            -- expand multi-line++            let text''' = expandMultiline opt text''+             -- parse source code, get the Cpp.Token list... -            let tokens = Cpp.tokenizer text''+            let tokens = Cpp.tokenizer text'''              -- get matching tokens ... @@ -96,9 +102,9 @@              putStrLevel2 (debug opt) $ "tokens    : " ++ show tokens'             putStrLevel2 (debug opt) $ "matches   : " ++ show matches-            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---"+            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" -            return $ mkOutput opt filename text matches+            return $ mkOutput opt filename text text''' matches   instance SemanticToken Cpp.Token where
src/CGrep/Strategy/Cpp/Tokenizer.hs view
@@ -42,7 +42,7 @@      -- transform text -    let text' = expandMultiline opt . ignoreCase opt $ text+    let text' = ignoreCase opt text      let filt  = (mkContextFilter opt) { getComment = False } @@ -53,14 +53,20 @@     let found = quickSearch opt ps text'      if maybe False not found-        then return $ mkOutput opt filename text []+        then return $ mkOutput opt filename text text []         else do +            -- context filter+             let text'' = contextFilter (getLang opt filename) filt text' +            -- expand multi-line++            let text''' = expandMultiline opt text''+             -- parse source code, get the Cpp.Token list... -            let tokens = Cpp.tokenizer text''+            let tokens = Cpp.tokenizer text'''              -- context-filterting... @@ -86,9 +92,9 @@             putStrLevel2 (debug opt) $ "tokens''  : " ++ show tokens''             putStrLevel2 (debug opt) $ "matches   : " ++ show matches -            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---"+            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" -            return $ mkOutput opt filename text matches+            return $ mkOutput opt filename text text''' matches   cppTokenFilter :: Options -> [String] -> [Cpp.Token] -> [Cpp.Token]
src/CGrep/Strategy/Generic/Semantic.hs view
@@ -48,7 +48,7 @@      -- transform text -    let text' = expandMultiline opt . ignoreCase opt $ text+    let text' = ignoreCase opt text      let filt  = (mkContextFilter opt) { getComment = False } @@ -78,14 +78,20 @@     let found = quickSearch opt ps' text'      if maybe False not found-        then return $ mkOutput opt filename text []+        then return $ mkOutput opt filename text text []         else do +            -- context filter+             let text'' = contextFilter (getLang opt filename) filt text' +            -- expand multi-line++            let text''' = expandMultiline opt text''+             -- parse source code, get the Generic.Token list... -            let tokens = Generic.tokenizer text''+            let tokens = Generic.tokenizer text'''              -- get matching tokens ... @@ -97,9 +103,9 @@             putStrLevel2 (debug opt) $ "tokens'   : " ++ show tokens'             putStrLevel2 (debug opt) $ "matches   : " ++ show matches -            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---"+            putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" -            return $ mkOutput opt filename text matches+            return $ mkOutput opt filename text text''' matches   wildCardMap :: M.Map String (WildCard a)
src/CGrep/Strategy/Levenshtein.hs view
@@ -39,11 +39,13 @@      -- transform text -    let text' = ignoreCase opt . expandMultiline opt . contextFilter (getLang opt filename) (mkContextFilter opt) $ text+    let text' = ignoreCase opt . contextFilter (getLang opt filename) (mkContextFilter opt) $ text +    let text'' = expandMultiline opt text'+     -- parse source code, get the Cpp.Token list... -    let tokens' = tokenizer text'+    let tokens' = tokenizer text''      -- filter tokens... @@ -55,7 +57,7 @@     putStrLevel2 (debug opt) $ "tokens'   : " ++ show tokens'     putStrLevel2 (debug opt) $ "matches   : " ++ show matches -    putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text' ++ "\n---"+    putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---" -    return $ mkOutput opt filename text matches+    return $ mkOutput opt filename text text'' matches 
src/CGrep/Strategy/Regex.hs view
@@ -49,14 +49,20 @@      putStrLevel1 (debug opt) $ "strategy  : running regex search on " ++ filename ++ "..." +    -- context filter+     let text'' = contextFilter (getLang opt filename) (mkContextFilter opt) text' +    -- expand multi-line++    let text''' = expandMultiline opt text''+     -- search for matching tokens -    let tokens = map (\(str, (off,_)) -> (off, C.unpack str) ) $  concatMap elems $ ps >>= (\p -> elems (getAllTextMatches $ text'' =~ p :: (Array Int) (MatchText Text8)) )+    let tokens = map (\(str, (off,_)) -> (off, C.unpack str) ) $  concatMap elems $ ps >>= (\p -> elems (getAllTextMatches $ text''' =~ p :: (Array Int) (MatchText Text8)) )      putStrLevel2 (debug opt) $ "tokens    : " ++ show tokens-    putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---"+    putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" -    return $ mkOutput opt filename text tokens+    return $ mkOutput opt filename text text''' tokens 
src/Config.hs view
@@ -31,7 +31,7 @@ cgreprc = "cgreprc"  version :: String-version = "6.4.3"+version = "6.4.4"  data Config = Config               {
src/Main.hs view
@@ -170,7 +170,7 @@                                         cgrepDispatch op f' op patterns $ guard (f' /= "") >> Just f'                             unless (null out) $ atomically $ writeTChan out_chan out                             action )-                    (\e -> let msg = show (e :: SomeException) in hPutStrLn stderr (showFile opts (fromMaybe "<STDIN>" f) ++ " -> " ++ if length msg > 80 then take 80 msg ++ "..." else msg) >> action )+                    (\e -> let msg = show (e :: SomeException) in hPutStrLn stderr (showFile opts (fromMaybe "<STDIN>" f) ++ ": exception: " ++ if length msg > 80 then take 80 msg ++ "..." else msg) >> action )             )