- Timestamp:
- Jun 3, 2015 11:24:53 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 100793
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/docbook-refentry-to-C-help.xsl
r56208 r56231 40 40 <xsl:template match="refentry"> 41 41 <!-- Assert refetry expectations. --> 42 <xsl:if test="not(./refsynopsisdiv)"><xsl:message terminate="yes">refentry must have a refsynopsisdiv</xsl:message></xsl:if> 43 <xsl:if test="not(./refsect1/title)"><xsl:message terminate="yes">refentry must have a refsynopsisdiv</xsl:message></xsl:if> 44 <xsl:if test="not(@id) or @id = ''"><xsl:message terminate="yes">refentry must have an id attribute</xsl:message></xsl:if> 42 <xsl:if test="not(./refsynopsisdiv)"> <xsl:message terminate="yes">refentry must have a refsynopsisdiv</xsl:message></xsl:if> 43 <xsl:if test="not(./refentryinfo/title)"> <xsl:message terminate="yes">refentry must have a refentryinfo with title</xsl:message></xsl:if> 44 <xsl:if test="not(./refsect1/title)"> <xsl:message terminate="yes">refentry must have a refsect1 with title</xsl:message></xsl:if> 45 <xsl:if test="not(@id) or @id = ''"> <xsl:message terminate="yes">refentry must have an id attribute</xsl:message></xsl:if> 45 46 46 47 <!-- variables --> 47 48 <xsl:variable name="sBaseId" select="@id"/> 48 49 <xsl:variable name="sDataBaseSym" select="concat('g_', translate(@id, '-', '_'))"/> 50 49 51 50 52 <!-- … … 65 67 66 68 <!-- Do the work. --> 67 <xsl:text> 69 <xsl:apply-templates select="."/> 70 71 </xsl:for-each> 72 <xsl:text> 73 };</xsl:text> 74 75 76 <!-- 77 Convert the whole manpage to help text. 78 --> 79 <xsl:text> 80 static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] = 81 {</xsl:text> 82 <!-- We start by combining the refentry title and the refpurpose into a short description. --> 83 <xsl:text> 68 84 { </xsl:text><xsl:call-template name="calc-scope"/><xsl:text>, 69 85 "</xsl:text> 70 <xsl:apply-templates select="."/> 71 <xsl:text>" }, 72 </xsl:text> 86 <xsl:apply-templates select="./refentryinfo/title/node()"/> 87 <xsl:text> -- </xsl:text> 88 <xsl:call-template name="capitalize"> 89 <xsl:with-param name="text"> 90 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/> 91 </xsl:with-param> 92 </xsl:call-template> 93 <xsl:text>." }, 94 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text> 95 96 <!-- The follows the usage (synopsis) section. --> 97 <xsl:text> 98 { REFENTRYSTR_SCOPE_GLOBAL, 99 "Usage:" },</xsl:text> 100 <xsl:apply-templates select="./refsynopsisdiv/node()"/> 101 102 <!-- Then comes the description and other refsect1 --> 103 <xsl:for-each select="./refsect1"> 104 <xsl:if test="name(*[1]) != 'title'"><xsl:message terminate="yes">Expected title as the first element in refsect1.</xsl:message></xsl:if> 105 <xsl:if test="text()"><xsl:message terminate="yes">No text supported in refsect1.</xsl:message></xsl:if> 106 <xsl:if test="not(./remark[@role='help-skip'])"> 107 <xsl:text> 108 { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" }, 109 { REFENTRYSTR_SCOPE_SAME, 110 "</xsl:text><xsl:apply-templates select="title/node()"/><xsl:text>:" },</xsl:text> 111 <xsl:apply-templates select="./*[position() > 1]"/> 112 </xsl:if> 73 113 </xsl:for-each> 74 <xsl:text> 114 115 <xsl:text> 116 };</xsl:text> 117 118 <!-- 119 Generate the refentry structure. 120 --> 121 <xsl:text> 122 static const REFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> = 123 { 124 /* .idinternal = */ HELP_CMD_</xsl:text> 125 <xsl:call-template name="str:to-upper"> 126 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/> 127 </xsl:call-template> 128 <xsl:text>, 129 /* .Synopsis = */ { </xsl:text> 130 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis, RT_ELEMENTS(</xsl:text> 131 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis) }, 132 /* .Help = */ { </xsl:text> 133 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help, RT_ELEMENTS(</xsl:text> 134 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help) }, 135 /* pszBrief = */ "</xsl:text> 136 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/> 137 <xsl:text>" 75 138 }; 76 139 </xsl:text> 140 </xsl:template> 141 142 143 <!-- 144 Convert command synopsis to text. 145 --> 146 <xsl:template match="cmdsynopsis"> 147 <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if> 148 <xsl:text> 149 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text>, 150 "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text> 151 </xsl:template> 152 153 <xsl:template match="sbr"> 154 <xsl:text>" }, 155 { REFENTRYSTR_SCOPE_SAME, 156 " </xsl:text><xsl:call-template name="emit-indentation"/> 157 </xsl:template> 158 159 <xsl:template match="command|option|computeroutput"> 160 <xsl:apply-templates select="node()|@*"/> 161 </xsl:template> 162 163 <xsl:template match="replaceable"> 164 <xsl:text><</xsl:text> 165 <xsl:apply-templates select="node()|@*"/> 166 <xsl:text>></xsl:text> 167 </xsl:template> 168 169 <xsl:template match="arg|group"> 170 <!-- separator char if we're not the first child --> 171 <xsl:if test="position() > 1"> 172 <xsl:choose> 173 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when> 174 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise> 175 </xsl:choose> 176 </xsl:if> 177 <!-- open wrapping --> 178 <xsl:choose> 179 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when> 180 <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when> 181 <xsl:when test="@choice = 'plain'"/> 182 <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise> 183 </xsl:choose> 184 <!-- render the arg (TODO: may need to do more work here) --> 185 <xsl:apply-templates select="node()|@*"/> 186 <!-- repeat wrapping --> 187 <xsl:choose> 188 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/> 189 <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when> 190 <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise> 191 </xsl:choose> 192 <!-- close wrapping --> 193 <xsl:choose> 194 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when> 195 <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when> 196 </xsl:choose> 197 </xsl:template> 198 199 200 <!-- 201 refsect2 202 --> 203 <xsl:template match="refsect2"> 204 <!-- assertions --> 205 <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if> 206 <xsl:if test="count(./cmdsynopsis) > 1"><xsl:message terminate="yes">Only a single cmdsynopsis is currently supported in a refsect2.</xsl:message></xsl:if> 207 <xsl:if test="count(./title) > 1"><xsl:message terminate="yes">Only a single title in refsect2</xsl:message></xsl:if> 208 209 <!-- title / command synopsis - sets the scope. --> 210 <xsl:text> 211 { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, 212 "</xsl:text><xsl:call-template name="emit-indentation"/> 213 <xsl:choose> 214 <xsl:when test="name(./*[1]) = 'cmdsynopsis'"> 215 <xsl:text> </xsl:text> 216 <xsl:apply-templates select="./cmdsynopsis/node()|./cmdsynopsis/@*"/> 217 </xsl:when> 218 <xsl:when test="name(./*[1]) = 'title'"> 219 <xsl:apply-templates select="./title/text()"/> 220 </xsl:when> 221 <xsl:otherwise> 222 <xsl:message terminate="yes">Expected either a title or cmdsynopsis as the first element in a refsect2. 223 (Put scoping remarks after.)</xsl:message> 224 </xsl:otherwise> 225 </xsl:choose> 226 <xsl:text>" },</xsl:text> 227 228 <!-- Format the text in the section --> 229 <xsl:apply-templates select="./*[position() > 1]"/> 230 231 <!-- Add a blank line, unless we're the last element in this refsect1. --> 232 <xsl:if test="position() != last()"> 233 <xsl:text> 234 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text> 235 </xsl:if> 236 </xsl:template> 237 238 239 <!-- 240 para 241 --> 242 <xsl:template match="para"> 243 <xsl:if test="position() != 1 or not(parent::listitem)"> 244 <xsl:text> 245 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text> 246 </xsl:if> 247 <xsl:call-template name="process-mixed"/> 248 </xsl:template> 249 250 251 <!-- 252 variablelist 253 --> 254 <xsl:template match="variablelist"> 255 <xsl:if test="*[not(self::varlistentry)]|text()"> 256 <xsl:message terminate="yes">Only varlistentry elements are supported in variablelist</xsl:message> 257 </xsl:if> 258 <xsl:for-each select="./varlistentry"> 259 <xsl:if test="count(*) != 2 or not(term) or not(listitem)"> 260 <xsl:message terminate="yes">Expected exactly one term and one listentry member in varlistentry element.</xsl:message> 261 </xsl:if> 262 <xsl:apply-templates select="*"/> 263 </xsl:for-each> 264 </xsl:template> 265 266 <xsl:template match="varlistentry/term"> 267 <xsl:call-template name="process-mixed"/> 268 </xsl:template> 269 270 <xsl:template match="varlistentry/listitem"> 271 <xsl:if test="text() or *[not(self::para)]"> 272 <xsl:message terminate="yes">Expected varlistentry/listitem to only contain para elements</xsl:message> 273 </xsl:if> 274 <xsl:apply-templates select="*"/> 275 </xsl:template> 276 277 278 <!-- 279 Text escaping for C. 280 --> 281 <xsl:template match="text()" name="escape_text"> 282 <xsl:choose> 283 284 <xsl:when test="contains(., '\') or contains(., '"')"> 285 <xsl:variable name="sTmp"> 286 <xsl:call-template name="str:subst"> 287 <xsl:with-param name="text" select="normalize-space(.)"/> 288 <xsl:with-param name="replace" select="'\'"/> 289 <xsl:with-param name="with" select="'\\'"/> 290 <xsl:with-param name="disable-output-escaping" select="yes"/> 291 </xsl:call-template> 292 </xsl:variable> 293 <xsl:call-template name="str:subst"> 294 <xsl:with-param name="text" select="$sTmp"/> 295 <xsl:with-param name="replace" select="'"'"/> 296 <xsl:with-param name="with" select="'\"'"/> 297 <xsl:with-param name="disable-output-escaping" select="yes"/> 298 </xsl:call-template> 299 </xsl:when> 300 301 <xsl:otherwise> 302 <xsl:value-of select="normalize-space(.)"/> 303 </xsl:otherwise> 304 </xsl:choose> 305 </xsl:template> 306 307 <!-- Elements producing non-breaking strings (single line). --> 308 <xsl:template match="command/text()|option/text()|computeroutput/text()" name="escape_fixed_text"> 309 <xsl:choose> 310 311 <xsl:when test="contains(., '\') or contains(., '"')"> 312 <xsl:variable name="sTmp1"> 313 <xsl:call-template name="str:subst"> 314 <xsl:with-param name="text" select="."/> 315 <xsl:with-param name="replace" select="'\'"/> 316 <xsl:with-param name="with" select="'\\'"/> 317 <xsl:with-param name="disable-output-escaping" select="yes"/> 318 </xsl:call-template> 319 </xsl:variable> 320 <xsl:variable name="sTmp2"> 321 <xsl:call-template name="str:subst"> 322 <xsl:with-param name="text" select="$sTmp1"/> 323 <xsl:with-param name="replace" select="'"'"/> 324 <xsl:with-param name="with" select="'\"'"/> 325 <xsl:with-param name="disable-output-escaping" select="yes"/> 326 </xsl:call-template> 327 </xsl:variable> 328 <xsl:call-template name="str:subst"> 329 <xsl:with-param name="text" select="$sTmp2"/> 330 <xsl:with-param name="replace" select="' '"/> 331 <xsl:with-param name="with" select="'\b'"/> 332 <xsl:with-param name="disable-output-escaping" select="yes"/> 333 </xsl:call-template> 334 </xsl:when> 335 336 <xsl:when test="contains(., ' ')"> 337 <xsl:call-template name="str:subst"> 338 <xsl:with-param name="text" select="."/> 339 <xsl:with-param name="replace" select="' '"/> 340 <xsl:with-param name="with" select="'\b'"/> 341 <xsl:with-param name="disable-output-escaping" select="yes"/> 342 </xsl:call-template> 343 </xsl:when> 344 345 <xsl:otherwise> 346 <xsl:value-of select="."/> 347 </xsl:otherwise> 348 </xsl:choose> 349 </xsl:template> 350 351 352 <!-- 353 Unsupported elements and elements handled directly. 354 --> 355 <xsl:template match="synopfragment|synopfragmentref|title|refsect1"> 356 <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message> 357 </xsl:template> 358 359 <!-- 360 Fail on misplaced scoping remarks. 361 --> 362 <xsl:template match="remark[@role = 'help-scope']"> 363 <xsl:choose> 364 <xsl:when test="parent::refsect1"/> 365 <xsl:when test="parent::refsect2"/> 366 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/> 367 <xsl:otherwise> 368 <xsl:message terminate="yes">Misplaced remark/@role=help-scope element. 369 Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message> 370 </xsl:otherwise> 371 </xsl:choose> 372 </xsl:template> 373 374 <!-- 375 Warn about unhandled elements 376 --> 377 <xsl:template match="*"> 378 <xsl:message terminate="no">Warning: Unhandled element: <xsl:value-of select="name(.)"/></xsl:message> 77 379 </xsl:template> 78 380 … … 83 385 Functions 84 386 --> 387 388 <!-- 389 Processes mixed children, i.e. both text and regular elements. 390 Normalizes whitespace. --> 391 <xsl:template name="process-mixed"> 392 <xsl:text> 393 { REFENTRYSTR_SCOPE_SAME, 394 "</xsl:text><xsl:call-template name="emit-indentation"/> 395 396 <xsl:for-each select="node()[not(self::remark)]"> 397 <xsl:if test="position() != 1"> 398 <xsl:text> </xsl:text> 399 </xsl:if> 400 <xsl:choose> 401 <xsl:when test="name() = ''"> 402 <xsl:call-template name="escape_text"/> 403 </xsl:when> 404 <xsl:otherwise> 405 <xsl:apply-templates select="."/> 406 </xsl:otherwise> 407 </xsl:choose> 408 </xsl:for-each> 409 410 <xsl:text>" },</xsl:text> 411 </xsl:template> 412 413 414 <!-- TODO: scoping must be reworked! --> 415 <!-- Figures out the scope of a refsect1 element. --> 416 <xsl:template name="calc-scope-refsect1"> 417 <xsl:choose> 418 <xsl:when test="title[text() = 'Description']"> 419 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text> 420 </xsl:when> 421 <xsl:otherwise> 422 <xsl:call-template name="calc-scope"/> 423 </xsl:otherwise> 424 </xsl:choose> 425 </xsl:template> 426 427 <!-- Figures out the scope of a refsect2 element. --> 428 <xsl:template name="calc-scope-refsect2"> 429 <xsl:choose> 430 <xsl:when test="0"> 431 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text> 432 </xsl:when> 433 <xsl:otherwise> 434 <xsl:call-template name="calc-scope"/> 435 </xsl:otherwise> 436 </xsl:choose> 437 </xsl:template> 438 439 <!-- Figures out the scope of a refsect1 element. --> 440 <xsl:template name="calc-scope-cmdsynopsis"> 441 <xsl:choose> 442 <xsl:when test="ancestor::refsynopsisdiv"> 443 <xsl:call-template name="calc-scope"/> 444 </xsl:when> 445 <xsl:otherwise> 446 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text> 447 </xsl:otherwise> 448 </xsl:choose> 449 </xsl:template> 85 450 86 451 <!-- Figures out the scope of an element. --> … … 88 453 <xsl:param name="a_Element" select="."/> 89 454 <xsl:param name="a_cRecursions" select="'1'"/> 455 <xsl:variable name="ScopeRemark" select="$a_Element/remark[@role='help-scope']"/> 90 456 91 457 <xsl:choose> 92 458 <!-- Check for an explicit scope remark: <remark role='scope' condition='uninstall'/> --> 93 <xsl:when test="$ a_Element/remark[@role='scope']">94 <xsl:if test="not($ a_Element/remark[@role='scope']/@condition)">459 <xsl:when test="$ScopeRemark"> 460 <xsl:if test="not($ScopeRemark/@condition)"> 95 461 <xsl:message terminate="yes">remark[role=scope] element must have a condition attribute.</xsl:message> 96 462 </xsl:if> 463 97 464 <xsl:call-template name="calc-scope-const"> 98 <xsl:with-param name="sId" select="concat(concat(ancestor::refentry[1]/@id, '-'), 99 $a_Element/remark[@role='scope']/@condition)"/> 465 <xsl:with-param name="sId" select="concat(concat(ancestor::refentry[1]/@id, '-'), $ScopeRemark/@condition)"/> 100 466 </xsl:call-template> 101 467 </xsl:when> … … 136 502 </xsl:call-template> 137 503 </xsl:variable> 138 <xsl:text>HELP_ </xsl:text>504 <xsl:text>HELP_SCOPE_</xsl:text> 139 505 <xsl:value-of select="$sTmp2"/> 140 506 </xsl:template> 141 507 142 143 <!-- 144 To text conversions. 145 --> 146 <xsl:template match="cmdsynopsis"> 147 <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if> 148 <xsl:text> </xsl:text> 149 <xsl:apply-templates select="node()|@*"/> 150 </xsl:template> 151 152 <xsl:template match="command"> 153 <!--xsl:choose> 154 <xsl:when test=" "> 155 </xsl:choose--> 156 <xsl:apply-templates select="node()|@*"/> 157 </xsl:template> 158 159 <xsl:template match="replaceable"> 160 <xsl:text><</xsl:text> 161 <xsl:apply-templates select="text()|node()|@*"/> 162 <xsl:text>></xsl:text> 163 </xsl:template> 164 165 <xsl:template match="arg|group"> 166 <!-- separator char if we're not the first child --> 167 <xsl:if test="position() > 1"> 168 <xsl:choose> 169 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when> 170 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise> 171 </xsl:choose> 172 </xsl:if> 173 <!-- open wrapping --> 174 <xsl:choose> 175 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when> 176 <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when> 177 <xsl:when test="@choice = 'plain'"/> 178 <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise> 179 </xsl:choose> 180 <!-- render the arg (TODO: may need to do more work here) --> 181 <xsl:apply-templates /> 182 <!-- repeat wrapping --> 183 <xsl:choose> 184 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/> 185 <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when> 186 <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise> 187 </xsl:choose> 188 <!-- close wrapping --> 189 <xsl:choose> 190 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when> 191 <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when> 192 </xsl:choose> 193 </xsl:template> 194 195 <!-- non-breaking strings --> 196 <xsl:template match="command/text()"> 197 <xsl:call-template name="str:subst"> 198 <xsl:with-param name="text" select="."/> 199 <xsl:with-param name="replace" select="' '"/> 200 <xsl:with-param name="with" select="'\b'"/> 201 <xsl:with-param name="disable-output-escaping" select="yes"/> 508 <!-- Calculates and emits indentation. --> 509 <xsl:template name="emit-indentation"> 510 <xsl:if test="ancestor::refsect1"> 511 <xsl:text> </xsl:text> 512 </xsl:if> 513 <xsl:if test="ancestor::refsect2"> 514 <xsl:text> </xsl:text> 515 </xsl:if> 516 <xsl:if test="ancestor::refsect3"> 517 <xsl:text> </xsl:text> 518 </xsl:if> 519 <xsl:if test="ancestor::varlistentry"> 520 <xsl:if test="ancestor-or-self::term"> 521 <xsl:text> </xsl:text> 522 </xsl:if> 523 <xsl:if test="ancestor-or-self::listitem"> 524 <xsl:text> </xsl:text> 525 </xsl:if> 526 </xsl:if> 527 </xsl:template> 528 529 <!-- Captializes the given text. --> 530 <xsl:template name="capitalize"> 531 <xsl:param name="text"/> 532 <xsl:call-template name="str:to-upper"> 533 <xsl:with-param name="text" select="substring($text,1,1)"/> 202 534 </xsl:call-template> 203 </xsl:template>204 535 <xsl:value-of select="substring($text,2)"/> 536 </xsl:template> 205 537 206 538 </xsl:stylesheet>
Note:
See TracChangeset
for help on using the changeset viewer.