File: xlprin.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (1451 lines) | stat: -rw-r--r-- 36,075 bytes parent folder | download
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
/* xlprint - xlisp print routine */
/* Copyright (c) 1989, by David Michael Betz.                            */
/* You may give out copies of this software; for conditions see the file */
/* COPYING included with this distribution.                              */

#include "xlisp.h"
#ifdef XLISP_STAT
#include "xlstat.h"
#endif /* XLISP_STAT */

/* forward declarations */
LOCAL VOID putpacksym P3H(LVAL, LVAL, int);
LOCAL VOID putsymbol P3H(LVAL, char *, int);
LOCAL VOID putstring P2H(LVAL, LVAL);
LOCAL VOID putqstring P2H(LVAL, LVAL);
LOCAL VOID putatm P3H(LVAL, char *, LVAL);
LOCAL VOID putsubr P3H(LVAL, char *, LVAL);
LOCAL VOID putclosure P2H(LVAL, LVAL);
LOCAL VOID putfixnum P2H(LVAL, FIXTYPE);
#ifdef BIGNUMS
LOCAL VOID putbignum P2H(LVAL, LVAL);
#endif
LOCAL VOID putflonum P2H(LVAL, FLOTYPE);
LOCAL VOID putchcode P3H(LVAL, int, int);
LOCAL VOID putoct P2H(LVAL, int);
LOCAL VOID putarray P3H(LVAL, LVAL, int);
LOCAL VOID checkreadable P1H(LVAL);
#ifdef BYTECODE
LOCAL VOID putcpsnode P2H(LVAL, LVAL);
LOCAL VOID putbcode P3H(LVAL, LVAL, int);
LOCAL VOID putbcclosure P3H(LVAL, LVAL, int);
#endif /* BYTECODE */
#ifdef PACKAGES
LOCAL VOID putpackage P2H(LVAL, LVAL);
#endif /* PACKAGES */
LOCAL VOID putrndstate P3H(LVAL, LVAL, int);
#ifdef PRINTCIRCLE
LOCAL LVAL newcircdata(V);
LOCAL VOID addcircdat P2H(LVAL, LVAL);
LOCAL LVAL findcircdat P2H(LVAL, LVAL);
LOCAL VOID cleancircdat P1H(LVAL);
LOCAL LVAL makecircdat P1H(LVAL);
LOCAL int printcircle P2H(LVAL, LVAL);
LOCAL int checkcircle P2H(LVAL, LVAL);
#endif /* PRINTCIRCLE */

/* $putpatch.c$: "MODULE_XLPRIN_C_GLOBALS" */

/* xlprint - print an xlisp value */
VOID xlprint P3C(LVAL, fptr, LVAL, vptr, int, flag)
{
  LVAL temp;
  int readably;

  readably = null(getvalue(s_printreadably)) ? FALSE : TRUE;

  temp = getvalue(s_printlevel);
  if (! readably && fixp(temp) &&
      getfixnum(temp) <= MAXPLEV && getfixnum(temp) >= 0) {
    plevel = (int)getfixnum(temp);
  }
  else {
    plevel = MAXPLEV;     /* clamp to "reasonable" level */
  }
  temp = getvalue(s_printlength);
  if (! readably && fixp(temp) &&
      getfixnum(temp) <= MAXPLEN && getfixnum(temp) >= 0) {
    plength = (int)getfixnum(temp);
  }
  else
    plength = MAXPLEN;
	
  xlprintl(fptr,vptr,flag);
}

#ifdef PRINTCIRCLE
#define PCHSIZE 31

LOCAL LVAL newcircdata(V)
{
  return cons(cvfixnum((FIXTYPE) 0), newvector(PCHSIZE));
}

LOCAL VOID addcircdat P2C(LVAL, x, LVAL, data)
{
  int i = (int) (CVPTR(car(x)) % PCHSIZE);
  rplacd(x, NIL);
  setelement(cdr(data), i, cons(x,getelement(cdr(data), i)));
}

LOCAL LVAL findcircdat P2C(LVAL, x, LVAL, data)
{
  int i = (int) (CVPTR(x) % PCHSIZE);
  LVAL next;
  for (next = getelement(cdr(data), i); consp(next); next = cdr(next))
    if (x == car(car(next)))
      return(car(next));
  return(NIL);
}

LOCAL VOID cleancircdat P1C(LVAL, data)
{
  LVAL next, last;
  int i;

  for (i = 0; i < PCHSIZE; i++) {
    for (next = getelement(cdr(data), i), last = NIL;
	 consp(next);
	 next = cdr(next)) {
      if (! null(cdr(car(next)))) {
	if (null(last)) {
	  setelement(cdr(data), i, next);
	  last = next;
	}
	else {
	  rplacd(last, next);
	  last = next;
	}
      }
    }
    if (null(last))
      setelement(cdr(data), i, NIL);
    else
      rplacd(last, NIL);
  }
}

