File: shtool

package info (click to toggle)
netdiag 1.2-1
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 3,268 kB
  • sloc: ansic: 23,895; sh: 5,544; makefile: 328; awk: 130
file content (1997 lines) | stat: -rwxr-xr-x 61,933 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
##
##  shtool -- Portable Shell Tool
##  Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. 
##  Version 1.2.3 (06-May-1999)
##

##
##  LICENSE
##  =======
##
##  ====================================================================
##  Copyright (c) 1994-1999 Ralf S. Engelschall. All rights reserved.
## 
##  Redistribution and use in source and binary forms, with or without
##  modification, are permitted provided that the following conditions
##  are met:
## 
##  1. Redistributions of source code must retain the above copyright
##     notice, this list of conditions and the following disclaimer. 
## 
##  2. Redistributions in binary form must reproduce the above copyright
##     notice, this list of conditions and the following disclaimer in
##     the documentation and/or other materials provided with the
##     distribution.
## 
##  3. All advertising materials mentioning features or use of this
##     software must display the following acknowledgment:
##     "This product includes software developed by
##      Ralf S. Engelschall <rse@engelschall.com>."
## 
##  4. Redistributions of any form whatsoever must retain the following
##     acknowledgment:
##     "This product includes software developed by
##      Ralf S. Engelschall <rse@engelschall.com>."
## 
##  THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
##  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
##  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
##  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL RALF S. ENGELSCHALL OR
##  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
##  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
##  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
##  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
##  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
##  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
##  OF THE POSSIBILITY OF SUCH DAMAGE.
##  ====================================================================
##
##  This product includes software developed by the Apache Group
##  for use in the Apache HTTP server project (http://www.apache.org/)
##

##
##  Usage: shtool <command> [<options>] [<args>]
##
##  Available commands:
##  echo         Print command with optional construct expansion
##  table        Pretty print a field-sperarated list as a table
##  prop         Display a process indication though a running propeller
##  move         Move files with simultan substitution and optimized movement
##  install      Install a program, script or datafile
##  mkdir        Make a directory
##  mkln         Extended ln(1) command which calculates relative links
##  mkshadow     Create a shadow tree
##  fixperm      Fix file permission inside a source tree
##  guessos      Simple OS/Platform guesser
##  arx          Archive (ar) wrapper command.
##  slo          Separate Linker Options by library class
##  version      Generate and maintain a version information file
##  path         Deal with $PATH variables
##

