bool SetCurPath(const OJString & path) { bool ret = !!::SetCurrentDirectory(path.c_str()); DEBUG_MSG_VS(OJStr("Current Work Directory: %s"), getCurPath().c_str()); return ret; }
//////////////////////////////////////////////////////////////////////// // // Description: // find current path tail // // use: public, virtual (SoCallbackAction overrides this) ////////////////////////////////////////////////////////////////////// // SoNode * SoAction::getCurPathTail() { #ifdef DEBUG if (curPath.getTail() != ((SoFullPath*)getCurPath())->getTail()){ SoDebugError::post("SoAction::getCurPathTail\n", "Inconsistent path tail. Did you change the scene graph\n" "During traversal?\n"); } #endif /*DEBUG*/ return(curPath.getTail()); }
void myCd(char*arg){ int error; if(arg==NULL){ error=chdir(".."); }else{ error=chdir(arg); } if(error!=0){ perror("run cd error"); }else{ getCurPath(curPath); } }
void LLDir::dumpCurrentDirectories() { LL_DEBUGS2("AppInit","Directories") << "Current Directories:" << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " CurPath: " << getCurPath() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " AppName: " << getAppName() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutableFilename: " << getExecutableFilename() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutableDir: " << getExecutableDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutablePathAndName: " << getExecutablePathAndName() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " WorkingDir: " << getWorkingDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " AppRODataDir: " << getAppRODataDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " OSUserDir: " << getOSUserDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " OSUserAppDir: " << getOSUserAppDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " LindenUserDir: " << getLindenUserDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " TempDir: " << getTempDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " CAFile: " << getCAFile() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " SkinDir: " << getSkinDir() << LL_ENDL; }
void LLDir::dumpCurrentDirectories() { LL_DEBUGS2("AppInit","Directories") << "Current Directories:" << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " CurPath: " << getCurPath() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " AppName: " << getAppName() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutableFilename: " << getExecutableFilename() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutableDir: " << getExecutableDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " ExecutablePathAndName: " << getExecutablePathAndName() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " WorkingDir: " << getWorkingDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " AppRODataDir: " << getAppRODataDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " OSUserDir: " << getOSUserDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " OSUserAppDir: " << getOSUserAppDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " LindenUserDir: " << getLindenUserDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " TempDir: " << getTempDir() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " CAFile: " << getCAFile() << LL_ENDL; LL_DEBUGS2("AppInit","Directories") << " SkinDir: " << getSkinDir() << LL_ENDL; #if LL_LIBXUL_ENABLED LL_DEBUGS2("AppInit","Directories") << " HTML Path: " << getExpandedFilename( LL_PATH_HTML, "" ) << llendl; LL_DEBUGS2("AppInit","Directories") << " Mozilla Profile Path: " << getExpandedFilename( LL_PATH_MOZILLA_PROFILE, "" ) << llendl; #endif }
int main(int argc,char* argv[]){ //获取当前路径 int i=0; for(i=0;i<argc;i++){ puts(argv[i]); } char command[1000]; //限制命令长度为999个字符 int comBegPos[20]; char **args; short argNum=0; pid_t child_id; int redirectPos=0; char*redirectedFileName; int fd[2]; int readPipe; int comNum=0; int lastOut[2]; getCurPath(curPath); printf("%s$",curPath); gets(command); while(strcmp(command,"exit")!=0){ getComAndArgs(command,&args,&argNum); comNum=getComNum(args,argNum,comBegPos); getComNumAndRedirectedPos(args,&comNum,&redirectPos); printf("command:%s,redirectPos:%d\n",command,redirectPos); printf("\n\ncommandInfo\ncomNum=%d,isRedirected:%d\n",comNum,redirectPos); for(i=0;i<argNum;i++){ if(args[i]==NULL){ puts("NULL"); }else{ puts(args[i]); } } for(i=0;i<comNum;i++){ printf("pos:%d\t",comBegPos[i]); } printf("\n\n\ncontent below:\n"); lastOut[1]=1; if(redirectPos!=0) { pipe(lastOut); redirectedFileName=args[comBegPos[comNum-1]+redirectPos]+1; args[comBegPos[comNum-1]+redirectPos]=NULL; } if(comNum==1){ //just one command and no pipe execCom(0,lastOut[1],args); }else{ //Given that if pipe(fd) ,fd[0]>0&&fd[1]>0; for(i=0;i<comNum;i++){ if(i==0){ //the first one pipe(fd); readPipe=0; execCom(readPipe,fd[1],args+comBegPos[i]); }else if(i==comNum-1){ //the last one close(fd[1]); if(readPipe!=0) close(readPipe); readPipe=fd[0]; execCom(readPipe,lastOut[1],args+comBegPos[i]); } else{ //not first nor last close(fd[1]); if(readPipe!=0) close(readPipe); readPipe=fd[0]; pipe(fd); execCom(readPipe,fd[1],args+comBegPos[i]); } } if(readPipe!=0) close(readPipe); } //has redirectPos and the result must in lastOut[0]; if(redirectPos!=0){ int file=open(redirectedFileName,O_RDWR|O_CREAT,S_IRWXU); char buffer[10000]; int len; len=read(lastOut[0],buffer,10000); write(file,buffer,len); close(file); close(lastOut[0]); close(lastOut[1]); } int k=0; for(k=0;k<argNum;k++){ // puts(args[k]); if(args[k]!=NULL); free(args[k]); } free(args); printf("%s$",curPath); gets(command); } puts("sh3.c结束运行"); }
LLDir_Mac::LLDir_Mac() { mDirDelimiter = "/"; mCurrentDirIndex = -1; mCurrentDirCount = -1; CFBundleRef mainBundleRef = NULL; CFURLRef executableURLRef = NULL; CFStringRef stringRef = NULL; OSStatus error = noErr; FSRef fileRef; CFStringRef secondLifeString = CFSTR("SecondLife"); mainBundleRef = CFBundleGetMainBundle(); executableURLRef = CFBundleCopyExecutableURL(mainBundleRef); if (executableURLRef != NULL) { // mExecutablePathAndName CFURLRefToLLString(executableURLRef, mExecutablePathAndName, false); // mExecutableFilename stringRef = CFURLCopyLastPathComponent(executableURLRef); CFStringRefToLLString(stringRef, mExecutableFilename, true); // mExecutableDir CFURLRef executableParentURLRef = CFURLCreateCopyDeletingLastPathComponent(NULL, executableURLRef); CFURLRefToLLString(executableParentURLRef, mExecutableDir, true); // mAppRODataDir CFURLRef resourcesURLRef = CFBundleCopyResourcesDirectoryURL(mainBundleRef); CFURLRefToLLString(resourcesURLRef, mAppRODataDir, true); // mOSUserDir error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, true, &fileRef); if (error == noErr) { FSRef newFileRef; // Create the directory error = CFCreateDirectory(&fileRef, secondLifeString, &newFileRef); if (error == noErr) { // Save the full path to the folder FSRefToLLString(&newFileRef, mOSUserDir); // Create our sub-dirs (void) CFCreateDirectory(&newFileRef, CFSTR("data"), NULL); //(void) CFCreateDirectory(&newFileRef, CFSTR("cache"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("logs"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("user_settings"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("browser_profile"), NULL); } } //mOSCacheDir FSRef cacheDirRef; error = FSFindFolder(kUserDomain, kCachedDataFolderType, true, &cacheDirRef); if (error == noErr) { FSRefToLLString(&cacheDirRef, mOSCacheDir); (void)CFCreateDirectory(&cacheDirRef, CFSTR("SecondLife"),NULL); } // mOSUserAppDir mOSUserAppDir = mOSUserDir; // mTempDir error = FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType, true, &fileRef); if (error == noErr) { FSRef tempRef; error = CFCreateDirectory(&fileRef, secondLifeString, &tempRef); if (error == noErr) FSRefToLLString(&tempRef, mTempDir); } mWorkingDir = getCurPath(); mLLPluginDir = mAppRODataDir + mDirDelimiter + "llplugin"; CFRelease(executableURLRef); executableURLRef = NULL; } }
LLDir_Win32::LLDir_Win32() { mDirDelimiter = "\\"; WCHAR w_str[MAX_PATH]; // Application Data is where user settings go SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE); mOSUserDir = utf16str_to_utf8str(llutf16string(w_str)); // We want cache files to go on the local disk, even if the // user is on a network with a "roaming profile". // // On XP this is: // C:\Docments and Settings\James\Local Settings\Application Data // On Vista this is: // C:\Users\James\AppData\Local // // We used to store the cache in AppData\Roaming, and the installer // cleans up that version on upgrade. JC SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE); mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str)); if (GetTempPath(MAX_PATH, w_str)) { if (wcslen(w_str)) /* Flawfinder: ignore */ { w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash } mTempDir = utf16str_to_utf8str(llutf16string(w_str)); } else { mTempDir = mOSUserDir; } // fprintf(stderr, "mTempDir = <%s>",mTempDir); #if 1 // Don't use the real app path for now, as we'll have to add parsing to detect if // we're in a developer tree, which has a different structure from the installed product. S32 size = GetModuleFileName(NULL, w_str, MAX_PATH); if (size) { w_str[size] = '\0'; mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str)); S32 path_end = mExecutablePathAndName.find_last_of('\\'); if (path_end != std::string::npos) { mExecutableDir = mExecutablePathAndName.substr(0, path_end); mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos); } else { mExecutableFilename = mExecutablePathAndName; } GetCurrentDirectory(MAX_PATH, w_str); mWorkingDir = utf16str_to_utf8str(llutf16string(w_str)); } else { fprintf(stderr, "Couldn't get APP path, assuming current directory!"); GetCurrentDirectory(MAX_PATH, w_str); mExecutableDir = utf16str_to_utf8str(llutf16string(w_str)); // Assume it's the current directory } #else GetCurrentDirectory(MAX_PATH, w_str); mExecutableDir = utf16str_to_utf8str(llutf16string(w_str)); #endif // When running in a dev tree, app_settings is under indra/newview/ // but in production it is under Program Files/meta7/ // Attempt to detect which one we're using. JC if (mExecutableDir.find("indra") != std::string::npos) mAppRODataDir = getCurPath(); else mAppRODataDir = mExecutableDir; // Build the default cache directory mDefaultCacheDir = buildSLOSCacheDir(); // Make sure it exists int res = LLFile::mkdir(mDefaultCacheDir); if (res == -1) { if (errno != EEXIST) { llwarns << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << llendl; } } }
LLDir_Win32::LLDir_Win32() { mDirDelimiter = "\\"; WCHAR w_str[MAX_PATH]; // Application Data is where user settings go SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE); mOSUserDir = utf16str_to_utf8str(llutf16string(w_str)); // Local Settings\Application Data is where cache files should // go, they don't get copied to the server if the user moves his // profile around on the network. JC // // TODO: patch the installer to remove old cache files on update, then // enable this code. //SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE); //mOSUserCacheDir = utf16str_to_utf8str(llutf16string(w_str)); if (GetTempPath(MAX_PATH, w_str)) { if (wcslen(w_str)) /* Flawfinder: ignore */ { w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash } mTempDir = utf16str_to_utf8str(llutf16string(w_str)); } else { mTempDir = mOSUserDir; } // fprintf(stderr, "mTempDir = <%s>",mTempDir); #if 1 // Don't use the real app path for now, as we'll have to add parsing to detect if // we're in a developer tree, which has a different structure from the installed product. S32 size = GetModuleFileName(NULL, w_str, MAX_PATH); if (size) { w_str[size] = '\0'; mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str)); S32 path_end = mExecutablePathAndName.find_last_of('\\'); if (path_end != std::string::npos) { mExecutableDir = mExecutablePathAndName.substr(0, path_end); mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos); } else { mExecutableFilename = mExecutablePathAndName; } GetCurrentDirectory(MAX_PATH, w_str); mWorkingDir = utf16str_to_utf8str(llutf16string(w_str)); } else { fprintf(stderr, "Couldn't get APP path, assuming current directory!"); GetCurrentDirectory(MAX_PATH, w_str); mExecutableDir = utf16str_to_utf8str(llutf16string(w_str)); // Assume it's the current directory } #else GetCurrentDirectory(MAX_PATH, w_str); mExecutableDir = utf16str_to_utf8str(llutf16string(w_str)); #endif // When running in a dev tree, app_settings is under indra/newview/ // but in production it is under Program Files/SecondLife/ // Attempt to detect which one we're using. JC if (mExecutableDir.find("indra") != std::string::npos) mAppRODataDir = getCurPath(); else mAppRODataDir = mExecutableDir; }
LLDir_Mac::LLDir_Mac() { mDirDelimiter = "/"; const std::string secondLifeString = "Firestorm"; std::string *executablepathstr = getSystemExecutableFolder(); //NOTE: LLINFOS/LLERRS will not output to log here. The streams are not initialized. if (executablepathstr) { // mExecutablePathAndName mExecutablePathAndName = *executablepathstr; boost::filesystem::path executablepath(*executablepathstr); # ifndef BOOST_SYSTEM_NO_DEPRECATED #endif mExecutableFilename = executablepath.filename().string(); mExecutableDir = executablepath.parent_path().string(); // mAppRODataDir std::string *resourcepath = getSystemResourceFolder(); mAppRODataDir = *resourcepath; // *NOTE: When running in a dev tree, use the copy of // skins in indra/newview/ rather than in the application bundle. This // mirrors Windows dev environment behavior and allows direct checkin // of edited skins/xui files. JC // MBW -- This keeps the mac application from finding other things. // If this is really for skins, it should JUST apply to skins. size_t build_dir_pos = mExecutableDir.rfind("/build-darwin-"); if (build_dir_pos != std::string::npos) { // ...we're in a dev checkout mSkinBaseDir = mExecutableDir.substr(0, build_dir_pos) + "/indra/newview/skins"; LL_INFOS() << "Running in dev checkout with mSkinBaseDir " << mSkinBaseDir << LL_ENDL; } else { // ...normal installation running mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; } // mOSUserDir std::string *appdir = getSystemApplicationSupportFolder(); std::string rootdir; //Create root directory if (CreateDirectory(*appdir, secondLifeString, &rootdir)) { // Save the full path to the folder mOSUserDir = rootdir; // Create our sub-dirs CreateDirectory(rootdir, std::string("data"), NULL); CreateDirectory(rootdir, std::string("logs"), NULL); CreateDirectory(rootdir, std::string("user_settings"), NULL); CreateDirectory(rootdir, std::string("browser_profile"), NULL); } //mOSCacheDir std::string *cachedir = getSystemCacheFolder(); if (cachedir) { mOSCacheDir = *cachedir; //TODO: This changes from ~/Library/Cache/Secondlife to ~/Library/Cache/com.app.secondlife/Secondlife. Last dir level could go away. //<FS:TS> Adjust the cache directory to match what's expected in lldir. //CreateDirectory(mOSCacheDir, secondLifeString, NULL); std::string FSCacheDirName = secondLifeString; // This was lifted from Cinder's fix for FIRE-8226. #ifdef OPENSIM #ifdef ND_BUILD64BIT_ARCH FSCacheDirName.append("OS_x64"); #else FSCacheDirName.append("OS"); #endif #else #ifdef ND_BUILD64BIT_ARCH FSCacheDirName.append("_x64"); #endif #endif // OPENSIM CreateDirectory(mOSCacheDir, FSCacheDirName, NULL); //</FS:TS> } // mOSUserAppDir mOSUserAppDir = mOSUserDir; // mTempDir //Aura 120920 boost::filesystem::temp_directory_path() not yet implemented on mac. :( std::string *tmpdir = getSystemTempFolder(); if (tmpdir) { CreateDirectory(*tmpdir, secondLifeString, &mTempDir); if (tmpdir) delete tmpdir; } mWorkingDir = getCurPath(); mLLPluginDir = mAppRODataDir + mDirDelimiter + "llplugin"; } }
LLDir_Mac::LLDir_Mac() { mDirDelimiter = "/"; mCurrentDirIndex = -1; mCurrentDirCount = -1; CFBundleRef mainBundleRef = NULL; CFURLRef executableURLRef = NULL; CFStringRef stringRef = NULL; OSStatus error = noErr; FSRef fileRef; CFStringRef secondLifeString = CFSTR("SecondLife"); mainBundleRef = CFBundleGetMainBundle(); executableURLRef = CFBundleCopyExecutableURL(mainBundleRef); if (executableURLRef != NULL) { // mExecutablePathAndName CFURLRefToLLString(executableURLRef, mExecutablePathAndName, false); // mExecutableFilename stringRef = CFURLCopyLastPathComponent(executableURLRef); CFStringRefToLLString(stringRef, mExecutableFilename, true); // mExecutableDir CFURLRef executableParentURLRef = CFURLCreateCopyDeletingLastPathComponent(NULL, executableURLRef); CFURLRefToLLString(executableParentURLRef, mExecutableDir, true); // mAppRODataDir // *NOTE: When running in a dev tree, use the copy of // skins in indra/newview/ rather than in the application bundle. This // mirrors Windows dev environment behavior and allows direct checkin // of edited skins/xui files. JC // MBW -- This keeps the mac application from finding other things. // If this is really for skins, it should JUST apply to skins. CFURLRef resourcesURLRef = CFBundleCopyResourcesDirectoryURL(mainBundleRef); CFURLRefToLLString(resourcesURLRef, mAppRODataDir, true); U32 indra_pos = mExecutableDir.find("/indra"); if (indra_pos != std::string::npos) { // ...we're in a dev checkout mSkinBaseDir = mExecutableDir.substr(0, indra_pos) + "/indra/newview/skins"; llinfos << "Running in dev checkout with mSkinBaseDir " << mSkinBaseDir << llendl; } else { // ...normal installation running mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; } // mOSUserDir error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, true, &fileRef); if (error == noErr) { FSRef newFileRef; // Create the directory error = CFCreateDirectory(&fileRef, secondLifeString, &newFileRef); if (error == noErr) { // Save the full path to the folder FSRefToLLString(&newFileRef, mOSUserDir); // Create our sub-dirs (void) CFCreateDirectory(&newFileRef, CFSTR("data"), NULL); //(void) CFCreateDirectory(&newFileRef, CFSTR("cache"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("logs"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("user_settings"), NULL); (void) CFCreateDirectory(&newFileRef, CFSTR("browser_profile"), NULL); } } //mOSCacheDir FSRef cacheDirRef; error = FSFindFolder(kUserDomain, kCachedDataFolderType, true, &cacheDirRef); if (error == noErr) { FSRefToLLString(&cacheDirRef, mOSCacheDir); (void)CFCreateDirectory(&cacheDirRef, CFSTR("SecondLife"),NULL); } // mOSUserAppDir mOSUserAppDir = mOSUserDir; // mTempDir error = FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType, true, &fileRef); if (error == noErr) { FSRef tempRef; error = CFCreateDirectory(&fileRef, secondLifeString, &tempRef); if (error == noErr) FSRefToLLString(&tempRef, mTempDir); } mWorkingDir = getCurPath(); mLLPluginDir = mAppRODataDir + mDirDelimiter + "llplugin"; CFRelease(executableURLRef); executableURLRef = NULL; } }