This file is indexed.

/usr/share/lifelines/ps-anc.ll is in lifelines-reports 3.0.61-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
/*
    @prognam      ps-anc
    @version      8.86, 4 Jul 2004
    @author       Robert Simms
    @output       PostScript
    @category     chart making
    @description  PS Charts

    a LifeLines genealogy report program that produces ancestry charts in
    PostScript

    This is an interim version on the way to a release of ps-anc9.
    For a log of changes, visit the web page
      http://www.math.clemson.edu/~rsimms/genealogy/ll/ps-anc/log.html
*/

/*
**  ps-anc,   9 Sep 1994, by Fred Wheeler (wheeler@ipl.rpi.edu)
**  ps-anc2, 16 August 1994, by Fred Wheeler (wheeler@ipl.rpi.edu)
**  ps-anc5, 19 Feb 1996, enhanced by Phil Stringer (P.Stringer@mcc.ac.uk)
**           - all comments/bugs should now go to Phil Stringer
**  ps-anc6, 30 Jan 1997, enhanced by Phil Stringer (P.Stringer@mcc.ac.uk)
**  ps-anc7, 1 Feb 1997, enhanced by Phil Stringer (P.Stringer@mcc.ac.uk)
**  ps-anc8, 18 Mar 1998, enhanced by Robert Simms and Allan Yates,
**                                 rsimms@math.clemson.edu and ayates@nortel.ca
**
**  GETTING THIS FILE
**
**  The ps-anc final release versions are available via the Internet:
**   (1) http://lifelines.sourceforge.net/
**   (1) ftp://ftp.cac.psu.edu/pub/genealogy/lines/reports/
**   (2) http://www.math.clemson.edu/~rsimms/genealogy/ll/
**
**  BRIEF DESCRIPTION
**
**  This LifeLines report program generates Postscript ancestral and
**  descendant charts.  The ancestral charts can include the siblings
**  of all direct ancestors (aunts, uncles, great-aunts, great-uncles,
**  etc.).  A multi-page poster chart can also be generated.  The
**  chart format is based on the program GedChart, by Tom Blumer.
**
**  The Postscript file created can be sent to any size printer; it
**  will automatically adapt the size of the chart.  I send the same
**  file to A-size (8.5 by 11) and B-size (11 by 17) printers.
**
**  After you use this program a few times, you should edit the
**  function interrogate_user().  This is the first function after
**  these comments and the global variable declarations.  This
**  function is set up to make it easy for you to configure what
**  questions this program should ask you each time and what default
**  values it should use for questions not asked.
**
**  Please contact me if you like this program, find any bugs, have
**  any bug fixes, or want to suggest improvements.  I am also always
**  on the lookout for better ancestral/descendant chart generating
**  programs.  If you know of a program that generates charts which
**  you like better than those generated by this program, please drop
**  me a line.
**
**  This report program works with the LifeLines Genealogical database
**  program only.  (see ftp://ftp.cac.psu.edu/pub/genealogy/lines/*)
**
**  CHANGE LOG
**
**  CHANGES since version 1:
**    Completely new descendant chart in addition to ancestral chart
**    Multi-page poster option
**    Multi-page charts scaled correctly (thanks to broman@Np.nosc.mil)
**    Maximum name length configurable by user (fixes long squashed names)
**    Option to suppress siblings of later generations in ancestral charts
**    Checks that user selects a valid person (bug fix)
**    Can make a guess at whether a title is a prefix or suffix type
**    Use of titles is configurable (prefix, suffix, guess, none)
**    Birth/death/marriage date styles are configurable (may include place)
**    Corner message is slightly smaller, and chart will not overlap it
**    Marriage date is printed before death date
**
**  CREDITS
**
**  Code improvements received from:
**    Vincent Broman (broman@Np.nosc.mil)
**
**  Helpful comments received from:
**    Vincent Broman (broman@Np.nosc.mil)
**    Frank H. Flaesland (phranx@imr.no)
**    Linda Wilson (lwilson@mcc.com)
**    Stacy Johnson (sjohnson@oucsace.cs.ohiou.edu)
**    John F. Chandler (jchbn@cuvmb.cc.columbia.edu)
**    Susan Radel
**
**  CHANGES in version 3:
**    Birth/death/marriage date style addition (full date with short place).
**    Examples for including other fonts.
**    Option for bold lines/text for direct line of ascent.
**    Option to start on right or left of page.
**    Option for landscape or portrait format.
**    Small additional space between border and text to improve appearance.
**    Now fills the page if max generations > actual generations.
**    With multi-page output generations are multiple of x-pages to prevent
**      text split over sheets.
**    Option to show aunts/uncles from parents multiple marriages.
**
**  CHANGES in version 4:
**    Border enhanced at the corners.
**    Chart title font changed.
**    Lines now used to join families rather than being used as a framework.
**    Names now adjacent to line or halfway between if in 2 families.
**    Descendant chart has reduced lines and is more tree like
**
**  CHANGES in version 5:
**    Enhanced descendant chart
**    Automatic choice of chart type if no children or no ancestors
**    Multi-page landscape bug fixed
**    Enhancements to user option specification
**    Character set enhanced to iso-8859-1
**    Additional personal titles 
**
**  CHANGES in version 6:
**    Corrected multi-page landscape printing
**    Descriptive title at bottom of chart
**    Smaller and faster PostScript code on multi-page output
**      (previously n-pages had  n * single page size of file)
**    Automatic choice of ancestor/descendant chart if no descendants/ancestors
**    Fixed bug on descendant charts of overprinting if it branched up, and
**      there was a spouse with birth and death details, and no children in
**      that family.
**    Character set inadvertently lost iso-8859-1 support.
**
**  CHANGES in version 7:
**    Fixed bug on descendant charts of overlapping vertical lines if it
**      branched up, and there was a spouse and no children in that family.
**    iso-8859-1 support reinstated.
**    More efficient print_all_persons code from Fred Wheeler
**
**    CREDITS
**
**      Code improvements received from:
**        Phil Stringer (p.stringer@mcc.ac.uk)
**
**  CHANGES in version 8 by Robert Simms and (+) Allan Yates:
**
**   >procedure do_anc:
**    Closed up extra space between branches of the chart by changing
**      min_pos to person_minpos, to be used to keep person from being drawn
**      too high on chart, but not to keep all ancestors of a person from being
**      drawn above this point.  Introduced abs_min_pos as the absolutely
**      highest position for any older siblings or half siblings of a person.
**    Fixed the printing of half siblings to be subject to the sibling depth
**      limit obtained from the interrogate function.
**    Fixed a mis-alignment in half sib. branch vertical line.
**   >procedure do_des:
**    Fixed conditions for drawing vertical line to exclude case where there
**      are children but no spouse and depth = max_depth.  In this case the
**      children heights are never computed so a vertical line can't be drawn.
**   >general:
**    +Added option for displaying surnames in upper case.
**    +Added date option to display the first two items in a place list
**    +Added option for not displaying large descriptive title, print small
**      one instead with title text added
**    +Do not print preceding comma if place exists and date does not exist
**    Fixed positioning of names that caused some names to be too close
**      to vertical lines, eliminating horizontal lines in come cases.
**    Added support in PostScript file for increasing the page margins together
**      with a new question in the interrogate function.  (This required
**      calculation of a clip rectangle since the device clip rectangle would
**      allow redundant display of parts of the chart at adjoining edges in
**      multi-page charts.)  This is useful for imposing a margin when a
**      PostScript file is converted to another format, such as Adobe PDF.
**      This was to prevent the converted file from having a zero margin
**      which doesn't print well on most printers.
**    Centered chart label and coordinated its placement with that of the title
**      to avoid having the two overlap.  This fix became more necessary with
**      the addition of the ability to increase the margins.
**    Added option for centering or left justifying chart label.
**    Replaced tabs in LifeLines code with spaces to avoid irregular
**      indentation.
**    Experimented with putting page drawing code into a procedure to reduce
**      the size of multi-page files.  Determined that doing so would
**      require changing the MaxOpStack limit in PostScript to handle the
**      potentially large number of items that would go into the procedure.
**      This could potentially place a limit on how many individuals
**      could be shown in a chart for some devices.  So, the idea was dropped.
**
**    CREDITS:
**      Phil Stringer, for initiating the min_pos fix in procedure do_anc.
*******************************************************************************
**
**  ABOUT GEDCHART (a different program)
**
**  This program includes PostScript code written by Tom Blumer
**  (blumer@ptltd.com).  It is used here with his permission.  This
**  PostScript code is from Tom Blumer's GedChart package.  The report
**  is very much like that generated by GedChart using the -Sa or -Sd
**  option.
**
**  GedChart is DOS program that generates ancestral and descendant
**  charts like this report program, and also fan charts.  GedChart
**  works directly from a GEDCOM file and is completely independent of
**  LifeLines.  It is currently up to version 1.6, which is a beta
**  version that may lead to a commercial product.  You can find
**  GedChart at ftp:oak.oakland.edu/pub/msdos/genealgy/gedcht16.zip
**
*/

option("explicitvars")  /* to catch misspellings or uninit'ed use of variables*/

/* If translation tables are in effect, and UTF-8 or 8-bit characters are used
   in a custom title, for instance, then it might be necessary to specify what
   codeset the report is using (say ISO-8859-1, ISO-8859-2, UTF-8, etc.)
   to ensure that those 8-bit characters arrive safely in the output
   This is done with the char_encoding() statement... */
/*char_encoding("ISO-8859-1")*/

global(version)              /* version string */
global(TRUE)                 /* int, set to 1 for use as boolean value */
global(FALSE)                /* int, set to 0 for use as boolean value */
global(UP)                   /* int, constant, set to -1 for desc. branches */
global(NEUTRAL)              /* int, constant, set to  0 for desc. branches */
global(DOWN)                 /* int, constant, set to  1 for desc. branches */
global(max_dateplace)        /* int, number of date-place styles */
global(place_modify)         /* boolean, use (included) abbreviation routine */

global(updown_override)      /* int, to force desc. to be all up or all down */
global(high_pos_gen)         /* array, highest so far in each generation */
global(high_pos_gen_offset)  /* used to allow non-positive array indexing */
global(high_depth)           /* int, highest depth so far */
global(low_depth)            /* int, lowest depth so far */

global(name_height)          /* height of name text on chart                */
global(date_height)          /* height of birth/death/marriage date text  */
global(corner_height)        /* space between parent and extreme child 
                              *   -- name_height was formerly used for this */
global(min_sibling_spacer)   /* constant, min. vert. space between siblings */
global(cloaked_depth)        /* used for hidding a gen. from get_clearance */
global(tighten)              /* boolean, descendant branches to be closer */
global(debug)
global(debug2)
global(debug_postscript)

/* variables prompted from or configured by the user */

global(chart_type)           /* int, 0: ancestral, 1: descendant */
global(root_person)          /* indi, person for whom to generate the chart */
global(root_fam)             /* fam, family for combination chart */
global(font_name)            /* string, name of font for individual names*/
global(ifont_name)           /* string, name of font for person info */
global(enc_choice)           /* int, specifies character encoding to use */
global(max_depth)            /* int, maximum number of gen. up from root */
global(min_depth)            /* int, minimum number of gen. down from root */
global(start_depth)          /* int, depth of root, used by reserve() also */
global(chart_label)          /* string, label for corner of chart */
global(chart_label_centered) /* boolean, center chart_label on first page */
global(color_chart)          /* boolean, is chart in color */
global(multi_page)           /* boolean, is chart many page poster type */
global(x_pages)              /* int, number of horizontal pages */
global(y_pages)              /* int, number of vertical pages */
global(name_letters)         /* int, maximum number of letters in a name */
global(title_method)         /* int, code for how to insert titles */
global(depth_siblings)       /* int, number of generations to show siblings */
global(dateplace_birth)      /* int, date style for birth/death/marriage */
global(dateplace_death)
global(dateplace_marriage)
global(dateplace_burial)
global(show_altname)         /* boolean, whether or not to show 2nd names */
global(show_address)         /* boolean, whether or not to show addresses */
global(no_resides_at)        /* boolean, show all or just current addresses */
global(surname_upper)        /* boolean, display surnames in upper case? */
global(display_title)        /* boolean, display descriptive title? */
global(chart_title_override) /* string, user-specified title */
global(display_label)        /* boolean, display identifying label? */
global(label_outside)        /* boolean, place label outside border? */ 
global(display_border)       /* boolean, display a fancy border? */
global(bold_chart)           /* bool, direct line in bold 0: no, 1: yes */
global(bold_factor)          /* int, how much larger bold lines should be */
global(mirror_chart)         /* bool, root person on right 0: no, 1: yes */
global(mom_first)            /* bool, mothers at branch tops: no(0), yes(1) */
global(halfsib)              /* bool, show half siblings 0: no, 1: yes */
global(halfsib_anc)          /* bool, show half sibling ancestors 0: no,1:yes*/
global(depth_halfsib_anc)    /* int, smallest generation in which half
                                      siblings will have ancestors plotted */
global(desc_gender)          /* int, gender restriction on descendants */
global(opt_rel_famc)         /* bool, non-birth branches use thin blue line*/
global(duplic_handling)      /* int, 0 do nothing, 1 dashed line, 2 anc once */
global(portrait)             /* int, 0: landscape, 1: portrait */
global(paper_width)          /* int, width in points of target paper */
global(paper_height)         /* int, height in points of target paper */
global(paper_name)           /* string, name of paper for PostScript device */
global(margin_top)           /* int, minimum top margin, in points*/
global(margin_bottom)        /* int, minimum bottom margin, in points*/
global(margin_left)          /* int, minimum left margin, in points*/
global(margin_right)         /* int, minimum rightmargin, in points*/
global(manual_feed_opt)      /* int, 0 don't specify, 1 on, 2 off */
global(postscript_level)     /* int, 1 or 2 for PostScript level 1 or greater */
global(pacificpage)          /* int, 0/1 have pacific page cartridge on Laser */

/* variables to return additional values from functions */
global(min_gap_return)
global(branch_up_min_pos)
global(dup_line_return)

/* these three constants define how close branches of the tree can get */
global(branch_dist_prev)     /* minimum distance from previous generation */
global(branch_dist_same)     /* minimum distance from same generation */
global(branch_dist_next)     /* minimum distance from next generation */

/* stacks for storing the information for each person on the chart */
/* see proc's enqueue_person and print_all_persons */

global(plist_person)  /* the person (to extract name, birth, death) */
global(plist_depth)   /* generation depth */
global(plist_pos)     /* vertical position */
global(plist_line)    /* 0,1 boolean, is direct ancestor? */
global(plist_mdate)   /* marriage date */
global(plist_up)      /* 0,1 boolean, person connects to next up level*/
global(plist_down)    /* 0,1 boolean, person connects to next down level */
global(plist_duplic)  /* 0,1 boolean, the person is a duplicate appearance */
global(plist_height)  /* to store person height for ease of branch adjustment */

/* set for enabling originality of chart appearances by individuals */
global(original_person)
global(original_depth)
global(duplicate_anc_return)
global(duplicate_return)

/* stacks for storing the information for each vertical line on the chart */
/* see proc's enqueue_vertical and print_all_verticals */

global(llist_depth)   /* generation depth */
global(llist_low)     /* starting point */
global(llist_high)    /* finishing point */
global(llist_color)   /* line color */
global(llist_duplic)  /* dashed lines for duplicates */

/* stacks for marking the beginning of a branch in the person and line lists */
global(branch_start_person)
global(branch_start_line)


global(ps_xlat)       /* for a table to hold character translations */
global(opt_xlat)      /* boolean, to control character translation */
global(opt_deparen)   /* boolean, control removal of parenthesized name text */

/*
   keyword: SHORTEN
   uncomment the following 'include' command and verify that the
   included file contains subroutines for place name shortening
*/

/* include("shorten.lllib") */


/*
**  function: interrogate_user
**
**  This function is designed to be modified by the user.  It asks
**  many questions about how to configure the charts.  If your answer
**  to one of the questions is always the same, you can easily
**  hardwire your answer here so that you are never asked again.
**
**  An 'if' statement is wrapped around each question.  The 'if(TRUE)'
**  can be changed to an 'if(FALSE)' to make the program use the default
**  value defined in the 'else' clause instead of asking every time.
**
**  The questions are grouped in the following way:
**    o CHART CONTENT -- root person, chart type, # gen, # gen sib,
**          show half siblings, show half sibling ancestors,
**          # gen half sibling ancestors, matrilinear/patrilinear drop line
**    o LAYOUT -- multi-page and orientation, # pages for multi-page,
**          root person on left or right, mothers or fathers at tops of branches
**    o ADD-ONS -- border, title, label, label text, center label,
**          label in/outside border
**    o STYLE -- font, character encoding, color, desc. branch directions,
**          bold lines of descent, bold line width factor, duplicate handling,
**          display of non-birth relations
**    o FORMAT OF INFORMATION -- date/place format, show 2nd names,
**          address specifics, title before/after name, 
**          lower/upper-case surnames,max. length for names,
**          removing parenthesized text from names
**    o OUTPUT OPTIONS -- paper size/type, minimum margins, manual feed request
**          PacificPage margin modification, filter some PostScript strings
**
*/

