summaryrefslogtreecommitdiff
path: root/contrib/groffer/shell/groffer2.sh
blob: 358eb317072209f82b809fd87a372175eb15cb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
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
#! /bin/sh

# groffer - display groff files

# Source file position: <groff-source>/contrib/groffer/shell/groffer2.sh
# Installed position: <prefix>/lib/groff/groffer/groffer2.sh

# This file should not be run independently.  It is called by
# `groffer.sh' in the source or by the installed `groffer' program.

# Copyright (C) 2001,2002,2003,2004,2005,2006
# Free Software Foundation, Inc.
# Written by Bernd Warken

# Last update: 7 Nov 2006

# This file is part of `groffer', which is part of `groff'.

# `groff' is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# `groff' 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 `groff'; see the files COPYING and LICENSE in the top
# directory of the `groff' source.  If not, write to the Free Software
# Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
# USA.


########################################################################
#             Test of rudimentary shell functionality
########################################################################

# Zsh is not Bourne compatible without the following:
if test -n "$ZSH_VERSION"; then
  emulate sh
  NULLCMD=:
fi


########################################################################
# Test of `unset'
#
export _UNSET;
export _foo;
_foo=bar;
_res="$(unset _foo 2>&1)";
if unset _foo >${_NULL_DEV} 2>&1 && \
   test _"${_res}"_ = __ && test _"${_foo}"_ = __
then
  _UNSET='unset';
  eval "${_UNSET}" _foo;
  eval "${_UNSET}" _res;
else
  _UNSET=':';
fi;


########################################################################
# Test of `test'.
#
if test a = a && test a != b && test -f "${_GROFFER_SH}"
then
  :;
else
  echo '"test" did not work.' >&2;
  exit "${_ERROR}";
fi;


########################################################################
# Test of `echo' and the `$()' construct.
#
if echo '' >${_NULL_DEV}
then
  :;
else
  echo '"echo" did not work.' >&2;
  exit "${_ERROR}";
fi;
if test _"$(t1="$(echo te)" &&
            t2="$(echo '')" &&
            t3="$(echo 'st')" &&
            echo "${t1}${t2}${t3}")"_ \
     != _test_
then
  echo 'The "$()" construct did not work' >&2;
  exit "${_ERROR}";
fi;


########################################################################
# Test of sed program; test in groffer.sh is not valid here.
#
if test _"$(echo xTesTx \
           | sed -n 's/^.\([Tt]e*x*sTT*\).*$/\1/p' \
           | sed 's|T|t|g')"_ != _test_
then
  echo 'The sed program did not work.' >&2;
  exit "${_ERROR}";
fi;


########################################################################
# Test of `cat'.
#
if test _"$(echo test | cat)"_ != _test_
then
  error 'Test of "cat" command failed.';
fi;


########################################################################
# Test of function definitions.
#
_t_e_s_t_f_u_n_c_()
{
  return 0;
}

_test_func()
{
  echo test;
}

if _t_e_s_t_f_u_n_c_ 2>${_NULL_DEV} && \
   test _"$(_test_func 2>${_NULL_DEV})"_ = _test_
then
  :;
else
  echo 'Shell '"${_SHELL}"' does not support function definitions.' >&2;
  exit "${_ERROR}";
fi;


########################################################################
# landmark (<text>)
#
# Print <text> to standard error as a debugging aid.
#
# Globals: $_DEBUG_LM
#
landmark()
{
  if test _"${_DEBUG_LM}"_ = _yes_
  then
    echo "LM: $*" >&2;
  fi;
} # landmark()


########################################################################
# test for compression.
#
export _HAS_COMPRESSION;
export _HAS_BZIP;
if test _"$(echo 'test' | gzip -c -d -f - 2>${_NULL_DEV})"_ = _test_
then
  _HAS_COMPRESSION='yes';
  if echo 'test' | bzip2 -c 2>${_NULL_DEV} | bzip2 -t 2>${_NULL_DEV} \
     && test _"$(echo 'test' | bzip2 -c 2>${_NULL_DEV} \
                             | bzip2 -d -c 2>${_NULL_DEV})"_ \
             = _test_
  then
    _HAS_BZIP='yes';
  else
    _HAS_BZIP='no';
  fi;
else
  _HAS_COMPRESSION='no';
  _HAS_BZIP='no';
fi;


########################################################################
#                    debug - diagnostic messages
########################################################################

export _DEBUG_FUNC_CHECK;
if test _"${_BEFORE_MAKE}"_ = _yes_
then
  _DEBUG_FUNC_CHECK='yes';
else
  _DEBUG_FUNC_CHECK='no';
fi;
_DEBUG_FUNC_CHECK='no';	# disable function checking
#_DEBUG_FUNC_CHECK='yes';	# enable function checking

export _DEBUG_STACKS;
_DEBUG_STACKS='no';		# disable stack output in each function
#_DEBUG_STACKS='yes';		# enable stack output in each function

export _DEBUG_USER_WITH_STACK;
_DEBUG_USER_WITH_STACK='no';	# disable stack dump in error_user()
#_DEBUG_USER_WITH_STACK='yes';	# enable stack dump in error_user()

export _DEBUG_LM;
_DEBUG_LM='no';			# disable landmark messages
#_DEBUG_LM='yes';		# enable landmark messages

export _DEBUG_GROG;
_DEBUG_GROG='no';		# disable grog output
#_DEBUG_GROG='yes';		# enable grog output

export _DEBUG_KEEP_FILES;
_DEBUG_KEEP_FILES='no'		# disable file keeping in temporary dir
#_DEBUG_KEEP_FILES='yes'	# enable file keeping in temporary dir

export _DEBUG_PRINT_PARAMS;
_DEBUG_PRINT_PARAMS='no';	# disable printing of all parameters
#_DEBUG_PRINT_PARAMS='yes';	# enable printing of all parameters

export _DEBUG_PRINT_SHELL;
_DEBUG_PRINT_SHELL='no';	# disable printing of the shell name
#_DEBUG_PRINT_SHELL='yes';	# enable printing of the shell name

export _DEBUG_PRINT_TMPDIR;
_DEBUG_PRINT_TMPDIR='no';	# disable printing of the temporary dir
#_DEBUG_PRINT_TMPDIR='yes';	# enable printing of the temporary dir

export _DEBUG_PRINT_FILENAMES;
_DEBUG_PRINT_FILENAMES='no';	# disable printing of the found file names
#_DEBUG_PRINT_FILENAMES='yes';	# enable printing of the found file names

# determine all --debug* options
case " $*" in
*\ --deb*|*\ --d*-*)
  # --debug-* options
  d=' --debug-all --debug-filenames --debug-func --debug-grog '\
'--debug-not-func --debug-keep --debug-lm --debug-params '\
'--debug-shell --debug-stacks --debug-tmpdir --debug-user ';
  # non-debug options with scheme --d*-*
  n=' --do-nothing --default-modes --dvi-viewer --dvi-viewer-tty ';
  for i
  do
    case "$i" in
    --deb|--debu|--debug)
      _DEBUG_FUNC_CHECK='yes';
      # _DEBUG_STACKS='yes';
      _DEBUG_USER_WITH_STACK='yes';
      # _DEBUG_LM='yes';
      _DEBUG_GROG='yes';
      _DEBUG_KEEP_FILES='yes';
      _DEBUG_PRINT_PARAMS='yes';
      _DEBUG_PRINT_SHELL='yes';
      _DEBUG_PRINT_TMPDIR='yes';
      _DEBUG_PRINT_FILENAMES='yes';
      continue;
      ;;
    --d*-*)
      # before `-'
      b="$(echo x"$i" | sed 's/^x--\([^-]*\)-.*$/\1/')";
      # after `-'
      a="$(echo x"$i" | sed 's/^x--[^-]*-\(.*\)$/\1/')";
      ;;
    *)
      continue;
      ;;
    esac;
    case "$n" in
    *\ --$b*-$a*)
      continue;
      ;;
    esac;
    case "$d" in
    *\ --$b*-$a*)
      case "$a" in
      f|s)			# double --debug-* options
        continue;
        ;;
      esac;
      # extract whole word of double abbreviation
      s="$(cat <<EOF | sed -n 's/^.* \(--'"$b"'[^ -]*-'"$a"'[^ ]*\) .*/\1/p'
$d
EOF
)"
      case "$s" in
      '') continue; ;;
      --debug-all)
        _DEBUG_FUNC_CHECK='yes';
        _DEBUG_STACKS='yes';
        _DEBUG_USER_WITH_STACK='yes';
        _DEBUG_GROG='yes';
        _DEBUG_LM='yes';
        _DEBUG_KEEP_FILES='yes';
        _DEBUG_PRINT_PARAMS='yes';
        _DEBUG_PRINT_SHELL='yes';
        _DEBUG_PRINT_TMPDIR='yes';
        _DEBUG_PRINT_FILENAMES='yes';
        _DEBUG_PRINT_FILENAMES='yes';
        ;;
      --debug-filenames)
        _DEBUG_PRINT_FILENAMES='yes';
        ;;
      --debug-func)
        _DEBUG_FUNC_CHECK='yes';
	;;
      --debug-not-func)
        _DEBUG_FUNC_CHECK='no';
        _DEBUG_STACKS='no';
        _DEBUG_USER_WITH_STACK='no';
	;;
      --debug-grog)
        _DEBUG_GROG='yes';
	;;
      --debug-keep)
        _DEBUG_PRINT_TMPDIR='yes';
        _DEBUG_KEEP_FILES='yes';
        ;;
      --debug-lm)
        _DEBUG_LM='yes';
        ;;
      --debug-params)
        _DEBUG_PRINT_PARAMS='yes';
        ;;
      --debug-shell)
        _DEBUG_PRINT_SHELL='yes';
        ;;
      --debug-stacks)
        _DEBUG_STACKS='yes';
        ;;
      --debug-tmpdir)
        _DEBUG_PRINT_TMPDIR='yes';
        ;;
      --debug-user)
        _DEBUG_USER_WITH_STACK='yes';
        ;;
      esac;
      ;;
    esac;
  done
  ;;
esac;

if test _"${_DEBUG_STACKS}"_ = _yes_ || \
   test _"${_DEBUG_USER_WITH_STACK}"_ = _yes_
then
  _DEBUG_FUNC_CHECK='yes';
fi

if test _"${_DEBUG_PRINT_PARAMS}"_ = _yes_
then
  echo "parameters: $@" >&2;
fi;

if test _"${_DEBUG_PRINT_SHELL}"_ = _yes_
then
  if test _"${_SHELL}"_ = __
  then
    if test _"${POSIXLY_CORRECT}"_ = _y_
    then
      echo 'shell: bash as /bin/sh (none specified)' >&2;
    else
      echo 'shell: /bin/sh (none specified)' >&2;
    fi;
  else
    echo "shell: ${_SHELL}" >&2;
  fi;
fi;


########################################################################
#                       Environment Variables
########################################################################

landmark "1: environment variables";

# Environment variables that exist only for this file start with an
# underscore letter.  Global variables to this file are written in
# upper case letters, e.g. $_GLOBAL_VARIABLE; temporary variables
# start with an underline and use only lower case letters and
# underlines, e.g.  $_local_variable.

#   [A-Z]*     system variables,      e.g. $MANPATH
#   _[A-Z_]*   global file variables, e.g. $_MAN_PATH
#   _[a-z_]*   temporary variables,   e.g. $_manpath

# Due to incompatibilities of the `ash' shell, the name of loop
# variables in `for' must be a single character.
#   [a-z]      local loop variables,   e.g. $i

# In functions, other writings are used for variables.  As some shells
# do not support the `local' command a unique prefix in lower case is
# constructed for each function, most are the abbreviation of the
# function name.  All variable names start with this prefix.
#   ${prefix}_[a-z_]*	variable name in a function, e.g. $msm_modes


########################################################################
# read-only variables (global to this file)
########################################################################

# function return values; `0' means ok; other values are error codes
export _BAD;
export _GOOD;
export _NO;
export _OK;
export _YES;

_GOOD='0';			# return ok
_BAD='1';			# return negatively, error code `1'
# $_ERROR was already defined as `7' in groffer.sh.

_NO="${_BAD}";
_YES="${_GOOD}";
_OK="${_GOOD}";

# quasi-functions, call with `eval', e.g `eval "${return_ok}"'
export return_ok;
export return_good;
export return_bad;
export return_yes;
export return_no;
export return_error;
export return_var;
return_ok="func_pop; return ${_OK}";
return_good="func_pop; return ${_GOOD}";
return_bad="func_pop; return ${_BAD}";
return_yes="func_pop; return ${_YES}";
return_no="func_pop; return ${_NO}";
return_error="func_pop; return ${_ERROR}";
return_var="func_pop; return";	# add number, e.g. `eval "${return_var} $n'


export _DEFAULT_MODES;
_DEFAULT_MODES="'pdf' 'html' 'ps' 'x' 'dvi' 'tty'";
export _DEFAULT_RESOLUTION;
_DEFAULT_RESOLUTION='75';

export _DEFAULT_TTY_DEVICE;
_DEFAULT_TTY_DEVICE='latin1';

# _VIEWER_* viewer programs for different modes constructed as lists
export _VIEWER_DVI_TTY;		# viewer program for dvi mode in tty
export _VIEWER_DVI_X;		# viewer program for dvi mode in X
export _VIEWER_HTML_TTY;	# viewer program for html mode in tty
export _VIEWER_HTML_X;		# viewer program for html mode in X
export _VIEWER_PDF_TTY;		# viewer program for pdf mode in tty
export _VIEWER_PDF_X;		# viewer program for pdf mode in X
export _VIEWER_PS_TTY;		# viewer program for ps mode in tty
export _VIEWER_PS_X;		# viewer program for ps mode in X
export _VIEWER_TTY_TTY;		# viewer program for X/x mode in tty
export _VIEWER_TTY_X;		# viewer program for X/x mode in X
export _VIEWER_X_TTY;		# viewer program for X/x mode in tty
export _VIEWER_X_X;		# viewer program for X/x mode in X
_VIEWER_DVI_TTY="";
_VIEWER_DVI_X="'kdvi' 'xdvi' 'dvilx'";
_VIEWER_HTML_TTY="'lynx' 'w3m'";
_VIEWER_HTML_X="'konqueror' 'epiphany' 'mozilla-firefox' 'firefox' 'mozilla' \
'netscape' 'galeon' 'opera' 'amaya' 'arena' 'mosaic'";
_VIEWER_PDF_TTY="";
_VIEWER_PDF_X="'kpdf' 'acroread' 'evince' 'xpdf -z 150' 'gpdf' \
'kghostview --scale 1.45' 'ggv'";
_VIEWER_PS_TTY="";
_VIEWER_PS_X="'kpdf' 'kghostview --scale 1.45' 'evince' 'ggv' 'gv' \
'ghostview' 'gs_x11,gs'";
_VIEWER_TTY_TTY="'less -r -R' 'more' 'pager'";
_VIEWER_TTY_X="'xless'";
_VIEWER_X_TTY="";
_VIEWER_X_X="'gxditview' 'xditview'";

# Search automatically in standard sections `1' to `8', and in the
# traditional sections `9', `n', and `o'.  On many systems, there
# exist even more sections, mostly containing a set of man pages
# special to a specific program package.  These aren't searched for
# automatically, but must be specified on the command line.
export _MAN_AUTO_SEC_LIST;
_MAN_AUTO_SEC_LIST="'1' '2' '3' '4' '5' '6' '7' '8' '9' 'n' 'o'";
export _MAN_AUTO_SEC_CHARS;
_MAN_AUTO_SEC_CHARS='[123456789no]';

export _SPACE_SED;
_SPACE_SED='['"${_SP}${_TAB}"']';

export _SPACE_CASE;
_SPACE_CASE='[\'"${_SP}"'\'"${_TAB}"']';

export _PROCESS_ID;		# for shutting down the program
_PROCESS_ID="$$";

export _START_DIR;		# directory at start time of the script
_START_DIR="$(pwd)";


############ the command line options of the involved programs
#
# The naming scheme for the options environment names is
# $_OPTS_<prog>_<length>[_<argspec>]
#
# <prog>:    program name GROFFER, GROFF, or CMDLINE (for all
#            command line options)
# <length>:  LONG (long options) or SHORT (single character options)
# <argspec>: ARG for options with argument, NA for no argument;
#            without _<argspec> both the ones with and without arg.
#
# Each option that takes an argument must be specified with a
# trailing : (colon).

# exports
export _OPTS_GROFFER_SHORT_NA;
export _OPTS_GROFFER_SHORT_ARG;
export _OPTS_GROFFER_LONG_NA;
export _OPTS_GROFFER_LONG_ARG;
export _OPTS_GROFF_SHORT_NA;
export _OPTS_GROFF_SHORT_ARG;
export _OPTS_GROFF_LONG_NA;
export _OPTS_GROFF_LONG_ARG;
export _OPTS_X_SHORT_ARG;
export _OPTS_X_SHORT_NA;
export _OPTS_X_LONG_ARG;
export _OPTS_X_LONG_NA;
export _OPTS_MAN_SHORT_ARG;
export _OPTS_MAN_SHORT_NA;
export _OPTS_MAN_LONG_ARG;
export _OPTS_MAN_LONG_NA;
export _OPTS_MANOPT_SHORT_ARG;
export _OPTS_MANOPT_SHORT_NA;
export _OPTS_MANOPT_LONG_ARG;
export _OPTS_MANOPT_LONG_NA;
export _OPTS_CMDLINE_SHORT_NA;
export _OPTS_CMDLINE_SHORT_ARG;
export _OPTS_CMDLINE_LONG_NA;
export _OPTS_CMDLINE_LONG_ARG;

###### groffer native options

_OPTS_GROFFER_SHORT_NA="'h' 'Q' 'v' 'V' 'X' 'Z'";
_OPTS_GROFFER_SHORT_ARG="'T'";

_OPTS_GROFFER_LONG_NA="'auto' \
'apropos' 'apropos-data' 'apropos-devel' 'apropos-progs' \
'debug' 'debug-all' 'debug-filenames' \
'debug-func' 'debug-not-func' 'debug-grog' 'debug-keep' 'debug-lm' \
'debug-params' 'debug-shell' 'debug-stacks' 'debug-tmpdir' 'debug-user' \
'default' 'do-nothing' 'dvi' 'groff' 'help' 'intermediate-output' 'html' \
'man' 'no-location' 'no-man' 'no-special' 'pdf' 'ps' 'rv' 'source' \
'text' 'to-stdout' 'text-device' 'tty' 'tty-device' \
'version' 'whatis' 'www' 'x' 'X'";

_OPTS_GROFFER_LONG_ARG="\
'default-modes' 'device' 'dvi-viewer' 'dvi-viewer-tty' 'extension' 'fg' \
'fn' 'font' 'foreground' 'html-viewer' 'html-viewer-tty' 'mode' \
'pdf-viewer' 'pdf-viewer-tty' 'print' 'ps-viewer' 'ps-viewer-tty' 'shell' \
'title' 'tty-viewer' 'tty-viewer-tty' 'www-viewer' 'www-viewer-tty' \
'x-viewer' 'x-viewer-tty' 'X-viewer' 'X-viewer-tty'";

##### groffer options inhereted from groff

_OPTS_GROFF_SHORT_NA="'a' 'b' 'c' 'C' 'e' 'E' 'g' 'G' 'i' 'k' 'l' 'N' 'p' \
'R' 's' 'S' 't' 'U' 'z'";
_OPTS_GROFF_SHORT_ARG="'d' 'f' 'F' 'I' 'K' 'L' 'm' 'M' 'n' 'o' 'P' 'r' \
'w' 'W'";
_OPTS_GROFF_LONG_NA="";
_OPTS_GROFF_LONG_ARG="";

##### groffer options inhereted from the X Window toolkit

_OPTS_X_SHORT_NA="";
_OPTS_X_SHORT_ARG="";

_OPTS_X_LONG_NA="'iconic' 'rv'";

_OPTS_X_LONG_ARG="'background' 'bd' 'bg' 'bordercolor' 'borderwidth' \
'bw' 'display' 'fg' 'fn' 'font' 'foreground' 'ft' 'geometry' \
'resolution' 'title' 'xrm'";

###### groffer options inherited from man

_OPTS_MAN_SHORT_NA="";
_OPTS_MAN_SHORT_ARG="";

_OPTS_MAN_LONG_NA="'all' 'ascii' 'catman' 'ditroff' \
'local-file' 'location' 'troff' 'update' 'where'";

_OPTS_MAN_LONG_ARG="'locale' 'manpath' \
'pager' 'preprocessor' 'prompt' 'sections' 'systems' 'troff-device'";

###### additional options for parsing $MANOPT only

_OPTS_MANOPT_SHORT_NA="'7' 'a' 'c' 'd' 'D' 'f' 'h' 'k' 'l' 't' 'u' \
'V' 'w' 'Z'";
_OPTS_MANOPT_SHORT_ARG="'e' 'L' 'm' 'M' 'p' 'P' 'r' 'S' 'T'";

_OPTS_MANOPT_LONG_NA="${_OPTS_MAN_LONG_NA} \
'apropos' 'debug' 'default' 'help' 'html' 'ignore-case' 'location-cat' \
'match-case' 'troff' 'update' 'version' 'whatis' 'where' 'where-cat'";

_OPTS_MANOPT_LONG_ARG="${_OPTS_MAN_LONG_NA} \
'config_file' 'encoding' 'extension' 'locale'";

###### collections of command line options

_OPTS_CMDLINE_SHORT_NA="${_OPTS_GROFFER_SHORT_NA} \
${_OPTS_GROFF_SHORT_NA} ${_OPTS_X_SHORT_NA} ${_OPTS_MAN_SHORT_NA}";
_OPTS_CMDLINE_SHORT_ARG="${_OPTS_GROFFER_SHORT_ARG} \
${_OPTS_GROFF_SHORT_ARG} ${_OPTS_X_SHORT_ARG} ${_OPTS_MAN_SHORT_ARG}";

_OPTS_CMDLINE_LONG_NA="${_OPTS_GROFFER_LONG_NA} \
${_OPTS_GROFF_LONG_NA} ${_OPTS_X_LONG_NA} ${_OPTS_MAN_LONG_NA}";
_OPTS_CMDLINE_LONG_ARG="${_OPTS_GROFFER_LONG_ARG} \
${_OPTS_GROFF_LONG_ARG} ${_OPTS_MAN_LONG_ARG} ${_OPTS_X_LONG_ARG}";


########################################################################
# read-write variables (global to this file)
########################################################################

export _ALL_PARAMS;		# All options and file name parameters
export _ADDOPTS_GROFF;		# Transp. options for groff (`eval').
export _APROPOS_PROG;		# Program to run apropos.
export _APROPOS_SECTIONS;	# Sections for different --apropos-*.
export _DISPLAY_MODE;		# Display mode.
export _DISPLAY_PROG;		# Viewer program to be used for display.
export _DISPLAY_ARGS;		# X resources for the viewer program.
export _FILE_NR;		# number for temporary `,file,*'
export _FILEARGS;		# Stores filespec parameters.
export _FILESPEC_ARG;		# Stores the actual filespec parameter.
export _FILESPEC_IS_MAN;	# filespec is for searching a man page
export _FUNC_STACK;		# Store debugging information.
export _MACRO_PACKAGES;		# groff's macro packages.
export _MACRO_PKG;		# Macro package for each found file.
export _NO_FILESPECS;		# Yes, if there are no filespec arguments.
export _OUTPUT_FILE_NAME;	# output generated, see main_set_res..()
export _REG_TITLE_LIST;		# Processed file names.
export _SOELIM_R;		# option -r for soelim
export _SPECIAL_FILESPEC;	# Filespec ran for apropos or whatis.
export _SPECIAL_SETUP;		# Test on setup for apropos or whatis.
export _VIEWER_BACKGROUND;	# viewer shall be run in the background or not
# _MAN_* finally used configuration of man searching
export _MAN_ALL;		# search all man pages per filespec
export _MAN_ENABLE;		# enable search for man pages
export _MAN_EXT;		# extension for man pages
export _MAN_FORCE;		# force file parameter to be man pages
export _MAN_IS_SETUP;		# setup man variables only once
export _MAN_LANG;		# language for man pages
export _MAN_LANG2;		# language for man pages
export _MAN_PATH;		# search path for man pages as a list
export _MAN_SEC;		# sections for man pages; sep. `:'
export _MAN_SEC_CHARS;		# sections for man pages as [] construct
export _MAN_SEC_LIST;		# sections for man pages as a list
export _MAN_SYS;		# system names for man pages as a list
# _MANOPT_* as parsed from $MANOPT
export _MANOPT_ALL;		# $MANOPT --all
export _MANOPT_EXTENSION;	# $MANOPT --extension
export _MANOPT_LANG;		# $MANOPT --locale
export _MANOPT_PATH;		# $MANOPT --manpath
export _MANOPT_PAGER;		# $MANOPT --pager
export _MANOPT_SEC;		# $MANOPT --sections
export _MANOPT_SYS;		# $MANOPT --systems
# variables for mode pdf
export _PDF_DID_NOT_WORK;
export _PDF_HAS_GS;
export _PDF_HAS_PS2PDF;
# _OPT_* as parsed from groffer command line
export _OPT_ALL;		# display all suitable man pages
export _OPT_APROPOS;		# call `apropos' program
export _OPT_BD;			# set border color in some modes
export _OPT_BG;			# set background color in some modes
export _OPT_BW;			# set border width in some modes
export _OPT_DEFAULT_MODES;	# `,'-list of modes when no mode given
export _OPT_DEVICE;		# device option
export _OPT_DO_NOTHING;		# do nothing in main_display()
export _OPT_DISPLAY;		# set X display
export _OPT_EXTENSION;		# set extension for man page search
export _OPT_FG;			# set foreground color in some modes
export _OPT_FN;			# set font in some modes
export _OPT_GEOMETRY;		# set size and position of viewer in X
export _OPT_ICONIC;		# -iconic option for X viewers
export _OPT_LANG;		# set language for man pages
export _OPT_MODE;		# values: X, tty, Q, Z, ""
export _OPT_MANPATH;		# manual setting of path for man-pages
export _OPT_PAGER;		# specify paging program for tty mode
export _OPT_RESOLUTION;		# set X resolution in dpi
export _OPT_RV;			# reverse fore- and background colors
export _OPT_SECTIONS;		# sections for man page search
export _OPT_STDOUT;		# print mode file to standard output
export _OPT_SYSTEMS;		# man pages of different OS's
export _OPT_TITLE;		# title for gxditview window
export _OPT_TEXT_DEVICE;	# set device for tty mode
export _OPT_V;			# groff option -V
export _OPT_VIEWER_DVI;		# viewer program for dvi mode
export _OPT_VIEWER_HTML;	# viewer program for html mode
export _OPT_VIEWER_PDF;		# viewer program for pdf mode
export _OPT_VIEWER_PS;		# viewer program for ps mode
export _OPT_VIEWER_X;		# viewer program for x mode
export _OPT_WHATIS;		# print the man description
export _OPT_XRM;		# specify X resource
export _OPT_Z;			# groff option -Z
# _TMP_* temporary directory and files
export _TMP_DIR;		# groffer directory for temporary files
export _TMP_CAT;		# stores concatenation of everything
export _TMP_MAN;		# stores find of man path
export _TMP_MANSPEC;		# filters man pages with filespec
export _TMP_STDIN;		# stores stdin, if any

