| 138 | |
| 139 | |
| 140 | bool cInitFile::processCommand(cString cmdstr, Apto::Array<sLine*, Apto::Smart>& lines, const cString& filename, int linenum, |
| 141 | const cString& working_dir, const Apto::Set<Apto::String>* custom_directives, Feedback& feedback) |
| 142 | { |
| 143 | cString cmd = cmdstr.PopWord(); |
| 144 | |
| 145 | if (cmd == "#include" || cmd == "#import") { |
| 146 | cString path = cmdstr.PopWord(); |
| 147 | cString mapping; |
| 148 | |
| 149 | // Grab mapping name, if specified |
| 150 | if (path.Find('=') >= 0) { |
| 151 | mapping = path.Pop('='); |
| 152 | } |
| 153 | |
| 154 | // Strip quotes |
| 155 | if (path[0] == '<' || path[0] == '"') { |
| 156 | int lidx = path.GetSize() - 1; |
| 157 | if ((path[0] == '"' && path[lidx] != '"') || (path[0] == '<' && path[lidx] != '>')) { |
| 158 | feedback.Error("%s:%d: syntax error processing include directive", (const char*)filename, linenum); |
| 159 | return false; |
| 160 | } |
| 161 | path = path.Substring(1, path.GetSize() - 2); |
| 162 | } |
| 163 | |
| 164 | // Handle mapping, if specified |
| 165 | Apto::String aPath; |
| 166 | if (mapping.GetSize() && m_mappings.Get((const char*)mapping, aPath)) path = (const char*)aPath; |
| 167 | |
| 168 | if (cmd != "#import" || !m_imported_files.HasString(path)) { |
| 169 | // Attempt to include the specified file |
| 170 | if (!loadFile(path, lines, working_dir, custom_directives, feedback)) { |
| 171 | feedback.Error("%s:%d: unable to process include directive", (const char*)filename, linenum); |
| 172 | return false; |
| 173 | } |
| 174 | } |
| 175 | } else if (cmd == "#filetype") { |
| 176 | cString ft = cmdstr.PopWord(); |
| 177 | if (m_ftype != "unknown" && m_ftype != ft) { |
| 178 | feedback.Error("%s:%d: duplicate filetype directive", (const char*)filename, linenum); |
| 179 | return false; |
| 180 | } |
| 181 | m_ftype = ft; |
| 182 | } else if (cmd == "#format") { |
| 183 | if (m_format.GetSize() != 0) { |
| 184 | feedback.Error("%s:%d: duplicate format directive", (const char*)filename, linenum); |
| 185 | return false; |
| 186 | } |
| 187 | m_format.Load(cmdstr); |
| 188 | } else if (cmd == "#define") { |
| 189 | cString mapping = cmdstr.PopWord(); |
| 190 | if (mapping.GetSize()) { |
| 191 | cString value = cmdstr.PopWord(); |
| 192 | value.Trim(); |
| 193 | |
| 194 | Apto::String aValue((const char*)value); |
| 195 | if (aValue.GetSize()) { |
| 196 | m_mappings.Set((const char*)mapping, aValue); |
| 197 | } else { |