diff options
Diffstat (limited to 'src/sisudoc/spine.d')
| -rw-r--r-- | src/sisudoc/spine.d | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/sisudoc/spine.d b/src/sisudoc/spine.d index 17950d0..9ceb069 100644 --- a/src/sisudoc/spine.d +++ b/src/sisudoc/spine.d @@ -213,6 +213,7 @@ string program_name = "spine"; ]; string[string] settings = [ "output" : "", + "ssp-round-trip" : "", "www-http" : "", "www-host" : "", "www-host-doc-root" : "", @@ -273,6 +274,7 @@ string program_name = "spine"; "odf", "open document format text (--odt)", &opts["odf"], "odt", "open document format text", &opts["odt"], "output", "=/path/to/output/dir specify where to place output", &settings["output"], + "ssp-round-trip", "=/path/to/file.ssp read a .ssp back and re-emit it on stdout", &settings["ssp-round-trip"], "parallel", "parallelisation", &opts["parallel"], "parallel-subprocesses", "nested parallelisation", &opts["parallel-subprocesses"], "pdf", "latex output for pdfs", &opts["pdf"], @@ -352,6 +354,49 @@ string program_name = "spine"; if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); } + /+ ↓ read a .ssp back into the abstraction and emit it again, on stdout. + the two should be byte identical: that is the check that the reader is + faithful, and it is made against the writer's own record definition, + not against a second description of the format + +/ + if (settings["ssp-round-trip"].length > 0) { + import sisudoc.ocda.abstraction.ssp; + import sisudoc.ocda.abstraction.ssp_in; + mixin spineAbstractionRead; + mixin sspObjectRecord; + auto _doc = sspReadFile(settings["ssp-round-trip"]); + string[] _out; + if (_doc.format.length > 0) { _out ~= _doc.format; } + if (_doc.source.length > 0) { _out ~= "% Source: " ~ _doc.source; } + _out ~= ""; + void _block(string _name, string[] _keys, string[string] _kv) { + _out ~= "@" ~ _name ~ " {"; + foreach (k; _keys) { + if (k in _kv) { _out ~= " " ~ k ~ ": " ~ _kv[k]; } + } + _out ~= "}"; + _out ~= ""; + } + _block("meta", _doc.meta_order, _doc.meta); + _block("make", _doc.make_order, _doc.make); + _block("doc_has", _doc.doc_has_order, _doc.doc_has); + foreach (section; _doc.section_order) { + _out ~= "@" ~ section ~ " {"; + _out ~= ""; + foreach (obj; _doc.abstraction[section]) { + _out ~= sspObjectRecord(obj, section); + } + _out ~= "}"; + _out ~= ""; + } + foreach (line; _out) { writeln(line); } + /+ ↓ the document goes to stdout, so the run-complete banner that + scope(success) prints would be part of it; leave without it + +/ + import core.stdc.stdlib : exit; + stdout.flush; + exit(0); + } enum outTask { source_or_pod, sqlite, sqlite_multi, latex, odt, epub, html_scroll, html_seg, html_stuff, text, skel } struct OptActions { @trusted bool allow_downloads() { |
