Changeset 4947


Ignore:
Timestamp:
Mar 2, 2016, 9:35:14 AM (3 years ago)
Author:
cameron
Message:

Restructuring step

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

Legend:

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

    r4946 r4947  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2016 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.
     
    6767}
    6868
    69 void GrepEngine::doGrep(const std::string & fileName) {
     69bool GrepEngine::openMMap(const std::string & fileName) {
    7070
    7171    mFileName = fileName;
     
    7575    if (exists(file)) {
    7676        if (is_directory(file)) {
    77             return;
     77            return false;
    7878        }
    7979    } else {
    8080        std::cerr << "Error: cannot open " << mFileName << " for processing. Skipped.\n";
    81         return;
     81        return false;
    8282    }
    8383
     
    9292        } catch (std::ios_base::failure e) {
    9393            std::cerr << "Error: Boost mmap of " << mFileName << ": " << e.what() << std::endl;
    94             return;
     94            return false;
    9595        }
    9696        mFileBuffer = mFile.data();
     
    101101    if (fdSrc == -1) {
    102102        std::cerr << "Error: cannot open " << mFileName << " for processing. Skipped.\n";
    103         return;
     103        return false;
    104104    }
    105105    if (fstat(fdSrc, &infile_sb) == -1) {
    106106        std::cerr << "Error: cannot stat " << mFileName << " for processing. Skipped.\n";
    107107        close (fdSrc);
    108         return;
     108        return false;
    109109    }
    110110    if (S_ISDIR(infile_sb.st_mode)) {
    111111        close (fdSrc);
    112         return;
     112        return false;
    113113    }
    114114    mFileSize = infile_sb.st_size;
     
    127127                close (fdSrc);
    128128            }
    129             return;
     129            return false;
    130130        }
    131131    }
     132    close(fdSrc);
     133
    132134#endif
     135    return true;  // success
     136}
    133137
     138
     139void GrepEngine::doGrep() {
     140       
    134141    llvm::raw_os_ostream out(std::cout);
    135 
     142   
    136143    uint64_t finalLineUnterminated = 0;
    137144    if(finalLineIsUnterminated())
    138145        finalLineUnterminated = 1;
    139 
    140     mMainFcn(mFileBuffer, mFileSize, fileName.c_str(), finalLineUnterminated);
    141 
     146   
     147    mMainFcn(mFileBuffer, mFileSize, mFileName.c_str(), finalLineUnterminated);
     148   
    142149    PrintTotalCount();
    143150   
     
    146153#else
    147154    munmap((void *)mFileBuffer, mFileSize);
    148     close(fdSrc);
    149155#endif   
    150156}
     157
    151158
    152159void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression) {
     
    178185
    179186
    180 re::CC *  GrepEngine::grepCodepoints(const std::string & UNameFile) {
     187re::CC *  GrepEngine::grepCodepoints() {
    181188    setParsedCodePointSet();
    182     doGrep(UNameFile);
     189    if (openMMap("../UName.txt")) {
     190        doGrep();
     191    }
    183192    return getParsedCodePointSet();
    184193}
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r4946 r4947  
    22#define DO_GREP_H
    33/*
    4  *  Copyright (c) 2015 International Characters.
     4 *  Copyright (c) 2016 International Characters.
    55 *  This software is licensed to the public under the Open Software License 3.0.
    66 *  icgrep is a trademark of International Characters.
     
    2424    void grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression = false);
    2525   
    26     void doGrep(const std::string & fileName);
     26    bool openMMap(const std::string & fileName);
     27
     28    void doGrep();
    2729   
    28     re::CC *  grepCodepoints(const std::string & UNameFile);
     30    re::CC *  grepCodepoints();
    2931
    3032    ~GrepEngine() {
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4946 r4947  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2016 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.
     
    129129   
    130130    for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
    131             grepEngine.doGrep(inputFiles[i]);
     131        if (grepEngine.openMMap(inputFiles[i])) {
     132            grepEngine.doGrep();
     133        }
    132134    }
    133135   
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4946 r4947  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2016 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.
     
    527527    engine.grepCodeGen("NamePattern", embedded, true);
    528528   
    529     CC * codepoints = engine.grepCodepoints("../Uname.txt");
     529    CC * codepoints = engine.grepCodepoints();
    530530   
    531531    if (codepoints) {
Note: See TracChangeset for help on using the changeset viewer.