void CommandPrompt::copyFileInDirectory(string parameters){ /* * Разделя параметрите. */ queue<string> filePaths = this->getPaths(parameters); /* * Намира файловете по адрес и ги записва в опашка. * Последният адрес е на destination directory. */ queue<TextFile*> files; TextFile* tempFile; while (filePaths.size() > 1) { tempFile = determinePathAndGetFile(filePaths.front()); if (tempFile != NULL) files.push(tempFile); else cerr << "File not found!" << endl; filePaths.pop(); } /* * Намираме адреса на директорията. Ако е NULL връщаме, ако не създаваме копия. */ Directory* destinationDir = this->determinePathAndGetDir(filePaths.front()); filePaths.pop(); if (destinationDir == NULL) cerr << "Destination directory not found!" << endl; else { while (!files.empty()){ destinationDir->addChild(new TextFile(*files.front())); files.pop(); } } }
// オプションノードから割付方法を取得する enum Common::tagAssignmentOrder Common::parseOrder(OptionParameter::OptionItem item) { Directory node; unsigned int i; for(i=0;i<item.countParameter();++i) node.addChild(item[i]); return parseOrder(&node); }
/* * Помощтна функция, за запазване/въвеждане на файлове. */ void CommandPrompt::saveConcatenatedFile(string path, string data){ /* * Ако няма данни и няма подаден адрес за запис връща. */ if (path.empty() && data.empty()) return; /* * Ако няма данни се въвеждат. */ if (data.empty()) { char line[1000]; string sline; while (sline != string(".")) { cin.getline(line, 1000); sline = line; if(sline != ".") data += sline; } } /* * Ако няма outputFile се извеждат данните, ако има * се намира/създава директория и се създава вайл в нея. * Наследява промените по големината на директориите. */ if (path.empty()) cout << data << endl; else { string fileName = path; Directory* dir = fs.getRoot(); int pos = path.rfind('/') + 1; if (pos - 1 != string::npos) { fileName = ""; while (pos < path.size()) fileName += path[pos++]; pos = path.rfind('/'); path = path.erase(pos, path.size()); dir = this->createNestedDirectories(path); } else dir = currentDir; if (dir->nameAvailable(fileName)) { dir->addChild(new TextFile(dir->getFSysPath(), fs.getNextNumber(), data, fileName)); dir->inheritSize(data.size()); } else { dir->findFileByName(fileName)->concatData(data); dir->inheritSize(data.size()); } } }
static void mergeFileDef(Directory *root,FileDef *fd) { QCString rootPath = root->name(); QCString filePath = fd->absFilePath(); //printf("merging %s\n",filePath.data()); Directory *dirNode = findDirNode(root,filePath); if (!dirNode->children().isEmpty()) { dirNode->children().last()->setLast(FALSE); } DirEntry *e=new DirEntry(dirNode,fd); dirNode->addChild(e); }
Directory * StaticAPI::allocate(Directory & container, const Token & token, const char * id, bool regist) { static unsigned int assignment_count = 0; Directory * node; if(!(token == Token::IDENTIFIER || token == Token::INTEGER)) ExceptionMessage("Given token(%) is not suitable for an object identifier.","オブジェクトの識別名として利用できない字句(%)が指定されました") << token << throwException; if(regist && (token == Token::INTEGER && token.value <= 0)) ExceptionMessage("Cannot assign an ID number less or equal to 0.","0以下のID番号を設定することはできません").throwException(); node = container.findChild(id); if(node != 0) { Directory::iterator scope; scope = node->begin(); while(scope != node->end()) { if((*scope).first.compare(token) == 0) ExceptionMessage("Identifier % is already used.","識別名%はすでに利用されています") << token << throwException; ++ scope; } }else node = container.addChild(id); node = node->addChild(token); (*node)["#order"] = assignment_count++; if(token == Token::IDENTIFIER) { if(regist) { Directory * scope = container.openChild("/","identifier",token.c_str(),NULL); if(*scope == Directory::INTEGER) *node = scope->toInteger(); } }else *node = token.value; last = node; return node; }
/* * Създава линкове на файловете в подадена директория. */ void CommandPrompt::createLinksInDirectory(string parameters){ stack<string> filePaths; string tempPath; /* * Извлича адресите в стек (защото последния адрес е директория). */ for (int i = 0; i <= parameters.size(); i++) { if (parameters[i] == ' ' || i == parameters.size()) { filePaths.push(tempPath); tempPath = ""; } else { tempPath += parameters[i]; } } /* * Намира директорията. Ако не я намери извежда грешка и връща. */ Directory* destinationDir = this->determinePathAndGetDir(filePaths.top()); filePaths.pop(); if (destinationDir == NULL) { cerr << "Destination directory not found!" << endl; return; } /* * Намира файловете по адрес и създава линкове към тях в директорията. */ TextFile* tempFile; while (!filePaths.empty()) { tempFile = this->determinePathAndGetFile(filePaths.top()); if (tempFile == NULL) { cerr << "File not found!" << endl; } else { destinationDir->addChild(new SymLink(tempFile, fs.getNextNumber(), destinationDir->getFSysPath())); } filePaths.pop(); } }
/* * Определя какъв е адреса и го обхожда име по име. * Ако намери директория която не съществува я създава. * @return - търсената директория, ако поради някакви причини не се е създала връща root. */ Directory* CommandPrompt::createNestedDirectories(string path) { string currentName; Directory* result = NULL; Directory* tempDir = fs.getRoot(); if (path.find('/') == string::npos) { if ((tempDir = tempDir->findDirByName(path)) == NULL) { result = new Directory(currentDir->getFSysPath(), fs.getNextNumber(), path, currentDir); currentDir->addChild(result); return result; } return tempDir; } else { for (int i = 0; i <= path.size(); i++) { if ((path[i] == '/' || i == path.size()) && !currentName.empty()) { if (tempDir->findDirByName(currentName) == NULL) { result = new Directory(tempDir->getFSysPath(), fs.getNextNumber(), currentName, tempDir); tempDir->addChild(result); } tempDir = tempDir->findDirByName(currentName); currentName = ""; } else if(path[i] != '/') { currentName += path[i]; } } } if (result == NULL) return tempDir; return result; }
bool ParserComponent::parseStaticAPI(Parser & p, Directory & container, Token token, const string domain) { bool isParseErrorOccured = false; map<string, ParseUnit *>::iterator api; Directory * node = NULL; if(token.type != Token::IDENTIFIER) return false; StaticAPI::clearLastObject(); node = container[PARSERESULT].addChild(); try { node->addChild("api",new Directory(token)); node->addChild("begin",new Directory((long)p.getLogBufferPos(-(int)token.size()-1))); if(!domain.empty()) node->addChild("domain", new Directory(domain)); api = StaticAPI::container().find(token); if(api == StaticAPI::container().end()) { if(ignoreUnknownAPI) { cerr << Message("%: Unknown static api % was ignored. (skipped)\n","%: 非登録のAPI % は無視されます\n") << p.getStreamLocation() << token; do { p.getToken(token); }while(token.compare(";") != 0); node->addChild("end",new Directory((long)p.getLogBufferPos())); (*node) = (long)0; return true; } ExceptionMessage("Static API [%] is not registered in the configurator", "静的API[%]は未登録です") << token << throwException; } DebugMessage(" StaticAPI [%]\n") << (*api).first; p.getToken("("); (*api).second->body(token, container, p, domain); p.getToken(")"); p.getToken(";"); node->addChild("end",new Directory((long)p.getLogBufferPos())); (*node) = (long)1; } catch(Exception & e) { int offset; string work; work = p.getStreamLocation() + Message(":[Error] ",":[エラー] ").str() + e.getDetails(); isParseErrorOccured = true; StaticAPI::dropLastObject(); failCount ++; offset = 0; token = p.getLastErrorToken(); while (token != Token::ERROR && token != Token::EOS) { if( token == ";" ) break; //読み出したトークンが静的APIと同じ名前なら きっとセミコロン忘れ api = StaticAPI::container().find(token); if(api != StaticAPI::container().end()) { cerr << Message("<The following error must be occured by lack of ';' at the end of previous line>\n","<次のエラーは直前行の';'忘れによる可能性が高いです>\n"); offset = -(int)token.size(); p.putBack(token); break; } p.getToken(token); } node->addChild("end",new Directory((long)p.getLogBufferPos(offset))); (*node) = (long)0; cerr << work << '\n'; ExceptionMessage("Fatal error on Static API parsing","静的APIの構文解析に失敗しました").throwException(); } return true; }
static Directory *findDirNode(Directory *root,const QCString &name) { QListIterator<DirEntry> dli(root->children()); DirEntry *de; for (dli.toFirst();(de=dli.current());++dli) { if (de->kind()==DirEntry::Dir) { Directory *dir = (Directory *)de; QCString dirName=dir->name(); int sp=findMatchingPart(name,dirName); //printf("findMatchingPart(%s,%s)=%d\n",name.data(),dirName.data(),sp); if (sp>0) // match found { if ((uint)sp==dirName.length()) // whole directory matches { // recurse into the directory return findDirNode(dir,name.mid(dirName.length()+1)); } else // partial match => we need to split the path into three parts { QCString baseName =dirName.left(sp); QCString oldBranchName=dirName.mid(sp+1); QCString newBranchName=name.mid(sp+1); // strip file name from path int newIndex=newBranchName.findRev('/'); if (newIndex>0) newBranchName=newBranchName.left(newIndex); //printf("Splitting off part in new branch \n" // "base=%s old=%s new=%s\n", // baseName.data(), // oldBranchName.data(), // newBranchName.data() // ); Directory *base = new Directory(root,baseName); Directory *newBranch = new Directory(base,newBranchName); dir->reParent(base); dir->rename(oldBranchName); base->addChild(dir); base->addChild(newBranch); dir->setLast(FALSE); // remove DirEntry container from list (without deleting it) root->children().setAutoDelete(FALSE); root->children().removeRef(dir); root->children().setAutoDelete(TRUE); // add new branch to the root if (!root->children().isEmpty()) { root->children().last()->setLast(FALSE); } root->addChild(base); return newBranch; } } } } int si=name.findRev('/'); if (si==-1) // no subdir { return root; // put the file under the root node. } else // need to create a subdir { QCString baseName = name.left(si); //printf("new subdir %s\n",baseName.data()); Directory *newBranch = new Directory(root,baseName); if (!root->children().isEmpty()) { root->children().last()->setLast(FALSE); } root->addChild(newBranch); return newBranch; } }