aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/sysenv.rb
blob: 0661aa13900811f8d4bd058acfb254cafc0a5d87 (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
=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 Ralph Amissah All Rights Reserved.

 * License: GPL 3 or later:

   SiSU, a framework for document structuring, publishing and search

   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
   2007 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/licenses/gpl.html>
   <http://www.gnu.org/copyleft/gpl.html>
   <http://www.jus.uio.no/sisu/gpl.fsf>

 * 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.jus.uio.no/sisu/SiSU/download.html>

 * 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 #''
module SiSU_Env
  require 'fileutils'
  require 'singleton'
  include FileUtils::Verbose
  @@noyaml=false
  class Info_date
    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.cweek
      @t.strftime('%W')
    end
    def monthonly
      @t.month
    end
    def year_static
      '2007'
    end
  end
  class Info_system
    require 'rbconfig'
    include Singleton
    @@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@rc,@@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,{} # %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'
    prcss_dir_tmp_root="/tmp/#{prcss_dir}"
    prcss_dir_stub="#{prcss_dir}/#{@stub_pwd}"
    @processing_dir=if @@home \
    and File.writable?("#{@@home}/.")
      "#{@@home}/#{prcss_dir_stub}"
    #elsif File.writable?("#{@@pwd}/."); "#{@@pwd}/#{prcss_dir}"
    else prcss_dir_stub
    end
    tmp_processing_base=if @@user; "#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
    else                      "#{prcss_dir_stub}"
    end
    tmp_processing_base_user=if @@user; "#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
    else                      "/tmp/#{prcss_dir_stub}"
    end
    tmp_processing=if @@user; "#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
    else                      "/tmp/#{prcss_dir_stub}"
    end
    user=ENV['USER']
    port_pgsql=if defined? ENV['PGPORT'] \
    and not (ENV['PGPORT'].nil? \
    or 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_PATH=:processing_path
    PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root
    PROCESSING_PATH_TMP=:processing_path_tmp
    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_ENCODING=:processing_encoding
    PAPERSIZE=:papersize
    LANGUAGE=:language
    LANGUAGE_CODE=:language_code
    MULTILINGUAL=:multilingual
    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_PATH =>       @processing_dir,
      PROCESSING_DIR_TMP_ROOT  => prcss_dir_tmp_root,
      PROCESSING_PATH_TMP_BASE => tmp_processing_base,
      PROCESSING_PATH_TMP =>   tmp_processing,
      PROCESSING_DAL =>        'dal',
      PROCESSING_TUNE =>       'tune',
      PROCESSING_LATEX =>      'tex',
      PROCESSING_TEXINFO =>    'texinfo',
      PROCESSING_LOUT =>       'lout',
      PROCESSING_ENCODING =>   'encoding',
      #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 =>          true,
      CONCORD_MAX =>           260000,
      DIGEST =>                'md5',
      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
    stub_pwd=@@pwd[m,1]
    @@rc_path=["#@@pwd/_sisu","#@@home/.sisu",@@sisu_etc]
    @@yamlrc_path=unless stub_pwd =~/^sisupod$/
      ["#@@pwd/_sisu","#@@home/.sisu",@@sisu_etc]
    else #security policy: prevent reading of sisurc.yml in sisupod
      ["#@@home/.sisu",@@sisu_etc]
    end
    @@ad_path=unless stub_pwd =~/^sisupod$/
      ["#@@pwd/_sisu/skin/yml","#@@home/.sisu/skin/yml","#{@@sisu_etc}/skin/yml"]
    else #security policy: prevent reading of sisurc.yml in sisupod
      ["#@@home/.sisu",@@sisu_etc]
    end
    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,:yamlrc_path,:ad_path
    def initialize
      @user,@home,@hostname,@pwd,@sisu_etc,@host,@arch,@rbver,@dir_arch,@dir_sitearch,@dir_bin,@locale,@default_dir,@rc_path,@yamlrc_path,@ad_path=@@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@default_dir,@@rc_path,@@yamlrc_path,@@ad_path
      #note rbver is duplicated in Info_version
    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
        tell=if @mandatory; SiSU_Screen::Ansi.new(@cmd,"module required: #@prog")
        else                SiSU_Screen::Ansi.new(@cmd,"#@prog load requested")
        end
        tell.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 Get_init < Info_system
    include Singleton
    @@noyaml=false
    @@rc,@@vz,@@tx=nil,nil,nil
    @@ad={ :promo=>nil,:promo_list=>nil,:flag_promo=>false }
    attr_accessor :yaml
    def initialize
      super()
    end
    def skin
      @@vz ||=SiSU_Viz::Skin.new
    end
    def tex
      @@tx ||=SiSU_Viz::TeX.new
    end
    def yamlrc
      unless @@rc
        @yamlrc_path.each do |v|
          if @@noyaml \
          or FileTest.exist?("#{v}/noyaml")
            puts "WARNING - YAML loading switched off, to enable delete the file:\n\t#{v}/noyaml\n\n" unless @@noyaml
            @@noyaml=true
            break
          else
            if FileTest.exist?("#{v}/sisurc.yml")
              unless @@rc
                require 'yaml'
                @@rc ||= YAML::load(File::open("#{v}/sisurc.yml"))
              end
              break
            end
            unless @@rc
              if FileTest.exist?("#{v}/sisurc.yaml")
                unless @@rc
                  require 'yaml'
                  @@rc ||= YAML::load(File::open("#{v}/sisurc.yaml"))
                end
                break
              end
            end
          end
        end
      end
      @@rc
    end
    def ads #WORK AREA
      tell_no_yaml='WARNING - YAML loading switched off, to enable delete the file:'
      @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
          #tell=SiSU_Screen::Ansi.new('','promo off (file not found): list.yml')
          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
          #tell.warn if @cmd=~/MV/
          @@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
          #tell=SiSU_Screen::Ansi.new('','promo off (file not found): promo.yml')
          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
          #tell.warn if @cmd=~/MV/
          @@ad[:flag_promo]=false
        end
      end
      @@ad
    end
  end
  class Env_call
    @@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='')
      super()
      @fns=fns
      @sys=Info_system.instance
      @rc=Get_init.instance.yamlrc
      @ad=Get_init.instance.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
        if multilingual
          m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst|ssm)$/
          @@fnn ||=@fns[m,1]
          @@fnb ||=@fns[m,2]
          @@fnt ||=@fns[m,3]
          @@flv ||=document_language_versions_found[:f]
          @@fnz ||=if @@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; @@fnb + '.ssm.zip'
          else @@fnb + '.sst.zip'
          end
        else m=/(.+?)\.((?:-|ssm\.)?sst|ssm)$/
          @@fnb ||=@fns[m,1]
          @@fnm ||=@fns[m,1]
          @@fnt ||=@fns[m,2]
          @@fnz ||=if @@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; @@fnb + '.ssm.zip'
          else @@fnb + '.sst.zip'
          end
        end
      end
      @fnn,@fnb,@fnt,@flv,@fnz=@@fnn,@@fnb,@@fnt,@@flv,@@fnz
    end
    def multilingual
      if defined? @rc['default']['multilingual'] \
      and @rc['default']['multilingual'] != nil
        @rc['default']['multilingual']
      else true
      end
    end
    def document_language_versions_found
      @fn={}
      unless (@fns.nil? \
      or @fns.empty?)
        if multilingual
          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::Standardise_language.new
      langs=lang.codes
      x=[]
      if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}"); x << "#{@fn[:m]}.#{@fn[:t]}"
      end
      x << @fns
      langs.each do |l|
        lng=SiSU_Env::Standardise_language.new(l)
        if FileTest.file?("#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
          x << "#{@fn[:m]}~#{lng.code}.#{@fn[:t]}"
        elsif FileTest.file?("#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
          x << "#{@fn[:m]}~#{lng.name}.#{@fn[:t]}"
        end
      end
      @fn[:f]=x.uniq!
      @fn
    end
    def published_manifests?(output_base)
      ob=output_base
      @fn={}
      @m=[]
      unless (@fns.nil? \
      or @fns.empty?)
        if multilingual
          m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst$)/
          @fn[:b],@fn[:m],@fn[:t]=@fns[m,1],@fns[m,2],@fns[m,3]
          #@fl[:v]=@env.document_language_versions_found
        else m=/(.+?)\.((?:-|ssm\.)?sst$)/
          @fn[:b]=@fn[:m]=@fns[m,1]
          @fn[:t]=@fns[m,2]
        end
      end
      lang=SiSU_Env::Standardise_language.new
      langs=lang.codes
      x=[]
      if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}"); x << "#{@fn[:m]}.#{@fn[:t]}"
      end
      dir=SiSU_Env::Info_env.new(@fns)
      @m << {:m => 'sisu_manifest.html', :l => 'English' } #fix later, default language
      langs.each do |l|
        lng=SiSU_Env::Standardise_language.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::Standardise_language.new.file_to_language(fns_c)
          lng=fn_set_lang[:l]
          fn=SiSU_Env::Env_call.new(fns_c).lang(fn_set_lang[:c])
          @m << {:m => fn[:manifest], :l => lng }
        elsif FileTest.file?(fns_l)
          fn_set_lang=SiSU_Env::Standardise_language.new.file_to_language(fns_l)
          @fnl=dir.i18n.lang_filename(fn_set_lang[:c])
          fn=SiSU_Env::Env_call.new(fns_l).lang(fn_set_lang[:c])
          @m << {:m => fn[:manifest], :l => lng }
        end
      end
      @m.uniq!
      @m
    end
    def filename(code,name,suffix)
      d=SiSU_Env::Info_env.new(@fns)
      fnl=d.i18n.lang_filename(code)
      if code
        "#{fnl[:pre]}#{name}#{fnl[:mid]}#{suffix}#{fnl[:post]}"
      else "#{name}#{suffix}"
      end
    end
    def lang(code)
      @fn={
        :html            => filename(code,'','.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,'landscape','.pdf'),
        :pdf_p           => filename(code,'portrait','.pdf'),
        :toc             => filename(code,'toc','.html'),
        :doc             => filename(code,'doc','.html'),
        :index           => filename(code,'index','.html'),
        :odf             => filename(code,'opendocument','.odt'),
        :plain           => filename(code,'plain','.txt'),
        :manpage         => filename(code,@fnb,'.1'),
        :wiki            => filename(code,'wiki','.txt'),
        :digest          => filename(code,'digest','.txt'),
        :metadata        => filename(code,'metadata','.html'), #chk
        :manifest        => filename(code,'sisu_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,'')
      }
      @fn
    end
  end
  class System_call
    @@locale_flag=false
    def initialize(input='',output='',cmd='')
      @input,@output,@cmd=input,output,cmd
      @prog=SiSU_Env::Info_program.new
      @sys=Info_system.instance
    end
    def program_found?(program)
      found=`whereis #{program}`
      state=if found =~/bin\/#{program}\b/; true
      else                                  false
      end
    end
    def locale                                                                 #locales utf8 or other
      unless @@locale_flag
        @@locale_flag=true
        puts @sys.locale #unless @cmd =~/q/                                       # locale info UTF8 etc. KEEP
      end
      @sys.locale
    end
    def file_encoding(filename,cmd='')                                         #file encoding
      program='file'
      fnsp=Info_env.new(filename).source_file_with_path
      if program_found?(program)
        encoding=%x{file #{fnsp}}.strip
        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
        #puts "\tWARN: #{program}\n\t\t using alternative to word count program #{program_ref}"
        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 puts "\tWARN: #{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 puts "\tWARN: #{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 puts "\tWARN: #{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 puts "\tWARN: #{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)
        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 puts "\tWARN: #{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 puts "\tWARN: #{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'
      program_ref="\n\t\tcreatedb dbname SiSU_#{dbname_stub} #for postgresql database creation"
      if program_found?(program); system("createdb SiSU_#{dbname_stub}")
      else puts "\tWARN: #{program} is not available #{program_ref}"               #if @cmd =~/v/
      end
    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"
      if program_found?(program); system("trang #@input #@output")
      else                        puts "\tWARN: #{program} is not installed #{program_ref}" if cmd =~/V/
      end
    end
    def rmagick                                                                    #rmagick is a ruby library
      program='identify'
      program_ref="\n\t\tsee http://www.imagemagick.org/"
      if program_found?(program); true
      else puts "\tWARN: #{program} is not installed #{program_ref}"               #if @cmd =~/v/
        false
      end
    end
    def well_formed?                                                           #tidy - check for well formed xml xhtml etc.
      program=@prog.tidy
      program_ref="\n\t\tsee http://tidy.sourceforge.net/"
      if program_found?(program); system("#{@prog.tidy} -xml #@input > #@output")
      else                        puts "\tWARN: #{program} is not installed #{program_ref}"
      end
    end
    def latex2pdf                                                              #convert from latex to pdf
      prog=[]
      prog=['pdflatex','pdfetex','pdftex']
      program_ref="\n\t\tSee http://www.tug.org/applications/pdftex/\n\t\tOn Debian this is is included in tetex-extra"
      @pdfetex_flag=false
      @cmd ||=''
      tell=if @cmd =~/[MVv]/; ''
      else                    '> /dev/null'
      end
      mode='batchmode'
      #mode='nonstopmode'
      prog.each do |program|
        if program_found?(program)
          case program
          when /pdflatex/; system("#{program} -interaction=#{mode} #@input #{tell}\n")
          when /pdfetex/; system("#{program} -interaction=#{mode} -fmt=pdflatex #@input #{tell}\n") # debian specific paramters ?
            #system("#{program} -interaction=batchmode -progname=pdflatex #@input\n")
          when /pdftex/; system("#{program} -interaction=#{mode} -fmt=pdflatex #@input #{tell}\n")
          end
          @pdfetex_flag=true
          break
        end
        unless @pdfetex_flag; puts "\tWARN: none of the following programs are installed: #{program[0]}, #{program[1]}, #{program[2]} is installed. #{program_ref}"
        end
      end
    end
    def makeinfo                                                               #texinfo
      program='makeinfo'
      program_ref="\n\t\tsee http://www.gnu.org/software/texinfo/"
      if program_found?(program); system("#{program} #@input\n")
      else                        puts "\tWARN: #{program} is not installed #{program_ref}"
      end
    end
    def scp
      program='scp'
      if program_found?(program); system("scp -Cr #@input #@output")
      else                        puts "\tWARN: #{program} not found"
      end
    end
    def rsync(action='')
      program='rsync'
      if program_found?(program)
        vb=if @cmd =~/q/; 'q'
        elsif @cmd =~/v/; 'v'
        else              ''
        end
        msg=''
        msg=" && echo 'OK: #@input -> #@output'" unless @cmd =~/q/
        system("rsync -az#{vb} #{action} #@input #@output #{msg}")
      else puts "\tWARN: #{program} not found"
      end
    end
    def rm
      if @cmd =~/^-Z[mMvVq]*$/;      rm_rf(@input)
      elsif @cmd =~/V/;              rm(@input)
      elsif @cmd !~/q/;              rm(@input)
      elsif @cmd =~/q/;              rm(@input)
      #elsif @cmd =~/q/;              system("rm #{action} #@input")
      else                          puts "\tWARN: operation ignored"
      end
    end
  end
  class Standardise_language
    def initialize(l='')
      @language=l
      if @language.empty?
        @language=Info_env.new.defaults[:language]
      end
    end
    def language #use ISO_639-2
      lang={}
      case @language
      when /American|^us$/i;                  d,c,l=false,'en','American English' #depreciated, see iso 639-2
      when /English|^en$/i;                   d,c,l=false,'en','English'
      when /French|Francais|^fr$/i;           d,c,l=false,'fr','French'
      when /German|^de$/i;                    d,c,l=false,'de','German'
      when /Italian|^it$/i;                   d,c,l=false,'it','Italian'
      when /Spanish|Espanol|^es$/i;           d,c,l=false,'es','Spanish'
      when /Brazilian(?: Portuguese)?|^br$/i; d,c,l=false,'pt','Brazilian Portuguese' #depreciated, see iso 639-2
      when /Portuguese|^pt$/i;                d,c,l=false,'pt','Portuguese'
      when /Swedish|Svensk|^sv$/i;            d,c,l=false,'sv','Swedish'
      when /Danish|Dansk|^da$/i;              d,c,l=false,'da','Danish'
      when /Finnish|Finsk|Suomi|^fi$/i;       d,c,l=false,'fi','Finnish'
      when /Norwegian|Norsk|^no$/i;           d,c,l=false,'no','Norwegian'
      when /Icelandic|^is$/i;                 d,c,l=false,'is','Icelandic'
      when /Dutch|^nl$/i;                     d,c,l=false,'nl','Dutch'
      when /Estonian|^et$/i;                  d,c,l=false,'et','Estonian'
      when /Hungarian|^hu$/i;                 d,c,l=false,'hu','Hungarian'
      when /Polish|^pl$/i;                    d,c,l=false,'pl','Polish'
      when /Romanian|^ro$/i;                  d,c,l=false,'ro','Romanian'
      when /Russian|^ru$/i;                   d,c,l=false,'ru','Russian'
      when /Greek|^el$/i;                     d,c,l=false,'el','Greek'
      when /Ukranian|^uk$/i;                  d,c,l=false,'uk','Ukranian'
      when /Turkish|^tr$/i;                   d,c,l=false,'tr','Turkish'
      #when /Serbian/i;                       d,c,l=false,'', 'Serbian'
      #when /Welsh/i;                         d,c,l=false,'', 'Welsh'
      #when /Basque/i;                        d,c,l=false,'', 'Basque'
      #when /Breton/i;                        d,c,l=false,'', 'Breton'
      #when /Catalan/i;                       d,c,l=false,'', 'Catalan'
      #when /Galician/i;                      d,c,l=false,'', 'Galician'
      #when /Saa?mi/i;                        d,c,l=false,'', 'Saami'
      #when /Hebrew/i;                        d,c,l=false,'', 'Hebrew'
      #when /Latin/i;                         d,c,l=false,'', 'Latin'
      #when /Esperanto/i;                     d,c,l=false,'', 'Esperanto'
      when /Slovenian|^sl$/i;                 d,c,l=false,'sl','Slovenian'
      when /Croatian|^hr$/i;                  d,c,l=false,'hr','Croatian'
      when /Slovak(?:ian)?|^sk$/i;            d,c,l=false,'sk','Slovakian'
      when /Czech|^cs$/i;                     d,c,l=false,'cs','Czech'
      when /Bulgarian|^bg$/i;                 d,c,l=false,'bg','Bulgarian'
      else                                    d,c,l=true,'en','English (default)'
      #else                                   d,c,l=true,'xx','Default'
      end
      lang[:d],lang[:c],lang[:l]=d,c,l
      lang
    end
    def name
      language[:l].downcase
    end
    def title
      language[:l]
    end
    def code
      language[:c]
    end
    def file_to_language(file)
      m=/.+?\~(\w{2,3})\.(?:-|ssm\.)?sst$/
      @language=if file =~m ; file[m,1]
      else ''
      end
      language
    end
    def codes
      codes=['us','en','fr','de','it','es','br','pt','sv','da','fi','no','is','nl','et','hu','pl','ro','ru','el','uk','tr','sk','hr','sl','cs','bg'] # remove us and br see iso-639-2
    end
  end
  class Info_env < Env_call
    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,: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 tatic info so frequently!
      @fns,@md=fns,md
      @env=Env_call.new(fns) if fns
      fnb=if @md \
      and defined? @md.fnb
        @md.fnb
      elsif defined? @env.fnb \
      and @env.fnb
        @env.fnb
      elsif not @fns.nil? \
      and not @fns.empty?
        m=/(.+)?\.(?:(?:-|ssm\.)?sst|ssm)$/m
        @fns[m,1] if not @fns.empty?
      end
      if fnb; @@fb ||=fnb
      end
      @sys=Info_system.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_src=@stub_pwd + '/src'
      @stub_pod=@stub_pwd + '/pod'
    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
      concord_max=if defined? @rc['processing']['concord_max'] \
      and @rc['processing']['concord_max']
        @rc['processing']['concord_max']
      else                                                       defaults[:concord_max]
      end
    end
    def current_document
      @@current_document||=Dir.pwd
      @@current_document
    end
    def stub_pwd                                                                     #200412
      @stub_pwd
    end
    def stub_src
      @stub_src
    end
    def stub_pod
      @stub_pod
    end
    def sisupod
      #path.processing
      #  sisupod
      #    sisu
      #      content.sst              [file content]
      #      filename.sst             [link to content.sst]
      #      _sisu
      #        conf
      #          skin/
      #            doc                [relevant skin if any other than default]
      #        image                  [all images for specific document gathered here]
      sisupod_processing_path="#{path.processing}/sisupod"
      if FileTest.directory?(sisupod_processing_path) \
      or FileTest.file?(sisupod_processing_path)
        rm_rf(sisupod_processing_path)
      end
      paths=[]
      paths=["#{path.processing}/sisupod/_sisu/skin/doc","#{path.processing}/sisupod/_sisu/skin/dir","#{path.processing}/sisupod/_sisu/skin/site","#{path.processing}/sisupod/_sisu/image"]
      paths.each {|x| File.mkpath(x) unless FileTest.directory?(x) }
    end
    def defaults #multiple default directories
      @default_dir ||=@sys.default_dir #DEFAULT_DIR
    end
    #def skin
    #  @@vz ||=SiSU_Viz::Skin.new
    #end
    def widget #needs (md) #move
      @rc=SiSU_Env::Get_init.instance.yamlrc
      @ad=SiSU_Env::Get_init.instance.ads
      @vz=SiSU_Env::Get_init.instance.skin
      @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.class == Array \
        and @vz.widget_promo.length > 0
          @flag[:sk]=true
          true
        elsif defined? @rc['promo'] \
        and not @rc['promo'].nil? \
        and @rc['promo'].length > 0
          @flag[:rc]=true
          true
        else
          false
        end
        @flag
      end
      def search?
        searches=['sisu','hyperestraier']
        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=true
        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::Get_init.instance.yamlrc
        create_form_hyperestraier=if defined? rc['search']['sisu']['flag'] \
        and rc['search']['sisu']['flag']==true \
        and action \
        and action =~/https?:\/\//
          true
        else false
        end
        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']=~/^SiSU_\S+/ \
            ? rc['search']['sisu']['db'] \
            : "SiSU_#{rc['search']['sisu']['db']}"
          else nil
          end
          action=rc['search']['sisu']['action']
          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" />
<br />
<input type="hidden" name="db" value="#{db}" />
<input type="hidden" name="ltd" value="1000" />
<input type="hidden" name="off" value="0" />
<input type="radio" name="view" value="index" checked="checked" /> idx
<input type="radio" name="view" value="text" /> txt
<input type="submit" name="ignore" value="search" />
<input type="checkbox" name="fns" value="#{@md.fnb}" />
</font></form>
#{table_close}
<!-- SiSU Search -->
WOK
        elsif create_form_hyperestraier \
        and type=~/hyperestraier/ \
        and defined? rc['search']['hyperestraier']
            <<WOK
<!-- SiSU Search using Hyperestraier -->
#{table_open}
<a name="search"></a>
<form method="get" action="#{rc['search']['hyperestraier']['action']}" target="_top">
<font size="2">
<input type="text" name="phrase" value="" size="24" maxlength="255" />
<br />
<input type="submit" value="search" />
<input type="hidden" name="enc" value="UTF-8" />
<font size="2">
<a href="#{rc['search']['hyperestraier']['action']}">hyperestraier search</a>
</font></form>
#{table_close}
<!-- SiSU Search using Hyperestraier -->
WOK
        else ''
        end
        form
      end
      def search_form_static(action=nil,db=nil)
        rc=SiSU_Env::Get_init.instance.yamlrc
        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']=~/^SiSU_\S+/ \
            ? rc['search']['sisu']['db'] \
            : "SiSU_#{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="radio" name="view" value="index" checked="checked" /> idx
<input type="radio" name="view" value="text" /> txt
<input type="submit" name="ignore" value="search" />
<input type="checkbox" name="fns" value="#{@md.fnb}" />
</font>
</form>
<!-- SiSU Search -->
</td> }
        else ''
        end
      end
      def search_action
        action=if search?
        else ''
        end
      end
      self
    end
    def widget_static
      @rc=SiSU_Env::Get_init.instance.yamlrc
      @vz=SiSU_Env::Get_init.instance.skin
      @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+/ \
        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::Get_init.instance.yamlrc
        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']=~/^SiSU_\S+/ ? rc['search']['sisu']['db'] : "SiSU_#{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="fns" value="#@fnb" />
<input type="radio" name="view" value="index" /> idx
<input type="radio" name="view" value="text" checked="checked" /> txt
<input type="submit" name="ignore" value="search" />
</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="radio" name="view" value="index" checked="checked" /> idx
<input type="radio" name="view" value="text" /> txt
<input type="submit" />
</font>
</form>
<!-- SiSU Search --> }
        else ''
        end
      end
      def search_action
        action=if search?
        else ''
        end
      end
      self
    end
    def source_file_path
      file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
      pth=unless file =~/\.ssm\.sst$/; "#{Dir.pwd}"
      else "#{path.composite_file}"
      end
    end
    def source_file_with_path
      file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
      "#{source_file_path}/#{file}"
    end
    def read_source_file(fns)
      fns_array=unless fns =~/\.ssm.sst$/
        IO.readlines(fns,'')
      else IO.readlines("#{path.composite_file}/#{fns}",'')
      end
    end
    def path                                                                     #dir
      def home
        @sys.home
      end
      def pwd
        @sys.pwd
      end
      def stub_pwd
        @stub_pwd
      end
      def stub_src
        @stub_src
      end
      def stub_pod
        @stub_pod
      end
      def etc
        defaults[:sisu_etc]                                                      #live/dynamic
        # @sys.sisu_etc                                                           #broken: live/dynamic
        # 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
        defaults[:stylesheet_stub]
      end
      def sample_data                                                            #sample data repository source directory
        defaults[:sample_data_path]
      end
      def rc
        @sys.rc_path
      end
      def yamlrc
        rc.each do |v|
          if FileTest.exist?("#{v}/sisurc.yml")
            @yamlrc_dir="#{v}/sisurc.yml"
            break
          end
        end
        unless @yamlrc_dir
          rc.each do |v|
            if FileTest.exist?("#{v}/sisurc.yaml")
              @yamlrc_dir="#{v}/sisurc.yaml"
              break
            end
          end
        end
        @yamlrc_dir
      end
      def man #check use
        if defined? @rc['webserv']['man']; "#{webserv}/#{@rc['webserv']['man']}"
        else defaults[:webserv_man]
        end
      end
      def webserv_path #testing, check need, remove
        @webserv_path
      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+/
            man_path=@@man_path=File.expand_path(@rc['webserv']['path'])
          else nil
          end
        else manpath=@@man_path
        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])
            File.mkpath(defaults[:output_local])
          end
          defaults[:output_local]
        end
      end
      def webserv_stub_ensure
        File.mkpath(path.webserv) unless FileTest.directory?(path.webserv)
        File.mkpath("#{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
        "#{path.webserv}/#@stub_pwd"
      end
      def output_src                                                                 #web/webserv output directory... subdirectory into which further subdirectories are made based on file names
        "#{path.output}/src"
      end
      def output_pod
        "#{path.output}/pod"
      end
      def manpage
        "#{path.output}/man"
      end
      def sitemaps
        "#{path.output}/sitemaps"
      end
      def encoding
        pth="#{processing}/#{defaults[:processing_encoding]}"
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def processing_base_tmp
        defaults[:processing_path_tmp_base]
      end
      def processing_dir_tmp_root
        defaults[:processing_dir_tmp_root]
      end
      def processing                                                             #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc)
        unless FileTest.directory?(defaults[:processing_dir_tmp_root])
          File.mkpath(defaults[:processing_dir_tmp_root])
          File.chmod(0777,defaults[:processing_dir_tmp_root])
        end
        File.mkpath(defaults[:processing_path]) unless FileTest.directory?(defaults[:processing_path])
        File.mkpath(defaults[:processing_path_tmp]) unless FileTest.directory?(defaults[:processing_path_tmp])
        path_processing=if defined? @rc['processing']['path'] \
        and @rc['processing']['path']
          unless FileTest.directory?("#{path.home}/#{@rc['processing']['path']}")
            File.mkpath("#{path.home}/#{@rc['processing']['path']}")
          end
          ["#{path.home}/#{@rc['processing']['path']}",defaults[:processing_path],defaults[:processing_path_tmp]]
        else [defaults[:processing_path],defaults[:processing_path_tmp]]
        end
        @processing=nil
        path_processing.each do |v|                                              #
          #if File.writable?("#{v}/.") #check now is earlier
            @processing=v
            unless FileTest.directory?(@processing)
              puts "a processing directory (#@processing) is being created for use by sisu"
              File.mkpath(@processing)
            end
            break
          #end
        end
        @processing
      end
      def composite_file
        pth=path.dal  #"#{processing}/composite"
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def dal
        pth=if defined? @rc['processing']['dal']; "#{processing}/#{@rc['processing']['dal']}"
        else                                             "#{processing}/#{defaults[:processing_dal]}"
        end
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def tune
        pth=if defined? @rc['processing']['tune'];      "#{processing}/#{@rc['processing']['tune']}"
        else                                             "#{processing}/#{defaults[:processing_tune]}"
        end
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def odf
        "#{processing}/odf"
      end
      def tex
        pth=if defined? @rc['processing']['latex'];     "#{processing}/#{@rc['processing']['latex']}"
        else                                             "#{processing}/#{defaults[:processing_latex]}"
        end
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def texi
        pth=if defined? @rc['processing']['texinfo'];   "#{processing}/#{@rc['processing']['texinfo']}"
        else                                             "#{processing}/#{defaults[:processing_texinfo]}"
        end
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def texinfo                                                                #texinfo webserv, check
        "#{processing}/#{defaults[:processing_texinfo]}"
      end
      def lout
        pth=if defined? @rc['processing']['lout'];      "#{processing}/#{@rc['processing']['lout']}"
        else                                             "#{processing}/#{defaults[:processing_lout]}"
        end
        File.mkpath(pth) unless FileTest.directory?(pth)
        pth
      end
      def feed
        if defined? @rc['webserv']['feed'];             "#{public_output}/#{@rc['webserv']['feed']}"
        else                                            defaults[:webserv_feed]
        end
      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 sqlite
        "#{home}/sqlite"
      end
      def cgi
        if defined? @rc['webserv']['cgi'];             "#{@rc['webserv']['cgi']}"
        else                                           defaults[:webserv_cgi]
        end
      end
      def php
        if defined? @rc['webserv']['php'];              "#{public_output}/#{@rc['webserv']['php']}"
        else                                            defaults[:webserv_php]
        end
      end
                                                                                 # programs
      def output_tell
        url.webserv_map_pwd
      end
      def image_source                                                           #image repository source directory
        image_path=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_tex                                                       #image repository source directory
        image_path=if defined? @rc['image']['path'] \
        and defined? @rc['image']['public']
          pth="#{@rc['image']['path']}"
          "#{pth}/#{@rc['image']['public']}"
        else
          image=defaults[:image_stub]
          "#{share}/image"
        end
      end
      def image_external
        "#{processing}/external_document/image"
      end
      def image_source_local_tex
        if FileTest.directory?(defaults[:image_local]);    defaults[:image_local]
        end
      end
      def image_source_remote_tex
        if FileTest.directory?(image_external); image_external
        end
      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 src_txt
        "#{root}/src"
      end
      def src_pod
        "#{root}/pod"
      end
      def webserv_host_base
        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 webrick_port
        if @md \
        and @md.cmd.inspect=~/-F/ \
        and @md.mod.inspect=~/port=(\d+)/
           $1
        else
          if defined? @rc['webserv_cgi']['port']
            if @rc['webserv_cgi']['port'].nil? \
            and (defined? @md.mod \
            and not @md.mod.nil? \
            and @md.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
        if @md \
        and @md.cmd.inspect=~/-F/ \
        and @md.mod.inspect=~/port=(\d+)/
           $1
        else
          if defined? @rc['webserv_cgi']['port']
            if @rc['webserv_cgi']['port'].nil? \
            and (defined? @md.mod \
            and not @md.mod.nil? \
            and @md.mod.inspect=~/webrick/)
              defaults[:webserv_port_cgi]
            elsif not @rc['webserv_cgi']['port'].nil?
              @rc['webserv_cgi']['port']
            else nil
            end
          else   nil
          end
        end
      end
      def webserv_cgi                                                           #web url for local webserv (localhost, or hostname)
        if defined? @rc['webserv_cgi']['host'] \
        and not @rc['webserv_cgi']['host'].nil?
          http=@rc['webserv_cgi']['host'] =~ /https?:\/\// ? '' : 'http://' #check https? missing
          if webserv_port_cgi
            "#{http}#{@rc['webserv_cgi']['host']}:#{webserv_port_cgi}/#@stub_pwd"
          else "#{http}#{@rc['webserv_cgi']['host']}/#@stub_pwd"
          end
        else
          http=webserv_host_base=~/https?:\/\// ? '' : 'http://'
          if webserv_port_cgi
            "#{http}#{webserv_host_base}:#{webserv_port_cgi}/#@stub_pwd"
          else "#{http}#{webserv_host_base}/#@stub_pwd"
          end
        end
      end
      def webserv_base_cgi                                                           #web url for local webserv (localhost, or hostname)
        if defined? @rc['webserv_cgi']['host'] \
        and not @rc['webserv_cgi']['host'].nil?
          http=@rc['webserv_cgi']['host'] =~ /https?:\/\// ? '' : 'http://'
          if webserv_port_cgi
            "#{http}#{@rc['webserv_cgi']['host']}:#{webserv_port_cgi}"
          else "#{http}#{@rc['webserv_cgi']['host']}"
          end
        else
          http=webserv_host_base=~/https?:\/\// ? '' : 'http://'
          if webserv_port_cgi
            "#{http}#{webserv_host_base}:#{webserv_port_cgi}"
          else "#{http}#{webserv_host_base}"
          end
        end
      end
      def webrick #must have a port #REMOVE
        #port=":#{webserv_port_cgi}"
        if defined? @rc['webserv_cgi']['host'] \
        and not @rc['webserv_cgi']['host'].nil?
          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 not webserv_host_base.nil?
          "#{http}#{webserv_host_base}"
        else "#{http}localhost" end
      end
      def webserv                                                                #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}/#@stub_pwd")
        elsif defined? @rc['webserv']['webrick_url'] \
        and @rc['webserv']['webrick_url'] == false
          "file://#{path.webserv}/#@stub_pwd"
        elsif webserv_port_cgi =~/\S+/
          "#{url.hostname}:#{webserv_port_cgi}/#@stub_pwd"
        else "#{url.hostname}/#@stub_pwd"
        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 #sort this out, messy
        if defined? @rc['webserv_cgi']['file_links']
          case @rc['webserv_cgi']['file_links']
          when /webserv_cgi/; url.webserv_base_cgi
          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
          end
        else                  webserv_base_cgi
        end
      end
      def sample_search_form_title
        if defined? @rc['search']['sisu']['title'] \
        and @rc['search']['sisu']['title'] =~/\S+/
          @rc['search']['sisu']['title']
        else %{SiSU search form (sample):}
        end
      end
      def output_tell
        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
        output=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
        '../_sisu/image'
      end
      def images_local
        if FileTest.directory?(defaults[:image_local])
          if @@image_flag
            require 'ftools'
            images=Dir.glob("#{defaults[:image_local]}/*.{png,jpg,gif}")
            pth="#{path.webserv}/#@stub_pwd"
            File.mkpath("#{pth}/_sisu/image") unless FileTest.directory?("#{pth}/_sisu/image")
            images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0
            @@image_flag=false
          end
          '../_sisu/image'
        else
          if @@local_image==true
            cmd=if @cmd; @cmd
            else ''
            end
            tell=SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] )
            tell.warn unless cmd =~/q/
            @@local_image=false
          end
          url.images
        end
      end
      #def images_external #url_images_external                                                    #ex defaults url.path_png
      #  '../_sisu/image_external'
      #end
      def images_external
        if FileTest.directory?(image_external)
          if @@image_flag
            require 'ftools'
            images=Dir.glob("#{image_external}/*.{png,jpg,gif}")
            pth="#{path.webserv}/#@stub_pwd"
            File.mkpath("#{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
          '../_sisu/image_external'
        else
          if @@local_image==true
            tell=SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external )
            tell.warn unless @cmd =~/q/
            @@local_image=false
          end
          url.images_external
        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                    'md5'
          end
        else                      'md5'
        end
      end
      def length
        case digest.type
        when /sha256/; 64
        when /md5/;    32
        else           32
        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
        if defined? @rc['program_select']['pdf_viewer'] \
        and @rc['program_select']['pdf_viewer'] =~/\S\S+/
          @rc['program_select']['pdf_viewer']
        else 'pdf-viewer'                                                        #'evince'
        end
      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'                                                      #'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'                                                #'links2' 'elinks' 'epiphany'
        end
      end
      def console_www_browser
        web_browser
      end
      def xml_viewer
        if defined? @rc['program_select']['xml_viewer'] \
        and @rc['program_select']['xml_viewer'] =~/\S\S+/
          @rc['program_select']['xml_viewer']
        else text_editor
        end
      end
      def xml_editor
        xml_viewer
      end
      def odf_viewer
        if defined? @rc['program_select']['odf_viewer'] \
        and @rc['program_select']['odf_viewer'] =~/\S\S+/
          @rc['program_select']['odf_viewer']
        else 'oowriter'                                                          #'odf-viewer','oowriter'
        end
      end
      def manpage_generator
        if defined? @rc['program_select']['man'] \
        and @rc['program_select']['man'] =~/\S\S+/
          @rc['program_select']['man']
        else 'nroff -man'                                                        #'nroff -man' #'groff -man -Tascii'
        end
      end
      def file_encoding #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 wc #wordcount
        is=''
        if defined? @rc['program_set']['wc']
          is=@rc['program_set']['wc']
        end
        if is.nil? \
        or is==true
          is='wc'
        end
        is
      end
      def tidy
        if defined? @rc['program_set']['tidy']
          is=@rc['program_set']['tidy']
        end
        if is.nil? \
        or is==true
          is='tidy'
        end
        is
      end
      def rmagick
        if defined? @rc['program_set']['rmagick']
          is=@rc['program_set']['rmagick']
        end
        if is.nil? \
        or is==true
          is='rmagick'
        end
        is
      end
      def rexml                                                                  #should be part of ruby 1.8 but apparently not always
        is=if FileTest.directory?("#{Config::CONFIG['rubylibdir']}/rexml") #Config::CONFIG['sitedir']
          true
        else false
        end
        is=if defined? @rc['program_set']['rexml'];      @rc['program_set']['rexml']
        else ''
        end
        if is.nil? \
        or is==true
          is='rexml'
        end
        is
      end
      def pdflatex
        is=if defined? @rc['program_set']['pdflatex'];   @rc['program_set']['pdflatex']
        else ''
        end
        if is.nil? \
        or is==true
          is='pdflatex'
        end
        is
      end
      def postgresql
        is=if defined? @rc['program_set']['postgresql'];  @rc['program_set']['postgresql']
        else ''
        end
        if is.nil? \
        or is==true
          is='postgresql'
        end
        is
      end
      def sqlite
        is=if defined? @rc['program_set']['sqlite'];      @rc['program_set']['sqlite']
        else ''
        end
        if is.nil? \
        or is==true
          is='sqlite'
        end
        is
      end
      self
    end
    def i18n
      def language                                                              # language settings
