//---------------------------------------------------------------------- void FFileDialog::cb_processActivate (FWidget*, FDataPtr) { if ( filename.getText().includes('*') || filename.getText().includes('?') ) { setFilter(filename.getText()); readDir(); filebrowser.redraw(); } else if ( filename.getText().getLength() == 0 ) { setFilter("*"); readDir(); filebrowser.redraw(); } else if ( filename.getText().trim() == FString("..") || filename.getText().includes('/') || filename.getText().includes('~') ) { changeDir(filename.getText().trim()); } else { bool found = false; if ( ! dir_entries.empty() ) { const auto& input = filename.getText().trim(); for (auto&& entry : dir_entries) { if ( entry.name && input && ! input.isNull() && std::strcmp(entry.name, input) == 0 && entry.directory ) { found = true; changeDir(input); break; } } } if ( ! found ) done (FDialog::Accept); } }
void Camera::rotateView(float x, float y) { float thetaX = -y*right.x + x*up.x; float thetaY = -y*right.y + x*up.y; float thetaZ = -y*right.z + x*up.z; if(cameraMode == FREEROAM_CAMERA) { vec3 newDir = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(dir, 1)); changeDir(newDir); } else if(cameraMode == MODELVIEWER_CAMERA) { pos = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(pos - viewCenter, 1)) + viewCenter; //Rotate position around center float pos_length = length(pos-viewCenter); vec3 _dir = normalize(pos-viewCenter); /*if (abs(_dir.y) > maxY) { if (_dir.y < 0) _dir.y = -maxY; else _dir.y = maxY; float s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z)); _dir.x *= s; _dir.z *= s; _dir = normalize(_dir); pos = viewCenter+_dir*pos_length; }*/ if ((_dir.y > maxY) || (_dir.y < minY)) { float s = 1.f; if (_dir.y > maxY) { _dir.y = maxY; s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z)); } else if (_dir.y < minY) { _dir.y = minY; s = sqrt((1 - minY*minY) / (_dir.x*_dir.x + _dir.z*_dir.z)); } dir.x *= s; _dir.z *= s; _dir = normalize(_dir); pos = viewCenter + _dir*pos_length; } changeDir(normalize(viewCenter-pos)); } }
void testNavigate(){ int check, nextX, nextY; initDir(); //start by getting the initial direction solution = createStack(); push(solution, current); // add the starting square to the stack while (current->val != 'F'){ // the maze sloving loop printf("current position: (%d, %d)\ncurrent direction: %c\n",current->x, current->y,dir); switch(dir){ case 'n': check = checkUp(); nextX = current->x; nextY = current->y - 1; break; case 's': check = checkDown(); nextX = current->x; nextY = current->y + 1; break; case 'e': check = checkRight(); nextX = current->x + 1; nextY = current->y; break; case 'w': check = checkLeft(); nextX = current->x - 1; nextY = current->y; break; } if (check == 1){ // if you can move, the next space is not a wall printf("the square ahead is not a wall!\n"); if (maze[nextX][nextY]->wasHere == 1){ //we have been there already printf("we have been here before!\n"); if (otherOptions(nextX, nextY) == 1){ // there are other options printf("we have other options, lets turn\n"); changeDir(); printf("new direction: %c\n",dir); } else { // no other options will need to go back to where we have been printf("we have no other options we must go this way\n"); pop(solution); // pop from stack current->deadEnd = 1; current = maze[nextX][nextY]; // move } } else { printf("we have not been here before, lets go!\n"); current = maze[nextX][nextY]; // move current-> wasHere = 1; push(solution, current); // add to stack } } else { printf("the square ahead is a wall, we must change directions\n"); changeDir(); printf("new direction: %c\n",dir); } char c = getchar(); } }
void navigate(){ int check, nextX, nextY; initDir(); //start by getting the initial direction solution = createStack(); push(solution, current); // add the starting square to the stack while (current->val != 'F'){ // the maze sloving loop switch(dir){ case 'n': check = checkUp(); nextX = current->x; nextY = current->y - 1; break; case 's': check = checkDown(); nextX = current->x; nextY = current->y + 1; break; case 'e': check = checkRight(); nextX = current->x + 1; nextY = current->y; break; case 'w': check = checkLeft(); nextX = current->x - 1; nextY = current->y; break; } if (check == 1){ // if you can move, the next space is not a wall if (maze[nextX][nextY]->wasHere == 1){ //we have been there already if (otherOptions(nextX, nextY) == 1){ // there are other options changeDir(); } else { // no other options will need to go back to where we have been pop(solution); // pop from stack current->deadEnd = 1; current = maze[nextX][nextY]; // move } } else { current = maze[nextX][nextY]; // move current-> wasHere = 1; push(solution, current); // add to stack } } else { changeDir(); } } }
// loads the full system path to the given file or directory to fpath int getFullPath(char *fpath, struct state *cstate, struct config *configuration, char *dirname) { if (strstr(dirname, "..")) { return (-1); } // the name is determined by absolute path // only joins root if (dirname[0] == '/') { if (strncpy(fpath, configuration->root_dir, PATH_LENGTH - 1) == NULL) return (-1); fpath[PATH_LENGTH - 1] = '\0'; if (strncat(fpath, dirname, PATH_LENGTH - 1) == NULL) return (-1); return (0); } // relative path // joins root, cwd and dirname if (strncpy(fpath, configuration->root_dir, PATH_LENGTH - 1) == NULL) return (-1); fpath[PATH_LENGTH - 1] = '\0'; if (strncat(fpath, cstate->path, PATH_LENGTH - 1) == NULL) return (-1); if ((fpath = changeDir(fpath, dirname)) == NULL) return (-1); return (0); }
// changes the working directory void cwd(char **params, short *abor, int fd, struct state *cstate, struct config *configuration) { if (!cstate->logged) { respond(fd, 5, 3, 0, "Not logged in."); return; } if (params[0] == NULL) { respond(fd, 5, 0, 4, "Need directory name."); return; } char old_path[PATH_LENGTH]; char dir[PATH_LENGTH]; strncpy(old_path, cstate->path, PATH_LENGTH - 1); old_path[PATH_LENGTH - 1] = '\0'; // loads the full path to the given directory into dir variable if (getFullPath(dir, cstate, configuration, params[0]) == -1) { respond(fd, 4, 5, 1, "Internal server error."); return; } // checks the directory existence if (isDir(dir) == -1) { respond(fd, 4, 5, 1, "Directory does not exist."); return; } // changes the "chrooted" part of path if (changeDir(cstate->path, params[0]) == NULL) { strcpy(cstate->path, old_path); respond(fd, 4, 5, 1, "Internal server error."); return; } respond(fd, 2, 5, 7, cstate->path); }
/* -------------------------------------------------- Function to run through the built in commands. Will return 1 if it found one, 0 otherwise. -------------------------------------------------- */ int checkBuiltIn(){ //exit simply flips the flag indicating we should not continue in the main loop if(strcmp(CARGV[0], "exit") == 0){ CONT = 0; return 1; } //cd will call a separate function. if(strcmp(CARGV[0], "cd") == 0){ changeDir(); return 1; } //status prints a message depending on the value of eStatus. if(strcmp(CARGV[0], "status") == 0){ if(STATUS == NULL){ printf("No message to print.\n"); } else { if(eStatus == 2){ printf(" terminated by signal 2\n"); }else{ printf("exit value: %u\n", WEXITSTATUS(eStatus)); } } return 1; } return 0; }
void pacmanRound() { switch (pacman.dir) { case UP: if (map[pacman.mapY + 1][pacman.mapX] != 0) clearPerson(map, pacman.mapX, pacman.mapY + 1); clearPerson(map, pacman.mapX, pacman.mapY); handleUp(); break; case DOWN: if (map[pacman.mapY - 1][pacman.mapX] != 0) clearPerson(map, pacman.mapX, pacman.mapY - 1); clearPerson(map, pacman.mapX, pacman.mapY); handleDown(); break; case LEFT: if (map[pacman.mapY][pacman.mapX + 1] != 0) clearPerson(map, pacman.mapX + 1, pacman.mapY); clearPerson(map, pacman.mapX, pacman.mapY); handleLeft(); break; case RIGHT: if (map[pacman.mapY][pacman.mapX - 1] != 0) clearPerson(map, pacman.mapX - 1, pacman.mapY); clearPerson(map, pacman.mapX, pacman.mapY); handleRight(); break; } changeDir(); drawPacman((int)pacman.screenX, (int)pacman.screenY, pacman.dir); }
APIRET fsChDir(ServerData * pServerData, struct chdir * pchdir) { if (VERIFYFIXED(pchdir->cdfsi.cdi_curdir)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "FS_CHDIR, flag=%d, cdfsi.dir=%s, cdfsi.flags=%d", pchdir->fsFlag, pchdir->cdfsi.cdi_curdir, pchdir->cdfsi.cdi_flags); switch (pchdir->fsFlag) { case CD_EXPLICIT: return changeDir(pServerData, pchdir); case CD_VERIFY: return verifyDir(pServerData, pchdir); case CD_FREE: return freeDir(pServerData, pchdir); default: logMsg(L_EVIL, "unknown FS_CHDIR flag: %d", pchdir->fsFlag); return ERROR_NOT_SUPPORTED; } }
QString Repository::Git::GitUtils::makeTmpFileFromCommand( QString command, QString filepath ) { bool ok = true; // Ulozim si current working directory QString cwd = QDir::currentPath(); // Nastavim absolutnu cestu k temp file ako template a zakazem automaticke mazanie QTemporaryFile tempFile; tempFile.setFileTemplate( QDir::toNativeSeparators( QDir::tempPath() + "/" + "qXXXXXX" ) ); tempFile.setAutoRemove( false ); // Ak sa nepodarilo vytvorit temp subor, tak nastavim flag "ok" na false a vypisem chybu if ( !tempFile.open() ) { qDebug() << "Nepodarilo sa vytvorit tmp subor"; ok = false; } // Ak sa podarilo vytvorit temp subor, tak zmenim current working directory if ( ok ) { ok = changeDir( filepath ); } // Ak sa podarilo zmenit current working directory, tak skontroluje existenciu git repozitara if ( ok ) { ok = existGit( filepath ); } // Ak existuje na danej ceste git repozitar, tak vykonam command a vystup ulozim do temp suboru if ( ok ) { QProcess process; process.setStandardOutputFile( QDir::toNativeSeparators( tempFile.fileName() ) ); process.start( command ); process.waitForFinished(); process.close(); process.terminate(); } // Vratim povodny current working directory, ak sa nepodari zmenit, vypisem do konzoly if ( !changeDir( cwd ) ) { qDebug() << "Nepodarilo sa vratit na povodny current working directory"; } // Vratim absolutnu cestu k temp suboru return tempFile.fileName(); }
INT_PTR TdlgMiscPage::msgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CHB_DLG_SHOWHINTS: parent->enableHints(!!getCheck(IDC_CHB_DLG_SHOWHINTS)); return TRUE; case IDC_CBX_LANG: if (HIWORD(wParam) == CBN_SELCHANGE) { const char_t *newlang = cbxGetCurText(IDC_CBX_LANG); if (newlang[0]) { int langint = (int)cbxGetCurItemData(IDC_CBX_LANG); if (langint == 20554/*JP*/ || langint == 16714/*JA*/) #ifdef UNICODE langint = 16714; // JA Unicode #else langint = 20554; // JP ANSI #endif Twindow::cfgSet(IDFF_lang, text<char_t>((const char*)&langint)); parent->translate(); } return TRUE; } break; case IDC_BT_PATH_DSCALER: if (HIWORD(wParam) == BN_CLICKED) { if (changeDir(IDFF_dscalerPath, _(-IDD_DLGMISC, _l("Select directory with installed DScaler")))) { paths2dlg(); } return TRUE; } break; case IDC_BT_PATH_FFDSHOW: if (HIWORD(wParam) == BN_CLICKED) { if (changeDir(IDFF_installPath, _(-IDD_DLGMISC, _l("Select ffdshow instalation directory")))) { paths2dlg(); } return TRUE; } break; } break; } return TconfPageBase::msgProc(uMsg, wParam, lParam); }
int main(){ //Signal handling: signal(SIGINT, signalHandler); char** argv; int numOfArgs = 0; std::vector<std::string> cmdHistory = {}; std::string command = ""; std::chrono::duration<double> totalTimeInChildProcesses(0); char ptime[] = "ptime"; char carat[] = "^"; char pwd[] = "pwd"; char history[] = "history"; char cd[] = "cd"; while ((command=commandPrompt()) != "exit"){ //Try if there are things in the command. try{ checkIfBlank(command); //Store every Command. storeCommand(cmdHistory, command); //Parse the commands numOfArgs = parseCommand(command, argv); if (strcmp(carat, argv[0]) == 0){ if (numOfArgs == 3){ runNthCmdInHistory(cmdHistory, argv, command); }else{ std::string error = "Error: incorrect number of arguments for '^ <history item>'."; throw error; } } if (strcmp(ptime, argv[0]) == 0){ std::cout<<"Time spent executing child processes: " << totalTimeInChildProcesses.count() <<"seconds\n"; }else if (strcmp(history, argv[0]) == 0){ listHistory(cmdHistory); }else if(strcmp(cd, argv[0]) == 0){ if (numOfArgs == 3){ changeDir(argv); }else{ std::string error = "Error: incorrect number of arguments for 'cd <directory>'."; throw error; } }else if(strcmp(pwd, argv[0]) == 0){ std::cout<<get_current_dir_name()<<std::endl; }else if(isPipeCmd(command)){ pipe(command, totalTimeInChildProcesses); }else{ runAndTimeChildProcess(argv[0], argv, totalTimeInChildProcesses); } }catch(std::string e){ std::cout<<e<<std::endl; } } return 0; }
void QMathMLFileViewer::readSettings( QSettings& settings ) { QString path = settings.value("FmlIde/mmlfileviewer/dir", QVariant(QDir::currentPath())).toString(); changeDir( path ); //if( m_dirTree ) // m_dirTree->setCurrentIndex( m_dirModel.index( m_currentDir.absolutePath() ) ); setRecursive(settings.value("FmlIde/mmlfileviewer/recursive", QVariant(true)).toBool()); if( btnRecursive ) btnRecursive->setChecked( isRecursive() ); }
Camera::Camera(vec3 _dir, vec3 _up, vec3 _pos) : up(_up), pos(_pos), cameraMode(FREEROAM_CAMERA), distance(5.f), lag(0.f) { changeDir(_dir); }
Camera::Camera(vec3 _dir, vec3 _up, vec3 _pos, int _cameraMode) : up(_up), pos(_pos), cameraMode(_cameraMode), distance(5.f), lag(0.f) { changeDir(_dir); }
//---------------------------------------------------------------------- void FFileDialog::cb_processClicked (FWidget*, FDataPtr) { const uLong n = uLong(filebrowser.currentItem() - 1); if ( dir_entries[n].directory ) changeDir(dir_entries[n].name); else done (FDialog::Accept); }
void Camera::changeViewCenter(vec3 _viewCenter) { vec3 diff = _viewCenter - viewCenter; viewCenter = _viewCenter; pos = pos + diff; printf("viewCenter - (%f, %f, %f)\n", viewCenter.x, viewCenter.y, viewCenter.z); changeDir(viewCenter - pos); }
void Camera::rotateViewAround(float x, float y) { float thetaX = -y*right.x + x*up.x; float thetaY = -y*right.y + x*up.y; float thetaZ = -y*right.z + x*up.z; pos = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY)* vec4(pos - viewCenter, 1) )+ viewCenter; //Rotate position around center changeDir(viewCenter-pos); }
void caller(){ char buffer[BUFFER]; char currWDir[BUFFER]; int err; char *token; token = strtok(buffer," \t"); while(1){ bzero(buffer, BUFFER); prompt(); fgets(buffer, BUFFER, stdin); if(compare(buffer, "cd") == 0){ token = strchr(buffer,' '); if(token != NULL){ token += 1; *strchr(token,'\n')='\0'; // printf("here\n"); changeDir(token); }else{ chdir("/home"); } }else if(compare(buffer,"mkdir") == 0){ makeDir(buffer); }else if(compare(buffer,"pwd") == 0){ getcwd(currWDir, BUFFER); printf("%s\n", currWDir); }else if(compare(buffer,"rmdir") == 0){ remDir(buffer); }else if(compare(buffer,"ls") == 0){ token = strtok(buffer," \t"); char *token2 = strtok(NULL," \t"); if(token2 == NULL){ listDir(); }else if(compare(token2, "-l") == 0){ listDirL(); }else{ printf("Command not recognized!\n"); } }else if(compare(buffer, "exit") == 0){ exit(0); }else if(compare(buffer, "cp") == 0){ token = strtok(buffer," \t"); char *src = strtok(NULL," \t"); char *dest = strtok(NULL," \t"); copy(src, dest); }else{ exec(buffer); exit(1); } } }
void exeCommand(char *input) { char *command = strtok(input, " \0"); int otherCommands; do { otherCommands = 0; if (command == NULL) {} // anders geeft ie segment error else if (!strcmp(command, "exit")) exit(0); else if (!strcmp(command, "cd")) { command = strtok(NULL, " "); if (command) changeDir(command); } else if (!strcmp(command, ".")) { // geen idee wat dit is maar moet bij de builtin dingen command = strtok(NULL, " "); printf("derp\n"); } else { pid_t child_pid; int child_status; child_pid = fork(); if (child_pid == 0) { /* This is done by the child process. */ char *args[MAXARGS]; for(int i = 1; i < MAXARGS; i++){ args[i] = strtok(NULL, " "); if (!args[i] || !strcmp(args[i], "|")) { // kan hier niks printen?? kan alleen buiten child_pid block args[i] = (char*) 0; otherCommands = 1; break; } } char temp[100] = "/bin/"; strcat(temp, command); args[0] = temp; execv(args[0], args); /* If execv returns, it must have failed. */ printf("Could not find command\n"); return; } else { /* This is run by the parent. Wait for the child to terminate. */ pid_t tpid; do { tpid = wait(&child_status); //if(tpid != child_pid) // process_terminated(tpid); process_terminated is geen functie? :S } while(tpid != child_pid); } } } while (otherCommands == 1); }
bool Ia::getUp() { if (_map->getCell(_posY + 1, _posX) == Tile::EMPTY || _map->getCell(_posY + 1, _posX) == Tile::CHARACTER || _map->getCell(_posY + 1, _posX) == Tile::INTEL || isPowerUp(_map->getCell(_posY + 1, _posX)) == true || _map->getCell(_posY + 1, _posX) == Tile::EXPLOSION) return true; if (decision == false) changeDir(); return false; }
bool Protester::moveDir(Direction d) { int x = getX(), y = getY(); changeDir(d); int dx = 0, dy = 0; switch (d) { case GraphObject::up: dy = 1; break; case GraphObject::down: dy = -1; break; case GraphObject::right: dx = 1; break; case GraphObject::left: dx = -1; break; default: break; } if (!getStudentWorld()->getSearch()->isMovable(x + dx, y + dy)) return false; moveTo(x + dx, y + dy); return true; }
int FishPool::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: changeDir((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: move(); break; case 2: openmouth(); break; } _id -= 3; } return _id; }
//this function check is for built in commands //and processes if there any int checkInternalCommand() { if(strcmp("cd", command.argv[0]) == 0){ changeDir(); return 1; } if(strcmp("clear", command.argv[0]) == 0){ clearScreen(); return 1; } if(strcmp("self",command.argv[0]) == 0){ clearScreen(); return 1; } return 0; }
// changes the working directory one level up by invoking the cwd command void cdup(char **params, short *abor, int fd, struct state *cstate, struct config *configuration) { if (!cstate->logged) { respond(fd, 5, 3, 0, "Not logged in."); return; } char old_path[PATH_LENGTH]; strcpy(old_path, cstate->path); // checks the directory existence // changes the "chrooted" part of path if (changeDir(cstate->path, "..") == NULL) { strcpy(cstate->path, old_path); respond(fd, 4, 5, 1, "Internal server error."); return; } respond(fd, 2, 5, 7, cstate->path); }
void RemoteHandler:: dispatch(char* command){ char* opcode = strtok(command, "|\n"); if (strcmp(opcode, "getFileList") == 0) getFileList(); else if (strcmp(opcode, "getFile") == 0) getFile(strtok(NULL, "|\n")); else if (strcmp(opcode, "changeDir") == 0) changeDir(strtok(NULL, "|\n")); else if (strcmp(opcode, "deleteFile") == 0) deleteFile(strtok(NULL, "|\n")); else if (strcmp(opcode, "closeHandler") == 0) closeHandler(); else cout << "else?? " << opcode; }
Boolean TChDirDialog::valid( ushort command ) { if( command != cmOK ) return True; char path[PATH_MAX]; strcpy( path, dirInput->data ); #ifndef __UNPATCHED // BUG FIX - EFW - Tue 05/16/95 // Ignore "Drives" line if switching drives. if(!strcmp(path, drivesText)) path[0] = EOS; // If it was "Drives" or the input line was blank, issue a // cmChangeDir event to select the current drive/directory. if(!path[0]) { TEvent event; event.what = evCommand; event.message.command = cmChangeDir; putEvent(event); return False; } // Otherwise, expand and check the path. #endif fexpand( path ); int len = strlen( path ); /* SS: changed */ if( len > 0 && path[len-1] == '/' ) path[len-1] = EOS; if( changeDir( path ) != 0 ) { messageBox( invalidText, mfError | mfOKButton ); return False; } return True; }
void Camera::trackDirAroundY(vec3 _dir, float timeStep) { vec3 flatDir = normalize(vec3(dir.x, 0.f, dir.z)); vec3 flat_Dir = normalize(vec3(_dir.x, 0.f, _dir.z)); float angleDiff = acos(dot(flatDir, flat_Dir)); if (angleDiff < 0.01f) return; float sign = 1.f; if (dot(right, _dir) >= 0) sign = -1.f; float adjustedSpeed = trackingSpeed*timeStep*trackingSpeedFunc(angleDiff); pos = vec3(rotY(sign*min(angleDiff, adjustedSpeed))*vec4(pos - viewCenter, 1.f))+viewCenter; changeDir(viewCenter - pos); }
int main(int argc, char **argv){ cmdList list = make_cmdList(); while(1){ char buf[PATH_MAX]; char s[linelen]; getcwd(buf,PATH_MAX); printf("current path: %s >\n",buf); fgets(s,linelen,stdin); cmdLine *cmdline; cmdline = parseCmdLines(s); if((cmdline)!= NULL){ /*testFunc(cmdline);*/ if(strcmp(cmdline->arguments[0],"quit")==0){ freeCmdLines(cmdline); break; } if (strcmp(cmdline->arguments[0],"cd")==0){ changeDir(cmdline); } else { if (s[0]=='!'){ invoke(list,s); } else{ add_cmdLine(list, s); if(strcmp(cmdline->arguments[0],"history") == 0){ history(list); } else { execute(list,cmdline); } } } } freeCmdLines(cmdline); } freeCmdList(list); return 0; }
//---------------------------------------------------------------------- void FFileDialog::onKeyPress (FKeyEvent* ev) { if ( ! isEnabled() ) return; FDialog::onKeyPress (ev); if ( ! filebrowser.hasFocus() ) return; FKey key = ev->key(); switch ( key ) { case fc::Fkey_erase: case fc::Fkey_backspace: changeDir(".."); ev->accept(); break; default: break; } }