summaryrefslogtreecommitdiff
path: root/gs/doc/Develop.htm
blob: d51cd803ad7759f33517fa1ceaf9b4df63f43c12 (plain)
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
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Information for Ghostscript developers</title>
<link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
<!-- $Id$ -->
</head>

<body>
<!-- [1.0 begin visible header] ============================================ -->

<!-- [1.1 begin headline] ================================================== -->

<h1>Information for Ghostscript developers</h1>

<!-- [1.1 end headline] ==================================================== -->

<!-- [1.2 begin table of contents] ========================================= -->

<h2>Table of contents</h2>

<blockquote><ul>
<li><a href="#Introduction">Introduction</a>
<li><a href="#Architecture">Architecture</a>
<ul>
<li><a href="#Design_goals">Design goals</a>
<li><a href="#Design_principles">Design principles</a>
<li><a href="#Large_scale_structure">Large-scale structure</a>
<li><a href="#Object_oriented_constructs">Object-oriented constructs</a>
</ul>
<li><a href="#File_roadmap">File roadmap</a>
<ul>
<li><a href="#Substrate">Substrate</a>
<li><a href="#Graphics_library">Graphics library</a>
<ul>
<li><a href="#Library_support">Support</a>,
    <a href="#Paths">Paths</a>,
    <a href="#Text">Text</a>,
    <a href="#Images">Images</a>,
    <a href="#Paint">Paint</a>,
    <a href="#Clipping">Clipping</a>,
    <a href="#Other_graphics">Other graphics</a>,
    <a href="#Driver_support">Driver support</a>,
    <a href="#FAPI_support_gx">Font API support</a>
    <a href="#Visual_trace">Visual Trace</a>
</ul>
<li><a href="#Device_drivers">Device drivers</a>
<ul>
<li><a href="#Internal_devices">Internal devices</a>,
    <a href="#PS_and_PDF_writers">PostScript and PDF writers</a>,
    <a href="#High_level_devices">Other high-level devices</a>,
    <a href="#Other_maintained_drivers">Other maintained drivers</a>,
    <a href="#Contributed_drivers">Contributed drivers</a>
</ul>
<li><a href="#PostScript_interpreter">PostScript interpreter</a>
<ul>
<li><a href="#Main_program">Main program</a>,
    <a href="#Data_structures">Data structures</a>,
    <a href="#Stacks">Stacks</a>,
    <a href="#Interpreter_loop">Interpreter loop</a>,
    <a href="#Scanning_parsing">Scanning/parsing</a>,
    <a href="#Standard_operators">Standard operators</a>,
    <a href="#Non_standard_operators">Non-standard operators</a>,
    <a href="#Interpreter_support">Interpreter support</a>,
    <a href="#PostScript_code">PostScript code</a>
</ul>
<li><a href="#PDF_interpreter">PDF interpreter</a>
<li><a href="#PPD">PostScript Printer Description</a>
<li><a href="#Build_process">Build process</a>
<ul>
<li><a href="#Makefile_structure">Makefile structure</a>,
    <a href="#dev_files">.dev files</a>,
    <a href="#Generators">Generators</a>,
    <a href="#Build_support">Support</a>
</ul>
<li><a href="#Utilities">Utilities</a>
<ul>
<li><a href="#Utilities_in_PostScript">Utilities in PostScript</a>
<li><a href="#Utility_scripts">Utility scripts</a>
</ul>
</ul>
<li><a href="#Memory_management">Memory management</a>
<ul>
<li><a href="#Memory_manager_architecture">Memory manager architecture</a>
<ul>
<li><a href="#Objects_vs_strings">Objects vs strings</a>,
    <a href="#Structure_descriptors">Structure descriptors</a>,
    <a href="#Garbage_collection">Garbage collection</a>,
    <a href="#Movability">Movability</a>,
    <a href="#Parent_hierarchy">Parent hierarchy</a>,
    <a href="#Allocator_API">Allocator API</a>
</ul>
<li><a href="#Freeing_storage">Freeing storage</a>
<ul>
<li><a href="#Explicit_freeing">Explicit freeing</a>,
    <a href="#Reference_counting">Reference counting</a>,
    <a href="#Real_garbage_collection">(Real) garbage collection</a>
</ul>
<li><a href="#Special_implementations">Special implementations</a>
<ul>
<li><a href="#malloc">malloc</a>,
    <a href="#Locking">Locking</a>,
    <a href="#Retrying">Retrying</a>,
    <a href="#Chunk">Chunk</a>
</ul>
<li><a href="#Standard_implementation">Standard implementation</a>
<li><a href="#PostScript_interpreter_extensions">PostScript interpreter extensions</a>
<ul>
<li><a href="#Refs">Refs (PostScript "objects")</a>,
    <a href="#save_forgetsave_restore">save/.forgetsave/restore</a>,
    <a href="#Stable_allocators">Stable allocators</a>,
    <a href="#Interpreter_GC">Garbage collection</a>
</ul>
</ul>
<li><a href="#Portability">Portability</a>
<ul>
<li><a href="#Structural">Structural</a>
<ul>
<li><a href="#CPU_and_compiler">CPU and compiler</a>,
    <a href="#Library_headers">Library headers</a>,
    <a href="#Cross_platform_APIs">Cross-platform APIs</a>,
    <a href="#Makefiles">Makefiles</a>
</ul>
<li><a href="#Coding">Coding</a>
<ul>
<li><a href="#Explicit_dependencies">Explicit dependencies</a>,
    <a href="#Implicit_dependencies">Implicit dependencies</a>
</ul>
<li><a href="#Platform_specific_code">Platform-specific code</a>
</ul>
<li><a href="#Adding_features_and_options">Adding features and options</a>
<li><a href="#Profiling">Profiling</a>
<ul>
<li><a href="#ProfilingMSVC6">Profiling with Microsoft Developer Studio 6</a>
</ul>
<li><a href="#Troubleshooting">Troubleshooting</a>
</ul></blockquote>

<!-- [1.2 end table of contents] =========================================== -->

<!-- [1.3 begin hint] ====================================================== -->

<p>For other information, see the <a href="Readme.htm">Ghostscript
overview</a>.

<!-- [1.3 end hint] ======================================================== -->

<hr>

<!-- [1.0 end visible header] ============================================== -->

<!-- [2.0 begin contents] ================================================== -->

<h2><a name="Introduction"></a>Introduction</h2>

<p>
This document provides a wealth of information about Ghostscript's
internals, primarily for developers actively working on Ghostscript.  It is
primarily <strong>descriptive</strong>, documenting the way things are; the
companion <a href="C-style.htm">C style guide</a> is primarily
<strong>prescriptive</strong>, documenting what developers should do when
writing new code.

<p>
THIS FILE IS A WORK IN PROGRESS.  MANY SECTIONS ARE PLACE-HOLDERS.

<h2><a name="Architecture"></a>Architecture</h2>

<h3><a name="Design_goals"></a>Design goals</h3>

<p>
Ghostscript has the following high-level design goals (not listed in order
of importance):

<ul>
<li>Functionality
<ul>
<li>Ability to interpret the current PostScript and PDF languages, as
defined (and occasionally, in the case of conflict, as implemented) by
Adobe.
<li>Ability to convert PostScript to and from PDF, comparable to
Adobe products.
<li>Ability to produce output for a wide range of resolutions (from
TV-resolution displays to imagesetters) and color models (black and white,
multilevel gray, bilevel or multi-level RGB and CMYK, 6- or 8-color
inkjet printers, spot color).
</ul>
<li>Performance
<ul>
<li>Ability to render PostScript and PDF with commercial-quality performance
(memory usage, speed, and output quality) on all platforms.
<li>Specifically, ability to render PostScript effectively in embedded
environments with constrained RAM, including the ability to put the code and
supporting data in ROM.
</ul>
<li>Licensing
<ul>
<li>Licensing that supports both the Open Source / Free software communities
and a commercial licensing business.
<li>Freedom from licensing restrictions or fees imposed by third parties.
</ul>
<li>Other
<ul>
<li>Easy source portability to any platform (CPU, operating system, and
development tools) that has an ANSI C compiler.
<li>Support for writing new interpreters and new drivers with no change to
any existing code; specifically, ability to support PCL 5e, PCL 5c, and PCL
XL interpreters, and the ever-changing roster of inkjet printers.
</ul>
</ul>

<p>
These goals often conflict: part of Ghostscript's claim to quality is that
the conflicts have been resolved well.

<h3><a name="Design_principles"></a>Design principles</h3>

<p>
Part of what has kept Ghostscript healthy through many years of major code
revisions and functional expansion is consistent and conscientious adherence
to a set of design principles.  We hope the following list captures the most
important ones.

<h4>Non-preemption</h4>

<p>
Ghostscript is designed to be used as a component.  As such, it must share
its environment with other components.  Therefore, it must not require
ownership of, or make decisions about, inherently shared resources.
Specifically, it must not assume that it can "own" either the locus of
control or the management of the address space.

<p>
Not owning control means that whenever Ghostscript passes control to its
caller, it must do so in a way that doesn't constrain what the caller can do
next.  The caller must be able to call any other piece of software, wait for
an external event, execute another task, etc., without having to worry about
Ghostscript being in an unknown state.  While this is easy to arrange in a
multi-threaded environment (by running Ghostscript in a separate thread),
multi-threading APIs are not well standardized at this time (December 2000),
and may not be implemented efficiently, or at all, on some platforms.
Therefore, Ghostscript must choose between only two options for interacting
with its caller: to <em>return</em>, preserving its own state in data
structures, or to <em>call back</em> through a caller-supplied procedure.
Calling back constrains the client program unacceptably: the callback
procedure only has the options of either returning, or aborting Ghostscript.
In particular, if it wants (for whatever reason) to multi-task Ghostscript
with another program, it cannot do so in general, especially if the other
program also uses callback rather than suspension.  Therefore, Ghostscript
tries extremely hard to return, rather than calling back, for all caller
interaction.  In particular:

<ul>

<li>For callers that want to pass input to Ghostscript piece by piece,
Ghostscript returns with an <b><tt>e_NeedInput</tt></b> code rather than
using a callback.  This allows the caller complete flexibility in its
control structure for managing the source of input.  (It might, for example,
be generating the input dynamically.)

<li>In the future, the same arrangement should be used for input from
<b><tt>stdin</tt></b> and output to <b><tt>stdout</tt></b> and
<b><tt>stderr</tt></b>.

<li>Likewise, scheduling of Ghostscript's own threads (contexts), currently
done with a callback, should be done with suspension.  The Display
Ghostscript project (GNU DGS) is working on this.

</ul>

<p>
The one area where suspension is not feasible with Ghostscript's current
architecture is device output.  Device drivers are called from deep within
the graphics library.  (If Ghostscript were being redesigned from scratch,
we might try to do this with suspension as well, or at least optional
suspension.)

<p>
Not owning management of the address space means that even though
Ghostscript supports garbage collection for its own data, it must not do any
of the things that garbage collection schemes for C often require: it must
not replace 'malloc' and 'free', must not require its clients to use its own
allocator, must not rely on manipulating the read/write status of memory
pages, must not require special compiler or run-time support (e.g., APIs for
scanning the C stack), must not depend on the availability of
multi-threading, and must not take possession of one of a limited number of
timer interrupts.  However, in order not to constrain its own code unduly,
it must also not require using special macros or calls to enter or leave
procedures or assign pointers, and must not constrain the variety of C data
structures any more than absolutely necessary.  It achieves all of these
goals, at the expense of some complexity, some performance cost (mostly for
garbage collection), and some extra manual work required for each structure
type allocated by its allocator.  The details appear in the <a
href="#Memory_management">Memory management</a> section below.

<h4>Multi-instantiability</h4>

<p>
From many years of experience with the benefits of object-oriented design,
we have learned that when the word "the" appears in a software design --
"the" process scheduler, "the" memory manager, "the" output device, "the"
interpreter, "the" stack -- it often flags an area in which the software
will have difficulty adapting to future needs.  For this reason, Ghostscript
attempts to make every internal structure capable of existing in multiple
instances.  For example, Ghostscript's memory manager is not a one-of-a-kind
entity with global state and procedures: it is (or rather they are, since
Ghostscript has multiple memory managers, some of which have multiple
instances) objects with their own state and (virtual) procedures.
Ghostscript's PostScript interpreter has no writable non-local data
(necessary, but not sufficient, to allow multiple instances), and in the
future will be extended to be completely reentrant and instantiable.  The
device driver API is designed to make this easy for drivers as well.  The
graphics library is currently not completely reentrant or instantiable: we
hope this will occur in the future.

<h4>Late configuration binding</h4>

<p>
Ghostscript is designed to make configuration choices as late as possible,
subject to simplicity and performance considerations.  The major binding
times for such choices are compilation, linking, startup, and dynamic.

<ul>

<li>Compilation binds only CPU and compiler characteristics (including data
type size, presence of floating point hardware, and data alignment), and
whether the code will be used for production, debugging, or profiling.

<li>Linking binds the choice of what features and device drivers will be
included in the executable.  (Work is underway to make the choice of drivers
dynamic.)

<li>Startup binds essentially nothing.  Almost every option and parameter
that can appear on the command line can also be changed dynamically.

<li>The selection of output device, all parameters associated with the
device, the selection of debugging printout and self-checking (in debugging
configurations), the macro-allocation of memory, and almost all other
operational parameters are dynamic.

</ul>

<p>
In addition, a number of major implementation decisions are made dynamically
depending on the availability of resources.  For example, Ghostscript
chooses between banded and non-banded rendering depending on memory
availability.

<h3><a name="Large_scale_structure"></a>Large-scale structure</h3>

<p>
At the largest design scale, Ghostscript consists of 4 layers.  Layer N
is allowed to use the facilities of all layers M &lt;= N.

<ol>

<li>The bottom layer is called the <a href="#Substrate">substrate</a>.  It
includes facilities like memory management, streams, fixed-point arithmetic,
and low-level interfaces to the operating system.  The substrate is written
in C, with a little C++ and/or assembler code for some platforms.

<li>The layer above the substrate is the graphics layer.  It consists of two
separate sub-parts.  The graphics layer is written in C.

<ul>

<li>The <a href="#Graphics_library">graphics library</a> manages graphics
state information for, and decomposes and renders 2-D images described
using, a graphics model that is approximately the union of those of
PostScript, PDF, and PCL 5e/5c/XL.

<li>The <a href="#Device_drivers">device drivers</a> are called by the
graphics library to produce actual output.  The graphics library, and all
higher layers, call device driver procedures only through virtual functions.

</ul>

<li>The principal clients of the graphics layer are language interpreters.
Ghostscript as distributed includes the <a
href="#PostScript_interpreter">PostScript interpreter</a>; there are also
interpreters for PCL 5e, PCL 5c, and PCL XL, which are not currently freely
redistributable and are not included in the standard Ghostscript package.
The PostScript interpreter is written partly in C and partly in PostScript.

<li>The <a href="#PDF_interpreter">PDF interpreter</a> is actually a client
of the PostScript interpreter: it is written entirely in PostScript.

</ol>

<p>
The most important interface in Ghostscript is the API between the graphics
library and the device drivers: new printers (and, to a lesser extent,
window systems, displays, plotters, film recorders, and graphics file
formats) come on the scene frequently, and it must be possible to produce
output for them with a minimum of effort and distruption.  This API is the
only one that is extensively documented (see <a
href="Drivers.htm">Drivers.htm</a>) and kept stringently backward-compatible
through successive releases.

<h3><a name="Object_oriented_constructs"></a>Object-oriented constructs</h3>

<p>
Ghostscript makes heavy use of object-oriented constructs, including
analogues of classes, instances, subclassing, and class-associated
procedures.  Since Ghostscript is written in C, not C++, implementing these
constructs requires following coding conventions.  The <a
href="C-style.htm#Objects">"Objects"</a> section of the C style guide
explains these.

<p>
The memory manager API provides run-time type information about each class,
but this information does not include anything about subclassing.  See under
<a href="#Structure_descriptors">Structure descriptors</a> below.

<hr>

<h2><a name="File_roadmap"></a>File roadmap</h2>

<p>
This section of the document provides a roadmap to all of the Ghostscript
source files.

<h3><a name="Substrate"></a>Substrate</h3>

<h4>Runtime Context</h4>

<dl>
<dt>
The libctx provides pointers to memory, stdio, and various other runtime 
portablility services.
<dd>
<a href="../src/gslibctx.h">src/gslibctx.h</a>,
<a href="../src/gslibctx.c">src/gslibctx.c</a>.
</dl>

<h4>Memory manager</h4>

<p>
See <a href="#Memory_management">below</a>.

<h4>Streams</h4>

<dl>

<dt>
Framework, file and string streams:
<dd>
<a href="../src/gsdsrc.c">src/gsdsrc.c</a>,
<a href="../src/gsdsrc.h">src/gsdsrc.h</a>,
<a href="../src/scommon.h">src/scommon.h</a>,
<a href="../src/strmio.c">src/strmio.c</a>,
<a href="../src/strmio.h">src/strmio.h</a>,
<a href="../src/sfxboth.c">src/sfxboth.c</a>,
<a href="../src/sfxfd.c">src/sfxfd.c</a>,
<a href="../src/sfxstdio.c">src/sfxstdio.c</a>,
<a href="../src/sfxcommon.c">src/sfxcommon.c</a>,
<a href="../src/stream.h">src/stream.h</a>,
<a href="../src/stream.c">src/stream.c</a>,
<a href="../src/strimpl.h">src/strimpl.h</a>.

<dt>
Standard filters:
<dd>

<dl>

<dt>
CCITTFax:
<dd>
<a href="../src/scf.h">src/scf.h</a>,
<a href="../src/scfd.c">src/scfd.c</a>,
<a href="../src/scfdgen.c">src/scfdgen.c</a>,
<a href="../src/scfdtab.c">src/scfdtab.c</a>,
<a href="../src/scfe.c">src/scfe.c</a>,
<a href="../src/scfetab.c">src/scfetab.c</a>,
<a href="../src/scfparam.c">src/scfparam.c</a>,
<a href="../src/scfx.h">src/scfx.h</a>.

<dt>
DCT (JPEG):
<dd>
<a href="../src/gsjconf.h">src/gsjconf.h</a>,
<a href="../src/gsjmorec.h">src/gsjmorec.h</a>,
<a href="../src/sdcparam.c">src/sdcparam.c</a>,
<a href="../src/sdcparam.h">src/sdcparam.h</a>,
<a href="../src/sdct.h">src/sdct.h</a>,
<a href="../src/sdctc.c">src/sdctc.c</a>,
<a href="../src/sdctd.c">src/sdctd.c</a>,
<a href="../src/sdcte.c">src/sdcte.c</a>,
<a href="../src/sddparam.c">src/sddparam.c</a>,
<a href="../src/sdeparam.c">src/sdeparam.c</a>,
<a href="../src/sjpeg.h">src/sjpeg.h</a>,
<a href="../src/sjpegc.c">src/sjpegc.c</a>,
<a href="../src/sjpegd.c">src/sjpegd.c</a>,
<a href="../src/sjpege.c">src/sjpege.c</a>.

<dt>
JBIG2:
<a href="../src/sjbig2.h">src/sjbig2.h</a>,
<a href="../src/sjbig2.c">src/sjbig2.c</a>
or
<a href="../src/sjbig2_luratech.h">src/sjbig2_luratech.h</a>,
<a href="../src/sjbig2_luratech.c">src/sjbig2_luratech.c</a>.

<dt>
JPX (JPEG 2000):
<a href="../src/sjpx.h">src/sjpx.h</a>,
<a href="../src/sjpx.c">src/sjpx.c</a>
or
<a href="../src/sjpx_luratech.h">src/sjpx_luratech.h</a>,
<a href="../src/sjpx_luratech.c">src/sjpx_luratech.c</a>.
<dt>
Other compression/decompression:
<dd>
<a href="../src/slzwc.c">src/slzwc.c</a>,
<a href="../src/slzwd.c">src/slzwd.c</a>,
<a href="../src/slzwe.c">src/slzwe.c</a>,
<a href="../src/slzwx.h">src/slzwx.h</a>,
<a href="../src/srld.c">src/srld.c</a>,
<a href="../src/srle.c">src/srle.c</a>,
<a href="../src/srlx.h">src/srlx.h</a>.

<dt>
Other:
<dd>
<a href="../src/sa85d.c">src/sa85d.c</a>,
<a href="../src/sa85d.h">src/sa85d.h</a>,
<a href="../src/sa85x.h">src/sa85x.h</a>,
<a href="../src/sfilter1.c">src/sfilter1.c</a>,
<a href="../src/sfilter2.c">src/sfilter2.c</a>,
<a href="../src/sstring.c">src/sstring.c</a>,
<a href="../src/sstring.h">src/sstring.h</a>.

</dl>

<dt>
Non-standard filters used to implement standard filters:
<dd>
<a href="../src/seexec.c">src/seexec.c</a>,
<a href="../src/sfilter.h">src/sfilter.h</a>,
<a href="../src/shc.c">src/shc.c</a>,
<a href="../src/shc.h">src/shc.h</a>,
<a href="../src/shcgen.c">src/shcgen.c</a>,
<a href="../src/shcgen.h">src/shcgen.h</a>,
<a href="../src/spdiff.c">src/spdiff.c</a>,
<a href="../src/spdiffx.h">src/spdiffx.h</a>,
<a href="../src/spngp.c">src/spngp.c</a>,
<a href="../src/spngpx.h">src/spngpx.h</a>,
<a href="../src/szlibc.c">src/szlibc.c</a>,
<a href="../src/szlibd.c">src/szlibd.c</a>,
<a href="../src/szlibe.c">src/szlibe.c</a>,
<a href="../src/szlibx.h">src/szlibx.h</a>,
<a href="../src/szlibxx.h">src/szlibxx.h</a>.

<dt>
Non-standard filters:
<dd>
<a href="../src/sbcp.c">src/sbcp.c</a>,
<a href="../src/sbcp.h">src/sbcp.h</a>,
<a href="../src/sbhc.c">src/sbhc.c</a>,
<a href="../src/sbhc.h">src/sbhc.h</a>,
<a href="../src/sbtx.h">src/sbtx.h</a>,
<a href="../src/sbwbs.c">src/sbwbs.c</a>,
<a href="../src/sbwbs.h">src/sbwbs.h</a>,
<a href="../src/smd5.c">src/smd5.c</a>,
<a href="../src/smd5.h">src/smd5.h</a>,
<a href="../src/saes.c">src/saes.c</a>,
<a href="../src/saes.h">src/saes.h</a>,
<a href="../src/sarc4.c">src/sarc4.c</a>,
<a href="../src/sarc4.h">src/sarc4.h</a>,
<a href="../src/smtf.c">src/smtf.c</a>,
<a href="../src/smtf.h">src/smtf.h</a>.

<dt>
Internal filters:
<dd>
<a href="../src/siinterp.c">src/siinterp.c</a>,
<a href="../src/siinterp.h">src/siinterp.h</a>,
<a href="../src/siscale.c">src/siscale.c</a>,
<a href="../src/siscale.h">src/siscale.h</a>,
<a href="../src/sidscale.c">src/sidscale.c</a>,
<a href="../src/sidscale.h">src/sidscale.h</a>,
<a href="../src/sisparam.h">src/sisparam.h</a>.

<dt>
Higher-level stream support:
<dd>
<a href="../src/spprint.c">src/spprint.c</a>,
<a href="../src/spprint.h">src/spprint.h</a>,
<a href="../src/spsdf.c">src/spsdf.c</a>,
<a href="../src/spsdf.h">src/spsdf.h</a>,
<a href="../src/srdline.h">src/srdline.h</a>.

</dl>

<h4>Platform-specific code</h4>

See <a href="#Cross_platform_APIs">below</a>.

<h4>Miscellaneous</h4>

<dl>

<dt>
Library top level:
<dd>
<a href="../src/gsinit.c">src/gsinit.c</a>,
<a href="../src/gslib.h">src/gslib.h</a>.

<dt>
Configuration-related:
<dd>
<a href="../src/gconf.c">src/gconf.c</a>,
<a href="../src/gconf.h">src/gconf.h</a>,
<a href="../src/gscdef.c">src/gscdef.c</a>,
<a href="../src/gscdefs.h">src/gscdefs.h</a>,
<a href="../src/gsromfs0.c">src/gsromfs0.c</a>.

<dt>
Arithmetic:
<dd>
<a href="../src/gsfemu.c">src/gsfemu.c</a>,
<a href="../src/gxarith.h">src/gxarith.h</a>,
<a href="../src/gxdda.h">src/gxdda.h</a>,
<a href="../src/gxfarith.h">src/gxfarith.h</a>,
<a href="../src/gxfixed.h">src/gxfixed.h</a>,
<a href="../src/gxfrac.h">src/gxfrac.h</a>.

<dt>
Operating system interface:
<dd>
<a href="../src/gserror.h">src/gserror.h</a>,
<a href="../src/gsexit.h">src/gsexit.h</a>,
<a href="../src/gxstdio.h">src/gxstdio.h</a>,
<a href="../src/gxsync.c">src/gxsync.c</a>,
<a href="../src/gxsync.h">src/gxsync.h</a>.