# these variables are preset in section `Preset' after the rudim. test


########################################################################
# Preset and reset of read-write global variables
########################################################################

# For variables that can be reset by option `--default', see reset().

_FILE_NR=0;
_FILEARGS='';
_MACRO_PACKAGES="'-man' '-mdoc' '-me' '-mm' '-mom' '-ms'";
_SPECIAL_FILESPEC='no';
_SPECIAL_SETUP='no';

# _TMP_* temporary files
_TMP_DIR='';
_TMP_CAT='';
_TMP_MAN='';
_TMP_CONF='';
_TMP_STDIN='';

# variables for mode pdf
_PDF_DID_NOT_WORK='no';
_PDF_HAS_GS='no';
_PDF_HAS_PS2PDF='no';

# option -r for soelim
if : | soelim -r 2>${_NULL_DEV} >${_NULL_DEV}
then
  _SOELIM_R='-r';
else
  _SOELIM_R='';
fi;

########################################################################
# reset ()
#
# Reset the variables that can be affected by options to their default.
#
reset()
{
  if test "$#" -ne 0
  then
    error "reset() does not have arguments.";
  fi;

  _ADDOPTS_GROFF='';
  _APROPOS_PROG='';
  _APROPOS_SECTIONS='';
  _DISPLAY_ARGS='';
  _DISPLAY_MODE='';
  _DISPLAY_PROG='';
  _MACRO_PKG='';
  _NO_FILESPECS='';
  _REG_TITLE_LIST='';

  # _MAN_* finally used configuration of man searching
  _MAN_ALL='no';
  _MAN_ENABLE='yes';		# do search for man-pages
  _MAN_EXT='';
  _MAN_FORCE='no';		# first local file, then search man page
  _MAN_IS_SETUP='no';
  _MAN_LANG='';
  _MAN_LANG2='';
  _MAN_PATH='';
  _MAN_SEC='';
  _MAN_SEC_CHARS='';
  _MAN_SEC_LIST='';
  _MAN_SYS='';

  # _MANOPT_* as parsed from $MANOPT
  _MANOPT_ALL='no';
  _MANOPT_EXTENSION='';
  _MANOPT_LANG='';
  _MANOPT_PATH='';
  _MANOPT_PAGER='';
  _MANOPT_SEC='';
  _MANOPT_SYS='';

  # _OPT_* as parsed from groffer command line
  _OPT_ALL='no';
  _OPT_APROPOS='no';
  _OPT_BD='';
  _OPT_BG='';
  _OPT_BW='';
  _OPT_DEFAULT_MODES='';
  _OPT_DEVICE='';
  _OPT_DISPLAY='';
  _OPT_DO_NOTHING='no';
  _OPT_EXTENSION='';
  _OPT_FG='';
  _OPT_FN='';
  _OPT_GEOMETRY='';
  _OPT_ICONIC='no';
  _OPT_LANG='';
  _OPT_MODE='';
  _OPT_MANPATH='';
  _OPT_PAGER='';
  _OPT_RESOLUTION='';
  _OPT_RV='no';
  _OPT_SECTIONS='';
  _OPT_SYSTEMS='';
  _OPT_STDOUT='no';
  _OPT_TITLE='';
  _OPT_TEXT_DEVICE='';
  _OPT_V='no';
  _OPT_VIEWER_DVI='';
  _OPT_VIEWER_PDF='';
  _OPT_VIEWER_PS='';
  _OPT_VIEWER_HTML='';
  _OPT_VIEWER_X='';
  _OPT_WHATIS='no';
  _OPT_XRM='';
  _OPT_Z='no';
  _VIEWER_BACKGROUND='no';
}

reset;


########################################################################
#              Preliminary functions for error handling
########################################################################

landmark "2: preliminary functions";

# These functions do not have a func-check frame.  Basically they could be
# moved to the functions in alphabetical order.

##############
# echo1 (<text>*)
#
# Output to stdout with final line break.
#
# Arguments : arbitrary text including `-'.
#
echo1()
{
  cat <<EOF
$@
EOF
} # echo1()


##############
# echo2 (<text>*)
#
# Output to stderr with final line break.
#
# Arguments : arbitrary text including `-'.
#
echo2()
{
  cat >&2 <<EOF
$@
EOF
} # echo2()




##############
# clean_up ()
#
# Clean up at exit.
#
cu_already='no';
clean_up()
{
  cd "${_START_DIR}" >"${_NULL_DEV}" 2>&1;
  if test _${_DEBUG_KEEP_FILES}_ = _yes_
  then
    if test _"$cu_already"_ = _yes_
    then
      eval "${return_ok}";
    fi;
    cu_already=yes;
    echo2 "Kept temporary directory ${_TMP_DIR}."
  else
    if test _"${_TMP_DIR}"_ != __
    then
      if test -e "${_TMP_DIR}"
      then
        rm -f -r "${_TMP_DIR}" >${_NULL_DEV} 2>&1;
      fi;
    fi;
  fi;
  eval "${return_ok}";
} # clean_up()


#############
# diag (text>*)
#
# Output a diagnostic message to stderr.
#
diag()
{
  echo2 '>>>>>'"$*";
} # diag()


#############
# error (<text>*)
#
# Print an error message to standard error, print the function stack,
# exit with an error condition.  The argument should contain the name
# of the function from which it was called.  This is for system errors.
#
error()
{
  case "$#" in
    1) echo2 'groffer error: '"$1"; ;;
    *) echo2 'groffer error: wrong number of arguments in error().'; ;;
  esac;
  func_stack_dump;
  if test _"${_TMP_DIR}"_ != __ && test -d "${_TMP_DIR}"
  then
    : >"${_TMP_DIR}"/,error;
  fi;
  exit "${_ERROR}";
} # error()


#############
# error_user (<text>*)
#
# Print an error message to standard error; exit with an error condition.
# The error is supposed to be produced by the user.  So the funtion stack
# is omitted.
#
error_user()
{
  case "$#" in
    1)
      echo2 'groffer error: '"$1";
       ;;
    *)
      echo2 'groffer error: wrong number of arguments in error_user().';
      ;;
  esac;
  if test _"${_DEBUG_USER_WITH_STACK}"_ = _yes_
  then
    func_stack_dump;
  fi;
  if test _"${_TMP_DIR}"_ != __ && test -d "${_TMP_DIR}"
  then
    : >"${_TMP_DIR}"/,error;
  fi;
  exit "${_ERROR}";
} # error_user()



#############
# exit_test ()
#
# Test whether the former command ended with error().  Exit again.
#
# Globals: $_ERROR
#
exit_test()
{
  if test "$?" = "${_ERROR}"
  then
    exit ${_ERROR};
  fi;
  if test _"${_TMP_DIR}"_ != __ && test -f "${_TMP_DIR}"/,error
  then
    exit ${_ERROR};
  fi;
} # exit_test()


########################################################################
#       Definition of normal Functions in alphabetical order
########################################################################

landmark "3: functions";

########################################################################
# apropos_filespec ()
#
# Compose temporary file for filspec.
#
# Globals:  in: $_OPT_APROPOS, $_SPECIAL_SETUP, $_FILESPEC_ARG,
#               $_APROPOS_PROG, $_APROPOS_SECTIONS, $_OPT_SECTIONS
#          out: $_SPECIAL_FILESPEC
#
# Variable prefix: af
#
apropos_filespec()
{

  func_check apropos_filespec '=' 0 "$@";
  if obj _OPT_APROPOS is_yes
  then
    if obj _SPECIAL_SETUP is_not_yes
    then
      error 'apropos_filespec(): apropos_setup() must be run first.';
    fi;
    _SPECIAL_FILESPEC='yes';
    if obj _NO_FILESPECS is_yes
    then
      to_tmp_line '.SH no filespec';
      eval "${_APROPOS_PROG}" | sed 's/^/\\\&/' >>"${_TMP_CAT}";
      eval "${return_ok}";
    fi;
    eval to_tmp_line \
      "'.SH $(echo1 "${_FILESPEC_ARG}" | sed 's/[^\\]-/\\-/g')'";
    exit_test;
    if obj _APROPOS_SECTIONS is_empty
    then
      if obj _OPT_SECTIONS is_empty
      then
        s='^.*(..*).*$';
      else
        s='^.*(['"$(echo1 "${_OPT_SECTIONS}" | sed 's/://g')"']';
      fi;
    else
      s='^.*(['"${_APROPOS_SECTIONS}"']';
    fi;
### apropos_filespec()
    af_filespec="$(echo1 "${_FILESPEC_ARG}" | sed '
s,/,\\/,g
s/\./\\./g
')";
    eval "${_APROPOS_PROG}" "'${_FILESPEC_ARG}'" | \
      sed -n '
/^'"${af_filespec}"': /s/^\(.*\)$/\\\&\1/p
/'"$s"'/p
' | \
      sort |\
      sed '
s/^\(.*(..*).*\)  *-  *\(.*\)$/\.br\n\.TP 15\n\.BR \"\1\"\n\\\&\2/
' >>"${_TMP_CAT}";
    eval ${_UNSET} af_filespec;
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # apropos_filespec()


########################################################################
# apropos_setup ()
#
# Setup for the --apropos* options, just 2 global variables are set.
#
# Globals:  in: $_OPT_APROPOS
#          out: $_SPECIAL_SETUP, $_APROPOS_PROG
#
apropos_setup()
{
  func_check apropos_setup '=' 0 "$@";
  if obj _OPT_APROPOS is_yes
  then
    if is_prog apropos
    then
      _APROPOS_PROG='apropos';
    elif is_prog man
    then
      if man --apropos man >${_NULL_DEV} 2>${_NULL_DEV}
      then
        _APROPOS_PROG='man --apropos';
      elif man -k man >${_NULL_DEV} 2>${_NULL_DEV}
      then
        _APROPOS_PROG='man -k';
      fi;
    fi;
    if obj _APROPOS_PROG is_empty
    then
      error 'apropos_setup(): no apropos program available.';
    fi;
    to_tmp_line '.TH GROFFER APROPOS';
    _SPECIAL_SETUP='yes';
    if obj _OPT_TITLE is_empty
    then
      _OPT_TITLE='apropos';
    fi;
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # apropos_setup()


########################################################################
# base_name (<path>)
#
# Get the file name part of <path>, i.e. delete everything up to last
# `/' from the beginning of <path>.  Remove final slashes, too, to get
# a non-empty output.  The output is constructed according the shell
# program `basename'.
#
# Arguments : 1
# Output    : the file name part (without slashes)
#
# Variable prefix: bn
#
base_name()
{
  func_check base_name = 1 "$@";
  bn_name="$1";
  case "${bn_name}" in
    */)
      # delete all final slashes
      bn_name="$(echo1 "${bn_name}" | sed 's|//*$||')";
      exit_test;
      ;;
  esac;
  case "${bn_name}" in
    '')
      eval ${_UNSET} bn_name;
      eval "${return_bad}";
      ;;
    /)
      # this is like `basename' does
      echo1 '/';
      ;;
    */*)
      # delete everything before and including the last slash `/'.
      echo1 "${bn_name}" | sed 's|^.*//*\([^/]*\)$|\1|';
      ;;
    *)
      obj bn_name echo1;
      ;;
  esac;
  eval ${_UNSET} bn_name;
  eval "${return_ok}";
} # base_name()


########################################################################
# cat_z (<file>)
#
# Decompress if possible or just print <file> to standard output.
# gzip, bzip2, and .Z decompression is supported.
#
# Arguments: 1, a file name.
# Output: the content of <file>, possibly decompressed.
#
cat_z()
{
  func_check cat_z = 1 "$@";
  case "$1" in
  '')
    error 'cat_z(): empty file name.';
    ;;
  '-')
    error 'cat_z(): for standard input use save_stdin().';
    ;;
  esac;
  if is_file "$1"
  then
    :;
  else
    error 'cat_z(): argument $1 is not a file.';
  fi;
  if test -s "$1"
  then
    :;
  else
    eval "${return_ok}";
  fi;
  if obj _HAS_COMPRESSION is_yes
  then
    if obj _HAS_BZIP is_yes
    then
      # test whether being compressed with bz2
      if bzip2 -t "$1" 2>${_NULL_DEV}
      then
        bzip2 -c -d "$1" 2>${_NULL_DEV};
        eval "${return_ok}";
      fi;
    fi;
    # if not compressed gzip acts like `cat'
    gzip -c -d -f "$1" 2>${_NULL_DEV};
  else
    cat "$1";
  fi;
  eval "${return_ok}";
} # cat_z()


########################################################################
# clean_up ()
#
# Do the final cleaning up before exiting; used by the trap calls.
#
# defined above


########################################################################
# diag (<text>*)
#
# Print marked message to standard error; useful for debugging.
#
# defined above


########################################################################
landmark '4: dir_name()*';
########################################################################

#######################################################################
# dir_name (<name>)
#
# Get the directory name of <name>.  The output is constructed
# according to the shell program `dirname'.
#
# Arguments : 1
# Output    : the directory part of <name>
#
# Variable prefix: dn
#
dir_name()
{
  func_check dir_name = 1 "$@";
  obj_from_output dn_name dir_name_chop "$1";
  case "${dn_name}" in
  ''|.)
    echo1 '.';
    ;;
  /)
    echo1 '/';
    ;;
  */*)
    echo1 "$(echo1 "${dn_name}" | sed 's#/*[^/][^/]*$##')";
    ;;
  *)
    echo1 "${dn_name}";
    ;;
  esac;
  eval "${return_ok}";
} # dir_name()


#######################################################################
# dir_name_append (<dir> <name>)
#
# Append `name' to `dir' with clean handling of `/'.
#
# Arguments : 2
# Output    : the generated new directory name <dir>/<name>
#
dir_name_append()
{
  func_check dir_name_append = 2 "$@";
  if is_empty "$1"
  then
    echo1 "$2";
  elif is_empty "$2"
  then
    echo1 "$1";
  else
    dir_name_chop "$1"/"$2";
  fi;
  eval "${return_ok}";
} # dir_name_append()


########################################################################
# dir_name_chop (<name>)
#
# Remove unnecessary slashes from directory name.
#
# Argument: 1, a directory name.
# Output:   path without double, or trailing slashes.
#
# Variable prefix: dc
#
dir_name_chop()
{
  func_check dir_name_chop = 1 "$@";
  # replace all multiple slashes by a single slash `/'.
  dc_res="$(echo1 "$1" | sed 's|///*|/|g')";
  exit_test;
  case "${dc_res}" in
  ?*/)
    # remove trailing slash '/';
    echo1 "${dc_res}" | sed 's|/$||';
    ;;
  *)
    obj dc_res echo1
    ;;
  esac;
  eval ${_UNSET} dc_res;
  eval "${return_ok}";
} # dir_name_chop()


########################################################################
# do_nothing ()
#
# Dummy function that does nothing.
#
do_nothing()
{
  eval return "${_OK}";
} # do_nothing()


########################################################################
# echo1 (<text>*)
#
# Print to standard output with final line break.
#
# defined above


########################################################################
# echo2 (<text>*)
#
# Print to standard error with final line break.
#
# defined above



########################################################################
# error (<text>*)
#
# Print error message and exit with error code.
#
# defined above


########################################################################
# exit_test ()
#
# Test whether the former command ended with error().  Exit again.
#
# defined above


if test _"${_DEBUG_FUNC_CHECK}"_ = _yes_
then

  #############
  # func_check (<func_name> <rel_op> <nr_args> "$@")
  #
  # This is called at the first line of each function.  It checks the
  # number of arguments of function <func_name> and registers the
  # function call to _FUNC_STACK.
  #
  # Arguments: >=3
  #   <func_name>: name of the calling function.
  #   <rel_op>:    a relational operator: = != < > <= >=
  #   <nr_args>:   number of arguments to be checked against <operator>
  #   "$@":        the arguments of the calling function.
  #
  # Variable prefix: fc
  #
  func_check()
  {
    if test "$#" -lt 3
    then
      error 'func_check() needs at least 3 arguments.';
    fi;
    fc_fname="$1";
    case "$3" in
    1)
      fc_nargs="$3";
      fc_s='';
      ;;
    0|[2-9])
      fc_nargs="$3";
      fc_s='s';
      ;;
    *)
      error "func_check(): third argument must be a digit.";
      ;;
    esac;
### func_check()
    case "$2" in
    '='|'-eq')
      fc_op='-eq';
      fc_comp='exactly';
      ;;
    '>='|'-ge')
      fc_op='-ge';
      fc_comp='at least';
      ;;
    '<='|'-le')
      fc_op='-le';
      fc_comp='at most';
      ;;
    '<'|'-lt')
      fc_op='-lt';
      fc_comp='less than';
      ;;
    '>'|'-gt')
      fc_op='-gt';
      fc_comp='more than';
      ;;
    '!='|'-ne')
      fc_op='-ne';
      fc_comp='not';
      ;;
### func_check()
    *)
      error \
        'func_check(): second argument is not a relational operator.';
      ;;
    esac;
    shift;
    shift;
    shift;
    if test "$#" "${fc_op}" "${fc_nargs}"
    then
      do_nothing;
    else
      error "func_check(): \
${fc_fname}"'() needs '"${fc_comp} ${fc_nargs}"' argument'"${fc_s}"'.';
    fi;
    func_push "${fc_fname}";
    if test _"${_DEBUG_STACKS}"_ = _yes_
    then
      echo2 '+++ '"${fc_fname} $@";
      echo2 '>>> '"${_FUNC_STACK}";
    fi;
    eval ${_UNSET} fc_comp;
    eval ${_UNSET} fc_fname;
    eval ${_UNSET} fc_nargs;
    eval ${_UNSET} fc_op;
    eval ${_UNSET} fc_s;
  } # func_check()


  #############
  # func_pop ()
  #
  # Retrieve the top element from the function stack.  This is called
  # by every return variable in each function.
  #
  # The stack elements are separated by `!'; the popped element is
  # identical to the original element, except that all `!' characters
  # were removed.
  #
  # Arguments: 1
  #
  func_pop()
  {
    if test "$#" -ne 0
    then
      error 'func_pop() does not have arguments.';
    fi;
    case "${_FUNC_STACK}" in
    '')
      if test _"${_DEBUG_STACKS}"_ = _yes_
      then
        error 'func_pop(): stack is empty.';
      fi;
      ;;
    *!*)
      # split at first bang `!'.
      _FUNC_STACK="$(echo1 "${_FUNC_STACK}" | sed 's/^[^!]*!//')";
      exit_test;
      ;;
    *)
      _FUNC_STACK='';
      ;;
    esac;
    if test _"${_DEBUG_STACKS}"_ = _yes_
    then
      echo2 '<<< '"${_FUNC_STACK}";
    fi;
  } # func_pop()


  #############
  # func_push (<element>)
  #
  # Store another element to the function stack.  This is called by
  # func_check() at the beginning of each function.
  #
  # The stack elements are separated by `!'; if <element> contains a `!'
  # it is removed first.
  #
  # Arguments: 1
  #
  # Variable prefix: fp
  #
  func_push()
  {
    if test "$#" -ne 1
    then
      error 'func_push() needs 1 argument.';
    fi;
    case "$1" in
    *'!'*)
      # remove all bangs `!'.
      fp_element="$(echo1 "$1" | sed 's/!//g')";
      exit_test;
      ;;
    *)
      fp_element="$1";
      ;;
    esac;
    if test _"${_FUNC_STACK}"_ = __
    then
      _FUNC_STACK="${fp_element}";
    else
      _FUNC_STACK="${fp_element}!${_FUNC_STACK}";
    fi;
    eval ${_UNSET} fp_element;
  } # func_push()


  #############
  # func_stack_dump ()
  #
  # Print the content of the function stack.  Ignore the arguments.
  #
  func_stack_dump()
  {
    diag 'call stack(): '"${_FUNC_STACK}";
  } # func_stack_dump()

else				# $_DEBUG_FUNC_CHECK is not `yes'

  func_check() { return; }
  func_pop() { return; }
  func_push() { return; }
  func_stack_dump() { return; }

fi;				# test of $_DEBUG_FUNC_CHECK


########################################################################
# get_first_essential (<arg>*)
#
# Retrieve first non-empty argument.
#
# Return  : `1' if all arguments are empty, `0' if found.
# Output  : the retrieved non-empty argument.
#
# Variable prefix: gfe
#
get_first_essential()
{
  func_check get_first_essential '>=' 0 "$@";
  if is_equal "$#" 0
  then
    eval "${return_ok}";
  fi;
  for i
  do
    gfe_var="$i";
    if obj gfe_var is_not_empty
    then
      obj gfe_var echo1;
      eval ${_UNSET} gfe_var;
      eval "${return_ok}";
    fi;
  done;
  eval ${_UNSET} gfe_var;
  eval "${return_bad}";
} # get_first_essential()


########################################################################
landmark '5: is_*()';
########################################################################

