Changeset 5946 for icGREP


Ignore:
Timestamp:
Apr 5, 2018, 9:59:17 PM (10 months ago)
Author:
cameron
Message:

Fix for wc

File:
1 edited

Legend:

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

    r5944 r5946  
    2424#include <pablo/pablo_toolchain.h>
    2525#include <toolchain/cpudriver.h>
     26#include <sys/stat.h>
    2627#include <fcntl.h>
    2728#include <util/file_select.h>
     
    206207}
    207208
     209
     210
    208211void wc(WordCountFunctionType fn_ptr, const int64_t fileIdx) {
    209212    std::string fileName = allFiles[fileIdx];
     213    struct stat sb;
    210214    const int fd = open(fileName.c_str(), O_RDONLY);
    211215    if (LLVM_UNLIKELY(fd == -1)) {
    212         std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
    213     } else {
    214         fn_ptr(fd, fileIdx);
     216        if (errno == EACCES) {
     217            std::cerr << "wc: " << fileName << ": Permission denied.\n";
     218        }
     219        else if (errno == ENOENT) {
     220            std::cerr << "wc: " << fileName << ": No such file.\n";
     221        }
     222        else {
     223            std::cerr << "wc: " << fileName << ": Failed.\n";
     224        }
     225        return;
     226    }
     227    if (stat(fileName.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
     228        std::cerr << "wc: " << fileName << ": Is a directory.\n";
    215229        close(fd);
    216     }
     230        return;
     231    }
     232    fn_ptr(fd, fileIdx);
     233    close(fd);
    217234}
    218235
    219236int main(int argc, char *argv[]) {
    220237    codegen::ParseCommandLineOptions(argc, argv, {&wcFlags, pablo_toolchain_flags(), codegen::codegen_flags()});
     238    if (argv::RecursiveFlag || argv::DereferenceRecursiveFlag) {
     239        argv::DirectoriesFlag = argv::Recurse;
     240    }
     241    allFiles = argv::getFullFileList(inputFiles);
     242   
     243    const auto fileCount = allFiles.size();
    221244    if (wcOptions.size() == 0) {
    222245        CountLines = true;
     
    245268    wcPipelineGen(pxDriver);
    246269    auto wordCountFunctionPtr = reinterpret_cast<WordCountFunctionType>(pxDriver.getMain());
    247 
    248     allFiles = argv::getFullFileList(inputFiles);
    249     const auto fileCount = allFiles.size();
    250270    lineCount.resize(fileCount);
    251271    wordCount.resize(fileCount);
    252272    charCount.resize(fileCount);
    253273    byteCount.resize(fileCount);
    254    
     274
    255275    for (unsigned i = 0; i < fileCount; ++i) {
    256276        wc(wordCountFunctionPtr, i);
     
    263283    if (CountBytes) maxCount = TotalBytes;
    264284   
    265    
    266    
    267285    int displayColumnWidth = std::to_string(maxCount).size() + 1;
    268286    if (displayColumnWidth < defaultDisplayColumnWidth) displayColumnWidth = defaultDisplayColumnWidth;
Note: See TracChangeset for help on using the changeset viewer.