76 return pars.getToken (val, pos + 1); |
76 return pars.getToken (val, pos + 1); |
77 } |
77 } |
78 |
78 |
79 // ============================================================================= |
79 // ============================================================================= |
80 void parseLDConfig () { |
80 void parseLDConfig () { |
81 FILE* fp = openLDrawFile ("LDConfig.ldr", false); |
81 File* f = openLDrawFile ("LDConfig.ldr", false); |
82 |
82 |
83 if (!fp) { |
83 if (!*f) { |
84 critical (fmt ("Unable to open LDConfig.ldr for parsing! (%1)", strerror (errno))); |
84 critical (fmt ("Unable to open LDConfig.ldr for parsing! (%1)", strerror (errno))); |
|
85 delete f; |
85 return; |
86 return; |
86 } |
87 } |
87 |
88 |
88 // Read in the lines |
89 // Read in the lines |
89 char buf[1024]; |
90 for (str line : *f) { |
90 while (fgets (buf, sizeof buf, fp)) { |
91 if (line.length () == 0 || line[0] != '0') |
91 if (strlen (buf) == 0 || buf[0] != '0') |
|
92 continue; // empty or illogical |
92 continue; // empty or illogical |
93 |
93 |
94 // Use StringParser to parse the LDConfig.ldr file. |
|
95 str line = buf; |
|
96 line.remove ('\r'); |
94 line.remove ('\r'); |
97 line.remove ('\n'); |
95 line.remove ('\n'); |
|
96 |
|
97 // Parse the line |
98 StringParser pars (line, ' '); |
98 StringParser pars (line, ' '); |
99 |
99 |
100 short code = 0, alpha = 255; |
100 short code = 0, alpha = 255; |
101 str name, facename, edgename, valuestr; |
101 str name, facename, edgename, valuestr; |
102 |
102 |