diff options
author | Cameron Cawley | 2019-04-17 22:06:17 +0100 |
---|---|---|
committer | David Turner | 2019-04-18 03:55:22 +0100 |
commit | 50ed922cb7466c25d874260e9c341cfbdb108341 (patch) | |
tree | 2bbbda13bdfe6f6ecf8d745741f2dcbdcafc5106 | |
parent | bcd44e7d95a3d8ceb957b5d611aa35e165a590d8 (diff) | |
download | scummvm-rg350-50ed922cb7466c25d874260e9c341cfbdb108341.tar.gz scummvm-rg350-50ed922cb7466c25d874260e9c341cfbdb108341.tar.bz2 scummvm-rg350-50ed922cb7466c25d874260e9c341cfbdb108341.zip |
RISCOS: Support creating a StrongHelp manual
-rw-r--r-- | backends/platform/sdl/riscos/riscos.mk | 31 | ||||
-rwxr-xr-x | configure | 6 | ||||
-rwxr-xr-x | devtools/credits.pl | 58 | ||||
-rw-r--r-- | dists/riscos/manual/stronghelp.lua | 341 |
4 files changed, 434 insertions, 2 deletions
diff --git a/backends/platform/sdl/riscos/riscos.mk b/backends/platform/sdl/riscos/riscos.mk index 44b49d513d..4fea4d4a3f 100644 --- a/backends/platform/sdl/riscos/riscos.mk +++ b/backends/platform/sdl/riscos/riscos.mk @@ -40,4 +40,35 @@ clean: riscosclean riscosclean: $(RM_REC) $(APP_NAME) +ifdef BINDHELP +ifdef PANDOC + +riscosdist: $(APP_NAME)/docs/ScummVM,3d6 # $(APP_NAME)/docs/de/ScummVM,3d6 $(APP_NAME)/docs/cz/ScummVM,3d6 $(APP_NAME)/se/ScummVM,3d6 + +README=${srcdir}/README.md +NEWS=${srcdir}/NEWS.md +$(APP_NAME)/docs/de/ScummVM,3d6: README=${srcdir}/doc/de/LIESMICH +$(APP_NAME)/docs/de/ScummVM,3d6: NEWS=${srcdir}/doc/de/NEUES +$(APP_NAME)/docs/cz/ScummVM,3d6: README=${srcdir}/doc/cz/PrectiMe +$(APP_NAME)/docs/se/ScummVM,3d6: README=${srcdir}/doc/se/LasMig + +define manual-markdown + echo Converting markdown file '$1' + echo "ScummVM - $(notdir $(basename $1)) " > $(APP_NAME)/tmp/$2,fff + $(PANDOC) -f gfm -t ${srcdir}/dists/riscos/manual/stronghelp.lua $1 | iconv --to-code=$(ENCODING) >> $(APP_NAME)/tmp/$2,fff +endef + +%,3d6: $(README) $(NEWS) ${srcdir}/dists/riscos/manual/stronghelp.lua ${srcdir}/devtools/credits.pl $(DIST_FILES_DOCS) + $(MKDIR) $(APP_NAME)/tmp + @$(call manual-markdown,$(README),!Root) + @$(call manual-markdown,$(NEWS),NEWS) + @$(call manual-markdown,${srcdir}/CONTRIBUTING.md,CONTRIBUTING) + ${srcdir}/devtools/credits.pl --stronghelp > $(APP_NAME)/tmp/AUTHORS,fff + $(MKDIR) $(APP_NAME)/docs + $(BINDHELP) $(APP_NAME)/tmp $@ -r -f + $(RM_REC) $(APP_NAME)/tmp + +endif +endif + .PHONY: riscosdist riscosclean @@ -1851,6 +1851,11 @@ riscos) elif `which tokenize >/dev/null 2>&1`; then add_line_to_config_mk "TOKENIZE := tokenize" fi + if test -e "$GCCSDK_INSTALL_ENV/bin/bindhelp"; then + add_line_to_config_mk "BINDHELP := $GCCSDK_INSTALL_ENV/bin/bindhelp" + elif `which bindhelp >/dev/null 2>&1`; then + add_line_to_config_mk "BINDHELP := bindhelp" + fi ;; tizen) if test -z "$TIZEN_ROOTSTRAP"; then @@ -2892,6 +2897,7 @@ case $_host_os in append_var CXXFLAGS "-fdata-sections" append_var LDFLAGS "-Wl,--gc-sections" _port_mk="backends/platform/sdl/riscos/riscos.mk" + _pandoc=yes ;; solaris*) append_var DEFINES "-DSOLARIS" diff --git a/devtools/credits.pl b/devtools/credits.pl index 59ebb51a07..b1c084515e 100755 --- a/devtools/credits.pl +++ b/devtools/credits.pl @@ -36,11 +36,12 @@ if ($#ARGV >= 0) { $mode = "CPP" if ($ARGV[0] eq "--cpp"); # credits.h (for use by about.cpp) $mode = "XML-DOC" if ($ARGV[0] eq "--xml-docbook"); # credits.xml (DocBook) $mode = "RTF" if ($ARGV[0] eq "--rtf"); # Credits.rtf (Mac OS X About box) + $mode = "STRONGHELP" if ($ARGV[0] eq "--stronghelp"); # AUTHORS (RISC OS StrongHelp manual) } if ($mode eq "") { - print STDERR "Usage: $0 [--text | --xml-website | --cpp | --xml-docbook | --rtf]\n"; - print STDERR " Just pass --text / --xml-website / --cpp / --xml-docbook / --rtf as parameter, and credits.pl\n"; + print STDERR "Usage: $0 [--text | --xml-website | --cpp | --xml-docbook | --rtf | --stronghelp]\n"; + print STDERR " Just pass --text / --xml-website / --cpp / --xml-docbook / --rtf / --stronghelp as parameter, and credits.pl\n"; print STDERR " will print out the corresponding version of the credits to stdout.\n"; exit 1; } @@ -106,6 +107,36 @@ sub html_entities_to_ascii { return $text; } +# Convert HTML entities to ISO/IEC 8859-1 for the StrongHelp manual +sub html_entities_to_iso8859_1 { + my $text = shift; + + $text =~ s/á/\xE1/g; + $text =~ s/é/\xE9/g; + $text =~ s/í/\xED/g; + $text =~ s/ì/\xEC/g; + $text =~ s/ó/\xF3/g; + $text =~ s/ø/\xF8/g; + $text =~ s/ú/\xFA/g; + $text =~ s/ą/a/g; + $text =~ s/Ł/L/g; + $text =~ s/ł/l/g; + $text =~ s/ś/s/g; + $text =~ s/Ľ/L/g; + $text =~ s/Š/S/g; + $text =~ s/å/\xE5/g; + $text =~ s/ñ/\xF1/g; + + $text =~ s/ä/\xE4/g; + $text =~ s/ë/\xEB/g; + $text =~ s/ü/\xFC/g; + $text =~ s/ö/\xF6/g; + + $text =~ s/&/&/g; + + return $text; +} + # Convert HTML entities to C++ characters sub html_entities_to_cpp { my $text = shift; @@ -219,6 +250,9 @@ sub begin_credits { print "<?xml version='1.0'?>\n"; print "<!-- This file was generated by credits.pl. Do not edit by hand! -->\n"; print "<credits>\n"; + } elsif ($mode eq "STRONGHELP") { + print "ScummVM - AUTHORS\n"; + print "# This file was generated by credits.pl. Do not edit by hand!\n"; } } @@ -314,6 +348,9 @@ sub begin_section { #print "\t\t\t<group>" . $title . "</group>\n"; #print "\t\t\t\t<name>" . $title . "</name>\n"; } + } elsif ($mode eq "STRONGHELP") { + $title = html_entities_to_iso8859_1($title); + print "#fH" . ($section_level + 1) . ":" . $title."\n"; } # Implicit start of person list on section level 2 @@ -369,6 +406,8 @@ sub end_persons { } elsif ($mode eq "XML-WEB") { #print "\t\t\t\t</persons>\n"; print "\t\t\t</group>\n"; + } elsif ($mode eq "STRONGHELP") { + print "\n"; } } @@ -443,6 +482,15 @@ sub add_person { print "\t\t\t\t\t<alias>" . $nick . "</alias>\n"; print "\t\t\t\t\t<description>" . $desc . "</description>\n"; print "\t\t\t\t</person>\n"; + } elsif ($mode eq "STRONGHELP") { + my $min_name_width = length $desc > 0 ? $max_name_width : 0; + $name = $nick if $name eq ""; + $name = html_entities_to_iso8859_1($name); + $desc = html_entities_to_iso8859_1($desc); + + $tab = " " x ($section_level * 2 + 1); + print $tab . "{*}" . $name . "{*}"; + print "\t" . $desc . "\n"; } } @@ -471,6 +519,12 @@ sub add_paragraph { print " <row><entry namest='start' nameend='job'> </entry></row>\n\n"; } elsif ($mode eq "XML-WEB") { print "\t\t<paragraph>" . $text . "</paragraph>\n"; + } elsif ($mode eq "STRONGHELP") { + $text = html_entities_to_iso8859_1($text); + print "#Wrap On\n"; + $tab = " " x ($section_level * 2 + 1); + print $text . "\n"; + print "#Wrap\n\n"; } } diff --git a/dists/riscos/manual/stronghelp.lua b/dists/riscos/manual/stronghelp.lua new file mode 100644 index 0000000000..ef17589dd7 --- /dev/null +++ b/dists/riscos/manual/stronghelp.lua @@ -0,0 +1,341 @@ +-- This is a custom writer for pandoc. It produces output suitable +-- for use in a StrongHelp manual. Not all functionalilty is currently +-- implemented. +-- +-- Invoke with: pandoc -t stronghelp.lua +-- +-- Note: you need not have lua installed on your system to use this +-- custom writer. However, if you do have lua installed, you can +-- use it to test changes to the script. 'lua stronghelp.lua' will +-- produce informative error messages if your code contains +-- syntax errors. + +-- Character escaping +local function escape(s, in_attribute) + return s:gsub("[<>$\\]", + function(x) + if x == '<' then + return '\\<' + elseif x == '>' then + return '\\>' + elseif x == '$' then + return '\\$' + elseif x == '\\' then + return '\\\\' + else + return x + end + end) +end + +local function convertPath(s) + local path = s:gsub("[./]", + function(x) + if x == '.' then + return '/' + elseif x == '/' then + return '.' + else + return x + end + end) + path = string.gsub(path, "/md", "") + return path; +end + +-- Helper function to convert an attributes table into +-- a string that can be put into HTML tags. +local function attributes(attr) + local attr_table = {} + for x,y in pairs(attr) do + if y and y ~= "" then + table.insert(attr_table, ' ' .. x .. '="' .. escape(y,true) .. '"') + end + end + return table.concat(attr_table) +end + +-- Helper function to look up an attribute by name from +-- an attributes table. +-- TODO: Is this necessary? +local function getattribute(attr, name) + local attr_table = {} + for x,y in pairs(attr) do + if x == name then + do return escape(y,true) end + end + end + return "" +end + +-- Table to store footnotes, so they can be included at the end. +local notes = {} + +-- Blocksep is used to separate block elements. +function Blocksep() + return "\n\n" +end + +-- This function is called once for the whole document. Parameters: +-- body is a string, metadata is a table, variables is a table. +-- This gives you a fragment. You could use the metadata table to +-- fill variables in a custom lua template. Or, pass `--template=...` +-- to pandoc, and pandoc will add do the template processing as +-- usual. +function Doc(body, metadata, variables) + local buffer = {} + local function add(s) + table.insert(buffer, s) + end + add(body) + if #notes > 0 then + for _,note in pairs(notes) do + add(note) + end + end + return "#Indent +4\n" .. table.concat(buffer, "") .. "\n#Indent\n" +end + +-- The functions that follow render corresponding pandoc elements. +-- s is always a string, attr is always a table of attributes, and +-- items is always an array of strings (the items in a list). +-- Comments indicate the types of other variables. + +function Str(s) + return escape(s) +end + +function Space() + return " " +end + +function SoftBreak() + return " " +end + +function LineBreak() + return "\n" +end + +function Emph(s) + return "{/}" .. s .. "{/}" +end + +function Strong(s) + return "{*}" .. s .. "{*}" +end + +function Subscript(s) + -- TODO + return s +end + +function Superscript(s) + -- TODO + return s +end + +function SmallCaps(s) + -- TODO + return s +end + +function Strikeout(s) + -- TODO + return s +end + +function Link(s, src, tit, attr) + -- escape(tit,true) + if string.find(src, "://") or string.find(src, "mailto:") then + return "<" .. s .. "=>#URL " .. escape(src,true) .. ">" + elseif string.sub(src, 1, 1) == '#' then + return "<" .. s .. "=>#TAG " .. escape(string.sub(src,2),true) .. ">" + else + return "<" .. s .. "=>" .. convertPath(escape(src,true)) .. ">" + end +end + +function Image(s, src, tit, attr) + -- TODO + return s +end + +function Code(s, attr) + return "{FCode}" .. escape(s) .. "{F}" +end + +function InlineMath(s) + return "\\(" .. escape(s) .. "\\)" +end + +function DisplayMath(s) + return "\\[" .. escape(s) .. "\\]" +end + +function SingleQuoted(s) + return "'" .. s .. "'" +end + +function DoubleQuoted(s) + return '"' .. s .. '"' +end + + +function Note(s) + local num = #notes + 1 + -- add a list item with the note to the note table. + table.insert(notes, '#Tag fn' .. num .. '\n' .. num .. ")\t" .. s .. '\n') + -- return the footnote reference, linked to the note. + return '<[' .. num .. ']=>#TAG fn' .. num .. '>' +end + +function Span(s, attr) + -- TODO + return s +end + +function RawInline(format, str) + -- TODO + return '' +end + +function Cite(s, cs) + -- TODO + return s +end + +function Plain(s) + return s +end + +function Para(s) + return s +end + +-- lev is an integer, the header level. +function Header(lev, s, attr) + return "#Tag " .. getattribute(attr, "id") .. "\n" .. "#fH" .. lev .. "\n" .. s .. "\n#f\n" +end + +function BlockQuote(s) + return "#Indent +6\n" .. s .. "\n#Indent\n" +end + +function HorizontalRule() + return "#Line\n" +end + +function LineBlock(ls) + -- TODO + return table.concat(ls, '\n') +end + +function CodeBlock(s, attr) + -- TODO: attr.class and string.match(' ' .. attr.class .. ' ',' dot ') + return "#fCode\n" .. escape(s) .. "\n#f" +end + +function BulletList(items) + local buffer = {} + for _, item in pairs(items) do + table.insert(buffer, " •\t" .. string.gsub(string.gsub(item, "\n", "\n\t"), "\n\t#", "\n#") .. "\n") + end + return "#Indent +4\n" .. table.concat(buffer, "") .. "#Indent\n" +end + +function OrderedList(items) + local buffer = {} + for _, item in pairs(items) do + table.insert(buffer, _ .. ")\t" .. string.gsub(string.gsub(item, "\n", "\n\t"), "\n\t#", "\n#") .. "\n") + end + return "#Indent +4\n" .. table.concat(buffer, "") .. "#Indent\n" +end + +function DefinitionList(items) + local buffer = {} + for _,item in pairs(items) do + local k, v = next(item) + table.insert(buffer, k .. "\t" .. table.concat(v,"\n\t") .. "\n") + end + return "#Indent +4\n" .. table.concat(buffer, "") .. "#Indent\n" +end + +-- Convert pandoc alignment to something StrongHelp can use. +-- align is AlignLeft, AlignRight, AlignCenter, or AlignDefault. +function stronghelp_align(align) + if align == 'AlignLeft' then + return 'Left' + elseif align == 'AlignRight' then + return 'Right' + elseif align == 'AlignCenter' then + return 'Centre' + else + return 'Left' + end +end + +function CaptionedImage(src, tit, caption, attr) + -- TODO + return tit .. '\n' .. caption .. '\n' +end + +-- Caption is a string, aligns is an array of strings, +-- widths is an array of floats, headers is an array of +-- strings, rows is an array of arrays of strings. +function Table(caption, aligns, widths, headers, rows) + local buffer = {} + local function add(s) + table.insert(buffer, s) + end + add("#Tab\n") + if caption ~= "" then + add(caption .. "\n") + end + local header_row = {} + local empty_header = true + for i, h in pairs(headers) do + table.insert(header_row,h .. '\t') + empty_header = empty_header and h == "" + end + if empty_header then + head = "" + else + local cells = {} + for _,h in pairs(header_row) do + table.insert(cells, h) + end + add('{*}' .. table.concat(cells,'\t') .. '{*}\n') + end + for _, row in pairs(rows) do + local cells = {} + for i,c in pairs(row) do + table.insert(cells, c) + end + add(table.concat(cells,'\t') .. '\n') + end + add("#Tab\n") + return table.concat(buffer,'') +end + +function RawBlock(format, str) + -- TODO + return '' +end + +function Div(s, attr) + -- TODO + return s +end + +-- The following code will produce runtime warnings when you haven't defined +-- all of the functions you need for the custom writer, so it's useful +-- to include when you're working on a writer. +local meta = {} +meta.__index = + function(_, key) + io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) + return function() return "" end + end +setmetatable(_G, meta) + |