annotate mde/mergetag/Reader.d @ 26:611f7b9063c6

Changed the licensing and removed a few dead files. Changed licensing to "GPL version 2 or later" to avoid future compatibility issues. Also a unittest fix to the previous commit. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 03 Apr 2008 18:15:02 +0100
parents 32eff0e01c05
children e0839643ff52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
1 /* LICENSE BLOCK
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
2 Part of mde: a Modular D game-oriented Engine
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
4
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
7 version 2 of the License, or (at your option) any later version.
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
8
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
11 See the GNU General Public License for more details.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
12
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
13 You should have received a copy of the GNU General Public License
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
15
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /**************************************************************************************************
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * This module contains all reading functions, for both binary and text MergeTag files.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 *************************************************************************************************/
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 module mde.mergetag.Reader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 // package imports
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 public import mde.mergetag.iface.IReader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.mergetag.DataSet;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import mde.mergetag.DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import mde.mergetag.exception;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import mde.mergetag.internal;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 import tango.core.Exception;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 // tango imports
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 import tango.io.UnicodeFile;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 import Util = tango.text.Util;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 import ConvInt = tango.text.convert.Integer;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 import tango.util.collection.model.View : View;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 import tango.util.collection.HashSet : HashSet;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 import tango.util.log.Log : Log, Logger;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 private Logger logger;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 static this() {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 logger = Log.getLogger ("mde.mergetag.Reader");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 // TODO: allow compressing with zlib for both binary and text? (.mtz, .mtt, .mtb extensions)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /** Make an IReader class.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 * If no extension is given, search for a file using each extension (.mtt and .mtb) appended to
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
49 * path, and set path to the most recent file name. If neither suffix added resolves a valid file,
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
50 * throw an MTFileIOException with a suitible error message.
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 * When an extension is available (either after the above or when supplied), use the appropriate
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 * reader (MTT or MTB).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 * $(TR $(TH Exception) $(TH Thrown when))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 * $(TR $(TD MTFileFormatException) $(TD Unable to determine format (only analysing file name)))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 * $(TR $(TD MTFileIOException) $(TD When no extension is given, neither appending .mtt nor
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 * appending .mtb resolves a valid file))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 * )
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 IReader makeReader (char[] path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 return makeReader (new FilePath(path), ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 IReader makeReader (PathView path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 if (path.ext.length == 0) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 PathView tPath = new FilePath (path.toString ~ ".mtt");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 PathView bPath = new FilePath (path.toString ~ ".mtb");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 bool bPathExists = bPath.exists;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 if (tPath.exists) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 if (bPathExists) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 // take the latest version (roughly speaking...)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 path = tPath.modified > bPath.modified ? tPath : bPath;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 } else path = tPath;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 if (bPathExists) path = bPath;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 else {
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
82 throw new MTFileIOException ("No file exists: "~path.toString~"[.mtt|.mtb]");
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 if (path.ext == "mtb") return new MTBReader (path, ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 else if (path.ext == "mtt") return new MTTReader (path, ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 else throw new MTFileFormatException;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 /**
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
93 * Class for reading a mergetag text file.
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 * Use as:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 * IReader foo;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 * try {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 * foo = new MTTReader("foo.mtt");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 * foo.read();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 * }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 * catch (MTException) {}
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
103 * // get your data from foo.dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 * $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 * $(TR $(TH Exception) $(TH Thrown when))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 * $(TR $(TD MTFileIOException) $(TD An error occurs while opening the file))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 * $(TR $(TD MTFileFormatException) $(TD The file doesn't start with a recognised header/version))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 * $(TR $(TD MTSyntaxException) $(TD A file syntax error occurs))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 * $(TR $(TD MTException) $(TD An unexpected error occurs))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 * )
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 * Note that all exceptions extend MTException and when any exception is thrown the class is
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 * rendered unusable: any subsequent calls to read will be ignored.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
117 * Threading: Separate instances of Reader should be thread-safe provided access to the same
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
118 * dataset is synchronized; i.e. no two readers refering to the same dataset should run
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 * simultaneously. (The Reader class could be made thread-safe w.r.t. datasets, but
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 * performance-wise I doubt it would be worth it.)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 * Do not run a single instance of Reader in multiple threads simultaneously.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 class MTTReader : IReader
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 //BEGIN DATA
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 /** Get or set the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 * A container for all read data.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
130 * This may be accessed from here; however it may be preferable to use an external reference
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 * (passed to the class on initialisation).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 DataSet dataset () { return _dataset; }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 void dataset (DataSet ds) /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135 { _dataset = ds; }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137 /** A delegate for creating new DataSections within the dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
138 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
139 * Allows a user-made class to be used in the DataSet instead of DefaultData (used if no
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 * dataSecCreator exists). Also allows an existing class instance to be used instead of a new
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141 * one.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143 * This works by supplying a function which returns a reference to an instance of a class
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 * implementing IDataSection. The function is passed the ID of the new section and may use this
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 * to use different IDataSection classes for different sections.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 * The function may also return null, in which case the section will be skipped. In the version
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 * of read taking a set of sections to read, the section will not be marked as read and may
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 * still be read later (assuming dataSecCreator returns non-null). However, in the version of
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 * read not taking the set argument, all sections are set as read regardless, and the section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 * cannot be read later.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 void dataSecCreator (IDataSection delegate (ID) dSC) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 _dataSecCreator = dSC;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 private:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 static Logger logger;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 // Non-static symbols:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 final char[] ErrFile; // added after ErrInFile to do the same without the "in " bit.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 final char[] ErrInFile; // something like "in \"path/file.mtt\""
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 final char[] fbuf; // file is read into this
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 MTFormatVersion.VERS fileVer = MTFormatVersion.VERS.INVALID; // Remains INVALID until set otherwise by CTOR.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 IDataSection delegate (ID) _dataSecCreator = null; // see property setter above
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 uint endOfHeader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 bool allRead = false; // true if endOfHeader == fbuf.length or read([]) has run
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 bool fatal = false; // a fatal file error occured; don't try to recover
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 /* If the file is scanned for sections, the starting position of all sections are stored
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173 * in secTable. If this is empty, either no sections exist (and endOfHeader == fbuf.length)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 * or a section scan has not been run (read() with no section names doesn't need to do so).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 struct SecMD { // sec meta data
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 static SecMD opCall (uint _pos, bool _read) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 SecMD ret;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 ret.pos = _pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 ret.read = _read;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181 return ret;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 uint pos; // position to start reading
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184 bool read; // true if already read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 SecMD [ID] secTable;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 DataSet _dataset;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189 //END DATA
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 //BEGIN METHODS: CTOR / DTOR
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 static this () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193 logger = Log.getLogger ("mde.mergetag.read.Reader");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 /** Tries to open file path and read it into a buffer.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
197 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198 * Params:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
199 * path = The name or FilePath of the file to open.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200 * Standard extensions are .mtt and .mtb for text and binary files respectively.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201 * ds = If null create a new DataSet, else use existing DataSet ds and merge read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 * data into it.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203 * rdHeader = If true, read the header like a standard section. Doesn't read the header by
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 * default since if it's not requested it's likely not wanted.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 * Memory:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 * This currently works by loading the whole file into memory at once. This should be fine most
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
208 * of the time, but could potentially be a problem. Changing this would mean significantly
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
209 * changes to the way the code works.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211 /* Ideas for implementing a partial-loading memory model:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
212 * Use a conduit directly.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
213 * Use a fiber to do the parsing; let it switch back when it runs out of memory.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 * Redesign the code so it never needs to look backwards in the buffer?
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 * Major problem: reading only some sections and keeping references to other sections
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 * would no longer be possible.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
218 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 public this (char[] path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
220 this (new FilePath (path), ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
222 /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223 public this (PathView path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224 // Create a dataset or use an existing one
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 if (ds !is null) _dataset = ds;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226 else _dataset = new DataSet();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228 // Open & read the file
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
229 try { // Supports unicode files with a BOM; defaults to UTF8 when there isn't a BOM:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
230 scope file = new UnicodeFile!(char) (path, Encoding.Unknown);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 fbuf = cast(char[]) file.read();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
232 } catch (Exception e) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
233 throwMTErr ("Error reading file: " ~ e.msg, new MTFileIOException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
234 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 // Remember the file name so that we can report errors (somewhat) informatively:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
236 ErrFile = path.path ~ path.file;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 ErrInFile = " in \"" ~ ErrFile ~ '"';
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
238
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
239 // Version checking & matching header section tag:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
240 if (fbuf.length < 6 || fbuf[0] != '{' || fbuf[1] != 'M' || fbuf[2] != 'T' || fbuf[5] != '}')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
241 throwMTErr("Not a valid MergeTag text file" ~ ErrInFile, new MTFileFormatException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
242 fileVer = MTFormatVersion.parseString (fbuf[3..5]);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
243 if (fileVer == MTFormatVersion.VERS.INVALID)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
244 throwMTErr("Unrecognised MergeTag version: MT" ~ fbuf[3..5] ~ ErrInFile, new MTFileFormatException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
245
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
246 // Header reading/skipping:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
247 if (rdHeader) { // only bother actually reading it if it was requested
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
248 // If already existing, merge; else create a new DefaultData.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
249 if (!_dataset.header) _dataset.header = new DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
250 endOfHeader = parseSection (6, cast(IDataSection) _dataset.header);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 else endOfHeader = parseSection (6,null);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
254 //END METHODS: CTOR / DTOR
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
255
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
256 //BEGIN METHODS: PUBLIC
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 /** Scans for sections if not already done and returns a list of IDs.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
258 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
259 * Won't work (will return an empty array) if all sections have already been read without
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
260 * scanning for sections.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
261 */
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
262 public ID[] getSectionNames () {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
263 if (fatal) return [];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
264 if (!secTable.length) read([]); // scan for sections
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
265 return secTable.keys;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
266 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
267
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
268 /** Reads (some) sections of the file into data. Note that sections will never be _read twice.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 * To be more accurate, the file is copied into a buffer by this(). read() then parses the
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271 * contents of this buffer, and stores the contents in dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273 * Each section read is stored in a DataSection class. By default this is an instance of
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 * DefaultData; this can be customised (see dataSecCreator).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 * If secSet is provided, reading is restricted to sections given in secSet, otherwise all
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
277 * sections are read. Sections given in secSet but not found in the file are not reported as an
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278 * error. Suggested: supply a HashSet!(uint) as the View!(ID). An ArrayBag!(ID) as used is not a
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
279 * good choice, except that in this case it's empty.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
280 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
281 * Merging:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
282 * Where a section already exists in the DataSet (when either the section is given more than
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
283 * once in the file, or it was read from a different file by another reader) it is merged.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
284 * Entries already in the DataSet take priority.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
285 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
286 * Performance:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
287 * Note that loading only desired sections like this still parses the sections not
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
288 * read (although it does not try to understand the type or data fields), so there is only a
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
289 * small performance advantage to this where other sections do exist in the file. There is also
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
290 * some overhead in only partially reading the file to keep track of where other sections are so
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
291 * that the entire file need not be re-read if further (or all remaining) sections are read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
292 * later.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
293 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
294 public void read () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
295 if (secTable.length) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
296 foreach (ID id, ref SecMD smd; secTable) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
297 if (!smd.read) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
298 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
299 parseSection (smd.pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
300 // allRead is set true so there's no point setting smd.read = true
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
301 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
302 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
303 } else { // this time we don't need to use secTable
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
304 for (uint pos = endOfHeader; pos < fbuf.length;) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
305 ID id = fbufReadSecMarker (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
306 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
307 pos = parseSection (pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
308 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
309 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
310
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
311 allRead = true;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
312 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
313 /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
314 public void read (ID[] secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
315 HashSet!(ID) hs = new HashSet!(ID);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
316 foreach (id; secSet) hs.add(id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
317 read (hs);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
318 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
319 /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
320 public void read (View!(ID) secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
321 if (allRead || fatal) return; // never do anything in either case
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
322
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
323 if (secTable.length) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
324 foreach (ID id; secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
325 SecMD* psmd = id in secTable;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
326 if (psmd && !psmd.read) { // may not exist
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
327 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
328 parseSection (psmd.pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
329 if (ds !is null) psmd.read = true; // getOrCreateSec may return null
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
330 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
331 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
332 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
333 for (uint pos = endOfHeader; pos < fbuf.length;) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
334 ID id = fbufReadSecMarker (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
335 secTable[id] = SecMD(pos,false); // add to table
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
336 if (secSet.contains(id)) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
337 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
338 pos = parseSection (pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
339 if (ds !is null) secTable[id].read = true;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
340 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
341 pos = parseSection (pos, null); // skip section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
342 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
343 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
344 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
345 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
346 //END METHODS: PUBLIC
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
347
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
348 //BEGIN METHODS: PRIVATE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
349 /* Utility function for read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
350 * Look for a section; return it if it exists otherwise create a new section:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
351 * use _dataSecCreator if it exists or just create a DefaultData if not.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
352 * However if _dataSecCreator returns null don't add it to the dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
353 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
354 private IDataSection getOrCreateSec (ID id) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
355 IDataSection* i = id in _dataset.sec;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
356 if (i) return *i;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
357 else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
358 IDataSection s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
359 if (_dataSecCreator !is null) s = _dataSecCreator(id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
360 else s = new DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
361 if (s !is null) _dataset.sec[id] = s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
362 return s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
363 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
364 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
365
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
366 /* Reads a section, starting from index pos, finishing at the next section marker (returning
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
367 the position of the start of the marker). pos should start after the section marker.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
368
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
369 After analysing tags, the function passes the type, ID and data to addTag.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
370
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
371 NOTE: from performance tests on indexing char[]'s and dereferencing char*'s, the char*'s are
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
372 slightly faster, but a tiny difference isn't worth the extra effort/risk of using char*'s.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
373 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
374 private uint parseSection (uint pos, IDataSection dsec) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
375 /* Searches fbuf starting from start to find one of <=>| and stops at its index.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
376
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
377 If quotable then be quote-aware for single and double quotes.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
378 Note: there's no length restriction for the content of the quote since it could be a single
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
379 non-ascii UTF-8 char which would look like several chars.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
380 */
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
381 void fbufLocateDataTagChar (ref uint pos, bool quotable) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
382 for (; pos < fbuf.length; ++pos) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
383 if ((fbuf[pos] >= '<' && fbuf[pos] <= '>') || fbuf[pos] == '|') return;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
384 else if (quotable) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
385 char c = fbuf[pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
386 if (c == '\'' || c == '"') {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
387 ++pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
388 while (fbuf[pos] != c) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
389 if (fbuf[pos] == '\\') ++pos; // escape seq.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
390 fbufIncrement(pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
391 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
392 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
393 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
394 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
395 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
396
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
397 // Used to ignore a tag (if it starts !< or !{ or should otherwise be ignored):
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
398 bool comment = false;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
399 for (; pos < fbuf.length; ++pos) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
400 if (Util.isSpace(fbuf[pos])) continue; // whitespace
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
401 else if (fbuf[pos] == '<') { // data tag
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
402 char[] ErrDTAG = "Bad data tag format: not <type|id=data>" ~ ErrInFile;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
403
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
404 fbufIncrement (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
405
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
406 // Type section of tag:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
407 uint pos_s = pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
408 fbufLocateDataTagChar (pos, false); // find end of type section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
409 if (fbuf[pos] != '|') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
410 char[] type = fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
411
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
412 fbufIncrement (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
413
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
414 // ID section of tag:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
415 pos_s = pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
416 fbufLocateDataTagChar (pos, false); // find end of type section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
417 if (fbuf[pos] != '=') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
418 ID tagID = cast(ID) fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
419
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
420 fbufIncrement (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
421
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
422 // Data section of tag:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
423 pos_s = pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
424 fbufLocateDataTagChar (pos, true); // find end of data section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
425 if (fbuf[pos] != '>') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
426 char[] data = fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
427
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
428 if (!comment && dsec !is null) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
429 type = Util.trim(type);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
430 try {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
431 dsec.addTag (type, tagID, data);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
432 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
433 catch (TextException e) {
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
434 logger.error ("TextException while reading " ~ ErrFile ~ ":"); // following a parse error
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
435 logger.error (e.msg);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
436 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
437 catch (Exception e) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
438 logger.error ("Unknown error occured" ~ ErrInFile ~ ':');
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
439 logger.error (e.msg);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
440 throwMTErr (e.msg); // Fatal to Reader
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
441 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
442 } else comment = false; // cancel comment status now
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
443 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
444 else if (fbuf[pos] == '{') {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
445 if (comment) { // simple block comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
446 uint depth = 0; // depth of embedded comment blocks
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
447 while (true) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
448 fbufIncrement (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
449 if (fbuf[pos] == '}') {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
450 if (depth == 0) break;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
451 else --depth;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
452 } else if (fbuf[pos] == '{')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
453 ++depth;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
454 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
455 comment = false; // end of this comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
456 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
457 return pos; // next section coming up; we are done
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
458 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
459 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
460 else if (fbuf[pos] == '!') { // possibly a comment; check next char
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
461 comment = true; // starting a comment (or an error)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
462 // variable is reset at end of comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
463 } else // must be an error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
464 throwMTErr ("Invalid character (or sequence starting \"!\") outside of tag" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
465 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
466 // if code execution reaches here, we're at EOF
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
467 // possible error: last character was ! (but don't bother checking since it's inconsequential)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
468 return pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
469 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
470
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
471 /* Parses fbuf for a section marker. Already knows fbuf[pos] == '{'.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
472 */
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
473 private ID fbufReadSecMarker (ref uint pos) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
474 // at this point pos is whatever a parseSection run returned
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
475 // since we haven't hit EOF, fbuf[pos] MUST be '{' so no need to check
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
476 fbufIncrement(pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
477
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
478 uint start = pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
479 for (; pos < fbuf.length; ++pos)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
480 if (fbuf[pos] == '}' || fbuf[pos] == '{') break;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
481
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
482 if (pos >= fbuf.length || fbuf[pos] != '}')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
483 throwMTErr ("Bad section tag format: not {id}" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
484
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
485 ID id = cast(ID) fbuf[start..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
486 fbufIncrement(pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
487 return id;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
488 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
489
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
490 /* Increments pos and checks it hasn't hit fbuf.length . */
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
491 private void fbufIncrement(ref uint pos) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
492 ++pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
493 if (pos >= fbuf.length) throwMTErr("Unexpected EOF" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
494 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
495
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
496 private void throwMTErr (char[] msg, MTException exc = new MTException) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
497 fatal = true; // if anyone catches the error and tries to do anything --- we're dead now
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
498 logger.error (msg); // report the error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
499 throw exc; // and signal our error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
500 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
501 //END METHODS: PRIVATE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
502 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
503
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
504
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
505 /**
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
506 * Class for reading a mergetag text file.
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
507 *
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
508 * Currently only a dummy class: a MTNotImplementedException will be thrown if created.
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
509 */
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
510 class MTBReader : IReader
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
511 {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
512 public this (char[] path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
513 this (new FilePath (path), ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
514 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
515 public this (PathView path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
516 throw new MTNotImplementedException;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
517 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
518
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
519 DataSet dataset () { /// Get the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
520 return null;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
521 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
522 void dataset (DataSet) {} /// Set the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
523
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
524 void dataSecCreator (IDataSection delegate (ID)) {} /// Set the dataSecCreator
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
525
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
526 ID[] getSectionNames () { /// Get identifiers for all sections
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
527 return [];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
528 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
529 void read () {} /// Commence reading
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
530 void read (ID[] secSet) {} /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
531 void read (View!(ID) secSet) {} /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
532 }