~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to o/print.d

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
14
License for more details.
 
15
 
 
16
You should have received a copy of the GNU Library General Public License 
 
17
along with GCL; see the file COPYING.  If not, write to the Free Software
 
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
/*
 
22
        print.d
 
23
*/
 
24
 
 
25
#define NEED_ISFINITE
 
26
 
 
27
#include "include.h"
 
28
#include <unistd.h>
 
29
 
 
30
#define LINE_LENGTH line_length
 
31
int  line_length = 72;
 
32
 
 
33
#ifndef WRITEC_NEWLINE
 
34
#define  WRITEC_NEWLINE(strm) (writec_stream('\n',strm))
 
35
#endif
 
36
 
 
37
#define to_be_escaped(c) \
 
38
        (standard_readtable->rt.rt_self[(c)&0377].rte_chattrib \
 
39
         != cat_constituent || \
 
40
         isLower((c)&0377) || (c) == ':')
 
41
 
 
42
 
 
43
#define mod(x)          ((x)%Q_SIZE)
 
44
 
 
45
 
 
46
#define queue printStructBufp->p_queue
 
47
#define indent_stack printStructBufp->p_indent_stack
 
48
#define qh printStructBufp->p_qh
 
49
#define qt printStructBufp->p_qt
 
50
#define qc printStructBufp->p_qc
 
51
#define isp printStructBufp->p_isp
 
52
#define iisp printStructBufp->p_iisp
 
53
 
 
54
 
 
55
object sSAprint_packageA;
 
56
object sSAprint_structureA;
 
57
 
 
58
 
 
59
/* bool RPINcircle; ??typo?? */
 
60
 
 
61
 
 
62
 
 
63
#define write_ch        (*write_ch_fun)
 
64
 
 
65
 
 
66
#define MARK            0400
 
67
#define UNMARK          0401
 
68
#define SET_INDENT      0402
 
69
#define INDENT          0403
 
70
#define INDENT1         0404
 
71
#define INDENT2         0405
 
72
 
 
73
extern object coerce_stream(object,int);
 
74
 
 
75
static void
 
76
flush_queue(int);
 
77
 
 
78
static void
 
79
writec_queue(c)
 
80
int c;
 
81
{
 
82
        if (qc >= Q_SIZE)
 
83
                flush_queue(FALSE);
 
84
        if (qc >= Q_SIZE)
 
85
                FEerror("Can't pretty-print.", 0);
 
86
        queue[qt] = c;
 
87
        qt = mod(qt+1);
 
88
        qc++;
 
89
}
 
90
 
 
91
static void
 
92
flush_queue(int force)
 
93
{
 
94
        int c, i, j, k, l, i0;
 
95
 
 
96
BEGIN:
 
97
        while (qc > 0) {
 
98
                c = queue[qh];
 
99
                if (c == MARK)
 
100
                        goto MDO_MARK;
 
101
                else if (c == UNMARK)
 
102
                        isp -= 2;
 
103
                else if (c == SET_INDENT)
 
104
                        indent_stack[isp] = file_column(PRINTstream);
 
105
                else if (c == INDENT) {
 
106
                        goto MDO_INDENT;
 
107
                } else if (c == INDENT1) {
 
108
                        i = file_column(PRINTstream)-indent_stack[isp];
 
109
                        if (i < 8 && indent_stack[isp] < LINE_LENGTH/2) {
 
110
                                writec_stream(' ', PRINTstream);
 
111
                                indent_stack[isp]
 
112
                                = file_column(PRINTstream);
 
113
                        } else {
 
114
                                if (indent_stack[isp] < LINE_LENGTH/2) {
 
115
                                        indent_stack[isp]
 
116
                                        = indent_stack[isp-1] + 4;
 
117
                                }
 
118
                                goto MDO_INDENT;
 
119
                        }
 
120
                } else if (c == INDENT2) {
 
121
                        indent_stack[isp] = indent_stack[isp-1] + 2;
 
122
                        goto PUT_INDENT;
 
123
                } else if (c < 0400)
 
124
                        writec_stream(c, PRINTstream);
 
125
                qh = mod(qh+1);
 
126
                --qc;
 
127
        }
 
128
        return;
 
129
 
 
130
MDO_MARK:
 
131
        k = LINE_LENGTH - 1 - file_column(PRINTstream);
 
132
        for (i = 1, j = 0, l = 1;  l > 0 && i < qc && j < k;  i++) {
 
133
                c = queue[mod(qh + i)];
 
134
                if (c == MARK)
 
135
                        l++;
 
136
                else if (c == UNMARK)
 
137
                        --l;
 
138
                else if (c == INDENT || c == INDENT1 || c == INDENT2)
 
139
                        j++;
 
140
                else if (c < 0400)
 
141
                        j++;
 
142
        }
 
143
        if (l == 0)
 
144
                goto FLUSH;
 
145
        if (i == qc && !force)
 
146
                return;
 
147
        qh = mod(qh+1);
 
148
        --qc;
 
149
        if (++isp >= IS_SIZE-1)
 
150
                FEerror("Can't pretty-print.", 0);
 
151
        indent_stack[isp++] = file_column(PRINTstream);
 
152
        indent_stack[isp] = indent_stack[isp-1];
 
153
        goto BEGIN;
 
154
 
 
155
MDO_INDENT:
 
156
        if (iisp > isp)
 
157
                goto PUT_INDENT;
 
158
        k = LINE_LENGTH - 1 - file_column(PRINTstream);
 
159
        for (i0 = 0, i = 1, j = 0, l = 1;  i < qc && j < k;  i++) {
 
160
                c = queue[mod(qh + i)];
 
161
                if (c == MARK)
 
162
                        l++;
 
163
                else if (c == UNMARK) {
 
164
                        if (--l == 0)
 
165
                                goto FLUSH;
 
166
                } else if (c == SET_INDENT) {
 
167
                        if (l == 1)
 
168
                                break;
 
169
                } else if (c == INDENT) {
 
170
                        if (l == 1)
 
171
                                i0 = i;
 
172
                        j++;
 
173
                } else if (c == INDENT1) {
 
174
                        if (l == 1)
 
175
                                break;
 
176
                        j++;
 
177
                } else if (c == INDENT2) {
 
178
                        if (l == 1) {
 
179
                                i0 = i;
 
180
                                break;
 
181
                        }
 
182
                        j++;
 
183
                } else if (c < 0400)
 
184
                        j++;
 
185
        }
 
186
        if (i == qc && !force)
 
187
                return;
 
188
        if (i0 == 0)
 
189
                goto PUT_INDENT;
 
190
        i = i0;
 
191
        goto FLUSH;
 
192
 
 
193
PUT_INDENT:
 
194
        qh = mod(qh+1);
 
195
        --qc;
 
196
        
 
197
        WRITEC_NEWLINE(PRINTstream);
 
198
        for (i = indent_stack[isp];  i > 0;  --i)
 
199
                writec_stream(' ', PRINTstream);
 
200
        iisp = isp;
 
201
        goto BEGIN;
 
202
 
 
203
FLUSH:
 
204
        for (j = 0;  j < i;  j++) {
 
205
                c = queue[qh];
 
206
                if (c == INDENT || c == INDENT1 || c == INDENT2)
 
207
                        writec_stream(' ', PRINTstream);
 
208
                else if (c < 0400)
 
209
                        writec_stream(c, PRINTstream);
 
210
                qh = mod(qh+1);
 
211
                --qc;
 
212
        }
 
213
        goto BEGIN;
 
214
}
 
215
 
 
216
void
 
217
writec_PRINTstream(c)
 
218
int c;
 
219
{
 
220
        if (c == INDENT || c == INDENT1)
 
221
                writec_stream(' ', PRINTstream);
 
222
        else if (c < 0400)
 
223
                writec_stream(c, PRINTstream);
 
224
}
 
225
 
 
226
void
 
227
write_str(s)
 
228
char *s;
 
229
{
 
230
        while (*s != '\0')
 
231
                write_ch(*s++);
 
232
}
 
233
 
 
234
static void
 
235
write_decimal1(int);
 
236
 
 
237
static void
 
238
write_decimal(i)
 
239
int i;
 
240
{
 
241
        if (i == 0) {
 
242
                write_ch('0');
 
243
                return;
 
244
        }
 
245
        write_decimal1(i);
 
246
}
 
247
 
 
248
static void
 
249
write_decimal1(i)
 
250
int i;
 
251
{
 
252
        if (i == 0)
 
253
                return;
 
254
        write_decimal1(i/10);
 
255
        write_ch(i%10 + '0');
 
256
}
 
257
 
 
258
static void
 
259
write_addr(x)
 
260
object x;
 
261
{
 
262
        long i;
 
263
        int j, k;
 
264
 
 
265
        i = (long)x;
 
266
        for (j = 8*sizeof(i)-4;  j >= 0;  j -= 4) {
 
267
                k = (i>>j) & 0xf;
 
268
                if (k < 10)
 
269
                        write_ch('0' + k);
 
270
                else
 
271
                        write_ch('a' + k - 10);
 
272
        }
 
273
}
 
274
 
 
275
static void
 
276
write_base(void)
 
277
{
 
278
        if (PRINTbase == 2)
 
279
                write_str("#b");
 
280
        else if (PRINTbase == 8)
 
281
                write_str("#o");
 
282
        else if (PRINTbase == 16)
 
283
                write_str("#x");
 
284
        else if (PRINTbase >= 10) {
 
285
                write_ch('#');
 
286
                write_ch(PRINTbase/10+'0');
 
287
                write_ch(PRINTbase%10+'0');
 
288
                write_ch('r');
 
289
        } else {
 
290
                write_ch('#');
 
291
                write_ch(PRINTbase+'0');
 
292
                write_ch('r');
 
293
        }
 
294
}
 
295
 
 
296
/* The floating point precision required to make the most-positive-long-float
 
297
   printed expression readable.   If this is too small, then the rounded
 
298
   off fraction, may be too big to read */
 
299
 
 
300
#ifndef FPRC 
 
301
#define FPRC 16
 
302
#endif
 
303
 
 
304
object sSAprint_nansA;
 
305
 
 
306
void
 
307
edit_double(n, d, sp, s, ep)
 
308
int n;
 
309
double d;
 
310
char *s;
 
311
int *sp;
 
312
int *ep;
 
