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
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
|
Path: funic!news.funet.fi!sunic!uupsi!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!charon!guido
From: [email protected] (Guido van Rossum)
Newsgroups: alt.sources
Subject: Python 0.9.1 part 21/21
Message-ID: <[email protected]>
Date: 19 Feb 91 17:42:58 GMT
Sender: [email protected]
Organization: CWI, Amsterdam
Lines: 1675
Originator: [email protected]
: This is a shell archive.
: Extract with 'sh this_file'.
:
: Extract part 01 first since it makes all directories
echo 'Start of pack.out, part 21 out of 21:'
if test -s 'demo/README'
then echo '*** I will not over-write existing file demo/README'
else
echo 'x - demo/README'
sed 's/^X//' > 'demo/README' << 'EOF'
XThis directory contains various demonstrations of what you can do with
XPython. The demos are grouped sub(sub*)directories according to
Xrequired optional built-in modules.
X
Xscripts Some useful Python scripts that I put in my bin
X directory. No optional built-in modules meeded.
X
Xsgi Demos that only run on Silicon Graphics machines.
X Require the built-in modules 'audio' and/or 'gl'.
X
Xstdwin Demos that use the STDWIN library. Require the 'stdwin'
X built-in module.
X
XWARNING: some scripts are executable and have a first line saying
X
X #! /ufs/guido/bin/sgi/python
X
XThis is unlikely to give good results anywhere else except in my
Xoffice. Edit the first line before installing such scripts; to try
Xthem out, you can just say "python file.py". (The .py suffix is not
Xnecessary in this case, but makes it possible to debug the modules
Xinteractively by importing them.)
EOF
fi
if test -s 'demo/scripts/findlinksto.py'
then echo '*** I will not over-write existing file demo/scripts/findlinksto.py'
else
echo 'x - demo/scripts/findlinksto.py'
sed 's/^X//' > 'demo/scripts/findlinksto.py' << 'EOF'
X#! /ufs/guido/bin/sgi/python
X
X# findlinksto
X#
X# find symbolic links to a given path
X
Ximport posix, path, sys
X
Xdef visit(pattern, dirname, names):
X if path.islink(dirname):
X names[:] = []
X return
X if path.ismount(dirname):
X print 'descend into', dirname
X n = len(pattern)
X for name in names:
X name = path.cat(dirname, name)
X try:
X linkto = posix.readlink(name)
X if linkto[:n] = pattern:
X print name, '->', linkto
X except posix.error:
X pass
X
Xdef main(pattern, args):
X for dirname in args:
X path.walk(dirname, visit, pattern)
X
Xmain(sys.argv[1], sys.argv[2:])
EOF
chmod +x 'demo/scripts/findlinksto.py'
fi
if test -s 'demo/scripts/suff.py'
then echo '*** I will not over-write existing file demo/scripts/suff.py'
else
echo 'x - demo/scripts/suff.py'
sed 's/^X//' > 'demo/scripts/suff.py' << 'EOF'
X#! /ufs/guido/bin/sgi/python
X
X# suff
X#
X# show different suffixes amongst arguments
X
Ximport sys
X
Xdef main():
X files = sys.argv[1:]
X suffixes = {}
X for file in files:
X suff = getsuffix(file)
X if not suffixes.has_key(suff):
X suffixes[suff] = []
X suffixes[suff].append(file)
X keys = suffixes.keys()
X keys.sort()
X for suff in keys:
X print `suff`, len(suffixes[suff])
X
Xdef getsuffix(file):
X suff = ''
X for i in range(len(file)):
X if file[i] = '.':
X suff = file[i:]
X return suff
X
Xmain()
EOF
chmod +x 'demo/scripts/suff.py'
fi
if test -s 'demo/sgi/README'
then echo '*** I will not over-write existing file demo/sgi/README'
else
echo 'x - demo/sgi/README'
sed 's/^X//' > 'demo/sgi/README' << 'EOF'
XDemonstrations of Python that use various features of the Silicon
XGraphics IRIS machines.
X
Xaudio Demonstrations of the audio capabilities of the 4D/25.
X Require the built-in module 'audio'.
X
Xaudio_stdwin Window-based demonstrations the audio capabilities of
X the 4D/25. Require the built-in modules 'stdwin' and
X 'audio'.
X
Xgl Demonstrations of the Graphics Library (GL).
X Require the built-in module 'gl'.
X
Xgl_panel Demonstrations of the Panel Library by NASA Ames.
X Require the built-in modules 'gl' and 'pnl'.
EOF
fi
if test -s 'demo/sgi/audio/README'
then echo '*** I will not over-write existing file demo/sgi/audio/README'
else
echo 'x - demo/sgi/audio/README'
sed 's/^X//' > 'demo/sgi/audio/README' << 'EOF'
XPrograms that demonstrate the use of the audio device on the SGI 4D/25.
XThese require the built-in module 'audio'.
X
Xplay Read a sound sample from a file and play it through the
X speaker. Options to set volume, sampling rate etc.
EOF
fi
if test -s 'demo/sgi/audio_stdwin/vumeter.py'
then echo '*** I will not over-write existing file demo/sgi/audio_stdwin/vumeter.py'
else
echo 'x - demo/sgi/audio_stdwin/vumeter.py'
sed 's/^X//' > 'demo/sgi/audio_stdwin/vumeter.py' << 'EOF'
X#! /ufs/guido/bin/sgi/python
X
Ximport audio
Ximport stdwin
X
Xfrom VUMeter import VUMeter
Xfrom WindowParent import WindowParent
Ximport MainLoop
X
XNBUFS=20
XBUFSIZE = NBUFS*48
XSCALE=128
X
Xclass MyVUMeter() = VUMeter():
X def init_reactivity(self):
X self.parent.need_mouse(self)
X def mouse_down(self, detail):
X if self.enabled:
X self.stop()
X else:
X self.start()
X def mouse_move(self, detail): pass
X def mouse_up(self, detail): pass
X
Xdef main():
X audio.setrate(3)
X audio.setoutgain(0)
X w = WindowParent().create('VU Meter', (200, 100))
X v = MyVUMeter().define(w)
X v.start()
X w.realize()
X while 1:
X w.dispatch(stdwin.getevent())
X
Xmain()
EOF
chmod +x 'demo/sgi/audio_stdwin/vumeter.py'
fi
if test -s 'demo/sgi/gl/README'
then echo '*** I will not over-write existing file demo/sgi/gl/README'
else
echo 'x - demo/sgi/gl/README'
sed 's/^X//' > 'demo/sgi/gl/README' << 'EOF'
XThese demos run only on SGI machines and require the 'gl' built-in module.
XThe demonstrate the abilities of SGI's GL library as well as the ease of
XGL programming in Python. Most demos require the Z-buffer (aka
X24-bitplane) option.
X
Xbackface Demonstrates the 'backface' GL function.
X
Xkites Show 3 flying kites. Demonstrates the rendering speed
X obtainable by Python programs.
X
Xmclock A colorful clock with more options than you can
X remember. Works on 8-bit machines (but allows more
X colors on 24-bit machines).
X
Xmixing Demonstrates the effect of color mixing: through
X frequent color switching it gives the effect of white
X light.
X
Xnurbs A simple demonstration of the 'nurbs' GL functions.
X
Xzrgb Displays a 3-D Gouraud-shaded figure which can be moved
X around with the mouse.
EOF
fi
if test -s 'demo/sgi/gl_panel/README'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/README'
else
echo 'x - demo/sgi/gl_panel/README'
sed 's/^X//' > 'demo/sgi/gl_panel/README' << 'EOF'
XThis directory contains demos that use the Panel Library by NASA Ames.
XThey only run on SGI machines and require the 'pnl' and 'gl' built-in
Xmodules. Each subdirectory contains one demo.
X
Xapanel A trivial user interface to the audio capabilities of
X the 4D/25 (Personal IRIS). Lets you record a sample and
X play it back at different volumes. Requires the 'audio'
X built-in module.
X
Xflying A large demonstration that can display several
X differently shaped objects through space. Control
X panels let you manipulate light sources, material
X properties and drawing modes.
X
Xnurbs A demo of the capabilities of the GL 'nurbs' functions
X that can display the control points. (It was intended
X to let you move these as well, but there was a problem
X with the mapping of mouse movements in a 3-D world.)
X
Xtwoview A demo of GL's transformation primitives. Two views on
X a scene are given, and the position and orientation of a
X viewer in one of the views can be changed through
X various buttons and dials in a control panel.
EOF
fi
if test -s 'demo/sgi/gl_panel/apanel/apanel.py'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/apanel/apanel.py'
else
echo 'x - demo/sgi/gl_panel/apanel/apanel.py'
sed 's/^X//' > 'demo/sgi/gl_panel/apanel/apanel.py' << 'EOF'
X#! /ufs/guido/bin/sgi/python
X
X# A (too) trivial control panel to record a sound sample and play it back.
X# Requires the audio built-in module.
X# Requires the NASA AMES Panel Library.
X
Ximport sys
X
Ximport gl
Ximport panel
X
Xpanel.block(1)
X
Ximport audio
X
Xdef main():
X gl.foreground()
X gl.noport()
X #gl.prefposition(700, 850, 950, 970)
X wid = gl.winopen('audio demo')
X #
X panels = panel.defpanellist('apanel.s') # XXX
X p = panels[0]
X p.playbackbutton.back = p
X p.recordbutton.back = p
X p.sample = ''
X #
X def quit(a):
X sys.exit(0)
X #
X p.quitbutton.downfunc = quit
X #
X def playback(a):
X p = a.back
X gain = int(255.0*p.outputgain.val)
X a.val = 1.0
X a.fixact()
X panel.drawpanel()
X audio.setoutgain(gain)
X audio.write(p.sample)
X audio.setoutgain(0)
X a.val = 0.0
X a.fixact()
X #
X p.playbackbutton.downfunc = playback
X #
X def record(a):
X p = a.back
X size = int(10.0 * 8192.0 * p.recordsize.val)
X a.val = 1.0
X a.fixact()
X panel.drawpanel()
X audio.setoutgain(0)
X p.sample = audio.read(size)
X a.val = 0.0
X a.fixact()
X #
X p.recordbutton.downfunc = record
X #
X while 1:
X act = panel.dopanel()
X
Xmain()
EOF
chmod +x 'demo/sgi/gl_panel/apanel/apanel.py'
fi
if test -s 'demo/sgi/gl_panel/flying/material.py'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/material.py'
else
echo 'x - demo/sgi/gl_panel/flying/material.py'
sed 's/^X//' > 'demo/sgi/gl_panel/flying/material.py' << 'EOF'
Ximport light
X
Xdef mkmatdict () :
X m = {}
X m['material 1'] = light.m1
X m['material 2'] = light.m2
X m['material 3'] = light.m3
X m['material 4'] = light.m4
X m['material 5'] = light.m5
X m['material 6'] = light.m6
X m['material 7'] = light.m7
X m['material 8'] = light.m8
X m['material 9'] = light.m9
X #
X return m
X
Xmaterdict = mkmatdict ()
X
Xdef mklichtdict () :
X m = {}
X m['light 1'] = light.light1
X m['light 2'] = light.light2
X #
X return m
X
Xlichtdict = mklichtdict ()
EOF
fi
if test -s 'demo/sgi/gl_panel/flying/objdict.py'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/objdict.py'
else
echo 'x - demo/sgi/gl_panel/flying/objdict.py'
sed 's/^X//' > 'demo/sgi/gl_panel/flying/objdict.py' << 'EOF'
X
Xfrom data import *
X
X#
X#the color light-blue
X#
XLightBlue = lightblue
X
X# the 'object' dictionary contains the strings of the menu items
X# that denote the objects
Xobjects = {}
X
X# object dictionary initialization
Xobjects['sphere'] = [ZERO, o1]
Xobjects['cylinder'] = [ZERO, o2]
Xobjects['cube'] = [ONE, o3]
Xobjects['icecream'] = [ZERO, o4]
Xobjects['disk'] = [ZERO, o5]
Xobjects['diamond'] = [ZERO, o6]
X#objects['glass'] = [ZERO]
Xobjects['pyramid'] = [ZERO, o7]
Xobjects['table'] = [ZERO, o8]
X
X# 'putDict' sets the value of entry 'key' of dictionary 'dict'
Xdef putDict(dict, key, val) :
X dict[key][0] = val
X
X#
X# 'getDict' get the contents of entry i of key 'key'
X# of dictionary 'dict'
X#
Xdef getDict(dict, key, i) :
X return dict[key][i]
X
X# the 'options' dictionary contains the strings of the menu items
X# that denote the options
Xoptions = {}
X
X# option dictionary initialization
Xoptions['wire'] = [ZERO]
Xoptions['filled'] = [ONE]
EOF
fi
if test -s 'demo/sgi/gl_panel/twoview/topview.s'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/twoview/topview.s'
else
echo 'x - demo/sgi/gl_panel/twoview/topview.s'
sed 's/^X//' > 'demo/sgi/gl_panel/twoview/topview.s' << 'EOF'
X;;; This file was automatically generated by the panel editor.
X;;; If you read it into gnu emacs, it will automagically format itself.
X
X(panel (prop help creator:user-panel-help)
X(prop user-panel #t)
X(label "Top View Control")
X(x 1020)
X(y 287)
X(al (pnl_hslider (name "xpos")
X(prop help creator:user-act-help)
X(label "X")
X(x 2)
X(y 0.5)
X(w 3.85)
X(h 0.4)
X(val 0.5)
X(downfunc move-then-resize)
X)
X(pnl_vslider (name "zpos")
X(prop help creator:user-act-help)
X(label "Z")
X(x 1.25)
X(y 1.3)
X(w 0.4)
X(h 3.6)
X(val 0.5)
X(downfunc move-then-resize)
X)
X(pnl_dial (name "direction")
X(prop help creator:user-act-help)
X(label "looking direction")
X(x 2.15)
X(y 1.4)
X(w 3.5)
X(h 3.45)
X(val 0.5)
X(downfunc move-then-resize)
X)
X)
X)
X;;; Local Variables:
X;;; mode: scheme
X;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
X;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
X;;; eval: (indent-region (point-min) (point-max) nil)
X;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
X;;; End:
EOF
fi
if test -s 'doc/README'
then echo '*** I will not over-write existing file doc/README'
else
echo 'x - doc/README'
sed 's/^X//' > 'doc/README' << 'EOF'
XThis directory contains the LaTeX source to the Python documentation.
XThe documentation is not all finished, but good enough to get you
Xstarted.
X
XThe following are the important latex source files:
X
X tut.tex A tutorial
X mod.tex The library reference
X
XThey both read the style option file "myformat.sty".
X
XYou can use the Makefile to format, preview and print the documents.
XType "make tut" or "make mod" to preview either document with xdvi.
XType "make print" to print them both (this only works if your print
Xspooler is set up just like mine...), or "make all" to create postscript
Xfiles that you can you can print using your local printing commands.
XType "make clean" to get rid of all the intermediate files produced by
Xthe latex process, and other junk files.
X
XYou can just as well ignore the Makefile; all you really need is:
X latex tut
X latex tut
X dvips tut | lpr
Xand similar for the "mod" document.
EOF
fi
if test -s 'doc/SetClass.py'
then echo '*** I will not over-write existing file doc/SetClass.py'
else
echo 'x - doc/SetClass.py'
sed 's/^X//' > 'doc/SetClass.py' << 'EOF'
Xclass Set():
X def new(self):
X self.elements = []
X return self
X def add(self, e):
X if e not in self.elements:
X self.elements.append(e)
X def remove(self, e):
X if e in self.elements:
X for i in range(len(self.elements)):
X if self.elements[i] = e:
X del self.elements[i]
X break
X def is_element(self, e):
X return e in self.elements
X def size(self):
X return len(self.elements)
EOF
fi
if test -s 'doc/fibo.py'
then echo '*** I will not over-write existing file doc/fibo.py'
else
echo 'x - doc/fibo.py'
sed 's/^X//' > 'doc/fibo.py' << 'EOF'
X# Fibonacci numbers demo
X
Xdef fib(n): # write Fibonacci series up to n
X a, b = 0, 1
X while b <= n:
X print b,
X a, b = b, a+b
X
Xdef fib2(n): # return Fibonacci series up to n
X ret = []
X a, b = 0, 1
X while b <= n:
X ret.append(b)
X a, b = b, a+b
X return ret
EOF
fi
if test -s 'doc/mod.tex'
then echo '*** I will not over-write existing file doc/mod.tex'
else
echo 'x - doc/mod.tex'
sed 's/^X//' > 'doc/mod.tex' << 'EOF'
X% Format this file with latex.
X
X%\documentstyle[garamond,11pt,myformat]{article}
X\documentstyle[11pt,myformat]{article}
X
X% A command to force the text after an item to start on a new line
X\newcommand{\itembreak}{
X \mbox{}\\*[0mm]
X}
X
X% A command to define a function item
X\newcommand{\funcitem}[2]{\item[#1(#2)]}
X
X% A command to define an exception item
X\newcommand{\excitem}[2]{
X\item[#1 = {\tt '#2'}]
X\itembreak
X}
X
X\title{\bf
X Python Library Reference \\
X (DRAFT)
X}
X
X\author{
X Guido van Rossum \\
X Dept. CST, CWI, Kruislaan 413 \\
X 1098 SJ Amsterdam, The Netherlands \\
X E-mail: {\tt [email protected]}
X}
X
X\begin{document}
X
X\pagenumbering{roman}
X
X\maketitle
X
X\begin{abstract}
X
X\noindent
XThis document describes the built-in types, exceptions and functions and
Xthe standard modules that come with the {\Python} system.
XIt assumes basic knowledge about the {\Python} language.
XFor an informal introduction to the language, see the Tutorial document.
XThe Language Reference document (XXX not yet existing)
Xgives a more formal reference to the language.
X
X\end{abstract}
X
X\pagebreak
X
X\tableofcontents
X
X\pagebreak
X
X\pagenumbering{arabic}
X
X\input{mod1.tex}
X\input{mod2.tex}
X\input{mod3.tex}
X
X\end{document}
EOF
fi
if test -s 'doc/myformat.sty'
then echo '*** I will not over-write existing file doc/myformat.sty'
else
echo 'x - doc/myformat.sty'
sed 's/^X//' > 'doc/myformat.sty' << 'EOF'
X% Style parameters and macros used by all documents here
X
X% Page lay-out parameters
X\textwidth = 160mm
X\textheight = 240mm
X\topmargin = -11mm
X\oddsidemargin = 0mm
X\evensidemargin = 0mm
X%\parindent = 0mm
X
X% Frequently used system names
X\newcommand{\Python}{Python} % Sometimes I want this italicized
X\newcommand{\UNIX}{U{\sc nix}}
X
X% Variable used by begin code command
X\newlength{\codewidth}
X
X\newcommand{\bcode}{
X % Calculate the text width for the minipage:
X \setlength{\codewidth}{\linewidth}
X \addtolength{\codewidth}{-\parindent}
X %
X \vspace{3mm}
X \par
X \indent
X \begin{minipage}[t]{\codewidth}
X}
X
X\newcommand{\ecode}{
X \end{minipage}
X \vspace{3mm}
X \par
X \noindent
X}
EOF
fi
if test -s 'doc/pytry'
then echo '*** I will not over-write existing file doc/pytry'
else
echo 'x - doc/pytry'
sed 's/^X//' > 'doc/pytry' << 'EOF'
XTMP=/usr/tmp/pytry$$
Xtrap 'rm -f $TMP; exit 1' 1 2 3 13 14 15
X
Xcat $* >$TMP
X
X(
X cat $TMP
X
X sed '
X s/^>>> //
X s/^>>>$//
X s/^\.\.\. //
X s/^\.\.\.$//
X ' $TMP |
X python
X
X echo '>>> '
X) 2>&1
X
Xrm $TMP
EOF
chmod +x 'doc/pytry'
fi
if test -s 'lib/Histogram.py'
then echo '*** I will not over-write existing file lib/Histogram.py'
else
echo 'x - lib/Histogram.py'
sed 's/^X//' > 'lib/Histogram.py' << 'EOF'
X# Module 'Histogram'
X
Xfrom Buttons import *
X
X# A Histogram displays a histogram of numeric data.
X#
Xclass HistogramAppearance() = LabelAppearance(), Define():
X #
X def define(self, parent):
X Define.define(self, (parent, ''))
X self.ydata = []
X self.scale = (0, 100)
X return self
X #
X def setdata(self, (ydata, scale)):
X self.ydata = ydata
X self.scale = scale # (min, max)
X self.parent.change(self.bounds)
X #
X def drawpict(self, d):
X (left, top), (right, bottom) = self.bounds
X min, max = self.scale
X size = max-min
X width, height = right-left, bottom-top
X ydata = self.ydata
X npoints = len(ydata)
X v1 = top + height # constant
X h1 = left # changed in loop
X for i in range(npoints):
X h0 = h1
X v0 = top + height - (ydata[i]-min)*height/size
X h1 = left + (i+1) * width/npoints
X d.paint((h0, v0), (h1, v1))
X #
X
Xclass Histogram() = NoReactivity(), HistogramAppearance(): pass
EOF
fi
if test -s 'lib/Soundogram.py'
then echo '*** I will not over-write existing file lib/Soundogram.py'
else
echo 'x - lib/Soundogram.py'
sed 's/^X//' > 'lib/Soundogram.py' << 'EOF'
X# Module 'Soundogram'
X
Ximport audio
Xfrom Histogram import Histogram
X
Xclass Soundogram() = Histogram():
X #
X def define(self, (win, chunk)):
X width, height = corner = win.getwinsize()
X bounds = (0, 0), corner
X self.chunk = chunk
X self.step = (len(chunk)-1)/(width/2+1) + 1
X ydata = _make_ydata(chunk, self.step)
X return Histogram.define(self, (win, bounds, ydata, (0, 128)))
X #
X def setchunk(self, chunk):
X self.chunk = chunk
X self.recompute()
X #
X def recompute(self):
X (left, top), (right, bottom) = self.bounds
X width = right - left
X self.step = (len(chunk)-1)/width + 1
X ydata = _make_ydata(chunk, self.step)
X self.setdata(ydata, (0, 128))
X #
X
X
Xdef _make_ydata(chunk, step):
X ydata = []
X for i in range(0, len(chunk), step):
X piece = audio.chr2num(chunk[i:i+step])
X mi, ma = min(piece), max(piece)
X y = max(abs(mi), abs(ma))
X ydata.append(y)
X return ydata
EOF
fi
if test -s 'lib/TestCSplit.py'
then echo '*** I will not over-write existing file lib/TestCSplit.py'
else
echo 'x - lib/TestCSplit.py'
sed 's/^X//' > 'lib/TestCSplit.py' << 'EOF'
X# TestCSplit
X
Ximport stdwin
Xfrom stdwinevents import WE_CLOSE
Xfrom WindowParent import WindowParent
Xfrom Buttons import PushButton
X
Xdef main(n):
X from CSplit import CSplit
X
X the_window = WindowParent().create('TestCSplit', (0, 0))
X the_csplit = CSplit().create(the_window)
X
X for i in range(n):
X the_child = PushButton().define(the_csplit)
X the_child.settext(`(i+n-1)%n+1`)
X
X the_window.realize()
X
X while 1:
X the_event = stdwin.getevent()
X if the_event[0] = WE_CLOSE: break
X the_window.dispatch(the_event)
X the_window.destroy()
X
Xmain(12)
EOF
fi
if test -s 'lib/VUMeter.py'
then echo '*** I will not over-write existing file lib/VUMeter.py'
else
echo 'x - lib/VUMeter.py'
sed 's/^X//' > 'lib/VUMeter.py' << 'EOF'
X# Module 'VUMeter'
X
Ximport audio
Xfrom StripChart import StripChart
X
XK = 1024
XRates = [0, 32*K, 16*K, 8*K]
X
Xclass VUMeter() = StripChart():
X #
X # Override define() and timer() methods
X #
X def define(self, parent):
X self = StripChart.define(self, (parent, 128))
X self.parent.need_timer(self)
X self.sampling = 0
X self.rate = 3
X self.enable(0)
X return self
X #
X def timer(self):
X if self.sampling:
X chunk = audio.wait_recording()
X self.sampling = 0
X nums = audio.chr2num(chunk)
X ampl = max(abs(min(nums)), abs(max(nums)))
X self.append(ampl)
X if self.enabled and not self.sampling:
X audio.setrate(self.rate)
X size = Rates[self.rate]/10
X size = size/48*48
X audio.start_recording(size)
X self.sampling = 1
X if self.sampling:
X self.parent.settimer(1)
X #
X # New methods: start() and stop()
X #
X def stop(self):
X if self.sampling:
X chunk = audio.stop_recording()
X self.sampling = 0
X self.enable(0)
X #
X def start(self):
X self.enable(1)
X self.timer()
EOF
fi
if test -s 'lib/anywin.py'
then echo '*** I will not over-write existing file lib/anywin.py'
else
echo 'x - lib/anywin.py'
sed 's/^X//' > 'lib/anywin.py' << 'EOF'
X# Module 'anywin'
X# Open a file or directory in a window
X
Ximport dirwin
Ximport filewin
Ximport path
X
Xdef open(name):
X print 'opening', name, '...'
X if path.isdir(name):
X w = dirwin.open(name)
X else:
X w = filewin.open(name)
X return w
EOF
fi
if test -s 'lib/dircache.py'
then echo '*** I will not over-write existing file lib/dircache.py'
else
echo 'x - lib/dircache.py'
sed 's/^X//' > 'lib/dircache.py' << 'EOF'
X# Module 'dircache'
X#
X# Return a sorted list of the files in a POSIX directory, using a cache
X# to avoid reading the directory more often than necessary.
X# Also contains a subroutine to append slashes to directories.
X
Ximport posix
Ximport path
X
Xcache = {}
X
Xdef listdir(path): # List directory contents, using cache
X try:
X cached_mtime, list = cache[path]
X del cache[path]
X except RuntimeError:
X cached_mtime, list = -1, []
X try:
X mtime = posix.stat(path)[8]
X except posix.error:
X return []
X if mtime <> cached_mtime:
X try:
X list = posix.listdir(path)
X except posix.error:
X return []
X list.sort()
X cache[path] = mtime, list
X return list
X
Xopendir = listdir # XXX backward compatibility
X
Xdef annotate(head, list): # Add '/' suffixes to directories
X for i in range(len(list)):
X if path.isdir(path.cat(head, list[i])):
X list[i] = list[i] + '/'
EOF
fi
if test -s 'lib/dirwin.py'
then echo '*** I will not over-write existing file lib/dirwin.py'
else
echo 'x - lib/dirwin.py'
sed 's/^X//' > 'lib/dirwin.py' << 'EOF'
X# Module 'dirwin'
X
X# Directory windows, a subclass of listwin
X
Ximport gwin
Ximport listwin
Ximport anywin
Ximport path
Ximport dircache
X
Xdef action(w, string, i, detail):
X (h, v), clicks, button, mask = detail
X if clicks = 2:
X name = path.cat(w.name, string)
X try:
X w2 = anywin.open(name)
X w2.parent = w
X except posix.error, why:
X stdwin.message('Can\'t open ' + name + ': ' + why[1])
X
Xdef open(name):
X name = path.cat(name, '')
X list = dircache.opendir(name)[:]
X list.sort()
X dircache.annotate(name, list)
X w = listwin.open(name, list)
X w.name = name
X w.action = action
X return w
EOF
fi
if test -s 'lib/fact.py'
then echo '*** I will not over-write existing file lib/fact.py'
else
echo 'x - lib/fact.py'
sed 's/^X//' > 'lib/fact.py' << 'EOF'
X# Factorize numbers -- slow, could use a table of all primes <= 2*16
X
Ximport sys
Ximport math
X
Xerror = 'fact.error' # exception
X
Xdef fact(n):
X if n < 1: raise error # fact() argument should be >= 1
X if n = 1: return [] # special case
X res = []
X _fact(n, 2, res)
X return res
X
Xdef _fact(n, lowest, res):
X highest = int(math.sqrt(float(n+1)))
X for i in range(lowest, highest+1):
X if n%i = 0:
X res.append(i)
X _fact(n/i, i, res)
X break
X else:
X res.append(n)
X
Xdef main():
X if len(sys.argv) > 1:
X for arg in sys.argv[1:]:
X n = eval(arg)
X print n, fact(n)
X else:
X try:
X while 1:
X print fact(input())
X except EOFError:
X pass
X
Xmain()
EOF
fi
if test -s 'lib/filewin.py'
then echo '*** I will not over-write existing file lib/filewin.py'
else
echo 'x - lib/filewin.py'
sed 's/^X//' > 'lib/filewin.py' << 'EOF'
X# Module 'filewin'
X# File windows, a subclass of textwin (which is a subclass of gwin)
X
Ximport textwin
Xfrom util import readfile
X
X
X# FILE WINDOW
X
Xdef open_readonly(fn): # Open a file window
X w = textwin.open_readonly(fn, readfile(fn))
X w.fn = fn
X return w
X
Xdef open(fn): # Open a file window
X w = textwin.open(fn, readfile(fn))
X w.fn = fn
X return w
EOF
fi
if test -s 'lib/fnmatch.py'
then echo '*** I will not over-write existing file lib/fnmatch.py'
else
echo 'x - lib/fnmatch.py'
sed 's/^X//' > 'lib/fnmatch.py' << 'EOF'
X# module 'fnmatch' -- filename matching with shell patterns
X
X# XXX [] patterns are not supported (but recognized)
X
Xdef fnmatch(name, pat):
X if '*' in pat or '?' in pat or '[' in pat:
X return fnmatch1(name, pat)
X return name = pat
X
Xdef fnmatch1(name, pat):
X for i in range(len(pat)):
X c = pat[i]
X if c = '*':
X restpat = pat[i+1:]
X if '*' in restpat or '?' in restpat or '[' in restpat:
X for i in range(i, len(name)):
X if fnmatch1(name[i:], restpat):
X return 1
X return 0
X else:
X return name[len(name)-len(restpat):] = restpat
X elif c = '?':
X if len(name) <= i : return 0
X elif c = '[':
X return 0 # XXX
X else:
X if name[i:i+1] <> c:
X return 0
X return 1
X
Xdef fnmatchlist(names, pat):
X res = []
X for name in names:
X if fnmatch(name, pat): res.append(name)
X return res
EOF
fi
if test -s 'lib/glob.py'
then echo '*** I will not over-write existing file lib/glob.py'
else
echo 'x - lib/glob.py'
sed 's/^X//' > 'lib/glob.py' << 'EOF'
X# Module 'glob' -- filename globbing.
X
Ximport posix
Ximport path
Ximport fnmatch
X
Xdef glob(pathname):
X if not has_magic(pathname): return [pathname]
X dirname, basename = path.split(pathname)
X if dirname[-1:] = '/' and dirname <> '/':
X dirname = dirname[:-1]
X if has_magic(dirname):
X list = glob(dirname)
X else:
X list = [dirname]
X if not has_magic(basename):
X result = []
X for dirname in list:
X if basename or path.isdir(dirname):
X name = path.cat(dirname, basename)
X if path.exists(name):
X result.append(name)
X else:
X result = []
X for dirname in list:
X sublist = glob1(dirname, basename)
X for name in sublist:
X result.append(path.cat(dirname, name))
X return result
X
Xdef glob1(dirname, pattern):
X if not dirname: dirname = '.'
X try:
X names = posix.listdir(dirname)
X except posix.error:
X return []
X result = []
X for name in names:
X if name[0] <> '.' or pattern[0] = '.':
X if fnmatch.fnmatch(name, pattern): result.append(name)
X return result
X
Xdef has_magic(s):
X return '*' in s or '?' in s or '[' in s
EOF
fi
if test -s 'lib/grep.py'
then echo '*** I will not over-write existing file lib/grep.py'
else
echo 'x - lib/grep.py'
sed 's/^X//' > 'lib/grep.py' << 'EOF'
X# 'grep'
X
Ximport regexp
Ximport string
X
Xdef grep(expr, filename):
X prog = regexp.compile(expr)
X fp = open(filename, 'r')
X lineno = 0
X while 1:
X line = fp.readline()
X if not line: break
X lineno = lineno + 1
X res = prog.exec(line)
X if res:
X #print res
X start, end = res[0]
X if line[-1:] = '\n': line = line[:-1]
X prefix = string.rjust(`lineno`, 3) + ': '
X print prefix + line
X if 0:
X line = line[:start]
X if '\t' not in line:
X prefix = ' ' * (len(prefix) + start)
X else:
X prefix = ' ' * len(prefix)
X for c in line:
X if c <> '\t': c = ' '
X prefix = prefix + c
X if start = end: prefix = prefix + '\\'
X else: prefix = prefix + '^'*(end-start)
X print prefix
EOF
fi
if test -s 'lib/maccache.py'
then echo '*** I will not over-write existing file lib/maccache.py'
else
echo 'x - lib/maccache.py'
sed 's/^X//' > 'lib/maccache.py' << 'EOF'
X# Module 'maccache'
X#
X# Maintain a cache of listdir(), isdir(), isfile() or exists() outcomes.
X
Ximport mac
Ximport macpath
X
X
X# The cache.
X# Keys are absolute pathnames;
X# values are 0 (nothing), 1 (file) or [...] (dir).
X#
Xcache = {}
X
X
X# Current working directory.
X#
Xcwd = mac.getcwd()
X
X
X# Constants.
X#
XNONE = 0
XFILE = 1
XLISTTYPE = type([])
X
Xdef _stat(name):
X name = macpath.cat(cwd, name)
X if cache.has_key(name):
X return cache[name]
X if macpath.isfile(name):
X cache[name] = FILE
X return FILE
X try:
X list = mac.listdir(name)
X except:
X cache[name] = NONE
X return NONE
X cache[name] = list
X if name[-1:] = ':': cache[name[:-1]] = list
X else: cache[name+':'] = list
X return list
X
Xdef isdir(name):
X st = _stat(name)
X return type(st) = LISTTYPE
X
Xdef isfile(name):
X st = _stat(name)
X return st = FILE
X
Xdef exists(name):
X st = _stat(name)
X return st <> NONE
X
Xdef listdir(name):
X st = _stat(name)
X if type(st) = LISTTYPE:
X return st
X else:
X raise RuntimeError, 'list non-directory'
EOF
fi
if test -s 'lib/macglob.py'
then echo '*** I will not over-write existing file lib/macglob.py'
else
echo 'x - lib/macglob.py'
sed 's/^X//' > 'lib/macglob.py' << 'EOF'
X# Module 'macglob' -- version of 'glob' for the Macintosh.
X
X# XXX At least one bug is left: a pattern like '*:' is treated
X# XXX as a relative pathname (and returns as if it was ':*:').
X
Ximport mac
Ximport macpath
Ximport fnmatch
X
Xdef glob(pathname):
X if not has_magic(pathname): return [pathname]
X dirname, basename = macpath.split(pathname)
X if has_magic(dirname):
X if dirname[-1:] = ':': dirname = dirname[:-1]
X list = glob(dirname)
X else:
X list = [dirname]
X if not has_magic(basename):
X result = []
X for dirname in list:
X if basename or macpath.isdir(dirname):
X name = macpath.cat(dirname, basename)
X if macpath.exists(name):
X result.append(name)
X else:
X result = []
X for dirname in list:
X sublist = glob1(dirname, basename)
X for name in sublist:
X result.append(macpath.cat(dirname, name))
X return result
X
Xdef glob1(dirname, pattern):
X if not dirname: dirname = ':'
X try:
X names = mac.listdir(dirname)
X except mac.error:
X return []
X result = []
X for name in names:
X if name[0] <> '.' or pattern[0] = '.':
X if fnmatch.fnmatch(name, pattern): result.append(name)
X return result
X
Xdef has_magic(s):
X return '*' in s or '?' in s or '[' in s
EOF
fi
if test -s 'lib/minmax.py'
then echo '*** I will not over-write existing file lib/minmax.py'
else
echo 'x - lib/minmax.py'
sed 's/^X//' > 'lib/minmax.py' << 'EOF'
X# Module 'minmax'
X# These are now built in functions.
X# For compatibility, we export the builtins
X
Xmin = min
Xmax = max
EOF
fi
if test -s 'lib/packmail.py'
then echo '*** I will not over-write existing file lib/packmail.py'
else
echo 'x - lib/packmail.py'
sed 's/^X//' > 'lib/packmail.py' << 'EOF'
X# Module 'packmail' -- create a shell script out of some files.
X
Ximport mac
Ximport macpath
Xfrom stat import ST_MTIME
X
X# Pack one file
Xdef pack(outfp, file, name):
X fp = open(file, 'r')
X outfp.write('sed "s/^X//" >' + name + ' <<"!"\n')
X while 1:
X line = fp.readline()
X if not line: break
X if line[-1:] <> '\n':
X line = line + '\n'
X outfp.write('X' + line)
X outfp.write('!\n')
X
X# Pack some files from a directory
Xdef packsome(outfp, dirname, names):
X for name in names:
X print name
X file = macpath.cat(dirname, name)
X pack(outfp, file, name)
X
X# Pack all files from a directory
Xdef packall(outfp, dirname):
X names = mac.listdir(dirname)
X names.sort()
X packsome(outfp, dirname, names)
X
X# Pack all files from a directory that are not older than a give one
Xdef packnotolder(outfp, dirname, oldest):
X names = mac.listdir(dirname)
X oldest = macpath.cat(dirname, oldest)
X st = mac.stat(oldest)
X mtime = st[ST_MTIME]
X todo = []
X for name in names:
X print name, '...',
X st = mac.stat(macpath.cat(dirname, name))
X if st[ST_MTIME] >= mtime:
X print 'Yes.'
X todo.append(name)
X else:
X print 'No.'
X todo.sort()
X packsome(outfp, dirname, todo)
EOF
fi
if test -s 'lib/rand.py'
then echo '*** I will not over-write existing file lib/rand.py'
else
echo 'x - lib/rand.py'
sed 's/^X//' > 'lib/rand.py' << 'EOF'
X# Module 'rand'
X
Ximport whrandom
X
Xdef srand(seed):
X whrandom.seed(seed%256, seed/256%256, seed/65536%256)
X
Xdef rand():
X return int(whrandom.random() * 32768.0) % 32768
X
Xdef choice(seq):
X return seq[rand() % len(seq)]
EOF
fi
if test -s 'lib/stat.py'
then echo '*** I will not over-write existing file lib/stat.py'
else
echo 'x - lib/stat.py'
sed 's/^X//' > 'lib/stat.py' << 'EOF'
X# Module 'stat'
X
X# Defines constants and functions for interpreting stat/lstat struct
X# as returned by posix.stat() and posix.lstat() (if it exists).
X
X# XXX This module may have to be adapted for UNIXoid systems whose
X# <sys/stat.h> deviates from AT&T or BSD UNIX; their S_IF* constants
X# may differ.
X
X# Suggested usage: from stat import *
X
X# Tuple indices for stat struct members
X
XST_MODE = 0
XST_INO = 1
XST_DEV = 2
XST_NLINK = 3
XST_UID = 4
XST_GID = 5
XST_SIZE = 6
XST_ATIME = 7
XST_MTIME = 8
XST_CTIME = 9
X
Xdef S_IMODE(mode):
X return mode%4096
Xdef S_IFMT(mode):
X return mode - mode%4096
X
XS_IFDIR = 0040000
XS_IFCHR = 0020000
XS_IFBLK = 0060000
XS_IFREG = 0100000
XS_IFIFO = 0010000
XS_IFLNK = 0120000
XS_IFSOCK = 0140000
X
Xdef S_ISDIR(mode):
X return S_IFMT(mode) = S_IFDIR
X
Xdef S_ISCHR(mode):
X return S_IFMT(mode) = S_IFCHR
X
Xdef S_ISBLK(mode):
X return S_IFMT(mode) = S_IFBLK
X
Xdef S_ISREG(mode):
X return S_IFMT(mode) = S_IFREG
X
Xdef S_ISFIFO(mode):
X return S_IFMT(mode) = S_IFIFO
X
Xdef S_ISLNK(mode):
X return S_IFMT(mode) = S_IFLNK
X
Xdef S_ISSOCK(mode):
X return S_IFMT(mode) = S_IFSOCK
EOF
fi
if test -s 'lib/stdwinsupport.py'
then echo '*** I will not over-write existing file lib/stdwinsupport.py'
else
echo 'x - lib/stdwinsupport.py'
sed 's/^X//' > 'lib/stdwinsupport.py' << 'EOF'
X# Module 'stdwinsupport'
X
Ximport stdwin
X
Xeventnames = ['null', 'activate', 'char', 'command']
Xeventnames = eventnames + ['mouse_down', 'mouse_move', 'mouse_up', 'menu']
Xeventnames = eventnames + ['size', 'move', 'draw', 'timer', 'deactivate']
X
Xwe_null = 0
Xwe_activate = 1
Xwe_char = 2
Xwe_command = 3
Xwe_mouse_down = 4
Xwe_mouse_move = 5
Xwe_mouse_up = 6
Xwe_menu = 7
Xwe_size = 8
Xwe_move = 9
Xwe_draw = 10
Xwe_timer = 11
Xwe_deactivate = 12
X
Xcommandnames = ['?', 'close', 'left', 'right', 'up', 'down', 'cancel']
Xcommandnames = commandnames + ['backspace', 'tab', 'return']
X
Xwc_close = 1
Xwc_left = 2
Xwc_right = 3
Xwc_up = 4
Xwc_down = 5
Xwc_cancel = 6 # not reported -- turned into KeyboardInterrupt
Xwc_backspace = 7
Xwc_tab = 8
Xwc_return = 9
EOF
fi
if test -s 'lib/util.py'
then echo '*** I will not over-write existing file lib/util.py'
else
echo 'x - lib/util.py'
sed 's/^X//' > 'lib/util.py' << 'EOF'
X# Module 'util' -- some useful functions that don't fit elsewhere
X
X
X# Remove an item from a list.
X# No complaints if it isn't in the list at all.
X# If it occurs more than once, remove the first occurrence.
X#
Xdef remove(item, list):
X for i in range(len(list)):
X if list[i] = item:
X del list[i]
X break
X
X
X# Return a string containing a file's contents.
X#
Xdef readfile(fn):
X return readopenfile(open(fn, 'r'))
X
X
X# Read an open file until EOF.
X#
Xdef readopenfile(fp):
X BUFSIZE = 512*8
X data = ''
X while 1:
X buf = fp.read(BUFSIZE)
X if not buf: break
X data = data + buf
X return data
EOF
fi
if test -s 'src/To.do'
then echo '*** I will not over-write existing file src/To.do'
else
echo 'x - src/To.do'
sed 's/^X//' > 'src/To.do' << 'EOF'
X- return better errors for file objects (also check read/write allowed, etc.)
X
X- introduce more specific exceptions (e.g., zero divide, index failure, ...)
X
X- why do reads from stdin fail when I suspend the process?
X
X- introduce macros to set/inspect errno for syscalls, to support things
X like getoserr()
X
X- fix interrupt handling (interruptable system calls should call
X intrcheck() to clear the interrupt status)
EOF
fi
if test -s 'src/assert.h'
then echo '*** I will not over-write existing file src/assert.h'
else
echo 'x - src/assert.h'
sed 's/^X//' > 'src/assert.h' << 'EOF'
X/***********************************************************
XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
XNetherlands.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of Stichting Mathematisch
XCentrum or CWI not be used in advertising or publicity pertaining to
Xdistribution of the software without specific, written prior permission.
X
XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X******************************************************************/
X
X#define assert(e) { if (!(e)) { printf("Assertion failed\n"); abort(); } }
EOF
fi
if test -s 'src/bltinmodule.h'
then echo '*** I will not over-write existing file src/bltinmodule.h'
else
echo 'x - src/bltinmodule.h'
sed 's/^X//' > 'src/bltinmodule.h' << 'EOF'
X/***********************************************************
XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
XNetherlands.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of Stichting Mathematisch
XCentrum or CWI not be used in advertising or publicity pertaining to
Xdistribution of the software without specific, written prior permission.
X
XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X******************************************************************/
X
X/* Built-in module interface */
X
Xextern object *getbuiltin PROTO((char *));
EOF
fi
if test -s 'src/fgetsintr.h'
then echo '*** I will not over-write existing file src/fgetsintr.h'
else
echo 'x - src/fgetsintr.h'
sed 's/^X//' > 'src/fgetsintr.h' << 'EOF'
X/***********************************************************
XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
XNetherlands.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of Stichting Mathematisch
XCentrum or CWI not be used in advertising or publicity pertaining to
Xdistribution of the software without specific, written prior permission.
X
XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X******************************************************************/
X
Xextern int fgets_intr PROTO((char *, int, FILE *));
EOF
fi
if test -s 'src/rltokenizer.c'
then echo '*** I will not over-write existing file src/rltokenizer.c'
else
echo 'x - src/rltokenizer.c'
sed 's/^X//' > 'src/rltokenizer.c' << 'EOF'
X/***********************************************************
XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
XNetherlands.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of Stichting Mathematisch
XCentrum or CWI not be used in advertising or publicity pertaining to
Xdistribution of the software without specific, written prior permission.
X
XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X******************************************************************/
X
X#define USE_READLINE
X#include "tokenizer.c"
EOF
fi
if test -s 'src/stubcode.h'
then echo '*** I will not over-write existing file src/stubcode.h'
else
echo 'x - src/stubcode.h'
sed 's/^X//' > 'src/stubcode.h' << 'EOF'
X/***********************************************************
XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
XNetherlands.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of Stichting Mathematisch
XCentrum or CWI not be used in advertising or publicity pertaining to
Xdistribution of the software without specific, written prior permission.
X
XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X******************************************************************/
X
X
X#define CAP 0
X#define STUBC 1
X#define NAME 2
EOF
fi
echo 'Part 21 out of 21 of pack.out complete.'
exit 0
|