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
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
|
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 04/21
Message-ID: <[email protected]>
Date: 19 Feb 91 17:41:26 GMT
Sender: [email protected]
Organization: CWI, Amsterdam
Lines: 2755
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 04 out of 21:'
if test -s 'demo/sgi/gl_panel/flying/freeze.s'
then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/freeze.s'
else
echo 'x - demo/sgi/gl_panel/flying/freeze.s'
sed 's/^X//' > 'demo/sgi/gl_panel/flying/freeze.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 "frames per second")
X(al (pnl_toggle_button (name "freeze")
X(prop help creator:user-act-help)
X(label "freeze")
X(x 0.25)
X(y 4.3)
X(w 1.45)
X(h 0.6)
X(labeltype 16)
X(downfunc move-then-resize)
X)
X(pnl_scale_chart (name "mystrip")
X(prop help creator:user-act-help)
X(x 0.25)
X(y 0.25)
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 'src/cstubs'
then echo '*** I will not over-write existing file src/cstubs'
else
echo 'x - src/cstubs'
sed 's/^X//' > 'src/cstubs' << 'EOF'
X/*
XInput used to generate the Python module "glmodule.c".
XThe stub generator is a Python script called "cgen".
X
XEach definition must be contained on one line:
X
X<returntype> <name> <type> <arg> <type> <arg>
X
X<returntype> can be: void, short, long (XXX maybe others?)
X
X<type> can be: char, string, short, float, long, or double
X string indicates a null terminated string;
X if <type> is char and <arg> begins with a *, the * is stripped
X and <type> is changed into string
X
X<arg> has the form <mode> or <mode>[<subscript>]
X where <mode> can be
X s: arg is sent
X r: arg is received (arg is a pointer)
X and <subscript> can be (N and I are numbers):
X N
X argI
X retval
X N*argI
X N*retval
X*/
X
X#include <gl.h>
X#include <device.h>
X
X#include "allobjects.h"
X#include "import.h"
X#include "modsupport.h"
X#include "cgensupport.h"
X
X/*
XSome stubs are too complicated for the stub generator.
XWe can include manually written versions of them here.
XA line starting with '%' gives the name of the function so the stub
Xgenerator can include it in the table of functions.
X*/
X
X/*
Xvarray -- an array of v.. calls.
XThe argument is an array (maybe list or tuple) of points.
XEach point must be a tuple or list of coordinates (x, y, z).
XThe points may be 2- or 3-dimensional but must all have the
Xsame dimension. Float and int values may be mixed however.
XThe points are always converted to 3D double precision points
Xby assuming z=0.0 if necessary (as indicated in the man page),
Xand for each point v3d() is called.
X*/
X
X% varray
X
Xstatic object *
Xgl_varray(self, args)
X object *self;
X object *args;
X{
X object *v, *w;
X int i, n, width;
X double vec[3];
X object * (*getitem) FPROTO((object *, int));
X
X if (!getiobjectarg(args, 1, 0, &v))
X return NULL;
X
X if (is_listobject(v)) {
X n = getlistsize(v);
X getitem = getlistitem;
X }
X else if (is_tupleobject(v)) {
X n = gettuplesize(v);
X getitem = gettupleitem;
X }
X else {
X err_badarg();
X return NULL;
X }
X
X if (n == 0) {
X INCREF(None);
X return None;
X }
X if (n > 0)
X w = (*getitem)(v, 0);
X
X width = 0;
X if (w == NULL) {
X }
X else if (is_listobject(w)) {
X width = getlistsize(w);
X }
X else if (is_tupleobject(w)) {
X width = gettuplesize(w);
X }
X
X switch (width) {
X case 2:
X vec[2] = 0.0;
X /* Fall through */
X case 3:
X break;
X default:
X err_badarg();
X return NULL;
X }
X
X for (i = 0; i < n; i++) {
X w = (*getitem)(v, i);
X if (!getidoublearray(w, 1, 0, width, vec))
X return NULL;
X v3d(vec);
X }
X
X INCREF(None);
X return None;
X}
X
X/*
Xvnarray, nvarray -- an array of n3f and v3f calls.
XThe argument is an array (list or tuple) of pairs of points and normals.
XEach pair is a tuple (NOT a list) of a point and a normal for that point.
XEach point or normal must be a tuple (NOT a list) of coordinates (x, y, z).
XThree coordinates must be given. Float and int values may be mixed.
XFor each pair, n3f() is called for the normal, and then v3f() is called
Xfor the vector.
X
Xvnarray and nvarray differ only in the order of the vector and normal in
Xthe pair: vnarray expects (v, n) while nvarray expects (n, v).
X*/
X
Xstatic object *gen_nvarray(); /* Forward */
X
X% nvarray
X
Xstatic object *
Xgl_nvarray(self, args)
X object *self;
X object *args;
X{
X return gen_nvarray(args, 0);
X}
X
X% vnarray
X
Xstatic object *
Xgl_vnarray(self, args)
X object *self;
X object *args;
X{
X return gen_nvarray(args, 1);
X}
X
X/* Generic, internal version of {nv,nv}array: inorm indicates the
X argument order, 0: normal first, 1: vector first. */
X
Xstatic object *
Xgen_nvarray(args, inorm)
X object *args;
X int inorm;
X{
X object *v, *w, *wnorm, *wvec;
X int i, n;
X float norm[3], vec[3];
X object * (*getitem) FPROTO((object *, int));
X
X if (!getiobjectarg(args, 1, 0, &v))
X return NULL;
X
X if (is_listobject(v)) {
X n = getlistsize(v);
X getitem = getlistitem;
X }
X else if (is_tupleobject(v)) {
X n = gettuplesize(v);
X getitem = gettupleitem;
X }
X else {
X err_badarg();
X return NULL;
X }
X
X for (i = 0; i < n; i++) {
X w = (*getitem)(v, i);
X if (!is_tupleobject(w) || gettuplesize(w) != 2) {
X err_badarg();
X return NULL;
X }
X wnorm = gettupleitem(w, inorm);
X wvec = gettupleitem(w, 1 - inorm);
X if (!getifloatarray(wnorm, 1, 0, 3, norm) ||
X !getifloatarray(wvec, 1, 0, 3, vec))
X return NULL;
X n3f(norm);
X v3f(vec);
X }
X
X INCREF(None);
X return None;
X}
X
X/* nurbssurface(s_knots[], t_knots[], ctl[][], s_order, t_order, type).
X The dimensions of ctl[] are computed as follows:
X [len(s_knots) - s_order], [len(t_knots) - t_order]
X*/
X
X% nurbssurface
X
Xstatic object *
Xgl_nurbssurface(self, args)
X object *self;
X object *args;
X{
X long arg1 ;
X double * arg2 ;
X long arg3 ;
X double * arg4 ;
X double *arg5 ;
X long arg6 ;
X long arg7 ;
X long arg8 ;
X long ncoords;
X long s_byte_stride, t_byte_stride;
X long s_nctl, t_nctl;
X long s, t;
X object *v, *w, *pt;
X double *pnext;
X if (!getilongarraysize(args, 6, 0, &arg1))
X return NULL;
X if ((arg2 = NEW(double, arg1 )) == NULL) {
X return err_nomem();
X }
X if (!getidoublearray(args, 6, 0, arg1 , arg2))
X return NULL;
X if (!getilongarraysize(args, 6, 1, &arg3))
X return NULL;
X if ((arg4 = NEW(double, arg3 )) == NULL) {
X return err_nomem();
X }
X if (!getidoublearray(args, 6, 1, arg3 , arg4))
X return NULL;
X if (!getilongarg(args, 6, 3, &arg6))
X return NULL;
X if (!getilongarg(args, 6, 4, &arg7))
X return NULL;
X if (!getilongarg(args, 6, 5, &arg8))
X return NULL;
X if (arg8 == N_XYZ)
X ncoords = 3;
X else if (arg8 == N_XYZW)
X ncoords = 4;
X else {
X err_badarg();
X return NULL;
X }
X s_nctl = arg1 - arg6;
X t_nctl = arg3 - arg7;
X if (!getiobjectarg(args, 6, 2, &v))
X return NULL;
X if (!is_listobject(v) || getlistsize(v) != s_nctl) {
X err_badarg();
X return NULL;
X }
X if ((arg5 = NEW(double, s_nctl*t_nctl*ncoords )) == NULL) {
X return err_nomem();
X }
X pnext = arg5;
X for (s = 0; s < s_nctl; s++) {
X w = getlistitem(v, s);
X if (w == NULL || !is_listobject(w) ||
X getlistsize(w) != t_nctl) {
X err_badarg();
X return NULL;
X }
X for (t = 0; t < t_nctl; t++) {
X pt = getlistitem(w, t);
X if (!getidoublearray(pt, 1, 0, ncoords, pnext))
X return NULL;
X pnext += ncoords;
X }
X }
X s_byte_stride = sizeof(double) * ncoords;
X t_byte_stride = s_byte_stride * s_nctl;
X nurbssurface( arg1 , arg2 , arg3 , arg4 ,
X s_byte_stride , t_byte_stride , arg5 , arg6 , arg7 , arg8 );
X DEL(arg2);
X DEL(arg4);
X DEL(arg5);
X INCREF(None);
X return None;
X}
X
X/* nurbscurve(knots, ctlpoints, order, type).
X The length of ctlpoints is len(knots)-order. */
X
X%nurbscurve
X
Xstatic object *
Xgl_nurbscurve(self, args)
X object *self;
X object *args;
X{
X long arg1 ;
X double * arg2 ;
X long arg3 ;
X double * arg4 ;
X long arg5 ;
X long arg6 ;
X int ncoords, npoints;
X int i;
X object *v;
X double *pnext;
X if (!getilongarraysize(args, 4, 0, &arg1))
X return NULL;
X if ((arg2 = NEW(double, arg1 )) == NULL) {
X return err_nomem();
X }
X if (!getidoublearray(args, 4, 0, arg1 , arg2))
X return NULL;
X if (!getilongarg(args, 4, 2, &arg5))
X return NULL;
X if (!getilongarg(args, 4, 3, &arg6))
X return NULL;
X if (arg6 == N_ST)
X ncoords = 2;
X else if (arg6 == N_STW)
X ncoords = 3;
X else {
X err_badarg();
X return NULL;
X }
X npoints = arg1 - arg5;
X if (!getiobjectarg(args, 4, 1, &v))
X return NULL;
X if (!is_listobject(v) || getlistsize(v) != npoints) {
X err_badarg();
X return NULL;
X }
X if ((arg4 = NEW(double, npoints*ncoords )) == NULL) {
X return err_nomem();
X }
X pnext = arg4;
X for (i = 0; i < npoints; i++) {
X if (!getidoublearray(getlistitem(v, i), 1, 0, ncoords, pnext))
X return NULL;
X pnext += ncoords;
X }
X arg3 = (sizeof(double)) * ncoords;
X nurbscurve( arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
X DEL(arg2);
X DEL(arg4);
X INCREF(None);
X return None;
X}
X
X/* pwlcurve(points, type).
X Points is a list of points. Type must be N_ST. */
X
X%pwlcurve
X
Xstatic object *
Xgl_pwlcurve(self, args)
X object *self;
X object *args;
X{
X object *v;
X long type;
X double *data, *pnext;
X long npoints, ncoords;
X int i;
X if (!getiobjectarg(args, 2, 0, &v))
X return NULL;
X if (!getilongarg(args, 2, 1, &type))
X return NULL;
X if (!is_listobject(v)) {
X err_badarg();
X return NULL;
X }
X npoints = getlistsize(v);
X if (type == N_ST)
X ncoords = 2;
X else {
X err_badarg();
X return NULL;
X }
X if ((data = NEW(double, npoints*ncoords)) == NULL) {
X return err_nomem();
X }
X pnext = data;
X for (i = 0; i < npoints; i++) {
X if (!getidoublearray(getlistitem(v, i), 1, 0, ncoords, pnext))
X return NULL;
X pnext += ncoords;
X }
X pwlcurve(npoints, data, sizeof(double)*ncoords, type);
X DEL(data);
X INCREF(None);
X return None;
X}
X
X
X/* Picking and Selecting */
X
Xstatic short *pickbuffer = NULL;
Xstatic long pickbuffersize;
X
Xstatic object *
Xpick_select(args, func)
X object *args;
X void (*func)();
X{
X if (!getilongarg(args, 1, 0, &pickbuffersize))
X return NULL;
X if (pickbuffer != NULL) {
X err_setstr(RuntimeError,
X "pick/gselect: already picking/selecting");
X return NULL;
X }
X if ((pickbuffer = NEW(short, pickbuffersize)) == NULL) {
X return err_nomem();
X }
X (*func)(pickbuffer, pickbuffersize);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xendpick_select(args, func)
X object *args;
X long (*func)();
X{
X object *v, *w;
X int i, nhits, n;
X if (!getnoarg(args))
X return NULL;
X if (pickbuffer == NULL) {
X err_setstr(RuntimeError,
X "endpick/endselect: not in pick/select mode");
X return NULL;
X }
X nhits = (*func)(pickbuffer);
X if (nhits < 0) {
X nhits = -nhits; /* How to report buffer overflow otherwise? */
X }
X /* Scan the buffer to see how many integers */
X n = 0;
X for (; nhits > 0; nhits--) {
X n += 1 + pickbuffer[n];
X }
X v = newlistobject(n);
X if (v == NULL)
X return NULL;
X /* XXX Could do it nicer and interpret the data structure here,
X returning a list of lists. But this can be done in Python... */
X for (i = 0; i < n; i++) {
X w = newintobject((long)pickbuffer[i]);
X if (w == NULL) {
X DECREF(v);
X return NULL;
X }
X setlistitem(v, i, w);
X }
X DEL(pickbuffer);
X pickbuffer = NULL;
X return v;
X}
X
Xextern void pick(), gselect();
Xextern long endpick(), endselect();
X
X%pick
Xstatic object *gl_pick(self, args) object *self, *args; {
X return pick_select(args, pick);
X}
X
X%endpick
Xstatic object *gl_endpick(self, args) object *self, *args; {
X return endpick_select(args, endpick);
X}
X
X%gselect
Xstatic object *gl_gselect(self, args) object *self, *args; {
X return pick_select(args, gselect);
X}
X
X%endselect
Xstatic object *gl_endselect(self, args) object *self, *args; {
X return endpick_select(args, endselect);
X}
X
X
X/* XXX The generator botches this one. Here's a quick hack to fix it. */
X
X% getmatrix float r[16]
X
Xstatic object *
Xgl_getmatrix(self, args)
X object *self;
X object *args;
X{
X float arg1 [ 16 ] ;
X object *v, *w;
X int i;
X getmatrix( arg1 );
X v = newlistobject(16);
X if (v == NULL) {
X return err_nomem();
X }
X for (i = 0; i < 16; i++) {
X w = mknewfloatobject(arg1[i]);
X if (w == NULL) {
X DECREF(v);
X return NULL;
X }
X setlistitem(v, i, w);
X }
X return v;
X}
X
X/* End of manually written stubs */
X
X%%
X
Xlong getshade
Xvoid devport short s long s
Xvoid rdr2i long s long s
Xvoid rectfs short s short s short s short s
Xvoid rects short s short s short s short s
Xvoid rmv2i long s long s
Xvoid noport
Xvoid popviewport
Xvoid clear
Xvoid clearhitcode
Xvoid closeobj
Xvoid cursoff
Xvoid curson
Xvoid doublebuffer
Xvoid finish
Xvoid gconfig
Xvoid ginit
Xvoid greset
Xvoid multimap
Xvoid onemap
Xvoid popattributes
Xvoid popmatrix
Xvoid pushattributes
Xvoid pushmatrix
Xvoid pushviewport
Xvoid qreset
Xvoid RGBmode
Xvoid singlebuffer
Xvoid swapbuffers
Xvoid gsync
Xvoid tpon
Xvoid tpoff
Xvoid clkon
Xvoid clkoff
Xvoid ringbell
X#void callfunc
Xvoid gbegin
Xvoid textinit
Xvoid initnames
Xvoid pclos
Xvoid popname
Xvoid spclos
Xvoid zclear
Xvoid screenspace
Xvoid reshapeviewport
Xvoid winpush
Xvoid winpop
Xvoid foreground
Xvoid endfullscrn
Xvoid endpupmode
Xvoid fullscrn
Xvoid pupmode
Xvoid winconstraints
Xvoid pagecolor short s
Xvoid textcolor short s
Xvoid color short s
Xvoid curveit short s
Xvoid font short s
Xvoid linewidth short s
Xvoid setlinestyle short s
Xvoid setmap short s
Xvoid swapinterval short s
Xvoid writemask short s
Xvoid textwritemask short s
Xvoid qdevice short s
Xvoid unqdevice short s
Xvoid curvebasis short s
Xvoid curveprecision short s
Xvoid loadname short s
Xvoid passthrough short s
Xvoid pushname short s
Xvoid setmonitor short s
Xvoid setshade short s
Xvoid setpattern short s
Xvoid pagewritemask short s
X#
Xvoid callobj long s
Xvoid delobj long s
Xvoid editobj long s
Xvoid makeobj long s
Xvoid maketag long s
Xvoid chunksize long s
Xvoid compactify long s
Xvoid deltag long s
Xvoid lsrepeat long s
Xvoid objinsert long s
Xvoid objreplace long s
Xvoid winclose long s
Xvoid blanktime long s
Xvoid freepup long s
X# This is not in the library!?
X###void pupcolor long s
X#
Xvoid backbuffer long s
Xvoid frontbuffer long s
Xvoid lsbackup long s
Xvoid resetls long s
Xvoid lampon long s
Xvoid lampoff long s
Xvoid setbell long s
Xvoid blankscreen long s
Xvoid depthcue long s
Xvoid zbuffer long s
Xvoid backface long s
X#
Xvoid cmov2i long s long s
Xvoid draw2i long s long s
Xvoid move2i long s long s
Xvoid pnt2i long s long s
Xvoid patchbasis long s long s
Xvoid patchprecision long s long s
Xvoid pdr2i long s long s
Xvoid pmv2i long s long s
Xvoid rpdr2i long s long s
Xvoid rpmv2i long s long s
Xvoid xfpt2i long s long s
Xvoid objdelete long s long s
Xvoid patchcurves long s long s
Xvoid minsize long s long s
Xvoid maxsize long s long s
Xvoid keepaspect long s long s
Xvoid prefsize long s long s
Xvoid stepunit long s long s
Xvoid fudge long s long s
Xvoid winmove long s long s
X#
Xvoid attachcursor short s short s
Xvoid deflinestyle short s short s
Xvoid noise short s short s
Xvoid picksize short s short s
Xvoid qenter short s short s
Xvoid setdepth short s short s
Xvoid cmov2s short s short s
Xvoid draw2s short s short s
Xvoid move2s short s short s
Xvoid pdr2s short s short s
Xvoid pmv2s short s short s
Xvoid pnt2s short s short s
Xvoid rdr2s short s short s
Xvoid rmv2s short s short s
Xvoid rpdr2s short s short s
Xvoid rpmv2s short s short s
Xvoid xfpt2s short s short s
X#
Xvoid cmov2 float s float s
Xvoid draw2 float s float s
Xvoid move2 float s float s
Xvoid pnt2 float s float s
Xvoid pdr2 float s float s
Xvoid pmv2 float s float s
Xvoid rdr2 float s float s
Xvoid rmv2 float s float s
Xvoid rpdr2 float s float s
Xvoid rpmv2 float s float s
Xvoid xfpt2 float s float s
X#
Xvoid loadmatrix float s[16]
Xvoid multmatrix float s[16]
Xvoid crv float s[16]
Xvoid rcrv float s[16]
X#
X# Methods that have strings.
X#
Xvoid addtopup long s char *s long s
Xvoid charstr char *s
Xvoid getport char *s
Xlong strwidth char *s
Xlong winopen char *s
Xvoid wintitle char *s
X#
X# Methods that have 1 long (# of elements) and an array
X#
Xvoid polf long s float s[3*arg1]
Xvoid polf2 long s float s[2*arg1]
Xvoid poly long s float s[3*arg1]
Xvoid poly2 long s float s[2*arg1]
Xvoid crvn long s float s[3*arg1]
Xvoid rcrvn long s float s[4*arg1]
X#
Xvoid polf2i long s long s[2*arg1]
Xvoid polfi long s long s[3*arg1]
Xvoid poly2i long s long s[2*arg1]
Xvoid polyi long s long s[3*arg1]
X#
Xvoid polf2s long s short s[2*arg1]
Xvoid polfs long s short s[3*arg1]
Xvoid polys long s short s[3*arg1]
Xvoid poly2s long s short s[2*arg1]
X#
Xvoid defcursor short s short s[16]
Xvoid writepixels short s short s[arg1]
Xvoid defbasis long s float s[16]
Xvoid gewrite short s short s[arg1]
X#
Xvoid rotate short s char s
X# This is not in the library!?
X###void setbutton short s char s
Xvoid rot float s char s
X#
Xvoid circfi long s long s long s
Xvoid circi long s long s long s
Xvoid cmovi long s long s long s
Xvoid drawi long s long s long s
Xvoid movei long s long s long s
Xvoid pnti long s long s long s
Xvoid newtag long s long s long s
Xvoid pdri long s long s long s
Xvoid pmvi long s long s long s
Xvoid rdri long s long s long s
Xvoid rmvi long s long s long s
Xvoid rpdri long s long s long s
Xvoid rpmvi long s long s long s
Xvoid xfpti long s long s long s
X#
Xvoid circ float s float s float s
Xvoid circf float s float s float s
Xvoid cmov float s float s float s
Xvoid draw float s float s float s
Xvoid move float s float s float s
Xvoid pnt float s float s float s
Xvoid scale float s float s float s
Xvoid translate float s float s float s
Xvoid pdr float s float s float s
Xvoid pmv float s float s float s
Xvoid rdr float s float s float s
Xvoid rmv float s float s float s
Xvoid rpdr float s float s float s
Xvoid rpmv float s float s float s
Xvoid xfpt float s float s float s
X#
Xvoid RGBcolor short s short s short s
Xvoid RGBwritemask short s short s short s
Xvoid setcursor short s short s short s
Xvoid tie short s short s short s
Xvoid circfs short s short s short s
Xvoid circs short s short s short s
Xvoid cmovs short s short s short s
Xvoid draws short s short s short s
Xvoid moves short s short s short s
Xvoid pdrs short s short s short s
Xvoid pmvs short s short s short s
Xvoid pnts short s short s short s
Xvoid rdrs short s short s short s
Xvoid rmvs short s short s short s
Xvoid rpdrs short s short s short s
Xvoid rpmvs short s short s short s
Xvoid xfpts short s short s short s
Xvoid curorigin short s short s short s
Xvoid cyclemap short s short s short s
X#
Xvoid patch float s[16] float s[16] float s[16]
Xvoid splf long s float s[3*arg1] short s[arg1]
Xvoid splf2 long s float s[2*arg1] short s[arg1]
Xvoid splfi long s long s[3*arg1] short s[arg1]
Xvoid splf2i long s long s[2*arg1] short s[arg1]
Xvoid splfs long s short s[3*arg1] short s[arg1]
Xvoid splf2s long s short s[2*arg1] short s[arg1]
Xvoid defpattern short s short s short s[arg2*arg2/16]
X#
Xvoid rpatch float s[16] float s[16] float s[16] float s[16]
X#
X# routines that send 4 floats
X#
Xvoid ortho2 float s float s float s float s
Xvoid rect float s float s float s float s
Xvoid rectf float s float s float s float s
Xvoid xfpt4 float s float s float s float s
X#
Xvoid textport short s short s short s short s
Xvoid mapcolor short s short s short s short s
Xvoid scrmask short s short s short s short s
Xvoid setvaluator short s short s short s short s
Xvoid viewport short s short s short s short s
Xvoid shaderange short s short s short s short s
Xvoid xfpt4s short s short s short s short s
Xvoid rectfi long s long s long s long s
Xvoid recti long s long s long s long s
Xvoid xfpt4i long s long s long s long s
Xvoid prefposition long s long s long s long s
X#
Xvoid arc float s float s float s short s short s
Xvoid arcf float s float s float s short s short s
Xvoid arcfi long s long s long s short s short s
Xvoid arci long s long s long s short s short s
X#
Xvoid bbox2 short s short s float s float s float s float s
Xvoid bbox2i short s short s long s long s long s long s
Xvoid bbox2s short s short s short s short s short s short s
Xvoid blink short s short s short s short s short s
Xvoid ortho float s float s float s float s float s float s
Xvoid window float s float s float s float s float s float s
Xvoid lookat float s float s float s float s float s float s short s
X#
Xvoid perspective short s float s float s float s
Xvoid polarview float s short s short s short s
X# XXX getichararray not supported
X#void writeRGB short s char s[arg1] char s[arg1] char s[arg1]
X#
Xvoid arcfs short s short s short s short s short s
Xvoid arcs short s short s short s short s short s
Xvoid rectcopy short s short s short s short s short s short s
Xvoid RGBcursor short s short s short s short s short s short s short s
X#
Xlong getbutton short s
Xlong getcmmode
Xlong getlsbackup
Xlong getresetls
Xlong getdcm
Xlong getzbuffer
Xlong ismex
Xlong isobj long s
Xlong isqueued short s
Xlong istag long s
X#
Xlong genobj
Xlong gentag
Xlong getbuffer
Xlong getcolor
Xlong getdisplaymode
Xlong getfont
Xlong getheight
Xlong gethitcode
Xlong getlstyle
Xlong getlwidth
Xlong getmap
Xlong getplanes
Xlong getwritemask
Xlong qtest
Xlong getlsrepeat
Xlong getmonitor
Xlong getopenobj
Xlong getpattern
Xlong winget
Xlong winattach
Xlong getothermonitor
Xlong newpup
X#
Xlong getvaluator short s
Xvoid winset long s
Xlong dopup long s
Xvoid getdepth short r short r
Xvoid getcpos short r short r
Xvoid getsize long r long r
Xvoid getorigin long r long r
Xvoid getviewport short r short r short r short r
Xvoid gettp short r short r short r short r
Xvoid getgpos float r float r float r float r
Xvoid winposition long s long s long s long s
Xvoid gRGBcolor short r short r short r
Xvoid gRGBmask short r short r short r
Xvoid getscrmask short r short r short r short r
Xvoid gRGBcursor short r short r short r short r short r short r short r short r long *
Xvoid getmcolor short s short r short r short r
Xvoid mapw long s short s short s float r float r float r float r float r float r
Xvoid mapw2 long s short s short s float r float r
Xvoid defrasterfont short s short s short s Fontchar s[arg3] short s short s[4*arg5]
Xlong qread short r
Xvoid getcursor short r short r short r long r
X#
X# For these we receive arrays of stuff
X#
Xvoid getdev long s short s[arg1] short r[arg1]
X#XXX not generated correctly yet
X#void getmatrix float r[16]
Xlong readpixels short s short r[retval]
Xlong readRGB short s char r[retval] char r[retval] char r[retval]
Xlong blkqread short s short r[arg1]
X#
X# New 4D routines
X#
Xvoid cmode
Xvoid concave long s
Xvoid curstype long s
Xvoid drawmode long s
Xvoid gammaramp short s[256] short s[256] short s[256]
Xlong getbackface
Xlong getdescender
Xlong getdrawmode
Xlong getmmode
Xlong getsm
Xlong getvideo long s
Xvoid imakebackground
Xvoid lmbind short s short s
Xvoid lmdef long s long s long s float s[arg3]
Xvoid mmode long s
Xvoid normal float s[3]
Xvoid overlay long s
Xvoid RGBrange short s short s short s short s short s short s short s short s
Xvoid setvideo long s long s
Xvoid shademodel long s
Xvoid underlay long s
X#
X# New Personal Iris/GT Routines
X#
Xvoid bgnclosedline
Xvoid bgnline
Xvoid bgnpoint
Xvoid bgnpolygon
Xvoid bgnsurface
Xvoid bgntmesh
Xvoid bgntrim
Xvoid endclosedline
Xvoid endline
Xvoid endpoint
Xvoid endpolygon
Xvoid endsurface
Xvoid endtmesh
Xvoid endtrim
Xvoid blendfunction long s long s
Xvoid c3f float s[3]
Xvoid c3i long s[3]
Xvoid c3s short s[3]
Xvoid c4f float s[4]
Xvoid c4i long s[4]
Xvoid c4s short s[4]
Xvoid colorf float s
Xvoid cpack long s
Xvoid czclear long s long s
Xvoid dglclose long s
Xlong dglopen char *s long s
Xlong getgdesc long s
Xvoid getnurbsproperty long s float r
Xvoid glcompat long s long s
Xvoid iconsize long s long s
Xvoid icontitle char *s
Xvoid lRGBrange short s short s short s short s short s short s long s long s
Xvoid linesmooth long s
Xvoid lmcolor long s
Xvoid logicop long s
Xlong lrectread short s short s short s short s long r[retval]
Xvoid lrectwrite short s short s short s short s long s[(arg2-arg1+1)*(arg4-arg3+1)]
Xlong rectread short s short s short s short s short r[retval]
Xvoid rectwrite short s short s short s short s short s[(arg2-arg1+1)*(arg4-arg3+1)]
Xvoid lsetdepth long s long s
Xvoid lshaderange short s short s long s long s
Xvoid n3f float s[3]
Xvoid noborder
Xvoid pntsmooth long s
Xvoid readsource long s
Xvoid rectzoom float s float s
Xvoid sbox float s float s float s float s
Xvoid sboxi long s long s long s long s
Xvoid sboxs short s short s short s short s
Xvoid sboxf float s float s float s float s
Xvoid sboxfi long s long s long s long s
Xvoid sboxfs short s short s short s short s
Xvoid setnurbsproperty long s float s
Xvoid setpup long s long s long s
Xvoid smoothline long s
Xvoid subpixel long s
Xvoid swaptmesh
Xlong swinopen long s
Xvoid v2f float s[2]
Xvoid v2i long s[2]
Xvoid v2s short s[2]
Xvoid v3f float s[3]
Xvoid v3i long s[3]
Xvoid v3s short s[3]
Xvoid v4f float s[4]
Xvoid v4i long s[4]
Xvoid v4s short s[4]
Xvoid videocmd long s
Xlong windepth long s
Xvoid wmpack long s
Xvoid zdraw long s
Xvoid zfunction long s
Xvoid zsource long s
Xvoid zwritemask long s
X#
X# uses doubles
X#
Xvoid v2d double s[2]
Xvoid v3d double s[3]
Xvoid v4d double s[4]
EOF
fi
if test -s 'src/stdwinmodule.c'
then echo '*** I will not over-write existing file src/stdwinmodule.c'
else
echo 'x - src/stdwinmodule.c'
sed 's/^X//' > 'src/stdwinmodule.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/* Stdwin module */
X
X/* Stdwin itself is a module, not a separate object type.
X Object types defined here:
X wp: a window
X dp: a drawing structure (only one can exist at a time)
X mp: a menu
X tp: a textedit block
X*/
X
X/* Rules for translating C stdwin function calls into Python stwin:
X - All names drop their initial letter 'w'
X - Functions with a window as first parameter are methods of window objects
X - There is no equivalent for wclose(); just delete the window object
X (all references to it!) (XXX maybe this is a bad idea)
X - w.begindrawing() returns a drawing object
X - There is no equivalent for wenddrawing(win); just delete the drawing
X object (all references to it!) (XXX maybe this is a bad idea)
X - Functions that may only be used inside wbegindrawing / wendddrawing
X are methods of the drawing object; this includes the text measurement
X functions (which however have doubles as module functions).
X - Methods of the drawing object drop an initial 'draw' from their name
X if they have it, e.g., wdrawline() --> d.line()
X - The obvious type conversions: int --> intobject; string --> stringobject
X - A text parameter followed by a length parameter is only a text (string)
X parameter in Python
X - A point or other pair of horizontal and vertical coordinates is always
X a pair of integers in Python
X - Two points forming a rectangle or endpoints of a line segment are a
X pair of points in Python
X - The arguments to d.elarc() are three points.
X - The functions wgetclip() and wsetclip() are translated into
X stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
X a bad word for what these functions do (clipping has a different
X meaning in the drawing world), while cutbuffer is standard X jargon.
X XXX This must change again in the light of changes to stdwin!
X - For textedit, similar rules hold, but they are less strict.
X XXX more?
X*/
X
X#include "allobjects.h"
X
X#include "modsupport.h"
X
X#include "stdwin.h"
X
X/* Window and menu object types declared here because of forward references */
X
Xtypedef struct {
X OB_HEAD
X object *w_title;
X WINDOW *w_win;
X object *w_attr; /* Attributes dictionary */
X} windowobject;
X
Xextern typeobject Windowtype; /* Really static, forward */
X
X#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
X
Xtypedef struct {
X OB_HEAD
X MENU *m_menu;
X int m_id;
X object *m_attr; /* Attributes dictionary */
X} menuobject;
X
Xextern typeobject Menutype; /* Really static, forward */
X
X#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
X
X
X/* Strongly stdwin-specific argument handlers */
X
Xstatic int
Xgetmousedetail(v, ep)
X object *v;
X EVENT *ep;
X{
X if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 4)
X return err_badarg();
X return getintintarg(gettupleitem(v, 0),
X &ep->u.where.h, &ep->u.where.v) &&
X getintarg(gettupleitem(v, 1), &ep->u.where.clicks) &&
X getintarg(gettupleitem(v, 2), &ep->u.where.button) &&
X getintarg(gettupleitem(v, 3), &ep->u.where.mask);
X}
X
Xstatic int
Xgetmenudetail(v, ep)
X object *v;
X EVENT *ep;
X{
X object *mp;
X if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2)
X return err_badarg();
X mp = gettupleitem(v, 0);
X if (mp == NULL || !is_menuobject(mp))
X return err_badarg();
X ep->u.m.id = ((menuobject *)mp) -> m_id;
X return getintarg(gettupleitem(v, 1), &ep->u.m.item);
X}
X
Xstatic int
Xgeteventarg(v, ep)
X object *v;
X EVENT *ep;
X{
X object *wp, *detail;
X int a[4];
X if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3)
X return err_badarg();
X if (!getintarg(gettupleitem(v, 0), &ep->type))
X return 0;
X wp = gettupleitem(v, 1);
X if (wp == None)
X ep->window = NULL;
X else if (wp == NULL || !is_windowobject(wp))
X return err_badarg();
X else
X ep->window = ((windowobject *)wp) -> w_win;
X detail = gettupleitem(v, 2);
X switch (ep->type) {
X case WE_CHAR:
X if (!is_stringobject(detail) || getstringsize(detail) != 1)
X return err_badarg();
X ep->u.character = getstringvalue(detail)[0];
X return 1;
X case WE_COMMAND:
X return getintarg(detail, &ep->u.command);
X case WE_DRAW:
X if (!getrectarg(detail, a))
X return 0;
X ep->u.area.left = a[0];
X ep->u.area.top = a[1];
X ep->u.area.right = a[2];
X ep->u.area.bottom = a[3];
X return 1;
X case WE_MOUSE_DOWN:
X case WE_MOUSE_UP:
X case WE_MOUSE_MOVE:
X return getmousedetail(detail, ep);
X case WE_MENU:
X return getmenudetail(detail, ep);
X default:
X return 1;
X }
X}
X
X
X/* Return construction tools */
X
Xstatic object *
Xmakepoint(a, b)
X int a, b;
X{
X object *v;
X object *w;
X if ((v = newtupleobject(2)) == NULL)
X return NULL;
X if ((w = newintobject((long)a)) == NULL ||
X settupleitem(v, 0, w) != 0 ||
X (w = newintobject((long)b)) == NULL ||
X settupleitem(v, 1, w) != 0) {
X DECREF(v);
X return NULL;
X }
X return v;
X}
X
Xstatic object *
Xmakerect(a, b, c, d)
X int a, b, c, d;
X{
X object *v;
X object *w;
X if ((v = newtupleobject(2)) == NULL)
X return NULL;
X if ((w = makepoint(a, b)) == NULL ||
X settupleitem(v, 0, w) != 0 ||
X (w = makepoint(c, d)) == NULL ||
X settupleitem(v, 1, w) != 0) {
X DECREF(v);
X return NULL;
X }
X return v;
X}
X
Xstatic object *
Xmakemouse(hor, ver, clicks, button, mask)
X int hor, ver, clicks, button, mask;
X{
X object *v;
X object *w;
X if ((v = newtupleobject(4)) == NULL)
X return NULL;
X if ((w = makepoint(hor, ver)) == NULL ||
X settupleitem(v, 0, w) != 0 ||
X (w = newintobject((long)clicks)) == NULL ||
X settupleitem(v, 1, w) != 0 ||
X (w = newintobject((long)button)) == NULL ||
X settupleitem(v, 2, w) != 0 ||
X (w = newintobject((long)mask)) == NULL ||
X settupleitem(v, 3, w) != 0) {
X DECREF(v);
X return NULL;
X }
X return v;
X}
X
Xstatic object *
Xmakemenu(mp, item)
X object *mp;
X int item;
X{
X object *v;
X object *w;
X if ((v = newtupleobject(2)) == NULL)
X return NULL;
X INCREF(mp);
X if (settupleitem(v, 0, mp) != 0 ||
X (w = newintobject((long)item)) == NULL ||
X settupleitem(v, 1, w) != 0) {
X DECREF(v);
X return NULL;
X }
X return v;
X}
X
X
X/* Drawing objects */
X
Xtypedef struct {
X OB_HEAD
X windowobject *d_ref;
X} drawingobject;
X
Xstatic drawingobject *Drawing; /* Set to current drawing object, or NULL */
X
X/* Drawing methods */
X
Xstatic void
Xdrawing_dealloc(dp)
X drawingobject *dp;
X{
X wenddrawing(dp->d_ref->w_win);
X Drawing = NULL;
X DECREF(dp->d_ref);
X free((char *)dp);
X}
X
Xstatic object *
Xdrawing_generic(dp, args, func)
X drawingobject *dp;
X object *args;
X void (*func) FPROTO((int, int, int, int));
X{
X int a[4];
X if (!getrectarg(args, a))
X return NULL;
X (*func)(a[0], a[1], a[2], a[3]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xdrawing_line(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, wdrawline);
X}
X
Xstatic object *
Xdrawing_xorline(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, wxorline);
X}
X
Xstatic object *
Xdrawing_circle(dp, args)
X drawingobject *dp;
X object *args;
X{
X int a[3];
X if (!getpointintarg(args, a))
X return NULL;
X wdrawcircle(a[0], a[1], a[2]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xdrawing_elarc(dp, args)
X drawingobject *dp;
X object *args;
X{
X int a[6];
X if (!get3pointarg(args, a))
X return NULL;
X wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xdrawing_box(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, wdrawbox);
X}
X
Xstatic object *
Xdrawing_erase(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, werase);
X}
X
Xstatic object *
Xdrawing_paint(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, wpaint);
X}
X
Xstatic object *
Xdrawing_invert(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, winvert);
X}
X
Xstatic object *
Xdrawing_cliprect(dp, args)
X drawingobject *dp;
X object *args;
X{
X drawing_generic(dp, args, wcliprect);
X}
X
Xstatic object *
Xdrawing_noclip(dp, args)
X drawingobject *dp;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X wnoclip();
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xdrawing_shade(dp, args)
X drawingobject *dp;
X object *args;
X{
X int a[5];
X if (!getrectintarg(args, a))
X return NULL;
X wshade(a[0], a[1], a[2], a[3], a[4]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xdrawing_text(dp, args)
X drawingobject *dp;
X object *args;
X{
X int a[2];
X object *s;
X if (!getpointstrarg(args, a, &s))
X return NULL;
X wdrawtext(a[0], a[1], getstringvalue(s), (int)getstringsize(s));
X INCREF(None);
X return None;
X}
X
X/* The following four are also used as stdwin functions */
X
Xstatic object *
Xdrawing_lineheight(dp, args)
X drawingobject *dp;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X return newintobject((long)wlineheight());
X}
X
Xstatic object *
Xdrawing_baseline(dp, args)
X drawingobject *dp;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X return newintobject((long)wbaseline());
X}
X
Xstatic object *
Xdrawing_textwidth(dp, args)
X drawingobject *dp;
X object *args;
X{
X object *s;
X if (!getstrarg(args, &s))
X return NULL;
X return newintobject(
X (long)wtextwidth(getstringvalue(s), (int)getstringsize(s)));
X}
X
Xstatic object *
Xdrawing_textbreak(dp, args)
X drawingobject *dp;
X object *args;
X{
X object *s;
X int a;
X if (!getstrintarg(args, &s, &a))
X return NULL;
X return newintobject(
X (long)wtextbreak(getstringvalue(s), (int)getstringsize(s), a));
X}
X
Xstatic struct methodlist drawing_methods[] = {
X {"box", drawing_box},
X {"circle", drawing_circle},
X {"cliprect", drawing_cliprect},
X {"elarc", drawing_elarc},
X {"erase", drawing_erase},
X {"invert", drawing_invert},
X {"line", drawing_line},
X {"noclip", drawing_noclip},
X {"paint", drawing_paint},
X {"shade", drawing_shade},
X {"text", drawing_text},
X {"xorline", drawing_xorline},
X
X /* Text measuring methods: */
X {"baseline", drawing_baseline},
X {"lineheight", drawing_lineheight},
X {"textbreak", drawing_textbreak},
X {"textwidth", drawing_textwidth},
X {NULL, NULL} /* sentinel */
X};
X
Xstatic object *
Xdrawing_getattr(wp, name)
X drawingobject *wp;
X char *name;
X{
X return findmethod(drawing_methods, (object *)wp, name);
X}
X
Xstatic typeobject Drawingtype = {
X OB_HEAD_INIT(&Typetype)
X 0, /*ob_size*/
X "drawing", /*tp_name*/
X sizeof(drawingobject), /*tp_size*/
X 0, /*tp_itemsize*/
X /* methods */
X drawing_dealloc, /*tp_dealloc*/
X 0, /*tp_print*/
X drawing_getattr, /*tp_getattr*/
X 0, /*tp_setattr*/
X 0, /*tp_compare*/
X 0, /*tp_repr*/
X};
X
X
X/* Text(edit) objects */
X
Xtypedef struct {
X OB_HEAD
X TEXTEDIT *t_text;
X windowobject *t_ref;
X object *t_attr; /* Attributes dictionary */
X} textobject;
X
Xextern typeobject Texttype; /* Really static, forward */
X
Xstatic textobject *
Xnewtextobject(wp, left, top, right, bottom)
X windowobject *wp;
X int left, top, right, bottom;
X{
X textobject *tp;
X tp = NEWOBJ(textobject, &Texttype);
X if (tp == NULL)
X return NULL;
X tp->t_attr = NULL;
X INCREF(wp);
X tp->t_ref = wp;
X tp->t_text = tecreate(wp->w_win, left, top, right, bottom);
X if (tp->t_text == NULL) {
X DECREF(tp);
X return (textobject *) err_nomem();
X }
X return tp;
X}
X
X/* Text(edit) methods */
X
Xstatic void
Xtext_dealloc(tp)
X textobject *tp;
X{
X if (tp->t_text != NULL)
X tefree(tp->t_text);
X if (tp->t_attr != NULL)
X DECREF(tp->t_attr);
X DECREF(tp->t_ref);
X DEL(tp);
X}
X
Xstatic object *
Xtext_arrow(self, args)
X textobject *self;
X object *args;
X{
X int code;
X if (!getintarg(args, &code))
X return NULL;
X tearrow(self->t_text, code);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xtext_draw(self, args)
X textobject *self;
X object *args;
X{
X register TEXTEDIT *tp = self->t_text;
X int a[4];
X int left, top, right, bottom;
X if (!getrectarg(args, a))
X return NULL;
X if (Drawing != NULL) {
X err_setstr(RuntimeError, "not drawing");
X return NULL;
X }
X /* Clip to text area and ignore if area is empty */
X left = tegetleft(tp);
X top = tegettop(tp);
X right = tegetright(tp);
X bottom = tegetbottom(tp);
X if (a[0] < left) a[0] = left;
X if (a[1] < top) a[1] = top;
X if (a[2] > right) a[2] = right;
X if (a[3] > bottom) a[3] = bottom;
X if (a[0] < a[2] && a[1] < a[3]) {
X /* Hide/show focus around draw call; these are undocumented,
X but required here to get the highlighting correct.
X The call to werase is also required for this reason.
X Finally, this forces us to require (above) that we are NOT
X already drawing. */
X tehidefocus(tp);
X wbegindrawing(self->t_ref->w_win);
X werase(a[0], a[1], a[2], a[3]);
X tedrawnew(tp, a[0], a[1], a[2], a[3]);
X wenddrawing(self->t_ref->w_win);
X teshowfocus(tp);
X }
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xtext_event(self, args)
X textobject *self;
X object *args;
X{
X register TEXTEDIT *tp = self->t_text;
X EVENT e;
X if (!geteventarg(args, &e))
X return NULL;
X if (e.type == WE_MOUSE_DOWN) {
X /* Cheat at the margins */
X int width, height;
X wgetdocsize(e.window, &width, &height);
X if (e.u.where.h < 0 && tegetleft(tp) == 0)
X e.u.where.h = 0;
X else if (e.u.where.h > width && tegetright(tp) == width)
X e.u.where.h = width;
X if (e.u.where.v < 0 && tegettop(tp) == 0)
X e.u.where.v = 0;
X else if (e.u.where.v > height && tegetright(tp) == height)
X e.u.where.v = height;
X }
X return newintobject((long) teevent(tp, &e));
X}
X
Xstatic object *
Xtext_getfocus(self, args)
X textobject *self;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text));
X}
X
Xstatic object *
Xtext_getfocustext(self, args)
X textobject *self;
X object *args;
X{
X int f1, f2;
X char *text;
X if (!getnoarg(args))
X return NULL;
X f1 = tegetfoc1(self->t_text);
X f2 = tegetfoc2(self->t_text);
X text = tegettext(self->t_text);
X return newsizedstringobject(text + f1, f2-f1);
X}
X
Xstatic object *
Xtext_getrect(self, args)
X textobject *self;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X return makerect(tegetleft(self->t_text),
X tegettop(self->t_text),
X tegetright(self->t_text),
X tegetbottom(self->t_text));
X}
X
Xstatic object *
Xtext_gettext(self, args)
X textobject *self;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X return newsizedstringobject(tegettext(self->t_text),
X tegetlen(self->t_text));
X}
X
Xstatic object *
Xtext_move(self, args)
X textobject *self;
X object *args;
X{
X int a[4];
X if (!getrectarg(args, a))
X return NULL;
X temovenew(self->t_text, a[0], a[1], a[2], a[3]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xtext_setfocus(self, args)
X textobject *self;
X object *args;
X{
X int a[2];
X if (!getpointarg(args, a))
X return NULL;
X tesetfocus(self->t_text, a[0], a[1]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xtext_replace(self, args)
X textobject *self;
X object *args;
X{
X object *text;
X if (!getstrarg(args, &text))
X return NULL;
X tereplace(self->t_text, getstringvalue(text));
X INCREF(None);
X return None;
X}
X
Xstatic struct methodlist text_methods[] = {
X "arrow", text_arrow,
X "draw", text_draw,
X "event", text_event,
X "getfocus", text_getfocus,
X "getfocustext", text_getfocustext,
X "getrect", text_getrect,
X "gettext", text_gettext,
X "move", text_move,
X "replace", text_replace,
X "setfocus", text_setfocus,
X {NULL, NULL} /* sentinel */
X};
X
Xstatic object *
Xtext_getattr(tp, name)
X textobject *tp;
X char *name;
X{
X if (tp->t_attr != NULL) {
X object *v = dictlookup(tp->t_attr, name);
X if (v != NULL) {
X INCREF(v);
X return v;
X }
X }
X return findmethod(text_methods, (object *)tp, name);
X}
X
Xstatic int
Xtext_setattr(tp, name, v)
X textobject *tp;
X char *name;
X object *v;
X{
X if (tp->t_attr == NULL) {
X tp->t_attr = newdictobject();
X if (tp->t_attr == NULL)
X return -1;
X }
X if (v == NULL)
X return dictremove(tp->t_attr, name);
X else
X return dictinsert(tp->t_attr, name, v);
X}
X
Xstatic typeobject Texttype = {
X OB_HEAD_INIT(&Typetype)
X 0, /*ob_size*/
X "textedit", /*tp_name*/
X sizeof(textobject), /*tp_size*/
X 0, /*tp_itemsize*/
X /* methods */
X text_dealloc, /*tp_dealloc*/
X 0, /*tp_print*/
X text_getattr, /*tp_getattr*/
X text_setattr, /*tp_setattr*/
X 0, /*tp_compare*/
X 0, /*tp_repr*/
X};
X
X
X/* Menu objects */
X
X#define IDOFFSET 10 /* Menu IDs we use start here */
X#define MAXNMENU 20 /* Max #menus we allow */
Xstatic menuobject *menulist[MAXNMENU];
X
Xstatic menuobject *
Xnewmenuobject(title)
X object *title;
X{
X int id;
X MENU *menu;
X menuobject *mp;
X for (id = 0; id < MAXNMENU; id++) {
X if (menulist[id] == NULL)
X break;
X }
X if (id >= MAXNMENU)
X return (menuobject *) err_nomem();
X menu = wmenucreate(id + IDOFFSET, getstringvalue(title));
X if (menu == NULL)
X return (menuobject *) err_nomem();
X mp = NEWOBJ(menuobject, &Menutype);
X if (mp != NULL) {
X mp->m_menu = menu;
X mp->m_id = id + IDOFFSET;
X mp->m_attr = NULL;
X menulist[id] = mp;
X }
X else
X wmenudelete(menu);
X return mp;
X}
X
X/* Menu methods */
X
Xstatic void
Xmenu_dealloc(mp)
X menuobject *mp;
X{
X
X int id = mp->m_id - IDOFFSET;
X if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
X menulist[id] = NULL;
X }
X wmenudelete(mp->m_menu);
X if (mp->m_attr != NULL)
X DECREF(mp->m_attr);
X DEL(mp);
X}
X
Xstatic object *
Xmenu_additem(self, args)
X menuobject *self;
X object *args;
X{
X object *text;
X int shortcut;
X if (is_tupleobject(args)) {
X object *v;
X if (!getstrstrarg(args, &text, &v))
X return NULL;
X if (getstringsize(v) != 1) {
X err_badarg();
X return NULL;
X }
X shortcut = *getstringvalue(v) & 0xff;
X }
X else {
X if (!getstrarg(args, &text))
X return NULL;
X shortcut = -1;
X }
X wmenuadditem(self->m_menu, getstringvalue(text), shortcut);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xmenu_setitem(self, args)
X menuobject *self;
X object *args;
X{
X int index;
X object *text;
X if (!getintstrarg(args, &index, &text))
X return NULL;
X wmenusetitem(self->m_menu, index, getstringvalue(text));
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xmenu_enable(self, args)
X menuobject *self;
X object *args;
X{
X int index;
X int flag;
X if (!getintintarg(args, &index, &flag))
X return NULL;
X wmenuenable(self->m_menu, index, flag);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xmenu_check(self, args)
X menuobject *self;
X object *args;
X{
X int index;
X int flag;
X if (!getintintarg(args, &index, &flag))
X return NULL;
X wmenucheck(self->m_menu, index, flag);
X INCREF(None);
X return None;
X}
X
Xstatic struct methodlist menu_methods[] = {
X "additem", menu_additem,
X "setitem", menu_setitem,
X "enable", menu_enable,
X "check", menu_check,
X {NULL, NULL} /* sentinel */
X};
X
Xstatic object *
Xmenu_getattr(mp, name)
X menuobject *mp;
X char *name;
X{
X if (mp->m_attr != NULL) {
X object *v = dictlookup(mp->m_attr, name);
X if (v != NULL) {
X INCREF(v);
X return v;
X }
X }
X return findmethod(menu_methods, (object *)mp, name);
X}
X
Xstatic int
Xmenu_setattr(mp, name, v)
X menuobject *mp;
X char *name;
X object *v;
X{
X if (mp->m_attr == NULL) {
X mp->m_attr = newdictobject();
X if (mp->m_attr == NULL)
X return -1;
X }
X if (v == NULL)
X return dictremove(mp->m_attr, name);
X else
X return dictinsert(mp->m_attr, name, v);
X}
X
Xstatic typeobject Menutype = {
X OB_HEAD_INIT(&Typetype)
X 0, /*ob_size*/
X "menu", /*tp_name*/
X sizeof(menuobject), /*tp_size*/
X 0, /*tp_itemsize*/
X /* methods */
X menu_dealloc, /*tp_dealloc*/
X 0, /*tp_print*/
X menu_getattr, /*tp_getattr*/
X menu_setattr, /*tp_setattr*/
X 0, /*tp_compare*/
X 0, /*tp_repr*/
X};
X
X
X/* Windows */
X
X#define MAXNWIN 50
Xstatic windowobject *windowlist[MAXNWIN];
X
X/* Window methods */
X
Xstatic void
Xwindow_dealloc(wp)
X windowobject *wp;
X{
X if (wp->w_win != NULL) {
X int tag = wgettag(wp->w_win);
X if (tag >= 0 && tag < MAXNWIN)
X windowlist[tag] = NULL;
X else
X fprintf(stderr, "XXX help! tag %d in window_dealloc\n",
X tag);
X wclose(wp->w_win);
X }
X DECREF(wp->w_title);
X if (wp->w_attr != NULL)
X DECREF(wp->w_attr);
X free((char *)wp);
X}
X
Xstatic void
Xwindow_print(wp, fp, flags)
X windowobject *wp;
X FILE *fp;
X int flags;
X{
X fprintf(fp, "<window titled '%s'>", getstringvalue(wp->w_title));
X}
X
Xstatic object *
Xwindow_begindrawing(wp, args)
X windowobject *wp;
X object *args;
X{
X drawingobject *dp;
X if (!getnoarg(args))
X return NULL;
X if (Drawing != NULL) {
X err_setstr(RuntimeError, "already drawing");
X return NULL;
X }
X dp = NEWOBJ(drawingobject, &Drawingtype);
X if (dp == NULL)
X return NULL;
X Drawing = dp;
X INCREF(wp);
X dp->d_ref = wp;
X wbegindrawing(wp->w_win);
X return (object *)dp;
X}
X
Xstatic object *
Xwindow_change(wp, args)
X windowobject *wp;
X object *args;
X{
X int a[4];
X if (!getrectarg(args, a))
X return NULL;
X wchange(wp->w_win, a[0], a[1], a[2], a[3]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_gettitle(wp, args)
X windowobject *wp;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X INCREF(wp->w_title);
X return wp->w_title;
X}
X
Xstatic object *
Xwindow_getwinsize(wp, args)
X windowobject *wp;
X object *args;
X{
X int width, height;
X if (!getnoarg(args))
X return NULL;
X wgetwinsize(wp->w_win, &width, &height);
X return makepoint(width, height);
X}
X
Xstatic object *
Xwindow_getdocsize(wp, args)
X windowobject *wp;
X object *args;
X{
X int width, height;
X if (!getnoarg(args))
X return NULL;
X wgetdocsize(wp->w_win, &width, &height);
X return makepoint(width, height);
X}
X
Xstatic object *
Xwindow_getorigin(wp, args)
X windowobject *wp;
X object *args;
X{
X int width, height;
X if (!getnoarg(args))
X return NULL;
X wgetorigin(wp->w_win, &width, &height);
X return makepoint(width, height);
X}
X
Xstatic object *
Xwindow_scroll(wp, args)
X windowobject *wp;
X object *args;
X{
X int a[6];
X if (!getrectpointarg(args, a))
X return NULL;
X wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_setdocsize(wp, args)
X windowobject *wp;
X object *args;
X{
X int a[2];
X if (!getpointarg(args, a))
X return NULL;
X wsetdocsize(wp->w_win, a[0], a[1]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_setorigin(wp, args)
X windowobject *wp;
X object *args;
X{
X int a[2];
X if (!getpointarg(args, a))
X return NULL;
X wsetorigin(wp->w_win, a[0], a[1]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_settitle(wp, args)
X windowobject *wp;
X object *args;
X{
X object *title;
X if (!getstrarg(args, &title))
X return NULL;
X DECREF(wp->w_title);
X INCREF(title);
X wp->w_title = title;
X wsettitle(wp->w_win, getstringvalue(title));
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_show(wp, args)
X windowobject *wp;
X object *args;
X{
X int a[4];
X if (!getrectarg(args, a))
X return NULL;
X wshow(wp->w_win, a[0], a[1], a[2], a[3]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_settimer(wp, args)
X windowobject *wp;
X object *args;
X{
X int a;
X if (!getintarg(args, &a))
X return NULL;
X wsettimer(wp->w_win, a);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xwindow_menucreate(self, args)
X windowobject *self;
X object *args;
X{
X menuobject *mp;
X object *title;
X if (!getstrarg(args, &title))
X return NULL;
X wmenusetdeflocal(1);
X mp = newmenuobject(title);
X if (mp == NULL)
X return NULL;
X wmenuattach(self->w_win, mp->m_menu);
X return (object *)mp;
X}
X
Xstatic object *
Xwindow_textcreate(self, args)
X windowobject *self;
X object *args;
X{
X textobject *tp;
X int a[4];
X if (!getrectarg(args, a))
X return NULL;
X return (object *)
X newtextobject(self, a[0], a[1], a[2], a[3]);
X}
X
Xstatic object *
Xwindow_setselection(self, args)
X windowobject *self;
X object *args;
X{
X int sel;
X object *str;
X int ok;
X if (!getintstrarg(args, &sel, &str))
X return NULL;
X ok = wsetselection(self->w_win, sel,
X getstringvalue(str), (int)getstringsize(str));
X return newintobject(ok);
X}
X
Xstatic object *
Xwindow_setwincursor(self, args)
X windowobject *self;
X object *args;
X{
X object *str;
X CURSOR *c;
X if (!getstrarg(args, &str))
X return NULL;
X c = wfetchcursor(getstringvalue(str));
X if (c == NULL) {
X err_setstr(RuntimeError, "no such cursor");
X return NULL;
X }
X wsetwincursor(self->w_win, c);
X INCREF(None);
X return None;
X}
X
Xstatic struct methodlist window_methods[] = {
X {"begindrawing",window_begindrawing},
X {"change", window_change},
X {"getdocsize", window_getdocsize},
X {"getorigin", window_getorigin},
X {"gettitle", window_gettitle},
X {"getwinsize", window_getwinsize},
X {"menucreate", window_menucreate},
X {"scroll", window_scroll},
X {"setwincursor",window_setwincursor},
X {"setdocsize", window_setdocsize},
X {"setorigin", window_setorigin},
X {"setselection",window_setselection},
X {"settimer", window_settimer},
X {"settitle", window_settitle},
X {"show", window_show},
X {"textcreate", window_textcreate},
X {NULL, NULL} /* sentinel */
X};
X
Xstatic object *
Xwindow_getattr(wp, name)
X windowobject *wp;
X char *name;
X{
X if (wp->w_attr != NULL) {
X object *v = dictlookup(wp->w_attr, name);
X if (v != NULL) {
X INCREF(v);
X return v;
X }
X }
X return findmethod(window_methods, (object *)wp, name);
X}
X
Xstatic int
Xwindow_setattr(wp, name, v)
X windowobject *wp;
X char *name;
X object *v;
X{
X if (wp->w_attr == NULL) {
X wp->w_attr = newdictobject();
X if (wp->w_attr == NULL)
X return -1;
X }
X if (v == NULL)
X return dictremove(wp->w_attr, name);
X else
X return dictinsert(wp->w_attr, name, v);
X}
X
Xstatic typeobject Windowtype = {
X OB_HEAD_INIT(&Typetype)
X 0, /*ob_size*/
X "window", /*tp_name*/
X sizeof(windowobject), /*tp_size*/
X 0, /*tp_itemsize*/
X /* methods */
X window_dealloc, /*tp_dealloc*/
X window_print, /*tp_print*/
X window_getattr, /*tp_getattr*/
X window_setattr, /*tp_setattr*/
X 0, /*tp_compare*/
X 0, /*tp_repr*/
X};
X
X/* Stdwin methods */
X
Xstatic object *
Xstdwin_open(sw, args)
X object *sw;
X object *args;
X{
X int tag;
X object *title;
X windowobject *wp;
X if (!getstrarg(args, &title))
X return NULL;
X for (tag = 0; tag < MAXNWIN; tag++) {
X if (windowlist[tag] == NULL)
X break;
X }
X if (tag >= MAXNWIN)
X return err_nomem();
X wp = NEWOBJ(windowobject, &Windowtype);
X if (wp == NULL)
X return NULL;
X INCREF(title);
X wp->w_title = title;
X wp->w_win = wopen(getstringvalue(title), (void (*)()) NULL);
X wp->w_attr = NULL;
X if (wp->w_win == NULL) {
X DECREF(wp);
X return NULL;
X }
X windowlist[tag] = wp;
X wsettag(wp->w_win, tag);
X return (object *)wp;
X}
X
Xstatic object *
Xstdwin_get_poll_event(poll, args)
X int poll;
X object *args;
X{
X EVENT e;
X object *v, *w;
X if (!getnoarg(args))
X return NULL;
X if (Drawing != NULL) {
X err_setstr(RuntimeError, "cannot getevent() while drawing");
X return NULL;
X }
X/* again: */
X if (poll) {
X if (!wpollevent(&e)) {
X INCREF(None);
X return None;
X }
X }
X else
X wgetevent(&e);
X if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
X /* Turn keyboard interrupts into exceptions */
X err_set(KeyboardInterrupt);
X return NULL;
X }
X/*
X if (e.window == NULL && (e.type == WE_COMMAND || e.type == WE_CHAR))
X goto again;
X*/
X if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
X /* Turn WC_CLOSE commands into WE_CLOSE events */
X e.type = WE_CLOSE;
X }
X v = newtupleobject(3);
X if (v == NULL)
X return NULL;
X if ((w = newintobject((long)e.type)) == NULL) {
X DECREF(v);
X return NULL;
X }
X settupleitem(v, 0, w);
X if (e.window == NULL)
X w = None;
X else {
X int tag = wgettag(e.window);
X if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL)
X w = None;
X else
X w = (object *)windowlist[tag];
X#ifdef sgi
X /* XXX Trap for unexplained weird bug */
X if ((long)w == (long)0x80000001) {
X err_setstr(SystemError,
X "bad pointer in stdwin.getevent()");
X return NULL;
X }
X#endif
X }
X INCREF(w);
X settupleitem(v, 1, w);
X switch (e.type) {
X case WE_CHAR:
X {
X char c[1];
X c[0] = e.u.character;
X w = newsizedstringobject(c, 1);
X }
X break;
X case WE_COMMAND:
X w = newintobject((long)e.u.command);
X break;
X case WE_DRAW:
X w = makerect(e.u.area.left, e.u.area.top,
X e.u.area.right, e.u.area.bottom);
X break;
X case WE_MOUSE_DOWN:
X case WE_MOUSE_MOVE:
X case WE_MOUSE_UP:
X w = makemouse(e.u.where.h, e.u.where.v,
X e.u.where.clicks,
X e.u.where.button,
X e.u.where.mask);
X break;
X case WE_MENU:
X if (e.u.m.id >= IDOFFSET && e.u.m.id < IDOFFSET+MAXNMENU &&
X menulist[e.u.m.id - IDOFFSET] != NULL)
X w = (object *)menulist[e.u.m.id - IDOFFSET];
X else
X w = None;
X w = makemenu(w, e.u.m.item);
X break;
X case WE_LOST_SEL:
X w = newintobject((long)e.u.sel);
X break;
X default:
X w = None;
X INCREF(w);
X break;
X }
X if (w == NULL) {
X DECREF(v);
X return NULL;
X }
X settupleitem(v, 2, w);
X return v;
X}
X
Xstatic object *
Xstdwin_getevent(sw, args)
X object *sw;
X object *args;
X{
X return stdwin_get_poll_event(0, args);
X}
X
Xstatic object *
Xstdwin_pollevent(sw, args)
X object *sw;
X object *args;
X{
X return stdwin_get_poll_event(1, args);
X}
X
Xstatic object *
Xstdwin_setdefwinpos(sw, args)
X object *sw;
X object *args;
X{
X int a[2];
X if (!getpointarg(args, a))
X return NULL;
X wsetdefwinpos(a[0], a[1]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_setdefwinsize(sw, args)
X object *sw;
X object *args;
X{
X int a[2];
X if (!getpointarg(args, a))
X return NULL;
X wsetdefwinsize(a[0], a[1]);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_getdefwinpos(wp, args)
X windowobject *wp;
X object *args;
X{
X int h, v;
X if (!getnoarg(args))
X return NULL;
X wgetdefwinpos(&h, &v);
X return makepoint(h, v);
X}
X
Xstatic object *
Xstdwin_getdefwinsize(wp, args)
X windowobject *wp;
X object *args;
X{
X int width, height;
X if (!getnoarg(args))
X return NULL;
X wgetdefwinsize(&width, &height);
X return makepoint(width, height);
X}
X
Xstatic object *
Xstdwin_menucreate(self, args)
X object *self;
X object *args;
X{
X object *title;
X if (!getstrarg(args, &title))
X return NULL;
X wmenusetdeflocal(0);
X return (object *)newmenuobject(title);
X}
X
Xstatic object *
Xstdwin_askfile(self, args)
X object *self;
X object *args;
X{
X object *prompt, *dflt;
X int new, ret;
X char buf[256];
X if (!getstrstrintarg(args, &prompt, &dflt, &new))
X return NULL;
X strncpy(buf, getstringvalue(dflt), sizeof buf);
X buf[sizeof buf - 1] = '\0';
X ret = waskfile(getstringvalue(prompt), buf, sizeof buf, new);
X if (!ret) {
X err_set(KeyboardInterrupt);
X return NULL;
X }
X return newstringobject(buf);
X}
X
Xstatic object *
Xstdwin_askync(self, args)
X object *self;
X object *args;
X{
X object *prompt;
X int new, ret;
X if (!getstrintarg(args, &prompt, &new))
X return NULL;
X ret = waskync(getstringvalue(prompt), new);
X if (ret < 0) {
X err_set(KeyboardInterrupt);
X return NULL;
X }
X return newintobject((long)ret);
X}
X
Xstatic object *
Xstdwin_askstr(self, args)
X object *self;
X object *args;
X{
X object *prompt, *dflt;
X int ret;
X char buf[256];
X if (!getstrstrarg(args, &prompt, &dflt))
X return NULL;
X strncpy(buf, getstringvalue(dflt), sizeof buf);
X buf[sizeof buf - 1] = '\0';
X ret = waskstr(getstringvalue(prompt), buf, sizeof buf);
X if (!ret) {
X err_set(KeyboardInterrupt);
X return NULL;
X }
X return newstringobject(buf);
X}
X
Xstatic object *
Xstdwin_message(self, args)
X object *self;
X object *args;
X{
X object *msg;
X if (!getstrarg(args, &msg))
X return NULL;
X wmessage(getstringvalue(msg));
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_fleep(self, args)
X object *self;
X object *args;
X{
X if (!getnoarg(args))
X return NULL;
X wfleep();
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_setcutbuffer(self, args)
X object *self;
X object *args;
X{
X int i;
X object *str;
X if (!getintstrarg(args, &i, &str))
X return NULL;
X wsetcutbuffer(i, getstringvalue(str), getstringsize(str));
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_getcutbuffer(self, args)
X object *self;
X object *args;
X{
X int i;
X char *str;
X int len;
X if (!getintarg(args, &i))
X return NULL;
X str = wgetcutbuffer(i, &len);
X if (str == NULL) {
X str = "";
X len = 0;
X }
X return newsizedstringobject(str, len);
X}
X
Xstatic object *
Xstdwin_rotatecutbuffers(self, args)
X object *self;
X object *args;
X{
X int i;
X if (!getintarg(args, &i))
X return NULL;
X wrotatecutbuffers(i);
X INCREF(None);
X return None;
X}
X
Xstatic object *
Xstdwin_getselection(self, args)
X object *self;
X object *args;
X{
X int sel;
X char *data;
X int len;
X if (!getintarg(args, &sel))
X return NULL;
X data = wgetselection(sel, &len);
X if (data == NULL) {
X data = "";
X len = 0;
X }
X return newsizedstringobject(data, len);
X}
X
Xstatic object *
Xstdwin_resetselection(self, args)
X object *self;
X object *args;
X{
X int sel;
X if (!getintarg(args, &sel))
X return NULL;
X wresetselection(sel);
X INCREF(None);
X return None;
X}
X
Xstatic struct methodlist stdwin_methods[] = {
X {"askfile", stdwin_askfile},
X {"askstr", stdwin_askstr},
X {"askync", stdwin_askync},
X {"fleep", stdwin_fleep},
X {"getselection", stdwin_getselection},
X {"getcutbuffer", stdwin_getcutbuffer},
X {"getdefwinpos", stdwin_getdefwinpos},
X {"getdefwinsize", stdwin_getdefwinsize},
X {"getevent", stdwin_getevent},
X {"menucreate", stdwin_menucreate},
X {"message", stdwin_message},
X {"open", stdwin_open},
X {"pollevent", stdwin_pollevent},
X {"resetselection", stdwin_resetselection},
X {"rotatecutbuffers", stdwin_rotatecutbuffers},
X {"setcutbuffer", stdwin_setcutbuffer},
X {"setdefwinpos", stdwin_setdefwinpos},
X {"setdefwinsize", stdwin_setdefwinsize},
X
X /* Text measuring methods borrow code from drawing objects: */
X {"baseline", drawing_baseline},
X {"lineheight", drawing_lineheight},
X {"textbreak", drawing_textbreak},
X {"textwidth", drawing_textwidth},
X {NULL, NULL} /* sentinel */
X};
X
Xvoid
Xinitstdwin()
X{
X static int inited;
X if (!inited) {
X winit();
X inited = 1;
X }
X initmodule("stdwin", stdwin_methods);
X}
EOF
fi
echo 'Part 04 out of 21 of pack.out complete.'
exit 0
|