if [ $# -eq 0 ]; then
    echo "$0:Error: Invalid command line" 1>&2
fi
if [ $# -eq 0 -o ".$1" = .-h ]; then
    echo "$0:Usage: shtool <command> [<options>] [<args>]" 
    echo ""
    echo "Available commands are:"
    echo ""
    echo '  echo       [-n] [-e] <string> [<string> ...]'
    echo '  table      [-F <sep>] [-w <width>] [-c <cols>] [-s <strip>]'
    echo '             <str><sep><str><sep><str>...'
    echo '  prop       [-p <prefix>]'
    echo '  move       [-e] [-p] <src> <dst>'
    echo '  install    [-c] [-m <mode>] [-o <owner>] [-g <group>]'
    echo '             [-s] [-S <stripflags>] [-e <extension>] <file> <dir-or-file>'
    echo '  mkdir      [-f] [-p] [-m <mode>] <dir> [<dir> ...]'
    echo '  mkln       [-v] [-f] [-s] <src> [<src> ...] <dst>'
    echo '  mkshadow   <srcdir> <dstdir>'
    echo '  fixperm    <file-or-dir> [<file-or-dir> ...]'
    echo '  guessos    '
    echo '  arx        [-v] <ar-prg> <ar-cmd> <archive> <file> [<file>'
    echo '             ...]'
    echo '  slo        -Lxx -lxx [ -Lxx -lxx ... ]'
    echo '  version    [-l <lang>] [-n <name>] [-p <prefix>] [-s'
    echo '             <version>] [-i <knob>] [-d <type>] <file>'
    echo '  path       [-s] [-r] [-d] [-b] [-m] [-p <path>] <string>'
    echo '             [<string> ...]'
    echo ""
    exit 1
fi
if [ ".$1" = .-v ]; then
    echo "shtool 1.2.3 (06-May-1999)"
    exit 0
fi
util=$1
shift
case $util in

echo )
    #
    #   command line parsing
    #
    newline="\n"
    expand=no
    while [ ".$1" != . ]; do
        case $1 in
            -n ) newline=""; shift; continue ;;
            -e ) expand=yes; shift; continue ;;
            *  ) break ;;
        esac
    done
    text="$*"
    
    #
    #   check for broken escape sequence expansion
    #
    seo=''
    bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
    if [ ".$bytes" != .3 ]; then
        bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
        if [ ".$bytes" = .3 ]; then
            seo='-E'
        fi
    fi
    
    #
    #   determine terminal bold sequence
    #
    term_bold='' 
    tern_norm=''
    if [ $expand = yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then
        case $TERM in
            xterm|xterm*|vt220|vt220*)
                term_bold=`echo dummy | awk '{ printf("%c%c%c%c", 27, 91, 49, 109); }'`
                term_norm=`echo dummy | awk '{ printf("%c%c%c", 27, 91, 109); }'`
                ;;
            vt100|vt100*)
                term_bold=`echo dummy | awk '{ printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }'`
                term_norm=`echo dummy | awk '{ printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }'`
                ;;
        esac
        if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
            md="`tput md 2>/dev/null`"
            me="`tput me 2>/dev/null`"
            if [ ".$md" != . -a ".$me" != . ]; then
                term_bold="$xmd" 
                term_norm="$xme"
            fi
        fi
        if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
            echo "$0:Warning: unable to determine terminal sequence for bold mode" 1>&2
        fi
    fi
    
    #
    #   determine user name
    #
    username=''
    if [ $expand = yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then
        username="$LOGNAME"
        if [ ".$username" = . ]; then
            username="$USER"
            if [ ".$username" = . ]; then
                username="`(whoami) 2>/dev/null |\
                           awk '{ printf("%s", $1); }'`"
                if [ ".$username" = . ]; then
                    username="`(who am i) 2>/dev/null |\
                               awk '{ printf("%s", $1); }'`"
                    if [ ".$username" = . ]; then
                        username='unknown'
                    fi
                fi
            fi
        fi
    fi
    
    #
    #   determine user id
    #
    userid=''
    if [ $expand = yes -a ".`echo $text | egrep '%U'`" != . ]; then
        userid="`(id -u) 2>/dev/null`"
        if [ ".$userid" = . ]; then
            str="`(id) 2>/dev/null`"
            if [ ".`echo $str | grep '^uid[ 	]*=[ 	]*[0-9]*('`" != . ]; then
                userid=`echo $str | sed -e 's/^uid[ 	]*=[ 	]*//' -e 's/(.*//'`
            fi
            if [ ".$userid" = . ]; then
                userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
                        sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
                if [ ".$userid" = . ]; then
                    userid=`(ypcat passwd) 2>/dev/null |
                            egrep "^${username}:" | \
                            sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
                    if [ ".$userid" = . ]; then
                        userid='?'
                    fi
                fi
            fi
        fi
    fi
    
    #
    #   determine host name
    #
    hostname=''
    if [ $expand = yes -a ".`echo $text | egrep '%h'`" != . ]; then
        hostname="`(uname -n) 2>/dev/null |\
                   awk '{ printf("%s", $1); }'`"
        if [ ".$hostname" = . ]; then
            hostname="`(hostname) 2>/dev/null |\
                       awk '{ printf("%s", $1); }'`"
            if [ ".$hostname" = . ]; then
                hostname='unknown'
            fi
        fi
        case $hostname in
            *.* )
                domainname=".`echo $hostname | cut -d. -f2-`"
                hostname="`echo $hostname | cut -d. -f1`"
                ;;
        esac
    fi
    
    #
    #   determine domain name
    #
    domainname=''
    if [ $expand = yes -a ".`echo $text | egrep '%d'`" != . ]; then
        if [ ".$domainname" = . ]; then
            if [ -f /etc/resolv.conf ]; then
                domainname="`egrep '^[ 	]*domain' /etc/resolv.conf | head -1 |\
                             sed -e 's/.*domain//' \
                                 -e 's/^[ 	]*//' -e 's/^ *//' -e 's/^	*//' \
                                 -e 's/^\.//' -e 's/^/./' |\
                             awk '{ printf("%s", $1); }'`"
                if [ ".$domainname" = . ]; then
                    domainname="`egrep '^[ 	]*search' /etc/resolv.conf | head -1 |\
                                 sed -e 's/.*search//' \
                                     -e 's/^[ 	]*//' -e 's/^ *//' -e 's/^	*//' \
                                     -e 's/ .*//' -e 's/	.*//' \
                                     -e 's/^\.//' -e 's/^/./' |\
                                 awk '{ printf("%s", $1); }'`"
                fi
            fi
        fi
    fi
    
    #
    #   determine current time
    #
    time_day=''
    time_month=''
    time_year=''
    time_monthname=''
    if [ $expand = yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then
        time_day="`date '+%d' | awk '{ printf("%s", $1); }'`"
        time_month="`date '+%m' | awk '{ printf("%s", $1); }'`"
        time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
        if test ".$time_year" = .; then
            time_year="`date '+%y' | awk '{ printf("%s", $1); }'`"
            case $time_year in
                9[0-9]*) time_year="19$time_year" ;;
                      *) time_year="20$time_year" ;;
            esac
        fi
        case $time_month in
            1|01) time_monthname='Jan' ;;
            2|02) time_monthname='Feb' ;;
            3|03) time_monthname='Mar' ;;
            4|04) time_monthname='Apr' ;;
            5|05) time_monthname='May' ;;
            6|06) time_monthname='Jun' ;;
            7|07) time_monthname='Jul' ;;
            8|08) time_monthname='Aug' ;;
            9|09) time_monthname='Sep' ;;
              10) time_monthname='Oct' ;;
              11) time_monthname='Nov' ;;
              12) time_monthname='Dec' ;;
        esac
    fi
    
    #
    #   expand special ``%x'' constructs
    #
    if [ $expand = yes ]; then
        text=`echo $seo "$text" |\
              sed -e "s;%B;${term_bold};g" \
                  -e "s;%b;${term_norm};g" \
                  -e "s;%u;${username};g" \
                  -e "s;%U;${userid};g" \
                  -e "s;%h;${hostname};g" \
                  -e "s;%d;${domainname};g" \
                  -e "s;%D;${time_day};g" \
                  -e "s;%M;${time_month};g" \
                  -e "s;%Y;${time_year};g" \
                  -e "s;%m;${time_monthname};g"`
    fi
    
    #
    #   create output
    #
    echo dummy |\
    awk '{ printf("%s%s", TEXT, NEWLINE); }' \
        TEXT="$text" NEWLINE="$newline"
;;

table )
    #
    #   command line parsing
    #
    width=15
    cols=3
    sep=':'
    strip=79
    while [ ".$1" != . ]; do
        case $1 in
            -F ) sep="$2";   shift; shift; continue ;;
            -w ) width="$2"; shift; shift; continue ;;
            -c ) cols="$2";  shift; shift; continue ;;
            -s ) strip="$2";   shift; shift; continue ;;
            *  ) break ;;
        esac
    done
    case x$sep in
        x? ) ;;
        *  ) echo "$0:Error: Invalid seperator (one char allowed only)" 1>&2; exit 1 ;;
    esac
    if [ $cols -gt 4 ]; then
        echo "$0:Error: Invalid number of colums (1..4 allowed only)" 1>&2
        exit 1
    fi
    
    #
    #   split the list into a table
    #
    list=`
        IFS="$sep"
        for entry in $*; do
            if [ ".$entry" != . ]; then
                echo "$entry"
            fi
        done |\
        awk "
            BEGIN { list = \"\"; n = 0; }
            { 
                list = list \\$1;
                n = n + 1;
                if (n < $cols) {
                    list = list \":\";
                }
                if (n == $cols) {
                    list = list \"\\n\";
                    n = 0;
                }
            }
            END { print list; }
         "
    `
    
    #
    #   format table cells and make sure table 
    #   doesn't exceed maximum width
    #
    IFS='
    '
    for entry in $list; do
        case $cols in
            1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s\\n\", \$1); }'" ;;
            2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s\\n\", \$1, \$2); }'" ;;
            3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s %-${width}s\\n\", \$1, \$2, \$3); }'" ;;
            4 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${width}s %-${width}s %-${width}s %-${width}s\\n\", \$1, \$2, \$3, \$4); }'" ;;
        esac
    done |\
    awk "{ 
        if (length(\$0) > $strip) { 
            printf(\"%s\\n\", substr(\$0, 0, $strip-1));
        } else { 
            print \$0; 
        }
    }"
;;

prop )
    #
    #   command line parsing
    #
    prefix=""
    while [ ".$1" != . ]; do
        case $1 in
            -p ) prefix="$2"; shift; shift; continue ;;
            *  ) break ;;
        esac
    done
    if [ $# -gt 0 ]; then
        echo "$0:Error: too much arguments" 1>&2
        exit 1
    fi
    
    perl=''
    for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
        if [ -f "$dir/perl" ]; then
            perl="$dir/perl"
            break
        fi
    done
    if [ ".$perl" != . ]; then
        #   Perl is preferred because writing to STDERR in
        #   Perl really writes immediately as one would expect
        $perl -e '
            @p = ("|","/","-","\\"); 
            $i = 0; 
            while (<STDIN>) { 
                printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]);
                $i = 0 if ($i > 3); 
            }
            printf(STDERR "\r%s    \n", $ARGV[0]);
        ' "$prefix"
    else
        #   But when Perl doesn't exists we use Awk even
        #   some Awk's buffer even the /dev/stderr writing :-(
        awk '
            BEGIN { 
                split("|#/#-#\\", p, "#");
                i = 1; 
            } 
            { 
                printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr"; 
                if (i > 4) { i = 1; } 
            }
            END {
                printf("\r%s    \n", prefix) > "/dev/stderr";
            }
        ' "prefix=$prefix" 
    fi
;;

move )
    #
    #   command line parsing
    #
    expand=no
    preserve=no
    while [ ".$1" != . ]; do
        case $1 in
            -e ) expand=yes ; shift; continue ;;
            -p ) preserve=yes ; shift; continue ;;
            *  ) break ;;
        esac
    done
    if [ $# -ne 2 ]; then
        echo "$0:Usage: move [-e] [-p] <src> <dst>" 1>&2
        exit 1
    fi
    src=$1
    dst=$2
    
    #
    #   consistency checks
    #
    if [ ".$src" = . -o ".$dst" = . ]; then
        echo "$0:Error: Invalid arguments" 1>&2
        exit 1
    fi
    if [ ".$src" = ".$dst" ]; then
        echo "$0:Error: Source and destination files are the same" 1>&2
        exit 1
    fi
    expsrc="$src"
    if [ $expand = yes ]; then
        expsrc="`echo $expsrc`"
    fi
    if [ $expand = yes ]; then
        if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then
            echo "$0:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2
            exit 1
        fi
        if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then
            echo "$0:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2
            exit 1
        fi
        if [ ".$expsrc" = ".$src" ]; then
            echo "$0:Error: Sources not found or no asterisk : $src" 1>&2
            exit 1
        fi
    else
        if [ ! -r "$src" ]; then
            echo "$0:Error: Source not found: $src" 1>&2
            exit 1
        fi
    fi
    
    #
    #   determine substitution patterns
    #
    if [ $expand = yes ]; then
        srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'`
        dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'`
    fi
    
    #
    #   iterate over source(s)
    #
    for onesrc in $expsrc; do
        if [ $expand = yes ]; then
            onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"`
        else
            onedst="$dst"
        fi
        errorstatus=0
        if [ -r $onedst ]; then
            if cmp -s $onesrc $onedst; then
                rm -f $onesrc || errstatus=$?
            else
                mv -f $onesrc $onedst || errstatus=$?
            fi
        else
            mv -f $onesrc $onedst || errstatus=$?
        fi
        if [ $errorstatus -ne 0 ]; then
            break;
        fi
    done
    
    #   die gracefully
    exit $errorstatus
;;

install )
    #
    #   put in absolute paths if you don't have them in your path; 
    #   or use env. vars.
    #
    mvprog="${MVPROG-mv}"
    cpprog="${CPPROG-cp}"
    chmodprog="${CHMODPROG-chmod}"
    chownprog="${CHOWNPROG-chown}"
    chgrpprog="${CHGRPPROG-chgrp}"
    stripprog="${STRIPPROG-strip}"
    rmprog="${RMPROG-rm}"
    
    #
    #   parse argument line
    #
    instcmd="$mvprog"
    chmodcmd=""
    chowncmd=""
    chgrpcmd=""
    stripcmd=""
    rmcmd="$rmprog -f"
    mvcmd="$mvprog"
    ext=""
    src=""
    dst=""
    while [ ".$1" != . ]; do
        case $1 in
            -c) instcmd="$cpprog"
                shift; continue
                ;;
            -m) chmodcmd="$chmodprog $2"
                shift; shift; continue
                ;;
            -o) chowncmd="$chownprog $2"
                shift; shift; continue
                ;;
            -g) chgrpcmd="$chgrpprog $2"
                shift; shift; continue
                ;;
            -s) stripcmd="$stripprog"
                shift; continue;;
            -S) stripcmd="$stripprog $2"
                shift; shift; continue ;;
            -e) ext="$2"
                shift; shift; continue
                ;;
            *)  if [ ".$src" = . ]; then
                    src=$1
                else
                    dst=$1
                fi
                shift; continue
                ;;
        esac
    done
    if [ ".$src" = . ]; then
         echo "install.sh: no input file specified"
         exit 1
    fi
    if [ ".$dst" = . ]; then
         echo "install.sh: no destination specified"
         exit 1
    fi
    
    #
    #  If destination is a directory, append the input filename; if
    #  your system does not like double slashes in filenames, you may
    #  need to add some logic
    #
    if [ -d $dst ]; then
        dst="$dst/`basename $src`"
    fi
    
    #  Add a possible extension (such as ".exe") to src and dst
    src="$src$ext"
    dst="$dst$ext"
    
    #  Make a temp file name in the proper directory.
    dstdir=`dirname $dst`
    dsttmp=$dstdir/#inst.$$#
    
    #  Move or copy the file name to the temp name
    $instcmd $src $dsttmp
    
    #  And set any options; do chmod last to preserve setuid bits
    if [ ".$chowncmd" != . ]; then $chowncmd $dsttmp; fi
    if [ ".$chgrpcmd" != . ]; then $chgrpcmd $dsttmp; fi
    if [ ".$stripcmd" != . ]; then $stripcmd $dsttmp; fi
    if [ ".$chmodcmd" != . ]; then $chmodcmd $dsttmp; fi
    
    #  Now rename the file to the real destination.
    $rmcmd $dst
    $mvcmd $dsttmp $dst
    
    exit 0
