rmonprint.c
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#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