func interrogate_user() {

/* CHART CONTENT */

/*
**  QUESTION: Who is the root person?
**
**  This question should always be asked, unless you always use the same
**  person, which is not likely.  If you do set a default, it is a string
**  representation of that persons number.
**
*/

  if(TRUE) {
    set(root_person, 0)
    getindimsg(root_person, "Identify root person for chart (blank to cancel)")
    if(not(root_person)) {
      return(0)       /* signals abnormal termination of interrogate_user() */
    }
  } else {
    set(root_person, indi("1"))
  }

/*
**  QUESTION: What type of chart?
**
**  This should always be asked, unless you never use two of the three
**  types of charts.
**
*/
  if(TRUE) {
    list(options)
    setel(options, 1, "Ancestors")
    setel(options, 2, "Descendants and Spouses")
    setel(options, 3, "Direct Descendants (Drop line)")
    setel(options, 4, "Ancestors and Descendants of a Family (Combo.)")
    setel(options, 5, "Ancestors and Descendants of an Extended Family (Cousins)")
    setel(options, 6, "Multiple Charts (program editing required)")
    set(chart_type, menuchoose(options, "Select chart type:"))
    if(or(le(chart_type, 0), ge(chart_type, 7))) {
      return(0)       /* signals abnormal termination of interrogate_user() */
    }

/*
    indiset(pset)
    addtoset(pset, root_person, 1)
    if(eq(lengthset(childset(pset)), 0) ) {
      print(" Printing ancestor chart as ", name(root_person), nl())
      print("                                    has no known children.", nl())
      set(chart_type, 1)
    } elsif(eq(lengthset(parentset(pset)), 0) ) {
      print(" Choose a chart with descendants as ", name(root_person),
          " has no known ancestors.", nl())
      getintmsg(chart_type,
          "Specify chart type: 2/descendant, 3/drop line, 4/combo.")
    } else {
      getintmsg(chart_type,
          "Enter chart type: 1/anc., 2/des., 3/drop line, 4/combo., 5/cousins")
    }
*/
  } else {
     set(chart_type, 1)
  }

  /*
     The following is code that pertains to the combination and cousin charts.
     No user-modification is needed between here and the next question.
  */
  if(or( eq(chart_type, 4), eq(chart_type, 5) )) {
    print(" Choose a family via spouse...")
    set(root_fam, choosefam(root_person))
    if(eq(root_fam, 0)) {
       return(0)       /* signals abnormal termination of interrogate_user() */
    }
    print(" done.", nl())

    if(not(and(husband(root_fam), wife(root_fam)))) {
       print(" That family only has one parent.", nl())
       print(" This chart-type requires a family with two parents.", nl())
       return(0)
    }
  }

/*
**  QUESTION: How many generations should be shown?
**
**  If there are less than this, then the page is filled anyway,
**  so you only need to ask if you want a restricted number.
**
*/

  if(TRUE) {
    set(min_depth, 1)
    set(max_depth, 1)
    if(ge(chart_type, 2)) {    /* chart has descendants: gen #s go negative */
      getintmsg(min_depth,
          "Maximum number of generations of descendants, including root")
      if(le(min_depth, 0)) {
        set(min_depth, 1)
      }
    }
    if(and( ne(chart_type, 2), ne(chart_type, 3) )) {
      /* chart has ancestors: gen #s go positive */
      getintmsg(max_depth,
          "Maximum number of generations of ancestors, including root")
      if(le(max_depth, 0)) {
        set(max_depth, 1)
      }
    }

  } else {
    set(min_depth, 1)
    set(max_depth, 1)
    if(ne(chart_type, 1)) {
      set(min_depth, 4)
    }
    if(or( eq(chart_type, 1), eq(chart_type, 4), eq(chart_type, 5) )) {
      set(max_depth, 4)
    }
  }

/*
**  QUESTION: How many ancestral generations should show siblings?
**
**  If you want to show siblings in all generations, set this default to 999.
**  This question is only asked for ancestral charts.
**
*/

  if(and( ne(chart_type, 2), ne(chart_type, 3) )) {

    if(FALSE) {
      getintmsg(depth_siblings,
          "How many ancestral generations to show siblings")
    } else {
      set(depth_siblings, 999)
    }
  }

/*
**  QUESTION: Should half siblings be shown?
**
**  In the ancestral report, if a parent has had multiple marriages
**  this determines whether the children of these marriages are shown
**  in the aunts/uncles. They are placed above the father or below the
**  mother with a thin vertical line in the aunt/uncle colour.
**
*/

  if( and( ne(chart_type, 2), ne(chart_type, 3), gt(depth_siblings, 0))) {

    if(FALSE) {
      getintmsg(halfsib,
          "Enter 1 to show half-brothers/sisters, 0 to omit them")
    } else {
       set(halfsib, 1)
    }
  }

/*
**  QUESTION: Should ancestors of half siblings be shown?
**  In the ancestral report, if a parent has had multiple marriages
**  this determines whether the ancestors of these spouses are shown.
*/

  if( and(ne(chart_type, 2), ne(chart_type, 3))) {

    if(FALSE) {
      if(halfsib) {
        getintmsg(halfsib_anc,
            "Enter 1 to show ancestors of half siblings, 0 to omit them")
      }
    } else {
      set(halfsib_anc, 1)
    }
  }
  
/*  QUESTION:  In how many generations do you want to show ancestors
**  of half siblings?
**
**  This is the last generation in which, if there are half siblings shown,
**  their ancestors will be shown, subject to the maximum depth limit.
*/

  if( and(ne(chart_type, 2), ne(chart_type, 3))) {

    if(FALSE) {
      if(halfsib_anc) {
        getintmsg(depth_halfsib_anc,
          "Number of generations from which to show ancestors of half siblings")
        if(ge(depth_halfsib_anc, max_depth)) {
          set(depth_halfsib_anc, sub(max_depth, 1))
        }
      }
    } else {
      set(depth_halfsib_anc, sub(max_depth, 1))
    }
  }

/*
**  QUESTION: Do you want descendant lines be matrilinear/patrilinear?
**
**  Currently only for dropline charts, this option allows the restriction
**  of descendant lines followed to a particular gender.
**  For branches that are cut off, a short horizontal line is drawn from a
**  person towards the younger generation to indicate that the person has
**  descendants.  This is the same thing that is done when a person has
**  descendants in that go off-chart.
*/

  if(TRUE) {
    if(eq(chart_type, 3)) {
      getintmsg(desc_gender,
          "Enter 2 for patrilinear, 1 for matrilinear, 0 for all descendants")
    } else {
      set(desc_gender, 0)  /* won't be used */
    }
  } else {
    set(desc_gender, 0)
  }

/* LAYOUT */

/*
**  QUESTION: Do you want multi-page poster output, and select orientation.
**
**  This controls whether (PostScript) output spans multiple pages.
**  In PostScript, this is achieved by enlarging the chart and moving
**  the plot origin to cause the desired portion of the chart to land in
**  a clipped region of a given page.
**  
*/

  if(TRUE) {
    list(options)
    setel(options, 1, "Single page, in portrait")
    setel(options, 2, "Single page, in landscape")
    setel(options, 3, "Multi page, using portrait sheets of paper")
    setel(options, 4, "Multi page, using landscape sheets of paper")
    set(mc, menuchoose(options, "Select page type:"))
    if( eq(0, mc)) {
      return(0) 
    } elsif( eq(1, mc)) {
      set(multi_page, 0)
      set(portrait, 1)
    } elsif( eq(2, mc)) {
      set(multi_page, 0)
      set(portrait, 0)
    } elsif( eq(3, mc)) {
      set(multi_page, 1)
      set(portrait, 1)
    } else {
      set(multi_page, 1)
      set(portrait, 0)
    }
    /* purge options list for later use */
    list(options)  /* new - RES */
    /*while(length(options)) {set(mc, pop(options))}*/
  } else {
    set(multi_page, 0)
    set(portrait, 1)
  }

/*
**  QUESTION: How many pages make up the poster?
**
**  You will probably want to always ask this question.  This question is
**  asked if a poster chart is requested.
**
*/

  if(multi_page) {

    if(TRUE) {
      getintmsg( x_pages, "Number of horizontal pages on finished chart")
      getintmsg( y_pages, "Number of vertical pages on finished chart")
    } else {
      set(x_pages, 1)
      set(y_pages, 2)
    }

  } else {
    set(x_pages, 1)
    set(y_pages, 1)
  }

/*
**  QUESTION: Should the younger generations be on the left or right?
**
*/

  if(FALSE) {
    getintmsg( mirror_chart,
        "Enter younger generations on the left (0), or the right (1)")
  } else {
    set( mirror_chart, 1)
  }

/*
**  QUESTION: Should mothers appear at the tops of ancestral branches?
*/

  if( and(ne(chart_type, 2), ne(chart_type, 3))) {

    if(TRUE) {
      getintmsg(mom_first,
          "Enter 1 to put mothers at top of anc. branches, 0 for fathers")
    } else {
      set(mom_first, 0)
    }
  }

/* ADD-ONS */

/*
**  QUESTION: Should a decorative border be shown?
*/

  if(FALSE) {
    getintmsg(display_border,
      "Enter 1 to print a decorative border, 0 to print no border")
  } else {
    set(display_border, 1)
  }

/*
**  QUESTION: Should descriptive title be displayed?
*/

  if(TRUE) {
    getintmsg(display_title,
        "Enter 1 to display descriptive title , 0 for no title")
    } else {
    set(display_title, 1)
  }

/*
**  QUESTION: Use an automaticly generated title, or a user-specified one?
*/

  if(and(FALSE, display_title)) {
    getstrmsg(chart_title_override,
        "Enter chart title, or none to have one created automatically.") 
  } else {
    set(chart_title_override, "")
  }

/*
**  QUESTION: Should a chart label be shown?
**
**  The chart label identifies the preparer, and optionally,
**  what would have been in the chart title, should one be omitted.
*/

  if(FALSE) {
    getintmsg(display_label,
        "Enter 1 to display identifying label , 0 for no label")
  } else {
    set(display_label, 0)
  }

/*
**  QUESTION: What message (label) should be shown at the bottom of the chart?
**
**  I suggest not asking this question, and setting a default credit with
**  your name.  The advantage of this is that you can have the date
**  automatically inserted.
**
*/

  set(label_set, 0)

  if(FALSE) {
    if(display_label) {
      getstrmsg(chart_label, "Label for corner of chart (your name, date)")
      set(chart_label, save(chart_label))
      set(label_set, 1)
    }
  }
  if(not(label_set)) {
    /* want to make sure there is a label written to the PostScript file, */
    /* in case user sets 'display_label' to true in PostScript output later */
    dayformat(2)
    monthformat(4)
    dateformat(0) /* format for date, if used in 'rpt_name' or 'chart_label' */

    set(rpt_name,
      "produced by Your Name, your web, e-mail, or mail address, for instance"
    )
    if(display_title) {
      /* don't need to repeat information given in title */
      set( chart_label, concat( save( stddate( gettoday() )), "  ", rpt_name))
    } else {
      set(chart_label,
        concat(save(stddate(gettoday())), "  ", chart_title(), "  ", rpt_name))
    }
  }


/*
**  QUESTION: Should the chart_label be centered?
**
**  Concerns the position on the first page (lower left) for the chart label.
**  The choices are to center the label, or to put it near the left edge.
**
*/

  if(display_label) {

    if(FALSE) {
      getintmsg(chart_label_centered,
          "Enter 1 to center chart label, 0 for left")
    } else {
       set(chart_label_centered, 0)
    }
  }

/*
**  QUESTION: Print label inside or outside the border?
**  If both a border and the label are to be on a chart, it is possible
**  to specify whether the label should go inside or outside the border.
*/

  if( and(display_border, display_label)) {

    if(FALSE) {
      getintmsg(label_outside,
          "Enter 1 to place label outside border, 0 for inside")
    } else {
      set(label_outside, 1)
    }

  } else {
    set(label_outside, 1)
  }

/* STYLE */

/*
**  QUESTION: What font should be used for names?
**
**  Because it is such a pain to enter a font name, and a spelling mistake
**  will get you an ugly default font, this should be set to a default.  I
**  suggest one of: Times-Roman, NewCenturySchlbk-Roman, or ZapfChancery.
**  Choosing the font via lists is provided primarily for when one is
**  curious as to what the others look like on a chart.
**
**  Search the Postscript code at bottom of this file for ideas (and spellings).
**  Look for "bolddict" where font names and their bold equivalents are defined.
**  When adding a new font choice, you should add the bold name (if one exists)
**  in the PS code yourself, using the existing code as a guide.  If your font
**  doesn't have a bold version, then the font itself will be used when a bold
**  font is called for.
**
**  For fonts with characters that are to be placed right-to-left it may be
**  necessary to add the font's name and an association with the 'rlshow'
**  procedure within the PostScript code.  This is done in the setup of a
**  PostScript dictionary.  Look for "fshowdict begin" below and follow
**  existing code as an example.  If that font also has a bold version, then
**  do the same for it, or the font will be shown r-to-l but the bold version
**  will go l-to-r.
**
**  If a font encoding array (like ISOLatin1, provided by PostScript Level 2)
**  is used with a font that uses non-standard character names, then many
**  or all characters may not show (they get replaced with .notdef).
**  In that case, in order to use the font, font reencoding should not be used.
**
**  Some fonts don't specify a FontBBox -- the dimensions of a rectangle that
**  will enclose any letter form, or glyph, from the font.  In this case,
**  the PostScript code produced may rely on estimating character dimensions
**  by testing a few letters.  Hershey-Gothic-English is such a font.
*/

  if(TRUE) {
    set(font_name, choose_font("individual names"))
    if(not(font_name)) {
      return(0)
    }
  } else {
    /*set( font_name, "Times-Roman")*/
    set( font_name, "ZapfChancery-MediumItalic")
    /*copyfile("/usr/local/lib/ghostscript/zcr.gsf")*/
    /*copyfile("/usr/local/lib/ghostscript/zcb.gsf")*/
  }

/*
**  QUESTION: Which font should be used for individual info (dates/places)?
*/

  if(TRUE) {
    set(ifont_name, choose_font("individual info"))
    if(not(ifont_name)) {
      return(0)
    }
  } else {
    set(ifont_name, "Times-Roman")
  }

/*
**  QUESTION: Which, if any, character encoding to enforce?
**
**  In some PostScript fonts, there are more characters available than
**  the 256 integers (ASCII) used to represent different text characters.
**  An encoding vector is used to assign a subset of the available glyphs or
**  letterforms to the 256 character codes (0 through 255).
**  This allows PostScript output to match the characters available to
**  genealogy software on many platforms.
**
**  However, if accented characters are not needed, or the encodings in
**  the fonts are sufficient, then simply using
**  an encoding built into a font file (no change) results in a smaller
**  PostScript file.
**
**  Printers may be incapable of composing accents with plain letters when
**  an accented character is not directly available in a font.
**  To get around this, printing the output through Ghostscript or converting
**  the PostScript output to PDF with Ghostscript or other conversion utility
**  should work.
**
**  ISO-Latin 1, or ISO 8859-1, is a world-wide standard for most languages
**  of Latin origin: Albanian, Basque, Breton, Catalan, Cornish, Danish, Dutch
**  English, Faroese, Finish (exc. S,s,Z,z with caron),
**  French (except OE, oe, and Y-with-dieresis), Frisian, Galician, German,
**  Greenlandic, Icelandic, Irish Gaelic (new orthography), Italian, Latin,
**  Luxemburgish, Norwegian, Portuguese, Rhaeto-Romanic, Scottish Gaelic,
**  Spanish, Swedish.
**
**  ISO Latin 2, or ISO 8859-2, covers these languages:  Albanian, Croatian,
**  Czech, English, German, Hungarian, Latin, Polish, Romanian (cedilla below
**  S,s,T,t instead of comma), Slovak, Sloverian, Sorbian.
*/

  if(TRUE) {
    list(options)
    setel(options, 1, "ISO Latin 1")
    setel(options, 2, "ISO Latin 2")
    setel(options, 3, "MS-DOS Codepage 437 (extended ASCII) international chars.")
    setel(options, 4, "let the font decide for me (use encoding specified in PS font)")
    set(enc_choice, menuchoose(options,
       "Select font reencoding, or (q) to use font's built-in encoding"))
    if(eq(enc_choice, 4)) {
       set(enc_choice, 0)
    }
  } else {
    set(enc_choice, 1)
  }


/*
**  QUESTION: Should color be used?
**
**  If you don't have access to a color printer, you should probably turn
**  off this question.
**
*/

  if(FALSE) {
    getintmsg( color_chart, "Enter 0 for black/white, 1 for color")
  } else {
    set(color_chart, 1)
  }

/*
**  QUESTION: Which way should descendant branches go?
**
**  The charting procedures can make decisions about branch directions,
**  roughtly, choosing up for the first half and down for the second half
**  of a person's descendant branches.
**  This may be overriden by forcing all branches to go up or all to go down.
*/

  if(FALSE) {
    if(and( ne(chart_type, 1) , ne(chart_type, 3))) {
      getintmsg( updown_override,
          "Desc. branch direction: -2: all up, 0: mix, 2: all down")
    } else {
      set(updown_override, 0)
    }
  } else {
    set(updown_override, 0)
  }

/*
**  QUESTION: Should the direct line of descent be put in bold?
**
**  Puts the text and lines for the direct line in bold.
**
*/

  if(FALSE) {
    getintmsg(bold_chart, "Enter 1 for bold direct line, 0 for all the same")
  } else {
    set(bold_chart, 1)
  }

/*
**  QUESTION: What scale factor should be used to make bold lines?
**
**  The default value should be 2 or 3.
**  A value of 1 will make bold lines look the same as non-bolded ones.
*/

    if(and( FALSE, bold_chart)) {
      getintmsg(bold_factor,
          "Enter the bold factor for direct relation lines")
    } else {
      set(bold_factor, 3)
    }

/*
**  QUESTION: How should duplicate individuals be handled?
**
**  When someone appears on a chart twice it can be helpful
**  to mark the duplicate entries so they aren't thought to
**  be different ancestors/descendants at first glance.
**
**  The options are to print a duplicate's horizontal lines in
**  a dashed style or to do that plus truncate a duplicate's ancestors
**  (since they would possibly already appear on the chart).

*/
/* RES!? -has truncation of descendants been enabled yet? */

  if(FALSE) {
    getintmsg(duplic_handling,
      "For duplicate individuals, make: 0 no change, 1 dashed, 2 truncated")
  } else {
    set(duplic_handling, 2)
  }

/*
** QUESTION: Do you want to show non-birth or legal relatives
**           (by adoption, fostering, or sealing relationsships) with
**           thin light blue lines, same as for other non-blood relatives?
** Non-birth child-to-family (FAMC) connections are indicated
** (according to GEDCOM 5.5) with a PEDI subnode of the FAMC node.
** The recognized values for the PEDI subnode are
** Birth, Adopted, Foster, Sealed.
*/

  if(TRUE) {
    getintmsg(opt_rel_famc,
      "Enter 1/0 for Adopted, Foster, and Sealing connections to be non-blood")
  } else {
    set(opt_rel_famc, 1)
  }

/* FORMAT OF INFORMATION */

/*
**  QUESTION: How should dates/places of birth/death/marriage be shown?
**
**  This is actually three questions, or the same question for birth
**  death and marriage dates.  The codes cause the dates to be printed
**  as follows.
**
**      0: do not show date
**      1: full date only
**         [ LifeLines date() function ]
**      2: date and place, just year and State/Country
**         [ LifeLines short() function ]
**      3: full date and full place, can get very long and thus smushed
**         [ LifeLines long() function ]
**      4: full date and first item on PLAC line
**      5: full date and first two items on PLAC line
**      6: full date and first three items on PLAC line
**      7: year and up to two sufficient components from the PLAC line
**
**  For more specific comments and the code that corresponds to these styles,
**  search for "func dateplace(".
**  To enable place modification or shortening, a date-place style that calls
**  on the modify function must be used. Currently: 4, 5, 6, 7.
**                                                      keyword: SHORTEN
*/

  if(FALSE) {
    set(dateplace_birth, 99)
    while( or( lt(dateplace_birth, 0), gt(dateplace_birth, max_dateplace))) {
      getintmsg(dateplace_birth,
              "Birth date style (0:no,1:date,2:short,3:long,4:d+1p,5:d+2p,6:d+3p,7:y+2p)")
    }
    set(dateplace_death, 99)
    while( or( lt(dateplace_death, 0), gt(dateplace_death, max_dateplace))) {
      getintmsg(dateplace_death,
              "Death date style (0:no,1:date,2:short,3:long,4:d+1p,5:d+2p,6:d+3p,7:y+2p)")
    }
    set(dateplace_marriage, 99)
    while( or( lt(dateplace_marriage, 0), gt(dateplace_marriage, max_dateplace))) {
      getintmsg(dateplace_marriage,
              "Marriage date style (0:no,1:date,2:short,3:long,4:d+1p,5:d+2p,6:d+3p,6:y+2p)")
    }
    set(dateplace_burial, 99)
    while( or( lt(dateplace_burial, 0), gt(dateplace_burial, max_dateplace))) {
      getintmsg(dateplace_burial,
              "Burial date style (0:no,1:date,2:short,3:long,4:d+1p,5:d+2p,6:d+3p,7:y+2p*)")
    }
  } else {
    set(dateplace_birth, 6)
    set(dateplace_death, 6)
    set(dateplace_marriage, 6)
    set(dateplace_burial, 6)
  }

/*
**  QUESTION: Is it ok to abbreviate (some) place components?
**
**  Should a function made available in an external file via an include
**  statement prior to this function (interrogate_user) be used to 
**  abbreviate some place components, such as country, state, or province
**  names?
*/

  if(FALSE) {
    getintmsg( place_modify,
        "Enter a 1 to allow place abbreviating, 0 to dissallow")
  } else {
    set(place_modify, 0)      /* keyword: SHORTEN */
  }

/*
**  QUESTION: Should second names be shown with person info?
**
**  Should there be a second name for a person, is it to be shown
**  with the other person info (in the same font size as the other info lines)?
*/

  if(FALSE) {
    getintmsg( show_altname,
        "Enter 1 to show 2nd name as information, 0 to suppress")
  } else {
    set(show_altname, 1)
  }

/*
**  QUESTION: Should addresses be shown?
**
**  Should a person's last address node be used to obtain a street address,
**  phone number, and e-mail address?
*/

  if(FALSE) {
    getintmsg( show_address,
        "Enter 1 to show address information, 0 to suppress")
  } else {
    set(show_address, 0)
  }

/*
**  QUESTION: Should any address node (ADDR, RESI) be used or
**            just active ones (ADDR)?
**
**  Notes: ADDR is a GEDCOM 5.5 standard.
**         RESI is a GEDCOM 5.5 standard for a former, "resided at"
**              address.  This allows the ADDR node type to be used strictly
**              for current addresses.
*/

  if(show_address) {

    if(FALSE) {
      getintmsg(no_resides_at,
          "Enter 1 to show only current addresses, 0 for any address type")
    } else {
      set(no_resides_at, 0)
    }
  }

/*
**  QUESTION: How should an individual's title be used?
**
**  I would leave this default set to 'guess' (3), or 'none' (0), if you
**  don't want the titles.  If you find a title that is guessed incorrectly,
**  please send an e-mail to the maintainer.
**
*/

  if(FALSE) {
    getintmsg(title_method, "Title method (0:none,1:prefix,2:suffix,3:guess)")
  } else {
    set(title_method, 3)
  }

/*
**  QUESTION: Should surnames be in upper case?
**
*/

  if(FALSE) {
    getintmsg(surname_upper,
        "Enter 1 for surnames in upper case, 0 for as is")
  } else {
    set(surname_upper, 0)
  }

/*
**  QUESTION: What is the maximum length for names?
**
**  It is best to just set a default maximum name length.  If you want
**  to always show the complete name, just set the default to 999.
*/

  if(FALSE) {
    getintmsg(name_letters, "Maximum name length")
  } else {
    set(name_letters, 40)
  }

/*
**  QUESTION: Should parenthesized text be omitted from names in charts.
**
**  This is to improve the chances that all important parts of a name
**  are shown.  Before names are cut to their length limit
**  (name_letters, above) text within a full name that is parenthesized may
**  be removed.  The routine used will catch any logical pairings of
**  '(' and ')' and can even handle nesting of parentheses.
*/

  if(FALSE) {
    getintmsg(opt_deparen,
        "Enter 1 to remove parenthesized text from names, 0 otherwise.")
  } else {
    set(opt_deparen, 1)
  }

/* OUTPUT OPTIONS */

/*
**  QUESTION: What paper size is expected?
**
**  This presents a list of paper sizes to choose from, or the option
**  of a custom size.  The custom size feature would be appropriate to
**  make a chart that can be included as an EPS file in another document.
**
**  The variables paper_height and paper_width are set to integer values
**  corresponding to the page dimensions, in points (72 points = 1 inch)*
**  Here are sizes and names taken from the PostScript news group's FAQ:
          Paper Size                      Dimension (in points)
          ------------------------------  ---------------------
          Comm #10 Envelope               297 x 684
          C5 Envelope                     461 x 648
          DL Envelope                     312 x 624
          Folio                           595 x 935
          Executive                       522 x 756
          Letter                          612 x 792
          Legal                           612 x 1008
          Ledger                          1224 x 792
          Tabloid                         792 x 1224
      **  A0                              2384 x 3370
          A1                              1684 x 2384
          A2                              1191 x 1684
          A3                              842 x 1191
          A4                              595 x 842
          A5                              420 x 595
          A6                              297 x 420
          A7                              210 x 297
          A8                              148 x 210
          A9                              105 x 148
          B0                              2920 x 4127
          B1                              2064 x 2920
          B2                              1460 x 2064
          B3                              1032 x 1460
          B4                              729 x 1032
          B5                              516 x 729
          B6                              363 x 516
          B7                              258 x 363
          B8                              181 x 258
          B9                              127 x 181 
          B10                             91 x 127

    * In PostScript and desktop publishing in general, points 1/72 inch,
      or .3527777778 mm.  1 pica = 12 points.  In traditional typography,
      points are 1/72.27 inch, or .3514598035 mm.  Metric resolutions are
      common with phototypesetters and supported by HTML, while laser and
      inkjet printers primarily use points or inches.

    **ISO 216 paper size system is based on the principle of doubling and
      halving to produce larger or smaller sizes, which are proportional to
      the original when rotated one quarter turn.  The side length ratio which
      accomplishes this is 1 : 'square root of 2'.
      Size A0 has an area of one square meter.
      The fixed aspect ratio of the different size papers makes photocopier
      enlarging/reducing a breeze.  Only the U.S. and Canada persist in their
      government and business use of non-ISO paper sizes, among industrialized
      nations.
*/

  if(TRUE) {
    list(options)
    setel(options, 1, "Adaptive, maximum area available")
    setel(options, 2, "EPSF, custom size (single page)")
    setel(options, 3, "Letter, 8 1/2\" x 11\" or 612 x 792 points")
    setel(options, 4, "Legal, 8 1/2\" x 14\" or 612 x 1008 points")
    setel(options, 5, "Ledger (Tabloid), 11\" x 17\" or 792 x 1224 points")
    setel(options, 6, "A4, 595 x 842 points")
    setel(options, 7, "A3, 842 x 1191 points")
    setel(options, 8, "B5, 516 x 729 points")
    setel(options, 9, "B4, 729 x 1032 points")
    set(mc, menuchoose(options, "Select page size:"))
    if( eq(mc, 1)) {
       set(paper_name, "NONE")  /* other paper_names are suitable for ps2pdf */
    } elsif( eq(mc, 2)) {
       getintmsg(paper_width, "Enter image width, in points")
       getintmsg(paper_height, "Enter image height, in points")
       set(paper_name, "EPSF")
       set( multi_page, 0)
       set( x_pages, 1)
       set( y_pages, 1)
    } elsif( eq(mc, 3)) {     /* Letter */
       set(paper_width, 612)
       set(paper_height, 792)
       set(paper_name, "letter")
    } elsif( eq(mc, 4)) {     /* Legal  */
       set(paper_width, 612)
       set(paper_height, 1008)
       set(paper_name, "legal")
    } elsif( eq(mc, 5)) {     /* Ledger */
       set(paper_width, 792)
       set(paper_height, 1223)
       set(paper_name, "ledger")
    } elsif( eq(mc, 6)) {     /*  A4    */
       set(paper_width, 595)
       set(paper_height, 842)
       set(paper_name, "a4")
    } elsif( eq(mc, 7)) {     /*  A3    */
       set(paper_width, 842)
       set(paper_height, 1191)
       set(paper_name, "a3")
    } elsif( eq(mc, 8)) {     /*  B5    */
       set(paper_width, 516)
       set(paper_height, 729)
       set(paper_name, "b5")
    } elsif( eq(mc, 9)) {     /*  B4    */
       set(paper_width, 729)
       set(paper_height, 1032)
       set(paper_name, "b4")
    } else {  /* user must have chosen 'q'uit */
      return(0)
    }
  } else {
    /* DEFAULT paper size, if the question is not to be asked */
    /* copy from above, capitalization and spelling of name are important */
    set(paper_name, "NONE")
  }

/*
**  QUESTION:  Specify minimum margins for each side of the paper.
**
**  The resulting PostScript file asks the printer how close to
**  the edge of the paper it can print.
**  If the maximum size chart is desired, set the margins to zero.
**
**  For all but the Adaptive page size, if a margin is required, specify it
**  here to ensure a margin at least that wide.
**      Margins on printed pages may be wider if the printing device requires
**      more distance from the edges of the paper.
**
**  For the Adaptive page size, margins are subtracted from what the printing
**  device gives as it's printing area.  In this case, margins specified here
**  are added onto the devices margins.
**  Be aware that when converting to a PDF file, margins become fixed.
**  This can result in edges of the intended output getting cropped by printing
**  from a PDF viewer.  If necessary, a shrink-to-fit option may be used
**  with such viewers -or- the margins specified here may be made large
**  enough to accomodate most printers self-imposed margins.  30 points may do.
**
**  The answers to these questions should be to the nearest integer point value,
**  18 points = 1/4 inch, 36 points = 1/2 inch, 72 points = 1 inch.
**
*/

    if(FALSE) {
      getintmsg(margin_top, "Minimum width of TOP margin")
      getintmsg(margin_bottom, "Minimum width of BOTTOM margin")
      getintmsg(margin_left, "Minimum width of LEFT margin")
      getintmsg(margin_right, "Minimum width of RIGHT margin")
    } else {
      set(margin_top, 30)
      set(margin_bottom, 30)
      set(margin_left, 30)
      set(margin_right, 30)
    }

/*
**   QUESTION: Do you want to try to tell the printer to request a manual feed?
**
*/
  if( and( nestr(paper_name, "EPSF"), nestr(paper_name, "NONE"))) {

    if(TRUE) {
      getintmsg(manual_feed_opt,
          "Manual feed request: 0 don't specify, 1 on, 2 off")
    } else {
      set( manual_feed_opt, 0)
    }

  } else {
    set( manual_feed_opt, 0)
  }

/*
**   QUESTION: Use PostScript Level 1 or Level 2 paper size request?
**
*/
  if( eq(manual_feed_opt, 1)) {

    if(TRUE) {
      set(postscript_level, 0)
      while( and( ne(postscript_level, 1), ne(postscript_level, 2))) {
        getintmsg(postscript_level,
               "Specify PostScript Level of printer: 1 or 2 (for 2 or higher)")
      }
    } else {
      set(postscript_level, 1)
    }
  }

/*
**   QUESTION: Use modification for PacificPage cartridge?
**
**   Adds to the PostScript output a margin modification specific to this
**   device.  This PostScript modification should be left out for
**   PostScript Level 1 compatibility.
*/

  if(FALSE) {
    getintmsg(pacificpage,
        "Enter 1 for PacificPage modification, 0 to leave it out")
  } else {
    set(pacificpage, 0)
  }

/*
**  QUESTION: Do you want to filter some PostScript strings to protect
**            PostScript files from errors.
**
**  Unbalanced parentheses or lone backslash characters can cause problems in
**  strings stored in PostScript files.  This option enables their being
**  made safer.
*/

  if(FALSE) {
    getintmsg(opt_xlat,
        "Enter 1 to protect PostScript from dangerous characters, 0 otherwise")
  } else {
    set(opt_xlat, 1)
  }

/*
**  END OF QUESTIONS
**
*/

  return(1)      /* signals that all necessary questions were answered */
}

/*
** function: choose_font
**
** Assists the user in selecting a font name.
**
*/

func choose_font(purpose) {
  list(options)
  setel(options, 1, "Roman")
  setel(options, 2, "Italic (default)")
  setel(options, 3, "Arabic")
  setel(options, 4, "Hebrew")
  set(ff, menuchoose(options, concat("Select font face for ", purpose, ": ")))
  if(eq(ff, 1)) {
    list(options)
    setel(options, 1, "Times Roman (default)")
    setel(options, 2, "New Century Schoolbook")
    setel(options, 3, "Garamond")
    setel( options, 4, "Hershey Plain")
    set(mc, menuchoose(options, "Select font family: "))
    if( eq(2, mc)) {
      set(font_choice, "NewCenturySchlbk-Roman")
    } elsif( eq(3, mc)) {
      set(font_choice, "AGaramond-Regular")
    } elsif( eq(4, mc)) {
      set(font_choice, "Hershey-Plain")
    } else {
      set(font_choice, "Times-Roman")
    }
  } elsif(eq(ff, 2)) {
    list(options)
    setel(options, 1, "Times Italic (default)")
    setel(options, 2, "New Century Schoolbook Italic")
    setel(options, 3, "Garamond Italic")
    setel(options, 4, "ZapfChancery")
    set(mc, menuchoose(options, "Select font: "))
    if(eq(1, mc)) {
      set(font_choice, "Times-Italic")
    } elsif(eq(2, mc)) {
      set(font_choice, "NewCenturySchlbk-Italic")
    } elsif(eq(3, mc)) {
      set(font_choice, "AGaramond-Italic")
    } elsif(eq(4, mc)) {
      set(font_choice, "ZapfChancery-MediumItalic")
      /*copyfile("/usr/local/lib/ghostscript/fonts/zcr.gsf")*/
      /*copyfile("/usr/local/lib/ghostscript/fonts/zcb.gsf")*/
    } else {
      set(font_choice, "Times-Italic")
    }
  } elsif(eq(ff, 3)) {
    list(options)
    setel(options, 1, "OmegaRsimms")
    setel(options, 2, "Baghdad")
    set(mc, menuchoose(options, "Select font: "))
    if(eq(1, mc)) {
      set(font_choice, "OmArabicRsimms (default)")
    } elsif(eq(2, mc)) {
      set(font_choice, "Baghdad")
    } else {
      set(font_choice, "OmArabicRsimms")
    }
  } elsif(eq(ff, 4)) {
    list(options)
    setel(options, 1, "Jerusalem")
    set(mc, menuchoose(options, "Select font: "))
    if(eq(1, mc)) {
      set(font_choice, "Jerusalem (default)")
    } else {
      set(font_choice, "Jerusalem")
    }
  } else {
    set(font_choice, 0)     /* user must want to quit */
  }
  return(font_choice)
}

