hmmer-3.3/easel/esl_fileparser.c
/* Function:  esl_fileparser_GetTokenOnLine()
 * Incept:    SRE, Tue Apr  3 08:46:59 2007 [Janelia]
 *
 * Purpose:   Same as <esl_fileparser_GetToken()>, except that it only
 *            retrieves tokens from the line that the parser is
 *            on. When it runs out of tokens on the line, it returns
 *            <eslEOL>. This allows a caller to count the tokens on a
 *            line (whereas <GetToken()> reads through newlines
 *            silently).
 *            
 *            The <opt_tok> pointer is into an internal line buffer
 *            that may be invalidated upon the next call to a
 *            <fileparser> function. If you want to store it, make a
 *            copy.
 *            
 *            Normally, a call to <esl_fileparser_GetTokenOnLine()>
 *            would be preceded by <esl_fileparser_NextLine()> to
 *            position the parser on the next data line with at least
 *            one token on it. However, you could also conceivably
 *            call <esl_fileparser_GetTokenOnLine()> after one or more
 *            calls to <esl_fileparser_GetToken()>, to get remaining
 *            tokens from a given line. What you can't do is to call
 *            <esl_fileparser_GetTokenOnLine()> immediately after 
 *            opening a file; the parser won't have a line loaded yet.
 *            (In this case, it would return <eslEOL>.)
 *
 * Returns:   <eslOK> on success, and the token and its length are
 *            in <opt_tok> and <opt_toklen>.
 *            
 *            Returns <eslEOL> if no more tokens exist on the line;
 *            in this case <opt_tok> is set to <NULL> and <opt_toklen>
 *            to 0.
 */
esl_fileparser_GetTokenOnLine()
Incept:    SRE, Tue Apr  3 08:46:59 2007 [Janelia]

Same as , except that it only
retrieves tokens from the line that the parser is
on. When it runs out of tokens on the line, it returns
. This allows a caller to count the tokens on a
line (whereas  reads through newlines
silently).

The  pointer is into an internal line buffer
that may be invalidated upon the next call to a
 function. If you want to store it, make a
copy.

Normally, a call to 
would be preceded by  to
position the parser on the next data line with at least
one token on it. However, you could also conceivably
call  after one or more
calls to , to get remaining
tokens from a given line. What you can't do is to call
 immediately after
opening a file; the parser won't have a line loaded yet.
(In this case, it would return .)

 on success, and the token and its length are
in  and .

Returns  if no more tokens exist on the line;
in this case  is set to  and 
to 0.
esl_fileparser_GetTokenOnLine () Incept : SRE Tue Apr 3 08 : 46 : 59 2007 [ Janelia ] Same as except that it only retrieves tokens from the line that the parser is on . When it runs out of tokens on the line it returns . This allows a caller to count the tokens on a line ( whereas reads through newlines silently ) . The pointer is into an internal line buffer that may be invalidated upon the next call to a function . If you want to store it make a copy . Normally a call to would be preceded by to position the parser on the next data line with at least one token on it . However you could also conceivably call after one or more calls to to get remaining tokens from a given line . What you can ' t do is to call immediately after opening a file ; the parser won ' t have a line loaded yet . ( In this case it would return . ) on success and the token and its length are in and . Returns if no more tokens exist on the line ; in this case is set to and to 0 .
int
esl_fileparser_GetTokenOnLine(ESL_FILEPARSER *efp, char **opt_tok, int *opt_toklen)
{
  char *tok    = NULL;
  int   toklen = 0;
  int status;
  if (efp->buf == NULL) { status = eslEOL;  goto ERROR; }
  status = esl_strtok_adv(&(efp->s), " \t\r\n", &tok, &toklen, NULL);
  if (status == eslEOL) goto ERROR;
  if (status != eslOK)  goto ERROR;
  if (status == eslOK && *tok == efp->commentchar) { status = eslEOL; goto ERROR; }
  if (opt_tok)    *opt_tok    = tok;
  if (opt_toklen) *opt_toklen = toklen;
  return eslOK;
 ERROR:
  if (opt_tok)    *opt_tok    = NULL;
  if (opt_toklen) *opt_toklen = 0;
  return status;
}
int esl_fileparser_GetTokenOnLine ( ESL_FILEPARSER * efp , char * * opt_tok , int * opt_toklen ) { char * tok = NULL ; int toklen = 0 ; int status ; if ( efp -> buf == NULL ) { status = eslEOL ; goto ERROR ; } status = esl_strtok_adv ( & ( efp -> s ) , " \t \r \n " , & tok , & toklen , NULL ) ; if ( status == eslEOL ) goto ERROR ; if ( status != eslOK ) goto ERROR ; if ( status == eslOK && * tok == efp -> commentchar ) { status = eslEOL ; goto ERROR ; } if ( opt_tok ) * opt_tok = tok ; if ( opt_toklen ) * opt_toklen = toklen ; return eslOK ; ERROR : if ( opt_tok ) * opt_tok = NULL ; if ( opt_toklen ) * opt_toklen = 0 ; return status ; }
Function:  esl_fileparser_GetTokenOnLine()
 Incept:    SRE, Tue Apr  3 08:46:59 2007 [Janelia]
Function : esl_fileparser_GetTokenOnLine () Incept : SRE Tue Apr 3 08 : 46 : 59 2007 [ Janelia ]
/* No line loaded? Then we can't find any token on it. */ /* Find next token in the line that's already loaded in the parser. */