Ignore:
Timestamp:
Dec 30, 2015, 9:21:06 AM (3 years ago)
Author:
cameron
Message:

Refactoring progress towards layered kernels

File:
1 edited

Legend:

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

    r4900 r4904  
    5656//
    5757
     58
     59void GrepExecutor::write_matched_line(llvm::raw_ostream & out, const char * buffer, ssize_t line_start, ssize_t line_end) {
     60    if (mShowFileNameOption) {
     61        out << mFileName << ':';
     62    }
     63    if (mShowLineNumberingOption) {
     64        out << mLineNum << ":";
     65    }
     66    if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
     67        // The line "starts" on the LF of a CRLF.  Really the end of the last line.
     68        line_start++;
     69    }
     70    if (buffer + line_end == mFileBuffer + mFileSize) {
     71        // The match position is at end-of-file.   We have a final unterminated line.
     72        out.write(&buffer[line_start], line_end - line_start);
     73        if (mNormalizeLineBreaksOption) {
     74            out << '\n';  // terminate it
     75        }
     76        return;
     77    }
     78    unsigned char end_byte = (unsigned char)buffer[line_end];
     79    if (mNormalizeLineBreaksOption) {
     80        if (end_byte == 0x85) {
     81            // Line terminated with NEL, on the second byte.  Back up 1.
     82            line_end--;
     83        } else if (end_byte > 0xD) {
     84            // Line terminated with PS or LS, on the third byte.  Back up 2.
     85            line_end -= 2;
     86        }
     87        out.write(&buffer[line_start], line_end - line_start);
     88        out << '\n';
     89    }
     90    else {
     91        if (end_byte == 0x0D) {
     92            // Check for line_end on first byte of CRLF;  note that we don't
     93            // want to access past the end of buffer.
     94            if ((buffer + line_end + 1 < mFileBuffer + mFileSize) && (buffer[line_end + 1] == 0x0A)) {
     95                // Found CRLF; preserve both bytes.
     96                line_end++;
     97            }
     98        }
     99        out.write(&buffer[line_start], line_end - line_start + 1);
     100    }
     101   
     102}
     103
    58104ssize_t GrepExecutor::write_matches(llvm::raw_ostream & out, const char * buffer, ssize_t line_start) {
    59105
     
    71117            mLineNum++;
    72118        }
    73         if (mShowFileNameOption) {
    74             out << mFileName << ':';
    75         }
    76         if (mShowLineNumberingOption) {
    77             out << mLineNum << ":";
    78         }
    79         if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
    80             // The line "starts" on the LF of a CRLF.  Really the end of the last line.
    81             line_start++;
    82         }
    83         if (buffer + line_end == mFileBuffer + mFileSize) {
    84             // The match position is at end-of-file.   We have a final unterminated line.
    85             out.write(&buffer[line_start], line_end - line_start);
    86             if (mNormalizeLineBreaksOption) {
    87               out << '\n';  // terminate it
    88             }
    89             return line_end;
    90         }
    91         unsigned char end_byte = (unsigned char)buffer[line_end];
    92         if (mNormalizeLineBreaksOption) {
    93             if (end_byte == 0x85) {
    94                 // Line terminated with NEL, on the second byte.  Back up 1.
    95                 line_end--;
    96             } else if (end_byte > 0xD) {
    97                 // Line terminated with PS or LS, on the third byte.  Back up 2.
    98                 line_end -= 2;
    99             }
    100             out.write(&buffer[line_start], line_end - line_start);
    101             out << '\n';
    102         }
    103         else {
    104             if (end_byte == 0x0D) {
    105                 // Check for line_end on first byte of CRLF;  note that we don't
    106                 // want to access past the end of buffer.
    107                 if ((buffer + line_end + 1 < mFileBuffer + mFileSize) && (buffer[line_end + 1] == 0x0A)) {
    108                     // Found CRLF; preserve both bytes.
    109                     line_end++;
    110                 }
    111             }
    112             out.write(&buffer[line_start], line_end - line_start + 1);
    113         }
     119        write_matched_line(out,buffer, line_start, line_end);
    114120        line_start = line_end + 1;
    115121        mLineNum++;
Note: See TracChangeset for help on using the changeset viewer.