313
{
 
314
        char *p, buff[FPRC + 9];
 
315
        int i;
 
316
 
 
317
#ifdef IEEEFLOAT
 
318
/*      if ((*((int *)&d +HIND) & 0x7ff00000) == 0x7ff00000)*/
 
319
        if (!ISFINITE(d))
 
320
           {if (sSAprint_nansA->s.s_dbind !=Cnil)
 
321
              {sprintf(s, "%e",d);
 
322
               *sp = 2;
 
323
               return;
 
324
             }
 
325
           else
 
326
                FEerror("Can't print a non-number.",
 
327
                        0);}
 
328
        else
 
329
                sprintf(buff, "%*.*e",FPRC+8,FPRC, d);
 
330
        if (buff[FPRC+3] != 'e') {
 
331
                sprintf(buff, "%*.*e",FPRC+7,FPRC,d);
 
332
                *ep = (buff[FPRC+5]-'0')*10 + (buff[FPRC+6]-'0');
 
333
        } else
 
334
                *ep = (buff[FPRC+5]-'0')*100 +
 
335
                  (buff[FPRC+6]-'0')*10 + (buff[FPRC+7]-'0');
 
336
        *sp = 1;
 
337
        if (buff[0] == '-')
 
338
                *sp *= -1;
 
339
#else
 
340
        sprintf(buff, "%*.*e",FPRC+7,FPRC, d);
 
341
        /*  "-D.MMMMMMMMMMMMMMMe+EE"  */
 
342
        /*   0123456789012345678901   */
 
343
        *sp = 1;
 
344
        if (buff[0] == '-')
 
345
                *sp *= -1;
 
346
        *ep = (buff[FPRC+5]-'0')*10 + (buff[FPRC+6]-'0');
 
347
#endif
 
348
 
 
349
        if (buff[FPRC+4] == '-')
 
350
                *ep *= -1;
 
351
        buff[2] = buff[1];
 
352
        p = buff + 2;
 
353
        if (n < FPRC+1) {
 
354
                if (p[n] >= '5') {
 
355
                        for (i = n - 1;  i >= 0;  --i)
 
356
                                if (p[i] == '9')
 
357
                                        p[i] = '0';
 
358
                                else {
 
359
                                        p[i]++;
 
360
                                        break;
 
361
                                }
 
362
                        if (i < 0) {
 
363
                                *--p = '1';
 
364
                                (*ep)++;
 
365
                        }
 
366
                }
 
367
                for (i = 0;  i < n;  i++)
 
368
                        s[i] = p[i];
 
369
        } else {
 
370
                for (i = 0;  i < FPRC+1;  i++)
 
371
                        s[i] = p[i];
 
372
                for (;  i < n;  i++)
 
373
                        s[i] = '0';
 
374
        }
 
375
        s[n] = '\0';
 
376
}
 
377
 
 
378
static void
 
379
write_double(d, e, shortp)
 
380
double d;
 
381
int e;
 
382
bool shortp;
 
383
{
 
384
        int sign;
 
385
        char buff[FPRC+5];
 
386
        int exp;
 
387
        int i;
 
388
        int n = FPRC+1;
 
389
 
 
390
        if (shortp)
 
391
                n = 7;
 
392
        edit_double(n, d, &sign, buff, &exp);
 
393
        if (sign==2) {write_str("#<");
 
394
                      write_str(buff);
 
395
                      write_ch('>');
 
396
                      return;
 
397
                    }
 
398
        if (sign < 0)
 
399
                write_ch('-');
 
400
        if (-3 <= exp && exp < 7) {
 
401
                if (exp < 0) {
 
402
                        write_ch('0');
 
403
                        write_ch('.');
 
404
                        exp = (-exp) - 1;
 
405
                        for (i = 0;  i < exp;  i++)
 
406
                                write_ch('0');
 
407
                        for (;  n > 0;  --n)
 
408
                                if (buff[n-1] != '0')
 
409
                                        break;
 
410
                        if (exp == 0 && n == 0)
 
411
                                n = 1;
 
412
                        for (i = 0;  i < n;  i++)
 
413
                                write_ch(buff[i]);
 
414
                } else {
 
415
                        exp++;
 
416
                        for (i = 0;  i < exp;  i++)
 
417
                                if (i < n)
 
418
                                        write_ch(buff[i]);
 
419
                                else
 
420
                                        write_ch('0');
 
421
                        write_ch('.');
 
422
                        if (i < n)
 
423
                                write_ch(buff[i]);
 
424
                        else
 
425
                                write_ch('0');
 
426
                        i++;
 
427
                        for (;  n > i;  --n)
 
428
                                if (buff[n-1] != '0')
 
429
                                        break;
 
430
                        for (;  i < n;  i++)
 
431
                                write_ch(buff[i]);
 
432
                }
 
433
                exp = 0;
 
434
        } else {
 
435
                write_ch(buff[0]);
 
436
                write_ch('.');
 
437
                write_ch(buff[1]);
 
438
                for (;  n > 2;  --n)
 
439
                        if (buff[n-1] != '0')
 
440
                                break;
 
441
                for (i = 2;  i < n;  i++)
 
442
                        write_ch(buff[i]);
 
443
        }
 
444
        if (exp == 0 && e == 0)
 
445
                return;
 
446
        if (e == 0)
 
447
                e = 'E';
 
448
        write_ch(e);
 
449
        if (exp < 0) {
 
450
                write_ch('-');
 
451
                exp *= -1;
 
452
        }
 
453
        write_decimal(exp);
 
454
}
 
455
 
 
456
static void
 
457
call_structure_print_function(x, level)
 
458
object x;
 
459
int level;
 
460
{
 
461
        int i;
 
462
        bool eflag;
 
463
        bds_ptr old_bds_top;
 
464
 
 
465
        void (*wf)(int) = write_ch_fun;
 
466
 
 
467
        object *vt = PRINTvs_top;
 
468
        object *vl = PRINTvs_limit;
 
469
        bool e = PRINTescape;
 
470
        bool ra = PRINTreadably;
 
471
        bool r = PRINTradix;
 
472
        int b = PRINTbase;
 
473
        bool c = PRINTcircle;
 
474
        bool p = PRINTpretty;
 
475
        int lv = PRINTlevel;
 
476
        int ln = PRINTlength;
 
477
        bool g = PRINTgensym;
 
478
        bool a = PRINTarray;
 
479
 
 
480
/*
 
481
        short oq[Q_SIZE];
 
482
*/
 
483
        short ois[IS_SIZE];
 
484
 
 
485
        int oqh;
 
486
        int oqt;
 
487
        int oqc;
 
488
        int oisp;
 
489
        int oiisp;
 
490
 
 
491
ONCE_MORE:
 
492
        if (interrupt_flag) {
 
493
                interrupt_flag = FALSE;
 
494
#ifdef UNIX
 
495
                alarm(0);
 
496
#endif
 
497
                terminal_interrupt(TRUE);
 
498
                goto ONCE_MORE;
 
499
        }
 
500
 
 
501
        if (PRINTpretty)
 
502
                flush_queue(TRUE);
 
503
 
 
504
        oqh = qh;
 
505
        oqt = qt;
 
506
        oqc = qc;
 
507
        oisp = isp;
 
508
        oiisp = iisp;
 
509
 
 
510
/*      No need to save the queue, since it is flushed.
 
511
        for (i = 0;  i < Q_SIZE;  i++)
 
512
                oq[i] = queue[i];
 
513
*/
 
514
        if (PRINTpretty)
 
515
        for (i = 0;  i <= isp;  i++)
 
516
                ois[i] = indent_stack[i];
 
517
 
 
518
        vs_push(PRINTstream);
 
519
        vs_push(PRINTcase);
 
520
 
 
521
        vs_push(make_fixnum(level));
 
522
 
 
523
        old_bds_top = bds_top;
 
524
        bds_bind(sLAprint_escapeA, PRINTescape?Ct:Cnil);
 
525
        bds_bind(sLAprint_readablyA, PRINTreadably?Ct:Cnil);
 
526
        bds_bind(sLAprint_radixA, PRINTradix?Ct:Cnil);
 
527
        bds_bind(sLAprint_baseA, make_fixnum(PRINTbase));
 
528
        bds_bind(sLAprint_circleA, PRINTcircle?Ct:Cnil);
 
529
        bds_bind(sLAprint_prettyA, PRINTpretty?Ct:Cnil);
 
530
        bds_bind(sLAprint_levelA, PRINTlevel<0?Cnil:make_fixnum(PRINTlevel));
 
531
        bds_bind(sLAprint_lengthA, PRINTlength<0?Cnil:make_fixnum(PRINTlength));
 
532
        bds_bind(sLAprint_gensymA, PRINTgensym?Ct:Cnil);
 
533
        bds_bind(sLAprint_arrayA, PRINTarray?Ct:Cnil);
 
534
        bds_bind(sLAprint_caseA, PRINTcase);
 
535
 
 
536
        frs_push(FRS_PROTECT, Cnil);
 
537
        if (nlj_active) {
 
538
                eflag = TRUE;
 
539
                goto L;
 
540
        }
 
541
 
 
542
        ifuncall3(S_DATA(x->str.str_def)->print_function,
 
543
                  x, PRINTstream, vs_head);
 
544
        vs_popp;
 
545
        eflag = FALSE;
 
546
 
 
547
L:
 
548
        frs_pop();
 
549
        bds_unwind(old_bds_top);
 
550
 
 
551
/*
 
552
        for (i = 0;  i < Q_SIZE;  i++)
 
553
                queue[i] = oq[i];
 
554
*/
 
555
        if (PRINTpretty)
 
556
        for (i = 0;  i <= oisp;  i++)
 
557
                indent_stack[i] = ois[i];
 
558
 
 
559
        iisp = oiisp;
 
560
        isp = oisp;
 
561
        qc = oqc;
 
562
        qt = oqt;
 
563
        qh = oqh;
 
564
 
 
565
        PRINTcase = vs_pop;
 
566
        PRINTstream = vs_pop;
 
567
        PRINTarray = a;
 
568
        PRINTgensym = g;
 
569
        PRINTlength = ln;
 
570
        PRINTlevel = lv;
 
571
        PRINTpretty = p;
 
572
        PRINTcircle = c;
 
573
        PRINTbase = b;
 
574
        PRINTradix = r;
 
575
        PRINTescape = e;
 
576
        PRINTreadably = ra;
 
577
        PRINTvs_limit = vl;
 
578
        PRINTvs_top = vt;
 
579
 
 
580
        write_ch_fun = wf;
 
581
 
 
582
        if (eflag) {
 
583
                nlj_active = FALSE;
 
584
                unwind(nlj_fr, nlj_tag);
 
585
        }
 
586
}
 
