sq3: show SQLite error messages on stderr by default
[iv.d.git] / saxytests / saxytest.d
bloba8f00d0dc9f8621387c88eb902c8fcbd04fc0889
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 * 2. Altered source versions must be plainly marked as such, and must not be
16 * misrepresented as being the original software.
17 * 3. This notice may not be removed or altered from any source distribution.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 module saxytest /*is aliced*/;
25 import iv.alice;
26 import iv.saxy;
27 import iv.strex;
29 static if (is(typeof({import iv.vfs;}))) {
30 import iv.vfs;
31 enum HasVFS = true;
32 } else {
33 enum HasVFS = false;
36 static if (is(typeof({import iv.strex;}))) {
37 import iv.strex;
38 } else {
39 private string quote (const(char)[] s) {
40 import std.array : appender;
41 import std.format : formatElement, FormatSpec;
42 auto res = appender!string();
43 FormatSpec!char fspc; // defaults to 's'
44 formatElement(res, s, fspc);
45 return res.data;
50 // ////////////////////////////////////////////////////////////////////////// //
51 char[] readFile (const(char)[] fname) {
52 static if (HasVFS) {
53 auto fl = VFile(fname);
54 auto res = new char[](cast(int)fl.size);
55 fl.rawReadExact(res[]);
56 return res;
57 } else {
58 import std.conv : to;
59 import std.stdio : File;
60 auto fl = File(fname.to!string);
61 auto res = new char[](cast(int)fl.size);
62 fl.rawRead(res[]);
63 return res;
68 // ////////////////////////////////////////////////////////////////////////// //
69 void main (string[] args) {
70 import std.stdio;
71 import std.utf;
72 string infilename = (args.length > 1 ? args[1] : "z00.xml");
73 char[] indent;
74 version(all) {
75 static if (HasVFS) {
76 auto inst = VFile(infilename);
77 } else {
78 auto inst = File(infilename);
80 } else {
81 auto inst = readFile(infilename).byChar;
83 xmparse(inst,
84 (char[] name, char[][string] attrs) {
85 import std.stdio;
86 write(indent);
87 write("tag '", name, "' opened");
88 if (attrs.length) {
89 write(' ');
90 foreach (const ref kv; attrs.byKeyValue) {
91 write(' ', kv.key, "=", kv.value.quote);
94 writeln;
95 indent ~= ' ';
97 (char[] name) {
98 import std.stdio;
99 indent.length -= 1;
100 indent.assumeSafeAppend;
101 writeln(indent, "tag '", name, "' closed");
103 (char[] text) {
104 import std.stdio;
105 writeln(indent, text.length, " bytes of content: ", text.quote);