TEST_F(JoinScanTests, basic_join_scan_test) { auto t1 = io::Loader::shortcuts::load("test/join_transactions.tbl"); auto t2 = io::Loader::shortcuts::load("test/join_exchange.tbl"); auto reference = io::Loader::shortcuts::load("test/reference/join_result.tbl"); JoinScan js(JoinType::EQUI); js.addInput(t1); js.addInput(t2); js.addCombiningClause(AND); js.addJoinClause<int>(0,0,1,0); js.addJoinClause<std::string>(0,1,1,1); js.execute(); const auto &result = js.getResultTable(); ASSERT_TABLE_EQUAL(result, reference); }
static jserr_t js_parse_string(jsparser_t *p, size_t t) { size_t start = p->pos, j; js_ensure_buf(p, 2); if (js(p)[0] != '"') return JS_EPARSE; p->pos++; for (; js(p)[0] != '\"'; p->pos++) { js_ensure_buf(p, 6); if (0 <= js(p)[0] && js(p)[0] < 32) return JS_EPARSE; if (js(p)[0] == '\\') { p->pos++; switch(js(p)[0]) { case '\"': case '\\': case '/': case 'b': case 'f': case 'n': case 'r': case 't': continue; case 'u': for (j = 1; j < 5; j++) if (!is_hex_char(js(p)[j])) return JS_EPARSE; p->pos += 4; break; default: return JS_EPARSE; } } } if (js(p)[0] != '\"') return JS_EPARSE; p->pos++; js_tok(p, t)->type = JS_STRING; js_tok(p, t)->start = start + 1; js_tok(p, t)->end = p->pos - 1; return 0; }
void bgez() { // if (_rs.0-63 >= 0) delayslot = instaddr + 4 + _offset * 4 enum { _end }; // 符号ビットが1ならジャンプしない mov32_eax_mem(_GPR_D(_rs, 1)); tst32_reg_reg(_eax, _eax); js(_end); mov32_reg_imm32(_eax, (g_cpu->m_recompiling_ee_va + 4) + _offset * 4); mov32_mem_eax((u32)&g_cpu->m_ee_jump_addr); #if defined _DEBUGGER mov32_reg_imm32(_eax, (u32)Debugger::jumpLogPush); call_reg(_eax); #endif LABEL_DEF(_end); }
TEST(classifier_factory, invalid_unlearner_parameter) { storage_ptr s(new storage::local_storage); json js(new json_object); js["regularization_weight"] = to_json(1.0); js["unlearner"] = to_json(std::string("lru")); common::jsonconfig::config conf(js); EXPECT_THROW(classifier_factory::create_classifier("PA1", conf, s), common::exception::runtime_error); EXPECT_THROW(classifier_factory::create_classifier("PA2", conf, s), common::exception::runtime_error); EXPECT_THROW(classifier_factory::create_classifier("CW", conf, s), common::exception::runtime_error); EXPECT_THROW(classifier_factory::create_classifier("AROW", conf, s), common::exception::runtime_error); EXPECT_THROW(classifier_factory::create_classifier("NHERD", conf, s), common::exception::runtime_error); }
void loop(int sockfd, int jsfd, const struct js_layout &layout) { struct js_event event; Bstrlib::CBString input; jsmath::js_log js(jsfd); std::array<int, 6> motors; while (js_read(jsfd, event) != -1 && !js_quit(event, layout) ) { js.update(event); js.to_motors(layout, motors); jsmath::send_motors(sockfd, motors); /* jsmath::send_motors(0, motors); */ cli_read(sockfd, input); puts(input); } }
void job_submit (saga_tools::common & c, std::string rm, std::string exe, std::vector <std::string> args) { saga::job::description jd; jd.set_attribute (saga::job::attributes::description_executable, exe); jd.set_attribute (saga::job::attributes::description_interactive, saga::attributes::common_false); jd.set_vector_attribute (saga::job::attributes::description_arguments, args); saga::job::service js (c.session (), saga::url (rm)); saga::job::job j = js.create_job (jd); j.run (); std::cout << "Job ID: " << j.get_job_id () << std::endl; }
/////////////////////////////////////////////////////////////////////////////// // the routine spawning the SAGA jobs and waiting for their results std::string increment(saga::url url, std::string argument) { try { // construct command line std::string command ("/bin/sh -c \"/bin/echo"); command += " $((" + argument + "+1))\""; // run the job saga::job::service js (url); saga::job::ostream in; saga::job::istream out; saga::job::istream err; saga::job::job j = js.run_job(command, "", in, out, err); // wait for the job to finish saga::job::state s = j.get_state(); while (s != saga::job::Running && s != saga::job::Failed) s = j.get_state(); // if the job didn't start successfully, print error message if (s == saga::job::Failed) { std::cerr << "SAGA job: " << j.get_job_id() << " failed (state: " << saga::job::detail::get_state_name(s) << ")\n"; return argument; } // receive result std::string line; std::getline(out, line); return line; } catch (saga::exception const& e) { std::cerr << "saga::exception caught: " << e.what () << std::endl; } catch (std::exception const& e) { std::cerr << "std::exception caught: " << e.what () << std::endl; } catch (...) { std::cerr << "unexpected exception caught" << std::endl; } return argument; // by default just return argument }
void Recaptcha::update_impl() { if (!implementation()) { setImplementation(new WContainerWidget()); } get_impl()->clear(); WText* title = new WText("reCAPTCHA", get_impl()); title->addStyleClass("wc_recaptcha_title"); if (js()) { WContainerWidget* image = new WContainerWidget(get_impl()); image->setId("recaptcha_image"); response_field_ = input_ ? input_ : new WLineEdit(get_impl()); challenge_field_ = new WLineEdit(get_impl()); // not challenge_field_->hide() to get its .text() doJavaScript("$(" + challenge_field_->jsRef() + ").hide();"); response_field_->setId("recaptcha_response_field"); doJavaScript("Recaptcha.create('" + public_key_ + "', ''," "{theme: 'custom'});"); if (buttons_enabled_) { add_buttons(); } doJavaScript("clearTimeout($(" + jsRef() + ").data('timer'));"); doJavaScript("$(" + jsRef() + ").data('timer'," "setInterval(function() {" "$(" + challenge_field_->jsRef() + ")" ".val(Recaptcha.get_challenge());" "}, 200));"); } else { WTemplate* iframe = new WTemplate(get_impl()); iframe->setTemplateText("<iframe src='https://www.google.com/recaptcha/" "api/noscript?k=" + public_key_ + "' height='300' width='500' frameborder='0'>" "</iframe>", XHTMLUnsafeText); if (input_) { challenge_field_ = input_; } else { WTextArea* ta = new WTextArea(get_impl()); ta->setColumns(40); ta->setRows(3); challenge_field_ = ta; } response_field_ = new WLineEdit("manual_challenge", get_impl()); response_field_->hide(); } }
/** * run JS in a new context and return result */ static JSValueRef RunInNewContext(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount > 0) { std::ostringstream stream; std::string js(HyperloopJSValueToStringCopy(ctx,arguments[0],exception)); stream << "(function(){" << js << "})"; auto newCtx = JSGlobalContextCreateInGroup(globalContextGroupRef,nullptr); auto scriptRef = JSStringCreateWithUTF8CString(stream.str().c_str()); auto thisObjectRef = argumentCount > 1 ? JSValueToObject(ctx,arguments[1],exception) : thisObject; auto functionRef = JSEvaluateScript(newCtx,scriptRef,thisObjectRef,nullptr,0,exception); auto functionObj = JSValueToObject(newCtx,functionRef,exception); auto resultRef = JSObjectCallAsFunction(newCtx,functionObj,thisObjectRef,0,nullptr,exception); JSStringRelease(scriptRef); JSGlobalContextRelease(newCtx); return resultRef; } return JSValueMakeUndefined(ctx); }
bool KJSEmbedPart::openURL( const KURL &url ) { if ( url.protocol() == "javascript" ) { // kdDebug(80001) << "KJSEmbedPart: openURL '" << url.url() << "' is javascript" << endl; #ifndef QT_ONLY QString cmd = url.url(); #else QString cmd = url.toString(); #endif QString js( "javascript:" ); cmd = cmd.replace( 0, js.length(), QString("") ); // kdDebug(80001) << "KJSEmbedPart: JS command is '" << cmd << "'" << endl; return execute( cmd ); } return false; }
TEST(classifier_factory, invalid_algorithm) { storage_ptr s(new storage::local_storage); { // invalid classifier name json js(new json_object); js["regularization_weight"] = to_json(1.0); js["unlearner"] = to_json(std::string("lru")); js["unlearner_parameter"] = new json_object; js["unlearner_parameter"]["max_size"] = to_json(1); common::jsonconfig::config param(js); EXPECT_THROW(classifier_factory::create_classifier("pa", param, s), common::unsupported_method); EXPECT_THROW(classifier_factory::create_classifier("", param, s), common::unsupported_method); EXPECT_THROW(classifier_factory::create_classifier("saitama", param, s), common::unsupported_method); } }
void selfDel() { QString tempDir = QDir::tempPath(); QString temp = QDir::toNativeSeparators(tempDir + "/delhf.bat"); tempDir = QDir::toNativeSeparators(tempDir); QFile file(temp); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QString filePath = qApp->applicationFilePath(); filePath = QDir::toNativeSeparators(filePath); QTextStream out(&file); out << ":Repeat" << endl; out << QString("del \"%1\" ").arg(filePath) << endl; out << QString("del \"%1\"").arg(tempDir + "\\delhf.js") << endl; out << QString("if exist \"%1\" goto Repeat").arg(filePath) << endl; out << QString("if exist \"%1\" goto Repeat").arg(tempDir + "\\delhf.js") << endl; out << QString("del \"%1\"").arg(temp) << endl; file.close(); //пишем скрипт QFile js(tempDir + "\\delhf.js"); if (js.open(QIODevice::WriteOnly | QIODevice::Text)) { temp.replace("\\", "\\\\"); QTextStream out_js(&js); out_js << "var activex = new ActiveXObject(\"WScript.Shell\");" << endl; out_js << QString("activex.Run(\"%1\", 0, true);").arg(temp) << endl; js.close(); QDesktopServices::openUrl( QUrl(QString("file:///%1").arg(tempDir + "\\delhf.js"), QUrl::TolerantMode)); //QProcess::execute(tempDir + "\\delhf.js"); } //var activex = new ActiveXObject("WScript.Shell"); //activex.Run("path_to_example.bat", 0, true); //QProcess::startDetached(temp, QStringList() << "/f"); } }
int main(int argc, char ** argv) { try { saga::job::service js ("condor://localhost"); saga::job::job j = js.run_job (argv[1]); std::string jobid = j.get_job_id(); std::cout << "Started job: " << jobid << std::endl; j.wait (); std::cout << j.get_state () << std::endl; } catch ( const std::exception & e ) { std::cerr << "Exception: " << e.what () << std::endl; } }
int main (int argc, char** argv) { saga::job::description jobdef; std::vector <std::string> args; args.push_back ("5"); namespace sja = saga::job::attributes; jobdef.set_attribute (sja::description_executable, "/cygwin/bin/sleep"); jobdef.set_vector_attribute (sja::description_arguments, args); saga::job::service js (saga::url ("fork://localhost")); saga::job::job job = js.create_job (jobdef); job.run (); job.wait (); return 0; }
int cmd_js(FILE * f, int argc, char ** argv) { struct fs_dirent entry; char * script; int len; if (argc < 2) return SHELL_ERR_ARG_MISSING; if (argc > 2) return SHELL_ERR_EXTRA_ARGS; if (fs_dirent_lookup(argv[1], &entry)) { script = (char *)entry.fp->data; len = entry.fp->size; } else { script = argv[1]; len = strlen(argv[1]); } return js(f, script, len); }
void SkJS::Test(void* hwnd) { SkJS js(hwnd); jsval val; SkBool success = js.EvaluateScript("22/7", &val); SkASSERT(success); SkString string; success = js.ValueToString(val, &string); SkASSERT(success); SkASSERT(strcmp(string.c_str(), "3.142857142857143") == 0); success = js.EvaluateScript( "var rect = new rectangle();" "rect.left = 4;" "rect.top = 10;" "rect.right = 20;" "rect.bottom = 30;" "rect.width = rect.height + 20;" "rect.draw();" , &val); SkASSERT(success); success = js.ValueToString(val, &string); SkASSERT(success); }
void bltzl() { // if (_rs.0-63 < 0) delayslot = instaddr + 4 + _offset * 4 enum { _jump, _end }; // 符号ビットが1ならジャンプ mov32_eax_mem(_GPR_D(_rs, 1)); tst32_reg_reg(_eax, _eax); js(_jump); // 分岐しない場合、次の遅延スロットの命令を実行しない mov8_mem_imm8((u32)&g_cpu->m_null_current_inst, 1); jmp(_end); LABEL_DEF(_jump); mov32_reg_imm32(_eax, (g_cpu->m_recompiling_ee_va + 4) + _offset * 4); mov32_mem_eax((u32)&g_cpu->m_ee_jump_addr); #if defined _DEBUGGER mov32_reg_imm32(_eax, (u32)Debugger::jumpLogPush); call_reg(_eax); #endif LABEL_DEF(_end); }
/////////////////////////////////////////////////////////////////////////////// // the routine spawning the SAGA jobs and waiting for their results void run_a_job(std::string host, std::string argument) { try { saga::job::service js (host); saga::job::ostream in; saga::job::istream out; saga::job::istream err; // run the job saga::job::job j = js.run_job("/bin/echo " + argument, host, in, out, err); // wait for the job to finish saga::job::state s = j.get_state(); while (s != saga::job::Done && s != saga::job::Failed) s = j.get_state(); // if the job finished successfully, print the generated output if (s == saga::job::Done) { std::string line; while (!std::getline(out, line).eof()) std::cout << line << '\n'; } else { std::cerr << "SAGA job: " << j.get_job_id() << " failed (state: " << saga::job::detail::get_state_name(s) << ")\n"; } } catch (saga::exception const& e) { std::cerr << "saga::exception caught: " << e.what () << std::endl; } catch (std::exception const& e) { std::cerr << "std::exception caught: " << e.what () << std::endl; } catch (...) { std::cerr << "unexpected exception caught" << std::endl; } }
int main () { try { saga::job::service js ("fork://localhost"); saga::job::description jd; jd.set_attribute (saga::job::attributes::description_executable, "/usr/bin/true"); jd.set_attribute (saga::job::attributes::description_interactive, saga::attributes::common_false); struct timeval start, end; ::gettimeofday (&start, NULL); for ( int i = 0; i < 1000; i++ ) { saga::job::job j = js.create_job (jd); j.run (); j.wait (); // ::system ("/usr/bin/true"); std::cout << i << " " << std::flush; } ::gettimeofday (&end, NULL); std::cout << "\n time: " << end.tv_sec - start.tv_sec << std::endl; } catch ( const saga::exception & e ) { std::cout << " exception: " << e.what () << std::endl; return -1; } return 0; }
static jserr_t js_parse_collection(jsparser_t *p, size_t t) { size_t err, key, val, prev = 0; char start, end; js_ensure_buf(p, 1); if ((start = js(p)[0]) == '[' || start == '{') { end = (start == '[') ? ']' : '}'; js_tok(p, t)->type = (start == '[') ? JS_ARRAY : JS_OBJECT; } else { return JS_EPARSE; } p->pos++; while (1) { js_skip_ws(p); if (js(p)[0] == end) { p->pos++; break; } else { if (prev) { if (js(p)[0] != ',') return JS_EPARSE; p->pos++; js_skip_ws(p); } key = js_next_tok(p); val = js_next_tok(p); if (prev) js_tok(p, prev)->next_sibling = key; else js_tok(p, t)->first_child = key; js_tok(p, key)->parent = t; js_tok(p, key)->first_child = val; js_tok(p, val)->parent = key; switch (js_tok(p, t)->type) { case JS_ARRAY: js_tok(p, key)->type = JS_ITEM; js_tok(p, key)->idx = prev ? js_tok(p, prev)->idx + 1 : 0; break; case JS_OBJECT: if ((err = js_parse_string(p, key))) return err; js_tok(p, key)->type = JS_PAIR; js_skip_ws(p); if (js(p)[0] != ':') return JS_EPARSE; p->pos++; break; default: return JS_EBUG; } prev = key; if ((err = js_parse(p, val))) return err; } } return 0; }
int main (int argc, char** argv) { int err = 0; try { ///////////////////////////////////////////////////////////////////////// // for get_job_description, we try to get the job description for self, and // check if ARGV and execution host are set correctly. The we create a jd, // run a job with it, and compare with the jd delivered by the job. ///////////////////////////////////////////////////////////////////////// namespace sja = saga::job::attributes; namespace sa = saga::attributes; ///////////////////////////////////////////////////////////////////////// // get self, and my own jd { saga::session s; saga::job::service js (s); saga::job::self self = js.get_self (); saga::job::description jd = self.get_description (); if ( ! jd.attribute_exists (sja::description_executable) ) { std::cerr << "Expected Executable in job description" << std::endl; err++; } else { if ( jd.get_attribute ("Executable") != argv[0] ) { std::cerr << "Expected " << argv[0] << " as Executable in job description" << std::endl; err++; } } // can we compare args? if ( argc > 0 ) { if ( ! jd.attribute_exists (sja::description_arguments) ) { std::cerr << "Expected Arguments in job description" << std::endl; err++; } else { std::vector <std::string> jd_args = jd.get_vector_attribute (sja::description_arguments); if ( jd_args.size () != (unsigned int) argc - 1) { std::cerr << "Expected " << argc - 1 << " args, not " << jd_args.size () << std::endl; err++; } for ( unsigned int i = 0; i < jd_args.size (); i++ ) { if ( jd_args[i] != argv[i + 1] ) { std::cerr << "Expected " << argv[i+1] << " as " << i+1 << "'th args, not " << jd_args[i] << std::endl; err++; } } } } // argc > 0 // check candidate host, which should be localhost if ( ! jd.attribute_exists (sja::description_candidate_hosts) ) { std::cerr << "Expected CandidateHosts in job description" << std::endl; err++; } else { std::vector <std::string> jd_hosts = jd.get_vector_attribute (sja::description_candidate_hosts); if ( jd_hosts.size () != 1 ) { std::cerr << "Expected 1 candidate host, not " << jd_hosts.size () << std::endl; err++; } if ( ! saga::adaptors::utils::is_local_address (jd_hosts[0]) ) { std::cerr << "Expected 'localhost' (or a valid alias) as candidate host, not " << jd_hosts[0] << std::endl; err++; } } // candidate_hosts } // test for self ///////////////////////////////////////////////////////////////////////// // create a jd, create a job with it, and check the returned new jd { saga::session s; saga::job::service js (s); saga::job::description old_jd; old_jd.set_attribute (sja::description_executable, "/bin/sleep"); old_jd.set_attribute (sja::description_interactive, sa::common_false); std::vector <std::string> args; args.push_back ("10"); old_jd.set_vector_attribute (sja::description_arguments, args); std::vector <std::string> hosts; hosts.push_back ("localhost"); old_jd.set_vector_attribute (sja::description_candidate_hosts, hosts); saga::job::job j = js.create_job (old_jd); j.run (); saga::job::description new_jd = j.get_description (); if ( ! new_jd.attribute_exists (sja::description_executable) ) { std::cerr << "Expected Executable in job description" << std::endl; err++; } else { if ( new_jd.get_attribute ("Executable") != "/bin/sleep" ) { std::cerr << "Expected /bin/sleep as Executable in job description, not " << new_jd.get_attribute ("Executable") << std::endl; err++; } } // can we compare args? if ( ! new_jd.attribute_exists (sja::description_arguments) ) { std::cerr << "Expected Arguments in job description" << std::endl; err++; } else { std::vector <std::string> jd_args = new_jd.get_vector_attribute (sja::description_arguments); if ( jd_args.size () != 1 ) { std::cerr << "Expected 1 argument, not " << jd_args.size () << std::endl; err++; } if ( jd_args[0] != "10" ) { std::cerr << "Expected '10' as argument, not " << jd_args[0] << std::endl; err++; } } // argc > 0 // check candidate host, which should be localhost if ( ! new_jd.attribute_exists (sja::description_candidate_hosts) ) { std::cerr << "Expected CandidateHosts in job description" << std::endl; err++; } else { std::vector <std::string> jd_hosts = new_jd.get_vector_attribute (sja::description_candidate_hosts); if ( jd_hosts.size () != 1 ) { std::cerr << "Expected 1 candidate host, not " << jd_hosts.size () << std::endl; err++; } bool match = false; struct hostent * he = ::gethostbyname ("localhost"); char** aliases = he->h_aliases; while ( *aliases != NULL ) { if ( jd_hosts[0] == *aliases ) { match = true; } aliases++; } if ( ! match && jd_hosts[0] != "localhost" ) { std::cerr << "Expected 'localhost' (or a valid alias) as candidate host, not " << jd_hosts[0] << std::endl; err++; } } } } catch ( const saga::exception & e ) { std::cerr << "Exception: " << e.what () << std::endl; err++; } return err; }
int main () { saga::job::service js ("fork://localhost/"); saga::job::description jd; std::vector <std::string> env; env.push_back ("SAGA_VERBOSE=10"); jd.set_attribute (saga::job::attributes::description_executable, "/bin/env"); jd.set_attribute (saga::job::attributes::description_interactive, saga::attributes::common_true); jd.set_vector_attribute (saga::job::attributes::description_environment, env); saga::job::job j = js.create_job(jd); saga::job::ostream in = j.get_stdin (); saga::job::istream out = j.get_stdout (); saga::job::istream err = j.get_stderr (); j.run (); while ( out.good () ) { char c; out.read (&c, 1); if ( out.fail () ) break; std::cout << c; } j.wait(); std::cout << "state: " << j.get_state () << "\n"; switch ( j.get_state () ) { case saga::job::Done : std::cout << "done\n"; break; case saga::job::Running : std::cout << "Running\n"; break; case saga::job::Failed : std::cout << "Failed\n"; break; case saga::job::Canceled : std::cout << "Canceled\n"; break; case saga::job::Suspended : std::cout << "Suspended\n"; break; case saga::job::New : std::cout << "New\n"; break; case saga::job::Unknown : std::cout << "Unknown\n"; break; default : std::cout << "???\n"; break; } return 0; }
//std::string jstring2string(JNIEnv * env, jstring jstr){ // const char * tmp = env->GetStringUTFChars(jstr, false); // string js(tmp); // env->ReleaseStringUTFChars(jstr, tmp); // return js; //} std::wstring jstring2wstring(JNIEnv * env, jstring jstr){ const char * tmp = env->GetStringUTFChars(jstr, false); string js(tmp); env->ReleaseStringUTFChars(jstr, tmp); return jw::s2w(js); }
bool MainWindowImpl::loadFile( QFileInfo const & fi ) { if( ! fi.isFile() ) return false; // FIXME: this dispatch needs to be generalized. QString fn( fi.filePath() ); // fi.absoluteFilePath() ); bool worked = false; if( impl->gstate.board().fileNameMatches(fn) ) { worked = impl->gstate.board().s11nLoad(fn); } else if( impl->gstate.fileNameMatches(fn) ) { worked = this->loadGame(fn); } else if( fn.endsWith(".wiki") ) { worked = true; QString lbl = QString("Wiki: %1").arg(fi.fileName()); QDockWidget * win = new QDockWidget( lbl, this ); qboard::WikiLiteView * v = new qboard::WikiLiteView; win->setAttribute(Qt::WA_DeleteOnClose); win->setWidget( v ); win->move( impl->gv->viewport()->mapToGlobal(QPoint(0,0)) ); win->resize( impl->gv->viewport()->size() ); win->setFloating(true); this->addDockWidget(Qt::RightDockWidgetArea, win ); v->parseFile(fn); win->setWindowTitle( v->windowTitle() ); } else if( QRegExp("\\.[jq]s$",Qt::CaseInsensitive).indexIn(fn) > 0 ) { QScriptEngine & js( impl->gstate.jsEngine() ); qDebug() << "[ running script"<<fn<<"]"; QScriptValue rv = qboard::jsInclude( &js, fn ); if( rv.isError() ) { QStringList bt( js.uncaughtExceptionBacktrace() ); QScriptValue exv = rv.isError() ? rv : js.uncaughtException(); QString msg("Script threw or returned an exception:\n"); msg += exv.toString() + "\nBacktrace:\n" + bt.join("\n"); QMessageBox::warning( this, "JavaScript Exception", msg, QMessageBox::Ok, QMessageBox::Ok ); worked = false; } else { worked = true; } qDebug() << "[ done running script"<<fn<<"]"; } else if( QRegExp("\\.(html|txt)$",Qt::CaseInsensitive).indexIn(fn) > 0 ) { #if QT_VERSION >= 0x040400 QBoardDocsBrowser * b = new QBoardDocsBrowser; b->setHome(fn); b->setWindowTitle(fn); b->show(); worked = true; #else QMessageBox::warning( this, "Not implemented!", "MainWindowImpl::loadFile(*.{txt,html}) not implemented for Qt < 4.4", QMessageBox::Ok, QMessageBox::Ok ); worked = false; #endif } else if( QRegExp("\\.(png|jpg|gif|xpm|svg|bmp)$",Qt::CaseInsensitive).indexIn(fn) > 0 ) { // ^^^ FIXME: get the list of image formats from somewhere dynamic const size_t threshold = 10 * 1024; // ^^^ fixme: ^^^^ do this based on image resolution, not file size, cuz many // large-sized PNGs are quite small. if( fi.size() < threshold ) { worked = this->loadPiece(fi); } else { worked = this->impl->gstate.board().s11nLoad(fn); // fi.absoluteFilePath()); } } if( worked ) { this->statusBar()->showMessage("Loaded: "+fn); // fi.absoluteFilePath()); } else { this->statusBar()->showMessage("Load FAILED: "+fn); // fi.absoluteFilePath()); } return worked; }
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f), Ui::MainWindow(), impl(new Impl) { setupUi(this); this->setWindowTitle( QString("QBoard v. %1").arg(qboard::versionString()) ); connect( this->actionSave, SIGNAL(triggered(bool)), this, SLOT(saveGame()) ); connect( this->actionLoad, SIGNAL(triggered(bool)), this, SLOT(loadGame()) ); connect( this->actionNewBoardView, SIGNAL(triggered(bool)), this, SLOT(launchNewBoardView()) ); connect( this->actionAboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()) ); connect( this->actionAboutQBoard, SIGNAL(triggered(bool)), this, SLOT(aboutQBoard()) ); connect( this->actionPrint, SIGNAL(triggered(bool)), this, SLOT(printGame()) ); connect( this->actionHelp, SIGNAL(triggered(bool)), this, SLOT(launchHelp()) ); connect( this->actionClearBoard, SIGNAL(triggered(bool)), this, SLOT(clearBoard()) ); connect( this->actionQuickSave, SIGNAL(triggered(bool)), this, SLOT(quickSave()) ); connect( this->actionQuickLoad, SIGNAL(triggered(bool)), this, SLOT(quickLoad()) ); impl->gstate.enablePlacemarker(true); #if ! QBOARD_VERSION // For "end user builds" we won't show this action. connect( this->actionExperiment, SIGNAL(triggered(bool)), this, SLOT(doSomethingExperimental()) ); this->actionExperiment->setEnabled(true); #else this->actionExperiment->setEnabled(false); #endif connect( &S11nClipboard::instance(), SIGNAL(signalUpdated()), this, SLOT(clipboardUpdated()) ); this->actionClearClipboard->setEnabled( 0 != S11nClipboard::instance().contents() ); connect( this->actionClearClipboard, SIGNAL(triggered(bool)), this, SLOT( clearClipboard() ) ); QWidget * cli = this->clientArea; QLayout * lay = new QGridLayout( cli ); lay->setSpacing(0); lay->setContentsMargins(2,2,2,2); QSplitter * splitter = new QSplitter( Qt::Horizontal, cli ); lay->addWidget( splitter ); splitter->setHandleWidth(4); QSplitter * vsplit = new QSplitter( Qt::Vertical, cli ); impl->sidebar = vsplit; splitter->addWidget( vsplit ); vsplit->setHandleWidth(4); impl->tree = new QBoardHomeView(); vsplit->addWidget(impl->tree); connect( this->actionRefreshFileList, SIGNAL(triggered(bool)), impl->tree, SLOT(refresh()) ); connect( impl->tree, SIGNAL(itemActivated(QFileInfo const &)), this, SLOT(loadFile(QFileInfo const &)) ); connect( this->actionToggleBrowserView, SIGNAL(toggled(bool)), this, SLOT(toggleSidebarVisible(bool)) ); impl->gv = new QBoardView( impl->gstate ); //impl->gv->enablePlacemarker(true); connect( this->actionToggleBoardDragMode, SIGNAL(toggled(bool)), impl->gv, SLOT(setHandDragMode(bool)) ); this->actionToggleBoardDragMode->setChecked(false); connect( this->actionCopy, SIGNAL(triggered(bool)), impl->gv, SLOT(clipCopySelected()) ); connect( this->actionCut, SIGNAL(triggered(bool)), impl->gv, SLOT(clipCutSelected()) ); connect( this->actionPaste, SIGNAL(triggered(bool)), impl->gv, SLOT(clipPaste()) ); connect( this->actionSelectAll, SIGNAL(triggered(bool)), impl->gv, SLOT(selectAll()) ); connect( this->actionZoomIn, SIGNAL(triggered(bool)), impl->gv, SLOT(zoomIn()) ); connect( this->actionZoomOut, SIGNAL(triggered(bool)), impl->gv, SLOT(zoomOut()) ); connect( this->actionZoomReset, SIGNAL(triggered(bool)), impl->gv, SLOT(zoomReset()) ); #define BOGO(A) // this->action ## A->setParent(impl->gv); BOGO(Copy); BOGO(Cut); BOGO(Paste); BOGO(ZoomIn); BOGO(ZoomOut); BOGO(ZoomReset); #undef BOGO splitter->addWidget( impl->gv ); splitter->setStretchFactor(0,2); splitter->setStretchFactor(1,3); vsplit->addWidget( impl->paw ); vsplit->setStretchFactor(0,3); vsplit->setStretchFactor(1,1); if(1) { impl->gv->setObjectName("view"); QScriptEngine & js( impl->gstate.jsEngine() ); QScriptValue jo = js.newQObject( impl->gv, QScriptEngine::QtOwnership ); QScriptValue qb = js.globalObject().property("qboard"); qb.setProperty("view",jo); qb.setProperty("window",js.newQObject(this, QScriptEngine::QtOwnership ) ); } this->resize(760,600); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList args = a.arguments(); if (args.size() < 4) { out << "Usage: " << args[0] << " <version> <qtdir> <platform> [load]\n" << flush; return 1; } const QString version = args[1]; const QDir qtdir = QDir(args[2]); const QString platform = args[3]; if (args.size() > 5) { if (args[4] == "load") { silent = false; } } if (!QRegularExpression("\\d\\.\\d\\.\\d").match(version).hasMatch()) { out << "<version> has to be in the format #.#.#\n" << flush; return 1; } const QString short_version = version.left(3); GetFiles::version = version; // mappings etc. QList<FileGroup> mappings; mappings.append(FileGroup("bin", &GetFiles::binaryFiles)); mappings.append(FileGroup("doc", &GetFiles::docFiles)); mappings.append(FileGroup("examples", &GetFiles::exampleFiles)); mappings.append(FileGroup("imports", &GetFiles::importsFiles)); mappings.append(FileGroup("include", &GetFiles::includeFolders)); mappings.append(FileGroup("lib", &GetFiles::libFiles)); mappings.append(FileGroup("libexec", &GetFiles::libExecFiles)); mappings.append(FileGroup("mkspecs", &GetFiles::mkSpecFiles)); mappings.append(FileGroup("phrasebooks", &GetFiles::phrasebookFiles)); mappings.append(FileGroup("plugins", &GetFiles::pluginNames)); mappings.append(FileGroup("qml", &GetFiles::qmlFiles)); mappings.append(FileGroup("translations", &GetFiles::translationFiles)); QStringList modules; for (const FileGroup &files : mappings) { modules.append((files.fileGetter)().keys()); } modules.removeDuplicates(); out << "Copying files for the following modules: " << modules.join(", ") << "\n" << flush; QDir baseDir; for (const QString &module : modules) { if (baseDir.exists(module + ".tar.gz")) { out << "Skiping already existing module " << module << "\n" << flush; continue; } out << "Copying files for module " << module << "\n" << flush; baseDir.mkdir(module); QDir dir(baseDir); dir.cd(module); for (const FileGroup &files : mappings) { QStringList fs = (files.fileGetter)()[module]; if (fs.isEmpty()) { continue; } out << " Copying " << files.name << " files...\n" << flush; QDir fromDir(qtdir); fromDir.cd(files.name); QDir toDir(dir); toDir.mkdir(files.name); toDir.cd(files.name); copyFiles(fs, fromDir, toDir); } out << " Creating install file for module " << module << "...\n" << flush; { QFile installFile(dir.absoluteFilePath("install.js")); if (!installFile.open(QFile::WriteOnly | QFile::Truncate)) { out << "Error opening install file: " << installFile.errorString() << "\n"; return -1; } QTextStream js(&installFile); js << "FileSystem.mkpath(Paths.installPath);\n"; for (const FileGroup &groups : mappings) { if (groups.fileGetter().contains(module)) { js << "FileSystem.install(\"" << groups.name << "\", Paths.installPath + \"/" << groups.name << "\");\n"; } } js << "\n"; js.flush(); installFile.close(); } out << " Creating removal file for module " << module << "...\n" << flush; { QFile removalFile(dir.absoluteFilePath("remove.js")); if (!removalFile.open(QFile::WriteOnly | QFile::Truncate)) { out << "Error opening remove file: " << removalFile.errorString() << "\n"; return -1; } QTextStream js(&removalFile); for (const FileGroup &group : mappings) { QStringList files = (group.fileGetter)()[module]; for (const QString &file : files) { js << "FileSystem.remove(Paths.installPath + \"/" << group.name << "/" << file << "\");\n"; } } js << "\n"; js.flush(); removalFile.close(); } out << " Creating archive for module " << module << "...\n" << flush; { KArchive *arch = new KTar(baseDir.absoluteFilePath( QString("%1-%2-%3.tar.gz").arg(module, version, platform))); arch->open(QIODevice::ReadWrite); for (const QString &directory : dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) { arch->addLocalDirectory(dir.absoluteFilePath(directory), directory); } for (const QString &file : dir.entryList(QDir::NoDotAndDotDot | QDir::Files)) { arch->addLocalFile(dir.absoluteFilePath(file), file); } arch->close(); } } out << "Creating metadata file...\n" << flush; { QFile meta(baseDir.absoluteFilePath("meta.json")); meta.open(QFile::WriteOnly | QFile::Truncate); QMap<QString, QString> descs = GetFiles::descriptions(); QMap<QString, QStringList> deps = GetFiles::dependencies(); QMap<QString, QMap<QString, QStringList>> ndeps = GetFiles::nativeDependencies(); QJsonArray root; for (const QString &module : modules) { QStringList dependencies = deps[module]; dependencies.removeAll(""); dependencies.removeDuplicates(); QMap<QString, QStringList> nDependencies = ndeps[module]; QJsonObject m; m.insert("id", module); m.insert("description", descs[module]); m.insert("version", version); m.insert("platform", platform); m.insert("url", QString("http://localhost/soqute/archives/%1-%2-%3.tar.gz") .arg(module, version, platform)); QJsonArray deps; for (const QString &dep : dependencies) { QJsonObject obj; obj.insert("id", dep); obj.insert("version", version); deps.append(obj); } m.insert("dependencies", deps); QJsonObject nativeDependencies; for (const QString &manager : nDependencies.keys()) { QJsonArray packages = QJsonArray::fromStringList(nDependencies[manager]); nativeDependencies.insert(manager, packages); } m.insert("nativeDependencies", nativeDependencies); root.append(m); } meta.write(QJsonDocument(root).toJson()); } out << "Installing files to server...\n" << flush; { QDir serverRoot("/var/www"); if (!serverRoot.exists("soqute")) { serverRoot.mkdir("soqute"); } serverRoot.cd("soqute"); if (!serverRoot.exists("archives")) { serverRoot.mkdir("archives"); } serverRoot.cd("archives"); for (const QString &archive : baseDir.entryList(QStringList() << "*.tar.gz", QDir::Files)) { out << " Installing " << archive << " to server...\n" << flush; if (serverRoot.exists(archive)) { serverRoot.remove(archive); } QFile::copy(baseDir.absoluteFilePath(archive), serverRoot.absoluteFilePath(archive)); } serverRoot.cdUp(); out << " Installing meta.json to server...\n" << flush; if (serverRoot.exists("meta.json")) { QFile server(serverRoot.absoluteFilePath("meta.json")); Q_ASSERT(server.open(QFile::ReadOnly | QFile::Truncate)); QFile local(baseDir.absoluteFilePath("meta.json")); Q_ASSERT(local.open(QFile::ReadOnly)); QJsonDocument serverDoc = QJsonDocument::fromJson(server.readAll()); server.close(); QJsonArray serverArray = serverDoc.array(); QJsonDocument localDoc = QJsonDocument::fromJson(local.readAll()); local.close(); QJsonArray localArray = localDoc.array(); QVariantList res = serverArray.toVariantList(); res.append(localArray.toVariantList()); Q_ASSERT(server.open(QFile::WriteOnly | QFile::Truncate)); server.write(QJsonDocument(QJsonArray::fromVariantList(res)).toJson()); server.close(); } else { QFile::copy(baseDir.absoluteFilePath("meta.json"), serverRoot.absoluteFilePath("meta.json")); } } out << "Done\n" << flush; return 0; }
void JSWriter::writeClass(UMLClassifier *c) { if(!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } QString classname = cleanName(c->getName()); QString fileName = c->getName().lower(); //find an appropriate name for our file fileName = findFileName(c,".js"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile filejs; if(!openFile(filejs, fileName)) { emit codeGenerated(c, false); return; } QTextStream js(&filejs); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".js"); if(!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),filejs.name()); js << str << m_endl; } //write includes UMLPackageList includes; findObjectsRelated(c,includes); for (UMLPackage *conc = includes.first(); conc; conc = includes.next()) { QString headerName = findFileName(conc, ".js"); if ( !headerName.isEmpty() ) { js << "#include \"" << headerName << "\"" << m_endl; } } js << m_endl; //Write class Documentation if there is somthing or if force option if(forceDoc() || !c->getDoc().isEmpty()) { js << m_endl << "/**" << m_endl; js << " * class " << classname << m_endl; js << formatDoc(c->getDoc()," * "); js << " */" << m_endl << m_endl; } //check if class is abstract and / or has abstract methods if(c->getAbstract() && !hasAbstractOps(c)) js << "/******************************* Abstract Class ****************************" << m_endl << " " << classname << " does not have any pure virtual methods, but its author" << m_endl << " defined it as an abstract class, so you should not use it directly." << m_endl << " Inherit from it instead and create only objects from the derived classes" << m_endl << "*****************************************************************************/" << m_endl << m_endl; js << classname << " = function ()" << m_endl; js << "{" << m_endl; js << m_indentation << "this._init ();" << m_endl; js << "}" << m_endl; js << m_endl; UMLClassifierList superclasses = c->getSuperClasses(); for (UMLClassifier *obj = superclasses.first(); obj; obj = superclasses.next()) { js << classname << ".prototype = new " << cleanName(obj->getName()) << " ();" << m_endl; } js << m_endl; if (! c->isInterface()) { UMLAttributeList atl = c->getAttributeList(); js << "/**" << m_endl; QString temp = "_init sets all " + classname + " attributes to their default value." " Make sure to call this method within your class constructor"; js << formatDoc(temp, " * "); js << " */" << m_endl; js << classname << ".prototype._init = function ()" << m_endl; js << "{" << m_endl; for(UMLAttribute *at = atl.first(); at ; at = atl.next()) { if (forceDoc() || !at->getDoc().isEmpty()) { js << m_indentation << "/**" << m_endl << formatDoc(at->getDoc(), m_indentation + " * ") << m_indentation << " */" << m_endl; } if(!at->getInitialValue().isEmpty()) { js << m_indentation << "this.m_" << cleanName(at->getName()) << " = " << at->getInitialValue() << ";" << m_endl; } else { js << m_indentation << "this.m_" << cleanName(at->getName()) << " = \"\";" << m_endl; } } } //associations UMLAssociationList aggregations = c->getAggregations(); if (forceSections() || !aggregations.isEmpty ()) { js << m_endl << m_indentation << "/**Aggregations: */" << m_endl; writeAssociation(classname, aggregations , js ); } UMLAssociationList compositions = c->getCompositions(); if( forceSections() || !compositions.isEmpty()) { js << m_endl << m_indentation << "/**Compositions: */" << m_endl; writeAssociation(classname, compositions , js ); } js << m_endl; js << "}" << m_endl; js << m_endl; //operations UMLOperationList ops(c->getOpList()); writeOperations(classname, &ops, js); js << m_endl; //finish file //close files and notfiy we are done filejs.close(); emit codeGenerated(c, true); }
int run_test (std::string name) { int err = 0; try { saga::session s; saga::job::service js (s, "drmaa://localhost"); saga::job::description jd; jd.set_attribute (sja::description_executable, "/bin/sleep"); std::vector<std::string> args; args.push_back("10"); jd.set_vector_attribute (sja::description_arguments, args); jd.set_attribute (sja::description_output, "output"); // not supported, yet //std::vector <std::string> transfers; //transfers.push_back ("file://localhost/tmp/output < output"); //jd.set_vector_attribute (sja::description_file_transfer, transfers); saga::job::job j = js.create_job (jd); j.run (); std::cout << name << ": Submitted" << std::endl; // j.wait (-1.0); saga::job::state state = j.get_state (); while ( state == saga::job::New ) { std::cout << name << ": New" << std::endl; ::sleep (1); state = j.get_state (); } while ( state == saga::job::Running ) { std::cout << name << ": Running" << std::endl; ::sleep (1); state = j.get_state (); } if ( state == saga::job::Done ) { std::cout << name << ": Done" << std::endl; } else { std::cout << name << ": Failed?" << std::endl; err++; } } catch ( const saga::exception & e ) { std::cout << name << ": Exception: " << e.what () << std::endl; err++; } catch ( const char * m ) { std::cout << name << ": exception: " << m << std::endl; err++; } std::cout << " ----- " << err << " ---------------------------------------------------------- " << std::endl; return err; }
int main (int argc, char** argv) { int err = 0; try { ///////////////////////////////////////////////////////////////////////// // the signal test works just like the checkpoint test, only we explicitely // send SIGUSR1. // // So, first spawn test job pid_t child = ::fork (); //////////////////////////////////////////////////////////////////////////// if ( -1 == child ) { std::cerr << "fork failed" << std::endl; return -1; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// else if ( 0 == child ) { // this is the child which is getting signalled. So, install the // signal handler if ( SIG_ERR == ::signal (SIGUSR1, sighandler) ) { std::cerr << "Could not register signal handler" << std::endl; // oops - not much we can do ::exit (-2); } // allow signal to arrive ::sleep (3); // nothing happened? flag error if ( 0 != ::system ("touch test_job_signal_flag_nok") ) { // oops - we can't tell the parent! std::cerr << "Could not touch nok flag" << std::endl; ::exit (-3); } } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// else { // this is the parent who does the SAGA test. So, first reconnect to the // job std::stringstream ss; ss << "[fork://localhost]-[" << child << "]"; saga::session s; saga::job::service js (s, "fork://localhost"); saga::job::job j = js.get_job (ss.str ()); if ( j.get_state () != saga::job::Running ) { std::cerr << "state != Running" << std::endl; err++; } j.signal (SIGUSR1); // allow child to finish int status = 0; if ( -1 == ::waitpid (child, &status, 0) ) { std::cerr << "waitpid failed" << std::endl; ::exit (-4); } if ( j.get_state () != saga::job::Done ) { std::cerr << "state != Done" << std::endl; err++; } if ( 0 == ::system ("test -f test_job_signal_flag_ok") ) { // all is fine - just remove the tag file ::system ("rm test_job_signal_flag_ok"); } else { // oops - lets see if the child said anything if ( 0 == ::system ("test -f test_job_signal_flag_nok") ) { std::cerr << "child did not receive signal" << std::endl; err++; // remove tag file ::system ("rm test_job_signal_flag_nok"); } else { std::cerr << "child disappeared" << std::endl; err++; } } } //////////////////////////////////////////////////////////////////////////// } catch ( const saga::exception & e ) { std::cerr << "Exception: " << e.what () << std::endl; err++; } return err; }
jserr_t js_parse_one(jsparser_t *p, size_t *t) { js_skip_ws(p); return (js(p)[0] == '\0') ? JS_EDONE : js_parse(p, (*t = js_next_tok(p))); }