LOCAL LVAL makecircdat P1C(LVAL, val)
{
  LVAL data, todo, current, cval, entry;

  /* try to avoid consing if val is simple */
  switch (ntype(val)) {
  case SUBR:
  case FSUBR:
  case FIXNUM:
  case FLONUM:
#ifdef BIGNUMS
  case RATIO:
  case BIGNUM:
#endif /* BIGNUMS */
  case STREAM:
  case CHAR:
  case USTREAM:
  case COMPLEX:
#ifdef BYTECODE
  case BCCLOSURE:
#endif /* BYTECODE */
  case CLOSURE:
    return(NIL);
  }

  xlstkcheck(3);
  xlsave(data);
  xlsave(todo);
  xlsave(current);

  data = newcircdata();
  todo = consa(val);

  /* build up the data base of the value to be printed */
  while (consp(todo)) {
    current = todo;
    cval = car(current);
    todo = cdr(todo);
    switch (ntype(cval)) {
    case CONS:
    case DARRAY:
    case RNDSTATE:
      entry = findcircdat(cval,data);
      if (! null(entry))
	rplacd(entry, s_true);
      else {
	addcircdat(current,data);
	todo = cons(cdr(cval),cons(car(cval),todo));
      }
      break;
    case ARRAY:
    case OBJECT:
    case VECTOR:
    case STRUCT:
#ifdef BYTECODE
    case CPSNODE:
    case BCODE:
#endif /* BYTECODE */
      entry = findcircdat(cval,data);
      if (! null(entry))
	rplacd(entry, s_true);
      else {
	int i, n;
	addcircdat(current,data);
#ifdef HASHFCNS
	if (structp(cval) && getelement(cval,0) == a_hashtable)
	  break;
#endif
	for (i = 0, n = getsize(cval); i < n; i++)
	  todo = cons(getelement(cval,i),todo);
      }
      break;
    case SYMBOL:
#ifdef PACKAGES
      if (null(getpackage(cval))) {
	entry = findcircdat(cval,data);
	if (! null(entry))
	  rplacd(entry, s_true);
	else
	  addcircdat(current,data);
      }
#endif /* PACKAGES */
      break;
    case STRING:
    case ADATA:
    case TVEC:
#ifdef PACKAGES
    case PACKAGE:
#endif /* PACKAGES */
      entry = findcircdat(cval,data);
      if (! null(entry))
	rplacd(entry, s_true);
      else
	addcircdat(current,data);
      break;
    }
  }

  /* drop items used only once */
  cleancircdat(data);

  xlpopn(3);
  return(data);
}

LOCAL int printcircle P2C(LVAL, fptr, LVAL, entry)
{
  xlputc(fptr, '#');
  if (fixp(cdr(entry))) {
    putfixnum(fptr, getfixnum(cdr(entry)));
    xlputc(fptr, '#');
    return(TRUE);
  }
  else {
    LVAL data = getvalue(s_prcircdat);
    int n = getfixnum(car(data));
    if (null(cdr(entry))) xlfail("null entry!!");
    putfixnum(fptr, n);
    rplacd(entry, cvfixnum((FIXTYPE) n));
    rplaca(data, cvfixnum((FIXTYPE) n + 1));
    xlputc(fptr, '=');
    return(FALSE);
  }
}

LOCAL int checkcircle P2C(LVAL, fptr, LVAL, val)
{
  LVAL entry;

  if (!null(getvalue(s_printcircle))
      && !null(entry = findcircdat(val,getvalue(s_prcircdat))))
    return(printcircle(fptr, entry));
  else return(FALSE);
}
#endif /* PRINTCIRCLE */
    
VOID xlprintl P3C(LVAL, fptr, LVAL, vptr, int, flag)
{
    LVAL nptr,next;
    int n,i;
    int llength;
    LVAL olddenv;
#ifdef PRINTCIRCLE
    LVAL entry;
#endif /* PRINTCIRCLE */

#ifdef STSZ
    /* check the stack */
    stchck();
#endif

    olddenv = xldenv;
    if (flag ^ (! null(getvalue(s_printescape))))
      xldbind(s_printescape, flag ? s_true : NIL);

    if (! null(getvalue(s_printreadably))) {
      if (!null(getvalue(s_printlevel)))
	xldbind(s_printlevel, NIL);
      if (!null(getvalue(s_printlength)))
	xldbind(s_printlength, NIL);
      if (null(getvalue(s_printgensym)))
	xldbind(s_printgensym, s_true);
      if (null(getvalue(s_printescape))) {
	xldbind(s_printescape, s_true);
	flag = TRUE;
      }
#ifdef PRINTCIRCLE
      if (null(getvalue(s_printcircle)))
	xldbind(s_printcircle, s_true);
#endif /* PRINTCIRCLE */
#ifdef BIGNUMS
      if (!null(getvalue(s_printbase)))
	xldbind(s_printbase, cvfixnum((FIXTYPE) 10));
#endif /* BIGNUMS */
    }

#ifdef PRINTCIRCLE
    if (getvalue(s_printcircle) != NIL && ! boundp(s_prcircdat))
      xldbind(s_prcircdat,makecircdat(vptr));
#endif /* PRINTCIRCLE */

    /* check value type */
    switch (ntype(vptr)) {
    case SUBR:
	    putsubr(fptr,"Subr",vptr);
	    break;
    case FSUBR:
	    putsubr(fptr,"FSubr",vptr);
	    break;
    case CONS:
            if (plevel-- == 0) {            /* depth limitation */
		xlputc(fptr, '#');
                plevel++;
                break;
	      }
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr))
	      break;
#endif /* PRINTCIRCLE */

	    xlputc(fptr,'(');
            llength = plength;
	    for (nptr = vptr; nptr != NIL; nptr = next) {
	      if (llength-- == 0) { /* length limitiation */
		xlputstr(fptr,"...");
		break;
	      }
	      xlprintl(fptr,car(nptr),flag);
	      if ((next = cdr(nptr)) != NIL) {
#ifdef PRINTCIRCLE
		if (!null(getvalue(s_printcircle))
		    && !null(entry = findcircdat(next,getvalue(s_prcircdat)))) {
		  xlputstr(fptr, " . ");
		  xlprintl(fptr,next,flag);
		  break;
		}
		else
#endif /* PRINTCIRCLE */
		if (consp(next))
		  xlputc(fptr,' ');
		else {
		  xlputstr(fptr," . ");
		  xlprintl(fptr,next,flag);
		  break;
		}
	      }
	    }
	    xlputc(fptr,')');
            plevel++;
	    break;
    case SYMBOL:
	    if (vptr == s_unbound) {    /* TAA MOD for new unbound 1/92 */
	      checkreadable(vptr);
	      xlputstr(fptr, "#<Unbound>");
	      break;
	    }
	    putpacksym(fptr, vptr, flag);
	    break;
    case FIXNUM:
	    putfixnum(fptr,getfixnum(vptr));
	    break;
    case FLONUM:
	    putflonum(fptr,getflonum(vptr));
	    break;
    case CHAR:
	    putchcode(fptr,getchcode(vptr),flag);
	    break;
    case STRING:
	    if (flag)