;;

mkdir )
    #   command line parsing
    mode=""
    force=0
    parent=0
    while [ ".$1" != . ]; do
        case $1 in
            -f)  force=1;          shift; continue ;; 
            -p)  parent=1;         shift; continue ;;
            -m)  mode="$2"; shift; shift; continue ;;
             *)  break ;;
        esac
    done
    if [ $# -eq 0 ]; then
        echo "$0:Usage: mkdir [-f] [-p] [-m <mode>] <dir> [<dir> ...]" 1>&2
        exit 1
    fi
    
    errstatus=0
    for p in ${1+"$@"}; do 
        #   when the directory already exists...
        if [ -d "$p" ]; then
            if [ $force = 0 ]; then
                echo "$0:Error: file exists: $p" 1>&2
                errstatus=1
                break
            else
                continue
            fi
        fi
        #   when the directory has to be created
        if [ $parent = 0 ]; then
            mkdir $p || errstatus=$?
        else
            #   the smart situation
            set fnord `echo ":$p" |\
                       sed -e 's/^:\//%/' \
                           -e 's/^://' \
                           -e 's/\// /g' \
                           -e 's/^%/\//'`
            shift
            pathcomp=
            for d in ${1+"$@"}; do
                pathcomp="$pathcomp$d"
                case "$pathcomp" in
                    -* ) pathcomp="./$pathcomp" ;;
                esac
                if [ ! -d "$pathcomp" ]; then
                    mkdir $pathcomp || errstatus=$?
                    if [ ".$mode" != . ]; then
                        chmod $mode $pathcomp || errstatus=$?
                    fi
                fi
                pathcomp="$pathcomp/"
            done
        fi
    done
    exit $errstatus
;;