587
object copy_big();
 
588
object coerce_big_to_string(object,int);
 
589
 
 
590
static bool
 
591
potential_number_p(object,int);
 
592
 
 
593
void
 
594
write_object(x, level)
 
595
object x;
 
596
int level;
 
597
{
 
598
        object r, y;
 
599
        int i, j, k,lw;
 
600
        object *vp;
 
601
 
 
602
        cs_check(x);
 
603
 
 
604
        if (x == OBJNULL) {
 
605
                write_str("#<OBJNULL>");
 
606
                return;
 
607
        }
 
608
        if (x->d.m == FREE) {
 
609
                write_str("#<FREE OBJECT ");
 
610
                write_addr(x);
 
611
                write_str(">");
 
612
                return;
 
613
        }
 
614
 
 
615
        switch (type_of(x)) {
 
616
 
 
617
        case t_fixnum:
 
618
        {
 
619
                object *vsp;
 
620
 
 
621
                if (PRINTradix && PRINTbase != 10)
 
622
                        write_base();
 
623
                i = fix(x);
 
624
                if (i == 0) {
 
625
                        write_ch('0');
 
626
                        if (PRINTradix && PRINTbase == 10)
 
627
                                write_ch('.');
 
628
                        break;
 
629
                }
 
630
                if (i < 0) {
 
631
                        write_ch('-');
 
632
                        if (i == MOST_NEG_FIXNUM) {
 
633
                                x = fixnum_add(1,(MOST_POSITIVE_FIXNUM));
 
634
                                vs_push(x);
 
635
                                i = PRINTradix;
 
636
                                PRINTradix = FALSE;
 
637
                                write_object(x, level);
 
638
                                PRINTradix = i;
 
639
                                vs_popp;
 
640
                                if (PRINTradix && PRINTbase == 10)
 
641
                                        write_ch('.');
 
642
                                break;
 
643
                        }
 
644
                        i = -i;
 
645
                }
 
646
                vsp = vs_top;
 
647
                for (vsp = vs_top;  i != 0;  i /= PRINTbase)
 
648
                        vs_push(code_char(digit_weight(i%PRINTbase,
 
649
                                                       PRINTbase)));
 
650
                while (vs_top > vsp)
 
651
                        write_ch(char_code((vs_pop)));
 
652
                if (PRINTradix && PRINTbase == 10)
 
653
                        write_ch('.');
 
654
                break;
 
655
        }
 
656
 
 
657
        case t_bignum:
 
658
        {
 
659
                if (PRINTradix && PRINTbase != 10)
 
660
                        write_base();
 
661
                i = big_sign(x);
 
662
                if (i == 0) {
 
663
                        write_ch('0');
 
664
                        if (PRINTradix && PRINTbase == 10)
 
665
                                write_ch('.');
 
666
                        break;
 
667
                }
 
668
                { object s = coerce_big_to_string(x,PRINTbase);
 
669
                  int i=0;
 
670
                  while (i<s->ust.ust_fillp) { write_ch(s->ust.ust_self[i++]); }
 
671
                 } 
 
672
                if (PRINTradix && PRINTbase == 10)
 
673
                        write_ch('.');
 
674
                break;
 
675
        }
 
676
 
 
677
        case t_ratio:
 
678
                if (PRINTradix) {
 
679
                        write_base();
 
680
                        PRINTradix = FALSE;
 
681
                        write_object(x->rat.rat_num, level);
 
682
                        write_ch('/');
 
683
                        write_object(x->rat.rat_den, level);
 
684
                        PRINTradix = TRUE;
 
685
                } else {
 
686
                        write_object(x->rat.rat_num, level);
 
687
                        write_ch('/');
 
688
                        write_object(x->rat.rat_den, level);
 
689
                }
 
690
                break;
 
691
 
 
692
        case t_shortfloat:
 
693
                r = symbol_value(sLAread_default_float_formatA);
 
694
                if (r == sLshort_float)
 
695
                        write_double((double)sf(x), 0, TRUE);
 
696
                else
 
697
                        write_double((double)sf(x), 'S', TRUE);
 
698
                break;
 
699
 
 
700
        case t_longfloat:
 
701
                r = symbol_value(sLAread_default_float_formatA);
 
702
                if (r == sLsingle_float ||
 
703
                    r == sLlong_float || r == sLdouble_float)
 
704
                        write_double(lf(x), 0, FALSE);
 
705
                else
 
706
                        write_double(lf(x), 'F', FALSE);
 
707
                break;
 
708
 
 
709
        case t_complex:
 
710
                write_str("#C(");
 
711
                write_object(x->cmp.cmp_real, level);
 
712
                write_ch(' ');
 
713
                write_object(x->cmp.cmp_imag, level);
 
714
                write_ch(')');
 
715
                break;
 
716
 
 
717
        case t_character:
 
718
                if (!PRINTescape) {
 
719
                        write_ch(char_code(x));
 
720
                        break;
 
721
                }
 
722
                write_str("#\\");
 
723
                switch (char_code(x)) {
 
724
                case '\r':
 
725
                        write_str("Return");
 
726
                        break;
 
727
 
 
728
                case ' ':
 
729
                        write_str("Space");
 
730
                        break;
 
731
 
 
732
                case '\177':
 
733
                        write_str("Rubout");
 
734
                        break;
 
735
 
 
736
                case '\f':
 
737
                        write_str("Page");
 
738
                        break;
 
739
 
 
740
                case '\t':
 
741
                        write_str("Tab");
 
742
                        break;
 
743
 
 
744
                case '\b':
 
745
                        write_str("Backspace");
 
746
                        break;
 
747
 
 
748
                case '\n':
 
749
                        write_str("Newline");
 
750
                        break;
 
751
 
 
752
                default:
 
753
                        if (char_code(x) & 0200) {
 
754
                                write_ch('\\');
 
755
                                i = char_code(x);
 
756
                                write_ch(((i>>6)&7) + '0');
 
757
                                write_ch(((i>>3)&7) + '0');
 
758
                                write_ch(((i>>0)&7) + '0');
 
759
                        } else if (char_code(x) < 040) {
 
760
                                write_ch('^');
 
761
                                write_ch(char_code(x) + 0100);
 
762
                        } else
 
763
                                write_ch(char_code(x));
 
764
                        break;
 
765
                }
 
766
                break;
 
767
 
 
768
        case t_symbol:
 
769
                if (!PRINTescape) {
 
770
                        for (lw = 0,i = 0;  i < x->s.s_fillp;  i++) {
 
771
                                j = x->s.s_self[i];
 
772
                                if (isUpper(j)) {
 
773
                                    if (PRINTcase == sKdowncase ||
 
774
                                        (PRINTcase == sKcapitalize && i!=lw))
 
775
                                          j += 'a' - 'A';
 
776
                                 } else if (!isLower(j))
 
777
                                         lw = i + 1;
 
778
                                  write_ch(j);
 
779
 
 
780
                        }
 
781
                        break;
 
782
                }
 
783
                if (x->s.s_hpack == Cnil) {
 
784
                    if (PRINTcircle) {
 
785
                        for (vp = PRINTvs_top;  vp < PRINTvs_limit;  vp += 2)
 
786
                            if (x == *vp) {
 
787
                                if (vp[1] != Cnil) {
 
788
                                    write_ch('#');
 
789
                                    write_decimal((vp-PRINTvs_top)/2);
 
790
                                    write_ch('#');
 
791
                                    return;
 
792
                                } else {
 
793
                                    write_ch('#');
 
794
                                    write_decimal((vp-PRINTvs_top)/2);
 
795
                                    write_ch('=');
 
796
                                    vp[1] = Ct;
 
797
                                }
 
798
                            }
 
799
                    }
 
800
                    if (PRINTgensym)
 
801
                        write_str("#:");
 
802
                } else if (x->s.s_hpack == keyword_package)
 
803
                        write_ch(':');
 
804
                else if (PRINTpackage||find_symbol(x,current_package())!=x
 
805
                         || intern_flag == 0)
 
806
                  {
 
807
                        k = 0;
 
808
                        for (i = 0;
 
809
                             i < x->s.s_hpack->p.p_name->st.st_fillp;
 
810
                             i++) {
 
811
                                j = x->s.s_hpack->p.p_name
 
812
                                    ->st.st_self[i];
 
813
                                if (to_be_escaped(j))
 
814
                                        k++;
 
815
                        }
 
816
                        if (k > 0)
 
817
                                write_ch('|');
 
818
                     for (lw = 0, i = 0;        
 
819
                             i < x->s.s_hpack->p.p_name->st.st_fillp;
 
820
                             i++) {
 
821
                                j = x->s.s_hpack->p.p_name
 
822
                                    ->st.st_self[i];
 
823
                                if (j == '|' || j == '\\')
 
824
                                        write_ch('\\');
 
825
                                 if (k == 0) {
 
826
                                         if (isUpper(j)) {
 
827
                                                 if (PRINTcase == sKdowncase ||
 
828
                                                     (PRINTcase == sKcapitalize && i!=lw))
 
829
                                                 j += 'a' - 'A';
 
830
                                         } else if (!isLower(j))
 
831
                                                 lw = i + 1;
 
832
                                 }
 
833
                                write_ch(j);
 
834
                        }
 
835
                        if (k > 0)
 
836
                                write_ch('|');
 
837
                        if (find_symbol(x, x->s.s_hpack) != x)
 
838
                                error("can't print symbol");
 
839
                        if (PRINTpackage || intern_flag == INTERNAL)
 
840
                                write_str("::");
 
841
                        else if (intern_flag == EXTERNAL)
 
842
                                write_ch(':');
 
843
                        else
 
844
                        FEerror("Pathological symbol --- cannot print.", 0);
 
845
                }
 
846
                k = 0;
 
847
                if (potential_number_p(x, PRINTbase))
 
848
                        k++;
 
849
                for (i = 0;  i < x->s.s_fillp;  i++) {
 
850
                        j = x->s.s_self[i];
 
851
                        if (to_be_escaped(j))
 
852
                                k++;
 
853
                }
 
854
                for (i = 0;  i < x->s.s_fillp;  i++)
 
855
                        if (x->s.s_self[i] != '.')
 
856
                                goto NOT_DOT;
 
857
                k++;
 
858
 
 
859
        NOT_DOT:                        
 
860
                if (k > 0)
 
861
                        write_ch('|');
 
862
                 for (lw = 0, i = 0;  i < x->s.s_fillp;  i++) {
 
863
                        j = x->s.s_self[i];
 
864
                        if (j == '|' || j == '\\')
 
865
                                write_ch('\\');
 
866
                         if (k == 0) {
 
867
                                 if (isUpper(j)) {
 
868
                                         if (PRINTcase == sKdowncase ||
 
869
                                             (PRINTcase == sKcapitalize && i != lw))
 
870
                                             j += 'a' - 'A';
 
871
                                 } else if (!isLower(j))
 
872
                                         lw = i + 1;
 
873
                         }
 
874
                        write_ch(j);
 
875
                }
 
876
                if (k > 0)
 
877
                        write_ch('|');
 
878
                break;
 
879
 
 
880
        case t_array:
 
881
        {
 
882
                int subscripts[ARANKLIM];
 
883
                int n, m;
 
884
 
 
885
                if (!PRINTarray) {
 
886
                        write_str("#<array ");
 
887
                        write_addr(x);
 
888
                        write_str(">");
 
889
                        break;
 
890
                }
 
891
                if (PRINTcircle) {
 
892
                        for (vp = PRINTvs_top;  vp < PRINTvs_limit;  vp += 2)
 
893
                            if (x == *vp) {
 
894
                                if (vp[1] != Cnil) {
 
895
                                    write_ch('#');
 
896
                                    write_decimal((vp-PRINTvs_top)/2);
 
897
                                    write_ch('#');
 
898
                                    return;
 
899
                                } else {
 
900
                                    write_ch('#');
 
901
                                    write_decimal((vp-PRINTvs_top)/2);
 
902
                                    write_ch('=');
 
903
                                    vp[1] = Ct;
 
904
                                    break;
 
905
                                }
 
906
                            }
 
907
                }
 
908
                if (PRINTlevel >= 0 && level >= PRINTlevel) {
 
909
                        write_ch('#');
 
910
                        break;
 
911
                }
 
912
                n = x->a.a_rank;
 
913
                write_ch('#');
 
914
                write_decimal(n);
 
915
                write_ch('A');
 
916
                if (PRINTlevel >= 0 && level+n >= PRINTlevel)
 
917
                        n = PRINTlevel - level;
 
918
                for (i = 0;  i < n;  i++)
 
919
                        subscripts[i] = 0;
 
920
                m = 0;
 
921
                j = 0;
 
922
                for (;;) {
 
923
                        for (i = j;  i < n;  i++) {
 
924
                                if (subscripts[i] == 0) {
 
925
                                        write_ch(MARK);
 
926
                                        write_ch('(');
 
927
                                        write_ch(SET_INDENT);
 
928
                                        if (x->a.a_dims[i] == 0) {
 
929
                                                write_ch(')');
 
930
                                                write_ch(UNMARK);
 
931
                                                j = i-1;
 
932
                                                k = 0;
 
933
                                                goto INC;
 
934
                                        }
 
935
                                }
 
936
                                if (subscripts[i] > 0)
 
937
                                        write_ch(INDENT);
 
938
                                if (PRINTlength >= 0 &&
 
939
                                    subscripts[i] >= PRINTlength) {
 
940
                                        write_str("...)");
 
941
                                        write_ch(UNMARK);
 
942
                                        k=x->a.a_dims[i]-subscripts[i];
 
943
                                        subscripts[i] = 0;
 
944
                                        for (j = i+1;  j < n;  j++)
 
945
                                                k *= x->a.a_dims[j];
 
946
                                        j = i-1;
 
947
                                        goto INC;
 
948
                                }
 
949
                        }
 
950
                        if (n == x->a.a_rank) {
 
951
                                vs_push(aref(x, m));
 
952
                                write_object(vs_head, level+n);
 
953
                                vs_popp;
 
954
                        } else
 
955
                                write_ch('#');
 
956
                        j = n-1;
 
957
                        k = 1;
 
958
 
 
959
                INC:
 
960
                        while (j >= 0) {
 
961
                                if (++subscripts[j] < x->a.a_dims[j])
 
962
                                        break;
 
963
                                subscripts[j] = 0;
 
964
                                write_ch(')');
 
965
                                write_ch(UNMARK);
 
966
                                --j;
 
967
                        }
 
968
                        if (j < 0)
 
969
                                break;
 
970
                        m += k;
 
971
                }
 
972
                break;
 
973
        }
 
974
 
 
975
        case t_vector:
 
976
                if (!PRINTarray) {
 
977
                        write_str("#<vector ");
 
978
                        write_addr(x);
 
979
                        write_str(">");
 
980
                        break;
 
981
                }
 
982
                if (PRINTcircle) {
 
983
                        for (vp = PRINTvs_top;  vp < PRINTvs_limit;  vp += 2)
 
984
                            if (x == *vp) {
 
985
                                if (vp[1] != Cnil) {
 
986
                                    write_ch('#');
 
987
                                    write_decimal((vp-PRINTvs_top)/2);
 
988
                                    write_ch('#');
 
989
                                    return;
 
990
                                } else {
 
991
                                    write_ch('#');
 
992
                                    write_decimal((vp-PRINTvs_top)/2);
 
993
                                    write_ch('=');
 
994
                                    vp[1] = Ct;
 
995
                                    break;
 
996
                                }
 
997
                            }
 
998
                }
 
999
                if (PRINTlevel >= 0 && level >= PRINTlevel) {
 
1000
                        write_ch('#');
 
1001
                        break;
 
1002
                }
 
1003
                write_ch('#');
 
1004
                write_ch(MARK);
 
1005
                write_ch('(');
 
1006
                write_ch(SET_INDENT);
 
1007
                if (x->v.v_fillp > 0) {
 
1008
                        if (PRINTlength == 0) {
 
1009
                                write_str("...)");
 
1010
                                write_ch(UNMARK);
 
1011
                                break;
 
1012
                        }
 
1013
                        vs_push(aref(x, 0));
 
1014
                        write_object(vs_head, level+1);
 
1015
                        vs_popp;
 
1016
                        for (i = 1;  i < x->v.v_fillp;  i++) {
 
1017
                                write_ch(INDENT);
 
1018
                                if (PRINTlength>=0 && i>=PRINTlength){
 
1019
                                        write_str("...");
 
1020
                                        break;
 
1021
                                }
 
1022
                                vs_push(aref(x, i));
 
1023
                                write_object(vs_head, level+1);
 
1024
                                vs_popp;
 
1025
                        }
 
1026
                }
 
1027
                write_ch(')');
 
1028
                write_ch(UNMARK);
 
1029
                break;
 
1030
 
 
1031
        case t_string:
 
1032
                if (!PRINTescape) {
 
1033
                        for (i = 0;  i < x->st.st_fillp;  i++)
 
1034
                                write_ch(x->st.st_self[i]);
 
1035
                        break;
 
1036
                }
 
1037
                write_ch('"');
 
1038
                for (i = 0;  i < x->st.st_fillp;  i++) {
 
1039
                        if (x->st.st_self[i] == '"' ||
 
1040
                            x->st.st_self[i] == '\\')
 
1041
                                write_ch('\\');
 
1042
                        write_ch(x->st.st_self[i]);
 
1043
                }
 
1044
                write_ch('"');
 
1045
                break;
 
1046
 
 
1047
        case t_bitvector:
 
1048
                if (!PRINTarray) {
 
1049
                        write_str("#<bit-vector ");
 
1050
                        write_addr(x);
 
1051
                        write_str(">");
 
1052
                        break;
 
1053
                }
 
1054
                write_str("#*");
 
1055
                for (i = x->bv.bv_offset;  i < x->bv.bv_fillp + x->bv.bv_offset;  i++)
 
1056
                        if (x->bv.bv_self[i/8] & (0200 >> i%8))
 
1057
                                write_ch('1');
 
1058
                        else
 
1059
                                write_ch('0');
 
1060
                break;
 
1061
 
 
1062
        case t_cons:
 
1063
                if (x->c.c_car == siSsharp_comma) {
 
1064
                        write_str("#.");
 
1065
                        write_object(x->c.c_cdr, level);
 
1066
                        break;
 
1067
                }
 
1068
                if (PRINTcircle) {
 
1069
                        for (vp = PRINTvs_top;  vp < PRINTvs_limit;  vp += 2)
 
1070
                            if (x == *vp) {
 
1071
                                if (vp[1] != Cnil) {
 
1072
                                    write_ch('#');
 
1073
                                    write_decimal((vp-PRINTvs_top)/2);
 
1074
                                    write_ch('#');
 
1075
                                    return;
 
1076
                                } else {
 
1077
                                    write_ch('#');
 
1078
                                    write_decimal((vp-PRINTvs_top)/2);
 
1079
                                    write_ch('=');
 
1080
                                    vp[1] = Ct;
 
1081
                                    break;
 
1082
                                }
 
1083
                            }
 
1084
                }
 
1085
                if (PRINTpretty) {
 
1086
                if (x->c.c_car == sLquote &&
 
1087
                    type_of(x->c.c_cdr) == t_cons &&
 
1088
                    x->c.c_cdr->c.c_cdr == Cnil) {
 
1089
                        write_ch('\'');
 
1090
                        write_object(x->c.c_cdr->c.c_car, level);
 
1091
                        break;
 
1092
                }
 
1093
                if (x->c.c_car == sLfunction &&
 
1094
                    type_of(x->c.c_cdr) == t_cons &&
 
1095
                    x->c.c_cdr->c.c_cdr == Cnil) {
 
1096
                        write_ch('#');
 
1097
                        write_ch('\'');
 
1098
                        write_object(x->c.c_cdr->c.c_car, level);
 
1099
                        break;
 
1100
                }
 
1101
                }
 
1102
                if (PRINTlevel >= 0 && level >= PRINTlevel) {
 
1103
                        write_ch('#');
 
1104
                        break;
 
1105
                }
 
1106
                write_ch(MARK);
 
1107
                write_ch('(');
 
1108
                write_ch(SET_INDENT);
 
1109
                if (PRINTpretty && x->c.c_car != OBJNULL &&
 
1110
                    type_of(x->c.c_car) == t_symbol &&
 
1111
                    (r = getf(x->c.c_car->s.s_plist,
 
1112
                              sSpretty_print_format, Cnil)) != Cnil)
 
1113
                        goto PRETTY_PRINT_FORMAT;
 
1114
                for (i = 0;  ;  i++) {
 
1115
                        if (PRINTlength >= 0 && i >= PRINTlength) {
 
1116
                                write_str("...");
 
1117
                                break;
 
1118
                        }
 
1119
                        y = x->c.c_car;
 
1120
                        x = x->c.c_cdr;
 
1121
                        write_object(y, level+1);
 
1122
                        if (type_of(x) != t_cons) {
 
1123
                                if (x != Cnil) {
 
1124
                                        write_ch(INDENT);
 
1125
                                        write_str(". ");
 
1126
                                        write_object(x, level);
 
1127
                                }
 
1128
                                break;
 
1129
                        }
 
1130
                        if (PRINTcircle) {
 
1131
                          for (vp = PRINTvs_top; vp < PRINTvs_limit; vp += 2)
 
1132
                            if (x == *vp) {
 
1133
                                if (vp[1] != Cnil) {
 
1134
                                    write_str(" . #");
 
1135
                                    write_decimal((vp-PRINTvs_top)/2);
 
1136
                                    write_ch('#');
 
1137
                                    goto RIGHT_PAREN;
 
1138
                                } else {
 
1139
                                    write_ch(INDENT);
 
1140
                                    write_str(". ");
 
1141
                                    write_object(x, level);
 
1142
                                    goto RIGHT_PAREN;
 
1143
                                }
 
1144
                            }
 
1145
                        }
 
1146
                        if (i == 0 && y != OBJNULL && type_of(y) == t_symbol)
 
1147
                                write_ch(INDENT1);
 
1148
                        else
 
1149
                                write_ch(INDENT);
 
1150
                }
 
1151
 
 
1152
        RIGHT_PAREN:
 
1153
                write_ch(')');
 
1154
                write_ch(UNMARK);
 
1155
                break;
 
1156
 
 
1157
        PRETTY_PRINT_FORMAT:
 
1158
                j = fixint(r);
 
1159
                for (i = 0;  ;  i++) {
 
1160
                        if (PRINTlength >= 0 && i >= PRINTlength) {
 
1161
                                write_str("...");
 
1162
                                break;
 
1163
                        }
 
1164
                        y = x->c.c_car;
 
1165
                        x = x->c.c_cdr;
 
1166
                        if (i <= j && y == Cnil)
 
1167
                                write_str("()");
 
1168
                        else
 
1169
                                write_object(y, level+1);
 
1170
                        if (type_of(x) != t_cons) {
 
1171
                                if (x != Cnil) {
 
1172
                                        write_ch(INDENT);
 
1173
                                        write_str(". ");
 
1174
                                        write_object(x, level);
 
1175
                                }
 
1176
                                break;
 
1177
                        }
 
1178
                        if (i >= j)
 
1179
                                write_ch(INDENT2);
 
1180
                        else if (i == 0)
 
1181
                                write_ch(INDENT1);
 
1182
                        else
 
1183
                                write_ch(INDENT);
 
1184
                }
 
1185
                goto RIGHT_PAREN;
 
1186
 
 
1187
        case t_package:
 
1188
                write_str("#<");
 
1189
                write_object(x->p.p_name, level);
 
1190
                write_str(" package>");
 
1191
                break;
 
1192
 
 
1193
        case t_hashtable:
 
1194
                write_str("#<hash-table ");
 
1195
                write_addr(x);
 
1196
                write_str(">");
 
1197
                break;
 
1198
 
 
1199
        case t_stream:
 
1200
                switch (x->sm.sm_mode) {
 
1201
                case smm_input:
 
1202
                        write_str("#<input stream ");
 
1203
                        write_object(x->sm.sm_object1, level);
 
1204
                        write_ch('>');
 
1205
                        break;
 
1206
 
 
1207
                case smm_output:
 
1208
                        write_str("#<output stream ");
 
1209
                        write_object(x->sm.sm_object1, level);
 
1210
                        write_ch('>');
 
1211
                        break;
 
1212
 
 
1213
                case smm_io:
 
1214
                        write_str("#<io stream ");
 
1215
                        write_object(x->sm.sm_object1, level);
 
1216
                        write_ch('>');
 
1217
                        break;
 
1218
 
 
1219
                case smm_socket:
 
1220
                        write_str("#<socket stream ");
 
1221
                        write_object(x->sm.sm_object0, level);
 
1222
                        write_ch('>');
 
1223
                        break;
 
1224
 
 
1225
 
 
1226
                case smm_probe:
 
1227
                        write_str("#<probe stream ");
 
1228
                        write_object(x->sm.sm_object1, level);
 
1229
                        write_ch('>');
 
1230
                        break;
 
1231
 
 
1232
                case smm_synonym:
 
1233
                        write_str("#<synonym stream to ");
 
1234
                        write_object(x->sm.sm_object0, level);
 
1235
                        write_ch('>');
 
1236
                        break;
 
1237
 
 
1238
                case smm_broadcast:
 
1239
                        write_str("#<broadcast stream ");
 
1240
                        write_addr(x);
 
1241
                        write_str(">");
 
1242
                        break;
 
1243
 
 
1244
                case smm_concatenated:
 
1245
                        write_str("#<concatenated stream ");
 
1246
                        write_addr(x);
 
1247
                        write_str(">");
 
1248
                        break;
 
1249
 
 
1250
                case smm_two_way:
 
1251
                        write_str("#<two-way stream ");
 
1252
                        write_addr(x);
 
1253
                        write_str(">");
 
1254
                        break;
 
1255
 
 
1256
                case smm_echo:
 
1257
                        write_str("#<echo stream ");
 
1258
                        write_addr(x);
 
1259
                        write_str(">");
 
1260
                        break;
 
1261
 
 
1262
                case smm_string_input:
 
1263
                        write_str("#<string-input stream from \"");
 
1264
                        y = x->sm.sm_object0;
 
1265
                        j = y->st.st_fillp;
 
1266
                        for (i = 0;  i < j && i < 16;  i++)
 
1267
                                write_ch(y->st.st_self[i]);
 
1268
                        if (j > 16)
 
1269
                                write_str("...");
 
1270
                        write_str("\">");
 
1271
                        break;
 
1272
#ifdef USER_DEFINED_STREAMS
 
1273
                case smm_user_defined:
 
1274
                        write_str("#<use-define stream");
 
1275
                        write_addr(x);
 
1276
                        write_str(">");
 
1277
                        break;
 
1278
#endif
 
1279
 
 
1280
                case smm_string_output:
 
1281
                        write_str("#<string-output stream ");
 
1282
                        write_addr(x);
 
1283
                        write_str(">");
 
1284
                        break;
 
1285
 
 
1286
                default:
 
1287
                        error("illegal stream mode");
 
1288
                }
 
1289
                break;
 
1290
 
 
1291
        case t_random:
 
1292
                write_str("#$");
 
1293
                y = alloc_object(t_fixnum);
 
1294
                fix(y) = x->rnd.rnd_value;
 
1295
                vs_push(y);
 
1296
                write_object(y, level);
 
1297
                vs_popp;
 
1298
                break;
 
1299
 
 
1300
        case t_structure:
 
1301
                if (PRINTcircle) {
 
1302
                        for (vp = PRINTvs_top;  vp < PRINTvs_limit;  vp += 2)
 
1303
                            if (x == *vp) {
 
1304
                                if (vp[1] != Cnil) {
 
1305
                                    write_ch('#');
 
1306
                                    write_decimal((vp-PRINTvs_top)/2);
 
1307
                                    write_ch('#');
 
1308
                                    return;
 
1309
                                } else {
 
1310
                                    write_ch('#');
 
1311
                                    write_decimal((vp-PRINTvs_top)/2);
 
1312
                                    write_ch('=');
 
1313
                                    vp[1] = Ct;
 
1314
                                    break;
 
1315
                                }
 
1316
                            }
 
1317
                }
 
1318
                if (PRINTlevel >= 0 && level >= PRINTlevel) {
 
1319
                        write_ch('#');
 
1320
                        break;
 
1321
                }
 
1322
                if (type_of(x->str.str_def) != t_structure)
 
1323
                        FEwrong_type_argument(sLstructure, x->str.str_def);
 
1324
                if (PRINTstructure ||
 
1325
                        S_DATA(x->str.str_def)->print_function == Cnil)
 
1326
                          {     
 
1327
                        write_str("#S");
 
1328
                        x = structure_to_list(x);
 
1329
                        vs_push(x);
 
1330
                        write_object(x, level);
 
1331
                        vs_popp;
 
1332
                        break;
 
1333
                }
 
1334
                call_structure_print_function(x, level);
 
1335
                break;
 
1336
 
 
1337
        case t_readtable:
 
1338
                write_str("#<readtable ");
 
1339
                write_addr(x);
 
1340
                write_str(">");
 
1341
                break;
 
1342
 
 
1343
        case t_pathname:
 
1344
                if (1 || PRINTescape) {
 
1345
                        write_ch('#');
 
1346
                        write_ch('p');
 
1347
                        vs_push(namestring(x));
 
1348
                        write_object(vs_head, level);
 
1349
                        vs_popp;
 
1350
                } else {
 
1351
                        write_str("#<pathname ");
 
1352
                        write_addr(x);
 
1353
                        write_str(">");
 
1354
                }
 
1355
                break;
 
1356
        case t_sfun:
 
1357
        case t_gfun:
 
1358
        case t_vfun:
 
1359
        case t_afun:    
 
1360
        case t_cfun:
 
1361
                write_str("#<compiled-function ");
 
1362
                if (x->cf.cf_name != Cnil)
 
1363
                        write_object(x->cf.cf_name, level);
 
1364
                else
 
1365
                        write_addr(x);
 
1366
                write_str(">");
 
1367
                break;
 
1368
 
 
1369
        case t_closure:
 
1370
        case t_cclosure:
 
1371
                write_str("#<compiled-closure ");
 
1372
                if (x->cc.cc_name != Cnil)
 
1373
                        write_object(x->cc.cc_name, level);
 
1374
                else
 
1375
                        write_addr(x);
 
1376
                write_str(">");
 
1377
                break;
 
1378
 
 
1379
        case t_spice:
 
1380
                write_str("#<\100");
 
1381
                for (i = 8*sizeof(long)-4;  i >= 0;  i -= 4) {
 
1382
                        j = ((long)x >> i) & 0xf;
 
1383
                        if (j < 10)
 
1384
                                write_ch('0' + j);
 
1385
                        else
 
1386
                                write_ch('A' + (j - 10));
 
1387
                }
 
1388
                write_ch('>');
 
1389
                break;
 
1390
 
 
1391
        default:
 
1392
                error("illegal type --- cannot print");
 
1393
        }
 
1394
}
 
