U_CAPI UBool U_EXPORT2 ucm_addMappingAuto(UCMFile *ucm, UBool forBase, UCMStates *baseStates, UCMapping *m, UChar32 codePoints[UCNV_EXT_MAX_UCHARS], uint8_t bytes[UCNV_EXT_MAX_BYTES]) { int32_t type; if(m->f==2 && m->uLen>1) { fprintf(stderr, "ucm error: illegal <subchar1> |2 mapping from multiple code points\n"); printMapping(m, codePoints, bytes, stderr); return FALSE; } if(baseStates!=NULL) { /* check validity of the bytes and count the characters in them */ type=ucm_mappingType(baseStates, m, codePoints, bytes); if(type<0) { /* illegal byte sequence */ printMapping(m, codePoints, bytes, stderr); return FALSE; } } else { /* not used - adding a mapping for an extension-only table before its base table is read */ type=1; } /* * Add the mapping to the base table if this is requested and suitable. * Otherwise, add it to the extension table. */ if(forBase && type==0) { ucm_addMapping(ucm->base, m, codePoints, bytes); } else { ucm_addMapping(ucm->ext, m, codePoints, bytes); } return TRUE; }
U_CAPI UBool U_EXPORT2 ucm_separateMappings(UCMFile *ucm, UBool isSISO) { UCMTable *table; UCMapping *m, *mLimit; int32_t type; UBool needsMove, isOK; table=ucm->base; m=table->mappings; mLimit=m+table->mappingsLength; needsMove=FALSE; isOK=TRUE; for(; m<mLimit; ++m) { if(isSISO && m->bLen==1 && (m->b.bytes[0]==0xe || m->b.bytes[0]==0xf)) { fprintf(stderr, "warning: removing illegal mapping from an SI/SO-stateful table\n"); ucm_printMapping(table, m, stderr); m->moveFlag|=UCM_REMOVE_MAPPING; needsMove=TRUE; continue; } type=ucm_mappingType( &ucm->states, m, UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m)); if(type<0) { /* illegal byte sequence */ printMapping(m, UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m), stderr); isOK=FALSE; } else if(type>0) { m->moveFlag|=UCM_MOVE_TO_EXT; needsMove=TRUE; } } if(!isOK) { return FALSE; } if(needsMove) { ucm_moveMappings(ucm->base, ucm->ext); return ucm_checkBaseExt(&ucm->states, ucm->base, ucm->ext, ucm->ext, FALSE); } else { ucm_sortTable(ucm->base); return TRUE; } }
U_CAPI void U_EXPORT2 ucm_printMapping(UCMTable *table, UCMapping *m, FILE *f) { printMapping(m, UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m), f); }
void RNAFuncs::printMAliXML(deque<pair<double,RNAProfileAlignment*> > &resultList,const RNAforesterOptions &options, double &minPairProb,AddXmlInfos &xmlInfos,const string &outputFile) { string xsdurl = getXSDURL(); int j; // get RNAforester call const char** args; int nrOptions; string command; args = options.getArgs(); nrOptions = options.getNrOfOptions(); for(int i=0;i<nrOptions;i++) { command.append(args[i]); command.append(" "); } try { xmlpp::Document document; deque<pair<string,string> > seqAli; deque<string> strAli; string consSeq, consStr; deque<double> baseprobs; deque<pair<pair<int,int>,double> > pairprobs; stringstream tmpBase; //create root node xmlpp::Element* nodeRoot = document.create_root_node("rnastructAlignmentML", "", ""); //set namespace declarations to root element nodeRoot->set_namespace_declaration(xsdurl, ""); nodeRoot->set_namespace_declaration("http://www.w3.org/2001/XMLSchema-instance","xsi"); nodeRoot->set_attribute("schemaLocation",xsdurl + " http://bibiserv.techfak.uni-bielefeld.de/xsd/net/sourceforge/hobit/20060515/rnastructAlignmentML.xsd","xsi"); // N VALues in the deque are n cluster deque<pair<double,RNAProfileAlignment*> >::const_iterator it; for(it=resultList.begin();it!=resultList.end();it++) { // create node rnastructalignment xmlpp::Element* nodeRnaStructAlignment = nodeRoot->add_child("rnastructurealignment"); //print aligned sequences and structures seqAli = it->second->getSeqAli(); strAli = it->second->getStrAli(); // j iterator to get structure alignment j=0; deque<pair<string,string> >::const_iterator it2; for(it2=seqAli.begin();it2!=seqAli.end();it2++) { xmlpp::Element* nodeSequence = nodeRnaStructAlignment->add_child("sequence"); nodeSequence->set_attribute("seqID",xmlInfos.idmapping[atoi(it2->first.c_str())]); if(xmlInfos.names.count(atoi(it2->first.c_str())) > 0){ nodeSequence->add_child("name")->set_child_text(xmlInfos.names[atoi(it2->first.c_str())]); } if(xmlInfos.synonyms.count(atoi(it2->first.c_str())) > 0){ nodeSequence->add_child("synonyms")->set_child_text(xmlInfos.synonyms[atoi(it2->first.c_str())]); } if(xmlInfos.descriptions.count(atoi(it2->first.c_str())) > 0){ nodeSequence->add_child("description")->set_child_text(xmlInfos.descriptions[atoi(it2->first.c_str())]); } xmlpp::Element* nodeAlignedFreeSequence = nodeSequence->add_child("alignedFreeSequence"); nodeAlignedFreeSequence->set_child_text(UpperCase(it2->second)); xmlpp::Element* nodeStructure = nodeSequence->add_child("structure"); nodeStructure->set_child_text(strAli[j]); if(xmlInfos.comments.count(atoi(it2->first.c_str())) > 0){ nodeSequence->add_child("comment")->set_child_text(xmlInfos.comments[atoi(it2->first.c_str())]); } j++; } // insert consensus element xmlpp::Element* nodeConsensus = nodeRnaStructAlignment->add_child("consensus"); // get and insert structure pairprobs it->second->getPairProb(minPairProb, pairprobs); xmlpp::Element* nodeStrProbs = nodeConsensus->add_child("structureprobabilities"); deque<pair<pair<int,int>,double> >::iterator it3; for(it3=pairprobs.begin();it3!=pairprobs.end();it3++) { xmlpp::Element* nodePt = nodeStrProbs->add_child("pt"); tmpBase << it3->first.first; nodePt->set_attribute("a",tmpBase.str()); tmpBase.str(""); tmpBase << it3->first.second; nodePt->set_attribute("b",tmpBase.str()); tmpBase.str(""); tmpBase << it3->second; nodePt->set_attribute("probability",tmpBase.str()); tmpBase.str(""); } // get and insert consensus sequence consSeq = it->second->getConsSeq(); xmlpp::Element* nodeConsSeq = nodeConsensus->add_child("sequence"); nodeConsSeq->set_attribute("seqID","consensus"); xmlpp::Element* nodeAlignedFSCons = nodeConsSeq->add_child("alignedFreeSequence"); nodeAlignedFSCons->set_child_text(UpperCase(consSeq)); // get and insert consensus structure consStr = it->second->getConsStr(minPairProb); xmlpp::Element* nodeConsStr = nodeConsSeq->add_child("structure"); nodeConsStr->set_child_text(consStr); //xmlpp::Element* nodeConsStr = nodeConsensus->add_child("structure"); //nodeConsStr->set_child_text(consStr); // insert nodes program and attribute command xmlpp::Element* nodeProgram = nodeRnaStructAlignment->add_child("program"); nodeProgram->set_attribute("command",command); } // end for document.write_to_file("./" + outputFile,"UTF-8"); // display the mapping from the internal id to the name of the sequence / structure qualified in the name element in the rnastructML if(xmlInfos.xmlInput){ printMapping(xmlInfos.idmapping); } } catch(const std::exception& ex) { cout << "xml exception: " << ex.what() << std::endl; } }
void RNAFuncs::printPAliXML(const string &id1, const string &id2, const string &seq1, const string &seq2, const string &str1, const string &str2, double &score, const RNAforesterOptions &options,AddXmlInfos &xmlInfos,const string &outputFile) { char arr_Score[20]; const char** args; int nrOptions; string command; bool xmlInput; string comment1; string comment2; string description1; string description2; xmlpp::Document* xmlDocOrig; xmlpp::DomParser domParser; xmlpp::Element* elemRootOrig; xmlpp::NodeSet nodeSetOrig; args = options.getArgs(); nrOptions = options.getNrOfOptions(); for(int i=0;i<nrOptions;i++){ command.append(args[i]); command.append(" "); } try { xmlpp::Document document; xmlpp::Element* nodeSequences[2]; xmlpp::Element* nodeProgram; string xsdurl; xsdurl = getXSDURL(); //create root node xmlpp::Element* nodeRoot = document.create_root_node("rnastructAlignmentML", "", ""); //set namespace declarations to root element nodeRoot->set_namespace_declaration(xsdurl, ""); nodeRoot->set_namespace_declaration("http://www.w3.org/2001/XMLSchema-instance","xsi"); nodeRoot->set_attribute("schemaLocation",xsdurl + " http://bibiserv.techfak.uni-bielefeld.de/xsd/net/sourceforge/hobit/20060515/rnastructAlignmentML.xsd","xsi"); xmlpp::Element* nodeRnaStructAlignment = nodeRoot->add_child("rnastructurealignment"); //convert double to char array to use in set_attribute sprintf(arr_Score,"%.0f",score); nodeRnaStructAlignment->set_attribute("score",arr_Score); nodeSequences[1] = nodeRnaStructAlignment->add_child("sequence"); nodeSequences[1]->set_attribute("seqID",xmlInfos.idmapping[atoi(id1.c_str())]); if(options.has(RNAforesterOptions::LocalSimilarity)){ stringstream ss; ss << xmlInfos.xbasepos; nodeSequences[1]->set_attribute("startingposition",ss.str()); } if(xmlInfos.names.count(atoi(id1.c_str())) > 0){ nodeSequences[1]->add_child("name")->set_child_text(xmlInfos.names[atoi(id1.c_str())]); } if(xmlInfos.synonyms.count(atoi(id1.c_str())) > 0){ nodeSequences[1]->add_child("synonyms")->set_child_text(xmlInfos.synonyms[atoi(id1.c_str())]); } if(xmlInfos.descriptions.count(atoi(id1.c_str())) > 0){ nodeSequences[1]->add_child("description")->set_child_text(xmlInfos.descriptions[atoi(id1.c_str())]); } nodeSequences[1]->add_child("alignedFreeSequence")->set_child_text(UpperCase(seq1)); nodeSequences[1]->add_child("structure")->set_child_text(str1); // id is of type string index of map is of size int => convert if(xmlInfos.comments.count(atoi(id1.c_str())) > 0){ nodeSequences[1]->add_child("comment")->set_child_text(xmlInfos.comments[atoi(id1.c_str())]); } nodeSequences[2] = nodeRnaStructAlignment->add_child("sequence"); nodeSequences[2]->set_attribute("seqID",xmlInfos.idmapping[atoi(id2.c_str())]); if(options.has(RNAforesterOptions::LocalSimilarity)){ stringstream ss; ss << xmlInfos.ybasepos; nodeSequences[2]->set_attribute("startingposition",ss.str()); } if(xmlInfos.names.count(atoi(id2.c_str())) > 0){ nodeSequences[2]->add_child("name")->set_child_text(xmlInfos.names[atoi(id2.c_str())]); } if(xmlInfos.synonyms.count(atoi(id2.c_str())) > 0){ nodeSequences[2]->add_child("synonyms")->set_child_text(xmlInfos.synonyms[atoi(id2.c_str())]); } if(xmlInfos.descriptions.count(atoi(id2.c_str())) > 0){ nodeSequences[2]->add_child("description")->set_child_text(xmlInfos.descriptions[atoi(id2.c_str())]); } nodeSequences[2]->add_child("alignedFreeSequence")->set_child_text(UpperCase(seq2)); nodeSequences[2]->add_child("structure")->set_child_text(str2); // id is of type string index of map is of size int => convert if(xmlInfos.comments.count(atoi(id2.c_str())) > 0){ nodeSequences[2]->add_child("comment")->set_child_text(xmlInfos.comments[atoi(id2.c_str())]); } nodeRnaStructAlignment->add_child("program")->set_attribute("command",command); document.write_to_file("./" + outputFile,"UTF-8"); // display the mapping from the internal id to the name of the sequence / structure qualified in the name element in the rnastructML if(xmlInfos.xmlInput){ printMapping(xmlInfos.idmapping); } } catch(const std::exception& ex) { cout << "xml exception: " << ex.what() << std::endl; } }
int main(int argc, char **argv) { extern int optind; char *database = NULL; char *ldapfilter = NULL; char *attribute = "dn"; char **key = NULL; char **ldapattribute = NULL; char *buffer[100]; char *err = NULL; char *p; int index = 1; int c; int rc; int verbose = 0; char *udata = NULL; ns_standalone_conf_t standalone_cfg = standaloneDefaults; ns_ldap_error_t *errorp = NULL; char *authmech = NULL; ns_auth_t auth = {NS_LDAP_AUTH_NONE, NS_LDAP_TLS_NONE, NS_LDAP_SASL_NONE, NS_LDAP_SASLOPT_NONE}; (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); openlog("ldaplist", LOG_PID, LOG_USER); if (argc == 2 && strlen(argv[1]) == 2 && strncmp(argv[1], "-h", 2) == 0) { /* preserve backwards compatability, support old -h option */ (void) printMapping(); exit(0); } while ((c = getopt(argc, argv, "h:M:N:P:r:a:D:w:j:dgvl")) != EOF) { switch (c) { case 'd': listflag |= NS_LDAP_SCOPE_BASE; break; case 'g': (void) printMapping(); exit(0); break; /* Never reached */ case 'l': attribute = "NULL"; break; case 'v': verbose = 1; break; case 'M': standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_DOMAIN = optarg; break; case 'h': standalone_cfg.type = NS_LDAP_SERVER; if (separatePort(optarg, &standalone_cfg.SA_SERVER, &standalone_cfg.SA_PORT) > 0) { exit(1); } break; case 'P': standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_CERT_PATH = optarg; break; case 'N': standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_PROFILE_NAME = optarg; break; case 'D': standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_BIND_DN = strdup(optarg); break; case 'w': if (standalone_cfg.SA_BIND_PWD != NULL) { (void) fprintf(stderr, gettext("The -w option is mutually " "exclusive of -j. -w is ignored.\n")); break; } if (optarg != NULL && optarg[0] == '-' && optarg[1] == '\0') { /* Ask for a password later */ break; } standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_BIND_PWD = strdup(optarg); break; case 'j': if (standalone_cfg.SA_BIND_PWD != NULL) { (void) fprintf(stderr, gettext("The -w option is mutually " "exclusive of -j. -w is ignored.\n")); free(standalone_cfg.SA_BIND_PWD); } standalone_cfg.type = NS_LDAP_SERVER; standalone_cfg.SA_BIND_PWD = readPwd(optarg); if (standalone_cfg.SA_BIND_PWD == NULL) { exit(1); } break; case 'a': authmech = optarg; break; default: usage(gettext("Invalid option")); } } if (standalone_cfg.type == NS_LDAP_SERVER && standalone_cfg.SA_SERVER == NULL) { (void) fprintf(stderr, gettext("Please specify an LDAP server you want " "to connect to. \n")); exit(1); } if ((c = argc - optind) > 0) database = argv[optind++]; if ((--c) > 0) key = &argv[optind]; if (authmech != NULL) { if (__ns_ldap_initAuth(authmech, &auth, &errorp) != NS_LDAP_SUCCESS) { if (errorp) { (void) fprintf(stderr, "%s", errorp->message); (void) __ns_ldap_freeError(&errorp); } exit(1); } } if (auth.saslmech != NS_LDAP_SASL_GSSAPI && standalone_cfg.SA_BIND_DN != NULL && standalone_cfg.SA_BIND_PWD == NULL) { /* If password is not specified, then prompt user for it. */ standalone_cfg.SA_BIND_PWD = strdup(getpassphrase("Enter password:"******"%s\n", errorp->message); (void) __ns_ldap_freeError(&errorp); } exit(1); } if (authmech != NULL) { if (__ns_ldap_setParam(NS_LDAP_AUTH_P, authmech, &errorp) != NS_LDAP_SUCCESS) { __ns_ldap_cancelStandalone(); if (errorp != NULL) { (void) fprintf(stderr, "%s", errorp->message); (void) __ns_ldap_freeError(&errorp); } exit(1); } } if (standalone_cfg.SA_CRED != NULL) { if (__ns_ldap_setParam(NS_LDAP_CREDENTIAL_LEVEL_P, standalone_cfg.SA_CRED, &errorp) != NS_LDAP_SUCCESS) { __ns_ldap_cancelStandalone(); if (errorp != NULL) { (void) fprintf(stderr, "%s", errorp->message); (void) __ns_ldap_freeError(&errorp); } exit(1); } } if (standalone_cfg.type != NS_CACHEMGR && standalone_cfg.SA_BIND_DN != NULL) { ns_auth_t **authpp = NULL, **authp = NULL; if (__ns_ldap_getParam(NS_LDAP_AUTH_P, (void ***)&authpp, &errorp) != NS_LDAP_SUCCESS || authpp == NULL) { __ns_ldap_cancelStandalone(); (void) __ns_ldap_freeParam((void ***)&authpp); if (errorp) { (void) fprintf(stderr, gettext(errorp->message)); (void) __ns_ldap_freeError(&errorp); } exit(1); } for (authp = authpp; *authp; authp++) { if ((*authp)->saslmech == NS_LDAP_SASL_GSSAPI) { /* * For now we have no use for bindDN and * bindPassword when using SASL/GSSAPI. */ (void) fprintf(stderr, gettext("Warning: SASL/GSSAPI will be " "used as an authentication method" "The bind DN and password will " "be ignored.\n")); break; } } } /* * If dumpping a database, * or all the containers, * use page control just * in case there are too many entries */ if (!key && !(listflag & NS_LDAP_SCOPE_BASE)) listflag |= NS_LDAP_PAGE_CTRL; /* build the attribute array */ if (strncasecmp(attribute, "NULL", 4) == 0) ldapattribute = NULL; else { buffer[0] = strdup(attribute); while ((p = strchr(attribute, ',')) != NULL) { buffer[index++] = attribute = p + 1; *p = '\0'; } buffer[index] = NULL; ldapattribute = buffer; } /* build the filter */ if (database && (strcasecmp(database, "publickey") == NULL)) { /* user publickey lookup */ char *err1 = NULL; int rc1; rc = rc1 = -1; ldapfilter = set_filter_publickey(key, database, 0, &udata); if (ldapfilter) { if (verbose) { (void) fprintf(stdout, gettext("+++ database=%s\n"), (database ? database : "NULL")); (void) fprintf(stdout, gettext("+++ filter=%s\n"), (ldapfilter ? ldapfilter : "NULL")); (void) fprintf(stdout, gettext("+++ template for merging" "SSD filter=%s\n"), (udata ? udata : "NULL")); } rc = list("passwd", ldapfilter, ldapattribute, &err, udata); free(ldapfilter); free(udata); } /* hosts publickey lookup */ ldapfilter = set_filter_publickey(key, database, 1, &udata); if (ldapfilter) { if (verbose) { (void) fprintf(stdout, gettext("+++ database=%s\n"), (database ? database : "NULL")); (void) fprintf(stdout, gettext("+++ filter=%s\n"), (ldapfilter ? ldapfilter : "NULL")); (void) fprintf(stdout, gettext("+++ template for merging" "SSD filter=%s\n"), (udata ? udata : "NULL")); } rc1 = list("hosts", ldapfilter, ldapattribute, &err1, udata); free(ldapfilter); free(udata); } if (rc == -1 && rc1 == -1) { /* this should never happen */ (void) fprintf(stderr, gettext("ldaplist: invalid publickey lookup\n")); rc = 2; } else if (rc != 0 && rc1 != 0) { (void) fprintf(stderr, gettext("ldaplist: %s\n"), (err ? err : err1)); if (rc == -1) rc = rc1; } else rc = 0; exit(switch_err(rc)); } /* * we set the search filter to (objectclass=*) when we want * to list the directory attribute instead of the entries * (the -d option). */ if (((ldapfilter = set_filter(key, database, &udata)) == NULL) || (listflag == NS_LDAP_SCOPE_BASE)) { ldapfilter = strdup("objectclass=*"); udata = strdup("%s"); } if (verbose) { (void) fprintf(stdout, gettext("+++ database=%s\n"), (database ? database : "NULL")); (void) fprintf(stdout, gettext("+++ filter=%s\n"), (ldapfilter ? ldapfilter : "NULL")); (void) fprintf(stdout, gettext("+++ template for merging SSD filter=%s\n"), (udata ? udata : "NULL")); } if (rc = list(database, ldapfilter, ldapattribute, &err, udata)) (void) fprintf(stderr, gettext("ldaplist: %s\n"), err); __ns_ldap_cancelStandalone(); if (ldapfilter) free(ldapfilter); if (udata) free(udata); exit(switch_err(rc)); return (0); /* Never reached */ }