]> git.lyx.org Git - features.git/commitdiff
I'll find a solution for the 'dirList problem', Abdel.
authorAndré Pönitz <poenitz@gmx.net>
Fri, 30 Nov 2007 20:57:53 +0000 (20:57 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 30 Nov 2007 20:57:53 +0000 (20:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21884 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
development/attic/cow_ptr.h [new file with mode: 0644]
development/tools/count_total_lines_of_compiled_code.sh
src/Converter.cpp
src/EmbeddedFiles.h
src/ModuleList.h
src/main.cpp
src/support/FileName.cpp
src/support/FileName.h
src/support/filetools.h
src/support/lstrings.cpp
src/support/lstrings.h
src/support/strfwd.h

diff --git a/development/attic/cow_ptr.h b/development/attic/cow_ptr.h
new file mode 100644 (file)
index 0000000..685d0e4
--- /dev/null
@@ -0,0 +1,124 @@
+// -*- C++ -*-
+/**
+ * \file cow_ptr.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * A pointer with copy-on-write semantics
+ *
+ * The original version of this class was written by Yonat Sharon
+ * and is freely available at http://ootips.org/yonat/
+ *
+ * I modified it to use boost::shared_ptr internally, rather than use his
+ * home-grown equivalent.
+ */
+
+#ifndef COW_PTR_H
+#define COW_PTR_H
+
+#include <boost/shared_ptr.hpp>
+
+
+namespace lyx {
+namespace support {
+
+template <typename T>
+class cow_ptr {
+public:
+       explicit cow_ptr(T * = 0);
+       cow_ptr(cow_ptr const &);
+       cow_ptr & operator=(cow_ptr const &);
+
+       T const & operator*() const;
+       T const * operator->() const;
+       T const * get() const;
+
+       T & operator*();
+       T * operator->();
+       T * get();
+
+private:
+       boost::shared_ptr<T> ptr_;
+       void copy();
+};
+
+
+template <typename T>
+cow_ptr<T>::cow_ptr(T * p)
+       : ptr_(p)
+{}
+
+
+template <typename T>
+cow_ptr<T>::cow_ptr(cow_ptr const & other)
+       : ptr_(other.ptr_)
+{}
+
+
+template <typename T>
+cow_ptr<T> & cow_ptr<T>::operator=(cow_ptr const & other)
+{
+       if (&other != this)
+               ptr_ = other.ptr_;
+       return *this;
+}
+
+
+template <typename T>
+T const & cow_ptr<T>::operator*() const
+{
+       return *ptr_;
+}
+
+
+template <typename T>
+T const * cow_ptr<T>::operator->() const
+{
+       return ptr_.get();
+}
+
+
+template <typename T>
+T const * cow_ptr<T>::get() const
+{
+       return ptr_.get();
+}
+
+
+template <typename T>
+T & cow_ptr<T>::operator*()
+{
+       copy();
+       return *ptr_;
+}
+
+
+template <typename T>
+T * cow_ptr<T>::operator->()
+{
+       copy();
+       return ptr_.get();
+}
+
+
+template <typename T>
+T * cow_ptr<T>::get()
+{
+       copy();
+       return ptr_.get();
+}
+
+
+template <typename T>
+void cow_ptr<T>::copy()
+{
+       if (!ptr_.unique())
+               ptr_ = boost::shared_ptr<T>(new T(*ptr_.get()));
+}
+
+} // namespace support
+} // namespace lyx
+
+#endif // NOT COW_PTR_H
index dc407bdb8f6d406b643e9e8d413fa5f38a6de286..0196d262c0bc4deec76136af025f8a47b389f917 100755 (executable)
@@ -20,11 +20,12 @@ t=0
 #for i in `find ../../src/support -name '*.cpp'` ; do
 #for i in `find ../../src/graphics -name '*.cpp'` ; do
 #for i in `find ../../src/graphics -name '*.cpp'` ; do
-#for i in ../../src/*.cpp ; do
+#for i in `find ../../src/support/chdir.cpp` ; do
 for i in `find ../.. -name '*.cpp'` ; do
        #echo $i
        #echo "g++ $inc -DQT_NO_STL -E $i"
        #g++ $inc -DQT_NO_STL -E $i > tmp/`basename $i`
+       g++ $inc -DQT_NO_STL -E $i > t
        l=`g++ $inc -DQT_NO_STL -E $i | wc -l`
        f=`cat $i | wc -l`
        s=$[s + l]
index 6715e028c0e1d3158dfe024bda36bf001f199901..fc82114308018ffbb6d284c006800b2f2e52d9ab 100644 (file)
@@ -519,8 +519,8 @@ bool Converters::move(string const & fmt,
        string const to_base = removeExtension(to.absFilename());
        string const to_extension = getExtension(to.absFilename());
 
-       vector<FileName> const files = FileName(path).dirList(
-               getExtension(from.absFilename()));
+       vector<FileName> const files =
+                       support::dirList(FileName(path), getExtension(from.absFilename()));
        for (vector<FileName>::const_iterator it = files.begin();
             it != files.end(); ++it) {
                string const from2 = it->absFilename();
index 277d9d3638dcdaac3107ac7556b19d8725a571e1..e7d80f48a848379b7254221aa7bbf0b0d677802e 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "support/FileName.h"
 
+#include <string>
 #include <vector>
 
 /**
index bab9a049ae1f1f6ec7b51a34dcd09058047c1584..09d793a23549ba1a1724e306899afcded6de7301 100644 (file)
@@ -15,6 +15,7 @@
 #include "support/FileName.h"
 
 #include <map>
+#include <string>
 #include <vector>
 
 namespace lyx {
index 41ce51a772e85d57823e1bffbf252753f1986b6a..384724aecbe232c41131905314aadfd20137ee6a 100644 (file)
 
 #include <config.h>
 
-#include "support/debug.h"
 #include "LyX.h"
-#include "support/gettext.h"
 
+#include "support/debug.h"
+#include "support/gettext.h"
 #include "support/os.h"
 
 #include <iostream>
@@ -33,6 +33,8 @@ int main(int argc, char * argv[])
        // early as possible.
        lyx::lyxerr.setStream(std::cerr);
 
+       LYXERR0("acssdc");
+
        lyx::support::os::init(argc, argv);
 
        // initialize for internationalized version *EK*
index 7c594da86c04e5da3b932ec76eeeaac55436b093..5704d2cb0241ae6ac338a714b5b9777599c82fd9 100644 (file)
@@ -268,7 +268,7 @@ static bool rmdir(QFileInfo const & fi)
        QDir dir(fi.absoluteFilePath());
        QFileInfoList list = dir.entryInfoList();
        bool global_success = true;
-       for (int i = 0; i < list.size(); ++i) {
+       for (int i = 0; i != list.size(); ++i) {
                if (list.at(i).fileName() == ".")
                        continue;
                if (list.at(i).fileName() == "..")
@@ -313,16 +313,15 @@ bool FileName::createDirectory(int permission) const
 }
 
 
-std::vector<FileName> FileName::dirList(std::string const & ext)
+std::vector<FileName> dirList(FileName const & dirname, std::string const & ext)
 {
        std::vector<FileName> dirlist;
-       if (!exists() || !isDirectory()) {
-               lyxerr << "FileName::dirList(): Directory \"" << absFilename()
-                       << "\" does not exist!" << endl;
+       if (!dirname.isDirectory()) {
+               LYXERR0("Directory '" << dirname << "' does not exist!");
                return dirlist;
        }
 
-       QDir dir(d->fi.absoluteFilePath());
+       QDir dir(dirname.d->fi.absoluteFilePath());
 
        if (!ext.empty()) {
                QString filter;
@@ -332,17 +331,16 @@ std::vector<FileName> FileName::dirList(std::string const & ext)
                default: filter = "*." + toqstr(ext);
                }
                dir.setNameFilters(QStringList(filter));
-               LYXERR(Debug::FILES, "FileName::dirList(): filtering on extension "
-                       << fromqstr(filter) << " is requested." << endl);
+               LYXERR(Debug::FILES, "filtering on extension "
+                       << fromqstr(filter) << " is requested.");
        }
 
        QFileInfoList list = dir.entryInfoList();
-       for (int i = 0; i < list.size(); ++i) {
+       for (int i = 0; i != list.size(); ++i) {
                FileName fi;
                fi.d->fi = list.at(i);
                dirlist.push_back(fi);
-               LYXERR(Debug::FILES, "FileName::dirList(): found file "
-                       << fi.absFilename() << endl);
+               LYXERR(Debug::FILES, "found file " << fi);
        }
 
        return dirlist;
@@ -641,20 +639,20 @@ void DocFileName::erase()
 }
 
 
-string const DocFileName::relFilename(string const & path) const
+string DocFileName::relFilename(string const & path) const
 {
        // FIXME UNICODE
        return to_utf8(makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path)));
 }
 
 
-string const DocFileName::outputFilename(string const & path) const
+string DocFileName::outputFilename(string const & path) const
 {
        return save_abs_path_ ? absFilename() : relFilename(path);
 }
 
 
-string const DocFileName::mangledFilename(std::string const & dir) const
+string DocFileName::mangledFilename(std::string const & dir) const
 {
        // We need to make sure that every DocFileName instance for a given
        // filename returns the same mangled name.
@@ -726,7 +724,7 @@ bool DocFileName::isZipped() const
 }
 
 
-string const DocFileName::unzippedFilename() const
+string DocFileName::unzippedFilename() const
 {
        return unzippedFileName(absFilename());
 }
index 0151c7fa819a3652efc368c99a145bde86b5b499..b6a4d85086046b71a73cfe5e1062db1e2010e251 100644 (file)
 #include "support/strfwd.h"
 
 #include <ctime>
-#include <string>
-#include <vector>
 
 
 namespace lyx {
 namespace support {
 
-
 /**
  * Class for storing file names.
  * The file name may be empty. If it is not empty it is an absolute path.
@@ -101,10 +98,6 @@ public:
        /// Creates directory. Returns true on success
        bool createDirectory(int permissions) const;
 
-       /// \return list files in a directory having optional extension ext..
-       std::vector<FileName> dirList(
-               std::string const & ext = std::string());
-
        /// Get the contents of a file as a huge std::string
        std::string fileContents() const;
        /**
@@ -119,7 +112,7 @@ public:
        * If oldname does not have an extension, it is appended.
        * If the extension is empty, any extension is removed from the name.
        */
-        void changeExtension(std::string const & extension);
+       void changeExtension(std::string const & extension);
 
        /** Guess the file format name (as in Format::name()) from contents.
         Normally you don't want to use this directly, but rather
@@ -134,7 +127,7 @@ public:
        /// (securely) create a temporary file in the given dir with the given mask
        /// \p mask must be in filesystem encoding
        static FileName tempName(FileName const & dir = FileName(),
-                                               std::string const & mask = std::string());
+                                               std::string const & mask = empty_string());
 
        /// filename without path
        std::string onlyFileName() const;
@@ -143,7 +136,7 @@ public:
        /// used for display in the Gui
        docstring displayName(int threshold = 1000) const;
 
-private:
+//private:
        friend class DocFileName;
        ///
        struct Private;
@@ -184,9 +177,9 @@ public:
 
        bool saveAbsPath() const { return save_abs_path_; }
        /// \param buffer_path if empty, uses `pwd`
-       std::string const relFilename(std::string const & buffer_path = std::string()) const;
+       std::string relFilename(std::string const & buffer_path = empty_string()) const;
        /// \param buf_path if empty, uses `pwd`
-       std::string const outputFilename(std::string const & buf_path = std::string()) const;
+       std::string outputFilename(std::string const & buf_path = empty_string()) const;
        
        /** @returns a mangled representation of the absolute file name
         *  suitable for use in the temp dir when, for example, converting
@@ -208,13 +201,13 @@ public:
         *  Only the mangled file name is returned. It is not prepended
         *  with @c dir.
         */
-       std::string const
-       mangledFilename(std::string const & dir = std::string()) const;
+       std::string
+       mangledFilename(std::string const & dir = empty_string()) const;
 
        /// \return true if the file is compressed.
        bool isZipped() const;
        /// \return the absolute file name without its .gz, .z, .Z extension
-       std::string const unzippedFilename() const;
+       std::string unzippedFilename() const;
 
 private:
        bool save_abs_path_;
index 5bd8167fb64f613e7b33b220ad1e856102441872..383aeac2f8b58cf937d9ba8a56dc5cb29a9d5516 100644 (file)
@@ -275,6 +275,10 @@ typedef std::pair<int, std::string> cmd_ret;
 
 cmd_ret const runCommand(std::string const & cmd);
 
+/// \return list files in a directory having optional extension ext..
+std::vector<FileName> dirList(FileName const & dir,
+               std::string const & ext = empty_string());
+
 } // namespace support
 } // namespace lyx
 
index 7aeefdfb527528680c351cb17515d2282b5e2355..1952300ecd305f17713893761bb51ce291e591f8 100644 (file)
@@ -42,6 +42,22 @@ using std::toupper;
 
 namespace lyx {
 
+// Using this allows us to have docstring default arguments in headers
+// without #include "support/docstring" there.
+docstring const & empty_docstring()
+{
+       static docstring s;
+       return s;
+}
+
+// Using this allows us to have std::string default arguments in headers
+// without #include <string>
+std::string const & empty_string()
+{
+       static std::string s;
+       return s;
+}
+
 /**
  * Convert a QChar into a UCS4 character.
  * This is a hack (it does only make sense for the common part of the UCS4
@@ -232,73 +248,77 @@ int compare_ascii_no_case(docstring const & s, docstring const & s2)
 
 bool isStrInt(string const & str)
 {
-       if (str.empty()) return false;
+       if (str.empty())
+               return false;
 
        // Remove leading and trailing white space chars.
        string const tmpstr = trim(str);
-       if (tmpstr.empty()) return false;
+       if (tmpstr.empty())
+               return false;
 
        string::const_iterator cit = tmpstr.begin();
-       if ((*cit) == '-') ++cit;
+       if ((*cit) == '-')
+               ++cit;
+
        string::const_iterator end = tmpstr.end();
-       for (; cit != end; ++cit) {
-               if (!isdigit((*cit))) return false;
-       }
+       for (; cit != end; ++cit)
+               if (!isdigit((*cit)))
+                       return false;
+
        return true;
 }
 
 
 bool isStrUnsignedInt(string const & str)
 {
-       if (str.empty()) return false;
+       if (str.empty())
+               return false;
 
        // Remove leading and trailing white space chars.
        string const tmpstr = trim(str);
-       if (tmpstr.empty()) return false;
+       if (tmpstr.empty())
+               return false;
 
        string::const_iterator cit = tmpstr.begin();
        string::const_iterator end = tmpstr.end();
-       for (; cit != end; ++cit) {
-               if (!isdigit((*cit))) return false;
-       }
+       for (; cit != end; ++cit)
+               if (!isdigit((*cit)))
+                       return false;
+
        return true;
 }
 
 
 bool isStrDbl(string const & str)
 {
-       if (str.empty()) return false;
+       if (str.empty())
+               return false;
 
        // Remove leading and trailing white space chars.
        string const tmpstr = trim(str);
-       if (tmpstr.empty()) return false;
-       //      if (1 < tmpstr.count('.')) return false;
+       if (tmpstr.empty())
+               return false;
+       //      if (tmpstr.count('.') > 1) return false;
 
        string::const_iterator cit = tmpstr.begin();
-       bool found_dot(false);
-       if ((*cit) == '-') ++cit;
+       bool found_dot = false;
+       if (*cit == '-')
+               ++cit;
        string::const_iterator end = tmpstr.end();
        for (; cit != end; ++cit) {
-               if (!isdigit((*cit))
-                   && '.' != (*cit)) {
+               if (!isdigit(*cit) && *cit != '.')
                        return false;
-               }
                if ('.' == (*cit)) {
-                       if (found_dot) {
+                       if (found_dot)
                                return false;
-                       } else {
-                               found_dot = true;
-                       }
+                       found_dot = true;
                }
        }
        return true;
 }
 
 
-namespace {
-
-inline
-bool isHexChar(char_type c)
+static bool isHexChar(char_type c)
 {
        return c == '0' ||
                c == '1' ||
@@ -318,8 +338,6 @@ bool isHexChar(char_type c)
                c == 'f' || c == 'F';
 }
 
-} // anon namespace
-
 
 bool isHex(docstring const & str)
 {
@@ -567,7 +585,8 @@ string const token(string const & a, char delim, int n)
 
 docstring const token(docstring const & a, char_type delim, int n)
 {
-       if (a.empty()) return docstring();
+       if (a.empty())
+               return docstring();
 
        size_t k = 0;
        size_t i = 0;
index f22e6564d819f66bf2ef83e68baa9147cf36608a..cfb504f2dbe9ab762a95622ccc19e72aa766ddcc 100644 (file)
@@ -19,6 +19,7 @@
 #include "support/docstring.h"
 
 #include <cstring>
+#include <string>
 #include <vector>
 
 
index 8dfed6e794031395916f7ed75b514542caa8e5b1..85dfed168fc46a06438153fa8faa2fbc1e042f6f 100644 (file)
@@ -67,6 +67,9 @@ typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream;
 extern odocstream & operator<<(odocstream &, char);
 #endif
 
+docstring const & empty_docstring();
+std::string const & empty_string();
+
 } // namespace lyx
 
 #endif