deps/kb_meme/meme-5.0.1/src/buffer.c
/*
 * buf_fread_until
 * reads data from the file ptr into the buffer until
 * one of the search strings is encountered or an error
 * occurs. Will try to read from the buffer before doing
 * any IO so buffer must be ready to be read.
 * returns the number of the string discovered or zero 
 * for eof and -1 for error.
 * If outfp is not null then data will be copied to it.
 */
buf_fread_until
reads data from the file ptr into the buffer until
one of the search strings is encountered or an error
occurs. Will try to read from the buffer before doing
any IO so buffer must be ready to be read.
returns the number of the string discovered or zero
for eof and -1 for error.
If outfp is not null then data will be copied to it.
buf_fread_until reads data from the file ptr into the buffer until one of the search strings is encountered or an error occurs . Will try to read from the buffer before doing any IO so buffer must be ready to be read . returns the number of the string discovered or zero for eof and - 1 for error . If outfp is not null then data will be copied to it .
int buf_fread_until(BUF_T *buf, FILE *fp, FILE *outfp, int count, BMSTR_T **strings) {
  int index, limit;
  assert(buf != NULL);
  assert(fp != NULL);
  assert(count > 0);
  assert(strings != NULL);
  buf_mark(buf);
  index = buf_bm_search(buf, count, strings);
  while (true) {
    if (outfp) {
      limit = buf_limit(buf);
      buf_set_limit(buf, buf_position(buf));
      buf_reset(buf);
      while (buf_remaining(buf)) {
        buf_fwrite(buf, outfp);
        if (ferror(outfp)) return -1;
      }
      buf_set_limit(buf, limit);
    }
    if (index >= 0) break;
    if (feof(fp)) return 0;
    buf_compact(buf);
    buf_fread(buf, fp);
    buf_flip(buf);
    if (ferror(fp)) return -1;
    buf_mark(buf);
    index = buf_bm_search(buf, count, strings);
  }
  return index + 1;
}
int buf_fread_until ( BUF_T * buf , FILE * fp , FILE * outfp , int count , BMSTR_T * * strings ) { int index , limit ; assert ( buf != NULL ) ; assert ( fp != NULL ) ; assert ( count > 0 ) ; assert ( strings != NULL ) ; buf_mark ( buf ) ; index = buf_bm_search ( buf , count , strings ) ; while ( true ) { if ( outfp ) { limit = buf_limit ( buf ) ; buf_set_limit ( buf , buf_position ( buf ) ) ; buf_reset ( buf ) ; while ( buf_remaining ( buf ) ) { buf_fwrite ( buf , outfp ) ; if ( ferror ( outfp ) ) return -1 ; } buf_set_limit ( buf , limit ) ; } if ( index >= 0 ) break ; if ( feof ( fp ) ) return 0 ; buf_compact ( buf ) ; buf_fread ( buf , fp ) ; buf_flip ( buf ) ; if ( ferror ( fp ) ) return -1 ; buf_mark ( buf ) ; index = buf_bm_search ( buf , count , strings ) ; } return index + 1 ; }
buf_fread_until
 reads data from the file ptr into the buffer until
 one of the search strings is encountered or an error
 occurs.
buf_fread_until reads data from the file ptr into the buffer until one of the search strings is encountered or an error occurs .