Changeset 5197


Ignore:
Timestamp:
Oct 18, 2016, 10:53:37 AM (3 years ago)
Author:
cameron
Message:

Support for -x, -w, -l, -L flags (in progress)

Location:
icGREP/icgrep-devel/icgrep
Files:
2 added
2 edited

Legend:

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

    r5196 r5197  
    1111#include <llvm/Support/Signals.h>
    1212#include <re/re_alt.h>
     13#include <re/re_seq.h>
     14#include <re/re_start.h>
     15#include <re/re_end.h>
    1316#include <re/re_parser.h>
     17#include <re/re_utility.h>
    1418#include <grep_engine.h>
    1519#include <fstream>
     
    4448#endif
    4549
     50static cl::opt<bool> EntireLineMatching("x", cl::desc("Require that entire lines be matched."), cl::cat(LegacyGrepOptions), cl::Grouping);
     51static cl::alias  EntireLineMatchingAlias("line-regexp", cl::desc("Alias for -x"), cl::aliasopt(EntireLineMatching));
     52
     53static cl::opt<bool> WholeWordMatching("w", cl::desc("Require that whole words be matched."), cl::cat(LegacyGrepOptions), cl::Grouping);
     54static cl::alias WholeWordMatchingAlias("word-regexp", cl::desc("Alias for -w"), cl::aliasopt(WholeWordMatching));
     55
    4656static cl::opt<bool> UTF_16("UTF-16", cl::desc("Regular expressions over the UTF-16 representation of Unicode."), cl::cat(LegacyGrepOptions));
    4757static cl::OptionCategory EnhancedGrepOptions("B. Enhanced Grep Options",
    4858                                       "These are additional options for icgrep functionality and performance.");
     59
     60static cl::opt<bool> FileNamesOnly("l", cl::desc("Display only the names of matching files."), cl::cat(LegacyGrepOptions), cl::Grouping);
     61static cl::alias FileNamesAlias("files-with-matches", cl::desc("Alias for -l"), cl::aliasopt(FileNamesOnly));
     62
     63static cl::opt<bool> NonMatchingFileNamesOnly("L", cl::desc("Display only the names of matching files."), cl::cat(LegacyGrepOptions), cl::Grouping);
     64static cl::alias NonMatchingFileNamesAlias("files-without-match", cl::desc("Alias for -L"), cl::aliasopt(NonMatchingFileNamesOnly));
     65
     66
    4967static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(LegacyGrepOptions), cl::Grouping);
    5068static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
     69
    5170
    5271static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
     
    5574static cl::opt<bool> FollowSubdirectorySymlinks("R", cl::desc("Recursively process files within directories, following symlinks at all levels."), cl::cat(LegacyGrepOptions), cl::Grouping);
    5675static cl::opt<bool> CaseInsensitive("i", cl::desc("Ignore case distinctions in the pattern and the file."), cl::cat(LegacyGrepOptions), cl::Grouping);
    57 
     76static cl::alias CaseInsensitiveAlisas("ignore-case", cl::desc("Ignore case distinctions in the pattern and the file."), cl::aliasopt(CaseInsensitive));
    5877
    5978static cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(LegacyGrepOptions));
     
    130149        re_ast = re::makeAlt(REs.begin(), REs.end());
    131150    }
    132    
     151    if (WholeWordMatching) {
     152        re_ast = re::makeSeq({re::makeWordBoundary(), re_ast, re::makeWordBoundary()});
     153    }
     154    if (EntireLineMatching) {
     155        re_ast = re::makeSeq({re::makeStart(), re_ast, re::makeEnd()});
     156    }   
    133157    return re_ast;
    134158}
     
    321345int main(int argc, char *argv[]) {
    322346    llvm::install_fatal_error_handler(&icgrep_error_handler);
    323 #ifndef USE_LLVM_3_6
     347#if LLVM_VERSION_MINOR > 6
    324348    cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>{&LegacyGrepOptions, &EnhancedGrepOptions, re::re_toolchain_flags(), pablo::pablo_toolchain_flags(), codegen::codegen_flags()});
    325349#endif
     
    332356    re::RE * re_ast = get_icgrep_RE();
    333357    std::string module_name = "grepcode:" + sha1sum(allREs) + ":" + std::to_string(globalFlags);
    334 
     358   
    335359    if (GrepSupport) {  // Calls icgrep again on command line and passes output to grep.
    336360        pipeIcGrepOutputToGrep(argc, argv);
     
    345369   
    346370    allFiles = getFullFileList(inputFiles);
     371   
     372    if (FileNamesOnly && NonMatchingFileNamesOnly) {
     373        // Strange request: print names of all matching files and all non-matching files: i.e., all of them.
     374        // (Although GNU grep prints nothing.)
     375        for (auto & f : allFiles) {
     376            if (boost::filesystem::exists(f)) {
     377                std::cout << f << "\n";
     378            }
     379            else {
     380                std::cerr << "Error: cannot open " << f << " for processing. Skipped.\n";
     381            }
     382        }
     383        exit(0);
     384    }
     385    if (FileNamesOnly) {
     386        llvm::report_fatal_error("Sorry, -l/-files-with-matches not yet supported\n.");
     387    }
     388    if (NonMatchingFileNamesOnly) {
     389        llvm::report_fatal_error("Sorry, -L/-files-without-match not yet supported\n.");
     390    }
    347391   
    348392    initResult(allFiles);
  • icGREP/icgrep-devel/icgrep/re/re_seq.h

    r4852 r5197  
    7474}
    7575
    76 #endif // JOIN_H
     76#endif // RE_SEQ_H
    7777
    7878
Note: See TracChangeset for help on using the changeset viewer.