/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

		Routines to do adjustment of output


   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

#include <stdio.h>
#include <varargs.h>
#include "../h/cdefs.h"

printc (va_alist)
va_dcl
{
	int n;
	char *fmt;
	va_list ap;

	va_start(ap);
	n = va_arg(ap, int);
	fmt = va_arg(ap, char*);
	vfprintc (stdout, n, fmt, ap);
	va_end(ap);	
}

fprintc (va_alist)
va_dcl
{
	FILE *fp;
	int n;
	char *fmt;
	va_list ap;

	va_start(ap);
	fp = va_arg(ap, FILE*);
	n = va_arg(ap, int);
	fmt = va_arg(ap, char*);
	vfprintc (fp, n, fmt, ap);
	va_end(ap);	
}

#define OBUFSIZE	256

vfprintc (fp, n, fmt, ap)
FILE *fp;
int n;
char *fmt;
va_list ap;
{
	char buf[OBUFSIZE+1];
	char *cp;
	int k, diff;
	
	vsnprintf (buf, OBUFSIZE, fmt, ap);
	if ((diff = ABS(n) - strlen(buf)) > 0)
	 { if (n < 0)
	    { for (cp = buf; *cp != '\0'; cp++)
	       { putc (*cp, fp);
	       }
	      for (k=0; k<diff; k++)
	       { putc (' ', fp);
	       }
	    }
	   else
	    { for (k=0; k<diff; k++)
	       { putc (' ', fp);
	       }
	      for (cp = buf; *cp != '\0'; cp++)
	       { putc (*cp, fp);
	       }
	    }	      
	 }
}
