File: msg.tcl

package info (click to toggle)
msort 8.53-2.2
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 2,360 kB
  • sloc: sh: 10,138; ansic: 10,031; makefile: 51
file content (10135 lines) | stat: -rwxr-xr-x 405,470 bytes parent folder | download | duplicates (3)
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
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh $0 $@
# Time-stamp: <2009-02-25 18:20:15 poser>
#
# Copyright (C) 2005-2009 William J. Poser (billposer@alum.mit.edu)
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 3 of the GNU General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# or go to the web page:  http://www.gnu.org/licenses/gpl.txt.

set Version "1.28";
set PackageVersion "8.53";
set DebugP 0;				# General debugging
#If you are running this under MS Windows without using cygwin, I am told that
#wish, the Tcl/Tk windowing shell, will not work properly. Try using tclsh.exe
#as the Tcl interpreter and uncomment the following line to import Tk.
#package require Tk
package require msgcat
package require Iwidgets

set UseCheckbuttonP 1;

proc dmsg {msg} {
    if {$::DebugP} {
	puts $msg;
	flush stdout;
    }
}

# Portability stuff

set KeySelHeight 1;
set KeySelWidth 10;
set InitFile  ".msgrc";

#Figure out what system we are running on
if {[string equal $tcl_platform(platform) windows]} {
    set System MSWindows;
    dmsg "Running under MS Windows";
} elseif {[string equal $tcl_platform(platform) unix]} {
    if {[string equal $tcl_platform(os) Darwin]} {
	set System MacOSX;
	dmsg "Running under Mac OS X";
    } else {
	set System Unix;
	dmsg "Running under Unix";
    }
}

#Find out what our base graphics system is
if {[string match X11*  [winfo server .]]} {
    set AquaP 0
    set WindowSystem X11
} else {
    if {[string match $System MSWindows]} {
	set AquaP 0;
	set WindowSystem MSWindows;
    }
    if {[string match $System MacOSX]} {
	set AquaP 1
	set WindowSystem Aqua
    }
}

#Find out if we are running in Tcl/Tk 8.5 or greater
#This matters because fonts are bigger in 8.5+ under Linux
set TkEightFivePlusOnX11P 0
set VLevelList [split [info patchlevel] "."]
set Major [lindex $VLevelList 0]
set Minor [lindex $VLevelList 1]
if {$WindowSystem eq "X11"} {
    if {$Major > 8} {
	set TkEightFivePlusOnX11P 1
    } else {
	if {($Major == 8) && ($Minor >= 5)} {
	    set TkEightFivePlusOnX11P 1
	}
    } 
}

if {[info exists ::env(TMP)]} {
    set TempDir $::env(TMP);
} elseif {[info exists ::env(TEMP)]} {
    set TempDir $::env(TEMP);
} else {
    if {[string equal $System MSWindows]} {
	set TempDir "C:\tmp";
    } else {
	set TempDir "/tmp";
    }
}

switch $System {
    Unix {
	event add <<B3>> <ButtonPress-3>
	event add <<B3Release>> <ButtonRelease-3>
    }
    MacOSX {
	event add <<B3>> <Control-ButtonPress-1>
	event add <<B3Release>> <Control-ButtonRelease-1>
	if {$AquaP} {
	    set KeySelHeight 2;
	    set KeySelWidth 10;
	}
    }
    MSWindows {
	event add <<B3>> <ButtonPress-3>
	event add <<B3Release>> <ButtonRelease-3>
	set InitFile    "Msgrc"
    }
}

proc _ {s} {return [::msgcat::mc $s]};	# Define shorthand for gettext


set BalloonHelpP 1;
set HPWidth 64;				# Width of help popups.
set HPLines 10;				# Number of lines for help popups.
set xcwidth 5;
set genfxpad 540
set grelief solid
set gborder 1
set LastCommandLineSaveTime 0;		# Time (in sec. since epoch) of last command line save.
set LastExecutionTime 0;		# Time (in sec. since epoch) of last msort execution.	
set SortInProgressP 0;
set SortAbortedP 0;
set SubdHeight 6;
set ReadInitFileP 1;
set CustomChartList "";
set FixedRecordLength 0;
set RecordParseDisplayedP 0;
set MiscOptionsDisplayedP 0;
set UnicodeDisplayedP 0;
set RandomNumberSeedDisplayedP 0;
set AlgorithmDisplayedP 0;
set InputFileDisplayedP 0;
set OutputFileDisplayedP 0;
set ExclusionsDisplayedP 0;
set KeyFieldIdentificationDisplayedP 0;
set MiscellaneousOptionsDisplayedP 0;
set SortOrderDisplayedP 0;
set SortTypeDisplayedP 0;
set SubstitutionsDisplayedP 0;
set UnicodeNormalization 0;

#set Opts(RandomSeed) ""
set Opts(RandomSeed) 17

set ColorSpecs(BalloonHelp,Background)		"\#FF8888"
set ColorSpecs(BalloonHelp,Foreground)		black
set ColorSpecs(Default,Background)		"light grey"
set ColorSpecs(Backdrop,Background)		black
set ColorSpecs(Menu,ActiveBackground)	        salmon;
set ColorSpecs(Menu,ActiveForeground)	        black
set ColorSpecs(Menu,Background)			azure3
set ColorSpecs(Menu,Foreground)			black
set ColorSpecs(Menu,Select)			coral
set ColorSpecs(Menubar,Background)	 	"\#c36176";
set ColorSpecs(Menubar,Foreground)		"\#fee4a9";
set ColorSpecs(Menubar,ActiveBackground)	"\#fee4a9";
set ColorSpecs(Menubar,ActiveForeground)	"\#c36176";
set ColorSpecs(Messages,Background) 		"\#e9c4dc";
set ColorSpecs(Messages,Foreground) 		"\#000000";
set ColorSpecs(IPAEntry,Background)		"\#FFFFFF";
set ColorSpecs(IPAEntry,Foreground)		"\#000000";
set ColorSpecs(IPAHeadings,Background)		"\#09ffb2";
set ColorSpecs(PageChoice,Background) 		"\#e6b483";
set ColorSpecs(PageChoice,ActiveBackground)	"\#5040FF";
set ColorSpecs(PageChoice,Selected) 	"\#F30086";
set ColorSpecs(PageChoice,ActiveForeground) 		"\#FFFFFF";
set ColorSpecs(PageChoice,UnselectedPageForeground) 		"\#000000";
set ColorSpecs(RadioButton,Background) "\#A0A0FF"
set ColorSpecs(RadioButton,SelectedBackground) green
set ColorSpecs(RadioButton,ActiveBackground) "\#FF8080"
set ColorSpecs(SortOrderDefinition,Background)			"\#FFFFFF";
set ColorSpecs(SortOrderSeparator,Background)			"\#FFFFFF";
set ColorSpecs(Substitutions,Background)		"\#FFFFFF";
set ColorSpecs(UserTextEntry,Background)	"\#FFFFFF";
set ColorSpecs(UserTextEntry,Foreground)	black
set ColorSpecs(Entry,Background)	"navajo white"
set ColorSpecs(Entry,DisabledBackground)		blue
set ColorSpecs(UserText,Foreground)		\#0000FF
set ColorSpecs(RollUpButton,ActiveBackground) NavajoWhite
set ColorSpecs(RollUpButton,ActiveForeground) red


# General defaults
set BMPOnlyP 0;
set GlobalInversionP 0;
set ReservePrivateUseAreasP 0;
set FieldSeparator  ""
set RecordSeparator "";
set KeyCount 0;
set MaxKeyCount $KeyCount;
set WhichKey 0;
set RecordParse 1;
set WholeRecordIsKeyP 0;
set EOLCarriageReturnP 0;
set WhichFontToSet MainFont

#This array maps key numbers to page names, e.g. 0-> .gen, 1->.ks1
array set KeyMap {};
array set InverseKeyMap {};
#This array maps key numbers to key selection buttons, e.g. 0->.top.sel.gen, 1->.top.sel.ks1
array set SelectionButtonMap {};
array set InverseSelectionButtonMap {};
array set CommandGlosses {};
array set PopupList {};
#This array is indexed on piece of information and key name.
array set KeyInfo {};

#Defaults
set SortAlgorithm q
set DefaultBrowser dillo
#For this purpose dillo is in many respects arguably the best choice because
#it is very lightweight and starts up fast. However, it isn't as fully
#featured as the others, and in particular, doesn't handle the full range of
#Unicode characters.
#To select a different default browser - uncomment (delete the initial #-sign from) one of the
#following lines:
#set DefaultBrowser firefox
#set DefaultBrowser epiphany;
#set DefaultBrowser galeon;
#set DefaultBrowser konqueror;
#set DefaultBrowser mozilla;
#set DefaultBrowser netscape;
#set DefaultBrowser opera;
set BrowserList [list firefox mozilla epiphany galeon konqueror dillo netscape]
set BrowserPIDS [list];

proc LoadMessageCatalog {} {
    global DebugP;

    if { $DebugP } {
	if { [::msgcat::mcload "msgs"] == 0} {
	    puts "No message catalog loaded."
	} else {
	    puts "Message catalog loaded."
	}
    } else  {
	::msgcat::mcload [file join [file dirname [info script]] msgs];
    }
}

proc ShutDown {} {
    global BrowserPIDS;
    #Shutdown child browsers
    foreach pid $BrowserPIDS {
	catch {exec kill $pid};
    }
    exit 0;
}

proc OldShutDown {} {
    global BrowserPIDS;
    #Shutdown child browsers
    foreach pid $BrowserPIDS {
	catch {exec kill $pid};
    }
    if {$::LastCommandLineSaveTime < $::LastExecutionTime} {
	ShowMessage [_ "The command line has not been saved recently."]
	SaveCommandLine; 
    }
    exit 0;
}

proc ShowWebPage {url} {
    global BrowserPIDS;
    if {[string equal $::System MacOSX]} {
	lappend BrowserPIDS [exec osascript -e "\"open location $url\""]
	return 
    }
    set BrowserFound 0;
    foreach Browser $::BrowserList {
	if { [string length [auto_execok $Browser]]} {
	    set BrowserFound 1;
	    break ;
	} else {
	    ShowMessage [format \
	     [_ "The browser %s is not available on this machine or not in your path."]\
		 $Browser];
	}
    }
    if {$BrowserFound} {
	lappend BrowserPIDS [exec $Browser $url &]
    } else {
	ShowMessage [_ "No browser on the browser list was located."]
    }
}

proc BindInsertionTarget {v} {
    bind $v <FocusIn> "+SetInsertionTargets $v"
}

#This provides an addition to the default methods of the Scrollbar
#widget. The default method, bound to <B1>, #increments or decrements
#the value by the resolution, by default 1. If you want a larger
#increment, you can use a larger resolution, but sometimes it is
#convenient to have a finer resolutio available while also being
#able to move in larger increments. A solution is to bind to
#<B3>, or some other event if you wish, a larger movement.
#This procedure moves by the specified multiplier k times
#the resolution of the Scrollbar. 

proc ScrollbarMoveBigIncrement {w f x y} {
    set part [$w identify $x $y]
    switch -exact -- $part {
	trough1 {
	    set dir -1;
	}
	arrow1 {
	    set dir -1;
	}
	trough2 {
	    set dir  1;
	}
	arrow2 {
	    set dir  1;
	}
	default {
	    return ;
	}
    }
    set CurrentFraction [lindex [$w get] 0]
    set NewFraction [expr $CurrentFraction + ($dir * $f)]
    eval [concat [$w cget -command] moveto $NewFraction]
}

#Font stuff
#Font system begins here

# We set these outside the namespace since FontInfo has to be global.
# Default defaults

set FontInfo(family) courier
set FontInfo(size) 12
set FontInfo(weight) normal
set FontInfo(slant) roman
set FontInfo(underline) 0
set FontInfo(overstrike) 0

namespace eval fontsel {
    variable FontPropertyList [list family size weight slant underline overstrike]
    variable FontPropertyClass
    variable FSCColors

    foreach p $FontPropertyList {
	set FontPropertyClass($p) generic;
    }
    set FontPropertyClass(underline) boolean
    set FontPropertyClass(overstrike) boolean

    #We check the existence of the variable so that this
    #can safely be called AFTER non-default values are set.
    proc SetFontInfoDefaults {} {
	global FontInfo;
	foreach ft $::FontList {
	    if {![info exist FontInfo($ft,family)]} {
		set FontInfo($ft,family)	$FontInfo(family)
	    }
	    if {![info exist FontInfo($ft,size)]} {
		set FontInfo($ft,size)	$FontInfo(size)
	    }
	    if {![info exist FontInfo($ft,weight)]} {
		set FontInfo($ft,weight)	$FontInfo(weight)
	    }
	    if {![info exist FontInfo($ft,slant)]} {
		set FontInfo($ft,slant)	$FontInfo(slant)
	    }
	    if {![info exist FontInfo($ft,underline)]} {
		set FontInfo($ft,underline)	$FontInfo(underline)
	    }
	    if {![info exist FontInfo($ft,overstrike)]} {
		set FontInfo($ft,overstrike)	$FontInfo(overstrike)
	    }
	    if {![info exist FontInfo($ft,gloss)]} {
		set FontInfo($ft,gloss)	$ft;
	    }
	    if {![info exist FontInfo($ft,help)]} {
		set FontInfo($ft,help)	"?"
	    }
	}
    }

    #For a given font assign font-specific properties from generics.
    proc FontSet {which} {
	global FontInfo
	variable FontPropertyList
	foreach prop $FontPropertyList {
	    set FontInfo($which,$prop) $FontInfo($prop);
	}
    }

    #Assign the proprety values of a specified font to the generics.
    proc InverseFontSet {which} {
	global FontInfo
	variable FontPropertyList
	foreach prop $FontPropertyList {
	    set FontInfo($prop) $FontInfo($which,$prop);
	}
    }

    #Configure a specified font according to the font-specific properties.
    proc ConfigureFont {which} {
	global FontInfo
	variable FontPropertyList
	foreach prop $FontPropertyList {
	    font configure $which -$prop $FontInfo($which,$prop)
	}
    }

    #Record as default values the font-specific values of properties at the
    #time of the call. The recorded values are intended for use by
    #ResetToDefaults 
    proc RecordDefaults {} {
	global FontInfo
	global FontList;
	variable FontPropertyList

	foreach f $FontList {
	    foreach p $FontPropertyList {
		set FontInfo($f,$p,Default) $FontInfo($f,$p);
	    }
	}
    }

    #Create all of the fonts on the font list and configure them
    #according to the generic values of the properties, which are
    #also assigned at this time to the font-specific variables.
    proc CreateFonts {} {
	global FontList;

	foreach ft $FontList {
	    font create $ft;
	    InverseFontSet $ft;
	    ConfigureFont $ft;
	}
    
    }

    #Get the values from the three scales, combine them into a hex RGB spec,
    #assign its value to FontExampleColor, and configure the two examples.
    proc UpdateFontExampleColor {x} {
	variable FSCColors
	global FontExampleColorConfigureWhich

	UpdateFontExampleColorHex;
	.selectFont.curcan.att.r1c1 configure \
	    -$::FontExampleColorConfigureWhich  \#$::FontExampleColor
	.selectFont.curcan.att.r2c1 configure \
	    -$::FontExampleColorConfigureWhich \#$::FontExampleColor
	set FSCColors(red,$FontExampleColorConfigureWhich)   $::FontRed;
	set FSCColors(green,$FontExampleColorConfigureWhich) $::FontGreen;
	set FSCColors(blue,$FontExampleColorConfigureWhich)  $::FontBlue;
    }

    proc UpdateFontExampleColorHex {} {
	set ::FontExampleColor [format "%02X%02X%02X" $::FontRed $::FontGreen $::FontBlue];
    }

    proc RestoreCSColors {} {
	variable FSCColors
	global FontExampleColorConfigureWhich
	set ::FontRed   $FSCColors(red,$FontExampleColorConfigureWhich)
	set ::FontGreen $FSCColors(green,$FontExampleColorConfigureWhich)
	set ::FontBlue  $FSCColors(blue,$FontExampleColorConfigureWhich)
	UpdateFontExampleColorHex;
    }

    proc CloneMainFontAsFontControlPanelFont {} {
	variable FontPropertyList
	global FontInfo

	foreach p $FontPropertyList {
	    font configure FontControlPanelFont -$p $FontInfo(MainFont,$p);
	}
    }
					

    #We create this separately because we don't want it on the FontList.
    font create FontControlPanelFont;

    #This is the main procedure of this package.
    #It creates the font control panel.
    proc CreateFontControlPanel {args} {
	global FontInfo;
	global WhichFontToSet
	global FontList;
	variable FontPropertyList
	variable FSCColors

	set General 1
	set exwid 10

	set w .selectFont
	if {[winfo exists $w]} {
	    wm deiconify $w;
	    raise $w;
	    return ;
	}
	toplevel $w
	wm title $w [_ "Font Selection"]
	BindKeys $w
	wm protocol $w WM_DELETE_WINDOW "wm withdraw $w"
	
	#The idea is that in general we want to use the main
	#font here, but we keep them separate so that we
	#can wait before switching the control panel to
	#the new main font configuration so that
	#the user isn't confronted with an unusable
	#control panel if he or she sets the mainfont to something
	#crazy.
	CloneMainFontAsFontControlPanelFont;

	if {[llength $args] > 0} {
	    set ::WhichFontToSet [lindex $args 0];
	    set General 0;
	} 
	set FontTypes [llength $FontList];
	if {$FontTypes == 1} {
	    set ::WhichFontToSet [lindex $FontList 0];
	    set General 0;
	}

	frame $w.which -relief ridge -border 3
	if {$General} {
	    set msg [_ "For what aspect of the program\ndo you wish to set the font?"]
	    balloonhelp_for $w.which $msg
	    label $w.which.title -text [_ "Use for which to set font"] \
		-anchor w -font FontControlPanelFont
	    frame $w.which.btns;
	    set k 0;
	    set PerRow 4;
	    set ypad 3
	    set xpad 10
	    foreach ft $FontList {
		set bn $w.which.btns.f$ft;
		radiobutton $bn -text [_ $FontInfo($ft,gloss)]  \
		    -variable WhichFontToSet -value $ft \
		    -command fontsel::SetFontSelectionDefaults \
		    -font FontControlPanelFont \
		    -indicatoron 0 -selectcolor $::ColorSpecs(Default,Background)
		balloonhelp_for $w.which.btns.f$ft $FontInfo($ft,help)
		set row [expr 1+ $k/$PerRow]
		set col [expr $k%$PerRow]
		if {$FontTypes >= $PerRow} {
		    grid $w.which.btns.f$ft -row $row -column $col \
			-sticky we -ipadx 3 -padx $xpad -pady $ypad
		}
		incr k
	    }
	    if {$FontTypes < $PerRow} {
		foreach ft $FontList {
		    pack $w.which.btns.f$ft -side left -expand 1 -fill x \
			-ipadx 5 -ipady 3 -padx 40 -pady 3
		}
	    }
	    frame $w.which.pad  -height 4
	    pack $w.which.title -side top -expand 1 -fill both -anchor w
	    pack $w.which.btns  -side top -expand 1 -fill both -anchor w
	    pack $w.which.pad   -side top -expand 0 -fill x    -anchor w

	}

	frame $w.mid 
	frame $w.mid.opts  -relief ridge -border 3
	frame $w.mid.families  -relief ridge -border 3
	label $w.mid.families.lab -text [_ "Family"] -relief ridge \
	    -justify center -font FontControlPanelFont
	listbox $w.mid.families.lb -height 1 -exportselection 0 \
	    -yscrollcommand "$w.mid.families.sbar set" -selectmode single \
	    -font FontControlPanelFont
	scrollbar $w.mid.families.sbar -orient vertical -command "$w.mid.families.lb yview"
	bind $w.mid.families.sbar <<B3>> \
	    "ScrollbarMoveBigIncrement $w.mid.families.sbar 0.20 %x %y"

	bind $w.mid.families.lb <<B3>> ProvideFontDescription

	pack $w.mid.families.lab  -side top -expand 0 -fill x
	pack $w.mid.families.lb   -side left -expand 1 -fill both
	pack $w.mid.families.sbar -side left -expand 1 -fill y

	label $w.mid.opts.lab -text [_ "Attributes"] -relief ridge \
	    -justify center -font FontControlPanelFont
	label $w.mid.opts.sizel -text [_ "Size:"]  -font FontControlPanelFont
	scale $w.mid.opts.size -orient h -digit 1 -from 5 -to 55 \
	    -variable FontInfo(size)  -tickinterval 0 -length 150 \
	    -font FontControlPanelFont
	bind $w.mid.opts.size <<B3>> "ScaleMoveBigIncrement $w.mid.opts.size 5 %x %y"

	label $w.mid.opts.weightl -text [::msgcat::mc "Bold:"] \
	    -font FontControlPanelFont	    
	checkbutton $w.mid.opts.weight -variable FontInfo(weight) \
	    -onvalue bold -offvalue normal  -font FontControlPanelFont

	label $w.mid.opts.slantl -text [::msgcat::mc "Italic:"] \
	    -font FontControlPanelFont
	checkbutton $w.mid.opts.slant -variable FontInfo(slant) \
	    -onvalue italic -offvalue roman -font FontControlPanelFont

	label $w.mid.opts.ulinel -text [::msgcat::mc "Underline:"] \
	    -font FontControlPanelFont
	checkbutton $w.mid.opts.uline -variable FontInfo(underline) \
	    -onvalue 1 -offvalue 0  -font FontControlPanelFont

	label $w.mid.opts.strkovl -text [::msgcat::mc "Overstrike:"] \
	    -font FontControlPanelFont
	checkbutton $w.mid.opts.strkov -variable FontInfo(overstrike) \
	    -onvalue 1 -offvalue 0  -font FontControlPanelFont

	grid $w.mid.opts.lab   -row 0 -column 0 -columnspan 2 -sticky ew
	grid $w.mid.opts.sizel -row 1 -column 0 -sticky w
	grid $w.mid.opts.size -row 1 -column 1 -sticky w
	grid $w.mid.opts.weightl -row 2 -column 0 -sticky w
	grid $w.mid.opts.weight -row 2 -column 1 -sticky w
	grid $w.mid.opts.slantl -row 3 -column 0 -sticky w
	grid $w.mid.opts.slant -row 3 -column 1 -sticky w
	grid $w.mid.opts.ulinel -row 4 -column 0 -sticky w
	grid $w.mid.opts.uline -row 4 -column 1 -sticky w
	grid $w.mid.opts.strkovl -row 5 -column 0 -sticky w
	grid $w.mid.opts.strkov -row 5 -column 1 -sticky w

	pack $w.mid.families -side left -expand 1 -fill both -padx 5 -pady 2
	pack $w.mid.opts     -side left -expand 1 -fill both -padx 5 -pady 2

	eval $w.mid.families.lb insert 0 [lsort [font families]]

	bind $w.mid.families.lb <ButtonPress-1> {fontsel::SelectFontFamily %W %y}

	frame $w.cntls -relief ridge -border 3
	button $w.cntls.sav -text [_ "Apply"]  -command fontsel::FontSave \
	    -font FontControlPanelFont
	button $w.cntls.res -text [_ "Reset"] -command  fontsel::ResetToDefaults \
	    -font FontControlPanelFont
	button $w.cntls.can -text [_ "Dismiss"] -command "wm withdraw $w" \
	    -font FontControlPanelFont
	button $w.cntls.cpanel -text [_ "Here Too?"] \
	    -command fontsel::CloneMainFontAsFontControlPanelFont \
	-font FontControlPanelFont
	pack $w.cntls.cpanel -side left  -expand 1 -fill both -padx 3
	pack $w.cntls.can    -side left  -expand 1 -fill both -padx 3
	pack $w.cntls.res    -side left  -expand 1 -fill both -padx 3
	pack $w.cntls.sav    -side right -expand 1 -fill both -padx 3

	set msg [_ "Press this button to dismiss the popup."];
	balloonhelp_for $w.cntls.can $msg
	set msg [_ "Press this button to reset the font to its defaults."];
	balloonhelp_for $w.cntls.res $msg
	set msg [_ "Press this button to make the changes\nyou have made take effect."]
	balloonhelp_for $w.cntls.sav $msg
	set msg [format \
	     [_ "Press this button to set the fonts\nin this control panel to the %s font."] \
		     [_ $::FontInfo(MainFont,gloss)]]
	balloonhelp_for $w.cntls.cpanel $msg

	frame $w.curcan -relief ridge -border 1
	set ATT [frame $w.curcan.att]
	set Row 0
	foreach r {Header Current Candidate} {
	    set Column 2
	    foreach p $FontPropertyList {
		set v $w.curcan.att.r${Row}c${Column};
		label $v  -font FontControlPanelFont
		incr Column;
	    } 
	    incr Row;
	}

	font create CurrentFontExampleFont \
	    -family $FontInfo($::WhichFontToSet,family) \
	    -size $FontInfo($::WhichFontToSet,size) \
	    -weight $FontInfo($::WhichFontToSet,weight) \
	    -slant $FontInfo($::WhichFontToSet,slant) \
	    -underline $FontInfo($::WhichFontToSet,underline) \
	    -overstrike $FontInfo($::WhichFontToSet,overstrike);

	font create CandidateFontExampleFont \
	    -family $FontInfo($::WhichFontToSet,family) \
	    -size $FontInfo($::WhichFontToSet,size) \
	    -weight $FontInfo($::WhichFontToSet,weight) \
	    -slant $FontInfo($::WhichFontToSet,slant) \
	    -underline $FontInfo($::WhichFontToSet,underline) \
	    -overstrike $FontInfo($::WhichFontToSet,overstrike);

	label $w.curcan.att.r0c0 -font FontControlPanelFont
	label $w.curcan.att.r0c1 -font FontControlPanelFont
	label $w.curcan.att.r1c0  -text [_ "Current"] -font FontControlPanelFont
	entry $w.curcan.att.r1c1 -font CurrentFontExampleFont -relief flat -width $exwid
	$w.curcan.att.r1c1 insert 0 [_ "example"]
	label $w.curcan.att.r2c0  -text [_ "Candidate"] -font FontControlPanelFont
	entry $w.curcan.att.r2c1 -font CandidateFontExampleFont -relief flat  -width $exwid
	$w.curcan.att.r2c1 insert 0 [_ "example"]

	#This is for use in conjunction with my character insertion library.
	#It arranges for the various character insertion widgets to insert
	#characters into the focussed window.
	if {[llength [info commands BindInsertionTarget]]} {
	    BindInsertionTarget $w.curcan.att.r1c1;
	    BindInsertionTarget $w.curcan.att.r2c1;
	}

	set CLR [frame $w.curcan.clr]
	set ln 60;
	set wd 10
	set trc \#D4B8C1
	scale $CLR.red -orient v -digit 1 -from 255 -to 0 -tickinterval 0 \
	    -variable FontRed  -showvalue 0 -length $ln -width $wd\
	    -troughcolor $trc -activebackground \#F0AAAA \
	    -bg red -fg yellow -command fontsel::UpdateFontExampleColor
	scale $CLR.grn -orient v -digit 1 -from 255 -to 0 -tickinterval 0 \
	    -variable FontGreen  -showvalue 0 -length $ln -width $wd\
	    -troughcolor $trc -activebackground \#AAF0AA \
	    -bg green -fg yellow -command fontsel::UpdateFontExampleColor
	scale $CLR.blu -orient v -digit 1 -from 255 -to 0 -tickinterval 0 \
	    -variable FontBlue  -showvalue 0 -length $ln -width $wd\
	    -troughcolor $trc -activebackground \#AAAAF0 \
	    -bg blue -fg yellow -command fontsel::UpdateFontExampleColor
	set FSCColors(red,bg)   0x00
	set FSCColors(green,bg) 0x00
	set FSCColors(blue,bg)  0x00
	set FSCColors(red,fg)   0x00
	set FSCColors(green,fg) 0x00
	set FSCColors(blue,fg)  0x00

	bind $CLR.red <<B3>> "ScaleMoveBigIncrement $CLR.red -20 %x %y"
	bind $CLR.grn <<B3>> "ScaleMoveBigIncrement $CLR.grn -20 %x %y"
	bind $CLR.blu <<B3>> "ScaleMoveBigIncrement $CLR.blu -20 %x %y"

	set ::FontRed   255
	set ::FontGreen 255
	set ::FontBlue  255
	set FontExampleColor \#FFFFFF
	label $CLR.rdt -textvariable FontExampleColor -width 7 -relief raised
	bind $CLR.rdt <Button-1> "pack forget $CLR"
	bind $ATT <Button-1> "pack $w.curcan.clr -before $ATT -side left -expand 1 -fill both"
	set msg [_ "Left click here to remove the color selector."]
	balloonhelp_for $CLR.rdt $msg;
	set msg [_ "Use this to set the colors in the example text boxes."]
	balloonhelp_for $CLR.red $msg;
	balloonhelp_for $CLR.grn $msg;
	balloonhelp_for $CLR.blu $msg;

	frame $CLR.whi
	set ::FontExampleColorConfigureWhich bg;
	radiobutton $CLR.whi.t -variable FontExampleColorConfigureWhich \
	    -value fg -command fontsel::RestoreCSColors -text [_ "fg"] \
	    -indicatoron 0 -activebackground gray -selectcolor gray \
	    -font FontControlPanelFont
	radiobutton $CLR.whi.b -variable FontExampleColorConfigureWhich \
	    -value bg -command fontsel::RestoreCSColors -text [_ "bg"] \
	    -indicatoron 0 -activebackground gray -selectcolor gray \
	    -font FontControlPanelFont
	pack $CLR.whi.t -side left -expand 1 -fill both
	pack $CLR.whi.b -side left -expand 1 -fill both

	pack $CLR.rdt -side top -expand 1  -fill both
	pack $CLR.whi -side bottom -expand 1  -fill both
	pack $CLR.red -side left -expand 1 -fill y
	pack $CLR.grn -side left -expand 1 -fill y
	pack $CLR.blu -side left -expand 1 -fill y

	set msg [_ "Choose the color for the sample text."]
	balloonhelp_for $CLR.whi.t $msg;
	set msg [_ "Choose the background color for the sample text."]
	balloonhelp_for $CLR.whi.b $msg;

	#Now grid them all
	set xp 5
	set yp 3
	set CLimit [expr [llength $FontPropertyList] + 2];
	for {set r 0} {$r < 3} {incr r} {
	    for {set c 0} {$c < $CLimit} {incr c} {
		set v $w.curcan.att.r${r}c${c};
		grid $v -row $r -column $c -sticky w -padx $xp -pady $yp
	    } 
	}

	set xp 3
	set yp 1
	if {!$General} {
	    $w.curcan.att.r0c0 configure -text [string totitle [_ $FontInfo($::WhichFontToSet,gloss)]]
	}

	pack $w.curcan.clr -side left -expand 1 -fill both -padx 9 -pady 5
	pack $w.curcan.att -side left -expand 1 -fill both -padx 3 -pady 5

	#Put it all together
	frame $w.botsep -height 4
	pack $w.which -side top -expand 1 -fill x -padx 8 -pady 6
	pack $w.curcan -side top -expand 1 -fill x -padx 8 -pady 6
	pack $w.mid   -side top -expand 1 -fill x -padx 8 -pady 1
	pack $w.cntls -side top -expand 1 -fill x -padx 8 -pady 2
	pack $w.botsep -side top -expand 1 -fill x -padx 8 -pady 2
	if {$General} {
	    $w.which.btns.f[lindex $FontList 0] invoke;#  Default to first on list
	}
	foreach f $FontPropertyList {
	    trace variable FontInfo($f) w fontsel::FontShow;
	}
	return $w;
    }

    #This resets the properties of the font specified by WhichFontToSet
    #to their default values, where "default" means whatever values
    #are stored in FontInfo(<font>,<property>,Default). The intention
    #is that these values will have been set by RecordDefaults at
    #a suitable point. A suitable point might be program startup or it
    #might be after init files have been read.
    #After resetting the attributes for the current font to their
    #default values, it configures the fonts for both the current and candidate
    #examples in the control panel to match.
    proc ResetToDefaults {} {
	global FontInfo;
	global WhichFontToSet
	variable FontPropertyList

	foreach prop $FontPropertyList {
	    set FontInfo($::WhichFontToSet,$prop) $FontInfo($::WhichFontToSet,$prop,Default);
	    set FontInfo($prop) $FontInfo($::WhichFontToSet,$prop,Default);
	}
	ConfigureFont $::WhichFontToSet;
	ConfigureCurrentExampleFont;
	ConfigureCandidateExampleFont;
	DescribeBothFonts;
    }

    #This is the procedure called from the control panel when the user decides
    #to apply and save the values set on the control panel. It sets the font-specific
    #attributes from the generic ones, configures the target font as well as the
    #current example font, and updates the description of the current font
    #in the control panel.
    proc FontSave {} {
	global FontInfo

	set f $::WhichFontToSet;
	FontSet $f;
	ConfigureFont $f
	ConfigureCurrentExampleFont;
	DescribeBothFonts;
    } 

    #This procedure configures the font used to display the candidate example
    #in the control panel. It is intended to be called whenever a property
    #is changed in the control panel or when the target font is changed.
    proc ConfigureCandidateExampleFont {} {
	global FontInfo
	global WhichFontToSet
	variable FontPropertyList

	foreach prop $FontPropertyList {
	    font configure CandidateFontExampleFont -$prop $FontInfo($prop)
	}
    }

