hmmer-3.3/easel/esl_sqio_ncbi.c
/* Function:  parse_string()
 * Synopsis:  Parse a visible string
 * Incept:    MSF, Mon Dec 10, 2009 [Janelia]
 *
 * Purpose:   Parses a string from the header stream.
 *
 *            If <str> is non null, the location of the string in 
 *            the header will be saved.  If <len> is non null, the
 *            length of the string will be filled in.  If <str> is
 *            non null, then <len> must be non null since the strings
 *            are not zero terminated.
 *
 * Returns:   <eslOK> on success.
 *            <eslEFORMAT> if there's a problem with the format.
 *            <eslEINCOMPAT> if <str> is non null and <len> is null.
 *
 */
parse_string()
Synopsis:  Parse a visible string
Incept:    MSF, Mon Dec 10, 2009 [Janelia]

Parses a string from the header stream.

If  is non null, the location of the string in
the header will be saved.  If  is non null, the
length of the string will be filled in.  If  is
non null, then  must be non null since the strings
are not zero terminated.

 on success.
 if there's a problem with the format.
 if  is non null and  is null.
parse_string () Synopsis : Parse a visible string Incept : MSF Mon Dec 10 2009 [ Janelia ] Parses a string from the header stream . If is non null the location of the string in the header will be saved . If is non null the length of the string will be filled in . If is non null then must be non null since the strings are not zero terminated . on success . if there ' s a problem with the format . if is non null and is null .
static int
parse_string(ESL_SQNCBI_DATA *ncbi, char **str, int *len)
{
  int n;
  unsigned char  x;
  unsigned char  c;
  unsigned char *ptr;
  if (parse_expect(ncbi, "\x1a", 1) != eslOK)  return eslEFORMAT;
  if (parse_consume(ncbi, &c, 1) != eslOK)     return eslEFORMAT;
  if (c < 128) {
    n = c;
  } else {
    c = c & 0x7f;
    if (c > sizeof(n))                                 return eslEFORMAT;
    n = 0;
    while (c > 0) {
      if (parse_consume(ncbi, &x, 1) != eslOK) return eslEFORMAT;
      n = (n << 8) + (unsigned int) x;
      --c;
    }
  }
  ptr = ncbi->hdr_ptr;
  if (parse_advance(ncbi, n) != eslOK)         return eslEFORMAT;
  if (str != NULL && len == NULL) return eslEINCOMPAT;
  if (len != NULL) *len = n;
  if (str != NULL) *str = (char *)ptr;
  return eslOK;
}
static int parse_string ( ESL_SQNCBI_DATA * ncbi , char * * str , int * len ) { int n ; unsigned char x ; unsigned char c ; unsigned char * ptr ; if ( parse_expect ( ncbi , " \x1a " , 1 ) != eslOK ) return eslEFORMAT ; if ( parse_consume ( ncbi , & c , 1 ) != eslOK ) return eslEFORMAT ; if ( c < 128 ) { n = c ; } else { c = c & 0x7f ; if ( c > sizeof ( n ) ) return eslEFORMAT ; n = 0 ; while ( c > 0 ) { if ( parse_consume ( ncbi , & x , 1 ) != eslOK ) return eslEFORMAT ; n = ( n << 8 ) + ( unsigned int ) x ; -- c ; } } ptr = ncbi -> hdr_ptr ; if ( parse_advance ( ncbi , n ) != eslOK ) return eslEFORMAT ; if ( str != NULL && len == NULL ) return eslEINCOMPAT ; if ( len != NULL ) * len = n ; if ( str != NULL ) * str = ( char * ) ptr ; return eslOK ; }
Function:  parse_string()
 Synopsis:  Parse a visible string
 Incept:    MSF, Mon Dec 10, 2009 [Janelia]
Function : parse_string () Synopsis : Parse a visible string Incept : MSF Mon Dec 10 2009 [ Janelia ]
/* the next byte is the length of the string.  if the length is
   * less than 128, then this is the true length; otherwise this
   * length describes the number of bytes necessary to hold the
   * true length of the string in the lower 7 bits.
   */ /* validate the length of the string */ /* fill in the values */