示例#1
0
/*
* Операция за конкатенация, извеждане и въвеждане на файл.
*/
void CommandPrompt::concatenateFiles(string filePaths){
	queue<string> paths;
	string outputFilePath;
	string temp;
	for (int i = 0; i <= filePaths.size(); i++) {
		/*
		* Ако сме достигнали '>' записва адреса на параметър ако е останал незаписан
		* и започва четенето на outputFilePath.
		*/
		if (filePaths[i] == '>' || i == filePaths.size()) {
			if(!temp.empty())
				paths.push(temp);
			if (i != filePaths.size()) {
				i += 2;
				while (i < filePaths.size()) {
					outputFilePath += filePaths[i++];
				}
			}
		}
		else if(filePaths[i] == ' ') {
			paths.push(temp);
			temp = "";
		}
		else {
			temp += filePaths[i];
		}
	}

	/*
	* Конкатенира данните на всички файлове в опашката и извиква
	* saveConcatenatedFile с параметри данните и outputFilePath.
	*/
	string resultData;
	TextFile* currentFile;
	while (!paths.empty()) {
		temp = paths.front();
		currentFile = this->determinePathAndGetFile(temp);
		if (currentFile != NULL)
			resultData += currentFile->getData();
		else
			cerr << "File not found!" << endl;
		paths.pop();
		if (!paths.empty())
			resultData += '\n';
	}
	this->saveConcatenatedFile(outputFilePath, resultData);
}