deps/kb_meme/meme-5.0.1/src/prior-reader-from-psp.c
/******************************************************************************
 * Read from the current position to the end of the current line.
 * Current position is assumed to be start of a new sequence.
 *
 * Returns true if it was able to read the sequence text, false if 
 * EOF reached before the terminal newline was found. Dies if other errors
 * are encountered.
 *****************************************************************************/
Read from the current position to the end of the current line.
Current position is assumed to be start of a new sequence.

Returns true if it was able to read the sequence text, false if
EOF reached before the terminal newline was found. Dies if other errors
are encountered.
Read from the current position to the end of the current line . Current position is assumed to be start of a new sequence . Returns true if it was able to read the sequence text false if EOF reached before the terminal newline was found . Dies if other errors are encountered .
bool read_seq_header_from_psp(
  PSP_DATA_BLOCK_READER_T *psp_reader
) {
  int result = false;
  const size_t initial_buffer_len = 100;
  if (psp_reader->sequence_header == NULL) {
     psp_reader->sequence_header = mm_malloc(sizeof(char) * initial_buffer_len);
     psp_reader->sequence_buffer_len = initial_buffer_len;
  }
  int c = 0;
  int seq_index = 0;
  while((c = fgetc(psp_reader->psp_file)) != EOF) {
    if (seq_index >= psp_reader->sequence_buffer_len) {
      psp_reader->sequence_header 
        = mm_realloc(
          psp_reader->sequence_header, 
          2 * psp_reader->sequence_buffer_len
        );
      psp_reader->sequence_buffer_len = 2 * psp_reader->sequence_buffer_len;
    }
    if (c == '\n') {
      psp_reader->sequence_header[seq_index] = '\0';
      psp_reader->sequence_header_len = seq_index + 1;
      psp_reader->at_start_of_line = true;
      result = true;
      break;
    }
    else {
      psp_reader->sequence_header[seq_index] = c;
      ++seq_index;
    }
  }
  if (c == EOF) {
    if (ferror(psp_reader->psp_file)) {
      die(
        "Error reading file:%s.\nError message: %s\n", 
        psp_reader->filename,
        strerror(ferror(psp_reader->psp_file))
      );
    }
    else if (feof(psp_reader->psp_file)) {
      psp_reader->sequence_header[0] = '\0';
      psp_reader->sequence_header_len = 0;
    }
  }
  return result;
}
bool read_seq_header_from_psp ( PSP_DATA_BLOCK_READER_T * psp_reader ) { int result = false ; const size_t initial_buffer_len = 100 ; if ( psp_reader -> sequence_header == NULL ) { psp_reader -> sequence_header = mm_malloc ( sizeof ( char ) * initial_buffer_len ) ; psp_reader -> sequence_buffer_len = initial_buffer_len ; } int c = 0 ; int seq_index = 0 ; while ( ( c = fgetc ( psp_reader -> psp_file ) ) != EOF ) { if ( seq_index >= psp_reader -> sequence_buffer_len ) { psp_reader -> sequence_header = mm_realloc ( psp_reader -> sequence_header , 2 * psp_reader -> sequence_buffer_len ) ; psp_reader -> sequence_buffer_len = 2 * psp_reader -> sequence_buffer_len ; } if ( c == ' \n ' ) { psp_reader -> sequence_header [ seq_index ] = ' \0 ' ; psp_reader -> sequence_header_len = seq_index + 1 ; psp_reader -> at_start_of_line = true ; result = true ; break ; } else { psp_reader -> sequence_header [ seq_index ] = c ; ++ seq_index ; } } if ( c == EOF ) { if ( ferror ( psp_reader -> psp_file ) ) { die ( " \n \n " , psp_reader -> filename , strerror ( ferror ( psp_reader -> psp_file ) ) ) ; } else if ( feof ( psp_reader -> psp_file ) ) { psp_reader -> sequence_header [ 0 ] = ' \0 ' ; psp_reader -> sequence_header_len = 0 ; } } return result ; }
Read from the current position to the end of the current line.
Read from the current position to the end of the current line .
// Initial allocation of sequence buffer // Look for EOL // Need to grow buffer // At this point c is EOL or EOF // EOF could actually indicate an error. // Reached EOF before reaching EOL for the sequence.