3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "support/FileName.h"
14 #include "support/FileNameList.h"
16 #include "support/convert.h"
17 #include "support/debug.h"
18 #include "support/filetools.h"
19 #include "support/lassert.h"
20 #include "support/lstrings.h"
21 #include "support/qstring_helpers.h"
22 #include "support/os.h"
23 #include "support/Package.h"
24 #include "support/qstring_helpers.h"
31 #include <QTemporaryFile>
34 #include <boost/crc.hpp>
35 #include <boost/scoped_array.hpp>
44 #ifdef HAVE_SYS_TYPES_H
45 # include <sys/types.h>
47 #ifdef HAVE_SYS_STAT_H
48 # include <sys/stat.h>
63 #if defined(HAVE_MKSTEMP) && ! defined(HAVE_DECL_MKSTEMP)
64 extern "C" int mkstemp(char *);
67 #if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
71 # ifdef HAVE_PROCESS_H
76 // Three implementations of checksum(), depending on having mmap support or not.
77 #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
80 #endif // SUM_WITH_MMAP
84 // OK, this is ugly, but it is the only workaround I found to compile
85 // with gcc (any version) on a system which uses a non-GNU toolchain.
86 // The problem is that gcc uses a weak symbol for a particular
87 // instantiation and that the system linker usually does not
88 // understand those weak symbols (seen on HP-UX, tru64, AIX and
89 // others). Thus we force an explicit instanciation of this particular
91 template struct boost::detail::crc_table_t<32, 0x04C11DB7, true>;
96 /////////////////////////////////////////////////////////////////////
100 /////////////////////////////////////////////////////////////////////
102 struct FileName::Private
106 Private(string const & abs_filename) : fi(toqstr(abs_filename))
109 fi.setCaching(fi.exists() ? true : false);
112 inline void refresh()
114 // There seems to be a bug in Qt >= 4.2.0, at least, that causes problems with
115 // QFileInfo::refresh() on *nix. So we recreate the object in that case.
116 // FIXME: When Trolltech fixes the bug, we will have to replace 0x999999 below
117 // with the actual working minimum version.
118 #if defined(_WIN32) || (QT_VERSION >= 0x999999)
121 fi = QFileInfo(fi.absoluteFilePath());
127 bool isFilesystemEqual(QString const & lhs, QString const & rhs)
129 return QString::compare(lhs, rhs, os::isFilesystemCaseSensitive() ?
130 Qt::CaseSensitive : Qt::CaseInsensitive) == 0;
133 /// The absolute file name in UTF-8 encoding.
139 /////////////////////////////////////////////////////////////////////
143 /////////////////////////////////////////////////////////////////////
146 FileName::FileName() : d(new Private)
151 FileName::FileName(string const & abs_filename)
152 : d(abs_filename.empty() ? new Private : new Private(abs_filename))
154 //LYXERR(Debug::FILES, "FileName(" << abs_filename << ')');
155 LASSERT(empty() || isAbsolute(d->name), /**/);
159 FileName::~FileName()
165 FileName::FileName(FileName const & rhs) : d(new Private)
167 d->name = rhs.d->name;
172 FileName::FileName(FileName const & rhs, string const & suffix) : d(new Private)
178 FileName & FileName::operator=(FileName const & rhs)
182 d->name = rhs.d->name;
188 bool FileName::empty() const
190 return d->name.empty();
194 bool FileName::isAbsolute(string const & name)
196 QFileInfo fi(toqstr(name));
197 return fi.isAbsolute();
201 string FileName::absFilename() const
207 string FileName::realPath() const
209 return os::real_path(toFilesystemEncoding());
213 void FileName::set(string const & name)
216 d->fi.setFile(toqstr(name));
217 //LYXERR(Debug::FILES, "FileName::set(" << name << ')');
218 LASSERT(empty() || isAbsolute(d->name), /**/);
222 void FileName::set(FileName const & rhs, string const & suffix)
224 if (!rhs.d->fi.isDir())
225 d->fi.setFile(rhs.d->fi.filePath() + toqstr(suffix));
227 d->fi.setFile(QDir(rhs.d->fi.absoluteFilePath()), toqstr(suffix));
228 d->name = fromqstr(d->fi.absoluteFilePath());
229 //LYXERR(Debug::FILES, "FileName::set(" << d->name << ')');
230 LASSERT(empty() || isAbsolute(d->name), /**/);
234 void FileName::erase()
241 bool FileName::copyTo(FileName const & name) const
243 LYXERR(Debug::FILES, "Copying " << name);
244 QFile::remove(name.d->fi.absoluteFilePath());
245 bool success = QFile::copy(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
247 LYXERR0("FileName::copyTo(): Could not copy file "
248 << *this << " to " << name);
253 bool FileName::renameTo(FileName const & name) const
255 bool success = QFile::rename(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
257 LYXERR0("Could not rename file " << *this << " to " << name);
262 bool FileName::moveTo(FileName const & name) const
264 QFile::remove(name.d->fi.absoluteFilePath());
266 bool success = QFile::rename(d->fi.absoluteFilePath(),
267 name.d->fi.absoluteFilePath());
269 LYXERR0("Could not move file " << *this << " to " << name);
274 bool FileName::changePermission(unsigned long int mode) const
276 #if defined (HAVE_CHMOD) && defined (HAVE_MODE_T)
277 if (::chmod(toFilesystemEncoding().c_str(), mode_t(mode)) != 0) {
278 LYXERR0("File " << *this << ": cannot change permission to "
287 string FileName::toFilesystemEncoding() const
289 // FIXME: This doesn't work on Windows for non ascii file names with Qt < 4.4.
290 // Provided that Windows package uses Qt4.4, this isn't a problem.
291 QByteArray const encoded = QFile::encodeName(d->fi.absoluteFilePath());
292 return string(encoded.begin(), encoded.end());
296 FileName FileName::fromFilesystemEncoding(string const & name)
298 QByteArray const encoded(name.c_str(), name.length());
299 return FileName(fromqstr(QFile::decodeName(encoded)));
303 bool FileName::exists() const
305 return !empty() && d->fi.exists();
309 bool FileName::isSymLink() const
311 return !empty() && d->fi.isSymLink();
315 bool FileName::isFileEmpty() const
317 LASSERT(!empty(), return true);
318 return d->fi.size() == 0;
322 bool FileName::isDirectory() const
324 return !empty() && d->fi.isDir();
328 bool FileName::isReadOnly() const
330 LASSERT(!empty(), return true);
331 return d->fi.isReadable() && !d->fi.isWritable();
335 bool FileName::isReadableDirectory() const
337 return isDirectory() && d->fi.isReadable();
341 string FileName::onlyFileName() const
343 return fromqstr(d->fi.fileName());
347 string FileName::onlyFileNameWithoutExt() const
349 return fromqstr(d->fi.completeBaseName());
353 string FileName::extension() const
355 return fromqstr(d->fi.suffix());
359 bool FileName::hasExtension(const string & ext)
361 return Private::isFilesystemEqual(d->fi.suffix(), toqstr(ext));
365 FileName FileName::onlyPath() const
370 path.d->fi.setFile(d->fi.path());
371 path.d->name = fromqstr(path.d->fi.absoluteFilePath());
376 bool FileName::isReadableFile() const
378 return !empty() && d->fi.isFile() && d->fi.isReadable();
382 bool FileName::isWritable() const
384 return !empty() && d->fi.isWritable();
388 bool FileName::isDirWritable() const
390 LASSERT(isDirectory(), return false);
391 QFileInfo tmp(QDir(d->fi.absoluteFilePath()), "lyxwritetest");
392 QTemporaryFile qt_tmp(tmp.absoluteFilePath());
394 LYXERR(Debug::FILES, "Directory " << *this << " is writable");
397 LYXERR(Debug::FILES, "Directory " << *this << " is not writable");
402 FileNameList FileName::dirList(string const & ext) const
404 FileNameList dirlist;
405 if (!isDirectory()) {
406 LYXERR0("Directory '" << *this << "' does not exist!");
410 QDir dir = d->fi.absoluteDir();
415 case '.': filter = "*" + toqstr(ext); break;
416 case '*': filter = toqstr(ext); break;
417 default: filter = "*." + toqstr(ext);
419 dir.setNameFilters(QStringList(filter));
420 LYXERR(Debug::FILES, "filtering on extension "
421 << fromqstr(filter) << " is requested.");
424 QFileInfoList list = dir.entryInfoList();
425 for (int i = 0; i != list.size(); ++i) {
426 FileName fi(fromqstr(list.at(i).absoluteFilePath()));
427 dirlist.push_back(fi);
428 LYXERR(Debug::FILES, "found file " << fi);
435 static string createTempFile(QString const & mask)
437 QTemporaryFile qt_tmp(mask);
439 string const temp_file = fromqstr(qt_tmp.fileName());
440 LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
443 LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
444 << qt_tmp.fileTemplate());
449 FileName FileName::tempName(FileName const & temp_dir, string const & mask)
451 QFileInfo tmp_fi(QDir(temp_dir.d->fi.absoluteFilePath()), toqstr(mask));
452 LYXERR(Debug::FILES, "Temporary file in " << tmp_fi.absoluteFilePath());
453 return FileName(createTempFile(tmp_fi.absoluteFilePath()));
457 FileName FileName::tempName(string const & mask)
459 return tempName(package().temp_dir(), mask);
463 FileName FileName::getcwd()
465 // return makeAbsPath("."); would create an infinite loop
467 return FileName(fromqstr(fi.absoluteFilePath()));
471 FileName FileName::tempPath()
473 return FileName(os::internal_path(fromqstr(QDir::tempPath())));
477 time_t FileName::lastModified() const
479 // QFileInfo caches information about the file. So, in case this file has
480 // been touched between the object creation and now, we refresh the file
483 return d->fi.lastModified().toTime_t();
487 bool FileName::chdir() const
489 return QDir::setCurrent(d->fi.absoluteFilePath());
493 unsigned long FileName::checksum() const
495 unsigned long result = 0;
498 //LYXERR0("File \"" << absFilename() << "\" does not exist!");
501 // a directory may be passed here so we need to test it. (bug 3622)
503 LYXERR0('"' << absFilename() << "\" is a directory!");
507 // This is used in the debug output at the end of the method.
509 if (lyxerr.debugging(Debug::FILES))
512 #if QT_VERSION >= 0x999999
513 // First version of checksum uses Qt4.4 mmap support.
514 // FIXME: This code is not ready with Qt4.4.2,
515 // see http://bugzilla.lyx.org/show_bug.cgi?id=5293
516 // FIXME: should we check if the MapExtension extension is supported?
517 // see QAbstractFileEngine::supportsExtension() and
518 // QAbstractFileEngine::MapExtension)
519 QFile qf(fi.filePath());
520 if (!qf.open(QIODevice::ReadOnly))
522 qint64 size = fi.size();
523 uchar * ubeg = qf.map(0, size);
524 uchar * uend = ubeg + size;
525 boost::crc_32_type ucrc;
526 ucrc.process_block(ubeg, uend);
529 result = ucrc.checksum();
533 string const encoded = toFilesystemEncoding();
534 char const * file = encoded.c_str();
537 //LYXERR(Debug::FILES, "using mmap (lightning fast)");
539 int fd = open(file, O_RDONLY);
546 void * mm = mmap(0, info.st_size, PROT_READ,
548 // Some platforms have the wrong type for MAP_FAILED (compaq cxx).
549 if (mm == reinterpret_cast<void*>(MAP_FAILED)) {
554 char * beg = static_cast<char*>(mm);
555 char * end = beg + info.st_size;
557 boost::crc_32_type crc;
558 crc.process_block(beg, end);
559 result = crc.checksum();
561 munmap(mm, info.st_size);
564 #else // no SUM_WITH_MMAP
566 //LYXERR(Debug::FILES, "lyx::sum() using istreambuf_iterator (fast)");
567 ifstream ifs(file, ios_base::in | ios_base::binary);
571 istreambuf_iterator<char> beg(ifs);
572 istreambuf_iterator<char> end;
573 boost::crc_32_type crc;
574 crc = for_each(beg, end, crc);
575 result = crc.checksum();
577 #endif // SUM_WITH_MMAP
580 LYXERR(Debug::FILES, "Checksumming \"" << absFilename() << "\" "
581 << result << " lasted " << t.elapsed() << " ms.");
586 bool FileName::removeFile() const
588 bool const success = QFile::remove(d->fi.absoluteFilePath());
590 if (!success && exists())
591 LYXERR0("Could not delete file " << *this);
596 static bool rmdir(QFileInfo const & fi)
598 QDir dir(fi.absoluteFilePath());
599 QFileInfoList list = dir.entryInfoList();
601 for (int i = 0; i != list.size(); ++i) {
602 if (list.at(i).fileName() == ".")
604 if (list.at(i).fileName() == "..")
607 if (list.at(i).isDir()) {
608 LYXERR(Debug::FILES, "Removing dir "
609 << fromqstr(list.at(i).absoluteFilePath()));
610 removed = rmdir(list.at(i));
613 LYXERR(Debug::FILES, "Removing file "
614 << fromqstr(list.at(i).absoluteFilePath()));
615 removed = dir.remove(list.at(i).fileName());
619 LYXERR0("Could not delete "
620 << fromqstr(list.at(i).absoluteFilePath()));
623 QDir parent = fi.absolutePath();
624 success &= parent.rmdir(fi.fileName());
629 bool FileName::destroyDirectory() const
631 bool const success = rmdir(d->fi);
633 LYXERR0("Could not delete " << *this);
639 // Only used in non Win32 platforms
640 static int mymkdir(char const * pathname, unsigned long int mode)
642 // FIXME: why don't we have mode_t in lyx::mkdir prototype ??
644 # if MKDIR_TAKES_ONE_ARG
646 return ::mkdir(pathname);
647 // FIXME: "Permissions of created directories are ignored on this system."
650 return ::mkdir(pathname, mode_t(mode));
652 #elif defined(_WIN32)
654 return CreateDirectory(pathname, 0) != 0 ? 0 : -1;
655 // FIXME: "Permissions of created directories are ignored on this system."
657 return ::_mkdir(pathname);
658 // FIXME: "Permissions of created directories are ignored on this system."
660 # error "Don't know how to create a directory on this system."
666 bool FileName::createDirectory(int permission) const
668 LASSERT(!empty(), return false);
670 // FIXME: "Permissions of created directories are ignored on this system."
673 return mymkdir(toFilesystemEncoding().c_str(), permission) == 0;
678 bool FileName::createPath() const
680 LASSERT(!empty(), return false);
681 LYXERR(Debug::FILES, "creating path '" << *this << "'.");
686 bool success = dir.mkpath(d->fi.absoluteFilePath());
688 LYXERR0("Cannot create path '" << *this << "'!");
693 docstring const FileName::absoluteFilePath() const
695 return qstring_to_ucs4(d->fi.absoluteFilePath());
699 docstring FileName::displayName(int threshold) const
701 return makeDisplayPath(absFilename(), threshold);
705 docstring FileName::fileContents(string const & encoding) const
707 if (!isReadableFile()) {
708 LYXERR0("File '" << *this << "' is not redable!");
712 QFile file(d->fi.absoluteFilePath());
713 if (!file.open(QIODevice::ReadOnly)) {
714 LYXERR0("File '" << *this
715 << "' could not be opened in read only mode!");
718 QByteArray contents = file.readAll();
721 if (contents.isEmpty()) {
722 LYXERR(Debug::FILES, "File '" << *this
723 << "' is either empty or some error happened while reading it.");
728 if (encoding.empty() || encoding == "UTF-8")
729 s = QString::fromUtf8(contents.data());
730 else if (encoding == "ascii")
731 s = QString::fromAscii(contents.data());
732 else if (encoding == "local8bit")
733 s = QString::fromLocal8Bit(contents.data());
734 else if (encoding == "latin1")
735 s = QString::fromLatin1(contents.data());
737 return qstring_to_ucs4(s);
741 void FileName::changeExtension(string const & extension)
743 // FIXME: use Qt native methods...
744 string const oldname = absFilename();
745 string::size_type const last_slash = oldname.rfind('/');
746 string::size_type last_dot = oldname.rfind('.');
747 if (last_dot < last_slash && last_slash != string::npos)
748 last_dot = string::npos;
751 // Make sure the extension starts with a dot
752 if (!extension.empty() && extension[0] != '.')
753 ext= '.' + extension;
757 set(oldname.substr(0, last_dot) + ext);
761 string FileName::guessFormatFromContents() const
763 // the different filetypes and what they contain in one of the first lines
764 // (dots are any characters). (Herbert 20020131)
767 // EPS %!PS-Adobe-3.0 EPSF...
774 // PBM P1... or P4 (B/W)
775 // PGM P2... or P5 (Grayscale)
776 // PPM P3... or P6 (color)
777 // PS %!PS-Adobe-2.0 or 1.0, no "EPSF"!
778 // SGI \001\332... (decimal 474)
780 // TIFF II... or MM...
782 // XPM /* XPM */ sometimes missing (f.ex. tgif-export)
783 // ...static char *...
784 // XWD \000\000\000\151 (0x00006900) decimal 105
786 // GZIP \037\213 http://www.ietf.org/rfc/rfc1952.txt
787 // ZIP PK... http://www.halyava.ru/document/ind_arch.htm
788 // Z \037\235 UNIX compress
791 if (empty() || !isReadableFile())
794 ifstream ifs(toFilesystemEncoding().c_str());
796 // Couldn't open file...
800 static string const gzipStamp = "\037\213";
803 static string const zipStamp = "PK";
806 static string const compressStamp = "\037\235";
808 // Maximum strings to read
809 int const max_count = 50;
814 bool firstLine = true;
815 while ((count++ < max_count) && format.empty()) {
817 LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
818 << "\tFile type not recognised before EOF!");
823 string const stamp = str.substr(0, 2);
824 if (firstLine && str.size() >= 2) {
825 // at first we check for a zipped file, because this
826 // information is saved in the first bytes of the file!
827 // also some graphic formats which save the information
828 // in the first line, too.
829 if (prefixIs(str, gzipStamp)) {
832 } else if (stamp == zipStamp) {
835 } else if (stamp == compressStamp) {
839 } else if (stamp == "BM") {
842 } else if (stamp == "\001\332") {
846 // Don't need to use str.at(0), str.at(1) because
847 // we already know that str.size() >= 2
848 } else if (str[0] == 'P') {
864 } else if ((stamp == "II") || (stamp == "MM")) {
867 } else if (prefixIs(str,"%TGIF")) {
870 } else if (prefixIs(str,"#FIG")) {
873 } else if (prefixIs(str,"GIF")) {
876 } else if (str.size() > 3) {
877 int const c = ((str[0] << 24) & (str[1] << 16) &
878 (str[2] << 8) & str[3]);
889 else if (contains(str,"EPSF"))
890 // dummy, if we have wrong file description like
891 // %!PS-Adobe-2.0EPSF"
894 else if (contains(str, "Grace"))
897 else if (contains(str, "JFIF"))
900 else if (contains(str, "%PDF"))
903 else if (contains(str, "PNG"))
906 else if (contains(str, "%!PS-Adobe")) {
909 if (contains(str,"EPSF"))
915 else if (contains(str, "_bits[]"))
918 else if (contains(str, "XPM") || contains(str, "static char *"))
921 else if (contains(str, "BITPIX"))
925 // Dia knows also compressed form
926 if ((format == "gzip") && (!compare_ascii_no_case(extension(), "dia")))
929 if (!format.empty()) {
930 LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
934 LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
935 << "\tCouldn't find a known format!");
940 bool FileName::isZippedFile() const
942 string const type = guessFormatFromContents();
943 return contains("gzip zip compress", type) && !type.empty();
947 docstring const FileName::relPath(string const & path) const
950 return makeRelPath(absoluteFilePath(), from_utf8(path));
954 // Note: According to Qt, QFileInfo::operator== is undefined when
955 // both files do not exist (Qt4.5 gives true for all non-existent
956 // files, while Qt4.4 compares the filenames).
958 // http://www.qtsoftware.com/developer/task-tracker/
959 // index_html?id=248471&method=entry.
960 bool equivalent(FileName const & l, FileName const & r)
962 // FIXME: In future use Qt.
963 // Qt 4.4: We need to solve this warning from Qt documentation:
964 // * Long and short file names that refer to the same file on Windows are
965 // treated as if they referred to different files.
966 // This is supposed to be fixed for Qt5.
967 FileName const lhs(os::internal_path(l.absFilename()));
968 FileName const rhs(os::internal_path(r.absFilename()));
971 // QFileInfo::operator==() returns false if the two QFileInfo are empty.
975 // Avoid unnecessary checks below.
981 if (!lhs.d->fi.isSymLink() && !rhs.d->fi.isSymLink()) {
982 // Qt already checks if the filesystem is case sensitive or not.
983 // see note above why the extra check with fileName is needed.
984 return lhs.d->fi == rhs.d->fi
985 && lhs.d->fi.fileName() == rhs.d->fi.fileName();
988 // FIXME: When/if QFileInfo support symlink comparison, remove this code.
989 QFileInfo fi1(lhs.d->fi);
991 fi1 = QFileInfo(fi1.symLinkTarget());
992 QFileInfo fi2(rhs.d->fi);
994 fi2 = QFileInfo(fi2.symLinkTarget());
995 // see note above why the extra check with fileName is needed.
996 return fi1 == fi2 && fi1.fileName() == fi2.fileName();
1000 bool operator==(FileName const & lhs, FileName const & rhs)
1002 return os::isFilesystemCaseSensitive()
1003 ? lhs.absFilename() == rhs.absFilename()
1004 : !QString::compare(toqstr(lhs.absFilename()),
1005 toqstr(rhs.absFilename()), Qt::CaseInsensitive);
1009 bool operator!=(FileName const & lhs, FileName const & rhs)
1011 return !(operator==(lhs, rhs));
1015 bool operator<(FileName const & lhs, FileName const & rhs)
1017 return lhs.absFilename() < rhs.absFilename();
1021 bool operator>(FileName const & lhs, FileName const & rhs)
1023 return lhs.absFilename() > rhs.absFilename();
1027 ostream & operator<<(ostream & os, FileName const & filename)
1029 return os << filename.absFilename();
1033 /////////////////////////////////////////////////////////////////////
1037 /////////////////////////////////////////////////////////////////////
1040 DocFileName::DocFileName()
1041 : save_abs_path_(true)
1045 DocFileName::DocFileName(string const & abs_filename, bool save_abs)
1046 : FileName(abs_filename), save_abs_path_(save_abs), zipped_valid_(false)
1050 DocFileName::DocFileName(FileName const & abs_filename, bool save_abs)
1051 : FileName(abs_filename), save_abs_path_(save_abs), zipped_valid_(false)
1055 void DocFileName::set(string const & name, string const & buffer_path)
1057 save_abs_path_ = isAbsolute(name);
1059 FileName::set(name);
1061 FileName::set(makeAbsPath(name, buffer_path).absFilename());
1062 zipped_valid_ = false;
1066 void DocFileName::erase()
1069 zipped_valid_ = false;
1073 string DocFileName::relFilename(string const & path) const
1076 return to_utf8(relPath(path));
1080 string DocFileName::outputFilename(string const & path) const
1082 return save_abs_path_ ? absFilename() : relFilename(path);
1086 string DocFileName::mangledFilename(string const & dir) const
1088 // We need to make sure that every DocFileName instance for a given
1089 // filename returns the same mangled name.
1090 typedef map<string, string> MangledMap;
1091 static MangledMap mangledNames;
1092 MangledMap::const_iterator const it = mangledNames.find(absFilename());
1093 if (it != mangledNames.end())
1094 return (*it).second;
1096 string const name = absFilename();
1097 // Now the real work
1098 string mname = os::internal_path(name);
1099 // Remove the extension.
1100 mname = support::changeExtension(name, string());
1101 // The mangled name must be a valid LaTeX name.
1102 // The list of characters to keep is probably over-restrictive,
1103 // but it is not really a problem.
1104 // Apart from non-ASCII characters, at least the following characters
1105 // are forbidden: '/', '.', ' ', and ':'.
1106 // On windows it is not possible to create files with '<', '>' or '?'
1108 static string const keep = "abcdefghijklmnopqrstuvwxyz"
1109 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1111 string::size_type pos = 0;
1112 while ((pos = mname.find_first_not_of(keep, pos)) != string::npos)
1114 // Add the extension back on
1115 mname = support::changeExtension(mname, getExtension(name));
1117 // Prepend a counter to the filename. This is necessary to make
1118 // the mangled name unique.
1119 static int counter = 0;
1121 s << counter++ << mname;
1124 // MiKTeX's YAP (version 2.4.1803) crashes if the file name
1125 // is longer than about 160 characters. MiKTeX's pdflatex
1126 // is even pickier. A maximum length of 100 has been proven to work.
1127 // If dir.size() > max length, all bets are off for YAP. We truncate
1128 // the filename nevertheless, keeping a minimum of 10 chars.
1130 string::size_type max_length = max(100 - ((int)dir.size() + 1), 10);
1132 // If the mangled file name is too long, hack it to fit.
1133 // We know we're guaranteed to have a unique file name because
1135 if (mname.size() > max_length) {
1136 int const half = (int(max_length) / 2) - 2;
1138 mname = mname.substr(0, half) + "___" +
1139 mname.substr(mname.size() - half);
1143 mangledNames[absFilename()] = mname;
1148 bool DocFileName::isZipped() const
1150 if (!zipped_valid_) {
1151 zipped_ = isZippedFile();
1152 zipped_valid_ = true;
1158 string DocFileName::unzippedFilename() const
1160 return unzippedFileName(absFilename());
1164 bool operator==(DocFileName const & lhs, DocFileName const & rhs)
1166 return static_cast<FileName const &>(lhs)
1167 == static_cast<FileName const &>(rhs)
1168 && lhs.saveAbsPath() == rhs.saveAbsPath();
1172 bool operator!=(DocFileName const & lhs, DocFileName const & rhs)
1174 return !(lhs == rhs);
1177 } // namespace support