########################################################################
# is_dir (<name>)
#
# Test whether `name' is a readable directory.
#
# Arguments : 1
# Return    : `0' if arg1 is a directory, `1' otherwise.
#
is_dir()
{
  func_check is_dir '=' 1 "$@";
  if is_not_empty "$1" && test -d "$1" && test -r "$1"
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_dir()


########################################################################
# is_empty (<string>)
#
# Test whether <string> is empty.
#
# Arguments : <=1
# Return    : `0' if arg1 is empty or does not exist, `1' otherwise.
#
is_empty()
{
  func_check is_empty '=' 1 "$@";
  if test _"$1"_ = __
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_empty()


########################################################################
# is_empty_file (<file_name>)
#
# Test whether <file_name> is an empty existing file.
#
# Arguments : <=1
# Return    :
#   `0' if arg1 is an empty existing file
#   `1' otherwise
#
is_empty_file()
{
  func_check is_empty_file '=' 1 "$@";
  if is_file "$1"
  then
    if test -s "$1"
    then
      eval "${return_no}";
    else
      eval "${return_yes}";
    fi;
  fi;
  eval "${return_no}";
} # is_empty_file()


########################################################################
# is_equal (<string1> <string2>)
#
# Test whether <string1> is equal to <string2>.
#
# Arguments : 2
# Return    : `0' both arguments are equal strings, `1' otherwise.
#
is_equal()
{
  func_check is_equal '=' 2 "$@";
  if test _"$1"_ = _"$2"_
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_equal()


########################################################################
# is_existing (<name>)
#
# Test whether <name> is an existing file or directory.  Solaris 2.5 does
# not have `test -e'.
#
# Arguments : 1
# Return    : `0' if arg1 exists, `1' otherwise.
#
is_existing()
{
  func_check is_existing '=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_no}";
  fi;
  if test -f "$1" || test -d "$1" || test -c "$1"
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_existing()


########################################################################
# is_file (<name>)
#
# Test whether <name> is a readable file.
#
# Arguments : 1
# Return    : `0' if arg1 is a readable file, `1' otherwise.
#
is_file()
{
  func_check is_file '=' 1 "$@";
  if is_not_empty "$1" && test -f "$1" && test -r "$1"
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_file()


########################################################################
# is_greater_than (<integer1> <integer2>)
#
# Test whether <integer1> is greater than <integer2>.
#
# Arguments : 2
# Return    : `0' if <integer1> is a greater integer than <integer2>,
#             `1' otherwise.
#
is_greater_than()
{
  func_check is_greater_than '=' 2 "$@";
  if is_integer "$1" && is_integer "$2" && test "$1" -gt "$2"
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_greater_than()


########################################################################
# is_integer (<string>)
#
# Test whether `string' is an integer.
#
# Arguments : 1
# Return    : `0' if argument is an integer, `1' otherwise.
#
is_integer()
{
  func_check is_integer '=' 1 "$@";
  if is_equal "$(echo1 "$1" | sed -n '
s/^[0-9][0-9]*$/ok/p
s/^[-+][0-9][0-9]*$/ok/p
')" 'ok'
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_integer()


########################################################################
# is_not_empty_file (<file_name>)
#
# Test whether <file_name> is a non-empty existing file.
#
# Arguments : <=1
# Return    :
#   `0' if arg1 is a non-empty existing file
#   `1' otherwise
#
is_not_empty_file()
{
  func_check is_not_empty_file '=' 1 "$@";
  if is_file "$1" && test -s "$1"
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_not_empty_file()


########################################################################
# is_not_dir (<name>)
#
# Test whether <name> is not a readable directory.
#
# Arguments : 1
# Return    : `0' if arg1 is a directory, `1' otherwise.
#
is_not_dir()
{
  func_check is_not_dir '=' 1 "$@";
  if is_dir "$1"
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_dir()


########################################################################
# is_not_empty (<string>)
#
# Test whether <string> is not empty.
#
# Arguments : <=1
# Return    : `0' if arg1 exists and is not empty, `1' otherwise.
#
is_not_empty()
{
  func_check is_not_empty '=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_empty()


########################################################################
# is_not_equal (<string1> <string2>)
#
# Test whether <string1> differs from <string2>.
#
# Arguments : 2
#
is_not_equal()
{
  func_check is_not_equal '=' 2 "$@";
  if is_equal "$1" "$2"
  then
    eval "${return_no}";
  fi
  eval "${return_yes}";
} # is_not_equal()


########################################################################
# is_not_file (<filename>)
#
# Test whether <filename> is a not readable file.
#
# Arguments : 1 (empty allowed)
#
is_not_file()
{
  func_check is_not_file '=' 1 "$@";
  if is_file "$1"
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_file()


########################################################################
# is_not_prog (<program>)
#
# Verify that <program> is not a command in $PATH.
#
# Arguments : 1,  <program> can have spaces and arguments.
#
is_not_prog()
{
  func_check is_not_prog '=' 1 "$@";
  if where_is_prog "$1" >${_NULL_DEV}
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_prog()


########################################################################
# is_not_writable (<name>)
#
# Test whether <name> is not a writable file or directory.
#
# Arguments : >=1 (empty allowed), more args are ignored
#
is_not_writable()
{
  func_check is_not_writable '>=' 1 "$@";
  if is_writable "$1"
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_writable()


########################################################################
# is_not_X ()
#
# Test whether the script is not running in X Window by checking $DISPLAY.
#
is_not_X()
{
  func_check is_not_X '=' 0 "$@";
  if obj DISPLAY is_empty
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_not_X()


########################################################################
# is_not_yes (<string>)
#
# Test whether <string> is not `yes'.
#
# Arguments : 1
#
is_not_yes()
{
  func_check is_not_yes = 1 "$@";
  if is_yes "$1"
  then
    eval "${return_no}";
  fi;
  eval "${return_yes}";
} # is_not_yes()


########################################################################
# is_prog (<name>)
#
# Determine whether <name> is a program in $PATH.
#
# Arguments : 1,  <program> can have spaces and arguments.
#
is_prog()
{
  func_check is_prog '=' 1 "$@";
  if where_is_prog "$1" >${_NULL_DEV}
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_prog()


########################################################################
# is_writable (<name>)
#
# Test whether <name> is a writable file or directory.
#
# Arguments : >=1 (empty allowed), more args are ignored
#
is_writable()
{
  func_check is_writable '>=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_no}";
  fi;
  if test -r "$1"
  then
    if test -w "$1"
    then
      eval "${return_yes}";
    fi;
  fi;
  eval "${return_no}";
} # is_writable()


########################################################################
# is_X ()
#
# Test whether the script is running in X Window by checking $DISPLAY.
#
is_X()
{
  func_check is_X '=' 0 "$@";
  if obj DISPLAY is_not_empty
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_X()


########################################################################
# is_yes (<string>)
#
# Test whether <string> has value `yes'.
#
# Return    : `0' if arg1 is `yes', `1' otherwise.
#
is_yes()
{
  func_check is_yes '=' 1 "$@";
  if is_equal "$1" 'yes'
  then
    eval "${return_yes}";
  fi;
  eval "${return_no}";
} # is_yes()


########################################################################
# landmark ()
#
# Print debugging information on standard error if $_DEBUG_LM is `yes'.
#
# Globals: $_DEBUG_LM
#
# Defined in section `Debugging functions'.


########################################################################
# leave ([<code>])
#
# Clean exit without an error or with error <code>.
#
leave()
{
  clean_up;
  if test $# = 0
  then
    exit "${_OK}";
  else
    exit "$1";
  fi;
} # leave()


########################################################################
landmark '6: list_*()';
########################################################################
#
# `list' is an object class that represents an array or list.  Its
# data consists of space-separated single-quoted elements.  So a list
# has the form "'first' 'second' '...' 'last'".  See list_append() for
# more details on the list structure.  The array elements of `list'
# can be get by `eval set x "$list"; shift`.


########################################################################
# list_append (<list> <element>...)
#
# Add one or more elements to an existing list.  <list> may also be
# empty.
#
# Arguments: >=2
#   <list>: a variable name for a list of single-quoted elements
#   <element>:  some sequence of characters.
# Output: none, but $<list> is set to
#   if <list> is empty:  "'<element>' '...'"
#   otherwise:           "$list '<element>' ..."
#
# Variable prefix: la
#
list_append()
{
  func_check list_append '>=' 2 "$@";
  la_name="$1";
  eval la_list='"${'"$1"'}"';
  shift;
  for s
  do
    la_s="$s";
    case "${la_s}" in
    *\'*)
      # escape each single quote by replacing each
      # "'" (squote) by "'\''" (squote bslash squote squote);
      # note that the backslash must be doubled in the following `sed'
      la_element="$(echo1 "${la_s}" | sed 's/'"${_SQ}"'/&\\&&/g')";
      exit_test;
      ;;
    '')
      la_element="";
      ;;
    *)
      la_element="${la_s}";
      ;;
    esac;
### list_append()
    if obj la_list is_empty
    then
      la_list="'${la_element}'";
    else
      la_list="${la_list} '${la_element}'";
    fi;
  done;
  eval "${la_name}"='"${la_list}"';
  eval ${_UNSET} la_element;
  eval ${_UNSET} la_list;
  eval ${_UNSET} la_name;
  eval ${_UNSET} la_s;
  eval "${return_ok}";
} # list_append()


########################################################################
# list_from_cmdline (<pre_name_of_opt_lists> [<cmdline_arg>...])
#
# Transform command line arguments into a normalized form.
#
# Options, option arguments, and file parameters are identified and
# output each as a single-quoted argument of its own.  Options and
# file parameters are separated by a '--' argument.
#
# Arguments: >=1
#   <pre_name>: common part of a set of 4 environment variable names:
#     $<pre_name>_SHORT_NA:  list of short options without an arg.
#     $<pre_name>_SHORT_ARG: list of short options that have an arg.
#     $<pre_name>_LONG_NA:   list of long options without an arg.
#     $<pre_name>_LONG_ARG:  list of long options that have an arg.
#   <cmdline_arg>...: the arguments from a command line, such as "$@",
#                     the content of a variable, or direct arguments.
#
# Output: ['-[-]opt' ['optarg']]... '--' ['filename']...
#
# Example:
#   list_from_cmdline PRE -a f1 -bcarg --lon=larg f2 low larg2
#     PRE_SHORT_NA="'a' 'b'"
#     PRE_SHORT_ARG="'c' 'd'"
#     PRE_LONG_NA="'help' 'version'"
#     PRE_LONG_ARG="'longer' 'lower'"
# This will result in printing:
#   '-a' '-b' '-c' 'arg' '--longer' 'larg' '--lower' 'larg2' '--' 'f1' 'f2'
#
#   Use this function in the following way:
#     eval set x "$(list_from_cmdline PRE_NAME "$@")";
#     shift;
#     while test "$1" != '--'; do
#       case "$1" in
#       ...
#       esac;
#       shift;
#     done;
#     shift;         #skip '--'
#     # all positional parameters ("$@") left are file name parameters.
#
# Variable prefix: lfc
#
list_from_cmdline()
{
  func_check list_from_cmdline '>=' 1 "$@";
  # short options, no argument
  obj_from_output lfc_short_n obj_data "$1"_SHORT_NA;
  # short options, with argument
  obj_from_output lfc_short_a obj_data "$1"_SHORT_ARG;
  # long options, no argument
  obj_from_output lfc_long_n obj_data "$1"_LONG_NA;
  # long options, with argument
  obj_from_output lfc_long_a obj_data "$1"_LONG_ARG;
  if obj lfc_short_n is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_SHORT_NA options.';
  fi;
  if obj lfc_short_a is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_SHORT_ARG options.';
  fi;
  if obj lfc_long_n is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_LONG_NA options.';
  fi;
  if obj lfc_long_a is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_LONG_ARG options.';
  fi;
  shift;

  if is_equal "$#" 0
  then
    echo1 "'--'"
    eval ${_UNSET} lfc_fparams;
    eval ${_UNSET} lfc_short_a;
    eval ${_UNSET} lfc_short_n;
### list_from_cmdline()
    eval ${_UNSET} lfc_long_a;
    eval ${_UNSET} lfc_long_n;
    eval ${_UNSET} lfc_result;
    eval "${return_ok}";
  fi;

  lfc_fparams='';
  lfc_result='';
  while is_greater_than "$#" 0
  do
    lfc_arg="$1";
    shift;
    case "${lfc_arg}" in
    --) break; ;;
    --*=*)
      # delete leading '--';
      lfc_with_equal="$(echo1 "${lfc_arg}" | sed 's/^--//')";
      # extract option by deleting from the first '=' to the end
      lfc_abbrev="$(echo1 "${lfc_with_equal}" | \
                    sed 's/^\([^=]*\)=.*$/\1/')";
      obj_from_output lfc_opt \
        list_single_from_abbrev lfc_long_a "${lfc_abbrev}";
      if obj lfc_opt is_empty
      then
        error_user "--${lfc_abbrev} is not an option.";
      else
        # get the option argument by deleting up to first `='
        lfc_optarg="$(echo1 "${lfc_with_equal}" | sed 's/^[^=]*=//')";
        exit_test;
        list_append lfc_result "--${lfc_opt}" "${lfc_optarg}";
        continue;
      fi;
### list_from_cmdline()
      ;;
    --*)
      # delete leading '--';
      lfc_abbrev="$(echo1 "${lfc_arg}" | sed 's/^--//')";
      if list_has lfc_long_n "${lfc_abbrev}"
      then
        lfc_opt="${lfc_abbrev}";
      else
        obj_from_output lfc_opt \
          list_single_from_abbrev lfc_long_n "${lfc_abbrev}";
        if obj lfc_opt is_not_empty && is_not_equal "$#" 0
        then
          obj_from_output a \
            list_single_from_abbrev lfc_long_a "${lfc_abbrev}";
          if obj a is_not_empty
          then
            error_user "The abbreviation ${lfc_arg} \
has multiple options: --${lfc_opt} and --${a}.";
          fi;
        fi;
      fi; # if list_has lfc_long_n "${lfc_abbrev}"
      if obj lfc_opt is_not_empty
      then
        # long option, no argument
        list_append lfc_result "--${lfc_opt}";
        continue;
      fi;
      obj_from_output lfc_opt \
        list_single_from_abbrev lfc_long_a "${lfc_abbrev}";
      if obj lfc_opt is_not_empty
      then
### list_from_cmdline()
        # long option with argument
        if is_equal "$#" 0
        then
          error_user "no argument for option --${lfc_opt}."
        fi;
        list_append lfc_result "--${lfc_opt}" "$1";
        shift;
        continue;
      fi; # if obj lfc_opt is_not_empty
      error_user "${lfc_arg} is not an option.";
      ;;
    -?*)			# short option (cluster)
      # delete leading `-';
      lfc_rest="$(echo1 "${lfc_arg}" | sed 's/^-//')";
      exit_test;
      while obj lfc_rest is_not_empty
      do
        # get next short option from cluster (first char of $lfc_rest)
        lfc_optchar="$(echo1 "${lfc_rest}" | sed 's/^\(.\).*$/\1/')";
        # remove first character from ${lfc_rest};
        lfc_rest="$(echo1 "${lfc_rest}" | sed 's/^.//')";
        exit_test;
        if list_has lfc_short_n "${lfc_optchar}"
        then
          list_append lfc_result "-${lfc_optchar}";
          continue;
        elif list_has lfc_short_a "${lfc_optchar}"
        then
          if obj lfc_rest is_empty
          then
            if is_greater_than "$#" 0
            then
### list_from_cmdline()
              list_append lfc_result "-${lfc_optchar}" "$1";
              shift;
              continue;
            else
              error_user "no argument for option -${lfc_optchar}.";
            fi;
          else			# rest is the argument
            list_append lfc_result "-${lfc_optchar}" "${lfc_rest}";
            lfc_rest='';
            continue;
          fi; # if obj lfc_rest is_empty
        else
          error_user "unknown option -${lfc_optchar}.";
        fi; # if list_has lfc_short_n "${lfc_optchar}"
      done; # while obj lfc_rest is_not_empty
      ;;
    *)
      # Here, $lfc_arg is not an option, so a file parameter.
      list_append lfc_fparams "${lfc_arg}";

      # Ignore the strange POSIX option handling to end option
      # parsing after the first file name argument.  To reuse it, do
      # a `break' here if $POSIXLY_CORRECT of `bash' is not empty.
      # When `bash' is called as `sh' $POSIXLY_CORRECT is set
      # automatically to `y'.
      ;;
    esac; # case "${lfc_arg}" in
  done; # while is_greater_than "$#" 0
  list_append lfc_result '--';
  if obj lfc_fparams is_not_empty
  then
    lfc_result="${lfc_result} ${lfc_fparams}";
  fi;
### list_from_cmdline()
  if is_greater_than "$#" 0
  then
    list_append lfc_result "$@";
  fi;
  obj lfc_result echo1;
  eval ${_UNSET} lfc_abbrev;
  eval ${_UNSET} lfc_fparams;
  eval ${_UNSET} lfc_short_a;
  eval ${_UNSET} lfc_short_n;
  eval ${_UNSET} lfc_long_a;
  eval ${_UNSET} lfc_long_n;
  eval ${_UNSET} lfc_result;
  eval ${_UNSET} lfc_arg;
  eval ${_UNSET} lfc_opt;
  eval ${_UNSET} lfc_opt_arg;
  eval ${_UNSET} lfc_opt_char;
  eval ${_UNSET} lfc_with_equal;
  eval ${_UNSET} lfc_rest;
  eval "${return_ok}";
} # list_from_cmdline()


########################################################################
# list_from_cmdline_with_minus (<pre_name_of_opt_lists> [<cmdline_arg>...])
#
# Transform command line arguments into a normalized form with a double
# abbreviation before and after an internal `-' sign.
#
# Options, option arguments, and file parameters are identified and
# output each as a single-quoted argument of its own.  Options and
# file parameters are separated by a `--' argument.
#
# Arguments: >=1
#   <pre_name>: common part of a set of 4 environment variable names:
#     $<pre_name>_SHORT_NA:  list of short options without an arg.
#     $<pre_name>_SHORT_ARG: list of short options that have an arg.
#     $<pre_name>_LONG_NA:   list of long options without an arg.
#     $<pre_name>_LONG_ARG:  list of long options that have an arg.
#   <cmdline_arg>...: the arguments from a command line, such as "$@",
#                     the content of a variable, or direct arguments.
#
# Output: ['-[-]opt' ['optarg']]... '--' ['filename']...
#
# Example:
#   list_from_cmdline PRE -a f1 -bcarg --lon=larg --h-n f2 low larg2
#     PRE_SHORT_NA="'a' 'b'"
#     PRE_SHORT_ARG="'c' 'd'"
#     PRE_LONG_NA="'help' 'version' 'hi-non-arg'"
#     PRE_LONG_ARG="'long-arg' 'low-arg'"
# This will result in printing:
#   '-a' '-b' '-c' 'arg' '--long-arg' 'larg' '--hi-non-arg' \
#     '--low-arg' 'larg2' '--' 'f1' 'f2'
#
# Use this function in the following way:
#   eval set x "$(list_from_cmdline_with_minus PRE_NAME "$@")";
#   shift;
#   while test "$1" != '--'; do
#     case "$1" in
#     ...
#     esac;
#     shift;
#   done;
#   shift;         #skip '--'
#   # all positional parameters ("$@") left are file name parameters.
#
# Variable prefix: lfcwm
#
list_from_cmdline_with_minus()
{
  func_check list_from_cmdline_with_minus '>=' 1 "$@";
  # short options, no argument
  obj_from_output lfcwm_short_n obj_data "$1"_SHORT_NA;
  # short options, with argument
  obj_from_output lfcwm_short_a obj_data "$1"_SHORT_ARG;
  # long options, no argument
  obj_from_output lfcwm_long_n obj_data "$1"_LONG_NA;
  # long options, with argument
  obj_from_output lfcwm_long_a obj_data "$1"_LONG_ARG;
  if obj lfcwm_short_n is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_SHORT_NA options.';
  fi;
  if obj lfcwm_short_a is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_SHORT_ARG options.';
  fi;
  if obj lfcwm_long_n is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_LONG_NA options.';
  fi;
  if obj lfcwm_long_a is_empty
  then
    error 'list_from_cmdline(): no $'"$1"'_LONG_ARG options.';
  fi;
  shift;

  if is_equal "$#" 0
  then
    echo1 "'--'";
    eval ${_UNSET} lfcwm_short_a;
    eval ${_UNSET} lfcwm_short_n;
### list_from_cmdline_with_minus()
    eval ${_UNSET} lfcwm_long_a;
    eval ${_UNSET} lfcwm_long_n;
    eval "${return_ok}";
  fi;
  obj_from_output lfcwm_long_both lists_combine lfcwm_long_a lfcwm_long_n;
  lfcwm_fparams='';
  lfcwm_result='';
  while is_greater_than "$#" 0	# command line arguments
  do
    lfcwm_arg="$1";
    shift;
    lfcwm_optarg='';
    case "${lfcwm_arg}" in
    --)
      break;
      ;;
    --*=*)
      # delete leading '--';
      lfcwm_with_equal="$(echo1 "${lfcwm_arg}" | sed 's/^--//')";
      # extract option by deleting from the first '=' to the end
      lfcwm_abbrev="$(echo1 "${lfcwm_with_equal}" | \
                    sed 's/^\([^=]*\)=.*$/\1/')";
      # extract option argument by deleting up to the first '='
      lfcwm_optarg="$(echo1 "${lfcwm_with_equal}" | \
                    sed 's/^[^=]*=\(.*\)$/\1/')";
### list_from_cmdline_with_minus()
      if list_has lfcwm_long_a "${lfcwm_abbrev}"
      then
        lfcwm_opt="${lfcwm_abbrev}";
      else
        obj_from_output lfcwm_opt \
          _search_abbrev lfcwm_long_a "${lfcwm_abbrev}";
      fi;
      list_append lfcwm_result "--${lfcwm_opt}" "${lfcwm_optarg}";
      continue;
      ;;
    --*)
      # delete leading '--';
      lfcwm_abbrev="$(echo1 "${lfcwm_arg}" | sed 's/^--//')";
      if list_has lfcwm_long_both "${lfcwm_abbrev}"
      then
        lfcwm_opt="${lfcwm_abbrev}";
      else
        obj_from_output lfcwm_opt \
          _search_abbrev lfcwm_long_both "${lfcwm_abbrev}";
      fi;
### list_from_cmdline_with_minus()
      if list_has lfcwm_long_a "${lfcwm_opt}"
      then
        if is_equal "$#" 0
        then
          error_user "Option ${lfcwm_opt} needs an argument.";
        fi;
        lfcwm_optarg="$1";
        shift;
        list_append lfcwm_result "--${lfcwm_opt}" "${lfcwm_optarg}";
      else
        list_append lfcwm_result "--${lfcwm_opt}";
      fi;
      continue;
      ;;
    -?*)			# short option (cluster)
      # delete leading '-';
      lfcwm_rest="$(echo1 "${lfcwm_arg}" | sed 's/^-//')";
      while obj lfcwm_rest is_not_empty
      do
        # get next short option from cluster (first char of $lfcwm_rest)
        lfcwm_optchar="$(echo1 "${lfcwm_rest}" | sed 's/^\(.\).*$/\1/')";
        # remove first character from ${lfcwm_rest};
        lfcwm_rest="$(echo1 "${lfcwm_rest}" | sed 's/^.//')";
        if list_has lfcwm_short_n "${lfcwm_optchar}"
        then
          list_append lfcwm_result "-${lfcwm_optchar}";
          continue;
        elif list_has lfcwm_short_a "${lfcwm_optchar}"
        then
          if obj lfcwm_rest is_empty
          then
            if is_greater_than "$#" 0
            then
### list_from_cmdline_with_minus()
              list_append lfcwm_result "-${lfcwm_optchar}" "$1";
              shift;
              continue;
            else
              error_user "no argument for option -${lfcwm_optchar}.";
            fi;
          else			# rest is the argument
            list_append lfcwm_result "-${lfcwm_optchar}" "${lfcwm_rest}";
            lfcwm_rest='';
            continue;
          fi; # if obj lfcwm_rest is_empty
        else
          error_user "unknown option -${lfcwm_optchar}.";
        fi; # if list_has lfcwm_short_n "${lfcwm_optchar}"
      done; # while obj lfcwm_rest is_not_empty
      ;;
    *)
      # Here, $lfcwm_arg is not an option, so a file parameter.
      list_append lfcwm_fparams "${lfcwm_arg}";

      # Ignore the strange POSIX option handling to end option
      # parsing after the first file name argument.  To reuse it, do
      # a `break' here if $POSIXLY_CORRECT of `bash' is not empty.
      # When `bash' is called as `sh' $POSIXLY_CORRECT is set
      # automatically to `y'.
      ;;
    esac;
  done;

  list_append lfcwm_result '--';
  if obj lfcwm_fparams is_not_empty
  then
    lfcwm_result="${lfcwm_result} ${lfcwm_fparams}";
  fi;
### list_from_cmdline_with_minus()
  if is_greater_than "$#" 0
  then
    list_append lfcwm_result "$@";
  fi;
  obj lfcwm_result echo1;
  eval ${_UNSET} lfcwm_abbrev;
  eval ${_UNSET} lfcwm_fparams;
  eval ${_UNSET} lfcwm_short_a;
  eval ${_UNSET} lfcwm_short_n;
  eval ${_UNSET} lfcwm_long_a;
  eval ${_UNSET} lfcwm_long_both;
  eval ${_UNSET} lfcwm_long_n;
  eval ${_UNSET} lfcwm_result;
  eval ${_UNSET} lfcwm_arg;
  eval ${_UNSET} lfcwm_opt;
  eval ${_UNSET} lfcwm_optarg;
  eval ${_UNSET} lfcwm_optchar;
  eval ${_UNSET} lfcwm_with_equal;
  eval ${_UNSET} lfcwm_rest;
  eval "${return_ok}";
} # list_from_cmdline_with_minus()


# _search_abbrev (<list> <abbrev>)
#
# Check whether <list> has an element constructed from the abbreviation
# <abbrev>.  All `-' in <abbrev> are replaced by `-*'.  This construction
# is searched first with `<construction>[^-]*'.  If there is more than a
# single element an error is created.  If none is found `<construction>*'
# is searched.  Again an error is created for several results.
# This function was constructed from the former function
# list_single_from_abbrev().
#
# This is a local function of list_from_cmdline_with_minus().
#
# Arguments: 2
#   <list>:   a variable name for a list of single-quoted elements
#   <abbrev>: some sequence of characters.
#
# Output: the found element (always not empty), error when none found.
#
# Variable prefix: _sa
#
_search_abbrev()
{
  func_check _search_abbrev '=' 2 "$@";
  eval _sa_list='"${'$1'}"';
  if obj _sa_list is_empty
  then
    error "_search_abbrev(): list is empty.";
  fi;

  _sa_abbrev="$2";
  if obj _sa_abbrev is_empty
  then
    error "_search_abbrev(): abbreviation argument is empty.";
  fi;

  _sa_case="$(echo1 "${_sa_abbrev}" | sed 's/-/\*-/g')";
  _sa_opt='';
  case " ${_sa_list}" in
  *\ \'${_sa_case}*)		# list has the abbreviation
    _sa_m1='';
    _sa_m2='';
    _sa_nm='';
    eval set x "${_sa_list}";
    shift;
    for i			# over the option list
    do
      _sa_i="$i";
### _search_abbrev() of list_from_cmdline_with_minus()
      case "${_sa_i}" in
      ${_sa_case}*-*)
        if obj _sa_m1 is_empty
        then
          _sa_m1="${_sa_i}";
          continue;
        fi;
        _sa_m2="${_sa_i}";
        continue;
        ;;
      ${_sa_case}*)
        if obj _sa_nm is_empty
        then
          _sa_nm="${_sa_i}";
          continue;
        fi;
        error_user "The abbreviation --${_sa_abbrev} has multiple options "\
"--${_sa_nm} and --${_sa_i}.";
        ;;
      esac;
    done;
    if obj _sa_nm is_empty
    then
      if obj _sa_m2 is_not_empty
      then
        error_user "The abbreviation --${_sa_abbrev} has multiple options "\
"--${_sa_m1} and --${_sa_m2}.";
      fi;
### _search_abbrev() of list_from_cmdline_with_minus()
      if obj _sa_m1 is_not_empty
      then
        _sa_opt="${_sa_m1}";
      fi;
    else
      _sa_opt="${_sa_nm}";
    fi;
    ;;
  esac;
  if obj _sa_opt is_empty
  then
    error_user "--${_sa_abbrev} is not an option.";
  fi;
  obj _sa_opt echo1;
  eval "${_UNSET}" _sa_abbrev;
  eval "${_UNSET}" _sa_case;
  eval "${_UNSET}" _sa_i;
  eval "${_UNSET}" _sa_list;
  eval "${_UNSET}" _sa_m1;
  eval "${_UNSET}" _sa_m2;
  eval "${_UNSET}" _sa_nm;
  eval "${_UNSET}" _sa_opt;
  eval "${return_ok}";
} # _search_abbrev() of list_from_cmdline_with_minus()


########################################################################
# list_from_file (<list_name> <file_name>)
#
# Extrect the lines from <file_name> and store them as elements to list
# <list_name>.
#
# Arguments: 2
#   <list_name>: a variable name for output, a list of single-quoted elts
#   <file_name>: the name of an existing file
#
# Variable prefix: lff
#
list_from_file()
{
  func_check list_from_file '=' 2 "$@";
  if is_not_file "$2"
  then
    eval "${return_bad}";
  fi;
  lff_n="$(wc -l "$2" | eval sed "'s/^[ ${_TAB}]*\([0-9]\+\).*$/\1/'")";
  eval "$1"="''";
  if obj lff_n is_equal 0
  then
    eval "${return_good}";
  fi;
  lff_i=0;
  while obj lff_i is_not_equal "${lff_n}"
  do
    lff_i="$(expr "${lff_i}" + 1)";
    list_append "$1" "$(eval sed -n "'${lff_i}p
${lff_i}q'" "'$2'")";
  done;
  eval "${_UNSET}" lff_i;
  eval "${_UNSET}" lff_n;
  eval "${return_good}";
} # list_from_file()


########################################################################
# list_from_split (<string> <separator_char>)
#
# Split <string> by <separator_char> into a list, omitting the separator.
#
# Arguments: 2: a <string> that is to be split into parts divided by
#               character <separator_char>
# Output: the resulting list string
#
# Variable prefix: lfs
#
list_from_split()
{
  func_check list_from_split = 2 "$@";
  if is_empty "$1"
  then
    eval "${return_ok}";
  fi;
  case "$2" in
  ?)
    lfs_splitter="$2";
    ;;
  '\:')
    lfs_splitter=':';
    ;;
  *)
    error "list_from_split(): split argument $2 must be a single character.";
    ;;
  esac;
  lfs_list='';
  lfs_rest="$1";
  while :
  do
    case "${lfs_rest}" in
    *${lfs_splitter}*)
      case "${lfs_splitter}" in
      /)
        lfs_elt="$(echo1 ${lfs_rest} | sed \
          's|^\([^'"${lfs_splitter}"']*\)'"${lfs_splitter}"'.*|\1|')";
        lfs_rest="$(echo1 ${lfs_rest} | sed \
          's|^[^'"${lfs_splitter}"']*'"${lfs_splitter}"'\(.*\)$|\1|')";
        ;;
      *)