/*
**  procedure: main
**
**  The main procedure.
**
*/

proc main() {
  /* set constants */

  set(version, "ps-anc8.86, 4 Jul 2004")
  set(TRUE, 1)       /* to make code in interrogate_user() */
  set(FALSE, 0)      /* more user friendly                 */
  set(UP, neg(1))    /* constant, branch direction indicator */
  set(NEUTRAL, 0)    /* constant, branch direction indicator */
  set(DOWN, 1)       /* constant, branch direction indicator */

  set(name_height, 1000)          /* height to allow for name text */
  set(date_height, 600)           /* height to allow for date text */

  set(branch_dist_prev, 1000)     /* previous generation */
  set(branch_dist_same, 1250)     /* same generation */
  set(branch_dist_next, 1000)     /* next generation */
  set(tighten, TRUE)              /* ok for desc branches to be side-by-side */

  set(corner_height, 1000)        /* space between parent and extreme child 
                                     -- name_height was formerly used for this*/
  set(min_sibling_spacer, 500)    /* force this much space between siblings */
  
  set(max_dateplace, 6)           /* number of date-place styles */

  /* initialize other global variables and declare global stacks */

  set(debug, FALSE)              /* debugging output should depend on these */
  set(debug2, FALSE)
  set(debug_postscript, TRUE)    /* adds features to PostScript file:        */
                                 /* in PS file, set show_positions to 'true' */

  print(nl()) /* trying to make screen output not get clobbered by LL menu */
  if(interrogate_user()) {        /* set options, some specified by user */
    set(start_depth, 0)           /* any posInteger or neg(posInteger) is ok */

    /* make depths rel. to start_depth, and figure depth offset for array */
    /*if(or( eq(chart_type, 1), eq(chart_type, 4), eq(chart_type, 5) )) {*/
    if( and(ne(chart_type, 2), ne(chart_type, 3))) {
      set(depth_siblings, add(start_depth, sub(depth_siblings, 1)))
      set(depth_halfsib_anc, add(start_depth, sub(depth_halfsib_anc, 1)))
    }
    set( max_depth, add(start_depth, sub(max_depth, 1)))
    set( min_depth, sub(start_depth, sub(min_depth, 1)))
    set( high_pos_gen_offset, sub( 1, min_depth))

    call initialize_data()    /* declares and clears contents of lists */

    if(place_modify) {
      /* keyword: SHORTEN
         these commands prepare for place abbreviation supported
         by an included program 
      */
      table(abbvtab)
      call setupabbvtab()
    }

    if(opt_xlat) {
      /*  Initialize PostScript translation table to escape characters */
      table(ps_xlat)
      insert(ps_xlat,"(","\\(")
      insert(ps_xlat,")","\\)")
      insert(ps_xlat,"\\","\\\\")
    }

    /* generate chart data */
    if( eq(chart_type, 1)) {
      set(not_used, do_anc( root_person, start_depth, 0, 0, 0, 2, 0) )
    } elsif( eq(chart_type, 2)) {
      set(not_used, do_des2(root_person, start_depth, 0, NEUTRAL, 2, 0, 0, 0))
    } elsif( eq(chart_type, 4)) {
      call combo2()    /* all the information it needs is global */
    } elsif( eq(chart_type, 5)) {
      call do_cousins()  /* all the information it needs is global */
    } elsif( eq(chart_type, 3)) {
      set(not_used, dropline(root_person, start_depth, 0, FALSE, 2, 0))
    } elsif( eq(chart_type, 6)) {
      /* With a few rules, you can put multiple charts in the same layout
         The first chart may be of any type, but for now, additional charts
         within the same layout must be among anc, des, and drop line.     */
      /* The combo and cousins charts insist on their central generation
         being at 'start_depth'.  However, anc, des, and drop line charts may
         be started from any generation, specified in their 'depth' argument. */
      /* Run the program, choose a person who has descendants (to avoid the
         automatic choice of ancestor chart)
         Give '5' for the chart type.
         If duplicate appearances happen accross different charts, then
         the lists original_person and original_depth must be init'ed between
         chart calls to keep them from being treated as duplicates, if desired.
      */
      set(display_label, 1)
      set(chart_label_centered, 0)
      set(chart_label, "© Rugrats created by Arlene Klasky, Gabor Csupo and Paul Germain.")
      set(display_title, 1)
      set(chart_title_override, "The Rugrats")
      
      set(child_depth, sub(start_depth, 1))

      set(root_person, indi("17")) /* Tommy Pickles */
      set(root_fam, parents(root_person)) /* Stu & Didi */
      call do_cousins()
      print("Done Stu & Didi.", nl())

      set(root_person, indi("7")) /* Phil */
      set(root_fam, parents(root_person))
      call combo2()
      print("Done Phil & Lil", nl())

       set(root_fam, fam("F1"))
      call combo2()
      /*set(root_person, indi("1"))*/ /* Chuckie Finster */
      /*set(not_used, do_anc(root_person, child_depth, 0, 0, 0, 2, 0))*/
      print("Done Chuckie.", nl())

      set(root_person, indi("26")) /* Susie Carmichael */
      set(root_fam, parents(root_person))
      call combo2()
      print("Done Susie.", nl())
    }
    print(" ", d(length(plist_person)), " individuals shown on the chart.",nl())

    /* use chart data to create a PostScript file as output */
    call write_ps(font_name, ifont_name,
        x_pages, y_pages, high_depth, low_depth)

    /* apply external file conversion/viewing command */
    newfile(outfile(), TRUE)  /* thump output buffer */

    list(actions)
    list(choices)
    print("Output file full-name: ", outfile(), nl())
    enqueue(choices, "Convert with 'ps2pdf'")
    if(eqstr(paper_name, "NONE")) {
      enqueue(actions, concat("ps2pdf -dPDFSETTINGS=/printer ", outfile(),
        " `echo ", outfile(), "|sed 's:\.ps:\.pdf:'` && rm -i ", outfile() ))
    } else {
      enqueue(actions, concat("ps2pdf -dPDFSETTINGS=/printer ",
        "-sPAPERSIZE=", paper_name, " ", 
        outfile(),
        " `echo ", outfile(), "|sed 's:\.ps:\.pdf:'` && rm -i ", outfile() ))
    }
    /*enqueue(actions, concat("ps2pdf ", outfile())*/
    enqueue(choices, "View with 'MacGhostViewX'")
    enqueue(actions, concat("open -a ",
      "/Applications/MacGhostViewX/MacGhostViewX.app ", outfile()))
    enqueue(choices, "Convert with 'PStill'")
    enqueue(actions, concat("open -a ",
      "/Applications/Stone\\ Studio/PStill.app ", outfile()))
    set(mc, menuchoose(choices, "Choose an action or (q)uit to leave as is"))
    if(mc) {
      print("performing: ", getel(actions, mc), nl())
      system(getel(actions, mc))
    }

  }
}

/*
**  function: do_anc
**
**  A recursive function to position persons on an ancestral chart.
**  First, a recursive call is made to put the father on the chart.
**  Where he is put on the chart determines the minimum position for
**  the mother.  Once the father and mother are put on the chart, the
**  siblings are put on the chart.
**
*/

func do_anc(person, depth, person_minpos, marriage_date, has_des, rel, duplicate) {
  if( or( gt(depth, add(high_depth, 1)), eq(length(plist_person), 0)) ) {
    set(ceiling, FALSE)
  } else {
    set(ceiling, TRUE)
  }
  set(min_gap_set, FALSE)
  if(and(tighten, lt(depth, max_depth))) {
    call cloak(add(depth, 1))
  }
  set(abs_min_pos, get_clearance(depth, 0))
  if(gt(depth, max_depth)) {
    set(duplicate_anc_return, 0)
    set(min_gap_return, -1)
    return(max(person_minpos, abs_min_pos))
  }

  set(fam, choosefamc(person))
  set(rel_next, rel_famc(person, fam, rel))
  if(fam) {   /* make a var suitable for passing as a parameter */
    set(has_anc, 1)
  } else {
    set(has_anc, 0)
  }
  if(mom_first) {
    set(par1, mother(person))
    set(par2, father(person))
  } else {
    set(par1, father(person))
    set(par2, mother(person))
  }
  set(notcutoff, not(
    and( eq(duplic_handling, 2), or(duplicate, blocked(person, depth)) ) ))

  /* Figure out number of siblings and total sibling height.         */
  /* Father is allowed to be older_sib_height above person_minpos.   */
  /* sibling_height will be min distance between the first and last  */
  /* sibling horizontal  */
  set(sibling_height, 0)
  set(older_sib_height, 0)
  set(num_not_younger, 1) /* count of prior sibling buffers space */
  if(and( fam, le(depth, depth_siblings), notcutoff )) {
    set(num_siblings, nchildren(fam))
    children(fam, child, cn) {
      if(eq(person, child)) {
        set(older_sib_height, sibling_height)
        if(gt(num_siblings, 1)) {
          set(older_sib_height, add(older_sib_height, corner_height))
        }
        set(num_not_younger, cn)
      }
      if(ne(cn, num_siblings)) {
        set(sibling_height, add(sibling_height,
          person_height2(child, eq(child, person), marriage_date),
          min_sibling_spacer))
      }
      call reserve(child, depth)
    }
    call reserve(fam, depth)
  } else {
    set(num_siblings, 1)
    call reserve(person, depth)
  }

  /* See if father had any other children by a different mother
   * and add up the space to show them.  */
  set(branch_top, max(sub(person_minpos, older_sib_height), abs_min_pos))
  /* space for adjustment for cases except half-sibs with their ancestors */
  if(ceiling) {
    set(min_gap, sub(branch_top, abs_min_pos))
  }
  set(hsibling_height, 0)
  set(do_hs, 0)
  set(hs_line_start, 0)
      /* remember the people of this branch in case they have to be moved */
  call remember_branch_start()   /* for branch adjustment */

  if(and( gt(nfamilies(par1), 1), le(depth, depth_siblings),
           halfsib, notcutoff )) {
    set(dup_line, 1)
    families(par1, fv, sv, nf) {
/*      if(ne(fam, fv)) {*/
/* RES: stopgap */
      if(nestr(key(fam), key(fv))) {
        set(dup_line, and( dup_line, blocked(fv, depth)))
        if(and( halfsib_anc, le(depth, depth_halfsib_anc), notcutoff )) {
          call reserve(fv, depth)   /* reserve since parents will show */
          set(mdate, dateplace(marriage(fv), dateplace_marriage))
          set(pos, do_anc(sv, add(depth, 1), add(branch_top, hsibling_height),
              mdate, 1, 0, duplicate) )
          if(not(do_hs)){
            set(hs_line_start, pos) /* top end of half sib. vertical */
            set(branch_top, pos)
            /* this min_gap will be less than or equal to the previous one */
            if(and(ceiling, ne(min_gap_return, -1))) {
              set(min_gap, min(min_gap_return, min_gap))
              set(min_gap_set, TRUE)
            }
            set(do_hs, 1)
          } else {
            set(hs_bottom, pos)
            /* show children by previous spouse */
            set(pos, distribute_children(fv_prev, branch_top, hs_bottom,
                hsibling_height, depth, rel_next) )
            set(branch_top, hs_bottom)
          }
          set(fv_prev, fv)
          /* figure height of siblings by current spouse */
          set(hsibling_height, corner_height)
          children(fv, child, cn) {
            set(hsibling_height, add(hsibling_height,
                person_height2(child, FALSE, 0), min_sibling_spacer))
            call reserve(child, depth)
          }
        } else {
          children(fv, child, cn) {
            set(hsibling_height, add(hsibling_height,
                person_height2(child, FALSE, 0), min_sibling_spacer))
            call reserve(child, depth)
            if(not(do_hs)) {
              set(do_hs, 1)
            }
          }
        }
      }
    } /* end families loop for stepfamilies via parent #1 */
  }

  /* do father if he exists and is not too deep */
  set(dad_min_pos, add(branch_top, hsibling_height) )
  if(and( fam, lt(depth, max_depth), notcutoff )) {
    /* don't want to stretch the siblings, so constrain dad *
     * to be older_sib_height distance from person_minpos;  *
     * it will get added back before placement of person    */
    set(dad_pos, do_anc(par1, add(depth, 1), dad_min_pos,
        dateplace(marriage(fam), dateplace_marriage), 1, rel_next,
          or(duplicate, blocked(person, depth))) )
    set(first_sib_pos, add(dad_pos, corner_height))
    set(dup_dad, duplicate_anc_return)
    if( and( ceiling, ne(min_gap_return, -1), not(min_gap_set) ) ) {
      set(min_gap, min(min_gap_return, min_gap))
      set(min_gap_set, TRUE)
    }
  } else {    /* didn't do dad */
    set(dad_pos, dad_min_pos)
    if(gt(num_siblings, 1)) {
      /* if there are siblings then allow for just corner_height vert. *
       * line above first sibling  when siblings aren't shown            */
      set(first_sib_pos, add(dad_pos, corner_height))
    } else {
      set(first_sib_pos, dad_min_pos)
    }
    set(dup_dad, 0)
  }

  /* Do mother if she exists and is not too deep. */
  /* Her branch, will be at least branch_dist_same from dad's branch. */
  set(last_sib_pos, add(first_sib_pos, sibling_height))
  set(mom_min_pos, last_sib_pos)
  if(and( fam, lt(depth, max_depth), notcutoff )) {
    set(mom_min_pos, add(mom_min_pos, corner_height))
    set(mom_pos, do_anc(par2, add(depth, 1), mom_min_pos, 0, 1, rel_next,
        or(duplicate, blocked(person, depth))) )
    set(last_sib_pos, sub(mom_pos, corner_height))
    set(dup_mom, duplicate_anc_return)
    set(do_vertical_line, TRUE)
  } else {    /* didn't do mom */
    if(gt(num_siblings, 1)) {
      /* if more than one sibling then corner_height    *
       * is added to siblings vertical line             */
      set(mom_pos, add(mom_min_pos, corner_height))
      set(do_vertical_line, TRUE)
    } else {
      /* no vertical line */
      set(mom_pos, mom_min_pos)
      set(do_vertical_line, FALSE)
    }
    set(dup_mom, 0)
  }

  /* find the spacer needed to line up siblings between mother and father */
  set(extra, sub(sub(last_sib_pos, first_sib_pos), sibling_height))
  set(spacer, div(extra, add(num_siblings, 1)))
  if(and( debug, lt(spacer, 0) )) {
    print(" Spacer<0 for ", name(person), "(", key(person), ")", nl())
    print(" Dad_min_pos, dad_pos: ", d(dad_min_pos), ", ", d(dad_pos), nl())
    print(" sibling_height: ", d(sibling_height), nl())
    print(" Mom_min_pos, mom_pos: ",
      d(mom_min_pos), ", ", d(mom_pos), nl(), nl())
  }

  /* Shift the parents' branches back up the page if possible. */
  /* min_gap = space availble for upward shift */
  /* compared with diff between anticipated person_pos and minimum person_pos */
  /* - includes stretching of older siblings  */
  set(person_pos, add(dad_pos, older_sib_height, mul(num_not_younger, spacer)))
  set(gapshrink, sub(person_minpos, person_pos))
  if(ceiling) {
    set(gapshrink, max(neg(min_gap), gapshrink))
  }

  /* call branch_adjust to pop the branch_start* stacks, even if shift=0 */
  call branch_adjust(gapshrink)
  if(ne(gapshrink, 0)) {
    /* adjust local position variables affected by branch shift */
    set(dad_pos, add(dad_pos, gapshrink))
    set(mom_pos, add(mom_pos, gapshrink))
    set(first_sib_pos, add(first_sib_pos, gapshrink))
    /*set(last_sib_pos, add(last_sib_pos, gapshrink))*/  /*RES-not used again */
    if(do_hs) {
      set(branch_top, add(branch_top, gapshrink))
      set(hs_line_start, add(hs_line_start, gapshrink))
    }
    if(ceiling) {
      set(min_gap, min(0, add(min_gap, gapshrink)))
    }
    if(debug) {
      print(" ", make_thousandths(neg(gapshrink)))
      print(" units of space recovered for the branch of ", name(person), nl())
    }
  }

  /* position siblings differently depending on whether there's more than 1 */
  set(pos, first_sib_pos)
  if(and( le(depth, depth_siblings), gt(num_siblings, 1), notcutoff )) {
    children(fam, child, cn) {
      set(pos, add(pos, spacer))
      /* if this is the ancestor, return the position and use marriage */
/*      if(eq(child, person)) {*/
/*RES: stopgap measure for INDI equality problem in LL from CVS March 2004 */      if(eqstr(key(child), key(person))) {
        call enqueue_person(child, depth, pos, rel, marriage_date,
            1, has_des, fam)
        set(do_anc_return, pos)
        set(duplicate_anc_return, duplicate_return)
      } else {
        call enqueue_person(child, depth, pos, half(rel_next), 0, 1, 0, fam)
      }
      /* increment position by height of person, used for high_pos */
      set(pos, add(pos,
          person_height2(child, eq(child, person), marriage_date)))
      if(ne(cn, num_siblings)) {
        set(pos, add(pos, min_sibling_spacer))
      }
    }  /* end of children loop */

  } else {    /* depth > depth_siblings or person has no siblings */
    if(do_vertical_line) {
      /* center person on vertical line of parent(s) */
      set(pos, add(pos, spacer))
    }
    call enqueue_person(person, depth, pos, rel, marriage_date,
        has_anc, has_des, fam)
    set(do_anc_return, pos)
    set(duplicate_anc_return, duplicate_return)
    /* increment position by height of person, used for */
    /* high_pos and maternal half siblings line start   */
    set(pos, add(pos, person_height2(person, TRUE, marriage_date)))
  }

  if(do_vertical_line) {
    call enqueue_vertical(depth, dad_pos, mom_pos, rel_next, blocked(fam, depth))
    /* pos is used in setting high_pos later */
    set(pos, max(mom_pos, pos))
    /* only if parents have been shown should a family be considered as shown */
    if(and( lt(depth, max_depth), has_anc, not(blocked(fam, depth)) )) {
      call reserve(fam, start_depth)
    }
  }

  /* If father had any other kids by a different mother print them        */
  /* use hpos instead of pos to avoid messing up pos for high_pos setting */
  if(do_hs) {
    if(and( halfsib_anc, le(depth, depth_halfsib_anc), notcutoff )) {
      set(hs_bottom, dad_pos)
      set(hpos, distribute_children(fv_prev, branch_top, hs_bottom,
          hsibling_height, depth, rel_next))
    } else {
      set(hpos, branch_top)  /*sub(dad_pos, hsibling_height)) */
      set(hs_line_start, hpos)
      families(par1, fv, sv, nf) {
/*        if(ne(fam, fv)) {*/
/* RES: stopgap */
        if(nestr(key(fam), key(fv))) {
          children(fv, child, un) {
            call enqueue_person(child, depth, hpos, half(rel_next), 0, 1, 0, fv)
            /* increment position by height of person */
            set(hpos, add(
                hpos, person_height2(child, FALSE, 0), min_sibling_spacer))
          }
        }
      }
    }
    call enqueue_vertical(depth, hs_line_start, dad_pos,
        half(rel_next), dup_line)
  }

  /* See if mother had any other children by a different father */
  set(do_hs, 0)
  if(and( halfsib, le(depth, depth_siblings),
           gt(nfamilies(par2), 1), notcutoff )) {
    set(hs_line_start, mom_pos)
                        /* pos here is from end of vertical line of parents */
    set(branch_top,
        add(max(pos, add(mom_pos, corner_height)), min_sibling_spacer))
    set(dup_line, 1)
    set(pos, branch_top)
    families(par2, fv, sv, nf) {
/*      if(ne(fam, fv)) {*/
/* RES: more stopgap measure */
      if(nestr(key(fam), key(fv))) {
        set(dup_line, and(dup_line, blocked(fv, depth)))
        if(and( lt( depth, max_depth), halfsib_anc )) {
          set(do_hs, 1)
          call reserve(fv, depth)   /* reserve since parents will show */
          /* get height of stepfather's children */
          set(hsibling_height, corner_height)
          children(fv, child, un) {
            set(hsibling_height, add(hsibling_height,
                person_height2(child, FALSE, 0), min_sibling_spacer))
            call reserve(child, depth)
          }
          /* print ancestors of stepfather, including marriage date */
          set(mdate, dateplace(marriage(fv), dateplace_marriage))
          set(hs_bottom, do_anc(sv, add(depth, 1),
              add(branch_top, hsibling_height), mdate, 1, 0, duplicate) )
          /* show this stepfather's children */
          set(pos, distribute_children(fv, branch_top, hs_bottom,
              hsibling_height, depth, rel_next) )
          set(branch_top, hs_bottom)
        } else {
          set(hs_bottom, pos)
          children(fv, child, un) {
            if(not(do_hs)) { /* first maternal half siblings group */
              set(do_hs, 1)
            }
            call enqueue_person(child, depth, pos,
                half(rel_next), 0, 1, 0, fv)
            set(hs_bottom, pos)
            set(pos, add(pos, person_height2(child, FALSE, 0),
                min_sibling_spacer))
          }
        }
      }
    }
    /* If there were any maternal half siblings draw the vertical line */
    if(do_hs) {
      call enqueue_vertical(depth, hs_line_start, hs_bottom,
          half(rel_next), dup_line)
    }
  }

  if(ceiling) {
    set(min_gap_return, min_gap)
  } else {
    set(min_gap_return, -1)
  }
  call max_with_high_pos_gen(depth, pos)
  return(do_anc_return)
}

/*
**  function: do_des2
**
**  Produces descendant branches which recursively do as follows:
**  For the specified person, show all spouses and, if not at the generation
**  limit, show in the next generation a descendant branch for each child
**  by those spouses.
**
**  Branches may be directed up or down, under the influence of the user
**  option 'updown_override'.  However, a person's marriages are always
**  in database order from top to bottom.
**
**  If the user option 'duplic_handling' specifies that truncation of
**  a duplicate person's branch is prefered, this is done only if
**  all of a person's marriages have been shown.
*/

func do_des2(person, depth, min_pos, updown, rel, has_anc, duplicate, famc) {
  set(rel, rel_famc(person, famc, rel))
  set(nfam, nfamilies(person))
  set(child_depth, sub(depth, 1))
  if(eq(updown, NEUTRAL)) {
    if(or( and(mom_first, eqstr(sex(person), "F")),
           and(not(mom_first), eqstr(sex(person), "M")) )) {
      set(updown, direction(DOWN))
    } else {
      set(updown, direction(UP))
    }
  }
  set(notcutoff, not(and(
      eq(duplic_handling, 2), or(duplicate, blocked(person, depth)) )))
  if(not(notcutoff)) {  /* if we're about to cut off a branch... */
    families(person, fv, sp, nf) { /* cut off only if all marriages are shown */
      set(notcutoff, or(notcutoff, not(blocked(fv, depth))))
    }
  }
  if(tighten) {
    call cloak(add(depth, 1))
    call cloak(child_depth)
  }
  if(and( eq(updown, UP), notcutoff )) {
    if(or( lt(depth, sub(low_depth, 1)),
           and(lt(depth, low_depth), cloak_check(low_depth)) )) {
      set(ceiling, FALSE)
    } else {
      set(ceiling, TRUE)
    }
    call remember_branch_start()
    if(nfam) {
      set(line_top, branch_up(person, 0, depth, 1, rel))
      set(person_pos, branch_up_min_pos)
    } else {
      set(person_pos, get_clearance(depth, min_pos))
    }
    call enqueue_person(person, depth, person_pos, rel, 0, has_anc, nfam, famc)
    set(shift, sub(min_pos, person_pos))
    if(ceiling) {
      set(shift, max(0, shift))
    }
    call branch_adjust(shift)
    set(person_pos, add(person_pos, shift))
    if(nfam) {
      set(line_top, add(line_top, shift))
      call enqueue_vertical(child_depth, line_top, person_pos,
          rel, dup_line_return)
    }
    call max_with_high_pos_gen(depth,
             add(person_pos, person_height2(person, 0, 0)))
  } elsif(and( eq(updown, DOWN), notcutoff )) {
    set(person_pos, get_clearance(depth, min_pos))
    set(person_extent, add(person_pos, person_height2(person, 0, 0)))
    if(nfam) {
      set(person_pos, branch_down(person, person_pos, person_extent, TRUE, 0,
          depth, 1, rel))
    } else {
      call max_with_high_pos_gen(depth, person_extent)
    }
    call enqueue_person(person, depth, person_pos, rel, 0, has_anc, nfam, famc)
  } else {  /* cut off this person's branch */
    set(person_pos, get_clearance(depth, min_pos))
    call enqueue_person(person, depth, person_pos, rel, 0, has_anc, 0, famc)
    set(person_extent, add(person_pos, person_height2(person, 0, 0)))
    call max_with_high_pos_gen(depth, person_extent)
  }
  return(person_pos)
}

/*
**  procedure: distribute_children
**
**  Given a family key, evenly space
**  the children of the family in a vertical range determined
**  by top and bottom positions of the range.
**
**  sibling_height should include an extra corner_height to allow for
**  vertical skip that balances with the mandatory corner_height skip that
**  follows the last sibling's placement.
**
*/
/* RES - would be nice to either eliminate this pocedure or make
         it general enough to take on more tasks from do_anc
*/

