void ArrayObject::save(const chowstring & filename) { FSFile fp(convert_path(filename).c_str(), "w"); if (!fp.is_open()) return; WriteStream stream; stream.write(CT_ARRAY_MAGIC, sizeof(CT_ARRAY_MAGIC)); stream.write_int16(ARRAY_MAJOR_VERSION); stream.write_int16(ARRAY_MINOR_VERSION); stream.write_int32(data.x_size); stream.write_int32(data.y_size); stream.write_int32(data.z_size); int flags = 0; if (data.is_numeric) flags |= NUMERIC_FLAG; if (data.offset != 0) flags |= BASE1_FLAG; stream.write_int32(flags); for (int i = 0; i < data.x_size * data.y_size * data.z_size; i++) { if (data.is_numeric) { stream.write_int32(int(data.array[i])); } else { stream.write_int32(data.strings[i].size()); stream.write_string(data.strings[i]); } } stream.save(fp); fp.close(); }
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length) { if (length == 0) return; ScopedPtr<MemoryReadStream> data(convertString(str, encoding, false)); size_t n = stream.writeStream(*data, length); while (n++ < length) stream.writeByte(0); }
void InsetMathAMSArray::write(WriteStream & os) const { MathEnsurer ensurer(os); os << "\\begin{" << name_ << '}'; bool open = os.startOuterRow(); InsetMathGrid::write(os); os << "\\end{" << name_ << '}'; if (open) os.startOuterRow(); }
void InsetMathCases::write(WriteStream & os) const { MathEnsurer ensurer(os); if (os.fragile()) os << "\\protect"; os << "\\begin{cases}\n"; InsetMathGrid::write(os); if (os.fragile()) os << "\\protect"; os << "\\end{cases}"; }
void AssociateArray::save(const std::string & path, int method) { FSFile fp(path.c_str(), "w"); if (!fp.is_open()) { std::cout << "Could not save associate array: " << path << std::endl; return; } WriteStream stream; save_assarray(*this, stream, method); stream.save(fp); fp.close(); }
void FoxPro::saveMemos(WriteStream &fpt) const { fpt.writeUint32BE(_memos.size() + 1); // Next free block fpt.writeUint16BE(0x0000); // Reserved fpt.writeUint16BE(_memoBlockSize); // Reserved for (int i = 0; i < 126; i++) fpt.writeUint32BE(0x00000000); for (size_t i = 0; i < _memos.size(); i++) fpt.write(_memos[i], _memoBlockSize); }
void FoxPro::saveRecords(WriteStream &dbf) const { // Write the records for (size_t i = 0; i < _records.size(); i++) { const Record &record = _records[i]; dbf.writeByte(record.deleted ? '*' : ' '); for (size_t j = 0; j < _fields.size(); j++) dbf.write(record.fields[j], _fields[j].size); } dbf.writeByte(0x1A); // Records end marker }
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length) { MemoryReadStream *data = 0; try { data = convertString(str, encoding, false); size_t n = stream.writeStream(*data, length); while (n++ < length) stream.writeByte(0); } catch (...) { delete data; throw; } delete data; }
size_t writeString(WriteStream &stream, const Common::UString &str, Encoding encoding, bool terminate) { ScopedPtr<MemoryReadStream> data(convertString(str, encoding, terminate)); const size_t n = stream.writeStream(*data); return n; }
void flush() { stream->write(buffer, buffer_pos); buffer_pos = 0; if(flush_event != nullptr) { flush_event->run(); } }
void InsetMathBig::write(WriteStream & os) const { MathEnsurer ensurer(os); os << '\\' << name_ << delim_; if (delim_[0] == '\\') os.pendingSpace(true); }
void InsetMathSplit::write(WriteStream & ws) const { MathEnsurer ensurer(ws); if (ws.fragile()) ws << "\\protect"; docstring suffix; if (!numbered_ && name_ == "align") suffix = from_ascii("*"); ws << "\\begin{" << name_ << suffix << '}'; if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c') ws << '[' << verticalAlignment() << ']'; if (name_ == "alignedat") ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}'; InsetMathGrid::write(ws); if (ws.fragile()) ws << "\\protect"; ws << "\\end{" << name_ << suffix << "}\n"; }
void InsetMathDecoration::write(WriteStream & os) const { MathEnsurer ensurer(os); if (os.fragile() && protect()) os << "\\protect"; os << '\\' << key_->name << '{'; ModeSpecifier specifier(os, currentMode()); os << cell(0) << '}'; }
void InsetMath::write(WriteStream & os) const { MathEnsurer ensurer(os); docstring const s = name(); os << "\\" << s; // We need an extra ' ' unless this is a single-char-non-ASCII name // or anything non-ASCII follows if (s.size() != 1 || isAlphaASCII(s[0])) os.pendingSpace(true); }
void InsetMathSymbol::write(WriteStream & os) const { MathEnsurer ensurer(os); os << '\\' << name(); // $,#, etc. In theory the restriction based on catcodes, but then // we do not handle catcodes very well, let alone cat code changes, // so being outside the alpha range is good enough. if (name().size() == 1 && !isAlphaASCII(name()[0])) return; os.pendingSpace(true); }
void InsetMathTabular::write(WriteStream & os) const { ModeSpecifier specifier(os, TEXT_MODE); if (os.fragile()) os << "\\protect"; os << "\\begin{" << name_ << '}'; bool open = os.startOuterRow(); char const v = verticalAlignment(); if (v == 't' || v == 'b') os << '[' << v << ']'; os << '{' << horizontalAlignments() << "}\n"; InsetMathGrid::write(os); if (os.fragile()) os << "\\protect"; os << "\\end{" << name_ << '}'; if (open) os.startOuterRow(); // adding a \n here is bad if the tabular is the last item // in an \eqnarray... }
size_t writeString(WriteStream &stream, const Common::UString &str, Encoding encoding, bool terminate) { size_t n = 0; MemoryReadStream *data = 0; try { data = convertString(str, encoding, terminate); n = stream.writeStream(*data); } catch (...) { delete data; throw; } delete data; return n; }
void InsetMathSymbol::write(WriteStream & os) const { unique_ptr<MathEnsurer> ensurer; if (currentMode() != TEXT_MODE) ensurer = make_unique<MathEnsurer>(os); else ensurer = make_unique<MathEnsurer>(os, false, true, true); os << '\\' << name(); // $,#, etc. In theory the restriction based on catcodes, but then // we do not handle catcodes very well, let alone cat code changes, // so being outside the alpha range is good enough. if (name().size() == 1 && !isAlphaASCII(name()[0])) return; os.pendingSpace(true); }
void InsetMathPhantom::write(WriteStream & os) const { MathEnsurer ensurer(os); if (os.fragile()) os << "\\protect"; switch (kind_) { case phantom: os << "\\phantom{"; break; case vphantom: os << "\\vphantom{"; break; case hphantom: os << "\\hphantom{"; break; case smash: os << "\\smash{"; break; case smasht: os << "\\smash[t]{"; break; case smashb: os << "\\smash[b]{"; break; case mathclap: os << "\\mathclap{"; break; case mathllap: os << "\\mathllap{"; break; case mathrlap: os << "\\mathrlap{"; break; } os << cell(0) << '}'; }
void InsetMathChar::write(WriteStream & os) const { os.os().put(char_); }
void ConfigManager::writeDomain(WriteStream &stream, const String &name, const Domain &domain) { if (domain.empty()) return; // Don't bother writing empty domains. // WORKAROUND: Fix for bug #1972625 "ALL: On-the-fly targets are // written to the config file": Do not save domains that came from // the command line if (domain.contains("id_came_from_command_line")) return; String comment; // Write domain comment (if any) comment = domain.getDomainComment(); if (!comment.empty()) stream.writeString(comment); // Write domain start stream.writeByte('['); stream.writeString(name); stream.writeByte(']'); #ifdef _WIN32 stream.writeByte('\r'); stream.writeByte('\n'); #else stream.writeByte('\n'); #endif // Write all key/value pairs in this domain, including comments Domain::const_iterator x; for (x = domain.begin(); x != domain.end(); ++x) { if (!x->_value.empty()) { // Write comment (if any) if (domain.hasKVComment(x->_key)) { comment = domain.getKVComment(x->_key); stream.writeString(comment); } // Write the key/value pair stream.writeString(x->_key); stream.writeByte('='); stream.writeString(x->_value); #ifdef _WIN32 stream.writeByte('\r'); stream.writeByte('\n'); #else stream.writeByte('\n'); #endif } } #ifdef _WIN32 stream.writeByte('\r'); stream.writeByte('\n'); #else stream.writeByte('\n'); #endif }
void ConfigFile::save(WriteStream &stream) const { // Write file prologue if (!_prologue.empty()) { stream.writeString(_prologue); stream.writeByte('\n'); stream.writeByte('\n'); } // Domains for (DomainList::const_iterator domain = _domainList.begin(); domain != _domainList.end(); ++domain) { // Write domain prologue if (!(*domain)->_prologue.empty()) { stream.writeString((*domain)->_prologue); stream.writeByte('\n'); } // Write domain name stream.writeByte('['); stream.writeString((*domain)->_name); stream.writeByte(']'); // Write domain comment if (!(*domain)->_comment.empty()) { stream.writeByte(' '); stream.writeString((*domain)->_comment); } stream.writeByte('\n'); // Lines for (ConfigDomain::LineList::const_iterator line = (*domain)->_lines.begin(); line != (*domain)->_lines.end(); ++line) { // Write key if (line->key != (*domain)->_keys.end()) { stream.writeString(line->key->first); stream.writeByte('='); stream.writeString(line->key->second); if (!line->comment.empty()) stream.writeByte(' '); } // Write comment if (!line->comment.empty()) stream.writeString(line->comment); stream.writeByte('\n'); } stream.writeByte('\n'); } // Write the epilogue if (!_epilogue.empty()) { stream.writeString(_epilogue); stream.writeByte('\n'); } stream.flush(); }
void InsetMathString::write(WriteStream & os) const { if (!os.latex() || os.lockedMode()) { os << (os.asciiOnly() ? escape(str_) : str_); return; } docstring::const_iterator cit = str_.begin(); docstring::const_iterator end = str_.end(); // We may already be inside an \ensuremath command. bool in_forced_mode = os.pendingBrace(); // We will take care of matching braces. os.pendingBrace(false); while (cit != end) { bool mathmode = in_forced_mode ? os.textMode() : !os.textMode(); char_type const c = *cit; docstring command(1, c); try { bool termination = false; if (isASCII(c) || Encodings::latexMathChar(c, mathmode, os.encoding(), command, termination)) { if (os.textMode()) { if (in_forced_mode) { // we were inside \lyxmathsym os << '}'; os.textMode(false); in_forced_mode = false; } if (!isASCII(c) && os.textMode()) { os << "\\ensuremath{"; os.textMode(false); in_forced_mode = true; } } else if (isASCII(c) && in_forced_mode) { // we were inside \ensuremath os << '}'; os.textMode(true); in_forced_mode = false; } } else if (!os.textMode()) { if (in_forced_mode) { // we were inside \ensuremath os << '}'; in_forced_mode = false; } else { os << "\\lyxmathsym{"; in_forced_mode = true; } os.textMode(true); } os << command; // We may need a space if the command contains a macro // and the last char is ASCII. if (termination) os.pendingSpace(true); } catch (EncodingException const & e) { switch (os.output()) { case WriteStream::wsDryrun: { os << "<" << _("LyX Warning: ") << _("uncodable character") << " '"; os << docstring(1, e.failed_char); os << "'>"; break; } case WriteStream::wsPreview: { // indicate the encoding error by a boxed '?' os << "{\\fboxsep=1pt\\fbox{?}}"; LYXERR0("Uncodable character" << " '" << docstring(1, e.failed_char) << "'"); break; } case WriteStream::wsDefault: default: // throw again throw(e); } } ++cit; } if (in_forced_mode && os.textMode()) { // We have to care for closing \lyxmathsym os << '}'; os.textMode(false); } else { os.pendingBrace(in_forced_mode); } }
void FoxPro::saveFields(WriteStream &dbf) const { for (size_t i = 0; i < _fields.size(); i++) { const Field &field = _fields[i]; int l = strlen(field.name.c_str()); dbf.write(field.name.c_str(), MIN(10, l)); dbf.writeByte(0x00); while ((10 - l++) > 0) dbf.writeByte(0x00); dbf.writeByte((byte) ((char) field.type)); dbf.writeUint32LE(field.offset); dbf.writeByte(field.size); dbf.writeByte(field.decimals); dbf.writeByte(field.flags); dbf.writeUint32LE(field.autoIncNext); dbf.writeByte (field.autoIncStep); dbf.writeUint32LE(0x00000000); // Reserved dbf.writeUint32LE(0x00000000); // Reserved } dbf.writeByte(0x0D); // Field end marker }
void FoxPro::saveHeader(WriteStream &dbf) const { dbf.writeByte(0xF5); // Version dbf.writeByte(_lastUpdate.year() - 2000); dbf.writeByte(_lastUpdate.month()); dbf.writeByte(_lastUpdate.day()); dbf.writeUint32LE(_records.size()); // Header + fields + field end marker uint16 firstRecordPos = 32 + _fields.size() * 32 + 1; dbf.writeUint16LE(firstRecordPos); uint16 recordSize = _fields.back().offset + _fields.back().size; dbf.writeUint16LE(recordSize); dbf.writeUint32LE(0x00000000); // Reserved dbf.writeUint32LE(0x00000000); // Reserved dbf.writeUint32LE(0x00000000); // Reserved dbf.writeUint32LE(0x00000000); // Reserved uint8 flags = (_hasIndex ? 0x01 : 0x00) | (_hasMemo ? 0x02 : 0x00); dbf.writeByte(flags); dbf.writeByte(0x00); // Codepage marker dbf.writeUint16LE(0x0000); // Reserved }
bool ConfigFile::saveToStream(WriteStream &stream) { for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { // Write out the section comment, if any if (! i->comment.empty()) { stream.writeString(i->comment); } // Write out the section name stream.writeByte('['); stream.writeString(i->name); stream.writeByte(']'); stream.writeByte('\n'); // Write out the key/value pairs for (List<KeyValue>::iterator kv = i->keys.begin(); kv != i->keys.end(); ++kv) { // Write out the comment, if any if (! kv->comment.empty()) { stream.writeString(kv->comment); } // Write out the key/value pair stream.writeString(kv->key); stream.writeByte('='); stream.writeString(kv->value); stream.writeByte('\n'); } } stream.flush(); return !stream.err(); }
void InsetMathSpecialChar::write(WriteStream & os) const { os << '\\' << name_; if (name_.size() != 1) os.pendingSpace(true); }