char * box_code(int n) { char *s; if (n == garrison_magic) return "Garrison"; return sout("[%s]", int_to_code(n)); }
void WCssStyleSheet::javaScriptUpdate(WApplication *app, std::ostream& js, bool all) { if (!all) { for (unsigned i = 0; i < rulesRemoved_.size(); ++i) { js << WT_CLASS ".removeCssRule("; DomElement::jsStringLiteral(js, rulesRemoved_[i], '\''); js << ");"; } rulesRemoved_.clear(); for (RuleSet::const_iterator i = rulesModified_.begin(); i != rulesModified_.end(); ++i) { js << "{ var d= " WT_CLASS ".getCssRule("; DomElement::jsStringLiteral(js, (*i)->selector(), '\''); js << ");if(d){"; DomElement *d = DomElement::updateGiven("d", DomElement_SPAN); if ((*i)->updateDomElement(*d, false)) { EscapeOStream sout(js); d->asJavaScript(sout, DomElement::Update); } delete d; js << "}}"; } rulesModified_.clear(); } if (!app->environment().agentIsIElt(9) && app->environment().agent() != WEnvironment::Konqueror) { RuleList& toProcess = all ? rules_ : rulesAdded_; for (unsigned i = 0; i < toProcess.size(); ++i) { WCssRule *rule = toProcess[i]; js << WT_CLASS ".addCss('" << rule->selector() << "',"; DomElement::jsStringLiteral(js, rule->declarations(), '\''); js << ");" << std::endl; } rulesAdded_.clear(); if (all) rulesModified_.clear(); } else { std::string text = cssText(all); if (!text.empty()) { js << WT_CLASS ".addCssText("; DomElement::jsStringLiteral(js, text, '\''); js << ");" << std::endl; } } }
static char * ship_cap_s(int n) { int sc, sw; if (sc = ship_cap(n)) { sw = ship_weight(n); return sout(", %d%% loaded", sw * 100 / sc); } return ""; }
char * highlight_units(int who, int n, int depth) { assert(depth >= 3); assert(indent == 0); if (kind(who) == T_player && player(n) == who) return sout(" *%s", &spaces[spaces_len - (depth - 2)]); return &spaces[spaces_len - depth]; }
void WTemplate::format(std::ostream& result, const WString& s, TextFormat textFormat) { if (textFormat == XHTMLText) { WString v = s; if (removeScript(v)) { result << v.toUTF8(); return; } else { EscapeOStream sout(result); sout.append(v.toUTF8(), *plainTextNewLineEscStream_); return; } } else if (textFormat == PlainText) { EscapeOStream sout(result); sout.append(s.toUTF8(), *plainTextNewLineEscStream_); return; } result << s.toUTF8(); }
void WWidget::htmlText(std::ostream& out) { DomElement *element = createSDomElement(WApplication::instance()); DomElement::TimeoutList timeouts; EscapeOStream sout(out); EscapeOStream js; element->asHTML(sout, js, timeouts); WApplication::instance()->doJavaScript(js.str()); delete element; }
static char * liner_desc_storm(int n) { char buf[LEN]; int owner; struct entity_misc *p; sprintf(buf, "%s", box_name_kind(n)); p = rp_misc(n); owner = npc_summoner(n); if (owner) strcat(buf, sout(", owner~%s", box_code_less(owner))); strcat(buf, sout(", strength~%s", comma_num(storm_strength(n)))); if (p && p->npc_dir) strcat(buf, sout(", heading %s", full_dir_s[p->npc_dir])); return sout("%s", buf); }
void incrementCount(ObjectPtr obj) { string buf; llvm::raw_string_ostream sout(buf); sout << obj; string s = sout.str(); llvm::StringMap<int>::iterator i = countsMap.find(s); if (i == countsMap.end()) { countsMap[s] = 1; } else { i->second += 1; } }
bool Transcode::m_doTranscode( const QString &transStr ) { QString sout( ":sout=" ); sout += transStr; char const *vlc_argv[] = { "-I", "dummy", "--no-skip-frame", }; int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv ); libvlc_exception_init( &m_vlcEx ); m_libvlc = libvlc_new( vlc_argc, vlc_argv, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; m_vlcMedia = libvlc_media_new( m_libvlc, m_origVidPath.toLocal8Bit(), &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; libvlc_media_add_option(m_vlcMedia, sout.toStdString().c_str(), &m_vlcEx); if ( catchVLCException( &m_vlcEx ) ) return false; m_vlcMp = libvlc_media_player_new_from_media( m_vlcMedia, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; m_vlcEM = libvlc_media_player_event_manager( m_vlcMp, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; libvlc_event_attach( m_vlcEM, libvlc_MediaPlayerPlaying, m_callback, this, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; libvlc_event_attach( m_vlcEM, libvlc_MediaPlayerEndReached, m_callback, this, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; libvlc_media_player_play( m_vlcMp, &m_vlcEx ); if ( catchVLCException( &m_vlcEx ) ) return false; m_running = true; m_initProgressDialog(); return true; }
bool UnitTest::checkIf( bool testSucceeded, std::string testDescription, unsigned& ntests, unsigned& nerr) { ntests++; if( !testSucceeded ) nerr++; if( testSucceeded ) { sout() << "---- SUCCESS of : " << testDescription << std::endl; } else { serr() << "==== FAILURE of : " << testDescription << std::endl; } return testSucceeded; }
void surface_correlationFunction_do( s_env& st_env ) { // //PRECONDITIONS // o The "target" surface (usually the working curvature) should // have a rip pattern denoting a path of interest. Typically this // implies that after a standard path search, the output label needs // to have been re-loaded in order to restore the rip pattern. // // POSTCONDITIONS // o A float correlation is dumped on the results channel. If this // correlation is '-1', then *no* rips were found on the working // surface. This denotes an error state. // float f_correl = 0.0; int denom = 0; int membership = 0; VERTEX* pvertex = NULL; void* pv_void = NULL; for (int i = 0;i < st_env.pMS_primary->nvertices;i++) { pvertex = &st_env.pMS_primary->vertices[i]; if (vertex_ripFlagIsTrue(pvertex, pv_void)) { denom++; pvertex = &st_env.pMS_secondary->vertices[i]; if (vertex_ripFlagIsTrue(pvertex, pv_void)) { //cout << i << endl; membership++; } } } //cout << "number overlap: " << membership << endl; //cout << "size of source: " << denom << endl; if (!denom) f_correl = -1; else f_correl = (float)membership / (float)denom; cout << "Correlation: " << f_correl << endl; stringstream sout(""); sout << f_correl; nRLOUT(sout.str()); }
char * box_name(int n) { char *s; if (n == garrison_magic) return "Garrison"; if (valid_box(n)) { s = display_name(n); if (s && *s) { if (options.output_tags > 0) return sout("<tag type=box id=%d>%s~%s</tag type=box id=%d>", n, s, box_code(n),n); else return sout("%s~%s", s, box_code(n)); } } return box_code(n); }
/* * Thu Nov 12 11:20:28 1998 -- Scott Turner * * Add display of shoring. * */ char * show_loc_header(int where) { char buf[LEN]; strcpy(buf, box_name_kind(where)); strcat(buf, loc_inside_string(loc(where))); if (subkind(where) == sub_mine_shaft) { struct entity_mine *mi = get_mine_info(where); if (mine_depth(where)) strcat(buf, sout(", depth~%d feet", (mine_depth(where) * 100) + 100)); if (mi) switch (mi->shoring[mine_depth(where)]) { case WOODEN_SHORING: strcat(buf, sout(", wooden shoring")); break; case IRON_SHORING: strcat(buf, sout(", iron shoring")); break; case NO_SHORING: default: strcat(buf, sout(", no shoring")); break; }; }; strcat(buf, safe_haven_s(where)); if (loc_hidden(where)) strcat(buf, ", hidden"); strcat(buf, loc_civ_s(where)); return sout("%s", buf); }
int FAR PASCAL Lib2( DWORD w1, WORD w2 ) { char buf[128]; #ifdef __cplusplus { ostrstream sout( buf, sizeof( buf ) ); sout << hex << "Lib2: w1=" << w1 << ", w2=" << w2 << ends; MessageBox( NULL, sout.str(), "DLL32", MB_OK | MB_TASKMODAL ); } #else sprintf( buf, "Lib2: w1=%lx, w2=%hx", w1, w2 ); MessageBox( NULL, buf, "DLL32", MB_OK | MB_TASKMODAL ); #endif return( w1 + 1 ); }
void DomElement::addChild(DomElement *child) { ++numManipulations_; if ((mode_ == ModeCreate || wasEmpty_) && canWriteInnerHTML()) { std::stringstream out; { EscapeOStream sout(out); child->asHTML(sout, timeouts_); } childrenHtml_ += out.str(); delete child; } else childrenToAdd_.push_back(std::make_pair("", child)); }
static char * liner_desc_road(int n) { int dest; char *hid = ""; int dist; dest = road_dest(n); if (road_hidden(n)) hid = ", hidden"; dist = exit_distance(loc(n), dest); return sout("%s, to %s%s, %d~day%s", box_name(n), box_name(dest), hid, add_ds(dist)); }
static char * incomplete_string(int n) { struct entity_subloc *p; struct entity_build *b; p = rp_subloc(n); if (p == NULL) return ""; b = get_build(n, BT_BUILD); if (b == NULL || b->effort_required == 0) return ""; return sout(", %d%% completed", b->effort_given * 100 / b->effort_required); }
char * loc_civ_s(int where) { int n; if (loc_depth(where) != LOC_province || subkind(where) == sub_ocean || in_faery(where) || in_hades(where)) { return ""; } n = has_item(where, item_peasant); if (n < 100) return ", wilderness"; return sout(", peasants: %d", n); }
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location) { #if !wxUSE_URL return NULL; #else wxString right = GetProtocol(location) + wxT(":") + StripProtocolAnchor(location); wxURL url(right); if (url.GetError() == wxURL_NOERR) { wxInputStream *s = url.GetInputStream(); if (s) { wxString tmpfile = wxFileName::CreateTempFileName(wxT("wxhtml")); { // now copy streams content to temporary file: wxFileOutputStream sout(tmpfile); s->Read(sout); } delete s; // Content-Type header, as defined by the RFC 2045, has the form of // "type/subtype" optionally followed by (multiple) "; parameter" // and we need just the MIME type here. const wxString& content = url.GetProtocol().GetContentType(); wxString mimetype = content.BeforeFirst(';'); mimetype.Trim(); return new wxFSFile(new wxTemporaryFileInputStream(tmpfile), right, mimetype, GetAnchor(location) #if wxUSE_DATETIME , wxDateTime::Now() #endif // wxUSE_DATETIME ); } } return NULL; // incorrect URL #endif }
void decompress(Stream* in_stream, Stream* out_stream) { BufferedStreamReader<4 * KB> sin(in_stream); BufferedStreamWriter<4 * KB> sout(out_stream); assert(in_stream != nullptr); assert(out_stream != nullptr); init(); ent.initDecoder(sin); for (;;) { int c = processByte<true>(sin); if (c == kEOFChar) { if (ent.decodeBit(sin) == 1) { break; } } sout.put(c); update(c); } }
Rcpp::IntegerVector process_subset_vector(Rcpp::RObject subset, int upper, bool zero_indexed) { if (subset.sexp_type()!=INTSXP) { throw std::runtime_error("subset vector must be an integer vector"); } Rcpp::IntegerVector sout(subset); if (!zero_indexed) { sout=Rcpp::clone(sout); for (auto& s : sout) { --s; } } for (auto sIt=sout.begin(); sIt!=sout.end(); ++sIt) { if (*sIt < 0 || *sIt >= upper) { throw std::runtime_error("subset indices out of range"); } } return sout; }
void Sorting::indirect_sort(const string &src, const string &des) { ifstream sin(src.c_str()); string x; vector<string> arr; while (sin>>x) arr.emplace_back(x); vector<string *> P; for (auto &t : arr) P.push_back(&t); sort(P.begin(), P.end(), [](const string *a, const string *b)->bool{return (*a).length()<(*b).length();}); ofstream sout(des.c_str()); for (auto &t : P) sout << *t << " "; sout << endl; }
void CueControl::maybeSave(QAbstractButton* button) { newfile = ui.lineEdit->text(); switch(ui.buttonBox->standardButton(button)) { case QDialogButtonBox::Save: { if(QFileInfo(newfile).isRelative()) newfile = dir+QDir::separator()+newfile; if(!QFileInfo(newfile).exists()) { QMessageBox::warning(this, tr("Error"), tr("File %1 not found!").arg(newfile)); errorDuringSave = true; return; } newfile = ui.lineEdit->text(); QFileInfo cueinfo(cue); QFile fin(cue), fout(cueinfo.path() + QDir::separator() + cueinfo.completeBaseName()+"_fixed.cue"); if(!fin.open(QFile::ReadOnly) || !fout.open(QFile::WriteOnly)) { QMessageBox::critical(this, tr("Error"), tr("Unable to create file %1").arg(fout.fileName())); errorDuringSave = true; return; } QTextStream sin(&fin), sout(&fout); QString line; do { line = sin.readLine(); if(line.startsWith("FILE")) { //QStringList l = line.split(' ', QString::SkipEmptyParts); sout << "FILE \"" << newfile << "\" WAVE";// << l.last(); } else { sout << line; } endl(sout); } while (!line.isNull()); fin.close(); fout.close(); QMessageBox::information(this, tr("Success"), tr("New CUE sheet stored as %1").arg(fout.fileName())); accept(); break; } default: break; } }
// find all files mentioned in structure, e.g. <bitmap>filename</bitmap> void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath) { // Is 'node' XML node element? if (node == NULL) return; if (node->GetType() != wxXML_ELEMENT_NODE) return; bool containsFilename = NodeContainsFilename(node); wxXmlNode *n = node->GetChildren(); while (n) { if (containsFilename && (n->GetType() == wxXML_TEXT_NODE || n->GetType() == wxXML_CDATA_SECTION_NODE)) { wxString fullname; if (wxIsAbsolutePath(n->GetContent()) || inputPath.empty()) fullname = n->GetContent(); else fullname = inputPath + wxFILE_SEP_PATH + n->GetContent(); if (flagVerbose) wxPrintf(_T("adding ") + fullname + _T("...\n")); wxString filename = GetInternalFileName(n->GetContent(), flist); n->SetContent(filename); if (flist.Index(filename) == wxNOT_FOUND) flist.Add(filename); wxFileInputStream sin(fullname); wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename); sin.Read(sout); // copy the stream } // subnodes: if (n->GetType() == wxXML_ELEMENT_NODE) FindFilesInXML(n, flist, inputPath); n = n->GetNext(); } }
void compress(Stream* in_stream, Stream* out_stream) { BufferedStreamReader<4 * KB> sin(in_stream); BufferedStreamWriter<4 * KB> sout(out_stream); assert(in_stream != nullptr); assert(out_stream != nullptr); init(); ent.init(); for (;;) { int c = sin.get(); if (c == EOF) break; processByte<false>(sout, c); if (c == kEOFChar) { ent.encodeBit(sout, 0); } update(c); } processByte<false>(sout, kEOFChar); ent.encodeBit(sout, 1); ent.flush(sout); }
signed char* PbfInputSplit::writeFields(size_t* len) const { stringstream sout(stringstream::out); DataOutputStream dos(sout); dos.writeLong(_start); dos.writeLong(_length); dos.writeString(_path); dos.writeString(_locations); dos.writeInt(_headers.size()); for (size_t i = 0; i < _headers.size(); i++) { dos.writeLong(_headers.at(i)); } sout.flush(); *len = sout.str().length(); signed char* result = new signed char[*len]; memcpy(result, sout.str().data(), *len); return result; }
char * loc_inside_string(int where) { char *reg_name; if (loc_depth(where) == LOC_build) { if (subkind(loc(where)) == sub_ocean) return sout(", in %s", box_name(province(where))); if (loc_depth(loc(where)) == LOC_province) return sout(", in province %s", box_name(province(where))); return sout(", in %s", box_name(province(where))); } else if (loc_depth(where) == LOC_subloc) { if (subkind(province(where)) == sub_ocean) return sout(", in %s", box_name(province(where))); else if (!valid_box(province(where))) return sout(", adrift in the Cosmos"); else return sout(", in province %s", box_name(province(where))); } else if (subkind(where) == sub_ocean) { reg_name = name(region(where)); if (reg_name && *reg_name) return sout(", in %s", reg_name); return ""; } else { reg_name = name(region(where)); if (reg_name && *reg_name) return sout(", in %s", reg_name); return ""; } }
static bool shouldLogCallable(ObjectPtr callable) { if (logMatchSymbols.empty()) return false; ModulePtr m = staticModule(callable); if (!m) return false; string name; llvm::raw_string_ostream sout(name); printStaticName(sout, callable); sout.flush(); pair<string,string> specificKey = make_pair(m->moduleName, name); pair<string,string> moduleGlobKey = make_pair(m->moduleName, string("*")); pair<string,string> anyModuleKey = make_pair(string("*"), name); return logMatchSymbols.find(specificKey) != logMatchSymbols.end() || logMatchSymbols.find(moduleGlobKey) != logMatchSymbols.end() || logMatchSymbols.find(anyModuleKey) != logMatchSymbols.end(); }
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location) { #if !wxUSE_URL return NULL; #else wxString right = GetProtocol(location) + wxT(":") + StripProtocolAnchor(location); wxURL url(right); if (url.GetError() == wxURL_NOERR) { wxInputStream *s = url.GetInputStream(); wxString content = url.GetProtocol().GetContentType(); if (content == wxEmptyString) content = GetMimeTypeFromExt(location); if (s) { wxString tmpfile = wxFileName::CreateTempFileName(wxT("wxhtml")); { // now copy streams content to temporary file: wxFileOutputStream sout(tmpfile); s->Read(sout); } delete s; return new wxFSFile(new wxTemporaryFileInputStream(tmpfile), right, content, GetAnchor(location) #if wxUSE_DATETIME , wxDateTime::Now() #endif // wxUSE_DATETIME ); } } return (wxFSFile*) NULL; // incorrect URL #endif }
void addForm::add_contact() { QFile fileNewContact("Contacts/"+ui->lName->text().simplified()+" "+ui->lNick->text().simplified()); if(fileNewContact.open(QIODevice::WriteOnly|QIODevice::Text)) { QTextStream sout(&fileNewContact); sout<<ui->lNick->text().simplified()<<endl << ui->lName->text().simplified()<<endl << ui->lFathername->text().simplified()<<endl << ui->lFamily->text().simplified()<<endl << ui->lCity->text().simplified()<<endl << ui->lICQ->text().simplified()<<endl << ui->lVK->text().simplified()<<endl << ui->lOK->text().simplified()<<endl << ui->lFacebook->text().simplified()<<endl << ui->lPhone->text().simplified()<<endl << ui->lMail->text().simplified()<<endl << ui->lInfo->toPlainText().simplified()<<endl; } fileNewContact.close(); emit closing(); this->close(); }