Thu, 01 Aug 2013 03:50:13 +0300
some further little optimization
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 |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | static bool parseLDConfigTag( LDConfigParser& pars, char const* tag, str& val ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | short pos; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
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 |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | if( !pars.findToken( pos, tag, 1 )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | return false; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
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 |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | return pars.getToken( val, pos + 1 ); |
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 | // ============================================================================= |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | void parseLDConfig() |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | File* f = openLDrawFile( "LDConfig.ldr", false ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | if( !f ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | critical( fmt( QObject::tr( "Unable to open LDConfig.ldr for parsing! (%1)" ), |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | strerror( errno )) ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | delete f; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | return; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // Read in the lines |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | for( str line : *f ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | if( line.length() == 0 || line[0] != '0' ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | continue; // empty or illogical |
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 | line.remove( '\r' ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | line.remove( '\n' ); |
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 | // Parse the line |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | LDConfigParser pars( line, ' ' ); |
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 | short code = 0, alpha = 255; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | str name, facename, edgename, valuestr; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | // Check 0 !COLOUR, parse the name |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | if( !pars.tokenCompare( 0, "0" ) || !pars.tokenCompare( 1, "!COLOUR" ) || !pars.getToken( name, 2 )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | continue; |
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 | // Replace underscores in the name with spaces for readability |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | name.replace( "_", " " ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | // Get the CODE tag |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | if( !parseLDConfigTag( pars, "CODE", valuestr )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | continue; |
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 | if( !isNumber( valuestr )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | continue; // not a number |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | // 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
|
82 | bool ok; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | code = valuestr.toShort( &ok ); |
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 | if( !ok || code < 0 || code >= 512 ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | continue; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | // VALUE and EDGE tags |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | if( !parseLDConfigTag( pars, "VALUE", facename ) || !parseLDConfigTag( pars, "EDGE", edgename )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | continue; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | // Ensure that our colors are correct |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | QColor faceColor( facename ), |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | edgeColor( edgename ); |
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 | if( !faceColor.isValid() || !edgeColor.isValid() ) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | continue; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // Parse alpha if given. |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | if( parseLDConfigTag( pars, "ALPHA", valuestr )) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | alpha = clamp<short> ( valuestr.toShort(), 0, 255 ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | LDColor* col = new LDColor; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | col->name = name; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | col->faceColor = faceColor; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | col->edgeColor = edgeColor; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | col->hexcode = facename; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | col->faceColor.setAlpha( alpha ); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | col->index = code; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | setColor( code, col ); |
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 | delete f; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | // ============================================================================= |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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 | LDConfigParser::LDConfigParser (str inText, char sep) { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | 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
|
121 | m_pos = -1; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
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 | bool LDConfigParser::atBeginning () { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | return (m_pos == -1); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | bool LDConfigParser::atEnd () { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | return (m_pos == (signed) m_tokens.size () - 1); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
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 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | 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
|
136 | if (pos >= m_tokens.size()) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | return false; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | val = m_tokens[pos]; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | return true; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
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 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | bool LDConfigParser::peekNext (str& val) { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | return getToken (val, m_pos + 1); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | } |
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 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | bool LDConfigParser::findToken (short& result, char const* needle, short args) { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | for (ushort i = 0; i < (m_tokens.size () - args); ++i) { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | if (m_tokens[i] == needle) { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | result = i; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | return true; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
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 | return false; |
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 | |
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 | void LDConfigParser::rewind () { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | m_pos = -1; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | 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
|
172 | 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
|
173 | } |
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 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | size_t LDConfigParser::size () { |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | return m_tokens.size(); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | // ----------------------------------------------------------------------------- |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | 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
|
182 | str tok; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | if (!getToken (tok, inPos)) |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | return false; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | return (tok == sOther); |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | } |