void LevelUpdater::operator()(osg::Node *node, osg::NodeVisitor *nv) { double currentStepTime = viewer.getFrameStamp()->getSimulationTime(); // compensate error arising from the osg::Viewer resetting its SimulationTime if(currentStepTime - _previousStepTime < 0.0f) { Player::getInstance()->resetPosition(); ((LazyCameraManipulator *)viewer.getCameraManipulator())->resetCamera(); _previousStepTime = currentStepTime - 0.5; } int numSimulationSubSteps = _level->getPhysicsWorld()->stepSimulation(currentStepTime - _previousStepTime, (int)((currentStepTime - _previousStepTime) * 60.0f) + 1); ((LazyCameraManipulator *)viewer.getCameraManipulator())->setNumSimulationSubSteps(numSimulationSubSteps); _previousStepTime = currentStepTime; // player dies when falling too low { btVector3 position = Player::getInstance()->getController()->getGhostObject()->getWorldTransform().getOrigin(); int yBucketIndex = (int)(position.y() / 20.0f); if(yBucketIndex >= _level->getDeadlyAltitudes().size()) yBucketIndex = _level->getDeadlyAltitudes().size() - 1; float minimum = min(_level->getDeadlyAltitudes()[yBucketIndex], (_level->getDeadlyAltitudes())[yBucketIndex + 1]); if(position.z() < (minimum - 5.0f)) _level->playerDied(); } // fade out when level is finished osg::Vec4 constantBlendColor = _blendColor->getConstantColor(); float alpha = constantBlendColor.a(); // player reached finish { osg::Vec3 position = Player::getInstance()->getPosition(); std::vector<osg::Vec3> finishs = _level->getFinishs(); for(size_t i = 0; i < finishs.size(); i++) { float maxDistance = 1.0f; osg::Vec3 diff = position - finishs[i]; if(diff.x() < maxDistance && diff.x() > -maxDistance && diff.y() < maxDistance * 3.0f && diff.y() > -maxDistance && diff.z() < maxDistance && diff.z() > -maxDistance) { if(alpha == 1.0f) { alpha -= 0.01f; _level->getHeadUpDisplay()->stopTimer(); viewer.getEventHandlers().remove(_level->getKeyboardHandler()); ((LazyCameraManipulator *)viewer.getCameraManipulator())->fadeOut(); Player::getInstance()->getPlayerState()->setRequestAccelerate(false); Player::getInstance()->getPlayerState()->setRequestDecelerate(true); } } } if(alpha < 1.0f) { alpha -= 0.01f; if(alpha <= 0.0f) { alpha = 0.0f; _level->setReachedFinish(true); } constantBlendColor[3] = alpha; _blendColor->setConstantColor(constantBlendColor); } } traverse(node, nv); }
//BEGIN MAIN int main (int argc, char *arg[]) { char *userInput; //what the user types in size_t buffer = 128; //sets buffer for getline() char **tokens; //array of pointers to tokens of command typed int numTokens; //the number of tokens in input command tokens = (char **)malloc(sizeof(char *) * 128); //mallocs tokens with a max number of 128 //---------------------------------------------------------------------------------------------- //BEGIN PROGRAM WHILE LOOP while(1) { printf("COMMAND> "); //print prompt to user userInput = (char *)malloc(sizeof(char) * 128); //malloc for userInput before tokenizing getline(&userInput, &buffer, stdin);// get user input userInput[strcspn(userInput, "\n")] = '\0'; //removes null character from end of user input //---Tokenize the user input char *point; int count; for(count = 0, point = strtok(userInput, " "); point != NULL; count++, point = strtok(NULL, " ")) { tokens[count] = (char *)malloc(strlen(point) + 1); strcpy(tokens[count], point); } //END tokenizing loop numTokens = count; //sets the number of token var equal to the number of actual tokens //---Check for output redirection and handle output if so int outputFile, consoleOutput; fflush(stdout); //clear stdout as a precaution int i; //counter for output redirection loop for(i = 0; i < numTokens; i++) { if(strcmp(tokens[i], ">") == 0) { //Output redirection outputFile = open(tokens[i+1], O_WRONLY | O_CREAT | O_TRUNC, 0644); consoleOutput = dup(STDOUT_FILENO); //Copy original STDOUT if(outputFile) { dup2(outputFile, STDOUT_FILENO); close(outputFile); } break; //break out of output redirection loop } } //END output redirection for loop //---QUIT COMMAND - quit the program if(strcmp(tokens[0], "quit") == 0) { break; }//END QUIT COMMAND //---HELP COMMAND - print the help menu else if(strcmp(tokens[0], "help") == 0) { printf("\nWelcome to the floppy program!\n"); printf("Here is a list of commands supported...\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("help - prints the help menu (You just did this!)\n"); printf(" usage: help\n"); printf("~\n"); printf("fmount - mounts a floppy image\n"); printf(" usage: fmount [floppyname]\n"); printf("~\n"); printf("fumount - unmounts the mounted floppy image\n"); printf(" usage: fumount\n"); printf("~\n"); printf("structure - lists the stucture of the floppy\n"); printf(" usage: structure\n"); printf("~\n"); printf("traverse - lists the content in the root directory\n"); printf(" usage: traverse\n"); printf("~\n"); printf("traverse -l - with the -l flag, the traverse command outputs more detailed info\n"); printf(" usage: traverse -l\n"); printf("~\n"); printf("showsector - show the content (in a hex dump) of the provided sector number\n"); printf(" usage: showsector [sectornumber]\n"); printf("~\n"); printf("showfat - show the content of the FAT table (in a hex dump)\n"); printf(" usage: showfat\n"); printf("~\n"); printf(">>>THIS PROGRAM SUPPORTS OUTPUT REDIRECTION<<<\n"); printf("\n"); }//END HELP COMMAND //---FMOUNT COMMAND - mounts the floppy else if(strcmp(tokens[0], "fmount") == 0) { int mounted; if(numTokens < 2) { printf("ERROR: INCORRECT USAGE - see help menu\n"); continue; } else { mount(tokens[1]); mounted = checkMount(); if(mounted < 0) { printf("ERROR: COULD NOT MOUNT FLOPPY\n"); } else { printf("%s is mounted!\n", tokens[1]); } } } //END FMOUNT COMMAND //---FUMOUNT FUNCTION - unmounts the floppy else if(strcmp(tokens[0], "fumount") == 0) { int mounted; mounted = checkMount(); if(mounted < 0) { printf("ERROR: THERE IS NO MOUNTED FLOPPY\n"); continue; } else { unmount(); printf("You have unmounted the floppy...\n"); } }//END FUMOUNT COMMAND //---STRUCTURE COMMAND - displays the structure of the floppy else if(strcmp(tokens[0], "structure") == 0) { int mounted; mounted = checkMount(); if(mounted < 0) { printf("ERROR: THERE IS NO MOUNTED FLOPPY\n"); continue; } else { structure(); } }//END STRUCTURE COMMAND //---TRAVERSE AND TRAVERSE -L COMMANDS else if(strcmp(tokens[0], "traverse") == 0) { int mounted; mounted = checkMount(); if(mounted < 0) { printf("ERROR: THERE IS NO MOUNTED FLOPPY\n"); continue; } else if(strcmp(tokens[1], "-l") == 0) { traverse(1); } else { traverse(0); } } //END TRAVERSE AND TRAVERSE -L COMMANDS //---SHOWSECTOR COMMAND else if(strcmp(tokens[0], "showsector") == 0) { int mounted; mounted = checkMount(); if(mounted < 0) { printf("ERROR: THERE IS NO MOUNTED FLOPPY\n"); continue; } else if(numTokens < 2) { printf("ERROR: INCORRECT USAGE - see help menu\n"); continue; } else { int sectorNumber = atoi(tokens[1]); showsector(sectorNumber); } } //END SHOWSECTOR COMMAND //---SHOWFAT COMMAND else if(strcmp(tokens[0], "showfat") == 0) { int mounted; mounted = checkMount(); if(mounted < 0) { printf("ERROR: THERE IS NO MOUNTED FLOPPY\n"); continue; } else { showfat(); } } //END SHOWFAT COMMAND //---Put output back to default (the console) (in case output redirection was used) fflush(stdout); //clear stdout as a precaution if(consoleOutput) { dup2(consoleOutput, STDOUT_FILENO); close(consoleOutput); } //END reset the output to console //---Free up userInput and tokens[] free(userInput); int j; for (j = 0; j < numTokens; j++) { free(tokens[j]); }//END freeing of userInput and tokens[] } //END PROGRAM WHILE LOOP return 1; //RETURN VALUE FOR main() } //END MAIN
/* Procedure typeCheck performs type checking * by a postorder syntax tree traversal */ void Analyze::typeCheck( TreeNode *syntaxTree ) { traverse( syntaxTree, nullProc, checkNode ); }
pathname(const Arena& arena) {traverse(arena);} // Traverse ancestors
int main() { int i,j,k; int l,m,n,o,bc,flag=0,count1=0,x=0,count2=0,row=0,count3=0,col=0,col2=0,prevcount=0,count5=0,size1=2,size2=3; int cancount=0,lk,lm,count11=0; int arr1[3],arr2[3],arr3[3]; int ab,div1,div2,count10=0,initial=0,initial2=0,candicount=0,prevcount1=0; for(i=1;i<=size;i++) { for(j=1;j<=size;j++) { headarray[i][j]=NULL; } } scanf("%d",&size); memset(check, 0, (sizeof check[0][0])*size*size); memset(notin, 0, (sizeof notin[0][0])*size*size); memset(see, 0, (sizeof see[0][0])*size*size); // taking sudoku input for(i=1;i<=(size*size);i++) { for(j=1;j<=(size*size);j++) { scanf("%d",&arr[i][j]); if(arr[i][j]==0) count++; } } traverse(); // updating missing no matrix cross(); // crosshatching candidatelist(); // preparing candidate list rule1(); // rule1 while(1) { prevcount1=count; rule1(); // rule1 rule2_box(); //rule2 for box rule2_row(); // rule2 column rule2_col(); // rule 2 for row rule1(); // rule 1 rule3(); // rule 3 rule2_box(); //rule2 for box rule2_row(); rule2_col(); rule4(); // rule 4 if(prevcount1==count) break; } for(i=1;i<=size*size;i++) { for(j=1;j<=size*size;j++) { printf("%d ",arr[i][j]); } printf("\n"); } return 0; }
void Node::animate() { traverse("animate"); }
int sumRootToLeaf(TreeNode* root) { return traverse(root, 0); }
static Iter begin(Node *root) { return Iter(traverse(root, [](int *_) ->void* { return new ValueContinue(nullptr, nullptr); })); }
void VisitorGetTransformationNode::visit(TransformationNodeModel* transformationNode) { if(m_foundNode == nullptr && transformationNode->getKey() == m_nodeToFind) m_foundNode = transformationNode; else traverse(transformationNode); }
Column_Space * Column_Space::col_space_at_index(int index) { Column_Space * col; traverse(col, this, 0, index); return col; }
static int chdirec(vnode_t *vp, int ischroot, int do_traverse) { int error; vnode_t *oldvp; proc_t *pp = curproc; vnode_t **vpp; refstr_t *cwd; int newcwd = 1; if (vp->v_type != VDIR) { error = ENOTDIR; goto bad; } if (error = VOP_ACCESS(vp, VEXEC, 0, CRED(), NULL)) goto bad; /* * The VOP_ACCESS() may have covered 'vp' with a new filesystem, * if 'vp' is an autoFS vnode. Traverse the mountpoint so * that we don't end up with a covered current directory. */ if (vn_mountedvfs(vp) != NULL && do_traverse) { if (error = traverse(&vp)) goto bad; } /* * Special chroot semantics: chroot is allowed if privileged * or if the target is really a loopback mount of the root (or * root of the zone) as determined by comparing dev and inode * numbers */ if (ischroot) { struct vattr tattr; struct vattr rattr; vnode_t *zonevp = curproc->p_zone->zone_rootvp; tattr.va_mask = AT_FSID|AT_NODEID; if (error = VOP_GETATTR(vp, &tattr, 0, CRED(), NULL)) goto bad; rattr.va_mask = AT_FSID|AT_NODEID; if (error = VOP_GETATTR(zonevp, &rattr, 0, CRED(), NULL)) goto bad; if ((tattr.va_fsid != rattr.va_fsid || tattr.va_nodeid != rattr.va_nodeid) && (error = secpolicy_chroot(CRED())) != 0) goto bad; vpp = &PTOU(pp)->u_rdir; } else { vpp = &PTOU(pp)->u_cdir; } if (audit_active) /* update abs cwd/root path see c2audit.c */ audit_chdirec(vp, vpp); mutex_enter(&pp->p_lock); /* * This bit of logic prevents us from overwriting u_cwd if we are * changing to the same directory. We set the cwd to NULL so that we * don't try to do the lookup on the next call to getcwd(). */ if (!ischroot && *vpp != NULL && vp != NULL && VN_CMP(*vpp, vp)) newcwd = 0; oldvp = *vpp; *vpp = vp; if ((cwd = PTOU(pp)->u_cwd) != NULL && newcwd) PTOU(pp)->u_cwd = NULL; mutex_exit(&pp->p_lock); if (cwd && newcwd) refstr_rele(cwd); if (oldvp) VN_RELE(oldvp); return (0); bad: VN_RELE(vp); return (error); }
int ls_main(int argc, char *argv[]) { static char dot[] = ".", *dotav[] = { dot, NULL }; struct winsize win; int ch, fts_options; #if !defined(HAVE_TNFTPD_H) int notused; #endif int kflag = 0; const char *p; setlocale(LC_ALL, ""); /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { if ((p = getenv("COLUMNS")) != NULL) termwidth = atoi(p); else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && win.ws_col > 0) termwidth = win.ws_col; f_column = f_nonprint = 1; } else f_singlecol = 1; /* Root is -A automatically. */ if (!getuid()) f_listdot = 1; fts_options = FTS_PHYSICAL; while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklmnopqrstux")) != -1) { switch (ch) { /* * The -1, -C, -l, -m and -x options all override each other so * shell aliasing works correctly. */ case '1': f_singlecol = 1; f_column = f_columnacross = f_longform = f_stream = 0; break; case 'C': f_column = 1; f_columnacross = f_longform = f_singlecol = f_stream = 0; break; case 'l': f_longform = 1; f_column = f_columnacross = f_singlecol = f_stream = 0; break; case 'm': f_stream = 1; f_column = f_columnacross = f_longform = f_singlecol = 0; break; case 'x': f_columnacross = 1; f_column = f_longform = f_singlecol = f_stream = 0; break; /* The -c and -u options override each other. */ case 'c': f_statustime = 1; f_accesstime = 0; break; case 'u': f_accesstime = 1; f_statustime = 0; break; case 'F': f_type = 1; break; case 'L': fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL; break; case 'R': f_recursive = 1; break; case 'a': fts_options |= FTS_SEEDOT; /* FALLTHROUGH */ case 'A': f_listdot = 1; break; /* The -d option turns off the -R option. */ case 'd': f_listdir = 1; f_recursive = 0; break; case 'f': f_nosort = 1; break; case 'g': /* Compatibility with 4.3BSD. */ break; case 'i': f_inode = 1; break; case 'k': blocksize = 1024; kflag = 1; break; case 'n': f_numericonly = 1; break; case 'o': f_flags = 1; break; case 'p': f_typedir = 1; break; case 'q': f_nonprint = 1; break; case 'r': f_reversesort = 1; break; case 'S': sortkey = BY_SIZE; break; case 's': f_size = 1; break; case 'T': f_sectime = 1; break; case 't': sortkey = BY_TIME; break; case 'W': f_whiteout = 1; break; default: case '?': usage(); } } argc -= optind; argv += optind; /* * If not -F, -i, -l, -p, -S, -s or -t options, don't require stat * information. */ if (!f_inode && !f_longform && !f_size && !f_type && !f_typedir && sortkey == BY_NAME) fts_options |= FTS_NOSTAT; /* * If not -F, -d or -l options, follow any symbolic links listed on * the command line. */ if (!f_longform && !f_listdir && !f_type) fts_options |= FTS_COMFOLLOW; /* * If -W, show whiteout entries */ #ifdef FTS_WHITEOUT if (f_whiteout) fts_options |= FTS_WHITEOUT; #endif /* If -l or -s, figure out block size. */ if (f_inode || f_longform || f_size) { #if defined(HAVE_TNFTPD_H) blocksize = 1024; #else /* !defined(HAVE_TNFTPD_H) */ if (!kflag) (void)getbsize(¬used, &blocksize); blocksize /= 512; #endif /* !defined(HAVE_TNFTPD_H) */ } /* Select a sort function. */ if (f_reversesort) { switch (sortkey) { case BY_NAME: sortfcn = revnamecmp; break; case BY_SIZE: sortfcn = revsizecmp; break; case BY_TIME: if (f_accesstime) sortfcn = revacccmp; else if (f_statustime) sortfcn = revstatcmp; else /* Use modification time. */ sortfcn = revmodcmp; break; } } else { switch (sortkey) { case BY_NAME: sortfcn = namecmp; break; case BY_SIZE: sortfcn = sizecmp; break; case BY_TIME: if (f_accesstime) sortfcn = acccmp; else if (f_statustime) sortfcn = statcmp; else /* Use modification time. */ sortfcn = modcmp; break; } } /* Select a print function. */ if (f_singlecol) printfcn = printscol; else if (f_columnacross) printfcn = printacol; else if (f_longform) printfcn = printlong; else if (f_stream) printfcn = printstream; else printfcn = printcol; if (argc) traverse(argc, argv, fts_options); else traverse(1, dotav, fts_options); exit(rval); /* NOTREACHED */ }
void xml_compiler::url_loader::traverse(const extracted_ptree& pt) const { for (const auto& it : pt) { if (it.get_tag_name() != "vkopenurldef") { if (!it.children_empty()) { traverse(it.children_extracted_ptree()); } } else { std::shared_ptr<url> newurl(new url()); if (!newurl) continue; // ---------------------------------------- bool error = false; for (const auto& child : it.children_extracted_ptree()) { if (child.get_tag_name() == "name") { newurl->set_name(pqrs::string::remove_whitespaces_copy(child.get_data())); if (!boost::starts_with(*(newurl->get_name()), "KeyCode::VK_OPEN_URL_")) { error = true; xml_compiler_.error_information_.set(boost::format("<name> within <vkopenurldef> must start with \"KeyCode::VK_OPEN_URL_\":\n\n<name>%1%</name>") % *(newurl->get_name())); } } else if (child.get_tag_name() == "url") { newurl->set_url(boost::trim_copy(child.get_data())); auto type = child.get_optional("<xmlattr>.type"); if (type) { newurl->set_type(boost::trim_copy(*type)); } } else if (child.get_tag_name() == "background") { newurl->set_background(true); } } if (error) { continue; } // ---------------------------------------- // Validation // name if (!newurl->get_name()) { xml_compiler_.error_information_.set(boost::format("No <name> within <%1%>.") % it.get_tag_name()); continue; } if (newurl->get_name()->empty()) { xml_compiler_.error_information_.set(boost::format("Empty <name> within <%1%>.") % it.get_tag_name()); continue; } // url if (!newurl->get_url()) { xml_compiler_.error_information_.set(boost::format("No <url> within <%1%>.") % it.get_tag_name()); continue; } if (newurl->get_url()->empty()) { xml_compiler_.error_information_.set(boost::format("Empty <url> within <%1%>.") % it.get_tag_name()); continue; } // ---------------------------------------- // register to symbol_map_. if (!symbol_map_.get_optional(*(newurl->get_name()))) { auto keycode = symbol_map_.add("KeyCode", boost::replace_first_copy(*(newurl->get_name()), "KeyCode::", "")); vk_open_url_map_[keycode] = newurl; } } } }
void main () { int n = __VERIFIER_nondet_int(); node_t* head = init_nondet_ll(n); traverse(head); }
void Node::commit() { traverse("commit"); }
/** * seq_read - ->read() method for sequential files. * @file: the file to read from * @buf: the buffer to read to * @size: the maximum number of bytes to read * @ppos: the current position in the file * * Ready-made ->f_op->read() */ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) { struct seq_file *m = file->private_data; size_t copied = 0; loff_t pos; size_t n; void *p; int err = 0; mutex_lock(&m->lock); /* * seq_file->op->..m_start/m_stop/m_next may do special actions * or optimisations based on the file->f_version, so we want to * pass the file->f_version to those methods. * * seq_file->version is just copy of f_version, and seq_file * methods can treat it simply as file version. * It is copied in first and copied out after all operations. * It is convenient to have it as part of structure to avoid the * need of passing another argument to all the seq_file methods. */ m->version = file->f_version; /* Don't assume *ppos is where we left it */ if (unlikely(*ppos != m->read_pos)) { while ((err = traverse(m, *ppos)) == -EAGAIN) ; if (err) { /* With prejudice... */ m->read_pos = 0; m->version = 0; m->index = 0; m->count = 0; goto Done; } else { m->read_pos = *ppos; } } /* grab buffer if we didn't have one */ if (!m->buf) { m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); if (!m->buf) goto Enomem; } /* if not empty - flush it first */ if (m->count) { n = min(m->count, size); err = copy_to_user(buf, m->buf + m->from, n); if (err) goto Efault; m->count -= n; m->from += n; size -= n; buf += n; copied += n; if (!m->count) m->index++; if (!size) goto Done; } /* we need at least one record in buffer */ pos = m->index; p = m->op->start(m, &pos); while (1) { err = PTR_ERR(p); if (!p || IS_ERR(p)) break; err = m->op->show(m, p); if (err < 0) break; if (unlikely(err)) m->count = 0; if (unlikely(!m->count)) { p = m->op->next(m, p, &pos); m->index = pos; continue; } if (m->count < m->size) goto Fill; m->op->stop(m, p); kfree(m->buf); m->count = 0; m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); if (!m->buf) goto Enomem; m->version = 0; pos = m->index; p = m->op->start(m, &pos); } m->op->stop(m, p); m->count = 0; goto Done; Fill: /* they want more? let's try to get some more */ while (m->count < size) { size_t offs = m->count; loff_t next = pos; p = m->op->next(m, p, &next); if (!p || IS_ERR(p)) { err = PTR_ERR(p); break; } err = m->op->show(m, p); if (seq_overflow(m) || err) { m->count = offs; if (likely(err <= 0)) break; } pos = next; } m->op->stop(m, p); n = min(m->count, size); err = copy_to_user(buf, m->buf, n); if (err) goto Efault; copied += n; m->count -= n; if (m->count) m->from = n; else pos++; m->index = pos; Done: if (!copied) copied = err; else { *ppos += copied; m->read_pos += copied; } file->f_version = m->version; mutex_unlock(&m->lock); return copied; Enomem: err = -ENOMEM; goto Done; Efault: err = -EFAULT; goto Done; }
void Node::finalize(RenderContext &ctx) { traverse(ctx, "render"); }
virtual void apply(osg::Geode &geode) { for (unsigned int i = 0; i < geode.getNumDrawables(); ++i) { tessellateDemoGeometry *geom = dynamic_cast<tessellateDemoGeometry*>(geode.getDrawable(i)); if (geom) { if (!geom->getBoundaryOnly()) // turn on bounds only { // NB this shows only the true boundary of the curves, no internal edges geom->setBoundaryOnly(true); } else // change to next type of tessellation... { geom->setBoundaryOnly(false); switch (geom->getWindingType()) { case osgUtil::Tessellator::TESS_WINDING_ODD: geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO); break; case osgUtil::Tessellator::TESS_WINDING_NONZERO: geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); break; case osgUtil::Tessellator::TESS_WINDING_POSITIVE: geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_NEGATIVE); break; case osgUtil::Tessellator::TESS_WINDING_NEGATIVE: geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); break; case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO: geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD); break; } } switch (geom->getWindingType()) // a text to be added to the scene. { case osgUtil::Tessellator::TESS_WINDING_ODD: str = "TESS_WINDING_ODD"; break; case osgUtil::Tessellator::TESS_WINDING_NONZERO: str = "TESS_WINDING_NONZERO"; break; case osgUtil::Tessellator::TESS_WINDING_POSITIVE: str = "TESS_WINDING_POSITIVE"; break; case osgUtil::Tessellator::TESS_WINDING_NEGATIVE: str = "TESS_WINDING_NEGATIVE"; break; case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO: str = "TESS_WINDING_ABS_GEQ_TWO"; break; } if (geom->getBoundaryOnly()) str += " Boundary"; geom->retessellatePolygons(*geom); } osgText::Text *txt = dynamic_cast<osgText::Text*>(geode.getDrawable(i)); if (txt) { const osg::Vec4 &ct = txt->getColor(); // pick the text to be changed by its color if (ct.z() < 0.9) { txt->setText(str.c_str()); } } } traverse(geode); }
void Node::traverse(const std::string &operation) { RenderContext ctx; traverse(ctx, operation); }
/* ARGSUSED */ static int zfsctl_snapdir_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp, int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, int *direntflags, pathname_t *realpnp) { zfsctl_snapdir_t *sdp = dvp->v_data; objset_t *snap; char snapname[MAXNAMELEN]; char real[MAXNAMELEN]; char *mountpoint; zfs_snapentry_t *sep, search; struct mounta margs; vfs_t *vfsp; size_t mountpoint_len; avl_index_t where; zfsvfs_t *zfsvfs = dvp->v_vfsp->vfs_data; int err; /* * No extended attributes allowed under .zfs */ if (flags & LOOKUP_XATTR) return (EINVAL); ASSERT(dvp->v_type == VDIR); /* * If we get a recursive call, that means we got called * from the domount() code while it was trying to look up the * spec (which looks like a local path for zfs). We need to * add some flag to domount() to tell it not to do this lookup. */ if (MUTEX_HELD(&sdp->sd_lock)) return (ENOENT); ZFS_ENTER(zfsvfs); if (gfs_lookup_dot(vpp, dvp, zfsvfs->z_ctldir, nm) == 0) { ZFS_EXIT(zfsvfs); return (0); } if (flags & FIGNORECASE) { boolean_t conflict = B_FALSE; err = dmu_snapshot_realname(zfsvfs->z_os, nm, real, MAXNAMELEN, &conflict); if (err == 0) { nm = real; } else if (err != ENOTSUP) { ZFS_EXIT(zfsvfs); return (err); } if (realpnp) (void) strlcpy(realpnp->pn_buf, nm, realpnp->pn_bufsize); if (conflict && direntflags) *direntflags = ED_CASE_CONFLICT; } mutex_enter(&sdp->sd_lock); search.se_name = (char *)nm; if ((sep = avl_find(&sdp->sd_snaps, &search, &where)) != NULL) { *vpp = sep->se_root; if (VN_HOLD(*vpp) == NULL) { *vpp = NULL; err = EAGAIN; } else { err = traverse(vpp); if (err) { VN_RELE(*vpp); *vpp = NULL; } else if (*vpp == sep->se_root) { /* * The snapshot was unmounted behind our backs, * try to remount it. */ goto domount; } else { /* * VROOT was set during the traverse call. We need * to clear it since we're pretending to be part * of our parent's vfs. */ (*vpp)->v_flag &= ~VROOT; } } mutex_exit(&sdp->sd_lock); ZFS_EXIT(zfsvfs); return (err); } /* * The requested snapshot is not currently mounted, look it up. */ err = zfsctl_snapshot_zname(dvp, nm, MAXNAMELEN, snapname); if (err) { mutex_exit(&sdp->sd_lock); ZFS_EXIT(zfsvfs); /* * handle "ls *" or "?" in a graceful manner, * forcing EILSEQ to ENOENT. * Since shell ultimately passes "*" or "?" as name to lookup */ return (err == EILSEQ ? ENOENT : err); } if (dmu_objset_hold(snapname, FTAG, &snap) != 0) { mutex_exit(&sdp->sd_lock); ZFS_EXIT(zfsvfs); return (ENOENT); } sep = kmem_alloc(sizeof (zfs_snapentry_t), KM_SLEEP); sep->se_name = kmem_alloc(strlen(nm) + 1, KM_SLEEP); (void) strcpy(sep->se_name, nm); *vpp = sep->se_root = zfsctl_snapshot_mknode(dvp, dmu_objset_id(snap)); avl_insert(&sdp->sd_snaps, sep, where); dmu_objset_rele(snap, FTAG); domount: mountpoint_len = strlen(refstr_value(dvp->v_vfsp->vfs_mntpt)) + strlen("/.zfs/snapshot/") + strlen(nm) + 1; mountpoint = kmem_alloc(mountpoint_len, KM_SLEEP); (void) snprintf(mountpoint, mountpoint_len, "%s/.zfs/snapshot/%s", refstr_value(dvp->v_vfsp->vfs_mntpt), nm); margs.spec = snapname; margs.dir = mountpoint; margs.flags = MS_SYSSPACE | MS_NOMNTTAB; margs.fstype = "zfs"; margs.dataptr = NULL; margs.datalen = 0; margs.optptr = NULL; margs.optlen = 0; err = domount("zfs", &margs, *vpp, kcred, &vfsp); kmem_free(mountpoint, mountpoint_len); if (err == 0) { /* * Return the mounted root rather than the covered mount point. * Takes the GFS vnode at .zfs/snapshot/<snapname> and returns * the ZFS vnode mounted on top of the GFS node. This ZFS * vnode is the root of the newly created vfsp. */ VFS_RELE(vfsp); err = traverse(vpp); } if (err == 0) { /* * Fix up the root vnode mounted on .zfs/snapshot/<snapname>. * * This is where we lie about our v_vfsp in order to * make .zfs/snapshot/<snapname> accessible over NFS * without requiring manual mounts of <snapname>. */ ASSERT(VTOZ(*vpp)->z_zfsvfs != zfsvfs); VTOZ(*vpp)->z_zfsvfs->z_parent = zfsvfs; (*vpp)->v_vfsp = zfsvfs->z_vfs; (*vpp)->v_flag &= ~VROOT; } mutex_exit(&sdp->sd_lock); ZFS_EXIT(zfsvfs); /* * If we had an error, drop our hold on the vnode and * zfsctl_snapshot_inactive() will clean up. */ if (err) { VN_RELE(*vpp); *vpp = NULL; } return (err); }
int main( int argc, char ** argv ) { /* Vars */ uint i, j, k; node block; /* check to make sure an input file was supplied */ /* get the number of blocks (the first line of input) */ /* I am just assuming that the input will always be */ /* correct since this is for a competition */ if( argc == 2) get_num_blocks(argv[1]); else exit(EXIT_FAILURE); /* Initialize the graph and cycles arrays */ /* The graph array is an incidence matrix */ /* if graph(i,j) is true, then there is a */ /* directed edge from i -> j */ for( i = 0; i < SIZE; ++i ) { for( j = 0; j < SIZE; ++j ) { graph[i][j] = NO_CONN; } } /* Get the input blocks */ for( i = 0; i < num_blocks; ++i ) { /* for each block... */ if( get_block( &block ) > 2 ) { /* if the block has more than 2 '00' terms then just skip it */ /* if the block has 3 or 4 sides with '00' terms then it */ /* cannot connect to anything so it doesn't matter */ continue; } /* else // block has less than 2 zeros */ /* if a block matches itself, then the structure is unbounded */ /* We wouldn't have to do this, but it is a simple enough check */ /* and as n -> 40,000 it can save a lot of time */ for( k = 0; k < 4; ++k ) { for( j = 0; j < 4; ++j ) { if( block[k*2] == block[j*2] && block[k*2+1] != block[j*2+1] ) goto unbounded; } } /* else // block does not match itself */ /* add links to the graph */ for( j = 0; j < 4; ++j ) { /* For each side... */ /* assume correct formatting so only need to test first block for if 0 */ if( block[j*2] == '0' ) { /* no links can be added */ continue; } else { for( k = 0; k < 4; ++k ) { /* for every other side on the block... */ if( j == k ) /* same side we are already on, so continue */ continue; else if( block[k*2] == '0' ) /* side is 00 so continue */ continue; /* else add link */ /* The basic idea for the links is, add a directed edge */ /* between the opposite of that side (i.d. opposite of */ /* P- is P+) to each of the other sides on the block. */ /* This is because if you can connect to the current */ /* side of the block (i.d. block[j*2]) then you will */ /* connect with the opposite of this block, and it will */ /* connect you to any of the other sides of the current */ /* block. */ /* The problem is actually pretty nice since you can */ /* rotate and reflect, the geometry of the block doesnt */ /* actually matter. */ if( block[j*2+1] == '+' ) graph[ NEGATIVE( block[j*2] ) ][ to_index( &block[k*2] ) ] = 1; /* else the block is negative */ else graph[ POSITIVE( block[j*2] ) ][ to_index( &block[k*2] ) ] = 1; } } } /* turn on __DEBUG__ if you want to see the graph */ print_graph(); } /* graph is all set up, just check for cycles */ if( traverse() ) goto unbounded; /* U mad bro? */ /* if we made it here then it is a bounded structure */ printf("bounded\n"); exit(EXIT_SUCCESS); unbounded: printf("unbounded\n"); exit(EXIT_SUCCESS); } /**~ end main ~**/
void QueapTree<T>::traverseTree() { traverse(root_, &QueapTree<T>::displayNode); }
vector<vector<int> > levelOrderBottom(TreeNode *root) { vector<vector<int>> result; traverse(root, 1, result); std::reverse(result.begin(), result.end()); return result; }
int64_t tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *p) { return traverse(tdb, F_WRLCK, fn, p); }
virtual void apply(osg::Node& node) { apply(node.getStateSet()); traverse(node); }
QList<KBookmark> KBookmarkGroupList::getList( const KBookmarkGroup &grp ) { traverse(grp); return m_list; }
int ls_main(int argc, char *argv[]) { static char dot[] = ".", *dotav[] = { dot, NULL }; struct winsize win; int ch, fts_options, notused; int kflag = 0; char *p; /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { if ((p = getenv("COLUMNS")) != NULL) termwidth = atoi(p); else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && win.ws_col > 0) termwidth = win.ws_col; f_column = f_nonprint = 1; } else { f_singlecol = 1; /* retrieve environment variable, in case of explicit -C */ if ((p = getenv("COLUMNS")) != NULL) termwidth = atoi(p); } /* Root is -A automatically. */ if (!getuid()) f_listdot = 1; fts_options = FTS_PHYSICAL; while ((ch = getopt(argc, argv, "1ACFHLRSTacdfghiklmnopqrstux")) != -1) { switch (ch) { /* * The -1, -C and -l, -m, -n and -x options all override each * other so shell aliasing works right. */ case '1': f_singlecol = 1; f_column = f_columnacross = f_longform = 0; f_numericonly = f_stream = 0; break; case 'C': f_column = 1; f_columnacross = f_longform = f_numericonly = 0; f_singlecol = f_stream = 0; break; case 'g': f_longform = 1; if (f_grouponly != -1) f_grouponly = 1; f_column = f_columnacross = f_singlecol = f_stream = 0; break; case 'l': f_longform = 1; f_grouponly = -1; /* -l always overrides -g */ f_column = f_columnacross = f_singlecol = f_stream = 0; break; case 'm': f_stream = 1; f_column = f_columnacross = f_longform = 0; f_numericonly = f_singlecol = 0; break; case 'x': f_columnacross = 1; f_column = f_longform = f_numericonly = 0; f_singlecol = f_stream = 0; break; case 'n': f_longform = 1; f_numericonly = 1; f_column = f_columnacross = f_singlecol = f_stream = 0; break; /* The -c and -u options override each other. */ case 'c': f_statustime = 1; f_accesstime = 0; break; case 'u': f_accesstime = 1; f_statustime = 0; break; case 'F': f_type = 1; break; case 'H': fts_options |= FTS_COMFOLLOW; break; case 'L': fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL; break; case 'R': f_recursive = 1; break; case 'a': fts_options |= FTS_SEEDOT; /* FALLTHROUGH */ case 'A': f_listdot = 1; break; /* The -d option turns off the -R option. */ case 'd': f_listdir = 1; f_recursive = 0; break; case 'f': f_nosort = 1; break; case 'h': f_humanval = 1; break; case 'i': f_inode = 1; break; case 'k': blocksize = 1024; kflag = 1; break; case 'o': f_flags = 1; break; case 'p': f_typedir = 1; break; case 'q': f_nonprint = 1; break; case 'r': f_reversesort = 1; break; case 'S': sortkey = BY_SIZE; break; case 's': f_size = 1; break; case 'T': f_sectime = 1; break; case 't': sortkey = BY_TIME; break; default: usage(); } } argc -= optind; argv += optind; /* * If both -g and -l options, let -l take precedence. * This preserves compatibility with the historic BSD ls -lg. */ if (f_grouponly == -1) f_grouponly = 0; /* * If not -F, -i, -l, -p, -S, -s or -t options, don't require stat * information. */ if (!f_longform && !f_inode && !f_size && !f_type && !f_typedir && sortkey == BY_NAME) fts_options |= FTS_NOSTAT; /* * If not -F, -d or -l options, follow any symbolic links listed on * the command line. */ if (!f_longform && !f_listdir && !f_type) fts_options |= FTS_COMFOLLOW; /* If -l or -s, figure out block size. */ if (f_longform || f_size) { if (!kflag) (void)getbsize(¬used, &blocksize); blocksize /= 512; } /* Select a sort function. */ if (f_reversesort) { switch (sortkey) { case BY_NAME: sortfcn = revnamecmp; break; case BY_SIZE: sortfcn = revsizecmp; break; case BY_TIME: if (f_accesstime) sortfcn = revacccmp; else if (f_statustime) sortfcn = revstatcmp; else /* Use modification time. */ sortfcn = revmodcmp; break; } } else { switch (sortkey) { case BY_NAME: sortfcn = namecmp; break; case BY_SIZE: sortfcn = sizecmp; break; case BY_TIME: if (f_accesstime) sortfcn = acccmp; else if (f_statustime) sortfcn = statcmp; else /* Use modification time. */ sortfcn = modcmp; break; } } /* Select a print function. */ if (f_singlecol) printfcn = printscol; else if (f_columnacross) printfcn = printacol; else if (f_longform) printfcn = printlong; else if (f_stream) printfcn = printstream; else printfcn = printcol; if (argc) traverse(argc, argv, fts_options); else traverse(1, dotav, fts_options); return (rval); }
void Node::verify() { traverse(VerifyNodes{false}); }
int main() { int ar[11] = {14,4,3,9,7,5,15,18,16,17,30}; node* root = NULL; stack<node*> *st_primary = new stack<node*>(); stack<node*> *st_secondry = new stack<node*>(); for (int i = 0; i < 11;i++) { if (root == NULL) { root = new node(ar[i]); st_primary->push(root); continue; } node * mainelem = st_primary->pop(); while (mainelem->data > ar[i]) { st_secondry->push(mainelem); if (st_primary->size() > 0) { mainelem = st_primary->pop(); } else if (st_primary->size() == 0) { mainelem = st_secondry->pop(); break; } } if (mainelem->data > ar[i]) { if (mainelem->left == NULL) { node * n1 = new node(ar[i]); mainelem->left = n1; st_primary->push(n1); st_primary->push(mainelem); copystack(st_secondry,st_primary); } else if (mainelem->left != NULL) { st_primary->push(mainelem); mainelem = st_secondry->pop(); node * n1 = new node(ar[i]); if (mainelem->data > ar[i] ) { if (mainelem->left != NULL) { printf("\n ----logic break 11 left--\n");fflush(stdout); } else { mainelem->left = n1; st_primary->push(n1); st_primary->push(mainelem); copystack(st_secondry, st_primary); } } else if (mainelem->data < ar[i]) { if (mainelem->right != NULL) { printf("\n ----logic break 11 rpte --\n");fflush(stdout); } else { mainelem->right = n1; st_primary->push(mainelem); st_primary->push(n1); copystack(st_secondry, st_primary); } } } } else if (mainelem->data < ar[i]) { if (mainelem->right == NULL) { node * n1 = new node(ar[i]); mainelem->right = n1; st_primary->push(mainelem); st_primary->push(n1); copystack(st_secondry,st_primary); } else if (mainelem->right != NULL) { st_primary->push(mainelem); mainelem = st_secondry->pop(); node *n1 = new node(ar[i]); if (mainelem->data > ar[i]) { if (mainelem->left != NULL) { printf("\n ------loginc brealk lpointer \n");fflush(stdout); } else { mainelem->left = n1; st_primary->push(n1); st_primary->push(mainelem); copystack(st_secondry, st_primary); } } else if (mainelem->data < ar[i]) { if (mainelem->right != NULL) { printf("\n --------logic break rpointer \n");fflush(stdout); } else { mainelem->right = n1; st_primary->push(mainelem); st_primary->push(n1); copystack(st_secondry, st_primary); } } } } } //for traverse(root); }
int main(int argc, char *argv[]) { size_t path_len, total_files; off_t bytes_wasted, total_wasted; char path_buffer[PATH_MAX_LEN], *hash_value; struct file_entry_t *file_entry, *trie_entry; SListIterator slist_iterator; SetIterator set_iterator; /* Step 0: Session data */ struct file_info_t file_info; clear_info(&file_info); /* Step 1: Parse arguments */ while (--argc) { /* Being unable to record implies insufficient resources */ if (!record(argv[argc], &file_info)){ fprintf(stderr, "[FATAL] out of memory\n"); destroy_info(&file_info); return (EXIT_FAILURE); } } /* Step 2: Fully explore any directories specified */ #ifndef NDEBUG printf("[DEBUG] Creating file list...\n"); #endif while (slist_length(file_info.file_stack) > 0) { /* Pick off the top of the file stack */ file_entry = (struct file_entry_t *)(slist_data(file_info.file_stack)); slist_remove_entry(&file_info.file_stack, file_info.file_stack); assert(file_entry->type == DIRECTORY); /* Copy the basename to a buffer */ memset(path_buffer, '\0', PATH_MAX_LEN); path_len = strnlen(file_entry->path, PATH_MAX_LEN); memcpy(path_buffer, file_entry->path, path_len); /* Ignore cases that would cause overflow */ if (path_len < PATH_MAX_LEN) { /* Append a trailing slash */ path_buffer[path_len] = '/'; /* Record all contents (may push onto file stack or one of the lists) */ DIR *directory = opendir(file_entry->path); if (traverse(&file_info, directory, path_buffer, ++path_len)) { fprintf(stderr, "[FATAL] out of memory\n"); destroy_info(&file_info); return (EXIT_FAILURE); } else if (closedir(directory)) { fprintf(stderr, "[WARNING] '%s' (close failed)\n", file_entry->path); } } /* Discard this entry */ destroy_entry(file_entry); } /* Step 3: Warn about any ignored files */ if (slist_length(file_info.bad_files) > 0) { slist_iterate(&file_info.bad_files, &slist_iterator); while (slist_iter_has_more(&slist_iterator)) { file_entry = slist_iter_next(&slist_iterator); fprintf(stderr, "[WARNING] '%s' ", file_entry->path); switch (file_entry->type) { case INVALID: ++file_info.invalid_files; fprintf(stderr, "(invalid file)\n"); break; case INACCESSIBLE: ++file_info.protected_files; fprintf(stderr, "(protected file)\n"); break; default: ++file_info.irregular_files; fprintf(stderr, "(irregular file)\n"); break; } } fprintf(stderr, "[WARNING] %lu file(s) ignored\n", (long unsigned)(num_errors(&file_info))); } #ifndef NDEBUG if (num_errors(&file_info) > 0) { fprintf(stderr, "[FATAL] cannot parse entire file tree\n"); destroy_info(&file_info); return (EXIT_FAILURE); } printf("[DEBUG] Found %lu / %lu valid files\n", (unsigned long)(num_files(&file_info)), (unsigned long)(file_info.total_files)); #endif /* Step 4: Begin the filtering process */ #ifndef NDEBUG printf("[DEBUG] Creating file table...\n"); #endif if (slist_length(file_info.good_files) > 0) { file_info.hash_trie = trie_new(); file_info.shash_trie = trie_new(); optimize_filter(&file_info); /* Extract each file from the list (they should all be regular) */ slist_iterate(&file_info.good_files, &slist_iterator); while (slist_iter_has_more(&slist_iterator)) { file_entry = slist_iter_next(&slist_iterator); assert(file_entry->type == REGULAR); /* Perform a "shallow" hash of the file */ hash_value = hash_entry(file_entry, SHALLOW); #ifndef NDEBUG printf("[SHASH] %s\t*%s\n", file_entry->path, hash_value); #endif /* Check to see if we might have seen this file before */ if (bloom_filter_query(file_info.shash_filter, hash_value)) { /* Get the full hash of the new file */ hash_value = hash_entry(file_entry, FULL); #ifndef NDEBUG printf("[+HASH] %s\t*%s\n", file_entry->path, hash_value); #endif archive(&file_info, file_entry); /* Check to see if bloom failed us */ trie_entry = trie_lookup(file_info.shash_trie, file_entry->shash); if (trie_entry == TRIE_NULL) { #ifndef NDEBUG printf("[DEBUG] '%s' (false positive)\n", file_entry->path); #endif trie_insert(file_info.shash_trie, file_entry->shash, file_entry); } else { /* Get the full hash of the old file */ hash_value = hash_entry(trie_entry, FULL); #ifndef NDEBUG if (hash_value) { printf("[-HASH] %s\t*%s\n", trie_entry->path, hash_value); } #endif archive(&file_info, trie_entry); } } else { /* Add a record of this shash to the filter */ bloom_filter_insert(file_info.shash_filter, hash_value); trie_insert(file_info.shash_trie, hash_value, file_entry); } } persist("bloom_store", &file_info); } /* Step 5: Output results and cleanup before exit */ printf("[EXTRA] Found %lu sets of duplicates...\n", (unsigned long)(slist_length(file_info.duplicates))); slist_iterate(&file_info.duplicates, &slist_iterator); for (total_files = total_wasted = bytes_wasted = 0; slist_iter_has_more(&slist_iterator); total_wasted += bytes_wasted) { Set *set = slist_iter_next(&slist_iterator); int size = set_num_entries(set); if (size < 2) { continue; } printf("[EXTRA] %lu files (w/ same hash):\n", (unsigned long)(size)); set_iterate(set, &set_iterator); for (bytes_wasted = 0; set_iter_has_more(&set_iterator); bytes_wasted += file_entry->size, ++total_files) { file_entry = set_iter_next(&set_iterator); printf("\t%s (%lu bytes)\n", file_entry->path, (unsigned long)(file_entry->size)); } } printf("[EXTRA] %lu bytes in %lu files (wasted)\n", (unsigned long)(total_wasted), (unsigned long)(total_files)); destroy_info(&file_info); return (EXIT_SUCCESS); }