[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| This patch should take care of most of the zlib issues.
>
| But I seems to have stumbled upon some other problems, espacially with
| insertion of lyx files. Has that been working of a very long time?
>
| Anyway...the patch...

And this is an update where a temporary file is used for lyx2lyx.

? newfile1.lyx.gz
? zlib-2.diff
? zlib.diff
Index: po/POTFILES.in
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/po/POTFILES.in,v
retrieving revision 1.348
diff -u -p -r1.348 POTFILES.in
--- po/POTFILES.in	28 Aug 2003 07:41:10 -0000	1.348
+++ po/POTFILES.in	1 Sep 2003 22:51:55 -0000
@@ -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
Index: src/BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.184
diff -u -p -r1.184 BufferView.C
--- src/BufferView.C	28 Aug 2003 07:41:10 -0000	1.184
+++ src/BufferView.C	1 Sep 2003 22:51:55 -0000
@@ -308,9 +308,8 @@ bool BufferView::insertLyXFile(string co
 	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()));
+		res = buffer()->readFile(fname, ParagraphList::iterator(text->cursor.par()));
 	} else {
 		lyxerr[Debug::INFO] << "Will insert file without header"
 				    << endl;
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.512
diff -u -p -r1.512 buffer.C
--- src/buffer.C	28 Aug 2003 07:41:12 -0000	1.512
+++ src/buffer.C	1 Sep 2003 22:51:56 -0000
@@ -448,10 +448,7 @@ bool Buffer::readFile(string const & fil
 		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 & fil
 }
 
 
-// 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, stri
 
 	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, stri
 		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, stri
 			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."));
+		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;
-		} 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);
+		}
+		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;
 }
Index: src/buffer.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v
retrieving revision 1.155
diff -u -p -r1.155 buffer.h
--- src/buffer.h	23 Aug 2003 00:16:07 -0000	1.155
+++ src/buffer.h	1 Sep 2003 22:51:56 -0000
@@ -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);
Index: src/frontends/Alert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Alert.C,v
retrieving revision 1.13
diff -u -p -r1.13 Alert.C
--- src/frontends/Alert.C	23 Aug 2003 00:16:34 -0000	1.13
+++ src/frontends/Alert.C	1 Sep 2003 22:51:56 -0000
@@ -25,66 +25,73 @@ int Alert::prompt(string const & title, 
            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);
 }
-- 
        Lgb

Reply via email to