##
        m=/.+\/\S+?\~(\S+)/
        pwd=Dir.pwd
        conf=if defined? @rc['default']['language']; @rc['default']['language']
        else nil
        end
        l=if pwd=~m ;                                pwd[m1,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::Standardise_language.new(l)
      end
      def multilingual
        if defined? @rc['default']['multilingual'] \
        and @rc['default']['multilingual'] != nil;  @rc['default']['multilingual']
        else                                         defaults[:multilingual]
        end
      end
      def lang_filename(l)
        @lang={}
        x=if multilingual
          x=if defined? @rc['default']['language_file'] \
          and @rc['default']['language_file'] != nil; @rc['default']['language_file']
          else 1
          end
        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
      if defined? @rc['default']['papersize'];   @rc['default']['papersize'].downcase
      else                                       defaults[:papersize].downcase
      end
    end
    def odf_structure
      rm_rf("#{path.processing}/odf")
      system("unzip -q #{path.share}/odf/odt.zip -d      #{path.processing}")
    end
    def sisupod_gen(fns_pod)
      pwd=Dir.pwd
      sisupod_processing_path="#{path.processing}/sisupod"
      if FileTest.directory?(sisupod_processing_path) \
      or FileTest.file?(sisupod_processing_path)
        rm_rf(sisupod_processing_path)
      end
      unless FileTest.directory?(sisupod_processing_path)
        File.mkpath(sisupod_processing_path)
      end
      if FileTest.file?("#{Dir.pwd}/#{fns_pod}")
        system("unzip -q #{Dir.pwd}/#{fns_pod} -d #{path.processing}")
      else
        tell=SiSU_Screen::Ansi.new('',"file not found: #{fns_pod}")
        tell.warn unless @cmd=~/q/
      end
      sisupod_processing_path
    end
  end
  class Info_processing_flag
    attr_accessor :color,:cf_0,:cf_1,:cf_2,:cf_3,:cf_4,:cf_5
    def initialize
      @rc=Get_init.instance.yamlrc
    end
    def color                                                                  #processing flag shortcuts
      if defined? @rc['flag']['color']; @rc['flag']['color']
      else                               false
      end
    end
    def cf_0                                                                   #processing flag shortcuts
      if defined? @rc['flag']['default'] \
      and not (@rc['flag']['default'].nil? \
      or @rc['flag']['default'].empty?)
        @rc['flag']['default']
      else                               '-NhwpaobxXyYv'
      end
    end
    def cf_1                                                                   #processing flag shortcuts
      if defined? @rc['flag']['i'] \
      and not (@rc['flag']['i'].nil? \
      or @rc['flag']['i'].empty?)
        @rc['flag']['i']
      else                               '-hwpoy'
      end
    end
    def cf_2                                                                   #processing flag shortcuts
      if defined? @rc['flag']['ii'] \
      and not (@rc['flag']['ii'].nil? \
      or @rc['flag']['ii'].empty?)
        @rc['flag']['ii']
      else                               '-NhwpaobxXy'
      end
    end
    def cf_3                                                                   #processing flag shortcuts
      if defined? @rc['flag']['iii'] \
      and not (@rc['flag']['iii'].nil? \
      or @rc['flag']['iii'].empty?)
        @rc['flag']['iii']
      else                               '-NhwpaobxXyY'
      end
    end
    def cf_4                                                                   #processing flag shortcuts
      if defined? @rc['flag']['iv'] \
      and not (@rc['flag']['iv'].nil? \
      or @rc['flag']['iv'].empty?)
        @rc['flag']['iv']
      else                               '-NhwpaobxXDyY --import'
      end
    end
    def cf_5                                                                   #processing flag shortcuts
      if defined? @rc['flag']['v'] \
      and not (@rc['flag']['v'].nil? \
      or @rc['flag']['v'].empty?)
        @rc['flag']['v']
      else                               '-NhwpaobxXDyY --update'
      end
    end
  end
  class Info_settings < Info_env
    def permission?(prog)                                                     #program defaults
      if defined? @rc['permission_set'][prog]; @rc['permission_set'][prog]
      else                                   false
      end
    end
    def program?(prog)                                                                    #program defaults
      if defined? @rc['program_set'][prog]; @rc['program_set'][prog]
      else                                   false
      end
    end
  end
  class File_map < Info_env
    attr_accessor :local_sisu_source
    def initialize(opt='') #watch
      super()
      @opt=opt #,opt.fns,opt.cmd
      #@file=@opt.fns #not always fns
      @env=if @opt.fns \
      and not @opt.fns.empty?
        SiSU_Env::Info_env.new(@opt.fns)
      else
        SiSU_Env::Info_env.new('dummy.sst')
      end
      if @opt.cmd =~/m/; @md=SiSU_Param::Parameters.new(@opt).get
      end
      ft=[]
      if @md \
      and defined? @md.fn \
      and @md.fn        # used for multilingual
        if @md.cmd =~ /[hH]/
          ft << @md.fn[:html]
        end
        if @md.cmd =~ /w/ \
        and @md.cmd !~ /[hH]/
          ft << @md.fn[:concordance]
        end
        if @md.cmd =~ /y/ \
        and @md.cmd !~ /[hH]/
          ft << @md.fn[:manifest]
        end
        if @md.cmd =~ /p/;   ft << @md.fn[:pdf_l] << @md.fn[:pdf_p]
        end
        if @md.cmd =~ /x/;   ft << @md.fn[:sax]
        end
        if @md.cmd =~ /X/;   ft << @md.fn[:dom]
        end
        if @md.cmd =~ /b/;   ft << @md.fn[:xhtml]
        end
        if @md.cmd =~ /a/;   ft << @md.fn[:plain]
        end
        if @md.cmd =~ /i/;   ft << @md.fn[:manpage]
        end
        if @md.cmd =~ /[g]/; ft << @md.fn[:wiki]
        end
        if @md.cmd =~ /N/;   ft << @md.fn[:digest]
        end
        if @md.cmd =~ /o/;   ft << @md.fn[:odf]
        end
        if @md.cmd =~ /O/;   ft << @md.fn[:oai_pmh]
        end
        if @md.cmd =~ /s/;   ft << @md.fns
        end
        if @md.cmd =~ /S/;   ft << @md.fn[:sisupod] << '.kdi'
        end
        @fnb=@md.fnb
      else                                                                     # still needed where/when param is not parsed
        if @opt.cmd =~ /[hH]/;  ft << '.html' << '.html.??'
        end
        if @opt.cmd =~ /w/ \
        and @opt.cmd !~ /[hH]/
          ft << 'concordance.html' << '??.concordance.html' << 'concordance.??.html'
        end
        if @opt.cmd =~ /y/ \
        and @opt.cmd !~ /[hH]/
          ft << 'sisu_manifest.html' << '??.sisu_manifest.html' << 'sisu_manifest.??.html'
        end
        if @opt.cmd =~ /p/;   ft << 'landscape.pdf' << 'portrait.pdf' << '.pdf'
        end
        if @opt.cmd =~ /x/;   ft << 'sax.xml' << '??.sax.xml' << 'sax.??.xml'
        end
        if @opt.cmd =~ /X/;   ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml'
        end
        if @opt.cmd =~ /b/;   ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml'
        end
        if @opt.cmd =~ /i/;   ft << '.1' << '??.man.1' << 'man.??.1'
        end
        if @opt.cmd =~ /a/;   ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt'
        end
        if @opt.cmd =~ /[g]/; ft << 'wiki.txt' << '??.wiki.txt' << 'wiki.??.txt'
        end
        if @opt.cmd =~ /N/;   ft << 'digest.txt' << '??.digest.txt' << 'digest.??.txt'
        end
        if @opt.cmd =~ /o/;   ft << 'opendocument.odt' << '??.opendocument.odt' << 'opendocument.??.odt'
        end
        if @opt.cmd =~ /O/;   ft << 'oai_pmh.xml'
        end
        if @opt.cmd =~ /s/;   ft << '.sst' << '.ssi' << '.ssm'
        end
        if @opt.cmd =~ /S/;   ft << '.zip' << '.kdi'
        end
        if @opt.mod.inspect =~ /sxm|sxs|xml/; ft << @fnb << '.sxs.xml'
        end
        if @opt.mod.inspect =~ /sxd/; ft << @fnb << '.sxd.xml'
        end
        if @opt.mod.inspect =~ /sxn/; ft << @fnb << '.sxn.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=if @fnb \
      and not @fnb.empty?
        "#{@env.path.output}/#@fnb"
      else @env.path.output
      end
      @source_path_src=if @fnb \
      and not @fnb.empty?
        "#{@env.path.output}/src"
      else @env.path.output_src
      end
      @local_sisu_source=if @filetypes =~/\S/; "#@source_path/#@filetypes"
      else                  @source_path
      end
    end
  end
  class Clean_output
    require 'fileutils'
    include FileUtils::Verbose
    def initialize(opt)
      @opt=opt
      z=File_map.new(@opt)
      @zap=z.local_sisu_source
      if @opt.cmd =~ /[hH]/
        @zap=Dir.glob(@zap).join(' ')
        if @opt.cmd !~ /w/; @zap.gsub!(/#@source_path\/concordance.html/,'')
        end
      end
      @env=SiSU_Env::Info_env.new
    end
    def zap
p @zap
      if @zap !~/\/\//; rm_rf(@zap) if FileTest.directory?(@zap)
      else puts 'suspect zap request, ignored'
      end
      #Dir.unlink(@zap) if FileTest.directory?(@zap)
      #System_call.new(@zap,'',@cmd).rm
    end
    def zap_map
      if @opt.fnb \
      and not @opt.fnb.empty?
        sm="#{@env.path.output}/sitemaps/sitemap_#{@opt.fnb}.xml"
        rm(sm) if FileTest.file?(sm)
      end
    end
  end
  class Info_remote_host
    def initialize
      @rc=Get_init.instance.yamlrc
    end
    def remote_host #see Info_remote remote_host_base_general
      r=[]
      r=if (defined? @rc['remote'] \
      and @rc['remote'].class==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'].class==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
        rhost1=if defined? SiSU_Env::Info_remote_host.new.remote_host[0][:name]
          SiSU_Env::Info_remote_host.new.remote_host[0][:name]
        else nil
        end
      end
      def r2
        rhost2=if defined? SiSU_Env::Info_remote_host.new.remote_host[1][:name]
          SiSU_Env::Info_remote_host.new.remote_host[1][:name]
        else nil
        end
      end
      def r3
        rhost3=if defined? SiSU_Env::Info_remote_host.new.remote_host[2][:name]
          SiSU_Env::Info_remote_host.new.remote_host[2][:name]
        else nil
        end
      end
      def r4
        rhost4=if defined? SiSU_Env::Info_remote_host.new.remote_host[3][:name]
          SiSU_Env::Info_remote_host.new.remote_host[3][:name]
        else nil
        end
      end
      def r5
        rhost5=if defined? SiSU_Env::Info_remote_host.new.remote_host[4][:name]
          SiSU_Env::Info_remote_host.new.remote_host[4][:name]
        else nil
        end
      end
      def r6
        rhost6=if defined? SiSU_Env::Info_remote_host.new.remote_host[5][:name]
          @ls + SiSU_Env::Info_remote_host.new.remote_host[5][:name]
        else nil
        end
      end
      self
    end
  end
  class Info_remote < File_map
    @@flag_remote=false
    require 'socket'
    def initialize(opt)
      super(opt) #
      @opt=opt
      @rc=Get_init.instance.yamlrc
    end
    def remote_host_base_general
      SiSU_Env::Info_remote_host.new.remote_host
    end
    def remote_host_base
      remote_host_base_general.each do |remote_conn|
        #host_ip=IPSocket.getaddress(remote[:host]) unless remote[:host].empty?
        @@flag_remote=true if remote_conn[:name] =~/\S+?@\S+/
        #remote_conn[:name]
      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
      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
        #remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
        local_src=@source_path_src
        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.zip')
        if (local_gen =~/\S/ \
        and local_gen !~/\/\//) \
        and (remote_gen =~/\S/ \
        and remote_gen !~/\/\//) \
        and @@flag_remote==true \
        and @opt.cmd !~/U/
          System_call.new(local_gen,remote_gen).scp
          if FileTest.file?("#{local_src}/#{src_txt}")
            System_call.new("#{local_src}/#{src_txt}",remote_src).scp
          elsif FileTest.file?("#{local_pod}/#{src_pod}")
            System_call.new("#{local_src}/#{src_pod}",remote_pod).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}"
          elsif FileTest.file?("#{local_pod}/#{src_doc}.zip")
            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 rsync
      self.remote_host_base.each do |remote_conn|
        local_gen=@source_path
        local_gen_image="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
        remote_gen="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
        remote_images="#{remote_conn[:name]}/#{@env.path.stub_pwd}/_sisu/image/."
        local_src=@source_path_src
        local_pod=@source_path_pod
        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.zip')
        if (local_gen =~/\S/ \
        and local_gen !~/\/\//) \
        and (remote_gen =~/\S/ \
        and remote_gen !~/\/\//) \
        and @@flag_remote==true \
        and @opt.cmd !~/U/
          System_call.new(local_gen,remote_gen,@opt.cmd).rsync('--delete-after')
          if FileTest.file?("#{local_src}/#{src_txt}")
            System_call.new("#{local_src}/#{src_txt}",remote_src,@opt.cmd).rsync
            if defined? @md.ec[:image]
              images="#{local_gen_image}/" + @md.ec[:image].join(" #{local_gen_image}/")
              System_call.new(images,remote_images,@opt.cmd).rsync
            end
          elsif FileTest.file?("#{local_pod}/#{src_pod}")
            System_call.new("#{local_pod}/#{src_pod}",remote_src,@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}.zip")
            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
    def scp_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}"
          System_call.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 scp_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}"
          System_call.new("#{local}/_sisu/image_sys/",remote).scp
          System_call.new("#{local}/_sisu/image/",remote).scp
          System_call.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
    def rsync_base                                                              #base site
      ldest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu"
      image_sys="#{@env.path.webserv}/_sisu/image_sys"
      images="#{@env.path.webserv}/_sisu/image"
      self.remote_host_base.each do |remote_conn|
        remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
        remote_conf="#{remote_conn[:name]}/_sisu"
        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 rsync_base: #{local} -> #{remote}"
          System_call.new("#{image_sys}","#{remote_conf}").rsync
          System_call.new("#{images}","#{remote_conf}").rsync
          System_call.new("#{ldest}","#{remote}").rsync
        elsif @opt.cmd =~/U/
          puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
          puts "rsync_base: #{local} -> #{remote}"
          puts "#{local}/_sisu/image -> #{remote}"
          puts "#{local}/_sisu/image_sys/ -> #{remote}"
          puts "#{local}/#{@env.path.style}/ -> #{remote}"
        else  puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
        end
      end
    end
    def rsync_base_sync                                                         #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 rsync_base_sync: #{local} -> #{remote}"
          System_call.new("#{local}/_sisu/image_sys/",remote).rsync('--delete-after')
          System_call.new("#{local}/_sisu/image/",remote).rsync('--delete-after')
          System_call.new("#{local}/#{@env.path.style}/",remote).rsync('--delete-after')
        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
    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
        #if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] #and @@flag_remote==true and @opt.cmd !~/U/
          System_call.new(local,remote).rsync('--delete-after')
        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 Info_version <Info_env
    require 'rbconfig'
    def get_version
      require 'ftools'
      @version={}
      @pwd=ENV['PWD']
      yst_etc="#{defaults[:sisu_etc]}/version.yml"
      lib_path=`echo $RUBYLIB`.split(':')
      if File.exist?(yst_etc); @version=YAML::load(File::open(yst_etc)) #unless @@noyaml
      end
      @version
    end
    def rbversion
      #Config::CONFIG['ruby_version']
      %x{ruby -v}.strip
    end
  end
  class Create_system_link #< Info_env                                          #revisit problems created 2004w41
    def initialize
      @env=SiSU_Env::Info_env.new
    end
    def images
      unless FileTest.directory?("#{@env.path.output}/_sisu")
        File.mkpath("#{@env.path.output}/_sisu") 
      end
      unless File.exist?("#{@env.path.output}/_sisu/image_sys") \
      or File.symlink?("#{@env.path.output}/_sisu/image_sys")
        File.symlink("../../_sisu/image_sys", "#{@env.path.output}/_sisu/image_sys") 
      end
    end
    def man_forms
      #File.symlink("../../man/form", "#{@env.path.output}/man/form") unless File.symlink?("#{@env.path.output}/man/form") == true
    end
    def man_pdf
      #File.symlink("../../man/form", "#{@env.path.output}/man/pdf") unless File.symlink?("#{@env.path.output}/man/pdf") == true
    end
  end
  class Info_file < Info_env
    def initialize(fns='')
      @env=SiSU_Env::Info_env.new
      @fns=fns
    end
    def basefilename
      m=/(.+?)\.(?:(?:-|ssm\.)?sst|ssm)$/m
      fnb=@fns[m,1]
    end
    def project
      "#{@env.development}/sisu.lnk"
    end
    def project_info
      "#{@env.datapriv_i}/sisu.er3"
    end
    def project_todo
      "#{@env.development}/todo.txt"
    end
    def admin_self
      "#{@env.path.home}/.corundum/dots.lnk"
    end
    def admin_root
      '/root/.corundum/admin.txt'
    end
  end
  class Info_db < Info_env
    @@rc=nil
    def initialize
      @@pwd ||=Dir.pwd
      @pwd=Dir.pwd
      @env=SiSU_Env::Info_env.new
      m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
      @pwd_stub=@pwd[m,1]
      @rc=@@rc ||=Get_init.instance.yamlrc
      @defaults=Info_env.new.defaults
    end
    def engine
      def default
        if defined? @rc['db']['engine']['default'] \
        and @rc['db']['engine']['default']=~/postgresql|sqlite/
          @rc['db']['engine']['default']
        else 'sqlite'
        end
      end
      self
    end
    def psql
      def user
        if defined? @rc['db']['postgresql']['user'] \
        and @rc['db']['postgresql']['user']=~/\S+/
          @rc['db']['postgresql']['user']
        else @env.user
        end
      end
      def db #db_name
        "SiSU_#@pwd_stub"
      end
      def port #PGPORT
        if defined? @rc['db']['postgresql']['port'] \
        and ( @rc['db']['postgresql']['port'] =~/\d+/ \
        or @rc['db']['postgresql']['port'].class == Fixnum)
          @rc['db']['postgresql']['port']
        else @defaults[:postgresql_port]
        end
      end
      def dbi
        "DBI:Pg:database=#{psql.db};port=#{psql.port}"
      end
      self
    end
    def mysql
      def db
        #"SiSU_#@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 dbi
        "DBI:SQLite:#{sqlite.db}" #sqlite3 ?
      end
      self
    end
  end
  class Info_port < Info_env
    def initialize
      @env=SiSU_Env::Info_env.new
    end
    def webrick
      @env.url.webrick_port
    end
  end
  class Info_program < Info_env                                                  #revisit
    attr_accessor :editor,:wc,:tidy,:rexml,:pdflatex,:postgresql,:sqlite
    def initialize
      prog=SiSU_Env::Info_env.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 Info_skin
    def initialize(md=nil,skin=nil)
      @md=md
      @d_sk=if skin.class==String ; skin
      elsif defined? md.doc_skin \
      and md.doc_skin
        md.doc_skin
      else nil
      end
      @home,@pwd=ENV['HOME'],ENV['PWD']
      m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
      @pwd_stub=@pwd[m,1]
      @env=SiSU_Env::Info_env.new
    end
    def select                                                                 # skin loading logic here
      load "#{SiSU_lib}/defaults.rb"
      skin_path=[]
      @env.sys.rc_path.each{|x| skin_path << "#{x}/skin"}
      skin_path << "#{@env.path.processing}/external_document/skin"
      #skin_path << "#{@env.path.processing}/external_document/_sisu/skin" #revisit
      skin=true
      if @pwd_stub =~/^sisupod$/ \
      and @md.mod.inspect !~/--trust/
        skin=false  #security only run skins on sisupod if --trust flag is provided
      end
      doc_skin,dir_skin=nil,nil
      if skin
        unless @d_sk.nil?
          sk_doc="doc/#@d_sk.rb"
          skin_path.each do |v|                                                    #document skin priority 1
            if FileTest.file?("#{v}/#{sk_doc}")
              doc_skin="#{v}/#{sk_doc}"
              load doc_skin
              break
            end
          end
        end
        unless doc_skin
          sk_dir="dir/skin_#@pwd_stub.rb"
          skin_path.each do |v|                                                  #directory skin priority 2
            if FileTest.file?("#{v}/#{sk_dir}")
              dir_skin="#{v}/#{sk_dir}"
              load dir_skin
              break
            end
          end
        end
      end
      sk=if doc_skin; doc_skin
      elsif dir_skin; dir_skin
      else            nil
      end
    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
  end
  class CSS_select < Info_env
    def initialize(md)
      @md=md
      @env=SiSU_Env::Info_env.new
    end
    def html
      css=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 CSS_default.new.html
      end
    end
    def html_tables
      css=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 CSS_default.new.html_tables
      end
    end
    def xhtml
      css=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 CSS_default.new.xhtml
      end
    end
    def xml_sax
      css=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 CSS_default.new.xml_sax
      end
    end
    def xml_dom
      css=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 CSS_default.new.xml_dom
      end
    end
    def docbook_xml
      css=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 CSS_default.new.docbook_xml
      end
    end
    def homepage
      css=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 CSS_default.new.homepage
      end
    end
  end
  class CSS_stylesheet
    def initialize(md)
      @md=md
      @css=CSS_select.new(@md)
      @env=SiSU_Env::Info_env.new
    end
    def html
      %{  <link rel="stylesheet" href="../#{@env.path.style}/#{@css.html}" type="text/css" />}
    end
    def html_tables
      %{  <link rel="stylesheet" href="../#{@env.path.style}/#{@css.html_tables}" type="text/css" />}
    end
  end
  class SiSU_file <Info_env                                                    #todo unify with Create_file
    def initialize(md,fno='')
      begin
        @fno,@fns,@fnb=fno,md.fns,md.fnb
        @env=SiSU_Env::Info_env.new(@fns)
        @env_out="#{@env.path.output}/#@fnb"
      rescue; STDERR.puts SiSU_Screen::Ansi.new(@cmd,$!,$@).rescue
      ensure
      end
    end
    def make_file(path,filename)
      if File.writable?("#{path}/."); File.new("#{path}/#{filename}",'w+')
      else SiSU_Screen::Ansi.new('',"is the file or directory writable?, could not create #{filename}").warn
      end
    end
    def touch_file(path,filename)
      if File.writable?("#{path}/.");
        system("touch #{path}/#{filename}")
        #File.new("#{path}/#{filename}",'w+')
      else SiSU_Screen::Ansi.new('',"is the file or directory writable?, could not create #{filename}").warn
      end
    end
    def make_path(path)
      File.mkpath(path) unless FileTest.directory?(path)
    end
    def mkdir_initialize                                                       # not used but consider using
      File.mkpath(@env.path.output) unless FileTest.directory?(@env.path.output)
      File.mkpath("#{@env.path.output}/#@fnb") unless FileTest.directory?("#{@env.path.output}/#@fnb")
      File.mkpath("#{@env.path.output}/#{@env.path.style}") unless FileTest.directory?("#{@env.path.output}/#{@env.path.style}")
      File.mkpath(@env.path.dal) unless FileTest.directory?(@env.path.dal)
      File.mkpath(@env.path.tune) unless FileTest.directory?(@env.path.tune)
    end
    def mkdir
      dir=@env.path.output
      txt_path="#{dir}/#@fnb"
      File.mkpath(dir) unless FileTest.directory?(dir)
      File.mkpath(txt_path) unless FileTest.directory?(txt_path)
      File.mkpath("#{dir}/#{@env.path.style}") unless FileTest.directory?("#{dir}/#{@env.path.style}")
      File.mkpath(@env.path.dal) unless FileTest.directory?(@env.path.dal)
      File.mkpath(@env.path.tune) unless FileTest.directory?(@env.path.tune)
    end
    def mkfile #consider using more
      path="#{@env.path.output}/#@fnb"
      filename=@fno
      file=make_file(path,filename)
    end
    def mkfile_man
      path="#{@env.path.output}/man"
      make_path(path)
      filename=@fno
      file=make_file(path,filename)
    end
    def mkfile_pwd
      path=Dir.pwd
      filename=@fno
      file=make_file(path,filename)
    end
  end
  class Create_file <Info_env                                                  #todo unify with SiSU_file
    def initialize(cmd,fns,operation='')
      @cmd=cmd
      begin
        super(fns)
        @env=SiSU_Env::Info_env.new(fns)
        ver=Info_version.new
        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"
            @env_tex=@env.path.tex
            @env_lout=@env.path.lout
            @@publisher='SiSU http://www.jus.uio.no/sisu'
            @env_pdf="#@env_out_root/pdf"
          end
        end
      rescue; STDERR.puts SiSU_Screen::Ansi.new(@cmd,$!,$@).rescue
      ensure
      end
    end
    def param_instantiate
      @cX||=SiSU_Screen::Ansi.new(@cmd)
      @@date=Info_date.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
    def html_root
      #@env.path.output
    end
    def mkdir_pdf
      Dir.mkdir(@env.path.tex) unless FileTest.directory?(@env.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_meta
      File.new("#{@env.path.dal}/#@fns.meta",'w+')
    end
    def file_note
      File.new("#{Dir.pwd}/#@fns.fn",'w+')
    end
    def marshal_meta
      "#{@env.path.dal}/#@fns.meta.rbm"
    end
    def meta
      "#{@env.path.dal}/#@fns.meta"
    end
    def file_tune
      File.new("#{@env.path.tune}/#@fns.tune",'w+')
    end
    def marshal_tune
      "#{@env.path.tune}/#@fns.marshal_tune"
    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 file_html_scroll(md)
      filename_scroll="#{@env.path.output}/#{md.fnb}/#{md.fnl[:pre]}doc#{md.fnl[:mid]}.html#{md.fnl[:post]}"
      @@filename_html_scroll=File.new(filename_scroll,'w+')
    end
    def file_html_index(md)
      filename_index="#{@env.path.output}/#{md.fnb}/#{md.fnl[:pre]}index#{md.fnl[:mid]}.html#{md.fnl[:post]}"
      @@filename_html_index=File.new(filename_index,'w+')
    end
    def file_html_segtoc(md)
      filename_segtoc="#{@env.path.output}/#{md.fnb}/#{md.fnl[:pre]}toc#{md.fnl[:mid]}.html#{md.fnl[:post]}"
      File.new(filename_segtoc,'w+')
    end
    def file_texinfo
      File.new("#{@env.path.texinfo}/#@fnb.texinfo",'w+')
    end
  end
  class Create_site < Info_env
    require "#{SiSU_lib}/css"
    include SiSU_Style
    def initialize(cmd)
      @cmd=cmd
      @env=SiSU_Env::Info_env.new
      @home,@pwd=ENV['HOME'],ENV['PWD'] #@pwd=Dir.pwd
      @rc=Get_init.instance.yamlrc
      @vz=SiSU_Env::Get_init.instance.skin
      @vz_home=SiSU_Viz::Home.new
    end
    def homepage
      homepage_path=nil
      @env.sys.rc_path.each do |v|
        if FileTest.file?("#{v}/home/index.html")
          homepage_path="#{v}/home/index.html"
          break
        end
      end
      File.mkpath("#{@env.path.webserv}/#{@env.path.stub_pwd}") unless FileTest.directory?("#{@env.path.webserv}/#{@env.path.stub_pwd}")
      if homepage_path \
      and FileTest.file?(homepage_path)
        cp(homepage_path,"#{@env.path.webserv}/#{@env.path.stub_pwd}/index.html")
        cp(homepage_path,"#{@env.path.webserv}/#{@env.path.stub_pwd}/toc.html")
      else
        doc_skin=nil
        sk_doc='doc/skin_sisu.rb'
        @env.sys.rc_path.each do |v|                                                     #document skin priority 1
          if FileTest.file?("#{v}/skin/#{sk_doc}")
            doc_skin="#{v}/skin/#{sk_doc}"
            load doc_skin
            break
          end
        end
        filename_homepage=File.new("#{@env.path.webserv}/#{@env.path.stub_pwd}/index.html",'w')
        filename_homepage_toc=File.new("#{@env.path.webserv}/#{@env.path.stub_pwd}/toc.html",'w')
        filename_homepage << @vz_home.homepage
        filename_homepage_toc << @vz_home.homepage
      end
    end
    def cp_images(src_path,dest_path)
      if FileTest.directory?(src_path)
        cd(src_path)
        source=Dir.glob("*.{png,jpg,gif,ico}")
        File.mkpath(dest_path) unless FileTest.directory?(dest_path)
        chmod(0755,dest_path)
        source.each do |i|
          cp_r(i,"#{dest_path}/#{i}")
          chmod(0644,"#{dest_path}/#{i}")
        end
        cd(@pwd)
      else puts "\tWARN, did not find - #{src_path}"
      end
    end
    def cp_local_images
      src="#@pwd/_sisu/image"
      dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
      cp_images(src,dest)
    end
    def cp_external_images
      src="#{@env.path.processing}/external_document/image"
      dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
      cp_images(src,dest)
    end
    def cp_webserver_images
      src=@env.path.image_source
      dest="#{@env.path.webserv}/_sisu/image"
      cp_images(src,dest)
    end
    def cp_base_images #fix images
      src="#{@env.path.share}/image"
      dest="#{@env.path.webserv}/_sisu/image_sys"
      cp_images(src,dest)
    end
    def cp_css
      File.mkpath("#{@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']
        tell=SiSU_Screen::Ansi.new(@cmd,"modify is css set to: #{@rc['permission_set']['css_modify']}")
        css_path.each do |x|
          if FileTest.directory?(x)
            cd(x)
            source=Dir.glob("*.{css}")
            source.each do |i|
              cp(i,"#{@env.path.output}/#{@env.path.style}")
            end
            cd(@pwd)
          end
        end
      else tell=SiSU_Screen::Ansi.new(@cmd,"modify css is not set or is set to: false")
      end
      tell.warn if @cmd=~/[MV]/
      fn_css=SiSU_Env::CSS_default.new
      css=SiSU_Style::CSS.new
      path_style="#{@env.path.output}/#{@env.path.style}"
      File.mkpath(path_style) unless FileTest.directory?(path_style)
      style=File.new("#{path_style}/#{fn_css.homepage}",'w')
      style << css.homepage
      style.close
      style=File.new("#{path_style}/#{fn_css.html_tables}",'w')
      style << css.html_tables
      style.close
      style=File.new("#{path_style}/#{fn_css.html}",'w')
      style << css.html
      style.close
      style=File.new("#{path_style}/#{fn_css.xml_sax}",'w')
      style << css.xml_sax
      style.close
      style=File.new("#{path_style}/#{fn_css.xml_dom}",'w')
      style << css.xml_dom
      style=File.new("#{path_style}/#{fn_css.docbook_xml}",'w')
      style << css.docbook_xml
      style.close
      style=File.new("#{path_style}/#{fn_css.xhtml}",'w')
      style << css.xhtml
      style.close
    end
  end
end
module SiSU_Screen
  require "#{SiSU_lib}/screen_text_color"
end
module SiSU_Errors
  require "#{SiSU_lib}/errors"
end
__END__
https? intro check 2007-09-22