cgrep 6.5.10 → 6.5.11
raw patch · 11 files changed
+55/−35 lines, 11 filesdep +process
Dependencies added: process
Files
- README.md +9/−8
- cgrep.cabal +3/−2
- src/CGrep/CGrep.hs +1/−1
- src/CGrep/Lang.hs +1/−1
- src/CGrep/Output.hs +1/−1
- src/CGrep/Parser/WildCard.hs +1/−0
- src/CmdOptions.hs +4/−3
- src/Config.hs +1/−1
- src/Main.hs +30/−10
- src/Options.hs +4/−3
- src/Util.hs +0/−5
README.md view
@@ -4,7 +4,7 @@ Usage ----- -Cgrep 6.5.10 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.5.11 Usage: cgrep [OPTION] [PATTERN] files... cgrep [OPTIONS] [ITEM] @@ -45,13 +45,14 @@ --oper operators Output control:-- -h --no-filename suppress the file name prefix on output- -N --no-line-umber suppress the line number on output lines- --lang=ITEM specify languages. ie: Cpp, +Haskell, -Makefile- --lang-maps lists the language mappings- --force-language=ITEM force the language- --multiline=INT enable multi-line matching+ + -h --no-filename Suppress the file name prefix on output+ -N --no-line-umber Suppress the line number on output lines+ --language-filter=ITEM Specify languages. ie: Cpp, +Haskell, -Makefile+ --language-force=ITEM Force the language+ --language-map Lists the language mappings+ --magic-filter=ITEM Use unix magic as file-filter+ --multiline=INT Enable multi-line matching -r --recursive Enable recursive search (don't follow symlinks) --prune-dir=ITEM Do not descend into dir -R --deference-recursive Recursive, follow symlinks
cgrep.cabal view
@@ -1,6 +1,6 @@ Name: cgrep Description: Cgrep: a context-aware grep for source codes-Version: 6.5.10+Version: 6.5.11 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2@@ -48,6 +48,7 @@ mtl >= 2.0, unix-compat >= 0.4, async >= 2.0,- transformers+ transformers,+ process Ghc-options: -O2 -Wall -threaded -rtsopts -with-rtsopts=-N Default-language: Haskell2010
src/CGrep/CGrep.hs view
@@ -16,7 +16,7 @@ -- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- -module CGrep.CGrep (sanitizeOptions, runCgrep) where+module CGrep.CGrep (sanitizeOptions, runCgrep, isRegexp) where import qualified CGrep.Strategy.BoyerMoore as BoyerMoore import qualified CGrep.Strategy.Levenshtein as Levenshtein
src/CGrep/Lang.hs view
@@ -100,7 +100,7 @@ forcedLang :: Options -> Maybe Lang-forcedLang Options{ force_language = l }+forcedLang Options{ language_force = l } | Nothing <- l = Nothing | otherwise = Map.lookup (Ext $ fromJust l) langRevMap <|> Map.lookup (Name $ fromJust l) langRevMap
src/CGrep/Output.hs view
@@ -243,5 +243,5 @@ (next, rest) = splitAt nn s hilightIndicies :: [Token] -> [(Int, Int)]-hilightIndicies = foldr (\t a -> let b = fst t in (b, b + length (snd t) - 1) : a) [] . filter ((>0) . length . snd)+hilightIndicies = foldr (\t a -> let b = fst t in (b, b + length (snd t) - 1) : a) [] . filter (not . null . snd)
src/CGrep/Parser/WildCard.hs view
@@ -20,6 +20,7 @@ mkWildCardFromToken, combineMultiCard, filterTokensWithMultiCards,+ wildCardMap, wildCardMatch, multiCardMatch) where
src/CmdOptions.hs view
@@ -47,9 +47,10 @@ , semantic = False &= groupname "\nSemantic (generic)" &= help "\"code\" pattern: _, _1, _2... (identifiers), $, $1, $2... (optionals), ANY, KEY, STR, CHR, LIT, NUM, HEX, OCT, OR. -> e.g. \"_1(_1 && \\$)\" search for move constructors, \"struct OR class _ { OR : OR <\" search for a class declaration" &= explicit &= name "S" &= name "semantic" , no_filename = False &= groupname "\nOutput control"&= help "Suppress the file name prefix on output" &= explicit &= name "h" &= name "no-filename" , no_linenumber= False &= help "Suppress the line number on output lines" &= explicit &= name "N" &= name "no-line-umber"- , lang = [] &= help "Specify languages. ie: Cpp, +Haskell, -Makefile"- , lang_maps = False &= help "Lists the language mappings"- , force_language = Nothing &= help "Force the language" &= explicit &= name "force-language"+ , language_filter = [] &= help "Specify languages. ie: Cpp, +Haskell, -Makefile"+ , language_force = Nothing &= help "Force the language" &= explicit &= name "language-force"+ , language_map = False &= help "Lists the language mappings"+ , magic_filter = [] &= help "Use unix magic as file-filter" , max_count = maxBound &= help "Stop search in files after INT matches" &= explicit &= name "max-count" , count = False &= help "Print only a count of matching lines per file" &= explicit &= name "count" , multiline = 1 &= help "Enable multi-line matching"
src/Config.hs view
@@ -33,7 +33,7 @@ cgreprc = "cgreprc" version :: String-version = "6.5.10"+version = "6.5.11" data Config = Config
src/Main.hs view
@@ -20,6 +20,7 @@ import Data.List import Data.List.Split+import qualified Data.Map as M import Data.Maybe import Data.Char import Data.Data()@@ -45,11 +46,13 @@ import System.PosixCompat.Files import System.IO import System.Exit+import System.Process (readProcess) import CGrep.CGrep import CGrep.Lang import CGrep.Output import CGrep.Common+import CGrep.Parser.WildCard import CmdOptions import Options@@ -60,6 +63,14 @@ import qualified Data.ByteString.Char8 as C +fileFilter :: Options -> [Lang] -> FilePath -> Bool+fileFilter opts langs filename = maybe False (`elem` langs) (getFileLang opts filename)+++getFilesMagic :: [FilePath] -> IO [String]+getFilesMagic filenames = fmap lines $ readProcess "/usr/bin/file" (["-b" ] ++ filenames) []++ -- push file names in Chan... withRecursiveContents :: Options -> FilePath -> [Lang] -> [String] -> Set.Set FilePath -> ([FilePath] -> IO ()) -> IO ()@@ -67,14 +78,20 @@ isDir <- doesDirectoryExist dir if isDir then do xs <- getDirectoryContents dir+ (dirs,files) <- partitionM doesDirectoryExist [dir </> x | x <- xs, x `notElem` [".", ".."]]- -- process files- let files' = mapMaybe- (\n -> let filename = takeFileName n- in if isNothing $ getFileLang opts filename >>= (\f -> f `elemIndex` langs <|> toMaybe 0 (null langs))- then Nothing- else Just n) files + magics <- if null (magic_filter opts) || null files+ then return []+ else getFilesMagic files++ -- filter the list of files+ --+ let files' = if null magics+ then filter (fileFilter opts langs) files+ else catMaybes $ zipWith (\f m -> if any (`isInfixOf` m) (magic_filter opts) then Just f else Nothing ) files magics++ unless (null files') $ let chunks = chunksOf (Options.chunk opts) files' in forM_ chunks $ \b -> action b@@ -200,7 +217,7 @@ -- display lang-map and exit... - when (lang_maps opts) $ dumpLangMap langMap >> exitSuccess+ when (language_map opts) $ dumpLangMap langMap >> exitSuccess -- check whether patterns list is empty, display help message if it's the case @@ -211,7 +228,10 @@ patterns <- if null (file opts) then return $ (if isTermIn then (:[]) . head else id) $ map C.pack (others opts) else readPatternsFromFile $ file opts - let patterns' = map (if ignore_case opts then C.map toLower else id) patterns+ let patterns' = map (if ignore_case opts then ic else id) patterns+ where ic | (not . isRegexp) opts && semantic opts = C.unwords . map (\p -> if C.unpack p `elem` wildCardTokens then p else C.map toLower p) . C.words+ | otherwise = C.map toLower+ where wildCardTokens = "OR" : M.keys wildCardMap -- "OR" is not included in wildCardMap -- load files to parse: @@ -219,7 +239,7 @@ -- parse cmd line language list: - let (l0, l1, l2) = splitLangList (lang opts)+ let (l0, l1, l2) = splitLangList (language_filter opts) -- language enabled: @@ -228,7 +248,7 @@ runReaderT (do putStrLevel1 $ "Cgrep " ++ version ++ "!" putStrLevel1 $ "options : " ++ show opts putStrLevel1 $ "languages : " ++ show langs- putStrLevel1 $ "pattern : " ++ show patterns+ putStrLevel1 $ "pattern : " ++ show patterns' putStrLevel1 $ "files : " ++ show paths putStrLevel1 $ "isTermIn : " ++ show isTermIn putStrLevel1 $ "isTermOut : " ++ show isTermOut
src/Options.hs view
@@ -50,9 +50,10 @@ -- Output: , no_filename :: Bool , no_linenumber :: Bool- , lang :: [String]- , lang_maps :: Bool- , force_language :: Maybe String+ , language_filter :: [String]+ , language_force :: Maybe String+ , language_map :: Bool+ , magic_filter :: [String] -- General: , multiline :: Int , recursive :: Bool
src/Util.hs view
@@ -37,11 +37,6 @@ return ([x | res]++as, [x | not res]++bs) -toMaybe :: a -> Bool -> Maybe a-toMaybe a True = Just a-toMaybe _ False = Nothing-- notNull :: [a] -> Bool notNull = not . null