cgrep 6.4.12 → 6.4.13
raw patch · 6 files changed
+49/−55 lines, 6 files
Files
- README.md +2/−2
- cgrep.cabal +1/−1
- src/CGrep/Common.hs +5/−10
- src/CmdOptions.hs +31/−31
- src/Config.hs +1/−1
- src/Main.hs +9/−10
README.md view
@@ -4,13 +4,13 @@ Usage ----- -Cgrep 6.4.12 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.4.13 Usage: cgrep [OPTION] [PATTERN] files... cgrep [OPTIONS] [ITEM] Pattern: - -f --file=FILE read PATTERNs from file+ -f --file=FILE read PATTERNs from file (one per line) -w --word force word matching -p --prefix force prefix matching -s --suffix force suffix matching
cgrep.cabal view
@@ -1,6 +1,6 @@ Name: cgrep Description: Cgrep: a context-aware grep for source codes-Version: 6.4.12+Version: 6.4.13 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2
src/CGrep/Common.hs view
@@ -26,6 +26,7 @@ ignoreCase, spanGroup, trim,+ trim8, unquotes) where import qualified Data.ByteString.Char8 as C@@ -82,16 +83,12 @@ spanGroup n xs = take n xs : spanGroup n (tail xs) -dropSpaceTail :: String -> String -> String-dropSpaceTail _ "" = ""-dropSpaceTail maybeStuff (x:xs)- | isSpace x = dropSpaceTail (x:maybeStuff) xs- | null maybeStuff = x : dropSpaceTail "" xs- | otherwise = reverse maybeStuff ++ x : dropSpaceTail "" xs+trim :: String -> String+trim = (dropWhile isSpace . reverse) . dropWhile isSpace . reverse -trim :: String -> String-trim xs = dropSpaceTail "" $ dropWhile isSpace xs+trim8 :: Text8 -> Text8+trim8 = (C.dropWhile isSpace . C.reverse) . C.dropWhile isSpace . C.reverse unquotes :: String -> String@@ -101,6 +98,4 @@ | x == '"' || x == '\'' = if x == last xs then init xs else y | otherwise = y--
src/CmdOptions.hs view
@@ -26,45 +26,45 @@ options :: Mode (CmdArgs Options) options = cmdArgsMode $ Options {- file = "" &= typ "FILE" &= help "Read PATTERNs from file" &= groupname "Pattern",- word_match = False &= help "Force word matching" &=explicit &= name "word" &= name "w",- prefix_match = False &= help "Force prefix matching" &=explicit &= name "prefix" &= name "p",- suffix_match = False &= help "Force suffix matching" &=explicit &= name "suffix" &= name "s",- edit_dist = False &= help "Use edit distance" &=explicit &= name "edit" &= name "e",- regex = False &= help "Use regex matching" &= explicit &= name "G" &=name "regex",- ignore_case = False &= help "Ignore case distinctions",+ file = "" &= typ "FILE" &= help "Read PATTERNs from file" &= groupname "Pattern",+ word_match = False &= help "Force word matching" &=explicit &= name "word" &= name "w",+ prefix_match = False &= help "Force prefix matching" &=explicit &= name "prefix" &= name "p",+ suffix_match = False &= help "Force suffix matching" &=explicit &= name "suffix" &= name "s",+ edit_dist = False &= help "Use edit distance" &=explicit &= name "edit" &= name "e",+ regex = False &= help "Use regex matching" &= explicit &= name "G" &=name "regex",+ ignore_case = False &= help "Ignore case distinctions", - code = False &= help "Enable search in source code" &= explicit &= name "c" &= name "code" &= groupname "\nContext filters (generic)",- comment = False &= help "Enable search in comments" &= explicit &= name "m" &= name "comment",- literal = False &= help "Enable search in string literals" &= explicit &= name "l" &= name "literal",+ code = False &= help "Enable search in source code" &= explicit &= name "c" &= name "code" &= groupname "\nContext filters (generic)",+ comment = False &= help "Enable search in comments" &= explicit &= name "m" &= name "comment",+ literal = False &= help "Enable search in string literals" &= explicit &= name "l" &= name "literal", - identifier = False &= help "Identifiers" &= explicit &= name "identifier" &= groupname "\nC/C++ language",- keyword = False &= help "Keywords" &= explicit &= name "keyword",- directive = False &= help "Preprocessing directives" &= explicit &= name "directive",- header = False &= help "Headers names" &= explicit &= name "header",- number = False &= help "Literal numbers" &= explicit &= name "number",- string = False &= help "Literal strings" &= explicit &= name "string",- char = False &= help "Literal chars" &= explicit &= name "char",- oper = False &= help "Operators" &= explicit &= name "oper",+ identifier = False &= help "Identifiers" &= explicit &= name "identifier" &= groupname "\nC/C++ language",+ keyword = False &= help "Keywords" &= explicit &= name "keyword",+ directive = False &= help "Preprocessing directives" &= explicit &= name "directive",+ header = False &= help "Headers names" &= explicit &= name "header",+ number = False &= help "Literal numbers" &= explicit &= name "number",+ string = False &= help "Literal strings" &= explicit &= name "string",+ char = False &= help "Literal chars" &= explicit &= name "char",+ oper = False &= help "Operators" &= explicit &= name "oper", - 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",+ 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 &= help "Suppress the file name prefix on output" &= explicit &= name "h" &= name "no-filename" &= groupname "\nOutput control",- 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",+ no_filename = False &= help "Suppress the file name prefix on output" &= explicit &= name "h" &= name "no-filename" &= groupname "\nOutput control",+ 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", - 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",+ 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", - jobs = 1 &= help "Number of jobs",- multiline = 1 &= help "Enable multi-line matching",+ jobs = 1 &= help "Number of jobs",+ multiline = 1 &= help "Enable multi-line matching", recursive = False &= help "Enable recursive search (don't follow symlinks)" &= explicit &= name "recursive" &= name "r", 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",- color = False &= help "Use colors to highlight the matching strings" &= explicit &= name "color",+ 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",+ color = False &= help "Use colors to highlight the matching strings" &= explicit &= name "color", format = Nothing &= typ "STRING" &= help "Format output. Var: #f #n #l #t ## #, #; #0 #1...\ne.g. \"#f:#n #0 #1\"" &= explicit &= name "format", #ifdef ENABLE_HINT
src/Config.hs view
@@ -31,7 +31,7 @@ cgreprc = "cgreprc" version :: String-version = "6.4.12"+version = "6.4.13" data Config = Config
src/Main.hs view
@@ -46,6 +46,7 @@ import CGrep.CGrep import CGrep.Lang import CGrep.Output+import CGrep.Common import CmdOptions import Options@@ -85,13 +86,12 @@ readPatternsFromFile :: FilePath -> IO [C.ByteString] readPatternsFromFile f = if null f then return []- else liftM C.words $ C.readFile f-+ else liftM (map trim8 . C.lines) $ C.readFile f main :: IO () main = do - -- check whether is a terminal device+ -- check whether this is a terminal device isTermIn <- hIsTerminalDevice stdin isTermOut <- hIsTerminalDevice stdout@@ -114,7 +114,8 @@ format opts, if xml opts then Just "" else Nothing, if json opts then Just "" else Nothing- ]) > 1) $ error "you can use one back-end at time!"+ ]) > 1)+ $ error "you can use one back-end at time!" -- display lang-map... @@ -126,12 +127,10 @@ -- load patterns: - patterns <- (if null $ file opts then return [C.pack $ head $ others opts]- else readPatternsFromFile $ file opts ) >>= \ps ->- return $ if ignore_case opts- then map (C.map toLower) ps- else ps+ patterns <- if null $ file opts then return [C.pack $ head $ others opts]+ else readPatternsFromFile $ file opts + let patternsLc = map (if ignore_case opts then C.map toLower else id) patterns -- retrieve files to parse @@ -170,7 +169,7 @@ Nothing -> atomically $ writeTChan out_chan [] Just x -> do out <- let op = sanitizeOptions x opts in- liftM (take (max_count opts)) $ cgrepDispatch op x op patterns $ guard (x /= "") >> f+ liftM (take (max_count opts)) $ cgrepDispatch op x op patternsLc $ guard (x /= "") >> f unless (null out) $ atomically $ writeTChan out_chan out ) (\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))