Changeset 5480


Ignore:
Timestamp:
May 29, 2017, 11:01:22 AM (2 years ago)
Author:
cameron
Message:

Recognize all standard Posix and GNU grep flags; support in progress

Location:
icGREP/icgrep-devel/icgrep
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_interface.cpp

    r5477 r5480  
    3939
    4040bool IgnoreCaseFlag;
    41 static cl::opt<bool, true> IgnoreCase("i", cl::location(IgnoreCaseFlag), cl::desc("Ignore case distinctions in the pattern and the file."), cl::cat(RE_Options), cl::Grouping);
    42 static cl::alias IgnoreCaseAlias("ignore-case", cl::desc("Alias for -i"), cl::aliasopt(IgnoreCase));
     41static cl::opt<bool, true> IgnoreCaseOption("i", cl::location(IgnoreCaseFlag), cl::desc("Ignore case distinctions in the pattern and the file."), cl::cat(RE_Options), cl::Grouping);
     42static cl::alias IgnoreCaseAlias("ignore-case", cl::desc("Alias for -i"), cl::aliasopt(IgnoreCaseOption));
    4343
    4444bool InvertMatchFlag;
    45 static cl::opt<bool, true> InvertMatch("v", cl::location(InvertMatchFlag), cl::desc("Invert match results: select non-matching lines."), cl::cat(RE_Options), cl::Grouping);
    46 static cl::alias InvertMatchAlias("invert-match", cl::desc("Alias for -v"), cl::aliasopt(InvertMatch));
     45static cl::opt<bool, true> InvertMatchOption("v", cl::location(InvertMatchFlag), cl::desc("Invert match results: select non-matching lines."), cl::cat(RE_Options), cl::Grouping);
     46static cl::alias InvertMatchAlias("invert-match", cl::desc("Alias for -v"), cl::aliasopt(InvertMatchOption));
    4747
    4848bool LineRegexpFlag;
    49 static cl::opt<bool, true> LineRegexp("x", cl::location(LineRegexpFlag), cl::desc("Require that entire lines be matched."), cl::cat(RE_Options), cl::Grouping);
    50 static cl::alias LineRegexpAlias("line-regexp", cl::desc("Alias for -x"), cl::aliasopt(LineRegexp));
     49static cl::opt<bool, true> LineRegexpOption("x", cl::location(LineRegexpFlag), cl::desc("Require that entire lines be matched."), cl::cat(RE_Options), cl::Grouping);
     50static cl::alias LineRegexpAlias("line-regexp", cl::desc("Alias for -x"), cl::aliasopt(LineRegexpOption));
    5151
    5252bool WordRegexpFlag;
    53 static cl::opt<bool, true> WordRegexp("w", cl::location(WordRegexpFlag), cl::desc("Require that that whole words be matched."), cl::cat(RE_Options), cl::Grouping);
    54 static cl::alias WordRegexpAlias("word-regexp", cl::desc("Alias for -w"), cl::aliasopt(WordRegexp));
    55    
    56    
    57 const cl::OptionCategory * grep_regexp_flags() {
    58     return &RE_Options;
    59 }
    60 
     53static cl::opt<bool, true> WordRegexpOption("w", cl::location(WordRegexpFlag), cl::desc("Require that that whole words be matched."), cl::cat(RE_Options), cl::Grouping);
     54static cl::alias WordRegexpAlias("word-regexp", cl::desc("Alias for -w"), cl::aliasopt(WordRegexpOption));
     55
     56std::vector<std::string> RegexpVector;
     57static cl::list<std::string, std::vector<std::string>> RegexpOption("e", cl::location(RegexpVector), cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(RE_Options), cl::Grouping);
     58static cl::alias RegexpAlias("regexp", cl::desc("Alias for -e"), cl::aliasopt(RegexpOption));
     59
     60std::string FileFlag;
     61static cl::opt<std::string, true> FileOption("f", cl::location(FileFlag), cl::desc("Take regular expressions (one per line) from a file."), cl::cat(RE_Options), cl::Grouping);
     62static cl::alias FileAlias("file", cl::desc("Alias for -f"), cl::aliasopt(FileOption));
     63   
    6164/*
    6265 *  B.  Grep input sources and interpretation.
     
    6669
    6770bool RecursiveFlag;
    68 static cl::opt<bool, true> Recursive("r", cl::location(RecursiveFlag), cl::desc("Recursively process files within directories, (but follow only top-level symlinks unless -R)."), cl::cat(Input_Options), cl::Grouping);
    69 static cl::alias RecursiveAlias("recursive", cl::desc("Alias for -r"), cl::aliasopt(Recursive));
     71static cl::opt<bool, true> RecursiveOption("r", cl::location(RecursiveFlag), cl::desc("Recursively process files within directories, (but follow only top-level symlinks unless -R)."), cl::cat(Input_Options), cl::Grouping);
     72static cl::alias RecursiveAlias("recursive", cl::desc("Alias for -r"), cl::aliasopt(RecursiveOption));
    7073
    7174bool DereferenceRecursiveFlag;
    72 static cl::opt<bool, true> DereferenceRecursive("R", cl::location(DereferenceRecursiveFlag), cl::desc("Recursively process files within directories, following symlinks at all levels."), cl::cat(Input_Options), cl::Grouping);
    73 static cl::alias DereferenceRecursiveAlias("dereference-recursive", cl::desc("Alias for -R"), cl::aliasopt(DereferenceRecursive));
     75static cl::opt<bool, true> DereferenceRecursiveOption("R", cl::location(DereferenceRecursiveFlag), cl::desc("Recursively process files within directories, following symlinks at all levels."), cl::cat(Input_Options), cl::Grouping);
     76static cl::alias DereferenceRecursiveAlias("dereference-recursive", cl::desc("Alias for -R"), cl::aliasopt(DereferenceRecursiveOption));
    7477
    7578bool TextFlag;
    76 static cl::opt<bool, true> Text("a", cl::location(TextFlag), cl::desc("Treat each input file as text, even if it is a binary file."), cl::cat(Input_Options), cl::Grouping);
    77 static cl::alias TextAlias("text", cl::desc("Alias for -a"), cl::aliasopt(Text));
     79static cl::opt<bool, true> TextOption("a", cl::location(TextFlag), cl::desc("Treat each input file as text, even if it is a binary file."), cl::cat(Input_Options), cl::Grouping);
     80static cl::alias TextAlias("text", cl::desc("Alias for -a"), cl::aliasopt(TextOption));
     81
     82bool BinaryNonMatchingFlag;
     83static cl::opt<bool, true> BinaryNonMatchingOption("I", cl::location(BinaryNonMatchingFlag), cl::desc("Treat binary files as non-matching."), cl::cat(Input_Options), cl::Grouping);
     84static cl::alias BinaryNonMatchingAlias("binary-non-matching", cl::desc("Alias for -I"), cl::aliasopt(BinaryNonMatchingOption));
    7885
    7986bool BinaryFlag;
    80 static cl::opt<bool, true> Binary("U", cl::location(BinaryFlag), cl::desc("Treat each input file as a binary file, without CRLF normalization."), cl::cat(Input_Options), cl::Grouping);
    81 static cl::alias BinaryAlias("binary", cl::desc("Alias for -U"), cl::aliasopt(Binary));
     87static cl::opt<bool, true> BinaryOption("U", cl::location(BinaryFlag), cl::desc("Treat each input file as a binary file, without CRLF normalization."), cl::cat(Input_Options), cl::Grouping);
     88static cl::alias BinaryAlias("binary", cl::desc("Alias for -U"), cl::aliasopt(BinaryOption));
    8289
    8390bool NullDataFlag;
    84 static cl::opt<bool, true> NullData("z", cl::location(NullDataFlag), cl::desc("Use the NUL character (codepoint 00) as the line-break character for input."), cl::cat(Input_Options), cl::Grouping);
    85 static cl::alias NullDataAlias("null-data", cl::desc("Alias for -z"), cl::aliasopt(NullData));
     91static cl::opt<bool, true> NullDataOption("z", cl::location(NullDataFlag), cl::desc("Use the NUL character (codepoint 00) as the line-break character for input."), cl::cat(Input_Options), cl::Grouping);
     92static cl::alias NullDataAlias("null-data", cl::desc("Alias for -z"), cl::aliasopt(NullDataOption));
    8693
    8794bool MmapFlag;
    88 static cl::opt<bool, true> Mmap("mmap", cl::location(MmapFlag), cl::desc("Use mmap for file input."), cl::cat(Input_Options));
    89    
    90    
    91 
     95static cl::opt<bool, true> MmapOption("mmap", cl::location(MmapFlag), cl::desc("Use mmap for file input."), cl::cat(Input_Options));
     96
     97std::string ExcludeFlag;
     98static cl::opt<std::string, true> ExcludeOption("exclude", cl::location(ExcludeFlag), cl::desc("Exclude files matching the given filename GLOB pattern."), cl::cat(Input_Options));
     99
     100std::string ExcludeFromFlag;
     101static cl::opt<std::string, true> ExcludeFromOption("exclude-from", cl::location(ExcludeFromFlag), cl::desc("Exclude files matching filename GLOB patterns from the given file."), cl::cat(Input_Options));
     102
     103std::string ExcludeDirFlag;
     104static cl::opt<std::string, true> ExcludeDirOption("exclude-dir", cl::location(ExcludeDirFlag), cl::desc("Exclude directories matching the given pattern."), cl::cat(Input_Options));
     105
     106std::string IncludeFlag;
     107static cl::opt<std::string, true> IncludeOption("include", cl::location(IncludeFlag), cl::desc("Include only files matching the given filename GLOB pattern."), cl::cat(Input_Options));
     108
     109DevDirAction DevicesFlag;
     110static cl::opt<DevDirAction, true> DevicesOption("D", cl::desc("Processing mode for devices:"),
     111                                                 cl::values(clEnumValN(Read, "read", "Treat devices as files to be searched."),
     112                                                            clEnumValN(Skip, "skip", "Silently skip devices."),
     113                                                            clEnumValEnd), cl::cat(Input_Options), cl::location(DevicesFlag), cl::init(Read));
     114static cl::alias DevicesAlias("devices", cl::desc("Alias for -D"), cl::aliasopt(DevicesOption));
     115
     116DevDirAction DirectoriesFlag;
     117static cl::opt<DevDirAction, true> DirectoriesOption("d", cl::desc("Processing mode for directories:"),
     118                                                     cl::values(clEnumValN(Read, "read", "Print an error message for any listed directories."),
     119                                                                clEnumValN(Skip, "skip", "Silently skip directories."),
     120                                                                clEnumValN(Recurse, "recurse", "Recursive process directories, equivalent to -r."),
     121                                                                clEnumValEnd), cl::cat(Input_Options), cl::location(DirectoriesFlag), cl::init(Read));
     122static cl::alias DirectoriesAlias("directories", cl::desc("Alias for -d"), cl::aliasopt(DirectoriesOption));
     123
     124BinaryFilesMode BinaryFilesFlag;
     125static cl::opt<BinaryFilesMode, true> BinaryFilesOption("binary-files", cl::desc("Processing mode for binary files:"),
     126                                                     cl::values(clEnumValN(Binary, "binary", "Report match/non-match without printing matches."),
     127                                                                clEnumValN(WithoutMatch, "without-match", "Always report as non-matching."),
     128                                                                clEnumValN(Text, "text", "Treat binary files as text."),
     129                                                                clEnumValEnd), cl::cat(Input_Options), cl::location(BinaryFilesFlag), cl::init(Binary));
     130   
    92131/*
    93132 *  C.  Grep output modes and options.
     
    113152
    114153bool NoMessagesFlag;
    115 static cl::opt<bool, true> NoMessages("s", cl::location(NoMessagesFlag), cl::desc("Suppress messages for file errors."), cl::cat(Output_Options), cl::Grouping);
    116 static cl::alias NoMessagesAlias("no-messages", cl::desc("Alias for -s"), cl::aliasopt(NoMessages));
     154static cl::opt<bool, true> NoMessagesOption("s", cl::location(NoMessagesFlag), cl::desc("Suppress messages for file errors."), cl::cat(Output_Options), cl::Grouping);
     155static cl::alias NoMessagesAlias("no-messages", cl::desc("Alias for -s"), cl::aliasopt(NoMessagesOption));
    117156
    118157bool WithFilenameFlag;
    119 static cl::opt<bool, true> WithFilename("H", cl::location(WithFilenameFlag), cl::desc("Show the file name with each matching line."), cl::cat(Output_Options), cl::Grouping);
    120 static cl::alias WithFilenameAlias("with-filename", cl::desc("Alias for -H"), cl::aliasopt(WithFilename));
     158static cl::opt<bool, true> WithFilenameOption("H", cl::location(WithFilenameFlag), cl::desc("Show the file name with each matching line."), cl::cat(Output_Options), cl::Grouping);
     159static cl::alias WithFilenameAlias("with-filename", cl::desc("Alias for -H"), cl::aliasopt(WithFilenameOption));
    121160
    122161bool NoFilenameFlag;
    123 static cl::opt<bool, true> NoFilename("h", cl::location(NoFilenameFlag), cl::desc("Do not show filenames with maches."), cl::cat(Output_Options), cl::Grouping);
    124 static cl::alias NoFilenameAlias("no-filename", cl::desc("Alias for -h"), cl::aliasopt(NoFilename));
     162static cl::opt<bool, true> NoFilenameOption("h", cl::location(NoFilenameFlag), cl::desc("Do not show filenames with maches."), cl::cat(Output_Options), cl::Grouping);
     163static cl::alias NoFilenameAlias("no-filename", cl::desc("Alias for -h"), cl::aliasopt(NoFilenameOption));
    125164
    126165bool NullFlag;
    127 static cl::opt<bool, true> Null("Z", cl::location(NullFlag), cl::desc("Write NUL characters after filenames generated to output."), cl::cat(Output_Options), cl::Grouping);
    128 static cl::alias NullAlias("null", cl::desc("Alias for -Z"), cl::aliasopt(Null));
     166static cl::opt<bool, true> NullOption("Z", cl::location(NullFlag), cl::desc("Write NUL characters after filenames generated to output."), cl::cat(Output_Options), cl::Grouping);
     167static cl::alias NullAlias("null", cl::desc("Alias for -Z"), cl::aliasopt(NullOption));
    129168
    130169bool LineNumberFlag;
    131 static cl::opt<bool, true> LineNumber("n", cl::location(LineNumberFlag), cl::desc("Show the line number with each matching line."), cl::cat(Output_Options), cl::Grouping);
    132 static cl::alias LineNumberAlias("line-number", cl::desc("Alias for -n"), cl::aliasopt(LineNumber));
     170static cl::opt<bool, true> LineNumberOption("n", cl::location(LineNumberFlag), cl::desc("Show the line number with each matching line."), cl::cat(Output_Options), cl::Grouping);
     171static cl::alias LineNumberAlias("line-number", cl::desc("Alias for -n"), cl::aliasopt(LineNumberOption));
    133172
    134173bool ByteOffsetFlag;
    135 static cl::opt<bool, true> ByteOffset("b", cl::location(ByteOffsetFlag), cl::desc("Show the byte offset within the file for each matching line."), cl::cat(Output_Options), cl::Grouping);
    136 static cl::alias ByteOffsetAlias("byte-offset", cl::desc("Alias for -b"), cl::aliasopt(ByteOffset));
     174static cl::opt<bool, true> ByteOffsetOption("b", cl::location(ByteOffsetFlag), cl::desc("Show the byte offset within the file for each matching line."), cl::cat(Output_Options), cl::Grouping);
     175static cl::alias ByteOffsetAlias("byte-offset", cl::desc("Alias for -b"), cl::aliasopt(ByteOffsetOption));
    137176
    138177bool UnixByteOffsetsFlag;
    139 static cl::opt<bool, true> UnixByteOffsets("u", cl::location(UnixByteOffsetsFlag), cl::desc("If byte offsets are displayed, report offsets as if all lines are terminated with a single LF."), cl::cat(Output_Options), cl::Grouping);
    140 static cl::alias UnixByteOffsetsAlias("unix-byte-offsets", cl::desc("Alias for -u"), cl::aliasopt(UnixByteOffsets));
     178static cl::opt<bool, true> UnixByteOffsetsOption("u", cl::location(UnixByteOffsetsFlag), cl::desc("If byte offsets are displayed, report offsets as if all lines are terminated with a single LF."), cl::cat(Output_Options), cl::Grouping);
     179static cl::alias UnixByteOffsetsAlias("unix-byte-offsets", cl::desc("Alias for -u"), cl::aliasopt(UnixByteOffsetsOption));
    141180
    142181bool InitialTabFlag;
    143 static cl::opt<bool, true> InitialTab("T", cl::location(InitialTabFlag), cl::desc("Line up matched line content using an inital tab character."), cl::cat(Output_Options), cl::Grouping);
    144 static cl::alias InitialTabAlias("initial-tab", cl::desc("Alias for -T"), cl::aliasopt(InitialTab));
     182static cl::opt<bool, true> InitialTabOption("T", cl::location(InitialTabFlag), cl::desc("Line up matched line content using an inital tab character."), cl::cat(Output_Options), cl::Grouping);
     183static cl::alias InitialTabAlias("initial-tab", cl::desc("Alias for -T"), cl::aliasopt(InitialTabOption));
    145184
    146185bool OnlyMatchingFlag;
    147 static cl::opt<bool, true> OnlyMatching("o", cl::location(OnlyMatchingFlag), cl::desc("Display only the exact strings that match the pattern, with possibly multiple matches per line."), cl::cat(Output_Options), cl::Grouping);
    148 static cl::alias OnlyMatchingAlias("only-matching", cl::desc("Alias for -o"), cl::aliasopt(OnlyMatching));
     186static cl::opt<bool, true> OnlyMatchingOption("o", cl::location(OnlyMatchingFlag), cl::desc("Display only the exact strings that match the pattern, with possibly multiple matches per line."), cl::cat(Output_Options), cl::Grouping);
     187static cl::alias OnlyMatchingAlias("only-matching", cl::desc("Alias for -o"), cl::aliasopt(OnlyMatchingOption));
     188
     189std::string LabelFlag;
     190static cl::opt<std::string, true> LabelOption("label", cl::location(LabelFlag), cl::desc("Set a label for input lines matched from stdin."), cl::cat(Output_Options));
    149191
    150192bool LineBufferedFlag;
    151 static cl::opt<bool, true> LineBuffered("line-buffered", cl::location(LineBufferedFlag), cl::desc("Buffer lines to output."), cl::cat(Output_Options));
     193static cl::opt<bool, true> LineBufferedOption("line-buffered", cl::location(LineBufferedFlag), cl::desc("Buffer lines to output."), cl::cat(Output_Options));
    152194
    153195bool NormalizeLineBreaksFlag;
    154 static cl::opt<bool, true> NormalizeLineBreaks("normalize-line-breaks", cl::location(NormalizeLineBreaksFlag), cl::desc("Normalize line breaks to LF."), cl::cat(Output_Options));
     196static cl::opt<bool, true> NormalizeLineBreaksOption("normalize-line-breaks", cl::location(NormalizeLineBreaksFlag), cl::desc("Normalize line breaks to LF."), cl::cat(Output_Options));
    155197
    156198int AfterContextFlag;
    157 static cl::opt<int, true> AfterContext("A", cl::location(AfterContextFlag), cl::desc("Print <num> lines of context after each matching line."), cl::cat(Output_Options), cl::Grouping, cl::Prefix);
    158 static cl::alias AfterContextAlias("after-context", cl::desc("Alias for -A"), cl::aliasopt(AfterContext));
     199static cl::opt<int, true> AfterContextOption("A", cl::location(AfterContextFlag), cl::desc("Print <num> lines of context after each matching line."), cl::cat(Output_Options), cl::Grouping);
     200static cl::alias AfterContextAlias("after-context", cl::desc("Alias for -A"), cl::aliasopt(AfterContextOption));
    159201
    160202int BeforeContextFlag;
    161 static cl::opt<int, true> BeforeContext("B", cl::location(BeforeContextFlag), cl::desc("Print <num>lines of context before each matching line."), cl::cat(Output_Options), cl::Grouping, cl::Prefix);
    162 static cl::alias BeforeContextAlias("before-context", cl::desc("Alias for -B"), cl::aliasopt(BeforeContext));
     203static cl::opt<int, true> BeforeContextOption("B", cl::location(BeforeContextFlag), cl::desc("Print <num>lines of context before each matching line."), cl::cat(Output_Options), cl::Grouping);
     204static cl::alias BeforeContextAlias("before-context", cl::desc("Alias for -B"), cl::aliasopt(BeforeContextOption));
    163205
    164206int ContextFlag;
    165 static cl::opt<int, true> Context("C", cl::location(ContextFlag), cl::desc("Print <num> lines of context before and after each matching line."), cl::cat(Output_Options), cl::Grouping, cl::Prefix);
    166 static cl::alias ContextAlias("context", cl::desc("Alias for -C"), cl::aliasopt(Context));
     207static cl::opt<int, true> ContextOption("C", cl::location(ContextFlag), cl::desc("Print <num> lines of context before and after each matching line."), cl::cat(Output_Options), cl::Grouping);
     208static cl::alias ContextAlias("context", cl::desc("Alias for -C"), cl::aliasopt(ContextOption));
    167209
    168210int MaxCountFlag;
    169 static cl::opt<int, true> MaxCount("m", cl::location(MaxCountFlag), cl::desc("Process only the first <num> matches per file."), cl::cat(Output_Options), cl::Grouping, cl::Prefix);
    170 static cl::alias MaxCountAlias("max-count", cl::desc("Alias for -m"), cl::aliasopt(MaxCount));
    171    
    172 std::string LabelFlag;
    173 static cl::opt<std::string, true> Label("label", cl::location(LabelFlag), cl::desc("Set a label for input lines matched from stdin."), cl::cat(Output_Options));
     211static cl::opt<int, true> MaxCountOption("m", cl::location(MaxCountFlag), cl::desc("Process only the first <num> matches per file."), cl::cat(Output_Options), cl::Grouping);
     212static cl::alias MaxCountAlias("max-count", cl::desc("Alias for -m"), cl::aliasopt(MaxCountOption));
    174213   
    175214ColoringType ColorFlag;
     
    210249#endif
    211250    cl::ParseCommandLineOptions(argc, argv);
     251    if (RecursiveFlag || DereferenceRecursiveFlag) {
     252        DirectoriesFlag = Recurse;
     253    }
     254   
    212255    if (RegexpSyntax == re::RE_Syntax::FixedStrings) {
    213256        llvm::report_fatal_error("Sorry, FixedStrings syntax is not fully supported.\n");
    214257    }
    215258    if (TextFlag) {
    216         llvm::report_fatal_error("Sorry, -a is not yet supported.\n");
     259        if (BinaryNonMatchingFlag || (BinaryFilesFlag == WithoutMatch)) {
     260            llvm::report_fatal_error("Conflicting options for binary files.\n");
     261        }
     262        BinaryFilesFlag = Text;
     263    }
     264    if (BinaryNonMatchingFlag) {
     265        if (BinaryFilesFlag == Text) {
     266            llvm::report_fatal_error("Conflicting options for binary files.\n");
     267        }
     268        BinaryFilesFlag = WithoutMatch;
    217269    }
    218270    if (BinaryFlag) {
     
    222274        llvm::report_fatal_error("Sorry, -z is not yet supported.\n");
    223275    }
     276    if (ExcludeFlag!="") {
     277        llvm::report_fatal_error("Sorry, -exclude is not yet supported.\n");
     278    }
     279    if (ExcludeFromFlag!="") {
     280        llvm::report_fatal_error("Sorry, -exclude-from is not yet supported.\n");
     281    }
     282    if (ExcludeDirFlag!="") {
     283        llvm::report_fatal_error("Sorry, -exclude-dir is not yet supported.\n");
     284    }
     285    if (IncludeFlag!="") {
     286        llvm::report_fatal_error("Sorry, -include is not yet supported.\n");
     287    }   
    224288    if (NoMessagesFlag) {
    225289        llvm::report_fatal_error("Sorry, -s is not yet supported.\n");
  • icGREP/icgrep-devel/icgrep/grep_interface.h

    r5477 r5480  
    3737extern bool LineRegexpFlag; // -x
    3838extern bool WordRegexpFlag; // -w
    39    
     39extern std::vector<std::string> RegexpVector; // -e
     40extern std::string FileFlag; // -f
     41
    4042/*
    4143 *  B.  Grep input sources and interpretation.
    4244 */
    43    
    44    
    45 // Grep input source control corresponding to -r, -R flags.
    46 extern bool RecursiveFlag; // -r
     45
     46// Use DirectoriesFlag==Recurse to test for recursive mode.
     47//extern bool RecursiveFlag;
    4748extern bool DereferenceRecursiveFlag; // -R
    4849extern bool TextFlag; // -a
     
    5051extern bool NullDataFlag; // -z
    5152extern bool MmapFlag; // -mmap
    52    
     53extern std::string ExcludeFlag; // -exclude
     54extern std::string ExcludeFromFlag; // -exclude-from
     55extern std::string ExcludeDirFlag; // -exclude-dir
     56extern std::string IncludeFlag; // -include
     57
    5358/*
    5459 *  C.  Grep output modes and options.
     
    6469enum ColoringType {alwaysColor, autoColor, neverColor};
    6570extern ColoringType ColorFlag;
     71
     72enum DevDirAction {Read, Skip, Recurse};
     73extern DevDirAction DevicesFlag;
     74extern DevDirAction DirectoriesFlag;
     75   
     76enum BinaryFilesMode {Binary, WithoutMatch, Text};
     77extern BinaryFilesMode BinaryFilesFlag;
    6678   
    6779extern bool NoMessagesFlag; // -s
     
    7486extern bool InitialTabFlag; // -T
    7587extern bool OnlyMatchingFlag; // -o
     88extern std::string LabelFlag; // -label
    7689extern bool LineBufferedFlag; // -line-buffered
    7790extern bool NormalizeLineBreaksFlag; // -normalize-line-breaks
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5476 r5480  
    3636using namespace llvm;
    3737
    38 static cl::OptionCategory LegacyGrepOptions("A. Standard Grep Options",
    39                                        "These are standard grep options intended for compatibility with typical grep usage.");
    40 
    41 
    42 static cl::opt<bool> UTF_16("UTF-16", cl::desc("Regular expressions over the UTF-16 representation of Unicode."), cl::cat(LegacyGrepOptions));
    43 static cl::OptionCategory EnhancedGrepOptions("B. Enhanced Grep Options",
    44                                        "These are additional options for icgrep functionality and performance.");
    45 
     38static cl::opt<bool> UTF_16("UTF-16", cl::desc("Regular expressions over the UTF-16 representation of Unicode."));
    4639
    4740static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
    4841
    49 static cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(LegacyGrepOptions));
    50 static cl::opt<std::string> RegexFilename("f", cl::desc("Take regular expressions (one per line) from a file"), cl::value_desc("regex file"), cl::init(""), cl::cat(LegacyGrepOptions));
    51 
    5242static cl::opt<int> Threads("t", cl::desc("Total number of threads."), cl::init(1));
    5343
    54 static cl::opt<bool> MultiGrepKernels("enable-multigrep-kernels", cl::desc("Construct separated kernels for each regular expression"), cl::cat(EnhancedGrepOptions));
     44static cl::opt<bool> MultiGrepKernels("enable-multigrep-kernels", cl::desc("Construct separated kernels for each regular expression"));
    5545static cl::opt<int> REsPerGroup("re-num", cl::desc("Number of regular expressions processed by each kernel."), cl::init(1));
    5646static std::vector<std::string> allFiles;
     
    6050std::vector<re::RE *> readExpressions() {
    6151 
    62     if (RegexFilename != "") {
    63         std::ifstream regexFile(RegexFilename.c_str());
     52    if (grep::FileFlag != "") {
     53        std::ifstream regexFile(grep::FileFlag.c_str());
    6454        std::string r;
    6555        if (regexFile.is_open()) {
    6656            while (std::getline(regexFile, r)) {
    67                 regexVector.push_back(r);
     57                grep::RegexpVector.push_back(r);
    6858            }
    6959            regexFile.close();
     
    7464    // must be a regex, not an input file.
    7565   
    76     if (regexVector.size() == 0) {
    77         regexVector.push_back(inputFiles[0]);
     66    if (grep::RegexpVector.size() == 0) {
     67        grep::RegexpVector.push_back(inputFiles[0]);
    7868        inputFiles.erase(inputFiles.begin());
    7969    }
     
    8373
    8474    std::vector<re::RE *> REs;
    85     for (unsigned i = 0; i < regexVector.size(); i++) {
    86         re::RE * re_ast = re::RE_Parser::parse(regexVector[i], globalFlags, grep::RegexpSyntax);
     75    for (unsigned i = 0; i < grep::RegexpVector.size(); i++) {
     76        re::RE * re_ast = re::RE_Parser::parse(grep::RegexpVector[i], globalFlags, grep::RegexpSyntax);
    8777        REs.push_back(re_ast);
    8878    }
     
    149139bool excludeDirectory(boost::filesystem::path dirpath) { return dirpath.filename() == ".svn";}
    150140
     141// Determine whether to skip a path based on -D skip or -d skip settings.
     142bool skip_path(boost::filesystem::path p) {
     143    using namespace boost::filesystem;
     144    switch (status(p).type()) {
     145        case directory_file: return grep::DirectoriesFlag == grep::Skip;
     146        case block_file:
     147        case character_file:
     148        case fifo_file:
     149        case socket_file:
     150            return grep::DevicesFlag == grep::Skip;
     151        default:
     152            return false;
     153    }
     154}
     155
    151156std::vector<std::string> getFullFileList(cl::list<std::string> & inputFiles) {
    152157    using namespace boost::filesystem;
     
    154159    std::vector<std::string> expanded_paths;
    155160    boost::system::error_code errc;
    156     if (grep::DereferenceRecursiveFlag) {
    157         grep::RecursiveFlag = true;
    158     }
    159161    for (const std::string & f : inputFiles) {
    160 //        if (f == "-") {
    161 //            continue;
    162 //        }
     162        //        if (f == "-") {
     163        //            continue;
     164        //        }
    163165        path p(f);
    164         if (LLVM_UNLIKELY(grep::RecursiveFlag && is_directory(p))) {
     166        if (skip_path(p)) {
     167            continue;
     168        }
     169        if (LLVM_UNLIKELY((grep::DirectoriesFlag == grep::Recurse) && is_directory(p))) {
    165170            if (!excludeDirectory(p)) {
    166171                recursive_directory_iterator di(p, follow_symlink, errc), end;
    167172                if (errc) {
    168173                    // If we cannot enter the directory, keep it in the list of files.
    169                     expanded_paths.push_back(f); 
     174                    expanded_paths.push_back(f);
    170175                    continue;
    171176                }
     
    177182                        }
    178183                    } else {
    179                         expanded_paths.push_back(e.string());
     184                        if (!skip_path(e)) expanded_paths.push_back(e.string());
    180185                    }
    181186                    di.increment(errc);
    182187                    if (errc) {
    183                         expanded_paths.push_back(e.string()); 
     188                        expanded_paths.push_back(e.string());
    184189                    }
    185190                }
     
    191196    return expanded_paths;
    192197}
    193 
    194198
    195199int main(int argc, char *argv[]) {
Note: See TracChangeset for help on using the changeset viewer.