<dt>
Other:
<dd>
<a href="../src/gsargs.c">src/gsargs.c</a>,
<a href="../src/gsargs.h">src/gsargs.h</a>,
<a href="../src/gserrors.h">src/gserrors.h</a>,
<a href="../src/gsnotify.c">src/gsnotify.c</a>,
<a href="../src/gsnotify.h">src/gsnotify.h</a>,
<a href="../src/gsrect.h">src/gsrect.h</a>,
<a href="../src/gstypes.h">src/gstypes.h</a>,
<a href="../src/gsuid.h">src/gsuid.h</a>,
<a href="../src/gsutil.h">src/gsutil.h</a>,
<a href="../src/gsutil.c">src/gsutil.c</a>,
<a href="../src/gx.h">src/gx.h</a>,
<a href="../src/md5.c">src/md5.c</a>,
<a href="../src/md5.h">src/md5.h</a>,
<a href="../src/md5main.c">src/md5main.c</a>,
<a href="../src/aes.c">src/aes.c</a>,
<a href="../src/aes.h">src/aes.h</a>.

</dl>

<h3><a name="Graphics_library"></a>Graphics library</h3>

<h4><a name="Library_support"></a>Support</h4>

<dl>

<dt>
Bitmap processing:
<dd>
<a href="../src/gsbitcom.c">src/gsbitcom.c</a>,
<a href="../src/gsbitmap.h">src/gsbitmap.h</a>,
<a href="../src/gsbitops.c">src/gsbitops.c</a>,
<a href="../src/gsbitops.h">src/gsbitops.h</a>,
<a href="../src/gsbittab.c">src/gsbittab.c</a>,
<a href="../src/gsbittab.h">src/gsbittab.h</a>,
<a href="../src/gsflip.c">src/gsflip.c</a>,
<a href="../src/gsflip.h">src/gsflip.h</a>,
<a href="../src/gxbitmap.h">src/gxbitmap.h</a>,
<a href="../src/gxbitops.h">src/gxbitops.h</a>,
<a href="../src/gxsample.c">src/gxsample.c</a>,
<a href="../src/gxsample.h">src/gxsample.h</a>.
<a href="../src/gxsamplp.h">src/gxsamplp.h</a>.

<dt>
Functions:
<dd>
<a href="../src/gsfunc.c">src/gsfunc.c</a>,
<a href="../src/gsfunc.h">src/gsfunc.h</a>,
<a href="../src/gsfunc0.c">src/gsfunc0.c</a>,
<a href="../src/gsfunc0.h">src/gsfunc0.h</a>,
<a href="../src/gsfunc3.c">src/gsfunc3.c</a>,
<a href="../src/gsfunc3.h">src/gsfunc3.h</a>,
<a href="../src/gsfunc4.c">src/gsfunc4.c</a>,
<a href="../src/gsfunc4.h">src/gsfunc4.h</a>,
<a href="../src/gxfunc.h">src/gxfunc.h</a>.

<dt>
Parameter lists:
<dd>
<a href="../src/gscparam.c">src/gscparam.c</a>,
<a href="../src/gsparam.c">src/gsparam.c</a>,
<a href="../src/gsparam.h">src/gsparam.h</a>,
<a href="../src/gsparam2.c">src/gsparam2.c</a> (not used),
<a href="../src/gsparams.c">src/gsparams.c</a>,
<a href="../src/gsparams.h">src/gsparams.h</a>,
<a href="../src/gsparamx.c">src/gsparamx.c</a>,
<a href="../src/gsparamx.h">src/gsparamx.h</a>.

<dt>
I/O-related:
<dd>
<a href="../src/gdevpipe.c">src/gdevpipe.c</a>,
<a href="../src/gsfname.c">src/gsfname.c</a>,
<a href="../src/gsfname.h">src/gsfname.h</a>,
<a href="../src/gsio.h">src/gsio.h</a>,
<a href="../src/gsiodev.c">src/gsiodev.c</a>,
<a href="../src/gsiodevs.c">src/gsiodevs.c</a>,
<a href="../src/gsiodisk.c">src/gsiodisk.c</a>,
<a href="../src/gsiorom.c">src/gsiorom.c</a>.
<a href="../src/gsiorom.h">src/gsiorom.h</a>.
<a href="../src/gxiodev.h">src/gxiodev.h</a>.

</dl>

<h4><a name="Paths"></a>Paths</h4>

<dl>

<dt>
Coordinate transformation:
<dd>
<a href="../src/gscoord.c">src/gscoord.c</a>,
<a href="../src/gscoord.h">src/gscoord.h</a>,
<a href="../src/gsmatrix.c">src/gsmatrix.c</a>,
<a href="../src/gsmatrix.h">src/gsmatrix.h</a>,
<a href="../src/gxcoord.h">src/gxcoord.h</a>,
<a href="../src/gxmatrix.h">src/gxmatrix.h</a>.

<dt>
Path building:
<dd>
<a href="../src/gsdps1.c">src/gsdps1.c</a>,
<a href="../src/gspath.c">src/gspath.c</a>,
<a href="../src/gspath.h">src/gspath.h</a>,
<a href="../src/gspath1.c">src/gspath1.c</a>,
<a href="../src/gspath2.h">src/gspath2.h</a>,
<a href="../src/gxpath.c">src/gxpath.c</a>,
<a href="../src/gxpath.h">src/gxpath.h</a>,
<a href="../src/gxpath2.c">src/gxpath2.c</a>,
<a href="../src/gxpcopy.c">src/gxpcopy.c</a>,
<a href="../src/gxpdash.c">src/gxpdash.c</a>,
<a href="../src/gxpflat.c">src/gxpflat.c</a>,
<a href="../src/gzpath.h">src/gzpath.h</a>.

<dt>
Path rendering:
<dd>
<a href="../src/gdevddrw.c">src/gdevddrw.c</a>,
<a href="../src/gdevddrw.h">src/gdevddrw.h</a>,
<a href="../src/gxdtfill.h">src/gxdtfill.h</a>,
<a href="../src/gsdps1.c">src/gsdps1.c</a>,
<a href="../src/gspaint.c">src/gspaint.c</a>,
<a href="../src/gspaint.h">src/gspaint.h</a>,
<a href="../src/gspenum.h">src/gspenum.h</a>,
<a href="../src/gxfill.c">src/gxfill.c</a>,
<a href="../src/gxfill.h">src/gxfill.h</a>,
<a href="../src/gxfillsl.h">src/gxfills1.h</a>,
<a href="../src/gxfilltr.h">src/gxfilltr.h</a>,
<a href="../src/gxfillts.h">src/gxfillts.h</a>,
<a href="../src/gximask.c">src/gximask.c</a>,
<a href="../src/gximask.h">src/gximask.h</a>,
<a href="../src/gxfdrop.c">src/gxdrop.c</a>,
<a href="../src/gxfdrop.h">src/gxdrop.h</a>,
<a href="../src/gxpaint.c">src/gxpaint.c</a>,
<a href="../src/gxpaint.h">src/gxpaint.h</a>,
<a href="../src/gxstroke.c">src/gxstroke.c</a>,
<a href="../src/gzspotan.c">src/gzspotan.c</a>,
<a href="../src/gzspotan.h">src/gzspotan.h</a>.

<dt>
Clipping:
<dd>
See under <a href="#Clipping">Clipping</a> below.

</dl>

<h4><a name="Text"></a>Text</h4>

<dl>

<dt>
Fonts, generic:
<dd>
<a href="../src/gsfont.c">src/gsfont.c</a>,
<a href="../src/gsfont.h">src/gsfont.h</a>,
<a href="../src/gxfcopy.c">src/gxfcopy.c</a>,
<a href="../src/gxfcopy.h">src/gxfcopy.h</a>,
<a href="../src/gxfont.h">src/gxfont.h</a>.

<dt>
Fonts, specific FontTypes:
<dd>
<a href="../src/gsfcid.c">src/gsfcid.c</a>,
<a href="../src/gsfcid2.c">src/gsfcid.c</a>,
<a href="../src/gsfcmap.c">src/gsfcmap.c</a>,
<a href="../src/gsfcmap1.c">src/gsfcmap1.c</a>,
<a href="../src/gsfcmap.h">src/gsfcmap.h</a>,
<a href="../src/gsfont0.c">src/gsfont0.c</a>,
<a href="../src/gsfont0c.c">src/gsfont0.c</a>,
<a href="../src/gxcid.h">src/gxcid.h</a>,
<a href="../src/gxfcid.h">src/gxfcid.h</a>,
<a href="../src/gxfcmap.h">src/gxfcmap.h</a>,
<a href="../src/gxfcmap1.h">src/gxfcmap1.h</a>,
<a href="../src/gxfont0.h">src/gxfont0.h</a>,
<a href="../src/gxfont0c.h">src/gxfont0c.h</a>,
<a href="../src/gxfont1.h">src/gxfont1.h</a>,
<a href="../src/gxfont42.h">src/gxfont42.h</a>,
<a href="../src/gxftype.h">src/gxftype.h</a>,
<a href="../src/gxttf.h">src/gxttf.h</a>.

<dt>
Character rendering + font cache, generic:
<dd>
<a href="../src/gsccode.h">src/gsccode.h</a>,
<a href="../src/gschar.c">src/gschar.c</a>,
<a href="../src/gschar.h">src/gschar.h</a>,
<a href="../src/gscpm.h">src/gscpm.h</a>,
<a href="../src/gsgdata.c">src/gsgdata.c</a>,
<a href="../src/gsgdata.h">src/gsgdata.h</a>,
<a href="../src/gsgcache.c">src/gsgcache.c</a>,
<a href="../src/gsgcache.h">src/gsgcache.h</a>,
<a href="../src/gstext.c">src/gstext.c</a>,
<a href="../src/gstext.h">src/gstext.h</a>,
<a href="../src/gxbcache.c">src/gxbcache.c</a>,
<a href="../src/gxbcache.h">src/gxbcache.h</a>,
<a href="../src/gxccache.c">src/gxccache.c</a>,
<a href="../src/gxccman.c">src/gxccman.c</a>,
<a href="../src/gxchar.c">src/gxchar.c</a>,
<a href="../src/gxchar.h">src/gxchar.h</a>,
<a href="../src/gxfcache.h">src/gxfcache.h</a>,
<a href="../src/gxtext.h">src/gxtext.h</a>.

<dt>
Character rendering, specific FontTypes:
<dd>
<a href="../src/gschar0.c">src/gschar0.c</a>,
<a href="../src/gscrypt1.c">src/gscrypt1.c</a>,
<a href="../src/gscrypt1.h">src/gscrypt1.h</a>,
<a href="../src/gstype1.c">src/gstype1.c</a>,
<a href="../src/gstype1.h">src/gstype1.h</a>,
<a href="../src/gstype2.c">src/gstype2.c</a>,
<a href="../src/gstype42.c">src/gstype42.c</a>,
<a href="../src/gxchrout.c">src/gxchrout.c</a>,
<a href="../src/gxchrout.h">src/gxchrout.h</a>,
<a href="../src/gxhint1.c">src/gxhint1.c</a>,
<a href="../src/gxhint2.c">src/gxhint2.c</a>,
<a href="../src/gxhint3.c">src/gxhint3.c</a>,
<a href="../src/gxhintn.h">src/gxhintn.h</a>,
<a href="../src/gxhintn.c">src/gxhintn.c</a>,
<a href="../src/gxhintn1.c">src/gxhintn1.c</a>,
<a href="../src/gxop1.h">src/gxop1.h</a>,
<a href="../src/gxtype1.c">src/gxtype1.c</a>,
<a href="../src/gxtype1.h">src/gxtype1.h</a>.

</dl>

<h4><a name="Images"></a>Images</h4>

<dl>

<dt>
Buffered API (mostly for PostScript interpreter):
<dd>
<a href="../src/gsimage.c">src/gsimage.c</a>,
<a href="../src/gsimage.h">src/gsimage.h</a>.

<dt>
Generic support:
<dd>
<a href="../src/gsiparam.h">src/gsiparam.h</a>,
<a href="../src/gxiclass.h">src/gxiclass.h</a>,
<a href="../src/gximage.c">src/gximage.c</a>,
<a href="../src/gximage.h">src/gximage.h</a>,
<a href="../src/gxiparam.h">src/gxiparam.h</a>.

<dt>
Type 1 and 4 images:
<dd>

<dl>

<dt>
Setup:
<dd>
<a href="../src/gsiparm4.h">src/gsiparm4.h</a>,
<a href="../src/gximage1.c">src/gximage1.c</a>,
<a href="../src/gximage4.c">src/gximage4.c</a>.

<dt>
Rendering:
<dd>
<a href="../src/gxi12bit.c">src/gxi12bit.c</a>,
<a href="../src/gxi16bit.c">src/gxi16bit.c</a>,
<a href="../src/gxicolor.c">src/gxicolor.c</a>,
<a href="../src/gxidata.c">src/gxidata.c</a>,
<a href="../src/gxifast.c">src/gxifast.c</a>,
<a href="../src/gximono.c">src/gximono.c</a>,
<a href="../src/gxino12b.c">src/gxino12b.c</a>,
<a href="../src/gxino16b.c">src/gxino16b.c</a>,
<a href="../src/gxipixel.c">src/gxipixel.c</a>,
<a href="../src/gxiscale.c">src/gxiscale.c</a>.

</dl>

<dt>
Type 2 images (Display PostScript):
<dd>
<a href="../src/gsiparm2.h">src/gsiparm2.h</a>,
<a href="../src/gximage2.c">src/gximage2.c</a>.

<dt>
Type 3 images:
<dd>
<a href="../src/gsipar3x.h">src/gsipar3x.h</a>,
<a href="../src/gsiparm3.h">src/gsiparm3.h</a>,
<a href="../src/gximag3x.c">src/gximag3x.c</a>,
<a href="../src/gximag3x.h">src/gximag3x.h</a>,
<a href="../src/gximage3.c">src/gximage3.c</a>,
<a href="../src/gximage3.h">src/gximage3.h</a>.

<dt>
Other:
<dd>
<a href="../src/gsimpath.c">src/gsimpath.c</a>,
<a href="../src/simscale.c">src/simscale.c</a>,
<a href="../src/simscale.h">src/simscale.h</a>.
.

</dl>

<h4><a name="Paint"></a>Paint</h4>

<p>
Ghostscript uses 4 internal representations of color.  We list them here in
the order in which they occur in the rendering pipeline.

<ol>

<li>Clients of the graphics library normally specify colors using the
<em>client color</em> structure (<b><tt>gs_client_color</tt></b>, defined in
<a href="../src/gsccolor.h">src/gsccolor.h</a>), consisting of one or more
numeric values and/or a pointer to a Pattern instance.  This corresponds
directly to the values that would be passed to the PostScript
<b><tt>setcolor</tt></b> operator: one or more (floating-point) numeric
components and/or a Pattern.  Client colors are interpreted relative to a
color space (<b><tt>gs_color_space</tt></b>, defined in <a
href="../src/gscspace.h">src/gscspace.h</a> and <a
href="../src/gxcspace.h">src/gxcspace.h</a>, with specific color spaces
defined in other files).  Client colors do not explicitly reference the
color space in which they are are interpreted: <b><tt>setcolor</tt></b> uses
the color space in the graphics state, while images and shadings explicitly
specify the color space to be used.

<li>For ordinary non-Pattern colors, the first step in color rendering
reduces a client color to a <em>concrete</em> color -- a set of values in a
color space that corresponds to the device's color model (except for
possible conversions between DeviceGray, DeviceRGB, and DeviceCMYK),
together with an identification of the associated color space.  (The
confusion here between color spaces and color models will have to be cleaned
up when we implement native Separation/DeviceN colors.)  Concrete colors are
like the numeric values in a client color, except that they are represented
by arrays of <b><tt>frac</tt></b> values (defined in <a
href="../src/gxfrac.h">src/gxfrac.h</a>) rather than floats.  The procedure
for this step is the virtual <b><tt>concretize_color</tt></b> and
<b><tt>concrete_space</tt></b> procedures in the (original) color space.
This step reduces Indexed colors, CIEBased colors, and Separation and
DeviceN colors that use the alternate space.

<li>The final step requires mapping a concrete color to the device's color
model, done by procedures in <a href="../src/gxcmap.c">src/gxcmap.c</a>.
These procedures combine the following three conceptual sub-steps:

<ul>

<li>A possible mapping between Device color spaces, possibly involving black
generation and undercolor removal.  The non-trivial cases are implemented in
<a href="../src/gxdcconv.c">src/gxdcconv.c</a>.

<li>Application of the transfer function(s) (done in-line).

<li>Halftoning if necessary: see below.

</ul>

The result is called (inappropriately) a <em>device color</em>
(<b><tt>gx_device_color</tt></b>, defined in <a
href="../src/gsdcolor.h">src/gsdcolor.h</a> and <a
href="../src/gxdcolor.h">src/gxdcolor.h</a>).  For ordinary non-Pattern
colors, a device color is either a pure color, or a halftone.  The device
and color model associated with a device color are implicit.  The procedure
for this step is the virtual <b><tt>remap_concrete_color</tt></b> procedure
in the color space.

<li>The pure colors that underlie a device color are opaque <em>pixel
values</em> defined by the device (misnamed <b><tt>gx_color_index</tt></b>,
defined in <a href="../src/gscindex.h">src/gscindex.h</a>).  The device with
which they are associated is implicit.  Although the format and
interpretation of a pixel value are known only to the device, the device's
color model and color representation capabilities are public, defined by a
<b><tt>gx_color_info</tt></b> structure stored in the device (defined in <a
href="../src/gxdevcli.h">src/gxdevcli.h</a>).  Virtual procedures of the
device driver map between pixel values and RGB or CMYK.  (This area is
untidy and will need to be cleaned up when we implement native
Separation/DeviceN colors.)

</ol>

<p>
Steps 2 and 3 are normally combined into a single step for efficiency, as
the <b><tt>remap_color</tt></b> virtual procedure in a color space.

<p>
Using a device color to actually paint pixels requires a further step called
<em>color loading</em>, implemented by the <b><tt>load</tt></b> virtual
procedure in the device color.  This does nothing for pure colors, but loads
the caches for halftones and Patterns.

<p>
All of the above steps -- concretizing, mapping to a device color, and color
loading -- are done as late as possible, normally not until the color is
actually needed for painting.

<p>
All painting operations (fill, stroke, imagemask/show) eventually call a
virtual procedure in the device color, either <b><tt>fill_rectangle</tt></b>
or <b><tt>fill_mask</tt></b> to actually paint pixels.  For rectangle fills,
pure colors call the device's <b><tt>fill_rectangle</tt></b> procedure;
halftones and tiled Patterns call the device's
<b><tt>tile_rectangle</tt></b>; shaded Patterns, and painting operations
that involve a RasterOp, do something more complicated.

<dl>

<dt>
Color specification:
<dd>
<a href="../src/gsccolor.h">src/gsccolor.h</a>,
<a href="../src/gscolor.c">src/gscolor.c</a>,
<a href="../src/gscolor.h">src/gscolor.h</a>,
<a href="../src/gscolor1.c">src/gscolor1.c</a>,
<a href="../src/gscolor1.h">src/gscolor1.h</a>,
<a href="../src/gscolor2.c">src/gscolor2.c</a>,
<a href="../src/gscolor2.h">src/gscolor2.h</a>,
<a href="../src/gscolor3.c">src/gscolor3.c</a>,
<a href="../src/gscolor3.h">src/gscolor3.h</a>,
<a href="../src/gshsb.c">src/gshsb.c</a>,
<a href="../src/gshsb.h">src/gshsb.h</a>,
<a href="../src/gxcolor2.h">src/gxcolor2.h</a>,
<a href="../src/gxcvalue.h">src/gxcvalue.h</a>.

<dt>
Color spaces:
<dd>
<a href="../src/gscdevn.c">src/gscdevn.c</a>,
<a href="../src/gscdevn.h">src/gscdevn.h</a>,
<a href="../src/gscie.c">src/gscie.c</a>,
<a href="../src/gscie.h">src/gscie.h</a>,
<a href="../src/gscpixel.c">src/gscpixel.c</a>,
<a href="../src/gscpixel.h">src/gscpixel.h</a>,
<a href="../src/gscscie.c">src/gscscie.c</a>,
<a href="../src/gscsepnm.h">src/gscsepnm.h</a>,
<a href="../src/gscsepr.c">src/gscsepr.c</a>,
<a href="../src/gscsepr.h">src/gscsepr.h</a>,
<a href="../src/gscspace.c">src/gscspace.c</a>,
<a href="../src/gscspace.h">src/gscspace.h</a>,
<a href="../src/gscssub.c">src/gscssub.c</a>,
<a href="../src/gscssub.h">src/gscssub.h</a>,
<a href="../src/gxcdevn.h">src/gxcdevn.h</a>,
<a href="../src/gxcie.h">src/gxcie.h</a>,
<a href="../src/gxcspace.h">src/gxcspace.h</a>.

<dt>
Color mapping:
<dd>
<a href="../src/gsciemap.c">src/gsciemap.c</a>,
<a href="../src/gscindex.h">src/gscindex.h</a>,
<a href="../src/gscrd.c">src/gscrd.c</a>,
<a href="../src/gscrd.h">src/gscrd.h</a>,
<a href="../src/gscrdp.c">src/gscrdp.c</a>,
<a href="../src/gscrdp.h">src/gscrdp.h</a>,
<a href="../src/gscsel.h">src/gscsel.h</a>,
<a href="../src/gsdcolor.h">src/gsdcolor.h</a>,
<a href="../src/gxcindex.h">src/gxcindex.h</a>,
<a href="../src/gxcmap.c">src/gxcmap.c</a>,
<a href="../src/gxcmap.h">src/gxcmap.h</a>,
<a href="../src/gxctable.c">src/gxctable.c</a>,
<a href="../src/gxctable.h">src/gxctable.h</a>,
<a href="../src/gxdcconv.c">src/gxdcconv.c</a>,
<a href="../src/gxdcconv.h">src/gxdcconv.h</a>,
<a href="../src/gxdcolor.c">src/gxdcolor.c</a>,
<a href="../src/gxdcolor.h">src/gxdcolor.h</a>,
<a href="../src/gxdevndi.c">src/gevndi.c</a>,
<a href="../src/gxdevndi.h">src/gxdevndi.h</a>,
<a href="../src/gxdither.h">src/gxdither.h</a>,
<a href="../src/gxfmap.h">src/gxfmap.h</a>,
<a href="../src/gxlum.h">src/gxlum.h</a>,
<a href="../src/gxtmap.h">src/gxtmap.h</a>.

<p>
ICC profiles are in some ways a special case of color mapping, but are
not standard in PostScript.

<dt>
<dd>
<a href="../src/gsicc.c">src/gsicc.c</a>,
<a href="../src/gsicc.h">src/gsicc.h</a>,

<p>
The following files provide a callback mechanism to allow a client program 
to specify a special case alternate tint transforms for Separation and DeviceN 
color spaces. Among other uses this can be used to provide special handling for
PANTONE colors.
<dt>
<dd>
<a href="../src/gsnamecl.c">src/gsnamecl.c</a>,
<a href="../src/gsnamecl.h">src/gsnamecl.h</a>,
<a href="../src/gsncdummy.c">src/gsncdummy.c</a>,
<a href="../src/gsncdummy.h">src/gsncdummy.h</a>,
<a href="../src/zncdummy.c">src/zncdummy.c</a>,

</dl>

<p>
Ghostscript represents halftones internally by "whitening orders" --
essentially, arrays of arrays of bit coordinates within a halftone cell,
specifying which bits are inverted to get from halftone level K to level
K+1.  The code does support all of the PostScript halftone types, but they
are all ultimately reduced to whitening orders.