mkln )
    #
    #   command line parsing
    #
    verbose=no
    force=no
    symbolic=no
    while [ ".$1" != . ]; do
        case $1 in
            -v)  verbose=yes; shift; continue ;; 
            -f)  force=yes; shift; continue ;; 
            -s)  symbolic=yes; shift; continue ;; 
             *)  break ;;
        esac
    done
    if [ $# -lt 2 ]; then
        echo "$0:Usage: mkln [-v] [-f] [-s] <from> [<from> ...] <to>" 1>&2
        exit 1
    fi
    args=$?
    srcs=""
    while [ $# -gt 1 ]; do
        srcs="$srcs $1"
        shift
    done
    dst="$1"
    if [ ! -d $dst ]; then
        if [ $args -gt 2 ]; then
            echo "$0:Error: multiple sources not allowed when destination isn't a directory" 1>&2
            exit 1
        fi
    fi
    
    #
    #   determine link options
    #
    lnopt=""
    if [ $force = yes ]; then
        lnopt="$lnopt -f"
    fi
    if [ $symbolic = yes ]; then
        lnopt="$lnopt -s"
    fi
    
    #
    #   iterate over sources
    #
    for src in $srcs; do
        #   debugging
        if [ $verbose = yes ]; then
            echo "src=\"$src\" dst=\"$dst\":"
        fi
    
        #   determine if one of the paths is an absolute path,
        #   because then we _have_ to use an absolute symlink
        oneisabs=0
        srcisabs=0
        dstisabs=0
        case $src in
            /* ) oneisabs=1; srcisabs=1 ;;
        esac
        case $dst in
            /* ) oneisabs=1; dstisabs=1 ;;
        esac
    
        #   split source and destination into dir and base name
        if [ -d $src ]; then
            srcdir=`echo $src | sed -e 's;/*$;;'`
            srcbase=""
        else
            srcdir=`echo  $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
            srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`
        fi
        if [ -d $dst ]; then
            dstdir=`echo $dst | sed -e 's;/*$;;'`
            dstbase=""
        else
            dstdir=`echo  $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
            dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`
        fi
    
        #   debugging
        if [ $verbose = yes ]; then
            echo "  STATE 1:"
            echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
            echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
            echo "  oneisabs=$oneisabs"
        fi
    
        #   consistency check
        if [ ".$dstdir" != . ]; then
            if [ ! -d $dstdir ]; then
                echo "$0:Error: destination directory not found: $dstdir" 1>&2
                exit 1
            fi
        fi
    
        #   make sure the source is reachable from the destination
        if [ $dstisabs = 1 ]; then
            if [ $srcisabs = 0 ]; then
                if [ -d $srcdir ]; then
                    srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"
                    srcisabs=1
                    oneisabs=1
                    #   debugging
                    if [ $verbose = yes ]; then
                        echo "  STATE 2:"
                        echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
                        echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
                        echo "  oneisabs=$oneisabs"
                    fi
                fi
            fi
        fi
    
        #   split away a common prefix
        prefix=""
        if [ ".$srcdir" = ".$dstdir" ] && [ ".$srcdir" != . ]; then
            prefix="$srcdir/"
            srcdir=""
            dstdir=""
        else
            while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do
                presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`
                predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`
                if [ ".$presrc" != ".$predst" ]; then
                    break
                fi
                prefix="$prefix$presrc/"
                srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`
                dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`
            done
        fi
    
        #   debugging
        if [ $verbose = yes ]; then
            echo "  STATE 3:"
            echo "  prefix=$prefix"
            echo "  srcisabs=$srcisabs srcdir=\"$srcdir\" srcbase=\"$srcbase\""
            echo "  dstisabs=$dstisabs dstdir=\"$dstdir\" dstbase=\"$dstbase\""
            echo "  oneisabs=$oneisabs"
        fi
    
        #   destination prefix is just the common prefix
        dstpre="$prefix"
    
        #   determine source prefix which is the reverse directory
        #   step-up corresponding to the destination directory
        srcpre=""
        if [ $oneisabs = 0 ] || [ ".$prefix" != . -a ".$prefix" != ./ ]; then
            pl="$dstdir/"
            OIFS="$IFS"; IFS='/'
            for pe in $pl; do
                [ ".$pe" = . ] && continue
                srcpre="../$srcpre"
            done
            IFS="$OIFS"
        else
            if [ $srcisabs = 1 ]; then
                srcpre="$prefix"
            fi
        fi
    
        #   debugging
        if [ $verbose = yes ]; then
            echo "  STATE 4:"
            echo "  prefix=$prefix"
            echo "  srcisabs=$srcisabs srcpre=\"$srcpre\" srcdir=\"$srcdir\" srcbase=\"$srcbase\""
            echo "  dstisabs=$dstisabs dstpre=\"$dstpre\" dstdir=\"$dstdir\" dstbase=\"$dstbase\""
            echo "  oneisabs=$oneisabs"
        fi
    
        #   determine destination symlink name
        if [ ".$dstbase" = . ]; then
            if [ ".$srcbase" != . ]; then
                dstbase="$srcbase"
            else
                dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`
            fi
        fi
    
        #   now finalize source and destination directory paths
        srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
        dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
    
        #   debugging
        if [ $verbose = yes ]; then
            echo "  STATE 5:"
            echo "  prefix=$prefix"
            echo "  srcisabs=$srcisabs srcpre=\"$srcpre\" srcdir=\"$srcdir\" srcbase=\"$srcbase\""
            echo "  dstisabs=$dstisabs dstpre=\"$dstpre\" dstdir=\"$dstdir\" dstbase=\"$dstbase\""
            echo "  oneisabs=$oneisabs"
        fi
    
        #   run the final link command
        if [ $verbose = yes ]; then
            echo "  RESULT:"
            echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
        fi
        eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
    done
    exit 0
;;

mkshadow )
    #   default IFS
    DIFS=' 	
    '
    
    #   command line check
    if [ $# -ne 2 ]; then
        echo "$0:Error: Invalid aruments" 1>&2
        exit 1
    fi
    
    #   source and destination directory
    src=`echo $1 | sed -e 's:/$::'`
    dst=`echo $2 | sed -e 's:/$::'`
    
    #   check whether source exists
    if [ ! -d $src ]; then
        echo "$0:Error: source directory not found" 1>&2
        exit 1
    fi
    
    #   determine if one of the paths is an absolute path,
    #   because then we have to use an absolute symlink
    oneisabs=0
    case $src in
        /* ) oneisabs=1 ;;
    esac
    case $dst in
        /* ) oneisabs=1 ;;
    esac
    
    #   determine reverse directory for destination directory
    dstrevdir=''
    if [ $oneisabs = 0 ]; then
        #   (inlined fp2rp)
        OIFS="$IFS"; IFS='/'
        for pe in $dst; do
            dstrevdir="../$dstrevdir"
        done
        IFS="$OIFS"
    else
        src="`cd $src; pwd`";
    fi
    
    #   create directory tree at destination
    if [ ! -d $dst ]; then
        mkdir $dst
    fi
    DIRS="`cd $src
           find . -type d -print |\
           sed -e '/\/CVS/d' \
               -e '/^\.$/d' \
               -e 's:^\./::'`"
    OIFS="$IFS" IFS="$DIFS"
    for dir in $DIRS; do
        mkdir $dst/$dir
    done
    IFS="$OIFS"
    
    #   fill directory tree with symlinks to files
    FILES="`cd $src
            find . -depth -print |\
            sed -e '/\.o$/d' \
                -e '/\.a$/d' \
                -e '/\.so$/d' \
                -e '/\.so-o$/d' \
                -e '/\.cvsignore$/d' \
                -e '/\/CVS/d' \
                -e '/\.indent\.pro$/d' \
                -e '/\.apaci.*/d' \
                -e '/Makefile$/d' \
                -e '/\/\.#/d' \
                -e '/\.orig$/d' \
                -e 's/^\.\///'`"
    OIFS="$IFS" IFS="$DIFS"
    for file in $FILES; do
         #  don't use `-type f' above for find because of symlinks
         if [ -d $file ]; then
             continue
         fi
         basename=`echo $file | sed -e 's:^.*/::'`
         dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
         from="$src/$file"
         to="$dst/$dir$basename"
         if [ $oneisabs = 0 ]; then
             if [ ".$dir" != . ]; then
                 subdir=`echo $dir | sed -e 's:/$::'`
                 #   (inlined fp2rp)
                 revdir=''
                 OIFS2="$IFS"; IFS='/'
                 for pe in $subdir; do
                     revdir="../$revdir"
                 done
                 IFS="$OIFS2"
                 #   finalize from
                 from="$revdir$from"
             fi
             from="$dstrevdir$from"
         fi
         echo "    $to"
         ln -s $from $to
    done
    IFS="$OIFS"
;;

fixperm )
    for p in $*; do
        for file in `find $p -depth -print`; do
            if [ -f $file ]; then
                if [ -x $file ]; then
                    echo "    $file (FILE/EXEC)"
                    chmod 775 $file
                else
                    echo "    $file (FILE/REGULAR)"
                    chmod 664 $file
                fi
                continue
            fi
            if [ -d $file ]; then
                echo "    $file (DIR)"
                chmod 775 $file
                continue
            fi
            echo "    $file (UNKNOWN)"
        done
    done
;;

guessos )
    MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
    RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
     SYSTEM=`(uname -s) 2>/dev/null` ||  SYSTEM="unknown"
    VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
    
    XREL=`(uname -X) 2>/dev/null | grep "^Release" | awk '{print $3}'`
    if [ "x$XREL" != "x" ]; then
        if [ -f /etc/kconfig ]; then
            case "$XREL" in
                4.0|4.1) echo "${MACHINE}-whatever-isc4"; exit 0 ;;
            esac
        else
        case "$XREL" in
            3.2v4.2) 
                echo "whatever-whatever-sco3"; exit 0 
                ;;
            3.2v5.0*) 
                echo "whatever-whatever-sco5"; exit 0 
                ;;
            4.2MP)
                if [ "x$VERSION" = "x2.1.1" ]; then
                    echo "${MACHINE}-whatever-unixware211"; exit 0
                elif [ "x$VERSION" = "x2.1.2" ]; then
                    echo "${MACHINE}-whatever-unixware212"; exit 0
                else
                    echo "${MACHINE}-whatever-unixware2"; exit 0
                fi
                ;;
            4.2) 
                echo "whatever-whatever-unixware1"; exit 0 
                ;;
            5)
                case "$VERSION" in
                    7*) echo "${MACHINE}-whatever-unixware7"; exit 0 ;;
                esac
                ;;
        esac
        fi
    fi
    case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
        MiNT:*)
            echo "m68k-atari-mint"; exit 0
            ;;
        A/UX:*)
            echo "m68k-apple-aux3"; exit 0
            ;;
        AIX:*)
            echo "${MACHINE}-ibm-aix${VERSION}.${RELEASE}"; exit 0
            ;;
        dgux:*)
            echo "${MACHINE}-dg-dgux"; exit 0
            ;;
        HI-UX:*)
            echo "${MACHINE}-hi-hiux"; exit 0
            ;;
        HP-UX:*)
            HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
            echo "${MACHINE}-hp-hpux${HPUXVER}"; exit 0
            ;;
        IRIX:*)
            if [ -f /usr/lib32/mips4/libm.so ]; then
                echo "${MACHINE}-sgi-irix32"; exit 0
            else
                echo "${MACHINE}-sgi-irix"; exit 0
            fi
            ;;
        IRIX64:*)
            echo "${MACHINE}-sgi-irix64"; exit 0
            ;;
        Linux:[2-9].*)
            echo "${MACHINE}-whatever-linux2"; exit 0
            ;;
        Linux:1.*)
            echo "${MACHINE}-whatever-linux1"; exit 0
            ;;
        LynxOS:*)
            echo "${MACHINE}-lynx-lynxos"; exit 0
            ;;
        BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
            echo "i486-whatever-bsdi"; exit 0
            ;;
        BSD/386:*|BSD/OS:*)
            echo "${MACHINE}-whatever-bsdi"; exit 0
            ;;
        FreeBSD:*)
            VERS=`echo ${RELEASE} | sed -e 's/[-(].*//'`
            MACH=`sysctl -n hw.model`
            ARCH='whatever'
            case ${MACH} in
               *386*       ) MACH="i386"     ;;
               *486*       ) MACH="i486"     ;;
               Pentium\ II*) MACH="i686"     ;;
               Pentium*    ) MACH="i586"     ;;
               Alpha*      ) MACH="alpha"    ;;
               *           ) MACH="$MACHINE" ;;
            esac
            case ${MACH} in
               i[0-9]86 ) ARCH="pc" ;;
            esac
            echo "${MACH}-${ARCH}-freebsd${VERS}"; exit 0
            ;;
        NetBSD:*:*:*486*)
            echo "i486-whatever-netbsd"; exit 0
            ;;
        NetBSD:*)
            echo "${MACHINE}-whatever-netbsd"; exit 0
            ;;
        OpenBSD:*)
            echo "${MACHINE}-whatever-openbsd"; exit 0
            ;;
        OSF1:*:*:*alpha*)
            echo "${MACHINE}-dec-osf"; exit 0
            ;;
        QNX:*)
            if [ "$VERSION" -gt 422 ]; then
                echo "${MACHINE}-qssl-qnx32"
            else
                echo "${MACHINE}-qssl-qnx"
            fi
            exit 0
            ;;
        Paragon*:*:*:*)
            echo "i860-intel-osf1"; exit 0
            ;;
        SunOS:5.*)
            SOLVER=`echo ${RELEASE}|awk -F. '{
            if (NF < 3)
                printf "2%s0\n",$2
            else
                printf "2%s%s\n",$2,$3
            }'`
            echo "${MACHINE}-sun-solaris2.${SOLVER}"; exit 0
            ;;
        SunOS:*)
            echo "${MACHINE}-sun-sunos4"; exit 0
            ;;
        UNIX_System_V:4.*:*)
            echo "${MACHINE}-whatever-sysv4"; exit 0
            ;;
        unix:3.0.9*:*:88k)
            echo "${MACHINE}-encore-sysv4"; exit 0
            ;;
        *:4*:R4*:m88k)
            echo "${MACHINE}-whatever-sysv4"; exit 0
            ;;
        UnixWare:5:99*:*)
            # Gemini, beta release of next rev of unixware
            echo "${MACHINE}-whatever-unixware212"; exit 0
            ;;
        DYNIX/ptx:4*:*)
            echo "${MACHINE}-whatever-sysv4"; exit 0
            ;;
        *:4.0:3.0:[345][0-9]?? | *:4.0:3.0:3[34]??[/,]* | library:*)
            echo "x86-ncr-sysv4"; exit 0
            ;;
        ULTRIX:*)
            echo "${MACHINE}-unknown-ultrix"; exit 0
            ;;
        SINIX-?:* | ReliantUNIX-?:*)
            echo "${MACHINE}-siemens-sysv4"; exit 0
            ;;
        POSIX*BS2000)
            echo "${MACHINE}-siemens-sysv4"; exit 0
            ;;
        machten:*)
           echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
           ;;
        ConvexOS:*:11.*:*)
           echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
           ;;
        UNIX_SV:*:*:maxion)
           echo "${MACHINE}-ccur-sysv4"; exit 0;
           ;;
        PowerMAX_OS:*:*:Night_Hawk)
           MACHINE=`uname -p`
           echo "${MACHINE}-concurrent-powermax"; exit 0;
           ;;
        UNIX_SV:*)
           if [ -d /usr/nec ];then
               echo "mips-nec-sysv4"; exit 0;
           fi
           ;;
        NonStop-UX:4.[02]*:[BC]*:*)
           echo "${MACHINE}-tandem-sysv4"; exit 0;
           ;;
        Rhapsody:*:*:*)
           case "${MACHINE}" in
               Power*) MACHINE=powerpc ;;
           esac
           echo "${MACHINE}-apple-rhapsody${RELEASE}"; exit 0
           ;;
        "RISC iX":*)
           echo "arm-whatever-riscix"; exit 0;
           ;;
        *:4.0:2:*)
           echo "whatever-unisys-sysv4"; exit 0;
           ;;
        *:*:dcosx:NILE*)
           echo "pyramid-pyramid-svr4"; exit 0;
           ;;
        *:*:*:"DRS 6000")
           echo "drs6000-whatever-whatever"; exit 0;
           ;;
    esac
    # existance of the /usr/apollo directory is proof enough for Apollo
    if [ -d /usr/apollo ]; then
        echo "whatever-apollo-whatever"
        exit 0
    fi
    # Now NeXT
    ISNEXT=`hostinfo 2>/dev/null`
    case "$ISNEXT" in
        *NeXT*)
             # Swiped from a friendly uname clone for NEXT/OPEN Step.
             NEXTOSVER="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`"
             if [ "$NEXTOSVER" -gt 3.3 ]; then
                 NEXTOS="openstep"
             else
                 NEXTOS="nextstep"
             fi
             NEXTREL="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`" 
             NEXTARCH=`arch`
             echo "${NEXTARCH}-next-${NEXTOS}${NEXTREL}" ; exit 0
             ;;
    esac
    
    echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}"