    #This procedure configures the font used to display the current example
    #in the control panel. It is intended to be called when the user
    #applies new values or when the target font is changed.
    proc ConfigureCurrentExampleFont {} {
	global FontInfo
	global WhichFontToSet
	variable FontPropertyList

	foreach prop $FontPropertyList {
	    font configure CurrentFontExampleFont -$prop $FontInfo($::WhichFontToSet,$prop)
	}
    }

    #This procedure configures the candidate example font#and updates the
    #description of the candidate font in the control panel. It is intended
    #to be called whenever a proprty of the candidate font is changed.
    proc FontShow {args} {
	ConfigureCandidateExampleFont;
	DescribeBothFonts;
    }

    #This procedure generates the descriptions of the current and candidate
    #fonts that are shown in the control panel.
    proc DescribeBothFonts {} {
	global FontInfo
	global WhichFontToSet;
	variable FontPropertyList

	set f $::WhichFontToSet;
	set c 2;
	foreach prop $FontPropertyList {
	    .selectFont.curcan.att.r0c$c configure -text  [string totitle [_ $prop]] 
	    set value $FontInfo($f,$prop)
	    if {$value == 1} {set value [_ "Yes"]} else {
		if {$value == 0} {set value [_ "No"]}}
	    .selectFont.curcan.att.r1c$c configure -text $value;
	    set value $FontInfo($prop)
	    if {$value == 1} {set value [_ "Yes"]} else {
		if {$value == 0} {set value [_ "No"]}}
	    .selectFont.curcan.att.r2c$c configure -text $value; 
	    incr c;
	}
    }

#This is to be called when we change font targets.
#It resets the control panel to show the current
#configuration for the newly targeted font.
    proc SetFontSelectionDefaults {} {
	global FontInfo;
	global WhichFontToSet;
	variable FontPropertyList

	foreach prop $FontPropertyList {
	    set FontInfo($prop) $FontInfo($WhichFontToSet,$prop);
	}
	set FontChoices [.selectFont.mid.families.lb size];
	set k 1;
	while {$k <= $FontChoices} {
	    set Family [.selectFont.mid.families.lb get $k];
	    if {[string equal $Family [string tolower $FontInfo($WhichFontToSet,family)]]} {
		.selectFont.mid.families.lb selection clear 0 end;
		.selectFont.mid.families.lb see $k
		.selectFont.mid.families.lb selection set $k $k;
		.selectFont.mid.families.lb activate $k;
		set FontInfo(family) [.selectFont.mid.families.lb get $k]
		break
	    }
	    incr k;
	}
	ConfigureCandidateExampleFont
	ConfigureCurrentExampleFont;
	DescribeBothFonts;
    }

    #This is the callback that extracts a new font family
    #setting from the control panel.
    proc SelectFontFamily {w y} {
	global FontInfo

	set index [$w nearest $y]
	if {$index != ""} {
	    set FontInfo(family) [$w get $index]
	}
    }

    #This is the callback that extracts a new font size
    #from the control panel.
    proc SelectFontSize {w} {
	global WhichFontToSet
	global FontInfo

	set size [$w get]
	if {[catch {expr round($size)} size] == 0} {
	    if { ($size > 0) && ($size <= 60) } {
		set FontInfo(size) $size
		return ;
	    }
	}
	$w delete 0 end
	$w insert 0 $FontInfo($WhichFontToSet,size)
    }

    #This is presently a stub.
    #It is intended to be called on an event, probably <B3>,
    #in the font family listbox in the control panel.
    #Its purpose is to provide the user with information about
    #the particular font. 
    proc ProvideFontDescription {w y} {
	variable FontDescriptions

	set index [$w nearest $y]
	if {$index != ""} {
	    FontDescriptions([$w get $index])
	}
    }

    #Create a command for setting each combination of font and property.
    proc DefineFontSettingProcs {} {
	variable FontPropertyList
	variable FontPropertyClass
	global FontList;
	global FontProcList;

	foreach ft $FontList {
	    foreach prop $fontsel::FontPropertyList {
		if {[string equal $FontPropertyClass($prop) boolean]} {
		    set ProcName  [format "::fontsel::Set%s%sP" $ft [string totitle $prop]];
		    lappend FontProcList $ProcName;
		    set cmd [list "proc"  $ProcName  "\{v\}" \
			 "set ::FontInfo($ft,$prop) \[SlaveBoolean \$v\];\nConfigureFont $ft;"]
		} else {
		    set ProcName  [format "::fontsel::Set%s%s" $ft [string totitle $prop]];
		    lappend FontProcList $ProcName;
		    set cmd [list "proc" $ProcName "\{v\}" \
			 "set ::FontInfo($ft,$prop) \$v;\nConfigureFont $ft;"]
		}
		eval $cmd;
	    }
	}
    }

    #Create aliases in the named daughter interpreter for the font setting commands
    proc AliasFontSettings {interp} {
	variable FontPropertyList
	variable FontPropertyClass
	global FontList;
	
	foreach ft $FontList {
	    foreach prop $FontPropertyList {
		set Tprop [string totitle $prop]
		set Tprop2 $Tprop;
		if {[string equal $FontPropertyClass($prop) boolean]} {
		    set Tprop ${Tprop}P
		}
		eval [split [format "%s alias %s%s ::fontsel::Set%s%s" \
			 $interp $ft $Tprop $ft $Tprop2]]
	    }
	}
    }

    #Returns a list of init file commands representing the current font settings.
    proc SaveFontSettings {} {
	variable FontPropertyList
	variable FontPropertyClass
	global FontInfo
	global FontList;
	
	set cl [list]
	foreach ft $FontList {
	    foreach prop $FontPropertyList {
		set Tprop [string totitle $prop]
		if {[string equal $FontPropertyClass($prop) boolean]} {
		    set Tprop ${Tprop}P
		}
		lappend cl [format "%s%s %s" $ft $Tprop [list $FontInfo($ft,$prop)]]
	    }
	}
	return [lsort $cl];
    }
}

# End of namespace fontsel

# This is the stuff specific to this program.

set FontList { \
MainFont\
HeaderFont\
BalloonHelpFont\
MenuFont\
UserPlainTextFont\
UserTechnicalTextFont\
CharacterEntryFont\
DiacriticFont\
AccentedLetterFont}

set FontInfo(family) code2000


set FontInfo(BalloonHelpFont,family) lucida
set FontInfo(BalloonHelpFont,gloss) "balloon help"
set FontInfo(BalloonHelpFont,help) "This font is used in help balloons."

set FontInfo(MainFont,family) "courier"
set FontInfo(MainFont,gloss) [_ "general"]
set FontInfo(MainFont,help) [_ "This font is used for most things."]

set FontInfo(HeaderFont,family) "courier"
set FontInfo(HeaderFont,size) 12
set FontInfo(HeaderFont,weight) bold
set FontInfo(HeaderFont,gloss) [_ "headings"]
set FontInfo(HeaderFont,help) [_ "This font is used for headings."]

set FontInfo(UserPlainTextFont,gloss) [_ "plain user text"]
set FontInfo(UserPlainTextFont,help) [_ "This font is used for ordinary text entered\nby the user, such as file names."]
set FontInfo(UserPlainTextFont,family) bible
set FontInfo(UserTechnicalTextFont,gloss) [_ "technical user text"]
set FontInfo(UserTechnicalTextFont,help) [_ "This font is used for text entered by the\nuser that is likely to contain unusual\ncharacters, such as multigraph definitions."]
set FontInfo(UserTechnicalTextFont,family) "sil doulos"

set FontInfo(MenuFont,family) courier
set FontInfo(MenuFont,gloss) [_ "menu"]
set FontInfo(MenuFont,help) [_ "This font is used for menu labels."]

set FontInfo(CharacterEntryFont,gloss) "character entry"
set FontInfo(CharacterEntryFont,help) "This font is used on the labels of\nmost character insertion widgets."
set FontInfo(AccentedLetterFont,gloss) "accented letters"
set FontInfo(AccentedLetterFont,help) "This font is used on the labels of the\naccented character insertion widget."

set FontInfo(DiacriticFont,gloss) "diacritics"
set FontInfo(DiacriticFont,help) "This font is used on the labels of the\ndiacritic insertion widget."

set FontInfo(SmallLabelFont,family) $FontInfo(MainFont,family);
set FontInfo(SmallLabelFont,gloss) "small labels"
set FontInfo(SmallLabelFont,help) "small labels"

set FontInfo(CharacterEntryFont,size) 14
set FontInfo(AccentedLetterFont,size) 14
set FontInfo(DiacriticFont,size)  [expr $FontInfo(CharacterEntryFont,size) + 40];
set FontInfo(SmallLabelFont,size) [expr $FontInfo(AccentedLetterFont,size) -  8];

if {$TkEightFivePlusOnX11P} {
    set FontInfo(BalloonHelpFont,size) 10
    set FontInfo(MainFont,size)  10
    set FontInfo(MenuFont,size)  10
    set FontInfo(AccentedLetterFont,size) 11
    set FontInfo(CharacterEntryLabelFont,size) 10
    set FontInfo(CharacterEntryFont,size) 11
    set FontInfo(RegexpFont,size) 11
    set FontInfo(UserPlainTextFont,size) 12
    set FontInfo(UserTechnicalTextFont,size) 11
    set FontInfo(CharacterEntryFont,size) 11
} else {
    set FontInfo(BalloonHelpFont,size) 13
    set FontInfo(MainFont,size) 12
    set FontInfo(MenuFont,size) 12
    set FontInfo(AccentedLetterFont,size) 14
    set FontInfo(CharacterEntryLabelFont,size) 13
    set FontInfo(CharacterEntryFont,size) 14
    set FontInfo(RegexpFont,size) 13
    set FontInfo(UserPlainTextFont,size) 14
    set FontInfo(UserTechnicalTextFont,size) 13
    set FontInfo(CharacterEntryFont,size) 14
}

#Now call these two functions.

fontsel::SetFontInfoDefaults;
fontsel::CreateFonts;

#End of font stuff

option add *selectFont*Font MainFont 100
option add *Label.Font MainFont 100
option add *Menu.Font MenuFont 100
option add *Radiobutton.Font MainFont 100

proc AddKey {} {
    incr ::KeyCount;
    incr ::MaxKeyCount;
    set KeyName [format ".ks%1d" $::MaxKeyCount]
    set KeyPageSelectionButtonLabel [format "Key %d" $::KeyCount] 
    #We start out with a simple correspondance of selection button name to page name.
    #If the button already exists, we increase the index until we find one that is free.
    set sbind $::KeyCount;
    set SelectionButtonName [format ".top.sel.ks%d" $sbind]
    while {[winfo exists $SelectionButtonName]} {
	incr sbind;
	set SelectionButtonName [format ".top.sel.ks%d" $sbind]
    }
    set ::SelectionButtonMap($::KeyCount) $SelectionButtonName;
    UpdateInverseSelectionButtonMap;
    set NewButton [radiobutton $SelectionButtonName \
	       -text $KeyPageSelectionButtonLabel \
	       -variable WhichKey -value $::KeyCount \
	       -width $::KeySelWidth -height $::KeySelHeight]
    $NewButton configure -bg $::ColorSpecs(PageChoice,Background)
    $NewButton configure -activebackground $::ColorSpecs(PageChoice,ActiveBackground)
    $NewButton configure -selectcolor $::ColorSpecs(PageChoice,Selected) 
    $NewButton configure -indicatoron 0
    pack $NewButton -side left
    set ::KeyMap($::KeyCount) $KeyName;
    UpdateInverseKeyMap;
    SetupKey $::KeyMap($::KeyCount);
    balloonhelp_for $NewButton [format [_ "Click on this button to switch to settings for key %d\nPress the right button, drag to another button,\nand release to swap keys."] $::KeyCount];
    BindKeySelectionButton $NewButton;
#    dmsg "Added key $KeyName with button $SelectionButtonName"
    TellKeyMap;
    TellSelectionButtonMap;
    $NewButton invoke
}

proc SwapKeys {m n} {
    set temp $::KeyMap($m);
    set ::KeyMap($m) $::KeyMap($n)
    set ::KeyMap($n) $temp;
    UpdateInverseKeyMap;
    TellKeyMap;
    TellSelectionButtonMap;
    $::SelectionButtonMap($::WhichKey) invoke
    ShowMessage [format [_ "Swapped keys %d and %d"] $m $n]
}

proc UpdateInverseKeyMap {} {
    unset ::InverseKeyMap;
    foreach KeyNumber [array names ::KeyMap] {
	set KeyName $::KeyMap($KeyNumber);
	set ::InverseKeyMap($KeyName) $KeyNumber;
    }
}

proc UpdateInverseSelectionButtonMap {} {
    unset ::InverseSelectionButtonMap;
    foreach KeyNumber [array names ::SelectionButtonMap] {
	set KeyName $::SelectionButtonMap($KeyNumber);
	set ::InverseSelectionButtonMap($KeyName) $KeyNumber;
    }
}

proc BindKeySelectionButton {b} {
    bind $b <<B3>> {SetKeyButtonMoveSource %X %Y}
    bind $b <<B3Release>> {SwapKeysOnEvent %X %Y}
}

proc SetKeyButtonMoveSource {x y} {
    set EventWindow [winfo containing $x $y];
    if {[info exists ::InverseSelectionButtonMap($EventWindow)] && $::InverseSelectionButtonMap($EventWindow)} {
	set ::KeyButtonMoveSource $::InverseSelectionButtonMap($EventWindow);
    } else {
	ShowMessage [_ "That wouldn't make sense. You can only swap key buttons."]
    }
}

proc SwapKeysOnEvent {x y} {
    set EventWindow [winfo containing $x $y];
    if {[info exists ::InverseSelectionButtonMap($EventWindow)] && $::InverseSelectionButtonMap($EventWindow)} {
	SwapKeys $::KeyButtonMoveSource $::InverseSelectionButtonMap($EventWindow);
    } else {
	ShowMessage [_ "That wouldn't make sense. You can only swap key buttons."]
    }
}

proc UpdateKeySelectionButtonLabels {} {
    for {set KeyNumber 1} {$KeyNumber <= $::KeyCount} {incr KeyNumber} {
	set KeyPageName $::KeyMap($KeyNumber);
	set KeyPageSelectionButton [format ".top.sel.ks%d" $KeyNumber];
	set KeyPageSelectionButtonLabel [format [_ "Key %d"] $KeyNumber]
	if {[winfo exists $KeyPageSelectionButton]} {
	    $KeyPageSelectionButton configure -text $KeyPageSelectionButtonLabel;
	}
    } 
}

proc RemoveKey {} {
    if {$::KeyCount == 1} {
	ShowMessage [_ "You can't sort anything without any keys."]
	return
    }
    set LastKeyNumber [lindex [lsort -integer -decreasing [array names ::KeyMap]] 0];
    set LastKeyName $::KeyMap($LastKeyNumber);
    trace vdelete ::KeyInfo(KeySelection,$LastKeyName) w ChooseActiveKeySelection
    trace vdelete ::KeyInfo(ExclusionsP,$LastKeyName) w ToggleExclusionEntryActive
    trace vdelete ::KeyInfo(SubstitutionsP,$LastKeyName) w ToggleSubstitutionEntryActive
    trace vdelete ::KeyInfo(SortOrderSpecType,$LastKeyName) w ToggleCustomSortOrderEntryActive
    trace vdelete ::KeyInfo(SortType,$LastKeyName) w ToggleOnSortType
    trace vdelete ::KeyInfo(OptionalP,$LastKeyName) w ToggleOptComparisonActive
    destroy $LastKeyName;

    set LastKeyPageSelectionButton $::SelectionButtonMap($::KeyCount);
    destroy $LastKeyPageSelectionButton;
    incr ::KeyCount -1;
    unset ::KeyMap($LastKeyNumber);
    unset ::SelectionButtonMap($LastKeyNumber);
    UpdateInverseSelectionButtonMap;
    UpdateInverseKeyMap;
    TellKeyMap;
    TellSelectionButtonMap;
    set ::WhichKey 1;
}

proc TellKeyMap {} {
    if {$::DebugP} {
	puts -nonewline "Keymap:            ";
	foreach n [array names ::KeyMap] {
	    puts -nonewline "$n $::KeyMap($n)   "
	}
	puts "";
	puts -nonewline "Inverse Keymap:    ";
	foreach n [array names ::InverseKeyMap] {
	    puts -nonewline "$n $::InverseKeyMap($n)   "
	}
	puts "";
    }
}

proc TellSelectionButtonMap {} {
    if {$::DebugP} {
	puts -nonewline "Buttonmap:         ";
	foreach n [array names ::SelectionButtonMap] {
	    puts -nonewline "$n $::SelectionButtonMap($n)   "
	}
	puts "";
	puts -nonewline "Inverse Buttonmap: ";
	foreach n [array names ::InverseSelectionButtonMap] {
	    puts -nonewline "$n $::InverseSelectionButtonMap($n)   "
	}
	puts "";
    }
}

proc ShowMessage {msg} {
    if {[winfo exists .top.msg]} {
	.top.msg configure -state normal;
	.top.msg delete 1.0 end;
	.top.msg insert 1.0 $msg;
	.top.msg configure -state disabled;
    } else {
	puts $msg;
    }
}

proc ClearMessageWindow {} {
     .top.msg configure -state normal
     .top.msg delete 1.0 end;
     .top.msg configure -state disabled
}

proc SpecifyExclusionFile {KeyName} {
    set ExclusionFile [tk_getOpenFile];
    if {$ExclusionFile == ""} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	$KeyName.exc.bot.ent delete 0 end;
	$KeyName.exc.bot.ent insert insert $ExclusionFile;
    }
}

proc SpecifySubstitutionFile {KeyName} {
    set SubstitutionFile [tk_getOpenFile];
    if {[string equal $SubstitutionFile ""]} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	$KeyName.sub.bot.ent delete 0 end;
	$KeyName.sub.bot.ent insert insert $ExclusionFile;
    }
}

proc GetFieldSeparator {} {
    return [.gen.ctr.wr.fsent get];
}

proc GetRecordSeparator {} {
    return [.gen.ctr.rp.cent get];
}

proc GetSortOrderSeparatorFile {KeyName} {
    return [$KeyName.sos.bot.ent get]
}

proc GetSortOrderFile {KeyName} {
    return [$KeyName.so.bot.ent get]
}

proc GetLocale {KeyName} {
    return [$KeyName.so.loc.ent get]
}

proc GetExclusionFile {KeyName} {
    return [$KeyName.exc.bot.ent get]
}

proc GetSubstitutionFile {KeyName} {
    return [$KeyName.sub.bot.ent get]
}

proc SpecifySortOrderFile {KeyName} {
    set SortOrderFile [tk_getOpenFile];
    if {$SortOrderFile == ""} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	$KeyName.so.bot.ent delete 0 end
	$KeyName.so.bot.ent insert insert $SortOrderFile;
    }
}

proc SpecifySortOrderSeparatorFile {KeyName} {
    set SortOrderSeparatorFile [tk_getOpenFile];
    if {$SortOrderSeparatorFile == ""} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	$KeyName.sos.bot.ent delete 0 end
	$KeyName.sos.bot.ent insert insert $SortOrderSeparatorFile;
    }
}

proc MsortAvailableP {} {
    if {[string length [auto_execok msort]]} {
	return 1;
    }
    return 0;
}

proc FindoutMsortVersion {} {
    catch {exec msort -v} vline
    return [lindex [split [lindex [split $vline "\n"] 0]] 1]
}


#Because of the strangeness needed in ExecuteMsort, this constructs everything
#except for the diversion of stdout to the output file.
proc ConstructCommandLine {} {
    global KeyMap;
    set cl [list msort];
    #Global flags
    lappend cl "-q";
    lappend cl "-a"
    switch -- $::SortAlgorithm {
	i {
	    lappend cl "i"
	}
	m {
	    lappend cl "m"
	}
	q {
	    lappend cl "q"
	}
	s {
	    lappend cl "s"
	}
    }
    if {$::GlobalInversionP == 1} {
	lappend cl "-I";
    }
    if {$::BMPOnlyP == 1} {
	lappend cl "-B";
    }
    if {$::ReservePrivateUseAreasP == 1} {
	lappend cl "-p";
    }
    if {$::EOLCarriageReturnP} {
	lappend cl "-m";
    }
    if {$::RecordParse == 0} {
	lappend cl "-l";
    } elseif {$::RecordParse ==2} {
	set rs [GetRecordSeparator];
	if {[string equal $rs ""] ==0} {
	    lappend cl "-r"
	    lappend cl $rs;
	}
    } elseif {$::RecordParse ==3} {
	lappend cl "-O"
	lappend cl [.gen.ctr.rp.fl.len get]
    }
    if {$::WholeRecordIsKeyP} {
	lappend cl "-w";
    } else {
	set fs [GetFieldSeparator];
	if {[string equal $fs ""] ==0} {
	    lappend cl "-d"
	    lappend cl $fs
	}
    }
    lappend cl "-u";
    switch -- $::UnicodeNormalization {
	0 {
	    lappend cl "n";
	}
	1 {
	    lappend cl "c";
	}
	2 {
	    lappend cl "d";
	}
	3 {
	    lappend cl "C";
	}
	4 {
	    lappend cl "D";
	}
    }
    if {[string length $::Opts(RandomSeed)] != 0} {
	lappend cl "-P"
	lappend cl $::Opts(RandomSeed)
    }
    #Key specific flags
    for {set i 1} {$i <= $::KeyCount} {incr i} {
	set hd $KeyMap($i);
	if {$::WholeRecordIsKeyP == 0} {
	    if {$::KeyInfo(KeySelection,$hd) == 0} {
		set p1 [$hd.key.ki.pos.posent.fldent1 get]
		set p2 [$hd.key.ki.pos.posent.fldent2 get]
		set c1 [$hd.key.ki.pos.posent.chrent1 get]
		set c2 [$hd.key.ki.pos.posent.chrent2 get]
		if {[string equal $p1 ""]} {
		    ShowMessage [format [_ "No start field has been specified for key %d"] $i];
		    return;
		}
		if {[string equal $p2 ""]} {
		    ShowMessage [format [_ "No end field has been specified for key %d"] $i];
		    return;
		}
		lappend cl "-n"
		set keyrange $p1
		if {![string equal $c1 ""]} {
		    append keyrange .$c1
		}
		if {$p1 != $p2} {
		    append keyrange ,$p2
		    if {![string equal $c2 ""]} {
			append keyrange .$c2
		    }
		}
		lappend cl $keyrange
	    } elseif {$::KeyInfo(KeySelection,$hd) == 1} {
		set t [$hd.key.ki.pos.tagent get];
		if {[string equal $t ""] == 0} {
		    lappend cl "-t"
		    lappend cl $t
		} else {
		    ShowMessage [format [_ "No tag has been specified for key %d"] $i];
		    return;
		}
	    } else {
		set first [$hd.key.ki.pos.firstent get];
		set last  [$hd.key.ki.pos.lastent  get];
		if { ([string equal $first ""] == 0) && ([string equal $last "" ] == 0)} {
		    lappend cl "-e"
		    lappend cl [format "%d,%d" $first $last]
		} else {
		    ShowMessage [format [_ "No character range has been specified for key %d"] $i];
		    return;
		}
	    }
	}
	lappend cl "-c";
	switch -- $::KeyInfo(SortType,$hd) {
	    1 {
		lappend cl "l";
	    }
	    2 {
		lappend cl "s";
	    }
	    3 {
		lappend cl "n";
		lappend cl "-y"
		lappend cl $::KeyInfo(NumberSystem,$hd)
	    }
	    4 {
		lappend cl "t";
	    }
	    5 {
		lappend cl "d";
		lappend cl "-f";
		lappend cl $::KeyInfo(DateFormat,$hd);
	    }
	    6 {
		lappend cl "i";
	    }
	    7 {
		lappend cl "h";
	    }
	    8 {
		lappend cl "r";
	    }
	    9 {
		lappend cl "a";
	    }
	    10 {
		lappend cl "N";
	    }
	    11 {
		lappend cl "m";
	    }
	    12 {
		lappend cl "D";
	    }
	}
	if { ($::KeyInfo(StripDiacriticsP,$hd)) || \
		 ($::KeyInfo(ConvertEnclosuresP,$hd)) || \
		 ($::KeyInfo(ConvertStylisticP,$hd)) } {
	    lappend cl "-T"
	    set arg "";
	    if {$::KeyInfo(StripDiacriticsP,$hd)} {
		append arg d
	    }
	    if {$::KeyInfo(ConvertEnclosuresP,$hd)} {
		append arg e
	    }
	    if {$::KeyInfo(ConvertStylisticP,$hd)} {
		append arg s
	    }
	    lappend cl $arg
	}
	if {$::KeyInfo(FoldCaseP,$hd)} {
	    set type $::KeyInfo(SortType,$hd)
	    if { ($type == 1) || ($type == 2) || ($type ==7)} {
		lappend cl "-C"
	    } else {
		ShowMessage [_ "Case-folding is not compatible with this comparison type."]
	    }
	}
	if {$::KeyInfo(FirstCharOnlyP,$hd)} {
	    set type $::KeyInfo(SortType,$hd)
	    if {$type == 1} {
		lappend cl "-A"
	    } else {
		ShowMessage [_ "Use of only the first character is not compatible with this comparison type."]
	    }
	}
	if {$::KeyInfo(TurkicFoldCaseP,$hd)} {
	    set type $::KeyInfo(SortType,$hd)
	    if { ($type == 1) || ($type == 2) || ($type ==7)} {
		lappend cl "-z"
	    } else {
		ShowMessage [_ "Case-folding is not compatible with this comparison type."]
	    }
	}
	if {$::KeyInfo(ReverseKeyP,$hd)} {
	    if {$::KeyInfo(SortType,$hd) == 1} {
		lappend cl "-R"
	    }
	}
	if {$::KeyInfo(LocalInversionP,$hd)} {
	    lappend cl "-i"
	}
	if {$::KeyInfo(OptionalP,$hd)} {
	    lappend cl "-o";
	    switch -- $::KeyInfo(OptComp,$hd) {
		-1 {lappend cl "l"}
		 0 {lappend cl "e"}
		 1 {lappend cl "g"}
	    }
	}
	set f [GetSortOrderSeparatorFile $hd];
	if {[string equal $f ""] ==0} {
	    lappend cl "-W"
	    lappend cl $f;
	}
	set f [GetExclusionFile $hd];
	if {[string equal $f ""] ==0} {
	    lappend cl "-x"
	    lappend cl $f;
	}
	set f [GetSubstitutionFile $hd];
	if {[string equal $f ""] ==0} {
	    lappend cl "-S"
	    lappend cl $f;
	}
	switch -exact -- $::KeyInfo(SortOrderSpecType,$hd) {
	    1 {
		set l [GetLocale $hd];
		lappend cl "-s"
		lappend cl $l;
	    }
	    2 {
		set f [GetSortOrderFile $hd];
		lappend cl "-s"
		lappend cl $f;
	    }
	}
    }
    lappend cl "<";
    set inf [.gen.ctr.if.ent get]
    if {[string equal $inf ""]} {
	ShowMessage [_ "No input file has been specified. You must supply one."]
	return "err";
    }
    if {[file exists $inf] == 0} {
	ShowMessage [format [_ "Input file \`%s\' does not exist."] $inf]
	return "err";
    }
    if {[file readable $inf] == 0} {
	ShowMessage [format [_ "Input file \`%s\' is not readable."] $inf]
	return "err";
    }
    lappend cl $inf;
    set outf [.gen.ctr.of.ent get]
    if {[string equal $outf ""]} {
	ShowMessage [_ "No output file has been specified. You must supply one."]
	return "err";
    }
    if {[file exists $outf]} {
	if {[file writable $outf] == 0} {
	    ShowMessage [format [_ "Output file \`%s\' is not writable."] $outf]
	    return "err";
	}
    }
    return [join $cl]; 
}


#Returns a list containing the record count and the number of comparisons.
proc GetLogInfo {} {
    if {[catch {open "msort.log" "r"} mlh ] != 0} {
	ShowMessage [_ "Mysterious failure to open msort log file."];
	return -1;
    }
    set LineCount 0;
    while { [gets $mlh line] >= 0} {
	incr LineCount;
	lappend log $line;
    }
    if {$LineCount < 1} {
	error;
    }
    set Penult [lindex $log [expr $LineCount -2]];
    if {[scan $Penult "Records written:[ ]%s" Records] < 1} {
	ShowMessage [_ "Unable to obtain record count from msort log."]
	set Records -1;
    }
    set Antepenult   [lindex $log [expr $LineCount -3]];
    if {[scan $Antepenult "\tComparisons:[ ]%s" Comparisons] < 1} {
	ShowMessage [_ "Unable to obtain comparison count from msort log."]
	set Comparisons -1;
    }
    set Preantepenult   [lindex $log [expr $LineCount -4]];
    if {[scan $Preantepenult "\tRandom number generator seed:[ ]%s" RandomSeed] < 1} {
	ShowMessage [_ "Unable to obtain random number generator seed from msort log."]
    } else {
	set ::Opts(RandomSeed) $RandomSeed
    }

    close $mlh;
    return [list [string trim $Records] [string trim $Comparisons]];
}

set ElapsedTime 0;
set StdoutResult "";
proc MsortPipeEvent {PipeHandle Start} {
    global ElapsedTime
    global StdoutResult
    if {[eof $PipeHandle]} {
	set ElapsedTime [expr {[clock seconds] - $Start}]
	catch {[close $PipeHandle]};
    } else {
	set StdoutResult [read $PipeHandle]
    }
}


set msortpid 0;
proc ExecuteMsort {} {
    set ::SortAbortedP 0;
    ClearMessageWindow;
    file delete msort.log
    set cl [ConstructCommandLine]
    if {[string match msort* $cl] == 0} {
	if {[string equal $cl ""]} {
	    ShowMessage [_ "Obligatory information is missing: cannot sort."];
	}
	return ;
    }
    set cl [split $cl];
    lappend cl "2>"
    lappend cl "/dev/null"
    set ::SortInProgressP 1;
    set StartTime [clock seconds]
    set ::LastExecutionTime  $StartTime;
    catch {open "|$cl" "r"} PipeID;
    fileevent $PipeID readable [list MsortPipeEvent $PipeID $StartTime]
    set ::msortpid [lindex [pid $PipeID] 0]
    tkwait variable ::ElapsedTime;
    set ::SortInProgressP 0;
    if {$::SortAbortedP} {return}
    catch {GetLogInfo} LogInfo;
    if {[info exists LogInfo]} {
	set Records [lindex $LogInfo 0];
	set Comparisons  [lindex $LogInfo 1];
    } else {
	set Records -1;
	set Comparisons -1;
    }
    set msg "";
    if {$Records >= 0} {
	lappend msg [format [_ "Records: %s"] $Records];
	if {$Comparisons >= 0} {
	    lappend msg [format [_ "  Comparisons: %s"] $Comparisons];
	}
    }
    lappend msg [format [_ "  Elapsed time: %d seconds"] $::ElapsedTime];
    if {[string equal $::errorCode "NONE"] == 0} {
	set spec [split $::errorCode]
	switch -exact -- [lindex $spec 0] {
	    CHILDSTATUS {
		set MsortErrorCode [lindex $spec 2];
		lappend msg [_ $::MsortErrors($MsortErrorCode)];
	    }
	    POSIX {
		lappend msg [lindex $spec 2]
	    }
	}
    }
    ShowMessage [join $msg];
    set OutputFile [.gen.ctr.of.ent get];
    if {[catch {open $OutputFile "w"} OutputHandle ] != 0} {
	ShowMessage [format [_ "Unable to open file %s."] $OutputFile];
	return ;
    }
    puts -nonewline $OutputHandle $::StdoutResult
    close $OutputHandle;
}

proc ExplicateErrorStatus {} {
    global FeatureTestDebugP;
    global FeatureTestLogHandle;
    switch -exact -- [lindex $::errorCode 0] {
	CHILDKILLED {
	    foreach { - pid sigName msg } $::errorCode break
	    if {$FeatureTestDebugP} {
		puts $FeatureTestLogHandle [format "Child process %d died on signal %s" $pid $sigName];
		puts $FeatureTestLogHandle [format "Error message: %s" $msg];
	    }
	}
	CHILDSTATUS {
	    foreach { - pid code } $::errorCode break
	    if {$FeatureTestDebugP} {
		puts $FeatureTestLogHandle [format "Child process %d exited with error code %d" $pid $code];
	    }
	}
	CHILDSUSP {
	    foreach { - pid sigName msg } $::errorCode break
	    if {$FeatureTestDebugP} {
		puts $FeatureTestLogHandle [format "Child process %d has been suspended due to signal %d" $pid $sigName];
		puts $FeatureTestLogHandle [format "Error message: %s" $msg];
	    }
	}
	POSIX {
	    foreach { - errName msg } $::errorCode break
	    if {$FeatureTestDebugP} {
		puts $FeatureTestLogHandle [format "One of the kernel calls to launch the command failed ith error code %d" $code];
		puts $FeatureTestLogHandle [format "Error message: %s" $msg];
	    }
	}
    }
}