### list_from_split()
        lfs_elt="$(echo1 ${lfs_rest} | sed \
          's/^\([^'"${lfs_splitter}"']*\)'"${lfs_splitter}"'.*/\1/')";
        lfs_rest="$(echo1 ${lfs_rest} | sed \
          's/^[^'"${lfs_splitter}"']*'"${lfs_splitter}"'\(.*\)$/\1/')";
        ;;
      esac;
      list_append lfs_list "${lfs_elt}"
      continue;
      ;;
    *)
      list_append lfs_list "${lfs_rest}"
      break
      ;;
    esac;
  done
  echo1 "${lfs_list}";

  eval ${_UNSET} lfs_elt;
  eval ${_UNSET} lfs_list;
  eval ${_UNSET} lfs_rest;
  eval ${_UNSET} lfs_splitter;
  eval "${return_ok}";
} # list_from_split()


########################################################################
# list_has (<list-name> <element>)
#
# Test whether the list <list-name> has the element <element>.
#
# Arguments: 2
#   <list_name>: a variable name for a list of single-quoted elements
#   <element>:  some sequence of characters.
#
# Variable prefix: lh
#
list_has()
{
  func_check list_has = 2 "$@";
  eval lh_list='"${'$1'}"';
  if obj lh_list is_empty
  then
    eval "${_UNSET}" lh_list;
    eval "${return_no}";
  fi;
  case "$2" in
    \'*\')  lh_element=" $2 "; ;;
    *)      lh_element=" '$2' "; ;;
  esac;
  if string_contains " ${lh_list} " "${lh_element}"
  then
    eval "${_UNSET}" lh_list;
    eval "${_UNSET}" lh_element;
    eval "${return_yes}";
  else
    eval "${_UNSET}" lh_list;
    eval "${_UNSET}" lh_element;
    eval "${return_no}";
  fi;
} # list_has()


########################################################################
# list_has_abbrev (<list_var> <abbrev>)
#
# Test whether the list of <list_var> has an element starting with
# <abbrev>.
#
# Arguments: 2
#   <list_var>: a variable name for a list of single-quoted elements
#   <abbrev>:   some sequence of characters.
#
# Variable prefix: lha
#
list_has_abbrev()
{
  func_check list_has_abbrev '=' 2 "$@";
  eval lha_list='"${'$1'}"';
  if obj lha_list is_empty
  then
    eval "${_UNSET}" lha_list;
    eval "${return_no}";
  fi;
  case "$2" in
  \'*)
    lha_element="$(echo1 "$2" | sed 's/'"${_SQ}"'$//')";
    ;;
  *)
    lha_element="'$2";
    ;;
  esac;
  if string_contains " ${lha_list}" " ${lha_element}"
  then
    eval "${_UNSET}" lha_list;
    eval "${_UNSET}" lha_element;
    eval "${return_yes}";
  else
    eval "${_UNSET}" lha_list;
    eval "${_UNSET}" lha_element;
    eval "${return_no}";
  fi;
  eval "${return_ok}";
} # list_has_abbrev()


########################################################################
# list_has_not (<list> <element>)
#
# Test whether <list> has no <element>.
#
# Arguments: 2
#   <list>:    a space-separated list of single-quoted elements.
#   <element>: some sequence of characters.
#
# Variable prefix: lhn
#
list_has_not()
{
  func_check list_has_not = 2 "$@";
  eval lhn_list='"${'$1'}"';
  if obj lhn_list is_empty
  then
    eval "${_UNSET}" lhn_list;
    eval "${return_yes}";
  fi;
  case "$2" in
    \'*\') lhn_element=" $2 "; ;;
    *)     lhn_element=" '$2' "; ;;
  esac;
  if string_contains " ${lhn_list} " "${lhn_element}"
  then
    eval "${_UNSET}" lhn_list;
    eval "${_UNSET}" lhn_element;
    eval "${return_no}";
  else
    eval "${_UNSET}" lhn_list;
    eval "${_UNSET}" lhn_element;
    eval "${return_yes}";
  fi;
} # list_has_not()


########################################################################
# list_single_from_abbrev (<list-var> <abbrev>)
#
# Check whether the list has an element starting with <abbrev>.  If
# there are more than a single element an error is raised.
#
# Arguments: 2
#   <list-var>: a variable name for a list of single-quoted elements
#   <abbrev>:   some sequence of characters.
#
# Output: the found element.
#
# Variable prefix: lsfa
#
list_single_from_abbrev()
{
  func_check list_single_from_abbrev '=' 2 "$@";
  eval lsfa_list='"${'$1'}"';
  if obj lsfa_list is_empty
  then
    eval "${_UNSET}" lsfa_list;
    eval "${return_no}";
  fi;
  lsfa_abbrev="$2";
  if list_has lsfa_list "${lsfa_abbrev}"
  then
    obj lsfa_abbrev echo1;
    eval "${_UNSET}" lsfa_abbrev;
    eval "${_UNSET}" lsfa_list;
    eval "${return_yes}";
  fi;
  if list_has_abbrev lsfa_list "${lsfa_abbrev}"
  then
    lsfa_element='';
    eval set x "${lsfa_list}";
    shift;
### list_single_from_abbrev()
    for i
    do
      case "$i" in
      ${lsfa_abbrev}*)
        if obj lsfa_element is_not_empty
        then
          error_user "The abbreviation --${lsfa_abbrev} \
has multiple options: --${lsfa_element} and --${i}.";
        fi;
        lsfa_element="$i";
        ;;
      esac;
    done;
    obj lsfa_element echo1;
    eval "${_UNSET}" lsfa_abbrev;
    eval "${_UNSET}" lsfa_element;
    eval "${_UNSET}" lsfa_list;
    eval "${return_yes}";
  else
    eval "${_UNSET}" lsfa_abbrev;
    eval "${_UNSET}" lsfa_element;
    eval "${_UNSET}" lsfa_list;
    eval "${return_no}";
  fi;
} # list_single_from_abbrev()


########################################################################
# list_uniq (<list>)
#
# Generate a list with only unique elements.
#
# Output: the corrected list
#
# Variable prefix: lu
#
list_uniq()
{
  func_check list_uniq '=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_ok}";
  fi;
  eval a='"${'"$1"'}"';
  if obj a is_empty
  then
    eval "${return_ok}";
  fi;
  eval set x "$a";
  shift;
  lu_list='';
  for i
  do
    lu_i="$i";
    if list_has lu_list "${lu_i}"
    then
      continue;
    else
      list_append lu_list ${lu_i};
    fi;
  done;
  obj lu_list echo1;
  eval "${_UNSET}" lu_i;
  eval "${_UNSET}" lu_list;
  eval "${return_ok}";
} # list_uniq()


########################################################################
# lists_combine (<list1> <list2> ...)
#
# Combine several lists to a single list.  All arguments are list names.
#
# Output: the combined list
#
# Variable prefix: lc
#
lists_combine()
{
  func_check lists_combine '>=' 2 "$@";
  lc_list='';
  for i
  do
    eval lc_arg='"${'"$i"'}"';
    case "${lc_arg}" in
    '') :; ;;
    "'"*"'")
      if obj lc_list is_empty
      then
        lc_list="${lc_arg}";
      else
        lc_list="${lc_list} ${lc_arg}";
      fi;
      ;;
    *)
      error 'lists_combine(): $'"$i"' is not a list.';
      ;;
    esac;
  done;
  obj lc_list echo1;
  eval "${_UNSET}" lc_arg;
  eval "${_UNSET}" lc_list;
  eval "${return_ok}";
} # lists_combine()


########################################################################
landmark '7: man_*()';
########################################################################

########################################################################
# Information on the search of man pages in groffer

# The search of man pages is based on a set of directories.  That
# starts with the so-called man path.  This is determined in function
# man_setup() either by the command-line option --manpath, by $MANOPT,
# or by $MANPATH.  There is also a program `manpath'.  If all of this
# does not work a man path is created from $PATH with function
# manpath_set_from_path().  We now have a set of existing directories
# for the search of man pages; usually they end with `/man'.

# The directory set of the man path can be changed in 2 ways.  If
# operating system names are given in $SYSTEM or by --systems on the
# command-line all man path directory will be appended by these names.
# The appended system names replace the original man path; but if no
# system name is set, the original man path is kept.  In `groffer',
# this is done by the function manpath_add_lang_sys() in man_setup().

# The next addition for directories is the language.  It is specified
# by --locale or by one of the environment variables $LC_ALL,
# $LC_MESSAGES, and $LANG.  The language name of `C' or `POSIX' means
# the return to the default language (usually English); this deletes
# former language specifications.  The language name and its
# abbreviation with 2 characters is appended to the man page
# directories.  But these new arising directories are added to the man
# page, they do not replace it such as the system names did.  This is
# done by function manpath_add_lang_sys() in man_setup() as well.

# Now we have the basic set of directories for the search of man pages
# for given filespec arguments.  The real directories with the man
# page source files are gotten by appending `man<section>' to each
# directory, where section is a single character of the form
# `[1-9on]'.

# There you find files named according to the form
# <name>.<section>[<extension>][<compression>], where `[]' means
# optional this time.  <name> is the name of the man page; <section>
# is the single character from the last paragraphe; the optional
# <extension> consists of some letters denoting special aspects for
# the section; and the optional <compression> is something like `.gz',
# `.Z', or `.bz2', meaning that the file is compressed.

# If name, section. and extension are specified on the command-line
# the file of the form <name>.<section><extension> with or without
# <compression> are handled.  The first one found according to the
# directory set for the section is shown.

# If just name and section are specified on the command-line then
# first <name>.<section> with or without <compression> are searched.
# If no matching file was found, <name>.<section><extension> with or
# without <compression> are searched for all possible extensions.

# If only name is specified on the command-line then the section
# directories are searched by and by, starting with section `1', until
# a file is matched.

# The function man_is_man() determines all suitable man files for a
# command-line argument, while man_get() searches the single matching
# file for display.


########################################################################
# man_get (<man-name> [<section> [<extension>]])
#
# Write a man page to the temporary file.
#
# Globals in: $_TMP_MANSPEC, $_MAN_SEC_CHARS, $_MAN_EXT, $_MAN_ALL
#
# Arguments: 1, 2, or 3
#
# Variable prefix: mg
#
man_get()
{
  func_check man_get '>=' 1 "$@";
  if obj _TMP_MANSPEC is_empty
  then
    error 'man_get(): man_is_man() must be run first on '"$*".;
  fi;
  mg_name="$1";
  mg_sec="$2";
  if is_empty "$2"
  then
    mg_sec="${_MAN_SEC_CHARS}";	# take care it is not a single section
  fi;
  mg_ext="$3";
  if is_empty "$3"
  then
    mg_ext="${_MAN_EXT}";
  fi;
  if obj _TMP_MANSPEC is_not_equal "${_TMP_DIR}/,man:$1:${mg_sec}${mg_ext}"
  then
    error 'man_get(): $_TMP_MANSPEC does not suit to the arguments '"$*".;
  fi;
### man_get()

  if obj _MAN_ALL is_yes
  then
    list_from_file mg_list "${_TMP_MANSPEC}";
    eval set x ${mg_list};
    shift;
    mg_ok='no';
    mg_list='';
    for f
    do
      mg_f="$f";
      if list_has mg_list "${mg_f}"
      then
        continue;
      else
        list_append mg_list "${mg_f}";
      fi;
### man_get()
      if obj mg_f is_file
      then
        to_tmp "${mg_f}" && mg_ok='yes';
      fi;
    done;
    if obj mg_ok is_yes
    then
      register_title man:"${mg_name}";
    fi;
    eval ${_UNSET} mg_ext;
    eval ${_UNSET} mg_f;
    eval ${_UNSET} mg_list;
    eval ${_UNSET} mg_name;
    eval ${_UNSET} mg_sec;
    eval "${return_ok}";
  else				# $_MAN_ALL is not 'yes'
    if is_empty "$2"
    then			# no section from command line
      if obj _MAN_SEC_LIST is_empty
      then
        m="${_MAN_AUTO_SEC_LIST}"; # list of all sections
      else
        m="${_MAN_SEC_LIST}";	# from --sections
      fi;
### man_get()
      for s in $(eval set x $m; shift; echo1 "$@")
      do
        mg_s="$s";
        list_from_file mg_list "${_TMP_MANSPEC}";
        eval set x ${mg_list};
        shift;
        if obj mg_ext is_empty
        then
          for f
          do
            mg_f="$f";
            case "${mg_f}" in
*/man"${mg_s}"/"${mg_name}"."${mg_s}"|*/man"${mg_s}"/"${mg_name}"."${mg_s}".*)
              if obj mg_f is_file
              then
                to_tmp "${mg_f}" && register_title "${mg_name}(${mg_s})";
                eval ${_UNSET} mg_ext;
                eval ${_UNSET} mg_f;
                eval ${_UNSET} mg_list;
                eval ${_UNSET} mg_name;
                eval ${_UNSET} mg_s;
                eval ${_UNSET} mg_sec;
                eval "${return_ok}";
              fi;
              ;;
             esac;		# "$mg_f"
          done;			# for f
        fi;			# mg_ext is_empty
### man_get()
        for f
        do
          mg_f="$f";
          case "${mg_f}" in
          */man"${mg_s}"/"${mg_name}"."${mg_s}""${mg_ext}"*)
            if obj mg_f is_file
            then
              to_tmp "${mg_f}" && register_title "${mg_name}(${mg_s})";
              eval ${_UNSET} mg_ext;
              eval ${_UNSET} mg_f;
              eval ${_UNSET} mg_list;
              eval ${_UNSET} mg_name;
              eval ${_UNSET} mg_s;
              eval ${_UNSET} mg_sec;
              eval "${return_ok}";
            fi;
            ;;
           esac;		# "$mg_f"
        done;			# for f
      done;			# for s
    else			# $mg_sec is not empty, do with section
      list_from_file mg_list "${_TMP_MANSPEC}";
      eval set x ${mg_list};
      shift;
      if obj mg_ext is_empty
      then
        for f
        do
          mg_f="$f";
### man_get()
          case "${mg_f}" in
*/man"${mg_sec}"/"${mg_name}"."${mg_sec}"|\
*/man"${mg_sec}"/"${mg_name}"."${mg_sec}".*)
            if obj mg_f is_file
            then
              obj mg_f to_tmp && \
                register_title "${mg_name}(${mg_sec})";
              eval ${_UNSET} mg_ext;
              eval ${_UNSET} mg_f;
              eval ${_UNSET} mg_list;
              eval ${_UNSET} mg_name;
              eval ${_UNSET} mg_s;
              eval ${_UNSET} mg_sec;
              eval "${return_ok}";
            fi;
            ;;
          esac;
        done;			# for f
        for f
        do
          mg_f="$f";
### man_get()
          case "${mg_f}" in
*/man"${mg_sec}"/"${mg_name}"."${mg_sec}"*)
            if obj mg_f is_file
            then
              obj mg_f to_tmp && \
                register_title "${mg_name}(${mg_sec})";
              eval ${_UNSET} mg_ext;
              eval ${_UNSET} mg_f;
              eval ${_UNSET} mg_list;
              eval ${_UNSET} mg_name;
              eval ${_UNSET} mg_s;
              eval ${_UNSET} mg_sec;
              eval "${return_ok}";
            fi;
            ;;
          esac;
        done;			# for f
      else			# mg_ext is not empty
        for f
        do
          mg_f="$f";
### man_get()
          case "${mg_f}" in
*/man"${mg_sec}"/"${mg_name}"."${mg_sec}""${mg_ext}"|\
*/man"${mg_sec}"/"${mg_name}"."${mg_sec}""${mg_ext}".*)
            if obj mg_f is_file
            then
              obj mg_f to_tmp && \
                register_title "${mg_name}(${mg_sec}${mg_ext})";
              eval ${_UNSET} mg_ext;
              eval ${_UNSET} mg_f;
              eval ${_UNSET} mg_list;
              eval ${_UNSET} mg_name;
              eval ${_UNSET} mg_s;
              eval ${_UNSET} mg_sec;
              eval "${return_ok}";
            fi;
            ;;
          esac;
        done;			# for f
        for f
        do
          mg_f="$f";
### man_get()
          case "${mg_f}" in
          */man"${mg_sec}"/"${mg_name}"."${mg_sec}""${mg_ext}"*)
            if obj mg_f is_file
            then
              obj mg_f to_tmp && \
                register_title "${mg_name}(${mg_sec}${mg_ext})";
              eval ${_UNSET} mg_ext;
              eval ${_UNSET} mg_f;
              eval ${_UNSET} mg_list;
              eval ${_UNSET} mg_name;
              eval ${_UNSET} mg_s;
              eval ${_UNSET} mg_sec;
              eval "${return_ok}";
            fi;
            ;;
          esac;
        done;			# for f
      fi;
    fi;				# $mg_sec
  fi;				# $_MAN_ALL

  eval ${_UNSET} mg_ext;
  eval ${_UNSET} mg_f;
  eval ${_UNSET} mg_list;
  eval ${_UNSET} mg_name;
  eval ${_UNSET} mg_sec;
  eval ${_UNSET} mg_s;
  eval "${return_ok}";
} # man_get()


########################################################################
# man_is_man (<man-name> [<section> [<extension>]])
#
# Test whether <man-name> exists as man page.
#
# Globals: in: $_TMP_MAN, $_MAN_SEC_CHARS, $_TMP_DIR, $_MAN_EXT,
#              $_MAN_AUTO_SEC_CHARS
#         out: $_TMP_MANSPEC
#
# Arguments: 1, 2, or 3
#
# Variable prefix: mim
#
man_is_man()
{
  func_check man_is_man '>=' 1 "$@";
  if is_empty "$1"
  then
    _TMP_MANSPEC='';
    eval "${return_no}";
  fi;
  if obj _TMP_DIR is_empty
  then
    error 'man_is_man(): main_init() must be run first.';
  fi;
  if obj _MAN_IS_SETUP is_not_yes
  then
    error 'man_is_man(): man_setup() must be run first.';
  fi;
  mim_sec="$2";
  if is_empty "$2"
  then
    mim_sec="${_MAN_SEC_CHARS}";
  fi;
  if is_empty "$3"
  then
    mim_ext="${_MAN_EXT}";
  else
    mim_ext="$3";
  fi;
  _TMP_MANSPEC="${_TMP_DIR}/,man:$1:${mim_sec}${mim_ext}";
### man_is_man()
  if obj _TMP_MANSPEC is_not_file
  then
    if obj mim_sec is_empty
    then
      m="${_MAN_AUTO_SEC_CHARS}";
      eval grep "'/man$m/$1\.$m${mim_ext}'" \
           "${_TMP_MAN}" > "${_TMP_MANSPEC}";
    else
      eval grep "'/man${mim_sec}/$1\.${mim_sec}${mim_ext}'" \
           "${_TMP_MAN}" > "${_TMP_MANSPEC}";
    fi;
  fi;
  eval ${_UNSET} mim_ext;
  eval ${_UNSET} mim_sec;
  if obj _TMP_MANSPEC is_empty_file
  then
    rm_file_with_debug "${_TMP_MANSPEC}";
    eval "${return_no}";
  else
    eval "${return_yes}";
  fi;
} # man_is_man()


########################################################################
# man_setup ()
#
# Setup the variables $_MAN_* needed for man page searching.
#
# Globals:
#   in:     $_OPT_*, $_MANOPT_*, $LANG, $LC_MESSAGES, $LC_ALL,
#           $MANPATH, $MANSEC, $PAGER, $SYSTEM, $MANOPT.
#   out:    $_MAN_PATH, $_MAN_LANG, $_MAN_SYS, $_MAN_LANG, $_MAN_LANG2,
#           $_MAN_SEC, $_MAN_ALL, $_TMP_MAN
#   in/out: $_MAN_ENABLE
#
# The precedence for the variables related to `man' is that of GNU
# `man', i.e.
#
# $LANG; overridden by
# $LC_MESSAGES; overridden by
# $LC_ALL; this has the same precedence as
# $MANPATH, $MANSEC, $PAGER, $SYSTEM; overridden by
# $MANOPT; overridden by
# the groffer command line options.
#
# $MANROFFSEQ is ignored because grog determines the preprocessors.
#
# Variable prefix: ms
#
man_setup()
{
  func_check man_setup '=' 0 "$@";

  if obj _MAN_IS_SETUP is_yes
  then
    eval "${return_ok}";
  fi;
  _MAN_IS_SETUP='yes';

  if obj _MAN_ENABLE is_not_yes
  then
    eval "${return_ok}";
  fi;

  # determine basic path for man pages
  obj_from_output ms_path \
    get_first_essential "${_OPT_MANPATH}" "${_MANOPT_PATH}" "${MANPATH}";
  if obj ms_path is_empty && is_prog 'manpath'
  then
    obj_from_output ms_path manpath 2>${_NULL_DEV}; # not always available
  fi;
  if obj ms_path is_empty
  then
    manpath_set_from_path;
  else
    obj_from_output _MAN_PATH path_list "${ms_path}";
  fi;
  if obj _MAN_PATH is_empty
  then
    _MAN_ENABLE="no";
    echo2 "man_setup(): man path is empty";
    eval ${_UNSET} ms_path;
    eval "${return_ok}";
  fi;
  obj_from_output _MAN_PATH list_uniq _MAN_PATH;
### man_setup()

  if obj _MAN_ALL is_not_yes
  then
    if obj _OPT_ALL is_yes || obj _MANOPT_ALL is_yes
    then
      _MAN_ALL='yes';
    else
      _MAN_ALL='no';
    fi;
  fi;

  ms_sys="$(get_first_essential \
              "${_OPT_SYSTEMS}" "${_MANOPT_SYS}" "${SYSTEM}")";
  if obj ms_sys is_not_empty
  then
    obj_from_output _MAN_SYS list_from_split "${ms_sys}" ',';
  fi;

  obj_from_output ms_lang get_first_essential \
           "${_OPT_LANG}" "${LC_ALL}" "${LC_MESSAGES}" "${LANG}";
  case "${ms_lang}" in
    C|POSIX)
      _MAN_LANG="";
      _MAN_LANG2="";
      ;;
    ?)
      _MAN_LANG="${ms_lang}";
      _MAN_LANG2="";
      ;;
    ??)
      _MAN_LANG="${ms_lang}";
      _MAN_LANG2="${ms_lang}";
      ;;
### man_setup()
    *)
      _MAN_LANG="${ms_lang}";
      # get first two characters of $ms_lang
      _MAN_LANG2="$(echo1 "${ms_lang}" | sed 's/^\(..\).*$/\1/')";
      exit_test;
      ;;
  esac;
  # from now on, use only $_MAN_LANG*, forget about $_OPT_LANG, $LC_*.

  manpath_add_lang_sys;
  obj_from_output _MAN_PATH list_uniq _MAN_PATH;

  obj_from_output _MAN_SEC get_first_essential \
    "${_OPT_SECTIONS}" "${_MANOPT_SEC}" "${MANSEC}";
  _MAN_SEC_LIST="";
  _MAN_SEC_CHARS="";
  case "${_MAN_SEC}" in
  *:*)
    eval set x "$(list_from_split "${_MAN_SEC}" :)";
    shift;
    for s
    do
      if list_has _MAN_AUTO_SEC_LIST "$s"
      then
        list_append _MAN_SEC_LIST "$s";
        _MAN_SEC_CHARS="${_MAN_SEC_CHARS}$s";
      fi;
    done
    if obj _MAN_SEC_CHARS is_not_empty
    then
      _MAN_SEC_CHARS="[${_MAN_SEC_CHARS}]";
    fi;
    ;;
  *)
    if list_has _MAN_AUTO_SEC_LIST "${_MAN_SEC}"
    then
      list_append _MAN_SEC_LIST "${_MAN_SEC}";
      _MAN_SEC_CHARS="[${_MAN_SEC}]";
    fi;
    ;;
  esac;