;;

arx )
    #
    #   command line parsing
    #
    verbose=no
    while [ ".$1" != . ]; do
        case $1 in
            -v)  verbose=yes; shift; continue ;; 
             *)  break ;;
        esac
    done
    if [ $# -le 4 ]; then
        echo "$0:Usage: arx [-v] <ar-prg> <ar-cmd> <archive> <file> [<file> ...]" 1>&2
        exit 1
    fi
    ar_prg=$1;  shift
    ar_cmd=$1;  shift
    archive=$1; shift
    files="$*"
    
    #
    #   walk through the file list and expand archives members
    #
    tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
    nfiles=""
    for file in $files; do
        if [ ! -f $file ]; then
            echo "$0:Error: input file not found: $file" 1>&2
            exit 1
        fi
        case $file in
            *.a ) 
                if [ ! -d $tmpdir ]; then
                    if [ $verbose = yes ]; then
                        echo "mkdir $tmpdir"
                    fi
                    mkdir $tmpdir
                fi
                case $tmpdir in
                     .arx ) 
                         from="../$file"
                         ;;
                     * )
                         dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
                         base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
                         from="`cd $dir; pwd`/$base"
                         ;;
                esac
                if [ $verbose = yes ]; then
                    echo "(cd $tmpdir && $ar_prg x $from)"
                fi
                (cd $tmpdir && eval $ar_prg x $from)
                if [ $? -ne 0 ]; then
                    echo "$0:Error: member extraction failed for archive: $file" 1>&2
                    exit 1
                fi
                for member in - `eval $ar_prg t $file`; do
                    [ ".$member" = .- ] && continue
                    nfiles="$nfiles $tmpdir/$member"
                done
                ;;
            * )
                nfiles="$nfiles $file"
                ;;
        esac
    done
    
    #
    #   run the final archive command
    #
    if [ $verbose = yes ]; then
        echo "$ar_prg $ar_cmd $archive $nfiles"
    fi
    eval $ar_prg $ar_cmd $archive $nfiles
    if [ $? -ne 0 ]; then
        echo "$0:Error: archive command failed" 1>&2
        exit $?
    fi
    
    #
    #   cleanup and die gracefully
    #
    if [ -d $tmpdir ]; then
        if [ $verbose = yes ]; then
            echo "rm -rf $tmpdir"
        fi
        rm -rf $tmpdir
    fi
    exit 0