#ifdef PRINTCIRCLE
	      {
		if (! checkcircle(fptr, vptr))
		  putqstring(fptr, vptr);
	      }
#else
                putqstring(fptr, vptr);
#endif /* PRINTCIRCLE */
	    else
		putstring(fptr,vptr);
	    break;
    case STREAM:
#ifdef FILETABLE
        {
            char *msg;
            FILEP fp = getfile(vptr);
	    checkreadable(vptr);
            if (fp == CLOSED)   xlputstr(fptr, "#<Closed-Stream>");
            else {
#ifndef BIGNUMS
	        char *msg2 = (vptr->n_sflags & S_BINARY)?"Binary":"Character";
#endif
                switch (vptr->n_sflags & (S_FORREADING | S_FORWRITING)) {
                    case S_FORREADING: msg = "Input-Stream"; break;
                    case S_FORWRITING: msg = "Output-Stream"; break;
                    default: msg = "IO-Stream"; break;
                }
#ifdef BIGNUMS
		if (vptr->n_sflags & S_BINARY)
		  sprintf(buf,"#<%s-Byte-%lu-%s %d:\"%s\">",
			  (vptr->n_sflags&S_UNSIGNED)?"Unsigned":"Signed",
			  vptr->n_bsiz*((unsigned long) 8L), msg, fp+1, filetab[fp].tname);
		else
		  sprintf(buf,"#<Character-%s %d:\"%s\">",
			  msg, fp+1, filetab[fp].tname);
#else
                sprintf(buf,"#<%s %s %d:\"%s\">", msg2, msg, fp+1, filetab[fp].tname);
#endif
                xlputstr(fptr,buf);
            }
        }
#else
        {
            char *msg;
            FILEP fp = getfile(vptr);
            if (fp == CLOSED)   msg = "Closed-Stream";
            else if (fp == STDIN) msg = "Stdin-Stream";
            else if (fp == STDOUT) msg = "Stdout-Stream";
            else if (fp == CONSOLE) msg = "Terminal-Stream";
            else switch (vptr->n_sflags & (S_FORREADING | S_FORWRITING | S_BINARY)) {
                case (S_FORREADING|S_BINARY): msg = "Binary Input-Stream"; break;
                case (S_FORWRITING|S_BINARY): msg = "Binary Output-Stream"; break;
                case S_BINARY: msg = "Binary IO-Stream"; break;
                case S_FORREADING: msg = "Input-Stream"; break;
                case S_FORWRITING: msg = "Output-Stream"; break;
                default: msg = "IO-Stream"; break;
            }
            putatm(fptr,msg,vptr);
        }
#endif
	    break;
    case USTREAM:
	    putatm(fptr,"Unnamed-Stream",vptr);
	    break;
    case OBJECT:
#ifdef PRINTCIRCLE
            if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
#ifdef XLISP_STAT
            print_mobject(vptr, fptr);
#else
            /* putobj fakes a (send obj :prin1 file) call */
            putobj(fptr,vptr);
#endif /* XLISP_STAT */
	    break;
    case VECTOR:
    case TVEC:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    if (! null(getvalue(s_printreadably)) && tvecp(vptr)) {
	      LVAL tmp;

	      xlsave1(tmp);
	      n = gettvecsize(vptr);
	      tmp = gettvecetype(vptr);
	      
	      xlputstr(fptr, "#.(");
	      putpacksym(fptr, s_make_array, TRUE);
	      xlputc(fptr, ' ');
	      putfixnum(fptr, n);
	      xlputc(fptr, ' ');
	      putpacksym(fptr, k_elementtype, TRUE);
	      xlputstr(fptr, " '");
	      xlprintl(fptr, tmp, TRUE);
	      xlputc(fptr, ' ');
	      putpacksym(fptr, k_initcont, TRUE);
	      xlputstr(fptr, " '(");

	      for (i = 0; i < n; i++) {
		tmp = gettvecelement(vptr,i);
		xlprintl(fptr,tmp,flag);
                if (i < n - 1) xlputc(fptr,' ');
	      }
	      xlputstr(fptr, "))");
	      xlpop();
	    }
	    else {
	      LVAL item;

	      if (plevel-- == 0) {            /* depth limitation */
		xlputc(fptr, '#');
                plevel++;
                break;
	      }
	      xlputc(fptr,'#'); xlputc(fptr,'(');
	      llength = plength;
	      n = gettvecsize(vptr);
	      
	      xlsave1(item);
	      for (i = 0; i < n; i++) {
                if (llength-- == 0) {        /* length limitiation */
		  xlputstr(fptr,"... ");
		  break;
		}
		item = gettvecelement(vptr,i);
		xlprintl(fptr,item,flag);
                if (i < n - 1) xlputc(fptr,' ');
	      }
	      xlpop();
	      xlputc(fptr,')');
	      plevel++;
	    }
	    break;
	case STRUCT:
#ifdef HASHFCNS
            if (getelement(vptr,0) == a_hashtable) {
                putatm(fptr,"Hash-table",vptr);
	    break;
            }
#endif
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    xlprstruct(fptr,vptr,plevel,flag);
	    break;
    case CLOSURE:
	    putclosure(fptr,vptr);
	    break;
#ifdef BIGNUMS
    case BIGNUM:
	    putbignum(fptr, vptr);
	    break;
    case RATIO:
	    xlprintl(fptr,getnumer(vptr),flag);
	    xlputc(fptr,'/');
	    xlprintl(fptr,getdenom(vptr),flag);
	    break;
