Example #1
0
QStringList texFileList(QString const & filename)
{
	QStringList list;
	FileName const file = libFileSearch(QString(), filename);
	if (file.empty())
		return list;

	// FIXME Unicode.
	vector<docstring> doclist = 
		getVectorFromString(file.fileContents("UTF-8"), from_ascii("\n"));

	// Normalise paths like /foo//bar ==> /foo/bar
	QSet<QString> set;
	for (size_t i = 0; i != doclist.size(); ++i) {
		QString file = toqstr(doclist[i]);
		file.replace("\r", "");
		while (file.contains("//"))
			file.replace("//", "/");
		if (!file.isEmpty())
			set.insert(file);
	}

	// remove duplicates
	return QList<QString>::fromSet(set);
}
Example #2
0
string const doSubstitution(InsetExternalParams const & params,
			    Buffer const & buffer, string const & s,
			    bool use_latex_path,
			    bool external_in_tmpdir,
			    Substitute what)
{
	Buffer const * masterBuffer = buffer.masterBuffer();
	string const parentpath = external_in_tmpdir ?
		masterBuffer->temppath() :
		buffer.filePath();
	string const filename = external_in_tmpdir ?
		params.filename.mangledFileName() :
		params.filename.outputFileName(parentpath);
	string const basename = changeExtension(
			onlyFileName(filename), string());
	string const absname = makeAbsPath(filename, parentpath).absFileName();

	string result = s;
	if (what != ALL_BUT_PATHS) {
		string const filepath = onlyPath(filename);
		string const abspath = onlyPath(absname);
		string const masterpath = external_in_tmpdir ?
			masterBuffer->temppath() :
			masterBuffer->filePath();
		// FIXME UNICODE
		string relToMasterPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(masterpath))));
		if (relToMasterPath == "./")
			relToMasterPath.clear();
		// FIXME UNICODE
		string relToParentPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(parentpath))));
		if (relToParentPath == "./")
			relToParentPath.clear();

		result = subst_path(result, "$$FPath", filepath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$AbsPath", abspath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathMaster",
				    relToMasterPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathParent",
				    relToParentPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		if (FileName::isAbsolute(filename)) {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		} else {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    relToMasterPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    relToParentPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		}
	}

	if (what == PATHS)
		return result;

	result = subst_path(result, "$$FName", filename, use_latex_path,
			    EXCLUDE_EXTENSION);
	result = subst_path(result, "$$Basename", basename, use_latex_path,
			    PROTECT_EXTENSION, ESCAPE_DOTS);
	result = subst_path(result, "$$Extension",
			'.' + getExtension(filename), use_latex_path);
	result = subst_path(result, "$$Tempname", params.tempname().absFileName(), use_latex_path);
	result = subst_path(result, "$$Sysdir",
				package().system_support().absFileName(), use_latex_path);

	// Handle the $$Contents(filename) syntax
	if (contains(result, "$$Contents(\"")) {
		// Since use_latex_path may be true we must extract the file
		// name from s instead of result and do the substitutions
		// again, this time with use_latex_path false.
		size_t const spos = s.find("$$Contents(\"");
		size_t const send = s.find("\")", spos);
		string const file_template = s.substr(spos + 12, send - (spos + 12));
		string const file = doSubstitution(params, buffer,
						   file_template, false,
						   external_in_tmpdir, what);
		string contents;

		FileName const absfile(
			makeAbsPath(file, masterBuffer->temppath()));
		if (absfile.isReadableFile())
			// FIXME UNICODE
			contents = to_utf8(absfile.fileContents("UTF-8"));

		size_t const pos = result.find("$$Contents(\"");
		size_t const end = result.find("\")", pos);
		result.replace(pos, end + 2, contents);
	}

	return result;
}