1395
 
 
1396
char travel_push_type[32]; 
 
1397
 
 
1398
static void
 
1399
travel_push_object(x)
 
1400
object x;
 
1401
{
 
1402
        enum type t;
 
1403
        int i;
 
1404
        object *vp;
 
1405
 
 
1406
        cs_check(x);
 
1407
 
 
1408
BEGIN:
 
1409
        t = type_of(x);
 
1410
        if(travel_push_type[(int)t]==0) return;
 
1411
        if(t==t_symbol && x->s.s_hpack != Cnil) return;
 
1412
 
 
1413
        for (vp = PRINTvs_top;  vp < vs_top;  vp += 2)
 
1414
                if (x == *vp) {
 
1415
                        if (vp[1] != Cnil)
 
1416
                                return;
 
1417
                        vp[1] = Ct;
 
1418
                        return;
 
1419
                }
 
1420
        vs_check_push(x);
 
1421
        vs_check_push(Cnil);
 
1422
        if (t == t_array && (enum aelttype)x->a.a_elttype == aet_object)
 
1423
                for (i = 0;  i < x->a.a_dim;  i++)
 
1424
                        travel_push_object(x->a.a_self[i]);
 
1425
        else if (t == t_vector && (enum aelttype)x->v.v_elttype == aet_object)
 
1426
                for (i = 0;  i < x->v.v_fillp;  i++)
 
1427
                        travel_push_object(x->v.v_self[i]);
 
1428
        else if (t == t_cons) {
 
1429
                travel_push_object(x->c.c_car);
 
1430
                x = x->c.c_cdr;
 
1431
                goto BEGIN;
 
1432
        } else if (t == t_structure) {
 
1433
                for (i = 0;  i < S_DATA(x->str.str_def)->length;  i++)
 
1434
                  travel_push_object(structure_ref(x,x->str.str_def,i));
 
1435
        }
 
1436
}
 