### man_setup()
  obj_from_output _MAN_EXT get_first_essential \
    "${_OPT_EXTENSION}" "${_MANOPT_EXTENSION}" "${EXTENSION}";

  _TMP_MAN="$(tmp_create man)";

  eval set x "${_MAN_PATH}";
  shift;
  if is_not_equal "$#" 0
  then
    for i
    do
      for j in "$i"/man*
      do
        if obj j is_dir
	then
          find "$j" >>"${_TMP_MAN}";
        fi;
      done
    done;
  fi;

  eval ${_UNSET} ms_lang;
  eval ${_UNSET} ms_list;
  eval ${_UNSET} ms_path;
  eval ${_UNSET} ms_sys;
  eval "${return_ok}";
} # man_setup()


########################################################################
landmark '8: manpath_*()';
########################################################################

########################################################################
# manpath_add_lang_sys ()
#
# Add language and operating system specific directories to man path.
#
# Arguments : 0
# Output    : none
# Globals:
#   in:     $_MAN_SYS: a list of names of operating systems.
#           $_MAN_LANG and $_MAN_LANG2: each a single name
#   in/out: $_MAN_PATH: list of directories which shall have the `man?'
#             subdirectories.
#
# Variable prefix: mals
#
manpath_add_lang_sys()
{
  func_check manpath_add_lang_sys '=' 0 "$@";
  if obj _MAN_PATH is_empty
  then
    eval "${return_ok}";
  fi;
  if obj _MAN_SYS is_empty
  then
    mals_mp="${_MAN_PATH}";
  else
    mals_mp='';
    eval set x "${_MAN_SYS}";
    shift;
    for s
    do
      _manpath_add_sys "$s";
    done;
  fi;

  if obj mals_mp is_not_empty
  then
    mals_lang_path='';
    if is_equal "$_MAN_LANG" "$_MAN_LANG2"
    then
      mals_man_lang2='';
    else
      mals_man_lang2="${_MAN_LANG2}";
    fi;
    for i in "${_MAN_LANG}" "${mals_man_lang2}"
    do
      if obj i is_empty
      then
        continue;
      fi;
### manpath_add_lang_sys()
      mals_lang="$i";
      eval set x "${mals_mp}";
      shift;
      for p
      do
        obj_from_output mals_dir dir_name_append "${p}" "${mals_lang}";
        if obj mals_dir is_dir
        then
          list_append mals_lang_path "${mals_dir}";
        fi;
      done;
    done;
    obj_from_output mals_mp lists_combine mals_lang_path mals_mp;
  fi;

  _MAN_PATH="${mals_mp}";
  eval ${_UNSET} mals_dir;
  eval ${_UNSET} mals_lang;
  eval ${_UNSET} mals_lang_path;
  eval ${_UNSET} mals_man_lang2;
  eval ${_UNSET} mals_mp;
  eval "${return_ok}";
} # manpath_add_lang_sys()


# _manpath_add_sys (<system>)
#
# Append the existing subdirectories <system> of man path directories to
# the list $mals_mp.
#
# Local function to manpath_add_lang_sys().
#
# Argument: 1, a operating system name (for appending to a man path
#              directory)
#
# Globals in:     $_MAN_PATH
# Globals in/out: $mals_mp
#
# Variable prefix: _mas
#
_manpath_add_sys()
{
  func_check _manpath_add_sys '=' 1 "$@";
  case "$1" in
  '')
    :;
    ;;
  man)
    obj_from_output mals_mp lists_combine mals_mp _MAN_PATH;
    ;;
  *)
    _mas_sys="$1";
    eval set x "${_MAN_PATH}";
    shift;
    for p
    do
      obj_from_output _mas_dir dir_name_append "${p}" "${_mas_sys}";
      if obj _mas_dir is_dir
      then
        list_append mals_mp "${_mas_dir}";
      fi;
    done;
    ;;
  esac;
  eval ${_UNSET} _mas_dir;
  eval ${_UNSET} _mas_sys;
  eval "${return_ok}";
} # _manpath_add_sys() of manpath_add_lang_sys()


########################################################################
# manpath_set_from_path ()
#
# Determine basic search path for man pages from $PATH.
#
# Return:    `0' if a valid man path was retrieved.
# Output:    none
# Globals:
#   in:  $PATH
#   out: $_MAN_PATH
#
# Variable prefix: msfp
#
manpath_set_from_path()
{
  func_check manpath_set_from_path '=' 0 "$@";

  msfp_manpath='';

  # get a basic man path from $PATH
  if obj PATH is_not_empty
  then
    # delete the final `/bin' part
    p="$(echo1 "${PATH}" | sed 's|//*bin/*:|:|g')";
    obj_from_output msfp_list path_list "$p";
    # append some default directories
    for b in /usr/local /usr/local /usr /usr \
           /usr/X11R6 /usr/openwin \
           /opt /opt/gnome /opt/kde
    do
      msfp_base="$b";
      if list_has_not msfp_list "${msfp_base}" && obj msfp_base is_dir
      then
        list_append msfp_list "${msfp_base}";
      fi;
    done;
    eval set x "${msfp_list}";
    shift;
    for d
    do
      # including empty for former `/bin'.
      msfp_base="$d";
      for e in /share/man /share/MAN /man /MAN
      do
        msfp_mandir="${msfp_base}$e";
        if obj msfp_mandir is_dir
        then
          list_append msfp_manpath "${msfp_mandir}";
        fi;
      done;
    done;
  fi;

  _MAN_PATH="${msfp_manpath}";
  eval ${_UNSET} msfp_base;
  eval ${_UNSET} msfp_list;
  eval ${_UNSET} msfp_mandir;
  eval ${_UNSET} msfp_manpath;
  eval "${return_ok}";
} # manpath_set_from_path()


########################################################################
landmark '9: obj_*()';
########################################################################

########################################################################
# obj (<object> <call_name> <arg>...)
#
# This works like a method (object function) call for an object.
# Run "<call_name> $<object> <arg> ...".
#
# The first argument represents an object name whose data is given as
# first argument to <call_name>().
#
# Argument: >=2
#           <object>: variable name
#           <call_name>: a program or function name
#
# Variable prefix: o
#
obj()
{
  func_check obj '>=' 2 "$@";
  eval o_arg1='"${'$1'}"';
  if is_empty "$2"
  then
    error "obj(): function name is empty."
  else
    o_func="$2";
  fi;
  shift;
  shift;
  eval "${o_func}"' "${o_arg1}" "$@"';
  n="$?";
  eval ${_UNSET} o_arg1;
  eval ${_UNSET} o_func;
  eval "${return_var} $n";
} # obj()


########################################################################
# obj_data (<object>)
#
# Print the data of <object>, i.e. the content of $<object>.
# For possible later extensions.
#
# Arguments: 1
#            <object>: a variable name
# Output:    the data of <object>
#
# Variable prefix: od
#
obj_data()
{
  func_check obj_data '=' 1 "$@";
  if is_empty "$1"
  then
    error "obj_data(): object name is empty."
  fi;
  eval od_res='"${'"$1"'}"';
  obj od_res echo1;
  eval ${_UNSET} od_res;
  eval "${return_ok}";
} # obj_data()


########################################################################
# obj_from_output (<object> <call_name> <arg>...)
#
# Run '$<object>="$(<call_name> <arg>...)"' to set the result of a
# function call to a global variable.  Variables are not stored.
#
# Arguments: >=2
#            <object>: a variable name
#            <call_name>: the name of a function or program
#            <arg>: optional argument to <call_name>
# Output:    none
#
# Variable prefix: ofo
#
obj_from_output()
{
  func_check obj_from_output '>=' 2 "$@";
  if is_empty "$1"
  then
    error "obj_from_output(): variable name is empty.";
  fi;
  if is_empty "$2"
  then
    error "obj_from_output(): function name is empty."
  fi;
  ofo_result_name="$1";
  shift;
  ofo_return=0;
  if is_equal "$#" 0
  then
    eval "${ofo_result_name}"'=""';
  else
    ofo_list='';
    for i
    do
      list_append ofo_list "$i";
    done;
    eval "${ofo_result_name}"'="$('"${ofo_list}"')"';
    ofo_return="$?";
    exit_test;
  fi;
  r="${ofo_return}";
  eval ${_UNSET} ofo_list;
  eval ${_UNSET} ofo_return;
  eval ${_UNSET} ofo_result_name;
  eval "${return_var} $r";
} # obj_from_output()


########################################################################
# obj_set (<object> <data>)
#
# Set the data of <object>, i.e. call "$<object>=<data>".
#
# Arguments: 2
#            <object>: a variable name
#            <data>: a string
# Output::   none
#
obj_set()
{
  func_check obj_set '=' 2 "$@";
  if is_empty "$1"
  then
    error "obj_set(): object name is empty."
  fi;
  eval "$1"='"$2"';
  eval "${return_ok}";
} # obj_set()


########################################################################
# path_chop (<path>)
#
# Remove unnecessary colons from path.
#
# Argument: 1, a colon separated path.
# Output:   path without leading, double, or trailing colons.
#
path_chop()
{
  func_check path_chop = 1 "$@";

  # replace multiple colons by a single colon `:'
  # remove leading and trailing colons
  echo1 "$1" | sed '
s/^:*//
s/:::*/:/g
s/:*$//
';
  eval "${return_ok}";
} # path_chop()


########################################################################
# path_clean (<path>)
#
# Remove non-existing directories from a colon-separated list.
#
# Argument: 1, a colon separated path.
# Output:   colon-separated list of existing directories.
#
# Variable prefix: pc
#
path_clean()
{
  func_check path_clean = 1 "$@";
  if is_not_equal "$#" 1
  then
    error 'path_clean() needs 1 argument.';
  fi;
  pc_arg="$1";
  eval set x "$(path_list "${pc_arg}")";
  exit_test;
  shift;
  pc_res="";
  for i
  do
    pc_i="$i";
    if obj pc_i is_not_empty \
       && obj pc_res path_not_contains "${pc_i}" \
       && obj pc_i is_dir
    then
      case "${pc_i}" in
      ?*/)
        pc_res="${pc_res}:$(dir_name_chop "${pc_i}")";
        exit_test;
        ;;
      *)
        pc_res="${pc_res}:${pc_i}";
        ;;
      esac;
    fi;
  done;
  path_chop "${pc_res}";
  eval ${_UNSET} pc_arg;
  eval ${_UNSET} pc_i;
  eval ${_UNSET} pc_res;
  eval "${return_ok}";
} # path_clean()


########################################################################
# path_contains (<path> <dir>)
#
# Test whether <dir> is contained in <path>, a list separated by `:'.
#
# Arguments : 2
# Return    : `0' if arg2 is substring of arg1, `1' otherwise.
#
path_contains()
{
  func_check path_contains = 2 "$@";
  case ":$1:" in
    *:${2}:*)
      eval "${return_yes}";
      ;;
    *)
      eval "${return_no}";
      ;;
  esac;
  eval "${return_ok}";
} # path_contains()


########################################################################
# path_not_contains (<path> <dir>)
#
# Test whether <dir> is not contained in colon separated <path>.
#
# Arguments : 2
#
path_not_contains()
{
  func_check path_not_contains = 2 "$@";
  if path_contains "$1" "$2"
  then
    eval "${return_no}";
  else
    eval "${return_yes}";
  fi;
  eval "${return_ok}";
} # path_not_contains()


########################################################################
# path_list (<path>)
#
# From a `:' separated path generate a list with unique elements.
#
# Arguments: 1: a colon-separated path
# Output:    the resulting list, process it with `eval set'
#
# Variable prefix: pl
#
path_list()
{
  func_check path_list = 1 "$@";
  eval set x "$(list_from_split "$1" '\:')";
  shift;
  pl_list='';
  for e
  do
    pl_elt="$e";
    if list_has pl_list "${pl_elt}"
    then
      continue;
    else
      list_append pl_list "${pl_elt}";
    fi;
  done;
  obj pl_list echo1;
  eval ${_UNSET} pl_elt;
  eval ${_UNSET} pl_list;
  eval "${return_ok}";
} # path_list()


########################################################################
landmark '10: register_*()';
########################################################################

########################################################################
# register_file (<filename>)
#
# Write a found file and register the title element.
#
# Arguments: 1: a file name
# Output: none
#
register_file()
{
  func_check register_file = 1 "$@";
  if is_empty "$1"
  then
    error 'register_file(): file name is empty';
  fi;
  if is_equal "$1" '-'
  then
    to_tmp "${_TMP_STDIN}" && register_title 'stdin';
  else
    to_tmp "$1" && register_title "$1";
    exit_test;
  fi;
  eval "${return_ok}";
} # register_file()


########################################################################
# register_title (<filespec>)
#
# Create title element from <filespec> and append to $_REG_TITLE_LIST.
# Basename is created.
#
# Globals: $_REG_TITLE_LIST (rw)
#
# Variable prefix: rt
#
register_title()
{
  func_check register_title '=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_ok}";
  fi;

  if obj _DEBUG_PRINT_FILENAMES is_yes
  then
    if is_equal "$1" 'stdin'
    then
      echo2 "file: standard input";
    else
      if obj _FILESPEC_IS_MAN is_yes
      then
        echo2 "file title: $1";
      else
        echo2 "file: $1";
      fi;
    fi;
  fi;

  case "${_REG_TITLE_LIST}" in
  *\ *\ *\ *)
    eval "${return_ok}";
    ;;
  esac;

  # remove directory part
  obj_from_output rt_title base_name "$1";
  # replace space characters by `_'
  rt_title="$(echo1 "${rt_title}" | sed 's/[ 	]/_/g')";
  # remove extension `.bz2'
  rt_title="$(echo1 "${rt_title}" | sed 's/\.bz2$//')";
  # remove extension `.gz'
  rt_title="$(echo1 "${rt_title}" | sed 's/\.gz$//')";
  # remove extension `.Z'
  rt_title="$(echo1 "${rt_title}" | sed 's/\.Z$//')";

  if obj rt_title is_empty
  then
    eval ${_UNSET} rt_title;
    eval "${return_ok}";
  fi;
  list_append _REG_TITLE_LIST "${rt_title}";
  eval ${_UNSET} rt_title;
  eval "${return_ok}";
} # register_title()


########################################################################
# reset ()
#
# Reset the variables that can be affected by options to their default.
#
#
# Defined in section `Preset' after the rudimentary shell tests.


########################################################################
# rm_file (<file_name>)
#
# Remove file.
#
rm_file()
{
  func_check rm_file '=' 1 "$@";
  if is_file "$1"
  then
    rm -f "$1" >${_NULL_DEV} 2>&1;
  fi;
  if is_existing "$1"
  then
    eval "${return_bad}";
  else
    eval "${return_good}";
  fi;
} # rm_file()


########################################################################
# rm_file_with_debug (<file_name>)
#
# Remove file if $_DEBUG_KEEP_FILES allows it.
#
# Globals: $_DEBUG_KEEP_FILES
#
rm_file_with_debug()
{
  func_check rm_file_with_debug '=' 1 "$@";
  if obj _DEBUG_KEEP_FILES is_not_yes
  then
    if is_file "$1"
    then
      rm -f "$1" >${_NULL_DEV} 2>&1;
    fi;
  fi;
  if is_existing "$1"
  then
    eval "${return_bad}";
  else
    eval "${return_good}";
  fi;
} # rm_file_with_debug()


########################################################################
# rm_tree (<dir_name>)
#
# Remove a file or a complete directory tree.
#
# Globals: $_DEBUG_KEEP_FILES
#
rm_tree()
{
  func_check rm_tree '=' 1 "$@";
  if is_existing "$1"
  then
    rm -f -r "$1" >${_NULL_DEV} 2>&1;
  fi;
  if is_existing "$1"
  then
    eval "${return_bad}";
  else
    eval "${return_good}";
  fi;
} # rm_tree()


########################################################################
# save_stdin ()
#
# Store standard input to temporary file (with decompression).
#
# Variable prefix: ss
#
if obj _HAS_COMPRESSION is_yes
then
  save_stdin()
  {
    func_check save_stdin '=' 0 "$@";
    ss_f="${_TMP_DIR}"/INPUT;
    cat >"${ss_f}";
    cat_z "${ss_f}" >"${_TMP_STDIN}";
    rm_file "${ss_f}";
    eval ${_UNSET} ss_f;
    eval "${return_ok}";
  } # save_stdin()
else				# no compression
  save_stdin()
  {
    func_check save_stdin '=' 0 "$@";
    cat >"${_TMP_STDIN}";
    eval "${return_ok}";
  } # save_stdin()
fi;


########################################################################
# special_filespec ()
#
# Handle special modes like whatis and apropos.  Run their filespec
# functions if suitable.
#
# Globals:  in: $_OPT_APROPOS, $_OPT_WHATIS, $_SPECIAL_SETUP
#          out: $_SPECIAL_FILESPEC (internal)
#
special_filespec()
{
  func_check special_filespec '=' 0 "$@";
  if obj _OPT_APROPOS is_not_yes && obj _OPT_WHATIS is_not_yes
  then
    eval "${return_bad}";
  fi;
  if obj _OPT_APROPOS is_yes && obj _OPT_WHATIS is_yes
  then
    error \
      'special_filespec(): $_OPT_APROPOS and $_OPT_WHATIS are both "yes"';
  fi;
  if obj _SPECIAL_SETUP is_not_yes
  then
    error 'special_filespec(): setup for apropos or whatis must be run first.';
  fi;
  if apropos_filespec || whatis_filespec;
  then
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # special_filespec()


########################################################################
# special_setup ()
#
# Handle special modes like whatis and apropos.  Run their setup
# functions if suitable.
#
special_setup()
{
  func_check special_setup '=' 0 "$@";
  if obj _OPT_APROPOS is_yes && obj _OPT_WHATIS is_yes
  then
    error \
      'special_setup(): $_OPT_APROPOS and $_OPT_WHATIS are both "yes"';
  fi;
  if apropos_setup || whatis_setup
  then
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # special_setup()


########################################################################
landmark '11: stack_*()';
########################################################################

########################################################################
# string_contains (<string> <part>)
#
# Test whether <part> is contained in <string>.
#
# Arguments : 2 text arguments.
# Return    : `0' if arg2 is substring of arg1, `1' otherwise.
#
string_contains()
{
  func_check string_contains '=' 2 "$@";
  case "$1" in
    *${2}*)
      eval "${return_yes}";
      ;;
    *)
      eval "${return_no}";
      ;;
  esac;
  eval "${return_ok}";
} # string_contains()


########################################################################
# string_not_contains (<string> <part>)
#
# Test whether <part> is not substring of <string>.
#
# Arguments : 2 text arguments.
# Return    : `0' if arg2 is substring of arg1, `1' otherwise.
#
string_not_contains()
{
  func_check string_not_contains '=' 2 "$@";
  if string_contains "$1" "$2"
  then
    eval "${return_no}";
  else
    eval "${return_yes}";
  fi;
  eval "${return_ok}";
} # string_not_contains()


########################################################################
landmark '12: tmp_*()';
########################################################################

########################################################################
# tmp_cat ()
#
# Output the temporary cat file (the concatenation of all input).
#
tmp_cat()
{
  func_check tmp_cat '=' 0 "$@";
  cat "${_TMP_CAT}";
  eval "${return_var}" "$?";
} # tmp_cat()


########################################################################
# tmp_create (<suffix>?)
#
# Create temporary file.  The generated name is `,' followed by
# <suffix>.
#
# Argument: 0 or 1
#
# Globals: $_TMP_DIR
#
# Output : name of created file
#
# Variable prefix: tc
#
tmp_create()
{
  func_check tmp_create '<=' 1 "$@";
  if obj _TMP_DIR is_empty || obj _TMP_DIR is_not_dir
  then
    error 'tmp_create(): there is no temporary directory.';
  else
    # the output file does not have `,' as first character, so these are
    # different names from the output file.
    tc_tmp="${_TMP_DIR}/,$1";
    obj tc_tmp rm_file;
    : >"${tc_tmp}"
    obj tc_tmp echo1;
  fi;
  eval ${_UNSET} tc_tmp;
  eval "${return_ok}";
} # tmp_create()


########################################################################
# to_tmp (<filename>)
#
# Print file (decompressed) to the temporary cat file.
#
# Variable prefix: tt
#
to_tmp()
{
  func_check to_tmp '=' 1 "$@";
  if obj _TMP_CAT is_empty
  then
    error 'to_tmp(): $_TMP_CAT is not yet set';
  fi;
  tt_1="$1";
  tt_so_nr=0;			# number for temporary `,so,*,*'
  if is_file "${tt_1}"
  then
    tt_dir="$(dir_name "${tt_1}")";
    if obj _OPT_WHATIS is_yes
    then
      whatis_filename "${tt_1}" >>"${_TMP_CAT}";
    else
      _FILE_NR="$(expr ${_FILE_NR} + 1)";
      tt_file="${_TMP_DIR}/,file${_FILE_NR}";
      if obj _FILESPEC_IS_MAN is_yes
      then
        if obj _DEBUG_PRINT_FILENAMES is_yes
        then
          echo2 "file: ${tt_1}";
        fi;
        tt_tmp="${_TMP_DIR}/,tmp";
        cat_z "${tt_1}" >"${tt_file}";
        grep '^\.[ 	]*so[ 	]' "${tt_file}" |
	  sed 's/^\.[ 	]*so[ 	]*//' >"${tt_tmp}";
        list_from_file tt_list "${tt_tmp}";
        eval set x ${tt_list};
        shift;
        for i
        do
          tt_i="$i";
          tt_so_nr="$(expr ${tt_so_nr} + 1)";
          tt_sofile="${_TMP_DIR}/,so${_FILE_NR}_${tt_so_nr}";
          tt_sofiles="${tt_sofiles} ${tt_sofile}";
          _do_man_so "${tt_i}";
        done;
        rm_file "${tt_tmp}";
        mv "${tt_file}" "${tt_tmp}";
        cat "${tt_tmp}" | soelim -I "${tt_dir}" ${_SOELIM_R} >"${tt_file}";
        for f in ${tt_sofiles}
        do
          rm_file_with_debug $f;
        done;
        rm_file "${tt_tmp}";
      else			# $_FILESPEC_IS_MAN ist not yes
        cat_z "${tt_1}" | soelim -I "${tt_dir}" ${_SOELIM_R} >"${tt_file}";
      fi;
### to_tmp()
      obj_from_output tt_grog grog "${tt_file}";
      if is_not_equal "$?" 0
      then
        exit "${_ERROR}";
      fi;
      echo2 "grog output: ${tt_grog}";
      case " ${tt_grog} " in
      *\ -m*)
        eval set x "$(echo1 " ${tt_grog} " | sed '
s/'"${_TAB}"'/ /g
s/  */ /g
s/ -m / -m/g
s/ -mm\([^ ]\)/ -m\1/g
')";
        shift;
        for i
        do
          tt_i="$i";
          case "${tt_i}" in
          -m*)
            if list_has _MACRO_PACKAGES "${tt_i}"
            then
              case "${_MACRO_PKG}" in
              '')
                _MACRO_PKG="${tt_i}";
                ;;
              ${tt_i})
                :;
                ;;
              -m*)
                echo2 "Ignore ${tt_1} because it needs ${tt_i} instead "\
"of ${_MACRO_PKG}."
                rm_file_with_debug "${tt_file}";
                eval ${_UNSET} tt_1;
                eval ${_UNSET} tt_dir;
                eval ${_UNSET} tt_file;
                eval ${_UNSET} tt_grog;
                eval ${_UNSET} tt_i;
                eval ${_UNSET} tt_so_nr;
                eval ${_UNSET} tt_sofile;
                eval ${_UNSET} tt_sofiles;
                eval ${_UNSET} tt_sofound;
                eval ${_UNSET} tt_list;
                eval ${_UNSET} tt_tmp;
                eval "${return_bad}";
                ;;
### to_tmp()
              *)
                error \
'to_tmp(): $_MACRO_PKG does not start with -m: '"${_MACRO_PKG}";
                ;;
              esac;
            fi;
            ;;
          esac;
        done;
        ;;
      esac;
      cat "${tt_file}" >>"${_TMP_CAT}";
      rm_file_with_debug "${tt_file}";
    fi;
  else
    error "to_tmp(): could not read file \`${tt_1}'.";
  fi;
  eval ${_UNSET} tt_1;
  eval ${_UNSET} tt_dir;
  eval ${_UNSET} tt_file;
  eval ${_UNSET} tt_grog;
  eval ${_UNSET} tt_i;
  eval ${_UNSET} tt_so_nr;
  eval ${_UNSET} tt_sofile;
  eval ${_UNSET} tt_sofiles;
  eval ${_UNSET} tt_sofound;
  eval ${_UNSET} tt_list;
  eval ${_UNSET} tt_tmp;
  eval "${return_ok}";
} # to_tmp()


