forked from akjmicro/dclang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_ops.c
97 lines (89 loc) · 2.2 KB
/
output_ops.c
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
/* output */
void showfunc()
{
if (data_stack_ptr < 1) {
printf(". (pop) -- stack underflow! ");
return;
}
fprintf(ofp, "%0.19g ", dclang_pop());
fflush(ofp);
}
void shownospacefunc()
{
if (data_stack_ptr < 1) {
printf("stack underflow! ");
return;
}
fprintf(ofp, "%0.19g", dclang_pop());
fflush(ofp);
}
void crfunc()
{
fprintf(ofp, "\n");
}
void showstackfunc()
{
DCLANG_INT x;
char *joiner;
x = data_stack_ptr > 16 ? data_stack_ptr - 16 : 0;
joiner = x == 0 ? " " : " ... ";
fprintf(ofp, "data_stack: <%lu>%s", data_stack_ptr, joiner);
fflush(ofp);
for (x=0; x < data_stack_ptr; x++) {
fprintf(ofp, "%0.19g ", data_stack[x]);
fflush(ofp);
}
fprintf(ofp, "\n");
// do the save data stack as well:
DCLANG_INT y;
char *sv_joiner;
y = save_data_stack_ptr > 16 ? save_data_stack_ptr - 16 : 0;
sv_joiner = y == 0 ? " " : " ... ";
fprintf(ofp, "save_stack: <%lu>%s", save_data_stack_ptr, sv_joiner);
fflush(ofp);
for (y=0; y < save_data_stack_ptr; y++) {
fprintf(ofp, "%0.19g ", save_data_stack[y]);
fflush(ofp);
}
fprintf(ofp, "\n");
}
void showrjfunc()
{
if (data_stack_ptr < 3) {
printf("Stack underflow! '.rj' needs: value, width, precision on the stack\n");
return;
}
// right-justified for pretty printing!
int precision = (DCLANG_INT) dclang_pop();
int width = (DCLANG_INT) dclang_pop();
fprintf(ofp, "%*.*f ", width, precision, dclang_pop());
fflush(ofp);
}
void showpzfunc()
{
// left pad with zeros
if (data_stack_ptr < 3) {
printf("Stack underflow! '.pz' needs: value, width, precision on the stack\n");
return;
}
int precision = (DCLANG_INT) dclang_pop();
int width = (DCLANG_INT) dclang_pop();
fprintf(ofp, "%0*.*f ", width, precision, dclang_pop());
fflush(ofp);
}
void redirectfunc()
{
if (data_stack_ptr < 1) {
printf("Stack underflow! 'redirect' needs an output file pointer before being called\n");
return;
}
ofp = (FILE *)(DCLANG_PTR) dclang_pop();
}
void resetoutfunc()
{
ofp = stdout;
}
void flushoutfunc()
{
fflush(ofp);
}