#!xsh # -*- cperl -*- if ("$xsh_grammar_file" = "") $xsh_grammar_file="src/xsh_grammar.xml"; if ("$db_stylesheet" = "") { # weired things happen in XML::LibXML/LibXSLT with new stylesheets! # $db_stylesheet="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"; perl { ($db_stylesheet)=split(/\n/,`locate html/docbook.xsl`); }; echo "Using DocBook XML stylesheet: $db_stylesheet" } if ("$db_stylesheet" = "") { echo "Cannot find docbook.xsl stylesheets! Exiting." exit 1; } if ("$html_stylesheet"="") $html_stylesheet="style.css"; quiet; load-ext-dtd 1; validation 1; parser-completes-attributes 1; open X = $xsh_grammar_file; validation 0; indent 1; def transform_section { map { s/^[ \t]+//; s/\n[ \t]+/\n/g; } %section//code/descendant::text(); foreach %section//code/descendant::tab { perl { $ws=' ' x count('string(@count)'); }; insert text $ws instead of .; } map { $_='programlisting' } %section//code; foreach %section//xref { $linkend=string(@linkend); foreach X:(id("$linkend")) { if (name()='section') { $content=string(title); } else { if (@name) { $content=string(@name); } else { $content="$linkend"; } } } add chunk "$content" replace .; }; foreach %section//link { map { $_='ulink' } .; add attribute url=${{string(@linkend)}} replace @linkend; map { $_="s_".$_.".html" } @url; } xslt S $db_stylesheet H params html.stylesheet="'$html_stylesheet'"; clone H=H; xadd attribute target=_self into H://*[name()='a']; # move content of .. out, so that it does not behave # as a link in browsers foreach H://*[name()='a' and not(@href)] { xmove ./node() after .; } for %section/@id { save_HTML H "doc/frames/s_${{string(.)}}.html"; saveas S "doc/frames/s_${{string(.)}}.xml"; } close H; } $toc_template=" Table of contents

XSH Reference

Syntax
Commands
Argument types

"; new I " XSH Reference <body> <p>XSH Reference - XSH is an XML Editing Shell</p> <small>Your browser must support frames to display this page correctly!</small> </body> "; save_HTML I 'doc/frames/index.html'; close I; new S "
Getting Started
"; %section=S://section; xcopy X:/recdescent-xml/doc/description/node() into %section; call transform_section; close S; # SYNTAX TOC new T $toc_template; for T:(/html/body/font/a[contains(@href,'syntax')]) { add chunk "" before .; move . into preceding-sibling::u/b; } add chunk "Getting started
" into T:/html/body/small; foreach X:/recdescent-xml/doc/section { $id=string(@id); add chunk "${{string(title)}}
" into T:/html/body/small; for (.) { # avoid selecting S:/ new S "
"; %section=S:section; } xcopy ./node() into %section; %rules=X:(/recdescent-xml/rules/rule[documentation[id(@sections)[@id='$id']]]); if %rules[@type='command'] { $c='Commands' } else { $c='' } if %rules[@type='argtype'] { $a='Argument Types' } else { $a='' } if ('$c' != '' and '$a' != '') { $t='$a and $c' } else { $t='$a$c' } if ('$a$c' != '') add chunk " Related $t " into %section; sort (@name|@id) { $a cmp $b } %rules; foreach %rules { add chunk " " into %section/simplesect[last()]/variablelist; xcopy ./documentation/shortdesc/node() into %section/simplesect[last()]/variablelist/varlistentry[last()]/listitem; } call transform_section; } save_HTML T "doc/frames/t_syntax.html"; close T; # COMMANDS AND TYPES foreach { qw(command type) } { new T $toc_template; for T:(/html/body/font/a[contains(@href,'$__')]) { add chunk "" before .; move . into preceding-sibling::u/b; } if ('$__'='type') $__='argtype'; %rules=X:(//rule[@type='$__']); sort (documentation/title|@name|@id) { lc($a) cmp lc($b) } %rules; foreach %rules { $ref=string(@id); new S "
"; cd X:id('$ref'); %section=S:section; # TITLE if (./documentation/title) { xcopy ./documentation/title into %section; } else { add chunk "${{string(@name)}}" into %section; } map { s/\s+argument\s+type//i; $_=lcfirst } %section/title/text(); for %section/title { add chunk "${{string(.)}}
" into T:/html/body/small; } if ('$__'='argtype') { $t = 'argument type' } else { $t = 'command' } insert text " $t" into %section/title; #USAGE if (./documentation/usage) { add chunk "Usage" into %section; foreach (./documentation/usage) { add element para into %section/simplesect[last()]; } copy ./documentation/usage into %section/simplesect[last()]/para; map { $_='literal' } %section/simplesect[last()]/para/usage; } #ALIASES if (./aliases/alias) { add chunk "Aliases " into %section; foreach (./aliases/alias) { copy ./@name append %section/simplesect[last()]/para/literal/text()[last()]; if (following-sibling::alias) { add text ", " append %section/simplesect[last()]/para/literal/text()[last()];; } } } #DESCRIPTION if (./documentation/description) { add chunk "Description" into %section; xcopy ./documentation/description/node() into %section/simplesect[last()]; } #SEE ALSO if (./documentation/see-also/ruleref) { add chunk "See Also" into %section; foreach (./documentation/see-also/ruleref) { add element "" into %section/simplesect[last()]/para; if (following-sibling::ruleref) { add text ", " into %section/simplesect[last()]/para; } } } #SECTIONS if (./documentation/@sections) { add chunk "Sections" into %section; $s=string(./documentation/@sections); foreach { split /\s+/, $s } { add chunk "" into %section/simplesect[last()]/para; }; foreach %section/simplesect[last()]/para/xref { if (following-sibling::xref) { add text ", " after . ; } } } call transform_section; close S; } save_HTML T "doc/frames/t_${__}.html"; close T; };