#############
# _do_man_so (<so_arg>)
#
# Handle single .so file name for man pages.
#
# Local function to to_tmp().
#
# Globals from to_tmp(): $tt_tmp, $tt_sofile, $tt_file
# Globals: $_TMP_MAN
#
# Variable prefix: dms
#
_do_man_so() {
  func_check _do_man_so '=' 1 "$@";
  _dms_so="$1";			# evt. with `\ '
  _dms_soname="$(echo $1 | sed 's/\\[ 	]/ /g')"; # without `\ '
  case "${_dms_soname}" in
  /*)				# absolute path
    if test -f "${_dms_soname}"
    then
      eval "${return_ok}";
    fi;
    if test -f "${_dms_soname}"'.gz'
    then
      _dms_sofound="${_dms_soname}"'.gz';
    elif test -f "${_dms_soname}"'.Z'
    then
      _dms_sofound="${_dms_soname}"'.Z';
    elif test -f "${_dms_soname}"'.bz2'
    then
      _dms_sofound="${_dms_soname}"'.bz2';
    else
      eval ${_UNSET} _dms_so;
      eval ${_UNSET} _dms_soname;
      eval "${return_ok}";
    fi;
    ;;
### _do_man_so() of to_tmp()
  *)				# relative to man path
    eval grep "'/${_dms_soname}\$'" "${_TMP_MAN}" >"${tt_tmp}";
    if is_empty_file "${tt_tmp}"
    then
      eval grep "'/${_dms_soname}.gz\$'" "${_TMP_MAN}" >"${tt_tmp}";
      if is_empty_file "${tt_tmp}"
      then
        eval grep "'/${_dms_soname}.Z\$'" "${_TMP_MAN}" >"${tt_tmp}";
        if is_empty_file "${tt_tmp}"
        then
          eval grep "'/${_dms_soname}.bz2\$'" "${_TMP_MAN}" >"${tt_tmp}";
        fi;
      fi;
    fi;
    if is_empty_file "${tt_tmp}"
    then
      eval "${return_ok}";
    fi;
    _dms_done='no';
    list_from_file _dms_list "${tt_tmp}";
    eval set x ${_dms_list};
    shift;
    for i
    do
      _dms_sofound="$i";
      if obj _dms_sofound is_empty
      then
        continue;
      fi;
      _dms_done='yes';
      break;
    done;
### _do_man_so() of to_tmp()
    if obj _dms_done is_not_yes
    then
      eval ${_UNSET} _dms_done;
      eval ${_UNSET} _dms_sofound;
      eval "${return_ok}";
    fi;
    ;;
  esac;
  if obj _DEBUG_PRINT_FILENAMES is_yes
  then
    echo2 "file from .so: ${_dms_so}";
  fi;
  cat_z "${_dms_sofound}" >"${tt_sofile}";
  _dms_esc="$(echo ${_dms_so} | sed 's/\\/\\\\/g')";
  cat "${tt_file}" | eval sed \
"'s#^\\.[ 	]*so[ 	]*\(${_dms_so}\|${_dms_esc}\|${_dms_soname}\)[ 	]*\$'"\
"'#.so ${tt_sofile}#'" \
    >"${tt_tmp}";
  rm_file "${tt_file}";
  mv "${tt_tmp}" "${tt_file}";
  eval ${_UNSET} _dms_done;
  eval ${_UNSET} _dms_esc;
  eval ${_UNSET} _dms_so;
  eval ${_UNSET} _dms_sofound;
  eval ${_UNSET} _dms_soname;
  eval "${return_ok}";
} # _do_man_so() of to_tmp()


########################################################################
# to_tmp_line (<text>...)
#
# Print single line with <text> to the temporary cat file.
#
to_tmp_line()
{
  func_check to_tmp_line '>=' 1 "$@";
  if obj _TMP_CAT is_empty
  then
    error 'to_tmp_line(): $_TMP_CAT is not yet set';
  fi;
  echo1 "$*" >>"${_TMP_CAT}";
  eval "${return_ok}";
} # to_tmp_line()


########################################################################
# trap_set
#
# Call function on signal 0.
#
trap_set()
{
  func_check trap_set '=' 0 "$@";
  trap 'clean_up' 0 2>${_NULL_DEV} || :;
  eval "${return_ok}";
} # trap_set()


########################################################################
# trap_unset ()
#
# Disable trap on signal 0.
#
trap_unset()
{
  func_check trap_unset '=' 0 "$@";
  trap '' 0 2>${_NULL_DEV} || :;
  eval "${return_ok}";
} # trap_unset()


########################################################################
# usage ()
#
# Print usage information to standard output; for groffer option --help.
#
usage()
{
  func_check usage = 0 "$@";
  echo;
  version;
  cat <<EOF

Usage: groffer [option]... [filespec]...

Display roff files, standard input, and/or Unix manual pages with a X
Window viewer or in several text modes.  All input is decompressed
on-the-fly with all formats that gzip can handle.

"filespec" is one of
  "filename"       name of a readable file
  "-"              for standard input
  "man:name(n)"    man page "name" in section "n"
  "man:name.n"     man page "name" in section "n"
  "man:name"       man page "name" in first section found
  "name(n)"        man page "name" in section "n"
  "name.n"         man page "name" in section "n"
  "n name"         man page "name" in section "n"
  "name"           man page "name" in first section found
where `section' is a single character out of [1-9on], optionally followed
by some more letters that are called the `extension'.

-h --help         print this usage message.
-T --device=name  pass to groff using output device "name".
-v --version      print version information.
-V                display the groff execution pipe instead of formatting.
-X                display with "gxditview" using groff -X.
-Z --ditroff --intermediate-output
                  generate groff intermediate output without
                  post-processing and viewing, like groff -Z.
All other short options are interpreted as "groff" formatting options.

The most important groffer long options are

--apropos=name    start man's "apropos" program for "name".
--apropos-data=name
                  "apropos" for "name" in man's data sections 4, 5, 7.
--apropos-devel=name
                  "apropos" for "name" in development sections 2, 3, 9.
--apropos-progs=name
                  "apropos" for "name" in man's program sections 1, 6, 8.
--auto            choose mode automatically from the default mode list.
--default         reset all options to the default value.
--default-modes=mode1,mode2,...
                  set sequence of automatically tried modes.
--dvi             display in a viewer for TeX device independent format.
--dvi-viewer=prog choose the viewer program for dvi mode.
--groff           process like groff, disable viewing features.
--help            display this helping output.
--html            display in a web browser.
--html-viewer=program
                  choose a web browser for html mode.
--man             check file parameters first whether they are man pages.
--mode=auto|dvi|groff|html|pdf|ps|source|text|tty|www|x|X
                  choose display mode.
--no-man          disable man-page facility.
--no-special      disable --all, --apropos*, and --whatis
--pager=program   preset the paging program for tty mode.
--pdf             display in a PDF viewer.
--pdf-viewer=prog choose the viewer program for pdf mode.
--ps              display in a Postscript viewer.
--ps-viewer=prog  choose the viewer program for ps mode.
--shell=program   specify a shell under which to run groffer2.sh.
--source          output as roff source.
--text            output in a text device without a pager.
--to-stdout       output the content of the mode file without display.
--tty             display with a pager on text terminal even when in X.
--tty-viewer=prog select a pager for tty mode; same as --pager.
--whatis          display the file name and description of man pages
--www             same as --html.
--www-viewer=prog same as --html-viewer
--x --X           display with "gxditview" using an X* device.
--x-viewer=prog   choose viewer program for x mode (X mode).
--X-viewer=prog   same as "--xviewer".

The usual X Windows toolkit options transformed into GNU long options:
--background=color, --bd=size, --bg=color, --bordercolor=color,
--borderwidth=size, --bw=size, --display=Xdisplay, --fg=color,
--fn=font, --font=font, --foreground=color, --geometry=geom, --iconic,
--resolution=dpi, --rv, --title=text, --xrm=resource

Long options of GNU "man":
--all, --ascii, --ditroff, --extension=suffix, --locale=language,
--local-file=name, --location, --manpath=dir1:dir2:...,
--sections=s1:s2:..., --systems=s1,s2,..., --where, ...

Development options that are not useful for normal usage:
--debug, --debug-all, --debug-filenames, --debug-func,
--debug-not-func, --debug-grog, --debug-keep, --debug-lm,
--debug-params, --debug-shell, --debug-stacks, --debug-tmpdir,
--debug-user, --do-nothing, --print=text, --shell=prog

EOF

  eval "${return_ok}";
} # usage()


########################################################################
# version ()
#
# Print version information to standard output.
# For groffer option --version.
#
version()
{
  func_check version = 0 "$@";
  y="$(echo "${_LAST_UPDATE}" | sed 's/^.* //')";
  cat <<EOF
groffer ${_PROGRAM_VERSION} of ${_LAST_UPDATE} (shell version)
is part of groff version ${_GROFF_VERSION}.
Copyright (C) $y Free Software Foundation, Inc.
GNU groff and groffer come with ABSOLUTELY NO WARRANTY.
You may redistribute copies of groff and its subprograms
under the terms of the GNU General Public License.
EOF
  eval "${return_ok}";
} # version()


########################################################################
# warning (<string>)
#
# Print warning to stderr.
#
warning()
{
  echo2 "warning: $*";
} # warning()


########################################################################
# whatis_filename (<filename>)
#
# Interpret <filename> as a man page and display its `whatis'
# information as a fragment written in the groff language.
#
# Globals:  in: $_OPT_WHATIS, $_SPECIAL_SETUP, $_SPECIAL_FILESPEC,
#               $_FILESPEC_ARG
#
# Variable prefix: wf
#
whatis_filename()
{
  func_check whatis_filename = 1 "$@";
  if obj _OPT_WHATIS is_not_yes
  then
    error 'whatis_filename(): $_OPT_WHATIS is not yes.';
  fi;
  if obj _SPECIAL_SETUP is_not_yes
  then
    error \
      'whatis_filename(): setup for whatis whatis_setup() must be run first.';
  fi;
  if obj _SPECIAL_FILESPEC is_not_yes
  then
    error 'whatis_filename(): whatis_filespec() must be run first.';
  fi;
  wf_arg="$1";
  if obj wf_arg is_not_file
  then
    error "whatis_filename(): argument is not a readable file."
  fi;
  wf_dot='^\.'"${_SPACE_SED}"'*';
### whatis_filename()
  if obj _FILESPEC_ARG is_equal '-'
  then
    wf_arg='stdin';
  fi;
  cat <<EOF
\f[CR]${wf_arg}\f[]:
.br
EOF

  # get the parts of the file name
  wf_name="$(base_name $1)";
  wf_section="$(echo1 $1 | sed -n '
s|^.*/man\('"${_MAN_AUTO_SEC_CHARS}"'\).*$|\1|p
')";
  if obj wf_section is_not_empty
  then
    case "${wf_name}" in
    *.${wf_section}*)
      s='yes';
      ;;
    *)
      s='';
      wf_section='';
      ;;
### whatis_filename()
    esac
    if obj s is_yes
    then
      wf_name="$(echo1 ${wf_name} | sed '
s/^\(.*\)\.'${wf_section}'.*$/\1/
')";
    fi;
  fi;

  # traditional man style; grep the line containing `.TH' macro, if any
  wf_res="$(cat_z "$1" | sed '
/'"${wf_dot}"'TH /p
d
')";
  exit_test;
  if obj wf_res is_not_empty
  then				# traditional man style
    # get the first line after the first `.SH' macro, by
    # - delete up to first .SH;
    # - print all lines before the next .SH;
    # - quit.
    wf_res="$(cat_z "$1" | sed -n '
1,/'"${wf_dot}"'SH/d
/'"${wf_dot}"'SH/q
p
')";

    if obj wf_section is_not_empty
    then
      case "${wf_res}" in
      ${wf_name}${_SPACE_CASE}*-${_SPACE_CASE}*)
        s='yes';
        ;;
### whatis_filename()
      *)
        s='';
        ;;
      esac;
      if obj s is_yes
      then
        wf_res="$(obj wf_res echo1 | sed '
s/^'"${wf_name}${_SPACE_SED}"'[^-]*-'"${_SPACE_SED}"'*\(.*\)$/'"${wf_name}"' ('"${wf_section}"') \\[em] \1/
')";
      fi;
    fi;
    obj wf_res echo1;
    echo;
    eval ${_UNSET} wf_arg;
    eval ${_UNSET} wf_dot;
    eval ${_UNSET} wf_name;
    eval ${_UNSET} wf_res;
    eval ${_UNSET} wf_section;
    eval "${return_ok}";
  fi;

  # mdoc style (BSD doc); grep the line containing `.Nd' macro, if any
  wf_res="$(cat_z "$1" | sed -n '/'"${wf_dot}"'Nd /s///p')";
  exit_test;
  if obj wf_res is_not_empty
  then				# BSD doc style
    if obj wf_section is_not_empty
    then
      wf_res="$(obj wf_res echo1 | sed -n '
s/^\(.*\)$/'"${wf_name}"' ('"${wf_section}"') \\[em] \1/p
')";
    fi;
### whatis_filename()
    obj wf_res echo1;
    echo;
    eval ${_UNSET} wf_arg;
    eval ${_UNSET} wf_dot;
    eval ${_UNSET} wf_name;
    eval ${_UNSET} wf_res;
    eval ${_UNSET} wf_section;
    eval "${return_ok}";
  fi;
  echo1 'is not a man page';
  echo;
  eval ${_UNSET} wf_arg;
  eval ${_UNSET} wf_dot;
  eval ${_UNSET} wf_name;
  eval ${_UNSET} wf_res;
  eval ${_UNSET} wf_section;
  eval "${return_bad}";
} # whatis_filename()



########################################################################
# whatis_filespec ()
#
# Print the filespec name as .SH to the temporary cat file.
#
# Globals:  in: $_OPT_WHATIS, $_SPECIAL_SETUP
#          out: $_SPECIAL_FILESPEC
#
whatis_filespec()
{
  func_check whatis_filespec '=' 0 "$@";
  if obj _OPT_WHATIS is_yes
  then
    if obj _SPECIAL_SETUP is_not_yes
    then
      error 'whatis_filespec(): whatis_setup() must be run first.';
    fi;
    _SPECIAL_FILESPEC='yes';
    eval to_tmp_line \
      "'.SH $(echo1 "${_FILESPEC_ARG}" | sed 's/[^\\]-/\\-/g')'";
    exit_test;
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # whatis_filespec()


########################################################################
# whatis_setup ()
#
# Print the whatis header to the temporary cat file; this is the setup
# for whatis.
#
# Globals:  in: $_OPT_WHATIS
#          out: $_SPECIAL_SETUP
#
whatis_setup()
{
  func_check whatis_setup '=' 0 "$@";
  if obj _OPT_WHATIS is_yes
  then
    to_tmp_line '.TH GROFFER WHATIS';
    _SPECIAL_SETUP='yes';
    if obj _OPT_TITLE is_empty
    then
      _OPT_TITLE='whatis';
    fi;
    eval "${return_ok}";
  else
    eval "${return_bad}";
  fi;
} # whatis_setup()


########################################################################
# where_is_prog (<program>)
#
# Output path of a program and the given arguments if in $PATH.
#
# Arguments : 1, <program> can have spaces and arguments.
# Output    : list of 2 elements: prog name (with directory) and arguments
# Return    : `0' if arg1 is a program in $PATH, `1' otherwise.
#
# Variable prefix: wip
#
where_is_prog()
{
  func_check where_is_prog '=' 1 "$@";
  if is_empty "$1"
  then
    eval "${return_bad}";
  fi;

  # Remove disturbing multiple spaces and tabs
  wip_1="$(echo1 "$1" | sed 's/[ 	][ 	]*/ /g' | \
           sed 's/\(\\\)* / /g' | sed 's/^ //' | sed 's/ $//')";
  wip_noarg="$(echo1 "${wip_1}" | sed 's/ -.*$//')";
  exit_test;

  if obj wip_noarg is_empty
  then
    eval ${_UNSET} wip_1;
    eval ${_UNSET} wip_noarg;
    eval "${return_bad}";
  fi;

  case "${wip_1}" in
  *\ -*)
    wip_args="$(echo1 "${wip_1}" |
                eval sed "'s#^${wip_noarg} ##'")";
    exit_test;
    ;;
  *)
    wip_args='';
    ;;
  esac;

  wip_result='';
### where_is_prog()

  if test -f "${wip_noarg}" && test -x "${wip_noarg}"
  then
    list_append wip_result "${wip_noarg}" "${wip_args}";
    exit_test;
    obj wip_result echo1;
    exit_test;
    eval ${_UNSET} wip_1;
    eval ${_UNSET} wip_args;
    eval ${_UNSET} wip_noarg;
    eval ${_UNSET} wip_result;
    eval "${return_ok}";
  fi;

  # test whether $wip_noarg has directory, so it is not tested with $PATH
  case "${wip_noarg}" in
  */*)
    # now $wip_noarg (with /) is not an executable file

    # test name with space
    obj_from_output wip_name base_name "${wip_noarg}";
    obj_from_output wip_dir dir_name "${wip_noarg}";
    case "${wip_name}" in
    *\ *)
      wip_base="$(echo1 "${wip_name}" | sed 's/ .*$//')";
      exit_test;
      obj_from_output wip_file dir_name_append "${wip_dir}" "${wip_base}";
      exit_test;
### where_is_prog()
      if test -f "${wip_file}" && test -x "${wip_file}"
      then
        wip_baseargs="$(echo1 "${wip_name}" |
                        eval sed "'s#^${wip_base} ##'")";
        exit_test;
        if obj wip_args is_empty
        then
          wip_args="${wip_baseargs}";
        else
          wip_args="${wip_baseargs} ${wip_args}";
        fi;

        list_append wip_result "${wip_file}" "${wip_args}";
        exit_test;
        obj wip_result echo1;
        exit_test;
        eval ${_UNSET} wip_1;
        eval ${_UNSET} wip_args;
        eval ${_UNSET} wip_base;
        eval ${_UNSET} wip_baseargs;
        eval ${_UNSET} wip_dir;
        eval ${_UNSET} wip_file;
        eval ${_UNSET} wip_name;
        eval ${_UNSET} wip_noarg;
        eval ${_UNSET} wip_result;
        eval "${return_ok}";
      fi; # test ${wip_file}
      ;;
    esac; # end of test name with space

### where_is_prog()
    eval ${_UNSET} wip_1;
    eval ${_UNSET} wip_args;
    eval ${_UNSET} wip_base;
    eval ${_UNSET} wip_dir;
    eval ${_UNSET} wip_name;
    eval ${_UNSET} wip_noarg;
    eval ${_UNSET} wip_result;
    eval "${return_bad}";
    ;;
  esac; # test of $wip_noarg on path with directory


  # now $wip_noarg does not have a /, so it is checked with $PATH.

  eval set x "$(path_list "${PATH}")";
  exit_test;
  shift;

  # test path with $win_noarg, evt. with spaces
  for d
  do
    wip_dir="$d";
    obj_from_output wip_file dir_name_append "${wip_dir}" "${wip_noarg}";
### where_is_prog()

    # test $win_file on executable file
    if test -f "${wip_file}" && test -x "${wip_file}"
    then
      list_append wip_result "${wip_file}" "${wip_args}";
      exit_test;
      obj wip_result echo1;
      exit_test;
      eval ${_UNSET} wip_1;
      eval ${_UNSET} wip_dir;
      eval ${_UNSET} wip_file;
      eval ${_UNSET} wip_noarg;
      eval ${_UNSET} wip_result;
      eval "${return_ok}";
    fi; # test $win_file on executable file
  done; # test path with $win_prog with spaces

  case "${wip_noarg}" in
  *\ *)
    # test on path with base name without space
    wip_base="$(echo1 "${wip_noarg}" | sed 's/^\([^ ]*\) .*$/\1/')";
    exit_test;
    for d
    do
      wip_dir="$d";
      obj_from_output wip_file dir_name_append "${wip_dir}" "${wip_base}";
      exit_test;
### where_is_prog()

      # test $win_file on executable file
      if test -f "${wip_file}" && test -x "${wip_file}"
      then
        wip_baseargs="$(echo1 "${wip_noarg}" |
                        sed 's/[^ ]* \(.*\)$/\1/')";
        exit_test;
        if obj wip_args is_empty
        then
          wip_args="${wip_baseargs}";
        else
          wip_args="${wip_args} ${wip_baseargs}";
        fi;
        list_append wip_result "${wip_file}" "${wip_args}";
        exit_test;
        obj wip_result echo1;
        exit_test;
        eval ${_UNSET} wip_1;
        eval ${_UNSET} wip_args;
        eval ${_UNSET} wip_base;
        eval ${_UNSET} wip_baseargs;
        eval ${_UNSET} wip_dir;
        eval ${_UNSET} wip_file;
        eval ${_UNSET} wip_name;
        eval ${_UNSET} wip_noarg;
        eval ${_UNSET} wip_result;
        eval "${return_ok}";
      fi; # test of $wip_file on executable file
    done; # test path with base name without space
### where_is_prog()
    ;;
  esac; # test of $wip_noarg on space

  eval ${_UNSET} wip_1;
  eval ${_UNSET} wip_args;
  eval ${_UNSET} wip_base;
  eval ${_UNSET} wip_baseargs;
  eval ${_UNSET} wip_dir;
  eval ${_UNSET} wip_file;
  eval ${_UNSET} wip_name;
  eval ${_UNSET} wip_noarg;
  eval ${_UNSET} wip_result;
  eval "${return_bad}";
} # where_is_prog()


########################################################################
#                        main* Functions
########################################################################

# The main area contains the following parts:
# - main_init(): initialize temporary files and set exit trap
# - main_parse_MANOPT(): parse $MANOPT
# - main_parse_args(): argument parsing
# - main_set_mode (): determine the display mode
# - main_do_fileargs(): process filespec arguments
# - main_set_resources(): setup X resources
# - main_display(): do the displaying
# - main(): the main function that calls all main_*()


#######################################################################
# main_init ()
#
# Set exit trap and create temporary directory and some temporary files.
#
# Globals: $_TMP_DIR, $_TMP_CAT, $_TMP_STDIN
#
# Variable prefix: mi
#
main_init()
{
  func_check main_init = 0 "$@";
  # call clean_up() on shell termination.
  trap_set;

  # create temporary directory
  umask 0077;
  _TMP_DIR='';
  for d in "${GROFF_TMPDIR}" "${TMPDIR}" "${TMP}" "${TEMP}" \
           "${TEMPDIR}" "${HOME}"'/tmp' '/tmp' "${HOME}" '.'
  do
    mi_dir="$d";
    if obj mi_dir is_empty || obj mi_dir is_not_dir || \
       obj mi_dir is_not_writable
    then
      continue;
    fi;

    case "${mi_dir}" in
    */)
      _TMP_DIR="${mi_dir}";
      ;;
    *)
      _TMP_DIR="${mi_dir}"'/';
      ;;
    esac;
    _TMP_DIR="${_TMP_DIR}groffer${_PROCESS_ID}";
    if obj _TMP_DIR rm_tree
    then
      :
    else
      mi_tdir_="${_TMP_DIR}"_;
      mi_n=1;
      mi_tdir_n="${mi_tdir_}${mi_n}";
### main_init()
      while obj mi_tdir_n is_existing
      do
        if obj mi_tdir_n rm_tree
        then
          # directory could not be removed
          mi_n="$(expr "${mi_n}" + 1)";
          mi_tdir_n="${mi_tdir_}${mi_n}";
          continue;
        fi;
      done;
      _TMP_DIR="${mi_tdir_n}";
    fi;
    eval mkdir "${_TMP_DIR}";
    if is_not_equal "$?" 0
    then
      obj _TMP_DIR rm_tree;
      _TMP_DIR='';
      continue;
    fi;
    if obj _TMP_DIR is_dir && obj _TMP_DIR is_writable
    then
      # $_TMP_DIR can now be used as temporary directory
      break;
    fi;
    obj _TMP_DIR rm_tree;
    _TMP_DIR='';
    continue;
  done;
  if obj _TMP_DIR is_empty
  then
    error "main_init(): \
Couldn't create a directory for storing temporary files.";
  fi;
### main_init()
  if obj _DEBUG_PRINT_TMPDIR is_yes
  then
    echo2 "temporary directory: ${_TMP_DIR}";
  fi;

  obj_from_output _TMP_CAT tmp_create groffer_cat;
  obj_from_output _TMP_STDIN tmp_create groffer_input;

  eval ${_UNSET} mi_dir;
  eval ${_UNSET} mi_n;
  eval ${_UNSET} mi_tdir_;
  eval ${_UNSET} mi_tdir_n;
  eval "${return_ok}";
} # main_init()


########################################################################
# main_parse_MANOPT ()
#
# Parse $MANOPT to retrieve man options, but only if it is a non-empty
# string; found man arguments can be overwritten by the command line.
#
# Globals:
#   in: $MANOPT, $_OPTS_MANOPT_*
#   out: $_MANOPT_*
#
# Variable prefix: mpm
#
main_parse_MANOPT()
{
  func_check main_parse_MANOPT = 0 "$@";

  if obj MANOPT is_not_empty
  then
    # Delete leading and final spaces
    MANOPT="$(echo1 "${MANOPT}" | sed '
s/^'"${_SPACE_SED}"'*//
s/'"${_SPACE_SED}"'*$//
')";
    exit_test;
  fi;
  if obj MANOPT is_empty
  then
    eval "${return_ok}";
  fi;

  mpm_list='';
  # add arguments in $MANOPT by mapping them to groffer options
  eval set x "$(list_from_cmdline _OPTS_MANOPT "${MANOPT}")";
  exit_test;
  shift;
  until test "$#" -le 0 || is_equal "$1" '--'
  do
    mpm_opt="$1";
    shift;
    case "${mpm_opt}" in
    -7|--ascii)
      list_append mpm_list '--ascii';
      ;;
    -a|--all)
      list_append mpm_list '--all';
      ;;
