]> git.lyx.org Git - lyx.git/blobdiff - src/Format.cpp
Support new languages in tex2lyx
[lyx.git] / src / Format.cpp
index 44e3f634d0cd34763b42be52c2b0cefc019df108..82712af0cd25a40dfd2cb75ea29ac55ac6661a2c 100644 (file)
@@ -22,6 +22,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/os.h"
 #include "support/PathChanger.h"
 #include "support/Systemcall.h"
@@ -241,17 +242,13 @@ string guessFormatFromContents(FileName const & fn)
        int const max_count = 50;
        int count = 0;
 
-       // Maximum number of binary chars allowed for latex detection
-       int const max_bin = 5;
-
        string str;
        string format;
        bool firstLine = true;
        bool backslash = false;
        bool maybelatex = false;
-       int binchars = 0;
        int dollars = 0;
-       while ((count++ < max_count) && format.empty() && binchars <= max_bin) {
+       while ((count++ < max_count) && format.empty() && !maybelatex) {
                if (ifs.eof())
                        break;
 
@@ -378,17 +375,9 @@ string guessFormatFromContents(FileName const & fn)
                                // inline equation
                                maybelatex = true;
                }
-
-               // Note that this is formally not correct, since count_bin_chars
-               // expects utf8, and str can be anything: plain text in any
-               // encoding, or really binary data. In practice it works, since
-               // QString::fromUtf8() drops invalid utf8 sequences, and while
-               // the exact number may not be correct, we still get a high
-               // number for truly binary files.
-               binchars += count_bin_chars(str);
        }
 
-       if (format.empty() && binchars <= max_bin && maybelatex)
+       if (format.empty() && maybelatex && !isBinaryFile(fn))
                format = "latex";
 
        if (format.empty()) {
@@ -515,14 +504,15 @@ struct ZippedInfo {
 };
 
 
-// FIXME THREAD
 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
 static std::map<std::string, ZippedInfo> zipped_;
+static Mutex zipped_mutex;
 
 
 bool Formats::isZippedFile(support::FileName const & filename) const {
        string const & fname = filename.absFileName();
        time_t timestamp = filename.lastModified();
+       Mutex::Locker lock(&zipped_mutex);
        map<string, ZippedInfo>::iterator it = zipped_.find(fname);
        if (it != zipped_.end() && it->second.timestamp == timestamp)
                return it->second.zipped;