1437
 
 
1438
static void
 
1439
setupPRINTcircle(x,dogensyms)
 
1440
     object x;
 
1441
     int dogensyms;
 
1442
{  object *vp,*vq;
 
1443
   travel_push_type[(int)t_symbol]=dogensyms;
 
1444
   travel_push_type[(int)t_array]=
 
1445
       (travel_push_type[(int)t_vector]=PRINTarray);
 
1446
   travel_push_object(x);
 
1447
   for (vp = vq = PRINTvs_top;  vp < vs_top;  vp += 2)
 
1448
     if (vp[1] != Cnil) {
 
1449
       vq[0] = vp[0];
 
1450
       vq[1] = Cnil;
 
1451
       vq += 2;
 
1452
     }
 
1453
   PRINTvs_limit = vs_top = vq;
 
1454
 }
 
1455
 
 
1456
void
 
1457
setupPRINTdefault(x)
 
1458
object x;
 
1459
{
 
1460
        object y;
 
1461
 
 
1462
        PRINTvs_top = vs_top;
 
1463
        PRINTstream = symbol_value(sLAstandard_outputA);
 
1464
        if (type_of(PRINTstream) != t_stream) {
 
1465
                sLAstandard_outputA->s.s_dbind
 
1466
                = symbol_value(sLAterminal_ioA);
 
1467
                vs_push(PRINTstream);
 
1468
                FEwrong_type_argument(sLstream, PRINTstream);
 
1469
        }
 
1470
        PRINTescape = symbol_value(sLAprint_escapeA) != Cnil;
 
1471
        PRINTreadably = symbol_value(sLAprint_readablyA) != Cnil;
 
1472
        PRINTpretty = symbol_value(sLAprint_prettyA) != Cnil;
 
1473
        PRINTcircle = symbol_value(sLAprint_circleA) != Cnil;
 
1474
        y = symbol_value(sLAprint_baseA);
 
1475
        if (type_of(y) != t_fixnum || fix(y) < 2 || fix(y) > 36) {
 
1476
                sLAprint_baseA->s.s_dbind = make_fixnum(10);
 
1477
                vs_push(y);
 
1478
                FEerror("~S is an illegal PRINT-BASE.", 1, y);
 
1479
        } else
 
1480
                PRINTbase = fix(y);
 
1481
        PRINTradix = symbol_value(sLAprint_radixA) != Cnil;
 
1482
        PRINTcase = symbol_value(sLAprint_caseA);
 
1483
        if (PRINTcase != sKupcase && PRINTcase != sKdowncase &&
 
1484
            PRINTcase != sKcapitalize) {
 
1485
                sLAprint_caseA->s.s_dbind = sKdowncase;
 
1486
                vs_push(PRINTcase);
 
1487
                FEerror("~S is an illegal PRINT-CASE.", 1, PRINTcase);
 
1488
        }
 
1489
        PRINTgensym = symbol_value(sLAprint_gensymA) != Cnil;
 
1490
        y = symbol_value(sLAprint_levelA);
 
1491
        if (y == Cnil)
 
1492
                PRINTlevel = -1;
 
1493
        else if (type_of(y) != t_fixnum || fix(y) < 0) {
 
1494
                sLAprint_levelA->s.s_dbind = Cnil;
 
1495
                vs_push(y);
 
1496
                FEerror("~S is an illegal PRINT-LEVEL.", 1, y);
 
1497
        } else
 
1498
                PRINTlevel = fix(y);
 
1499
        y = symbol_value(sLAprint_lengthA);
 
1500
        if (y == Cnil)
 
1501
                PRINTlength = -1;
 
1502
        else if (type_of(y) != t_fixnum || fix(y) < 0) {
 
1503
                sLAprint_lengthA->s.s_dbind = Cnil;
 
1504
                vs_push(y);
 
1505
                FEerror("~S is an illegal PRINT-LENGTH.", 1, y);
 
1506
        } else
 
1507
                PRINTlength = fix(y);
 
1508
        PRINTarray = symbol_value(sLAprint_arrayA) != Cnil;
 
1509
        if (PRINTcircle) setupPRINTcircle(x,1);
 
1510
        if (PRINTpretty) {
 
1511
                qh = qt = qc = 0;
 
1512
                isp = iisp = 0;
 
1513
                indent_stack[0] = 0;
 
1514
                write_ch_fun = writec_queue;
 
1515
        } else
 
1516
                write_ch_fun = writec_PRINTstream;
 
1517
        PRINTpackage = symbol_value(sSAprint_packageA) != Cnil;
 
1518
        PRINTstructure = symbol_value(sSAprint_structureA) != Cnil;
 
1519
}
 
