link-grammar-5.8.0/link-grammar/print/print-util.c
/**
 * Append to a dynamic string with vprintf-like formatting.
 * @return The number of appended bytes, or a negative value on error.
 *
 * Note: As in the rest of the LG library, we assume here C99 library
 * compliance (without it, this code would be buggy).
 */
Append to a dynamic string with vprintf-like formatting.
@return The number of appended bytes, or a negative value on error.

As in the rest of the LG library, we assume here C99 library
compliance (without it, this code would be buggy).
Append to a dynamic string with vprintf - like formatting . @return The number of appended bytes or a negative value on error . As in the rest of the LG library we assume here C99 library compliance ( without it this code would be buggy ) .
int vappend_string(dyn_str * string, const char *fmt, va_list args)
{
#define TMPLEN 1024 /* Big enough for a possible error message, see below */
	char temp_buffer[TMPLEN];
	char *temp_string = temp_buffer;
	int templen;
	va_list copy_args;
	va_copy(copy_args, args);
	templen = vsnprintf(temp_string, TMPLEN, fmt, copy_args);
	va_end(copy_args);
	if (templen < 0) goto error;
	if (0)
	{
		if (fmt[0] == '(') { errno=2; goto error;} 
	}
	if (templen >= TMPLEN)
	{
		temp_string = malloc(templen+1);
		templen = vsnprintf(temp_string, templen+1, fmt, args);
		if (templen < 0)
		{
			free(temp_string);
			goto error;
		}
	}
	va_end(args);
	patch_subscript_marks(temp_string);
	dyn_strcat(string, temp_string);
	if (templen >= TMPLEN) free(temp_string);
	return templen;
error:
	{
		const char msg[] = "[vappend_string(): ";
		strcpy(temp_buffer, msg);
		lg_strerror(errno, temp_buffer+sizeof(msg)-1, TMPLEN-sizeof(msg));
		strcat(temp_buffer, "]");
		dyn_strcat(string, temp_buffer);
		va_end(args);
		return templen;
	}
}
int vappend_string ( dyn_str * string , const char * fmt , va_list args ) { #define TMPLEN  1024 /* Big enough for a possible error message, see below */ char temp_buffer [ TMPLEN ] ; char * temp_string = temp_buffer ; int templen ; va_list copy_args ; va_copy ( copy_args , args ) ; templen = vsnprintf ( temp_string , TMPLEN , fmt , copy_args ) ; va_end ( copy_args ) ; if ( templen < 0 ) goto error ; if ( 0 ) { if ( fmt [ 0 ] == ' ' ) { errno = 2 ; goto error ; } } if ( templen >= TMPLEN ) { temp_string = malloc ( templen + 1 ) ; templen = vsnprintf ( temp_string , templen + 1 , fmt , args ) ; if ( templen < 0 ) { free ( temp_string ) ; goto error ; } } va_end ( args ) ; patch_subscript_marks ( temp_string ) ; dyn_strcat ( string , temp_string ) ; if ( templen >= TMPLEN ) free ( temp_string ) ; return templen ; error : { const char msg [ ] = " " ; strcpy ( temp_buffer , msg ) ; lg_strerror ( errno , temp_buffer + sizeof ( msg ) - 1 , TMPLEN - sizeof ( msg ) ) ; strcat ( temp_buffer , " " ) ; dyn_strcat ( string , temp_buffer ) ; va_end ( args ) ; return templen ; } }
Append to a dynamic string with vprintf-like formatting.
Append to a dynamic string with vprintf - like formatting .
/* Test the error reporting. */ /* TMPLEN is too small - use a bigger buffer. This may happen
		 * when printing dictionary words using !! with a wildcard
		 * or when debug-printing all the connectors. */ /* Some error has occurred */