Changeset 5483 for icGREP/icgrep-devel


Ignore:
Timestamp:
May 31, 2017, 10:44:04 AM (2 years ago)
Author:
cameron
Message:

Support for -label, -T, -Z flags, default (standard input) label for stdin

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

Legend:

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

    r5482 r5483  
    117117static std::stringstream * resultStrs = nullptr;
    118118static std::vector<std::string> inputFiles;
     119static std::vector<std::string> linePrefix;
    119120
    120121void initFileResult(std::vector<std::string> filenames){
    121122    const int n = filenames.size();
     123    linePrefix.resize(n);
    122124    if ((n > 1) && !NoFilenameFlag) {
    123125        WithFilenameFlag = true;
     126    }
     127    std::string fileSuffix;
     128    if (WithFilenameFlag) {
     129        if (NullFlag) {
     130            fileSuffix = std::string("\0", 1);
     131        }
     132        else if ((Mode == NormalMode) && InitialTabFlag && !(LineNumberFlag || ByteOffsetFlag)) {
     133            fileSuffix = "\t:";
     134        }
     135        else {
     136            fileSuffix = ":";
     137        }
    124138    }
    125139    inputFiles = filenames;
    126140    resultStrs = new std::stringstream[n];
    127141    total_count = new int[n];
    128     for (unsigned i = 0; i < inputFiles.size(); ++i){
     142    for (unsigned i = 0; i < inputFiles.size(); ++i) {
     143        if (WithFilenameFlag) {
     144            if (inputFiles[i] == "-") {
     145                linePrefix[i] = LabelFlag + fileSuffix;
     146            }
     147            else {
     148                linePrefix[i] = inputFiles[i] + fileSuffix;
     149            }
     150        }
    129151        total_count[i] = 0;
    130152    }
    131 
    132153}
    133154
     
    142163
    143164    if (WithFilenameFlag) {
    144         resultStrs[fileIdx] << inputFiles[fileIdx] << ':';
     165        resultStrs[fileIdx] << linePrefix[fileIdx];
    145166    }
    146167    if (LineNumberFlag) {
    147168        // Internally line numbers are counted from 0.  For display, adjust
    148169        // the line number so that lines are numbered from 1.
    149         resultStrs[fileIdx] << lineNum+1 << ":";
     170        if (InitialTabFlag) {
     171            resultStrs[fileIdx] << lineNum+1 << "\t:";
     172        }
     173        else {
     174            resultStrs[fileIdx] << lineNum+1 << ":";
     175        }
    150176    }
    151177
     
    206232        } else {
    207233            for (unsigned i = 0; i < inputFiles.size(); ++i){
    208                 std::cout << inputFiles[i] << ':' << total_CountOnly[i] << std::endl;
     234                std::cout << linePrefix[i] << total_CountOnly[i] << std::endl;
    209235                total += total_CountOnly[i];
    210236            };
     
    217243        for (unsigned i = 0; i < inputFiles.size(); ++i) {
    218244            if (total_CountOnly[i] == requiredCount) {
    219                 std::cout << inputFiles[i] << std::endl;
     245                std::cout << linePrefix[i];
     246                if (!NullFlag) {
     247                    std::cout << "\n";
     248                }
    220249            }
    221250            total += total_CountOnly[i];
  • icGREP/icgrep-devel/icgrep/grep_interface.cpp

    r5480 r5483  
    188188
    189189std::string LabelFlag;
    190 static cl::opt<std::string, true> LabelOption("label", cl::location(LabelFlag), cl::desc("Set a label for input lines matched from stdin."), cl::cat(Output_Options));
     190    static cl::opt<std::string, true> LabelOption("label", cl::location(LabelFlag), cl::init("(standard input)"),
     191                                              cl::desc("Set a label for input lines matched from stdin."), cl::cat(Output_Options));
    191192
    192193bool LineBufferedFlag;
     
    289290        llvm::report_fatal_error("Sorry, -s is not yet supported.\n");
    290291    }
    291     if (NullFlag) {
    292         llvm::report_fatal_error("Sorry, -Z is not yet supported.\n");
    293     }
    294292    if (ByteOffsetFlag) {
    295293        llvm::report_fatal_error("Sorry, -b is not yet supported.\n");
     
    298296        llvm::report_fatal_error("Sorry, -u is not yet supported.\n");
    299297    }
    300     if (InitialTabFlag) {
    301         llvm::report_fatal_error("Sorry, -T is not yet supported.\n");
    302     }
    303298    if (OnlyMatchingFlag) {
    304299        llvm::report_fatal_error("Sorry, -o is not yet supported.\n");
     
    316311        llvm::report_fatal_error("Sorry, -C is not yet supported.\n");
    317312    }
    318     if (LabelFlag!="") {
    319         llvm::report_fatal_error("Sorry, -label is not yet supported.\n");
    320     }
    321313    if (ColorFlag!=neverColor) {
    322314        llvm::report_fatal_error("Sorry, -color is not yet supported.\n");
Note: See TracChangeset for help on using the changeset viewer.