hmmer-3.3/easel/esl_sq.c
/* Function:  esl_sq_AppendDesc()
 * Synopsis:  Append a new line to a growing multiline description.
 * Incept:    SRE, Thu May 22 15:33:43 2008 [Janelia]
 *
 * Purpose:   Append line <desc> to the description annotation line
 *            in <sq>. 
 *            
 *            The annotation line <sq->desc> is a single line; it may
 *            not contain \verb+\n+ newlines. Caller is responsible
 *            for making sure <desc> does not terminate in \verb+\n+.
 *            If <sq->desc> already contains a description
 *            line (presumably because we're reading from a file format
 *            that's split the description across multiple lines), 
 *            append a space before adding this next line <desc>.
 *            
 * Returns:   <eslOK> on success.
 *
 * Throws:    <eslEMEM> on allocation failure.
 */
esl_sq_AppendDesc()
Synopsis:  Append a new line to a growing multiline description.

Append line  to the description annotation line
in .

The annotation line desc> is a single line; it may
not contain \verb+\n+ newlines. Caller is responsible
for making sure  does not terminate in \verb+\n+.
If desc> already contains a description
line (presumably because we're reading from a file format
that's split the description across multiple lines),
append a space before adding this next line .

 on success.

 on allocation failure.
esl_sq_AppendDesc () Synopsis : Append a new line to a growing multiline description . Append line to the description annotation line in . The annotation line desc > is a single line ; it may not contain \ verb + \ n + newlines . Caller is responsible for making sure does not terminate in \ verb + \ n + . If desc > already contains a description line ( presumably because we ' re reading from a file format that ' s split the description across multiple lines ) append a space before adding this next line . on success . on allocation failure .
int
esl_sq_AppendDesc(ESL_SQ *sq, const char *desc)
{
  int   dlen   = (sq->desc == NULL ? 0 : strlen(sq->desc));
  int   newlen = (desc     == NULL ? 0 : strlen(desc));
  int   status;
  if (desc == NULL) return eslOK;
  if (sq->desc == NULL || dlen + newlen + 1 >= sq->dalloc) {    
    ESL_REALLOC(sq->desc, sizeof(char) * (newlen+dlen+eslSQ_DESCCHUNK));
    sq->dalloc = newlen+dlen+eslSQ_DESCCHUNK;
  }
  if (dlen > 0) { sq->desc[dlen] = ' '; dlen++; } 
  strcpy(sq->desc + dlen, desc);
  return eslOK;
 ERROR:
  return status;
}
int esl_sq_AppendDesc ( ESL_SQ * sq , const char * desc ) { int dlen = ( sq -> desc == NULL ? 0 : strlen ( sq -> desc ) ) ; int newlen = ( desc == NULL ? 0 : strlen ( desc ) ) ; int status ; if ( desc == NULL ) return eslOK ; if ( sq -> desc == NULL || dlen + newlen + 1 >= sq -> dalloc ) { ESL_REALLOC ( sq -> desc , sizeof ( char ) * ( newlen + dlen + eslSQ_DESCCHUNK ) ) ; sq -> dalloc = newlen + dlen + eslSQ_DESCCHUNK ; } if ( dlen > 0 ) { sq -> desc [ dlen ] = ' ' ; dlen ++ ; } strcpy ( sq -> desc + dlen , desc ) ; return eslOK ; ERROR : return status ; }
Function:  esl_sq_AppendDesc()
 Synopsis:  Append a new line to a growing multiline description.
Function : esl_sq_AppendDesc () Synopsis : Append a new line to a growing multiline description .
// sq->desc == NULL check below is logically unnecessary but it silences zealous static analyzers // +1 for appended space. 