func distribute_children(fam, top, bottom, sibling_height, depth, rel) {
  set(extra, sub(bottom, add(top, sibling_height)))
  set(spacer, div(extra, add(nchildren(fam), 1)))
  if(and(debug, lt(spacer, 0))) {
    print(" distribute_children: spacer < 0 !!\n")
    print("          top: ", d(top), "  bottom: ", d(bottom), nl())
  }
  
  set(pos, add(top, corner_height, spacer))
  children(fam, child, num) {
    call enqueue_person(child, depth, pos, half(rel), 0, 1, 0, fam)
    set(pos, add(
            pos, person_height2(child, FALSE, 0), min_sibling_spacer, spacer))
  }
  return(pos)
}

/*
**  function: branch_up
**
**  For a specific person, charts his/her spouses and the children/descendants
**  by them.
**
**  Shouldn't be called if nfamilies(person) is 0, or 1 when exclude_fam=0.
**  To notify us of a problem, this function is designed to intentionally
**  force an error message if there are no families to work with.  That is
**  because there is no good value to return in that case.
*/
/* RES -- add descriptions of the various return values to the above comment */

func branch_up(person, exclude_fam, depth, show_des, rel) {
  set(child_depth, sub(depth, 1))
  set(nfam, nfamilies(person))
  if(exclude_fam) { decr(nfam) }
  set(switch_fam, half(add(nfam, 1))) /* last family to branch up */
  set(dup_line, 1)
  set(dir, UP)
  set(fnn, 0)
  if(tighten) {
    call cloak(add(depth, 1))
    call cloak(child_depth)
  }
  set(spouse_minpos, get_clearance(depth, 0))
  families(person, fv, sv, fn) {
    if(ne(fv, exclude_fam)) {
      incr(fnn)
      set(dup_line, and(dup_line, blocked(fv, depth)))
      call reserve(sv, depth)
      call reserve(fv, depth)
      if(tighten) {
        call cloak(sub(child_depth, 1))
      }
      set(child_minpos, add(spouse_minpos, corner_height))
      set(child_minpos, get_clearance(child_depth, child_minpos))
      set(child_extent, 0)
      set(first_child_pos, child_minpos)
      if(gt(depth, min_depth)) {
        set(num_children, nchildren(fv))
        set(switch_child, half(add(nchildren(fv), 1)))
        children(fv, child, cn) {
          if(show_des) {
            set(child_pos,
                do_des2(child, child_depth, child_minpos, dir, rel, 1, 0, fv))
          } else {
            set(child_pos, child_minpos)
            call enqueue_person(child, child_depth, child_pos, rel, 0, 1, 0, fv)
            set(child_extent, add(child_pos, person_height2(child, 0, 0)))
            set(child_minpos, add(child_extent, min_sibling_spacer))
          }
          if(eq(cn, 1)) {
            set(first_child_pos, child_pos)
          }
          if(eq(cn, num_children)) {
            set(spouse_minpos, add(child_pos, corner_height))
          }
          if(and(eq(nfam, 1), eq(cn, switch_child))) {
            set(dir, DOWN)
          }
        }
        if(num_children) {
          call max_with_high_pos_gen(child_depth, child_extent)
        }
      }
      set(spouse_pos, sub(first_child_pos, corner_height))
      if(eq(fnn, 1)) {
        set(branch_top, spouse_pos)
      }
      /*
      print("sp: ", d(spouse_pos), "   bt: ", d(branch_top), "   fnn: ", d(fnn), "  fv: ", key(fv), nl())
      */
      if(le(depth, max_depth)) {
        set(mdate, dateplace(marriage(fv), dateplace_marriage))
        call enqueue_person(sv, depth, spouse_pos, 0, mdate, 0, 1, 0)
        set(spouse_extent, add(person_height2(sv, TRUE, mdate), spouse_pos))
        call max_with_high_pos_gen(depth, spouse_extent)
        if(not(blocked(fv, depth))) {
          call reserve(fv, start_depth)
        }
        set(spouse_minpos,
            max(add(get_high_pos_gen(depth), branch_dist_same), spouse_minpos))
      }
      if(eq(fnn, switch_fam)) {
        set(dir, DOWN)
      }
    }
  }
  set(branch_up_min_pos, spouse_minpos)
  set(dup_line_return, dup_line)
  return(branch_top)
}

/*
**  procedure: branch_down
**
**  person_extent should be either the bottom of the info on the person,
*/
/* RES -- add descriptions of the various return values to the above comment
          also need to just fix the above comment
*/

func branch_down(person, prev_spouse_pos, prev_spouse_extent, adjustable, exclude_fam, depth, show_des, rel) {
  set(person_pos, prev_spouse_pos)
  set(child_depth, sub(depth, 1))
  set(nfam, nfamilies(person))
  if(exclude_fam) { decr(nfam) }
  set(switch_fam, half(nfam)) /* last family to branch up */
  set(dup_line, 1)
  if(tighten) {
    call cloak(sub(child_depth, 1))
  }
  set(child_minpos, add(prev_spouse_pos, corner_height))
  set(child_minpos, get_clearance(child_depth, child_minpos))
  set(dir, direction(UP))
  set(fnn, 0)
  families(person, fv, sv, fn) {
    if(ne(fv, exclude_fam)) {
      incr(fnn)
      set(dup_line, and(dup_line, blocked(fv, depth)))
      call reserve(sv, depth)
      call reserve(fv, depth)
      if(tighten) {
        call cloak(sub(child_depth, 1))
      }
      set(child_minpos, add(prev_spouse_pos, corner_height))
      set(child_minpos, get_clearance(child_depth, child_minpos))
      set(child_extent, 0)
      set(first_child_pos, child_minpos)
      set(last_child_pos, child_minpos)
      call remember_branch_start()
      if(gt(depth, min_depth)) {
        set(num_children, nchildren(fv))
        set(switch_child, half(num_children)) /* favors DOWN when odd num_ch. */
        if(and(eq(nfam, 1), eq(switch_child, 0))) {
          set(dir, direction(DOWN))
        }
        children(fv, child, cn) {
          if(show_des) {
            set(child_pos,
                do_des2(child, child_depth, child_minpos, dir, rel, 1, 0, fv))
          } else {
            set(child_pos, child_minpos)
            call enqueue_person(child, child_depth, child_pos,
                     rel, 0, 1, 0, fv)
            set(child_extent, add(child_pos, person_height2(child, 0, 0)))
            set(child_minpos, add(child_extent, min_sibling_spacer))
          }
          if(eq(cn, 1)) {
            set(first_child_pos, child_pos)
          }
          if(eq(cn, num_children)) {
            set(last_child_pos, child_pos)
          }
          if(and(eq(nfam, 1), eq(cn, switch_child))) {
            set(dir, direction(DOWN))
          }
        }
        if(num_children) {
          call max_with_high_pos_gen(child_depth, child_extent)
        }
      }
      set(spouse_pos, add(last_child_pos, corner_height))
      /* adjust children + spouse to keep spouse clear of prev parent info */
      set(shift, max(
          0, sub(add(prev_spouse_extent, branch_dist_same), spouse_pos) ))
      call branch_adjust(shift)
      set(first_child_pos, add(first_child_pos, shift))
      set(spouse_pos, add(spouse_pos, shift))
      if(and(eq(fnn, 1), adjustable)) {
        set(person_pos, add(prev_spouse_pos, min(
          sub(sub(first_child_pos, corner_height), prev_spouse_pos),
          max(0, sub(spouse_pos, add(prev_spouse_extent, branch_dist_same)))
        )))
      }
      if(le(depth, max_depth)) {
        set(mdate, dateplace(marriage(fv), dateplace_marriage))
        call enqueue_person(sv, depth, spouse_pos, 0, mdate, 0, 1, 0)
        set(spouse_extent, add(person_height2(sv, TRUE, mdate), spouse_pos))
      } else {
        set(spouse_extent, name_height)
      }
      set(prev_spouse_pos, spouse_pos)
      set(prev_spouse_extent, spouse_extent)
      /* set next fam's child_minpos before this spouse can interfere */
      set(child_minpos, add(prev_spouse_pos, corner_height))
      set(child_minpos, get_clearance(child_depth, child_minpos))
      if(le(depth, max_depth)) {
        call max_with_high_pos_gen(depth, spouse_extent)
        if(not(blocked(fv, depth))) {
          call reserve(fv, start_depth)
        }
      }
      if(eq(fnn, switch_fam)) {
        set(dir, direction(DOWN))
      }
    }
  }
  if(gt(fnn, 0)) {
    call enqueue_vertical(child_depth, person_pos, spouse_pos, rel, dup_line)
  }
  return(person_pos)
}

/*
**  function: dropline
**
**  Generates a drop line chart of descendants of a person.
**  The return value is the vertical position of the person's horizontal line.
**
*/

func dropline(person, depth, has_anc, duplicate, rel, famc) {
   set(rel, rel_famc(person, famc, rel))
   set(abs_min_pos, get_clearance(depth, 0))
   set(child_depth, sub(depth, 1))
   set(low_depth, min(depth, low_depth))
   set(high_depth, max(depth, high_depth))
   set(notcutoff, not(and(
       eq(duplic_handling, 2), or(duplicate, blocked(person, depth)) )))
   if(and(desc_gender, ne(depth, start_depth))) {
     set(notcutoff, and(notcutoff, or(
       and(eq(desc_gender, 1), eqstr(sex(person), "F")),
       and(eq(desc_gender, 2), eqstr(sex(person), "M")) )))
   }
   call reserve(person, depth)
   set(line_to_kids, FALSE)
   set(vertical_line, FALSE)
   set(dup_line, TRUE)
   set(first_pos, abs_min_pos)
   set(last_pos, first_pos)
   set(child_pos, first_pos)
   call remember_branch_start()
   families(person, fam, spouse, fn) {
      set(dup_line, and(dup_line, blocked(fam, depth)))
      call reserve(fam, depth)
      children(fam, child, cn) {
         if(and(ge(child_depth, min_depth), notcutoff)) {
            set(child_pos, dropline(child, child_depth, TRUE,
               or(duplicate, blocked(person, depth)), rel, fam))
            if(not(line_to_kids)) {
               set(first_pos, child_pos)
            } else {
               set(vertical_line, TRUE)
            }
         }
         set(line_to_kids, TRUE)
      }
      if(and( ge(child_depth, min_depth), not(blocked(fam, depth)),
          notcutoff)) {
         /* marriage, indicated by vert. line, is original on the chart */
         call reserve(fam, start_depth)
      }
   }

   set(last_pos, child_pos)
   if(vertical_line) {
      call enqueue_vertical(child_depth, first_pos, last_pos, 2, dup_line)
   }

   set(this_pos, half(add(first_pos, last_pos)))
   set(shift, max(0, sub(abs_min_pos, this_pos)))
   call branch_adjust(shift)
   set(this_pos, add(this_pos, shift))
   call enqueue_person(person, depth, this_pos, rel, 0, has_anc, line_to_kids, famc)

   /* RES - this could be made obsolete if done by enqueue_person */
   /* maybe enqueue_person could return the person's extent */
   set(this_extent, add(this_pos, person_height2(person, FALSE, 0)))
   call max_with_high_pos_gen(depth, this_extent)
   return(this_pos)
}


/*
**  procedure: combo2
**
**  Show ancestors and descendants of a couple.
*/

proc combo2() {
  set(child_depth, sub(start_depth, 1))
  if(mom_first) {
    set(par1, wife(root_fam))
    set(par2, husband(root_fam))
  } else {
    set(par1, husband(root_fam))
    set(par2, wife(root_fam))
  }
  set(mdate, dateplace(marriage(root_fam), dateplace_marriage))
  set(num_siblings, nchildren(root_fam))

  call reserve(root_fam, start_depth)
  call reserve(par1, start_depth)
  call reserve(par2, start_depth)

  if(gt(nfamilies(par1), 1)) {
    set(hline_top, branch_up(par1, root_fam, start_depth, 1, 1))
  }
  call remember_branch_start()
  set(dad_pos, do_anc(par1, start_depth, 0, 0, 1, 2, 0) )

  if(and( ge(num_siblings, 1), gt(start_depth, min_depth) )) {
    set(first_sib_pos, add(dad_pos, corner_height))
    set(child_minpos, first_sib_pos)
    set(prev_pos, child_minpos)
    set(last_sib_pos, first_sib_pos)
    set(dir, direction(UP))
    set(switch_child, half(add(nchildren(root_fam), 1)))
    children(root_fam, child, cn) {
       call cloak(start_depth)
       call remember_branch_start()
       set(this_pos,
         do_des2(child, child_depth, child_minpos, dir, 2, 1, 0, root_fam) )
       set(prev_pos, this_pos)
       if(eq(cn, 1)) {
         set(first_sib_pos, this_pos)
       }
       if(eq(cn, num_siblings)) {
         set(last_sib_pos, this_pos)
       }
       if(eq(cn, switch_child)) {
         set(dir, direction(DOWN))
       }
    }
    set(dad_minpos, sub(first_sib_pos, corner_height))
    set(sibling_span, add(
        sub(last_sib_pos, first_sib_pos), mul(2, corner_height) ))
  } else {
    set(sibling_span, 0)
    set(dad_minpos, dad_pos)
  }
 
  set(shift, sub(dad_minpos, dad_pos))
  call branch_adjust_first(shift)
  /* need to shift dad's ancestor branch */
  set(dad_pos, dad_minpos)
  
  set(mom_minpos, add(dad_pos, sibling_span))
  call remember_branch_start()
  call cloak(child_depth)
  set(mom_pos, do_anc(par2, start_depth, mom_minpos, mdate, 1, 2, 0) )

  set(mom_shift, max(0, sub(mom_pos, mom_minpos)))
  call multi_branch_adjust(mom_shift, nchildren(root_fam))
  
  /* dad's marriage line for other spouses
     do this now to avoid the vert line being shifted by multi_branch_adjust */
  if(gt(nfamilies(par1), 1)) {
    call enqueue_vertical(child_depth, hline_top, dad_pos, 1, dup_line_return)
  }


  call enqueue_vertical(child_depth, dad_pos, mom_pos, 2, 0)

  set(not_used,
      branch_down(par2, mom_pos, 0, FALSE, root_fam, start_depth, 1, 1))
}


/*
**  procedure: do_cousins
**    show a couple as married along with their ancestors, descendants, and
**    the descendants of their siblings
*/

proc do_cousins() {
  set(child_depth, sub(start_depth, 1))
  set(grand_depth, add(start_depth, 1))

  set(num_sib, nchildren(root_fam))
  set(mdate_root_fam, dateplace(marriage(root_fam), dateplace_marriage))
  if(mom_first) {
    set(par1, wife(root_fam))
    set(par2, husband(root_fam))
  } else {
    set(par1, husband(root_fam))
    set(par2, wife(root_fam))
  }

  set(dfam, choosefamc(par1))
  set(drel, rel_famc(par1, dfam, 2))
  if(dfam) {
    set(num_dsib, nchildren(dfam))
    set(mdate_dfam, dateplace(marriage(dfam), dateplace_marriage))
    if(mom_first) {
      set(dpar1, wife(dfam))
      set(dpar2, husband(dfam))
    } else {
      set(dpar1, husband(dfam))
      set(dpar2, wife(dfam))
    }
  } else {
    set(dpar1, 0)
    set(dpar2, 0)
    set(num_dsib, 1)
    set(mdate_dfam, 0)
  }

  set(mfam, choosefamc(par2))
  set(mrel, rel_famc(par2, mfam, 2))
  if(mfam) {
    set(num_msib, nchildren(mfam))
    set(mdate_mfam, dateplace(marriage(mfam), dateplace_marriage))
    if(mom_first) {
      set(mpar1, wife(mfam))
      set(mpar2, husband(mfam))
    } else {
      set(mpar1, husband(mfam))
      set(mpar2, wife(mfam))
    }
  } else {
    set(mpar1, 0)
    set(mpar2, 0)
    set(num_msib, 1)
    set(mdate_mfam, 0)
  }

  call reserve(par1, start_depth)
  call reserve(par2, start_depth)
  call reserve(root_fam, start_depth)
  if(dfam) { /* this is enough to catch extra appearances in anc branches */
    call reserve(dpar1, grand_depth)
    call reserve(dpar2, grand_depth)
    call reserve(dfam, grand_depth)
    families(dpar1, fv, sv, fn) { /* claim originality for start_depth people */
      children(fv, cv, cn) {
        call reserve(cv, start_depth)
        families(cv, cfv, csv, cfn) {
          call reserve(cfv, start_depth)
        }
      }
    }
    families(dpar2, fv, sv, fn) {
      if(ne(sv, dpar1)) {
        children(fv, cv, cn) {
          call reserve(cv, start_depth)
          families(cv, cfv, csv, cfn) {
            call reserve(cfv, start_depth)
          }
        }
      }
    }
  }
  if(mfam) {
    call reserve(mpar1, grand_depth)
    call reserve(mpar2, grand_depth)
    call reserve(mfam, grand_depth)
    families(mpar1, fv, sv, fn) { /* claim originality for start_depth people */
      children(fv, cv, cn) {
        call reserve(cv, start_depth)
        families(cv, cfv, csv, cfn) {
          call reserve(cfv, start_depth)
        }
      }
    }
    families(mpar2, fv, sv, fn) {
      if(ne(sv, mpar1)) {
        children(fv, cv, cn) {
          call reserve(cv, start_depth)
          families(cv, cfv, csv, cfn) {
            call reserve(cfv, start_depth)
          }
        }
      }
    }
  }

  print(" Determining relative spacing of 1st parent's ancestors...\n")
  if(gt(nfamilies(dpar1), 1)) {
    set(hline_top, branch_up(dpar1, dfam, grand_depth, FALSE, half(drel)))
    call cloak(start_depth)
  }
  set(ddad_pos, do_anc(dpar1, grand_depth, 0, mdate_dfam, 1, drel, 0) )
  set(ddad_minpos, ddad_pos)

  set(dmom_pos, do_anc(dpar2, grand_depth, ddad_minpos, 0, 1, drel, 0) )
  set(dmom_relpos, sub(dmom_pos, ddad_pos))
  if(not(blocked(dfam, grand_depth))) {
    call reserve(dfam, start_depth)
  }
/* RES interferes with relative position figuring of the grandparents */
/* RES need to just replace this with a reserving of the spouses and children */
/*
  set(not_used, branch_down(dpar2, dmom_pos, 0, FALSE, dfam,
      grand_depth, FALSE, half(drel)))
*/

  print(" Determining relative spacing of 1st parent's siblings...\n")
  set(child_minpos, add(ddad_minpos, corner_height))
  set(prevpos, child_minpos)
  if(gt(num_dsib, 1)) {
    list(dsib_relpos)
    set(dir, direction(UP)) /* all of 1st parent's siblings can branch up */
    set(cnn, 0)
    children(dfam, child, cn) {
      if(ne(child, par1)) {
        set(cnn, add(cnn, 1))
        call cloak(grand_depth)
        set(thispos,
          do_des2(child, start_depth, child_minpos, dir,
              half(drel), 1, 0, dfam))
        setel(dsib_relpos, cn, sub(thispos, prevpos))
        set(prevpos, thispos)
        if(eq(cnn, 1)) {
          set(first_dsib_pos, thispos)
          setel(dsib_relpos, cn, 0)
        }
        if(eq(cnn, sub(num_dsib, 1))) {
          set(last_dsib_pos, thispos)
          set(dad_minpos, add(thispos,
            person_height2(child, FALSE, 0), branch_dist_same))
        }
      }
    }
    /* ddad_minpos might be affected by up-branching of descendants */
    set(ddad_minpos, sub(first_dsib_pos, corner_height))
  } else {
    set(first_dsib_pos, child_minpos)
    set(last_dsib_pos, first_dsib_pos)
    set(dad_minpos, add(ddad_minpos, corner_height))
  }

  print(" Determining relative spacing of the family's descendants...\n")
  if(gt(nfamilies(par1), 1)) {
    call cloak(grand_depth)
    set(line_top, branch_up(par1, root_fam, start_depth, TRUE, 1))
    set(dad_minpos, max(
        dad_minpos, add(get_high_pos_gen(start_depth), branch_dist_same) ))
  }
  set(dad_relpos, sub(dad_minpos, last_dsib_pos))
  set(older_dsib_height, sub(dad_minpos, ddad_minpos))

  set(prevpos, add(dad_minpos, corner_height))
  set(child_minpos, prevpos)
  if( and(gt(num_sib, 0), ge(child_depth, min_depth)) ) {
    list(sib_relpos)
    set(dir, direction(UP))
    set(switch_child, half(add(nchildren(root_fam), 1)))
    children(root_fam, child, cn) {
      call cloak(start_depth)
      set(thispos,
        do_des2(child, child_depth, child_minpos, dir, 2, 1, 0, root_fam) )
      setel(sib_relpos, cn, sub(thispos, prevpos))
      set(prevpos, thispos)
      if(eq(cn, 1)) {
        set(first_sib_pos, thispos)
        setel(sib_relpos, cn, 0)
      }
      if(eq(cn, num_sib)) {
        set(last_sib_pos, thispos)
      }
      if(eq(cn, switch_child)) {
        set(dir, direction(DOWN))
      }
    }
  } else {
    set(first_sib_pos, child_minpos)
    set(last_sib_pos, first_sib_pos)
  }
  set(sib_span, add(sub(last_sib_pos, first_sib_pos), mul(2, corner_height)))
  /* place dad corner_height before his first child */
  set(dad_pos, max( dad_minpos, sub(first_sib_pos, corner_height) ))
  if(gt(num_dsib, 1)) {
/* commented out because it can cause first parent to push away from siblings*/
/*    set(dad_relpos, sub(dad_pos, last_dsib_pos))*/
    set(older_dsib_height, sub(dad_pos, ddad_minpos))
  }
  
  set(dsib_span, add(older_dsib_height, corner_height))
  set(spacer1, div( max(0, sub(dmom_relpos, dsib_span)), add(num_dsib, 1) ))
  set(ddad_minpos, max( ddad_minpos,
      sub(sub(dad_pos, older_dsib_height), mul(num_dsib, spacer1)) ))

  call enqueue_person(par1, start_depth, dad_pos, 2, mdate_root_fam, 1, 1, 0)
  set(par1_extent, add(dad_pos, person_height2(par1, TRUE, mdate_root_fam)))
  call max_with_high_pos_gen(start_depth, par1_extent)

  print(" Determining relative spacing of the 2nd parent's ancestors...\n")
/* RES - up-branch above mother would have parent(s) that block mdad from
   determining how close he can go to dmom's branch

  if(gt(nfamilies(mpar1), 1)) {
    call cloak(child_depth)
    set(hline_top, branch_up(mpar1, mfam, grand_depth, FALSE, half(mrel)))
  }
*/
  call cloak(start_depth) /* RES - necessary due to par1 info lines ? */
  set(mdad_pos, do_anc(mpar1, grand_depth, 0, mdate_mfam, 1, mrel, 0))
  set(mdad_relpos, sub(mdad_pos, dmom_pos))

  call cloak(start_depth)
  set(mmom_pos, do_anc(mpar2, grand_depth, mdad_pos, 0, 1, mrel, 0) )
  set(mmom_relpos, sub(mmom_pos, mdad_pos))
  if(not(blocked(mfam, grand_depth))) {
    call reserve(mfam, start_depth)
  }
  set(not_used, branch_down(mpar2, mmom_pos, 0, FALSE, mfam,
      grand_depth, FALSE, half(mrel)))

  set(mom_pos, max( add(last_sib_pos, corner_height),
      add(get_high_pos_gen(start_depth), branch_dist_same) ))
  call enqueue_person(par2, start_depth, mom_pos, 2, 0, 1, 1, 0)
  set(par2_extent, add(mom_pos, person_height2(par2, FALSE, 0)))
  call max_with_high_pos_gen(start_depth, par2_extent)
  set(not_used, branch_down(par2, mom_pos, 0, FALSE, root_fam,
      start_depth, TRUE, 1))

  print(" Determining relative spacing of 2nd parent's siblings...\n")
  set(prevpos, mom_pos)
  set(child_minpos,
      add(mom_pos, person_height2(par2, FALSE, 0), branch_dist_same))
  if(gt(num_msib, 1)) {
    list(msib_relpos)
    set(dir, direction(DOWN)) /* all of 2nd parent's siblings branch down */
    set(cnn, 0)
    children(mfam, child, cn) {
      if(ne(child, par2)) {
        incr(cnn)
        call cloak(grand_depth)
        call cloak(child_depth)   /* RES experimental */
        set(thispos, do_des2(child, start_depth, child_minpos,
            dir, half(mrel), 1, 0, mfam))
        setel(msib_relpos, cn, sub(thispos, prevpos))
        set(prevpos, thispos)
        if(eq(cnn, sub(num_msib, 1))) {
          set(last_msib_pos, thispos)
        }
      }
    }
  } else {
    set(last_msib_pos, prevpos)
  }
  set(msib_span, sub(add(last_msib_pos, corner_height),
                       sub(mom_pos, corner_height)) )
  set(spacer2, div( max(0, sub(mmom_relpos, msib_span)), add(num_msib, 1) ))

  call initialize_data()
/*------------------------cousin middle-------------------------------------*/

  print(" Determining final positions on the chart...\n")
  call reserve(root_fam, start_depth)
  call reserve(par1, start_depth)
  call reserve(par2, start_depth)
  if(dfam) { /* this is enough to catch extra appearances in anc branches */
    call reserve(dpar1, grand_depth)
    call reserve(dpar2, grand_depth)
    call reserve(dfam, grand_depth)
    families(dpar1, fv, sv, fn) { /* claim originality for start_depth people */
      children(fv, cv, cn) {
        call reserve(cv, start_depth)
        families(cv, cfv, csv, cfn) {
          call reserve(cfv, start_depth)
        }
      }
    }
    families(dpar2, fv, sv, fn) {
      if(ne(sv, dpar1)) {
        children(fv, cv, cn) {
          call reserve(cv, start_depth)
          families(cv, cfv, csv, cfn) {
            call reserve(cfv, start_depth)
          }
        }
      }
    }
  }
  if(mfam) {
    call reserve(mpar1, grand_depth)
    call reserve(mpar2, grand_depth)
    call reserve(mfam, grand_depth)
    families(mpar1, fv, sv, fn) { /* claim originality for start_depth people */
      children(fv, cv, cn) {
        call reserve(cv, start_depth)
        families(cv, cfv, csv, cfn) {
          call reserve(cfv, start_depth)
        }
      }
    }
    families(mpar2, fv, sv, fn) {
      if(ne(sv, mpar1)) {
        children(fv, cv, cn) {
          call reserve(cv, start_depth)
          families(cv, cfv, csv, cfn) {
            call reserve(cfv, start_depth)
          }
        }
      }
    }
  }

  if(gt(nfamilies(dpar1), 1)) {
    set(hline_top, branch_up(dpar1, dfam, grand_depth, FALSE, half(drel)))
    call cloak(start_depth)
  }
  set(ddad_pos, do_anc(dpar1, grand_depth, ddad_minpos, mdate_dfam, 1, drel, 0))
  if(gt(nfamilies(dpar1), 1)) {
    call enqueue_vertical(start_depth, hline_top, ddad_pos,
        half(drel), dup_line_return)
  }
  if(debug2) {
    if(ne(ddad_minpos, ddad_pos)) {
      print(" ddad appears to be slipping...", nl())
      print("  ", d(ddad_minpos), " -> ", d(ddad_pos), nl())
    }
  }

  set(prevpos, add(ddad_pos, corner_height))
  set(dir, direction(UP))
  children(dfam, child, cn) {
    if(ne(child, par1)) {
      set(child_minpos, add(prevpos, getel(dsib_relpos, cn), spacer1))
      call cloak(grand_depth)
      set(prevpos,
        do_des2(child, start_depth, child_minpos, dir, half(drel), 1, 0, dfam))
      if(and(debug, ne(prevpos, child_minpos))) {
        print(name(child), " child_minpos != actual\n")
      }
    } else {
      if(ne(cn, num_dsib)) {
        print("The first parent has been moved to last in his/her sibling order.", nl())
      }
    }
  }

  call remember_branch_start()
  set(dad_minpos, add(prevpos, dad_relpos))
  if(gt(nfamilies(par1), 1)) {
    call cloak(grand_depth)
    set(hline_top, branch_up(par1, root_fam, start_depth, TRUE, 1))
    set(dad_pos, max(branch_up_min_pos,
        add(get_high_pos_gen(start_depth), branch_dist_same)) )
  }
/* HERE */
  call enqueue_person(par1, start_depth, dad_pos, 2, mdate_root_fam, 1, 1, 0)
  set(par1_extent, add(dad_pos, person_height2(par1, TRUE, mdate_root_fam)))
  call max_with_high_pos_gen(start_depth, par1_extent)
  set(dad_minpos, add(prevpos, dad_relpos, spacer1))
  call branch_adjust(max(0, sub(dad_minpos, dad_pos)))
  set(dad_pos, max(dad_minpos, dad_pos))
  if(gt(nfamilies(par1), 1)) {
    call enqueue_vertical(child_depth, hline_top, dad_pos,
        1, dup_line_return)
  }

  set(dmom_minpos, add(dad_pos, corner_height, spacer1))
  call cloak(start_depth)        /* to ignore dsibs */
  set(dmom_pos, do_anc(dpar2, grand_depth, dmom_minpos, 0, 1, drel, 0))
  if(debug2) {
    if(ne(dmom_minpos, dmom_pos)) {
      print(" dmom appears to be slipping...", nl())
      print(d(dmom_minpos), " -> ", d(dmom_pos), nl())
    }
  }
  call enqueue_vertical(start_depth, ddad_pos, dmom_pos, drel,
      blocked(dfam, grand_depth))
  if(not(blocked(dfam, grand_depth))) {
    call reserve(dfam, start_depth)
  }
  set(not_used, branch_down(dpar2, dmom_pos, 0, FALSE, dfam,
      grand_depth, FALSE, half(drel)))

  /* RES - new25jun 1 line*/
  set(mdad_minpos, max(add(dmom_pos, mdad_relpos),
      get_high_pos_gen(start_depth)))
  if(gt(nfamilies(mpar1), 1)) {
    call remember_branch_start()
    set(hline_top, branch_up(mpar1, mfam, grand_depth, FALSE, half(mrel)))
/* RES - new22jun */
    set(shift, max(0, sub(mdad_minpos, branch_up_min_pos)))
    call branch_adjust(shift)
    set(hline_top, add(hline_top, shift))
    call cloak(start_depth)
  }
  /* RES - max with mdad_minpos + c.h. + sp2 is a safeguard */
  set(mom_pos, max( add(dad_pos, sib_span),
      add(mdad_minpos, corner_height, spacer2)))
  set(mdad_minpos, max(mdad_minpos, sub(sub(mom_pos, corner_height), spacer2)))
  call cloak(start_depth)
  set(mdad_pos, do_anc(mpar1, grand_depth, mdad_minpos, mdate_mfam, 1, mrel, 0))
  if(gt(nfamilies(mpar1), 1)) {
    call enqueue_vertical(start_depth, hline_top, mdad_pos,
        half(mrel), dup_line_return)
  }
  
  set(mmom_minpos, add(mdad_pos, max(mmom_relpos, msib_span)) )
  set(spacer, div( max(0, sub(sub(mom_pos, dad_pos), sib_span)),
      add(num_sib, 1) ))

  set(prevpos, add(dad_pos, corner_height))
  if(ge(child_depth, min_depth)) {
    set(dir, direction(UP))
    set(switch_child, half(add(nchildren(root_fam), 1)))
    children(root_fam, child, cn) {
      set(child_minpos, add(prevpos, getel(sib_relpos, cn), spacer))
      call cloak(start_depth)
      set(prevpos,
        do_des2(child, child_depth, child_minpos, dir, 2, 1, 0, root_fam))
      if(debug) {
        if(ne(child_minpos, prevpos)) {
          print(" ! Descendant branch slipping down page ! (",
              name(child), ")\n")
          print("  As a result, there will be extra space above the branch.\n")
        }
      }
      if(eq(cn, switch_child)) {
        set(dir, direction(DOWN))
      }
    }
  }

  if(gt(add(prevpos, spacer, corner_height), mom_pos)) {
    print(" 2nd parent will be moved to compensate for descendant slippage\n")
    set(mom_pos, max(mom_pos, add(prevpos, spacer, corner_height)))
  }
  /* RES - fix unknown reason why mom has no corner between her and mpar1 */
  set(mom_pos, max(mom_pos, add(mdad_pos, corner_height, spacer2)))
  call enqueue_person(par2, start_depth, mom_pos, 2, 0, 1, 1, 0)
  set(par2_extent, add(mom_pos, person_height2(par2, FALSE, 0)))
  call max_with_high_pos_gen(start_depth, par2_extent)
  call enqueue_vertical(child_depth, dad_pos, mom_pos, 2, 0)
  set(not_used, branch_down(par2, mom_pos, 0, FALSE, root_fam,
      start_depth, TRUE, 1))

  set(prevpos, mom_pos)
  set(dir, direction(DOWN))
  children(mfam, child, cn) {
    if(ne(child, par2)) {
      set(child_minpos, add(prevpos, getel(msib_relpos, cn), spacer2))
      call cloak(grand_depth)
      call cloak(child_depth)
      set(prevpos,
        do_des2(child, start_depth, child_minpos, dir, half(mrel), 1, 0, mfam))
    } else {
      if(ne(cn, num_msib)) {
        print("The second parent has been moved to first in his/her sibling order.", nl())
      }
    }
  }

  set(mmom_minpos, max(mmom_minpos, add(prevpos, corner_height, spacer2)))
  call cloak(start_depth)        /* to ignore msibs */
  set(mmom_pos, do_anc(mpar2, grand_depth, mmom_minpos, 0, 1, 2, 0) )
  if(and(debug, ne(mmom_pos, mmom_minpos))) {
    print(" mmom appears to be slipping...", nl())
    print("  ", d(mmom_minpos), " -> ", d(mmom_pos), nl())
  }
  call enqueue_vertical(start_depth, mdad_pos, mmom_pos, mrel,
      blocked(mfam, grand_depth))
  if(not(blocked(mfam, grand_depth))) {
    call reserve(mfam, start_depth)
  }
  set(not_used, branch_down(mpar2, mmom_pos, 0, FALSE, mfam,
      grand_depth, FALSE, half(mrel)))
}

