Main::Main(int inArgc, char **inArgv, text compilerName, text syntaxName, text styleSheetName, text builtinsName) // ---------------------------------------------------------------------------- // Initialization of the globals // ---------------------------------------------------------------------------- : argc(inArgc), argv(inArgv), positions(), errors(InitErrorsAndMAIN()), topLevelErrors(), syntax(syntaxName.c_str()), options(inArgc, inArgv), compiler(new Compiler(compilerName.c_str(), inArgc, inArgv)), context(new Context(NULL, NULL)), globals(new Symbols(NULL)), renderer(std::cout, styleSheetName, syntax), reader(NULL), writer(NULL) { XL_INIT_TRACES(); Options::options = &options; Renderer::renderer = &renderer; Syntax::syntax = &syntax; MAIN = this; options.builtins = builtinsName; ParseOptions(); FlightRecorder::SResize(options.flightRecorderSize); if (options.flightRecorderFlags) FlightRecorder::SFlags(options.flightRecorderFlags); globals->is_global = true; // Duh... }
//copy constructor for the text object text::text(const text &textSource){ //copy all of the items over from the source to the //current object setTitle(textSource.getTitle()); setAuthor(textSource.getAuthor()); setRating(textSource.getRating()); setKeyword(textSource.getKeyword()); strcpy(response, textSource.getResponse()); }
void Syntax::ReadSyntaxFile (text filename, uint indents) // ---------------------------------------------------------------------------- // Read a syntax directly from a syntax file // ---------------------------------------------------------------------------- { Syntax baseSyntax; Positions basePositions; Errors errors; Scanner scanner(filename.c_str(), baseSyntax, basePositions, errors); ReadSyntaxFile(scanner, indents); }
SourceFile::SourceFile(text n, Tree *t, Context *c, Symbols *s, bool ro) // ---------------------------------------------------------------------------- // Construct a source file given a name // ---------------------------------------------------------------------------- : name(n), tree(t), context(c), symbols(s), modified(0), changed(false), readOnly(ro), info(NULL) { #if defined(CONFIG_MINGW) struct _stat st; #else struct stat st; #endif if (utf8_stat (n.c_str(), &st) < 0) return; modified = st.st_mtime; if (utf8_access (n.c_str(), W_OK) != 0) readOnly = true; if (s) s->is_global = true; }
void Chooser::AddCommands(text begin, text label) // ---------------------------------------------------------------------------- // Add chooser commands from the symbols table // ---------------------------------------------------------------------------- { // Add all the commands that begin with the prefix in the current context XL::name_set names, infix, prefix, postfix; XL::MAIN->ListNames(begin, names, infix, prefix, postfix); // Loop over all rewrites that match uint first = begin.length(); for (XL::name_set::iterator n = names.begin(); n != names.end(); n++) { text symname = *n; text caption = ""; kstring data = symname.data(); uint c, maxc = symname.length(); for (c = first; c < maxc; c = Utf8Next(data, c)) { wchar_t wc; char wcbuf[MB_LEN_MAX]; if (mbtowc(&wc, data + c, maxc - c) > 0) { if (wc == '_') wc = ' '; else if (c == first && label.length() > 0) wc = towupper(wc); } int sz = wctomb(wcbuf, wc); if (sz > 0) caption.insert(caption.end(), wcbuf, wcbuf + sz); } // Create a closure from the resulting commands to remember context Tree *command = new XL::Name(symname); caption = widget->xlTr(NULL, caption); AddItem(label + caption, command); } }
void xl_set_documentation(Tree *node, text doc) // ---------------------------------------------------------------------------- // Attach the documentation to the node as a comment // ---------------------------------------------------------------------------- { if (!doc.empty()) { std::vector<text> com(1,doc); CommentsInfo *cinfo = new CommentsInfo(); cinfo->after = com; node->SetInfo<CommentsInfo> (cinfo); } }
bool CompiledUnit::ValidCName(Tree *tree, text &label) // ---------------------------------------------------------------------------- // Check if the name is valid for C // ---------------------------------------------------------------------------- { uint len = 0; if (Name *name = tree->AsName()) { label = name->value; len = label.length(); } else if (Text *text = tree->AsText()) { label = text->value; len = label.length(); } if (len == 0) { Ooops("No valid C name in $1", tree); return false; } // We will NOT call functions beginning with _ (internal functions) for (uint i = 0; i < len; i++) { char c = label[i]; if (!isalpha(c) && c != '_' && !(i && isdigit(c))) { Ooops("C name $1 contains invalid characters", tree); return false; } } return true; }
bool text::operator==(const text& t) const { if (getWordCount() == t.getWordCount()) { bool equal = true; std::vector <shared_ptr <word> >::const_iterator i = m_words.begin(); std::vector <shared_ptr <word> >::const_iterator j = t.m_words.begin(); for ( ; equal && i != m_words.end() ; ++i, ++j) equal = (**i == **j); return (equal); } return (false); }
utility::stream::size_type body::getGeneratedSize(const generationContext& ctx) { // MIME-Multipart if (getPartCount() != 0) { utility::stream::size_type size = 0; // Size of parts and boundaries for (size_t p = 0 ; p < getPartCount() ; ++p) { size += 100; // boundary, CRLF... size += getPartAt(p)->getGeneratedSize(ctx); } // Size of prolog/epilog text const text prologText = getActualPrologText(ctx); if (!prologText.isEmpty()) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); prologText.encodeAndFold(ctx, osa, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); size += oss.str().size(); } const text epilogText = getActualEpilogText(ctx); if (!epilogText.isEmpty()) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); epilogText.encodeAndFold(ctx, osa, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); size += oss.str().size(); } return size; } // Simple body else { ref <utility::encoder::encoder> srcEncoder = m_contents->getEncoding().getEncoder(); ref <utility::encoder::encoder> dstEncoder = getEncoding().getEncoder(); return dstEncoder->getEncodedSize(srcEncoder->getDecodedSize(m_contents->getLength())); } }
void htmlTextPart::parse(shared_ptr <const bodyPart> message, shared_ptr <const bodyPart> parent, shared_ptr <const bodyPart> textPart) { // Search for possible embedded objects in the _whole_ message. std::vector <shared_ptr <const bodyPart> > cidParts; std::vector <shared_ptr <const bodyPart> > locParts; findEmbeddedParts(*message, cidParts, locParts); // Extract HTML text std::ostringstream oss; utility::outputStreamAdapter adapter(oss); textPart->getBody()->getContents()->extract(adapter); const string data = oss.str(); m_text = textPart->getBody()->getContents()->clone(); // Find charset shared_ptr <const contentTypeField> ctf = textPart->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE); if (ctf && ctf->hasCharset()) m_charset = ctf->getCharset(); else m_charset = charset(); // Extract embedded objects. The algorithm is quite simple: for each previously // found inline part, we check if its CID/Location is contained in the HTML text. for (std::vector <shared_ptr <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) { const shared_ptr <const headerField> midField = (*p)->getHeader()->findField(fields::CONTENT_ID); const messageId mid = *midField->getValue <messageId>(); if (data.find("CID:" + mid.getId()) != string::npos || data.find("cid:" + mid.getId()) != string::npos) { // This part is referenced in the HTML text. // Add it to the embedded object list. addEmbeddedObject(**p, mid.getId(), embeddedObject::REFERENCED_BY_ID); } } for (std::vector <shared_ptr <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) { const shared_ptr <const headerField> locField = (*p)->getHeader()->findField(fields::CONTENT_LOCATION); const text loc = *locField->getValue <text>(); const string locStr = loc.getWholeBuffer(); if (data.find(locStr) != string::npos) { // This part is referenced in the HTML text. // Add it to the embedded object list. addEmbeddedObject(**p, locStr, embeddedObject::REFERENCED_BY_LOCATION); } } // Extract plain text, if any. if (!findPlainTextPart(*message, *parent, *textPart)) { m_plainText = make_shared <emptyContentHandler>(); } }
void htmlTextPart::parse(ref <const bodyPart> message, ref <const bodyPart> parent, ref <const bodyPart> textPart) { // Search for possible embedded objects in the _whole_ message. std::vector <ref <const bodyPart> > cidParts; std::vector <ref <const bodyPart> > locParts; findEmbeddedParts(*message, cidParts, locParts); // Extract HTML text std::ostringstream oss; utility::outputStreamAdapter adapter(oss); textPart->getBody()->getContents()->extract(adapter); const string data = oss.str(); m_text = textPart->getBody()->getContents()->clone(); try { const ref <const contentTypeField> ctf = textPart->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>(); m_charset = ctf->getCharset(); } catch (exceptions::no_such_field) { // No "Content-type" field. } catch (exceptions::no_such_parameter) { // No "charset" parameter. } // Extract embedded objects. The algorithm is quite simple: for each previously // found inline part, we check if its CID/Location is contained in the HTML text. for (std::vector <ref <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) { const ref <const headerField> midField = (*p)->getHeader()->findField(fields::CONTENT_ID); const messageId mid = *midField->getValue().dynamicCast <const messageId>(); if (data.find("CID:" + mid.getId()) != string::npos || data.find("cid:" + mid.getId()) != string::npos) { // This part is referenced in the HTML text. // Add it to the embedded object list. addEmbeddedObject(**p, mid.getId()); } } for (std::vector <ref <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) { const ref <const headerField> locField = (*p)->getHeader()->findField(fields::CONTENT_LOCATION); const text loc = *locField->getValue().dynamicCast <const text>(); const string locStr = loc.getWholeBuffer(); if (data.find(locStr) != string::npos) { // This part is referenced in the HTML text. // Add it to the embedded object list. addEmbeddedObject(**p, locStr); } } // Extract plain text, if any. if (!findPlainTextPart(*message, *parent, *textPart)) { m_plainText = vmime::create <emptyContentHandler>(); } }
void CGuiFont::BuildVertexArray( SMeshData<SMeshTexture>& _vertices, text _text, float drawX, float drawY ) { int countLetters, index, i, letter; // Get the number of letters in the sentence. countLetters = (int)wcslen( _text.c_str() ); index = 0; // Draw each letter onto a quad. for(i = 0; i < countLetters; i++) { letter = ((int)_text[i]) - 32; // If the letter is a space then just move over three pixels. if(letter == 0) { drawX = drawX + 3.0f; } else { // First triangle in quad. SMeshTexture tempText; tempText = SMeshTexture( XMFLOAT3( drawX, drawY, 0.0f ), XMFLOAT2( m_type[letter].left, 0.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( drawX, drawY, 0.0f ); // Top left. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 0.0f ); index++; tempText = SMeshTexture( XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].right, 1.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ); // Bottom right. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 1.0f ); index++; tempText = SMeshTexture( XMFLOAT3( drawX, (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].left, 1.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( drawX, (drawY - 16), 0.0f ); // Bottom left. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 1.0f ); index++; // Second triangle in quad. tempText = SMeshTexture( XMFLOAT3( drawX, drawY, 0.0f ), XMFLOAT2( m_type[letter].left, 0.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( drawX, drawY, 0.0f ); // Top left. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].left, 0.0f ); index++; tempText = SMeshTexture( XMFLOAT3( drawX + m_type[letter].size, drawY, 0.0f ), XMFLOAT2( m_type[letter].right, 0.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( drawX + m_type[letter].size, drawY, 0.0f ); // Top right. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 0.0f ); index++; tempText = SMeshTexture( XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ), XMFLOAT2( m_type[letter].right, 1.0f ) ); _vertices.vertices.push_back( tempText ); _vertices.indices.push_back( index ); //_vertices.vertices[index].vertex = XMFLOAT3( (drawX + m_type[letter].size), (drawY - 16), 0.0f ); // Bottom right. //_vertices.vertices[index].uv = XMFLOAT2( m_type[letter].right, 1.0f ); index++; // Update the x location for drawing by the size of the letter and one pixel. drawX = drawX + m_type[letter].size + 1.0f; } } }
void body::generateImpl (const generationContext& ctx, utility::outputStream& os, const string::size_type /* curLinePos */, string::size_type* newLinePos) const { // MIME-Multipart if (getPartCount() != 0) { string boundary; if (m_header.acquire() == NULL) { boundary = generateRandomBoundaryString(); } else { try { ref <const contentTypeField> ctf = m_header.acquire()->findField(fields::CONTENT_TYPE) .dynamicCast <const contentTypeField>(); boundary = ctf->getBoundary(); } catch (exceptions::no_such_field&) { // Warning: no content-type and no boundary string specified! boundary = generateRandomBoundaryString(); } catch (exceptions::no_such_parameter&) { // Warning: no boundary string specified! boundary = generateRandomBoundaryString(); } } const text prologText = getActualPrologText(ctx); const text epilogText = getActualEpilogText(ctx); if (!prologText.isEmpty()) { prologText.encodeAndFold(ctx, os, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); os << CRLF; } os << "--" << boundary; for (size_t p = 0 ; p < getPartCount() ; ++p) { os << CRLF; getPartAt(p)->generate(ctx, os, 0); os << CRLF << "--" << boundary; } os << "--" << CRLF; if (!epilogText.isEmpty()) { epilogText.encodeAndFold(ctx, os, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); os << CRLF; } if (newLinePos) *newLinePos = 0; } // Simple body else { // Generate the contents ref <contentHandler> contents = m_contents->clone(); contents->setContentTypeHint(getContentType()); contents->generate(os, getEncoding(), ctx.getMaxLineLength()); } }
int Main::LoadFile(text file, bool updateContext, Context *importContext, Symbols *importSymbols) // ---------------------------------------------------------------------------- // Load an individual file // ---------------------------------------------------------------------------- { Tree_p tree = NULL; bool hadError = false; IFTRACE(fileload) std::cout << "Loading: " << file << "\n"; // Find which source file we are referencing SourceFile &sf = files[file]; // Parse program - Local parser to delete scanner and close file // This ensures positions are updated even if there is a 'load' // being called during execution. if (options.readSerialized) { if (!reader) reader = new Deserializer(std::cin); tree = reader->ReadTree(); if (!reader->IsValid()) { errors->Log(Error("Serialized stream cannot be read: $1") .Arg(file)); hadError = true; return hadError; } } else { utf8_ifstream ifs(file.c_str(), std::ios::in | std::ios::binary); Deserializer ds(ifs); tree = ds.ReadTree(); if (!ds.IsValid()) { std::string decrypted = MAIN->Decrypt(file.c_str()); if (decrypted != "") { // Parse decrypted string as XL source IFTRACE(fileload) std::cerr << "Info: file was succesfully decrypted\n"; std::istringstream iss; iss.str(decrypted); Parser parser (iss, syntax, positions, topLevelErrors); tree = parser.Parse(); } else { // Parse as XL source Parser parser (file.c_str(), syntax, positions, topLevelErrors); tree = parser.Parse(); } } else { IFTRACE(fileload) std::cerr << "Info: file is in serialized format\n"; } } if (options.writeSerialized) { if (!writer) writer = new Serializer(std::cout); if (tree) tree->Do(writer); } if (tree) { tree = Normalize(tree); } else { if (options.doDiff) { files[file] = SourceFile (file, NULL, NULL, NULL); hadError = false; } } // Create new symbol table for the file, or clear it if we had one Context *ctx = MAIN->context; Context *savedCtx = ctx; Symbols *syms = MAIN->globals; Symbols *savedSyms = syms; if (sf.context) { updateContext = false; ctx = sf.context; syms = sf.symbols; ctx->Clear(); syms->Clear(); } else { ctx = new Context(ctx, NULL); syms = new Symbols(syms); syms->name = file; } MAIN->context = ctx; MAIN->globals = syms; syms->is_global = true; // Connect imports if any if (importContext) importContext->Import(ctx); if (importSymbols) importSymbols->Import(syms); // HACK - do not hide imported .xl if (file.find(".ddd") == file.npos && file.find("tao.xl") == file.npos && file.find("builtins.xl") == file.npos) { Name_p module_file = new Name("module_file"); // TODO: Position Name_p module_dir = new Name("module_dir"); Text_p module_file_value = new Text(file); Text_p module_dir_value = new Text(ParentDir(file)); ctx->Define(module_file, module_file_value); ctx->Define(module_dir, module_dir_value); syms->EnterName(module_file->value, module_file_value,Rewrite::LOCAL); syms->EnterName(module_dir->value, module_dir_value,Rewrite::LOCAL); } // Register the source file we had sf = SourceFile (file, tree, ctx, syms); if (tree) { // Set symbols and compile if required if (!options.parseOnly) { if (options.optimize_level == 1) { tree->SetSymbols(syms); if (!tree) hadError = true; else files[file].tree = tree; syms->ProcessDeclarations(tree); } // TODO: At -O3, do we need to do anything here? } // Graph of the input tree if (options.showGV) { SetNodeIdAction sni; BreadthFirstSearch<SetNodeIdAction> bfs(sni); tree->Do(bfs); GvOutput gvout(std::cout); tree->Do(gvout); } } if (options.showSource) std::cout << tree << "\n"; if (options.verbose) debugp(tree); // Decide if we update symbols for next run if (!updateContext) { MAIN->context = savedCtx; MAIN->globals = savedSyms; } IFTRACE(symbols) std::cerr << "Loaded file " << file << " with context " << MAIN->context << '\n'; return hadError; }
void body::generateImpl (const generationContext& ctx, utility::outputStream& os, const size_t /* curLinePos */, size_t* newLinePos) const { // MIME-Multipart if (getPartCount() != 0) { string boundary; if (!m_part) { boundary = generateRandomBoundaryString(); } else { // Use current boundary string, if specified. If no "Content-Type" field is // present, or the boundary is not specified, generate a random one shared_ptr <contentTypeField> ctf = m_part->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE); if (ctf) { if (ctf->hasBoundary()) { boundary = ctf->getBoundary(); } else { // No boundary string specified boundary = generateRandomBoundaryString(); } } else { // No Content-Type (and no boundary string specified) boundary = generateRandomBoundaryString(); } } const text prologText = getActualPrologText(ctx); const text epilogText = getActualEpilogText(ctx); if (!prologText.isEmpty()) { prologText.encodeAndFold(ctx, os, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); os << CRLF; } os << "--" << boundary; for (size_t p = 0 ; p < getPartCount() ; ++p) { os << CRLF; getPartAt(p)->generate(ctx, os, 0); os << CRLF << "--" << boundary; } os << "--" << CRLF; if (!epilogText.isEmpty()) { epilogText.encodeAndFold(ctx, os, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); os << CRLF; } if (newLinePos) *newLinePos = 0; } // Simple body else { // Generate the contents shared_ptr <contentHandler> contents = m_contents->clone(); contents->setContentTypeHint(getContentType()); contents->generate(os, getEncoding(), ctx.getMaxLineLength()); } }