/*====================================================================*
 *
 *   void markup (signed fd, signed indent, char const * format, ...);
 *
 *   format.h
 *
 *   write an indented and formatted wtring to the specified device;
 *
 *.  Motley Tools by Charles Maier <cmaier@cmassoc.net>;
 *:  Published 2001-2006 by Charles Maier Associates Limited;
 *;  Released under the GNU General Public Licence v2 and later;
 *
 *--------------------------------------------------------------------*/

#ifndef MARKUP_SOURCE
#define MARKUP_SOURCE

#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>

#include "../tools/format.h"

#ifdef __GNUC__

__attribute__ ((format (printf, 3, 4))) 

#endif

void markup (signed fd, signed indent, char const * format, ...) 

{
	static char tab = '\t';
	static char end = '\n';
	char buffer [1024];
	signed length = 0;
	while (indent-- > 0) 
	{
		write (fd, &tab, sizeof (tab));
	}
	if ((format) && (*format)) 
	{
		va_list arglist;
		va_start (arglist, format);
		length = vsnprintf (buffer, sizeof (buffer), format, arglist);
		va_end (arglist);
	}
	write (fd, buffer, length);
	write (fd, &end, sizeof (end));
	return;
}

#endif