src/ldconfig.cpp

Sat, 24 Aug 2013 16:30:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 24 Aug 2013 16:30:30 +0300
changeset 483
138b7c5c3c59
parent 455
c5d14d112034
child 493
16766ac1bbd9
permissions
-rw-r--r--

removed unused LabeledWidget

406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "file.h"
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "ldconfig.h"
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "gui.h"
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "misc.h"
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "colors.h"
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 // =============================================================================
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 // Helper function for parseLDConfig
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
27 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
28 static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, str& val) {
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 short pos;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
30
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 // Try find the token and get its position
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
32 if (!pars.findToken (pos, tag, 1))
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 return false;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
34
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 // Get the token after it and store it into val
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
36 return pars.getToken (val, pos + 1);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
40 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
41 void parseLDConfig() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
42 File* f = openLDrawFile ("LDConfig.ldr", false);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
44 if (!f) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
45 critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing! (%1)"),
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
46 strerror (errno)));
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 return;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // Read in the lines
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
51 for (str line : *f) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
52 if (line.length() == 0 || line[0] != '0')
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 continue; // empty or illogical
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
55 line.remove ('\r');
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
56 line.remove ('\n');
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 // Parse the line
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
59 LDConfigParser pars (line, ' ');
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 short code = 0, alpha = 255;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 str name, facename, edgename, valuestr;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 // Check 0 !COLOUR, parse the name
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
65 if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (name, 2))
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 continue;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 // Replace underscores in the name with spaces for readability
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
69 name.replace ("_", " ");
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // Get the CODE tag
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
72 if (!parseLDConfigTag (pars, "CODE", valuestr))
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 continue;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
75 if (!isNumber (valuestr))
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 continue; // not a number
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // Ensure that the code is within [0 - 511]
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 bool ok;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
80 code = valuestr.toShort (&ok);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
82 if (!ok || code < 0 || code >= 512)
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 continue;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 // VALUE and EDGE tags
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
86 if (!parseLDConfigTag (pars, "VALUE", facename) || !parseLDConfigTag (pars, "EDGE", edgename))
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 continue;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 // Ensure that our colors are correct
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
90 QColor faceColor (facename),
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
91 edgeColor (edgename);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
93 if (!faceColor.isValid() || !edgeColor.isValid())
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 continue;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 // Parse alpha if given.
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
97 if (parseLDConfigTag (pars, "ALPHA", valuestr))
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
98 alpha = clamp<short> (valuestr.toShort(), 0, 255);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 LDColor* col = new LDColor;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 col->name = name;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 col->faceColor = faceColor;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 col->edgeColor = edgeColor;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 col->hexcode = facename;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
105 col->faceColor.setAlpha (alpha);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 col->index = code;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
107 setColor (code, col);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 delete f;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // =============================================================================
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
114 // -----------------------------------------------------------------------------
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 LDConfigParser::LDConfigParser (str inText, char sep) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 m_tokens = container_cast<QStringList, List<str>> (inText.split (sep, QString::SkipEmptyParts));
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 m_pos = -1;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
120 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
122 bool LDConfigParser::atBeginning() {
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 return (m_pos == -1);
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
126 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
128 bool LDConfigParser::atEnd() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
129 return (m_pos == (signed) m_tokens.size() - 1);
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
132 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 bool LDConfigParser::getToken (str& val, const ushort pos) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 if (pos >= m_tokens.size())
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 return false;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 val = m_tokens[pos];
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 return true;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
142 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 bool LDConfigParser::next (str& val) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 return getToken (val, ++m_pos);
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
148 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 bool LDConfigParser::peekNext (str& val) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 return getToken (val, m_pos + 1);
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
154 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 bool LDConfigParser::findToken (short& result, char const* needle, short args) {
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
157 for (ushort i = 0; i < (m_tokens.size() - args); ++i) {
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 if (m_tokens[i] == needle) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 result = i;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 return true;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 return false;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
167 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
169 void LDConfigParser::rewind() {
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 m_pos = -1;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
173 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 void LDConfigParser::seek (short amount, bool rel) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 m_pos = (rel ? m_pos : 0) + amount;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
179 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 // -----------------------------------------------------------------------------
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
181 size_t LDConfigParser::size() {
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 return m_tokens.size();
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 }
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
185 // =============================================================================
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 // -----------------------------------------------------------------------------
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 bool LDConfigParser::tokenCompare (short inPos, const char* sOther) {
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 str tok;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 if (!getToken (tok, inPos))
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 return false;
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 return (tok == sOther);
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 }

mercurial