Changeset 5707 for icGREP


Ignore:
Timestamp:
Oct 25, 2017, 10:07:12 PM (16 months ago)
Author:
cameron
Message:

Fix for older compilers

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

Legend:

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

    r5704 r5707  
    8080    const int n = filenames.size();
    8181    mResultStrs.resize(n);
     82    for (unsigned i = 0; i < n; i++) {
     83        mResultStrs[i] = make_unique<std::stringstream>();
     84    }
    8285    inputFiles = filenames;
    8386}
     
    319322    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    320323   
    321     int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx]);
     324    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx].get());
    322325    if (fileDescriptor == -1) return 0;
    323326   
     
    329332uint64_t CountOnlyEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
    330333    uint64_t grepResult = GrepEngine::doGrep(fileName, fileIdx);
    331    
    332     if (WithFilenameFlag) mResultStrs[fileIdx] << linePrefix(fileName);
    333     mResultStrs[fileIdx] << grepResult << "\n";
     334    if (WithFilenameFlag) *mResultStrs[fileIdx] << linePrefix(fileName);
     335    *mResultStrs[fileIdx] << grepResult << "\n";
    334336    return grepResult;
    335337}
     
    347349    uint64_t grepResult = GrepEngine::doGrep(fileName, fileIdx);
    348350    if (grepResult == mRequiredCount) {
    349         mResultStrs[fileIdx] << linePrefix(fileName);
     351       *mResultStrs[fileIdx] << linePrefix(fileName);
    350352    }
    351353    return grepResult;
     
    356358    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    357359   
    358     int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx]);
     360    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx].get());
    359361    if (fileDescriptor == -1) return 0;
    360     EmitMatch accum(linePrefix(fileName), &mResultStrs[fileIdx]);
     362    EmitMatch accum(linePrefix(fileName), mResultStrs[fileIdx].get());
    361363    uint64_t grepResult = f(fileDescriptor, reinterpret_cast<intptr_t>(&accum));
    362364    close(fileDescriptor);
     
    366368
    367369// Open a file and return its file desciptor.
    368 int32_t GrepEngine::openFile(const std::string & fileName, std::stringstream & msgstrm) {
     370int32_t GrepEngine::openFile(const std::string & fileName, std::stringstream * msgstrm) {
    369371    if (fileName == "-") {
    370372        return STDIN_FILENO;
     
    376378            if (!NoMessagesFlag) {
    377379                if (errno == EACCES) {
    378                     msgstrm << "icgrep: " << fileName << ": Permission denied.\n";
     380                    *msgstrm << "icgrep: " << fileName << ": Permission denied.\n";
    379381                }
    380382                else if (errno == ENOENT) {
    381                     msgstrm << "icgrep: " << fileName << ": No such file.\n";
     383                    *msgstrm << "icgrep: " << fileName << ": No such file.\n";
    382384                }
    383385                else {
    384                     msgstrm << "icgrep: " << fileName << ": Failed.\n";
     386                    *msgstrm << "icgrep: " << fileName << ": Failed.\n";
    385387                }
    386388            }
     
    389391        if (stat(fileName.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
    390392            if (!NoMessagesFlag) {
    391                 msgstrm << "icgrep: " << fileName << ": Is a directory.\n";
     393                *msgstrm << "icgrep: " << fileName << ": Is a directory.\n";
    392394            }
    393395            close(fileDescriptor);
     
    457459void GrepEngine::writeMatches() {
    458460    for (unsigned i = 0; i < inputFiles.size(); ++i) {
    459         std::cout << mResultStrs[i].str();
    460     }
    461 }
    462 
    463 }
    464 
     461        std::cout << mResultStrs[i]->str();
     462    }
     463}
     464
     465}
     466
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5704 r5707  
    3939    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
    4040    std::string linePrefix(std::string fileName);
    41     int32_t openFile(const std::string & fileName, std::stringstream & msgstrm);
     41    int32_t openFile(const std::string & fileName, std::stringstream * msgstrm);
    4242
    4343    Driver * mGrepDriver;
    4444
    4545    std::vector<std::string> inputFiles;
    46     std::vector<std::stringstream> mResultStrs;
     46    std::vector<std::unique_ptr<std::stringstream>> mResultStrs;
    4747   
    4848    std::string mFileSuffix;
Note: See TracChangeset for help on using the changeset viewer.