/usr/bin/gtml is in gtml 3.5.4-11.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/perl
#
# Program: gtml
#
# Version: 3.5.4 (See NEWS file for revision history)
#
# Description: gtml is a program to manage groups of HTML files with
# similar properties.
#
# Authors: versions 1.0 to 2.3
# Gihan Perera <gihan@pobox.com>, First Step Communications
# versions 3.0 to 3.5.3
# Bruno Beaufils <beaufils@lifl.fr>
# version 3.5.4
# Andrew E. Schulman <schulman@users.sourceforge.net>
# (see CREDITS file for complete list of contributors)
#
# Documentation and updates for this program are available at:
#
# http://sourceforge.net/projects/gtml
#
# Copying and Distribution:
#
# Copyright (C) 1996-1999 Gihan Perera
# Copyright (C) 1999 Bruno Beaufils
# Copyright (C) 2004 Andrew E. Schulman
#
# 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 2 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, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------------
#
# Here comes lists of global variables with their utility.
#
# Firstly comes variables which may not be changed by gtml or its user:
#
# @configurationFiles gtml default configuration file list
# @extProject project file suffix list
# @extSource gtml source file suffix list
#
# Then comes variables which may be modified by gtml user:
#
# $argsep argument separator
# $beSilent to produce processing info output or not
# $compression to produce compressed output or not
# $debug print debug informations when developping or not
# $delim1 opening macro delimiter
# $delim2 closing macro delimiter
# $entities to convert HTML entities or not
# $extTarget output file suffix
# $generateMakefiles generate Makefiles or process files (MAKE_GEN)
# $literal to not interpret GTML command or to do
# $makefileName name of the makefile to generate (MAKE_GEN)
# $mstamp string containing format of file timestamp
# $outputDir directory where files will be created
# $stamp string containing format of basic timestamp
# %characters hash table of characters and their translation
# %defines hash table of macro and their definitions
# %fileAliases hash table of file alias and their real names
# @fileToProcess table of files to process within project file
# @pfile list of file names of the pages structure
# @plevel list of file level of the pages structure
# @ptitle list of file title of the pages structure
#
# Finally comes variables which may be modified only by gtml itself:
#
# $current index in @supress of the current ignoring state
# $exitStatus gtml exit status
# $filenum file handler of read file, must be >= 5
# $ifLevel depth of current if-command
# $hierarchyRead has a hierarchy command been read
# $nbError number of processing errors
# %dependencies hash table of dependencies for each file (MAKE_GEN)
# @extensions list of all output extensions used (MAKE_GEN)
# @lines list of ouput lines stored when compressing is asked
# @outputFiles list of all generated files (MAKE_GEN)
# @suppress list of line-ignoring state coming from if/ifdef
# @wasTrue list of whether we've seen a true condition yet in
# an if...elsif... sequence
# @wasElse list of whether we've seen an 'else' yet
# ----------------------------------------------------------------------------
# ============================================================================
@extProject = (".gtp");
@extSource = (".gtm", ".gtml");
$extTarget = ".html";
@configurationFiles = (".gtmlrc", "gtml.conf");
@extensions = ($extTarget);
$delim1 = "<<";
$delim2 = ">>";
$argsep = ',';
$entities = 0;
$literal = 0;
$beSilent = 0;
$compression = 0;
$generateMakefiles = 0;
$makefileName = "GNUmakefile";
@suppress = (0);
$current = 0;
$ifLevel = 0;
$exitStatus = 0;
$initialFilenum = 5;
$filenum = $initialFilenum;
$nbError = 0;
$debug = 0;
# ----------------------------------------------------------------------------
# Process the command line for informative opions.
foreach $i ( @ARGV )
{
#
# Show help message.
#
if ( $i =~ /^-h/ || $i =~ /^--help/ )
{
&ShowHelp();
exit(0);
}
#
# Show version
#
elsif ( $i =~ /^--version/ )
{
&ShowVersion();
exit(0);
}
#
# Do not output informations during process time.
#
elsif ( $i =~ /^--silent/ )
{
$i =~ s/^--silent//;
$beSilent = 1;
}
}
# ----------------------------------------------------------------------------
# Add all environment variables as defined macros.
foreach $key ( keys %ENV )
{
&Define($key, $ENV{$key});
}
# ----------------------------------------------------------------------------
# Parse default configuration project file if present.
foreach $i ( @configurationFiles )
{
my $confFile = $ENV{"HOME"} . "/" . $i;
&ProcessProjectFile($confFile) if ( -r $confFile );
}
foreach $i ( @configurationFiles )
{
&ProcessProjectFile($i) if ( -r $i );
}
# ----------------------------------------------------------------------------
# Process the command line.
foreach $i ( @ARGV )
{
#
# Define a macro.
#
if ( $i =~ /^-D/ )
{
$i =~ s/^-D//;
($key, $value) = split(/=/, $i, 2);
&Define($key, $value);
}
#
# Generate a makefile.
#
elsif ( $i =~ /^-M/ )
{
if ( $i =~ /^-M([^- \t]+)/ )
{
$makefileName = $1;
}
$generateMakefiles = 1;
}
#
# Specify which file to process in the next project file.
#
elsif ( $i =~ /^-F/ )
{
$i =~ s/^-F//;
push(@fileToProcess, $i);
}
#
# Process files.
#
else
{
if ( &isProjectFile($i) )
{
&ProcessProjectFile($i, 1);
}
elsif ( &isSourceFile($i) )
{
&ProcessSourceFile($i, "");
}
else
{
&Warning("Skipping `$i' (unknown file type)");
}
}
}
if ($generateMakefiles)
{
&GenerateMakefile();
}
&Notice("\n$nbError errors occured during process.\n") if ( $nbError != 0);
exit($exitStatus);
# ============================================================================
# ----------------------------------------------------------------------------
# Add a macro in the definition list.
sub Define
{
local ($key, $value) = @_;
#
# Special macros.
#
if ( $key eq "__PERL__"
|| $key eq "__SYSTEM__"
|| $key eq "__NEWLINE__"
|| $key eq "__TAB__")
{
&Warning("system macros unmodifiable `$key'");
return
}
@includePath = split(/:/, $value) if ( $key eq "INCLUDE_PATH" );
$outputDir = $value if ( $key eq "OUTPUT_DIR" );
$delim1 = $value if ( $key eq "OPEN_DELIMITER" );
$delim2 = $value if ( $key eq "CLOSE_DELIMITER" );
$argsep = $value if ( $key eq "ARGUMENT_SEPARATOR" );
$extTarget = $value if ( $key eq "EXTENSION" );
push(@extensions, $value) if ( $key eq "EXTENSION" );
$debug = 1 if ( $key eq "DEBUG" );
&SetTimestamps() if ( $key eq "LANGUAGE" );
$value = "(((BLANK)))" if ( $value eq "");
$defines{"$key"} = $value;
}
# ----------------------------------------------------------------------------
# Add a file alias in the hash table of filename aliases.
sub DefineFilename
{
local ($key, $value) = @_;
if ( $value =~ /^\// )
{
&Error("no absolute file references allowed: $value");
return;
}
$fileAliases{"$key"} = $value;
&Define($key, $value);
}
# ----------------------------------------------------------------------------
# Define the value of each filename aliases as macros.
sub SetFileReferences
{
foreach $key ( keys(%fileAliases) )
{
if ( &GetValue("ROOT_PATH") eq "(((BLANK)))" )
{
$value = $fileAliases{$key};
}
else
{
$value = &GetValue("ROOT_PATH") . $fileAliases{$key};
}
$value = &ChangeExtension($value);
&Define($key, $value);
}
}
# ----------------------------------------------------------------------------
# Get the value of a specified macro.
sub GetValue
{
local ($key) = @_;
return $defines{"$key"};
}
# ----------------------------------------------------------------------------
# Remove a specified macro from the list of macros.
sub Undefine
{
local ($key) = @_;
delete($defines{ $key });
delete($characters{$key});
}
# ----------------------------------------------------------------------------
# Mark up a given definition in order to outline argument of a definition.
sub Markup
{
local ($key, $value) = @_;
my (@args, $arg, $pos, $len);
local ($start, $oldvalue);
if ( $key =~ /(.+)\((.+)\)/ )
{
#
# Tag has parens: MACRO(x,y) ....x....y....
#
$key = $1;
$arg = $2;
@args = split($argsep, $arg);
$start = 0;
#
# Verify if key is not yet defined, if yes find last argument.
#
$oldvalue = &GetValue($key);
if ( ! $oldvalue eq "" )
{
my $s = substr($oldvalue, rindex($oldvalue, "(((MARKER"));
if ( $s =~ /^\(\(\(MARKER([0-9])+\)\)\).*$/ )
{
$start = $1 + 1;
}
}
#
# Markup argument
#
for ($i = 0; $i <= $#args; $i++)
{
$pos = index($value, $args[$i]);
$len = length($args[$i]);
while ($pos >= 0 && $len > 0)
{
$j = $i + $start;
substr($value, $pos, $len) = "(((MARKER$j)))";
$pos = index($value, $args[$i]);
$len = length($args[$i]);
}
}
}
return ($key, $value);
}
# ----------------------------------------------------------------------------
# Substitute all macros in the current line.
sub Substitute
{
local (@args) = ();
local ($key, $value, $arg);
local ($ii);
#
# HTML entities may be converted.
#
if ($entities == 1)
{
#
# The default case: substitute '<', '&', and '>'.
#
s/&/&/g;
s/</</g;
s/>/>/g;
}
#
# User-defined characters has to be converted.
#
foreach $car ( keys %characters )
{
$ii = index($_, $car);
while ( $ii != ($[-1) )
{
substr($_, $ii, length($car)) = $characters{$car};
$ii = index($_, $car);
}
}
#
# Macros has to be replaced by their values.
# __NEWLINE__ and __TAB__ are substitute after all others.
#
$special = $delim1."__NEWLINE__".$delim2;
$ii = index($_, $special);
while ( $ii != ($[-1) )
{
substr($_, $ii, length($special)) = "__NEWLINE__";
$ii = index($_, $special);
}
$special = $delim1."__TAB__".$delim2;
$ii = index($_, $special);
while ( $ii != ($[-1) )
{
substr($_, $ii, length($special)) = "__TAB__";
$ii = index($_, $special);
}
$l1 = length($delim1);
$l2 = length($delim2);
my $more = 1;
while ($more)
{
$p2 = index($_, $delim2);
$p1 = rindex($_, $delim1, $p2);
if ( $p2 >= $l1 )
{
$key = substr($_, $p1+$l1, $p2-$p1-$l2);
if ( $key =~ /^[^ \t]+[ \t]*\(.*\)$/ )
{
#
# Tag contains a keyword and arguments.
#
($key, $arg) = split(/\(/, $key, 2);
$arg =~ s/\)$//g;
@args = &SplitArgs($arg);
}
if ( $key eq "__PERL__" )
{
$value = eval($args[0]);
}
elsif ( $key eq "__SYSTEM__" )
{
$value = qx{$args[0]};
}
else
{
$value = $defines{$key};
for ($i = 0; $i <= $#args; $i++)
{
#
# Argument substitution.
#
$marker = "(((MARKER$i)))";
$q = index($value, $marker);
while ($q >= 0)
{
#
# Substitution template contains a replacement marker.
#
$l = length($marker);
substr($value, $q, $l) = $args[$i];
$q = index($value, $marker);
}
}
}
#
# Make some verifications.
#
if ( $value eq ""
&& ! ($key eq "__PERL__" || $key eq "__SYSTEM__") )
{
&Warning("undefined name `$key'");
}
if ( $value =~ /\(\(\(MARKER([0-9])+\)\)\)/ )
{
&Error("missing argument $1");
}
#
# Straightforward substitution.
#
$value = "" if ( $value eq "(((BLANK)))" );
substr($_, $p1, $p2-$p1+$l2) = $value;
}
else
{
$value = "" if ( $value eq "(((BLANK)))" );
$more = 0;
}
}
s/__NEWLINE__/\n/g;
s/__TAB__/\t/g;
}
# ----------------------------------------------------------------------------
# Split a string containing arguments into an array of argument and returns
# this array. Take care of quoted arguments, in order to allow the use of
# argument separator in argument.
sub SplitArgs
{
local ($in) = @_;
local (@temp) = split($argsep, $in);
local (@args) = ();
local ($_);
while ($#temp >= 0)
{
$_ = shift(@temp);
if (/^"/) #"
{
#
# Start of "quoted arg" detected, look for end, and add argument.
#
while ( ! /(^"[^"]*")/ ) #"
{
$_ .= $argsep . shift(@temp);
}
s/^"([^"]*)"/$1/; #"
push(@args, $_);
}
elsif (/^'/) #'
{
#
# Start of 'quoted arg' detected, look for end, and add argument.
#
while (! /(^'[^']*')/) #'
{
$_ .= $argsep . shift(@temp);
}
s/^'([^']*)'/$1/; #'
push(@args, $_);
}
else
{
push(@args, $_);
}
}
return @args;
}
# ----------------------------------------------------------------------------
# Return 1 if given filename may be a project file, 0 else.
sub isProjectFile
{
local ($filename) = @_;
foreach $ext ( @extProject )
{
return 1 if ( $filename =~ /$ext$/i );
}
return 0;
}
# ----------------------------------------------------------------------------
# Return 1 if given filename may be a source file, 0 else.
sub isSourceFile
{
local ($filename) = @_;
foreach $ext ( @extSource )
{
return 1 if ( $filename =~ /$ext$/i );
}
return 0;
}
# ----------------------------------------------------------------------------
# Return the given source filename with extension changed according to
# $extTartget.
sub ChangeExtension
{
local ($file) = @_;
foreach $ext (@extSource)
{
$file =~ s/\.$ext$// if ( $file =~ /\.$ext/ );
$file =~ s/$ext$/$extTarget/ if ( $file =~ /$ext$/i );
}
return $file;
}
# ----------------------------------------------------------------------------
# Get the pathname of a given file.
# Always ends with a `/' if non-null.
sub GetPathname
{
local ($name) = @_;
$name =~ s/\\/\//g; # "\" -> "/"
$n = rindex($name, "/");
if ( $n > $[-1 )
{
$name = substr($name, 0, $n+1);
}
else
{
$name = ""; # DEBUG ./
}
return $name;
}
# ----------------------------------------------------------------------------
# Get the basename of a given output file.
sub GetOutputBasename
{
local ($name) = @_;
$name =~ s/\\/\//g; # "\" -> "/"
$n = rindex($name, "/");
$baseName = substr($name, $n+1);
$baseName =~ s/$extTarget$//;
return $baseName;
}
# ----------------------------------------------------------------------------
# Returns a list of all source files under the `.' directory.
sub AllSourceFiles
{
my @files = ();
my @dirs = (".");
my $dir = pop(@dirs);
while ( $dir )
{
opendir(DIR, $dir) || die("Can't open $dir");
if ( $dir eq "." )
{
$dir = "";
}
else
{
$dir .= "/";
}
my $file;
foreach $file ( grep(!/\.$/, readdir(DIR)) ) # from <niemans@acm.org>
{
if ( &isSourceFile($file) == 1 )
{
push(@files, "$dir$file");
}
elsif ( -d "$dir$file" )
{
push(@dirs, "$dir$file");
}
}
$dir = pop(@dirs);
}
return @files;
}
# ----------------------------------------------------------------------------
# Get the path to the root directory of the project from a given a file name.
# Always end with a `/' if non-null.
sub GetPathToRoot
{
local ($name) = @_;
local ($basename) = $name;
$basename =~ s/\\/\//g; # "\" -> "/"
$n = rindex($basename, "/");
$basename = substr($basename, $n+1) if ( $n != $[-1 );
local ($pathToRoot) = $name;
$pathToRoot =~ s/$basename//g;
$pathToRoot =~ s/[^\/\.]+\//\.\.\//g;
# DEBUG ./ $pathToRoot = "./" if ( $pathToRoot eq "" );
return $pathToRoot;
}
# ----------------------------------------------------------------------------
# Returns the complete name of a file which may be stored anywhere in the
# @includePath.
sub ResolveIncludeFile
{
local ($name) = @_;
$file = &GetValue("PATHNAME") . $name;
$file =~ s/\/\//\//g;
$file = $name if ( &GetValue("PATHNAME") eq "(((BLANK)))" );
if ( -r $file )
{
return $file;
}
elsif ( -r $name )
{
return $name;
}
local ($_) = @includePath;
Substitute;
foreach $dir ($_)
{
$file = $dir . "/" . $name;
$file =~ s/\/\//\//g;
return $file if ( -r $file );
}
&Error("no include file `$name' in `" . &GetValue("INCLUDE_PATH") . "'");
return "";
}
# ----------------------------------------------------------------------------
# Print the gtml version on the standard ouptut.
sub ShowHelp
{
print (
"Usage: gtml [OPTIONS...] file...
OPTIONS:
-M[:file] Do not produce ouput files but generate a makefile
ready to create them with gtml. If no <file> is
given the generated file will be called `GNUmakefile'.
-Dmacro[=definition] Define constant <macro> eventually defined
by <definition>.
-Ffile Do not process all files in the next project,
but <file>.
--silent Do not produce any output informations during file
processing.
-h, --help Show this help message.
--version Show gtml current version.
NOTES:
Before processing command line arguments, gtml try to process project files
`\${HOME}/.gtmlrc', `\${HOME}/gtml.conf', `./.gtmlrc' and `./gtml.conf' in
this order, allowing one to add/modify default behavior of gtml.
Exit status is 1 if errors have been encountered, and 0 if all was OK.
Report bugs at http://sourceforge.net/projects/gtml/.
");
}
# ----------------------------------------------------------------------------
# Print the gtml version on the standard ouptut.
sub ShowVersion
{
print (
"GTML version 3.5.4,
Copyright (C) 1996-1999 Gihan Perera
Copyright (C) 1999 Bruno Beaufils
Copyright (C) 2004 Andrew E. Schulman
GTML comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redristribute it
under the conditions defined in the GNU General Public License;
See the README or COPYING file for details.
"); #'
}
# ----------------------------------------------------------------------------
# Print a given message, as is, on the standard output if allowed.
sub Notice
{
local ($message) = @_;
print($message) if ( $beSilent == 0 );
}
# ----------------------------------------------------------------------------
# Print a debug information.
sub Debug
{
local ($message) = @_;
print("########### " . $message) if ( $debug == 1 );
}
# ----------------------------------------------------------------------------
# Notice a given warning.
sub Warning
{
local ($message) = @_;
&Notice(" !!! Warning: lines $.: $message.\n") if ( ! ($. eq "") );
&Notice(" !!! Warning: $message.\n") if ( ($. eq "") );
}
# ----------------------------------------------------------------------------
# Notice a given error.
sub Error
{
local ($message) = @_;
&Notice(" *** Error: line $.: $message.\n") if ( ! ($. eq "") );
&Notice(" *** Error: $message.\n") if ( $. eq "" );
$exitStatus |= 2;
$nbError += 1;
}
# ----------------------------------------------------------------------------
# Split a given time into the following global printable values:
#
# $sec Seconds, 00 - 59
# $min Minutes, 00 - 59
# $hour Hours, 00 - 23
# $wday Day of the week, Sunday - Saturday
# $shortwday First three letters of month name, Sun - Sat
# $mday Day of the month, 1 - 31
# $mdayth Day of the month with particuliar extension, 1st - 31th
# $mon Month number, 1 - 12
# $monthname Full month name, January - December
# $shortmon First three letters of month name, Jan - Dec
# $year Full year (e.g. 1996)
# $syear Last two digits of year (e.g. 96)
sub SplitTime
{
($sec, $min, $hour, $mday, $mon, $syear, $wday, $yday, $isdst) = @_;
#
# Month and Weekdays are defined differently in each language.
#
if ( &GetValue("LANGUAGE") eq "fr" )
{
@Month = ( "Janvier", "Février", "Mars",
"Avril", "Mai", "Juin",
"Juillet", "Août", "Septembre",
"Octobre", "Novembre", "Décembre" );
@WeekDay = ( "Dimanche", "Lundi", "Mardi",
"Mercredi", "Jeudi", "Vendredi", "Samedi" );
$mdayth = $mday;
$mdayth = "1er" if ($mday == 1);
}
# "no" thanks to Helmers, Jens Bloch <Jens.Bloch.Helmers@dnv.com>
elsif ( &GetValue("LANGUAGE") eq "no" )
{
@Month = ( "januar", "februar", "mars",
"april", "mai", "juni",
"juli", "august", "september",
"oktober", "november", "desember" );
@WeekDay = ( "Søndag", "Mandag", "Tirsdag",
"Onsdag", "Torsdag", "Fredag", "Lørdag" );
$mdayth = $mday . ".";
}
# "se" thanks to magog, <magog@swipnet.se>
elsif ( &GetValue("LANGUAGE") eq "se" )
{
@Month = ( "januari", "februari", "mars",
"april", "maj", "juni",
"juli", "augusti", "september",
"oktober", "november", "december" );
@WeekDay = ( "Söndag", "Måndag", "Tisdag","Onsdag",
"Torsdag", "Fredag", "Lördag" );
$mdayth = $mday; # XXX: Not verified
}
# "it" thanks to Pioppo, <pioppo@4net.it>
elsif ( &GetValue("LANGUAGE") eq "it" )
{
@Month = ( "Gennaio", "Febbraio", "Marzo",
"Aprile", "Maggio", "Giugno",
"Luglio", "Agosto", "Settembre",
"Ottobre", "Novembre", "Dicembre" );
@WeekDay = ( "Domenica", "Lunedì", "Martedì", "Mercoledì",
"Giovedì", "Venerdì", "Sabato" );
$mdayth = $mday;
}
# "nl" thanks to Gert-Jan Brink <gertjan@code4u.com>
elsif ( &GetValue("LANGUAGE") eq "nl" )
{
@Month = ( "januari", "februari", "maart",
"april", "mei", "juni",
"juli", "augustus", "september",
"oktober", "november", "december" );
@WeekDay = ( "zondag", "maandag", "dinsdag", "woensdag",
"donderdag", "vrijdag", "zaterdag" );
$mdayth = $mday;
}
# "de" thanks to Uwe Arzt <uwe.arzt@robots.de>
elsif ( &GetValue("LANGUAGE") eq "de" )
{
@Month = ( "Januar", "Februar", "März",
"April", "Mai", "Juni",
"Juli", "August", "September",
"Oktober", "November", "Dezember" );
@WeekDay = ( "Sonntag", "Montag", "Dienstag",
"Mittwoch", "Donnerstag", "Freitag", "Samstag" );
$mdayth = $mday;
}
# "ie" thanks to Ken Guest <kengu@credo.ie>
elsif ( &GetValue("LANGUAGE") eq "ie" )
{
@Month = ( "Enáir", "Feabhra", "Márta",
"Bealtaine", "Aibreán", "Meitheamh",
"Lúil", "Lúnasa", "Méan Fomhair",
"Deireadh Fomhair", "Samhain", "MÃ na Nollaig" );
@WeekDay = ( "Domhnach", "Luan", "Máirt",
"Céadaoin", "Déardaoin", "Aoine", "Satharn" );
$mdayth = $mday . ".";
}
# default is english.
else
{
@Month = ( "January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" );
@WeekDay = ( "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );
$mdayth = $mday . "th";
# from <agre3@ironbark.bendigo.latrobe.edu.au>
$mdayth = $mday . "st" if ($mday == 1 || $mday == 21 || $mday == 31);
$mdayth = $mday . "nd" if ($mday == 2 || $mday == 22);
$mdayth = $mday . "rd" if ($mday == 3 || $mday == 23);
}
$sec = sprintf("%02d", $sec);
$min = sprintf("%02d", $min);
$hour = sprintf("%02d", $hour);
$wday = $WeekDay[$wday]; # from <agre3@ironbark.bendigo.latrobe.edu.au>
$shortwday = substr($wday, 0, 3);
$monthname = $Month[$mon];
$shortmon = substr($monthname, 0, 3);
$year = $syear + 1900;
$syear = substr($year, -2, 2);
$mon++; # Because it starts from 0
}
# ----------------------------------------------------------------------------
# Returns a printable time/date string based on a given format string.
#
# The format string is passed in the variable $stamp, and the following
# substitutions are made in it:
#
# $ss -> seconds
# $mm -> minutes
# $hh -> hour
# $Ddd -> Short weekday name (Sun - Sat)
# $Day -> full weekday name
# $dd -> day of the month
# $ddth -> day of the month with th extension
# $MM -> month number (1 - 12)
# $Mmm -> short month name (Jan - Dec)
# $Month -> full month name
# $yyyy -> full year (e.g. 1996)
# $yy -> short year (e.g. 96)
#
# Make sure you call "SplitTime" first to initialise time global variables,
# i.e time to format.
sub FormatTimestamp
{
local ($stamp) = @_;
$stamp =~ s/\$ss/$sec/g;
$stamp =~ s/\$mm/$min/g;
$stamp =~ s/\$hh/$hour/g;
$stamp =~ s/\$Ddd/$shortwday/g;
$stamp =~ s/\$Day/$wday/g;
$stamp =~ s/\$ddth/$mdayth/g;
$stamp =~ s/\$dd/$mday/g;
$stamp =~ s/\$MM/$mon/g;
$stamp =~ s/\$Month/$monthname/g;
$stamp =~ s/\$Mmm/$shortmon/g;
$stamp =~ s/\$yyyy/$year/g;
$stamp =~ s/\$yy/$syear/g;
return $stamp;
}
# ----------------------------------------------------------------------------
# Defines eventual timestamps macros.
sub SetTimestamps
{
local($name) = @_;
if ( ! $stamp eq "" )
{
&SplitTime(localtime);
&Define("TIMESTAMP", &FormatTimestamp($stamp));
}
if ( ! $mstamp eq "" && ! $name eq "" )
{
&SplitTime(localtime((stat($name))[9]));
&Define("MTIMESTAMP", &FormatTimestamp($mstamp));
}
}
# ----------------------------------------------------------------------------
# Read a source line into a given file. Source lines may be written on
# multiple lines via `\' character at the end.
sub ReadLine
{
local ($file) = @_;
local ($line);
#
# Read a line from input file.
#
$_ = <$file>;
while ( /\\\n$/ )
{
#
# We are on multilines, so remove last `\'.
#
s/\\\n$//g;
#
# Read a new line from input file.
#
$_ .= <$file>;
}
return $_ ;
}
# ----------------------------------------------------------------------------
# What to do with a given project file. If second argument is 0 then source
# files will not be processed (i.e. means the routine is called for an
# included project file).
sub ProcessProjectFile
{
local ($name, $process) = @_;
local ($file);
local ($STREAM);
local ($hierarchyRead) = 0;
my @suppress = (0);
my @wasTrue = (0);
my @wasElse = (0);
my $current = 0;
my $ifLevel = 0;
if ( $process )
{
&Notice("=== Project file $name ===\n");
$STREAM = 3;
}
else
{
&Notice ("--- Included project file $name ---\n");
$STREAM = 4;
}
open($STREAM, $name);
while ( &ReadLine($STREAM) )
{
#
# Skip blank and comment lines.
#
next if ( /^\/\// );
next if ( /^[ \t]*$/ );
#
# Next process if(def)/elsif/else/endif to decide if we want to
# suppress any lines.
#
if ( /^if/ || /^elsif/ )
{
chop;
my ($wasIf, $match, $var, $condl, $comp, $value);
if ( /^if/ )
{
$ifLevel += 1;
$wasIf = 1;
}
else
{
s/^els//;
$wasIf = 0;
}
Substitute();
if ( /^ifdef/ || /^ifndef/ )
{
( $dummy, $var ) = split(/[ \t]+/, $_);
$match = ( &GetValue($var) ne "" );
$match = ! $match if ( /^ifndef/ );
}
else
{
( $condl, $var, $comp, $value ) = split(" ", $_, 4);
if ( $comp eq "==" )
{
$match = ( $var eq $value );
}
elsif ( $comp eq "!=" )
{
$match = ( $var ne $value );
}
else
{
Error("unknown comparator `$comp'");
$match = 0;
}
}
if ( $wasIf )
{
push(@suppress, ! $match);
push(@wasTrue, $match);
push(@wasElse, 0);
$current = $ifLevel if ( ! $suppress[$current] );
}
else
{
if ( $ifLevel == 0 )
{
$condl =~ s/^/els/;
Error("$condl with no preceding if");
}
elsif ( $wasTrue[$ifLevel] )
{
$suppress[$ifLevel] = 1;
}
else
{
$suppress[$ifLevel] = ! $match;
$wasTrue[$ifLevel] = $match;
}
}
next;
}
elsif ( /^else/ )
{
if ( $ifLevel == 0 )
{
Error("else with no preceding if");
}
elsif ( $wasElse[$ifLevel] )
{
Error("multiple 'else's");
}
else
{
$suppress[$ifLevel] = $wasTrue[$ifLevel];
$wasElse[$ifLevel] = 1;
}
next;
}
elsif ( /^endif/ )
{
if ( $ifLevel == 0 )
{
Error("unmatched endif");
}
else
{
pop(@suppress);
pop(@wasTrue);
pop(@wasElse);
$current -= 1 if ( $current == $ifLevel );
$ifLevel -= 1;
}
next;
}
#
# Skip lines if current ignoring state says so.
#
next if ( $suppress[$current] );
#
# Characters translation can be defined here.
#
if ( /^definechar[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
$characters{$key} = $value;
}
#
# Macros can be defined here.
#
elsif ( /^define[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( $key =~ /(.+)\((.+)\)/ )
{
&Undefine($1);
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^newdefine[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( ! &GetValue($key) eq "" )
{
next;
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^define\!/ )
{
chop;
&Substitute();
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( $key =~ /(.+)\((.+)\)/ )
{
&Undefine($1);
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^newdefine!/ )
{
chop;
&Substitute();
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( ! &GetValue($key) eq "" )
{
next;
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^define\+/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
( $key, $value ) = &Markup($key, $value);
&Define($key, &GetValue($key) . $value);
}
elsif ( /^undef[ \t]/ )
{
chop;
( $dummy, $key ) = split ( /[ \t]+/, $_);
&Undefine($key);
}
#
# Saving bandwidth file compression eliminates anything not necessary
# for correct display of content on the client browser.
#
elsif ( /^compress/ )
{
chop;
( $dummy, $switch ) = split(/[ \t]+/, $_);
if ( $switch =~ /^ON$/i )
{
$compression = 1;
}
elsif ( $switch =~ /^OFF$/i )
{
$compression = 0;
}
else
{
&Error("expecting compress as `ON' or `OFF'");
}
}
#
# Timestamp format can be defined here.
#
elsif ( /^timestamp[ \t]/ )
{
chop;
( $dummy, $stamp ) = split(/[ \t]/, $_, 2);
}
elsif ( /^mtimestamp[ \t]/ )
{
chop;
( $dummy, $mstamp ) = split(/[ \t]/, $_, 2);
}
#
# Filenames aliases can be defined here.
#
elsif ( /^filename[ \t]/ )
{
chop;
&Substitute();
( $dummy, $key, $value ) = split(/[ \t]+/, $_, 3);
&DefineFilename($key, $value);
}
#
# Included files.
#
elsif ( /^include[ \t]/ )
{
chop;
&Substitute();
s/^include[ \t]*"//;
s/".*$//; #"
$file = $_;
$file = &ResolveIncludeFile($file);
$dependencies{$name} .= "$file ";
&ProcessProjectFile($file, 0);
}
#
# They can ask for all source files here.
#
elsif ( /^allsource/ )
{
foreach $file ( &AllSourceFiles() )
{
&ProcessSourceFile($file, $name);
}
}
#
# They can ask for hierarchy files process.
#
elsif ( /^hierarchy/ )
{
for ( $ii = 0; $ii <= $#pfile; $ii += 1)
{
&SetLinks();
&ProcessSourceFile($pfile[$ii], $name, " ($plevel[$ii])");
}
$hierarchyRead = 1;
}
#
# Everything else must be a source file name.
#
else
{
chop;
&Substitute();
s/\s+/ /g;
( $file, $level, $title ) = split(/\s/, $_, 3);
$file = $fileAliases{$file} if ( defined($fileAliases{$file}) );
if ( $file =~ /^\// )
{
&Error("no absolute file references allowed: $file");
next;
}
if ( &isSourceFile($file) )
{
if ( $level eq "" )
{
&ProcessSourceFile($file, $name);
}
else
{
$lkey = "__TOC_" . $level . "__";
if ( ! defined($defines{$lkey}) )
{
&Define($lkey, "<ul>(((MARKER0)))</ul>");
}
$lkey = "__TOC_" . $level . "_ITEM__";
if ( ! defined($defines{$lkey}) )
{
&Define($lkey, "<li><a href=\"(((MARKER0)))\">(((MARKER1)))</a>");
}
push(@pfile, $file);
push(@plevel, $level);
push(@ptitle, $title);
}
}
else
{
&Warning("Skipping `$_' (unknown file type)");
}
}
}
#
# Process files with links to others.
#
if ( ! $hierarchyRead )
{
for ( $ii = 0; $ii <= $#pfile; $ii += 1)
{
&SetLinks();
&ProcessSourceFile($pfile[$ii], $name, " ($plevel[$ii])");
}
}
#
# Clean up a bit.
#
if ($process)
{
undef(@fileToProcess);
undef(@pfile);
undef(@plevel);
undef(@ptitle);
}
close $STREAM;
}
# ----------------------------------------------------------------------------
# Add macros used for link to other pages for files with links to others.
sub SetLinks
{
#
# Be sure that there is nothing defined.
#
&Undefine("TITLE_CURRENT");
&Undefine("TITLE_UP");
&Undefine("TITLE_NEXT");
&Undefine("TITLE_PREV");
&Undefine("LINK_UP");
&Undefine("LINK_NEXT");
&Undefine("LINK_PREV");
#
# All links are relative to the root directory.
#
local ($pathToRoot) = &GetPathToRoot($pfile[$ii]);
&Define("TITLE_CURRENT", $ptitle[$ii]);
#
# Go up one level.
#
my $up_file;
$i = $ii - 1;
while ($i >= 0 && $plevel[$i] >= $plevel[$ii])
{
--$i;
}
if ($i >= 0 && $plevel[$i] < $plevel[$ii])
{
if ( $pfile[$i] =~ /^\// )
{
&Define("LINK_UP", &ChangeExtension("$pfile[$i]"));
}
else
{
&Define("LINK_UP", &ChangeExtension("$pathToRoot$pfile[$i]"));
}
&Define("TITLE_UP", $ptitle[$i]);
$up_file = $pfile[$i];
}
else
{
&Undefine("LINK_UP");
&Undefine("TITLE_UP");
}
#
# Previous document.
#
$i = $ii - 1;
if ($i >= 0 && $pfile[$i] && $pfile[$i] ne $up_file)
{
if ( $pfile[$i] =~ /^\// )
{
&Define("LINK_PREV", &ChangeExtension("$pfile[$i]"));
}
else
{
&Define("LINK_PREV", &ChangeExtension("$pathToRoot$pfile[$i]"));
}
&Define("TITLE_PREV", $ptitle[$i]);
}
else
{
&Undefine("LINK_PREV");
&Undefine("TITLE_PREV");
}
#
# Next document.
#
$i = $ii + 1;
if ($pfile[$i])
{
if ( $pfile[$i] =~ /^\// )
{
&Define("LINK_NEXT", &ChangeExtension("$pfile[$i]"));
}
else
{
&Define("LINK_NEXT", &ChangeExtension("$pathToRoot$pfile[$i]"));
}
&Define("TITLE_NEXT", $ptitle[$i]);
}
else
{
&Undefine("LINK_NEXT");
&Undefine("TITLE_NEXT");
}
}
# ----------------------------------------------------------------------------
# Generate a complete SiteMap using predefined macros __TOC_x__, and
# __TOC_x_ITEM__. Almost all ideas and code comes from <Uwe.Arzt@t-mobil.de>,
# and <marquet@lifl.fr>.
sub GenSiteMap
{
$levelold = 0;
$_ = "";
for ( $xx = 0; $xx <= $#pfile; ++$xx )
{
$f = $pfile[$xx];
$f = &ChangeExtension($f);
if($levelold < $plevel[$xx])
{
$_ .= (" " x (($plevel[$xx]-1) * 2))
. $delim1."__TOC_".$plevel[$xx]."__(\'"
. $delim1."__NEWLINE__".$delim2;
$_ .= (" " x (($plevel[$xx]-1) * 2 + 2))
. $delim1."__TOC_".$plevel[$xx]
. "_ITEM__(\'".$f."\'".$argsep."\'".$ptitle[$xx]."\')"
. $delim2.$delim1."__NEWLINE__".$delim2;
}
if($levelold == $plevel[$xx])
{
$_ .= (" " x (($plevel[$xx]-1) * 2 + 2))
. $delim1."__TOC_".$plevel[$xx]
. "_ITEM__(\'".$f."\'".$argsep."\'".$ptitle[$xx]."\')"
. $delim2.$delim1."__NEWLINE__".$delim2;
}
if ($levelold > $plevel[$xx])
{
$_ .= (" " x ($plevel[$xx] * 2))
. "\')".$delim2.$delim1."__NEWLINE__".$delim2;
$_ .= (" " x (($plevel[$xx]-1) * 2 + 2))
. $delim1."__TOC_".$plevel[$xx]
. "_ITEM__(\'".$f."\'".$argsep."\'".$ptitle[$xx]."\')"
. $delim2.$delim1."__NEWLINE__".$delim2;
}
$levelold = $plevel[$xx];
}
for($xx = $levelold; $xx > 0; --$xx)
{
$_ .= (" " x (($plevel[$xx]-2) * 2))
. "\')".$delim2.$delim1."__NEWLINE__".$delim2;
}
&Substitute();
}
# ----------------------------------------------------------------------------
# Returns the output name of a given source filename.
sub ResolveOutputName
{
local ($file) = @_;
$file = &ChangeExtension($file);
$file = "$outputDir/$file" if ( $outputDir ne "" && $file !~ /^\// );
#
# Make sure the directory exists for the output file.
#
$n = 0;
while ( $n != ($[-1) )
{
$n = index($file, "/", $n);
$n = 1 if ( $n == 0 );
if ( $n != ($[-1) )
{
$dir = substr($file, 0, $n);
mkdir($dir, 0755) if ( ! -d $dir ); # from <magog@swipnet.se>
++$n;
}
}
return $file;
}
# ----------------------------------------------------------------------------
# Return 1 if a given string is a member of a given list 0 else.
sub Member
{
local ($elt, @list) = @_;
foreach $val (@list)
{
return 1 if ( $val eq $elt );
}
return 0;
}
# ----------------------------------------------------------------------------
# What to do with a given source file. The level of the page in the document
# may be given.
sub ProcessSourceFile
{
local ($name, $parent, $level) = @_;
local ($oname);
@lines = ();
%saveDefines = %defines;
%saveCharacters = %characters;
#
# Process source files only if asked.
#
if (@fileToProcess && ! (&Member($name, @fileToProcess)) )
{
return;
}
&Notice("--- $name$level ---\n");
if ( ! -r $name )
{
&Error("`$name' unreadable");
}
else
{
$oname = &ResolveOutputName($name);
&Define("ROOT_PATH", &GetPathToRoot($name));
&Define("BASENAME", &GetOutputBasename($oname));
&Define("FILENAME", "$baseName$extTarget");
&Define("PATHNAME", &GetPathname($name));
if ( $name eq $oname )
{
&Error("source `$name' same as target `$oname'");
}
else
{
$dependencies{$oname} .= "$parent $name";
push(@outputFiles, $oname);
#
# if FAST_GENERATION process files only if newer than output.
#
if ( !defined($defines{"FAST_GENERATION"})
|| ((stat($name))[9] > (stat($oname))[9]))
{
&SetFileReferences();
&SetTimestamps($name);
open(OUTFILE, ">$oname") if (!$generateMakefiles);
&ProcessLines($name);
close OUTFILE if (!$generateMakefiles);
}
else
{
&Warning("output more recent than input, nothing done");
}
}
}
%defines = %saveDefines;
%characters = %saveCharacters;
}
# ----------------------------------------------------------------------------
# Compresses all lines, removing all thing not necessary for a browser.
sub CompressLines
{
local ($_) = join(' ', @lines);
@lines = ();
#
# Translate tabs and linefeed into spaces.
#
tr/\t\n/ /;
#
# Discard all comments.
#
$del1 = '<!--'; $len1 = length( $del1 );
$del2 = '-->'; $len2 = length( $del2 );
while (1)
{
$p1 = index($_, $del1);
$p2 = index($_, $del2);
if ( $p1 >= 0 && $p2 >= 0 && $p2 > $p1 )
{
substr($_, $p1, $p2-$p1+$len2) = '';
}
else
{
last;
}
}
#
# Squeeze all multiple spaces. Terminate the compressed sequence by \n
#
tr/ / /s;
if ( substr($_, length($_), 1) eq ' ' )
{
chop;
}
return $_ . "\n";
}
# ----------------------------------------------------------------------------
# Process lines of a source file.
sub ProcessLines
{
local ($iname) = @_;
local ($INFILE) = $filenum++;
my @suppress = (0);
my @wasTrue = (0);
my @wasElse = (0);
my $current = 0;
my $ifLevel = 0;
if ( ! -r $iname )
{
&Error("`$iname' unreadable");
return;
}
open($INFILE, $iname);
while ( &ReadLine($INFILE) )
{
#
# Allow GTML commands inside HTML comments.
#
if ( /<!-- ###/ )
{
s/<!-- ##//;
s/|-->.*$//;
s/\s*-->.*$//;
}
#
# Parse '#literal' command because if literal processing is ON,
# we simply print the line and continue to the next line.
#
if ( /^#literal/ )
{
chop;
( $dummy, $switch ) = split(/[ \t]+/, $_);
if ( $switch =~ /^ON$/i )
{
$literal = 1;
}
elsif ( $switch =~ /^OFF$/i )
{
$literal = 0;
}
else
{
&Error("expecting \#literal as `ON' or `OFF'");
}
next;
}
if ( $literal )
{
if ( $compression )
{
print(OUTFILE &CompressLines);
}
&Substitute();
print(OUTFILE $_);
next;
}
#
# Next parse the if(def)/elsif/else/endif to decide if we want to
# suppress any lines.
#
# $ifLevel = current level of nested ifs.
# $current = operative level of nested ifs. This is less than $ifLevel
# when an outer 'if' condition is false.
# @suppress = vector of suppression indicators at the different nesting levels.
# @wasTrue = vector of indicators for whether at least one condition in a sequence
# of if...elsif...elsif...else has already been true. In that case the rest of
# the conditions in the sequence are ignored.
# @wasElse = vector of indicators of whether an 'else' condition has already been
# seen.
#
if ( /^#if/ || /^#elsif/ )
{
chop;
my ($wasIf, $match, $var, $condl, $comp, $value);
if ( /^#if/ )
{
$ifLevel += 1;
$wasIf = 1;
}
else
{
s/^#els/#/;
$wasIf = 0;
}
Substitute();
if ( /^#ifdef/ || /^#ifndef/ )
{
( $dummy, $var ) = split(/[ \t]+/, $_);
$match = ( &GetValue($var) ne "" );
$match = ! $match if ( /^#ifndef/ );
}
else
{
( $condl, $var, $comp, $value ) = split(" ", $_, 4);
if ( $comp eq "==" )
{
$match = ( $var eq $value );
}
elsif ( $comp eq "!=" )
{
$match = ! ( $var eq $value );
}
else
{
Error("unknown comparator `$comp'");
$match = 0;
}
}
if ( $wasIf )
{
push(@suppress, ! $match);
push(@wasTrue, $match);
push(@wasElse, 0);
$current = $ifLevel if ( ! $suppress[$current] );
}
else
{
if ( $ifLevel == 0 )
{
$condl =~ s/^#/#els/;
Error("$condl with no preceding #if");
}
elsif ( $wasTrue[$ifLevel] )
{
$suppress[$ifLevel] = 1;
}
else
{
$suppress[$ifLevel] = ! $match;
$wasTrue[$ifLevel] = $match;
}
}
next;
}
elsif ( /^#else/ )
{
if ( $ifLevel == 0 )
{
Error("#else with no preceding #if");
}
elsif ( $wasElse[$ifLevel] )
{
Error("multiple '#else's");
}
else
{
$suppress[$ifLevel] = $wasTrue[$ifLevel];
$wasElse[$ifLevel] = 1;
}
next;
}
elsif ( /^#endif/ )
{
if ( $ifLevel == 0 )
{
Error("unmatched #endif");
}
else
{
pop(@suppress);
pop(@wasTrue);
pop(@wasElse);
$current-- if ( $current == $ifLevel );
$ifLevel--;
}
next;
}
#
# Skip lines if current ignoring state says so.
#
next if ( $suppress[$current] );
#
# Now do others commands.
#
if ( /^#entities/ )
{
chop;
( $dummy, $switch ) = split(/[ \t]+/, $_);
if ( $switch =~ /^ON$/i )
{
$entities = 1;
}
elsif ( $switch =~ /^OFF$/i )
{
$entities = 0;
}
else
{
&Error("expecting \#entities as `ON' or `OFF'");
}
next;
}
#
# Included files.
#
elsif ( /^#include/ )
{
local( $my_prev_literal_setting ) = $literal;
if( /^#includeliteral/ )
{
$literal = 1;
}
chop;
if ( $compression )
{
print(OUTFILE &CompressLines);
}
&Substitute();
s/^#include(literal)?[ \t]*"//;
s/".*$//; #"
$file = $_;
$file = &ResolveIncludeFile($file);
$dependencies{$iname} .= "$file ";
if ( $file ne "" )
{
# TODO # &Notice(" --- $file\n");
&ProcessLines($file);
}
$literal = $my_prev_literal_setting;
next;
}
#
# Characters translation can be defined here.
#
if ( /^#definechar[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
$characters{$key} = $value;
}
#
# Macros can be defined here.
#
elsif ( /^#define[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( $key =~ /(.+)\((.+)\)/ )
{
&Undefine($1);
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^#newdefine[ \t]/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( ! &GetValue($key) eq "" )
{
next;
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^#define\!/ )
{
chop;
&Substitute();
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( $key =~ /(.+)\((.+)\)/ )
{
&Undefine($1);
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^#newdefine!/ )
{
chop;
&Substitute();
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
if ( ! &GetValue($key) eq "" )
{
next;
}
( $key, $value ) = &Markup($key, $value);
&Define($key, $value);
}
elsif ( /^#define\+/ )
{
chop;
( $dummy, $key, $value ) = split( /[ \t]+/, $_, 3 );
( $key, $value ) = &Markup($key, $value);
&Define($key, &GetValue($key) . $value);
}
elsif ( /^#undef[ \t]/ )
{
chop;
( $dummy, $key ) = split ( /[ \t]+/, $_);
&Undefine($key);
}
#
# Saving bandwidth file compression eliminates anything not necessary
# for correct display of content on the client browser.
#
elsif ( /^#compress/ )
{
chop;
( $dummy, $switch ) = split(/[ \t]+/, $_);
if ( $switch =~ /^ON$/i )
{
$compression = 1;
}
elsif ( $switch =~ /^OFF$/i )
{
print(OUTFILE &CompressLines) if ( $compression );
$compression = 0;
}
else
{
&Error("expecting \#compress as `ON' or `OFF'");
}
}
#
# Table of contents can be used here.
#
elsif ( /^#toc/ || /^#sitemap/ )
{
&GenSiteMap();
if ( $compression )
{
push(@lines, $_);
}
else
{
print(OUTFILE $_);
}
}
#
# Timestamp format can be defined here.
#
elsif ( /^#timestamp[ \t]/ )
{
chop;
( $dummy, $stamp ) = split(/[ \t]/, $_, 2);
&SetTimestamps( $iname );
}
elsif ( /^#mtimestamp[ \t]/ )
{
chop;
( $dummy, $mstamp ) = split(/[ \t]/, $_, 2);
&SetTimestamps( $iname );
}
#
# Normal lines.
#
elsif ( ! /^#/ )
{
&Substitute();
if ( $compression )
{
push(@lines, $_);
}
else
{
print(OUTFILE $_);
}
}
}
if ( $compression )
{
print(OUTFILE &CompressLines);
}
close $INFILE;
$filenum--;
}
# ----------------------------------------------------------------------------
# Generate a makefile from dependencies.
sub GenerateMakefile
{
open(OUTFILE, ">$makefileName");
#
# makefile basics.
#
print(OUTFILE "# GTML generated makefile, usable with GNU make.\n");
print(OUTFILE "\n");
print(OUTFILE "GTML = gtml\n");
print(OUTFILE "RM = rm\n");
print(OUTFILE "\n");
print(OUTFILE ".SUFFIXES: "
. join(' ', @extProject)
. ' '
. join(' ', @extSource)
. ' '
. join(' ', @extensions));
print(OUTFILE "\n");
print(OUTFILE ".PHONY: clean\n");
print(OUTFILE "\n");
#
# Generated files list.
#
print(OUTFILE "##############\n");
print(OUTFILE "# Files list #\n");
print(OUTFILE "##############\n");
print(OUTFILE "\n");
print (OUTFILE "OUTPUT_FILES = \\\n");
for ($i = 0; $i < $#outputFiles; $i++)
{
print(OUTFILE "\t$outputFiles[$i] \\\n");
}
print(OUTFILE "\t$outputFiles[$#outputFiles]\n");
print(OUTFILE "\n");
#
# Rules.
#
print(OUTFILE "#####################\n");
print(OUTFILE "# Processsing rules #\n");
print(OUTFILE "#####################\n");
print(OUTFILE "\n");
print(OUTFILE "all: \$(OUTPUT_FILES)\n");
print(OUTFILE "\n");
print(OUTFILE "clean:\n");
print(OUTFILE "\t-\$(RM) \$(OUTPUT_FILES)\n");
print(OUTFILE "\t-\$(RM) *~\n");
print(OUTFILE "\n");
$outputDir .= "/" if ( ! ($outputDir eq "") );
$outputDir =~ s/\/\//\//g;
foreach $ext ( @extSource )
{
foreach $ext2 ( @extensions )
{
print(OUTFILE "$outputDir\%$ext2: \%$ext\n");
print(OUTFILE "\t\$(GTML) -F\$< \$(word 1, \$(word 2, \$^) \$<)\n");
print(OUTFILE "\n");
}
}
#
# Dependencies.
#
print(OUTFILE "#####################\n");
print(OUTFILE "# File dependencies #\n");
print(OUTFILE "#####################\n");
print(OUTFILE "\n");
foreach $file ( keys(%dependencies) )
{
$dependencies{$file} =~ s/^ //;
print(OUTFILE "$file: $dependencies{$file}\n");
if ( ! &Member($file, @outputFiles) )
{
print(OUTFILE "\ttouch \$\@\n");
}
elsif ( ! ($file =~ /$extTarget$/) )
{
print(OUTFILE "\t\$(GTML) -F\$(word 2, \$^) \$(word 1, \$^)\n");
}
}
print(OUTFILE "\n");
print(OUTFILE "# End of makefile.\n");
close(OUTFILE);
}
# ----------------------------------------------------------------------------
# Well you may ask why sometimes I add some stupid comments like #' or #", the
# answer is simple: I use emacs, and color syntaxing with font-lock-mode and
# when it does not find matching, i.e closing, " or ' it color the text as
# string until a closing one, which is really not pleasant. Giving it what it
# looks for is the simplest trick I found to correct that.
# -Bruno
# ----------------------------------------------------------------------------
|