sq3: show SQLite error messages on stderr by default
[iv.d.git] / btenc_samples / bte_list.d
blobbeab1bcd1da5b20a5f11944323c76feb5405a0ea
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module list /*is aliced*/;
19 import iv.alice;
20 import iv.btenc;
23 void die(A...) (string fmt, A args) {
24 import std.stdio : stderr;
25 static if (args.length == 0) {
26 stderr.writeln("FATAL: ", fmt);
27 } else {
28 import std.string : format;
29 auto s = format(fmt, args);
30 stderr.writeln("FATAL: ", s);
32 import core.exception : ExitException;
33 throw new ExitException();
37 void main (string[] args) {
38 import std.stdio : writeln;
39 if (args.length != 2) die("one argument expected");
40 auto btf = BTField.load(args[1]);
41 if (!btf.isDict) die("benc file is not a dictionary");
42 auto info = "info" in btf;
43 if (info is null) die("no \"info\" entry");
44 if (!info.isDict) die("invalid \"info\" entry");
45 auto name = "name" in *info;
46 if (name is null) die("no \"name\" entry");
47 if (!name.isStr) die("invalid \"name\" entry");
48 if (auto files = "files" in *info) {
49 if (!files.isList) die("invalid \"files\" entry");
50 foreach (ref fi; files.vlist) {
51 string fpath = name.vstr;
52 if (!fi.isDict) die("invalid file entry");
53 if (auto pt = "path" in fi) {
54 if (!pt.isList) die("invalid \"path\" entry");
55 foreach (ref dd; pt.vlist) {
56 if (!dd.isStr) die("invalid \"path\" entry");
57 fpath ~= "/";
58 fpath ~= dd.vstr;
60 } else {
61 die("invalid file entry");
63 writeln(fpath);
65 } else {
66 writeln(name.vstr);