static void main_loop() { int p = 0; int c, n; L: show_all(); sh(p); fflush(stdout); while (1) { c = getch(); if (c == 3 || c == 4 || c == 27 || c < 0) break; if (c == 257 && p > 0) p--; if (c == 258 && p < counts - 1) p++; if (c == 259 && p < counts - 19) p += 19; if (c == 260 && p >= 19) p -= 19; if (c == 13 || c == 10) { bbsnet(p); goto L; } for (n = 0; n < counts; n++) if (str[n] == c) p = n; sh(p); fflush(stdout); } }
void visit_eq(app* eq) { ast_manager& m = m_manager; SASSERT(m.is_eq(eq)); sort* s = m.get_sort(eq->get_arg(0)); SASSERT(is_sort_of(s, m_fid, ARRAY_SORT)); // sort* rng = get_array_range(s); unsigned arity = get_array_arity(s); shift_vars sh(m); expr_ref e1(m), e2(m); sh(find(eq->get_arg(0)), arity, e1); sh(find(eq->get_arg(1)), arity, e2); expr_ref_vector args(m); buffer<symbol> names; ptr_buffer<sort> sorts; args.push_back(e1); for (unsigned i = 0; i < arity; ++i) { args.push_back(m.mk_var(i, get_array_domain(s, i))); sorts.push_back(get_array_domain(s, arity - i - 1)); names.push_back(symbol(m_offset++)); } e1 = mk_select(args.size(), args.c_ptr()); args[0] = e2; e2 = mk_select(args.size(), args.c_ptr()); e1 = m.mk_eq(e1, e2); e1 = m.mk_quantifier(true, arity, sorts.c_ptr(), names.c_ptr(), e1, 1); insert(eq, e1); }
long __Call_sh( CDSR_VMEval& /*vm*/, MMD_Address& addr, UniWord *arg ) { #if _DEBUG if( addr.param2 < 0 ) throw _T("__Call_(fun) : internal error, out of range"); #endif if( addr.param2 == 0 ) // DSRDATA_TYPE_REAL *(arg - 1) = CDSRReal( sh( (arg - 1)->getReal() ) ); else // DSRDATA_TYPE_COMPLEX *(arg - 1) = CDSRComplex( sh( (arg - 1)->getComplex() ) ); return 1 - addr.param3; }
void reflective_copy(const Src& s, Dst& d) { holder sh(create_holder(const_cast< Src& >(s))); holder dh(create_holder(d)); reflective_copy(sh, dh); }
void CdbDumperHelper::moduleLoadHook(const QString &module, HANDLE debuggeeHandle) { if (loadDebug > 1) qDebug() << "moduleLoadHook" << module << m_state << debuggeeHandle; switch (m_state) { case Disabled: case Initialized: break; case NotLoaded: // Try an inject load as soon as a Qt lib is loaded. // for the thread to finish as this would lock up. if (m_tryInjectLoad && module.contains(QLatin1String("Qt"), Qt::CaseInsensitive)) { // Also shows up in the log window. m_manager->showStatusMessage(msgLoading(m_library, true), messageTimeOut); QString errorMessage; SharedLibraryInjector sh(GetProcessId(debuggeeHandle)); if (sh.remoteInject(m_library, false, &errorMessage)) { m_state = InjectLoading; } else { m_state = InjectLoadFailed; // Ok, try call loading... m_manager->showDebuggerOutput(LogMisc, msgLoadFailed(m_library, true, errorMessage)); } } break; case InjectLoading: // check if gdbmacros.dll loaded if (module.contains(QLatin1String(dumperModuleNameC), Qt::CaseInsensitive)) { m_state = Loaded; m_manager->showDebuggerOutput(LogMisc, msgLoadSucceeded(m_library, true)); } break; } }
int basic_socket_impl::send_data(std::string dat) { boost::shared_array<char> sh(new char[dat.size()]); memcpy(sh.get(), dat.c_str(), dat.size()); stream_buffer buf(sh, dat.size(), dat.size()); return send_data(buf); }
const AnimationData* ResourceLoader::anim(string name) { auto anim = animations.find(name); if (anim == animations.end()) { pugi::xml_document animXml; string path = root + name; animXml.load_file(path.c_str()); if (animXml.begin() == animXml.end()) { // Couldn't open .anim file! std::cerr << "ERROR: couldn't load animation \"" << path << "\"\n"; return &AnimationData::defaultAnim; } pugi::xml_node node = animXml.child("animations"); string sheetName = animXml.first_child().first_attribute().as_string(); const SpriteSheet* sheet = sh(sheetName); if (sheet == nullptr) { std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } AnimationData& aData = animations[name]; if (!loadAnimData(aData, animXml, sheet)) { animations.erase(animations.find(name)); std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } const sf::Texture* texture = tex(sheet->imageName); if (texture == nullptr) { std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } aData.tx = texture; return &aData; } return &anim->second; }
double Pst:: psutt(const ECString& shU, int t, int word_num) { //cerr << "Unknown word: " << shU << " for tag: " << t << endl; double ans = pHugt(t); //cerr << "pHugt = " << ans << endl; if(ans == 0) return 0; double phyp = pHypgt(shU,t); ans *= phyp; //cerr << "pHypgt = " << phyp << endl; double phcp = pCapgt(shU,t, word_num); ans *= phcp; ans *= .000001; if(Term::fromInt(t)->openClass()) { char temp[1024]; ECString sh(langAwareToLower(shU.c_str(),temp)); float phegt = pegt(sh,t); if(phegt == 0) phegt = .00001; //if(phegt == 0) phegt = .00005; //cerr << "pegt( " << sh << " | " << t << " ) = " << phegt << endl; ans *= phegt; } else ans *= .00000001; //cerr << "psutt( " << shU << " | " << t << " ) = " << ans << endl; return ans; }
void CaptureWgt::slotResolution() { QObject * o = sender(); QAction * a = dynamic_cast<QAction *>( o ); if ( !a ) return; for ( int i=0; i<pd->resList.size(); i++ ) { QAction * n = dynamic_cast<QAction *>( pd->resList[i] ); if ( ( n ) && ( a == n ) ) n->setChecked( true ); else n->setChecked( false ); } QString stri = a->text(); QRegExp reg( "\\d{1,}\\s{0,}x" ); QString sw( "640 x" ); if ( reg.indexIn( stri ) != -1 ) sw = reg.cap( 0 ); QString sh( "x 480" ); reg.setPattern( "x\\s{0,}\\d{1,}" ); if ( reg.indexIn( stri ) != -1 ) sh = reg.cap( 0 ); int w = sw.left( sw.length() - 1 ).toInt(); int h = sh.right( sh.length() - 1 ).toInt(); pd->cap->setResolution( QSize( w, h ) ); }
/** * Sort a linked list in an order defined by the sort handler * * @param list Linked list * @param sh Sort handler * @param arg Handler argument */ void list_sort(struct list *list, list_sort_h *sh, void *arg) { struct le *le; bool sort; if (!list || !sh) return; retry: le = list->head; sort = false; while (le && le->next) { if (sh(le, le->next, arg)) { le = le->next; } else { struct le *tle = le->next; list_unlink(le); list_insert_after(list, tle, le, le->data); sort = true; } } if (sort) { goto retry; } }
static ERROR clink(const struct stage *stage, const char *out_fn, const char *inputs, const char *extra) { static const char fmt[] = "%s %s " LDFLAGS " %s %s %s -o %s%s %s"; const char *ext = ""; if (strcmp(g_opt.compiler, "emcc") == 0) { ext = ".js"; } char *user_ldflags = collect_stage_flag(stage, ID_LDFLAGS); size_t len = strlen(fmt) + strlen(g_opt.ccache) + strlen(g_opt.compiler) + strlen(g_opt.cflags) + strlen(inputs) + strlen(extra) + strlen(out_fn) + strlen(ext) + strlen(user_ldflags); char *cmd = calloc(len + 1, sizeof(char)); sprintf(cmd, fmt, g_opt.ccache, g_opt.compiler, g_opt.cflags, inputs, extra, out_fn, ext, user_ldflags); free(user_ldflags); error e = sh(cmd); free(cmd); EXCEPT(e); return 0; }
// send server hello void sendServerHello(SSL& ssl, BufferOutput buffer) { if (ssl.getSecurity().get_resuming()) ssl.verifyState(clientKeyExchangeComplete); else ssl.verifyState(clientHelloComplete); if (ssl.GetError()) return; ServerHello sh(ssl.getSecurity().get_connection().version_, ssl.getSecurity().get_connection().compression_); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildServerHello(ssl, sh); ssl.set_random(sh.get_random(), server_end); buildHeaders(ssl, hsHeader, rlHeader, sh); buildOutput(*out.get(), rlHeader, hsHeader, sh); hashHandShake(ssl, *out.get()); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }
void SwaptionVolatilityHullWhite::performCalculations() const { SwaptionVolatilityDiscrete::performCalculations(); // we might use iterators here... for (Size i=0; i<volatilities_.rows(); ++i) for (Size j=0; j<volatilities_.columns(); ++j) volatilities_[i][j] = volHandles_[i][j]->value(); interpolation_.update(); //LevenbergMarquardt lm; Simplex sp(0.001); // we should use another optimizer here... EndCriteria ec(1000,500,1E-8,1E-8,1E-8); NoConstraint cons; Array val(1); for(Size i=0; i<optionTenors_.size() ; i++) { for(Size j=0; j<swapTenors_.size() ; j++) { boost::shared_ptr<SwaptionHelper> sh(new SwaptionHelper(optionTenors_[i],swapTenors_[j],Handle<Quote>(new SimpleQuote(volatilities_[i][j])),indexBase_->iborIndex(),indexBase_->fixedLegTenor(), indexBase_->dayCounter(),Actual360(),yts_)); // FIXME float leg day counter hardcoded ? boost::shared_ptr<HullWhite> hwTmp(new HullWhite(yts_,reversion_)); boost::shared_ptr<JamshidianSwaptionEngine> jamshidianEngine(new JamshidianSwaptionEngine(hwTmp,yts_)); sh->setPricingEngine(jamshidianEngine); calibrationFunction cfct(hwTmp,sh); val[0]=sqrt(0.01); Problem p(cfct,cons,val); sp.minimize(p,ec); hwsigmas_[i][j] = p.currentValue()[0]*p.currentValue()[0]; //std::cout << std::setprecision(8) << "calibration: " << optionTenors_[i] << "/" << swapTenors_[j] << " sigma=" << hwsigmas_[i][j] << " model=" << sh->modelValue() << " market=" << sh->marketValue() << std::endl; } } interpolationSigma_.update(); }
//trace ray RGB Multi::traceRay(const Ray& ray) { Shade sh(world_->hitNearestObject(ray)); if (sh.hit) return sh.color; else return world_->bgColor; }
unsigned long long mul(const unsigned long long& a, const unsigned long long& b, const unsigned long long& m) { unsigned long long a_h = (a >> 32), a_l = (a << 32) >> 32, b_h = (b >> 32), b_l = (b << 32) >> 32, val_hh = (a_h * b_h) % m, val_hl = (a_h * b_l) % m, val_lh = (a_l * b_h) % m, val_ll = (a_l * b_l) % m; sh(val_hh, 64, m); sh(val_lh, 32, m); sh(val_hl, 32, m); unsigned long long res = (val_hh + val_hl) % m; res = (res + val_lh) % m; res = (res + val_ll) % m; return res; }
int main() { boost::shared_ptr<int> sh(new int(99)); boost::weak_ptr<int> w(sh); HANDLE threads[2]; threads[0] = CreateThread(0, 0, reset, &sh, 0, 0); threads[1] = CreateThread(0, 0, print, &w, 0, 0); WaitForMultipleObjects(2, threads, TRUE, INFINITE); }
QSize SplitterCollapser::sizeHint() const { int extent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); QSize sh(extent * 3 / 4, extent * 240 / 100); if (d->isVertical()) { sh.transpose(); } return sh; }
Search::Search(QWidget *parent) : QMainWindow(parent), ui(new Ui::Search) { ui->setupUi(this); sh(); }
int main(int argc, char **argv) { int ret, f; if(argc==1) return sh(0,1); if((f=open(argv[1],O_RDONLY)) == -1) { writestr(2,"sh: "); writestr(2,argv[1]); writestr(2,": Can't open\n"); return 1; } ret=sh(f,0); close(f); return ret; }
int MASA::navierstokes_4d_compressible_powerlaw<Scalar>::init_var() { // Set parameter values directly on the instance MASA::nsctpl::isothermal_channel(*this); // Tell MASA about each parameter so it believes they are initialized set_helper<Scalar> sh(this); this->foreach_parameter(sh); return 0; }
virtual QSize sizeHint() const { QSize sh(2*frameWidth()+1,2*frameWidth()+1); if (verticalScrollBar()) sh.setWidth(sh.width() + verticalScrollBar()->sizeHint().width()); if (horizontalScrollBar()) sh.setHeight(sh.height() + horizontalScrollBar()->sizeHint().height()); if (widget()) sh += widgetResizable() ? widget()->sizeHint() : widget()->size(); return sh; }
void TDMShutdownBase::slotActivatePlugMenu() { if (needRoot) { TQPopupMenu *cmnu = verify->getPlugMenu(); if (!cmnu) return; TQSize sh( cmnu->sizeHint() / 2 ); cmnu->exec( geometry().center() - TQPoint( sh.width(), sh.height() ) ); } }
int main(int argc, char **argv) { print_copyright(); print_license(); #ifdef SVNRELEASE printf("At svn revision %s.\n\n",SVNREVISION); #endif print_hostname(); if(argc!=5) { printf("Usage: %s zeta l Nf method\n",argv[0]); printf("zeta is the STO exponent to fit\n"); printf("l is angular momentum to use\n"); printf("Nf is number of exponents to use\n"); printf("method is 0 for even-tempered, 1 for well-tempered and 2 for full optimization, or 3 for midpoint quadrature.\n"); return 1; } // Read parameteres double zeta=atof(argv[1]); double am=atoi(argv[2]); int Nf=atoi(argv[3]); int method=atoi(argv[4]); // Do the optimization std::vector<contr_t> contr; if(method>=0 && method<=2) contr=slater_fit(zeta,am,Nf,true,method); else if(method==3) contr=slater_fit_midpoint(zeta,am,Nf); else throw std::runtime_error("Unknown method.\n"); // Print them out printf("\nExponential contraction\nc_i\t\tz_i\t\tlg z_i\n"); for(size_t i=0;i<contr.size();i++) printf("% e\t%e\t% e\n",contr[i].c,contr[i].z,log10(contr[i].z)); // Form basis set ElementBasisSet elbas("El"); FunctionShell sh(am,contr); elbas.add_function(sh); // Save the basis set BasisSetLibrary baslib; baslib.add_element(elbas); baslib.save_gaussian94("slater-contr.gbs"); // also in decontracted form baslib.decontract(); baslib.save_gaussian94("slater-uncontr.gbs"); return 0; }
vector<int> smooth(vector<int> hists, int bins) { vector<int> sh(bins, 0); sh[0] = (hists[0] + hists[1]) /2; sh[bins - 1] = (hists[bins - 1] + hists[bins -2]) / 2; for(int pp = 1; pp < bins - 1; pp ++) { sh[pp] = (hists[pp-1] + hists[pp] + hists[pp+1])/3; //printf("%d ", h[pp]) } return sh; }
IServerSPtr ServersManager::createServer(IConnectionSettingsBaseSPtr settings) { if (!settings) { NOTREACHED(); return IServerSPtr(); } connectionTypes conT = settings->type(); IServer* server = nullptr; #ifdef BUILD_WITH_REDIS if (conT == REDIS) { server = new redis::RedisServer(settings); } #endif #ifdef BUILD_WITH_MEMCACHED if (conT == MEMCACHED) { server = new memcached::MemcachedServer(settings); } #endif #ifdef BUILD_WITH_SSDB if (conT == SSDB) { server = new ssdb::SsdbServer(settings); } #endif #ifdef BUILD_WITH_LEVELDB if (conT == LEVELDB) { server = new leveldb::LeveldbServer(settings); } #endif #ifdef BUILD_WITH_ROCKSDB if (conT == ROCKSDB) { server = new rocksdb::RocksdbServer(settings); } #endif #ifdef BUILD_WITH_UNQLITE if (conT == UNQLITE) { server = new unqlite::UnqliteServer(settings); } #endif #ifdef BUILD_WITH_LMDB if (conT == LMDB) { server = new lmdb::LmdbServer(settings); } #endif if (!server) { NOTREACHED(); return IServerSPtr(); } IServerSPtr sh(server); servers_.push_back(sh); return sh; }
QSizeF MWidgetController::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_D(const MWidgetController); QSizeF sh(constraint); // check if we have, or if we can create, a view if (view()) { QRect margins = d->view->margins(); qreal widthMargin = margins.left() + margins.width(); qreal heightMargin = margins.top() + margins.height(); // Adjust the constraint to remove the margins if (sh.width() > 0) sh.setWidth( qMax((qreal)0, sh.width() - widthMargin) ); if (sh.height() > 0) sh.setHeight( qMax((qreal)0, sh.height() - heightMargin) ); //Combine the constraint with the size given by the style (e.g. as set by the CSS file), //with the constraint taking priority QSizeF styleSize; if (which == Qt::MinimumSize) styleSize = d->view->style()->minimumSize(); else if (which == Qt::MaximumSize) styleSize = d->view->style()->maximumSize(); else if (which == Qt::PreferredSize) styleSize = d->view->style()->preferredSize(); combineSize(sh, styleSize); // The size isn't fully specified by the constraint and CSS. Fetch the size hint from the view if (!sh.isValid()) combineSize(sh, d->view->sizeHint(which, sh)); // unless the final size dimensions are unconstrained, we need to add margins to them // so the layouting system reserves enough space for the content + margins. if (sh.width() >= 0) sh.rwidth() += widthMargin; if (sh.height() >= 0) sh.rheight() += heightMargin; } //If the size is not specified manually, nor by css, nor by the view, then //fallback to using the layout's sizeHint if (!sh.isValid()) { QSizeF widgetSize = MWidget::sizeHint(which, sh); if (widgetSize.width() == 0) // Work around bug NB#189091 widgetSize = MWidget::sizeHint(which); combineSize(sh, widgetSize); } // Round the size hint return sh.toSize(); }
static ERROR run_examples(const struct stage *stage) { static const char *out_fn = "a.out.examples"; static const char *main_fn = "a.out.examples.c"; FILE *run = fopen(main_fn, "w"); if (run == NULL) { THROWF(errno, "Cannot open output file '%s'", main_fn); } for (size_t n = 0; n < stage->sorted_count; ++n) { const struct module *mod = stage->sorted[n]; fprintf(run, "void "); print_c_runexamples_name(run, mod); fprintf(run, "(void);\n"); } fprintf(run, "void _$Nprelude(int *argc, char ***argv, char ***env);\n" "extern int n$builtins$last_exit_code;\n" "void _$Npostlude(int *ret);\n"); fprintf(run, "int main(int argc, char **argv, char **env) {\n" "_$Nprelude(&argc, &argv, &env);\n"); for (size_t n = 0; n < stage->sorted_count; ++n) { const struct module *mod = stage->sorted[n]; print_c_runexamples_name(run, mod); fprintf(run, "();\n"); } fprintf(run, "n$builtins$last_exit_code = 0;\n" "return n$builtins$last_exit_code;\n" "}\n"); fclose(run); char *inputs = file_list((const struct module **)stage->sorted, stage->sorted_count, o_filename); error e = clink(stage, out_fn, inputs, main_fn); free(inputs); EXCEPT(e); static const char *fmt = "%s ./%s%s"; const char *runner = ""; const char *ext = ""; if (strcmp(g_opt.compiler, "emcc") == 0) { runner = "d8"; ext = ".js"; } char *cmd = calloc(strlen(fmt) + strlen(runner) + strlen(main_fn) + strlen(ext) + 1, sizeof(char)); sprintf(cmd, fmt, runner, out_fn, ext); e = sh(cmd); free(cmd); EXCEPTF(e, "examples failed"); return 0; }
void getDisparities(MRF *mrf, int width, int height, CByteImage &disp) { CShape sh(width, height, 1); disp.ReAllocate(sh); int n = 0; for (int y = 0; y < height; y++) { uchar *row = &disp.Pixel(0, y, 0); for (int x = 0; x < width; x++) { row[x] = mrf->getLabel(n++); } } }
void S_gen(char *s) {PA_variable *pp; haelem *hp; hp = SC_hasharr_lookup(PA_gs.variable_tab, s); if (hp != NULL) {pp = (PA_variable *) hp->def; varh(pp);} else if (SC_numstrp(s)) sh(s); return;}
virtual QSize sizeHint() const { QSize sh(2*frameWidth()+1, 2*frameWidth()+1); if (verticalScrollBar()) sh.rwidth() += verticalScrollBar()->sizeHint().width(); if (horizontalScrollBar()) sh.rheight() += horizontalScrollBar()->sizeHint().height(); if (widget()) sh += widgetResizable() ? widget()->sizeHint() : widget()->size(); QSize desktopSize = QApplication::desktop()->availableGeometry(this).size(); return sh.boundedTo(desktopSize/2); }