int Comando_Terminal_Local(int conexao,char *param,int tipo){ int ret; if(tipo==CD){ if(ret=cd(param)==-1) printf("Diretório inexistente ou sem acesso\n"); } else ls(param); if(param!=NULL) strcpy(param,""); return; }
int popd(Stack *in){ if(in->top == -1){ return EXIT_FAILURE; } else{ char *temp = in->stack[in->top--]; cd(temp); free(temp); return EXIT_SUCCESS; } }
QString Paths::resourceDir(const QString& file) { auto resourceDir = QDir(QGuiApplication::applicationDirPath()); #ifdef Q_OS_MAC resourceDir.cdUp(); resourceDir.cd("Resources"); #endif return resourceDir.filePath(file); }
TEST(CompressedMatrix, CopyConstructor) { CompressedMatrix<int> ci(3, 3); ci[0][0] = 1; ci[1][1] = 2; ci[2][2] = 3; CompressedMatrix<double> cd(ci); EXPECT_EQ(ci, cd); }
//This tests touch and creat //First test makes sure the mtime changes on a file that exists. //Returns 0 if the time isnt greater than what it was before. //Second test touches a file that doesnt exits, and therefore makes one. //Checks the inode of the new file, and if isn't what is expected, returns zero. //This second test checks both if touch and creat are working. int touchTest() { MINODE *test_mip = running->cwd; INODE *ip = NULL; int ino = 0; int old = 0; int expected1 = 28; strcpy(pathname, ""); cd(pathname); test_mip = running->cwd; printf("\n\n-------- TESTING TOUCH FUNCTION --------\n\n"); strcpy(pathname, "tiny"); ino = getino(test_mip, pathname); test_mip = iget(dev, ino); ip = &test_mip->INODE; old = ip->i_mtime; printf("tiny's current mtime = %d\n", ip->i_mtime); printf("Testing >touch tiny\n"); strcpy(pathname, "tiny"); touch_file(pathname); printf("tiny's new mtime = %d\n", ip->i_mtime); if(ip->i_mtime > old) printf("TEST PASSED!\n\n"); else { printf("TEST FAILED!\n\n"); return 0; } test_mip = running->cwd; printf("Testing >touch newfile\n"); strcpy(pathname, "newfile"); touch_file(pathname); strcpy(pathname, "newfile"); ino = getino(test_mip, pathname); printf("Expected ino of newfile = %d\n", expected1); printf("Actual ino of newfile = %d\n", ino); if (ino != expected1) { printf("TEST FAILED!\n\n"); return 0; } printf("TEST PASSED!\n\n"); printf("\nALL TOUCH TESTS PASSED!\n\n\n"); return 1; }
int pushd(int argc, char** argv) { if (top==MAX_DIRECTORY_STACK) { fprintf(stderr,"%s: cannot pushd: directory stack full\n",shellname); return 1; } else { dstack[top]=getcwd(malloc(PATH_MAX),PATH_MAX); // push current directory to stack top++; cd(argc,argv); // change to requested directory dirs(1,NULL); // stat stack status } return 0; }
//big ass switchy thingy int find_and_exec(const char * command_name, const char * parameters){ int ret; if(command_name == NULL){ return 0; } else if(strcmp(command_name,"pwd") == 0){ return pwd(); } else if(strcmp(command_name,"cd") == 0){ return cd(parameters); } else if(strcmp(command_name,"echo") == 0){ return echo(parameters); } else if(strcmp(command_name,"pushd") == 0){ return pushd(parameters); } else if(strcmp(command_name,"popd") == 0){ return popd(); } else if(strcmp(command_name,"exit") == 0){ exitc(parameters); } else if(strcmp(command_name,"set") == 0){ printf("Did you mean export? If you are looking for windows try your walls\n"); return 0; } else if(strcmp(command_name,"history") == 0){ print_stack_lines(history); return 0; } else if(strcmp(command_name,"unsetenv") == 0){ return unsetenv(parameters); } else { int pid = fork(); if(pid == -1){return 1;} else if(pid == 0){ if(parameters == NULL) { execlp(command_name,command_name,NULL); } else { execvp(command_name,split_spaces_cmd(command_name,parameters)); } } else { wait(&ret); return ret; } } return 0; }
QDir createTestDir() { auto tempDir = QDir::temp(); QProcess process; process.start("rm -rf " + tempDir.filePath("test")); process.waitForFinished(); tempDir.mkdir("test"); tempDir.cd("test"); return tempDir; }
void start(bool read_from_file) { cd(""); // let shell starts from home if(read_from_file){ // file processing functions should be called from here shell_loop(true); } else{ shell_loop(false); } }
int execute_non_forking(char **subcmd){ int retval; char *cmd = subcmd[0]; char **args = &subcmd[1]; if (strcmp(cmd, "exit") == 0) { retval = exit_shell(); } else if (strcmp(cmd, "cd") == 0) { retval = cd(args[0]); } else { retval = 2; } return retval; }
/** * Quash entry point * * @param argc argument count from the command line * @param argv argument vector from the command line * @return program exit status */ int main(int argc, char** argv) { command_t cmd; //< Command holder argument start(); struct sigaction NULL_sa; struct sigaction sa; sigset_t mask_set; sigfillset(&mask_set); sigdelset(&mask_set,SIGINT); sigdelset(&mask_set,SIGTSTP); sa.sa_handler = catchChild; sigprocmask(SIG_SETMASK, &mask_set, NULL); //TODO: this is involved withe the error 10 problem. Removing it remedies the issue for now but breaks other things. sigaction(SIGCHLD, &sa,NULL);//child termination calls catchChild; setenv( "WKDIR", getenv("HOME"), 1 ); puts("hOi! Welcome to Quash!"); // Main execution loop while (is_running()) { // NOTE: I would not recommend keeping anything inside the body of // this while loop. It is just an example. // The commands should be parsed, then executed. if( !get_command(&cmd, stdin) ); else if (!strcmp(cmd.cmdstr, "q")||!strcmp(cmd.cmdstr, "exit")||!strcmp(cmd.cmdstr, "quit")) terminate(); // Exit Quash else if(!strcmp(cmd.execArgs[0], "set")) set(cmd);//set environment variables else if(!strcmp(cmd.execArgs[0], "echo")) echo(cmd);//echos environment variables else if(!strcmp(cmd.execArgs[0], "pwd")) pwd(cmd);//prints current working directory else if(!strcmp(cmd.execArgs[0], "cd")) cd(cmd);//changes the working directory else if(!strcmp(cmd.execArgs[0], "jobs")) jobs();//prints out a list of currently running jobs else if(!strcmp(cmd.execArgs[0], "kill")) killChild(cmd);//kills specified job else if (!strcmp(cmd.execArgs[0], "wait")) sleep(atoi(cmd.execArgs[1])); else if (strchr(cmd.cmdstr,'|')!= NULL) exec_pipes(cmd);//executes piped commands else exec_cmd(cmd);//executes normal commands } return EXIT_SUCCESS; }
mkdir(char *dname){ //WORKS!!! char *FileName; struct NODE *temp; temp = cwd; strcpy(bname, basename(dname)); if(0 == strcmp(basename(dname), "/")){ // printf("cannot create directory '/'"); return 0; } if(!dname || bname[0] == '.' || bname[0] == '/'){ return 0; } char *character = dirname(dname); if(strcmp(character, ".")){ printf("%s\n", character); if(cd(&temp, character) == 0){ printf("mkdir: cannot create directory '%s': directory does not exist\n", dname); return 0; }; } // printf("%s ###: ", character); // pwd(temp); // printf(" ###\n"); // printf("Dir: '%s' File: '%s'\n",dname, bname); if(temp->childPtr == NULL){ temp->childPtr = (struct NODE *)malloc(sizeof(struct NODE)); strcpy(temp->childPtr->Name, bname); temp->childPtr->parentPtr = temp; strcpy(temp->childPtr->Type, "D"); } else{ temp = temp->childPtr; if(0 == strcmp(temp->Name, bname)){ printf("mkdir: cannot create directory '%s': directory exists\n", bname); return 0; } while(temp->siblingPtr != NULL){ temp = temp->siblingPtr; // printf("%s != %s\n", temp->Name, dname); if(0 == strcmp(temp->Name, bname)){ printf("mkdir: cannot create directory '%s': directory exists\n", dname); return 0; } } temp->siblingPtr = (struct NODE *)malloc(sizeof(struct NODE)); strcpy(temp->siblingPtr->Name, bname); temp->siblingPtr->parentPtr = temp->parentPtr; strcpy(temp->siblingPtr->Type, "D"); } //printf("Directory: %s Created.\n", dname); }
int main(int argc, char *argv[]) { char *delimiter_position = NULL; char *command = NULL; int i = 0; if (argc < 2) { while(1) { if (getcwd(current_work_path, sizeof(current_work_path)) == NULL) { break; } if (getlogin_r(user, sizeof(user)) != 0) { break; } sprintf(PS1, "%s:%s$ ", user, current_work_path); if (command != NULL) { free(command); command = NULL; } command = readline(PS1); if ((command != NULL) && (*command != '\0')) { add_history(command); } delimiter_position = strtok(command, " "); while (delimiter_position != NULL) { argv[i++] = delimiter_position; delimiter_position = strtok(NULL, " "); } argv[i] = NULL; i = 0; if (strcmp(argv[0], "quit") == 0) { break; } if (strcmp(argv[0], "cd") == 0) { cd(argv); continue; } execute(argv); } } else { readopt(argc, argv); } return 0; }
void MainWindow::connect2mysql() { ConnectDialog cd(this); cd.readSettings(); if ( cd.exec() == QDialog::Accepted ) { cd.writeSettings(); try { md = cd.getConnection(); QMessageBox::information(this, "Connected", "Connected to MYSQL!"); } catch ( std::exception & e ) { QMessageBox::warning(this, "Failed", e.what()); } } }
void PB_DS_CLASS_C_DEC:: copy_from_ordered_range(It first_it, It last_it, It other_first_it, It other_last_it) { clear(); const size_type len = std::distance(first_it, last_it) + std::distance(other_first_it, other_last_it); value_vector a_values = s_value_alloc.allocate(len); iterator target_it = a_values; It source_it = first_it; It source_end_it = last_it; cond_dtor<size_type> cd(a_values, target_it, len); while (source_it != source_end_it) { new (const_cast<void* >(static_cast<const void* >(target_it))) value_type(*source_it++); ++target_it; } source_it = other_first_it; source_end_it = other_last_it; while (source_it != source_end_it) { new (const_cast<void* >(static_cast<const void* >(target_it))) value_type(*source_it++); ++target_it; } reallocate_metadata((node_update* )this, len); cd.set_no_action(); m_a_values = a_values; m_size = len; m_end_it = m_a_values + m_size; update(PB_DS_node_begin_imp(), (node_update* )this); #ifdef _GLIBCXX_DEBUG const_iterator dbg_it = m_a_values; while (dbg_it != m_end_it) { map_debug_base::insert_new(PB_DS_V2F(*dbg_it)); dbg_it++; } PB_DS_CLASS_C_DEC::assert_valid(); #endif }
bool CacheManager::addEmptyEntry(const std::string& name) { if (entryExists(name)) { return false; } std::unique_ptr<CacheData> cd(new CacheData); cd->createEmpty(name, entry_counter_++); cache_map_[name] = std::move(cd); addDirectories(name); return true; }
void CacheManager::addDirectories(const std::string& path) { std::vector<std::string> path_list; path_list = TextUtil::MakePathList(path); if (path_list.empty()) { return; } for (const auto& it : path_list) { std::unique_ptr<CacheData> cd(new CacheData); cd->createDirectory(it, entry_counter_++); cache_map_[it] = std::move(cd); } }
void collision_detection::CollisionWorldFCL::checkRobotCollisionHelper(const CollisionRequest &req, CollisionResult &res, const CollisionRobot &robot, const robot_state::RobotState &state, const AllowedCollisionMatrix *acm) const { const CollisionRobotFCL &robot_fcl = dynamic_cast<const CollisionRobotFCL&>(robot); FCLObject fcl_obj; robot_fcl.constructFCLObject(state, fcl_obj); CollisionData cd(&req, &res, acm); cd.enableGroup(robot.getRobotModel()); for (std::size_t i = 0 ; !cd.done_ && i < fcl_obj.collision_objects_.size() ; ++i) manager_->collide(fcl_obj.collision_objects_[i].get(), &cd, &collisionCallback); if (req.distance) res.distance = distanceRobotHelper(robot, state, acm); }
int main(int argc, char** argv) { QApplication qapp(argc, argv); KComponentData cd("graphicsview-test"); Calligra::Sheets::Part part; Calligra::Sheets::Doc doc(&part); part.setDocument(&doc); bool ok = doc.openUrl(QUrl("/home/marijn/kde/src/calligra/docs/oos_AMSAT-IARU_Link_Model.ods")); if (!ok) { qDebug() << "failed to load"; return 0; } QFont font(KoGlobal::defaultFont()); Calligra::Sheets::CanvasItem* canvas = new Calligra::Sheets::CanvasItem(&doc); QRect usedArea = canvas->activeSheet()->usedArea(true); QFontMetricsF fm(font, 0); QSizeF size(canvas->activeSheet()->columnPosition(usedArea.right()+3), canvas->activeSheet()->rowPosition(usedArea.bottom()+5)); canvas->setDocumentSize(size); size = canvas->zoomHandler()->documentToView(size); canvas->resize(size); canvas->setPos(0, 0); Calligra::Sheets::ColumnHeaderItem* columnHeader = static_cast<Calligra::Sheets::ColumnHeaderItem*>(canvas->columnHeader()); static_cast<QGraphicsWidget*>(columnHeader)->resize(size.width(), fm.height() + 3); columnHeader->setPos(0, -columnHeader->height()); Calligra::Sheets::RowHeaderItem* rowHeader = static_cast<Calligra::Sheets::RowHeaderItem*>(canvas->rowHeader()); static_cast<QGraphicsWidget*>(rowHeader)->resize(fm.width(QString::fromLatin1("99999")) + 3, size.height()); rowHeader->setPos(-rowHeader->width(), 0); columnHeader->toolChanged("PanTool"); rowHeader->toolChanged("PanTool"); QGraphicsScene scene; scene.addItem(canvas); scene.addItem(columnHeader); scene.addItem(rowHeader); QGraphicsView view(&scene); view.show(); qapp.exec(); }
euint8 putty_cd(euint8* path) { SDfolder original;original = currDir;/*Backup*/ if(path[0]=='/') { //absolute address currDir = root;//move back to the root folder then we can begin strChomp(path); } else { //relative address } /*new we pass through the strings section by section attempting to move*/ printf("-->%s\n",path); char* tokens[20]; euint8 count = string_parser2(path,tokens); euint8 i=0; euint8 abort=0; for(i=0;i<count;i++) { printf("->%s\n", tokens[i]); if(abort==0) { if(cd( tokens[i])!=0) { abort=1; } free(tokens[i]); } if(abort==1) { currDir = original; return -1; } else return 0; } /*Removes the first char from a string*/ void strChomp(euint8* s) { euint32 i=0; for(i=1;i<strlen(s);i++) { s[i-1]=s[i]; } s[i-1]=0;//move the null }
void QMessage::appendAttachments(const QStringList &fileNames) { if (d_ptr->_message.multipartType() == QMailMessage::MultipartNone) { if (d_ptr->_message.hasBody()) { // Move the existing body to become the first part QMailMessageContentType ct(d_ptr->_message.contentType()); QString bodyText(d_ptr->_message.body().data()); QMailMessageContentDisposition cd(QMailMessageContentDisposition::Inline); cd.setSize(bodyText.length()); QMailMessagePart textPart(QMailMessagePart::fromData(bodyText, cd, ct, QMailMessageBody::Base64)); d_ptr->_message.setMultipartType(QMailMessage::MultipartMixed); d_ptr->_message.appendPart(textPart); } else { // Just set this message to be multipart d_ptr->_message.setMultipartType(QMailMessage::MultipartMixed); } } foreach (const QString &filename, fileNames) { QString mimeType(QMail::mimeTypeFromFileName(filename)); if (!mimeType.isEmpty()) { QFileInfo fi(filename); QMailMessageContentDisposition cd(QMailMessageContentDisposition::Attachment); cd.setFilename(fi.fileName().toAscii()); cd.setSize(fi.size()); QMailMessageContentType ct(mimeType.toAscii()); QMailMessagePart part(QMailMessagePart::fromFile(filename, cd, ct, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding)); d_ptr->_message.appendPart(part); } }
double collision_detection::CollisionRobotFCL::distanceSelfHelper(const planning_models::KinematicState &state, const AllowedCollisionMatrix *acm) const { FCLManager manager; allocSelfCollisionBroadPhase(state, manager); CollisionRequest req; CollisionResult res; CollisionData cd(&req, &res, acm); cd.enableGroup(getKinematicModel()); manager.manager_->distance(&cd, &distanceCallback); return res.distance; }
int check_built_in(char **command, int num_args, char **path_list, int *path_num) { if(cd(command, num_args) == 0) { return 0; } else if(pwd(command) == 0) { return 0; } else if(path(command, num_args, path_list, path_num) == 0) { return 0; } else { return 1; } }
HRESULT VFSExplorer::cdUp(ComPtr<IProgress> &aProgress) { Utf8Str strUpPath; { AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); /* Remove lowest dir entry in a platform neutral way. */ char *pszNewPath = RTStrDup(m->strPath.c_str()); RTPathStripTrailingSlash(pszNewPath); RTPathStripFilename(pszNewPath); strUpPath = pszNewPath; RTStrFree(pszNewPath); } return cd(strUpPath, aProgress); }
// //InspectCreatureDefMessage // int InspectCreatureDefMessage::handleMessage(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { int CDefID = GetInteger(&sim->readPtr[sim->ReadPos], sim->ReadPos); g_CharacterManager.GetThread("SimulatorThread::handle_inspectCreatureDef"); CharacterData *charData = g_CharacterManager.GetPointerByID(CDefID); g_CharacterManager.ReleaseThread(); if (charData != NULL) { /* Is a player, is it for a player in the current active instance? If so, we need * appearance modifiers so use the creature instance's calculated appearance. * * TODO Em - I don't really like this. It makes me wonder if modifiers should * be on the creature def. */ CreatureInstance* cInst = creatureInstance == NULL || creatureInstance->actInst == NULL ? NULL : creatureInstance->actInst->GetPlayerByCDefID( charData->cdef.CreatureDefID); if (cInst != NULL) { CreatureDefinition cd(charData->cdef); cd.css.SetAppearance(cInst->PeekAppearance().c_str()); cd.css.SetEqAppearance(cInst->PeekAppearanceEq().c_str()); return PrepExt_CreatureDef(sim->SendBuf, &cd); // std::string currentAppearance = charData->cdef.css.appearance; // std::string currentEqAppearance = charData->cdef.css.eq_appearance; // charData->cdef.css.SetAppearance(cInst->PeekAppearance().c_str()); // charData->cdef.css.SetEqAppearance(cInst->PeekAppearanceEq().c_str()); // // AttemptSend(SendBuf, PrepExt_CreatureDef(SendBuf, &charData->cdef)); // // charData->cdef.css.SetAppearance(currentAppearance.c_str()); // charData->cdef.css.SetEqAppearance(currentEqAppearance.c_str()); } else return PrepExt_CreatureDef(sim->SendBuf, &charData->cdef); } else { CreatureDefinition *target = CreatureDef.GetPointerByCDef(CDefID); if (target != NULL) return PrepExt_CreatureDef(sim->SendBuf, target); else g_Logs.simulator->warn( "[%d] inspectCreatureDef: could not find ID [%d]", sim->InternalID, CDefID); } return 0; }
void CommitDetailsTest::test_clear() { CommitDetails cd(nullptr, "//Root/Path/To/Node"); QVERIFY( !cd.hasOptions() ); QCOMPARE( cd.nodePath(), QString("//Root/Path/To/Node") ); cd.setOption("Option1", "OldVal", "NewVal"); QVERIFY( cd.hasOptions() ); cd.clear(); QVERIFY( !cd.hasOptions() ); QVERIFY( cd.nodePath().isEmpty() ); }
QDir CreateIfNotExists (QString path) { auto home = QDir::home (); path.prepend (".leechcraft/"); if (!home.exists (path) && !home.mkpath (path)) throw std::runtime_error (qPrintable (QObject::tr ("Could not create %1") .arg (QDir::toNativeSeparators (home.filePath (path))))); if (home.cd (path)) return home; else throw std::runtime_error (qPrintable (QObject::tr ("Could not cd into %1") .arg (QDir::toNativeSeparators (home.filePath (path))))); }
void playWithHomeTheaterFacade() { // Create all the parts of the home theatre system // Not encapsulated or owned by the facade. Amplifier amp("Top-O-Line Amplifier"); CdPlayer cd("Top-O-Line CD Player", &); DvdPlayer dvd("Top-O-Line DVD Player", &); Screen screen("My Theater Screen"); PopcornPopper popper("My Popcorn Popper"); Tuner tuner("Top-O-Line AM/FM Tuner", &); TheaterLights lights("Theater Ceiling Lights"); Projector projector("Top-O-Line Projector"); HomeTheaterFacade theater(&, &tuner, &dvd, &cd, &projector, &lights, &screen, &popper); theater.watchMovie("Raiders of the Lost Ark"); theater.endMovie(); }
/*************************************************************************** *Function : ce *RETURNS : None ***************************************************************************/ void ce() { int k=0; for(i=2; i<t; i++) { if(t%i == 0) continue; flag = prime(i); if(flag==1 && i!=p && i!=q) { e[k] = i; flag = cd(e[k]); if(flag > 0) d[k++] = flag; if(k == 99) break; } } }
int seg_intersection(const point &a, const point &b, const point &c, const point &d, point *p = NULL, point *q = NULL) { static const bool TOUCH_IS_INTERSECT = true; point ab(b.x - a.x, b.y - a.y); point ac(c.x - a.x, c.y - a.y); point cd(d.x - c.x, d.y - c.y); double c1 = cross(ab, cd), c2 = cross(ac, ab); if (EQ(c1, 0) && EQ(c2, 0)) { // Collinear. double t0 = dot(ac, ab) / sqnorm(ab); double t1 = t0 + dot(cd, ab) / sqnorm(ab); double mint = std::min(t0, t1), maxt = std::max(t0, t1); bool overlap = TOUCH_IS_INTERSECT ? (LE(mint, 1) && LE(0, maxt)) : (LT(mint, 1) && LT(0, maxt)); if (overlap) { point res1 = std::max(std::min(a, b), std::min(c, d)); point res2 = std::min(std::max(a, b), std::max(c, d)); if (res1 == res2) { if (p != NULL) { *p = res1; } return 0; // Collinear and meeting at an endpoint. } if (p != NULL && q != NULL) { *p = res1; *q = res2; } return 1; // Collinear and overlapping. } else { return -1; // Collinear and disjoint. } } if (EQ(c1, 0)) { return -1; // Parallel and disjoint. } double t = cross(ac, cd)/c1, u = c2/c1; bool t_between_01 = TOUCH_IS_INTERSECT ? (LE(0, t) && LE(t, 1)) : (LT(0, t) && LT(t, 1)); bool u_between_01 = TOUCH_IS_INTERSECT ? (LE(0, u) && LE(u, 1)) : (LT(0, u) && LT(u, 1)); if (t_between_01 && u_between_01) { if (p != NULL) { *p = point(a.x + t*ab.x, a.y + t*ab.y); } return 0; // Non-parallel with one intersection. } return -1; // Non-parallel with no intersections. }