Mon, 18 Mar 2013 04:03:05 +0200
added dummy action for future inlining command. Also GCC says that deleting instances of classes with virtual members but no virtual destructors is bad.
0 | 1 | #include <vector> |
2 | ||
3 | #include "common.h" | |
4 | #include "io.h" | |
5 | #include "misc.h" | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
6 | #include "bbox.h" |
0 | 7 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
8 | vector<str> g_zaFileLoadPaths; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
9 | |
0 | 10 | // ============================================================================= |
11 | // IO_FindLoadedFile (str) | |
12 | // | |
13 | // Returns a pointer to the first found open file with the given name. | |
14 | // ============================================================================= | |
15 | OpenFile* IO_FindLoadedFile (str name) { | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
16 | for (ulong i = 0; i < g_LoadedFiles.size(); i++) { |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
17 | OpenFile* const file = g_LoadedFiles[i]; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
18 | if (file->zFileName == name) |
0 | 19 | return file; |
20 | } | |
21 | ||
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
22 | return nullptr; |
0 | 23 | } |
24 | ||
25 | // ============================================================================= | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
26 | // IO_OpenLDrawFile (str) |
0 | 27 | // |
28 | // Opens the given file and parses the LDraw code within. | |
29 | // ============================================================================= | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
30 | OpenFile* IO_OpenLDrawFile (str path) { |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
31 | logf ("Opening %s...\n", path.chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
32 | |
0 | 33 | FILE* fp = fopen (path.chars (), "r"); |
34 | ||
35 | if (!fp) { | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
36 | for (ushort i = 0; i < g_zaFileLoadPaths.size(); ++i) { |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
37 | str zFilePath = str::mkfmt ("%s/%s", g_zaFileLoadPaths[i].chars(), path.chars()); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
38 | fp = fopen (zFilePath.chars (), "r"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
39 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
40 | if (fp) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
41 | break; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
42 | } |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
43 | } |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
44 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
45 | if (!fp) { |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
46 | logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
47 | return nullptr; |
0 | 48 | } |
49 | ||
50 | OpenFile* load = new OpenFile; | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
51 | ulong numWarnings = 0; |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
52 | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
53 | load->zFileName = path; |
0 | 54 | |
55 | vector<str> lines; | |
56 | ||
57 | { | |
58 | char line[1024]; | |
59 | while (fgets (line, sizeof line, fp)) { | |
60 | // Trim the trailing newline | |
61 | str zLine = line; | |
62 | while (zLine[~zLine - 1] == '\n' || zLine[~zLine - 1] == '\r') | |
63 | zLine -= 1; | |
64 | ||
65 | lines.push_back (zLine); | |
66 | } | |
67 | } | |
68 | ||
69 | fclose (fp); | |
70 | ||
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
71 | for (ulong i = 0; i < lines.size(); ++i) { |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
72 | LDObject* obj = ParseLine (lines[i]); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
73 | load->objects.push_back (obj); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
74 | |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
75 | // Check for warnings |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
76 | if (obj->getType() == OBJ_Gibberish) { |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
77 | logf (LOG_Warning, "Couldn't parse line #%lu: %s\n", |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
78 | i, static_cast<LDGibberish*> (obj)->zReason.chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
79 | logf (LOG_Warning, "- Line was: %s\n", lines[i].chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
80 | numWarnings++; |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
81 | } |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
82 | } |
0 | 83 | |
84 | g_LoadedFiles.push_back (load); | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
85 | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
86 | logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n", |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
87 | path.chars(), numWarnings, PLURAL (numWarnings)); |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
88 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
89 | return load; |
0 | 90 | } |
91 | ||
92 | // ============================================================================= | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
93 | // isNumber (char*) [static] |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
94 | // |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
95 | // Returns whether a given string represents a floating point number |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
96 | // TODO: Does LDraw support scientific notation? |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
97 | // ============================================================================= |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
98 | static bool isNumber (char* sToken) { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
99 | char* sPointer = &sToken[0]; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
100 | bool bGotDot = false; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
101 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
102 | // Allow leading hyphen for negatives |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
103 | if (*sPointer == '-') |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
104 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
105 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
106 | while (*sPointer != '\0') { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
107 | if (*sPointer == '.' && !bGotDot) { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
108 | // Decimal point |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
109 | bGotDot = true; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
110 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
111 | continue; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
112 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
113 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
114 | if (*sPointer >= '0' && *sPointer <= '9') { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
115 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
116 | continue; // Digit |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
117 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
118 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
119 | // If the above cases didn't catch this character, it was |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
120 | // illegal and this is therefore not a number. |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
121 | return false; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
122 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
123 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
124 | return true; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
125 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
126 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
127 | // ============================================================================= |
0 | 128 | // ParseLine (str) |
129 | // | |
130 | // Parses a string line containing an LDraw object and returns the object parsed. | |
131 | // ============================================================================= | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
132 | #define CHECK_TOKEN_COUNT(N) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
133 | if (tokens.size() != N) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
134 | return new LDGibberish (zLine, "Bad amount of tokens"); |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
135 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
136 | #define CHECK_TOKEN_NUMBERS(MIN,MAX) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
137 | for (ushort i = MIN; i <= MAX; ++i) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
138 | if (!isNumber (tokens[i])) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
139 | return new LDGibberish (zLine, str::mkfmt ("Token #%u was `%s`, expected a number", \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
140 | (i + 1), tokens[i].chars())); |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
141 | |
0 | 142 | LDObject* ParseLine (str zLine) { |
143 | str zNoWhitespace = zLine; | |
144 | StripWhitespace (zNoWhitespace); | |
145 | if (!~zNoWhitespace) { | |
146 | // Line was empty, or only consisted of whitespace | |
147 | return new LDEmpty; | |
148 | } | |
149 | ||
150 | vector<str> tokens = zLine / " "; | |
151 | ||
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
152 | // Rid leading all-whitespace tokens |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
153 | while (tokens.size() && !(~tokens[0])) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
154 | tokens.erase (tokens.begin()); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
155 | |
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
156 | if (~tokens[0] != 1) |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
157 | return new LDGibberish (zLine, "Illogical line code"); |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
158 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
159 | char const c = tokens[0][0]; |
0 | 160 | switch (c - '0') { |
161 | case 0: | |
162 | { | |
163 | // Comment | |
164 | LDComment* obj = new LDComment; | |
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
165 | obj->zText = zLine.substr (2, -1); |
0 | 166 | return obj; |
167 | } | |
168 | ||
169 | case 1: | |
170 | { | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
171 | // Subfile |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
172 | CHECK_TOKEN_COUNT (15) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
173 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
174 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
175 | #ifndef WIN32 |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
176 | tokens[14].replace ("\\", "/"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
177 | #endif // WIN32 |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
178 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
179 | // Try open the file |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
180 | OpenFile* pFile = IO_FindLoadedFile (tokens[14]); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
181 | if (!pFile) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
182 | pFile = IO_OpenLDrawFile (tokens[14]); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
183 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
184 | // If we cannot open the file, mark it an error |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
185 | if (!pFile) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
186 | return new LDGibberish (zLine, "Could not open referred file"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
187 | |
0 | 188 | LDSubfile* obj = new LDSubfile; |
189 | obj->dColor = atoi (tokens[1]); | |
190 | obj->vPosition = ParseVertex (zLine, 2); // 2 - 4 | |
191 | ||
192 | for (short i = 0; i < 9; ++i) | |
193 | obj->faMatrix[i] = atof (tokens[i + 5]); // 5 - 13 | |
194 | ||
195 | obj->zFileName = tokens[14]; | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
196 | obj->pFile = pFile; |
0 | 197 | return obj; |
198 | } | |
199 | ||
200 | case 2: | |
201 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
202 | CHECK_TOKEN_COUNT (8) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
203 | CHECK_TOKEN_NUMBERS (1, 7) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
204 | |
0 | 205 | // Line |
206 | LDLine* obj = new LDLine; | |
207 | obj->dColor = GetWordInt (zLine, 1); | |
208 | for (short i = 0; i < 2; ++i) | |
209 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 7 | |
210 | return obj; | |
211 | } | |
212 | ||
213 | case 3: | |
214 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
215 | CHECK_TOKEN_COUNT (11) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
216 | CHECK_TOKEN_NUMBERS (1, 10) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
217 | |
0 | 218 | // Triangle |
219 | LDTriangle* obj = new LDTriangle; | |
220 | obj->dColor = GetWordInt (zLine, 1); | |
221 | ||
222 | for (short i = 0; i < 3; ++i) | |
223 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 10 | |
224 | ||
225 | return obj; | |
226 | } | |
227 | ||
228 | case 4: | |
229 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
230 | CHECK_TOKEN_COUNT (14) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
231 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
232 | |
0 | 233 | // Quadrilateral |
234 | LDQuad* obj = new LDQuad; | |
235 | obj->dColor = GetWordInt (zLine, 1); | |
236 | ||
237 | for (short i = 0; i < 4; ++i) | |
238 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 13 | |
239 | ||
240 | return obj; | |
241 | } | |
242 | ||
243 | case 5: | |
244 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
245 | CHECK_TOKEN_COUNT (14) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
246 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
247 | |
0 | 248 | // Conditional line |
249 | LDCondLine* obj = new LDCondLine; | |
250 | obj->dColor = GetWordInt (zLine, 1); | |
251 | ||
252 | for (short i = 0; i < 2; ++i) | |
253 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 7 | |
254 | ||
255 | for (short i = 0; i < 2; ++i) | |
256 | obj->vaControl[i] = ParseVertex (zLine, 8 + (i * 3)); // 8 - 13 | |
257 | return obj; | |
258 | } | |
259 | ||
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
260 | default: // Strange line we couldn't parse |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
261 | return new LDGibberish (zLine, "Unknown line code number"); |
0 | 262 | } |
263 | } |