1520
 
 
1521
void
 
1522
cleanupPRINT(void)
 
1523
{
 
1524
        vs_top = PRINTvs_top;
 
1525
        if (PRINTpretty)
 
1526
                flush_queue(TRUE);
 
1527
}
 
1528
 
 
1529
/*static void
 
1530
write_object_by_default(x)
 
1531
object x;
 
1532
{
 
1533
        SETUP_PRINT_DEFAULT(x);
 
1534
        write_object(x, 0);
 
1535
        flush_stream(PRINTstream);
 
1536
        CLEANUP_PRINT_DEFAULT;
 
1537
}*/
 
1538
 
 
1539
/*static void
 
1540
terpri_by_default()
 
1541
{
 
1542
        PRINTstream = symbol_value(sLAstandard_outputA);
 
1543
        if (type_of(PRINTstream) != t_stream)
 
1544
                FEwrong_type_argument(sLstream, PRINTstream);
 
1545
        WRITEC_NEWLINE(PRINTstream);
 
1546
}*/
 
1547
 
 
1548
static bool
 
1549
potential_number_p(strng, base)
 
1550
object strng;
 
1551
int base;
 
1552
{
 
1553
        int i, l, c, dc;
 
1554
        char *s;
 
1555
 
 
1556
        l = strng->st.st_fillp;
 
1557
        if (l == 0)
 
1558
                return(FALSE);
 
1559
        s = strng->st.st_self;
 
1560
        dc = 0;
 
1561
        c = s[0];
 
1562
        if (digitp(c, base) >= 0)
 
1563
                dc++;
 
1564
        else if (c != '+' && c != '-' && c != '^' && c != '_')
 
1565
                return(FALSE);
 
1566
        if (s[l-1] == '+' || s[l-1] == '-')
 
1567
                return(FALSE);
 
1568
        for (i = 1;  i < l;  i++) {
 
1569
                c = s[i];
 
1570
                if (digitp(c, base) >= 0) {
 
1571
                        dc++;
 
1572
                        continue;
 
1573
                }
 
1574
                if (c != '+' && c != '-' && c != '/' && c != '.' &&
 
1575
                    c != '^' && c != '_' &&
 
1576
                    c != 'e' && c != 'E' &&
 
1577
                    c != 's' && c != 'S' && c != 'l' && c != 'L')
 
1578
                        return(FALSE);
 
1579
        }
 
1580
        if (dc == 0)
 
1581
                return(FALSE);
 
1582
        return(TRUE);
 
1583
}
 
