| 215 | |
| 216 | |
| 217 | void cInitFile::postProcess(Apto::Array<sLine*, Apto::Smart>& lines) |
| 218 | { |
| 219 | m_mappings.Clear(); |
| 220 | m_imported_files.Clear(); |
| 221 | |
| 222 | // We're going to handle this compression in multiple passes to make it |
| 223 | // clean and easy. |
| 224 | |
| 225 | const int num_lines = lines.GetSize(); |
| 226 | |
| 227 | // PASS 1: Remove all comments -- everything after a '#' sign -- and |
| 228 | // compress all whitespace into a single space. |
| 229 | for (int i = 0; i < num_lines; i++) { |
| 230 | cString& cur_line = lines[i]->line; |
| 231 | |
| 232 | // Remove all characters past a comment mark and reduce whitespace. |
| 233 | int comment_pos = cur_line.Find('#'); |
| 234 | if (comment_pos >= 0) cur_line.Clip(comment_pos); |
| 235 | cur_line.CompressWhitespace(); |
| 236 | } |
| 237 | |
| 238 | // PASS 2: Merge each line ending with a continue marker '\' with the |
| 239 | // next line. |
| 240 | |
| 241 | int prev_line_id = -1; |
| 242 | bool continued = false; |
| 243 | for (int i = 0; i < num_lines; i++) { |
| 244 | // If the current line is a continuation, append it to the previous line. |
| 245 | if (continued == true) { |
| 246 | lines[prev_line_id]->line += lines[i]->line; |
| 247 | lines[i]->line = ""; |
| 248 | } |
| 249 | else prev_line_id = i; |
| 250 | |
| 251 | // See if the prev_line is continued, and if it is, take care of it. |
| 252 | cString& prev_line = lines[prev_line_id]->line; |
| 253 | if (prev_line.GetSize() > 0 && prev_line[prev_line.GetSize() - 1] == '\\') { |
| 254 | prev_line.ClipEnd(1); // Remove continuation mark. |
| 255 | continued = true; |
| 256 | } |
| 257 | else continued = false; |
| 258 | } |
| 259 | |
| 260 | // PASS 3: Remove now-empty lines. |
| 261 | |
| 262 | int next_id = 0; |
| 263 | for (int i = 0; i < num_lines; i++) { |
| 264 | // If we should keep this line, compact it. |
| 265 | if (lines[i]->line.GetSize() > 0) { |
| 266 | if (next_id != i) { |
| 267 | delete lines[next_id]; |
| 268 | lines[next_id] = lines[i]; |
| 269 | lines[i] = NULL; |
| 270 | } |
| 271 | next_id++; |
| 272 | } |
| 273 | } |
| 274 |
nothing calls this directly
no test coverage detected