Ignore:
Timestamp:
Mar 18, 2014, 2:51:27 PM (6 years ago)
Author:
ksherdy
Message:

Updated to match lines without LFs. GNU grep does this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/demo/grep_template.cpp

    r3730 r3734  
    1212 * 1. Tranpose.do_block expects 'byte_data' and 'basis_bits'.
    1313 * 2. All StreamFunction.do_final_block methods expect 'EOF_mask'.
    14  * 3. Sequential iterators (scanners) expect 'output.matches' in post processing.
    15  *
     14 * 3. Sequential iterators (scanners) expect 'output.matches'.
     15 * 4. Sequential iterators (scanners) expect 'lex.LF'.
    1616 **/
    1717
     
    112112
    113113int copy_back_size          = 0;
    114 int copy_back_index         = 0;
     114int copy_back_pos           = 0;
    115115
    116116int block_index             = 0; // block index wrt current segment
     
    142142
    143143  // Marker stream iterator.
    144   BitStreamScanner<BitBlock, ScanWord, ScanWord, SEGMENT_BLOCKS> scanner;
     144  BitStreamScanner<BitBlock, ScanWord, ScanWord, SEGMENT_BLOCKS> match_scanner;
     145  BitStreamScanner<BitBlock, ScanWord, ScanWord, SEGMENT_BLOCKS> LF_scanner;
    145146
    146147  // Segment-at-a-time processing.
     
    158159
    159160    while (bytes_avail >= SEGMENT_SIZE) {
    160       scanner.init();
     161      match_scanner.init();
     162      LF_scanner.init();
    161163
    162164      for(block_index = 0;
     
    168170        @block_stmts
    169171
    170         scanner.load_block(output.matches, block_index);
     172        match_scanner.load_block(output.matches, block_index);
     173        LF_scanner.load_block(lex.LF, block_index);
    171174      }
    172175
    173       while(scanner.has_next()) {
    174         match_pos = scanner.scan_to_next()
     176      while(match_scanner.has_next()) {
     177        match_pos = match_scanner.scan_to_next()
    175178                       + stream_base - pattern_size + 1;
    176179        printf("%d:%s\n", match_pos, fixed_pattern);
     
    184187    block_index = 0;
    185188    final_segment_size = bytes_avail;
    186     scanner.init();
     189    match_scanner.init();
    187190
    188191    // Process full blocks.
     
    192195      @block_stmts
    193196
    194       scanner.load_block(output.matches, block_index);
     197      match_scanner.load_block(output.matches, block_index);
    195198
    196199      block_base += BLOCK_SIZE;
     
    206209      @final_block_stmts
    207210
    208       scanner.load_block(output.matches, block_index);
    209     }
    210 
    211     while(scanner.has_next()) {
    212       match_pos = scanner.scan_to_next()
     211      match_scanner.load_block(output.matches, block_index);
     212    }
     213
     214    while(match_scanner.has_next()) {
     215      match_pos = match_scanner.scan_to_next()
    213216                     + stream_base - pattern_size + 1;
    214217
     
    221224    // partial matches of the "needle" at segment boundaries.
    222225    copy_back_size     = pattern_size - 1;
    223     copy_back_index    = block_base + bytes_avail - copy_back_size;
    224     memmove(&buffer[0], &buffer[copy_back_index], copy_back_size);
     226    copy_back_pos      = block_base + bytes_avail - copy_back_size;
     227
     228//    int copy_back_size = SEGMENT_SIZE - copy_back_pos;
     229//    int copy_back_pos = LF_scanner.get_final_pos() + 1;
     230
     231    memmove(&buffer[0], &buffer[copy_back_pos], copy_back_size);
    225232
    226233    stream_base -= copy_back_size;
Note: See TracChangeset for help on using the changeset viewer.