int main(int argc, char **argv) { virt_dirent_t *tp; virtdir_t t; struct stat st; (void) memset(&t, 0x0, sizeof(t)); stat(".", &st); virtdir_add(&t, ".", 1, 'd', NULL, 0); stat("..", &st); virtdir_add(&t, "..", 2, 'd', NULL, 0); st.st_mode = S_IFREG | 0644; virtdir_add(&t, "file1", 5, 'f', NULL, 0); ptree(&t); virtdir_add(&t, "file2", 5, 'f', NULL, 0); virtdir_add(&t, "file0", 5, 'f', NULL, 0); virtdir_add(&t, "abcde", 5, 'f', NULL, 0); virtdir_add(&t, "bcdef", 5, 'f', NULL, 0); virtdir_add(&t, "a", 1, 'f', NULL, 0); ptree(&t); if ((tp = virtdir_find(&t, "a", 1)) == NULL) { printf("borked2\n"); } else { printf("a found\n"); } virtdir_drop(&t); exit(EXIT_SUCCESS); }
static void ptree_type_pattern(int flags, enum nodetype t, const char *pat) { struct printer_info info; struct node *np; info.flags = flags; info.pat = pat; info.t = t; switch (t) { case T_FAULT: lut_walk(Faults, (lut_cb)byname_printer, (void *)&info); return; case T_UPSET: lut_walk(Upsets, (lut_cb)byname_printer, (void *)&info); return; case T_DEFECT: lut_walk(Defects, (lut_cb)byname_printer, (void *)&info); return; case T_ERROR: lut_walk(Errors, (lut_cb)byname_printer, (void *)&info); return; case T_EREPORT: lut_walk(Ereports, (lut_cb)byname_printer, (void *)&info); return; case T_SERD: lut_walk(SERDs, (lut_cb)byname_printer, (void *)&info); return; case T_STAT: lut_walk(STATs, (lut_cb)byname_printer, (void *)&info); return; case T_ASRU: lut_walk(ASRUs, (lut_cb)byname_printer, (void *)&info); return; case T_FRU: lut_walk(FRUs, (lut_cb)byname_printer, (void *)&info); return; case T_CONFIG: lut_walk(Configs, (lut_cb)byname_printer, (void *)&info); return; case T_PROP: for (np = Props; np; np = np->u.stmt.next) if (name_pattern_match_in_subtree(np->u.stmt.np, pat)) ptree(flags, np, 0, 0); return; case T_MASK: for (np = Masks; np; np = np->u.stmt.next) if (name_pattern_match_in_subtree(np->u.stmt.np, pat)) ptree(flags, np, 0, 0); return; default: ptree(flags, tree_root(NULL), 0, 0); } }
void ptree(int x) { if (x == 0) printf("."); else { printf("("); ptree(left[x]); printf((count[x] == 1) ? " %d " : " %d:%d ", key[x], count[x]); ptree(right[x]); printf(")"); } }
// Retrieve the node corresponding to the given key. If the node does not exist, it is created. ModelMain::ptree &ModelMain::fetch(const std::string &key) { if(_root->find(key)==_root->not_found()) { _root->put_child(key, ptree()); } return _root->get_child(key); }
/* If the hash is not present nothing happens other than splaying the tree. Otherwise the identified node is removed from the tree and then placed back at the front of the chain. */ static inline void cacheset_remove(struct cache_set *cs, unsigned char *md5, size_t size) { struct node *targetnode; struct node *reattachnode; int64_t hash[2]; memcpy(hash, md5, 16); if(splay(hash, size, cs) != 1) { cli_dbgmsg("cacheset_remove: node not found in tree\n"); return; /* No op */ } ptree("cacheset_remove: node found and splayed to root\n"); targetnode = cs->root; /* First fix the tree */ if(targetnode->left == NULL) { /* At left edge so prune */ cs->root = targetnode->right; if(cs->root) cs->root->up = NULL; } else { /* new root will come from leftside tree */ cs->root = targetnode->left; cs->root->up = NULL; /* splay tree, expecting not found, bringing rightmost member to root */ splay(hash, size, cs); if (targetnode->right) { /* reattach right tree to clean right-side attach point */ reattachnode = cs->root; while (reattachnode->right) reattachnode = reattachnode->right; /* shouldn't happen, but safer in case of dupe */ reattachnode->right = targetnode->right; } } targetnode->up = NULL; targetnode->left = NULL; targetnode->right = NULL; /* Tree is fixed, so now fix chain around targetnode */ if(targetnode->prev) targetnode->prev->next = targetnode->next; if(targetnode->next) targetnode->next->prev = targetnode->prev; if(cs->last == targetnode) cs->last = targetnode->prev; /* Put targetnode at front of chain */ if(cs->first && (cs->first != targetnode)) { cs->first->prev = targetnode; } targetnode->next = cs->first; targetnode->prev = NULL; cs->first = targetnode; }
static void byname_printer(struct node *lhs, struct node *rhs, void *arg) { struct printer_info *infop = (struct printer_info *)arg; if (infop->t != T_NOTHING && rhs->t != infop->t) return; if (!name_pattern_match(lhs, infop->pat)) return; ptree(infop->flags, rhs, 0, 0); }
void TF_Datasource::writeProjectionMetaData(boost::property_tree::ptree& propertyTree, std::string metaDataFileName, std::vector<ScannerGeometry*> projectionProperties, const std::vector<std::string>& filenames) { for(unsigned int i = 0; i < projectionProperties.size(); i++) { STEMScannerGeometry* geometry = dynamic_cast<STEMScannerGeometry*>(projectionProperties[i]); if (geometry == nullptr) throw Exception("TF_Datasource requires STEMScannerGeometry data"); ptree& projectionNode = propertyTree.add_child("projection", ptree()); ptree& imageNode = projectionNode.add_child("image", ptree()); imageNode.add("<xmlattr>.filename", filenames[i]); ptree& tiltNode = projectionNode.add_child("tiltAngle", ptree()); tiltNode.add("<xmlattr>.value", geometry->getTiltAngle()); projectionNode.add_child("convergent", ptree()); ptree& openingNode = projectionNode.add_child("beamOpeningAngle", ptree()); openingNode.add("<xmlattr>.value", geometry->getConfocalOpeningHalfAngle()); ptree& focalNode = projectionNode.add_child("focalDistance", ptree()); focalNode.add("<xmlattr>.value", geometry->getFocalDepth()); ptree& focalDifferenceNode = projectionNode.add_child("focalDistanceBetweenImages", ptree()); focalDifferenceNode.add("<xmlattr>.value", geometry->getFocalDifferenceBetweenImages()); } }
static int printtree(struct cache_set *cs, struct node *n, int d) { int i; int ab = 0; if (n == NULL) return 0; if(n == cs->root) { ptree("--------------------------\n"); } ab |= printtree(cs, n->right, d+1); if(n->right) { if(cmp(n->digest, n->size, n->right->digest, n->right->size) >= 0) { for (i=0; i<d; i++) ptree(" "); ptree("^^^^ %lld >= %lld\n", n->digest[1], n->right->digest[1]); ab = 1; } } for (i=0; i<d; i++) ptree(" "); ptree("%08x(%02u)\n", n->digest[1]>>48, n - cs->data); if(n->left) { if(cmp(n->digest, n->size, n->left->digest, n->left->size) <= 0) { for (i=0; i<d; i++) ptree(" "); ptree("vvvv %lld <= %lld\n", n->digest[1], n->left->digest[1]); ab = 1; } } if(d){ if(!n->up) { ptree("no parent!\n"); ab = 1; } else { if(n->up->left != n && n->up->right != n) { ptree("broken parent\n"); ab = 1; } } } else { if(n->up) { ptree("root with a parent!\n"); ab = 1; } } ab |= printtree(cs, n->left, d+1); return ab; }
// Constructor. ModelMain::ModelMain() : DECLARE_READ_ONLY (config_file ), DECLARE_READ_WRITE(time_control ), DECLARE_READ_WRITE(show_status_bar ), DECLARE_READ_WRITE(reset_confirmation ), DECLARE_READ_WRITE(delay_before_display_seconds), DECLARE_READ_WRITE(display_time_after_timeout ), DECLARE_READ_WRITE(display_bronstein_extra_info), DECLARE_READ_WRITE(display_byo_yomi_extra_info ), DECLARE_READ_WRITE(keyboard_id ), DECLARE_READ_WRITE(keyboard_has_numeric_keypad ), DECLARE_READ_WRITE(modifier_keys ), DECLARE_READ_WRITE(left_player ), DECLARE_READ_WRITE(right_player ), DECLARE_READ_WRITE(show_player_names ) { register_property(config_file ); register_property(time_control ); register_property(show_status_bar ); register_property(reset_confirmation ); register_property(delay_before_display_seconds); register_property(display_time_after_timeout ); register_property(display_bronstein_extra_info); register_property(display_byo_yomi_extra_info ); register_property(keyboard_id ); register_property(keyboard_has_numeric_keypad ); register_property(modifier_keys ); register_property(left_player ); register_property(right_player ); register_property(show_player_names ); // Load the file if it exists. if(boost::filesystem::exists(config_file())) { try { boost::property_tree::read_xml(config_file(), _data, boost::property_tree::xml_parser::trim_whitespace); } catch(boost::property_tree::xml_parser_error &) { throw std::runtime_error("An error has occurred while reading the preference file."); } } // Set up the root node. if(_data.find("options")==_data.not_found()) { _data.put_child("options", ptree()); } _root = &_data.get_child("options"); }
//********************************************************************************************************************** vector<string> SetCurrentCommand::setParameters(){ try { CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pflow); CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfile); CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pbiom); CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pphylip); CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcolumn); CommandParameter psummary("summary", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psummary); CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfasta); CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname); CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup); CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(plist); CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptaxonomy); CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pconstaxonomy); CommandParameter pcontigsreport("contigsreport", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcontigsreport); CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pqfile); CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prabund); CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psabund); CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign); CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(porder); CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptree); CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pshared); CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pordergroup); CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcount); CommandParameter pcurrent("current", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcurrent); CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prelabund); CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psff); CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos); CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear); CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector<string> myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { m->errorOut(e, "SetCurrentCommand", "setParameters"); exit(1); } }
bool ConfigTree::ptreeFromParam(ConfigParameter fromParam, ptree &toPtree) { CONFIGSYS_DEBUG_CALLS; toPtree = ptree(); toPtree.put("desc", fromParam.getDescription()); std::string modStr = (fromParam.isModified())? "true" : "false"; toPtree.put("modified", modStr); std::string lockStr = (fromParam.isLocked())? "true" : "false"; toPtree.put("locked", lockStr); value_type vt = fromParam.getType(); std::string typStr = makeValueTypeString(vt); toPtree.put("type", typStr); return addParamValueandRangeToPtree(fromParam, toPtree); }
//********************************************************************************************************************** vector<string> ParsimonyCommand::setParameters(){ try { CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","parsimony-psummary",false,true,true); parameters.push_back(ptree); CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); CommandParameter prandom("random", "String", "", "", "", "", "","",false,false); parameters.push_back(prandom); CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector<string> myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { m->errorOut(e, "ParsimonyCommand", "setParameters"); exit(1); } }
void ptree_plut(void *name, void *val, void *arg) { struct plut_wlk_data *pd = (struct plut_wlk_data *)arg; int c; static int indent; indent++; if (pd->first == 0) out(pd->flags, ","); else pd->first = 0; for (c = indent; c > 0; c--) out(pd->flags|O_NONL, "\t"); out(pd->flags|O_NONL, "%s", (char *)name); out(pd->flags|O_NONL, "="); ptree(pd->flags, val, 0, 0); indent--; }
/* If the hash is present nothing happens. Otherwise a new node is created for the hash picking one from the begin of the chain. Used nodes are moved to the end of the chain */ static inline void cacheset_add(struct cache_set *cs, unsigned char *md5, size_t size, uint32_t reclevel) { struct node *newnode; int64_t hash[2]; memcpy(hash, md5, 16); if(splay(hash, size, cs)) { if(cs->root->minrec > reclevel) cs->root->minrec = reclevel; return; /* Already there */ } ptree("1:\n"); if(printtree(cs, cs->root, 0)) { cli_errmsg("cacheset_add: inconsistent tree before choosing newnode, good luck\n"); return; } newnode = cs->first; while(newnode) { if(!newnode->right && !newnode->left) break; newnode = newnode->next; } if(!newnode) { cli_errmsg("cacheset_add: tree has got no end nodes\n"); return; } if(newnode->up) { if(newnode->up->left == newnode) newnode->up->left = NULL; else newnode->up->right = NULL; } if(newnode->prev) newnode->prev->next = newnode->next; if(newnode->next) newnode->next->prev = newnode->prev; if(cs->first == newnode) cs->first = newnode->next; newnode->prev = cs->last; newnode->next = NULL; cs->last->next = newnode; cs->last = newnode; ptree("2:\n"); if(printtree(cs, cs->root, 0)) { cli_errmsg("cacheset_add: inconsistent tree before adding newnode, good luck\n"); return; } if(!cs->root) { newnode->left = NULL; newnode->right = NULL; } else { if(cmp(hash, size, cs->root->digest, cs->root->size) < 0) { newnode->left = cs->root->left; newnode->right = cs->root; cs->root->left = NULL; } else { newnode->right = cs->root->right; newnode->left = cs->root; cs->root->right = NULL; } if(newnode->left) newnode->left->up = newnode; if(newnode->right) newnode->right->up = newnode; } newnode->digest[0] = hash[0]; newnode->digest[1] = hash[1]; newnode->up = NULL; newnode->size = size; newnode->minrec = reclevel; cs->root = newnode; ptree("3: %lld\n", hash[1]); if(printtree(cs, cs->root, 0)) { cli_errmsg("cacheset_add: inconsistent tree after adding newnode, good luck\n"); return; } }
void print(int r) { ptree(r); printf("\n"); }
void ptree(int flags, struct node *np, int no_iterators, int fileline) { if (np == NULL) return; switch (np->t) { case T_NOTHING: break; case T_NAME: out(flags|O_NONL, "%s", np->u.name.s); if (!no_iterators) { if (np->u.name.cp != NULL) { int num; cp2num(np->u.name.cp, &num); out(flags|O_NONL, "%d", num); } else if (np->u.name.it == IT_HORIZONTAL) { if (np->u.name.child == NULL || (np->u.name.childgen && !Pchildgen)) out(flags|O_NONL, "<>"); else { out(flags|O_NONL, "<"); ptree(flags, np->u.name.child, no_iterators, fileline); out(flags|O_NONL, ">"); } } else if (np->u.name.child && (!np->u.name.childgen || Pchildgen)) { if (np->u.name.it != IT_NONE) out(flags|O_NONL, "["); ptree(flags, np->u.name.child, no_iterators, fileline); if (np->u.name.it != IT_NONE) out(flags|O_NONL, "]"); } } if (np->u.name.next) { ASSERT(np->u.name.next->t == T_NAME); if (np->u.name.it == IT_ENAME) out(flags|O_NONL, "."); else out(flags|O_NONL, "/"); ptree(flags, np->u.name.next, no_iterators, fileline); } break; case T_TIMEVAL: ptree_timeval(flags, &np->u.ull); break; case T_NUM: out(flags|O_NONL, "%llu", np->u.ull); break; case T_QUOTE: out(flags|O_NONL, "\"%s\"", np->u.quote.s); break; case T_GLOBID: out(flags|O_NONL, "$%s", np->u.globid.s); break; case T_FUNC: out(flags|O_NONL, "%s(", np->u.func.s); ptree(flags, np->u.func.arglist, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_NVPAIR: ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "="); ptree(flags, np->u.expr.right, no_iterators, fileline); break; case T_EVENT: ptree(flags, np->u.event.ename, no_iterators, fileline); if (np->u.event.epname) { out(flags|O_NONL, "@"); ptree(flags, np->u.event.epname, no_iterators, fileline); } if (np->u.event.eexprlist) { out(flags|O_NONL, "{"); ptree(flags, np->u.event.eexprlist, no_iterators, fileline); out(flags|O_NONL, "}"); } break; case T_ASSIGN: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "="); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_NOT: out(flags|O_NONL, "("); out(flags|O_NONL, "!"); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_AND: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "&&"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_OR: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "||"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_EQ: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "=="); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_NE: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "!="); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_SUB: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "-"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_ADD: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "+"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_MUL: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "*"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_DIV: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "/"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_MOD: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "%%"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_LT: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "<"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_LE: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "<="); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_GT: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ">"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_GE: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ">="); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_BITNOT: out(flags|O_NONL, "("); out(flags|O_NONL, "~"); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_BITAND: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "&"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_BITOR: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "|"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_BITXOR: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "^"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_LSHIFT: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "<<"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_RSHIFT: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ">>"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_CONDIF: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, "?"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_CONDELSE: out(flags|O_NONL, "("); ptree(flags, np->u.expr.left, no_iterators, fileline); out(flags|O_NONL, ":"); ptree(flags, np->u.expr.right, no_iterators, fileline); out(flags|O_NONL, ")"); break; case T_ARROW: ptree(flags, np->u.arrow.lhs, no_iterators, fileline); if (np->u.arrow.nnp) { out(flags|O_NONL, "("); ptree(flags, np->u.arrow.nnp, no_iterators, fileline); out(flags|O_NONL, ")"); } out(flags|O_NONL, "->"); if (np->u.arrow.knp) { out(flags|O_NONL, "("); ptree(flags, np->u.arrow.knp, no_iterators, fileline); out(flags|O_NONL, ")"); } ptree(flags, np->u.arrow.rhs, no_iterators, fileline); break; case T_LIST: ptree(flags, np->u.expr.left, no_iterators, fileline); if (np->u.expr.left && np->u.expr.right && (np->u.expr.left->t != T_LIST || ! is_stmt(np->u.expr.right))) out(flags|O_NONL, ","); ptree(flags, np->u.expr.right, no_iterators, fileline); break; case T_FAULT: case T_UPSET: case T_DEFECT: case T_ERROR: case T_EREPORT: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "event "); ptree(flags, np->u.stmt.np, no_iterators, fileline); if (np->u.stmt.nvpairs) { out(flags|O_NONL, " "); ptree(flags, np->u.stmt.nvpairs, no_iterators, fileline); } out(flags, ";"); break; case T_SERD: case T_STAT: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "engine "); ptree(flags, np->u.stmt.np, no_iterators, fileline); if (np->u.stmt.nvpairs) { out(flags|O_NONL, " "); ptree(flags, np->u.stmt.nvpairs, no_iterators, fileline); } else if (np->u.stmt.lutp) { struct plut_wlk_data pd; pd.flags = flags; pd.first = 0; lut_walk(np->u.stmt.lutp, ptree_plut, &pd); } out(flags, ";"); break; case T_ASRU: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "asru "); ptree(flags, np->u.stmt.np, no_iterators, fileline); if (np->u.stmt.nvpairs) { out(flags|O_NONL, " "); ptree(flags, np->u.stmt.nvpairs, no_iterators, fileline); } out(flags, ";"); break; case T_FRU: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "fru "); ptree(flags, np->u.stmt.np, no_iterators, fileline); if (np->u.stmt.nvpairs) { out(flags|O_NONL, " "); ptree(flags, np->u.stmt.nvpairs, no_iterators, fileline); } out(flags, ";"); break; case T_CONFIG: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "config "); ptree(flags, np->u.stmt.np, no_iterators, fileline); if (np->u.stmt.nvpairs) { out(flags|O_NONL, " "); ptree(flags, np->u.stmt.nvpairs, no_iterators, fileline); } out(flags, ";"); break; case T_PROP: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "prop "); ptree(flags, np->u.stmt.np, no_iterators, fileline); out(flags, ";"); break; case T_MASK: if (fileline) out(flags, "# %d \"%s\"", np->line, np->file); out(flags|O_NONL, "mask "); ptree(flags, np->u.stmt.np, no_iterators, fileline); out(flags, ";"); break; default: out(O_DIE, "internal error: ptree unexpected nodetype: %d", np->t); /*NOTREACHED*/ } }
int main(int argc, char **argv) { int nscores = 5; std::string ttable = ""; bool useAlignments = false; bool reportCounts = false; for(int i = 1; i < argc; i++) { if(!strcmp(argv[i], "-n")) { if(i + 1 == argc) usage(); nscores = atoi(argv[++i]); } else if(!strcmp(argv[i], "-t")) { if(i + 1 == argc) usage(); ttable = argv[++i]; } else if(!strcmp(argv[i], "-a")) { useAlignments = true; } else if (!strcmp(argv[i], "-c")) { reportCounts = true; } else usage(); } if(ttable == "") usage(); Moses::PhraseDictionaryTree ptree(nscores); ptree.UseWordAlignment(useAlignments); ptree.Read(ttable); std::string line; while(getline(std::cin, line)) { std::vector<std::string> srcphrase; srcphrase = Moses::Tokenize<std::string>(line); std::vector<Moses::StringTgtCand> tgtcands; std::vector<std::string> wordAlignment; if(useAlignments) ptree.GetTargetCandidates(srcphrase, tgtcands, wordAlignment); else ptree.GetTargetCandidates(srcphrase, tgtcands); if (reportCounts) { std::cout << line << " " << tgtcands.size() << "\n"; } else { for(uint i = 0; i < tgtcands.size(); i++) { std::cout << line << " |||"; for(uint j = 0; j < tgtcands[i].tokens.size(); j++) std::cout << ' ' << *tgtcands[i].tokens[j]; std::cout << " |||"; if(useAlignments) { std::cout << " " << wordAlignment[i] << " |||"; } for(uint j = 0; j < tgtcands[i].scores.size(); j++) std::cout << ' ' << tgtcands[i].scores[j]; std::cout << '\n'; } std::cout << '\n'; } std::cout.flush(); } }
int main(int argc, char * argv[]) { #ifndef _WIN32 printf("For now, only for Windows.\n"); return 1; #endif if (argc!=3) { printf("Too few parameters...\n%s SRCDIR DSTDIR\n",argv[0]); return 1;} folders=malloc(foldersAllocated*sizeof(char*)); files=malloc(filesAllocated*sizeof(char*)); char *srce=argv[1]; char *dest=argv[2]; removePathExcludedChars(srce); removePathExcludedChars(dest); DIR *dirp; char command[7680]; int ret; snprintf(command, 7680, "MOVE \"%s\" \"%s\" >NUL 2>NUL", srce, dest); if ((dirp = opendir(dest)) == NULL) if ((ret=system(command) != 0 )) // just rename src if dest folder not exist { printf("Error while renaming SRCDIR\n"); return ret;} else return 0; // rename successful, exit else closedir(dirp); // folder already exist, close it ptree(srce); // gather files and folders //remove duplicates and those already taken into account ( if there is "a\b\c\" we can skip "a\b\" ) int i=0; int j=0; again: for (i=0;i<currentNumberFolders-1;i++) for (j=i+1;j<currentNumberFolders;j++) { if ( folders[j]==NULL || folders[i]==NULL ) continue; if ( strstr(folders[i],folders[j]) ) {free(folders[j]);folders[j]=NULL; goto again;} if ( strstr(folders[j],folders[i]) ) {free(folders[i]);folders[i]=NULL; goto again;} } // rearrange pointers int count=0; for (i=0;i<currentNumberFolders;i++) if (folders[i]!=NULL) folders[count++]=folders[i]; // remove main folder from path int offset=strlen(srce)+1; for (i=0;i<count;i++) folders[i]=folders[i]+offset; #ifdef DEBUG //print files for (i=0;i<currentNumberFiles;i++) printf("%s\n",files[i]); #endif #ifdef DEBUG //print folders for (i=0;i<count;i++) printf("%s\n",folders[i]); #endif // create subfolders (if they already exists, nothing bad happens) for (i=0;i<count;i++) { snprintf(command, 7680, "MD \"%s\\%s\" >NUL 2>NUL", dest, folders[i]); system(command); } // move files for (i=0;i<currentNumberFiles;i++) { snprintf(command, 7680, "MOVE /Y \"%s\" \"%s\\%s\" >NUL 2>NUL", files[i], dest, files[i]+offset); #ifdef DEBUG printf("%s\n",command); #endif if ((ret=system(command)!= 0)) {printf("Error while moving file %s\n",files[i]); return ret;} } // still here, so everything is good, remove source dir snprintf(command, 7680, "RD /S /Q \"%s\" >NUL 2>NUL", srce); if ((ret=system(command) != 0)) {printf("Error while removing dir %s\n",srce); return ret;} return 0; }
static int ptree(char *path) { static char ep[260]; static struct stat st; static struct dirent *entryp; int epSize; DIR *dirp; char *p; if ((dirp = opendir(path)) == NULL) {printf("Can not open directory %s\n",path); _exit(1);} epSize=strlen(path); while ( (entryp=readdir(dirp)) != NULL ) { // do we care about . and .. ? Nope! if (strcmp(entryp->d_name, ".") == 0 || strcmp(entryp->d_name, "..") == 0) continue; // build path for new entry *(ep+epSize)=0; snprintf(ep, sizeof(ep), "%s/%s", path, entryp->d_name); while ((p=strchr(ep,'/'))) *p='\\'; // replace all slash to backslash // removes ".\" if any p=( (*ep=='.' && *(ep+1)=='\\') ? ep+2 : ep); if (stat(ep, &st) == -1) {printf("Can not stat %s\n",ep); _exit(1);} if (S_ISREG(st.st_mode)) { if ((++currentNumberFiles)>filesAllocated) { filesAllocated+=16384; files=(char**)realloc(files,filesAllocated*sizeof(char*)); } files[currentNumberFiles-1]=strdup(p); #ifdef DEBUG printf("F %s\n",p); #endif } else if (S_ISDIR(st.st_mode)) { if ((++currentNumberFolders)>foldersAllocated) { foldersAllocated+=4096; folders=(char**)realloc(folders,foldersAllocated*sizeof(char*)); } folders[currentNumberFolders-1]=strdup(p); #ifdef DEBUG printf("D %s\n",p); #endif ptree(ep); } } closedir(dirp); return 0; }
void ptree_name(int flags, struct node *np) { ptree(flags, np, 1, 0); }
void ptree_name_iter(int flags, struct node *np) { ptree(flags, np, 0, 0); }
int CNSRemoteJobControlApp::Run(void) { const CArgs& args = GetArgs(); IRWRegistry& reg = GetConfig(); if (args["q"]) { string queue = args["q"].AsString(); reg.Set(kNetScheduleAPIDriverName, "queue_name", queue); } if ( args["ns"]) { reg.Set(kNetScheduleAPIDriverName, "client_name", "ns_remote_job_control"); reg.Set(kNetScheduleAPIDriverName, "service", args["ns"].AsString()); reg.Set(kNetScheduleAPIDriverName, "use_permanent_connection", "true"); reg.Set(kNetScheduleAPIDriverName, "use_embedded_storage", "true"); } if ( args["nc"]) { reg.Set(kNetCacheAPIDriverName, "client_name", "ns_remote_job_control"); reg.Set(kNetCacheAPIDriverName, "service", args["nc"].AsString()); } auto_ptr<CNSInfoCollector> info_collector; CNcbiOstream* out = &NcbiCout; if (args["of"]) { out = &args["of"].AsOutputFile(); } CNetCacheAPI nc_api(reg); auto_ptr<CConfig::TParamTree> ptree(CConfig::ConvertRegToTree(reg)); const CConfig::TParamTree* ns_tree = ptree->FindSubNode(kNetScheduleAPIDriverName); if (!ns_tree) NCBI_THROW(CArgException, eInvalidArg, "Could not find \"" + string(kNetScheduleAPIDriverName) + "\" section"); CConfig ns_conf(ns_tree); string queue = ns_conf.GetString(kNetScheduleAPIDriverName, "queue_name", CConfig::eErr_NoThrow, ""); NStr::TruncateSpacesInPlace(queue); if (queue.empty()) queue = "noname"; string service = ns_conf.GetString(kNetScheduleAPIDriverName, "service", CConfig::eErr_NoThrow, ""); NStr::TruncateSpacesInPlace(service); if (service.empty()) NCBI_THROW(CArgException, eInvalidArg, "\"service\" parameter is not set " "neither in config file nor in cmd line"); info_collector.reset(new CNSInfoCollector(queue, service, nc_api)); if (args["stdout"]) { DumpStdStreams(args["stdout"], info_collector.get(), out, false); return 0; } if (args["stderr"]) { DumpStdStreams(args["stderr"], info_collector.get(), out, true); return 0; } auto_ptr<ITagWriter> writer; if (args["render"]) { string type = args["render"].AsString(); if(NStr::CompareNocase(type, "xml") == 0) writer.reset(new CXmlTagWriter(*out)); } if (!writer.get()) writer.reset(new CTextTagWriter(*out)); try { if (args["bid"]) { auto_ptr<CNSInfoRenderer> renderer(new CNSInfoRenderer(*writer, *info_collector)); string id = args["bid"].AsString(); renderer->RenderBlob(id); return 0; } CNSInfoRenderer::TFlags flags = 0; if (args["attr"]) { const CArgValue::TStringArray& strings = args["attr"].GetStringList(); CArgValue::TStringArray::const_iterator it; for( it = strings.begin(); it != strings.end(); ++it) { if (NStr::CompareNocase(*it, "minmal") == 0) flags = CNSInfoRenderer::eMinimal; if (NStr::CompareNocase(*it, "standard") == 0) flags = CNSInfoRenderer::eStandard; if (NStr::CompareNocase(*it, "full") == 0) flags = CNSInfoRenderer::eFull; if (NStr::CompareNocase(*it, "status") == 0) flags |= CNSInfoRenderer::eStatus; if (NStr::CompareNocase(*it, "progress") == 0) flags |= CNSInfoRenderer::eProgress; if (NStr::CompareNocase(*it, "retcode") == 0) flags |= CNSInfoRenderer::eRetCode; if (NStr::CompareNocase(*it, "cmdline") == 0) flags |= CNSInfoRenderer::eCmdLine; if (NStr::CompareNocase(*it, "stdin") == 0) flags |= CNSInfoRenderer::eStdIn; if (NStr::CompareNocase(*it, "stdout") == 0) flags |= CNSInfoRenderer::eStdOut; if (NStr::CompareNocase(*it, "stderr") == 0) flags |= CNSInfoRenderer::eStdErr; if (NStr::CompareNocase(*it, "raw_input") == 0) flags |= CNSInfoRenderer::eRawInput; if (NStr::CompareNocase(*it, "raw_output") == 0) flags |= CNSInfoRenderer::eRawOutput; } } auto_ptr<CNSInfoRenderer> renderer(new CNSInfoRenderer(*writer, *info_collector)); if (args["jid"]) { string jid = args["jid"].AsString(); renderer->RenderJob(jid, flags); } else if (args["wnlist"]) { renderer->RenderWNodes(flags); } else if (args["qlist"]) { renderer->RenderQueueList(); } else if (args["cancel"]) { string jid = args["cancel"].AsString(); info_collector->CancelJob(jid); } else if (args["cmd"]) { string cmd = args["cmd"].AsString(); if (NStr::CompareNocase(cmd, "shutdown_nodes") == 0) { CWNodeShutdownAction action(CNetScheduleAdmin::eShutdownImmediate); info_collector->TraverseNodes(action); } else if (NStr::CompareNocase(cmd, "kill_nodes") == 0) { CWNodeShutdownAction action(CNetScheduleAdmin::eDie); info_collector->TraverseNodes(action); } } } catch (exception& ex) { writer->WriteBeginTag("Error"); writer->WriteText(ex.what()); writer->WriteCloseTag("Error"); return 1; } catch (...) { writer->WriteTag("Error", "Unknown error"); return 2; } return 0; }