array set MsortErrors {
    1 "Failed to open file"\
    2 "I/o error"\
    3 "Not really an error - provided information"\
    4 "Limit exceeded"\
    5 "Command line option not recognized"\
    6 "Invalid argument to command line option"\
    7 "Out of memory"\
    8 "Ill-formed record"\
    9 "Other error"
}

proc AbortSort {} {
    if {$::SortInProgressP} {
	if {[string equal $::System MSWindows] == 0} {
	    catch {[exec kill -9 $::msortpid]}
	    set ::SortAbortedP 1;
	    ShowMessage [_ "Sort aborted."]
	} else {
	    ShowMessage [_ "Sorry, this must be an MS Windows system."];
	}
    } else {
	ShowMessage [_ "No sort is in progress."]
    }
}

proc SaveCommandLine {} {
    set cl [ConstructCommandLine];
    if {[string match msort* $cl] == 0} {
	if {[string equal $cl ""]} {
	    ShowMessage [_ "Failed to construct command line."]
	}
	return ;
    }
    set outf [.gen.ctr.of.ent get]
    set cl [split $cl];
    lappend cl ">"
    lappend cl $outf 
    set cl [join $cl];
    set SaveFile [tk_getSaveFile -initialfile [_ "SavedMsortCommandLine"]];
    if {$SaveFile == ""} {
	ShowMessage [_ "File selection cancelled."]
	return ;
    }
    if {[catch {open $SaveFile "w"} SaveHandle ] != 0} {
	ShowMessage [format [_ "Unable to open file %s."] $SaveFile];
	return ;
    }
    puts $SaveHandle $cl;
    close $SaveHandle;
    set ::LastCommandLineSaveTime  [clock seconds];
}

proc ShowCommandLine {} {
    set cl [ConstructCommandLine];
    if {[string match msort* $cl] == 0} {
	if {[string equal $cl ""]} {
	    ShowMessage [_ "Failed to construct command line."]
	}
	return ;
    } else {
	set outf [.gen.ctr.of.ent get]
	set cl [split $cl];
	lappend cl ">"
	lappend cl $outf 
	ShowMessage [join $cl];
    }
}

proc InsertClipboardContents {w} {
    set sel "";
    if {[catch {set sel [selection get -selection CLIPBOARD -type UTF8_STRING]}]} {
	ShowMessage [_ "The clipboard is empty."];
	return;
    } else {
	$w insert insert $sel;
    }
}

#If the filename passed as argument is a pathname
#leading to a file in the current working directory,
#return just the basename+extension. Otherwise
#return the argument.
proc MinimizeFileName {s} {
    set cwd [pwd];
    set sdir [file dirname $s]
    if {[string equal $cwd $sdir]} {
	return [file tail $s]
    } else {
	return $s;
    }
}


proc SelectInputFile {} {
    set InputFile [tk_getOpenFile];
    if {$InputFile == ""} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	.gen.ctr.if.ent delete 0 end
	.gen.ctr.if.ent insert 0 [MinimizeFileName $InputFile]
    }
}

proc SelectOutputFile {} {
    set OutputFile [tk_getSaveFile -initialfile [_ "SortOutput"]];
    if {$OutputFile == ""} {
	ShowMessage [_ "File selection aborted."]
	return
    } else { 
	.gen.ctr.of.ent delete 0 end
	.gen.ctr.of.ent insert 0 [MinimizeFileName $OutputFile]
    }
}

array set DefaultKeyBindings {
"<Control-c>" 		  AbortSort
"<Control-d>"             ToggleIPAD
"<Control-b>" 		  ToggleBalloonHelp
"<Control-j>"             ToggleIPAC
"<Control-k>"             DescribeKeyBindings
"<Control-w>"             ToggleIPAV
};

if {[string equal $tcl_platform(platform) "unix"]} {
    set DefaultKeyBindings(<Control-c>) AbortSort;
}

proc SetCommandGlosses {} {
    global CommandGlosses;

    set Pairs [list\
	   AbortSort "[_ "Abort the currently running msort job"]"\
	   ToggleIPAC "[_ "Toggle the IPA consonant entry widget."]"\
	   ToggleIPAV "[_ "Toggle the IPA vowel entry widget."]"\
		   ToggleBalloonHelp "[_ "Toggle Balloon Help"]"\
	   DescribeKeyBindings "[_ "Toggle Key Binding Help"]"\
	   ToggleIPAD "[_ "Toggle the IPA diacritic entry widget."]"]
    array set CommandGlosses $Pairs;
}

proc BindKeys {w {bl DefaultKeyBindings}} {
    upvar \#0 $bl kb;
    foreach KeySeq [array names kb] {
	bind $w $KeySeq $kb($KeySeq);
    }
}

proc DescribeKeyBindings {{bl DefaultKeyBindings}} {
    global CommandGlosses;
    upvar \#0 $bl kb;

    if {[PopupDown KeyBindings] ==1} {return}
    set po [CreateTextDisplay [_ "Key Bindings"] 88 6]
    BindKeys $po;
    set ::PopupList(KeyBindings) $po;

    #Invert array and get maximum length of gloss while we are at it.
    set MaxGlossLength 0;
    foreach KeySeq [array names kb] {
	set Gloss $CommandGlosses($kb($KeySeq));
	set GlossLength [string length $Gloss];
	if {$MaxGlossLength < $GlossLength} {set MaxGlossLength $GlossLength}
	set GlossToKeySeq($Gloss) $KeySeq;
    }
    #Now generate entries in alphabetical order of command glosses
    foreach Gloss [lsort [array names GlossToKeySeq]] {
	AppendToTextDisplay $po [format "%-*s\t%s\n" $MaxGlossLength $Gloss $GlossToKeySeq($Gloss)];
    }
}

set bhInfo(active) 1
proc balloonhelp_control {state} {
     global bhInfo
     if {$state} {
          set bhInfo(active) 1
     } else {
	balloonhelp_cancel
	set bhInfo(active) 0
     }
}

proc balloonhelp_for {win mesg} {
    global bhInfo
    set bhInfo($win) $mesg
    set ::bhOverlapP($win) 1; 
    bind $win <Enter> {+balloonhelp_pending %W}
    bind $win <Leave> {+balloonhelp_cancel}
}

proc balloonhelpd_for {win mesg} {
    global bhInfo
    set ::bhOverlapP($win) 0;
    set bhInfo($win) $mesg
    bind $win <Enter> {+balloonhelp_show %W}
}

proc balloonhelp_pending {win} {
     global bhInfo
     balloonhelp_cancel
     set bhInfo(pending) [after 1000 [list balloonhelp_show $win]]
}

proc balloonhelp_cancel {} {
    global bhInfo
    if { [info exists bhInfo(pending)]} {
	after cancel $bhInfo(pending)
	unset bhInfo(pending)
    }
    if {[winfo exists .balloonhelp]} {
	wm withdraw .balloonhelp
    }
}

proc balloonhelp_show {win} {
    global bhInfo;
    global bhOverlapP;
    if {$bhOverlapP($win)} {
	set Overlap 25;
    } else {
	set Overlap -10;
    }
    if {[winfo exists $win]} {
	if {$bhInfo(active)} {
	    .balloonhelp.info configure -text $bhInfo($win)
	    #Set abcissa
	    set MaxStringWidth 0;
	    foreach line [split $bhInfo($win) "\n"] {
		set StringWidth [font measure BalloonHelpFont -displayof .balloonhelp.info $line]
		if {$StringWidth > $MaxStringWidth} {
		    set MaxStringWidth $StringWidth;
		}
	    }
	    set ScreenWidth [winfo screenwidth $win]
	    set Width [winfo width $win];
	    set LeftEdge  [winfo rootx $win];
	    set RightEdge [expr $LeftEdge + $Width];
	    if {$ScreenWidth - $RightEdge < $MaxStringWidth} { 
		if {$LeftEdge > $MaxStringWidth} {
		    set x [expr $LeftEdge - $MaxStringWidth + $Overlap];
		} else {
		    if {$ScreenWidth - $MaxStringWidth > 0} {
			set x [expr $RightEdge - $MaxStringWidth];
		    } else {
			set x [expr $ScreenWidth - $MaxStringWidth];
		    }
		}
	    } else {
		set x [expr $RightEdge - $Overlap];
	    }
	    #Set ordinate
	    set Height [winfo height $win];
	    set TopEdge [winfo rooty $win];
	    set y [expr $TopEdge + ($Height/2)];
	    wm geometry .balloonhelp +$x+$y
	    wm deiconify .balloonhelp
	    raise .balloonhelp
	}
    }
    if {[info exist bhInfo(pending)]} {
	unset bhInfo(pending)
    }
}

proc ToggleBalloonHelp {} {
    global BalloonHelpP;
    global BalloonHelpIndex;
    global m;

    if {$BalloonHelpP} {
	set BalloonHelpP 0;
	balloonhelp_control 0
	ShowMessage [_ "Irritating Balloon Help Disabled"];
	$m.configure entryconfigure $BalloonHelpIndex -label [_ "Enable Balloon Help"];
    } else {
	set BalloonHelpP 1;
	balloonhelp_control 1
	ShowMessage [_ "Balloon Help Enabled"];
	$m.configure entryconfigure $BalloonHelpIndex -label [_ "Disable Irritating Balloon Help"];
    }
}

proc new_dialog_create {class {win "auto"}} {
    if {$win == "auto"} {
        set count 0
        set win ".ndialog[incr count]"
        while {[winfo exists $win]} {
            set win ".ndialog[incr count]"
        }
    }
    toplevel $win -class $class;
    frame $win.info
    pack $win.info -expand yes -fill both -padx 4 -pady 4
    wm title $win $class
    wm group $win .

    after idle [format {
        update idletasks
        wm minsize %s [winfo reqwidth %s] [winfo reqheight %s]
    } $win $win $win]

    return $win
}

# The following code is taken from the Efftcl library by Mark Harrison and
# Michael McLennan, copyrighted by Mark Harrison and Lucent Technologies, available
# from http://www.awprofessional.com/content/images/0201634740/sourcecode/efftcl.zip.
# As the authors explicitly give permission to "steal the code for your own applications"
# the relevant portions are included here so as not to require the user to install
# to install the library. If you install the library, remove the following and
# uncomment the line "#package require Efftcl" by deleting the crosshatch.

#  Effective Tcl/Tk Programming
#    Mark Harrison, DSC Communications Corp.
#    Michael McLennan, Bell Labs Innovations for Lucent Technologies
#    Addison-Wesley Professional Computing Series
# ======================================================================
#  Copyright (c) 1996-1997  Lucent Technologies Inc. and Mark Harrison
# ======================================================================

proc dialog_create {class {win "auto"}} {
    if {$win == "auto"} {
        set count 0
        set win ".dialog[incr count]"
        while {[winfo exists $win]} {
            set win ".dialog[incr count]"
        }
    }
    toplevel $win -class $class -background \#2200DD;

    frame $win.info
    pack $win.info -expand yes -fill both -padx 4 -pady 4
    frame $win.sep -height 2 -borderwidth 1 -relief sunken
    pack $win.sep -fill x -pady 4
    frame $win.controls
    pack $win.controls -fill x -padx 4 -pady 1

    wm title $win $class
    wm group $win .

    after idle [format {
        update idletasks
        wm minsize %s [winfo reqwidth %s] [winfo reqheight %s]
    } $win $win $win]

    return $win
}

proc dialog_info {win} {
    return "$win.info"
}

proc dialog_controls {win} {
    return "$win.controls"
}

proc dialog_wait {win varName} {
    dialog_safeguard $win

    set x [expr [winfo rootx .]+50]
    set y [expr [winfo rooty .]+50]
    wm geometry $win "+$x+$y"

    wm deiconify $win
    grab set $win

    vwait $varName

    grab release $win
    wm withdraw $win
}

bind modalDialog <ButtonPress> {
    wm deiconify %W
    raise %W
}
proc dialog_safeguard {win} {
    if {[lsearch [bindtags $win] modalDialog] < 0} {
        bindtags $win [linsert [bindtags $win] 0 modalDialog]
    }
}

proc CreateTextDisplay {title width height {bg "\#96C4A3"} {fg "\#000000"} } {
    set top [new_dialog_create Textdisplay]
    wm title $top $title
    set info [dialog_info $top]
    scrollbar $info.sbar -command "$info.text yview" 
    bind $info.sbar <<B3>> "ScrollbarMoveBigIncrement $info.sbar 0.20 %x %y"
    pack $info.sbar -side right -fill y
    text $info.text -height $height -width $width -font UserTechnicalTextFont \
	-wrap word -yscrollcommand "$info.sbar set"  \
	-background $bg -foreground $fg -exportselection 1;
    pack $info.text -side left -expand yes -fill both
    $info.text configure -state disabled
    return $top
}

proc AppendToTextDisplay {top mesg} {
    set info [dialog_info $top]
    $info.text configure -state normal
    $info.text insert end $mesg
    $info.text configure -state disabled
}

set linkNum 0;
proc AppendLinkToTextDisplay {top mesg LinkCode} {
    global linkNum
    set info [dialog_info $top]
    $info.text configure -state normal
    set tag "link[incr linkNum]"
    bind $info.text <ButtonPress> break
    $info.text insert end $mesg [list body $tag]
    $info.text tag configure $tag -foreground red -underline 1
    $info.text tag bind $tag <Enter> \
        "$info.text tag configure $tag -foreground blue"
    $info.text tag bind $tag <Leave> \
        "$info.text tag configure $tag -foreground red"
    $info.text tag bind $tag <ButtonPress> \
        "$LinkCode"
    $info.text configure -state disabled
}

proc About {} {
    global Version;
    global PackageVersion;
    if {[PopupDown About] ==1} {return}
    set po [CreateTextDisplay [_ "About"] 55 8];
    BindKeys $po
    set ::PopupList(About) $po
    AppendToTextDisplay $po [format [_ "This is msg version %s."] $Version];
    AppendToTextDisplay $po [format [_ " It is part of the msort package, version %s."] $PackageVersion];
    AppendToTextDisplay $po " It is a graphical front end to Msort, a sophisticated sorting program. In order for it to be of any use, you must have Msort installed.";
    AppendToTextDisplay $po " You can obtain both Msort and Msg from:\n";
    AppendLinkToTextDisplay $po "http://www.billposer.org/Software/msort.html" {ShowWebPage http://www.billposer.org/Software/msort.html};
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po "Both programs were written by Bill Poser (billposer@alum.mit.edu).";
    AppendToTextDisplay $po "\n";
}

proc BugReports {} {
    global Version;
    global tcl_platform;

    if {[PopupDown BugReports] ==1} {return}
    set po [CreateTextDisplay [_ "Bug Reports"] 50 21];
    BindKeys $po
    set ::PopupList(BugReports) $po
    AppendToTextDisplay $po [_ "Report bugs to: billposer@alum.mit.edu.\n"];
    AppendToTextDisplay $po [_ "Please include the following information:\n\n"];
    AppendToTextDisplay $po [_ "\tWhat version of the program are you using?\n"];
    AppendToTextDisplay $po [format [_ "\t\t(This is version %s.)\n\n"] $Version];
    AppendToTextDisplay $po [_ "\tWhat version of msort are you using?\n"];
    AppendToTextDisplay $po [format [_ "\t\t(Version located: %s.)\n\n"] [FindoutMsortVersion]];
    AppendToTextDisplay $po [_ "\tWhat operating system are you running?.\n"];
    set OS $tcl_platform(os);
    if {$OS == "Linux"} {set OS "GNU/Linux"};
    AppendToTextDisplay $po [format [_ "\t\t(This is %s  %s.)\n\n"] $OS  $tcl_platform(osVersion)];
    AppendToTextDisplay $po [_ "\tWhat window system are you using?.\n"];
    AppendToTextDisplay $po [format [_ "\t\t(This is %s.)\n\n"] $::WindowSystem]
    AppendToTextDisplay $po [_ "\tWhat version of tcl/tk are you using?.\n"];
    AppendToTextDisplay $po [format [_ "\t\t(This is version %s.)\n\n"] [info patchlevel]];
    AppendToTextDisplay $po [_ "Bug reports may be sent in any language that I can read without too much trouble or am trying to learn or improve. These include:\n\n"];
    AppendLinkToTextDisplay $po [_ "\tCatalan"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=cat};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tDakelh (Carrier)"] {ShowWebPage http://ydli.org}
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tDutch"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=nld};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tEnglish"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=eng};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tEsperanto"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=epo};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tFrench"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=fra};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tGerman"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=deu};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tItalian"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=ita};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tJapanese"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=jpn};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tKazakh"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=kaz};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tKorean"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=kor};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tLatin"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=lat};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tPanjabi"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=pan};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tPortuguese"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=por};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tSpanish"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=spa};
    AppendToTextDisplay $po "\n";
    AppendLinkToTextDisplay $po [_ "\tTurkish"] {ShowWebPage http://www.ethnologue.com/show_language.asp?code=tur};
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po "Please note that in many cases although I can understand the language my ability to respond in it may be limited.\n";
    AppendToTextDisplay $po "\n";
}