### main_parse_MANOPT()
    -c|--catman)
      do_nothing;
      shift;
      ;;
    -d|--debug)
      do_nothing;
      ;;
    -D|--default)
      # undo all man options so far
      mpm_list='';
      ;;
    -e|--extension)
      list_append mpm_list '--extension';
      shift;
      ;;
    -f|--whatis)
      list_append mpm_list '--whatis';
      shift;
      ;;
    -h|--help)
      do_nothing;
      ;;
    -k|--apropos)
      # groffer's --apropos takes an argument, but man's does not, so
      do_nothing;
      ;;
    -l|--local-file)
      do_nothing;
      ;;
    -L|--locale)
      list_append mpm_list '--locale' "$1";
      shift;
      ;;
### main_parse_MANOPT()
    -m|--systems)
      list_append mpm_list '--systems' "$1";
      shift;
      ;;
    -M|--manpath)
      list_append mpm_list '--manpath' "$1";
      shift;
      ;;
    -p|--preprocessor)
      do_nothing;
      shift;
      ;;
    -P|--pager)
      list_append mpm_list '--pager' "$1";
      shift;
      ;;
    -r|--prompt)
      do_nothing;
      shift;
      ;;
    -S|--sections)
      list_append mpm_list '--sections' "$1";
      shift;
      ;;
    -t|--troff)
      do_nothing;
      ;;
    -T|--device)
      list_append mpm_list '-T' "$1";
      shift;
      ;;
### main_parse_MANOPT()
    -u|--update)
      do_nothing;
      ;;
    -V|--version)
      do_nothing;
      ;;
    -w|--where|--location)
      list_append mpm_list '--location';
      ;;
    -Z|--ditroff)
      do_nothing;
      ;;
    # ignore all other options
    esac;
  done;

  # prepend $mpm_list to the command line
  if obj mpm_list is_not_empty
  then
    eval set x "${mpm_list}" '"$@"';
    shift;
  fi;

  eval ${_UNSET} mpm_list;
  eval ${_UNSET} mpm_opt;
  eval "${return_ok}";
} # main_parse_MANOPT()


########################################################################
# main_parse_args (<command_line_args>*)
#
# Parse arguments; process options and filespec parameters.
#
# Arguments: pass the command line arguments unaltered.
# Globals:
#   in:  $_OPTS_*
#   out: $_OPT_*, $_ADDOPTS, $_FILEARGS
#
# Variable prefix: mpa
#
main_parse_args()
{
  func_check main_parse_args '>=' 0 "$@";
  obj_from_output _ALL_PARAMS list_from_cmdline_with_minus _OPTS_CMDLINE "$@";
  if obj _DEBUG_PRINT_PARAMS is_yes
  then
    echo2 "parameters: ${_ALL_PARAMS}";
  fi;
  eval set x "${_ALL_PARAMS}";
  shift;

  # By the call of `eval', unnecessary quoting was removed.  So the
  # positional shell parameters ($1, $2, ...) are now guaranteed to
  # represent an option or an argument to the previous option, if any;
  # then a `--' argument for separating options and
  # parameters; followed by the filespec parameters if any.

  # Note, the existence of arguments to options has already been checked.
  # So a check for `$#' or `--' should not be done for arguments.

  until test "$#" -le 0 || is_equal "$1" '--'
  do
    mpa_opt="$1";		# $mpa_opt is fed into the option handler
    shift;
    case "${mpa_opt}" in
    -h|--help)
      usage;
      leave;
      ;;
    -Q|--source)		# output source code (`Quellcode').
      _OPT_MODE='source';
      ;;
### main_parse_args()
    -T|--device|--troff-device) # device; arg
      _OPT_DEVICE="$1";
      _check_device_with_mode;
      shift;
      ;;
    -v|--version)
      version;
      leave;
      ;;
    -V)
      _OPT_V='yes';
      ;;
    -Z|--ditroff|--intermediate-output) # groff intermediate output
      _OPT_Z='yes';
      ;;
    -X)
      _OPT_MODE=X;
      ;;
    -?)
      # delete leading `-'
      mpa_optchar="$(echo1 "${mpa_opt}" | sed 's/^-//')";
      exit_test;
      if list_has _OPTS_GROFF_SHORT_NA "${mpa_optchar}"
      then
        list_append _ADDOPTS_GROFF "${mpa_opt}";
      elif list_has _OPTS_GROFF_SHORT_ARG "${mpa_optchar}"
      then
        list_append _ADDOPTS_GROFF "${mpa_opt}" "$1";
        shift;
### main_parse_args()
      else
        error "main_parse_args(): Unknown option : \`$1'";
      fi;
      ;;
    --all)
        _OPT_ALL='yes';
        ;;
    --apropos)			# run `apropos'
      _OPT_APROPOS='yes';
      _APROPOS_SECTIONS='';
      _OPT_WHATIS='no';
      ;;
    --apropos-data)		# run `apropos' for data sections
      _OPT_APROPOS='yes';
      _APROPOS_SECTIONS='457';
      _OPT_WHATIS='no';
      ;;
    --apropos-devel)		# run `apropos' for development sections
      _OPT_APROPOS='yes';
      _APROPOS_SECTIONS='239';
      _OPT_WHATIS='no';
      ;;
    --apropos-progs)		# run `apropos' for program sections
      _OPT_APROPOS='yes';
      _APROPOS_SECTIONS='168';
      _OPT_WHATIS='no';
      ;;
### main_parse_args()
    --ascii)
      list_append _ADDOPTS_GROFF '-mtty-char';
      if obj _OPT_MODE is_empty
      then
        _OPT_MODE='text';
      fi;
      ;;
    --auto)			# the default automatic mode
      _OPT_MODE='';
      ;;
    --bd|--bordercolor)		# border color for viewers, arg;
      _OPT_BD="$1";
      shift;
      ;;
    --bg|--backgroud)		# background color for viewers, arg;
      _OPT_BG="$1";
      shift;
      ;;
    --bw|--borderwidth)		# border width for viewers, arg;
      _OPT_BW="$1";
      shift;
      ;;
    --debug|--debug-all|--debug-filenames|--debug-func|--debug-not-func|\
--debug-grog|--debug-keep|--debug-lm|--debug-params|--debug-shell|\
--debug-stacks|--debug-tmpdir|--debug-user)
      # debug is handled at the beginning
      :;
      ;;
    --default)			# reset variables to default
      reset;
      ;;
### main_parse_args()
    --default-modes)		# sequence of modes in auto mode; arg
      _OPT_DEFAULT_MODES="$1";
      shift;
      ;;
    --display)			# set X display, arg
      _OPT_DISPLAY="$1";
      shift;
      ;;
    --do-nothing)
      _OPT_DO_NOTHING='yes';
      ;;
    --dvi)
      _OPT_MODE='dvi';
      ;;
    --dvi-viewer|--dvi-viewer-tty) # viewer program for dvi mode; arg
      _OPT_VIEWER_DVI="$1";
      shift;
      ;;
    --extension)		# the extension for man pages, arg
      _OPT_EXTENSION="$1";
      shift;
      ;;
### main_parse_args()
    --fg|--foreground)		# foreground color for viewers, arg;
      _OPT_FG="$1";
      shift;
      ;;
    --fn|--ft|--font)		# set font for viewers, arg;
      _OPT_FN="$1";
      shift;
      ;;
    --geometry)			# window geometry for viewers, arg;
      _OPT_GEOMETRY="$1";
      shift;
      ;;
    --groff)
      _OPT_MODE='groff';
      ;;
    --html|--www)		# display with web browser
      _OPT_MODE=html;
      ;;
    --html-viewer|--www-viewer|--html-viewer-tty|--www-viewer-tty)
      # viewer program for html mode; arg
      _OPT_VIEWER_HTML="$1";
      shift;
      ;;
    --iconic)			# start viewers as icons
      _OPT_ICONIC='yes';
      ;;
### main_parse_args()
    --locale)			# set language for man pages, arg
      # argument is xx[_territory[.codeset[@modifier]]] (ISO 639,...)
      _OPT_LANG="$1";
      shift;
      ;;
    --local-file)		# force local files; same as `--no-man'
      _MAN_FORCE='no';
      _MAN_ENABLE='no';
      ;;
    --location|--where)		# print file locations to stderr
      _DEBUG_PRINT_FILENAMES='yes';
      ;;
    --man)		       # force all file params to be man pages
      _MAN_ENABLE='yes';
      _MAN_FORCE='yes';
      ;;
    --manpath)		      # specify search path for man pages, arg
      # arg is colon-separated list of directories
      _OPT_MANPATH="$1";
      shift;
      ;;
    --mode)			# display mode
      mpa_arg="$1";
      shift;
      case "${mpa_arg}" in
      auto|'')		     # search mode automatically among default
        _OPT_MODE='';
        ;;
      groff)			# pass input to plain groff
        _OPT_MODE='groff';
        ;;
### main_parse_args()
      html|www)			# display with a web browser
        _OPT_MODE='html';
        ;;
      dvi)			# display with xdvi viewer
        _OPT_MODE='dvi';
        ;;
      pdf)			# display with PDF viewer
        _OPT_MODE='pdf';
        ;;
      ps)			# display with Postscript viewer
        _OPT_MODE='ps';
        ;;
      text)			# output on terminal
        _OPT_MODE='text';
        ;;
      tty)			# output on terminal
        _OPT_MODE='tty';
        ;;
      X|x)			# output on X roff viewer
        _OPT_MODE='x';
        ;;
### main_parse_args()
      Q|source)			# display source code
        _OPT_MODE="source";
        ;;
      *)
        error "main_parse_args(): unknown mode ${mpa_arg}";
        ;;
      esac;
      ;;
    --no-location)		# disable former call to `--location'
      _DEBUG_PRINT_FILENAMES='no';
      ;;
    --no-man)			# disable search for man pages
      # the same as --local-file
      _MAN_FORCE='no';
      _MAN_ENABLE='no';
      ;;
    --no-special)		# disable some special former calls
      _OPT_ALL='no'
      _OPT_APROPOS='no'
      _OPT_WHATIS='no'
      ;;
    --pager|--tty-viewer|--tty-viewer-tty)
      # set paging program for tty mode, arg
      _OPT_PAGER="$1";
      shift;
      ;;
    --pdf)
      _OPT_MODE='pdf';
      ;;
### main_parse_args()
    --pdf-viewer|--pdf-viewer-tty) # viewer program for pdf mode; arg
      _OPT_VIEWER_PDF="$1";
      shift;
      ;;
    --print)			# for argument test
      echo2 "$1";
      shift;
      ;;
    --ps)
      _OPT_MODE='ps';
      ;;
    --ps-viewer|--ps-viewer-tty) # viewer program for ps mode; arg
      _OPT_VIEWER_PS="$1";
      shift;
      ;;
### main_parse_args()
    --resolution)		# set resolution for X devices, arg
      mpa_arg="$1";
      shift;
      case "${mpa_arg}" in
      75|75dpi)
        mpa_dpi=75;
        ;;
      100|100dpi)
        mpa_dpi=100;
        ;;
      *)
        error "main_parse_args(): \
only resoutions of 75 or 100 dpi are supported";
        ;;
      esac;
      _OPT_RESOLUTION="${mpa_dpi}";
      ;;
    --rv)
      _OPT_RV='yes';
      ;;
    --sections)			# specify sections for man pages, arg
      # arg is colon-separated list of section names
      _OPT_SECTIONS="$1";
      shift;
      ;;
    --shell)
      # already done during the first run; so ignore the argument
      shift;
      ;;
### main_parse_args()
    --systems)			# man pages for different OS's, arg
      # argument is a comma-separated list
      _OPT_SYSTEMS="$1";
      shift;
      ;;
    --text)			# text mode without pager
      _OPT_MODE=text;
      ;;
    --title)			# title for X viewers; arg
      if is_not_empty "$1"
      then
        list_append _OPT_TITLE "$1";
      fi;
      shift;
      ;;
     --to-stdout)		# print mode file without display
      _OPT_STDOUT='yes';
      ;;
     --tty)			# tty mode, text with pager
      _OPT_MODE=tty;
      ;;
    --text-device|--tty-device) # device for tty mode; arg
      _OPT_TEXT_DEVICE="$1";
      shift;
      ;;
    --whatis)
      _OPT_WHATIS='yes';
      _OPT_APROPOS='no';
      ;;
    --X|--x)
      _OPT_MODE=x;
      ;;
### main_parse_args()
    --xrm)			# pass X resource string, arg;
      list_append _OPT_XRM "$1";
      shift;
      ;;
    --x-viewer|--X-viewer|--x-viewer-tty|--X-viewer-tty)
      # viewer program for x mode; arg
      _OPT_VIEWER_X="$1";
      shift;
      ;;
    *)
      error 'main_parse_args(): unknown option '"\`${mpa_opt}'.";
      ;;
    esac;
  done;
  shift;			# remove `--' argument

  if obj _OPT_WHATIS is_yes
  then
    _MAN_ALL='yes';
    _APROPOS_SECTIONS='';
  fi;

  if obj _OPT_DO_NOTHING is_yes
  then
    leave;
  fi;

### main_parse_args()
  case "$_OPT_DEFAULT_MODES" in
  '') :; ;;
  *,*)
    obj_from_output _OPT_DEFAULT_MODES \
      obj _OPT_DEFAULT_MODES list_from_split ',';
    ;;
  *) :; ;;
  esac;

  # Remaining arguments are file names (filespecs).
  # Save them to list $_FILEARGS
  if is_equal "$#" 0
  then				# use "-" for standard input
    _NO_FILESPECS='yes';
    set x '-';
    shift;
  fi;
  _FILEARGS='';
  list_append _FILEARGS "$@";
  # $_FILEARGS must be retrieved with `eval set x "$_FILEARGS"; shift;'
  eval ${_UNSET} mpa_arg;
  eval ${_UNSET} mpa_dpi;
  eval ${_UNSET} mpa_opt;
  eval ${_UNSET} mpa_optchar;
  eval "${return_ok}";
} # main_parse_args()


# Called from main_parse_args() because double `case' is not possible.
# Globals: $_OPT_DEVICE, $_OPT_MODE
_check_device_with_mode()
{
  func_check _check_device_with_mode = 0 "$@";
  case "${_OPT_DEVICE}" in
  dvi)
    _OPT_MODE=dvi;
    eval "${return_ok}";
    ;;
  html)
    _OPT_MODE=html;
    eval "${return_ok}";
    ;;
  lbp|lj4)
    _OPT_MODE=groff;
    eval "${return_ok}";
    ;;
  ps)
    _OPT_MODE=ps;
    eval "${return_ok}";
    ;;
  ascii|cp1047|latin1|utf8)
    if obj _OPT_MODE is_not_equal text
    then
      _OPT_MODE=tty;		# default text mode
    fi;
    eval "${return_ok}";
    ;;
  X*)
    _OPT_MODE=x;
    eval "${return_ok}";
    ;;
  *)				# unknown device, go to groff mode
    _OPT_MODE=groff;
    eval "${return_ok}";
    ;;
  esac;
  eval "${return_error}";
} # _check_device_with_mode() of main_parse_args()


########################################################################
# main_set_mode ()
#
# Determine the display mode and the corresponding viewer program.
#
# Globals:
#   in:  $DISPLAY, $_OPT_MODE, $_OPT_DEVICE
#   out: $_DISPLAY_MODE
#
# Variable prefix: msm
#
main_set_mode()
{
  func_check main_set_mode = 0 "$@";

  # set display
  if obj _OPT_DISPLAY is_not_empty
  then
    DISPLAY="${_OPT_DISPLAY}";
  fi;

  if obj _OPT_V is_yes
  then
    list_append _ADDOPTS_GROFF '-V';
  fi;
  if obj _OPT_Z is_yes
  then
    _DISPLAY_MODE='groff';
    list_append _ADDOPTS_GROFF '-Z';
  fi;
  if obj _OPT_MODE is_equal 'groff'
  then
    _DISPLAY_MODE='groff';
  fi;
  if obj _DISPLAY_MODE is_equal 'groff'
  then
    eval ${_UNSET} msm_modes;
    eval ${_UNSET} msm_viewers;
    eval "${return_ok}";
  fi;

### main_set_mode()

  case "${_OPT_MODE}" in
  '')				# automatic mode
    case "${_OPT_DEVICE}" in
    X*)
     if is_not_X
      then
        error_user "no X display found for device ${_OPT_DEVICE}";
      fi;
      _DISPLAY_MODE='x';
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    ascii|cp1047|latin1|utf8)
      if obj _DISPLAY_MODE is_not_equal 'text'
      then
        _DISPLAY_MODE='tty';
      fi;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
### main_set_mode()
    esac;
    if is_not_X
    then
      _DISPLAY_MODE='tty';
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
    fi;

    if obj _OPT_DEFAULT_MODES is_empty
    then
      msm_modes="${_DEFAULT_MODES}";
    else
      msm_modes="${_OPT_DEFAULT_MODES}";
    fi;
    ;;
  source)
    _DISPLAY_MODE='source';
    eval ${_UNSET} msm_modes;
    eval ${_UNSET} msm_viewers;
    eval "${return_ok}";
    ;;
  text)
    _DISPLAY_MODE='text';
    eval ${_UNSET} msm_modes;
    eval ${_UNSET} msm_viewers;
    eval "${return_ok}";
    ;;
  tty)
    _DISPLAY_MODE='tty';
    eval ${_UNSET} msm_modes;
    eval ${_UNSET} msm_viewers;
    eval "${return_ok}";
    ;;
### main_set_mode()
  html)
    _DISPLAY_MODE='html';
    msm_modes="${_OPT_MODE}";
    ;;
  *)				# display mode was given
    msm_modes="${_OPT_MODE}";
    ;;
  esac;

  eval set x "${msm_modes}";
  shift;
  while is_greater_than "$#" 0
  do
    msm_1="$1";
    shift;

    _VIEWER_BACKGROUND='no';

    case "${msm_1}" in
    dvi)
      _get_prog_args DVI;
      if is_not_equal "$?" 0
      then
        continue;
      fi;
      if obj _DISPLAY_PROG is_empty
      then
        if is_equal "$#" 0
        then
          error 'main_set_mode(): No viewer for dvi mode available.';
        else
          continue;
        fi;
      fi;
### main_set_mode()
      _DISPLAY_MODE="dvi";
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    html)
      _get_prog_args HTML;
      if is_not_equal "$?" 0
      then
        continue;
      fi;
      if obj _DISPLAY_PROG is_empty
      then
        if is_equal "$#" 0
        then
          error 'main_set_mode(): No viewer for html mode available.';
        else
          continue;
        fi;
      fi;
### main_set_mode()
      _DISPLAY_MODE=html;
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    pdf)
      if obj _PDF_DID_NOT_WORK is_yes
      then
        if is_equal "$#" 0
        then
          error 'main_set_mode(): pdf mode did not work.';
        else
          continue;
        fi;
      fi;
      if obj _PDF_HAS_PS2PDF is_not_yes
      then
        if is_prog ps2pdf
        then
          _PDF_HAS_PS2PDF='yes';
        fi;
      fi;
      if obj _PDF_HAS_GS is_not_yes
      then
        if is_prog gs
        then
          _PDF_HAS_GS='yes';
        fi;
      fi;
      _get_prog_args PDF;
      if is_not_equal "$?" 0
      then
        _PDF_DID_NOT_WORK='yes';
        continue;
      fi;
      if obj _DISPLAY_PROG is_empty
      then
        _PDF_DID_NOT_WORK='yes';
        if is_equal "$#" 0
        then
          error 'main_set_mode(): No viewer for pdf mode available.';
        else
          continue;
        fi;
      fi;
      _DISPLAY_MODE="pdf";
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
### main_set_mode()
    ps)
      _get_prog_args PS;
      if is_not_equal "$?" 0
      then
        continue;
      fi;
      if obj _DISPLAY_PROG is_empty
      then
        if is_equal "$#" 0
        then
          error 'main_set_mode(): No viewer for ps mode available.';
        else
          continue;
        fi;
      fi;
      _DISPLAY_MODE="ps";
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    text)
      _DISPLAY_MODE='text';
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
### main_set_mode()
    tty)
      _DISPLAY_MODE='tty';
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    x)
      _get_prog_args x;
      if is_not_equal "$?" 0
      then
        continue;
      fi;
      if obj _DISPLAY_PROG is_empty
      then
        if is_equal "$#" 0
        then
          error 'main_set_mode(): No viewer for x mode available.';
        else
          continue;
        fi;
      fi;
      _DISPLAY_MODE='x';
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
### main_set_mode()
    X)
      _DISPLAY_MODE='X';
      eval ${_UNSET} msm_1;
      eval ${_UNSET} msm_modes;
      eval ${_UNSET} msm_viewers;
      eval "${return_ok}";
      ;;
    esac;
  done;
  eval ${_UNSET} msm_1;
  eval ${_UNSET} msm_modes;
  eval ${_UNSET} msm_viewers;
  error_user "No suitable display mode found.";
} # main_set_mode()


# _get_prog_args (<MODE>)
#
# Simplification for loop in main_set_mode().
#
# Globals in/out: $_VIEWER_BACKGROUND
# Globals in    : $_OPT_VIEWER_<MODE>, $_VIEWER_<MODE>_X, $_VIEWER_<MODE>_TTY
#
# Variable prefix: _gpa
#
_get_prog_args()
{
  func_check _get_prog_args '=' 1 "$@";

  x="$(echo1 $1 | tr [a-z] [A-Z])";
  eval _gpa_opt='"${_OPT_VIEWER_'"$x"'}"';
  _gpa_xlist=_VIEWER_"$x"_X;
  _gpa_ttylist=_VIEWER_"$x"_TTY;

  if obj _gpa_opt is_empty
  then
    _VIEWER_BACKGROUND='no';
    if is_X
    then
      _get_first_prog "${_gpa_xlist}";
      x="$?";
      if is_equal "$x" 0
      then
        _VIEWER_BACKGROUND='yes';
      fi;
    else
      _get_first_prog "${_gpa_ttylist}";
      x="$?";
    fi;
    exit_test;
    eval ${_UNSET} _gpa_opt;
    eval ${_UNSET} _gpa_prog;
    eval ${_UNSET} _gpa_ttylist;
    eval ${_UNSET} _gpa_xlist;
    eval "${return_var} $x";
### _get_prog_args() of main_set_mode()
  else				# $_gpa_opt is not empty
    obj_from_output _gpa_prog where_is_prog "${_gpa_opt}";
    if is_not_equal "$?" 0 || obj _gpa_prog is_empty
    then
      exit_test;
      echo2 "_get_prog_args(): '${_gpa_opt}' is not an existing program.";
      eval ${_UNSET} _gpa_opt;
      eval ${_UNSET} _gpa_prog;
      eval ${_UNSET} _gpa_ttylist;
      eval ${_UNSET} _gpa_xlist;
      eval "${return_bad}";
    fi;
    exit_test;

    # $_gpa_prog from opt is an existing program

### _get_prog_args() of main_set_mode()
    if is_X
    then
      eval _check_prog_on_list ${_gpa_prog} ${_gpa_xlist};
      if is_equal "$?" 0
      then
        _VIEWER_BACKGROUND='yes';
      else
        _VIEWER_BACKGROUND='no';
        eval _check_prog_on_list ${_gpa_prog} ${_gpa_ttylist};
      fi;
    else			# is not X
      _VIEWER_BACKGROUND='no';
      eval _check_prog_on_list ${_gpa_prog} ${_gpa_ttylist};
    fi;				# is_X
  fi;				# test of $_gpa_opt
  eval ${_UNSET} _gpa_opt;
  eval ${_UNSET} _gpa_prog;
  eval ${_UNSET} _gpa_ttylist;
  eval ${_UNSET} _gpa_xlist;
  eval "${return_good}";
} # _get_prog_args() of main_set_mode()


# _get_first_prog (<prog_list_name>)
#
# Retrieve from the elements of the list in the argument the first
# existing program in $PATH.
#
# Local function for main_set_mode().
#
# Return  : `1' if none found, `0' if found.
# Output  : none
#
# Variable prefix: _gfp
#
_get_first_prog()
{
  func_check _get_first_prog '=' 1 "$@";
  eval x='"${'"$1"'}"';
  eval set x "$x";
  shift;
  for i
  do
    _gfp_i="$i";
    if obj _gfp_i is_empty
    then
      continue;
    fi;
    obj_from_output _gfp_result where_is_prog "${_gfp_i}";
    if is_equal "$?" 0 && obj _gfp_result is_not_empty
    then
      exit_test;
      eval set x ${_gfp_result};
      shift;
      _DISPLAY_PROG="$1";
      _DISPLAY_ARGS="$2";
      eval ${_UNSET} _gfp_i;
      eval ${_UNSET} _gfp_result;
      eval "${return_good}";
    fi;
    exit_test;
  done;
  eval ${_UNSET} _gfp_i;
  eval ${_UNSET} _gfp_result;
  eval "${return_bad}";
} # _get_first_prog() of main_set_mode()