;;

slo )
    DIFS=' 	
    '
    
    #   
    #   parse out -L and -l options from command line
    #
    DIRS=''
    LIBS=''
    ARGV=''
    optprev=""
    OIFS="$IFS" IFS="$DIFS"
    for opt
    do
        #   concatenate with previous option if exists
        if [ ".$optprev" != . ]; then
            opt="${optprev}${opt}";
            optprev=''
        fi
        #   remember options for arg when used stand-alone
        if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then
            optprev="$opt"
            continue;
        fi
        #   split argument into option plus option argument
        arg="`echo $opt | cut -c3-`"
        opt="`echo $opt | cut -c1-2`"
        #   store into containers
        case $opt in
            -L) DIRS="$DIRS:$arg" ;;
            -l) LIBS="$LIBS:$arg" ;;
             *) ARGV="$ARGV $opt" ;;
        esac
    done
    IFS="$OIFS"
    
    #
    #   set linker default directories
    #
    DIRS_DEFAULT='/lib:/usr/lib'
    if [ ".$LD_LIBRARY_PATH" != . ]; then
        DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
    fi
    
    #
    #   sort options by class
    #
    DIRS_OBJ=''
    LIBS_OBJ=''
    DIRS_PIC=''
    LIBS_PIC=''
    DIRS_DSO=''
    LIBS_DSO=''
    
    #    for each library...
    OIFS="$IFS" IFS=':'
    for lib in $LIBS; do
        [ ".$lib" = . ] && continue
    
        found='no'
        found_indefdir='no'
        found_type=''
        found_dir=''
    
        #    for each directory...
        OIFS2="$IFS" IFS=":$DIFS"
        for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
            [ ".$dir" = . ] && continue
            [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
            [ ! -d $dir ] && continue
    
            #    search the file
            OIFS3="$IFS" IFS="$DIFS"
            for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do
                 [ ".$file" = . ] && continue
                 case $file in
                     *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
                          found=yes;
                          found_type=DSO; 
                          break 
                          ;;
                     *.lo|*.la )
                          found=yes;
                          found_type=PIC 
                          ;;
                     *.a )
                          if [ ".$found_type" = . ]; then
                              found=yes
                              found_type=OBJ 
                          fi
                          ;;
                 esac
            done
            IFS="$OIFS3"
            if [ ".$found" = .yes ]; then
                found_dir="$dir"
                break
            fi
        done
        IFS="$OIFS2"
    
        if [ ".$found" = .yes ]; then
            if [ ".$found_indefdir" != .yes ]; then
                eval "dirlist=\"\${DIRS_${found_type}}:\""
                if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then
                    eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\""
                fi
                eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
            else
                eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
            fi
        else
            LIBS_OBJ="$LIBS_OBJ:$lib"
            #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
            #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
            #echo "slo:Warning: $dirlist" 1>&1
        fi
    done
    IFS="$OIFS"
    
    #
    #   also pass-through unused dirs even if it's useless
    #
    OIFS="$IFS" IFS=':'
    for dir in $DIRS; do
        dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
        if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then
            DIRS_OBJ="$DIRS_OBJ:$dir"
        fi
    done
    IFS="$OIFS"
    
    #
    #   reassemble the options but seperated by type
    #
    OIFS="$IFS" IFS="$DIFS"
    for type in OBJ PIC DSO; do
        OIFS2="$IFS" IFS=':'
        eval "libs=\"\$LIBS_${type}\""
        opts=''
        for lib in $libs; do
            [ ".$lib" = . ] && continue
            opts="$opts -l$lib"
        done
        eval "LIBS_${type}=\"$opts\""
    
        eval "dirs=\"\$DIRS_${type}\""
        opts=''
        for dir in $dirs; do
            [ ".$dir" = . ] && continue
            opts="$opts -L$dir"
        done
        eval "DIRS_${type}=\"$opts\""
        IFS="$OIFS2"
    done
    IFS="$OIFS"
    
    #
    #   give back results
    #
    OIFS="$IFS" IFS="$DIFS"
    for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
        eval "val=\"\$${var}\""
        val="`echo $val | sed -e 's/^ *//'`"
        echo "SLO_${var}=\"${val}\""
    done
    IFS="$OIFS"