#endif
    case COMPLEX:
	    xlputstr(fptr, "#C(");
	    xlprintl(fptr,getreal(vptr),flag);
	    xlputc(fptr,' ');
	    xlprintl(fptr,getimag(vptr),flag);
	    xlputc(fptr, ')');
	    break;
    case ADATA:  /* L. Tierney */
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    putatm(fptr,"Data",vptr);
	    break;
    case NATPTR:  /* L. Tierney */
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    checkreadable(vptr);
	    if (flag) {
	      sprintf(buf, "#<%s: #", "Pointer");
	      xlputstr(fptr, buf);
	    }
	    sprintf(buf, AFMT, CVPTR(getnpaddr(vptr)));
	    xlputstr(fptr, buf);
	    if (flag)
	      xlputc(fptr, '>');
	    break;
    case WEAKBOX:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    checkreadable(vptr);
	    putatm(fptr,"Weak Box",vptr);
	    break;
    case DARRAY:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    if (plevel == 0)
	      xlputc(fptr, '#');
	    else
	      putarray(fptr, vptr, flag);
	    break;
#ifdef BYTECODE
    case BCCLOSURE:
	    putbcclosure(fptr, vptr, flag);
	    break;
    case CPSNODE:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    putcpsnode(fptr,vptr);
	    break;
    case BCODE:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    putbcode(fptr,vptr,flag);
	    break;
#endif /* BYTECODE */
#ifdef PACKAGES
    case PACKAGE:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    putpackage(fptr,vptr);
	    break;
#endif /* PACKAGES */
    case RNDSTATE:
#ifdef PRINTCIRCLE
	    if (checkcircle(fptr, vptr)) break;
#endif /* PRINTCIRCLE */
	    putrndstate(fptr, vptr, flag);
	    break;
    case FREE:
	    putatm(fptr,"Free",vptr);
	    break;

    /* $putpatch.c$: "MODULE_XLPRIN_C_XLPRINT" */

    default:
	    putatm(fptr,"Unknown",vptr);        /* was 'Foo`   TAA Mod */
	    break;
    }
    xlunbind(olddenv);
}

/* xlterpri - terminate the current print line */
VOID xlterpri P1C(LVAL, fptr)
{
    xlputc(fptr,'\n');
}

/* xlgetcolumn -- find the current file column */

int xlgetcolumn P1C(LVAL, fptr)
{
    if (fptr == NIL) return 0;
    else if (ntype(fptr) == USTREAM) { /* hard work ahead :-( */
        LVAL ptr = gethead(fptr);
        int count = 0;

        while (ptr != NIL) {
            if (getchcode(car(ptr)) == '\n') count = 0 ;
            else count++;
            ptr = cdr(ptr);
        }
        return count;
    }
    else if (getfile(fptr) == CONSOLE)
        return lposition;
    else
        return ((fptr->n_sflags & S_WRITING)? fptr->n_cpos : 0);
}


/* xlfreshline -- start new line if not at beginning of line */
int xlfreshline P1C(LVAL, fptr)
{
    if (xlgetcolumn(fptr) != 0) {
        xlterpri(fptr);
        return TRUE;
    }
    return FALSE;
}

/* xlputstr - output a string */
VOID xlputstr P2C(LVAL, fptr, char *, str)
{
    /* solve reentrancy problems if gc prints messages and
       xlputstr output is directed to a string stream */
    if (ustreamp(fptr)) {
        int oplevel=plevel, oplength=plength;   /* save these variables */
        char nbuf[STRMAX+1];

        if (buf == str) {   /* copy to reentrant buffer if necessary */
            str = strcpy(nbuf, buf);
        }

        while (*str)        /* print string */
            xlputc(fptr, *str++);

        plevel = oplevel;   /* restore level and length */
        plength = oplength;
    }
    else
    while (*str)
	xlputc(fptr,*str++);
}

/* print package and symbol */
#ifdef PACKAGES
LOCAL VOID putpacksym P3C(LVAL, fptr, LVAL, sym, int, flag)
{
  LVAL pack, foundsym;
  char *pname;
  int full;

  pack = getvalue(s_package);
  pname = getstring(getpname(sym));
  
  full = (null(getvalue(s_printsympack))) ? FALSE : TRUE;

  if (!flag || !goodpackagep(pack))
    putsymbol(fptr, pname, flag);
  else if (keywordp(sym)) {
    xlputc(fptr, ':');
    putsymbol(fptr, pname, flag);
  }
  /* TAA MOD 10/96 -- if no home package, always print with #: */
  else if (! full && (!null(getpackage(sym))) &&
	   xlfindsymbol(pname, pack, &foundsym) && sym == foundsym)
    putsymbol(fptr, pname, flag);
  else {
    /* TAA modified to handle mixed cases when in :invert, 9/13/96 */
    LVAL olddenv = xldenv;
    pack = getpackage(sym);
    if (packagep(pack)) {
      if (getvalue(s_rtcase) == k_invert)  {
	char *cp, c;
	int up=0, low=0;
	cp = getstring(xlpackagename(pack));
	while ((c=*cp++)!='\0') {
	  if (ISUPPER(c)) up++;
	  else if (ISLOWER(c)) low++;
	}
	cp = getstring(getpname(sym));
	while ((c=*cp++)!='\0') {
	  if (ISUPPER(c)) up++;
	  else if (ISLOWER(c)) low++;
	}
	xldbind(s_rtcase, ((up!=0 && low!=0) ? k_preserve : k_invert));
      }
      putsymbol(fptr, getstring(xlpackagename(pack)), flag);
      if (! full && xlfindsymbol(pname, pack, &foundsym) == SYM_EXTERNAL)
	xlputc(fptr, ':');
      else
	xlputstr(fptr, "::");
      putsymbol(fptr, pname, flag);
      xlunbind(olddenv);
    }
    else if (flag && !null(getvalue(s_printgensym))) {
#ifdef PRINTCIRCLE
      if (! checkcircle(fptr, sym)) {
	xlputstr(fptr,"#:");
	putsymbol(fptr, pname, flag);
      }
#else
      xlputstr(fptr,"#:");
      putsymbol(fptr, pname, flag);
#endif /* PRINTCIRCLE */
    }
    else putsymbol(fptr, pname, flag);
  }
}
#else
LOCAL VOID putpacksym P3C(LVAL, fptr, LVAL, sym, int, flag)
{
  /* check for uninterned symbol */
  if (flag && !null(getvalue(s_printgensym)) && ! syminterned(sym))
    xlputstr(fptr,"#:");
  putsymbol(fptr, getstring(getpname(sym)), flag);
}
#endif /* PACKAGES */

