mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
Fix some zlib issues, use a temp file for lyx2lyx conversion.
Simplify some parts of file loading and insertion. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7631 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
36d1797dad
commit
9d3229d5d7
@ -183,7 +183,6 @@ src/mathed/ref_inset.C
|
||||
src/paragraph.C
|
||||
src/paragraph_funcs.C
|
||||
src/rowpainter.C
|
||||
src/support/path_defines.C
|
||||
src/text.C
|
||||
src/text2.C
|
||||
src/text3.C
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "support/filetools.h"
|
||||
#include "support/types.h"
|
||||
#include "support/lyxalgo.h" // lyx_count
|
||||
#include "support/LAssert.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@ -271,51 +272,15 @@ bool BufferView::insertLyXFile(string const & filen)
|
||||
//
|
||||
// Moved from lyx_cb.C (Lgb)
|
||||
{
|
||||
if (filen.empty())
|
||||
return false;
|
||||
Assert(!filen.empty());
|
||||
|
||||
string const fname = MakeAbsPath(filen);
|
||||
|
||||
// check if file exist
|
||||
FileInfo const fi(fname);
|
||||
|
||||
if (!fi.readable()) {
|
||||
string const file = MakeDisplayPath(fname, 50);
|
||||
string const text =
|
||||
bformat(_("The specified document\n%1$s\ncould not be read."), file);
|
||||
Alert::error(_("Could not read document"), text);
|
||||
return false;
|
||||
}
|
||||
|
||||
beforeChange(text);
|
||||
|
||||
ifstream ifs(fname.c_str());
|
||||
if (!ifs) {
|
||||
string const file = MakeDisplayPath(fname, 50);
|
||||
string const text =
|
||||
bformat(_("Could not open the specified document %1$s\n"), file);
|
||||
Alert::error(_("Could not open file"), text);
|
||||
return false;
|
||||
}
|
||||
|
||||
int const c = ifs.peek();
|
||||
|
||||
LyXLex lex(0, 0);
|
||||
lex.setStream(ifs);
|
||||
|
||||
bool res = true;
|
||||
|
||||
text->breakParagraph(buffer()->paragraphs);
|
||||
|
||||
if (c == '#') {
|
||||
// FIXME: huh ? No we won't !
|
||||
lyxerr[Debug::INFO] << "Will insert file with header" << endl;
|
||||
res = buffer()->readFile(lex, fname, ParagraphList::iterator(text->cursor.par()));
|
||||
} else {
|
||||
lyxerr[Debug::INFO] << "Will insert file without header"
|
||||
<< endl;
|
||||
res = buffer()->readBody(lex, ParagraphList::iterator(text->cursor.par()));
|
||||
}
|
||||
bool res = buffer()->readFile(fname, text->cursor.par());
|
||||
|
||||
resize();
|
||||
return res;
|
||||
|
@ -1,3 +1,15 @@
|
||||
2003-09-02 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* buffer.C (readFile): new function, take a filename and a
|
||||
ParagraphList::iterator
|
||||
(readFile): adjust
|
||||
(readFile): adjust, make it private. don't use setStream, make
|
||||
lyx2lyx use a temporary file. Some simplificaton. Make the Alerts
|
||||
always contain the filename.
|
||||
|
||||
* BufferView.C (insertLyXFile): simplify and make it work for
|
||||
gzipped files.
|
||||
|
||||
2003-08-30 John Levon <levon@movementarian.org>
|
||||
|
||||
* Makefile.am: fix dist (from Kayvan)
|
||||
|
110
src/buffer.C
110
src/buffer.C
@ -448,10 +448,7 @@ bool Buffer::readFile(string const & filename)
|
||||
params.compressed = true;
|
||||
}
|
||||
|
||||
LyXLex lex(0, 0);
|
||||
lex.setFile(filename);
|
||||
|
||||
bool ret = readFile(lex, filename, paragraphs.begin());
|
||||
bool ret = readFile(filename, paragraphs.begin());
|
||||
|
||||
// After we have read a file, we must ensure that the buffer
|
||||
// language is set and used in the gui.
|
||||
@ -462,13 +459,23 @@ bool Buffer::readFile(string const & filename)
|
||||
}
|
||||
|
||||
|
||||
// FIXME: all the below Alerts should give the filename..
|
||||
bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
|
||||
{
|
||||
LyXLex lex(0, 0);
|
||||
lex.setFile(filename);
|
||||
|
||||
return readFile(lex, filename, pit);
|
||||
}
|
||||
|
||||
|
||||
bool Buffer::readFile(LyXLex & lex, string const & filename,
|
||||
ParagraphList::iterator pit)
|
||||
{
|
||||
Assert(!filename.empty());
|
||||
|
||||
if (!lex.isOK()) {
|
||||
Alert::error(_("Document could not be read"),
|
||||
_("The specified document could not be read."));
|
||||
bformat(_("%1$s could not be read."), filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -477,7 +484,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
|
||||
|
||||
if (!lex.isOK()) {
|
||||
Alert::error(_("Document could not be read"),
|
||||
_("The specified document could not be read."));
|
||||
bformat(_("%1$s could not be read."), filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -486,7 +493,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
|
||||
lyxerr << "Token: " << token << endl;
|
||||
|
||||
Alert::error(_("Document format failure"),
|
||||
_("The specified document is not a LyX document."));
|
||||
bformat(_("%1$s is not a LyX document."),
|
||||
filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -500,62 +508,56 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
|
||||
tmp_format.erase(dot, 1);
|
||||
int file_format = strToInt(tmp_format);
|
||||
//lyxerr << "format: " << file_format << endl;
|
||||
if (file_format == LYX_FORMAT) {
|
||||
// current format
|
||||
} else if (file_format > LYX_FORMAT) {
|
||||
|
||||
if (file_format > LYX_FORMAT) {
|
||||
Alert::warning(_("Document format failure"),
|
||||
_("This document was created with a newer version of "
|
||||
"LyX. This is likely to cause problems."));
|
||||
bformat(_("%1$swas created with a newer version"
|
||||
" of LyX. This is likely to cause"
|
||||
" problems."),
|
||||
filename));
|
||||
} else if (file_format < LYX_FORMAT) {
|
||||
// old formats
|
||||
if (file_format < 200) {
|
||||
Alert::error(_("Document format failure"),
|
||||
_("This LyX document is too old to be read "
|
||||
"by this version of LyX. Try LyX 0.10."));
|
||||
return false;
|
||||
} else if (!filename.empty()) {
|
||||
string command =
|
||||
LibFileSearch("lyx2lyx", "lyx2lyx");
|
||||
if (command.empty()) {
|
||||
Alert::error(_("Conversion script not found"),
|
||||
_("The document is from an earlier version "
|
||||
"of LyX, but the conversion script lyx2lyx "
|
||||
"could not be found."));
|
||||
return false;
|
||||
}
|
||||
command += " -t"
|
||||
+ tostr(LYX_FORMAT) + ' '
|
||||
+ QuoteName(filename);
|
||||
lyxerr[Debug::INFO] << "Running '"
|
||||
<< command << '\''
|
||||
<< endl;
|
||||
cmd_ret const ret = RunCommand(command);
|
||||
if (ret.first) {
|
||||
Alert::error(_("Conversion script failed"),
|
||||
_("The document is from an earlier version "
|
||||
"of LyX, but the lyx2lyx script failed "
|
||||
"to convert it."));
|
||||
return false;
|
||||
}
|
||||
istringstream is(STRCONV(ret.second));
|
||||
LyXLex tmplex(0, 0);
|
||||
tmplex.setStream(is);
|
||||
return readFile(tmplex, string(), pit);
|
||||
} else {
|
||||
// This code is reached if lyx2lyx failed (for
|
||||
// some reason) to change the file format of
|
||||
// the file.
|
||||
Assert(false);
|
||||
string const tmpfile = tempName();
|
||||
string command = LibFileSearch("lyx2lyx", "lyx2lyx");
|
||||
if (command.empty()) {
|
||||
Alert::error(_("Conversion script not found"),
|
||||
bformat(_("%1$s is from an earlier"
|
||||
" version of LyX, but the"
|
||||
" conversion script lyx2lyx"
|
||||
" could not be found."),
|
||||
filename));
|
||||
return false;
|
||||
}
|
||||
command += " -t"
|
||||
+ tostr(LYX_FORMAT)
|
||||
+ " -o " + tmpfile + ' '
|
||||
+ QuoteName(filename);
|
||||
lyxerr[Debug::INFO] << "Running '"
|
||||
<< command << '\''
|
||||
<< endl;
|
||||
cmd_ret const ret = RunCommand(command);
|
||||
if (ret.first != 0) {
|
||||
Alert::error(_("Conversion script failed"),
|
||||
bformat(_("%1$s is from an earlier version"
|
||||
" of LyX, but the lyx2lyx script"
|
||||
" failed to convert it."),
|
||||
filename));
|
||||
return false;
|
||||
} else {
|
||||
bool ret = readFile(tmpfile, pit);
|
||||
// Do stuff with tmpfile name and buffer name here.
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool the_end = readBody(lex, pit);
|
||||
params.setPaperStuff();
|
||||
|
||||
if (!the_end) {
|
||||
Alert::error(_("Document format failure"),
|
||||
_("The document ended unexpectedly, which means "
|
||||
"that it is probably corrupted."));
|
||||
bformat(_("%1$s ended unexpectedly, which means"
|
||||
" that it is probably corrupted."),
|
||||
filename));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
10
src/buffer.h
10
src/buffer.h
@ -72,15 +72,19 @@ public:
|
||||
/// Load the autosaved file.
|
||||
void loadAutoSaveFile();
|
||||
|
||||
private:
|
||||
/** Inserts a file into a document
|
||||
\param par if != 0 insert the file.
|
||||
\return \c false if method fails.
|
||||
*/
|
||||
bool readFile(LyXLex &, string const &, ParagraphList::iterator pit);
|
||||
bool readFile(LyXLex &, string const & filename,
|
||||
ParagraphList::iterator pit);
|
||||
|
||||
// FIXME: it's very silly to pass a lex in here
|
||||
public:
|
||||
/// load a new file
|
||||
bool readFile(string const &);
|
||||
bool readFile(string const & filename);
|
||||
|
||||
bool readFile(string const & filename, ParagraphList::iterator pit);
|
||||
|
||||
/// read the header, returns number of unknown tokens
|
||||
int readHeader(LyXLex & lex);
|
||||
|
@ -25,66 +25,73 @@ int Alert::prompt(string const & title, string const & question,
|
||||
int default_button, int escape_button,
|
||||
string const & b1, string const & b2, string const & b3)
|
||||
{
|
||||
if (lyx_gui::use_gui)
|
||||
return prompt_pimpl(title, question,
|
||||
default_button, escape_button, b1, b2, b3);
|
||||
if (!lyx_gui::use_gui || lyxerr.debugging()) {
|
||||
lyxerr << title
|
||||
<< "----------------------------------------"
|
||||
<< question << endl;
|
||||
|
||||
lyxerr << title << endl;
|
||||
lyxerr << "----------------------------------------" << endl;
|
||||
lyxerr << question << endl;
|
||||
lyxerr << "Assuming answer is ";
|
||||
switch (default_button) {
|
||||
lyxerr << "Assuming answer is ";
|
||||
switch (default_button) {
|
||||
case 0: lyxerr << b1 << endl;
|
||||
case 1: lyxerr << b2 << endl;
|
||||
case 2: lyxerr << b3 << endl;
|
||||
}
|
||||
if (!lyx_gui::use_gui)
|
||||
return default_button;
|
||||
}
|
||||
return default_button;
|
||||
|
||||
return prompt_pimpl(title, question,
|
||||
default_button, escape_button, b1, b2, b3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Alert::warning(string const & title, string const & message)
|
||||
{
|
||||
if (!lyx_gui::use_gui || lyxerr.debugging())
|
||||
lyxerr << "Warning: " << title
|
||||
<< "----------------------------------------"
|
||||
<< message << endl;
|
||||
if (lyx_gui::use_gui)
|
||||
return warning_pimpl(title, message);
|
||||
|
||||
lyxerr << "Warning: " << title << endl;
|
||||
lyxerr << "----------------------------------------" << endl;
|
||||
lyxerr << message << endl;
|
||||
warning_pimpl(title, message);
|
||||
}
|
||||
|
||||
|
||||
void Alert::error(string const & title, string const & message)
|
||||
{
|
||||
if (lyx_gui::use_gui)
|
||||
return error_pimpl(title, message);
|
||||
if (!lyx_gui::use_gui || lyxerr.debugging())
|
||||
lyxerr << "Error: " << title << '\n'
|
||||
<< "----------------------------------------\n"
|
||||
<< message << endl;
|
||||
|
||||
lyxerr << "Error: " << title << endl;
|
||||
lyxerr << "----------------------------------------" << endl;
|
||||
lyxerr << message << endl;
|
||||
if (lyx_gui::use_gui)
|
||||
error_pimpl(title, message);
|
||||
}
|
||||
|
||||
|
||||
void Alert::information(string const & title, string const & message)
|
||||
{
|
||||
if (lyx_gui::use_gui)
|
||||
return information_pimpl(title, message);
|
||||
if (!lyx_gui::use_gui || lyxerr.debugging())
|
||||
lyxerr << title
|
||||
<< "----------------------------------------"
|
||||
<< message << endl;
|
||||
|
||||
lyxerr << title << endl;
|
||||
lyxerr << "----------------------------------------" << endl;
|
||||
lyxerr << message << endl;
|
||||
if (lyx_gui::use_gui)
|
||||
information_pimpl(title, message);
|
||||
}
|
||||
|
||||
|
||||
pair<bool, string> const Alert::askForText(string const & msg,
|
||||
string const & dflt)
|
||||
{
|
||||
if (!lyx_gui::use_gui) {
|
||||
lyxerr << "----------------------------------------" << endl
|
||||
<< msg << endl
|
||||
<< "Assuming answer is " << dflt
|
||||
if (!lyx_gui::use_gui || lyxerr.debugging()) {
|
||||
lyxerr << "----------------------------------------\n"
|
||||
<< msg << '\n'
|
||||
<< "Assuming answer is " << dflt << '\n'
|
||||
<< "----------------------------------------" << endl;
|
||||
return make_pair<bool, string>(true, dflt);
|
||||
} else {
|
||||
return askForText_pimpl(msg, dflt);
|
||||
if (!lyx_gui::use_gui)
|
||||
return make_pair<bool, string>(true, dflt);
|
||||
}
|
||||
|
||||
return askForText_pimpl(msg, dflt);
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
2003-09-02 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* Alert.C (prompt, warning, error, information, askForText): Make
|
||||
them output the alert to stderr if debugging is turned on.
|
||||
|
||||
2003-08-27 John Levon <levon@movementarian.org>
|
||||
|
||||
* screen.C: fix cursor in ERT (bug 1341)
|
||||
@ -38,7 +43,7 @@
|
||||
* Menubar.h: do not use a pimpl, but rather an abstract class
|
||||
|
||||
* Menubar.C: removed
|
||||
|
||||
|
||||
2003-07-25 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* Toolbar.h: do not use a pimpl, but rather an abstract class
|
||||
|
@ -118,7 +118,7 @@ private:
|
||||
int iy_;
|
||||
};
|
||||
|
||||
///
|
||||
///
|
||||
bool operator==(LyXCursor const & a, LyXCursor const & b);
|
||||
///
|
||||
bool operator!=(LyXCursor const & a, LyXCursor const & b);
|
||||
|
Loading…
Reference in New Issue
Block a user