cgrep 6.5.4 → 6.5.5
raw patch · 8 files changed
+28/−20 lines, 8 files
Files
- README.md +2/−1
- cgrep.cabal +1/−1
- src/CmdOptions.hs +1/−0
- src/Config.hs +15/−12
- src/Debug.hs +1/−0
- src/Main.hs +3/−3
- src/Options.hs +1/−0
- src/Util.hs +4/−3
README.md view
@@ -4,7 +4,7 @@ Usage ----- -Cgrep 6.5.4 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.5.5 Usage: cgrep [OPTION] [PATTERN] files... cgrep [OPTIONS] [ITEM] @@ -52,6 +52,7 @@ --force-language=ITEM force the language --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 -v --invert-match select non-matching lines --max-count=INT stop search in files after INT matches
cgrep.cabal view
@@ -1,6 +1,6 @@ Name: cgrep Description: Cgrep: a context-aware grep for source codes-Version: 6.5.4+Version: 6.5.5 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2
src/CmdOptions.hs view
@@ -53,6 +53,7 @@ , count = False &= help "Print only a count of matching lines per file" &= explicit &= name "count" , multiline = 1 &= help "Enable multi-line matching" , recursive = False &= help "Enable recursive search (don't follow symlinks)" &= explicit &= name "recursive" &= name "r"+ , prune_dir = [] &= help "Do not descend into dir" &= explicit &= name "prune-dir" , deference_recursive = False &= help "Recursive, follow symlinks" &= explicit &= name "deference-recursive" &= name "R" , invert_match = False &= help "Select non-matching lines" &= explicit &= name "invert-match" &= name "v" , show_match = False &= help "Show list of matching tokens" &= explicit &= name "show-match"
src/Config.hs view
@@ -18,7 +18,9 @@ module Config where -import Data.Maybe+import Data.List+import Data.Char+ import Control.Monad import System.Directory import System.FilePath ((</>))@@ -31,7 +33,7 @@ cgreprc = "cgreprc" version :: String-version = "6.5.4"+version = "6.5.5" data Config = Config@@ -41,16 +43,17 @@ } deriving (Show, Read) -getConfig :: IO Config-getConfig = do- home <- getHomeDirectory- conf <- liftM msum $ forM [ home </> "." ++ cgreprc, "/etc" </> cgreprc ] $ \f ->- (doesFileExist >=> (\b -> return $ guard b >> Just f)) f - if isJust conf then readFile (fromJust conf) >>= \xs ->- return (prettyRead (dropComments xs) "Config error" :: Config)- else return $ Config [] [] False+dropComments :: String -> String+dropComments = unlines . filter notComment . lines+ where notComment = (not . ("#" `isPrefixOf`)) . dropWhile isSpace - where dropComments :: String -> String- dropComments = unlines . map (takeWhile $ not .(== '#')) . lines++getConfig :: IO Config+getConfig = do+ home <- getHomeDirectory+ confs <- filterM doesFileExist ["." ++ cgreprc, home </> "." ++ cgreprc, "/etc" </> cgreprc]+ if notNull confs then liftM dropComments (readFile (head confs)) >>= \xs ->+ return (prettyRead xs "Config error" :: Config)+ else return $ Config [] [] False
src/Debug.hs view
@@ -24,6 +24,7 @@ import Control.Monad import Options + putStrLevel1 :: String -> ReaderT Options IO () putStrLevel1 xs = do n <- reader debug
src/Main.hs view
@@ -82,10 +82,10 @@ -- process dirs -- forM_ dirs $ \path -> do- let filename = takeFileName path+ let dirname = takeFileName path lstatus <- getSymbolicLinkStatus path when ( deference_recursive opts || not (isSymbolicLink lstatus)) $- unless (filename `elem` prunedir) $ do -- this is a good directory (unless already visited)!+ unless (dirname `elem` prunedir) $ do -- this is a good directory (unless already visited)! cpath <- canonicalizePath path unless (cpath `Set.member` visited) $ withRecursiveContents opts path langs prunedir (Set.insert cpath visited) action else action [dir]@@ -139,7 +139,7 @@ _ <- liftIO . forkIO $ do if recursive opts || deference_recursive opts- then forM_ (if null paths then ["."] else paths) $ \p -> withRecursiveContents opts p langs (configPruneDirs conf) (Set.singleton p) (atomically . writeTChan in_chan)+ then forM_ (if null paths then ["."] else paths) $ \p -> withRecursiveContents opts p langs (configPruneDirs conf ++ prune_dir opts) (Set.singleton p) (atomically . writeTChan in_chan) else forM_ (if null paths && not isTermIn then [""] else paths) (atomically . writeTChan in_chan . (:[])) -- enqueue EOF messages:
src/Options.hs view
@@ -55,6 +55,7 @@ -- General: , multiline :: Int , recursive :: Bool+ , prune_dir :: [FilePath] , deference_recursive :: Bool , invert_match :: Bool , max_count :: Int
src/Util.hs view
@@ -28,6 +28,7 @@ -- from hlint :-) + partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) partitionM _ [] = return ([], []) partitionM f (x:xs) = do@@ -51,10 +52,9 @@ prettyRead :: Read a => String -> String -> a prettyRead xs err =- case value of+ case readMaybe xs of Just v -> v- _ -> error $ err ++ ": parse error near " ++ show(take 40 xs)- where value = readMaybe xs+ _ -> error $ err ++ ": parse error near " ++ show (take 40 xs) readMaybe :: Read a => String -> Maybe a@@ -69,6 +69,7 @@ toStrict :: LC.ByteString -> C.ByteString toStrict = C.concat . LC.toChunks+ toLowercase :: Char -> Char toLowercase x = ctypeLowercase ! x