/*========================== end of charting functions ======================*/

/*
** function: rel_famc
**
** Checks for a pedigree tag on a FAMC link to determine if the relationsship
** is not by birth.  Returns 0 if not birth or echoes the relationship passed
** in otherwise.
*/

func rel_famc(ind, fam, rel) {
  if(or(not(opt_rel_famc), not(fam))) {
    return(rel)
  }
  set(ped_label, pedigree(ind, fam))
  if(eq(1, index(lower(ped_label), "birth", 1))) {
    return(rel)
  } else {
    return(0)
  }
}

/*
** function: pedigree
**
** Returns a string identifying the nature of a child-to-family (FAMC) link.
** Different relationships are indicated by a subnode tag of PEDI which may
** have the following values:  Birth, Adopted, Foster, Sealed
*/

func pedigree(ind, fam_match) {
  if(or(not(ind), not(fam_match))) {
    return(0)
  }
  set(pedi_label, "")
  fornodes(inode(ind), node) {
    if(eqstr(tag(node), "FAMC")) {
      set(fam_this, fam(value(node)))
      if(eq(fam_this, fam_match)) {
        set(birth_famc, 1)
        set(pedi_label, "Birth (assumed)")
        fornodes(node, subnode) {
          if(eqstr(tag(subnode), "PEDI")) {
            set(birth_famc, 0)
            set(pedi_label, value(subnode))
            if( or( eqstr(pedi_label, "Birth"),
                eqstr(pedi_label, "birth")) ) {
              set(birth_famc, 1)
            } elsif(eqstr(pedi_label, "")) {
              print("! ", name(indi),
                " has a FAMC.PEDI node with no value.", nl())
            }
          }
        }
      }
    }
  }
  return(pedi_label)
}

/*
** function: choosefamc
**
** Offers the choice of parent families of a child when there are several,
** as with adoption, fostering, or sealing (LDS).
** A child-to-family link is indicated by a FAMC tag with a family
** cross-reference in an individual's GEDCOM record.
**
*/

func choosefamc(ind) {
  if(not(ind)) {
    return(0)
  }
  list(choices)
  table(fams)
  fornodes(inode(ind), node) {
    if(eqstr(tag(node), "FAMC")) {
      set(choice, "")
      set(choice, concat("FAMC ", value(node)))
      set(fam_this, fam(value(node)))
      set(birth_famc, 1)
      set(pedi_label, "Birth (assumed)")
      fornodes(node, subnode) {
        if(eqstr(tag(subnode), "PEDI")) {
          set(birth_famc, 0)
          set(pedi_label, value(subnode))
          if( or( eqstr(pedi_label, "Birth"),
              eqstr(pedi_label, "birth")) ) {
            set(birth_famc, 1)
          } elsif(eqstr(pedi_label, "")) {
            print(" ", name(indi), " has a FAMC.PEDI node with no value.", nl())
          }
          break()
        }
      }
      set(choice, concat(choice, " ", pedi_label))
      enqueue(choices, choice)
      insert(fams, d(length(choices)), fam_this)
    }
  }
  if(empty(choices)) {
    return(0)
  }
  if(eq(length(choices), 1)) {
    set(mc, 1)
  } else {
    set(mc,
      menuchoose(choices, concat("Choose a parent family of ", name(ind))))
    if(eq(mc, 0)) {
      return(0)
    }
  }
  return(lookup(fams, d(mc)))
}

/*
**  procedure: reserve
**
**
*/

proc reserve(person, depth) {
  if(and(person, duplic_handling)) {
    /* better code for LL 3.0.5 users -tentative*/
    /* problem seems to be that inlist only returns T/F, not position */
    /*
    set(n, inlist(original_person, person))
    if(ne(n, 0)) {
      set(level, getel(original_depth, n))
      if(le( abs(sub(depth, start_depth)), abs(sub(level, start_depth)) )) {
        setel(original_depth, n, depth)
      }
    } else {
      enqueue(original_person, key(person))
      enqueue(original_depth, depth)
    }
    */
    set(on_list, 0)
    forlist(original_person, i, n) {
      if(eqstr(key(person), i)) {
        set(on_list, 1)
        set(level, getel(original_depth, n))
        if(le( abs(sub(depth, start_depth)), abs(sub(level, start_depth)) )) {
          setel(original_depth, n, depth)
        }
        break()
      }
    }
    if(not(on_list)) {
      enqueue(original_person, key(person))
      enqueue(original_depth, depth)
    }
  }
}

/*
**  function: blocked
**
**  Return 1 if individual is  blocked by a reservation at an earlier depth,
**         0 otherwise
*/

func blocked(person, depth) {
  set(ans, 0)
  if(not(person)) {
    return(ans)
  }
  if(duplic_handling) {
    /* better code for LL 3.0.5 users -tentative*/
    /*
    set(n, inlist(original_person, person))
    if(ne(n, 0)) {
      if(gt( abs(sub(depth, start_depth)), abs( sub(level, start_depth)) )) {
        set(ans, 1)
        break()
      }
    }
    */
    forlist(original_person, i, n) {
      if(eqstr(key(person), i)) {
        set(level, getel(original_depth, n))
        /* only block appearances farther away from root than original person */
        if(gt( abs(sub(depth, start_depth)), abs(sub(level, start_depth)) )) {
           set(ans, 1)
           break()
        }
      }
    }
  }
  return(ans)
}


/*
**  procedure: remember_branch_start
**
**  pushes lengths of person and line lists onto special stacks
**
*/

proc remember_branch_start() {
   push(branch_start_person, add(length(plist_pos), 1))
   push(branch_start_line, add(length(llist_low), 1))
   set(bsp, length(branch_start_person))
   set(bsl, length(branch_start_line))
   if(ne(bsp, bsl)) {
     print("! for some reason, a fragment of a branch mark was left behind\n")
     print("  length(branch_start_person): ", d(bsp), nl())
     print("  length(branch_start_line): ", d(bsl), nl())
   }
}


/*
** procedure: branch_adjust
**
** 'shift' is the signed distance of the adjustment,
**         positive for down the chart.
** 
** Originally written to recover space when younger siblings get spread
** apart and their first parent branch has room to move back up the page.
** Now this task has been made general enough to be able to shift any branch
** in either direction, vertically. -- by Robert Simms 
*/

proc branch_adjust(shift) {
  set(start_plist, pop(branch_start_person))
  set(start_llist, pop(branch_start_line))

  if(and(ne(shift, 0), ge(length(plist_depth), start_plist))) {
    /* initialize low_depth_this_branch and high_depth_this_branch */
    set(low_depth_this_branch, getel(plist_depth, start_plist))
    set(high_depth_this_branch, low_depth_this_branch)
    forlist(plist_depth, stored_depth, pc) {
      if(ge(pc, start_plist)) {
        /* find the depth range from plist_depth  */
        set(low_depth_this_branch, min(low_depth_this_branch, stored_depth)) 
        set(high_depth_this_branch, max(high_depth_this_branch, stored_depth))
      }
    }
    /* make adjustment in global lists */
    forlist(plist_pos, stored_pos, pc) {
      if(ge(pc, start_plist)) {
        setel(plist_pos, pc, add(stored_pos, shift))
      }
    }
    forlist(llist_low, stored_pos, pc) {
      if(ge(pc, start_llist)) {
        setel(llist_low, pc, add(stored_pos, shift))
      }
    }
    forlist(llist_high, stored_pos, pc) {
      if(ge(pc, start_llist)) {
        setel(llist_high, pc, add(stored_pos, shift))
      }
    }
    set(depth_val, low_depth_this_branch)
    while(le(depth_val, high_depth_this_branch)) {
       set(stored_pos, get_high_pos_gen(depth_val))
       /* don't need to do this for current depth of caller because
        * high_pos_gen has likely already been read and will be set by caller
        * after use of this procedure.  Leave it just in case -- it's easier. */
       call set_high_pos_gen(depth_val, add(stored_pos, shift))
       incr(depth_val)
    }
  }
}

/*
** procedure: branch_adjust_first
**
** 'shift' is the signed distance of the adjustment,
**         positive for down the chart.
** 
** this procedure will adjust the first branch delimited by 'markers'
** (markers are indices stored in branch_start_person and branch_start_line
** that refer to the various plist_ and llist_ lists that store person and line
** vertical coordinates.
*/

proc branch_adjust_first(shift) {
  set(start_plist, dequeue(branch_start_person))
  set(start_llist, dequeue(branch_start_line))
  if(gt(length(branch_start_person), 0)) {
    set(stop_plist, getel(branch_start_person, 1))
  } else {
    set(stop_plist, add(length(plist_person), 1))
  }
  if(gt(length(branch_start_line), 0)) {
    set(stop_llist, getel(branch_start_line, 1))
  } else {
    set(stop_llist, add(length(llist_low), 1))
  }

  if(and(ne(shift, 0), ge(length(plist_depth), start_plist))) {
    /* initialize low_depth_this_branch and high_depth_this_branch */
    set(low_depth_this_branch, getel(plist_depth, start_plist))
    set(high_depth_this_branch, low_depth_this_branch)
    forlist(plist_depth, stored_depth, pc) {
      if(and(ge(pc, start_plist), lt(pc, stop_plist))) {
        /* find the depth range from plist_depth  */
        set(low_depth_this_branch, min(low_depth_this_branch, stored_depth)) 
        set(high_depth_this_branch, max(high_depth_this_branch, stored_depth))
      }
    }
    /* make adjustment in global lists */
    forlist(plist_pos, stored_pos, pc) {
      if(and(ge(pc, start_plist), lt(pc, stop_plist))) {
        setel(plist_pos, pc, add(stored_pos, shift))
      }
    }
    forlist(llist_low, stored_pos, pc) {
      if(and(ge(pc, start_llist), lt(pc, stop_llist))) {
        setel(llist_low, pc, add(stored_pos, shift))
      }
    }
    forlist(llist_high, stored_pos, pc) {
      if(and(ge(pc, start_llist), lt(pc, stop_llist))) {
        setel(llist_high, pc, add(stored_pos, shift))
      }
    }
    set(depth_val, low_depth_this_branch)
    while(le(depth_val, high_depth_this_branch)) {
       set(stored_pos, get_high_pos_gen(depth_val))
       /* don't need to do this for current depth of caller because
        * high_pos_gen has likely already been read and will be set by caller
        * after use of this procedure.  Leave it just in case -- it's easier. */
       /* doing this under the assumption that nothing has been placed beneath this branch on the chart*/
       call set_high_pos_gen(depth_val, add(stored_pos, shift))
       incr(depth_val)
    }
  }
}


/*
** procedure: multi_branch_adjust
**
** 'shift' is the signed distance of the adjustment,
**         positive for down the chart.
** 
** Originally written to recover space when younger siblings get spread
** apart and their first parent branch has room to move back up the page.
** Now this task has been made general enough to be able to shift any branch
** in either direction, vertically. -- by Robert Simms 
*/

proc multi_branch_adjust(total_shift, nbranches) {
  set(i, 1)
  set(stop_plist, dequeue(branch_start_person))
  set(stop_llist, dequeue(branch_start_line))
  while(le(i, nbranches)) {
    set(start_plist, stop_plist)
    set(start_llist, stop_llist)
    set(stop_plist, dequeue(branch_start_person))
    set(stop_llist, dequeue(branch_start_line))

    set(shift, div(mul(i, total_shift), add(nbranches, 1)))

    if(and(ne(shift, 0), ge(length(plist_depth), start_plist))) {
      /* initialize low_depth_this_branch and high_depth_this_branch */
      set(low_depth_this_branch, getel(plist_depth, start_plist))
      set(high_depth_this_branch, low_depth_this_branch)
      forlist(plist_depth, stored_depth, pc) {
        if(and(ge(pc, start_plist), lt(pc, stop_plist))) {
          /* find the depth range from plist_depth  */
          set(low_depth_this_branch, min(low_depth_this_branch, stored_depth)) 
          set(high_depth_this_branch, max(high_depth_this_branch, stored_depth))
        }
      }
      /* make adjustment in global lists */
      forlist(plist_pos, stored_pos, pc) {
        if(and(ge(pc, start_plist), lt(pc, stop_plist))) {
          setel(plist_pos, pc, add(stored_pos, shift))
/* RES - won't be necessary when highest person in each gen is tracked */
          call max_with_high_pos_gen(getel(plist_depth, pc), add(stored_pos,
             shift, getel(plist_height, pc)))
        }
      }
      forlist(llist_low, stored_pos, pc) {
        if(and(ge(pc, start_llist), lt(pc, stop_llist))) {
          setel(llist_low, pc, add(stored_pos, shift))
        }
      }
      forlist(llist_high, stored_pos, pc) {
        if(and(ge(pc, start_llist), lt(pc, stop_llist))) {
          setel(llist_high, pc, add(stored_pos, shift))
        }
      }
    }
    incr(i)
  }
/* MUST reassess high_pos_gen for each gen in [low, high] this branch */
/*
  set(depth_val, low_depth_this_branch)
  while(le(depth_val, high_depth_this_branch)) {
     set(stored_pos, get_high_pos_gen(depth_val))
     call set_high_pos_gen(depth_val,
         add(stored_pos, div(mul(sub(nbranches, 1), shift), nbranches)))
     incr(depth_val)
  }
*/
}


/*
** procedure: max_with_high_pos_gen
**
** handles the updating of the highest position (down) on the page
** in a particular generation and over all generations
*/

proc max_with_high_pos_gen(depth, pos) {
  /* update the highest position array, or set it for the first time */
  set(prev_high, get_high_pos_gen(depth))
  call set_high_pos_gen(depth, max(pos, prev_high))
}

/*
** functions: calc_high_pos_text & calc_high_pos_line
**
** Determines maximum of all entries in
** high_pos_gen array and llist_high list, respectively.
**
*/

/* RES!!!
   Really need to search over  plist_pos -- but we need pos+extent
   which means plist_extent will need to be created
   (that will help with accurate knowledge of highest element anyway)
*/
func calc_high_pos_text() {
  set(high_pos_text, get_high_pos_gen(low_depth))
  set(depth_val, low_depth)
  while(le(depth_val, high_depth)) {
    set(high_pos_text, max(high_pos_text, get_high_pos_gen(depth_val)))
    incr(depth_val)
  }
  return(high_pos_text)
}

func calc_high_pos_line() {
  set(high_pos_line, getel(llist_high, 1))
  forlist(llist_high, x, pc) {
    set(high_pos_line, max(high_pos_line, x))
  }
  return(high_pos_line)
}

/*
** functions: calc_low_pos_text & calc_low_pos_line
**
** Determines minimum of all entries in
** plist_pos array and llist_low list, respectively.
**
*/

func calc_low_pos_text() {
  set(low_pos_text, get_high_pos_gen(low_depth))
  forlist(plist_pos, x, pc) {
    set(low_pos_text, min(low_pos_text, x))
  }
  return(low_pos_text)
}

func calc_low_pos_line() {
  set(low_pos_line, getel(llist_low, 1))
  forlist(llist_low, x, pc) {
    set(low_pos_line, min(low_pos_line, x))
  }
  return(low_pos_line)
}

/*
** function: get_clearance
**
** handles the determination of a minimum position down the chart
** necessary for a person to stay clear of others already on the chart
**
*/

func get_clearance(depth, min_pos) {
   set(next_depth, sub(depth, 1))
   set(prev_depth, add(depth, 1))

   set(new_min_pos, min_pos)
   if(high, get_high_pos_gen(prev_depth)) {
      if(not(cloak_check(prev_depth))) {
         set(new_min_pos, max(add(high, branch_dist_prev), new_min_pos))
      }
   }
   if(high, get_high_pos_gen(depth)) {
      set(new_min_pos, max(add(high, branch_dist_same), new_min_pos))
   }
   if(high, get_high_pos_gen(next_depth)) {
      if(not(cloak_check(next_depth))) {
         set(new_min_pos, max(add(high, branch_dist_next), new_min_pos))
      }
   }
   list(cloaked_depth)
   return(new_min_pos)
}

/*
** procedure cloak
**
** To be called just before a main charting procedure.
** Enables temporary hidding of a generation from get_clearance()
** so that generations closer to the root don't interfere with placement of
** branches in adjacent generations, such as with placement of maternal
** ancestor branches.
*/

proc cloak(depth) {
  push(cloaked_depth, depth)
}

/*
** function not_cloaked
**
** Checks whether a generation has been hidden from get_clearance...
**    if not then TRUE is returned,
**    if yes then FALSE is returned and the hidden status is cleared.
*/

func not_cloaked(depth) {
  if(inlist(cloaked_depth, depth)) {
    list(cloaked_depth)
    return(FALSE)
  } else {
    return(TRUE)
  }
}

/*
** function cloak_check
**
** Returns true or false depending on whether a depth is the cloaked_depth.
*/

func cloak_check(depth) {
  return(inlist(cloaked_depth, depth))
}

/*
** procedure: set_high_pos_gen
**     &
** function:  get_high_pos_gen
**
** They simplify access to the high_pos_gen list.
** LifeLines lists are indexed from 1.  In order to allow generation
** (depth) numbers to span an arbitrary range of integers, it is necessary
** to translate the depth range to one that has a minimum value of 1.
** The global variable high_pos_gen_offset is the amount necessary
** to translate the depths.
**
*/

proc set_high_pos_gen(depth, pos) {
   if(and(ge(depth, min_depth), le(depth, max_depth))) {
      set(low_depth, min(low_depth, depth))
      set(high_depth, max(high_depth, depth))
      /* not using max(pos, get_high_pos_gen(depth)) because *
       * branch_adjust() might need to decrease these numbers */
      setel(high_pos_gen, add(depth, high_pos_gen_offset), pos)
   } else {
      print(" ! Attempt to access array out of bounds: set_high_pos_gen()\n")
      print("   position: ", d(pos), "      depth: ", d(depth), nl())
   }
}

