synop.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:exsl="http://exslt.org/common"
  4. exclude-result-prefixes="exsl"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id: synop.xsl 7956 2008-03-27 12:07:43Z xmldoc $
  8. ********************************************************************
  9. This file is part of the XSL DocBook Stylesheet distribution.
  10. See ../README or http://docbook.sf.net/release/xsl/current/ for
  11. copyright and other information.
  12. ******************************************************************** -->
  13. <xsl:variable name="arg.or.sep"> |</xsl:variable>
  14. <!-- * Note: If you're looking for the *Synopsis* element, you won't -->
  15. <!-- * find any code here for handling it. It's a "verbatim" -->
  16. <!-- * environment; see the block.xsl file instead. -->
  17. <xsl:template match="synopfragmentref">
  18. <xsl:variable name="target" select="key('id',@linkend)"/>
  19. <xsl:variable name="snum">
  20. <xsl:apply-templates select="$target" mode="synopfragment.number"/>
  21. </xsl:variable>
  22. <xsl:text>(</xsl:text>
  23. <xsl:value-of select="$snum"/>
  24. <xsl:text>)</xsl:text>
  25. <xsl:text>&#x2580;</xsl:text>
  26. <xsl:call-template name="italic">
  27. <xsl:with-param name="node" select="."/>
  28. <xsl:with-param name="context" select="."/>
  29. </xsl:call-template>
  30. </xsl:template>
  31. <xsl:template match="synopfragment" mode="synopfragment.number">
  32. <xsl:number format="1"/>
  33. </xsl:template>
  34. <xsl:template match="synopfragment">
  35. <xsl:variable name="snum">
  36. <xsl:apply-templates select="." mode="synopfragment.number"/>
  37. </xsl:variable>
  38. <xsl:text>&#10;</xsl:text>
  39. <!-- * If we have a group of Synopfragments, we only want to output a -->
  40. <!-- * line of space before the first; so when we find a Synopfragment -->
  41. <!-- * which has another Synopfragment as a following sibling, we use-->
  42. <!-- * the pinch-together template to close up the line of space -->
  43. <!-- * that would otherwise be generated by the .HP macro -->
  44. <xsl:if test="following-sibling::*[self::synopfragment]">
  45. <xsl:call-template name="pinch.together"/>
  46. </xsl:if>
  47. <xsl:text>.HP </xsl:text>
  48. <xsl:text>\w'</xsl:text>
  49. <xsl:text>(</xsl:text>
  50. <xsl:value-of select="$snum"/>
  51. <xsl:text>)</xsl:text>
  52. <xsl:text>\ 'u</xsl:text>
  53. <xsl:text>&#10;</xsl:text>
  54. <xsl:text>(</xsl:text>
  55. <xsl:value-of select="$snum"/>
  56. <xsl:text>)</xsl:text>
  57. <xsl:text>\ </xsl:text>
  58. <xsl:apply-templates/>
  59. </xsl:template>
  60. <xsl:template match="group|arg" name="group-or-arg">
  61. <xsl:variable name="choice" select="@choice"/>
  62. <xsl:variable name="rep" select="@rep"/>
  63. <xsl:variable name="sepchar">
  64. <xsl:choose>
  65. <xsl:when test="ancestor-or-self::*/@sepchar">
  66. <xsl:value-of select="ancestor-or-self::*/@sepchar"/>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:text> </xsl:text>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:variable>
  73. <xsl:if test="position()>1 and
  74. not(preceding-sibling::*[1][self::sbr])"
  75. ><xsl:value-of select="$sepchar"/></xsl:if>
  76. <xsl:choose>
  77. <xsl:when test="$choice='plain'">
  78. <!-- * do nothing -->
  79. </xsl:when>
  80. <xsl:when test="$choice='req'">
  81. <xsl:value-of select="$arg.choice.req.open.str"/>
  82. </xsl:when>
  83. <xsl:when test="$choice='opt'">
  84. <xsl:value-of select="$arg.choice.opt.open.str"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <xsl:value-of select="$arg.choice.def.open.str"/>
  88. </xsl:otherwise>
  89. </xsl:choose>
  90. <xsl:variable name="arg">
  91. <xsl:apply-templates/>
  92. </xsl:variable>
  93. <xsl:choose>
  94. <xsl:when test="local-name(.) = 'arg' and not(ancestor::arg)">
  95. <!-- * Prevent arg contents from getting wrapped and broken up -->
  96. <xsl:variable name="arg.wrapper">
  97. <Arg><xsl:value-of select="normalize-space($arg)"/></Arg>
  98. </xsl:variable>
  99. <xsl:apply-templates mode="prevent.line.breaking"
  100. select="exsl:node-set($arg.wrapper)"/>
  101. </xsl:when>
  102. <xsl:otherwise>
  103. <xsl:value-of select="$arg"/>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. <xsl:choose>
  107. <xsl:when test="$rep='repeat'">
  108. <xsl:value-of select="$arg.rep.repeat.str"/>
  109. </xsl:when>
  110. <xsl:when test="$rep='norepeat'">
  111. <xsl:value-of select="$arg.rep.norepeat.str"/>
  112. </xsl:when>
  113. <xsl:otherwise>
  114. <xsl:value-of select="$arg.rep.def.str"/>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. <xsl:choose>
  118. <xsl:when test="$choice='plain'">
  119. <xsl:if test='arg'>
  120. <xsl:value-of select="$arg.choice.plain.close.str"/>
  121. </xsl:if>
  122. </xsl:when>
  123. <xsl:when test="$choice='req'">
  124. <xsl:value-of select="$arg.choice.req.close.str"/>
  125. </xsl:when>
  126. <xsl:when test="$choice='opt'">
  127. <xsl:value-of select="$arg.choice.opt.close.str"/>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:value-of select="$arg.choice.def.close.str"/>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. </xsl:template>
  134. <xsl:template match="group/arg">
  135. <xsl:variable name="choice" select="@choice"/>
  136. <xsl:variable name="rep" select="@rep"/>
  137. <xsl:if test="position()>1"><xsl:value-of select="$arg.or.sep"/></xsl:if>
  138. <xsl:call-template name="group-or-arg"/>
  139. </xsl:template>
  140. <xsl:template match="sbr">
  141. <xsl:text>&#x2592;</xsl:text>
  142. <xsl:text>.br&#x2592;</xsl:text>
  143. </xsl:template>
  144. <xsl:template match="cmdsynopsis">
  145. <!-- * if justification is enabled by default, turn it off temporarily -->
  146. <xsl:if test="$man.justify != 0">
  147. <xsl:text>.ad l&#10;</xsl:text>
  148. </xsl:if>
  149. <!-- * if hyphenation is enabled by default, turn it off temporarily -->
  150. <xsl:if test="$man.hyphenate != 0">
  151. <xsl:text>.hy 0&#10;</xsl:text>
  152. </xsl:if>
  153. <xsl:call-template name="synopsis-block-start"/>
  154. <xsl:text>.HP </xsl:text>
  155. <xsl:text>\w'</xsl:text>
  156. <xsl:variable name="command">
  157. <xsl:apply-templates select="command"/>
  158. </xsl:variable>
  159. <xsl:call-template name="string.subst">
  160. <xsl:with-param name="string" select="normalize-space($command)"/>
  161. <xsl:with-param name="target" select="' '"/>
  162. <xsl:with-param name="replacement" select="'\ '"/>
  163. </xsl:call-template>
  164. <xsl:text>\ 'u</xsl:text>
  165. <xsl:text>&#10;</xsl:text>
  166. <xsl:apply-templates/>
  167. <xsl:text>&#10;</xsl:text>
  168. <xsl:call-template name="synopsis-block-end"/>
  169. <!-- * if justification is enabled by default, turn it back on -->
  170. <xsl:if test="$man.justify != 0">
  171. <xsl:text>.ad&#10;</xsl:text>
  172. </xsl:if>
  173. <!-- * if hyphenation is enabled by default, turn it back on -->
  174. <xsl:if test="$man.hyphenate != 0">
  175. <xsl:text>.hy&#10;</xsl:text>
  176. </xsl:if>
  177. </xsl:template>
  178. <!-- ==================================================================== -->
  179. <!-- * Funcsynopis hierarchy starts here -->
  180. <!-- ==================================================================== -->
  181. <!-- * Note: If you're looking for the *Funcsynopsisinfo* element, -->
  182. <!-- * you won't find any code here for handling it. It's a "verbatim" -->
  183. <!-- * environment; see the block.xsl file instead. -->
  184. <!-- * Within funcsynopis output, disable hyphenation, and use -->
  185. <!-- * left-aligned filling for the duration of the synopsis, so that -->
  186. <!-- * line breaks only occur between separate paramdefs. -->
  187. <xsl:template match="funcsynopsis">
  188. <!-- * if justification is enabled by default, turn it off temporarily -->
  189. <xsl:if test="$man.justify != 0">
  190. <xsl:text>.ad l&#10;</xsl:text>
  191. </xsl:if>
  192. <!-- * if hyphenation is enabled by default, turn it off temporarily -->
  193. <xsl:if test="$man.hyphenate != 0">
  194. <xsl:text>.hy 0&#10;</xsl:text>
  195. </xsl:if>
  196. <xsl:apply-templates/>
  197. <!-- * if justification is enabled by default, turn it back on -->
  198. <xsl:if test="$man.justify != 0">
  199. <xsl:text>.ad&#10;</xsl:text>
  200. </xsl:if>
  201. <!-- * if hyphenation is enabled by default, turn it back on -->
  202. <xsl:if test="$man.hyphenate != 0">
  203. <xsl:text>.hy&#10;</xsl:text>
  204. </xsl:if>
  205. </xsl:template>
  206. <!-- * In HTML output, placing a dbfunclist PI as a child of a particular -->
  207. <!-- * element creates a hyperlinked list of all funcsynopsis instances -->
  208. <!-- * that are descendants of that element. But we can’t really do this -->
  209. <!-- * kind of hyperlinked list in manpages output, so we just need to -->
  210. <!-- * suppress it instead. -->
  211. <xsl:template match="processing-instruction('dbfunclist')"/>
  212. <!-- * ***************************************************************** -->
  213. <!-- * Note about boldface in funcprototype output -->
  214. <!-- * ***************************************************************** -->
  215. <!-- * All funcprototype content is by default rendered in bold, -->
  216. <!-- * because the old man(7) man page, now man-pages(7) says this: -->
  217. <!-- * -->
  218. <!-- * For functions, the arguments are always specified using -->
  219. <!-- * italics, even in the SYNOPSIS section, where the rest of -->
  220. <!-- * the function is specified in bold -->
  221. <!-- * -->
  222. <!-- * Look through the contents of the man/man2 and man3 directories -->
  223. <!-- * on your system, and you'll see that most existing pages do follow -->
  224. <!-- * this "bold everything in function synopsis" rule. -->
  225. <!-- * -->
  226. <!-- * Users who don't want the bold output can choose to adjust the -->
  227. <!-- * man.font.funcprototype parameter on their own. So even if you -->
  228. <!-- * don't personally like the way it looks, please don't change the -->
  229. <!-- * default to be non-bold - because it's a convention that's -->
  230. <!-- * followed is the vast majority of existing man pages that document -->
  231. <!-- * functions, and we need to follow it by default, like it or no. -->
  232. <!-- * ***************************************************************** -->
  233. <xsl:template match="funcprototype">
  234. <xsl:variable name="man-funcprototype-style">
  235. <xsl:call-template name="pi.dbman_funcsynopsis-style">
  236. <xsl:with-param name="node" select="ancestor::funcsynopsis/descendant-or-self::*"/>
  237. </xsl:call-template>
  238. </xsl:variable>
  239. <xsl:variable name="style">
  240. <xsl:choose>
  241. <xsl:when test="not($man-funcprototype-style = '')">
  242. <xsl:value-of select="$man-funcprototype-style"/>
  243. </xsl:when>
  244. <xsl:otherwise>
  245. <xsl:value-of select="$man.funcsynopsis.style"/>
  246. </xsl:otherwise>
  247. </xsl:choose>
  248. </xsl:variable>
  249. <xsl:variable name="funcprototype.string.value">
  250. <xsl:value-of select="funcdef"/>
  251. </xsl:variable>
  252. <xsl:variable name="funcprototype">
  253. <xsl:apply-templates select="funcdef"/>
  254. </xsl:variable>
  255. <xsl:call-template name="synopsis-block-start"/>
  256. <xsl:text>.HP </xsl:text>
  257. <xsl:text>\w'</xsl:text>
  258. <xsl:variable name="funcdef">
  259. <xsl:apply-templates select="funcdef"/>
  260. </xsl:variable>
  261. <xsl:call-template name="string.subst">
  262. <xsl:with-param name="string" select="normalize-space($funcdef)"/>
  263. <xsl:with-param name="target" select="' '"/>
  264. <xsl:with-param name="replacement" select="'\ '"/>
  265. </xsl:call-template>
  266. <xsl:text>('u</xsl:text>
  267. <xsl:text>&#10;</xsl:text>
  268. <xsl:text>.</xsl:text>
  269. <xsl:value-of select="$man.font.funcprototype"/>
  270. <xsl:text> </xsl:text>
  271. <!-- * The following quotation mark (and the one further below) are -->
  272. <!-- * needed to properly delimit the parts of the Funcprototype that -->
  273. <!-- * should be rendered in the prevailing font (either Bold or Roman) -->
  274. <!-- * from Parameter output that needs to be alternately rendered in -->
  275. <!-- * italic. -->
  276. <xsl:text>"</xsl:text>
  277. <xsl:value-of select="normalize-space($funcprototype)"/>
  278. <xsl:text>(</xsl:text>
  279. <xsl:choose>
  280. <xsl:when test="not($style = 'ansi')">
  281. <xsl:apply-templates select="*[local-name() != 'funcdef']" mode="kr"/>
  282. </xsl:when>
  283. <xsl:otherwise>
  284. <xsl:apply-templates select="*[local-name() != 'funcdef']" mode="ansi"/>
  285. </xsl:otherwise>
  286. </xsl:choose>
  287. <xsl:text>"</xsl:text>
  288. <xsl:text>&#10;</xsl:text>
  289. <xsl:if test="paramdef and not($style = 'ansi')">
  290. <!-- * if we have any paramdef instances in this funcprototype and -->
  291. <!-- * the user has chosen K&R style output (by specifying some style -->
  292. <!-- * value other than the default 'ansi'), then we need to generate -->
  293. <!-- * the separate list of param definitions for this funcprototype -->
  294. <!-- * -->
  295. <!-- * we put a blank line after the prototype and before the list, -->
  296. <!-- * and we indent the list by whatever width $list-indent is set -->
  297. <!-- * to (4 spaces by default) -->
  298. <xsl:text>.sp&#10;</xsl:text>
  299. <xsl:text>.RS</xsl:text>
  300. <xsl:if test="not($list-indent = '')">
  301. <xsl:text> </xsl:text>
  302. <xsl:value-of select="$list-indent"/>
  303. </xsl:if>
  304. <xsl:text>&#10;</xsl:text>
  305. <xsl:apply-templates select="paramdef" mode="kr-paramdef-list"/>
  306. <xsl:text>.RE&#10;</xsl:text>
  307. </xsl:if>
  308. <xsl:call-template name="synopsis-block-end"/>
  309. </xsl:template>
  310. <xsl:template match="funcdef">
  311. <xsl:apply-templates mode="prevent.line.breaking"/>
  312. </xsl:template>
  313. <xsl:template match="funcdef/function">
  314. <xsl:apply-templates/>
  315. </xsl:template>
  316. <xsl:template match="void" mode="kr">
  317. <xsl:text>);</xsl:text>
  318. </xsl:template>
  319. <xsl:template match="varargs" mode="kr">
  320. <xsl:text>...);</xsl:text>
  321. </xsl:template>
  322. <xsl:template match="void" mode="ansi">
  323. <xsl:text>void);</xsl:text>
  324. </xsl:template>
  325. <xsl:template match="varargs" mode="ansi">
  326. <xsl:text>...);</xsl:text>
  327. </xsl:template>
  328. <xsl:template match="paramdef" mode="kr">
  329. <!-- * in K&R-style output, the prototype just contains the parameter -->
  330. <!-- * names - because the parameter definitions for each parameter -->
  331. <!-- * (including the type information) are displayed in a separate -->
  332. <!-- * list following the prototype; so in this mode (which is for the -->
  333. <!-- * prototype, not the separate list), we first just want to grab -->
  334. <!-- * the parameter for each paramdef -->
  335. <xsl:variable name="contents">
  336. <xsl:apply-templates select="parameter"/>
  337. </xsl:variable>
  338. <xsl:apply-templates mode="prevent.line.breaking" select="exsl:node-set($contents)"/>
  339. <xsl:choose>
  340. <xsl:when test="following-sibling::*">
  341. <xsl:text>, </xsl:text>
  342. </xsl:when>
  343. <xsl:otherwise>
  344. <xsl:text>);</xsl:text>
  345. </xsl:otherwise>
  346. </xsl:choose>
  347. </xsl:template>
  348. <xsl:template match="paramdef" mode="ansi">
  349. <!-- * in ANSI-style output, the prototype contains the complete -->
  350. <!-- * parameter definitions for each parameter (there is no separate -->
  351. <!-- * list of parameter definitions like the one for K&R style -->
  352. <xsl:apply-templates mode="prevent.line.breaking" select="."/>
  353. <xsl:choose>
  354. <xsl:when test="following-sibling::*">
  355. <xsl:text>, </xsl:text>
  356. </xsl:when>
  357. <xsl:otherwise>
  358. <xsl:text>);</xsl:text>
  359. </xsl:otherwise>
  360. </xsl:choose>
  361. </xsl:template>
  362. <xsl:template match="paramdef" mode="kr-paramdef-list">
  363. <!-- * this mode is for generating the separate list of parameter -->
  364. <!-- * definitions in K&R-style output -->
  365. <xsl:text>.br&#10;</xsl:text>
  366. <xsl:text>.</xsl:text>
  367. <xsl:value-of select="$man.font.funcprototype"/>
  368. <xsl:text> </xsl:text>
  369. <!-- * The following quotation mark (and the one further below) are -->
  370. <!-- * needed to properly delimit the parts of the Funcprototype that -->
  371. <!-- * should be rendered in the prevailing font (either Bold or Roman) -->
  372. <!-- * from Parameter output that needs to be alternately rendered in -->
  373. <!-- * italic. -->
  374. <xsl:text>"</xsl:text>
  375. <xsl:variable name="contents">
  376. <xsl:apply-templates/>
  377. </xsl:variable>
  378. <xsl:value-of select="normalize-space($contents)"/>
  379. <xsl:text>;</xsl:text>
  380. <xsl:text>"</xsl:text>
  381. <xsl:text>&#10;</xsl:text>
  382. </xsl:template>
  383. <xsl:template match="paramdef/parameter">
  384. <!-- * We use U+2591 here in place of a normal space, because if we -->
  385. <!-- * were to just use a normal space, it would get replaced with a -->
  386. <!-- * non-breaking space when we run the whole Paramdef through the -->
  387. <!-- * prevent.line.breaking template. And as far as why we're -->
  388. <!-- * inserting the space and quotation marks around each Parameter -->
  389. <!-- * to begin with, the reason is that we need to because we are -->
  390. <!-- * outputting Funcsynopsis in either the "BI" or "RI" font, and -->
  391. <!-- * the space and quotation marks delimit the text as the -->
  392. <!-- * "alternate" or "I" text that needs to be rendered in italic. -->
  393. <xsl:text>"&#x2591;"</xsl:text>
  394. <xsl:apply-templates/>
  395. <xsl:text>"&#x2591;"</xsl:text>
  396. </xsl:template>
  397. <xsl:template match="funcparams">
  398. <xsl:text>(</xsl:text>
  399. <xsl:apply-templates/>
  400. <xsl:text>)</xsl:text>
  401. </xsl:template>
  402. </xsl:stylesheet>