<p>
Threshold arrays, the more conventional representation of halftones, can be
mapped to whitening orders straightforwardly; however, whitening orders can
represent non-monotonic halftones (halftones where the bits turned on for
level K+1 don't necessarily include all the bits turned on for level K),
while threshold arrays cannot.  On the other hand, threshold arrays allow
rapid conversion of images (using a threshold comparison for each pixel)
with no additional space, while whitening orders do not: they require
storing the rendered halftone cell for each possible level as a bitmap.

<p>
Ghostscript uses two distinct types of rendered halftones -- that is, the
bitmap(s) that represent a particular level.

<ul>

<li>Binary halftones.  The rendered halftone is a single bit plane; each bit
selects one of two pure colors.  These are fast but limited: they are used
for monochrome output devices, or for color devices in those cases where
only two distinct colors are involved in a halftone (e.g., a pure cyan shade
on a CMYK device).  The device color for a binary halftone stores a pointer
to the halftone bitmap, and the two pure colors.

<li>Multi-plane halftones.  Internally, each plane is rendered individually.
Since there isn't enough room to store all 2^N pure colors, multi-plane
halftones only store the scaled values for the individual components; the
halftone renderer maps these to the pure colors on the fly, then combines
the planes to assemble an N-bit index into the list of colors for each
pixel, and stores the color into the fully rendered halftone.

</ul>

<p>
The halftone level for rendering a color is computed in <a
href="../src/gxdevndi.c">src/gxdevndi.c</a>; the actual halftone mask or
tile is computed either in <a href="../src/gxcht.c">src/gxcht.c</a> (for
multi-plane halftones), or in <a href="../src/gxht.c">src/gxht.c</a> and <a
href="../src/gxhtbit.c">src/gxhtbit.c</a> (for binary halftones).

<dl>

<dt>
Halftoning:
<dd>
<a href="../src/gsht.c">src/gsht.c</a>,
<a href="../src/gsht.h">src/gsht.h</a>,
<a href="../src/gsht1.c">src/gsht1.c</a>,
<a href="../src/gsht1.h">src/gsht1.h</a>,
<a href="../src/gshtscr.c">src/gshtscr.c</a>,
<a href="../src/gshtx.c">src/gshtx.c</a>,
<a href="../src/gshtx.h">src/gshtx.h</a>,
<a href="../src/gxcht.c">src/gxcht.c</a>,
<a href="../src/gxdht.h">src/gxdht.h</a>,
<a href="../src/gxdhtres.h">src/gxdhtres.h</a>,
<a href="../src/gxht.c">src/gxht.c</a>,
<a href="../src/gxht.h">src/gxht.h</a>,
<a href="../src/gxhtbit.c">src/gxhtbit.c</a>,
<a href="../src/gxhttile.h">src/gxhttile.h</a>,
<a href="../src/gxhttype.h">src/gxhttype.h</a>,
<a href="../src/gzht.h">src/gzht.h</a>.

<dt>
Well tempered screening:
<dd>
<a href="../src/gswts.h">src/gswts.h</a>,
<a href="../src/gswts.c">src/gswts.c</a>,
<a href="../src/gxwts.h">src/gxwts.h</a>,
<a href="../src/gxwts.c">src/gxwts.c</a>,
<a href="../src/wtsimdi.c">src/wtsimdi.c</a>.
</dl>

<p>
Pattern colors (tiled patterns and shadings) each use a slightly different
approach from solid colors.

<p>
The device color for a tiled (PatternType 1) pattern contains a pointer to a
pattern instance, plus (for uncolored patterns) the device color to be
masked.  The pattern instance includes a procedure that actually paints the
pattern if the pattern is not in the cache.  For the PostScript interpreter,
this procedure returns an <b><tt>e_RemapColor</tt></b> exception code: this
eventually causes the interpreter to run the pattern's PaintProc, loading
the rendering into the cache, and then re-execute the original drawing
operator.

<dl>

<dt>
Patterns:
<dd>
<a href="../src/gspcolor.c">src/gspcolor.c</a>,
<a href="../src/gspcolor.h">src/gspcolor.h</a>,
<a href="../src/gsptype1.c">src/gsptype1.c</a>,
<a href="../src/gsptype1.h">src/gsptype1.h</a>,
<a href="../src/gxp1fill.c">src/gxp1fill.c</a>,
<a href="../src/gxp1impl.h">src/gxp1impl.h</a>,
<a href="../src/gxpcache.h">src/gxpcache.h</a>,
<a href="../src/gxpcmap.c">src/gxpcmap.c</a>,
<a href="../src/gxpcolor.h">src/gxpcolor.h</a>.

</dl>

<p>
The device color for a shading (PatternType 2) pattern also contains a
pointer to a pattern instance.  Shadings are not cached: painting with a
shading runs the shading algorithm every time.

<dl>

<dt>
Shading:
<dd>
<a href="../src/gsptype2.c">src/gsptype2.c</a>,
<a href="../src/gsptype2.h">src/gsptype2.h</a>,
<a href="../src/gsshade.c">src/gsshade.c</a>,
<a href="../src/gsshade.h">src/gsshade.h</a>,
<a href="../src/gxshade.c">src/gxshade.c</a>,
<a href="../src/gxshade.h">src/gxshade.h</a>,
<a href="../src/gxshade1.c">src/gxshade1.c</a>,
<a href="../src/gxshade4.c">src/gxshade4.c</a>,
<a href="../src/gxshade4.h">src/gxshade4.h</a>,
<a href="../src/gxshade6.c">src/gxshade6.c</a>,
<a href="../src/gscicach.h">src/gscicach.h</a>,
<a href="../src/gscicach.c">src/gscicach.c</a>.

</dl>

<p> In addition to the PostScript graphics model, Ghostscript supports RasterOp, 
  a weak form of alpha channel, and eventually the full PDF 1.4 transparency model. 
  The implemention of these facilities is quite slipshod and scattered: only RasterOp 
  is really implemented fully. There is a general compositing architecture, but 
  it is hardly used at all, and in particular is not used for RasterOp. It is 
  used for implementation of the general support for overprint and overprint mode.
<dl>

<dt>
Compositing architecture:
<dd>
<a href="../src/gscompt.h">src/gscompt.h</a>,
<a href="../src/gxcomp.h">src/gxcomp.h</a>.

<dt>
RasterOp:
<dd>
<a href="../src/gdevdrop.c">src/gdevdrop.c</a>,
<a href="../src/gdevrops.c">src/gdevrops.c</a>,
<a href="../src/gsnorop.c">src/gsnorop.c</a>,
<a href="../src/gsrop.c">src/gsrop.c</a>,
<a href="../src/gsrop.h">src/gsrop.h</a>,
<a href="../src/gsropt.h">src/gsropt.h</a>,
<a href="../src/gsroptab.c">src/gsroptab.c</a>,
<a href="../src/gxdevrop.h">src/gxdevrop.h</a>.

<dt>
Alpha channel and compositing:
<dd>
<a href="../src/gsalpha.c">src/gsalpha.c</a>,
<a href="../src/gsalpha.h">src/gsalpha.h</a>,
<a href="../src/gsalphac.c">src/gsalphac.c</a>,
<a href="../src/gsalphac.h">src/gsalphac.h</a>,
<a href="../src/gsdpnext.h">src/gsdpnext.h</a>,
<a href="../src/gxalpha.h">src/gxalpha.h</a>.

<dt>
Advanced transparency:
<dd>
<a href="../src/gstparam.h">src/gstparam.h</a>,
<a href="../src/gstrans.c">src/gstrans.c</a>,
<a href="../src/gstrans.h">src/gstrans.h</a>,
<a href="../src/gxblend.c">src/gxblend.c</a>,
<a href="../src/gxblend.h">src/gxblend.h</a>,
<a href="../src/gdevp14.c">src/gdevp14.c</a>,
<a href="../src/gdevp14.h">src/gdevp14.h</a>,
<a href="../src/gdevpnga.c">src/gdevpnga.c</a>.

<dt>
Overprint and Overprint mode:
<dd>
<a href="../src/gsovrc.c">src/gsovrc.c</a>,
<a href="../src/gsovrc.h">src/gsovrc.h</a>,
<a href="../src/gxoprect.c">src/gxoprect.c</a>,
<a href="../src/gxoprect.h">src/gxoprect.h</a>.
There is support for both overprint and overprint mode. There is a general
compositor based implementation of these features for all devices. In addition,
the memory devices implement a higher speed set of special fill routines to
improve performance for printer based devices.

</dl>

<h4><a name="Clipping"></a>Clipping</h4>

<p>
The Ghostscript graphics library implements clipping by inserting a clipping
device in the device pipeline.  The clipping device modifies all drawing
operations to confine them to the clipping region.

<p>
The library supports three different kinds of clipping:

<dl>

<dt>
Region/path clipping
<dd>
This corresponds to the PostScript concept of a clipping path.  The clipping
region is specified either by a list of rectangles (subject to the
constraints documented in <a href="../src/gxcpath.h">src/gxcpath.h</a>), or
by a path that is converted to such a list of rectangles.

<dt>
Stationary mask clipping
<dd>
This corresponds to the mask operand of a PostScript ImageType 3 image.  The
clipping region is specified by a bitmap and an (X,Y) offset in the
coordinate space.

<dt>
Tiled mask clipping
<dd>
This corresponds to the region painted by a PostScript Pattern, for the case
where the Pattern does not completely cover its bounding box but the
combined transformation matrix has no skew or non-orthogonal rotation (i.e.,
XStep and YStep map respectively to (X,0) and (0,Y) or vice versa).  The
clipping region is specified by a bitmap and an (X,Y) offset in the
coordinate space, and is replicated indefinitely in both X and Y.

</dl>

<p>
Note that simply scan-converting a clipping path in the usual way does not
produce a succession of rectangles that can simply be stored as the list for
region-based clipping: in general, the rectangles do not satisfy the
constraint for rectangle lists specified in <a
href="../src/gxcpath.h">src/gxcpath.h</a>, since they may overlap in X, Y,
or both.  A non-trivial "clipping list accumulator" device is needed to
produce a rectangle list that does satisfy the constraint.

<dl>

<dt>
Clipping support:
<dd>
<a href="../src/gxclip.c">src/gxclip.c</a>,
<a href="../src/gxclip.h">src/gxclip.h</a>.

<dt>
Region/path clipping:
<dd>
<a href="../src/gxcpath.c">src/gxcpath.c</a>,
<a href="../src/gxcpath.h">src/gxcpath.h</a>,
<a href="../src/gzcpath.h">src/gzcpath.h</a>.

<dt>
Clipping list accumulator:
<dd>
<a href="../src/gxacpath.c">src/gxacpath.c</a>,
<a href="../src/gzacpath.h">src/gzacpath.h</a>.

<dt>
Mask clipping support:
<dd>
<a href="../src/gxmclip.c">src/gxmclip.c</a>,
<a href="../src/gxmclip.h">src/gxmclip.h</a>.

<dt>
Stationary mask clipping:
<dd>
<a href="../src/gxclipm.c">src/gxclipm.c</a>,
<a href="../src/gxclipm.h">src/gxclipm.h</a>.

<dt>
Tiled mask clipping:
<dd>
<a href="../src/gxclip2.c">src/gxclip2.c</a>,
<a href="../src/gxclip2.h">src/gxclip2.h</a>.

</dl>

<h4><a name="Other_graphics"></a>Other graphics</h4>

<dl>

<dt>
Miscellaneous graphics state:
<dd>
<a href="../src/gsclipsr.c">src/gsclipsr.c</a>,
<a href="../src/gsclipsr.h">src/gsclipsr.h</a>,
<a href="../src/gsdps.c">src/gsdps.c</a>,
<a href="../src/gsdps.h">src/gsdps.h</a>,
<a href="../src/gsdps1.c">src/gsdps1.c</a>,
<a href="../src/gsistate.c">src/gsistate.c</a>,
<a href="../src/gsline.c">src/gsline.c</a>,
<a href="../src/gsline.h">src/gsline.h</a>,
<a href="../src/gslparam.h">src/gslparam.h</a>,
<a href="../src/gsstate.c">src/gsstate.c</a>,
<a href="../src/gsstate.h">src/gsstate.h</a>,
<a href="../src/gstrap.c">src/gstrap.c</a>,
<a href="../src/gstrap.h">src/gstrap.h</a>,
<a href="../src/gxclipsr.h">src/gxclipsr.h</a>,
<a href="../src/gxistate.h">src/gxistate.h</a>,
<a href="../src/gxline.h">src/gxline.h</a>,
<a href="../src/gxstate.h">src/gxstate.h</a>,
<a href="../src/gzline.h">src/gzline.h</a>,
<a href="../src/gzstate.h">src/gzstate.h</a>.

</dl>

<h4><a name="FAPI_support_gx"></a>Font API support</h4>

<dl>

<dt>
UFST bridge:
<dd>
<a href="../src/gxfapiu.c">src/gxfapiu.c</a>,
<a href="../src/gxfapiu.h">src/gxfapiu.h</a>.
</dl>


<h4><a name="Driver_support"></a>Driver support</h4>

<dl>

<dt>
Generic driver support:
<dd>
<a href="../src/gdevdcrd.c">src/gdevdcrd.c</a>,
<a href="../src/gdevdcrd.h">src/gdevdcrd.h</a>,
<a href="../src/gdevdsha.c">src/gdevdsha.c</a>,
<a href="../src/gdevemap.c">src/gdevemap.c</a>,
<a href="../src/gsdevice.c">src/gsdevice.c</a>,
<a href="../src/gsdevice.h">src/gsdevice.h</a>,
<a href="../src/gsdparam.c">src/gsdparam.c</a>,
<a href="../src/gsxfont.h">src/gsxfont.h</a>,
<a href="../src/gxdevbuf.h">src/gxdevbuf.h</a>,
<a href="../src/gxdevcli.h">src/gxdevcli.h</a>,
<a href="../src/gxdevice.h">src/gxdevice.h</a>,
<a href="../src/gxrplane.h">src/gxrplane.h</a>,
<a href="../src/gxxfont.h">src/gxxfont.h</a>.

<dt>
Accessing rendered bits:
<dd>
<a href="../src/gdevdbit.c">src/gdevdbit.c</a>,
<a href="../src/gdevdgbr.c">src/gdevdgbr.c</a>,
<a href="../src/gxbitfmt.h">src/gxbitfmt.h</a>,
<a href="../src/gxgetbit.h">src/gxgetbit.h</a>.

<dt>
"Printer" driver support:
<dd>
<a href="../src/gdevmeds.c">src/gdevmeds.c</a>,
<a href="../src/gdevmeds.h">src/gdevmeds.h</a>,
<a href="../src/gdevppla.c">src/gdevppla.c</a>,
<a href="../src/gdevppla.h">src/gdevppla.h</a>,
<a href="../src/gdevprn.c">src/gdevprn.c</a>,
<a href="../src/gdevprn.h">src/gdevprn.h</a>,
<a href="../src/gdevprna.c">src/gdevprna.c</a>,
<a href="../src/gdevprna.h">src/gdevprna.h</a>,
<a href="../src/gxband.h">src/gxband.h</a>,
<a href="../src/gxpageq.c">src/gxpageq.c</a>,
<a href="../src/gxpageq.h">src/gxpageq.h</a>.

<dt>
High-level device support:
<dd>
<a href="../src/gdevvec.c">src/gdevvec.c</a>,
<a href="../src/gdevvec.h">src/gdevvec.h</a>,
<a href="../src/gxhldevc.c">src/gxhldevc.c</a>,
<a href="../src/gxhldevc.h">src/gxhldevc.h</a>.

<dt>
Banding:
<dd>
<a href="../src/gxclbits.c">src/gxclbits.c</a>,
<a href="../src/gxcldev.h">src/gxcldev.h</a>,
<a href="../src/gxclfile.c">src/gxclfile.c</a>,
<a href="../src/gxclimag.c">src/gxclimag.c</a>,
<a href="../src/gxclio.h">src/gxclio.h</a>,
<a href="../src/gxclist.c">src/gxclist.c</a>,
<a href="../src/gxclist.h">src/gxclist.h</a>,
<a href="../src/gxcllzw.c">src/gxcllzw.c</a>,
<a href="../src/gxclmem.c">src/gxclmem.c</a>,
<a href="../src/gxclmem.h">src/gxclmem.h</a>,
<a href="../src/gxclpage.c">src/gxclpage.c</a>,
<a href="../src/gxclpage.h">src/gxclpage.h</a>,
<a href="../src/gxclpath.c">src/gxclpath.c</a>,
<a href="../src/gxclpath.h">src/gxclpath.h</a>,
<a href="../src/gxclrast.c">src/gxclrast.c</a>,
<a href="../src/gxclread.c">src/gxclread.c</a>,
<a href="../src/gxclrect.c">src/gxclrect.c</a>,
<a href="../src/gxclthrd.c">src/gxclthrd.c</a>,
<a href="../src/gxclthrd.h">src/gxclthrd.h</a>,
<a href="../src/gxclutil.c">src/gxclutil.c</a>,
<a href="../src/gxclzlib.c">src/gxclzlib.c</a>,
<a href="../src/gxdhtserial.c">src/gxdhtserial.c</a>,
<a href="../src/gxdhtserial.h">src/gxdhtserial.h</a>,
<a href="../src/gsserial.c">src/gsserial.c</a>,
<a href="../src/gsserial.h">src/gsserial.h</a>.

<dt>
Color mapping:
<dd>
<a href="../src/gdevimdi.c">src/gdevimdi.c</a>.

</dl>

<h4><a name="Visual_trace"></a>Visual Trace</h4>

<dl>

<dt>
Visual Trace support :
<dd>
<a href="../src/vdtrace.h">src/vdtrace.h</a>,
<a href="../src/vdtrace.c">src/vdtrace.c</a>.
</dl>

See <a href="Lib.htm">doc/Lib.htm</a> for extensive documentation on
Visual Trace instructions.


<h3><a name="Device_drivers"></a>Device drivers</h3>

<p>
See <a href="Drivers.htm">doc/Drivers.htm</a> for extensive documentation on
the interface between the core code and drivers.

<p>
The driver API includes high-level (path / image / text), mid-level
(polygon), and low-level (rectangle / raster) operations.  Most devices
implement only the low-level operations, and let generic code break down the
high-level operations.  However, some devices produce high-level output, and
therefore must implement the high-level operations.

<h4><a name="Internal_devices"></a>Internal devices</h4>

<p>
There are a number of "devices" that serve internal purposes.  Some of these
are meant to be real rendering targets; others are intended for use in
device pipelines.  The rendering targets are:

<dl>

<dt>
Memory devices, depth-independent:
<dd>
<a href="../src/gdevmem.c">src/gdevmem.c</a>,
<a href="../src/gdevmem.h">src/gdevmem.h</a>,
<a href="../src/gdevmpla.c">src/gdevmpla.c</a>,
<a href="../src/gdevmpla.h">src/gdevmpla.h</a>,
<a href="../src/gdevmrop.h">src/gdevmrop.h</a>,
<a href="../src/gsdevmem.c">src/gsdevmem.c</a>,
<a href="../src/gxdevmem.h">src/gxdevmem.h</a>.

<dt>
Memory devices, specific depths:
<dd>
<a href="../src/gdevm1.c">src/gdevm1.c</a>,
<a href="../src/gdevm2.c">src/gdevm2.c</a>,
<a href="../src/gdevm4.c">src/gdevm4.c</a>,
<a href="../src/gdevm8.c">src/gdevm8.c</a>,
<a href="../src/gdevm16.c">src/gdevm16.c</a>,
<a href="../src/gdevm24.c">src/gdevm24.c</a>,
<a href="../src/gdevm32.c">src/gdevm32.c</a>,
<a href="../src/gdevm40.c">src/gdevm40.c</a>,
<a href="../src/gdevm48.c">src/gdevm48.c</a>,
<a href="../src/gdevm56.c">src/gdevm56.c</a>,
<a href="../src/gdevm64.c">src/gdevm64.c</a>,
<a href="../src/gdevmr1.c">src/gdevmr1.c</a>,
<a href="../src/gdevmr2n.c">src/gdevmr2n.c</a>,
<a href="../src/gdevmr8n.c">src/gdevmr8n.c</a>.

<dt>
Alpha-related devices:
<dd>
<a href="../src/gdevabuf.c">src/gdevabuf.c</a>.

<dt>
Other devices:
<dd>
<a href="../src/gdevdflt.c">src/gdevdflt.c</a>,
<a href="../src/gdevhit.c">src/gdevhit.c</a>,
<a href="../src/gdevmrun.c">src/gdevmrun.c</a>,
<a href="../src/gdevmrun.h">src/gdevmrun.h</a>,
<a href="../src/gdevplnx.c">src/gdevplnx.c</a>,
<a href="../src/gdevplnx.h">src/gdevplnx.h</a>.
</dl>

<p>
The forwarding devices meant for use in pipelines are:

<dl>

<dt>
The bounding box device:
<dd>
<a href="../src/gdevbbox.h">src/gdevbbox.h</a>,
<a href="../src/gdevbbox.c">src/gdevbbox.c</a>.

<dt>
Clipping devices:
<dd>
See under <a href="#Clipping">Clipping</a> above.

<dt>
Device filter stack:
<dd>
<a href="../src/gsdfilt.c">src/gsdfilt.c</a>,
<a href="../src/gsdfilt.h">src/gsdfilt.h</a>.

<dt>
Other devices:
<dd>
<a href="../src/gdevnfwd.c">src/gdevnfwd.c</a>.

</dl>

<h4><a name="PS_and_PDF_writers"></a>PostScript and PDF writers</h4>

<p>
Because PostScript and PDF have the same graphics model, lexical syntax, and
stack-based execution model, the drivers that produce PostScript and PDF
output share a significant amount of support code.  In the future, the
PostScript output driver should be replaced with a slightly modified version
of the PDF driver, since the latter is far more sophisticated (in
particular, it has extensive facilities for image compression and for
handling text and fonts).

<p>
The PDF code for handling text and fonts is complex and fragile.  A major
rewrite in June 2002 was intended to make it more robust and somewhat easier
to understand, but also increased its size by about 40%, contrary to the
expectation that it would shrink.  Currently both sets of code are in the
code base, with compatible APIs, selected by a line in <a
href="../src/devs.mak">src/devs.mak</a>.

<dl>

<dt>
Shared support:
<dd>

<dl>
Writing fonts:
<dd>
<a href="../src/gdevpsf.h">src/gdevpsf.h</a>,
<a href="../src/gdevpsf1.c">src/gdevpsf1.c</a>,
<a href="../src/gdevpsf2.c">src/gdevpsf2.c</a>,
<a href="../src/gdevpsfm.c">src/gdevpsfm.c</a>,
<a href="../src/gdevpsft.c">src/gdevpsft.c</a>,
<a href="../src/gdevpsfu.c">src/gdevpsfu.c</a>,
<a href="../src/gdevpsfx.c">src/gdevpsfx.c</a>,
<a href="../src/gscedata.c">src/gscedata.c</a>,
<a href="../src/gscedata.h">src/gscedata.h</a>,
<a href="../src/gscencs.c">src/gscencs.c</a>,
<a href="../src/gscencs.h">src/gscencs.h</a>.

<dt>
Other:
<dd>
<a href="../src/gdevpsdf.h">src/gdevpsdf.h</a>,
<a href="../src/gdevpsdi.c">src/gdevpsdi.c</a>,
<a href="../src/gdevpsdp.c">src/gdevpsdp.c</a>,
<a href="../src/gdevpsds.c">src/gdevpsds.c</a>,
<a href="../src/gdevpsds.h">src/gdevpsds.h</a>,
<a href="../src/gdevpsdu.c">src/gdevpsdu.c</a>.

</dl>

<dt>
PostScript output driver ([e]pswrite):
<dd>
<a href="../src/gdevps.c">src/gdevps.c</a>,
<a href="../src/gdevpsu.c">src/gdevpsu.c</a>,
<a href="../src/gdevpsu.h">src/gdevpsu.h</a>.

<dt>
PDF output driver (pdfwrite):
<dd>
<dl>

<dt>
Substrate:
<dd>
<a href="../src/gdevpdfo.c">src/gdevpdfo.c</a>,
<a href="../src/gdevpdfo.h">src/gdevpdfo.h</a>,
<a href="../src/gdevpdfr.c">src/gdevpdfr.c</a>,
<a href="../src/gdevpdfu.c">src/gdevpdfu.c</a>.

<dt>
Old text and fonts:
<dd>
<a href="../src/gdevpdfe.c">src/gdevpdfe.c</a>,
<a href="../src/gdevpdff.c">src/gdevpdff.c</a>,
<a href="../src/gdevpdff.h">src/gdevpdff.h</a>,
<a href="../src/gdevpdfs.c">src/gdevpdfs.c</a>,
<a href="../src/gdevpdft.c">src/gdevpdft.c</a>,
<a href="../src/gdevpdft.h">src/gdevpdft.h</a>,
<a href="../src/gdevpdfw.c">src/gdevpdfw.c</a>.

<dt>
New text and fonts:
<dd>
<a href="../src/gdevpdt.c">src/gdevpdt.c</a>,
<a href="../src/gdevpdt.h">src/gdevpdt.h</a>,
<a href="../src/gdevpdtb.c">src/gdevpdtb.c</a>,
<a href="../src/gdevpdtb.h">src/gdevpdtb.h</a>,
<a href="../src/gdevpdtc.c">src/gdevpdtc.c</a>,
<a href="../src/gdevpdtd.c">src/gdevpdtd.c</a>,
<a href="../src/gdevpdtd.h">src/gdevpdtd.h</a>,
<a href="../src/gdevpdte.c">src/gdevpdte.c</a>,
<a href="../src/gdevpdtf.c">src/gdevpdtf.c</a>,
<a href="../src/gdevpdtf.h">src/gdevpdtf.h</a>,
<a href="../src/gdevpdti.c">src/gdevpdti.c</a>,
<a href="../src/gdevpdti.h">src/gdevpdti.h</a>,
<a href="../src/gdevpdts.c">src/gdevpdts.c</a>,
<a href="../src/gdevpdts.h">src/gdevpdts.h</a>,
<a href="../src/gdevpdtt.c">src/gdevpdtt.c</a>,
<a href="../src/gdevpdtt.h">src/gdevpdtt.h</a>,
<a href="../src/gdevpdtv.c">src/gdevpdtv.c</a>,
<a href="../src/gdevpdtv.h">src/gdevpdtv.h</a>,
<a href="../src/gdevpdtw.c">src/gdevpdtw.c</a>,
<a href="../src/gdevpdtw.h">src/gdevpdtw.h</a>,
<a href="../src/gdevpdtx.h">src/gdevpdtx.h</a>.
<a href="../src/ConvertUTF.h">src/ConvertUTF.h</a>,
<a href="../src/ConvertUTF.c">src/ConvertUTF.c</a>,

<dt>
Graphics:
<dd>
<a href="../src/gdevpdfc.c">src/gdevpdfc.c</a>,
<a href="../src/gdevpdfc.h">src/gdevpdfc.h</a>,
<a href="../src/gdevpdfd.c">src/gdevpdfd.c</a>,
<a href="../src/gdevpdfg.c">src/gdevpdfg.c</a>,
<a href="../src/gdevpdfg.h">src/gdevpdfg.h</a>,
<a href="../src/gdevpdfk.c">src/gdevpdfk.c</a>,
<a href="../src/gdevpdft.c">src/gdevpdft.c</a>.
<a href="../src/gdevpdfv.c">src/gdevpdfv.c</a>.

<dt>
Images:
<dd>
<a href="../src/gdevpdfb.c">src/gdevpdfb.c</a>,
<a href="../src/gdevpdfi.c">src/gdevpdfi.c</a>,
<a href="../src/gdevpdfj.c">src/gdevpdfj.c</a>.

<dt>
Other:
<dd>
<a href="../src/gdevpdf.c">src/gdevpdf.c</a>,
<a href="../src/gdevpdfm.c">src/gdevpdfm.c</a>,
<a href="../src/gdevpdfp.c">src/gdevpdfp.c</a>,
<a href="../src/gdevpdfx.h">src/gdevpdfx.h</a>.
<a href="../src/gdevpdfb.h">src/gdevpdfb.h</a>.

</dl>

</dl>

<h4><a name="High_level_devices"></a>Other high-level devices</h4>

<p>
Currently, the CGM driver is raster-only.  If anyone cares seriously about
CGM in the future, this driver should be upgraded to a higher level.

<dl>

<dt>
PCL XL output device (pxlmono, pxlcolor):
<dd>
<a href="../src/gdevpx.c">src/gdevpx.c</a>,
<a href="../src/gdevpxat.h">src/gdevpxat.h</a>,
<a href="../src/gdevpxen.h">src/gdevpxen.h</a>,
<a href="../src/gdevpxop.h">src/gdevpxop.h</a>,
<a href="../src/gdevpxut.c">src/gdevpxut.c</a>,
<a href="../src/gdevpxut.h">src/gdevpxut.h</a>.

<dt>
Cairo and SVG output devices (cairo, svgwrite):
<dd>
<a href="../src/gdevcairo.c">src/gdevcairo.c</a>,
<a href="../src/gdevsvg.c">src/gdevsvg.c</a>.

<p>
The svgwrite device produces SVG only. The cairo device uses the cairo 
graphics library to produce PDF, EPS, SVG or PNG output, based on the
requested filename extension.

<dt>
Text extraction:
<dd>
<a href="../src/gdevtxtw.c">src/gdevtxtw.c</a>.

<dt>
Other high-level devices:
<dd>
<a href="../src/gdevtrac.c">src/gdevtrac.c</a>.

</dl>

<h4><a name="Other_maintained_drivers"></a>Other maintained drivers</h4>

<p>
The standard Ghostscript distribution includes a collection of drivers,
mostly written by Aladdin Enterprises, that are "maintained" in the same
sense as the Ghostscript core code.

<dl>

<dt>
Display drivers:
<dd>
<a href="../src/gdev8bcm.c">src/gdev8bcm.c</a>,
<a href="../src/gdev8bcm.h">src/gdev8bcm.h</a>,
<a href="../src/gdevevga.c">src/gdevevga.c</a>,
<a href="../src/gdevl256.c">src/gdevl256.c</a>,
<a href="../src/gdevpccm.c">src/gdevpccm.c</a>,
<a href="../src/gdevpccm.h">src/gdevpccm.h</a>,
<a href="../src/gdevpcfb.c">src/gdevpcfb.c</a>,
<a href="../src/gdevpcfb.h">src/gdevpcfb.h</a>,
<a href="../src/gdevs3ga.c">src/gdevs3ga.c</a>,
<a href="../src/gdevsco.c">src/gdevsco.c</a>,
<a href="../src/gdevsvga.c">src/gdevsvga.c</a>,
<a href="../src/gdevsvga.h">src/gdevsvga.h</a>,
<a href="../src/gdevvglb.c">src/gdevvglb.c</a>.

<dt>
Window system drivers:
<dd>

<dl>

<dt>
X Windows:
<dd>
<a href="../src/gdevx.c">src/gdevx.c</a>,
<a href="../src/gdevx.h">src/gdevx.h</a>,
<a href="../src/gdevxalt.c">src/gdevxalt.c</a>,
<a href="../src/gdevxcmp.c">src/gdevxcmp.c</a>,
<a href="../src/gdevxcmp.h">src/gdevxcmp.h</a>,
<a href="../src/gdevxini.c">src/gdevxini.c</a>,
<a href="../src/gdevxres.c">src/gdevxres.c</a>,
<a href="../src/gdevxxf.c">src/gdevxxf.c</a>.

<dt>
Microsoft Windows:
<dd>
<a href="../src/gdevmswn.c">src/gdevmswn.c</a>,
<a href="../src/gdevmswn.h">src/gdevmswn.h</a>,
<a href="../src/gdevmsxf.c">src/gdevmsxf.c</a>,
<a href="../src/gdevwddb.c">src/gdevwddb.c</a>,
<a href="../src/gdevwdib.c">src/gdevwdib.c</a>.

<dt>
OS/2 Presentation Manager:
<dd>
<a href="../src/gdevpm.c">src/gdevpm.c</a>,
<a href="../src/gdevpm.h">src/gdevpm.h</a>,
<a href="../src/gspmdrv.c">src/gspmdrv.c</a>,
<a href="../src/gspmdrv.h">src/gspmdrv.h</a>.

</dl>

<dt>
Raster file output drivers:
<dd>

<dl>

<dt>
Fax and TIFF:
<dd>
<a href="../src/gdevfax.c">src/gdevfax.c</a>,
<a href="../src/gdevfax.h">src/gdevfax.h</a>,
<a href="../src/gdevtfax.c">src/gdevtfax.c</a>,
<a href="../src/gdevtfax.h">src/gdevtfax.h</a>,
<a href="../src/gdevtifs.c">src/gdevtifs.c</a>,
<a href="../src/gdevtifs.h">src/gdevtifs.h</a>,
<a href="../src/gdevtfnx.c">src/gdevtfnx.c</a>.
<a href="../src/gdevtsep.c">src/gdevtsep.c</a>.

<dt>
(Low-level) CGM:
<dd>
<a href="../src/gdevcgm.c">src/gdevcgm.c</a>,
<a href="../src/gdevcgml.c">src/gdevcgml.c</a>,
<a href="../src/gdevcgml.h">src/gdevcgml.h</a>,
<a href="../src/gdevcgmx.h">src/gdevcgmx.h</a>.

<dt>
Example DeviceN devices:
<dd>
<a href="../src/gdevdevn.c">src/gdevdevn.c</a>,
<a href="../src/gdevdevn.h">src/gdevdevn.h</a>,
<a href="../src/gdevxcf.c">src/gdevxcf.c</a>,
<a href="../src/gdevpsd.c">src/gdevpsd.c</a>,
<a href="../src/gdevperm.c">src/gdevperm.c</a>.

<dt>
Other raster file formats:
<dd>
<a href="../src/gdevbit.c">src/gdevbit.c</a>,
<a href="../src/gdevbmp.c">src/gdevbmp.c</a>,
<a href="../src/gdevbmp.h">src/gdevbmp.h</a>,
<a href="../src/gdevbmpa.c">src/gdevbmpa.c</a>,
<a href="../src/gdevbmpc.c">src/gdevbmpc.c</a>,
<a href="../src/gdevjpeg.c">src/gdevjpeg.c</a>,
<a href="../src/gdevmiff.c">src/gdevmiff.c</a>,
<a href="../src/gdevp2up.c">src/gdevp2up.c</a>,
<a href="../src/gdevpcx.c">src/gdevpcx.c</a>,
<a href="../src/gdevpbm.c">src/gdevpbm.c</a>,
<a href="../src/gdevpng.c">src/gdevpng.c</a>,
<a href="../src/gdevpsim.c">src/gdevpsim.c</a>.

</dl>

<dt>
Printer drivers:
<dd>

<dl>

<dt>
Operating system printer services:
<dd>
<a href="../src/gdevos2p.c">src/gdevos2p.c</a>,
<a href="../src/gdevwpr2.c">src/gdevwpr2.c</a>,
<a href="../src/gdevwprn.c">src/gdevwprn.c</a>.

<dt>
H-P monochrome printers:
<dd>
<a href="../src/gdevdljm.c">src/gdevdljm.c</a>,
<a href="../src/gdevdljm.h">src/gdevdljm.h</a>,
<a href="../src/gdevdjet.c">src/gdevdjet.c</a>,
<a href="../src/gdevlj56.c">src/gdevlj56.c</a>.

<dt>
Other printers:
<dd>
<a href="../src/gdevatx.c">src/gdevatx.c</a>.

</dl>

</dl>

<h4><a name="Contributed_drivers"></a>Contributed drivers</h4>

<p>
This list is likely to be incomplete and inaccurate: see <a
href="../src/contrib.mak">src/contrib.mak</a> for the real one.

<dl>

<dt>
Display and window system drivers:
<dd>
<a href="../src/gdev3b1.c">src/gdev3b1.c</a>,
<a href="../src/gdevherc.c">src/gdevherc.c</a>,
<a href="../src/gdevpe.c">src/gdevpe.c</a>,
<a href="../src/gdevsnfb.c">src/gdevsnfb.c</a>,
<a href="../src/gdevsun.c">src/gdevsun.c</a>.

<dt>
Raster file output drivers:
<dd>
<a href="../src/gdevcfax.c">src/gdevcfax.c</a>,
<a href="../src/gdevcif.c">src/gdevcif.c</a>,
<a href="../src/gdevdfax.c">src/gdevdfax.c</a>,
<a href="../src/gdevifno.c">src/gdevifno.c</a>,
<a href="../src/gdevmgr.c">src/gdevmgr.c</a>,
<a href="../src/gdevmgr.h">src/gdevmgr.h</a>,
<a href="../src/gdevsgi.c">src/gdevsgi.c</a>,
<a href="../src/gdevsgi.h">src/gdevsgi.h</a>,
<a href="../src/gdevsunr.c">src/gdevsunr.c</a>,
<a href="../src/gdevjbig2.c">src/gdevjbig2.c</a>,
<a href="../src/gdevjpx.c">src/gdevjpx.c</a>.

<dt>
Printer drivers:
<dd>
<a href="../lib/bj8.rpd">lib/bj8.rpd</a>,
<a href="../lib/cbjc600.ppd">lib/cbjc600.ppd</a>,
<a href="../lib/cbjc800.ppd">lib/cbjc800.ppd</a>,
<a href="../src/gdev3852.c">src/gdev3852.c</a>,
<a href="../src/gdev4081.c">src/gdev4081.c</a>,
<a href="../src/gdev4693.c">src/gdev4693.c</a>,
<a href="../src/gdev8510.c">src/gdev8510.c</a>,
<a href="../src/gdevadmp.c">src/gdevadmp.c</a>,
<a href="../src/gdevbj10.c">src/gdevbj10.c</a>,
<a href="../src/gdevbjc.h">src/gdevbjc.h</a>,
<a href="../src/gdevbjcl.c">src/gdevbjcl.c</a>,
<a href="../src/gdevbjcl.h">src/gdevbjcl.h</a>,
<a href="../src/gdevccr.c">src/gdevccr.c</a>,
<a href="../src/gdevcdj.c">src/gdevcdj.c</a>,
<a href="../src/gdevclj.c">src/gdevclj.c</a>,
<a href="../src/gdevcljc.c">src/gdevcljc.c</a>,
<a href="../src/gdevcp50.c">src/gdevcp50.c</a>,
<a href="../src/gdevcslw.c">src/gdevcslw.c</a>,
<a href="../src/gdevdjtc.c">src/gdevdjtc.c</a>,
<a href="../src/gdevdm24.c">src/gdevdm24.c</a>,
<a href="../src/gdevepsc.c">src/gdevepsc.c</a>,
<a href="../src/gdevepsn.c">src/gdevepsn.c</a>,
<a href="../src/gdevescp.c">src/gdevescp.c</a>,
<a href="../src/gdevhl7x.c">src/gdevhl7x.c</a>,
<a href="../src/gdevijs.c">src/gdevijs.c</a>,
<a href="../src/gdevimgn.c">src/gdevimgn.c</a>,
<a href="../src/gdevl31s.c">src/gdevl31s.c</a>,
<a href="../src/gdevlbp8.c">src/gdevlbp8.c</a>,
<a href="../src/gdevlp8k.c">src/gdevlp8k.c</a>,
<a href="../src/gdevlxm.c">src/gdevlxm.c</a>,
<a href="../src/gdevn533.c">src/gdevn533.c</a>,
<a href="../src/gdevo182.c">src/gdevo182.c</a>,
<a href="../src/gdevokii.c">src/gdevokii.c</a>,
<a href="../src/gdevpcl.c">src/gdevpcl.c</a>,
<a href="../src/gdevpcl.h">src/gdevpcl.h</a>,
<a href="../src/gdevphex.c">src/gdevphex.c</a>,
<a href="../src/gdevpjet.c">src/gdevpjet.c</a>,
<a href="../src/gdevsj48.c">src/gdevsj48.c</a>,
<a href="../src/gdevsppr.c">src/gdevsppr.c</a>,
<a href="../src/gdevstc.c">src/gdevstc.c</a>,
<a href="../src/gdevstc.h">src/gdevstc.h</a>,
<a href="../src/gdevstc1.c">src/gdevstc1.c</a>,
<a href="../src/gdevstc2.c">src/gdevstc2.c</a>,
<a href="../src/gdevstc3.c">src/gdevstc3.c</a>,
<a href="../src/gdevstc4.c">src/gdevstc4.c</a>,
<a href="../src/gdevtknk.c">src/gdevtknk.c</a>,
<a href="../src/gdevupd.c">src/gdevupd.c</a>.

<dt>
The special <tt>rinkj</tt> high-quality inkjet driver:
<dd>
<a href="../src/gdevrinkj.c">src/gdevrinkj.c</a>,
<a href="../src/gsequivc.c">src/gsequivc.c</a>,
<a href="../src/gsequivc.h">src/gsequivc.h</a>,
<a href="../src/rinkj/evenbetter-rll.c">src/rinkj/evenbetter-rll.c</a>,
<a href="../src/rinkj/evenbetter-rll.h">src/rinkj/evenbetter-rll.h</a>,
<a href="../src/rinkj/rinkj-byte-stream.c">src/rinkj/rinkj-byte-stream.c</a>,
<a href="../src/rinkj/rinkj-byte-stream.h">src/rinkj/rinkj-byte-stream.h</a>,
<a href="../src/rinkj/rinkj-config.c">src/rinkj/rinkj-config.c</a>,
<a href="../src/rinkj/rinkj-config.h">src/rinkj/rinkj-config.h</a>,
<a href="../src/rinkj/rinkj-device.c">src/rinkj/rinkj-device.c</a>,
<a href="../src/rinkj/rinkj-device.h">src/rinkj/rinkj-device.h</a>,
<a href="../src/rinkj/rinkj-dither.c">src/rinkj/rinkj-dither.c</a>,
<a href="../src/rinkj/rinkj-dither.h">src/rinkj/rinkj-dither.h</a>,
<a href="../src/rinkj/rinkj-epson870.c">src/rinkj/rinkj-epson870.c</a>,
<a href="../src/rinkj/rinkj-epson870.h">src/rinkj/rinkj-epson870.h</a>,
<a href="../src/rinkj/rinkj-screen-eb.c">src/rinkj/rinkj-screen-eb.c</a>,
<a href="../src/rinkj/rinkj-screen-eb.h">src/rinkj/rinkj-screen-eb.h</a>,
<a href="../lib/rinkj-2200-setup">lib/rinkj-2200-setup</a>.

<dt>
A device implementing Well Tempered Screening and IMDI color correction:
<dd>
<a href="../src/gdevwts.c">src/gdevwts.c</a>.
</dl>

<h3><a name="PostScript_interpreter"></a>PostScript interpreter</h3>

<p>
The PostScript interpreter is conceptually simple: in fact, an interpreter
that could execute "3 4 add =" and print "7" was running 3 weeks after the
first line of Ghostscript code was written.  However, a number of
considerations make the code large and complex.

<p>
The interpreter is designed to run in environments with very limited memory.
The main consequence of this is that it cannot allocate its stacks
(dictionary, execution, operand) as ordinary arrays, since the
user-specified stack size limit may be very large.  Instead, it allocates
them as a linked list of blocks.  See below for more details.

<p>
The interpreter must never cause a C runtime error that it cannot trap.
Unfortunately, C implementations almost never provide the ability to trap
stack overflow.  In order to put a fixed bound on the C stack size, the
interpreter never implements PostScript recursion by C recursion.  This
means that any C code that logically needs to call the interpreter must
instead push a continuation (including all necessary state information) on
the PostScript execution stack, followed by the PostScript object to be
executed, and then <em>return</em> to the interpreter.  (See <a
href="../src/estack.h">src/estack.h</a> for more details about
continuations.)  Unfortunately, since PostScript Level 2 introduces streams
whose data source can be a PostScript procedure, any code that reads or
writes stream data must be prepared to suspend itself, storing all necessary
state in a continuation.  There are some places where this is extremely
awkward, such as the scanner/parser.

<p>
The use of continuations affects many places in the interpreter, and even
some places in the graphics library.  For example, when processing an image,
one may need to call a PostScript procedure as part of mapping a CIE color
to a device color.  Ghostscript uses a variety of dodges to handle this: for
example, in the case of CIE color mapping, all of the PostScript procedures
are pre-sampled and the results cached.  The Adobe implementation limits
this kind of recursion to a fixed number of levels (5?): this would be
another acceptable approach, but at this point it would require far more
code restructuring than it would be worth.

<p>
A significant amount of the PostScript language implementation is in fact
written in PostScript.  Writing in PostScript leverages the C code for
multi-threading, garbage collection, error handling, continuations for
streams, etc., etc.; also, we have found PostScript in general more concise
and easier to debug than C, mostly because of memory management issues.  So
given the choice, we tended to implement a feature in PostScript if it
worked primarily with PostScript data structures, wasn't heavily used
(example: font loading), or if it interacted with the stream or other
callback machinery (examples: ReusableFileDecode streams, resourceforall).
Often we would add non-standard PostScript operators for functions that had
to run faster or that did more C-like things, such as the media matching
algorithm for setpagedevice.



<h4><a name="Main_program"></a>Main program</h4>

<p>
The main program of the interpreter is normally invoked from the command
line, but it has an API as well.  In fact, it has two APIs: one that
recognizes the existence of multiple "interpreter instances" (although it
currently provides a default instance, which almost all clients use), and a
completely different one designed for Windows DLLs.  These should be unified
as soon as possible, since there are two steadily growing incompatible
bodies of client code.

<dl>

<dt>
Files:
<dd>
<a href="../src/gs.c">src/gs.c</a>,
<a href="../src/gserver.c">src/gserver.c</a>,
<a href="../src/iccinit0.c">src/iccinit0.c</a>(COMPILE_INITS=0),
<a href="../src/iccinit1.c">src/iccinit1.c</a>(COMPILE_INITS=1),
<a href="../src/iinit.c">src/iinit.c</a>,
<a href="../src/iinit.h">src/iinit.h</a>,
<a href="../src/imain.c">src/imain.c</a>,
<a href="../src/imain.h">src/imain.h</a>,
<a href="../src/imainarg.c">src/imainarg.c</a>,
<a href="../src/imainarg.h">src/imainarg.h</a>,
<a href="../src/iminst.h">src/iminst.h</a>,
<a href="../src/main.h">src/main.h</a>.

</dl>

<h4><a name="Data_structures"></a>Data structures</h4>

<p>
The main data structures visible to the PostScript programmers are arrays,
contexts, dictionaries, names, and stacks.

<p>
Arrays have no unusual properties.  See under <a href="#Refs">Refs</a> below
for more information about how array elements are stored.

<p>
Contexts are used to hold the interpreter state even in configurations that
don't include the Display PostScript multiple context extension.  Context
switching is implemented by a complex cooperation of C and PostScript code.

<p>
Dictionaries have two special properties worth noting:

<ul>

<li>They use an optimized storage representation if all the keys are names,
which is almost always the case.

<li>They interact with a caching scheme used to accelerate name lookup in
the interpreter.

</ul>

<p>
Names are allocated in blocks.  The characters and hash chains are stored
separately from the lookup cache information, so that in the future, most of
the former can be compiled into the executable and shared or put in ROM.
(This is not actually done yet.)

<dl>

<dt>
Contexts:
<dd>
<a href="../src/icontext.c">src/icontext.c</a>,
<a href="../src/icontext.h">src/icontext.h</a>,
<a href="../src/icstate.h">src/icstate.h</a>.

<dt>
Dictionaries:
<dd>
<a href="../src/iddict.h">src/iddict.h</a>,
<a href="../src/idict.h">src/idict.h</a>,
<a href="../src/idict.c">src/idict.c</a>,
<a href="../src/idictdef.h">src/idictdef.h</a>,
<a href="../src/idicttpl.h">src/idicttpl.h</a>.

<dt>
Names:
<dd>
<a href="../src/iname.c">src/iname.c</a>,
<a href="../src/iname.h">src/iname.h</a>,
<a href="../src/inamedef.h">src/inamedef.h</a>,
<a href="../src/inameidx.h">src/inameidx.h</a>,
<a href="../src/inames.h">src/inames.h</a>,
<a href="../src/inamestr.h">src/inamestr.h</a>.

</dl>

<h4><a name="Stacks"></a>Stacks</h4>

<p>
As mentioned above, each stack is allocated as a linked list of blocks.
However, for reasonable performance, operators must normally be able to
access their operands and produce their results using indexing rather than
an access procedure.  This is implemented by ensuring that all the operands
of an operator are in the topmost block of the stack, using guard entries
that cause an internal error if the condition isn't met.  See <a
href="../src/iostack.h">src/iostack.h</a> for more details.

<dl>

<dt>
Generic stacks:
<dd>
<a href="../src/isdata.h">src/isdata.h</a>,
<a href="../src/istack.c">src/istack.c</a>,
<a href="../src/istack.h">src/istack.h</a>,
<a href="../src/istkparm.h">src/istkparm.h</a>.

<dt>
Specific stacks:
<dd>

<dl>

<dt>
Dictionary stack:
<dd>
<a href="../src/dstack.h">src/dstack.h</a>,
<a href="../src/iddstack.h">src/iddstack.h</a>,
<a href="../src/idsdata.h">src/idsdata.h</a>,
<a href="../src/idstack.c">src/idstack.c</a>,
<a href="../src/idstack.h">src/idstack.h</a>.

<dt>
Execution stack:
<dd>
<a href="../src/estack.h">src/estack.h</a>,
<a href="../src/iesdata.h">src/iesdata.h</a>,
<a href="../src/iestack.h">src/iestack.h</a>.

<dt>
Operand stack:
<dd>
<a href="../src/iosdata.h">src/iosdata.h</a>,
<a href="../src/iostack.h">src/iostack.h</a>,
<a href="../src/ostack.h">src/ostack.h</a>.

</dl>

</dl>

<h4><a name="Interpreter_loop"></a>Interpreter loop</h4>

<dl>

<dt>
Files:
<dd>
<a href="../src/interp.c">src/interp.c</a>,
<a href="../src/interp.h">src/interp.h</a>.

</dl>

<h4><a name="Scanning_parsing"></a>Scanning/parsing</h4>

<p>
PostScript parsing consists essentially of token scanning, and is simple in
principle.  The scanner is complex because it must be able to suspend its
operation at any time (i.e., between any two input characters) to allow an
interpreter callout, if its input is coming from a procedure-based stream
and the procedure must be called to provide more input data.

<dl>

<dt>
Main scanner:
<dd>
<a href="../src/iscan.c">src/iscan.c</a>,
<a href="../src/iscan.h">src/iscan.h</a>,
<a href="../src/iscannum.c">src/iscannum.c</a>,
<a href="../src/iscannum.h">src/iscannum.h</a>,
<a href="../src/scanchar.h">src/scanchar.h</a>,
<a href="../src/scantab.c">src/scantab.c</a>.

<dt>
Binary tokens:
<dd>
<a href="../src/btoken.h">src/btoken.h</a>,
<a href="../src/ibnum.c">src/ibnum.c</a>,
<a href="../src/ibnum.h">src/ibnum.h</a>,
<a href="../src/inobtokn.c">src/inobtokn.c</a>,
<a href="../src/iscanbin.c">src/iscanbin.c</a>,
<a href="../src/iscanbin.h">src/iscanbin.h</a>.

<dt>
DSC parsing:
<dd>
<a href="../src/dscparse.c">src/dscparse.c</a>,
<a href="../src/dscparse.h">src/dscparse.h</a>.

</dl>

<h4><a name="Standard_operators"></a>Standard operators</h4>

<dl>

<dt>
Non-output-related:
<dd>

<dl>

<dt>
Filters:
<dd>
<a href="../src/ifilter.h">src/ifilter.h</a>,
<a href="../src/ifilter2.h">src/ifilter2.h</a>,
<a href="../src/ifrpred.h">src/ifrpred.h</a>,
<a href="../src/ifwpred.h">src/ifwpred.h</a>,
<a href="../src/istream.h">src/istream.h</a>,
<a href="../src/zfbcp.c">src/zfbcp.c</a>,
<a href="../src/zfdctd.c">src/zfdctd.c</a>,
<a href="../src/zfdcte.c">src/zfdcte.c</a>,
<a href="../src/zfdecode.c">src/zfdecode.c</a>,
<a href="../src/zfilter.c">src/zfilter.c</a>,
<a href="../src/zfilter2.c">src/zfilter2.c</a>,
<a href="../src/zfilterx.c">src/zfilterx.c</a>,
<a href="../src/zfjbig2.c">src/zfjbig2.c</a>,
<a href="../src/zfjpx.c">src/zfjpx.c</a>,
<a href="../src/zfmd5.c">src/zfmd5.c</a>,
<a href="../src/zfarc4.c">src/zfarc4.c</a>,
<a href="../src/zfproc.c">src/zfproc.c</a>,
<a href="../src/zfrsd.c">src/zfrsd.c</a>,
<a href="../src/zfzlib.c">src/zfzlib.c</a>.

<dt>
File and stream I/O:
<dd>
<a href="../src/files.h">src/files.h</a>,
<a href="../src/itoken.h">src/itoken.h</a>,
<a href="../src/zbseq.c">src/zbseq.c</a>,
<a href="../src/zdscpars.c">src/zdscpars.c</a>,
<a href="../src/zfile.h">src/zfile.h</a>,
<a href="../src/zfile.c">src/zfile.c</a>,
<a href="../src/zfile1.c">src/zfile1.c</a>,
<a href="../src/zfileio.c">src/zfileio.c</a>,
<a href="../src/ztoken.c">src/ztoken.c</a>.

<dt>
Data structures:
<dd>
<a href="../src/zarray.c">src/zarray.c</a>,
<a href="../src/zdict.c">src/zdict.c</a>,
<a href="../src/zgeneric.c">src/zgeneric.c</a>,
<a href="../src/zpacked.c">src/zpacked.c</a>,
<a href="../src/zstring.c">src/zstring.c</a>.

<dt>
Functions:
<dd>
<a href="../src/ifunc.h">src/ifunc.h</a>,
<a href="../src/zfunc.c">src/zfunc.c</a>,
<a href="../src/zfunc0.c">src/zfunc0.c</a>,
<a href="../src/zfunc3.c">src/zfunc3.c</a>,
<a href="../src/zfunc4.c">src/zfunc4.c</a>,

<dt>
Other:
<dd>
<a href="../src/ivmem2.h">src/ivmem2.h</a>,
<a href="../src/zalg.c">src/zalg.c</a>,
<a href="../src/zarith.c">src/zarith.c</a>,
<a href="../src/zcontext.c">src/zcontext.c</a>,
<a href="../src/zcontrol.c">src/zcontrol.c</a>,
<a href="../src/zmath.c">src/zmath.c</a>,
<a href="../src/zmatrix.c">src/zmatrix.c</a>,
<a href="../src/zmisc.c">src/zmisc.c</a>,
<a href="../src/zmisc1.c">src/zmisc1.c</a>,
<a href="../src/zmisc2.c">src/zmisc2.c</a>,
<a href="../src/zmisc3.c">src/zmisc3.c</a>,
<a href="../src/zrelbit.c">src/zrelbit.c</a>,
<a href="../src/zstack.c">src/zstack.c</a>,
<a href="../src/ztype.c">src/ztype.c</a>,
<a href="../src/zusparam.c">src/zusparam.c</a>,
<a href="../src/zvmem.c">src/zvmem.c</a>,
<a href="../src/zvmem2.c">src/zvmem2.c</a>.

</dl>

<dt>
Output-related:
<dd>

<dl>

<dt>
Device management:
<dd>
<a href="../src/zdevcal.c">src/zdevcal.c</a>,
<a href="../src/zdevice.c">src/zdevice.c</a>,
<a href="../src/zdevice2.c">src/zdevice2.c</a>,
<a href="../src/ziodev.c">src/ziodev.c</a>,
<a href="../src/ziodev2.c">src/ziodev2.c</a>,
<a href="../src/ziodevs.c">src/ziodevs.c</a>,
<a href="../src/ziodevsc.c">src/ziodevsc.c</a>,
<a href="../src/ziodevst.c">src/ziodevst.c</a>,
<a href="../src/zmedia2.c">src/zmedia2.c</a>,
<a href="../src/zdfilter.c">src/zdfilter.c</a>.

<dt>
Fonts and text:
<dd>
<a href="../src/bfont.h">src/bfont.h</a>,
<a href="../src/ccfont.h">src/ccfont.h</a>,
<a href="../src/iccfont.c">src/iccfont.c</a>,
<a href="../src/icfontab.c">src/icfontab.c</a>,
<a href="../src/ichar.h">src/ichar.h</a>,
<a href="../src/ichar1.h">src/ichar1.h</a>,
<a href="../src/icharout.h">src/icharout.h</a>,
<a href="../src/icid.h">src/icid.h</a>,
<a href="../src/ifcid.h">src/ifcid.h</a>,
<a href="../src/ifont.h">src/ifont.h</a>,
<a href="../src/ifont1.h">src/ifont1.h</a>,
<a href="../src/ifont2.h">src/ifont2.h</a>,
<a href="../src/ifont42.h">src/ifont42.h</a>,
<a href="../src/zbfont.c">src/zbfont.c</a>,
<a href="../src/zcfont.c">src/zcfont.c</a>,
<a href="../src/zchar.c">src/zchar.c</a>,
<a href="../src/zchar1.c">src/zchar1.c</a>,
<a href="../src/zchar2.c">src/zchar2.c</a>,
<a href="../src/zchar32.c">src/zchar32.c</a>,
<a href="../src/zchar42.c">src/zchar42.c</a>,
<a href="../src/zchar42.h">src/zchar42.h</a>,
<a href="../src/zcharout.c">src/zcharout.c</a>,
<a href="../src/zcharx.c">src/zcharx.c</a>,
<a href="../src/zcid.c">src/zcid.c</a>,
<a href="../src/zcidtest.c">src/zcidtest.c</a>,
<a href="../src/zfcid.c">src/zfcid.c</a>,
<a href="../src/zfcid0.c">src/zfcid0.c</a>,
<a href="../src/zfcid1.c">src/zfcid1.c</a>,
<a href="../src/zfcmap.c">src/zfcmap.c</a>,
<a href="../src/zfont.c">src/zfont.c</a>,
<a href="../src/zfont0.c">src/zfont0.c</a>,
<a href="../src/zfont1.c">src/zfont1.c</a>,
<a href="../src/zfont2.c">src/zfont2.c</a>,
<a href="../src/zfont32.c">src/zfont32.c</a>,
<a href="../src/zfont42.c">src/zfont42.c</a>,
<a href="../src/zfontenum.c">src/zfontenum.c</a>.

<dt>
A bridge to the True Type bytecode interpreter:
<dd>
<a href="../src/gxttfb.c">src/gxttfb.c</a>,
<a href="../src/gxttfb.h">src/gxttfb.h</a>,
<a href="../src/ttfoutl.h">src/ttfoutl.h</a>,
<a href="../src/ttfmain.c">src/ttfmain.c</a>,
<a href="../src/ttfmemd.c">src/ttfmemd.c</a>,
<a href="../src/ttfmemd.h">src/ttfmemd.h</a>,
<a href="../src/ttfinp.c">src/ttfinp.c</a>,
<a href="../src/ttfinp.h">src/ttfinp.h</a>.

<dt>
A reduced True Type bytecode interpreter:
<br><em>(this is based in part on the work of the Freetype Team and incorporates some code from
the
FreeType 1 project)</em>
<dd>
<a href="../src/ttfsfnt.h">src/ttfsfnt.h</a>,
<a href="../src/ttcalc.c">src/ttcalc.c</a>,
<a href="../src/ttcalc.h">src/ttcalc.h</a>,
<a href="../src/ttcommon.h">src/ttcommon.h</a>,
<a href="../src/ttconf.h">src/ttconf.h</a>,
<a href="../src/ttconfig.h">src/ttconfig.h</a>,
<a href="../src/ttinterp.c">src/ttinterp.c</a>,
<a href="../src/ttinterp.h">src/ttinterp.h</a>,
<a href="../src/ttload.c">src/ttload.c</a>,
<a href="../src/ttload.h">src/ttload.h</a>,
<a href="../src/ttmisc.h">src/ttmisc.h</a>,
<a href="../src/ttobjs.c">src/ttobjs.c</a>,
<a href="../src/ttobjs.h">src/ttobjs.h</a>,
<a href="../src/tttables.h">src/tttables.h</a>,
<a href="../src/tttype.h">src/tttype.h</a>,
<a href="../src/tttypes.h">src/tttypes.h</a>.

<dt>
Color, pattern, and halftone:
<dd>
<a href="../src/icie.h">src/icie.h</a>,
<a href="../src/icolor.h">src/icolor.h</a>,
<a href="../src/icremap.h">src/icremap.h</a>,
<a href="../src/icsmap.h">src/icsmap.h</a>,
<a href="../src/iht.h">src/iht.h</a>,
<a href="../src/ipcolor.h">src/ipcolor.h</a>,
<a href="../src/zcie.c">src/zcie.c</a>,
<a href="../src/zcolor.c">src/zcolor.c</a>,
<a href="../src/zcolor1.c">src/zcolor1.c</a>,
<a href="../src/zcolor2.c">src/zcolor2.c</a>,
<a href="../src/zcolor3.c">src/zcolor3.c</a>,
<a href="../src/zcrd.c">src/zcrd.c</a>,
<a href="../src/zcsdevn.c">src/zcsdevn.c</a>,
<a href="../src/zcsindex.c">src/zcsindex.c</a>,
<a href="../src/zcspixel.c">src/zcspixel.c</a>,
<a href="../src/zcssepr.c">src/zcssepr.c</a>,
<a href="../src/zicc.c">src/zicc.c</a>,
<a href="../src/zhsb.c">src/zhsb.c</a>,
<a href="../src/zht.c">src/zht.c</a>,
<a href="../src/zht1.c">src/zht1.c</a>,
<a href="../src/zht2.h">src/zht2.h</a>,
<a href="../src/zht2.c">src/zht2.c</a>,
<a href="../src/zpcolor.c">src/zpcolor.c</a>,
<a href="../src/zshade.c">src/zshade.c</a>,
<a href="../src/ztrans.c">src/ztrans.c</a>.

<dt>
Images:
<dd>
<a href="../src/iimage.h">src/iimage.h</a>,
<a href="../src/iimage2.h">src/iimage2.h</a>,
<a href="../src/zimage.c">src/zimage.c</a>,
<a href="../src/zimage2.c">src/zimage2.c</a>,
<a href="../src/zimage3.c">src/zimage3.c</a>,
<a href="../src/zfimscale.c">src/zfimscale.c</a>.

<dt>
Other graphics:
<dd>
<a href="../src/igstate.h">src/igstate.h</a>,
<a href="../src/zdpnext.c">src/zdpnext.c</a>,
<a href="../src/zdps.c">src/zdps.c</a>,
<a href="../src/zdps1.c">src/zdps1.c</a>,
<a href="../src/zgstate.c">src/zgstate.c</a>,
<a href="../src/zpaint.c">src/zpaint.c</a>,
<a href="../src/zpath.c">src/zpath.c</a>,
<a href="../src/zpath1.c">src/zpath1.c</a>,
<a href="../src/zrop.c">src/zrop.c</a>,
<a href="../src/ztrap.c">src/ztrap.c</a>,
<a href="../src/zupath.c">src/zupath.c</a>.

</dl>

<dt>
Operator support:
<dd>
<a href="../src/oparc.h">src/oparc.h</a>,
<a href="../src/opcheck.h">src/opcheck.h</a>,
<a href="../src/opdef.h">src/opdef.h</a>,
<a href="../src/oper.h">src/oper.h</a>,
<a href="../src/opextern.h">src/opextern.h</a>.

</dl>

<h4><a name="Non_standard_operators"></a>Non-standard operators</h4>

<p>
The interpreter includes many non-standard operators.  Most of these provide
some part of the function of a standard operator, so that the standard
operator itself can be implemented in PostScript: these are not of interest
to users, and their function is usually obvious from the way they are used.
However, some non-standard operators provide access to additional,
non-standard facilities that users might want to know about, such as
transparency, RasterOp, and in-memory rendering.  These are documented at <a
href="Language.htm#Additional_operators">Language.htm#Additional_operators</a>.

<p>
We don't document the complete set of non-standard operators here, because
the set changes frequently.  However, all non-standard operators are
supposed to have names that begin with '.', so you can find them all by
executing the following (Unix) command:

<blockquote><pre>
grep '{".[.]' src/[zi]*.c
</pre></blockquote>

<p>
In addition to individual non-standard operators implemented in the same
files as standard ones, there are several independent optional packages of
non-standard operators.  As with other non-standard operators, the names of
all the operators in these packages begin with '.'.  We list those packages
here.

<dl>

<dt>
<a href="../src/zdosio.c">src/zdosio.c</a>
<dd>
Provides access to PC hardware I/O through MS-DOS system calls.  Probably no
longer useful.

<dt>
<a href="../src/zdouble.c">src/zdouble.c</a>
<dd>
Provides "double" floating point arithmetic, using 8-byte strings to hold
values.  Developed under a contract; probably used only by the group that
funded the development.

<dt>
<a href="../src/zfsample.c">src/zfsample.c</a>,
<dd>
Provides a special operator to sample a given function and create a new type 0 function.

<dt>
<a href="../src/zsysvm.c">src/zsysvm.c</a>
<dd>
Provides operators for allocating objects in specific VM spaces,
disregarding the current VM mode.

</dl>

<h4><a name="Interpreter_support"></a>Interpreter support</h4>

<p>
Memory management (refs, GC, save/restore) -- see <a
href="#PostScript_interpreter_extensions">below</a>.

<dl>
<dt>
Font API :
<dd>
<a href="../src/ifapi.h">src/ifapi.h</a>,
<a href="../src/zfapi.c">src/zfapi.c</a>,
<a href="../src/fapiufst.c">src/fapiufst.c</a>,
<a href="../src/fapi_ft.c">src/fapi_ft.c</a>,
<a href="../src/wrfont.h">src/wrfont.h</a>,
<a href="../src/wrfont.c">src/wrfont.c</a>,
<a href="../src/write_t1.h">src/write_t1.h</a>,
<a href="../src/write_t1.c">src/write_t1.c</a>,
<a href="../src/write_t2.h">src/write_t2.h</a>,
<a href="../src/write_t2.c">src/write_t2.c</a>,

<dt>
Miscellaneous support:
<dd>
<a href="../src/ierrors.h">src/ierrors.h</a>,
<a href="../src/errors.h">src/errors.h</a> <em>(deprecated)</em>,
<a href="../src/ghost.h">src/ghost.h</a>,
<a href="../src/iconf.c">src/iconf.c</a>,
<a href="../src/iconf.h">src/iconf.h</a>,
<a href="../src/idparam.c">src/idparam.c</a>,
<a href="../src/idparam.h">src/idparam.h</a>,
<a href="../src/ilevel.h">src/ilevel.h</a>,
<a href="../src/inouparm.c">src/inouparm.c</a>,
<a href="../src/iparam.c">src/iparam.c</a>,
<a href="../src/iparam.h">src/iparam.h</a>,
<a href="../src/iparray.h">src/iparray.h</a>,
<a href="../src/iutil.c">src/iutil.c</a>,
<a href="../src/iutil.h">src/iutil.h</a>,
<a href="../src/iutil2.c">src/iutil2.c</a>,
<a href="../src/iutil2.h">src/iutil2.h</a>,
<a href="../src/iplugin.c">src/iplugin.c</a>,
<a href="../src/iplugin.h">src/iplugin.h</a>.

</dl>

<h4><a name="PostScript_code"></a>PostScript code</h4>

<dl>

<dt>
Initialization and language support:
<dd>

<dl>

<dt>
All configurations:
<dd>
<a href="../lib/gs_init.ps">lib/gs_init.ps</a>,
<a href="../lib/gs_statd.ps">lib/gs_statd.ps</a>.

<dt>
Level 2:
<dd>
<a href="../lib/gs_btokn.ps">lib/gs_btokn.ps</a>,
<a href="../lib/gs_dps1.ps">lib/gs_dps1.ps</a>,
<a href="../lib/gs_dps2.ps">lib/gs_dps2.ps</a>,
<a href="../lib/gs_lev2.ps">lib/gs_lev2.ps</a>,
<a href="../lib/gs_res.ps">lib/gs_res.ps</a>,
<a href="../lib/gs_resmp.ps">lib/gs_resmp.ps</a>,
<a href="../lib/gs_resst.ps">lib/gs_resst.ps</a>,
<a href="../lib/gs_stres.ps">lib/gs_stres.ps</a>,
<a href="../lib/gs_setpd.ps">lib/gs_setpd.ps</a>.

<dt>
LanguageLevel 3:
<dd>
<a href="../lib/gs_frsd.ps">lib/gs_frsd.ps</a>,
<a href="../lib/gs_ll3.ps">lib/gs_ll3.ps</a>,
<a href="../lib/gs_trap.ps">lib/gs_trap.ps</a>.

<dt>
Display PostScript:
<dd>
<a href="../lib/gs_dpnxt.ps">lib/gs_dpnxt.ps</a>,
<a href="../lib/gs_dps.ps">lib/gs_dps.ps</a>.

<dt>
Emulation of other interpreters:
<dd>
<a href="../lib/gs_cet.ps">lib/gs_cet.ps</a> (Adobe CPSI).

</dl>

<dt>
Color Spaces and support:
<dd>

<dl>

<dt>
Color Space Loading:
<dd>
<a href="../lib/gs_ciecs2.ps">lib/gs_ciecs2.ps</a>,
<a href="../lib/gs_ciecs3.ps">lib/gs_ciecs3.ps</a>,
<a href="../lib/gs_cspace.ps">lib/gs_cspace.ps</a>,
<a href="../lib/gs_devcs.ps">lib/gs_devcs.ps</a>,
<a href="../lib/gs_devn.ps">lib/gs_devn.ps</a>,
<a href="../lib/gs_devpxl.ps">lib/gs_devpxl.ps</a>,
<a href="../lib/gs_indxd.ps">lib/gs_indxd.ps</a>,
<a href="../lib/gs_patrn.ps">lib/gs_patrn.ps</a>,
<a href="../lib/gs_sepr.ps">lib/gs_sepr.ps</a>.

<dt>
ICC color profiles:
<dd>
<a href="../lib/gs_icc.ps">lib/gs_icc.ps</a>.

</dl>

<dt>
Font loading and support:
<dd>

<dl>

<dt>
Font name mapping:
<dd>
<a href="../lib/Fontmap">lib/Fontmap</a>,
<a href="../lib/Fontmap.ATB">lib/Fontmap.ATB</a>,
<a href="../lib/Fontmap.ATM">lib/Fontmap.ATM</a>,
<a href="../lib/Fontmap.GS">lib/Fontmap.GS</a>,
<a href="../lib/Fontmap.OS2">lib/Fontmap.OS2</a>,
<a href="../lib/Fontmap.OSF">lib/Fontmap.OSF</a>,
<a href="../lib/Fontmap.SGI">lib/Fontmap.SGI</a>,
<a href="../lib/Fontmap.Sol">lib/Fontmap.Sol</a>,
<a href="../lib/Fontmap.Ult">lib/Fontmap.Ult</a>,
<a href="../lib/Fontmap.VMS">lib/Fontmap.VMS</a>,
<a href="../lib/cidfmap">lib/cidfmap</a>,
<a href="../lib/FAPIcidfmap">lib/FAPIcidfmap</a>,
<a href="../lib/FAPIfontmap">lib/FAPIfontmap</a>,
<a href="../lib/FCOfontmap">lib/FCOfontmap</a>.

<dt>
Generic:
<dd>
<a href="../lib/gs_ccfnt.ps">lib/gs_ccfnt.ps</a>,
<a href="../lib/gs_fonts.ps">lib/gs_fonts.ps</a>,
<a href="../lib/gs_fntem.ps">lib/gs_fntem.ps</a>.

<dt>
Type 1 and CFF:
<dd>
<a href="../lib/gs_cff.ps">lib/gs_cff.ps</a>,
<a href="../lib/gs_diskf.ps">lib/gs_diskf.ps</a>,
<a href="../lib/gs_type1.ps">lib/gs_type1.ps</a>.

<dt>
TrueType:
<dd>
<a href="../lib/gs_ttf.ps">lib/gs_ttf.ps</a>,
<a href="../lib/gs_typ42.ps">lib/gs_typ42.ps</a>.

<dt>
CID-keyed:
<dd>
<a href="../lib/gs_cidcm.ps">lib/gs_cidcm.ps</a>,
<a href="../lib/gs_cidfn.ps">lib/gs_cidfn.ps</a>,
<a href="../lib/gs_cmap.ps">lib/gs_cmap.ps</a>,
<a href="../lib/gs_ciddc.ps">lib/gs_ciddc.ps</a>,
<a href="../lib/gs_cidfm.ps">lib/gs_cidfm.ps</a>,
<a href="../lib/gs_cidtt.ps">lib/gs_cidtt.ps</a>.

<dt>
Font API:
<dd>
<a href="../lib/gs_fapi.ps">lib/gs_fapi.ps</a>,
<a href="../lib/FAPIconfig">lib/FAPIconfig</a>,
<a href="../lib/FAPIconfig-FCO">lib/FAPIconfig-FCO</a>,
<a href="../lib/xlatmap">lib/xlatmap</a>.
<a href="../lib/FCOfontmap-PCLPS2">lib/FCOfontmap-PCLPS2</a>.
<a href="../lib/FCOfontmap-PCLPS3">lib/FCOfontmap-PCLPS3</a>.
<a href="../lib/FCOfontmap-PS3">lib/FCOfontmap-PS3</a>.

<dt>
Other:
<dd>
<a href="../lib/gs_kanji.ps">lib/gs_kanji.ps</a>,
<a href="../lib/gs_pfile.ps">lib/gs_pfile.ps</a>,
<a href="../lib/gs_typ32.ps">lib/gs_typ32.ps</a>.

</dl>

<dt>
Encodings:
<dd>

<dl>

<dt>
Adobe-specified:
<dd>
<a href="../lib/gs_ce_e.ps">lib/gs_ce_e.ps</a>,
<a href="../lib/gs_dbt_e.ps">lib/gs_dbt_e.ps</a>,
<a href="../lib/gs_il1_e.ps">lib/gs_il1_e.ps</a>,
<a href="../lib/gs_mex_e.ps">lib/gs_mex_e.ps</a>,
<a href="../lib/gs_mro_e.ps">lib/gs_mro_e.ps</a>,
<a href="../lib/gs_pdf_e.ps">lib/gs_pdf_e.ps</a>,
<a href="../lib/gs_std_e.ps">lib/gs_std_e.ps</a>,
<a href="../lib/gs_sym_e.ps">lib/gs_sym_e.ps</a>,
<a href="../lib/gs_wan_e.ps">lib/gs_wan_e.ps</a>.

<dt>
Additional:
<dd>
<a href="../lib/gs_il2_e.ps">lib/gs_il2_e.ps</a>,
<a href="../lib/gs_ksb_e.ps">lib/gs_ksb_e.ps</a>,
<a href="../lib/gs_wl1_e.ps">lib/gs_wl1_e.ps</a>,
<a href="../lib/gs_wl2_e.ps">lib/gs_wl2_e.ps</a>,
<a href="../lib/gs_wl5_e.ps">lib/gs_wl5_e.ps</a>.

<dt>
Pseudo-encodings for internal use:
<dd>
<a href="../lib/gs_css_e.ps">lib/gs_css_e.ps</a>,
<a href="../lib/gs_lgo_e.ps">lib/gs_lgo_e.ps</a>,
<a href="../lib/gs_lgx_e.ps">lib/gs_lgx_e.ps</a>,
<a href="../lib/gs_mgl_e.ps">lib/gs_mgl_e.ps</a>.

</dl>

<dt>
Miscellaneous:
<dd>

<dl>

<dt>
Image support:
<dd>
<a href="../lib/gs_img.ps">lib/gs_img.ps</a>,

<dt>
Emulation of %disk IODevice:
<dd>
<a href="../lib/gs_diskn.ps">lib/gs_diskn.ps</a>,

<dt>
Other support:
<dd>
<a href="../lib/gs_agl.ps">lib/gs_agl.ps</a>,
<a href="../lib/gs_dscp.ps">lib/gs_dscp.ps</a>,
<a href="../lib/gs_epsf.ps">lib/gs_epsf.ps</a>,
<a href="../lib/gs_pdfwr.ps">lib/gs_pdfwr.ps</a>,
<a href="../lib/gs_rdlin.ps">lib/gs_rdlin.ps</a>.

<dt>
X Windows icon bitmaps:
<dd>
<a href="../lib/gs_l.xbm">lib/gs_l.xbm</a>,
<a href="../lib/gs_l.xpm">lib/gs_l.xpm</a>,
<a href="../lib/gs_l_m.xbm">lib/gs_l_m.xbm</a>,
<a href="../lib/gs_m.xbm">lib/gs_m.xbm</a>,
<a href="../lib/gs_m.xpm">lib/gs_m.xpm</a>,
<a href="../lib/gs_m_m.xbm">lib/gs_m_m.xbm</a>,
<a href="../lib/gs_s.xbm">lib/gs_s.xbm</a>,
<a href="../lib/gs_s.xpm">lib/gs_s.xpm</a>,
<a href="../lib/gs_s_m.xbm">lib/gs_s_m.xbm</a>,
<a href="../lib/gs_t.xbm">lib/gs_t.xbm</a>,
<a href="../lib/gs_t.xpm">lib/gs_t.xpm</a>,
<a href="../lib/gs_t_m.xbm">lib/gs_t_m.xbm</a>.

<dt>
PDF/X-3 definition file sample :
<dd>
<a href="../lib/PDFX_def.ps">lib/PDFX_def.ps</a>,

<dt>
Not currently used:
<dd>
<a href="../lib/gs_cmdl.ps">lib/gs_cmdl.ps</a>,
<a href="../lib/gs_fform.ps">lib/gs_fform.ps</a>,
<a href="../lib/gs_l2img.ps">lib/gs_l2img.ps</a>.

</dl>

</dl>

<h3><a name="PDF_interpreter"></a>PDF interpreter</h3>

<p>
Ghostscript's PDF interpreter is written entirely in PostScript, because its
data structures are the same as PostScript's, and it is much more convenient
to manipulate PostScript-like data structures in PostScript than in C.
There is definitely a performance cost, but apparently not a substantial
one: we considered moving the main interpreter loop (read a token using
slightly different syntax than PostScript, push it on the stack if literal,
look it up in a special dictionary for execution if not) into C, but we did
some profiling and discovered that this wasn't accounting for enough of the
time to be worthwhile.

<p>
Until recently, there was essentially no C code specifically for the purpose
of supporting PDF interpretation.  The one major exception is the PDF 1.4
transparency features, which we (but not Adobe) have made available to
PostScript code.

<p>
In addition to patching the <b><tt>run</tt></b> operator to detect PDF
files, the interpreter provides some procedures in <a
href="../lib/pdf_main.ps">lib/pdf_main.ps</a> that are meant to be called
from applications such as previewers.

<dl>

<dt>
Files:
<dd>
<a href="../lib/pdf_base.ps">lib/pdf_base.ps</a>,
<a href="../lib/pdf_draw.ps">lib/pdf_draw.ps</a>,
<a href="../lib/pdf_font.ps">lib/pdf_font.ps</a>,
<a href="../lib/pdf_main.ps">lib/pdf_main.ps</a>,
<a href="../lib/pdf_rbld.ps">lib/pdf_rbld.ps</a>,
<a href="../lib/pdf_ops.ps">lib/pdf_ops.ps</a>,
<a href="../lib/pdf_sec.ps">lib/pdf_sec.ps</a>.
</dl>

<p>
Extraction of layer information from Illustratir CS2/CS3 PDF files is
implemented for a specific commercial customer; it is not used by any of the
included drivers. To activate this feature add
<b><tt>cslayer.dev</tt></b> to the list of feature devices.
<dl>
Files:
<dt>
<dd>
<a href="../lib/pdf_cslayer.ps">lib/pdf_cslayer.ps</a>,
</dl>

<h3><a name="PPD"></a>PostScript Printer Description</h3>
<p>
A PostScript Printer Description tells a generic PostScript printer 
driver how to generate PostScript for a particular printer.
Ghostscript includes a PPD file for generating PostScript 
intended to be converted to PDF.  A Windows INF file for
installing the PPD on Windows 2000 and XP is included.

<dl>

<dt>
Files:
<dd>
<a href="../lib/ghostpdf.ppd">lib/ghostpdf.ppd</a>,
<a href="../lib/ghostpdf.inf">lib/ghostpdf.inf</a>.

</dl>

<h3><a name="Build_process"></a>Build process</h3>

<h4><a name="Makefile_structure"></a>Makefile structure</h4>

<p>
Ghostscript's makefiles embody a number of design decisions and assumptions
that may not be obvious from a casual reading of the code.

<ul>

<li>All files are stored in subdirectories.  The names of all subdirectories
used in the build process are defined in the top-level makefiles for the
various platforms: there are no "hard wired" directory names in any makefile
rule.  Subdirectory names in the makefiles are relative to the directory
that is current at build time: normally this directory is the parent of the
various subdirectories, and holds only a <b><tt>makefile</tt></b>, which in
turn simply references the real top-level makefile in the source
subdirectory.

<li>All compiler and linker switches are likewise defined by macros, again
preferably in the top-level platform makefile.

<li>There is an absolute distinction between "source-like" subdirectories,
which are read-only during the build process, and "object-like"
subdirectories, all of whose contents are generated by the build process and
which can be emptied (<b><tt>rm&nbsp;*</tt></b>) at any time with no bad
effects.  The source subdirectories are defined by macros named
<b><tt>xxxSRCDIR</tt></b>.

<li>Object subdirectories may distinguish further between those that hold
the results of the build process that are needed at run time (i.e., that
should be included in a run-time distribution), defined by
<b><tt>BINDIR</tt></b>, and those that are not needed at run time, defined
by <b><tt>xxxGENDIR</tt></b> and <b><tt>xxxOBJDIR</tt></b>.  (The
distinction between these is historical and probably no longer relevant.)

<li>There may be multiple object subdirectories for different build
configurations.  On Unix, the <b><tt>obj</tt></b> and <b><tt>bin</tt></b>
directories are used for normal production builds, the
<b><tt>debugobj</tt></b> directory for debugging builds, and the
<b><tt>pgobj</tt></b> directory for profiling builds; other platforms may
use different conventions.  The Unix makefiles support targets named
<b><tt>debug</tt></b> and <b><tt>pg</tt></b> for debugging and profiling
builds respectively; other platforms generally do not.

<li>Makefiles will be maintained by hand.  This requires editing the
following makefile elements whenever the relevant source files changes:

<ul>

<li>Every header (.h) file must have a corresponding macro definition in a
makefile.  If <b><tt>abc.h</tt></b> #includes <b><tt>def.h</tt></b> and
<b><tt>xyz.h</tt></b>, the definition must have the form

<blockquote><pre>
xyz_h=$(xxxSRCD)xyz.h $(def_h) $(xyz_h)
</pre></blockquote>

where <b><tt>xxxSRCD</tt></b> is the macro defining the relevant source
directory (including a trailing '/').  Note that the '.' in the file name
has been replaced by an underscore.  Note also that the definition must
follow all definitions it references, since some <b><tt>make</tt></b>
programs expand macros in definitions at the time of definition rather than
at the time of use.

<li>Every .c file must have a corresponding rule in a makefile.  If
<b><tt>abc.c</tt></b> #includes <b><tt>def.h</tt></b> and
<b><tt>lmn.h</tt></b>, the rule must have approximately the form

<blockquote><pre>
$(xxxOBJD)abc.$(OBJ) : $(xxxSRCD)abc.c $(def_h) $(lmn_h)
    $(xxCC) $(xxO_)abc.$(OBJ) $(C_) $(xxxSRCD)abc.c
</pre></blockquote>

where <b><tt>xxxSRCD</tt></b> is as before; <b><tt>xxxOBJD</tt></b> is the
relevant object directory; <b><tt>xxCC</tt></b> defines the name of the C
compiler plus the relevant compilation switches; and <b><tt>xxO_</tt></b>
and <b><tt>C_</tt></b> are macros used to bridge syntactic differences
between different <b><tt>make</tt></b> programs.

</ul>

</ul>

<p>
The requirement to keep makefiles up to date by hand has been controversial.
Two alternatives are generally proposed.

<ul>

<li>Programs like <b><tt>makedeps</tt></b>, which generate build rules
automatically from the #include lists in C files.  We have found such
programs useless: they "wire in" specific, concrete directory names, not
only for our own code but even for the system header files; they have to be
run manually whenever code files are added, renamed, or deleted, or whenever
the list of #includes in any file changes; and they cannot deal with
different source files requiring different compilation switches.

<li>MSVC-style "project" files.  These are equally useless: they are not
portable across different vendors' tools -- in fact, there may not even be a
usable import/export facility to convert their data to or from text form --
and they cannot combine configuration-independent data with
configuration-specific data.

</ul>

<p>
We have seriously considered writing our own build program in Tcl or Python
that would eliminate these problems, or perhaps porting the tools developed
by Digital's Vesta research project (if we can get access to them); however,
either of these approaches would create potential portability problems of
its own, not to mention difficulties in integrating with others' build
systems.

<p>
For more information about makefiles:

<ul>

<li>For a detailed list of makefiles, and a discussion of makefile issues
related to portability, see the <a href="#Makefiles">Makefiles</a> section
below.

<li>For more detailed information about editing configuration information in
makefiles, see <a
href="Make.htm#Makefile_overview">doc/Make.htm#Makefile_overview</a>.

<li>For a complete example of adding a new driver to a makefile, see <a
href="Drivers.htm#Adding_drivers">doc/Drivers.htm#Adding_drivers</a>.

<li>For a few more notes on makefile coding conventions, see <a
href="C-style.htm#Makefiles">doc/C-style.htm#Makefiles</a>.

</ul>

<h4><a name="dev_files"></a>.dev files</h4>

<p>
On top of the general conventions just described, Ghostscript's makefiles
add a further layer of structure in order to support an open-ended set of
fine-grained, flexible configuration options.  Selecting an option (usually
called a "module") for inclusion in the build may affect the build in many
ways:

<ul>

<li>Almost always, it requires linking in some compiled code files.

<li>It may require running some additional initialization procedures at
startup.

<li>It may require reading in some additional PostScript files at startup.
For example, a Level 2 PostScript build requires support for PostScript
resources and for setpagedevice, which are implemented in PostScript code.

<li>It may require adding entries to a variety of internal tables that
catalogue such things as drivers, IODevices, Function types, etc.

<li>It may require that other particular modules be included.  For example,
the "PostScript Level 2" module requires the modules for various filters,
color spaces, etc.

<li>It may require <em>removing</em> some other (default) module from the
build.  For example, the core (Level 1) PostScript build has a "stub" for
binary tokens, which are a Level 2 feature but are referenced by the core
scanner: a Level 2 build must remove the stub.  For more information about
this, look for the string <b><tt>-replace</tt></b> in the makefiles and in
<a href="../src/genconf.c">src/genconf.c</a>.

</ul>

<p>
Each module is defined in the makefiles by rules that create a file named
<b><em>xxx</em><tt>.dev</tt></b>.  The dependencies of the rule include all
the files that make up the module (compiled code files, PostScript files,
etc.); the body of the rule creates the .dev file by writing the description
of the module into it.  A program called <b><tt>genconf</tt></b>, described
in the next section, merges all the relevant .dev files together.  For
examples of .dev rules, see any of the Ghostscript makefiles.

<p>
Ultimately, a person must specify the root set of modules to include in a
build (which of course may require other modules, recursively).
Ghostscript's makefiles do this with a set of macros called
<b><tt>FEATURE_DEVS</tt></b> and <b><tt>DEVICE_DEVS</tt>n</b>, defined in
each top-level makefile, but nothing in the module machinery depends on
this.

<h4><a name="Generators"></a>Generators</h4>

<p>
Ghostscript's build procedure is somewhat unusual in that it compiles and
then executes some support programs during the build process.  These
programs then generate data or source code that is used later on in the
build.

<p>
The most important and complex of the generator programs is
<b><tt>genconf</tt></b>.  <b><tt>genconf</tt></b> merges all the .dev files
that make up the build, and creates three or more output files used in later
stages:

<ul>

<li><b><tt>gconfig.h</tt></b>, consisting mainly of macro calls, one call
per "resource" making up the build, other than "resources" listed in the
other output files.

<li><b><tt>gconfigf.h</tt></b>, produced only for PostScript builds with
compiled-in fonts, consisting of one macro call per font.

<li>A linker control file whose name varies from one platform to another,
containing the list of compiled code files to be linked.

<li>If necessary, another linker control file, also varying between
platforms, that contains other information for the linker such as the list
of system libraries to be searched.  (On Unix platforms, the two linker
control functions are combined in a single file.)

</ul>

<dl>

<dt>
Source generators:
<dd>

<dl>

<dt>
<a href="../src/genarch.c">src/genarch.c</a>
<dd>
Creates a header file containing a variety of information about the hardware
and compiler that isn't provided in any standard system header file.  Always
used.

<dt>
<a href="../src/genconf.c">src/genconf.c</a> (also generates non-source)
<dd>
Constructs header files and linker control files from the collection of
options and modules that make up the build.  See above.  Always used.

<dt>
<a href="../src/genht.c">src/genht.c</a>
<dd>
Converts a PostScript halftone (in a particular constrained format) to a C
data structure that can be compiled into an executable.  Only used if any
such halftones are included in the build.

<dt>
<a href="../src/geninit.c">src/geninit.c</a>
<dd>
Converts PostScript initialization files to a single PostScript file that
has comments removed and optionally, a C data structure that can be
compiled into an executable.  Only used when building a PostScript
interpreter, and only if <b><tt>COMPILE_INITS</tt></b> was set to 1 in the
makefile.

<dt>
<a href="../src/mkromfs.c">src/mkromfs.c</a>
<dd>
Takes a set of directories, and creates a compressed filesystem
image that can be compiled into the executable as static data and accessed
through the %rom% iodevice prefix. This is used to implement the
<b><tt>COMPILE_INITS=1</tt></b> feature (a compressed init fileset is more
efficient than the current 'gsinit.c' produced by 'geninit.c'). This IODevice
is more versatile since other files can be encapsulated such as fonts, helper
PostScript files and Resources. The list of files is defined in part in 
<a href="../src/psromfs.mak">src/psromfs.mak</a>.

</dl>

<dt>
Other generators:
<dd>

<dl>

<dt>
<a href="../src/echogs.c">src/echogs.c</a>
<dd>
Implements a variety of shell-like functions to get around quirks,
limitations, and omissions in the shells on various platforms.  Always used.

<dt>
<a href="../src/genconf.c">src/genconf.c</a> (also generates source)
<dd>
See above.

<dt>
<a href="../src/gendev.c">src/gendev.c</a> (not used)
<dd>
Was intended as a replacement for <b><tt>genconf</tt></b>, but was never
completed.

</dl>

</dl>

<h4><a name="Build_support"></a>Support</h4>

<p>
There are a number of programs, scripts, and configuration files that exist
only for the sake of the build process.

<dl>

<dt>
Files for PC environments:
<dd>
<a href="../src/gswin.icx">src/gswin.icx</a>,
<a href="../src/gswin16.icx">src/gswin16.icx</a>,
<a href="../src/bcc32.cfg">src/bcc32.cfg</a>,
<a href="../src/cp.bat">src/cp.bat</a>,
<a href="../src/cp.cmd">src/cp.cmd</a>,
<a href="../src/dw32c.def">src/dw32c.def</a>,
<a href="../src/dwmain.rc">src/dwmain.rc</a>,
<a href="../src/dwmain32.def">src/dwmain32.def</a>,
<a href="../src/dwsetup.def">src/dwsetup.def</a>,
<a href="../src/dwsetup.rc">src/dwsetup.rc</a>,
<a href="../src/dwuninst.def">src/dwuninst.def</a>,
<a href="../src/dwuninst.rc">src/dwuninst.rc</a>,
<a href="../src/gsdll2.def">src/gsdll2.def</a>,
<a href="../src/gsdll2.rc">src/gsdll2.rc</a>,
<a href="../src/gsdll32.def">src/gsdll32.def</a>,
<a href="../src/gsdll32.rc">src/gsdll32.rc</a>,
<a href="../src/gsdll32w.lnk">src/gsdll32w.lnk</a>,
<a href="../src/gsos2.def">src/gsos2.def</a>,
<a href="../src/gsos2.icx">src/gsos2.icx</a>,
<a href="../src/gsos2.rc">src/gsos2.rc</a>,
<a href="../src/gspmdrv.def">src/gspmdrv.def</a>,
<a href="../src/gspmdrv.icx">src/gspmdrv.icx</a>,
<a href="../src/gspmdrv.rc">src/gspmdrv.rc</a>,
<a href="../src/gswin.rc">src/gswin.rc</a>,
<a href="../src/gswin32.rc">src/gswin32.rc</a>,
<a href="../src/mv.bat">src/mv.bat</a>,
<a href="../src/mv.cmd">src/mv.cmd</a>,
<a href="../src/rm.bat">src/rm.bat</a>,
<a href="../src/rm.cmd">src/rm.cmd</a>,
<a href="../src/turboc.cfg">src/turboc.cfg</a>.

<dt>
Files for MacOS:
<dd>
<a href="../lib/Info-macos.plist">lib/Info-macos.plist</a>.

<dt>
Files for OpenVMS:
<dd>
<a href="../src/append_l.com">src/append_l.com</a>,
<a href="../src/copy_one.com">src/copy_one.com</a>,
<a href="../src/rm_all.com">src/rm_all.com</a>,
<a href="../src/rm_one.com">src/rm_one.com</a>.

<dt>
Other files:
<dd>
<a href="../src/bench.c">src/bench.c</a>,
<a href="../src/catmake">src/catmake</a>,
<a href="../src/instcopy">src/instcopy</a>.

</dl>

<h3><a name="Utilities"></a>Utilities</h3>

<p>
Ghostscript comes with many utilities for doing things like viewing bitmap
files and converting between file formats.  Some of these are written in
PostScript, some as scripts, and some as scripts that invoke special
PostScript code.

<h4><a name="Utilities_in_PostScript"></a>Utilities in PostScript</h4>

<p>
These are all documented in <a href="Psfiles.htm">doc/Psfiles.htm</a>, q.v.

<h4><a name="Utility_scripts"></a>Utility scripts</h4>

<p>
Many of these scripts come in both Unix and MS-DOS (<b><tt>.bat</tt></b>
versions; some also have an OS/2 (<b><tt>.cmd</tt></b>) version.  The choice
of which versions are provided is historical and irregular.  These scripts
should all be documented somewhere, but currently, many of them have man
pages, a few have their own documentation in the doc directory, and some
aren't documented at all.

<dl>

<dt>
Script files without PC versions:
<dd>
<a href="../lib/afmdiff.awk">lib/afmdiff.awk</a>,
<a href="../lib/dvipdf">lib/dvipdf</a>,
<a href="../lib/fixmswrd.pl">lib/fixmswrd.pl</a>,
<a href="../lib/lprsetup.sh">lib/lprsetup.sh</a>,
<a href="../lib/pj-gs.sh">lib/pj-gs.sh</a>,
<a href="../lib/pphs">lib/pphs</a>,
<a href="../lib/printafm">lib/printafm</a>,
<a href="../lib/pv.sh">lib/pv.sh</a>,
<a href="../lib/sysvlp.sh">lib/sysvlp.sh</a>,
<a href="../lib/unix-lpr.sh">lib/unix-lpr.sh</a>,
<a href="../lib/wftopfa">lib/wftopfa</a>.

<dt>
Script files with PC versions:
<dd>
<a href="../lib/bdftops">lib/bdftops</a>,
<a href="../lib/bdftops.bat">lib/bdftops.bat</a>,
<a href="../lib/bdftops.cmd">lib/bdftops.cmd</a>,
<a href="../lib/dumphint">lib/dumphint</a>,
<a href="../lib/dumphint.bat">lib/dumphint.bat</a>,
<a href="../lib/eps2eps">lib/eps2eps</a>,
<a href="../lib/eps2eps.bat">lib/eps2eps.bat</a>,
<a href="../lib/eps2eps.cmd">lib/eps2eps.cmd</a>,
<a href="../lib/ps2write.bat">lib/ps2write.bat</a>,
<a href="../lib/ps2write.cmd">lib/ps2write.cmd</a>,
<a href="../lib/ps2ps2">lib/ps2ps2</a>,
<a href="../lib/ps2ps2.bat">lib/ps2ps2.bat</a>,
<a href="../lib/ps2ps2.cmd">lib/ps2ps2.cmd</a>,
<a href="../lib/font2c">lib/font2c</a>,
<a href="../lib/font2c.bat">lib/font2c.bat</a>,
<a href="../lib/font2c.cmd">lib/font2c.cmd</a>,
<a href="../lib/gsbj">lib/gsbj</a>,
<a href="../lib/gsbj.bat">lib/gsbj.bat</a>,
<a href="../lib/gsdj">lib/gsdj</a>,
<a href="../lib/gsdj.bat">lib/gsdj.bat</a>,
<a href="../lib/gsdj500">lib/gsdj500</a>,
<a href="../lib/gsdj500.bat">lib/gsdj500.bat</a>,
<a href="../lib/gslj">lib/gslj</a>,
<a href="../lib/gslj.bat">lib/gslj.bat</a>,
<a href="../lib/gslp">lib/gslp</a>,
<a href="../lib/gslp.bat">lib/gslp.bat</a>,
<a href="../lib/gsnd">lib/gsnd</a>,
<a href="../lib/gsnd.bat">lib/gsnd.bat</a>,
<a href="../lib/pdf2dsc">lib/pdf2dsc</a>,
<a href="../lib/pdf2dsc.bat">lib/pdf2dsc.bat</a>,
<a href="../lib/pdf2ps">lib/pdf2ps</a>,
<a href="../lib/pdf2ps.bat">lib/pdf2ps.bat</a>,
<a href="../lib/pdf2ps.cmd">lib/pdf2ps.cmd</a>,
<a href="../lib/pdfopt">lib/pdfopt</a>,
<a href="../lib/pdfopt.bat">lib/pdfopt.bat</a>,
<a href="../lib/pf2afm">lib/pf2afm</a>,
<a href="../lib/pf2afm.bat">lib/pf2afm.bat</a>,
<a href="../lib/pf2afm.cmd">lib/pf2afm.cmd</a>,
<a href="../lib/pfbtopfa">lib/pfbtopfa</a>,
<a href="../lib/pfbtopfa.bat">lib/pfbtopfa.bat</a>,
<a href="../lib/ps2ascii">lib/ps2ascii</a>,
<a href="../lib/ps2ascii.bat">lib/ps2ascii.bat</a>,
<a href="../lib/ps2ascii.cmd">lib/ps2ascii.cmd</a>,
<a href="../lib/ps2epsi">lib/ps2epsi</a>,
<a href="../lib/ps2epsi.bat">lib/ps2epsi.bat</a>,
<a href="../lib/ps2epsi.cmd">lib/ps2epsi.cmd</a>,
<a href="../lib/ps2pdf">lib/ps2pdf</a>,
<a href="../lib/ps2pdf.bat">lib/ps2pdf.bat</a>,
<a href="../lib/ps2pdf.cmd">lib/ps2pdf.cmd</a>,
<a href="../lib/ps2pdf12">lib/ps2pdf12</a>,
<a href="../lib/ps2pdf12.bat">lib/ps2pdf12.bat</a>,
<a href="../lib/ps2pdf12.cmd">lib/ps2pdf12.cmd</a>,
<a href="../lib/ps2pdf13">lib/ps2pdf13</a>,
<a href="../lib/ps2pdf13.bat">lib/ps2pdf13.bat</a>,
<a href="../lib/ps2pdf13.cmd">lib/ps2pdf13.cmd</a>,
<a href="../lib/ps2pdf14">lib/ps2pdf14</a>,
<a href="../lib/ps2pdf14.bat">lib/ps2pdf14.bat</a>,
<a href="../lib/ps2pdf14.cmd">lib/ps2pdf14.cmd</a>,
<a href="../lib/ps2pdfwr">lib/ps2pdfwr</a>,
<a href="../lib/ps2pdfxx.bat">lib/ps2pdfxx.bat</a>,
<a href="../lib/ps2ps">lib/ps2ps</a>,
<a href="../lib/ps2ps.bat">lib/ps2ps.bat</a>,
<a href="../lib/ps2ps.cmd">lib/ps2ps.cmd</a>.

<dt>
Script files with only PC versions:
<dd>
<a href="../lib/gsndt.bat">lib/gsndt.bat</a>,
<a href="../lib/gssetgs.bat">lib/gssetgs.bat</a>,
<a href="../lib/gst.bat">lib/gst.bat</a>,
<a href="../lib/gstt.bat">lib/gstt.bat</a>,
<a href="../lib/lp386.bat">lib/lp386.bat</a>,
<a href="../lib/lp386r2.bat">lib/lp386r2.bat</a>,
<a href="../lib/lpgs.bat">lib/lpgs.bat</a>,
<a href="../lib/lpr2.bat">lib/lpr2.bat</a>,
<a href="../lib/pftogsf.bat">lib/pftogsf.bat</a>,
<a href="../lib/wmakebat.bat">lib/wmakebat.bat</a>.

</dl>

<hr>

<h2><a name="Memory_management"></a>Memory management</h2>

<h3><a name="Memory_manager_architecture"></a>Memory manager architecture</h3>

<p>
In many environments, the memory manager is a set of library facilities that
implicitly manage the entire address space in a homogenous manner.
Ghostscript's memory manager architecture has none of these properties:

<ul>

<li>Rather than a single library accessed as procedures, Ghostscript
includes multiple allocator types, each of which in turn may have multiple
instances (allocators).  Allocators are 'objects' with a substantial set of
virtual functions.

<li>Rather than managing the entire address space, each allocator manages a
storage pool, which it may or may not be able to expand or reduce by calling
on a 'parent' allocator.

<li>Rather than a single genus of untyped storage blocks, Ghostscript's
allocators provide two genera -- type-tagged 'objects', and 'strings' --
with substantially different properties.

</ul>

<h4><a name="Objects_vs_strings"></a>Objects vs strings</h4>

<p>
As noted above, allocators provide two different storage genera.

<p>
Objects:

<ul>
<li>Are aligned in storage to satisfy the most stringent alignment
requirement imposed by the CPU or compiler;
<li>Can be referenced only by pointers to their start, not to any internal
location, unless special arrangements are made;
<li>May contain pointers to other objects, or to strings;
<li>Have an associated <em>structure descriptor</em> that specifies their
size (usually) and the location of any pointers contained within them.
</ul>

<p>
Given a pointer to an object, the allocator that allocated it must be able
to return the object's size and the pointer to its structure descriptor.
(It is up to the client to know what allocator allocated an object.)

<p>
Strings:

<ul>
<li>Are not aligned in storage;
<li>Can be referenced by pointers (consisting of a starting address and a
length) to any substring, starting anywhere within the string;
<li>May not contain pointers;
<li>Do not have a structure descriptor.
</ul>

<p>
The object/string distinction reflects a space/capability tradeoff.  The
per-object space overhead of the standard type of allocator is typically 12
bytes; this is too much to impose on every string of a few bytes.  On the
other hand, restricting object pointers to reference the start of the object
currently makes object garbage collection and compaction more
space-efficient.  If we were to redesign the standard allocator, we would
probably opt for a different design in which strings were allocated within
container objects of a few hundred bytes, and pointers into the middle of
all objects were allowed.

<h4><a name="Structure_descriptors"></a>Structure descriptors</h4>

<p>
Every object allocated by a Ghostscript allocator has an associated
structure descriptor, which the caller provides when allocating the object.
The structure descriptor serves several purposes:

<ul>
<li>Specifying the size of the object for allocation;
<li>Providing pointer-enumeration and pointer-relocation procedures for
the garbage collector;
<li>Providing an optional finalization procedure to be called when the
object is freed (either explicitly or automatically).
</ul>

<p>
Structure descriptors are read-only, and are normally defined statically
using one of the large set of <b><tt>gs_private_st_</tt></b> or
<b><tt>gs_public_st_</tt></b> macros in <a
href="../src/gsstruct.h">src/gsstruct.h</a>.

<p>
While the structure descriptor normally specifies the size of the object,
one can also allocate an array of bytes or objects, whose size is a multiple
of the size in the descriptor.  For this reason, every object stores its
size as well as a reference to its descriptor.

<p>
Because the standard Ghostscript garbage collector is non-conservative and
can move objects, every object allocated by a Ghostscript allocator must
have an accurate structure descriptor.  If you define a new type of object
(structure) that will be allocated in storage managed by Ghostscript, you
<em>must</em> create an accurate descriptor for it, and use that descriptor
to allocate it.  The process of creating accurate descriptors for all
structures was long and painful, and accounted for many hard-to-diagnose
bugs.

<p>
By convention, the structure descriptor for structure type
<b><tt>xxx_t</tt></b> is named <b><tt>st_xxx</tt></b> (this is preferred),
or occasionally <b><tt>st_xxx_t</tt></b>.

<p>
Note that a structure descriptor is only required for objects allocated by
the Ghostscript allocator.  A structure type <b><tt>xxx_t</tt></b> does not
require a structure descriptor if instances of that type are used
<em>only</em> in the following ways:

<ul>

<li>Instances are allocated only on the C stack, e.g., as
<b><tt>xxx_t&nbsp;xxx1,&nbsp;xxx2;</tt></b>, or on the C heap, with
<b><tt>malloc</tt></b> or through the Ghostscript "wrapper" defined in <a
href="../src/gsmalloc.h">src/gsmalloc.h</a>.

<li>Pointers to instances are not stored in places where the garbage
collector will try to trace the pointer.

<li>Code never attempts to get the structure type or size of an instance
through the allocator API.

</ul>

<p>
In general, structures without descriptors are problem-prone, and are
deprecated; in new code, they should only be used if the structure is
confined to a single .c file and its instances are only allocated on the C
stack.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsstruct.h">src/gsstruct.h</a>,
<a href="../src/gsstype.h">src/gsstype.h</a>.
</dl>

<h4><a name="Garbage_collection"></a>Garbage collection</h4>

<p>
The allocator architecture is designed to support compacting garbage
collection.  Every object must be able to enumerate all the pointers it
contains, both for tracing and for relocation.  As noted just above, the
structure descriptor provides procedures that do this.

<p>
Whether or not a particular allocator type actually provides a garbage
collector is up to the allocator: garbage collection is invoked through a
virtual procedure.  In practice, however, there are only two useful garbage
collectors for Ghostscript's own allocator:

<ul>
<li>The "real" garbage collector associated with the PostScript interpreter,
described <a href="#Interpreter_GC">below</a>;
<li>A "non" garbage collector that only merges adjacent free blocks.
</ul>

<p>
As noted above, because the architecture supports compacting garbage
collection, a "real" garbage collector cannot be run at arbitrary times,
because it cannot reliably find and relocate pointers that are on the C
stack.  In general, it is only safe to run a "real" garbage collector when
control is at the top level of the program, when there are no pointers to
garbage collectable objects from the stack (other than designated roots).

<dl>
<dt>
Files:
<dd>
<a href="../src/gsgc.h">src/gsgc.h</a>,
<a href="../src/gsnogc.c">src/gsnogc.c</a>,
<a href="../src/gsnogc.h">src/gsnogc.h</a>.
</dl>

<h4><a name="Movability"></a>Movability</h4>

<p>
As just noted, objects are normally movable by the garbage collector.
However, some objects must be immovable, usually because some other piece of
software must retain pointers to them.  The allocator API includes
procedures for allocating both movable (default) and immovable objects.
Note, however, that even immovable objects must be traceable (have a
structure descriptor), and may be freed, by the garbage collector.

<h4><a name="Parent_hierarchy"></a>Parent hierarchy</h4>

<p>
When an allocator needs to add memory to the pool that it manages, it
requests the memory from its <em>parent</em> allocator.  Every allocator has
a pointer to its parent; multiple allocators may share a single parent.  The
ultimate ancestor of all allocators that can expand their pool dynamically
is an allocator that calls <b><tt>malloc</tt></b>, described <a
href="#malloc">below</a>.  However, especially in embedded environments, an
allocator may be limited to a fixed-size pool assigned to it when it is
created.

<h4><a name="Allocator_API"></a>Allocator API</h4>

In summary, the allocator API provides the following principal operations:

<ul>
<li>Allocate and free movable (default) or immovable objects and strings.
<li>Return the structure type and size of an object.
<li>Resize (shrink or grow) movable objects and strings, preserving
the contents insofar as possible.
<li>Report the size of the managed pool, and how much of it is in use.
<li>Register and unregister root pointers for the garbage collector.
<li>Free the allocator itself.
<li>Consolidate adjacent free blocks to reduce fragmentation.
</ul>

<p>
For details, see <a href="../src/gsmemory.h">src/gsmemory.h</a>.

<p>
The allocator API also includes one special hook for the PostScript
interpreter: the concept of stable allocators.  See the section on <a
href="#save_forgetsave_restore"><b><tt>save</tt></b> and
<b><tt>restore</tt></b></a> below for details.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsmemraw.h">src/gsmemraw.h</a>,
<a href="../src/gsmemory.c">src/gsmemory.c</a>,
<a href="../src/gsmemory.h">src/gsmemory.h</a>,
<a href="../src/gsstruct.h">src/gsstruct.h</a>,
<a href="../src/gsstype.h">src/gsstype.h</a>.
</dl>

<h3><a name="Freeing_storage"></a>Freeing storage</h3>

<p>
Ghostscript's memory management architecture provides three different ways
to free objects: explicitly, by reference counting, or by garbage
collection.  They provide different safety / performance / convenience
tradeoffs; we believe that all three are necessary.

<p>
Objects are always freed as a whole; strings may be freed piecemeal.

<p>
An object may have an associated finalization procedure, defined in the
structure descriptor.  This procedure is called just before the object is
freed, independent of which method is being used to free the object.  A few
types of objects have a virtual finalization procedure as well: the
finalization procedure defined in the descriptor simply calls the one in the
object.

<h4><a name="Explicit_freeing"></a>Explicit freeing</h4>

<p>
Objects and strings may be freed explicitly, using the
<b><tt>gs_free_</tt></b> virtual procedures in the allocator API.  It is up
to the client to ensure that all allocated objects are freed at most once,
and that there are no dangling pointers.

<p>
Explicit freeing is the fastest method, but is the least convenient and
least safe.  It is most appropriate when storage is freed in the same
procedure where it is allocated, or for storage that is known to be
referenced by only one pointer.

<h4><a name="Reference_counting"></a>Reference counting</h4>

<p>
Objects may be managed by reference counting.  When an object is allocated,
its reference count may be set to 0 or 1.  Subsequently, when the reference
count is decremented to 0, the object is freed.

<p>
The reference counting machinery provides its own virtual finalization
procedure for all reference-counted objects.  The machinery calls this
procedure when it is about to free the object (but not when the object is
freed in any other way, which is probably a design bug).  This is in
addition to (and called before) any finalization procedure associated with
the object type.

<p>
Reference counting is as fast as explicit freeing, but takes more space in
the object.  It is most appropriate for relatively large objects which are
referenced only from a small set of pointers.  Note that reference counting
cannot free objects that are involved in a pointer cycle (e.g., A -> B -> C
-> A).

<dl>
<dt>
Files:
<dd>
<a href="../src/gsrefct.h">src/gsrefct.h</a>.
</dl>

<h4><a name="Real_garbage_collection"></a>(Real) garbage collection</h4>

<p>
Objects and strings may be freed automatically by a garbage collector.  See
<a href="#Interpreter_GC">below</a>.

<h3><a name="Special_implementations"></a>Special implementations</h3>

<h4><a name="malloc"></a>malloc</h4>

<p>
As mentioned <a href="#Parent_hierarchy">above</a>, the ultimate ancestor of
all allocators with an expandable pool is one that calls
<b><tt>malloc</tt></b>.

<p>Note that the default gsmalloc.c allocator for malloc/free now uses
a mutex so that allocators that use this can be assured of thread safe
behavior.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsmalloc.h">src/gsmalloc.h</a>,
<a href="../src/gsmalloc.c">src/gsmalloc.c</a>.
</dl>

<h4><a name="Locking"></a>Locking</h4>

<p>
In a multi-threaded environment, if an allocator must be callable from
multiple threads (for example, if it is used to allocate structures in one
thread that are passed to, and freed by, another thread), the allocator must
provide mutex protection.  Ghostscript provides this capability in the form
of a <em>wrapper</em> allocator, that simply forwards all calls to a
<em>target</em> allocator under protection of a mutex.  Using the wrapper
technique, any allocator can be made thread-safe.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsmemlok.h">src/gsmemlok.h</a>,
<a href="../src/gsmemlok.c">src/gsmemlok.c</a>.
</dl>

<h4><a name="Retrying"></a>Retrying</h4>

<p>
In an embedded environment, job failure due to memory exhaustion is very
undesirable.  Ghostscript provides a wrapper allocator that, when an
allocation attempt fails, calls a client-provided procedure that can attempt
to free memory, then ask for the original allocation to be retried.  For
example, such a procedure can wait for a queue to empty, or can free memory
occupied by caches.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsmemret.h">src/gsmemret.h</a>,
<a href="../src/gsmemret.c">src/gsmemret.c</a>.
</dl>

<h4><a name="Chunk"></a>Chunk</h4>

<p>When multiple threads are used and there may be frequent memory allocator
requests, mutex contention is a problem and can cause severe performance
degradation. The chunk memory wrapper can provide each thread with its own
instance of an allocator that only makes requests on the underlying (non-GC)
alloctor when large blocks are needed. Small object allocations are managed
within chunks.

<p>This allocator is intended to be used on top of the basic 'gsmalloc'
allocator (malloc/free) which is NOT garbage collected or relocated and
which MUST be mutex protected.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsmchunk.h">src/gsmchunk.h</a>,
<a href="../src/gsmchunk.c">src/gsmchunk.c</a>.
</dl>

<h3><a name="Standard_implementation"></a>Standard implementation</h3>

<p>
The standard Ghostscript allocator gets storage from its parent (normally
the <b><tt>malloc</tt></b> allocator) in large blocks called
<em>chunks</em>, and then allocates objects up from the low end and strings
down from the high end.  Large objects or strings are allocated in their own
chunk.

<p>
The standard allocator maintains a set of free-block lists for small object
sizes, one list per size (rounded up to the word size), plus a free-block
list for large objects (but not for objects so large that they get their own
chunk: when such an object is freed, its chunk is returned to the parent).
The lists are not sorted; adjacent blocks are only merged if needed.

<p>
While the standard allocator implements the generic allocator API, and is
usable with the library alone, it includes a special hook for the PostScript
interpreter to aid in the efficient allocation of PostScript composite
objects (arrays and dictionaries).  See the section on <a
href="#Refs">Refs</a> below for details.

<dl>
<dt>
Files:
<dd>
<a href="../src/gsalloc.c">src/gsalloc.c</a>,
<a href="../src/gsalloc.h">src/gsalloc.h</a>,
<a href="../src/gxalloc.h">src/gxalloc.h</a>,
<a href="../src/gxobj.h">src/gxobj.h</a>.
</dl>

<h3><a name="PostScript_interpreter_extensions"></a>PostScript interpreter extensions</h3>

<p>
The PostScript interpreter uses an allocator that extends the graphic
library's standard allocator to handle PostScript objects,
<b><tt>save</tt></b> and <b><tt>restore</tt></b>, and real garbage
collection.

<h4><a name="Refs"></a>Refs (PostScript "objects")</h4>

<p>
Ghostscript represents what the PLRM calls PostScript "objects" using a
structure called a <b><tt>ref</tt></b>, defined in <a
href="../src/iref.h">src/iref.h</a>; packed refs, used for the elements of
packed arrays, are defined in <a href="../src/ipacked.h">src/ipacked.h</a>.
See those files for detailed information.

<dl>
<dt>
Files:
<dd>
<a href="../src/ipacked.h">src/ipacked.h</a>,
<a href="../src/iref.h">src/iref.h</a>.
</dl>

<p>
The PLRM calls for two types of "virtual memory" (VM) space: global and
local.  Ghostscript adds a third space, <em>system</em> VM, whose lifetime
is an entire session -- i.e., it is effectively "permanent".  All three
spaces are subject to garbage collection.  There is a separate allocator
instance for each VM space (actually, two instances each for global and
local spaces; see <a href="#save_forgetsave_restore">below</a>).  In a
system with multiple contexts and multiple global or local VMs, each global
or local VM has its own allocator instance(s).

<p>
Refs that represent PostScript composite objects, and therefore include
pointers to stored data, include a 2-bit VM space tag to indicate in which
VM the object data are stored.  In addition to system, global, and local VM,
there is a tag for "foreign" VM, which means that the memory is not managed
by a Ghostscript allocator at all.  Every store into a composite object must
check for <b><tt>invalidaccess</tt></b>: the VM space tag values are chosen
to help make this check efficient.  See <a
href="../src/ivmspace.h">src/ivmspace.h</a>, <a
href="../src/iref.h">src/iref.h</a>, and <a
href="../src/store.h">src/store.h</a> for details.

<dl>
<dt>
Files:
<dd>
<a href="../src/ivmspace.h">src/ivmspace.h</a>.
</dl>

<p>
PostScript composite objects (arrays and dictionaries) are usually small.
Using a separate memory manager object for each composite object would waste
a lot of space for object headers.  Therefore, the interpreter's memory
manager packs multiple composite objects (also called "ref-containing
objects") into a single memory manager object, similar to the way the memory
manager packs multiple objects into a chunk (see <a
href="#Standard_implementation">above</a>).  See <a
href="../src/gxalloc.h">src/gxalloc.h</a> for details.  This memory manager
object has a structure descriptor, like all other memory manager objects.

<p>
Note that the <b><tt>value.pdict</tt></b>, <b><tt>value.refs</tt></b>, or
<b><tt>value.packed</tt></b> member of a ref must point to a PostScript
composite object, and therefore can point into the middle of a memory
manager object.  This requires special handling by the garbage collector (<a
href="#Interpreter_GC">q.v.</a>).

<dl>
<dt>
Files:
<dd>
<a href="../src/ialloc.c">src/ialloc.c</a>,
<a href="../src/ialloc.h">src/ialloc.h</a>,
<a href="../src/iastate.h">src/iastate.h</a>,
<a href="../src/iastruct.h">src/iastruct.h</a>,
<a href="../src/ilocate.c">src/ilocate.c</a>,
<a href="../src/imemory.h">src/imemory.h</a>,
<a href="../src/istruct.h">src/istruct.h</a>.
</dl>

<h4><a name="save_forgetsave_restore"></a>save/.forgetsave/restore</h4>

<p>
In addition to <b><tt>save</tt></b> and <b><tt>restore</tt></b>, Ghostscript
provides a <b><tt>.forgetsave</tt></b> operator that makes things as though
a given <b><tt>save</tt></b> had never happened.  (In data base terminology,
<b><tt>save</tt></b> is "begin transaction", <b><tt>restore</tt></b> is
"abort transaction", and <b><tt>.forgetsave</tt></b> is "end/commit
transaction").  <b><tt>.forgetsave</tt></b> was implemented for a specific
commercial customer (who may no longer even be using it): it was a pain to
make work, but it's in the code now, and should be maintained.  See the
extensive comments in <a href="../src/isave.c">src/isave.c</a> for more
information about how these operations work.

<dl>
<dt>
Files:
<dd>
<a href="../src/idosave.h">src/idosave.h</a>,
<a href="../src/isave.c">src/isave.c</a>,
<a href="../src/isave.h">src/isave.h</a>,
<a href="../src/isstate.h">src/isstate.h</a>,
<a href="../src/store.h">src/store.h</a>.
</dl>

<h4><a name="Stable_allocators"></a>Stable allocators</h4>

<p>
Even though <b><tt>save</tt></b> and <b><tt>restore</tt></b> are concepts
from the PostScript interpreter, the generic allocator architecture and API
include a feature to support them, called <em>stable</em> allocators.  Every
allocator has an associated stable allocator, which tags pointers with the
same VM space number but which is not subject to <b><tt>save</tt></b> and
<b><tt>restore</tt></b>.  System VM is intrinsically stable (its associated
stable allocator is the same allocator), so there are only 5 allocators in
ordinary single-context usage: system VM, stable global VM, ordinary global
VM, stable local VM, ordinary local VM.

<p>
The reason that we cannot simply allocate all stable objects in system VM is
that their refs must still be tagged with the correct VM space number, so
that the check against storing pointers from global VM to local VM can be
enforced properly.

<p>
All PostScript objects are normally allocated with the non-stable
allocators.  The stable allocators should be used with care, since using
them can easily create dangling pointers: if storage allocated with a stable
allocator contains any references to PostScript objects, the client is
responsible for ensuring that the references don't outlive the referenced
objects, normally by ensuring that any such referenced objects are allocated
at the outermost <b><tt>save</tt></b> level.

<p>
The original reason for wanting stable allocators was the PostScript stacks,
which are essentially PostScript arrays but are not subject to
<b><tt>save</tt></b> and <b><tt>restore</tt></b>.  Some other uses of stable
allocators are:

<ul>

<li>Several per-context structures for DPS.

<li>Paths (see <b><tt>gstate_path_memory</tt></b> in
<a href="../src/gsstate.c">src/gsstate.c</a>.

<li>Row buffers for images (see <b><tt>gs_image_row_memory</tt></b> in <a
href="../src/gsimage.c">src/gsimage.c</a>), because the data-reading
procedure for an image can invoke <b><tt>save</tt></b> and
<b><tt>restore</tt></b>.

<li>Notification lists for fonts, to handle the sequence allocate .. save
.. register .. restore.

<li>The parameter lists for pdfwrite and pswrite devices (in <a
href="../src/gdevpsdp.c">src/gdevpsdp.c</a>), because the whole issue of
local vs. global VM for setpagedevice is, in the words of Ed Taft of Adobe,
"a mess".

<li>Many places in the pdfwrite driver, because many of its bookkeeping
structures must not be restorable.

</ul>

<p>
For more specific examples, search the sources for references to
<b><tt>gs_memory_stable</tt></b>.

<h4><a name="Interpreter_GC"></a>Garbage collection</h4>

<p>
The interpreter's garbage collector is a compacting, non-conservative,
mark-and-sweep collector.

<ul>
<li>It compacts storage because that is the only way to avoid permanent
sandbars, which is essential in limited-memory environments.
<li>It is non-conservative because conservative collectors (which attempt
to determine whether arbitrary bit patterns are pointers) cannot compact.
<li>It uses mark-and-sweep, rather than a more modern copying approach,
because it cannot afford the extra memory required for copying.
</ul>

<p>
Because the garbage collector is non-conservative, it cannot be run if there
are any pointers to movable storage from the C stack.  Thus it cannot be run
automatically when the allocator is unable to allocate requested space.
Instead, when the allocator has allocated a given amount of storage (the
<b><tt>vm_threshold</tt></b> amount, corresponding to the PostScript
<b><tt>VMThreshold</tt></b> parameter), it sets a flag that the interpreter
checks in the main loop.  When the interpreter sees that this flag is set,
it calls the garbage collector: at that point, there are no problematic
pointers from the stack.

<p>
Roots for tracing must be registered with the allocator.  Most roots are
registered during initialization.

<p>
"Mark-and-sweep" is a bit of a misnomer.  The garbage collector actually has
5 main phases:

<ul>
<li>Sweep to clear marks;
<li>Trace and mark;
<li>Sweep to compute relocation;
<li>Sweep to relocate pointers;
<li>Sweep and compact.
</ul>

<p>
There is some extra complexity to handle collecting local VM only.  In this
case, all pointers in global VM are treated as roots, and global VM is not
compacted.

<p>
As noted above, PostScript arrays and strings can have refs that point
within them (because of <b><tt>getinterval</tt></b>).  Thus the garbage
collector must mark each element of an array, and even each byte of a
string, individually.  Specifically, it marks objects, refs, and strings
using 3 different mechanisms:

<ul>

<li>Objects have a mark bit in their header: see
<a href="../src/gxobj.h">src/gxobj.h</a>,

<li>Refs and packed refs have a reserved mark bit: see <a
href="../src/iref.h">src/iref.h</a> and <a
href="../src/ipacked.h">src/ipacked.h</a>.

<li>Strings use a separate bit table, with one bit per string byte: see
<a href="../src/gxalloc.h">src/gxalloc.h</a>,

</ul>

<p>
Similarly, it records the relocation information for objects, refs, and
strings differently:

<ul>

<li>Objects record relocation in the object header.

<li>Refs record relocation in unused fields of refs such as nulls that
don't use their <b><tt>value</tt></b> field.  Every memory manager object
that stores ref-containing objects as described above has an extra, unused
ref at the end for this purpose.

<li>Strings use a separate relocation table.

</ul>

<dl>
<dt>
Files:
<dd>
<a href="../src/igc.c">src/igc.c</a>,
<a href="../src/igc.h">src/igc.h</a>,
<a href="../src/igcref.c">src/igcref.c</a>,
<a href="../src/igcstr.c">src/igcstr.c</a>,
<a href="../src/igcstr.h">src/igcstr.h</a>,
<a href="../src/ireclaim.c">src/ireclaim.c</a>.
</dl>

<hr>

<h2><a name="Portability"></a>Portability</h2>

<p>
One of Ghostscript's most important features is its great portability across
platforms (CPUs, operating systems, compilers, and build tools).  The code
supports portability through two mechanisms:

<ul>

<li><a href="#Structural">Structural mechanisms</a> -- segregating
platform-dependent information into files in a particular way.

<li><a href="#Coding">Coding standards</a> -- avoiding relying on byte
order, scalar size, and platform-specific compiler or library features.

</ul>

<h3><a name="Structural"></a>Structural</h3>

<h4><a name="CPU_and_compiler"></a>CPU and compiler</h4>

<p>
Ghostscript attempts to discover characteristics of the CPU and compiler
automatically during the build process, by compiling and then executing a
program called <b><tt>genarch</tt></b>.  <b><tt>genarch</tt></b> generates a
file <b><tt>obj/arch.h</tt></b>, which almost all Ghostscript files then
include.  This works well for things like word size, byte order, and
floating point representation, but it can't determine whether or not a
compiler supports a particular feature, because if a feature is absent, the
compilation may fail.

<dl>
<dt>
Files:
<dd>
<a href="../src/genarch.c">src/genarch.c</a>,
<a href="../obj/arch.h">obj/arch.h</a>.
</dl>

<h4><a name="Library_headers"></a>Library headers</h4>

<p>
Despite the supposed standardization of ANSI C, platforms vary considerably
in where (and whether) they provide various standard library facilities.
Currently, Ghostscript's build process doesn't attempt to sort this out
automatically.  Instead, for each library header file
<b><tt>&lt;</tt></b><em>xxx</em><b><tt>.h&gt;</tt></b> there is a
corresponding Ghostscript source file
<b><tt>src/</tt></b><em>xxx</em><b><tt>_.h</tt></b>, containing a set of
compile-time conditionals that attempt to select the correct platform header
file, or in some cases substitute Ghostscript's own code for a missing
facility.  You may need to edit these files when moving to platforms with
unusually non-standard libraries.

<dl>
<dt>
Files:
<dd>
<a href="../src/ctype_.h">src/ctype_.h</a>,
<a href="../src/dirent_.h">src/dirent_.h</a>,
<a href="../src/dos_.h">src/dos_.h</a>,
<a href="../src/errno_.h">src/errno_.h</a>,
<a href="../src/fcntl_.h">src/fcntl_.h</a>,
<a href="../src/jerror_.h">src/jerror_.h</a>,
<a href="../src/malloc_.h">src/malloc_.h</a>,
<a href="../src/math_.h">src/math_.h</a>,
<a href="../src/memory_.h">src/memory_.h</a>,
<a href="../src/pipe_.h">src/pipe_.h</a>,
<a href="../src/png_.h">src/png_.h</a>,
<a href="../src/setjmp_.h">src/setjmp_.h</a>,
<a href="../src/stat_.h">src/stat_.h</a>,
<a href="../src/stdint_.h">src/stdint_.h</a>,
<a href="../src/stdio_.h">src/stdio_.h</a>,
<a href="../src/string_.h">src/string_.h</a>,
<a href="../src/time_.h">src/time_.h</a>,
<a href="../src/unistd_.h">src/unistd_.h</a>,
<a href="../src/vmsmath.h">src/vmsmath.h</a>,
<a href="../src/windows_.h">src/windows_.h</a>,
<a href="../src/x_.h">src/x_.h</a>.
</dl>

<p>
It has been suggested that the GNU <b><tt>configure</tt></b> scripts do the
above better, for Unix systems, than Ghostscript's current methods.  While
this may be true, we have found <b><tt>configure</tt></b> scripts difficult
to write, understand, and maintain; and the <b><tt>autoconf</tt></b> tool
for generating <b><tt>configure</tt></b> scripts, which we found easy to
use, doesn't cover much of the ground that Ghostscript requires.

<h4><a name="Cross_platform_APIs"></a>Cross-platform APIs</h4>

<p>
For a few library facilities that are available on all platforms but are not
well standardized, or that may need to be changed for special environments,
Ghostscript defines its own APIs.  It is an architectural property of
Ghostscript that the implementations of these APIs are the only .c files for
which the choice of platform (as opposed to choices of drivers or optional
features) determines whether they are compiled and linked into an
executable.

<dl>

<dt>
API:
<dd>
<a href="../src/gp.h">src/gp.h</a>,
<a href="../src/gpcheck.h">src/gpcheck.h</a>,
<a href="../src/gpgetenv.h">src/gpgetenv.h</a>,
<a href="../src/gpmisc.h">src/gpmisc.h</a>,
<a href="../src/gpsync.h">src/gpsync.h</a>.

<dt>
Implementation files shared among multiple platforms:
<dd>
<a href="../src/gp_getnv.c">src/gp_getnv.c</a>,
<a href="../src/gp_mktmp.c">src/gp_mktmp.c</a>,
<a href="../src/gp_nsync.c">src/gp_nsync.c</a>,
<a href="../src/gp_psync.c">src/gp_psync.c</a>,
<a href="../src/gp_strdl.c">src/gp_strdl.c</a>,
<a href="../src/gpmisc.c">src/gpmisc.c</a>.

<dt>
Platform-specific implementation files:
<dd>
<a href="../src/gp_dosfe.c">src/gp_dosfe.c</a>,
<a href="../src/gp_dosfs.c">src/gp_dosfs.c</a>,
<a href="../src/gp_dvx.c">src/gp_dvx.c</a>,
<a href="../src/gp_iwatc.c">src/gp_iwatc.c</a>,
<a href="../src/gp_msdos.c">src/gp_msdos.c</a>,
<a href="../src/gp_mshdl.c">src/gp_mshdl.c</a>,
<a href="../src/gp_msio.c">src/gp_msio.c</a>,
<a href="../src/gp_mslib.c">src/gp_mslib.c</a>,
<a href="../src/gp_mswin.c">src/gp_mswin.c</a>,
<a href="../src/gp_mswin.h">src/gp_mswin.h</a>,
<a href="../src/gp_ntfs.c">src/gp_ntfs.c</a>,
<a href="../src/gp_os2.c">src/gp_os2.c</a>,
<a href="../src/gp_os2.h">src/gp_os2.h</a>,
<a href="../src/gp_os9.c">src/gp_os9.c</a>,
<a href="../src/gp_stdia.c">src/gp_stdia.c</a>,
<a href="../src/gp_stdin.c">src/gp_stdin.c</a>,
<a href="../src/gp_sysv.c">src/gp_sysv.c</a>,
<a href="../src/gp_unifn.c">src/gp_unifn.c</a>,
<a href="../src/gp_unifs.c">src/gp_unifs.c</a>,
<a href="../src/gp_unix.c">src/gp_unix.c</a>,
<a href="../src/gp_unix_cache.c">src/gp_unix_cache.c</a>,
<a href="../src/gp_vms.c">src/gp_vms.c</a>,
<a href="../src/gp_wgetv.c">src/gp_wgetv.c</a>,
<a href="../src/gp_win32.c">src/gp_win32.c</a>,
<a href="../src/gp_wsync.c">src/gp_wsync.c</a>,
<a href="../src/gs_dll_call.h">src/gs_dll_call.h</a>.

</dl>

<h4><a name="Makefiles"></a>Makefiles</h4>

<p>
For information on the structure and conventions used within makefiles, see
the <a href="#Makefile_structure">Makefile structure</a> section above.

<p>
Ghostscript's makefiles are structured very similarly to the cross-platform
library files.  The great majority of the makefiles are portable across all
platforms and all versions of <b><tt>make</tt></b>.  To achieve this, the
platform-independent makefiles must obey two constraints beyond those of the
POSIX <b><tt>make</tt></b> program:

<ul>

<li>No conditionals or <b><tt>include</tt></b>s are allowed.  While most
<b><tt>make</tt></b> programs now provide some form of conditional execution
and some form of inclusion, there is no agreement on the syntax.
(Conditionals and includes are allowed in platform-dependent makefiles; in
fact, an inclusion facility is required.)

<li>There must be a space on both sides of the : that separates the target
of a rule from its dependencies.  This is required for compatibility with
the OpenVMS <b><tt>MMS</tt></b> and <b><tt>MMK</tt></b> programs.

</ul>

<p>
The top-level makefile for each platform (where "platform" includes the OS,
the compiler, and the flavor of <b><tt>make</tt></b>) contains all the build
options, plus <b><tt>include</tt></b>s for the generic makefiles and any
platform-dependent makefiles that are shared among multiple platforms.

<p>
While most of the top-level makefiles build a PostScript and/or PDF
interpreter configuration, there are also a few makefiles that build a test
program that only uses the graphics library without any language
interpreter.  Among other things, this can be helpful in verifying that no
accidental dependencies on the interpreter have crept into the library or
drivers.

<p>
For families of similar platforms, the question arises whether to use
multiple top-level makefiles, or whether to use a single top-level makefile
that may require minor editing for some (or all) platforms.  Ghostscript
currently uses the following top-level makefiles for building interpreter
configurations:

<ul>

<li>POSIX systems (inluding Linux and Unix):
<ul>
<li><a href="../src/configure.ac">src/configure.ac</a>,
GNU Autoconf source script for automatic build configuration.
<li><a href="../src/Makefile.in">src/Makefile.in</a>,
source for the top-level makefile used in the Autoconf build.
<li><a href="../src/unix-gcc.mak">src/unix-gcc.mak</a>,
for Unix with gcc.
<li><a href="../src/unixansi.mak">src/unixansi.mak</a>,
for Unix with an ANSI C compiler other than gcc.
</ul>

<li>PC:
<ul>
<li><a href="../src/bcwin32.mak">src/bcwin32.mak</a>,
for MS Windows with Borland C++ Builder.
<li><a href="../src/msvc32.mak">src/msvc32.mak</a>,
for MS Windows with Microsoft Visual C (MSVC).
<li><a href="../src/os2.mak">src/os2.mak</a>,
for MS-DOS or OS/2 GCC/EMX environment.
<li><a href="../src/watcw32.mak">src/watcw32.mak</a>,
for MS Windows with Watcom C.
</ul>

<li>Macintosh:
<ul>
<li><a href="../src/macosx.mak">src/macosx.mak</a>,
commandline makefile for MacOS X.
<li><a href="../src/macos-mcp.mak">src/macos-mcp.mak</a>,
dummy makefile to generate an xml project file for Metrowerks Codewarrior.
</ul>


<li>Other:
<ul>
<li><a href="../src/all-arch.mak">src/all-arch.mak</a>,
for building on many Unix systems in a networked test environment.
<li><a href="../src/dvx-gcc.mak">src/dvx-gcc.mak</a>,
for DesqView/X with gcc.
<li><a href="../src/openvms.mak">src/openvms.mak</a>,
for OpenVMS with Digital's CC compiler and the MMS build program.
<li><a href="../src/openvms.mmk">src/openvms.mmk</a>,
for OpenVMS with Digital's CC compiler and the MMK build program.
</ul>

</ul>

<p>
The following top-level makefiles build the library test program:

<ul>
<li><a href="../src/ugcclib.mak">src/ugcclib.mak</a>,
on Unix with gcc.
<li><a href="../src/msvclib.mak">src/msvclib.mak</a>,
on MS Windows with MSVC.
<li><a href="../src/watclib.mak">src/watclib.mak</a>,
on extended MS-DOS with Watcom C.
</ul>

<p>
The MSVC makefiles may require editing to select between different versions
of MSVC, since different versions may have slightly incompatible command
line switches or customary installation path names.  The Unix makefiles
often require editing to deal with differing library path names and/or
library names.  For details, see <a href="Make.htm#Unix_build">the Unix
section</a> of the documentation for building Ghostscript.

<dl>

<dt>
Library test program:
<dd>
<a href="../src/gslib.c">src/gslib.c</a>.

<dt>
Platform-independent makefiles:
<dd>

<dl>

<dt>
Graphics library and support:
<dd>
<a href="../src/contrib.mak">src/contrib.mak</a>,
<a href="../src/devs.mak">src/devs.mak</a>,
<a href="../src/gs.mak">src/gs.mak</a>,
<a href="../src/lib.mak">src/lib.mak</a>,
<a href="../src/version.mak">src/version.mak</a>.

<dt>
PostScript interpreter and fonts:
<dd>
<a href="../src/cfonts.mak">src/cfonts.mak</a>,
<a href="../src/int.mak">src/int.mak</a>,
<a href="../src/wmin.mak">src/wmin.mak</a>.

<dt>
Third-party libraries:
<dd>
<a href="../src/expat.mak">src/expat.mak</a>,
<a href="../src/icclib.mak">src/icclib.mak</a>,
<a href="../src/ijs.mak">src/ijs.mak</a>,
<a href="../src/jasper.mak">src/jasper.mak</a>,
<a href="../src/jbig2.mak">src/jbig2.mak</a>,
<a href="../src/ldf_jb2.mak">src/ldf_jb2.mak</a>,
<a href="../src/lwf_jp2.mak">src/lwf_jp2.mak</a>,
<a href="../src/jpeg.mak">src/jpeg.mak</a>,
<a href="../src/libpng.mak">src/libpng.mak</a>,
<a href="../src/zlib.mak">src/zlib.mak</a>.
</dl>

<dt>
Shared platform-dependent makefiles:
<dd>

<dl>

<dt>
Unix:
<dd>
<a href="../src/unix-aux.mak">src/unix-aux.mak</a>,
<a href="../src/unix-dll.mak">src/unix-dll.mak</a>,
<a href="../src/unix-end.mak">src/unix-end.mak</a>,
<a href="../src/unixhead.mak">src/unixhead.mak</a>,
<a href="../src/unixinst.mak">src/unixinst.mak</a>,
<a href="../src/unixlink.mak">src/unixlink.mak</a>.

<dt>
Microsoft Windows and MS-DOS:
<dd>
<a href="../src/msvccmd.mak">src/msvccmd.mak</a>,
<a href="../src/msvctail.mak">src/msvctail.mak</a>,
<a href="../src/pcwin.mak">src/pcwin.mak</a>,
<a href="../src/wccommon.mak">src/wccommon.mak</a>,
<a href="../src/wctail.mak">src/wctail.mak</a>,
<a href="../src/winint.mak">src/winint.mak</a>,
<a href="../src/winlib.mak">src/winlib.mak</a>,
<a href="../src/winplat.mak">src/winplat.mak</a>.

<dt>
Other:
<dd>
<a href="../src/dvx-head.mak">src/dvx-head.mak</a>,
<a href="../src/dvx-tail.mak">src/dvx-tail.mak</a>.<br>
<a href="../src/macos-fw.mak">src/macos-fw.mak</a>,
for building as a MacOS X Framework.

</dl>

</dl>

<h3><a name="Coding"></a>Coding</h3>

<p>
Coding for portability requires avoiding both <em>explicit</em>
dependencies, such as platform-dependent <b><tt>#ifdef</tt></b>s, and
<em>implicit</em> dependencies, such as dependencies on byte order or the
size of the integral types.

<h4><a name="Explicit_dependencies"></a>Explicit dependencies</h4>

<p>
The platform-independent .c files never, ever, use <b><tt>#ifdef</tt></b> or
<b><tt>#if</tt></b> to select code for specific platforms.  Instead, we
always try to characterize some abstract property that is being tested.  For
example, rather than checking for macros that are defined on those specific
platforms that have 64-bit <b><tt>long</tt></b> values, we define a macro
<b><tt>ARCH_SIZEOF_LONG</tt></b> that can then be tested.  Such macros are
always defined in a .h file, either automatically in <b><tt>arch.h</tt></b>,
or explicitly in a <em>xxx</em><b><tt>_.h</tt></b> file, as described in
earlier sections.

<dl>
<dt>
Files:
<dd>
<a href="../src/std.h">src/std.h</a>,
<a href="../src/stdpn.h">src/stdpn.h</a>,
<a href="../src/stdpre.h">src/stdpre.h</a>.
</dl>

<h4><a name="Implicit_dependencies"></a>Implicit dependencies</h4>

<p>
The most common source of byte ordering dependencies is casting between
types (T1 *) and (T2 *) where T1 and T2 are numeric types that aren't merely
signed/unsigned variants of each other.  To avoid this, the only casts
allowed in the code are between numeric types, from a pointer type to a long
integral type, and between pointer types.

<p>
Ghostscript's code assumes the following about the sizes of various types:

<dl>
<dt>char<dd>8 bits
<dt>short<dd>16 bits
<dt>int<dd>32 or 64 bits
<dt>long<dd>32 or 64 bits
<dt>float<dd>32 bits (may work with 64 bits)
<dt>double<dd>64 bits (may work with 128 bits)
</dl>

<p>
The code does not assume that the <b><tt>char</tt></b> type is signed (or
unsigned); except for places where the value is always a literal string, or
for interfacing to library procedures, the code uses <b><tt>byte</tt></b> (a
Ghostscript synonym for <b><tt>unsigned char</tt></b>) almost everywhere.

<p>
Pointers are signed on some platforms and unsigned on others.  In the few
places in the memory manager where it's necessary to reliably order-compare
(as opposed to equality-compare) pointers that aren't known to point to the
same allocated block of memory, the code uses the
<b><tt>PTR_</tt></b><em>relation</em> macros rather than direct comparisons.

<p>
See the files listed above for other situations where a macro provides
platform-independence or a workaround for bugs in specific compilers or
libraries (of which there are a distressing number).

<h4><a name="Platform_specific_code"></a>Platform-specific code</h4>

<p>
There are some features that are inherently platform-specific:

<ul>

<li>Microsoft Windows requires a lot of special top-level code, and also has
an installer and uninstaller.

<li>OS/2 requires a little special code.

<li>MacOS also requires special top-level code (now distributed with the
standard Ghostscript package).

<li>All platforms supporting DLLs (currently all three of the above) share
some special top-level code.

</ul>

<dl>

<dt>
MS Windows files:
<dd>
<a href="../src/dpmain.c">src/dpmain.c</a>,
<a href="../src/dwdll.c">src/dwdll.c</a>,
<a href="../src/dwdll.h">src/dwdll.h</a>,
<a href="../src/dwimg.c">src/dwimg.c</a>,
<a href="../src/dwimg.h">src/dwimg.h</a>,
<a href="../src/dwinst.cpp">src/dwinst.cpp</a>,
<a href="../src/dwinst.h">src/dwinst.h</a>,
<a href="../src/dwmain.c">src/dwmain.c</a>,
<a href="../src/dwmain.h">src/dwmain.h</a>,
<a href="../src/dwmainc.c">src/dwmainc.c</a>,
<a href="../src/dwnodll.c">src/dwnodll.c</a>,
<a href="../src/dwreg.c">src/dwreg.c</a>,
<a href="../src/dwreg.h">src/dwreg.h</a>,
<a href="../src/dwsetup.cpp">src/dwsetup.cpp</a>,
<a href="../src/dwsetup.h">src/dwsetup.h</a>,
<a href="../src/dwtext.c">src/dwtext.c</a>,
<a href="../src/dwtext.h">src/dwtext.h</a>,
<a href="../src/dwtrace.c">src/dwtrace.c</a>,
<a href="../src/dwtrace.h">src/dwtrace.h</a>,
<a href="../src/dwuninst.cpp">src/dwuninst.cpp</a>,
<a href="../src/dwuninst.h">src/dwuninst.h</a>,
<a href="../src/gp_msdll.c">src/gp_msdll.c</a>,
<a href="../src/gp_mspol.c">src/gp_mspol.c</a>,
<a href="../src/gp_msprn.c">src/gp_msprn.c</a>,
<a href="../src/gsdllwin.h">src/gsdllwin.h</a>.

<dt>
OS/2 files:
<dd>
<a href="../src/gp_os2pr.c">src/gp_os2pr.c</a>,
<a href="../src/gsdllos2.h">src/gsdllos2.h</a>.

<dt>
Unix files:
<dd>
<a href="../src/dxmain.c">src/dxmain.c</a>,
<a href="../src/dxmainc.c">src/dxmainc.c</a>.

<dt>
Macintosh files:
<dd>
<a href="../src/gdevmac.c">src/gdevmac.c</a>,
<a href="../src/gdevmac.h">src/gdevmac.h</a>,
<a href="../src/gdevmacpictop.h">src/gdevmacpictop.h</a>,
<a href="../src/gdevmacttf.h">src/gdevmacttf.h</a>,
<a href="../src/gdevmacxf.c">src/gdevmacxf.c</a>,
<a href="../src/gp_mac.c">src/gp_mac.c</a>,
<a href="../src/gp_mac.h">src/gp_mac.h</a>,
<a href="../src/gp_macio.c">src/gp_macio.c</a>,
<a href="../src/gp_macpoll.c">src/gp_macpoll.c</a>,
<a href="../src/gsiomacres.c">src/gsiomacres.c</a>,
<a href="../src/macgenmcpxml.sh">src/macgenmcpxml.sh</a>,
<a href="../src/macsystypes.h">src/macsystypes.h</a>,
<a href="../src/macos_carbon_pre.h">src/macos_carbon_pre.h</a>,
<a href="../src/macos_carbon_d_pre.h">src/macos_carbon_d_pre.h</a>,
<a href="../src/macos_classic_d_pre.h">src/macos_classic_d_pre.h</a>,

<a href="../src/dmmain.c">src/dmmain.c</a>,
<a href="../src/dmmain.r">src/dmmain.r</a>.

<dt>
VMS files:
<dd>
<a href="../src/vms_x_fix.h">src/vms_x_fix.h</a>.

<dt>
DLL files:
<dd>
<a href="../src/gsdll.c">src/gsdll.c</a>,
<a href="../src/gsdll.h">src/gsdll.h</a>,
<a href="../src/gdevdsp.c">src/gdevdsp.c</a>,
<a href="../src/gdevdsp.h">src/gdevdsp.h</a>,
<a href="../src/gdevdsp2.h">src/gdevdsp2.h</a>,
<a href="../src/iapi.c">src/iapi.c</a>,
<a href="../src/iapi.h">src/iapi.h</a>,
<a href="../src/idisp.c">src/idisp.c</a>,
<a href="../src/idisp.h">src/idisp.h</a>.
<p>
The new DLL interface (new as of 7.0) is especially useful with the
new display device, so it is included here. Both are due to Russell
Lang.

</dl>


<hr>

<h2><a name="Adding_features_and_options"></a>Adding features and options</h2>

<p>
[Ray, please supply more information about what you want here]


<h2><a name="Profiling"></a>Profilinging</h2>

<p>


<h2><a name="Troubleshooting"></a>Troubleshooting</h2>

<p>
The Ghostscript code has many tracing and debugging features that can be
enabled at run time using the <b><tt>-Z</tt></b> command line switch, if the
executable was compiled with <b><tt>DEBUG</tt></b> defined.  One
particularly useful combination is <b><tt>-Z@\?</tt></b>, which fills free
memory blocks with a pattern and also turns on run-time memory consistency
checking.  For more information, see <a
href="Use.htm#Debugging">doc/Use.htm#Debugging</a>; you can also search for
occurrences of <b><tt>if_debug</tt></b> or <b><tt>gs_debug_c</tt></b> in the
source code.  Note that many of these features are in the graphics library
and do not require a PostScript interpreter.

<p>
The code also contains many run-time procedures whose only purpose is to be
called from the debugger to print out various data structures, including all
the procedures in <a href="../src/idebug.c">src/idebug.c</a> (for the
PostScript interpreter) and the <b><tt>debug_dump_</tt></b> procedures in <a
href="../src/gsmisc.c">src/gsmisc.c</a>.

<dl>
<dt>
Files:
<dd>
<a href="Use.htm#Debugging">doc/Use.htm#Debugging</a>,
<a href="../src/gdebug.h">src/gdebug.h</a>,
<a href="../src/gsmdebug.h">src/gsmdebug.h</a>,
<a href="../src/idebug.h">src/idebug.h</a>,
<a href="../src/idebug.c">src/idebug.c</a>.
</dl>

<hr>

<h2><a name="Profiling"></a>Profilinging</h2>
<h3><a name="ProfilingMSVC6"></a>Profiling with Microsoft Developer Studio 6</h3>

<p>
The Microsoft profiling tool is included into Microsoft Developer Studio 6
Enterprise Edition only. Standard Edition and Professional Edition do not include it.

<p>
Microsoft profiler tool requires the application to be linked with
a special linker option. To provide it you need the following change to 
<tt><b>gs/src/msvccmd.mak</tt></b> :

<blockquote><pre><tt> 
 
*** SVN-GS\HEAD\gs\src\msvccmd.mak	Tue Jan  9 21:41:07 2007
--- gs\src\msvccmd.mak	Mon May  7 11:29:35 2007
***************
*** 159,163 ****
  # Note that it must be followed by a space.
  CT=/Od /Fd$(GLOBJDIR) $(NULL) $(CDCC) $(CPCH)
! LCT=/DEBUG /INCREMENTAL:YES
  COMPILE_FULL_OPTIMIZED=    # no optimization when debugging
  COMPILE_WITH_FRAMES=    # no optimization when debugging
--- 159,164 ----
  # Note that it must be followed by a space.
  CT=/Od /Fd$(GLOBJDIR) $(NULL) $(CDCC) $(CPCH)
! # LCT=/DEBUG /INCREMENTAL:YES
! LCT=/DEBUG /PROFILE
  COMPILE_FULL_OPTIMIZED=    # no optimization when debugging
  COMPILE_WITH_FRAMES=    # no optimization when debugging
***************
*** 167,175 ****
  !if $(DEBUGSYM)==0
  CT=
! LCT=
  CMT=/MT
  !else
  CT=/Zi /Fd$(GLOBJDIR) $(NULL)
! LCT=/DEBUG
  CMT=/MTd
  !endif
--- 168,178 ----
  !if $(DEBUGSYM)==0
  CT=
! # LCT=
! LCT=/PROFILE
  CMT=/MT
  !else
  CT=/Zi /Fd$(GLOBJDIR) $(NULL)
! # LCT=/DEBUG
! LCT=/DEBUG /PROFILE
  CMT=/MTd
  !endif

</blockquote></pre></tt>

Note that any of debug and release build may be profiled.
 
<p>
Mictosoft Profiler tool can't profile a dynamically loaded DLLs. 
When building Ghostscript with makefiles you need to specify 
<tt><b>MAKEDLL=0</tt></b> to <tt><b>nmake</tt></b> command line.

<p>
The Integrated Development Environment of Microsoft Developer Studio 6
cannot profile a makefile-based project. Therefore the profiling tool
to be started from command line. 

<p>
The profiling from command line is a 4 step procedure.
The following batch file provides a sample for it :

<blockquote><pre><tt>

set DEVSTUDIO=G:\Program Files\Microsoft Visual Studio
set GS_HOME=..\..\gs-hdp
set GS_COMMAND_LINE=%GS_HOME%\bin\gswin32c.exe -I%GS_HOME%\lib;f:\afpl\fonts -r144 -dBATCH -dNOPAUSE -d/DEBUG attachment.pdf
set START_FUNCTION=_main
set Path=%DEVSTUDIO%\Common\MSDev98\Bin;%DEVSTUDIO%\VC98\Bin
PREP.EXE /OM /SF %START_FUNCTION% /FT   %GS_HOME%\bin\gswin32c.exe  
If ERRORLEVEL 1 echo step 1 fails&exit
PROFILE  /I %GS_HOME%\bin\gswin32c.pbi  %GS_COMMAND_LINE%
If ERRORLEVEL 1 echo step 2 fails&exit
PREP /M %GS_HOME%\bin\gswin32c /OT xxx.pbt 
If ERRORLEVEL 1 echo step 3 fails&exit
PLIST /ST xxx.pbt >profile.txt
If ERRORLEVEL 1 echo step 4 fails&exit

</blockquote></pre></tt>

<p>
This batch file to be adopted to your configuration :

<ul>
<li>
Edit the path to developer studio in the line 1.
<li>
Edit the Ghostscript home directory in the line 2.
<li>
Edit Ghostscript command line in line 3. Note that profiling without /NOPAUSE is a bad idea.
<li>
In the line 4 edit the function name to start the profiling from.
The sample code specifies _main as the starting function.
Note it is the linker's function name, which starts with underscore.
<li>
Edit the output file name in the line 5.
</ul>




<!-- [2.0 end contents] ==================================================== -->

<!-- [3.0 begin visible trailer] =========================================== -->
<hr>

<p>
<small>Copyright &copy; 2001-2006 Artifex Software, Inc.  All rights reserved.</small>

<p>
This software is provided AS-IS with no warranty, either express or
implied.

This software is distributed under license and may not be copied, modified
or distributed except as expressly authorized under the terms of that
license.  Refer to licensing information at http://www.artifex.com/
or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.

<p>
<small>Ghostscript version 8.63, 29 July 2008

<!-- [3.0 end visible trailer] ============================================= -->

</small></body>
</html>