1584
@(defun write (x
 
1585
               &key ((:stream strm) Cnil)
 
1586
                    (escape `symbol_value(sLAprint_escapeA)`)
 
1587
                    (readably `symbol_value(sLAprint_readablyA)`)
 
1588
                    (radix `symbol_value(sLAprint_radixA)`)
 
1589
                    (base `symbol_value(sLAprint_baseA)`)
 
1590
                    (circle `symbol_value(sLAprint_circleA)`)
 
1591
                    (pretty `symbol_value(sLAprint_prettyA)`)
 
1592
                    (level `symbol_value(sLAprint_levelA)`)
 
1593
                    (length `symbol_value(sLAprint_lengthA)`)
 
1594
                    ((:case cas) `symbol_value(sLAprint_caseA)`)
 
1595
                    (gensym `symbol_value(sLAprint_gensymA)`)
 
1596
                    (array `symbol_value(sLAprint_arrayA)`))
 
1597
        struct printStruct printStructBuf; 
 
1598
        struct printStruct *old_printStructBufp = printStructBufp;  
 
1599
@
 
1600
 
 
1601
        printStructBufp = &printStructBuf; 
 
1602
        if (strm == Cnil)
 
1603
                strm = symbol_value(sLAstandard_outputA);
 
1604
        else if (strm == Ct)
 
1605
                strm = symbol_value(sLAterminal_ioA);
 
1606
        if (type_of(strm) != t_stream)
 
1607
                FEerror("~S is not a stream.", 1, strm);
 
1608
        PRINTvs_top = vs_top;
 
1609
        PRINTstream = strm;
 
1610
        PRINTreadably = readably != Cnil;
 
1611
        PRINTescape = PRINTreadably || escape != Cnil;
 
1612
        PRINTpretty = pretty != Cnil;
 
1613
        PRINTcircle = circle != Cnil;
 
1614
        if (type_of(base)!=t_fixnum || fix((base))<2 || fix((base))>36)
 
1615
                FEerror("~S is an illegal PRINT-BASE.", 1, base);
 
1616
        else
 
1617
                PRINTbase = fix((base));
 
1618
        PRINTradix = radix != Cnil;
 
1619
        PRINTcase = cas;
 
1620
        if (PRINTcase != sKupcase && PRINTcase != sKdowncase &&
 
1621
            PRINTcase != sKcapitalize)
 
1622
                FEerror("~S is an illegal PRINT-CASE.", 1, cas);
 
1623
        PRINTgensym = PRINTreadably || gensym != Cnil;
 
1624
        if (PRINTreadably || level == Cnil)
 
1625
                PRINTlevel = -1;
 
1626
        else if (type_of(level) != t_fixnum || fix((level)) < 0)
 
1627
                FEerror("~S is an illegal PRINT-LEVEL.", 1, level);
 
1628
        else
 
1629
                PRINTlevel = fix((level));
 
1630
        if (PRINTreadably || length == Cnil)
 
1631
                PRINTlength = -1;
 
1632
        else if (type_of(length) != t_fixnum || fix((length)) < 0)
 
1633
                FEerror("~S is an illegal PRINT-LENGTH.", 1, length);
 
1634
        else
 
1635
                PRINTlength = fix((length));
 
1636
        PRINTarray = PRINTreadably || array != Cnil;
 
1637
        if (PRINTcircle) setupPRINTcircle(x,1);
 
1638
        if (PRINTpretty) {
 
1639
                qh = qt = qc = 0;
 
1640
                isp = iisp = 0;
 
1641
                indent_stack[0] = 0;
 
1642
                write_ch_fun = writec_queue;
 
1643
        } else
 
1644
                write_ch_fun = writec_PRINTstream;
 
1645
        PRINTpackage = symbol_value(sSAprint_packageA) != Cnil;
 
1646
        PRINTstructure = symbol_value(sSAprint_structureA) != Cnil;
 
1647
        write_object(x, 0);
 
1648
        CLEANUP_PRINT_DEFAULT;
 
1649
        flush_stream(PRINTstream);
 
1650
        @(return x)
 
1651
@)
 
1652
 
 
1653
@(defun prin1 (obj &optional strm)
 
1654
@
 
1655
        prin1(obj, strm);
 
1656
        @(return obj)
 
1657
@)
 
1658
 
 
1659
@(defun print (obj &optional strm)
 
1660
@
 
1661
        print(obj, strm);
 
1662
        @(return obj)
 
1663
@)
 
1664
 
 
1665
@(defun pprint (obj &optional strm)
 
1666
@
 
1667
        if (strm == Cnil)
 
1668
                strm = symbol_value(sLAstandard_outputA);
 
1669
        else if (strm == Ct)
 
1670
                strm = symbol_value(sLAterminal_ioA);
 
1671
        check_type_stream(&strm);
 
1672
        WRITEC_NEWLINE(strm);
 
1673
        {SETUP_PRINT_DEFAULT(obj);
 
1674
        PRINTstream = strm;
 
1675
        PRINTreadably = FALSE;
 
1676
        PRINTescape = TRUE;
 
1677
        PRINTpretty = TRUE;
 
1678
        qh = qt = qc = 0;
 
1679
        isp = iisp = 0;
 
1680
        indent_stack[0] = 0;
 
1681
        write_ch_fun = writec_queue;
 
1682
        write_object(obj, 0);
 
1683
        CLEANUP_PRINT_DEFAULT;
 
1684
        flush_stream(strm);}
 
1685
        @(return)
 
1686
@)
 
1687
 
 
1688
@(defun princ (obj &optional strm)
 
1689
@
 
1690
        princ(obj, strm);
 
1691
        @(return obj)
 
1692
@)
 
1693
 
 
1694
@(defun write_char (c &optional strm)
 
1695
@
 
1696
        if (strm == Cnil)
 
1697
                strm = symbol_value(sLAstandard_outputA);
 
1698
        else if (strm == Ct)
 
1699
                strm = symbol_value(sLAterminal_ioA);
 
1700
        check_type_character(&c);
 
1701
        check_type_stream(&strm);
 
1702
        writec_stream(char_code(c), strm);
 
1703
/*
 
1704
        flush_stream(strm);
 
1705
*/
 
1706
        @(return c)
 
1707
@)
 
1708
 
 
1709
@(defun write_string (strng &o strm &k start end)
 
1710
        int s, e, i;
 
1711
@
 
1712
        get_string_start_end(strng, start, end, &s, &e);
 
1713
        if (strm == Cnil)
 
1714
                strm = symbol_value(sLAstandard_outputA);
 
1715
        else if (strm == Ct)
 
1716
                strm = symbol_value(sLAterminal_ioA);
 
1717
        check_type_string(&strng);
 
1718
        check_type_stream(&strm);
 
1719
        for (i = s;  i < e;  i++)
 
1720
                writec_stream(strng->st.st_self[i], strm);
 
1721
        flush_stream(strm);
 
1722
        @(return strng)
 
1723
@)
 
1724
 
 
1725
@(defun write_line (strng &o strm &k start end)
 
1726
        int s, e, i;
 
1727
@
 
1728
        get_string_start_end(strng, start, end, &s, &e);
 
1729
        if (strm == Cnil)
 
1730
                strm = symbol_value(sLAstandard_outputA);
 
1731
        else if (strm == Ct)
 
1732
                strm = symbol_value(sLAterminal_ioA);
 
1733
        check_type_string(&strng);
 
1734
        check_type_stream(&strm);
 
1735
        for (i = s;  i < e;  i++)
 
1736
                writec_stream(strng->st.st_self[i], strm);
 
1737
        WRITEC_NEWLINE(strm);
 
1738
        flush_stream(strm);
 
1739
        @(return strng)
 
1740
@)
 
1741
 
 
1742
@(defun terpri (&optional strm)
 
1743
@
 
1744
        terpri(strm);
 
1745
        @(return Cnil)
 
1746
@)
 
1747
 
 
1748
@(defun fresh_line (&optional strm)
 
1749
@
 
1750
        if (strm == Cnil)
 
1751
                strm = symbol_value(sLAstandard_outputA);
 
1752
        else if (strm == Ct)
 
1753
                strm = symbol_value(sLAterminal_ioA);
 
1754
        /* we need to get the real output stream, if possible */
 
1755
        {object tmp=coerce_stream(strm,1);
 
1756
           if(tmp != Cnil) strm = tmp ;
 
1757
         else 
 
1758
          check_type_stream(&strm);
 
1759
         }
 
1760
        if (file_column(strm) == 0)
 
1761
                @(return Cnil)
 
1762
        WRITEC_NEWLINE(strm);
 
1763
        flush_stream(strm);
 
1764
        @(return Ct)
 
1765
@)
 
1766
 
 
1767
@(defun finish_output (&o strm)
 
1768
@
 
1769
        if (strm == Cnil)
 
1770
                strm = symbol_value(sLAstandard_outputA);
 
1771
        else if (strm == Ct)
 
1772
                strm = symbol_value(sLAterminal_ioA);
 
1773
        check_type_stream(&strm);
 
1774
        flush_stream(strm);
 
1775
        @(return Cnil)
 
1776
@)
 
1777
 
 
1778
@(defun force_output (&o strm)
 
1779
@
 
1780
        if (strm == Cnil)
 
1781
                strm = symbol_value(sLAstandard_outputA);
 
1782
        else if (strm == Ct)
 
1783
                strm = symbol_value(sLAterminal_ioA);
 
1784
        check_type_stream(&strm);
 
1785
        flush_stream(strm);
 
1786
        @(return Cnil)
 
1787
@)
 
1788
 
 
1789
@(defun clear_output (&o strm)
 
1790
@
 
1791
        if (strm == Cnil)
 
1792
                strm = symbol_value(sLAstandard_outputA);
 
1793
        else if (strm == Ct)
 
1794
                strm = symbol_value(sLAterminal_ioA);
 
1795
        check_type_stream(&strm);
 
1796
        @(return Cnil)
 
1797
@)
 
1798
 
 
1799
@(defun write_byte (integer binary_output_stream)
 
1800
@
 
1801
        if (type_of(integer) != t_fixnum)
 
1802
                FEerror("~S is not a byte.", 1, integer);
 
1803
        check_type_stream(&binary_output_stream);
 
1804
        writec_stream(fix(integer), binary_output_stream);
 
1805
        @(return integer)
 
1806
@)
 
1807
 
 
1808
DEF_ORDINARY("UPCASE",sKupcase,KEYWORD,"");
 
1809
DEF_ORDINARY("DOWNCASE",sKdowncase,KEYWORD,"");
 
1810
DEF_ORDINARY("CAPITALIZE",sKcapitalize,KEYWORD,"");
 
1811
DEF_ORDINARY("STREAM",sKstream,KEYWORD,"");
 
1812
DEF_ORDINARY("ESCAPE",sKescape,KEYWORD,"");
 
1813
DEF_ORDINARY("READABLY",sKreadably,KEYWORD,"");
 
1814
DEF_ORDINARY("PRETTY",sKpretty,KEYWORD,"");
 
1815
DEF_ORDINARY("CIRCLE",sKcircle,KEYWORD,"");
 
1816
DEF_ORDINARY("BASE",sKbase,KEYWORD,"");
 
1817
DEF_ORDINARY("RADIX",sKradix,KEYWORD,"");
 
1818
DEF_ORDINARY("CASE",sKcase,KEYWORD,"");
 
1819
DEF_ORDINARY("GENSYM",sKgensym,KEYWORD,"");
 
1820
DEF_ORDINARY("LEVEL",sKlevel,KEYWORD,"");
 
1821
DEF_ORDINARY("LENGTH",sKlength,KEYWORD,"");
 
1822
DEF_ORDINARY("ARRAY",sKarray,KEYWORD,"");
 
1823
DEFVAR("*PRINT-ESCAPE*",sLAprint_escapeA,LISP,Ct,"");
 
1824
DEFVAR("*PRINT-READABLY*",sLAprint_readablyA,LISP,Ct,"");
 
1825
DEFVAR("*PRINT-PRETTY*",sLAprint_prettyA,LISP,Ct,"");
 