proc HowTo {} {
    if {[PopupDown HowTo] ==1} {return}
    set po [CreateTextDisplay [_ "HowTo"] 55 20];
    BindKeys $po
    set ::PopupList(HowTo) $po
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "This program provides a graphical interface to msort, a sophisticated and flexible sorting program. It helps you to choose the right options to obtain the output that you desire. For full details,
see the Msort Reference Manual, which provides a description of the sorting process as well as details of the program.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "The display consists of a number of regions. The first few are the same on every page. At the top (unless you are using a Macintosh) is the menubar. Next (or first, on a Macintosh) comes the Message REgion. This is where Msg prints messages to you. Immediately below the Message Region is a row of two or more buttons used to select the page to work on. What follows depends on whether you are working on the General page or on a key-specific page.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "Msg provides two kinds of pages. The first page that you see is for general settings, that is, settings that are not particular to a specific key. You can always get back to this page by clicking on the General button in the region just below the message region. The General button is always the leftmost button. Following the General button are one or more buttons labelled with key numbers, e.g. \`Key 1\'. When Msg starts up, one such button is already present since you cannot sort without at least one key. If you need to use more than one key, you can add key pages by clicking on the Add Key button in the menubar. If you decide that you don't need that many keys, you can remove keys by clicking on the Remove Last Key button. You can tell which key you are working on by looking at the label on the highlighted page selection button.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "The General page is used to set parameters that are not key-specific. You must provide the name of the input file (the file whose contents you wish to sort) and the name of the file in which to put the results of the sort. You must also decide how the input is to be divided into records and how each record is to be divided into fields. This page also provides the option of inverting the overall order of the output.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "The key-specific pages allow you to specify how to locate the field that contains the key and to determine various details of the sort, such as what sort order to use and whether to sort lexicographically or numerically. Msort provides a number of useful but unusual options, so you may wish to explore what it provides.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "Information about particular aspects of a page comes in two main forms. First, if you leave the mouse pointer over a region for a short time, a help balloon will pop up. Help balloons provide a short explanation of the function of the region. (Once you are familiar with the program, you may find help balloons irritating. You can disable them by means of a command on the Help menu.) Second, in many cases more detailed information is available by clicking the right mouse button. (On a MacIntosh, clicking while depressing the Control key should be equivalent.) Right-clicking again in the same region will remove the popup.\n"];
    AppendToTextDisplay $po "\n";
    AppendToTextDisplay $po [_ "When you have set the necessary parameters, you can execute the sort by pressing the sort button on the menubar. If you are familiar with the msort command line, you can see what command Msg will execute by selecting the command Show Command Line on the File menu. If you want to save the command line for future use, you can copy it to a file by selecting the command Save Command Line from the File Menu.\n"];
    AppendToTextDisplay $po "\n";
}

proc ShowGPL {} {
    if {[PopupDown ShowGPL] ==1} {return}
    set po [CreateTextDisplay [_ "License"] 70 24]
    set ::PopupList(ShowGPL) $po;
    BindKeys $po;
    AppendToTextDisplay $po [format "%s%s" [format "%s\n\t%s\n" [_ "For this license in your language see:"] [_ "http://www.gnu.org/copyleft/gpl.html"]]  "\
\

		    GNU GENERAL PUBLIC LICENSE\

                       Version 3, 29 June 2007\


 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
\

                            Preamble
\

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.
\

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.
\

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
\

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
\

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.
\

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
\

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
\

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
\

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
\

  The precise terms and conditions for copying, distribution and
modification follow.
\

                       TERMS AND CONDITIONS
\

  0. Definitions.
\

  \"This License\" refers to version 3 of the GNU General Public License.
\

  \"Copyright\" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
\

  \"The Program\" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as \"you\".  \"Licensees\" and
\"recipients\" may be individuals or organizations.
\

  To \"modify\" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a \"modified version\" of the
earlier work or a work \"based on\" the earlier work.
\

  A \"covered work\" means either the unmodified Program or a work based
on the Program.
\

  To \"propagate\" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
\

  To \"convey\" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
\

  An interactive user interface displays \"Appropriate Legal Notices\"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
\

  1. Source Code.
\

  The \"source code\" for a work means the preferred form of the work
for making modifications to it.  \"Object code\" means any non-source
form of a work.
\

  A \"Standard Interface\" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
\

  The \"System Libraries\" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
\"Major Component\", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
\

  The \"Corresponding Source\" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
\

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
\

  The Corresponding Source for a work in source code form is that
same work.
\

  2. Basic Permissions.
\

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
\

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
\

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.
\

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
\

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
\

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
\

  4. Conveying Verbatim Copies.
\

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
\

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
\

  5. Conveying Modified Source Versions.
\

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
\

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.
\

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    \"keep intact all notices\".
\

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.
\

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.
\

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
\"aggregate\" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
\

  6. Conveying Non-Source Forms.
\

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
\

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.
\

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.
\

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.
\

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.
\

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.
\

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
\

  A \"User Product\" is either (1) a \"consumer product\", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, \"normally used\" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
\

  \"Installation Information\" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
\

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
\

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
\

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
\

  7. Additional Terms.
\

  \"Additional permissions\" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
\

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
\

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
\

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or
\

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or
\

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or
\

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or
\

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or
\

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.
\

  All other non-permissive additional terms are considered \"further
restrictions\" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
\

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
\

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
\

  8. Termination.
\

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
\

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
\

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
\

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
\

  9. Acceptance Not Required for Having Copies.
\

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
\

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.
\

  An \"entity transaction\" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
\

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
\

  11. Patents.
\

  A \"contributor\" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's \"contributor version\".
\

  A contributor's \"essential patent claims\" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, \"control\" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
\

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
\

  In the following three paragraphs, a \"patent license\" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To \"grant\" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
\

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  \"Knowingly relying\" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
\

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
\

  A patent license is \"discriminatory\" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
\

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
\

  12. No Surrender of Others' Freedom.
\

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
\

  13. Use with the GNU Affero General Public License.
\

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
\

  14. Revised Versions of this License.
\

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
\

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License \"or any later version\" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
\

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
\

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
\

  15. Disclaimer of Warranty.
\

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
\

  16. Limitation of Liability.
\

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
\

  17. Interpretation of Sections 15 and 16.
\

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
"]
}

set MainKeyFieldIdentBH [_ "How is the field used for this key identified? One possibility\nis by its position in the record. A second is by tag, that is,\na sequence of characters with which the field begins. The third\nis by a range of characters, that is, the characters in certain\npositions constitute the key."]
set DisabledKeyFieldIdentBH [_ "This area is used to specify how to select the key field.\nIt is currently disabled since you have chosen\nto use the entire record as the sort key."] 

proc DisableKeyFieldID {hd} {
    $hd.key.ki.pos.rdb1 configure -state disabled
    $hd.key.ki.pos.rdb2 configure -state disabled
    $hd.key.ki.pos.rdb3 configure -state disabled
    $hd.key.ki.pos.posent.fldent1 configure -state disabled
    $hd.key.ki.pos.tagent configure -state disabled
    $hd.key.ki.pos.firstent configure -state disabled
    $hd.key.ki.pos.lastent configure -state disabled
    balloonhelp_for $hd.key.ki $::DisabledKeyFieldIdentBH;
    balloonhelp_for $hd.key.ki.pos.posent.fldent1 $::DisabledKeyFieldIdentBH;
    balloonhelp_for $hd.key.ki.pos.tagent $::DisabledKeyFieldIdentBH;
    balloonhelp_for $hd.key.ki.pos.firstent $::DisabledKeyFieldIdentBH;
    balloonhelp_for $hd.key.ki.pos.lastent $::DisabledKeyFieldIdentBH;
}

proc EnableKeyFieldID {hd} {
    $hd.key.ki.pos.rdb1 configure -state normal
    $hd.key.ki.pos.rdb2 configure -state normal
    $hd.key.ki.pos.rdb3 configure -state normal
    balloonhelp_for $hd.key.ki $::MainKeyFieldIdentBH;
    balloonhelp_for $hd.key.ki.pos.rdb1 [_ "A position specification consists of a single position or\na contiguous range of positions specified by their beginning\nand end. A position consists of a field number together with\na character offset. Field numbers, but not character offsets,\nmay be negative, in which case the count is from the right."]
    balloonhelp_for $hd.key.ki.pos.posent.fldent1 [_ "Enter the field number here."]
    balloonhelp_for $hd.key.ki.pos.posent.fldent2 [_ "Enter the field number here."]
    balloonhelp_for $hd.key.ki.pos.posent.chrent1 [_ "Enter the character offset here."]
    balloonhelp_for $hd.key.ki.pos.posent.chrent2 [_ "Enter the character offset here."]
    balloonhelp_for $hd.key.ki.pos.tagent [_ "Enter the tag regular expression here."]
    balloonhelp_for $hd.key.ki.pos.firstent [_ "Enter the index of the first character in the range\n(starting from 1) here. Negative numbers may be used\nto count from the end."]
    balloonhelp_for $hd.key.ki.pos.lastent [_ "Enter the index of the last character in the range\n(starting from 1) here. Negative numbers may be used\nto count from the end."]
 }

proc PackGen {} {

    set genxpadl {12 8}
    set genxpadr {8 12}
    set genypadi 5
    set genypadt {8 5}
    set genypadb {5 8}

    grid forget .gen.ctr.rp
    grid forget .gen.ctr.wr
    grid forget .gen.ctr.parckb
    grid forget .gen.ctr.gi
    grid forget .gen.ctr.eol
    grid forget .gen.ctr.miscckb
    grid forget .gen.ctr.bmp
    grid forget .gen.ctr.pua
    grid forget .gen.ctr.un
    grid forget .gen.ctr.unickb
    grid forget .gen.ctr.rns
    grid forget .gen.ctr.rnsckb
    grid forget .gen.ctr.al
    grid forget .gen.ctr.alckb
    grid forget .gen.ctr.if
    grid forget .gen.ctr.of

    grid forget .gen.ctr.parf
    grid forget .gen.ctr.miscf
    grid forget .gen.ctr.alf
    grid forget .gen.ctr.unif
    grid forget .gen.ctr.rnsf
    grid forget .gen.ctr.iff
    grid forget .gen.ctr.off

    set Row 0;

    if {$::RecordParseDisplayedP} {
	grid .gen.ctr.rp  -row $Row -column 0 -sticky wens -pady $genypadt -padx $genxpadl
	grid .gen.ctr.wr  -row $Row -column 1 -sticky wens -pady $genypadt -padx $genxpadr
	grid .gen.ctr.parckb -row $Row -column 2 -sticky e -pady $genypadb -padx $genxpadl
    } else {
	grid .gen.ctr.parf -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row
 
    if {$::UnicodeDisplayedP} {
	grid .gen.ctr.bmp -row $Row -column 0 -sticky wens -pady $genypadi -padx $genxpadl
	grid .gen.ctr.pua -row $Row -column 1 -sticky wens -pady $genypadi -padx $genxpadr
	grid .gen.ctr.unickb -row $Row -column 2 -sticky e -pady $genypadb -padx $genxpadl
    } else {
	grid .gen.ctr.unif -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row

    if {$::AlgorithmDisplayedP} {
	grid .gen.ctr.al  -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl
	grid .gen.ctr.un  -row $Row -column 1 -sticky wens -pady $genypadi -padx $genxpadr
	grid .gen.ctr.alckb -row $Row -column 2 -sticky e -pady $genypadb -padx $genxpadl
    } else {
	grid .gen.ctr.alf -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row

    if {$::MiscOptionsDisplayedP} {
	grid .gen.ctr.gi  -row $Row -column 0 -sticky wens -pady $genypadi -padx $genxpadl
	grid .gen.ctr.eol -row $Row -column 1 -sticky wens -pady $genypadi -padx $genxpadr
	grid .gen.ctr.miscckb -row $Row -column 2 -sticky e -pady $genypadb -padx $genxpadl
    } else {
	grid .gen.ctr.miscf -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row

    if {$::RandomNumberSeedDisplayedP} {
	grid .gen.ctr.rns  -row $Row -column 0 -sticky wens -pady $genypadi -padx $genxpadl
	grid .gen.ctr.rnsckb -row $Row -column 2 -sticky e -pady $genypadb -padx $genxpadl
    } else {
	grid .gen.ctr.rnsf -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row

    if {$::InputFileDisplayedP} {
	grid .gen.ctr.if  -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    } else {
	grid .gen.ctr.iff -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    incr Row

    if {$::OutputFileDisplayedP} {
	grid .gen.ctr.of  -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    } else {
	grid .gen.ctr.off -row $Row -column 0 -sticky wens -pady $genypadb -padx $genxpadl \
	    -columnspan 3
    }
    pack  .gen.ctr -side top -expand 1 -fill x -padx 6
    ConfigureGenOne
    ConfigureGenTwo
}

proc OldPackGen {} {
    pack forget .gen.ctr
    pack forget .gen.sep3

    pack  .gen.ctr -side top -expand 1 -fill x -padx 6
    pack  .gen.sep3 -side top -expand 1 -fill x -padx 6
}

proc PackKeyPage {hd} {
    set kpxpd 5
    set kpypd 2
    set kpfypd 4

    pack forget $hd.misco
    pack forget $hd.exc
    pack forget $hd.sub
    pack forget $hd.sos
    pack forget $hd.so
    pack forget $hd.st
    pack forget $hd.key

    pack forget $hd.miscof
    pack forget $hd.excf
    pack forget $hd.subf
    pack forget $hd.sosf
    pack forget $hd.sof
    pack forget $hd.stf
    pack forget $hd.keyf

    if {$::KeyInfo(MiscellaneousOptionsDisplayedP,$hd)} {
	pack $hd.misco -side bottom -expand y -fill x -pady $kpypd -padx $kpxpd
    } else {
	pack $hd.miscof -side bottom -expand y -fill x -pady $kpfypd -padx $kpxpd
    }

    if {$::KeyInfo(SubstitutionsDisplayedP,$hd)} {
	pack $hd.sub -side bottom -expand 0 -fill x -pady $kpypd -padx $kpxpd
    } else {
	pack $hd.subf -side bottom -expand 0 -fill x -pady $kpfypd -padx $kpxpd
    }
    if {$::KeyInfo(ExclusionsDisplayedP,$hd)} {
	pack $hd.exc -side bottom -expand 0 -fill x -pady $kpypd -padx $kpxpd
    } else {
	pack $hd.excf -side bottom -expand 0 -fill x -pady $kpfypd -padx $kpxpd
    }

    if {$::KeyInfo(SortOrderSpecType,$hd) == 2} {
	if {$::KeyInfo(SortOrderDisplayedP,$hd)} {
	    pack $hd.sos   -expand y -fill x -side bottom -pady $kpypd -padx $kpxpd
	}
    }

    set SortType $::KeyInfo(SortType,$hd)
    if {$SortType == 1 || $SortType == 2 || $SortType == 7} {
	if {$::KeyInfo(SortOrderDisplayedP,$hd)} {
	    pack $hd.so  -side bottom -expand 0 -fill both -pady $kpypd -padx $kpxpd
	} else {
	    pack $hd.sof  -side bottom -expand 0 -fill both -pady $kpfypd -padx $kpxpd
	}
    }

    if {$::KeyInfo(SortTypeDisplayedP,$hd)} {
	pack $hd.st  -side bottom -expand 0 -fill both -pady $kpypd -padx $kpxpd
    } else {
	pack $hd.stf  -side bottom -expand 0 -fill both -pady $kpfypd -padx $kpxpd
    }
    if {$::KeyInfo(KeyFieldIdentificationDisplayedP,$hd)} {
	pack $hd.key -side bottom -expand 0 -fill both -pady $kpypd -padx $kpxpd
    } else {
	pack $hd.keyf -side bottom -expand 0 -fill both -pady $kpfypd -padx $kpxpd
    }
}

proc ValidatePositionField {w s type action} {
    if {$s == 0} {
	ShowMessage [_ "There is no field 0."]
	focus $w;
	return 0;
    }
    if {[string equal $type focusout]} { 
	if {[string length $s] == 0} {
	    ShowMessage [_ "You must specify a position."]
	    focus $w;
	    return 0;
	}
	if {![regexp {^-?[[:digit:]]+$} $s]} {
	    ShowMessage [_ "The field number must be an integer."]
	    focus $w;
	    return 0
	}
    }
    if {[string equal $type key]} {
	if {![regexp {^-?[[:digit:]]*$} $s]} {
	    ShowMessage [_ "The field number must be an integer."]
	    focus $w;
	    return 0
	}
    }
    ClearMessageWindow
    return 1;
}

proc ValidatePositionChar {w s type action} {
    if {$s == 0} {
	ShowMessage [_ "There is no character 0."]
	focus $w;
	return 0;
    }
    if {[string equal $type focusout]} { 
	if {[string length $s] == 0} {
	    ShowMessage [_ "You must specify a character offset."]
	    focus $w;
	    return 0;
	}
	if {![regexp {^-?[[:digit:]]+$} $s]} {
	    ShowMessage [_ "The character offset must be a positive integer."]
	    focus $w;
	    return 0
	}
    }
    if {[string equal $type key]} {
	if {![regexp {^-?[[:digit:]]*$} $s]} {
	    ShowMessage [_ "The character offset must be a positive integer."]
	    focus $w;
	    return 0
	}
    }
    ClearMessageWindow
    return 1;
}

proc ValidateRange {w s type action} {
    if {[string equal $type focusout]} { 
	if {[string length $s] == 0} {
	    ShowMessage [_ "You must specify a position."]
	    focus $w;
	    return 0;
	}
	if {![regexp {^-?[[:digit:]]+$} $s]} {
	    ShowMessage [_ "The position must be an integer."]
	    focus $w;
	    return 0
	}
    }
    if {[string equal $type key]} {
	if {![regexp {^-?[[:digit:]]*$} $s]} {
	    ShowMessage [_ "The position must be an integer."]
	    focus $w;
	    return 0
	}
    }
    ClearMessageWindow
    return 1;
}

proc ValidateRandomNumberSeed {w s type action} {
    if {[string equal $type focusout]} { 
	if {[string length $s] == 0} {
	    return 1;
	}
	if {![regexp {^[[:digit:]]+$} $s]} {
	    ShowMessage [_ "The random number seed must be a non-negative integer."]
	    focus $w;
	    return 0
	}
    }
    if {[string equal $type key]} {
	if {![regexp {^[[:digit:]]*$} $s]} {
	    ShowMessage [_ "The random number seed must be a non-negative integer."]
	    focus $w;
	    return 0
	}
    }
    ClearMessageWindow
    return 1;
}


proc SetupKey {hd} {

    set ::KeyInfo(SortOrderSpecType,$hd) 0;
    set ::KeyInfo(ExclusionsP,$hd) 0;
    set ::KeyInfo(SubstitutionsP,$hd) 0;
    set ::KeyInfo(KeySelection,$hd) 0;
    set ::KeyInfo(OptionalP,$hd) 0
    set ::KeyInfo(LocalInversionP,$hd) 0
    set ::KeyInfo(ReverseKeyP,$hd) 0;
    set ::KeyInfo(FoldCaseP,$hd) 0;
    set ::KeyInfo(TurkicFoldCaseP,$hd) 0;
    set ::KeyInfo(FirstCharOnlyP,$hd) 0;
    set ::KeyInfo(StripDiacriticsP,$hd) 0;
    set ::KeyInfo(ConvertEnclosuresP,$hd) 0;
    set ::KeyInfo(ConvertStylisticP,$hd) 0;
    set ::KeyInfo(SortType,$hd) 1;
    set ::KeyInfo(NumberSystem,$hd) "Ascii";
    set ::KeyInfo(DateFormat,$hd) "y-m-d";

    set ::KeyInfo(ExclusionsDisplayedP,$hd) $::ExclusionsDisplayedP;
    set ::KeyInfo(KeyFieldIdentificationDisplayedP,$hd) $::KeyFieldIdentificationDisplayedP;
    set ::KeyInfo(MiscellaneousOptionsDisplayedP,$hd) $::MiscellaneousOptionsDisplayedP;
    set ::KeyInfo(SortOrderDisplayedP,$hd) $::SortOrderDisplayedP;
    set ::KeyInfo(SortTypeDisplayedP,$hd) $::SortTypeDisplayedP;
    set ::KeyInfo(SubstitutionsDisplayedP,$hd) $::SubstitutionsDisplayedP;

    set FileNameEntryWidth 50

    #How to identify the key field
    set mrelief solid
    set mborder 1
    frame $hd -bg $::ColorSpecs(Backdrop,Background);

    if {$::UseCheckbuttonP} {
	frame       $hd.keyf -relief $mrelief -border $mborder
	label  $hd.keyf.lab  -text [_ "How to Identify the Key Field"]   -anchor w -font HeaderFont
	checkbutton $hd.keyf.ckb -variable KeyInfo(KeyFieldIdentificationDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.keyf.lab -side left -expand 0 -fill y -anchor w
	pack $hd.keyf.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.keyf -relief $mrelief -border $mborder
	checkbutton $hd.keyf.ckb -variable KeyInfo(KeyFieldIdentificationDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "How to Identify the Key Field"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.keyf.ckb -side right -expand 1 -fill both -anchor e
    }

    frame	$hd.key -relief $mrelief -border $mborder -bg $::ColorSpecs(Default,Background);
    checkbutton $hd.key.ckb -variable KeyInfo(KeyFieldIdentificationDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    frame       $hd.key.ki
    frame $hd.key.ki.pos
    label       $hd.key.ki.title  -text [_ "How To Identify the Key Field"] -anchor w \
	 -font HeaderFont
    radiobutton $hd.key.ki.pos.rdb1 \
	-variable KeyInfo(KeySelection,$hd) -value 0 \
	-text [_ "position"]  -anchor w
    radiobutton $hd.key.ki.pos.rdb2 \
	-variable KeyInfo(KeySelection,$hd) -value 1 \
	-text [_ "tag"]  -anchor w
    radiobutton $hd.key.ki.pos.rdb3 \
	-variable KeyInfo(KeySelection,$hd) -value 2 \
	-text [_ "range"]  -anchor w

    frame $hd.key.ki.pos.posent;
    entry       $hd.key.ki.pos.posent.fldent1   -width 2 -font UserPlainTextFont -validate all \
	-validatecommand {ValidatePositionField %W %P %V %d}
    entry       $hd.key.ki.pos.posent.fldent2   -width 2 -font UserPlainTextFont -validate all \
	-validatecommand {ValidatePositionField %W %P %V %d}
    entry       $hd.key.ki.pos.posent.chrent1   -width 2 -font UserPlainTextFont -validate all \
	-validatecommand {ValidatePositionChar %W %P %V %d}
    entry       $hd.key.ki.pos.posent.chrent2   -width 2 -font UserPlainTextFont -validate all \
	-validatecommand {ValidatePositionChar %W %P %V %d}

    pack $hd.key.ki.pos.posent.fldent1 -side left -padx {0 1}
    pack $hd.key.ki.pos.posent.chrent1 -side left -padx {2 6}
    pack $hd.key.ki.pos.posent.fldent2 -side left -padx {6 1}
    pack $hd.key.ki.pos.posent.chrent2 -side left -padx {2 3}

    entry       $hd.key.ki.pos.tagent   -width 8 -font UserTechnicalTextFont
    entry       $hd.key.ki.pos.firstent -width 4 -font UserPlainTextFont -validate all \
	-validatecommand {ValidateRange %W %P %V %d}
    entry       $hd.key.ki.pos.lastent  -width 4 -font UserPlainTextFont -validate all \
	-validatecommand {ValidateRange %W %P %V %d}
    bind $hd.key.ki.pos.tagent <FocusIn> "SetInsertionTargets $hd.key.ki.pos.tagent"

    $hd.key.ki.pos.posent.fldent1 insert end $::KeyCount;
    $hd.key.ki.pos.posent.fldent2 insert end $::KeyCount;
    bind $hd.key.ki.pos.rdb1 <<B3>> ExplainPositionID;
    bind $hd.key.ki.pos.rdb2 <<B3>> ExplainTagID;
    bind $hd.key.ki.pos.rdb3 <<B3>> ExplainRangeID;
    $hd.key.ki.pos.rdb1 select
    $hd.key.ki.pos.posent.fldent1 configure -state normal
    $hd.key.ki.pos.posent.fldent2 configure -state normal
    $hd.key.ki.pos.posent.chrent1 configure -state normal
    $hd.key.ki.pos.posent.chrent2 configure -state normal
    $hd.key.ki.pos.tagent configure -state disabled
    $hd.key.ki.pos.firstent configure -state disabled
    $hd.key.ki.pos.lastent configure -state disabled
    grid $hd.key.ki.pos.rdb1   -row 0 -column 0 -sticky w -pady 3
    grid $hd.key.ki.pos.posent -row 0 -column 1  -columnspan 2 -sticky w -pady 3 -padx {14 0}
    grid $hd.key.ki.pos.rdb2   -row 1 -column 0 -sticky w -pady 3
    grid $hd.key.ki.pos.tagent -row 1 -column 1  -sticky w -pady 3 -padx {14 0}
    grid $hd.key.ki.pos.rdb3   -row 2 -column 0 -sticky w -pady 3
    grid $hd.key.ki.pos.firstent -row 2 -column 1  -sticky w -pady 3 -padx {14 0}
    grid $hd.key.ki.pos.lastent -row 2 -column 2  -sticky w -pady 3
    pack $hd.key.ki.title -side top -anchor w -padx 5
    pack $hd.key.ki.pos -side bottom -anchor w -padx 15
    bind $hd.key.ki.pos.tagent <Control-v> {InsertClipboardContents %W}
    bind $hd.key.ki.title <<B3>> ExplainHowToIdentifyKey;
    bind $hd.keyf <<B3>> ExplainHowToIdentifyKey;
    $hd.key.ki.pos.rdb1 select

#Optional field?
    frame $hd.key.opt
    label       $hd.key.opt.title -text [_ "Is This Key Optional?"] -anchor w -font HeaderFont
    radiobutton $hd.key.opt.rdb1 -variable KeyInfo(OptionalP,$hd) -value -0 \
	-text [_ "no"]  -anchor w 
    radiobutton $hd.key.opt.rdb2 -variable KeyInfo(OptionalP,$hd) -value -1 \
	-text [_ "yes"] -anchor w 
    $hd.key.opt.rdb1 select
    frame $hd.key.opt.oc
    label       $hd.key.opt.oc.clab -text [_ "Comparison"]
    radiobutton $hd.key.opt.oc.rdb3 -variable KeyInfo(OptComp,$hd) \
	-value -1 -text [_ "<"] -state disabled
    radiobutton $hd.key.opt.oc.rdb4 -variable KeyInfo(OptComp,$hd) \
	-value  0 -text [_ "="] -state disabled
    radiobutton $hd.key.opt.oc.rdb5 -variable KeyInfo(OptComp,$hd) \
	-value  1 -text [_ ">"] -state disabled
    $hd.key.opt.oc.rdb4 select
    pack $hd.key.opt.oc.clab -side top
    pack $hd.key.opt.oc.rdb3 -side left  -expand 1 -padx 2
    pack $hd.key.opt.oc.rdb5 -side right -expand 1 -padx 2
    pack $hd.key.opt.oc.rdb4 -side right -expand 1 -padx 2
    pack $hd.key.opt.title -side top -expand 1 -fill both  -anchor w -pady {1 8}
    pack $hd.key.opt.rdb1 -side top  -expand 1 -fill y -anchor w  -padx {15 1}
    pack $hd.key.opt.rdb2 -side left -expand 0 -anchor w -padx {15 4} 
    pack $hd.key.opt.oc   -side left -expand 0 -anchor w -padx 5 -pady {1 18}
    bind $hd.key.opt.title <<B3>> ExplainOptional
    bind $hd.key.opt.oc <<B3>> ExplainOptional
    bind $hd.key.opt.rdb1 <<B3>> ExplainOptional
    bind $hd.key.opt.rdb2 <<B3>> ExplainOptional
    bind $hd.key.opt.oc.rdb3 <<B3>> ExplainComparison
    bind $hd.key.opt.oc.rdb4 <<B3>> ExplainComparison
    bind $hd.key.opt.oc.rdb5 <<B3>> ExplainComparison
    bind $hd.key.opt.oc.clab <<B3>> ExplainComparison

    pack $hd.key.ki  -side left -expand 1 -fill both -pady 4
    pack $hd.key.opt -side left -expand 1 -fill both -pady 4
    pack $hd.key.ckb -side left -expand 0 -fill x -pady 4 -anchor ne

    #Sort type selection widget

    if {$::UseCheckbuttonP} {
	frame       $hd.stf -relief $mrelief -border $mborder
	label  $hd.stf.lab  -text [_ "Sort Type"]   -anchor w -font HeaderFont
	checkbutton $hd.stf.ckb -variable KeyInfo(SortTypeDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.stf.lab -side left -expand 0 -fill y -anchor w
	pack $hd.stf.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.stf -relief $mrelief -border $mborder
	checkbutton $hd.stf.ckb -variable KeyInfo(SortTypeDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "Sort Type"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.stf.ckb -side right -expand 1 -fill both -anchor e
    }

    frame $hd.st -relief $mrelief -border $mborder
    frame $hd.st.lab
    frame $hd.st.cnt
    frame $hd.st.buf
    label      $hd.st.lab.title -text [_ "Sort Type"] -anchor w -font HeaderFont
    checkbutton $hd.st.lab.ckb -variable KeyInfo(SortTypeDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    pack $hd.st.lab.title -side left  -expand 1 -fill both -anchor w
    pack $hd.st.lab.ckb -side right -expand 0 -fill both -anchor e

    radiobutton $hd.st.cnt.rdbLex -variable KeyInfo(SortType,$hd) -value 1 -text [_ "lexicographic"]
    radiobutton $hd.st.cnt.rdbStrLen -variable KeyInfo(SortType,$hd) -value 2 -text [_ "string length"]
    radiobutton $hd.st.cnt.rdbNumeric -variable KeyInfo(SortType,$hd) -value 3 -text [_ "numeric"]
    radiobutton $hd.st.cnt.rdbISO8601 -variable KeyInfo(SortType,$hd) -value 6 -text [_ "iso8601"]
    radiobutton $hd.st.cnt.rdbHybrid -variable KeyInfo(SortType,$hd) -value 7 -text [_ "hybrid"]
    radiobutton $hd.st.cnt.rdbRandom -variable KeyInfo(SortType,$hd) -value 8 -text [_ "random"]
    radiobutton $hd.st.cnt.rdbAngle -variable KeyInfo(SortType,$hd) -value 9 -text [_ "angle"]
    radiobutton $hd.st.cnt.rdbNumStr -variable KeyInfo(SortType,$hd) -value 10 -text [_ "numeric\nstring"]
    radiobutton $hd.st.cnt.rdbTime -variable KeyInfo(SortType,$hd) -value 4 -text [_ "time"]
    radiobutton $hd.st.cnt.rdbDate -variable KeyInfo(SortType,$hd) -value 5 -text [_ "date"]
    radiobutton $hd.st.cnt.rdbMonth -variable KeyInfo(SortType,$hd) -value 11 -text [_ "month"]
    radiobutton $hd.st.cnt.rdbDomain -variable KeyInfo(SortType,$hd) -value 12 -text [_ "domain name"]
    button      $hd.st.cnt.bDateFormat  -text [_ "Date Format"] -state disabled \
	-command [list PopupSetDateFormat $hd]
    button      $hd.st.cnt.bNumSys  -text [_ "Number System"] -state disabled \
	-command [list PopupSetNumberSystem $hd]
    $hd.st.cnt.rdbLex select
    balloonhelp_for $hd.st.cnt.bDateFormat [_ "Press this button to set the date format\nfor this key. It is only available if you\nhave selected a date key."]

    frame $hd.st.cnt.bsep -height 6
    set stxpd 10
#    grid $hd.st.cnt.title  -row 0 -column 0   -sticky w -pady 3 -columnspan 4  -padx 5
    grid $hd.st.cnt.rdbLex   -row 1 -column 0   -sticky w -pady 3 -padx {15 4}
    grid $hd.st.cnt.rdbHybrid   -row 1 -column 1   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbAngle   -row 1 -column 2   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbMonth   -row 1 -column 3   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbStrLen   -row 2 -column 0   -sticky w -pady 3 -padx {15 4}
    grid $hd.st.cnt.rdbISO8601   -row 2 -column 1   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbTime   -row 2 -column 2   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbDate   -row 2 -column 3   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.bDateFormat    -row 2 -column 4   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbDomain   -row 3 -column 0   -sticky w -pady 3 -padx {15 4}
    grid $hd.st.cnt.rdbRandom   -row 3 -column 1   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbNumStr   -row 3 -column 2   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.rdbNumeric    -row 3 -column 3   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.bNumSys    -row 3 -column 4   -sticky w -pady 3 -padx $stxpd
    grid $hd.st.cnt.bsep   -row 4 -column 0   -sticky w -pady 3

    pack $hd.st.lab -side top  -expand 1 -fill both -anchor w
    pack $hd.st.cnt -side left -expand 0 -fill none -anchor w
    pack $hd.st.buf -side left -expand 1 -fill none

    bind $hd.st.lab.title <<B3>> ExplainSortType
    bind $hd.st.cnt.rdbLex <<B3>> ExplainLexicographicComparison;
    bind $hd.st.cnt.rdbStrLen <<B3>> ExplainStringLength;
    bind $hd.st.cnt.rdbNumeric <<B3>> ExplainNumericComparison;
    bind $hd.st.cnt.rdbTime <<B3>> ExplainTimeComparison;
    bind $hd.st.cnt.rdbDate <<B3>> ExplainDateComparison;
    bind $hd.st.cnt.rdbISO8601 <<B3>> ExplainISO8601Comparison;
    bind $hd.st.cnt.rdbHybrid <<B3>> ExplainHybridComparison;
    bind $hd.st.cnt.rdbRandom <<B3>> ExplainRandomComparison;
    bind $hd.st.cnt.rdbAngle <<B3>> ExplainAngleComparison;
    bind $hd.st.cnt.rdbDomain <<B3>> ExplainDomainNameComparison;
    bind $hd.st.cnt.bNumSys  <<B3>> ExplainNumberSystem;

    frame $hd.misco -relief $mrelief -border $mborder;
    frame $hd.misco.labf
    frame $hd.misco.bd
    pack $hd.misco.labf -side top -expand 1 -fill both 
    pack $hd.misco.bd   -side top -expand 1 -fill both 
    label $hd.misco.labf.lab -text "Miscellaneous Options" -font HeaderFont
    checkbutton $hd.misco.labf.ckb -variable KeyInfo(MiscellaneousOptionsDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    pack $hd.misco.labf.lab -side left -expand 0 -fill y -anchor w
    pack $hd.misco.labf.ckb -side right -expand 1 -fill y -anchor e

    if {$::UseCheckbuttonP} {
	frame       $hd.miscof -relief $mrelief -border $mborder
	label  $hd.miscof.lab  -text [_ "Miscellaneous Options"]   -anchor w -font HeaderFont
	checkbutton $hd.miscof.ckb  -variable KeyInfo(MiscellaneousOptionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.miscof.lab -side left -expand 0 -fill y -anchor w
	pack $hd.miscof.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.miscof -relief $mrelief -border $mborder
	checkbutton $hd.miscof.ckb -variable KeyInfo(MiscellaneousOptionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "Miscellaneous Options"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.miscof.ckb -side right -expand 1 -fill both -anchor e
    }

	
    #Fold case?
    frame       $hd.misco.bd.fc
    frame       $hd.misco.bd.fc.left
    label       $hd.misco.bd.fc.left.lab  -text [_ "Fold Case?"] -anchor w -font HeaderFont
    label       $hd.misco.bd.fc.img;
    frame       $hd.misco.bd.fc.left.rbf
    radiobutton $hd.misco.bd.fc.left.rbf.rdb1 -variable KeyInfo(FoldCaseP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.fc.left.rbf.rdb2 -variable KeyInfo(FoldCaseP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.fc.left.rbf.rdb1 select
    pack $hd.misco.bd.fc.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.fc.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.fc.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.fc.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.fc.left -side left
    pack $hd.misco.bd.fc.img -side right -expand 1;
    bind $hd.misco.bd.fc.img <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.fc.left <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.fc.left.lab <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.fc.left.rbf <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.fc.left.rbf.rdb1 <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.fc.left.rbf.rdb2 <<B3>> ExplainFoldCase;
    set bhmsg [_ "Make comparisons insensitive to case?"]
    balloonhelp_for $hd.misco.bd.fc $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.img $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.left $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.fc.left.lab $bhmsg;
    #Turkic fold case?
    frame       $hd.misco.bd.tfc
    frame       $hd.misco.bd.tfc.left
    label       $hd.misco.bd.tfc.left.lab  -text [_ "Turkic Fold Case?"] -anchor w -font HeaderFont
    label       $hd.misco.bd.tfc.img;
    frame       $hd.misco.bd.tfc.left.rbf
    radiobutton $hd.misco.bd.tfc.left.rbf.rdb1 -variable KeyInfo(TurkicFoldCaseP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.tfc.left.rbf.rdb2 -variable KeyInfo(TurkicFoldCaseP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.tfc.left.rbf.rdb1 select
    pack $hd.misco.bd.tfc.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.tfc.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.tfc.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.tfc.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.tfc.left -side left
    pack $hd.misco.bd.tfc.img -side right -expand 1;
    bind $hd.misco.bd.tfc.img <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.tfc.left <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.tfc.left.lab <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.tfc.left.rbf <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.tfc.left.rbf.rdb1 <<B3>> ExplainFoldCase;
    bind $hd.misco.bd.tfc.left.rbf.rdb2 <<B3>> ExplainFoldCase;
    set bhmsg [_ "Make comparisons insensitive to case including Turkic\nfolding of \u0049 U+0049 to \u0131 U+0131 and \u0130 U+0130 to \u0069 U+0069 ?"]
    balloonhelp_for $hd.misco.bd.tfc $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.img $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.left $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.tfc.left.lab $bhmsg;

    #Reverse key?
    frame       $hd.misco.bd.rk
    frame       $hd.misco.bd.rk.left
    label       $hd.misco.bd.rk.left.lab  -text [_ "Reverse Key?"] -anchor w -font HeaderFont
    label       $hd.misco.bd.rk.img;
    frame       $hd.misco.bd.rk.left.rbf
    radiobutton $hd.misco.bd.rk.left.rbf.rdb1 -variable KeyInfo(ReverseKeyP,$hd) -value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.rk.left.rbf.rdb2 -variable KeyInfo(ReverseKeyP,$hd) -value 1 -text [_ "yes"]
    $hd.misco.bd.rk.left.rbf.rdb1 select
    pack $hd.misco.bd.rk.left.rbf.rdb1  -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.rk.left.rbf.rdb2  -anchor w -side left -expand 0
    pack $hd.misco.bd.rk.left.lab -side top -expand y -fill x  -anchor w
    pack $hd.misco.bd.rk.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.rk.left -side left
    pack $hd.misco.bd.rk.img -side right -expand 1;
    bind $hd.misco.bd.rk.left <<B3>> ExplainReverseKey;
    bind $hd.misco.bd.rk.img <<B3>> ExplainReverseKey;
    bind $hd.misco.bd.rk.left.lab <<B3>> ExplainReverseKey;
    bind $hd.misco.bd.rk.left.rbf <<B3>> ExplainReverseKey;
    bind $hd.misco.bd.rk.left.rbf.rdb1 <<B3>> ExplainReverseKey;
    bind $hd.misco.bd.rk.left.rbf.rdb2 <<B3>> ExplainReverseKey;
    #Invert comparison?
    frame       $hd.misco.bd.li
    label       $hd.misco.bd.li.lab  -text [_ "Invert Comparison?"] -anchor w -font HeaderFont
    frame       $hd.misco.bd.li.rbf
    radiobutton $hd.misco.bd.li.rbf.rdb1 -variable KeyInfo(LocalInversionP,$hd) -value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.li.rbf.rdb2 -variable KeyInfo(LocalInversionP,$hd) -value 1 -text [_ "yes"]
    $hd.misco.bd.li.rbf.rdb1 select
    pack $hd.misco.bd.li.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.li.rbf.rdb2 -anchor w -side left -expand 0
    pack $hd.misco.bd.li.lab -side top -expand y -fill x  -anchor w
    pack $hd.misco.bd.li.rbf -side bottom -expand y -anchor w
    bind $hd.misco.bd.li.lab <<B3>> ExplainInvertComparison;
    bind $hd.misco.bd.li.rbf <<B3>> ExplainInvertComparison;
    bind $hd.misco.bd.li.rbf.rdb1 <<B3>> ExplainInvertComparison;
    bind $hd.misco.bd.li.rbf.rdb2 <<B3>> ExplainInvertComparison;

    #Strip diacritics
    frame       $hd.misco.bd.sd
    frame       $hd.misco.bd.sd.left
    label       $hd.misco.bd.sd.left.lab  -text [_ "Strip Diacritics?"] -anchor w -font HeaderFont
    label       $hd.misco.bd.sd.img;
    frame       $hd.misco.bd.sd.left.rbf
    radiobutton $hd.misco.bd.sd.left.rbf.rdb1 -variable KeyInfo(StripDiacriticsP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.sd.left.rbf.rdb2 -variable KeyInfo(StripDiacriticsP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.sd.left.rbf.rdb1 select
    pack $hd.misco.bd.sd.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.sd.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.sd.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.sd.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.sd.left -side left
    pack $hd.misco.bd.sd.img -side right -expand 1;
    bind $hd.misco.bd.sd.img <<B3>> ExplainStripDiacritics;
    bind $hd.misco.bd.sd.left <<B3>> ExplainStripDiacritics;
    bind $hd.misco.bd.sd.left.lab <<B3>> ExplainStripDiacritics;
    bind $hd.misco.bd.sd.left.rbf <<B3>> ExplainStripDiacritics;
    bind $hd.misco.bd.sd.left.rbf.rdb1 <<B3>> ExplainStripDiacritics;
    bind $hd.misco.bd.sd.left.rbf.rdb2 <<B3>> ExplainStripDiacritics;
    set bhmsg [_ "Strip diacritics?"]
    balloonhelp_for $hd.misco.bd.sd $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.img $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.left $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.sd.left.lab $bhmsg;

    #Convert enclosures
    frame       $hd.misco.bd.ce
    frame       $hd.misco.bd.ce.left
    label       $hd.misco.bd.ce.left.lab  -text [_ "Strip Enclosures?"] -anchor w -font HeaderFont
    label       $hd.misco.bd.ce.img;
    frame       $hd.misco.bd.ce.left.rbf
    radiobutton $hd.misco.bd.ce.left.rbf.rdb1 -variable KeyInfo(ConvertEnclosuresP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.ce.left.rbf.rdb2 -variable KeyInfo(ConvertEnclosuresP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.ce.left.rbf.rdb1 select
    pack $hd.misco.bd.ce.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.ce.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.ce.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.ce.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.ce.left -side left
    pack $hd.misco.bd.ce.img -side right -expand 1;
    bind $hd.misco.bd.ce.img <<B3>> ExplainConvertEnclosures;
    bind $hd.misco.bd.ce.left <<B3>> ExplainConvertEnclosures;
    bind $hd.misco.bd.ce.left.lab <<B3>> ExplainConvertEnclosures;
    bind $hd.misco.bd.ce.left.rbf <<B3>> ExplainConvertEnclosures;
    bind $hd.misco.bd.ce.left.rbf.rdb1 <<B3>> ExplainConvertEnclosures;
    bind $hd.misco.bd.ce.left.rbf.rdb2 <<B3>> ExplainConvertEnclosures;
    set bhmsg [_ "Convert enclosures?"]
    balloonhelp_for $hd.misco.bd.ce $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.img $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.left $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.ce.left.lab $bhmsg;

    #Convert stylistic
    frame       $hd.misco.bd.cs
    frame       $hd.misco.bd.cs.left
    label       $hd.misco.bd.cs.left.lab  -text [_ "Strip Style?"] -anchor w\
	-font HeaderFont
    label       $hd.misco.bd.cs.img;
    frame       $hd.misco.bd.cs.left.rbf
    radiobutton $hd.misco.bd.cs.left.rbf.rdb1 -variable KeyInfo(ConvertStylisticP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.cs.left.rbf.rdb2 -variable KeyInfo(ConvertStylisticP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.cs.left.rbf.rdb1 select
    pack $hd.misco.bd.cs.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.cs.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.cs.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.cs.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.cs.left -side left
    pack $hd.misco.bd.cs.img -side right -expand 1;
    bind $hd.misco.bd.cs.img <<B3>> ExplainConvertStylistic;
    bind $hd.misco.bd.cs.left <<B3>> ExplainConvertStylistic;
    bind $hd.misco.bd.cs.left.lab <<B3>> ExplainConvertStylistic;
    bind $hd.misco.bd.cs.left.rbf <<B3>> ExplainConvertStylistic;
    bind $hd.misco.bd.cs.left.rbf.rdb1 <<B3>> ExplainConvertStylistic;
    bind $hd.misco.bd.cs.left.rbf.rdb2 <<B3>> ExplainConvertStylistic;
    set bhmsg [_ "Convert stylistic equivalents?"]
    balloonhelp_for $hd.misco.bd.cs $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.img $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.left $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.cs.left.lab $bhmsg;

    #First character only?
    frame       $hd.misco.bd.of
    frame       $hd.misco.bd.of.left
    label       $hd.misco.bd.of.left.lab  -text [_ "Use First Character Only?"] -anchor w\
	-font HeaderFont
    label       $hd.misco.bd.of.img;
    frame       $hd.misco.bd.of.left.rbf
    radiobutton $hd.misco.bd.of.left.rbf.rdb1 -variable KeyInfo(FirstCharOnlyP,$hd) \
	-value 0 -text [_ "no"]
    radiobutton $hd.misco.bd.of.left.rbf.rdb2 -variable KeyInfo(FirstCharOnlyP,$hd) \
	-value 1 -text [_ "yes"]
    $hd.misco.bd.of.left.rbf.rdb1 select
    pack $hd.misco.bd.of.left.rbf.rdb1 -anchor w -side left -padx {15 3}
    pack $hd.misco.bd.of.left.rbf.rdb2 -anchor w -side left
    pack $hd.misco.bd.of.left.lab -side top -expand y -fill x  -anchor w -padx 5
    pack $hd.misco.bd.of.left.rbf -side bottom -expand y -anchor w
    pack $hd.misco.bd.of.left -side left
    pack $hd.misco.bd.of.img -side right -expand 1;
    bind $hd.misco.bd.of.img <<B3>> ExplainFirstCharOnly;
    bind $hd.misco.bd.of.left <<B3>> ExplainFirstCharOnly;
    bind $hd.misco.bd.of.left.lab <<B3>> ExplainFirstCharOnly;
    bind $hd.misco.bd.of.left.rbf <<B3>> ExplainFirstCharOnly;
    bind $hd.misco.bd.of.left.rbf.rdb1 <<B3>> ExplainFirstCharOnly;
    bind $hd.misco.bd.of.left.rbf.rdb2 <<B3>> ExplainFirstCharOnly;
    set bhmsg [_ "Only use first character of key?"]
    balloonhelp_for $hd.misco.bd.of $bhmsg;
    balloonhelp_for $hd.misco.bd.of.img $bhmsg;
    balloonhelp_for $hd.misco.bd.of.left $bhmsg;
    balloonhelp_for $hd.misco.bd.of.left.rbf $bhmsg;
    balloonhelp_for $hd.misco.bd.of.left.rbf.rdb1 $bhmsg;
    balloonhelp_for $hd.misco.bd.of.left.rbf.rdb2 $bhmsg;
    balloonhelp_for $hd.misco.bd.of.left.lab $bhmsg;

    set xp 5
    grid $hd.misco.bd.rk  -row 1 -column 1 -sticky w -pady {5  5} -padx {5 5}
    grid $hd.misco.bd.li  -row 1 -column 2 -sticky w -pady {10 5} -padx $xp
    grid $hd.misco.bd.cs  -row 1 -column 3 -sticky w -pady {10 5} -padx $xp
    grid $hd.misco.bd.of  -row 1 -column 4 -sticky w -pady {10 5} -padx $xp
    grid $hd.misco.bd.ce  -row 2 -column 1 -sticky w -pady {5 12} -padx {5 5}
    grid $hd.misco.bd.sd  -row 2 -column 2 -sticky w -pady {5 12} -padx $xp
    grid $hd.misco.bd.fc  -row 2 -column 3 -sticky w -pady {5 12} -padx $xp
    grid $hd.misco.bd.tfc -row 2 -column 4 -sticky w -pady {5 12} -padx $xp

    # Sort order/multigraphs
    frame       $hd.so -relief $mrelief -border $mborder
    frame       $hd.so.labf -relief $mrelief -border $mborder
    label       $hd.so.labf.lab  -text [_ "Sort Order"] -anchor w -font HeaderFont
    checkbutton $hd.so.labf.ckb -variable KeyInfo(SortOrderDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    pack $hd.so.labf.lab -side left  -expand 1 -fill both -anchor w
    pack $hd.so.labf.ckb -side right -expand 0 -fill both -anchor e
    radiobutton $hd.so.rdb0 -variable KeyInfo(SortOrderSpecType,$hd) \
	-value 0 -text [_ "Unicode Order"] -anchor w

    if {$::UseCheckbuttonP} {
	frame       $hd.sof -relief $mrelief -border $mborder
	label  $hd.sof.lab  -text [_ "Sort Order"]   -anchor w -font HeaderFont
	checkbutton $hd.sof.ckb -variable KeyInfo(SortOrderDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.sof.lab -side left -expand 0 -fill y -anchor w
	pack $hd.sof.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.sof -relief $mrelief -border $mborder
	checkbutton $hd.sof.ckb -variable KeyInfo(SortOrderDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "Sort Order"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.sof.ckb -side right -expand 1 -fill both -anchor e
    }


    frame       $hd.so.loc 
    radiobutton $hd.so.loc.rdb1 -variable KeyInfo(SortOrderSpecType,$hd) \
	-value 1 -text [_ "Locale Order"] -anchor w
    entry  $hd.so.loc.ent -width $FileNameEntryWidth  -font UserPlainTextFont
    $hd.so.loc.ent insert end "current"
    $hd.so.loc.ent configure -state disabled
    bind $hd.so.loc.ent <FocusIn> "SetInsertionTargets $hd.so.loc.ent"
    frame       $hd.so.bot 
    radiobutton $hd.so.bot.rdb2 -variable KeyInfo(SortOrderSpecType,$hd) \
	-value 2 -text [_ "Custom Order"] -anchor w
    $hd.so.rdb0 select
    button      $hd.so.bot.b1  -text [_ "Specify File"] \
	-state disabled -command [list SpecifySortOrderFile $hd]
    button      $hd.so.bot.b2  -text [_ "Define"]  -state disabled -command "EnterSortOrder $hd"
    entry  $hd.so.bot.ent -width $FileNameEntryWidth -state disabled  -font UserPlainTextFont
    bind $hd.so.bot.ent <FocusIn> "SetInsertionTargets $hd.so.bot.ent"
    frame $hd.so.bsep -height 5
    frame $hd.so.tsep -height 5

    pack $hd.so.labf -side top -expand 1 -fill both  -padx 5
    pack $hd.so.bot.rdb2 -side left -expand 0 -fill x  -anchor w -padx {0 4}
    pack $hd.so.bot.b2 -side left -expand 0  -anchor w -padx {2 4}
    pack $hd.so.bot.b1 -side left -expand 0  -anchor w
    pack $hd.so.bot.ent  -expand 0 -fill none  -anchor w -side left -padx 3
    pack $hd.so.loc.rdb1 -side left -expand 0 -fill x  -anchor w -padx {0 4}
    pack $hd.so.loc.ent  -expand 0 -fill none  -anchor w -side left -padx 3
    pack $hd.so.bsep -side bottom -expand 0 -fill both
    pack $hd.so.bot  -side bottom -expand 0 -fill x  -anchor w -padx {15 4}
    pack $hd.so.tsep -side top -expand 0 -fill both
    pack $hd.so.rdb0 -side top -expand 0 -fill y  -anchor w -padx {15 4}
    pack $hd.so.loc -side top -expand 0 -fill y  -anchor w -padx {15 4}
    bind $hd.so.labf <<B3>> ExplainSortOrder;
    balloonhelp_for $hd.so.rdb0 [_ "Choose this option if you want to sort on this key using the order of\nUnicode codepoints as the sort order. For ASCII characters this is the\nsame as ASCII order."]
    balloonhelp_for $hd.so.bot.b1 [_ "The sort order definition will be read from the file shown\nin the entry box to the right. You can type the name of the\nfile in the entry box if you like, or you can press this button\nto bring up a file selection dialogue."]
    balloonhelp_for $hd.so.bot.b2 [_ "Press this button if you want to define a sort order interactively.\nThe result will be written out to a file,\nwhose name will appear in the entry box to the right."]
    balloonhelp_for $hd.so.loc.rdb1 [_ "Choose this option if you want to sort on this key using\nthe collation rules for a locale."]
    balloonhelp_for $hd.so.bot.rdb2 [_ "Choose this option if you want to use a custom sort order."]
    balloonhelp_for $hd.so.loc.ent [_ "The sort order will be determined by the collation rules for\nthe locale specified here. You may enter either a locale name\nor the word \"current\". In the latter case, your current locale\nwill be used. Note that this only works on systems using glibc\nand only if the locale you choose has been installed."]
    balloonhelp_for $hd.so.bot.ent [_ "The sort order will be read from the file whose name\nis shown in this entry box. You may select an\nexisting file by entering its name directly or by using\nthe file selection dialogue. You may also\ndefine the sort order interactively, after which\nit will be written to a file, whose name\nwill appear in the entry box."]

     #Sort order file separators
    frame $hd.sos -relief $mrelief -border $mborder
    label       $hd.sos.tit  -text [_ "Custom Sort Order File Separators?"] \
	-anchor w -font HeaderFont
    radiobutton $hd.sos.rdb1 -variable KeyInfo(CustomSortOrderSeparatorsP,$hd) -value 0 -text [_ "no"] -anchor w
    frame       $hd.sos.bot 
    radiobutton $hd.sos.bot.rdb2 -variable KeyInfo(CustomSortOrderSeparatorsP,$hd) -value 1 -text [_ "yes"] -anchor w
    $hd.sos.rdb1 select
    button      $hd.sos.bot.b1  -text [_ "Specify File"] -state disabled -command [list SpecifySortOrderSeparatorFile $hd]
    button      $hd.sos.bot.b2  -text [_ "Define"]  -state disabled -command "EnterSortOrderSeparators $hd"
    entry  $hd.sos.bot.ent -width $FileNameEntryWidth -state disabled  -font UserPlainTextFont
    bind $hd.sos.bot.ent <FocusIn> "SetInsertionTargets $hd.sos.bot.ent"
    frame $hd.sos.bsep -height 5
    frame $hd.sos.tsep -height 5
    pack $hd.sos.bot.rdb2 -side left -expand 0 -fill x  -anchor w -padx {0 4}
    pack $hd.sos.bot.b2 -side left -expand 0  -anchor w -padx {2 4}
    pack $hd.sos.bot.b1 -side left -expand 0  -anchor w
    pack $hd.sos.bot.ent  -expand 0 -fill none  -anchor w -side left -padx 3
    pack $hd.sos.tsep -side top -expand 1 -fill both
    pack $hd.sos.tit -side top -expand 1 -fill both  -padx 5
    pack $hd.sos.bsep -side bottom -expand 1 -fill both
    pack $hd.sos.bot -side bottom -expand 1 -fill x  -anchor w -padx {15 4}
    pack $hd.sos.rdb1 -side top -expand 1 -fill y  -anchor w -padx {15 4}
    bind $hd.sos.tit <<B3>> ExplainSortOrderSeparators;
    set msg [_ "Redefine sort order separators so as to\ninclude whitespace in multigraphs?"];
    balloonhelp_for $hd.sos $msg;
    balloonhelp_for $hd.sos.tit $msg;
    balloonhelp_for $hd.sos.bot $msg;
    balloonhelp_for $hd.sos.rdb1 $msg;
    balloonhelp_for $hd.sos.bot.rdb2 $msg;
    balloonhelp_for $hd.sos.bot.b1 [_ "The sort order separators will be read from the file shown\nin the entry box to the right. You can type the name of the\nfile in the entry box if you like, or you can press this button\nto bring up a file selection dialogue."]
    balloonhelp_for $hd.sos.bot.b2 [_ "Press this button if you want to enter the separators interactively.\nThe result will be written out to a file,\nwhose name will appear in the entry box to the right."]
    balloonhelp_for $hd.sos.bot.ent [_ "The sort order separators will be read from the file whose name\n is shown in this entry box. You may select an\nexisting file by entering its name directly or by using\nthe file selection dialogue. You may also\ndefine the sort order interactively, after which\nthey it will be written to a file, whose name\nwill appear in the entry box."]

     #Exclusions
    frame       $hd.exc -relief $mrelief -border $mborder
    frame       $hd.exc.labf -relief $mrelief -border $mborder
    label       $hd.exc.labf.lab  -text [_ "Exclusions"] -anchor w -font HeaderFont
    checkbutton $hd.exc.labf.ckb -variable KeyInfo(ExclusionsDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    pack $hd.exc.labf.lab -side left  -expand 1 -fill both -anchor w
    pack $hd.exc.labf.ckb -side right -expand 0 -fill both -anchor e
    radiobutton $hd.exc.rdb1 -variable KeyInfo(ExclusionsP,$hd) -value 0 -text [_ "no"] -anchor w
    frame       $hd.exc.bot 
    radiobutton $hd.exc.bot.rdb2 -variable KeyInfo(ExclusionsP,$hd) -value 1 -text [_ "yes"] -anchor w
    $hd.exc.rdb1 select
    button      $hd.exc.bot.b1  -text [_ "Specify File"] -state disabled -command [list SpecifyExclusionFile $hd]
    button      $hd.exc.bot.b2  -text [_ "Define"]  -state disabled -command "EnterExclusions $hd"
    entry  $hd.exc.bot.ent -width $FileNameEntryWidth -state disabled -font UserPlainTextFont
    bind $hd.exc.bot.ent <FocusIn> "SetInsertionTargets $hd.exc.bot.ent"
    frame $hd.exc.bsep -height 5
    frame $hd.exc.tsep -height 5
    pack $hd.exc.bot.rdb2 -side left -expand 0 -fill x  -anchor w -padx {0 4}
    pack $hd.exc.bot.b2 -side left -expand 0  -anchor w -padx {2 4}
    pack $hd.exc.bot.b1 -side left -expand 0  -anchor w
    pack $hd.exc.bot.ent  -expand 0 -fill none  -anchor w -side left  -padx 3
    pack $hd.exc.labf -side top -anchor w -expand 1 -fill both -padx 5
    pack $hd.exc.bsep -side bottom -expand 1 -fill both
    pack $hd.exc.bot -side bottom -expand 1 -fill x  -anchor w -padx {15 4}
    pack $hd.exc.tsep -side top -expand 1 -fill both
    pack $hd.exc.rdb1 -side top -expand 1 -fill y  -anchor w -padx {15 4}

    if {$::UseCheckbuttonP} {
	frame       $hd.excf -relief $mrelief -border $mborder
	label  $hd.excf.lab  -text [_ "Exclusions"]   -anchor w -font HeaderFont
	checkbutton $hd.excf.ckb -variable KeyInfo(ExclusionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.excf.lab -side left -expand 0 -fill y -anchor w
	pack $hd.excf.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.excf -relief $mrelief -border $mborder
	checkbutton $hd.excf.ckb -variable KeyInfo(ExclusionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "Exclusions"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.excf.ckb -side right -expand 1 -fill both -anchor e
    }

    bind $hd.exc.labf <<B3>> ExplainExclusions
    bind $hd.excf.ckb  <<B3>> ExplainExclusions
    bind $hd.exc.bot <<B3>> ExplainExclusions
    bind $hd.exc.rdb1 <<B3>> ExplainExclusions
    bind $hd.exc.bot.rdb2 <<B3>> ExplainExclusions
    bind $hd.exc.bot.b1 <<B3>> ExplainExclusions
    bind $hd.exc.bot.b2 <<B3>> ExplainExclusions
    bind $hd.exc.bot.ent <<B3>> ExplainExclusions
    balloonhelp_for $hd.exc.bot.b1 [_ "The exclusions will be read from the file shown\nin the entry box to the right. You can type the name of the\nfile in the entry box if you like, or you can press this button\nto bring up a file selection dialogue."]
    balloonhelp_for $hd.exc.bot.b2 [_ "Press this button if you want to define exclusions interactively.\nThe result will be written out to a file,\nwhose name will appear in the entry box to the right."]
    balloonhelp_for $hd.exc.bot.ent [_ "Exclusions will be read from the file whose name\n is shown in this entry box. You may select an\nexisting file by entering its name directly or by using\nthe file selection dialogue. You may also\ndefine exclusions interactively, after which\nthey will be written to a file, whose name\nwill appear in the entry box."]

     #Substitutions
    frame       $hd.sub -relief $mrelief -border $mborder
    frame       $hd.sub.labf -relief $mrelief -border $mborder
    label       $hd.sub.labf.lab  -text [_ "Substitutions"] -anchor w -font HeaderFont
    checkbutton $hd.sub.labf.ckb -variable KeyInfo(SubstitutionsDisplayedP,$hd) \
	-onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" -text [_ "roll up"] \
	-activebackground $::ColorSpecs(RollUpButton,ActiveBackground) \
	-activeforeground $::ColorSpecs(RollUpButton,ActiveForeground)
    pack $hd.sub.labf.lab -side left  -expand 1 -fill both -anchor w
    pack $hd.sub.labf.ckb -side right -expand 0 -fill both -anchor e
    radiobutton $hd.sub.rdb1 -variable KeyInfo(SubstitutionsP,$hd) -value 0 \
	-text [_ "no"] -anchor w
    frame       $hd.sub.bot 
    radiobutton $hd.sub.bot.rdb2 -variable KeyInfo(SubstitutionsP,$hd) \
	-value 1 -text [_ "yes"] -anchor w
    $hd.sub.rdb1 select
    button      $hd.sub.bot.b1  -text [_ "Specify File"] \
	-state disabled -command [list SpecifySubstitutionFile $hd]
    button      $hd.sub.bot.b2  -text [_ "Define"]  -state disabled \
	-command "EnterSubstitutions $hd"
    entry  $hd.sub.bot.ent -width $FileNameEntryWidth -state disabled -font UserPlainTextFont
    bind $hd.sub.bot.ent <FocusIn> "SetInsertionTargets $hd.sub.bot.ent"

    frame $hd.sub.bsep -height 5
    frame $hd.sub.tsep -height 5
    pack $hd.sub.bot.rdb2 -side left -expand 0 -fill x  -anchor w -padx {0 4}
    pack $hd.sub.bot.b2 -side left -expand 0  -anchor w -padx {2 4}
    pack $hd.sub.bot.b1 -side left -expand 0  -anchor w
    pack $hd.sub.bot.ent  -expand 0 -fill none  -anchor w -side left  -padx 3

    pack $hd.sub.tsep -side top -expand 1 -fill both
    pack $hd.sub.labf -side top -anchor w -expand 1 -fill both -padx 5
    pack $hd.sub.bsep -side bottom -expand 1 -fill both
    pack $hd.sub.bot  -side bottom -expand 1 -fill x  -anchor w -padx {15 4}
    pack $hd.sub.rdb1 -side top -expand 1 -fill y  -anchor w -padx {15 4}

    if {$::UseCheckbuttonP} {
	frame       $hd.subf -relief $mrelief -border $mborder
	label  $hd.subf.lab  -text [_ "Substitutions"]   -anchor w -font HeaderFont
	checkbutton $hd.subf.ckb -variable KeyInfo(SubstitutionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" 
	pack $hd.subf.lab -side left -expand 0 -fill y -anchor w
	pack $hd.subf.ckb -side right -expand 1 -fill y -anchor e
    } else {
	frame       $hd.subf -relief $mrelief -border $mborder
	checkbutton $hd.subf.ckb -variable KeyInfo(SubstitutionsDisplayedP,$hd) \
	    -onvalue 1 -offvalue 0 -command "PackKeyPage $hd;" \
	    -text [_ "Substitutions"] -anchor w -font HeaderFont -indicatoron 0 \
	    -activeforeground red 	-activebackground navajowhite
	pack $hd.subf.ckb -side right -expand 1 -fill both -anchor e
    }

    bind $hd.sub.labf <<B3>> ExplainSubstitutions
    bind $hd.sub.bot <<B3>> ExplainSubstitutions
    bind $hd.sub.rdb1 <<B3>> ExplainSubstitutions
    bind $hd.sub.bot.rdb2 <<B3>> ExplainSubstitutions
    bind $hd.sub.bot.b1 <<B3>> ExplainSubstitutions
    bind $hd.sub.bot.b2 <<B3>> ExplainSubstitutions
    bind $hd.sub.bot.ent <<B3>> ExplainSubstitutions
    balloonhelp_for $hd.sub.bot.b1 [_ "The substitutions will be read from the file shown\nin the entry box to the right. You can type the name of the\nfile in the entry box if you like, or you can press this button\nto bring up a file selection dialogue."]
    balloonhelp_for $hd.sub.bot.b2 [_ "Press this button if you want to define substitutions interactively.\nThe result will be written out to a file,\nwhose name will appear in the entry box to the right."]
    balloonhelp_for $hd.sub.bot.ent [_ "Substitutions will be read from the file whose name\n is shown in this entry box. You may select an\nexisting file by entering its name directly or by using\nthe file selection dialogue. You may also\ndefine substitutions interactively, after which\nthey will be written to a file, whose name\nwill appear in the entry box."]

    # Pack it all together
    PackKeyPage $hd;

    balloonhelp_for $hd.exc    [_ "Should some characters in some positions\nbe ignored when comparing records on this key?"]
    balloonhelp_for $hd.sub    [_ "Should some sequences be replaced with others?"]
    balloonhelp_for $hd.key.ki $::MainKeyFieldIdentBH;
    balloonhelp_for $hd.misco.bd.li     [_ "Invert the sense of comparisons on this key?"]
    balloonhelp_for $hd.misco.bd.rk     [_ "Reverse the order of the characters in the key?"]
    balloonhelp_for $hd.key.opt    [_ "Is this key obligatory or may it be omitted?"]
    balloonhelp_for $hd.key.opt.oc [_ "How should a record with a missing optional key\ncompare with a record in which the same key is present?"]
    balloonhelp_for $hd.so     [_ "What sort order do you wish to use for this key?"]
    balloonhelp_for $hd.st.cnt     [_ "What sort of comparison should be done on this field?"]

    trace add variable ::KeyInfo(KeySelection,$hd) write ChooseActiveKeySelection
    trace add variable ::KeyInfo(ExclusionsP,$hd) write ToggleExclusionEntryActive
    trace add variable ::KeyInfo(SubstitutionsP,$hd) write ToggleSubstitutionEntryActive
    trace add variable ::KeyInfo(SortOrderSpecType,$hd) write ToggleCustomSortOrderEntryActive
    trace add variable ::KeyInfo(CustomSortOrderSeparatorsP,$hd) write ToggleCustomSortOrderSeparatorsEntryActive
    trace add variable ::KeyInfo(SortType,$hd) write ToggleOnSortType
    trace add variable ::KeyInfo(OptionalP,$hd) write ToggleOptComparisonActive
    BindKeys $hd;
}

proc ChangePage {n e o} {
    foreach i [array names ::KeyMap] {
	set w $::KeyMap($i);
	if {[winfo exists $w]} {
	    $::SelectionButtonMap($i) configure -fg $::ColorSpecs(PageChoice,UnselectedPageForeground)
	    pack forget $w;
	} else {
	    dmsg "ChangePage: attempt to unpack non-existant window $w";
	}
    }
    set w $::KeyMap($::WhichKey)
    if {[winfo exists $w] == 0} {
	dmsg "ChangePage: attempt to pack non-existant window $w";
	return ;
    }
    pack $w -expand 1 -fill both -pady 0
    $::SelectionButtonMap($::WhichKey) configure -fg $::ColorSpecs(PageChoice,ActiveForeground);
    if {$::WhichKey > 0} {
	if {$::WholeRecordIsKeyP} {
	    DisableKeyFieldID $::KeyMap($::WhichKey);
	} else {
	    EnableKeyFieldID $::KeyMap($::WhichKey);
	}
    }
}

proc ChooseActiveKeySelection {n e o} {
    set hd [lindex [split $e ","] 1]
    switch $::KeyInfo($e) {
	0 {
	    $hd.key.ki.pos.posent.fldent1   configure -state normal
	    $hd.key.ki.pos.posent.fldent2   configure -state normal
	    $hd.key.ki.pos.posent.chrent1   configure -state normal
	    $hd.key.ki.pos.posent.chrent2   configure -state normal
	    $hd.key.ki.pos.tagent   configure -state disabled
	    $hd.key.ki.pos.firstent configure -state disabled
	    $hd.key.ki.pos.lastent  configure -state disabled
	    focus $hd.key.ki.pos.posent.fldent1;
	}
	1 {
	    $hd.key.ki.pos.posent.fldent1   configure -state disabled
	    $hd.key.ki.pos.posent.fldent2   configure -state disabled
	    $hd.key.ki.pos.posent.chrent1   configure -state disabled
	    $hd.key.ki.pos.posent.chrent2   configure -state disabled
	    $hd.key.ki.pos.tagent   configure -state normal
	    $hd.key.ki.pos.firstent configure -state disabled
	    $hd.key.ki.pos.lastent  configure -state disabled
	    focus $hd.key.ki.pos.tagent;
	}
	2 {
	    $hd.key.ki.pos.posent.fldent1   configure -state disabled
	    $hd.key.ki.pos.posent.fldent2   configure -state disabled
	    $hd.key.ki.pos.posent.chrent1   configure -state disabled
	    $hd.key.ki.pos.posent.chrent2   configure -state disabled
	    $hd.key.ki.pos.tagent   configure -state disabled
	    $hd.key.ki.pos.firstent configure -state normal
	    $hd.key.ki.pos.lastent  configure -state normal
	    focus $hd.key.ki.pos.firstent;
	}
    }
}

proc ToggleExclusionEntryActive {n e o} {
    set hd [lindex [split $e ","] 1]
    if {$::KeyInfo($e)} {
	$hd.exc.bot.b1 configure -state normal
	$hd.exc.bot.b2 configure -state normal
	$hd.exc.bot.ent configure -state normal
    } else {
	$hd.exc.bot.b1 configure -state disabled
	$hd.exc.bot.b2 configure -state disabled
	$hd.exc.bot.ent configure -state disabled
    }
}

proc ToggleSubstitutionEntryActive {n e o} {
    set hd [lindex [split $e ","] 1]
    if {$::KeyInfo($e)} {
	$hd.sub.bot.b1 configure -state normal
	$hd.sub.bot.b2 configure -state normal
	$hd.sub.bot.ent configure -state normal
    } else {
	$hd.sub.bot.b1 configure -state disabled
	$hd.sub.bot.b2 configure -state disabled
	$hd.sub.bot.ent configure -state disabled
    }
}

proc ToggleCustomSortOrderEntryActive {n e o} {
    set hd [lindex [split $e ","] 1]
    switch $::KeyInfo($e) {
	2 {
	    $hd.so.bot.b1 configure -state normal
	    $hd.so.bot.b2 configure -state normal
	    $hd.so.bot.ent configure -state normal
	    $hd.so.loc.ent configure -state disabled
	}
	1 {
	    $hd.so.bot.b1 configure -state disabled
	    $hd.so.bot.b2 configure -state disabled
	    $hd.so.bot.ent configure -state disabled
	    $hd.so.loc.ent configure -state normal
	}
	0 {
	    $hd.so.bot.b1 configure -state disabled
	    $hd.so.bot.b2 configure -state disabled
	    $hd.so.bot.ent configure -state disabled
	    $hd.so.loc.ent configure -state disabled
	}
    }
    PackKeyPage $hd;
}

proc ToggleCustomSortOrderSeparatorsEntryActive {n e o} {
    set hd [lindex [split $e ","] 1]
    if {$::KeyInfo($e)} {
	$hd.sos.bot.b1 configure -state normal
	$hd.sos.bot.b2 configure -state normal
	$hd.sos.bot.ent configure -state normal
    } else {
	$hd.sos.bot.b1 configure -state disabled
	$hd.sos.bot.b2 configure -state disabled
	$hd.sos.bot.ent configure -state disabled
    }
}

proc ToggleOnSortType {n e o} {
    set hd [lindex [split $e ","] 1]
    set SortType $::KeyInfo($e)

    if {$SortType == 5} {
	$hd.st.cnt.bDateFormat configure -state normal
	$hd.st.cnt.bNumSys configure -state disabled
    } elseif {($SortType == 3) || ($SortType == 10)} {
	$hd.st.cnt.bNumSys configure -state normal
	$hd.st.cnt.bDateFormat configure -state disabled
    } else {
	$hd.st.cnt.bDateFormat configure -state disabled
	$hd.st.cnt.bNumSys configure -state disabled
    }
    PackKeyPage $hd
}

proc ToggleFieldSeparatorEntryActive {n e o} {
     if {$::WholeRecordIsKeyP} {
	.gen.ctr.wr.fsent configure -state disabled
    } else {
	.gen.ctr.wr.fsent configure -state normal
	focus .gen.ctr.wr.fsent
    }
}

proc ToggleRecordSeparatorEntryActive {n e o} {
    .gen.ctr.wr.fsent delete 0 end
    switch $::RecordParse {
	0 {
	    .gen.ctr.rp.cent configure -state disabled
	    .gen.ctr.rp.fl.len configure -state disabled
	    .gen.ctr.wr.fsent insert insert {\t\040}
	}
	1 {
	    if {$::EOLCarriageReturnP} {
		.gen.ctr.wr.fsent insert insert {\015}
	    } else {
		.gen.ctr.wr.fsent insert insert {\n}
	    }
	    .gen.ctr.rp.fl.len configure -state disabled
	    .gen.ctr.rp.cent configure -state disabled
	}
	2 {
	    .gen.ctr.rp.fl.len configure -state disabled
	    .gen.ctr.rp.cent configure -state normal
	    focus .gen.ctr.rp.cent;
	}
	3 {
	    .gen.ctr.rp.fl.len configure -state normal
	    focus .gen.ctr.rp.fl.len
	    .gen.ctr.rp.cent configure -state disabled
	}
    }
}

proc UpdateDefaultFieldSeparator {n e o} {
    if {$::RecordParse == 1} {
	.gen.ctr.wr.fsent delete 0 end;
	if {$::EOLCarriageReturnP} {
	    .gen.ctr.wr.fsent insert insert {\015}
	}  else {
	    .gen.ctr.wr.fsent insert insert {\n}
	}
    }
}

proc ToggleOptComparisonActive {n e o} {
    set hd [lindex [split $e ","] 1]
    if {$::KeyInfo($e)} {
	$hd.key.opt.oc.rdb3 configure -state normal
	$hd.key.opt.oc.rdb4 configure -state normal
	$hd.key.opt.oc.rdb5 configure -state normal
    } else {
	$hd.key.opt.oc.rdb3 configure -state disabled
	$hd.key.opt.oc.rdb4 configure -state disabled
	$hd.key.opt.oc.rdb5 configure -state disabled
    }
}

#Character entry code begins here
#Set this to the path to character entry menu
set CEM .menubar.charentry
#Set the default insertion target here.
set InsertionTarget .gen.ctr.wr.fsent;

set CharentryMenuItems 6;
set IPAAIsDisplayedP 0;
set IPACIsDisplayedP 0;
set IPAVIsDisplayedP 0;
set IPADIsDisplayedP 0;
set CharEntryByCodeIsDisplayedP 0;

set DisplayConsonantChartColumnLabelsP 1
set DisplayConsonantChartRowLabelsP 1
set DisplayVowelChartColumnLabelsP 1
set DisplayVowelChartRowLabelsP 1

option add *ipaec.Button.font CharacterEntryFont 100
option add *ipaec.Label.background  $ColorSpecs(IPAEntry,Background)
option add *ipaec.Button.background $ColorSpecs(IPAEntry,Background)
option add *ipaec.Button.foreground $ColorSpecs(IPAEntry,Foreground)
option add *ipaec.Label.relief raised

option add *ipaev.Button.font CharacterEntryFont 100
option add *ipaev.Label.background  $ColorSpecs(IPAEntry,Background)
option add *ipaev.Button.background $ColorSpecs(IPAEntry,Background)
option add *ipaev.Button.foreground $ColorSpecs(IPAEntry,Foreground)
option add *ipaev.Label.relief raised

option add *ipaea.Button.font AccentedLetterFont 100
option add *ipaea.Label.background  "\#E0E0E0"
option add *ipaea.Button.background "\#FFFFFF"
option add *ipaea.Button.foreground "\#000000"
option add *ipaea.Label.relief raised

option add *ipaed.Button.font DiacriticFont 100
#option add *ipaed.Label.background  $ColorSpecs(IPAEntry,Background)
option add *ipaed.Button.background "\#E0E0FF"
option add *ipaed.Label.background "\#E0E0E0"
option add *ipaed.Button.foreground "\#000000"
option add *ipaed.Label.relief raised

proc SetInsertionTargets {tgt} {
    set ::InsertionTarget $tgt;
    set ::CharByCodeInsertionTarget $tgt;
}
#Insert character entry stuff here
set CustomCEMEntries 0;
option add *ipae*.*Label.font CharacterEntryLabelFont 100
option add *ipaec.*Button.font CharacterEntryFont 100
namespace eval ipaentry {
    variable IPAECColumnLabelList [list];
    variable IPAECRowLabelList [list];
    variable IPAEVColumnLabelList [list];
    variable IPAEVRowLabelList [list];

    set row 0;
    variable poa $row;
    incr row;
    variable vlstop $row;
    incr row;
    variable vdstop $row;
    incr row;
    variable vdimplosive $row;
    incr row;
    variable click $row;
    incr row;
    variable nasal  $row;
    incr row;
    variable trill $row;
    incr row;
    variable tap $row;
    incr row;
    variable vlfric $row;
    incr row;
    variable vdfric $row;
    incr row;
    variable vlaffric $row;
    incr row;
    variable vdaffric $row;
    incr row;
    variable approx $row;
    incr row; 
    variable latapprox $row;
    variable lastrow $row;

    set col 0;
    variable manner $col; 
    incr col;
    variable labial $col; 
    incr col;
    variable labiodental $col; 
    incr col;
    variable dental $col; 
    incr col;
    variable alveolar $col;
    incr col;
    variable postalveolar $col; 
    incr col;
    variable retroflex $col; 
    incr col;
    variable palatal $col; 
    incr col;
    variable velar $col; 
    incr col;
    variable uvular $col; 
    incr col;
    variable pharyngeal $col; 
    incr col;
    variable epiglottal $col; 
    incr col;
    variable glottal $col;
    variable lastcolumn $col;

    proc cfesh {} {
	variable vlfric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vlfric $postalveolar] configure -text "\u0161"];
    }
    proc cresh {} {
	variable vlfric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vlfric $postalveolar] configure -text "\u0283"];
    }

    proc cfeshr {} {
	variable vlfric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlfric $retroflex] configure -text "\u1E63"];
    }
    proc creshr {} {
	variable vlfric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlfric $retroflex] configure -text "\u0282"];
    }

    proc cryod {} {
	variable approx
	variable palatal
	eval [list [format ".ipaec.r%dc%d" $approx $palatal] configure -text "j"];
    }

    proc cfyod {} {
	variable approx
	variable palatal
	eval [list [format ".ipaec.r%dc%d" $approx $palatal] configure -text "y"];
    }

    proc crny {} {
	variable nasal
	variable palatal
	eval [list [format ".ipaec.r%dc%d" $nasal $palatal] configure -text "\u0272"];
    }
    proc cfny {} {
	variable nasal
	variable palatal
	eval [list [format ".ipaec.r%dc%d" $nasal $palatal] configure -text "\u00F1"];
    }

    proc crch {} {
	variable vlaffric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vlaffric $postalveolar] configure -text "t\u0283"];
    }
    proc cfch {} {
	variable vlaffric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vlaffric $postalveolar] configure -text "\u010D"];
    }

    proc crchr {} {
	variable vlaffric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlaffric $retroflex] configure -text "\u0288\u0282"];
    }

    proc cfchr {} {
	variable vlaffric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlaffric $retroflex] configure -text "\u1E6D\u1E63"];
    }


    proc crdj {} {
	eval [list [format ".ipaec.r%dc%d" $ipaentry::vdaffric $ipaentry::postalveolar] configure -text "d\u0292"];
    }

    proc cfdj {} {
	eval [list [format ".ipaec.r%dc%d" $ipaentry::vdaffric $ipaentry::postalveolar] configure -text "\u01C6"];
    }

    proc crdjr {} {
	eval [list [format ".ipaec.r%dc%d" $ipaentry::vdaffric $ipaentry::retroflex] configure -text "\u0256\u0290"];
    }

    proc cfdjr {} {
	eval [list [format ".ipaec.r%dc%d" $ipaentry::vdaffric $ipaentry::retroflex] configure -text "\u1E0D\u1E93"];
    }

    proc crzh {} {
	variable vdfric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vdfric $postalveolar] configure -text "\u0292"];
    }
    proc cfzh {} {
	variable vdfric
	variable postalveolar
	eval [list [format ".ipaec.r%dc%d" $vdfric $postalveolar] configure -text "\u017E"];
    }

    proc crtr {} {
	variable vlstop
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlstop $retroflex] configure -text "\u0288"];
    }
    proc cftr {} {
	variable vlstop
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vlstop $retroflex] configure -text "\u1E6D"];
    }

    proc crdr {} {
	variable vdstop
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vdstop $retroflex] configure -text "\u0256"];
    }
    proc cfdr {} {
	variable vdstop
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vdstop $retroflex] configure -text "\u1E0D"];
    }


    proc crnr {} {
	variable nasal
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $nasal $retroflex] configure -text "\u0273"];
    }
    proc cfnr {} {
	variable nasal
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $nasal $retroflex] configure -text "\u1E47"];
    }


    proc crzhr {} {
	variable vdfric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vdfric $retroflex] configure -text "\u0290"];
    }
    proc cfzhr {} {
	variable vdfric
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $vdfric $retroflex] configure -text "\u1E93"];
    }

    proc crflapr {} {
	variable tap;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $tap $retroflex] configure -text "\u027D"];
    }
    proc cfflapr {} {
	variable tap;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $tap $retroflex] configure -text "\u1E5B"];
    }

    proc crlr {} {
	variable latapprox;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $latapprox $retroflex] configure -text "\u026D"];
    }
    proc cflr {} {
	variable latapprox;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $latapprox $retroflex] configure -text "\u1E37"];
    }

    proc crrr {} {
	variable approx;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $approx $retroflex] configure -text "\u027B"];
    }
    proc cfrr {} {
	variable approx;
	variable retroflex
	eval [list [format ".ipaec.r%dc%d" $approx $retroflex] configure -text "\u1E5B"];
    }

    proc bhcham {w} {
	balloonhelp_for $w "The standard IPA character is shown by default. When the mouse\npointer is over the button, the \"North American\" variant is shown.\nRight click to insert the variant."
    }

    proc bhsp {w} {
	balloonhelp_for $w "The characters below and to the right are characters\nthat do not fit neatly into the chart."
    }

    proc UnpackConsonantColumnLabels {} {
	variable IPAECColumnLabelList;
	foreach l $IPAECColumnLabelList {
	    grid forget $l;
	}
    }

    proc PackConsonantColumnLabels {} {
	destroy .ipaec
	PopupIPAEntryC;
    }

    proc UnpackConsonantRowLabels {} {
	variable IPAECRowLabelList;
	foreach l $IPAECRowLabelList {
	    grid forget $l;
	}
    }

    proc PackConsonantRowLabels {} {
	destroy .ipaec;
	PopupIPAEntryC;
    }

    proc UnpackVowelColumnLabels {} {
	variable IPAEVColumnLabelList;
	foreach l $IPAEVColumnLabelList {
	    grid forget $l;
	}
    }

    proc PackVowelColumnLabels {} {
	destroy .ipaev;
	PopupIPAEntryV;
    }

    proc UnpackVowelRowLabels {} {
	variable IPAEVRowLabelList;
	foreach l $IPAEVRowLabelList {
	    grid forget $l;
	}
    }

    proc PackVowelRowLabels {} {
	destroy .ipaev;
	PopupIPAEntryV;
    }

    proc PopupIPAEntryC {} {
	variable poa
	variable vlstop 
	variable vdstop
	variable vdimplosive 
	variable click 
	variable nasal  
	variable trill 
	variable tap 
	variable vlfric 
	variable vdfric 
	variable vlaffric 
	variable vdaffric 
	variable approx 
	variable latapprox
	variable lastrow

	variable manner 
	variable labial 
	variable labiodental 
	variable dental 
	variable alveolar 
	variable postalveolar 
	variable retroflex 
	variable palatal 
	variable velar 
	variable uvular 
	variable pharyngeal 
	variable epiglottal 
	variable glottal
	variable lastcolumn

	variable IPAECColumnLabelList;
	variable IPAECRowLabelList;
	global DisplayConsonantChartColumnLabelsP
	global DisplayConsonantChartRowLabelsP

	set IPAECColumnLabelList [list];
	set IPAECRowLabelList [list];
	
	set xp 2;
	set yp 3;
	set spcolor 	\#c46276;
	toplevel .ipaec -borderwidth 3 -class CharEntry
	wm title .ipaec [_ "Consonant Symbols"]
	BindKeys .ipaec;
	set DownMsg [_ "Display IPA Consonant Chart"];
	set UpMsg   [_ "Remove IPA Consonant Chart"];
	bind .ipaec <Destroy> \
	    "set ::IPACIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPACIndex -label \"$DownMsg\""
	bind .ipaec <Unmap> \
	    "set ::IPACIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPACIndex -label \"$DownMsg\""
	bind .ipaec <Map> \
	    "set ::IPACIsDisplayedP 1;$::CEM entryconfigure $::ToggleIPACIndex -label \"$UpMsg\""
	set tmp [label [format ".ipaec.r%dc%d" $manner $poa] \
	  -text [_ "IPA\nConsonants"]  -padx 5 -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList $tmp;
	lappend IPAECRowLabelList $tmp;
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $labial] \
	    -text [_ "labial"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $labiodental] \
	    -text [_ "labio\ndental"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $dental] \
	    -text [_ "dental"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $alveolar] \
	    -text [_ "alveolar"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $postalveolar] \
	    -text [_ "post\nalveolar"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $retroflex] \
	    -text [_ "retro\nflex"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $palatal] \
	    -text [_ "palatal"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $velar] \
	    -text [_ "velar"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $uvular] \
	    -text [_ "uvular"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $pharyngeal] \
	    -text [_ "pharyn\ngeal"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $epiglottal] \
	    -text [_ "epi\nglottal"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAECColumnLabelList [label [format ".ipaec.r%dc%d" $manner $glottal] \
	    -text [_ "glottal"]   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]

	#Voiceless oral stops
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vlstop $poa] \
	       -text [_ "voiceless stops"] -anchor w  -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list p]}
	set bn [format ".ipaec.r%dc%d"  $vlstop $labial]
	button $bn  -text "p" -padx $xp -pady $yp -command  $cmd \
	    -fg $::ColorSpecs(UserTextEntry,Foreground); #debug
	balloonhelpd_for $bn [_ "voiceless labial stop"]

	label [format ".ipaec.r%dc%d" $vlstop $labiodental] \
	    -text " " -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list t\u032A]}
	set bn [format ".ipaec.r%dc%d"  $vlstop $dental]
	button $bn  -text "t\u032A"   -padx $xp -pady $yp -command  $cmd
	balloonhelpd_for $bn [_ "voiceless dental stop"]

	set cmd {$::InsertionTarget insert insert [list t]}
	set bn [format ".ipaec.r%dc%d"  $vlstop $alveolar]
	button $bn -text "t"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless alveolar stop"]

	label [format ".ipaec.r%dc%d"  $vlstop $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0288]}
	set bn [format ".ipaec.r%dc%d"  $vlstop $retroflex]
	button $bn  -text \u0288   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E6D]}
	bind $bn <Enter> {ipaentry::cftr}
	bind $bn <Leave> {ipaentry::crtr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiceless retroflex stop"]

	set cmd {$::InsertionTarget insert insert [list c]}
	set bn [format ".ipaec.r%dc%d"  $vlstop $palatal]
	button $bn -text "c"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless palatal stop"]

	set cmd {$::InsertionTarget insert insert [list k]}
	set bn [format ".ipaec.r%dc%d" $vlstop $velar]
	button $bn -text "k" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless velar stop"]

	set cmd {$::InsertionTarget insert insert [list q]}
	set bn [format ".ipaec.r%dc%d" $vlstop $uvular]
	button $bn  -text "q"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless uvular stop"]

	label [format ".ipaec.r%dc%d" $vlstop $pharyngeal] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $vlstop $epiglottal] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0294]}
	set bn [format ".ipaec.r%dc%d" $vlstop $glottal]
	button $bn -text \u0294   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless glottal stop"]

	#Voiced oral stops
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vdstop $poa] \
	       -text [_ "voiced stops"] -anchor w   -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list b]}
	set bn [format ".ipaec.r%dc%d" $vdstop $labial]
	button $bn -text "b"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced bilabial stop"]

	label [format ".ipaec.r%dc%d" $vdstop $labiodental] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list d\u032A]}
	set bn [format ".ipaec.r%dc%d" $vdstop $dental]
	button $bn -text "d\u032A"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced dental stop"]

	set cmd {$::InsertionTarget insert insert [list d]}
	set bn [format ".ipaec.r%dc%d" $vdstop $alveolar]
	button  $bn -text "d"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced alveolar stop"]

	label [format ".ipaec.r%dc%d"  $vdstop $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0256]}
	set bn [format ".ipaec.r%dc%d"  $vdstop $retroflex]
	button $bn  -text \u0256   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E0D]}
	bind $bn <Enter> {ipaentry::cfdr}
	bind $bn <Leave> {ipaentry::crdr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiced retroflex stop"]

	set cmd {$::InsertionTarget insert insert [list \u025F]}
	set bn [format ".ipaec.r%dc%d" $vdstop $palatal]
	button $bn -text \u025F   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced palatal stop"]


	set cmd {$::InsertionTarget insert insert [list g]}
	set bn [format ".ipaec.r%dc%d" $vdstop $velar]
	button $bn -text "g"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced velar stop"]

	set cmd {$::InsertionTarget insert insert [list \u0262]}
	set bn [format ".ipaec.r%dc%d" $vdstop $uvular]
	button $bn -text \u0262  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced uvular stop"]

	label [format ".ipaec.r%dc%d" $vdstop $pharyngeal] -text " "  -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u02A1]}
	set bn [format ".ipaec.r%dc%d" $vdstop $epiglottal]
	button $bn -text \u02A1  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced epiglottal stop"]

	label [format ".ipaec.r%dc%d" $vdstop $glottal] -text " "  -padx $xp -pady $yp

	#Nasals
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $nasal $poa] \
	       -text [_ "nasals"] -anchor w -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list m]}
	set bn [format ".ipaec.r%dc%d" $nasal $labial]
	button $bn -text "m" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "bilabial nasal"]

	set cmd {$::InsertionTarget insert insert [list \u0271]}
	set bn [format ".ipaec.r%dc%d" $nasal $labiodental]
	button $bn -text \u0271   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "labiodental nasal"]

	set cmd {$::InsertionTarget insert insert [list n\u032A]}
	set bn [format ".ipaec.r%dc%d" $nasal $dental]
	button $bn -text n\u032A   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "dental nasal"]

	set cmd {$::InsertionTarget insert insert [list n]}
	set bn [format ".ipaec.r%dc%d" $nasal $alveolar]
	button $bn -text "n"      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "alveolar nasal"]

	label [format ".ipaec.r%dc%d"  $nasal $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0273]}
	set bn [format ".ipaec.r%dc%d"  $nasal $retroflex]
	button $bn  -text \u0273   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E47]}
	bind $bn <Enter> {ipaentry::cfnr}
	bind $bn <Leave> {ipaentry::crnr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "retroflex nasal"]

	set cmd {$::InsertionTarget insert insert [list \u0272]}
	set bn [format ".ipaec.r%dc%d" $nasal $palatal]
	button $bn  -text \u0272    -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u00F1]}
	bind $bn <Enter> {ipaentry::cfny}
	bind $bn <Leave> {ipaentry::crny}
	bhcham $bn;
	balloonhelpd_for $bn [_ "palatal nasal"]

	set cmd {$::InsertionTarget insert insert [list \u014B]}
	set bn [format ".ipaec.r%dc%d" $nasal $velar]
	button $bn -text \u014B    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "velar nasal"]

	set cmd {$::InsertionTarget insert insert [list \u0274]}
	set bn [format ".ipaec.r%dc%d" $nasal $uvular]
	button $bn -text \u0274    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "uvular nasal"]

	label [format ".ipaec.r%dc%d" $nasal $pharyngeal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $nasal $epiglottal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $nasal $glottal] -text " "    -padx $xp -pady $yp

	#Voiceless fricatives
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vlfric $poa] \
	       -text [_ "voiceless fricatives"] -anchor w  -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list \u03C6]}
	set bn [format ".ipaec.r%dc%d" $vlfric $labial]
	button $bn -text \u03C6  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless bilabial fricative"]

	set cmd {$::InsertionTarget insert insert [list f]}
	set bn [format ".ipaec.r%dc%d" $vlfric $labiodental]
	button $bn  -text "f"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless labiodental fricative"]

	set cmd {$::InsertionTarget insert insert [list \u03B8]}
	set bn [format ".ipaec.r%dc%d" $vlfric $dental]
	button $bn -text \u03B8   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless dental fricative"]

	set cmd {$::InsertionTarget insert insert [list "s"]}
	set bn [format ".ipaec.r%dc%d" $vlfric $alveolar]
	button $bn -text "s"  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless alveolar fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0283]}
	set bn [format ".ipaec.r%dc%d" $vlfric $postalveolar];
	button $bn -text \u0283   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u0161]}
	bind $bn <Enter> {ipaentry::cfesh}
	bind $bn <Leave> {ipaentry::cresh}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiceless postalveolar fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0282]}
	set bn [format ".ipaec.r%dc%d" $vlfric $retroflex];
	button $bn -text \u0282   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E63]}
	bind $bn <Enter> {ipaentry::cfeshr}
	bind $bn <Leave> {ipaentry::creshr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiceless retroflex fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0255]}
	set bn [format ".ipaec.r%dc%d" $vlfric $palatal]
	button $bn -text \u0255  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless palatal fricative"]

	set cmd {$::InsertionTarget insert insert [list "x"]}
	set bn [format ".ipaec.r%dc%d" $vlfric $velar]
	button $bn -text "x" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless velar fricative"]

	set cmd {$::InsertionTarget insert insert [list "\u03C7"]}
	set bn [format ".ipaec.r%dc%d" $vlfric $uvular]
	button $bn -text "\u03C7"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless uvular fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0127]}
	set bn [format ".ipaec.r%dc%d" $vlfric $pharyngeal]
	button $bn -text \u0127 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless pharyngeal fricative"]

	set cmd {$::InsertionTarget insert insert [list \u029C]}
	set bn [format ".ipaec.r%dc%d" $vlfric $epiglottal]
	button $bn -text \u029C   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless epiglottal fricative"]

	set cmd {$::InsertionTarget insert insert [list "h"]}
	set bn [format ".ipaec.r%dc%d" $vlfric $glottal]
	button $bn -text "h" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless glottal fricative"]

	#Voiced fricatives
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vdfric $poa] \
	       -text [_ "voiced fricatives"] -anchor w \
	       -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list \u03B2]}
	set bn [format ".ipaec.r%dc%d" $vdfric $labial]
	button $bn -text \u03B2  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced bilabial fricative"]

	set cmd {$::InsertionTarget insert insert [list v]}
	set bn [format ".ipaec.r%dc%d" $vdfric $labiodental]
	button $bn -text "v" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced labiodental fricative"]

	set cmd {$::InsertionTarget insert insert [list "\u00F0"]}
	set bn [format ".ipaec.r%dc%d" $vdfric $dental]
	button $bn -text "\u00F0"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced dental fricative"]

	set cmd {$::InsertionTarget insert insert [list "z"]}
	set bn [format ".ipaec.r%dc%d" $vdfric $alveolar]
	button $bn -text "z"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced alveolar fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0292]}
	set bn [format ".ipaec.r%dc%d" $vdfric $postalveolar]
	button $bn -text \u0292  -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u017E]}
	bind $bn <Enter> {ipaentry::cfzh}
	bind $bn <Leave> {ipaentry::crzh}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiced postalveolar fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0290]}
	set bn [format ".ipaec.r%dc%d" $vdfric $retroflex]
	button $bn -text \u0290   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E93]}
	bind $bn <Enter> {ipaentry::cfzhr}
	bind $bn <Leave> {ipaentry::crzhr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiced retroflex fricative"]

	set cmd {$::InsertionTarget insert insert [list \u029D]}
	set bn [format ".ipaec.r%dc%d" $vdfric $palatal]
	button $bn -text  \u029D  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced palatal fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0263]}
	set bn [format ".ipaec.r%dc%d" $vdfric $velar]
	button $bn -text \u0263  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced velar fricative"]

	set cmd {$::InsertionTarget insert insert [list "\u0281"]}
	set bn [format ".ipaec.r%dc%d" $vdfric $uvular]
	button $bn -text "\u0281" -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced uvular fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0295]}
	set bn [format ".ipaec.r%dc%d" $vdfric $pharyngeal]
	button $bn -text \u0295 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced pharyngeal fricative"]

	set cmd {$::InsertionTarget insert insert [list \u02A2]}
	set bn [format ".ipaec.r%dc%d" $vdfric $epiglottal] 
	button $bn -text \u02A2    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced epiglottal fricative"]

	set cmd {$::InsertionTarget insert insert [list \u0266]}
	set bn [format ".ipaec.r%dc%d" $vdfric $glottal]
	button $bn -text \u0266    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced glottal fricative"]

	#trills
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $trill $poa] \
	       -text [_ "trills"] -anchor w   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list \u0299]}
	set bn [format ".ipaec.r%dc%d" $trill $labial]
	button  $bn -text \u0299      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "bilabial trill"]

	label [format ".ipaec.r%dc%d" $trill $labiodental] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $trill $dental] -text " "   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list r]}
	set bn [format ".ipaec.r%dc%d" $trill $alveolar]
	button $bn -text "r"      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "alveolar trill"]

	label [format ".ipaec.r%dc%d"  $trill $postalveolar] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d"  $trill $retroflex] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $trill $palatal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $trill $velar] -text " "    -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0280]}
	set bn [format ".ipaec.r%dc%d" $trill $uvular]
	button $bn -text \u0280    -padx $xp -pady $yp
	balloonhelpd_for $bn [_ "uvular trill"] -command $cmd

	label [format ".ipaec.r%dc%d" $trill $pharyngeal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $trill $epiglottal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $trill $glottal] -text " "    -padx $xp -pady $yp

	#taps and flaps
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $tap $poa] \
	       -text [_ "taps/flaps"] -anchor w   -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	label [format ".ipaec.r%dc%d" $tap $labial] -text " "      -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $labiodental] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $dental] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u027E]}
	set bn [format ".ipaec.r%dc%d" $tap $alveolar]
	button $bn -text \u027E -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "uvular trill"]

	label [format ".ipaec.r%dc%d"  $tap $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u027D]}
	set bn [format ".ipaec.r%dc%d"  $tap $retroflex];
	button $bn -text \u027D   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E5B]}
	bind $bn <Enter> {ipaentry::cfflapr}
	bind $bn <Leave> {ipaentry::crflapr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "retroflex tap"]

	label [format ".ipaec.r%dc%d" $tap $palatal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $velar] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $uvular] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $pharyngeal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $epiglottal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $tap $glottal] -text " "    -padx $xp -pady $yp

	#approximants
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $approx $poa] \
	       -text [_ "approximants"] -anchor w \
	       -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	label [format ".ipaec.r%dc%d" $approx $labial] -text " "      -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u028B]}
	set bn [format ".ipaec.r%dc%d" $approx $labiodental]
	button $bn -text \u028B   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "labiodental approximant"]

	label [format ".ipaec.r%dc%d" $approx $dental] -text " "   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u0279]}
	set bn [format ".ipaec.r%dc%d" $approx $alveolar]
	button $bn -text  \u0279 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "alveolar approximant"]

	label [format ".ipaec.r%dc%d"  $approx $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u027B]}
	set bn [format ".ipaec.r%dc%d"  $approx $retroflex]
	button $bn -text \u027B   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E5B]}
	bind $bn <Enter> {ipaentry::cfrr}
	bind $bn <Leave> {ipaentry::crrr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "retroflex approximant"]

	set cmd {$::InsertionTarget insert insert [list "j"]}
	set bn [format ".ipaec.r%dc%d" $approx $palatal]
	button $bn -text "j"    -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list "y"]}
	bind $bn <Enter> {ipaentry::cfyod}
	bind $bn <Leave> {ipaentry::cryod}
	bhcham $bn;
	balloonhelpd_for $bn [_ "palatal approximant"]

	set cmd {$::InsertionTarget insert insert [list \u0270]}
	set bn [format ".ipaec.r%dc%d" $approx $velar]
	button $bn  -text \u0270    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "velar approximant"]

	label [format ".ipaec.r%dc%d" $approx $uvular] -text " "  \
	    -padx $xp -pady $yp -bg $spcolor
	label [format ".ipaec.r%dc%d" $approx $pharyngeal] -text " "  \
	    -padx $xp -pady $yp -bg $spcolor

	#label [format ".ipaec.r%dc%d" $approx $epiglottal] -text " "  \
	    -padx $xp -pady $yp -bg $spcolor
	#label [format ".ipaec.r%dc%d" $approx $glottal] -text " "   \
	    -padx $xp -pady $yp -bg $spcolor

	#lateral approximants
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $latapprox $poa] \
	       -text [_ "lateral approximants"] -anchor w \
	       -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	label [format ".ipaec.r%dc%d" $latapprox $labial] -text " "      -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $latapprox $labiodental] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $latapprox $dental] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list "l"]}
	set bn [format ".ipaec.r%dc%d" $latapprox $alveolar]
	button $bn -text "l"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "alveolar lateral approximant"]

	label [format ".ipaec.r%dc%d"  $latapprox $postalveolar] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u026D]}
	set bn [format ".ipaec.r%dc%d"  $latapprox $retroflex]
	button $bn  -text \u026D   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E37]}
	bind $bn <Enter> {ipaentry::cflr}
	bind $bn <Leave> {ipaentry::crlr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "retroflex lateral approximant"]

	set cmd {$::InsertionTarget insert insert [list \u028E]}
	set bn [format ".ipaec.r%dc%d" $latapprox $palatal]
	button $bn -text \u028E    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "palatal lateral approximant"]

	set cmd {$::InsertionTarget insert insert [list \u029F]}
	set bn [format ".ipaec.r%dc%d" $latapprox $velar]
	button $bn -text \u029F    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "velar lateral approximant"]

	label [format ".ipaec.r%dc%d" $latapprox $uvular] -text " "  \
	    -padx $xp -pady $yp -bg $spcolor
	#label [format ".ipaec.r%dc%d" $latapprox $pharyngeal] -text " "  \
	    -padx $xp -pady $yp -bg $spcolor
	#label [format ".ipaec.r%dc%d" $latapprox $epiglottal] -text " "  \
	    -padx $xp -pady $yp
	#label [format ".ipaec.r%dc%d" $latapprox $glottal] -text " "  \
	    -padx $xp -pady $yp

	#voiced implosives
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vdimplosive $poa] \
	       -text [_ "voiced implosives"] -anchor w \
	       -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list \u0253]}
	set bn [format ".ipaec.r%dc%d" $vdimplosive $labial]
	button $bn -text \u0253 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced bilabial implosive"]

	label [format ".ipaec.r%dc%d" $vdimplosive $labiodental] -text " " \
	    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $vdimplosive $dental] -text " "  \
	    -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u0257]}
	set bn [format ".ipaec.r%dc%d" $vdimplosive $alveolar]
	button $bn -text \u0257   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced alveolar implosive"]

	label [format ".ipaec.r%dc%d"  $vdimplosive $postalveolar] -text " " \
	    -padx $xp -pady $yp

	#Not officially recognized by IPA yet.
	set cmd {$::InsertionTarget insert insert [list \u1D91]}
	set bn [format ".ipaec.r%dc%d"  $vdimplosive $retroflex]
	button $bn -text \u1D91  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced retroflex implosive"]

	set cmd {$::InsertionTarget insert insert [list \u0284]}
	set bn [format ".ipaec.r%dc%d" $vdimplosive $palatal]
	button $bn -text \u0284  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced palatal implosive"]

	set cmd {$::InsertionTarget insert insert [list \u0260]}
	set bn [format ".ipaec.r%dc%d" $vdimplosive $velar]
	button $bn -text \u0260 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced velar implosive"]

	set cmd {$::InsertionTarget insert insert [list \u029B]}
	set bn [format ".ipaec.r%dc%d" $vdimplosive $uvular]
	button $bn -text \u029B    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced uvular implosive"]

	label [format ".ipaec.r%dc%d" $vdimplosive $pharyngeal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $vdimplosive $epiglottal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $vdimplosive $glottal] -text " "    -padx $xp -pady $yp

	#clicks
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $click $poa] \
	       -text [_ "clicks"] -anchor w  -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list \u0298]}
	set bn [format ".ipaec.r%dc%d" $click $labial]
	button $bn -text \u0298      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "labial click"]

	label [format ".ipaec.r%dc%d" $click $labiodental] -text " "   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list \u01C0]}
	set bn [format ".ipaec.r%dc%d" $click $dental]
	button $bn -text \u01C0   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "dental click"]

	set cmd {$::InsertionTarget insert insert [list \u01C2]}
	set bn [format ".ipaec.r%dc%d" $click $alveolar]
	button $bn -text \u01C2   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "alveolar click"]

	set cmd {$::InsertionTarget insert insert [list \u01C3]}
	set bn [format ".ipaec.r%dc%d"  $click $postalveolar]
	button $bn -text \u01C3 \
	    -padx $xp -pady $yp  -command $cmd
	balloonhelpd_for $bn [_ "postalveolar click"]

	label [format ".ipaec.r%dc%d"  $click $retroflex] -text " "   -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $click $palatal] -text " "  -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $click $velar] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $click $uvular] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $click $pharyngeal] -text " "    -padx $xp -pady $yp
	label [format ".ipaec.r%dc%d" $click $epiglottal] -text " "    -padx $xp -pady $yp
	set cmd {BackDelete $::InsertionTarget}
	set bn [format ".ipaec.r%dc%d" $click $glottal];
	button $bn -text [_ "Delete"]  -padx $xp -pady $yp -command $cmd -background "\#E0D0FF";
	set DeleteButton $bn;


	#Voiceless affricates
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vlaffric $poa] \
	       -text [_ "voiceless affricates"] -anchor w -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list p\u03C6]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $labial]
	button $bn -text "p\u03C6"      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless bilabial affricate"]

	label [format ".ipaec.r%dc%d" $vlaffric $labiodental] -text "" -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list t\u03B8]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $dental]
	button $bn -text "t\u03B8"   -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless dental affricate"]

	set cmd {$::InsertionTarget insert insert [list "ts"]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $alveolar]
	button $bn -text "ts"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless alveolar affricate"]

	set cmd {$::InsertionTarget insert insert [list t\u0283]}
	set bn [format ".ipaec.r%dc%d"  $vlaffric $postalveolar]
	button $bn -text "t\u0283"   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u010D]}
	bind $bn <Enter> {ipaentry::cfch}
	bind $bn <Leave> {ipaentry::crch}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiceless postalveolar affricate"]

	set cmd {$::InsertionTarget insert insert [list \u0288\u0282]}
	set bn [format ".ipaec.r%dc%d"  $vlaffric $retroflex]
	button $bn -text \u0288\u0282   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E6D\u1E63]}
	bind $bn <Enter> {ipaentry::cfchr}
	bind $bn <Leave> {ipaentry::crchr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiceless retroflex affricate"]

	set cmd {$::InsertionTarget insert insert [list t\u0255]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $palatal]
	button $bn -text t\u0255 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless palatal affricate"]

	set cmd {$::InsertionTarget insert insert [list "kx"]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $velar]
	button $bn -text "kx"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless velar affricate"]

	set cmd {$::InsertionTarget insert insert [list "q\u03C7"]}
	set bn [format ".ipaec.r%dc%d" $vlaffric $uvular]
	button $bn -text "q\u03C7"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiceless uvular affricate"]

	label [format ".ipaec.r%dc%d" $vlaffric $pharyngeal] -text "" \
	    -padx $xp -pady $yp -bg $spcolor
	label [format ".ipaec.r%dc%d" $vlaffric $epiglottal] -text "" \
	    -padx $xp -pady $yp -bg $spcolor
	label [format ".ipaec.r%dc%d" $vlaffric $glottal] -text "" \
	    -padx $xp -pady $yp -bg $spcolor

	#Voiced affricate
	lappend IPAECRowLabelList [label [format ".ipaec.r%dc%d" $vdaffric $poa] \
	       -text [_ "voiced affricates"] -anchor w -padx $xp -pady $yp \
	       -bg $::ColorSpecs(IPAHeadings,Background)]

	set cmd {$::InsertionTarget insert insert [list b\u03B2]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $labial]
	button $bn -text b\u03B2      -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced bilabial affricate"]

	label [format ".ipaec.r%dc%d" $vdaffric $labiodental] -text ""   -padx $xp -pady $yp

	set cmd {$::InsertionTarget insert insert [list "d\u00F0"]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $dental]
	button $bn -text "d\u00F0"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced dental affricate"]

	set cmd {$::InsertionTarget insert insert [list "dz"]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $alveolar]
	button  $bn -text "dz"  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced alveolar affricate"]

	set cmd {$::InsertionTarget insert insert [list d\u0292]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $postalveolar]
	button $bn -text d\u0292  -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u01C6]}
	bind $bn <Enter> {ipaentry::cfdj}
	bind $bn <Leave> {ipaentry::crdj}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiced postalveolar affricate"]

	set cmd {$::InsertionTarget insert insert [list \u0256\u0290]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $retroflex]
	button $bn -text \u0256\u0290   -padx $xp -pady $yp -command $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u1E0D\u1E93]}
	bind $bn <Enter> {ipaentry::cfdjr}
	bind $bn <Leave> {ipaentry::crdjr}
	bhcham $bn;
	balloonhelpd_for $bn [_ "voiced retroflex affricate"]

	set cmd {$::InsertionTarget insert insert [list d\u029D]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $palatal]
	button $bn -text  d\u029D  -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced palatal affricate"]

	set cmd {$::InsertionTarget insert insert [list g\u0263]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $velar]
	button $bn -text g\u0263    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced velar affricate"]

	set cmd {$::InsertionTarget insert insert [list "\u0262\u0281"]}
	set bn [format ".ipaec.r%dc%d" $vdaffric $uvular]
	button $bn -text "\u0262\u0281"    -padx $xp -pady $yp -command $cmd
	balloonhelpd_for $bn [_ "voiced uvular affricate"]

	label [format ".ipaec.r%dc%d" $vdaffric $pharyngeal] -text "" \
	    -padx $xp -pady $yp -bg $spcolor
	#label [format ".ipaec.r%dc%d" $vdaffric $epiglottal] -text "" \
	    -padx $xp -pady $yp -bg $spcolor
	#label [format ".ipaec.r%dc%d" $vdaffric $glottal] -text ""   \
	    -padx $xp -pady $yp -bg $spcolor

	set cmd {$::InsertionTarget insert insert [list "\u028D"]}
	button .ipaec.r13c10 -text \u028D -padx $xp -pady $yp -command $cmd
	balloonhelpd_for .ipaec.r13c10  [_ "Voiceless labio-velar fricative"]
	set cmd {$::InsertionTarget insert insert [list "\u0265"]}
	button .ipaec.r11c11 -text \u0265 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for .ipaec.r11c11  [_ "Voiced labio-palatal approximant"]
	set cmd {$::InsertionTarget insert insert [list "\u0077"]}
	button .ipaec.r11c12 -text \u0077 -padx $xp -pady $yp -command $cmd
	balloonhelpd_for .ipaec.r11c12  [_ "Voiced labio-velar approximant"]
	set cmd {$::InsertionTarget insert insert [list "\u01C1"]}
	button .ipaec.r12c11 -text \u01C1 -padx $xp -pady $yp -command $cmd
	set cmd {$::InsertionTarget insert insert [list "\u02A0"]}
	button .ipaec.r12c12 -text \u02A0 -padx $xp -pady $yp -command $cmd
	set cmd {$::InsertionTarget insert insert [list "\u026C"]}
	button .ipaec.r13c11 -text \u026C -padx $xp -pady $yp -command $cmd
	set cmd {$::InsertionTarget insert insert [list "\u026E"]}
	button .ipaec.r13c12 -text \u026E -padx $xp -pady $yp -command $cmd

	for {set row 0} {$row <= $lastrow} {incr row} {
	    set line [list];
	    for {set col 0} {$col <= $lastcolumn} {incr col} {
		set cell [format ".ipaec.r%dc%d" $row $col]
		lappend line $cell
		if {[string equal [winfo class $cell] "Label"]} {
		    balloonhelp_for $cell  [_ "Left click to insert standard characters.\nRight click to insert alternative characters."]
		}
	    }
	    eval grid $line -sticky news;
	}
	balloonhelpd_for .ipaec.r12c11  [_ "Lateral click"]
	balloonhelpd_for .ipaec.r12c12  [_ "Voiceless uvular implosive"]
	balloonhelpd_for .ipaec.r13c11  [_ "Voiceless lateral fricative"]
	balloonhelpd_for .ipaec.r13c12  [_ "Voiced lateral fricative"]
	bhsp [format ".ipaec.r%dc%d" $latapprox $uvular]
	bhsp [format ".ipaec.r%dc%d" $approx $uvular]
	bhsp [format ".ipaec.r%dc%d" $approx $pharyngeal]
	bhsp [format ".ipaec.r%dc%d" $vlaffric $pharyngeal]
	bhsp [format ".ipaec.r%dc%d" $vlaffric $epiglottal]
	bhsp [format ".ipaec.r%dc%d" $vlaffric $glottal]
	bhsp [format ".ipaec.r%dc%d" $vdaffric $pharyngeal]
	balloonhelpd_for $DeleteButton [_ "No, there isn't a glottal click  called \"Delete\".\nThis is so that you can correct mistakes while using\nthe mouse, without having to go back to the keyboard."]
	after idle {
	    update idletasks
	    raise .ipaec;
	}
	if {!$DisplayConsonantChartColumnLabelsP} {UnpackConsonantColumnLabels}
	if {!$DisplayConsonantChartRowLabelsP} {UnpackConsonantRowLabels}
    }

    set row 0;
    variable frontness $row;
    incr row;
    variable close $row;
    incr row;
    variable closeclosemid $row;
    incr row;
    variable closemid $row;
    incr row;
    variable midmid $row;
    incr row;
    variable openmid $row;
    incr row;
    variable openopenmid $row;
    incr row;
    variable open $row;
    variable lastvrow $row;

    set col 0;
    variable height $col; 
    incr col;
    variable fronturd $col;
    incr col;
    variable frontrnd $col;
    incr col;
    variable centurd $col;
    incr col;
    variable centrnd $col;
    incr col;
    variable backurd $col;
    incr col;
    variable backrnd $col;
    variable lastvcolumn $col;

    proc vry {} {
	variable close
	variable frontrnd
	eval [list [format ".ipaev.r%dc%d" $close $frontrnd] configure -text "y"];
	}
    
    proc vfy {} {
	variable close
	variable frontrnd
	eval [list [format ".ipaev.r%dc%d" $close $frontrnd] configure -text "\u00FC"];
	}

    proc vrphi {} {
	variable frontrnd;
	variable closemid
	eval [list [format ".ipaev.r%dc%d" $closemid $frontrnd] configure -text "\u00F8"];
    }
    
    proc vfphi {} {
	variable frontrnd;
	variable closemid
	eval [list [format ".ipaev.r%dc%d" $closemid $frontrnd] configure -text "o\u0308"];
    }

    proc vroe {} {
	variable frontrnd;
	variable openmid
	eval [list [format ".ipaev.r%dc%d" $openmid $frontrnd] configure -text "\u0153"];
    }

    proc vfoe {} {
	variable frontrnd;
	variable openmid
	eval [list [format ".ipaev.r%dc%d" $openmid $frontrnd] configure -text "\u0254\0308"];
    }


    proc PopupIPAEntryV {} {
	variable frontness
	variable close
	variable closeclosemid
	variable closemid
	variable openmid
	variable midmid
	variable openopenmid
	variable open
	variable lastvrow

	variable height
	variable fronturd
	variable frontrnd
	variable centurd
	variable centrnd
	variable backurd
	variable backrnd
	variable lastvcolumn

	variable IPAEVColumnLabelList
	variable IPAEVRowLabelList
	global DisplayVowelChartColumnLabelsP
	global DisplayVowelChartRowLabelsP

	set xp 2;
	set yp 3;
	toplevel .ipaev -borderwidth 3
	wm title .ipaev [_ "Vowel Symbols"]
	BindKeys .ipaev;
	set DownMsg [_ "Display IPA Vowel Chart"];
	set UpMsg   [_ "Remove IPA Vowel Chart"];
	bind .ipaev <Destroy> \
	    "set ::IPAVIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPAVIndex -label \"$DownMsg\""
	bind .ipaev <Unmap> \
	    "set ::IPAVIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPAVIndex -label \"$DownMsg\""
	bind .ipaev <Map> \
	    "set ::IPAVIsDisplayedP 1;$::CEM entryconfigure $::ToggleIPAVIndex -label \"$UpMsg\""

	#Column headers
	set tmp [label [format ".ipaev.r%dc%d" $height $frontness] \
	     -text [_ "IPA\nVowels"]  -padx $xp -pady $yp -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList $tmp;
	lappend IPAEVRowLabelList $tmp;
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $fronturd] \
	     -text [_ "Front\nUnrounded"]  -padx $xp -pady $yp \
     	     -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $frontrnd] \
	     -text [_ "Front\nRounded"]  -padx $xp -pady $yp \
  	     -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $centurd] \
	     -text [_ "Central\nUnrounded"]  -padx $xp -pady $yp \
	     -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $centrnd] \
	     -text [_ "Central\nRounded"]  -padx $xp -pady $yp \
   	     -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $backurd] \
	     -text [_ "Back\nUnrounded"]  -padx $xp -pady $yp \
  	     -bg $::ColorSpecs(IPAHeadings,Background)]
	lappend IPAEVColumnLabelList [label [format ".ipaev.r%dc%d" $height $backrnd] \
	     -text [_ "Back\nRounded"]  -padx $xp -pady $yp \
  	     -bg $::ColorSpecs(IPAHeadings,Background)]


	#Close vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $close $frontness] \
	   -text [_ "Close"] -anchor w  -padx $xp -pady $yp \
  	   -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list i]}
	button [format ".ipaev.r%dc%d"  $close $fronturd] \
	     -text "i"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list y]}
	set bn  [format ".ipaev.r%dc%d"  $close $frontrnd]
	button $bn -text "y"   -padx $xp -pady $yp -command  $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u00FC]}
	bind $bn <Enter> {ipaentry::vfy}
	bind $bn <Leave> {ipaentry::vry}
	bhcham $bn;

	set cmd {$::InsertionTarget insert insert [list \u0268]}
	button [format ".ipaev.r%dc%d"  $close $centurd] \
	     -text "\u0268"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0289]}
	button [format ".ipaev.r%dc%d"  $close $centrnd] \
	     -text "\u0289"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0268]}
	button [format ".ipaev.r%dc%d"  $close $backurd] \
	     -text "\u0268"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list u]}
	button [format ".ipaev.r%dc%d"  $close $backrnd] \
	     -text "u"   -padx $xp -pady $yp -command  $cmd

	# Close close mid vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $closeclosemid $frontness] \
	     -text [_ "Close Close Mid"] -anchor w  -padx $xp -pady $yp \
	  -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list I]}
	button [format ".ipaev.r%dc%d"  $closeclosemid $fronturd] \
	     -text "I"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list Y]}
	button [format ".ipaev.r%dc%d"  $closeclosemid $frontrnd] \
	     -text "Y"   -padx $xp -pady $yp -command  $cmd
	label [format ".ipaev.r%dc%d"  $closeclosemid $centurd] \
	     -text ""   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u028A]}
	button [format ".ipaev.r%dc%d"  $closeclosemid $centrnd] \
	     -text "\u028A"   -padx $xp -pady $yp -command  $cmd
	label [format ".ipaev.r%dc%d"  $closeclosemid $backurd] \
	     -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $closeclosemid $backrnd] \
	     -text ""   -padx $xp -pady $yp

	# Close mid vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $closemid $frontness] \
	     -text [_ "Close Mid"] -anchor w  -padx $xp -pady $yp \
	  -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list e]}
	button [format ".ipaev.r%dc%d"  $closemid $fronturd] \
	     -text "e"   -padx $xp -pady $yp -command  $cmd

	set cmd {$::InsertionTarget insert insert [list \u00F8]}
	set bn [format ".ipaev.r%dc%d"  $closemid $frontrnd]
	button $bn -text "\u00F8"   -padx $xp -pady $yp -command  $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list o\u0308]}
	bind $bn <Enter> {ipaentry::vfphi}
	bind $bn <Leave> {ipaentry::vrphi}
	bhcham $bn;

	set cmd {$::InsertionTarget insert insert [list \u0258]}
	button [format ".ipaev.r%dc%d"  $closemid $centurd] \
	     -text "\u0258"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0275]}
	button [format ".ipaev.r%dc%d"  $closemid $centrnd] \
	     -text "\u0275"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0264]}
	button [format ".ipaev.r%dc%d"  $closemid $backurd] \
	     -text "\u0264"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list o]}
	button [format ".ipaev.r%dc%d"  $closemid $backrnd] \
	     -text "o"   -padx $xp -pady $yp -command  $cmd

	# Mid mid vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $midmid $frontness] \
	     -text [_ "Mid Mid"] -anchor w  -padx $xp -pady $yp \
	  -bg $::ColorSpecs(IPAHeadings,Background)]
	label [format ".ipaev.r%dc%d"  $midmid $fronturd] \
	     -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $midmid $frontrnd] \
	     -text ""   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u0259]}
	button [format ".ipaev.r%dc%d"  $midmid $centurd] \
	     -text "\u0259"   -padx $xp -pady $yp -command  $cmd
	set cmd {BackDelete $::InsertionTarget}
	set bn [format ".ipaev.r%dc%d" $midmid $centrnd];
	button $bn -text [_ "Delete"]  \
	     -padx $xp -pady $yp -command $cmd -background "\#E0D0FF";
	set DeleteButton $bn;
	label [format ".ipaev.r%dc%d"  $midmid $backurd] -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $midmid $backrnd] -text ""   -padx $xp -pady $yp

	# Open mid vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $openmid $frontness] \
	     -text [_ "Open Mid"] -anchor w  -padx $xp -pady $yp \
  	     -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list \u025B]}
	button [format ".ipaev.r%dc%d"  $openmid $fronturd] \
	     -text \u025B   -padx $xp -pady $yp -command  $cmd

	set cmd {$::InsertionTarget insert insert [list \u0153]}
	set bn [format ".ipaev.r%dc%d"  $openmid $frontrnd]
	button $bn -text "\u0153"   -padx $xp -pady $yp -command  $cmd
	bind $bn <<B3>> {$::InsertionTarget insert insert [list \u0254\u0308]}
	bind $bn <Enter> {ipaentry::vfoe}
	bind $bn <Leave> {ipaentry::vroe}
	bhcham $bn;

	set cmd {$::InsertionTarget insert insert [list \u025C]}
	button [format ".ipaev.r%dc%d"  $openmid $centurd] \
	     -text "\u025C"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u025E]}
	button [format ".ipaev.r%dc%d"  $openmid $centrnd] \
	     -text "\u025E"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u028C]}
	button [format ".ipaev.r%dc%d"  $openmid $backurd] \
	     -text "\u028C"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0254]}
	button [format ".ipaev.r%dc%d"  $openmid $backrnd] \
	     -text "\u0254"   -padx $xp -pady $yp -command  $cmd

	# Open open mid vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $openopenmid $frontness] \
	     -text [_ "Open Open Mid"] -anchor w  -padx $xp -pady $yp \
  	     -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list \u00E6]}
	button [format ".ipaev.r%dc%d"  $openopenmid $fronturd] \
	     -text \u00E6   -padx $xp -pady $yp -command  $cmd
	label [format ".ipaev.r%dc%d"  $openopenmid $frontrnd] -text ""   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u0250]}
	button [format ".ipaev.r%dc%d"  $openopenmid $centurd] \
	     -text "\u0250"   -padx $xp -pady $yp -command  $cmd
	label [format ".ipaev.r%dc%d"  $openopenmid $centrnd] \
		     -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $openopenmid $backurd] \
	     -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $openopenmid $backrnd] \
	     -text ""   -padx $xp -pady $yp

	# Open  vowels
	lappend IPAEVRowLabelList [label [format ".ipaev.r%dc%d" $open $frontness] \
	   -text [_ "Open"] -anchor w  -padx $xp -pady $yp \
	   -bg $::ColorSpecs(IPAHeadings,Background)]
	set cmd {$::InsertionTarget insert insert [list a]}
	button [format ".ipaev.r%dc%d"  $open $fronturd] \
	     -text "a"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0276]}
	button [format ".ipaev.r%dc%d"  $open $frontrnd] \
	     -text "\u0276"   -padx $xp -pady $yp -command  $cmd
	label [format ".ipaev.r%dc%d"  $open $centurd] \
	     -text ""   -padx $xp -pady $yp
	label [format ".ipaev.r%dc%d"  $open $centrnd] \
	     -text ""   -padx $xp -pady $yp
	set cmd {$::InsertionTarget insert insert [list \u0251]}
	button [format ".ipaev.r%dc%d"  $open $backurd] \
	     -text "\u0251"   -padx $xp -pady $yp -command  $cmd
	set cmd {$::InsertionTarget insert insert [list \u0252]}
	button [format ".ipaev.r%dc%d"  $open  $backrnd] \
	     -text "\u0252"   -padx $xp -pady $yp -command  $cmd

	for {set row 0} {$row <= $lastvrow} {incr row} {
	    set line [list];
	    for {set col 0} {$col <= $lastvcolumn} {incr col} {
		set cell [format ".ipaev.r%dc%d" $row $col]
		lappend line $cell
		balloonhelp_for $cell  \
		    [_ "Left click to insert standard characters.\n\
Right click to insert alternative characters."]
	    }
	    eval grid $line -sticky news;
	}
	balloonhelpd_for $DeleteButton [_ "No, there isn't a mid-mid central rounded vowel called \"Delete\".\nThis is so that you can correct mistakes while using\nthe mouse, without having to go back to the keyboard."]
	if {!$DisplayVowelChartColumnLabelsP} {UnpackVowelColumnLabels}
	if {!$DisplayVowelChartRowLabelsP} {UnpackVowelRowLabels}
    }

#Rearrange into functional groups, e.g. tone marks, vowel quality marks,
#etc. Separate IPA and non-IPA.

    proc PopupIPAEntryD {} {
	set PerRow 10;
	set BaseChar "o";
	set xp 2;
	set yp 3;
	toplevel .ipaed -borderwidth 3
	wm title .ipaed [_ "Phonetic Diacritics"]
	BindKeys .ipaed
	set DownMsg [_ "Display IPA Diacritic Chart"];
	set UpMsg   [_ "Remove IPA Diacritic Chart"];
	bind .ipaed <Destroy> \
	    "set ::IPADIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPADIndex -label \"$DownMsg\""
	bind .ipaed <Unmap> \
	    "set ::IPADIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPADIndex -label \"$DownMsg\""
	bind .ipaed <Map> \
	    "set ::IPADIsDisplayedP 1;$::CEM entryconfigure $::ToggleIPADIndex -label \"$UpMsg\""
	array set Diacritics [list\
				  0  {"\u02D0" "long"}\
				  1  {"\u02D1" "half long"}\
				  2  {"\u0303" "nasalized"}\
				  3  {"\u0324" "breathy voice"}\
				  4  {"\u0325" "voiceless"}\
				  5  {"\u032C" "voiced"}\
				  6  {"\u031A" "unreleased"}\
				  7  {"\u031C" "lower/open variety of vowel"}\
				  8  {"\u031D" "raised/closed variety of vowel"}\
				  9  {"\u031E" "lower/open variety of vowel"}\
				  10  {"\u031F" "advanced/fronted"}\
				  11  {"\u0320" "retracted/backed"}\
				  12  {"\u0321" "palatalized"}\
				  13  {"\u0322" "retroflex"}\
				  14  {"\u0323" "closer variety of vowel/retroflex"}\
				  15  {"\u0329" "syllabic"}\
				  16  {"\u032A" "dental"}\
				  17  {"\u032B" "labialized"}\
				  18  {"\u0330" "creaky voice"}\
				  19  {"\u0334" "velarized/pharyngealized"}\
				  20  {"\u0346" "dentolabial"}\
				  21  {"\u0347" "alveolar"}\
				  22  {"\u0348" "strong articulation"}\
				  23  {"\u0349" "weak articulation"}\
				  24  {"\u02CA" "high tone"}\
				  25  {"\u02CB" "low tone"}\
				  26  {"\u0302" "falling tone"}\
				  27  {"\u0304" "long"}\
				  28  {"\u0306" "short"}\
				  29  {"\u0308" "non-canonical backness"}\
				  30  {"\u02CC" "secondary stress"}\
				  31  {"\u02C8" "primary stress/downstep"}\
				  32  {"\u02B8" "palatalized"}\
				  33  {"\u02DE" "rhotacized"}\
				  34  {"\u0328" "nasalized"}\
				  35  {"\u034A" "denasal"}\
				  36  {"\u034B" "nasal escape"}\
				  37  {"\u034C" "velopharyngeal friction"}\
				  38  {"\u034D" "labial spreading"}\
				  39  {"\u034E" "whistled"}
				 ];

	set DiacriticCnt [llength [array names Diacritics]];
	set Rows [expr ceil(double($DiacriticCnt)/double($PerRow))]
	set Total [expr $PerRow * $Rows]
	#Generate buttons with blank labels for empty padding slots
	for {set k 0} {$k < $Total} {incr k} {
	    set row [expr $k/$PerRow]
	    set col [expr $k%$PerRow]
	    if {[info exist Diacritics($k)]} {
		button .ipaed.r${row}c${col} -text "$BaseChar[lindex $Diacritics($k) 0]"\
		    -padx $xp -pady $yp\
		    -command "\$::InsertionTarget insert insert  [lindex $Diacritics($k) 0]"
		balloonhelpd_for .ipaed.r${row}c${col} [_ [lindex $Diacritics($k) 1]]  
	    } else {
		label .ipaed.r${row}c${col} -text "";
	    }
	    set LastRow $row;
	    set LastCol $col;
	}
	#Lay the buttons and labels out in a grid.
	for {set row 0} {$row <= $LastRow} {incr row} {
	    set line [list];
	    for {set col 0} {$col <= $LastCol} {incr col} {
		set cell [format ".ipaed.r%dc%d" $row $col]
		lappend line $cell
	    }
	    eval grid $line -sticky news;
	}
    }

#Accented letters
    proc PopupIPAEntryA {} {
	set PerRow 12;
	set xp 3;
	set yp 3;
	toplevel .ipaea -borderwidth 4
	wm title .ipaea [_ "Accented Letters"]
	BindKeys .ipaea
	set DownMsg [_ "Display Accented Letter Chart"]
	set UpMsg   [_ "Display Accented Letter Chart"]
	bind .ipaea <Destroy> \
	    "set ::IPAAIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPAAIndex -label \"$DownMsg\""
	bind .ipaea <Unmap> \
	    "set ::IPAAIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPAAIndex -label \"$DownMsg\""
	bind .ipaea <Map> \
	    "set ::IPAAIsDisplayedP 0;$::CEM entryconfigure $::ToggleIPAAIndex -label \"$UpMsg\""
	set AccentedLetters [list \
				 {"\u00E0" "a with grave"}\
				 {"\u00E1" "a with acute"}\
				 {"\u00E2" "a with circumflex"}\
				 {"\u00E3" "a with tilde"}\
				 {"\u00E4" "a with diaresis"}\
				 {"\u00E5" "a with ring above"}\
				 {"\u0101" "a with macron"}\
				 {"\u0103" "a with breve"}\
				 {"\u0105" "a with ogonek"}\
				 {"\u01CE" "a with caron"}\
				 {"\u0201" "a with double grave"}\
				 {"\u0203" "a with inverted breve"}\
				 {"\u01DF" "a with diaresis and macron"}\
				 {"\u01E1" "a with dot above and macron"}\
				 {"\u01FB" "a with ring above"}\
				 {"\u0227" "a with dot above"}\
				 {"\u1EA1" "a with dot below"}\
				 {"\u01E3" "ae with macron"}\
				 {"\u01FD" "ash with acute"}\
				 {"\u0180" "b with stroke"}\
				 {"\u0183" "b with topbar"}\
				 {"\u1E03" "b with dot above"}\
				 {"\u1E05" "b with dot below"}\
				 {"\u1E07" "b with line below"}\
				 {"\u0188" "c with hook"}\
				 {"\u0107" "c with acute"}\
				 {"\u0109" "c with circumflex"}\
				 {"\u010B" "c with dot above"}\
				 {"\u00E7" "c with cedilla"}\
				 {"\u1E09" "c with cedilla and acute"}\
				 {"\u010D" "c with caron"}\
				 {"\u018c" "d with topbar"}\
				 {"\u010F" "d with caron"}\
				 {"\u0111" "d with stroke"}\
				 {"\u0221" "d with curl"}\
				 {"\u1E0B" "d with dot above"}\
				 {"\u1E0D" "d with dot below"}\
				 {"\u1E0F" "d with line below"}\
				 {"\u021F" "h with caron"}\
				 {"\u00E8" "e with grave"}\
				 {"\u00E9" "e with acute"}\
				 {"\u00EA" "e with circumflex"}\
				 {"\u00EB" "e with diaresis"}\
				 {"\u0113" "e with macron"}\
				 {"\u0115" "e with breve"}\
				 {"\u0117" "e with dot above"}\
				 {"\u1EB9" "e with dot below"}\
				 {"\u0119" "e with ogonek"}\
				 {"\u011B" "e with caron"}\
				 {"\u0229" "e with cedilla"}\
				 {"\u0205" "e with double grave"}\
				 {"\u0207" "e with inverted breve"}\
				 {"\u01F5" "g with acute"}\
				 {"\u011D" "g with circumflex"}\
				 {"\u011F" "g with breve"}\
				 {"\u0121" "g with dot above"}\
				 {"\u0123" "g with cedilla"}\
				 {"\u01E5" "g with stroke"}\
				 {"\u01E7" "g with caron"}\
				 {"\u0125" "h with circumflex"}\
				 {"\u0127" "h with stroke"}\
				 {"\u1E25" "h with dot below"}\
				 {"\u00EC" "i with grave"}\
				 {"\u00ED" "i with acute"}\
				 {"\u00EE" "i with circumflex"}\
				 {"\u00EF" "i with diaresis"}\
				 {"\u0129" "i with tilde"}\
				 {"\u012B" "i with macron"}\
				 {"\u012D" "i with breve"}\
				 {"\u012F" "i with ogonek"}\
				 {"\u01D0" "i with caron"}\
				 {"\u0209" "i with double grave"}\
				 {"\u020B" "i with inverted breve"}\
				 {"\u1ECB" "i with dot below"}\
				 {"\u0131" "dotless i"}\
				 {"\u0135" "j with circumflex"}\
				 {"\u01F0" "j with caron"}\
				 {"\u01E9" "k with caron"}\
				 {"\u0199" "k with hook"}\
				 {"\u0137" "k with cedilla "}\
				 {"\u1E33" "k with dot below"}\
				 {"\u013A" "l with acute"}\
				 {"\u013C" "l with cedilla"}\
				 {"\u013E" "l with caron"}\
				 {"\u0140" "l with middle dot"}\
				 {"\u0142" "l with stroke"}\
				 {"\u019A" "l with bar"}\
				 {"\u0234" "l with curl"}\
				 {"\u1E37" "l with dot below"}\
				 {"\u1E39" "l with dot below and macron"}\
				 {"\u1E3B" "l with line below"}\
				 {"\u019B" "lambda with stroke"}\
				 {"\u0235" "n with a curl"}\
				 {"\u0146" "n with cedilla"}\
				 {"\u0148" "n with caron"}\
				 {"\u01F9" "n with grave"}\
				 {"\u00F1" "n with tilde"}\
				 {"\u019E" "n with long right leg"}\
				 {"\u0144" "n with acute"}\
				 {"\u1E43" "m with dot below"}\
				 {"\u1E45" "n with dot above"}\
				 {"\u1E47" "n with dot below"}\
				 {"\u1E49" "n with line below"}\
				 {"\u00F2" "o with grave"}\
				 {"\u00F3" "o with acute"}\
				 {"\u00F4" "o with circumflex"}\
				 {"\u00F5" "o with tilde"}\
				 {"\u00F6" "o with diaresis"}\
				 {"\u00F8" "o with stroke"}\
				 {"\u014D" "o with macron"}\
				 {"\u014F" "o with breve"}\
				 {"\u0151" "o with double acute"}\
				 {"\u01A1" "o with horn"}\
				 {"\u01EB" "o with ogonek"}\
				 {"\u01ED" "o with ogonek and macron"}\
				 {"\u01D2" "o with caron"}\
				 {"\u022B" "o with diaresis and macron"}\
				 {"\u022D" "o with tilde and macron"}\
				 {"\u022F" "o with dot above"}\
				 {"\u01FF" "o with stroke and acute"}\
				 {"\u020D" "o with double grave"}\
				 {"\u020F" "o with inverted breve"}\
				 {"\u0231" "o with dot above and macron"}\
				 {"\u1ECD" "o with dot below"}\
				 {"\u0223" "ou"}\
				 {"\u01A5" "p with hook"}\
				 {"\u0155" "r with acute"}\
				 {"\u0157" "r with cedilla"}\
				 {"\u0159" "r with caron"}\
				 {"\u0211" "r with double grave"}\
				 {"\u0213" "r with inverted breve"}\
				 {"\u1E5B" "r with dot below"}\
				 {"\u027F" "reversed r with fishhook"}\
				 {"\u015B" "s with acute"}\
				 {"\u015D" "s with circumflex"}\
				 {"\u015F" "s with cedilla"}\
				 {"\u0161" "s with caron"}\
				 {"\u0219" "s with comma below"}\
				 {"\u1E63" "s with dot below"}\
				 {"\u021B" "t with comma below"}\
				 {"\u01AB" "t with palatal hook"}\
				 {"\u01AD" "t with hook"}\
				 {"\u0163" "t wwith cedilla"}\
				 {"\u0165" "t with caron"}\
				 {"\u0167" "t with stroke"}\
				 {"\u0236" "t with curl"}\
				 {"\u00F9" "u with grave"}\
				 {"\u00FA" "u with acute"}\
				 {"\u00FB" "u with circumflex"}\
				 {"\u00FC" "u with diaresis"}\
				 {"\u01D4" "u with caron"}\
				 {"\u01D6" "u with diaresis and macron"}\
				 {"\u01D8" "u with diaresis and acute"}\
				 {"\u01DA" "u with diaresis and caron"}\
				 {"\u01DC" "u with diaresis and grave"}\
				 {"\u01B0" "u with horn"}\
				 {"\u0169" "u with tilde"}\
				 {"\u016B" "u with macron"}\
				 {"\u016D" "u with breve"}\
				 {"\u016F" "u with ring above"}\
				 {"\u0171" "u with double acute"}\
				 {"\u0173" "u with ogonek"}\
				 {"\u0215" "u with double grave"}\
				 {"\u0217" "u with inverted breve"}\
				 {"\u1EE5" "u with dot below"}\
				 {"\u01B4" "y with hook"}\
				 {"\u00FD" "y with acute"}\
				 {"\u00FF" "y with diaresis"}\
				 {"\u0233" "y with macron"}\
				 {"\u0175" "w with circumflex"}\
				 {"\u0177" "y with circumflex"}\
				 {"\u017A" "z with acute"}\
				 {"\u017C" "z with dot above"}\
				 {"\u017E" "z with caron"}\
				 {"\u01B6" "z with stroke"}\
				 {"\u0225" "z with hook"}\
				 {"\u01EF" "ezh with caron"}\
							 ];

#Done through 0236 			 {"\u" ""}\

	set AccentedLetterCnt [llength $AccentedLetters];
	set Rows [expr ceil(double($AccentedLetterCnt)/double($PerRow))]
	set Total [expr $PerRow * $Rows]
	#Generate buttons with blank labels for empty padding slots
	for {set k 0} {$k < $Total} {incr k} {
	    set row [expr $k/$PerRow]
	    set col [expr $k%$PerRow]
	    if {$k < $AccentedLetterCnt} {
		button .ipaea.r${row}c${col} -text "[lindex [lindex $AccentedLetters $k] 0]"\
		    -padx $xp -pady $yp\
		    -command "\$::InsertionTarget insert insert  [lindex [lindex $AccentedLetters $k] 0]"
		balloonhelpd_for .ipaea.r${row}c${col} [_ [lindex [lindex $AccentedLetters $k] 1] ]  
	    } else {
		label .ipaea.r${row}c${col} -text "";
	    }
	}
	set LastRow $row;
	set LastCol $col;
	set LastCell .ipaea.r${row}c${col}
	destroy $LastCell
	button $LastCell -image $::LeftArrowImage -command {BackDelete $::InsertionTarget}
	balloonhelpd_for $LastCell  [_ "Delete, so that you can correct mistakes while using\nthe mouse, without having to go back to the keyboard."]
	
	#Lay the buttons and labels out in a grid.
	for {set row 0} {$row <= $LastRow} {incr row} {
	    set line [list];
	    for {set col 0} {$col <= $LastCol} {incr col} {
		set cell [format ".ipaea.r%dc%d" $row $col]
		lappend line $cell
	    }
	    eval grid $line -sticky news;
	}
    }

}



set LeftArrowImage [image create photo -data {
R0lGODlhFAAUAIAAAAAAAL+/vyH5BAEAAAEALAAAAAAUABQAAAIqjI+py43gGIAxTVrNxXVz
54WTIopWGZ7oRq7X4o4wm2lvbX+ZjGv9/ysAADs=
}]

proc BackDelete {w} {
    if {[string equal [winfo class $w] "Text"]} {
	set Insert [$w index insert]
	set FirstHalf  [$w get 1.0 $Insert-1chars]
	set SecondHalf [string trimright [$w get insert end]]
	$w delete 1.0 end;
	$w insert 1.0 $FirstHalf$SecondHalf;
    } else {
	set delind [expr [$w index insert] -1];
	$w delete $delind;
    }
}

proc PopupCharEntryByCode {} {
    toplevel .charent -borderwidth 4 -relief raised
    BindKeys .charent;
    wm title .charent "Entry By Codepoint";
    after idle {
	update idletasks
	set xmax [winfo screenwidth .charent]
	set ymax [winfo screenheight .charent]
	set x0 [expr 1 * ($xmax -[winfo reqwidth .charent])/3];
	set y0 [expr 1 * ($ymax -[winfo reqheight .charent])/3];
	wm geometry .charent "+$x0+$y0";
    }
    label .charent.title -text [_ "Insert Character by Numerical Code"]
    frame .charent.ef;
    entry .charent.ef.ent -width 8 -font MainFont -relief flat -bg \#E0EEFF;
    label .charent.ef.prefix -text "0x" -font MainFont
    pack .charent.ef.prefix -side left  -expand 1 -fill x -anchor e
    pack .charent.ef.ent    -side right -expand 1 -fill x -anchor w
    button .charent.d  -text [_ "Dismiss"] -command {destroy .charent}
    button .charent.x  -text [_ "Delete"] -command [list BackDelete $::CharByCodeInsertionTarget]
    button .charent.i  -text [_ "Insert"] -command {InsertUnicode}
    pack .charent.title -side top
    pack .charent.ef -side top
    pack .charent.d -side left -expand 1 -fill both
    pack .charent.x -side left -expand 1 -fill both
    pack .charent.i -side right -expand 1 -fill both
    focus .charent.ef.ent;
    set DownMsg [_ "Display Widget for Entering Characters by Unicode Code"];
    set UpMsg   [_ "Remove Widget for Entering Characters by Unicode Code"];
    bind .charent <Destroy> \
	"set ::CharEntryByCodeIsDisplayedP 0;$::CEM entryconfigure $::ToggleCharEntryByCodeIndex -label \"$DownMsg\""
    bind .charent <Unmap> \
	"set ::CharEntryByCodeIsDisplayedP 0;$::CEM entryconfigure $::ToggleCharEntryByCodeIndex -label \"$DownMsg\""
    bind .charent <Map> \
	"set ::CharEntryByCodeIsDisplayedP 1;$::CEM entryconfigure $::ToggleCharEntryByCodeIndex -label \"$UpMsg\""
    bind .charent.ef.ent <Destroy> {set ::InsertionTarget  [focus -lastfor .gen]}
    bind .charent.ef.ent <Return> {InsertUnicode}
    bind .charent.ef.ent <Control-k> {.charent.ef.ent delete 0 end;break}


    set charentbh  [_ "Enter a character by its Unicode code, as a sequence of four hexadecimal digits.\nFor example, you may specify \'\u0298\', the International Phonetic Alphabet\nsymbol for the bilabial click, as 0298, and the Chinese character \'\u4E39\' \"egg\" as 4E39.\nDo not type the prefix 0x shown to the left of the entry box.\nIt is entered for you automatically. Return inserts the current character.\nControl-k erases the current character code."]
    balloonhelp_for .charent $charentbh
    balloonhelp_for .charent.title $charentbh
    balloonhelp_for .charent.ef.ent $charentbh
    balloonhelp_for .charent.i $charentbh
    balloonhelp_for .charent.d $charentbh
    balloonhelp_for .charent.x $charentbh
    set ::CharEntryByCodeIsDisplayedP 1;
}

#Get entry from popup, validate it, and insert it into the insertion target.
proc InsertUnicode {} {
    ClearMessageWindow;
    set str [.charent.ef.ent get];
    if {[string length $str] == 0} {
	ShowMessage [_ "The empty string is not a valid Unicode codepoint"]
	return ;
    }
    #Validate
    set BadValueP 0;
    #Make sure all digits are hex and that prefix is appropriate.
    if {[regexp {[[:xdigit:]]{4,4}} $str] == 0} {
	ShowMessage [_ "$str is not a well-formed hexadecimal Unicode value"]
	return;
    }
    set str [format "0x%s" $str]
    if {[scan $str "%x" num] < 1} {
	ShowMessage [format [_ "Ill-formed code %s"] $str]
	return;
    }

    #Reject illegal codepoints.
    if {$num  >  65535} {
	ShowMessage [_ "Tcl/Tk may not support codepoints outside the BMP (Plane 0)."]
    }
    set BadValueP 0;
    set BadRanges [list\
  	       0x0750 0x077F\
	       0x07C0 0x08FF\
	       0x1380 0x139F\
	       0x18B0 0x18FF\
	       0x1980 0x19DF\
	       0x1A00 0x1CFF\
	       0x1D80 0x1DFF\
	       0x2C00 0x2E7F\
	       0x2FE0 0x2FEF\
	       0x31C0 0x31EF\
	       0x9FB0 0x9FFF\
	       0xA4D0 0xABFF\
	       0xD7B0 0xD7FF\
	       0xD800 0xDBFF\
	       0xDC00 0xDFFF\
	       0xFE10 0xFE1F\
	       0x10140 0x102FF\
	       0x104B0 0x107FF\
	       0x10840 0x1CFFF\
	       0x1D200 0x1D2FF\
	       0x1D360 0x1D3FF\
	       0x1D800 0x1FFFF\
	       0x2A6E0 0x2F7FF\
	       0x2FAB0 0x2FFFF\
	       0xE0080 0xE00FF\
	       0xE01F0 0xEFFFF\
	       0xFFFFE 0xFFFFF];

    for {set k 0} {$k < [llength $BadRanges]} {incr k} {
	if { ($num >= [lindex $BadRanges [expr 2 * $k]]) &&\
		 ($num <= [lindex $BadRanges [expr (2 * $k) + 1]])} { 
	    set BadValueP 1;
	    break; 
	}
    }
    if {$BadValueP} {
	ShowMessage [format [_ "%s is not a valid Unicode codepoint"] $str]
	return;
    }
    if {$num >= 1114110} {
	ShowMessage [_ "Warning: codepoints above 0x10FFFD have not been assigned as of version 4.0."]
    }

    #Insert
    $::CharByCodeInsertionTarget insert insert [format "%c" $num]
}

proc IndicateIPACUp {} {
	$::CEM entryconfigure $::ToggleIPACIndex \
	    -label [_ "Remove IPA Consonant Chart"];
	set ::IPACIsDisplayedP 1;
}

proc IndicateIPACDown {} {
	$::CEM entryconfigure $::ToggleIPACIndex \
	    -label [_ "Display IPA Consonant Chart"];
	set ::IPACIsDisplayedP 0;
}

proc ToggleIPAC {} {
    global IPACIsDisplayedP;
    global m;

    if { $IPACIsDisplayedP == 0} {
	if {[winfo exists .ipaec]} {
	    wm deiconify .ipaec;
	} else { 
	    ipaentry::PopupIPAEntryC;
	}
	IndicateIPACUp;
    } else {
	wm iconify .ipaec;
	IndicateIPACDown;
    }
}

proc IndicateIPAVUp {} {
	$::CEM entryconfigure $::ToggleIPAVIndex \
	    -label [_ "Remove IPA Vowel Chart"];
	set ::IPAVIsDisplayedP 1;
}

proc IndicateIPAVDown {} {
	$::CEM entryconfigure $::ToggleIPAVIndex \
	    -label [_ "Display IPA Vowel Chart"];
	set ::IPAVIsDisplayedP 0;
}

proc ToggleIPAV {} {
    global IPAVIsDisplayedP;
    global m;

    if { $IPAVIsDisplayedP == 0} {
	if {[winfo exists .ipaev]} {
	    wm deiconify .ipaev;
	} else { 
	    ipaentry::PopupIPAEntryV;
	}
	$::CEM entryconfigure $::ToggleIPAVIndex -label [_ "Remove IPA Vowel Chart"];
	set IPAVIsDisplayedP 1;
    } else {
	wm iconify .ipaev;
	$::CEM entryconfigure $::ToggleIPAVIndex -label [_ "Display IPA Vowel Chart"];
	set IPAVIsDisplayedP 0;
    }
}

proc IndicateIPADUp {} {
	$::CEM entryconfigure $::ToggleIPADIndex \
	    -label [_ "Remove IPA Diacritic Chart"];
	set ::IPADIsDisplayedP 1;
}

proc IndicateIPADDown {} {
	$::CEM entryconfigure $::ToggleIPADIndex \
	    -label [_ "Display IPA Diacritic Chart"];
	set ::IPADIsDisplayedP 0;
}

proc ToggleIPAD {} {
    global IPADIsDisplayedP;
    global m;

    if { $IPADIsDisplayedP == 0} {
	if {[winfo exists .ipaed]} {
	    wm deiconify .ipaed;
	} else { 
	    ipaentry::PopupIPAEntryD;
	}
	IndicateIPADUp
    } else {
	wm iconify .ipaed;
	IndicateIPADDown;
    }
}

proc IndicateIPAAUp {} {
	$::CEM entryconfigure $::ToggleIPAAIndex \
	    -label [_ "Remove Accented Letter Chart"];
	set ::IPAAIsDisplayedP 1;
}

proc IndicateIPAADown {} {
	$::CEM entryconfigure $::ToggleIPAAIndex \
	    -label [_ "Display Accented Letter Chart"];
	set ::IPAAIsDisplayedP 0;
}

proc ToggleIPAA {} {
    global m;

    if { $::IPAAIsDisplayedP == 0} {
	if {[winfo exists .ipaea]} {
	    wm deiconify .ipaea;
	} else { 
	    ipaentry::PopupIPAEntryA;
	}
	IndicateIPAAUp;
    } else {
	wm iconify .ipaea;
	IndicateIPAADown;
    }
}


proc IndicateCharEntryByCodeUp {} {
	$::CEM entryconfigure $::ToggleCharEntryByCodeIndex \
	    -label [_ "Remove Widget for Entering Characters by Unicode Code"];
	set ::CharEntryByCodeIsDisplayedP 1;
}

proc IndicateCharEntryByCodeDown {} {
	$::CEM entryconfigure $::ToggleCharEntryByCodeIndex \
	    -label [_ "Display Widget for Entering Characters by Unicode Code"];
	set ::CharEntryByCodeIsDisplayedP 0;
}

proc ToggleCharEntryByCode {} {
    global CharEntryByCodeIsDisplayedP;
    global m;

    if { $CharEntryByCodeIsDisplayedP == 0} {
	if {[winfo exists .charent]} {
	    wm deiconify .charent;
	    raise .charent;
	} else { 
	    PopupCharEntryByCode;
	}
	IndicateCharEntryByCodeUp;
    } else {
	wm iconify .charent;
	IndicateCharEntryByCodeDown;
    }
}

proc SetUseCheckbuttonP {b} {
    set ::UseCheckbuttonP [Boolean $b];
}
proc SetExclusionsDisplayedP {b} {
    set ::ExclusionsDisplayedP [Boolean $b]
}
proc SetKeyFieldIdentificationDisplayedP {b} {
    set ::KeyFieldIdentificationDisplayedP [Boolean $b]
}
proc SetMiscellaneousOptionsDisplayedP {b} {
    set ::MiscellaneousOptionsDisplayedP [Boolean $b]
}
proc SetSortOrderDisplayedP {b} {
    set ::SortOrderDisplayedP [Boolean $b]
} 
proc SetSortTypeDisplayedP {b} {
    set ::SortTypeDisplayedP [Boolean $b]
}
proc SetSubstitutionsDisplayedP {b} {
    set ::SubstitutionsDisplayedP [Boolean $b]
}

proc SetRecordParseDisplayedP {b} {
    set ::RecordParseDisplayedP [Boolean $b];
}

proc SetMiscOptionsDisplayedP {b} {
    set ::MiscOptionsDisplayedP [Boolean $b];
}

proc SetUnicodeDisplayedP {b} {
    set ::UnicodeDisplayedP [Boolean $b];
}

proc SetOutputFileDisplayedP {b} {
    set ::OutputFileDisplayedP [Boolean $b];
}

proc SetAlgorithmDisplayedP {b} {
    set ::AlgorithmDisplayedP [Boolean $b];
}

proc SetInputFileDisplayedP {b} {
    set ::InputFileDisplayedP [Boolean $b];
}
proc SetSortAlgorithm {s} {
    set ::SortAlgorithm $s;
}

proc SetDisplayConsonantChartColumnLabelsP {b} {
    global DisplayConsonantChartColumnLabelsP
    set DisplayConsonantChartColumnLabelsP [Boolean $b];
}

proc SetDisplayConsonantChartRowLabelsP {b} {
    global DisplayConsonantChartRowLabelsP
    set DisplayConsonantChartRowLabelsP [Boolean $b];
}

proc SetDisplayVowelChartColumnLabelsP {b} {
    global DisplayVowelChartColumnLabelsP
    set DisplayVowelChartColumnLabelsP [Boolean $b]
}

proc SetDisplayVowelChartRowLabelsP {b} {
    global DisplayVowelChartRowLabelsP
    set DisplayVowelChartRowLabelsP [Boolean $b]
}

proc ControlDisplayConsonantChartColumnLabels {} {
    if {$::DisplayConsonantChartColumnLabelsP} {
	ipaentry::PackConsonantColumnLabels;
    } else {
	ipaentry::UnpackConsonantColumnLabels;
    }
}

proc ControlDisplayConsonantChartRowLabels {} {
    if {$::DisplayConsonantChartRowLabelsP} {
	ipaentry::PackConsonantRowLabels;
    } else {
	ipaentry::UnpackConsonantRowLabels;
    }
}

proc ControlDisplayVowelChartColumnLabels {} {
    if {$::DisplayVowelChartColumnLabelsP} {
	ipaentry::PackVowelColumnLabels;
    } else {
	ipaentry::UnpackVowelColumnLabels;
    }
}

proc ControlDisplayVowelChartRowLabels {} {
    if {$::DisplayVowelChartRowLabelsP} {
	ipaentry::PackVowelRowLabels;
    } else {
	ipaentry::UnpackVowelRowLabels;
    }
}

####################################################

#File     -> LineList	LoadCustomCharacterChart
#LineList -> CDEF	DefineCustomCharacterChart
#CDEF     -> Popup      PopupSpecialPalette

proc ReadCustomCharacterChartPopup {args} {
    if {[llength $args]} {
	set dl [LoadCustomCharacterChart [lindex $args 0]]
    } else {
	set dl [LoadCustomCharacterChart];
    }
    PopupSpecialPalette [DefineCustomCharacterChart $dl]
}

proc DefineCustomCharacterChartPopup {ll} {
    PopupSpecialPalette [DefineCustomCharacterChart $ll];
}

#Returns a linelist.
proc LoadCustomCharacterChart {args} {
    if {[llength $args]} {
	set fn [lindex $args 0]
    } else {
	set fn [tk_getOpenFile -title [_ "Load Custom Character Chart"]];
	if {[string equal $fn ""]} {
	    ShowMessage [_ "File selection cancelled."];
	    return ;
	}
    }
    if { [catch {open $fn "r"} fhd ] != 0} {
	ShowMessage [format [_ "Unable to open character chart definition file %s."] $fn];
	return ;
    }
    set LineCnt 0
    while { [gets $fhd line] > 0} {
	lappend Lines $line;
	incr LineCnt
    }
    close $fhd;
    if {$LineCnt < 1} {
	ShowMessage [_ "File %s is empty" $fn]
	return "";
    }
    ShowMessage [format [_ "Loaded custom character chart definition from %s."] $fn]
    return $Lines;
}


#This procedure takes a list of lines defining a custom
#character entry chart, which may have been read from a
#standalone file or may be an instant list in an
#init file, and generates an internal character chart
#definition, which it stores. It does not actualy
#create a display
proc DefineCustomCharacterChart {LineList {fn NONE}} {
    #The first line is special. It contains meta-information:
    #the title, the desired number of buttons per row,
    #and the proposed font family and size. Only the
    #title is obligatory.
    set line [lindex $LineList 0]
    set flds [split $line "|"]
    set FieldCnt [llength $flds];
    set Title [lindex $flds 0];
    #The remaining lines contain pairs of code sequences and glosses.
    set cd [list];
    set LineList [lrange $LineList 1 end]
    foreach line $LineList {
	set f [split $line "|"];
	set gloss [lindex $f 1];
	set c [string trim [lindex $f 0] \"];
	set cf [split $c];
	set str "\{\"";
	foreach n $cf {
	    append str [format "%s" $n]
	}
	append str "\""
	append str [format " \"%s\"\}" $gloss]
	lappend cd $str;
    }
    set info [list [join $cd]]
    if {$FieldCnt > 1} {
	lappend info [lindex $flds 1];	# Columns
    }
    if {$FieldCnt > 2} {
	lappend info [lindex $flds 2];	# Font family
    }
    if {$FieldCnt > 3} {
	lappend info [lindex $flds 3];	# Font size
    }
    if {![string equal $fn NONE]} {	# File name
	lappend info $fn;
    }
    set ::SpecialCharacterPalette($Title) $info;
    $::CEM add command -label $Title -command "PopupSpecialPalette $Title";
    incr ::CustomCEMEntries;
    return $Title;
}

#Creates a popup chart from a stored definition.
set SccCnt 0;
proc PopupSpecialPalette {Title} {
    set name [format ".scc%d" $::SccCnt] 
    if {[info exists ::SpecialCharacterPalette($Title,WidgetName)]} {
	set w $::SpecialCharacterPalette($Title,WidgetName);
	if {[winfo exists $w]} {
	    wm deiconify $w;
	    raise $w;
	    return ;
	}
    }
    set cdefs [lindex $::SpecialCharacterPalette($Title) 0];
    set Items [llength $::SpecialCharacterPalette($Title)];
    if {$Items > 1} {
	set PerRow [lindex $::SpecialCharacterPalette($Title) 1];
    } else {
	set PerRow 5;
    }
    if {$Items > 2} {
	set FontFamily [lindex $::SpecialCharacterPalette($Title) 2];
    } else {
	set FontFamily $::FontInfo(CharacterEntryFont,family)
    }
    if {$Items > 3} {
	set FontSize [lindex $::SpecialCharacterPalette($Title) 3];
    } else {
	set FontSize $::FontInfo(CharacterEntryFont,size);
    }
    incr ::SccCnt;
    set xp 3;
    set yp 3;
    toplevel $name -borderwidth 4
    set ::SpecialCharacterPalette($Title,WidgetName) $name; 
    wm title $name $Title
    iwidgets::scrolledframe $name.sf -vscrollmode dynamic -hscrollmode dynamic \
	-height 180 -width 250
    set tf [$name.sf childsite]
    pack $name.sf -expand 1 -fill both
    BindKeys $name
    bind [$name.sf component vertsb] <<B3>> \
	"ScrollbarMoveBigIncrement [$name.sf component vertsb] 0.20 %x %y"
    set CdefCnt [llength $cdefs];
    set Rows [expr int(ceil(double($CdefCnt)/double($PerRow)))]
    set Total [expr $PerRow * $Rows]
    if {$CdefCnt == $Total} {
	incr Rows;
	set Total [expr $PerRow * $Rows]
    }
    set fontname [string trimleft $name .]Font
    font create $fontname -family $FontFamily -size $FontSize
    for {set k 0} {$k < $Total} {incr k} {
	set row [expr $k/$PerRow]
	set col [expr $k%$PerRow]
	if {$k < $CdefCnt} {
	    set csalt "";
	    set entry [lindex $cdefs $k];
	    set chstr [lindex $entry 0];
	    set gloss [lindex $entry 1];
	    set chstrParts [split $chstr ":"];
	    if {[llength $chstrParts] > 1} {
		set cs    [lindex $chstrParts 0];
		set csalt [lindex $chstrParts 1];
	    } else {
		set cs [lindex $chstr 0];
	    }
	    button $tf.r${row}c${col} -text $cs\
		-padx $xp -pady $yp -font $fontname\
		-command "\$::InsertionTarget insert insert $cs"
	    if {![string equal $csalt ""]} {
		bind $tf.r${row}c${col} <<B3>> "\$::InsertionTarget insert insert $csalt"
	    }
	    balloonhelpd_for $tf.r${row}c${col} $gloss;
	} else {
	    set ln $tf.r${row}c${col};
	    #Generate buttons with blank labels for empty padding slots
	    label $ln  -text "";
	    balloonhelp_for $ln [_ "This space for rent."]
	}
    }
    set LastRow $row;
    set LastCol $col;
    set LastCell $tf.r${row}c${col}
    destroy $LastCell
    button $LastCell -image $::LeftArrowImage -command {BackDelete $::InsertionTarget}
    balloonhelpd_for $LastCell  [_ "Delete, so that you can correct mistakes while using\nthe mouse, without having to go back to the keyboard."]
    
    #Lay the buttons and labels out in a grid.
    for {set row 0} {$row <= $LastRow} {incr row} {
	set line [list];
	for {set col 0} {$col <= $LastCol} {incr col} {
	    set cell [format "%s.r%dc%d" $tf $row $col]
	    lappend line $cell
	}
	eval grid $line -sticky news;
    }
    return $name;
}

proc ExplainStringLength {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(StringLength)]} {
	if {[winfo exists $PopupList(StringLength)]} {
	    destroy $PopupList(StringLength);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "String Length Comparison"] $HPWidth 12]
    BindKeys $po;
    set PopupList(StringLength) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key on the basis of the length of the key string in characters. Length is measured after preprocessing, including multigraph compression and deletion of excluded characters. Keys compared for size are treated exactly like lexicographic keys except that when comparisons are finally done on them, the comparison is a numeric comparison of the length of the key rather than a lexicographic comparison of the key as a string."];
    AppendToTextDisplay $po [_ "\n\n"]
    AppendToTextDisplay $po [_ "If you use string length as the primary key with a data set of any size, you will probably find that the sort takes a long time. This is because the number of different word-lengths in most data sets is very small in comparison to the number of distinct words. This means that on the primary key most words are ranked the same as many other words. The result is that the sort routine does many comparisons in a largely futile effort to break ties."]
    AppendToTextDisplay $po [_ "\n\n"]
    AppendToTextDisplay $po [_ "In this situation, you can speed up the sort considerably by adding a subsidiary key that can be used to break ties. For example, a straight lexicographic sort of a list of 254,817 English words required 6,852,774 comparisons and took 10 seconds on my desktop machine.Sorting the same list purely on string length required 3,173,191,623 comparisons, more than 12,000 times as many, and took almost 25 minutes, 1500 times as long. This is because this file contains only 25 different word lengths, of which nine comprise over 92% of the list. Sorting the list with string length as the primary key and a lexicographic secondary key required 6,671,259 comparisons, slightly fewer than the pure lexicographic sort, and took about 10 seconds. Much of the time you probably want to do this anyway as you won't want the results to be ordered randomly so long as they are of the same length, but even if you really don't care about anything other than string length, it will probably be to your advantage to add a tie-breaking key."]
}
 
proc ExplainNumericComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Numeric)]} {
	if {[winfo exists $PopupList(Numeric)]} {
	    destroy $PopupList(Numeric);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Numeric Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Numeric) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key on the basis of the numerical value of the keys. Each string is converted to a floating point number.
Consider, for example, the strings \`9\' and \`10\' . If these are compared lexicographically, \`10\' will be ordered before \`9\' because the character \`1\' precedes \`9\'. If they are compared numerically, \`9\' is ordered before \`10\' because 9 is less than 10."];}

proc ExplainNumberSystem {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(NumberSystem)]} {
	if {[winfo exists $PopupList(NumberSystem)]} {
	    destroy $PopupList(NumberSystem);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Number System"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(NumberSystem) $po;
    AppendToTextDisplay $po [_ "By default numbers are written in the usual Indo-Arabic numbers. Msort can handle a variety of other number systems. You may specify a number system or one of two special values. The value \'all\' means that any supported number system may be used. Different records may make use of different number systems. Msort will detect the number system used by each key. The value \'any\' means that any supported number system may be used but that all records must use the same one. Msort will determine the number system on the basis of the first record and assume that subsequent records use the same number system for that field.\n"];}

proc ExplainTimeComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Time)]} {
	if {[winfo exists $PopupList(Time)]} {
	    destroy $PopupList(Time);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Time Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Time) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key on the basis of the key interpreted as a time. Each string is parsed as a time and converted to a purely numerical form. The strings are then compared numerically."];
    AppendToTextDisplay $po [_ "A time is expected to be of the form \`HH:MM(.SS)\'or \'HH:MM:SS(.sss)\'. In the first case,  an integer specifying the hour followed by a colon followed by an integer specifying the minute is expected, with an integer specifying the second, separated from the minute by a period, optional. In the second case, an integer specifying the hour followed by a colon specifying the mintute followed by an integer specifying the second is expected, with an integer specying fractional seconds separated from the second by a period optional."];
    AppendToTextDisplay $po [_ "Msort detects and reports inappropriate values such as minutes greater than 59."];
    AppendToTextDisplay $po [_ "Examples of well-formed times are: 23:11:08, 23:11:08.5, 11:10.55, and 14:11"];
}

proc ExplainAngleComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Angle)]} {
	if {[winfo exists $PopupList(Angle)]} {
	    destroy $PopupList(Angle);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Angle Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Angle) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, the key is treated as an angle in sexagesimal degree format. The angle is expected to be in the format DD:MM:SS(.sss), that is to say, degrees, minutes, and seconds separated by colons, with an optional fractional part for seconds. The key is converted to a value with dimensions of seconds and compared numerically. Msort detects and reports invalid values such as seconds greater than or equal to 60."];}

proc ExplainDateComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Date)]} {
	if {[winfo exists $PopupList(Date)]} {
	    destroy $PopupList(Date);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Date Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Date) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key on the basis of the key interpreted as a date. Each string is parsed as a date and converted to a purely numerical form. The strings are then compared numerically."];
    AppendToTextDisplay $po [_ "For example, a date in the"];
    AppendLinkToTextDisplay $po [_ "International Date Format"] {ShowWebPage http://www.saqqara.demon.co.uk/datefmt.htm};
AppendToTextDisplay $po [_ "consists of the year followed by the month followed by the day separated by dashes, e.g. 2005-04-24 for April 4, 2005. The format for such a date is: y-m-d."];
    AppendToTextDisplay $po [_ "The same date in the format usual in Europe has the format d/m/y, i.e. 24/04/2005."];
    AppendToTextDisplay $po [_ "The same date in the format usual in the United States has the format m/d/y, i.e. 4/24/2005."];
    AppendToTextDisplay $po [_ "The punctuation used to separate the components of dates also varies. In many countries periods are used instead of slashes, e.g. 24.04.2005, for which the format specification is: d.m.y"];
}

proc ExplainDomainNameComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(DomainName)]} {
	if {[winfo exists $PopupList(DomainName)]} {
	    destroy $PopupList(DomainName);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Domain Name Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(DomainName) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, the key is parsed into components separated by periods and the order of the components is reversed. For example, directory.fsf.org is treated as if it were org.fsf.directory. Using this type of comparison results in output in which subdomains of the same domain are grouped together."];
    AppendToTextDisplay $po "\n\n"
    AppendToTextDisplay $po [_ "Instead of"];
    AppendToTextDisplay $po "\n\n"
    AppendToTextDisplay $po [_ "directory.fsf.org\nfreshmeat.net\nsourceforge.net\nwww.fsf.org\nwww.gnu.org"];
    AppendToTextDisplay $po "\n\n"
    AppendToTextDisplay $po [_ "the order will be:\n\n"]
    AppendToTextDisplay $po [_ "freshmeat.net\nsourceforge.net\ndirectory.fsf.org\nwww.fsf.org\nwww.gnu.org"];
    AppendToTextDisplay $po "\n\n"
    AppendToTextDisplay $po "Email addresses are also handled. They are treated just like domain names save for the fact that if the string contains an @-sign, the substring preceding the @-sign is treated as an additional component."
}

proc ExplainISO8601Comparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(ISO8601)]} {
	if {[winfo exists $PopupList(ISO8601)]} {
	    destroy $PopupList(ISO8601);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "ISO8601 Date/Time Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(ISO8601) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key on the basis of the assumption that the key consists of a combined date and time in the format standardized by International Standards Organization standard 8601. Such combined dates and times consist of a date in ISO8601 format, the upper case letter <T>, and a time in international format. An ISO8601 date consists of a year number followed by month number followed by day number, separated by hyphens. A time in international format is a 24-hour time with hours preceding minutes separated by a colon. Seconds optionally follow, separated from minutes by a period."];
    AppendToTextDisplay $po [_ "For example, 2005-04-25T14:11.33 represents 33 seconds past 2:11 p.m. on April 25th, 2005."];
}

proc ExplainLexicographicComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Lexicographic)]} {
	if {[winfo exists $PopupList(Lexicographic)]} {
	    destroy $PopupList(Lexicographic);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Lexicographic Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Lexicographic) $po;
    AppendToTextDisplay $po [_ "If this option is chosen, records are compared on this key by \'dictionary ordering\'. If the first letters of the two words have different sort ranks, that determines the ordering of the two words. If not, we consider the next letter of each word. Again, if they have different sort ranks, we are done, but if they do not, we move on to the next letter. If one string comes to an end before the other, the shorter string ranks first."];
    AppendToTextDisplay $po "\n\n"
    AppendToTextDisplay $po [_ "It is important to be careful about the use of terms like \"lexicographic\" and \"dictonary\" order because they are used inconsistently. Here I am using the term \"lexicographic\" only to mean that the ordering is based on the ranking of the individual letters and not on interpretation of the string in some fashion, as it is when we sort numerically. At least three other meanings of this term exist. First, some people consider \"dictionary\" order to be case-insensitive. With Msort, if you want case-insensitive behavior you can get it, but it is controlled by a separate option. Secondly, some people use this term for sorting in which sequences of digits are treated as integers and compared numerically. If you want this behavior in Msort, you want \"hybrid\" sorting. Third, the term may imply that non-alphanumeric characters are ignored. Again, this behavior is available in Msort if you want it, but it is not implicit in either \"lexicographic\" or \"hybrid\" comparison. If you want to ignore certain characters, use the exclusion facilities."]
   AppendToTextDisplay $po [_ "As examples of the other usages, the --dictionary option in GNU sort has the effect of making the comparison case-insensitive and of making it ignore non-alphanumeric characters. The -dict option to Tcl's lsort command has the effect of treating sequences of digits as integers and comparing them numerically."]
}

proc ExplainHybridComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Hybrid)]} {
	if {[winfo exists $PopupList(Hybrid)]} {
	    destroy $PopupList(Hybrid);
	    return;
	}
    }

    set po [CreateTextDisplay [_ "Hybrid Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Hybrid) $po;
    AppendToTextDisplay $po [_ "This type of comparison is the same as lexicographic comparison except for the treatment of numerals."];
    AppendToTextDisplay $po [_ "In lexicographic comparison, numerals are treated like any other characters."]
    AppendToTextDisplay $po [_ "For example, A12 sorts before A3 because 1 precedes 3."]
    AppendToTextDisplay $po [_ "In hybrid comparison, each uninterrupted string of numerals is converted to the number that it represents. "];
    AppendToTextDisplay $po [_ "These numbers are then compared numerically."]
    AppendToTextDisplay $po [_ "In a hybrid sort, A3 sorts before A12 because the number 3 is less than the number 12."];
}

proc ExplainRandomComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(Random)]} {
	if {[winfo exists $PopupList(Random)]} {
	    destroy $PopupList(Random);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Random Comparison"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(Random) $po;
    AppendToTextDisplay $po [_ "This option is used for randomizing files, not actually for sorting them. Its effect is that, each time two records are compared on the specified key, the result of the comparison is determined by a random number generator rather than by the contents of the key fields. The records will be reported as comparing less-than, equal, or greater-than with equal probability."];
}

proc ExplainPositionID {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(PositionID)]} {
	if {[winfo exists $PopupList(PositionID)]} {
	    destroy $PopupList(PositionID);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Identifying Keys by Position"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(PositionID) $po;
    AppendToTextDisplay $po [_ "A key is identified by position by specifying a contiguous range of positions, where a position consists of a field number and a character offset into the field. Fields may be counted from the end of the record by using negative numbers. The first field is numbered 1, the last field -1. Character offsets must be positive and begin at 1. The beginning and end of a range may be the same. For example, the range 1.2,1.2 specifies the key as consisting of the second character of the first field. The range 1.1,-1.2 specifies the key as the first field through the last field, with only the first character of the last field in the key."];
}

proc ExplainTagID {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(TagID)]} {
	if {[winfo exists $PopupList(TagID)]} {
	    destroy $PopupList(TagID);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Identifying Key Fields By Tag"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(TagID) $po;
    AppendToTextDisplay $po [_ "When key fields are identified by tags, each field must begin with a string that indicates what field it is. For example, in an address list one tag might be \`Postal Code\', which would indicate that the remainder of the field contains a postal code. Tags do not have to be fixed strings; Msort allows tags to be specified by regular expressions. The regular expression notation used is that of the "];
    AppendLinkToTextDisplay $po [_ "TRE library."] {ShowWebPage http://laurikari.net/tre/};
    AppendToTextDisplay $po [_ " Details may be found in the "];
    AppendLinkToTextDisplay $po [_ "TRE Syntax Manual."] {ShowWebPage http://laurikari.net/tre/syntax.html};
}

proc ExplainRangeID {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(RangeID)]} {
	if {[winfo exists $PopupList(RangeID)]} {
	    destroy $PopupList(RangeID);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Identifying Key Fields By Character Range"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(RangeID) $po;
    AppendToTextDisplay $po [_ "A range of characters may be specified as a key. A range\
consists of the characters M through N. The first character in the record has index 1.\
Negative indices indicate position with respect to the end of the record.  For\
example, the range 1 through 3 contains the first three characters of the record.
The range 3 through -2 contains the third character through the next-to-last character."];
}

proc ExplainReverseKey {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(ReverseKey)]} {
	if {[winfo exists $PopupList(ReverseKey)]} {
	    destroy $PopupList(ReverseKey);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Key Reversal"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(ReverseKey) $po;
    AppendToTextDisplay $po [_ "Key reversal means reversing the order of characters in the key. For example, reversing \'spelling\' yields \'gnilleps\'. Reversing the order of characters in a key gives priority to the end of a string rather than to its beginning. Among other things, this option allows the generation of reverse dictionaries. Note that reversal is done following multigraph compression. For example, if \`lh\' is declared in the sort order specification as a multigraph, \`bilh\' will sort as if it were \`lhib\', not as if it were \`hlib\'. Key reversal is only applicable to lexicographic keys."]
}

proc ExplainInvertComparison {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(InvertComparison)]} {
	if {[winfo exists $PopupList(InvertComparison)]} {
	    destroy $PopupList(InvertComparison);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Inversion of Comparison"] $HPWidth 20]
    BindKeys $po;
    set PopupList(InvertComparison) $po;
    AppendToTextDisplay $po [_ "Sorting ultimately comes down to pairwise comparisons of records, where it is decided whether one record is greater than the other, less than it, or equal to it. Inverting comparison means making the opposite decision for comparisons on this key. For instance, if we are comparing numerical values and record A's key is 100 and record B's key is 200, the usual comparison will order A before B. If comparisons on this key are inverted, A will be ordered after B."]
    AppendToTextDisplay $po [_ "If there is only a single key, inverting comparisons has the same effect as a global inversion of the sort order. If there is more than one key, however, the effect of inverting comparisons on invidual keys is not the same as that of a global inversion of the sort order. Suppose, for example, that you have a list of names and dates, such as this:\n\n"];
    AppendToTextDisplay $po [_ "    2004/01/17 Smith\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Khaled\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Gomez\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Yamamoto\n"]
    AppendToTextDisplay $po [_ "    2003/02/03 Maurois\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Burger\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "Here is the result of sorting first by date, then by name, in both cases in the usual ascending order:\n\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Burger\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Yamamoto\n"]
    AppendToTextDisplay $po [_ "    2003/02/03 Maurois\n"]
    AppendToTextDisplay $po [_ "    2004/01/17 Smith\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Gomez\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Khaled\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "Now suppose that you decide that you would like the most recent dates first. If you invert the order globally, the result is this:\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Khaled\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Gomez\n"]
    AppendToTextDisplay $po [_ "    2004/01/17 Smith\n"]
    AppendToTextDisplay $po [_ "    2003/02/03 Maurois\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Yamamoto\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Burger\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "This is probably not what you want. The dates are now descending, but the names are in reverse alphabetical order. What you want is more likely this:\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Gomez\n"]
    AppendToTextDisplay $po [_ "    2004/03/15 Khaled\n"]
    AppendToTextDisplay $po [_ "    2004/01/17 Smith\n"]
    AppendToTextDisplay $po [_ "    2003/02/03 Maurois\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Burger\n"]
    AppendToTextDisplay $po [_ "    1999/01/28 Yamamoto\n"]
    AppendToTextDisplay $po [_ "\n"]
    AppendToTextDisplay $po [_ "This is the result of inverting comparisons on dates but not on names.\n"]
}

proc ExplainFoldCase {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(FoldCase)]} {
	if {[winfo exists $PopupList(FoldCase)]} {
	    destroy $PopupList(FoldCase);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Case Folding"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(FoldCase) $po;
    AppendToTextDisplay $po [_ "It is often the case that upper- and lower-case letters should be treated the same for sorting purposes. Setting case folding on makes comparisons insensitive to case.This can be done by the use of a suitable sort order definition, but it is common enough that msort, like other sorting programs, provides a separate option for it."]
}

proc ExplainUnicodeNormalization {} {
    global HPWidth;
    global HPLines;
    global PopupList;
    if {[info exists PopupList(UnicodeNormalization)]} {
	if {[winfo exists $PopupList(UnicodeNormalization)]} {
	    destroy $PopupList(UnicodeNormalization);
	    return;
	}
    }
    set po [CreateTextDisplay [_ "Unicode Normalization"] $HPWidth $HPLines]
    BindKeys $po;
    set PopupList(UnicodeNormalization) $po;
    AppendToTextDisplay $po [_ "There are quite a few composite characters, such as letters with accents, that may be represented in Unicode in more than one way depending on whether the composite character consists of a single codepoint or more than one codepoint. For example, the letter &eacute; \"lower case e with acute accent\", may be encoded as a single unit at U+00E9 or as the sequence of lower case e with no accent, U+0085 followed by the combining acute accent U+0301. In the first case we have canonically composed encoding. In the second case we have the canonically decomposed encoding. Normalization to normalization format NFC converts sequences like U+0085 U+0301 to U+00E9. Normalization to Normalization Form NFD converts single codepoints like U+00E9 to U+0085 U+0301. If neither normalization form is used a string containing U+00E9 will not,in general, be treated the same way as a string containing, in the same position, U+0065 U+0301. As this is generally desirable,