Changeset 4327


Ignore:
Timestamp:
Dec 8, 2014, 4:29:09 PM (4 years ago)
Author:
cameron
Message:

Line numbering option

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

Legend:

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

    r4325 r4327  
    6767    while (line_end < match_pos) {
    6868      line_start = line_end + 1;
     69      line_no++;
    6970      line_end = LF_scanner.scan_to_next();
    7071    }
     
    7273      std::cout << currentFileName;
    7374    }
     75    if (mShowLineNumberingOption) {
     76      std::cout << line_no << ":";
     77    }
    7478    fwrite(&buffer[line_start], 1, line_end - line_start + 1, outfile);
    7579    line_start = line_end + 1;
     80    line_no++;
    7681
    7782  }
     
    7984    line_end = LF_scanner.scan_to_next();
    8085    line_start = line_end+1;
     86    line_no++;
    8187  }
    8288  return line_start;
     
    106112    int line_end = 0;
    107113    int match_pos = 0;
    108     int line_no = 0;
     114    line_no = 1;
    109115
    110116    match_vector = simd<1>::constant<0>();
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4325 r4327  
    5353    mProcessBlockFcn(process_block), outfile(stdout)
    5454    {}
    55    
     55         
    5656    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
    5757    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
     
    7373    ScannerT LF_scanner;
    7474    ScannerT match_scanner;
     75    long line_no;
    7576};
    7677
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4325 r4327  
    44 *  icgrep is a trademark of International Characters.
    55 */
     6
     7#include <string>
    68
    79#include "icgrep.h"
     
    1113#include "do_grep.h"
    1214
    13 #include <fstream>
    14 #include <sstream>
    15 #include <iostream>
    16 #include <string>
    17 #include <stdint.h>
    18 
    19 #include <stdio.h>
    20 #include <stdlib.h>
    21 #include <unistd.h>
    22 #include <errno.h>
    23 #include <sys/types.h>
    24 #include <sys/stat.h>
    25 
    2615#include "llvm/Support/CommandLine.h"
    2716
    28 
    29    
    3017int main(int argc, char *argv[]) {
    3118    static cl::opt<std::string> regexp1(cl::Positional, cl::Required, cl::desc("<regexp>"));
     
    5340    const auto llvm_codegen = icgrep::compile(encoding, regexp1, false, false);
    5441
    55     if (llvm_codegen.process_block_fptr != 0)
    56      
    57     {
     42    if (llvm_codegen.process_block_fptr != 0) {
    5843        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) =
    5944           (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
    6045        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
    6146        grepEngine.setCountOnlyOption(CountOnly);
    62         if (inputFiles.size() > 1) grepEngine.setShowFileNameOption();
     47        grepEngine.setShowLineNumberOption(ShowLineNumbers);
     48        if (inputFiles.size() > 1 || ShowFileNames) grepEngine.setShowFileNameOption();
    6349        for (unsigned i = 0; i != inputFiles.size(); ++i) {
    6450            grepEngine.doGrep(inputFiles[i].c_str());
    6551        }
    6652    }
    67 
     53   
    6854    return 0;
    6955}
Note: See TracChangeset for help on using the changeset viewer.