autodriver/autodriver.c
void insertTimestamp(char *buffer,
                     size_t bufferOffset,
                     size_t bufferLength,
                     char **scanCursorInOut,
                     unsigned *currentStampInOut) {
  char *scanCursor = *scanCursorInOut;
  unsigned currentStamp = *currentStampInOut;
  size_t nextOffset = bufferOffset + bufferLength;
  size_t eolOffset = 0;

  // pace through timestamps that fall into the buffer
  while (currentStamp < timestampCount &&
         timestampMap[currentStamp].offset < nextOffset) {

    // there might be unused timestamps from last read buffer or before last eol.
    // skip over them.
    if (timestampMap[currentStamp].offset < bufferOffset ||
        timestampMap[currentStamp].offset <= eolOffset) {
      currentStamp++;
      continue;
    }

    char *eolSearchStart = buffer + (timestampMap[currentStamp].offset - bufferOffset);
    char *nextEol = strchr(eolSearchStart, '\n');
    if (!nextEol) {  // no line break found in read buffer to insert timestamp
      break;
    }

    // write the stuff up to the line break
    if (writeBuffer(scanCursor, (nextEol + 1) - scanCursor)) {
      ERROR("Write failed: buffer %p cursor %p nextEol %p", buffer, scanCursor, nextEol);
      break;
    }
    scanCursor = nextEol + 1;

    // no timestamp at EOF, because the test scores are on the last line
    eolOffset = bufferOffset + (nextEol - buffer);
    if (eolOffset + 1 >= outputFileSize) {
      break;
    }

    // write the timestamp
    char stampInsert[300];
    sprintf(stampInsert,
            "...[timestamp %s inserted by autodriver at offset ~%lu. Maybe out of sync with output's own timestamps.]...\n",
            getTimestamp(timestampMap[currentStamp].time),
            timestampMap[currentStamp].offset);
    if (writeBuffer(stampInsert, strlen(stampInsert))) {break;}
    currentStamp++;
  }  // while loop through the stamps falling into read buffer's range

  *scanCursorInOut = scanCursor;
  *currentStampInOut = currentStamp;
}
// Insert the timestamp at the appropriate places.
// When failing to write to the output file, return with updated scanCursor,
Insert the timestamp at the appropriate places.
When failing to write to the output file, return with updated scanCursor.
Insert the timestamp at the appropriate places . When failing to write to the output file return with updated scanCursor .
void insertTimestamp(char *buffer,
                     size_t bufferOffset,
                     size_t bufferLength,
                     char **scanCursorInOut,
                     unsigned *currentStampInOut) {
  char *scanCursor = *scanCursorInOut;
  unsigned currentStamp = *currentStampInOut;
  size_t nextOffset = bufferOffset + bufferLength;
  size_t eolOffset = 0;
  while (currentStamp < timestampCount &&
         timestampMap[currentStamp].offset < nextOffset) {
    if (timestampMap[currentStamp].offset < bufferOffset ||
        timestampMap[currentStamp].offset <= eolOffset) {
      currentStamp++;
      continue;
    }
    char *eolSearchStart = buffer + (timestampMap[currentStamp].offset - bufferOffset);
    char *nextEol = strchr(eolSearchStart, '\n');
    if (!nextEol) {  
      break;
    }
    if (writeBuffer(scanCursor, (nextEol + 1) - scanCursor)) {
      ERROR("Write failed: buffer %p cursor %p nextEol %p", buffer, scanCursor, nextEol);
      break;
    }
    scanCursor = nextEol + 1;
    eolOffset = bufferOffset + (nextEol - buffer);
    if (eolOffset + 1 >= outputFileSize) {
      break;
    }
    char stampInsert[300];
    sprintf(stampInsert,
            "...[timestamp %s inserted by autodriver at offset ~%lu. Maybe out of sync with output's own timestamps.]...\n",
            getTimestamp(timestampMap[currentStamp].time),
            timestampMap[currentStamp].offset);
    if (writeBuffer(stampInsert, strlen(stampInsert))) {break;}
    currentStamp++;
  }  
  *scanCursorInOut = scanCursor;
  *currentStampInOut = currentStamp;
}
void insertTimestamp ( char * buffer , size_t bufferOffset , size_t bufferLength , char * * scanCursorInOut , unsigned * currentStampInOut ) { char * scanCursor = * scanCursorInOut ; unsigned currentStamp = * currentStampInOut ; size_t nextOffset = bufferOffset + bufferLength ; size_t eolOffset = 0 ; while ( currentStamp < timestampCount && timestampMap [ currentStamp ] . offset < nextOffset ) { if ( timestampMap [ currentStamp ] . offset < bufferOffset || timestampMap [ currentStamp ] . offset <= eolOffset ) { currentStamp ++ ; continue ; } char * eolSearchStart = buffer + ( timestampMap [ currentStamp ] . offset - bufferOffset ) ; char * nextEol = strchr ( eolSearchStart , ' \n ' ) ; if ( ! nextEol ) { break ; } if ( writeBuffer ( scanCursor , ( nextEol + 1 ) - scanCursor ) ) { ERROR ( " " , buffer , scanCursor , nextEol ) ; break ; } scanCursor = nextEol + 1 ; eolOffset = bufferOffset + ( nextEol - buffer ) ; if ( eolOffset + 1 >= outputFileSize ) { break ; } char stampInsert [ 300 ] ; sprintf ( stampInsert , " \n " , getTimestamp ( timestampMap [ currentStamp ] . time ) , timestampMap [ currentStamp ] . offset ) ; if ( writeBuffer ( stampInsert , strlen ( stampInsert ) ) ) { break ; } currentStamp ++ ; } * scanCursorInOut = scanCursor ; * currentStampInOut = currentStamp ; }
Insert the timestamp at the appropriate places.
Insert the timestamp at the appropriate places .
// pace through timestamps that fall into the buffer // there might be unused timestamps from last read buffer or before last eol. // skip over them. // no line break found in read buffer to insert timestamp // write the stuff up to the line break // no timestamp at EOF, because the test scores are on the last line // write the timestamp // while loop through the stamps falling into read buffer's range