static bool OpenIncludeFile(const std::string& includeFileFullPath, char*& pFileBuffer, unsigned& fileSizeInBytes) { bool ret = false; // Open the file. std::ifstream includeFile(includeFileFullPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate); if (includeFile.is_open()) { // Get the file size. fileSizeInBytes = (unsigned int)includeFile.tellg(); if (fileSizeInBytes > 0) { // Allocate the buffer. pFileBuffer = new char[fileSizeInBytes]; // Read the file's contents into the buffer. includeFile.seekg(0, std::ios::beg); includeFile.read(pFileBuffer, fileSizeInBytes); // Close the file. includeFile.close(); // We are done. ret = true; } } return ret; }
/* * Call either include "includeFile" or "includeLine". * If fin is stdin include one line. Otherwise include the whole file. */ SrcLineList include(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont) { if (fnameIsStdin(fn) && fin) return includeLine(fn, fin, plineno, iscont); else return includeFile(fn); }
static void initialize() { commentOnlyObjectName(); commentOnlyObjectText(); version(); header(); commentOnlyLine(); contentAndCommentLine(); group(); includeFile(); removeObject(); line(); memoProperty(); noteProperty(); objectNoFields(); objectAndFields(); uniqueProperty(); requiredObjectProperty(); obsoleteProperty(); hasurlProperty(); extensibleProperty(); formatProperty(); minFieldsProperty(); maxFieldsProperty(); field(); closingField(); lastField(); name(); nameProperty(); requiredFieldProperty(); autosizableProperty(); autocalculatableProperty(); retaincaseProperty(); unitsProperty(); ipUnitsProperty(); minExclusiveProperty(); minInclusiveProperty(); maxExclusiveProperty(); maxInclusiveProperty(); deprecatedProperty(); defaultProperty(); automaticDefault(); typeProperty(); keyProperty(); objectListProperty(); externalListProperty(); referenceProperty(); beginExtensible(); beginExtensibleProperty(); metaDataComment(); versionObjectName(); }
void Parser::parseFile(DeckPtr deck, const boost::filesystem::path& file, const boost::filesystem::path& rootPath, bool parseStrict) const { bool verbose = false; std::ifstream inputstream; size_t lineNR = 0; inputstream.open(file.string().c_str()); if (inputstream) { RawKeywordPtr rawKeyword; while (tryParseKeyword(deck, file.string() , lineNR , inputstream, rawKeyword, parseStrict)) { if (rawKeyword->getKeywordName() == Opm::RawConsts::include) { RawRecordConstPtr firstRecord = rawKeyword->getRecord(0); std::string includeFileString = firstRecord->getItem(0); boost::filesystem::path includeFile(includeFileString); if (includeFile.is_relative()) includeFile = rootPath / includeFile; if (verbose) std::cout << rawKeyword->getKeywordName() << " " << includeFile << std::endl; parseFile(deck, includeFile, rootPath , parseStrict); } else { if (verbose) std::cout << rawKeyword->getKeywordName() << std::endl; if (hasKeyword(rawKeyword->getKeywordName())) { ParserKeywordConstPtr parserKeyword = m_parserKeywords.at(rawKeyword->getKeywordName()); ParserKeywordActionEnum action = parserKeyword->getAction(); if (action == INTERNALIZE) { DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword); deck->addKeyword(deckKeyword); } else if (action == IGNORE_WARNING) deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is ignored - this might potentially affect the results" , file.string() , rawKeyword->getLineNR()); } else { DeckKeywordConstPtr deckKeyword(new DeckKeyword(rawKeyword->getKeywordName(), false)); deck->addKeyword(deckKeyword); deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is not recognized" , file.string() , lineNR); } } rawKeyword.reset(); } inputstream.close(); } else throw std::invalid_argument("Failed to open file: " + file.string()); }
void TemplateDocumentPrivate::processTemplateIncludes(QString &input) { QRegExp rx("%!\\{([^}]*)\\}%"); QStringList includes; int pos = 0; while ((pos = rx.indexIn(input, pos)) != -1) { includes << rx.cap(1); pos += rx.matchedLength(); } for (const QString &include: includes) { QFile includeFile(QLatin1String(":/htmlfeatures/includes/") + include + QLatin1String(".inc")); if (includeFile.open(QIODevice::ReadOnly)) { input.replace(QLatin1String("%!{") + include + QLatin1String("}%"), includeFile.readAll()); } else { mDebug() << "[WARNING] Can't process template include" << include; } } }
// ************************************************************** //! \param idPrimitive the token of a primitive else an exception //! is triggered. //! UnknownForthPrimitive if idPrimitive is not the token of a //! primitive (idPrimitive >= NUM_PRIMITIVES). //! \throw UnfinishedStream called by Forth::nextWord() if the //! stream does not contain a Forth word. //! \throw UnknownForthWord if the extracted word by Forth::nextWord() //! is not present in the dictionary. //! \throw AbortForth if triggered by the Forth word ABORT. //! \throw ModifiedStackDepth if the data stack depth is modified //! during a definition. //! \throw OutOfBoundDictionary if attempting to store data outside //! the dictionary bounds. //! \throw NoSpaceDictionary if attempting to add a new entry in a //! full dictionary. // ************************************************************** void Forth::execPrimitive(const Cell16 idPrimitive) { //std::cout << "execPrimitive " << idPrimitive << std::endl; switch (idPrimitive) { // Dummy word / No operation case FORTH_PRIMITIVE_NOP: std::cout << "NOP\n"; break; // Begin of commentary case FORTH_PRIMITIVE_LPARENTHESIS: m_saved_state = m_state; m_state = forth::Comment; break; // End of commentary case FORTH_PRIMITIVE_RPARENTHESIS: m_state = m_saved_state; break; // Line of commentary case FORTH_PRIMITIVE_COMMENTARY: STREAM.skipLine(); break; // Begin the definition of a new word case FORTH_PRIMITIVE_COLON: create(nextWord()); m_state = forth::Compile; break; // End the definition of a new word case FORTH_PRIMITIVE_SEMICOLON: m_dictionary.appendCell16(FORTH_PRIMITIVE_EXIT); m_state = forth::Interprete; if (m_depth_at_colon != stackDepth(forth::DataStack)) { m_dictionary.m_last = m_last_at_colon; m_dictionary.m_here = m_here_at_colon; ModifiedStackDepth e(m_creating_word); throw e; } break; // Push in data stack the next free slot in the dictionary case FORTH_PRIMITIVE_PCREATE: DPUSH(m_tos); m_tos = m_ip + 4U; break; // Give a name to the next free slot in the dictionary. // (note: HERE is not moved) // https://fr.wikiversity.org/wiki/Forth/Conserver_des_donn%C3%A9es case FORTH_PRIMITIVE_CREATE: create(nextWord()); m_dictionary.appendCell16(FORTH_PRIMITIVE_PCREATE); m_dictionary.appendCell16(FORTH_PRIMITIVE_EXIT); break; case FORTH_PRIMITIVE_BUILDS: create(nextWord()); break; case FORTH_PRIMITIVE_DOES: break; // Set immediate the last word case FORTH_PRIMITIVE_IMMEDIATE: m_dictionary.m_dictionary[m_dictionary.m_last] |= FLAG_IMMEDIATE; break; case FORTH_PRIMITIVE_INCLUDE: // Restore TOS register (because execToken() poped TOS) DPUSH(m_tos); includeFile(nextWord()); DPOP(m_tos); break; case FORTH_PRIMITIVE_STATE: DPUSH(m_tos); m_tos = m_state; break; case FORTH_PRIMITIVE_TRACE_ON: LOGI("Forth trace: ON"); m_trace = true; break; case FORTH_PRIMITIVE_TRACE_OFF: LOGI("Forth trace: OFF"); m_trace = false; break; case FORTH_PRIMITIVE_SMUDGE: { std::string const& word = nextWord(); if (false == m_dictionary.smudge(word)) { std::cout << FORTH_WARNING_COLOR << "[WARNING] Unknown word '" << word << "'. Word SMUDGE Ignored !" << FORTH_NORMAL_COLOR << std::endl; } } break; case FORTH_PRIMITIVE_TICK: { std::string const& word = nextWord(); Cell16 token; bool immediate; if (false == m_dictionary.find(word, token, immediate)) { token = 0; std::cout << FORTH_WARNING_COLOR << "[WARNING] Unknown word '" << word << "'. Word TICK Ignored !" << FORTH_NORMAL_COLOR << std::endl; } DPUSH(m_tos); m_tos = token; } break; case FORTH_PRIMITIVE_COMPILE: m_ip += 2; m_dictionary.appendCell16(m_dictionary.read16at(m_ip)); break; // Append to the dictionary the next word case FORTH_PRIMITIVE_ICOMPILE: { Cell16 token; bool immediate; std::string const& word = nextWord(); //m_ip += 2; if (m_dictionary.find(word, token, immediate)) { m_dictionary.appendCell16(token); } else { UnknownForthWord e(word); throw e; } } break; // ANSI word to replace [COMPILE] and COMPILE case FORTH_PRIMITIVE_POSTPONE: { Cell16 token; bool immediate; std::string const& word = nextWord(); if (m_dictionary.find(word, token, immediate)) { if (immediate) { m_dictionary.appendCell16(token); } else { m_ip += 2; m_dictionary.appendCell16(m_dictionary.read16at(m_ip)); } } else { UnknownForthWord e(word); throw e; } } break; case FORTH_PRIMITIVE_ABORT: abort("COUCOU"); break; case FORTH_PRIMITIVE_EXECUTE: execToken(m_tos); break; case FORTH_PRIMITIVE_LBRACKET: m_state = forth::Interprete; break; case FORTH_PRIMITIVE_RBRACKET: m_state = forth::Compile; break; case FORTH_PRIMITIVE_HERE: DPUSH(m_tos); m_tos = m_dictionary.here(); break; case FORTH_PRIMITIVE_LAST: DPUSH(m_tos); m_tos = m_dictionary.last(); break; case FORTH_PRIMITIVE_ALLOT: m_dictionary.allot((int32_t) m_tos); DPOP(m_tos); break; // Reserve one cell of data space and store x in the cell. case FORTH_PRIMITIVE_COMMA32: m_dictionary.appendCell32(m_tos); DPOP(m_tos); break; // Reserve one cell of data space and store x in the cell. case FORTH_PRIMITIVE_COMMA16: m_dictionary.appendCell16(m_tos); DPOP(m_tos); break; // Reserve one cell of data space and store x in the cell. case FORTH_PRIMITIVE_COMMA8: m_dictionary.appendCell8(m_tos); DPOP(m_tos); break; // ( a-addr -- x ) // x is the value stored at a-addr. case FORTH_PRIMITIVE_FETCH: m_tos = m_dictionary.read32at(m_tos); break; // Store x at a-addr. // ( x a-addr -- ) case FORTH_PRIMITIVE_STORE32: DPOP(m_tos1); m_dictionary.write32at(m_tos, m_tos1); DPOP(m_tos); break; case FORTH_PRIMITIVE_STORE16: DPOP(m_tos1); m_dictionary.write16at(m_tos, m_tos1); DPOP(m_tos); break; case FORTH_PRIMITIVE_STORE8: DPOP(m_tos1); m_dictionary.write8at(m_tos, m_tos1); DPOP(m_tos); break; /* ( src dst n -- ) */ case FORTH_PRIMITIVE_CMOVE: DPOP(m_tos2); // dst DPOP(m_tos1); // src m_dictionary.move(m_tos2, m_tos1, m_tos); DPOP(m_tos); break; /* case FORTH_PRIMITIVE_THROW: if (m_tos) { M_THROW(m_tos); } else DPOP(m_tos); break;*/ // Restore the IP when interpreting the definition // of a non primitive word case FORTH_PRIMITIVE_EXIT: RPOP(m_ip); if (m_trace) { std::cout << "POPed: " << std::hex << (int) m_ip << std::endl; } break; // Change IP case FORTH_PRIMITIVE_BRANCH: m_ip += m_dictionary.read16at(m_ip + 2U); // Do not forget that m_ip will be += 2 next iteration break; // Change IP if top of stack is 0 case FORTH_PRIMITIVE_0BRANCH: if (0 == m_tos) { m_ip += m_dictionary.read16at(m_ip + 2U); } else { m_ip += 2U; } // Do not forget that m_ip will be += 2 next iteration DPOP(m_tos); break; // Move x to the return stack. // ( x -- ) ( R: -- x ) case FORTH_PRIMITIVE_TO_RSTACK: RPUSH(m_tos); DPOP(m_tos); break; // Transfer cell pair x1 x2 to the return stack // ( x1 x2 -- ) ( R: -- x1 x2 ) case FORTH_PRIMITIVE_2TO_RSTACK: DPOP(m_tos1); RPUSH(m_tos1); RPUSH(m_tos); DPOP(m_tos); break; case FORTH_PRIMITIVE_FROM_RSTACK: DPUSH(m_tos); RPOP(m_tos); break; case FORTH_PRIMITIVE_2FROM_RSTACK: DPUSH(m_tos); RPOP(m_tos); RPOP(m_tos1); DPUSH(m_tos1); break; #if 0 case FORTH_PRIMITIVE_DO: std::cout << "(DO)" << std::endl; RPUSH(m_tos); DPOP(m_tos1); // FIXME: optim: RPUSH(DPOP); RPUSH(m_tos1); m_tos = DDROP(); break; case FORTH_PRIMITIVE_LOOP: std::cout << "(LOOP)" << std::endl; RPOP(m_tos1); /* limit */ RPOP(m_tos2); /* index */ ++m_tos2; if (m_tos2 == m_tos1) { ++m_ip; /* skip branch offset, exit loop */ } else { /* Push index and limit back to R */ RPUSH(m_tos2); RPUSH(m_tos1); /* Branch back to just after (DO) */ m_ip = m_dictionary.read16at(m_ip); } break; #endif case FORTH_PRIMITIVE_I: DPUSH(m_tos); m_tos = RPICK(0); break; case FORTH_PRIMITIVE_J: DPUSH(m_tos); m_tos = RPICK(2); break; case FORTH_PRIMITIVE_CELL: DPUSH(m_tos); m_tos = sizeof (Cell32); break; case FORTH_PRIMITIVE_CELLS: m_tos = m_tos * sizeof (Cell32); break; case FORTH_PRIMITIVE_LITERAL_16: DPUSH(m_tos); m_ip += 2U; // Skip primitive LITERAL m_tos = m_dictionary.read16at(m_ip); break; case FORTH_PRIMITIVE_LITERAL_32: DPUSH(m_tos); m_ip += 2U; // Skip primitive LITERAL m_tos = m_dictionary.read32at(m_ip); m_ip += 2U; // Skip the number - 2 because of next ip break; case FORTH_PRIMITIVE_1MINUS: --m_tos; break; case FORTH_PRIMITIVE_1PLUS: ++m_tos; break; case FORTH_PRIMITIVE_2MINUS: m_tos -= 2; break; case FORTH_PRIMITIVE_2PLUS: m_tos += 2; break; // drop ( a -- ) case FORTH_PRIMITIVE_DROP: DPOP(m_tos); break; case FORTH_PRIMITIVE_DEPTH: DPUSH(m_tos); m_tos = stackDepth(forth::DataStack); break; // nip ( a b -- b ) swap drop ; case FORTH_PRIMITIVE_NIP: DPOP(m_tos1); break; case FORTH_PRIMITIVE_ROLL: { m_tos1 = DPICK(m_tos); uint32_t *src = &DPICK(m_tos - 1); uint32_t *dst = &DPICK(m_tos); uint32_t ri = m_tos; while (ri--) { *dst-- = *src--; } m_tos = m_tos1; ++m_dsp; } break; // ( ... n -- sp(n) ) case FORTH_PRIMITIVE_PICK: m_tos = DPICK(m_tos); break; // dup ( a -- a a ) case FORTH_PRIMITIVE_DUP: DPUSH(m_tos); break; case FORTH_PRIMITIVE_QDUP: if (m_tos) { DPUSH(m_tos); } break; // swap ( a b -- b a ) case FORTH_PRIMITIVE_SWAP: m_tos2 = m_tos; DPOP(m_tos); DPUSH(m_tos2); break; // over ( a b -- a b a ) case FORTH_PRIMITIVE_OVER: DPUSH(m_tos); m_tos = DPICK(1); break; // rot ( a b c -- b c a ) case FORTH_PRIMITIVE_ROT: DPOP(m_tos2); DPOP(m_tos3); DPUSH(m_tos2); DPUSH(m_tos); m_tos = m_tos3; break; // tuck ( a b -- b a b ) swap over ; case FORTH_PRIMITIVE_TUCK: DPOP(m_tos2); DPUSH(m_tos); DPUSH(m_tos2); break; // 2dup ( a b -- a b a b ) over over ; case FORTH_PRIMITIVE_2DUP: DPUSH(m_tos); m_tos2 = DPICK(1); DPUSH(m_tos2); break; // 2over ( a b c d -- a b c d a b ) case FORTH_PRIMITIVE_2OVER: DPUSH(m_tos); m_tos2 = DPICK(3); DPUSH(m_tos2); m_tos = DPICK(3); break; // 2swap ( a b c d -- c d a b ) case FORTH_PRIMITIVE_2SWAP: DPOP(m_tos1); DPOP(m_tos2); DPOP(m_tos3); DPUSH(m_tos1); DPUSH(m_tos); DPUSH(m_tos3); m_tos = m_tos2; break; // 2drop ( a b -- ) drop drop ; case FORTH_PRIMITIVE_2DROP: DPOP(m_tos); DPOP(m_tos); break; // case FORTH_PRIMITIVE_BINARY: changeDisplayBase(2U); break; case FORTH_PRIMITIVE_OCTAL: changeDisplayBase(8U); break; case FORTH_PRIMITIVE_HEXADECIMAL: changeDisplayBase(16U); break; case FORTH_PRIMITIVE_DECIMAL: changeDisplayBase(10U); break; case FORTH_PRIMITIVE_GET_BASE: DPUSH(m_tos); m_tos = m_base; break; case FORTH_PRIMITIVE_SET_BASE: if (false == changeDisplayBase(m_tos)) { std::cerr << FORTH_WARNING_COLOR << "[WARNING] '" << m_tos << "' is an invalid base and shall be [2..36]. Ignored !" << FORTH_NORMAL_COLOR << std::endl; } break; case FORTH_PRIMITIVE_NEGATE: m_tos = -m_tos; break; case FORTH_PRIMITIVE_ABS: m_tos = std::abs((int32_t) m_tos); break; case FORTH_PRIMITIVE_PLUS: BINARY_OP(+); break; case FORTH_PRIMITIVE_MINUS: BINARY_OP(-); break; case FORTH_PRIMITIVE_DIV: BINARY_OP(/); break; case FORTH_PRIMITIVE_TIMES: BINARY_OP(*); break; case FORTH_PRIMITIVE_RSHIFT: BINARY_OP(>>); break; case FORTH_PRIMITIVE_LSHIFT: BINARY_OP(<<); break; case FORTH_PRIMITIVE_FALSE: m_tos = 0; DPUSH(m_tos); break; case FORTH_PRIMITIVE_TRUE: m_tos = -1; DPUSH(m_tos); break; case FORTH_PRIMITIVE_GREATER_EQUAL: LOGICAL_OP(>=); break; case FORTH_PRIMITIVE_LOWER_EQUAL: LOGICAL_OP(<=); break; case FORTH_PRIMITIVE_GREATER: LOGICAL_OP(>); break; case FORTH_PRIMITIVE_LOWER: LOGICAL_OP(<); break; case FORTH_PRIMITIVE_EQUAL: LOGICAL_OP(==); break; case FORTH_PRIMITIVE_0EQUAL: DPUSH(0U); LOGICAL_OP(==); break; case FORTH_PRIMITIVE_NOT_EQUAL: LOGICAL_OP(!=); break; case FORTH_PRIMITIVE_AND: BINARY_OP(&); break; case FORTH_PRIMITIVE_OR: BINARY_OP(|); break; case FORTH_PRIMITIVE_XOR: BINARY_OP(^); break; case FORTH_PRIMITIVE_MIN: DPOP(m_tos1); m_tos = ((int32_t) m_tos < (int32_t) m_tos1) ? m_tos : m_tos1; break; case FORTH_PRIMITIVE_MAX: DPOP(m_tos1); m_tos = ((int32_t) m_tos > (int32_t) m_tos1) ? m_tos : m_tos1; break; case FORTH_PRIMITIVE_DISP: std::cout << std::setbase(m_base) << (int32_t) m_tos << " "; DPOP(m_tos); break; case FORTH_PRIMITIVE_UDISP: std::cout << std::setbase(m_base) << (uint32_t) m_tos << " "; DPOP(m_tos); break; case FORTH_PRIMITIVE_CARRIAGE_RETURN: std::cout << std::endl; break; case FORTH_PRIMITIVE_DISPLAY_DSTACK: DPUSH(m_tos); displayStack(std::cout, forth::DataStack); DPOP(m_tos); break; case FORTH_PRIMITIVE_BEGIN_C_LIB: { std::pair<bool, std::string> res = m_dynamic_libs.begin(STREAM); if (!res.first) { abort(res.second); } } break; case FORTH_PRIMITIVE_END_C_LIB: { std::pair<bool, std::string> res = m_dynamic_libs.end(/*nth*/); // FIXME if (res.first) { uint16_t i = 0; for (auto it: m_dynamic_libs/*[nth]*/.m_functions) { create(it.func_forth_name); m_dictionary.appendCell16(FORTH_PRIMITIVE_EXEC_C_FUNC); m_dictionary.appendCell16(i); m_dictionary.appendCell16(FORTH_PRIMITIVE_EXIT); ++i; } } else { abort(res.second); } } break; case FORTH_PRIMITIVE_EXEC_C_FUNC: DPUSH(m_tos); m_ip += 2U; // Skip the index of pointer function m_tos = m_dictionary.read16at(m_ip); //std::cout << "Pile avant: "; //displayStack(std::cout, forth::DataStack); m_dynamic_libs/*[nth]*/.m_functions[m_tos].fun_ptr(&m_dsp); //std::cout << "Pile apres: "; //displayStack(std::cout, forth::DataStack); DPOP(m_tos); break; case FORTH_PRIMITIVE_C_FUNCTION: { std::pair<bool, std::string> res = m_dynamic_libs.function(STREAM); if (!res.first) { abort(res.second); } } break; case FORTH_PRIMITIVE_C_CODE: { std::pair<bool, std::string> res = m_dynamic_libs.code(STREAM); if (!res.first) { abort(res.second); } } break; case FORTH_PRIMITIVE_ADD_EXT_C_LIB: { std::pair<bool, std::string> res = m_dynamic_libs.extlib(STREAM); if (!res.first) { abort(res.second); } } break; default: UnknownForthPrimitive e(idPrimitive, __PRETTY_FUNCTION__); throw e; break; } }
inline bool readNode(SpriteNode* node, TiXmlElement* elemNode, TiXmlElement* elemParent, SpriteBlock* &oldSibling) { const char* strType = elemNode->Value(); if (strcmp(strType, "if") == 0 || strcmp(strType, "else") == 0) { SpriteBlock* block = new SpriteBlock(); if (!elemNode->Attribute("file") && elemParent->Attribute("file")) { elemNode->SetAttribute("file", elemParent->Attribute("file")); } if (!parseSpriteNode(block,elemNode)) { delete(block); return false; } if (elemNode->Attribute("else") || strcmp(strType, "else") == 0) { if (!oldSibling) { contentError("Misplaced or invalid element in SpriteNode",elemNode); return false; } oldSibling->addElse(block); } else { node->addChild(block); } oldSibling = block; } else if (strcmp(strType, "rotate") == 0) { RotationBlock* block = new RotationBlock(); if (!elemNode->Attribute("file") && elemParent->Attribute("file")) { elemNode->SetAttribute("file",elemParent->Attribute("file")); } if (!parseSpriteNode(block,elemNode)) { delete(block); return false; } else { node->addChild(block); } oldSibling = NULL; } else if ((strcmp(strType, "sprite") == 0) || (strcmp(strType, "empty") == 0)) { int fileindex = 0; const char* pfilename = elemParent->Attribute("file"); if (pfilename != NULL && pfilename[0] != 0) { fileindex = loadConfigImgFile((char*)pfilename,elemNode); } SpriteElement* sprite = new SpriteElement(); sprite->sprite.set_by_xml(elemNode, fileindex); node->addChild(sprite); } else if (strcmp(strType, "include") == 0) { if (!includeFile(node,elemNode,oldSibling)) { return false; } } else { contentError("Misplaced or invalid element in SpriteNode",elemNode); return false; } return true; }
inline bool readNode(SpriteNode* node, TiXmlElement* elemNode, TiXmlElement* elemParent, SpriteBlock* &oldSibling) { const char* strType = elemNode->Value(); if (strcmp(strType, "if") == 0 || strcmp(strType, "else") == 0) { SpriteBlock* block = new SpriteBlock(); if (!elemNode->Attribute("file") && elemParent->Attribute("file")) { elemNode->SetAttribute("file", elemParent->Attribute("file")); } if (!parseSpriteNode(block,elemNode)) { delete(block); return false; } if (elemNode->Attribute("else") || strcmp(strType, "else") == 0) { if (!oldSibling) { contentError("Misplaced or invalid element in SpriteNode",elemNode); return false; } oldSibling->addElse(block); } else { node->addChild(block); } oldSibling = block; } else if (strcmp(strType, "rotate") == 0) { RotationBlock* block = new RotationBlock(); if (!elemNode->Attribute("file") && elemParent->Attribute("file")) { elemNode->SetAttribute("file",elemParent->Attribute("file")); } if (!parseSpriteNode(block,elemNode)) { delete(block); return false; } else { node->addChild(block); } oldSibling = NULL; } else if ((strcmp(strType, "sprite") == 0) || (strcmp(strType, "empty") == 0)) { SpriteElement* sprite = new SpriteElement(); const char* strSheetIndex = elemNode->Attribute("index"); const char* strOffsetX = elemNode->Attribute("offsetx"); const char* strOffsetY = elemNode->Attribute("offsety"); const char* filename = elemNode->Attribute("file"); getAnimFrames(elemNode->Attribute("frames")); sprite->sprite.animFrames = getAnimFrames(elemNode->Attribute("frames")); if (sprite->sprite.animFrames == 0) sprite->sprite.animFrames = ALL_FRAMES; sprite->sprite.sheetIndex = (strSheetIndex != 0 ? atoi(strSheetIndex) : -1); sprite->sprite.x = (strOffsetX != 0 ? atoi(strOffsetX) : 0); sprite->sprite.y = (strOffsetY != 0 ? atoi(strOffsetY) : 0); sprite->sprite.fileIndex = -1; if (filename != NULL && filename[0] != 0) { sprite->sprite.fileIndex = loadConfigImgFile((char*)filename,elemNode); } else { const char* pfilename = elemParent->Attribute("file"); if (pfilename != NULL && pfilename[0] != 0) { sprite->sprite.fileIndex = loadConfigImgFile((char*)pfilename,elemNode); } } node->addChild(sprite); } else if (strcmp(strType, "include") == 0) { if (!includeFile(node,elemNode,oldSibling)) { return false; } } else { contentError("Misplaced or invalid element in SpriteNode",elemNode); return false; } return true; }
void ShaderWriter::includeFile(string filename, string fromFile) { if(fileExists(currentDir() + "/"+ filename)){ filename = currentDir() + "/"+ filename; } else if (fileExists(dirName(fromFile) + "/"+ filename)){ filename = dirName(fromFile) + "/"+ filename; } else if (fileExists(shaderDir() + "/"+ filename)){ filename = shaderDir() + "/"+ filename; } else if(!fileExists(filename)) { cerr << "Could not find file: " << filename << endl; return; } ifstream file; file.open(filename); bool inComment = false; char _buff[200]; while(!file.eof()) { file.getline(_buff,sizeof(_buff)); string buff(_buff); if(!m_Debug) { if(buff[buff.size()-1] == '\r') { buff[buff.size()-1] =0; } if(inComment) { size_t i = buff.find("*/"); if(i != -1){ buff = buff.substr(i+2); inComment = false; } else { buff=""; } }else{ size_t i = buff.find("//"); if(i != -1) { buff = buff.substr(0,i); } i = buff.find("/*"); if(i != -1) { buff = buff.substr(0,i); inComment =true; } buff = stringReplace(buff,"\t",""); } } if(buff.substr(0,8) == "#include"){ includeFile(string(buff).substr(9),filename); }else{ m_Shader << buff << endl; } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively( QFile& file, qint64 startPos, const std::vector< std::pair<QString, QString> >& pathAliasDefinitions, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults, bool* isEditKeywordDetected, const QString& faultIncludeFileAbsolutePathPrefix) { QString line; if (!file.seek(startPos)) { return false; } bool continueParsing = true; do { line = file.readLine(); line = line.trimmed(); if (line.startsWith("--", Qt::CaseInsensitive)) { continue; } else if (line.startsWith(editKeyword, Qt::CaseInsensitive)) { if (isEditKeywordDetected) { *isEditKeywordDetected = true; } return false; } if (line.startsWith(includeKeyword, Qt::CaseInsensitive)) { line = file.readLine(); line = line.trimmed(); while (line.startsWith("--", Qt::CaseInsensitive)) { line = file.readLine(); line = line.trimmed(); } int firstQuote = line.indexOf("'"); int lastQuote = line.lastIndexOf("'"); if (!(firstQuote < 0 || lastQuote < 0 || firstQuote == lastQuote)) { QDir currentFileFolder; { QFileInfo fi(file.fileName()); currentFileFolder = fi.absoluteDir(); } // Read include file name, and both relative and absolute path is supported QString includeFilename = line.mid(firstQuote + 1, lastQuote - firstQuote - 1); for (auto entry : pathAliasDefinitions) { QString textToReplace = "$" + entry.first; includeFilename.replace(textToReplace, entry.second); } #ifdef WIN32 if (includeFilename.startsWith('/')) { // Absolute UNIX path, prefix on Windows includeFilename = faultIncludeFileAbsolutePathPrefix + includeFilename; } #endif QFileInfo fi(currentFileFolder, includeFilename); if (fi.exists()) { QString absoluteFilename = fi.canonicalFilePath(); QFile includeFile(absoluteFilename); if (includeFile.open(QFile::ReadOnly)) { //qDebug() << "Found include statement, and start parsing of\n " << absoluteFilename; if (!readFaultsAndParseIncludeStatementsRecursively(includeFile, 0, pathAliasDefinitions, faults, filenamesWithFaults, isEditKeywordDetected, faultIncludeFileAbsolutePathPrefix)) { qDebug() << "Error when parsing include file : " << absoluteFilename; } } } } } else if (line.startsWith(faultsKeyword, Qt::CaseInsensitive)) { if (!line.contains("/")) { readFaults(file, file.pos(), faults, isEditKeywordDetected); filenamesWithFaults->push_back(file.fileName()); } } if (isEditKeywordDetected && *isEditKeywordDetected) { continueParsing = false; } if (file.atEnd()) { continueParsing = false; } } while (continueParsing); return true; }
const QMap<QString,QString> &Smb4KGlobalPrivate::globalSambaOptions(bool read) { if (read) { // Clear the options. m_samba_options.clear(); // Now search the smb.conf file and read the [global] section // from it. // With the introduction of Samba 4, the smb.conf file might also // be named smb4.conf. Thus we need to search for two filenames. // Please note that the file named smb.conf will always be picked // if it exists. QStringList paths; paths << "/etc"; paths << "/etc/samba"; paths << "/usr/local/etc"; paths << "/usr/local/etc/samba"; QFile smbConf; QStringList contents; for (int i = 0; i < paths.size(); ++i) { QDir::setCurrent(paths.at(i)); QFile file1("smb.conf"); QFile file2("smb4.conf"); if (file1.exists()) { smbConf.setFileName(QDir::currentPath()+QDir::separator()+file1.fileName()); break; } else if (file2.exists()) { smbConf.setFileName(QDir::currentPath()+QDir::separator()+file2.fileName()); break; } else { continue; } } if (smbConf.exists()) { if (smbConf.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream ts(&smbConf); while (!ts.atEnd()) { contents.append(ts.readLine(0)); } smbConf.close(); } else { Smb4KNotification::openingFileFailed(smbConf); return m_samba_options; } } else { Smb4KNotification::sambaConfigFileMissing(); return m_samba_options; } // Now process the contents of the smb.conf file. if (!contents.isEmpty()) { // Process the file contents. for (int i = contents.indexOf("[global]", 0); i < contents.size(); ++i) { if (i == -1) { // The smb.conf file does not contain a global section. break; } else { // Do nothing } if (contents.at(i).trimmed().startsWith('#') || contents.at(i).trimmed().startsWith(';')) { // This is a comment. We do not need it. continue; } else if (contents.at(i).trimmed().startsWith(QLatin1String("include"))) { // Look for the include file and put its contents into the // m_samba_options map. QFile includeFile(contents.at(i).section('=', 1, 1).trimmed()); if (includeFile.exists()) { if (includeFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream ts(&includeFile); QString buffer; while(!ts.atEnd()) { buffer = ts.readLine(0).trimmed(); if (buffer.startsWith('#') || buffer.startsWith(';')) { continue; } else { QString key = buffer.section('=', 0, 0).trimmed().toLower(); m_samba_options[key] = buffer.section('=', 1, 1).trimmed().toUpper(); continue; } } } else { Smb4KNotification::openingFileFailed(includeFile); continue; } } } else if (contents.at(i).startsWith('[') && !contents.at(i).contains("[global]", Qt::CaseSensitive)) { // We reached the end of the [global] section. Stop here. break; } else { // Put the entries of the [global] section into the m_samba_options // map. QString key = contents.at(i).section('=', 0, 0).trimmed().toLower(); m_samba_options[key] = contents.at(i).section('=', 1, 1).trimmed().toUpper(); } } } else { // Nothing to do } // Post-processing. Some values should be entered with their defaults, if they are // not already present. if (!m_samba_options.contains("netbios name")) { m_samba_options["netbios name"] = QHostInfo::localHostName().toUpper(); } else { // Do nothing } } else { // Do nothing } return m_samba_options; }
bool ScriptFile::AddScriptSection(asIScriptEngine* engine, Deserializer& source) { ResourceCache* cache = GetSubsystem<ResourceCache>(); unsigned dataSize = source.GetSize(); SharedArrayPtr<char> buffer(new char[dataSize]); source.Read((void*)buffer.Get(), dataSize); // Pre-parse for includes // Adapted from Angelscript's scriptbuilder add-on Vector<String> includeFiles; unsigned pos = 0; while(pos < dataSize) { int len; asETokenClass t = engine->ParseToken(&buffer[pos], dataSize - pos, &len); if (t == asTC_COMMENT || t == asTC_WHITESPACE) { pos += len; continue; } // Is this a preprocessor directive? if (buffer[pos] == '#') { int start = pos++; asETokenClass t = engine->ParseToken(&buffer[pos], dataSize - pos, &len); if (t == asTC_IDENTIFIER) { String token(&buffer[pos], len); if (token == "include") { pos += len; t = engine->ParseToken(&buffer[pos], dataSize - pos, &len); if (t == asTC_WHITESPACE) { pos += len; t = engine->ParseToken(&buffer[pos], dataSize - pos, &len); } if (t == asTC_VALUE && len > 2 && buffer[pos] == '"') { // Get the include file String includeFile(&buffer[pos+1], len - 2); pos += len; // If the file is not found as it is, add the path of current file but only if it is found there if (!cache->Exists(includeFile)) { String prefixedIncludeFile = GetPath(GetName()) + includeFile; if (cache->Exists(prefixedIncludeFile)) includeFile = prefixedIncludeFile; } String includeFileLower = includeFile.ToLower(); // If not included yet, store it for later processing if (!includeFiles_.Contains(includeFileLower)) { includeFiles_.Insert(includeFileLower); includeFiles.Push(includeFile); } // Overwrite the include directive with space characters to avoid compiler error memset(&buffer[start], ' ', pos - start); } } } } // Don't search includes within statement blocks or between tokens in statements else { int len; // Skip until ; or { whichever comes first while (pos < dataSize && buffer[pos] != ';' && buffer[pos] != '{') { engine->ParseToken(&buffer[pos], 0, &len); pos += len; } // Skip entire statement block if (pos < dataSize && buffer[pos] == '{') { ++pos; // Find the end of the statement block int level = 1; while (level > 0 && pos < dataSize) { asETokenClass t = engine->ParseToken(&buffer[pos], 0, &len); if (t == asTC_KEYWORD) { if (buffer[pos] == '{') ++level; else if(buffer[pos] == '}') --level; } pos += len; } } else ++pos; } } // Process includes first for (unsigned i = 0; i < includeFiles.Size(); ++i) { cache->StoreResourceDependency(this, includeFiles[i]); SharedPtr<File> file = cache->GetFile(includeFiles[i]); if (file) { if (!AddScriptSection(engine, *file)) return false; } else { LOGERROR("Could not process all the include directives in " + GetName() + ": missing " + includeFiles[i]); return false; } } // Then add this section if (scriptModule_->AddScriptSection(source.GetName().CString(), (const char*)buffer.Get(), dataSize) < 0) { LOGERROR("Failed to add script section " + source.GetName()); return false; } SetMemoryUse(GetMemoryUse() + dataSize); return true; }