int addreflexiveaxioms() { // add x = x axiom String varname = uniqueName(String("_V")); Semantic *pvar1 = new Semantic(Term::Variable, varname); MustBeTrue(pvar1 != NULL); Semantic *pvar2 = new Semantic(Term::Variable, varname); MustBeTrue(pvar2 != NULL); List<Semantic * > *pargs = new List<Semantic * >; MustBeTrue(pargs != NULL); MustBeTrue(pargs->insertAtEnd(pvar1) == OK); MustBeTrue(pargs->insertAtEnd(pvar2) == OK); Semantic *peq = new Semantic(Predicate::Equal, String("="), pargs, 2); MustBeTrue(peq != NULL); Semantic *pu = new Semantic(Expression::Universal, varname, peq); MustBeTrue(pu != NULL); MustBeTrue(ptrees.insertAtFront(pu) == OK); // add reflexive axioms for each function BinaryTree_AVL_Iterator_InOrder<Symbol> symbolsIter(symbols); for ( ; !symbolsIter.done(); symbolsIter++) { // check if symbol is a function Symbol symbol = symbolsIter(); if (symbol.getType() != Symbol::Function) continue; // we have a function, get number of arguments int argnum = symbol.getArgs(); String fname = symbol.getName(); // generate list of variable names Array<String> argnames(argnum); for (int arg = 0; arg < argnum; arg++) { argnames[arg] = uniqueName(String("_V")); } // build record recursively int iarg = 0; Semantic *psem = NULL; if (addreflexiveaxioms( iarg, argnum, fname, argnames, psem) != OK) { ERROR("failed to build semantic record.", errno); return(NOTOK); } // add to set of axioms MustBeTrue(ptrees.insertAtFront(psem) == OK); } // all done return(OK); }
bool EnttecDMXUSBOpen::open() { if (isOpen() == false) { if (ftdi_usb_open_desc(&m_context, EnttecDMXUSBWidget::VID, EnttecDMXUSBWidget::PID, name().toAscii(), serial().toAscii()) < 0) { qWarning() << "Unable to open" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return false; } if (ftdi_usb_reset(&m_context) < 0) { qWarning() << "Unable to reset" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return close(); } if (ftdi_set_line_property(&m_context, BITS_8, STOP_BIT_2, NONE) < 0) { qWarning() << "Unable to set 8N2 serial properties to" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return close(); } if (ftdi_set_baudrate(&m_context, 250000) < 0) { qWarning() << "Unable to set 250kbps baudrate for" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return close(); } if (ftdi_setrts(&m_context, 0) < 0) { qWarning() << "Unable to set RTS line to 0 for" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return close(); } if (isRunning() == false) start(); return true; } else { /* Already open */ return true; } }
int addeqsymmetryaxiom() { // get variable names String x = uniqueName(String("_V")); String y = uniqueName(String("_V")); // create x!=y record Semantic *px = new Semantic(Term::Variable, x); MustBeTrue(px != NULL); Semantic *py = new Semantic(Term::Variable, y); MustBeTrue(py != NULL); List<Semantic * > *pargs = new List<Semantic * >; MustBeTrue(pargs != NULL); MustBeTrue(pargs->insertAtEnd(px) == OK); MustBeTrue(pargs->insertAtEnd(py) == OK); Semantic *peq = new Semantic(Predicate::Equal, String("="), pargs, 2); MustBeTrue(peq != NULL); Semantic *pxney = new Semantic(Expression::Negation, NULL, peq); MustBeTrue(pxney != NULL); // create y==x record py = new Semantic(Term::Variable, y); MustBeTrue(py != NULL); px = new Semantic(Term::Variable, x); MustBeTrue(px != NULL); pargs = new List<Semantic * >; MustBeTrue(pargs != NULL); MustBeTrue(pargs->insertAtEnd(py) == OK); MustBeTrue(pargs->insertAtEnd(px) == OK); Semantic *pyeqx = new Semantic(Predicate::Equal, String("="), pargs, 2); MustBeTrue(pyeqx != NULL); // create x!=y || y==x record Semantic *por = new Semantic(Expression::Or, pxney, pyeqx); MustBeTrue(por != NULL); // create a universal record Semantic *pu = new Semantic(Expression::Universal, y, por); MustBeTrue(pu != NULL); Semantic *pu2 = new Semantic(Expression::Universal, x, pu); MustBeTrue(pu2 != NULL); // save record, place a front of program. MustBeTrue(ptrees.insertAtFront(pu2) == OK); // all done return(OK); }
// axiomatize equality int addeqreflexiveaxiom() { // get variable name String x = uniqueName(String("_V")); // get two variable records Semantic *pvar1 = new Semantic(Term::Variable, x); MustBeTrue(pvar1 != NULL); Semantic *pvar2 = new Semantic(Term::Variable, x); MustBeTrue(pvar2 != NULL); // create a equal record List<Semantic * > *pargs = new List<Semantic * >; MustBeTrue(pargs != NULL); MustBeTrue(pargs->insertAtEnd(pvar1) == OK); MustBeTrue(pargs->insertAtEnd(pvar2) == OK); Semantic *peq = new Semantic(Predicate::Equal, String("="), pargs, 2); MustBeTrue(peq != NULL); // create a universal record Semantic *pu = new Semantic(Expression::Universal, x, peq); MustBeTrue(pu != NULL); // save record, place at front of program. MustBeTrue(ptrees.insertAtFront(pu) == OK); // all done return(OK); }
bool BaseChannel::registerObject(DBusError *error) { if (isRegistered()) { return true; } QString name = uniqueName(); QString busName = mPriv->connection->busName(); //QString busName = QString(QLatin1String("%1.%2")) // .arg(mPriv->connection->busName(),name); QString objectPath = QString(QLatin1String("%1/%2")) .arg(mPriv->connection->objectPath(), name); debug() << "Registering channel: busName: " << busName << " objectName: " << objectPath; DBusError _error; debug() << "Channel: registering interfaces at " << dbusObject(); foreach(const AbstractChannelInterfacePtr & iface, mPriv->interfaces) { if (!iface->registerInterface(dbusObject())) { // lets not fail if an optional interface fails registering, lets warn only warning() << "Unable to register interface" << iface->interfaceName(); } } bool ret = registerObject(busName, objectPath, &_error); if (!ret && error) { error->set(_error.name(), _error.message()); } return ret; }
Contents(const Type &t, int dims) : t(t), name(uniqueName('m')) { sizes.resize(dims); for (int i = 0; i < dims; i++) { sizes[i] = Var(std::string(".") + name + ".dim." + int_to_str(i)); // Connelly: std::ostringstream broken in Python binding, use string + instead } }
NamedItemPtr NameManager::registerName(const std::string & name, std::tr1::shared_ptr<Object> object) { std::string tempName = uniqueName(name); // Since the name is free, register it NamedItemPtr tempNamedItem = NamedItemPtr(new NamedObject(tempName, object)); names_.insert(std::pair<std::string,NamedItemPtr>(tempName, tempNamedItem)); return tempNamedItem; }
NamedItemPtr NameManager::registerName(const std::string & name) { std::string tempName = uniqueName(name); // Since the name is free, register it NamedItemPtr tempNamedItem = NamedItemPtr(new NamedItem(tempName)); names_.insert(std::pair<std::string,NamedItemPtr>(tempName, tempNamedItem)); return tempNamedItem; }
void EnttecDMXUSBOpen::run() { ftdi_usb_purge_buffers(&m_context); m_running = true; while (m_running == true) { if (isOpen() == false) continue; if (ftdi_set_line_property2(&m_context, BITS_8, STOP_BIT_2, NONE, BREAK_ON) < 0) { qWarning() << "Unable to toggle BREAK_ON for" << uniqueName() << ":" << ftdi_get_error_string(&m_context); goto framesleep; } sleep(88); if (ftdi_set_line_property2(&m_context, BITS_8, STOP_BIT_2, NONE, BREAK_OFF) < 0) { qWarning() << "Unable to toggle BREAK_OFF for" << uniqueName() << ":" << ftdi_get_error_string(&m_context); goto framesleep; } sleep(8); m_mutex.lock(); if (ftdi_write_data(&m_context, (unsigned char*) m_universe.data(), m_universe.size()) < 0) { qWarning() << "Unable to write DMX data to" << uniqueName() << ":" << ftdi_get_error_string(&m_context); } m_mutex.unlock(); framesleep: sleep(22754); } }
void GameObjectManager::renameObject(GameObject* object, const QString& newName) { if (!object) return; QString name = newName; name = uniqueName(object, name); object->setName(name); }
/** Adds the server * * This method uses the dialog's informations with CurlServerAdd to * submit an administration form to add the server. It is called by * the onOkClicked callback is the controls found no error. * */ void RainbruRPG::Gui::AddServer::addServer(){ std::string name(tfServerName->getText().text()); std::string uniqueName(tfServerUniqueName->getText().text()); std::string type=StringConv::getSingleton() .itos(cbServerType->getCurrentItem()+1); std::string ip (tfServerIp->getText().text()); std::string port(tfServerPort->getText().text()); std::string ftp (tfServerFtp->getText().text()); std::string cli (tfServerCli->getText().text()); std::string desc(txtDesc->getText().text()); std::string tech(txtTech->getText().text()); LOGI("Setting posted data :"); LOGCATS("Server name : '"); LOGCATS(name.c_str()); LOGCATS("'"); LOGCAT(); LOGCATS("Server IP : '"); LOGCATS(ip.c_str()); LOGCATS("'"); LOGCAT(); LOGCATS("Server port : '"); LOGCATS(port.c_str()); LOGCATS("'"); LOGCAT(); LOGCATS("Server maxClients : '"); LOGCATS(cli.c_str()); LOGCATS("'"); LOGCAT(); CurlServerAdd csa; csa.setName(name); csa.setUniqueName(uniqueName); csa.setType(type); csa.setIpAddress(ip); csa.setPort(port); csa.setFtpPort(ftp); csa.setMaxClients(cli); csa.setDescription( desc); csa.setTechNote( tech); // csa.setPostedData("technote", tech); bool per=csa.perform(); if (per){ LOGI("The form was correctly posted"); } else{ HttpResponse hr; long resp=csa.getServerResponse(); const char* mes=hr.getMessage(resp); LOGCATS("HTTP rsponse :"); LOGCATS(mes); } }
QString Document::addShape(const Shape &shape) { QString name = Shape::typeToString(shape.type()); name = uniqueName(name); m_shapeList.append(shape); m_shapeList[m_shapeList.count() - 1].m_name = name; setCurrentShape(m_shapeList.count() - 1); return name; }
DynImage::Contents::Contents(const Type &t, std::vector<int> sizes) : type(t), size(sizes), stride(sizes.size()), name(uniqueName('i')), copyToHost(NULL), freeBuffer(NULL) { size_t total = 1; for (size_t i = 0; i < sizes.size(); i++) { assert(sizes[i] > 0 && "Images must have positive sizes"); stride[i] = total; total *= sizes[i]; } allocate(total * (t.bits/8)); }
void addTypeDeclaration ( struct symbolTableRecord* syms, char* name, struct typeRecord* typ ) { struct symbolRecord* s = newSymbolRecord(name, typeSymbol); uniqueName(syms, name); s->u.t.typ = typ; addNewSymbol(syms, s); }
void QgsAttributeActionDialog::insert() { // Add the action details as a new row in the table. int pos = mAttributeActionTable->rowCount(); QgsAttributeActionPropertiesDialog dlg( mLayer, this ); dlg.setWindowTitle( tr( "Add new action" ) ); if ( dlg.exec() ) { QString name = uniqueName( dlg.description() ); insertRow( pos, dlg.type(), name, dlg.actionText(), dlg.iconPath(), dlg.capture() ); } }
struct symbolRecord* addVariable ( struct symbolTableRecord* syms, char* name, struct typeRecord* typ ) { struct symbolRecord* s = newSymbolRecord(name, varSymbol); uniqueName(syms, name); s->u.v.typ = typ; s->u.v.location = syms->size++; addNewSymbol(syms, s); return s; }
int addfunctionaxioms() { // add axioms for every function BinaryTree_AVL_Iterator_InOrder<Symbol> symbolsIter(symbols); for ( ; !symbolsIter.done(); symbolsIter++) { // check if symbol is a function Symbol symbol = symbolsIter(); if (symbol.getType() != Symbol::Function) continue; // we have a function, get number of arguments int argnum = symbol.getArgs(); String pname = symbol.getName(); // generate list of variable names Array<String> argnames(argnum+1); for (int arg = 0; arg <= argnum; arg++) { argnames[arg] = uniqueName(String("_V")); } // build record recursively for (int j = 1; j <= argnum; j++) { // build records int iarg = 0; Semantic *psem = NULL; if (addfunctionaxioms( j, iarg, argnum, pname, argnames, psem) != OK) { ERROR("failed to build semantic record.", errno); return(NOTOK); } // add to set of axioms MustBeTrue(ptrees.insertAtFront(psem) == OK); } } // all done return(OK); }
void QgsAttributeActionDialog::insert( int pos ) { // Check to see if the action name and the action have been specified // before proceeding if ( actionName->text().isEmpty() || actionAction->toPlainText().isEmpty() ) { QMessageBox::warning( this, tr( "Missing Information" ), tr( "To create an attribute action, you must provide both a name and the action to perform." ) ); } else { // Get the action details and insert into the table at the given // position. Name needs to be unique, so make it so if required. // If the new action name is the same as the action name in the // given pos, don't make the new name unique (because we're // replacing it). int numRows = attributeActionTable->rowCount(); QString name; if ( pos < numRows && actionName->text() == attributeActionTable->item( pos, 0 )->text() ) name = actionName->text(); else name = uniqueName( actionName->text() ); if ( pos >= numRows ) { // Expand the table to have a row with index pos insertRow( pos, ( QgsAction::ActionType ) actionType->currentIndex(), name, actionAction->toPlainText(), actionIcon->text(), captureCB->isChecked() ); } else { // Update existing row attributeActionTable->item( pos, 0 )->setText( actionType->currentText() ); attributeActionTable->item( pos, 1 )->setText( name ); attributeActionTable->item( pos, 2 )->setText( actionAction->toPlainText() ); attributeActionTable->item( pos, 3 )->setCheckState( captureCB->isChecked() ? Qt::Checked : Qt::Unchecked ); attributeActionTable->verticalHeaderItem( pos )->setIcon( QIcon( actionIcon->text() ) ); attributeActionTable->verticalHeaderItem( pos )->setData( Qt::UserRole, actionIcon->text() ); } } }
int Semantic::renameAgain(Semantic::RenameMapType &names) { if (type_ == Variable) { RenameMapTypeIter it = names.find(name_); if (it != names.end()) { name_ = it->second; } else { std::string unique_name = uniqueName("rvar"); names.insert(RenameMapType::value_type(name_, unique_name)); name_ = unique_name; } } if ((left_ != NULL) && (left_->renameAgain(names) != OK)) { return NOTOK; } if ((right_ != NULL) && (right_->renameAgain(names) != OK)) { return NOTOK; } if (arguments_.size() > 0) { ArgListTypeIter it = arguments_.begin(); ArgListTypeIter itend = arguments_.end(); for ( ; it!=itend; ++it) { if ((*it)->renameAgain(names) != OK) { return NOTOK; } } } return OK; }
// generate a ground substitution for a clause int groundSubstitutions(const Clause &clause, Substitutions &subs) { // clear substitutions subs.clear(); // get a string representation String clstring = (String)clause; // list of variables Map<String, String> variables; // find variables in clause StringTokens clst(clstring, " \t"); for ( ; !clst.done(); clst++) { if ((clst()(0,2) == String("_V")) || (clst()(0,3) == String("_RV"))) { String variable(clst()); if (!variables.isInMap(variable)) { variables[variable] = uniqueName("_CONST"); } } } // generate substitutions now MapIterator<String, String> varsIter(variables); for ( ; !varsIter.done(); varsIter++) { Substitution sub(Terms(varsIter.data()), varsIter.key()); subs = subs*sub; } // all done return(OK); }
void addConstant ( struct symbolTableRecord* syms, char* name, struct expressionRecord* value ) { struct symbolRecord* s = newSymbolRecord(name, constSymbol); if (syms->ttype == classTable) { yyerror("current implementation does not permit constants in classes"); } uniqueName(syms, name); s->u.s.val = value; s->u.s.location = syms->size++; s->u.s.typ = newConstantType(value->resultType); s->u.s.lineNumber = linenumber; addNewSymbol(syms, s); }
bool EnttecDMXUSBOpen::close() { if (isOpen() == true) { /* Stop the writer thread */ if (isRunning() == true) stop(); if (ftdi_usb_close(&m_context) < 0) { qWarning() << "Unable to close" << uniqueName() << ":" << ftdi_get_error_string(&m_context); return false; } else { return true; } } else { return true; } }
int Semantic::skolemize() { // check if expression or predicate // if it's a predicate, there is nothing to do // since we are at the beginning of the expression, // and quantifiers are expressions. // if (!isExpression()) return(OK); // list of variables in scope List<Symbol> localscope; // get expression Expression *pe = (Expression *)prep; // what type is it if (pe->type == Expression::Universal) { // store universal variable localscope.insertAtEnd(Symbol(pe->name, Symbol::UniversalVariable)); // follow right leg, left leg is null MustBeTrue(pe->left == NULL && pe->right != NULL); if (pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } // remove universal variable Symbol tmp; localscope.removeAtEnd(tmp); } else if (pe->type == Expression::Existential) { // store existential variable String uname = uniqueName(String("_SK")); localscope.insertAtEnd(Symbol(pe->name, uname, Symbol::ExistentialVariable)); if (updateVariableNames(pe->name, uname) != OK) { ERROR("update variable names failed.", EINVAL); return(NOTOK); } // follow right leg, left leg is null MustBeTrue(pe->left == NULL && pe->right != NULL); if (pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } // remove existential variable Symbol tmp(pe->name); localscope.removeAtEnd(tmp); } else { // follow down other expression operators if (pe->left != NULL && pe->left->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } if (pe->right != NULL && pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } } // scan one more time to remove existential records return(removeExistentials()); }
// remove existential quantifier by using skolem functions. all skolem // functions must be unique. remember that the skolem function is dependent // on any universal variables that are in scope. // int Semantic::skolemize(List<Symbol> &localscope) { // check if expression or predicate if (isExpression()) { // get expression Expression *pe = (Expression *)prep; // what type is it if (pe->type == Expression::Universal) { // store universal variable localscope.insertAtEnd(Symbol(pe->name, Symbol::UniversalVariable)); // follow right leg, left leg is null MustBeTrue(pe->left == NULL && pe->right != NULL); if (pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } // remove universal variable Symbol tmp; localscope.removeAtEnd(tmp); } else if (pe->type == Expression::Existential) { // store existential variable String uname = uniqueName(String("_SK")); localscope.insertAtEnd(Symbol(pe->name, uname, Symbol::ExistentialVariable)); if (updateVariableNames(pe->name, uname) != OK) { ERROR("update variable names failed.", EINVAL); return(NOTOK); } // follow right leg, left leg is null MustBeTrue(pe->left == NULL && pe->right != NULL); if (pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } // remove existential variable Symbol tmp; localscope.removeAtEnd(tmp); } else { // follow down other expression operators if (pe->left != NULL && pe->left->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } if (pe->right != NULL && pe->right->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } } } else if (isPredicate()) { // get predicate Predicate *pp = (Predicate *)prep; // check for functions if ((pp->type == Predicate::Function) || (pp->type == Predicate::Equal)) { // cycle thru arguments ListIterator<Semantic * > pargsIter(*pp->pargs); for ( ; !pargsIter.done(); pargsIter++) { Semantic *parg = pargsIter(); if (parg != NULL && parg->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } } } } else if (isTerm()) { // check type of argument Term *pa = (Term *)prep; switch (pa->type) { case Term::Variable: { // check if an existential variable Symbol qvarsym(pa->name); if(localscope.retrieve(qvarsym) != OK) break; if (qvarsym.getType() != Symbol::ExistentialVariable) break; // we have an existential variable String skolemName(qvarsym.getUniqueName()); // need to replace this variable with a // skolem function which is dependent on all // universal variables in scope at this time. // List<Semantic * > *pargs = new List<Semantic * >; MustBeTrue(pargs != NULL); ListIterator<Symbol> scopeIter(localscope); int nargs; for (nargs = 0; !scopeIter.done(); scopeIter++) { // get symbol Symbol uvar = scopeIter(); // check if we found the current // symbol. this marks the end of // dependent variables for the // skolem function. all other // existential variables are skipped. // if (uvar.getType() == Symbol::ExistentialVariable) { if (uvar == Symbol(pa->name)) break; else continue; } // we have a universal variable in // scope // Semantic *parg = new Semantic( Term::Variable, uvar.getName()); MustBeTrue(parg != NULL); pargs->insertAtEnd(parg); nargs++; } if (nargs == 0) { // skolem constant pa->type = Term::Constant; pa->name = skolemName; pa->pargs = NULL; pa->argnum = 0; // delete unused argument list delete pargs; } else { // skolem function pa->type = Term::Function; pa->name = skolemName; pa->pargs = pargs; pa->argnum = nargs; } break; } case Term::Function: { // we have a function, scan its arguments ListIterator<Semantic *> pargsIter(*pa->pargs); for ( ; !pargsIter.done(); pargsIter++) { Semantic *parg = pargsIter(); if (parg != NULL && parg->skolemize(localscope) != OK) { ERROR("skolemize failed.", EINVAL); return(NOTOK); } } break; } } } else { MustBeTrue(0); } // all done return(OK); }
// rename all variable names to unique names. int Semantic::renameVariables(List<Symbol> &localscope) { // check of predicate or expression if (isExpression()) { // get expression record Expression *pe = (Expression *)prep; // check if we have quantifier int popscope = 0; if (pe->type == Expression::Universal) { // we have a quantifier, rename variable popscope = 1; String uname = uniqueName(String("_V")); localscope.insertAtFront( Symbol(pe->name, uname, Symbol::UniversalVariable)); // change name in semantic record if (updateVariableNames(pe->name, uname) != OK) { ERROR("update variable names failed.", EINVAL); return(NOTOK); } pe->name = uname; } else if (pe->type == Expression::Existential) { // we have a quantifier, rename variable popscope = 1; String uname = uniqueName(String("_V")); localscope.insertAtFront( Symbol(pe->name, uname, Symbol::ExistentialVariable)); // change name in semantic record if (updateVariableNames(pe->name, uname) != OK) { ERROR("update variable names failed.", EINVAL); return(NOTOK); } pe->name = uname; } // follow left and right branches if (pe->left != NULL && pe->left->renameVariables(localscope) != OK) { ERROR("renameVariables failed.", EINVAL); return(NOTOK); } if (pe->right != NULL && pe->right->renameVariables(localscope) != OK) { ERROR("renameVariables failed.", EINVAL); return(NOTOK); } // pop scope variable if required if (popscope) { Symbol tmp; MustBeTrue(localscope.removeAtFront(tmp) == OK); } } else if (isPredicate()) { // get predicate record Predicate *pp = (Predicate *)prep; // check if a function if ((pp->type == Predicate::Function) || (pp->type == Predicate::Equal)) { // we have a function, scan argument list ListIterator<Semantic *> pargsIter(*pp->pargs); for ( ; !pargsIter.done(); pargsIter++) { Semantic *parg = pargsIter(); if (parg != NULL && parg->renameVariables(localscope) != OK) { ERROR("renameVariables failed.", EINVAL); return(NOTOK); } } } } else if (isTerm()) { // check if a variable, function or anything else Term *pa = (Term *)prep; if (pa->type == Term::Variable) { // find variable in scope Symbol usym(pa->name); if (localscope.retrieve(usym) == OK) { pa->name = usym.getUniqueName(); MustBeTrue(pa->name != String("")); } } else if (pa->type == Term::Function) { // we have a function, scan argument list ListIterator<Semantic *> pargsIter(*pa->pargs); for ( ; !pargsIter.done(); pargsIter++) { Semantic *parg = pargsIter(); if (parg != NULL && parg->renameVariables(localscope) != OK) { ERROR("renameVariables failed.", EINVAL); return(NOTOK); } } } } else { MustBeTrue(0); } // all done return(OK); }
void runTest(const char* path) { /* std::string line; g_shell->out() << "echo Hello world\n" << std::flush; std::getline(g_shell->in(), line); termcolor::set(termcolor::RED); std::cout << line << std::endl; termcolor::reset(); */ std::stringstream cmd; std::string binary; std::string out, err; std::string filename = "/tmp/"; int rv; filename += uniqueName(path); binary = stripext(filename); termcolor::set(termcolor::WHITE, termcolor::BLACK, termcolor::DIM); std::cout << "Uploading " << path << "...\n"; // upload the source code g_sftp->upload(path, filename); try { std::cout << "Compiling...\n"; // compile the code remotely cmd << compiler(path) << ' ' << cflags(path) << filename << " -o " << binary; rv = g_ssh->runCommand(cmd.str(), out, err); if (rv) throw compile_error(err); std::cout << "Running remotely...\n"; // run the program remotely rv = g_ssh->runCommand(binary, out, err); if (rv) throw nonzero_exit_error(true, out); std::cout << "Downloading...\n"; // download the Mach-O executable g_sftp->download(binary, binary); std::cout << "Running locally...\n"; // run the executable via dyld std::stringstream locOut; pstream* loc = pstream::popen(std::string(DYLD_COMMAND) + " " + binary); locOut << loc; rv = loc->wait(); if (rv) throw nonzero_exit_error(false, locOut.str()); if (locOut.str() != out) throw different_output_error(out, locOut.str()); } catch (...) { // clean up locally unlink(binary.c_str()); try { // clean up remotely g_sftp->unlink(binary); g_sftp->unlink(filename); } catch (...) {} throw; } }
// // Contemplate the object-to-be-signed and set up the Signer state accordingly. // void SecCodeSigner::Signer::prepare(SecCSFlags flags) { // get the Info.plist out of the rep for some creative defaulting CFRef<CFDictionaryRef> infoDict; if (CFRef<CFDataRef> infoData = rep->component(cdInfoSlot)) infoDict.take(makeCFDictionaryFrom(infoData)); // work out the canonical identifier identifier = state.mIdentifier; if (identifier.empty()) { identifier = rep->recommendedIdentifier(state); if (identifier.find('.') == string::npos) identifier = state.mIdentifierPrefix + identifier; if (identifier.find('.') == string::npos && state.isAdhoc()) identifier = identifier + "-" + uniqueName(); secdebug("signer", "using default identifier=%s", identifier.c_str()); } else secdebug("signer", "using explicit identifier=%s", identifier.c_str()); // work out the CodeDirectory flags word if (state.mCdFlagsGiven) { cdFlags = state.mCdFlags; secdebug("signer", "using explicit cdFlags=0x%x", cdFlags); } else { cdFlags = 0; if (infoDict) if (CFTypeRef csflags = CFDictionaryGetValue(infoDict, CFSTR("CSFlags"))) { if (CFGetTypeID(csflags) == CFNumberGetTypeID()) { cdFlags = cfNumber<uint32_t>(CFNumberRef(csflags)); secdebug("signer", "using numeric cdFlags=0x%x from Info.plist", cdFlags); } else if (CFGetTypeID(csflags) == CFStringGetTypeID()) { cdFlags = cdTextFlags(cfString(CFStringRef(csflags))); secdebug("signer", "using text cdFlags=0x%x from Info.plist", cdFlags); } else MacOSError::throwMe(errSecCSBadDictionaryFormat); } } if (state.mSigner == SecIdentityRef(kCFNull)) // ad-hoc signing requested... cdFlags |= kSecCodeSignatureAdhoc; // ... so note that // prepare the resource directory, if any string rpath = rep->resourcesRootPath(); if (!rpath.empty()) { // explicitly given resource rules always win CFCopyRef<CFDictionaryRef> resourceRules = state.mResourceRules; // embedded resource rules come next if (!resourceRules && infoDict) if (CFTypeRef spec = CFDictionaryGetValue(infoDict, _kCFBundleResourceSpecificationKey)) { if (CFGetTypeID(spec) == CFStringGetTypeID()) if (CFRef<CFDataRef> data = cfLoadFile(rpath + "/" + cfString(CFStringRef(spec)))) if (CFDictionaryRef dict = makeCFDictionaryFrom(data)) resourceRules.take(dict); if (!resourceRules) // embedded rules present but unacceptable MacOSError::throwMe(errSecCSResourceRulesInvalid); } // finally, ask the DiskRep for its default if (!resourceRules) resourceRules.take(rep->defaultResourceRules(state)); // build the resource directory ResourceBuilder resources(rpath, cfget<CFDictionaryRef>(resourceRules, "rules"), digestAlgorithm()); rep->adjustResources(resources); // DiskRep-specific adjustments CFRef<CFDictionaryRef> rdir = resources.build(); resourceDirectory.take(CFPropertyListCreateXMLData(NULL, rdir)); } // screen and set the signing time CFAbsoluteTime now = CFAbsoluteTimeGetCurrent(); if (state.mSigningTime == CFDateRef(kCFNull)) { signingTime = 0; // no time at all } else if (!state.mSigningTime) { signingTime = now; // default } else { CFAbsoluteTime time = CFDateGetAbsoluteTime(state.mSigningTime); if (time > now) // not allowed to post-date a signature MacOSError::throwMe(errSecCSBadDictionaryFormat); signingTime = time; } pagesize = state.mPageSize ? cfNumber<size_t>(state.mPageSize) : rep->pageSize(state); // Timestamping setup CFRef<SecIdentityRef> mTSAuth; // identity for client-side authentication to the Timestamp server }
DynImage::Contents::Contents(const Type &t, int a) : type(t), size{a}, stride{1}, name(uniqueName('i')), copyToHost(NULL), freeBuffer(NULL) { assert(a > 0 && "Images must have positive sizes\n"); allocate(a * (t.bits/8)); }
static void drawDial ( const QStyleOptionSlider *option, QPainter *painter ) { QPalette pal = option->palette; QColor buttonColor = pal.button().color(); const int width = option->rect.width(); const int height = option->rect.height(); const bool enabled = option->state & QStyle::State_Enabled; qreal r = qMin(width, height) / 2; r -= r/50; const qreal penSize = r/20.0; painter->save(); painter->setRenderHint(QPainter::Antialiasing); // Draw notches if (option->subControls & QStyle::SC_DialTickmarks) { painter->setPen(option->palette.dark().color().darker(120)); painter->drawLines(calcLines(option)); } // Cache dial background QString a = QString::fromLatin1("qdial"); QRect rect = option->rect; QPixmap internalPixmapCache; QImage imageCache; QPainter *p = painter; QString unique = uniqueName((a), option, option->rect.size()); int txType = painter->deviceTransform().type() | painter->worldTransform().type(); bool doPixmapCache = txType <= QTransform::TxTranslate; if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); } else { if (doPixmapCache) { rect.setRect(0, 0, option->rect.width(), option->rect.height()); imageCache = QImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); imageCache.fill(0); p = new QPainter(&imageCache); } //--BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); p->setRenderHint(QPainter::Antialiasing); const qreal d_ = r / 6; const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); buttonColor.setHsv(buttonColor .hue(), qMin(140, buttonColor .saturation()), qMax(180, buttonColor.value())); QColor shadowColor(0, 0, 0, 20); if (enabled) { // Drop shadow qreal shadowSize = qMax(1.0, penSize/2.0); QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, 2*shadowSize, 2*shadowSize); QRadialGradient shadowGradient(shadowRect.center().x(), shadowRect.center().y(), shadowRect.width()/2.0, shadowRect.center().x(), shadowRect.center().y()); shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); shadowGradient.setColorAt(qreal(1.0), Qt::transparent); p->setBrush(shadowGradient); p->setPen(Qt::NoPen); p->translate(shadowSize, shadowSize); p->drawEllipse(shadowRect); p->translate(-shadowSize, -shadowSize); // Main gradient QRadialGradient gradient(br.center().x() - br.width()/3, dy, br.width()*1.3, br.center().x(), br.center().y() - br.height()/2); gradient.setColorAt(0, buttonColor.lighter(110)); gradient.setColorAt(qreal(0.5), buttonColor); gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); gradient.setColorAt(1, buttonColor.darker(115)); p->setBrush(gradient); } else { p->setBrush(Qt::NoBrush); } p->setPen(QPen(buttonColor.darker(280))); p->drawEllipse(br); p->setBrush(Qt::NoBrush); p->setPen(buttonColor.lighter(110)); p->drawEllipse(br.adjusted(1, 1, -1, -1)); if (option->state & QStyle::State_HasFocus) { QColor highlight = pal.highlight().color(); highlight.setHsv(highlight.hue(), qMin(160, highlight.saturation()), qMax(230, highlight.value())); highlight.setAlpha(127); p->setPen(QPen(highlight, 2.0)); p->setBrush(Qt::NoBrush); p->drawEllipse(br.adjusted(-1, -1, 1, 1)); } //--END_STYLE_PIXMAPCACHE if (doPixmapCache) { p->end(); delete p; internalPixmapCache = QPixmap::fromImage(imageCache); painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); QPixmapCache::insert(unique, internalPixmapCache); } } QPointF dp = calcRadialPos(option, qreal(0.70)); buttonColor = buttonColor.lighter(104); buttonColor.setAlphaF(qreal(0.8)); const qreal ds = r/qreal(7.0); QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, dialRect.center().y() + dialRect.width(), dialRect.width()*2, dialRect.center().x(), dialRect.center().y()); dialGradient.setColorAt(1, buttonColor.darker(140)); dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); dialGradient.setColorAt(0, buttonColor.darker(110)); if (penSize > 3.0) { painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); } painter->setBrush(dialGradient); painter->setPen(QColor(255, 255, 255, 150)); painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); painter->setPen(QColor(0, 0, 0, 80)); painter->drawEllipse(dialRect); painter->restore(); }
DynImage::Contents::Contents(const Type &t, int a, int b, int c, int d) : type(t), size{a, b, c, d}, stride{1, a, a*b, a*b*c}, name(uniqueName('i')), copyToHost(NULL), freeBuffer(NULL) { assert(a > 0 && b > 0 && c > 0 && d > 0 && "Images must have positive sizes"); allocate(a * b * c * d * (t.bits/8)); }