Changeset 4440


Ignore:
Timestamp:
Jan 24, 2015, 10:47:27 AM (4 years ago)
Author:
cameron
Message:

Send all output to std::cout, convert line breaks

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

Legend:

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

    r4430 r4440  
    7777      std::cout << line_no << ":";
    7878    }
    79     fwrite(&buffer[line_start], 1, line_end - line_start + 1, outfile);
     79    if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
     80        // The LF of a CRLF.  Really the end of the last line. 
     81        line_start++;
     82    }
     83    if (buffer[line_end] == 0xA) {
     84        // Normal Unix line end; just write the line.
     85        std::cout.write(&buffer[line_start], line_end - line_start + 1);
     86    }
     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     
     103
    80104    line_start = line_end + 1;
    81105    line_no++;
     
    244268            std::cout << currentFileName;
    245269        }
    246         fprintf(outfile, "%d\n", match_count);
     270        std::cout << match_count << std::endl;
    247271    }
    248272    else
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4358 r4440  
    5151    mCountOnlyOption(false), mShowFileNameOption(false), mShowLineNumberingOption(false),
    5252    mCarries(carry_count), mAdvances(advance_count),
    53     mProcessBlockFcn(process_block), outfile(stdout)
     53    mProcessBlockFcn(process_block)
    5454    {}
    5555         
     
    7070   
    7171    std::string currentFileName;
    72     FILE * outfile;
    7372    ScannerT LF_scanner;
    7473    ScannerT match_scanner;
Note: See TracChangeset for help on using the changeset viewer.