| 100 | |
| 101 | |
| 102 | bool cInitFile::loadFile(const cString& filename, Apto::Array<sLine*, Apto::Smart>& lines, const cString& working_dir, |
| 103 | const Apto::Set<Apto::String>* custom_directives, Feedback& feedback) |
| 104 | { |
| 105 | cString path = cString(Apto::FileSystem::GetAbsolutePath(Apto::String(filename), Apto::String(working_dir))); |
| 106 | cFile file(path); |
| 107 | if (!file.IsOpen()) { |
| 108 | feedback.Error("unable to open file '%s'.", (const char*)filename); |
| 109 | return false; // The file must be opened! |
| 110 | } |
| 111 | |
| 112 | m_found = true; |
| 113 | |
| 114 | cStringList line_list; // Create a list to load all of the lines into. |
| 115 | |
| 116 | int linenum = 0; |
| 117 | cString buf; |
| 118 | while (!file.Eof() && file.ReadLine(buf)) { |
| 119 | linenum++; |
| 120 | |
| 121 | // Perform variable substitution |
| 122 | for (Apto::Map<Apto::String, Apto::String>::Iterator it = m_mappings.Begin(); it.Next() != NULL;) { |
| 123 | Apto::String varname = Apto::FormatStr("$%s", (const char*)it.Get()->Value1()); |
| 124 | buf.Replace((const char*)varname, (const char*)*it.Get()->Value2()); |
| 125 | } |
| 126 | |
| 127 | // Process the line |
| 128 | if (buf.GetSize() && buf[0] == '#') { |
| 129 | if (!processCommand(buf, lines, filename, linenum, working_dir, custom_directives, feedback)) return false; |
| 130 | } else { |
| 131 | lines.Push(new sLine(buf, filename, linenum)); |
| 132 | } |
| 133 | } |
| 134 | file.Close(); |
| 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | bool cInitFile::processCommand(cString cmdstr, Apto::Array<sLine*, Apto::Smart>& lines, const cString& filename, int linenum, |
nothing calls this directly
no test coverage detected