-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
executable file
·145 lines (137 loc) · 2.94 KB
/
print.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "lisp.h"
#include "error.h"//N//
#include "print.h"
#include "read.h"//N//
#include "save.h"
#include <ctype.h>
#define forever for(;;)
#define ISCELL1P(x) (C1 <= (x) && (x) < C1 + (CELLSIZ / 2))
#define ISATOM1P(x) (A1 <= (x) && (x) < A1 + (ATOMSIZ / 2))
#define ISNUM1P(x) (N1 <= (x) && (x) < N1 + (NUMSIZ / 2))
#define ISCELL2P(x) (C2 <= (x) && (x) < C2 + (CELLSIZ / 2))
#define ISATOM2P(x) (A2 <= (x) && (x) < A2 + (ATOMSIZ / 2))
#define ISNUM2P(x) (N2 <= (x) && (x) < N2 + (NUMSIZ / 2))
#define ISOLDCELLP(x) (old_freecelltop <= (x) && (x) < old_freecelltop + CELLSIZ)
#define ISOLDATOMP(x) (old_freeatomtop <= (x) && (x) < old_freeatomtop + ATOMSIZ)
#define ISOLDNUMP(x) (old_freenumtop <= (x) && (x) < old_freenumtop + NUMSIZ)
#define ISSYSATOMP(x) (freesysatom <= (x) && (x) < freesysatom + SYSATOMS)
static void putstr(int mode, STR tp);//N//
void pp(void* cp)
{
char* c = "E";
if(ISOLDATOMP((ATOMP)cp))
{
c = "A";
}
else if(ISOLDCELLP(cp))
{
c = "C";
}
else if(ISOLDNUMP((NUMP)cp))
{
c = "N";
}
else if(ISCELL1P(cp))
{
c = "c1";
}
else if(ISATOM1P((ATOMP)cp))
{
c = "a1";
}
else if(ISNUM1P((NUMP)cp))
{
c = "n1";
}
else if(ISCELL2P(cp))
{
c = "c2";
}
else if(ISATOM2P((ATOMP)cp))
{
c = "a2";
}
else if(ISNUM2P((NUMP)cp))
{
c = "n2";
}
else if(ISSYSATOMP(cp))
{
c = "S";
}
else
{
c = "O";
}
printf("[%p:%s]", cp, c);
}
void print_s(CELLP cp, int mode) {
//printf("[print_s: id=%x]", (int)cp->id);
if(cp->id != _CELL) {
pri_atom(cp, mode);
}
else {
//fprintf(cur_fpo, "[%p]", cp);
//pp(cp);
fputc('(', cur_fpo);
forever{
print_s(cp->car, mode);
cp = cp->cdr;
if(cp->id != _CELL) {
break;
}
fputc(' ', cur_fpo);
//fprintf(cur_fpo, "cdr[%p]", cp);
//printf("-cdr-");
//pp(cp);
}
if(cp != (CELLP)nil) {
fprintf(cur_fpo, " . ");
pri_atom(cp,mode);
}
fputc(')', cur_fpo);
}
}
void pri_atom(CELLP cp, int mode) {
//fprintf(cur_fpo, "[%p]", cp);
//pp(cp);
switch(cp->id) {
case _FIX:
fprintf(cur_fpo, "%ld", ((NUMP)cp)->value.fix);
break;
case _FLT:
fprintf(cur_fpo, "%#.6g", ((NUMP)cp)->value.flt);
break;
case _ATOM:
putstr(mode, ((ATOMP)cp)->name);
//printf("fptr(%p):", ((ATOMP)cp)->fptr);
//if(((ATOMP)cp)->ftype == _EXPR) print_s(((ATOMP)cp)->fptr->car, ESCOFF);
break;
default:
error(ULO);
}
}
static void putstr(int mode, STR tp) {//N//
if(mode == ESCOFF) {
fprintf(cur_fpo, "%s", tp);
} else if(*tp == '\0') {
fprintf(cur_fpo, "||");
} else {
if(num(tp)) {
fputc('\\', cur_fpo);
}
do {
if(iskanji(*tp) && iskanji2(*(tp+1))) {
fputc(*tp++, cur_fpo);
fputc(*tp++, cur_fpo);
} else if(!isprkana(*tp)) {
fprintf(cur_fpo, "#\\%03d", *tp++);
} else {
if(isesc(*tp)) {
fputc('\\', cur_fpo);
}
fputc(*tp++, cur_fpo);
}
} while(*tp != '\0');
}
}