mxmldoc.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <html>
  2. <body>
  3. <h1 align='right'><a name='MXMLDOC'><img src="4.gif" align="right"
  4. hspace="10" width="100" height="100" alt="4"></a>Using the mxmldoc
  5. Utility</h1>
  6. <p>This chapter describes how to use <tt>mxmldoc(1)</tt> program to
  7. automatically generate documentation from C and C++ source
  8. files.</p>
  9. <h2>The Basics</h2>
  10. <p>Originally developed to generate the Mini-XML and CUPS API
  11. documentation, <tt>mxmldoc</tt> is now a general-purpose utility
  12. which scans C and C++ source files to produce HTML and man page
  13. documentation along with an XML file representing the functions,
  14. types, and definitions in those source files. Unlike popular
  15. documentation generators like Doxygen or Javadoc, <tt>mxmldoc</tt>
  16. uses in-line comments rather than comment headers, allowing for more
  17. "natural" code documentation.</p>
  18. <p>By default, <tt>mxmldoc</tt> produces HTML documentation. For
  19. example, the following command will scan all of the C source and
  20. header files in the current directory and produce a HTML
  21. documentation file called <var>filename.html</var>:</p>
  22. <pre>
  23. <kbd>mxmldoc *.h *.c &gt;filename.html ENTER</kbd>
  24. </pre>
  25. <p>You can also specify an XML file to create which contains all of
  26. the information from the source files. For example, the following
  27. command creates an XML file called <var>filename.xml</var> in
  28. addition to the HTML file:</p>
  29. <pre>
  30. <kbd>mxmldoc filename.xml *.h *.c &gt;filename.html ENTER</kbd>
  31. </pre>
  32. <p>The <tt>--no-output</tt> option disables the normal HTML
  33. output:</p>
  34. <pre>
  35. <kbd>mxmldoc --no-output filename.xml *.h *.c ENTER</kbd>
  36. </pre>
  37. <p>You can then run <tt>mxmldoc</tt> again with the XML file alone
  38. to generate the HTML documentation:</p>
  39. <pre>
  40. <kbd>mxmldoc filename.xml &gt;filename.html ENTER</kbd>
  41. </pre>
  42. <h3>Creating Man Pages</h3>
  43. <p>The <tt>--man filename</tt> option tells <tt>mxmldoc</tt> to
  44. create a man page instead of HTML documentation, for example:</p>
  45. <pre>
  46. <kbd>mxmldoc --man filename filename.xml \
  47. &gt;filename.man ENTER</kbd>
  48. <kbd>mxmldoc --man filename *.h *.c \
  49. &gt;filename.man ENTER</kbd>
  50. </pre>
  51. <h3>Creating Xcode Documentation Sets</h3>
  52. <p>The <tt>--docset directory.docset</tt> option tells <tt>mxmldoc</tt> to
  53. create an Xcode documentation set containing the HTML documentation, for
  54. example:</p>
  55. <pre>
  56. <kbd>mxmldoc --docset foo.docset *.h *.c foo.xml ENTER</kbd>
  57. </pre>
  58. <p>Xcode documentation sets can only be built on Mac OS X with Xcode 3.0 or
  59. higher installed.</p>
  60. <h2>Commenting Your Code</h2>
  61. <p>As noted previously, <tt>mxmldoc</tt> looks for in-line comments
  62. to describe the functions, types, and constants in your code.
  63. <tt>Mxmldoc</tt> will document all public names it finds in your
  64. source files - any names starting with the underscore character (_)
  65. or names that are documented with the <A
  66. HREF="#ATDIRECTIVES">@private@</A> directive are treated as private
  67. and are not documented.</p>
  68. <p>Comments appearing directly before a function or type definition
  69. are used to document that function or type. Comments appearing after
  70. argument, definition, return type, or variable declarations are used
  71. to document that argument, definition, return type, or variable. For
  72. example, the following code excerpt defines a key/value structure
  73. and a function that creates a new instance of that structure:</p>
  74. <pre>
  75. /* A key/value pair. This is used with the
  76. dictionary structure. */
  77. struct keyval
  78. {
  79. char *key; /* Key string */
  80. char *val; /* Value string */
  81. };
  82. /* Create a new key/value pair. */
  83. struct keyval * /* New key/value pair */
  84. new_keyval(
  85. const char *key, /* Key string */
  86. const char *val) /* Value string */
  87. {
  88. ...
  89. }
  90. </pre>
  91. <p><tt>Mxmldoc</tt> also knows to remove extra asterisks (*) from
  92. the comment string, so the comment string:</p>
  93. <pre>
  94. /*
  95. * Compute the value of PI.
  96. *
  97. * The function connects to an Internet server
  98. * that streams audio of mathematical monks
  99. * chanting the first 100 digits of PI.
  100. */
  101. </pre>
  102. <p>will be shown as:</p>
  103. <pre>
  104. Compute the value of PI.
  105. The function connects to an Internet server
  106. that streams audio of mathematical monks
  107. chanting the first 100 digits of PI.
  108. </pre>
  109. <p><a name="ATDIRECTIVES">Comments</a> can also include the
  110. following special <tt>@name ...@</tt> directive strings:</p>
  111. <ul>
  112. <li><tt>@deprecated@</tt> - flags the item as deprecated to
  113. discourage its use</li>
  114. <li><tt>@private@</tt> - flags the item as private so it
  115. will not be included in the documentation</li>
  116. <li><tt>@since ...@</tt> - flags the item as new since a
  117. particular release. The text following the <tt>@since</tt>
  118. up to the closing <tt>@</tt> is highlighted in the generated
  119. documentation, e.g. <tt>@since Mini-XML 2.7@</tt>.</li>
  120. </ul>
  121. <!-- NEED 10 -->
  122. <h2>Titles, Sections, and Introductions</h2>
  123. <p><tt>Mxmldoc</tt> also provides options to set the title, section,
  124. and introduction text for the generated documentation. The
  125. <tt>--title text</tt> option specifies the title for the
  126. documentation. The title string is usually put in quotes:</p>
  127. <pre>
  128. <kbd>mxmldoc filename.xml \
  129. --title "My Famous Documentation" \
  130. &gt;filename.html ENTER</kbd>
  131. </pre>
  132. <p>The <tt>--section name</tt> option specifies the section for
  133. the documentation. For HTML documentation, the name is placed in
  134. a HTML comment such as:</p>
  135. <pre>
  136. &lt;!-- SECTION: name -->
  137. </pre>
  138. <p>For man pages, the section name is usually just a number ("3"),
  139. or a number followed by a vendor name ("3acme"). The section name is
  140. used in the <tt>.TH</tt> directive in the man page:</p>
  141. <pre>
  142. .TH mylibrary 3acme "My Title" ...
  143. </pre>
  144. <p>The default section name for man page output is "3". There is no
  145. default section name for HTML output.</p>
  146. <p>Finally, the <tt>--intro filename</tt> option specifies a file to
  147. embed after the title and section but before the generated
  148. documentation. For HTML documentation, the file must consist of
  149. valid HTML without the usual <tt>DOCTYPE</tt>, <tt>html</tt>, and
  150. <tt>body</tt> elements. For man page documentation, the file must
  151. consist of valid <tt>nroff(1)</tt> text.</p>
  152. </body>
  153. </html>