summaryrefslogtreecommitdiffhomepage
path: root/dlang/test/dump.d
blob: 17aa9bbcf0ea89d4c054dbca25832a1999d7c37e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/++
  Write a loaded abstraction out canonically.

  The oracle for everything that claims to implement this model: load a
  .ssp or a .ocda.db and print the model, deterministically, so that two
  implementations can be compared with diff.

  Usage: ocda-dump [--unknown] <file>.ssp|<file>.ocda.db [lang]
+/
import std.stdio;
import ocda.model;
import ocda.load;
import ocda.dump;

int main(string[] args) {
  bool unknown = false;
  string[] rest;
  foreach (a; args[1 .. $]) {
    if (a == "--unknown") { unknown = true; } else { rest ~= a; }
  }
  if (rest.length < 1) {
    stderr.writeln("usage: ocda-dump [--unknown] <file>.ssp|<file>.ocda.db [lang]");
    return 2;
  }
  string lang = (rest.length > 1) ? rest[1] : "";
  OcdaDocument doc;
  try {
    doc = load(rest[0], lang);
  } catch (Exception e) {
    stderr.writeln("error: ", e.msg);
    return 2;
  }
  write(unknown ? dumpUnknown(doc) : dumpDocument(doc));
  return 0;
}