#ifdef READTABLECASE
#define RUP  0      /* values for upcase, downcase, preserve, and invert */
#define RDWN 1
#define RPRE 2
#define RINV 3
#endif

/* putsymbol - output a symbol */
LOCAL VOID putsymbol P3C(LVAL, fptr, char *, stri, int, flag)
{
#ifdef READTABLECASE
    LVAL rtcase = getvalue(s_rtcase);
    int rcase,up,low;
    int mixcase;
#endif
    int downcase;
    int capitalize;
    LVAL type;
    unsigned char *p;
    unsigned char c;
#define str stri

#ifdef READTABLECASE
    /* check value of *readtable-case* */
    if      (rtcase == k_upcase)   rcase = RUP;
    else if (rtcase == k_invert)   rcase = RINV;
    else if (rtcase == k_downcase) rcase = RDWN;
    else if (rtcase == k_preserve) rcase = RPRE;
    else rcase = RUP;                           /* default is upcase */
#endif

    /* handle escaping if flag is true */
    if (flag) {
        /* check to see if symbol needs escape characters */
        for (p = (unsigned char *)str; (c = *p) != 0 ; ++p)
#ifdef READTABLECASE
            if    ((rcase == RUP && ISLOWER(c))
                || (rcase == RDWN && ISUPPER(c))
                ||  ((type = tentry(c)) != k_const
                    && (!consp(type) || car(type) != k_nmacro)))
#else
            if (ISLOWER(c)
                ||  ((type = tentry(c)) != k_const
                    && (!consp(type) || car(type) != k_nmacro)))
#endif
            {
		xlputc(fptr,'|');
		while (*str) {
		    if (*str == '\\' || *str == '|')
			xlputc(fptr,'\\');
		    xlputc(fptr,*str++);
		}
		xlputc(fptr,'|');
		return;
	    }
        /* check for the first character being '#'
            or string looking like a number */
        if (*str == '#' || isnumber(str,NULL))
            xlputc(fptr,'\\');
    }

    /* get the case translation flag -- default upcase */
    downcase = (getvalue(s_printcase) == k_downcase);
    /* use capitalize mode if RUP or RDWN and printcase is capitalize */
    capitalize = 
#ifdef READTABLECASE
        (rcase==RUP || rcase==RDWN) &&
#endif
        (getvalue(s_printcase) == k_capitalize);

#ifdef READTABLECASE
    /* we need to know if there is a mixed case symbol if reading :INVERT */
    if (rcase == RINV)  {
        up=FALSE;
        low=FALSE;
        mixcase = FALSE;
        for (p=(unsigned char *)str ; (c = *p) != 0 && !mixcase ; ++p)  {
            if (ISLOWER(c))
                low = TRUE;
            else if (ISUPPER(c))
                up = TRUE;
            mixcase = up&low;
        }
        if (mixcase) rcase = RPRE;  /* preserve if cases mixed */
    }
    low = (rcase == RINV) || (rcase == RUP && (downcase||capitalize));
    up  = (rcase == RINV) || (rcase == RDWN && !downcase);

#endif

    /* output each character */
    mixcase = TRUE; /* set at start of a "word */
    while ((c = (unsigned char) *str++) != 0) {
#ifdef PACKAGES
	if (flag && (c == '\\' || c == '|' || c == ':'))
#else
	if (flag && (c == '\\' || c == '|'))
#endif /* PACKAGES */
	    xlputc(fptr,'\\');
#ifdef READTABLECASE
        if (capitalize) {
            xlputc(fptr, (mixcase ? ((ISLOWER(c)&&up) ? TOUPPER(c) : c)
                                  : ((ISUPPER(c)&&low) ? TOLOWER(c) : c)));
            mixcase = !ISLOWERA(c) && !ISUPPER(c);
        }
        else if (ISUPPER(c)) xlputc(fptr, low ? TOLOWER(c) : c);
        else if (ISLOWER(c)) xlputc(fptr, up  ? TOUPPER(c) : c);
        else xlputc(fptr,c);
#else
        if (capitalize) {
            xlputc(fptr, (mixcase ? (ISLOWER(c) ? TOUPPER(c) : c)
                                  : (ISUPPER(c) ? TOLOWER(c) : c)));
            mixcase = !ISLOWERA(c) && !ISUPPER(c);
        }
	else xlputc(fptr,(downcase && ISUPPER(c) ? TOLOWER(c) : c));
#endif
    }
}

#undef str

/* putstring - output a string */
/* rewritten to  print strings containing nulls TAA mod*/
LOCAL VOID putstring P2C(LVAL, fptr, LVAL, str)
{
    char *p = getstring(str);
    unsigned len = getslength(str);

    /* output each character */
    while (len-- > 0) xlputc(fptr,*p++);
}

