Changeset 4460


Ignore:
Timestamp:
Feb 5, 2015, 11:52:07 AM (4 years ago)
Author:
cameron
Message:

Set normalize line breaks option;default off

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

Legend:

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

    r4440 r4460  
    8181        line_start++;
    8282    }
    83     if (buffer[line_end] == 0xA) {
    84         // Normal Unix line end; just write the line.
     83    unsigned char end_byte = (unsigned char) buffer[line_end];
     84    if (mNormalizeLineBreaksOption) {
     85        if (end_byte <= 0xD) {
     86            // Line terminated with LF, VT, FF or CR. 
     87            std::cout.write(&buffer[line_start], line_end - line_start);
     88            std::cout << std::endl;
     89        }
     90        else if (end_byte == 0x85) {
     91            // Line terminated with NEL, on the second byte. 
     92            std::cout.write(&buffer[line_start], line_end - line_start - 1);
     93            std::cout << std::endl;
     94        }
     95        else  {
     96            // Line terminated with PS or LS, on the third byte.
     97            std::cout.write(&buffer[line_start], line_end - line_start - 2);
     98            std::cout << std::endl;
     99        }
     100    }
     101    else {
     102        // TODO:  Adjust for CRLF
    85103        std::cout.write(&buffer[line_start], line_end - line_start + 1);
    86104    }
    87     else if (buffer[line_end] <= 0xD) {
    88         // Line terminated with VT, FF or CR. 
    89         std::cout.write(&buffer[line_start], line_end - line_start);
    90         std::cout << std::endl;
    91     }
    92     else if (((unsigned char) buffer[line_end]) == 0x85) {
    93         // Line terminated with NEL, on the second byte. 
    94         std::cout.write(&buffer[line_start], line_end - line_start - 1);
    95         std::cout << std::endl;
    96     }
    97     else  {
    98         // Line terminated with PS or LS, on the third byte.
    99         std::cout.write(&buffer[line_start], line_end - line_start -2);
    100         std::cout << std::endl;
    101     }
    102      
    103105
    104106    line_start = line_end + 1;
     
    161163        return;
    162164    }
    163    
     165    currentFileSize = infile_sb.st_size;
    164166    char * buffer_ptr;
    165167    int segment = 0;
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4440 r4460  
    5757    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
    5858    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
     59    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
    5960   
    6061    void doGrep(std::string fileName);
     
    6566    bool mShowFileNameOption;
    6667    bool mShowLineNumberingOption;
     68    bool mNormalizeLineBreaksOption;
    6769    int mCarries;
    6870    int mAdvances;
     
    7072   
    7173    std::string currentFileName;
     74    size_t currentFileSize;
    7275    ScannerT LF_scanner;
    7376    ScannerT match_scanner;
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4412 r4460  
    5656    cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
    5757    cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
     58    cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
    5859   
    5960    cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
     
    109110        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
    110111        grepEngine.setCountOnlyOption(CountOnly);
     112        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
    111113        grepEngine.setShowLineNumberOption(ShowLineNumbers);
    112114            if (inputFiles.size() > (firstInputFile + 1) || ShowFileNames) {
Note: See TracChangeset for help on using the changeset viewer.