src/ldconfig.cpp

Wed, 16 Oct 2013 23:20:35 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 16 Oct 2013 23:20:35 +0300
changeset 508
7ace3537a560
parent 498
791c831c8020
child 538
2f85d4d286e5
permissions
-rw-r--r--

removed some custom functions in favor of Qt implementations

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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
28 static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, str& val)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
29 { short pos;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
41 void parseLDConfig()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
42 { File* f = openLDrawFile ("LDConfig.ldr", false);
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
43
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
44 if (!f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
45 { critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing! (%1)"),
421
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 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
49
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // Read in the lines
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
51 for (str line : *f)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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');
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
57
406
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, ' ');
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
60
406
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
63
406
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
67
406
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 ("_", " ");
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
70
406
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
74
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
75 if (!numeric (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
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
77
406
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);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
84
406
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
88
406
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);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
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;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
95
406
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);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
99
406
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 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
109
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
115 LDConfigParser::LDConfigParser (str inText, char sep)
496
d6cbf21af8fb nuked "container_cast"
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
116 { m_tokens = inText.split (sep, QString::SkipEmptyParts);
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
122 bool LDConfigParser::atBeginning()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
123 { return (m_pos == -1);
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
128 bool LDConfigParser::atEnd()
496
d6cbf21af8fb nuked "container_cast"
Santeri Piippo <crimsondusk64@gmail.com>
parents: 493
diff changeset
129 { return (m_pos == 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 // -----------------------------------------------------------------------------
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 496
diff changeset
134 bool LDConfigParser::getToken (str& val, const int pos)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
135 { if (pos >= m_tokens.size())
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
137
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
144 bool LDConfigParser::next (str& val)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
145 { return getToken (val, ++m_pos);
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
150 bool LDConfigParser::peekNext (str& val)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
151 { return getToken (val, m_pos + 1);
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
156 bool LDConfigParser::findToken (short& result, char const* needle, short args)
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 496
diff changeset
157 { for (int i = 0; i < (m_tokens.size() - args); ++i)
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
158 { if (m_tokens[i] == needle)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
159 { result = i;
406
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 }
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
163
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
169 void LDConfigParser::rewind()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
170 { m_pos = -1;
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
175 void LDConfigParser::seek (short amount, bool rel)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
176 { m_pos = (rel ? m_pos : 0) + amount;
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
181 size_t LDConfigParser::size()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
182 { return m_tokens.size();
406
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 // -----------------------------------------------------------------------------
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
187 bool LDConfigParser::tokenCompare (short inPos, const char* sOther)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
188 { str tok;
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
189
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 if (!getToken (tok, inPos))
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 return false;
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
192
406
5371baa17346 Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 return (tok == sOther);
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 483
diff changeset
194 }

mercurial