rmonprint.c 1.91 KB
#if 0   /* rmonPrintf no longer supported !! */

/* rmonPrintf function */

#include "xstdio.h"
#include "rmon.h"
#include "dbgdefs.h"
#include "dbgproto.h"
#include "rmonint.h"

/* This is required by Plauger's book for royalty-free usage */
/* Portions of this work are derived from the Standard C Library, */
/* copyright (c) 1992 by P.J. Plauger, published by Prentice-Hall, */
/* and are used with permission. */


static char rmonHoldWord[4];
static char rmonHoldCount = 0;
static int column = 0;

static void *proutPrintf(void *, const char *, size_t);
static void putchar(char);
static void rmonPutchar(char);
static void rmonFlush(void);

void rmonPrintf(const char *fmt, ...)
{
	/* print formatted to stdout */
	int ans;
	va_list ap;

	if (osGetThreadPri(0) < 128)
		__rmonAcquirePrintf();
	va_start(ap, fmt);
	ans = _Printf(&proutPrintf, NULL, fmt, ap);
	va_end(ap);
	rmonFlush();
	if (osGetThreadPri(0) < 128)
		__rmonReleasePrintf();
}

static void *proutPrintf(void *str, const char *buf, size_t n)
{
	/* write to file */
	/* return (fwrite(buf, 1, n, str) == n ? str : NULL);*/
	int i;

	for (i = 0; i < n; i++)
		putchar(buf[i]);
	return ((void *) 1);   /* return a fake pointer so that it's not NULL */
}

static void putchar(char c)
{
	switch (c) {
	case '\n':
		rmonPutchar('\n');
		/* Unix systems only expect a line feed.
		rmonPutchar('\r');
		*/
		rmonFlush();
		column = 0;
		break;
	case '\t':
		do {
			rmonPutchar(' ');
		} while (++column % 8);
		break;
	default:
		/* if ((c >= 32) && (c < 127)) { */
			column++;
			rmonPutchar(c);
		/* } */
		break;
	}
}

static void rmonPutchar(char c)
{
	rmonHoldWord[rmonHoldCount++] = c;
	if (rmonHoldCount == 4) {
		__rmonPputw(*(int *) rmonHoldWord);
		rmonHoldCount = 0;
	}
}

static void rmonFlush(void)
{
	if (rmonHoldCount) {
		while (rmonHoldCount < 4)
			rmonHoldWord[rmonHoldCount++] = 0;
		__rmonPputw(*(int *) rmonHoldWord);
		rmonHoldCount = 0;
	}
	__rmonPflush();
}

#endif