int builtin_cd(t_cmd *cmd, char **envp) { if (cmd == NULL) return (ERR); if (ft_strncmp(cmd->arg, "-") && cmd->arg->next == NULL) return (old_path(envp)); if (cmd->arg == NULL) return (chdir(extract_home(envp))); return (chdir(cmd->arg)); }
void FileView::ChangeFilePath(const QString& new_path_native) { QString new_path = QDir::fromNativeSeparators(new_path_native); QFileInfo info(new_path); if (!info.exists() || !info.isDir()) return; QString old_path(model_->rootPath()); if (old_path == new_path) return; undo_stack_->push(new UndoCommand(this, new_path)); }
std::string PragmaParser::substitutePragmas(const std::string& OldFile) { INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Substituting pragma in " + OldFile); THROW_ASSERT(boost::filesystem::exists(boost::filesystem::path(OldFile)), "Input file \"" + OldFile + "\" does not exist"); boost::filesystem::path old_path(OldFile); std::string FileName = Param->getOption<std::string>(OPT_output_temporary_directory) + STR_CST_pragma_prefix + boost::lexical_cast<std::string>(file_counter) + "_" + GetLeafFileName(old_path); boost::filesystem::ofstream fileOutput(FileName.c_str(), std::ios::out); file_counter++; level = 0; unsigned line_number = 0; // Get a stream from the input file std::ifstream instream(OldFile.c_str()); // Test if the file has been correctly opened THROW_ASSERT(instream.is_open(), "INPUT FILE ERROR: Could not open input file: " + OldFile); while (!instream.eof()) { std::string input_line; getline (instream,input_line); INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Read line <" + input_line + ">"); std::string output_line = input_line; /// search for function name if (search_function) { std::string::size_type notwhite = output_line.find_first_of("("); if (notwhite != std::string::npos) { std::string Token = input_line; Token.erase(notwhite); name_function += Token; notwhite = name_function.find_last_not_of(" \t\r\n"); name_function.erase(notwhite+1); notwhite = name_function.find_last_of(" \t\n*>"); name_function.erase(0, notwhite+1); INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found function " + name_function); ///Pragma associated with called are added by pragma_analysis if (level == 0) PM->AddFunctionDefinitionPragmas(name_function, FunctionPragmas); name_function.clear(); search_function = false; FunctionPragmas.clear(); } else name_function += input_line + " "; } if (input_line.find("#pragma") != std::string::npos) { INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found a pragma"); output_line = input_line; char const* delims = " \t\r\n"; // trim leading whitespace std::string::size_type notwhite = output_line.find_first_not_of(delims); output_line.erase(0,notwhite); // trim trailing whitespace notwhite = output_line.find_last_not_of(delims); output_line.erase(notwhite+1); analyze_pragma(output_line); } /// print out the new pragma line fileOutput << output_line << std::endl; /// manage nesting levels bool found = false; for(unsigned int i = 0; i < input_line.size(); i++) { if (input_line[i] == '{') { level++; INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found {: Current level " + boost::lexical_cast<std::string>(level)); if (!found) { for(std::list<std::string>::iterator it = FloatingPragmas.begin(); it != FloatingPragmas.end(); it++) OpenPragmas[level].push_back(*it); FloatingPragmas.clear(); } found = true; } if (input_line[i] == '}') { if (OpenPragmas.count(level)) { for(std::list<std::string>::iterator open_pragma = OpenPragmas[level].begin(); open_pragma != OpenPragmas[level].end(); open_pragma++) fileOutput << std::string(STR_CST_pragma_function_end) + "(\"" << *open_pragma << "\");" << std::endl; OpenPragmas[level].clear(); } level--; INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found }: Current level " + boost::lexical_cast<std::string>(level)); } } /// increment line number line_number++; } fileOutput.close(); INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Substituted pragma in " + OldFile); return FileName; }