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
|
/****h* ROBODoc/Generator
* FUNCTION
* This contains routines to generate the documentation from the
* headers collected from the source code. It contains
* functionality common for all document types (HTML, RTF etc).
* The specifics are handled in the modules for each of the several
* document types.
*
* The behaviour of many of the functions in this module are
* modified by the global output_mode.
*
* The general call sequence is as follows:
* RB_Generate_Documentation
* +> RB_Generate_SingleDoc
* +> RB_Generate_Part
* +> RB_Generate_Header
* +> RB_Generate_Item_Doc
* +> RB_Generate_Item_Line
* +> RB_Generate_Char
* BUGS
* o Confusing use of doctype and output mode.
* NOTES
* Might be a good idea to replace all the switch statements with
* function pointers.
* So instead of:
*
* switch (output_mode)
* {
* case HTML:
* RB_HTML_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* case DBSGML:
* RB_SGMLDocBook_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* case LATEX:
* RB_LaTeX_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* case RTF:
* RB_RTF_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* case ASCII:
* RB_ASCII_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* case TROFF:
* RB_TROFF_Generate_Doc_Start(dest_doc, src_name, name, toc);
* break;
* default:
* break;
* }
*
* we will have
*
* (*rb_generate_doc_start)(dest_doc, src_name, name, toc);
*
* were the function pointers are initialized at program start based
* on the output mode.
*******
* $Id: generator.c,v 1.57 2003/12/30 17:39:36 gumpu Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "globals.h"
#include "robodoc.h"
#include "headers.h"
#include "items.h"
#include "folds.h"
#include "util.h"
#include "links.h"
#include "generator.h"
#include "document.h"
#include "part.h"
#include "file.h"
#include "roboconfig.h"
/* Generators */
#include "html_generator.h"
#include "latex_generator.h"
#include "sgmldocbook_generator.h"
#include "xmldocbook_generator.h"
#include "rtf_generator.h"
#include "troff_generator.h"
#include "ascii_generator.h"
/* TODO This should not be here.... */
#include "analyser.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
/* Module functions */
static void RB_Generate_Item_Doc( FILE * dest_doc, char **lines,
int line_begin, int line_end,
int item_type, char *srcname,
char *docname, char *function_name,
char *extension, char *charset );
static void RB_Generate_Empty_Item( FILE * dest_doc );
static void RB_Generate_Item_Line( FILE * dest_doc, char *line,
int item_type, char *srcname,
char *docname,
char *function_name );
void RB_Generate_Char( FILE * dest_doc, int cur_char );
char *RB_Get_Index_FileName( char *docroot, char *extension );
static void RB_Generate_Index( struct RB_Document *document,
FILE * dest, char *dest_name );
static void RB_Generate_Header( FILE * f,
struct RB_Document *document,
struct RB_header *header,
char *srcname, char *docname );
void RB_Generate_TOC_2( FILE * dest_doc, T_RB_DocType doctype,
struct RB_header **headers, int count,
struct RB_Part *owner,
char *dest_name );
static char piping = FALSE;
/* TODO Documentation */
void
RB_Generate_False_Link( FILE * dest_doc, char *name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_False_Link( dest_doc, name );
break;
case HTML:
RB_HTML_Generate_False_Link( dest_doc, name );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
RB_LaTeX_Generate_False_Link( dest_doc, name );
break;
case RTF:
RB_RTF_Generate_False_Link( dest_doc, name );
break;
case ASCII:
RB_ASCII_Generate_False_Link( dest_doc, name );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/****f* Generator/RB_Generate_Item_Begin
* FUNCTION
* Generate the begin of an item. This should switch to some
* preformatted output mode, similar to HTML's <PRE>.
* SYNOPSIS
* void RB_Generate_Item_Begin( FILE* dest_doc )
* INPUTS
* dest_doc -- file to be written to
* output_mode -- global with the current output mode
* SOURCE
*/
void
RB_Generate_Item_Begin( FILE * dest_doc )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Item_Begin( dest_doc );
break;
case HTML:
RB_HTML_Generate_Item_Begin( dest_doc );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
RB_LaTeX_Generate_Item_Begin( dest_doc );
break;
case RTF:
RB_RTF_Generate_Item_Begin( dest_doc );
break;
case ASCII:
RB_ASCII_Generate_Item_Begin( dest_doc );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/******/
/****f* Generator/RB_Generate_Label
* FUNCTION
* Generate a label that can be used for a link.
* For instance in HTML this is <a name="label">
* SYNOPSIS
* void RB_Generate_Label( FILE* dest_doc, char* name )
* INPUTS
* dest_doc -- file to be written to
* name -- the label's name.
* output_mode -- global with the current output mode
* SOURCE
*/
void
RB_Generate_Label( FILE * dest_doc, char *name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Label( dest_doc, name );
break;
case HTML:
RB_HTML_Generate_Label( dest_doc, name );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
/* Doesn't apply */
break;
case RTF:
RB_RTF_Generate_Label( dest_doc, name );
break;
case ASCII:
/* Doesn't apply */
break;
case TROFF:
/* Doesn't apply */
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/******/
/****f* Generator/RB_Generate_Item_End
* FUNCTION
* Generate the end of an item. This should switch back from the
* preformatted mode. So in HTML it generates the </PRE> of a <PRE>
* </PRE> pair.
* INPUTS
* dest_doc -- file to be written to
* output_mode -- global with the current output mode
* SOURCE
*/
void
RB_Generate_Item_End( FILE * dest_doc )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Item_End( dest_doc );
break;
case HTML:
RB_HTML_Generate_Item_End( dest_doc );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
if ( piping == TRUE )
{
fprintf( dest_doc, "\\begin{verbatim}\n" );
piping = FALSE;
}
RB_LaTeX_Generate_Item_End( dest_doc );
break;
case RTF:
RB_RTF_Generate_Item_End( dest_doc );
break;
case ASCII:
RB_ASCII_Generate_Item_End( dest_doc );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/****/
/****f Generator/RB_Get_Len_Extension
* FUNCTION
* Compute the length of the filename extension for
* the current document type.
*****
*/
size_t
RB_Get_Len_Extension( char *extension )
{
size_t size = 0;
size = strlen( extension );
if ( *extension != '.' )
size++;
return size;
}
/****f* Generator/RB_Add_Extension
* FUNCTION
* Add an extension to the filename base based on on the current
* output mode.
* INPUTS
* doctype -- output mode
* name -- the name of the file without extension and with
* enough room left to add the extension.
* OUTPUT
* name -- the name of the file including the extension.
* SOURCE
*/
void
RB_Add_Extension( char *extension, char *name )
{
if ( *extension != '.' )
strcat( name, "." );
strcat( name, extension );
}
/******/
/*x**f Generator/RB_Default_Len_Extension
* FUNCTION
* Returns default extension for
* the current document type.
*****
*/
char *
RB_Get_Default_Extension( T_RB_DocType doctype )
{
char *extension = NULL;
switch ( doctype )
{
case XMLDOCBOOK:
extension = RB_XMLDB_Get_Default_Extension( );
break;
case HTML:
extension = RB_HTML_Get_Default_Extension( );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
extension = RB_LaTeX_Get_Default_Extension( );
break;
case RTF:
extension = RB_RTF_Get_Default_Extension( );
break;
case ASCII:
extension = RB_ASCII_Get_Default_Extension( );
break;
case TROFF:
extension = RB_TROFF_Get_Default_Extension( );
break;
case UNKNOWN:
default:
assert( 0 );
}
return extension;
}
/****f* Generator/RB_Generate_EndSection
* FUNCTION
* Generate a section of level depth in the current output mode.
* This is used for the --sections option. Where each header is
* placed in a section based on the header hierarchy.
* INPUTS
* dest_doc -- the destination file.
* doctype --
* depth -- the level of the section
* name -- the name of the section
* output_mode -- global with the current output mode.
* SOURCE
*/
void
RB_Generate_BeginSection( FILE * dest_doc, int depth, char *name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_BeginSection( dest_doc, depth, name );
break;
case HTML:
RB_HTML_Generate_BeginSection( dest_doc, depth, name );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
RB_LaTeX_Generate_BeginSection( dest_doc, depth, name );
break;
case RTF:
RB_RTF_Generate_BeginSection( dest_doc, depth, name );
break;
case ASCII:
assert( 0 );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/*******/
/****f* Generator/RB_Generate_EndSection
* FUNCTION
* Generate the end of a section base on the current output mode.
* The functions is used for the --section option.
* It closes a section in the current output mode.
* INPUTS
* dest_doc -- the destination file.
* doctype --
* depth -- the level of the section
* name -- the name of the section
* output_mode -- global with the current output mode.
* SOURCE
*/
void
RB_Generate_EndSection( FILE * dest_doc, int depth, char *name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_EndSection( dest_doc, depth, name );
break;
case HTML:
RB_HTML_Generate_EndSection( dest_doc, depth, name );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
RB_LaTeX_Generate_EndSection( dest_doc, depth, name );
break;
case RTF:
RB_RTF_Generate_EndSection( dest_doc, depth, name );
break;
case ASCII:
assert( 0 );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/******/
/****f* Generator/RB_Generate_Index_Entry
* FUNCTION
* Generate an entry for an auto generated index. This works only
* for output modes that support this, LaTeX for instance. This
* has nothting to do with the master index.
* INPUTS
* dest_doc -- the destination file.
* header -- pointer to the header the index entry is for.
* output_mode -- global with the current output mode.
* SOURCE
*/
void
RB_Generate_Index_Entry( FILE * dest_doc, T_RB_DocType doctype,
struct RB_header *header )
{
switch ( doctype )
{
case XMLDOCBOOK:
/* TODO */
break;
case HTML:
/* TODO */
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
RB_LaTeX_Generate_Index_Entry( dest_doc, header );
break;
case RTF:
/* TODO */
break;
case ASCII:
/* No index available */
break;
case TROFF:
/* No index available */
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/*******/
/****f* Generator/RB_Generate_TOC_2
* FUNCTION
* Create a Table of Contents based on the headers found in
* _all_ source files. There is also a function to create
* a table of contents based on the headers found in a single
* source file RB_Generate_TOC_1
* SYNOPSIS
* void RB_Generate_TOC_2( FILE* dest_doc, T_RB_DocType doctype,
* struct RB_header** headers, int count,
* struct RB_Part* owner,
* char* dest_name )
* INPUTS
* dest_doc -- the destination file.
* headers -- an array of pointers to all the headers.
* count -- the number of pointers in the array.
* output_mode -- global with the current output mode.
* owner -- The owner of the TOC. Only the headers that are owned
* by this owner are included in the TOC. Can be NULL,
* in which case all headers are included.
* SOURCE
*/
void
RB_Generate_TOC_2( FILE * dest_doc, T_RB_DocType doctype,
struct RB_header **headers, int count,
struct RB_Part *owner, char *dest_name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
break;
case HTML:
RB_HTML_Generate_TOC_2( dest_doc, headers, count, owner, dest_name );
break;
case DBSGML:
assert( 0 );
break;
case LATEX:
/* LaTeX has it's own mechanism for creating
* a table of content */
break;
case RTF:
RB_RTF_Generate_TOC_2( dest_doc, headers, count );
break;
case ASCII:
assert( 0 );
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/******/
/****f* Generator/RB_Generate_Doc_Start [3.0j]
* NAME
* RB_Generate_Doc_Start -- Generate document header.
* SYNOPSIS
* RB_Generate_Doc_Start (dest_doc, src_name, name, toc)
*
* RB_Generate_Doc_Start (FILE *, char *, char *, char)
* FUNCTION
* Generates for depending on the output_mode the text that
* will be at the start of a document.
* Including the table of contents.
* INPUTS
* dest_doc - pointer to the file to which the output will
* be written.
* src_name - the name of the source file or directory.
* name - the name of this file.
* output_mode - global variable that indicates the output
* mode.
* toc - generate table of contens
* SEE ALSO
* RB_Generate_Doc_End
* SOURCE
*/
void
RB_Generate_Doc_Start( FILE * dest_doc, char *src_name, char *title, char toc,
char *dest_name, char *charset )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case HTML:
RB_HTML_Generate_Doc_Start( dest_doc, src_name, title, toc, dest_name,
charset );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case LATEX:
RB_LaTeX_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case RTF:
RB_RTF_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case ASCII:
RB_ASCII_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case TROFF:
RB_TROFF_Generate_Doc_Start( dest_doc, src_name, title, toc );
break;
case UNKNOWN:
default:
;
}
}
/***************/
/****f* Generator/RB_Generate_Doc_End [3.0h]
* NAME
* RB_Generate_Doc_End -- generate document trailer.
* SYNOPSIS
* RB_Generate_Doc_End (dest_doc, name)
*
* RB_Generate_Doc_End (FILE *, char *)
* FUNCTION
* Generates for depending on the output_mode the text that
* will be at the end of a document.
* INPUTS
* dest_doc - pointer to the file to which the output will
* be written.
* name - the name of this file.
* output_mode - global variable that indicates the output
* mode.
* NOTES
* Doesn't do anything with its arguments, but that might
* change in the future.
* BUGS
* SOURCE
*/
void
RB_Generate_Doc_End( FILE * dest_doc, char *name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Doc_End( dest_doc, name );
break;
case HTML:
RB_HTML_Generate_Doc_End( dest_doc, name );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Doc_End( dest_doc, name );
break;
case LATEX:
RB_LaTeX_Generate_Doc_End( dest_doc, name );
break;
case RTF:
RB_RTF_Generate_Doc_End( dest_doc, name );
break;
case ASCII:
break;
case UNKNOWN:
case TROFF:
default:
assert( 0 );
}
}
/************/
/****f* Generator/RB_Generate_Header_Start [3.0h]
* NAME
* RB_Generate_Header_Start -- generate header start text.
* SYNOPSIS
* void RB_Generate_Header_Start (dest_doc, cur_header)
*
* void RB_Generate_Header_Start (FILE *, struct RB_header *)
* FUNCTION
* Generates depending on the output_mode the text that
* will be at the end of each header.
* INPUTS
* dest_doc - pointer to the file to which the output will
* be written.
* cur_header - pointer to a RB_header structure.
* SEE ALSO
* RB_Generate_Header_End
* SOURCE
*/
void
RB_Generate_Header_Start( FILE * dest_doc, struct RB_header *cur_header )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Header_Start( dest_doc, cur_header );
break;
case HTML:
RB_HTML_Generate_Header_Start( dest_doc, cur_header );
break;
case LATEX:
RB_LaTeX_Generate_Header_Start( dest_doc, cur_header );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Header_Start( dest_doc, cur_header );
break;
case RTF:
RB_RTF_Generate_Header_Start( dest_doc, cur_header );
break;
case ASCII:
RB_ASCII_Generate_Header_Start( dest_doc, cur_header );
break;
case TROFF:
RB_TROFF_Generate_Header_Start( dest_doc, cur_header );
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/******/
/****f* Generator/RB_Generate_Header_End [3.0h]
* NAME
* RB_Generate_Header_End
* SYNOPSIS
* void RB_Generate_Header_End (dest_doc, cur_header)
*
* void RB_Generate_Header_End (FILE *, struct RB_header *)
* FUNCTION
* Generates for depending on the output_mode the text that
* will be at the end of a header.
* This function is used if the option --section is _not_
* used.
* INPUTS
* dest_doc - pointer to the file to which the output will
* be written.
* cur_header - pointer to a RB_header structure.
* SEE ALSO
* RB_Generate_Header_Start, RB_Generate_EndSection,
* RB_Generate_BeginSection
* SOURCE
*/
void
RB_Generate_Header_End( FILE * dest_doc, struct RB_header *cur_header )
{
switch ( output_mode )
{ /* switch by *koessi */
case XMLDOCBOOK:
RB_XMLDB_Generate_Header_End( dest_doc, cur_header );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Header_End( dest_doc, cur_header );
break;
case HTML:
RB_HTML_Generate_Header_End( dest_doc, cur_header );
break;
case LATEX:
RB_LaTeX_Generate_Header_End( dest_doc, cur_header );
break;
case RTF:
RB_RTF_Generate_Header_End( dest_doc, cur_header );
break;
case ASCII:
RB_ASCII_Generate_Header_End( dest_doc, cur_header );
break;
case TROFF:
RB_TROFF_Generate_Header_End( dest_doc, cur_header );
break;
case UNKNOWN:
default:
break;
}
}
/*****/
/****f* Generator/RB_Generate_Item_Name [2.01]
* NAME
* RB_Generate_Item_Name -- fast&easy
* SYNOPSIS
* void RB_Generate_Item_Name( FILE * dest_doc, int item_type )
* FUNCTION
* write the item's name to the doc
* INPUTS
* FILE* dest_doc -- destination file
* int item_type -- the type of item
* AUTHOR
* Koessi
* NOTES
* uses globals: output_mode, item_names[]
* SOURCE
*/
void
RB_Generate_Item_Name( FILE * dest_doc, int item_type )
{
char *name = configuration.item_names[item_type];
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Item_Name( dest_doc, name );
break;
case DBSGML:
assert( 0 );
/* RB_SGMLDocBook_Generate_Item_Name( dest_doc, cur_header ); */
break;
case HTML:
RB_HTML_Generate_Item_Name( dest_doc, name );
break;
case LATEX:
RB_LaTeX_Generate_Item_Name( dest_doc, name );
break;
case RTF:
RB_RTF_Generate_Item_Name( dest_doc, name );
break;
case ASCII:
RB_ASCII_Generate_Item_Name( dest_doc, name );
break;
case TROFF:
assert( 0 );
/* RB_TROFF_Generate_Item_Name( dest_doc, cur_header ); */
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/*********/
/****f* Generator/ExpandTab
* FUNCTION
* Expand the tabs in a line of text.
* SYNOPSIS
* char* RB_ExpandTab(char* line)
* INPUTS
* line -- the line to be expanded
* line_buffer -- global. (No point in allocating memory for each
* line).
* tab_size -- global.
* RETURN
* pointer to the expanded line.
* NOTE
* This function is not reentrant.
* SOURCE
*/
char *
RB_ExpandTab( char *line )
{
char *cur_char = line;
int n = 0;
int jump = 0;
for ( ; *cur_char; ++cur_char )
{
if ( *cur_char == '\t' )
{
int i;
jump = tab_size - ( n % tab_size );
for ( i = 0; i < jump; i++ )
{
line_buffer[n] = ' ';
++n;
}
}
else
{
line_buffer[n] = *cur_char;
++n;
}
}
line_buffer[n] = '\0';
return line_buffer;
}
/******/
/* TODO Documentation */
int
RB_HTML_Extra( FILE * dest_doc, int item_type, char *cur_char )
{
int res = 0;
switch ( output_mode )
{
case XMLDOCBOOK:
break;
case DBSGML:
/* TODO */
break;
case HTML:
res = RB_HTML_Generate_Extra( dest_doc, item_type, cur_char );
break;
case LATEX:
/* TODO */
break;
case RTF:
/* TODO */
break;
case ASCII:
/* TODO */
break;
case TROFF:
/* TODO */
break;
case UNKNOWN:
default:
/* Bug */
assert( 0 );
}
return res;
}
/****f* Generator/RB_Name_Headers
* FUNCTION
* Give all headers a unique name. This makes sure that if
* two headers have the same name linking to one of the headers
* still works.
* SYNOPSIS
* void RB_Name_Headers( struct RB_header** headers, long count )
* SOURCE
*/
#define MAX_UNIQUE_ID_LENGTH 80
void
RB_Name_Headers( struct RB_header **headers, long count )
{
int i;
char id[MAX_UNIQUE_ID_LENGTH + 1];
for ( i = 0; i < count; ++i )
{
struct RB_header *header;
header = headers[i];
sprintf( id, "robo%d", i );
header->unique_name = RB_StrDup( id );
}
}
/******/
/****f* Generator/RB_Generate_Documentation
* FUNCTION
* Generate the documentation for all the information contained in a
* RB_Document structure.
* SYNOPSIS
* void RB_Generate_Documentation( struct RB_Document* document )
* INPUTS
* document -- pointer to the RB_Document structure.
* SOURCE
*/
void
RB_Generate_Documentation( struct RB_Document *document )
{
/* moved to main
output_mode = document->doctype; / * one of the globals that are still left */
if ( document->actions & DO_SINGLEDOC )
{
RB_Generate_SingleDoc( document );
}
else if ( document->actions & DO_MULTIDOC )
{
RB_Generate_MultiDoc( document );
}
else if ( document->actions & DO_SINGLEFILE )
{
RB_Generate_SingleDoc( document );
}
}
/*****/
/****f* Generator/RB_Generate_MultiDoc
* FUNCTION
* Create documentation by creating a file for each
* individual source file that was scanned.
* SYNOPSIS
* void RB_Generate_MultiDoc( struct RB_Document* document )
* INPUTS
* document -- pointer to the RB_Document structure.
* SOURCE
*/
void
RB_Generate_MultiDoc( struct RB_Document *document )
{
struct RB_Part *i_part;
FILE *document_file;
RB_Document_Determine_DocFilePaths( document );
RB_Document_Create_DocFilePaths( document );
RB_Document_Determine_DocFileNames( document );
RB_Document_Collect_Headers( document );
RB_Document_Link_Headers( document );
RB_Fill_Header_Filename( document );
RB_Name_Headers( document->headers, document->no_headers );
RB_CollectLinks( document, document->headers, document->no_headers );
if ( output_mode == HTML )
{
RB_Create_CSS( document );
}
for ( i_part = document->parts; i_part != NULL; i_part = i_part->next )
{
char *srcname = RB_Get_Fullname( i_part->filename );
char *docname = RB_Get_FullDocname( i_part->filename );
document_file = RB_Open_Documentation( i_part );
RB_Generate_Doc_Start( document_file, srcname, docname, 1, docname,
document->charset );
if ( ( document->actions & DO_TOC ) && document->no_headers )
{
RB_Generate_TOC_2( document_file, document->doctype,
document->headers, document->no_headers,
i_part, docname );
}
RB_Generate_Part( document_file, document, i_part );
RB_Generate_Doc_End( document_file, docname );
fclose( document_file );
}
if ( document->actions & DO_INDEX )
{
char *filename =
RB_Get_Index_FileName( document->docroot->name,
document->extension );
FILE *indexfile = fopen( filename, "w" );
if ( indexfile )
{
RB_Generate_Index( document, indexfile, filename );
fclose( indexfile );
}
else
{
RB_Panic( "can't open %s!", filename );
}
free( filename );
}
RB_Free_Links();
}
/*****/
/****f* Generator/RB_Generate_SingleDoc
* FUNCTION
* Create documentation by creating a single file for all individual
* source file that were scanned.
*
* This function is called when the option --singledoc is used.
* Based on whether the option --sections is used this function then
* calls RB_Generate_Sections or RB_Generate_Part
* SYNOPSIS
* void RB_Generate_SingleDoc( struct RB_Document* document )
* INPUTS
* document -- pointer to the RB_Document structure.
* SOURCE
*/
void
RB_Generate_SingleDoc( struct RB_Document *document )
{
FILE *document_file;
struct RB_Part *i_part;
RB_Document_Collect_Headers( document );
RB_Document_Link_Headers( document );
RB_Fill_Header_Filename( document );
RB_Name_Headers( document->headers, document->no_headers );
RB_CollectLinks( document, document->headers, document->no_headers );
if ( output_mode == HTML )
{
RB_Create_CSS( document );
}
document_file = RB_Open_SingleDocumentation( document );
assert( document->parts->filename->name );
RB_Generate_Doc_Start( document_file,
document->srcroot->name,
document->singledoc_name, 1,
document->singledoc_name, document->charset );
if ( ( document->actions & DO_TOC ) && document->no_headers )
{
RB_Generate_TOC_2( document_file, document->doctype,
document->headers, document->no_headers, NULL,
document->parts->filename->name );
}
if ( document->actions & DO_SECTIONS )
{
RB_Generate_Sections( document_file, document );
}
else
{
for ( i_part = document->parts;
i_part != NULL; i_part = i_part->next )
{
RB_Generate_Part( document_file, document, i_part );
}
}
RB_Generate_Doc_End( document_file, "singledoc" );
fclose( document_file );
RB_Free_Links( );
}
/******/
/****f* Generator/RB_Generate_Sections
* FUNCTION
* Creates the documentation for all headers found in all source
* files. The order in which they are generated depends on the
* header hierarchy. First the top level header's documentation
* is generated then, the documentation for all it's childern, then
* the next top level header's documentation is generated.
* This is a recursive proces.
* The idea is to create something like:
* 1. Parentheader1
* 1.1 Child1
* 1.2 Child2
* 1.2.1 Child's child1
* 2. Parentheader2
* etc
* SYNOPSIS
* void RB_Generate_Sections( FILE* document_file,
* struct RB_Document* document )
* INPUTS
* document_file -- destination file.
* document -- pointer to the RB_Document structure.
* SOURCE
*/
void
RB_Generate_Sections( FILE * document_file, struct RB_Document *document )
{
unsigned long i;
int depth = 1;
struct RB_header *header;
RB_Say( "Generating Sections\n" );
for ( i = 0; i < document->no_headers; ++i )
{
header = ( document->headers )[i];
if ( header->parent )
{
/* This will be in one of the subsections */
}
else
{
RB_Generate_Section( document_file, header, document, depth );
}
}
}
/******/
/****f* Generator/RB_Generate_Section
* FUNCTION
* Generate the documentation for a header and all
* its childern.
* INPUTS
* document_file -- destination file
* parent -- the parent of the header for which the documentation
* is to be generated.
* document -- pointer to the RB_Document structure.
* depth -- level of sectioning ( 1 1.1 1.1.1 etc)
* NOTE
* This is a recursive function.
* SEE ALSO
* RB_Generate_Sections
* SOURCE
*/
void
RB_Generate_Section( FILE * document_file,
struct RB_header *parent, struct RB_Document *document,
int depth )
{
unsigned long i;
struct RB_header *header;
RB_Generate_Label( document_file, parent->unique_name );
RB_Generate_Label( document_file, parent->name );
RB_Generate_BeginSection( document_file, depth, parent->name );
RB_Generate_Index_Entry( document_file, document->doctype, parent );
RB_Generate_Header( document_file, document, parent, "dummy", "dummy" );
for ( i = 0; i < document->no_headers; ++i )
{
header = ( document->headers )[i];
if ( header->parent == parent )
{
RB_Generate_Section( document_file, header, document, depth + 1 );
}
else
{
/* Leeg */
}
}
RB_Generate_EndSection( document_file, depth, parent->name );
}
/******/
/****f* Generator/RB_Generate_Part
* FUNCTION
* Generate the documention for all the headers found in a single
* source file.
* INPUTS
* document_file -- The file were it stored.
* document -- All the documentation.
* part -- pointer to a RB_Part that contains all the headers found
* in a single source file.
* SOURCE
*/
void
RB_Generate_Part( FILE * document_file,
struct RB_Document *document, struct RB_Part *part )
{
struct RB_header *i_header;
char *docname = NULL;
char *srcname = RB_Get_Fullname( part->filename );
if ( document->actions & DO_SINGLEDOC )
{
docname = document->singledoc_name;
}
else if ( document->actions & DO_MULTIDOC )
{
docname = RB_Get_FullDocname( part->filename );
}
else if ( document->actions & DO_SINGLEFILE )
{
docname = document->singledoc_name;
}
else
{
assert( 0 );
}
for ( i_header = part->headers; i_header; i_header = i_header->next )
{
RB_Say( "generating documentation for \"%s\"\n", i_header->name );
RB_Generate_Header_Start( document_file, i_header );
RB_Generate_Index_Entry( document_file, document->doctype, i_header );
RB_Generate_Header( document_file, document, i_header,
srcname, docname );
RB_Generate_Header_End( document_file, i_header );
}
}
/******/
/****f* Generator/RB_Generate_Header
* FUNCTION
* Generate the documentation for all the items found in
* a header except for any items specified in
* configuration.ignore_items.
* SYNOPSIS
* void RB_Generate_Header( FILE* f, struct RB_Document* document,
* struct RB_header* header, char* srcname, char* docname)
* INPUTS
* f -- destination file
* header -- header to be searched.
* srcname -- name of the source file the header was found in.
* document -- name of the documentation file.
* BUGS
* This skips the first item body if the first item name was
* not correctly spelled.
* SOURCE
*/
static void
RB_Generate_Header( FILE * f,
struct RB_Document *document,
struct RB_header *header, char *srcname, char *docname )
{
int line_nr;
int next_line_nr = 0;
enum ItemType item_type = NO_ITEM;
enum ItemType next_item_type = NO_ITEM;
char **lines = header->lines;
char *line;
int ignore = FALSE;
/* option --lock */
RB_Header_Lock_Reset( );
/* Find the first item in the header. */
for ( line_nr = 0; line_nr < header->no_lines; ++line_nr )
{
line = lines[line_nr];
item_type = RB_Is_ItemName( line );
if ( item_type != NO_ITEM )
{
break;
}
}
if ( item_type == NO_ITEM )
{
printf( "%s: WARNING, header \"%s\" has no items\n",
whoami, header->name );
}
if ( item_type == POSSIBLE_ITEM )
{
printf
( "%s: WARNING, header \"%s\" has a possible misspelled item %s\n",
whoami, header->name, RB_Get_Item_Name( ) );
item_type = NO_ITEM;
}
/* Find all the other items */
while ( item_type != NO_ITEM && ( next_line_nr < header->no_lines ) )
{
next_line_nr = line_nr + 1;
ignore = RB_Ignore_Last_Item();
for ( ; next_line_nr < header->no_lines; ++next_line_nr )
{
line = lines[next_line_nr];
next_item_type = RB_Is_ItemName( line );
if ( next_item_type != NO_ITEM )
{
break;
}
}
if ( next_item_type == POSSIBLE_ITEM )
{
printf
( "%s: WARNING, header \"%s\" has a possible misspelled item:\n \"%s\"\n",
whoami, header->name, RB_Get_Item_Name( ) );
next_item_type = NO_ITEM;
}
else if ( !( ( item_type == SOURCE_ITEM ) &&
( course_of_action & DO_NOSOURCE ) ) && !ignore )
{
if ( course_of_action & DO_TELL )
{
printf( "[%s]\n", configuration.item_names[item_type] );
}
RB_Generate_Item_Name( f, item_type );
if ( line_nr + 1 == next_line_nr )
{
RB_Generate_Empty_Item( f );
}
else
{
assert( next_line_nr <= header->no_lines );
RB_Generate_Item_Doc( f, lines, line_nr, next_line_nr,
item_type, srcname, docname,
header->function_name,
document->extension,
document->charset );
}
}
else
{
/* Ignore the item */
}
item_type = next_item_type;
line_nr = next_line_nr;
}
if ( course_of_action & DO_TELL )
{
printf( "\n" );
}
}
/******/
/*x**f* Generator/RB_Generate_Empty_Item
* FUNCTION
* Generate documentation for an item with an empty body.
* INPUTS
* dest_doc -- destination file.
****
* TODO Documentation
*/
static void
RB_Generate_Empty_Item( FILE * dest_doc )
{
switch ( output_mode )
{
case XMLDOCBOOK:
break;
case HTML:
RB_HTML_Generate_Empty_Item( dest_doc );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Empty_Item( dest_doc );
break;
case LATEX:
RB_LaTeX_Generate_Empty_Item( dest_doc );
break;
case RTF:
RB_RTF_Generate_Empty_Item( dest_doc );
break;
case TROFF:
RB_TROFF_Generate_Empty_Item( dest_doc );
break;
case ASCII:
RB_ASCII_Generate_Empty_Item( dest_doc );
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/****f* Generator/RB_Generate_Item_Doc
* FUNCTION
* Generate the body of a single item. The item's body is generated
* line by line.
* Any empty lines at the front or the back of the item are skipped.
* This makes the documentation look more uniform when more than
* one person is working on the sources and one adds an empty line
* after an item name and the others do not.
*
* Except for the SOURCE item, all lines that do not start with
* a remark marker are not included in the documentation.
* SYNOPSIS
* static void
* RB_Generate_Item_Doc( FILE * dest_doc,
* char **lines, int line_begin, int line_end,
* int item_type,
* char *srcname, char *docname,
* char *function_name, char *extension, char *charset )
*
* SOURCE
*/
static void
RB_Generate_Item_Doc( FILE * dest_doc,
char **lines, int line_begin, int line_end,
int item_type,
char *srcname, char *docname,
char *function_name, char *extension, char *charset )
{
int line_nr = line_begin + 1;
char *line;
if ( item_type == SOURCE_ITEM )
{
/* Skip end marker after the source item */
++line_nr;
/* skip blank lines leading up to the source */
for ( ;
( line_nr < line_end ) && ( strlen( lines[line_nr] ) == 0 );
++line_nr )
{
/* Empty */
}
}
else
{
/* Skip any empty lines in the front of the back
* This makes the documentation look more uniform.
*/
for ( ; line_nr < line_end; ++line_nr )
{
line = RB_ExpandTab( lines[line_nr] );
assert( line );
line = RB_Skip_Whitespace( line );
if ( RB_Has_Remark_Marker( line ) )
{
line = RB_Skip_Remark_Marker( line );
if ( strlen( line ) )
{
/* A non empty line */
break;
}
}
}
for ( --line_end; line_nr < line_end; --line_end )
{
line = RB_ExpandTab( lines[line_end] );
assert( line );
line = RB_Skip_Whitespace( line );
if ( RB_Has_Remark_Marker( line ) )
{
line = RB_Skip_Remark_Marker( line );
if ( strlen( line ) )
{
break;
}
}
}
++line_end;
}
RB_Generate_Item_Begin( dest_doc );
/* Now generate the itembody line by line */
for ( ; line_nr < line_end; line_nr++ )
{
line = RB_ExpandTab( lines[line_nr] );
if ( item_type != SOURCE_ITEM )
{
line = RB_Skip_Whitespace( line );
if ( RB_Has_Remark_Marker( line ) )
{
line = RB_Skip_Remark_Marker( line );
RB_Generate_Item_Line( dest_doc, line,
item_type, srcname, docname,
function_name );
}
else
{
/* The line did not start with one of the
* remark markers, so we skip it
*/
}
}
else
{
/* TODO Should check if we actually want folds! */
if ( RB_Fold( line, &docname, &dest_doc, extension, charset ) )
{
/* Empty */
}
else
{
RB_Generate_Item_Line( dest_doc, line,
item_type, srcname, docname,
function_name );
}
}
}
RB_Generate_Item_End( dest_doc );
}
/*****/
/****f* Generator/RB_Is_Pipe_Marker
* NAME
* RB_Is_Pipe_Marker
* FUNCTION
* Check for "pipe" markers e.g. "|html ".
* SYNOPSIS
* static char * RB_Is_Pipe_Marker(char *cur_char, int *pipe_mode )
* RESULT
* Pointer to the data to be piped to document or in case no pointers
* are found.
* SEE ALSO
* RB_Check_Pipe
*******
*/
static char *
RB_Is_Pipe_Marker( char *cur_char, int *pipe_mode )
{
char *s = cur_char + 1;
*pipe_mode = -1;
if ( *cur_char == '|' && *s )
{
if ( strncmp( "html ", s, 5 ) == 0 )
{
*pipe_mode = HTML;
return ( s + 5 );
}
else if ( strncmp( "latex ", s, 6 ) == 0 )
{
*pipe_mode = LATEX;
return ( s + 6 );
}
else if ( strncmp( "rtf ", s, 4 ) == 0 )
{
*pipe_mode = RTF;
return ( s + 4 );
}
else if ( strncmp( "dbxml ", s, 6 ) == 0 )
{
*pipe_mode = XMLDOCBOOK;
return ( s + 6 );
}
else if ( strncmp( "ascii ", s, 6 ) == 0 )
{
*pipe_mode = ASCII;
return ( s + 6 );
}
}
return ( char * ) NULL;
}
/****f* Generator/RB_Check_Pipe
* NAME
* RB_Check_Pipe
* FUNCTION
* Check for pipe marker in given line skipping whitespaces in the beginning.
* SYNOPSIS
* static char * RB_Is_Pipe_Marker(char *cur_char, int *pipe_mode )
* RESULT
* Pointer to the data to be piped to document body or null in case no
* pointers are found.
* SEE ALSO
* RB_Is_Pipe_Marker
*******
*/
static char *
RB_Check_Pipe( char *line, int *pipe_mode )
{
char *cur_char = line;
skip_while( *cur_char == ' ' || *cur_char == '\t' );
return RB_Is_Pipe_Marker( cur_char, pipe_mode );
}
/*x**f* Generator/RB_Generate_Item_Line
* NAME
* RB_Generate_Item_Line
* FUNCTION
* Generate a single line of an item's body.
******
* TODO Documentation
*/
static void
RB_Generate_Item_Line( FILE * dest_doc, char *line,
int item_type,
char *srcname, char *docname, char *function_name )
{
char *cur_char = line;
char *pipe_line = NULL;
char *object_name = NULL;
char *label_name = NULL;
char *file_name = NULL;
int do_search = TRUE;
int was_link = FALSE, pipe_mode;
if ( item_type == SOURCE_ITEM )
{
/* indent source code */
fprintf( dest_doc, " " );
if ( output_mode == LATEX && piping == TRUE )
{
fprintf( dest_doc, "\\begin{verbatim}\n" );
}
piping = FALSE;
}
else
{
/* `pipes' can not be embedded in source items */
pipe_line = RB_Check_Pipe( cur_char, &pipe_mode );
if ( pipe_line )
{
if ( pipe_mode != output_mode )
{
return; /* skip */
}
if ( output_mode == LATEX && piping == FALSE )
{
fprintf( dest_doc, "\\end{verbatim}\n" );
}
/* preserve whitespaces before any pipe directives */
for ( ; *cur_char && ( *cur_char == ' ' || *cur_char == '\t' );
cur_char++ )
{
fputc( *cur_char, dest_doc );
}
fprintf( dest_doc, "%s%s", pipe_line,
( output_mode == RTF ? "\\line" : "\n" ) );
piping = TRUE;
return;
}
else
{
if ( output_mode == LATEX && piping == TRUE )
{
fprintf( dest_doc, "\\begin{verbatim}\n" );
}
piping = FALSE;
}
}
for ( ; *cur_char; cur_char++ )
{
char c = *cur_char;
/* This is a little statemachine to switch searching for
* links on and off.
*/
if ( !do_search )
{
/* if we are not in searching mode and we are outside a
* word then we switch searching back on. This way the
* next word can result in a link.
*/
do_search = ( !isalnum( c ) && ( c != '_' ) );
was_link = FALSE;
}
else
{
if ( isalpha( c ) || ( c == '_' ) )
{
was_link = RB_Find_Link( cur_char,
&object_name, &label_name,
&file_name );
do_search = FALSE;
}
else
{
was_link = FALSE;
}
}
if ( !was_link )
{
int res;
res = RB_HTML_Extra( dest_doc, item_type, cur_char );
if ( res )
{
cur_char += res;
}
else
{
/* convert from signed to unsigned */
unsigned char c2 = *cur_char;
RB_Generate_Char( dest_doc, c2 );
}
}
else
{
if ( object_name && function_name )
{
if ( strcmp( object_name, function_name ) == 0 )
{
RB_Generate_False_Link( dest_doc, object_name );
cur_char += strlen( object_name ) - 1;
}
else
{
RB_Generate_Link( dest_doc, docname,
file_name, label_name, object_name );
cur_char += strlen( object_name ) - 1;
}
}
}
}
/* TODO Move to the RTF_Generator */
if ( output_mode == RTF )
fprintf( dest_doc, "\\line" );
/* For all modes we add a newline. */
fputc( '\n', dest_doc );
}
/****f* Generator/RB_Generate_Link
* FUNCTION
* Generate a link to another headers documentation.
* SYNOPSIS
* void RB_Generate_Link( FILE* dest_doc, char* docname, char* file_name,
* char* label_name, char* function_name )
* INPUT
* dest_doc -- the output file
* docname -- the name of the output file
* file_name -- the name of the file that contains the link's body
* label_name -- the label for the link
* function_name -- the name that is shown for the link in the
* documentation
* SOURCE
*/
void
RB_Generate_Link( FILE * dest_doc, char *docname, char *file_name,
char *label_name, char *function_name )
{
int in_fold = 0;
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Link( dest_doc, docname, file_name, label_name,
function_name, in_fold );
break;
case HTML:
RB_HTML_Generate_Link( dest_doc, docname, file_name, label_name,
function_name, in_fold );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Link( dest_doc, docname, file_name,
label_name, function_name, in_fold );
break;
case RTF:
RB_RTF_Generate_Link( dest_doc, docname, file_name, label_name,
function_name, in_fold );
break;
case UNKNOWN:
case ASCII:
case LATEX:
case TROFF:
default:
fprintf( dest_doc, "%s", function_name );
}
}
/******/
/****f* Generator/RB_Generate_Char
* FUNCTION
* Generate a single character in the current output mode.
* The individual generators will make sure that special
* characters are escaped.
* INPUTS
* dest_doc -- destination file.
* cur_char -- character to be generated.
*******
*/
void
RB_Generate_Char( FILE * dest_doc, int cur_char )
{
switch ( output_mode )
{
case XMLDOCBOOK:
RB_XMLDB_Generate_Char( dest_doc, cur_char );
break;
case DBSGML:
RB_SGMLDocBook_Generate_Char( dest_doc, cur_char );
break;
case HTML:
RB_HTML_Generate_Char( dest_doc, cur_char );
break;
case LATEX:
RB_LaTeX_Generate_Char( dest_doc, cur_char );
break;
case RTF:
RB_RTF_Generate_Char( dest_doc, cur_char );
break;
case TROFF:
RB_TROFF_Generate_Char( dest_doc, cur_char );
break;
case ASCII:
RB_ASCII_Generate_Char( dest_doc, cur_char );
break;
case UNKNOWN:
default:
assert( 0 );
}
}
/****f* Generator/RB_Get_SubIndex_FileName
* FUNCTION
* Get the name of the master index file for a specific
* header_type.
* INPUTS
* docroot -- the path to the documentation directory.
* extension -- the extension for the file
* header_type -- the header type
* RESULT
* a pointer to a freshly allocated string.
* NOTES
* Has too many parameters.
******
*/
char *
RB_Get_SubIndex_FileName( char *docroot, char *extension,
struct RB_HeaderType *header_type )
{
size_t l;
char *filename;
assert( docroot );
l = strlen( docroot );
l += RB_Get_Len_Extension( extension );
l += strlen( docroot );
l += strlen( header_type->fileName );
filename = ( char * ) malloc( l + 2 );
assert( filename );
filename[0] = '\0';
strcat( filename, docroot );
strcat( filename, header_type->fileName );
RB_Add_Extension( extension, filename );
return filename;
}
char *
RB_Get_Index_FileName( char *docroot, char *extension )
{
size_t l;
char *basename = "masterindex";
char *filename;
assert( docroot );
l = strlen( docroot );
l += strlen( basename );
l += RB_Get_Len_Extension( extension );
filename = ( char * ) malloc( l + 1 );
assert( filename );
filename[0] = '\0';
strcat( filename, docroot );
strcat( filename, basename );
RB_Add_Extension( extension, filename );
return filename;
}
/****f* Generator/RB_Generate_Index
* NAME
* RB_Generate_Index -- generate index file based on xref files.
* SYNOPSIS
* void RB_Generate_Index(FILE *dest, char *name)
* FUNCTION
* Create a master index file. It contains pointers to the
* documentation generated for each source file, as well as all
* "objects" found in the source files.
********
*/
static void
RB_Generate_Index( struct RB_Document *document, FILE * dest,
char *dest_name )
{
switch ( output_mode )
{
case XMLDOCBOOK:
break;
case HTML:
RB_HTML_Generate_Index( document );
break;
case DBSGML:
/* RB_SGMLDocBook_Generate_Index(dest, source); */
assert( 0 );
break;
case LATEX:
/* RB_LaTeX_Generate_Index(dest, source); */
assert( 0 );
break;
case UNKNOWN:
case ASCII:
case TROFF:
case RTF:
default:
break;
}
}
|