QString ScriptAdapterGenerator::parNames( const QString& filterName,MLXMLPluginInfo& xmlInfo ) const { QString names; //the order is important !!! MLXMLPluginInfo::XMLMapList params = xmlInfo.filterParametersExtendedInfo(filterName); int ii; bool optional = false; QString ariet = xmlInfo.filterAttribute(filterName,MLXMLElNames::filterArity); bool isSingle = (ariet == MLXMLElNames::singleMeshArity); QString mid = meshID(); if ((names.isEmpty()) && isSingle && (xmlInfo.filterScriptCode(filterName) == "")) names = mid; else if (isSingle && (xmlInfo.filterScriptCode(filterName) == "")) names = mid + ", " + names; for(ii = 0;ii < params.size();++ii) { bool isImp = (params[ii][MLXMLElNames::paramIsImportant] == "true"); if (names.isEmpty() && isImp) names += /*params[ii][MLXMLElNames::paramType] + "_" +*/ params[ii][MLXMLElNames::paramName]; else if (isImp) names += ", " + /*params[ii][MLXMLElNames::paramType] + "_" + */params[ii][MLXMLElNames::paramName]; else optional = true; } if (optional && !(names.isEmpty())) names += ", " + optName(); if (optional && names.isEmpty()) names += optName(); return names; }
CouchbaseEmbedFunctionContext::CouchbaseEmbedFunctionContext(const IContextLogger &_logctx, const char *options, unsigned _flags) : logctx(_logctx), m_NextRow(), m_nextParam(0), m_numParams(0), m_scriptFlags(_flags) { cbQueryIterator = NULL; m_pCouchbaseClient = nullptr; m_pQuery = nullptr; m_pQcmd = nullptr; const char *server = "localhost"; const char *user = ""; const char *password = ""; const char *bucketname = "default"; unsigned port = 8093; bool useSSL = false; StringBuffer connectionOptions; StringArray inputOptions; inputOptions.appendList(options, ","); ForEachItemIn(idx, inputOptions) { const char *opt = inputOptions.item(idx); const char *val = strchr(opt, '='); if (val) { StringBuffer optName(val-opt, opt); val++; if (stricmp(optName, "server")==0) server = val; // Note that lifetime of val is adequate for this to be safe else if (stricmp(optName, "port")==0) port = atoi(val); else if (stricmp(optName, "user")==0) user = val; else if (stricmp(optName, "password")==0) password = val; else if (stricmp(optName, "bucket")==0) bucketname = val; else if (stricmp(optName, "useSSL")==0) useSSL = clipStrToBool(val); //Connection String options else if (stricmp(optName, "detailed_errcodes")==0 || stricmp(optName, "operation_timeout")==0 || stricmp(optName, "config_total_timeout")==0 || stricmp(optName, "http_poolsize")==0 || stricmp(optName, "detailed_errcodes")==0) connectionOptions.appendf("%s%s=%s", connectionOptions.length() == 0 ? "?" : "&", optName.str(), val); else failx("Unknown option %s", optName.str()); } } m_oCBConnection.setown(new CouchbaseConnection(useSSL, server, port, bucketname, user, password, connectionOptions.str())); m_oCBConnection->connect(); }
static void defineOptSym( // DEFINE SYMBOL FOR THREAD_CTL OPT_DEFN *odef ) // - optimization definition { SYMBOL var; // - new variable var = SymCreateFileScope( TypePtrToVoid() , SC_EXTERN , SF_REFERENCED , optName( odef ) ); odef->sym = var; LinkageSet( var, "C" ); }
static SYMBOL lookupOptSym( // LOOK UP OPTIMIZATION SYMBOL OPT_DEFN *odef ) // - optimization definition { SEARCH_RESULT* result; // - lookup result SYMBOL var; // - name defined in compiled code result = ScopeFindNaked( GetFileScope(), optName( odef ) ); if( result == NULL ) { var = NULL; } else { var = result->sym_name->name_syms; odef->sym = var; ScopeFreeResult( result ); } return var; }
QString ScriptAdapterGenerator::funCodeGenerator( const QString& filterName,MLXMLPluginInfo& xmlInfo ) const { QString code; QString names = parNames(filterName,xmlInfo); code += "function (" + names + ")\n"; code += "{\n"; MLXMLPluginInfo::XMLMapList mplist = xmlInfo.filterParametersExtendedInfo(filterName); if (names.indexOf(optName()) != -1) { QString defValues; for(int ii = 0;ii < mplist.size();++ii) { MLXMLPluginInfo::XMLMap mp = mplist[ii]; if (mp[MLXMLElNames::paramIsImportant] == "false") defValues += mp[MLXMLElNames::paramName] + " : " + mp[MLXMLElNames::paramDefExpr] + ", "; } code += "\t" + optName() + " = __mergeOptions(" + optName() + ",{" + defValues + "});\n"; } code += "\tvar environ = new Env;\n"; QString ariet = xmlInfo.filterAttribute(filterName,MLXMLElNames::filterArity); bool isSingle = (ariet == MLXMLElNames::singleMeshArity); //if is singleMeshAriety i have to jump the first argument because is the meshID int arg = (int) isSingle; for(int ii = 0; ii < mplist.size();++ii) { MLXMLPluginInfo::XMLMap mp = mplist[ii]; bool isenum = false; QString num = QString::number(ii); QString values = mp[MLXMLElNames::paramType]; if (values.contains(MLXMLElNames::enumType)) { QRegExp rem(MLXMLElNames::enumType + " \\{"); values.remove(rem); rem.setPattern("\\}"); values.remove(rem); MLXMLPluginInfo::XMLMap valuesMap = MLXMLPluginInfo::mapFromString(values,QRegExp("\\|"),QRegExp("\\:")); code += "\tfunction enumfun_" + num + "()\n\t{\t\n"; for(MLXMLPluginInfo::XMLMap::iterator it = valuesMap.begin();it != valuesMap.end();++it) { code += "\t\tthis[\"" + it.key() + "\"] = " + it.value() + ";\n"; code += "\t\tthis[parseInt(" + it.value() + ")] = \"" + it.key() + "\";\n"; } code += "\t}\n"; code += "\tfunction get_" + num + "(ff,ii)\n\t{\t\n"; code += "\t\tif (typeof(ii) == \"number\") return ff[ff[ii]];\n"; code += "\t\telse if (typeof(ii) == \"string\") return ff[ii];\n"; code += "\t\t\telse return undefined;\n"; code += "\t}\n"; code += "\tvar enumtype_" + num + " = new enumfun_" + num + "();\n"; isenum = true; } if (mp[MLXMLElNames::paramIsImportant] == "true") { QString argument = "arguments[" + QString::number(arg) + "]"; if (isenum) { code += "\tvar argenum_" + num + " = get_" + num + "(enumtype_" + num + "," + argument + ");\n"; code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\",argenum_" + num + ");\n"; } else //code += "\tprint(" + argument + ");\n"; code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\"," + argument + ");\n"; ++arg; } else { if (isenum) { //code += "\tvar argenum_" + num + " = enumtype_" + num + "[" + argument + "];\n"; code += "\tvar " + mp[MLXMLElNames::paramName] + " = get_" + num + "(enumtype_" + num + "," + optName() + "." + /*mp[MLXMLElNames::paramType] + "_" +*/ mp[MLXMLElNames::paramName] + ");\n"; code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\", " + mp[MLXMLElNames::paramName] + ");\n"; } else { code += "\tvar " + mp[MLXMLElNames::paramName] + " = " + optName() + "." + /*mp[MLXMLElNames::paramType] + "_" +*/ mp[MLXMLElNames::paramName] + ";\n"; code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\", " + mp[MLXMLElNames::paramName] + ");\n"; } } } code += "\tvar environWrap = new EnvWrap(environ);\n"; if (isSingle) { code += "\tvar oldInd=" + meshDocVarName() + ".setCurrent(" + meshID() + ");\n"; code += "\tif (oldInd == -1) return false;\n"; } code += "\tvar result = _applyFilter(\"" + filterName + "\",environWrap);\n"; if (isSingle) code += "\t" +meshDocVarName() + ".setCurrent(oldInd);\n"; code += "\treturn result;\n"; code += "};\n"; return code; }
bool TGOParser::validate(const int &argc, const char **argv) { bool escape_mode = false; for(int i = 1; i < argc; i++) { printf("arg: %s\n", argv[i]); int len = strlen(argv[i]); if(!escape_mode && len >= 2) { if(argv[i][0] == '-') { if(argv[i][1] == '-') { printf("long opt: %s\n", argv[i]); // long option, or -- separator if(len == 2) // -- separator { // all following command line parameters are passed in as is. // no parsing options escape_mode = true; continue; } else { char *eq = (char *)index(argv[i], '='); if(eq) { int name_len = eq - argv[i] - 2; int value_len = len - name_len; std::string optName(argv[i]+2, name_len); std::string optValue(eq+1, value_len); printf("opt: '%s'='%s'\n", optName.c_str(), optValue.c_str()); if(!longOptMap.count(optName)) { printf("unknown option %s.\n", optName.c_str()); return false; } TGOOptionBase *opt = longOptMap[optName]; if(opt->valueRequired()) { if(!optValue.size()) { printf("option %s requires a value.\n", optName.c_str()); return false; } if(opt->validate(optValue)) opt->setOptionValue(optValue); else { printf("option %s value is invalue.\n", argv[i]); return false; } } else { opt->setOptionValue("1"); } } else { if(longOptMap.count(argv[i]+2)) { TGOOptionBase *opt = longOptMap[argv[i]+2]; if(opt->valueRequired()) { if(i+1 >= argc) { printf("option %s requires a value.\n", argv[i]); return false; } const char *nextArg = argv[i+1]; size_t nextArgLen = strlen(nextArg); const char *nextArgValue = 0; if(nextArgLen) { if(nextArg[0] == '-') { if(nextArgLen == 2 && nextArg[1] == '-') { // -- escape arg, pull in argv[i+2] if(i+2 >= argc) { printf("option %s requires a value.\n", argv[i]); return false; } nextArgValue = argv[i+2]; i += 2; } else if(nextArgLen > 1) { printf("option %s requires a value.\n", argv[i]); return false; } else { // singular - (dash) signifies stdin nextArgValue = argv[i+1]; i++; } } else { nextArgValue = argv[i+1]; i++; } } else { printf("option %s requires a value.\n", argv[i]); return false; } if(opt->validate(nextArgValue)) opt->setOptionValue(nextArgValue); else printf("option %s value is invalid.\n", argv[i]); } else { opt->setOptionValue("1"); } } else { printf("unknown option %s\n", argv[i]); return false; } } } } else { // short option, or - stdin marker if(len == 1) { // stdin marker extra_parameters.push_back(argv[i]); } else { for(int j = 1; j < len; j++) { if(!shortOptMap.count(argv[i][j])) { printf("unknown option %c\n", argv[i][j]); return false; } if(shortOptMap[argv[i][j]]->valueRequired()) { if(j <= len) { printf("option %c requires a value.\n", argv[i][j]); return false; } if(shortOptMap[argv[i][j]]->validate(argv[i+1])) { shortOptMap[argv[i][j]]->setOptionValue(argv[i+1]); printf("opt: '%c'='%s'\n", argv[i][j], argv[i+1]); i++; } else { printf("option %c value is invalid.\n", argv[i][j]); return false; } } else { shortOptMap[argv[i][j]]->setOptionValue("1"); } } } } } } else extra_parameters.push_back(argv[i]); } return true; }
//----------------------------------------------------------------------------- // Creates a vstAttachment Locator //----------------------------------------------------------------------------- MStatus CVstAttachmentCmd::DoCreate() { MDagModifier *mDagModifier( new MDagModifier ); if ( !mDagModifier ) { merr << "Can't create new MDagModifier" << std::endl; return MS::kFailure; } MString optName( "vstAttachment" ); if ( m_mArgDatabase->isFlagSet( kOptName ) ) { m_mArgDatabase->getFlagArgument( kOptName, 0, optName ); } // Create the helper bone locator's transform MObject xObj = mDagModifier->createNode( "transform" ); mDagModifier->doIt(); if ( xObj.isNull() ) { merr << "Can't create new transform node" << std::endl; return MS::kFailure; } // name the shape & the transform the same thing mDagModifier->renameNode( xObj, optName ); mDagModifier->doIt(); MObject vstAttachmentObj = mDagModifier->createNode( "vstAttachment", xObj ); if ( vstAttachmentObj.isNull() ) { merr << "Can't create new vstAttachment node" << std::endl; mDagModifier->undoIt(); return MS::kFailure; } // name the shape & the transform the same thing mDagModifier->renameNode( vstAttachmentObj, MFnDependencyNode( xObj ).name() ); mDagModifier->doIt(); m_undoable = true; m_mDagModifier = mDagModifier; if ( m_mArgDatabase->isFlagSet( kOptParent ) ) { MSelectionList mSelectionList; m_mArgDatabase->getObjects( mSelectionList ); for ( MItSelectionList sIt( mSelectionList, MFn::kDagNode ); !sIt.isDone(); sIt.next() ) { MDagPath mDagPath; if ( sIt.getDagPath( mDagPath ) ) { m_mDagModifier->reparentNode( xObj, mDagPath.node() ); m_mDagModifier->doIt(); break; } } } // Save the current selection just in case we want to undo stuff MGlobal::getActiveSelectionList( m_mSelectionList ); MDagPath xDagPath; MDagPath::getAPathTo( xObj, xDagPath ); MGlobal::select( xDagPath, MObject::kNullObj, MGlobal::kReplaceList ); setResult( xDagPath.partialPathName() ); return MS::kSuccess; }