func get_high_pos_gen(depth) {
  if(and(ge(depth, low_depth), le(depth, high_depth))) {
    set(ans, getel(high_pos_gen, add(depth, high_pos_gen_offset)))
  } else {
    set(ans, 0)
  }
  return(ans)
}

/*
**  function: person_height2
**
**  Return the height of a single person's information.
**  All lines of information on a person that print_person() may issue
**  should be accounted for here.
**  The name is assumed to be in the database.  So this height will always
**  be at least name_height.  The dates are checked for in the person's record.
**
**  A TRUE (non-zero) value for the second parameter along with a non-zero
**  marriage date (third parameter) will result in
**  an extra date_height being added to the person's height corresponding
**  to the assumed intention of including the marriage date when the
**  associated enqueue_person() call is made.
**  It is thus the responsibility of the calling code to determine when to
**  use a marriage date.
*/

func person_height2(person, use_mdate, mdate) {
  /* determine height of person and put in global var person_height_return */
  set(num_info_lines, 0)
  set(person_height_return, name_height)
  if(show_altname) {
    if(altname, name2(person)) {
      incr(num_info_lines)
    }
  }
  if(dateplace(birth(person), dateplace_birth)) {
    incr(num_info_lines)
  }
  if(and(use_mdate, mdate)) {
    incr(num_info_lines)
  }
  if(dateplace(death(person), dateplace_death)) {
    incr(num_info_lines)
  }
  if(dateplace(burial(person), dateplace_burial)) {
    incr(num_info_lines)
  }
  set(num_info_lines, add(num_info_lines, address_ps(person, FALSE)) )
  set(person_height_return, add(person_height_return,
                                 mul(num_info_lines, date_height)) )
  return(person_height_return)
}

/*
**  function: dateplace
**
**  Get the date of an event in the appropriate style (which may include
**  the place).  Comments below describe the date styles.
**
*/

func dateplace(ev, style) {
  if(or( eq(ev, 0), eq(style, 0) )) {
    set(dateplace_return, 0)
  }
  /* 1 - use only the date value */
  if(eq(style, 1)) {
    set(dateplace_return, save(date(ev)))
  }

  /* 2 - use only the year and/or LAST place component (no modification) */
  if(eq(style, 2)) {
    set(dateplace_return, save(short(ev)))
  }

  /* 3 - use VERBATIM values from date and place (no modification) */
  if(eq(style, 3)) {
    set(dateplace_return, save(long(ev)))
  }

  /* 4 - date value and the FIRST component of the place */
  if(eq(style, 4)) {
    if(long(ev)) {
      if(place(ev)) {
        list(pl)
        extractplaces(ev, pl, np)
        set(where, modify(dequeue(pl)))
        if(eqstr(date(ev), "")) {
          set(dateplace_return, save(where))
        } else {
          set(dateplace_return, save(concat(date(ev), ", ", where)))
        }
      } else {
        set(dateplace_return, save(date(ev)))
      }
    } else {
      set(dateplace_return, 0)
    }
  }

  /* 5 - date value and the FIRST TWO components of the place */
  if(eq(style, 5)) {
    if(long(ev)) {
      if(place(ev)) {
        list(pl)
        extractplaces(ev, pl, np)
        if(eq(1, np)) {
          set(where, modify(dequeue(pl)))
        } else {
          set(where, concat(modify(dequeue(pl)), ", ", modify(dequeue(pl))))
        }
        if(eqstr(date(ev), "")) {
          set(dateplace_return, save(where))
        } else {
          set(dateplace_return, save(concat(date(ev), ", ", where)))
        }
      } else {
        set(dateplace_return, save(date(ev)))
      }
    } else {
        set(dateplace_return, 0)
    }
  }

  /* 6 - date value and the first THREE components of the place */
  if(eq(style, 6)) {
    if(long(ev)) {
      if(place(ev)) {
        list(pl)
        extractplaces(ev, pl, np)
        if(eq(1, np)) {
          set(where, modify(dequeue(pl)))
        } elsif(eq(2, np)) {
          set(where, concat(modify(dequeue(pl)), ", ", modify(dequeue(pl))))
  } else {
    set(where, concat(
        modify(dequeue(pl)), ", ",
        modify(dequeue(pl)), ", ",
        modify(dequeue(pl)) ))
        }
        if(eqstr(date(ev), "")) {
          set(dateplace_return, save(where))
        } else {
          set(dateplace_return, save(concat(date(ev), ", ", where)))
        }
      } else {
        set(dateplace_return, save(date(ev)))
      }
    } else {
        set(dateplace_return, 0)
    }
  }
  /* 7 - For US places, in the format "city, county, state, country"
     where any one component implies that all less specific ones are present,
     this style will choose, when available, the country,
     state, county and state, or city and state
     If enabled, place modification (abbreviation) is applied to the
     country (when the only place item) or
     the state (when NOT the only place item).
  */
  if(eq(style, 7)) {
    if(long(ev)) {
      if(place(ev)) {
        list(pl)
        extractplaces(ev, pl, np)
        if(eq(1, np)) {
           set(where, modify(getel(pl,1)))
        } elsif(eq(np, 2)) {
          set(where, getel(pl, 1))
        } elsif(eq(np, 3)) {
          set(where,concat(getel(pl, 1), ", ", modify(getel(pl, 2))))
        } elsif(ge(np, 4)) {
          set(where, concat(getel(pl, sub(np, 3)), ", " ,
              modify(getel(pl, sub(np, 1)))))
        } 
        if(eqstr(date(ev), "")) {
          set(dateplace_return, save(where))
        } else {
          set(dateplace_return, save(concat(year(ev), ", ", where)))
        }
      } else {
        set(dateplace_return, save(year(ev)))
      }
    } else {
        set(dateplace_return, 0)
    }
  }
  if(ge(style, 7)) {
    set(dateplace_return, 0)
    print(" error: invalid date style code", nl())
  }
  return(dateplace_return)
}

/*
**  function: address_ps
**
**  Prints address info as PostScript strings, if the print_flag is non-zero.
**  Returns a count of the number of info lines whether or not info is printed.
**
**  Finds last address or residence of PERSON by traversing
**  all ADDR (GEDCOM 5.5),
**  and RESI (GEDCOM 5.5)
**  nodes.
**  Here are some examples:
**      1 ADDR 122 Oak Street
**        2 CONT Somewhere, MO 55555
**      1 PHON 501-555-1212
**      1 EMAI itsme@sofa.net
** or
**      1 RESI
**        2 ADDR 122 Oak Street
**          3 CONT Somewhere, MO 55555
**        2 DATE from 23 Dec 1996
**
**  Phone and e-mail information is printed as well.
**
*/

func address_ps(person, print_flag) {
  set(lines_return, 0)
  if(not(and(person, show_address))) {
    return(lines_return)
  }
  list(addrlist)
  set(addrnode, FALSE)
  set(found_addr, FALSE)
  traverse(inode(person), node, lev) {
    if(eq(lev, 1)) {
      if(eqstr(tag(node),"ADDR")) {
        set(addrnode, node)
        set(found_addr, TRUE)
      } elsif(and( eqstr(tag(node),"RESI"), not(no_resides_at),
                   not(found_addr) )) {
        set(addrnode, node)
      }
    }
  }
  if(addrnode) {
    if(eqstr(tag(addrnode), "RESI")) {
      set(addrflag, "* ")
      set(newnode, 0)
      traverse(addrnode, node, lev) {
        if(and( eq(parent(node), addrnode), or(eqstr(tag(node), "ADDR"),
          eqstr(tag(node), "PLAC") ))) {
          set(newnode, node)
        }
      }
      if(newnode) {
        set(addrnode, newnode)
      } else {
        print("RESI node with no ADDR subnode, for ", name(person), nl())
      }
    } else {
      set(addrflag, "! ")
    }
    if(gt(strlen(place(addrnode)), 23)) {
      if(debug) {
        print(" caught a long place node, for ", name(person), nl())
      }
      extractplaces(addrnode, addrlist, np)
      /* RES - might be better to do this with a stack, to handle more than 2 */
      set(line1, 0)
      set(line1, modify(dequeue(addrlist)))
      set(line2, 0)
      if(not(empty(addrlist))) {
        set(line2, concat(line2, modify(dequeue(addrlist))))
      }
      while(not(empty(addrlist))) {
        set(line2, concat(line2, " ", modify(dequeue(addrlist))))
      }
      if(print_flag) {
        "(" addrflag strxlat(ps_xlat, line1) ")"
        "(" addrflag strxlat(ps_xlat, line2) ")"
      }
      set(lines_return, 2)
    } elsif(gt(strlen(place(addrnode)), 0)) {
      print(" caught an empty place/addr node, for ", name(person), nl())
      if(print_flag) {
        "(" addrflag strxlat(ps_xlat, place(addrnode)) ")"
      }
      set(lines_return, 1)
    } else {
      set(line1, 0)
      set(line1, modify(value(addrnode)))
      if(not(line1)) {
        print("ADDR node with no address info with tag, for ", name(person),
          nl())
        set(lines_return, 0)
      } else {
        if(print_flag) {
          "(" addrflag strxlat(ps_xlat, line1) ")"
        }
        set(lines_return, 1)
        traverse(addrnode, subnode, lev) {
          if(and(eq(parent(subnode), addrnode), eqstr(tag(subnode), "CONT") )) {
            set(line2, modify(value(subnode)))
            if(print_flag) {
              "(" addrflag strxlat(ps_xlat, line2) ")"
            }
            incr(lines_return)
          }
        }
      } 
    }
  }
  traverse(inode(person), subnode, lev) {
    if(or( eqstr(tag(subnode), "EMAI"), eqstr(tag(subnode), "PHON") )) {
      incr(lines_return)
      if(print_flag) {
        "(" "! " strxlat(ps_xlat, value(subnode)) ")"
      }
    }
    if(eqstr(tag(subnode), "PLACE")) {
      print("5-letter subnode tag: PLACE, for ", name(person), nl())
    }
    if(eqstr(tag(subnode), "EMAIL")) {
      print("5-letter subnode tag: EMAIL, for ", name(person), nl())
    }
  }
  return(lines_return)
}

/*
**  function: name2
**
**  Returns the name from the second NAME node, or a 0 (FALSE) if none.
**  This function attempts to format the name as is done to other names
**  elsewhere in the program.  The difficulty lies in LifeLines having
**  name formatting commands that only that work only with the first NAME
**  node of a person, and not on NAME nodes or strings.
*/

func name2(ind) {
  if(not(ind)) {
    return(0)
  }
  set(altnamenode, 0)
  set(found_one, FALSE)
  traverse(inode(ind), node, lev) {
    if(eq(lev, 1)) {
      if(eqstr(tag(node), "NAME")) {
        if(not(found_one)) {
          set(found_one, TRUE)
        } else {
          set(altnamenode, node)
          break()
        }
      }
    }
  }
  if(altnamenode) {
    list(parts)
    extractnames(altnamenode, parts, np, sni)
    set(altname, "")
    forlist(parts, nstr, si) {
      if(and(ge(si, sni), surname_upper)) {
        set(altname, concat(altname, upper(nstr), " "))
      } else {
        set(altname, concat(altname, nstr, " "))
      }
    }
    set(altname, trim(altname, sub(strlen(altname), 1)))
  } else {
    set(altname, 0)
  }
  return(altname)
}


/*
**  function: modify
**
**  Use a function (shorten), possibly accessed via an "include" statement
**  prior to the main() procedure code block.
**  The purpose of which is to modify place strings.
**  If the global variable 'place_modify' is set to FALSE, then place strings
**  will be returned unaltered.                       keyword: SHORTEN
**
*/

func modify(old) {
  if(and(strlen(old), place_modify)) {
    if(index(old, ",", 1)) {   /* is this a string with commas? */
      list(pl)
      extracttokens(old, pl, np, ",")
      set(new, "")
      if(gt(length(pl), 0)) {
        set(new, shorten(dequeue(pl)))
        while(gt(length(pl), 0)) {
          set(new, concat(new, ", ", shorten(dequeue(pl))))
        }
      }
    } else {
      set(new, shorten(old))
    }
  } else {
    set(new, old)
  }
  if(debug) { print("modify: ", old, " -> ", new, nl())}
  return(new)
}

/*
**  function: strxlat
**
**  If there is a chance that text containing unbalanced parentheses may
**  be written to a PostScript file as a string (which is delimited with
**  parentheses) then at least the lone parentheses must be escaped, meaning
**  preceeded by a '\' character.  The appearance of '\' characters in such
**  strings must also be escaped.
**  This function returns a string with all parentheses and
**  backslash characters escaped.
**  This idea was copied and/or adapted from Jim Eggert's modification
**  to the ps-circ(le) program for LifeLines.
**  A typical call would look like:
**      set(str, strxlat(ps_xlat, name(person)))
**  which would translate characters in person's name according to the
**  table called ps_xlat.  The output is assigned to str.
**  The output of strxlat() can also be sent directly to output.
*/

func strxlat(xlat, string) {
  if(opt_xlat) {
    set(fixstring, "")
    set(pos, 1)
    while(le(pos, strlen(string))) {
      set(char, substring(string, pos, pos))
      if (special, lookup(xlat, char)) {
        set(fixstring, concat(fixstring, special))
      } else {
        set(fixstring, concat(fixstring, char))
      }
      incr(pos)
    }
  } else {
    set(fixstring, string)
  }
  return(save(fixstring))  /* save() is used for compatibilty with older LL */
}

/*
**  function: deparen
**
**  Removes parenthesized text from a string and returns the result.
**  This routine can handle nesting of parentheses and multiple occurences
**  of parenthesized text in the same string.
*/

func deparen(str) {
  if(and(opt_deparen, index(str, ")", 1), nestr(str, ""))) {
    list(maybe)
    set(level, 0)
    while(len, strlen(str)) {
      set(s, substring(str, 1, 1))
      set(str, substring(str, 2, len))
      if(eqstr(s, ")")) {
        if(gt(level, 0)) {
          set(d, pop(maybe))
          while(nestr(d, "(")) {
            set(d, pop(maybe))
          }
          if(d, pop(maybe)) {
            if(nestr(d, " ")) {
              push(maybe, d)
            }
          } elsif(eqstr(" ", substring(str, 1, 1))) {
            set(str, substring(str, 2, len))
          }
          decr(level)
        } else {
          push(maybe, s)
        }
      } elsif(eqstr(s, "(")) {
        push(maybe, s)
        incr(level)
      } else {
        push(maybe, s)
      }
    }
    while(s, dequeue(maybe)) {
      set(str, concat(str, s))
    }
  }
  return(str)
}


/*
**  procedures: enqueue_person
**
**  Store the data for a person in the global lists.  It will be
**  printed later.
**
**  Some variable meanings:
**    line   2 = bold line, for direct anc/des
**           1 = thin line, for non-direct, blood relatives
**                                             (aunts and uncles, cousins)
**           0 = thin line in second color, for non-blood relatives
**    rel_up   = 1 if person is connected to the next level up, 0 otherwise
**    rel_down = 1 if person is connected to the next level down, 0 otherwise
**         fam = parents, if chart flow is down through this person
**               0, otherwise
**               The purpose is to check the type of connection to parents
**               and set line style accordingly.
*/

proc enqueue_person(person, depth, pos, rel, mdate, rel_up, rel_down, fam) {
  set(line, rel_famc(person, fam, rel))
  set(duplicate, blocked(person, depth))
  if(not(duplicate)) {
    call reserve(person, start_depth)
  }
  set(height, person_height2(person, mdate, mdate))

  enqueue(plist_person, person)
  enqueue(plist_depth,  depth)
  enqueue(plist_pos,    pos)
  enqueue(plist_line,   line)
  enqueue(plist_mdate,  mdate)
  enqueue(plist_up,     rel_up)
  enqueue(plist_down,   rel_down)
  enqueue(plist_duplic, duplicate)
  enqueue(plist_height, height)

  set(duplicate_return, duplicate)
}

/*
** procedure: initialize_data
**
**  Empty the lists that hold chart data.
**  This clears the way for a second pass for the more complex charts.
**
*/

proc initialize_data() {
  list(branch_start_person)
  list(branch_start_line)
  list(original_person)
  list(original_depth)
  list(high_pos_gen)

  list(plist_person)
  list(plist_depth)
  list(plist_pos)
  list(plist_line)
  list(plist_mdate)
  list(plist_up)
  list(plist_down)
  list(plist_duplic)
  list(plist_height)

  list(llist_depth)
  list(llist_low)
  list(llist_high)
  list(cloaked_depth)
  list(llist_color)
  list(llist_duplic)

  set(low_depth, start_depth)
  set(high_depth, start_depth)
}

/*
**  procedure: print_all_persons
**
**  Print all persons stored in the global lists.
*/

proc print_all_persons() {
  while(length(plist_person)) {
    set(person,  dequeue(plist_person))
    set(depth,  dequeue(plist_depth))
    set(pos,    dequeue(plist_pos))
    set(line,   dequeue(plist_line))
    set(mdate,   dequeue(plist_mdate))
    set(rel_up,   dequeue(plist_up))
    set(rel_down, dequeue(plist_down))                                     
    set(duplic,   dequeue(plist_duplic))
    call print_person(person, depth, pos, line, mdate, rel_up, rel_down, duplic)
  }
}


/*
**  procedure: print_person
**
**  Print a line of data for a person in PostScript format.  Each line
**  printed is essentially a call to a PostScript function defined in the
**  header.
**
*/

proc print_person(person, depth, pos, rel, mdate, rel_up, rel_down, duplicate) {
  /* specify an index for storage in PostScript array*/
  d(length(plist_person)) " {"

  /* print generation */
  d(depth) " "

  /* print vertical position */
  make_thousandths(pos) " "

  /* 2=direct ancestor, 1=blood relative, 0=non-blood relative */
  d(rel) " "
  if(or(lt(rel, 0), lt(2, rel))) {
    print(" >> print_person() caught invalid relationship code for ",
      name(person), nl())
  }

  /* duplicate individual */
  if(duplicate) { "1 " } else { "0 " }

  /* person has ancestors (descendants, if mirror_chart)*/
  if(rel_up) { "1 " } else { "0 " }

  /* person has descendants (ancestors, if mirror_chart)*/
  if(rel_down) { "1 " } else { "0 " }

  set(t, title(person))
  if(eqstr(t, "")) {
    set(t, 0)
  }
  if(person) {
    if(or(t, eq(title_method, 0))) {
      set(prefix_title, 0)
      set(suffix_title, 0)
    }
    if(eq(title_method, 1)) {
      set(prefix_title, t)
      set(suffix_title, 0)
    }
    if(eq(title_method, 2)) {
      set(prefix_title, 0)
      set(suffix_title, t)
    }
    if(eq(title_method, 3)) {
      set(prefix_title, 0)
      set(suffix_title, 0)
      if(is_prefix_title(t)) {
        set(prefix_title, t)
      } else {
        set(suffix_title, t)
      }
    }

    set(nlet, name_letters)
    if(prefix_title) {
      set(nlet, sub(nlet, add(strlen(prefix_title), 1)))
    }
    if(suffix_title) {
      set(nlet, sub(nlet, add(strlen(suffix_title), 1)))
    }
  }

  /* print name and title */
  "("
  if(not(person)) {
    "                           "
  } else {
    if(prefix_title) {
      prefix_title " "
    }
    strxlat(ps_xlat, deparen(fullname(person, surname_upper, 1, nlet)))
    if(suffix_title) {
      " " suffix_title
    }
  }
  ")"

  /* print info: birth, death, etc. */
  " ["
  if(person) {
    if(show_altname) {
      if(altname, name2(person)) {
        "(" strxlat(ps_xlat, altname) ")"
      }
    }
    if(date_birth, dateplace(birth(person), dateplace_birth)) {
      "(b. " strxlat(ps_xlat, date_birth) ")"
    }

    /* print marriage date, if it exists */
    if(mdate) {
      "(m. " strxlat(ps_xlat, mdate) ")"
    }

    /* print death date, if it exists */
    if(date_death, dateplace(death(person), dateplace_death)) {
      "(d. " strxlat(ps_xlat, date_death) ")"
    }

    /* print burial date/place, if it exists */
    if(date_burial, dateplace(burial(person), dateplace_burial)) {
      "(bur. " strxlat(ps_xlat, date_burial) ")"
    }

    /* print last known address or living address */
    set(dummy, address_ps(person, TRUE))
  }

  "]"         /* end of info array */

  " ("         /* drop in a complimentary indi. key -- to aid in debugging */
  if(person) {
    key(person, 1)
  } else {
    "-"
  }
  ")"

  /* call PostScript function to process and print this data */
  "} Q"

  nl()
}

/*
**  function: is_prefix_title
**
**  Decide if the given title is a prefix type title.
**
*/

