Changeset 5940


Ignore:
Timestamp:
Apr 2, 2018, 5:32:16 PM (13 months ago)
Author:
cameron
Message:

icgrep -GLOB option for GLOB syntax, utilities for file include/exclude command arguments

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

Legend:

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

    r5927 r5940  
    11/*
    2  *  Copyright (c) 2017 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    1111#include <llvm/Support/raw_ostream.h>
    1212#include <toolchain/toolchain.h>
     13#include <re/parsers/parser.h>
     14#include <re/re_alt.h>
    1315#include <re/re_toolchain.h>
     16#include <fstream>
     17#include <string>
     18
    1419#include <pablo/pablo_toolchain.h>
    1520
     
    3540        clEnumValN(re::RE_Syntax::BRE, "basic-regexp", "Alias for -G"),
    3641        clEnumValN(re::RE_Syntax::PCRE, "perl-regexp", "Alias for -P"),
     42        clEnumValN(re::RE_Syntax::FileGLOB, "GLOB", "Posix GLOB syntax for file name patterns"),
    3743        clEnumValN(re::RE_Syntax::PROSITE, "PROSITE", "PROSITE protein patterns syntax")
    3844        CL_ENUM_VAL_SENTINEL), cl::cat(RE_Options), cl::Grouping, cl::location(RegexpSyntax), cl::init(re::RE_Syntax::PCRE));
     
    131137                                                                clEnumValN(Text, "text", "Treat binary files as text.")
    132138                                                                CL_ENUM_VAL_SENTINEL), cl::cat(Input_Options), cl::location(BinaryFilesFlag), cl::init(Binary));
     139   
     140
     141   
     142re::RE * getFileExcludePattern() {
     143    std::vector<re::RE *> patterns;
     144    if (grep::ExcludeFlag != "") {
     145        re::RE * glob = re::RE_Parser::parse(grep::ExcludeFlag, re::DEFAULT_MODE, re::RE_Syntax::FileGLOB);
     146        patterns.push_back(glob);
     147    }
     148   
     149    if (grep::ExcludeFromFlag != "") {
     150        std::ifstream globFile(grep::ExcludeFromFlag.c_str());
     151        std::string r;
     152        if (globFile.is_open()) {
     153            while (std::getline(globFile, r)) {
     154                re::RE * glob = re::RE_Parser::parse(r, re::DEFAULT_MODE, re::RE_Syntax::FileGLOB);
     155                patterns.push_back(glob);
     156            }
     157            globFile.close();
     158        }
     159    }
     160    if (patterns.empty()) return nullptr;
     161    return re::makeAlt(patterns.begin(), patterns.end());
     162}
     163
     164re::RE * getDirectoryExcludePattern() {
     165    if (grep::ExcludeDirFlag != "") {
     166        return re::RE_Parser::parse(grep::ExcludeDirFlag, re::DEFAULT_MODE, re::RE_Syntax::FileGLOB);
     167    }
     168    return nullptr;
     169}
     170
     171re::RE * getFileIncludePattern() {
     172    if (grep::IncludeFlag != "") {
     173        return re::RE_Parser::parse(grep::IncludeFlag, re::DEFAULT_MODE, re::RE_Syntax::FileGLOB);
     174    }
     175    return nullptr;
     176}
     177
     178// Include is the default unless a -include= option exists and is prior to any -exclude
     179// or -exclude-dir option.
     180bool includeIsDefault() {
     181    if (IncludeFlag == "") return true;
     182    if ((ExcludeFlag != "") && (ExcludeOption.getPosition() < IncludeOption.getPosition())) return true;
     183    if ((ExcludeDirFlag != "") && (ExcludeDirOption.getPosition() < IncludeOption.getPosition())) return true;
     184    return false;
     185}
    133186   
    134187/*
  • icGREP/icgrep-devel/icgrep/grep_interface.h

    r5938 r5940  
    5959extern std::string IncludeFlag; // -include
    6060
     61// File exclude pattern parsed from ExcludeFlag and ExcludeFromFlag
     62re::RE * getFileExcludePattern();
     63
     64// File exclude pattern parsed from ExcludeDirFlag.
     65re::RE * getDirectoryExcludePattern();
     66
     67// File include pattern parsed from InludeFlag
     68re::RE * getFileIncludePattern();
     69
     70// Determine whether include is the default for files that do not match any pattern.
     71bool includeIsDefault();
     72
     73
    6174/*
    6275 *  C.  Grep output modes and options.
Note: See TracChangeset for help on using the changeset viewer.