# _check_prog_on_list (<prog> <args> <prog_list_name>)
#
# Check whether the content of <prog> is in the list <prog_list_name>.
# The globals are set correspondingly.
#
# Local function for main_set_mode().
#
# Arguments: 3
#
# Return  : `1' if not a part of the list, `0' if found in the list.
# Output  : none
#
# Globals in    : $_VIEWER_<MODE>_X, $_VIEWER_<MODE>_TTY
# Globals in/out: $_DISPLAY_PROG, $_DISPLAY_ARGS
#
# Variable prefix: _cpol
#
_check_prog_on_list()
{
  func_check _check_prog_on_list '=' 3 "$@";
  _DISPLAY_PROG="$1";
  _DISPLAY_ARGS="$2";

  eval _cpol_3='"${'"$3"'}"';
  eval set x "${_cpol_3}";
  shift;
  eval ${_UNSET} _cpol_3;

  for i
  do
    _cpol_i="$i";
    obj_from_output _cpol_list where_is_prog "${_cpol_i}";
    if is_not_equal "$?" 0 || obj _cpol_list is_empty
    then
      exit_test;
      continue;
    fi;
    exit_test;
    _cpol_prog="$(eval set x ${_cpol_list}; shift; echo1 "$1")";

    if is_not_equal "${_DISPLAY_PROG}" "${_cpol_prog}"
    then
      exit_test;
      continue;
    fi;
    exit_test;
### _check_prog_on_list() of main_set_mode()

    # equal, prog found

    _cpol_args="$(eval set x ${_cpol_list}; shift; echo1 "$2")";
    eval ${_UNSET} _cpol_list;
    if obj _cpol_args is_not_empty
    then
      if obj _DISPLAY_ARGS is_empty
      then
        _DISPLAY_ARGS="${_cpol_args}";
      else
        _DISPLAY_ARGS="${_cpol_args} ${_DISPLAY_ARGS}";
      fi;
    fi;

    eval ${_UNSET} _cpol_i;
    eval ${_UNSET} _cpol_args;
    eval ${_UNSET} _cpol_prog;
    eval "${return_good}";
  done; # for vars in list

  # prog was not in the list
  eval ${_UNSET} _cpol_i;
  eval ${_UNSET} _cpol_args;
  eval ${_UNSET} _cpol_list;
  eval ${_UNSET} _cpol_prog;
  eval "${return_bad}";
} # _check_prog_on_list() of main_set_mode()


#######################################################################
# main_do_fileargs ()
#
# Process filespec arguments.
#
# Globals:
#   in: $_FILEARGS (process with `eval set x "$_FILEARGS"; shift;')
#
# Variable prefix: mdfa
#
main_do_fileargs()
{
  func_check main_do_fileargs = 0 "$@";
  special_setup;
  if obj _OPT_APROPOS is_yes
  then
    if obj _NO_FILESPECS is_yes
    then
      apropos_filespec;
      eval "${return_ok}";
    fi;
  else
    if list_has _FILEARGS '-'
    then
      save_stdin;
    fi;
  fi;
  eval set x "${_FILEARGS}";
  shift;
  eval ${_UNSET} _FILEARGS;
### main_do_fileargs()
  while is_greater_than "$#" 0
  do
    mdfa_filespec="$1";
    _FILESPEC_ARG="$1";
    shift;
    _FILESPEC_IS_MAN='no';
    _TMP_MANSPEC='';
    _SPECIAL_FILESPEC='no';

    case "${mdfa_filespec}" in
    '')
      continue;
      ;;
    esac;

    # check for file
    case "${mdfa_filespec}" in
    '-')
      special_filespec;
      if obj _OPT_APROPOS is_yes
      then
        continue;
      fi;
      register_file '-';
      continue;
      ;;
### main_do_fileargs()
    */*)
      special_filespec;
      if obj _OPT_APROPOS is_yes
      then
        continue;
      fi;
      if obj mdfa_filespec is_file
      then
        obj mdfa_filespec register_file;
      else
        echo2 "The argument ${mdfa_filespec} is not a file.";
      fi;
      continue;
      ;;
    *)
      if obj _OPT_APROPOS is_yes
      then
        special_filespec;
        continue;
      fi;
      # check whether filespec is an existing file
      if obj _MAN_FORCE is_not_yes
      then
        if obj mdfa_filespec is_file
        then
          special_filespec;
          obj mdfa_filespec register_file;
          continue;
        fi;
      fi;
      ;;
    esac;
### main_do_fileargs()

    # now it must be a man page pattern

    if obj _MACRO_PKG is_not_empty && obj _MACRO_PKG is_not_equal '-man'
    then
      echo2 "${mdfa_filespec} is not a file, man pages are ignored "\
"due to ${_MACRO_PKG}.";
      continue;
    fi;

    # check for man page
    if obj _MAN_ENABLE is_not_yes
    then
      echo2 "The argument ${mdfa_filespec} is not a file.";
      continue;
    fi;
    if obj _MAN_FORCE is_yes
    then
      mdfa_errmsg='is not a man page.';
    else
      mdfa_errmsg='is neither a file nor a man page.';
    fi;
### main_do_fileargs()
    man_setup;
    _FILESPEC_IS_MAN='yes';

    # test filespec with `man:...' or `...(...)' on man page
    mdfa_name='';
    mdfa_section='';
    mdfa_ext='';

    mdfa_names="${mdfa_filespec}";
    case "${mdfa_filespec}" in
    man:*)
        mdfa_names="${mdfa_names} "\
"$(obj mdfa_filespec echo1 | sed 's/^man://')";
        ;;
    esac;

    mdfa_continue='no';
    for i in ${mdfa_names}
    do
      mdfa_i=$i;
      if obj mdfa_i man_is_man
      then
        special_filespec;
        obj mdfa_i man_get;
        mdfa_continue='yes';
        break;
      fi;
      case "${mdfa_i}" in
      *\(${_MAN_AUTO_SEC_CHARS}*\))
        mdfa_section="$(obj mdfa_i echo1 | sed 's/^[^(]*(\(.\).*)$/\1/')";
        mdfa_name="$(obj mdfa_i echo1 | sed 's/^\([^(]*\)(.*)$/\1/')";
        mdfa_ext="$(obj mdfa_i echo1 | sed 's/^[^(]*(.\(.*\))$/\1/')";
        if man_is_man "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}"
        then
          special_filespec;
          man_get "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}";
          mdfa_continue='yes';
          break;
        fi;
        ;;
      *.${_MAN_AUTO_SEC_CHARS}*)
        mdfa_name="$(obj mdfa_i echo1 | \
          sed 's/^\(.*\)\.'"${_MAN_AUTO_SEC_CHARS}"'.*$/\1/')";
        mdfa_section="$(obj mdfa_i echo1 | \
          sed 's/^.*\.\('"${_MAN_AUTO_SEC_CHARS}"'\).*$/\1/')";
        mdfa_ext="$(obj mdfa_i echo1 | \
          sed 's/^.*\.'"${_MAN_AUTO_SEC_CHARS}"'\(.*\)$/\1/')";
        if man_is_man "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}"
        then
          special_filespec;
          man_get "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}";
          mdfa_continue='yes';
          break;
        fi;
      ;;
      esac;
    done;

    if obj mdfa_continue is_yes
    then
      continue;
    fi;

### main_do_fileargs()
    # check on "s name", where "s" is a section with or without an extension
    if is_not_empty "$1"
    then
      mdfa_name="$1";
      case "${mdfa_filespec}" in
      ${_MAN_AUTO_SEC_CHARS})
        mdfa_section="${mdfa_filespec}";
        mdfa_ext='';
        ;;
      ${_MAN_AUTO_SEC_CHARS}*)
        mdfa_section="$(echo1 "${mdfa_filespec}" | \
                        sed 's/^\(.\).*$/\1/')";
        mdfa_ext="$(echo1 "${mdfa_filespec}" | \
                    sed 's/^.\(.*\)$/\1/')";
        ;;
      *)
        echo2 "${mdfa_filespec} ${mdfa_errmsg}";
        continue;
        ;;
      esac;
      shift;
      if man_is_man "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}"
      then
        _FILESPEC_ARG="${mdfa_filespec} ${mdfa_name}";
        special_filespec;
        man_get "${mdfa_name}" "${mdfa_section}" "${mdfa_ext}";
        continue;
      else
        echo2 "No man page for ${mdfa_name} with section ${mdfa_filespec}.";
        continue;
      fi;
    fi;

### main_do_fileargs()
    echo2 "${mdfa_filespec} ${mdfa_errmsg}";
    continue;
  done;

  obj _TMP_STDIN rm_file_with_debug;
  eval ${_UNSET} mdfa_filespec;
  eval ${_UNSET} mdfa_i;
  eval ${_UNSET} mdfa_name;
  eval ${_UNSET} mdfa_names;
  eval "${return_ok}";
} # main_do_fileargs()


########################################################################
# main_set_resources ()
#
# Determine options for setting X resources with $_DISPLAY_PROG.
#
# Globals: $_DISPLAY_PROG, $_OUTPUT_FILE_NAME
#
# Variable prefix: msr
#
main_set_resources()
{
  func_check main_set_resources = 0 "$@";
  # $msr_prog   viewer program
  # $msr_rl     resource list
  for f in ${_TMP_DIR}/,man*
  do
    rm_file_with_debug $f;
  done;
  obj_from_output msr_title \
    get_first_essential "${_OPT_TITLE}" "${_REG_TITLE_LIST}";
  _OUTPUT_FILE_NAME='';
  eval set x "${msr_title}";
  shift;
  until is_equal "$#" 0
  do
    msr_n="$1";
    case "${msr_n}" in
    '')
      continue;
      ;;
    ,*)
      msr_n="$(echo1 "$1" | sed 's/^,,*//')";
      exit_test;
      ;;
    esac;
    if obj msr_n is_empty
    then
      continue;
    fi;
    if obj _OUTPUT_FILE_NAME is_not_empty
    then
      _OUTPUT_FILE_NAME="${_OUTPUT_FILE_NAME}"',';
    fi;
    _OUTPUT_FILE_NAME="${_OUTPUT_FILE_NAME}${msr_n}";
    shift;
  done; # until $# is 0
### main_set_resources()

  case "${_OUTPUT_FILE_NAME}" in
  '')
    _OUTPUT_FILE_NAME='-';
    ;;
  ,*)
    error "main_set_resources(): ${_OUTPUT_FILE_NAME} starts with a comma.";
    ;;
  esac;
  _OUTPUT_FILE_NAME="${_TMP_DIR}/${_OUTPUT_FILE_NAME}";

  if obj _DISPLAY_PROG is_empty
  then				# for example, for groff mode
    _DISPLAY_ARGS='';
    eval ${_UNSET} msr_n;
    eval ${_UNSET} msr_prog;
    eval ${_UNSET} msr_rl;
    eval ${_UNSET} msr_title;
    eval "${return_ok}";
  fi;

  eval set x "${_DISPLAY_PROG}";
  shift;
  obj_from_output msr_prog base_name "$1";
  shift;
  if is_greater_than $# 0
  then
    if obj _DISPLAY_ARGS is_empty
    then
      _DISPLAY_ARGS="$*";
    else
      _DISPLAY_ARGS="$* ${_DISPLAY_ARGS}";
    fi;
  fi;
### main_set_resources()
  msr_rl='';
  if obj _OPT_BD is_not_empty
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-bd' "${_OPT_BD}";
      ;;
    esac;
  fi;
  if obj _OPT_BG is_not_empty
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-bg' "${_OPT_BG}";
      ;;
    kghostview)
      list_append msr_rl '--bg' "${_OPT_BG}";
      ;;
    xpdf)
      list_append msr_rl '-papercolor' "${_OPT_BG}";
      ;;
    esac;
  fi;
  if obj _OPT_BW is_not_empty
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      _list_append msr_rl '-bw' "${_OPT_BW}";
      ;;
    esac;
  fi;
### main_set_resources()
  if obj _OPT_FG is_not_empty
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-fg' "${_OPT_FG}";
      ;;
    kghostview)
      list_append msr_rl '--fg' "${_OPT_FG}";
      ;;
    esac;
  fi;
  if is_not_empty "${_OPT_FN}"
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-fn' "${_OPT_FN}";
      ;;
    kghostview)
      list_append msr_rl '--fn' "${_OPT_FN}";
      ;;
    esac;
  fi;
  if is_not_empty "${_OPT_GEOMETRY}"
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi|xpdf)
      list_append msr_rl '-geometry' "${_OPT_GEOMETRY}";
      ;;
    kghostview)
      list_append msr_rl '--geometry' "${_OPT_GEOMETRY}";
      ;;
    esac;
  fi;
### main_set_resources()
  if is_empty "${_OPT_RESOLUTION}"
  then
    _OPT_RESOLUTION="${_DEFAULT_RESOLUTION}";
    case "${msr_prog}" in
    gxditview|xditview)
      list_append msr_rl '-resolution' "${_DEFAULT_RESOLUTION}";
      ;;
    xpdf)
      case "${_DISPLAY_PROG}" in
      *-z*)
        :;
        ;;
      *)			# if xpdf does not have option -z
        case "${_DEFAULT_RESOLUTION}" in
        75)
          # 72dpi is '100'
          list_append msr_rl '-z' '104';
          ;;
        100)
          list_append msr_rl '-z' '139';
          ;;
        esac;
        ;;
      esac;
      ;;
    esac;
  else
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-resolution' "${_OPT_RESOLUTION}";
      ;;
    xpdf)
      case "${_DISPLAY_PROG}" in
      *-z*)
        :;
        ;;
      *)			# if xpdf does not have option -z
        case "${_OPT_RESOLUTION}" in
        75)
          list_append msr_rl '-z' '104';
          # '100' corresponds to 72dpi
          ;;
### main_set_resources()
        100)
          list_append msr_rl '-z' '139';
          ;;
        esac;
        ;;
      esac;
      ;;
    esac;
  fi;
  if is_yes "${_OPT_ICONIC}"
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-iconic';
      ;;
    esac;
  fi;
  if is_yes "${_OPT_RV}"
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi)
      list_append msr_rl '-rv';
      ;;
    esac;
  fi;
  if is_not_empty "${_OPT_XRM}"
  then
    case "${msr_prog}" in
    ghostview|gv|gxditview|xditview|xdvi|xpdf)
      eval set x "${_OPT_XRM}";
      shift;
      for i
      do
        list_append msr_rl '-xrm' "$i";
      done;
### main_set_resources()
      ;;
    esac;
  fi;
  if is_not_empty "${msr_title}"
  then
    case "${msr_prog}" in
    gxditview|xditview)
      list_append msr_rl '-title' "${msr_title}";
      ;;
    esac;
  fi;
  if obj _DISPLAY_ARGS is_empty
  then
    _DISPLAY_ARGS="${msr_rl}";
  else
    _DISPLAY_ARGS="${msr_l} ${_DISPLAY_ARGS}";
  fi;
  eval ${_UNSET} msr_n;
  eval ${_UNSET} msr_prog;
  eval ${_UNSET} msr_rl;
  eval ${_UNSET} msr_title;
  eval "${return_ok}";
} # main_set_resources


########################################################################
# main_display ()
#
# Do the actual display of the whole thing.
#
# Globals:
#   in: $_DISPLAY_MODE, $_OPT_DEVICE, $_ADDOPTS_GROFF,
#       $_TMP_CAT, $_OPT_PAGER, $_MANOPT_PAGER, $_OUTPUT_FILE_NAME
#
# Variable prefix: md
#
main_display()
{
  func_check main_display = 0 "$@";

  export md_addopts;
  export md_groggy;
  export md_modefile;

  if obj _TMP_CAT is_empty_file
  then
    echo2 'groffer: empty input.';
    clean_up;
    eval "${return_ok}";
  fi;

  md_modefile="${_OUTPUT_FILE_NAME}";

  # go to the temporary directory to be able to access internal data files
  cd "${_TMP_DIR}" >"${_NULL_DEV}" 2>&1;

  case "${_DISPLAY_MODE}" in
  groff)
    if obj _OPT_DEVICE is_not_empty
    then
      _ADDOPTS_GROFF="${_ADDOPTS_GROFF} -T${_OPT_DEVICE}";
    fi;
    md_groggy="$(tmp_cat | eval grog)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_opt_V;

### main_display()
    obj md_modefile rm_file;
    mv "${_TMP_CAT}" "${md_modefile}";
    trap_unset;
    cat "${md_modefile}" | \
    {
      trap_set;
      eval "${md_groggy}" "${_ADDOPTS_GROFF}";
    } &
    ;;
  text|tty)
    case "${_OPT_DEVICE}" in
    '')
      obj_from_output md_device \
        get_first_essential "${_OPT_TEXT_DEVICE}" "${_DEFAULT_TTY_DEVICE}";
      ;;
    ascii|cp1047|latin1|utf8)
      md_device="${_OPT_DEVICE}";
      ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}";
      ;;
    esac;
    md_addopts="${_ADDOPTS_GROFF}";
    md_groggy="$(tmp_cat | grog -T${md_device})";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    if obj _DISPLAY_MODE is_equal 'text'
    then
      _do_opt_V;
      tmp_cat | eval "${md_groggy}" "${md_addopts}";
    else			# $_DISPLAY_MODE is 'tty'
### main_display()
      md_pager='';
      for p in "${_OPT_PAGER}" "${_MANOPT_PAGER}" "${PAGER}"
      do
        if obj p is_empty
        then
          continue;
        fi;
        obj_from_output md_pager where_is_prog "$p";
        if is_not_equal "$?" 0 || obj md_pager is_empty
        then
          md_pager='';
          continue;
        fi;
        eval set x $md_pager;
        shift;
        case "$1" in
        */less)
          if is_empty "$2"
          then
            md_pager="$1"' -r -R';
          else
            md_pager="$1"' -r -R '"$2";
          fi;
          ;;
### main_display()
        *)
          if is_empty "$2"
          then
            md_pager="$1";
          else
            md_pager="$1 $2";
          fi;
          ;;
        esac;
        break;
      done;
      if obj md_pager is_empty
      then
        eval set x ${_VIEWER_TTY_TTY} ${_VIEWER_TTY_X} 'cat';
        shift;
        # that is: 'less -r -R' 'more' 'pager' 'xless' 'cat'
        for p
        do
          if obj p is_empty
          then
            continue;
          fi;
          md_p="$p";
          if is_prog "${md_p}"
          then
            md_pager="${md_p}";
            break;
          fi;
        done;
      fi;
### main_display()
      if obj md_pager is_empty
      then
        error 'main_display(): no pager program found for tty mode';
      fi;
      _do_opt_V;
      tmp_cat | eval "${md_groggy}" "${md_addopts}" | \
                eval "${md_pager}";
    fi;				# $_DISPLAY_MODE
    clean_up;
    ;;				# text|tty)
  source)
    tmp_cat;
    clean_up;
    ;;

  #### viewer modes

### main_display()
  dvi)
    case "${_OPT_DEVICE}" in
    ''|dvi) do_nothing; ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}"
      ;;
    esac;
    md_modefile="${md_modefile}".dvi;
    md_groggy="$(tmp_cat | grog -Tdvi)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_display;
    ;;
  html)
    case "${_OPT_DEVICE}" in
    ''|html) do_nothing; ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}";
      ;;
    esac;
    md_modefile="${md_modefile}".html;
    md_groggy="$(tmp_cat | grog -Thtml)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_display;
    ;;
### main_display()
  pdf)
    case "${_OPT_DEVICE}" in
    ''|ps)
      do_nothing;
      ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}";
      ;;
    esac;
    md_groggy="$(tmp_cat | grog -Tps)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_display _make_pdf;
    ;;
  ps)
    case "${_OPT_DEVICE}" in
    ''|ps)
      do_nothing;
      ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}";
      ;;
    esac;
    md_modefile="${md_modefile}".ps;
    md_groggy="$(tmp_cat | grog -Tps)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_display;
    ;;
### main_display()
  x)
    case "${_OPT_DEVICE}" in
    X*)
      md_device="${_OPT_DEVICE}"
      ;;
    *)
      case "${_OPT_RESOLUTION}" in
      100)
        md_device='X100';
        if obj _OPT_GEOMETRY is_empty
        then
          case "${_DISPLAY_PROG}" in
          gxditview|xditview)
            # add width of 800dpi for resolution of 100dpi to the args
            list_append _DISPLAY_ARGS '-geometry' '800';
            ;;
          esac;
        fi;
        ;;
      *)
        md_device='X75-12';
        ;;
      esac
    esac;
    md_groggy="$(tmp_cat | grog -T${md_device} -Z)";
    if is_not_equal "$?" 0
    then
      exit "${_ERROR}";
    fi;
    echo2 "grog output: ${md_groggy}";
    exit_test;
    _do_display;
    ;;
### main_display()
  X)
    case "${_OPT_DEVICE}" in
    '')
      md_groggy="$(tmp_cat | grog -X)";
      if is_not_equal "$?" 0
      then
        exit "${_ERROR}";
      fi;
      echo2 "grog output: ${md_groggy}";
      exit_test;
      ;;
    X*|dvi|html|lbp|lj4|ps)
      # these devices work with
      md_groggy="$(tmp_cat | grog -T"${_OPT_DEVICE}" -X)";
      if is_not_equal "$?" 0
      then
        exit "${_ERROR}";
      fi;
      echo2 "grog output: ${md_groggy}";
      exit_test;
      ;;
    *)
      warning "main_display(): \
wrong device for ${_DISPLAY_MODE} mode: ${_OPT_DEVICE}";
      md_groggy="$(tmp_cat | grog -Z)";
      if is_not_equal "$?" 0
      then
        exit "${_ERROR}";
      fi;
      echo2 "grog output: ${md_groggy}";
      exit_test;
      ;;
    esac;
    _do_display;
    ;;
  *)
    error "main_display(): unknown mode \`${_DISPLAY_MODE}'";
    ;;
  esac;
  eval ${_UNSET} md_addopts;
  eval ${_UNSET} md_device;
  eval ${_UNSET} md_groggy;
  eval ${_UNSET} md_modefile;
  eval ${_UNSET} md_p;
  eval ${_UNSET} md_pager;
  eval "${return_ok}";
} # main_display()


########################
# _do_display ([<prog>])
#
# Perform the generation of the output and view the result.  If an
# argument is given interpret it as a function name that is called in
# the midst (actually only for `pdf').
#
# Globals: $md_modefile, $md_groggy (from main_display())
#
_do_display()
{
  func_check _do_display '>=' 0 "$@";
  _do_opt_V;
  if obj _DISPLAY_PROG is_empty
  then
    trap_unset;
    {
      trap_set;
      eval "${md_groggy}" "${_ADDOPTS_GROFF}" "${_TMP_CAT}";
    } &
  else
    obj md_modefile rm_file;
    cat "${_TMP_CAT}" | \
      eval "${md_groggy}" "${_ADDOPTS_GROFF}" > "${md_modefile}";
    if obj md_modefile is_empty_file
    then
      echo2 '_do_display(): empty output.';
      clean_up;
      exit;
    fi;
    if is_not_empty "$1"
    then
      eval "$1";
    fi;
### _do_display() of main_display()
    obj _TMP_CAT rm_file_with_debug;
    if obj _OPT_STDOUT is_yes
    then
      cat "${md_modefile}";
      clean_up;
      exit;
    fi;
    if obj _VIEWER_BACKGROUND is_not_yes # for programs that run on tty
    then
      eval "'${_DISPLAY_PROG}'" ${_DISPLAY_ARGS} "\"${md_modefile}\"";
    else
      trap_unset;
      {
        trap_set;
        eval "${_DISPLAY_PROG}" ${_DISPLAY_ARGS} "\"${md_modefile}\"";
      } &
    fi;
  fi;
  eval "${return_ok}";
} # _do_display() of main_display()


#############
# _do_opt_V ()
#
# Check on option `-V'; if set print the corresponding output and leave.
#
# Globals: $_ALL_PARAMS, $_ADDOPTS_GROFF, $_DISPLAY_MODE, $_DISPLAY_PROG,
#          $_DISPLAY_ARGS, $md_groggy,  $md_modefile
#
# Variable prefix: _doV
#
_do_opt_V()
{
  func_check _do_opt_V '=' 0 "$@";
  if obj _OPT_V is_yes
  then
    _OPT_V='no';
    echo1 "Parameters:     ${_ALL_PARAMS}";
    echo1 "Display mode:   ${_DISPLAY_MODE}";
    echo1 "Output file:    ${md_modefile}";
    echo1 "Display prog:   ${_DISPLAY_PROG} ${_DISPLAY_ARGS}";
    a="$(eval echo1 "'${_ADDOPTS_GROFF}'")";
    exit_test;
    echo1 "Output of grog: ${md_groggy} $a";
    _doV_res="$(eval "${md_groggy}" "${_ADDOPTS_GROFF}")";
    exit_test;
    echo1 "groff -V:       ${_doV_res}"
    leave;
  fi;
  eval "${return_ok}";
} # _do_opt_V() of main_display()


##############
# _make_pdf ()
#
# Transform to pdf format; for pdf mode in _do_display().
#
# Globals: $md_modefile (from main_display())
#
# Variable prefix: _mp
#
_make_pdf()
{
  func_check _make_pdf '=' 0 "$@";
  _mp_psfile="${md_modefile}";
  md_modefile="${md_modefile}.pdf";
  obj md_modefile rm_file;
  if obj _PDF_HAS_PS2PDF is_yes && ps2pdf "${_mp_psfile}" "${md_modefile}";
  then
    :;
  elif obj _PDF_HAS_GS is_yes && gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
       -sOutputFile="${md_modefile}" -c save pop -f "${_mp_psfile}";
  then
    :;
  else
    _PDF_DID_NOT_WORK='yes';
    echo2 '_make_pdf(): Could not transform into pdf format. '\
'The Postscript mode (ps) is used instead.';
    _OPT_MODE='ps';
    main_set_mode;
    main_set_resources;
    main_display;
    exit;
  fi;
  obj _mp_psfile rm_file_with_debug;
  eval ${_UNSET} _mp_psfile;
  eval "${return_ok}";
} # _make_pdf() of main_display()


########################################################################
# main (<command_line_args>*)
#
# The main function for groffer.
#
# Arguments:
#
main()
{
  func_check main '>=' 0 "$@";
  # Do not change the sequence of the following functions!
  landmark '13: main_init()';
  main_init;
  landmark '14: main_parse_MANOPT()';
  main_parse_MANOPT;
  landmark '15: main_parse_args()';
  main_parse_args "$@";
  landmark '16: main_set_mode()';
  main_set_mode;
  landmark '17: main_do_fileargs()';
  main_do_fileargs;
  landmark '18: main_set_resources()';
  main_set_resources;
  landmark '19: main_display()';
  main_display;
  eval "${return_ok}";
}


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

main "$@";