func is_prefix_title(t) {
  set(is_prefix_title_return, 0)
  if( index(t, "Arch",   1))  { set( is_prefix_title_return, 1) }
  if( index(t, "Baron",  1))  { set( is_prefix_title_return, 1) }
  if( index(t, "Bish", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Brot", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Card", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Colonel", 1)) { set( is_prefix_title_return, 1) }
  if( index(t, "Canon", 1))   { set( is_prefix_title_return, 1) }
  if( index(t, "Cong", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Deacon", 1))  { set( is_prefix_title_return, 1) }
  if( index(t, "Dr", 1))      { set( is_prefix_title_return, 1) }
  if( index(t, "Duke", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Father", 1))  { set( is_prefix_title_return, 1) }
  if( index(t, "Fr", 1))      { set( is_prefix_title_return, 1) }
  if( index(t, "Hon", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Judge", 1))   { set( is_prefix_title_return, 1) }
  if( index(t, "King", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Lady", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Lord", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Miss", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Mons", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Mr", 1))      { set( is_prefix_title_return, 1) }
  if( index(t, "Mrs", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Ms", 1))      { set( is_prefix_title_return, 1) }
  if( index(t, "Msgr", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Pope", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Pres", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Princ", 1))   { set( is_prefix_title_return, 1) }
  if( index(t, "Prof", 1))    { set( is_prefix_title_return, 1) }
  if( index(t, "Queen", 1))   { set( is_prefix_title_return, 1) }
  if( index(t, "Rabbi", 1))   { set( is_prefix_title_return, 1) }
  if( index(t, "Rav", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Rep", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Sen", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Sir", 1))     { set( is_prefix_title_return, 1) }
  if( index(t, "Sis", 1))     { set( is_prefix_title_return, 1) }
  return(is_prefix_title_return)
}

/*
**  procedures: enqueue_vertical
**
**  Enqueue the data for a single vertical line onto the global lists.
**
*/

proc enqueue_vertical(depth, low, high, color, duplicate) {
  enqueue(llist_depth,  depth)
  enqueue(llist_low,    low)
  enqueue(llist_high,   high)
  enqueue(llist_color,  color)
  enqueue(llist_duplic, duplicate)
}

/*
**  procedure: print_all_verticals
**
**  Dequeue and print all vertical lines.  The lines are stored in a
**  second queue as they are printed and then placed back in the
**  original, global, queue.
**
*/

proc print_all_verticals() {
  while(length(llist_depth)) {
    set(depth,  dequeue(llist_depth))
    set(low,    dequeue(llist_low))
    set(high,   dequeue(llist_high))
    set(color,  dequeue(llist_color))
    set(duplic, dequeue(llist_duplic))

    d(length(llist_depth))
    " {" d(depth)
    " " make_thousandths(low)
    " " make_thousandths(high)
    " " d(color)
    " " d(duplic)
    "} P" nl()
  }
}

/*
**  function: make_thousandths
**
**  Since LifeLines does not have a floating point type, decimal
**  computation is done using integers that represent thousands.  This
**  procedure converts a number in thousandths to decimal notation as a string.
**  The result always has three decimal places.
*/

func make_thousandths(n) {
  set(s, "")
  if(lt(n, 0)) {
    set(s, "-")
    set(n, neg(n))
  }
  set(s, concat(s, d(div(n, 1000)), "."))
  set(t, d(mod(n, 1000)))
  if(eq(strlen(t), 1)) {
    set(s, concat(s, "00", t))
  }
  if(eq(strlen(t), 2)) {
    set(s, concat(s, "0", t))
  }
  if(eq(strlen(t), 3)) {
    set(s, concat(s, t))
  }
  return(s)
}

/*
**  function: direction
**
**  applies global option: updown_override to direction (UP or DOWN)
**  and returns a direction.  This allows for statements like
**  set(dir, direction(UP)) that are simpler than the actual formula used.
*/

func direction(updown) {
  return(mod(add(updown, updown_override), 2))
}

/*
**  functions: min and max; half
**
**  min() and max() return the minimum and maximum of a pair of integers
**
**  half() returns the integer part of dividing its argument by 2.
*/

func min(x, y) {
  if(le(x, y)) {
    set(ans, x)
  } else {
    set(ans, y)
  }
  return(ans)
}

func max(x, y) {
  if(ge(x, y)) {
    set(ans, x)
  } else {
    set(ans, y)
  }
  return(ans)
}

func half(x) {
  return(div(x, 2))
}

/*
**  function: abs
**
**  Return the absolute value of an integer
*/

func abs(x) {
  if(lt(x, 0)) {
    set(ans, neg(x))
  } else {
    set(ans, x)
  }
  return(ans)
}

/*
**  function: chart_title
**
**  Return a string containing a standard chart title based
**  on chart type and possibly generation restrictions.
*/

func chart_title() {
  set(title_return, "")
  if(nestr(chart_title_override, "")) {
    set(title_return, chart_title_override)
  } else {
    if(eq(chart_type, 1)) {
      set(title_return, concat("The ancestors of ",
        name(root_person, surname_upper),
        fromto(root_person) ))
    } elsif(or( eq(chart_type, 2), eq(chart_type, 3) )) {
      set(title_return, concat("The descendants of ",
        name(root_person, surname_upper),
        fromto(root_person) ))
    } elsif(eq(chart_type, 4)) {
      if(eq(low_depth, start_depth)) {
        set(title_return, "The ancestors of the ")
      } else {
        set(title_return, "The ancestors and descendants of the ")
      }
      set(title_return, concat(title_return,
        name(husband(root_fam), surname_upper), " and ",
        name(wife(root_fam), surname_upper), " family" ))
    } elsif(eq(chart_type, 5)) {
      if(eq(low_depth, start_depth)) {
        set(title_return, "The ancestors of the extended family of " )
      } else {
        set(title_return,
          "The ancestors and descendants of the extended family of " )
      }
      set(title_return, concat(title_return,
        name(husband(root_fam), surname_upper), " and ",
        name(wife(root_fam), surname_upper) ))
    } else {
      set(title_return, concat("<<Set chart title with",
        " 'chart_title_override' or set 'display_title' to 0 to disable.>>" ))
    }
  }
  return(title_return)
}

/*
**  function: fromto
**
**  Return a string reprsenting the time when a person lived.
*/

func fromto(indi) {
  set(e, birth(indi))
  set(f, death(indi))
  set(s, "")
  if(or(year(e), year(f))) {
    /* balanced parenthesis are OK unescaped in PostScript strings */
    set(s, concat(s, " ("))
    if(e) {
      if(year(e)) {
        set(s, concat(s, year(e)))
      } else {
        set(s, concat(s, "?"))
      }
    }
    set(s, concat(s, "-"))
    if(f) {
      if(year(f)) {
        set(s, concat(s, year(f)))
      } else {
        set(s, concat(s, "?"))
      }
    }
    set(s, concat(s, ")"))
  }
  return(save(s))
}

/*
**  procedure: write_ps
**
**  Generate the PostScript code.  Defines PostScript
**  functions for printing peoples names, dates and the lines on the
**  chart, and more.  Then the actual names and lines with their positions
**  and other data are inserted as array definitions in the PostScript code.
**  Maybe some day, other output procedures will be written, like write_pdf?
**
**  Arguments:
**    cl:  chart label, string
**    fn:  font name for an individual's name
**    fi:  font name for an individual's info (birth, death, marriage, etc.)
**    xn:  number of horizontal pages
**    yn:  number of vertical pages
**    ml:  maximum level, integer
**    nl:  minimum level, integer
**
**    Not all arguments are passed, because there are so many.
**
**  The original PostScript code was written by Thomas P. Blumer
**  (blumer@ptltd.com).
**
*/

proc write_ps(fn, fi, xn, yn, ml, nl) {
  "%!PS-Adobe-3.0" if(eqstr(paper_name, "EPSF")) {" EPSF-3.0"} nl()
  "%%Title: " chart_title() nl()
  "%%CreationDate: " stddate(gettoday()) nl()
  "%%Creator: " version
      ", a report program for LifeLines" nl()
  "%%Pages: " d(mul(xn, yn)) nl()
  "%%PageOrder: Ascend" nl()
  if(nestr(paper_name, "NONE")) {
    "%%BoundingBox: 0 0 " d(paper_width) " " d(paper_height) nl()
  }
  "%%Orientation: "
    if(portrait) {
      "Portrait"
    } else {
      "Landscape"
    }
    nl()
  "%%EndComments" nl()
  "%%BeginDefaults" nl()
  "%%ViewingOrientation: " if(portrait) {"1 0 0 1"} else {"0 -1 1 0"} nl()
  "%%EndDefaults" nl()
  "%%BeginProlog" nl()
  "% --- Define constants ---" nl()
  "% ** This first section of constants are "
          "user-modifiable here in the PS file **" nl()
  "/fontname /" fn " def" nl()
  "/ifontname /" fi " def" nl()
  "/titlefontname fontname def" nl()
  "/labelfontname /Helvetica def" nl()
  "/chart_title (" strxlat(ps_xlat, chart_title()) ") def" nl()
  "/display_title " if(display_title) {"true"} else {"false"} " def" nl()
  "/chart_label (" strxlat(ps_xlat, chart_label) ") def" nl()
  "/display_label " if(display_label) {"true"} else {"false"} " def" nl()
  "/chart_label_centered "
      if(chart_label_centered) {"true"} else {"false"} " def" nl()
  "/label_outside_border "
      if(label_outside) {"true"} else {"false"} " def" nl()
  "/show_border " if(display_border) {"true"} else {"false"} " def" nl()
  "/mirror " if(mirror_chart) { "true" } else { "false" } " def" nl()
  "/portrait " if(portrait) { "true" } else { "false" } " def" nl()
  "/margin_top " d(margin_top) " def" nl()
  "/margin_bottom " d(margin_bottom) " def" nl()
  "/margin_left " d(margin_left) " def" nl()
  "/margin_right " d(margin_right) " def" nl()
  "% indent is the fraction of generation width to allow for horizontal lines"
  nl()
  "/indent .05 def" nl()
  "/use_color " if(color_chart) { "true" } else { "false" } " def" nl()
  "/use_bold " if(bold_chart) { "true" } else { "false" } " def" nl()
  "/bold_factor " make_thousandths(mul(bold_factor, 1000)) " def" nl()
  "/tweak 0 def    % points to shift chart vertically within border" nl()
  "% Red,Green,Blue intensities for lines and text (regular and bold)" nl()
  "%   Values may have decimals and must be between 0 and 1." nl()
  "/lr 0 def /lg 1 def /lb 1 def" nl()
  "/Lr 0 def /Lg 0 def /Lb 1 def" nl()
  "/tr 0 def /tg 0 def /tb 0 def" nl()
  "/Tr 0 def /Tg 0 def /Tb 0 def" nl()
  if(debug_postscript) {
    "/show_positions false def    % make true to show person positions" nl()
  }
  "/show_keys false def     % set to true to turn on display of keys" nl()
  "% ** End of user-modifiable constants **" nl()
  if(nestr(paper_name, "NONE")) {
    "/paper_height " d(paper_height) " def" nl()
    "/paper_width " d(paper_width) " def" nl()
  }
  "/name_height " make_thousandths(name_height) " def" nl()
  "/date_height " make_thousandths(date_height) " def" nl()
  "/xpages " d(xn) " def" nl()
  "/ypages " d(yn) " def" nl()
  "/minpos_text " make_thousandths(calc_low_pos_text()) " def" nl()
  "/minpos_line " make_thousandths(calc_low_pos_line()) " def" nl()
  "/maxpos_text " make_thousandths(calc_high_pos_text()) " def" nl()
  "/maxpos_line " make_thousandths(calc_high_pos_line()) " def" nl()
  "/maxlevel " d(ml) " def" nl()
  "/minlevel " d(nl) " def" nl()
  "% --- Start Subroutines ---" nl()
  "% emulations of Level 2 operators" nl()
  "%" nl()
  "/*SF {                 % Complete selectfont emulation" nl()
  "  exch findfont exch" nl()
  "  dup type /arraytype eq {makefont}{scalefont} ifelse setfont" nl()
  "} bind def" nl()
  nl()
  "/BuildRectPath {" nl()
  "  dup type dup /integertype eq exch /realtype eq or {" nl()
  "    4 -2 roll moveto" nl()
  "    dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto closepath" nl()
  "  }{" nl()
  "    dup length 4 sub 0 exch 4 exch" nl()
  "    {" nl()
  "      1 index exch 4 getinterval aload pop" nl()
  "      BuildRectPath" nl()
  "    } for" nl()
  "    pop" nl()
  "  } ifelse" nl()
  "} bind def" nl()
  nl()
  "/*RC {" nl()
  "  gsave newpath BuildRectPath clip grestore" nl()
  "} bind def" nl()
  nl()
  "% install Level 2 emulations, or substitute built-in Level 2 operators" nl()
  "/languagelevel where" nl()
  "  {pop languagelevel}{1} ifelse" nl()
  "2 lt {" nl()
  "  /RC /*RC load def" nl()
  "  /SF /*SF load def" nl()
  "}{" nl()
  "  /RC /rectclip load def      % use RC instead of rectclip" nl()
  "  /SF /selectfont load def    % use SF instead of selectfont" nl()
  "} ifelse" nl()
  "/SF2 {SF" nl()
  "  /fshow fshowdict currentfont /FontName get get load def" nl()
  "} bind def" nl()
  nl()
  "% Handy little functions: min, max" nl()
  "/min {" nl()
  "  2 copy gt { exch } if pop" nl()
  "} bind def" nl()
  "/max {" nl()
  "  2 copy lt { exch } if pop" nl()
  "} bind def" nl()
  nl()
  "% Line and Person array filling procedures" nl()
  "/P {Alin 3 1 roll put} def" nl()
  "/Q {Aind 3 1 roll put} def" nl()
  nl()
  "/black-and-white-device     % true for black & white, false otherwise" nl()
  "{    statusdict begin" nl() 
  "     /processcolors where" nl()
  "     { pop processcolors } { 1 } ifelse" nl()
  "     end" nl()
  "     1 eq" nl()
  "} def" nl()
  nl()
  "% wshow* usage:  string num  wshow*  --" nl()
  "% scale to fit string in specified width at current point" nl()
  "/wshow* {" nl()
  "  /s exch def" nl()
  "  /len exch def" nl()
  "  s stringwidth pop line_gap add dup len lt {" nl()
  "    pop s fshow" nl()
  "  }{" nl()
  "    gsave" nl()
  "    % scale for exact fit (current point is not affected)" nl()
  "    len exch div dup scale" nl()
  "    s fshow" nl()
  "    grestore" nl()
  "  } ifelse" nl()
  "} bind def" nl()
  nl()
  "% wlen usage:  string num1 num2  wlen  num3 num4" nl()
  "% The string is to be rendered no longer than specified length (num1)," nl()
  "% starting with initial font size (num2)." nl()
  "% Determines scale (num3) necessary to render string with length (num4)" nl()
  "% Assumes 'direct' variable is currently set to indicate use of bold font."
  nl()
  "/wlen {" nl()
  "     /s exch def" nl()
  "     /len exch def" nl()
  "     /fntsiz exch def" nl()
  "     /bfn exch def" nl()
  "     /fn exch def" nl()
  "     use_bold direct and {" nl()
  "        bfn fntsiz SF2" nl()
  "     } {" nl()
  "        fn fntsiz SF2" nl()
  "     } ifelse" nl()
  "     s stringwidth pop line_gap add dup len lt {" nl()
  "        % text already fits so return scale of 1 and text length" nl()
  "        1 exch" nl()
  "     } {" nl()
  "        % scale, len for text length since scale makes fit exact" nl()
  "        len exch div len" nl()
  "     } ifelse" nl()
  "} bind def" nl()
  nl()
  "%" nl()
  "% Show text from right to left, with left end at current point" nl()
  "%" nl()
  "/rlshow {" nl()
  "  dup stringwidth rmoveto" nl()
  "  { (_) dup 0 4 -1 roll put" nl()
  "    dup stringwidth pop neg 0 rmoveto" nl()
  "    currentpoint 3 -1 roll show" nl()
  "    moveto" nl()
  "  } forall" nl()
  "} bind def" nl()
  nl()
  "%" nl()
  "% Print a title across the bottom of the page" nl()
  "%" nl()
  "/print_title {" nl()
  "  /fsize th1 18 div def" nl()
  "  /len tw1 .9 mul def" nl()
  "  titlefontname fsize SF2" nl()
  "  chart_title stringwidth pop dup len lt {" nl()
  "    pop" nl()
  "  } {" nl()
  "    % compute new font size for exact fit lengthwise" nl()
  "    len exch div fsize mul /fsize exch def" nl()
  "    titlefontname fsize SF2" nl()
  "  } ifelse" nl()
  "  titlefontname findfont /FontBBox get dup" nl()
  "  3 get /sy2 exch fsize mul 1000 div def" nl()
  "  1 get /sy1 exch fsize mul 1000 div def" nl()
  "  sy2 0 eq {" nl()
  "    newpath 0 0 moveto" nl()
  "    (A) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop" nl()
  "    newpath 0 0 moveto" nl()
  "    (p) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop" nl()
  "  } if" nl()
  "  /title_length chart_title stringwidth pop def" nl()
  "  /title_height sy2 sy1 sub def" nl()
  "  /title_allowance title_height 1.1 mul def" nl()
  "  /startx tw1 title_length sub 2 div def" nl()
  "  /starty sy1 neg title_height .05 mul add def" nl()
  "  startx starty chart_title stringwidth pop" nl()
  "  startx starty moveto" nl()
  "  textcolr0" nl()
  "  chart_title fshow" nl()
  "  0 title_allowance translate       % set origin above title" nl()
  "  /th1 th1 title_allowance sub def  % shorten chart space accordingly" nl()
  "} bind def" nl()
  nl()
  "/print_label {" nl()
  "  /labelfs 6 def" nl()
  "  /len wp1 def" nl()
  "  labelfontname labelfs SF2" nl()
  "  chart_label stringwidth pop dup len lt {pop} {" nl()
  "    len exch div labelfs mul /labelfs exch def" nl()
  "    labelfontname labelfs SF2" nl()
  "  } ifelse" nl()
  "  labelfontname findfont /FontBBox get dup" nl()
  "  3 get /sy2 exch labelfs mul 1000 div def" nl()
  "  1 get /sy1 exch labelfs mul 1000 div def" nl()
  "  sy2 0 eq {" nl()
  "    newpath 0 0 moveto" nl()
  "    (A) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop" nl()
  "    newpath 0 0 moveto" nl()
  "    (p) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop   " nl()
  "  } if" nl()
  "  chart_label_centered" nl()
  "    {len chart_label stringwidth pop sub 2 div}" nl()
  "    {0} ifelse" nl()
  "  0 sy1 neg moveto" nl()
  "  chart_label fshow" nl()
  "  sy2 sy1 sub 1.2 mul dup" nl()
  "  0 exch translate" nl()
  "  th1 exch sub /th1 exch def" nl()
  "} bind def" nl()
  nl()

  /* To write an alternative PostScript border procedure,
     here are the current guidelines for compatibility:
     - external PostScript variables used in the original border procedure:
        lincolr0 -- a procedure that sets the drawing color to the one used
                    for blood relatives
        tw1      -- the width, in points, available
        th1      -- the height, in points, available
        wp1      -- the width, in points, available on the lower left page
     - what the border procedure must do when finished:
        1. translate to just inside the lower left corner of the border
        2. subtract border thickness from /tw1, /th1, and /wp1
        3. set /bgap to the empty space at the bottom on the inside of
           the border -- some of which is used as extra space for a title
           or inside label
  */
  "% Print a decorative border" nl()
  "%" nl()
  "/print_border {" nl()
  "  /bwid1 2.5 def" nl()
  "  /gapwid 1.5 def" nl()
  "  /bwid2 0.7 def" nl()
  "  /bgap 10 def" nl()
  "  /tbwid bwid1 gapwid bwid2 bgap add add add def" nl()
  "  /tw 7.2 def" nl()
  "  /rect {" nl()
  "    /rh exch def" nl()
  "    /rw exch def" nl()
  "    moveto" nl()
  "    rw 0 rlineto" nl()
  "    0 rh rlineto" nl()
  "    rw neg 0 rlineto" nl()
  "    closepath stroke" nl()
  "  } def" nl()
  "  /rectt {" nl()
  "    /rh exch def" nl()
  "    /rw exch def" nl()
  "    /rhs rh tw sub tw sub def" nl()
  "    /rws rw tw sub tw sub def" nl()
  "    moveto" nl()
  "    0 tw rmoveto" nl()
  "    tw 0 rlineto" nl()
  "    0 tw neg rlineto" nl()
  "    rws 0 rlineto" nl()
  "    0 tw rlineto" nl()
  "    tw 0 rlineto" nl()
  "    0 rhs rlineto" nl()
  "    tw neg 0 rlineto" nl()
  "    0 tw rlineto" nl()
  "    rws neg 0 rlineto" nl()
  "    0 tw neg rlineto" nl()
  "    tw neg 0 rlineto" nl()
  "    closepath stroke" nl()
  "  } def" nl()
  nl()
  /* assuming that 2*(border thickness) < (chart width) */
  "  2 setlinecap" nl()
  "  0 setlinejoin" nl()
  "  bwid1 setlinewidth" nl()
  "  lincolr0" nl()
  "  bwid1 2 div  dup  tw1 bwid1 sub  th1 bwid1 sub  rectt" nl()
  "  bwid2 setlinewidth" nl()
  "  bwid1 gapwid bwid2 2 div add add  dup" nl()
  "  tw1 bwid1 2 mul sub gapwid 2 mul sub bwid2 sub " nl()
  "  th1 bwid1 2 mul sub gapwid 2 mul sub bwid2 sub rect" nl()
  "  %  move the chart origin inside the border zone" nl()
  "  tbwid tbwid translate" nl()
  "  % take border thickness away from chart area" nl()
  "  /th1 th1 tbwid 2 mul sub def" nl()
  "  /tw1 tw1 tbwid 2 mul sub def" nl()
  "  /wp1 wp1 tbwid xpages 1 eq {2 mul} if sub def" nl()
  "} bind def" nl()
  nl()

  "% calculate max. font sizes and scale factor for placement of chart elements" nl()
  "% depends on: th1, tw1" nl()
  "% determines: posunit, minpos, rl, fntsize, fntsize2, linwid, dashwid," nl()
  "%       char2line, line2char, line_gap, name_adjust, name_extra, len1" nl()
  "/calcScale {" nl()
  "  % for now, overestimate the upwards name_adjust with name_height" nl()
  "  /minpos minpos_text name_height sub minpos_line min def" nl()
  "  /maxpos maxpos_text maxpos_line max def" nl()
  "  /posunit th1 maxpos minpos sub div def" nl()
  nl()
  "  % Now we have the remaining height and width, compute" nl()
  "  % the column width, font size etc." nl()
  "  %" nl()
  "  /rl tw1 maxlevel minlevel sub 1 add div def" nl()
  nl()
  "  % calculate base font size from segment length" nl()
  "  /fntsize rl 9.0 div def" nl()
  nl()
  /* RES: make so two solid marks of dashed line appear on indent length */
  "  /dashwid rl indent mul 3 div def" nl()
  nl()
  "  % size of name text, layout relies on a restricted font size" nl()
  "  fntsize name_height posunit mul gt {" nl()
  "     /fntsize name_height posunit mul def" nl()
  "  } if" nl()
  nl()
  "  % find out how low below baseline any of the letters can reach" nl()
  "  fontname findfont /FontBBox get dup" nl()
  "  3 get /sy2 exch fntsize mul 1000 div def" nl()
  "  1 get /sy1 exch fntsize mul 1000 div def" nl()
  "  sy2 0 eq {" nl()
  "    newpath 0 0 moveto" nl()
  "    (A) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop" nl()
  "    newpath 0 0 moveto" nl()
  "    (p) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop   " nl()
  "  } if" nl()
  "  /name_desc sy1 neg def" nl()
  nl()
  "  % font for birth/death dates" nl()
  "  /fntsize2 fntsize date_height mul def" nl()
  nl()
  "  % find out how low below baseline any of the letters can reach" nl()
  "  ifontname findfont /FontBBox get dup" nl()
  "  3 get /sy2 exch fntsize2 mul 1000 div def" nl()
  "  1 get /sy1 exch fntsize2 mul 1000 div def" nl()
  "  sy2 0 eq {" nl()
  "    newpath 0 0 moveto" nl()
  "    (A) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop" nl()
  "    newpath 0 0 moveto" nl()
  "    (p) false charpath flattenpath pathbbox newpath" nl()
  "    sy2 max /sy2 exch def pop sy1 min /sy1 exch def pop   " nl()
  "  } if" nl()
  "  /info_desc sy1 neg def" nl()
  "  /info_asc sy2 def" nl()
  nl()
  "  % calc line width from font size" nl()
  "  /linwid fntsize .06 mul def" nl()
  nl()
  "  % name_adjust -- adjustment to 'center' names on horiz. lines." nl()
  "  %               it's the distance from baseline to middle of '-'." nl()
  "  % char2line & line2char -- indicate offsets to horiz. line ends" nl()
  "  % relative to char origins matching behavior of minus char. as a line" nl()
  "  boldfontname fntsize SF2" nl()
  "  newpath 0 0 moveto" nl()
  "  (-) false charpath flattenpath pathbbox newpath" nl()
  "    exch /minus_end exch def add 2 div /name_adjust exch def" nl()
  "    /char2line exch def" nl()
  "  (-) stringwidth pop minus_end sub /line2char exch def" nl()
  "  /line_gap char2line line2char add def" nl()
  nl()
  "  % this is the highest a name can extend above its horiz. line (pos)" nl()
  "  /name_extra sy2 name_adjust sub def" nl()
  nl()
  "  % name string length for all generations" nl()
  "  /len1 rl 1 indent 2 mul sub mul def" nl()
  "} def" nl()
  nl()
  "% Draw a vertical line" nl()
  "%" nl()
  "/l {" nl()
  "    /duplic exch 1 eq def" nl()
  "    dup /direct exch 2 eq def" nl()
  "    /blood exch 1 ge def" nl()
  "    /parent exch def" nl()
  "    /pos exch def" nl()
  "    /level exch def" nl()
  nl()
  "    mirror {" nl()
  "        /x maxlevel level sub rl mul def" nl()
  "    } {" nl()
  "        /x level minlevel sub 1 add rl mul def" nl()
  "    } ifelse" nl()
  "    /y1 top pos minpos sub posunit mul sub def" nl()
  "    /y2 top parent minpos sub posunit mul sub def" nl()
  "    blood {lincolr0}{lincolr1} ifelse" nl()
  "    duplic {[dashwid] 0 setdash}{[] 0 setdash} ifelse" nl()
  "    use_bold direct and {" nl()
  "        linwid bold_factor mul setlinewidth" nl()
  "    } {" nl()
  "        linwid setlinewidth" nl()
  "    } ifelse" nl()
  "    0 setlinecap" nl()
  "    % 2 setlinecap affects dashes, so have to extend line ends manually" nl()
  "    x y1 currentlinewidth 2 div add moveto" nl()
  "    x y2 currentlinewidth 2 div sub lineto stroke" nl()
  "} bind def" nl()
  nl()
  "%" nl()
  "% Print a person" nl()
  "% called once for each individual on chart" nl()
  "%" nl()
  "/i {" nl()
  "   /key exch def           % database key, make show_keys true to show" nl()
  "   /info exch def          % array of info strings: birth, death, etc." nl()
  "   /name exch def" nl()
  "   /rel_down exch 1 eq def % true if person connects to next level down" nl()
  "   /rel_up exch 1 eq def   % true if person connects to next level up" nl()
  "   /duplic exch 1 eq def   % true for duplicate individual" nl()
  "   dup                     % copy line-type for two uses" nl() 
  "   /direct exch 2 eq def   % true for direct ancestor, false for indirect"
  nl()
  "   /blood exch 1 ge def    % true for blood relatives" nl()
  "   /pos exch def           % vertical position" nl()
  "   /level exch def         % generation level, 0 = youngest" nl()
  nl()
  "   mirror {  % smallest gen. # on the right" nl()
  "      /rel_left rel_up def" nl()
  "      /rel_right rel_down def" nl()
  "      /x1 maxlevel level sub rl mul def" nl()
  "   } {  % smallest gen. # on the left" nl()
  "      /rel_left rel_down def" nl()
  "      /rel_right rel_up def" nl()
  "      /x1 level minlevel sub rl mul def" nl()
  "   } ifelse" nl()
  "   /x2 x1 rl add def" nl()
  nl()
  "   % x1=left edge, x=start of text, x2=right edge" nl()
  nl()
  "   /ylin top pos minpos sub posunit mul sub def" nl()
  nl()
  "   % Calculate the printed length of the name" nl()
  "   fontname boldfontname fntsize len1 name wlen" nl()
  "   /lname exch def /scalefactor exch def" nl()
  nl()
  "   % use relative change in fontsize determined by wlen to scale name_adjust"
  nl()
  "   % then determine the baseline position relative to the horizontal line"
  nl()
  "   /y ylin name_adjust scalefactor mul sub def" nl()
  nl()
  "   % Find the size of the longest text string" nl()
  "   /ls lname def" nl()
  "   /infoscale 1 def" nl()
  "   info {" nl()
  "     dup length 0 gt" nl()
  "     {ifontname boldifontname fntsize2 len1 5 4 roll wlen" nl()
  "       dup ls gt {/ls exch def}{pop}ifelse" nl()
  "       dup infoscale lt {/infoscale exch def}{pop}ifelse" nl()
  "     }{pop" nl()
  "     }ifelse" nl()
  "   }forall" nl()
  nl()
  "   direct rel_left rel_right and or {" nl()
  "      % center record within generation" nl()
  "      /x x1 rl ls line_gap scalefactor mul add sub 2 div add def" nl()
  "   }{" nl()
  "      rel_right {/x x2 rl indent mul sub ls sub def} if" nl()
  "      rel_left {/x x1 rl indent mul add def} if" nl()
  "   } ifelse" nl()
  "   /xlin x def" nl()
  "   /x xlin line2char scalefactor mul add def" nl()
  nl()
  "   use_bold direct and {" nl()
  "      boldfontname fntsize SF2" nl()
  "      linwid bold_factor mul setlinewidth" nl()
  "   } {" nl()
  "      fontname fntsize SF2" nl()
  "      linwid setlinewidth" nl()
  "   } ifelse" nl()
  nl()
  "   blood {lincolr0}{lincolr1} ifelse" nl()
  "   duplic {[dashwid] 0 setdash}{[] 0 setdash} ifelse" nl()
  "   0 setlinecap   % don't cap lines -- stay clear of name characters" nl()
  nl()
  "   rel_left {" nl()
  "      x1 ylin moveto xlin ylin lineto stroke" nl()
  "   } if" nl()
  "   rel_right {" nl()
  "      x lname add char2line scalefactor mul add ylin moveto" nl()
  "      x2 ylin lineto stroke" nl()
  "   } if" nl()
  nl()
  "   % print name" nl()
  "   direct use_bold and {textcolr0}{textcolr1} ifelse"  nl()
  "   x y moveto" nl()
  "   len1 name wshow*" nl()
  "   % drop down by height of name font descenders" nl()
  "   /y y name_desc sub def" nl()
  "   % drop down by height of small text above its baseline + small font gap" nl()
  "   /y y info_asc infoscale mul sub def" nl()
  nl()
  "  use_bold direct and {" nl()
        /* RES - alternative is to pass infoscale to wshow* */
        /* that would avoid danger of generating too many fonts in PS engine */
  "     boldifontname fntsize2 infoscale mul SF2" nl()
  "  }{" nl()
  "     ifontname fntsize2 infoscale mul SF2" nl()
  "  } ifelse" nl()
  nl()
  "  % print info: birth, death, etc." nl()
  "  info" nl()
  "  { dup length 0 gt" nl()
  "    { x y moveto" nl()
  "      len1 exch wshow*" nl()
  "      /y y fntsize2 sub def" nl()
  "    }{pop" nl()
  "    }ifelse" nl()
  "  }forall" nl()
  if(debug_postscript) {
    nl()
    "  show_positions {     % not for use with show_keys simultaneously" nl()
    "    pos abs floor 1 ge {" nl()
    "      pos abs log cvi" nl()
    "    }{1}ifelse" nl()
    "    pos 0 lt {1 add} if" nl()
    "    5 add string /tmp exch def" nl()
    "    pos tmp cvs" nl()
    "    x y moveto" nl()
    "    len1 tmp wshow*" nl()
    "  }if" nl()
  }
  "  show_keys {" nl()
  "    x y moveto" nl()
  "    len1 key wshow*" nl()
  "  }if" nl()
  "} bind def" nl()
  nl()

  "% If colour is required, set the appropriate fields" nl()
  "%   and define colour setting procedures accordingly." nl()
  "% Note: setcmykcolor is a PostScript Level 2 operator." nl()
  "%" nl()
  "use_color black-and-white-device not and {" nl()
  "  /setcmykcolor where { pop" nl()
  "    Tr Tg Tb add add 0 eq {" nl()
  "      /Tk 1 def" nl()
  "    } {" nl()
  "      /Tk 0 def" nl()
  "      /Tr 1 Tr sub def /Tg 1 Tg sub def /Tb 1 Tb sub def" nl()
  "    } ifelse" nl()
  nl()
  "    tr tg tb add add 0 eq {" nl()
  "      /tk 1 def" nl()
  "    } {" nl()
  "      /tk 0 def" nl()
  "      /tr 1 tr sub def /tg 1 tg sub def /tb 1 tb sub def" nl()
  "    } ifelse" nl()
  nl()
  "    Lr Lg Lb add add 0 eq {" nl()
  "      /Lk 1 def" nl()
  "    } {" nl()
  "      /Lk 0 def" nl()
  "      /Lr 1 Lr sub def /Lg 1 Lg sub def /Lb 1 Lb sub def" nl()
  "    } ifelse" nl()
  nl()
  "    lr lg lb add add 0 eq {" nl()
  "      /lk 1 def" nl()
  "    } {" nl()
  "      /lk 0 def" nl()
  "      /lr 1 lr sub def /lg 1 lg sub def /lb 1 lb sub def" nl()
  "    } ifelse" nl()
  nl()
  "    /textcolr0 {Tr Tg Tb Tk setcmykcolor} bind def % direct names" nl()
  "    /textcolr1 {tr tg tb tk setcmykcolor} bind def % indirect names" nl()
  "    /lincolr0 {Lr Lg Lb Lk setcmykcolor} bind def  % direct lines" nl()
  "    /lincolr1 {lr lg lb lk setcmykcolor} bind def  % indirect lines" nl()
  "  } {" nl()
  "    /textcolr0 {Tr Tg Tb setrgbcolor} bind def % direct names" nl()
  "    /textcolr1 {tr tg tb setrgbcolor} bind def % indirect names" nl()
  "    /lincolr0 {Lr Lg Lb setrgbcolor} bind def  % direct lines" nl()
  "    /lincolr1 {lr lg lb setrgbcolor} bind def  % indirect lines" nl()
  "  } ifelse" nl()
  "} {" nl()
  "  /textcolr0 {} bind def" nl()
  "  /textcolr1 {} bind def" nl()
  "  /lincolr0 {} bind def" nl()
  "  /lincolr1 {} bind def" nl()
  "} ifelse" nl()
  nl()

  "% page printing procedure" nl()
  "/print-a-page {" nl()
  "  /ypage exch def" nl()
  "  /xpage exch def" nl()
  "  /th1 th0 def" nl()
  "  /tw1 tw0 def" nl()
  "  /wp1 wp def" nl()
  "  % adjust for portrait or landscape" nl()
  "  % move origin so that desired page lands on the clip rectangle" nl()
  "  gsave     % so we can undo portrait/landscape adjustments" nl()
  nl()
  "  portrait {" nl()
  "    % portrait mode" nl()
  "    llx lly translate" nl()
  "  }{" nl()
  "    llx ury translate -90 rotate" nl()
  "  } ifelse" nl()
  nl()
  "  % specify (rectangular) clipping path to keep the margins clean" nl()
  "  0 0 wp hp RC" nl()
  nl()
  "  % move origin so that desired portion of chart lands within clipping path"
    nl()
  "  xpage wp mul neg ypage hp mul neg translate" nl()
  nl()
  "  label_outside_border {" nl()
  "    display_label {print_label} if" nl()
  "    show_border {print_border} if" nl()
  "    display_title {" nl()
  "      show_border {" nl()
  "        % let the title or inside label get in closer to the border" nl()
  "        0 bgap .9 mul neg translate /th1 th1 bgap .9 mul add def" nl()
  "        } if" nl()
  "      print_title" nl()
  "    } if" nl()
  "  }{" nl()
  "    show_border {print_border} if" nl()
  "    display_label display_title or {" nl()
  "      % let the title or inside label get in closer to the border" nl()
  "      0 bgap .9 mul neg translate /th1 th1 bgap .9 mul add def" nl()
  "      display_label {print_label} if" nl()
  "      display_title {print_title} if" nl()
  "    } if" nl()
  "  } ifelse" nl()
  nl()

  "  calcScale  % figure font size and scale factor to make chart fit" nl()
  nl()

  "  % chart starts this high on the page from chart origin.  Allow for" nl()
  "  % the first name to extend above the 0 position." nl()
  "  /top th1 tweak add def" nl()
  nl()

  "  % print all lines and person info" nl()
  "  Aind {exec i} forall" nl()
  "  Alin {exec l} forall" nl()
  nl()
  "  grestore" nl()
  nl()
  "} def      % print-a-page procedure" nl()
  "% --- End of Subroutines ---" nl()
  "%%EndProlog" nl()
  "%%BeginSetUp" nl()
  if(and( nestr(paper_name, "NONE"), nestr(paper_name, "EPSF") )) {
    if(manual_feed_opt) {
      "%%BeginFeature: *ManualFeed "
      if(eq(manual_feed_opt, 1)) {"True"} else {"False"} nl()
      "/languagelevel where {pop languagelevel 2 ge}{false} ifelse" nl()
      "  {1 dict dup /ManualFeed "
      if(eq(manual_feed_opt, 1)) {"true"} else {"false"}
      " put setpagedevice" nl()
      "  }{statusdict /manualfeed "
      if(eq(manual_feed_opt, 1)) {"true"} else {"false"}
      " put}" nl()
      "ifelse" nl()
      "%%EndFeature" nl()
    }
    "%%BeginFeature: "
      if(eq(manual_feed_opt, 1)) {"*PageRegion "} else {"*PageSize "}
      if(eq(postscript_level, 1)) {
        lower(paper_name)
      } else {
        paper_name
      }
      nl()
      "/languagelevel where {pop languagelevel 2 ge}{false} ifelse" nl()
      " {1 dict" nl()
      "  dup /Policies 2 dict dup /PageSize 2 put dup /MediaType 0 put put" nl()
      "  setpagedevice" nl()
      "  2 dict" nl()
      "  dup /PageSize [" d(paper_width) " " d(paper_height) "] put" nl()
      "  dup /ImagingBBox null put" nl()
      "  setpagedevice" nl()
      " }{ " lower(paper_name) nl()
      " } ifelse" nl()
    "%%EndFeature" nl()
  }
  nl()
  if(ne(enc_choice, 0)) {
    "/encvecmod* {  % on stack should be /Encoding and an encoding array" nl()
    "  % make an array copy so we don't try to modify the original via pointer"
      nl()
    "  dup length array copy" nl()
    "  encvecmod aload length dup 2 idiv exch 2 add -1 roll exch" nl()
    "  {dup 4 2 roll put}" nl()
    "  repeat" nl()
    "} def" nl()
    "/reenc {" nl()
    "   findfont" nl()
    "   dup length dict begin" nl()
    "      {1 index /FID eq {pop pop} {" nl()
    "         1 index /Encoding eq {" nl()
    "               encvecmod* def" nl()
    "            }{def} ifelse" nl()
    "         } ifelse" nl()
    "      } forall" nl()
    "      currentdict" nl()
    "   end" nl()
    "   definefont pop" nl()
    "} def" nl()
  }
  if(eq(enc_choice, 1)) {
    "% Adjust the font so that it is iso-8859-1 compatible" nl()
    "/languagelevel where" nl()
    "   {pop languagelevel}{1} ifelse" nl()
    "2 ge {" nl()
    "    % Use built-in ISOLatin1Encoding if PS interpreter is Level 2" nl()
    "    /encvecmod* {pop ISOLatin1Encoding} def" nl()
    "}{" nl()
    /* This array indicates changes to go from the Standard Encoding Vector
       to the ISOLatin1 Encoding Vector for ISO-8859-1 compatibility,
       according to the PostScript Language Reference Manual, 2nd ed.
       The characters from A0 to FF are essential for 8859-1 conformance.
    */
    "   /encvecmod [" nl()
"16#90 /dotlessi   16#91 /grave        16#92 /acute      16#93 /circumflex" nl()
"16#94 /tilde      16#95 /macron       16#96 /breve      16#97 /dotaccent" nl()
"16#98 /dieresis   16#99 /.notdef      16#9a /ring       16#9b /cedilla" nl()
"16#9c /.notdef    16#9d /hungarumlaut 16#9e /ogonek     16#9f /caron" nl()
"16#a0 /space      16#a1 /exclamdown   16#a2 /cent       16#a3 /sterling" nl()
"16#a4 /currency   16#a5 /yen         16#a6 /brokenbar   16#a7 /section" nl()
"16#a8 /dieresis   16#a9 /copyright   16#aa /ordfeminine 16#ab /guillemotleft"
  nl()
"16#ac /logicalnot 16#ad /hyphen      16#ae /registered  16#af /macron" nl()
"16#b0 /degree     16#b1 /plusminus   16#b2 /twosuperior 16#b3 /threesuperior"
  nl()
"16#b4 /acute      16#b5 /mu          16#b6 /paragraph    16#b7 /periodcentered"
  nl()
"16#b8 /cedilla    16#b9 /onesuperior 16#ba /ordmasculine 16#bb /guillemotright"
  nl()
"16#bc /onequarter 16#bd /onehalf    16#be /threequarters 16#bf /questiondown"
  nl()
"16#c0 /Agrave      16#c1 /Aacute    16#c2 /Acircumflex 16#c3 /Atilde" nl()
"16#c4 /Adieresis   16#c5 /Aring     16#c6 /AE          16#c7 /Ccedilla" nl()
"16#c8 /Egrave      16#c9 /Eacute    16#ca /Ecircumflex 16#cb /Edieresis" nl()
"16#cc /Igrave      16#cd /Iacute    16#ce /Icircumflex 16#cf /Idieresis" nl()
"16#d0 /Eth         16#d1 /Ntilde    16#d2 /Ograve      16#d3 /Oacute" nl()
"16#d4 /Ocircumflex 16#d5 /Otilde    16#d6 /Odieresis   16#d7 /multiply" nl()
"16#d8 /Oslash      16#d9 /Ugrave    16#da /Uacute      16#db /Ucircumflex" nl()
"16#dc /Udieresis   16#dd /Yacute    16#de /Thorn       16#df /germandbls" nl()
"16#e0 /agrave      16#e1 /aacute    16#e2 /acircumflex 16#e3 /atilde" nl()
"16#e4 /adieresis   16#e5 /aring     16#e6 /ae          16#e7 /ccedilla" nl()
"16#e8 /egrave      16#e9 /eacute    16#ea /ecircumflex 16#eb /edieresis" nl()
"16#ec /igrave      16#ed /iacute    16#ee /icircumflex 16#ef /idieresis" nl()
"16#f0 /eth         16#f1 /ntilde    16#f2 /ograve      16#f3 /oacute" nl()
"16#f4 /ocircumflex 16#f5 /otilde    16#f6 /odieresis   16#f7 /divide" nl()
"16#f8 /oslash      16#f9 /ugrave    16#fa /uacute      16#fb /ucircumflex" nl()
"16#fc /udieresis   16#fd /yacute    16#fe /thorn       16#ff /ydieresis" nl()
    "  ] def" nl()
    "} ifelse" nl()
    nl()
  } elsif(eq(enc_choice, 2)) {
    /* The following array specifies changes to make to a font encoding
       to make characters A0 through FF match the ISO Latin alphabet no. 2
       This will work as long as there are instructions in the font for
       drawing the glyphs named here.  Missing glyphs would be 
       substituted with /.notdef from the font by the PostScript interpreter.
    */
    "/encvecmod [" nl()
    "16#a0 /space     16#a1 /Aogonek 16#a2 /breve     16#a3 /Lslash" nl()
    "16#a4 /currency  16#a5 /Lcaron  16#a6 /Sacute    16#a7 /section" nl()
    "16#a8 /dieresis  16#a9 /Scaron  16#aa /Scedilla  16#ab /Tcaron" nl()
    "16#ac /Zacute    16#ad /hyphen  16#ae /Zcaron    16#af /Zdotaccent" nl()
    "16#b0 /degree    16#b1 /aogonek 16#b2 /ogonek    16#b3 /lslash" nl()
    "16#b4 /acute     16#b5 /lcaron  16#b6 /sacute    16#b7 /caron" nl()
    "16#b8 /cedilla   16#b9 /scaron  16#ba /scedilla  16#bb /tcaron" nl()
    "16#bc /zacute    16#bd /hungarumlaut 16#be /zcaron 16#bf /zdotaccent" nl()
    "16#c0 /Racute    16#c1 /Aacute  16#c2 /Acircumflex 16#c3 /Abreve" nl()
    "16#c4 /Adieresis 16#c5 /Lacute  16#c6 /Cacute    16#c7 /Ccedilla" nl()
    "16#c8 /Ccaron    16#c9 /Eacute  16#ca /Eogonek   16#cb /Edieresis" nl()
    "16#cc /Ecaron    16#cd /Iacute  16#ce /Icircumflex 16#cf /Dcaron" nl()
    "16#d0 /Dcroat    16#d1 /Nacute   16#d2 /Ncaron    16#d3 /Oacute" nl()
    "16#d4 /Ocircumflex 16#d5 /Ohungarumlaut 16#d6 /Odieresis 16#d7 /multiply"
      nl()
    "16#d8 /Rcaron    16#d9 /Uring   16#da /Uacute    16#db /Uhungarumlaut" nl()
    "16#dc /Udieresis 16#dd /Yacute  16#de /Tcommaaccent 16#df /germandbls" nl()
    "16#e0 /racute    16#e1 /aacute  16#e2 /acircumflex 16#e3 /abreve" nl()
    "16#e4 /adieresis 16#e5 /lacute  16#e6 /cacute    16#e7 /ccedilla" nl()
    "16#e8 /ccaron    16#e9 /eacute  16#ea /eogonek   16#eb /edieresis" nl()
    "16#ec /ecaron    16#ed /iacute  16#ee /icircumflex 16#ef /dcaron" nl()
    "16#f0 /dcroat    16#f1 /nacute  16#f2 /ncaron     16#f3 /oacute" nl()
    "16#f4 /ocircumflex 16#f5 /ohungarumlaut 16#f6 /odieresis 16#f7 /divide"
      nl()
    "16#f8 /rcaron    16#f9 /uring   16#fa /uacute    16#fb /uhungarumlaut" nl()
    "16#fc /udieresis 16#fd /yacute  16#fe /tcommaaccent  16#ff /dotaccent" nl()
    "  ] def" nl()
    nl()
  } elsif(eq(enc_choice, 3)) {
    /* This array indicates changes necessary to go from the Standard Encoding
       Vector to one matching the int'l characters and some others in the
       IBM Extended Character Set (extended ASCII).
    */
    "/encvecmod [" nl()
"16#80 /Ccedilla    16#81 /udieresis 16#82 /eacute      16#83 /acircumflex" nl()
"16#84 /adieresis   16#85 /agrave    16#86 /aring       16#87 /ccedilla" nl()
"16#88 /ecircumflex 16#89 /edieresis 16#8a /egrave      16#8b /idieresis" nl()
"16#8c /icircumflex 16#8d /igrave    16#8e /Adieresis   16#8f /Aring" nl()
"16#90 /Eacute      16#91 /ae        16#92 /AE          16#93 /ocircumflex" nl()
"16#94 /odieresis   16#95 /ograve    16#96 /ucircumflex 16#97 /ugrave" nl()
"16#98 /ydieresis   16#99 /Odieresis 16#9a /Udieresis   16#9b /cent" nl()
"16#9c /sterling    16#9d /yen       16#9e /.notdef     16#9f /florin" nl()
"16#a0 /aacute      16#a1 /iacute    16#a2 /oacute      16#a3 /uacute" nl()
"16#a4 /ntilde      16#a5 /Ntilde    16#a6 /ordfeminine 16#a7 /ordmasculine"
nl()
"16#a8 /questiondown 16#a9 /.notdef  16#aa /.notdef     16#ab /onehalf" nl()
"16#ac /onequarter  16#ad /exclamdown 16#ae /guillemotleft "
                                                    "16#af /guillemotright" nl()
"16#e1 /germandbls  16#ed /oslash    16#f1 /plusminus   16#f6 /divide" nl()
"16#f8 /degree      16#f9 /bullet" nl()
    "  ] def" nl()
    nl()
  }

  "% Copyright (c) 1991-1993 Thomas P. Blumer.  All Rights Reserved." nl()
  "% Permission granted to use in LifeLines report generation." nl()
  "% table of how to get bold fonts" nl()
  "/bolddict 40 dict def" nl()  /* dictionary size might need boosting */
  "bolddict begin" nl()
  "  % default table entry is that boldfontname = fontname" nl()
  "  fontname fontname def" nl()
  "  ifontname ifontname def" nl()
  "  labelfontname labelfontname def" nl() 
                                /* ADD new bold font associations below here */
  "  /AvantGarde-Book /AvantGarde-Demi def" nl()
  "  /AvantGarde-BookOblique /AvantGarde-DemiOblique def" nl()
  "  /Bookman-Light /Bookman-Demi def" nl()
  "  /Bookman-LightItalic /Bookman-DemiItalic def" nl()
  "  /Courier /Courier-Bold def" nl()
  "  /Courier-Oblique /Courier-BoldOblique def" nl()
  "  /Times-Roman /Times-Bold def" nl()
  "  /Times-Italic /Times-BoldItalic def" nl()
  "  /Helvetica /Helvetica-Bold def" nl()
  "  /Helvetica-Condensed /Helvetica-Condensed-Bold def" nl()
  "  /Helvetica-Condensed-Oblique /Helvetica-Condensed-BoldObl def" nl()
  "  /Helvetica-Narrow /Helvetica-Narrow-Bold def" nl()
  "  /Helvetica-Narrow-Oblique /Helvetica-Narrow-BoldOblique def" nl()
  "  /Helvetica-Oblique /Helvetica-BoldOblique def" nl()
  "  /Hershey-Plain /Hershey-Plain-Bold def" nl()
  "  /NewCenturySchlbk-Roman /NewCenturySchlbk-Bold def" nl()
  "  /NewCenturySchlbk-Italic /NewCenturySchlbk-BoldItalic def" nl()
  "  /Palatino-Roman /Palatino-Bold def" nl()
  "  /Palatino-Italic /Palatino-BoldItalic def" nl()
  "  /ZapfChancery /ZapfChancery-Bold def" nl()
  "  /ZapfChancery-MediumItalic /ZapfChancery-Bold def" nl()
  "  /OmArabicRsimms /OmArabicRsimms-Bold def" nl()
  "end" nl()
  nl()
  "/boldfontname bolddict fontname get def" nl()
  "/boldifontname bolddict ifontname get def" nl()
  nl()
  "% The fshowdict is used to declare which PostScript proc to use" nl()
  "% to show strings.  For some Arabic and Hebrew fonts at least, the" nl()
  "% characters have positive widths, which makes the 'show' command" nl()
  "% place a character to the right of the prior one." nl()
  "% A special 'show' variant, 'rlshow,' compensates for this." nl()
  "% Record font names, both internal and those used to refer to a font." nl()
  "% A font's real FontName should be here when there's the possibility" nl()
  "%  of using aliases for that font -- like using ZapfChancery instead of" nl()
  "%  ZapfChancery-MediumItalic.  The font still thinks its name is the" nl()
  "%  latter." nl()
  "/fshowdict 25 dict def" nl()
  "fshowdict begin" nl()
  "  fontname /show def" nl()
  "  ifontname /show def" nl()
  "  boldfontname /show def" nl()
  "  boldifontname /show def" nl()
  "  labelfontname /show def" nl()
                           /* these two are typical substitution fonts */
  "  /Courier /show def" nl() 
  "  /Helvetica-Bold /show def" nl()
                           /* real font names, for which aliases may be used*/
  "  /ZapfChancery-MediumItalic /show def" nl()
                           /* ADD NEW rlshow associations below here */
  "  /Baghdad /rlshow def" nl()
  "  /Jerusalem /rlshow def" nl()
  "  /Jslm /rlshow def" nl()
  "  /OmArabicRsimms /rlshow def" nl()
  "  /OmArabicRsimms-Bold /rlshow def" nl()
  "  /OmegaSerifArabicOne /rlshow def" nl()
  "end" nl()
  nl()
  if(ne(enc_choice, 0)) {
    "/NewFont fontname reenc" nl()
    "/fontname /NewFont def" nl()
    nl()
    "/NewBoldFont boldfontname reenc" nl()
    "/boldfontname /NewBoldFont def" nl()
    nl()
    "/NewLabelFont labelfontname reenc" nl()
    "/labelfontname /NewLabelFont def" nl()
    nl()
    "/NewTitleFont titlefontname reenc" nl()
    "/titlefontname /NewTitleFont def" nl()
    nl()
    "/NewIFont ifontname reenc" nl()
    "/ifontname /NewIFont def" nl()
    nl()
    "/NewBoldIFont boldifontname reenc"
    "/boldifontname /NewBoldIFont def"
    "% end font reencoding" nl()
    nl()
  }

  "% Find printable dimension for chart with a sequence of steps" nl()
  nl()
  "% get printable area for each page" nl()
  "clippath pathbbox newpath" nl()
  "/ury exch def /urx exch def" nl()
  "/lly exch def /llx exch def" nl()
  nl()
  if(pacificpage) {
    "% adjust for PacificPage cartridge" nl()
    "statusdict /product known {" nl()
    "     statusdict begin product end (PacificPage) eq" nl()
    "     version (4.06) eq and {" nl()
    "             /lly lly 5 add def" nl()
    "             /ury ury 10 sub def" nl()
    "     } if" nl()
    "} if" nl()
    nl()
  }
  if(nestr(paper_name, "NONE")) {
    "% ensure minimum margins and that chart fits in defined paper size" nl()
    "llx margin_left lt {/llx margin_left def} if" nl()
    "lly margin_bottom lt {/lly margin_bottom def} if" nl()
    "paper_height margin_top sub dup ury lt {/ury exch def}{pop} ifelse" nl()
    "paper_width margin_right sub dup urx lt {/urx exch def}{pop} ifelse" nl()
    nl()
  } else { /* paper dimensions not specified, so take margins from print area */
    "/llx llx margin_left add def /lly lly margin_bottom add def" nl()
    "/urx urx margin_right sub def /ury ury margin_top sub def" nl()
    nl()
  }
  "% get available width and height for printing on a sheet of paper" nl()
  "/wp urx llx sub def" nl()
  "/hp ury lly sub def" nl()
  nl()
  "% adjust for portrait or landscape" nl()
  "portrait not {" nl()
  "   /tmp hp def" nl()
  "   /hp wp def" nl()
  "   /wp tmp def" nl()
  "} if" nl()
  nl()
  "% get width and height of the multi-page printable area" nl()
  "/tw0 wp xpages mul def" nl()
  "/th0 hp ypages mul def" nl()
  nl()
  "% store vertical lines and individual records in arrays" nl()
  "/Alin " d(length(llist_depth)) " array def" nl()
  "/Aind " d(length(plist_person)) " array def" nl()
  nl()
  call print_all_verticals()
  nl()
  call print_all_persons()
  "%%EndSetUp" nl()
  set(yi, sub(yn, 1))
  while(ge(yi, 0)) {
    set(yi_ord, sub(sub(yn, 1), yi))
    set(xi, 0)
    while(lt(xi, xn)) {
      set(page_num, add(mul(yi_ord, xn), xi, 1))
      "%%Page: " d(page_num) " " d(page_num) nl()
      if(nestr(paper_name, "NONE")) {
        "%%PageBoundingBox: 0 0 " d(paper_width) " " d(paper_height) nl()
      }
      d(xi) " " d(yi) " print-a-page" nl()
      "showpage" nl()
      set(xi, add(xi, 1))
    }
    set(yi, sub(yi, 1))
  }
  "%%EOF" nl()
}