/* putqstring - output a quoted string */
/* rewritten to  print strings containing nulls TAA mod*/
LOCAL VOID putqstring P2C(LVAL, fptr, LVAL, str)
{
    char *p = getstring(str);
    unsigned len = getslength(str);
    int ch;

    /* output the initial quote */
    xlputc(fptr,'"');

    /* output each character in the string */
    while (len-- > 0) {
#ifdef __SASC__
	/* For IBM mainframe, Convert EBCDIC to ASCII for the tests below */
	int testch;

	ch = *(unsigned char *)p++;
	testch = etoa(ch);

	/* check for a control character */
	if (testch < 040 || testch == '\\' ||
	    testch == '"' || testch > 0176) /* TAA MOD quote quote */
#else /* __SASC__ */
        ch = *(unsigned char *)p++;

	/* check for a control character */
	/* removed newline - Luke Tierney */
#ifdef ASCII8   /* in this case, upper bit set characters are printable! */
                /* TAA MOD added 8/92 */
        if (ch != '\n' && (ch < 040 || ch == '\\' || ch == '"' || (ch&0177) == 0177))
#else
	if (ch != '\n' && (ch < 040 || ch == '\\' || ch == '"' || ch > 0176)) /* TAA MOD quote quote */
#endif
#endif
            {
	    xlputc(fptr,'\\');
#ifdef __SASC__
	    switch (testch)
#else
	    switch (ch)
#endif
	    {
	    case '\011':
		    xlputc(fptr,'t');
		    break;
	    case '\012':
		    xlputc(fptr,'n');
		    break;
	    case '\014':
		    xlputc(fptr,'f');
		    break;
	    case '\015':
		    xlputc(fptr,'r');
		    break;
	    case 0x5c:  /* is '\\' except for EBCDIC */
	    case 0x22:  /* is '"'  except for EBCDIC, so use int constant*/
		    xlputc(fptr,ch);
		    break;
	    default:
		    putoct(fptr,ch);
		    break;
	    }
	}

	/* output a normal character */
	else
	    xlputc(fptr,ch);
    }

    /* output the terminating quote */
    xlputc(fptr,'"');
}

/* putatm - output an atom */
LOCAL VOID putatm P3C(LVAL, fptr, char *, tag, LVAL, val)
{
    checkreadable(val);
    sprintf(buf, "#<%s: #", tag);
    xlputstr(fptr, buf);
    sprintf(buf, AFMT, CVPTR(val)); /* TAA Fix 2/94: was just val */
    xlputstr(fptr, buf);
    xlputc(fptr, '>');
}

/* putsubr - output a subr/fsubr */
LOCAL VOID putsubr P3C(LVAL, fptr, char *, tag, LVAL, val)
{
/*    sprintf(buf,"#<%s-%s: #",tag,funtab[getoffset(val)].fd_name); */
    char *str;      /* TAA mod */
    checkreadable(val);
    if ((str = funtab[getoffset(val)].fd_name) != NULL)
        sprintf(buf,"#<%s-%s: #",tag,str);
    else
        sprintf(buf,"#<%s: #",tag);
    xlputstr(fptr, buf);
    sprintf(buf, AFMT, CVPTR(val)); /* TAA Fix 2/94: was just val */
    xlputstr(fptr, buf);
    xlputc(fptr, '>');
}

/* putclosure - output a closure */
LOCAL VOID putclosure P2C(LVAL, fptr, LVAL, val)
{
    LVAL name;
    checkreadable(val);
    if ((name = getname(val)) != NIL)
	sprintf(buf,"#<Closure-%s: #",getstring(getpname(name)));
    else
	strcpy(buf,"#<Closure: #");
    xlputstr(fptr, buf);
    sprintf(buf, AFMT, CVPTR(val)); /* TAA Fix 2/94: was just val */
    xlputstr(fptr, buf);
    xlputc(fptr, '>');
}

/* print an array */
LOCAL VOID putarray P3C(LVAL, fptr, LVAL, array, int, flag)
{
  LVAL value, data;
  
  /* protect a pointer */
  xlsave1(value);
  
  data = getdarraydata(array);
  if (! null(getvalue(s_printreadably)) && (stringp(data) || tvecp(data))) {
    LVAL tmp;
    int i, n;

    xlsave1(tmp);
    xlputstr(fptr, "#.(");
    putpacksym(fptr, s_make_array, TRUE);

    value = getdarraydim(array);
    n = getsize(value);
    xlputstr(fptr, " '(");
    for (i = 0; i < n; i++) {
      tmp = getelement(value,i);
      xlprintl(fptr,tmp,flag);
      if (i < n - 1) xlputc(fptr,' ');
    }
    xlputstr(fptr, ") ");

    value = gettvecetype(data);
    putpacksym(fptr, k_elementtype, TRUE);
    xlputstr(fptr, " '");
    xlprintl(fptr, value, TRUE);

    value = array_to_nested_list(array);
    xlputc(fptr, ' ');
    putpacksym(fptr, k_initcont, TRUE);
    xlputstr(fptr, " '");
    if (value == NIL) {
      xlputc(fptr,'(');
    xlputc(fptr,')');
    }
    else
      xlprintl(fptr, value, flag);
    xlputc(fptr, ')');
    xlpop();
  }
  else {
    xlputc(fptr,'#');
    value = cvfixnum((FIXTYPE) getdarrayrank(array));
    xlprint(fptr, value, flag);
    xlputc(fptr, 'A');
    value = array_to_nested_list(array);
    if (value == NIL) {
      xlputc(fptr,'(');
      xlputc(fptr,')');
    }
    else
      xlprintl(fptr, value, flag);
  }
  
  /* restore the stack frame */
  xlpop();
}