1826
DEFVAR("*PRINT-CIRCLE*",sLAprint_circleA,LISP,Cnil,"");
 
1827
DEFVAR("*PRINT-BASE*",sLAprint_baseA,LISP,make_fixnum(10),"");
 
1828
DEFVAR("*PRINT-RADIX*",sLAprint_radixA,LISP,Cnil,"");
 
1829
DEFVAR("*PRINT-CASE*",sLAprint_caseA,LISP,sKupcase,"");
 
1830
DEFVAR("*PRINT-GENSYM*",sLAprint_gensymA,LISP,Ct,"");
 
1831
DEFVAR("*PRINT-LEVEL*",sLAprint_levelA,LISP,Cnil,"");
 
1832
DEFVAR("*PRINT-LENGTH*",sLAprint_lengthA,LISP,Cnil,"");
 
1833
DEFVAR("*PRINT-ARRAY*",sLAprint_arrayA,LISP,Ct,"");
 
1834
DEFVAR("*PRINT-PACKAGE*",sSAprint_packageA,SI,Cnil,"");
 
1835
DEFVAR("*PRINT-STRUCTURE*",sSAprint_structureA,SI,Cnil,"");
 
1836
DEF_ORDINARY("PRETTY-PRINT-FORMAT",sSpretty_print_format,SI,"");
 
1837
 
 
1838
void
 
1839
gcl_init_print()
 
1840
{
 
1841
 
 
1842
        travel_push_type[(int)t_array]=1;
 
1843
        travel_push_type[(int)t_vector]=1;
 
1844
        travel_push_type[(int)t_structure]=1;
 
1845
        travel_push_type[(int) t_cons]=1;
 
1846
        if(sizeof(travel_push_type) < (int) t_other)
 
1847
          error("travel_push_size to small see print.d");
 
1848
 
 
1849
        PRINTstream = Cnil;
 
1850
        enter_mark_origin(&PRINTstream);
 
1851
        PRINTreadably = FALSE;
 
1852
        PRINTescape = TRUE;
 
1853
        PRINTpretty = FALSE;
 
1854
        PRINTcircle = FALSE;
 
1855
        PRINTbase = 10;
 
1856
        PRINTradix = FALSE;
 
1857
        PRINTcase = sKupcase;
 
1858
        enter_mark_origin(&PRINTcase);
 
1859
        PRINTgensym = TRUE;
 
1860
        PRINTlevel = -1;
 
1861
        PRINTlength = -1;
 
1862
        PRINTarray = FALSE;
 
1863
 
 
1864
        write_ch_fun = writec_PRINTstream;
 
1865
}
 
1866
 
 
1867
object
 
1868
princ(obj, strm)
 
1869
object obj, strm;
 
1870
{
 
1871
        if (strm == Cnil)
 
1872
                strm = symbol_value(sLAstandard_outputA);
 
1873
        else if (strm == Ct)
 
1874
                strm = symbol_value(sLAterminal_ioA);
 
1875
        if (type_of(strm) != t_stream)
 
1876
                FEerror("~S is not a stream.", 1, strm);
 
1877
        if (obj == OBJNULL)
 
1878
                goto SIMPLE_CASE;
 
1879
        switch (type_of(obj)) {
 
1880
        case t_symbol:
 
1881
                PRINTcase = symbol_value(sLAprint_caseA);
 
1882
                PRINTpackage = symbol_value(sSAprint_packageA) != Cnil;
 
1883
 
 
1884
        SIMPLE_CASE:
 
1885
        case t_string:
 
1886
        case t_character:
 
1887
                PRINTstream = strm;
 
1888
                PRINTreadably = FALSE;
 
1889
                PRINTescape = FALSE;
 
1890
                write_ch_fun = writec_PRINTstream;
 
1891
                write_object(obj, 0);
 
1892
                break;
 
1893
 
 
1894
        default:
 
1895
                {SETUP_PRINT_DEFAULT(obj);
 
1896
                PRINTstream = strm;
 
1897
                PRINTreadably = FALSE;
 
1898
                PRINTescape = FALSE;
 
1899
                write_object(obj, 0);
 
1900
                CLEANUP_PRINT_DEFAULT;}
 
1901
                break;
 
1902
        }
 
1903
        return(obj);
 
1904
}
 
1905
 
 
1906
object
 
1907
prin1(obj, strm)
 
1908
object obj, strm;
 
1909
{
 
1910
        if (strm == Cnil)
 
1911
                strm = symbol_value(sLAstandard_outputA);
 
1912
        else if (strm == Ct)
 
1913
                strm = symbol_value(sLAterminal_ioA);
 
1914
        if (type_of(strm) != t_stream)
 
1915
                FEerror("~S is not a stream.", 1, strm);
 
1916
        if (obj == OBJNULL)
 
1917
                goto SIMPLE_CASE;
 
1918
        switch (type_of(obj)) {
 
1919
        SIMPLE_CASE:
 
1920
        case t_string:
 
1921
        case t_character:
 
1922
                PRINTstream = strm;
 
1923
                PRINTreadably = FALSE;
 
1924
                PRINTescape = TRUE;
 
1925
                write_ch_fun = writec_PRINTstream;
 
1926
                write_object(obj, 0);
 
1927
                break;
 
1928
 
 
1929
        default:
 
1930
                {SETUP_PRINT_DEFAULT(obj);
 
1931
                PRINTstream = strm;
 
1932
                PRINTreadably = FALSE;
 
1933
                PRINTescape = TRUE;
 
1934
                write_object(obj, 0);
 
1935
                CLEANUP_PRINT_DEFAULT;}
 
1936
                break;
 
1937
        }
 
1938
        flush_stream(strm);
 
1939
        return(obj);
 
1940
}
 
1941
 
 
1942
object
 
1943
print(obj, strm)
 
1944
object obj, strm;
 
1945
{
 
1946
        terpri(strm);
 
1947
        prin1(obj,strm);
 
1948
        princ(code_char(' '),strm);
 
1949
        return(obj);
 
1950
}
 
1951
 
 
1952
object
 
1953
terpri(strm)
 
1954
object strm;
 
1955
{
 
1956
        if (strm == Cnil)
 
1957
                strm = symbol_value(sLAstandard_outputA);
 
1958
        else if (strm == Ct)
 
1959
                strm = symbol_value(sLAterminal_ioA);
 
1960
        if (type_of(strm) != t_stream)
 
1961
                FEerror("~S is not a stream.", 1, strm);
 
1962
        WRITEC_NEWLINE(strm);
 
1963
        flush_stream(strm);
 
1964
        return(Cnil);
 
1965
}
 
1966
 
 
1967
void
 
1968
write_string(strng, strm)
 
1969
object strng, strm;
 
1970
{
 
1971
        int i;
 
1972
 
 
1973
        if (strm == Cnil)
 
1974
                strm = symbol_value(sLAstandard_outputA);
 
1975
        else if (strm == Ct)
 
1976
                strm = symbol_value(sLAterminal_ioA);
 
1977
        check_type_string(&strng);
 
1978
        check_type_stream(&strm);
 
1979
        for (i = 0;  i < strng->st.st_fillp;  i++)
 
1980
                writec_stream(strng->st.st_self[i], strm);
 
1981
        flush_stream(strm);
 
1982
}
 
1983
 
 
1984
/*
 
1985
        THE ULTRA-SPECIAL-DINNER-SERVICE OPTIMIZATION
 
1986
*/
 
1987
void
 
1988
princ_str(s, sym)
 
1989
char *s;
 
1990
object sym;
 
1991
{
 
1992
        sym = symbol_value(sym);
 
1993
        if (sym == Cnil)
 
1994
                sym = symbol_value(sLAstandard_outputA);
 
1995
        else if (sym == Ct)
 
1996
                sym = symbol_value(sLAterminal_ioA);
 
1997
        check_type_stream(&sym);
 
1998
        writestr_stream(s, sym);
 
1999
}
 
2000
 
 
2001
void
 
2002
princ_char(c, sym)
 
2003
int c;
 
2004
object sym;
 
2005
{
 
2006
        sym = symbol_value(sym);
 
2007
        if (sym == Cnil)
 
2008
                sym = symbol_value(sLAstandard_outputA);
 
2009
        else if (sym == Ct)
 
2010
                sym = symbol_value(sLAterminal_ioA);
 
2011
        check_type_stream(&sym);
 
2012
        if (c == '\n')
 
2013
           {WRITEC_NEWLINE(sym);
 
2014
            flush_stream(sym);}
 
2015
        else
 
2016
        writec_stream(c, sym);
 
2017
 
 
2018
}
 
2019
 
 
2020
 
 
2021
static void
 
2022
pp(x)
 
2023
object x;
 
2024
{
 
2025
princ(x,Cnil);
 
2026
flush_stream(symbol_value(sLAstandard_outputA));
 
2027
}
 
2028
 
 
2029
static object
 
2030
FFN(set_line_length)(n)
 
2031
int n;
 
2032
{
 
2033
  line_length=n;
 
2034
  return make_fixnum(line_length);
 
2035
}
 
2036
 
 
2037
DEFVAR("*PRINT-NANS*",sSAprint_nansA,SI,Cnil,"");
 
2038
 
 
2039
void
 
2040
gcl_init_print_function()
 
2041
{
 
2042
        make_function("WRITE", Lwrite);
 
2043
        make_function("PRIN1", Lprin1);
 
2044
        make_function("PRINT", Lprint);
 
2045
        make_function("PPRINT", Lpprint);
 
2046
        make_function("PRINC", Lprinc);
 
2047
 
 
2048
        make_function("WRITE-CHAR", Lwrite_char);
 
2049
        make_function("WRITE-STRING", Lwrite_string);
 
2050
        make_function("WRITE-LINE", Lwrite_line);
 
2051
        make_function("TERPRI", Lterpri);
 
2052
        make_function("FRESH-LINE", Lfresh_line);
 
2053
        make_function("FINISH-OUTPUT", Lfinish_output);
 
2054
        make_function("FORCE-OUTPUT", Lforce_output);
 
2055
        make_function("CLEAR-OUTPUT", Lclear_output);
 
2056
        make_function("WRITE-BYTE", Lwrite_byte);
 
2057
        make_si_sfun("SET-LINE-LENGTH",set_line_length,ARGTYPE1(f_fixnum)
 
2058
                | RESTYPE(f_fixnum));
 
2059
}
 
2060
 
 
2061
 
 
2062
 
 
2063
 
 
2064