;;

version )
    LANGUAGE=txt
    NAME=unknown
    PREFIX=unknown
    FULLVERSION=unknown
    REPORT=NO
    INCREASE=P
    USAGE=NO
    FILE=""
    while [ ".$1" != . ]; do
        case $1 in
            -l) LANGUAGE=$2; shift; shift; continue ;;
            -n) NAME=$2; shift; shift; continue ;;
            -p) PREFIX=$2; shift; shift; continue ;;
            -s) FULLVERSION=$2; shift; shift; continue ;;
            -i) INCREASE=$2; shift; shift; continue ;;
            -d) REPORT=$2; shift; shift; continue ;;
            -h) USAGE=YES; shift; continue ;;
             *) break;
        esac
    done
    if [ $# -ne 1 ]; then
        USAGE=YES
    else
        FILE=$1
    fi
    
    if [ ".$USAGE" = .YES ]; then
        echo "$0:Usage: version [options] file"
        echo "Options are:"
        echo "-l <lang>                 set language to one of 'txt', 'c' or 'perl'" 
        echo "-n <name>                 set program name"
        echo "-p <prefix>               set symbol prefix"
        echo "-s <v>.<r>[.pb]<p>        set version string"
        echo "-i v|r|P|p|b|a|s          increase version, revision or {alpha,batch,patch,snap} level"
        echo "-d short|long|libtool|hex display current version only"
        echo "-h                        print this page"
        exit 0
    fi
    
    #   determine language
    if [ ".$LANGUAGE" = .unknown ]; then
        case $FILE in
            *.txt )       LANGUAGE=txt  ;;
            *.c )         LANGUAGE=c    ;;
            *.pl | *.pm ) LANGUAGE=perl ;;
            * )           echo "$0:Error: Unknown language type" 1>&2; exit 1 ;;
        esac
    fi
    
    #   determine prefix from name and vice versa
    if [ ".$PREFIX" = . -o ".$PREFIX" = .unknown ]; then
        if [ ".$NAME" != . -a ".$NAME" != .unknown ]; then
            PREFIX="$NAME"
        fi
    fi
    if [ ".$NAME" = . -o ".$NAME" = .unknown ]; then
        if [ ".$PREFIX" != . -a ".$PREFIX" != .unknown ]; then
            NAME="$PREFIX"
        fi
    fi
    
    #   determine version
    date=unknown
    if [ ".$FULLVERSION" = .unknown ]; then
        if [ -r "$FILE" ]; then
            #   grep out current information
            id=`grep 'Version [0-9]*.[0-9]*[.abps][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $FILE | \
                head -1 | \
                sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\1:\2:\3:\4:\5%'`
            version=`echo $id | awk -F: '{ print $1 }'`
            revision=`echo $id | awk -F: '{ print $2 }'`
            bptype=`echo $id | awk -F: '{ print $3 }'`
            bplevel=`echo $id | awk -F: '{ print $4 }'`
            date=`echo $id | awk -F: '{ print $5 }'`
            if [ .$REPORT = .NO ]; then
                case $INCREASE in
                    b ) bplevel=`expr $bplevel + 1`
                        bptype=b
                        ;;
                    a ) bplevel=`expr $bplevel + 1`
                        bptype=a
                        ;;
                    s ) bplevel=`expr $bplevel + 1`
                        bptype=s
                        ;;
                    P ) bplevel=`expr $bplevel + 1`
                        bptype=.
                        ;;
                    p ) bplevel=`expr $bplevel + 1`
                        bptype=p
                        ;;
                    r ) revision=`expr $revision + 1`
                        bplevel=0
                        ;;
                    v ) version=`expr $version + 1`
                        revision=0
                        bplevel=0
                        ;;
                esac
                date=calc
            fi
            FULLVERSION="$version.$revision$bptype$bplevel"
        else
            #   intialise to first version
            version=0
            revision=5
            bptype=b
            bplevel=0
            date=calc
        fi
    else
        #   take given version
        V=`echo $FULLVERSION | sed -e 's%\([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\).*%\1:\2:\3:\4%'`
        version=`echo $V | awk -F: '{ print $1 }'`
        revision=`echo $V | awk -F: '{ print $2 }'`
        bptype=`echo $V | awk -F: '{ print $3 }'`
        bplevel=`echo $V | awk -F: '{ print $4 }'`
        date=calc
    fi
    
    #   determine hex value of version
    case $FULLVERSION in
        *.*a* )
            HEX=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
                 echo "$FULLVERSION" | sed -e 's/.*a//' | awk '{ printf("0%02d", $1); }'`
            ;;
        *.*b* )
            HEX=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
                 echo "$FULLVERSION" | sed -e 's/.*b//' | awk '{ printf("1%02d", $1); }'`
            ;;
        *.*.* )
            HEX=`echo "$FULLVERSION" | awk -F. '{ printf("%d%02d2%02d", $1, $2, $3); }'`
            ;;
    esac
    
    #   determine libtool version
    case $FULLVERSION in
        *.*a* )
            LTV=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
            ;;
        *.*b* )
            LTV=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
            ;;
        *.*.* )
            LTV=`echo "$FULLVERSION" | awk -F. '{ printf("%d:%d", $1*10+$2, $3); }'`
            ;;
    esac
    
    #   determine string out of filename
    FILESTR=`echo "$FILE" | tr 'abcdefghijklmnopqrstuvwxyz./%+-' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_____'`
    
    #   determine date
    if [ ".$date" = .calc ]; then
        day="`date '+%d' | awk '{ printf("%s", $1); }'`"
        month="`date '+%m' | awk '{ printf("%s", $1); }'`"
        year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
        if test ".$time_year" = .; then
            year="`date '+%y' | awk '{ printf("%s", $1); }'`"
            case $year in
                9[0-9]*) year="19$year" ;;
                      *) year="20$year" ;;
            esac
        fi
        case $month in
            1|01) month='Jan' ;;
            2|02) month='Feb' ;;
            3|03) month='Mar' ;;
            4|04) month='Apr' ;;
            5|05) month='May' ;;
            6|06) month='Jun' ;;
            7|07) month='Jul' ;;
            8|08) month='Aug' ;;
            9|09) month='Sep' ;;
              10) month='Oct' ;;
              11) month='Nov' ;;
              12) month='Dec' ;;
        esac
        date="${day}-${month}-${year}"
    fi
    
    if [ .$REPORT != .NO ]; then
        case $REPORT in
            long )
                echo "$version.$revision$bptype$bplevel ($date)"
                ;;
            short )
                echo "$version.$revision$bptype$bplevel"
                ;;
            libtool )
                echo "$LTV"
                ;;
            hex )
                echo "0x$HEX"
                ;;
        esac
        exit 0
    fi
    
    #   create the version file according the the selected language  
    echo "new version: $version.$revision$bptype$bplevel ($date)"
    tmpfile="/tmp/version.tmp.$$"
    rm -f $tmpfile >/dev/null 2>&1
    case $LANGUAGE in
        txt )
            cat >$tmpfile <<'EOT'
    
  This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)
EOT
            ;;
        c )
            cat >$tmpfile <<'EOT'
/*
**  @FILE@ -- Version File (automatically generated and maintained by shtool)
*/

#ifdef AS_HEADER

