+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * format.[Ch] (getFormatFromFile): new method
+ * exporter.C: s/getFormatFromContents/formats.getFormatFromFile/
+
2004-11-09 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lengthcommon.C (unitFromString): fix off-by-one error (bug 1682)
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * client.C: remove format hack
+
2004-10-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* client.C (formats): new, needed for libsupport.a
#include <config.h>
#include "debug.h"
-#include "format.h"
#include "support/lstrings.h"
#include <boost/filesystem/operations.hpp>
using std::endl;
-// hack to link in libsupport
-Formats formats;
-
-
namespace support {
string itoa(unsigned int i)
using lyx::support::bformat;
using lyx::support::ChangeExtension;
using lyx::support::contains;
-using lyx::support::getFormatFromContents;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
CopyStatus status = SUCCESS;
for (vector<ExportedFile>::const_iterator it = files.begin();
it != files.end() && status != CANCEL; ++it) {
- string const fmt = getFormatFromContents(it->sourceName);
+ string const fmt =
+ formats.getFormatFromFile(it->sourceName);
status = copyFile(fmt, it->sourceName,
MakeAbsPath(it->exportName, dest),
it->exportName, status == FORCE);
string name_;
};
+
+class FormatExtensionsEqual : public std::unary_function<Format, bool> {
+public:
+ FormatExtensionsEqual(string const & extension)
+ : extension_(extension) {}
+ bool operator()(Format const & f) const
+ {
+ return f.extension() == extension_;
+ }
+private:
+ string extension_;
+};
+
} //namespace anon
bool operator<(Format const & a, Format const & b)
}
+string Formats::getFormatFromFile(string const & filename) const
+{
+ if (filename.empty())
+ return string();
+
+ string const format = lyx::support::getFormatFromContents(filename);
+ if (!format.empty())
+ return format;
+
+ // try to find a format from the file extension.
+ string const ext(lyx::support::GetExtension(filename));
+ if (!ext.empty()) {
+ // this is ambigous if two formats have the same extension,
+ // but better than nothing
+ Formats::const_iterator cit =
+ find_if(formatlist.begin(), formatlist.end(),
+ FormatExtensionsEqual(ext));
+ if (cit != formats.end()) {
+ lyxerr[Debug::GRAPHICS]
+ << "\twill guess format from file extension: "
+ << ext << " -> " << cit->name() << std::endl;
+ return cit->name();
+ }
+ }
+ return string();
+}
+
+
int Formats::getNumber(string const & name) const
{
FormatList::const_iterator cit =
}
/// \returns format named \p name if it exists, otherwise 0
Format const * getFormat(std::string const & name) const;
+ /*!
+ * Get the format of \p filename from file contents or, if this
+ * fails, from file extension.
+ * \returns file format if it could be found, otherwise an empty
+ * string.
+ */
+ std::string getFormatFromFile(std::string const & filename) const;
///
int getNumber(std::string const & name) const;
///
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * ControlInclude.C (browse): Use GetExtension() instead of
+ getFormatFromContents()
+
2004-11-05 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlRef.C (gotoRef, gotoBookmark):
void ControlInclude::load(string const & file)
{
- string const format = support::getFormatFromContents(file);
- if (format == "lyx")
+ string const ext = support::GetExtension(file);
+ if (ext == "lyx")
kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
else
// tex file or other text file in verbatim mode
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * GraphicsCacheItem.C:
+ s/getFormatFromContents/formats.getFormatFromFile/
+
2004-10-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* GraphicsCacheItem.C: s/getExtFromContents/getFormatFromContents/
#include "GraphicsImage.h"
#include "debug.h"
+#include "format.h"
#include "support/filetools.h"
#include "support/FileMonitor.h"
using support::IsFileReadable;
using support::MakeDisplayPath;
using support::OnlyFilename;
-using support::getFormatFromContents;
using support::tempName;
using support::unlink;
using support::unzipFile;
<< "\n\twith displayed filename: " << displayed_filename
<< endl;
- string from = getFormatFromContents(filename);
+ string const from = formats.getFormatFromFile(filename);
+ if (from.empty()) {
+ setStatus(ErrorConverting);
+ lyxerr[Debug::GRAPHICS]
+ << "\tCould not determine file format." << endl;
+ return;
+ }
lyxerr[Debug::GRAPHICS]
<< "\n\tThe file contains " << from << " format data." << endl;
string const to = findTargetFormat(from);
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * ExternalSupport.C, insetgraphics.C:
+ s/getFormatFromContents/formats.getFormatFromFile/
+
2004-11-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetcharstyle.[Ch]:
{
string const file_with_path = params.filename.absFilename();
formats.edit(buffer, file_with_path,
- support::getFormatFromContents(file_with_path));
+ formats.getFormatFromFile(file_with_path));
}
return; // NOT_NEEDED
// Try and ascertain the file format from its contents.
- from_format = support::getFormatFromContents(abs_from_file);
+ from_format = formats.getFormatFromFile(abs_from_file);
if (from_format.empty())
return; // FAILURE
using lyx::support::FileName;
using lyx::support::float_equal;
using lyx::support::GetExtension;
-using lyx::support::getFormatFromContents;
using lyx::support::IsFileReadable;
using lyx::support::LibFileSearch;
using lyx::support::OnlyFilename;
// Nothing to do...
return std::make_pair(IDENTICAL_CONTENTS, file_out);
- Mover const & mover = movers(getFormatFromContents(file_in));
+ Mover const & mover = movers(formats.getFormatFromFile(file_in));
bool const success = mover.copy(file_in, file_out);
if (!success) {
lyxerr[Debug::GRAPHICS]
}
}
- string const from = getFormatFromContents(temp_file);
+ string const from = formats.getFormatFromFile(temp_file);
+ if (from.empty()) {
+ lyxerr[Debug::GRAPHICS]
+ << "\tCould not get file format." << endl;
+ return orig_file;
+ }
string const to = findTargetFormat(from, runparams);
string const ext = formats.extension(to);
lyxerr[Debug::GRAPHICS]
}
-void InsetGraphics::editGraphics(InsetGraphicsParams const & p, Buffer const & buffer) const
+void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
+ Buffer const & buffer) const
{
string const file_with_path = p.filename.absFilename();
- formats.edit(buffer, file_with_path, getFormatFromContents(file_with_path));
+ formats.edit(buffer, file_with_path,
+ formats.getFormatFromFile(file_with_path));
}
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * filetools.[Ch] (getFormatFromContents): don't guess format from
+ extension, return string() instead of "user" if the format could
+ not be determined
+
2004-11-07 Lars Gullik Bjonnes <larsbj@gullik.net>
* Make it clearer where include files are comming from.
// FIXME Interface violation
#include "gettext.h"
#include "debug.h"
-//#include "format.h"
#include <boost/assert.hpp>
#include <boost/regex.hpp>
}
-#if 0
-namespace {
-
-class FormatExtensionsEqual : public std::unary_function<Format, bool> {
-public:
- FormatExtensionsEqual(string const & extension)
- : extension_(extension) {}
- bool operator()(Format const & f) const
- {
- return f.extension() == extension_;
- }
-private:
- string extension_;
-};
-
-} // namespace anon
-#endif
-
-
// the different filetypes and what they contain in one of the first lines
// (dots are any characters). (Herbert 20020131)
// AGR Grace...
// ZIP PK... http://www.halyava.ru/document/ind_arch.htm
// Z \037\235 UNIX compress
-/// return the "extension" which belongs to the contents.
-/// for no knowing contents return the extension. Without
-/// an extension and unknown contents we return "user"
string const getFormatFromContents(string const & filename)
{
// paranoia check
return format;
}
- string const ext(GetExtension(filename));
lyxerr[Debug::GRAPHICS]
<< "filetools(getFormatFromContents)\n"
<< "\tCouldn't find a known format!\n";
-#if 0
- // This just cannot be here. It is a blatant violation of interfaces.
- // Nothing in support should have any knowledge of internal structures
- // in the rest of lyx. This case needs to be explictly checked for
- // in the places where this function is called. Also it makes the
- // function name a lie. (Lgb)
- if (!ext.empty()) {
- // this is ambigous if two formats have the same extension,
- // but better than nothing
- Formats::const_iterator cit =
- find_if(formats.begin(), formats.end(),
- FormatExtensionsEqual(ext));
- if (cit != formats.end()) {
- lyxerr[Debug::GRAPHICS]
- << "\twill guess format from file extension: "
- << ext << " -> " << cit->name() << endl;
- return cit->name();
- }
- }
-#endif
- lyxerr[Debug::GRAPHICS]
- << "\twill use a \"user\" defined format" << endl;
- return "user";
+ return string();
}
/// Return the extension of the file (not including the .)
std::string const GetExtension(std::string const & name);
-/// Guess the file format name (as in Format::name()) from contents
+/** Guess the file format name (as in Format::name()) from contents.
+ Normally you don't want to use this directly, but rather
+ Formats::getFormatFromFile().
+ */
std::string const getFormatFromContents(std::string const & name);
/// check for zipped file
+2004-11-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * tex2lyx.C: remove format hack
+
2004-11-07 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* texparser.C (getNewline): new
#include "context.h"
#include "debug.h"
-#include "format.h"
#include "lyxtextclass.h"
#include "support/path_defines.h"
#include "support/filetools.h"
LyXErr lyxerr(std::cerr.rdbuf());
-// hack to link in libsupport
-Formats formats;
-
-
string const trim(string const & a, char const * p)
{
// BOOST_ASSERT(p);