#ifdef BYTECODE
/* putcpsnode - output a CPS node */
LOCAL VOID putcpsnode P2C(LVAL, fptr, LVAL, val)
{
    LVAL type;
    checkreadable(val);
    type = getcpstype(val);
    if (null(type) || ! symbolp(type))
	strcpy(buf,"#<CPS-Node NIL: #");
    else
	sprintf(buf,"#<CPS-Node %s: #",getstring(getpname(type)));
    xlputstr(fptr,buf);
    sprintf(buf,AFMT, CVPTR(val)); xlputstr(fptr,buf);
    xlputc(fptr,'>');
}

/* putbcode - output a byte code vector */
LOCAL VOID putbcode P3C(LVAL, fptr, LVAL, val, int, flag)
{
  if (null(getvalue(s_printreadably))) {
    sprintf(buf,"#<Byte-Code: #");
    xlputstr(fptr,buf);
    sprintf(buf,AFMT, CVPTR(val));
    xlputstr(fptr,buf);
    xlputc(fptr,'>');
  }
  else {
    LVAL olddenv = xldenv;
    if (getvalue(s_rtcase) != k_upcase)
      xldbind(s_rtcase, k_upcase);
    if (getvalue(s_printcase) != k_upcase)
      xldbind(s_printcase, k_upcase);
    xlputc(fptr,'#');
    xlputc(fptr, 'K');
    xlputc(fptr, '(');
    xlputc(fptr,'#');
    xlputc(fptr,'(');
    {
      int i, n;
      char *s;

      s = getstring(getbccode(val));
      n = getslength(getbccode(val)) - 1;

      for (i = 0; i < n; ++i) {
	putfixnum(fptr, (FIXTYPE) (unsigned char) s[i]);
	xlputc(fptr,' ');
      }
      putfixnum(fptr, (FIXTYPE) (unsigned char) s[n]);
      xlputc(fptr,')');
    }
    xlputc(fptr, ' ');
    xlprint(fptr, getbcjtab(val), flag);
    xlputc(fptr, ' ');
    xlprint(fptr, getbclits(val), flag);
    xlputc(fptr, ' ');
    xlprint(fptr, getbcidx(val), flag);
    xlputc(fptr, ' ');
    xlprint(fptr, getbcenv(val), flag);
    xlputc(fptr,')');
    xlunbind(olddenv);
  }
}
#endif /* BYTECODE */

/* putrndstate - output a random state */
LOCAL VOID putrndstate P3C(LVAL, fptr, LVAL, val, int, flag)
{
  xlputstr(fptr,"#$(");
  xlprintl(fptr, getrndgen(val), flag);
  xlputc(fptr, ' ');
  xlprintl(fptr, getrnddata(val), flag);
  xlputc(fptr,')');
}

#ifdef BYTECODE
/* putbcclosure - output a random state */
LOCAL VOID putbcclosure P3C(LVAL, fptr, LVAL, val, int, flag)
{
    LVAL name;
    checkreadable(val);
    if ((name = getbcname(getbcccode(val))) != NIL)
      sprintf(buf,"#<Byte-Code-Closure-%s: #",getstring(getpname(name)));
    else
      strcpy(buf,"#<Byte-Code-Closure: #");
    xlputstr(fptr,buf);
    sprintf(buf,AFMT, CVPTR(val)); xlputstr(fptr,buf);
    xlputc(fptr,'>');
}
#endif /* BYTECODE */

/* putfixnum - output a fixnum */
LOCAL VOID putfixnum P2C(LVAL, fptr, FIXTYPE, n)
{
#ifdef BIGNUMS
	if (getvalue(s_printbase) != NIL) {
		/* expect non decimal radix */
		putbignum(fptr, cvtfixbignum(n));
		return;
	}
	else {
		sprintf(buf, INTFMT, n);
	}
#else
    LVAL val;
    char *fmt;

    val = getvalue(s_ifmt);
    fmt = (stringp(val) ? getstring(val) : INTFMT);
    sprintf(buf,fmt,n);
#endif
    xlputstr(fptr,buf);
}

#ifdef PACKAGES
/* putpackage - output package */
LOCAL VOID putpackage P2C(LVAL, fptr, LVAL, val)
{
  LVAL names;
  checkreadable(val);
  names = getpacknames(val);
  if (consp(names) && stringp(car(names))) {
    sprintf(buf,"#<Package %s>",getstring(car(names)));
    xlputstr(fptr, buf);
  }
  else {
    xlputstr(fptr, "#<Package ???: #");
    sprintf(buf,AFMT, CVPTR(val)); /* TAA Fix 2/94, was (OFFTYPE)val */
    xlputstr(fptr,buf);
    xlputc(fptr,'>');
  }
}
#endif /* PACKAGES */

#ifdef BIGNUMS
/* putbignum - output a bignum */
LOCAL VOID putbignum P2C(LVAL, fptr, LVAL, n)
{
	LVAL val;
	FIXTYPE radix;
	char *pstring;

	if (zeropbignum(n)) {
	  /* skip all of this for zero */
	  xlputc(fptr, '0');
	  return;
	}

	val = getvalue(s_printbase);
	if (fixp(val)) {
		radix = getfixnum(val);
		if (radix < 2 || radix > 36) radix = 10;
	}
	else
		radix = 10;

	pstring = cvtbignumstr(n, (int)radix);
	xlputstr(fptr, pstring);
	MFREE(pstring);
}
#endif

int read_exponent P1C(char *, s)
{
  int i;

  i = 0;
  if (s[0] == '+' || s[0] == '-') i++;
  for (; s[i] != 0; i++)
    if (! isdigit(s[i]))
      return(0);
  return(atoi(s));
}

