void EQKAnalyzer::MKDirFor( const std::string& path, bool isdir ) const { if( path.empty() ) return; std::stringstream spath(path); std::vector<std::string> dirs; for(std::string dir; std::getline(spath, dir, '/'); ) { dirs.push_back(dir); } int dsize = dirs.size(); if( ! isdir ) dsize--; std::string pathcur; for( int idir=0; idir<dsize; idir++ ) { pathcur += dirs[idir]; if( MKDir( pathcur.c_str() ) ) WarningEA::Other(FuncName, "Making directory: " + pathcur ); pathcur += "/"; } }
void MKDirRec(std::string dir) { MakeAbsolute(dir); TSTLStrSize start = 1; // Skip first root path TSTLStrSize end = 0; do { end = dir.find("/", start); std::string subdir = dir.substr(0, end); if (subdir.empty()) break; if (!FileExists(subdir)) MKDir(subdir, (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH)); start = end + 1; } while (end != std::string::npos); }
int main() { SpaceId newProc; OpenFileId input = ConsoleInput; OpenFileId output = ConsoleOutput; char prompt[2], ch, buffer[60], cmd[20], arg[40]; char* quit, ls, exec, path, echo, mkdir, rm, create, open, cd, close, read, write; int bufferSize, bufferIndex, cmdIndex, argIndex; OpenFileId fd; prompt[0] = '-'; prompt[1] = '-'; while( 1 ) { Print("nachos:// ", 's'); bufferSize = 0; do { Read(&buffer[bufferSize], 1, input); } while( buffer[bufferSize++] != '\n' ); buffer[--bufferSize] = '\0'; bufferIndex = 0; cmdIndex = 0; while(bufferIndex < bufferSize && buffer[bufferIndex] != '\0' && buffer[bufferIndex] != ' ') { cmd[cmdIndex++] = buffer[bufferIndex++]; } cmd[cmdIndex] = '\0'; while(bufferIndex < bufferSize && buffer[bufferIndex] == ' ') { bufferIndex++; } argIndex = 0; while(bufferIndex < bufferSize && buffer[bufferIndex] != '\0' && buffer[bufferIndex] != ' ') { arg[argIndex++] = buffer[bufferIndex++]; } arg[argIndex] = '\0'; if(cmdIndex > 0) { if(argIndex > 0 && strcmp("exec", cmd, 4) == 0) { newProc = Exec(arg); if(newProc < 0) { Print("unable to run ", 's'); Println(arg, 's'); continue; } Print("SpaceId : ", 's'); Println(newProc, 'd'); Join(newProc); } if(strcmp("join", cmd, 4) == 0) { if(newProc >= 0) Join(newProc); } if(strcmp("ls", cmd, 2) == 0) { LS(); } if(strcmp("quit", cmd, 4) == 0) { Exit(0); } if(strcmp("halt", cmd, 4) == 0) { Halt(); } if(strcmp("path", cmd, 4) == 0) { Path(); } if(strcmp("help", cmd, 4) == 0) { Println("ls,echo,mkdir,cd,rm is the same as linux", 's'); Println("create a new file with: create [filename]", 's'); Println("open a file with: open [filename]", 's'); Println("close a file with: close [filename]", 's'); Println("write an opened file with: write [content]", 's'); Println("read an opened file with: read", 's'); Println("close an opened file with: close", 's'); Println("show current path with: path", 's'); Println("exit system with: exit", 's'); Println("halt system with: halt", 's'); } if(argIndex > 0 && strcmp("echo", cmd, 4) == 0) { Println(arg, 's'); } if(argIndex > 0 && strcmp("mkdir", cmd, 5) == 0) { MKDir(arg); } if(argIndex > 0 && strcmp("cd", cmd, 2) == 0) { CDDir(arg); } if(argIndex > 0 && strcmp("rm", cmd, 2) == 0) { Remove(arg); } if(argIndex > 0 && strcmp("create", cmd, 6) == 0) { Create(arg); } if(argIndex > 0 && strcmp("open", cmd, 4) == 0) { fd = Open(arg); } if(strcmp("close", cmd, 5) == 0) { Close(fd); } if(argIndex > 0 && strcmp("write", cmd, 5) == 0) { Write(arg, argIndex, fd); } if(strcmp("read", cmd, 4) == 0) { int readNum = Read(arg, 40, fd); arg[readNum] = '\0'; Println(arg, 's'); } if(strcmp("send", cmd, 4) == 0) { int num = parseInt(arg, argIndex); PutMsg(num, newProc); } if(strcmp("get", cmd, 3) == 0) { int num = GetMsg(); Println(num, 'd'); } if(strcmp("ts", cmd, 2) == 0) { TS(); } } } }
/*---------------------------------------------------- Extract osac from seed file ----------------------------------------------------*/ bool SeedRec::ExtractSac( const std::string& staname, const std::string& netname, const std::string& chname, const int sps, const std::string& rec_outname, const std::string& resp_outname, float& gapfrac, SacRec& sacout ) { /* random number generator */ unsigned timeseed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine generator (timeseed); std::uniform_real_distribution<float> distribution(0., 1.); auto rand = std::bind ( distribution, generator ); /* set up working directory */ std::string tdir; #pragma omp critical (mkdir) { while( true ) { tdir = "Working_" + std::to_string(rand()); if( MKDir( tdir.c_str() ) ) break; } } setvbuf(stdout, NULL, _IOLBF, 0); /* extract sacs from the seed */ std::string fresp; std::vector<std::string> filelst; if( ! pimpl->RunRdseed( staname, netname, chname, tdir, fresp, filelst ) ) { //reports << " sac record not found from " << pimpl->fseed << "! " << std::endl; dRemove(tdir.c_str()); return false; } /* read sacfile names from the filelst, * resample and merge one at a time */ sacout.Load(filelst.at(0).c_str()); sacout.Resample(sps); fRemove(filelst.at(0).c_str()); bool merged = false; for(int i=1; i<filelst.size(); i++) { SacRec sacnew(filelst.at(i).c_str(), *report); sacnew.Load(); sacnew.Resample(sps); sacout.merge(sacnew); fRemove(filelst.at(i).c_str()); merged = true; } //delete [] filelst; /* arrange the signal and check for percentage of poles if merged */ gapfrac = 0.; if( merged ) { int Nholes; if( ! rec_outname.empty() ) Nholes = sacout.arrange(rec_outname.c_str()); else Nholes = sacout.arrange(); gapfrac = (float)Nholes/(float)sacout.shd.npts; } // rename resp file if( ! resp_outname.empty() ) Move( fresp.c_str(), resp_outname.c_str() ); //reports << " done. "<<std::endl; dRemove(tdir.c_str()); return true; }