/* SAction::initActions * Loads and parses all SActions configured in actions.cfg in the * program resource archive *******************************************************************/ bool SAction::initActions() { // Get actions.cfg from slade.pk3 auto cfg_entry = theArchiveManager->programResourceArchive()->entryAtPath("actions.cfg"); if (!cfg_entry) return false; Parser parser(cfg_entry->getParentDir()); if (parser.parseText(cfg_entry->getMCData(), "actions.cfg")) { auto root = parser.parseTreeRoot(); for (unsigned a = 0; a < root->nChildren(); a++) { auto node = root->getChildPTN(a); // Single action if (S_CMPNOCASE(node->type(), "action")) { auto action = new SAction(node->getName(), node->getName()); if (action->parse(node)) actions.push_back(action); else delete action; } // Group of actions else if (S_CMPNOCASE(node->getName(), "group")) { int group = newGroup(); for (unsigned b = 0; b < node->nChildren(); b++) { auto group_node = node->getChildPTN(b); if (S_CMPNOCASE(group_node->type(), "action")) { auto action = new SAction(group_node->getName(), group_node->getName()); if (action->parse(group_node)) { action->group = group; actions.push_back(action); } else delete action; } } } } } return true; }
// ---------------------------------------------------------------------------- // ParseTreeNode::parsePreprocessor // // Parses a preprocessor directive at [tz]'s current token // ---------------------------------------------------------------------------- bool ParseTreeNode::parsePreprocessor(Tokenizer& tz) { //Log::debug(S_FMT("Preprocessor %s", CHR(tz.current().text))); // #define if (tz.current() == "#define") parser_->define(tz.next().text); // #if(n)def else if (tz.current() == "#ifdef" || tz.current() == "#ifndef") { // Continue if condition succeeds bool test = true; if (tz.current() == "#ifndef") test = false; string define = tz.next().text; if (parser_->defined(define) == test) return true; // Failed condition, skip section int skip = 0; while (true) { auto& token = tz.next(); if (token == "#endif") skip--; else if (token == "#ifdef") skip++; else if (token == "#ifndef") skip++; // TODO: #else if (skip < 0) break; } } // #include else if (tz.current() == "#include") { // Include entry at the given path if we have an archive dir set if (archive_dir_) { // Get entry to include auto inc_path = tz.next().text; auto archive = archive_dir_->archive(); auto inc_entry = archive->entryAtPath(archive_dir_->getPath() + inc_path); if (!inc_entry) // Try absolute path inc_entry = archive->entryAtPath(inc_path); //Log::debug(S_FMT("Include %s", CHR(inc_path))); if (inc_entry) { // Save the current dir and set it to the included entry's dir auto orig_dir = archive_dir_; archive_dir_ = inc_entry->getParentDir(); // Parse text in the entry Tokenizer inc_tz; inc_tz.openMem(inc_entry->getMCData(), inc_entry->getName()); bool ok = parse(inc_tz); // Reset dir and abort if parsing failed archive_dir_ = orig_dir; if (!ok) return false; } else logError(tz, S_FMT("Include entry %s not found", CHR(inc_path))); } else tz.adv(); // Skip include path } // #endif (ignore) else if (tz.current() == "#endif") return true; // TODO: #else // Unrecognised else logError(tz, S_FMT("Unrecognised preprocessor directive \"%s\"", CHR(tz.current().text))); return true; }
/* ArchiveEntry::getData * Returns a pointer to the entry data. If no entry data exists and * allow_load is true, entry data will be loaded from its parent * archive (if it exists) *******************************************************************/ const uint8_t* ArchiveEntry::getData(bool allow_load) { // Return entry data return getMCData(allow_load).getData(); }