/* modified for consistency with CL -- L. Tierney */
/* putflonum - output a flonum */
LOCAL VOID putflonum P2C(LVAL, fptr, FLOTYPE, n)
{
#ifdef OLDPRINT
  char *fmt;
  LVAL val;

  val = getvalue(s_ffmt);
  fmt = (stringp(val) ? getstring(val) : "%g");
  sprintf(buf,fmt,n);
  xlputstr(fptr,buf);
#else
  if (stringp(getvalue(s_ffmt)) && null(getvalue(s_printreadably))) {
    sprintf(buf, getstring(getvalue(s_ffmt)), n);
    xlputstr(fptr,buf);
  }
  else {
#ifdef IEEEFP
    if (! is_finite(n)) {
      xlputstr(fptr,"#.");
      if (is_nan(n))
	putpacksym(fptr, s_notanumber, TRUE);
      else if (n > 0)
	putpacksym(fptr, s_posinfinity, TRUE);
      else
	putpacksym(fptr, s_neginfinity, TRUE);
      return;
    }
#endif
    /* print the sign */
    if (n < 0) {
      xlputc(fptr, '-');
      n = -n;
    }

    if (n == 0.0) xlputstr(fptr, "0.0");
    else if (1.0e-3 <= n && n < 1.0e7) {
      int e, f, i, m;
      char *ep;

      write_double_efmt(buf, n, 16);

      /* locate the exponent */
      ep = strchr(buf, 'e');

      if (ep != NULL) { /* exponent found -- should always be true */
	/* read exponent and terminate string */
	e = read_exponent(ep + 1);
	*ep = 0;

	/* trim trailing zeros and find lingth of fractional part */
	for (ep--; *ep == '0' && ep > buf; ep--)
	  *ep = 0;
	f = ep - buf - 1;

	if (e < 0) {
	  MEMMOVE(buf + 2 - e, buf + 2, f); /* shift fractional part */
	  buf[1 - e] = buf[0];              /* move leading digit */
	  buf[0] = '0';                     /* set leading digit to zero */
	  for (i = 2; i < 1 - e; i++)       /* insert zeros if needed */
	    buf[i] = '0';
	  buf[2 + f - e] = 0;               /* terminate string */
	}
	else {
	  m = e > f ? f : e;                /* shift the decimal point */
	  MEMMOVE(buf + 1, buf + 2, m);
	  f -= m;
	  buf[e + 1] = '.';
	  for (i = m + 1; i < e + 1; i++)   /* insert zeros */
	    buf[i] = '0';
	  if (f == 0) {                     /* add trailing zero if needed */
	    buf[e + 2] = '0';
	    buf[e + 3] = 0;
	  }
	}
      }
      xlputstr(fptr,buf);
    }
    else {
      int d, e, i, z;

      write_double_efmt(buf, n, 16);

      /* locate the decimal point */
      for (i = 0, d = -1; buf[i] != 0; i++) {
	if (buf[i] == '.') {
	  d = i;
	  break;
	}
      }

      if (d != -1) { /* decimal point found -- true unless Infinity or NaN */

	/* find the exponent marker */
	for (e = d + 1; buf[e] != 0 && ! isalpha(buf[e]); e++);

	/* find the first trailing zero, if any */
	for (z = e - 1; z > d + 1 && buf[z] == '0'; z--);
	z++;

	/* process the exponent */
	if (isalpha(buf[e])) {
	  i = read_exponent(buf + e + 1);
	  sprintf(buf + z, "E%d", i);
	}
      }
      xlputstr(fptr,buf);
    }
  }
#endif /* OLDPRINT */
}

/* putchcode - output a character */
/* modified to print control and meta characters TAA Mod */
LOCAL VOID putchcode P3C(LVAL, fptr, int, ch, int, escflag)
{
#ifdef __SASC__
    int testch = etoa((unsigned) ch);
#endif
    if (escflag) {
        xlputstr(fptr,"#\\");
#ifndef ASCII8  /* print graphics if not defined */
#if __SASC__
	if (testch > 127) {
	    testch -= 128;
	    xlputstr(fptr,"M-");
	}
#else
        if (ch > 127) {
            ch -= 128;
            xlputstr(fptr,"M-");
        }
#endif
#endif
#ifdef __SASC__
	switch (testch)
#else
	switch (ch)
#endif
	{
	case 0x0a:	/* ASCII '\n' */
	    xlputstr(fptr,"Newline");
	    break;
	case 0x20:	/* ASCII ' ' */
	    xlputstr(fptr,"Space");
	    break;
	case 127:
	    xlputstr(fptr,"Rubout");
	    break;
	case 12:
	    xlputstr(fptr,"Page");
	    break;
        case '\t':
	    xlputstr(fptr,"Tab");
	    break;
	case 8:
	    xlputstr(fptr,"Backspace");
	    break;
	case 13:
	    xlputstr(fptr,"Return");
	    break;
#ifdef ASCII8
	case 255:
	    xlputstr(fptr,"M-Rubout");
#endif
#ifdef MACINTOSH /* lines added by Luke Tierney, March 12, 1988 */
	case 0x12: xlputstr(fptr, "Check"); break;
	case 0x14: xlputstr(fptr, "Apple"); break;
#endif /* MACINTOSH */ /* lines added by Luke Tierney, March 12, 1988 */
	default:
#ifdef __SASC__
		if (testch < 32) {
		    testch += '@';
		    xlputstr(fptr,"C-");
		}
		/* Convert ASCII testch to EBCDIC for printing... */
		xlputc(fptr,atoe((unsigned)testch));
		break;
#else
	    if (ch < 32) {
	      ch += '@';
	      xlputstr(fptr,"C-");
	    }
	    xlputc(fptr,ch);
	    break;
#endif
	}
    }
    else xlputc(fptr,ch);
}

/* putoct - output an octal byte value */
LOCAL VOID putoct P2C(LVAL, fptr, int, n)
{
    sprintf(buf,"%03o",n);
    xlputstr(fptr,buf);
}

/* signal error if *print-readably* is true */
LOCAL VOID checkreadable P1C(LVAL, x)
{
  /* argument is ignored; eventually need to print unreadable version */
  if (!null(getvalue(s_printreadably)))
    xlfail("can't readably print an unreadable object");
}