aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/sysenv.rb
blob: d4079f8caf4a9c1664a5329023debdcdf20d0c69 (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
# encoding: utf-8
=begin

 * Name: SiSU

 * Description: a framework for document structuring, publishing and search

 * Author: Ralph Amissah

 * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
   2007, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved.

 * License: GPL 3 or later:

   SiSU, a framework for document structuring, publishing and search

   Copyright (C) Ralph Amissah

   This program 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 3 of the License, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
   more details.

   You should have received a copy of the GNU General Public License along with
   this program. If not, see <http://www.gnu.org/licenses/>.

   If you have Internet connection, the latest version of the GPL should be
   available at these locations:
   <http://www.fsf.org/licensing/licenses/gpl.html>
   <http://www.gnu.org/licenses/gpl.html>

   <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>

 * SiSU uses:
   * Standard SiSU markup syntax,
   * Standard SiSU meta-markup syntax, and the
   * Standard SiSU object citation numbering and system

 * Hompages:
   <http://www.jus.uio.no/sisu>
   <http://www.sisudoc.org>

 * Download:
   <http://www.sisudoc.org/sisu/en/SiSU/download.html>

 * Git
   <http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
   <http://sources.sisudoc.org/?p=code/sisu.git;a=blob;f=lib/sisu/v5/sysenv.rb;hb=HEAD>

 * Ralph Amissah
   <ralph@amissah.com>
   <ralph.amissah@gmail.com>

 ** Description: system environment, resource control and configuration details

=end
@@cX=nil
@@current_document=Dir.pwd #nil #''
@@lang_info=nil
module SiSU_Env
  require_relative 'constants'                             # constants.rb
  require_relative 'utils'                                 # utils.rb
  require 'fileutils'
    include FileUtils::Verbose
  require 'singleton'
  @@noyaml=false
  class InfoDate
    require 'date'
    attr_accessor :dt,:t
    def initialize
      @dt,@t=Date.today.to_s,Time.now
    end
    def week
      w=@t.strftime('%W')
      "#{@t.year}w#{w}"
    end
    def month
      "#{@t.year}#{@t.month}"
    end
    def year
      @t.year
    end
    def weekonly
      @t.strftime('%W')
    end
    def monthonly
      @t.month
    end
    def year_static
      YEAR
    end
  end
  class InfoSystemGen
    require 'rbconfig'
    @@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@rc,@@sisurc_path,@@ad=ENV['USER'],ENV['HOME'],ENV['HOSTNAME'],ENV['PWD'],Config::CONFIG['sysconfdir'] + '/sisu',Config::CONFIG['host'],Config::CONFIG['arch'],%x{ruby -v}.strip,Config::CONFIG['archdir'],Config::CONFIG['sitearchdir'],Config::CONFIG['bindir'],%x{locale charmap}.strip,nil,nil,{} # %x{ruby -v}.strip # Config::CONFIG['rb_ver']
    out=Config::CONFIG['localstatedir']
    etc=Config::CONFIG['sysconfdir'] + '/sisu'
    share=Config::CONFIG['datadir'] + '/sisu'
    data=Config::CONFIG['datadir'] + '/doc/sisu'
    m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
    @stub_pwd ||=@@pwd[m,1]
    prcss_dir='_sisu_processing_' + '.' + SiSU_version_dir
    prcss_dir_tmp_root="/tmp/#{prcss_dir}"
    prcss_dir_stub="#{prcss_dir}/#{@stub_pwd}"
    if @@user
      tmp_processing="#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
      tmp_processing_individual="#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
    else #error
      tmp_processing=tmp_processing_individual="/tmp/#{prcss_dir_stub}"
    end
    processing_pth=tmp_processing_individual
    processing_dir=prcss_dir
    processing_git="#{Dir.pwd}/#{Gt[:grotto]}"
    user=ENV['USER']
    port_pgsql=if defined? ENV['PGPORT'] \
    and not (ENV['PGPORT'].nil? \
    || ENV['PGPORT'].empty?) \
    and ENV['PGPORT']=~/^\d+$/
      ENV['PGPORT']
    else '5432'
    end
    IMAGES=:images
    SISU_ETC=:sisu_etc
    SISU_SHARE=:sisu_share
    SAMPLE_DATA_PATH=:sample_data_path
    IMAGE_STUB=:image_stub
    STYLESHEET_STUB=:stylesheet_stub
    IMAGE_LOCAL=:image_local
    WEBSERV_PATH=:webserv_path
    WEBSERV_MAN=:webserv_man
    WEBSERV_PHP=:webserv_php
    WEBSERV_CGI=:webserv_cgi
    WEBSERV_RSS=:webserv_rss
    WEBSERV_SQLITE=:webserv_sqlite
    OUTPUT_LOCAL=:output_local
    PROCESSING_DIR=:processing_dir
    PROCESSING_PATH=:processing_path
    PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root
    PROCESSING_PATH_TMP_BASE=:processing_path_tmp_base
    PROCESSING_DAL=:processing_dal
    PROCESSING_TUNE=:processing_tune
    PROCESSING_LATEX=:processing_latex
    PROCESSING_TEXINFO=:processing_texinfo
    PROCESSING_LOUT=:processing_lout
    PROCESSING_SQLITE=:processing_sqlite
    PROCESSING_POSTGRESQL=:processing_postgresql
    PROCESSING_ENCODING=:processing_encoding
    PROCESSING_GIT=:processing_git
    PAPERSIZE=:papersize
    #LANGUAGE=:language
    #LANGUAGE_CODE=:language_code
    MULTILINGUAL=:multilingual
    BUNDLE=:bundle
    CONCORD_MAX=:concord_max
    DIGEST=:digest
    WEBSERV_HOST_CGI=:webserv_host_cgi
    WEBSERV_PORT_CGI=:webserv_port_cgi
    POSTGRESQL_USER=:postgresql_user
    POSTGRESQL_PORT=:postgresql_port
    SQLITE_USER=:sqlite_user
    SQLITE_PATH=:sqlite_path
    SQLITE_PORT=:sqlite_port
    DEFAULT_DIR={
      IMAGES =>                   '_sisu/image',
      SISU_ETC =>                 etc,
      SISU_SHARE =>               share,
      SAMPLE_DATA_PATH =>         data,
      IMAGE_STUB =>               '_sisu/image',
      STYLESHEET_STUB =>          '_sisu/css',
      IMAGE_LOCAL =>              @@pwd + '/_sisu/image',
      WEBSERV_PATH =>             out + '/www',
      #WEBSERV_DIR =>             www, # uncomment for urls...
      #WEBSERV_IMAGE =>            out + '/www/_sisu/image',
      WEBSERV_MAN =>              out + '/www/man', #alter
      WEBSERV_PHP =>              out + '/www/php',
      WEBSERV_CGI =>              '/usr/lib/cgi-bin',
      WEBSERV_RSS =>              out + '/www/feed',
      WEBSERV_SQLITE =>           out + '/www/sqlite',
      OUTPUT_LOCAL =>             @@home + '/sisu_www',
      PROCESSING_DIR =>           processing_dir,
      PROCESSING_PATH =>          processing_pth,
      PROCESSING_DIR_TMP_ROOT  => prcss_dir_tmp_root,
      PROCESSING_PATH_TMP_BASE => processing_pth,
      PROCESSING_DAL =>           'dal',
      PROCESSING_TUNE =>          'tune',
      PROCESSING_LATEX =>         'tex',
      PROCESSING_TEXINFO =>       'texinfo',
      PROCESSING_SQLITE =>        'sqlite',
      PROCESSING_POSTGRESQL=>     'postgresql',
      PROCESSING_ENCODING =>      'encoding',
      PROCESSING_GIT =>           processing_git,
      #TEXINFO_STUB =>             'texinfo',
      PAPERSIZE =>                'A4', #A4, US_letter, book_b5, book_a5, US_legal
      #LANGUAGE =>                 'English',
      #LANGUAGE_CODE =>            'en', #change, unecessary duplication though currently used
      MULTILINGUAL =>             false,
      BUNDLE =>                   false,
      CONCORD_MAX =>              260000,
      DIGEST =>                   'sha256',
      WEBSERV_HOST_CGI =>     '   http://localhost',
      WEBSERV_PORT_CGI =>         8081, #8111,8123,8081
      POSTGRESQL_USER =>          @@user, #'ralph', # change user !!!
      POSTGRESQL_PORT =>          port_pgsql,
      #POSGRESQL_LINKS_PATH =>    '',
      SQLITE_USER =>              @@user,
      SQLITE_PATH =>              @@user, #??
      SQLITE_PORT =>              '**',
    }
    @@default_dir=DEFAULT_DIR
    m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
    @@pwd=@pwd=SiSU_Utils::Path.new.base_markup
    attr_accessor :user,:home,:hostname,:pwd,:host,:arch,:rbver,:dir_arch,:dir_sitearch,:dir_bin,:locale,:webserv_path,:webserv_host_cgi,:webserv_port_cgi,:default_dir,:rc_path,:ad_path
    def initialize
      @user,@home,@hostname,@pwd,@sisu_etc,@host,@arch,@rbver,@dir_arch,@dir_sitearch,@dir_bin,@locale,@default_dir=\
      @@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@default_dir
      #note rbver is duplicated in InfoVersion
    end
  end
  class InfoSystem < InfoSystemGen
    include Singleton
    def initialize
      super()
    end
  end
  class Load
    def initialize(prog,mandatory=false)
      @prog,@mandatory=prog,mandatory
    end
    def prog
      load_prog=false
      $:.each do |reqpath|
        if FileTest.exist?("#{reqpath}/#{@prog}.rb")
          load_prog=true
          break
        end
      end
      if load_prog \
      and @prog=~/dbi/
        require 'dbi' #revisit
      end
      if load_prog
        require @prog
      else
        @mandatory \
        ? (SiSU_Screen::Ansi.new(@prog,"*WARN* module required: #{@prog}").warn)
        : '' #(SiSU_Screen::Ansi.new(@prog,"*WARN* #{@prog} load requested").warn)
      end
      load_prog
    end
    def prog?
      load_prog=false
      $:.each do |reqpath|
        if FileTest.exist?("#{reqpath}/#{@prog}.rb"); load_prog=true
          break
        end
      end
      load_prog
    end
  end
  class GetInit < InfoSystemGen
    @@noyaml=false
    @@rc,@@sisu_doc_makefile,@@sisurc_path,@@tx=nil,nil,nil,nil
    @@ad={ promo: nil, promo_list: nil, flag_promo: false }
    @@sdmd=nil
    attr_accessor :yaml
    def initialize
      super()
        @markup_dir_changed_=if @@sdmd==$sisu_document_markup_directory
          false
        else
          @@sdmd=$sisu_document_markup_directory
          true
        end
    end
    def tex
      @@tx ||=SiSU_Viz::TeX.new
    end
    def rc_path_options
      [
        "#{$sisu_document_markup_directory_base_fixed_path}/.sisu/#{SiSU_version_dir}",
        "#{$sisu_document_markup_directory_base_fixed_path}/.sisu",
        "#{$sisu_document_markup_directory_base_fixed_path}/_sisu/#{SiSU_version_dir}",
        "#{$sisu_document_markup_directory_base_fixed_path}/_sisu",
        "#{@@home}/.sisu/#{SiSU_version_dir}",
        "#{@@home}/.sisu",
        "#{@@sisu_etc}/#{SiSU_version_dir}",
        "#{@@sisu_etc}",
      ]
    end
    def sisu_document_make
      def makefile_name
        S_CONF[:header_make]
      end
      def makefile
        rc_path_options.each do |v|
          if FileTest.exist?("#{v}/#{makefile_name}")
            @sisu_make_path=v
            break
          end
        end
        @sisu_make_file_path=@sisu_make_path \
        ? "#{@sisu_make_path}/#{makefile_name}"
        : nil
      end
      def makefile_read
        if makefile
          sisu_doc_makefile=IO.read(makefile, mode: 'r:utf-8')
          @sisu_doc_makefile=sisu_doc_makefile.split(/\s*\n\s*\n/m)
        end
        @sisu_doc_makefile
      end
      self
    end
    def sisu_yaml
      def rc
        if @markup_dir_changed_
          rc_path_options.each do |v|
            if @@noyaml \
            or FileTest.exist?("#{v}/noyaml")
              STDERR.puts "WARNING - YAML loading switched off, to enable delete the file:\n\t#{v}/noyaml\n\n" unless @@noyaml
              @@noyaml=true
              break
            else
              f=S_CONF[:rc_yml]
              p_f="#{v}/#{f}"
              if FileTest.exist?(p_f)
                require 'yaml'
                @@sisurc_path=v
                @@rc=YAML::load(File::open(p_f))
                break
              end
              unless @@rc
                f='sisurc.yaml'
                p_f="#{v}/#{f}"
                if FileTest.exist?(p_f)
                  require 'yaml'
                  @@sisurc_path=v
                  @@rc=YAML::load(File::open(p_f))
                  break
                end
              end
            end
          end
        end
        @@rc
      end
      def rc_path
        rc
        @@sisurc_path
      end
      self
    end
    def ads #WORK AREA
      tell_no_yaml='WARNING - YAML loading switched off, to enable delete the file:'
      if @markup_dir_changed_
        @ad_path=[
          "#{$sisu_document_markup_directory_base_fixed_path}/.sisu/#{SiSU_version_dir}/skin/yml",
          "#{$sisu_document_markup_directory_base_fixed_path}/.sisu/skin/yml",
          "#{$sisu_document_markup_directory_base_fixed_path}/_sisu/#{SiSU_version_dir}/skin/yml",
          "#{$sisu_document_markup_directory_base_fixed_path}/_sisu/skin/yml",
          "#{@@home}/.sisu/#{SiSU_version_dir}/skin/yml",
          "#{@@home}/.sisu/skin/yml",
          "#{@@sisu_etc}/#{SiSU_version_dir}/skin/yml",
          "#{@@sisu_etc}/skin/yml",
        ]
        @ad_path.each do |v|
          if @@noyaml \
          or FileTest.exist?("#{v}/noyaml")
            puts tell_no_yaml + "\n\t#{v}/noyaml\n" unless @@noyaml
            @@noyaml=true
            break
          else
            if FileTest.exist?("#{v}/list.yml")
              unless @@ad[:promo_list]
                require 'yaml'
                @@ad[:promo_list] ||= YAML::load(File::open("#{v}/list.yml"))
              end
              @@ad[:flag_promo]=true
              break
            end
            @@ad[:flag_promo]=false
          end
        end
        @ad_path.each do |v|
          if @@noyaml \
          or FileTest.exist?("#{v}/noyaml")
            puts tell_no_yaml + "\n\t#{v}/noyaml\n" unless @@noyaml
            @@noyaml=true
            break
          else
            if FileTest.exist?("#{v}/promo.yml")
              unless @@ad[:promo]
                require 'yaml'
                @@ad[:promo] ||= YAML::load(File::open("#{v}/promo.yml"))
              end
              @@ad[:flag_promo]=true
              break
            end
            @@ad[:flag_promo]=false
          end
        end
      end
      @@ad
    end
  end
  class EnvCall
    @@rc,@@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=nil,nil,nil,nil,nil,nil,nil
    @@ad={}
    attr_accessor :rc,:fnn,:fnb,:fnt,:fnv,:fnz,:ad
    def initialize(fns='')
      @fns=fns
      @sys=InfoSystem.instance
      get_init=SiSU_Env::GetInit.new
      @rc=get_init.sisu_yaml.rc
      @ad=get_init.ads
      if @fns \
      and @fns != '' \
      and @fns !=@@fns
        @@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=@fns,nil,nil,nil,nil,nil
      end
      if @fns \
      and @fns != '' #watch
        m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/
        @@fnn ||=@fns[m,1]
        @@fnb ||=@fns[m,2]
        @@fnt ||=@fns[m,3]
        @@flv ||=document_language_versions_found[:f]
        unless @@fns =~/\S+?\.txz/
          @@fnz ||=if @@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; @@fnb + '.ssm.txz'
          elsif @@fnb; @@fnb + '.sst.txz'
          else '' # e.g. termsheet
          end
        end
      end
      @fnn,@fnb,@fnt,@flv,@fnz=@@fnn,@@fnb,@@fnt,@@flv,@@fnz
    end
    def default_language?
      if @rc \
      && defined? @rc['language_default']
        if (@rc['language_default'].is_a?(String)) \
        && (@rc['language_default'] =~/#{Px[:lng_lst_rgx]}/)
          @rc['language_default']
        else 'en'
        end
      else 'en'
      end
    end
    def mono_multi_lingual?
      if @rc \
      && defined? @rc['lingual']
        if (@rc['lingual'].is_a?(String)) \
        && (@rc['lingual'] =~/mono(?:lingual)?/)
          :mono
        elsif  (@rc['lingual'].is_a?(String)) \
        && (@rc['lingual'] =~/multi(?:lingual)?/)
          :multi
        else :multi
        end
      else :multi
      end
    end
    def output_dir_structure
      def by?
        output_structure=:filename #set default output structure
        if @rc \
        && defined? @rc['output_dir_structure_by']
          output_structure=if (@rc['output_dir_structure_by'] =~/dump/) \
          or ((defined? @rc['output_structure']['dump']) \
          && @rc['output_structure']['dump'] ==true)
            :dump
          elsif (@rc['output_dir_structure_by'] =~/redirect/) \
          or ((defined? @rc['output_structure']['redirect']) \
          && @rc['output_structure']['redirect'] ==true)
            :redirect
          elsif (@rc['output_dir_structure_by'] =~/language/) \
          or ((defined? @rc['output_structure']['by_language']) \
          && @rc['output_structure']['by_language'] ==true)
            :language
          elsif (@rc['output_dir_structure_by'] =~/filetype/) \
          or ((defined? @rc['output_structure']['by_filetype']) \
          && @rc['output_structure']['by_filetype'] ==true)
            :filetype
          elsif (@rc['output_dir_structure_by'] =~/filename/) \
          or ((defined? @rc['output_structure']['by_filename']) \
          && @rc['output_structure']['by_filename'] ==true)
            :filename
          else #set default
            :language
          end
        else #set default
          :language
        end
      end
      def dump?
        ((by?) ==:dump) \
        ? true
        : false
      end
      def redirect?
        ((by?) ==:redirect) \
        ? true
        : false
      end
      def by_language_code?
        ((by?) ==:language) \
        ? true
        : false
      end
      def by_filetype?
        ((by?) ==:filetype) \
        ? true
        : false
      end
      def by_filename?
        ((by?) ==:filename) \
        ? true
        : false
      end
      def multilingual?
        by_language_code?
      end
      self
    end
    def document_language_versions_found #REVISIT
      @fn={}
      filename=(@fns =~/\.ssm\.sst$/) \
      ? @fns.gsub(/\.ssm\.sst$/,'.ssm')
      : @fns
      if filename.is_a?(String) \
      and not filename.empty?
        if output_dir_structure.by_language_code?
          m=/((.+?)(?:\~\w{2,3})?)\.(sst|ssm)$/
          @fn[:b],@fn[:m],@fn[:t]=filename[m,1],filename[m,2],filename[m,3]
        else m=/(.+?)\.(sst|ssm)$/
          @fn[:b]=@fn[:m]=filename[m,1]
          @fn[:t]=filename[m,2]
        end
      end
      lng_base=SiSU_Env::InfoEnv.new.language_default_set
      lang=SiSU_Env::StandardiseLanguage.new
      langs=lang.codes
      x=[]
      if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}")
        n=@fn[:m].gsub(/^.+?\//,'')
        n =n + '.' + @fn[:t]
        x << { f: "#{@fn[:m]}.#{@fn[:t]}", l: lng_base, n: n }
      end
      langs.each do |l|
        lng=SiSU_Env::StandardiseLanguage.new(l)
        if FileTest.file?("#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
          x << { f: "#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
        elsif FileTest.file?("#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
          x << { f: "#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
        end
        if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
          if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
            x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
          elsif FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
            x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
          end
        end
        if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
          if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
            x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
          elsif FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
            x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
          end
        end
      end
      @fn[:f]=x
      @fn
    end
    def published_manifests?(output_base)
      @fn={}
      @m=[]
      unless (@fns.nil? \
      or @fns.empty?)
        if output_dir_structure.by_language_code?
          m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst$)/
          @fn[:b],@fn[:m],@fn[:t]=@fns[m,1],@fns[m,2],@fns[m,3]
        else m=/(.+?)\.((?:-|ssm\.)?sst$)/
          @fn[:b]=@fn[:m]=@fns[m,1]
          @fn[:t]=@fns[m,2]
        end
      end
      lang=SiSU_Env::StandardiseLanguage.new
      langs=lang.codes
      x=[]
      if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}"); x << "#{@fn[:m]}.#{@fn[:t]}"
      end
      dir=SiSU_Env::InfoEnv.new(@fns)
      @m << { m: 'sisu_manifest.html', l: 'English' } #fix later, default language
      langs.each do |l|
        lng=SiSU_Env::StandardiseLanguage.new(l)
        fns_c="#{@fn[:m]}~#{lng.code}.#{@fn[:t]}"
        fns_l="#{@fn[:m]}~#{lng.name}.#{@fn[:t]}"
        if FileTest.file?(fns_c)
          fn_set_lang=SiSU_Env::StandardiseLanguage.new.file_to_language(fns_c) #reconsider file_to_language
          lng=fn_set_lang[:n]
          fn=SiSU_Env::EnvCall.new(fns_c).lang(fn_set_lang[:c])
          @m << { m: fn[:manifest], l: lng }
        elsif FileTest.file?(fns_l)
          fn_set_lang=SiSU_Env::StandardiseLanguage.new.file_to_language(fns_l) #reconsider file_to_language
          @fnl=dir.i18n.lang_filename(fn_set_lang[:c])
          fn=SiSU_Env::EnvCall.new(fns_l).lang(fn_set_lang[:c])
          @m << { m: fn[:manifest], l: lng }
        end
      end
      @m=@m.uniq
    end
    def filename(code,name,suffix)
      "#{name}#{suffix}"
    end
    def lang(code)
      {
        html:            filename(code,'','.html'),
        book_index:      filename(code,'book_index','.html'),
        concordance:     filename(code,'concordance','.html'),
        sax:             filename(code,'sax','.xml'),
        dom:             filename(code,'dom','.xml'),
        docbook:         filename(code,'docbook','.xml'),
        xhtml:           filename(code,'scroll','.xhtml'),
        pdf_l:           filename(code,'','.pdf'),
        pdf_p:           filename(code,'','.pdf'),
        pdf_l_a4:        filename(code,"a4",'.pdf'),
        pdf_p_a4:        filename(code,"a4",'.pdf'),
        pdf_l_a5:        filename(code,"a5",'.pdf'),
        pdf_p_a5:        filename(code,"a5",'.pdf'),
        pdf_l_b5:        filename(code,"b5",'.pdf'),
        pdf_p_b5:        filename(code,"b5",'.pdf'),
        pdf_l_letter:    filename(code,"letter",'.pdf'),
        pdf_p_letter:    filename(code,"letter",'.pdf'),
        pdf_l_legal:     filename(code,"legal",'.pdf'),
        pdf_p_legal:     filename(code,"legal",'.pdf'),
        toc:             filename(code,'toc','.html'),
        doc:             filename(code,fnb,'.html'),
        index:           filename(code,'index','.html'),
        po:              filename(code,@fns,'.po'),
        pot:             filename(code,@fns,'.pot'),
        odf:             filename(code,'','.odt'),
        epub:            filename(code,'','.epub'),
        plain:           filename(code,'','.txt'),
        qrcode:          filename(code,'','.jpg'),
        manpage:         filename(code,'','.1'),          #fix, section number
        wiki:            filename(code,'wiki','.txt'),
        digest:          filename(code,'digest','.txt'),
        metadata:        filename(code,'metadata','.html'), #chk
        manifest:        filename(code,'manifest','.html'),
        oai_pmh:         filename(code,'oai_pmh','.xml'),
        sitemap:         filename(code,'sitemap','.xml'),
        sitemap_touch:   filename(code,"sitemap_#{fnb}",'.xml'),
        sxs:             filename(code,fnb,'.sxs.xml'),
        sxd:             filename(code,fnb,'.sxd.xml'),
        sxn:             filename(code,fnb,'.sxn.xml'),
        sisupod:         filename(nil,@fnz,''),
        book_idx_html:   filename(code,'book_index','.html'),
        book_idx_epub:   filename(code,'book_index','.xhtml'),
        epub_concord:    filename(code,'concordance','.xhtml'),
      }
    end
  end
  class SystemCall
    @@locale_flag=false
    def initialize(input='',output='',opt_or_cmd='')
      @input,@output=input,output
      (opt_or_cmd.is_a?(SiSU_Commandline::Options)) \
      ? (@cmd,@opt=opt_or_cmd.cmd,opt_or_cmd)
      : (@cmd,@opt=opt_or_cmd,nil) #cmd.is_a?(String)
      @prog=SiSU_Env::InfoProgram.new
      @sys=InfoSystem.instance
    end
    def program_found?(program)
      found=`which #{program}` #`whereis #{program}`
      (found =~/bin\/#{program}\b/) ? true : false
    end
    def locale                                                                 #locales utf8 or other
      unless @@locale_flag
        @@locale_flag=true
      end
      @sys.locale
    end
    def file_encoding(filename,cmd='')                                         #file encoding
      program='file'
      fnsp=SiSU_Env::InfoEnv.new(filename).source_file_with_path
      if program_found?(program)
        encoding=%x{file -L #{fnsp}}.strip
        encoding=encoding.gsub(/#{fnsp}:(\s+|$)/,'')
        encoding=if encoding \
        and not encoding.empty?
          encoding
        else 'UTF-8 assumed, encoding undetermined'
        end
        puts encoding if cmd =~/[VM]/
        encoding
      else encoding='UTF-8 assumed, file encoding check program unavailable'
      end
    end
    def wc                                                                     #word count
      program='wc'
      if program_found?(program) \
      and locale !~/utf-?8/i
        true
      else
        program_ref="(not available)" unless program_found?(program)
        program_ref="(UTF-8)" if locale =~/utf-?8/i
        false
      end
    end
    def rcs                                                                    #rcs for document markup data
      program='rcs'
      program_ref="\n\t\tdocument version information requested"
      if program_found?(program); true
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def cvs                                                                    #cvs for document markup data
      program='cvs'
      program_ref="\n\t\tdocument version information requested"
      if program_found?(program); true
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def openssl                                                                #openssl for digests
      program='openssl'
      program_ref="\n\t\tused to generate requested source document identification digest"
      if program_found?(program); true
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def md5(filename)                                                          #md5 dgst
      program='openssl'
      program_ref="\n\t\tmd5 digest requested"
      if program_found?(program)
        pwd=Dir.pwd
        Dir.chdir(File.dirname(filename))
        dgst=%x{openssl dgst -md5 #{File.basename(filename)}}.strip #use file name without file path
        Dir.chdir(pwd)
        dgst.scan(/\S+/)
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def sha256(filename)                                                       #sha dgst
      program='openssl'
      program_ref="\n\t\tsha digest requested"
      if program_found?(program)
        pwd=Dir.pwd
        Dir.chdir(File.dirname(filename))
        dgst=%x{openssl dgst -sha256 #{File.basename(filename)}}.strip #use file name without file path
        Dir.chdir(pwd)
        dgst.scan(/\S+/)
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def psql                                                                   #psql
      program='psql'
      program_ref="\n\t\tpsql requested"
      if program_found?(program); true
      else STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def create_pg_db(dbname_stub=nil)                                          #createdb
      unless dbname_stub
        @pwd ||=Dir.pwd
        m=/.+\/(?:src\/)?(\S+)/im # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
        dbname_stub=@pwd[m,1]
      end
      program='createdb'
      db_name="#{Db[:name_prefix]}#{dbname_stub}"
      program_ref="\n\t\tcreatedb dbname #{db_name} #for postgresql database creation"
      (program_found?(program)) \
      ? system("#{program} #{dbname_name}")
      : (STDERR.puts "\t*WARN* #{program} is not available #{program_ref}")
    end
    def relaxng(cmd='')                                                        #trang - convert between different schema languages for XML
      program='trang'
      program_ref="\n\t\tsee <http://www.thaiopensource.com/relaxng/trang.html>"
      (program_found?(program)) \
      ? system("#{program} #{@input} #{@output}")
      : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" if cmd =~/V/)
    end
    def qrencode                                                               #qrcode - for generating QR code
      program='qrencode'
      program_ref="\n\t\tsee <http://megaui.net/fukuchi/works/qrencode/index.en.html>"
      found=(program_found?(program)) ? true : false
      found \
      ? (system(%{
          echo "#{@input}" | #{program} -s 3 -o #{@output}
        }))
      : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" if cmd =~/V/)
      #found
    end
    def imagemagick                                                            #imagemagick is a image manipulation program
      program='identify'
      #program_ref="\n\t\tsee <http://www.imagemagick.org/>"
      found=(program_found?(program)) ? true : false
      #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found
      found
    end
    def graphicksmagick                                                        #graphicsmagick is a image manipulation program
      program='gm'
      #program_ref="\n\t\tsee <http://www.graphicsmagick.org/>"
      found=(program_found?(program)) ? true : false
      #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found
      found
    end
    def well_formed?                                                           #tidy - check for well formed xml xhtml etc.
      program=@prog.tidy
      program_ref="\n\t\tsee <http://tidy.sourceforge.net/>"
      (program_found?(program)) \
      ? system("#{@prog.tidy} -xml #{@input} > #{@output}")
      : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}")
    end
    def tex2pdf_engine
      prog=['xetex','xelatex','pdflatex','pdfetex','pdftex']
      @pdfetex_flag=false
      @cmd ||=''
      @texpdf=nil
      prog.each do |program|
        if program_found?(program)
          @texpdf=program if program =~/xetex|xelatex|pdftex|pdflatex/
          @pdfetex_flag=true
          break
        end
      end
      if @pdfetex_flag==false
        @texpdf=prog.join(', ')
      end
      @texpdf
    end
    def latex2pdf(md,papersize='a4')                                           #convert from latex to pdf
      tell=if @cmd =~/[MV]/
        ''
      elsif @cmd =~/[v]/
        %q{2>&1 | grep -v ' WARNING '}
      else %q{2>&1 | grep -v '$'}
      end
      mode='batchmode' #mode='nonstopmode'
      program_ref="\n\t\tSee http://www.tug.org/applications/pdftex/\n\t\tOn Debian this is is included in tetex-extra"
      texpdf=tex2pdf_engine
      if @pdfetex_flag
        texpdf_cmd=case texpdf
        when /xetex/
          %{#{texpdf} -interaction=#{mode} -fmt=xelatex -papersize="#{papersize}" #{@input} #{tell}\n}
        when /xelatex/
          %{#{texpdf} -interaction=#{mode} -papersize="#{papersize}" #{@input} #{tell}\n}
        when /pdftex/
          "#{texpdf} -interaction=#{mode} -fmt=pdflatex #{@input} #{tell}\n"
        when /pdflatex/
          "#{texpdf} -interaction=#{mode} #{@input} #{tell}\n"
        end
        system(texpdf_cmd)
      else STDERR.puts "\t*WARN* none of the following programs are installed: #{program[0]}, #{program[1]}, #{program[2]} is installed. #{program_ref}"
      end
    end
    def makeinfo                                                               #texinfo
      program='makeinfo'
      options='' #'--force' #''
      program_ref="\n\t\tsee http://www.gnu.org/software/texinfo/"
      (program_found?(program)) \
      ? system("#{program} #{options} #{@input}\n")
      : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}")
    end
    def scp
      puts "scp -Cr #{@input} #{@output}" if @cmd =~/[vVM]/
      puts "scp disabled"
    end
    def rsync(action='',chdir=nil)
      program='rsync'
      if program_found?(program)
        vb=if @cmd =~/q/; 'q'
        elsif @cmd =~/v/; 'v'
        else              ''
        end
        cX=SiSU_Screen::Ansi.new(@cmd).cX
        msg=(@cmd =~/q/) ? '' : %{ && echo " #{cX.grey}OK: #{@input} -> #{@output}#{cX.off}"}
        amp=(@opt \
        && @opt.files.length > 1) \
        ? ''
        : ((@cmd =~/[vVM]/) ? '' : '&')
        rsync_cmd="rsync -az#{vb} #{action} #{@input} #{@output}"
        puts rsync_cmd if @cmd =~/[vVM]/
        dir_change,dir_return='',''
        if not chdir.nil? \
        && chdir != Dir.pwd
          dir_change=Dir.chdir(chdir)
          dir_return=Dir.pwd
        end
        dir_change #check
        system("
          #{rsync_cmd} #{msg} #{amp}
        ")
        dir_return
      else STDERR.puts "\t*WARN* #{program} not found"
      end
    end
    def rm
      if @cmd =~/^-Z[mMvVq]*$/;      FileUtils::rm_rf(@input)
      elsif @cmd =~/V/;              FileUtils::rm(@input)
      elsif @cmd !~/q/;              FileUtils::rm(@input)
      elsif @cmd =~/q/;              FileUtils::rm(@input)
      else                           STDERR.puts "\t*WARN* operation ignored"
      end
    end
  end
  class StandardiseLanguage
    require_relative 'i18n'                  # i18n.rb
    def initialize(l='')
      @language=(l.nil? || l.empty?) \
      ? SiSU_Env::InfoEnv.new.language_default_set
      : l
      @r=%{(?:#{Px[:lng_lst_rgx]})}
      @lang_info=SiSU_i18n::Languages.new
    end
    def lang_lst                              # from i18n
      @@lang_info ||=@lang_info.language.list
    end
    def lang(l='')                              # from i18n
      if l =~/^#{@r}$/
        @lang_info.language.list[l]
      elsif @language =~/^#{@r}$/
        @lang_info.language.list[@language]
      else nil
      end
    end
    def language
      lng={}
      case @language
      when /^am$|Amharic/i;                    d,c,l=false,lang_lst['am'][:c],    lang_lst['am'][:n]
      when /^bg$|Bulgarian/i;                  d,c,l=false,lang_lst['bg'][:c],    lang_lst['bg'][:n]
      when /^bn$|Bengali/i;                    d,c,l=false,lang_lst['bn'][:c],    lang_lst['bn'][:n]
      when /^br$|Breton/i;                     d,c,l=false,lang_lst['br'][:c],    lang_lst['br'][:n]
      when /^ca$|Catalan/i;                    d,c,l=false,lang_lst['ca'][:c],    lang_lst['ca'][:n]
      when /^cs$|Czech/i;                      d,c,l=false,lang_lst['cs'][:c],    lang_lst['cs'][:n]
      when /^cy$|Welsh/i;                      d,c,l=false,lang_lst['cy'][:c],    lang_lst['cy'][:n]
      when /^da$|Danish|Dansk/i;               d,c,l=false,lang_lst['da'][:c],    lang_lst['da'][:n]
      when /^de$|German/i;                     d,c,l=false,lang_lst['de'][:c],    lang_lst['de'][:n]
      when /^el$|Greek/i;                      d,c,l=false,lang_lst['el'][:c],    lang_lst['el'][:n]
      when /^en$|English/i;                    d,c,l=false,lang_lst['en'][:c],    lang_lst['en'][:n]
      when /^eo$|Esperanto/i;                  d,c,l=false,lang_lst['eo'][:c],    lang_lst['eo'][:n]
      when /^es$|Spanish|Espanol/i;            d,c,l=false,lang_lst['es'][:c],    lang_lst['es'][:n]
      when /^et$|Estonian/i;                   d,c,l=false,lang_lst['et'][:c],    lang_lst['et'][:n]
      when /^eu$|Basque/i;                     d,c,l=false,lang_lst['eu'][:c],    lang_lst['eu'][:n]
      when /^fi$|Finnish|Finsk|Suomi/i;        d,c,l=false,lang_lst['fi'][:c],    lang_lst['fi'][:n]
      when /^fr$|French|Francais/i;            d,c,l=false,lang_lst['fr'][:c],    lang_lst['fr'][:n]
      when /^ga$|Irish/i;                      d,c,l=false,lang_lst['ga'][:c],    lang_lst['ga'][:n]
      when /^gl$|Galician/i;                   d,c,l=false,lang_lst['gl'][:c],    lang_lst['gl'][:n]
      when /^he$|Hebrew/i;                     d,c,l=false,lang_lst['he'][:c],    lang_lst['he'][:n]
      when /^hi$|Hindi/i;                      d,c,l=false,lang_lst['hi'][:c],    lang_lst['hi'][:n]
      when /^hr$|Croatian/i;                   d,c,l=false,lang_lst['hr'][:c],    lang_lst['hr'][:n]
      when /^hy$|Armenian/i;                   d,c,l=false,lang_lst['hy'][:c],    lang_lst['hy'][:n]
      when /^ia$|Interlingua/i;                d,c,l=false,lang_lst['ia'][:c],    lang_lst['ia'][:n]
      when /^is$|Icelandic/i;                  d,c,l=false,lang_lst['is'][:c],    lang_lst['is'][:n]
      when /^it$|Italian/i;                    d,c,l=false,lang_lst['it'][:c],    lang_lst['it'][:n]
      when /^la$|Latin/i;                      d,c,l=false,lang_lst['la'][:c],    lang_lst['la'][:n]
      when /^lo$|Lao/i;                        d,c,l=false,lang_lst['lo'][:c],    lang_lst['lo'][:n]
      when /^lt$|Lithuanian/i;                 d,c,l=false,lang_lst['lt'][:c],    lang_lst['lt'][:n]
      when /^lv$|Latvian/i;                    d,c,l=false,lang_lst['lv'][:c],    lang_lst['lv'][:n]
      when /^ml$|Malayalam/i;                  d,c,l=false,lang_lst['ml'][:c],    lang_lst['ml'][:n]
      when /^mr$|Marathi/i;                    d,c,l=false,lang_lst['mr'][:c],    lang_lst['mr'][:n]
      when /^nl$|Dutch/i;                      d,c,l=false,lang_lst['nl'][:c],    lang_lst['nl'][:n]
      when /^no$|Norwegian|Norsk/i;            d,c,l=false,lang_lst['no'][:c],    lang_lst['no'][:n]
      when /^nn$|Norwegian Nynorsk/i;          d,c,l=false,lang_lst['nn'][:c],    lang_lst['nn'][:n]
      when /^oc$|Occitan/i;                    d,c,l=false,lang_lst['oc'][:c],    lang_lst['oc'][:n]
      when /^pl$|Polish/i;                     d,c,l=false,lang_lst['pl'][:c],    lang_lst['pl'][:n]
      when /^pt$|Portuguese/i;                 d,c,l=false,lang_lst['pt'][:c],    lang_lst['pt'][:n]
      when /^pt_BR$|Portuguese Brazil/i;       d,c,l=false,lang_lst['pt_BR'][:c], lang_lst['pt_BR'][:n]
      when /^ro$|Romanian/i;                   d,c,l=false,lang_lst['ro'][:c],    lang_lst['ro'][:n]
      when /^ru$|Russian/i;                    d,c,l=false,lang_lst['ru'][:c],    lang_lst['ru'][:n]
      when /^sa$|Sanskrit/i;                   d,c,l=false,lang_lst['sa'][:c],    lang_lst['sa'][:n]
      when /^se$|Sami/i;                       d,c,l=false,lang_lst['se'][:c],    lang_lst['se'][:n]
      when /^sk$|Slovak/i;                     d,c,l=false,lang_lst['sk'][:c],    lang_lst['sk'][:n]
      when /^sl$|Slovenian/i;                  d,c,l=false,lang_lst['sl'][:c],    lang_lst['sl'][:n]
      when /^sq$|Albanian/i;                   d,c,l=false,lang_lst['sq'][:c],    lang_lst['sq'][:n]
      when /^sr$|Serbian/i;                    d,c,l=false,lang_lst['sr'][:c],    lang_lst['sr'][:n]
      when /^sv$|Swedish|Svensk/i;             d,c,l=false,lang_lst['sv'][:c],    lang_lst['sv'][:n]
      when /^ta$|Tamil/i;                      d,c,l=false,lang_lst['ta'][:c],    lang_lst['ta'][:n]
      when /^te$|Telugu/i;                     d,c,l=false,lang_lst['te'][:c],    lang_lst['te'][:n]
      when /^th$|Thai/i;                       d,c,l=false,lang_lst['th'][:c],    lang_lst['th'][:n]
      when /^tk$|Turkmen/i;                    d,c,l=false,lang_lst['tk'][:c],    lang_lst['tk'][:n]
      when /^tr$|Turkish/i;                    d,c,l=false,lang_lst['tr'][:c],    lang_lst['tr'][:n]
      when /^uk$|Ukranian/i;                   d,c,l=false,lang_lst['uk'][:c],    lang_lst['uk'][:n]
      when /^ur$|Urdu/i;                       d,c,l=false,lang_lst['ur'][:c],    lang_lst['ur'][:n]
      when /^us|American$|/i;                  d,c,l=false,lang_lst['en'][:c],    lang_lst['en'][:n]
      when /^vi$|Vietnamese/i;                 d,c,l=false,lang_lst['vi'][:c],    lang_lst['vi'][:n]
      else                                     d,c,l=true, lang_lst['en'][:c],    lang_lst['en'][:n] #default
      end
      lng[:d],lng[:c],lng[:n]=d,c,l
      lng
    end
    def name
      language[:n].downcase
    end
    def title
      language[:n]
    end
    def code
      language[:c]
    end
    def tex_name
      language[:xlp]
    end
    def file_to_language(file) # used, fix and remove
      m=/.+?\~(\w{2,3})\.(?:-|ssm\.)?sst$/
      @language=if file =~m ; file[m,1]
      else ''
      end
      language
    end
    def codes
      # Language List po4a
      #   <http://www.debian.org/international/l10n/po/>
      #   Px[:lng_lst] see constants.rb
      # see polyglossia for subset
      #   <http://mirrors.ctan.org/macros/xetex/latex/polyglossia/polyglossia.pdf>
      # also note ISO_639-2
      #   <http://en.wikipedia.org/wiki/ISO_639-2>
      #   <http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes>
      Px[:lng_lst] # constants.rb
    end
  end
  class InfoEnv < EnvCall
    require 'pathname'
    require 'fileutils'
      include FileUtils
    attr_accessor :filename,:sys,:home,:hostname,:user,:env,:rc,:www,:fnb,:fnn,:fnt,:flv,:webserv_path,:stub_pwd,:stub_src,:webserv_host_cgi,:webserv_port_cgi,:processing,:processing_git,:etc,:yamlrc_dir
    @@image_flag,@@local_image=true,true   #warning on @@image_flag
    @@fb,@@man_path=nil,nil
    def initialize(fns='',md=nil)
      super() #you may not want to re-execute this static info so frequently!
      @init=SiSU_Env::GetInit.new
      @fns,@md=fns,md
      @env=SiSU_Env::EnvCall.new(fns) if fns
      fnb=if @md \
      and defined? @md.fnb
        @md.fnb
      elsif defined? @env.fnb \
      and @env.fnb
        @env.fnb
      elsif @fns.is_a?(String) \
      and not @fns.empty?
        m=/(.+)?\.(?:(?:-|ssm\.)?sst|ssm)$/m
        @fns[m,1] if not @fns.empty?
      end
      if fnb; @@fb ||=fnb
      end
      @sys=InfoSystem.instance
      @fnb ||=@@fb #clean up this... used primarily for zap which is not passed normal parameters
      @fixed_websev_root='' # @home
      @pwd=@@pwd=Dir.pwd
      m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
      @stub_pwd=@@pwd[m,1]
      @stub_txt=     @stub_pwd + '/txt'
      @stub_html=    @stub_pwd + '/html'
      @stub_epub=    @stub_pwd + '/epub'
      @stub_odt=     @stub_pwd + '/odt'
      @stub_pdf=     @stub_pwd + '/pdf'
      @stub_manifest=@stub_pwd + '/manifest'
      @stub_odt=     @stub_pwd + '/odt'
      @stub_src=     @stub_pwd + '/src'
      @stub_pod=     @stub_pwd + '/pod'
      @stub_md=      @stub_pwd + '/sisu_site_metadata'
      pt=Pathname.new(Dir.pwd)
      stub=if output_dir_structure.by_language_code?
        r=Px[:lng_lst_rgx]
        stub=if Dir.pwd =~/.+?\/([^\/]+)(?:\/(#{r})$)/
          lng=pt.split[-1].to_s
          lng_part='/' + lng
          base=pt.split[0].split[-1].to_s
        else
          lng_part='/' + language_default_set
          base=pt.split[-1].to_s
        end
        base + lng_part
      elsif output_dir_structure.by_filetype?
        pt.split[-1].to_s
      elsif  output_dir_structure.by_filename?
        ''
      else
        SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('set output type, by: language, filetype or filename')
      end
      @stub_set_manifest=stub + '/manifest'
    end
    def user
      @sys.user
    end
    def hostname
      @sys.hostname
    end
    def host
      @sys.host
    end
    def arch
      @sys.arch
    end
    def rbver
      @sys.rbver
    end
    def locale
      @sys.locale
    end
    def concord_max
      ((defined? @rc['processing']['concord_max']) \
      && @rc['processing']['concord_max']) \
      ? @rc['processing']['concord_max']
      : (defaults[:concord_max])
    end
    def language_default_set #set directory (default) language
      ((defined? @rc['default']['language']) \
      && @rc['default']['language'] =~/\S+/) \
      ? @rc['default']['language']
      : 'en'
    end
    def markup_emphasis
      if defined? @rc['default']['emphasis'] \
      and @rc['default']['emphasis'] \
      and @rc['default']['emphasis']=~/bold/
        'bold'
      elsif defined? @rc['default']['emphasis'] \
      and @rc['default']['emphasis'] \
      and @rc['default']['emphasis']=~/italic/
        'italics'
      elsif defined? @rc['default']['emphasis'] \
      and @rc['default']['emphasis'] \
      and @rc['default']['emphasis']=~/underscore/
        'underscore'
      else 'bold'
      end
    end
    def plaintext_wrap
      ((defined? @rc['default']['text_wrap']) \
      && (@rc['default']['text_wrap']) \
      && (@rc['default']['text_wrap'].to_s=~/\d\d+/) \
      && (@rc['default']['text_wrap'].to_i > 19) \
      && (@rc['default']['text_wrap'].to_i < 201)) \
      ? @rc['default']['text_wrap'].to_i
      : 78
    end
    def current_document
      @@current_document||=Dir.pwd
      @@current_document
    end
    def stub_pwd                                                               #200412
      @stub_pwd
    end
    def stub_md_harvest                                                        #watch
      @stub_set_manifest
    end
    def stub_src
      @stub_src
    end
    def stub_pod
      @stub_pod
    end
    def sisupod_v4(opt)
      #processing_path.processing
      #  sisupod
      #    doc/
      #      manifest.txt
      #      en/content.sst                [file content]
      #      fr/content.sst
      #      _sisu
      #        sisu_document_make
      #        image@ (ln -s ../../image)
      #        audio@ (ln -s ../../audio)
      #        video@ (ln -s ../../video)
      #    image/                          [all images for specific document gathered here]
      #    audio/
      #    video/
      spp="#{processing_path.processing}/#{Gt[:sisupod]}"
      sppc="#{spp}/doc/_sisu"
      lng_dirs=[]
      if FileTest.directory?(spp) \
      or FileTest.file?(spp)
        FileUtils::rm_rf(spp)
      end
      paths=[]
      flv=SiSU_Env::EnvCall.new(opt.fns).document_language_versions_found
      flv[:f].each {|l| lng_dirs << l[:l] }
      lng_dirs.uniq.each do |lng|
        paths << "#{spp}/doc/#{lng}"
      end
      paths \
      << "#{spp}/image"
     #<< "#{spp}/audio" \
     #<< "#{spp}/video" \
      paths.each do |x|
        unless FileTest.directory?(x)
          FileUtils::mkdir_p(x)
        end
      end
      if FileTest.directory?(sppc)
        pwd=Dir.pwd
        Dir.chdir(sppc)
        FileUtils::ln_s('../../image', 'image')
       #FileUtils::ln_s('../../audio', 'audio')
       #FileUtils::ln_s('../../video', 'video')
        Dir.chdir(pwd)
      end
    end
    def sisupod_v3(opt)
      #processing_path.processing
      #  sisupod
      #    doc/
      #      manifest.txt
      #      en/content.sst                [file content]
      #      fr/content.sst
      #      _sisu
      #        skin/
      #          doc                       [relevant skin if any other than default]
      #        image@ (ln -s ../../image)
      #        audio@ (ln -s ../../audio)
      #        video@ (ln -s ../../video)
      #    image/                          [all images for specific document gathered here]
      #    audio/
      #    video/
      spp="#{processing_path.processing}/#{Gt[:sisupod]}"
      sppc="#{spp}/doc/_sisu"
      lng_dirs=[]
      if FileTest.directory?(spp) \
      or FileTest.file?(spp)
        FileUtils::rm_rf(spp)
      end
      paths=[]
      flv=SiSU_Env::EnvCall.new(opt.fns).document_language_versions_found
      flv[:f].each {|l| lng_dirs << l[:l] }
      lng_dirs.uniq.each do |lng|
        paths << "#{spp}/doc/#{lng}"
      end
      paths \
      << "#{spp}/image" \
      << "#{sppc}/skin/doc" \
      << "#{sppc}/skin/dir" \
      << "#{sppc}/skin/site"
     #<< "#{spp}/audio" \
     #<< "#{spp}/video" \
      paths.each do |x|
        unless FileTest.directory?(x)
          FileUtils::mkdir_p(x)
        end
      end
      if FileTest.directory?(sppc)
        pwd=Dir.pwd
        Dir.chdir(sppc)
        FileUtils::ln_s('../../image', 'image')
       #FileUtils::ln_s('../../audio', 'audio')
       #FileUtils::ln_s('../../video', 'video')
        Dir.chdir(pwd)
      end
    end
    def sisupod_v2
      #processing_path.processing
      #  sisupod
      #    content.sst              [file content]
      #    filename.sst             [link to content.sst]
      #    _sisu
      #      skin/
      #        doc                  [relevant skin if any other than default]
      #      image                  [all images for specific document gathered here]
      sisupod_processing_path="#{processing_path.processing}/#{Gt[:sisupod]}"
      if FileTest.directory?(sisupod_processing_path) \
      or FileTest.file?(sisupod_processing_path)
        FileUtils::rm_rf(sisupod_processing_path)
      end
      paths=[]
      paths=[
        "#{processing_path.processing}/#{Gt[:sisupod]}/_sisu/skin/doc",
        "#{processing_path.processing}/#{Gt[:sisupod]}/_sisu/skin/dir",
        "#{processing_path.processing}/#{Gt[:sisupod]}/_sisu/skin/site",
        "#{processing_path.processing}/#{Gt[:sisupod]}/_sisu/image"
      ]
      paths.each {|x| FileUtils::mkdir_p(x) unless FileTest.directory?(x) }
    end
    def defaults #multiple default directories
      @default_dir ||=@sys.default_dir #DEFAULT_DIR
    end
    def html_seg_title_banner?
      ((defined? @rc['html']['seg_title_banner']) \
      && @rc['html']['seg_title_banner']==true) \
      ? @rc['html']['seg_title_banner']
      : false
    end
    def html_quick_ref?
      ((defined? @rc['html']['quick_ref']) \
      && @rc['html']['quick_ref']==true) \
      ? @rc['html']['quick_ref']
      : false
    end
    def html_minitoc?
      if defined? @rc['html']['minitoc'] \
      and @rc['html']['minitoc'].is_a?(String)
        @rc['html']['minitoc']
      else false
      end
    end
    def manifest_minitoc?
      if defined? @rc['manifest']['minitoc'] \
      and @rc['manifest']['minitoc'].is_a?(String)
        @rc['manifest']['minitoc']
      else false
      end
    end
    def build
      def omit_list
        @off_list ||=if defined? @rc['omit_list'] \
        and @rc['omit_list'].is_a?(String)
          @rc['omit_list']
        elsif defined? @rc['omit']['list'] \
        and @rc['omit']['list'].is_a?(String)
          @rc['omit']['list']
        else
          nil
        end
      end
      def listed?(test) #fix
        listed=if omit_list
          x=(omit_list.scan(/\b#{test}\b/)).join
          test==x \
          ? true
          : false
        else
          false
        end
        listed
      end
      def ocn?
        if (defined? @rc['omit']['ocn'] \
        and not @rc['omit']['ocn'].nil?) \
        or listed?('ocn')
          :off
        else
          :na
        end
      end
      def toc?
        if (defined? @rc['omit']['toc'] \
        and not @rc['omit']['toc'].nil?) \
        or listed?('toc')
          :off
        else
          :na
        end
      end
      def manifest?
        if (defined? @rc['omit']['manifest'] \
        and not @rc['omit']['manifest'].nil?) \
        or listed?('manifest')
          :off
        else
          :na
        end
      end
      def links_to_manifest?
        if (defined? @rc['omit']['links_to_manifest'] \
        and not @rc['omit']['links_to_manifest'].nil?) \
        or (listed?('links_to_manifest') \
        ||  listed?('manifest_links'))
          :off
        else
          :na
        end
      end
      def metadata?
        if (defined? @rc['omit']['metadata'] \
        and not @rc['omit']['metadata'].nil?) \
        or listed?('metadata')
          :off
        else
          :na
        end
      end
      def minitoc?
        if (defined? @rc['omit']['minitoc'] \
        and not @rc['omit']['minitoc'].nil?) \
        or (listed?('minitoc'))
          :off
        else
          :na
        end
      end
      def manifest_minitoc?
        if (defined? @rc['omit']['manifest_minitoc'] \
        and not @rc['omit']['manifest_minitoc'].nil?) \
        or listed?('manifest_minitoc')
          :off
        else
          :na
        end
      end
      def html_minitoc?
        if (defined? @rc['omit']['html_minitoc'] \
        and not @rc['omit']['html_minitoc'].nil?) \
        or (listed?('html_minitoc') \
        || listed?('minitoc'))
          :off
        else
          :na
        end
      end
      def html_navigation?
        if (defined? @rc['omit']['html_navigation'] \
        and not @rc['omit']['html_navigation'].nil?) \
        or listed?('html_navigation')
          :off
        else
          :na
        end
      end
      def html_navigation_bar?
        if (defined? @rc['omit']['html_navigation_bar'] \
        and not @rc['omit']['html_navigation_bar'].nil?) \
        or listed?('html_navigation_bar')
          :off
        else
          :na
        end
      end
      def segsubtoc?
        if (defined? @rc['omit']['segsubtoc'] \
        and not @rc['omit']['segsubtoc'].nil?) \
        or listed?('segsubtoc')
          :off
        else
          :na
        end
      end
      def html_right_pane?
        if (defined? @rc['omit']['html_right_pane'] \
        and not @rc['omit']['html_right_pane'].nil?) \
        or listed?('html_right_pane')
          :off
        else
          :na
        end
      end
      def html_top_band?
        if (defined? @rc['omit']['html_top_band'] \
        and not @rc['omit']['html_top_band'].nil?) \
        or listed?('html_top_band')
          :off
        else
          :na
        end
      end
      def search_form? #decide later, as is configured here (in sisurc) and can be turned off on command line
        if (defined? @rc['omit']['search_form'] \
        and not @rc['omit']['search_form'].nil?) \
        or listed?('search_form')
          :off
        else
          :na
        end
      end
      def html_search_form? #decide later, as is configured here (in sisurc) and can be turned off on command line
        if (defined? @rc['omit']['html_search_form'] \
        and not @rc['omit']['html_search_form'].nil?) \
        or listed?('html_search_form')
          :off
        else
          :na
        end
      end
      self
    end
    def odt_ocn?
      ((defined? @rc['odt']['ocn']) \
      && @rc['odt']['ocn']==false) \
      ? @rc['odt']['ocn']
      : true
    end
    def xml_scaffold_ocn?
      ((defined? @rc['xml_scaffold']['ocn']) \
      && @rc['xml_scaffold']['ocn']==false) \
      ? @rc['xml_scaffold']['ocn']
      : true
    end
    def plaintext_ocn?
      ((defined? @rc['plaintext']['ocn']) \
      && @rc['plaintext']['ocn']==false) \
      ? @rc['plaintext']['ocn']
      : true
    end
    def widget #needs (md) #move
      @rc=SiSU_Env::GetInit.new.sisu_yaml.rc
      @ad=SiSU_Env::GetInit.new.ads
      @vz=SiSU_Viz::Defaults.new
      @flag={ ad: false, md: false, sk: false, rc: false }
      def promo?
        @flag[:ad]=if @md.flag_promo && @ad[:flag_promo]
          @flag[:md]=true
          true
        elsif defined? @vz.widget_promo \
        and not @vz.widget_promo.nil? \
        and @vz.widget_promo.is_a?(Array) \
        and @vz.widget_promo.length > 0
          @flag[:sk]=true
          true
        elsif defined? @rc['html']['promo'] \
        and not @rc['html']['promo'].nil? \
        and @rc['html']['promo'].length > 0
          @flag[:rc]=true
          true
        else false
        end
        @flag
      end
      def search?
        searches=['sisu']
        flag=false
        if defined? @rc['search']
          searches.each do |type|
            flag=if defined? @rc['search'][type] \
            and defined? @rc['search'][type]['action'] \
            and @rc['search'][type]['flag']==true \
            and @rc['search'][type]['action'] =~/https?:\/\//
              flag=if promo?[:ad]
                false
              elsif defined? @vz.widget_search \
              and @vz.widget_search==true
                true
              elsif defined? @rc['search'][type]['flag'] \
              and @rc['search'][type]['flag']==true
                true
              else false
              end
            else false
            end
          end
        else false
        end
        flag
      end
      def search_fixed?
        searches=['sisu','hyperestraier']
        flag=if defined? @rc['search']
          searches.each do |type|
            if defined? @rc['search'][type] \
            and defined? @rc['search'][type]['action'] \
            and @rc['search'][type]['action'] =~/https?:\/\// \
            and defined? @rc['search'][type]['db'] \
            and @rc['search'][type]['db'] =~/\S+/
              flag=if promo?[:ad]
                false
              elsif defined? @vz.widget_search \
              and @vz.widget_search==true
                true
              elsif defined? @rc['search'][type]['flag'] \
              and @rc['search'][type]['flag']==true
                true
              else false
              end
            else false
            end
          end
        else false
        end
      end
      def search_form(type='sisusearch',action=nil,db=nil,table=false)
        rc=SiSU_Env::GetInit.new.sisu_yaml.rc
        create_form_sisu=if action \
        and db \
        and action =~/https?:\/\// \
        and db =~/\S+/
          true
        elsif widget.search?
          db=if rc['search']['sisu']['flag']==true \
          and rc['search']['sisu']['db']=~/\S+/
            (rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
            ? rc['search']['sisu']['db']
            : "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
          else nil
          end
          action=rc['search']['sisu']['action']
          true
        elsif defined? rc['search']['sisu']['flag'] \
        and defined? rc['search']['sisu']['action'] \
        and rc['search']['sisu']['flag']==true \
        and rc['search']['sisu']['action'] =~/https?:\/\//
          true
        else false
        end
        if table
          table_open='<td align="center" bgcolor="#ffffff">'
          table_close='</td>'
        else
          table_open=''
          table_close='<br />'
        end
        form=if create_form_sisu \
        and type=~/sisusearch/ \
        and defined? rc['search']['sisu'] \
        and defined? rc['search']['sisu']['action']
          <<WOK
<!-- SiSU Search -->
#{table_open}
<a name="search"></a>
<form method="get" action="#{rc['search']['sisu']['action']}" target="_top">
<font size="2">
<input type="text" name="s1" size="24" maxlength="255" />
<input type="hidden" name="db" value="#{db}" />
<input type="hidden" name="ltd" value="1000" />
<input type="hidden" name="off" value="0" />
<input type="hidden" name="doc" value="#{@md.fnb}" /><br />
<input type="submit" name="search" value="search doc" />
<input type="submit" name="search" value="search db" />
</font></form>
#{table_close}
<!-- SiSU Search -->
WOK
        else ''
        end
        form
      end
      def search_form_static(action=nil,db=nil)
        rc=SiSU_Env::GetInit.new.sisu_yaml.rc
        create_form=if rc['search']['sisu']['flag']==true \
        and action \
        and db \
        and action =~/https?:\/\// \
        and db =~/\S+/
          true
        elsif widget.search_fixed?
          db=if rc['search']['sisu']['flag']==true \
          and rc['search']['sisu']['db']=~/\S+/
            (rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
            ? rc['search']['sisu']['db']
            : "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
          else nil
          end
          action=rc['search']['sisu']['action']
          true
        else false
        end
        if create_form
          %{<td align="center" bgcolor="#ffffff">
<!-- SiSU Search -->
<a name="search"></a>
<form method="get" action="#{rc['search']['sisu']['action']}" target="_top">
<font size="2">
<input type="text" name="s1" size="24" maxlength="255" />
<br />
<input type="hidden" name="db" value="#{db}" />
<input type="hidden" name="ltd" value="1000" />
<input type="hidden" name="off" value="0" />
<input type="hidden" name="doc" value="#{@md.fnb}" />
<input type="submit" name="search" value="search doc" />
<input type="submit" name="search" value="search db" />
</font>
</form>
<!-- SiSU Search -->
</td> }
        else ''
        end
      end
      def search_action #check
        if search?
        else ''
        end
      end
      self
    end
    def widget_static
      @rc=SiSU_Env::GetInit.new.sisu_yaml.rc
      @vz=SiSU_Viz::Defaults.new
      @flag={ ad: false, md: false, sk: false, rc: false }
      def search?
        flag=if defined? @rc['search'] \
        and defined? @rc['search']['sisu'] \
        and defined? @rc['search']['sisu']['action'] \
        and @rc['search']['sisu']['action'] =~/https?:\/\// \
        and defined? @rc['search']['sisu']['db'] \
        and @rc['search']['sisu']['db'] =~/\S+/
          flag=if defined? @vz.widget_search \
          and @vz.widget_search==true
            true
          elsif defined? @rc['search']['sisu']['flag'] \
          and @rc['search']['sisu']['flag']==true
            true
          else
            false
          end
        else
          false
        end
      end
      def search_fixed?
        flag=if defined? @rc['search'] \
        and defined? @rc['search']['sisu'] \
        and defined? @rc['search']['sisu']['action'] \
        and @rc['search']['sisu']['action'] =~/https?:\/\// \
        and defined? @rc['search']['sisu']['db'] \
        and @rc['search']['sisu']['db'] =~/\S+/ \
        and defined? @rc['search']['sisu']['db'] \
        and @rc['search']['sisu']['db'] =~/\S+/
          flag=if defined? @vz.widget_search \
          and @vz.widget_search==true
            true
          elsif defined? @rc['search']['sisu']['flag'] \
          and @rc['search']['sisu']['flag']==true
            true
          else
            false
          end
        else
          false
        end
      end
      def search_form(action=nil,db=nil)
        rc=SiSU_Env::GetInit.new.sisu_yaml.rc
        create_form=if defined? rc['search']['sisu']['flag'] \
        and rc['search']['sisu']['flag']==true \
        and action \
        and db \
        and action =~/https?:\/\// \
        and db =~/\S+/
          true
        elsif widget_static.search? \
        and rc['search']['sisu']['flag']==true
          db=if rc['search']['sisu']['db']=~/\S+/
            (rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
            ? rc['search']['sisu']['db']
            : "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
          else nil
          end
          action=rc['search']['sisu']['action']
          true
        else false
        end
        if create_form \
        and @fnb \
        and @fnb=~/\S+/
          %{<!-- SiSU Search -->
<a name="search"></a>
<form method="get" action="#{rc['search']['sisu']['action']}" target="_top">
<font size="2">
<input type="text" name="s1" size="24" maxlength="255" />
<br />
<input type="hidden" name="db" value="#{db}" />
<input type="hidden" name="doc" value="#{@fnb}" />
<input type="submit" name="search" value="search doc" />
<input type="submit" name="search" value="search db" />
</font>
</form>
<!-- SiSU Search --> }
        elsif create_form
          %{<!-- SiSU Search -->
<a name="search"></a>
<form method="get" action="#{rc['search']['sisu']['action']}" target="_top">
<font size="2">
<input type="text" name="s1" size="24" maxlength="255" />
<br />
<input type="hidden" name="db" value="#{db}" />
<input type="submit" name="search" value="search db" />
</font>
</form>
<!-- SiSU Search --> }
        else ''
        end
      end
      def search_action #check
        if search?
        else ''
        end
      end
      self
    end
    def source_file_path
      file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
      unless file =~/\.ssm\.sst$/; "#{Dir.pwd}"
      else "#{processing_path.composite_file}"
      end
    end
    def source_file_with_path
      file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
      "#{source_file_path}/#{file}"
    end
    def font
      def texpdf
        # you may wish to check selected font against available fonts:
        # fc-list :outline -f "%{family}\n"
        # fc-list :lang=ja
        def main
          (defined? @rc['default']['texpdf_font']) \
          && (@rc['default']['texpdf_font']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font']
          : 'Liberation Sans'
        end
        def sans                                                               # not used
          (defined? @rc['default']['texpdf_font_sans']) \
          && (@rc['default']['texpdf_font_sans']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_sans']
          : 'Liberation Sans'
        end
        def serif                                                              # not used
          (defined? @rc['default']['texpdf_font_serif']) \
          && (@rc['default']['texpdf_font_serif']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_serif']
          : 'Liberation Serif'
        end
        def mono
          (defined? @rc['default']['texpdf_font_mono']) \
          && (@rc['default']['texpdf_font_mono']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_mono']
          : 'Liberation Mono'
        end
        def cjk
          (defined? @rc['default']['texpdf_font_cjk']) \
          && (@rc['default']['texpdf_font_cjk']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_cjk']
          : 'IPAGothic' # 'IPAGothic' # 'IPAMincho' # 'TakaoMincho' # 'VL Gothic'
        end
        def cjk_zh
          (defined? @rc['default']['texpdf_font_cjk_zh']) \
          && (@rc['default']['texpdf_font_cjk_zh']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_cjk_zh']
          : 'IPAGothic'
        end
        def cjk_ja
          (defined? @rc['default']['texpdf_font_cjk_ja']) \
          && (@rc['default']['texpdf_font_cjk_ja']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_cjk_ja']
          : 'IPAGothic'
        end
        def cjk_ko
          (defined? @rc['default']['texpdf_font_cjk_ko']) \
          && (@rc['default']['texpdf_font_cjk_ko']=~/\S{3,}/)  \
          ? @rc['default']['texpdf_font_cjk_ko']
          : 'IPAGothic'
        end
        self
      end
      self
    end
    def path_rel_links
      def html_scroll_2
        if @env.output_dir_structure.by_language_code?
          '../../'
        elsif @env.output_dir_structure.by_filetype?
          '../'
        else
          '../'
        end
      end
      def html_seg_2
        if @env.output_dir_structure.by_language_code?
          '../../../'
        elsif @env.output_dir_structure.by_filetype?
          '../../'
        else
          '../'
        end
      end
      def html_scroll_1
        if @env.output_dir_structure.by_language_code?
          '../'
        elsif @env.output_dir_structure.by_filetype?
          '../'
        else
          './'
        end
      end
      def html_seg_1
        if @env.output_dir_structure.by_language_code?
          '../../'
        elsif @env.output_dir_structure.by_filetype?
          '../../'
        else
          './'
        end
      end
      self
    end
    def read_source_file_array(fns)
      (fns !~/\.ssm.sst$/) \
      ? (IO.readlines(fns, mode: 'r:utf-8', cr_newline: true))
      : (IO.readlines("#{processing_path.composite_file}/#{fns}", mode: 'r:utf-8', cr_newline: true))
    end
    def read_source_file(fns)
      read_source_file_array(fns)
    end
    def read_source_file_string(fns)
      (fns !~/\.ssm.sst$/) \
      ? (IO.read(fns, mode: 'r:utf-8', cr_newline: true))
      : (IO.read("#{processing_path.composite_file}/#{fns}", mode: 'r:utf-8', cr_newline: true))
    end
    def source_file_processing_array(fns)
      read_source_file_string(fns).split(/\s*\n\s*\n/m)
    end
    def path                                                                     #dir
      def home
        @sys.home
      end
      def sisurc_path
        GetInit.new.sisu_yaml.rc_path
      end
      def pwd
        @sys.pwd
      end
      def stub_pwd
        @stub_pwd
      end
      def stub_txt
        @stub_txt
      end
      def stub_html
        @stub_html
      end
      def stub_epub
        @stub_epub
      end
      def stub_odt
        @stub_odt
      end
      def stub_pdf
        @stub_pdf
      end
      def stub_manifest
        @stub_manifest
      end
      def stub_set_manifest
        @stub_set_manifest
      end
      def stub_src
        @stub_src
      end
      def stub_pod
        @stub_pod
      end
      def stub_md_harvest
        @stub_set_manifest
      end
      def etc
        defaults[:sisu_etc]                                                      #live/dynamic
      end
      def arch
        @sys.dir_arch
      end
      def sitearch
        @sys.dir_sitearch
      end
      def bin
        @sys.dir_bin
      end
      def share                                                                #shared data repository source directory
        defaults[:sisu_share]
      end
      def style
        if @md \
        && ((@md.opt.opt_act[:dump][:bool] \
        &&   @md.opt.opt_act[:dump][:inst]) \
        ||  (@md.opt.opt_act[:redirect][:bool] \
        &&   @md.opt.opt_act[:redirect][:inst]))
          'css'
        else
         defaults[:stylesheet_stub]
        end
      end
      def sample_data                                                          #sample data repository source directory
        defaults[:sample_data_path]
      end
      def rc
        @init.rc_path
      end
      def yamlrc
        GetInit.new.sisu_yaml.rc_path
      end
      def man #check use
        (defined? @rc['webserv']['man']) \
        ? "#{webserv}/#{@rc['webserv']['man']}"
        : defaults[:webserv_man]
      end
      def webserv_path #testing, check need, remove
        webserv
      end
      def webserv                                                              #separation required for webrick which cannot use path.output (different requirements as no file is passed)
        man_path=if @@man_path.nil?
          man_path=if defined? @rc['webserv']['path'] \
          and @rc['webserv']['path'] =~/\S\S+/
            pwd=Dir.pwd
            Dir.chdir(SiSU_Utils::Path.new.base_markup)
            man_path=@@man_path=File.expand_path(@rc['webserv']['path'])
            Dir.chdir(pwd)
            man_path
          else defaults[:webserv_path]
          end
        else @@man_path
        end
        man_path_head=man_path.gsub(/(\S+)\/[^\/\s]+$/,'\1')
        unless FileTest.directory?(man_path)
          FileUtils::mkdir_p(man_path) if File.writable?("#{man_path_head}/.")
        end
        @webserv_path=if defined? man_path \
        and File.writable?("#{man_path}/.")
          man_path #web server path as configured in rc file
        elsif FileTest.directory?(defaults[:webserv_path]) \
        and File.writable?("#{defaults[:webserv_path]}/.") #web server path default
          defaults[:webserv_path]
        else #create default directory under home and place output there
          unless FileTest.directory?(defaults[:output_local])
            FileUtils::mkdir_p(defaults[:output_local])
          end
          defaults[:output_local]
        end
      end
      def webserv_stub_ensure
        FileUtils::mkdir_p(path.webserv) unless FileTest.directory?(path.webserv)
        FileUtils::mkdir_p("#{path.webserv}/#{@stub_pwd}") unless FileTest.directory?("#{path.webserv}/#{@stub_pwd}")
      end
      def webserv_map_pwd #dir
        "#{path.webserv}/#{stub_pwd}"
      end
      def webserv_dir                                                          #fixed/hard path to /www web/presentation directory, on Debian /var/www subdirectories are created within it, depending on markup directory stub-name (last segment of markup directory name)
        defaults[:webserv_dir]
      end
      def webserv_image                                                        #web/presentation directory, subdirectories are created within it, depending on markup directory stub-name (last segment of markup directory name)
        images=if defined? @rc['webserv']['images']
          @rc['webserv']['images']
        else defaults[:images]
        end
        "#{path.webserv}/#{images}"
      end
      def output                                                               #web/webserv output directory... subdirectory into which further subdirectories are made based on file names
        r=Px[:lng_lst_rgx]
        u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
        base_stub=@sys.pwd.gsub(u,'\1')
        if Dir.pwd =~/\/#{Gt[:sisupod]}\/[^\/]+\/#{Gt[:pod]}\/#{Gt[:doc]}/
          "#{path.webserv}/#{Gt[:doc]}"
        else
          "#{path.webserv}/#{base_stub}"
        end
      end
      def feed
        (defined? @rc['webserv']['feed']) \
        ? ("#{public_output}/#{@rc['webserv']['feed']}")
        : (defaults[:webserv_feed])
      end
      def feed_home
        "#{public_output}/#{@rc['webserv']['feed_home']}"
      end
      def scripts                                                                #used previously only to include tla version info
        if defined? @rc['project']['path']; "#{home}/#{@rc['project']['path']}"
        end
      end
      def cgi
        (defined? @rc['webserv']['cgi']) \
        ? "#{@rc['webserv']['cgi']}"
        : (defaults[:webserv_cgi])
      end
      def php
        (defined? @rc['webserv']['php']) \
        ? "#{public_output}/#{@rc['webserv']['php']}"
        : (defaults[:webserv_php])
      end
                                                                                 # programs
      def output_tell
        url.webserv_map_pwd
      end
      def image_source                                                           #image repository source directory
        if defined? @rc['image']['path'] \
        and defined? @rc['image']['public']
          pth="#{@rc['image']['path']}"
          "#{pth}/#{@rc['image']['public']}"
        else
          "#{share}/image"
        end
      end
      def image_source_sisu_includes
        "#{share}/image"
      end
      def image_source_include                                                       #image repository source directory
        if defined? @rc['image']['path'] \
        and defined? @rc['image']['public'] \
        and FileTest.directory?("#{@rc['image']['path']}/#{@rc['image']['public']}")==true
          "#{@rc['image']['path']}/#{@rc['image']['public']}"
        elsif FileTest.directory?("#{@@pwd}/#{defaults[:image_stub]}")==true
          "#{@@pwd}/#{defaults[:image_stub]}"
        elsif FileTest.directory?("#{SiSU_Utils::Path.new.base_markup}/#{defaults[:image_stub]}")==true
          "#{SiSU_Utils::Path.new.base_markup}/#{defaults[:image_stub]}"
        else
          "#{share}/image"
        end
      end
      def image_external
        "#{processing}/external_document/image"
      end
      def image_source_include_local
        if FileTest.directory?(defaults[:image_local]); defaults[:image_local]
        end
      end
      def image_source_include_remote
        if FileTest.directory?(image_external); image_external
        end
      end
      self
    end
    def processing_path
      def encoding
        pth="#{processing}/#{defaults[:processing_encoding]}"
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def processing_base_tmp
        defaults[:processing_path_tmp_base]
      end
      def tmp_root_dir
        defaults[:processing_dir_tmp_root]
      end
      def root_dir
        proposed_path_base=if defined? @rc['processing']['path'] \
        and not @rc['processing']['path'].nil? \
        and not @rc['processing']['path'].empty?
          x=if @rc['processing']['path'] =~/^(?:~|home)$/
            home #fix
          else @rc['processing']['path']
          end
        else nil
        end
        proposed_dir=if defined? @rc['processing']['dir'] \
        and not @rc['processing']['dir'].nil? \
        and not @rc['processing']['dir'].empty?
          @rc['processing']['dir']
        else defaults[:processing_dir]
        end
        v=SiSU_Env::InfoVersion.instance.get_version
        v_dev=(DEVELOPER[:maintenance]==:true) \
        ? "_#{v[:version]}"
        : ''
        path=if proposed_path_base \
        and FileTest.directory?(proposed_path_base) \
        and File.writable?("#{proposed_path_base}/.")
          x=proposed_dir \
          ? "#{proposed_path_base}/#{proposed_dir}"
          : "#{proposed_path_base}/#{defaults[:processing_dir]}"
        else defaults[:processing_dir_tmp_root]
        end
        path = path + v_dev
      end
      def usr_dir?
        case root_dir
        when /^\/home/; false
        else true
        end
      end
      def stub_dir
        (usr_dir?) \
        ? ("#{root_dir}/#{user}/#{stub_pwd}")
        : ("#{root_dir}/#{stub_pwd}") # see defaults[:processing_path]
      end
      def stub_dir_orig # ends up with lang, if lang dir
        (usr_dir?) \
        ? ("#{root_dir}/#{user}/#{stub_pwd}")
        : ("#{root_dir}/#{stub_pwd}") # see defaults[:processing_path]
      end
      def processing_sisupod(opt=nil)                                                   #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc)
        @opt=opt
        def paths
          processing_path_usr="#{root_dir}/#{user}"
          processing_path_fnb=processing_path_usr + '/' + Gt[:pods] + '/' + @opt.fng
          processing_path_sisupod=processing_path_fnb + '/' + Gt[:sisupod]
          { fnb: processing_path_fnb, sisupod: processing_path_sisupod }
        end
        def make
          unless FileTest.directory?(root_dir)
            FileUtils::mkdir_p(root_dir)
            File.chmod(0777,root_dir)
          end
          if usr_dir?
            processing_path_usr="#{root_dir}/#{user}"
            FileUtils::mkdir_p(processing_path_usr) unless FileTest.directory?(processing_path_usr)
            File.chmod(0700,processing_path_usr)
          end
          sisupod_processing_path=paths[:sisupod]
          FileUtils::mkdir_p(sisupod_processing_path) unless FileTest.directory?(sisupod_processing_path)
          sisupod_processing_path_lng=if defined? @opt.lng
            sisupod_processing_path + '/' + Gt[:doc] + '/' + @opt.lng
          else
            sisupod_processing_path + '/' + Gt[:doc]
          end
          unless FileTest.directory?(sisupod_processing_path_lng)
            #puts "a processing directory (#{sisupod_processing_path_lng}) is being created for use by sisu"
            FileUtils::mkdir_p(sisupod_processing_path_lng)
            File.chmod(0700,sisupod_processing_path_lng)
          end
          sisupod_processing_path
        end
        self
      end
      def processing                                                             #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc)
        unless FileTest.directory?(root_dir)
          FileUtils::mkdir_p(root_dir)
          File.chmod(0777,root_dir)
        end
        if usr_dir?
          processing_path_usr="#{root_dir}/#{user}"
          FileUtils::mkdir_p(processing_path_usr) unless FileTest.directory?(processing_path_usr)
          File.chmod(0700,processing_path_usr)
        end
        FileUtils::mkdir_p(stub_dir) unless FileTest.directory?(stub_dir)
        File.chmod(0700,stub_dir)
        path_processing=[stub_dir,defaults[:processing_path],defaults[:processing_path_home]]
        processing=nil
        path_processing.each do |v|                                              #
          processing=v
          unless FileTest.directory?(processing)
            FileUtils::mkdir_p(processing)
            File.chmod(0700,processing)
          end
          break
        end
        processing
      end
      def dal
        pth=if defined? @rc['processing']['dal'] \
          and @rc['processing']['dal'].is_a?(String)
          "#{processing}/#{@rc['processing']['dal']}"
        else "#{processing}/#{defaults[:processing_dal]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def tune
        pth=if defined? @rc['processing']['tune'] \
          and @rc['processing']['tune'].is_a?(String)
          "#{processing}/#{@rc['processing']['tune']}"
        else "#{processing}/#{defaults[:processing_tune]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def composite_file
        pth=processing_path.dal  #"#{processing}/composite"
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def git
        pth=if defined? @rc['git']['dir'] \
        and @rc['git']['dir'].is_a?(String)
          (@rc['git']['dir'] =~/^(?:~|home)$/) \
          ? home + '/' + Gt[:git]
          : @rc['git']['dir'] + '/' + Gt[:git]
        else defaults[:processing_git]
        end
        unless FileTest.directory?(pth)
          FileUtils::mkdir_p(pth)
          File.chmod(0700,pth)
        end
        pth
      end
      def odf_pth
        pth="#{processing}/odf/#{@fns}"
        pth
      end
      def odf
        odt
      end
      def odt
        pth=odf_pth + '/odt'
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def odf
        pth="#{processing}/odf"
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def odt_bld
        FileUtils::rm_rf(processing_path.odt)
        FileUtils::mkdir_p(processing_path.odt) unless FileTest.directory?(processing_path.odt)
        FileUtils::mkdir_p("#{processing_path.odt}/Configurations2") unless FileTest.directory?("#{processing_path.odt}/Configurations2")
        FileUtils::mkdir_p("#{processing_path.odt}/META-INF") unless FileTest.directory?("#{processing_path.odt}/META-INF")
        FileUtils::mkdir_p("#{processing_path.odt}/Pictures") unless FileTest.directory?("#{processing_path.odt}/Pictures")
        FileUtils::mkdir_p("#{processing_path.odt}/Thumbnails") unless FileTest.directory?("#{processing_path.odt}/Thumbnails")
        processing_path.odt
      end
      def epub
        "#{processing}/epub/#{@fnb}"
      end
      def epub_bld #(md)
        FileUtils::rm_rf(processing_path.epub) if FileTest.directory?(processing_path.epub)
        FileUtils::mkdir_p(processing_path.epub) unless FileTest.directory?(processing_path.epub)
        FileUtils::mkdir_p("#{processing_path.epub}/META-INF") unless FileTest.directory?("#{processing_path.epub}/META-INF")
        FileUtils::mkdir_p("#{processing_path.epub}/#{Ep[:d_oebps]}/image") unless FileTest.directory?("#{processing_path.epub}/#{Ep[:d_oebps]}/image")
        FileUtils::mkdir_p("#{processing_path.epub}/#{Ep[:d_oebps]}/css") unless FileTest.directory?("#{processing_path.epub}/#{Ep[:d_oebps]}/css")
        processing_path.epub
      end
      def epub_cp_images(md)
        pth="#{processing_path.epub}/#{Ep[:d_oebps]}/image"
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        src="#{path.share}/image"
        images=%W[bullet_09.png arrow_next_red.png arrow_prev_red.png arrow_up_red.png]
        images.each do |i| #move to avoid repeated tests
          if FileTest.file?("#{src}/#{i}")
            FileUtils::cp("#{src}/#{i}","#{pth}/#{i}") unless FileTest.file?("#{pth}/#{i}")
          else STDERR.puts %{\t*WARN* did not find image - "#{i}" [#{__FILE__}:#{__LINE__}]}
          end
        end
        pth
      end
      def tex
        pth=if defined? @rc['processing']['latex'] \
        and @rc['processing']['latex'].is_a?(String)
          "#{processing}/#{@rc['processing']['latex']}"
        else "#{processing}/#{defaults[:processing_latex]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def texi
        pth=if defined? @rc['processing']['texinfo'] \
        and @rc['processing']['texinfo'].is_a?(String)
          "#{processing}/#{@rc['processing']['texinfo']}"
        else "#{processing}/#{defaults[:processing_texinfo]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def texinfo                                                                #texinfo webserv, check
        "#{processing}/#{defaults[:processing_texinfo]}"
      end
      def manpage
        "#{path.output}/man"
      end
      def lout
        pth=if defined? @rc['processing']['lout'] \
        and @rc['processing']['lout'].is_a?(String)
          "#{processing}/#{@rc['processing']['lout']}"
        else "#{processing}/#{defaults[:processing_lout]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def sql
        pth="#{processing}/sql"
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def sqlite
        pth=if defined? @rc['processing']['sqlite'] \
        and @rc['processing']['sqlite'].is_a?(String)
          "#{processing}/#{@rc['processing']['sqlite']}"
        else "#{processing}/#{defaults[:processing_sqlite]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      def postgresql
        pth=if defined? @rc['processing']['postgresql'] \
        and @rc['processing']['postgresql'].is_a?(String)
          "#{processing}/#{@rc['processing']['postgresql']}"
        else "#{processing}/#{defaults[:processing_postgresql]}"
        end
        FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
        pth
      end
      self
    end
    def url
      def hostname
        "http://#{@sys.hostname}"
      end
      def dir_url
        "file://#{path.webserv}/#{stub_pwd}"
      end
      def localhost
        "http://localhost/#{stub_pwd}"
      end
      def local
        "http://#{hostname}/#{@stub_pwd}"
      end
      def root
        if defined? @rc['webserv']['url_root'] \
        and @rc['webserv']['url_root'] =~/https?:\/\//
          "#{@rc['webserv']['url_root']}/#{@stub_pwd}"
        elsif defined? @rc['webserv']['url_root'] \
        and @rc['webserv']['url_root'] =~/localhost/
          "http://localhost/#{@stub_pwd}"
        else "file://#{path.output}"
        end
      end
      def remote
        root
      end
      def txt
        "#{root}/txt"
      end
      def html
        "#{root}/html"
      end
      def epub
        "#{root}/epub"
      end
      def odt
        "#{root}/odt"
      end
      def pdf
        "#{root}/pdf"
      end
      def src_txt
        "#{root}/src"
      end
      def src_pod
        "#{root}/pod"
      end
      def pot
        "#{root}/po4a/pot"
      end
      def po
        "#{root}/po4a/po"
      end
      def webserv_host_base(opt=nil)
        if defined? @rc['webserv']['host']
          case  @rc['webserv']['host']
          when /https?:\/\//; @rc['webserv']['host']
          when /\S+/; "http://#{@rc['webserv']['host']}"
          else defaults[:webserv_host_cgi]
          end
        else   defaults[:webserv_host_cgi]
        end
      end
      def webserv_cgi(opt=nil)                                                          #web url for local webserv (localhost, or hostname)
        http=if defined? @rc['webserv_cgi']['host'] \
        and @rc['webserv_cgi']['host'].is_a?(String)
          http=((@rc['webserv_cgi']['host'] =~ /https?:\/\//) ? '' : 'http://') #check https? missing
          if port.webserv_port_cgi
            "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi}/#{@stub_pwd}"
          else "#{http}#{@rc['webserv_cgi']['host']}/#{@stub_pwd}"
          end
        else
          http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
          if port.webserv_port_cgi(opt)
            "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}/#{@stub_pwd}"
          else "#{http}#{webserv_host_base}/#{@stub_pwd}"
          end
        end
        http=http.strip
      end
      def webserv_base_cgi(opt=nil)                                                     #web url for local webserv (localhost, or hostname)
        http=if opt.mod.inspect =~/--webserv-(?:cgi|db|search)[=-]["']?(\S+)["']+/
          m=$1
          (m=~/http\/\/:/) ? m : %{http://#{m}}
        elsif defined? @rc['webserv_cgi']['host'] \
        and @rc['webserv_cgi']['host'].is_a?(String)
          http=((@rc['webserv_cgi']['host'] =~ /https?:\/\//) ? '' : 'http://')
          if port.webserv_port_cgi(opt)
            "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi(opt)}"
          else "#{http}#{@rc['webserv_cgi']['host']}"
          end
        else
          http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
          if port.webserv_port_cgi(opt)
            "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}"
          else "#{http}#{webserv_host_base}"
          end
        end
        http=http.strip
      end
      def webrick #must have a port #REMOVE
        if defined? @rc['webserv_cgi']['host'] \
        and @rc['webserv_cgi']['host'].is_a?(String)
          http=if @rc['webserv_cgi']['host'] =~/http:\/\//
            'http://'
          elsif @rc['webserv_cgi']['host'] =~/https:\/\//
            'https://'
          else defaults
          end
          "#{http}#{@rc['webserv_cgi']['host']}"
        elsif webserv_host_base \
        and webserv_host_base.is_a?(String)
          "#{http}#{webserv_host_base}"
        else "#{http}localhost" end
      end
      def webserv                                                              #web url for local webserv (localhost, or hostname)
        if defined? @rc['webserv']['url_root'] \
        and @rc['webserv']['url_root'] =~/http/
          # needed for alternative output dir structures, fixes manifest url links, check may cause problems elsewhere
          @rc['webserv']['url_root']
        elsif path.webserv_dir \
        and path.webserv =~ /#{path.webserv_dir}/ #revisit
          "#{path.webserv}/#{@stub_pwd}".gsub(/#{path.webserv_dir}/,"#{url.hostname}/#{@stub_pwd}")
        elsif defined? @rc['webserv']['webrick_url'] \
        and @rc['webserv']['webrick_url']==false
          "file://#{path.webserv}"
        elsif port.webserv_port_cgi =~/\S+/
          "#{url.hostname}:#{port.webserv_port_cgi}"
        else
          url.hostname
        end
      end
      def webserv_base                                                         #web url for local webserv (localhost, or hostname)
        if path.webserv_dir \
        and path.webserv =~ /#{path.webserv_dir}/ #revisit
          "#{path.webserv}/#{@stub_pwd}".gsub(/#{path.webserv_dir}/,"#{url.hostname}")
        elsif defined? @rc['webserv']['webrick_url'] \
        and @rc['webserv']['webrick_url']==false
          "file://#{path.webserv}"
        else "#{url.webrick_base}"
        end
      end
      def webserv_files_from_db(opt=nil) #sort this out, messy
        if opt.mod.inspect =~/--webserv-output[=-]["']?(\S+)["']+/
          m=$1
          (m=~/(?:http|file\/)\/\/:/) ? m : %{http://#{m}}
        else
          show_output_on=if defined? @rc['webserv_cgi']['show_output_on']
            @rc['webserv_cgi']['show_output_on']
          elsif  defined? @rc['webserv_cgi']['file_links']
            @rc['webserv_cgi']['file_links']
          else ''
          end
          m=case show_output_on
          when /webserv_cgi/; url.webserv_base_cgi(opt)
          when /webserv/;     @rc['webserv']['url_root']
          when /https?:\/\//; @rc['webserv_cgi']['file_links']
          when /\S+/;         "http://#{@rc['webserv_cgi']['file_links']}"
          else                webserv_base_cgi(opt)
          end
        end
      end
      def cgi_sample_search_form_name(opt=nil)
        if opt.mod.inspect =~/--(?:cgi-)?search-form-name[=-]["']?(\S+?\.cgi)/
          $1
        elsif not opt.mod.inspect =~/--db[=-]["']?sqlite/ \
        and defined? @rc['search'] \
        and defined? @rc['search']['sisu'] \
        and defined? @rc['search']['sisu']['action'] \
        and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/
          /(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1]
        else
          (opt.mod.inspect =~/--db[=-]["']?sqlite/) \
          ? "#{Db[:name_prefix_db]}sqlite.cgi" \
          :  "#{Db[:name_prefix_db]}pgsql.cgi"
        end
      end
      def sample_search_form_title(organised_by=:language)
        title=if defined? @rc['search']['sisu']['title'] \
        and @rc['search']['sisu']['title'] =~/\S+/
          @rc['search']['sisu']['title']
        else %{SiSU (generated sample) search form}
        end
        title=title + " (content organised by #{organised_by})"
      end
      def output_tell                                      #BROKEN Revisit 2011-02
        output_type=if defined? @rc['show_output_on'] \
        and @rc['show_output_on'] =~/^(?:filesystem|webserv|(?:local|remote)(?:_webserv)?|webrick)/
          @rc['show_output_on']
        else 'filesystem'
        end
        case output_type
        when /^filesystem(?:_url)?/;       url.dir_url
        when /^remote(?:_webserv)?/;       url.remote
        when /^(?:webserv|local_webserv)/; url.local
        when /^local(:\d+)/;               url.hostname + $1 + '/' + stub_pwd
        when /^localhost(:\d+)/;           url.localhost + $1 +  '/' + stub_pwd
        when /^localhost/;                 url.localhost
        when /^webrick/;                   url.webrick
        when /^path/;                      url.webserv_map_pwd
        else                               url.webserv_map_pwd
        end
      end
      def images
        "#{Xx[:html_relative2]}/_sisu/image"
      end
      #def images
      #  '../_sisu/image'
      #end
      def images_local
        if FileTest.directory?(path.image_source_include)
          path.image_source_include
        else
          if @@local_image==true
            cmd=@cmd ? @cmd : ''
            SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] ).warn unless cmd =~/q/
            @@local_image=false
          end
          url.images
        end
      end
      def images_external
        if FileTest.directory?(image_external)
          if @@image_flag
            images=Dir.glob("#{image_external}/*.{png,jpg,gif}")
            pth="#{path.webserv}/#{@stub_pwd}"
            FileUtils::mkdir_p("#{pth}/_sisu/image_external") unless FileTest.directory?("#{pth}/_sisu/image_external")
            images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0
            @@image_flag=false
          end
          "#{Xx[:html_relative2]}/_sisu/image_external"
        else
          if @@local_image==true
            SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external ).warn unless @cmd =~/q/
            @@local_image=false
          end
          url.images_external
        end
      end
      def images_epub
        './image'
      end
      self
    end
    def port
      def webrick_port
        if @md \
        and @md.opt.cmd.inspect=~/-F/ \
        and @md.opt.mod.inspect=~/port=(\d+)/
           $1
        else
          if defined? @rc['webserv_cgi']['port']
            if @rc['webserv_cgi']['port'].nil? \
            and (defined? @md.opt.mod \
            and not @md.opt.mod.nil? \
            and @md.opt.mod.inspect=~/webrick/)
              defaults[:webserv_port_cgi]
            elsif not @rc['webserv_cgi']['port'].nil?
              @rc['webserv_cgi']['port']
            else defaults[:webserv_port_cgi]
            end
          else   defaults[:webserv_port_cgi]
          end
        end
      end
      def webserv_port_cgi(opt=nil)
        port=if opt \
        and opt.cmd.inspect=~/-F/ \
        and opt.mod.inspect=~/port=(\d+)/
           $1
        else
          port=if defined? @rc['webserv_cgi']['port']
            if @rc['webserv_cgi']['port'].nil? \
            and (defined? opt.mod \
            and not opt.mod.nil? \
            and opt.mod.inspect=~/webrick/)
              defaults[:webserv_port_cgi]
            elsif not @rc['webserv_cgi']['port'].nil?
              @rc['webserv_cgi']['port']
            else nil
            end
          else
            if (defined? opt.mod \
            and not opt.mod.nil? \
            and opt.mod.inspect=~/webrick/)
              defaults[:webserv_port_cgi]
            else nil
            end
          end
        end
      end
      self
    end
    def digest
      def type
        if defined? @rc['default']['digest'] \
        and @rc['default']['digest'] != nil
          case @rc['default']['digest']
          when /^sha(?:2|256)?$/; 'sha256'
          when /^md5$/;           'md5'
          else                    'sha256'
          end
        else                      'sha256'
        end
      end
      def length
        case digest.type
        when /sha256/; 64
        when /md5/;    32
        else           64
        end
      end
      def pattern
        "[0-9a-f]{#{digest.length}}" #/[0-9a-f]{#{digest.length}}/
      end
      self
    end
    def program
      def text_editor
        if defined? @rc['program_select']['editor'] \
        and @rc['program_select']['editor'] =~/\S\S+/
          @rc['program_select']['editor']
        elsif defined? @rc['program_select']['text_editor'] \
        and @rc['program_select']['text_editor'] =~/\S\S+/
          @rc['program_select']['text_editor']
        else 'editor'                                                            #'gvim -c :R -c :S'
        end
      end
      def pdf_viewer
        ((defined? @rc['program_select']['pdf_viewer']) \
        && @rc['program_select']['pdf_viewer'] =~/\S\S+/) \
        ? @rc['program_select']['pdf_viewer']
        : 'pdf-viewer'                                                        #'evince'
      end
      def web_browser
        if defined? @rc['program_select']['www_browser'] \
        and @rc['program_select']['www_browser'] =~/\S\S+/
          @rc['program_select']['www_browser']
        elsif defined? @rc['program_select']['web_browser'] \
        and @rc['program_select']['web_browser'] =~/\S\S+/
          @rc['program_select']['web_browser']
        else 'x-www-browser'                                                      #'firefox' 'iceweasel' 'kazehakase' 'galeon'
        end
      end
      def www_browser
        web_browser
      end
      def console_web_browser
        if defined? @rc['program_select']['console_www_browser'] \
        and @rc['program_select']['console_www_browser'] =~/\S\S+/
          @rc['program_select']['console_www_browser']
        elsif defined? @rc['program_select']['console_web_browser'] \
        and @rc['program_select']['console_web_browser'] =~/\S\S+/
          @rc['program_select']['console_web_browser']
        else 'console-www-browser'                                             #'lynx' 'links' 'links2' 'elinks' 'w3m'
        end
      end
      def console_www_browser
        web_browser
      end
      def epub_viewer
        ((defined? @rc['program_select']['epub_viewer']) \
        && @rc['program_select']['epub_viewer'] =~/\S\S+/) \
        ? @rc['program_select']['epub_viewer']
        : 'ebook-viewer'                                                    #'calibre' 'fbreader'
      end
      def xml_viewer
        ((defined? @rc['program_select']['xml_viewer']) \
        && @rc['program_select']['xml_viewer'] =~/\S\S+/) \
        ? @rc['program_select']['xml_viewer']
        : text_editor
      end
      def xml_editor
        xml_viewer
      end
      def odf_viewer
        ((defined? @rc['program_select']['odf_viewer']) \
        && @rc['program_select']['odf_viewer'] =~/\S\S+/) \
        ? @rc['program_select']['odf_viewer']
        : 'lowriter'                                                           #'odf-viewer','oowriter'
      end
      def manpage_viewer
        'man'
      end
      def manpage_generator
        ((defined? @rc['program_select']['man']) \
        && @rc['program_select']['man'] =~/\S\S+/) \
        ? @rc['program_select']['man']
        : 'nroff -man'                                                        #'nroff -man' #'groff -man -Tascii'
      end
      def texinfo
        ((defined? @rc['program_select']['info_viewer']) \
        && @rc['program_select']['info_viewer'] =~/\S\S+/) \
        ? @rc['program_select']['info_viewer']
        : 'pinfo -f'                                                          #'pinfo -f' 'info' 'tkinfo'
      end
      def file_encoding
        is=(defined? @rc['program_set']['file_encoding']) ? @rc['program_set']['encoding'] : ''
        (is.nil? || is==true) ? 'encoding' : is
      end
      def wc #wordcount
        is=(defined? @rc['program_set']['wc']) ? @rc['program_set']['wc'] : ''
        (is.nil? || is==true) ? 'wc' : is
      end
      def tidy
        is=(defined? @rc['program_set']['tidy']) ? @rc['program_set']['tidy'] : nil
        (is.nil? || is==true) ? 'tidy' : is
      end
      def rmagick
        is=(defined? @rc['program_set']['rmagick']) ? @rc['program_set']['rmagick'] : nil
        (is.nil? || is==true) ? 'rmagick' : is
      end
      def rexml                                                                  #should be part of ruby 1.8 but apparently not always
        is=(defined? @rc['program_set']['rexml']) ? @rc['program_set']['rexml'] : ''
        (is.nil? || is==true) ? 'rexml' : is
      end
      def pdflatex
        is=(defined? @rc['program_set']['pdflatex']) ? @rc['program_set']['pdflatex'] : ''
        (is.nil? || is==true) ? 'pdflatex' : is
      end
      def postgresql
        is=(defined? @rc['program_set']['postgresql']) ? @rc['program_set']['postgresql'] : ''
        (is.nil? || is==true) ? 'postgresql' : is
      end
      def sqlite
        is=(defined? @rc['program_set']['sqlite']) ? @rc['program_set']['sqlite'] : ''
        (is.nil? || is==true) ? 'sqlite' : is
      end
      self
    end
    def i18n
      def language                                                             # language settings
        m=/.+\/\S+?\~(\S+)/
        pwd=Dir.pwd
        conf=(defined? @rc['default']['language']) ? @rc['default']['language'] : nil
        l=if pwd=~ m;                             pwd[m,1]                    #2 directory: by visible directory name
        elsif conf; @rc['default']['language']                                  #3 config: from sisurc.yaml
        else                                      defaults[:language]          #4 sisu: program default
        end                                                                     #1 document: param gets
        SiSU_Env::StandardiseLanguage.new(l)
      end
      #def multilingual
      #  x=(defined? @rc['output_structure']['multilingual'] \
      #  && @rc['output_structure']['multilingual'] ==true) \
      #  ? true : false
      #end
      #def bundle
      #  x=(defined? @rc['output_structure']['bundle'] \
      #  && @rc['output_structure']['bundle'] ==true) \
      #  ? true : false
      #end
      def lang_filename(l)
        @lang={}
        x=if output_dir_structure.by_language_code?
          (( defined? @rc['default']['language_file']) \
          && @rc['default']['language_file'] != nil) \
          ? @rc['default']['language_file']
          : 1
        else 0
        end
        if (l != defaults[:language_code]) \
        or (language.code != defaults[:language_code]) #watch
          if x==1;    @lang[:pre],@lang[:mid],@lang[:post]="#{l}.",'',''
          elsif x==2; @lang[:pre],@lang[:mid],@lang[:post]='',".#{l}",''
          elsif x==3; @lang[:pre],@lang[:mid],@lang[:post]='','',".#{l}"
          else        @lang[:pre],@lang[:mid],@lang[:post]='','',''
          end
        else          @lang[:pre],@lang[:mid],@lang[:post]='','',''
        end
        @lang
      end
      self
    end
    def file_encoding
      is=''
      if defined? @rc['program_set']['file_encoding'];  is=@rc['program_set']['encoding']
      end
      if is.nil? \
      or is==true
        is='encoding'
      end
      is
    end
    def papersize                                                              # paper settings, default overidden in param if set within document
      (defined? @rc['default']['papersize']) \
      ? @rc['default']['papersize'].downcase
      : (defaults[:papersize].downcase)
    end
    def odf_structure
      FileUtils::rm_rf(processing_path.processing_path.odf_pth)
      FileUtils::mkdir_p(processing_path.processing_path.odf_pth)
      system("unzip -q #{path.share}/#{SiSU_version_dir}/odf/odt.zip -d      #{processing_path.odf_pth}")
    end
    def sisupod_gen(fns_pod)
      sisupod_gen_v3(fns_pod)
    end
    def sisupod_gen_v3(fns_pod)
      pwd=Dir.pwd
      sisupod_processing_path="#{processing_path.processing}/#{Gt[:sisupod]}"
      if FileTest.directory?(sisupod_processing_path) \
      or FileTest.file?(sisupod_processing_path)
        FileUtils::rm_rf(sisupod_processing_path)
      end
      unless FileTest.directory?(sisupod_processing_path)
        FileUtils::mkdir_p(sisupod_processing_path)
      end
      f_pod=if FileTest.file?("#{Dir.pwd}/#{fns_pod}")
        "#{Dir.pwd}/#{fns_pod}"
      elsif FileTest.file?(fns_pod)
        fns_pod
      end
      if f_pod \
      && FileTest.file?(f_pod)
        (SiSU_Env::SystemCall.new.program_found?('tree')) \
        ? "tree #{processing_path.processing}/#{Gt[:sisupod]}"
        : ''
        if FileTest.directory?(processing_path.processing)
          Dir.chdir(processing_path.processing)
          system(%{tar xJf #{f_pod}})
          Dir.chdir(pwd)
        end
        #system(tree)                                                          #enable if (/[vVM]/)
      else
        SiSU_Screen::Ansi.new('',"*WARN* file not found: #{fns_pod}").warn unless @cmd=~/q/
      end
      sisupod_processing_path
    end
    def sisupod_gen_v2(fns_pod)
      sisupod_processing_path="#{processing_path.processing}/#{Gt[:sisupod]}"
      if FileTest.directory?(sisupod_processing_path) \
      or FileTest.file?(sisupod_processing_path)
        FileUtils::rm_rf(sisupod_processing_path)
      end
      unless FileTest.directory?(sisupod_processing_path)
        FileUtils::mkdir_p(sisupod_processing_path)
      end
      (FileTest.file?(fns_pod)) \
      ? system("unzip -q #{fns_pod} -d #{processing_path.processing}")
      : (SiSU_Screen::Ansi.new('',"*WARN* file not found: #{fns_pod}").warn unless @cmd=~/q/)
      sisupod_processing_path
    end
  end
  class InfoProcessingFlag
    attr_accessor :color,:cf_0,:cf_1,:cf_2,:cf_3,:cf_4,:cf_5
    def initialize
      @rc=GetInit.new.sisu_yaml.rc
    end
    def color                                                                  #processing flag shortcuts
      (defined? @rc['flag']['color']) ? @rc['flag']['color'] : false
    end
    def cf_0                                                                   #processing flag shortcuts
      if defined? @rc['flag']['default'] \
      and @rc['flag']['default'].is_a?(String)
        @rc['flag']['default']
      else                               '-NQhewpotbxXdyYv'
      end
    end
    def cf_1                                                                   #processing flag shortcuts
      if defined? @rc['flag']['i'] \
      and @rc['flag']['i'].is_a?(String)
        @rc['flag']['i']
      else                               '-Qhewpoty'
      end
    end
    def cf_2                                                                   #processing flag shortcuts
      if defined? @rc['flag']['ii'] \
      and @rc['flag']['ii'].is_a?(String)
        @rc['flag']['ii']
      else                               '-NQhewpotbxXdy'
      end
    end
    def cf_3                                                                   #processing flag shortcuts
      if defined? @rc['flag']['iii'] \
      and @rc['flag']['iii'].is_a?(String)
        @rc['flag']['iii']
      else                               '-NQhewpotbxXdyY'
      end
    end
    def cf_4                                                                   #processing flag shortcuts
      if defined? @rc['flag']['iv'] \
      and @rc['flag']['iv'].is_a?(String)
        @rc['flag']['iv']
      else                               '-NQhewpotbxXdDyY --update'
      end
    end
    def cf_5                                                                   #processing flag shortcuts
      if defined? @rc['flag']['v'] \
      and @rc['flag']['v'].is_a?(String)
        @rc['flag']['v']
      else                               '-NQhewpotbxXdDyYv --update'
      end
    end
  end
  class InfoSettings < InfoEnv
    def permission?(prog)                                                      #program defaults
      (defined? @rc['permission_set'][prog]) \
      ? @rc['permission_set'][prog]
      : false
    end
    def program?(prog)                                                         #program defaults
      (defined? @rc['program_set'][prog]) \
      ? @rc['program_set'][prog]
      : false
    end
  end
  class FileMap < InfoEnv
    attr_accessor :local_sisu_source
    def initialize(opt='') #watch / REVIEW
      super()
      @opt=opt #,opt.fns,opt.cmd
      @env=(@opt.fns && !(@opt.fns.empty?) \
      ? (SiSU_Env::InfoEnv.new(@opt.fns))
      : (SiSU_Env::InfoEnv.new('dummy.sst')))
      ft=[]
      if @opt.act[:dal][:set]==:on
        @md=SiSU_Param::Parameters.new(@opt).get
        if @md \
        and defined? @md.fn \
        and @md.fn        # used for by_language_code?
          if @md.opt.act[:html][:set]==:on                  #% --html, -h -H
            ft << @md.fn[:html]
          end
          if @md.opt.act[:concordance][:set]==:on           #% --concordance, -w
            ft << @md.fn[:concordance]
          end
          if @md.opt.act[:manifest][:set]==:on              #% --manifest, -y
            ft << @md.fn[:manifest]
          end
          if @md.opt.act[:txt][:set]==:on                   #% --txt, -t -a
            ft << @md.fn[:plain]
          end
          if @md.opt.act[:xhtml][:set]==:on                 #% --xhtml, -b xhtml
            ft << @md.fn[:xhtml]
          end
          if @md.opt.act[:epub][:set]==:on                  #% --epub, -e
            ft << @md.fn[:epub]
          end
          if @md.opt.act[:manpage][:set]==:on               #% --manpage, -i
            ft << @md.fn[:manpage]
          end
          if @md.opt.act[:hash_digests][:set]==:on          #% --hash-digests, -N digest tree
            ft << @md.fn[:digest]
          end
          if @md.opt.act[:odt][:set]==:on                   #% --odt, -o opendocument
            ft << @md.fn[:odf]
          end
          if @md.opt.act[:pdf][:set]==:on                   #% --pdf-l --pdf, -p latex/ texpdf
            ft << @md.fn[:pdf_l] << @md.fn[:pdf_p]
          end
          if @md.opt.act[:share_source][:set]==:on
            ft << @md.fns
          end
          if @md.opt.act[:sisupod][:set]==:on               #% --sisupod, -S make sisupod
            ft << @md.fn[:sisupod]
          end
          if @md.opt.act[:xml_sax][:set]==:on               #% --xml-sax, -x xml sax type
            ft << @md.fn[:sax]
          end
          if @md.opt.act[:xml_dom][:set]==:on               #% --xml-dom, -X xml dom type
            ft << @md.fn[:dom]
          end
          if @md.opt.act[:xml_scaffold_structure_sisu][:set]==:on          #% --xml-scaffold --xml-scaffold-sisu
            ft << @md.fn[:xml_scaffold_structure_sisu]
          end
          if @md.opt.act[:xml_scaffold_structure_collapse][:set]==:on      #% --xml-scaffold-collapse
            ft << @md.fn[:xml_scaffold_structure_collapse]
          end
          @fnb=@md.fnb
        else                                                                     # still needed where/when param is not parsed
          if @opt.act[:html][:set]==:on                  #% --html, -h -H
            ft << '.html' << '.html.??'
          end
          if @opt.act[:concordance][:set]==:on           #% --concordance, -w
            ft << 'concordance.html' << '??.concordance.html' << 'concordance.??.html'
          end
          if @opt.act[:manifest][:set]==:on              #% --manifest, -y
            ft << 'sisu_manifest.html' << '??.sisu_manifest.html' << 'sisu_manifest.??.html'
          end
          if @opt.act[:txt][:set]==:on                   #% --txt, -t -a
            ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt'
          end
          if @opt.act[:xhtml][:set]==:on                 #% --xhtml, -b xhtml
            ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml'
          end
          if @opt.act[:epub][:set]==:on                  #% --epub, -e
            ft  << @fnb << '.epub'
          end
          if @opt.act[:manpage][:set]==:on               #% --manpage, -i
            ft << '.1' << '??.man.1' << 'man.??.1'
          end
          if @opt.act[:hash_digests][:set]==:on          #% --hash-digests, -N digest tree
            ft << 'digest.txt' << '??.digest.txt' << 'digest.??.txt'
          end
          if @opt.act[:odt][:set]==:on                   #% --odt, -o opendocument
            ft << 'opendocument.odt' << '??.opendocument.odt' << 'opendocument.??.odt'
          end
          if @opt.act[:pdf][:set]==:on                   #% --pdf-l --pdf, -p latex/ texpdf
            ft << 'landscape.pdf' << 'portrait.pdf' << '.pdf'
          end
          if @opt.act[:share_source][:set]==:on
            ft << '.sst' << '.ssi' << '.ssm'
          end
          if @opt.act[:sisupod][:set]==:on               #% --sisupod, -S make sisupod
            ft << '.zip'
          end
          if @opt.act[:xml_sax][:set]==:on               #% --xml-sax, -x xml sax type
            ft << 'sax.xml' << '??.sax.xml' << 'sax.??.xml'
          end
          if @opt.act[:xml_dom][:set]==:on               #% --xml-dom, -X xml dom type
            ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml'
          end
          if @opt.act[:xml_scaffold_structure_sisu][:set]==:on          #% --xml-scaffold --xml-scaffold-sisu
            ft << 'scaffold.xml' << '??.scaffold.xml' << 'scaffold.??.xml'
          end
          if @opt.act[:xml_scaffold_structure_collapse][:set]==:on      #% --xml-scaffold-collapse
            ft << 'scaffold.xml' << '??.scaffold.xml' << 'scaffold.??.xml'
          end
        end
        ft=ft.uniq
        filetypes=ft.join(',')
        @filetypes=if filetypes !~/..+/;             ''   # -r called alone, copy all
        elsif @opt.cmd =~/u/;                        ''   # -u added, copy all, (used to create remote directory tree see output path), not the usual function of -u
        elsif filetypes =~/\S+?,\S+/;                '*{' + filetypes + '}' # more than one relevant file type
        else                                         '*' + filetypes # one relevant file type
        end
        @source_path=(@fnb && !(@fnb.empty?) \
        ? "#{@env.path.output}/#{@fnb}"
        : @env.path.output)
        @source_path_epub=(@fnb && !(@fnb.empty?) \
        ? "#{@env.path.output}/epub"
        : @env.path.output_epub)
        @source_path_src=(@fnb && !(@fnb.empty?) \
        ? "#{@env.path.output}/src"
        : @env.path.output_src)
        @source_path_pod=(@fnb && !(@fnb.empty?) \
        ? "#{@env.path.output}/pod"
        : @env.path.output_pod)
        @source_path_harvest=(@fnb && !(@fnb.empty?) \
        ? "#{@env.path.output}/manifest"
        : @env.path.output_harvest)
        @local_sisu_source=(@filetypes =~/\S/) \
        ? "#{@source_path}/#{@filetypes}"
        : @source_path
      end
      if @opt.act[:rsync][:set]==:on
      end
    end
  end
  class CleanOutput
    require 'fileutils'
      include FileUtils::Verbose
    def initialize(opt)
      @opt=opt
      z=SiSU_Env::FileMap.new(opt)
      zap=z.local_sisu_source
      if opt.cmd =~ /h/i
        zap=Dir.glob(zap).join(' ')
        @zap=if opt.cmd !~ /w/
          zap.gsub(/#{@source_path}\/concordance.html/,'')
        else zap
        end
      end
      @env=SiSU_Env::InfoEnv.new
    end
    def zap
      def deletion(fn)
        if FileTest.file?(fn)==true
          File.delete(fn)
          tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns, 'remove: ' + fn)
          tell.warn unless @opt.cmd =~/q/
        end
      end
      def remove_output
        if @opt.act[:maintenance][:set] == :on
          m=InfoFile.new(@opt.fnc)
          tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns, 'remove maintenance files from: ' + @env.processing_path.dal)
          tell.warn unless @opt.cmd =~/q/
          deletion(m.marshal.dal_content)
          deletion(m.marshal.dal_idx_sst_rel_html_seg)
          deletion(m.dal_idx_sst_rel)
          deletion(m.dal_idx_html)
          deletion(m.dal_idx_xhtml)
          deletion(m.dal_metadata)
          deletion(m.dal_map_nametags)
          deletion(m.dal_map_ocn_htmlseg)
          deletion(m.html_tune)
        end
        md=SiSU_Param::Parameters.new(@opt).get
        f=SiSU_Env::FileOp.new(md)
        deletion(f.place_file.html_segtoc.dir)
        deletion(f.place_file.html_scroll.dir)
        deletion(f.place_file.html_book_index.dir)
        deletion(f.place_file.html_concordance.dir)
        deletion(f.place_file.epub.dir)
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_letter}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_l_letter}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_a4}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_l_a4}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_a5}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_l_a5}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_b5}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_l_b5}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_legal}")
        deletion("#{f.output_path.pdf.dir}/#{f.base_filename.pdf_p_legal}")
        deletion(f.place_file.odt.dir)
        deletion(f.place_file.xhtml.dir)
        deletion(f.place_file.xml_sax.dir)
        deletion(f.place_file.xml_dom.dir)
        deletion(f.place_file.xml_scaffold_structure_sisu.dir)
        deletion(f.place_file.xml_scaffold_structure_collapse.dir)
        deletion(f.place_file.info.dir)
        deletion(f.place_file.manpage.dir)
        deletion(f.place_file.sqlite_discrete.dir)
        deletion(f.place_file.txt.dir)
        deletion(f.place_file.hash_digest.dir)
        deletion(f.place_file.manifest.dir)
        deletion(f.place_file.qrcode_md.dir)
        deletion(f.place_file.qrcode_title.dir)
        deletion(f.place_file.src.dir)
        deletion(f.place_file.sisupod.dir)
      end
      self
    end
  end
  class InfoRemoteHost
    def initialize
      @rc=GetInit.new.sisu_yaml.rc
    end
    def remote_host #see InfoRemote remote_host_base_general
      r=[]
      r=if (defined? @rc['remote'] \
      and @rc['remote'].is_a?(Array))
        r_array=@rc['remote']
        r_array.each_with_index do |renv,i|
          r[i]={}
          if defined? renv['user'] \
          and defined? renv['host']
          end
          r[i][:user]=renv['user']
          r[i][:host]=renv['host']
          r[i][:path]=if defined? renv['path']
            renv['path']
          else ''
          end
          r[i][:name]="#{r[i][:user]}@#{r[i][:host]}:#{r[i][:path]}"
        end
        r
      elsif (defined? @rc['remote'] \
      and @rc['remote'].is_a?(Hash) \
      and defined? @rc['remote']['user'] \
      and defined? @rc['remote']['host'])
        r[0]={}
        r[0][:user]=@rc['remote']['user']
        r[0][:host]=@rc['remote']['host']
        r[0][:path]=if defined? @rc['remote']['path']
          @rc['remote']['path']
        else ''
        end
        r[0][:name]="#{r[0][:user]}@#{r[0][:host]}:#{r[0][:path]}"
        r
      else
        r[0]={}
        r[0][:name]='.'
        r[0][:user]=''
        r[0][:host]=''
        r[0][:path]=''
        #puts "no remote host or user"
        r
      end
    end
    def rhost
      def r1
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[0][:name]) \
        ? (SiSU_Env::InfoRemoteHost.new.remote_host[0][:name])
        : nil
      end
      def r2
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[1][:name]) \
        ? (SiSU_Env::InfoRemoteHost.new.remote_host[1][:name])
        : nil
      end
      def r3
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[2][:name]) \
        ? (SiSU_Env::InfoRemoteHost.new.remote_host[2][:name])
        : nil
      end
      def r4
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[3][:name]) \
        ? (SiSU_Env::InfoRemoteHost.new.remote_host[3][:name])
        : nil
      end
      def r5
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[4][:name]) \
        ? (SiSU_Env::InfoRemoteHost.new.remote_host[4][:name])
        : nil
      end
      def r6
        (defined? SiSU_Env::InfoRemoteHost.new.remote_host[5][:name]) \
        ? (@ls + SiSU_Env::InfoRemoteHost.new.remote_host[5][:name])
         : nil
      end
      self
    end
  end
  class InfoRemote < FileMap
    @@flag_remote=false
    require 'socket'
    def initialize(opt)
      super(opt) #
      @opt=opt
      @rc=GetInit.new.sisu_yaml.rc
    end
    def remote_host_base_general
      SiSU_Env::InfoRemoteHost.new.remote_host
    end
    def remote_host_base
      remote_host_base_general.each do |remote_conn|
        @@flag_remote=true if remote_conn[:name] =~/\S+?@\S+/
      end
      remote_host_base_general
    end
    def scp                                                                    #sort out later using ruby libraries #not ideal, first time each file is sent, -r must be called separately for subdir to be built
      def document
        self.remote_host_base.each do |remote_conn|
          local_gen=@source_path
          remote_gen=case @opt.cmd
          when /u/;                "#{remote_conn[:name]}/#{@env.path.stub_pwd}/."             #creates remote directory tree, this is not the usual function of u
          when /[abhHNopwxXy]/;    "#{remote_conn[:name]}/#{@env.path.stub_pwd}/#{@fnb}/."
          else                     "#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
          end
          local_epub=@source_path_epub
          local_src=@source_path_src
          local_pod=@source_path_pod
          remote_epub="#{remote_conn[:name]}/#{@env.path.stub_epub}/."
          remote_src="#{remote_conn[:name]}/#{@env.path.stub_src}/."
          remote_pod="#{remote_conn[:name]}/#{@env.path.stub_pod}/."
          src_txt=@opt.fnc
          src_pod=@opt.fncb.gsub(/(\.ss[mt])(?:\.sst)?$/,'\1.txz')
          if (local_gen =~/\S/ \
          and local_gen !~/\/\//) \
          and (remote_gen =~/\S/ \
          and remote_gen !~/\/\//) \
          and @@flag_remote==true \
          and @opt.cmd !~/U/
            SiSU_Env::SystemCall.new(local_gen,remote_gen).scp
            if FileTest.file?("#{local_src}/#{src_txt}")
              SiSU_Env::SystemCall.new("#{local_src}/#{src_txt}",remote_src).scp
            end
            if FileTest.file?("#{local_pod}/#{src_pod}")
              SiSU_Env::SystemCall.new("#{local_src}/#{src_pod}",remote_pod).scp
            end
            if FileTest.file?("#{local_epub}/#{@opt.fnb}.epub")
              SiSU_Env::SystemCall.new("#{local_epub}/#{@opt.fnb}.epub",remote_epub,@opt.cmd).scp
            end
          elsif  @opt.cmd =~/U/
            puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            puts "#{local_gen} -> #{remote_gen}"
            if FileTest.file?("#{local_src}/#{src_doc}")
              puts "#{local_src}/#{src_doc}* -> #{remote_src}"
            end
            if FileTest.file?("#{local_pod}/#{src_doc}.txz")
              puts "#{local_pod}/#{src_doc}* -> #{remote_pod}"
            end
          else
            puts 'suspect scp request, ignored'
            puts "#{local_gen} -> #{remote_gen} remote flag: #{@@flag_remote}"
            puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          end
        end
      end
      def site_base                                                               #base site
        self.remote_host_base.each do |remote_conn|
          local=@source_path
          remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
          if defined? @rc['permission_set']['remote_base_site'] \
          and @rc['permission_set']['remote_base_site'] \
          and @@flag_remote==true \
          and @opt.cmd !~/U/
            puts "begin scp_base: #{local} -> #{remote}"
            SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).scp
          elsif @opt.cmd =~/U/
            puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            puts "begin scp_base: #{local} -> #{remote}"
            puts "#{local}/#{@env.path.style}/ -> #{remote}"
          else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          end
        end
      end
      def site_base_all                                                           #base site
        self.remote_host_base.each do |remote_conn|
          local=@source_path
          remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
          if defined? @rc['permission_set']['remote_base_site'] \
          and @rc['permission_set']['remote_base_site'] \
          and @@flag_remote==true \
          and @opt.cmd !~/U/
            puts "begin scp_base_all: #{local} -> #{remote}"
            SiSU_Env::SystemCall.new("#{local}/_sisu/image_sys/",remote).scp
            SiSU_Env::SystemCall.new("#{local}/_sisu/image/",remote).scp
            SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).scp
          elsif @opt.cmd =~/U/
            puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            puts "scp_base_all: #{local} -> #{remote}"
            puts "#{local}/_sisu/image_sys/ -> #{remote}"
            puts "#{local}/_sisu/image/ -> #{remote}"
            puts "#{local}/#{@env.path.style}/ -> #{remote}"
          else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          end
        end
      end
      self
    end
    def rsync
      def document
        f=(@opt.act[:dal][:set]==:on) \
        ? SiSU_Env::FileOp.new(@md)
        : nil
        if f
          self.remote_host_base.each do |remote_conn|
            local_gen=@source_path
            #local_gen_image="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
            #local_gen_image_external="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
            remote_gen="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
            remote_rel=remote_conn[:name] + '/' + f.output_path.stub.rcp
            @opt.fnc
            if (local_gen =~/\S/ \
            and local_gen !~/\/\//) \
            and (remote_gen =~/\S/ \
            and remote_gen !~/\/\//) \
            and @@flag_remote==true \
            and @opt.cmd !~/U/
#             SiSU_Env::SystemCall.new("#{local_src}/#{src_txt}",remote_src,@opt.cmd).rsync
              #delete_extra_files='--delete' # '--delete-after'
              inp=[]
              if (@opt.act[:html][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.html_scroll.dir)
                inp << f.output_path.html_seg.rel << f.place_file.html_scroll.rel
              end
              if (@opt.act[:concordance][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.html_concordance.dir)
                inp << f.place_file.html_concordance.rel
              end
              if (@opt.act[:epub][:set]==:on \
              || @opt.cmd =~/^-R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.epub.dir)
                inp << f.place_file.epub.rel
              end
              if (@opt.act[:odt][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.odt.dir)
                inp << f.place_file.odt.rel
              end
              if (@opt.act[:xhtml][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.xhtml.dir)
                inp << f.place_file.xhtml.rel
              end
              if (@opt.act[:xml_sax][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.xml_sax.dir)
                inp << f.place_file.xml_sax.rel
              end
              if (@opt.act[:xml_dom][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.xml_dom.dir)
                inp << f.place_file.xml_dom.rel
              end
              if (@opt.act[:xml_scaffold_structure_sisu][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.xml_scaffold_structure_sisu.dir)
                inp << f.place_file.xml_scaffold_structure_sisu.rel
              end
              if (@opt.act[:xml_scaffold_structure_collapse][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.xml_scaffold_structure_collapse.dir)
                inp << f.place_file.xml_scaffold_structure_collapse.rel
              end
              if (@opt.act[:txt][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.txt.dir)
                inp << f.place_file.txt.rel
              end
              if (@opt.act[:manpage][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*i[mqvVM]*$/) \
              && FileTest.file?(f.place_file.manpage.dir)
                inp << f.place_file.manpage.rel
              end
              if (@opt.act[:texinfo][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*I[mqvVM]*$/) \
              && FileTest.file?(f.place_file.info.dir)
                inp << f.place_file.info.rel
              end
              if (@opt.act[:hash_digests][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.hash_digest.dir)
                inp << f.place_file.hash_digest.rel
              end
              if (@opt.act[:share_source][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.src.dir)
                inp << f.place_file.src.rel
              end
              if (@opt.act[:sisupod][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.sisupod.dir)
                inp << f.place_file.sisupod.rel
              end
              if (@opt.act[:pdf][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/)
                inp <<=(@opt.dir_structure_by == :filename) \
                ? (f.output_path.pdf.rel + '/*.pdf')
                : (f.output_path.pdf.rel + '/' + @opt.fnb + '*.pdf')
              end
              if (@opt.act[:sqlite_discrete][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.sqlite_discrete.dir)
                inp << f.place_file.sqlite_discrete.rel
              end
              if (@opt.act[:qrcode][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.qrcode_md.dir)
                inp << f.place_file.qrcode_md.rel << f.place_file.qrcode_title.rel
              end
              if (@opt.act[:manifest][:set]==:on \
              || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
              && FileTest.file?(f.place_file.manifest.dir)
                inp << f.place_file.manifest.rel
              end
              local_gen=if inp.length > 0
                inp.join(' ')
              else ''
              end
              local_css,images,images_system='','',''
              images=images_skin=images_system=local_css=''
              if @opt.cmd =~/[hwbxX]/ \
              && (defined? @md.ec[:image]) \
              && (@md.ec[:image].length > 0)
                images=f.place_file.images.rel + '/' + @md.ec[:image].join(" #{f.output_path.images.rel}/")
              end
              if @opt.cmd =~/[yhwbxX]/ \
              && (defined? @md.ec[:image]) \
              && (@md.ec[:image].length > 0)
                local_css=f.output_path.css.rel
                images_system='_sisu/image_sys'
              end
              begin
                ##create file structure without copying files?:
                ##rsync -av -f"+ */" -f"- *" f.output_path.base.dir remote:./path/.
                #local_dirs=%{-f"+ */" -f"- *" #{f.output_path.base.dir}/*}
                #SiSU_Env::SystemCall.new(local_dirs,remote_gen,@opt.cmd).rsync
                local=local_gen + ' ' + images + ' ' + images_skin + ' ' + images_system + ' ' + local_css
                SiSU_Env::SystemCall.new(local,remote_rel,@opt.cmd).rsync('--relative',f.output_path.base.dir)
              rescue
                p __LINE__.to_s + ':' + __FILE__
                local_dirs=%{--include='*/' --exclude='*' #{f.output_path.base.dir}}
                SiSU_Env::SystemCall.new(local_dirs,remote_gen,@opt.cmd).rsync
              end
            elsif @opt.cmd =~/U/
              puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
              puts "#{local_gen} -> #{remote_gen}"
              if FileTest.file?("#{local_src}/#{src_doc}") \
              or FileTest.file?("#{local_src}/#{src_doc}.txz")
                puts "#{local_src}/#{src_doc}* -> #{remote_src}"
              end
            else
              puts 'suspect rsync request, ignored'
              puts "#{local_gen} -> #{remote_gen} remote flag: #{@@flag_remote}"
              puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            end
          end
        end
      end
      def site_harvest
        self.remote_host_base.each do |remote_conn|
          local=@source_path_harvest
          l_rel="#{@env.path.webserv}/#{@env.path.stub_pwd}"
          lng='en'
          if @env.output_dir_structure.by? == :language
            ldest="#{lng}/manifest"
            files="#{ldest}/authors.html #{ldest}/topics.html"
          elsif @env.output_dir_structure.by? == :filetype
            ldest="manifest"
            files="#{ldest}/authors.#{lng}.html #{ldest}/topics.#{lng}.html"
          elsif @env.output_dir_structure.by? == :filename
            files="#{l_rel}/authors.#{lng}.html #{l_rel}/topics.#{lng}.html"
          end
          remote="#{remote_conn[:name]}/#{@opt.base_stub}"
          if @opt.act[:harvest][:set] \
          && @opt.act[:rsync][:set]
            (@env.output_dir_structure.by? == :filename) \
            ? (SiSU_Env::SystemCall.new(files,remote).rsync)
            : (SiSU_Env::SystemCall.new(ldest,remote).rsync('--relative',l_rel))
          elsif @opt.cmd =~/U/
            puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            puts "rsync_harvest: #{local} -> #{remote}"
          else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          end
        end
      end
      def site_base                                                             #base site
        ldest='_sisu/*'
        l_rel="#{@env.path.webserv}/#{@env.path.stub_pwd}"
        image_sys="#{@env.path.webserv}/_sisu/image_sys"
        self.remote_host_base.each do |remote_conn|
          remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}"
          remote_conf="#{remote_conn[:name]}/_sisu"
            SiSU_Env::SystemCall.new(image_sys,remote_conf).rsync
            SiSU_Env::SystemCall.new(ldest,remote).rsync('--relative',l_rel)
        end
      end
      def site_base_sync
        self.remote_host_base.each do |remote_conn|
          local=@source_path
          remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
          if defined? @rc['permission_set']['remote_base_site'] \
          and @rc['permission_set']['remote_base_site'] \
          and @@flag_remote==true \
          and @opt.cmd !~/U/
            delete_extra_files='--delete' # '--delete-after'
            puts "begin rsync_base_sync: #{local} -> #{remote}"
            SiSU_Env::SystemCall.new("#{local}/_sisu/image_sys/",remote).rsync(delete_extra_files)
            SiSU_Env::SystemCall.new("#{local}/_sisu/image/",remote).rsync(delete_extra_files)
            SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).rsync(delete_extra_files)
          elsif @opt.cmd =~/U/
            puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
            puts "rsync_base_sync: #{local} -> #{remote}"
            puts "#{local}/_sisu/image_sys/ -> #{remote}"
            puts "#{local}/_sisu/image/ -> #{remote}"
            puts "#{local}/#{@env.path.style}/ -> #{remote}"
          else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          end
        end
      end
      self
    end
    def rsync_sitemaps                                                         #sitemap directory
      self.remote_host_base.each do |remote_conn|
        local="#{@source_path}/sitemapindex.xml"
        remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
        if @@flag_remote
          delete_extra_files='--delete' # '--delete-after'
          SiSU_Env::SystemCall.new(local,remote).rsync(delete_extra_files)
        elsif @opt.cmd =~/U/
          puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          puts "rsync_sitemaps: #{local} -> #{remote}"
        else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
        end
      end
    end
  end
  class InfoVersion <InfoEnv
    include Singleton
    require 'rbconfig'
    require 'yaml'
    @@lib_path=nil
    def get_version
      @version={}
      @pwd=ENV['PWD']
      yst_ver=SiSU_path_specified_Version_ \
      ? SiSU_path_specified_Version_
      : "#{defaults[:sisu_share]}/#{SiSU_version_dir}/v/version.yml"
      lib_path=@@lib_path ? @@lib_path : `echo $RUBYLIB`.split(':')
      @@lib_path ||=lib_path
      if File.exist?(yst_ver)
        @version=YAML::load(File::open(yst_ver)) #unless @@noyaml
      end
      @version
    end
    def rbversion
      %x{ruby -v}.strip
    end
  end
  class InfoAbout
    def initialize(color='')
      @color=color
    end
    def sisu_version
      version=SiSU_Env::InfoVersion.instance.get_version
      rb_ver=SiSU_Env::InfoVersion.instance.rbversion
      if version[:version]
        opt_cmd=if defined? @color.cmd \
        and @color.cmd =~/[ck]/
          @color.cmd
        else '-v'
        end
        SiSU_Screen::Ansi.new(opt_cmd,version[:project],version[:version],version[:date_stamp],version[:date],rb_ver).version
      else puts 'SiSU version information not available'
      end
    end
    def sisu_about
      puts <<-WOK
     sisu: documents; markup, structuring, publishing in multiple standard formats, & search
     most (not all) useful commands (are made in a directory containing a sisu markup file &) take the form:
       sisu [action(s)] [filename(s)]
     where filename refers to a valid sisu marked up file, e.g.:
       cd /usr/share/doc/sisu/markup-samples/sisu_manual
       sisu --html --verbose sisu_commands.sst
       sisu --txt --html --epub --odt --pdf --sqlite --manpage --texinfo --concordance --qrcode --verbose sisu.ssm
       cd -
     See output produced, or see man pages: man sisu
     <http://www.sisudoc.org/> <http://www.jus.uio.no/sisu/>
        WOK
    end
  end
  class InfoFile <InfoEnv                                                  #todo unify with FileOp
    def initialize(fns)
      begin
        super(fns)
        @fns=fns
        @env=SiSU_Env::InfoEnv.new(@fns)
        m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm)$/ #watch added match for sss
        @fnn,@fnb,@fnt=@fns[m,1],@fns[m,2],@fns[m,3]
      rescue
        SiSU_Screen::Ansi.new('',$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def basefilename #Remove if possible
      m=/(.+?)\.(?:(?:-|ssm\.)?sst|ssm)$/m
      @fns[m,1]
    end
    def make_file(path,filename)
      (File.writable?("#{path}/.")) \
      ? File.new("#{path}/#{filename}",'w+')
      : (SiSU_Screen::Ansi.new('',"*WARN* is the file or directory writable?, could not create #{filename}").warn)
    end
    def touch_file(path,filename)
      if File.writable?("#{path}/.");
        FileUtils::touch("#{path}/#{filename}")
      else SiSU_Screen::Ansi.new('',"*WARN* is the file or directory writable?, could not create #{filename}").warn
      end
    end
    def make_path(path)
      FileUtils::mkdir_p(path) unless FileTest.directory?(path)
    end
    def marshal
      def dal_content
        "#{@env.processing_path.dal}/#{@fns}.content.rbm"
      end
      def dal_idx_sst_rel_html_seg
        "#{@env.processing_path.dal}/#{@fns}.idx_sst.rbm"
      end
      def dal_idx_sst_rel #used by tex & odf
        "#{@env.processing_path.dal}/#{@fns}.idx_raw.rbm"
      end
      def dal_idx_html
        "#{@env.processing_path.dal}/#{@fns}.idx_html.rbm"
      end
      def dal_idx_xhtml
        "#{@env.processing_path.dal}/#{@fns}.idx_xhtml.rbm"
      end
      def dal_metadata
        "#{@env.processing_path.dal}/#{@fns}.metadata.rbm"
      end
      def dal_map_nametags
        "#{@env.processing_path.dal}/#{@fns}.map_name_tags.rbm"
      end
      def dal_map_ocn_htmlseg
        "#{@env.processing_path.dal}/#{@fns}.map_ocn_htmlseg.rbm"
      end
      def html_tune
        "#{@env.processing_path.tune}/#{@fns}.marshal_tune"
      end
      self
    end
    def write_file_processing
      def html_tune
        File.new("#{@env.processing_path.tune}/#{@fns}.tune",'w+')
      end
      self
    end
    def mkdir #check moved from FileOp, existing mkdir
      def processing
        def dal
          FileUtils::mkdir_p(@env.processing_path.dal) unless FileTest.directory?(@env.processing_path.dal)
        end
        def tune
          FileUtils::mkdir_p(@env.processing_path.tune) unless FileTest.directory?(@env.processing_path.tune)
        end
        self
      end
    end
  end
  class ProcessingSettings
    def initialize(md)
      @md=md
    end
    def cnf_rc #sisurc.yml
      @rc=SiSU_Env::GetInit.new.sisu_yaml.rc
    end
    def env_rc #env rc (including sisurc.yml)
      @env_rc ||=SiSU_Env::InfoEnv.new(@md.fns)
    end
    def doc_rc #document rc, make instructions
      (defined? @md.make) \
      ? @md.make
      : nil
    end
    def cmd_rc_act #command-line rc
      @cmd_rc_act=@md.opt.opt_act
    end
    def build
      def ocn?
        if cmd_rc_act[:ocn][:set]==:on
          true
        elsif cmd_rc_act[:ocn][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.ocn? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.ocn? ==:off
          false
        else
          true
        end
      end
      def toc?
        if cmd_rc_act[:toc][:set]==:on
          true
        elsif cmd_rc_act[:toc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.toc? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.toc? ==:off
          false
        else
          true
        end
      end
      def manifest?
        if cmd_rc_act[:manifest][:set]==:on
          true
        elsif cmd_rc_act[:manifest][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.manifest? \
        and doc_rc.manifest? ==:off
          false
        elsif env_rc.build.manifest? ==:off
          false
        else
          true
        end
      end
      def links_to_manifest?
        if cmd_rc_act[:links_to_manifest][:set]==:on
          true
        elsif cmd_rc_act[:links_to_manifest][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.links_to_manifest? \
        and doc_rc.links_to_manifest? ==:off
          false
        elsif env_rc.build.links_to_manifest? ==:off
          false
        else
          true
        end
      end
      def metadata?
        if cmd_rc_act[:metadata][:set]==:on
          true
        elsif cmd_rc_act[:metadata][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.metadata? \
        and doc_rc.metadata? ==:off
          false
        elsif env_rc.build.metadata? ==:off
          false
        else
          true
        end
      end
      def minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.minitoc? \
        and doc_rc.minitoc? ==:off
          false
        elsif env_rc.build.minitoc? ==:off
          false
        else
          true
        end
      end
      def manifest_minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:manifest_minitoc][:set]==:on \
        || cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:manifest_minitoc][:set]==:off \
        || cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.manifest_minitoc? \
        and (doc_rc.manifest_minitoc? ==:off \
        || doc_rc.minitoc? ==:off)
          false
        elsif env_rc.build.manifest_minitoc? ==:off \
        || env_rc.build.minitoc? ==:off
          false
        elsif minitoc? == false
          false
        else
          true
        end
      end
      def html_minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:html_minitoc][:set]==:on \
        || cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:html_minitoc][:set]==:off \
        || cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_minitoc? \
        and (doc_rc.html_minitoc? ==:off \
        || doc_rc.minitoc? ==:off)
          false
        elsif env_rc.build.html_minitoc? ==:off \
        || env_rc.build.minitoc? ==:off
          false
        elsif minitoc? == false
          false
        else
          true
        end
      end
      def html_top_band?
        if cmd_rc_act[:html_top_band][:set]==:on
          true
        elsif cmd_rc_act[:html_top_band][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_top_band? \
        and doc_rc.html_top_band? ==:off
          false
        elsif env_rc.build.html_top_band? ==:off
          false
        else
          true
        end
      end
      def html_navigation?
        if cmd_rc_act[:html_navigation][:set]==:on
          true
        elsif cmd_rc_act[:html_navigation][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_navigation? \
        and doc_rc.html_navigation? ==:off
          false
        elsif env_rc.build.html_navigation? ==:off
          false
        else
          true
        end
      end
      def html_navigation_bar?
        if cmd_rc_act[:html_navigation_bar][:set]==:on
          true
        elsif cmd_rc_act[:html_navigation_bar][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_navigation_bar? \
        and doc_rc.html_navigation_bar? ==:off
          false
        elsif env_rc.build.html_navigation_bar? ==:off
          false
        else
          true
        end
      end
      def search_form?
        if cmd_rc_act[:search_form][:set]==:on
          true
        elsif cmd_rc_act[:search_form][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_search_form? \
        and doc_rc.search_form? ==:off
          false
        elsif env_rc.build.search_form? ==:off
          false
        else
          true
        end
      end
      def html_search_form?
        if cmd_rc_act[:html_search_form][:set]==:on \
        || cmd_rc_act[:search_form][:set]==:on
          true
        elsif cmd_rc_act[:html_search_form][:set]==:off \
        || cmd_rc_act[:search_form][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_search_form? \
        and (doc_rc.html_search_form? ==:off \
        || doc_rc.search_form? ==:off)
          false
        elsif env_rc.build.html_search_form? ==:off \
        || env_rc.build.search_form? ==:off
          false
        elsif search_form? == false
          false
        else
          true
        end
      end
      def html_right_pane?
        if cmd_rc_act[:html_right_pane][:set]==:on
          true
        elsif cmd_rc_act[:html_right_pane][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_right_pane? \
        and doc_rc.html_right_pane? ==:off
          false
        elsif env_rc.build.html_right_pane? ==:off
          false
        else
          true
        end
      end
      def segsubtoc?
        if cmd_rc_act[:segsubtoc][:set]==:on
          true
        elsif cmd_rc_act[:segsubtoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.segsubtoc? \
        and doc_rc.segsubtoc? ==:off
          false
        elsif env_rc.build.segsubtoc? ==:off
          false
        else
          true
        end
      end
      self
    end
    def output_dir_structure
      def by_language_code?
        if cmd_rc_act[:output_by][:set] == :language
          true
        elsif cmd_rc_act[:output_by][:set] == :filetype \
        or cmd_rc_act[:output_by][:set] == :filename
          false
        elsif cmd_rc_act[:output_by][:set] == :language
          true
        else
          env_rc.output_dir_structure.by_language_code?
        end
      end
      def by_filetype?
        if cmd_rc_act[:output_by][:set] == :filetype
          true
        elsif cmd_rc_act[:output_by][:set] == :language \
        or cmd_rc_act[:output_by][:set] == :filename
          false
        elsif cmd_rc_act[:output_by][:set] == :filetype
          true
        else
          env_rc.output_dir_structure.by_filetype?
        end
      end
      def by_filename?
        if cmd_rc_act[:output_by][:set] == :filename
          true
        elsif cmd_rc_act[:output_by][:set] == :language \
        or cmd_rc_act[:output_by][:set] == :filetype
          false
        elsif cmd_rc_act[:output_by][:set] == :filename
          true
        else
          env_rc.output_dir_structure.by_filename?
        end
      end
      def multilingual?
        by_language_code?
      end
      def dump?
        ((cmd_rc_act[:dump][:bool] \
        &&  cmd_rc_act[:dump][:inst]) \
        || (env_rc.output_dir_structure.dump?)) \
        ? true
        : false
      end
      def redirect?
        ((cmd_rc_act[:redirect][:bool] \
        &&  cmd_rc_act[:redirect][:inst]) \
        || (env_rc.output_dir_structure.redirect?)) \
        ? true
        : false
      end
      def dump_or_redirect?
        ((dump?) || (redirect?)) \
        ? true
        : false
      end
      def by?
        if dump?
          :dump
        elsif redirect?
          :redirect
        elsif by_language_code?
          :language
        elsif by_filetype?
          :filetype
        elsif by_filename?
          :filename
        else #recheck current default
          :language
        end
      end
      self
    end
  end
  class InfoDb < InfoEnv
    @@rc=nil
    def initialize
      @@pwd=@pwd=SiSU_Utils::Path.new.base_markup
      @env=SiSU_Env::InfoEnv.new
      pt=Pathname.new(@pwd)
      r=Px[:lng_lst_rgx]
      u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
      @pwd_stub=pt.realpath.to_s[u,1]
      @rc=@@rc ||=GetInit.new.sisu_yaml.rc
      @defaults=SiSU_Env::InfoEnv.new.defaults
    end
    def share_source?
      ((defined? @rc['db']['share_source']) \
      && @rc['db']['share_source']==true) \
      ? @rc['db']['share_source']
      : false
    end
    def engine
      def default
        ((defined? @rc['db']['engine']['default']) \
        && @rc['db']['engine']['default']=~/postgresql|sqlite/) \
        ? @rc['db']['engine']['default']
        : 'sqlite'
      end
      self
    end
    def psql
      def user(opt=nil)
        if opt \
        and opt.mod.inspect =~/--db-user[=-]["']?(\S+)["']+/
          $1
        elsif opt \
        and opt.mod =~/--webserv[=-]webrick/
          @env.user
        else
          ((defined? @rc['db']['postgresql']['user']) \
          && @rc['db']['postgresql']['user']=~/\S+/) \
          ? @rc['db']['postgresql']['user']
          : @env.user
        end
      end
      def db #db_name
        "#{Db[:name_prefix]}#{@pwd_stub}"
      end
      def port #PGPORT
        ((defined? @rc['db']['postgresql']['port']) \
        && ( @rc['db']['postgresql']['port'] =~/\d+/ \
        || @rc['db']['postgresql']['port'].is_a?(Fixnum))) \
        ? @rc['db']['postgresql']['port']
        : (@defaults[:postgresql_port])
      end
      def password
        ((defined? @rc['db']['postgresql']['password']) \
        && @rc['db']['postgresql']['password']=~/\S+/) \
        ? @rc['db']['postgresql']['password']
        : ''
      end
      def host
        ((defined? @rc['db']['postgresql']['host']) \
        && @rc['db']['postgresql']['host']=~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
        ? @rc['db']['postgresql']['host']
        : ''
      end
      def dbi
        (psql.host =~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
        ? "DBI:Pg:database=#{psql.db};host=#{psql.host};port=#{psql.port}"
        : "DBI:Pg:database=#{psql.db};port=#{psql.port}"
      end
      def conn_dbi
        DBI.connect(psql.dbi,psql.user,psql.db)
      end
     self
    end
    def mysql
      def db
        #"#{Db[:name_prefix]}#{@pwd_stub}"
      end
      def port
        '**'
      end
      def dbi
        "dbi:Mysql:database=#{mysql.db};port=#{mysql.port}"
      end
      self
    end
    def sqlite
      def db
        "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
      end
      def db_discrete(md)
        # "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
      end
      def dbi
        "DBI:SQLite3:#{sqlite.db}" #sqlite3 ?
      end
      def sqlite3
        sqlite.db #sqlite3 ?
      end
      def conn_dbi
        DBI.connect(sqlite.dbi)
      end
      def conn_sqlite3
        SQLite3::Database.new(sqlite.sqlite3)
      end
      self
    end
  end
  class DbOp <InfoDb
    def initialize(md)
      begin
        @md=md
      rescue
        SiSU_Screen::Ansi.new(md.opt.cmd,$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def sqlite_discrete
      def db
        "#{@md.file.output_path.sqlite_discrete.dir}/#{@md.file.base_filename.sqlite_discrete}"
      end
      def dbi
        "DBI:SQLite3:#{sqlite_discrete.db}"
      end
      def sqlite3
        sqlite_discrete.db
      end
      def conn_dbi
        DBI.connect(sqlite_discrete.dbi)
      end
      def conn_sqlite3
        SQLite3::Database.new(sqlite_discrete.sqlite3)
      end
      self
    end
  end
  class FileOp <InfoFile                                                    #todo unify with CreateFile
    def initialize(md,fno='')
      begin
        @md,@fno=md,fno
        @env=SiSU_Env::InfoEnv.new(@md.fns)
      rescue
        SiSU_Screen::Ansi.new(md.opt.cmd,$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def output_dir_structure
      ProcessingSettings.new(@md).output_dir_structure
    end
    def mkdir_initialize                                                       # not used but consider using
      FileUtils::mkdir_p(output_path.base.dir) unless FileTest.directory?(output_path.base.dir)
      FileUtils::mkdir_p("#{output_path.base.dir}/#{@md.fnb}") unless FileTest.directory?("#{output_path.base.dir}/#{@md.fnb}")
      FileUtils::mkdir_p("#{output_path.base.dir}/#{@env.path.style}") unless FileTest.directory?("#{output_path.base.dir}/#{@env.path.style}")
      FileUtils::mkdir_p(@env.processing_path.dal) unless FileTest.directory?(@env.processing_path.dal)
      FileUtils::mkdir_p(@env.processing_path.tune) unless FileTest.directory?(@env.processing_path.tune)
    end
    def path_rel_links
      def html_scroll_2
        if output_dir_structure.by_language_code?
          '../../'
        elsif output_dir_structure.by_filetype?
          '../'
        else
          '../'
        end
      end
      def html_seg_2
        if output_dir_structure.by_language_code?
          '../../../'
        elsif output_dir_structure.by_filetype?
          '../../'
        else
          '../'
        end
      end
      def html_scroll_1
        if output_dir_structure.by_language_code?
          '../'
        elsif output_dir_structure.by_filetype?
          '../'
        else
          './'
        end
      end
      def html_seg_1
        if output_dir_structure.by_language_code?
          '../../'
        elsif output_dir_structure.by_filetype?
          '../../'
        else
          './'
        end
      end
      def default_output_css
        if (@md.opt.opt_act[:dump][:bool] \
        &&  @md.opt.opt_act[:dump][:inst]) \
        || (@md.opt.opt_act[:redirect][:bool] \
        &&  @md.opt.opt_act[:redirect][:inst])
          './'
        elsif output_dir_structure.by_language_code?
          '../../'
        elsif output_dir_structure.by_filetype?
          '../'
        else
          '../'
        end
      end
      def html_scroll_css
        default_output_css
      end
      def xhtml_css
        default_output_css
      end
      def xml_css
        default_output_css
      end
      def html_seg_css
        if output_dir_structure.by_language_code?
          '../../../'
        elsif output_dir_structure.by_filetype?
          '../../'
        else
          '../'
        end
      end
      def manifest_css
        if output_dir_structure.by_language_code?
          '../../_sisu/css'
        elsif output_dir_structure.by_filetype?
          ''
        else
          '../'
        end
      end
      self
    end
    def mkdir
      def output
        def base
          FileUtils::mkdir_p(output_path.base.dir) unless FileTest.directory?(output_path.base.dir)
        end
        def css
          FileUtils::mkdir_p("#{output_path.base.dir}/#{@env.path.style}") unless FileTest.directory?("#{output_path.base.dir}/#{@env.path.style}")
        end
        def epub
          path=output_path.epub.dir
          make_path(path)
        end
        self
      end
      self
    end
    def mkfile #consider using more
      path="#{output_path.base.dir}/#{@md.fnb}"
      make_path(path)
      filename=@fno
      make_file(path,filename)
    end
    def mkfile_pwd
      path=Dir.pwd
      filename=@fno
      make_file(path,filename)
    end
    def write_file
      def txt
        path=output_path.txt.dir
        make_path(path)
        fn=base_filename.txt
        make_file(path,fn)
      end
      def html_scroll
        pth=output_path.html.dir
        make_path(pth)
        p_fn=place_file.html_scroll.dir
        @@filename_html_scroll=File.new(p_fn,'w+')
      end
      def html_seg_index
        pth=((output_dir_structure.by_filename?) \
          || (output_dir_structure.dump?)) \
        ? "#{output_path.html.dir}"
        : "#{output_path.html.dir}/#{@md.fnb}"
        make_path(pth)
        p_fn=place_file.html_seg_index.dir
        @@filename_html_index=File.new(p_fn,'w+')
      end
      def html_segtoc
        pth=((output_dir_structure.by_filename?) \
          || (output_dir_structure.dump?) \
          || (output_dir_structure.redirect?)) \
        ? "#{output_path.html.dir}"
        : "#{output_path.html.dir}/#{@md.fnb}"
        make_path(pth)
        p_fn=place_file.html_segtoc.dir
        @@filename_html_index=File.new(p_fn,'w+')
      end
      def xhtml
        path=output_path.xhtml.dir
        make_path(path)
        fn=base_filename.xhtml
        make_file(path,fn)
      end
      def xml_sax
        path=output_path.xml.dir
        make_path(path)
        fn=base_filename.xml_sax
        make_file(path,fn)
      end
      def xml_dom
        path=output_path.xml.dir
        make_path(path)
        fn=base_filename.xml_dom
        make_file(path,fn)
      end
      def xml_scaffold_structure_sisu
        path=output_path.xml_scaffold_structure_sisu.dir
        make_path(path)
        fn=base_filename.xml_scaffold_structure_sisu
        make_file(path,fn)
      end
      def xml_scaffold_structure_collapse
        path=output_path.xml_scaffold_structure_collapse.dir
        make_path(path)
        fn=base_filename.xml_scaffold_structure_collapse
        make_file(path,fn)
      end
      def manpage
        path=output_path.manpage.dir
        make_path(path)
        fn=base_filename.manpage
        make_file(path,fn)
      end
      def texinfo
        path=output_path.texinfo.dir
        make_path(path)
        fn=base_filename.texinfo
        make_file(path,fn)
      end
      def info
        path=output_path.texinfo.dir
        make_path(path)
        fn=base_filename.info
        make_file(path,fn)
      end
      def hash_digest
        path=output_path.hash_digest.dir
        make_path(path)
        fn=base_filename.hash_digest
        make_file(path,fn)
      end
      def qrcode
        path=output_path.qrcode.dir
        make_path(path)
        fn=base_filename.qrcode
        make_file(path,fn)
      end
      def manifest
        path=output_path.manifest.dir
        make_path(path)
        fn=base_filename.manifest
        make_file(path,fn)
      end
      def manifest_txt
        path=output_path.manifest.dir
        make_path(path)
        fn=base_filename.manifest_txt
        make_file(path,fn)
      end
      def pot
        path=output_path.pot.dir
        make_path(path)
        fn=base_filename.pot
        make_file(path,fn)
      end
      def po
        path=output_path.po.dir
        make_path(path)
        fn=base_filename.po
        make_file(path,fn)
      end
      self
    end
    def place_file
      def txt
        def dir
          output_path.txt.dir + '/' + base_filename.txt
        end
        def rel
          output_path.txt.rel + '/' + base_filename.txt
        end
        self
      end
      def html_scroll
        def dir
          output_path.html_scroll.dir + '/' + base_filename.html_scroll
        end
        def rel
          output_path.html_scroll.rel + '/' + base_filename.html_scroll
        end
        self
      end
      def html_seg_index
        def dir
          output_path.html_seg.dir + '/' + base_filename.html_seg_index
        end
        def rel
          output_path.html_seg.rel + '/' + base_filename.html_seg_index
        end
        self
      end
      def html_segtoc
        def dir
          output_path.html_seg.dir + '/' + base_filename.html_segtoc
        end
        def rel
          output_path.html_seg.rel + '/' + base_filename.html_segtoc
        end
        self
      end
      def html_book_index
        def dir
          output_path.html_seg.dir + '/' + base_filename.html_book_index
        end
        def rel
          output_path.html_seg.rel + '/' + base_filename.html_book_index
        end
        self
      end
      def html_concordance
        def dir
          output_path.html_seg.dir + '/' + base_filename.html_concordance
        end
        def rel
          output_path.html_seg.rel + '/' + base_filename.html_concordance
        end
        self
      end
      def odt
        def dir
          output_path.odt.dir + '/' + base_filename.odt
        end
        def rel
          output_path.odt.rel + '/' + base_filename.odt
        end
        self
      end
      def epub
        def dir
          output_path.epub.dir + '/' + base_filename.epub
        end
        def rel
          output_path.epub.rel + '/' + base_filename.epub
        end
        self
      end
      def pdf_p
        STDERR.puts 'ERROR not available due to multiple page format sizes'
      end
      def pdf_l
        STDERR.puts 'ERROR not available due to multiple page format sizes'
      end
      def xhtml
        def dir
          output_path.xhtml.dir + '/' + base_filename.xhtml
        end
        def rel
          output_path.xhtml.rel + '/' + base_filename.xhtml
        end
        self
      end
      def xml_sax
        def dir
          output_path.xml.dir + '/' + base_filename.xml_sax
        end
        def rel
          output_path.xml.rel + '/' + base_filename.xml_sax
        end
        self
      end
      def xml_dom
        def dir
          output_path.xml.dir + '/' + base_filename.xml_dom
        end
        def rel
          output_path.xml.rel + '/' + base_filename.xml_dom
        end
        self
      end
      def xml_scaffold_structure_sisu
        def dir
          output_path.xml.dir + '/' + base_filename.xml_scaffold_structure_sisu
        end
        def rel
          output_path.xml.rel + '/' + base_filename.xml_scaffold_structure_sisu
        end
        self
      end
      def xml_scaffold_structure_collapse
        def dir
          output_path.xml.dir + '/' + base_filename.xml_scaffold_structure_collapse
        end
        def rel
          output_path.xml.rel + '/' + base_filename.xml_scaffold_structure_collapse
        end
        self
      end
      def sqlite_discrete
        def dir
          output_path.sqlite_discrete.dir + '/' + base_filename.sqlite_discrete
        end
        def rel
          output_path.sqlite_discrete.rel + '/' + base_filename.sqlite_discrete
        end
        self
      end
      def hash_digest
        def dir
          output_path.hash_digest.dir + '/' + base_filename.hash_digest
        end
        def rel
          output_path.hash_digest.rel + '/' + base_filename.hash_digest
        end
        self
      end
      def src
        def dir
          output_path.src.dir + '/' + base_filename.src
        end
        def rel
          output_path.src.rel + '/' + base_filename.src
        end
        self
      end
      def sisupod
        def dir
          output_path.sisupod.dir + '/' + base_filename.sisupod
        end
        def rel
          output_path.sisupod.rel + '/' + base_filename.sisupod
        end
        self
      end
      def po
        def dir
          output_path.po.dir + '/' + base_filename.po
        end
        def rel
          output_path.po.rel + '/' + base_filename.po
        end
        self
      end
      def pot
        def dir
          output_path.pot.dir + '/' + base_filename.pot
        end
        def rel
          output_path.pot.rel + '/' + base_filename.pot
        end
        self
      end
      def po_git
        def dir
          output_path.po_git + '/' + base_filename.po
        end
        def rel
          #output_path.po_git + '/' + base_filename.po
        end
        self
      end
      def pot_git
        def dir
          output_path.pot_git + '/' + base_filename.pot
        end
        def rel
          #output_path.pot_git + '/' + base_filename.pot
        end
        self
      end
      def manpage
        def dir
          output_path.manpage.dir + '/' + base_filename.manpage
        end
        def rel
          output_path.manpage.rel + '/' + base_filename.manpage
        end
        self
      end
      def texinfo
        def dir
          output_path.texinfo.dir + '/' + base_filename.texinfo
        end
        def rel
          output_path.texinfo.rel + '/' + base_filename.texinfo
        end
        self
      end
      def info
        def dir
          output_path.texinfo.dir + '/' + base_filename.info
        end
        def rel
          output_path.texinfo.rel + '/' + base_filename.info
        end
        self
      end
      def qrcode_title
        def dir
          output_path.qrcode.dir + '/' + base_filename.qrcode_title
        end
        def rel
          output_path.qrcode.rel + '/' + base_filename.qrcode_title
        end
        self
      end
      def qrcode_md
        def dir
          output_path.qrcode.dir + '/' + base_filename.qrcode_md
        end
        def rel
          output_path.qrcode.rel + '/' + base_filename.qrcode_md
        end
        self
      end
      def manifest
        def dir
          output_path.manifest.dir + '/' + base_filename.manifest
        end
        def rel
          output_path.manifest.rel + '/' + base_filename.manifest
        end
        self
      end
      self
    end
    def base_filename
      def i18n(f)
        f=default_hash.merge(f)
        f[:lng] ||=@md.lang_code_insert
        f[:fn] + f[:lng] + f[:ft]
      end
      def default_hash
        {
          fn: @md.fnb,
          lng: @md.lang_code_insert,
        }
      end
      def default_hash_build(fh,sfx)
        if fh.is_a?(Hash)
          fh[:fn] ||=@md.fnb
          fh[:lng] ||= @md.lang_code_insert
          fh[:ft]=sfx
          fh
        else
          {
            fn: @md.fnb,
            lng: @md.lang_code_insert,
            ft: sfx,
          }
        end
      end
      def lang_code?(lng)
        (output_dir_structure.by_language_code?) \
        ? ''
        : (lng ||=@md.lang_code_insert)
      end
      def txt(fh=nil)
        fh=default_hash_build(fh,Sfx[:txt])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'plain',
            ft: fh[:ft],
            lng: fh[:lng],
           }
         else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def html_scroll(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def html_seg_index(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: 'index',
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def html_segtoc(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fnh=if output_dir_structure.dump_or_redirect?
          {
            fn: fh[:fn] + '.toc',
            ft: fh[:ft],
          }
        else
          {
            fn: 'toc',
            ft: fh[:ft],
            lng: lang_code?(fh[:lng]),
          }
        end
        i18n(fnh)
      end
      def html_seg(fh)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def html_book_index(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: 'book_index',
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def html_concordance(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.dump_or_redirect?
          @md.fnb + '.concordance' + ft
        else
          {
            fn: 'concordance',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def xhtml(fh=nil)
        fh=default_hash_build(fh,Sfx[:xhtml])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def epub(fh=nil)
        fh=default_hash_build(fh,Sfx[:epub])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: fh[:fn],
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def odt(fh=nil)
        fh=default_hash_build(fh,Sfx[:odt])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'opendocument',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def xml_sax(fh=nil)
        fh=default_hash_build(fh,Sfx[:xml_sax])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def xml_dom(fh=nil)
        fh=default_hash_build(fh,Sfx[:xml_dom])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def xml_scaffold_structure_sisu(fh=nil)
        fh=default_hash_build(fh,Sfx[:xml_scaffold_structure_sisu])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def xml_scaffold_structure_collapse(fh=nil)
        fh=default_hash_build(fh,Sfx[:xml_scaffold_structure_collapse])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'scroll',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def pdf_p(fh=nil)
        fh=default_hash_build(fh,Sfx[:pdf])
        fh[:lng]=lang_code?(fh[:lng])
        if output_dir_structure.by_filename?
          'portrait' + fh[:lng] + '.'
        else
          fh[:fn] + '.portrait' + fh[:lng] + '.'
        end
      end
      def pdf_l(fh=nil)
        fh=default_hash_build(fh,Sfx[:pdf])
        fh[:lng]=lang_code?(fh[:lng])
        if output_dir_structure.by_filename?
          'landscape' + fh[:lng] + '.'
        else
          fh[:fn] + '.landscape' + fh[:lng] + '.'
        end
      end
      def pdf_p_a4(fh=nil)
        pdf_p(fh) + @md.fn[:pdf_p_a4]
      end
      def pdf_p_a5(fh=nil)
        pdf_p(fh) + @md.fn[:pdf_p_a5]
      end
      def pdf_p_b5(fh=nil)
        pdf_p(fh) + @md.fn[:pdf_p_b5]
      end
      def pdf_p_letter(fh=nil)
        pdf_p(fh) + @md.fn[:pdf_p_letter]
      end
      def pdf_p_legal(fh=nil)
        pdf_p(fh) + @md.fn[:pdf_p_legal]
      end
      def pdf_l_a4(fh=nil)
        pdf_l(fh) + @md.fn[:pdf_l_a4]
      end
      def pdf_l_a5(fh=nil)
        pdf_l(fh) + @md.fn[:pdf_l_a5]
      end
      def pdf_l_b5(fh=nil)
        pdf_l(fh) + @md.fn[:pdf_l_b5]
      end
      def pdf_l_letter(fh=nil)
        pdf_l(fh) + @md.fn[:pdf_l_letter]
      end
      def pdf_l_legal(fh=nil)
        pdf_l(fh) + @md.fn[:pdf_l_legal]
      end
      def manpage(fh=nil)
        fh=default_hash_build(fh,Sfx[:manpage])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: fh[:fn],
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def info(fh=nil)
        fh=default_hash_build(fh,Sfx[:info])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: fh[:fn],
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def texinfo(fh=nil)
        fh=default_hash_build(fh,Sfx[:texinfo])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: fh[:fn],
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def sqlite_discrete(fh=nil)
        fh=default_hash_build(fh,Sfx[:sql])
        fh[:lng]=lang_code?(fh[:lng])
        fnh={
          fn: fh[:fn],
          ft: fh[:ft],
          lng: fh[:lng],
        }
        i18n(fnh)
      end
      def hash_digest(fh=nil)
        fh=default_hash_build(fh,Sfx[:txt])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_language_code?
          {
            fn: fh[:fn] + '.hash_digest',
            ft: fh[:ft],
          }
        elsif output_dir_structure.by_filetype?
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: 'digest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def sitemap(fh=nil)
        fh=default_hash_build(fh,Sfx[:xml])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_language_code?
          {
            fn: fh[:fn] + '.sitemap',
            ft: fh[:ft],
          }
        elsif output_dir_structure.by_filetype?
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: 'sitemap',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def qrcode_title(fh=nil)
        fh=default_hash_build(fh,'.title.png')
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'sisu_manifest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def qrcode_md #check name below
        fh=default_hash_build(fh,'.md.png')
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'sisu_manifest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def manifest_txt(fh=nil)
        fh=default_hash_build(fh,Sfx[:txt])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.by_filename?
          {
            fn: 'sisu_manifest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def manifest(fh=nil)
        fh=default_hash_build(fh,Sfx[:html])
        fh[:lng]=lang_code?(fh[:lng])
        fnh=if output_dir_structure.dump_or_redirect?
          {
            fn: fh[:fn] + '.manifest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        elsif output_dir_structure.by_filename?
          {
            fn: 'sisu_manifest',
            ft: fh[:ft],
            lng: fh[:lng],
          }
        else
          {
            fn: fh[:fn],
            ft: fh[:ft],
            lng: fh[:lng],
          }
        end
        i18n(fnh)
      end
      def src
        @md.fno
      end
      def po #check
        (@fno.empty?) \
        ? (@md.fn[:po])
        : (@fno + '.po')
      end
      def pot
        (@fno.empty?) \
        ? (@md.fn[:pot])
        : (@fno + '.pot')
      end
      def sisupod
        (@md.fns =~/\.ssm\.sst$/) \
        ? @md.fns.gsub(/(?:\~\S{2,3})?\.ssm\.sst$/,'.ssm.txz')
        : @md.fns.gsub(/(?:\~\S{2,3})?(\.sst)$/,'\1.txz')
      end
      self
    end
    def set_path(ft)
      @ft=ft
      def dir
        def abc
          if output_dir_structure.redirect?
            "#{@md.opt.opt_act[:redirect][:inst]}/#{@md.fnb}"
          elsif output_dir_structure.dump?
            @md.opt.opt_act[:dump][:inst]
          elsif output_dir_structure.by_language_code?
            "#{output_path.base.dir}/#{@md.opt.lng}/#{@ft}"
          elsif output_dir_structure.by_filetype?
            "#{output_path.base.dir}/#{@ft}"
          else
            "#{output_path.base.dir}/#{@md.fnb}"
          end
        end
        def ab
          if output_dir_structure.redirect?
            "#{@md.opt.opt_act[:redirect][:inst]}/#{@md.fnb}"
          elsif output_dir_structure.dump?
            @md.opt.opt_act[:dump][:inst]
          elsif output_dir_structure.by_language_code?
            "#{output_path.base.dir}/#{@md.opt.lng}/#{@ft}"
          else
            "#{output_path.base.dir}/#{@ft}"
          end
        end
        def ab_src
          if output_dir_structure.redirect?
            "#{@md.opt.opt_act[:redirect][:inst]}/#{@md.fnb}"
          elsif output_dir_structure.dump?
            @md.opt.opt_act[:dump][:inst]
          else
            "#{output_path.base.dir}/#{@ft}/#{@md.opt.fng}/#{Gt[:sisupod]}/#{Gt[:doc]}/#{@md.opt.lng}"
          end
        end
        def ab_pod
          if output_dir_structure.redirect?
            "#{@md.opt.opt_act[:redirect][:inst]}/#{@md.fnb}"
          elsif output_dir_structure.dump?
            @md.opt.opt_act[:dump][:inst]
          else
            "#{output_path.base.dir}/#{@ft}"
          end
        end
        self
      end
      def url
        def abc
          if output_dir_structure.by_language_code?
            "#{output_path.base.url}/#{@md.opt.lng}/#{@ft}"
          elsif output_dir_structure.by_filetype?
            "#{output_path.base.url}/#{@ft}"
          else
            "#{output_path.base.url}/#{@md.fnb}"
          end
        end
        def ab
          if output_dir_structure.by_language_code?
            "#{output_path.base.url}/#{@md.opt.lng}/#{@ft}"
          else
            "#{output_path.base.url}/#{@ft}"
          end
        end
        def ab_src
          "#{output_path.base.url}/#{@ft}/#{@md.opt.fng}/#{Gt[:sisupod]}/#{Gt[:doc]}/#{@md.opt.lng}"
        end
        def ab_pod
          "#{output_path.base.url}/#{@ft}"
        end
        self
      end
      def rel
        def abc
          if output_dir_structure.by_language_code?
            "#{@md.opt.lng}/#{@ft}"
          elsif output_dir_structure.by_filetype?
            "#{@ft}"
          else
            "#{@md.fnb}"
          end
        end
        def ab
          if output_dir_structure.by_language_code?
            "#{@md.opt.lng}/#{@ft}"
          else
            "#{@ft}"
          end
        end
        def ab_src
          @ft
        end
        def ab_pod
          @ft
        end
        self
      end
      def rel_sm
        def abc
          if output_dir_structure.by_language_code?
            "#{@md.opt.lng}/#{@ft}"
          elsif output_dir_structure.by_filetype?
            "#{@ft}"
          else
            "#{@md.fnb}"
          end
        end
        def ab
          if output_dir_structure.dump_or_redirect?
            '.'
          elsif output_dir_structure.by_language_code? \
          or output_dir_structure.by_filetype?
            '../' + @ft
          else '.'
          end
        end
        def ab_src
          locate="#{@ft}/#{@md.opt.fng}/#{Gt[:sisupod]}/#{Gt[:doc]}/#{@md.opt.lng}"
          if output_dir_structure.dump_or_redirect?
            '.'
          elsif output_dir_structure.by_language_code?
            "../../#{locate}"
          else
            "../#{locate}"
          end
        end
        def ab_pod
          if output_dir_structure.dump_or_redirect?
            '.'
          elsif output_dir_structure.by_language_code?
            "../../#{@ft}"
          else
            "../#{@ft}"
          end
        end
        self
      end
      def rcp
        def abc
          if output_dir_structure.by_language_code?
            "#{output_path.stub.rcp}/#{@md.opt.lng}/#{@ft}"
          elsif output_dir_structure.by_filetype?
            "#{output_path.stub.rcp}/#{@ft}"
          else
            "#{output_path.stub.rcp}/#{@md.fnb}"
          end
        end
        def ab
          if output_dir_structure.by_language_code?
            "#{output_path.stub.rcp}/#{@md.opt.lng}/#{@ft}"
          else
            "#{output_path.stub.rcp}/#{@ft}"
          end
        end
        self
      end
      self
    end
    def output_path
      def web_base
        def dir
          @env.path.webserv
        end
        def url
          #"#{@env.url.root}"
        end
        def rel
          '.'
        end
        def rcp
          '.'
        end
        self
      end
      def stub
        def dir
          "#{@md.opt.f_pth[:pth_stub]}"
        end
        #def url
        #  "#{@env.url.root}"
        #end
        def rel
          "./#{@md.opt.f_pth[:pth_stub]}"
        end
        def rcp
          "#{@md.opt.f_pth[:pth_stub]}"
        end
        self
      end
      def webserver_path
        if output_dir_structure.dump?
          @md.opt.opt_act[:dump][:inst]
        elsif output_dir_structure.redirect?
          @md.opt.opt_act[:redirect][:inst]
        else
          @env.path.webserv
        end
      end
      def base
        def dir
          "#{webserver_path}/#{@md.opt.f_pth[:pth_stub]}"
        end
        def url
          "#{@env.url.webserv}/#{@md.opt.f_pth[:pth_stub]}"
        end
        def rel
          "./#{@md.opt.f_pth[:pth_stub]}"
        end
        def rcp
          "./#{@md.opt.f_pth[:pth_stub]}"
        end
        self
      end
      def sisugit
        def dir
          "#{output_path.base.dir}/git"
        end
        def url
          "#{output_path.base.url}/git"
        end
        def rel
          "#{output_path.base.rel}/git"
        end
        def rcp
          "#{output_path.base.rcp}/git"
        end
        self
      end
      #def pod
      #  ft='pod'
      #  path=set_path(ft).dir.ab
      #end
      def src
        def ft
          Gt[:src]
        end
        def dir
          set_path(ft).dir.ab_src
        end
        def url
          set_path(ft).url.ab_src
        end
        def rel
          set_path(ft).rel.ab_src
        end
        def rcp
          set_path(ft).rcp.ab_src
        end
        def rel_sm
          set_path(ft).rel_sm.ab_src
        end
        self
      end
      def sisupod
        def ft
          Gt[:src]
        end
        def dir
          set_path(ft).dir.ab_pod
        end
        def url
          set_path(ft).url.ab_pod
        end
        def rel
          set_path(ft).rel.ab_pod
        end
        def rcp
          set_path(ft).rcp.ab_pod
        end
        def rel_sm
          set_path(ft).rel_sm.ab_pod
        end
        self
      end
      def po
        def dir
          "#{output_path.base.dir}/#{Gt[:src]}/#{@md.opt.fng}/po4a/po/#{@md.opt.lng}"
        end
        def url
          "#{output_path.base.url}/po4a/#{@md.fnb}/po/#{@md.opt.lng}"
        end
        self
      end
      def pot
        def dir
         "#{output_path.base.dir}/#{Gt[:src]}/#{@md.opt.fng}/po4a/pot"
        end
        def url
          "#{output_path.base.url}/po4a/#{@md.fnb}/pot"
        end
        def rcp
          #p "#{output_path.base.dir}/po4a/#{@md.fnb}/pot"
        end
        self
      end
      def po_git # consider !!!
        def ft
          Gt[:po]
        end
        def dir
          pth=@env.processing_path.git + '/' + @md.fnb + '/' + ft + '/' + @md.opt.lng
          FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
          pth
        end
        self
      end
      def pot_git # consider !!!
        def ft
          Gt[:pot]
        end
        def dir
          @env.processing_path.git + '/' + @md.fnb + '/' + ft
        end
        self
      end
      def md_harvest
        manifest
        self
      end
      def txt
        def ft
         'txt'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def html_scroll
        def ft
         'html'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          if output_dir_structure.dump_or_redirect?
            './image'
          elsif output_dir_structure.by_language_code?
            '../../_sisu/image'
          elsif output_dir_structure.by_filetype?
            '../_sisu/image'
          else
            '../_sisu/image'
          end
        end
        self
      end
      def html_seg
        def ft
          "html/#{@md.fnb}"
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          if output_dir_structure.dump_or_redirect?
            './image'
          elsif output_dir_structure.by_language_code?
            '../../../_sisu/image'
          elsif output_dir_structure.by_filetype?
            '../../_sisu/image'
          else
            '../_sisu/image'
          end
        end
        self
      end
      def html_concordance
        html_seg
        self
      end
      def html
        def ft
         'html'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).url.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          if output_dir_structure.by_language_code?
            '../../_sisu/image'
          elsif output_dir_structure.by_filetype?
            '../_sisu/image'
          else
            '../_sisu/image'
          end
        end
        self
      end
      def xhtml
        def ft
         'xhtml'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          '../../_sisu/image'
        end
        self
      end
      def epub
        def ft
         'epub'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          './image'
        end
        self
      end
      def odt
        def ft
         'odt'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def xml
        def ft
         'xml'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          '../../_sisu/image'
        end
        self
      end
      def xml_sax
        xml
        self
      end
      def xml_dom
        xml
        self
      end
      def xml_scaffold_structure_sisu
        def ft
         'sisu.scaffold.xml'
         #'xml'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          '../../_sisu/image'
        end
        self
      end
      def xml_scaffold_structure_collapse
        def ft
         'collapsed.scaffold.xml'
         #'xml'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        def rel_image
          '../../_sisu/image'
        end
        self
      end
      def pdf
        def ft
         'pdf'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def sqlite_discrete
        def ft
         'sql'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def hash_digest
        def ft
         'hashes'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def manifest
        def ft
         'manifest'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rel_image
          if output_dir_structure.dump_or_redirect?
            './image'
          elsif output_dir_structure.by_language_code?
            '../../_sisu/image'
          elsif output_dir_structure.by_filetype?
            '../_sisu/image'
          else
            '../_sisu/image'
          end
        end
        def rcp
          set_path(ft).rcp.abc
        end
        self
      end
      def qrcode
        def ft
         'manifest/qrcode'
        end
        def dir
          set_path(ft).dir.abc
        end
        def url
          set_path(ft).url.abc
        end
        def rel
          set_path(ft).rel.abc
        end
        def rcp
          set_path(ft).rcp.abc
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def harvest
        def ft
         'site_metadata'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        def rel_sm
          if output_dir_structure.by_language_code?
            ''
          elsif output_dir_structure.by_filetype?
            ''
          else
            ''
          end
        end
        self
      end
      def manpage
        def ft
         'man'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def texinfo
        def ft
         'texinfo'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        def rel_sm
          set_path(ft).rel_sm.ab
        end
        self
      end
      def sitemaps
        def ft
          'sitemaps'
        end
        def dir
          set_path(ft).dir.ab
        end
        def url
          set_path(ft).url.ab
        end
        def rel
          set_path(ft).rel.ab
        end
        def rcp
          set_path(ft).rcp.ab
        end
        self
      end
      def sqlite #check url
        def dir
          output_path.base.dir
        end
        def url
          output_path.base.url
        end
        def rel
          output_path.base.rel
        end
        def rcp
          output_path.base.rcp
        end
        self
      end
      #def cgi
      #end
      def css
        @d='_sisu/css'
        def dir
          output_path.base.dir + '/' + @d
        end
        def url
          output_path.base.url + '/' + @d
        end
        def rel
          @d
          #output_path.base.rel + '/' + @d
        end
        def rcp
          output_path.stub.rcp + '/' + @d
        end
        self
      end
      def images
        @d='_sisu/image'
        def dir
          output_path.base.dir + '/' + @d
        end
        def url
          output_path.base.url + '/' + @d
        end
        def rel
          @d
          #output_path.base.rel + '/' + @d
        end
        def rcp
          output_path.stub.rcp + '/' + @d
        end
        self
      end
      def images_external
        @d='_sisu/image_external'
        def dir
          output_path.base.dir + '/' + @d
        end
        def url
          output_path.base.url + '/' + @d
        end
        def rel
          output_path.base.rel + '/' + @d
        end
        def rcp
          output_path.base.rcp + '/' + @d
        end
        self
      end
      #def css
      #  #"#{@env.path.output}/#{@env.path.style}"
      #end
      self
    end
  end
  class FilenameLanguageCodeInsert
    def initialize(opt,lng=nil)
      @opt,@lng=opt,lng
      @opt=opt
      @lng=lng ||=@opt.lng
    end
    def language_code_insert
      if @opt.dir_structure_by ==:language \
      or ((@opt.dir_structure_by ==:filetype \
      || @opt.dir_structure_by ==:filename) \
      and (@opt.lingual ==:mono \
      && @lng == @opt.act[:default_language][:code]))
        ''
      elsif (@opt.dir_structure_by ==:filetype \
      || @opt.dir_structure_by ==:filename) \
      and not @opt.lingual ==:mono
        ".#{@lng}"
      else
        ".#{@lng}"
      end
    end
  end
  class CreateFile <InfoEnv                                                  #todo unify with FileOp
    def initialize(fns)
      begin
        super(fns)
        @env=SiSU_Env::InfoEnv.new(fns)
      rescue
        SiSU_Screen::Ansi.new('',$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def html_root
      #@env.path.output
    end
    def mkdir_pdf
      Dir.mkdir(@env.processing_path.tex) unless FileTest.directory?(@env.processing_path.tex)
    end
    def file_generic(output_file='')
      filename="#{@env.path.output}/#{@fnb}/#{output_file}"
      File.new(filename,'w+')
    end
    def file_error
      File.new('/tmp/errorlog.sisu','w+')
    end
    def file_txt
      File.new("#{@env.processing_path.dal}/#{@fns}.txt",'w+')
    end
    def file_debug
      File.new("#{@env.processing_path.dal}/#{@fns}.debug.txt",'w+')
    end
    def metaverse
      def file_meta
        File.new("#{@env.processing_path.dal}/#{@fns}.meta",'w+')
      end
      def file_meta_idx_html
        File.new("#{@env.processing_path.dal}/#{@fns}.idx.html",'w+')
      end
      self
    end
    def file_note
      File.new("#{Dir.pwd}/#{@fns}.fn",'w+')
    end
    def meta
      "#{@env.processing_path.dal}/#{@fns}.meta"
    end
    def file_semantic
      filename_semantic="./semantic.yaml"
      @@filename_semantic=File.new(filename_semantic,'w+')
    end
    def file_rss
      filename_rss="./semantic.xml"
      @@filename_rss=File.new(filename_rss,'w+')
    end
    def epub
      @pth=@env.processing_path.epub
      def xhtml_index
        filename_index="#{@pth}/#{Ep[:d_oebps]}/index.xhtml"
        File.new(filename_index,'w+')
      end
      def xhtml_cover_image
        filename_index="#{@pth}/#{Ep[:d_oebps]}/cover_image.xhtml"
        File.new(filename_index,'w+')
      end
      def xhtml_segtoc
        filename_segtoc="#{@pth}/#{Ep[:d_oebps]}/toc.xhtml"
        File.new(filename_segtoc,'w+')
      end
      def mimetype  #fixed application/epub+zip ~/grotto/theatre/dbld/builds/epub_sample/mimetype
        File.new("#{@pth}/mimetype",'w')
      end
      def metadata #variable matadata ~/grotto/theatre/dbld/builds/epub_sample/metadata.opf
        File.new("#{@pth}/#{Ep[:d_oebps]}/#{Ep[:f_opf]}",'w')
      end
      def toc_ncx  #variable toc ~/grotto/theatre/dbld/builds/epub_sample/toc.ncx
        File.new("#{@pth}/#{Ep[:d_oebps]}/#{Ep[:f_ncx]}",'w')
      end
      def metainf_cont #variable content ~/grotto/theatre/dbld/builds/epub_sample/META-INF/container.xml
        File.new("#{@pth}/META-INF/container.xml",'w')
      end
      def xhtml_css #fixed epub xhtml css
        File.new("#{@pth}/#{Ep[:d_oebps]}/css/xhtml.css",'w')
      end
      self
    end
    def file_texinfo
      File.new("#{@env.processing_path.texinfo}/#{@fnb}.texinfo",'w+')
    end
  end
  class Clear <InfoEnv                                                  #todo unify with FileOp
    def initialize(cmd,fns,operation='')
      @cmd=cmd
      begin
        super(fns)
        @env=SiSU_Env::InfoEnv.new(fns)
        InfoVersion.instance
        if operation.class.inspect =~/SiSU_Param/
          @md=operation
        end
        case operation #watch
        when /pdf/; @env_out=''
        when /sql/
        when /xml|plaintext|ascii/; @env_out="#{@env.path.output}/#{@fnb}" #check change of name to plaintext from ascii
        else
          if defined? @md.sfx_src \
          and @md.sfx_src =~/ss[ftsumc]/
            @env_suf='lm'
            @env_out_root=@env.path.output
            @env_out="#{@env.path.output}/#{@fnb}"
            @@publisher='SiSU http://www.jus.uio.no/sisu'
            @env_pdf="#{@env_out_root}/pdf"
          end
        end
      rescue
        SiSU_Screen::Ansi.new(@cmd,$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def param_instantiate
      @cX||=SiSU_Screen::Ansi.new(@cmd)
      @@date=SiSU_Env::InfoDate.new
      @@proc=@@filename_txt=@@filename_texinfo=@@filename_lout_portrait=@@filename_lout_landscape=@@filename_html_scroll=@@filename_html_index=@@filename_html_segtoc=@@filename_semantic=@@filename_rss=@@newfile=@@drr=@@yaml=@@yamladdr=nil
      @@publisher='SiSU scribe'
    end
  end
  class InfoPort < InfoEnv
    def initialize
      @env=SiSU_Env::InfoEnv.new
    end
    def webrick
      @env.port.webrick_port
    end
  end
  class InfoProgram < InfoEnv                                                #revisit
    attr_accessor :editor,:wc,:tidy,:rexml,:pdflatex,:postgresql,:sqlite
    def initialize
      prog=SiSU_Env::InfoEnv.new.program
      @editor,@wc,@tidy,@rexml,@pdflatex,@postgresql,@sqlite=prog.text_editor,prog.wc,prog.tidy,prog.rexml,prog.pdflatex,prog.postgresql,prog.sqlite
    end
  end
  class CSS_Default
    def html
      'html.css'
    end
    def html_tables
      'html_tables.css'
    end
    def xhtml
      'xhtml.css'
    end
    def xml_sax
      'sax.css'
    end
    def xml_dom
      'dom.css'
    end
    def docbook_xml
      'docbook.css'
    end
    def homepage
      'homepage.css'
    end
    def harvest
      'harvest.css'
    end
  end
  class CSS_Select < InfoEnv
    def initialize(md)
      @md=md
      @env=SiSU_Env::InfoEnv.new('',@md)
    end
    def html
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_html.css")
        "#{@md.doc_css}_html.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_html.css")
        "#{@env.path.stub_pwd}_html.css"
      else
        SiSU_Env::CSS_Default.new.html
      end
    end
    def html_tables
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_html_tables.css")
        "#{@md.doc_css}_html_tables.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_html_tables.css")
        "#{@env.path.stub_pwd}_html_tables.css"
      else SiSU_Env::CSS_Default.new.html_tables
      end
    end
    def xhtml
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xhtml.css")
        "#{@md.doc_css}_xhtml.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xhtml.css")
        "#{@env.path.stub_pwd}_xhtml.css"
      else SiSU_Env::CSS_Default.new.xhtml
      end
    end
    def xml_sax
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xml_sax.css")
        "#{@md.doc_css}_xml_sax.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xml_sax.css")
        "#{@env.path.stub_pwd}_xml_sax.css"
      else SiSU_Env::CSS_Default.new.xml_sax
      end
    end
    def xml_dom
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xml_dom.css")
        "#{@md.doc_css}_xml_dom.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xml_dom.css")
        "#{@env.path.stub_pwd}_xml_dom.css"
      else SiSU_Env::CSS_Default.new.xml_dom
      end
    end
    def docbook_xml
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_docbook.css")
        "#{@md.doc_css}_xml_dom.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_docbook.css")
        "#{@env.path.stub_pwd}_docbook.css"
      else SiSU_Env::CSS_Default.new.docbook_xml
      end
    end
    def homepage
      if @md.doc_css \
      and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_homepage.css")
        "#{@md.doc_css}_homepage.css"
      elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_homepage.css")
        "#{@env.path.stub_pwd}_homepage.css"
      else SiSU_Env::CSS_Default.new.homepage
      end
    end
  end
  class CSS_Stylesheet
    def initialize(md)
      @md=md
      @css=SiSU_Env::CSS_Select.new(@md)
      @env=SiSU_Env::InfoEnv.new('',@md)
      @file=SiSU_Env::FileOp.new(@md)
    end
    def html
      stylesheet="#{@file.path_rel_links.html_scroll_css}#{@env.path.style}/#{@css.html}"
      %{  <link rel="stylesheet" href="#{stylesheet}" type="text/css" />}
    end
    def html_seg
      stylesheet="#{@file.path_rel_links.html_seg_css}#{@env.path.style}/#{@css.html}"
      %{  <link rel="stylesheet" href="#{stylesheet}" type="text/css" />}
    end
    def html_tables
      stylesheet="#{@file.path_rel_links.html_seg_css}#{@env.path.style}/#{@css.html}"
      %{  <link rel="stylesheet" href="#{stylesheet}" type="text/css" />}
    end
    def xhtml_epub
      %{  <link rel="stylesheet" href="css/xhtml.css" type="text/css" />}
    end
    def epub
      xhtml_epub
    end
    def xhtml
      stylesheet="#{@file.path_rel_links.xhtml_css}#{@env.path.style}/#{@css.xhtml}"
      %{<?xml-stylesheet type="text/css" href="#{stylesheet}"?>}
    end
    def xml_sax
      stylesheet="#{@file.path_rel_links.xml_css}#{@env.path.style}/#{@css.xml_sax}"
      %{<?xml-stylesheet type="text/css" href="#{stylesheet}"?>}
    end
    def xml_dom
      stylesheet="#{@file.path_rel_links.xml_css}#{@env.path.style}/#{@css.xml_dom}"
      %{<?xml-stylesheet type="text/css" href="#{stylesheet}"?>}
    end
  end
  class CreateSite < InfoEnv
    require_relative 'css'                              # css.rb
      include SiSU_Style
    def initialize(cmd)
      @cmd=cmd
      @env=SiSU_Env::InfoEnv.new
      @init=SiSU_Env::GetInit.new
      @home,@pwd=ENV['HOME'],ENV['PWD'] #@pwd=Dir.pwd
      @rc=GetInit.new.sisu_yaml.rc
      @vz=SiSU_Viz::Defaults.new
      @vz_home=SiSU_Viz::Home.new
    end
    def create_default_sisu_homepage(action=:none)
      if action==:none
        puts %{  place your homepages in directory:\n    "#{@env.path.rc}/home/*.html"\n  (no action taken)}
      else
        puts %{  place your homepages in directory:\n    "#{@env.path.rc}/home/*.html"\n  (in order to replace default sisu homepage)}
        filename_homepage="#{@env.path.webserv}/#{@env.path.stub_pwd}/index.html"
        filename_home_toc="#{@env.path.webserv}/#{@env.path.stub_pwd}/toc.html"
        file_homepage=File.new(filename_homepage,'w')
        file_home_toc=File.new(filename_home_toc,'w')
        file_homepage << @vz_home.homepage
        file_home_toc << @vz_home.homepage
        file_homepage.close
        file_home_toc.close
      end
    end
    def homepage
      home_pages_manually_created=Dir.glob("#{@env.path.rc}/home/*.html")
      FileUtils::mkdir_p("#{@env.path.webserv}/#{@env.path.stub_pwd}") unless FileTest.directory?("#{@env.path.webserv}/#{@env.path.stub_pwd}")
      if home_pages_manually_created.length > 0
        home_pages_manually_created.each do |homepage|
          FileUtils.cp(homepage,"#{@env.path.webserv}/#{@env.path.stub_pwd}")
        end
      else
        create_default_sisu_homepage(:none)
        #create_default_sisu_homepage(:default)
      end
    end
    def cp_images(src_path,dest_path)
      if FileTest.directory?(src_path)
        FileUtils::cd(src_path)
        source=Dir.glob("*.{png,jpg,gif,ico}")
        FileUtils::mkdir_p(dest_path) unless FileTest.directory?(dest_path)
        FileUtils::chmod(0755,dest_path)
        source.each do |i|
          if FileTest.file?(i)
            FileUtils::cp(i,"#{dest_path}/#{i}")
            FileUtils::chmod(0644,"#{dest_path}/#{i}")
          else STDERR.puts %{\t*WARN* did not find image - "#{i}" [#{__FILE__}:#{__LINE__}]}
          end
        end
        FileUtils::cd(@pwd)
      else STDERR.puts %{\t*WARN* did not find - #{src_path} [#{__FILE__}:#{__LINE__}]}
      end
    end
    def cp_local_images
      src="#{@pwd}/_sisu/image"
      dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
      cp_images(src,dest) if FileTest.directory?(src)
    end
    def cp_external_images
      src="#{@env.processing_path.processing}/external_document/image"
      dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
      if FileTest.directory?(src)
        cp_images(src,dest) if FileTest.directory?(src)
      end
    end
    def cp_webserver_images
      src=@env.path.image_source
      dest_arr=[
        "#{@env.path.webserv}/_sisu/image",
        "#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
      ]
      dest_arr.each do |dest|
        cp_images(src,dest) if FileTest.directory?(src)
      end
    end
    def cp_webserver_images_local #this should not have been necessary
      src=@env.path.image_source
      dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
      cp_images(src,dest) if FileTest.directory?(src)
    end
    def cp_base_images #fix images
      src=SiSU_path_base \
      ? SiSU_path_base + '/data/sisu/image'
      : "#{@env.path.share}/image"
      dest_arr=[
        "#{@env.path.webserv}/_sisu/image_sys",
        "#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_sys"
      ]
      dest_arr.each do |dest|
        cp_images(src,dest) if FileTest.directory?(src)
      end
    end
    def cp_css
      FileUtils::mkdir_p("#{@env.path.output}/#{@env.path.style}") unless FileTest.directory?("#{@env.path.output}/#{@env.path.style}")
      css_path=['/etc/sisu/css',"#{@home}/.sisu/css","#{@pwd}/_sisu/css"] #BROKEN
      if defined? @rc['permission_set']['css_modify'] \
      and @rc['permission_set']['css_modify']
        SiSU_Screen::Ansi.new(@cmd,"*WARN* modify is css set to: #{@rc['permission_set']['css_modify']}").warn if @cmd=~/[MV]/
        css_path.each do |x|
          if FileTest.directory?(x)
            FileUtils::cd(x)
            source=Dir.glob("*.{css}")
            source.each do |i|
              if FileTest.file?(i)
                FileUtils::cp(i,"#{@env.path.output}/#{@env.path.style}")
              else STDERR.puts %{\t*WARN* did not find css - "#{i}" [#{__FILE__}:#{__LINE__}]}
              end
            end
            FileUtils::cd(@pwd)
          end
        end
      else SiSU_Screen::Ansi.new(@cmd,"*WARN* modify css is not set or is set to: false").warn if @cmd=~/[MV]/
      end
      fn_css=SiSU_Env::CSS_Default.new
      css=SiSU_Style::CSS.new
      path_style="#{@env.path.output}/#{@env.path.style}"
      FileUtils::mkdir_p(path_style) unless FileTest.directory?(path_style)
      if @cmd =~/C/ \
      or not FileTest.file?("#{path_style}/#{fn_css.homepage}")
        style=File.new("#{path_style}/#{fn_css.homepage}",'w')
        style << css.homepage
        style.close
      end
      if @cmd =~/C/ \
      or not FileTest.file?("#{path_style}/#{fn_css.html_tables}")
        style=File.new("#{path_style}/#{fn_css.html_tables}",'w')
        style << css.html_tables
        style.close
      end
      if @cmd =~/C/ \
      or not FileTest.file?("#{path_style}/#{fn_css.html}")
        style=File.new("#{path_style}/#{fn_css.html}",'w')
        style << css.html
        style.close
      end
      if @cmd =~/C/ \
      or not FileTest.file?("#{path_style}/#{fn_css.harvest}")
        style=File.new("#{path_style}/#{fn_css.harvest}",'w')
        style << css.harvest
        style.close
      end
      if @cmd =~/C/ \
      or (@cmd =~/[x]/ \
        and not FileTest.file?("#{path_style}/#{fn_css.xml_sax}"))
        style=File.new("#{path_style}/#{fn_css.xml_sax}",'w')
        style << css.xml_sax
        style.close
      end
      if @cmd =~/C/ \
      or (@cmd =~/[X]/ \
        and not FileTest.file?("#{path_style}/#{fn_css.xml_dom}"))
        style=File.new("#{path_style}/#{fn_css.xml_dom}",'w')
        style << css.xml_dom
        style.close
      end
      if @cmd =~/C/ \
      or (@cmd =~/[b]/ \
        and not FileTest.file?("#{path_style}/#{fn_css.xhtml}"))
        style=File.new("#{path_style}/#{fn_css.xhtml}",'w')
        style << css.xhtml
        style.close
      end
    end
  end
end
module SiSU_Screen
  require_relative 'screen_text_color'                  # screen_text_color.rb
end
module SiSU_Errors
  require_relative 'errors'                             # errors.rb
end
__END__
https? intro check 2007-09-22