src/ldConfig.cc

changeset 714
b4a990f59a5e
parent 662
2f1bd9112408
child 739
152b33a6d51b
equal deleted inserted replaced
713:46377d340c23 714:b4a990f59a5e
30 static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, QString& val) 30 static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, QString& val)
31 { 31 {
32 int pos; 32 int pos;
33 33
34 // Try find the token and get its position 34 // Try find the token and get its position
35 if (!pars.findToken (pos, tag, 1)) 35 if (not pars.findToken (pos, tag, 1))
36 return false; 36 return false;
37 37
38 // Get the token after it and store it into val 38 // Get the token after it and store it into val
39 return pars.getToken (val, pos + 1); 39 return pars.getToken (val, pos + 1);
40 } 40 }
43 // 43 //
44 void parseLDConfig() 44 void parseLDConfig()
45 { 45 {
46 QFile* fp = openLDrawFile ("LDConfig.ldr", false); 46 QFile* fp = openLDrawFile ("LDConfig.ldr", false);
47 47
48 if (!fp) 48 if (fp == null)
49 { 49 {
50 critical (QObject::tr ("Unable to open LDConfig.ldr for parsing.")); 50 critical (QObject::tr ("Unable to open LDConfig.ldr for parsing."));
51 return; 51 return;
52 } 52 }
53 53
54 // Read in the lines 54 // Read in the lines
55 while (fp->atEnd() == false) 55 while (not fp->atEnd())
56 { 56 {
57 QString line = QString::fromUtf8 (fp->readLine()); 57 QString line = QString::fromUtf8 (fp->readLine());
58 58
59 if (line.isEmpty() || line[0] != '0') 59 if (line.isEmpty() || line[0] != '0')
60 continue; // empty or illogical 60 continue; // empty or illogical
67 67
68 int code = 0, alpha = 255; 68 int code = 0, alpha = 255;
69 QString name, facename, edgename, valuestr; 69 QString name, facename, edgename, valuestr;
70 70
71 // Check 0 !COLOUR, parse the name 71 // Check 0 !COLOUR, parse the name
72 if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (name, 2)) 72 if (not pars.tokenCompare (0, "0") ||
73 continue; 73 not pars.tokenCompare (1, "!COLOUR") ||
74 not pars.getToken (name, 2))
75 {
76 continue;
77 }
74 78
75 // Replace underscores in the name with spaces for readability 79 // Replace underscores in the name with spaces for readability
76 name.replace ("_", " "); 80 name.replace ("_", " ");
77 81
78 // Get the CODE tag 82 // Get the CODE tag
79 if (!parseLDConfigTag (pars, "CODE", valuestr)) 83 if (not parseLDConfigTag (pars, "CODE", valuestr))
80 continue; 84 continue;
81 85
82 if (!numeric (valuestr)) 86 if (not numeric (valuestr))
83 continue; // not a number 87 continue; // not a number
84 88
85 // Ensure that the code is within [0 - 511] 89 // Ensure that the code is within [0 - 511]
86 bool ok; 90 bool ok;
87 code = valuestr.toShort (&ok); 91 code = valuestr.toShort (&ok);
88 92
89 if (!ok || code < 0 || code >= 512) 93 if (not ok || code < 0 || code >= 512)
90 continue; 94 continue;
91 95
92 // VALUE and EDGE tags 96 // VALUE and EDGE tags
93 if (!parseLDConfigTag (pars, "VALUE", facename) || !parseLDConfigTag (pars, "EDGE", edgename)) 97 if (not parseLDConfigTag (pars, "VALUE", facename) || not parseLDConfigTag (pars, "EDGE", edgename))
94 continue; 98 continue;
95 99
96 // Ensure that our colors are correct 100 // Ensure that our colors are correct
97 QColor faceColor (facename), 101 QColor faceColor (facename),
98 edgeColor (edgename); 102 edgeColor (edgename);
99 103
100 if (!faceColor.isValid() || !edgeColor.isValid()) 104 if (not faceColor.isValid() || not edgeColor.isValid())
101 continue; 105 continue;
102 106
103 // Parse alpha if given. 107 // Parse alpha if given.
104 if (parseLDConfigTag (pars, "ALPHA", valuestr)) 108 if (parseLDConfigTag (pars, "ALPHA", valuestr))
105 alpha = clamp (valuestr.toInt(), 0, 255); 109 alpha = clamp (valuestr.toInt(), 0, 255);
206 // 210 //
207 bool LDConfigParser::tokenCompare (int inPos, const char* sOther) 211 bool LDConfigParser::tokenCompare (int inPos, const char* sOther)
208 { 212 {
209 QString tok; 213 QString tok;
210 214
211 if (!getToken (tok, inPos)) 215 if (not getToken (tok, inPos))
212 return false; 216 return false;
213 217
214 return (tok == sOther); 218 return (tok == sOther);
215 } 219 }

mercurial