#ifndef @FILESTR@
#define @FILESTR@
#define @PREFIX@_VERSION 0x@HEX@
extern const int  @PREFIX@_Version;
extern const char @PREFIX@_VersionStr[];
extern const char @PREFIX@_Hello[];
extern const char @PREFIX@_GNUVersion[];
extern const char @PREFIX@_WhatID[];
extern const char @PREFIX@_RCSIdentID[];
extern const char @PREFIX@_WebID[];
extern const char @PREFIX@_PlainID[];
#endif

#else

const int  @PREFIX@_Version      = 0x@HEX@;
const char @PREFIX@_VersionStr[] = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_Hello[]      = "This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_GNUVersion[] = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
const char @PREFIX@_WhatID[]     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_RCSIdentID[] = "$Id: @NAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ $";
const char @PREFIX@_WebID[]      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
const char @PREFIX@_PlainID[]    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";

#endif
EOT
            ;;
        perl )
            cat >$tmpfile <<'EOT'
##
##  @FILE@ -- Version File (automatically generated and maintained by shtool)
##

$@PREFIX@_Version    = 0x@HEX@;
$@PREFIX@_VersionStr = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_Hello      = "This is @NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_GNUVersion = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
$@PREFIX@_WhatID     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_RCSIdentID = "\$Id: @NAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ \$";
$@PREFIX@_WebID      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
$@PREFIX@_PlainID    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";

1;
EOT
            ;;
    esac
    
    #   now create the version file
    rm -f $FILE >/dev/null 2>&1
    sed \
        -e "s|@FILE@|$FILE|g" \
        -e "s|@FILESTR@|$FILESTR|g" \
        -e "s|@PREFIX@|$PREFIX|g" \
        -e "s|@NAME@|$NAME|g" \
        -e "s|@HEX@|$HEX|g" \
        -e "s|@VERSION@|$version|g" \
        -e "s|@REVISION@|$revision|g" \
        -e "s|@BPTYPE@|$bptype|g" \
        -e "s|@BPLEVEL@|$bplevel|g" \
        -e "s|@YEAR@|$year|g" \
        -e "s|@MONTH@|$month|g" \
        -e "s|@DAY@|$day|g" <$tmpfile >$FILE
    rm -f $tmpfile >/dev/null 2>&1
    exit 0
;;

path )
    #
    #   parse argument line
    #
    silent=no
    reverse=no
    magic=no
    dirname=no
    basename=no
    pathlist="$PATH"
    namelist=""
    tmpfile="/tmp/path.tmp.$$"
    while [ ".$1" != . ]; do
        case $1 in
            -s ) silent=yes   ; shift; continue ;;
            -r ) reverse=yes  ; shift; continue ;;
            -d ) dirname=yes  ; shift; continue ;;
            -b ) basename=yes ; shift; continue ;;
            -m ) magic=yes    ; shift; continue ;;
            -p ) pathlist="$2"; shift; shift; continue ;;
            *  ) break ;;
        esac
    done
    if [ $# -eq 0 ]; then
        echo "$0:Usage: path [-s] [-r] [-d] [-b] [-p <path>] <string> [<string> ...]" 1>&2
        exit 1
    fi
    namelist="$*"
    
    #
    #   check whether the test command supports the -x option
    #
    cat >$tmpfile <<EOT
if [ -x / ] || [ -x /bin ] || [ -x /bin/ls ]; then
    exit 0
fi
exit 1
EOT
    if sh $tmpfile 2>/dev/null; then
        minusx="-x"
    else
        minusx="-r"
    fi
    rm -f $tmpfile
    
    #
    #   split path string
    #
    paths="`echo $pathlist |\
            sed -e 's/^:/.:/' \
                -e 's/::/:.:/g' \
                -e 's/:$/:./' \
                -e 's/:/ /g'`"
    
    #
    #   SPECIAL REQUEST
    #   translate forward to reverse path
    #
    if [ $reverse = yes ]; then
        if [ "x$namelist" = "x." ]; then
            rp='.'
        else
            rp=''
            for pe in `IFS="$IFS/"; echo $namelist`; do
                rp="../$rp"
            done
        fi
        echo $rp | sed -e 's:/$::'
        exit 0
    fi
    
    #
    #   SPECIAL REQUEST
    #   strip out directory or base name
    #
    if [ $dirname = yes ]; then
        echo "$namelist" |\
        sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
        exit 0
    fi
    if [ $basename = yes ]; then
        echo "$namelist" |\
        sed -e 's;.*/\([^/]*\)$;\1;'
        exit 0
    fi
    
    #
    #   MAGIC SITUATION
    #   Perl Interpreter (perl)
    #
    if [ ".$magic" = .yes ] && [ ".$namelist" = .perl ]; then
        rm -f $tmpfile
        touch $tmpfile
        c=0
        found=0
        for dir in $paths; do
            dir=`echo $dir | sed -e 's;/*$;;'`
            for perl in perl5 perl miniperl; do
                 if [ $minusx "$dir/$perl" ]; then
                     perl="$dir/$perl"
                     version=`$perl -v | grep version |\
                              sed -e 's/.* version //' -e 's/ built.*//' -e 's/ with.*//'`
                     versionnum="`echo $version | sed -e 's/\.//g' -e 's/_//g'`"
                     versionnum=`expr $versionnum - $c`
                     echo "$versionnum $perl" >>$tmpfile
                     found=1
                 fi
            done
            c=`expr $c + 1`
        done
        if [ $found = 1 ]; then
            perl="`cat $tmpfile | sort -u | tail -1 | cut '-d ' -f2`"
            rm -f $tmpfile
            echo "$perl"
            exit 0
        fi
        exit 1
    fi
    
    #
    #   MAGIC SITUATION
    #   C pre-processor (cpp)
    #
    if [ ".$magic" = .yes ] && [ ".$namelist" = .cpp ]; then
        cat >$tmpfile.c <<EOT
#include <assert.h>
    Syntax Error
EOT
        #   1. try the standard cc -E approach
        cpp="${CC-cc} -E"
        (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
        my_error=`grep -v '^ *+' $tmpfile.out`
        if [ ".$my_error" != . ]; then
            #   2. try the cc -E approach and GCC's -traditional-ccp option
            cpp="${CC-cc} -E -traditional-cpp"
            (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
            my_error=`grep -v '^ *+' $tmpfile.out`
            if [ ".$my_error" != . ]; then
                #   3. try a standalone cpp command in path and lib dirs
                for path in $paths /lib /usr/lib /usr/local/lib; do
                    path=`echo $path | sed -e 's;/*$;;'`
                    if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
                        cpp="$path/cpp"
                        break
                    fi
                done
                if [ ".$cpp" != . ]; then
                    (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
                    my_error=`grep -v '^ *+' $tmpfile.out`
                    if [ ".$my_error" != . ]; then
                        #   ok, we gave up...
                        cpp=''
                    fi
                fi
            fi
        fi
        rm -f $tmpfile.c $tmpfile.out
        if [ ".$cpp" != . ]; then
            echo "$cpp"
            exit 0
        fi
        exit 1
    fi
    
    #
    #   STANDARD SITUATION
    #   iterate over names
    #
    for name in $namelist; do
        #   iterate over paths
        for path in $paths; do
            path=`echo $path | sed -e 's;/*$;;'`
            if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
                if [ "$silent" != "yes" ]; then
                    echo "$path/$name"
                fi
                exit 0
            fi
        done
    done
    exit 1
;;

* )
    echo "$0:Error: Unknown command" 2>&1
    echo "$0:Hint:  Run 'shtool.gen -h' for usage" 2>&1
    exit 1
    ;;
esac

##EOF##