RE: [NeoStats-Devel] [Commits] r2594 - in trunk: modules/textserv src

"Justin Hammond" <justin-kLev/[email protected]>
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Can we put something like tsprintf into the core to handle things like
botdetails, etc etc etc?

> +/** @brief tsprintf
> + *
> + *  printf style message function 
> + *
> + *  @param buf Storage location for output. 
> + *  @param fmt Format specification. 
> + *  @param ... to list of arguments. 
> + *
> + *  @return number of characters written excluding terminating null
> + */
> +
> +int tsprintf( char *botname, char *from, char *target, char 
> *buf, const size_t size, const char *fmt, ... )
> +{
> +	static char nullstring[] = "(null)";
> +	size_t len = 0;
> +    char *str;
> +    char c;
> +    va_list args;
> +
> +	va_start( args, fmt );
> +	while( ( c = *fmt++ ) != 0 && ( len < size ) )
> +	{
> +		/* Is it a format string character? */
> +	    if( c == '%' ) 
> +		{
> +			switch( *fmt ) 
> +			{
> +				/* handle %B (botname) */
> +				case 'B': 
> +					str = botname;
> +					/* If NULL string point 
> to our null output string */
> +					if( str == NULL ) {
> +						str = nullstring;
> +					}
> +					/* copy string to 
> output observing limit */
> +					while( *str && len < size ) {
> +						buf[len++] = *str++;
> +					}
> +					/* next char... */
> +					fmt++;
> +					break;
> +				/* handle %F (from) */
> +				case 'F': 
> +					str = from;
> +					/* If NULL string point 
> to our null output string */
> +					if( str == NULL ) {
> +						str = nullstring;
> +					}
> +					/* copy string to 
> output observing limit */
> +					while( *str && len < size ) {
> +						buf[len++] = *str++;
> +					}
> +					/* next char... */
> +					fmt++;
> +					break;
> +				/* handle %T (target) */
> +				case 'T': 
> +					str = target;
> +					/* If NULL string point 
> to our null output string */
> +					if( str == NULL ) {
> +						str = nullstring;
> +					}
> +					/* copy string to 
> output observing limit */
> +					while( *str && len < size ) {
> +						buf[len++] = *str++;
> +					}
> +					/* next char... */
> +					fmt++;
> +					break;
> +				default:
> +					buf[len++] = c;
> +					break;
> +			}
> +		}
> +		/* just copy char from src */
> +		else 
> +		{
> +			buf[len++] = c;
> +	    }
> +	}
> +	/* NULL terminate */
> +	if( len < size ) 
> +		buf[len] = 0;
> +	else
> +		buf[size -1] = 0;
> +	/* return count chars written */
> +    va_end( args );
> +    return len;
> +}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.